aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 12:58:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 12:58:16 -0400
commit240c3c3424366c8109babd2a0fe80855de511b35 (patch)
tree72eb8652c8e513715efee1e254644b4b670333fd /drivers
parent19b344efa35dbc253e2d10403dafe6aafda73c56 (diff)
parentdf90e2258950fd631cdbf322c1ee1f22068391aa (diff)
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media update from Mauro Carvalho Chehab: - OF documentation and patches at core and drivers, to be used by for embedded media systems - some I2C drivers used on go7007 were rewritten/promoted from staging: sony-btf-mpx, tw2804, tw9903, tw9906, wis-ov7640, wis-uda1342 - add fimc-is driver (Exynos) - add a new radio driver: radio-si476x - add a two new tuners: r820t and tuner_it913x - split camera code on em28xx driver and add more models - the cypress firmware load is used outside dvb usb drivers. So, move it to a common directory to make easier to re-use it - siano media driver updated to work with sms2270 devices - several work done in order to promote go7007 and solo6x1x out of staging (still, there are some pending issues) - several API compliance fixes at v4l2 drivers that don't behave as expected - as usual, lots of driver fixes, improvements, cleanups and new device addition at the existing drivers. * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (831 commits) [media] cx88: make core less verbose [media] em28xx: fix oops at em28xx_dvb_bus_ctrl() [media] s5c73m3: fix indentation of the help section in Kconfig [media] cx25821-alsa: get rid of a __must_check warning [media] cx25821-video: declare cx25821_vidioc_s_std as static [media] cx25821-video: remove maxw from cx25821_vidioc_try_fmt_vid_cap [media] r820t: Remove a warning for an unused value [media] dib0090: Fix a warning at dib0090_set_EFUSE [media] dib8000: fix a warning [media] dib8000: Fix sub-channel range [media] dib8000: store dtv_property_cache in a temp var [media] dib8000: warning fix: declare internal functions as static [media] r820t: quiet gcc warning on n_ring [media] r820t: memory leak in release() [media] r820t: precendence bug in r820t_xtal_check() [media] videodev2.h: Remove the unused old V4L1 buffer types [media] anysee: Grammar s/report the/report to/ [media] anysee: Initialize ret = 0 in anysee_frontend_attach() [media] media: videobuf2: fix the length check for mmap [media] em28xx: save isoc endpoint number for DVB only if endpoint has alt settings with xMaxPacketSize != 0 ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/common/Kconfig4
-rw-r--r--drivers/media/common/Makefile1
-rw-r--r--drivers/media/common/b2c2/flexcop-fe-tuner.c4
-rw-r--r--drivers/media/common/cypress_firmware.c (renamed from drivers/media/usb/dvb-usb-v2/cypress_firmware.c)82
-rw-r--r--drivers/media/common/cypress_firmware.h (renamed from drivers/media/usb/dvb-usb-v2/cypress_firmware.h)9
-rw-r--r--drivers/media/common/saa7146/saa7146_video.c4
-rw-r--r--drivers/media/common/siano/Kconfig12
-rw-r--r--drivers/media/common/siano/Makefile5
-rw-r--r--drivers/media/common/siano/sms-cards.c115
-rw-r--r--drivers/media/common/siano/sms-cards.h14
-rw-r--r--drivers/media/common/siano/smscoreapi.c1298
-rw-r--r--drivers/media/common/siano/smscoreapi.h1007
-rw-r--r--drivers/media/common/siano/smsdvb-debugfs.c551
-rw-r--r--drivers/media/common/siano/smsdvb-main.c1230
-rw-r--r--drivers/media/common/siano/smsdvb.c1078
-rw-r--r--drivers/media/common/siano/smsdvb.h130
-rw-r--r--drivers/media/common/siano/smsendian.c44
-rw-r--r--drivers/media/common/siano/smsir.h1
-rw-r--r--drivers/media/dvb-core/demux.h39
-rw-r--r--drivers/media/dvb-core/dmxdev.c5
-rw-r--r--drivers/media/dvb-core/dvb-usb-ids.h3
-rw-r--r--drivers/media/dvb-core/dvb_demux.c30
-rw-r--r--drivers/media/dvb-core/dvb_demux.h4
-rw-r--r--drivers/media/dvb-core/dvb_frontend.c333
-rw-r--r--drivers/media/dvb-core/dvb_frontend.h4
-rw-r--r--drivers/media/dvb-core/dvb_net.c2
-rw-r--r--drivers/media/dvb-frontends/Kconfig2
-rw-r--r--drivers/media/dvb-frontends/a8293.h5
-rw-r--r--drivers/media/dvb-frontends/af9013.h4
-rw-r--r--drivers/media/dvb-frontends/af9033.c138
-rw-r--r--drivers/media/dvb-frontends/af9033.h20
-rw-r--r--drivers/media/dvb-frontends/af9033_priv.h1506
-rw-r--r--drivers/media/dvb-frontends/atbm8830.h4
-rw-r--r--drivers/media/dvb-frontends/au8522.h4
-rw-r--r--drivers/media/dvb-frontends/au8522_decoder.c125
-rw-r--r--drivers/media/dvb-frontends/au8522_priv.h6
-rw-r--r--drivers/media/dvb-frontends/cx22702.h4
-rw-r--r--drivers/media/dvb-frontends/cx24113.h5
-rw-r--r--drivers/media/dvb-frontends/cx24116.h4
-rw-r--r--drivers/media/dvb-frontends/cx24123.c28
-rw-r--r--drivers/media/dvb-frontends/cx24123.h4
-rw-r--r--drivers/media/dvb-frontends/cxd2820r.h4
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_core.c3
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_t2.c17
-rw-r--r--drivers/media/dvb-frontends/dib0090.c434
-rw-r--r--drivers/media/dvb-frontends/dib3000mc.h5
-rw-r--r--drivers/media/dvb-frontends/dib7000m.h5
-rw-r--r--drivers/media/dvb-frontends/dib7000p.c17
-rw-r--r--drivers/media/dvb-frontends/dib7000p.h12
-rw-r--r--drivers/media/dvb-frontends/dib8000.c2268
-rw-r--r--drivers/media/dvb-frontends/dib8000.h6
-rw-r--r--drivers/media/dvb-frontends/dibx000_common.h3
-rw-r--r--drivers/media/dvb-frontends/drxd.h4
-rw-r--r--drivers/media/dvb-frontends/drxk.h4
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.c309
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.h2
-rw-r--r--drivers/media/dvb-frontends/drxk_map.h3
-rw-r--r--drivers/media/dvb-frontends/ds3000.h4
-rw-r--r--drivers/media/dvb-frontends/dvb_dummy_fe.h4
-rw-r--r--drivers/media/dvb-frontends/ec100.h4
-rw-r--r--drivers/media/dvb-frontends/hd29l2.h4
-rw-r--r--drivers/media/dvb-frontends/isl6421.c28
-rw-r--r--drivers/media/dvb-frontends/isl6421.h4
-rw-r--r--drivers/media/dvb-frontends/it913x-fe.h4
-rw-r--r--drivers/media/dvb-frontends/ix2505v.h4
-rw-r--r--drivers/media/dvb-frontends/lg2160.h8
-rw-r--r--drivers/media/dvb-frontends/lgdt3305.h4
-rw-r--r--drivers/media/dvb-frontends/lgs8gl5.h4
-rw-r--r--drivers/media/dvb-frontends/lgs8gxx.h4
-rw-r--r--drivers/media/dvb-frontends/lnbh24.h5
-rw-r--r--drivers/media/dvb-frontends/lnbp21.h5
-rw-r--r--drivers/media/dvb-frontends/lnbp22.h5
-rw-r--r--drivers/media/dvb-frontends/m88rs2000.h4
-rw-r--r--drivers/media/dvb-frontends/mb86a20s.c505
-rw-r--r--drivers/media/dvb-frontends/mb86a20s.h12
-rw-r--r--drivers/media/dvb-frontends/rtl2830.h4
-rw-r--r--drivers/media/dvb-frontends/rtl2832.c85
-rw-r--r--drivers/media/dvb-frontends/rtl2832.h5
-rw-r--r--drivers/media/dvb-frontends/rtl2832_priv.h28
-rw-r--r--drivers/media/dvb-frontends/s5h1409.h4
-rw-r--r--drivers/media/dvb-frontends/s5h1411.h4
-rw-r--r--drivers/media/dvb-frontends/s5h1432.h4
-rw-r--r--drivers/media/dvb-frontends/s921.h4
-rw-r--r--drivers/media/dvb-frontends/si21xx.h4
-rw-r--r--drivers/media/dvb-frontends/stb6000.h4
-rw-r--r--drivers/media/dvb-frontends/stv0288.h4
-rw-r--r--drivers/media/dvb-frontends/stv0367.h4
-rw-r--r--drivers/media/dvb-frontends/stv0900.h4
-rw-r--r--drivers/media/dvb-frontends/stv090x.c22
-rw-r--r--drivers/media/dvb-frontends/stv6110.h4
-rw-r--r--drivers/media/dvb-frontends/tda10048.h4
-rw-r--r--drivers/media/dvb-frontends/tda10071.h4
-rw-r--r--drivers/media/dvb-frontends/tda18271c2dd.h6
-rw-r--r--drivers/media/dvb-frontends/ts2020.h4
-rw-r--r--drivers/media/dvb-frontends/zl10036.h4
-rw-r--r--drivers/media/dvb-frontends/zl10039.h5
-rw-r--r--drivers/media/firewire/firedtv-dvb.c14
-rw-r--r--drivers/media/i2c/Kconfig70
-rw-r--r--drivers/media/i2c/Makefile8
-rw-r--r--drivers/media/i2c/ad9389b.c2
-rw-r--r--drivers/media/i2c/adp1653.c4
-rw-r--r--drivers/media/i2c/adv7180.c4
-rw-r--r--drivers/media/i2c/adv7183.c2
-rw-r--r--drivers/media/i2c/adv7604.c2
-rw-r--r--drivers/media/i2c/ak881x.c2
-rw-r--r--drivers/media/i2c/cs5345.c2
-rw-r--r--drivers/media/i2c/cx25840/cx25840-core.c6
-rw-r--r--drivers/media/i2c/ir-kbd-i2c.c14
-rw-r--r--drivers/media/i2c/m52790.c2
-rw-r--r--drivers/media/i2c/msp3400-driver.c4
-rw-r--r--drivers/media/i2c/mt9m032.c48
-rw-r--r--drivers/media/i2c/mt9p031.c58
-rw-r--r--drivers/media/i2c/mt9v011.c2
-rw-r--r--drivers/media/i2c/ov7640.c (renamed from drivers/staging/media/go7007/wis-ov7640.c)70
-rw-r--r--drivers/media/i2c/ov7670.c2
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-core.c23
-rw-r--r--drivers/media/i2c/saa6588.c2
-rw-r--r--drivers/media/i2c/saa7115.c80
-rw-r--r--drivers/media/i2c/saa7127.c2
-rw-r--r--drivers/media/i2c/saa717x.c4
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c4
-rw-r--r--drivers/media/i2c/soc_camera/Kconfig2
-rw-r--r--drivers/media/i2c/soc_camera/mt9m001.c2
-rw-r--r--drivers/media/i2c/soc_camera/mt9m111.c11
-rw-r--r--drivers/media/i2c/soc_camera/mt9t031.c2
-rw-r--r--drivers/media/i2c/soc_camera/mt9t112.c2
-rw-r--r--drivers/media/i2c/soc_camera/mt9v022.c21
-rw-r--r--drivers/media/i2c/soc_camera/ov2640.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov5642.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov6650.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov772x.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.c2
-rw-r--r--drivers/media/i2c/soc_camera/ov9740.c2
-rw-r--r--drivers/media/i2c/soc_camera/rj54n1cb0c.c2
-rw-r--r--drivers/media/i2c/soc_camera/tw9910.c2
-rw-r--r--drivers/media/i2c/sony-btf-mpx.c399
-rw-r--r--drivers/media/i2c/tda7432.c276
-rw-r--r--drivers/media/i2c/tda9840.c2
-rw-r--r--drivers/media/i2c/ths7303.c351
-rw-r--r--drivers/media/i2c/tvaudio.c6
-rw-r--r--drivers/media/i2c/tvp514x.c163
-rw-r--r--drivers/media/i2c/tvp5150.c2
-rw-r--r--drivers/media/i2c/tvp7002.c184
-rw-r--r--drivers/media/i2c/tw2804.c453
-rw-r--r--drivers/media/i2c/tw9903.c279
-rw-r--r--drivers/media/i2c/tw9906.c247
-rw-r--r--drivers/media/i2c/uda1342.c (renamed from drivers/staging/media/go7007/wis-uda1342.c)83
-rw-r--r--drivers/media/i2c/upd64031a.c4
-rw-r--r--drivers/media/i2c/upd64083.c2
-rw-r--r--drivers/media/i2c/vp27smpx.c2
-rw-r--r--drivers/media/i2c/vs6624.c2
-rw-r--r--drivers/media/i2c/wm8775.c2
-rw-r--r--drivers/media/media-device.c111
-rw-r--r--drivers/media/media-devnode.c31
-rw-r--r--drivers/media/mmc/siano/smssdio.c27
-rw-r--r--drivers/media/parport/pms.c4
-rw-r--r--drivers/media/pci/bt8xx/bttv-cards.c21
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c1226
-rw-r--r--drivers/media/pci/bt8xx/bttv-i2c.c8
-rw-r--r--drivers/media/pci/bt8xx/bttv-input.c30
-rw-r--r--drivers/media/pci/bt8xx/bttv.h3
-rw-r--r--drivers/media/pci/bt8xx/bttvp.h38
-rw-r--r--drivers/media/pci/cx18/cx18-av-core.c6
-rw-r--r--drivers/media/pci/cx18/cx18-driver.c2
-rw-r--r--drivers/media/pci/cx18/cx18-ioctl.c52
-rw-r--r--drivers/media/pci/cx18/cx18-ioctl.h4
-rw-r--r--drivers/media/pci/cx23885/altera-ci.h5
-rw-r--r--drivers/media/pci/cx23885/cx23885-417.c10
-rw-r--r--drivers/media/pci/cx23885/cx23885-ioctl.c9
-rw-r--r--drivers/media/pci/cx23885/cx23885-ioctl.h2
-rw-r--r--drivers/media/pci/cx23885/cx23885-video.c14
-rw-r--r--drivers/media/pci/cx23885/cx23885.h2
-rw-r--r--drivers/media/pci/cx23885/cx23888-ir.c2
-rw-r--r--drivers/media/pci/cx25821/Kconfig7
-rw-r--r--drivers/media/pci/cx25821/Makefile7
-rw-r--r--drivers/media/pci/cx25821/cx25821-alsa.c83
-rw-r--r--drivers/media/pci/cx25821/cx25821-audio-upstream.c43
-rw-r--r--drivers/media/pci/cx25821/cx25821-cards.c23
-rw-r--r--drivers/media/pci/cx25821/cx25821-core.c133
-rw-r--r--drivers/media/pci/cx25821/cx25821-gpio.c1
-rw-r--r--drivers/media/pci/cx25821/cx25821-i2c.c3
-rw-r--r--drivers/media/pci/cx25821/cx25821-medusa-video.c46
-rw-r--r--drivers/media/pci/cx25821/cx25821-video-upstream-ch2.c800
-rw-r--r--drivers/media/pci/cx25821/cx25821-video-upstream-ch2.h138
-rw-r--r--drivers/media/pci/cx25821/cx25821-video-upstream.c519
-rw-r--r--drivers/media/pci/cx25821/cx25821-video.c1822
-rw-r--r--drivers/media/pci/cx25821/cx25821-video.h125
-rw-r--r--drivers/media/pci/cx25821/cx25821.h304
-rw-r--r--drivers/media/pci/cx88/cx88-blackbird.c8
-rw-r--r--drivers/media/pci/cx88/cx88-cards.c30
-rw-r--r--drivers/media/pci/cx88/cx88-core.c12
-rw-r--r--drivers/media/pci/cx88/cx88-dvb.c16
-rw-r--r--drivers/media/pci/cx88/cx88-mpeg.c10
-rw-r--r--drivers/media/pci/cx88/cx88-video.c35
-rw-r--r--drivers/media/pci/cx88/cx88.h5
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c4
-rw-r--r--drivers/media/pci/ivtv/ivtv-firmware.c4
-rw-r--r--drivers/media/pci/ivtv/ivtv-gpio.c2
-rw-r--r--drivers/media/pci/ivtv/ivtv-ioctl.c57
-rw-r--r--drivers/media/pci/ivtv/ivtv-ioctl.h6
-rw-r--r--drivers/media/pci/ivtv/ivtvfb.c3
-rw-r--r--drivers/media/pci/meye/meye.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-cards.c94
-rw-r--r--drivers/media/pci/saa7134/saa7134-core.c3
-rw-r--r--drivers/media/pci/saa7134/saa7134-dvb.c31
-rw-r--r--drivers/media/pci/saa7134/saa7134-empress.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-i2c.c1
-rw-r--r--drivers/media/pci/saa7134/saa7134-input.c3
-rw-r--r--drivers/media/pci/saa7134/saa7134-tvaudio.c1
-rw-r--r--drivers/media/pci/saa7134/saa7134-video.c189
-rw-r--r--drivers/media/pci/saa7134/saa7134.h11
-rw-r--r--drivers/media/pci/saa7146/mxb.c9
-rw-r--r--drivers/media/pci/saa7164/saa7164-encoder.c14
-rw-r--r--drivers/media/pci/saa7164/saa7164-vbi.c12
-rw-r--r--drivers/media/pci/sta2x11/Kconfig1
-rw-r--r--drivers/media/pci/sta2x11/sta2x11_vip.c18
-rw-r--r--drivers/media/pci/ttpci/av7110.c6
-rw-r--r--drivers/media/pci/ttpci/av7110_v4l.c4
-rw-r--r--drivers/media/pci/ttpci/budget.c12
-rw-r--r--drivers/media/pci/zoran/zoran_driver.c4
-rw-r--r--drivers/media/pci/zoran/zoran_procfs.c2
-rw-r--r--drivers/media/platform/Kconfig2
-rw-r--r--drivers/media/platform/Makefile2
-rw-r--r--drivers/media/platform/blackfin/bfin_capture.c13
-rw-r--r--drivers/media/platform/coda.c5
-rw-r--r--drivers/media/platform/davinci/Kconfig103
-rw-r--r--drivers/media/platform/davinci/Makefile17
-rw-r--r--drivers/media/platform/davinci/dm355_ccdc.c49
-rw-r--r--drivers/media/platform/davinci/dm355_ccdc_regs.h2
-rw-r--r--drivers/media/platform/davinci/dm644x_ccdc.c57
-rw-r--r--drivers/media/platform/davinci/dm644x_ccdc_regs.h2
-rw-r--r--drivers/media/platform/davinci/isif.c30
-rw-r--r--drivers/media/platform/davinci/isif_regs.h4
-rw-r--r--drivers/media/platform/davinci/vpbe.c16
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c17
-rw-r--r--drivers/media/platform/davinci/vpbe_osd.c3
-rw-r--r--drivers/media/platform/davinci/vpbe_venc.c36
-rw-r--r--drivers/media/platform/davinci/vpfe_capture.c62
-rw-r--r--drivers/media/platform/davinci/vpif.c32
-rw-r--r--drivers/media/platform/davinci/vpif.h2
-rw-r--r--drivers/media/platform/davinci/vpif_capture.c12
-rw-r--r--drivers/media/platform/davinci/vpif_display.c16
-rw-r--r--drivers/media/platform/davinci/vpss.c36
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-m2m.c5
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-regs.c1
-rw-r--r--drivers/media/platform/exynos4-is/Kconfig (renamed from drivers/media/platform/s5p-fimc/Kconfig)21
-rw-r--r--drivers/media/platform/exynos4-is/Makefile (renamed from drivers/media/platform/s5p-fimc/Makefile)5
-rw-r--r--drivers/media/platform/exynos4-is/fimc-capture.c (renamed from drivers/media/platform/s5p-fimc/fimc-capture.c)411
-rw-r--r--drivers/media/platform/exynos4-is/fimc-core.c (renamed from drivers/media/platform/s5p-fimc/fimc-core.c)312
-rw-r--r--drivers/media/platform/exynos4-is/fimc-core.h (renamed from drivers/media/platform/s5p-fimc/fimc-core.h)86
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-command.h137
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-errno.c272
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-errno.h248
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-i2c.c126
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-i2c.h15
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-param.c900
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-param.h1020
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-regs.c243
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-regs.h164
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-sensor.c305
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-sensor.h89
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is.c1007
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is.h345
-rw-r--r--drivers/media/platform/exynos4-is/fimc-isp.c703
-rw-r--r--drivers/media/platform/exynos4-is/fimc-isp.h181
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite-reg.c (renamed from drivers/media/platform/s5p-fimc/fimc-lite-reg.c)4
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite-reg.h (renamed from drivers/media/platform/s5p-fimc/fimc-lite-reg.h)8
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite.c (renamed from drivers/media/platform/s5p-fimc/fimc-lite.c)429
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite.h (renamed from drivers/media/platform/s5p-fimc/fimc-lite.h)20
-rw-r--r--drivers/media/platform/exynos4-is/fimc-m2m.c (renamed from drivers/media/platform/s5p-fimc/fimc-m2m.c)40
-rw-r--r--drivers/media/platform/exynos4-is/fimc-reg.c (renamed from drivers/media/platform/s5p-fimc/fimc-reg.c)87
-rw-r--r--drivers/media/platform/exynos4-is/fimc-reg.h (renamed from drivers/media/platform/s5p-fimc/fimc-reg.h)27
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.c (renamed from drivers/media/platform/s5p-fimc/fimc-mdevice.c)725
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.h (renamed from drivers/media/platform/s5p-fimc/fimc-mdevice.h)54
-rw-r--r--drivers/media/platform/exynos4-is/mipi-csis.c (renamed from drivers/media/platform/s5p-fimc/mipi-csis.c)169
-rw-r--r--drivers/media/platform/exynos4-is/mipi-csis.h (renamed from drivers/media/platform/s5p-fimc/mipi-csis.h)1
-rw-r--r--drivers/media/platform/fsl-viu.c6
-rw-r--r--drivers/media/platform/m2m-deinterlace.c5
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c4
-rw-r--r--drivers/media/platform/mem2mem_testdev.c12
-rw-r--r--drivers/media/platform/mx2_emmaprp.c5
-rw-r--r--drivers/media/platform/omap/omap_vout.c14
-rw-r--r--drivers/media/platform/s3c-camif/camif-capture.c16
-rw-r--r--drivers/media/platform/s5p-g2d/g2d.c36
-rw-r--r--drivers/media/platform/s5p-jpeg/jpeg-core.c5
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c19
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c12
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c12
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_dec.c76
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c112
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c122
-rw-r--r--drivers/media/platform/s5p-tv/hdmi_drv.c129
-rw-r--r--drivers/media/platform/s5p-tv/hdmiphy_drv.c55
-rw-r--r--drivers/media/platform/s5p-tv/mixer_video.c52
-rw-r--r--drivers/media/platform/s5p-tv/sii9234_drv.c3
-rw-r--r--drivers/media/platform/sh_veu.c20
-rw-r--r--drivers/media/platform/sh_vou.c27
-rw-r--r--drivers/media/platform/soc_camera/atmel-isi.c16
-rw-r--r--drivers/media/platform/soc_camera/mx1_camera.c17
-rw-r--r--drivers/media/platform/soc_camera/mx2_camera.c8
-rw-r--r--drivers/media/platform/soc_camera/mx3_camera.c3
-rw-r--r--drivers/media/platform/soc_camera/omap1_camera.c6
-rw-r--r--drivers/media/platform/soc_camera/pxa_camera.c12
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c12
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_csi2.c9
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c48
-rw-r--r--drivers/media/platform/soc_camera/soc_camera_platform.c2
-rw-r--r--drivers/media/platform/soc_camera/soc_mediabus.c46
-rw-r--r--drivers/media/platform/timblogiw.c8
-rw-r--r--drivers/media/platform/via-camera.c2
-rw-r--r--drivers/media/platform/vino.c10
-rw-r--r--drivers/media/platform/vivi.c10
-rw-r--r--drivers/media/radio/Kconfig16
-rw-r--r--drivers/media/radio/Makefile1
-rw-r--r--drivers/media/radio/dsbr100.c4
-rw-r--r--drivers/media/radio/radio-cadet.c48
-rw-r--r--drivers/media/radio/radio-isa.c15
-rw-r--r--drivers/media/radio/radio-keene.c8
-rw-r--r--drivers/media/radio/radio-ma901.c4
-rw-r--r--drivers/media/radio/radio-miropcm20.c12
-rw-r--r--drivers/media/radio/radio-mr800.c14
-rw-r--r--drivers/media/radio/radio-rtrack2.c5
-rw-r--r--drivers/media/radio/radio-sf16fmi.c4
-rw-r--r--drivers/media/radio/radio-si4713.c204
-rw-r--r--drivers/media/radio/radio-si476x.c1599
-rw-r--r--drivers/media/radio/radio-tea5764.c4
-rw-r--r--drivers/media/radio/radio-tea5777.c9
-rw-r--r--drivers/media/radio/radio-timb.c4
-rw-r--r--drivers/media/radio/radio-wl1273.c4
-rw-r--r--drivers/media/radio/si470x/radio-si470x-common.c4
-rw-r--r--drivers/media/radio/si4713-i2c.c1049
-rw-r--r--drivers/media/radio/si4713-i2c.h66
-rw-r--r--drivers/media/radio/tef6862.c4
-rw-r--r--drivers/media/radio/wl128x/fmdrv_v4l2.c8
-rw-r--r--drivers/media/rc/ene_ir.c1
-rw-r--r--drivers/media/rc/imon.c46
-rw-r--r--drivers/media/rc/ir-jvc-decoder.c2
-rw-r--r--drivers/media/rc/ir-lirc-codec.c2
-rw-r--r--drivers/media/rc/ir-mce_kbd-decoder.c2
-rw-r--r--drivers/media/rc/ir-nec-decoder.c2
-rw-r--r--drivers/media/rc/ir-raw.c2
-rw-r--r--drivers/media/rc/ir-rc5-decoder.c6
-rw-r--r--drivers/media/rc/ir-rc5-sz-decoder.c2
-rw-r--r--drivers/media/rc/ir-rc6-decoder.c2
-rw-r--r--drivers/media/rc/ir-rx51.c4
-rw-r--r--drivers/media/rc/ir-sanyo-decoder.c2
-rw-r--r--drivers/media/rc/ir-sony-decoder.c8
-rw-r--r--drivers/media/rc/ite-cir.c1
-rw-r--r--drivers/media/rc/keymaps/Makefile3
-rw-r--r--drivers/media/rc/keymaps/rc-reddo.c86
-rw-r--r--drivers/media/rc/mceusb.c11
-rw-r--r--drivers/media/rc/nuvoton-cir.c1
-rw-r--r--drivers/media/rc/rc-core-priv.h1
-rw-r--r--drivers/media/rc/rc-main.c46
-rw-r--r--drivers/media/rc/redrat3.c457
-rw-r--r--drivers/media/rc/ttusbir.c1
-rw-r--r--drivers/media/rc/winbond-cir.c1
-rw-r--r--drivers/media/tuners/Kconfig14
-rw-r--r--drivers/media/tuners/Makefile2
-rw-r--r--drivers/media/tuners/e4000.h4
-rw-r--r--drivers/media/tuners/fc0011.h4
-rw-r--r--drivers/media/tuners/fc0012.h4
-rw-r--r--drivers/media/tuners/fc0013.h4
-rw-r--r--drivers/media/tuners/fc2580.h4
-rw-r--r--drivers/media/tuners/max2165.h5
-rw-r--r--drivers/media/tuners/mc44s803.h5
-rw-r--r--drivers/media/tuners/mxl5005s.h5
-rw-r--r--drivers/media/tuners/r820t.c2355
-rw-r--r--drivers/media/tuners/r820t.h59
-rw-r--r--drivers/media/tuners/tda18212.h4
-rw-r--r--drivers/media/tuners/tda18218.h4
-rw-r--r--drivers/media/tuners/tda18271-fe.c9
-rw-r--r--drivers/media/tuners/tda827x.c10
-rw-r--r--drivers/media/tuners/tda827x.h3
-rw-r--r--drivers/media/tuners/tda8290.c75
-rw-r--r--drivers/media/tuners/tda8290.h12
-rw-r--r--drivers/media/tuners/tda9887.c14
-rw-r--r--drivers/media/tuners/tua9001.h4
-rw-r--r--drivers/media/tuners/tuner-simple.c5
-rw-r--r--drivers/media/tuners/tuner-types.c69
-rw-r--r--drivers/media/tuners/tuner-xc2028.c3
-rw-r--r--drivers/media/tuners/tuner_it913x.c447
-rw-r--r--drivers/media/tuners/tuner_it913x.h45
-rw-r--r--drivers/media/tuners/tuner_it913x_priv.h78
-rw-r--r--drivers/media/tuners/xc5000.c20
-rw-r--r--drivers/media/tuners/xc5000.h4
-rw-r--r--drivers/media/usb/au0828/au0828-core.c61
-rw-r--r--drivers/media/usb/au0828/au0828-video.c299
-rw-r--r--drivers/media/usb/au0828/au0828.h7
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-417.c1182
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-audio.c8
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-avcore.c85
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c59
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-core.c2
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-dvb.c4
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c2
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-pcb-cfg.h5
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-vbi.c25
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-video.c601
-rw-r--r--drivers/media/usb/cx231xx/cx231xx.h55
-rw-r--r--drivers/media/usb/dvb-usb-v2/Kconfig8
-rw-r--r--drivers/media/usb/dvb-usb-v2/Makefile5
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.c79
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c600
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.h49
-rw-r--r--drivers/media/usb/dvb-usb-v2/anysee.c48
-rw-r--r--drivers/media/usb/dvb-usb-v2/anysee.h3
-rw-r--r--drivers/media/usb/dvb-usb-v2/az6007.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb.h9
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb_core.c311
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c43
-rw-r--r--drivers/media/usb/dvb-usb-v2/it913x.c1
-rw-r--r--drivers/media/usb/dvb-usb-v2/lmedm04.c8
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h4
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h5
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.c36
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.h1
-rw-r--r--drivers/media/usb/dvb-usb-v2/usb_urb.c36
-rw-r--r--drivers/media/usb/dvb-usb/cinergyT2-fe.c3
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_devices.c465
-rw-r--r--drivers/media/usb/dvb-usb/dibusb-common.c5
-rw-r--r--drivers/media/usb/dvb-usb/dw2102.c19
-rw-r--r--drivers/media/usb/dvb-usb/m920x.c10
-rw-r--r--drivers/media/usb/em28xx/Kconfig1
-rw-r--r--drivers/media/usb/em28xx/Makefile2
-rw-r--r--drivers/media/usb/em28xx/em28xx-camera.c434
-rw-r--r--drivers/media/usb/em28xx/em28xx-cards.c366
-rw-r--r--drivers/media/usb/em28xx/em28xx-core.c45
-rw-r--r--drivers/media/usb/em28xx/em28xx-dvb.c125
-rw-r--r--drivers/media/usb/em28xx/em28xx-i2c.c691
-rw-r--r--drivers/media/usb/em28xx/em28xx-input.c5
-rw-r--r--drivers/media/usb/em28xx/em28xx-reg.h35
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c415
-rw-r--r--drivers/media/usb/em28xx/em28xx.h231
-rw-r--r--drivers/media/usb/gspca/autogain_functions.h183
-rw-r--r--drivers/media/usb/gspca/benq.c2
-rw-r--r--drivers/media/usb/gspca/conex.c12
-rw-r--r--drivers/media/usb/gspca/cpia1.c33
-rw-r--r--drivers/media/usb/gspca/etoms.c12
-rw-r--r--drivers/media/usb/gspca/gl860/gl860.c224
-rw-r--r--drivers/media/usb/gspca/gspca.c240
-rw-r--r--drivers/media/usb/gspca/gspca.h70
-rw-r--r--drivers/media/usb/gspca/jeilinj.c2
-rw-r--r--drivers/media/usb/gspca/konica.c28
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_bridge.h27
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_core.c22
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_mt9m111.c404
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_mt9m111.h2
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_ov7660.c312
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_ov7660.h3
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_ov9650.c469
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_ov9650.h2
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_po1030.c471
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_po1030.h2
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_s5k4aa.c352
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_s5k4aa.h2
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_s5k83a.c291
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_s5k83a.h9
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_sensor.h3
-rw-r--r--drivers/media/usb/gspca/mr97310a.c8
-rw-r--r--drivers/media/usb/gspca/ov519.c81
-rw-r--r--drivers/media/usb/gspca/ov534.c2
-rw-r--r--drivers/media/usb/gspca/pac207.c2
-rw-r--r--drivers/media/usb/gspca/pac7302.c9
-rw-r--r--drivers/media/usb/gspca/pac7311.c5
-rw-r--r--drivers/media/usb/gspca/pac_common.h2
-rw-r--r--drivers/media/usb/gspca/sn9c2028.c4
-rw-r--r--drivers/media/usb/gspca/sn9c20x.c2
-rw-r--r--drivers/media/usb/gspca/sonixb.c22
-rw-r--r--drivers/media/usb/gspca/sonixj.c556
-rw-r--r--drivers/media/usb/gspca/spca1528.c4
-rw-r--r--drivers/media/usb/gspca/spca500.c36
-rw-r--r--drivers/media/usb/gspca/spca501.c44
-rw-r--r--drivers/media/usb/gspca/spca505.c42
-rw-r--r--drivers/media/usb/gspca/spca508.c41
-rw-r--r--drivers/media/usb/gspca/spca561.c70
-rw-r--r--drivers/media/usb/gspca/sq905.c2
-rw-r--r--drivers/media/usb/gspca/sq905c.c6
-rw-r--r--drivers/media/usb/gspca/sq930x.c4
-rw-r--r--drivers/media/usb/gspca/stv0680.c14
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx.c17
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx_hdcs.c8
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c14
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx_st6422.c2
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c10
-rw-r--r--drivers/media/usb/gspca/sunplus.c27
-rw-r--r--drivers/media/usb/gspca/vc032x.c9
-rw-r--r--drivers/media/usb/gspca/w996Xcf.c5
-rw-r--r--drivers/media/usb/gspca/zc3xx.c3
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-core.c15
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-video.c945
-rw-r--r--drivers/media/usb/hdpvr/hdpvr.h19
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.c2
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.h2
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-v4l2.c10
-rw-r--r--drivers/media/usb/pwc/pwc-if.c1
-rw-r--r--drivers/media/usb/s2255/s2255drv.c441
-rw-r--r--drivers/media/usb/siano/smsusb.c158
-rw-r--r--drivers/media/usb/stk1160/stk1160-v4l.c14
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c309
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.h8
-rw-r--r--drivers/media/usb/tlg2300/pd-common.h26
-rw-r--r--drivers/media/usb/tlg2300/pd-main.c16
-rw-r--r--drivers/media/usb/tlg2300/pd-radio.c229
-rw-r--r--drivers/media/usb/tlg2300/pd-video.c303
-rw-r--r--drivers/media/usb/tm6000/tm6000-video.c16
-rw-r--r--drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c10
-rw-r--r--drivers/media/usb/ttusb-dec/ttusb_dec.c20
-rw-r--r--drivers/media/usb/usbvision/usbvision-video.c10
-rw-r--r--drivers/media/usb/uvc/uvc_ctrl.c2
-rw-r--r--drivers/media/usb/uvc/uvc_queue.c1
-rw-r--r--drivers/media/v4l2-core/Kconfig1
-rw-r--r--drivers/media/v4l2-core/Makefile3
-rw-r--r--drivers/media/v4l2-core/tuner-core.c72
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c54
-rw-r--r--drivers/media/v4l2-core/v4l2-compat-ioctl32.c4
-rw-r--r--drivers/media/v4l2-core/v4l2-ctrls.c25
-rw-r--r--drivers/media/v4l2-core/v4l2-dev.c9
-rw-r--r--drivers/media/v4l2-core/v4l2-ioctl.c219
-rw-r--r--drivers/media/v4l2-core/v4l2-mem2mem.c34
-rw-r--r--drivers/media/v4l2-core/v4l2-of.c266
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-contig.c130
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c32
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-contig.c8
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-sg.c25
-rw-r--r--drivers/media/v4l2-core/videobuf2-vmalloc.c4
-rw-r--r--drivers/of/base.c1
-rw-r--r--drivers/staging/media/as102/Makefile2
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe.c2
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif.c3
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.c4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c2
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c24
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_video.c18
-rw-r--r--drivers/staging/media/dt3155v4l/dt3155v4l.c11
-rw-r--r--drivers/staging/media/go7007/Kconfig103
-rw-r--r--drivers/staging/media/go7007/Makefile23
-rw-r--r--drivers/staging/media/go7007/README142
-rw-r--r--drivers/staging/media/go7007/go7007-driver.c390
-rw-r--r--drivers/staging/media/go7007/go7007-fw.c88
-rw-r--r--drivers/staging/media/go7007/go7007-i2c.c21
-rw-r--r--drivers/staging/media/go7007/go7007-loader.c144
-rw-r--r--drivers/staging/media/go7007/go7007-priv.h104
-rw-r--r--drivers/staging/media/go7007/go7007-usb.c394
-rw-r--r--drivers/staging/media/go7007/go7007-v4l2.c1747
-rw-r--r--drivers/staging/media/go7007/go7007.h74
-rw-r--r--drivers/staging/media/go7007/s2250-board.c171
-rw-r--r--drivers/staging/media/go7007/s2250-loader.c169
-rw-r--r--drivers/staging/media/go7007/s2250-loader.h24
-rw-r--r--drivers/staging/media/go7007/saa7134-go7007.c171
-rw-r--r--drivers/staging/media/go7007/snd-go7007.c11
-rw-r--r--drivers/staging/media/go7007/wis-i2c.h42
-rw-r--r--drivers/staging/media/go7007/wis-saa7113.c324
-rw-r--r--drivers/staging/media/go7007/wis-saa7115.c457
-rw-r--r--drivers/staging/media/go7007/wis-sony-tuner.c707
-rw-r--r--drivers/staging/media/go7007/wis-tw2804.c348
-rw-r--r--drivers/staging/media/go7007/wis-tw9903.c328
-rw-r--r--drivers/staging/media/lirc/lirc_sir.c10
-rw-r--r--drivers/staging/media/solo6x10/Kconfig3
-rw-r--r--drivers/staging/media/solo6x10/Makefile4
-rw-r--r--drivers/staging/media/solo6x10/TODO39
-rw-r--r--drivers/staging/media/solo6x10/core.c321
-rw-r--r--drivers/staging/media/solo6x10/offsets.h74
-rw-r--r--drivers/staging/media/solo6x10/osd-font.h154
-rw-r--r--drivers/staging/media/solo6x10/p2m.c306
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-core.c709
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-disp.c (renamed from drivers/staging/media/solo6x10/disp.c)129
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-eeprom.c154
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-enc.c (renamed from drivers/staging/media/solo6x10/enc.c)239
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-g723.c (renamed from drivers/staging/media/solo6x10/g723.c)94
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-gpio.c (renamed from drivers/staging/media/solo6x10/gpio.c)13
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-i2c.c (renamed from drivers/staging/media/solo6x10/i2c.c)26
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-jpeg.h94
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-offsets.h85
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-p2m.c333
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-regs.h (renamed from drivers/staging/media/solo6x10/registers.h)88
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-tw28.c (renamed from drivers/staging/media/solo6x10/tw28.c)187
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-tw28.h (renamed from drivers/staging/media/solo6x10/tw28.h)12
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c1385
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-v4l2.c734
-rw-r--r--drivers/staging/media/solo6x10/solo6x10.h265
-rw-r--r--drivers/staging/media/solo6x10/v4l2-enc.c1829
-rw-r--r--drivers/staging/media/solo6x10/v4l2.c961
584 files changed, 38253 insertions, 27890 deletions
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index 56c25e6299e9..b85f88c8ddbd 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -16,6 +16,10 @@ config VIDEO_TVEEPROM
16 tristate 16 tristate
17 depends on I2C 17 depends on I2C
18 18
19config CYPRESS_FIRMWARE
20 tristate "Cypress firmware helper routines"
21 depends on USB
22
19source "drivers/media/common/b2c2/Kconfig" 23source "drivers/media/common/b2c2/Kconfig"
20source "drivers/media/common/saa7146/Kconfig" 24source "drivers/media/common/saa7146/Kconfig"
21source "drivers/media/common/siano/Kconfig" 25source "drivers/media/common/siano/Kconfig"
diff --git a/drivers/media/common/Makefile b/drivers/media/common/Makefile
index 8f8d18755d15..d208de3b7cc0 100644
--- a/drivers/media/common/Makefile
+++ b/drivers/media/common/Makefile
@@ -2,3 +2,4 @@ obj-y += b2c2/ saa7146/ siano/
2obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o 2obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
3obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o 3obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
4obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o 4obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
5obj-$(CONFIG_CYPRESS_FIRMWARE) += cypress_firmware.o
diff --git a/drivers/media/common/b2c2/flexcop-fe-tuner.c b/drivers/media/common/b2c2/flexcop-fe-tuner.c
index 850a6c606750..7e14e90d2922 100644
--- a/drivers/media/common/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/common/b2c2/flexcop-fe-tuner.c
@@ -325,7 +325,7 @@ static int skystar2_rev27_attach(struct flexcop_device *fc,
325 /* enable no_base_addr - no repeated start when reading */ 325 /* enable no_base_addr - no repeated start when reading */
326 fc->fc_i2c_adap[2].no_base_addr = 1; 326 fc->fc_i2c_adap[2].no_base_addr = 1;
327 if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap, 327 if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
328 0x08, 1, 1)) { 328 0x08, 1, 1, false)) {
329 err("ISL6421 could NOT be attached"); 329 err("ISL6421 could NOT be attached");
330 goto fail_isl; 330 goto fail_isl;
331 } 331 }
@@ -391,7 +391,7 @@ static int skystar2_rev28_attach(struct flexcop_device *fc,
391 391
392 fc->fc_i2c_adap[2].no_base_addr = 1; 392 fc->fc_i2c_adap[2].no_base_addr = 1;
393 if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap, 393 if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
394 0x08, 0, 0)) { 394 0x08, 0, 0, false)) {
395 err("ISL6421 could NOT be attached"); 395 err("ISL6421 could NOT be attached");
396 fc->fc_i2c_adap[2].no_base_addr = 0; 396 fc->fc_i2c_adap[2].no_base_addr = 0;
397 return 0; 397 return 0;
diff --git a/drivers/media/usb/dvb-usb-v2/cypress_firmware.c b/drivers/media/common/cypress_firmware.c
index 211df549f26a..577e82058fdc 100644
--- a/drivers/media/usb/dvb-usb-v2/cypress_firmware.c
+++ b/drivers/media/common/cypress_firmware.c
@@ -8,7 +8,10 @@
8 * 8 *
9 */ 9 */
10 10
11#include "dvb_usb.h" 11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/usb.h>
14#include <linux/firmware.h>
12#include "cypress_firmware.h" 15#include "cypress_firmware.h"
13 16
14struct usb_cypress_controller { 17struct usb_cypress_controller {
@@ -30,14 +33,42 @@ static const struct usb_cypress_controller cypress[] = {
30static int usb_cypress_writemem(struct usb_device *udev, u16 addr, u8 *data, 33static int usb_cypress_writemem(struct usb_device *udev, u16 addr, u8 *data,
31 u8 len) 34 u8 len)
32{ 35{
33 dvb_usb_dbg_usb_control_msg(udev,
34 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len);
35
36 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 36 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
37 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5000); 37 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5000);
38} 38}
39 39
40int usbv2_cypress_load_firmware(struct usb_device *udev, 40static int cypress_get_hexline(const struct firmware *fw,
41 struct hexline *hx, int *pos)
42{
43 u8 *b = (u8 *) &fw->data[*pos];
44 int data_offs = 4;
45
46 if (*pos >= fw->size)
47 return 0;
48
49 memset(hx, 0, sizeof(struct hexline));
50 hx->len = b[0];
51
52 if ((*pos + hx->len + 4) >= fw->size)
53 return -EINVAL;
54
55 hx->addr = b[1] | (b[2] << 8);
56 hx->type = b[3];
57
58 if (hx->type == 0x04) {
59 /* b[4] and b[5] are the Extended linear address record data
60 * field */
61 hx->addr |= (b[4] << 24) | (b[5] << 16);
62 }
63
64 memcpy(hx->data, &b[data_offs], hx->len);
65 hx->chk = b[hx->len + data_offs];
66 *pos += hx->len + 5;
67
68 return *pos;
69}
70
71int cypress_load_firmware(struct usb_device *udev,
41 const struct firmware *fw, int type) 72 const struct firmware *fw, int type)
42{ 73{
43 struct hexline *hx; 74 struct hexline *hx;
@@ -61,7 +92,7 @@ int usbv2_cypress_load_firmware(struct usb_device *udev,
61 92
62 /* write firmware to memory */ 93 /* write firmware to memory */
63 for (;;) { 94 for (;;) {
64 ret = dvb_usbv2_get_hexline(fw, hx, &pos); 95 ret = cypress_get_hexline(fw, hx, &pos);
65 if (ret < 0) 96 if (ret < 0)
66 goto err_kfree; 97 goto err_kfree;
67 else if (ret == 0) 98 else if (ret == 0)
@@ -71,9 +102,8 @@ int usbv2_cypress_load_firmware(struct usb_device *udev,
71 if (ret < 0) { 102 if (ret < 0) {
72 goto err_kfree; 103 goto err_kfree;
73 } else if (ret != hx->len) { 104 } else if (ret != hx->len) {
74 dev_err(&udev->dev, "%s: error while transferring " \ 105 dev_err(&udev->dev,
75 "firmware (transferred size=%d, " \ 106 "%s: error while transferring firmware (transferred size=%d, block size=%d)\n",
76 "block size=%d)\n",
77 KBUILD_MODNAME, ret, hx->len); 107 KBUILD_MODNAME, ret, hx->len);
78 ret = -EIO; 108 ret = -EIO;
79 goto err_kfree; 109 goto err_kfree;
@@ -95,39 +125,7 @@ err_kfree:
95 kfree(hx); 125 kfree(hx);
96 return ret; 126 return ret;
97} 127}
98EXPORT_SYMBOL(usbv2_cypress_load_firmware); 128EXPORT_SYMBOL(cypress_load_firmware);
99
100int dvb_usbv2_get_hexline(const struct firmware *fw, struct hexline *hx,
101 int *pos)
102{
103 u8 *b = (u8 *) &fw->data[*pos];
104 int data_offs = 4;
105
106 if (*pos >= fw->size)
107 return 0;
108
109 memset(hx, 0, sizeof(struct hexline));
110 hx->len = b[0];
111
112 if ((*pos + hx->len + 4) >= fw->size)
113 return -EINVAL;
114
115 hx->addr = b[1] | (b[2] << 8);
116 hx->type = b[3];
117
118 if (hx->type == 0x04) {
119 /* b[4] and b[5] are the Extended linear address record data
120 * field */
121 hx->addr |= (b[4] << 24) | (b[5] << 16);
122 }
123
124 memcpy(hx->data, &b[data_offs], hx->len);
125 hx->chk = b[hx->len + data_offs];
126 *pos += hx->len + 5;
127
128 return *pos;
129}
130EXPORT_SYMBOL(dvb_usbv2_get_hexline);
131 129
132MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 130MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
133MODULE_DESCRIPTION("Cypress firmware download"); 131MODULE_DESCRIPTION("Cypress firmware download");
diff --git a/drivers/media/usb/dvb-usb-v2/cypress_firmware.h b/drivers/media/common/cypress_firmware.h
index 80085fd4132c..e493cbc7a528 100644
--- a/drivers/media/usb/dvb-usb-v2/cypress_firmware.h
+++ b/drivers/media/common/cypress_firmware.h
@@ -1,5 +1,4 @@
1/* cypress_firmware.h is part of the DVB USB library. 1/*
2 *
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de) 2 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information. 3 * see dvb-usb-init.c for copyright information.
5 * 4 *
@@ -23,9 +22,7 @@ struct hexline {
23 u8 data[255]; 22 u8 data[255];
24 u8 chk; 23 u8 chk;
25}; 24};
26extern int usbv2_cypress_load_firmware(struct usb_device *, 25
27 const struct firmware *, int); 26int cypress_load_firmware(struct usb_device *, const struct firmware *, int);
28extern int dvb_usbv2_get_hexline(const struct firmware *,
29 struct hexline *, int *);
30 27
31#endif 28#endif
diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
index 4143d61f79b1..fe907f2e8f59 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -832,7 +832,7 @@ static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
832 } 832 }
833 */ 833 */
834 834
835static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id) 835static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id id)
836{ 836{
837 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 837 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
838 struct saa7146_vv *vv = dev->vv_data; 838 struct saa7146_vv *vv = dev->vv_data;
@@ -856,7 +856,7 @@ static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id)
856 } 856 }
857 857
858 for (i = 0; i < dev->ext_vv_data->num_stds; i++) 858 for (i = 0; i < dev->ext_vv_data->num_stds; i++)
859 if (*id & dev->ext_vv_data->stds[i].id) 859 if (id & dev->ext_vv_data->stds[i].id)
860 break; 860 break;
861 if (i != dev->ext_vv_data->num_stds) { 861 if (i != dev->ext_vv_data->num_stds) {
862 vv->standard = &dev->ext_vv_data->stds[i]; 862 vv->standard = &dev->ext_vv_data->stds[i];
diff --git a/drivers/media/common/siano/Kconfig b/drivers/media/common/siano/Kconfig
index 68f0f604678e..f3f5ec44e685 100644
--- a/drivers/media/common/siano/Kconfig
+++ b/drivers/media/common/siano/Kconfig
@@ -17,3 +17,15 @@ config SMS_SIANO_RC
17 default y 17 default y
18 ---help--- 18 ---help---
19 Choose Y to select Remote Controller support for Siano driver. 19 Choose Y to select Remote Controller support for Siano driver.
20
21config SMS_SIANO_DEBUGFS
22 bool "Enable debugfs for smsdvb"
23 depends on SMS_SIANO_MDTV
24 depends on DEBUG_FS
25 depends on SMS_USB_DRV
26 ---help---
27 Choose Y to enable visualizing a dump of the frontend
28 statistics response packets via debugfs. Currently, works
29 only with Siano USB devices.
30
31 Useful only for developers. In doubt, say N.
diff --git a/drivers/media/common/siano/Makefile b/drivers/media/common/siano/Makefile
index 81b1e985bea5..4c0567f106b2 100644
--- a/drivers/media/common/siano/Makefile
+++ b/drivers/media/common/siano/Makefile
@@ -1,4 +1,5 @@
1smsmdtv-objs := smscoreapi.o sms-cards.o smsendian.o 1smsmdtv-objs := smscoreapi.o sms-cards.o smsendian.o
2smsdvb-objs := smsdvb-main.o
2 3
3obj-$(CONFIG_SMS_SIANO_MDTV) += smsmdtv.o smsdvb.o 4obj-$(CONFIG_SMS_SIANO_MDTV) += smsmdtv.o smsdvb.o
4 5
@@ -6,6 +7,10 @@ ifeq ($(CONFIG_SMS_SIANO_RC),y)
6 smsmdtv-objs += smsir.o 7 smsmdtv-objs += smsir.o
7endif 8endif
8 9
10ifeq ($(CONFIG_SMS_SIANO_DEBUGFS),y)
11 smsdvb-objs += smsdvb-debugfs.o
12endif
13
9ccflags-y += -Idrivers/media/dvb-core 14ccflags-y += -Idrivers/media/dvb-core
10ccflags-y += $(extra-cflags-y) $(extra-cflags-m) 15ccflags-y += $(extra-cflags-y) $(extra-cflags-m)
11 16
diff --git a/drivers/media/common/siano/sms-cards.c b/drivers/media/common/siano/sms-cards.c
index 680c781c8dd6..82769993eeb7 100644
--- a/drivers/media/common/siano/sms-cards.c
+++ b/drivers/media/common/siano/sms-cards.c
@@ -28,43 +28,53 @@ MODULE_PARM_DESC(cards_dbg, "set debug level (info=1, adv=2 (or-able))");
28static struct sms_board sms_boards[] = { 28static struct sms_board sms_boards[] = {
29 [SMS_BOARD_UNKNOWN] = { 29 [SMS_BOARD_UNKNOWN] = {
30 .name = "Unknown board", 30 .name = "Unknown board",
31 .type = SMS_UNKNOWN_TYPE,
32 .default_mode = DEVICE_MODE_NONE,
31 }, 33 },
32 [SMS1XXX_BOARD_SIANO_STELLAR] = { 34 [SMS1XXX_BOARD_SIANO_STELLAR] = {
33 .name = "Siano Stellar Digital Receiver", 35 .name = "Siano Stellar Digital Receiver",
34 .type = SMS_STELLAR, 36 .type = SMS_STELLAR,
37 .default_mode = DEVICE_MODE_DVBT_BDA,
35 }, 38 },
36 [SMS1XXX_BOARD_SIANO_NOVA_A] = { 39 [SMS1XXX_BOARD_SIANO_NOVA_A] = {
37 .name = "Siano Nova A Digital Receiver", 40 .name = "Siano Nova A Digital Receiver",
38 .type = SMS_NOVA_A0, 41 .type = SMS_NOVA_A0,
42 .default_mode = DEVICE_MODE_DVBT_BDA,
39 }, 43 },
40 [SMS1XXX_BOARD_SIANO_NOVA_B] = { 44 [SMS1XXX_BOARD_SIANO_NOVA_B] = {
41 .name = "Siano Nova B Digital Receiver", 45 .name = "Siano Nova B Digital Receiver",
42 .type = SMS_NOVA_B0, 46 .type = SMS_NOVA_B0,
47 .default_mode = DEVICE_MODE_DVBT_BDA,
43 }, 48 },
44 [SMS1XXX_BOARD_SIANO_VEGA] = { 49 [SMS1XXX_BOARD_SIANO_VEGA] = {
45 .name = "Siano Vega Digital Receiver", 50 .name = "Siano Vega Digital Receiver",
46 .type = SMS_VEGA, 51 .type = SMS_VEGA,
52 .default_mode = DEVICE_MODE_CMMB,
47 }, 53 },
48 [SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = { 54 [SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = {
49 .name = "Hauppauge Catamount", 55 .name = "Hauppauge Catamount",
50 .type = SMS_STELLAR, 56 .type = SMS_STELLAR,
51 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-stellar-dvbt-01.fw", 57 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_STELLAR,
58 .default_mode = DEVICE_MODE_DVBT_BDA,
52 }, 59 },
53 [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = { 60 [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = {
54 .name = "Hauppauge Okemo-A", 61 .name = "Hauppauge Okemo-A",
55 .type = SMS_NOVA_A0, 62 .type = SMS_NOVA_A0,
56 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-a-dvbt-01.fw", 63 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_A,
64 .default_mode = DEVICE_MODE_DVBT_BDA,
57 }, 65 },
58 [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = { 66 [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = {
59 .name = "Hauppauge Okemo-B", 67 .name = "Hauppauge Okemo-B",
60 .type = SMS_NOVA_B0, 68 .type = SMS_NOVA_B0,
61 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-b-dvbt-01.fw", 69 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_B,
70 .default_mode = DEVICE_MODE_DVBT_BDA,
62 }, 71 },
63 [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = { 72 [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
64 .name = "Hauppauge WinTV MiniStick", 73 .name = "Hauppauge WinTV MiniStick",
65 .type = SMS_NOVA_B0, 74 .type = SMS_NOVA_B0,
66 .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw", 75 .fw[DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_HCW_55XXX,
67 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 76 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
77 .default_mode = DEVICE_MODE_DVBT_BDA,
68 .rc_codes = RC_MAP_HAUPPAUGE, 78 .rc_codes = RC_MAP_HAUPPAUGE,
69 .board_cfg.leds_power = 26, 79 .board_cfg.leds_power = 26,
70 .board_cfg.led0 = 27, 80 .board_cfg.led0 = 27,
@@ -77,7 +87,8 @@ static struct sms_board sms_boards[] = {
77 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = { 87 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = {
78 .name = "Hauppauge WinTV MiniCard", 88 .name = "Hauppauge WinTV MiniCard",
79 .type = SMS_NOVA_B0, 89 .type = SMS_NOVA_B0,
80 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 90 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
91 .default_mode = DEVICE_MODE_DVBT_BDA,
81 .lna_ctrl = 29, 92 .lna_ctrl = 29,
82 .board_cfg.foreign_lna0_ctrl = 29, 93 .board_cfg.foreign_lna0_ctrl = 29,
83 .rf_switch = 17, 94 .rf_switch = 17,
@@ -86,18 +97,65 @@ static struct sms_board sms_boards[] = {
86 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = { 97 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
87 .name = "Hauppauge WinTV MiniCard", 98 .name = "Hauppauge WinTV MiniCard",
88 .type = SMS_NOVA_B0, 99 .type = SMS_NOVA_B0,
89 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 100 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
101 .default_mode = DEVICE_MODE_DVBT_BDA,
90 .lna_ctrl = -1, 102 .lna_ctrl = -1,
91 }, 103 },
92 [SMS1XXX_BOARD_SIANO_NICE] = { 104 [SMS1XXX_BOARD_SIANO_NICE] = {
93 /* 11 */
94 .name = "Siano Nice Digital Receiver", 105 .name = "Siano Nice Digital Receiver",
95 .type = SMS_NOVA_B0, 106 .type = SMS_NOVA_B0,
107 .default_mode = DEVICE_MODE_DVBT_BDA,
96 }, 108 },
97 [SMS1XXX_BOARD_SIANO_VENICE] = { 109 [SMS1XXX_BOARD_SIANO_VENICE] = {
98 /* 12 */
99 .name = "Siano Venice Digital Receiver", 110 .name = "Siano Venice Digital Receiver",
100 .type = SMS_VEGA, 111 .type = SMS_VEGA,
112 .default_mode = DEVICE_MODE_CMMB,
113 },
114 [SMS1XXX_BOARD_SIANO_STELLAR_ROM] = {
115 .name = "Siano Stellar Digital Receiver ROM",
116 .type = SMS_STELLAR,
117 .default_mode = DEVICE_MODE_DVBT_BDA,
118 .intf_num = 1,
119 },
120 [SMS1XXX_BOARD_ZTE_DVB_DATA_CARD] = {
121 .name = "ZTE Data Card Digital Receiver",
122 .type = SMS_NOVA_B0,
123 .default_mode = DEVICE_MODE_DVBT_BDA,
124 .intf_num = 5,
125 .mtu = 15792,
126 },
127 [SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD] = {
128 .name = "ONDA Data Card Digital Receiver",
129 .type = SMS_NOVA_B0,
130 .default_mode = DEVICE_MODE_DVBT_BDA,
131 .intf_num = 6,
132 .mtu = 15792,
133 },
134 [SMS1XXX_BOARD_SIANO_MING] = {
135 .name = "Siano Ming Digital Receiver",
136 .type = SMS_MING,
137 .default_mode = DEVICE_MODE_CMMB,
138 },
139 [SMS1XXX_BOARD_SIANO_PELE] = {
140 .name = "Siano Pele Digital Receiver",
141 .type = SMS_PELE,
142 .default_mode = DEVICE_MODE_ISDBT_BDA,
143 },
144 [SMS1XXX_BOARD_SIANO_RIO] = {
145 .name = "Siano Rio Digital Receiver",
146 .type = SMS_RIO,
147 .default_mode = DEVICE_MODE_ISDBT_BDA,
148 },
149 [SMS1XXX_BOARD_SIANO_DENVER_1530] = {
150 .name = "Siano Denver (ATSC-M/H) Digital Receiver",
151 .type = SMS_DENVER_1530,
152 .default_mode = DEVICE_MODE_ATSC,
153 .crystal = 2400,
154 },
155 [SMS1XXX_BOARD_SIANO_DENVER_2160] = {
156 .name = "Siano Denver (TDMB) Digital Receiver",
157 .type = SMS_DENVER_2160,
158 .default_mode = DEVICE_MODE_DAB_TDMB,
101 }, 159 },
102}; 160};
103 161
@@ -109,20 +167,21 @@ struct sms_board *sms_get_board(unsigned id)
109} 167}
110EXPORT_SYMBOL_GPL(sms_get_board); 168EXPORT_SYMBOL_GPL(sms_get_board);
111static inline void sms_gpio_assign_11xx_default_led_config( 169static inline void sms_gpio_assign_11xx_default_led_config(
112 struct smscore_gpio_config *pGpioConfig) { 170 struct smscore_config_gpio *p_gpio_config) {
113 pGpioConfig->Direction = SMS_GPIO_DIRECTION_OUTPUT; 171 p_gpio_config->direction = SMS_GPIO_DIRECTION_OUTPUT;
114 pGpioConfig->InputCharacteristics = 172 p_gpio_config->inputcharacteristics =
115 SMS_GPIO_INPUT_CHARACTERISTICS_NORMAL; 173 SMS_GPIO_INPUTCHARACTERISTICS_NORMAL;
116 pGpioConfig->OutputDriving = SMS_GPIO_OUTPUT_DRIVING_4mA; 174 p_gpio_config->outputdriving = SMS_GPIO_OUTPUTDRIVING_4mA;
117 pGpioConfig->OutputSlewRate = SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS; 175 p_gpio_config->outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS;
118 pGpioConfig->PullUpDown = SMS_GPIO_PULL_UP_DOWN_NONE; 176 p_gpio_config->pullupdown = SMS_GPIO_PULLUPDOWN_NONE;
119} 177}
120 178
121int sms_board_event(struct smscore_device_t *coredev, 179int sms_board_event(struct smscore_device_t *coredev,
122 enum SMS_BOARD_EVENTS gevent) { 180 enum SMS_BOARD_EVENTS gevent)
123 struct smscore_gpio_config MyGpioConfig; 181{
182 struct smscore_config_gpio my_gpio_config;
124 183
125 sms_gpio_assign_11xx_default_led_config(&MyGpioConfig); 184 sms_gpio_assign_11xx_default_led_config(&my_gpio_config);
126 185
127 switch (gevent) { 186 switch (gevent) {
128 case BOARD_EVENT_POWER_INIT: /* including hotplug */ 187 case BOARD_EVENT_POWER_INIT: /* including hotplug */
@@ -182,8 +241,8 @@ static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
182 .direction = SMS_GPIO_DIRECTION_OUTPUT, 241 .direction = SMS_GPIO_DIRECTION_OUTPUT,
183 .pullupdown = SMS_GPIO_PULLUPDOWN_NONE, 242 .pullupdown = SMS_GPIO_PULLUPDOWN_NONE,
184 .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL, 243 .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
185 .outputslewrate = SMS_GPIO_OUTPUTSLEWRATE_FAST, 244 .outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_FAST,
186 .outputdriving = SMS_GPIO_OUTPUTDRIVING_4mA, 245 .outputdriving = SMS_GPIO_OUTPUTDRIVING_S_4mA,
187 }; 246 };
188 247
189 if (pin == 0) 248 if (pin == 0)
@@ -293,19 +352,7 @@ EXPORT_SYMBOL_GPL(sms_board_lna_control);
293 352
294int sms_board_load_modules(int id) 353int sms_board_load_modules(int id)
295{ 354{
296 switch (id) { 355 request_module("smsdvb");
297 case SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT:
298 case SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A:
299 case SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B:
300 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
301 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
302 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
303 request_module("smsdvb");
304 break;
305 default:
306 /* do nothing */
307 break;
308 }
309 return 0; 356 return 0;
310} 357}
311EXPORT_SYMBOL_GPL(sms_board_load_modules); 358EXPORT_SYMBOL_GPL(sms_board_load_modules);
diff --git a/drivers/media/common/siano/sms-cards.h b/drivers/media/common/siano/sms-cards.h
index d8cdf756f7cf..c63b544c49c5 100644
--- a/drivers/media/common/siano/sms-cards.h
+++ b/drivers/media/common/siano/sms-cards.h
@@ -37,6 +37,14 @@
37#define SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 10 37#define SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 10
38#define SMS1XXX_BOARD_SIANO_NICE 11 38#define SMS1XXX_BOARD_SIANO_NICE 11
39#define SMS1XXX_BOARD_SIANO_VENICE 12 39#define SMS1XXX_BOARD_SIANO_VENICE 12
40#define SMS1XXX_BOARD_SIANO_STELLAR_ROM 13
41#define SMS1XXX_BOARD_ZTE_DVB_DATA_CARD 14
42#define SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD 15
43#define SMS1XXX_BOARD_SIANO_MING 16
44#define SMS1XXX_BOARD_SIANO_PELE 17
45#define SMS1XXX_BOARD_SIANO_RIO 18
46#define SMS1XXX_BOARD_SIANO_DENVER_1530 19
47#define SMS1XXX_BOARD_SIANO_DENVER_2160 20
40 48
41struct sms_board_gpio_cfg { 49struct sms_board_gpio_cfg {
42 int lna_vhf_exist; 50 int lna_vhf_exist;
@@ -79,6 +87,12 @@ struct sms_board {
79 87
80 /* gpios */ 88 /* gpios */
81 int led_power, led_hi, led_lo, lna_ctrl, rf_switch; 89 int led_power, led_hi, led_lo, lna_ctrl, rf_switch;
90
91 char intf_num;
92 int default_mode;
93 unsigned int mtu;
94 unsigned int crystal;
95 struct sms_antenna_config_ST *antenna_config;
82}; 96};
83 97
84struct sms_board *sms_get_board(unsigned id); 98struct sms_board *sms_get_board(unsigned id);
diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c
index 1842e64e6338..45ac9eea4882 100644
--- a/drivers/media/common/siano/smscoreapi.c
+++ b/drivers/media/common/siano/smscoreapi.c
@@ -37,7 +37,6 @@
37#include "smscoreapi.h" 37#include "smscoreapi.h"
38#include "sms-cards.h" 38#include "sms-cards.h"
39#include "smsir.h" 39#include "smsir.h"
40#include "smsendian.h"
41 40
42static int sms_dbg; 41static int sms_dbg;
43module_param_named(debug, sms_dbg, int, 0644); 42module_param_named(debug, sms_dbg, int, 0644);
@@ -58,11 +57,350 @@ struct smscore_client_t {
58 struct list_head entry; 57 struct list_head entry;
59 struct smscore_device_t *coredev; 58 struct smscore_device_t *coredev;
60 void *context; 59 void *context;
61 struct list_head idlist; 60 struct list_head idlist;
62 onresponse_t onresponse_handler; 61 onresponse_t onresponse_handler;
63 onremove_t onremove_handler; 62 onremove_t onremove_handler;
64}; 63};
65 64
65static char *siano_msgs[] = {
66 [MSG_TYPE_BASE_VAL - MSG_TYPE_BASE_VAL] = "MSG_TYPE_BASE_VAL",
67 [MSG_SMS_GET_VERSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_REQ",
68 [MSG_SMS_GET_VERSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_RES",
69 [MSG_SMS_MULTI_BRIDGE_CFG - MSG_TYPE_BASE_VAL] = "MSG_SMS_MULTI_BRIDGE_CFG",
70 [MSG_SMS_GPIO_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_REQ",
71 [MSG_SMS_GPIO_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_RES",
72 [MSG_SMS_GPIO_SET_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_SET_LEVEL_REQ",
73 [MSG_SMS_GPIO_SET_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_SET_LEVEL_RES",
74 [MSG_SMS_GPIO_GET_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_GET_LEVEL_REQ",
75 [MSG_SMS_GPIO_GET_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_GET_LEVEL_RES",
76 [MSG_SMS_EEPROM_BURN_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_BURN_IND",
77 [MSG_SMS_LOG_ENABLE_CHANGE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ENABLE_CHANGE_REQ",
78 [MSG_SMS_LOG_ENABLE_CHANGE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ENABLE_CHANGE_RES",
79 [MSG_SMS_SET_MAX_TX_MSG_LEN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_MAX_TX_MSG_LEN_REQ",
80 [MSG_SMS_SET_MAX_TX_MSG_LEN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_MAX_TX_MSG_LEN_RES",
81 [MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE",
82 [MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST",
83 [MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ",
84 [MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES",
85 [MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND",
86 [MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND",
87 [MSG_SMS_CONFIGURE_RF_SWITCH_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIGURE_RF_SWITCH_REQ",
88 [MSG_SMS_CONFIGURE_RF_SWITCH_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIGURE_RF_SWITCH_RES",
89 [MSG_SMS_MRC_PATH_DISCONNECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_PATH_DISCONNECT_REQ",
90 [MSG_SMS_MRC_PATH_DISCONNECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_PATH_DISCONNECT_RES",
91 [MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ",
92 [MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES",
93 [MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ",
94 [MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES",
95 [MSG_WR_REG_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_WR_REG_RFT_REQ",
96 [MSG_WR_REG_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_WR_REG_RFT_RES",
97 [MSG_RD_REG_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_RFT_REQ",
98 [MSG_RD_REG_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_RFT_RES",
99 [MSG_RD_REG_ALL_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_ALL_RFT_REQ",
100 [MSG_RD_REG_ALL_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_ALL_RFT_RES",
101 [MSG_HELP_INT - MSG_TYPE_BASE_VAL] = "MSG_HELP_INT",
102 [MSG_RUN_SCRIPT_INT - MSG_TYPE_BASE_VAL] = "MSG_RUN_SCRIPT_INT",
103 [MSG_SMS_EWS_INBAND_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EWS_INBAND_REQ",
104 [MSG_SMS_EWS_INBAND_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EWS_INBAND_RES",
105 [MSG_SMS_RFS_SELECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RFS_SELECT_REQ",
106 [MSG_SMS_RFS_SELECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RFS_SELECT_RES",
107 [MSG_SMS_MB_GET_VER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_GET_VER_REQ",
108 [MSG_SMS_MB_GET_VER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_GET_VER_RES",
109 [MSG_SMS_MB_WRITE_CFGFILE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_WRITE_CFGFILE_REQ",
110 [MSG_SMS_MB_WRITE_CFGFILE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_WRITE_CFGFILE_RES",
111 [MSG_SMS_MB_READ_CFGFILE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_READ_CFGFILE_REQ",
112 [MSG_SMS_MB_READ_CFGFILE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_READ_CFGFILE_RES",
113 [MSG_SMS_RD_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RD_MEM_REQ",
114 [MSG_SMS_RD_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RD_MEM_RES",
115 [MSG_SMS_WR_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_WR_MEM_REQ",
116 [MSG_SMS_WR_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_WR_MEM_RES",
117 [MSG_SMS_UPDATE_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_UPDATE_MEM_REQ",
118 [MSG_SMS_UPDATE_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_UPDATE_MEM_RES",
119 [MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ",
120 [MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES",
121 [MSG_SMS_RF_TUNE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RF_TUNE_REQ",
122 [MSG_SMS_RF_TUNE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RF_TUNE_RES",
123 [MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ",
124 [MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES",
125 [MSG_SMS_ISDBT_SB_RECEPTION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_SB_RECEPTION_REQ",
126 [MSG_SMS_ISDBT_SB_RECEPTION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_SB_RECEPTION_RES",
127 [MSG_SMS_GENERIC_EPROM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_WRITE_REQ",
128 [MSG_SMS_GENERIC_EPROM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_WRITE_RES",
129 [MSG_SMS_GENERIC_EPROM_READ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_READ_REQ",
130 [MSG_SMS_GENERIC_EPROM_READ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_READ_RES",
131 [MSG_SMS_EEPROM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_WRITE_REQ",
132 [MSG_SMS_EEPROM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_WRITE_RES",
133 [MSG_SMS_CUSTOM_READ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_READ_REQ",
134 [MSG_SMS_CUSTOM_READ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_READ_RES",
135 [MSG_SMS_CUSTOM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_WRITE_REQ",
136 [MSG_SMS_CUSTOM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_WRITE_RES",
137 [MSG_SMS_INIT_DEVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_INIT_DEVICE_REQ",
138 [MSG_SMS_INIT_DEVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_INIT_DEVICE_RES",
139 [MSG_SMS_ATSC_SET_ALL_IP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SET_ALL_IP_REQ",
140 [MSG_SMS_ATSC_SET_ALL_IP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SET_ALL_IP_RES",
141 [MSG_SMS_ATSC_START_ENSEMBLE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_START_ENSEMBLE_REQ",
142 [MSG_SMS_ATSC_START_ENSEMBLE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_START_ENSEMBLE_RES",
143 [MSG_SMS_SET_OUTPUT_MODE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_OUTPUT_MODE_REQ",
144 [MSG_SMS_SET_OUTPUT_MODE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_OUTPUT_MODE_RES",
145 [MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ",
146 [MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES",
147 [MSG_SMS_SUB_CHANNEL_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_START_REQ",
148 [MSG_SMS_SUB_CHANNEL_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_START_RES",
149 [MSG_SMS_SUB_CHANNEL_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_STOP_REQ",
150 [MSG_SMS_SUB_CHANNEL_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_STOP_RES",
151 [MSG_SMS_ATSC_IP_FILTER_ADD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_ADD_REQ",
152 [MSG_SMS_ATSC_IP_FILTER_ADD_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_ADD_RES",
153 [MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ",
154 [MSG_SMS_ATSC_IP_FILTER_REMOVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_RES",
155 [MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ",
156 [MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES",
157 [MSG_SMS_WAIT_CMD - MSG_TYPE_BASE_VAL] = "MSG_SMS_WAIT_CMD",
158 [MSG_SMS_ADD_PID_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ADD_PID_FILTER_REQ",
159 [MSG_SMS_ADD_PID_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ADD_PID_FILTER_RES",
160 [MSG_SMS_REMOVE_PID_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_REMOVE_PID_FILTER_REQ",
161 [MSG_SMS_REMOVE_PID_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_REMOVE_PID_FILTER_RES",
162 [MSG_SMS_FAST_INFORMATION_CHANNEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_FAST_INFORMATION_CHANNEL_REQ",
163 [MSG_SMS_FAST_INFORMATION_CHANNEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_FAST_INFORMATION_CHANNEL_RES",
164 [MSG_SMS_DAB_CHANNEL - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_CHANNEL",
165 [MSG_SMS_GET_PID_FILTER_LIST_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_PID_FILTER_LIST_REQ",
166 [MSG_SMS_GET_PID_FILTER_LIST_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_PID_FILTER_LIST_RES",
167 [MSG_SMS_POWER_DOWN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_REQ",
168 [MSG_SMS_POWER_DOWN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_RES",
169 [MSG_SMS_ATSC_SLT_EXIST_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SLT_EXIST_IND",
170 [MSG_SMS_ATSC_NO_SLT_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_NO_SLT_IND",
171 [MSG_SMS_GET_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_REQ",
172 [MSG_SMS_GET_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_RES",
173 [MSG_SMS_SEND_DUMP - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_DUMP",
174 [MSG_SMS_SCAN_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_START_REQ",
175 [MSG_SMS_SCAN_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_START_RES",
176 [MSG_SMS_SCAN_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_STOP_REQ",
177 [MSG_SMS_SCAN_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_STOP_RES",
178 [MSG_SMS_SCAN_PROGRESS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_PROGRESS_IND",
179 [MSG_SMS_SCAN_COMPLETE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_COMPLETE_IND",
180 [MSG_SMS_LOG_ITEM - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ITEM",
181 [MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ",
182 [MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES",
183 [MSG_SMS_HO_PER_SLICES_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PER_SLICES_IND",
184 [MSG_SMS_HO_INBAND_POWER_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_INBAND_POWER_IND",
185 [MSG_SMS_MANUAL_DEMOD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MANUAL_DEMOD_REQ",
186 [MSG_SMS_HO_TUNE_ON_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_ON_REQ",
187 [MSG_SMS_HO_TUNE_ON_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_ON_RES",
188 [MSG_SMS_HO_TUNE_OFF_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_OFF_REQ",
189 [MSG_SMS_HO_TUNE_OFF_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_OFF_RES",
190 [MSG_SMS_HO_PEEK_FREQ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_REQ",
191 [MSG_SMS_HO_PEEK_FREQ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_RES",
192 [MSG_SMS_HO_PEEK_FREQ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_IND",
193 [MSG_SMS_MB_ATTEN_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_ATTEN_SET_REQ",
194 [MSG_SMS_MB_ATTEN_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_ATTEN_SET_RES",
195 [MSG_SMS_ENABLE_STAT_IN_I2C_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENABLE_STAT_IN_I2C_REQ",
196 [MSG_SMS_ENABLE_STAT_IN_I2C_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENABLE_STAT_IN_I2C_RES",
197 [MSG_SMS_SET_ANTENNA_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_ANTENNA_CONFIG_REQ",
198 [MSG_SMS_SET_ANTENNA_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_ANTENNA_CONFIG_RES",
199 [MSG_SMS_GET_STATISTICS_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_EX_REQ",
200 [MSG_SMS_GET_STATISTICS_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_EX_RES",
201 [MSG_SMS_SLEEP_RESUME_COMP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SLEEP_RESUME_COMP_IND",
202 [MSG_SMS_SWITCH_HOST_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWITCH_HOST_INTERFACE_REQ",
203 [MSG_SMS_SWITCH_HOST_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWITCH_HOST_INTERFACE_RES",
204 [MSG_SMS_DATA_DOWNLOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_DOWNLOAD_REQ",
205 [MSG_SMS_DATA_DOWNLOAD_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_DOWNLOAD_RES",
206 [MSG_SMS_DATA_VALIDITY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_VALIDITY_REQ",
207 [MSG_SMS_DATA_VALIDITY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_VALIDITY_RES",
208 [MSG_SMS_SWDOWNLOAD_TRIGGER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_TRIGGER_REQ",
209 [MSG_SMS_SWDOWNLOAD_TRIGGER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_TRIGGER_RES",
210 [MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ",
211 [MSG_SMS_SWDOWNLOAD_BACKDOOR_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_BACKDOOR_RES",
212 [MSG_SMS_GET_VERSION_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_EX_REQ",
213 [MSG_SMS_GET_VERSION_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_EX_RES",
214 [MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ",
215 [MSG_SMS_CLOCK_OUTPUT_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CLOCK_OUTPUT_CONFIG_RES",
216 [MSG_SMS_I2C_SET_FREQ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SET_FREQ_REQ",
217 [MSG_SMS_I2C_SET_FREQ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SET_FREQ_RES",
218 [MSG_SMS_GENERIC_I2C_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_I2C_REQ",
219 [MSG_SMS_GENERIC_I2C_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_I2C_RES",
220 [MSG_SMS_DVBT_BDA_DATA - MSG_TYPE_BASE_VAL] = "MSG_SMS_DVBT_BDA_DATA",
221 [MSG_SW_RELOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_REQ",
222 [MSG_SMS_DATA_MSG - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_MSG",
223 [MSG_TABLE_UPLOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_TABLE_UPLOAD_REQ",
224 [MSG_TABLE_UPLOAD_RES - MSG_TYPE_BASE_VAL] = "MSG_TABLE_UPLOAD_RES",
225 [MSG_SW_RELOAD_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_START_REQ",
226 [MSG_SW_RELOAD_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_START_RES",
227 [MSG_SW_RELOAD_EXEC_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_EXEC_REQ",
228 [MSG_SW_RELOAD_EXEC_RES - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_EXEC_RES",
229 [MSG_SMS_SPI_INT_LINE_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_INT_LINE_SET_REQ",
230 [MSG_SMS_SPI_INT_LINE_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_INT_LINE_SET_RES",
231 [MSG_SMS_GPIO_CONFIG_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_EX_REQ",
232 [MSG_SMS_GPIO_CONFIG_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_EX_RES",
233 [MSG_SMS_WATCHDOG_ACT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_WATCHDOG_ACT_REQ",
234 [MSG_SMS_WATCHDOG_ACT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_WATCHDOG_ACT_RES",
235 [MSG_SMS_LOOPBACK_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOOPBACK_REQ",
236 [MSG_SMS_LOOPBACK_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOOPBACK_RES",
237 [MSG_SMS_RAW_CAPTURE_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_START_REQ",
238 [MSG_SMS_RAW_CAPTURE_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_START_RES",
239 [MSG_SMS_RAW_CAPTURE_ABORT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_ABORT_REQ",
240 [MSG_SMS_RAW_CAPTURE_ABORT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_ABORT_RES",
241 [MSG_SMS_RAW_CAPTURE_COMPLETE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_COMPLETE_IND",
242 [MSG_SMS_DATA_PUMP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_IND",
243 [MSG_SMS_DATA_PUMP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_REQ",
244 [MSG_SMS_DATA_PUMP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_RES",
245 [MSG_SMS_FLASH_DL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_FLASH_DL_REQ",
246 [MSG_SMS_EXEC_TEST_1_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXEC_TEST_1_REQ",
247 [MSG_SMS_EXEC_TEST_1_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXEC_TEST_1_RES",
248 [MSG_SMS_ENBALE_TS_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENBALE_TS_INTERFACE_REQ",
249 [MSG_SMS_ENBALE_TS_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENBALE_TS_INTERFACE_RES",
250 [MSG_SMS_SPI_SET_BUS_WIDTH_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_SET_BUS_WIDTH_REQ",
251 [MSG_SMS_SPI_SET_BUS_WIDTH_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_SET_BUS_WIDTH_RES",
252 [MSG_SMS_SEND_EMM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_EMM_REQ",
253 [MSG_SMS_SEND_EMM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_EMM_RES",
254 [MSG_SMS_DISABLE_TS_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DISABLE_TS_INTERFACE_REQ",
255 [MSG_SMS_DISABLE_TS_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DISABLE_TS_INTERFACE_RES",
256 [MSG_SMS_IS_BUF_FREE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IS_BUF_FREE_REQ",
257 [MSG_SMS_IS_BUF_FREE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IS_BUF_FREE_RES",
258 [MSG_SMS_EXT_ANTENNA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXT_ANTENNA_REQ",
259 [MSG_SMS_EXT_ANTENNA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXT_ANTENNA_RES",
260 [MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE",
261 [MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE",
262 [MSG_SMS_BATTERY_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_BATTERY_LEVEL_REQ",
263 [MSG_SMS_BATTERY_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_BATTERY_LEVEL_RES",
264 [MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE",
265 [MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE",
266 [MSG_SMS_FM_RADIO_BLOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_FM_RADIO_BLOCK_IND",
267 [MSG_SMS_HOST_NOTIFICATION_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HOST_NOTIFICATION_IND",
268 [MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE",
269 [MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE",
270 [MSG_SMS_CMMB_GET_NETWORKS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NETWORKS_REQ",
271 [MSG_SMS_CMMB_GET_NETWORKS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NETWORKS_RES",
272 [MSG_SMS_CMMB_START_SERVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_SERVICE_REQ",
273 [MSG_SMS_CMMB_START_SERVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_SERVICE_RES",
274 [MSG_SMS_CMMB_STOP_SERVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_SERVICE_REQ",
275 [MSG_SMS_CMMB_STOP_SERVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_SERVICE_RES",
276 [MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ",
277 [MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES",
278 [MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ",
279 [MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES",
280 [MSG_SMS_CMMB_START_CONTROL_INFO_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_CONTROL_INFO_REQ",
281 [MSG_SMS_CMMB_START_CONTROL_INFO_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_CONTROL_INFO_RES",
282 [MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ",
283 [MSG_SMS_CMMB_STOP_CONTROL_INFO_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_CONTROL_INFO_RES",
284 [MSG_SMS_ISDBT_TUNE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_TUNE_REQ",
285 [MSG_SMS_ISDBT_TUNE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_TUNE_RES",
286 [MSG_SMS_TRANSMISSION_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_TRANSMISSION_IND",
287 [MSG_SMS_PID_STATISTICS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_PID_STATISTICS_IND",
288 [MSG_SMS_POWER_DOWN_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_IND",
289 [MSG_SMS_POWER_DOWN_CONF - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_CONF",
290 [MSG_SMS_POWER_UP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_UP_IND",
291 [MSG_SMS_POWER_UP_CONF - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_UP_CONF",
292 [MSG_SMS_POWER_MODE_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_MODE_SET_REQ",
293 [MSG_SMS_POWER_MODE_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_MODE_SET_RES",
294 [MSG_SMS_DEBUG_HOST_EVENT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEBUG_HOST_EVENT_REQ",
295 [MSG_SMS_DEBUG_HOST_EVENT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEBUG_HOST_EVENT_RES",
296 [MSG_SMS_NEW_CRYSTAL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NEW_CRYSTAL_REQ",
297 [MSG_SMS_NEW_CRYSTAL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NEW_CRYSTAL_RES",
298 [MSG_SMS_CONFIG_SPI_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIG_SPI_REQ",
299 [MSG_SMS_CONFIG_SPI_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIG_SPI_RES",
300 [MSG_SMS_I2C_SHORT_STAT_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SHORT_STAT_IND",
301 [MSG_SMS_START_IR_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_START_IR_REQ",
302 [MSG_SMS_START_IR_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_START_IR_RES",
303 [MSG_SMS_IR_SAMPLES_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_IR_SAMPLES_IND",
304 [MSG_SMS_CMMB_CA_SERVICE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_CA_SERVICE_IND",
305 [MSG_SMS_SLAVE_DEVICE_DETECTED - MSG_TYPE_BASE_VAL] = "MSG_SMS_SLAVE_DEVICE_DETECTED",
306 [MSG_SMS_INTERFACE_LOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_INTERFACE_LOCK_IND",
307 [MSG_SMS_INTERFACE_UNLOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_INTERFACE_UNLOCK_IND",
308 [MSG_SMS_SEND_ROSUM_BUFF_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_ROSUM_BUFF_REQ",
309 [MSG_SMS_SEND_ROSUM_BUFF_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_ROSUM_BUFF_RES",
310 [MSG_SMS_ROSUM_BUFF - MSG_TYPE_BASE_VAL] = "MSG_SMS_ROSUM_BUFF",
311 [MSG_SMS_SET_AES128_KEY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_AES128_KEY_REQ",
312 [MSG_SMS_SET_AES128_KEY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_AES128_KEY_RES",
313 [MSG_SMS_MBBMS_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_WRITE_REQ",
314 [MSG_SMS_MBBMS_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_WRITE_RES",
315 [MSG_SMS_MBBMS_READ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_READ_IND",
316 [MSG_SMS_IQ_STREAM_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_START_REQ",
317 [MSG_SMS_IQ_STREAM_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_START_RES",
318 [MSG_SMS_IQ_STREAM_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_STOP_REQ",
319 [MSG_SMS_IQ_STREAM_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_STOP_RES",
320 [MSG_SMS_IQ_STREAM_DATA_BLOCK - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_DATA_BLOCK",
321 [MSG_SMS_GET_EEPROM_VERSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_EEPROM_VERSION_REQ",
322 [MSG_SMS_GET_EEPROM_VERSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_EEPROM_VERSION_RES",
323 [MSG_SMS_SIGNAL_DETECTED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SIGNAL_DETECTED_IND",
324 [MSG_SMS_NO_SIGNAL_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_NO_SIGNAL_IND",
325 [MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ",
326 [MSG_SMS_MRC_SHUTDOWN_SLAVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_SHUTDOWN_SLAVE_RES",
327 [MSG_SMS_MRC_BRINGUP_SLAVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_BRINGUP_SLAVE_REQ",
328 [MSG_SMS_MRC_BRINGUP_SLAVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_BRINGUP_SLAVE_RES",
329 [MSG_SMS_EXTERNAL_LNA_CTRL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXTERNAL_LNA_CTRL_REQ",
330 [MSG_SMS_EXTERNAL_LNA_CTRL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXTERNAL_LNA_CTRL_RES",
331 [MSG_SMS_SET_PERIODIC_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_PERIODIC_STATISTICS_REQ",
332 [MSG_SMS_SET_PERIODIC_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_PERIODIC_STATISTICS_RES",
333 [MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ",
334 [MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES",
335 [LOCAL_TUNE - MSG_TYPE_BASE_VAL] = "LOCAL_TUNE",
336 [LOCAL_IFFT_H_ICI - MSG_TYPE_BASE_VAL] = "LOCAL_IFFT_H_ICI",
337 [MSG_RESYNC_REQ - MSG_TYPE_BASE_VAL] = "MSG_RESYNC_REQ",
338 [MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ",
339 [MSG_SMS_CMMB_GET_MRC_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_MRC_STATISTICS_RES",
340 [MSG_SMS_LOG_EX_ITEM - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_EX_ITEM",
341 [MSG_SMS_DEVICE_DATA_LOSS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEVICE_DATA_LOSS_IND",
342 [MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND",
343 [MSG_SMS_USER_MSG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_USER_MSG_REQ",
344 [MSG_SMS_USER_MSG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_USER_MSG_RES",
345 [MSG_SMS_SMART_CARD_INIT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_INIT_REQ",
346 [MSG_SMS_SMART_CARD_INIT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_INIT_RES",
347 [MSG_SMS_SMART_CARD_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_WRITE_REQ",
348 [MSG_SMS_SMART_CARD_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_WRITE_RES",
349 [MSG_SMS_SMART_CARD_READ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_READ_IND",
350 [MSG_SMS_TSE_ENABLE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_TSE_ENABLE_REQ",
351 [MSG_SMS_TSE_ENABLE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_TSE_ENABLE_RES",
352 [MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ",
353 [MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES",
354 [MSG_SMS_LED_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LED_CONFIG_REQ",
355 [MSG_SMS_LED_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LED_CONFIG_RES",
356 [MSG_PWM_ANTENNA_REQ - MSG_TYPE_BASE_VAL] = "MSG_PWM_ANTENNA_REQ",
357 [MSG_PWM_ANTENNA_RES - MSG_TYPE_BASE_VAL] = "MSG_PWM_ANTENNA_RES",
358 [MSG_SMS_CMMB_SMD_SN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SMD_SN_REQ",
359 [MSG_SMS_CMMB_SMD_SN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SMD_SN_RES",
360 [MSG_SMS_CMMB_SET_CA_CW_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_CW_REQ",
361 [MSG_SMS_CMMB_SET_CA_CW_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_CW_RES",
362 [MSG_SMS_CMMB_SET_CA_SALT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_SALT_REQ",
363 [MSG_SMS_CMMB_SET_CA_SALT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_SALT_RES",
364 [MSG_SMS_NSCD_INIT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_INIT_REQ",
365 [MSG_SMS_NSCD_INIT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_INIT_RES",
366 [MSG_SMS_NSCD_PROCESS_SECTION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_PROCESS_SECTION_REQ",
367 [MSG_SMS_NSCD_PROCESS_SECTION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_PROCESS_SECTION_RES",
368 [MSG_SMS_DBD_CREATE_OBJECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CREATE_OBJECT_REQ",
369 [MSG_SMS_DBD_CREATE_OBJECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CREATE_OBJECT_RES",
370 [MSG_SMS_DBD_CONFIGURE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CONFIGURE_REQ",
371 [MSG_SMS_DBD_CONFIGURE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CONFIGURE_RES",
372 [MSG_SMS_DBD_SET_KEYS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_SET_KEYS_REQ",
373 [MSG_SMS_DBD_SET_KEYS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_SET_KEYS_RES",
374 [MSG_SMS_DBD_PROCESS_HEADER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_HEADER_REQ",
375 [MSG_SMS_DBD_PROCESS_HEADER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_HEADER_RES",
376 [MSG_SMS_DBD_PROCESS_DATA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_DATA_REQ",
377 [MSG_SMS_DBD_PROCESS_DATA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_DATA_RES",
378 [MSG_SMS_DBD_PROCESS_GET_DATA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_GET_DATA_REQ",
379 [MSG_SMS_DBD_PROCESS_GET_DATA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_GET_DATA_RES",
380 [MSG_SMS_NSCD_OPEN_SESSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_OPEN_SESSION_REQ",
381 [MSG_SMS_NSCD_OPEN_SESSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_OPEN_SESSION_RES",
382 [MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ",
383 [MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES",
384 [MSG_LAST_MSG_TYPE - MSG_TYPE_BASE_VAL] = "MSG_LAST_MSG_TYPE",
385};
386
387char *smscore_translate_msg(enum msg_types msgtype)
388{
389 int i = msgtype - MSG_TYPE_BASE_VAL;
390 char *msg;
391
392 if (i < 0 || i >= ARRAY_SIZE(siano_msgs))
393 return "Unknown msg type";
394
395 msg = siano_msgs[i];
396
397 if (!*msg)
398 return "Unknown msg type";
399
400 return msg;
401}
402EXPORT_SYMBOL_GPL(smscore_translate_msg);
403
66void smscore_set_board_id(struct smscore_device_t *core, int id) 404void smscore_set_board_id(struct smscore_device_t *core, int id)
67{ 405{
68 core->board_id = id; 406 core->board_id = id;
@@ -96,7 +434,7 @@ static struct mutex g_smscore_deviceslock;
96static struct list_head g_smscore_registry; 434static struct list_head g_smscore_registry;
97static struct mutex g_smscore_registrylock; 435static struct mutex g_smscore_registrylock;
98 436
99static int default_mode = 4; 437static int default_mode = DEVICE_MODE_NONE;
100 438
101module_param(default_mode, int, 0644); 439module_param(default_mode, int, 0644);
102MODULE_PARM_DESC(default_mode, "default firmware id (device mode)"); 440MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
@@ -151,10 +489,10 @@ static enum sms_device_type_st smscore_registry_gettype(char *devpath)
151 else 489 else
152 sms_err("No registry found."); 490 sms_err("No registry found.");
153 491
154 return -1; 492 return -EINVAL;
155} 493}
156 494
157void smscore_registry_setmode(char *devpath, int mode) 495static void smscore_registry_setmode(char *devpath, int mode)
158{ 496{
159 struct smscore_registry_entry_t *entry; 497 struct smscore_registry_entry_t *entry;
160 498
@@ -294,10 +632,11 @@ static struct
294smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer, 632smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
295 dma_addr_t common_buffer_phys) 633 dma_addr_t common_buffer_phys)
296{ 634{
297 struct smscore_buffer_t *cb = 635 struct smscore_buffer_t *cb;
298 kmalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL); 636
637 cb = kzalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL);
299 if (!cb) { 638 if (!cb) {
300 sms_info("kmalloc(...) failed"); 639 sms_info("kzalloc(...) failed");
301 return NULL; 640 return NULL;
302 } 641 }
303 642
@@ -344,6 +683,7 @@ int smscore_register_device(struct smsdevice_params_t *params,
344 /* init completion events */ 683 /* init completion events */
345 init_completion(&dev->version_ex_done); 684 init_completion(&dev->version_ex_done);
346 init_completion(&dev->data_download_done); 685 init_completion(&dev->data_download_done);
686 init_completion(&dev->data_validity_done);
347 init_completion(&dev->trigger_done); 687 init_completion(&dev->trigger_done);
348 init_completion(&dev->init_device_done); 688 init_completion(&dev->init_device_done);
349 init_completion(&dev->reload_start_done); 689 init_completion(&dev->reload_start_done);
@@ -370,9 +710,10 @@ int smscore_register_device(struct smsdevice_params_t *params,
370 for (buffer = dev->common_buffer; 710 for (buffer = dev->common_buffer;
371 dev->num_buffers < params->num_buffers; 711 dev->num_buffers < params->num_buffers;
372 dev->num_buffers++, buffer += params->buffer_size) { 712 dev->num_buffers++, buffer += params->buffer_size) {
373 struct smscore_buffer_t *cb = 713 struct smscore_buffer_t *cb;
374 smscore_createbuffer(buffer, dev->common_buffer, 714
375 dev->common_buffer_phys); 715 cb = smscore_createbuffer(buffer, dev->common_buffer,
716 dev->common_buffer_phys);
376 if (!cb) { 717 if (!cb) {
377 smscore_unregister_device(dev); 718 smscore_unregister_device(dev);
378 return -ENOMEM; 719 return -ENOMEM;
@@ -384,6 +725,7 @@ int smscore_register_device(struct smsdevice_params_t *params,
384 sms_info("allocated %d buffers", dev->num_buffers); 725 sms_info("allocated %d buffers", dev->num_buffers);
385 726
386 dev->mode = DEVICE_MODE_NONE; 727 dev->mode = DEVICE_MODE_NONE;
728 dev->board_id = SMS_BOARD_UNKNOWN;
387 dev->context = params->context; 729 dev->context = params->context;
388 dev->device = params->device; 730 dev->device = params->device;
389 dev->setmode_handler = params->setmode_handler; 731 dev->setmode_handler = params->setmode_handler;
@@ -413,7 +755,13 @@ EXPORT_SYMBOL_GPL(smscore_register_device);
413 755
414static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev, 756static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev,
415 void *buffer, size_t size, struct completion *completion) { 757 void *buffer, size_t size, struct completion *completion) {
416 int rc = coredev->sendrequest_handler(coredev->context, buffer, size); 758 int rc;
759
760 if (completion == NULL)
761 return -EINVAL;
762 init_completion(completion);
763
764 rc = coredev->sendrequest_handler(coredev->context, buffer, size);
417 if (rc < 0) { 765 if (rc < 0) {
418 sms_info("sendrequest returned error %d", rc); 766 sms_info("sendrequest returned error %d", rc);
419 return rc; 767 return rc;
@@ -444,24 +792,22 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
444 if (rc != 0) 792 if (rc != 0)
445 sms_err("Error initialization DTV IR sub-module"); 793 sms_err("Error initialization DTV IR sub-module");
446 else { 794 else {
447 buffer = kmalloc(sizeof(struct SmsMsgData_ST2) + 795 buffer = kmalloc(sizeof(struct sms_msg_data2) +
448 SMS_DMA_ALIGNMENT, 796 SMS_DMA_ALIGNMENT,
449 GFP_KERNEL | GFP_DMA); 797 GFP_KERNEL | GFP_DMA);
450 if (buffer) { 798 if (buffer) {
451 struct SmsMsgData_ST2 *msg = 799 struct sms_msg_data2 *msg =
452 (struct SmsMsgData_ST2 *) 800 (struct sms_msg_data2 *)
453 SMS_ALIGN_ADDRESS(buffer); 801 SMS_ALIGN_ADDRESS(buffer);
454 802
455 SMS_INIT_MSG(&msg->xMsgHeader, 803 SMS_INIT_MSG(&msg->x_msg_header,
456 MSG_SMS_START_IR_REQ, 804 MSG_SMS_START_IR_REQ,
457 sizeof(struct SmsMsgData_ST2)); 805 sizeof(struct sms_msg_data2));
458 msg->msgData[0] = coredev->ir.controller; 806 msg->msg_data[0] = coredev->ir.controller;
459 msg->msgData[1] = coredev->ir.timeout; 807 msg->msg_data[1] = coredev->ir.timeout;
460 808
461 smsendian_handle_tx_message(
462 (struct SmsMsgHdr_ST2 *)msg);
463 rc = smscore_sendrequest_and_wait(coredev, msg, 809 rc = smscore_sendrequest_and_wait(coredev, msg,
464 msg->xMsgHeader. msgLength, 810 msg->x_msg_header. msg_length,
465 &coredev->ir_init_done); 811 &coredev->ir_init_done);
466 812
467 kfree(buffer); 813 kfree(buffer);
@@ -476,21 +822,82 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
476} 822}
477 823
478/** 824/**
825 * configures device features according to board configuration structure.
826 *
827 * @param coredev pointer to a coredev object returned by
828 * smscore_register_device
829 *
830 * @return 0 on success, <0 on error.
831 */
832static int smscore_configure_board(struct smscore_device_t *coredev)
833{
834 struct sms_board *board;
835
836 board = sms_get_board(coredev->board_id);
837 if (!board) {
838 sms_err("no board configuration exist.");
839 return -EINVAL;
840 }
841
842 if (board->mtu) {
843 struct sms_msg_data mtu_msg;
844 sms_debug("set max transmit unit %d", board->mtu);
845
846 mtu_msg.x_msg_header.msg_src_id = 0;
847 mtu_msg.x_msg_header.msg_dst_id = HIF_TASK;
848 mtu_msg.x_msg_header.msg_flags = 0;
849 mtu_msg.x_msg_header.msg_type = MSG_SMS_SET_MAX_TX_MSG_LEN_REQ;
850 mtu_msg.x_msg_header.msg_length = sizeof(mtu_msg);
851 mtu_msg.msg_data[0] = board->mtu;
852
853 coredev->sendrequest_handler(coredev->context, &mtu_msg,
854 sizeof(mtu_msg));
855 }
856
857 if (board->crystal) {
858 struct sms_msg_data crys_msg;
859 sms_debug("set crystal value %d", board->crystal);
860
861 SMS_INIT_MSG(&crys_msg.x_msg_header,
862 MSG_SMS_NEW_CRYSTAL_REQ,
863 sizeof(crys_msg));
864 crys_msg.msg_data[0] = board->crystal;
865
866 coredev->sendrequest_handler(coredev->context, &crys_msg,
867 sizeof(crys_msg));
868 }
869
870 return 0;
871}
872
873/**
479 * sets initial device mode and notifies client hotplugs that device is ready 874 * sets initial device mode and notifies client hotplugs that device is ready
480 * 875 *
481 * @param coredev pointer to a coredev object returned by 876 * @param coredev pointer to a coredev object returned by
482 * smscore_register_device 877 * smscore_register_device
483 * 878 *
484 * @return 0 on success, <0 on error. 879 * @return 0 on success, <0 on error.
485 */ 880 */
486int smscore_start_device(struct smscore_device_t *coredev) 881int smscore_start_device(struct smscore_device_t *coredev)
487{ 882{
488 int rc = smscore_set_device_mode( 883 int rc;
489 coredev, smscore_registry_getmode(coredev->devpath)); 884 int board_id = smscore_get_board_id(coredev);
885 int mode = smscore_registry_getmode(coredev->devpath);
886
887 /* Device is initialized as DEVICE_MODE_NONE */
888 if (board_id != SMS_BOARD_UNKNOWN && mode == DEVICE_MODE_NONE)
889 mode = sms_get_board(board_id)->default_mode;
890
891 rc = smscore_set_device_mode(coredev, mode);
490 if (rc < 0) { 892 if (rc < 0) {
491 sms_info("set device mode faile , rc %d", rc); 893 sms_info("set device mode faile , rc %d", rc);
492 return rc; 894 return rc;
493 } 895 }
896 rc = smscore_configure_board(coredev);
897 if (rc < 0) {
898 sms_info("configure board failed , rc %d", rc);
899 return rc;
900 }
494 901
495 kmutex_lock(&g_smscore_deviceslock); 902 kmutex_lock(&g_smscore_deviceslock);
496 903
@@ -509,18 +916,19 @@ EXPORT_SYMBOL_GPL(smscore_start_device);
509static int smscore_load_firmware_family2(struct smscore_device_t *coredev, 916static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
510 void *buffer, size_t size) 917 void *buffer, size_t size)
511{ 918{
512 struct SmsFirmware_ST *firmware = (struct SmsFirmware_ST *) buffer; 919 struct sms_firmware *firmware = (struct sms_firmware *) buffer;
513 struct SmsMsgHdr_ST *msg; 920 struct sms_msg_data4 *msg;
514 u32 mem_address; 921 u32 mem_address, calc_checksum = 0;
515 u8 *payload = firmware->Payload; 922 u32 i, *ptr;
923 u8 *payload = firmware->payload;
516 int rc = 0; 924 int rc = 0;
517 firmware->StartAddress = le32_to_cpu(firmware->StartAddress); 925 firmware->start_address = le32_to_cpu(firmware->start_address);
518 firmware->Length = le32_to_cpu(firmware->Length); 926 firmware->length = le32_to_cpu(firmware->length);
519 927
520 mem_address = firmware->StartAddress; 928 mem_address = firmware->start_address;
521 929
522 sms_info("loading FW to addr 0x%x size %d", 930 sms_info("loading FW to addr 0x%x size %d",
523 mem_address, firmware->Length); 931 mem_address, firmware->length);
524 if (coredev->preload_handler) { 932 if (coredev->preload_handler) {
525 rc = coredev->preload_handler(coredev->context); 933 rc = coredev->preload_handler(coredev->context);
526 if (rc < 0) 934 if (rc < 0)
@@ -534,35 +942,36 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
534 942
535 if (coredev->mode != DEVICE_MODE_NONE) { 943 if (coredev->mode != DEVICE_MODE_NONE) {
536 sms_debug("sending reload command."); 944 sms_debug("sending reload command.");
537 SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, 945 SMS_INIT_MSG(&msg->x_msg_header, MSG_SW_RELOAD_START_REQ,
538 sizeof(struct SmsMsgHdr_ST)); 946 sizeof(struct sms_msg_hdr));
539 rc = smscore_sendrequest_and_wait(coredev, msg, 947 rc = smscore_sendrequest_and_wait(coredev, msg,
540 msg->msgLength, 948 msg->x_msg_header.msg_length,
541 &coredev->reload_start_done); 949 &coredev->reload_start_done);
950 if (rc < 0) {
951 sms_err("device reload failed, rc %d", rc);
952 goto exit_fw_download;
953 }
542 mem_address = *(u32 *) &payload[20]; 954 mem_address = *(u32 *) &payload[20];
543 } 955 }
544 956
957 for (i = 0, ptr = (u32 *)firmware->payload; i < firmware->length/4 ;
958 i++, ptr++)
959 calc_checksum += *ptr;
960
545 while (size && rc >= 0) { 961 while (size && rc >= 0) {
546 struct SmsDataDownload_ST *DataMsg = 962 struct sms_data_download *data_msg =
547 (struct SmsDataDownload_ST *) msg; 963 (struct sms_data_download *) msg;
548 int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE); 964 int payload_size = min_t(int, size, SMS_MAX_PAYLOAD_SIZE);
549 965
550 SMS_INIT_MSG(msg, MSG_SMS_DATA_DOWNLOAD_REQ, 966 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_DOWNLOAD_REQ,
551 (u16)(sizeof(struct SmsMsgHdr_ST) + 967 (u16)(sizeof(struct sms_msg_hdr) +
552 sizeof(u32) + payload_size)); 968 sizeof(u32) + payload_size));
553 969
554 DataMsg->MemAddr = mem_address; 970 data_msg->mem_addr = mem_address;
555 memcpy(DataMsg->Payload, payload, payload_size); 971 memcpy(data_msg->payload, payload, payload_size);
556 972
557 if ((coredev->device_flags & SMS_ROM_NO_RESPONSE) && 973 rc = smscore_sendrequest_and_wait(coredev, data_msg,
558 (coredev->mode == DEVICE_MODE_NONE)) 974 data_msg->x_msg_header.msg_length,
559 rc = coredev->sendrequest_handler(
560 coredev->context, DataMsg,
561 DataMsg->xMsgHeader.msgLength);
562 else
563 rc = smscore_sendrequest_and_wait(
564 coredev, DataMsg,
565 DataMsg->xMsgHeader.msgLength,
566 &coredev->data_download_done); 975 &coredev->data_download_done);
567 976
568 payload += payload_size; 977 payload += payload_size;
@@ -570,50 +979,158 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
570 mem_address += payload_size; 979 mem_address += payload_size;
571 } 980 }
572 981
573 if (rc >= 0) { 982 if (rc < 0)
574 if (coredev->mode == DEVICE_MODE_NONE) { 983 goto exit_fw_download;
575 struct SmsMsgData_ST *TriggerMsg = 984
576 (struct SmsMsgData_ST *) msg; 985 sms_err("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
577 986 calc_checksum);
578 SMS_INIT_MSG(msg, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ, 987 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_VALIDITY_REQ,
579 sizeof(struct SmsMsgHdr_ST) + 988 sizeof(msg->x_msg_header) +
580 sizeof(u32) * 5); 989 sizeof(u32) * 3);
581 990 msg->msg_data[0] = firmware->start_address;
582 TriggerMsg->msgData[0] = firmware->StartAddress; 991 /* Entry point */
583 /* Entry point */ 992 msg->msg_data[1] = firmware->length;
584 TriggerMsg->msgData[1] = 5; /* Priority */ 993 msg->msg_data[2] = 0; /* Regular checksum*/
585 TriggerMsg->msgData[2] = 0x200; /* Stack size */ 994 rc = smscore_sendrequest_and_wait(coredev, msg,
586 TriggerMsg->msgData[3] = 0; /* Parameter */ 995 msg->x_msg_header.msg_length,
587 TriggerMsg->msgData[4] = 4; /* Task ID */ 996 &coredev->data_validity_done);
588 997 if (rc < 0)
589 if (coredev->device_flags & SMS_ROM_NO_RESPONSE) { 998 goto exit_fw_download;
590 rc = coredev->sendrequest_handler( 999
591 coredev->context, TriggerMsg, 1000 if (coredev->mode == DEVICE_MODE_NONE) {
592 TriggerMsg->xMsgHeader.msgLength); 1001 struct sms_msg_data *trigger_msg =
593 msleep(100); 1002 (struct sms_msg_data *) msg;
594 } else 1003
595 rc = smscore_sendrequest_and_wait( 1004 sms_debug("sending MSG_SMS_SWDOWNLOAD_TRIGGER_REQ");
596 coredev, TriggerMsg, 1005 SMS_INIT_MSG(&msg->x_msg_header,
597 TriggerMsg->xMsgHeader.msgLength, 1006 MSG_SMS_SWDOWNLOAD_TRIGGER_REQ,
1007 sizeof(struct sms_msg_hdr) +
1008 sizeof(u32) * 5);
1009
1010 trigger_msg->msg_data[0] = firmware->start_address;
1011 /* Entry point */
1012 trigger_msg->msg_data[1] = 6; /* Priority */
1013 trigger_msg->msg_data[2] = 0x200; /* Stack size */
1014 trigger_msg->msg_data[3] = 0; /* Parameter */
1015 trigger_msg->msg_data[4] = 4; /* Task ID */
1016
1017 rc = smscore_sendrequest_and_wait(coredev, trigger_msg,
1018 trigger_msg->x_msg_header.msg_length,
598 &coredev->trigger_done); 1019 &coredev->trigger_done);
599 } else { 1020 } else {
600 SMS_INIT_MSG(msg, MSG_SW_RELOAD_EXEC_REQ, 1021 SMS_INIT_MSG(&msg->x_msg_header, MSG_SW_RELOAD_EXEC_REQ,
601 sizeof(struct SmsMsgHdr_ST)); 1022 sizeof(struct sms_msg_hdr));
602 1023 rc = coredev->sendrequest_handler(coredev->context, msg,
603 rc = coredev->sendrequest_handler(coredev->context, 1024 msg->x_msg_header.msg_length);
604 msg, msg->msgLength);
605 }
606 msleep(500);
607 } 1025 }
608 1026
609 sms_debug("rc=%d, postload=%p ", rc, 1027 if (rc < 0)
610 coredev->postload_handler); 1028 goto exit_fw_download;
1029
1030 /*
1031 * backward compatibility - wait to device_ready_done for
1032 * not more than 400 ms
1033 */
1034 msleep(400);
611 1035
1036exit_fw_download:
612 kfree(msg); 1037 kfree(msg);
613 1038
614 return ((rc >= 0) && coredev->postload_handler) ? 1039 if (coredev->postload_handler) {
615 coredev->postload_handler(coredev->context) : 1040 sms_debug("rc=%d, postload=0x%p", rc, coredev->postload_handler);
616 rc; 1041 if (rc >= 0)
1042 return coredev->postload_handler(coredev->context);
1043 }
1044
1045 sms_debug("rc=%d", rc);
1046 return rc;
1047}
1048
1049static char *smscore_fw_lkup[][DEVICE_MODE_MAX] = {
1050 [SMS_NOVA_A0] = {
1051 [DEVICE_MODE_DVBT] = SMS_FW_DVB_NOVA_12MHZ,
1052 [DEVICE_MODE_DVBH] = SMS_FW_DVB_NOVA_12MHZ,
1053 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_NOVA_12MHZ,
1054 [DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_NOVA_12MHZ,
1055 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_NOVA_12MHZ,
1056 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_NOVA_12MHZ,
1057 },
1058 [SMS_NOVA_B0] = {
1059 [DEVICE_MODE_DVBT] = SMS_FW_DVB_NOVA_12MHZ_B0,
1060 [DEVICE_MODE_DVBH] = SMS_FW_DVB_NOVA_12MHZ_B0,
1061 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_NOVA_12MHZ_B0,
1062 [DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_NOVA_12MHZ_B0,
1063 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_NOVA_12MHZ_B0,
1064 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_NOVA_12MHZ_B0,
1065 [DEVICE_MODE_FM_RADIO] = SMS_FW_FM_RADIO,
1066 [DEVICE_MODE_FM_RADIO_BDA] = SMS_FW_FM_RADIO,
1067 },
1068 [SMS_VEGA] = {
1069 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_VEGA_12MHZ,
1070 },
1071 [SMS_VENICE] = {
1072 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_VENICE_12MHZ,
1073 },
1074 [SMS_MING] = {
1075 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_MING_APP,
1076 },
1077 [SMS_PELE] = {
1078 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_PELE,
1079 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_PELE,
1080 },
1081 [SMS_RIO] = {
1082 [DEVICE_MODE_DVBT] = SMS_FW_DVB_RIO,
1083 [DEVICE_MODE_DVBH] = SMS_FW_DVBH_RIO,
1084 [DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_RIO,
1085 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_RIO,
1086 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_RIO,
1087 [DEVICE_MODE_FM_RADIO] = SMS_FW_FM_RADIO_RIO,
1088 [DEVICE_MODE_FM_RADIO_BDA] = SMS_FW_FM_RADIO_RIO,
1089 },
1090 [SMS_DENVER_1530] = {
1091 [DEVICE_MODE_ATSC] = SMS_FW_ATSC_DENVER,
1092 },
1093 [SMS_DENVER_2160] = {
1094 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_DENVER,
1095 },
1096};
1097
1098/**
1099 * get firmware file name from one of the two mechanisms : sms_boards or
1100 * smscore_fw_lkup.
1101 * @param coredev pointer to a coredev object returned by
1102 * smscore_register_device
1103 * @param mode requested mode of operation
1104 * @param lookup if 1, always get the fw filename from smscore_fw_lkup
1105 * table. if 0, try first to get from sms_boards
1106 *
1107 * @return 0 on success, <0 on error.
1108 */
1109static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
1110 int mode)
1111{
1112 char **fw;
1113 int board_id = smscore_get_board_id(coredev);
1114 enum sms_device_type_st type;
1115
1116 type = smscore_registry_gettype(coredev->devpath);
1117
1118 /* Prevent looking outside the smscore_fw_lkup table */
1119 if (type <= SMS_UNKNOWN_TYPE || type >= SMS_NUM_OF_DEVICE_TYPES)
1120 return NULL;
1121 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX)
1122 return NULL;
1123
1124 sms_debug("trying to get fw name from sms_boards board_id %d mode %d",
1125 board_id, mode);
1126 fw = sms_get_board(board_id)->fw;
1127 if (!fw || !fw[mode]) {
1128 sms_debug("cannot find fw name in sms_boards, getting from lookup table mode %d type %d",
1129 mode, type);
1130 return smscore_fw_lkup[type][mode];
1131 }
1132
1133 return fw[mode];
617} 1134}
618 1135
619/** 1136/**
@@ -627,41 +1144,46 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
627 * @return 0 on success, <0 on error. 1144 * @return 0 on success, <0 on error.
628 */ 1145 */
629static int smscore_load_firmware_from_file(struct smscore_device_t *coredev, 1146static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
630 char *filename, 1147 int mode,
631 loadfirmware_t loadfirmware_handler) 1148 loadfirmware_t loadfirmware_handler)
632{ 1149{
633 int rc = -ENOENT; 1150 int rc = -ENOENT;
1151 u8 *fw_buf;
1152 u32 fw_buf_size;
634 const struct firmware *fw; 1153 const struct firmware *fw;
635 u8 *fw_buffer;
636 1154
637 if (loadfirmware_handler == NULL && !(coredev->device_flags & 1155 char *fw_filename = smscore_get_fw_filename(coredev, mode);
638 SMS_DEVICE_FAMILY2)) 1156 if (!fw_filename) {
1157 sms_info("mode %d not supported on this device", mode);
1158 return -ENOENT;
1159 }
1160 sms_debug("Firmware name: %s", fw_filename);
1161
1162 if (loadfirmware_handler == NULL && !(coredev->device_flags
1163 & SMS_DEVICE_FAMILY2))
639 return -EINVAL; 1164 return -EINVAL;
640 1165
641 rc = request_firmware(&fw, filename, coredev->device); 1166 rc = request_firmware(&fw, fw_filename, coredev->device);
642 if (rc < 0) { 1167 if (rc < 0) {
643 sms_info("failed to open \"%s\"", filename); 1168 sms_info("failed to open \"%s\"", fw_filename);
644 return rc; 1169 return rc;
645 } 1170 }
646 sms_info("read FW %s, size=%zd", filename, fw->size); 1171 sms_info("read fw %s, buffer size=0x%zx", fw_filename, fw->size);
647 fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), 1172 fw_buf = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT),
648 GFP_KERNEL | GFP_DMA); 1173 GFP_KERNEL | GFP_DMA);
649 if (fw_buffer) { 1174 if (!fw_buf) {
650 memcpy(fw_buffer, fw->data, fw->size);
651
652 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
653 smscore_load_firmware_family2(coredev,
654 fw_buffer,
655 fw->size) :
656 loadfirmware_handler(coredev->context,
657 fw_buffer, fw->size);
658
659 kfree(fw_buffer);
660 } else {
661 sms_info("failed to allocate firmware buffer"); 1175 sms_info("failed to allocate firmware buffer");
662 rc = -ENOMEM; 1176 return -ENOMEM;
663 } 1177 }
1178 memcpy(fw_buf, fw->data, fw->size);
1179 fw_buf_size = fw->size;
1180
1181 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
1182 smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
1183 : loadfirmware_handler(coredev->context, fw_buf,
1184 fw_buf_size);
664 1185
1186 kfree(fw_buf);
665 release_firmware(fw); 1187 release_firmware(fw);
666 1188
667 return rc; 1189 return rc;
@@ -703,14 +1225,15 @@ void smscore_unregister_device(struct smscore_device_t *coredev)
703 if (num_buffers == coredev->num_buffers) 1225 if (num_buffers == coredev->num_buffers)
704 break; 1226 break;
705 if (++retry > 10) { 1227 if (++retry > 10) {
706 sms_info("exiting although " 1228 sms_info("exiting although not all buffers released.");
707 "not all buffers released.");
708 break; 1229 break;
709 } 1230 }
710 1231
711 sms_info("waiting for %d buffer(s)", 1232 sms_info("waiting for %d buffer(s)",
712 coredev->num_buffers - num_buffers); 1233 coredev->num_buffers - num_buffers);
1234 kmutex_unlock(&g_smscore_deviceslock);
713 msleep(100); 1235 msleep(100);
1236 kmutex_lock(&g_smscore_deviceslock);
714 } 1237 }
715 1238
716 sms_info("freed %d buffers", num_buffers); 1239 sms_info("freed %d buffers", num_buffers);
@@ -719,8 +1242,7 @@ void smscore_unregister_device(struct smscore_device_t *coredev)
719 dma_free_coherent(NULL, coredev->common_buffer_size, 1242 dma_free_coherent(NULL, coredev->common_buffer_size,
720 coredev->common_buffer, coredev->common_buffer_phys); 1243 coredev->common_buffer, coredev->common_buffer_phys);
721 1244
722 if (coredev->fw_buf != NULL) 1245 kfree(coredev->fw_buf);
723 kfree(coredev->fw_buf);
724 1246
725 list_del(&coredev->entry); 1247 list_del(&coredev->entry);
726 kfree(coredev); 1248 kfree(coredev);
@@ -733,19 +1255,19 @@ EXPORT_SYMBOL_GPL(smscore_unregister_device);
733 1255
734static int smscore_detect_mode(struct smscore_device_t *coredev) 1256static int smscore_detect_mode(struct smscore_device_t *coredev)
735{ 1257{
736 void *buffer = kmalloc(sizeof(struct SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT, 1258 void *buffer = kmalloc(sizeof(struct sms_msg_hdr) + SMS_DMA_ALIGNMENT,
737 GFP_KERNEL | GFP_DMA); 1259 GFP_KERNEL | GFP_DMA);
738 struct SmsMsgHdr_ST *msg = 1260 struct sms_msg_hdr *msg =
739 (struct SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer); 1261 (struct sms_msg_hdr *) SMS_ALIGN_ADDRESS(buffer);
740 int rc; 1262 int rc;
741 1263
742 if (!buffer) 1264 if (!buffer)
743 return -ENOMEM; 1265 return -ENOMEM;
744 1266
745 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ, 1267 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ,
746 sizeof(struct SmsMsgHdr_ST)); 1268 sizeof(struct sms_msg_hdr));
747 1269
748 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, 1270 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msg_length,
749 &coredev->version_ex_done); 1271 &coredev->version_ex_done);
750 if (rc == -ETIME) { 1272 if (rc == -ETIME) {
751 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try"); 1273 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try");
@@ -753,11 +1275,11 @@ static int smscore_detect_mode(struct smscore_device_t *coredev)
753 if (wait_for_completion_timeout(&coredev->resume_done, 1275 if (wait_for_completion_timeout(&coredev->resume_done,
754 msecs_to_jiffies(5000))) { 1276 msecs_to_jiffies(5000))) {
755 rc = smscore_sendrequest_and_wait( 1277 rc = smscore_sendrequest_and_wait(
756 coredev, msg, msg->msgLength, 1278 coredev, msg, msg->msg_length,
757 &coredev->version_ex_done); 1279 &coredev->version_ex_done);
758 if (rc < 0) 1280 if (rc < 0)
759 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed " 1281 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed second try, rc %d",
760 "second try, rc %d", rc); 1282 rc);
761 } else 1283 } else
762 rc = -ETIME; 1284 rc = -ETIME;
763 } 1285 }
@@ -767,31 +1289,39 @@ static int smscore_detect_mode(struct smscore_device_t *coredev)
767 return rc; 1289 return rc;
768} 1290}
769 1291
770static char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = { 1292/**
771 /*Stellar NOVA A0 Nova B0 VEGA*/ 1293 * send init device request and wait for response
772 /*DVBT*/ 1294 *
773 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, 1295 * @param coredev pointer to a coredev object returned by
774 /*DVBH*/ 1296 * smscore_register_device
775 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, 1297 * @param mode requested mode of operation
776 /*TDMB*/ 1298 *
777 {"none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none"}, 1299 * @return 0 on success, <0 on error.
778 /*DABIP*/ 1300 */
779 {"none", "none", "none", "none"}, 1301static int smscore_init_device(struct smscore_device_t *coredev, int mode)
780 /*BDA*/
781 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
782 /*ISDBT*/
783 {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
784 /*ISDBTBDA*/
785 {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
786 /*CMMB*/
787 {"none", "none", "none", "cmmb_vega_12mhz.inp"}
788};
789
790static inline char *sms_get_fw_name(struct smscore_device_t *coredev,
791 int mode, enum sms_device_type_st type)
792{ 1302{
793 char **fw = sms_get_board(smscore_get_board_id(coredev))->fw; 1303 void *buffer;
794 return (fw && fw[mode]) ? fw[mode] : smscore_fw_lkup[mode][type]; 1304 struct sms_msg_data *msg;
1305 int rc = 0;
1306
1307 buffer = kmalloc(sizeof(struct sms_msg_data) +
1308 SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
1309 if (!buffer) {
1310 sms_err("Could not allocate buffer for init device message.");
1311 return -ENOMEM;
1312 }
1313
1314 msg = (struct sms_msg_data *)SMS_ALIGN_ADDRESS(buffer);
1315 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
1316 sizeof(struct sms_msg_data));
1317 msg->msg_data[0] = mode;
1318
1319 rc = smscore_sendrequest_and_wait(coredev, msg,
1320 msg->x_msg_header. msg_length,
1321 &coredev->init_device_done);
1322
1323 kfree(buffer);
1324 return rc;
795} 1325}
796 1326
797/** 1327/**
@@ -806,13 +1336,11 @@ static inline char *sms_get_fw_name(struct smscore_device_t *coredev,
806 */ 1336 */
807int smscore_set_device_mode(struct smscore_device_t *coredev, int mode) 1337int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
808{ 1338{
809 void *buffer;
810 int rc = 0; 1339 int rc = 0;
811 enum sms_device_type_st type;
812 1340
813 sms_debug("set device mode to %d", mode); 1341 sms_debug("set device mode to %d", mode);
814 if (coredev->device_flags & SMS_DEVICE_FAMILY2) { 1342 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
815 if (mode < DEVICE_MODE_DVBT || mode >= DEVICE_MODE_RAW_TUNER) { 1343 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX) {
816 sms_err("invalid mode specified %d", mode); 1344 sms_err("invalid mode specified %d", mode);
817 return -EINVAL; 1345 return -EINVAL;
818 } 1346 }
@@ -833,58 +1361,21 @@ int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
833 } 1361 }
834 1362
835 if (!(coredev->modes_supported & (1 << mode))) { 1363 if (!(coredev->modes_supported & (1 << mode))) {
836 char *fw_filename;
837
838 type = smscore_registry_gettype(coredev->devpath);
839 fw_filename = sms_get_fw_name(coredev, mode, type);
840
841 rc = smscore_load_firmware_from_file(coredev, 1364 rc = smscore_load_firmware_from_file(coredev,
842 fw_filename, NULL); 1365 mode, NULL);
843 if (rc < 0) { 1366 if (rc >= 0)
844 sms_warn("error %d loading firmware: %s, " 1367 sms_info("firmware download success");
845 "trying again with default firmware",
846 rc, fw_filename);
847
848 /* try again with the default firmware */
849 fw_filename = smscore_fw_lkup[mode][type];
850 rc = smscore_load_firmware_from_file(coredev,
851 fw_filename, NULL);
852
853 if (rc < 0) {
854 sms_warn("error %d loading "
855 "firmware: %s", rc,
856 fw_filename);
857 return rc;
858 }
859 }
860 sms_log("firmware download success: %s", fw_filename);
861 } else
862 sms_info("mode %d supported by running "
863 "firmware", mode);
864
865 buffer = kmalloc(sizeof(struct SmsMsgData_ST) +
866 SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
867 if (buffer) {
868 struct SmsMsgData_ST *msg =
869 (struct SmsMsgData_ST *)
870 SMS_ALIGN_ADDRESS(buffer);
871
872 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ,
873 sizeof(struct SmsMsgData_ST));
874 msg->msgData[0] = mode;
875
876 rc = smscore_sendrequest_and_wait(
877 coredev, msg, msg->xMsgHeader.msgLength,
878 &coredev->init_device_done);
879
880 kfree(buffer);
881 } else { 1368 } else {
882 sms_err("Could not allocate buffer for " 1369 sms_info("mode %d is already supported by running firmware",
883 "init device message."); 1370 mode);
884 rc = -ENOMEM; 1371 }
1372 if (coredev->fw_version >= 0x800) {
1373 rc = smscore_init_device(coredev, mode);
1374 if (rc < 0)
1375 sms_err("device init failed, rc %d.", rc);
885 } 1376 }
886 } else { 1377 } else {
887 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) { 1378 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX) {
888 sms_err("invalid mode specified %d", mode); 1379 sms_err("invalid mode specified %d", mode);
889 return -EINVAL; 1380 return -EINVAL;
890 } 1381 }
@@ -900,12 +1391,32 @@ int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
900 } 1391 }
901 1392
902 if (rc >= 0) { 1393 if (rc >= 0) {
1394 char *buffer;
903 coredev->mode = mode; 1395 coredev->mode = mode;
904 coredev->device_flags &= ~SMS_DEVICE_NOT_READY; 1396 coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
1397
1398 buffer = kmalloc(sizeof(struct sms_msg_data) +
1399 SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
1400 if (buffer) {
1401 struct sms_msg_data *msg = (struct sms_msg_data *) SMS_ALIGN_ADDRESS(buffer);
1402
1403 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
1404 sizeof(struct sms_msg_data));
1405 msg->msg_data[0] = mode;
1406
1407 rc = smscore_sendrequest_and_wait(
1408 coredev, msg, msg->x_msg_header.msg_length,
1409 &coredev->init_device_done);
1410
1411 kfree(buffer);
1412 }
905 } 1413 }
906 1414
907 if (rc < 0) 1415 if (rc < 0)
908 sms_err("return error code %d.", rc); 1416 sms_err("return error code %d.", rc);
1417 else
1418 sms_debug("Success setting device mode.");
1419
909 return rc; 1420 return rc;
910} 1421}
911 1422
@@ -971,7 +1482,7 @@ found:
971 */ 1482 */
972void smscore_onresponse(struct smscore_device_t *coredev, 1483void smscore_onresponse(struct smscore_device_t *coredev,
973 struct smscore_buffer_t *cb) { 1484 struct smscore_buffer_t *cb) {
974 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) ((u8 *) cb->p 1485 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) ((u8 *) cb->p
975 + cb->offset); 1486 + cb->offset);
976 struct smscore_client_t *client; 1487 struct smscore_client_t *client;
977 int rc = -EBUSY; 1488 int rc = -EBUSY;
@@ -983,7 +1494,7 @@ void smscore_onresponse(struct smscore_device_t *coredev,
983 last_sample_time = time_now; 1494 last_sample_time = time_now;
984 1495
985 if (time_now - last_sample_time > 10000) { 1496 if (time_now - last_sample_time > 10000) {
986 sms_debug("\ndata rate %d bytes/secs", 1497 sms_debug("data rate %d bytes/secs",
987 (int)((data_total * 1000) / 1498 (int)((data_total * 1000) /
988 (time_now - last_sample_time))); 1499 (time_now - last_sample_time)));
989 1500
@@ -993,14 +1504,14 @@ void smscore_onresponse(struct smscore_device_t *coredev,
993 1504
994 data_total += cb->size; 1505 data_total += cb->size;
995 /* Do we need to re-route? */ 1506 /* Do we need to re-route? */
996 if ((phdr->msgType == MSG_SMS_HO_PER_SLICES_IND) || 1507 if ((phdr->msg_type == MSG_SMS_HO_PER_SLICES_IND) ||
997 (phdr->msgType == MSG_SMS_TRANSMISSION_IND)) { 1508 (phdr->msg_type == MSG_SMS_TRANSMISSION_IND)) {
998 if (coredev->mode == DEVICE_MODE_DVBT_BDA) 1509 if (coredev->mode == DEVICE_MODE_DVBT_BDA)
999 phdr->msgDstId = DVBT_BDA_CONTROL_MSG_ID; 1510 phdr->msg_dst_id = DVBT_BDA_CONTROL_MSG_ID;
1000 } 1511 }
1001 1512
1002 1513
1003 client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId); 1514 client = smscore_find_client(coredev, phdr->msg_type, phdr->msg_dst_id);
1004 1515
1005 /* If no client registered for type & id, 1516 /* If no client registered for type & id,
1006 * check for control client where type is not registered */ 1517 * check for control client where type is not registered */
@@ -1008,57 +1519,75 @@ void smscore_onresponse(struct smscore_device_t *coredev,
1008 rc = client->onresponse_handler(client->context, cb); 1519 rc = client->onresponse_handler(client->context, cb);
1009 1520
1010 if (rc < 0) { 1521 if (rc < 0) {
1011 switch (phdr->msgType) { 1522 switch (phdr->msg_type) {
1523 case MSG_SMS_ISDBT_TUNE_RES:
1524 break;
1525 case MSG_SMS_RF_TUNE_RES:
1526 break;
1527 case MSG_SMS_SIGNAL_DETECTED_IND:
1528 break;
1529 case MSG_SMS_NO_SIGNAL_IND:
1530 break;
1531 case MSG_SMS_SPI_INT_LINE_SET_RES:
1532 break;
1533 case MSG_SMS_INTERFACE_LOCK_IND:
1534 break;
1535 case MSG_SMS_INTERFACE_UNLOCK_IND:
1536 break;
1012 case MSG_SMS_GET_VERSION_EX_RES: 1537 case MSG_SMS_GET_VERSION_EX_RES:
1013 { 1538 {
1014 struct SmsVersionRes_ST *ver = 1539 struct sms_version_res *ver =
1015 (struct SmsVersionRes_ST *) phdr; 1540 (struct sms_version_res *) phdr;
1016 sms_debug("MSG_SMS_GET_VERSION_EX_RES " 1541 sms_debug("Firmware id %d prots 0x%x ver %d.%d",
1017 "id %d prots 0x%x ver %d.%d", 1542 ver->firmware_id, ver->supported_protocols,
1018 ver->FirmwareId, ver->SupportedProtocols, 1543 ver->rom_ver_major, ver->rom_ver_minor);
1019 ver->RomVersionMajor, ver->RomVersionMinor); 1544
1020 1545 coredev->mode = ver->firmware_id == 255 ?
1021 coredev->mode = ver->FirmwareId == 255 ? 1546 DEVICE_MODE_NONE : ver->firmware_id;
1022 DEVICE_MODE_NONE : ver->FirmwareId; 1547 coredev->modes_supported = ver->supported_protocols;
1023 coredev->modes_supported = ver->SupportedProtocols; 1548 coredev->fw_version = ver->rom_ver_major << 8 |
1549 ver->rom_ver_minor;
1024 1550
1025 complete(&coredev->version_ex_done); 1551 complete(&coredev->version_ex_done);
1026 break; 1552 break;
1027 } 1553 }
1028 case MSG_SMS_INIT_DEVICE_RES: 1554 case MSG_SMS_INIT_DEVICE_RES:
1029 sms_debug("MSG_SMS_INIT_DEVICE_RES");
1030 complete(&coredev->init_device_done); 1555 complete(&coredev->init_device_done);
1031 break; 1556 break;
1032 case MSG_SW_RELOAD_START_RES: 1557 case MSG_SW_RELOAD_START_RES:
1033 sms_debug("MSG_SW_RELOAD_START_RES");
1034 complete(&coredev->reload_start_done); 1558 complete(&coredev->reload_start_done);
1035 break; 1559 break;
1560 case MSG_SMS_DATA_VALIDITY_RES:
1561 {
1562 struct sms_msg_data *validity = (struct sms_msg_data *) phdr;
1563
1564 sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
1565 validity->msg_data[0]);
1566 complete(&coredev->data_validity_done);
1567 break;
1568 }
1036 case MSG_SMS_DATA_DOWNLOAD_RES: 1569 case MSG_SMS_DATA_DOWNLOAD_RES:
1037 complete(&coredev->data_download_done); 1570 complete(&coredev->data_download_done);
1038 break; 1571 break;
1039 case MSG_SW_RELOAD_EXEC_RES: 1572 case MSG_SW_RELOAD_EXEC_RES:
1040 sms_debug("MSG_SW_RELOAD_EXEC_RES");
1041 break; 1573 break;
1042 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES: 1574 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
1043 sms_debug("MSG_SMS_SWDOWNLOAD_TRIGGER_RES");
1044 complete(&coredev->trigger_done); 1575 complete(&coredev->trigger_done);
1045 break; 1576 break;
1046 case MSG_SMS_SLEEP_RESUME_COMP_IND: 1577 case MSG_SMS_SLEEP_RESUME_COMP_IND:
1047 complete(&coredev->resume_done); 1578 complete(&coredev->resume_done);
1048 break; 1579 break;
1049 case MSG_SMS_GPIO_CONFIG_EX_RES: 1580 case MSG_SMS_GPIO_CONFIG_EX_RES:
1050 sms_debug("MSG_SMS_GPIO_CONFIG_EX_RES");
1051 complete(&coredev->gpio_configuration_done); 1581 complete(&coredev->gpio_configuration_done);
1052 break; 1582 break;
1053 case MSG_SMS_GPIO_SET_LEVEL_RES: 1583 case MSG_SMS_GPIO_SET_LEVEL_RES:
1054 sms_debug("MSG_SMS_GPIO_SET_LEVEL_RES");
1055 complete(&coredev->gpio_set_level_done); 1584 complete(&coredev->gpio_set_level_done);
1056 break; 1585 break;
1057 case MSG_SMS_GPIO_GET_LEVEL_RES: 1586 case MSG_SMS_GPIO_GET_LEVEL_RES:
1058 { 1587 {
1059 u32 *msgdata = (u32 *) phdr; 1588 u32 *msgdata = (u32 *) phdr;
1060 coredev->gpio_get_res = msgdata[1]; 1589 coredev->gpio_get_res = msgdata[1];
1061 sms_debug("MSG_SMS_GPIO_GET_LEVEL_RES gpio level %d", 1590 sms_debug("gpio level %d",
1062 coredev->gpio_get_res); 1591 coredev->gpio_get_res);
1063 complete(&coredev->gpio_get_level_done); 1592 complete(&coredev->gpio_get_level_done);
1064 break; 1593 break;
@@ -1070,12 +1599,24 @@ void smscore_onresponse(struct smscore_device_t *coredev,
1070 sms_ir_event(coredev, 1599 sms_ir_event(coredev,
1071 (const char *) 1600 (const char *)
1072 ((char *)phdr 1601 ((char *)phdr
1073 + sizeof(struct SmsMsgHdr_ST)), 1602 + sizeof(struct sms_msg_hdr)),
1074 (int)phdr->msgLength 1603 (int)phdr->msg_length
1075 - sizeof(struct SmsMsgHdr_ST)); 1604 - sizeof(struct sms_msg_hdr));
1605 break;
1606
1607 case MSG_SMS_DVBT_BDA_DATA:
1608 /*
1609 * It can be received here, if the frontend is
1610 * tuned into a valid channel and the proper firmware
1611 * is loaded. That happens when the module got removed
1612 * and re-inserted, without powering the device off
1613 */
1076 break; 1614 break;
1077 1615
1078 default: 1616 default:
1617 sms_debug("message %s(%d) not handled.",
1618 smscore_translate_msg(phdr->msg_type),
1619 phdr->msg_type);
1079 break; 1620 break;
1080 } 1621 }
1081 smscore_putbuffer(coredev, cb); 1622 smscore_putbuffer(coredev, cb);
@@ -1257,7 +1798,7 @@ int smsclient_sendrequest(struct smscore_client_t *client,
1257 void *buffer, size_t size) 1798 void *buffer, size_t size)
1258{ 1799{
1259 struct smscore_device_t *coredev; 1800 struct smscore_device_t *coredev;
1260 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer; 1801 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;
1261 int rc; 1802 int rc;
1262 1803
1263 if (client == NULL) { 1804 if (client == NULL) {
@@ -1274,7 +1815,7 @@ int smsclient_sendrequest(struct smscore_client_t *client,
1274 } 1815 }
1275 1816
1276 rc = smscore_validate_client(client->coredev, client, 0, 1817 rc = smscore_validate_client(client->coredev, client, 0,
1277 phdr->msgSrcId); 1818 phdr->msg_src_id);
1278 if (rc < 0) 1819 if (rc < 0)
1279 return rc; 1820 return rc;
1280 1821
@@ -1288,16 +1829,16 @@ int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
1288 struct smscore_config_gpio *pinconfig) 1829 struct smscore_config_gpio *pinconfig)
1289{ 1830{
1290 struct { 1831 struct {
1291 struct SmsMsgHdr_ST hdr; 1832 struct sms_msg_hdr hdr;
1292 u32 data[6]; 1833 u32 data[6];
1293 } msg; 1834 } msg;
1294 1835
1295 if (coredev->device_flags & SMS_DEVICE_FAMILY2) { 1836 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
1296 msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 1837 msg.hdr.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1297 msg.hdr.msgDstId = HIF_TASK; 1838 msg.hdr.msg_dst_id = HIF_TASK;
1298 msg.hdr.msgFlags = 0; 1839 msg.hdr.msg_flags = 0;
1299 msg.hdr.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ; 1840 msg.hdr.msg_type = MSG_SMS_GPIO_CONFIG_EX_REQ;
1300 msg.hdr.msgLength = sizeof(msg); 1841 msg.hdr.msg_length = sizeof(msg);
1301 1842
1302 msg.data[0] = pin; 1843 msg.data[0] = pin;
1303 msg.data[1] = pinconfig->pullupdown; 1844 msg.data[1] = pinconfig->pullupdown;
@@ -1306,16 +1847,16 @@ int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
1306 msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0; 1847 msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0;
1307 1848
1308 switch (pinconfig->outputdriving) { 1849 switch (pinconfig->outputdriving) {
1309 case SMS_GPIO_OUTPUTDRIVING_16mA: 1850 case SMS_GPIO_OUTPUTDRIVING_S_16mA:
1310 msg.data[3] = 7; /* Nova - 16mA */ 1851 msg.data[3] = 7; /* Nova - 16mA */
1311 break; 1852 break;
1312 case SMS_GPIO_OUTPUTDRIVING_12mA: 1853 case SMS_GPIO_OUTPUTDRIVING_S_12mA:
1313 msg.data[3] = 5; /* Nova - 11mA */ 1854 msg.data[3] = 5; /* Nova - 11mA */
1314 break; 1855 break;
1315 case SMS_GPIO_OUTPUTDRIVING_8mA: 1856 case SMS_GPIO_OUTPUTDRIVING_S_8mA:
1316 msg.data[3] = 3; /* Nova - 7mA */ 1857 msg.data[3] = 3; /* Nova - 7mA */
1317 break; 1858 break;
1318 case SMS_GPIO_OUTPUTDRIVING_4mA: 1859 case SMS_GPIO_OUTPUTDRIVING_S_4mA:
1319 default: 1860 default:
1320 msg.data[3] = 2; /* Nova - 4mA */ 1861 msg.data[3] = 2; /* Nova - 4mA */
1321 break; 1862 break;
@@ -1333,18 +1874,18 @@ int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
1333int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level) 1874int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
1334{ 1875{
1335 struct { 1876 struct {
1336 struct SmsMsgHdr_ST hdr; 1877 struct sms_msg_hdr hdr;
1337 u32 data[3]; 1878 u32 data[3];
1338 } msg; 1879 } msg;
1339 1880
1340 if (pin > MAX_GPIO_PIN_NUMBER) 1881 if (pin > MAX_GPIO_PIN_NUMBER)
1341 return -EINVAL; 1882 return -EINVAL;
1342 1883
1343 msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 1884 msg.hdr.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1344 msg.hdr.msgDstId = HIF_TASK; 1885 msg.hdr.msg_dst_id = HIF_TASK;
1345 msg.hdr.msgFlags = 0; 1886 msg.hdr.msg_flags = 0;
1346 msg.hdr.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ; 1887 msg.hdr.msg_type = MSG_SMS_GPIO_SET_LEVEL_REQ;
1347 msg.hdr.msgLength = sizeof(msg); 1888 msg.hdr.msg_length = sizeof(msg);
1348 1889
1349 msg.data[0] = pin; 1890 msg.data[0] = pin;
1350 msg.data[1] = level ? 1 : 0; 1891 msg.data[1] = level ? 1 : 0;
@@ -1355,122 +1896,121 @@ int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
1355} 1896}
1356 1897
1357/* new GPIO management implementation */ 1898/* new GPIO management implementation */
1358static int GetGpioPinParams(u32 PinNum, u32 *pTranslatedPinNum, 1899static int get_gpio_pin_params(u32 pin_num, u32 *p_translatedpin_num,
1359 u32 *pGroupNum, u32 *pGroupCfg) { 1900 u32 *p_group_num, u32 *p_group_cfg) {
1360 1901
1361 *pGroupCfg = 1; 1902 *p_group_cfg = 1;
1362 1903
1363 if (PinNum <= 1) { 1904 if (pin_num <= 1) {
1364 *pTranslatedPinNum = 0; 1905 *p_translatedpin_num = 0;
1365 *pGroupNum = 9; 1906 *p_group_num = 9;
1366 *pGroupCfg = 2; 1907 *p_group_cfg = 2;
1367 } else if (PinNum >= 2 && PinNum <= 6) { 1908 } else if (pin_num >= 2 && pin_num <= 6) {
1368 *pTranslatedPinNum = 2; 1909 *p_translatedpin_num = 2;
1369 *pGroupNum = 0; 1910 *p_group_num = 0;
1370 *pGroupCfg = 2; 1911 *p_group_cfg = 2;
1371 } else if (PinNum >= 7 && PinNum <= 11) { 1912 } else if (pin_num >= 7 && pin_num <= 11) {
1372 *pTranslatedPinNum = 7; 1913 *p_translatedpin_num = 7;
1373 *pGroupNum = 1; 1914 *p_group_num = 1;
1374 } else if (PinNum >= 12 && PinNum <= 15) { 1915 } else if (pin_num >= 12 && pin_num <= 15) {
1375 *pTranslatedPinNum = 12; 1916 *p_translatedpin_num = 12;
1376 *pGroupNum = 2; 1917 *p_group_num = 2;
1377 *pGroupCfg = 3; 1918 *p_group_cfg = 3;
1378 } else if (PinNum == 16) { 1919 } else if (pin_num == 16) {
1379 *pTranslatedPinNum = 16; 1920 *p_translatedpin_num = 16;
1380 *pGroupNum = 23; 1921 *p_group_num = 23;
1381 } else if (PinNum >= 17 && PinNum <= 24) { 1922 } else if (pin_num >= 17 && pin_num <= 24) {
1382 *pTranslatedPinNum = 17; 1923 *p_translatedpin_num = 17;
1383 *pGroupNum = 3; 1924 *p_group_num = 3;
1384 } else if (PinNum == 25) { 1925 } else if (pin_num == 25) {
1385 *pTranslatedPinNum = 25; 1926 *p_translatedpin_num = 25;
1386 *pGroupNum = 6; 1927 *p_group_num = 6;
1387 } else if (PinNum >= 26 && PinNum <= 28) { 1928 } else if (pin_num >= 26 && pin_num <= 28) {
1388 *pTranslatedPinNum = 26; 1929 *p_translatedpin_num = 26;
1389 *pGroupNum = 4; 1930 *p_group_num = 4;
1390 } else if (PinNum == 29) { 1931 } else if (pin_num == 29) {
1391 *pTranslatedPinNum = 29; 1932 *p_translatedpin_num = 29;
1392 *pGroupNum = 5; 1933 *p_group_num = 5;
1393 *pGroupCfg = 2; 1934 *p_group_cfg = 2;
1394 } else if (PinNum == 30) { 1935 } else if (pin_num == 30) {
1395 *pTranslatedPinNum = 30; 1936 *p_translatedpin_num = 30;
1396 *pGroupNum = 8; 1937 *p_group_num = 8;
1397 } else if (PinNum == 31) { 1938 } else if (pin_num == 31) {
1398 *pTranslatedPinNum = 31; 1939 *p_translatedpin_num = 31;
1399 *pGroupNum = 17; 1940 *p_group_num = 17;
1400 } else 1941 } else
1401 return -1; 1942 return -1;
1402 1943
1403 *pGroupCfg <<= 24; 1944 *p_group_cfg <<= 24;
1404 1945
1405 return 0; 1946 return 0;
1406} 1947}
1407 1948
1408int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum, 1949int smscore_gpio_configure(struct smscore_device_t *coredev, u8 pin_num,
1409 struct smscore_gpio_config *pGpioConfig) { 1950 struct smscore_config_gpio *p_gpio_config) {
1410 1951
1411 u32 totalLen; 1952 u32 total_len;
1412 u32 TranslatedPinNum = 0; 1953 u32 translatedpin_num = 0;
1413 u32 GroupNum = 0; 1954 u32 group_num = 0;
1414 u32 ElectricChar; 1955 u32 electric_char;
1415 u32 groupCfg; 1956 u32 group_cfg;
1416 void *buffer; 1957 void *buffer;
1417 int rc; 1958 int rc;
1418 1959
1419 struct SetGpioMsg { 1960 struct set_gpio_msg {
1420 struct SmsMsgHdr_ST xMsgHeader; 1961 struct sms_msg_hdr x_msg_header;
1421 u32 msgData[6]; 1962 u32 msg_data[6];
1422 } *pMsg; 1963 } *p_msg;
1423 1964
1424 1965
1425 if (PinNum > MAX_GPIO_PIN_NUMBER) 1966 if (pin_num > MAX_GPIO_PIN_NUMBER)
1426 return -EINVAL; 1967 return -EINVAL;
1427 1968
1428 if (pGpioConfig == NULL) 1969 if (p_gpio_config == NULL)
1429 return -EINVAL; 1970 return -EINVAL;
1430 1971
1431 totalLen = sizeof(struct SmsMsgHdr_ST) + (sizeof(u32) * 6); 1972 total_len = sizeof(struct sms_msg_hdr) + (sizeof(u32) * 6);
1432 1973
1433 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT, 1974 buffer = kmalloc(total_len + SMS_DMA_ALIGNMENT,
1434 GFP_KERNEL | GFP_DMA); 1975 GFP_KERNEL | GFP_DMA);
1435 if (!buffer) 1976 if (!buffer)
1436 return -ENOMEM; 1977 return -ENOMEM;
1437 1978
1438 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer); 1979 p_msg = (struct set_gpio_msg *) SMS_ALIGN_ADDRESS(buffer);
1439 1980
1440 pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 1981 p_msg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1441 pMsg->xMsgHeader.msgDstId = HIF_TASK; 1982 p_msg->x_msg_header.msg_dst_id = HIF_TASK;
1442 pMsg->xMsgHeader.msgFlags = 0; 1983 p_msg->x_msg_header.msg_flags = 0;
1443 pMsg->xMsgHeader.msgLength = (u16) totalLen; 1984 p_msg->x_msg_header.msg_length = (u16) total_len;
1444 pMsg->msgData[0] = PinNum; 1985 p_msg->msg_data[0] = pin_num;
1445 1986
1446 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) { 1987 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
1447 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ; 1988 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_CONFIG_REQ;
1448 if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum, 1989 if (get_gpio_pin_params(pin_num, &translatedpin_num, &group_num,
1449 &groupCfg) != 0) { 1990 &group_cfg) != 0) {
1450 rc = -EINVAL; 1991 rc = -EINVAL;
1451 goto free; 1992 goto free;
1452 } 1993 }
1453 1994
1454 pMsg->msgData[1] = TranslatedPinNum; 1995 p_msg->msg_data[1] = translatedpin_num;
1455 pMsg->msgData[2] = GroupNum; 1996 p_msg->msg_data[2] = group_num;
1456 ElectricChar = (pGpioConfig->PullUpDown) 1997 electric_char = (p_gpio_config->pullupdown)
1457 | (pGpioConfig->InputCharacteristics << 2) 1998 | (p_gpio_config->inputcharacteristics << 2)
1458 | (pGpioConfig->OutputSlewRate << 3) 1999 | (p_gpio_config->outputslewrate << 3)
1459 | (pGpioConfig->OutputDriving << 4); 2000 | (p_gpio_config->outputdriving << 4);
1460 pMsg->msgData[3] = ElectricChar; 2001 p_msg->msg_data[3] = electric_char;
1461 pMsg->msgData[4] = pGpioConfig->Direction; 2002 p_msg->msg_data[4] = p_gpio_config->direction;
1462 pMsg->msgData[5] = groupCfg; 2003 p_msg->msg_data[5] = group_cfg;
1463 } else { 2004 } else {
1464 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ; 2005 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_CONFIG_EX_REQ;
1465 pMsg->msgData[1] = pGpioConfig->PullUpDown; 2006 p_msg->msg_data[1] = p_gpio_config->pullupdown;
1466 pMsg->msgData[2] = pGpioConfig->OutputSlewRate; 2007 p_msg->msg_data[2] = p_gpio_config->outputslewrate;
1467 pMsg->msgData[3] = pGpioConfig->OutputDriving; 2008 p_msg->msg_data[3] = p_gpio_config->outputdriving;
1468 pMsg->msgData[4] = pGpioConfig->Direction; 2009 p_msg->msg_data[4] = p_gpio_config->direction;
1469 pMsg->msgData[5] = 0; 2010 p_msg->msg_data[5] = 0;
1470 } 2011 }
1471 2012
1472 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg); 2013 rc = smscore_sendrequest_and_wait(coredev, p_msg, total_len,
1473 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1474 &coredev->gpio_configuration_done); 2014 &coredev->gpio_configuration_done);
1475 2015
1476 if (rc != 0) { 2016 if (rc != 0) {
@@ -1485,42 +2025,41 @@ free:
1485 return rc; 2025 return rc;
1486} 2026}
1487 2027
1488int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum, 2028int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 pin_num,
1489 u8 NewLevel) { 2029 u8 new_level) {
1490 2030
1491 u32 totalLen; 2031 u32 total_len;
1492 int rc; 2032 int rc;
1493 void *buffer; 2033 void *buffer;
1494 2034
1495 struct SetGpioMsg { 2035 struct set_gpio_msg {
1496 struct SmsMsgHdr_ST xMsgHeader; 2036 struct sms_msg_hdr x_msg_header;
1497 u32 msgData[3]; /* keep it 3 ! */ 2037 u32 msg_data[3]; /* keep it 3 ! */
1498 } *pMsg; 2038 } *p_msg;
1499 2039
1500 if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER)) 2040 if ((new_level > 1) || (pin_num > MAX_GPIO_PIN_NUMBER))
1501 return -EINVAL; 2041 return -EINVAL;
1502 2042
1503 totalLen = sizeof(struct SmsMsgHdr_ST) + 2043 total_len = sizeof(struct sms_msg_hdr) +
1504 (3 * sizeof(u32)); /* keep it 3 ! */ 2044 (3 * sizeof(u32)); /* keep it 3 ! */
1505 2045
1506 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT, 2046 buffer = kmalloc(total_len + SMS_DMA_ALIGNMENT,
1507 GFP_KERNEL | GFP_DMA); 2047 GFP_KERNEL | GFP_DMA);
1508 if (!buffer) 2048 if (!buffer)
1509 return -ENOMEM; 2049 return -ENOMEM;
1510 2050
1511 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer); 2051 p_msg = (struct set_gpio_msg *) SMS_ALIGN_ADDRESS(buffer);
1512 2052
1513 pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 2053 p_msg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1514 pMsg->xMsgHeader.msgDstId = HIF_TASK; 2054 p_msg->x_msg_header.msg_dst_id = HIF_TASK;
1515 pMsg->xMsgHeader.msgFlags = 0; 2055 p_msg->x_msg_header.msg_flags = 0;
1516 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ; 2056 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_SET_LEVEL_REQ;
1517 pMsg->xMsgHeader.msgLength = (u16) totalLen; 2057 p_msg->x_msg_header.msg_length = (u16) total_len;
1518 pMsg->msgData[0] = PinNum; 2058 p_msg->msg_data[0] = pin_num;
1519 pMsg->msgData[1] = NewLevel; 2059 p_msg->msg_data[1] = new_level;
1520 2060
1521 /* Send message to SMS */ 2061 /* Send message to SMS */
1522 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg); 2062 rc = smscore_sendrequest_and_wait(coredev, p_msg, total_len,
1523 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1524 &coredev->gpio_set_level_done); 2063 &coredev->gpio_set_level_done);
1525 2064
1526 if (rc != 0) { 2065 if (rc != 0) {
@@ -1534,42 +2073,41 @@ int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
1534 return rc; 2073 return rc;
1535} 2074}
1536 2075
1537int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum, 2076int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 pin_num,
1538 u8 *level) { 2077 u8 *level) {
1539 2078
1540 u32 totalLen; 2079 u32 total_len;
1541 int rc; 2080 int rc;
1542 void *buffer; 2081 void *buffer;
1543 2082
1544 struct SetGpioMsg { 2083 struct set_gpio_msg {
1545 struct SmsMsgHdr_ST xMsgHeader; 2084 struct sms_msg_hdr x_msg_header;
1546 u32 msgData[2]; 2085 u32 msg_data[2];
1547 } *pMsg; 2086 } *p_msg;
1548 2087
1549 2088
1550 if (PinNum > MAX_GPIO_PIN_NUMBER) 2089 if (pin_num > MAX_GPIO_PIN_NUMBER)
1551 return -EINVAL; 2090 return -EINVAL;
1552 2091
1553 totalLen = sizeof(struct SmsMsgHdr_ST) + (2 * sizeof(u32)); 2092 total_len = sizeof(struct sms_msg_hdr) + (2 * sizeof(u32));
1554 2093
1555 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT, 2094 buffer = kmalloc(total_len + SMS_DMA_ALIGNMENT,
1556 GFP_KERNEL | GFP_DMA); 2095 GFP_KERNEL | GFP_DMA);
1557 if (!buffer) 2096 if (!buffer)
1558 return -ENOMEM; 2097 return -ENOMEM;
1559 2098
1560 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer); 2099 p_msg = (struct set_gpio_msg *) SMS_ALIGN_ADDRESS(buffer);
1561 2100
1562 pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 2101 p_msg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1563 pMsg->xMsgHeader.msgDstId = HIF_TASK; 2102 p_msg->x_msg_header.msg_dst_id = HIF_TASK;
1564 pMsg->xMsgHeader.msgFlags = 0; 2103 p_msg->x_msg_header.msg_flags = 0;
1565 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_GET_LEVEL_REQ; 2104 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_GET_LEVEL_REQ;
1566 pMsg->xMsgHeader.msgLength = (u16) totalLen; 2105 p_msg->x_msg_header.msg_length = (u16) total_len;
1567 pMsg->msgData[0] = PinNum; 2106 p_msg->msg_data[0] = pin_num;
1568 pMsg->msgData[1] = 0; 2107 p_msg->msg_data[1] = 0;
1569 2108
1570 /* Send message to SMS */ 2109 /* Send message to SMS */
1571 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg); 2110 rc = smscore_sendrequest_and_wait(coredev, p_msg, total_len,
1572 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1573 &coredev->gpio_get_level_done); 2111 &coredev->gpio_get_level_done);
1574 2112
1575 if (rc != 0) { 2113 if (rc != 0) {
@@ -1635,3 +2173,27 @@ module_exit(smscore_module_exit);
1635MODULE_DESCRIPTION("Siano MDTV Core module"); 2173MODULE_DESCRIPTION("Siano MDTV Core module");
1636MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)"); 2174MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
1637MODULE_LICENSE("GPL"); 2175MODULE_LICENSE("GPL");
2176
2177/* This should match what's defined at smscoreapi.h */
2178MODULE_FIRMWARE(SMS_FW_ATSC_DENVER);
2179MODULE_FIRMWARE(SMS_FW_CMMB_MING_APP);
2180MODULE_FIRMWARE(SMS_FW_CMMB_VEGA_12MHZ);
2181MODULE_FIRMWARE(SMS_FW_CMMB_VENICE_12MHZ);
2182MODULE_FIRMWARE(SMS_FW_DVBH_RIO);
2183MODULE_FIRMWARE(SMS_FW_DVB_NOVA_12MHZ_B0);
2184MODULE_FIRMWARE(SMS_FW_DVB_NOVA_12MHZ);
2185MODULE_FIRMWARE(SMS_FW_DVB_RIO);
2186MODULE_FIRMWARE(SMS_FW_FM_RADIO);
2187MODULE_FIRMWARE(SMS_FW_FM_RADIO_RIO);
2188MODULE_FIRMWARE(SMS_FW_DVBT_HCW_55XXX);
2189MODULE_FIRMWARE(SMS_FW_ISDBT_HCW_55XXX);
2190MODULE_FIRMWARE(SMS_FW_ISDBT_NOVA_12MHZ_B0);
2191MODULE_FIRMWARE(SMS_FW_ISDBT_NOVA_12MHZ);
2192MODULE_FIRMWARE(SMS_FW_ISDBT_PELE);
2193MODULE_FIRMWARE(SMS_FW_ISDBT_RIO);
2194MODULE_FIRMWARE(SMS_FW_DVBT_NOVA_A);
2195MODULE_FIRMWARE(SMS_FW_DVBT_NOVA_B);
2196MODULE_FIRMWARE(SMS_FW_DVBT_STELLAR);
2197MODULE_FIRMWARE(SMS_FW_TDMB_DENVER);
2198MODULE_FIRMWARE(SMS_FW_TDMB_NOVA_12MHZ_B0);
2199MODULE_FIRMWARE(SMS_FW_TDMB_NOVA_12MHZ);
diff --git a/drivers/media/common/siano/smscoreapi.h b/drivers/media/common/siano/smscoreapi.h
index c592ae090397..d0799e323364 100644
--- a/drivers/media/common/siano/smscoreapi.h
+++ b/drivers/media/common/siano/smscoreapi.h
@@ -40,9 +40,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
40#define kmutex_trylock(_p_) mutex_trylock(_p_) 40#define kmutex_trylock(_p_) mutex_trylock(_p_)
41#define kmutex_unlock(_p_) mutex_unlock(_p_) 41#define kmutex_unlock(_p_) mutex_unlock(_p_)
42 42
43#ifndef min 43/*
44#define min(a, b) (((a) < (b)) ? (a) : (b)) 44 * Define the firmware names used by the driver.
45#endif 45 * Those should match what's used at smscoreapi.c and sms-cards.c
46 * including the MODULE_FIRMWARE() macros at the end of smscoreapi.c
47 */
48#define SMS_FW_ATSC_DENVER "atsc_denver.inp"
49#define SMS_FW_CMMB_MING_APP "cmmb_ming_app.inp"
50#define SMS_FW_CMMB_VEGA_12MHZ "cmmb_vega_12mhz.inp"
51#define SMS_FW_CMMB_VENICE_12MHZ "cmmb_venice_12mhz.inp"
52#define SMS_FW_DVBH_RIO "dvbh_rio.inp"
53#define SMS_FW_DVB_NOVA_12MHZ_B0 "dvb_nova_12mhz_b0.inp"
54#define SMS_FW_DVB_NOVA_12MHZ "dvb_nova_12mhz.inp"
55#define SMS_FW_DVB_RIO "dvb_rio.inp"
56#define SMS_FW_FM_RADIO "fm_radio.inp"
57#define SMS_FW_FM_RADIO_RIO "fm_radio_rio.inp"
58#define SMS_FW_DVBT_HCW_55XXX "sms1xxx-hcw-55xxx-dvbt-02.fw"
59#define SMS_FW_ISDBT_HCW_55XXX "sms1xxx-hcw-55xxx-isdbt-02.fw"
60#define SMS_FW_ISDBT_NOVA_12MHZ_B0 "isdbt_nova_12mhz_b0.inp"
61#define SMS_FW_ISDBT_NOVA_12MHZ "isdbt_nova_12mhz.inp"
62#define SMS_FW_ISDBT_PELE "isdbt_pele.inp"
63#define SMS_FW_ISDBT_RIO "isdbt_rio.inp"
64#define SMS_FW_DVBT_NOVA_A "sms1xxx-nova-a-dvbt-01.fw"
65#define SMS_FW_DVBT_NOVA_B "sms1xxx-nova-b-dvbt-01.fw"
66#define SMS_FW_DVBT_STELLAR "sms1xxx-stellar-dvbt-01.fw"
67#define SMS_FW_TDMB_DENVER "tdmb_denver.inp"
68#define SMS_FW_TDMB_NOVA_12MHZ_B0 "tdmb_nova_12mhz_b0.inp"
69#define SMS_FW_TDMB_NOVA_12MHZ "tdmb_nova_12mhz.inp"
46 70
47#define SMS_PROTOCOL_MAX_RAOUNDTRIP_MS (10000) 71#define SMS_PROTOCOL_MAX_RAOUNDTRIP_MS (10000)
48#define SMS_ALLOC_ALIGNMENT 128 72#define SMS_ALLOC_ALIGNMENT 128
@@ -50,18 +74,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
50#define SMS_ALIGN_ADDRESS(addr) \ 74#define SMS_ALIGN_ADDRESS(addr) \
51 ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1)) 75 ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
52 76
77#define SMS_DEVICE_FAMILY1 0
53#define SMS_DEVICE_FAMILY2 1 78#define SMS_DEVICE_FAMILY2 1
54#define SMS_ROM_NO_RESPONSE 2 79#define SMS_ROM_NO_RESPONSE 2
55#define SMS_DEVICE_NOT_READY 0x8000000 80#define SMS_DEVICE_NOT_READY 0x8000000
56 81
57enum sms_device_type_st { 82enum sms_device_type_st {
83 SMS_UNKNOWN_TYPE = -1,
58 SMS_STELLAR = 0, 84 SMS_STELLAR = 0,
59 SMS_NOVA_A0, 85 SMS_NOVA_A0,
60 SMS_NOVA_B0, 86 SMS_NOVA_B0,
61 SMS_VEGA, 87 SMS_VEGA,
88 SMS_VENICE,
89 SMS_MING,
90 SMS_PELE,
91 SMS_RIO,
92 SMS_DENVER_1530,
93 SMS_DENVER_2160,
62 SMS_NUM_OF_DEVICE_TYPES 94 SMS_NUM_OF_DEVICE_TYPES
63}; 95};
64 96
97enum sms_power_mode_st {
98 SMS_POWER_MODE_ACTIVE,
99 SMS_POWER_MODE_SUSPENDED
100};
101
65struct smscore_device_t; 102struct smscore_device_t;
66struct smscore_client_t; 103struct smscore_client_t;
67struct smscore_buffer_t; 104struct smscore_buffer_t;
@@ -149,6 +186,7 @@ struct smscore_device_t {
149 186
150 /* host <--> device messages */ 187 /* host <--> device messages */
151 struct completion version_ex_done, data_download_done, trigger_done; 188 struct completion version_ex_done, data_download_done, trigger_done;
189 struct completion data_validity_done, device_ready_done;
152 struct completion init_device_done, reload_start_done, resume_done; 190 struct completion init_device_done, reload_start_done, resume_done;
153 struct completion gpio_configuration_done, gpio_set_level_done; 191 struct completion gpio_configuration_done, gpio_set_level_done;
154 struct completion gpio_get_level_done, ir_init_done; 192 struct completion gpio_get_level_done, ir_init_done;
@@ -165,10 +203,17 @@ struct smscore_device_t {
165 /* Firmware */ 203 /* Firmware */
166 u8 *fw_buf; 204 u8 *fw_buf;
167 u32 fw_buf_size; 205 u32 fw_buf_size;
206 u16 fw_version;
168 207
169 /* Infrared (IR) */ 208 /* Infrared (IR) */
170 struct ir_t ir; 209 struct ir_t ir;
171 210
211 /*
212 * Identify if device is USB or not.
213 * Used by smsdvb-sysfs to know the root node for debugfs
214 */
215 bool is_usb_device;
216
172 int led_state; 217 int led_state;
173}; 218};
174 219
@@ -176,81 +221,363 @@ struct smscore_device_t {
176#define SMS_ANTENNA_GPIO_0 1 221#define SMS_ANTENNA_GPIO_0 1
177#define SMS_ANTENNA_GPIO_1 0 222#define SMS_ANTENNA_GPIO_1 0
178 223
179#define BW_8_MHZ 0 224enum sms_bandwidth_mode {
180#define BW_7_MHZ 1 225 BW_8_MHZ = 0,
181#define BW_6_MHZ 2 226 BW_7_MHZ = 1,
182#define BW_5_MHZ 3 227 BW_6_MHZ = 2,
183#define BW_ISDBT_1SEG 4 228 BW_5_MHZ = 3,
184#define BW_ISDBT_3SEG 5 229 BW_ISDBT_1SEG = 4,
230 BW_ISDBT_3SEG = 5,
231 BW_2_MHZ = 6,
232 BW_FM_RADIO = 7,
233 BW_ISDBT_13SEG = 8,
234 BW_1_5_MHZ = 15,
235 BW_UNKNOWN = 0xffff
236};
237
185 238
186#define MSG_HDR_FLAG_SPLIT_MSG 4 239#define MSG_HDR_FLAG_SPLIT_MSG 4
187 240
188#define MAX_GPIO_PIN_NUMBER 31 241#define MAX_GPIO_PIN_NUMBER 31
189 242
190#define HIF_TASK 11 243#define HIF_TASK 11
244#define HIF_TASK_SLAVE 22
245#define HIF_TASK_SLAVE2 33
246#define HIF_TASK_SLAVE3 44
191#define SMS_HOST_LIB 150 247#define SMS_HOST_LIB 150
192#define DVBT_BDA_CONTROL_MSG_ID 201 248#define DVBT_BDA_CONTROL_MSG_ID 201
193 249
194#define SMS_MAX_PAYLOAD_SIZE 240 250#define SMS_MAX_PAYLOAD_SIZE 240
195#define SMS_TUNE_TIMEOUT 500 251#define SMS_TUNE_TIMEOUT 500
196 252
197#define MSG_SMS_GPIO_CONFIG_REQ 507 253enum msg_types {
198#define MSG_SMS_GPIO_CONFIG_RES 508 254 MSG_TYPE_BASE_VAL = 500,
199#define MSG_SMS_GPIO_SET_LEVEL_REQ 509 255 MSG_SMS_GET_VERSION_REQ = 503,
200#define MSG_SMS_GPIO_SET_LEVEL_RES 510 256 MSG_SMS_GET_VERSION_RES = 504,
201#define MSG_SMS_GPIO_GET_LEVEL_REQ 511 257 MSG_SMS_MULTI_BRIDGE_CFG = 505,
202#define MSG_SMS_GPIO_GET_LEVEL_RES 512 258 MSG_SMS_GPIO_CONFIG_REQ = 507,
203#define MSG_SMS_RF_TUNE_REQ 561 259 MSG_SMS_GPIO_CONFIG_RES = 508,
204#define MSG_SMS_RF_TUNE_RES 562 260 MSG_SMS_GPIO_SET_LEVEL_REQ = 509,
205#define MSG_SMS_INIT_DEVICE_REQ 578 261 MSG_SMS_GPIO_SET_LEVEL_RES = 510,
206#define MSG_SMS_INIT_DEVICE_RES 579 262 MSG_SMS_GPIO_GET_LEVEL_REQ = 511,
207#define MSG_SMS_ADD_PID_FILTER_REQ 601 263 MSG_SMS_GPIO_GET_LEVEL_RES = 512,
208#define MSG_SMS_ADD_PID_FILTER_RES 602 264 MSG_SMS_EEPROM_BURN_IND = 513,
209#define MSG_SMS_REMOVE_PID_FILTER_REQ 603 265 MSG_SMS_LOG_ENABLE_CHANGE_REQ = 514,
210#define MSG_SMS_REMOVE_PID_FILTER_RES 604 266 MSG_SMS_LOG_ENABLE_CHANGE_RES = 515,
211#define MSG_SMS_DAB_CHANNEL 607 267 MSG_SMS_SET_MAX_TX_MSG_LEN_REQ = 516,
212#define MSG_SMS_GET_PID_FILTER_LIST_REQ 608 268 MSG_SMS_SET_MAX_TX_MSG_LEN_RES = 517,
213#define MSG_SMS_GET_PID_FILTER_LIST_RES 609 269 MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE = 518,
214#define MSG_SMS_GET_STATISTICS_RES 616 270 MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST = 519,
215#define MSG_SMS_GET_STATISTICS_REQ 615 271 MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ = 520,
216#define MSG_SMS_HO_PER_SLICES_IND 630 272 MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES = 521,
217#define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651 273 MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND = 522,
218#define MSG_SMS_SET_ANTENNA_CONFIG_RES 652 274 MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND = 523,
219#define MSG_SMS_SLEEP_RESUME_COMP_IND 655 275 MSG_SMS_CONFIGURE_RF_SWITCH_REQ = 524,
220#define MSG_SMS_DATA_DOWNLOAD_REQ 660 276 MSG_SMS_CONFIGURE_RF_SWITCH_RES = 525,
221#define MSG_SMS_DATA_DOWNLOAD_RES 661 277 MSG_SMS_MRC_PATH_DISCONNECT_REQ = 526,
222#define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664 278 MSG_SMS_MRC_PATH_DISCONNECT_RES = 527,
223#define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665 279 MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ = 528,
224#define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666 280 MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES = 529,
225#define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667 281 MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ = 530,
226#define MSG_SMS_GET_VERSION_EX_REQ 668 282 MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES = 531,
227#define MSG_SMS_GET_VERSION_EX_RES 669 283 MSG_WR_REG_RFT_REQ = 533,
228#define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670 284 MSG_WR_REG_RFT_RES = 534,
229#define MSG_SMS_I2C_SET_FREQ_REQ 685 285 MSG_RD_REG_RFT_REQ = 535,
230#define MSG_SMS_GENERIC_I2C_REQ 687 286 MSG_RD_REG_RFT_RES = 536,
231#define MSG_SMS_GENERIC_I2C_RES 688 287 MSG_RD_REG_ALL_RFT_REQ = 537,
232#define MSG_SMS_DVBT_BDA_DATA 693 288 MSG_RD_REG_ALL_RFT_RES = 538,
233#define MSG_SW_RELOAD_REQ 697 289 MSG_HELP_INT = 539,
234#define MSG_SMS_DATA_MSG 699 290 MSG_RUN_SCRIPT_INT = 540,
235#define MSG_SW_RELOAD_START_REQ 702 291 MSG_SMS_EWS_INBAND_REQ = 541,
236#define MSG_SW_RELOAD_START_RES 703 292 MSG_SMS_EWS_INBAND_RES = 542,
237#define MSG_SW_RELOAD_EXEC_REQ 704 293 MSG_SMS_RFS_SELECT_REQ = 543,
238#define MSG_SW_RELOAD_EXEC_RES 705 294 MSG_SMS_RFS_SELECT_RES = 544,
239#define MSG_SMS_SPI_INT_LINE_SET_REQ 710 295 MSG_SMS_MB_GET_VER_REQ = 545,
240#define MSG_SMS_GPIO_CONFIG_EX_REQ 712 296 MSG_SMS_MB_GET_VER_RES = 546,
241#define MSG_SMS_GPIO_CONFIG_EX_RES 713 297 MSG_SMS_MB_WRITE_CFGFILE_REQ = 547,
242#define MSG_SMS_ISDBT_TUNE_REQ 776 298 MSG_SMS_MB_WRITE_CFGFILE_RES = 548,
243#define MSG_SMS_ISDBT_TUNE_RES 777 299 MSG_SMS_MB_READ_CFGFILE_REQ = 549,
244#define MSG_SMS_TRANSMISSION_IND 782 300 MSG_SMS_MB_READ_CFGFILE_RES = 550,
245#define MSG_SMS_START_IR_REQ 800 301 MSG_SMS_RD_MEM_REQ = 552,
246#define MSG_SMS_START_IR_RES 801 302 MSG_SMS_RD_MEM_RES = 553,
247#define MSG_SMS_IR_SAMPLES_IND 802 303 MSG_SMS_WR_MEM_REQ = 554,
248#define MSG_SMS_SIGNAL_DETECTED_IND 827 304 MSG_SMS_WR_MEM_RES = 555,
249#define MSG_SMS_NO_SIGNAL_IND 828 305 MSG_SMS_UPDATE_MEM_REQ = 556,
306 MSG_SMS_UPDATE_MEM_RES = 557,
307 MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ = 558,
308 MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES = 559,
309 MSG_SMS_RF_TUNE_REQ = 561,
310 MSG_SMS_RF_TUNE_RES = 562,
311 MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ = 563,
312 MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES = 564,
313 MSG_SMS_ISDBT_SB_RECEPTION_REQ = 565,
314 MSG_SMS_ISDBT_SB_RECEPTION_RES = 566,
315 MSG_SMS_GENERIC_EPROM_WRITE_REQ = 567,
316 MSG_SMS_GENERIC_EPROM_WRITE_RES = 568,
317 MSG_SMS_GENERIC_EPROM_READ_REQ = 569,
318 MSG_SMS_GENERIC_EPROM_READ_RES = 570,
319 MSG_SMS_EEPROM_WRITE_REQ = 571,
320 MSG_SMS_EEPROM_WRITE_RES = 572,
321 MSG_SMS_CUSTOM_READ_REQ = 574,
322 MSG_SMS_CUSTOM_READ_RES = 575,
323 MSG_SMS_CUSTOM_WRITE_REQ = 576,
324 MSG_SMS_CUSTOM_WRITE_RES = 577,
325 MSG_SMS_INIT_DEVICE_REQ = 578,
326 MSG_SMS_INIT_DEVICE_RES = 579,
327 MSG_SMS_ATSC_SET_ALL_IP_REQ = 580,
328 MSG_SMS_ATSC_SET_ALL_IP_RES = 581,
329 MSG_SMS_ATSC_START_ENSEMBLE_REQ = 582,
330 MSG_SMS_ATSC_START_ENSEMBLE_RES = 583,
331 MSG_SMS_SET_OUTPUT_MODE_REQ = 584,
332 MSG_SMS_SET_OUTPUT_MODE_RES = 585,
333 MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ = 586,
334 MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES = 587,
335 MSG_SMS_SUB_CHANNEL_START_REQ = 589,
336 MSG_SMS_SUB_CHANNEL_START_RES = 590,
337 MSG_SMS_SUB_CHANNEL_STOP_REQ = 591,
338 MSG_SMS_SUB_CHANNEL_STOP_RES = 592,
339 MSG_SMS_ATSC_IP_FILTER_ADD_REQ = 593,
340 MSG_SMS_ATSC_IP_FILTER_ADD_RES = 594,
341 MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ = 595,
342 MSG_SMS_ATSC_IP_FILTER_REMOVE_RES = 596,
343 MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ = 597,
344 MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES = 598,
345 MSG_SMS_WAIT_CMD = 599,
346 MSG_SMS_ADD_PID_FILTER_REQ = 601,
347 MSG_SMS_ADD_PID_FILTER_RES = 602,
348 MSG_SMS_REMOVE_PID_FILTER_REQ = 603,
349 MSG_SMS_REMOVE_PID_FILTER_RES = 604,
350 MSG_SMS_FAST_INFORMATION_CHANNEL_REQ = 605,
351 MSG_SMS_FAST_INFORMATION_CHANNEL_RES = 606,
352 MSG_SMS_DAB_CHANNEL = 607,
353 MSG_SMS_GET_PID_FILTER_LIST_REQ = 608,
354 MSG_SMS_GET_PID_FILTER_LIST_RES = 609,
355 MSG_SMS_POWER_DOWN_REQ = 610,
356 MSG_SMS_POWER_DOWN_RES = 611,
357 MSG_SMS_ATSC_SLT_EXIST_IND = 612,
358 MSG_SMS_ATSC_NO_SLT_IND = 613,
359 MSG_SMS_GET_STATISTICS_REQ = 615,
360 MSG_SMS_GET_STATISTICS_RES = 616,
361 MSG_SMS_SEND_DUMP = 617,
362 MSG_SMS_SCAN_START_REQ = 618,
363 MSG_SMS_SCAN_START_RES = 619,
364 MSG_SMS_SCAN_STOP_REQ = 620,
365 MSG_SMS_SCAN_STOP_RES = 621,
366 MSG_SMS_SCAN_PROGRESS_IND = 622,
367 MSG_SMS_SCAN_COMPLETE_IND = 623,
368 MSG_SMS_LOG_ITEM = 624,
369 MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ = 628,
370 MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES = 629,
371 MSG_SMS_HO_PER_SLICES_IND = 630,
372 MSG_SMS_HO_INBAND_POWER_IND = 631,
373 MSG_SMS_MANUAL_DEMOD_REQ = 632,
374 MSG_SMS_HO_TUNE_ON_REQ = 636,
375 MSG_SMS_HO_TUNE_ON_RES = 637,
376 MSG_SMS_HO_TUNE_OFF_REQ = 638,
377 MSG_SMS_HO_TUNE_OFF_RES = 639,
378 MSG_SMS_HO_PEEK_FREQ_REQ = 640,
379 MSG_SMS_HO_PEEK_FREQ_RES = 641,
380 MSG_SMS_HO_PEEK_FREQ_IND = 642,
381 MSG_SMS_MB_ATTEN_SET_REQ = 643,
382 MSG_SMS_MB_ATTEN_SET_RES = 644,
383 MSG_SMS_ENABLE_STAT_IN_I2C_REQ = 649,
384 MSG_SMS_ENABLE_STAT_IN_I2C_RES = 650,
385 MSG_SMS_SET_ANTENNA_CONFIG_REQ = 651,
386 MSG_SMS_SET_ANTENNA_CONFIG_RES = 652,
387 MSG_SMS_GET_STATISTICS_EX_REQ = 653,
388 MSG_SMS_GET_STATISTICS_EX_RES = 654,
389 MSG_SMS_SLEEP_RESUME_COMP_IND = 655,
390 MSG_SMS_SWITCH_HOST_INTERFACE_REQ = 656,
391 MSG_SMS_SWITCH_HOST_INTERFACE_RES = 657,
392 MSG_SMS_DATA_DOWNLOAD_REQ = 660,
393 MSG_SMS_DATA_DOWNLOAD_RES = 661,
394 MSG_SMS_DATA_VALIDITY_REQ = 662,
395 MSG_SMS_DATA_VALIDITY_RES = 663,
396 MSG_SMS_SWDOWNLOAD_TRIGGER_REQ = 664,
397 MSG_SMS_SWDOWNLOAD_TRIGGER_RES = 665,
398 MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ = 666,
399 MSG_SMS_SWDOWNLOAD_BACKDOOR_RES = 667,
400 MSG_SMS_GET_VERSION_EX_REQ = 668,
401 MSG_SMS_GET_VERSION_EX_RES = 669,
402 MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ = 670,
403 MSG_SMS_CLOCK_OUTPUT_CONFIG_RES = 671,
404 MSG_SMS_I2C_SET_FREQ_REQ = 685,
405 MSG_SMS_I2C_SET_FREQ_RES = 686,
406 MSG_SMS_GENERIC_I2C_REQ = 687,
407 MSG_SMS_GENERIC_I2C_RES = 688,
408 MSG_SMS_DVBT_BDA_DATA = 693,
409 MSG_SW_RELOAD_REQ = 697,
410 MSG_SMS_DATA_MSG = 699,
411 MSG_TABLE_UPLOAD_REQ = 700,
412 MSG_TABLE_UPLOAD_RES = 701,
413 MSG_SW_RELOAD_START_REQ = 702,
414 MSG_SW_RELOAD_START_RES = 703,
415 MSG_SW_RELOAD_EXEC_REQ = 704,
416 MSG_SW_RELOAD_EXEC_RES = 705,
417 MSG_SMS_SPI_INT_LINE_SET_REQ = 710,
418 MSG_SMS_SPI_INT_LINE_SET_RES = 711,
419 MSG_SMS_GPIO_CONFIG_EX_REQ = 712,
420 MSG_SMS_GPIO_CONFIG_EX_RES = 713,
421 MSG_SMS_WATCHDOG_ACT_REQ = 716,
422 MSG_SMS_WATCHDOG_ACT_RES = 717,
423 MSG_SMS_LOOPBACK_REQ = 718,
424 MSG_SMS_LOOPBACK_RES = 719,
425 MSG_SMS_RAW_CAPTURE_START_REQ = 720,
426 MSG_SMS_RAW_CAPTURE_START_RES = 721,
427 MSG_SMS_RAW_CAPTURE_ABORT_REQ = 722,
428 MSG_SMS_RAW_CAPTURE_ABORT_RES = 723,
429 MSG_SMS_RAW_CAPTURE_COMPLETE_IND = 728,
430 MSG_SMS_DATA_PUMP_IND = 729,
431 MSG_SMS_DATA_PUMP_REQ = 730,
432 MSG_SMS_DATA_PUMP_RES = 731,
433 MSG_SMS_FLASH_DL_REQ = 732,
434 MSG_SMS_EXEC_TEST_1_REQ = 734,
435 MSG_SMS_EXEC_TEST_1_RES = 735,
436 MSG_SMS_ENBALE_TS_INTERFACE_REQ = 736,
437 MSG_SMS_ENBALE_TS_INTERFACE_RES = 737,
438 MSG_SMS_SPI_SET_BUS_WIDTH_REQ = 738,
439 MSG_SMS_SPI_SET_BUS_WIDTH_RES = 739,
440 MSG_SMS_SEND_EMM_REQ = 740,
441 MSG_SMS_SEND_EMM_RES = 741,
442 MSG_SMS_DISABLE_TS_INTERFACE_REQ = 742,
443 MSG_SMS_DISABLE_TS_INTERFACE_RES = 743,
444 MSG_SMS_IS_BUF_FREE_REQ = 744,
445 MSG_SMS_IS_BUF_FREE_RES = 745,
446 MSG_SMS_EXT_ANTENNA_REQ = 746,
447 MSG_SMS_EXT_ANTENNA_RES = 747,
448 MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE = 748,
449 MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE = 749,
450 MSG_SMS_BATTERY_LEVEL_REQ = 750,
451 MSG_SMS_BATTERY_LEVEL_RES = 751,
452 MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE = 752,
453 MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE = 753,
454 MSG_SMS_FM_RADIO_BLOCK_IND = 754,
455 MSG_SMS_HOST_NOTIFICATION_IND = 755,
456 MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE = 756,
457 MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE = 757,
458 MSG_SMS_CMMB_GET_NETWORKS_REQ = 760,
459 MSG_SMS_CMMB_GET_NETWORKS_RES = 761,
460 MSG_SMS_CMMB_START_SERVICE_REQ = 762,
461 MSG_SMS_CMMB_START_SERVICE_RES = 763,
462 MSG_SMS_CMMB_STOP_SERVICE_REQ = 764,
463 MSG_SMS_CMMB_STOP_SERVICE_RES = 765,
464 MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ = 768,
465 MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES = 769,
466 MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ = 770,
467 MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES = 771,
468 MSG_SMS_CMMB_START_CONTROL_INFO_REQ = 772,
469 MSG_SMS_CMMB_START_CONTROL_INFO_RES = 773,
470 MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ = 774,
471 MSG_SMS_CMMB_STOP_CONTROL_INFO_RES = 775,
472 MSG_SMS_ISDBT_TUNE_REQ = 776,
473 MSG_SMS_ISDBT_TUNE_RES = 777,
474 MSG_SMS_TRANSMISSION_IND = 782,
475 MSG_SMS_PID_STATISTICS_IND = 783,
476 MSG_SMS_POWER_DOWN_IND = 784,
477 MSG_SMS_POWER_DOWN_CONF = 785,
478 MSG_SMS_POWER_UP_IND = 786,
479 MSG_SMS_POWER_UP_CONF = 787,
480 MSG_SMS_POWER_MODE_SET_REQ = 790,
481 MSG_SMS_POWER_MODE_SET_RES = 791,
482 MSG_SMS_DEBUG_HOST_EVENT_REQ = 792,
483 MSG_SMS_DEBUG_HOST_EVENT_RES = 793,
484 MSG_SMS_NEW_CRYSTAL_REQ = 794,
485 MSG_SMS_NEW_CRYSTAL_RES = 795,
486 MSG_SMS_CONFIG_SPI_REQ = 796,
487 MSG_SMS_CONFIG_SPI_RES = 797,
488 MSG_SMS_I2C_SHORT_STAT_IND = 798,
489 MSG_SMS_START_IR_REQ = 800,
490 MSG_SMS_START_IR_RES = 801,
491 MSG_SMS_IR_SAMPLES_IND = 802,
492 MSG_SMS_CMMB_CA_SERVICE_IND = 803,
493 MSG_SMS_SLAVE_DEVICE_DETECTED = 804,
494 MSG_SMS_INTERFACE_LOCK_IND = 805,
495 MSG_SMS_INTERFACE_UNLOCK_IND = 806,
496 MSG_SMS_SEND_ROSUM_BUFF_REQ = 810,
497 MSG_SMS_SEND_ROSUM_BUFF_RES = 811,
498 MSG_SMS_ROSUM_BUFF = 812,
499 MSG_SMS_SET_AES128_KEY_REQ = 815,
500 MSG_SMS_SET_AES128_KEY_RES = 816,
501 MSG_SMS_MBBMS_WRITE_REQ = 817,
502 MSG_SMS_MBBMS_WRITE_RES = 818,
503 MSG_SMS_MBBMS_READ_IND = 819,
504 MSG_SMS_IQ_STREAM_START_REQ = 820,
505 MSG_SMS_IQ_STREAM_START_RES = 821,
506 MSG_SMS_IQ_STREAM_STOP_REQ = 822,
507 MSG_SMS_IQ_STREAM_STOP_RES = 823,
508 MSG_SMS_IQ_STREAM_DATA_BLOCK = 824,
509 MSG_SMS_GET_EEPROM_VERSION_REQ = 825,
510 MSG_SMS_GET_EEPROM_VERSION_RES = 826,
511 MSG_SMS_SIGNAL_DETECTED_IND = 827,
512 MSG_SMS_NO_SIGNAL_IND = 828,
513 MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ = 830,
514 MSG_SMS_MRC_SHUTDOWN_SLAVE_RES = 831,
515 MSG_SMS_MRC_BRINGUP_SLAVE_REQ = 832,
516 MSG_SMS_MRC_BRINGUP_SLAVE_RES = 833,
517 MSG_SMS_EXTERNAL_LNA_CTRL_REQ = 834,
518 MSG_SMS_EXTERNAL_LNA_CTRL_RES = 835,
519 MSG_SMS_SET_PERIODIC_STATISTICS_REQ = 836,
520 MSG_SMS_SET_PERIODIC_STATISTICS_RES = 837,
521 MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ = 838,
522 MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES = 839,
523 LOCAL_TUNE = 850,
524 LOCAL_IFFT_H_ICI = 851,
525 MSG_RESYNC_REQ = 852,
526 MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ = 853,
527 MSG_SMS_CMMB_GET_MRC_STATISTICS_RES = 854,
528 MSG_SMS_LOG_EX_ITEM = 855,
529 MSG_SMS_DEVICE_DATA_LOSS_IND = 856,
530 MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND = 857,
531 MSG_SMS_USER_MSG_REQ = 858,
532 MSG_SMS_USER_MSG_RES = 859,
533 MSG_SMS_SMART_CARD_INIT_REQ = 860,
534 MSG_SMS_SMART_CARD_INIT_RES = 861,
535 MSG_SMS_SMART_CARD_WRITE_REQ = 862,
536 MSG_SMS_SMART_CARD_WRITE_RES = 863,
537 MSG_SMS_SMART_CARD_READ_IND = 864,
538 MSG_SMS_TSE_ENABLE_REQ = 866,
539 MSG_SMS_TSE_ENABLE_RES = 867,
540 MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ = 868,
541 MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES = 869,
542 MSG_SMS_LED_CONFIG_REQ = 870,
543 MSG_SMS_LED_CONFIG_RES = 871,
544 MSG_PWM_ANTENNA_REQ = 872,
545 MSG_PWM_ANTENNA_RES = 873,
546 MSG_SMS_CMMB_SMD_SN_REQ = 874,
547 MSG_SMS_CMMB_SMD_SN_RES = 875,
548 MSG_SMS_CMMB_SET_CA_CW_REQ = 876,
549 MSG_SMS_CMMB_SET_CA_CW_RES = 877,
550 MSG_SMS_CMMB_SET_CA_SALT_REQ = 878,
551 MSG_SMS_CMMB_SET_CA_SALT_RES = 879,
552 MSG_SMS_NSCD_INIT_REQ = 880,
553 MSG_SMS_NSCD_INIT_RES = 881,
554 MSG_SMS_NSCD_PROCESS_SECTION_REQ = 882,
555 MSG_SMS_NSCD_PROCESS_SECTION_RES = 883,
556 MSG_SMS_DBD_CREATE_OBJECT_REQ = 884,
557 MSG_SMS_DBD_CREATE_OBJECT_RES = 885,
558 MSG_SMS_DBD_CONFIGURE_REQ = 886,
559 MSG_SMS_DBD_CONFIGURE_RES = 887,
560 MSG_SMS_DBD_SET_KEYS_REQ = 888,
561 MSG_SMS_DBD_SET_KEYS_RES = 889,
562 MSG_SMS_DBD_PROCESS_HEADER_REQ = 890,
563 MSG_SMS_DBD_PROCESS_HEADER_RES = 891,
564 MSG_SMS_DBD_PROCESS_DATA_REQ = 892,
565 MSG_SMS_DBD_PROCESS_DATA_RES = 893,
566 MSG_SMS_DBD_PROCESS_GET_DATA_REQ = 894,
567 MSG_SMS_DBD_PROCESS_GET_DATA_RES = 895,
568 MSG_SMS_NSCD_OPEN_SESSION_REQ = 896,
569 MSG_SMS_NSCD_OPEN_SESSION_RES = 897,
570 MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ = 898,
571 MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES = 899,
572 MSG_LAST_MSG_TYPE = 900,
573};
250 574
251#define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \ 575#define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
252 (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \ 576 (ptr)->msg_type = type; \
253 (ptr)->msgLength = len; (ptr)->msgFlags = 0; \ 577 (ptr)->msg_src_id = src; \
578 (ptr)->msg_dst_id = dst; \
579 (ptr)->msg_length = len; \
580 (ptr)->msg_flags = 0; \
254} while (0) 581} while (0)
255 582
256#define SMS_INIT_MSG(ptr, type, len) \ 583#define SMS_INIT_MSG(ptr, type, len) \
@@ -277,228 +604,296 @@ enum SMS_DEVICE_MODE {
277 DEVICE_MODE_ISDBT_BDA, 604 DEVICE_MODE_ISDBT_BDA,
278 DEVICE_MODE_CMMB, 605 DEVICE_MODE_CMMB,
279 DEVICE_MODE_RAW_TUNER, 606 DEVICE_MODE_RAW_TUNER,
607 DEVICE_MODE_FM_RADIO,
608 DEVICE_MODE_FM_RADIO_BDA,
609 DEVICE_MODE_ATSC,
280 DEVICE_MODE_MAX, 610 DEVICE_MODE_MAX,
281}; 611};
282 612
283struct SmsMsgHdr_ST { 613struct sms_msg_hdr {
284 u16 msgType; 614 u16 msg_type;
285 u8 msgSrcId; 615 u8 msg_src_id;
286 u8 msgDstId; 616 u8 msg_dst_id;
287 u16 msgLength; /* Length of entire message, including header */ 617 u16 msg_length; /* length of entire message, including header */
288 u16 msgFlags; 618 u16 msg_flags;
619};
620
621struct sms_msg_data {
622 struct sms_msg_hdr x_msg_header;
623 u32 msg_data[1];
289}; 624};
290 625
291struct SmsMsgData_ST { 626struct sms_msg_data2 {
292 struct SmsMsgHdr_ST xMsgHeader; 627 struct sms_msg_hdr x_msg_header;
293 u32 msgData[1]; 628 u32 msg_data[2];
294}; 629};
295 630
296struct SmsMsgData_ST2 { 631struct sms_msg_data4 {
297 struct SmsMsgHdr_ST xMsgHeader; 632 struct sms_msg_hdr x_msg_header;
298 u32 msgData[2]; 633 u32 msg_data[4];
299}; 634};
300 635
301struct SmsDataDownload_ST { 636struct sms_data_download {
302 struct SmsMsgHdr_ST xMsgHeader; 637 struct sms_msg_hdr x_msg_header;
303 u32 MemAddr; 638 u32 mem_addr;
304 u8 Payload[SMS_MAX_PAYLOAD_SIZE]; 639 u8 payload[SMS_MAX_PAYLOAD_SIZE];
305}; 640};
306 641
307struct SmsVersionRes_ST { 642struct sms_version_res {
308 struct SmsMsgHdr_ST xMsgHeader; 643 struct sms_msg_hdr x_msg_header;
309 644
310 u16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */ 645 u16 chip_model; /* e.g. 0x1102 for SMS-1102 "Nova" */
311 u8 Step; /* 0 - Step A */ 646 u8 step; /* 0 - step A */
312 u8 MetalFix; /* 0 - Metal 0 */ 647 u8 metal_fix; /* 0 - Metal 0 */
313 648
314 /* FirmwareId 0xFF if ROM, otherwise the 649 /* firmware_id 0xFF if ROM, otherwise the
315 * value indicated by SMSHOSTLIB_DEVICE_MODES_E */ 650 * value indicated by SMSHOSTLIB_DEVICE_MODES_E */
316 u8 FirmwareId; 651 u8 firmware_id;
317 /* SupportedProtocols Bitwise OR combination of 652 /* supported_protocols Bitwise OR combination of
318 * supported protocols */ 653 * supported protocols */
319 u8 SupportedProtocols; 654 u8 supported_protocols;
320 655
321 u8 VersionMajor; 656 u8 version_major;
322 u8 VersionMinor; 657 u8 version_minor;
323 u8 VersionPatch; 658 u8 version_patch;
324 u8 VersionFieldPatch; 659 u8 version_field_patch;
325 660
326 u8 RomVersionMajor; 661 u8 rom_ver_major;
327 u8 RomVersionMinor; 662 u8 rom_ver_minor;
328 u8 RomVersionPatch; 663 u8 rom_ver_patch;
329 u8 RomVersionFieldPatch; 664 u8 rom_ver_field_patch;
330 665
331 u8 TextLabel[34]; 666 u8 TextLabel[34];
332}; 667};
333 668
334struct SmsFirmware_ST { 669struct sms_firmware {
335 u32 CheckSum; 670 u32 check_sum;
336 u32 Length; 671 u32 length;
337 u32 StartAddress; 672 u32 start_address;
338 u8 Payload[1]; 673 u8 payload[1];
339}; 674};
340 675
341/* Statistics information returned as response for 676/* statistics information returned as response for
342 * SmsHostApiGetStatistics_Req */ 677 * SmsHostApiGetstatistics_Req */
343struct SMSHOSTLIB_STATISTICS_ST { 678struct sms_stats {
344 u32 Reserved; /* Reserved */ 679 u32 reserved; /* reserved */
345 680
346 /* Common parameters */ 681 /* Common parameters */
347 u32 IsRfLocked; /* 0 - not locked, 1 - locked */ 682 u32 is_rf_locked; /* 0 - not locked, 1 - locked */
348 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */ 683 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
349 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */ 684 u32 is_external_lna_on; /* 0 - external LNA off, 1 - external LNA on */
350 685
351 /* Reception quality */ 686 /* Reception quality */
352 s32 SNR; /* dB */ 687 s32 SNR; /* dB */
353 u32 BER; /* Post Viterbi BER [1E-5] */ 688 u32 ber; /* Post Viterbi ber [1E-5] */
354 u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */ 689 u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
355 u32 TS_PER; /* Transport stream PER, 690 u32 ts_per; /* Transport stream PER,
356 0xFFFFFFFF indicate N/A, valid only for DVB-T/H */ 691 0xFFFFFFFF indicate N/A, valid only for DVB-T/H */
357 u32 MFER; /* DVB-H frame error rate in percentage, 692 u32 MFER; /* DVB-H frame error rate in percentage,
358 0xFFFFFFFF indicate N/A, valid only for DVB-H */ 693 0xFFFFFFFF indicate N/A, valid only for DVB-H */
359 s32 RSSI; /* dBm */ 694 s32 RSSI; /* dBm */
360 s32 InBandPwr; /* In band power in dBM */ 695 s32 in_band_pwr; /* In band power in dBM */
361 s32 CarrierOffset; /* Carrier Offset in bin/1024 */ 696 s32 carrier_offset; /* Carrier Offset in bin/1024 */
362 697
363 /* Transmission parameters */ 698 /* Transmission parameters */
364 u32 Frequency; /* Frequency in Hz */ 699 u32 frequency; /* frequency in Hz */
365 u32 Bandwidth; /* Bandwidth in MHz, valid only for DVB-T/H */ 700 u32 bandwidth; /* bandwidth in MHz, valid only for DVB-T/H */
366 u32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4, 701 u32 transmission_mode; /* Transmission Mode, for DAB modes 1-4,
367 for DVB-T/H FFT mode carriers in Kilos */ 702 for DVB-T/H FFT mode carriers in Kilos */
368 u32 ModemState; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET, 703 u32 modem_state; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET,
369 valid only for DVB-T/H */ 704 valid only for DVB-T/H */
370 u32 GuardInterval; /* Guard Interval from 705 u32 guard_interval; /* Guard Interval from
371 SMSHOSTLIB_GUARD_INTERVALS_ET, valid only for DVB-T/H */ 706 SMSHOSTLIB_GUARD_INTERVALS_ET, valid only for DVB-T/H */
372 u32 CodeRate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET, 707 u32 code_rate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET,
373 valid only for DVB-T/H */ 708 valid only for DVB-T/H */
374 u32 LPCodeRate; /* Low Priority Code Rate from 709 u32 lp_code_rate; /* Low Priority Code Rate from
375 SMSHOSTLIB_CODE_RATE_ET, valid only for DVB-T/H */ 710 SMSHOSTLIB_CODE_RATE_ET, valid only for DVB-T/H */
376 u32 Hierarchy; /* Hierarchy from SMSHOSTLIB_HIERARCHY_ET, 711 u32 hierarchy; /* hierarchy from SMSHOSTLIB_HIERARCHY_ET,
377 valid only for DVB-T/H */ 712 valid only for DVB-T/H */
378 u32 Constellation; /* Constellation from 713 u32 constellation; /* constellation from
379 SMSHOSTLIB_CONSTELLATION_ET, valid only for DVB-T/H */ 714 SMSHOSTLIB_CONSTELLATION_ET, valid only for DVB-T/H */
380 715
381 /* Burst parameters, valid only for DVB-H */ 716 /* Burst parameters, valid only for DVB-H */
382 u32 BurstSize; /* Current burst size in bytes, 717 u32 burst_size; /* Current burst size in bytes,
383 valid only for DVB-H */ 718 valid only for DVB-H */
384 u32 BurstDuration; /* Current burst duration in mSec, 719 u32 burst_duration; /* Current burst duration in mSec,
385 valid only for DVB-H */ 720 valid only for DVB-H */
386 u32 BurstCycleTime; /* Current burst cycle time in mSec, 721 u32 burst_cycle_time; /* Current burst cycle time in mSec,
387 valid only for DVB-H */ 722 valid only for DVB-H */
388 u32 CalculatedBurstCycleTime;/* Current burst cycle time in mSec, 723 u32 calc_burst_cycle_time;/* Current burst cycle time in mSec,
389 as calculated by demodulator, valid only for DVB-H */ 724 as calculated by demodulator, valid only for DVB-H */
390 u32 NumOfRows; /* Number of rows in MPE table, 725 u32 num_of_rows; /* Number of rows in MPE table,
391 valid only for DVB-H */ 726 valid only for DVB-H */
392 u32 NumOfPaddCols; /* Number of padding columns in MPE table, 727 u32 num_of_padd_cols; /* Number of padding columns in MPE table,
393 valid only for DVB-H */ 728 valid only for DVB-H */
394 u32 NumOfPunctCols; /* Number of puncturing columns in MPE table, 729 u32 num_of_punct_cols; /* Number of puncturing columns in MPE table,
395 valid only for DVB-H */ 730 valid only for DVB-H */
396 u32 ErrorTSPackets; /* Number of erroneous 731 u32 error_ts_packets; /* Number of erroneous
397 transport-stream packets */ 732 transport-stream packets */
398 u32 TotalTSPackets; /* Total number of transport-stream packets */ 733 u32 total_ts_packets; /* Total number of transport-stream packets */
399 u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include 734 u32 num_of_valid_mpe_tlbs; /* Number of MPE tables which do not include
400 errors after MPE RS decoding */ 735 errors after MPE RS decoding */
401 u32 NumOfInvalidMpeTlbs;/* Number of MPE tables which include errors 736 u32 num_of_invalid_mpe_tlbs;/* Number of MPE tables which include errors
402 after MPE RS decoding */ 737 after MPE RS decoding */
403 u32 NumOfCorrectedMpeTlbs;/* Number of MPE tables which were 738 u32 num_of_corrected_mpe_tlbs;/* Number of MPE tables which were
404 corrected by MPE RS decoding */ 739 corrected by MPE RS decoding */
405 /* Common params */ 740 /* Common params */
406 u32 BERErrorCount; /* Number of errornous SYNC bits. */ 741 u32 ber_error_count; /* Number of errornous SYNC bits. */
407 u32 BERBitCount; /* Total number of SYNC bits. */ 742 u32 ber_bit_count; /* Total number of SYNC bits. */
408 743
409 /* Interface information */ 744 /* Interface information */
410 u32 SmsToHostTxErrors; /* Total number of transmission errors. */ 745 u32 sms_to_host_tx_errors; /* Total number of transmission errors. */
411 746
412 /* DAB/T-DMB */ 747 /* DAB/T-DMB */
413 u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */ 748 u32 pre_ber; /* DAB/T-DMB only: Pre Viterbi ber [1E-5] */
414 749
415 /* DVB-H TPS parameters */ 750 /* DVB-H TPS parameters */
416 u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero; 751 u32 cell_id; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
417 if set to 0xFFFFFFFF cell_id not yet recovered */ 752 if set to 0xFFFFFFFF cell_id not yet recovered */
418 u32 DvbhSrvIndHP; /* DVB-H service indication info, bit 1 - 753 u32 dvbh_srv_ind_hp; /* DVB-H service indication info, bit 1 -
419 Time Slicing indicator, bit 0 - MPE-FEC indicator */ 754 Time Slicing indicator, bit 0 - MPE-FEC indicator */
420 u32 DvbhSrvIndLP; /* DVB-H service indication info, bit 1 - 755 u32 dvbh_srv_ind_lp; /* DVB-H service indication info, bit 1 -
421 Time Slicing indicator, bit 0 - MPE-FEC indicator */ 756 Time Slicing indicator, bit 0 - MPE-FEC indicator */
422 757
423 u32 NumMPEReceived; /* DVB-H, Num MPE section received */ 758 u32 num_mpe_received; /* DVB-H, Num MPE section received */
424 759
425 u32 ReservedFields[10]; /* Reserved */ 760 u32 reservedFields[10]; /* reserved */
426}; 761};
427 762
428struct SmsMsgStatisticsInfo_ST { 763struct sms_msg_statistics_info {
429 u32 RequestResult; 764 u32 request_result;
430 765
431 struct SMSHOSTLIB_STATISTICS_ST Stat; 766 struct sms_stats stat;
432 767
433 /* Split the calc of the SNR in DAB */ 768 /* Split the calc of the SNR in DAB */
434 u32 Signal; /* dB */ 769 u32 signal; /* dB */
435 u32 Noise; /* dB */ 770 u32 noise; /* dB */
436 771
437}; 772};
438 773
439struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST { 774struct sms_isdbt_layer_stats {
440 /* Per-layer information */ 775 /* Per-layer information */
441 u32 CodeRate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET, 776 u32 code_rate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET,
442 * 255 means layer does not exist */ 777 * 255 means layer does not exist */
443 u32 Constellation; /* Constellation from SMSHOSTLIB_CONSTELLATION_ET, 778 u32 constellation; /* constellation from SMSHOSTLIB_CONSTELLATION_ET,
444 * 255 means layer does not exist */ 779 * 255 means layer does not exist */
445 u32 BER; /* Post Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */ 780 u32 ber; /* Post Viterbi ber [1E-5], 0xFFFFFFFF indicate N/A */
446 u32 BERErrorCount; /* Post Viterbi Error Bits Count */ 781 u32 ber_error_count; /* Post Viterbi Error Bits Count */
447 u32 BERBitCount; /* Post Viterbi Total Bits Count */ 782 u32 ber_bit_count; /* Post Viterbi Total Bits Count */
448 u32 PreBER; /* Pre Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */ 783 u32 pre_ber; /* Pre Viterbi ber [1E-5], 0xFFFFFFFF indicate N/A */
449 u32 TS_PER; /* Transport stream PER [%], 0xFFFFFFFF indicate N/A */ 784 u32 ts_per; /* Transport stream PER [%], 0xFFFFFFFF indicate N/A */
450 u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */ 785 u32 error_ts_packets; /* Number of erroneous transport-stream packets */
451 u32 TotalTSPackets; /* Total number of transport-stream packets */ 786 u32 total_ts_packets; /* Total number of transport-stream packets */
452 u32 TILdepthI; /* Time interleaver depth I parameter, 787 u32 ti_ldepth_i; /* Time interleaver depth I parameter,
453 * 255 means layer does not exist */ 788 * 255 means layer does not exist */
454 u32 NumberOfSegments; /* Number of segments in layer A, 789 u32 number_of_segments; /* Number of segments in layer A,
455 * 255 means layer does not exist */ 790 * 255 means layer does not exist */
456 u32 TMCCErrors; /* TMCC errors */ 791 u32 tmcc_errors; /* TMCC errors */
457}; 792};
458 793
459struct SMSHOSTLIB_STATISTICS_ISDBT_ST { 794struct sms_isdbt_stats {
460 u32 StatisticsType; /* Enumerator identifying the type of the 795 u32 statistics_type; /* Enumerator identifying the type of the
461 * structure. Values are the same as 796 * structure. Values are the same as
462 * SMSHOSTLIB_DEVICE_MODES_E 797 * SMSHOSTLIB_DEVICE_MODES_E
463 * 798 *
464 * This field MUST always be first in any 799 * This field MUST always be first in any
465 * statistics structure */ 800 * statistics structure */
466 801
467 u32 FullSize; /* Total size of the structure returned by the modem. 802 u32 full_size; /* Total size of the structure returned by the modem.
468 * If the size requested by the host is smaller than 803 * If the size requested by the host is smaller than
469 * FullSize, the struct will be truncated */ 804 * full_size, the struct will be truncated */
470 805
471 /* Common parameters */ 806 /* Common parameters */
472 u32 IsRfLocked; /* 0 - not locked, 1 - locked */ 807 u32 is_rf_locked; /* 0 - not locked, 1 - locked */
473 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */ 808 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
474 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */ 809 u32 is_external_lna_on; /* 0 - external LNA off, 1 - external LNA on */
475 810
476 /* Reception quality */ 811 /* Reception quality */
477 s32 SNR; /* dB */ 812 s32 SNR; /* dB */
478 s32 RSSI; /* dBm */ 813 s32 RSSI; /* dBm */
479 s32 InBandPwr; /* In band power in dBM */ 814 s32 in_band_pwr; /* In band power in dBM */
480 s32 CarrierOffset; /* Carrier Offset in Hz */ 815 s32 carrier_offset; /* Carrier Offset in Hz */
481 816
482 /* Transmission parameters */ 817 /* Transmission parameters */
483 u32 Frequency; /* Frequency in Hz */ 818 u32 frequency; /* frequency in Hz */
484 u32 Bandwidth; /* Bandwidth in MHz */ 819 u32 bandwidth; /* bandwidth in MHz */
485 u32 TransmissionMode; /* ISDB-T transmission mode */ 820 u32 transmission_mode; /* ISDB-T transmission mode */
486 u32 ModemState; /* 0 - Acquisition, 1 - Locked */ 821 u32 modem_state; /* 0 - Acquisition, 1 - Locked */
487 u32 GuardInterval; /* Guard Interval, 1 divided by value */ 822 u32 guard_interval; /* Guard Interval, 1 divided by value */
488 u32 SystemType; /* ISDB-T system type (ISDB-T / ISDB-Tsb) */ 823 u32 system_type; /* ISDB-T system type (ISDB-T / ISDB-Tsb) */
489 u32 PartialReception; /* TRUE - partial reception, FALSE otherwise */ 824 u32 partial_reception; /* TRUE - partial reception, FALSE otherwise */
490 u32 NumOfLayers; /* Number of ISDB-T layers in the network */ 825 u32 num_of_layers; /* Number of ISDB-T layers in the network */
491 826
492 /* Per-layer information */ 827 /* Per-layer information */
493 /* Layers A, B and C */ 828 /* Layers A, B and C */
494 struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST LayerInfo[3]; 829 struct sms_isdbt_layer_stats layer_info[3];
495 /* Per-layer statistics, see SMSHOSTLIB_ISDBT_LAYER_STAT_ST */ 830 /* Per-layer statistics, see sms_isdbt_layer_stats */
496 831
497 /* Interface information */ 832 /* Interface information */
498 u32 SmsToHostTxErrors; /* Total number of transmission errors. */ 833 u32 sms_to_host_tx_errors; /* Total number of transmission errors. */
499}; 834};
500 835
501struct PID_STATISTICS_DATA_S { 836struct sms_isdbt_stats_ex {
837 u32 statistics_type; /* Enumerator identifying the type of the
838 * structure. Values are the same as
839 * SMSHOSTLIB_DEVICE_MODES_E
840 *
841 * This field MUST always be first in any
842 * statistics structure */
843
844 u32 full_size; /* Total size of the structure returned by the modem.
845 * If the size requested by the host is smaller than
846 * full_size, the struct will be truncated */
847
848 /* Common parameters */
849 u32 is_rf_locked; /* 0 - not locked, 1 - locked */
850 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
851 u32 is_external_lna_on; /* 0 - external LNA off, 1 - external LNA on */
852
853 /* Reception quality */
854 s32 SNR; /* dB */
855 s32 RSSI; /* dBm */
856 s32 in_band_pwr; /* In band power in dBM */
857 s32 carrier_offset; /* Carrier Offset in Hz */
858
859 /* Transmission parameters */
860 u32 frequency; /* frequency in Hz */
861 u32 bandwidth; /* bandwidth in MHz */
862 u32 transmission_mode; /* ISDB-T transmission mode */
863 u32 modem_state; /* 0 - Acquisition, 1 - Locked */
864 u32 guard_interval; /* Guard Interval, 1 divided by value */
865 u32 system_type; /* ISDB-T system type (ISDB-T / ISDB-Tsb) */
866 u32 partial_reception; /* TRUE - partial reception, FALSE otherwise */
867 u32 num_of_layers; /* Number of ISDB-T layers in the network */
868
869 u32 segment_number; /* Segment number for ISDB-Tsb */
870 u32 tune_bw; /* Tuned bandwidth - BW_ISDBT_1SEG / BW_ISDBT_3SEG */
871
872 /* Per-layer information */
873 /* Layers A, B and C */
874 struct sms_isdbt_layer_stats layer_info[3];
875 /* Per-layer statistics, see sms_isdbt_layer_stats */
876
877 /* Interface information */
878 u32 reserved1; /* Was sms_to_host_tx_errors - obsolete . */
879 /* Proprietary information */
880 u32 ext_antenna; /* Obsolete field. */
881 u32 reception_quality;
882 u32 ews_alert_active; /* signals if EWS alert is currently on */
883 u32 lna_on_off; /* Internal LNA state: 0: OFF, 1: ON */
884
885 u32 rf_agc_level; /* RF AGC Level [linear units], full gain = 65535 (20dB) */
886 u32 bb_agc_level; /* Baseband AGC level [linear units], full gain = 65535 (71.5dB) */
887 u32 fw_errors_counter; /* Application errors - should be always zero */
888 u8 FwErrorsHistoryArr[8]; /* Last FW errors IDs - first is most recent, last is oldest */
889
890 s32 MRC_SNR; /* dB */
891 u32 snr_full_res; /* dB x 65536 */
892 u32 reserved4[4];
893};
894
895
896struct sms_pid_stats_data {
502 struct PID_BURST_S { 897 struct PID_BURST_S {
503 u32 size; 898 u32 size;
504 u32 padding_cols; 899 u32 padding_cols;
@@ -513,112 +908,155 @@ struct PID_STATISTICS_DATA_S {
513 u32 tot_cor_tbl; 908 u32 tot_cor_tbl;
514}; 909};
515 910
516struct PID_DATA_S { 911struct sms_pid_data {
517 u32 pid; 912 u32 pid;
518 u32 num_rows; 913 u32 num_rows;
519 struct PID_STATISTICS_DATA_S pid_statistics; 914 struct sms_pid_stats_data pid_statistics;
520}; 915};
521 916
522#define CORRECT_STAT_RSSI(_stat) ((_stat).RSSI *= -1) 917#define CORRECT_STAT_RSSI(_stat) ((_stat).RSSI *= -1)
523#define CORRECT_STAT_BANDWIDTH(_stat) (_stat.Bandwidth = 8 - _stat.Bandwidth) 918#define CORRECT_STAT_BANDWIDTH(_stat) (_stat.bandwidth = 8 - _stat.bandwidth)
524#define CORRECT_STAT_TRANSMISSON_MODE(_stat) \ 919#define CORRECT_STAT_TRANSMISSON_MODE(_stat) \
525 if (_stat.TransmissionMode == 0) \ 920 if (_stat.transmission_mode == 0) \
526 _stat.TransmissionMode = 2; \ 921 _stat.transmission_mode = 2; \
527 else if (_stat.TransmissionMode == 1) \ 922 else if (_stat.transmission_mode == 1) \
528 _stat.TransmissionMode = 8; \ 923 _stat.transmission_mode = 8; \
529 else \ 924 else \
530 _stat.TransmissionMode = 4; 925 _stat.transmission_mode = 4;
531 926
532struct TRANSMISSION_STATISTICS_S { 927struct sms_tx_stats {
533 u32 Frequency; /* Frequency in Hz */ 928 u32 frequency; /* frequency in Hz */
534 u32 Bandwidth; /* Bandwidth in MHz */ 929 u32 bandwidth; /* bandwidth in MHz */
535 u32 TransmissionMode; /* FFT mode carriers in Kilos */ 930 u32 transmission_mode; /* FFT mode carriers in Kilos */
536 u32 GuardInterval; /* Guard Interval from 931 u32 guard_interval; /* Guard Interval from
537 SMSHOSTLIB_GUARD_INTERVALS_ET */ 932 SMSHOSTLIB_GUARD_INTERVALS_ET */
538 u32 CodeRate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET */ 933 u32 code_rate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET */
539 u32 LPCodeRate; /* Low Priority Code Rate from 934 u32 lp_code_rate; /* Low Priority Code Rate from
540 SMSHOSTLIB_CODE_RATE_ET */ 935 SMSHOSTLIB_CODE_RATE_ET */
541 u32 Hierarchy; /* Hierarchy from SMSHOSTLIB_HIERARCHY_ET */ 936 u32 hierarchy; /* hierarchy from SMSHOSTLIB_HIERARCHY_ET */
542 u32 Constellation; /* Constellation from 937 u32 constellation; /* constellation from
543 SMSHOSTLIB_CONSTELLATION_ET */ 938 SMSHOSTLIB_CONSTELLATION_ET */
544 939
545 /* DVB-H TPS parameters */ 940 /* DVB-H TPS parameters */
546 u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero; 941 u32 cell_id; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
547 if set to 0xFFFFFFFF cell_id not yet recovered */ 942 if set to 0xFFFFFFFF cell_id not yet recovered */
548 u32 DvbhSrvIndHP; /* DVB-H service indication info, bit 1 - 943 u32 dvbh_srv_ind_hp; /* DVB-H service indication info, bit 1 -
549 Time Slicing indicator, bit 0 - MPE-FEC indicator */ 944 Time Slicing indicator, bit 0 - MPE-FEC indicator */
550 u32 DvbhSrvIndLP; /* DVB-H service indication info, bit 1 - 945 u32 dvbh_srv_ind_lp; /* DVB-H service indication info, bit 1 -
551 Time Slicing indicator, bit 0 - MPE-FEC indicator */ 946 Time Slicing indicator, bit 0 - MPE-FEC indicator */
552 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */ 947 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
948};
949
950struct sms_rx_stats {
951 u32 is_rf_locked; /* 0 - not locked, 1 - locked */
952 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
953 u32 is_external_lna_on; /* 0 - external LNA off, 1 - external LNA on */
954
955 u32 modem_state; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */
956 s32 SNR; /* dB */
957 u32 ber; /* Post Viterbi ber [1E-5] */
958 u32 ber_error_count; /* Number of erronous SYNC bits. */
959 u32 ber_bit_count; /* Total number of SYNC bits. */
960 u32 ts_per; /* Transport stream PER,
961 0xFFFFFFFF indicate N/A */
962 u32 MFER; /* DVB-H frame error rate in percentage,
963 0xFFFFFFFF indicate N/A, valid only for DVB-H */
964 s32 RSSI; /* dBm */
965 s32 in_band_pwr; /* In band power in dBM */
966 s32 carrier_offset; /* Carrier Offset in bin/1024 */
967 u32 error_ts_packets; /* Number of erroneous
968 transport-stream packets */
969 u32 total_ts_packets; /* Total number of transport-stream packets */
970
971 s32 MRC_SNR; /* dB */
972 s32 MRC_RSSI; /* dBm */
973 s32 mrc_in_band_pwr; /* In band power in dBM */
553}; 974};
554 975
555struct RECEPTION_STATISTICS_S { 976struct sms_rx_stats_ex {
556 u32 IsRfLocked; /* 0 - not locked, 1 - locked */ 977 u32 is_rf_locked; /* 0 - not locked, 1 - locked */
557 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */ 978 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
558 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */ 979 u32 is_external_lna_on; /* 0 - external LNA off, 1 - external LNA on */
559 980
560 u32 ModemState; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */ 981 u32 modem_state; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */
561 s32 SNR; /* dB */ 982 s32 SNR; /* dB */
562 u32 BER; /* Post Viterbi BER [1E-5] */ 983 u32 ber; /* Post Viterbi ber [1E-5] */
563 u32 BERErrorCount; /* Number of erronous SYNC bits. */ 984 u32 ber_error_count; /* Number of erronous SYNC bits. */
564 u32 BERBitCount; /* Total number of SYNC bits. */ 985 u32 ber_bit_count; /* Total number of SYNC bits. */
565 u32 TS_PER; /* Transport stream PER, 986 u32 ts_per; /* Transport stream PER,
566 0xFFFFFFFF indicate N/A */ 987 0xFFFFFFFF indicate N/A */
567 u32 MFER; /* DVB-H frame error rate in percentage, 988 u32 MFER; /* DVB-H frame error rate in percentage,
568 0xFFFFFFFF indicate N/A, valid only for DVB-H */ 989 0xFFFFFFFF indicate N/A, valid only for DVB-H */
569 s32 RSSI; /* dBm */ 990 s32 RSSI; /* dBm */
570 s32 InBandPwr; /* In band power in dBM */ 991 s32 in_band_pwr; /* In band power in dBM */
571 s32 CarrierOffset; /* Carrier Offset in bin/1024 */ 992 s32 carrier_offset; /* Carrier Offset in bin/1024 */
572 u32 ErrorTSPackets; /* Number of erroneous 993 u32 error_ts_packets; /* Number of erroneous
573 transport-stream packets */ 994 transport-stream packets */
574 u32 TotalTSPackets; /* Total number of transport-stream packets */ 995 u32 total_ts_packets; /* Total number of transport-stream packets */
996
997 s32 ref_dev_ppm;
998 s32 freq_dev_hz;
575 999
576 s32 MRC_SNR; /* dB */ 1000 s32 MRC_SNR; /* dB */
577 s32 MRC_RSSI; /* dBm */ 1001 s32 MRC_RSSI; /* dBm */
578 s32 MRC_InBandPwr; /* In band power in dBM */ 1002 s32 mrc_in_band_pwr; /* In band power in dBM */
579}; 1003};
580 1004
581 1005
582/* Statistics information returned as response for 1006/* statistics information returned as response for
583 * SmsHostApiGetStatisticsEx_Req for DVB applications, SMS1100 and up */ 1007 * SmsHostApiGetstatisticsEx_Req for DVB applications, SMS1100 and up */
584struct SMSHOSTLIB_STATISTICS_DVB_S { 1008struct sms_stats_dvb {
585 /* Reception */ 1009 /* Reception */
586 struct RECEPTION_STATISTICS_S ReceptionData; 1010 struct sms_rx_stats reception_data;
587 1011
588 /* Transmission parameters */ 1012 /* Transmission parameters */
589 struct TRANSMISSION_STATISTICS_S TransmissionData; 1013 struct sms_tx_stats transmission_data;
590 1014
591 /* Burst parameters, valid only for DVB-H */ 1015 /* Burst parameters, valid only for DVB-H */
592#define SRVM_MAX_PID_FILTERS 8 1016#define SRVM_MAX_PID_FILTERS 8
593 struct PID_DATA_S PidData[SRVM_MAX_PID_FILTERS]; 1017 struct sms_pid_data pid_data[SRVM_MAX_PID_FILTERS];
594}; 1018};
595 1019
596struct SRVM_SIGNAL_STATUS_S { 1020/* statistics information returned as response for
1021 * SmsHostApiGetstatisticsEx_Req for DVB applications, SMS1100 and up */
1022struct sms_stats_dvb_ex {
1023 /* Reception */
1024 struct sms_rx_stats_ex reception_data;
1025
1026 /* Transmission parameters */
1027 struct sms_tx_stats transmission_data;
1028
1029 /* Burst parameters, valid only for DVB-H */
1030#define SRVM_MAX_PID_FILTERS 8
1031 struct sms_pid_data pid_data[SRVM_MAX_PID_FILTERS];
1032};
1033
1034struct sms_srvm_signal_status {
597 u32 result; 1035 u32 result;
598 u32 snr; 1036 u32 snr;
599 u32 tsPackets; 1037 u32 ts_packets;
600 u32 etsPackets; 1038 u32 ets_packets;
601 u32 constellation; 1039 u32 constellation;
602 u32 hpCode; 1040 u32 hp_code;
603 u32 tpsSrvIndLP; 1041 u32 tps_srv_ind_lp;
604 u32 tpsSrvIndHP; 1042 u32 tps_srv_ind_hp;
605 u32 cellId; 1043 u32 cell_id;
606 u32 reason; 1044 u32 reason;
607 1045
608 s32 inBandPower; 1046 s32 in_band_power;
609 u32 requestId; 1047 u32 request_id;
610}; 1048};
611 1049
612struct SMSHOSTLIB_I2C_REQ_ST { 1050struct sms_i2c_req {
613 u32 DeviceAddress; /* I2c device address */ 1051 u32 device_address; /* I2c device address */
614 u32 WriteCount; /* number of bytes to write */ 1052 u32 write_count; /* number of bytes to write */
615 u32 ReadCount; /* number of bytes to read */ 1053 u32 read_count; /* number of bytes to read */
616 u8 Data[1]; 1054 u8 Data[1];
617}; 1055};
618 1056
619struct SMSHOSTLIB_I2C_RES_ST { 1057struct sms_i2c_res {
620 u32 Status; /* non-zero value in case of failure */ 1058 u32 status; /* non-zero value in case of failure */
621 u32 ReadCount; /* number of bytes read */ 1059 u32 read_count; /* number of bytes read */
622 u8 Data[1]; 1060 u8 Data[1];
623}; 1061};
624 1062
@@ -638,59 +1076,39 @@ struct smscore_config_gpio {
638#define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1 1076#define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1
639 u8 inputcharacteristics; 1077 u8 inputcharacteristics;
640 1078
641#define SMS_GPIO_OUTPUTSLEWRATE_FAST 0 1079 /* 10xx */
642#define SMS_GPIO_OUTPUTSLEWRATE_SLOW 1 1080#define SMS_GPIO_OUTPUT_SLEW_RATE_FAST 0
643 u8 outputslewrate; 1081#define SMS_GPIO_OUTPUT_SLEW_WRATE_SLOW 1
644
645#define SMS_GPIO_OUTPUTDRIVING_4mA 0
646#define SMS_GPIO_OUTPUTDRIVING_8mA 1
647#define SMS_GPIO_OUTPUTDRIVING_12mA 2
648#define SMS_GPIO_OUTPUTDRIVING_16mA 3
649 u8 outputdriving;
650};
651
652struct smscore_gpio_config {
653#define SMS_GPIO_DIRECTION_INPUT 0
654#define SMS_GPIO_DIRECTION_OUTPUT 1
655 u8 Direction;
656
657#define SMS_GPIO_PULL_UP_DOWN_NONE 0
658#define SMS_GPIO_PULL_UP_DOWN_PULLDOWN 1
659#define SMS_GPIO_PULL_UP_DOWN_PULLUP 2
660#define SMS_GPIO_PULL_UP_DOWN_KEEPER 3
661 u8 PullUpDown;
662
663#define SMS_GPIO_INPUT_CHARACTERISTICS_NORMAL 0
664#define SMS_GPIO_INPUT_CHARACTERISTICS_SCHMITT 1
665 u8 InputCharacteristics;
666
667#define SMS_GPIO_OUTPUT_SLEW_RATE_SLOW 1 /* 10xx */
668#define SMS_GPIO_OUTPUT_SLEW_RATE_FAST 0 /* 10xx */
669 1082
1083 /* 11xx */
1084#define SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS 0
1085#define SMS_GPIO_OUTPUT_SLEW_RATE_0_9_V_NS 1
1086#define SMS_GPIO_OUTPUT_SLEW_RATE_1_7_V_NS 2
1087#define SMS_GPIO_OUTPUT_SLEW_RATE_3_3_V_NS 3
670 1088
671#define SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS 0 /* 11xx */ 1089 u8 outputslewrate;
672#define SMS_GPIO_OUTPUT_SLEW_RATE_0_9_V_NS 1 /* 11xx */
673#define SMS_GPIO_OUTPUT_SLEW_RATE_1_7_V_NS 2 /* 11xx */
674#define SMS_GPIO_OUTPUT_SLEW_RATE_3_3_V_NS 3 /* 11xx */
675 u8 OutputSlewRate;
676 1090
677#define SMS_GPIO_OUTPUT_DRIVING_S_4mA 0 /* 10xx */ 1091 /* 10xx */
678#define SMS_GPIO_OUTPUT_DRIVING_S_8mA 1 /* 10xx */ 1092#define SMS_GPIO_OUTPUTDRIVING_S_4mA 0
679#define SMS_GPIO_OUTPUT_DRIVING_S_12mA 2 /* 10xx */ 1093#define SMS_GPIO_OUTPUTDRIVING_S_8mA 1
680#define SMS_GPIO_OUTPUT_DRIVING_S_16mA 3 /* 10xx */ 1094#define SMS_GPIO_OUTPUTDRIVING_S_12mA 2
1095#define SMS_GPIO_OUTPUTDRIVING_S_16mA 3
1096
1097 /* 11xx*/
1098#define SMS_GPIO_OUTPUTDRIVING_1_5mA 0
1099#define SMS_GPIO_OUTPUTDRIVING_2_8mA 1
1100#define SMS_GPIO_OUTPUTDRIVING_4mA 2
1101#define SMS_GPIO_OUTPUTDRIVING_7mA 3
1102#define SMS_GPIO_OUTPUTDRIVING_10mA 4
1103#define SMS_GPIO_OUTPUTDRIVING_11mA 5
1104#define SMS_GPIO_OUTPUTDRIVING_14mA 6
1105#define SMS_GPIO_OUTPUTDRIVING_16mA 7
681 1106
682#define SMS_GPIO_OUTPUT_DRIVING_1_5mA 0 /* 11xx */ 1107 u8 outputdriving;
683#define SMS_GPIO_OUTPUT_DRIVING_2_8mA 1 /* 11xx */
684#define SMS_GPIO_OUTPUT_DRIVING_4mA 2 /* 11xx */
685#define SMS_GPIO_OUTPUT_DRIVING_7mA 3 /* 11xx */
686#define SMS_GPIO_OUTPUT_DRIVING_10mA 4 /* 11xx */
687#define SMS_GPIO_OUTPUT_DRIVING_11mA 5 /* 11xx */
688#define SMS_GPIO_OUTPUT_DRIVING_14mA 6 /* 11xx */
689#define SMS_GPIO_OUTPUT_DRIVING_16mA 7 /* 11xx */
690 u8 OutputDriving;
691}; 1108};
692 1109
693extern void smscore_registry_setmode(char *devpath, int mode); 1110char *smscore_translate_msg(enum msg_types msgtype);
1111
694extern int smscore_registry_getmode(char *devpath); 1112extern int smscore_registry_getmode(char *devpath);
695 1113
696extern int smscore_register_hotplug(hotplug_t hotplug); 1114extern int smscore_register_hotplug(hotplug_t hotplug);
@@ -721,8 +1139,6 @@ extern void smscore_onresponse(struct smscore_device_t *coredev,
721extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev); 1139extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
722extern int smscore_map_common_buffer(struct smscore_device_t *coredev, 1140extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
723 struct vm_area_struct *vma); 1141 struct vm_area_struct *vma);
724extern int smscore_get_fw_filename(struct smscore_device_t *coredev,
725 int mode, char *filename);
726extern int smscore_send_fw_file(struct smscore_device_t *coredev, 1142extern int smscore_send_fw_file(struct smscore_device_t *coredev,
727 u8 *ufwbuf, int size); 1143 u8 *ufwbuf, int size);
728 1144
@@ -737,11 +1153,11 @@ int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
737int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level); 1153int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level);
738 1154
739/* new GPIO management */ 1155/* new GPIO management */
740extern int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum, 1156extern int smscore_gpio_configure(struct smscore_device_t *coredev, u8 pin_num,
741 struct smscore_gpio_config *pGpioConfig); 1157 struct smscore_config_gpio *p_gpio_config);
742extern int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum, 1158extern int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 pin_num,
743 u8 NewLevel); 1159 u8 new_level);
744extern int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum, 1160extern int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 pin_num,
745 u8 *level); 1161 u8 *level);
746 1162
747void smscore_set_board_id(struct smscore_device_t *core, int id); 1163void smscore_set_board_id(struct smscore_device_t *core, int id);
@@ -760,7 +1176,8 @@ int smscore_led_state(struct smscore_device_t *core, int led);
760 1176
761#define dprintk(kern, lvl, fmt, arg...) do {\ 1177#define dprintk(kern, lvl, fmt, arg...) do {\
762 if (sms_dbg & lvl) \ 1178 if (sms_dbg & lvl) \
763 sms_printk(kern, fmt, ##arg); } while (0) 1179 sms_printk(kern, fmt, ##arg); \
1180} while (0)
764 1181
765#define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg) 1182#define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
766#define sms_err(fmt, arg...) \ 1183#define sms_err(fmt, arg...) \
diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c
new file mode 100644
index 000000000000..0bb4430535f9
--- /dev/null
+++ b/drivers/media/common/siano/smsdvb-debugfs.c
@@ -0,0 +1,551 @@
1/***********************************************************************
2 *
3 * Copyright(c) 2013 Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ***********************************************************************/
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <linux/debugfs.h>
26#include <linux/spinlock.h>
27#include <linux/usb.h>
28
29#include "dmxdev.h"
30#include "dvbdev.h"
31#include "dvb_demux.h"
32#include "dvb_frontend.h"
33
34#include "smscoreapi.h"
35
36#include "smsdvb.h"
37
38static struct dentry *smsdvb_debugfs_usb_root;
39
40struct smsdvb_debugfs {
41 struct kref refcount;
42 spinlock_t lock;
43
44 char stats_data[PAGE_SIZE];
45 unsigned stats_count;
46 bool stats_was_read;
47
48 wait_queue_head_t stats_queue;
49};
50
51static void smsdvb_print_dvb_stats(struct smsdvb_debugfs *debug_data,
52 struct sms_stats *p)
53{
54 int n = 0;
55 char *buf;
56
57 spin_lock(&debug_data->lock);
58 if (debug_data->stats_count) {
59 spin_unlock(&debug_data->lock);
60 return;
61 }
62
63 buf = debug_data->stats_data;
64
65 n += snprintf(&buf[n], PAGE_SIZE - n,
66 "is_rf_locked = %d\n", p->is_rf_locked);
67 n += snprintf(&buf[n], PAGE_SIZE - n,
68 "is_demod_locked = %d\n", p->is_demod_locked);
69 n += snprintf(&buf[n], PAGE_SIZE - n,
70 "is_external_lna_on = %d\n", p->is_external_lna_on);
71 n += snprintf(&buf[n], PAGE_SIZE - n,
72 "SNR = %d\n", p->SNR);
73 n += snprintf(&buf[n], PAGE_SIZE - n,
74 "ber = %d\n", p->ber);
75 n += snprintf(&buf[n], PAGE_SIZE - n,
76 "FIB_CRC = %d\n", p->FIB_CRC);
77 n += snprintf(&buf[n], PAGE_SIZE - n,
78 "ts_per = %d\n", p->ts_per);
79 n += snprintf(&buf[n], PAGE_SIZE - n,
80 "MFER = %d\n", p->MFER);
81 n += snprintf(&buf[n], PAGE_SIZE - n,
82 "RSSI = %d\n", p->RSSI);
83 n += snprintf(&buf[n], PAGE_SIZE - n,
84 "in_band_pwr = %d\n", p->in_band_pwr);
85 n += snprintf(&buf[n], PAGE_SIZE - n,
86 "carrier_offset = %d\n", p->carrier_offset);
87 n += snprintf(&buf[n], PAGE_SIZE - n,
88 "modem_state = %d\n", p->modem_state);
89 n += snprintf(&buf[n], PAGE_SIZE - n,
90 "frequency = %d\n", p->frequency);
91 n += snprintf(&buf[n], PAGE_SIZE - n,
92 "bandwidth = %d\n", p->bandwidth);
93 n += snprintf(&buf[n], PAGE_SIZE - n,
94 "transmission_mode = %d\n", p->transmission_mode);
95 n += snprintf(&buf[n], PAGE_SIZE - n,
96 "modem_state = %d\n", p->modem_state);
97 n += snprintf(&buf[n], PAGE_SIZE - n,
98 "guard_interval = %d\n", p->guard_interval);
99 n += snprintf(&buf[n], PAGE_SIZE - n,
100 "code_rate = %d\n", p->code_rate);
101 n += snprintf(&buf[n], PAGE_SIZE - n,
102 "lp_code_rate = %d\n", p->lp_code_rate);
103 n += snprintf(&buf[n], PAGE_SIZE - n,
104 "hierarchy = %d\n", p->hierarchy);
105 n += snprintf(&buf[n], PAGE_SIZE - n,
106 "constellation = %d\n", p->constellation);
107 n += snprintf(&buf[n], PAGE_SIZE - n,
108 "burst_size = %d\n", p->burst_size);
109 n += snprintf(&buf[n], PAGE_SIZE - n,
110 "burst_duration = %d\n", p->burst_duration);
111 n += snprintf(&buf[n], PAGE_SIZE - n,
112 "burst_cycle_time = %d\n", p->burst_cycle_time);
113 n += snprintf(&buf[n], PAGE_SIZE - n,
114 "calc_burst_cycle_time = %d\n",
115 p->calc_burst_cycle_time);
116 n += snprintf(&buf[n], PAGE_SIZE - n,
117 "num_of_rows = %d\n", p->num_of_rows);
118 n += snprintf(&buf[n], PAGE_SIZE - n,
119 "num_of_padd_cols = %d\n", p->num_of_padd_cols);
120 n += snprintf(&buf[n], PAGE_SIZE - n,
121 "num_of_punct_cols = %d\n", p->num_of_punct_cols);
122 n += snprintf(&buf[n], PAGE_SIZE - n,
123 "error_ts_packets = %d\n", p->error_ts_packets);
124 n += snprintf(&buf[n], PAGE_SIZE - n,
125 "total_ts_packets = %d\n", p->total_ts_packets);
126 n += snprintf(&buf[n], PAGE_SIZE - n,
127 "num_of_valid_mpe_tlbs = %d\n", p->num_of_valid_mpe_tlbs);
128 n += snprintf(&buf[n], PAGE_SIZE - n,
129 "num_of_invalid_mpe_tlbs = %d\n", p->num_of_invalid_mpe_tlbs);
130 n += snprintf(&buf[n], PAGE_SIZE - n,
131 "num_of_corrected_mpe_tlbs = %d\n", p->num_of_corrected_mpe_tlbs);
132 n += snprintf(&buf[n], PAGE_SIZE - n,
133 "ber_error_count = %d\n", p->ber_error_count);
134 n += snprintf(&buf[n], PAGE_SIZE - n,
135 "ber_bit_count = %d\n", p->ber_bit_count);
136 n += snprintf(&buf[n], PAGE_SIZE - n,
137 "sms_to_host_tx_errors = %d\n", p->sms_to_host_tx_errors);
138 n += snprintf(&buf[n], PAGE_SIZE - n,
139 "pre_ber = %d\n", p->pre_ber);
140 n += snprintf(&buf[n], PAGE_SIZE - n,
141 "cell_id = %d\n", p->cell_id);
142 n += snprintf(&buf[n], PAGE_SIZE - n,
143 "dvbh_srv_ind_hp = %d\n", p->dvbh_srv_ind_hp);
144 n += snprintf(&buf[n], PAGE_SIZE - n,
145 "dvbh_srv_ind_lp = %d\n", p->dvbh_srv_ind_lp);
146 n += snprintf(&buf[n], PAGE_SIZE - n,
147 "num_mpe_received = %d\n", p->num_mpe_received);
148
149 debug_data->stats_count = n;
150 spin_unlock(&debug_data->lock);
151 wake_up(&debug_data->stats_queue);
152}
153
154static void smsdvb_print_isdb_stats(struct smsdvb_debugfs *debug_data,
155 struct sms_isdbt_stats *p)
156{
157 int i, n = 0;
158 char *buf;
159
160 spin_lock(&debug_data->lock);
161 if (debug_data->stats_count) {
162 spin_unlock(&debug_data->lock);
163 return;
164 }
165
166 buf = debug_data->stats_data;
167
168 n += snprintf(&buf[n], PAGE_SIZE - n,
169 "statistics_type = %d\t", p->statistics_type);
170 n += snprintf(&buf[n], PAGE_SIZE - n,
171 "full_size = %d\n", p->full_size);
172
173 n += snprintf(&buf[n], PAGE_SIZE - n,
174 "is_rf_locked = %d\t\t", p->is_rf_locked);
175 n += snprintf(&buf[n], PAGE_SIZE - n,
176 "is_demod_locked = %d\t", p->is_demod_locked);
177 n += snprintf(&buf[n], PAGE_SIZE - n,
178 "is_external_lna_on = %d\n", p->is_external_lna_on);
179 n += snprintf(&buf[n], PAGE_SIZE - n,
180 "SNR = %d dB\t\t", p->SNR);
181 n += snprintf(&buf[n], PAGE_SIZE - n,
182 "RSSI = %d dBm\t\t", p->RSSI);
183 n += snprintf(&buf[n], PAGE_SIZE - n,
184 "in_band_pwr = %d dBm\n", p->in_band_pwr);
185 n += snprintf(&buf[n], PAGE_SIZE - n,
186 "carrier_offset = %d\t", p->carrier_offset);
187 n += snprintf(&buf[n], PAGE_SIZE - n,
188 "bandwidth = %d\t\t", p->bandwidth);
189 n += snprintf(&buf[n], PAGE_SIZE - n,
190 "frequency = %d Hz\n", p->frequency);
191 n += snprintf(&buf[n], PAGE_SIZE - n,
192 "transmission_mode = %d\t", p->transmission_mode);
193 n += snprintf(&buf[n], PAGE_SIZE - n,
194 "modem_state = %d\t\t", p->modem_state);
195 n += snprintf(&buf[n], PAGE_SIZE - n,
196 "guard_interval = %d\n", p->guard_interval);
197 n += snprintf(&buf[n], PAGE_SIZE - n,
198 "system_type = %d\t\t", p->system_type);
199 n += snprintf(&buf[n], PAGE_SIZE - n,
200 "partial_reception = %d\t", p->partial_reception);
201 n += snprintf(&buf[n], PAGE_SIZE - n,
202 "num_of_layers = %d\n", p->num_of_layers);
203 n += snprintf(&buf[n], PAGE_SIZE - n,
204 "sms_to_host_tx_errors = %d\n", p->sms_to_host_tx_errors);
205
206 for (i = 0; i < 3; i++) {
207 if (p->layer_info[i].number_of_segments < 1 ||
208 p->layer_info[i].number_of_segments > 13)
209 continue;
210
211 n += snprintf(&buf[n], PAGE_SIZE - n, "\nLayer %d\n", i);
212 n += snprintf(&buf[n], PAGE_SIZE - n, "\tcode_rate = %d\t",
213 p->layer_info[i].code_rate);
214 n += snprintf(&buf[n], PAGE_SIZE - n, "constellation = %d\n",
215 p->layer_info[i].constellation);
216 n += snprintf(&buf[n], PAGE_SIZE - n, "\tber = %-5d\t",
217 p->layer_info[i].ber);
218 n += snprintf(&buf[n], PAGE_SIZE - n, "\tber_error_count = %-5d\t",
219 p->layer_info[i].ber_error_count);
220 n += snprintf(&buf[n], PAGE_SIZE - n, "ber_bit_count = %-5d\n",
221 p->layer_info[i].ber_bit_count);
222 n += snprintf(&buf[n], PAGE_SIZE - n, "\tpre_ber = %-5d\t",
223 p->layer_info[i].pre_ber);
224 n += snprintf(&buf[n], PAGE_SIZE - n, "\tts_per = %-5d\n",
225 p->layer_info[i].ts_per);
226 n += snprintf(&buf[n], PAGE_SIZE - n, "\terror_ts_packets = %-5d\t",
227 p->layer_info[i].error_ts_packets);
228 n += snprintf(&buf[n], PAGE_SIZE - n, "total_ts_packets = %-5d\t",
229 p->layer_info[i].total_ts_packets);
230 n += snprintf(&buf[n], PAGE_SIZE - n, "ti_ldepth_i = %d\n",
231 p->layer_info[i].ti_ldepth_i);
232 n += snprintf(&buf[n], PAGE_SIZE - n,
233 "\tnumber_of_segments = %d\t",
234 p->layer_info[i].number_of_segments);
235 n += snprintf(&buf[n], PAGE_SIZE - n, "tmcc_errors = %d\n",
236 p->layer_info[i].tmcc_errors);
237 }
238
239 debug_data->stats_count = n;
240 spin_unlock(&debug_data->lock);
241 wake_up(&debug_data->stats_queue);
242}
243
244static void smsdvb_print_isdb_stats_ex(struct smsdvb_debugfs *debug_data,
245 struct sms_isdbt_stats_ex *p)
246{
247 int i, n = 0;
248 char *buf;
249
250 spin_lock(&debug_data->lock);
251 if (debug_data->stats_count) {
252 spin_unlock(&debug_data->lock);
253 return;
254 }
255
256 buf = debug_data->stats_data;
257
258 n += snprintf(&buf[n], PAGE_SIZE - n,
259 "statistics_type = %d\t", p->statistics_type);
260 n += snprintf(&buf[n], PAGE_SIZE - n,
261 "full_size = %d\n", p->full_size);
262
263 n += snprintf(&buf[n], PAGE_SIZE - n,
264 "is_rf_locked = %d\t\t", p->is_rf_locked);
265 n += snprintf(&buf[n], PAGE_SIZE - n,
266 "is_demod_locked = %d\t", p->is_demod_locked);
267 n += snprintf(&buf[n], PAGE_SIZE - n,
268 "is_external_lna_on = %d\n", p->is_external_lna_on);
269 n += snprintf(&buf[n], PAGE_SIZE - n,
270 "SNR = %d dB\t\t", p->SNR);
271 n += snprintf(&buf[n], PAGE_SIZE - n,
272 "RSSI = %d dBm\t\t", p->RSSI);
273 n += snprintf(&buf[n], PAGE_SIZE - n,
274 "in_band_pwr = %d dBm\n", p->in_band_pwr);
275 n += snprintf(&buf[n], PAGE_SIZE - n,
276 "carrier_offset = %d\t", p->carrier_offset);
277 n += snprintf(&buf[n], PAGE_SIZE - n,
278 "bandwidth = %d\t\t", p->bandwidth);
279 n += snprintf(&buf[n], PAGE_SIZE - n,
280 "frequency = %d Hz\n", p->frequency);
281 n += snprintf(&buf[n], PAGE_SIZE - n,
282 "transmission_mode = %d\t", p->transmission_mode);
283 n += snprintf(&buf[n], PAGE_SIZE - n,
284 "modem_state = %d\t\t", p->modem_state);
285 n += snprintf(&buf[n], PAGE_SIZE - n,
286 "guard_interval = %d\n", p->guard_interval);
287 n += snprintf(&buf[n], PAGE_SIZE - n,
288 "system_type = %d\t\t", p->system_type);
289 n += snprintf(&buf[n], PAGE_SIZE - n,
290 "partial_reception = %d\t", p->partial_reception);
291 n += snprintf(&buf[n], PAGE_SIZE - n,
292 "num_of_layers = %d\n", p->num_of_layers);
293 n += snprintf(&buf[n], PAGE_SIZE - n, "segment_number = %d\t",
294 p->segment_number);
295 n += snprintf(&buf[n], PAGE_SIZE - n, "tune_bw = %d\n",
296 p->tune_bw);
297
298 for (i = 0; i < 3; i++) {
299 if (p->layer_info[i].number_of_segments < 1 ||
300 p->layer_info[i].number_of_segments > 13)
301 continue;
302
303 n += snprintf(&buf[n], PAGE_SIZE - n, "\nLayer %d\n", i);
304 n += snprintf(&buf[n], PAGE_SIZE - n, "\tcode_rate = %d\t",
305 p->layer_info[i].code_rate);
306 n += snprintf(&buf[n], PAGE_SIZE - n, "constellation = %d\n",
307 p->layer_info[i].constellation);
308 n += snprintf(&buf[n], PAGE_SIZE - n, "\tber = %-5d\t",
309 p->layer_info[i].ber);
310 n += snprintf(&buf[n], PAGE_SIZE - n, "\tber_error_count = %-5d\t",
311 p->layer_info[i].ber_error_count);
312 n += snprintf(&buf[n], PAGE_SIZE - n, "ber_bit_count = %-5d\n",
313 p->layer_info[i].ber_bit_count);
314 n += snprintf(&buf[n], PAGE_SIZE - n, "\tpre_ber = %-5d\t",
315 p->layer_info[i].pre_ber);
316 n += snprintf(&buf[n], PAGE_SIZE - n, "\tts_per = %-5d\n",
317 p->layer_info[i].ts_per);
318 n += snprintf(&buf[n], PAGE_SIZE - n, "\terror_ts_packets = %-5d\t",
319 p->layer_info[i].error_ts_packets);
320 n += snprintf(&buf[n], PAGE_SIZE - n, "total_ts_packets = %-5d\t",
321 p->layer_info[i].total_ts_packets);
322 n += snprintf(&buf[n], PAGE_SIZE - n, "ti_ldepth_i = %d\n",
323 p->layer_info[i].ti_ldepth_i);
324 n += snprintf(&buf[n], PAGE_SIZE - n,
325 "\tnumber_of_segments = %d\t",
326 p->layer_info[i].number_of_segments);
327 n += snprintf(&buf[n], PAGE_SIZE - n, "tmcc_errors = %d\n",
328 p->layer_info[i].tmcc_errors);
329 }
330
331
332 debug_data->stats_count = n;
333 spin_unlock(&debug_data->lock);
334
335 wake_up(&debug_data->stats_queue);
336}
337
338static int smsdvb_stats_open(struct inode *inode, struct file *file)
339{
340 struct smsdvb_client_t *client = inode->i_private;
341 struct smsdvb_debugfs *debug_data = client->debug_data;
342
343 kref_get(&debug_data->refcount);
344
345 spin_lock(&debug_data->lock);
346 debug_data->stats_count = 0;
347 debug_data->stats_was_read = false;
348 spin_unlock(&debug_data->lock);
349
350 file->private_data = debug_data;
351
352 return 0;
353}
354
355static void smsdvb_debugfs_data_release(struct kref *ref)
356{
357 struct smsdvb_debugfs *debug_data;
358
359 debug_data = container_of(ref, struct smsdvb_debugfs, refcount);
360 kfree(debug_data);
361}
362
363static int smsdvb_stats_wait_read(struct smsdvb_debugfs *debug_data)
364{
365 int rc = 1;
366
367 spin_lock(&debug_data->lock);
368
369 if (debug_data->stats_was_read)
370 goto exit;
371
372 rc = debug_data->stats_count;
373
374exit:
375 spin_unlock(&debug_data->lock);
376 return rc;
377}
378
379static unsigned int smsdvb_stats_poll(struct file *file, poll_table *wait)
380{
381 struct smsdvb_debugfs *debug_data = file->private_data;
382 int rc;
383
384 kref_get(&debug_data->refcount);
385
386 poll_wait(file, &debug_data->stats_queue, wait);
387
388 rc = smsdvb_stats_wait_read(debug_data);
389 if (rc > 0)
390 rc = POLLIN | POLLRDNORM;
391
392 kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
393
394 return rc;
395}
396
397static ssize_t smsdvb_stats_read(struct file *file, char __user *user_buf,
398 size_t nbytes, loff_t *ppos)
399{
400 int rc = 0, len;
401 struct smsdvb_debugfs *debug_data = file->private_data;
402
403 kref_get(&debug_data->refcount);
404
405 if (file->f_flags & O_NONBLOCK) {
406 rc = smsdvb_stats_wait_read(debug_data);
407 if (!rc) {
408 rc = -EWOULDBLOCK;
409 goto ret;
410 }
411 } else {
412 rc = wait_event_interruptible(debug_data->stats_queue,
413 smsdvb_stats_wait_read(debug_data));
414 if (rc < 0)
415 goto ret;
416 }
417
418 if (debug_data->stats_was_read) {
419 rc = 0; /* EOF */
420 goto ret;
421 }
422
423 len = debug_data->stats_count - *ppos;
424 if (len >= 0)
425 rc = simple_read_from_buffer(user_buf, nbytes, ppos,
426 debug_data->stats_data, len);
427 else
428 rc = 0;
429
430 if (*ppos >= debug_data->stats_count) {
431 spin_lock(&debug_data->lock);
432 debug_data->stats_was_read = true;
433 spin_unlock(&debug_data->lock);
434 }
435ret:
436 kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
437 return rc;
438}
439
440static int smsdvb_stats_release(struct inode *inode, struct file *file)
441{
442 struct smsdvb_debugfs *debug_data = file->private_data;
443
444 spin_lock(&debug_data->lock);
445 debug_data->stats_was_read = true; /* return EOF to read() */
446 spin_unlock(&debug_data->lock);
447 wake_up_interruptible_sync(&debug_data->stats_queue);
448
449 kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
450 file->private_data = NULL;
451
452 return 0;
453}
454
455static const struct file_operations debugfs_stats_ops = {
456 .open = smsdvb_stats_open,
457 .poll = smsdvb_stats_poll,
458 .read = smsdvb_stats_read,
459 .release = smsdvb_stats_release,
460 .llseek = generic_file_llseek,
461};
462
463/*
464 * Functions used by smsdvb, in order to create the interfaces
465 */
466
467int smsdvb_debugfs_create(struct smsdvb_client_t *client)
468{
469 struct smscore_device_t *coredev = client->coredev;
470 struct dentry *d;
471 struct smsdvb_debugfs *debug_data;
472
473 if (!smsdvb_debugfs_usb_root || !coredev->is_usb_device)
474 return -ENODEV;
475
476 client->debugfs = debugfs_create_dir(coredev->devpath,
477 smsdvb_debugfs_usb_root);
478 if (IS_ERR_OR_NULL(client->debugfs)) {
479 pr_info("Unable to create debugfs %s directory.\n",
480 coredev->devpath);
481 return -ENODEV;
482 }
483
484 d = debugfs_create_file("stats", S_IRUGO | S_IWUSR, client->debugfs,
485 client, &debugfs_stats_ops);
486 if (!d) {
487 debugfs_remove(client->debugfs);
488 return -ENOMEM;
489 }
490
491 debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL);
492 if (!debug_data)
493 return -ENOMEM;
494
495 client->debug_data = debug_data;
496 client->prt_dvb_stats = smsdvb_print_dvb_stats;
497 client->prt_isdb_stats = smsdvb_print_isdb_stats;
498 client->prt_isdb_stats_ex = smsdvb_print_isdb_stats_ex;
499
500 init_waitqueue_head(&debug_data->stats_queue);
501 spin_lock_init(&debug_data->lock);
502 kref_init(&debug_data->refcount);
503
504 return 0;
505}
506
507void smsdvb_debugfs_release(struct smsdvb_client_t *client)
508{
509 if (!client->debugfs)
510 return;
511
512 client->prt_dvb_stats = NULL;
513 client->prt_isdb_stats = NULL;
514 client->prt_isdb_stats_ex = NULL;
515
516 debugfs_remove_recursive(client->debugfs);
517 kref_put(&client->debug_data->refcount, smsdvb_debugfs_data_release);
518
519 client->debug_data = NULL;
520 client->debugfs = NULL;
521}
522
523int smsdvb_debugfs_register(void)
524{
525 struct dentry *d;
526
527 /*
528 * FIXME: This was written to debug Siano USB devices. So, it creates
529 * the debugfs node under <debugfs>/usb.
530 * A similar logic would be needed for Siano sdio devices, but, in that
531 * case, usb_debug_root is not a good choice.
532 *
533 * Perhaps the right fix here would be to create another sysfs root
534 * node for sdio-based boards, but this may need some logic at sdio
535 * subsystem.
536 */
537 d = debugfs_create_dir("smsdvb", usb_debug_root);
538 if (IS_ERR_OR_NULL(d)) {
539 sms_err("Couldn't create sysfs node for smsdvb");
540 return PTR_ERR(d);
541 } else {
542 smsdvb_debugfs_usb_root = d;
543 }
544 return 0;
545}
546
547void smsdvb_debugfs_unregister(void)
548{
549 debugfs_remove_recursive(smsdvb_debugfs_usb_root);
550 smsdvb_debugfs_usb_root = NULL;
551}
diff --git a/drivers/media/common/siano/smsdvb-main.c b/drivers/media/common/siano/smsdvb-main.c
new file mode 100644
index 000000000000..297f1b2f9a32
--- /dev/null
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -0,0 +1,1230 @@
1/****************************************************************
2
3Siano Mobile Silicon, Inc.
4MDTV receiver kernel modules.
5Copyright (C) 2006-2008, Uri Shkolnik
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the 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,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20****************************************************************/
21
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <asm/div64.h>
26
27#include "dmxdev.h"
28#include "dvbdev.h"
29#include "dvb_demux.h"
30#include "dvb_frontend.h"
31
32#include "smscoreapi.h"
33#include "sms-cards.h"
34
35#include "smsdvb.h"
36
37DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
38
39static struct list_head g_smsdvb_clients;
40static struct mutex g_smsdvb_clientslock;
41
42static int sms_dbg;
43module_param_named(debug, sms_dbg, int, 0644);
44MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
45
46
47u32 sms_to_guard_interval_table[] = {
48 [0] = GUARD_INTERVAL_1_32,
49 [1] = GUARD_INTERVAL_1_16,
50 [2] = GUARD_INTERVAL_1_8,
51 [3] = GUARD_INTERVAL_1_4,
52};
53
54u32 sms_to_code_rate_table[] = {
55 [0] = FEC_1_2,
56 [1] = FEC_2_3,
57 [2] = FEC_3_4,
58 [3] = FEC_5_6,
59 [4] = FEC_7_8,
60};
61
62
63u32 sms_to_hierarchy_table[] = {
64 [0] = HIERARCHY_NONE,
65 [1] = HIERARCHY_1,
66 [2] = HIERARCHY_2,
67 [3] = HIERARCHY_4,
68};
69
70u32 sms_to_modulation_table[] = {
71 [0] = QPSK,
72 [1] = QAM_16,
73 [2] = QAM_64,
74 [3] = DQPSK,
75};
76
77
78/* Events that may come from DVB v3 adapter */
79static void sms_board_dvb3_event(struct smsdvb_client_t *client,
80 enum SMS_DVB3_EVENTS event) {
81
82 struct smscore_device_t *coredev = client->coredev;
83 switch (event) {
84 case DVB3_EVENT_INIT:
85 sms_debug("DVB3_EVENT_INIT");
86 sms_board_event(coredev, BOARD_EVENT_BIND);
87 break;
88 case DVB3_EVENT_SLEEP:
89 sms_debug("DVB3_EVENT_SLEEP");
90 sms_board_event(coredev, BOARD_EVENT_POWER_SUSPEND);
91 break;
92 case DVB3_EVENT_HOTPLUG:
93 sms_debug("DVB3_EVENT_HOTPLUG");
94 sms_board_event(coredev, BOARD_EVENT_POWER_INIT);
95 break;
96 case DVB3_EVENT_FE_LOCK:
97 if (client->event_fe_state != DVB3_EVENT_FE_LOCK) {
98 client->event_fe_state = DVB3_EVENT_FE_LOCK;
99 sms_debug("DVB3_EVENT_FE_LOCK");
100 sms_board_event(coredev, BOARD_EVENT_FE_LOCK);
101 }
102 break;
103 case DVB3_EVENT_FE_UNLOCK:
104 if (client->event_fe_state != DVB3_EVENT_FE_UNLOCK) {
105 client->event_fe_state = DVB3_EVENT_FE_UNLOCK;
106 sms_debug("DVB3_EVENT_FE_UNLOCK");
107 sms_board_event(coredev, BOARD_EVENT_FE_UNLOCK);
108 }
109 break;
110 case DVB3_EVENT_UNC_OK:
111 if (client->event_unc_state != DVB3_EVENT_UNC_OK) {
112 client->event_unc_state = DVB3_EVENT_UNC_OK;
113 sms_debug("DVB3_EVENT_UNC_OK");
114 sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_OK);
115 }
116 break;
117 case DVB3_EVENT_UNC_ERR:
118 if (client->event_unc_state != DVB3_EVENT_UNC_ERR) {
119 client->event_unc_state = DVB3_EVENT_UNC_ERR;
120 sms_debug("DVB3_EVENT_UNC_ERR");
121 sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_ERRORS);
122 }
123 break;
124
125 default:
126 sms_err("Unknown dvb3 api event");
127 break;
128 }
129}
130
131static void smsdvb_stats_not_ready(struct dvb_frontend *fe)
132{
133 struct smsdvb_client_t *client =
134 container_of(fe, struct smsdvb_client_t, frontend);
135 struct smscore_device_t *coredev = client->coredev;
136 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
137 int i, n_layers;
138
139 switch (smscore_get_device_mode(coredev)) {
140 case DEVICE_MODE_ISDBT:
141 case DEVICE_MODE_ISDBT_BDA:
142 n_layers = 4;
143 default:
144 n_layers = 1;
145 }
146
147 /* Global stats */
148 c->strength.len = 1;
149 c->cnr.len = 1;
150 c->strength.stat[0].scale = FE_SCALE_DECIBEL;
151 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
152
153 /* Per-layer stats */
154 c->post_bit_error.len = n_layers;
155 c->post_bit_count.len = n_layers;
156 c->block_error.len = n_layers;
157 c->block_count.len = n_layers;
158
159 /*
160 * Put all of them at FE_SCALE_NOT_AVAILABLE. They're dynamically
161 * changed when the stats become available.
162 */
163 for (i = 0; i < n_layers; i++) {
164 c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
165 c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
166 c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
167 c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
168 }
169}
170
171static inline int sms_to_mode(u32 mode)
172{
173 switch (mode) {
174 case 2:
175 return TRANSMISSION_MODE_2K;
176 case 4:
177 return TRANSMISSION_MODE_4K;
178 case 8:
179 return TRANSMISSION_MODE_8K;
180 }
181 return TRANSMISSION_MODE_AUTO;
182}
183
184static inline int sms_to_status(u32 is_demod_locked, u32 is_rf_locked)
185{
186 if (is_demod_locked)
187 return FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI |
188 FE_HAS_SYNC | FE_HAS_LOCK;
189
190 if (is_rf_locked)
191 return FE_HAS_SIGNAL | FE_HAS_CARRIER;
192
193 return 0;
194}
195
196static inline u32 sms_to_bw(u32 value)
197{
198 return value * 1000000;
199}
200
201#define convert_from_table(value, table, defval) ({ \
202 u32 __ret; \
203 if (value < ARRAY_SIZE(table)) \
204 __ret = table[value]; \
205 else \
206 __ret = defval; \
207 __ret; \
208})
209
210#define sms_to_guard_interval(value) \
211 convert_from_table(value, sms_to_guard_interval_table, \
212 GUARD_INTERVAL_AUTO);
213
214#define sms_to_code_rate(value) \
215 convert_from_table(value, sms_to_code_rate_table, \
216 FEC_NONE);
217
218#define sms_to_hierarchy(value) \
219 convert_from_table(value, sms_to_hierarchy_table, \
220 FEC_NONE);
221
222#define sms_to_modulation(value) \
223 convert_from_table(value, sms_to_modulation_table, \
224 FEC_NONE);
225
226static void smsdvb_update_tx_params(struct smsdvb_client_t *client,
227 struct sms_tx_stats *p)
228{
229 struct dvb_frontend *fe = &client->frontend;
230 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
231
232 c->frequency = p->frequency;
233 client->fe_status = sms_to_status(p->is_demod_locked, 0);
234 c->bandwidth_hz = sms_to_bw(p->bandwidth);
235 c->transmission_mode = sms_to_mode(p->transmission_mode);
236 c->guard_interval = sms_to_guard_interval(p->guard_interval);
237 c->code_rate_HP = sms_to_code_rate(p->code_rate);
238 c->code_rate_LP = sms_to_code_rate(p->lp_code_rate);
239 c->hierarchy = sms_to_hierarchy(p->hierarchy);
240 c->modulation = sms_to_modulation(p->constellation);
241}
242
243static void smsdvb_update_per_slices(struct smsdvb_client_t *client,
244 struct RECEPTION_STATISTICS_PER_SLICES_S *p)
245{
246 struct dvb_frontend *fe = &client->frontend;
247 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
248 u64 tmp;
249
250 client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked);
251 c->modulation = sms_to_modulation(p->constellation);
252
253 /* signal Strength, in DBm */
254 c->strength.stat[0].uvalue = p->in_band_power * 1000;
255
256 /* Carrier to noise ratio, in DB */
257 c->cnr.stat[0].svalue = p->snr * 1000;
258
259 /* PER/BER requires demod lock */
260 if (!p->is_demod_locked)
261 return;
262
263 /* TS PER */
264 client->last_per = c->block_error.stat[0].uvalue;
265 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
266 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
267 c->block_error.stat[0].uvalue += p->ets_packets;
268 c->block_count.stat[0].uvalue += p->ets_packets + p->ts_packets;
269
270 /* ber */
271 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
272 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
273 c->post_bit_error.stat[0].uvalue += p->ber_error_count;
274 c->post_bit_count.stat[0].uvalue += p->ber_bit_count;
275
276 /* Legacy PER/BER */
277 tmp = p->ets_packets * 65535;
278 do_div(tmp, p->ts_packets + p->ets_packets);
279 client->legacy_per = tmp;
280}
281
282static void smsdvb_update_dvb_stats(struct smsdvb_client_t *client,
283 struct sms_stats *p)
284{
285 struct dvb_frontend *fe = &client->frontend;
286 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
287
288 if (client->prt_dvb_stats)
289 client->prt_dvb_stats(client->debug_data, p);
290
291 client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked);
292
293 /* Update DVB modulation parameters */
294 c->frequency = p->frequency;
295 client->fe_status = sms_to_status(p->is_demod_locked, 0);
296 c->bandwidth_hz = sms_to_bw(p->bandwidth);
297 c->transmission_mode = sms_to_mode(p->transmission_mode);
298 c->guard_interval = sms_to_guard_interval(p->guard_interval);
299 c->code_rate_HP = sms_to_code_rate(p->code_rate);
300 c->code_rate_LP = sms_to_code_rate(p->lp_code_rate);
301 c->hierarchy = sms_to_hierarchy(p->hierarchy);
302 c->modulation = sms_to_modulation(p->constellation);
303
304 /* update reception data */
305 c->lna = p->is_external_lna_on ? 1 : 0;
306
307 /* Carrier to noise ratio, in DB */
308 c->cnr.stat[0].svalue = p->SNR * 1000;
309
310 /* signal Strength, in DBm */
311 c->strength.stat[0].uvalue = p->in_band_pwr * 1000;
312
313 /* PER/BER requires demod lock */
314 if (!p->is_demod_locked)
315 return;
316
317 /* TS PER */
318 client->last_per = c->block_error.stat[0].uvalue;
319 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
320 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
321 c->block_error.stat[0].uvalue += p->error_ts_packets;
322 c->block_count.stat[0].uvalue += p->total_ts_packets;
323
324 /* ber */
325 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
326 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
327 c->post_bit_error.stat[0].uvalue += p->ber_error_count;
328 c->post_bit_count.stat[0].uvalue += p->ber_bit_count;
329
330 /* Legacy PER/BER */
331 client->legacy_ber = p->ber;
332};
333
334static void smsdvb_update_isdbt_stats(struct smsdvb_client_t *client,
335 struct sms_isdbt_stats *p)
336{
337 struct dvb_frontend *fe = &client->frontend;
338 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
339 struct sms_isdbt_layer_stats *lr;
340 int i, n_layers;
341
342 if (client->prt_isdb_stats)
343 client->prt_isdb_stats(client->debug_data, p);
344
345 client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked);
346
347 /*
348 * Firmware 2.1 seems to report only lock status and
349 * signal strength. The signal strength indicator is at the
350 * wrong field.
351 */
352 if (p->statistics_type == 0) {
353 c->strength.stat[0].uvalue = ((s32)p->transmission_mode) * 1000;
354 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
355 return;
356 }
357
358 /* Update ISDB-T transmission parameters */
359 c->frequency = p->frequency;
360 c->bandwidth_hz = sms_to_bw(p->bandwidth);
361 c->transmission_mode = sms_to_mode(p->transmission_mode);
362 c->guard_interval = sms_to_guard_interval(p->guard_interval);
363 c->isdbt_partial_reception = p->partial_reception ? 1 : 0;
364 n_layers = p->num_of_layers;
365 if (n_layers < 1)
366 n_layers = 1;
367 if (n_layers > 3)
368 n_layers = 3;
369 c->isdbt_layer_enabled = 0;
370
371 /* update reception data */
372 c->lna = p->is_external_lna_on ? 1 : 0;
373
374 /* Carrier to noise ratio, in DB */
375 c->cnr.stat[0].svalue = p->SNR * 1000;
376
377 /* signal Strength, in DBm */
378 c->strength.stat[0].uvalue = p->in_band_pwr * 1000;
379
380 /* PER/BER and per-layer stats require demod lock */
381 if (!p->is_demod_locked)
382 return;
383
384 client->last_per = c->block_error.stat[0].uvalue;
385
386 /* Clears global counters, as the code below will sum it again */
387 c->block_error.stat[0].uvalue = 0;
388 c->block_count.stat[0].uvalue = 0;
389 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
390 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
391 c->post_bit_error.stat[0].uvalue = 0;
392 c->post_bit_count.stat[0].uvalue = 0;
393 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
394 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
395
396 for (i = 0; i < n_layers; i++) {
397 lr = &p->layer_info[i];
398
399 /* Update per-layer transmission parameters */
400 if (lr->number_of_segments > 0 && lr->number_of_segments < 13) {
401 c->isdbt_layer_enabled |= 1 << i;
402 c->layer[i].segment_count = lr->number_of_segments;
403 } else {
404 continue;
405 }
406 c->layer[i].modulation = sms_to_modulation(lr->constellation);
407
408 /* TS PER */
409 c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
410 c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
411 c->block_error.stat[i + 1].uvalue += lr->error_ts_packets;
412 c->block_count.stat[i + 1].uvalue += lr->total_ts_packets;
413
414 /* Update global PER counter */
415 c->block_error.stat[0].uvalue += lr->error_ts_packets;
416 c->block_count.stat[0].uvalue += lr->total_ts_packets;
417
418 /* BER */
419 c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
420 c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
421 c->post_bit_error.stat[i + 1].uvalue += lr->ber_error_count;
422 c->post_bit_count.stat[i + 1].uvalue += lr->ber_bit_count;
423
424 /* Update global BER counter */
425 c->post_bit_error.stat[0].uvalue += lr->ber_error_count;
426 c->post_bit_count.stat[0].uvalue += lr->ber_bit_count;
427 }
428}
429
430static void smsdvb_update_isdbt_stats_ex(struct smsdvb_client_t *client,
431 struct sms_isdbt_stats_ex *p)
432{
433 struct dvb_frontend *fe = &client->frontend;
434 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
435 struct sms_isdbt_layer_stats *lr;
436 int i, n_layers;
437
438 if (client->prt_isdb_stats_ex)
439 client->prt_isdb_stats_ex(client->debug_data, p);
440
441 /* Update ISDB-T transmission parameters */
442 c->frequency = p->frequency;
443 client->fe_status = sms_to_status(p->is_demod_locked, 0);
444 c->bandwidth_hz = sms_to_bw(p->bandwidth);
445 c->transmission_mode = sms_to_mode(p->transmission_mode);
446 c->guard_interval = sms_to_guard_interval(p->guard_interval);
447 c->isdbt_partial_reception = p->partial_reception ? 1 : 0;
448 n_layers = p->num_of_layers;
449 if (n_layers < 1)
450 n_layers = 1;
451 if (n_layers > 3)
452 n_layers = 3;
453 c->isdbt_layer_enabled = 0;
454
455 /* update reception data */
456 c->lna = p->is_external_lna_on ? 1 : 0;
457
458 /* Carrier to noise ratio, in DB */
459 c->cnr.stat[0].svalue = p->SNR * 1000;
460
461 /* signal Strength, in DBm */
462 c->strength.stat[0].uvalue = p->in_band_pwr * 1000;
463
464 /* PER/BER and per-layer stats require demod lock */
465 if (!p->is_demod_locked)
466 return;
467
468 client->last_per = c->block_error.stat[0].uvalue;
469
470 /* Clears global counters, as the code below will sum it again */
471 c->block_error.stat[0].uvalue = 0;
472 c->block_count.stat[0].uvalue = 0;
473 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
474 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
475 c->post_bit_error.stat[0].uvalue = 0;
476 c->post_bit_count.stat[0].uvalue = 0;
477 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
478 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
479
480 c->post_bit_error.len = n_layers + 1;
481 c->post_bit_count.len = n_layers + 1;
482 c->block_error.len = n_layers + 1;
483 c->block_count.len = n_layers + 1;
484 for (i = 0; i < n_layers; i++) {
485 lr = &p->layer_info[i];
486
487 /* Update per-layer transmission parameters */
488 if (lr->number_of_segments > 0 && lr->number_of_segments < 13) {
489 c->isdbt_layer_enabled |= 1 << i;
490 c->layer[i].segment_count = lr->number_of_segments;
491 } else {
492 continue;
493 }
494 c->layer[i].modulation = sms_to_modulation(lr->constellation);
495
496 /* TS PER */
497 c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
498 c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
499 c->block_error.stat[i + 1].uvalue += lr->error_ts_packets;
500 c->block_count.stat[i + 1].uvalue += lr->total_ts_packets;
501
502 /* Update global PER counter */
503 c->block_error.stat[0].uvalue += lr->error_ts_packets;
504 c->block_count.stat[0].uvalue += lr->total_ts_packets;
505
506 /* ber */
507 c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
508 c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
509 c->post_bit_error.stat[i + 1].uvalue += lr->ber_error_count;
510 c->post_bit_count.stat[i + 1].uvalue += lr->ber_bit_count;
511
512 /* Update global ber counter */
513 c->post_bit_error.stat[0].uvalue += lr->ber_error_count;
514 c->post_bit_count.stat[0].uvalue += lr->ber_bit_count;
515 }
516}
517
518static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
519{
520 struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
521 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) (((u8 *) cb->p)
522 + cb->offset);
523 void *p = phdr + 1;
524 struct dvb_frontend *fe = &client->frontend;
525 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
526 bool is_status_update = false;
527
528 switch (phdr->msg_type) {
529 case MSG_SMS_DVBT_BDA_DATA:
530 /*
531 * Only feed data to dvb demux if are there any feed listening
532 * to it and if the device has tuned
533 */
534 if (client->feed_users && client->has_tuned)
535 dvb_dmx_swfilter(&client->demux, p,
536 cb->size - sizeof(struct sms_msg_hdr));
537 break;
538
539 case MSG_SMS_RF_TUNE_RES:
540 case MSG_SMS_ISDBT_TUNE_RES:
541 complete(&client->tune_done);
542 break;
543
544 case MSG_SMS_SIGNAL_DETECTED_IND:
545 client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
546 FE_HAS_VITERBI | FE_HAS_SYNC |
547 FE_HAS_LOCK;
548
549 is_status_update = true;
550 break;
551
552 case MSG_SMS_NO_SIGNAL_IND:
553 client->fe_status = 0;
554
555 is_status_update = true;
556 break;
557
558 case MSG_SMS_TRANSMISSION_IND:
559 smsdvb_update_tx_params(client, p);
560
561 is_status_update = true;
562 break;
563
564 case MSG_SMS_HO_PER_SLICES_IND:
565 smsdvb_update_per_slices(client, p);
566
567 is_status_update = true;
568 break;
569
570 case MSG_SMS_GET_STATISTICS_RES:
571 switch (smscore_get_device_mode(client->coredev)) {
572 case DEVICE_MODE_ISDBT:
573 case DEVICE_MODE_ISDBT_BDA:
574 smsdvb_update_isdbt_stats(client, p);
575 break;
576 default:
577 /* Skip sms_msg_statistics_info:request_result field */
578 smsdvb_update_dvb_stats(client, p + sizeof(u32));
579 }
580
581 is_status_update = true;
582 break;
583
584 /* Only for ISDB-T */
585 case MSG_SMS_GET_STATISTICS_EX_RES:
586 /* Skip sms_msg_statistics_info:request_result field? */
587 smsdvb_update_isdbt_stats_ex(client, p + sizeof(u32));
588 is_status_update = true;
589 break;
590 default:
591 sms_info("message not handled");
592 }
593 smscore_putbuffer(client->coredev, cb);
594
595 if (is_status_update) {
596 if (client->fe_status & FE_HAS_LOCK) {
597 sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK);
598 if (client->last_per == c->block_error.stat[0].uvalue)
599 sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK);
600 else
601 sms_board_dvb3_event(client, DVB3_EVENT_UNC_ERR);
602 client->has_tuned = true;
603 } else {
604 smsdvb_stats_not_ready(fe);
605 client->has_tuned = false;
606 sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK);
607 }
608 complete(&client->stats_done);
609 }
610
611 return 0;
612}
613
614static void smsdvb_unregister_client(struct smsdvb_client_t *client)
615{
616 /* must be called under clientslock */
617
618 list_del(&client->entry);
619
620 smsdvb_debugfs_release(client);
621 smscore_unregister_client(client->smsclient);
622 dvb_unregister_frontend(&client->frontend);
623 dvb_dmxdev_release(&client->dmxdev);
624 dvb_dmx_release(&client->demux);
625 dvb_unregister_adapter(&client->adapter);
626 kfree(client);
627}
628
629static void smsdvb_onremove(void *context)
630{
631 kmutex_lock(&g_smsdvb_clientslock);
632
633 smsdvb_unregister_client((struct smsdvb_client_t *) context);
634
635 kmutex_unlock(&g_smsdvb_clientslock);
636}
637
638static int smsdvb_start_feed(struct dvb_demux_feed *feed)
639{
640 struct smsdvb_client_t *client =
641 container_of(feed->demux, struct smsdvb_client_t, demux);
642 struct sms_msg_data pid_msg;
643
644 sms_debug("add pid %d(%x)",
645 feed->pid, feed->pid);
646
647 client->feed_users++;
648
649 pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
650 pid_msg.x_msg_header.msg_dst_id = HIF_TASK;
651 pid_msg.x_msg_header.msg_flags = 0;
652 pid_msg.x_msg_header.msg_type = MSG_SMS_ADD_PID_FILTER_REQ;
653 pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
654 pid_msg.msg_data[0] = feed->pid;
655
656 return smsclient_sendrequest(client->smsclient,
657 &pid_msg, sizeof(pid_msg));
658}
659
660static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
661{
662 struct smsdvb_client_t *client =
663 container_of(feed->demux, struct smsdvb_client_t, demux);
664 struct sms_msg_data pid_msg;
665
666 sms_debug("remove pid %d(%x)",
667 feed->pid, feed->pid);
668
669 client->feed_users--;
670
671 pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
672 pid_msg.x_msg_header.msg_dst_id = HIF_TASK;
673 pid_msg.x_msg_header.msg_flags = 0;
674 pid_msg.x_msg_header.msg_type = MSG_SMS_REMOVE_PID_FILTER_REQ;
675 pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
676 pid_msg.msg_data[0] = feed->pid;
677
678 return smsclient_sendrequest(client->smsclient,
679 &pid_msg, sizeof(pid_msg));
680}
681
682static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
683 void *buffer, size_t size,
684 struct completion *completion)
685{
686 int rc;
687
688 rc = smsclient_sendrequest(client->smsclient, buffer, size);
689 if (rc < 0)
690 return rc;
691
692 return wait_for_completion_timeout(completion,
693 msecs_to_jiffies(2000)) ?
694 0 : -ETIME;
695}
696
697static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
698{
699 int rc;
700 struct sms_msg_hdr msg;
701
702 /* Don't request stats too fast */
703 if (client->get_stats_jiffies &&
704 (!time_after(jiffies, client->get_stats_jiffies)))
705 return 0;
706 client->get_stats_jiffies = jiffies + msecs_to_jiffies(100);
707
708 msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
709 msg.msg_dst_id = HIF_TASK;
710 msg.msg_flags = 0;
711 msg.msg_length = sizeof(msg);
712
713 switch (smscore_get_device_mode(client->coredev)) {
714 case DEVICE_MODE_ISDBT:
715 case DEVICE_MODE_ISDBT_BDA:
716 /*
717 * Check for firmware version, to avoid breaking for old cards
718 */
719 if (client->coredev->fw_version >= 0x800)
720 msg.msg_type = MSG_SMS_GET_STATISTICS_EX_REQ;
721 else
722 msg.msg_type = MSG_SMS_GET_STATISTICS_REQ;
723 break;
724 default:
725 msg.msg_type = MSG_SMS_GET_STATISTICS_REQ;
726 }
727
728 rc = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
729 &client->stats_done);
730
731 return rc;
732}
733
734static inline int led_feedback(struct smsdvb_client_t *client)
735{
736 if (!(client->fe_status & FE_HAS_LOCK))
737 return sms_board_led_feedback(client->coredev, SMS_LED_OFF);
738
739 return sms_board_led_feedback(client->coredev,
740 (client->legacy_ber == 0) ?
741 SMS_LED_HI : SMS_LED_LO);
742}
743
744static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat)
745{
746 int rc;
747 struct smsdvb_client_t *client;
748 client = container_of(fe, struct smsdvb_client_t, frontend);
749
750 rc = smsdvb_send_statistics_request(client);
751
752 *stat = client->fe_status;
753
754 led_feedback(client);
755
756 return rc;
757}
758
759static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
760{
761 int rc;
762 struct smsdvb_client_t *client;
763
764 client = container_of(fe, struct smsdvb_client_t, frontend);
765
766 rc = smsdvb_send_statistics_request(client);
767
768 *ber = client->legacy_ber;
769
770 led_feedback(client);
771
772 return rc;
773}
774
775static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
776{
777 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
778 int rc;
779 s32 power = (s32) c->strength.stat[0].uvalue;
780 struct smsdvb_client_t *client;
781
782 client = container_of(fe, struct smsdvb_client_t, frontend);
783
784 rc = smsdvb_send_statistics_request(client);
785
786 if (power < -95)
787 *strength = 0;
788 else if (power > -29)
789 *strength = 65535;
790 else
791 *strength = (power + 95) * 65535 / 66;
792
793 led_feedback(client);
794
795 return rc;
796}
797
798static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
799{
800 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
801 int rc;
802 struct smsdvb_client_t *client;
803
804 client = container_of(fe, struct smsdvb_client_t, frontend);
805
806 rc = smsdvb_send_statistics_request(client);
807
808 /* Preferred scale for SNR with legacy API: 0.1 dB */
809 *snr = ((u32)c->cnr.stat[0].svalue) / 100;
810
811 led_feedback(client);
812
813 return rc;
814}
815
816static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
817{
818 int rc;
819 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
820 struct smsdvb_client_t *client;
821
822 client = container_of(fe, struct smsdvb_client_t, frontend);
823
824 rc = smsdvb_send_statistics_request(client);
825
826 *ucblocks = c->block_error.stat[0].uvalue;
827
828 led_feedback(client);
829
830 return rc;
831}
832
833static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
834 struct dvb_frontend_tune_settings *tune)
835{
836 sms_debug("");
837
838 tune->min_delay_ms = 400;
839 tune->step_size = 250000;
840 tune->max_drift = 0;
841 return 0;
842}
843
844static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
845{
846 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
847 struct smsdvb_client_t *client =
848 container_of(fe, struct smsdvb_client_t, frontend);
849
850 struct {
851 struct sms_msg_hdr msg;
852 u32 Data[3];
853 } msg;
854
855 int ret;
856
857 client->fe_status = 0;
858 client->event_fe_state = -1;
859 client->event_unc_state = -1;
860 fe->dtv_property_cache.delivery_system = SYS_DVBT;
861
862 msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
863 msg.msg.msg_dst_id = HIF_TASK;
864 msg.msg.msg_flags = 0;
865 msg.msg.msg_type = MSG_SMS_RF_TUNE_REQ;
866 msg.msg.msg_length = sizeof(msg);
867 msg.Data[0] = c->frequency;
868 msg.Data[2] = 12000000;
869
870 sms_info("%s: freq %d band %d", __func__, c->frequency,
871 c->bandwidth_hz);
872
873 switch (c->bandwidth_hz / 1000000) {
874 case 8:
875 msg.Data[1] = BW_8_MHZ;
876 break;
877 case 7:
878 msg.Data[1] = BW_7_MHZ;
879 break;
880 case 6:
881 msg.Data[1] = BW_6_MHZ;
882 break;
883 case 0:
884 return -EOPNOTSUPP;
885 default:
886 return -EINVAL;
887 }
888 /* Disable LNA, if any. An error is returned if no LNA is present */
889 ret = sms_board_lna_control(client->coredev, 0);
890 if (ret == 0) {
891 fe_status_t status;
892
893 /* tune with LNA off at first */
894 ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
895 &client->tune_done);
896
897 smsdvb_read_status(fe, &status);
898
899 if (status & FE_HAS_LOCK)
900 return ret;
901
902 /* previous tune didn't lock - enable LNA and tune again */
903 sms_board_lna_control(client->coredev, 1);
904 }
905
906 return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
907 &client->tune_done);
908}
909
910static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
911{
912 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
913 struct smsdvb_client_t *client =
914 container_of(fe, struct smsdvb_client_t, frontend);
915 int board_id = smscore_get_board_id(client->coredev);
916 struct sms_board *board = sms_get_board(board_id);
917 enum sms_device_type_st type = board->type;
918 int ret;
919
920 struct {
921 struct sms_msg_hdr msg;
922 u32 Data[4];
923 } msg;
924
925 fe->dtv_property_cache.delivery_system = SYS_ISDBT;
926
927 msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
928 msg.msg.msg_dst_id = HIF_TASK;
929 msg.msg.msg_flags = 0;
930 msg.msg.msg_type = MSG_SMS_ISDBT_TUNE_REQ;
931 msg.msg.msg_length = sizeof(msg);
932
933 if (c->isdbt_sb_segment_idx == -1)
934 c->isdbt_sb_segment_idx = 0;
935
936 if (!c->isdbt_layer_enabled)
937 c->isdbt_layer_enabled = 7;
938
939 msg.Data[0] = c->frequency;
940 msg.Data[1] = BW_ISDBT_1SEG;
941 msg.Data[2] = 12000000;
942 msg.Data[3] = c->isdbt_sb_segment_idx;
943
944 if (c->isdbt_partial_reception) {
945 if ((type == SMS_PELE || type == SMS_RIO) &&
946 c->isdbt_sb_segment_count > 3)
947 msg.Data[1] = BW_ISDBT_13SEG;
948 else if (c->isdbt_sb_segment_count > 1)
949 msg.Data[1] = BW_ISDBT_3SEG;
950 } else if (type == SMS_PELE || type == SMS_RIO)
951 msg.Data[1] = BW_ISDBT_13SEG;
952
953 c->bandwidth_hz = 6000000;
954
955 sms_info("%s: freq %d segwidth %d segindex %d", __func__,
956 c->frequency, c->isdbt_sb_segment_count,
957 c->isdbt_sb_segment_idx);
958
959 /* Disable LNA, if any. An error is returned if no LNA is present */
960 ret = sms_board_lna_control(client->coredev, 0);
961 if (ret == 0) {
962 fe_status_t status;
963
964 /* tune with LNA off at first */
965 ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
966 &client->tune_done);
967
968 smsdvb_read_status(fe, &status);
969
970 if (status & FE_HAS_LOCK)
971 return ret;
972
973 /* previous tune didn't lock - enable LNA and tune again */
974 sms_board_lna_control(client->coredev, 1);
975 }
976 return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
977 &client->tune_done);
978}
979
980static int smsdvb_set_frontend(struct dvb_frontend *fe)
981{
982 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
983 struct smsdvb_client_t *client =
984 container_of(fe, struct smsdvb_client_t, frontend);
985 struct smscore_device_t *coredev = client->coredev;
986
987 smsdvb_stats_not_ready(fe);
988 c->strength.stat[0].uvalue = 0;
989 c->cnr.stat[0].uvalue = 0;
990
991 client->has_tuned = false;
992
993 switch (smscore_get_device_mode(coredev)) {
994 case DEVICE_MODE_DVBT:
995 case DEVICE_MODE_DVBT_BDA:
996 return smsdvb_dvbt_set_frontend(fe);
997 case DEVICE_MODE_ISDBT:
998 case DEVICE_MODE_ISDBT_BDA:
999 return smsdvb_isdbt_set_frontend(fe);
1000 default:
1001 return -EINVAL;
1002 }
1003}
1004
1005/* Nothing to do here, as stats are automatically updated */
1006static int smsdvb_get_frontend(struct dvb_frontend *fe)
1007{
1008 return 0;
1009}
1010
1011static int smsdvb_init(struct dvb_frontend *fe)
1012{
1013 struct smsdvb_client_t *client =
1014 container_of(fe, struct smsdvb_client_t, frontend);
1015
1016 sms_board_power(client->coredev, 1);
1017
1018 sms_board_dvb3_event(client, DVB3_EVENT_INIT);
1019 return 0;
1020}
1021
1022static int smsdvb_sleep(struct dvb_frontend *fe)
1023{
1024 struct smsdvb_client_t *client =
1025 container_of(fe, struct smsdvb_client_t, frontend);
1026
1027 sms_board_led_feedback(client->coredev, SMS_LED_OFF);
1028 sms_board_power(client->coredev, 0);
1029
1030 sms_board_dvb3_event(client, DVB3_EVENT_SLEEP);
1031
1032 return 0;
1033}
1034
1035static void smsdvb_release(struct dvb_frontend *fe)
1036{
1037 /* do nothing */
1038}
1039
1040static struct dvb_frontend_ops smsdvb_fe_ops = {
1041 .info = {
1042 .name = "Siano Mobile Digital MDTV Receiver",
1043 .frequency_min = 44250000,
1044 .frequency_max = 867250000,
1045 .frequency_stepsize = 250000,
1046 .caps = FE_CAN_INVERSION_AUTO |
1047 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1048 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1049 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
1050 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
1051 FE_CAN_GUARD_INTERVAL_AUTO |
1052 FE_CAN_RECOVER |
1053 FE_CAN_HIERARCHY_AUTO,
1054 },
1055
1056 .release = smsdvb_release,
1057
1058 .set_frontend = smsdvb_set_frontend,
1059 .get_frontend = smsdvb_get_frontend,
1060 .get_tune_settings = smsdvb_get_tune_settings,
1061
1062 .read_status = smsdvb_read_status,
1063 .read_ber = smsdvb_read_ber,
1064 .read_signal_strength = smsdvb_read_signal_strength,
1065 .read_snr = smsdvb_read_snr,
1066 .read_ucblocks = smsdvb_read_ucblocks,
1067
1068 .init = smsdvb_init,
1069 .sleep = smsdvb_sleep,
1070};
1071
1072static int smsdvb_hotplug(struct smscore_device_t *coredev,
1073 struct device *device, int arrival)
1074{
1075 struct smsclient_params_t params;
1076 struct smsdvb_client_t *client;
1077 int rc;
1078
1079 /* device removal handled by onremove callback */
1080 if (!arrival)
1081 return 0;
1082 client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
1083 if (!client) {
1084 sms_err("kmalloc() failed");
1085 return -ENOMEM;
1086 }
1087
1088 /* register dvb adapter */
1089 rc = dvb_register_adapter(&client->adapter,
1090 sms_get_board(
1091 smscore_get_board_id(coredev))->name,
1092 THIS_MODULE, device, adapter_nr);
1093 if (rc < 0) {
1094 sms_err("dvb_register_adapter() failed %d", rc);
1095 goto adapter_error;
1096 }
1097
1098 /* init dvb demux */
1099 client->demux.dmx.capabilities = DMX_TS_FILTERING;
1100 client->demux.filternum = 32; /* todo: nova ??? */
1101 client->demux.feednum = 32;
1102 client->demux.start_feed = smsdvb_start_feed;
1103 client->demux.stop_feed = smsdvb_stop_feed;
1104
1105 rc = dvb_dmx_init(&client->demux);
1106 if (rc < 0) {
1107 sms_err("dvb_dmx_init failed %d", rc);
1108 goto dvbdmx_error;
1109 }
1110
1111 /* init dmxdev */
1112 client->dmxdev.filternum = 32;
1113 client->dmxdev.demux = &client->demux.dmx;
1114 client->dmxdev.capabilities = 0;
1115
1116 rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
1117 if (rc < 0) {
1118 sms_err("dvb_dmxdev_init failed %d", rc);
1119 goto dmxdev_error;
1120 }
1121
1122 /* init and register frontend */
1123 memcpy(&client->frontend.ops, &smsdvb_fe_ops,
1124 sizeof(struct dvb_frontend_ops));
1125
1126 switch (smscore_get_device_mode(coredev)) {
1127 case DEVICE_MODE_DVBT:
1128 case DEVICE_MODE_DVBT_BDA:
1129 client->frontend.ops.delsys[0] = SYS_DVBT;
1130 break;
1131 case DEVICE_MODE_ISDBT:
1132 case DEVICE_MODE_ISDBT_BDA:
1133 client->frontend.ops.delsys[0] = SYS_ISDBT;
1134 break;
1135 }
1136
1137 rc = dvb_register_frontend(&client->adapter, &client->frontend);
1138 if (rc < 0) {
1139 sms_err("frontend registration failed %d", rc);
1140 goto frontend_error;
1141 }
1142
1143 params.initial_id = 1;
1144 params.data_type = MSG_SMS_DVBT_BDA_DATA;
1145 params.onresponse_handler = smsdvb_onresponse;
1146 params.onremove_handler = smsdvb_onremove;
1147 params.context = client;
1148
1149 rc = smscore_register_client(coredev, &params, &client->smsclient);
1150 if (rc < 0) {
1151 sms_err("smscore_register_client() failed %d", rc);
1152 goto client_error;
1153 }
1154
1155 client->coredev = coredev;
1156
1157 init_completion(&client->tune_done);
1158 init_completion(&client->stats_done);
1159
1160 kmutex_lock(&g_smsdvb_clientslock);
1161
1162 list_add(&client->entry, &g_smsdvb_clients);
1163
1164 kmutex_unlock(&g_smsdvb_clientslock);
1165
1166 client->event_fe_state = -1;
1167 client->event_unc_state = -1;
1168 sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG);
1169
1170 sms_info("success");
1171 sms_board_setup(coredev);
1172
1173 if (smsdvb_debugfs_create(client) < 0)
1174 sms_info("failed to create debugfs node");
1175
1176 return 0;
1177
1178client_error:
1179 dvb_unregister_frontend(&client->frontend);
1180
1181frontend_error:
1182 dvb_dmxdev_release(&client->dmxdev);
1183
1184dmxdev_error:
1185 dvb_dmx_release(&client->demux);
1186
1187dvbdmx_error:
1188 dvb_unregister_adapter(&client->adapter);
1189
1190adapter_error:
1191 kfree(client);
1192 return rc;
1193}
1194
1195static int __init smsdvb_module_init(void)
1196{
1197 int rc;
1198
1199 INIT_LIST_HEAD(&g_smsdvb_clients);
1200 kmutex_init(&g_smsdvb_clientslock);
1201
1202 smsdvb_debugfs_register();
1203
1204 rc = smscore_register_hotplug(smsdvb_hotplug);
1205
1206 sms_debug("");
1207
1208 return rc;
1209}
1210
1211static void __exit smsdvb_module_exit(void)
1212{
1213 smscore_unregister_hotplug(smsdvb_hotplug);
1214
1215 kmutex_lock(&g_smsdvb_clientslock);
1216
1217 while (!list_empty(&g_smsdvb_clients))
1218 smsdvb_unregister_client((struct smsdvb_client_t *)g_smsdvb_clients.next);
1219
1220 smsdvb_debugfs_unregister();
1221
1222 kmutex_unlock(&g_smsdvb_clientslock);
1223}
1224
1225module_init(smsdvb_module_init);
1226module_exit(smsdvb_module_exit);
1227
1228MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
1229MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
1230MODULE_LICENSE("GPL");
diff --git a/drivers/media/common/siano/smsdvb.c b/drivers/media/common/siano/smsdvb.c
deleted file mode 100644
index aa77e54a8fae..000000000000
--- a/drivers/media/common/siano/smsdvb.c
+++ /dev/null
@@ -1,1078 +0,0 @@
1/****************************************************************
2
3Siano Mobile Silicon, Inc.
4MDTV receiver kernel modules.
5Copyright (C) 2006-2008, Uri Shkolnik
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the 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,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20****************************************************************/
21
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30
31#include "smscoreapi.h"
32#include "smsendian.h"
33#include "sms-cards.h"
34
35DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
36
37struct smsdvb_client_t {
38 struct list_head entry;
39
40 struct smscore_device_t *coredev;
41 struct smscore_client_t *smsclient;
42
43 struct dvb_adapter adapter;
44 struct dvb_demux demux;
45 struct dmxdev dmxdev;
46 struct dvb_frontend frontend;
47
48 fe_status_t fe_status;
49
50 struct completion tune_done;
51
52 struct SMSHOSTLIB_STATISTICS_DVB_S sms_stat_dvb;
53 int event_fe_state;
54 int event_unc_state;
55};
56
57static struct list_head g_smsdvb_clients;
58static struct mutex g_smsdvb_clientslock;
59
60static int sms_dbg;
61module_param_named(debug, sms_dbg, int, 0644);
62MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
63
64/* Events that may come from DVB v3 adapter */
65static void sms_board_dvb3_event(struct smsdvb_client_t *client,
66 enum SMS_DVB3_EVENTS event) {
67
68 struct smscore_device_t *coredev = client->coredev;
69 switch (event) {
70 case DVB3_EVENT_INIT:
71 sms_debug("DVB3_EVENT_INIT");
72 sms_board_event(coredev, BOARD_EVENT_BIND);
73 break;
74 case DVB3_EVENT_SLEEP:
75 sms_debug("DVB3_EVENT_SLEEP");
76 sms_board_event(coredev, BOARD_EVENT_POWER_SUSPEND);
77 break;
78 case DVB3_EVENT_HOTPLUG:
79 sms_debug("DVB3_EVENT_HOTPLUG");
80 sms_board_event(coredev, BOARD_EVENT_POWER_INIT);
81 break;
82 case DVB3_EVENT_FE_LOCK:
83 if (client->event_fe_state != DVB3_EVENT_FE_LOCK) {
84 client->event_fe_state = DVB3_EVENT_FE_LOCK;
85 sms_debug("DVB3_EVENT_FE_LOCK");
86 sms_board_event(coredev, BOARD_EVENT_FE_LOCK);
87 }
88 break;
89 case DVB3_EVENT_FE_UNLOCK:
90 if (client->event_fe_state != DVB3_EVENT_FE_UNLOCK) {
91 client->event_fe_state = DVB3_EVENT_FE_UNLOCK;
92 sms_debug("DVB3_EVENT_FE_UNLOCK");
93 sms_board_event(coredev, BOARD_EVENT_FE_UNLOCK);
94 }
95 break;
96 case DVB3_EVENT_UNC_OK:
97 if (client->event_unc_state != DVB3_EVENT_UNC_OK) {
98 client->event_unc_state = DVB3_EVENT_UNC_OK;
99 sms_debug("DVB3_EVENT_UNC_OK");
100 sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_OK);
101 }
102 break;
103 case DVB3_EVENT_UNC_ERR:
104 if (client->event_unc_state != DVB3_EVENT_UNC_ERR) {
105 client->event_unc_state = DVB3_EVENT_UNC_ERR;
106 sms_debug("DVB3_EVENT_UNC_ERR");
107 sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_ERRORS);
108 }
109 break;
110
111 default:
112 sms_err("Unknown dvb3 api event");
113 break;
114 }
115}
116
117
118static void smsdvb_update_dvb_stats(struct RECEPTION_STATISTICS_S *pReceptionData,
119 struct SMSHOSTLIB_STATISTICS_ST *p)
120{
121 if (sms_dbg & 2) {
122 printk(KERN_DEBUG "Reserved = %d", p->Reserved);
123 printk(KERN_DEBUG "IsRfLocked = %d", p->IsRfLocked);
124 printk(KERN_DEBUG "IsDemodLocked = %d", p->IsDemodLocked);
125 printk(KERN_DEBUG "IsExternalLNAOn = %d", p->IsExternalLNAOn);
126 printk(KERN_DEBUG "SNR = %d", p->SNR);
127 printk(KERN_DEBUG "BER = %d", p->BER);
128 printk(KERN_DEBUG "FIB_CRC = %d", p->FIB_CRC);
129 printk(KERN_DEBUG "TS_PER = %d", p->TS_PER);
130 printk(KERN_DEBUG "MFER = %d", p->MFER);
131 printk(KERN_DEBUG "RSSI = %d", p->RSSI);
132 printk(KERN_DEBUG "InBandPwr = %d", p->InBandPwr);
133 printk(KERN_DEBUG "CarrierOffset = %d", p->CarrierOffset);
134 printk(KERN_DEBUG "Frequency = %d", p->Frequency);
135 printk(KERN_DEBUG "Bandwidth = %d", p->Bandwidth);
136 printk(KERN_DEBUG "TransmissionMode = %d", p->TransmissionMode);
137 printk(KERN_DEBUG "ModemState = %d", p->ModemState);
138 printk(KERN_DEBUG "GuardInterval = %d", p->GuardInterval);
139 printk(KERN_DEBUG "CodeRate = %d", p->CodeRate);
140 printk(KERN_DEBUG "LPCodeRate = %d", p->LPCodeRate);
141 printk(KERN_DEBUG "Hierarchy = %d", p->Hierarchy);
142 printk(KERN_DEBUG "Constellation = %d", p->Constellation);
143 printk(KERN_DEBUG "BurstSize = %d", p->BurstSize);
144 printk(KERN_DEBUG "BurstDuration = %d", p->BurstDuration);
145 printk(KERN_DEBUG "BurstCycleTime = %d", p->BurstCycleTime);
146 printk(KERN_DEBUG "CalculatedBurstCycleTime = %d", p->CalculatedBurstCycleTime);
147 printk(KERN_DEBUG "NumOfRows = %d", p->NumOfRows);
148 printk(KERN_DEBUG "NumOfPaddCols = %d", p->NumOfPaddCols);
149 printk(KERN_DEBUG "NumOfPunctCols = %d", p->NumOfPunctCols);
150 printk(KERN_DEBUG "ErrorTSPackets = %d", p->ErrorTSPackets);
151 printk(KERN_DEBUG "TotalTSPackets = %d", p->TotalTSPackets);
152 printk(KERN_DEBUG "NumOfValidMpeTlbs = %d", p->NumOfValidMpeTlbs);
153 printk(KERN_DEBUG "NumOfInvalidMpeTlbs = %d", p->NumOfInvalidMpeTlbs);
154 printk(KERN_DEBUG "NumOfCorrectedMpeTlbs = %d", p->NumOfCorrectedMpeTlbs);
155 printk(KERN_DEBUG "BERErrorCount = %d", p->BERErrorCount);
156 printk(KERN_DEBUG "BERBitCount = %d", p->BERBitCount);
157 printk(KERN_DEBUG "SmsToHostTxErrors = %d", p->SmsToHostTxErrors);
158 printk(KERN_DEBUG "PreBER = %d", p->PreBER);
159 printk(KERN_DEBUG "CellId = %d", p->CellId);
160 printk(KERN_DEBUG "DvbhSrvIndHP = %d", p->DvbhSrvIndHP);
161 printk(KERN_DEBUG "DvbhSrvIndLP = %d", p->DvbhSrvIndLP);
162 printk(KERN_DEBUG "NumMPEReceived = %d", p->NumMPEReceived);
163 }
164
165 pReceptionData->IsDemodLocked = p->IsDemodLocked;
166
167 pReceptionData->SNR = p->SNR;
168 pReceptionData->BER = p->BER;
169 pReceptionData->BERErrorCount = p->BERErrorCount;
170 pReceptionData->InBandPwr = p->InBandPwr;
171 pReceptionData->ErrorTSPackets = p->ErrorTSPackets;
172};
173
174
175static void smsdvb_update_isdbt_stats(struct RECEPTION_STATISTICS_S *pReceptionData,
176 struct SMSHOSTLIB_STATISTICS_ISDBT_ST *p)
177{
178 int i;
179
180 if (sms_dbg & 2) {
181 printk(KERN_DEBUG "IsRfLocked = %d", p->IsRfLocked);
182 printk(KERN_DEBUG "IsDemodLocked = %d", p->IsDemodLocked);
183 printk(KERN_DEBUG "IsExternalLNAOn = %d", p->IsExternalLNAOn);
184 printk(KERN_DEBUG "SNR = %d", p->SNR);
185 printk(KERN_DEBUG "RSSI = %d", p->RSSI);
186 printk(KERN_DEBUG "InBandPwr = %d", p->InBandPwr);
187 printk(KERN_DEBUG "CarrierOffset = %d", p->CarrierOffset);
188 printk(KERN_DEBUG "Frequency = %d", p->Frequency);
189 printk(KERN_DEBUG "Bandwidth = %d", p->Bandwidth);
190 printk(KERN_DEBUG "TransmissionMode = %d", p->TransmissionMode);
191 printk(KERN_DEBUG "ModemState = %d", p->ModemState);
192 printk(KERN_DEBUG "GuardInterval = %d", p->GuardInterval);
193 printk(KERN_DEBUG "SystemType = %d", p->SystemType);
194 printk(KERN_DEBUG "PartialReception = %d", p->PartialReception);
195 printk(KERN_DEBUG "NumOfLayers = %d", p->NumOfLayers);
196 printk(KERN_DEBUG "SmsToHostTxErrors = %d", p->SmsToHostTxErrors);
197
198 for (i = 0; i < 3; i++) {
199 printk(KERN_DEBUG "%d: CodeRate = %d", i, p->LayerInfo[i].CodeRate);
200 printk(KERN_DEBUG "%d: Constellation = %d", i, p->LayerInfo[i].Constellation);
201 printk(KERN_DEBUG "%d: BER = %d", i, p->LayerInfo[i].BER);
202 printk(KERN_DEBUG "%d: BERErrorCount = %d", i, p->LayerInfo[i].BERErrorCount);
203 printk(KERN_DEBUG "%d: BERBitCount = %d", i, p->LayerInfo[i].BERBitCount);
204 printk(KERN_DEBUG "%d: PreBER = %d", i, p->LayerInfo[i].PreBER);
205 printk(KERN_DEBUG "%d: TS_PER = %d", i, p->LayerInfo[i].TS_PER);
206 printk(KERN_DEBUG "%d: ErrorTSPackets = %d", i, p->LayerInfo[i].ErrorTSPackets);
207 printk(KERN_DEBUG "%d: TotalTSPackets = %d", i, p->LayerInfo[i].TotalTSPackets);
208 printk(KERN_DEBUG "%d: TILdepthI = %d", i, p->LayerInfo[i].TILdepthI);
209 printk(KERN_DEBUG "%d: NumberOfSegments = %d", i, p->LayerInfo[i].NumberOfSegments);
210 printk(KERN_DEBUG "%d: TMCCErrors = %d", i, p->LayerInfo[i].TMCCErrors);
211 }
212 }
213
214 pReceptionData->IsDemodLocked = p->IsDemodLocked;
215
216 pReceptionData->SNR = p->SNR;
217 pReceptionData->InBandPwr = p->InBandPwr;
218
219 pReceptionData->ErrorTSPackets = 0;
220 pReceptionData->BER = 0;
221 pReceptionData->BERErrorCount = 0;
222 for (i = 0; i < 3; i++) {
223 pReceptionData->BER += p->LayerInfo[i].BER;
224 pReceptionData->BERErrorCount += p->LayerInfo[i].BERErrorCount;
225 pReceptionData->ErrorTSPackets += p->LayerInfo[i].ErrorTSPackets;
226 }
227}
228
229static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
230{
231 struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
232 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) (((u8 *) cb->p)
233 + cb->offset);
234 u32 *pMsgData = (u32 *) phdr + 1;
235 /*u32 MsgDataLen = phdr->msgLength - sizeof(struct SmsMsgHdr_ST);*/
236 bool is_status_update = false;
237
238 smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);
239
240 switch (phdr->msgType) {
241 case MSG_SMS_DVBT_BDA_DATA:
242 dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1),
243 cb->size - sizeof(struct SmsMsgHdr_ST));
244 break;
245
246 case MSG_SMS_RF_TUNE_RES:
247 case MSG_SMS_ISDBT_TUNE_RES:
248 complete(&client->tune_done);
249 break;
250
251 case MSG_SMS_SIGNAL_DETECTED_IND:
252 sms_info("MSG_SMS_SIGNAL_DETECTED_IND");
253 client->sms_stat_dvb.TransmissionData.IsDemodLocked = true;
254 is_status_update = true;
255 break;
256
257 case MSG_SMS_NO_SIGNAL_IND:
258 sms_info("MSG_SMS_NO_SIGNAL_IND");
259 client->sms_stat_dvb.TransmissionData.IsDemodLocked = false;
260 is_status_update = true;
261 break;
262
263 case MSG_SMS_TRANSMISSION_IND: {
264 sms_info("MSG_SMS_TRANSMISSION_IND");
265
266 pMsgData++;
267 memcpy(&client->sms_stat_dvb.TransmissionData, pMsgData,
268 sizeof(struct TRANSMISSION_STATISTICS_S));
269
270 /* Mo need to correct guard interval
271 * (as opposed to old statistics message).
272 */
273 CORRECT_STAT_BANDWIDTH(client->sms_stat_dvb.TransmissionData);
274 CORRECT_STAT_TRANSMISSON_MODE(
275 client->sms_stat_dvb.TransmissionData);
276 is_status_update = true;
277 break;
278 }
279 case MSG_SMS_HO_PER_SLICES_IND: {
280 struct RECEPTION_STATISTICS_S *pReceptionData =
281 &client->sms_stat_dvb.ReceptionData;
282 struct SRVM_SIGNAL_STATUS_S SignalStatusData;
283
284 /*sms_info("MSG_SMS_HO_PER_SLICES_IND");*/
285 pMsgData++;
286 SignalStatusData.result = pMsgData[0];
287 SignalStatusData.snr = pMsgData[1];
288 SignalStatusData.inBandPower = (s32) pMsgData[2];
289 SignalStatusData.tsPackets = pMsgData[3];
290 SignalStatusData.etsPackets = pMsgData[4];
291 SignalStatusData.constellation = pMsgData[5];
292 SignalStatusData.hpCode = pMsgData[6];
293 SignalStatusData.tpsSrvIndLP = pMsgData[7] & 0x03;
294 SignalStatusData.tpsSrvIndHP = pMsgData[8] & 0x03;
295 SignalStatusData.cellId = pMsgData[9] & 0xFFFF;
296 SignalStatusData.reason = pMsgData[10];
297 SignalStatusData.requestId = pMsgData[11];
298 pReceptionData->IsRfLocked = pMsgData[16];
299 pReceptionData->IsDemodLocked = pMsgData[17];
300 pReceptionData->ModemState = pMsgData[12];
301 pReceptionData->SNR = pMsgData[1];
302 pReceptionData->BER = pMsgData[13];
303 pReceptionData->RSSI = pMsgData[14];
304 CORRECT_STAT_RSSI(client->sms_stat_dvb.ReceptionData);
305
306 pReceptionData->InBandPwr = (s32) pMsgData[2];
307 pReceptionData->CarrierOffset = (s32) pMsgData[15];
308 pReceptionData->TotalTSPackets = pMsgData[3];
309 pReceptionData->ErrorTSPackets = pMsgData[4];
310
311 /* TS PER */
312 if ((SignalStatusData.tsPackets + SignalStatusData.etsPackets)
313 > 0) {
314 pReceptionData->TS_PER = (SignalStatusData.etsPackets
315 * 100) / (SignalStatusData.tsPackets
316 + SignalStatusData.etsPackets);
317 } else {
318 pReceptionData->TS_PER = 0;
319 }
320
321 pReceptionData->BERBitCount = pMsgData[18];
322 pReceptionData->BERErrorCount = pMsgData[19];
323
324 pReceptionData->MRC_SNR = pMsgData[20];
325 pReceptionData->MRC_InBandPwr = pMsgData[21];
326 pReceptionData->MRC_RSSI = pMsgData[22];
327
328 is_status_update = true;
329 break;
330 }
331 case MSG_SMS_GET_STATISTICS_RES: {
332 union {
333 struct SMSHOSTLIB_STATISTICS_ISDBT_ST isdbt;
334 struct SmsMsgStatisticsInfo_ST dvb;
335 } *p = (void *) (phdr + 1);
336 struct RECEPTION_STATISTICS_S *pReceptionData =
337 &client->sms_stat_dvb.ReceptionData;
338
339 sms_info("MSG_SMS_GET_STATISTICS_RES");
340
341 is_status_update = true;
342
343 switch (smscore_get_device_mode(client->coredev)) {
344 case DEVICE_MODE_ISDBT:
345 case DEVICE_MODE_ISDBT_BDA:
346 smsdvb_update_isdbt_stats(pReceptionData, &p->isdbt);
347 break;
348 default:
349 smsdvb_update_dvb_stats(pReceptionData, &p->dvb.Stat);
350 }
351 if (!pReceptionData->IsDemodLocked) {
352 pReceptionData->SNR = 0;
353 pReceptionData->BER = 0;
354 pReceptionData->BERErrorCount = 0;
355 pReceptionData->InBandPwr = 0;
356 pReceptionData->ErrorTSPackets = 0;
357 }
358
359 complete(&client->tune_done);
360 break;
361 }
362 default:
363 sms_info("Unhandled message %d", phdr->msgType);
364
365 }
366 smscore_putbuffer(client->coredev, cb);
367
368 if (is_status_update) {
369 if (client->sms_stat_dvb.ReceptionData.IsDemodLocked) {
370 client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER
371 | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
372 sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK);
373 if (client->sms_stat_dvb.ReceptionData.ErrorTSPackets
374 == 0)
375 sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK);
376 else
377 sms_board_dvb3_event(client,
378 DVB3_EVENT_UNC_ERR);
379
380 } else {
381 if (client->sms_stat_dvb.ReceptionData.IsRfLocked)
382 client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
383 else
384 client->fe_status = 0;
385 sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK);
386 }
387 }
388
389 return 0;
390}
391
392static void smsdvb_unregister_client(struct smsdvb_client_t *client)
393{
394 /* must be called under clientslock */
395
396 list_del(&client->entry);
397
398 smscore_unregister_client(client->smsclient);
399 dvb_unregister_frontend(&client->frontend);
400 dvb_dmxdev_release(&client->dmxdev);
401 dvb_dmx_release(&client->demux);
402 dvb_unregister_adapter(&client->adapter);
403 kfree(client);
404}
405
406static void smsdvb_onremove(void *context)
407{
408 kmutex_lock(&g_smsdvb_clientslock);
409
410 smsdvb_unregister_client((struct smsdvb_client_t *) context);
411
412 kmutex_unlock(&g_smsdvb_clientslock);
413}
414
415static int smsdvb_start_feed(struct dvb_demux_feed *feed)
416{
417 struct smsdvb_client_t *client =
418 container_of(feed->demux, struct smsdvb_client_t, demux);
419 struct SmsMsgData_ST PidMsg;
420
421 sms_debug("add pid %d(%x)",
422 feed->pid, feed->pid);
423
424 PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
425 PidMsg.xMsgHeader.msgDstId = HIF_TASK;
426 PidMsg.xMsgHeader.msgFlags = 0;
427 PidMsg.xMsgHeader.msgType = MSG_SMS_ADD_PID_FILTER_REQ;
428 PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
429 PidMsg.msgData[0] = feed->pid;
430
431 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
432 return smsclient_sendrequest(client->smsclient,
433 &PidMsg, sizeof(PidMsg));
434}
435
436static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
437{
438 struct smsdvb_client_t *client =
439 container_of(feed->demux, struct smsdvb_client_t, demux);
440 struct SmsMsgData_ST PidMsg;
441
442 sms_debug("remove pid %d(%x)",
443 feed->pid, feed->pid);
444
445 PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
446 PidMsg.xMsgHeader.msgDstId = HIF_TASK;
447 PidMsg.xMsgHeader.msgFlags = 0;
448 PidMsg.xMsgHeader.msgType = MSG_SMS_REMOVE_PID_FILTER_REQ;
449 PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
450 PidMsg.msgData[0] = feed->pid;
451
452 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
453 return smsclient_sendrequest(client->smsclient,
454 &PidMsg, sizeof(PidMsg));
455}
456
457static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
458 void *buffer, size_t size,
459 struct completion *completion)
460{
461 int rc;
462
463 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)buffer);
464 rc = smsclient_sendrequest(client->smsclient, buffer, size);
465 if (rc < 0)
466 return rc;
467
468 return wait_for_completion_timeout(completion,
469 msecs_to_jiffies(2000)) ?
470 0 : -ETIME;
471}
472
473static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
474{
475 int rc;
476 struct SmsMsgHdr_ST Msg = { MSG_SMS_GET_STATISTICS_REQ,
477 DVBT_BDA_CONTROL_MSG_ID,
478 HIF_TASK,
479 sizeof(struct SmsMsgHdr_ST), 0 };
480
481 rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
482 &client->tune_done);
483
484 return rc;
485}
486
487static inline int led_feedback(struct smsdvb_client_t *client)
488{
489 if (client->fe_status & FE_HAS_LOCK)
490 return sms_board_led_feedback(client->coredev,
491 (client->sms_stat_dvb.ReceptionData.BER
492 == 0) ? SMS_LED_HI : SMS_LED_LO);
493 else
494 return sms_board_led_feedback(client->coredev, SMS_LED_OFF);
495}
496
497static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat)
498{
499 int rc;
500 struct smsdvb_client_t *client;
501 client = container_of(fe, struct smsdvb_client_t, frontend);
502
503 rc = smsdvb_send_statistics_request(client);
504
505 *stat = client->fe_status;
506
507 led_feedback(client);
508
509 return rc;
510}
511
512static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
513{
514 int rc;
515 struct smsdvb_client_t *client;
516 client = container_of(fe, struct smsdvb_client_t, frontend);
517
518 rc = smsdvb_send_statistics_request(client);
519
520 *ber = client->sms_stat_dvb.ReceptionData.BER;
521
522 led_feedback(client);
523
524 return rc;
525}
526
527static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
528{
529 int rc;
530
531 struct smsdvb_client_t *client;
532 client = container_of(fe, struct smsdvb_client_t, frontend);
533
534 rc = smsdvb_send_statistics_request(client);
535
536 if (client->sms_stat_dvb.ReceptionData.InBandPwr < -95)
537 *strength = 0;
538 else if (client->sms_stat_dvb.ReceptionData.InBandPwr > -29)
539 *strength = 100;
540 else
541 *strength =
542 (client->sms_stat_dvb.ReceptionData.InBandPwr
543 + 95) * 3 / 2;
544
545 led_feedback(client);
546
547 return rc;
548}
549
550static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
551{
552 int rc;
553 struct smsdvb_client_t *client;
554 client = container_of(fe, struct smsdvb_client_t, frontend);
555
556 rc = smsdvb_send_statistics_request(client);
557
558 *snr = client->sms_stat_dvb.ReceptionData.SNR;
559
560 led_feedback(client);
561
562 return rc;
563}
564
565static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
566{
567 int rc;
568 struct smsdvb_client_t *client;
569 client = container_of(fe, struct smsdvb_client_t, frontend);
570
571 rc = smsdvb_send_statistics_request(client);
572
573 *ucblocks = client->sms_stat_dvb.ReceptionData.ErrorTSPackets;
574
575 led_feedback(client);
576
577 return rc;
578}
579
580static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
581 struct dvb_frontend_tune_settings *tune)
582{
583 sms_debug("");
584
585 tune->min_delay_ms = 400;
586 tune->step_size = 250000;
587 tune->max_drift = 0;
588 return 0;
589}
590
591static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
592{
593 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
594 struct smsdvb_client_t *client =
595 container_of(fe, struct smsdvb_client_t, frontend);
596
597 struct {
598 struct SmsMsgHdr_ST Msg;
599 u32 Data[3];
600 } Msg;
601
602 int ret;
603
604 client->fe_status = FE_HAS_SIGNAL;
605 client->event_fe_state = -1;
606 client->event_unc_state = -1;
607 fe->dtv_property_cache.delivery_system = SYS_DVBT;
608
609 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
610 Msg.Msg.msgDstId = HIF_TASK;
611 Msg.Msg.msgFlags = 0;
612 Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ;
613 Msg.Msg.msgLength = sizeof(Msg);
614 Msg.Data[0] = c->frequency;
615 Msg.Data[2] = 12000000;
616
617 sms_info("%s: freq %d band %d", __func__, c->frequency,
618 c->bandwidth_hz);
619
620 switch (c->bandwidth_hz / 1000000) {
621 case 8:
622 Msg.Data[1] = BW_8_MHZ;
623 break;
624 case 7:
625 Msg.Data[1] = BW_7_MHZ;
626 break;
627 case 6:
628 Msg.Data[1] = BW_6_MHZ;
629 break;
630 case 0:
631 return -EOPNOTSUPP;
632 default:
633 return -EINVAL;
634 }
635 /* Disable LNA, if any. An error is returned if no LNA is present */
636 ret = sms_board_lna_control(client->coredev, 0);
637 if (ret == 0) {
638 fe_status_t status;
639
640 /* tune with LNA off at first */
641 ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
642 &client->tune_done);
643
644 smsdvb_read_status(fe, &status);
645
646 if (status & FE_HAS_LOCK)
647 return ret;
648
649 /* previous tune didn't lock - enable LNA and tune again */
650 sms_board_lna_control(client->coredev, 1);
651 }
652
653 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
654 &client->tune_done);
655}
656
657static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
658{
659 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
660 struct smsdvb_client_t *client =
661 container_of(fe, struct smsdvb_client_t, frontend);
662
663 struct {
664 struct SmsMsgHdr_ST Msg;
665 u32 Data[4];
666 } Msg;
667
668 fe->dtv_property_cache.delivery_system = SYS_ISDBT;
669
670 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
671 Msg.Msg.msgDstId = HIF_TASK;
672 Msg.Msg.msgFlags = 0;
673 Msg.Msg.msgType = MSG_SMS_ISDBT_TUNE_REQ;
674 Msg.Msg.msgLength = sizeof(Msg);
675
676 if (c->isdbt_sb_segment_idx == -1)
677 c->isdbt_sb_segment_idx = 0;
678
679 switch (c->isdbt_sb_segment_count) {
680 case 3:
681 Msg.Data[1] = BW_ISDBT_3SEG;
682 break;
683 case 1:
684 Msg.Data[1] = BW_ISDBT_1SEG;
685 break;
686 case 0: /* AUTO */
687 switch (c->bandwidth_hz / 1000000) {
688 case 8:
689 case 7:
690 c->isdbt_sb_segment_count = 3;
691 Msg.Data[1] = BW_ISDBT_3SEG;
692 break;
693 case 6:
694 c->isdbt_sb_segment_count = 1;
695 Msg.Data[1] = BW_ISDBT_1SEG;
696 break;
697 default: /* Assumes 6 MHZ bw */
698 c->isdbt_sb_segment_count = 1;
699 c->bandwidth_hz = 6000;
700 Msg.Data[1] = BW_ISDBT_1SEG;
701 break;
702 }
703 break;
704 default:
705 sms_info("Segment count %d not supported", c->isdbt_sb_segment_count);
706 return -EINVAL;
707 }
708
709 Msg.Data[0] = c->frequency;
710 Msg.Data[2] = 12000000;
711 Msg.Data[3] = c->isdbt_sb_segment_idx;
712
713 sms_info("%s: freq %d segwidth %d segindex %d\n", __func__,
714 c->frequency, c->isdbt_sb_segment_count,
715 c->isdbt_sb_segment_idx);
716
717 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
718 &client->tune_done);
719}
720
721static int smsdvb_set_frontend(struct dvb_frontend *fe)
722{
723 struct smsdvb_client_t *client =
724 container_of(fe, struct smsdvb_client_t, frontend);
725 struct smscore_device_t *coredev = client->coredev;
726
727 switch (smscore_get_device_mode(coredev)) {
728 case DEVICE_MODE_DVBT:
729 case DEVICE_MODE_DVBT_BDA:
730 return smsdvb_dvbt_set_frontend(fe);
731 case DEVICE_MODE_ISDBT:
732 case DEVICE_MODE_ISDBT_BDA:
733 return smsdvb_isdbt_set_frontend(fe);
734 default:
735 return -EINVAL;
736 }
737}
738
739static int smsdvb_get_frontend(struct dvb_frontend *fe)
740{
741 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
742 struct smsdvb_client_t *client =
743 container_of(fe, struct smsdvb_client_t, frontend);
744 struct smscore_device_t *coredev = client->coredev;
745 struct TRANSMISSION_STATISTICS_S *td =
746 &client->sms_stat_dvb.TransmissionData;
747
748 switch (smscore_get_device_mode(coredev)) {
749 case DEVICE_MODE_DVBT:
750 case DEVICE_MODE_DVBT_BDA:
751 fep->frequency = td->Frequency;
752
753 switch (td->Bandwidth) {
754 case 6:
755 fep->bandwidth_hz = 6000000;
756 break;
757 case 7:
758 fep->bandwidth_hz = 7000000;
759 break;
760 case 8:
761 fep->bandwidth_hz = 8000000;
762 break;
763 }
764
765 switch (td->TransmissionMode) {
766 case 2:
767 fep->transmission_mode = TRANSMISSION_MODE_2K;
768 break;
769 case 8:
770 fep->transmission_mode = TRANSMISSION_MODE_8K;
771 }
772
773 switch (td->GuardInterval) {
774 case 0:
775 fep->guard_interval = GUARD_INTERVAL_1_32;
776 break;
777 case 1:
778 fep->guard_interval = GUARD_INTERVAL_1_16;
779 break;
780 case 2:
781 fep->guard_interval = GUARD_INTERVAL_1_8;
782 break;
783 case 3:
784 fep->guard_interval = GUARD_INTERVAL_1_4;
785 break;
786 }
787
788 switch (td->CodeRate) {
789 case 0:
790 fep->code_rate_HP = FEC_1_2;
791 break;
792 case 1:
793 fep->code_rate_HP = FEC_2_3;
794 break;
795 case 2:
796 fep->code_rate_HP = FEC_3_4;
797 break;
798 case 3:
799 fep->code_rate_HP = FEC_5_6;
800 break;
801 case 4:
802 fep->code_rate_HP = FEC_7_8;
803 break;
804 }
805
806 switch (td->LPCodeRate) {
807 case 0:
808 fep->code_rate_LP = FEC_1_2;
809 break;
810 case 1:
811 fep->code_rate_LP = FEC_2_3;
812 break;
813 case 2:
814 fep->code_rate_LP = FEC_3_4;
815 break;
816 case 3:
817 fep->code_rate_LP = FEC_5_6;
818 break;
819 case 4:
820 fep->code_rate_LP = FEC_7_8;
821 break;
822 }
823
824 switch (td->Constellation) {
825 case 0:
826 fep->modulation = QPSK;
827 break;
828 case 1:
829 fep->modulation = QAM_16;
830 break;
831 case 2:
832 fep->modulation = QAM_64;
833 break;
834 }
835
836 switch (td->Hierarchy) {
837 case 0:
838 fep->hierarchy = HIERARCHY_NONE;
839 break;
840 case 1:
841 fep->hierarchy = HIERARCHY_1;
842 break;
843 case 2:
844 fep->hierarchy = HIERARCHY_2;
845 break;
846 case 3:
847 fep->hierarchy = HIERARCHY_4;
848 break;
849 }
850
851 fep->inversion = INVERSION_AUTO;
852 break;
853 case DEVICE_MODE_ISDBT:
854 case DEVICE_MODE_ISDBT_BDA:
855 fep->frequency = td->Frequency;
856 fep->bandwidth_hz = 6000000;
857 /* todo: retrive the other parameters */
858 break;
859 default:
860 return -EINVAL;
861 }
862
863 return 0;
864}
865
866static int smsdvb_init(struct dvb_frontend *fe)
867{
868 struct smsdvb_client_t *client =
869 container_of(fe, struct smsdvb_client_t, frontend);
870
871 sms_board_power(client->coredev, 1);
872
873 sms_board_dvb3_event(client, DVB3_EVENT_INIT);
874 return 0;
875}
876
877static int smsdvb_sleep(struct dvb_frontend *fe)
878{
879 struct smsdvb_client_t *client =
880 container_of(fe, struct smsdvb_client_t, frontend);
881
882 sms_board_led_feedback(client->coredev, SMS_LED_OFF);
883 sms_board_power(client->coredev, 0);
884
885 sms_board_dvb3_event(client, DVB3_EVENT_SLEEP);
886
887 return 0;
888}
889
890static void smsdvb_release(struct dvb_frontend *fe)
891{
892 /* do nothing */
893}
894
895static struct dvb_frontend_ops smsdvb_fe_ops = {
896 .info = {
897 .name = "Siano Mobile Digital MDTV Receiver",
898 .frequency_min = 44250000,
899 .frequency_max = 867250000,
900 .frequency_stepsize = 250000,
901 .caps = FE_CAN_INVERSION_AUTO |
902 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
903 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
904 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
905 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
906 FE_CAN_GUARD_INTERVAL_AUTO |
907 FE_CAN_RECOVER |
908 FE_CAN_HIERARCHY_AUTO,
909 },
910
911 .release = smsdvb_release,
912
913 .set_frontend = smsdvb_set_frontend,
914 .get_frontend = smsdvb_get_frontend,
915 .get_tune_settings = smsdvb_get_tune_settings,
916
917 .read_status = smsdvb_read_status,
918 .read_ber = smsdvb_read_ber,
919 .read_signal_strength = smsdvb_read_signal_strength,
920 .read_snr = smsdvb_read_snr,
921 .read_ucblocks = smsdvb_read_ucblocks,
922
923 .init = smsdvb_init,
924 .sleep = smsdvb_sleep,
925};
926
927static int smsdvb_hotplug(struct smscore_device_t *coredev,
928 struct device *device, int arrival)
929{
930 struct smsclient_params_t params;
931 struct smsdvb_client_t *client;
932 int rc;
933
934 /* device removal handled by onremove callback */
935 if (!arrival)
936 return 0;
937 client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
938 if (!client) {
939 sms_err("kmalloc() failed");
940 return -ENOMEM;
941 }
942
943 /* register dvb adapter */
944 rc = dvb_register_adapter(&client->adapter,
945 sms_get_board(
946 smscore_get_board_id(coredev))->name,
947 THIS_MODULE, device, adapter_nr);
948 if (rc < 0) {
949 sms_err("dvb_register_adapter() failed %d", rc);
950 goto adapter_error;
951 }
952
953 /* init dvb demux */
954 client->demux.dmx.capabilities = DMX_TS_FILTERING;
955 client->demux.filternum = 32; /* todo: nova ??? */
956 client->demux.feednum = 32;
957 client->demux.start_feed = smsdvb_start_feed;
958 client->demux.stop_feed = smsdvb_stop_feed;
959
960 rc = dvb_dmx_init(&client->demux);
961 if (rc < 0) {
962 sms_err("dvb_dmx_init failed %d", rc);
963 goto dvbdmx_error;
964 }
965
966 /* init dmxdev */
967 client->dmxdev.filternum = 32;
968 client->dmxdev.demux = &client->demux.dmx;
969 client->dmxdev.capabilities = 0;
970
971 rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
972 if (rc < 0) {
973 sms_err("dvb_dmxdev_init failed %d", rc);
974 goto dmxdev_error;
975 }
976
977 /* init and register frontend */
978 memcpy(&client->frontend.ops, &smsdvb_fe_ops,
979 sizeof(struct dvb_frontend_ops));
980
981 switch (smscore_get_device_mode(coredev)) {
982 case DEVICE_MODE_DVBT:
983 case DEVICE_MODE_DVBT_BDA:
984 client->frontend.ops.delsys[0] = SYS_DVBT;
985 break;
986 case DEVICE_MODE_ISDBT:
987 case DEVICE_MODE_ISDBT_BDA:
988 client->frontend.ops.delsys[0] = SYS_ISDBT;
989 break;
990 }
991
992 rc = dvb_register_frontend(&client->adapter, &client->frontend);
993 if (rc < 0) {
994 sms_err("frontend registration failed %d", rc);
995 goto frontend_error;
996 }
997
998 params.initial_id = 1;
999 params.data_type = MSG_SMS_DVBT_BDA_DATA;
1000 params.onresponse_handler = smsdvb_onresponse;
1001 params.onremove_handler = smsdvb_onremove;
1002 params.context = client;
1003
1004 rc = smscore_register_client(coredev, &params, &client->smsclient);
1005 if (rc < 0) {
1006 sms_err("smscore_register_client() failed %d", rc);
1007 goto client_error;
1008 }
1009
1010 client->coredev = coredev;
1011
1012 init_completion(&client->tune_done);
1013
1014 kmutex_lock(&g_smsdvb_clientslock);
1015
1016 list_add(&client->entry, &g_smsdvb_clients);
1017
1018 kmutex_unlock(&g_smsdvb_clientslock);
1019
1020 client->event_fe_state = -1;
1021 client->event_unc_state = -1;
1022 sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG);
1023
1024 sms_info("success");
1025 sms_board_setup(coredev);
1026
1027 return 0;
1028
1029client_error:
1030 dvb_unregister_frontend(&client->frontend);
1031
1032frontend_error:
1033 dvb_dmxdev_release(&client->dmxdev);
1034
1035dmxdev_error:
1036 dvb_dmx_release(&client->demux);
1037
1038dvbdmx_error:
1039 dvb_unregister_adapter(&client->adapter);
1040
1041adapter_error:
1042 kfree(client);
1043 return rc;
1044}
1045
1046static int __init smsdvb_module_init(void)
1047{
1048 int rc;
1049
1050 INIT_LIST_HEAD(&g_smsdvb_clients);
1051 kmutex_init(&g_smsdvb_clientslock);
1052
1053 rc = smscore_register_hotplug(smsdvb_hotplug);
1054
1055 sms_debug("");
1056
1057 return rc;
1058}
1059
1060static void __exit smsdvb_module_exit(void)
1061{
1062 smscore_unregister_hotplug(smsdvb_hotplug);
1063
1064 kmutex_lock(&g_smsdvb_clientslock);
1065
1066 while (!list_empty(&g_smsdvb_clients))
1067 smsdvb_unregister_client(
1068 (struct smsdvb_client_t *) g_smsdvb_clients.next);
1069
1070 kmutex_unlock(&g_smsdvb_clientslock);
1071}
1072
1073module_init(smsdvb_module_init);
1074module_exit(smsdvb_module_exit);
1075
1076MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
1077MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
1078MODULE_LICENSE("GPL");
diff --git a/drivers/media/common/siano/smsdvb.h b/drivers/media/common/siano/smsdvb.h
new file mode 100644
index 000000000000..92c413ba0c79
--- /dev/null
+++ b/drivers/media/common/siano/smsdvb.h
@@ -0,0 +1,130 @@
1/***********************************************************************
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
15 *
16 ***********************************************************************/
17
18struct smsdvb_debugfs;
19struct smsdvb_client_t;
20
21typedef void (*sms_prt_dvb_stats_t)(struct smsdvb_debugfs *debug_data,
22 struct sms_stats *p);
23
24typedef void (*sms_prt_isdb_stats_t)(struct smsdvb_debugfs *debug_data,
25 struct sms_isdbt_stats *p);
26
27typedef void (*sms_prt_isdb_stats_ex_t)
28 (struct smsdvb_debugfs *debug_data,
29 struct sms_isdbt_stats_ex *p);
30
31
32struct smsdvb_client_t {
33 struct list_head entry;
34
35 struct smscore_device_t *coredev;
36 struct smscore_client_t *smsclient;
37
38 struct dvb_adapter adapter;
39 struct dvb_demux demux;
40 struct dmxdev dmxdev;
41 struct dvb_frontend frontend;
42
43 fe_status_t fe_status;
44
45 struct completion tune_done;
46 struct completion stats_done;
47
48 int last_per;
49
50 int legacy_ber, legacy_per;
51
52 int event_fe_state;
53 int event_unc_state;
54
55 unsigned long get_stats_jiffies;
56
57 int feed_users;
58 bool has_tuned;
59
60 /* stats debugfs data */
61 struct dentry *debugfs;
62
63 struct smsdvb_debugfs *debug_data;
64
65 sms_prt_dvb_stats_t prt_dvb_stats;
66 sms_prt_isdb_stats_t prt_isdb_stats;
67 sms_prt_isdb_stats_ex_t prt_isdb_stats_ex;
68};
69
70/*
71 * This struct is a mix of struct sms_rx_stats_ex and
72 * struct sms_srvm_signal_status.
73 * It was obtained by comparing the way it was filled by the original code
74 */
75struct RECEPTION_STATISTICS_PER_SLICES_S {
76 u32 result;
77 u32 snr;
78 s32 in_band_power;
79 u32 ts_packets;
80 u32 ets_packets;
81 u32 constellation;
82 u32 hp_code;
83 u32 tps_srv_ind_lp;
84 u32 tps_srv_ind_hp;
85 u32 cell_id;
86 u32 reason;
87 u32 request_id;
88 u32 modem_state; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */
89
90 u32 ber; /* Post Viterbi BER [1E-5] */
91 s32 RSSI; /* dBm */
92 s32 carrier_offset; /* Carrier Offset in bin/1024 */
93
94 u32 is_rf_locked; /* 0 - not locked, 1 - locked */
95 u32 is_demod_locked; /* 0 - not locked, 1 - locked */
96
97 u32 ber_bit_count; /* Total number of SYNC bits. */
98 u32 ber_error_count; /* Number of erronous SYNC bits. */
99
100 s32 MRC_SNR; /* dB */
101 s32 mrc_in_band_pwr; /* In band power in dBM */
102 s32 MRC_RSSI; /* dBm */
103};
104
105/* From smsdvb-debugfs.c */
106#ifdef CONFIG_SMS_SIANO_DEBUGFS
107
108int smsdvb_debugfs_create(struct smsdvb_client_t *client);
109void smsdvb_debugfs_release(struct smsdvb_client_t *client);
110int smsdvb_debugfs_register(void);
111void smsdvb_debugfs_unregister(void);
112
113#else
114
115static inline int smsdvb_debugfs_create(struct smsdvb_client_t *client)
116{
117 return 0;
118}
119
120static inline void smsdvb_debugfs_release(struct smsdvb_client_t *client) {}
121
122static inline int smsdvb_debugfs_register(void)
123{
124 return 0;
125};
126
127static inline void smsdvb_debugfs_unregister(void) {};
128
129#endif
130
diff --git a/drivers/media/common/siano/smsendian.c b/drivers/media/common/siano/smsendian.c
index e2657c2f0109..bfe831c10b1c 100644
--- a/drivers/media/common/siano/smsendian.c
+++ b/drivers/media/common/siano/smsendian.c
@@ -28,23 +28,23 @@
28void smsendian_handle_tx_message(void *buffer) 28void smsendian_handle_tx_message(void *buffer)
29{ 29{
30#ifdef __BIG_ENDIAN 30#ifdef __BIG_ENDIAN
31 struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *)buffer; 31 struct sms_msg_data *msg = (struct sms_msg_data *)buffer;
32 int i; 32 int i;
33 int msgWords; 33 int msg_words;
34 34
35 switch (msg->xMsgHeader.msgType) { 35 switch (msg->x_msg_header.msg_type) {
36 case MSG_SMS_DATA_DOWNLOAD_REQ: 36 case MSG_SMS_DATA_DOWNLOAD_REQ:
37 { 37 {
38 msg->msgData[0] = le32_to_cpu(msg->msgData[0]); 38 msg->msg_data[0] = le32_to_cpu(msg->msg_data[0]);
39 break; 39 break;
40 } 40 }
41 41
42 default: 42 default:
43 msgWords = (msg->xMsgHeader.msgLength - 43 msg_words = (msg->x_msg_header.msg_length -
44 sizeof(struct SmsMsgHdr_ST))/4; 44 sizeof(struct sms_msg_hdr))/4;
45 45
46 for (i = 0; i < msgWords; i++) 46 for (i = 0; i < msg_words; i++)
47 msg->msgData[i] = le32_to_cpu(msg->msgData[i]); 47 msg->msg_data[i] = le32_to_cpu(msg->msg_data[i]);
48 48
49 break; 49 break;
50 } 50 }
@@ -55,16 +55,16 @@ EXPORT_SYMBOL_GPL(smsendian_handle_tx_message);
55void smsendian_handle_rx_message(void *buffer) 55void smsendian_handle_rx_message(void *buffer)
56{ 56{
57#ifdef __BIG_ENDIAN 57#ifdef __BIG_ENDIAN
58 struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *)buffer; 58 struct sms_msg_data *msg = (struct sms_msg_data *)buffer;
59 int i; 59 int i;
60 int msgWords; 60 int msg_words;
61 61
62 switch (msg->xMsgHeader.msgType) { 62 switch (msg->x_msg_header.msg_type) {
63 case MSG_SMS_GET_VERSION_EX_RES: 63 case MSG_SMS_GET_VERSION_EX_RES:
64 { 64 {
65 struct SmsVersionRes_ST *ver = 65 struct sms_version_res *ver =
66 (struct SmsVersionRes_ST *) msg; 66 (struct sms_version_res *) msg;
67 ver->ChipModel = le16_to_cpu(ver->ChipModel); 67 ver->chip_model = le16_to_cpu(ver->chip_model);
68 break; 68 break;
69 } 69 }
70 70
@@ -77,11 +77,11 @@ void smsendian_handle_rx_message(void *buffer)
77 77
78 default: 78 default:
79 { 79 {
80 msgWords = (msg->xMsgHeader.msgLength - 80 msg_words = (msg->x_msg_header.msg_length -
81 sizeof(struct SmsMsgHdr_ST))/4; 81 sizeof(struct sms_msg_hdr))/4;
82 82
83 for (i = 0; i < msgWords; i++) 83 for (i = 0; i < msg_words; i++)
84 msg->msgData[i] = le32_to_cpu(msg->msgData[i]); 84 msg->msg_data[i] = le32_to_cpu(msg->msg_data[i]);
85 85
86 break; 86 break;
87 } 87 }
@@ -93,11 +93,11 @@ EXPORT_SYMBOL_GPL(smsendian_handle_rx_message);
93void smsendian_handle_message_header(void *msg) 93void smsendian_handle_message_header(void *msg)
94{ 94{
95#ifdef __BIG_ENDIAN 95#ifdef __BIG_ENDIAN
96 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)msg; 96 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *)msg;
97 97
98 phdr->msgType = le16_to_cpu(phdr->msgType); 98 phdr->msg_type = le16_to_cpu(phdr->msg_type);
99 phdr->msgLength = le16_to_cpu(phdr->msgLength); 99 phdr->msg_length = le16_to_cpu(phdr->msg_length);
100 phdr->msgFlags = le16_to_cpu(phdr->msgFlags); 100 phdr->msg_flags = le16_to_cpu(phdr->msg_flags);
101#endif /* __BIG_ENDIAN */ 101#endif /* __BIG_ENDIAN */
102} 102}
103EXPORT_SYMBOL_GPL(smsendian_handle_message_header); 103EXPORT_SYMBOL_GPL(smsendian_handle_message_header);
diff --git a/drivers/media/common/siano/smsir.h b/drivers/media/common/siano/smsir.h
index 69b59b9eee28..fc8b7925c532 100644
--- a/drivers/media/common/siano/smsir.h
+++ b/drivers/media/common/siano/smsir.h
@@ -40,7 +40,6 @@ struct ir_t {
40 char phys[32]; 40 char phys[32];
41 41
42 char *rc_codes; 42 char *rc_codes;
43 u64 protocol;
44 43
45 u32 timeout; 44 u32 timeout;
46 u32 controller; 45 u32 controller;
diff --git a/drivers/media/dvb-core/demux.h b/drivers/media/dvb-core/demux.h
index eb91fd808c16..833191bcd810 100644
--- a/drivers/media/dvb-core/demux.h
+++ b/drivers/media/dvb-core/demux.h
@@ -83,45 +83,6 @@ enum dmx_success {
83#define TS_DEMUX 8 /* in case TS_PACKET is set, send the TS to 83#define TS_DEMUX 8 /* in case TS_PACKET is set, send the TS to
84 the demux device, not to the dvr device */ 84 the demux device, not to the dvr device */
85 85
86/* PES type for filters which write to built-in decoder */
87/* these should be kept identical to the types in dmx.h */
88
89enum dmx_ts_pes
90{ /* also send packets to decoder (if it exists) */
91 DMX_TS_PES_AUDIO0,
92 DMX_TS_PES_VIDEO0,
93 DMX_TS_PES_TELETEXT0,
94 DMX_TS_PES_SUBTITLE0,
95 DMX_TS_PES_PCR0,
96
97 DMX_TS_PES_AUDIO1,
98 DMX_TS_PES_VIDEO1,
99 DMX_TS_PES_TELETEXT1,
100 DMX_TS_PES_SUBTITLE1,
101 DMX_TS_PES_PCR1,
102
103 DMX_TS_PES_AUDIO2,
104 DMX_TS_PES_VIDEO2,
105 DMX_TS_PES_TELETEXT2,
106 DMX_TS_PES_SUBTITLE2,
107 DMX_TS_PES_PCR2,
108
109 DMX_TS_PES_AUDIO3,
110 DMX_TS_PES_VIDEO3,
111 DMX_TS_PES_TELETEXT3,
112 DMX_TS_PES_SUBTITLE3,
113 DMX_TS_PES_PCR3,
114
115 DMX_TS_PES_OTHER
116};
117
118#define DMX_TS_PES_AUDIO DMX_TS_PES_AUDIO0
119#define DMX_TS_PES_VIDEO DMX_TS_PES_VIDEO0
120#define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
121#define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
122#define DMX_TS_PES_PCR DMX_TS_PES_PCR0
123
124
125struct dmx_ts_feed { 86struct dmx_ts_feed {
126 int is_filtering; /* Set to non-zero when filtering in progress */ 87 int is_filtering; /* Set to non-zero when filtering in progress */
127 struct dmx_demux *parent; /* Back-pointer */ 88 struct dmx_demux *parent; /* Back-pointer */
diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index d81dbb22aa81..a1a3a5159d71 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -569,7 +569,7 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev,
569 dmx_output_t otype; 569 dmx_output_t otype;
570 int ret; 570 int ret;
571 int ts_type; 571 int ts_type;
572 dmx_pes_type_t ts_pes; 572 enum dmx_ts_pes ts_pes;
573 struct dmx_ts_feed *tsfeed; 573 struct dmx_ts_feed *tsfeed;
574 574
575 feed->ts = NULL; 575 feed->ts = NULL;
@@ -852,7 +852,8 @@ static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev,
852 struct dmxdev_filter *dmxdevfilter, 852 struct dmxdev_filter *dmxdevfilter,
853 struct dmx_sct_filter_params *params) 853 struct dmx_sct_filter_params *params)
854{ 854{
855 dprintk("function : %s\n", __func__); 855 dprintk("function : %s, PID=0x%04x, flags=%02x, timeout=%d\n",
856 __func__, params->pid, params->flags, params->timeout);
856 857
857 dvb_dmxdev_filter_stop(dmxdevfilter); 858 dvb_dmxdev_filter_stop(dmxdevfilter);
858 859
diff --git a/drivers/media/dvb-core/dvb-usb-ids.h b/drivers/media/dvb-core/dvb-usb-ids.h
index 399e1042d351..335a8f4695b4 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -124,8 +124,7 @@
124#define USB_PID_DIBCOM_STK7770P 0x1e80 124#define USB_PID_DIBCOM_STK7770P 0x1e80
125#define USB_PID_DIBCOM_NIM7090 0x1bb2 125#define USB_PID_DIBCOM_NIM7090 0x1bb2
126#define USB_PID_DIBCOM_TFE7090PVR 0x1bb4 126#define USB_PID_DIBCOM_TFE7090PVR 0x1bb4
127#define USB_PID_DIBCOM_TFE7090E 0x1bb7 127#define USB_PID_DIBCOM_TFE7790P 0x1e6e
128#define USB_PID_DIBCOM_TFE7790E 0x1e6e
129#define USB_PID_DIBCOM_NIM9090M 0x2383 128#define USB_PID_DIBCOM_NIM9090M 0x2383
130#define USB_PID_DIBCOM_NIM9090MD 0x2384 129#define USB_PID_DIBCOM_NIM9090MD 0x2384
131#define USB_PID_DPOSH_M9206_COLD 0x9206 130#define USB_PID_DPOSH_M9206_COLD 0x9206
diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c
index d319717eb535..3485655fa082 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -440,20 +440,22 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
440 if (!dvb_demux_feed_err_pkts) 440 if (!dvb_demux_feed_err_pkts)
441 return; 441 return;
442 } else /* if TEI bit is set, pid may be wrong- skip pkt counter */ 442 } else /* if TEI bit is set, pid may be wrong- skip pkt counter */
443 if (demux->cnt_storage && dvb_demux_tscheck) { 443 if (demux->cnt_storage && dvb_demux_tscheck) {
444 /* check pkt counter */ 444 /* check pkt counter */
445 if (pid < MAX_PID) { 445 if (pid < MAX_PID) {
446 if ((buf[3] & 0xf) != demux->cnt_storage[pid]) 446 if (buf[3] & 0x10)
447 dprintk_tscheck("TS packet counter mismatch. " 447 demux->cnt_storage[pid] =
448 "PID=0x%x expected 0x%x " 448 (demux->cnt_storage[pid] + 1) & 0xf;
449 "got 0x%x\n", 449
450 if ((buf[3] & 0xf) != demux->cnt_storage[pid]) {
451 dprintk_tscheck("TS packet counter mismatch. PID=0x%x expected 0x%x got 0x%x\n",
450 pid, demux->cnt_storage[pid], 452 pid, demux->cnt_storage[pid],
451 buf[3] & 0xf); 453 buf[3] & 0xf);
452 454 demux->cnt_storage[pid] = buf[3] & 0xf;
453 demux->cnt_storage[pid] = ((buf[3] & 0xf) + 1)&0xf; 455 }
456 }
457 /* end check */
454 } 458 }
455 /* end check */
456 }
457 459
458 list_for_each_entry(feed, &demux->feed_list, list_head) { 460 list_for_each_entry(feed, &demux->feed_list, list_head) {
459 if ((feed->pid != pid) && (feed->pid != 0x2000)) 461 if ((feed->pid != pid) && (feed->pid != 0x2000))
@@ -672,7 +674,7 @@ static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
672 return -ERESTARTSYS; 674 return -ERESTARTSYS;
673 675
674 if (ts_type & TS_DECODER) { 676 if (ts_type & TS_DECODER) {
675 if (pes_type >= DMX_TS_PES_OTHER) { 677 if (pes_type >= DMX_PES_OTHER) {
676 mutex_unlock(&demux->mutex); 678 mutex_unlock(&demux->mutex);
677 return -EINVAL; 679 return -EINVAL;
678 } 680 }
@@ -844,7 +846,7 @@ static int dvbdmx_release_ts_feed(struct dmx_demux *dmx,
844 846
845 feed->pid = 0xffff; 847 feed->pid = 0xffff;
846 848
847 if (feed->ts_type & TS_DECODER && feed->pes_type < DMX_TS_PES_OTHER) 849 if (feed->ts_type & TS_DECODER && feed->pes_type < DMX_PES_OTHER)
848 demux->pesfilter[feed->pes_type] = NULL; 850 demux->pesfilter[feed->pes_type] = NULL;
849 851
850 mutex_unlock(&demux->mutex); 852 mutex_unlock(&demux->mutex);
@@ -1266,7 +1268,7 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1266 1268
1267 INIT_LIST_HEAD(&dvbdemux->frontend_list); 1269 INIT_LIST_HEAD(&dvbdemux->frontend_list);
1268 1270
1269 for (i = 0; i < DMX_TS_PES_OTHER; i++) { 1271 for (i = 0; i < DMX_PES_OTHER; i++) {
1270 dvbdemux->pesfilter[i] = NULL; 1272 dvbdemux->pesfilter[i] = NULL;
1271 dvbdemux->pids[i] = 0xffff; 1273 dvbdemux->pids[i] = 0xffff;
1272 } 1274 }
diff --git a/drivers/media/dvb-core/dvb_demux.h b/drivers/media/dvb-core/dvb_demux.h
index fa7188a253aa..ae7fc33c3231 100644
--- a/drivers/media/dvb-core/dvb_demux.h
+++ b/drivers/media/dvb-core/dvb_demux.h
@@ -119,8 +119,8 @@ struct dvb_demux {
119 119
120 struct list_head frontend_list; 120 struct list_head frontend_list;
121 121
122 struct dvb_demux_feed *pesfilter[DMX_TS_PES_OTHER]; 122 struct dvb_demux_feed *pesfilter[DMX_PES_OTHER];
123 u16 pids[DMX_TS_PES_OTHER]; 123 u16 pids[DMX_PES_OTHER];
124 int playing; 124 int playing;
125 int recording; 125 int recording;
126 126
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 6e50a7581568..57601c0704c1 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -920,7 +920,7 @@ static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
920 u32 delsys; 920 u32 delsys;
921 921
922 delsys = c->delivery_system; 922 delsys = c->delivery_system;
923 memset(c, 0, sizeof(struct dtv_frontend_properties)); 923 memset(c, 0, offsetof(struct dtv_frontend_properties, strength));
924 c->delivery_system = delsys; 924 c->delivery_system = delsys;
925 925
926 c->state = DTV_CLEAR; 926 c->state = DTV_CLEAR;
@@ -1509,9 +1509,74 @@ static bool is_dvbv3_delsys(u32 delsys)
1509 return status; 1509 return status;
1510} 1510}
1511 1511
1512static int set_delivery_system(struct dvb_frontend *fe, u32 desired_system) 1512/**
1513 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1514 * @fe: struct frontend;
1515 * @delsys: DVBv5 type that will be used for emulation
1516 *
1517 * Provides emulation for delivery systems that are compatible with the old
1518 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1519 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontent
1520 * parameters are compatible with DVB-S spec.
1521 */
1522static int emulate_delivery_system(struct dvb_frontend *fe, u32 delsys)
1513{ 1523{
1514 int ncaps, i; 1524 int i;
1525 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1526
1527 c->delivery_system = delsys;
1528
1529 /*
1530 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1531 */
1532 if (c->delivery_system == SYS_ISDBT) {
1533 dev_dbg(fe->dvb->device,
1534 "%s: Using defaults for SYS_ISDBT\n",
1535 __func__);
1536
1537 if (!c->bandwidth_hz)
1538 c->bandwidth_hz = 6000000;
1539
1540 c->isdbt_partial_reception = 0;
1541 c->isdbt_sb_mode = 0;
1542 c->isdbt_sb_subchannel = 0;
1543 c->isdbt_sb_segment_idx = 0;
1544 c->isdbt_sb_segment_count = 0;
1545 c->isdbt_layer_enabled = 7;
1546 for (i = 0; i < 3; i++) {
1547 c->layer[i].fec = FEC_AUTO;
1548 c->layer[i].modulation = QAM_AUTO;
1549 c->layer[i].interleaving = 0;
1550 c->layer[i].segment_count = 0;
1551 }
1552 }
1553 dev_dbg(fe->dvb->device, "%s: change delivery system on cache to %d\n",
1554 __func__, c->delivery_system);
1555
1556 return 0;
1557}
1558
1559/**
1560 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1561 * @fe: frontend struct
1562 * @desired_system: delivery system requested by the user
1563 *
1564 * A DVBv5 call know what's the desired system it wants. So, set it.
1565 *
1566 * There are, however, a few known issues with early DVBv5 applications that
1567 * are also handled by this logic:
1568 *
1569 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1570 * This is an API violation, but, as we don't want to break userspace,
1571 * convert it to the first supported delivery system.
1572 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1573 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1574 * ISDB-T provided backward compat with DVB-T.
1575 */
1576static int dvbv5_set_delivery_system(struct dvb_frontend *fe,
1577 u32 desired_system)
1578{
1579 int ncaps;
1515 u32 delsys = SYS_UNDEFINED; 1580 u32 delsys = SYS_UNDEFINED;
1516 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1581 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1517 enum dvbv3_emulation_type type; 1582 enum dvbv3_emulation_type type;
@@ -1522,166 +1587,136 @@ static int set_delivery_system(struct dvb_frontend *fe, u32 desired_system)
1522 * assume that the application wants to use the first supported 1587 * assume that the application wants to use the first supported
1523 * delivery system. 1588 * delivery system.
1524 */ 1589 */
1525 if (c->delivery_system == SYS_UNDEFINED) 1590 if (desired_system == SYS_UNDEFINED)
1526 c->delivery_system = fe->ops.delsys[0]; 1591 desired_system = fe->ops.delsys[0];
1527 1592
1528 if (desired_system == SYS_UNDEFINED) { 1593 /*
1529 /* 1594 * This is a DVBv5 call. So, it likely knows the supported
1530 * A DVBv3 call doesn't know what's the desired system. 1595 * delivery systems. So, check if the desired delivery system is
1531 * Also, DVBv3 applications don't know that ops.info->type 1596 * supported
1532 * could be changed, and they simply dies when it doesn't 1597 */
1533 * match. 1598 ncaps = 0;
1534 * So, don't change the current delivery system, as it 1599 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) {
1535 * may be trying to do the wrong thing, like setting an 1600 if (fe->ops.delsys[ncaps] == desired_system) {
1536 * ISDB-T frontend as DVB-T. Instead, find the closest 1601 c->delivery_system = desired_system;
1537 * DVBv3 system that matches the delivery system.
1538 */
1539 if (is_dvbv3_delsys(c->delivery_system)) {
1540 dev_dbg(fe->dvb->device, 1602 dev_dbg(fe->dvb->device,
1541 "%s: Using delivery system to %d\n", 1603 "%s: Changing delivery system to %d\n",
1542 __func__, c->delivery_system);
1543 return 0;
1544 }
1545 type = dvbv3_type(c->delivery_system);
1546 switch (type) {
1547 case DVBV3_QPSK:
1548 desired_system = SYS_DVBS;
1549 break;
1550 case DVBV3_QAM:
1551 desired_system = SYS_DVBC_ANNEX_A;
1552 break;
1553 case DVBV3_ATSC:
1554 desired_system = SYS_ATSC;
1555 break;
1556 case DVBV3_OFDM:
1557 desired_system = SYS_DVBT;
1558 break;
1559 default:
1560 dev_dbg(fe->dvb->device, "%s: This frontend doesn't support DVBv3 calls\n",
1561 __func__);
1562 return -EINVAL;
1563 }
1564 /*
1565 * Get a delivery system that is compatible with DVBv3
1566 * NOTE: in order for this to work with softwares like Kaffeine that
1567 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1568 * DVB-S, drivers that support both should put the SYS_DVBS entry
1569 * before the SYS_DVBS2, otherwise it won't switch back to DVB-S.
1570 * The real fix is that userspace applications should not use DVBv3
1571 * and not trust on calling FE_SET_FRONTEND to switch the delivery
1572 * system.
1573 */
1574 ncaps = 0;
1575 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) {
1576 if (fe->ops.delsys[ncaps] == desired_system) {
1577 delsys = desired_system;
1578 break;
1579 }
1580 ncaps++;
1581 }
1582 if (delsys == SYS_UNDEFINED) {
1583 dev_dbg(fe->dvb->device, "%s: Couldn't find a delivery system that matches %d\n",
1584 __func__, desired_system); 1604 __func__, desired_system);
1605 return 0;
1585 } 1606 }
1586 } else { 1607 ncaps++;
1587 /* 1608 }
1588 * This is a DVBv5 call. So, it likely knows the supported
1589 * delivery systems.
1590 */
1591 1609
1592 /* Check if the desired delivery system is supported */ 1610 /*
1593 ncaps = 0; 1611 * The requested delivery system isn't supported. Maybe userspace
1594 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) { 1612 * is requesting a DVBv3 compatible delivery system.
1595 if (fe->ops.delsys[ncaps] == desired_system) { 1613 *
1596 c->delivery_system = desired_system; 1614 * The emulation only works if the desired system is one of the
1597 dev_dbg(fe->dvb->device, 1615 * delivery systems supported by DVBv3 API
1598 "%s: Changing delivery system to %d\n", 1616 */
1599 __func__, desired_system); 1617 if (!is_dvbv3_delsys(desired_system)) {
1600 return 0; 1618 dev_dbg(fe->dvb->device,
1601 } 1619 "%s: Delivery system %d not supported.\n",
1602 ncaps++; 1620 __func__, desired_system);
1603 } 1621 return -EINVAL;
1604 type = dvbv3_type(desired_system); 1622 }
1605 1623
1606 /* 1624 type = dvbv3_type(desired_system);
1607 * The delivery system is not supported. See if it can be
1608 * emulated.
1609 * The emulation only works if the desired system is one of the
1610 * DVBv3 delivery systems
1611 */
1612 if (!is_dvbv3_delsys(desired_system)) {
1613 dev_dbg(fe->dvb->device,
1614 "%s: can't use a DVBv3 FE_SET_FRONTEND call on this frontend\n",
1615 __func__);
1616 return -EINVAL;
1617 }
1618 1625
1619 /* 1626 /*
1620 * Get the last non-DVBv3 delivery system that has the same type 1627 * Get the last non-DVBv3 delivery system that has the same type
1621 * of the desired system 1628 * of the desired system
1622 */ 1629 */
1623 ncaps = 0; 1630 ncaps = 0;
1624 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) { 1631 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) {
1625 if ((dvbv3_type(fe->ops.delsys[ncaps]) == type) && 1632 if (dvbv3_type(fe->ops.delsys[ncaps]) == type)
1626 !is_dvbv3_delsys(fe->ops.delsys[ncaps])) 1633 delsys = fe->ops.delsys[ncaps];
1627 delsys = fe->ops.delsys[ncaps]; 1634 ncaps++;
1628 ncaps++;
1629 }
1630 /* There's nothing compatible with the desired delivery system */
1631 if (delsys == SYS_UNDEFINED) {
1632 dev_dbg(fe->dvb->device,
1633 "%s: Incompatible DVBv3 FE_SET_FRONTEND call for this frontend\n",
1634 __func__);
1635 return -EINVAL;
1636 }
1637 } 1635 }
1638 1636
1639 c->delivery_system = delsys; 1637 /* There's nothing compatible with the desired delivery system */
1638 if (delsys == SYS_UNDEFINED) {
1639 dev_dbg(fe->dvb->device,
1640 "%s: Delivery system %d not supported on emulation mode.\n",
1641 __func__, desired_system);
1642 return -EINVAL;
1643 }
1644
1645 dev_dbg(fe->dvb->device,
1646 "%s: Using delivery system %d emulated as if it were %d\n",
1647 __func__, delsys, desired_system);
1648
1649 return emulate_delivery_system(fe, desired_system);
1650}
1651
1652/**
1653 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1654 * @fe: frontend struct
1655 *
1656 * A DVBv3 call doesn't know what's the desired system it wants. It also
1657 * doesn't allow to switch between different types. Due to that, userspace
1658 * should use DVBv5 instead.
1659 * However, in order to avoid breaking userspace API, limited backward
1660 * compatibility support is provided.
1661 *
1662 * There are some delivery systems that are incompatible with DVBv3 calls.
1663 *
1664 * This routine should work fine for frontends that support just one delivery
1665 * system.
1666 *
1667 * For frontends that support multiple frontends:
1668 * 1) It defaults to use the first supported delivery system. There's an
1669 * userspace application that allows changing it at runtime;
1670 *
1671 * 2) If the current delivery system is not compatible with DVBv3, it gets
1672 * the first one that it is compatible.
1673 *
1674 * NOTE: in order for this to work with applications like Kaffeine that
1675 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1676 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1677 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1678 * to DVB-S.
1679 */
1680static int dvbv3_set_delivery_system(struct dvb_frontend *fe)
1681{
1682 int ncaps;
1683 u32 delsys = SYS_UNDEFINED;
1684 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1685
1686 /* If not set yet, defaults to the first supported delivery system */
1687 if (c->delivery_system == SYS_UNDEFINED)
1688 c->delivery_system = fe->ops.delsys[0];
1640 1689
1641 /* 1690 /*
1642 * The DVBv3 or DVBv5 call is requesting a different system. So, 1691 * Trivial case: just use the current one, if it already a DVBv3
1643 * emulation is needed. 1692 * delivery system
1644 *
1645 * Emulate newer delivery systems like ISDBT, DVBT and DTMB
1646 * for older DVBv5 applications. The emulation will try to use
1647 * the auto mode for most things, and will assume that the desired
1648 * delivery system is the last one at the ops.delsys[] array
1649 */ 1693 */
1650 dev_dbg(fe->dvb->device, 1694 if (is_dvbv3_delsys(c->delivery_system)) {
1651 "%s: Using delivery system %d emulated as if it were a %d\n", 1695 dev_dbg(fe->dvb->device,
1652 __func__, delsys, desired_system); 1696 "%s: Using delivery system to %d\n",
1697 __func__, c->delivery_system);
1698 return 0;
1699 }
1653 1700
1654 /* 1701 /*
1655 * For now, handles ISDB-T calls. More code may be needed here for the 1702 * Seek for the first delivery system that it is compatible with a
1656 * other emulated stuff 1703 * DVBv3 standard
1657 */ 1704 */
1658 if (type == DVBV3_OFDM) { 1705 ncaps = 0;
1659 if (c->delivery_system == SYS_ISDBT) { 1706 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) {
1660 dev_dbg(fe->dvb->device, 1707 if (dvbv3_type(fe->ops.delsys[ncaps]) != DVBV3_UNKNOWN) {
1661 "%s: Using defaults for SYS_ISDBT\n", 1708 delsys = fe->ops.delsys[ncaps];
1662 __func__); 1709 break;
1663
1664 if (!c->bandwidth_hz)
1665 c->bandwidth_hz = 6000000;
1666
1667 c->isdbt_partial_reception = 0;
1668 c->isdbt_sb_mode = 0;
1669 c->isdbt_sb_subchannel = 0;
1670 c->isdbt_sb_segment_idx = 0;
1671 c->isdbt_sb_segment_count = 0;
1672 c->isdbt_layer_enabled = 0;
1673 for (i = 0; i < 3; i++) {
1674 c->layer[i].fec = FEC_AUTO;
1675 c->layer[i].modulation = QAM_AUTO;
1676 c->layer[i].interleaving = 0;
1677 c->layer[i].segment_count = 0;
1678 }
1679 } 1710 }
1711 ncaps++;
1680 } 1712 }
1681 dev_dbg(fe->dvb->device, "%s: change delivery system on cache to %d\n", 1713 if (delsys == SYS_UNDEFINED) {
1682 __func__, c->delivery_system); 1714 dev_dbg(fe->dvb->device,
1683 1715 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1684 return 0; 1716 __func__);
1717 return -EINVAL;
1718 }
1719 return emulate_delivery_system(fe, delsys);
1685} 1720}
1686 1721
1687static int dtv_property_process_set(struct dvb_frontend *fe, 1722static int dtv_property_process_set(struct dvb_frontend *fe,
@@ -1742,7 +1777,7 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
1742 c->rolloff = tvp->u.data; 1777 c->rolloff = tvp->u.data;
1743 break; 1778 break;
1744 case DTV_DELIVERY_SYSTEM: 1779 case DTV_DELIVERY_SYSTEM:
1745 r = set_delivery_system(fe, tvp->u.data); 1780 r = dvbv5_set_delivery_system(fe, tvp->u.data);
1746 break; 1781 break;
1747 case DTV_VOLTAGE: 1782 case DTV_VOLTAGE:
1748 c->voltage = tvp->u.data; 1783 c->voltage = tvp->u.data;
@@ -2335,7 +2370,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2335 break; 2370 break;
2336 2371
2337 case FE_SET_FRONTEND: 2372 case FE_SET_FRONTEND:
2338 err = set_delivery_system(fe, SYS_UNDEFINED); 2373 err = dvbv3_set_delivery_system(fe);
2339 if (err) 2374 if (err)
2340 break; 2375 break;
2341 2376
@@ -2594,7 +2629,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
2594 * first supported delivery system (ops->delsys[0]) 2629 * first supported delivery system (ops->delsys[0])
2595 */ 2630 */
2596 2631
2597 fe->dtv_property_cache.delivery_system = fe->ops.delsys[0]; 2632 fe->dtv_property_cache.delivery_system = fe->ops.delsys[0];
2598 dvb_frontend_clear_cache(fe); 2633 dvb_frontend_clear_cache(fe);
2599 2634
2600 mutex_unlock(&frontend_mutex); 2635 mutex_unlock(&frontend_mutex);
diff --git a/drivers/media/dvb-core/dvb_frontend.h b/drivers/media/dvb-core/dvb_frontend.h
index b34922a08156..371b6caf486c 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -245,8 +245,8 @@ struct analog_demod_ops {
245 245
246 void (*set_params)(struct dvb_frontend *fe, 246 void (*set_params)(struct dvb_frontend *fe,
247 struct analog_parameters *params); 247 struct analog_parameters *params);
248 int (*has_signal)(struct dvb_frontend *fe); 248 int (*has_signal)(struct dvb_frontend *fe, u16 *signal);
249 int (*get_afc)(struct dvb_frontend *fe); 249 int (*get_afc)(struct dvb_frontend *fe, s32 *afc);
250 void (*tuner_status)(struct dvb_frontend *fe); 250 void (*tuner_status)(struct dvb_frontend *fe);
251 void (*standby)(struct dvb_frontend *fe); 251 void (*standby)(struct dvb_frontend *fe);
252 void (*release)(struct dvb_frontend *fe); 252 void (*release)(struct dvb_frontend *fe);
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index 44225b186f6d..e17cb85d3ecf 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -1044,7 +1044,7 @@ static int dvb_net_feed_start(struct net_device *dev)
1044 ret = priv->tsfeed->set(priv->tsfeed, 1044 ret = priv->tsfeed->set(priv->tsfeed,
1045 priv->pid, /* pid */ 1045 priv->pid, /* pid */
1046 TS_PACKET, /* type */ 1046 TS_PACKET, /* type */
1047 DMX_TS_PES_OTHER, /* pes type */ 1047 DMX_PES_OTHER, /* pes type */
1048 32768, /* circular buffer size */ 1048 32768, /* circular buffer size */
1049 timeout /* timeout */ 1049 timeout /* timeout */
1050 ); 1050 );
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 6f809a70c78e..0e2ec6f73b05 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -210,7 +210,7 @@ config DVB_SI21XX
210config DVB_TS2020 210config DVB_TS2020
211 tristate "Montage Tehnology TS2020 based tuners" 211 tristate "Montage Tehnology TS2020 based tuners"
212 depends on DVB_CORE && I2C 212 depends on DVB_CORE && I2C
213 default m if DVB_FE_CUSTOMISE 213 default m if !MEDIA_SUBDRV_AUTOSELECT
214 help 214 help
215 A DVB-S/S2 silicon tuner. Say Y when you want to support this tuner. 215 A DVB-S/S2 silicon tuner. Say Y when you want to support this tuner.
216 216
diff --git a/drivers/media/dvb-frontends/a8293.h b/drivers/media/dvb-frontends/a8293.h
index ed29e5504f76..b6ef6427cfa5 100644
--- a/drivers/media/dvb-frontends/a8293.h
+++ b/drivers/media/dvb-frontends/a8293.h
@@ -21,12 +21,13 @@
21#ifndef A8293_H 21#ifndef A8293_H
22#define A8293_H 22#define A8293_H
23 23
24#include <linux/kconfig.h>
25
24struct a8293_config { 26struct a8293_config {
25 u8 i2c_addr; 27 u8 i2c_addr;
26}; 28};
27 29
28#if defined(CONFIG_DVB_A8293) || \ 30#if IS_ENABLED(CONFIG_DVB_A8293)
29 (defined(CONFIG_DVB_A8293_MODULE) && defined(MODULE))
30extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe, 31extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
31 struct i2c_adapter *i2c, const struct a8293_config *cfg); 32 struct i2c_adapter *i2c, const struct a8293_config *cfg);
32#else 33#else
diff --git a/drivers/media/dvb-frontends/af9013.h b/drivers/media/dvb-frontends/af9013.h
index dc837d91327a..09273b2cd310 100644
--- a/drivers/media/dvb-frontends/af9013.h
+++ b/drivers/media/dvb-frontends/af9013.h
@@ -25,6 +25,7 @@
25#ifndef AF9013_H 25#ifndef AF9013_H
26#define AF9013_H 26#define AF9013_H
27 27
28#include <linux/kconfig.h>
28#include <linux/dvb/frontend.h> 29#include <linux/dvb/frontend.h>
29 30
30/* AF9013/5 GPIOs (mostly guessed) 31/* AF9013/5 GPIOs (mostly guessed)
@@ -102,8 +103,7 @@ struct af9013_config {
102 u8 gpio[4]; 103 u8 gpio[4];
103}; 104};
104 105
105#if defined(CONFIG_DVB_AF9013) || \ 106#if IS_ENABLED(CONFIG_DVB_AF9013)
106 (defined(CONFIG_DVB_AF9013_MODULE) && defined(MODULE))
107extern struct dvb_frontend *af9013_attach(const struct af9013_config *config, 107extern struct dvb_frontend *af9013_attach(const struct af9013_config *config,
108 struct i2c_adapter *i2c); 108 struct i2c_adapter *i2c);
109#else 109#else
diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
index c9cad989b8b9..a777b4b944eb 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -156,6 +156,37 @@ static int af9033_rd_reg_mask(struct af9033_state *state, u32 reg, u8 *val,
156 return 0; 156 return 0;
157} 157}
158 158
159/* write reg val table using reg addr auto increment */
160static int af9033_wr_reg_val_tab(struct af9033_state *state,
161 const struct reg_val *tab, int tab_len)
162{
163 int ret, i, j;
164 u8 buf[tab_len];
165
166 dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len);
167
168 for (i = 0, j = 0; i < tab_len; i++) {
169 buf[j] = tab[i].val;
170
171 if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1) {
172 ret = af9033_wr_regs(state, tab[i].reg - j, buf, j + 1);
173 if (ret < 0)
174 goto err;
175
176 j = 0;
177 } else {
178 j++;
179 }
180 }
181
182 return 0;
183
184err:
185 dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret);
186
187 return ret;
188}
189
159static u32 af9033_div(struct af9033_state *state, u32 a, u32 b, u32 x) 190static u32 af9033_div(struct af9033_state *state, u32 a, u32 b, u32 x)
160{ 191{
161 u32 r = 0, c = 0, i; 192 u32 r = 0, c = 0, i;
@@ -223,6 +254,7 @@ static int af9033_init(struct dvb_frontend *fe)
223 { 0x80f986, state->ts_mode_parallel, 0x01 }, 254 { 0x80f986, state->ts_mode_parallel, 0x01 },
224 { 0x00d827, 0x00, 0xff }, 255 { 0x00d827, 0x00, 0xff },
225 { 0x00d829, 0x00, 0xff }, 256 { 0x00d829, 0x00, 0xff },
257 { 0x800045, state->cfg.adc_multiplier, 0xff },
226 }; 258 };
227 259
228 /* program clock control */ 260 /* program clock control */
@@ -286,14 +318,29 @@ static int af9033_init(struct dvb_frontend *fe)
286 318
287 /* load OFSM settings */ 319 /* load OFSM settings */
288 dev_dbg(&state->i2c->dev, "%s: load ofsm settings\n", __func__); 320 dev_dbg(&state->i2c->dev, "%s: load ofsm settings\n", __func__);
289 len = ARRAY_SIZE(ofsm_init); 321 switch (state->cfg.tuner) {
290 init = ofsm_init; 322 case AF9033_TUNER_IT9135_38:
291 for (i = 0; i < len; i++) { 323 case AF9033_TUNER_IT9135_51:
292 ret = af9033_wr_reg(state, init[i].reg, init[i].val); 324 case AF9033_TUNER_IT9135_52:
293 if (ret < 0) 325 len = ARRAY_SIZE(ofsm_init_it9135_v1);
294 goto err; 326 init = ofsm_init_it9135_v1;
327 break;
328 case AF9033_TUNER_IT9135_60:
329 case AF9033_TUNER_IT9135_61:
330 case AF9033_TUNER_IT9135_62:
331 len = ARRAY_SIZE(ofsm_init_it9135_v2);
332 init = ofsm_init_it9135_v2;
333 break;
334 default:
335 len = ARRAY_SIZE(ofsm_init);
336 init = ofsm_init;
337 break;
295 } 338 }
296 339
340 ret = af9033_wr_reg_val_tab(state, init, len);
341 if (ret < 0)
342 goto err;
343
297 /* load tuner specific settings */ 344 /* load tuner specific settings */
298 dev_dbg(&state->i2c->dev, "%s: load tuner specific settings\n", 345 dev_dbg(&state->i2c->dev, "%s: load tuner specific settings\n",
299 __func__); 346 __func__);
@@ -322,6 +369,30 @@ static int af9033_init(struct dvb_frontend *fe)
322 len = ARRAY_SIZE(tuner_init_fc0012); 369 len = ARRAY_SIZE(tuner_init_fc0012);
323 init = tuner_init_fc0012; 370 init = tuner_init_fc0012;
324 break; 371 break;
372 case AF9033_TUNER_IT9135_38:
373 len = ARRAY_SIZE(tuner_init_it9135_38);
374 init = tuner_init_it9135_38;
375 break;
376 case AF9033_TUNER_IT9135_51:
377 len = ARRAY_SIZE(tuner_init_it9135_51);
378 init = tuner_init_it9135_51;
379 break;
380 case AF9033_TUNER_IT9135_52:
381 len = ARRAY_SIZE(tuner_init_it9135_52);
382 init = tuner_init_it9135_52;
383 break;
384 case AF9033_TUNER_IT9135_60:
385 len = ARRAY_SIZE(tuner_init_it9135_60);
386 init = tuner_init_it9135_60;
387 break;
388 case AF9033_TUNER_IT9135_61:
389 len = ARRAY_SIZE(tuner_init_it9135_61);
390 init = tuner_init_it9135_61;
391 break;
392 case AF9033_TUNER_IT9135_62:
393 len = ARRAY_SIZE(tuner_init_it9135_62);
394 init = tuner_init_it9135_62;
395 break;
325 default: 396 default:
326 dev_dbg(&state->i2c->dev, "%s: unsupported tuner ID=%d\n", 397 dev_dbg(&state->i2c->dev, "%s: unsupported tuner ID=%d\n",
327 __func__, state->cfg.tuner); 398 __func__, state->cfg.tuner);
@@ -329,11 +400,9 @@ static int af9033_init(struct dvb_frontend *fe)
329 goto err; 400 goto err;
330 } 401 }
331 402
332 for (i = 0; i < len; i++) { 403 ret = af9033_wr_reg_val_tab(state, init, len);
333 ret = af9033_wr_reg(state, init[i].reg, init[i].val); 404 if (ret < 0)
334 if (ret < 0) 405 goto err;
335 goto err;
336 }
337 406
338 if (state->cfg.ts_mode == AF9033_TS_MODE_SERIAL) { 407 if (state->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
339 ret = af9033_wr_reg_mask(state, 0x00d91c, 0x01, 0x01); 408 ret = af9033_wr_reg_mask(state, 0x00d91c, 0x01, 0x01);
@@ -349,6 +418,15 @@ static int af9033_init(struct dvb_frontend *fe)
349 goto err; 418 goto err;
350 } 419 }
351 420
421 switch (state->cfg.tuner) {
422 case AF9033_TUNER_IT9135_60:
423 case AF9033_TUNER_IT9135_61:
424 case AF9033_TUNER_IT9135_62:
425 ret = af9033_wr_reg(state, 0x800000, 0x01);
426 if (ret < 0)
427 goto err;
428 }
429
352 state->bandwidth_hz = 0; /* force to program all parameters */ 430 state->bandwidth_hz = 0; /* force to program all parameters */
353 431
354 return 0; 432 return 0;
@@ -415,7 +493,8 @@ err:
415static int af9033_get_tune_settings(struct dvb_frontend *fe, 493static int af9033_get_tune_settings(struct dvb_frontend *fe,
416 struct dvb_frontend_tune_settings *fesettings) 494 struct dvb_frontend_tune_settings *fesettings)
417{ 495{
418 fesettings->min_delay_ms = 800; 496 /* 800 => 2000 because IT9135 v2 is slow to gain lock */
497 fesettings->min_delay_ms = 2000;
419 fesettings->step_size = 0; 498 fesettings->step_size = 0;
420 fesettings->max_drift = 0; 499 fesettings->max_drift = 0;
421 500
@@ -498,17 +577,17 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
498 if (spec_inv == -1) 577 if (spec_inv == -1)
499 freq_cw = 0x800000 - freq_cw; 578 freq_cw = 0x800000 - freq_cw;
500 579
501 /* get adc multiplies */ 580 if (state->cfg.adc_multiplier == AF9033_ADC_MULTIPLIER_2X)
502 ret = af9033_rd_reg(state, 0x800045, &tmp);
503 if (ret < 0)
504 goto err;
505
506 if (tmp == 1)
507 freq_cw /= 2; 581 freq_cw /= 2;
508 582
509 buf[0] = (freq_cw >> 0) & 0xff; 583 buf[0] = (freq_cw >> 0) & 0xff;
510 buf[1] = (freq_cw >> 8) & 0xff; 584 buf[1] = (freq_cw >> 8) & 0xff;
511 buf[2] = (freq_cw >> 16) & 0x7f; 585 buf[2] = (freq_cw >> 16) & 0x7f;
586
587 /* FIXME: there seems to be calculation error here... */
588 if (if_frequency == 0)
589 buf[2] = 0;
590
512 ret = af9033_wr_regs(state, 0x800029, buf, 3); 591 ret = af9033_wr_regs(state, 0x800029, buf, 3);
513 if (ret < 0) 592 if (ret < 0)
514 goto err; 593 goto err;
@@ -934,13 +1013,24 @@ struct dvb_frontend *af9033_attach(const struct af9033_config *config,
934 buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); 1013 buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
935 1014
936 /* sleep */ 1015 /* sleep */
937 ret = af9033_wr_reg(state, 0x80004c, 1); 1016 switch (state->cfg.tuner) {
938 if (ret < 0) 1017 case AF9033_TUNER_IT9135_38:
939 goto err; 1018 case AF9033_TUNER_IT9135_51:
1019 case AF9033_TUNER_IT9135_52:
1020 case AF9033_TUNER_IT9135_60:
1021 case AF9033_TUNER_IT9135_61:
1022 case AF9033_TUNER_IT9135_62:
1023 /* IT9135 did not like to sleep at that early */
1024 break;
1025 default:
1026 ret = af9033_wr_reg(state, 0x80004c, 1);
1027 if (ret < 0)
1028 goto err;
940 1029
941 ret = af9033_wr_reg(state, 0x800000, 0); 1030 ret = af9033_wr_reg(state, 0x800000, 0);
942 if (ret < 0) 1031 if (ret < 0)
943 goto err; 1032 goto err;
1033 }
944 1034
945 /* configure internal TS mode */ 1035 /* configure internal TS mode */
946 switch (state->cfg.ts_mode) { 1036 switch (state->cfg.ts_mode) {
diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
index 82bd8c1513b6..c286e8f1ec02 100644
--- a/drivers/media/dvb-frontends/af9033.h
+++ b/drivers/media/dvb-frontends/af9033.h
@@ -22,6 +22,8 @@
22#ifndef AF9033_H 22#ifndef AF9033_H
23#define AF9033_H 23#define AF9033_H
24 24
25#include <linux/kconfig.h>
26
25struct af9033_config { 27struct af9033_config {
26 /* 28 /*
27 * I2C address 29 * I2C address
@@ -36,6 +38,13 @@ struct af9033_config {
36 u32 clock; 38 u32 clock;
37 39
38 /* 40 /*
41 * ADC multiplier
42 */
43#define AF9033_ADC_MULTIPLIER_1X 0
44#define AF9033_ADC_MULTIPLIER_2X 1
45 u8 adc_multiplier;
46
47 /*
39 * tuner 48 * tuner
40 */ 49 */
41#define AF9033_TUNER_TUA9001 0x27 /* Infineon TUA 9001 */ 50#define AF9033_TUNER_TUA9001 0x27 /* Infineon TUA 9001 */
@@ -44,6 +53,14 @@ struct af9033_config {
44#define AF9033_TUNER_MXL5007T 0xa0 /* MaxLinear MxL5007T */ 53#define AF9033_TUNER_MXL5007T 0xa0 /* MaxLinear MxL5007T */
45#define AF9033_TUNER_TDA18218 0xa1 /* NXP TDA 18218HN */ 54#define AF9033_TUNER_TDA18218 0xa1 /* NXP TDA 18218HN */
46#define AF9033_TUNER_FC2580 0x32 /* FCI FC2580 */ 55#define AF9033_TUNER_FC2580 0x32 /* FCI FC2580 */
56/* 50-5f Omega */
57#define AF9033_TUNER_IT9135_38 0x38 /* Omega */
58#define AF9033_TUNER_IT9135_51 0x51 /* Omega LNA config 1 */
59#define AF9033_TUNER_IT9135_52 0x52 /* Omega LNA config 2 */
60/* 60-6f Omega v2 */
61#define AF9033_TUNER_IT9135_60 0x60 /* Omega v2 */
62#define AF9033_TUNER_IT9135_61 0x61 /* Omega v2 LNA config 1 */
63#define AF9033_TUNER_IT9135_62 0x62 /* Omega v2 LNA config 2 */
47 u8 tuner; 64 u8 tuner;
48 65
49 /* 66 /*
@@ -61,8 +78,7 @@ struct af9033_config {
61}; 78};
62 79
63 80
64#if defined(CONFIG_DVB_AF9033) || \ 81#if IS_ENABLED(CONFIG_DVB_AF9033)
65 (defined(CONFIG_DVB_AF9033_MODULE) && defined(MODULE))
66extern struct dvb_frontend *af9033_attach(const struct af9033_config *config, 82extern struct dvb_frontend *af9033_attach(const struct af9033_config *config,
67 struct i2c_adapter *i2c); 83 struct i2c_adapter *i2c);
68#else 84#else
diff --git a/drivers/media/dvb-frontends/af9033_priv.h b/drivers/media/dvb-frontends/af9033_priv.h
index e9bd78265543..fc2ad581e302 100644
--- a/drivers/media/dvb-frontends/af9033_priv.h
+++ b/drivers/media/dvb-frontends/af9033_priv.h
@@ -547,5 +547,1509 @@ static const struct reg_val tuner_init_fc2580[] = {
547 { 0x80f1e6, 0x01 }, 547 { 0x80f1e6, 0x01 },
548}; 548};
549 549
550#endif /* AF9033_PRIV_H */ 550static const struct reg_val ofsm_init_it9135_v1[] = {
551 { 0x800051, 0x01 },
552 { 0x800070, 0x0a },
553 { 0x80007e, 0x04 },
554 { 0x800081, 0x0a },
555 { 0x80008a, 0x01 },
556 { 0x80008e, 0x01 },
557 { 0x800092, 0x06 },
558 { 0x800099, 0x01 },
559 { 0x80009f, 0xe1 },
560 { 0x8000a0, 0xcf },
561 { 0x8000a3, 0x01 },
562 { 0x8000a5, 0x01 },
563 { 0x8000a6, 0x01 },
564 { 0x8000a9, 0x00 },
565 { 0x8000aa, 0x01 },
566 { 0x8000b0, 0x01 },
567 { 0x8000c2, 0x05 },
568 { 0x8000c6, 0x19 },
569 { 0x80f000, 0x0f },
570 { 0x80f016, 0x10 },
571 { 0x80f017, 0x04 },
572 { 0x80f018, 0x05 },
573 { 0x80f019, 0x04 },
574 { 0x80f01a, 0x05 },
575 { 0x80f021, 0x03 },
576 { 0x80f022, 0x0a },
577 { 0x80f023, 0x0a },
578 { 0x80f02b, 0x00 },
579 { 0x80f02c, 0x01 },
580 { 0x80f064, 0x03 },
581 { 0x80f065, 0xf9 },
582 { 0x80f066, 0x03 },
583 { 0x80f067, 0x01 },
584 { 0x80f06f, 0xe0 },
585 { 0x80f070, 0x03 },
586 { 0x80f072, 0x0f },
587 { 0x80f073, 0x03 },
588 { 0x80f078, 0x00 },
589 { 0x80f087, 0x00 },
590 { 0x80f09b, 0x3f },
591 { 0x80f09c, 0x00 },
592 { 0x80f09d, 0x20 },
593 { 0x80f09e, 0x00 },
594 { 0x80f09f, 0x0c },
595 { 0x80f0a0, 0x00 },
596 { 0x80f130, 0x04 },
597 { 0x80f132, 0x04 },
598 { 0x80f144, 0x1a },
599 { 0x80f146, 0x00 },
600 { 0x80f14a, 0x01 },
601 { 0x80f14c, 0x00 },
602 { 0x80f14d, 0x00 },
603 { 0x80f14f, 0x04 },
604 { 0x80f158, 0x7f },
605 { 0x80f15a, 0x00 },
606 { 0x80f15b, 0x08 },
607 { 0x80f15d, 0x03 },
608 { 0x80f15e, 0x05 },
609 { 0x80f163, 0x05 },
610 { 0x80f166, 0x01 },
611 { 0x80f167, 0x40 },
612 { 0x80f168, 0x0f },
613 { 0x80f17a, 0x00 },
614 { 0x80f17b, 0x00 },
615 { 0x80f183, 0x01 },
616 { 0x80f19d, 0x40 },
617 { 0x80f1bc, 0x36 },
618 { 0x80f1bd, 0x00 },
619 { 0x80f1cb, 0xa0 },
620 { 0x80f1cc, 0x01 },
621 { 0x80f204, 0x10 },
622 { 0x80f214, 0x00 },
623 { 0x80f40e, 0x0a },
624 { 0x80f40f, 0x40 },
625 { 0x80f410, 0x08 },
626 { 0x80f55f, 0x0a },
627 { 0x80f561, 0x15 },
628 { 0x80f562, 0x20 },
629 { 0x80f5df, 0xfb },
630 { 0x80f5e0, 0x00 },
631 { 0x80f5e3, 0x09 },
632 { 0x80f5e4, 0x01 },
633 { 0x80f5e5, 0x01 },
634 { 0x80f5f8, 0x01 },
635 { 0x80f5fd, 0x01 },
636 { 0x80f600, 0x05 },
637 { 0x80f601, 0x08 },
638 { 0x80f602, 0x0b },
639 { 0x80f603, 0x0e },
640 { 0x80f604, 0x11 },
641 { 0x80f605, 0x14 },
642 { 0x80f606, 0x17 },
643 { 0x80f607, 0x1f },
644 { 0x80f60e, 0x00 },
645 { 0x80f60f, 0x04 },
646 { 0x80f610, 0x32 },
647 { 0x80f611, 0x10 },
648 { 0x80f707, 0xfc },
649 { 0x80f708, 0x00 },
650 { 0x80f709, 0x37 },
651 { 0x80f70a, 0x00 },
652 { 0x80f78b, 0x01 },
653 { 0x80f80f, 0x40 },
654 { 0x80f810, 0x54 },
655 { 0x80f811, 0x5a },
656 { 0x80f905, 0x01 },
657 { 0x80fb06, 0x03 },
658 { 0x80fd8b, 0x00 },
659};
660
661/* ITE Tech IT9135 Omega tuner init
662 AF9033_TUNER_IT9135_38 = 0x38 */
663static const struct reg_val tuner_init_it9135_38[] = {
664 { 0x800043, 0x00 },
665 { 0x800046, 0x38 },
666 { 0x800051, 0x01 },
667 { 0x80005f, 0x00 },
668 { 0x800060, 0x00 },
669 { 0x800068, 0x0a },
670 { 0x800070, 0x0a },
671 { 0x800071, 0x05 },
672 { 0x800072, 0x02 },
673 { 0x800075, 0x8c },
674 { 0x800076, 0x8c },
675 { 0x800077, 0x8c },
676 { 0x800078, 0xc8 },
677 { 0x800079, 0x01 },
678 { 0x80007e, 0x04 },
679 { 0x80007f, 0x00 },
680 { 0x800081, 0x0a },
681 { 0x800082, 0x12 },
682 { 0x800083, 0x02 },
683 { 0x800084, 0x0a },
684 { 0x800085, 0x03 },
685 { 0x800086, 0xc8 },
686 { 0x800087, 0xb8 },
687 { 0x800088, 0xd0 },
688 { 0x800089, 0xc3 },
689 { 0x80008a, 0x01 },
690 { 0x80008e, 0x01 },
691 { 0x800092, 0x06 },
692 { 0x800093, 0x00 },
693 { 0x800094, 0x00 },
694 { 0x800095, 0x00 },
695 { 0x800096, 0x00 },
696 { 0x800099, 0x01 },
697 { 0x80009b, 0x3c },
698 { 0x80009c, 0x28 },
699 { 0x80009f, 0xe1 },
700 { 0x8000a0, 0xcf },
701 { 0x8000a3, 0x01 },
702 { 0x8000a4, 0x5a },
703 { 0x8000a5, 0x01 },
704 { 0x8000a6, 0x01 },
705 { 0x8000a9, 0x00 },
706 { 0x8000aa, 0x01 },
707 { 0x8000b0, 0x01 },
708 { 0x8000b3, 0x02 },
709 { 0x8000b4, 0x32 },
710 { 0x8000b6, 0x14 },
711 { 0x8000c0, 0x11 },
712 { 0x8000c1, 0x00 },
713 { 0x8000c2, 0x05 },
714 { 0x8000c4, 0x00 },
715 { 0x8000c6, 0x19 },
716 { 0x8000c7, 0x00 },
717 { 0x8000cc, 0x2e },
718 { 0x8000cd, 0x51 },
719 { 0x8000ce, 0x33 },
720 { 0x8000f3, 0x05 },
721 { 0x8000f4, 0x8c },
722 { 0x8000f5, 0x8c },
723 { 0x8000f8, 0x03 },
724 { 0x8000f9, 0x06 },
725 { 0x8000fa, 0x06 },
726 { 0x8000fc, 0x02 },
727 { 0x8000fd, 0x02 },
728 { 0x8000fe, 0x02 },
729 { 0x8000ff, 0x09 },
730 { 0x800100, 0x50 },
731 { 0x800101, 0x7b },
732 { 0x800102, 0x77 },
733 { 0x800103, 0x00 },
734 { 0x800104, 0x02 },
735 { 0x800105, 0xc8 },
736 { 0x800106, 0x05 },
737 { 0x800107, 0x7b },
738 { 0x800109, 0x02 },
739 { 0x800115, 0x0a },
740 { 0x800116, 0x03 },
741 { 0x800117, 0x02 },
742 { 0x800118, 0x80 },
743 { 0x80011a, 0xc8 },
744 { 0x80011b, 0x7b },
745 { 0x80011c, 0x8a },
746 { 0x80011d, 0xa0 },
747 { 0x800122, 0x02 },
748 { 0x800123, 0x18 },
749 { 0x800124, 0xc3 },
750 { 0x800127, 0x00 },
751 { 0x800128, 0x07 },
752 { 0x80012a, 0x53 },
753 { 0x80012b, 0x51 },
754 { 0x80012c, 0x4e },
755 { 0x80012d, 0x43 },
756 { 0x800137, 0x01 },
757 { 0x800138, 0x00 },
758 { 0x800139, 0x07 },
759 { 0x80013a, 0x00 },
760 { 0x80013b, 0x06 },
761 { 0x80013d, 0x00 },
762 { 0x80013e, 0x01 },
763 { 0x80013f, 0x5b },
764 { 0x800140, 0xc8 },
765 { 0x800141, 0x59 },
766 { 0x80f000, 0x0f },
767 { 0x80f016, 0x10 },
768 { 0x80f017, 0x04 },
769 { 0x80f018, 0x05 },
770 { 0x80f019, 0x04 },
771 { 0x80f01a, 0x05 },
772 { 0x80f01f, 0x8c },
773 { 0x80f020, 0x00 },
774 { 0x80f021, 0x03 },
775 { 0x80f022, 0x0a },
776 { 0x80f023, 0x0a },
777 { 0x80f029, 0x8c },
778 { 0x80f02a, 0x00 },
779 { 0x80f02b, 0x00 },
780 { 0x80f02c, 0x01 },
781 { 0x80f064, 0x03 },
782 { 0x80f065, 0xf9 },
783 { 0x80f066, 0x03 },
784 { 0x80f067, 0x01 },
785 { 0x80f06f, 0xe0 },
786 { 0x80f070, 0x03 },
787 { 0x80f072, 0x0f },
788 { 0x80f073, 0x03 },
789 { 0x80f077, 0x01 },
790 { 0x80f078, 0x00 },
791 { 0x80f085, 0x00 },
792 { 0x80f086, 0x02 },
793 { 0x80f087, 0x00 },
794 { 0x80f09b, 0x3f },
795 { 0x80f09c, 0x00 },
796 { 0x80f09d, 0x20 },
797 { 0x80f09e, 0x00 },
798 { 0x80f09f, 0x0c },
799 { 0x80f0a0, 0x00 },
800 { 0x80f130, 0x04 },
801 { 0x80f132, 0x04 },
802 { 0x80f144, 0x1a },
803 { 0x80f146, 0x00 },
804 { 0x80f14a, 0x01 },
805 { 0x80f14c, 0x00 },
806 { 0x80f14d, 0x00 },
807 { 0x80f14f, 0x04 },
808 { 0x80f158, 0x7f },
809 { 0x80f15a, 0x00 },
810 { 0x80f15b, 0x08 },
811 { 0x80f15d, 0x03 },
812 { 0x80f15e, 0x05 },
813 { 0x80f163, 0x05 },
814 { 0x80f166, 0x01 },
815 { 0x80f167, 0x40 },
816 { 0x80f168, 0x0f },
817 { 0x80f17a, 0x00 },
818 { 0x80f17b, 0x00 },
819 { 0x80f183, 0x01 },
820 { 0x80f19d, 0x40 },
821 { 0x80f1bc, 0x36 },
822 { 0x80f1bd, 0x00 },
823 { 0x80f1cb, 0xa0 },
824 { 0x80f1cc, 0x01 },
825 { 0x80f204, 0x10 },
826 { 0x80f214, 0x00 },
827 { 0x80f24c, 0x88 },
828 { 0x80f24d, 0x95 },
829 { 0x80f24e, 0x9a },
830 { 0x80f24f, 0x90 },
831 { 0x80f25a, 0x07 },
832 { 0x80f25b, 0xe8 },
833 { 0x80f25c, 0x03 },
834 { 0x80f25d, 0xb0 },
835 { 0x80f25e, 0x04 },
836 { 0x80f270, 0x01 },
837 { 0x80f271, 0x02 },
838 { 0x80f272, 0x01 },
839 { 0x80f273, 0x02 },
840 { 0x80f40e, 0x0a },
841 { 0x80f40f, 0x40 },
842 { 0x80f410, 0x08 },
843 { 0x80f55f, 0x0a },
844 { 0x80f561, 0x15 },
845 { 0x80f562, 0x20 },
846 { 0x80f5df, 0xfb },
847 { 0x80f5e0, 0x00 },
848 { 0x80f5e3, 0x09 },
849 { 0x80f5e4, 0x01 },
850 { 0x80f5e5, 0x01 },
851 { 0x80f5f8, 0x01 },
852 { 0x80f5fd, 0x01 },
853 { 0x80f600, 0x05 },
854 { 0x80f601, 0x08 },
855 { 0x80f602, 0x0b },
856 { 0x80f603, 0x0e },
857 { 0x80f604, 0x11 },
858 { 0x80f605, 0x14 },
859 { 0x80f606, 0x17 },
860 { 0x80f607, 0x1f },
861 { 0x80f60e, 0x00 },
862 { 0x80f60f, 0x04 },
863 { 0x80f610, 0x32 },
864 { 0x80f611, 0x10 },
865 { 0x80f707, 0xfc },
866 { 0x80f708, 0x00 },
867 { 0x80f709, 0x37 },
868 { 0x80f70a, 0x00 },
869 { 0x80f78b, 0x01 },
870 { 0x80f80f, 0x40 },
871 { 0x80f810, 0x54 },
872 { 0x80f811, 0x5a },
873 { 0x80f905, 0x01 },
874 { 0x80fb06, 0x03 },
875 { 0x80fd8b, 0x00 },
876};
877
878/* ITE Tech IT9135 Omega LNA config 1 tuner init
879 AF9033_TUNER_IT9135_51 = 0x51 */
880static const struct reg_val tuner_init_it9135_51[] = {
881 { 0x800043, 0x00 },
882 { 0x800046, 0x51 },
883 { 0x800051, 0x01 },
884 { 0x80005f, 0x00 },
885 { 0x800060, 0x00 },
886 { 0x800068, 0x0a },
887 { 0x800070, 0x0a },
888 { 0x800071, 0x06 },
889 { 0x800072, 0x02 },
890 { 0x800075, 0x8c },
891 { 0x800076, 0x8c },
892 { 0x800077, 0x8c },
893 { 0x800078, 0xc8 },
894 { 0x800079, 0x01 },
895 { 0x80007e, 0x04 },
896 { 0x80007f, 0x00 },
897 { 0x800081, 0x0a },
898 { 0x800082, 0x12 },
899 { 0x800083, 0x02 },
900 { 0x800084, 0x0a },
901 { 0x800085, 0x03 },
902 { 0x800086, 0xc0 },
903 { 0x800087, 0x96 },
904 { 0x800088, 0xcf },
905 { 0x800089, 0xc3 },
906 { 0x80008a, 0x01 },
907 { 0x80008e, 0x01 },
908 { 0x800092, 0x06 },
909 { 0x800093, 0x00 },
910 { 0x800094, 0x00 },
911 { 0x800095, 0x00 },
912 { 0x800096, 0x00 },
913 { 0x800099, 0x01 },
914 { 0x80009b, 0x3c },
915 { 0x80009c, 0x28 },
916 { 0x80009f, 0xe1 },
917 { 0x8000a0, 0xcf },
918 { 0x8000a3, 0x01 },
919 { 0x8000a4, 0x5a },
920 { 0x8000a5, 0x01 },
921 { 0x8000a6, 0x01 },
922 { 0x8000a9, 0x00 },
923 { 0x8000aa, 0x01 },
924 { 0x8000b0, 0x01 },
925 { 0x8000b3, 0x02 },
926 { 0x8000b4, 0x3c },
927 { 0x8000b6, 0x14 },
928 { 0x8000c0, 0x11 },
929 { 0x8000c1, 0x00 },
930 { 0x8000c2, 0x05 },
931 { 0x8000c4, 0x00 },
932 { 0x8000c6, 0x19 },
933 { 0x8000c7, 0x00 },
934 { 0x8000cc, 0x2e },
935 { 0x8000cd, 0x51 },
936 { 0x8000ce, 0x33 },
937 { 0x8000f3, 0x05 },
938 { 0x8000f4, 0x8c },
939 { 0x8000f5, 0x8c },
940 { 0x8000f8, 0x03 },
941 { 0x8000f9, 0x06 },
942 { 0x8000fa, 0x06 },
943 { 0x8000fc, 0x03 },
944 { 0x8000fd, 0x02 },
945 { 0x8000fe, 0x02 },
946 { 0x8000ff, 0x09 },
947 { 0x800100, 0x50 },
948 { 0x800101, 0x7a },
949 { 0x800102, 0x77 },
950 { 0x800103, 0x01 },
951 { 0x800104, 0x02 },
952 { 0x800105, 0xb0 },
953 { 0x800106, 0x02 },
954 { 0x800107, 0x7a },
955 { 0x800109, 0x02 },
956 { 0x800115, 0x0a },
957 { 0x800116, 0x03 },
958 { 0x800117, 0x02 },
959 { 0x800118, 0x80 },
960 { 0x80011a, 0xc0 },
961 { 0x80011b, 0x7a },
962 { 0x80011c, 0xac },
963 { 0x80011d, 0x8c },
964 { 0x800122, 0x02 },
965 { 0x800123, 0x70 },
966 { 0x800124, 0xa4 },
967 { 0x800127, 0x00 },
968 { 0x800128, 0x07 },
969 { 0x80012a, 0x53 },
970 { 0x80012b, 0x51 },
971 { 0x80012c, 0x4e },
972 { 0x80012d, 0x43 },
973 { 0x800137, 0x01 },
974 { 0x800138, 0x00 },
975 { 0x800139, 0x07 },
976 { 0x80013a, 0x00 },
977 { 0x80013b, 0x06 },
978 { 0x80013d, 0x00 },
979 { 0x80013e, 0x01 },
980 { 0x80013f, 0x5b },
981 { 0x800140, 0xc0 },
982 { 0x800141, 0x59 },
983 { 0x80f000, 0x0f },
984 { 0x80f016, 0x10 },
985 { 0x80f017, 0x04 },
986 { 0x80f018, 0x05 },
987 { 0x80f019, 0x04 },
988 { 0x80f01a, 0x05 },
989 { 0x80f01f, 0x8c },
990 { 0x80f020, 0x00 },
991 { 0x80f021, 0x03 },
992 { 0x80f022, 0x0a },
993 { 0x80f023, 0x0a },
994 { 0x80f029, 0x8c },
995 { 0x80f02a, 0x00 },
996 { 0x80f02b, 0x00 },
997 { 0x80f02c, 0x01 },
998 { 0x80f064, 0x03 },
999 { 0x80f065, 0xf9 },
1000 { 0x80f066, 0x03 },
1001 { 0x80f067, 0x01 },
1002 { 0x80f06f, 0xe0 },
1003 { 0x80f070, 0x03 },
1004 { 0x80f072, 0x0f },
1005 { 0x80f073, 0x03 },
1006 { 0x80f077, 0x01 },
1007 { 0x80f078, 0x00 },
1008 { 0x80f085, 0xc0 },
1009 { 0x80f086, 0x01 },
1010 { 0x80f087, 0x00 },
1011 { 0x80f09b, 0x3f },
1012 { 0x80f09c, 0x00 },
1013 { 0x80f09d, 0x20 },
1014 { 0x80f09e, 0x00 },
1015 { 0x80f09f, 0x0c },
1016 { 0x80f0a0, 0x00 },
1017 { 0x80f130, 0x04 },
1018 { 0x80f132, 0x04 },
1019 { 0x80f144, 0x1a },
1020 { 0x80f146, 0x00 },
1021 { 0x80f14a, 0x01 },
1022 { 0x80f14c, 0x00 },
1023 { 0x80f14d, 0x00 },
1024 { 0x80f14f, 0x04 },
1025 { 0x80f158, 0x7f },
1026 { 0x80f15a, 0x00 },
1027 { 0x80f15b, 0x08 },
1028 { 0x80f15d, 0x03 },
1029 { 0x80f15e, 0x05 },
1030 { 0x80f163, 0x05 },
1031 { 0x80f166, 0x01 },
1032 { 0x80f167, 0x40 },
1033 { 0x80f168, 0x0f },
1034 { 0x80f17a, 0x00 },
1035 { 0x80f17b, 0x00 },
1036 { 0x80f183, 0x01 },
1037 { 0x80f19d, 0x40 },
1038 { 0x80f1bc, 0x36 },
1039 { 0x80f1bd, 0x00 },
1040 { 0x80f1cb, 0xa0 },
1041 { 0x80f1cc, 0x01 },
1042 { 0x80f204, 0x10 },
1043 { 0x80f214, 0x00 },
1044 { 0x80f24c, 0x88 },
1045 { 0x80f24d, 0x95 },
1046 { 0x80f24e, 0x9a },
1047 { 0x80f24f, 0x90 },
1048 { 0x80f25a, 0x07 },
1049 { 0x80f25b, 0xe8 },
1050 { 0x80f25c, 0x03 },
1051 { 0x80f25d, 0xb0 },
1052 { 0x80f25e, 0x04 },
1053 { 0x80f270, 0x01 },
1054 { 0x80f271, 0x02 },
1055 { 0x80f272, 0x01 },
1056 { 0x80f273, 0x02 },
1057 { 0x80f40e, 0x0a },
1058 { 0x80f40f, 0x40 },
1059 { 0x80f410, 0x08 },
1060 { 0x80f55f, 0x0a },
1061 { 0x80f561, 0x15 },
1062 { 0x80f562, 0x20 },
1063 { 0x80f5df, 0xfb },
1064 { 0x80f5e0, 0x00 },
1065 { 0x80f5e3, 0x09 },
1066 { 0x80f5e4, 0x01 },
1067 { 0x80f5e5, 0x01 },
1068 { 0x80f5f8, 0x01 },
1069 { 0x80f5fd, 0x01 },
1070 { 0x80f600, 0x05 },
1071 { 0x80f601, 0x08 },
1072 { 0x80f602, 0x0b },
1073 { 0x80f603, 0x0e },
1074 { 0x80f604, 0x11 },
1075 { 0x80f605, 0x14 },
1076 { 0x80f606, 0x17 },
1077 { 0x80f607, 0x1f },
1078 { 0x80f60e, 0x00 },
1079 { 0x80f60f, 0x04 },
1080 { 0x80f610, 0x32 },
1081 { 0x80f611, 0x10 },
1082 { 0x80f707, 0xfc },
1083 { 0x80f708, 0x00 },
1084 { 0x80f709, 0x37 },
1085 { 0x80f70a, 0x00 },
1086 { 0x80f78b, 0x01 },
1087 { 0x80f80f, 0x40 },
1088 { 0x80f810, 0x54 },
1089 { 0x80f811, 0x5a },
1090 { 0x80f905, 0x01 },
1091 { 0x80fb06, 0x03 },
1092 { 0x80fd8b, 0x00 },
1093};
1094
1095/* ITE Tech IT9135 Omega LNA config 2 tuner init
1096 AF9033_TUNER_IT9135_52 = 0x52 */
1097static const struct reg_val tuner_init_it9135_52[] = {
1098 { 0x800043, 0x00 },
1099 { 0x800046, 0x52 },
1100 { 0x800051, 0x01 },
1101 { 0x80005f, 0x00 },
1102 { 0x800060, 0x00 },
1103 { 0x800068, 0x10 },
1104 { 0x800070, 0x0a },
1105 { 0x800071, 0x05 },
1106 { 0x800072, 0x02 },
1107 { 0x800075, 0x8c },
1108 { 0x800076, 0x8c },
1109 { 0x800077, 0x8c },
1110 { 0x800078, 0xa0 },
1111 { 0x800079, 0x01 },
1112 { 0x80007e, 0x04 },
1113 { 0x80007f, 0x00 },
1114 { 0x800081, 0x0a },
1115 { 0x800082, 0x17 },
1116 { 0x800083, 0x03 },
1117 { 0x800084, 0x0a },
1118 { 0x800085, 0x03 },
1119 { 0x800086, 0xb3 },
1120 { 0x800087, 0x97 },
1121 { 0x800088, 0xc0 },
1122 { 0x800089, 0x9e },
1123 { 0x80008a, 0x01 },
1124 { 0x80008e, 0x01 },
1125 { 0x800092, 0x06 },
1126 { 0x800093, 0x00 },
1127 { 0x800094, 0x00 },
1128 { 0x800095, 0x00 },
1129 { 0x800096, 0x00 },
1130 { 0x800099, 0x01 },
1131 { 0x80009b, 0x3c },
1132 { 0x80009c, 0x28 },
1133 { 0x80009f, 0xe1 },
1134 { 0x8000a0, 0xcf },
1135 { 0x8000a3, 0x01 },
1136 { 0x8000a4, 0x5c },
1137 { 0x8000a5, 0x01 },
1138 { 0x8000a6, 0x01 },
1139 { 0x8000a9, 0x00 },
1140 { 0x8000aa, 0x01 },
1141 { 0x8000b0, 0x01 },
1142 { 0x8000b3, 0x02 },
1143 { 0x8000b4, 0x3c },
1144 { 0x8000b6, 0x14 },
1145 { 0x8000c0, 0x11 },
1146 { 0x8000c1, 0x00 },
1147 { 0x8000c2, 0x05 },
1148 { 0x8000c4, 0x00 },
1149 { 0x8000c6, 0x19 },
1150 { 0x8000c7, 0x00 },
1151 { 0x8000cc, 0x2e },
1152 { 0x8000cd, 0x51 },
1153 { 0x8000ce, 0x33 },
1154 { 0x8000f3, 0x05 },
1155 { 0x8000f4, 0x91 },
1156 { 0x8000f5, 0x8c },
1157 { 0x8000f8, 0x03 },
1158 { 0x8000f9, 0x06 },
1159 { 0x8000fa, 0x06 },
1160 { 0x8000fc, 0x03 },
1161 { 0x8000fd, 0x02 },
1162 { 0x8000fe, 0x02 },
1163 { 0x8000ff, 0x09 },
1164 { 0x800100, 0x50 },
1165 { 0x800101, 0x74 },
1166 { 0x800102, 0x77 },
1167 { 0x800103, 0x02 },
1168 { 0x800104, 0x02 },
1169 { 0x800105, 0xa4 },
1170 { 0x800106, 0x02 },
1171 { 0x800107, 0x6e },
1172 { 0x800109, 0x02 },
1173 { 0x800115, 0x0a },
1174 { 0x800116, 0x03 },
1175 { 0x800117, 0x02 },
1176 { 0x800118, 0x80 },
1177 { 0x80011a, 0xcd },
1178 { 0x80011b, 0x62 },
1179 { 0x80011c, 0xa4 },
1180 { 0x80011d, 0x8c },
1181 { 0x800122, 0x03 },
1182 { 0x800123, 0x18 },
1183 { 0x800124, 0x9e },
1184 { 0x800127, 0x00 },
1185 { 0x800128, 0x07 },
1186 { 0x80012a, 0x53 },
1187 { 0x80012b, 0x51 },
1188 { 0x80012c, 0x4e },
1189 { 0x80012d, 0x43 },
1190 { 0x800137, 0x00 },
1191 { 0x800138, 0x00 },
1192 { 0x800139, 0x07 },
1193 { 0x80013a, 0x00 },
1194 { 0x80013b, 0x06 },
1195 { 0x80013d, 0x00 },
1196 { 0x80013e, 0x01 },
1197 { 0x80013f, 0x5b },
1198 { 0x800140, 0xb6 },
1199 { 0x800141, 0x59 },
1200 { 0x80f000, 0x0f },
1201 { 0x80f016, 0x10 },
1202 { 0x80f017, 0x04 },
1203 { 0x80f018, 0x05 },
1204 { 0x80f019, 0x04 },
1205 { 0x80f01a, 0x05 },
1206 { 0x80f01f, 0x8c },
1207 { 0x80f020, 0x00 },
1208 { 0x80f021, 0x03 },
1209 { 0x80f022, 0x0a },
1210 { 0x80f023, 0x0a },
1211 { 0x80f029, 0x8c },
1212 { 0x80f02a, 0x00 },
1213 { 0x80f02b, 0x00 },
1214 { 0x80f02c, 0x01 },
1215 { 0x80f064, 0x03 },
1216 { 0x80f065, 0xf9 },
1217 { 0x80f066, 0x03 },
1218 { 0x80f067, 0x01 },
1219 { 0x80f06f, 0xe0 },
1220 { 0x80f070, 0x03 },
1221 { 0x80f072, 0x0f },
1222 { 0x80f073, 0x03 },
1223 { 0x80f077, 0x01 },
1224 { 0x80f078, 0x00 },
1225 { 0x80f085, 0xc0 },
1226 { 0x80f086, 0x01 },
1227 { 0x80f087, 0x00 },
1228 { 0x80f09b, 0x3f },
1229 { 0x80f09c, 0x00 },
1230 { 0x80f09d, 0x20 },
1231 { 0x80f09e, 0x00 },
1232 { 0x80f09f, 0x0c },
1233 { 0x80f0a0, 0x00 },
1234 { 0x80f130, 0x04 },
1235 { 0x80f132, 0x04 },
1236 { 0x80f144, 0x1a },
1237 { 0x80f146, 0x00 },
1238 { 0x80f14a, 0x01 },
1239 { 0x80f14c, 0x00 },
1240 { 0x80f14d, 0x00 },
1241 { 0x80f14f, 0x04 },
1242 { 0x80f158, 0x7f },
1243 { 0x80f15a, 0x00 },
1244 { 0x80f15b, 0x08 },
1245 { 0x80f15d, 0x03 },
1246 { 0x80f15e, 0x05 },
1247 { 0x80f163, 0x05 },
1248 { 0x80f166, 0x01 },
1249 { 0x80f167, 0x40 },
1250 { 0x80f168, 0x0f },
1251 { 0x80f17a, 0x00 },
1252 { 0x80f17b, 0x00 },
1253 { 0x80f183, 0x01 },
1254 { 0x80f19d, 0x40 },
1255 { 0x80f1bc, 0x36 },
1256 { 0x80f1bd, 0x00 },
1257 { 0x80f1cb, 0xa0 },
1258 { 0x80f1cc, 0x01 },
1259 { 0x80f204, 0x10 },
1260 { 0x80f214, 0x00 },
1261 { 0x80f24c, 0x88 },
1262 { 0x80f24d, 0x95 },
1263 { 0x80f24e, 0x9a },
1264 { 0x80f24f, 0x90 },
1265 { 0x80f25a, 0x07 },
1266 { 0x80f25b, 0xe8 },
1267 { 0x80f25c, 0x03 },
1268 { 0x80f25d, 0xb0 },
1269 { 0x80f25e, 0x04 },
1270 { 0x80f270, 0x01 },
1271 { 0x80f271, 0x02 },
1272 { 0x80f272, 0x01 },
1273 { 0x80f273, 0x02 },
1274 { 0x80f40e, 0x0a },
1275 { 0x80f40f, 0x40 },
1276 { 0x80f410, 0x08 },
1277 { 0x80f55f, 0x0a },
1278 { 0x80f561, 0x15 },
1279 { 0x80f562, 0x20 },
1280 { 0x80f5df, 0xfb },
1281 { 0x80f5e0, 0x00 },
1282 { 0x80f5e3, 0x09 },
1283 { 0x80f5e4, 0x01 },
1284 { 0x80f5e5, 0x01 },
1285 { 0x80f5f8, 0x01 },
1286 { 0x80f5fd, 0x01 },
1287 { 0x80f600, 0x05 },
1288 { 0x80f601, 0x08 },
1289 { 0x80f602, 0x0b },
1290 { 0x80f603, 0x0e },
1291 { 0x80f604, 0x11 },
1292 { 0x80f605, 0x14 },
1293 { 0x80f606, 0x17 },
1294 { 0x80f607, 0x1f },
1295 { 0x80f60e, 0x00 },
1296 { 0x80f60f, 0x04 },
1297 { 0x80f610, 0x32 },
1298 { 0x80f611, 0x10 },
1299 { 0x80f707, 0xfc },
1300 { 0x80f708, 0x00 },
1301 { 0x80f709, 0x37 },
1302 { 0x80f70a, 0x00 },
1303 { 0x80f78b, 0x01 },
1304 { 0x80f80f, 0x40 },
1305 { 0x80f810, 0x54 },
1306 { 0x80f811, 0x5a },
1307 { 0x80f905, 0x01 },
1308 { 0x80fb06, 0x03 },
1309 { 0x80fd8b, 0x00 },
1310};
1311
1312static const struct reg_val ofsm_init_it9135_v2[] = {
1313 { 0x800051, 0x01 },
1314 { 0x800070, 0x0a },
1315 { 0x80007e, 0x04 },
1316 { 0x800081, 0x0a },
1317 { 0x80008a, 0x01 },
1318 { 0x80008e, 0x01 },
1319 { 0x800092, 0x06 },
1320 { 0x800099, 0x01 },
1321 { 0x80009f, 0xe1 },
1322 { 0x8000a0, 0xcf },
1323 { 0x8000a3, 0x01 },
1324 { 0x8000a5, 0x01 },
1325 { 0x8000a6, 0x01 },
1326 { 0x8000a9, 0x00 },
1327 { 0x8000aa, 0x01 },
1328 { 0x8000b0, 0x01 },
1329 { 0x8000c2, 0x05 },
1330 { 0x8000c6, 0x19 },
1331 { 0x80f000, 0x0f },
1332 { 0x80f02b, 0x00 },
1333 { 0x80f064, 0x03 },
1334 { 0x80f065, 0xf9 },
1335 { 0x80f066, 0x03 },
1336 { 0x80f067, 0x01 },
1337 { 0x80f06f, 0xe0 },
1338 { 0x80f070, 0x03 },
1339 { 0x80f072, 0x0f },
1340 { 0x80f073, 0x03 },
1341 { 0x80f078, 0x00 },
1342 { 0x80f087, 0x00 },
1343 { 0x80f09b, 0x3f },
1344 { 0x80f09c, 0x00 },
1345 { 0x80f09d, 0x20 },
1346 { 0x80f09e, 0x00 },
1347 { 0x80f09f, 0x0c },
1348 { 0x80f0a0, 0x00 },
1349 { 0x80f130, 0x04 },
1350 { 0x80f132, 0x04 },
1351 { 0x80f144, 0x1a },
1352 { 0x80f146, 0x00 },
1353 { 0x80f14a, 0x01 },
1354 { 0x80f14c, 0x00 },
1355 { 0x80f14d, 0x00 },
1356 { 0x80f14f, 0x04 },
1357 { 0x80f158, 0x7f },
1358 { 0x80f15a, 0x00 },
1359 { 0x80f15b, 0x08 },
1360 { 0x80f15d, 0x03 },
1361 { 0x80f15e, 0x05 },
1362 { 0x80f163, 0x05 },
1363 { 0x80f166, 0x01 },
1364 { 0x80f167, 0x40 },
1365 { 0x80f168, 0x0f },
1366 { 0x80f17a, 0x00 },
1367 { 0x80f17b, 0x00 },
1368 { 0x80f183, 0x01 },
1369 { 0x80f19d, 0x40 },
1370 { 0x80f1bc, 0x36 },
1371 { 0x80f1bd, 0x00 },
1372 { 0x80f1cb, 0xa0 },
1373 { 0x80f1cc, 0x01 },
1374 { 0x80f204, 0x10 },
1375 { 0x80f214, 0x00 },
1376 { 0x80f40e, 0x0a },
1377 { 0x80f40f, 0x40 },
1378 { 0x80f410, 0x08 },
1379 { 0x80f55f, 0x0a },
1380 { 0x80f561, 0x15 },
1381 { 0x80f562, 0x20 },
1382 { 0x80f5e3, 0x09 },
1383 { 0x80f5e4, 0x01 },
1384 { 0x80f5e5, 0x01 },
1385 { 0x80f600, 0x05 },
1386 { 0x80f601, 0x08 },
1387 { 0x80f602, 0x0b },
1388 { 0x80f603, 0x0e },
1389 { 0x80f604, 0x11 },
1390 { 0x80f605, 0x14 },
1391 { 0x80f606, 0x17 },
1392 { 0x80f607, 0x1f },
1393 { 0x80f60e, 0x00 },
1394 { 0x80f60f, 0x04 },
1395 { 0x80f610, 0x32 },
1396 { 0x80f611, 0x10 },
1397 { 0x80f707, 0xfc },
1398 { 0x80f708, 0x00 },
1399 { 0x80f709, 0x37 },
1400 { 0x80f70a, 0x00 },
1401 { 0x80f78b, 0x01 },
1402 { 0x80f80f, 0x40 },
1403 { 0x80f810, 0x54 },
1404 { 0x80f811, 0x5a },
1405 { 0x80f905, 0x01 },
1406 { 0x80fb06, 0x03 },
1407 { 0x80fd8b, 0x00 },
1408};
1409
1410/* ITE Tech IT9135 Omega v2 tuner init
1411 AF9033_TUNER_IT9135_60 = 0x60 */
1412static const struct reg_val tuner_init_it9135_60[] = {
1413 { 0x800043, 0x00 },
1414 { 0x800046, 0x60 },
1415 { 0x800051, 0x01 },
1416 { 0x80005f, 0x00 },
1417 { 0x800060, 0x00 },
1418 { 0x800068, 0x0a },
1419 { 0x80006a, 0x03 },
1420 { 0x800070, 0x0a },
1421 { 0x800071, 0x05 },
1422 { 0x800072, 0x02 },
1423 { 0x800075, 0x8c },
1424 { 0x800076, 0x8c },
1425 { 0x800077, 0x8c },
1426 { 0x800078, 0x8c },
1427 { 0x800079, 0x01 },
1428 { 0x80007e, 0x04 },
1429 { 0x800081, 0x0a },
1430 { 0x800082, 0x18 },
1431 { 0x800084, 0x0a },
1432 { 0x800085, 0x33 },
1433 { 0x800086, 0xbe },
1434 { 0x800087, 0xa0 },
1435 { 0x800088, 0xc6 },
1436 { 0x800089, 0xb6 },
1437 { 0x80008a, 0x01 },
1438 { 0x80008e, 0x01 },
1439 { 0x800092, 0x06 },
1440 { 0x800093, 0x00 },
1441 { 0x800094, 0x00 },
1442 { 0x800095, 0x00 },
1443 { 0x800096, 0x00 },
1444 { 0x800099, 0x01 },
1445 { 0x80009b, 0x3c },
1446 { 0x80009c, 0x28 },
1447 { 0x80009f, 0xe1 },
1448 { 0x8000a0, 0xcf },
1449 { 0x8000a3, 0x01 },
1450 { 0x8000a4, 0x5a },
1451 { 0x8000a5, 0x01 },
1452 { 0x8000a6, 0x01 },
1453 { 0x8000a9, 0x00 },
1454 { 0x8000aa, 0x01 },
1455 { 0x8000b0, 0x01 },
1456 { 0x8000b3, 0x02 },
1457 { 0x8000b4, 0x3a },
1458 { 0x8000b6, 0x14 },
1459 { 0x8000c0, 0x11 },
1460 { 0x8000c1, 0x00 },
1461 { 0x8000c2, 0x05 },
1462 { 0x8000c3, 0x01 },
1463 { 0x8000c4, 0x00 },
1464 { 0x8000c6, 0x19 },
1465 { 0x8000c7, 0x00 },
1466 { 0x8000cb, 0x32 },
1467 { 0x8000cc, 0x2c },
1468 { 0x8000cd, 0x4f },
1469 { 0x8000ce, 0x30 },
1470 { 0x8000f3, 0x05 },
1471 { 0x8000f4, 0xa0 },
1472 { 0x8000f5, 0x8c },
1473 { 0x8000f8, 0x03 },
1474 { 0x8000f9, 0x06 },
1475 { 0x8000fa, 0x06 },
1476 { 0x8000fc, 0x03 },
1477 { 0x8000fd, 0x03 },
1478 { 0x8000fe, 0x02 },
1479 { 0x8000ff, 0x0a },
1480 { 0x800100, 0x50 },
1481 { 0x800101, 0x7b },
1482 { 0x800102, 0x8c },
1483 { 0x800103, 0x00 },
1484 { 0x800104, 0x02 },
1485 { 0x800105, 0xbe },
1486 { 0x800106, 0x00 },
1487 { 0x800109, 0x02 },
1488 { 0x800115, 0x0a },
1489 { 0x800116, 0x03 },
1490 { 0x80011a, 0xbe },
1491 { 0x800124, 0xae },
1492 { 0x800127, 0x00 },
1493 { 0x80012a, 0x56 },
1494 { 0x80012b, 0x50 },
1495 { 0x80012c, 0x47 },
1496 { 0x80012d, 0x42 },
1497 { 0x800137, 0x00 },
1498 { 0x80013b, 0x08 },
1499 { 0x80013f, 0x5b },
1500 { 0x800141, 0x59 },
1501 { 0x800142, 0xf9 },
1502 { 0x800143, 0x19 },
1503 { 0x800144, 0x00 },
1504 { 0x800145, 0x8c },
1505 { 0x800146, 0x8c },
1506 { 0x800147, 0x8c },
1507 { 0x800148, 0x6e },
1508 { 0x800149, 0x8c },
1509 { 0x80014a, 0x50 },
1510 { 0x80014b, 0x8c },
1511 { 0x80014d, 0xac },
1512 { 0x80014e, 0xc6 },
1513 { 0x80014f, 0x03 },
1514 { 0x800151, 0x1e },
1515 { 0x800153, 0xbc },
1516 { 0x800178, 0x09 },
1517 { 0x800181, 0x94 },
1518 { 0x800182, 0x6e },
1519 { 0x800185, 0x24 },
1520 { 0x800189, 0xbe },
1521 { 0x80018c, 0x03 },
1522 { 0x80018d, 0x5f },
1523 { 0x80018f, 0xa0 },
1524 { 0x800190, 0x5a },
1525 { 0x80ed02, 0xff },
1526 { 0x80ee42, 0xff },
1527 { 0x80ee82, 0xff },
1528 { 0x80f000, 0x0f },
1529 { 0x80f01f, 0x8c },
1530 { 0x80f020, 0x00 },
1531 { 0x80f029, 0x8c },
1532 { 0x80f02a, 0x00 },
1533 { 0x80f02b, 0x00 },
1534 { 0x80f064, 0x03 },
1535 { 0x80f065, 0xf9 },
1536 { 0x80f066, 0x03 },
1537 { 0x80f067, 0x01 },
1538 { 0x80f06f, 0xe0 },
1539 { 0x80f070, 0x03 },
1540 { 0x80f072, 0x0f },
1541 { 0x80f073, 0x03 },
1542 { 0x80f077, 0x01 },
1543 { 0x80f078, 0x00 },
1544 { 0x80f087, 0x00 },
1545 { 0x80f09b, 0x3f },
1546 { 0x80f09c, 0x00 },
1547 { 0x80f09d, 0x20 },
1548 { 0x80f09e, 0x00 },
1549 { 0x80f09f, 0x0c },
1550 { 0x80f0a0, 0x00 },
1551 { 0x80f130, 0x04 },
1552 { 0x80f132, 0x04 },
1553 { 0x80f144, 0x1a },
1554 { 0x80f146, 0x00 },
1555 { 0x80f14a, 0x01 },
1556 { 0x80f14c, 0x00 },
1557 { 0x80f14d, 0x00 },
1558 { 0x80f14f, 0x04 },
1559 { 0x80f158, 0x7f },
1560 { 0x80f15a, 0x00 },
1561 { 0x80f15b, 0x08 },
1562 { 0x80f15d, 0x03 },
1563 { 0x80f15e, 0x05 },
1564 { 0x80f163, 0x05 },
1565 { 0x80f166, 0x01 },
1566 { 0x80f167, 0x40 },
1567 { 0x80f168, 0x0f },
1568 { 0x80f17a, 0x00 },
1569 { 0x80f17b, 0x00 },
1570 { 0x80f183, 0x01 },
1571 { 0x80f19d, 0x40 },
1572 { 0x80f1bc, 0x36 },
1573 { 0x80f1bd, 0x00 },
1574 { 0x80f1cb, 0xa0 },
1575 { 0x80f1cc, 0x01 },
1576 { 0x80f204, 0x10 },
1577 { 0x80f214, 0x00 },
1578 { 0x80f24c, 0x88 },
1579 { 0x80f24d, 0x95 },
1580 { 0x80f24e, 0x9a },
1581 { 0x80f24f, 0x90 },
1582 { 0x80f25a, 0x07 },
1583 { 0x80f25b, 0xe8 },
1584 { 0x80f25c, 0x03 },
1585 { 0x80f25d, 0xb0 },
1586 { 0x80f25e, 0x04 },
1587 { 0x80f270, 0x01 },
1588 { 0x80f271, 0x02 },
1589 { 0x80f272, 0x01 },
1590 { 0x80f273, 0x02 },
1591 { 0x80f40e, 0x0a },
1592 { 0x80f40f, 0x40 },
1593 { 0x80f410, 0x08 },
1594 { 0x80f55f, 0x0a },
1595 { 0x80f561, 0x15 },
1596 { 0x80f562, 0x20 },
1597 { 0x80f5e3, 0x09 },
1598 { 0x80f5e4, 0x01 },
1599 { 0x80f5e5, 0x01 },
1600 { 0x80f600, 0x05 },
1601 { 0x80f601, 0x08 },
1602 { 0x80f602, 0x0b },
1603 { 0x80f603, 0x0e },
1604 { 0x80f604, 0x11 },
1605 { 0x80f605, 0x14 },
1606 { 0x80f606, 0x17 },
1607 { 0x80f607, 0x1f },
1608 { 0x80f60e, 0x00 },
1609 { 0x80f60f, 0x04 },
1610 { 0x80f610, 0x32 },
1611 { 0x80f611, 0x10 },
1612 { 0x80f707, 0xfc },
1613 { 0x80f708, 0x00 },
1614 { 0x80f709, 0x37 },
1615 { 0x80f70a, 0x00 },
1616 { 0x80f78b, 0x01 },
1617 { 0x80f80f, 0x40 },
1618 { 0x80f810, 0x54 },
1619 { 0x80f811, 0x5a },
1620 { 0x80f905, 0x01 },
1621 { 0x80fb06, 0x03 },
1622 { 0x80fd8b, 0x00 },
1623};
551 1624
1625/* ITE Tech IT9135 Omega v2 LNA config 1 tuner init
1626 AF9033_TUNER_IT9135_61 = 0x61 */
1627static const struct reg_val tuner_init_it9135_61[] = {
1628 { 0x800043, 0x00 },
1629 { 0x800046, 0x61 },
1630 { 0x800051, 0x01 },
1631 { 0x80005f, 0x00 },
1632 { 0x800060, 0x00 },
1633 { 0x800068, 0x06 },
1634 { 0x80006a, 0x03 },
1635 { 0x800070, 0x0a },
1636 { 0x800071, 0x05 },
1637 { 0x800072, 0x02 },
1638 { 0x800075, 0x8c },
1639 { 0x800076, 0x8c },
1640 { 0x800077, 0x8c },
1641 { 0x800078, 0x90 },
1642 { 0x800079, 0x01 },
1643 { 0x80007e, 0x04 },
1644 { 0x800081, 0x0a },
1645 { 0x800082, 0x12 },
1646 { 0x800084, 0x0a },
1647 { 0x800085, 0x33 },
1648 { 0x800086, 0xbc },
1649 { 0x800087, 0x9c },
1650 { 0x800088, 0xcc },
1651 { 0x800089, 0xa8 },
1652 { 0x80008a, 0x01 },
1653 { 0x80008e, 0x01 },
1654 { 0x800092, 0x06 },
1655 { 0x800093, 0x00 },
1656 { 0x800094, 0x00 },
1657 { 0x800095, 0x00 },
1658 { 0x800096, 0x00 },
1659 { 0x800099, 0x01 },
1660 { 0x80009b, 0x3c },
1661 { 0x80009c, 0x28 },
1662 { 0x80009f, 0xe1 },
1663 { 0x8000a0, 0xcf },
1664 { 0x8000a3, 0x01 },
1665 { 0x8000a4, 0x5c },
1666 { 0x8000a5, 0x01 },
1667 { 0x8000a6, 0x01 },
1668 { 0x8000a9, 0x00 },
1669 { 0x8000aa, 0x01 },
1670 { 0x8000b0, 0x01 },
1671 { 0x8000b3, 0x02 },
1672 { 0x8000b4, 0x3a },
1673 { 0x8000b6, 0x14 },
1674 { 0x8000c0, 0x11 },
1675 { 0x8000c1, 0x00 },
1676 { 0x8000c2, 0x05 },
1677 { 0x8000c3, 0x01 },
1678 { 0x8000c4, 0x00 },
1679 { 0x8000c6, 0x19 },
1680 { 0x8000c7, 0x00 },
1681 { 0x8000cb, 0x32 },
1682 { 0x8000cc, 0x2c },
1683 { 0x8000cd, 0x4f },
1684 { 0x8000ce, 0x30 },
1685 { 0x8000f3, 0x05 },
1686 { 0x8000f4, 0xa0 },
1687 { 0x8000f5, 0x8c },
1688 { 0x8000f8, 0x03 },
1689 { 0x8000f9, 0x06 },
1690 { 0x8000fa, 0x06 },
1691 { 0x8000fc, 0x03 },
1692 { 0x8000fd, 0x03 },
1693 { 0x8000fe, 0x02 },
1694 { 0x8000ff, 0x08 },
1695 { 0x800100, 0x50 },
1696 { 0x800101, 0x7b },
1697 { 0x800102, 0x8c },
1698 { 0x800103, 0x01 },
1699 { 0x800104, 0x02 },
1700 { 0x800105, 0xc8 },
1701 { 0x800106, 0x00 },
1702 { 0x800109, 0x02 },
1703 { 0x800115, 0x0a },
1704 { 0x800116, 0x03 },
1705 { 0x80011a, 0xc6 },
1706 { 0x800124, 0xa8 },
1707 { 0x800127, 0x00 },
1708 { 0x80012a, 0x59 },
1709 { 0x80012b, 0x50 },
1710 { 0x80012c, 0x47 },
1711 { 0x80012d, 0x42 },
1712 { 0x800137, 0x00 },
1713 { 0x80013b, 0x05 },
1714 { 0x80013f, 0x5b },
1715 { 0x800141, 0x59 },
1716 { 0x800142, 0xf9 },
1717 { 0x800143, 0x59 },
1718 { 0x800144, 0x01 },
1719 { 0x800145, 0x8c },
1720 { 0x800146, 0x8c },
1721 { 0x800147, 0x8c },
1722 { 0x800148, 0x7b },
1723 { 0x800149, 0x8c },
1724 { 0x80014a, 0x50 },
1725 { 0x80014b, 0x8c },
1726 { 0x80014d, 0xa8 },
1727 { 0x80014e, 0xc6 },
1728 { 0x80014f, 0x03 },
1729 { 0x800151, 0x28 },
1730 { 0x800153, 0xcc },
1731 { 0x800178, 0x09 },
1732 { 0x800181, 0x9c },
1733 { 0x800182, 0x76 },
1734 { 0x800185, 0x28 },
1735 { 0x800189, 0xaa },
1736 { 0x80018c, 0x03 },
1737 { 0x80018d, 0x5f },
1738 { 0x80018f, 0xfb },
1739 { 0x800190, 0x5c },
1740 { 0x80ed02, 0xff },
1741 { 0x80ee42, 0xff },
1742 { 0x80ee82, 0xff },
1743 { 0x80f000, 0x0f },
1744 { 0x80f01f, 0x8c },
1745 { 0x80f020, 0x00 },
1746 { 0x80f029, 0x8c },
1747 { 0x80f02a, 0x00 },
1748 { 0x80f02b, 0x00 },
1749 { 0x80f064, 0x03 },
1750 { 0x80f065, 0xf9 },
1751 { 0x80f066, 0x03 },
1752 { 0x80f067, 0x01 },
1753 { 0x80f06f, 0xe0 },
1754 { 0x80f070, 0x03 },
1755 { 0x80f072, 0x0f },
1756 { 0x80f073, 0x03 },
1757 { 0x80f077, 0x01 },
1758 { 0x80f078, 0x00 },
1759 { 0x80f087, 0x00 },
1760 { 0x80f09b, 0x3f },
1761 { 0x80f09c, 0x00 },
1762 { 0x80f09d, 0x20 },
1763 { 0x80f09e, 0x00 },
1764 { 0x80f09f, 0x0c },
1765 { 0x80f0a0, 0x00 },
1766 { 0x80f130, 0x04 },
1767 { 0x80f132, 0x04 },
1768 { 0x80f144, 0x1a },
1769 { 0x80f146, 0x00 },
1770 { 0x80f14a, 0x01 },
1771 { 0x80f14c, 0x00 },
1772 { 0x80f14d, 0x00 },
1773 { 0x80f14f, 0x04 },
1774 { 0x80f158, 0x7f },
1775 { 0x80f15a, 0x00 },
1776 { 0x80f15b, 0x08 },
1777 { 0x80f15d, 0x03 },
1778 { 0x80f15e, 0x05 },
1779 { 0x80f163, 0x05 },
1780 { 0x80f166, 0x01 },
1781 { 0x80f167, 0x40 },
1782 { 0x80f168, 0x0f },
1783 { 0x80f17a, 0x00 },
1784 { 0x80f17b, 0x00 },
1785 { 0x80f183, 0x01 },
1786 { 0x80f19d, 0x40 },
1787 { 0x80f1bc, 0x36 },
1788 { 0x80f1bd, 0x00 },
1789 { 0x80f1cb, 0xa0 },
1790 { 0x80f1cc, 0x01 },
1791 { 0x80f204, 0x10 },
1792 { 0x80f214, 0x00 },
1793 { 0x80f24c, 0x88 },
1794 { 0x80f24d, 0x95 },
1795 { 0x80f24e, 0x9a },
1796 { 0x80f24f, 0x90 },
1797 { 0x80f25a, 0x07 },
1798 { 0x80f25b, 0xe8 },
1799 { 0x80f25c, 0x03 },
1800 { 0x80f25d, 0xb0 },
1801 { 0x80f25e, 0x04 },
1802 { 0x80f270, 0x01 },
1803 { 0x80f271, 0x02 },
1804 { 0x80f272, 0x01 },
1805 { 0x80f273, 0x02 },
1806 { 0x80f40e, 0x0a },
1807 { 0x80f40f, 0x40 },
1808 { 0x80f410, 0x08 },
1809 { 0x80f55f, 0x0a },
1810 { 0x80f561, 0x15 },
1811 { 0x80f562, 0x20 },
1812 { 0x80f5e3, 0x09 },
1813 { 0x80f5e4, 0x01 },
1814 { 0x80f5e5, 0x01 },
1815 { 0x80f600, 0x05 },
1816 { 0x80f601, 0x08 },
1817 { 0x80f602, 0x0b },
1818 { 0x80f603, 0x0e },
1819 { 0x80f604, 0x11 },
1820 { 0x80f605, 0x14 },
1821 { 0x80f606, 0x17 },
1822 { 0x80f607, 0x1f },
1823 { 0x80f60e, 0x00 },
1824 { 0x80f60f, 0x04 },
1825 { 0x80f610, 0x32 },
1826 { 0x80f611, 0x10 },
1827 { 0x80f707, 0xfc },
1828 { 0x80f708, 0x00 },
1829 { 0x80f709, 0x37 },
1830 { 0x80f70a, 0x00 },
1831 { 0x80f78b, 0x01 },
1832 { 0x80f80f, 0x40 },
1833 { 0x80f810, 0x54 },
1834 { 0x80f811, 0x5a },
1835 { 0x80f905, 0x01 },
1836 { 0x80fb06, 0x03 },
1837 { 0x80fd8b, 0x00 },
1838};
1839
1840/* ITE Tech IT9135 Omega v2 LNA config 2 tuner init
1841 AF9033_TUNER_IT9135_62 = 0x62 */
1842static const struct reg_val tuner_init_it9135_62[] = {
1843 { 0x800043, 0x00 },
1844 { 0x800046, 0x62 },
1845 { 0x800051, 0x01 },
1846 { 0x80005f, 0x00 },
1847 { 0x800060, 0x00 },
1848 { 0x800068, 0x0a },
1849 { 0x80006a, 0x03 },
1850 { 0x800070, 0x0a },
1851 { 0x800071, 0x05 },
1852 { 0x800072, 0x02 },
1853 { 0x800075, 0x8c },
1854 { 0x800076, 0x8c },
1855 { 0x800077, 0x8c },
1856 { 0x800078, 0x8c },
1857 { 0x800079, 0x01 },
1858 { 0x80007e, 0x04 },
1859 { 0x800081, 0x0a },
1860 { 0x800082, 0x12 },
1861 { 0x800084, 0x0a },
1862 { 0x800085, 0x33 },
1863 { 0x800086, 0xb8 },
1864 { 0x800087, 0x9c },
1865 { 0x800088, 0xb2 },
1866 { 0x800089, 0xa6 },
1867 { 0x80008a, 0x01 },
1868 { 0x80008e, 0x01 },
1869 { 0x800092, 0x06 },
1870 { 0x800093, 0x00 },
1871 { 0x800094, 0x00 },
1872 { 0x800095, 0x00 },
1873 { 0x800096, 0x00 },
1874 { 0x800099, 0x01 },
1875 { 0x80009b, 0x3c },
1876 { 0x80009c, 0x28 },
1877 { 0x80009f, 0xe1 },
1878 { 0x8000a0, 0xcf },
1879 { 0x8000a3, 0x01 },
1880 { 0x8000a4, 0x5a },
1881 { 0x8000a5, 0x01 },
1882 { 0x8000a6, 0x01 },
1883 { 0x8000a9, 0x00 },
1884 { 0x8000aa, 0x01 },
1885 { 0x8000b0, 0x01 },
1886 { 0x8000b3, 0x02 },
1887 { 0x8000b4, 0x3a },
1888 { 0x8000b6, 0x14 },
1889 { 0x8000c0, 0x11 },
1890 { 0x8000c1, 0x00 },
1891 { 0x8000c2, 0x05 },
1892 { 0x8000c3, 0x01 },
1893 { 0x8000c4, 0x00 },
1894 { 0x8000c6, 0x19 },
1895 { 0x8000c7, 0x00 },
1896 { 0x8000cb, 0x32 },
1897 { 0x8000cc, 0x2c },
1898 { 0x8000cd, 0x4f },
1899 { 0x8000ce, 0x30 },
1900 { 0x8000f3, 0x05 },
1901 { 0x8000f4, 0x8c },
1902 { 0x8000f5, 0x8c },
1903 { 0x8000f8, 0x03 },
1904 { 0x8000f9, 0x06 },
1905 { 0x8000fa, 0x06 },
1906 { 0x8000fc, 0x02 },
1907 { 0x8000fd, 0x03 },
1908 { 0x8000fe, 0x02 },
1909 { 0x8000ff, 0x09 },
1910 { 0x800100, 0x50 },
1911 { 0x800101, 0x6e },
1912 { 0x800102, 0x8c },
1913 { 0x800103, 0x02 },
1914 { 0x800104, 0x02 },
1915 { 0x800105, 0xc2 },
1916 { 0x800106, 0x00 },
1917 { 0x800109, 0x02 },
1918 { 0x800115, 0x0a },
1919 { 0x800116, 0x03 },
1920 { 0x80011a, 0xb8 },
1921 { 0x800124, 0xa8 },
1922 { 0x800127, 0x00 },
1923 { 0x80012a, 0x53 },
1924 { 0x80012b, 0x51 },
1925 { 0x80012c, 0x4e },
1926 { 0x80012d, 0x43 },
1927 { 0x800137, 0x00 },
1928 { 0x80013b, 0x05 },
1929 { 0x80013f, 0x5b },
1930 { 0x800141, 0x59 },
1931 { 0x800142, 0xf9 },
1932 { 0x800143, 0x59 },
1933 { 0x800144, 0x00 },
1934 { 0x800145, 0x8c },
1935 { 0x800146, 0x8c },
1936 { 0x800147, 0x8c },
1937 { 0x800148, 0x7b },
1938 { 0x800149, 0x8c },
1939 { 0x80014a, 0x50 },
1940 { 0x80014b, 0x70 },
1941 { 0x80014d, 0x96 },
1942 { 0x80014e, 0xd0 },
1943 { 0x80014f, 0x03 },
1944 { 0x800151, 0x28 },
1945 { 0x800153, 0xb2 },
1946 { 0x800178, 0x09 },
1947 { 0x800181, 0x9c },
1948 { 0x800182, 0x6e },
1949 { 0x800185, 0x24 },
1950 { 0x800189, 0xb8 },
1951 { 0x80018c, 0x03 },
1952 { 0x80018d, 0x5f },
1953 { 0x80018f, 0xfb },
1954 { 0x800190, 0x5a },
1955 { 0x80ed02, 0xff },
1956 { 0x80ee42, 0xff },
1957 { 0x80ee82, 0xff },
1958 { 0x80f000, 0x0f },
1959 { 0x80f01f, 0x8c },
1960 { 0x80f020, 0x00 },
1961 { 0x80f029, 0x8c },
1962 { 0x80f02a, 0x00 },
1963 { 0x80f02b, 0x00 },
1964 { 0x80f064, 0x03 },
1965 { 0x80f065, 0xf9 },
1966 { 0x80f066, 0x03 },
1967 { 0x80f067, 0x01 },
1968 { 0x80f06f, 0xe0 },
1969 { 0x80f070, 0x03 },
1970 { 0x80f072, 0x0f },
1971 { 0x80f073, 0x03 },
1972 { 0x80f077, 0x01 },
1973 { 0x80f078, 0x00 },
1974 { 0x80f087, 0x00 },
1975 { 0x80f09b, 0x3f },
1976 { 0x80f09c, 0x00 },
1977 { 0x80f09d, 0x20 },
1978 { 0x80f09e, 0x00 },
1979 { 0x80f09f, 0x0c },
1980 { 0x80f0a0, 0x00 },
1981 { 0x80f130, 0x04 },
1982 { 0x80f132, 0x04 },
1983 { 0x80f144, 0x1a },
1984 { 0x80f146, 0x00 },
1985 { 0x80f14a, 0x01 },
1986 { 0x80f14c, 0x00 },
1987 { 0x80f14d, 0x00 },
1988 { 0x80f14f, 0x04 },
1989 { 0x80f158, 0x7f },
1990 { 0x80f15a, 0x00 },
1991 { 0x80f15b, 0x08 },
1992 { 0x80f15d, 0x03 },
1993 { 0x80f15e, 0x05 },
1994 { 0x80f163, 0x05 },
1995 { 0x80f166, 0x01 },
1996 { 0x80f167, 0x40 },
1997 { 0x80f168, 0x0f },
1998 { 0x80f17a, 0x00 },
1999 { 0x80f17b, 0x00 },
2000 { 0x80f183, 0x01 },
2001 { 0x80f19d, 0x40 },
2002 { 0x80f1bc, 0x36 },
2003 { 0x80f1bd, 0x00 },
2004 { 0x80f1cb, 0xa0 },
2005 { 0x80f1cc, 0x01 },
2006 { 0x80f204, 0x10 },
2007 { 0x80f214, 0x00 },
2008 { 0x80f24c, 0x88 },
2009 { 0x80f24d, 0x95 },
2010 { 0x80f24e, 0x9a },
2011 { 0x80f24f, 0x90 },
2012 { 0x80f25a, 0x07 },
2013 { 0x80f25b, 0xe8 },
2014 { 0x80f25c, 0x03 },
2015 { 0x80f25d, 0xb0 },
2016 { 0x80f25e, 0x04 },
2017 { 0x80f270, 0x01 },
2018 { 0x80f271, 0x02 },
2019 { 0x80f272, 0x01 },
2020 { 0x80f273, 0x02 },
2021 { 0x80f40e, 0x0a },
2022 { 0x80f40f, 0x40 },
2023 { 0x80f410, 0x08 },
2024 { 0x80f55f, 0x0a },
2025 { 0x80f561, 0x15 },
2026 { 0x80f562, 0x20 },
2027 { 0x80f5e3, 0x09 },
2028 { 0x80f5e4, 0x01 },
2029 { 0x80f5e5, 0x01 },
2030 { 0x80f600, 0x05 },
2031 { 0x80f601, 0x08 },
2032 { 0x80f602, 0x0b },
2033 { 0x80f603, 0x0e },
2034 { 0x80f604, 0x11 },
2035 { 0x80f605, 0x14 },
2036 { 0x80f606, 0x17 },
2037 { 0x80f607, 0x1f },
2038 { 0x80f60e, 0x00 },
2039 { 0x80f60f, 0x04 },
2040 { 0x80f610, 0x32 },
2041 { 0x80f611, 0x10 },
2042 { 0x80f707, 0xfc },
2043 { 0x80f708, 0x00 },
2044 { 0x80f709, 0x37 },
2045 { 0x80f70a, 0x00 },
2046 { 0x80f78b, 0x01 },
2047 { 0x80f80f, 0x40 },
2048 { 0x80f810, 0x54 },
2049 { 0x80f811, 0x5a },
2050 { 0x80f905, 0x01 },
2051 { 0x80fb06, 0x03 },
2052 { 0x80fd8b, 0x00 },
2053};
2054
2055#endif /* AF9033_PRIV_H */
diff --git a/drivers/media/dvb-frontends/atbm8830.h b/drivers/media/dvb-frontends/atbm8830.h
index 024273374bd8..8e0ac98f8d08 100644
--- a/drivers/media/dvb-frontends/atbm8830.h
+++ b/drivers/media/dvb-frontends/atbm8830.h
@@ -22,6 +22,7 @@
22#ifndef __ATBM8830_H__ 22#ifndef __ATBM8830_H__
23#define __ATBM8830_H__ 23#define __ATBM8830_H__
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26#include <linux/i2c.h> 27#include <linux/i2c.h>
27 28
@@ -60,8 +61,7 @@ struct atbm8830_config {
60 u8 agc_hold_loop; 61 u8 agc_hold_loop;
61}; 62};
62 63
63#if defined(CONFIG_DVB_ATBM8830) || \ 64#if IS_ENABLED(CONFIG_DVB_ATBM8830)
64 (defined(CONFIG_DVB_ATBM8830_MODULE) && defined(MODULE))
65extern struct dvb_frontend *atbm8830_attach(const struct atbm8830_config *config, 65extern struct dvb_frontend *atbm8830_attach(const struct atbm8830_config *config,
66 struct i2c_adapter *i2c); 66 struct i2c_adapter *i2c);
67#else 67#else
diff --git a/drivers/media/dvb-frontends/au8522.h b/drivers/media/dvb-frontends/au8522.h
index 565dcf31af57..83fe9a615619 100644
--- a/drivers/media/dvb-frontends/au8522.h
+++ b/drivers/media/dvb-frontends/au8522.h
@@ -22,6 +22,7 @@
22#ifndef __AU8522_H__ 22#ifndef __AU8522_H__
23#define __AU8522_H__ 23#define __AU8522_H__
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27enum au8522_if_freq { 28enum au8522_if_freq {
@@ -60,8 +61,7 @@ struct au8522_config {
60 enum au8522_if_freq qam_if; 61 enum au8522_if_freq qam_if;
61}; 62};
62 63
63#if defined(CONFIG_DVB_AU8522) || \ 64#if IS_ENABLED(CONFIG_DVB_AU8522_DTV)
64 (defined(CONFIG_DVB_AU8522_MODULE) && defined(MODULE))
65extern struct dvb_frontend *au8522_attach(const struct au8522_config *config, 65extern struct dvb_frontend *au8522_attach(const struct au8522_config *config,
66 struct i2c_adapter *i2c); 66 struct i2c_adapter *i2c);
67#else 67#else
diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 5243ba6295cc..2099f21e374d 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -229,15 +229,11 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
229 /* Provide reasonable defaults for picture tuning values */ 229 /* Provide reasonable defaults for picture tuning values */
230 au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0x07); 230 au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0x07);
231 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0xed); 231 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0xed);
232 state->brightness = 0xed - 128;
233 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0x79); 232 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0x79);
234 state->contrast = 0x79;
235 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0x80); 233 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0x80);
236 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0x80); 234 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0x80);
237 state->saturation = 0x80;
238 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0x00); 235 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0x00);
239 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0x00); 236 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0x00);
240 state->hue = 0x00;
241 237
242 /* Other decoder registers */ 238 /* Other decoder registers */
243 au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00); 239 au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00);
@@ -489,75 +485,32 @@ static void set_audio_input(struct au8522_state *state, int aud_input)
489 485
490/* ----------------------------------------------------------------------- */ 486/* ----------------------------------------------------------------------- */
491 487
492static int au8522_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 488static int au8522_s_ctrl(struct v4l2_ctrl *ctrl)
493{ 489{
494 struct au8522_state *state = to_state(sd); 490 struct au8522_state *state =
491 container_of(ctrl->handler, struct au8522_state, hdl);
495 492
496 switch (ctrl->id) { 493 switch (ctrl->id) {
497 case V4L2_CID_BRIGHTNESS: 494 case V4L2_CID_BRIGHTNESS:
498 state->brightness = ctrl->value;
499 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 495 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH,
500 ctrl->value - 128); 496 ctrl->val - 128);
501 break; 497 break;
502 case V4L2_CID_CONTRAST: 498 case V4L2_CID_CONTRAST:
503 state->contrast = ctrl->value;
504 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 499 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH,
505 ctrl->value); 500 ctrl->val);
506 break; 501 break;
507 case V4L2_CID_SATURATION: 502 case V4L2_CID_SATURATION:
508 state->saturation = ctrl->value;
509 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 503 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH,
510 ctrl->value); 504 ctrl->val);
511 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 505 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH,
512 ctrl->value); 506 ctrl->val);
513 break; 507 break;
514 case V4L2_CID_HUE: 508 case V4L2_CID_HUE:
515 state->hue = ctrl->value;
516 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 509 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH,
517 ctrl->value >> 8); 510 ctrl->val >> 8);
518 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 511 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH,
519 ctrl->value & 0xFF); 512 ctrl->val & 0xFF);
520 break;
521 case V4L2_CID_AUDIO_VOLUME:
522 case V4L2_CID_AUDIO_BASS:
523 case V4L2_CID_AUDIO_TREBLE:
524 case V4L2_CID_AUDIO_BALANCE:
525 case V4L2_CID_AUDIO_MUTE:
526 /* Not yet implemented */
527 default:
528 return -EINVAL;
529 }
530
531 return 0;
532}
533
534static int au8522_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
535{
536 struct au8522_state *state = to_state(sd);
537
538 /* Note that we are using values cached in the state structure instead
539 of reading the registers due to issues with i2c reads not working
540 properly/consistently yet on the HVR-950q */
541
542 switch (ctrl->id) {
543 case V4L2_CID_BRIGHTNESS:
544 ctrl->value = state->brightness;
545 break;
546 case V4L2_CID_CONTRAST:
547 ctrl->value = state->contrast;
548 break; 513 break;
549 case V4L2_CID_SATURATION:
550 ctrl->value = state->saturation;
551 break;
552 case V4L2_CID_HUE:
553 ctrl->value = state->hue;
554 break;
555 case V4L2_CID_AUDIO_VOLUME:
556 case V4L2_CID_AUDIO_BASS:
557 case V4L2_CID_AUDIO_TREBLE:
558 case V4L2_CID_AUDIO_BALANCE:
559 case V4L2_CID_AUDIO_MUTE:
560 /* Not yet supported */
561 default: 514 default:
562 return -EINVAL; 515 return -EINVAL;
563 } 516 }
@@ -583,7 +536,7 @@ static int au8522_g_register(struct v4l2_subdev *sd,
583} 536}
584 537
585static int au8522_s_register(struct v4l2_subdev *sd, 538static int au8522_s_register(struct v4l2_subdev *sd,
586 struct v4l2_dbg_register *reg) 539 const struct v4l2_dbg_register *reg)
587{ 540{
588 struct i2c_client *client = v4l2_get_subdevdata(sd); 541 struct i2c_client *client = v4l2_get_subdevdata(sd);
589 struct au8522_state *state = to_state(sd); 542 struct au8522_state *state = to_state(sd);
@@ -616,26 +569,6 @@ static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
616 return 0; 569 return 0;
617} 570}
618 571
619static int au8522_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
620{
621 switch (qc->id) {
622 case V4L2_CID_CONTRAST:
623 return v4l2_ctrl_query_fill(qc, 0, 255, 1,
624 AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
625 case V4L2_CID_BRIGHTNESS:
626 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 109);
627 case V4L2_CID_SATURATION:
628 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
629 case V4L2_CID_HUE:
630 return v4l2_ctrl_query_fill(qc, -32768, 32768, 1, 0);
631 default:
632 break;
633 }
634
635 qc->type = 0;
636 return -EINVAL;
637}
638
639static int au8522_reset(struct v4l2_subdev *sd, u32 val) 572static int au8522_reset(struct v4l2_subdev *sd, u32 val)
640{ 573{
641 struct au8522_state *state = to_state(sd); 574 struct au8522_state *state = to_state(sd);
@@ -712,20 +645,11 @@ static int au8522_g_chip_ident(struct v4l2_subdev *sd,
712 return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev); 645 return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev);
713} 646}
714 647
715static int au8522_log_status(struct v4l2_subdev *sd)
716{
717 /* FIXME: Add some status info here */
718 return 0;
719}
720
721/* ----------------------------------------------------------------------- */ 648/* ----------------------------------------------------------------------- */
722 649
723static const struct v4l2_subdev_core_ops au8522_core_ops = { 650static const struct v4l2_subdev_core_ops au8522_core_ops = {
724 .log_status = au8522_log_status, 651 .log_status = v4l2_ctrl_subdev_log_status,
725 .g_chip_ident = au8522_g_chip_ident, 652 .g_chip_ident = au8522_g_chip_ident,
726 .g_ctrl = au8522_g_ctrl,
727 .s_ctrl = au8522_s_ctrl,
728 .queryctrl = au8522_queryctrl,
729 .reset = au8522_reset, 653 .reset = au8522_reset,
730#ifdef CONFIG_VIDEO_ADV_DEBUG 654#ifdef CONFIG_VIDEO_ADV_DEBUG
731 .g_register = au8522_g_register, 655 .g_register = au8522_g_register,
@@ -753,12 +677,17 @@ static const struct v4l2_subdev_ops au8522_ops = {
753 .video = &au8522_video_ops, 677 .video = &au8522_video_ops,
754}; 678};
755 679
680static const struct v4l2_ctrl_ops au8522_ctrl_ops = {
681 .s_ctrl = au8522_s_ctrl,
682};
683
756/* ----------------------------------------------------------------------- */ 684/* ----------------------------------------------------------------------- */
757 685
758static int au8522_probe(struct i2c_client *client, 686static int au8522_probe(struct i2c_client *client,
759 const struct i2c_device_id *did) 687 const struct i2c_device_id *did)
760{ 688{
761 struct au8522_state *state; 689 struct au8522_state *state;
690 struct v4l2_ctrl_handler *hdl;
762 struct v4l2_subdev *sd; 691 struct v4l2_subdev *sd;
763 int instance; 692 int instance;
764 struct au8522_config *demod_config; 693 struct au8522_config *demod_config;
@@ -799,6 +728,27 @@ static int au8522_probe(struct i2c_client *client,
799 sd = &state->sd; 728 sd = &state->sd;
800 v4l2_i2c_subdev_init(sd, client, &au8522_ops); 729 v4l2_i2c_subdev_init(sd, client, &au8522_ops);
801 730
731 hdl = &state->hdl;
732 v4l2_ctrl_handler_init(hdl, 4);
733 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
734 V4L2_CID_BRIGHTNESS, 0, 255, 1, 109);
735 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
736 V4L2_CID_CONTRAST, 0, 255, 1,
737 AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
738 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
739 V4L2_CID_SATURATION, 0, 255, 1, 128);
740 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
741 V4L2_CID_HUE, -32768, 32767, 1, 0);
742 sd->ctrl_handler = hdl;
743 if (hdl->error) {
744 int err = hdl->error;
745
746 v4l2_ctrl_handler_free(hdl);
747 kfree(demod_config);
748 kfree(state);
749 return err;
750 }
751
802 state->c = client; 752 state->c = client;
803 state->vid_input = AU8522_COMPOSITE_CH1; 753 state->vid_input = AU8522_COMPOSITE_CH1;
804 state->aud_input = AU8522_AUDIO_NONE; 754 state->aud_input = AU8522_AUDIO_NONE;
@@ -815,6 +765,7 @@ static int au8522_remove(struct i2c_client *client)
815{ 765{
816 struct v4l2_subdev *sd = i2c_get_clientdata(client); 766 struct v4l2_subdev *sd = i2c_get_clientdata(client);
817 v4l2_device_unregister_subdev(sd); 767 v4l2_device_unregister_subdev(sd);
768 v4l2_ctrl_handler_free(sd->ctrl_handler);
818 au8522_release_state(to_state(sd)); 769 au8522_release_state(to_state(sd));
819 return 0; 770 return 0;
820} 771}
diff --git a/drivers/media/dvb-frontends/au8522_priv.h b/drivers/media/dvb-frontends/au8522_priv.h
index 0529699a27bd..aa0f16d6b610 100644
--- a/drivers/media/dvb-frontends/au8522_priv.h
+++ b/drivers/media/dvb-frontends/au8522_priv.h
@@ -29,6 +29,7 @@
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
32#include <media/v4l2-ctrls.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33#include "dvb_frontend.h" 34#include "dvb_frontend.h"
34#include "au8522.h" 35#include "au8522.h"
@@ -65,10 +66,7 @@ struct au8522_state {
65 int aud_input; 66 int aud_input;
66 u32 id; 67 u32 id;
67 u32 rev; 68 u32 rev;
68 u8 brightness; 69 struct v4l2_ctrl_handler hdl;
69 u8 contrast;
70 u8 saturation;
71 s16 hue;
72}; 70};
73 71
74/* These are routines shared by both the VSB/QAM demodulator and the analog 72/* These are routines shared by both the VSB/QAM demodulator and the analog
diff --git a/drivers/media/dvb-frontends/cx22702.h b/drivers/media/dvb-frontends/cx22702.h
index f154e1f428eb..0b1a6c2f9d5f 100644
--- a/drivers/media/dvb-frontends/cx22702.h
+++ b/drivers/media/dvb-frontends/cx22702.h
@@ -28,6 +28,7 @@
28#ifndef CX22702_H 28#ifndef CX22702_H
29#define CX22702_H 29#define CX22702_H
30 30
31#include <linux/kconfig.h>
31#include <linux/dvb/frontend.h> 32#include <linux/dvb/frontend.h>
32 33
33struct cx22702_config { 34struct cx22702_config {
@@ -40,8 +41,7 @@ struct cx22702_config {
40 u8 output_mode; 41 u8 output_mode;
41}; 42};
42 43
43#if defined(CONFIG_DVB_CX22702) || (defined(CONFIG_DVB_CX22702_MODULE) \ 44#if IS_ENABLED(CONFIG_DVB_CX22702)
44 && defined(MODULE))
45extern struct dvb_frontend *cx22702_attach( 45extern struct dvb_frontend *cx22702_attach(
46 const struct cx22702_config *config, 46 const struct cx22702_config *config,
47 struct i2c_adapter *i2c); 47 struct i2c_adapter *i2c);
diff --git a/drivers/media/dvb-frontends/cx24113.h b/drivers/media/dvb-frontends/cx24113.h
index 01eb7b9c28f4..782711ba1a32 100644
--- a/drivers/media/dvb-frontends/cx24113.h
+++ b/drivers/media/dvb-frontends/cx24113.h
@@ -22,6 +22,8 @@
22#ifndef CX24113_H 22#ifndef CX24113_H
23#define CX24113_H 23#define CX24113_H
24 24
25#include <linux/kconfig.h>
26
25struct dvb_frontend; 27struct dvb_frontend;
26 28
27struct cx24113_config { 29struct cx24113_config {
@@ -30,8 +32,7 @@ struct cx24113_config {
30 u32 xtal_khz; 32 u32 xtal_khz;
31}; 33};
32 34
33#if defined(CONFIG_DVB_TUNER_CX24113) || \ 35#if IS_ENABLED(CONFIG_DVB_TUNER_CX24113)
34 (defined(CONFIG_DVB_TUNER_CX24113_MODULE) && defined(MODULE))
35extern struct dvb_frontend *cx24113_attach(struct dvb_frontend *, 36extern struct dvb_frontend *cx24113_attach(struct dvb_frontend *,
36 const struct cx24113_config *config, struct i2c_adapter *i2c); 37 const struct cx24113_config *config, struct i2c_adapter *i2c);
37 38
diff --git a/drivers/media/dvb-frontends/cx24116.h b/drivers/media/dvb-frontends/cx24116.h
index 7d90ab949c03..2ec84fae3f9f 100644
--- a/drivers/media/dvb-frontends/cx24116.h
+++ b/drivers/media/dvb-frontends/cx24116.h
@@ -21,6 +21,7 @@
21#ifndef CX24116_H 21#ifndef CX24116_H
22#define CX24116_H 22#define CX24116_H
23 23
24#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
25 26
26struct cx24116_config { 27struct cx24116_config {
@@ -40,8 +41,7 @@ struct cx24116_config {
40 u16 i2c_wr_max; 41 u16 i2c_wr_max;
41}; 42};
42 43
43#if defined(CONFIG_DVB_CX24116) || \ 44#if IS_ENABLED(CONFIG_DVB_CX24116)
44 (defined(CONFIG_DVB_CX24116_MODULE) && defined(MODULE))
45extern struct dvb_frontend *cx24116_attach( 45extern struct dvb_frontend *cx24116_attach(
46 const struct cx24116_config *config, 46 const struct cx24116_config *config,
47 struct i2c_adapter *i2c); 47 struct i2c_adapter *i2c);
diff --git a/drivers/media/dvb-frontends/cx24123.c b/drivers/media/dvb-frontends/cx24123.c
index 68c88ab58e71..a771da3e9f99 100644
--- a/drivers/media/dvb-frontends/cx24123.c
+++ b/drivers/media/dvb-frontends/cx24123.c
@@ -26,6 +26,7 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <asm/div64.h>
29 30
30#include "dvb_frontend.h" 31#include "dvb_frontend.h"
31#include "cx24123.h" 32#include "cx24123.h"
@@ -452,7 +453,8 @@ static u32 cx24123_int_log2(u32 a, u32 b)
452 453
453static int cx24123_set_symbolrate(struct cx24123_state *state, u32 srate) 454static int cx24123_set_symbolrate(struct cx24123_state *state, u32 srate)
454{ 455{
455 u32 tmp, sample_rate, ratio, sample_gain; 456 u64 tmp;
457 u32 sample_rate, ratio, sample_gain;
456 u8 pll_mult; 458 u8 pll_mult;
457 459
458 /* check if symbol rate is within limits */ 460 /* check if symbol rate is within limits */
@@ -482,27 +484,11 @@ static int cx24123_set_symbolrate(struct cx24123_state *state, u32 srate)
482 484
483 sample_rate = pll_mult * XTAL; 485 sample_rate = pll_mult * XTAL;
484 486
485 /* 487 /* SYSSymbolRate[21:0] = (srate << 23) / sample_rate */
486 SYSSymbolRate[21:0] = (srate << 23) / sample_rate
487
488 We have to use 32 bit unsigned arithmetic without precision loss.
489 The maximum srate is 45000000 or 0x02AEA540. This number has
490 only 6 clear bits on top, hence we can shift it left only 6 bits
491 at a time. Borrowed from cx24110.c
492 */
493
494 tmp = srate << 6;
495 ratio = tmp / sample_rate;
496
497 tmp = (tmp % sample_rate) << 6;
498 ratio = (ratio << 6) + (tmp / sample_rate);
499
500 tmp = (tmp % sample_rate) << 6;
501 ratio = (ratio << 6) + (tmp / sample_rate);
502
503 tmp = (tmp % sample_rate) << 5;
504 ratio = (ratio << 5) + (tmp / sample_rate);
505 488
489 tmp = ((u64)srate) << 23;
490 do_div(tmp, sample_rate);
491 ratio = (u32) tmp;
506 492
507 cx24123_writereg(state, 0x01, pll_mult * 6); 493 cx24123_writereg(state, 0x01, pll_mult * 6);
508 494
diff --git a/drivers/media/dvb-frontends/cx24123.h b/drivers/media/dvb-frontends/cx24123.h
index 51ae866e9fed..102e70d17c43 100644
--- a/drivers/media/dvb-frontends/cx24123.h
+++ b/drivers/media/dvb-frontends/cx24123.h
@@ -21,6 +21,7 @@
21#ifndef CX24123_H 21#ifndef CX24123_H
22#define CX24123_H 22#define CX24123_H
23 23
24#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
25 26
26struct cx24123_config { 27struct cx24123_config {
@@ -38,8 +39,7 @@ struct cx24123_config {
38 void (*agc_callback) (struct dvb_frontend *); 39 void (*agc_callback) (struct dvb_frontend *);
39}; 40};
40 41
41#if defined(CONFIG_DVB_CX24123) || (defined(CONFIG_DVB_CX24123_MODULE) \ 42#if IS_ENABLED(CONFIG_DVB_CX24123)
42 && defined(MODULE))
43extern struct dvb_frontend *cx24123_attach(const struct cx24123_config *config, 43extern struct dvb_frontend *cx24123_attach(const struct cx24123_config *config,
44 struct i2c_adapter *i2c); 44 struct i2c_adapter *i2c);
45extern struct i2c_adapter *cx24123_get_tuner_i2c_adapter(struct dvb_frontend *); 45extern struct i2c_adapter *cx24123_get_tuner_i2c_adapter(struct dvb_frontend *);
diff --git a/drivers/media/dvb-frontends/cxd2820r.h b/drivers/media/dvb-frontends/cxd2820r.h
index 6acc21c581c5..82b3d93718f8 100644
--- a/drivers/media/dvb-frontends/cxd2820r.h
+++ b/drivers/media/dvb-frontends/cxd2820r.h
@@ -22,6 +22,7 @@
22#ifndef CXD2820R_H 22#ifndef CXD2820R_H
23#define CXD2820R_H 23#define CXD2820R_H
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27#define CXD2820R_GPIO_D (0 << 0) /* disable */ 28#define CXD2820R_GPIO_D (0 << 0) /* disable */
@@ -65,8 +66,7 @@ struct cxd2820r_config {
65}; 66};
66 67
67 68
68#if defined(CONFIG_DVB_CXD2820R) || \ 69#if IS_ENABLED(CONFIG_DVB_CXD2820R)
69 (defined(CONFIG_DVB_CXD2820R_MODULE) && defined(MODULE))
70extern struct dvb_frontend *cxd2820r_attach( 70extern struct dvb_frontend *cxd2820r_attach(
71 const struct cxd2820r_config *config, 71 const struct cxd2820r_config *config,
72 struct i2c_adapter *i2c, 72 struct i2c_adapter *i2c,
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
index 9b658c1cf39a..7ca5c69dd200 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -660,7 +660,8 @@ static const struct dvb_frontend_ops cxd2820r_ops = {
660 FE_CAN_GUARD_INTERVAL_AUTO | 660 FE_CAN_GUARD_INTERVAL_AUTO |
661 FE_CAN_HIERARCHY_AUTO | 661 FE_CAN_HIERARCHY_AUTO |
662 FE_CAN_MUTE_TS | 662 FE_CAN_MUTE_TS |
663 FE_CAN_2G_MODULATION 663 FE_CAN_2G_MODULATION |
664 FE_CAN_MULTISTREAM
664 }, 665 },
665 666
666 .release = cxd2820r_release, 667 .release = cxd2820r_release,
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c b/drivers/media/dvb-frontends/cxd2820r_t2.c
index e82d82a7a2eb..2ba130e245b6 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ -124,6 +124,23 @@ int cxd2820r_set_frontend_t2(struct dvb_frontend *fe)
124 buf[1] = ((if_ctl >> 8) & 0xff); 124 buf[1] = ((if_ctl >> 8) & 0xff);
125 buf[2] = ((if_ctl >> 0) & 0xff); 125 buf[2] = ((if_ctl >> 0) & 0xff);
126 126
127 /* PLP filtering */
128 if (c->stream_id > 255) {
129 dev_dbg(&priv->i2c->dev, "%s: Disable PLP filtering\n", __func__);
130 ret = cxd2820r_wr_reg(priv, 0x023ad , 0);
131 if (ret)
132 goto error;
133 } else {
134 dev_dbg(&priv->i2c->dev, "%s: Enable PLP filtering = %d\n", __func__,
135 c->stream_id);
136 ret = cxd2820r_wr_reg(priv, 0x023af , c->stream_id & 0xFF);
137 if (ret)
138 goto error;
139 ret = cxd2820r_wr_reg(priv, 0x023ad , 1);
140 if (ret)
141 goto error;
142 }
143
127 ret = cxd2820r_wr_regs(priv, 0x020b6, buf, 3); 144 ret = cxd2820r_wr_regs(priv, 0x020b6, buf, 3);
128 if (ret) 145 if (ret)
129 goto error; 146 goto error;
diff --git a/drivers/media/dvb-frontends/dib0090.c b/drivers/media/dvb-frontends/dib0090.c
index d9fe60b4be48..3ee22ff76315 100644
--- a/drivers/media/dvb-frontends/dib0090.c
+++ b/drivers/media/dvb-frontends/dib0090.c
@@ -528,20 +528,19 @@ static void dib0090_reset_digital(struct dvb_frontend *fe, const struct dib0090_
528 u16 PllCfg, i, v; 528 u16 PllCfg, i, v;
529 529
530 HARD_RESET(state); 530 HARD_RESET(state);
531
532 dib0090_write_reg(state, 0x24, EN_PLL | EN_CRYSTAL); 531 dib0090_write_reg(state, 0x24, EN_PLL | EN_CRYSTAL);
533 dib0090_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */ 532 if (cfg->in_soc)
533 return;
534 534
535 if (!cfg->in_soc) { 535 dib0090_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */
536 /* adcClkOutRatio=8->7, release reset */ 536 /* adcClkOutRatio=8->7, release reset */
537 dib0090_write_reg(state, 0x20, ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0); 537 dib0090_write_reg(state, 0x20, ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0);
538 if (cfg->clkoutdrive != 0) 538 if (cfg->clkoutdrive != 0)
539 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8) 539 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8)
540 | (cfg->clkoutdrive << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0)); 540 | (cfg->clkoutdrive << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0));
541 else 541 else
542 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8) 542 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8)
543 | (7 << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0)); 543 | (7 << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0));
544 }
545 544
546 /* Read Pll current config * */ 545 /* Read Pll current config * */
547 PllCfg = dib0090_read_reg(state, 0x21); 546 PllCfg = dib0090_read_reg(state, 0x21);
@@ -694,192 +693,174 @@ void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast)
694EXPORT_SYMBOL(dib0090_dcc_freq); 693EXPORT_SYMBOL(dib0090_dcc_freq);
695 694
696static const u16 bb_ramp_pwm_normal_socs[] = { 695static const u16 bb_ramp_pwm_normal_socs[] = {
697 550, /* max BB gain in 10th of dB */ 696 550, /* max BB gain in 10th of dB */
698 (1 << 9) | 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> BB_RAMP2 */ 697 (1<<9) | 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> BB_RAMP2 */
699 440, 698 440,
700 (4 << 9) | 0, /* BB_RAMP3 = 26dB */ 699 (4 << 9) | 0, /* BB_RAMP3 = 26dB */
701 (0 << 9) | 208, /* BB_RAMP4 */ 700 (0 << 9) | 208, /* BB_RAMP4 */
702 (4 << 9) | 208, /* BB_RAMP5 = 29dB */ 701 (4 << 9) | 208, /* BB_RAMP5 = 29dB */
703 (0 << 9) | 440, /* BB_RAMP6 */ 702 (0 << 9) | 440, /* BB_RAMP6 */
704}; 703};
705 704
706static const u16 rf_ramp_pwm_cband_7090[] = { 705static const u16 rf_ramp_pwm_cband_7090p[] = {
707 280, /* max RF gain in 10th of dB */ 706 280, /* max RF gain in 10th of dB */
708 18, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 707 18, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
709 504, /* ramp_max = maximum X used on the ramp */ 708 504, /* ramp_max = maximum X used on the ramp */
710 (29 << 10) | 364, /* RF_RAMP5, LNA 1 = 8dB */ 709 (29 << 10) | 364, /* RF_RAMP5, LNA 1 = 8dB */
711 (0 << 10) | 504, /* RF_RAMP6, LNA 1 */ 710 (0 << 10) | 504, /* RF_RAMP6, LNA 1 */
712 (60 << 10) | 228, /* RF_RAMP7, LNA 2 = 7.7dB */ 711 (60 << 10) | 228, /* RF_RAMP7, LNA 2 = 7.7dB */
713 (0 << 10) | 364, /* RF_RAMP8, LNA 2 */ 712 (0 << 10) | 364, /* RF_RAMP8, LNA 2 */
714 (34 << 10) | 109, /* GAIN_4_1, LNA 3 = 6.8dB */ 713 (34 << 10) | 109, /* GAIN_4_1, LNA 3 = 6.8dB */
715 (0 << 10) | 228, /* GAIN_4_2, LNA 3 */ 714 (0 << 10) | 228, /* GAIN_4_2, LNA 3 */
716 (37 << 10) | 0, /* RF_RAMP3, LNA 4 = 6.2dB */ 715 (37 << 10) | 0, /* RF_RAMP3, LNA 4 = 6.2dB */
717 (0 << 10) | 109, /* RF_RAMP4, LNA 4 */ 716 (0 << 10) | 109, /* RF_RAMP4, LNA 4 */
718}; 717};
719 718
720static const uint16_t rf_ramp_pwm_cband_7090e_sensitivity[] = { 719static const u16 rf_ramp_pwm_cband_7090e_sensitivity[] = {
721 186, 720 186, /* max RF gain in 10th of dB */
722 40, 721 40, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
723 746, 722 746, /* ramp_max = maximum X used on the ramp */
724 (10 << 10) | 345, 723 (10 << 10) | 345, /* RF_RAMP5, LNA 1 = 10dB */
725 (0 << 10) | 746, 724 (0 << 10) | 746, /* RF_RAMP6, LNA 1 */
726 (0 << 10) | 0, 725 (0 << 10) | 0, /* RF_RAMP7, LNA 2 = 0 dB */
727 (0 << 10) | 0, 726 (0 << 10) | 0, /* RF_RAMP8, LNA 2 */
728 (28 << 10) | 200, 727 (28 << 10) | 200, /* GAIN_4_1, LNA 3 = 6.8dB */ /* 3.61 dB */
729 (0 << 10) | 345, 728 (0 << 10) | 345, /* GAIN_4_2, LNA 3 */
730 (20 << 10) | 0, 729 (20 << 10) | 0, /* RF_RAMP3, LNA 4 = 6.2dB */ /* 4.96 dB */
731 (0 << 10) | 200, 730 (0 << 10) | 200, /* RF_RAMP4, LNA 4 */
732}; 731};
733 732
734static const uint16_t rf_ramp_pwm_cband_7090e_aci[] = { 733static const u16 rf_ramp_pwm_cband_7090e_aci[] = {
735 86, 734 86, /* max RF gain in 10th of dB */
736 40, 735 40, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
737 345, 736 345, /* ramp_max = maximum X used on the ramp */
738 (0 << 10) | 0, 737 (0 << 10) | 0, /* RF_RAMP5, LNA 1 = 8dB */ /* 7.47 dB */
739 (0 << 10) | 0, 738 (0 << 10) | 0, /* RF_RAMP6, LNA 1 */
740 (0 << 10) | 0, 739 (0 << 10) | 0, /* RF_RAMP7, LNA 2 = 0 dB */
741 (0 << 10) | 0, 740 (0 << 10) | 0, /* RF_RAMP8, LNA 2 */
742 (28 << 10) | 200, 741 (28 << 10) | 200, /* GAIN_4_1, LNA 3 = 6.8dB */ /* 3.61 dB */
743 (0 << 10) | 345, 742 (0 << 10) | 345, /* GAIN_4_2, LNA 3 */
744 (20 << 10) | 0, 743 (20 << 10) | 0, /* RF_RAMP3, LNA 4 = 6.2dB */ /* 4.96 dB */
745 (0 << 10) | 200, 744 (0 << 10) | 200, /* RF_RAMP4, LNA 4 */
746}; 745};
747 746
748static const u16 rf_ramp_pwm_cband_8090[] = { 747static const u16 rf_ramp_pwm_cband_8090[] = {
749 345, /* max RF gain in 10th of dB */ 748 345, /* max RF gain in 10th of dB */
750 29, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 749 29, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
751 1000, /* ramp_max = maximum X used on the ramp */ 750 1000, /* ramp_max = maximum X used on the ramp */
752 (35 << 10) | 772, /* RF_RAMP3, LNA 1 = 8dB */ 751 (35 << 10) | 772, /* RF_RAMP3, LNA 1 = 8dB */
753 (0 << 10) | 1000, /* RF_RAMP4, LNA 1 */ 752 (0 << 10) | 1000, /* RF_RAMP4, LNA 1 */
754 (58 << 10) | 496, /* RF_RAMP5, LNA 2 = 9.5dB */ 753 (58 << 10) | 496, /* RF_RAMP5, LNA 2 = 9.5dB */
755 (0 << 10) | 772, /* RF_RAMP6, LNA 2 */ 754 (0 << 10) | 772, /* RF_RAMP6, LNA 2 */
756 (27 << 10) | 200, /* RF_RAMP7, LNA 3 = 10.5dB */ 755 (27 << 10) | 200, /* RF_RAMP7, LNA 3 = 10.5dB */
757 (0 << 10) | 496, /* RF_RAMP8, LNA 3 */ 756 (0 << 10) | 496, /* RF_RAMP8, LNA 3 */
758 (40 << 10) | 0, /* GAIN_4_1, LNA 4 = 7dB */ 757 (40 << 10) | 0, /* GAIN_4_1, LNA 4 = 7dB */
759 (0 << 10) | 200, /* GAIN_4_2, LNA 4 */ 758 (0 << 10) | 200, /* GAIN_4_2, LNA 4 */
760}; 759};
761 760
762static const u16 rf_ramp_pwm_uhf_7090[] = { 761static const u16 rf_ramp_pwm_uhf_7090[] = {
763 407, /* max RF gain in 10th of dB */ 762 407, /* max RF gain in 10th of dB */
764 13, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 763 13, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
765 529, /* ramp_max = maximum X used on the ramp */ 764 529, /* ramp_max = maximum X used on the ramp */
766 (23 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */ 765 (23 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */
767 (0 << 10) | 176, /* RF_RAMP4, LNA 1 */ 766 (0 << 10) | 176, /* RF_RAMP4, LNA 1 */
768 (63 << 10) | 400, /* RF_RAMP5, LNA 2 = 8dB */ 767 (63 << 10) | 400, /* RF_RAMP5, LNA 2 = 8dB */
769 (0 << 10) | 529, /* RF_RAMP6, LNA 2 */ 768 (0 << 10) | 529, /* RF_RAMP6, LNA 2 */
770 (48 << 10) | 316, /* RF_RAMP7, LNA 3 = 6.8dB */ 769 (48 << 10) | 316, /* RF_RAMP7, LNA 3 = 6.8dB */
771 (0 << 10) | 400, /* RF_RAMP8, LNA 3 */ 770 (0 << 10) | 400, /* RF_RAMP8, LNA 3 */
772 (29 << 10) | 176, /* GAIN_4_1, LNA 4 = 11.5dB */ 771 (29 << 10) | 176, /* GAIN_4_1, LNA 4 = 11.5dB */
773 (0 << 10) | 316, /* GAIN_4_2, LNA 4 */ 772 (0 << 10) | 316, /* GAIN_4_2, LNA 4 */
774}; 773};
775 774
776static const u16 rf_ramp_pwm_uhf_8090[] = { 775static const u16 rf_ramp_pwm_uhf_8090[] = {
777 388, /* max RF gain in 10th of dB */ 776 388, /* max RF gain in 10th of dB */
778 26, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 777 26, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
779 1008, /* ramp_max = maximum X used on the ramp */ 778 1008, /* ramp_max = maximum X used on the ramp */
780 (11 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */ 779 (11 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */
781 (0 << 10) | 369, /* RF_RAMP4, LNA 1 */ 780 (0 << 10) | 369, /* RF_RAMP4, LNA 1 */
782 (41 << 10) | 809, /* RF_RAMP5, LNA 2 = 8dB */ 781 (41 << 10) | 809, /* RF_RAMP5, LNA 2 = 8dB */
783 (0 << 10) | 1008, /* RF_RAMP6, LNA 2 */ 782 (0 << 10) | 1008, /* RF_RAMP6, LNA 2 */
784 (27 << 10) | 659, /* RF_RAMP7, LNA 3 = 6dB */ 783 (27 << 10) | 659, /* RF_RAMP7, LNA 3 = 6dB */
785 (0 << 10) | 809, /* RF_RAMP8, LNA 3 */ 784 (0 << 10) | 809, /* RF_RAMP8, LNA 3 */
786 (14 << 10) | 369, /* GAIN_4_1, LNA 4 = 11.5dB */ 785 (14 << 10) | 369, /* GAIN_4_1, LNA 4 = 11.5dB */
787 (0 << 10) | 659, /* GAIN_4_2, LNA 4 */ 786 (0 << 10) | 659, /* GAIN_4_2, LNA 4 */
788}; 787};
789 788
790static const u16 rf_ramp_pwm_cband[] = { 789/* GENERAL PWM ramp definition for all other Krosus */
791 0, /* max RF gain in 10th of dB */ 790static const u16 bb_ramp_pwm_normal[] = {
792 0, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> 0x2b */ 791 500, /* max BB gain in 10th of dB */
793 0, /* ramp_max = maximum X used on the ramp */ 792 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> BB_RAMP2 */
794 (0 << 10) | 0, /* 0x2c, LNA 1 = 0dB */ 793 400,
795 (0 << 10) | 0, /* 0x2d, LNA 1 */ 794 (2 << 9) | 0, /* BB_RAMP3 = 21dB */
796 (0 << 10) | 0, /* 0x2e, LNA 2 = 0dB */ 795 (0 << 9) | 168, /* BB_RAMP4 */
797 (0 << 10) | 0, /* 0x2f, LNA 2 */ 796 (2 << 9) | 168, /* BB_RAMP5 = 29dB */
798 (0 << 10) | 0, /* 0x30, LNA 3 = 0dB */ 797 (0 << 9) | 400, /* BB_RAMP6 */
799 (0 << 10) | 0, /* 0x31, LNA 3 */
800 (0 << 10) | 0, /* GAIN_4_1, LNA 4 = 0dB */
801 (0 << 10) | 0, /* GAIN_4_2, LNA 4 */
802};
803
804static const u16 rf_ramp_vhf[] = {
805 412, /* max RF gain in 10th of dB */
806 132, 307, 127, /* LNA1, 13.2dB */
807 105, 412, 255, /* LNA2, 10.5dB */
808 50, 50, 127, /* LNA3, 5dB */
809 125, 175, 127, /* LNA4, 12.5dB */
810 0, 0, 127, /* CBAND, 0dB */
811};
812
813static const u16 rf_ramp_uhf[] = {
814 412, /* max RF gain in 10th of dB */
815 132, 307, 127, /* LNA1 : total gain = 13.2dB, point on the ramp where this amp is full gain, value to write to get full gain */
816 105, 412, 255, /* LNA2 : 10.5 dB */
817 50, 50, 127, /* LNA3 : 5.0 dB */
818 125, 175, 127, /* LNA4 : 12.5 dB */
819 0, 0, 127, /* CBAND : 0.0 dB */
820}; 798};
821 799
822static const u16 rf_ramp_cband_broadmatching[] = /* for p1G only */ 800static const u16 bb_ramp_pwm_boost[] = {
823{ 801 550, /* max BB gain in 10th of dB */
824 314, /* Calibrated at 200MHz order has been changed g4-g3-g2-g1 */ 802 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> BB_RAMP2 */
825 84, 314, 127, /* LNA1 */ 803 440,
826 80, 230, 255, /* LNA2 */ 804 (2 << 9) | 0, /* BB_RAMP3 = 26dB */
827 80, 150, 127, /* LNA3 It was measured 12dB, do not lock if 120 */ 805 (0 << 9) | 208, /* BB_RAMP4 */
828 70, 70, 127, /* LNA4 */ 806 (2 << 9) | 208, /* BB_RAMP5 = 29dB */
829 0, 0, 127, /* CBAND */ 807 (0 << 9) | 440, /* BB_RAMP6 */
830}; 808};
831 809
832static const u16 rf_ramp_cband[] = { 810static const u16 rf_ramp_pwm_cband[] = {
833 332, /* max RF gain in 10th of dB */ 811 314, /* max RF gain in 10th of dB */
834 132, 252, 127, /* LNA1, dB */ 812 33, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
835 80, 332, 255, /* LNA2, dB */ 813 1023, /* ramp_max = maximum X used on the ramp */
836 0, 0, 127, /* LNA3, dB */ 814 (8 << 10) | 743, /* RF_RAMP3, LNA 1 = 0dB */
837 0, 0, 127, /* LNA4, dB */ 815 (0 << 10) | 1023, /* RF_RAMP4, LNA 1 */
838 120, 120, 127, /* LT1 CBAND */ 816 (15 << 10) | 469, /* RF_RAMP5, LNA 2 = 0dB */
817 (0 << 10) | 742, /* RF_RAMP6, LNA 2 */
818 (9 << 10) | 234, /* RF_RAMP7, LNA 3 = 0dB */
819 (0 << 10) | 468, /* RF_RAMP8, LNA 3 */
820 (9 << 10) | 0, /* GAIN_4_1, LNA 4 = 0dB */
821 (0 << 10) | 233, /* GAIN_4_2, LNA 4 */
839}; 822};
840 823
841static const u16 rf_ramp_pwm_vhf[] = { 824static const u16 rf_ramp_pwm_vhf[] = {
842 404, /* max RF gain in 10th of dB */ 825 398, /* max RF gain in 10th of dB */
843 25, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> 0x2b */ 826 24, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
844 1011, /* ramp_max = maximum X used on the ramp */ 827 954, /* ramp_max = maximum X used on the ramp */
845 (6 << 10) | 417, /* 0x2c, LNA 1 = 13.2dB */ 828 (7 << 10) | 0, /* RF_RAMP3, LNA 1 = 13.2dB */
846 (0 << 10) | 756, /* 0x2d, LNA 1 */ 829 (0 << 10) | 290, /* RF_RAMP4, LNA 1 */
847 (16 << 10) | 756, /* 0x2e, LNA 2 = 10.5dB */ 830 (16 << 10) | 699, /* RF_RAMP5, LNA 2 = 10.5dB */
848 (0 << 10) | 1011, /* 0x2f, LNA 2 */ 831 (0 << 10) | 954, /* RF_RAMP6, LNA 2 */
849 (16 << 10) | 290, /* 0x30, LNA 3 = 5dB */ 832 (17 << 10) | 580, /* RF_RAMP7, LNA 3 = 5dB */
850 (0 << 10) | 417, /* 0x31, LNA 3 */ 833 (0 << 10) | 699, /* RF_RAMP8, LNA 3 */
851 (7 << 10) | 0, /* GAIN_4_1, LNA 4 = 12.5dB */ 834 (7 << 10) | 290, /* GAIN_4_1, LNA 4 = 12.5dB */
852 (0 << 10) | 290, /* GAIN_4_2, LNA 4 */ 835 (0 << 10) | 580, /* GAIN_4_2, LNA 4 */
853}; 836};
854 837
855static const u16 rf_ramp_pwm_uhf[] = { 838static const u16 rf_ramp_pwm_uhf[] = {
856 404, /* max RF gain in 10th of dB */ 839 398, /* max RF gain in 10th of dB */
857 25, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> 0x2b */ 840 24, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
858 1011, /* ramp_max = maximum X used on the ramp */ 841 954, /* ramp_max = maximum X used on the ramp */
859 (6 << 10) | 417, /* 0x2c, LNA 1 = 13.2dB */ 842 (7 << 10) | 0, /* RF_RAMP3, LNA 1 = 13.2dB */
860 (0 << 10) | 756, /* 0x2d, LNA 1 */ 843 (0 << 10) | 290, /* RF_RAMP4, LNA 1 */
861 (16 << 10) | 756, /* 0x2e, LNA 2 = 10.5dB */ 844 (16 << 10) | 699, /* RF_RAMP5, LNA 2 = 10.5dB */
862 (0 << 10) | 1011, /* 0x2f, LNA 2 */ 845 (0 << 10) | 954, /* RF_RAMP6, LNA 2 */
863 (16 << 10) | 0, /* 0x30, LNA 3 = 5dB */ 846 (17 << 10) | 580, /* RF_RAMP7, LNA 3 = 5dB */
864 (0 << 10) | 127, /* 0x31, LNA 3 */ 847 (0 << 10) | 699, /* RF_RAMP8, LNA 3 */
865 (7 << 10) | 127, /* GAIN_4_1, LNA 4 = 12.5dB */ 848 (7 << 10) | 290, /* GAIN_4_1, LNA 4 = 12.5dB */
866 (0 << 10) | 417, /* GAIN_4_2, LNA 4 */ 849 (0 << 10) | 580, /* GAIN_4_2, LNA 4 */
867}; 850};
868 851
869static const u16 bb_ramp_boost[] = { 852static const u16 rf_ramp_pwm_sband[] = {
870 550, /* max BB gain in 10th of dB */ 853 253, /* max RF gain in 10th of dB */
871 260, 260, 26, /* BB1, 26dB */ 854 38, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
872 290, 550, 29, /* BB2, 29dB */ 855 961,
873}; 856 (4 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.1dB */
874 857 (0 << 10) | 508, /* RF_RAMP4, LNA 1 */
875static const u16 bb_ramp_pwm_normal[] = { 858 (9 << 10) | 508, /* RF_RAMP5, LNA 2 = 11.2dB */
876 500, /* max RF gain in 10th of dB */ 859 (0 << 10) | 961, /* RF_RAMP6, LNA 2 */
877 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> 0x34 */ 860 (0 << 10) | 0, /* RF_RAMP7, LNA 3 = 0dB */
878 400, 861 (0 << 10) | 0, /* RF_RAMP8, LNA 3 */
879 (2 << 9) | 0, /* 0x35 = 21dB */ 862 (0 << 10) | 0, /* GAIN_4_1, LNA 4 = 0dB */
880 (0 << 9) | 168, /* 0x36 */ 863 (0 << 10) | 0, /* GAIN_4_2, LNA 4 */
881 (2 << 9) | 168, /* 0x37 = 29dB */
882 (0 << 9) | 400, /* 0x38 */
883}; 864};
884 865
885struct slope { 866struct slope {
@@ -1089,70 +1070,69 @@ static void dib0090_set_bbramp_pwm(struct dib0090_state *state, const u16 * cfg)
1089void dib0090_pwm_gain_reset(struct dvb_frontend *fe) 1070void dib0090_pwm_gain_reset(struct dvb_frontend *fe)
1090{ 1071{
1091 struct dib0090_state *state = fe->tuner_priv; 1072 struct dib0090_state *state = fe->tuner_priv;
1092 /* reset the AGC */ 1073 u16 *bb_ramp = (u16 *)&bb_ramp_pwm_normal; /* default baseband config */
1074 u16 *rf_ramp = NULL;
1075 u8 en_pwm_rf_mux = 1;
1093 1076
1077 /* reset the AGC */
1094 if (state->config->use_pwm_agc) { 1078 if (state->config->use_pwm_agc) {
1095#ifdef CONFIG_BAND_SBAND
1096 if (state->current_band == BAND_SBAND) {
1097 dib0090_set_rframp_pwm(state, rf_ramp_pwm_sband);
1098 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_boost);
1099 } else
1100#endif
1101#ifdef CONFIG_BAND_CBAND
1102 if (state->current_band == BAND_CBAND) { 1079 if (state->current_band == BAND_CBAND) {
1103 if (state->identity.in_soc) { 1080 if (state->identity.in_soc) {
1104 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs); 1081 bb_ramp = (u16 *)&bb_ramp_pwm_normal_socs;
1105 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1) 1082 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1)
1106 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_8090); 1083 rf_ramp = (u16 *)&rf_ramp_pwm_cband_8090;
1107 else if (state->identity.version == SOC_7090_P1G_11R1 1084 else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1) {
1108 || state->identity.version == SOC_7090_P1G_21R1) {
1109 if (state->config->is_dib7090e) { 1085 if (state->config->is_dib7090e) {
1110 if (state->rf_ramp == NULL) 1086 if (state->rf_ramp == NULL)
1111 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_7090e_sensitivity); 1087 rf_ramp = (u16 *)&rf_ramp_pwm_cband_7090e_sensitivity;
1112 else 1088 else
1113 dib0090_set_rframp_pwm(state, state->rf_ramp); 1089 rf_ramp = (u16 *)state->rf_ramp;
1114 } else 1090 } else
1115 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_7090); 1091 rf_ramp = (u16 *)&rf_ramp_pwm_cband_7090p;
1116 } 1092 }
1117 } else { 1093 } else
1118 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband); 1094 rf_ramp = (u16 *)&rf_ramp_pwm_cband;
1119 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1120 }
1121 } else 1095 } else
1122#endif 1096
1123#ifdef CONFIG_BAND_VHF 1097 if (state->current_band == BAND_VHF) {
1124 if (state->current_band == BAND_VHF) { 1098 if (state->identity.in_soc) {
1125 if (state->identity.in_soc) { 1099 bb_ramp = (u16 *)&bb_ramp_pwm_normal_socs;
1126 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs); 1100 /* rf_ramp = &rf_ramp_pwm_vhf_socs; */ /* TODO */
1127 } else { 1101 } else
1128 dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf); 1102 rf_ramp = (u16 *)&rf_ramp_pwm_vhf;
1129 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 1103 } else if (state->current_band == BAND_UHF) {
1104 if (state->identity.in_soc) {
1105 bb_ramp = (u16 *)&bb_ramp_pwm_normal_socs;
1106 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1)
1107 rf_ramp = (u16 *)&rf_ramp_pwm_uhf_8090;
1108 else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1)
1109 rf_ramp = (u16 *)&rf_ramp_pwm_uhf_7090;
1110 } else
1111 rf_ramp = (u16 *)&rf_ramp_pwm_uhf;
1130 } 1112 }
1113 if (rf_ramp)
1114 dib0090_set_rframp_pwm(state, rf_ramp);
1115 dib0090_set_bbramp_pwm(state, bb_ramp);
1116
1117 /* activate the ramp generator using PWM control */
1118 dprintk("ramp RF gain = %d BAND = %s version = %d", state->rf_ramp[0], (state->current_band == BAND_CBAND) ? "CBAND" : "NOT CBAND", state->identity.version & 0x1f);
1119
1120 if ((state->rf_ramp[0] == 0) || (state->current_band == BAND_CBAND && (state->identity.version & 0x1f) <= P1D_E_F)) {
1121 dprintk("DE-Engage mux for direct gain reg control");
1122 en_pwm_rf_mux = 0;
1131 } else 1123 } else
1132#endif 1124 dprintk("Engage mux for PWM control");
1133 {
1134 if (state->identity.in_soc) {
1135 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1)
1136 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_8090);
1137 else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1)
1138 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_7090);
1139 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1140 } else {
1141 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf);
1142 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1143 }
1144 }
1145 1125
1146 if (state->rf_ramp[0] != 0) 1126 dib0090_write_reg(state, 0x32, (en_pwm_rf_mux << 12) | (en_pwm_rf_mux << 11));
1147 dib0090_write_reg(state, 0x32, (3 << 11));
1148 else
1149 dib0090_write_reg(state, 0x32, (0 << 11));
1150 1127
1151 dib0090_write_reg(state, 0x04, 0x03); 1128 /* Set fast servo cutoff to start AGC; 0 = 1KHz ; 1 = 50Hz ; 2 = 150Hz ; 3 = 50KHz ; 4 = servo fast*/
1152 dib0090_write_reg(state, 0x39, (1 << 10)); 1129 if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1)
1130 dib0090_write_reg(state, 0x04, 3);
1131 else
1132 dib0090_write_reg(state, 0x04, 1);
1133 dib0090_write_reg(state, 0x39, (1 << 10)); /* 0 gain by default */
1153 } 1134 }
1154} 1135}
1155
1156EXPORT_SYMBOL(dib0090_pwm_gain_reset); 1136EXPORT_SYMBOL(dib0090_pwm_gain_reset);
1157 1137
1158void dib0090_set_dc_servo(struct dvb_frontend *fe, u8 DC_servo_cutoff) 1138void dib0090_set_dc_servo(struct dvb_frontend *fe, u8 DC_servo_cutoff)
@@ -1193,22 +1173,22 @@ int dib0090_gain_control(struct dvb_frontend *fe)
1193#endif 1173#endif
1194#ifdef CONFIG_BAND_VHF 1174#ifdef CONFIG_BAND_VHF
1195 if (state->current_band == BAND_VHF && !state->identity.p1g) { 1175 if (state->current_band == BAND_VHF && !state->identity.p1g) {
1196 dib0090_set_rframp(state, rf_ramp_vhf); 1176 dib0090_set_rframp(state, rf_ramp_pwm_vhf);
1197 dib0090_set_bbramp(state, bb_ramp_boost); 1177 dib0090_set_bbramp(state, bb_ramp_pwm_normal);
1198 } else 1178 } else
1199#endif 1179#endif
1200#ifdef CONFIG_BAND_CBAND 1180#ifdef CONFIG_BAND_CBAND
1201 if (state->current_band == BAND_CBAND && !state->identity.p1g) { 1181 if (state->current_band == BAND_CBAND && !state->identity.p1g) {
1202 dib0090_set_rframp(state, rf_ramp_cband); 1182 dib0090_set_rframp(state, rf_ramp_pwm_cband);
1203 dib0090_set_bbramp(state, bb_ramp_boost); 1183 dib0090_set_bbramp(state, bb_ramp_pwm_normal);
1204 } else 1184 } else
1205#endif 1185#endif
1206 if ((state->current_band == BAND_CBAND || state->current_band == BAND_VHF) && state->identity.p1g) { 1186 if ((state->current_band == BAND_CBAND || state->current_band == BAND_VHF) && state->identity.p1g) {
1207 dib0090_set_rframp(state, rf_ramp_cband_broadmatching); 1187 dib0090_set_rframp(state, rf_ramp_pwm_cband_7090p);
1208 dib0090_set_bbramp(state, bb_ramp_boost); 1188 dib0090_set_bbramp(state, bb_ramp_pwm_normal_socs);
1209 } else { 1189 } else {
1210 dib0090_set_rframp(state, rf_ramp_uhf); 1190 dib0090_set_rframp(state, rf_ramp_pwm_uhf);
1211 dib0090_set_bbramp(state, bb_ramp_boost); 1191 dib0090_set_bbramp(state, bb_ramp_pwm_normal);
1212 } 1192 }
1213 1193
1214 dib0090_write_reg(state, 0x32, 0); 1194 dib0090_write_reg(state, 0x32, 0);
@@ -1553,14 +1533,16 @@ static void dib0090_set_EFUSE(struct dib0090_state *state)
1553 1533
1554 if ((c >= CAP_VALUE_MAX) || (c <= CAP_VALUE_MIN)) 1534 if ((c >= CAP_VALUE_MAX) || (c <= CAP_VALUE_MIN))
1555 c = 32; 1535 c = 32;
1536 else
1537 c += 14;
1556 if ((h >= HR_MAX) || (h <= HR_MIN)) 1538 if ((h >= HR_MAX) || (h <= HR_MIN))
1557 h = 34; 1539 h = 34;
1558 if ((n >= POLY_MAX) || (n <= POLY_MIN)) 1540 if ((n >= POLY_MAX) || (n <= POLY_MIN))
1559 n = 3; 1541 n = 3;
1560 1542
1561 dib0090_write_reg(state, 0x13, (h << 10)) ; 1543 dib0090_write_reg(state, 0x13, (h << 10));
1562 e2 = (n<<11) | ((h>>2)<<6) | (c); 1544 e2 = (n << 11) | ((h >> 2)<<6) | c;
1563 dib0090_write_reg(state, 0x2, e2) ; /* Load the BB_2 */ 1545 dib0090_write_reg(state, 0x2, e2); /* Load the BB_2 */
1564 } 1546 }
1565} 1547}
1566 1548
diff --git a/drivers/media/dvb-frontends/dib3000mc.h b/drivers/media/dvb-frontends/dib3000mc.h
index d75ffad2d752..129d1425516a 100644
--- a/drivers/media/dvb-frontends/dib3000mc.h
+++ b/drivers/media/dvb-frontends/dib3000mc.h
@@ -13,6 +13,8 @@
13#ifndef DIB3000MC_H 13#ifndef DIB3000MC_H
14#define DIB3000MC_H 14#define DIB3000MC_H
15 15
16#include <linux/kconfig.h>
17
16#include "dibx000_common.h" 18#include "dibx000_common.h"
17 19
18struct dib3000mc_config { 20struct dib3000mc_config {
@@ -39,8 +41,7 @@ struct dib3000mc_config {
39#define DEFAULT_DIB3000MC_I2C_ADDRESS 16 41#define DEFAULT_DIB3000MC_I2C_ADDRESS 16
40#define DEFAULT_DIB3000P_I2C_ADDRESS 24 42#define DEFAULT_DIB3000P_I2C_ADDRESS 24
41 43
42#if defined(CONFIG_DVB_DIB3000MC) || (defined(CONFIG_DVB_DIB3000MC_MODULE) && \ 44#if IS_ENABLED(CONFIG_DVB_DIB3000MC)
43 defined(MODULE))
44extern struct dvb_frontend *dib3000mc_attach(struct i2c_adapter *i2c_adap, 45extern struct dvb_frontend *dib3000mc_attach(struct i2c_adapter *i2c_adap,
45 u8 i2c_addr, 46 u8 i2c_addr,
46 struct dib3000mc_config *cfg); 47 struct dib3000mc_config *cfg);
diff --git a/drivers/media/dvb-frontends/dib7000m.h b/drivers/media/dvb-frontends/dib7000m.h
index 81fcf2241c64..b585413f9a29 100644
--- a/drivers/media/dvb-frontends/dib7000m.h
+++ b/drivers/media/dvb-frontends/dib7000m.h
@@ -1,6 +1,8 @@
1#ifndef DIB7000M_H 1#ifndef DIB7000M_H
2#define DIB7000M_H 2#define DIB7000M_H
3 3
4#include <linux/kconfig.h>
5
4#include "dibx000_common.h" 6#include "dibx000_common.h"
5 7
6struct dib7000m_config { 8struct dib7000m_config {
@@ -38,8 +40,7 @@ struct dib7000m_config {
38 40
39#define DEFAULT_DIB7000M_I2C_ADDRESS 18 41#define DEFAULT_DIB7000M_I2C_ADDRESS 18
40 42
41#if defined(CONFIG_DVB_DIB7000M) || (defined(CONFIG_DVB_DIB7000M_MODULE) && \ 43#if IS_ENABLED(CONFIG_DVB_DIB7000M)
42 defined(MODULE))
43extern struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap, 44extern struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap,
44 u8 i2c_addr, 45 u8 i2c_addr,
45 struct dib7000m_config *cfg); 46 struct dib7000m_config *cfg);
diff --git a/drivers/media/dvb-frontends/dib7000p.c b/drivers/media/dvb-frontends/dib7000p.c
index 3e1eefada0e8..effb87f773b0 100644
--- a/drivers/media/dvb-frontends/dib7000p.c
+++ b/drivers/media/dvb-frontends/dib7000p.c
@@ -429,6 +429,13 @@ int dib7000p_get_agc_values(struct dvb_frontend *fe,
429} 429}
430EXPORT_SYMBOL(dib7000p_get_agc_values); 430EXPORT_SYMBOL(dib7000p_get_agc_values);
431 431
432int dib7000p_set_agc1_min(struct dvb_frontend *fe, u16 v)
433{
434 struct dib7000p_state *state = fe->demodulator_priv;
435 return dib7000p_write_word(state, 108, v);
436}
437EXPORT_SYMBOL(dib7000p_set_agc1_min);
438
432static void dib7000p_reset_pll(struct dib7000p_state *state) 439static void dib7000p_reset_pll(struct dib7000p_state *state)
433{ 440{
434 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0]; 441 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0];
@@ -821,6 +828,7 @@ static int dib7000p_agc_startup(struct dvb_frontend *demod)
821 u8 agc_split; 828 u8 agc_split;
822 u16 reg; 829 u16 reg;
823 u32 upd_demod_gain_period = 0x1000; 830 u32 upd_demod_gain_period = 0x1000;
831 s32 frequency_offset = 0;
824 832
825 switch (state->agc_state) { 833 switch (state->agc_state) {
826 case 0: 834 case 0:
@@ -841,7 +849,14 @@ static int dib7000p_agc_startup(struct dvb_frontend *demod)
841 if (dib7000p_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency / 1000)) != 0) 849 if (dib7000p_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency / 1000)) != 0)
842 return -1; 850 return -1;
843 851
844 dib7000p_set_dds(state, 0); 852 if (demod->ops.tuner_ops.get_frequency) {
853 u32 frequency_tuner;
854
855 demod->ops.tuner_ops.get_frequency(demod, &frequency_tuner);
856 frequency_offset = (s32)frequency_tuner / 1000 - ch->frequency / 1000;
857 }
858
859 dib7000p_set_dds(state, frequency_offset);
845 ret = 7; 860 ret = 7;
846 (*agc_state)++; 861 (*agc_state)++;
847 break; 862 break;
diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
index b61b03a6e1ed..d08cdff59bdf 100644
--- a/drivers/media/dvb-frontends/dib7000p.h
+++ b/drivers/media/dvb-frontends/dib7000p.h
@@ -1,6 +1,8 @@
1#ifndef DIB7000P_H 1#ifndef DIB7000P_H
2#define DIB7000P_H 2#define DIB7000P_H
3 3
4#include <linux/kconfig.h>
5
4#include "dibx000_common.h" 6#include "dibx000_common.h"
5 7
6struct dib7000p_config { 8struct dib7000p_config {
@@ -44,8 +46,7 @@ struct dib7000p_config {
44 46
45#define DEFAULT_DIB7000P_I2C_ADDRESS 18 47#define DEFAULT_DIB7000P_I2C_ADDRESS 18
46 48
47#if defined(CONFIG_DVB_DIB7000P) || (defined(CONFIG_DVB_DIB7000P_MODULE) && \ 49#if IS_ENABLED(CONFIG_DVB_DIB7000P)
48 defined(MODULE))
49extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg); 50extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
50extern struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int); 51extern struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
51extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]); 52extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]);
@@ -62,6 +63,7 @@ extern struct i2c_adapter *dib7090_get_i2c_tuner(struct dvb_frontend *fe);
62extern int dib7090_slave_reset(struct dvb_frontend *fe); 63extern int dib7090_slave_reset(struct dvb_frontend *fe);
63extern int dib7000p_get_agc_values(struct dvb_frontend *fe, 64extern int dib7000p_get_agc_values(struct dvb_frontend *fe,
64 u16 *agc_global, u16 *agc1, u16 *agc2, u16 *wbd); 65 u16 *agc_global, u16 *agc1, u16 *agc2, u16 *wbd);
66extern int dib7000p_set_agc1_min(struct dvb_frontend *fe, u16 v);
65#else 67#else
66static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg) 68static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg)
67{ 69{
@@ -153,6 +155,12 @@ static inline int dib7000p_get_agc_values(struct dvb_frontend *fe,
153 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 155 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
154 return -ENODEV; 156 return -ENODEV;
155} 157}
158
159static inline int dib7000p_set_agc1_min(struct dvb_frontend *fe, u16 v)
160{
161 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
162 return -ENODEV;
163}
156#endif 164#endif
157 165
158#endif 166#endif
diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c
index 1f3bcb5a1de8..a54182dd0e91 100644
--- a/drivers/media/dvb-frontends/dib8000.c
+++ b/drivers/media/dvb-frontends/dib8000.c
@@ -23,8 +23,8 @@
23#define LAYER_B 2 23#define LAYER_B 2
24#define LAYER_C 3 24#define LAYER_C 3
25 25
26#define FE_CALLBACK_TIME_NEVER 0xffffffff
27#define MAX_NUMBER_OF_FRONTENDS 6 26#define MAX_NUMBER_OF_FRONTENDS 6
27/* #define DIB8000_AGC_FREEZE */
28 28
29static int debug; 29static int debug;
30module_param(debug, int, 0644); 30module_param(debug, int, 0644);
@@ -32,8 +32,6 @@ MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
32 32
33#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB8000: "); printk(args); printk("\n"); } } while (0) 33#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB8000: "); printk(args); printk("\n"); } } while (0)
34 34
35#define FE_STATUS_TUNE_FAILED 0
36
37struct i2c_device { 35struct i2c_device {
38 struct i2c_adapter *adap; 36 struct i2c_adapter *adap;
39 u8 addr; 37 u8 addr;
@@ -42,6 +40,23 @@ struct i2c_device {
42 struct mutex *i2c_buffer_lock; 40 struct mutex *i2c_buffer_lock;
43}; 41};
44 42
43enum param_loop_step {
44 LOOP_TUNE_1,
45 LOOP_TUNE_2
46};
47
48enum dib8000_autosearch_step {
49 AS_START = 0,
50 AS_SEARCHING_FFT,
51 AS_SEARCHING_GUARD,
52 AS_DONE = 100,
53};
54
55enum timeout_mode {
56 SYMBOL_DEPENDENT_OFF = 0,
57 SYMBOL_DEPENDENT_ON,
58};
59
45struct dib8000_state { 60struct dib8000_state {
46 struct dib8000_config cfg; 61 struct dib8000_config cfg;
47 62
@@ -72,7 +87,7 @@ struct dib8000_state {
72 u16 revision; 87 u16 revision;
73 u8 isdbt_cfg_loaded; 88 u8 isdbt_cfg_loaded;
74 enum frontend_tune_state tune_state; 89 enum frontend_tune_state tune_state;
75 u32 status; 90 s32 status;
76 91
77 struct dvb_frontend *fe[MAX_NUMBER_OF_FRONTENDS]; 92 struct dvb_frontend *fe[MAX_NUMBER_OF_FRONTENDS];
78 93
@@ -85,6 +100,30 @@ struct dib8000_state {
85 100
86 u16 tuner_enable; 101 u16 tuner_enable;
87 struct i2c_adapter dib8096p_tuner_adap; 102 struct i2c_adapter dib8096p_tuner_adap;
103 u16 current_demod_bw;
104
105 u16 seg_mask;
106 u16 seg_diff_mask;
107 u16 mode;
108 u8 layer_b_nb_seg;
109 u8 layer_c_nb_seg;
110
111 u8 channel_parameters_set;
112 u16 autosearch_state;
113 u16 found_nfft;
114 u16 found_guard;
115 u8 subchannel;
116 u8 symbol_duration;
117 u32 timeout;
118 u8 longest_intlv_layer;
119 u16 output_mode;
120
121#ifdef DIB8000_AGC_FREEZE
122 u16 agc1_max;
123 u16 agc1_min;
124 u16 agc2_max;
125 u16 agc2_min;
126#endif
88}; 127};
89 128
90enum dib8000_power_mode { 129enum dib8000_power_mode {
@@ -338,9 +377,9 @@ static void dib8000_set_acquisition_mode(struct dib8000_state *state)
338static int dib8000_set_output_mode(struct dvb_frontend *fe, int mode) 377static int dib8000_set_output_mode(struct dvb_frontend *fe, int mode)
339{ 378{
340 struct dib8000_state *state = fe->demodulator_priv; 379 struct dib8000_state *state = fe->demodulator_priv;
341
342 u16 outreg, fifo_threshold, smo_mode, sram = 0x0205; /* by default SDRAM deintlv is enabled */ 380 u16 outreg, fifo_threshold, smo_mode, sram = 0x0205; /* by default SDRAM deintlv is enabled */
343 381
382 state->output_mode = mode;
344 outreg = 0; 383 outreg = 0;
345 fifo_threshold = 1792; 384 fifo_threshold = 1792;
346 smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1); 385 smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1);
@@ -399,8 +438,9 @@ static int dib8000_set_output_mode(struct dvb_frontend *fe, int mode)
399static int dib8000_set_diversity_in(struct dvb_frontend *fe, int onoff) 438static int dib8000_set_diversity_in(struct dvb_frontend *fe, int onoff)
400{ 439{
401 struct dib8000_state *state = fe->demodulator_priv; 440 struct dib8000_state *state = fe->demodulator_priv;
402 u16 sync_wait = dib8000_read_word(state, 273) & 0xfff0; 441 u16 tmp, sync_wait = dib8000_read_word(state, 273) & 0xfff0;
403 442
443 dprintk("set diversity input to %i", onoff);
404 if (!state->differential_constellation) { 444 if (!state->differential_constellation) {
405 dib8000_write_word(state, 272, 1 << 9); //dvsy_off_lmod4 = 1 445 dib8000_write_word(state, 272, 1 << 9); //dvsy_off_lmod4 = 1
406 dib8000_write_word(state, 273, sync_wait | (1 << 2) | 2); // sync_enable = 1; comb_mode = 2 446 dib8000_write_word(state, 273, sync_wait | (1 << 2) | 2); // sync_enable = 1; comb_mode = 2
@@ -424,6 +464,13 @@ static int dib8000_set_diversity_in(struct dvb_frontend *fe, int onoff)
424 dib8000_write_word(state, 271, 1); 464 dib8000_write_word(state, 271, 1);
425 break; 465 break;
426 } 466 }
467
468 if (state->revision == 0x8002) {
469 tmp = dib8000_read_word(state, 903);
470 dib8000_write_word(state, 903, tmp & ~(1 << 3));
471 msleep(30);
472 dib8000_write_word(state, 903, tmp | (1 << 3));
473 }
427 return 0; 474 return 0;
428} 475}
429 476
@@ -468,27 +515,6 @@ static void dib8000_set_power_mode(struct dib8000_state *state, enum dib8000_pow
468 dib8000_write_word(state, 1280, reg_1280); 515 dib8000_write_word(state, 1280, reg_1280);
469} 516}
470 517
471static int dib8000_init_sdram(struct dib8000_state *state)
472{
473 u16 reg = 0;
474 dprintk("Init sdram");
475
476 reg = dib8000_read_word(state, 274)&0xfff0;
477 /* P_dintlv_delay_ram = 7 because of MobileSdram */
478 dib8000_write_word(state, 274, reg | 0x7);
479
480 dib8000_write_word(state, 1803, (7<<2));
481
482 reg = dib8000_read_word(state, 1280);
483 /* force restart P_restart_sdram */
484 dib8000_write_word(state, 1280, reg | (1<<2));
485
486 /* release restart P_restart_sdram */
487 dib8000_write_word(state, 1280, reg);
488
489 return 0;
490}
491
492static int dib8000_set_adc_state(struct dib8000_state *state, enum dibx000_adc_states no) 518static int dib8000_set_adc_state(struct dib8000_state *state, enum dibx000_adc_states no)
493{ 519{
494 int ret = 0; 520 int ret = 0;
@@ -584,18 +610,23 @@ static int dib8000_set_bandwidth(struct dvb_frontend *fe, u32 bw)
584 610
585static int dib8000_sad_calib(struct dib8000_state *state) 611static int dib8000_sad_calib(struct dib8000_state *state)
586{ 612{
613 u8 sad_sel = 3;
614
587 if (state->revision == 0x8090) { 615 if (state->revision == 0x8090) {
588 dprintk("%s: the sad calibration is not needed for the dib8096P", 616 dib8000_write_word(state, 922, (sad_sel << 2));
589 __func__); 617 dib8000_write_word(state, 923, 2048);
590 return 0; 618
591 } 619 dib8000_write_word(state, 922, (sad_sel << 2) | 0x1);
592 /* internal */ 620 dib8000_write_word(state, 922, (sad_sel << 2));
593 dib8000_write_word(state, 923, (0 << 1) | (0 << 0)); 621 } else {
594 dib8000_write_word(state, 924, 776); // 0.625*3.3 / 4096 622 /* internal */
623 dib8000_write_word(state, 923, (0 << 1) | (0 << 0));
624 dib8000_write_word(state, 924, 776);
595 625
596 /* do the calibration */ 626 /* do the calibration */
597 dib8000_write_word(state, 923, (1 << 0)); 627 dib8000_write_word(state, 923, (1 << 0));
598 dib8000_write_word(state, 923, (0 << 0)); 628 dib8000_write_word(state, 923, (0 << 0));
629 }
599 630
600 msleep(1); 631 msleep(1);
601 return 0; 632 return 0;
@@ -609,8 +640,8 @@ int dib8000_set_wbd_ref(struct dvb_frontend *fe, u16 value)
609 state->wbd_ref = value; 640 state->wbd_ref = value;
610 return dib8000_write_word(state, 106, value); 641 return dib8000_write_word(state, 106, value);
611} 642}
612
613EXPORT_SYMBOL(dib8000_set_wbd_ref); 643EXPORT_SYMBOL(dib8000_set_wbd_ref);
644
614static void dib8000_reset_pll_common(struct dib8000_state *state, const struct dibx000_bandwidth_config *bw) 645static void dib8000_reset_pll_common(struct dib8000_state *state, const struct dibx000_bandwidth_config *bw)
615{ 646{
616 dprintk("ifreq: %d %x, inversion: %d", bw->ifreq, bw->ifreq, bw->ifreq >> 25); 647 dprintk("ifreq: %d %x, inversion: %d", bw->ifreq, bw->ifreq, bw->ifreq >> 25);
@@ -685,20 +716,23 @@ static void dib8000_reset_pll(struct dib8000_state *state)
685} 716}
686 717
687int dib8000_update_pll(struct dvb_frontend *fe, 718int dib8000_update_pll(struct dvb_frontend *fe,
688 struct dibx000_bandwidth_config *pll) 719 struct dibx000_bandwidth_config *pll, u32 bw, u8 ratio)
689{ 720{
690 struct dib8000_state *state = fe->demodulator_priv; 721 struct dib8000_state *state = fe->demodulator_priv;
691 u16 reg_1857, reg_1856 = dib8000_read_word(state, 1856); 722 u16 reg_1857, reg_1856 = dib8000_read_word(state, 1856);
692 u8 loopdiv, prediv; 723 u8 loopdiv, prediv, oldprediv = state->cfg.pll->pll_prediv ;
693 u32 internal, xtal; 724 u32 internal, xtal;
694 725
695 /* get back old values */ 726 /* get back old values */
696 prediv = reg_1856 & 0x3f; 727 prediv = reg_1856 & 0x3f;
697 loopdiv = (reg_1856 >> 6) & 0x3f; 728 loopdiv = (reg_1856 >> 6) & 0x3f;
698 729
699 if ((pll != NULL) && (pll->pll_prediv != prediv || 730 if ((pll == NULL) || (pll->pll_prediv == prediv &&
700 pll->pll_ratio != loopdiv)) { 731 pll->pll_ratio == loopdiv))
701 dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)", prediv, pll->pll_prediv, loopdiv, pll->pll_ratio); 732 return -EINVAL;
733
734 dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)", prediv, pll->pll_prediv, loopdiv, pll->pll_ratio);
735 if (state->revision == 0x8090) {
702 reg_1856 &= 0xf000; 736 reg_1856 &= 0xf000;
703 reg_1857 = dib8000_read_word(state, 1857); 737 reg_1857 = dib8000_read_word(state, 1857);
704 /* disable PLL */ 738 /* disable PLL */
@@ -729,10 +763,33 @@ int dib8000_update_pll(struct dvb_frontend *fe,
729 reg_1856 = dib8000_read_word(state, 1856); 763 reg_1856 = dib8000_read_word(state, 1856);
730 dprintk("PLL Updated with prediv = %d and loopdiv = %d", 764 dprintk("PLL Updated with prediv = %d and loopdiv = %d",
731 reg_1856&0x3f, (reg_1856>>6)&0x3f); 765 reg_1856&0x3f, (reg_1856>>6)&0x3f);
766 } else {
767 if (bw != state->current_demod_bw) {
768 /** Bandwidth change => force PLL update **/
769 dprintk("PLL: Bandwidth Change %d MHz -> %d MHz (prediv: %d->%d)", state->current_demod_bw / 1000, bw / 1000, oldprediv, state->cfg.pll->pll_prediv);
770
771 if (state->cfg.pll->pll_prediv != oldprediv) {
772 /** Full PLL change only if prediv is changed **/
773
774 /** full update => bypass and reconfigure **/
775 dprintk("PLL: New Setting for %d MHz Bandwidth (prediv: %d, ratio: %d)", bw/1000, state->cfg.pll->pll_prediv, state->cfg.pll->pll_ratio);
776 dib8000_write_word(state, 902, dib8000_read_word(state, 902) | (1<<3)); /* bypass PLL */
777 dib8000_reset_pll(state);
778 dib8000_write_word(state, 898, 0x0004); /* sad */
779 } else
780 ratio = state->cfg.pll->pll_ratio;
732 781
733 return 0; 782 state->current_demod_bw = bw;
734 } 783 }
735 return -EINVAL; 784
785 if (ratio != 0) {
786 /** ratio update => only change ratio **/
787 dprintk("PLL: Update ratio (prediv: %d, ratio: %d)", state->cfg.pll->pll_prediv, ratio);
788 dib8000_write_word(state, 901, (state->cfg.pll->pll_prediv << 8) | (ratio << 0)); /* only the PLL ratio is updated. */
789 }
790}
791
792 return 0;
736} 793}
737EXPORT_SYMBOL(dib8000_update_pll); 794EXPORT_SYMBOL(dib8000_update_pll);
738 795
@@ -928,7 +985,7 @@ static int dib8000_reset(struct dvb_frontend *fe)
928 dib8000_set_power_mode(state, DIB8000_POWER_ALL); 985 dib8000_set_power_mode(state, DIB8000_POWER_ALL);
929 986
930 /* always leave the VBG voltage on - it consumes almost nothing but takes a long time to start */ 987 /* always leave the VBG voltage on - it consumes almost nothing but takes a long time to start */
931 dib8000_set_adc_state(state, DIBX000_VBG_ENABLE); 988 dib8000_set_adc_state(state, DIBX000_ADC_OFF);
932 989
933 /* restart all parts */ 990 /* restart all parts */
934 dib8000_write_word(state, 770, 0xffff); 991 dib8000_write_word(state, 770, 0xffff);
@@ -992,12 +1049,11 @@ static int dib8000_reset(struct dvb_frontend *fe)
992 l = *n++; 1049 l = *n++;
993 } 1050 }
994 } 1051 }
995 if (state->revision != 0x8090) 1052
996 dib8000_write_word(state, 903, (0 << 4) | 2);
997 state->isdbt_cfg_loaded = 0; 1053 state->isdbt_cfg_loaded = 0;
998 1054
999 //div_cfg override for special configs 1055 //div_cfg override for special configs
1000 if (state->cfg.div_cfg != 0) 1056 if ((state->revision != 8090) && (state->cfg.div_cfg != 0))
1001 dib8000_write_word(state, 903, state->cfg.div_cfg); 1057 dib8000_write_word(state, 903, state->cfg.div_cfg);
1002 1058
1003 /* unforce divstr regardless whether i2c enumeration was done or not */ 1059 /* unforce divstr regardless whether i2c enumeration was done or not */
@@ -1006,10 +1062,12 @@ static int dib8000_reset(struct dvb_frontend *fe)
1006 dib8000_set_bandwidth(fe, 6000); 1062 dib8000_set_bandwidth(fe, 6000);
1007 1063
1008 dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON); 1064 dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON);
1009 if (state->revision != 0x8090) { 1065 dib8000_sad_calib(state);
1010 dib8000_sad_calib(state); 1066 if (state->revision != 0x8090)
1011 dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF); 1067 dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
1012 } 1068
1069 /* ber_rs_len = 3 */
1070 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & ~0x60) | (3 << 5));
1013 1071
1014 dib8000_set_power_mode(state, DIB8000_POWER_INTERFACE_ONLY); 1072 dib8000_set_power_mode(state, DIB8000_POWER_INTERFACE_ONLY);
1015 1073
@@ -1441,6 +1499,7 @@ static int dib8096p_set_output_mode(struct dvb_frontend *fe, int mode)
1441 u8 prefer_mpeg_mux_use = 1; 1499 u8 prefer_mpeg_mux_use = 1;
1442 int ret = 0; 1500 int ret = 0;
1443 1501
1502 state->output_mode = mode;
1444 dib8096p_host_bus_drive(state, 1); 1503 dib8096p_host_bus_drive(state, 1);
1445 1504
1446 fifo_threshold = 1792; 1505 fifo_threshold = 1792;
@@ -1879,782 +1938,643 @@ static const u16 adc_target_16dB[11] = {
1879}; 1938};
1880static const u8 permu_seg[] = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 }; 1939static const u8 permu_seg[] = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 };
1881 1940
1882static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosearching) 1941static u16 dib8000_set_layer(struct dib8000_state *state, u8 layer_index, u16 max_constellation)
1883{ 1942{
1884 u16 mode, max_constellation, seg_diff_mask = 0, nbseg_diff = 0; 1943 u8 cr, constellation, time_intlv;
1885 u8 guard, crate, constellation, timeI; 1944 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
1886 u16 i, coeff[4], P_cfr_left_edge = 0, P_cfr_right_edge = 0, seg_mask13 = 0x1fff; // All 13 segments enabled
1887 const s16 *ncoeff = NULL, *ana_fe;
1888 u16 tmcc_pow = 0;
1889 u16 coff_pow = 0x2800;
1890 u16 init_prbs = 0xfff;
1891 u16 ana_gain = 0;
1892
1893 if (state->revision == 0x8090)
1894 dib8000_init_sdram(state);
1895 1945
1896 if (state->ber_monitored_layer != LAYER_ALL) 1946 switch (c->layer[layer_index].modulation) {
1897 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & 0x60) | state->ber_monitored_layer); 1947 case DQPSK:
1898 else
1899 dib8000_write_word(state, 285, dib8000_read_word(state, 285) & 0x60);
1900
1901 i = dib8000_read_word(state, 26) & 1; // P_dds_invspec
1902 dib8000_write_word(state, 26, state->fe[0]->dtv_property_cache.inversion^i);
1903
1904 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode) {
1905 //compute new dds_freq for the seg and adjust prbs
1906 int seg_offset =
1907 state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx -
1908 (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) -
1909 (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2);
1910 int clk = state->cfg.pll->internal;
1911 u32 segtodds = ((u32) (430 << 23) / clk) << 3; // segtodds = SegBW / Fclk * pow(2,26)
1912 int dds_offset = seg_offset * segtodds;
1913 int new_dds, sub_channel;
1914 if ((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1915 dds_offset -= (int)(segtodds / 2);
1916
1917 if (state->cfg.pll->ifreq == 0) {
1918 if ((state->fe[0]->dtv_property_cache.inversion ^ i) == 0) {
1919 dib8000_write_word(state, 26, dib8000_read_word(state, 26) | 1);
1920 new_dds = dds_offset;
1921 } else
1922 new_dds = dds_offset;
1923
1924 // We shift tuning frequency if the wanted segment is :
1925 // - the segment of center frequency with an odd total number of segments
1926 // - the segment to the left of center frequency with an even total number of segments
1927 // - the segment to the right of center frequency with an even total number of segments
1928 if ((state->fe[0]->dtv_property_cache.delivery_system == SYS_ISDBT)
1929 && (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1)
1930 && (((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2)
1931 && (state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx ==
1932 ((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
1933 || (((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1934 && (state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx == (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2)))
1935 || (((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1936 && (state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx ==
1937 ((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
1938 )) {
1939 new_dds -= ((u32) (850 << 22) / clk) << 4; // new_dds = 850 (freq shift in KHz) / Fclk * pow(2,26)
1940 }
1941 } else {
1942 if ((state->fe[0]->dtv_property_cache.inversion ^ i) == 0)
1943 new_dds = state->cfg.pll->ifreq - dds_offset;
1944 else
1945 new_dds = state->cfg.pll->ifreq + dds_offset;
1946 }
1947 dib8000_write_word(state, 27, (u16) ((new_dds >> 16) & 0x01ff));
1948 dib8000_write_word(state, 28, (u16) (new_dds & 0xffff));
1949 if (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2)
1950 sub_channel = ((state->fe[0]->dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset) + 1) % 41) / 3;
1951 else
1952 sub_channel = ((state->fe[0]->dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset)) % 41) / 3;
1953 sub_channel -= 6;
1954
1955 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_2K
1956 || state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_4K) {
1957 dib8000_write_word(state, 219, dib8000_read_word(state, 219) | 0x1); //adp_pass =1
1958 dib8000_write_word(state, 190, dib8000_read_word(state, 190) | (0x1 << 14)); //pha3_force_pha_shift = 1
1959 } else {
1960 dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe); //adp_pass =0
1961 dib8000_write_word(state, 190, dib8000_read_word(state, 190) & 0xbfff); //pha3_force_pha_shift = 0
1962 }
1963
1964 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
1965 case TRANSMISSION_MODE_2K:
1966 switch (sub_channel) {
1967 case -6:
1968 init_prbs = 0x0;
1969 break; // 41, 0, 1
1970 case -5:
1971 init_prbs = 0x423;
1972 break; // 02~04
1973 case -4:
1974 init_prbs = 0x9;
1975 break; // 05~07
1976 case -3:
1977 init_prbs = 0x5C7;
1978 break; // 08~10
1979 case -2:
1980 init_prbs = 0x7A6;
1981 break; // 11~13
1982 case -1:
1983 init_prbs = 0x3D8;
1984 break; // 14~16
1985 case 0:
1986 init_prbs = 0x527;
1987 break; // 17~19
1988 case 1:
1989 init_prbs = 0x7FF;
1990 break; // 20~22
1991 case 2:
1992 init_prbs = 0x79B;
1993 break; // 23~25
1994 case 3:
1995 init_prbs = 0x3D6;
1996 break; // 26~28
1997 case 4:
1998 init_prbs = 0x3A2;
1999 break; // 29~31
2000 case 5:
2001 init_prbs = 0x53B;
2002 break; // 32~34
2003 case 6:
2004 init_prbs = 0x2F4;
2005 break; // 35~37
2006 default:
2007 case 7:
2008 init_prbs = 0x213;
2009 break; // 38~40
2010 }
2011 break;
2012
2013 case TRANSMISSION_MODE_4K:
2014 switch (sub_channel) {
2015 case -6:
2016 init_prbs = 0x0;
2017 break; // 41, 0, 1
2018 case -5:
2019 init_prbs = 0x208;
2020 break; // 02~04
2021 case -4:
2022 init_prbs = 0xC3;
2023 break; // 05~07
2024 case -3:
2025 init_prbs = 0x7B9;
2026 break; // 08~10
2027 case -2:
2028 init_prbs = 0x423;
2029 break; // 11~13
2030 case -1:
2031 init_prbs = 0x5C7;
2032 break; // 14~16
2033 case 0:
2034 init_prbs = 0x3D8;
2035 break; // 17~19
2036 case 1:
2037 init_prbs = 0x7FF;
2038 break; // 20~22
2039 case 2:
2040 init_prbs = 0x3D6;
2041 break; // 23~25
2042 case 3:
2043 init_prbs = 0x53B;
2044 break; // 26~28
2045 case 4:
2046 init_prbs = 0x213;
2047 break; // 29~31
2048 case 5:
2049 init_prbs = 0x29;
2050 break; // 32~34
2051 case 6:
2052 init_prbs = 0xD0;
2053 break; // 35~37
2054 default:
2055 case 7:
2056 init_prbs = 0x48E;
2057 break; // 38~40
2058 }
2059 break;
2060
2061 default:
2062 case TRANSMISSION_MODE_8K:
2063 switch (sub_channel) {
2064 case -6:
2065 init_prbs = 0x0;
2066 break; // 41, 0, 1
2067 case -5:
2068 init_prbs = 0x740;
2069 break; // 02~04
2070 case -4:
2071 init_prbs = 0x069;
2072 break; // 05~07
2073 case -3:
2074 init_prbs = 0x7DD;
2075 break; // 08~10
2076 case -2:
2077 init_prbs = 0x208;
2078 break; // 11~13
2079 case -1:
2080 init_prbs = 0x7B9;
2081 break; // 14~16
2082 case 0:
2083 init_prbs = 0x5C7;
2084 break; // 17~19
2085 case 1:
2086 init_prbs = 0x7FF;
2087 break; // 20~22
2088 case 2:
2089 init_prbs = 0x53B;
2090 break; // 23~25
2091 case 3:
2092 init_prbs = 0x29;
2093 break; // 26~28
2094 case 4:
2095 init_prbs = 0x48E;
2096 break; // 29~31
2097 case 5:
2098 init_prbs = 0x4C4;
2099 break; // 32~34
2100 case 6:
2101 init_prbs = 0x367;
2102 break; // 33~37
2103 default:
2104 case 7:
2105 init_prbs = 0x684;
2106 break; // 38~40
2107 }
2108 break;
2109 }
2110 } else {
2111 dib8000_write_word(state, 27, (u16) ((state->cfg.pll->ifreq >> 16) & 0x01ff));
2112 dib8000_write_word(state, 28, (u16) (state->cfg.pll->ifreq & 0xffff));
2113 dib8000_write_word(state, 26, (u16) ((state->cfg.pll->ifreq >> 25) & 0x0003));
2114 }
2115 /*P_mode == ?? */
2116 dib8000_write_word(state, 10, (seq << 4));
2117 // dib8000_write_word(state, 287, (dib8000_read_word(state, 287) & 0xe000) | 0x1000);
2118
2119 switch (state->fe[0]->dtv_property_cache.guard_interval) {
2120 case GUARD_INTERVAL_1_32:
2121 guard = 0;
2122 break;
2123 case GUARD_INTERVAL_1_16:
2124 guard = 1;
2125 break;
2126 case GUARD_INTERVAL_1_8:
2127 guard = 2;
2128 break;
2129 case GUARD_INTERVAL_1_4:
2130 default:
2131 guard = 3;
2132 break;
2133 }
2134
2135 dib8000_write_word(state, 1, (init_prbs << 2) | (guard & 0x3)); // ADDR 1
2136
2137 max_constellation = DQPSK;
2138 for (i = 0; i < 3; i++) {
2139 switch (state->fe[0]->dtv_property_cache.layer[i].modulation) {
2140 case DQPSK:
2141 constellation = 0; 1948 constellation = 0;
2142 break; 1949 break;
2143 case QPSK: 1950 case QPSK:
2144 constellation = 1; 1951 constellation = 1;
2145 break; 1952 break;
2146 case QAM_16: 1953 case QAM_16:
2147 constellation = 2; 1954 constellation = 2;
2148 break; 1955 break;
2149 case QAM_64: 1956 case QAM_64:
2150 default: 1957 default:
2151 constellation = 3; 1958 constellation = 3;
2152 break; 1959 break;
2153 } 1960 }
2154 1961
2155 switch (state->fe[0]->dtv_property_cache.layer[i].fec) { 1962 switch (c->layer[layer_index].fec) {
2156 case FEC_1_2: 1963 case FEC_1_2:
2157 crate = 1; 1964 cr = 1;
2158 break; 1965 break;
2159 case FEC_2_3: 1966 case FEC_2_3:
2160 crate = 2; 1967 cr = 2;
2161 break; 1968 break;
2162 case FEC_3_4: 1969 case FEC_3_4:
2163 crate = 3; 1970 cr = 3;
2164 break; 1971 break;
2165 case FEC_5_6: 1972 case FEC_5_6:
2166 crate = 5; 1973 cr = 5;
2167 break; 1974 break;
2168 case FEC_7_8: 1975 case FEC_7_8:
2169 default: 1976 default:
2170 crate = 7; 1977 cr = 7;
2171 break; 1978 break;
2172 } 1979 }
2173 1980
2174 if ((state->fe[0]->dtv_property_cache.layer[i].interleaving > 0) && 1981 if ((c->layer[layer_index].interleaving > 0) && ((c->layer[layer_index].interleaving <= 3) || (c->layer[layer_index].interleaving == 4 && c->isdbt_sb_mode == 1)))
2175 ((state->fe[0]->dtv_property_cache.layer[i].interleaving <= 3) || 1982 time_intlv = c->layer[layer_index].interleaving;
2176 (state->fe[0]->dtv_property_cache.layer[i].interleaving == 4 && state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1)) 1983 else
2177 ) 1984 time_intlv = 0;
2178 timeI = state->fe[0]->dtv_property_cache.layer[i].interleaving; 1985
2179 else 1986 dib8000_write_word(state, 2 + layer_index, (constellation << 10) | ((c->layer[layer_index].segment_count & 0xf) << 6) | (cr << 3) | time_intlv);
2180 timeI = 0; 1987 if (c->layer[layer_index].segment_count > 0) {
2181 dib8000_write_word(state, 2 + i, (constellation << 10) | ((state->fe[0]->dtv_property_cache.layer[i].segment_count & 0xf) << 6) | 1988 switch (max_constellation) {
2182 (crate << 3) | timeI); 1989 case DQPSK:
2183 if (state->fe[0]->dtv_property_cache.layer[i].segment_count > 0) { 1990 case QPSK:
2184 switch (max_constellation) { 1991 if (c->layer[layer_index].modulation == QAM_16 || c->layer[layer_index].modulation == QAM_64)
2185 case DQPSK: 1992 max_constellation = c->layer[layer_index].modulation;
2186 case QPSK:
2187 if (state->fe[0]->dtv_property_cache.layer[i].modulation == QAM_16 ||
2188 state->fe[0]->dtv_property_cache.layer[i].modulation == QAM_64)
2189 max_constellation = state->fe[0]->dtv_property_cache.layer[i].modulation;
2190 break; 1993 break;
2191 case QAM_16: 1994 case QAM_16:
2192 if (state->fe[0]->dtv_property_cache.layer[i].modulation == QAM_64) 1995 if (c->layer[layer_index].modulation == QAM_64)
2193 max_constellation = state->fe[0]->dtv_property_cache.layer[i].modulation; 1996 max_constellation = c->layer[layer_index].modulation;
2194 break; 1997 break;
2195 }
2196 } 1998 }
2197 } 1999 }
2198 2000
2199 mode = fft_to_mode(state); 2001 return max_constellation;
2002}
2200 2003
2201 //dib8000_write_word(state, 5, 13); /*p_last_seg = 13*/ 2004static const u16 adp_Q64[4] = {0x0148, 0xfff0, 0x00a4, 0xfff8}; /* P_adp_regul_cnt 0.04, P_adp_noise_cnt -0.002, P_adp_regul_ext 0.02, P_adp_noise_ext -0.001 */
2005static const u16 adp_Q16[4] = {0x023d, 0xffdf, 0x00a4, 0xfff0}; /* P_adp_regul_cnt 0.07, P_adp_noise_cnt -0.004, P_adp_regul_ext 0.02, P_adp_noise_ext -0.002 */
2006static const u16 adp_Qdefault[4] = {0x099a, 0xffae, 0x0333, 0xfff8}; /* P_adp_regul_cnt 0.3, P_adp_noise_cnt -0.01, P_adp_regul_ext 0.1, P_adp_noise_ext -0.002 */
2007static u16 dib8000_adp_fine_tune(struct dib8000_state *state, u16 max_constellation)
2008{
2009 u16 i, ana_gain = 0;
2010 const u16 *adp;
2202 2011
2203 dib8000_write_word(state, 274, (dib8000_read_word(state, 274) & 0xffcf) | 2012 /* channel estimation fine configuration */
2204 ((state->fe[0]->dtv_property_cache.isdbt_partial_reception & 1) << 5) | ((state->fe[0]->dtv_property_cache. 2013 switch (max_constellation) {
2205 isdbt_sb_mode & 1) << 4)); 2014 case QAM_64:
2015 ana_gain = 0x7;
2016 adp = &adp_Q64[0];
2017 break;
2018 case QAM_16:
2019 ana_gain = 0x7;
2020 adp = &adp_Q16[0];
2021 break;
2022 default:
2023 ana_gain = 0;
2024 adp = &adp_Qdefault[0];
2025 break;
2026 }
2206 2027
2207 dprintk("mode = %d ; guard = %d", mode, state->fe[0]->dtv_property_cache.guard_interval); 2028 for (i = 0; i < 4; i++)
2029 dib8000_write_word(state, 215 + i, adp[i]);
2208 2030
2209 /* signal optimization parameter */ 2031 return ana_gain;
2032}
2210 2033
2211 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception) { 2034static void dib8000_update_ana_gain(struct dib8000_state *state, u16 ana_gain)
2212 seg_diff_mask = (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) << permu_seg[0]; 2035{
2213 for (i = 1; i < 3; i++) 2036 u16 i;
2214 nbseg_diff += 2037
2215 (state->fe[0]->dtv_property_cache.layer[i].modulation == DQPSK) * state->fe[0]->dtv_property_cache.layer[i].segment_count; 2038 dib8000_write_word(state, 116, ana_gain);
2216 for (i = 0; i < nbseg_diff; i++) 2039
2217 seg_diff_mask |= 1 << permu_seg[i + 1]; 2040 /* update ADC target depending on ana_gain */
2218 } else { 2041 if (ana_gain) { /* set -16dB ADC target for ana_gain=-1 */
2219 for (i = 0; i < 3; i++) 2042 for (i = 0; i < 10; i++)
2220 nbseg_diff += 2043 dib8000_write_word(state, 80 + i, adc_target_16dB[i]);
2221 (state->fe[0]->dtv_property_cache.layer[i].modulation == DQPSK) * state->fe[0]->dtv_property_cache.layer[i].segment_count; 2044 } else { /* set -22dB ADC target for ana_gain=0 */
2222 for (i = 0; i < nbseg_diff; i++) 2045 for (i = 0; i < 10; i++)
2223 seg_diff_mask |= 1 << permu_seg[i]; 2046 dib8000_write_word(state, 80 + i, adc_target_16dB[i] - 355);
2224 } 2047 }
2225 dprintk("nbseg_diff = %X (%d)", seg_diff_mask, seg_diff_mask); 2048}
2226 2049
2227 state->differential_constellation = (seg_diff_mask != 0); 2050static void dib8000_load_ana_fe_coefs(struct dib8000_state *state, const s16 *ana_fe)
2228 if (state->revision != 0x8090) 2051{
2229 dib8000_set_diversity_in(state->fe[0], state->diversity_onoff); 2052 u16 mode = 0;
2230 else
2231 dib8096p_set_diversity_in(state->fe[0], state->diversity_onoff);
2232 2053
2233 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) { 2054 if (state->isdbt_cfg_loaded == 0)
2234 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 1) 2055 for (mode = 0; mode < 24; mode++)
2235 seg_mask13 = 0x00E0; 2056 dib8000_write_word(state, 117 + mode, ana_fe[mode]);
2236 else // 1-segment 2057}
2237 seg_mask13 = 0x0040;
2238 } else
2239 seg_mask13 = 0x1fff;
2240 2058
2241 // WRITE: Mode & Diff mask 2059static const u16 lut_prbs_2k[14] = {
2242 dib8000_write_word(state, 0, (mode << 13) | seg_diff_mask); 2060 0, 0x423, 0x009, 0x5C7, 0x7A6, 0x3D8, 0x527, 0x7FF, 0x79B, 0x3D6, 0x3A2, 0x53B, 0x2F4, 0x213
2061};
2062static const u16 lut_prbs_4k[14] = {
2063 0, 0x208, 0x0C3, 0x7B9, 0x423, 0x5C7, 0x3D8, 0x7FF, 0x3D6, 0x53B, 0x213, 0x029, 0x0D0, 0x48E
2064};
2065static const u16 lut_prbs_8k[14] = {
2066 0, 0x740, 0x069, 0x7DD, 0x208, 0x7B9, 0x5C7, 0x7FF, 0x53B, 0x029, 0x48E, 0x4C4, 0x367, 0x684
2067};
2243 2068
2244 if ((seg_diff_mask) || (state->fe[0]->dtv_property_cache.isdbt_sb_mode)) 2069static u16 dib8000_get_init_prbs(struct dib8000_state *state, u16 subchannel)
2245 dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200); 2070{
2246 else 2071 int sub_channel_prbs_group = 0;
2247 dib8000_write_word(state, 268, (2 << 9) | 39); //init value
2248 2072
2249 // ---- SMALL ---- 2073 sub_channel_prbs_group = (subchannel / 3) + 1;
2250 // P_small_seg_diff 2074 dprintk("sub_channel_prbs_group = %d , subchannel =%d prbs = 0x%04x", sub_channel_prbs_group, subchannel, lut_prbs_8k[sub_channel_prbs_group]);
2251 dib8000_write_word(state, 352, seg_diff_mask); // ADDR 352
2252 2075
2253 dib8000_write_word(state, 353, seg_mask13); // ADDR 353 2076 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
2077 case TRANSMISSION_MODE_2K:
2078 return lut_prbs_2k[sub_channel_prbs_group];
2079 case TRANSMISSION_MODE_4K:
2080 return lut_prbs_4k[sub_channel_prbs_group];
2081 default:
2082 case TRANSMISSION_MODE_8K:
2083 return lut_prbs_8k[sub_channel_prbs_group];
2084 }
2085}
2086
2087static void dib8000_set_13seg_channel(struct dib8000_state *state)
2088{
2089 u16 i;
2090 u16 coff_pow = 0x2800;
2254 2091
2255/* // P_small_narrow_band=0, P_small_last_seg=13, P_small_offset_num_car=5 */ 2092 state->seg_mask = 0x1fff; /* All 13 segments enabled */
2256 2093
2257 // ---- SMALL ---- 2094 /* ---- COFF ---- Carloff, the most robust --- */
2258 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) { 2095 if (state->isdbt_cfg_loaded == 0) { /* if not Sound Broadcasting mode : put default values for 13 segments */
2259 switch (state->fe[0]->dtv_property_cache.transmission_mode) { 2096 dib8000_write_word(state, 180, (16 << 6) | 9);
2097 dib8000_write_word(state, 187, (4 << 12) | (8 << 5) | 0x2);
2098 coff_pow = 0x2800;
2099 for (i = 0; i < 6; i++)
2100 dib8000_write_word(state, 181+i, coff_pow);
2101
2102 /* P_ctrl_corm_thres4pre_freq_inh=1, P_ctrl_pre_freq_mode_sat=1 */
2103 /* P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 3, P_pre_freq_win_len=1 */
2104 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (3 << 5) | 1);
2105
2106 /* P_ctrl_pre_freq_win_len=8, P_ctrl_pre_freq_thres_lockin=6 */
2107 dib8000_write_word(state, 340, (8 << 6) | (6 << 0));
2108 /* P_ctrl_pre_freq_thres_lockout=4, P_small_use_tmcc/ac/cp=1 */
2109 dib8000_write_word(state, 341, (4 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
2110
2111 dib8000_write_word(state, 228, 0); /* default value */
2112 dib8000_write_word(state, 265, 31); /* default value */
2113 dib8000_write_word(state, 205, 0x200f); /* init value */
2114 }
2115
2116 /*
2117 * make the cpil_coff_lock more robust but slower p_coff_winlen
2118 * 6bits; p_coff_thres_lock 6bits (for coff lock if needed)
2119 */
2120
2121 if (state->cfg.pll->ifreq == 0)
2122 dib8000_write_word(state, 266, ~state->seg_mask | state->seg_diff_mask | 0x40); /* P_equal_noise_seg_inh */
2123
2124 dib8000_load_ana_fe_coefs(state, ana_fe_coeff_13seg);
2125}
2126
2127static void dib8000_set_subchannel_prbs(struct dib8000_state *state, u16 init_prbs)
2128{
2129 u16 reg_1;
2130
2131 reg_1 = dib8000_read_word(state, 1);
2132 dib8000_write_word(state, 1, (init_prbs << 2) | (reg_1 & 0x3)); /* ADDR 1 */
2133}
2134
2135static void dib8000_small_fine_tune(struct dib8000_state *state)
2136{
2137 u16 i;
2138 const s16 *ncoeff;
2139 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2140
2141 dib8000_write_word(state, 352, state->seg_diff_mask);
2142 dib8000_write_word(state, 353, state->seg_mask);
2143
2144 /* P_small_coef_ext_enable=ISDB-Tsb, P_small_narrow_band=ISDB-Tsb, P_small_last_seg=13, P_small_offset_num_car=5 */
2145 dib8000_write_word(state, 351, (c->isdbt_sb_mode << 9) | (c->isdbt_sb_mode << 8) | (13 << 4) | 5);
2146
2147 if (c->isdbt_sb_mode) {
2148 /* ---- SMALL ---- */
2149 switch (c->transmission_mode) {
2260 case TRANSMISSION_MODE_2K: 2150 case TRANSMISSION_MODE_2K:
2261 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) { 2151 if (c->isdbt_partial_reception == 0) { /* 1-seg */
2262 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) 2152 if (c->layer[0].modulation == DQPSK) /* DQPSK */
2263 ncoeff = coeff_2k_sb_1seg_dqpsk; 2153 ncoeff = coeff_2k_sb_1seg_dqpsk;
2264 else // QPSK or QAM 2154 else /* QPSK or QAM */
2265 ncoeff = coeff_2k_sb_1seg; 2155 ncoeff = coeff_2k_sb_1seg;
2266 } else { // 3-segments 2156 } else { /* 3-segments */
2267 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) { 2157 if (c->layer[0].modulation == DQPSK) { /* DQPSK on central segment */
2268 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) 2158 if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
2269 ncoeff = coeff_2k_sb_3seg_0dqpsk_1dqpsk; 2159 ncoeff = coeff_2k_sb_3seg_0dqpsk_1dqpsk;
2270 else // QPSK or QAM on external segments 2160 else /* QPSK or QAM on external segments */
2271 ncoeff = coeff_2k_sb_3seg_0dqpsk; 2161 ncoeff = coeff_2k_sb_3seg_0dqpsk;
2272 } else { // QPSK or QAM on central segment 2162 } else { /* QPSK or QAM on central segment */
2273 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) 2163 if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
2274 ncoeff = coeff_2k_sb_3seg_1dqpsk; 2164 ncoeff = coeff_2k_sb_3seg_1dqpsk;
2275 else // QPSK or QAM on external segments 2165 else /* QPSK or QAM on external segments */
2276 ncoeff = coeff_2k_sb_3seg; 2166 ncoeff = coeff_2k_sb_3seg;
2167 }
2277 } 2168 }
2278 } 2169 break;
2279 break;
2280
2281 case TRANSMISSION_MODE_4K: 2170 case TRANSMISSION_MODE_4K:
2282 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) { 2171 if (c->isdbt_partial_reception == 0) { /* 1-seg */
2283 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) 2172 if (c->layer[0].modulation == DQPSK) /* DQPSK */
2284 ncoeff = coeff_4k_sb_1seg_dqpsk; 2173 ncoeff = coeff_4k_sb_1seg_dqpsk;
2285 else // QPSK or QAM 2174 else /* QPSK or QAM */
2286 ncoeff = coeff_4k_sb_1seg; 2175 ncoeff = coeff_4k_sb_1seg;
2287 } else { // 3-segments 2176 } else { /* 3-segments */
2288 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) { 2177 if (c->layer[0].modulation == DQPSK) { /* DQPSK on central segment */
2289 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) { 2178 if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
2290 ncoeff = coeff_4k_sb_3seg_0dqpsk_1dqpsk; 2179 ncoeff = coeff_4k_sb_3seg_0dqpsk_1dqpsk;
2291 } else { // QPSK or QAM on external segments 2180 else /* QPSK or QAM on external segments */
2292 ncoeff = coeff_4k_sb_3seg_0dqpsk; 2181 ncoeff = coeff_4k_sb_3seg_0dqpsk;
2182 } else { /* QPSK or QAM on central segment */
2183 if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
2184 ncoeff = coeff_4k_sb_3seg_1dqpsk;
2185 else /* QPSK or QAM on external segments */
2186 ncoeff = coeff_4k_sb_3seg;
2293 } 2187 }
2294 } else { // QPSK or QAM on central segment
2295 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) {
2296 ncoeff = coeff_4k_sb_3seg_1dqpsk;
2297 } else // QPSK or QAM on external segments
2298 ncoeff = coeff_4k_sb_3seg;
2299 } 2188 }
2300 } 2189 break;
2301 break;
2302
2303 case TRANSMISSION_MODE_AUTO: 2190 case TRANSMISSION_MODE_AUTO:
2304 case TRANSMISSION_MODE_8K: 2191 case TRANSMISSION_MODE_8K:
2305 default: 2192 default:
2306 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) { 2193 if (c->isdbt_partial_reception == 0) { /* 1-seg */
2307 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) 2194 if (c->layer[0].modulation == DQPSK) /* DQPSK */
2308 ncoeff = coeff_8k_sb_1seg_dqpsk; 2195 ncoeff = coeff_8k_sb_1seg_dqpsk;
2309 else // QPSK or QAM 2196 else /* QPSK or QAM */
2310 ncoeff = coeff_8k_sb_1seg; 2197 ncoeff = coeff_8k_sb_1seg;
2311 } else { // 3-segments 2198 } else { /* 3-segments */
2312 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) { 2199 if (c->layer[0].modulation == DQPSK) { /* DQPSK on central segment */
2313 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) { 2200 if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
2314 ncoeff = coeff_8k_sb_3seg_0dqpsk_1dqpsk; 2201 ncoeff = coeff_8k_sb_3seg_0dqpsk_1dqpsk;
2315 } else { // QPSK or QAM on external segments 2202 else /* QPSK or QAM on external segments */
2316 ncoeff = coeff_8k_sb_3seg_0dqpsk; 2203 ncoeff = coeff_8k_sb_3seg_0dqpsk;
2204 } else { /* QPSK or QAM on central segment */
2205 if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
2206 ncoeff = coeff_8k_sb_3seg_1dqpsk;
2207 else /* QPSK or QAM on external segments */
2208 ncoeff = coeff_8k_sb_3seg;
2317 } 2209 }
2318 } else { // QPSK or QAM on central segment
2319 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) {
2320 ncoeff = coeff_8k_sb_3seg_1dqpsk;
2321 } else // QPSK or QAM on external segments
2322 ncoeff = coeff_8k_sb_3seg;
2323 } 2210 }
2324 } 2211 break;
2325 break;
2326 } 2212 }
2213
2327 for (i = 0; i < 8; i++) 2214 for (i = 0; i < 8; i++)
2328 dib8000_write_word(state, 343 + i, ncoeff[i]); 2215 dib8000_write_word(state, 343 + i, ncoeff[i]);
2329 } 2216 }
2217}
2330 2218
2331 // P_small_coef_ext_enable=ISDB-Tsb, P_small_narrow_band=ISDB-Tsb, P_small_last_seg=13, P_small_offset_num_car=5 2219static const u16 coff_thres_1seg[3] = {300, 150, 80};
2332 dib8000_write_word(state, 351, 2220static const u16 coff_thres_3seg[3] = {350, 300, 250};
2333 (state->fe[0]->dtv_property_cache.isdbt_sb_mode << 9) | (state->fe[0]->dtv_property_cache.isdbt_sb_mode << 8) | (13 << 4) | 5); 2221static void dib8000_set_sb_channel(struct dib8000_state *state)
2222{
2223 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2224 const u16 *coff;
2225 u16 i;
2334 2226
2335 // ---- COFF ---- 2227 if (c->transmission_mode == TRANSMISSION_MODE_2K || c->transmission_mode == TRANSMISSION_MODE_4K) {
2336 // Carloff, the most robust 2228 dib8000_write_word(state, 219, dib8000_read_word(state, 219) | 0x1); /* adp_pass =1 */
2337 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) { 2229 dib8000_write_word(state, 190, dib8000_read_word(state, 190) | (0x1 << 14)); /* pha3_force_pha_shift = 1 */
2230 } else {
2231 dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe); /* adp_pass =0 */
2232 dib8000_write_word(state, 190, dib8000_read_word(state, 190) & 0xbfff); /* pha3_force_pha_shift = 0 */
2233 }
2338 2234
2339 // P_coff_cpil_alpha=4, P_coff_inh=0, P_coff_cpil_winlen=64 2235 if (c->isdbt_partial_reception == 1) /* 3-segments */
2340 // P_coff_narrow_band=1, P_coff_square_val=1, P_coff_one_seg=~partial_rcpt, P_coff_use_tmcc=1, P_coff_use_ac=1 2236 state->seg_mask = 0x00E0;
2341 dib8000_write_word(state, 187, 2237 else /* 1-segment */
2342 (4 << 12) | (0 << 11) | (63 << 5) | (0x3 << 3) | ((~state->fe[0]->dtv_property_cache.isdbt_partial_reception & 1) << 2) 2238 state->seg_mask = 0x0040;
2343 | 0x3);
2344 2239
2345/* // P_small_coef_ext_enable = 1 */ 2240 dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200);
2346/* dib8000_write_word(state, 351, dib8000_read_word(state, 351) | 0x200); */
2347 2241
2348 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) { 2242 /* ---- COFF ---- Carloff, the most robust --- */
2243 /* P_coff_cpil_alpha=4, P_coff_inh=0, P_coff_cpil_winlen=64, P_coff_narrow_band=1, P_coff_square_val=1, P_coff_one_seg=~partial_rcpt, P_coff_use_tmcc=1, P_coff_use_ac=1 */
2244 dib8000_write_word(state, 187, (4 << 12) | (0 << 11) | (63 << 5) | (0x3 << 3) | ((~c->isdbt_partial_reception & 1) << 2) | 0x3);
2349 2245
2350 // P_coff_winlen=63, P_coff_thres_lock=15, P_coff_one_seg_width= (P_mode == 3) , P_coff_one_seg_sym= (P_mode-1) 2246 dib8000_write_word(state, 340, (16 << 6) | (8 << 0)); /* P_ctrl_pre_freq_win_len=16, P_ctrl_pre_freq_thres_lockin=8 */
2351 if (mode == 3) 2247 dib8000_write_word(state, 341, (6 << 3) | (1 << 2) | (1 << 1) | (1 << 0));/* P_ctrl_pre_freq_thres_lockout=6, P_small_use_tmcc/ac/cp=1 */
2352 dib8000_write_word(state, 180, 0x1fcf | ((mode - 1) << 14));
2353 else
2354 dib8000_write_word(state, 180, 0x0fcf | ((mode - 1) << 14));
2355 // P_ctrl_corm_thres4pre_freq_inh=1,P_ctrl_pre_freq_mode_sat=1,
2356 // P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 5, P_pre_freq_win_len=4
2357 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (5 << 5) | 4);
2358 // P_ctrl_pre_freq_win_len=16, P_ctrl_pre_freq_thres_lockin=8
2359 dib8000_write_word(state, 340, (16 << 6) | (8 << 0));
2360 // P_ctrl_pre_freq_thres_lockout=6, P_small_use_tmcc/ac/cp=1
2361 dib8000_write_word(state, 341, (6 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
2362
2363 // P_coff_corthres_8k, 4k, 2k and P_coff_cpilthres_8k, 4k, 2k
2364 dib8000_write_word(state, 181, 300);
2365 dib8000_write_word(state, 182, 150);
2366 dib8000_write_word(state, 183, 80);
2367 dib8000_write_word(state, 184, 300);
2368 dib8000_write_word(state, 185, 150);
2369 dib8000_write_word(state, 186, 80);
2370 } else { // Sound Broadcasting mode 3 seg
2371 // P_coff_one_seg_sym= 1, P_coff_one_seg_width= 1, P_coff_winlen=63, P_coff_thres_lock=15
2372 /* if (mode == 3) */
2373 /* dib8000_write_word(state, 180, 0x2fca | ((0) << 14)); */
2374 /* else */
2375 /* dib8000_write_word(state, 180, 0x2fca | ((1) << 14)); */
2376 dib8000_write_word(state, 180, 0x1fcf | (1 << 14));
2377
2378 // P_ctrl_corm_thres4pre_freq_inh = 1, P_ctrl_pre_freq_mode_sat=1,
2379 // P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 4, P_pre_freq_win_len=4
2380 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (4 << 5) | 4);
2381 // P_ctrl_pre_freq_win_len=16, P_ctrl_pre_freq_thres_lockin=8
2382 dib8000_write_word(state, 340, (16 << 6) | (8 << 0));
2383 //P_ctrl_pre_freq_thres_lockout=6, P_small_use_tmcc/ac/cp=1
2384 dib8000_write_word(state, 341, (6 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
2385
2386 // P_coff_corthres_8k, 4k, 2k and P_coff_cpilthres_8k, 4k, 2k
2387 dib8000_write_word(state, 181, 350);
2388 dib8000_write_word(state, 182, 300);
2389 dib8000_write_word(state, 183, 250);
2390 dib8000_write_word(state, 184, 350);
2391 dib8000_write_word(state, 185, 300);
2392 dib8000_write_word(state, 186, 250);
2393 }
2394 2248
2395 } else if (state->isdbt_cfg_loaded == 0) { // if not Sound Broadcasting mode : put default values for 13 segments 2249 /* Sound Broadcasting mode 1 seg */
2396 dib8000_write_word(state, 180, (16 << 6) | 9); 2250 if (c->isdbt_partial_reception == 0) {
2397 dib8000_write_word(state, 187, (4 << 12) | (8 << 5) | 0x2); 2251 /* P_coff_winlen=63, P_coff_thres_lock=15, P_coff_one_seg_width = (P_mode == 3) , P_coff_one_seg_sym = (P_mode-1) */
2398 coff_pow = 0x2800; 2252 if (state->mode == 3)
2399 for (i = 0; i < 6; i++) 2253 dib8000_write_word(state, 180, 0x1fcf | ((state->mode - 1) << 14));
2400 dib8000_write_word(state, 181 + i, coff_pow); 2254 else
2255 dib8000_write_word(state, 180, 0x0fcf | ((state->mode - 1) << 14));
2401 2256
2402 // P_ctrl_corm_thres4pre_freq_inh=1, P_ctrl_pre_freq_mode_sat=1, 2257 /* P_ctrl_corm_thres4pre_freq_inh=1,P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 5, P_pre_freq_win_len=4 */
2403 // P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 3, P_pre_freq_win_len=1 2258 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (5 << 5) | 4);
2404 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (3 << 5) | 1); 2259 coff = &coff_thres_1seg[0];
2260 } else { /* Sound Broadcasting mode 3 seg */
2261 dib8000_write_word(state, 180, 0x1fcf | (1 << 14));
2262 /* P_ctrl_corm_thres4pre_freq_inh = 1, P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 4, P_pre_freq_win_len=4 */
2263 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (4 << 5) | 4);
2264 coff = &coff_thres_3seg[0];
2265 }
2405 2266
2406 // P_ctrl_pre_freq_win_len=8, P_ctrl_pre_freq_thres_lockin=6 2267 dib8000_write_word(state, 228, 1); /* P_2d_mode_byp=1 */
2407 dib8000_write_word(state, 340, (8 << 6) | (6 << 0)); 2268 dib8000_write_word(state, 205, dib8000_read_word(state, 205) & 0xfff0); /* P_cspu_win_cut = 0 */
2408 // P_ctrl_pre_freq_thres_lockout=4, P_small_use_tmcc/ac/cp=1 2269
2409 dib8000_write_word(state, 341, (4 << 3) | (1 << 2) | (1 << 1) | (1 << 0)); 2270 if (c->isdbt_partial_reception == 0 && c->transmission_mode == TRANSMISSION_MODE_2K)
2271 dib8000_write_word(state, 265, 15); /* P_equal_noise_sel = 15 */
2272
2273 /* Write COFF thres */
2274 for (i = 0 ; i < 3; i++) {
2275 dib8000_write_word(state, 181+i, coff[i]);
2276 dib8000_write_word(state, 184+i, coff[i]);
2410 } 2277 }
2411 // ---- FFT ----
2412 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1 && state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2413 dib8000_write_word(state, 178, 64); // P_fft_powrange=64
2414 else
2415 dib8000_write_word(state, 178, 32); // P_fft_powrange=32
2416 2278
2417 /* make the cpil_coff_lock more robust but slower p_coff_winlen 2279 /*
2280 * make the cpil_coff_lock more robust but slower p_coff_winlen
2418 * 6bits; p_coff_thres_lock 6bits (for coff lock if needed) 2281 * 6bits; p_coff_thres_lock 6bits (for coff lock if needed)
2419 */ 2282 */
2420 /* if ( ( nbseg_diff>0)&&(nbseg_diff<13)) 2283
2421 dib8000_write_word(state, 187, (dib8000_read_word(state, 187) & 0xfffb) | (1 << 3)); */ 2284 dib8000_write_word(state, 266, ~state->seg_mask | state->seg_diff_mask); /* P_equal_noise_seg_inh */
2422 2285
2423 dib8000_write_word(state, 189, ~seg_mask13 | seg_diff_mask); /* P_lmod4_seg_inh */ 2286 if (c->isdbt_partial_reception == 0)
2424 dib8000_write_word(state, 192, ~seg_mask13 | seg_diff_mask); /* P_pha3_seg_inh */ 2287 dib8000_write_word(state, 178, 64); /* P_fft_powrange = 64 */
2425 dib8000_write_word(state, 225, ~seg_mask13 | seg_diff_mask); /* P_tac_seg_inh */
2426 if ((!state->fe[0]->dtv_property_cache.isdbt_sb_mode) && (state->cfg.pll->ifreq == 0))
2427 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask | 0x40); /* P_equal_noise_seg_inh */
2428 else
2429 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask); /* P_equal_noise_seg_inh */
2430 dib8000_write_word(state, 287, ~seg_mask13 | 0x1000); /* P_tmcc_seg_inh */
2431 //dib8000_write_word(state, 288, ~seg_mask13 | seg_diff_mask); /* P_tmcc_seg_eq_inh */
2432 if (!autosearching)
2433 dib8000_write_word(state, 288, (~seg_mask13 | seg_diff_mask) & 0x1fff); /* P_tmcc_seg_eq_inh */
2434 else 2288 else
2435 dib8000_write_word(state, 288, 0x1fff); //disable equalisation of the tmcc when autosearch to be able to find the DQPSK channels. 2289 dib8000_write_word(state, 178, 32); /* P_fft_powrange = 32 */
2436 dprintk("287 = %X (%d)", ~seg_mask13 | 0x1000, ~seg_mask13 | 0x1000); 2290}
2437
2438 dib8000_write_word(state, 211, seg_mask13 & (~seg_diff_mask)); /* P_des_seg_enabled */
2439
2440 /* offset loop parameters */
2441 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2442 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2443 /* P_timf_alpha = (11-P_mode), P_corm_alpha=6, P_corm_thres=0x80 */
2444 dib8000_write_word(state, 32, ((11 - mode) << 12) | (6 << 8) | 0x40);
2445
2446 else // Sound Broadcasting mode 3 seg
2447 /* P_timf_alpha = (10-P_mode), P_corm_alpha=6, P_corm_thres=0x80 */
2448 dib8000_write_word(state, 32, ((10 - mode) << 12) | (6 << 8) | 0x60);
2449 } else
2450 // TODO in 13 seg, timf_alpha can always be the same or not ?
2451 /* P_timf_alpha = (9-P_mode, P_corm_alpha=6, P_corm_thres=0x80 */
2452 dib8000_write_word(state, 32, ((9 - mode) << 12) | (6 << 8) | 0x80);
2453
2454 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2455 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2456 /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (11-P_mode) */
2457 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (10 - mode));
2458
2459 else // Sound Broadcasting mode 3 seg
2460 /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (10-P_mode) */
2461 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (9 - mode));
2462 } else
2463 /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = 9 */
2464 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (8 - mode));
2465 2291
2466 /* P_dvsy_sync_wait - reuse mode */ 2292static void dib8000_set_isdbt_common_channel(struct dib8000_state *state, u8 seq, u8 autosearching)
2467 switch (state->fe[0]->dtv_property_cache.transmission_mode) { 2293{
2468 case TRANSMISSION_MODE_8K: 2294 u16 p_cfr_left_edge = 0, p_cfr_right_edge = 0;
2469 mode = 256; 2295 u16 tmcc_pow = 0, ana_gain = 0, tmp = 0, i = 0, nbseg_diff = 0 ;
2470 break; 2296 u16 max_constellation = DQPSK;
2471 case TRANSMISSION_MODE_4K: 2297 int init_prbs;
2472 mode = 128; 2298 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2473 break; 2299
2474 default: 2300 /* P_mode */
2475 case TRANSMISSION_MODE_2K: 2301 dib8000_write_word(state, 10, (seq << 4));
2476 mode = 64; 2302
2477 break; 2303 /* init mode */
2304 state->mode = fft_to_mode(state);
2305
2306 /* set guard */
2307 tmp = dib8000_read_word(state, 1);
2308 dib8000_write_word(state, 1, (tmp&0xfffc) | (c->guard_interval & 0x3));
2309
2310 dib8000_write_word(state, 274, (dib8000_read_word(state, 274) & 0xffcf) | ((c->isdbt_partial_reception & 1) << 5) | ((c->isdbt_sb_mode & 1) << 4));
2311
2312 /* signal optimization parameter */
2313 if (c->isdbt_partial_reception) {
2314 state->seg_diff_mask = (c->layer[0].modulation == DQPSK) << permu_seg[0];
2315 for (i = 1; i < 3; i++)
2316 nbseg_diff += (c->layer[i].modulation == DQPSK) * c->layer[i].segment_count;
2317 for (i = 0; i < nbseg_diff; i++)
2318 state->seg_diff_mask |= 1 << permu_seg[i+1];
2319 } else {
2320 for (i = 0; i < 3; i++)
2321 nbseg_diff += (c->layer[i].modulation == DQPSK) * c->layer[i].segment_count;
2322 for (i = 0; i < nbseg_diff; i++)
2323 state->seg_diff_mask |= 1 << permu_seg[i];
2478 } 2324 }
2479 if (state->cfg.diversity_delay == 0) 2325
2480 mode = (mode * (1 << (guard)) * 3) / 2 + 48; // add 50% SFN margin + compensate for one DVSY-fifo 2326 if (state->seg_diff_mask)
2327 dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200);
2481 else 2328 else
2482 mode = (mode * (1 << (guard)) * 3) / 2 + state->cfg.diversity_delay; // add 50% SFN margin + compensate for DVSY-fifo 2329 dib8000_write_word(state, 268, (2 << 9) | 39); /*init value */
2483 mode <<= 4;
2484 dib8000_write_word(state, 273, (dib8000_read_word(state, 273) & 0x000f) | mode);
2485 2330
2486 /* channel estimation fine configuration */ 2331 for (i = 0; i < 3; i++)
2487 switch (max_constellation) { 2332 max_constellation = dib8000_set_layer(state, i, max_constellation);
2488 case QAM_64: 2333 if (autosearching == 0) {
2489 ana_gain = 0x7; // -1 : avoid def_est saturation when ADC target is -16dB 2334 state->layer_b_nb_seg = c->layer[1].segment_count;
2490 coeff[0] = 0x0148; /* P_adp_regul_cnt 0.04 */ 2335 state->layer_c_nb_seg = c->layer[2].segment_count;
2491 coeff[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
2492 coeff[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
2493 coeff[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
2494 //if (!state->cfg.hostbus_diversity) //if diversity, we should prehaps use the configuration of the max_constallation -1
2495 break;
2496 case QAM_16:
2497 ana_gain = 0x7; // -1 : avoid def_est saturation when ADC target is -16dB
2498 coeff[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
2499 coeff[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
2500 coeff[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
2501 coeff[3] = 0xfff0; /* P_adp_noise_ext -0.002 */
2502 //if (!((state->cfg.hostbus_diversity) && (max_constellation == QAM_16)))
2503 break;
2504 default:
2505 ana_gain = 0; // 0 : goes along with ADC target at -22dB to keep good mobile performance and lock at sensitivity level
2506 coeff[0] = 0x099a; /* P_adp_regul_cnt 0.3 */
2507 coeff[1] = 0xffae; /* P_adp_noise_cnt -0.01 */
2508 coeff[2] = 0x0333; /* P_adp_regul_ext 0.1 */
2509 coeff[3] = 0xfff8; /* P_adp_noise_ext -0.002 */
2510 break;
2511 } 2336 }
2512 for (mode = 0; mode < 4; mode++)
2513 dib8000_write_word(state, 215 + mode, coeff[mode]);
2514 2337
2515 // update ana_gain depending on max constellation 2338 /* WRITE: Mode & Diff mask */
2516 dib8000_write_word(state, 116, ana_gain); 2339 dib8000_write_word(state, 0, (state->mode << 13) | state->seg_diff_mask);
2517 // update ADC target depending on ana_gain 2340
2518 if (ana_gain) { // set -16dB ADC target for ana_gain=-1 2341 state->differential_constellation = (state->seg_diff_mask != 0);
2519 for (i = 0; i < 10; i++) 2342
2520 dib8000_write_word(state, 80 + i, adc_target_16dB[i]); 2343 /* channel estimation fine configuration */
2521 } else { // set -22dB ADC target for ana_gain=0 2344 ana_gain = dib8000_adp_fine_tune(state, max_constellation);
2522 for (i = 0; i < 10; i++) 2345
2523 dib8000_write_word(state, 80 + i, adc_target_16dB[i] - 355); 2346 /* update ana_gain depending on max constellation */
2347 dib8000_update_ana_gain(state, ana_gain);
2348
2349 /* ---- ANA_FE ---- */
2350 if (c->isdbt_partial_reception) /* 3-segments */
2351 dib8000_load_ana_fe_coefs(state, ana_fe_coeff_3seg);
2352 else
2353 dib8000_load_ana_fe_coefs(state, ana_fe_coeff_1seg); /* 1-segment */
2354
2355 /* TSB or ISDBT ? apply it now */
2356 if (c->isdbt_sb_mode) {
2357 dib8000_set_sb_channel(state);
2358 if (c->isdbt_sb_subchannel < 14)
2359 init_prbs = dib8000_get_init_prbs(state, c->isdbt_sb_subchannel);
2360 else
2361 init_prbs = 0;
2362 } else {
2363 dib8000_set_13seg_channel(state);
2364 init_prbs = 0xfff;
2524 } 2365 }
2525 2366
2526 // ---- ANA_FE ---- 2367 /* SMALL */
2527 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode) { 2368 dib8000_small_fine_tune(state);
2528 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 1)
2529 ana_fe = ana_fe_coeff_3seg;
2530 else // 1-segment
2531 ana_fe = ana_fe_coeff_1seg;
2532 } else
2533 ana_fe = ana_fe_coeff_13seg;
2534 2369
2535 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1 || state->isdbt_cfg_loaded == 0) 2370 dib8000_set_subchannel_prbs(state, init_prbs);
2536 for (mode = 0; mode < 24; mode++)
2537 dib8000_write_word(state, 117 + mode, ana_fe[mode]);
2538 2371
2539 // ---- CHAN_BLK ---- 2372 /* ---- CHAN_BLK ---- */
2540 for (i = 0; i < 13; i++) { 2373 for (i = 0; i < 13; i++) {
2541 if ((((~seg_diff_mask) >> i) & 1) == 1) { 2374 if ((((~state->seg_diff_mask) >> i) & 1) == 1) {
2542 P_cfr_left_edge += (1 << i) * ((i == 0) || ((((seg_mask13 & (~seg_diff_mask)) >> (i - 1)) & 1) == 0)); 2375 p_cfr_left_edge += (1 << i) * ((i == 0) || ((((state->seg_mask & (~state->seg_diff_mask)) >> (i - 1)) & 1) == 0));
2543 P_cfr_right_edge += (1 << i) * ((i == 12) || ((((seg_mask13 & (~seg_diff_mask)) >> (i + 1)) & 1) == 0)); 2376 p_cfr_right_edge += (1 << i) * ((i == 12) || ((((state->seg_mask & (~state->seg_diff_mask)) >> (i + 1)) & 1) == 0));
2544 } 2377 }
2545 } 2378 }
2546 dib8000_write_word(state, 222, P_cfr_left_edge); // P_cfr_left_edge 2379 dib8000_write_word(state, 222, p_cfr_left_edge); /* p_cfr_left_edge */
2547 dib8000_write_word(state, 223, P_cfr_right_edge); // P_cfr_right_edge 2380 dib8000_write_word(state, 223, p_cfr_right_edge); /* p_cfr_right_edge */
2548 // "P_cspu_left_edge" not used => do not care 2381 /* "P_cspu_left_edge" & "P_cspu_right_edge" not used => do not care */
2549 // "P_cspu_right_edge" not used => do not care 2382
2550 2383 dib8000_write_word(state, 189, ~state->seg_mask | state->seg_diff_mask); /* P_lmod4_seg_inh */
2551 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) { 2384 dib8000_write_word(state, 192, ~state->seg_mask | state->seg_diff_mask); /* P_pha3_seg_inh */
2552 dib8000_write_word(state, 228, 1); // P_2d_mode_byp=1 2385 dib8000_write_word(state, 225, ~state->seg_mask | state->seg_diff_mask); /* P_tac_seg_inh */
2553 dib8000_write_word(state, 205, dib8000_read_word(state, 205) & 0xfff0); // P_cspu_win_cut = 0 2386
2554 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0 2387 if (!autosearching)
2555 && state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_2K) { 2388 dib8000_write_word(state, 288, (~state->seg_mask | state->seg_diff_mask) & 0x1fff); /* P_tmcc_seg_eq_inh */
2556 //dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe); // P_adp_pass = 0 2389 else
2557 dib8000_write_word(state, 265, 15); // P_equal_noise_sel = 15 2390 dib8000_write_word(state, 288, 0x1fff); /*disable equalisation of the tmcc when autosearch to be able to find the DQPSK channels. */
2558 } 2391
2559 } else if (state->isdbt_cfg_loaded == 0) { 2392 dib8000_write_word(state, 211, state->seg_mask & (~state->seg_diff_mask)); /* P_des_seg_enabled */
2560 dib8000_write_word(state, 228, 0); // default value 2393 dib8000_write_word(state, 287, ~state->seg_mask | 0x1000); /* P_tmcc_seg_inh */
2561 dib8000_write_word(state, 265, 31); // default value 2394
2562 dib8000_write_word(state, 205, 0x200f); // init value 2395 dib8000_write_word(state, 178, 32); /* P_fft_powrange = 32 */
2563 } 2396
2564 // ---- TMCC ---- 2397 /* ---- TMCC ---- */
2565 for (i = 0; i < 3; i++) 2398 for (i = 0; i < 3; i++)
2566 tmcc_pow += 2399 tmcc_pow += (((c->layer[i].modulation == DQPSK) * 4 + 1) * c->layer[i].segment_count) ;
2567 (((state->fe[0]->dtv_property_cache.layer[i].modulation == DQPSK) * 4 + 1) * state->fe[0]->dtv_property_cache.layer[i].segment_count); 2400
2568 // Quantif of "P_tmcc_dec_thres_?k" is (0, 5+mode, 9); 2401 /* Quantif of "P_tmcc_dec_thres_?k" is (0, 5+mode, 9); */
2569 // Threshold is set at 1/4 of max power. 2402 /* Threshold is set at 1/4 of max power. */
2570 tmcc_pow *= (1 << (9 - 2)); 2403 tmcc_pow *= (1 << (9-2));
2571 2404 dib8000_write_word(state, 290, tmcc_pow); /* P_tmcc_dec_thres_2k */
2572 dib8000_write_word(state, 290, tmcc_pow); // P_tmcc_dec_thres_2k 2405 dib8000_write_word(state, 291, tmcc_pow); /* P_tmcc_dec_thres_4k */
2573 dib8000_write_word(state, 291, tmcc_pow); // P_tmcc_dec_thres_4k 2406 dib8000_write_word(state, 292, tmcc_pow); /* P_tmcc_dec_thres_8k */
2574 dib8000_write_word(state, 292, tmcc_pow); // P_tmcc_dec_thres_8k 2407 /*dib8000_write_word(state, 287, (1 << 13) | 0x1000 ); */
2575 //dib8000_write_word(state, 287, (1 << 13) | 0x1000 );
2576 // ---- PHA3 ----
2577 2408
2409 /* ---- PHA3 ---- */
2578 if (state->isdbt_cfg_loaded == 0) 2410 if (state->isdbt_cfg_loaded == 0)
2579 dib8000_write_word(state, 250, 3285); /*p_2d_hspeed_thr0 */ 2411 dib8000_write_word(state, 250, 3285); /* p_2d_hspeed_thr0 */
2580 2412
2581 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) 2413 state->isdbt_cfg_loaded = 0;
2582 state->isdbt_cfg_loaded = 0; 2414}
2583 else
2584 state->isdbt_cfg_loaded = 1;
2585 2415
2416static u32 dib8000_wait_lock(struct dib8000_state *state, u32 internal,
2417 u32 wait0_ms, u32 wait1_ms, u32 wait2_ms)
2418{
2419 u32 value = 0; /* P_search_end0 wait time */
2420 u16 reg = 11; /* P_search_end0 start addr */
2421
2422 for (reg = 11; reg < 16; reg += 2) {
2423 if (reg == 11) {
2424 if (state->revision == 0x8090)
2425 value = internal * wait1_ms;
2426 else
2427 value = internal * wait0_ms;
2428 } else if (reg == 13)
2429 value = internal * wait1_ms;
2430 else if (reg == 15)
2431 value = internal * wait2_ms;
2432 dib8000_write_word(state, reg, (u16)((value >> 16) & 0xffff));
2433 dib8000_write_word(state, (reg + 1), (u16)(value & 0xffff));
2434 }
2435 return value;
2586} 2436}
2587 2437
2588static int dib8000_autosearch_start(struct dvb_frontend *fe) 2438static int dib8000_autosearch_start(struct dvb_frontend *fe)
2589{ 2439{
2590 u8 factor;
2591 u32 value;
2592 struct dib8000_state *state = fe->demodulator_priv; 2440 struct dib8000_state *state = fe->demodulator_priv;
2441 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2442 u8 slist = 0;
2443 u32 value, internal = state->cfg.pll->internal;
2593 2444
2594 int slist = 0; 2445 if (state->revision == 0x8090)
2595 2446 internal = dib8000_read32(state, 23) / 1000;
2596 state->fe[0]->dtv_property_cache.inversion = 0; 2447
2597 if (!state->fe[0]->dtv_property_cache.isdbt_sb_mode) 2448 if (state->autosearch_state == AS_SEARCHING_FFT) {
2598 state->fe[0]->dtv_property_cache.layer[0].segment_count = 13; 2449 dib8000_write_word(state, 37, 0x0065); /* P_ctrl_pha_off_max default values */
2599 state->fe[0]->dtv_property_cache.layer[0].modulation = QAM_64; 2450 dib8000_write_word(state, 116, 0x0000); /* P_ana_gain to 0 */
2600 state->fe[0]->dtv_property_cache.layer[0].fec = FEC_2_3;
2601 state->fe[0]->dtv_property_cache.layer[0].interleaving = 0;
2602
2603 //choose the right list, in sb, always do everything
2604 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode) {
2605 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K;
2606 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8;
2607 slist = 7;
2608 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
2609 } else {
2610 if (state->fe[0]->dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) {
2611 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) {
2612 slist = 7;
2613 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1 to have autosearch start ok with mode2
2614 } else
2615 slist = 3;
2616 } else {
2617 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) {
2618 slist = 2;
2619 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1
2620 } else
2621 slist = 0;
2622 }
2623 2451
2624 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) 2452 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x1fff) | (0 << 13) | (1 << 15)); /* P_mode = 0, P_restart_search=1 */
2625 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K; 2453 dib8000_write_word(state, 1, (dib8000_read_word(state, 1) & 0xfffc) | 0); /* P_guard = 0 */
2626 if (state->fe[0]->dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) 2454 dib8000_write_word(state, 6, 0); /* P_lock0_mask = 0 */
2627 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8; 2455 dib8000_write_word(state, 7, 0); /* P_lock1_mask = 0 */
2456 dib8000_write_word(state, 8, 0); /* P_lock2_mask = 0 */
2457 dib8000_write_word(state, 10, (dib8000_read_word(state, 10) & 0x200) | (16 << 4) | (0 << 0)); /* P_search_list=16, P_search_maxtrial=0 */
2628 2458
2629 dprintk("using list for autosearch : %d", slist); 2459 if (state->revision == 0x8090)
2630 dib8000_set_channel(state, (unsigned char)slist, 1); 2460 value = dib8000_wait_lock(state, internal, 10, 10, 10); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
2631 //dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1 2461 else
2462 value = dib8000_wait_lock(state, internal, 20, 20, 20); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
2632 2463
2633 factor = 1; 2464 dib8000_write_word(state, 17, 0);
2465 dib8000_write_word(state, 18, 200); /* P_search_rstst = 200 */
2466 dib8000_write_word(state, 19, 0);
2467 dib8000_write_word(state, 20, 400); /* P_search_rstend = 400 */
2468 dib8000_write_word(state, 21, (value >> 16) & 0xffff); /* P_search_checkst */
2469 dib8000_write_word(state, 22, value & 0xffff);
2634 2470
2635 //set lock_mask values 2471 if (state->revision == 0x8090)
2472 dib8000_write_word(state, 32, (dib8000_read_word(state, 32) & 0xf0ff) | (0 << 8)); /* P_corm_alpha = 0 */
2473 else
2474 dib8000_write_word(state, 32, (dib8000_read_word(state, 32) & 0xf0ff) | (9 << 8)); /* P_corm_alpha = 3 */
2475 dib8000_write_word(state, 355, 2); /* P_search_param_max = 2 */
2476
2477 /* P_search_param_select = (1 | 1<<4 | 1 << 8) */
2478 dib8000_write_word(state, 356, 0);
2479 dib8000_write_word(state, 357, 0x111);
2480
2481 dib8000_write_word(state, 770, (dib8000_read_word(state, 770) & 0xdfff) | (1 << 13)); /* P_restart_ccg = 1 */
2482 dib8000_write_word(state, 770, (dib8000_read_word(state, 770) & 0xdfff) | (0 << 13)); /* P_restart_ccg = 0 */
2483 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x7ff) | (0 << 15) | (1 << 13)); /* P_restart_search = 0; */
2484 } else if (state->autosearch_state == AS_SEARCHING_GUARD) {
2485 c->transmission_mode = TRANSMISSION_MODE_8K;
2486 c->guard_interval = GUARD_INTERVAL_1_8;
2487 c->inversion = 0;
2488 c->layer[0].modulation = QAM_64;
2489 c->layer[0].fec = FEC_2_3;
2490 c->layer[0].interleaving = 0;
2491 c->layer[0].segment_count = 13;
2492
2493 slist = 16;
2494 c->transmission_mode = state->found_nfft;
2495
2496 dib8000_set_isdbt_common_channel(state, slist, 1);
2497
2498 /* set lock_mask values */
2636 dib8000_write_word(state, 6, 0x4); 2499 dib8000_write_word(state, 6, 0x4);
2637 dib8000_write_word(state, 7, 0x8); 2500 if (state->revision == 0x8090)
2501 dib8000_write_word(state, 7, ((1 << 12) | (1 << 11) | (1 << 10)));/* tmcc_dec_lock, tmcc_sync_lock, tmcc_data_lock, tmcc_bch_uncor */
2502 else
2503 dib8000_write_word(state, 7, 0x8);
2638 dib8000_write_word(state, 8, 0x1000); 2504 dib8000_write_word(state, 8, 0x1000);
2639 2505
2640 //set lock_mask wait time values 2506 /* set lock_mask wait time values */
2641 value = 50 * state->cfg.pll->internal * factor; 2507 if (state->revision == 0x8090)
2642 dib8000_write_word(state, 11, (u16) ((value >> 16) & 0xffff)); // lock0 wait time 2508 dib8000_wait_lock(state, internal, 50, 100, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
2643 dib8000_write_word(state, 12, (u16) (value & 0xffff)); // lock0 wait time 2509 else
2644 value = 100 * state->cfg.pll->internal * factor; 2510 dib8000_wait_lock(state, internal, 50, 200, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
2645 dib8000_write_word(state, 13, (u16) ((value >> 16) & 0xffff)); // lock1 wait time 2511
2646 dib8000_write_word(state, 14, (u16) (value & 0xffff)); // lock1 wait time 2512 dib8000_write_word(state, 355, 3); /* P_search_param_max = 3 */
2647 value = 1000 * state->cfg.pll->internal * factor; 2513
2648 dib8000_write_word(state, 15, (u16) ((value >> 16) & 0xffff)); // lock2 wait time 2514 /* P_search_param_select = 0xf; look for the 4 different guard intervals */
2649 dib8000_write_word(state, 16, (u16) (value & 0xffff)); // lock2 wait time 2515 dib8000_write_word(state, 356, 0);
2516 dib8000_write_word(state, 357, 0xf);
2650 2517
2651 value = dib8000_read_word(state, 0); 2518 value = dib8000_read_word(state, 0);
2652 dib8000_write_word(state, 0, (u16) ((1 << 15) | value)); 2519 dib8000_write_word(state, 0, (u16)((1 << 15) | value));
2653 dib8000_read_word(state, 1284); // reset the INT. n_irq_pending 2520 dib8000_read_word(state, 1284); /* reset the INT. n_irq_pending */
2654 dib8000_write_word(state, 0, (u16) value); 2521 dib8000_write_word(state, 0, (u16)value);
2522 } else {
2523 c->inversion = 0;
2524 c->layer[0].modulation = QAM_64;
2525 c->layer[0].fec = FEC_2_3;
2526 c->layer[0].interleaving = 0;
2527 c->layer[0].segment_count = 13;
2528 if (!c->isdbt_sb_mode)
2529 c->layer[0].segment_count = 13;
2530
2531 /* choose the right list, in sb, always do everything */
2532 if (c->isdbt_sb_mode) {
2533 slist = 7;
2534 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
2535 } else {
2536 if (c->guard_interval == GUARD_INTERVAL_AUTO) {
2537 if (c->transmission_mode == TRANSMISSION_MODE_AUTO) {
2538 c->transmission_mode = TRANSMISSION_MODE_8K;
2539 c->guard_interval = GUARD_INTERVAL_1_8;
2540 slist = 7;
2541 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); /* P_mode = 1 to have autosearch start ok with mode2 */
2542 } else {
2543 c->guard_interval = GUARD_INTERVAL_1_8;
2544 slist = 3;
2545 }
2546 } else {
2547 if (c->transmission_mode == TRANSMISSION_MODE_AUTO) {
2548 c->transmission_mode = TRANSMISSION_MODE_8K;
2549 slist = 2;
2550 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); /* P_mode = 1 */
2551 } else
2552 slist = 0;
2553 }
2554 }
2555 dprintk("Using list for autosearch : %d", slist);
2655 2556
2656 } 2557 dib8000_set_isdbt_common_channel(state, slist, 1);
2558
2559 /* set lock_mask values */
2560 dib8000_write_word(state, 6, 0x4);
2561 if (state->revision == 0x8090)
2562 dib8000_write_word(state, 7, (1 << 12) | (1 << 11) | (1 << 10));
2563 else
2564 dib8000_write_word(state, 7, 0x8);
2565 dib8000_write_word(state, 8, 0x1000);
2657 2566
2567 /* set lock_mask wait time values */
2568 if (state->revision == 0x8090)
2569 dib8000_wait_lock(state, internal, 50, 200, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
2570 else
2571 dib8000_wait_lock(state, internal, 50, 100, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
2572
2573 value = dib8000_read_word(state, 0);
2574 dib8000_write_word(state, 0, (u16)((1 << 15) | value));
2575 dib8000_read_word(state, 1284); /* reset the INT. n_irq_pending */
2576 dib8000_write_word(state, 0, (u16)value);
2577 }
2658 return 0; 2578 return 0;
2659} 2579}
2660 2580
@@ -2663,96 +2583,635 @@ static int dib8000_autosearch_irq(struct dvb_frontend *fe)
2663 struct dib8000_state *state = fe->demodulator_priv; 2583 struct dib8000_state *state = fe->demodulator_priv;
2664 u16 irq_pending = dib8000_read_word(state, 1284); 2584 u16 irq_pending = dib8000_read_word(state, 1284);
2665 2585
2666 if (irq_pending & 0x1) { // failed 2586 if (state->autosearch_state == AS_SEARCHING_FFT) {
2667 dprintk("dib8000_autosearch_irq failed"); 2587 if (irq_pending & 0x1) {
2668 return 1; 2588 dprintk("dib8000_autosearch_irq: max correlation result available");
2669 } 2589 return 3;
2590 }
2591 } else {
2592 if (irq_pending & 0x1) { /* failed */
2593 dprintk("dib8000_autosearch_irq failed");
2594 return 1;
2595 }
2670 2596
2671 if (irq_pending & 0x2) { // succeeded 2597 if (irq_pending & 0x2) { /* succeeded */
2672 dprintk("dib8000_autosearch_irq succeeded"); 2598 dprintk("dib8000_autosearch_irq succeeded");
2673 return 2; 2599 return 2;
2600 }
2674 } 2601 }
2675 2602
2676 return 0; // still pending 2603 return 0; // still pending
2677} 2604}
2678 2605
2679static int dib8000_tune(struct dvb_frontend *fe) 2606static void dib8000_viterbi_state(struct dib8000_state *state, u8 onoff)
2680{ 2607{
2681 struct dib8000_state *state = fe->demodulator_priv; 2608 u16 tmp;
2682 int ret = 0;
2683 u16 lock, value, mode;
2684 2609
2685 // we are already tuned - just resuming from suspend 2610 tmp = dib8000_read_word(state, 771);
2686 if (state == NULL) 2611 if (onoff) /* start P_restart_chd : channel_decoder */
2687 return -EINVAL; 2612 dib8000_write_word(state, 771, tmp & 0xfffd);
2613 else /* stop P_restart_chd : channel_decoder */
2614 dib8000_write_word(state, 771, tmp | (1<<1));
2615}
2616
2617static void dib8000_set_dds(struct dib8000_state *state, s32 offset_khz)
2618{
2619 s16 unit_khz_dds_val;
2620 u32 abs_offset_khz = ABS(offset_khz);
2621 u32 dds = state->cfg.pll->ifreq & 0x1ffffff;
2622 u8 invert = !!(state->cfg.pll->ifreq & (1 << 25));
2623 u8 ratio;
2688 2624
2689 mode = fft_to_mode(state); 2625 if (state->revision == 0x8090) {
2626 ratio = 4;
2627 unit_khz_dds_val = (1<<26) / (dib8000_read32(state, 23) / 1000);
2628 if (offset_khz < 0)
2629 dds = (1 << 26) - (abs_offset_khz * unit_khz_dds_val);
2630 else
2631 dds = (abs_offset_khz * unit_khz_dds_val);
2690 2632
2691 dib8000_set_bandwidth(fe, state->fe[0]->dtv_property_cache.bandwidth_hz / 1000); 2633 if (invert)
2692 dib8000_set_channel(state, 0, 0); 2634 dds = (1<<26) - dds;
2635 } else {
2636 ratio = 2;
2637 unit_khz_dds_val = (u16) (67108864 / state->cfg.pll->internal);
2693 2638
2694 // restart demod 2639 if (offset_khz < 0)
2695 ret |= dib8000_write_word(state, 770, 0x4000); 2640 unit_khz_dds_val *= -1;
2696 ret |= dib8000_write_word(state, 770, 0x0000);
2697 msleep(45);
2698 2641
2699 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3 */ 2642 /* IF tuner */
2700 /* ret |= dib8000_write_word(state, 29, (0 << 9) | (4 << 5) | (0 << 4) | (3 << 0) ); workaround inh_isi stays at 1 */ 2643 if (invert)
2644 dds -= abs_offset_khz * unit_khz_dds_val;
2645 else
2646 dds += abs_offset_khz * unit_khz_dds_val;
2647 }
2701 2648
2702 // never achieved a lock before - wait for timfreq to update 2649 dprintk("setting a DDS frequency offset of %c%dkHz", invert ? '-' : ' ', dds / unit_khz_dds_val);
2703 if (state->timf == 0) { 2650
2704 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) { 2651 if (abs_offset_khz <= (state->cfg.pll->internal / ratio)) {
2705 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) 2652 /* Max dds offset is the half of the demod freq */
2706 msleep(300); 2653 dib8000_write_word(state, 26, invert);
2707 else // Sound Broadcasting mode 3 seg 2654 dib8000_write_word(state, 27, (u16)(dds >> 16) & 0x1ff);
2708 msleep(500); 2655 dib8000_write_word(state, 28, (u16)(dds & 0xffff));
2709 } else // 13 seg
2710 msleep(200);
2711 } 2656 }
2712 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) { 2657}
2713 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
2714 2658
2715 /* P_timf_alpha = (13-P_mode) , P_corm_alpha=6, P_corm_thres=0x40 alpha to check on board */ 2659static void dib8000_set_frequency_offset(struct dib8000_state *state)
2716 dib8000_write_word(state, 32, ((13 - mode) << 12) | (6 << 8) | 0x40); 2660{
2717 //dib8000_write_word(state, 32, (8 << 12) | (6 << 8) | 0x80); 2661 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2662 int i;
2663 u32 current_rf;
2664 int total_dds_offset_khz;
2718 2665
2719 /* P_ctrl_sfreq_step= (12-P_mode) P_ctrl_sfreq_inh =0 P_ctrl_pha_off_max */ 2666 if (state->fe[0]->ops.tuner_ops.get_frequency)
2720 ret |= dib8000_write_word(state, 37, (12 - mode) | ((5 + mode) << 5)); 2667 state->fe[0]->ops.tuner_ops.get_frequency(state->fe[0], &current_rf);
2668 else
2669 current_rf = c->frequency;
2670 current_rf /= 1000;
2671 total_dds_offset_khz = (int)current_rf - (int)c->frequency / 1000;
2721 2672
2722 } else { // Sound Broadcasting mode 3 seg 2673 if (c->isdbt_sb_mode) {
2674 state->subchannel = c->isdbt_sb_subchannel;
2723 2675
2724 /* P_timf_alpha = (12-P_mode) , P_corm_alpha=6, P_corm_thres=0x60 alpha to check on board */ 2676 i = dib8000_read_word(state, 26) & 1; /* P_dds_invspec */
2725 dib8000_write_word(state, 32, ((12 - mode) << 12) | (6 << 8) | 0x60); 2677 dib8000_write_word(state, 26, c->inversion ^ i);
2726 2678
2727 ret |= dib8000_write_word(state, 37, (11 - mode) | ((5 + mode) << 5)); 2679 if (state->cfg.pll->ifreq == 0) { /* low if tuner */
2680 if ((c->inversion ^ i) == 0)
2681 dib8000_write_word(state, 26, dib8000_read_word(state, 26) | 1);
2682 } else {
2683 if ((c->inversion ^ i) == 0)
2684 total_dds_offset_khz *= -1;
2728 } 2685 }
2686 }
2729 2687
2730 } else { // 13 seg 2688 dprintk("%dkhz tuner offset (frequency = %dHz & current_rf = %dHz) total_dds_offset_hz = %d", c->frequency - current_rf, c->frequency, current_rf, total_dds_offset_khz);
2731 /* P_timf_alpha = 8 , P_corm_alpha=6, P_corm_thres=0x80 alpha to check on board */
2732 dib8000_write_word(state, 32, ((11 - mode) << 12) | (6 << 8) | 0x80);
2733 2689
2734 ret |= dib8000_write_word(state, 37, (10 - mode) | ((5 + mode) << 5)); 2690 /* apply dds offset now */
2691 dib8000_set_dds(state, total_dds_offset_khz);
2692}
2693
2694static u16 LUT_isdbt_symbol_duration[4] = { 26, 101, 63 };
2695
2696static u32 dib8000_get_symbol_duration(struct dib8000_state *state)
2697{
2698 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2699 u16 i;
2735 2700
2701 switch (c->transmission_mode) {
2702 case TRANSMISSION_MODE_2K:
2703 i = 0;
2704 break;
2705 case TRANSMISSION_MODE_4K:
2706 i = 2;
2707 break;
2708 default:
2709 case TRANSMISSION_MODE_AUTO:
2710 case TRANSMISSION_MODE_8K:
2711 i = 1;
2712 break;
2736 } 2713 }
2737 2714
2738 // we achieved a coff_cpil_lock - it's time to update the timf 2715 return (LUT_isdbt_symbol_duration[i] / (c->bandwidth_hz / 1000)) + 1;
2739 if (state->revision != 0x8090) 2716}
2740 lock = dib8000_read_word(state, 568); 2717
2718static void dib8000_set_isdbt_loop_params(struct dib8000_state *state, enum param_loop_step loop_step)
2719{
2720 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2721 u16 reg_32 = 0, reg_37 = 0;
2722
2723 switch (loop_step) {
2724 case LOOP_TUNE_1:
2725 if (c->isdbt_sb_mode) {
2726 if (c->isdbt_partial_reception == 0) {
2727 reg_32 = ((11 - state->mode) << 12) | (6 << 8) | 0x40; /* P_timf_alpha = (11-P_mode), P_corm_alpha=6, P_corm_thres=0x40 */
2728 reg_37 = (3 << 5) | (0 << 4) | (10 - state->mode); /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (10-P_mode) */
2729 } else { /* Sound Broadcasting mode 3 seg */
2730 reg_32 = ((10 - state->mode) << 12) | (6 << 8) | 0x60; /* P_timf_alpha = (10-P_mode), P_corm_alpha=6, P_corm_thres=0x60 */
2731 reg_37 = (3 << 5) | (0 << 4) | (9 - state->mode); /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (9-P_mode) */
2732 }
2733 } else { /* 13-seg start conf offset loop parameters */
2734 reg_32 = ((9 - state->mode) << 12) | (6 << 8) | 0x80; /* P_timf_alpha = (9-P_mode, P_corm_alpha=6, P_corm_thres=0x80 */
2735 reg_37 = (3 << 5) | (0 << 4) | (8 - state->mode); /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = 9 */
2736 }
2737 break;
2738 case LOOP_TUNE_2:
2739 if (c->isdbt_sb_mode) {
2740 if (c->isdbt_partial_reception == 0) { /* Sound Broadcasting mode 1 seg */
2741 reg_32 = ((13-state->mode) << 12) | (6 << 8) | 0x40; /* P_timf_alpha = (13-P_mode) , P_corm_alpha=6, P_corm_thres=0x40*/
2742 reg_37 = (12-state->mode) | ((5 + state->mode) << 5);
2743 } else { /* Sound Broadcasting mode 3 seg */
2744 reg_32 = ((12-state->mode) << 12) | (6 << 8) | 0x60; /* P_timf_alpha = (12-P_mode) , P_corm_alpha=6, P_corm_thres=0x60 */
2745 reg_37 = (11-state->mode) | ((5 + state->mode) << 5);
2746 }
2747 } else { /* 13 seg */
2748 reg_32 = ((11-state->mode) << 12) | (6 << 8) | 0x80; /* P_timf_alpha = 8 , P_corm_alpha=6, P_corm_thres=0x80 */
2749 reg_37 = ((5+state->mode) << 5) | (10 - state->mode);
2750 }
2751 break;
2752 }
2753 dib8000_write_word(state, 32, reg_32);
2754 dib8000_write_word(state, 37, reg_37);
2755}
2756
2757static void dib8000_demod_restart(struct dib8000_state *state)
2758{
2759 dib8000_write_word(state, 770, 0x4000);
2760 dib8000_write_word(state, 770, 0x0000);
2761 return;
2762}
2763
2764static void dib8000_set_sync_wait(struct dib8000_state *state)
2765{
2766 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2767 u16 sync_wait = 64;
2768
2769 /* P_dvsy_sync_wait - reuse mode */
2770 switch (c->transmission_mode) {
2771 case TRANSMISSION_MODE_8K:
2772 sync_wait = 256;
2773 break;
2774 case TRANSMISSION_MODE_4K:
2775 sync_wait = 128;
2776 break;
2777 default:
2778 case TRANSMISSION_MODE_2K:
2779 sync_wait = 64;
2780 break;
2781 }
2782
2783 if (state->cfg.diversity_delay == 0)
2784 sync_wait = (sync_wait * (1 << (c->guard_interval)) * 3) / 2 + 48; /* add 50% SFN margin + compensate for one DVSY-fifo */
2741 else 2785 else
2742 lock = dib8000_read_word(state, 570); 2786 sync_wait = (sync_wait * (1 << (c->guard_interval)) * 3) / 2 + state->cfg.diversity_delay; /* add 50% SFN margin + compensate for DVSY-fifo */
2743 if ((lock >> 11) & 0x1)
2744 dib8000_update_timf(state);
2745 2787
2746 //now that tune is finished, lock0 should lock on fec_mpeg to output this lock on MP_LOCK. It's changed in autosearch start 2788 dib8000_write_word(state, 273, (dib8000_read_word(state, 273) & 0x000f) | (sync_wait << 4));
2747 dib8000_write_word(state, 6, 0x200); 2789}
2748 2790
2749 if (state->revision == 0x8002) { 2791static u32 dib8000_get_timeout(struct dib8000_state *state, u32 delay, enum timeout_mode mode)
2750 value = dib8000_read_word(state, 903); 2792{
2751 dib8000_write_word(state, 903, value & ~(1 << 3)); 2793 if (mode == SYMBOL_DEPENDENT_ON)
2752 msleep(1); 2794 return systime() + (delay * state->symbol_duration);
2753 dib8000_write_word(state, 903, value | (1 << 3)); 2795 else
2796 return systime() + delay;
2797}
2798
2799static s32 dib8000_get_status(struct dvb_frontend *fe)
2800{
2801 struct dib8000_state *state = fe->demodulator_priv;
2802 return state->status;
2803}
2804
2805enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe)
2806{
2807 struct dib8000_state *state = fe->demodulator_priv;
2808 return state->tune_state;
2809}
2810EXPORT_SYMBOL(dib8000_get_tune_state);
2811
2812int dib8000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state)
2813{
2814 struct dib8000_state *state = fe->demodulator_priv;
2815
2816 state->tune_state = tune_state;
2817 return 0;
2818}
2819EXPORT_SYMBOL(dib8000_set_tune_state);
2820
2821static int dib8000_tune_restart_from_demod(struct dvb_frontend *fe)
2822{
2823 struct dib8000_state *state = fe->demodulator_priv;
2824
2825 state->status = FE_STATUS_TUNE_PENDING;
2826 state->tune_state = CT_DEMOD_START;
2827 return 0;
2828}
2829
2830static u16 dib8000_read_lock(struct dvb_frontend *fe)
2831{
2832 struct dib8000_state *state = fe->demodulator_priv;
2833
2834 if (state->revision == 0x8090)
2835 return dib8000_read_word(state, 570);
2836 return dib8000_read_word(state, 568);
2837}
2838
2839static int dib8090p_init_sdram(struct dib8000_state *state)
2840{
2841 u16 reg = 0;
2842 dprintk("init sdram");
2843
2844 reg = dib8000_read_word(state, 274) & 0xfff0;
2845 dib8000_write_word(state, 274, reg | 0x7); /* P_dintlv_delay_ram = 7 because of MobileSdram */
2846
2847 dib8000_write_word(state, 1803, (7 << 2));
2848
2849 reg = dib8000_read_word(state, 1280);
2850 dib8000_write_word(state, 1280, reg | (1 << 2)); /* force restart P_restart_sdram */
2851 dib8000_write_word(state, 1280, reg); /* release restart P_restart_sdram */
2852
2853 return 0;
2854}
2855
2856static int dib8000_tune(struct dvb_frontend *fe)
2857{
2858 struct dib8000_state *state = fe->demodulator_priv;
2859 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2860 enum frontend_tune_state *tune_state = &state->tune_state;
2861
2862 u16 locks, deeper_interleaver = 0, i;
2863 int ret = 1; /* 1 symbol duration (in 100us unit) delay most of the time */
2864
2865 u32 *timeout = &state->timeout;
2866 u32 now = systime();
2867#ifdef DIB8000_AGC_FREEZE
2868 u16 agc1, agc2;
2869#endif
2870
2871 u32 corm[4] = {0, 0, 0, 0};
2872 u8 find_index, max_value;
2873
2874#if 0
2875 if (*tune_state < CT_DEMOD_STOP)
2876 dprintk("IN: context status = %d, TUNE_STATE %d autosearch step = %u systime = %u", state->channel_parameters_set, *tune_state, state->autosearch_state, now);
2877#endif
2878
2879 switch (*tune_state) {
2880 case CT_DEMOD_START: /* 30 */
2881 if (state->revision == 0x8090)
2882 dib8090p_init_sdram(state);
2883 state->status = FE_STATUS_TUNE_PENDING;
2884 if ((c->delivery_system != SYS_ISDBT) ||
2885 (c->inversion == INVERSION_AUTO) ||
2886 (c->transmission_mode == TRANSMISSION_MODE_AUTO) ||
2887 (c->guard_interval == GUARD_INTERVAL_AUTO) ||
2888 (((c->isdbt_layer_enabled & (1 << 0)) != 0) &&
2889 (c->layer[0].segment_count != 0xff) &&
2890 (c->layer[0].segment_count != 0) &&
2891 ((c->layer[0].modulation == QAM_AUTO) ||
2892 (c->layer[0].fec == FEC_AUTO))) ||
2893 (((c->isdbt_layer_enabled & (1 << 1)) != 0) &&
2894 (c->layer[1].segment_count != 0xff) &&
2895 (c->layer[1].segment_count != 0) &&
2896 ((c->layer[1].modulation == QAM_AUTO) ||
2897 (c->layer[1].fec == FEC_AUTO))) ||
2898 (((c->isdbt_layer_enabled & (1 << 2)) != 0) &&
2899 (c->layer[2].segment_count != 0xff) &&
2900 (c->layer[2].segment_count != 0) &&
2901 ((c->layer[2].modulation == QAM_AUTO) ||
2902 (c->layer[2].fec == FEC_AUTO))) ||
2903 (((c->layer[0].segment_count == 0) ||
2904 ((c->isdbt_layer_enabled & (1 << 0)) == 0)) &&
2905 ((c->layer[1].segment_count == 0) ||
2906 ((c->isdbt_layer_enabled & (2 << 0)) == 0)) &&
2907 ((c->layer[2].segment_count == 0) || ((c->isdbt_layer_enabled & (3 << 0)) == 0))))
2908 state->channel_parameters_set = 0; /* auto search */
2909 else
2910 state->channel_parameters_set = 1; /* channel parameters are known */
2911
2912 dib8000_viterbi_state(state, 0); /* force chan dec in restart */
2913
2914 /* Layer monit */
2915 dib8000_write_word(state, 285, dib8000_read_word(state, 285) & 0x60);
2916
2917 dib8000_set_frequency_offset(state);
2918 dib8000_set_bandwidth(fe, c->bandwidth_hz / 1000);
2919
2920 if (state->channel_parameters_set == 0) { /* The channel struct is unknown, search it ! */
2921#ifdef DIB8000_AGC_FREEZE
2922 if (state->revision != 0x8090) {
2923 state->agc1_max = dib8000_read_word(state, 108);
2924 state->agc1_min = dib8000_read_word(state, 109);
2925 state->agc2_max = dib8000_read_word(state, 110);
2926 state->agc2_min = dib8000_read_word(state, 111);
2927 agc1 = dib8000_read_word(state, 388);
2928 agc2 = dib8000_read_word(state, 389);
2929 dib8000_write_word(state, 108, agc1);
2930 dib8000_write_word(state, 109, agc1);
2931 dib8000_write_word(state, 110, agc2);
2932 dib8000_write_word(state, 111, agc2);
2933 }
2934#endif
2935 state->autosearch_state = AS_SEARCHING_FFT;
2936 state->found_nfft = TRANSMISSION_MODE_AUTO;
2937 state->found_guard = GUARD_INTERVAL_AUTO;
2938 *tune_state = CT_DEMOD_SEARCH_NEXT;
2939 } else { /* we already know the channel struct so TUNE only ! */
2940 state->autosearch_state = AS_DONE;
2941 *tune_state = CT_DEMOD_STEP_3;
2942 }
2943 state->symbol_duration = dib8000_get_symbol_duration(state);
2944 break;
2945
2946 case CT_DEMOD_SEARCH_NEXT: /* 51 */
2947 dib8000_autosearch_start(fe);
2948 if (state->revision == 0x8090)
2949 ret = 50;
2950 else
2951 ret = 15;
2952 *tune_state = CT_DEMOD_STEP_1;
2953 break;
2954
2955 case CT_DEMOD_STEP_1: /* 31 */
2956 switch (dib8000_autosearch_irq(fe)) {
2957 case 1: /* fail */
2958 state->status = FE_STATUS_TUNE_FAILED;
2959 state->autosearch_state = AS_DONE;
2960 *tune_state = CT_DEMOD_STOP; /* else we are done here */
2961 break;
2962 case 2: /* Succes */
2963 state->status = FE_STATUS_FFT_SUCCESS; /* signal to the upper layer, that there was a channel found and the parameters can be read */
2964 *tune_state = CT_DEMOD_STEP_3;
2965 if (state->autosearch_state == AS_SEARCHING_GUARD)
2966 *tune_state = CT_DEMOD_STEP_2;
2967 else
2968 state->autosearch_state = AS_DONE;
2969 break;
2970 case 3: /* Autosearch FFT max correlation endded */
2971 *tune_state = CT_DEMOD_STEP_2;
2972 break;
2973 }
2974 break;
2975
2976 case CT_DEMOD_STEP_2:
2977 switch (state->autosearch_state) {
2978 case AS_SEARCHING_FFT:
2979 /* searching for the correct FFT */
2980 if (state->revision == 0x8090) {
2981 corm[2] = (dib8000_read_word(state, 596) << 16) | (dib8000_read_word(state, 597));
2982 corm[1] = (dib8000_read_word(state, 598) << 16) | (dib8000_read_word(state, 599));
2983 corm[0] = (dib8000_read_word(state, 600) << 16) | (dib8000_read_word(state, 601));
2984 } else {
2985 corm[2] = (dib8000_read_word(state, 594) << 16) | (dib8000_read_word(state, 595));
2986 corm[1] = (dib8000_read_word(state, 596) << 16) | (dib8000_read_word(state, 597));
2987 corm[0] = (dib8000_read_word(state, 598) << 16) | (dib8000_read_word(state, 599));
2988 }
2989 /* dprintk("corm fft: %u %u %u", corm[0], corm[1], corm[2]); */
2990
2991 max_value = 0;
2992 for (find_index = 1 ; find_index < 3 ; find_index++) {
2993 if (corm[max_value] < corm[find_index])
2994 max_value = find_index ;
2995 }
2996
2997 switch (max_value) {
2998 case 0:
2999 state->found_nfft = TRANSMISSION_MODE_2K;
3000 break;
3001 case 1:
3002 state->found_nfft = TRANSMISSION_MODE_4K;
3003 break;
3004 case 2:
3005 default:
3006 state->found_nfft = TRANSMISSION_MODE_8K;
3007 break;
3008 }
3009 /* dprintk("Autosearch FFT has found Mode %d", max_value + 1); */
3010
3011 *tune_state = CT_DEMOD_SEARCH_NEXT;
3012 state->autosearch_state = AS_SEARCHING_GUARD;
3013 if (state->revision == 0x8090)
3014 ret = 50;
3015 else
3016 ret = 10;
3017 break;
3018 case AS_SEARCHING_GUARD:
3019 /* searching for the correct guard interval */
3020 if (state->revision == 0x8090)
3021 state->found_guard = dib8000_read_word(state, 572) & 0x3;
3022 else
3023 state->found_guard = dib8000_read_word(state, 570) & 0x3;
3024 /* dprintk("guard interval found=%i", state->found_guard); */
3025
3026 *tune_state = CT_DEMOD_STEP_3;
3027 break;
3028 default:
3029 /* the demod should never be in this state */
3030 state->status = FE_STATUS_TUNE_FAILED;
3031 state->autosearch_state = AS_DONE;
3032 *tune_state = CT_DEMOD_STOP; /* else we are done here */
3033 break;
3034 }
3035 break;
3036
3037 case CT_DEMOD_STEP_3: /* 33 */
3038 state->symbol_duration = dib8000_get_symbol_duration(state);
3039 dib8000_set_isdbt_loop_params(state, LOOP_TUNE_1);
3040 dib8000_set_isdbt_common_channel(state, 0, 0);/* setting the known channel parameters here */
3041 *tune_state = CT_DEMOD_STEP_4;
3042 break;
3043
3044 case CT_DEMOD_STEP_4: /* (34) */
3045 dib8000_demod_restart(state);
3046
3047 dib8000_set_sync_wait(state);
3048 dib8000_set_diversity_in(state->fe[0], state->diversity_onoff);
3049
3050 locks = (dib8000_read_word(state, 180) >> 6) & 0x3f; /* P_coff_winlen ? */
3051 /* coff should lock over P_coff_winlen ofdm symbols : give 3 times this lenght to lock */
3052 *timeout = dib8000_get_timeout(state, 2 * locks, SYMBOL_DEPENDENT_ON);
3053 *tune_state = CT_DEMOD_STEP_5;
3054 break;
3055
3056 case CT_DEMOD_STEP_5: /* (35) */
3057 locks = dib8000_read_lock(fe);
3058 if (locks & (0x3 << 11)) { /* coff-lock and off_cpil_lock achieved */
3059 dib8000_update_timf(state); /* we achieved a coff_cpil_lock - it's time to update the timf */
3060 if (!state->differential_constellation) {
3061 /* 2 times lmod4_win_len + 10 symbols (pipe delay after coff + nb to compute a 1st correlation) */
3062 *timeout = dib8000_get_timeout(state, (20 * ((dib8000_read_word(state, 188)>>5)&0x1f)), SYMBOL_DEPENDENT_ON);
3063 *tune_state = CT_DEMOD_STEP_7;
3064 } else {
3065 *tune_state = CT_DEMOD_STEP_8;
3066 }
3067 } else if (now > *timeout) {
3068 *tune_state = CT_DEMOD_STEP_6; /* goto check for diversity input connection */
3069 }
3070 break;
3071
3072 case CT_DEMOD_STEP_6: /* (36) if there is an input (diversity) */
3073 if ((state->fe[1] != NULL) && (state->output_mode != OUTMODE_DIVERSITY)) {
3074 /* if there is a diversity fe in input and this fe is has not already failled : wait here until this this fe has succedeed or failled */
3075 if (dib8000_get_status(state->fe[1]) <= FE_STATUS_STD_SUCCESS) /* Something is locked on the input fe */
3076 *tune_state = CT_DEMOD_STEP_8; /* go for mpeg */
3077 else if (dib8000_get_status(state->fe[1]) >= FE_STATUS_TUNE_TIME_TOO_SHORT) { /* fe in input failled also, break the current one */
3078 *tune_state = CT_DEMOD_STOP; /* else we are done here ; step 8 will close the loops and exit */
3079 dib8000_viterbi_state(state, 1); /* start viterbi chandec */
3080 dib8000_set_isdbt_loop_params(state, LOOP_TUNE_2);
3081 state->status = FE_STATUS_TUNE_FAILED;
3082 }
3083 } else {
3084 dib8000_viterbi_state(state, 1); /* start viterbi chandec */
3085 dib8000_set_isdbt_loop_params(state, LOOP_TUNE_2);
3086 *tune_state = CT_DEMOD_STOP; /* else we are done here ; step 8 will close the loops and exit */
3087 state->status = FE_STATUS_TUNE_FAILED;
3088 }
3089 break;
3090
3091 case CT_DEMOD_STEP_7: /* 37 */
3092 locks = dib8000_read_lock(fe);
3093 if (locks & (1<<10)) { /* lmod4_lock */
3094 ret = 14; /* wait for 14 symbols */
3095 *tune_state = CT_DEMOD_STEP_8;
3096 } else if (now > *timeout)
3097 *tune_state = CT_DEMOD_STEP_6; /* goto check for diversity input connection */
3098 break;
3099
3100 case CT_DEMOD_STEP_8: /* 38 */
3101 dib8000_viterbi_state(state, 1); /* start viterbi chandec */
3102 dib8000_set_isdbt_loop_params(state, LOOP_TUNE_2);
3103
3104 /* mpeg will never lock on this condition because init_prbs is not set : search for it !*/
3105 if (c->isdbt_sb_mode
3106 && c->isdbt_sb_subchannel < 14
3107 && !state->differential_constellation) {
3108 state->subchannel = 0;
3109 *tune_state = CT_DEMOD_STEP_11;
3110 } else {
3111 *tune_state = CT_DEMOD_STEP_9;
3112 state->status = FE_STATUS_LOCKED;
3113 }
3114 break;
3115
3116 case CT_DEMOD_STEP_9: /* 39 */
3117 if ((state->revision == 0x8090) || ((dib8000_read_word(state, 1291) >> 9) & 0x1)) { /* fe capable of deinterleaving : esram */
3118 /* defines timeout for mpeg lock depending on interleaver lenght of longest layer */
3119 for (i = 0; i < 3; i++) {
3120 if (c->layer[i].interleaving >= deeper_interleaver) {
3121 dprintk("layer%i: time interleaver = %d ", i, c->layer[i].interleaving);
3122 if (c->layer[i].segment_count > 0) { /* valid layer */
3123 deeper_interleaver = c->layer[0].interleaving;
3124 state->longest_intlv_layer = i;
3125 }
3126 }
3127 }
3128
3129 if (deeper_interleaver == 0)
3130 locks = 2; /* locks is the tmp local variable name */
3131 else if (deeper_interleaver == 3)
3132 locks = 8;
3133 else
3134 locks = 2 * deeper_interleaver;
3135
3136 if (state->diversity_onoff != 0) /* because of diversity sync */
3137 locks *= 2;
3138
3139 *timeout = now + (2000 * locks); /* give the mpeg lock 800ms if sram is present */
3140 dprintk("Deeper interleaver mode = %d on layer %d : timeout mult factor = %d => will use timeout = %d", deeper_interleaver, state->longest_intlv_layer, locks, *timeout);
3141
3142 *tune_state = CT_DEMOD_STEP_10;
3143 } else
3144 *tune_state = CT_DEMOD_STOP;
3145 break;
3146
3147 case CT_DEMOD_STEP_10: /* 40 */
3148 locks = dib8000_read_lock(fe);
3149 if (locks&(1<<(7-state->longest_intlv_layer))) { /* mpeg lock : check the longest one */
3150 dprintk("Mpeg locks [ L0 : %d | L1 : %d | L2 : %d ]", (locks>>7)&0x1, (locks>>6)&0x1, (locks>>5)&0x1);
3151 if (c->isdbt_sb_mode
3152 && c->isdbt_sb_subchannel < 14
3153 && !state->differential_constellation)
3154 /* signal to the upper layer, that there was a channel found and the parameters can be read */
3155 state->status = FE_STATUS_DEMOD_SUCCESS;
3156 else
3157 state->status = FE_STATUS_DATA_LOCKED;
3158 *tune_state = CT_DEMOD_STOP;
3159 } else if (now > *timeout) {
3160 if (c->isdbt_sb_mode
3161 && c->isdbt_sb_subchannel < 14
3162 && !state->differential_constellation) { /* continue to try init prbs autosearch */
3163 state->subchannel += 3;
3164 *tune_state = CT_DEMOD_STEP_11;
3165 } else { /* we are done mpeg of the longest interleaver xas not locking but let's try if an other layer has locked in the same time */
3166 if (locks & (0x7<<5)) {
3167 dprintk("Mpeg locks [ L0 : %d | L1 : %d | L2 : %d ]", (locks>>7)&0x1, (locks>>6)&0x1, (locks>>5)&0x1);
3168 state->status = FE_STATUS_DATA_LOCKED;
3169 } else
3170 state->status = FE_STATUS_TUNE_FAILED;
3171 *tune_state = CT_DEMOD_STOP;
3172 }
3173 }
3174 break;
3175
3176 case CT_DEMOD_STEP_11: /* 41 : init prbs autosearch */
3177 if (state->subchannel <= 41) {
3178 dib8000_set_subchannel_prbs(state, dib8000_get_init_prbs(state, state->subchannel));
3179 *tune_state = CT_DEMOD_STEP_9;
3180 } else {
3181 *tune_state = CT_DEMOD_STOP;
3182 state->status = FE_STATUS_TUNE_FAILED;
3183 }
3184 break;
3185
3186 default:
3187 break;
3188 }
3189
3190 /* tuning is finished - cleanup the demod */
3191 switch (*tune_state) {
3192 case CT_DEMOD_STOP: /* (42) */
3193#ifdef DIB8000_AGC_FREEZE
3194 if ((state->revision != 0x8090) && (state->agc1_max != 0)) {
3195 dib8000_write_word(state, 108, state->agc1_max);
3196 dib8000_write_word(state, 109, state->agc1_min);
3197 dib8000_write_word(state, 110, state->agc2_max);
3198 dib8000_write_word(state, 111, state->agc2_min);
3199 state->agc1_max = 0;
3200 state->agc1_min = 0;
3201 state->agc2_max = 0;
3202 state->agc2_min = 0;
3203 }
3204#endif
3205 ret = FE_CALLBACK_TIME_NEVER;
3206 break;
3207 default:
3208 break;
2754 } 3209 }
2755 3210
3211 if ((ret > 0) && (*tune_state > CT_DEMOD_STEP_3))
3212 return ret * state->symbol_duration;
3213 if ((ret > 0) && (ret < state->symbol_duration))
3214 return state->symbol_duration; /* at least one symbol */
2756 return ret; 3215 return ret;
2757} 3216}
2758 3217
@@ -2767,7 +3226,7 @@ static int dib8000_wakeup(struct dvb_frontend *fe)
2767 if (dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0) 3226 if (dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0)
2768 dprintk("could not start Slow ADC"); 3227 dprintk("could not start Slow ADC");
2769 3228
2770 if (state->revision != 0x8090) 3229 if (state->revision == 0x8090)
2771 dib8000_sad_calib(state); 3230 dib8000_sad_calib(state);
2772 3231
2773 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) { 3232 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
@@ -2797,21 +3256,6 @@ static int dib8000_sleep(struct dvb_frontend *fe)
2797 return dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(state, DIBX000_ADC_OFF); 3256 return dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(state, DIBX000_ADC_OFF);
2798} 3257}
2799 3258
2800enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe)
2801{
2802 struct dib8000_state *state = fe->demodulator_priv;
2803 return state->tune_state;
2804}
2805EXPORT_SYMBOL(dib8000_get_tune_state);
2806
2807int dib8000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state)
2808{
2809 struct dib8000_state *state = fe->demodulator_priv;
2810 state->tune_state = tune_state;
2811 return 0;
2812}
2813EXPORT_SYMBOL(dib8000_set_tune_state);
2814
2815static int dib8000_get_frontend(struct dvb_frontend *fe) 3259static int dib8000_get_frontend(struct dvb_frontend *fe)
2816{ 3260{
2817 struct dib8000_state *state = fe->demodulator_priv; 3261 struct dib8000_state *state = fe->demodulator_priv;
@@ -2961,19 +3405,19 @@ static int dib8000_get_frontend(struct dvb_frontend *fe)
2961static int dib8000_set_frontend(struct dvb_frontend *fe) 3405static int dib8000_set_frontend(struct dvb_frontend *fe)
2962{ 3406{
2963 struct dib8000_state *state = fe->demodulator_priv; 3407 struct dib8000_state *state = fe->demodulator_priv;
2964 u8 nbr_pending, exit_condition, index_frontend; 3408 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
2965 s8 index_frontend_success = -1; 3409 int l, i, active, time, ret, time_slave = FE_CALLBACK_TIME_NEVER;
2966 int time, ret; 3410 u8 exit_condition, index_frontend;
2967 int time_slave = FE_CALLBACK_TIME_NEVER; 3411 u32 delay, callback_time;
2968 3412
2969 if (state->fe[0]->dtv_property_cache.frequency == 0) { 3413 if (c->frequency == 0) {
2970 dprintk("dib8000: must at least specify frequency "); 3414 dprintk("dib8000: must at least specify frequency ");
2971 return 0; 3415 return 0;
2972 } 3416 }
2973 3417
2974 if (state->fe[0]->dtv_property_cache.bandwidth_hz == 0) { 3418 if (c->bandwidth_hz == 0) {
2975 dprintk("dib8000: no bandwidth specified, set to default "); 3419 dprintk("dib8000: no bandwidth specified, set to default ");
2976 state->fe[0]->dtv_property_cache.bandwidth_hz = 6000000; 3420 c->bandwidth_hz = 6000000;
2977 } 3421 }
2978 3422
2979 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) { 3423 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
@@ -2981,18 +3425,36 @@ static int dib8000_set_frontend(struct dvb_frontend *fe)
2981 state->fe[index_frontend]->dtv_property_cache.delivery_system = SYS_ISDBT; 3425 state->fe[index_frontend]->dtv_property_cache.delivery_system = SYS_ISDBT;
2982 memcpy(&state->fe[index_frontend]->dtv_property_cache, &fe->dtv_property_cache, sizeof(struct dtv_frontend_properties)); 3426 memcpy(&state->fe[index_frontend]->dtv_property_cache, &fe->dtv_property_cache, sizeof(struct dtv_frontend_properties));
2983 3427
2984 if (state->revision != 0x8090) 3428 /* set output mode and diversity input */
2985 dib8000_set_output_mode(state->fe[index_frontend], 3429 if (state->revision != 0x8090) {
2986 OUTMODE_HIGH_Z); 3430 dib8000_set_diversity_in(state->fe[index_frontend], 1);
2987 else 3431 if (index_frontend != 0)
2988 dib8096p_set_output_mode(state->fe[index_frontend], 3432 dib8000_set_output_mode(state->fe[index_frontend],
2989 OUTMODE_HIGH_Z); 3433 OUTMODE_DIVERSITY);
3434 else
3435 dib8000_set_output_mode(state->fe[0], OUTMODE_HIGH_Z);
3436 } else {
3437 dib8096p_set_diversity_in(state->fe[index_frontend], 1);
3438 if (index_frontend != 0)
3439 dib8096p_set_output_mode(state->fe[index_frontend],
3440 OUTMODE_DIVERSITY);
3441 else
3442 dib8096p_set_output_mode(state->fe[0], OUTMODE_HIGH_Z);
3443 }
3444
3445 /* tune the tuner */
2990 if (state->fe[index_frontend]->ops.tuner_ops.set_params) 3446 if (state->fe[index_frontend]->ops.tuner_ops.set_params)
2991 state->fe[index_frontend]->ops.tuner_ops.set_params(state->fe[index_frontend]); 3447 state->fe[index_frontend]->ops.tuner_ops.set_params(state->fe[index_frontend]);
2992 3448
2993 dib8000_set_tune_state(state->fe[index_frontend], CT_AGC_START); 3449 dib8000_set_tune_state(state->fe[index_frontend], CT_AGC_START);
2994 } 3450 }
2995 3451
3452 /* turn off the diversity of the last chip */
3453 if (state->revision != 0x8090)
3454 dib8000_set_diversity_in(state->fe[index_frontend - 1], 0);
3455 else
3456 dib8096p_set_diversity_in(state->fe[index_frontend - 1], 0);
3457
2996 /* start up the AGC */ 3458 /* start up the AGC */
2997 do { 3459 do {
2998 time = dib8000_agc_startup(state->fe[0]); 3460 time = dib8000_agc_startup(state->fe[0]);
@@ -3019,139 +3481,88 @@ static int dib8000_set_frontend(struct dvb_frontend *fe)
3019 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) 3481 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
3020 dib8000_set_tune_state(state->fe[index_frontend], CT_DEMOD_START); 3482 dib8000_set_tune_state(state->fe[index_frontend], CT_DEMOD_START);
3021 3483
3022 if ((state->fe[0]->dtv_property_cache.delivery_system != SYS_ISDBT) || 3484 active = 1;
3023 (state->fe[0]->dtv_property_cache.inversion == INVERSION_AUTO) || 3485 do {
3024 (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) || 3486 callback_time = FE_CALLBACK_TIME_NEVER;
3025 (state->fe[0]->dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) ||
3026 (((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 0)) != 0) &&
3027 (state->fe[0]->dtv_property_cache.layer[0].segment_count != 0xff) &&
3028 (state->fe[0]->dtv_property_cache.layer[0].segment_count != 0) &&
3029 ((state->fe[0]->dtv_property_cache.layer[0].modulation == QAM_AUTO) ||
3030 (state->fe[0]->dtv_property_cache.layer[0].fec == FEC_AUTO))) ||
3031 (((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 1)) != 0) &&
3032 (state->fe[0]->dtv_property_cache.layer[1].segment_count != 0xff) &&
3033 (state->fe[0]->dtv_property_cache.layer[1].segment_count != 0) &&
3034 ((state->fe[0]->dtv_property_cache.layer[1].modulation == QAM_AUTO) ||
3035 (state->fe[0]->dtv_property_cache.layer[1].fec == FEC_AUTO))) ||
3036 (((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 2)) != 0) &&
3037 (state->fe[0]->dtv_property_cache.layer[2].segment_count != 0xff) &&
3038 (state->fe[0]->dtv_property_cache.layer[2].segment_count != 0) &&
3039 ((state->fe[0]->dtv_property_cache.layer[2].modulation == QAM_AUTO) ||
3040 (state->fe[0]->dtv_property_cache.layer[2].fec == FEC_AUTO))) ||
3041 (((state->fe[0]->dtv_property_cache.layer[0].segment_count == 0) ||
3042 ((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 0)) == 0)) &&
3043 ((state->fe[0]->dtv_property_cache.layer[1].segment_count == 0) ||
3044 ((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (2 << 0)) == 0)) &&
3045 ((state->fe[0]->dtv_property_cache.layer[2].segment_count == 0) || ((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (3 << 0)) == 0)))) {
3046 int i = 100;
3047 u8 found = 0;
3048 u8 tune_failed = 0;
3049
3050 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) { 3487 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
3051 dib8000_set_bandwidth(state->fe[index_frontend], fe->dtv_property_cache.bandwidth_hz / 1000); 3488 delay = dib8000_tune(state->fe[index_frontend]);
3052 dib8000_autosearch_start(state->fe[index_frontend]); 3489 if (delay != FE_CALLBACK_TIME_NEVER)
3053 } 3490 delay += systime();
3054 3491
3055 do { 3492 /* we are in autosearch */
3056 msleep(20); 3493 if (state->channel_parameters_set == 0) { /* searching */
3057 nbr_pending = 0; 3494 if ((dib8000_get_status(state->fe[index_frontend]) == FE_STATUS_DEMOD_SUCCESS) || (dib8000_get_status(state->fe[index_frontend]) == FE_STATUS_FFT_SUCCESS)) {
3058 exit_condition = 0; /* 0: tune pending; 1: tune failed; 2:tune success */ 3495 dprintk("autosearch succeeded on fe%i", index_frontend);
3059 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) { 3496 dib8000_get_frontend(state->fe[index_frontend]); /* we read the channel parameters from the frontend which was successful */
3060 if (((tune_failed >> index_frontend) & 0x1) == 0) { 3497 state->channel_parameters_set = 1;
3061 found = dib8000_autosearch_irq(state->fe[index_frontend]); 3498
3062 switch (found) { 3499 for (l = 0; (l < MAX_NUMBER_OF_FRONTENDS) && (state->fe[l] != NULL); l++) {
3063 case 0: /* tune pending */ 3500 if (l != index_frontend) { /* and for all frontend except the successful one */
3064 nbr_pending++; 3501 dib8000_tune_restart_from_demod(state->fe[l]);
3065 break; 3502
3066 case 2: 3503 state->fe[l]->dtv_property_cache.isdbt_sb_mode = state->fe[index_frontend]->dtv_property_cache.isdbt_sb_mode;
3067 dprintk("autosearch succeed on the frontend%i", index_frontend); 3504 state->fe[l]->dtv_property_cache.inversion = state->fe[index_frontend]->dtv_property_cache.inversion;
3068 exit_condition = 2; 3505 state->fe[l]->dtv_property_cache.transmission_mode = state->fe[index_frontend]->dtv_property_cache.transmission_mode;
3069 index_frontend_success = index_frontend; 3506 state->fe[l]->dtv_property_cache.guard_interval = state->fe[index_frontend]->dtv_property_cache.guard_interval;
3070 break; 3507 state->fe[l]->dtv_property_cache.isdbt_partial_reception = state->fe[index_frontend]->dtv_property_cache.isdbt_partial_reception;
3071 default: 3508 for (i = 0; i < 3; i++) {
3072 dprintk("unhandled autosearch result"); 3509 state->fe[l]->dtv_property_cache.layer[i].segment_count = state->fe[index_frontend]->dtv_property_cache.layer[i].segment_count;
3073 case 1: 3510 state->fe[l]->dtv_property_cache.layer[i].interleaving = state->fe[index_frontend]->dtv_property_cache.layer[i].interleaving;
3074 tune_failed |= (1 << index_frontend); 3511 state->fe[l]->dtv_property_cache.layer[i].fec = state->fe[index_frontend]->dtv_property_cache.layer[i].fec;
3075 dprintk("autosearch failed for the frontend%i", index_frontend); 3512 state->fe[l]->dtv_property_cache.layer[i].modulation = state->fe[index_frontend]->dtv_property_cache.layer[i].modulation;
3076 break; 3513 }
3514
3515 }
3077 } 3516 }
3078 } 3517 }
3079 } 3518 }
3080 3519 if (delay < callback_time)
3081 /* if all tune are done and no success, exit: tune failed */ 3520 callback_time = delay;
3082 if ((nbr_pending == 0) && (exit_condition == 0)) 3521 }
3083 exit_condition = 1; 3522 /* tuning is done when the master frontend is done (failed or success) */
3084 } while ((exit_condition == 0) && i--); 3523 if (dib8000_get_status(state->fe[0]) == FE_STATUS_TUNE_FAILED ||
3085 3524 dib8000_get_status(state->fe[0]) == FE_STATUS_LOCKED ||
3086 if (exit_condition == 1) { /* tune failed */ 3525 dib8000_get_status(state->fe[0]) == FE_STATUS_DATA_LOCKED) {
3087 dprintk("tune failed"); 3526 active = 0;
3088 return 0; 3527 /* we need to wait for all frontends to be finished */
3528 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
3529 if (dib8000_get_tune_state(state->fe[index_frontend]) != CT_DEMOD_STOP)
3530 active = 1;
3531 }
3532 if (active == 0)
3533 dprintk("tuning done with status %d", dib8000_get_status(state->fe[0]));
3089 } 3534 }
3090 3535
3091 dprintk("tune success on frontend%i", index_frontend_success); 3536 if ((active == 1) && (callback_time == FE_CALLBACK_TIME_NEVER)) {
3092 3537 dprintk("strange callback time something went wrong");
3093 dib8000_get_frontend(fe); 3538 active = 0;
3094 } 3539 }
3095 3540
3096 for (index_frontend = 0, ret = 0; (ret >= 0) && (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) 3541 while ((active == 1) && (systime() < callback_time))
3097 ret = dib8000_tune(state->fe[index_frontend]); 3542 msleep(100);
3543 } while (active);
3098 3544
3099 /* set output mode and diversity input */ 3545 /* set output mode */
3100 if (state->revision != 0x8090) { 3546 if (state->revision != 0x8090)
3101 dib8000_set_output_mode(state->fe[0], state->cfg.output_mode); 3547 dib8000_set_output_mode(state->fe[0], state->cfg.output_mode);
3102 for (index_frontend = 1; 3548 else {
3103 (index_frontend < MAX_NUMBER_OF_FRONTENDS) &&
3104 (state->fe[index_frontend] != NULL);
3105 index_frontend++) {
3106 dib8000_set_output_mode(state->fe[index_frontend],
3107 OUTMODE_DIVERSITY);
3108 dib8000_set_diversity_in(state->fe[index_frontend-1], 1);
3109 }
3110
3111 /* turn off the diversity of the last chip */
3112 dib8000_set_diversity_in(state->fe[index_frontend-1], 0);
3113 } else {
3114 dib8096p_set_output_mode(state->fe[0], state->cfg.output_mode); 3549 dib8096p_set_output_mode(state->fe[0], state->cfg.output_mode);
3115 if (state->cfg.enMpegOutput == 0) { 3550 if (state->cfg.enMpegOutput == 0) {
3116 dib8096p_setDibTxMux(state, MPEG_ON_DIBTX); 3551 dib8096p_setDibTxMux(state, MPEG_ON_DIBTX);
3117 dib8096p_setHostBusMux(state, DIBTX_ON_HOSTBUS); 3552 dib8096p_setHostBusMux(state, DIBTX_ON_HOSTBUS);
3118 } 3553 }
3119 for (index_frontend = 1;
3120 (index_frontend < MAX_NUMBER_OF_FRONTENDS) &&
3121 (state->fe[index_frontend] != NULL);
3122 index_frontend++) {
3123 dib8096p_set_output_mode(state->fe[index_frontend],
3124 OUTMODE_DIVERSITY);
3125 dib8096p_set_diversity_in(state->fe[index_frontend-1], 1);
3126 }
3127
3128 /* turn off the diversity of the last chip */
3129 dib8096p_set_diversity_in(state->fe[index_frontend-1], 0);
3130 } 3554 }
3131 3555
3132 return ret; 3556 return ret;
3133} 3557}
3134 3558
3135static u16 dib8000_read_lock(struct dvb_frontend *fe)
3136{
3137 struct dib8000_state *state = fe->demodulator_priv;
3138
3139 if (state->revision == 0x8090)
3140 return dib8000_read_word(state, 570);
3141 return dib8000_read_word(state, 568);
3142}
3143
3144static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat) 3559static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
3145{ 3560{
3146 struct dib8000_state *state = fe->demodulator_priv; 3561 struct dib8000_state *state = fe->demodulator_priv;
3147 u16 lock_slave = 0, lock; 3562 u16 lock_slave = 0, lock;
3148 u8 index_frontend; 3563 u8 index_frontend;
3149 3564
3150 if (state->revision == 0x8090) 3565 lock = dib8000_read_lock(fe);
3151 lock = dib8000_read_word(state, 570);
3152 else
3153 lock = dib8000_read_word(state, 568);
3154
3155 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) 3566 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
3156 lock_slave |= dib8000_read_lock(state->fe[index_frontend]); 3567 lock_slave |= dib8000_read_lock(state->fe[index_frontend]);
3157 3568
@@ -3545,10 +3956,11 @@ struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, s
3545 dib8000_reset(fe); 3956 dib8000_reset(fe);
3546 3957
3547 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & ~0x60) | (3 << 5)); /* ber_rs_len = 3 */ 3958 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & ~0x60) | (3 << 5)); /* ber_rs_len = 3 */
3959 state->current_demod_bw = 6000;
3548 3960
3549 return fe; 3961 return fe;
3550 3962
3551 error: 3963error:
3552 kfree(state); 3964 kfree(state);
3553 return NULL; 3965 return NULL;
3554} 3966}
diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
index 9e7a2b170d55..b8c11e52c512 100644
--- a/drivers/media/dvb-frontends/dib8000.h
+++ b/drivers/media/dvb-frontends/dib8000.h
@@ -33,6 +33,8 @@ struct dib8000_config {
33 u8 output_mode; 33 u8 output_mode;
34 u8 refclksel; 34 u8 refclksel;
35 u8 enMpegOutput:1; 35 u8 enMpegOutput:1;
36
37 struct dibx000_bandwidth_config *plltable;
36}; 38};
37 39
38#define DEFAULT_DIB8000_I2C_ADDRESS 18 40#define DEFAULT_DIB8000_I2C_ADDRESS 18
@@ -58,7 +60,7 @@ extern int dib8090p_get_dc_power(struct dvb_frontend *fe, u8 IQ);
58extern u32 dib8000_ctrl_timf(struct dvb_frontend *fe, 60extern u32 dib8000_ctrl_timf(struct dvb_frontend *fe,
59 uint8_t op, uint32_t timf); 61 uint8_t op, uint32_t timf);
60extern int dib8000_update_pll(struct dvb_frontend *fe, 62extern int dib8000_update_pll(struct dvb_frontend *fe,
61 struct dibx000_bandwidth_config *pll); 63 struct dibx000_bandwidth_config *pll, u32 bw, u8 ratio);
62extern int dib8000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave); 64extern int dib8000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave);
63extern int dib8000_remove_slave_frontend(struct dvb_frontend *fe); 65extern int dib8000_remove_slave_frontend(struct dvb_frontend *fe);
64extern struct dvb_frontend *dib8000_get_slave_frontend(struct dvb_frontend *fe, int slave_index); 66extern struct dvb_frontend *dib8000_get_slave_frontend(struct dvb_frontend *fe, int slave_index);
@@ -147,7 +149,7 @@ static inline u32 dib8000_ctrl_timf(struct dvb_frontend *fe,
147 return 0; 149 return 0;
148} 150}
149static inline int dib8000_update_pll(struct dvb_frontend *fe, 151static inline int dib8000_update_pll(struct dvb_frontend *fe,
150 struct dibx000_bandwidth_config *pll) 152 struct dibx000_bandwidth_config *pll, u32 bw, u8 ratio)
151{ 153{
152 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 154 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
153 return -ENODEV; 155 return -ENODEV;
diff --git a/drivers/media/dvb-frontends/dibx000_common.h b/drivers/media/dvb-frontends/dibx000_common.h
index 5f484881d7b1..b538e0555c95 100644
--- a/drivers/media/dvb-frontends/dibx000_common.h
+++ b/drivers/media/dvb-frontends/dibx000_common.h
@@ -193,7 +193,8 @@ enum frontend_tune_state {
193 CT_DEMOD_STEP_8, 193 CT_DEMOD_STEP_8,
194 CT_DEMOD_STEP_9, 194 CT_DEMOD_STEP_9,
195 CT_DEMOD_STEP_10, 195 CT_DEMOD_STEP_10,
196 CT_DEMOD_SEARCH_NEXT = 41, 196 CT_DEMOD_STEP_11,
197 CT_DEMOD_SEARCH_NEXT = 51,
197 CT_DEMOD_STEP_LOCKED, 198 CT_DEMOD_STEP_LOCKED,
198 CT_DEMOD_STOP, 199 CT_DEMOD_STOP,
199 200
diff --git a/drivers/media/dvb-frontends/drxd.h b/drivers/media/dvb-frontends/drxd.h
index 216c8c3702f8..5f1d6b5f1685 100644
--- a/drivers/media/dvb-frontends/drxd.h
+++ b/drivers/media/dvb-frontends/drxd.h
@@ -24,6 +24,7 @@
24#ifndef _DRXD_H_ 24#ifndef _DRXD_H_
25#define _DRXD_H_ 25#define _DRXD_H_
26 26
27#include <linux/kconfig.h>
27#include <linux/types.h> 28#include <linux/types.h>
28#include <linux/i2c.h> 29#include <linux/i2c.h>
29 30
@@ -51,8 +52,7 @@ struct drxd_config {
51 s16(*osc_deviation) (void *priv, s16 dev, int flag); 52 s16(*osc_deviation) (void *priv, s16 dev, int flag);
52}; 53};
53 54
54#if defined(CONFIG_DVB_DRXD) || \ 55#if IS_ENABLED(CONFIG_DVB_DRXD)
55 (defined(CONFIG_DVB_DRXD_MODULE) && defined(MODULE))
56extern 56extern
57struct dvb_frontend *drxd_attach(const struct drxd_config *config, 57struct dvb_frontend *drxd_attach(const struct drxd_config *config,
58 void *priv, struct i2c_adapter *i2c, 58 void *priv, struct i2c_adapter *i2c,
diff --git a/drivers/media/dvb-frontends/drxk.h b/drivers/media/dvb-frontends/drxk.h
index 94fecfbf14c1..e6667189ddce 100644
--- a/drivers/media/dvb-frontends/drxk.h
+++ b/drivers/media/dvb-frontends/drxk.h
@@ -1,6 +1,7 @@
1#ifndef _DRXK_H_ 1#ifndef _DRXK_H_
2#define _DRXK_H_ 2#define _DRXK_H_
3 3
4#include <linux/kconfig.h>
4#include <linux/types.h> 5#include <linux/types.h>
5#include <linux/i2c.h> 6#include <linux/i2c.h>
6 7
@@ -52,8 +53,7 @@ struct drxk_config {
52 int qam_demod_parameter_count; 53 int qam_demod_parameter_count;
53}; 54};
54 55
55#if defined(CONFIG_DVB_DRXK) || (defined(CONFIG_DVB_DRXK_MODULE) \ 56#if IS_ENABLED(CONFIG_DVB_DRXK)
56 && defined(MODULE))
57extern struct dvb_frontend *drxk_attach(const struct drxk_config *config, 57extern struct dvb_frontend *drxk_attach(const struct drxk_config *config,
58 struct i2c_adapter *i2c); 58 struct i2c_adapter *i2c);
59#else 59#else
diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c
index c2fc7da0d6bf..ec24d71e153d 100644
--- a/drivers/media/dvb-frontends/drxk_hard.c
+++ b/drivers/media/dvb-frontends/drxk_hard.c
@@ -1947,8 +1947,7 @@ static int ShutDown(struct drxk_state *state)
1947 return 0; 1947 return 0;
1948} 1948}
1949 1949
1950static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus, 1950static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus)
1951 u32 Time)
1952{ 1951{
1953 int status = -EINVAL; 1952 int status = -EINVAL;
1954 1953
@@ -2490,32 +2489,6 @@ error:
2490 return status; 2489 return status;
2491} 2490}
2492 2491
2493static int ReadIFAgc(struct drxk_state *state, u32 *pValue)
2494{
2495 u16 agcDacLvl;
2496 int status;
2497 u16 Level = 0;
2498
2499 dprintk(1, "\n");
2500
2501 status = read16(state, IQM_AF_AGC_IF__A, &agcDacLvl);
2502 if (status < 0) {
2503 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
2504 return status;
2505 }
2506
2507 *pValue = 0;
2508
2509 if (agcDacLvl > DRXK_AGC_DAC_OFFSET)
2510 Level = agcDacLvl - DRXK_AGC_DAC_OFFSET;
2511 if (Level < 14000)
2512 *pValue = (14000 - Level) / 4;
2513 else
2514 *pValue = 0;
2515
2516 return status;
2517}
2518
2519static int GetQAMSignalToNoise(struct drxk_state *state, 2492static int GetQAMSignalToNoise(struct drxk_state *state,
2520 s32 *pSignalToNoise) 2493 s32 *pSignalToNoise)
2521{ 2494{
@@ -2654,12 +2627,7 @@ static int GetDVBTSignalToNoise(struct drxk_state *state,
2654 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ 2627 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */
2655 c = Log10Times100(SqrErrIQ); 2628 c = Log10Times100(SqrErrIQ);
2656 2629
2657 iMER = a + b; 2630 iMER = a + b - c;
2658 /* No negative MER, clip to zero */
2659 if (iMER > c)
2660 iMER -= c;
2661 else
2662 iMER = 0;
2663 } 2631 }
2664 *pSignalToNoise = iMER; 2632 *pSignalToNoise = iMER;
2665 2633
@@ -6380,46 +6348,257 @@ static int drxk_set_parameters(struct dvb_frontend *fe)
6380 fe->ops.tuner_ops.get_if_frequency(fe, &IF); 6348 fe->ops.tuner_ops.get_if_frequency(fe, &IF);
6381 Start(state, 0, IF); 6349 Start(state, 0, IF);
6382 6350
6351 /* After set_frontend, stats aren't avaliable */
6352 p->strength.stat[0].scale = FE_SCALE_RELATIVE;
6353 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6354 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6355 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6356 p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6357 p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6358 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6359 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6360
6383 /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */ 6361 /* printk(KERN_DEBUG "drxk: %s IF=%d done\n", __func__, IF); */
6384 6362
6385 return 0; 6363 return 0;
6386} 6364}
6387 6365
6388static int drxk_read_status(struct dvb_frontend *fe, fe_status_t *status) 6366static int get_strength(struct drxk_state *state, u64 *strength)
6389{ 6367{
6368 int status;
6369 struct SCfgAgc rfAgc, ifAgc;
6370 u32 totalGain = 0;
6371 u32 atten = 0;
6372 u32 agcRange = 0;
6373 u16 scu_lvl = 0;
6374 u16 scu_coc = 0;
6375 /* FIXME: those are part of the tuner presets */
6376 u16 tunerRfGain = 50; /* Default value on az6007 driver */
6377 u16 tunerIfGain = 40; /* Default value on az6007 driver */
6378
6379 *strength = 0;
6380
6381 if (IsDVBT(state)) {
6382 rfAgc = state->m_dvbtRfAgcCfg;
6383 ifAgc = state->m_dvbtIfAgcCfg;
6384 } else if (IsQAM(state)) {
6385 rfAgc = state->m_qamRfAgcCfg;
6386 ifAgc = state->m_qamIfAgcCfg;
6387 } else {
6388 rfAgc = state->m_atvRfAgcCfg;
6389 ifAgc = state->m_atvIfAgcCfg;
6390 }
6391
6392 if (rfAgc.ctrlMode == DRXK_AGC_CTRL_AUTO) {
6393 /* SCU outputLevel */
6394 status = read16(state, SCU_RAM_AGC_RF_IACCU_HI__A, &scu_lvl);
6395 if (status < 0)
6396 return status;
6397
6398 /* SCU c.o.c. */
6399 read16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, &scu_coc);
6400 if (status < 0)
6401 return status;
6402
6403 if (((u32) scu_lvl + (u32) scu_coc) < 0xffff)
6404 rfAgc.outputLevel = scu_lvl + scu_coc;
6405 else
6406 rfAgc.outputLevel = 0xffff;
6407
6408 /* Take RF gain into account */
6409 totalGain += tunerRfGain;
6410
6411 /* clip output value */
6412 if (rfAgc.outputLevel < rfAgc.minOutputLevel)
6413 rfAgc.outputLevel = rfAgc.minOutputLevel;
6414 if (rfAgc.outputLevel > rfAgc.maxOutputLevel)
6415 rfAgc.outputLevel = rfAgc.maxOutputLevel;
6416
6417 agcRange = (u32) (rfAgc.maxOutputLevel - rfAgc.minOutputLevel);
6418 if (agcRange > 0) {
6419 atten += 100UL *
6420 ((u32)(tunerRfGain)) *
6421 ((u32)(rfAgc.outputLevel - rfAgc.minOutputLevel))
6422 / agcRange;
6423 }
6424 }
6425
6426 if (ifAgc.ctrlMode == DRXK_AGC_CTRL_AUTO) {
6427 status = read16(state, SCU_RAM_AGC_IF_IACCU_HI__A,
6428 &ifAgc.outputLevel);
6429 if (status < 0)
6430 return status;
6431
6432 status = read16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A,
6433 &ifAgc.top);
6434 if (status < 0)
6435 return status;
6436
6437 /* Take IF gain into account */
6438 totalGain += (u32) tunerIfGain;
6439
6440 /* clip output value */
6441 if (ifAgc.outputLevel < ifAgc.minOutputLevel)
6442 ifAgc.outputLevel = ifAgc.minOutputLevel;
6443 if (ifAgc.outputLevel > ifAgc.maxOutputLevel)
6444 ifAgc.outputLevel = ifAgc.maxOutputLevel;
6445
6446 agcRange = (u32) (ifAgc.maxOutputLevel - ifAgc.minOutputLevel);
6447 if (agcRange > 0) {
6448 atten += 100UL *
6449 ((u32)(tunerIfGain)) *
6450 ((u32)(ifAgc.outputLevel - ifAgc.minOutputLevel))
6451 / agcRange;
6452 }
6453 }
6454
6455 /*
6456 * Convert to 0..65535 scale.
6457 * If it can't be measured (AGC is disabled), just show 100%.
6458 */
6459 if (totalGain > 0)
6460 *strength = (65535UL * atten / totalGain / 100);
6461 else
6462 *strength = 65535;
6463
6464 return 0;
6465}
6466
6467static int drxk_get_stats(struct dvb_frontend *fe)
6468{
6469 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
6390 struct drxk_state *state = fe->demodulator_priv; 6470 struct drxk_state *state = fe->demodulator_priv;
6471 int status;
6391 u32 stat; 6472 u32 stat;
6392 6473 u16 reg16;
6393 dprintk(1, "\n"); 6474 u32 post_bit_count;
6475 u32 post_bit_err_count;
6476 u32 post_bit_error_scale;
6477 u32 pre_bit_err_count;
6478 u32 pre_bit_count;
6479 u32 pkt_count;
6480 u32 pkt_error_count;
6481 s32 cnr;
6394 6482
6395 if (state->m_DrxkState == DRXK_NO_DEV) 6483 if (state->m_DrxkState == DRXK_NO_DEV)
6396 return -ENODEV; 6484 return -ENODEV;
6397 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6485 if (state->m_DrxkState == DRXK_UNINITIALIZED)
6398 return -EAGAIN; 6486 return -EAGAIN;
6399 6487
6400 *status = 0; 6488 /* get status */
6401 GetLockStatus(state, &stat, 0); 6489 state->fe_status = 0;
6490 GetLockStatus(state, &stat);
6402 if (stat == MPEG_LOCK) 6491 if (stat == MPEG_LOCK)
6403 *status |= 0x1f; 6492 state->fe_status |= 0x1f;
6404 if (stat == FEC_LOCK) 6493 if (stat == FEC_LOCK)
6405 *status |= 0x0f; 6494 state->fe_status |= 0x0f;
6406 if (stat == DEMOD_LOCK) 6495 if (stat == DEMOD_LOCK)
6407 *status |= 0x07; 6496 state->fe_status |= 0x07;
6408 return 0; 6497
6498 /*
6499 * Estimate signal strength from AGC
6500 */
6501 get_strength(state, &c->strength.stat[0].uvalue);
6502 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
6503
6504
6505 if (stat >= DEMOD_LOCK) {
6506 GetSignalToNoise(state, &cnr);
6507 c->cnr.stat[0].svalue = cnr * 100;
6508 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
6509 } else {
6510 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6511 }
6512
6513 if (stat < FEC_LOCK) {
6514 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6515 c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6516 c->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6517 c->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6518 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6519 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6520 return 0;
6521 }
6522
6523 /* Get post BER */
6524
6525 /* BER measurement is valid if at least FEC lock is achieved */
6526
6527 /* OFDM_EC_VD_REQ_SMB_CNT__A and/or OFDM_EC_VD_REQ_BIT_CNT can be written
6528 to set nr of symbols or bits over which
6529 to measure EC_VD_REG_ERR_BIT_CNT__A . See CtrlSetCfg(). */
6530
6531 /* Read registers for post/preViterbi BER calculation */
6532 status = read16(state, OFDM_EC_VD_ERR_BIT_CNT__A, &reg16);
6533 if (status < 0)
6534 goto error;
6535 pre_bit_err_count = reg16;
6536
6537 status = read16(state, OFDM_EC_VD_IN_BIT_CNT__A , &reg16);
6538 if (status < 0)
6539 goto error;
6540 pre_bit_count = reg16;
6541
6542 /* Number of bit-errors */
6543 status = read16(state, FEC_RS_NR_BIT_ERRORS__A, &reg16);
6544 if (status < 0)
6545 goto error;
6546 post_bit_err_count = reg16;
6547
6548 status = read16(state, FEC_RS_MEASUREMENT_PRESCALE__A, &reg16);
6549 if (status < 0)
6550 goto error;
6551 post_bit_error_scale = reg16;
6552
6553 status = read16(state, FEC_RS_MEASUREMENT_PERIOD__A, &reg16);
6554 if (status < 0)
6555 goto error;
6556 pkt_count = reg16;
6557
6558 status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, &reg16);
6559 if (status < 0)
6560 goto error;
6561 pkt_error_count = reg16;
6562 write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0);
6563
6564 post_bit_err_count *= post_bit_error_scale;
6565
6566 post_bit_count = pkt_count * 204 * 8;
6567
6568 /* Store the results */
6569 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
6570 c->block_error.stat[0].uvalue += pkt_error_count;
6571 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
6572 c->block_count.stat[0].uvalue += pkt_count;
6573
6574 c->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER;
6575 c->pre_bit_error.stat[0].uvalue += pre_bit_err_count;
6576 c->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER;
6577 c->pre_bit_count.stat[0].uvalue += pre_bit_count;
6578
6579 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
6580 c->post_bit_error.stat[0].uvalue += post_bit_err_count;
6581 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
6582 c->post_bit_count.stat[0].uvalue += post_bit_count;
6583
6584error:
6585 return status;
6409} 6586}
6410 6587
6411static int drxk_read_ber(struct dvb_frontend *fe, u32 *ber) 6588
6589static int drxk_read_status(struct dvb_frontend *fe, fe_status_t *status)
6412{ 6590{
6413 struct drxk_state *state = fe->demodulator_priv; 6591 struct drxk_state *state = fe->demodulator_priv;
6592 int rc;
6414 6593
6415 dprintk(1, "\n"); 6594 dprintk(1, "\n");
6416 6595
6417 if (state->m_DrxkState == DRXK_NO_DEV) 6596 rc = drxk_get_stats(fe);
6418 return -ENODEV; 6597 if (rc < 0)
6419 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6598 return rc;
6420 return -EAGAIN; 6599
6600 *status = state->fe_status;
6421 6601
6422 *ber = 0;
6423 return 0; 6602 return 0;
6424} 6603}
6425 6604
@@ -6427,7 +6606,7 @@ static int drxk_read_signal_strength(struct dvb_frontend *fe,
6427 u16 *strength) 6606 u16 *strength)
6428{ 6607{
6429 struct drxk_state *state = fe->demodulator_priv; 6608 struct drxk_state *state = fe->demodulator_priv;
6430 u32 val = 0; 6609 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
6431 6610
6432 dprintk(1, "\n"); 6611 dprintk(1, "\n");
6433 6612
@@ -6436,8 +6615,7 @@ static int drxk_read_signal_strength(struct dvb_frontend *fe,
6436 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6615 if (state->m_DrxkState == DRXK_UNINITIALIZED)
6437 return -EAGAIN; 6616 return -EAGAIN;
6438 6617
6439 ReadIFAgc(state, &val); 6618 *strength = c->strength.stat[0].uvalue;
6440 *strength = val & 0xffff;
6441 return 0; 6619 return 0;
6442} 6620}
6443 6621
@@ -6454,6 +6632,10 @@ static int drxk_read_snr(struct dvb_frontend *fe, u16 *snr)
6454 return -EAGAIN; 6632 return -EAGAIN;
6455 6633
6456 GetSignalToNoise(state, &snr2); 6634 GetSignalToNoise(state, &snr2);
6635
6636 /* No negative SNR, clip to zero */
6637 if (snr2 < 0)
6638 snr2 = 0;
6457 *snr = snr2 & 0xffff; 6639 *snr = snr2 & 0xffff;
6458 return 0; 6640 return 0;
6459} 6641}
@@ -6529,7 +6711,6 @@ static struct dvb_frontend_ops drxk_ops = {
6529 .get_tune_settings = drxk_get_tune_settings, 6711 .get_tune_settings = drxk_get_tune_settings,
6530 6712
6531 .read_status = drxk_read_status, 6713 .read_status = drxk_read_status,
6532 .read_ber = drxk_read_ber,
6533 .read_signal_strength = drxk_read_signal_strength, 6714 .read_signal_strength = drxk_read_signal_strength,
6534 .read_snr = drxk_read_snr, 6715 .read_snr = drxk_read_snr,
6535 .read_ucblocks = drxk_read_ucblocks, 6716 .read_ucblocks = drxk_read_ucblocks,
@@ -6538,6 +6719,7 @@ static struct dvb_frontend_ops drxk_ops = {
6538struct dvb_frontend *drxk_attach(const struct drxk_config *config, 6719struct dvb_frontend *drxk_attach(const struct drxk_config *config,
6539 struct i2c_adapter *i2c) 6720 struct i2c_adapter *i2c)
6540{ 6721{
6722 struct dtv_frontend_properties *p;
6541 struct drxk_state *state = NULL; 6723 struct drxk_state *state = NULL;
6542 u8 adr = config->adr; 6724 u8 adr = config->adr;
6543 int status; 6725 int status;
@@ -6618,6 +6800,27 @@ struct dvb_frontend *drxk_attach(const struct drxk_config *config,
6618 } else if (init_drxk(state) < 0) 6800 } else if (init_drxk(state) < 0)
6619 goto error; 6801 goto error;
6620 6802
6803
6804 /* Initialize stats */
6805 p = &state->frontend.dtv_property_cache;
6806 p->strength.len = 1;
6807 p->cnr.len = 1;
6808 p->block_error.len = 1;
6809 p->block_count.len = 1;
6810 p->pre_bit_error.len = 1;
6811 p->pre_bit_count.len = 1;
6812 p->post_bit_error.len = 1;
6813 p->post_bit_count.len = 1;
6814
6815 p->strength.stat[0].scale = FE_SCALE_RELATIVE;
6816 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6817 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6818 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6819 p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6820 p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6821 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6822 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6823
6621 printk(KERN_INFO "drxk: frontend initialized.\n"); 6824 printk(KERN_INFO "drxk: frontend initialized.\n");
6622 return &state->frontend; 6825 return &state->frontend;
6623 6826
diff --git a/drivers/media/dvb-frontends/drxk_hard.h b/drivers/media/dvb-frontends/drxk_hard.h
index d18a896a9835..b8424f15f9a6 100644
--- a/drivers/media/dvb-frontends/drxk_hard.h
+++ b/drivers/media/dvb-frontends/drxk_hard.h
@@ -345,6 +345,8 @@ struct drxk_state {
345 bool antenna_dvbt; 345 bool antenna_dvbt;
346 u16 antenna_gpio; 346 u16 antenna_gpio;
347 347
348 fe_status_t fe_status;
349
348 /* Firmware */ 350 /* Firmware */
349 const char *microcode_name; 351 const char *microcode_name;
350 struct completion fw_wait_load; 352 struct completion fw_wait_load;
diff --git a/drivers/media/dvb-frontends/drxk_map.h b/drivers/media/dvb-frontends/drxk_map.h
index 23e16c12f234..761613f9fd5a 100644
--- a/drivers/media/dvb-frontends/drxk_map.h
+++ b/drivers/media/dvb-frontends/drxk_map.h
@@ -10,6 +10,7 @@
10#define FEC_RS_COMM_EXEC_STOP 0x0 10#define FEC_RS_COMM_EXEC_STOP 0x0
11#define FEC_RS_MEASUREMENT_PERIOD__A 0x1C30012 11#define FEC_RS_MEASUREMENT_PERIOD__A 0x1C30012
12#define FEC_RS_MEASUREMENT_PRESCALE__A 0x1C30013 12#define FEC_RS_MEASUREMENT_PRESCALE__A 0x1C30013
13#define FEC_RS_NR_BIT_ERRORS__A 0x1C30014
13#define FEC_OC_MODE__A 0x1C40011 14#define FEC_OC_MODE__A 0x1C40011
14#define FEC_OC_MODE_PARITY__M 0x1 15#define FEC_OC_MODE_PARITY__M 0x1
15#define FEC_OC_DTO_MODE__A 0x1C40014 16#define FEC_OC_DTO_MODE__A 0x1C40014
@@ -129,6 +130,8 @@
129#define OFDM_EC_SB_PRIOR__A 0x3410013 130#define OFDM_EC_SB_PRIOR__A 0x3410013
130#define OFDM_EC_SB_PRIOR_HI 0x0 131#define OFDM_EC_SB_PRIOR_HI 0x0
131#define OFDM_EC_SB_PRIOR_LO 0x1 132#define OFDM_EC_SB_PRIOR_LO 0x1
133#define OFDM_EC_VD_ERR_BIT_CNT__A 0x3420017
134#define OFDM_EC_VD_IN_BIT_CNT__A 0x3420018
132#define OFDM_EQ_TOP_TD_TPS_CONST__A 0x3010054 135#define OFDM_EQ_TOP_TD_TPS_CONST__A 0x3010054
133#define OFDM_EQ_TOP_TD_TPS_CONST__M 0x3 136#define OFDM_EQ_TOP_TD_TPS_CONST__M 0x3
134#define OFDM_EQ_TOP_TD_TPS_CONST_64QAM 0x2 137#define OFDM_EQ_TOP_TD_TPS_CONST_64QAM 0x2
diff --git a/drivers/media/dvb-frontends/ds3000.h b/drivers/media/dvb-frontends/ds3000.h
index 478ad66c63d7..f9c21fb7af13 100644
--- a/drivers/media/dvb-frontends/ds3000.h
+++ b/drivers/media/dvb-frontends/ds3000.h
@@ -22,6 +22,7 @@
22#ifndef DS3000_H 22#ifndef DS3000_H
23#define DS3000_H 23#define DS3000_H
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27struct ds3000_config { 28struct ds3000_config {
@@ -34,8 +35,7 @@ struct ds3000_config {
34 void (*set_lock_led)(struct dvb_frontend *fe, int offon); 35 void (*set_lock_led)(struct dvb_frontend *fe, int offon);
35}; 36};
36 37
37#if defined(CONFIG_DVB_DS3000) || \ 38#if IS_ENABLED(CONFIG_DVB_DS3000)
38 (defined(CONFIG_DVB_DS3000_MODULE) && defined(MODULE))
39extern struct dvb_frontend *ds3000_attach(const struct ds3000_config *config, 39extern struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
40 struct i2c_adapter *i2c); 40 struct i2c_adapter *i2c);
41#else 41#else
diff --git a/drivers/media/dvb-frontends/dvb_dummy_fe.h b/drivers/media/dvb-frontends/dvb_dummy_fe.h
index 1fcb987d6386..0cbf96105631 100644
--- a/drivers/media/dvb-frontends/dvb_dummy_fe.h
+++ b/drivers/media/dvb-frontends/dvb_dummy_fe.h
@@ -22,11 +22,11 @@
22#ifndef DVB_DUMMY_FE_H 22#ifndef DVB_DUMMY_FE_H
23#define DVB_DUMMY_FE_H 23#define DVB_DUMMY_FE_H
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26#include "dvb_frontend.h" 27#include "dvb_frontend.h"
27 28
28#if defined(CONFIG_DVB_DUMMY_FE) || (defined(CONFIG_DVB_DUMMY_FE_MODULE) && \ 29#if IS_ENABLED(CONFIG_DVB_DUMMY_FE)
29defined(MODULE))
30extern struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void); 30extern struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void);
31extern struct dvb_frontend* dvb_dummy_fe_qpsk_attach(void); 31extern struct dvb_frontend* dvb_dummy_fe_qpsk_attach(void);
32extern struct dvb_frontend* dvb_dummy_fe_qam_attach(void); 32extern struct dvb_frontend* dvb_dummy_fe_qam_attach(void);
diff --git a/drivers/media/dvb-frontends/ec100.h b/drivers/media/dvb-frontends/ec100.h
index b8479719d7f1..37558403068d 100644
--- a/drivers/media/dvb-frontends/ec100.h
+++ b/drivers/media/dvb-frontends/ec100.h
@@ -22,6 +22,7 @@
22#ifndef EC100_H 22#ifndef EC100_H
23#define EC100_H 23#define EC100_H
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27struct ec100_config { 28struct ec100_config {
@@ -30,8 +31,7 @@ struct ec100_config {
30}; 31};
31 32
32 33
33#if defined(CONFIG_DVB_EC100) || \ 34#if IS_ENABLED(CONFIG_DVB_EC100)
34 (defined(CONFIG_DVB_EC100_MODULE) && defined(MODULE))
35extern struct dvb_frontend *ec100_attach(const struct ec100_config *config, 35extern struct dvb_frontend *ec100_attach(const struct ec100_config *config,
36 struct i2c_adapter *i2c); 36 struct i2c_adapter *i2c);
37#else 37#else
diff --git a/drivers/media/dvb-frontends/hd29l2.h b/drivers/media/dvb-frontends/hd29l2.h
index 4ad00d79aa77..05cd13028a91 100644
--- a/drivers/media/dvb-frontends/hd29l2.h
+++ b/drivers/media/dvb-frontends/hd29l2.h
@@ -23,6 +23,7 @@
23#ifndef HD29L2_H 23#ifndef HD29L2_H
24#define HD29L2_H 24#define HD29L2_H
25 25
26#include <linux/kconfig.h>
26#include <linux/dvb/frontend.h> 27#include <linux/dvb/frontend.h>
27 28
28struct hd29l2_config { 29struct hd29l2_config {
@@ -50,8 +51,7 @@ struct hd29l2_config {
50}; 51};
51 52
52 53
53#if defined(CONFIG_DVB_HD29L2) || \ 54#if IS_ENABLED(CONFIG_DVB_HD29L2)
54 (defined(CONFIG_DVB_HD29L2_MODULE) && defined(MODULE))
55extern struct dvb_frontend *hd29l2_attach(const struct hd29l2_config *config, 55extern struct dvb_frontend *hd29l2_attach(const struct hd29l2_config *config,
56 struct i2c_adapter *i2c); 56 struct i2c_adapter *i2c);
57#else 57#else
diff --git a/drivers/media/dvb-frontends/isl6421.c b/drivers/media/dvb-frontends/isl6421.c
index 0cb3f0f74c9c..c77002fcc8e2 100644
--- a/drivers/media/dvb-frontends/isl6421.c
+++ b/drivers/media/dvb-frontends/isl6421.c
@@ -89,6 +89,30 @@ static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
89 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO; 89 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
90} 90}
91 91
92static int isl6421_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
93{
94 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
95 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
96 .buf = &isl6421->config,
97 .len = sizeof(isl6421->config) };
98
99 switch (tone) {
100 case SEC_TONE_ON:
101 isl6421->config |= ISL6421_ENT1;
102 break;
103 case SEC_TONE_OFF:
104 isl6421->config &= ~ISL6421_ENT1;
105 break;
106 default:
107 return -EINVAL;
108 }
109
110 isl6421->config |= isl6421->override_or;
111 isl6421->config &= isl6421->override_and;
112
113 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
114}
115
92static void isl6421_release(struct dvb_frontend *fe) 116static void isl6421_release(struct dvb_frontend *fe)
93{ 117{
94 /* power off */ 118 /* power off */
@@ -100,7 +124,7 @@ static void isl6421_release(struct dvb_frontend *fe)
100} 124}
101 125
102struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr, 126struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
103 u8 override_set, u8 override_clear) 127 u8 override_set, u8 override_clear, bool override_tone)
104{ 128{
105 struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL); 129 struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL);
106 if (!isl6421) 130 if (!isl6421)
@@ -131,6 +155,8 @@ struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter
131 /* override frontend ops */ 155 /* override frontend ops */
132 fe->ops.set_voltage = isl6421_set_voltage; 156 fe->ops.set_voltage = isl6421_set_voltage;
133 fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage; 157 fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage;
158 if (override_tone)
159 fe->ops.set_tone = isl6421_set_tone;
134 160
135 return fe; 161 return fe;
136} 162}
diff --git a/drivers/media/dvb-frontends/isl6421.h b/drivers/media/dvb-frontends/isl6421.h
index e7ca7d12b50a..630e7f8a150e 100644
--- a/drivers/media/dvb-frontends/isl6421.h
+++ b/drivers/media/dvb-frontends/isl6421.h
@@ -42,10 +42,10 @@
42#if IS_ENABLED(CONFIG_DVB_ISL6421) 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, bool override_tone);
46#else 46#else
47static inline struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr, 47static inline struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
48 u8 override_set, u8 override_clear) 48 u8 override_set, u8 override_clear, bool override_tone)
49{ 49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL; 51 return NULL;
diff --git a/drivers/media/dvb-frontends/it913x-fe.h b/drivers/media/dvb-frontends/it913x-fe.h
index 07fa4594c12b..df0ad4207343 100644
--- a/drivers/media/dvb-frontends/it913x-fe.h
+++ b/drivers/media/dvb-frontends/it913x-fe.h
@@ -21,6 +21,7 @@
21#ifndef IT913X_FE_H 21#ifndef IT913X_FE_H
22#define IT913X_FE_H 22#define IT913X_FE_H
23 23
24#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
25#include "dvb_frontend.h" 26#include "dvb_frontend.h"
26 27
@@ -38,8 +39,7 @@ struct ite_config {
38 u8 read_slevel; 39 u8 read_slevel;
39}; 40};
40 41
41#if defined(CONFIG_DVB_IT913X_FE) || (defined(CONFIG_DVB_IT913X_FE_MODULE) && \ 42#if IS_ENABLED(CONFIG_DVB_IT913X_FE)
42defined(MODULE))
43extern struct dvb_frontend *it913x_fe_attach(struct i2c_adapter *i2c_adap, 43extern struct dvb_frontend *it913x_fe_attach(struct i2c_adapter *i2c_adap,
44 u8 i2c_addr, struct ite_config *config); 44 u8 i2c_addr, struct ite_config *config);
45#else 45#else
diff --git a/drivers/media/dvb-frontends/ix2505v.h b/drivers/media/dvb-frontends/ix2505v.h
index 67e89d616d50..1a735a75aa98 100644
--- a/drivers/media/dvb-frontends/ix2505v.h
+++ b/drivers/media/dvb-frontends/ix2505v.h
@@ -20,6 +20,7 @@
20#ifndef DVB_IX2505V_H 20#ifndef DVB_IX2505V_H
21#define DVB_IX2505V_H 21#define DVB_IX2505V_H
22 22
23#include <linux/kconfig.h>
23#include <linux/i2c.h> 24#include <linux/i2c.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
@@ -48,8 +49,7 @@ struct ix2505v_config {
48 49
49}; 50};
50 51
51#if defined(CONFIG_DVB_IX2505V) || \ 52#if IS_ENABLED(CONFIG_DVB_IX2505V)
52 (defined(CONFIG_DVB_IX2505V_MODULE) && defined(MODULE))
53extern struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe, 53extern struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe,
54 const struct ix2505v_config *config, struct i2c_adapter *i2c); 54 const struct ix2505v_config *config, struct i2c_adapter *i2c);
55#else 55#else
diff --git a/drivers/media/dvb-frontends/lg2160.h b/drivers/media/dvb-frontends/lg2160.h
index 9e2c0f41199a..194a07a78dc1 100644
--- a/drivers/media/dvb-frontends/lg2160.h
+++ b/drivers/media/dvb-frontends/lg2160.h
@@ -22,6 +22,7 @@
22#ifndef _LG2160_H_ 22#ifndef _LG2160_H_
23#define _LG2160_H_ 23#define _LG2160_H_
24 24
25#include <linux/kconfig.h>
25#include <linux/i2c.h> 26#include <linux/i2c.h>
26#include "dvb_frontend.h" 27#include "dvb_frontend.h"
27 28
@@ -56,18 +57,17 @@ struct lg2160_config {
56 u16 if_khz; 57 u16 if_khz;
57 58
58 /* disable i2c repeater - 0:repeater enabled 1:repeater disabled */ 59 /* disable i2c repeater - 0:repeater enabled 1:repeater disabled */
59 int deny_i2c_rptr:1; 60 unsigned int deny_i2c_rptr:1;
60 61
61 /* spectral inversion - 0:disabled 1:enabled */ 62 /* spectral inversion - 0:disabled 1:enabled */
62 int spectral_inversion:1; 63 unsigned int spectral_inversion:1;
63 64
64 unsigned int output_if; 65 unsigned int output_if;
65 enum lg2160_spi_clock spi_clock; 66 enum lg2160_spi_clock spi_clock;
66 enum lg_chip_type lg_chip; 67 enum lg_chip_type lg_chip;
67}; 68};
68 69
69#if defined(CONFIG_DVB_LG2160) || (defined(CONFIG_DVB_LG2160_MODULE) && \ 70#if IS_ENABLED(CONFIG_DVB_LG2160)
70 defined(MODULE))
71extern 71extern
72struct dvb_frontend *lg2160_attach(const struct lg2160_config *config, 72struct dvb_frontend *lg2160_attach(const struct lg2160_config *config,
73 struct i2c_adapter *i2c_adap); 73 struct i2c_adapter *i2c_adap);
diff --git a/drivers/media/dvb-frontends/lgdt3305.h b/drivers/media/dvb-frontends/lgdt3305.h
index 02172eca4d47..d9ab556c1b27 100644
--- a/drivers/media/dvb-frontends/lgdt3305.h
+++ b/drivers/media/dvb-frontends/lgdt3305.h
@@ -22,6 +22,7 @@
22#ifndef _LGDT3305_H_ 22#ifndef _LGDT3305_H_
23#define _LGDT3305_H_ 23#define _LGDT3305_H_
24 24
25#include <linux/kconfig.h>
25#include <linux/i2c.h> 26#include <linux/i2c.h>
26#include "dvb_frontend.h" 27#include "dvb_frontend.h"
27 28
@@ -73,8 +74,7 @@ struct lgdt3305_config {
73 enum lgdt_demod_chip_type demod_chip; 74 enum lgdt_demod_chip_type demod_chip;
74}; 75};
75 76
76#if defined(CONFIG_DVB_LGDT3305) || (defined(CONFIG_DVB_LGDT3305_MODULE) && \ 77#if IS_ENABLED(CONFIG_DVB_LGDT3305)
77 defined(MODULE))
78extern 78extern
79struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, 79struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
80 struct i2c_adapter *i2c_adap); 80 struct i2c_adapter *i2c_adap);
diff --git a/drivers/media/dvb-frontends/lgs8gl5.h b/drivers/media/dvb-frontends/lgs8gl5.h
index d14176787a7d..c2da59614727 100644
--- a/drivers/media/dvb-frontends/lgs8gl5.h
+++ b/drivers/media/dvb-frontends/lgs8gl5.h
@@ -23,6 +23,7 @@
23#ifndef LGS8GL5_H 23#ifndef LGS8GL5_H
24#define LGS8GL5_H 24#define LGS8GL5_H
25 25
26#include <linux/kconfig.h>
26#include <linux/dvb/frontend.h> 27#include <linux/dvb/frontend.h>
27 28
28struct lgs8gl5_config { 29struct lgs8gl5_config {
@@ -30,8 +31,7 @@ struct lgs8gl5_config {
30 u8 demod_address; 31 u8 demod_address;
31}; 32};
32 33
33#if defined(CONFIG_DVB_LGS8GL5) || \ 34#if IS_ENABLED(CONFIG_DVB_LGS8GL5)
34 (defined(CONFIG_DVB_LGS8GL5_MODULE) && defined(MODULE))
35extern struct dvb_frontend *lgs8gl5_attach( 35extern struct dvb_frontend *lgs8gl5_attach(
36 const struct lgs8gl5_config *config, struct i2c_adapter *i2c); 36 const struct lgs8gl5_config *config, struct i2c_adapter *i2c);
37#else 37#else
diff --git a/drivers/media/dvb-frontends/lgs8gxx.h b/drivers/media/dvb-frontends/lgs8gxx.h
index 33c3c5e162fa..dadb78bf61a9 100644
--- a/drivers/media/dvb-frontends/lgs8gxx.h
+++ b/drivers/media/dvb-frontends/lgs8gxx.h
@@ -26,6 +26,7 @@
26#ifndef __LGS8GXX_H__ 26#ifndef __LGS8GXX_H__
27#define __LGS8GXX_H__ 27#define __LGS8GXX_H__
28 28
29#include <linux/kconfig.h>
29#include <linux/dvb/frontend.h> 30#include <linux/dvb/frontend.h>
30#include <linux/i2c.h> 31#include <linux/i2c.h>
31 32
@@ -79,8 +80,7 @@ struct lgs8gxx_config {
79 u8 tuner_address; 80 u8 tuner_address;
80}; 81};
81 82
82#if defined(CONFIG_DVB_LGS8GXX) || \ 83#if IS_ENABLED(CONFIG_DVB_LGS8GXX)
83 (defined(CONFIG_DVB_LGS8GXX_MODULE) && defined(MODULE))
84extern struct dvb_frontend *lgs8gxx_attach(const struct lgs8gxx_config *config, 84extern struct dvb_frontend *lgs8gxx_attach(const struct lgs8gxx_config *config,
85 struct i2c_adapter *i2c); 85 struct i2c_adapter *i2c);
86#else 86#else
diff --git a/drivers/media/dvb-frontends/lnbh24.h b/drivers/media/dvb-frontends/lnbh24.h
index c059b165318f..b327a4f31d16 100644
--- a/drivers/media/dvb-frontends/lnbh24.h
+++ b/drivers/media/dvb-frontends/lnbh24.h
@@ -23,6 +23,8 @@
23#ifndef _LNBH24_H 23#ifndef _LNBH24_H
24#define _LNBH24_H 24#define _LNBH24_H
25 25
26#include <linux/kconfig.h>
27
26/* system register bits */ 28/* system register bits */
27#define LNBH24_OLF 0x01 29#define LNBH24_OLF 0x01
28#define LNBH24_OTF 0x02 30#define LNBH24_OTF 0x02
@@ -35,8 +37,7 @@
35 37
36#include <linux/dvb/frontend.h> 38#include <linux/dvb/frontend.h>
37 39
38#if defined(CONFIG_DVB_LNBP21) || (defined(CONFIG_DVB_LNBP21_MODULE) \ 40#if IS_ENABLED(CONFIG_DVB_LNBP21)
39 && defined(MODULE))
40/* override_set and override_clear control which 41/* override_set and override_clear control which
41 system register bits (above) to always set & clear */ 42 system register bits (above) to always set & clear */
42extern struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe, 43extern struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe,
diff --git a/drivers/media/dvb-frontends/lnbp21.h b/drivers/media/dvb-frontends/lnbp21.h
index fcdf1c650dde..dbcbcc2f20a3 100644
--- a/drivers/media/dvb-frontends/lnbp21.h
+++ b/drivers/media/dvb-frontends/lnbp21.h
@@ -27,6 +27,8 @@
27#ifndef _LNBP21_H 27#ifndef _LNBP21_H
28#define _LNBP21_H 28#define _LNBP21_H
29 29
30#include <linux/kconfig.h>
31
30/* system register bits */ 32/* system register bits */
31/* [RO] 0=OK; 1=over current limit flag */ 33/* [RO] 0=OK; 1=over current limit flag */
32#define LNBP21_OLF 0x01 34#define LNBP21_OLF 0x01
@@ -55,8 +57,7 @@
55 57
56#include <linux/dvb/frontend.h> 58#include <linux/dvb/frontend.h>
57 59
58#if defined(CONFIG_DVB_LNBP21) || (defined(CONFIG_DVB_LNBP21_MODULE) \ 60#if IS_ENABLED(CONFIG_DVB_LNBP21)
59 && defined(MODULE))
60/* override_set and override_clear control which 61/* override_set and override_clear control which
61 system register bits (above) to always set & clear */ 62 system register bits (above) to always set & clear */
62extern struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, 63extern struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe,
diff --git a/drivers/media/dvb-frontends/lnbp22.h b/drivers/media/dvb-frontends/lnbp22.h
index 63e2dec7e68a..63861b311dd8 100644
--- a/drivers/media/dvb-frontends/lnbp22.h
+++ b/drivers/media/dvb-frontends/lnbp22.h
@@ -28,6 +28,8 @@
28#ifndef _LNBP22_H 28#ifndef _LNBP22_H
29#define _LNBP22_H 29#define _LNBP22_H
30 30
31#include <linux/kconfig.h>
32
31/* Enable */ 33/* Enable */
32#define LNBP22_EN 0x10 34#define LNBP22_EN 0x10
33/* Voltage selection */ 35/* Voltage selection */
@@ -37,8 +39,7 @@
37 39
38#include <linux/dvb/frontend.h> 40#include <linux/dvb/frontend.h>
39 41
40#if defined(CONFIG_DVB_LNBP22) || \ 42#if IS_ENABLED(CONFIG_DVB_LNBP22)
41 (defined(CONFIG_DVB_LNBP22_MODULE) && defined(MODULE))
42/* 43/*
43 * override_set and override_clear control which system register bits (above) 44 * override_set and override_clear control which system register bits (above)
44 * to always set & clear 45 * to always set & clear
diff --git a/drivers/media/dvb-frontends/m88rs2000.h b/drivers/media/dvb-frontends/m88rs2000.h
index 5a8023e5a4b8..14ce31e76ae6 100644
--- a/drivers/media/dvb-frontends/m88rs2000.h
+++ b/drivers/media/dvb-frontends/m88rs2000.h
@@ -20,6 +20,7 @@
20#ifndef M88RS2000_H 20#ifndef M88RS2000_H
21#define M88RS2000_H 21#define M88RS2000_H
22 22
23#include <linux/kconfig.h>
23#include <linux/dvb/frontend.h> 24#include <linux/dvb/frontend.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
@@ -40,8 +41,7 @@ enum {
40 CALL_IS_READ, 41 CALL_IS_READ,
41}; 42};
42 43
43#if defined(CONFIG_DVB_M88RS2000) || (defined(CONFIG_DVB_M88RS2000_MODULE) && \ 44#if IS_ENABLED(CONFIG_DVB_M88RS2000)
44 defined(MODULE))
45extern struct dvb_frontend *m88rs2000_attach( 45extern struct dvb_frontend *m88rs2000_attach(
46 const struct m88rs2000_config *config, struct i2c_adapter *i2c); 46 const struct m88rs2000_config *config, struct i2c_adapter *i2c);
47#else 47#else
diff --git a/drivers/media/dvb-frontends/mb86a20s.c b/drivers/media/dvb-frontends/mb86a20s.c
index 4faaf8053f26..856374bd3676 100644
--- a/drivers/media/dvb-frontends/mb86a20s.c
+++ b/drivers/media/dvb-frontends/mb86a20s.c
@@ -20,10 +20,24 @@
20#include "dvb_frontend.h" 20#include "dvb_frontend.h"
21#include "mb86a20s.h" 21#include "mb86a20s.h"
22 22
23#define NUM_LAYERS 3
24
23static int debug = 1; 25static int debug = 1;
24module_param(debug, int, 0644); 26module_param(debug, int, 0644);
25MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)"); 27MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
26 28
29enum mb86a20s_bandwidth {
30 MB86A20S_13SEG = 0,
31 MB86A20S_13SEG_PARTIAL = 1,
32 MB86A20S_1SEG = 2,
33 MB86A20S_3SEG = 3,
34};
35
36u8 mb86a20s_subchannel[] = {
37 0xb0, 0xc0, 0xd0, 0xe0,
38 0xf0, 0x00, 0x10, 0x20,
39};
40
27struct mb86a20s_state { 41struct mb86a20s_state {
28 struct i2c_adapter *i2c; 42 struct i2c_adapter *i2c;
29 const struct mb86a20s_config *config; 43 const struct mb86a20s_config *config;
@@ -31,7 +45,13 @@ struct mb86a20s_state {
31 45
32 struct dvb_frontend frontend; 46 struct dvb_frontend frontend;
33 47
34 u32 estimated_rate[3]; 48 u32 if_freq;
49 enum mb86a20s_bandwidth bw;
50 bool inversion;
51 u32 subchannel;
52
53 u32 estimated_rate[NUM_LAYERS];
54 unsigned long get_strength_time;
35 55
36 bool need_init; 56 bool need_init;
37}; 57};
@@ -47,35 +67,33 @@ struct regdata {
47 * Initialization sequence: Use whatevere default values that PV SBTVD 67 * Initialization sequence: Use whatevere default values that PV SBTVD
48 * does on its initialisation, obtained via USB snoop 68 * does on its initialisation, obtained via USB snoop
49 */ 69 */
50static struct regdata mb86a20s_init[] = { 70static struct regdata mb86a20s_init1[] = {
51 { 0x70, 0x0f }, 71 { 0x70, 0x0f },
52 { 0x70, 0xff }, 72 { 0x70, 0xff },
53 { 0x08, 0x01 }, 73 { 0x08, 0x01 },
54 { 0x09, 0x3e }, 74 { 0x50, 0xd1 }, { 0x51, 0x20 },
55 { 0x50, 0xd1 }, { 0x51, 0x22 }, 75};
56 { 0x39, 0x01 }, 76
57 { 0x71, 0x00 }, 77static struct regdata mb86a20s_init2[] = {
58 { 0x28, 0x2a }, { 0x29, 0x00 }, { 0x2a, 0xff }, { 0x2b, 0x80 },
59 { 0x28, 0x20 }, { 0x29, 0x33 }, { 0x2a, 0xdf }, { 0x2b, 0xa9 },
60 { 0x28, 0x22 }, { 0x29, 0x00 }, { 0x2a, 0x1f }, { 0x2b, 0xf0 }, 78 { 0x28, 0x22 }, { 0x29, 0x00 }, { 0x2a, 0x1f }, { 0x2b, 0xf0 },
61 { 0x3b, 0x21 }, 79 { 0x3b, 0x21 },
62 { 0x3c, 0x3a }, 80 { 0x3c, 0x38 },
63 { 0x01, 0x0d }, 81 { 0x01, 0x0d },
64 { 0x04, 0x08 }, { 0x05, 0x05 }, 82 { 0x04, 0x08 }, { 0x05, 0x03 },
65 { 0x04, 0x0e }, { 0x05, 0x00 }, 83 { 0x04, 0x0e }, { 0x05, 0x00 },
66 { 0x04, 0x0f }, { 0x05, 0x14 }, 84 { 0x04, 0x0f }, { 0x05, 0x37 },
67 { 0x04, 0x0b }, { 0x05, 0x8c }, 85 { 0x04, 0x0b }, { 0x05, 0x78 },
68 { 0x04, 0x00 }, { 0x05, 0x00 }, 86 { 0x04, 0x00 }, { 0x05, 0x00 },
69 { 0x04, 0x01 }, { 0x05, 0x07 }, 87 { 0x04, 0x01 }, { 0x05, 0x1e },
70 { 0x04, 0x02 }, { 0x05, 0x0f }, 88 { 0x04, 0x02 }, { 0x05, 0x07 },
71 { 0x04, 0x03 }, { 0x05, 0xa0 }, 89 { 0x04, 0x03 }, { 0x05, 0xd0 },
72 { 0x04, 0x09 }, { 0x05, 0x00 }, 90 { 0x04, 0x09 }, { 0x05, 0x00 },
73 { 0x04, 0x0a }, { 0x05, 0xff }, 91 { 0x04, 0x0a }, { 0x05, 0xff },
74 { 0x04, 0x27 }, { 0x05, 0x64 }, 92 { 0x04, 0x27 }, { 0x05, 0x00 },
75 { 0x04, 0x28 }, { 0x05, 0x00 }, 93 { 0x04, 0x28 }, { 0x05, 0x00 },
76 { 0x04, 0x1e }, { 0x05, 0xff }, 94 { 0x04, 0x1e }, { 0x05, 0x00 },
77 { 0x04, 0x29 }, { 0x05, 0x0a }, 95 { 0x04, 0x29 }, { 0x05, 0x64 },
78 { 0x04, 0x32 }, { 0x05, 0x0a }, 96 { 0x04, 0x32 }, { 0x05, 0x02 },
79 { 0x04, 0x14 }, { 0x05, 0x02 }, 97 { 0x04, 0x14 }, { 0x05, 0x02 },
80 { 0x04, 0x04 }, { 0x05, 0x00 }, 98 { 0x04, 0x04 }, { 0x05, 0x00 },
81 { 0x04, 0x05 }, { 0x05, 0x22 }, 99 { 0x04, 0x05 }, { 0x05, 0x22 },
@@ -142,39 +160,39 @@ static struct regdata mb86a20s_init[] = {
142 { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */ 160 { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */
143 { 0x50, 0xd6 }, { 0x51, 0x1f }, 161 { 0x50, 0xd6 }, { 0x51, 0x1f },
144 { 0x50, 0xd2 }, { 0x51, 0x03 }, 162 { 0x50, 0xd2 }, { 0x51, 0x03 },
145 { 0x50, 0xd7 }, { 0x51, 0x3f }, 163 { 0x50, 0xd7 }, { 0x51, 0xbf },
146 { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x28, 0x74 }, { 0x29, 0x40 }, 164 { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0xff },
147 { 0x28, 0x46 }, { 0x29, 0x2c }, { 0x28, 0x46 }, { 0x29, 0x0c }, 165 { 0x28, 0x46 }, { 0x29, 0x00 }, { 0x2a, 0x1a }, { 0x2b, 0x0c },
148 166
149 { 0x04, 0x40 }, { 0x05, 0x00 }, 167 { 0x04, 0x40 }, { 0x05, 0x00 },
150 { 0x28, 0x00 }, { 0x29, 0x10 }, 168 { 0x28, 0x00 }, { 0x2b, 0x08 },
151 { 0x28, 0x05 }, { 0x29, 0x02 }, 169 { 0x28, 0x05 }, { 0x2b, 0x00 },
152 { 0x1c, 0x01 }, 170 { 0x1c, 0x01 },
153 { 0x28, 0x06 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x03 }, 171 { 0x28, 0x06 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x1f },
154 { 0x28, 0x07 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0d }, 172 { 0x28, 0x07 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x18 },
155 { 0x28, 0x08 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x02 }, 173 { 0x28, 0x08 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x12 },
156 { 0x28, 0x09 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x01 }, 174 { 0x28, 0x09 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x30 },
157 { 0x28, 0x0a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x21 }, 175 { 0x28, 0x0a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x37 },
158 { 0x28, 0x0b }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x29 }, 176 { 0x28, 0x0b }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x02 },
159 { 0x28, 0x0c }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x16 }, 177 { 0x28, 0x0c }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x09 },
160 { 0x28, 0x0d }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x31 }, 178 { 0x28, 0x0d }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x06 },
161 { 0x28, 0x0e }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0e }, 179 { 0x28, 0x0e }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x7b },
162 { 0x28, 0x0f }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x4e }, 180 { 0x28, 0x0f }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x76 },
163 { 0x28, 0x10 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x46 }, 181 { 0x28, 0x10 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x7d },
164 { 0x28, 0x11 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0f }, 182 { 0x28, 0x11 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x08 },
165 { 0x28, 0x12 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x56 }, 183 { 0x28, 0x12 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0b },
166 { 0x28, 0x13 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x35 }, 184 { 0x28, 0x13 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x00 },
167 { 0x28, 0x14 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xbe }, 185 { 0x28, 0x14 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xf2 },
168 { 0x28, 0x15 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0x84 }, 186 { 0x28, 0x15 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xf3 },
169 { 0x28, 0x16 }, { 0x29, 0x00 }, { 0x2a, 0x03 }, { 0x2b, 0xee }, 187 { 0x28, 0x16 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x05 },
170 { 0x28, 0x17 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x98 }, 188 { 0x28, 0x17 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x16 },
171 { 0x28, 0x18 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x9f }, 189 { 0x28, 0x18 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0f },
172 { 0x28, 0x19 }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0xb2 }, 190 { 0x28, 0x19 }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0xef },
173 { 0x28, 0x1a }, { 0x29, 0x00 }, { 0x2a, 0x06 }, { 0x2b, 0xc2 }, 191 { 0x28, 0x1a }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0xd8 },
174 { 0x28, 0x1b }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0x4a }, 192 { 0x28, 0x1b }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0xf1 },
175 { 0x28, 0x1c }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xbc }, 193 { 0x28, 0x1c }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x3d },
176 { 0x28, 0x1d }, { 0x29, 0x00 }, { 0x2a, 0x04 }, { 0x2b, 0xba }, 194 { 0x28, 0x1d }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x94 },
177 { 0x28, 0x1e }, { 0x29, 0x00 }, { 0x2a, 0x06 }, { 0x2b, 0x14 }, 195 { 0x28, 0x1e }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0xba },
178 { 0x50, 0x1e }, { 0x51, 0x5d }, 196 { 0x50, 0x1e }, { 0x51, 0x5d },
179 { 0x50, 0x22 }, { 0x51, 0x00 }, 197 { 0x50, 0x22 }, { 0x51, 0x00 },
180 { 0x50, 0x23 }, { 0x51, 0xc8 }, 198 { 0x50, 0x23 }, { 0x51, 0xc8 },
@@ -183,6 +201,8 @@ static struct regdata mb86a20s_init[] = {
183 { 0x50, 0x26 }, { 0x51, 0x00 }, 201 { 0x50, 0x26 }, { 0x51, 0x00 },
184 { 0x50, 0x27 }, { 0x51, 0xc3 }, 202 { 0x50, 0x27 }, { 0x51, 0xc3 },
185 { 0x50, 0x39 }, { 0x51, 0x02 }, 203 { 0x50, 0x39 }, { 0x51, 0x02 },
204 { 0xec, 0x0f },
205 { 0xeb, 0x1f },
186 { 0x28, 0x6a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x00 }, 206 { 0x28, 0x6a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x00 },
187 { 0xd0, 0x00 }, 207 { 0xd0, 0x00 },
188}; 208};
@@ -308,15 +328,23 @@ static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)
308 dev_dbg(&state->i2c->dev, "%s: Status = 0x%02x (state = %d)\n", 328 dev_dbg(&state->i2c->dev, "%s: Status = 0x%02x (state = %d)\n",
309 __func__, *status, val); 329 __func__, *status, val);
310 330
311 return 0; 331 return val;
312} 332}
313 333
314static int mb86a20s_read_signal_strength(struct dvb_frontend *fe) 334static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)
315{ 335{
316 struct mb86a20s_state *state = fe->demodulator_priv; 336 struct mb86a20s_state *state = fe->demodulator_priv;
337 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
317 int rc; 338 int rc;
318 unsigned rf_max, rf_min, rf; 339 unsigned rf_max, rf_min, rf;
319 340
341 if (state->get_strength_time &&
342 (!time_after(jiffies, state->get_strength_time)))
343 return c->strength.stat[0].uvalue;
344
345 /* Reset its value if an error happen */
346 c->strength.stat[0].uvalue = 0;
347
320 /* Does a binary search to get RF strength */ 348 /* Does a binary search to get RF strength */
321 rf_max = 0xfff; 349 rf_max = 0xfff;
322 rf_min = 0; 350 rf_min = 0;
@@ -331,7 +359,7 @@ static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)
331 rc = mb86a20s_writereg(state, 0x04, 0x20); 359 rc = mb86a20s_writereg(state, 0x04, 0x20);
332 if (rc < 0) 360 if (rc < 0)
333 return rc; 361 return rc;
334 rc = mb86a20s_writereg(state, 0x04, rf); 362 rc = mb86a20s_writereg(state, 0x05, rf);
335 if (rc < 0) 363 if (rc < 0)
336 return rc; 364 return rc;
337 365
@@ -346,15 +374,19 @@ static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)
346 rf = (rf_max + rf_min) / 2; 374 rf = (rf_max + rf_min) / 2;
347 375
348 /* Rescale it from 2^12 (4096) to 2^16 */ 376 /* Rescale it from 2^12 (4096) to 2^16 */
349 rf <<= (16 - 12); 377 rf = rf << (16 - 12);
378 if (rf)
379 rf |= (1 << 12) - 1;
380
350 dev_dbg(&state->i2c->dev, 381 dev_dbg(&state->i2c->dev,
351 "%s: signal strength = %d (%d < RF=%d < %d)\n", 382 "%s: signal strength = %d (%d < RF=%d < %d)\n",
352 __func__, rf, rf_min, rf >> 4, rf_max); 383 __func__, rf, rf_min, rf >> 4, rf_max);
353 return rf; 384 c->strength.stat[0].uvalue = rf;
385 state->get_strength_time = jiffies +
386 msecs_to_jiffies(1000);
387 return 0;
354 } 388 }
355 } while (1); 389 } while (1);
356
357 return 0;
358} 390}
359 391
360static int mb86a20s_get_modulation(struct mb86a20s_state *state, 392static int mb86a20s_get_modulation(struct mb86a20s_state *state,
@@ -534,12 +566,13 @@ static u32 isdbt_rate[3][5][4] = {
534}; 566};
535 567
536static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer, 568static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
537 u32 modulation, u32 fec, u32 interleaving, 569 u32 modulation, u32 forward_error_correction,
570 u32 interleaving,
538 u32 segment) 571 u32 segment)
539{ 572{
540 struct mb86a20s_state *state = fe->demodulator_priv; 573 struct mb86a20s_state *state = fe->demodulator_priv;
541 u32 rate; 574 u32 rate;
542 int m, f, i; 575 int mod, fec, guard;
543 576
544 /* 577 /*
545 * If modulation/fec/interleaving is not detected, the default is 578 * If modulation/fec/interleaving is not detected, the default is
@@ -550,54 +583,54 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
550 case DQPSK: 583 case DQPSK:
551 case QPSK: 584 case QPSK:
552 default: 585 default:
553 m = 0; 586 mod = 0;
554 break; 587 break;
555 case QAM_16: 588 case QAM_16:
556 m = 1; 589 mod = 1;
557 break; 590 break;
558 case QAM_64: 591 case QAM_64:
559 m = 2; 592 mod = 2;
560 break; 593 break;
561 } 594 }
562 595
563 switch (fec) { 596 switch (forward_error_correction) {
564 default: 597 default:
565 case FEC_1_2: 598 case FEC_1_2:
566 case FEC_AUTO: 599 case FEC_AUTO:
567 f = 0; 600 fec = 0;
568 break; 601 break;
569 case FEC_2_3: 602 case FEC_2_3:
570 f = 1; 603 fec = 1;
571 break; 604 break;
572 case FEC_3_4: 605 case FEC_3_4:
573 f = 2; 606 fec = 2;
574 break; 607 break;
575 case FEC_5_6: 608 case FEC_5_6:
576 f = 3; 609 fec = 3;
577 break; 610 break;
578 case FEC_7_8: 611 case FEC_7_8:
579 f = 4; 612 fec = 4;
580 break; 613 break;
581 } 614 }
582 615
583 switch (interleaving) { 616 switch (interleaving) {
584 default: 617 default:
585 case GUARD_INTERVAL_1_4: 618 case GUARD_INTERVAL_1_4:
586 i = 0; 619 guard = 0;
587 break; 620 break;
588 case GUARD_INTERVAL_1_8: 621 case GUARD_INTERVAL_1_8:
589 i = 1; 622 guard = 1;
590 break; 623 break;
591 case GUARD_INTERVAL_1_16: 624 case GUARD_INTERVAL_1_16:
592 i = 2; 625 guard = 2;
593 break; 626 break;
594 case GUARD_INTERVAL_1_32: 627 case GUARD_INTERVAL_1_32:
595 i = 3; 628 guard = 3;
596 break; 629 break;
597 } 630 }
598 631
599 /* Samples BER at BER_SAMPLING_RATE seconds */ 632 /* Samples BER at BER_SAMPLING_RATE seconds */
600 rate = isdbt_rate[m][f][i] * segment * BER_SAMPLING_RATE; 633 rate = isdbt_rate[mod][fec][guard] * segment * BER_SAMPLING_RATE;
601 634
602 /* Avoids sampling too quickly or to overflow the register */ 635 /* Avoids sampling too quickly or to overflow the register */
603 if (rate < 256) 636 if (rate < 256)
@@ -607,18 +640,18 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
607 640
608 dev_dbg(&state->i2c->dev, 641 dev_dbg(&state->i2c->dev,
609 "%s: layer %c bitrate: %d kbps; counter = %d (0x%06x)\n", 642 "%s: layer %c bitrate: %d kbps; counter = %d (0x%06x)\n",
610 __func__, 'A' + layer, segment * isdbt_rate[m][f][i]/1000, 643 __func__, 'A' + layer,
644 segment * isdbt_rate[mod][fec][guard]/1000,
611 rate, rate); 645 rate, rate);
612 646
613 state->estimated_rate[layer] = rate; 647 state->estimated_rate[layer] = rate;
614} 648}
615 649
616
617static int mb86a20s_get_frontend(struct dvb_frontend *fe) 650static int mb86a20s_get_frontend(struct dvb_frontend *fe)
618{ 651{
619 struct mb86a20s_state *state = fe->demodulator_priv; 652 struct mb86a20s_state *state = fe->demodulator_priv;
620 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 653 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
621 int i, rc; 654 int layer, rc;
622 655
623 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 656 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
624 657
@@ -636,43 +669,43 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)
636 669
637 /* Get per-layer data */ 670 /* Get per-layer data */
638 671
639 for (i = 0; i < 3; i++) { 672 for (layer = 0; layer < NUM_LAYERS; layer++) {
640 dev_dbg(&state->i2c->dev, "%s: getting data for layer %c.\n", 673 dev_dbg(&state->i2c->dev, "%s: getting data for layer %c.\n",
641 __func__, 'A' + i); 674 __func__, 'A' + layer);
642 675
643 rc = mb86a20s_get_segment_count(state, i); 676 rc = mb86a20s_get_segment_count(state, layer);
644 if (rc < 0) 677 if (rc < 0)
645 goto noperlayer_error; 678 goto noperlayer_error;
646 if (rc >= 0 && rc < 14) { 679 if (rc >= 0 && rc < 14) {
647 c->layer[i].segment_count = rc; 680 c->layer[layer].segment_count = rc;
648 } else { 681 } else {
649 c->layer[i].segment_count = 0; 682 c->layer[layer].segment_count = 0;
650 state->estimated_rate[i] = 0; 683 state->estimated_rate[layer] = 0;
651 continue; 684 continue;
652 } 685 }
653 c->isdbt_layer_enabled |= 1 << i; 686 c->isdbt_layer_enabled |= 1 << layer;
654 rc = mb86a20s_get_modulation(state, i); 687 rc = mb86a20s_get_modulation(state, layer);
655 if (rc < 0) 688 if (rc < 0)
656 goto noperlayer_error; 689 goto noperlayer_error;
657 dev_dbg(&state->i2c->dev, "%s: modulation %d.\n", 690 dev_dbg(&state->i2c->dev, "%s: modulation %d.\n",
658 __func__, rc); 691 __func__, rc);
659 c->layer[i].modulation = rc; 692 c->layer[layer].modulation = rc;
660 rc = mb86a20s_get_fec(state, i); 693 rc = mb86a20s_get_fec(state, layer);
661 if (rc < 0) 694 if (rc < 0)
662 goto noperlayer_error; 695 goto noperlayer_error;
663 dev_dbg(&state->i2c->dev, "%s: FEC %d.\n", 696 dev_dbg(&state->i2c->dev, "%s: FEC %d.\n",
664 __func__, rc); 697 __func__, rc);
665 c->layer[i].fec = rc; 698 c->layer[layer].fec = rc;
666 rc = mb86a20s_get_interleaving(state, i); 699 rc = mb86a20s_get_interleaving(state, layer);
667 if (rc < 0) 700 if (rc < 0)
668 goto noperlayer_error; 701 goto noperlayer_error;
669 dev_dbg(&state->i2c->dev, "%s: interleaving %d.\n", 702 dev_dbg(&state->i2c->dev, "%s: interleaving %d.\n",
670 __func__, rc); 703 __func__, rc);
671 c->layer[i].interleaving = rc; 704 c->layer[layer].interleaving = rc;
672 mb86a20s_layer_bitrate(fe, i, c->layer[i].modulation, 705 mb86a20s_layer_bitrate(fe, layer, c->layer[layer].modulation,
673 c->layer[i].fec, 706 c->layer[layer].fec,
674 c->layer[i].interleaving, 707 c->layer[layer].interleaving,
675 c->layer[i].segment_count); 708 c->layer[layer].segment_count);
676 } 709 }
677 710
678 rc = mb86a20s_writereg(state, 0x6d, 0x84); 711 rc = mb86a20s_writereg(state, 0x6d, 0x84);
@@ -735,7 +768,6 @@ static int mb86a20s_reset_counters(struct dvb_frontend *fe)
735 768
736 /* Reset the counters, if the channel changed */ 769 /* Reset the counters, if the channel changed */
737 if (state->last_frequency != c->frequency) { 770 if (state->last_frequency != c->frequency) {
738 memset(&c->strength, 0, sizeof(c->strength));
739 memset(&c->cnr, 0, sizeof(c->cnr)); 771 memset(&c->cnr, 0, sizeof(c->cnr));
740 memset(&c->pre_bit_error, 0, sizeof(c->pre_bit_error)); 772 memset(&c->pre_bit_error, 0, sizeof(c->pre_bit_error));
741 memset(&c->pre_bit_count, 0, sizeof(c->pre_bit_count)); 773 memset(&c->pre_bit_count, 0, sizeof(c->pre_bit_count));
@@ -799,7 +831,7 @@ static int mb86a20s_get_pre_ber(struct dvb_frontend *fe,
799 831
800 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 832 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
801 833
802 if (layer >= 3) 834 if (layer >= NUM_LAYERS)
803 return -EINVAL; 835 return -EINVAL;
804 836
805 /* Check if the BER measures are already available */ 837 /* Check if the BER measures are already available */
@@ -933,7 +965,7 @@ static int mb86a20s_get_post_ber(struct dvb_frontend *fe,
933 965
934 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 966 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
935 967
936 if (layer >= 3) 968 if (layer >= NUM_LAYERS)
937 return -EINVAL; 969 return -EINVAL;
938 970
939 /* Check if the BER measures are already available */ 971 /* Check if the BER measures are already available */
@@ -1060,7 +1092,7 @@ static int mb86a20s_get_blk_error(struct dvb_frontend *fe,
1060 u32 collect_rate; 1092 u32 collect_rate;
1061 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 1093 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1062 1094
1063 if (layer >= 3) 1095 if (layer >= NUM_LAYERS)
1064 return -EINVAL; 1096 return -EINVAL;
1065 1097
1066 /* Check if the PER measures are already available */ 1098 /* Check if the PER measures are already available */
@@ -1095,7 +1127,7 @@ static int mb86a20s_get_blk_error(struct dvb_frontend *fe,
1095 if (rc < 0) 1127 if (rc < 0)
1096 return rc; 1128 return rc;
1097 *error |= rc; 1129 *error |= rc;
1098 dev_err(&state->i2c->dev, "%s: block error for layer %c: %d.\n", 1130 dev_dbg(&state->i2c->dev, "%s: block error for layer %c: %d.\n",
1099 __func__, 'A' + layer, *error); 1131 __func__, 'A' + layer, *error);
1100 1132
1101 /* Read Bit Count */ 1133 /* Read Bit Count */
@@ -1386,7 +1418,7 @@ static int mb86a20s_get_main_CNR(struct dvb_frontend *fe)
1386 return rc; 1418 return rc;
1387 1419
1388 if (!(rc & 0x40)) { 1420 if (!(rc & 0x40)) {
1389 dev_info(&state->i2c->dev, "%s: CNR is not available yet.\n", 1421 dev_dbg(&state->i2c->dev, "%s: CNR is not available yet.\n",
1390 __func__); 1422 __func__);
1391 return -EBUSY; 1423 return -EBUSY;
1392 } 1424 }
@@ -1425,7 +1457,7 @@ static int mb86a20s_get_blk_error_layer_CNR(struct dvb_frontend *fe)
1425 struct mb86a20s_state *state = fe->demodulator_priv; 1457 struct mb86a20s_state *state = fe->demodulator_priv;
1426 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1458 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1427 u32 mer, cnr; 1459 u32 mer, cnr;
1428 int rc, val, i; 1460 int rc, val, layer;
1429 struct linear_segments *segs; 1461 struct linear_segments *segs;
1430 unsigned segs_len; 1462 unsigned segs_len;
1431 1463
@@ -1441,33 +1473,33 @@ static int mb86a20s_get_blk_error_layer_CNR(struct dvb_frontend *fe)
1441 1473
1442 /* Check if data is available */ 1474 /* Check if data is available */
1443 if (!(rc & 0x01)) { 1475 if (!(rc & 0x01)) {
1444 dev_info(&state->i2c->dev, 1476 dev_dbg(&state->i2c->dev,
1445 "%s: MER measures aren't available yet.\n", __func__); 1477 "%s: MER measures aren't available yet.\n", __func__);
1446 return -EBUSY; 1478 return -EBUSY;
1447 } 1479 }
1448 1480
1449 /* Read all layers */ 1481 /* Read all layers */
1450 for (i = 0; i < 3; i++) { 1482 for (layer = 0; layer < NUM_LAYERS; layer++) {
1451 if (!(c->isdbt_layer_enabled & (1 << i))) { 1483 if (!(c->isdbt_layer_enabled & (1 << layer))) {
1452 c->cnr.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1484 c->cnr.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1453 continue; 1485 continue;
1454 } 1486 }
1455 1487
1456 rc = mb86a20s_writereg(state, 0x50, 0x52 + i * 3); 1488 rc = mb86a20s_writereg(state, 0x50, 0x52 + layer * 3);
1457 if (rc < 0) 1489 if (rc < 0)
1458 return rc; 1490 return rc;
1459 rc = mb86a20s_readreg(state, 0x51); 1491 rc = mb86a20s_readreg(state, 0x51);
1460 if (rc < 0) 1492 if (rc < 0)
1461 return rc; 1493 return rc;
1462 mer = rc << 16; 1494 mer = rc << 16;
1463 rc = mb86a20s_writereg(state, 0x50, 0x53 + i * 3); 1495 rc = mb86a20s_writereg(state, 0x50, 0x53 + layer * 3);
1464 if (rc < 0) 1496 if (rc < 0)
1465 return rc; 1497 return rc;
1466 rc = mb86a20s_readreg(state, 0x51); 1498 rc = mb86a20s_readreg(state, 0x51);
1467 if (rc < 0) 1499 if (rc < 0)
1468 return rc; 1500 return rc;
1469 mer |= rc << 8; 1501 mer |= rc << 8;
1470 rc = mb86a20s_writereg(state, 0x50, 0x54 + i * 3); 1502 rc = mb86a20s_writereg(state, 0x50, 0x54 + layer * 3);
1471 if (rc < 0) 1503 if (rc < 0)
1472 return rc; 1504 return rc;
1473 rc = mb86a20s_readreg(state, 0x51); 1505 rc = mb86a20s_readreg(state, 0x51);
@@ -1475,7 +1507,7 @@ static int mb86a20s_get_blk_error_layer_CNR(struct dvb_frontend *fe)
1475 return rc; 1507 return rc;
1476 mer |= rc; 1508 mer |= rc;
1477 1509
1478 switch (c->layer[i].modulation) { 1510 switch (c->layer[layer].modulation) {
1479 case DQPSK: 1511 case DQPSK:
1480 case QPSK: 1512 case QPSK:
1481 segs = cnr_qpsk_table; 1513 segs = cnr_qpsk_table;
@@ -1493,12 +1525,12 @@ static int mb86a20s_get_blk_error_layer_CNR(struct dvb_frontend *fe)
1493 } 1525 }
1494 cnr = interpolate_value(mer, segs, segs_len); 1526 cnr = interpolate_value(mer, segs, segs_len);
1495 1527
1496 c->cnr.stat[1 + i].scale = FE_SCALE_DECIBEL; 1528 c->cnr.stat[1 + layer].scale = FE_SCALE_DECIBEL;
1497 c->cnr.stat[1 + i].svalue = cnr; 1529 c->cnr.stat[1 + layer].svalue = cnr;
1498 1530
1499 dev_dbg(&state->i2c->dev, 1531 dev_dbg(&state->i2c->dev,
1500 "%s: CNR for layer %c is %d.%03d dB (MER = %d).\n", 1532 "%s: CNR for layer %c is %d.%03d dB (MER = %d).\n",
1501 __func__, 'A' + i, cnr / 1000, cnr % 1000, mer); 1533 __func__, 'A' + layer, cnr / 1000, cnr % 1000, mer);
1502 1534
1503 } 1535 }
1504 1536
@@ -1526,7 +1558,7 @@ static void mb86a20s_stats_not_ready(struct dvb_frontend *fe)
1526{ 1558{
1527 struct mb86a20s_state *state = fe->demodulator_priv; 1559 struct mb86a20s_state *state = fe->demodulator_priv;
1528 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1560 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1529 int i; 1561 int layer;
1530 1562
1531 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 1563 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1532 1564
@@ -1536,35 +1568,35 @@ static void mb86a20s_stats_not_ready(struct dvb_frontend *fe)
1536 c->strength.len = 1; 1568 c->strength.len = 1;
1537 1569
1538 /* Per-layer stats - 3 layers + global */ 1570 /* Per-layer stats - 3 layers + global */
1539 c->cnr.len = 4; 1571 c->cnr.len = NUM_LAYERS + 1;
1540 c->pre_bit_error.len = 4; 1572 c->pre_bit_error.len = NUM_LAYERS + 1;
1541 c->pre_bit_count.len = 4; 1573 c->pre_bit_count.len = NUM_LAYERS + 1;
1542 c->post_bit_error.len = 4; 1574 c->post_bit_error.len = NUM_LAYERS + 1;
1543 c->post_bit_count.len = 4; 1575 c->post_bit_count.len = NUM_LAYERS + 1;
1544 c->block_error.len = 4; 1576 c->block_error.len = NUM_LAYERS + 1;
1545 c->block_count.len = 4; 1577 c->block_count.len = NUM_LAYERS + 1;
1546 1578
1547 /* Signal is always available */ 1579 /* Signal is always available */
1548 c->strength.stat[0].scale = FE_SCALE_RELATIVE; 1580 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
1549 c->strength.stat[0].uvalue = 0; 1581 c->strength.stat[0].uvalue = 0;
1550 1582
1551 /* Put all of them at FE_SCALE_NOT_AVAILABLE */ 1583 /* Put all of them at FE_SCALE_NOT_AVAILABLE */
1552 for (i = 0; i < 4; i++) { 1584 for (layer = 0; layer < NUM_LAYERS + 1; layer++) {
1553 c->cnr.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1585 c->cnr.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1554 c->pre_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1586 c->pre_bit_error.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1555 c->pre_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1587 c->pre_bit_count.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1556 c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1588 c->post_bit_error.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1557 c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1589 c->post_bit_count.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1558 c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1590 c->block_error.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1559 c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE; 1591 c->block_count.stat[layer].scale = FE_SCALE_NOT_AVAILABLE;
1560 } 1592 }
1561} 1593}
1562 1594
1563static int mb86a20s_get_stats(struct dvb_frontend *fe) 1595static int mb86a20s_get_stats(struct dvb_frontend *fe, int status_nr)
1564{ 1596{
1565 struct mb86a20s_state *state = fe->demodulator_priv; 1597 struct mb86a20s_state *state = fe->demodulator_priv;
1566 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1598 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1567 int rc = 0, i; 1599 int rc = 0, layer;
1568 u32 bit_error = 0, bit_count = 0; 1600 u32 bit_error = 0, bit_count = 0;
1569 u32 t_pre_bit_error = 0, t_pre_bit_count = 0; 1601 u32 t_pre_bit_error = 0, t_pre_bit_count = 0;
1570 u32 t_post_bit_error = 0, t_post_bit_count = 0; 1602 u32 t_post_bit_error = 0, t_post_bit_count = 0;
@@ -1580,90 +1612,98 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)
1580 /* Get per-layer stats */ 1612 /* Get per-layer stats */
1581 mb86a20s_get_blk_error_layer_CNR(fe); 1613 mb86a20s_get_blk_error_layer_CNR(fe);
1582 1614
1583 for (i = 0; i < 3; i++) { 1615 /*
1584 if (c->isdbt_layer_enabled & (1 << i)) { 1616 * At state 7, only CNR is available
1617 * For BER measures, state=9 is required
1618 * FIXME: we may get MER measures with state=8
1619 */
1620 if (status_nr < 9)
1621 return 0;
1622
1623 for (layer = 0; layer < NUM_LAYERS; layer++) {
1624 if (c->isdbt_layer_enabled & (1 << layer)) {
1585 /* Layer is active and has rc segments */ 1625 /* Layer is active and has rc segments */
1586 active_layers++; 1626 active_layers++;
1587 1627
1588 /* Handle BER before vterbi */ 1628 /* Handle BER before vterbi */
1589 rc = mb86a20s_get_pre_ber(fe, i, 1629 rc = mb86a20s_get_pre_ber(fe, layer,
1590 &bit_error, &bit_count); 1630 &bit_error, &bit_count);
1591 if (rc >= 0) { 1631 if (rc >= 0) {
1592 c->pre_bit_error.stat[1 + i].scale = FE_SCALE_COUNTER; 1632 c->pre_bit_error.stat[1 + layer].scale = FE_SCALE_COUNTER;
1593 c->pre_bit_error.stat[1 + i].uvalue += bit_error; 1633 c->pre_bit_error.stat[1 + layer].uvalue += bit_error;
1594 c->pre_bit_count.stat[1 + i].scale = FE_SCALE_COUNTER; 1634 c->pre_bit_count.stat[1 + layer].scale = FE_SCALE_COUNTER;
1595 c->pre_bit_count.stat[1 + i].uvalue += bit_count; 1635 c->pre_bit_count.stat[1 + layer].uvalue += bit_count;
1596 } else if (rc != -EBUSY) { 1636 } else if (rc != -EBUSY) {
1597 /* 1637 /*
1598 * If an I/O error happened, 1638 * If an I/O error happened,
1599 * measures are now unavailable 1639 * measures are now unavailable
1600 */ 1640 */
1601 c->pre_bit_error.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1641 c->pre_bit_error.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1602 c->pre_bit_count.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1642 c->pre_bit_count.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1603 dev_err(&state->i2c->dev, 1643 dev_err(&state->i2c->dev,
1604 "%s: Can't get BER for layer %c (error %d).\n", 1644 "%s: Can't get BER for layer %c (error %d).\n",
1605 __func__, 'A' + i, rc); 1645 __func__, 'A' + layer, rc);
1606 } 1646 }
1607 if (c->block_error.stat[1 + i].scale != FE_SCALE_NOT_AVAILABLE) 1647 if (c->block_error.stat[1 + layer].scale != FE_SCALE_NOT_AVAILABLE)
1608 pre_ber_layers++; 1648 pre_ber_layers++;
1609 1649
1610 /* Handle BER post vterbi */ 1650 /* Handle BER post vterbi */
1611 rc = mb86a20s_get_post_ber(fe, i, 1651 rc = mb86a20s_get_post_ber(fe, layer,
1612 &bit_error, &bit_count); 1652 &bit_error, &bit_count);
1613 if (rc >= 0) { 1653 if (rc >= 0) {
1614 c->post_bit_error.stat[1 + i].scale = FE_SCALE_COUNTER; 1654 c->post_bit_error.stat[1 + layer].scale = FE_SCALE_COUNTER;
1615 c->post_bit_error.stat[1 + i].uvalue += bit_error; 1655 c->post_bit_error.stat[1 + layer].uvalue += bit_error;
1616 c->post_bit_count.stat[1 + i].scale = FE_SCALE_COUNTER; 1656 c->post_bit_count.stat[1 + layer].scale = FE_SCALE_COUNTER;
1617 c->post_bit_count.stat[1 + i].uvalue += bit_count; 1657 c->post_bit_count.stat[1 + layer].uvalue += bit_count;
1618 } else if (rc != -EBUSY) { 1658 } else if (rc != -EBUSY) {
1619 /* 1659 /*
1620 * If an I/O error happened, 1660 * If an I/O error happened,
1621 * measures are now unavailable 1661 * measures are now unavailable
1622 */ 1662 */
1623 c->post_bit_error.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1663 c->post_bit_error.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1624 c->post_bit_count.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1664 c->post_bit_count.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1625 dev_err(&state->i2c->dev, 1665 dev_err(&state->i2c->dev,
1626 "%s: Can't get BER for layer %c (error %d).\n", 1666 "%s: Can't get BER for layer %c (error %d).\n",
1627 __func__, 'A' + i, rc); 1667 __func__, 'A' + layer, rc);
1628 } 1668 }
1629 if (c->block_error.stat[1 + i].scale != FE_SCALE_NOT_AVAILABLE) 1669 if (c->block_error.stat[1 + layer].scale != FE_SCALE_NOT_AVAILABLE)
1630 post_ber_layers++; 1670 post_ber_layers++;
1631 1671
1632 /* Handle Block errors for PER/UCB reports */ 1672 /* Handle Block errors for PER/UCB reports */
1633 rc = mb86a20s_get_blk_error(fe, i, 1673 rc = mb86a20s_get_blk_error(fe, layer,
1634 &block_error, 1674 &block_error,
1635 &block_count); 1675 &block_count);
1636 if (rc >= 0) { 1676 if (rc >= 0) {
1637 c->block_error.stat[1 + i].scale = FE_SCALE_COUNTER; 1677 c->block_error.stat[1 + layer].scale = FE_SCALE_COUNTER;
1638 c->block_error.stat[1 + i].uvalue += block_error; 1678 c->block_error.stat[1 + layer].uvalue += block_error;
1639 c->block_count.stat[1 + i].scale = FE_SCALE_COUNTER; 1679 c->block_count.stat[1 + layer].scale = FE_SCALE_COUNTER;
1640 c->block_count.stat[1 + i].uvalue += block_count; 1680 c->block_count.stat[1 + layer].uvalue += block_count;
1641 } else if (rc != -EBUSY) { 1681 } else if (rc != -EBUSY) {
1642 /* 1682 /*
1643 * If an I/O error happened, 1683 * If an I/O error happened,
1644 * measures are now unavailable 1684 * measures are now unavailable
1645 */ 1685 */
1646 c->block_error.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1686 c->block_error.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1647 c->block_count.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE; 1687 c->block_count.stat[1 + layer].scale = FE_SCALE_NOT_AVAILABLE;
1648 dev_err(&state->i2c->dev, 1688 dev_err(&state->i2c->dev,
1649 "%s: Can't get PER for layer %c (error %d).\n", 1689 "%s: Can't get PER for layer %c (error %d).\n",
1650 __func__, 'A' + i, rc); 1690 __func__, 'A' + layer, rc);
1651 1691
1652 } 1692 }
1653 if (c->block_error.stat[1 + i].scale != FE_SCALE_NOT_AVAILABLE) 1693 if (c->block_error.stat[1 + layer].scale != FE_SCALE_NOT_AVAILABLE)
1654 per_layers++; 1694 per_layers++;
1655 1695
1656 /* Update total preBER */ 1696 /* Update total preBER */
1657 t_pre_bit_error += c->pre_bit_error.stat[1 + i].uvalue; 1697 t_pre_bit_error += c->pre_bit_error.stat[1 + layer].uvalue;
1658 t_pre_bit_count += c->pre_bit_count.stat[1 + i].uvalue; 1698 t_pre_bit_count += c->pre_bit_count.stat[1 + layer].uvalue;
1659 1699
1660 /* Update total postBER */ 1700 /* Update total postBER */
1661 t_post_bit_error += c->post_bit_error.stat[1 + i].uvalue; 1701 t_post_bit_error += c->post_bit_error.stat[1 + layer].uvalue;
1662 t_post_bit_count += c->post_bit_count.stat[1 + i].uvalue; 1702 t_post_bit_count += c->post_bit_count.stat[1 + layer].uvalue;
1663 1703
1664 /* Update total PER */ 1704 /* Update total PER */
1665 t_block_error += c->block_error.stat[1 + i].uvalue; 1705 t_block_error += c->block_error.stat[1 + layer].uvalue;
1666 t_block_count += c->block_count.stat[1 + i].uvalue; 1706 t_block_count += c->block_count.stat[1 + layer].uvalue;
1667 } 1707 }
1668 } 1708 }
1669 1709
@@ -1737,8 +1777,10 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)
1737static int mb86a20s_initfe(struct dvb_frontend *fe) 1777static int mb86a20s_initfe(struct dvb_frontend *fe)
1738{ 1778{
1739 struct mb86a20s_state *state = fe->demodulator_priv; 1779 struct mb86a20s_state *state = fe->demodulator_priv;
1780 u64 pll;
1781 u32 fclk;
1740 int rc; 1782 int rc;
1741 u8 regD5 = 1; 1783 u8 regD5 = 1, reg71, reg09 = 0x3a;
1742 1784
1743 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 1785 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1744 1786
@@ -1746,10 +1788,78 @@ static int mb86a20s_initfe(struct dvb_frontend *fe)
1746 fe->ops.i2c_gate_ctrl(fe, 0); 1788 fe->ops.i2c_gate_ctrl(fe, 0);
1747 1789
1748 /* Initialize the frontend */ 1790 /* Initialize the frontend */
1749 rc = mb86a20s_writeregdata(state, mb86a20s_init); 1791 rc = mb86a20s_writeregdata(state, mb86a20s_init1);
1750 if (rc < 0) 1792 if (rc < 0)
1751 goto err; 1793 goto err;
1752 1794
1795 if (!state->inversion)
1796 reg09 |= 0x04;
1797 rc = mb86a20s_writereg(state, 0x09, reg09);
1798 if (rc < 0)
1799 goto err;
1800 if (!state->bw)
1801 reg71 = 1;
1802 else
1803 reg71 = 0;
1804 rc = mb86a20s_writereg(state, 0x39, reg71);
1805 if (rc < 0)
1806 goto err;
1807 rc = mb86a20s_writereg(state, 0x71, state->bw);
1808 if (rc < 0)
1809 goto err;
1810 if (state->subchannel) {
1811 rc = mb86a20s_writereg(state, 0x44, state->subchannel);
1812 if (rc < 0)
1813 goto err;
1814 }
1815
1816 fclk = state->config->fclk;
1817 if (!fclk)
1818 fclk = 32571428;
1819
1820 /* Adjust IF frequency to match tuner */
1821 if (fe->ops.tuner_ops.get_if_frequency)
1822 fe->ops.tuner_ops.get_if_frequency(fe, &state->if_freq);
1823
1824 if (!state->if_freq)
1825 state->if_freq = 3300000;
1826
1827 pll = (((u64)1) << 34) * state->if_freq;
1828 do_div(pll, 63 * fclk);
1829 pll = (1 << 25) - pll;
1830 rc = mb86a20s_writereg(state, 0x28, 0x2a);
1831 if (rc < 0)
1832 goto err;
1833 rc = mb86a20s_writereg(state, 0x29, (pll >> 16) & 0xff);
1834 if (rc < 0)
1835 goto err;
1836 rc = mb86a20s_writereg(state, 0x2a, (pll >> 8) & 0xff);
1837 if (rc < 0)
1838 goto err;
1839 rc = mb86a20s_writereg(state, 0x2b, pll & 0xff);
1840 if (rc < 0)
1841 goto err;
1842 dev_dbg(&state->i2c->dev, "%s: fclk=%d, IF=%d, clock reg=0x%06llx\n",
1843 __func__, fclk, state->if_freq, (long long)pll);
1844
1845 /* pll = freq[Hz] * 2^24/10^6 / 16.285714286 */
1846 pll = state->if_freq * 1677721600L;
1847 do_div(pll, 1628571429L);
1848 rc = mb86a20s_writereg(state, 0x28, 0x20);
1849 if (rc < 0)
1850 goto err;
1851 rc = mb86a20s_writereg(state, 0x29, (pll >> 16) & 0xff);
1852 if (rc < 0)
1853 goto err;
1854 rc = mb86a20s_writereg(state, 0x2a, (pll >> 8) & 0xff);
1855 if (rc < 0)
1856 goto err;
1857 rc = mb86a20s_writereg(state, 0x2b, pll & 0xff);
1858 if (rc < 0)
1859 goto err;
1860 dev_dbg(&state->i2c->dev, "%s: IF=%d, IF reg=0x%06llx\n",
1861 __func__, state->if_freq, (long long)pll);
1862
1753 if (!state->config->is_serial) { 1863 if (!state->config->is_serial) {
1754 regD5 &= ~1; 1864 regD5 &= ~1;
1755 1865
@@ -1761,6 +1871,11 @@ static int mb86a20s_initfe(struct dvb_frontend *fe)
1761 goto err; 1871 goto err;
1762 } 1872 }
1763 1873
1874 rc = mb86a20s_writeregdata(state, mb86a20s_init2);
1875 if (rc < 0)
1876 goto err;
1877
1878
1764err: 1879err:
1765 if (fe->ops.i2c_gate_ctrl) 1880 if (fe->ops.i2c_gate_ctrl)
1766 fe->ops.i2c_gate_ctrl(fe, 1); 1881 fe->ops.i2c_gate_ctrl(fe, 1);
@@ -1779,15 +1894,34 @@ err:
1779static int mb86a20s_set_frontend(struct dvb_frontend *fe) 1894static int mb86a20s_set_frontend(struct dvb_frontend *fe)
1780{ 1895{
1781 struct mb86a20s_state *state = fe->demodulator_priv; 1896 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; 1897 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1788#endif 1898 int rc, if_freq;
1789 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 1899 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1790 1900
1901 if (!c->isdbt_layer_enabled)
1902 c->isdbt_layer_enabled = 7;
1903
1904 if (c->isdbt_layer_enabled == 1)
1905 state->bw = MB86A20S_1SEG;
1906 else if (c->isdbt_partial_reception)
1907 state->bw = MB86A20S_13SEG_PARTIAL;
1908 else
1909 state->bw = MB86A20S_13SEG;
1910
1911 if (c->inversion == INVERSION_ON)
1912 state->inversion = true;
1913 else
1914 state->inversion = false;
1915
1916 if (!c->isdbt_sb_mode) {
1917 state->subchannel = 0;
1918 } else {
1919 if (c->isdbt_sb_subchannel >= ARRAY_SIZE(mb86a20s_subchannel))
1920 c->isdbt_sb_subchannel = 0;
1921
1922 state->subchannel = mb86a20s_subchannel[c->isdbt_sb_subchannel];
1923 }
1924
1791 /* 1925 /*
1792 * Gate should already be opened, but it doesn't hurt to 1926 * Gate should already be opened, but it doesn't hurt to
1793 * double-check 1927 * double-check
@@ -1796,6 +1930,9 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)
1796 fe->ops.i2c_gate_ctrl(fe, 1); 1930 fe->ops.i2c_gate_ctrl(fe, 1);
1797 fe->ops.tuner_ops.set_params(fe); 1931 fe->ops.tuner_ops.set_params(fe);
1798 1932
1933 if (fe->ops.tuner_ops.get_if_frequency)
1934 fe->ops.tuner_ops.get_if_frequency(fe, &if_freq);
1935
1799 /* 1936 /*
1800 * Make it more reliable: if, for some reason, the initial 1937 * Make it more reliable: if, for some reason, the initial
1801 * device initialization doesn't happen, initialize it when 1938 * device initialization doesn't happen, initialize it when
@@ -1805,15 +1942,22 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)
1805 * the agc callback logic is not called during DVB attach time, 1942 * the agc callback logic is not called during DVB attach time,
1806 * causing mb86a20s to not be initialized with Kworld SBTVD. 1943 * causing mb86a20s to not be initialized with Kworld SBTVD.
1807 * So, this hack is needed, in order to make Kworld SBTVD to work. 1944 * So, this hack is needed, in order to make Kworld SBTVD to work.
1945 *
1946 * It is also needed to change the IF after the initial init.
1947 *
1948 * HACK: Always init the frontend when set_frontend is called:
1949 * it was noticed that, on some devices, it fails to lock on a
1950 * different channel. So, it is better to reset everything, even
1951 * wasting some time, than to loose channel lock.
1808 */ 1952 */
1809 if (state->need_init) 1953 mb86a20s_initfe(fe);
1810 mb86a20s_initfe(fe);
1811 1954
1812 if (fe->ops.i2c_gate_ctrl) 1955 if (fe->ops.i2c_gate_ctrl)
1813 fe->ops.i2c_gate_ctrl(fe, 0); 1956 fe->ops.i2c_gate_ctrl(fe, 0);
1814 1957
1815 rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception); 1958 rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception);
1816 mb86a20s_reset_counters(fe); 1959 mb86a20s_reset_counters(fe);
1960 mb86a20s_stats_not_ready(fe);
1817 1961
1818 if (fe->ops.i2c_gate_ctrl) 1962 if (fe->ops.i2c_gate_ctrl)
1819 fe->ops.i2c_gate_ctrl(fe, 1); 1963 fe->ops.i2c_gate_ctrl(fe, 1);
@@ -1825,8 +1969,7 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,
1825 fe_status_t *status) 1969 fe_status_t *status)
1826{ 1970{
1827 struct mb86a20s_state *state = fe->demodulator_priv; 1971 struct mb86a20s_state *state = fe->demodulator_priv;
1828 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1972 int rc, status_nr;
1829 int rc;
1830 1973
1831 dev_dbg(&state->i2c->dev, "%s called.\n", __func__); 1974 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1832 1975
@@ -1834,12 +1977,12 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,
1834 fe->ops.i2c_gate_ctrl(fe, 0); 1977 fe->ops.i2c_gate_ctrl(fe, 0);
1835 1978
1836 /* Get lock */ 1979 /* Get lock */
1837 rc = mb86a20s_read_status(fe, status); 1980 status_nr = mb86a20s_read_status(fe, status);
1838 if (!(*status & FE_HAS_LOCK)) { 1981 if (status_nr < 7) {
1839 mb86a20s_stats_not_ready(fe); 1982 mb86a20s_stats_not_ready(fe);
1840 mb86a20s_reset_frontend_cache(fe); 1983 mb86a20s_reset_frontend_cache(fe);
1841 } 1984 }
1842 if (rc < 0) { 1985 if (status_nr < 0) {
1843 dev_err(&state->i2c->dev, 1986 dev_err(&state->i2c->dev,
1844 "%s: Can't read frontend lock status\n", __func__); 1987 "%s: Can't read frontend lock status\n", __func__);
1845 goto error; 1988 goto error;
@@ -1856,10 +1999,8 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,
1856 rc = 0; /* Status is OK */ 1999 rc = 0; /* Status is OK */
1857 goto error; 2000 goto error;
1858 } 2001 }
1859 /* Fill signal strength */
1860 c->strength.stat[0].uvalue = rc;
1861 2002
1862 if (*status & FE_HAS_LOCK) { 2003 if (status_nr >= 7) {
1863 /* Get TMCC info*/ 2004 /* Get TMCC info*/
1864 rc = mb86a20s_get_frontend(fe); 2005 rc = mb86a20s_get_frontend(fe);
1865 if (rc < 0) { 2006 if (rc < 0) {
@@ -1870,7 +2011,7 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,
1870 } 2011 }
1871 2012
1872 /* Get statistics */ 2013 /* Get statistics */
1873 rc = mb86a20s_get_stats(fe); 2014 rc = mb86a20s_get_stats(fe, status_nr);
1874 if (rc < 0 && rc != -EBUSY) { 2015 if (rc < 0 && rc != -EBUSY) {
1875 dev_err(&state->i2c->dev, 2016 dev_err(&state->i2c->dev,
1876 "%s: Can't get FE statistics.\n", __func__); 2017 "%s: Can't get FE statistics.\n", __func__);
@@ -1994,7 +2135,7 @@ static struct dvb_frontend_ops mb86a20s_ops = {
1994 /* Use dib8000 values per default */ 2135 /* Use dib8000 values per default */
1995 .info = { 2136 .info = {
1996 .name = "Fujitsu mb86A20s", 2137 .name = "Fujitsu mb86A20s",
1997 .caps = FE_CAN_INVERSION_AUTO | FE_CAN_RECOVER | 2138 .caps = FE_CAN_RECOVER |
1998 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 2139 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1999 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | 2140 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
2000 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | 2141 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
diff --git a/drivers/media/dvb-frontends/mb86a20s.h b/drivers/media/dvb-frontends/mb86a20s.h
index bf22e77888b9..6627a3976087 100644
--- a/drivers/media/dvb-frontends/mb86a20s.h
+++ b/drivers/media/dvb-frontends/mb86a20s.h
@@ -16,21 +16,25 @@
16#ifndef MB86A20S_H 16#ifndef MB86A20S_H
17#define MB86A20S_H 17#define MB86A20S_H
18 18
19#include <linux/kconfig.h>
19#include <linux/dvb/frontend.h> 20#include <linux/dvb/frontend.h>
20 21
21/** 22/**
22 * struct mb86a20s_config - Define the per-device attributes of the frontend 23 * struct mb86a20s_config - Define the per-device attributes of the frontend
23 * 24 *
25 * @fclk: Clock frequency. If zero, assumes the default
26 * (32.57142 Mhz)
24 * @demod_address: the demodulator's i2c address 27 * @demod_address: the demodulator's i2c address
28 * @is_serial: if true, TS is serial. Otherwise, TS is parallel
25 */ 29 */
26 30
27struct mb86a20s_config { 31struct mb86a20s_config {
28 u8 demod_address; 32 u32 fclk;
29 bool is_serial; 33 u8 demod_address;
34 bool is_serial;
30}; 35};
31 36
32#if defined(CONFIG_DVB_MB86A20S) || (defined(CONFIG_DVB_MB86A20S_MODULE) \ 37#if IS_ENABLED(CONFIG_DVB_MB86A20S)
33 && defined(MODULE))
34extern struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config, 38extern struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
35 struct i2c_adapter *i2c); 39 struct i2c_adapter *i2c);
36extern struct i2c_adapter *mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *); 40extern struct i2c_adapter *mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *);
diff --git a/drivers/media/dvb-frontends/rtl2830.h b/drivers/media/dvb-frontends/rtl2830.h
index f4349a1fc03e..3313847fb0be 100644
--- a/drivers/media/dvb-frontends/rtl2830.h
+++ b/drivers/media/dvb-frontends/rtl2830.h
@@ -21,6 +21,7 @@
21#ifndef RTL2830_H 21#ifndef RTL2830_H
22#define RTL2830_H 22#define RTL2830_H
23 23
24#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
25 26
26struct rtl2830_config { 27struct rtl2830_config {
@@ -59,8 +60,7 @@ struct rtl2830_config {
59 u8 agc_targ_val; 60 u8 agc_targ_val;
60}; 61};
61 62
62#if defined(CONFIG_DVB_RTL2830) || \ 63#if IS_ENABLED(CONFIG_DVB_RTL2830)
63 (defined(CONFIG_DVB_RTL2830_MODULE) && defined(MODULE))
64extern struct dvb_frontend *rtl2830_attach( 64extern struct dvb_frontend *rtl2830_attach(
65 const struct rtl2830_config *config, 65 const struct rtl2830_config *config,
66 struct i2c_adapter *i2c 66 struct i2c_adapter *i2c
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index 73887690b046..facb84841518 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -380,13 +380,41 @@ err:
380 return ret; 380 return ret;
381} 381}
382 382
383static int rtl2832_init(struct dvb_frontend *fe) 383
384static int rtl2832_set_if(struct dvb_frontend *fe, u32 if_freq)
384{ 385{
385 struct rtl2832_priv *priv = fe->demodulator_priv; 386 struct rtl2832_priv *priv = fe->demodulator_priv;
386 int i, ret, len; 387 int ret;
387 u8 en_bbin;
388 u64 pset_iffreq; 388 u64 pset_iffreq;
389 u8 en_bbin = (if_freq == 0 ? 0x1 : 0x0);
390
391 /*
392 * PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22)
393 * / CrystalFreqHz)
394 */
395
396 pset_iffreq = if_freq % priv->cfg.xtal;
397 pset_iffreq *= 0x400000;
398 pset_iffreq = div_u64(pset_iffreq, priv->cfg.xtal);
399 pset_iffreq = -pset_iffreq;
400 pset_iffreq = pset_iffreq & 0x3fffff;
401 dev_dbg(&priv->i2c->dev, "%s: if_frequency=%d pset_iffreq=%08x\n",
402 __func__, if_freq, (unsigned)pset_iffreq);
403
404 ret = rtl2832_wr_demod_reg(priv, DVBT_EN_BBIN, en_bbin);
405 if (ret)
406 return ret;
407
408 ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq);
409
410 return (ret);
411}
412
413static int rtl2832_init(struct dvb_frontend *fe)
414{
415 struct rtl2832_priv *priv = fe->demodulator_priv;
389 const struct rtl2832_reg_value *init; 416 const struct rtl2832_reg_value *init;
417 int i, ret, len;
390 418
391 /* initialization values for the demodulator registers */ 419 /* initialization values for the demodulator registers */
392 struct rtl2832_reg_value rtl2832_initial_regs[] = { 420 struct rtl2832_reg_value rtl2832_initial_regs[] = {
@@ -432,22 +460,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
432 {DVBT_TR_THD_SET2, 0x6}, 460 {DVBT_TR_THD_SET2, 0x6},
433 {DVBT_TRK_KC_I2, 0x5}, 461 {DVBT_TRK_KC_I2, 0x5},
434 {DVBT_CR_THD_SET2, 0x1}, 462 {DVBT_CR_THD_SET2, 0x1},
435 {DVBT_SPEC_INV, 0x0},
436 }; 463 };
437 464
438 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 465 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
439 466
440 en_bbin = (priv->cfg.if_dvbt == 0 ? 0x1 : 0x0);
441
442 /*
443 * PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22)
444 * / CrystalFreqHz)
445 */
446 pset_iffreq = priv->cfg.if_dvbt % priv->cfg.xtal;
447 pset_iffreq *= 0x400000;
448 pset_iffreq = div_u64(pset_iffreq, priv->cfg.xtal);
449 pset_iffreq = pset_iffreq & 0x3fffff;
450
451 for (i = 0; i < ARRAY_SIZE(rtl2832_initial_regs); i++) { 467 for (i = 0; i < ARRAY_SIZE(rtl2832_initial_regs); i++) {
452 ret = rtl2832_wr_demod_reg(priv, rtl2832_initial_regs[i].reg, 468 ret = rtl2832_wr_demod_reg(priv, rtl2832_initial_regs[i].reg,
453 rtl2832_initial_regs[i].value); 469 rtl2832_initial_regs[i].value);
@@ -472,6 +488,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
472 len = ARRAY_SIZE(rtl2832_tuner_init_e4000); 488 len = ARRAY_SIZE(rtl2832_tuner_init_e4000);
473 init = rtl2832_tuner_init_e4000; 489 init = rtl2832_tuner_init_e4000;
474 break; 490 break;
491 case RTL2832_TUNER_R820T:
492 len = ARRAY_SIZE(rtl2832_tuner_init_r820t);
493 init = rtl2832_tuner_init_r820t;
494 break;
475 default: 495 default:
476 ret = -EINVAL; 496 ret = -EINVAL;
477 goto err; 497 goto err;
@@ -483,14 +503,26 @@ static int rtl2832_init(struct dvb_frontend *fe)
483 goto err; 503 goto err;
484 } 504 }
485 505
486 /* if frequency settings */ 506 if (!fe->ops.tuner_ops.get_if_frequency) {
487 ret = rtl2832_wr_demod_reg(priv, DVBT_EN_BBIN, en_bbin); 507 ret = rtl2832_set_if(fe, priv->cfg.if_dvbt);
488 if (ret) 508 if (ret)
489 goto err; 509 goto err;
510 }
490 511
491 ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq); 512 /*
492 if (ret) 513 * r820t NIM code does a software reset here at the demod -
493 goto err; 514 * may not be needed, as there's already a software reset at set_params()
515 */
516#if 1
517 /* soft reset */
518 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x1);
519 if (ret)
520 goto err;
521
522 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x0);
523 if (ret)
524 goto err;
525#endif
494 526
495 priv->sleeping = false; 527 priv->sleeping = false;
496 528
@@ -564,6 +596,19 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
564 if (fe->ops.tuner_ops.set_params) 596 if (fe->ops.tuner_ops.set_params)
565 fe->ops.tuner_ops.set_params(fe); 597 fe->ops.tuner_ops.set_params(fe);
566 598
599 /* If the frontend has get_if_frequency(), use it */
600 if (fe->ops.tuner_ops.get_if_frequency) {
601 u32 if_freq;
602
603 ret = fe->ops.tuner_ops.get_if_frequency(fe, &if_freq);
604 if (ret)
605 goto err;
606
607 ret = rtl2832_set_if(fe, if_freq);
608 if (ret)
609 goto err;
610 }
611
567 switch (c->bandwidth_hz) { 612 switch (c->bandwidth_hz) {
568 case 6000000: 613 case 6000000:
569 i = 0; 614 i = 0;
diff --git a/drivers/media/dvb-frontends/rtl2832.h b/drivers/media/dvb-frontends/rtl2832.h
index 785a466eb065..91b2dcf5a6ea 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -21,6 +21,7 @@
21#ifndef RTL2832_H 21#ifndef RTL2832_H
22#define RTL2832_H 22#define RTL2832_H
23 23
24#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
25 26
26struct rtl2832_config { 27struct rtl2832_config {
@@ -51,11 +52,11 @@ struct rtl2832_config {
51#define RTL2832_TUNER_FC0012 0x26 52#define RTL2832_TUNER_FC0012 0x26
52#define RTL2832_TUNER_E4000 0x27 53#define RTL2832_TUNER_E4000 0x27
53#define RTL2832_TUNER_FC0013 0x29 54#define RTL2832_TUNER_FC0013 0x29
55#define RTL2832_TUNER_R820T 0x2a
54 u8 tuner; 56 u8 tuner;
55}; 57};
56 58
57#if defined(CONFIG_DVB_RTL2832) || \ 59#if IS_ENABLED(CONFIG_DVB_RTL2832)
58 (defined(CONFIG_DVB_RTL2832_MODULE) && defined(MODULE))
59extern struct dvb_frontend *rtl2832_attach( 60extern struct dvb_frontend *rtl2832_attach(
60 const struct rtl2832_config *cfg, 61 const struct rtl2832_config *cfg,
61 struct i2c_adapter *i2c 62 struct i2c_adapter *i2c
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h b/drivers/media/dvb-frontends/rtl2832_priv.h
index 7d97ce9d2193..b5f2b80092ee 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -267,6 +267,7 @@ static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001[] = {
267 {DVBT_OPT_ADC_IQ, 0x1}, 267 {DVBT_OPT_ADC_IQ, 0x1},
268 {DVBT_AD_AVI, 0x0}, 268 {DVBT_AD_AVI, 0x0},
269 {DVBT_AD_AVQ, 0x0}, 269 {DVBT_AD_AVQ, 0x0},
270 {DVBT_SPEC_INV, 0x0},
270}; 271};
271 272
272static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012[] = { 273static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012[] = {
@@ -300,6 +301,7 @@ static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012[] = {
300 {DVBT_GI_PGA_STATE, 0x0}, 301 {DVBT_GI_PGA_STATE, 0x0},
301 {DVBT_EN_AGC_PGA, 0x1}, 302 {DVBT_EN_AGC_PGA, 0x1},
302 {DVBT_IF_AGC_MAN, 0x0}, 303 {DVBT_IF_AGC_MAN, 0x0},
304 {DVBT_SPEC_INV, 0x0},
303}; 305};
304 306
305static const struct rtl2832_reg_value rtl2832_tuner_init_e4000[] = { 307static const struct rtl2832_reg_value rtl2832_tuner_init_e4000[] = {
@@ -337,6 +339,32 @@ static const struct rtl2832_reg_value rtl2832_tuner_init_e4000[] = {
337 {DVBT_REG_MONSEL, 0x1}, 339 {DVBT_REG_MONSEL, 0x1},
338 {DVBT_REG_MON, 0x1}, 340 {DVBT_REG_MON, 0x1},
339 {DVBT_REG_4MSEL, 0x0}, 341 {DVBT_REG_4MSEL, 0x0},
342 {DVBT_SPEC_INV, 0x0},
343};
344
345static const struct rtl2832_reg_value rtl2832_tuner_init_r820t[] = {
346 {DVBT_DAGC_TRG_VAL, 0x39},
347 {DVBT_AGC_TARG_VAL_0, 0x0},
348 {DVBT_AGC_TARG_VAL_8_1, 0x40},
349 {DVBT_AAGC_LOOP_GAIN, 0x16},
350 {DVBT_LOOP_GAIN2_3_0, 0x8},
351 {DVBT_LOOP_GAIN2_4, 0x1},
352 {DVBT_LOOP_GAIN3, 0x18},
353 {DVBT_VTOP1, 0x35},
354 {DVBT_VTOP2, 0x21},
355 {DVBT_VTOP3, 0x21},
356 {DVBT_KRF1, 0x0},
357 {DVBT_KRF2, 0x40},
358 {DVBT_KRF3, 0x10},
359 {DVBT_KRF4, 0x10},
360 {DVBT_IF_AGC_MIN, 0x80},
361 {DVBT_IF_AGC_MAX, 0x7f},
362 {DVBT_RF_AGC_MIN, 0x80},
363 {DVBT_RF_AGC_MAX, 0x7f},
364 {DVBT_POLAR_RF_AGC, 0x0},
365 {DVBT_POLAR_IF_AGC, 0x0},
366 {DVBT_AD7_SETTING, 0xe9f4},
367 {DVBT_SPEC_INV, 0x1},
340}; 368};
341 369
342#endif /* RTL2832_PRIV_H */ 370#endif /* RTL2832_PRIV_H */
diff --git a/drivers/media/dvb-frontends/s5h1409.h b/drivers/media/dvb-frontends/s5h1409.h
index 91f2ebd1a534..63b1e0a34e4e 100644
--- a/drivers/media/dvb-frontends/s5h1409.h
+++ b/drivers/media/dvb-frontends/s5h1409.h
@@ -22,6 +22,7 @@
22#ifndef __S5H1409_H__ 22#ifndef __S5H1409_H__
23#define __S5H1409_H__ 23#define __S5H1409_H__
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27struct s5h1409_config { 28struct s5h1409_config {
@@ -66,8 +67,7 @@ struct s5h1409_config {
66 u8 hvr1600_opt; 67 u8 hvr1600_opt;
67}; 68};
68 69
69#if defined(CONFIG_DVB_S5H1409) || (defined(CONFIG_DVB_S5H1409_MODULE) \ 70#if IS_ENABLED(CONFIG_DVB_S5H1409)
70 && defined(MODULE))
71extern struct dvb_frontend *s5h1409_attach(const struct s5h1409_config *config, 71extern struct dvb_frontend *s5h1409_attach(const struct s5h1409_config *config,
72 struct i2c_adapter *i2c); 72 struct i2c_adapter *i2c);
73#else 73#else
diff --git a/drivers/media/dvb-frontends/s5h1411.h b/drivers/media/dvb-frontends/s5h1411.h
index 45ec0f82989c..e4f56871f982 100644
--- a/drivers/media/dvb-frontends/s5h1411.h
+++ b/drivers/media/dvb-frontends/s5h1411.h
@@ -22,6 +22,7 @@
22#ifndef __S5H1411_H__ 22#ifndef __S5H1411_H__
23#define __S5H1411_H__ 23#define __S5H1411_H__
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27#define S5H1411_I2C_TOP_ADDR (0x32 >> 1) 28#define S5H1411_I2C_TOP_ADDR (0x32 >> 1)
@@ -68,8 +69,7 @@ struct s5h1411_config {
68 u8 status_mode; 69 u8 status_mode;
69}; 70};
70 71
71#if defined(CONFIG_DVB_S5H1411) || \ 72#if IS_ENABLED(CONFIG_DVB_S5H1411)
72 (defined(CONFIG_DVB_S5H1411_MODULE) && defined(MODULE))
73extern struct dvb_frontend *s5h1411_attach(const struct s5h1411_config *config, 73extern struct dvb_frontend *s5h1411_attach(const struct s5h1411_config *config,
74 struct i2c_adapter *i2c); 74 struct i2c_adapter *i2c);
75#else 75#else
diff --git a/drivers/media/dvb-frontends/s5h1432.h b/drivers/media/dvb-frontends/s5h1432.h
index b57438c32546..70917dd2533a 100644
--- a/drivers/media/dvb-frontends/s5h1432.h
+++ b/drivers/media/dvb-frontends/s5h1432.h
@@ -22,6 +22,7 @@
22#ifndef __S5H1432_H__ 22#ifndef __S5H1432_H__
23#define __S5H1432_H__ 23#define __S5H1432_H__
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27#define S5H1432_I2C_TOP_ADDR (0x02 >> 1) 28#define S5H1432_I2C_TOP_ADDR (0x02 >> 1)
@@ -74,8 +75,7 @@ struct s5h1432_config {
74 u8 status_mode; 75 u8 status_mode;
75}; 76};
76 77
77#if defined(CONFIG_DVB_S5H1432) || \ 78#if IS_ENABLED(CONFIG_DVB_S5H1432)
78 (defined(CONFIG_DVB_S5H1432_MODULE) && defined(MODULE))
79extern struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config, 79extern struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config,
80 struct i2c_adapter *i2c); 80 struct i2c_adapter *i2c);
81#else 81#else
diff --git a/drivers/media/dvb-frontends/s921.h b/drivers/media/dvb-frontends/s921.h
index f220d8299c81..8d5e2a6e187c 100644
--- a/drivers/media/dvb-frontends/s921.h
+++ b/drivers/media/dvb-frontends/s921.h
@@ -17,6 +17,7 @@
17#ifndef S921_H 17#ifndef S921_H
18#define S921_H 18#define S921_H
19 19
20#include <linux/kconfig.h>
20#include <linux/dvb/frontend.h> 21#include <linux/dvb/frontend.h>
21 22
22struct s921_config { 23struct s921_config {
@@ -24,8 +25,7 @@ struct s921_config {
24 u8 demod_address; 25 u8 demod_address;
25}; 26};
26 27
27#if defined(CONFIG_DVB_S921) || (defined(CONFIG_DVB_S921_MODULE) \ 28#if IS_ENABLED(CONFIG_DVB_S921)
28 && defined(MODULE))
29extern struct dvb_frontend *s921_attach(const struct s921_config *config, 29extern struct dvb_frontend *s921_attach(const struct s921_config *config,
30 struct i2c_adapter *i2c); 30 struct i2c_adapter *i2c);
31extern struct i2c_adapter *s921_get_tuner_i2c_adapter(struct dvb_frontend *); 31extern struct i2c_adapter *s921_get_tuner_i2c_adapter(struct dvb_frontend *);
diff --git a/drivers/media/dvb-frontends/si21xx.h b/drivers/media/dvb-frontends/si21xx.h
index 141b5b8a5f63..1509fed44a3a 100644
--- a/drivers/media/dvb-frontends/si21xx.h
+++ b/drivers/media/dvb-frontends/si21xx.h
@@ -1,6 +1,7 @@
1#ifndef SI21XX_H 1#ifndef SI21XX_H
2#define SI21XX_H 2#define SI21XX_H
3 3
4#include <linux/kconfig.h>
4#include <linux/dvb/frontend.h> 5#include <linux/dvb/frontend.h>
5#include "dvb_frontend.h" 6#include "dvb_frontend.h"
6 7
@@ -12,8 +13,7 @@ struct si21xx_config {
12 int min_delay_ms; 13 int min_delay_ms;
13}; 14};
14 15
15#if defined(CONFIG_DVB_SI21XX) || \ 16#if IS_ENABLED(CONFIG_DVB_SI21XX)
16 (defined(CONFIG_DVB_SI21XX_MODULE) && defined(MODULE))
17extern struct dvb_frontend *si21xx_attach(const struct si21xx_config *config, 17extern struct dvb_frontend *si21xx_attach(const struct si21xx_config *config,
18 struct i2c_adapter *i2c); 18 struct i2c_adapter *i2c);
19#else 19#else
diff --git a/drivers/media/dvb-frontends/stb6000.h b/drivers/media/dvb-frontends/stb6000.h
index 7be479c22d5b..a768189bfaad 100644
--- a/drivers/media/dvb-frontends/stb6000.h
+++ b/drivers/media/dvb-frontends/stb6000.h
@@ -23,6 +23,7 @@
23#ifndef __DVB_STB6000_H__ 23#ifndef __DVB_STB6000_H__
24#define __DVB_STB6000_H__ 24#define __DVB_STB6000_H__
25 25
26#include <linux/kconfig.h>
26#include <linux/i2c.h> 27#include <linux/i2c.h>
27#include "dvb_frontend.h" 28#include "dvb_frontend.h"
28 29
@@ -34,8 +35,7 @@
34 * @param i2c i2c adapter to use. 35 * @param i2c i2c adapter to use.
35 * @return FE pointer on success, NULL on failure. 36 * @return FE pointer on success, NULL on failure.
36 */ 37 */
37#if defined(CONFIG_DVB_STB6000) || (defined(CONFIG_DVB_STB6000_MODULE) \ 38#if IS_ENABLED(CONFIG_DVB_STB6000)
38 && defined(MODULE))
39extern struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr, 39extern struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr,
40 struct i2c_adapter *i2c); 40 struct i2c_adapter *i2c);
41#else 41#else
diff --git a/drivers/media/dvb-frontends/stv0288.h b/drivers/media/dvb-frontends/stv0288.h
index f2b53db0606d..a0bd93107154 100644
--- a/drivers/media/dvb-frontends/stv0288.h
+++ b/drivers/media/dvb-frontends/stv0288.h
@@ -27,6 +27,7 @@
27#ifndef STV0288_H 27#ifndef STV0288_H
28#define STV0288_H 28#define STV0288_H
29 29
30#include <linux/kconfig.h>
30#include <linux/dvb/frontend.h> 31#include <linux/dvb/frontend.h>
31#include "dvb_frontend.h" 32#include "dvb_frontend.h"
32 33
@@ -42,8 +43,7 @@ struct stv0288_config {
42 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); 43 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
43}; 44};
44 45
45#if defined(CONFIG_DVB_STV0288) || (defined(CONFIG_DVB_STV0288_MODULE) && \ 46#if IS_ENABLED(CONFIG_DVB_STV0288)
46 defined(MODULE))
47extern struct dvb_frontend *stv0288_attach(const struct stv0288_config *config, 47extern struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
48 struct i2c_adapter *i2c); 48 struct i2c_adapter *i2c);
49#else 49#else
diff --git a/drivers/media/dvb-frontends/stv0367.h b/drivers/media/dvb-frontends/stv0367.h
index 93cc4a57eea0..ea80b341f094 100644
--- a/drivers/media/dvb-frontends/stv0367.h
+++ b/drivers/media/dvb-frontends/stv0367.h
@@ -26,6 +26,7 @@
26#ifndef STV0367_H 26#ifndef STV0367_H
27#define STV0367_H 27#define STV0367_H
28 28
29#include <linux/kconfig.h>
29#include <linux/dvb/frontend.h> 30#include <linux/dvb/frontend.h>
30#include "dvb_frontend.h" 31#include "dvb_frontend.h"
31 32
@@ -38,8 +39,7 @@ struct stv0367_config {
38 int clk_pol; 39 int clk_pol;
39}; 40};
40 41
41#if defined(CONFIG_DVB_STV0367) || (defined(CONFIG_DVB_STV0367_MODULE) \ 42#if IS_ENABLED(CONFIG_DVB_STV0367)
42 && defined(MODULE))
43extern struct 43extern struct
44dvb_frontend *stv0367ter_attach(const struct stv0367_config *config, 44dvb_frontend *stv0367ter_attach(const struct stv0367_config *config,
45 struct i2c_adapter *i2c); 45 struct i2c_adapter *i2c);
diff --git a/drivers/media/dvb-frontends/stv0900.h b/drivers/media/dvb-frontends/stv0900.h
index 91c7ee8b2313..e2a6dc69ecb4 100644
--- a/drivers/media/dvb-frontends/stv0900.h
+++ b/drivers/media/dvb-frontends/stv0900.h
@@ -26,6 +26,7 @@
26#ifndef STV0900_H 26#ifndef STV0900_H
27#define STV0900_H 27#define STV0900_H
28 28
29#include <linux/kconfig.h>
29#include <linux/dvb/frontend.h> 30#include <linux/dvb/frontend.h>
30#include "dvb_frontend.h" 31#include "dvb_frontend.h"
31 32
@@ -57,8 +58,7 @@ struct stv0900_config {
57 void (*set_lock_led)(struct dvb_frontend *fe, int offon); 58 void (*set_lock_led)(struct dvb_frontend *fe, int offon);
58}; 59};
59 60
60#if defined(CONFIG_DVB_STV0900) || (defined(CONFIG_DVB_STV0900_MODULE) \ 61#if IS_ENABLED(CONFIG_DVB_STV0900)
61 && defined(MODULE))
62extern struct dvb_frontend *stv0900_attach(const struct stv0900_config *config, 62extern struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
63 struct i2c_adapter *i2c, int demod); 63 struct i2c_adapter *i2c, int demod);
64#else 64#else
diff --git a/drivers/media/dvb-frontends/stv090x.c b/drivers/media/dvb-frontends/stv090x.c
index f36eeefb76a6..56d470ad5a82 100644
--- a/drivers/media/dvb-frontends/stv090x.c
+++ b/drivers/media/dvb-frontends/stv090x.c
@@ -3906,12 +3906,12 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3906 reg = stv090x_read_reg(state, STV090x_TSTTNR1); 3906 reg = stv090x_read_reg(state, STV090x_TSTTNR1);
3907 STV090x_SETFIELD(reg, ADC1_PON_FIELD, 0); 3907 STV090x_SETFIELD(reg, ADC1_PON_FIELD, 0);
3908 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) 3908 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0)
3909 goto err; 3909 goto err_unlock;
3910 /* power off DiSEqC 1 */ 3910 /* power off DiSEqC 1 */
3911 reg = stv090x_read_reg(state, STV090x_TSTTNR2); 3911 reg = stv090x_read_reg(state, STV090x_TSTTNR2);
3912 STV090x_SETFIELD(reg, DISEQC1_PON_FIELD, 0); 3912 STV090x_SETFIELD(reg, DISEQC1_PON_FIELD, 0);
3913 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0) 3913 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0)
3914 goto err; 3914 goto err_unlock;
3915 3915
3916 /* check whether path 2 is already sleeping, that is when 3916 /* check whether path 2 is already sleeping, that is when
3917 ADC2 is off */ 3917 ADC2 is off */
@@ -3930,7 +3930,7 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3930 if (full_standby) 3930 if (full_standby)
3931 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 1); 3931 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 1);
3932 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) 3932 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0)
3933 goto err; 3933 goto err_unlock;
3934 reg = stv090x_read_reg(state, STV090x_STOPCLK2); 3934 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
3935 /* sampling 1 clock */ 3935 /* sampling 1 clock */
3936 STV090x_SETFIELD(reg, STOP_CLKSAMP1_FIELD, 1); 3936 STV090x_SETFIELD(reg, STOP_CLKSAMP1_FIELD, 1);
@@ -3941,7 +3941,7 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3941 if (full_standby) 3941 if (full_standby)
3942 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 1); 3942 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 1);
3943 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) 3943 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
3944 goto err; 3944 goto err_unlock;
3945 break; 3945 break;
3946 3946
3947 case STV090x_DEMODULATOR_1: 3947 case STV090x_DEMODULATOR_1:
@@ -3949,12 +3949,12 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3949 reg = stv090x_read_reg(state, STV090x_TSTTNR3); 3949 reg = stv090x_read_reg(state, STV090x_TSTTNR3);
3950 STV090x_SETFIELD(reg, ADC2_PON_FIELD, 0); 3950 STV090x_SETFIELD(reg, ADC2_PON_FIELD, 0);
3951 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) 3951 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0)
3952 goto err; 3952 goto err_unlock;
3953 /* power off DiSEqC 2 */ 3953 /* power off DiSEqC 2 */
3954 reg = stv090x_read_reg(state, STV090x_TSTTNR4); 3954 reg = stv090x_read_reg(state, STV090x_TSTTNR4);
3955 STV090x_SETFIELD(reg, DISEQC2_PON_FIELD, 0); 3955 STV090x_SETFIELD(reg, DISEQC2_PON_FIELD, 0);
3956 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0) 3956 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0)
3957 goto err; 3957 goto err_unlock;
3958 3958
3959 /* check whether path 1 is already sleeping, that is when 3959 /* check whether path 1 is already sleeping, that is when
3960 ADC1 is off */ 3960 ADC1 is off */
@@ -3973,7 +3973,7 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3973 if (full_standby) 3973 if (full_standby)
3974 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 1); 3974 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 1);
3975 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) 3975 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0)
3976 goto err; 3976 goto err_unlock;
3977 reg = stv090x_read_reg(state, STV090x_STOPCLK2); 3977 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
3978 /* sampling 2 clock */ 3978 /* sampling 2 clock */
3979 STV090x_SETFIELD(reg, STOP_CLKSAMP2_FIELD, 1); 3979 STV090x_SETFIELD(reg, STOP_CLKSAMP2_FIELD, 1);
@@ -3984,7 +3984,7 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3984 if (full_standby) 3984 if (full_standby)
3985 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 1); 3985 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 1);
3986 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) 3986 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
3987 goto err; 3987 goto err_unlock;
3988 break; 3988 break;
3989 3989
3990 default: 3990 default:
@@ -3997,7 +3997,7 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3997 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); 3997 reg = stv090x_read_reg(state, STV090x_SYNTCTRL);
3998 STV090x_SETFIELD(reg, STANDBY_FIELD, 0x01); 3998 STV090x_SETFIELD(reg, STANDBY_FIELD, 0x01);
3999 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0) 3999 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0)
4000 goto err; 4000 goto err_unlock;
4001 } 4001 }
4002 4002
4003 mutex_unlock(&state->internal->demod_lock); 4003 mutex_unlock(&state->internal->demod_lock);
@@ -4005,8 +4005,10 @@ static int stv090x_sleep(struct dvb_frontend *fe)
4005 4005
4006err_gateoff: 4006err_gateoff:
4007 stv090x_i2c_gate_ctrl(state, 0); 4007 stv090x_i2c_gate_ctrl(state, 0);
4008err: 4008 goto err;
4009err_unlock:
4009 mutex_unlock(&state->internal->demod_lock); 4010 mutex_unlock(&state->internal->demod_lock);
4011err:
4010 dprintk(FE_ERROR, 1, "I/O error"); 4012 dprintk(FE_ERROR, 1, "I/O error");
4011 return -1; 4013 return -1;
4012} 4014}
diff --git a/drivers/media/dvb-frontends/stv6110.h b/drivers/media/dvb-frontends/stv6110.h
index fe71bba6a26e..8fa07e6a6745 100644
--- a/drivers/media/dvb-frontends/stv6110.h
+++ b/drivers/media/dvb-frontends/stv6110.h
@@ -25,6 +25,7 @@
25#ifndef __DVB_STV6110_H__ 25#ifndef __DVB_STV6110_H__
26#define __DVB_STV6110_H__ 26#define __DVB_STV6110_H__
27 27
28#include <linux/kconfig.h>
28#include <linux/i2c.h> 29#include <linux/i2c.h>
29#include "dvb_frontend.h" 30#include "dvb_frontend.h"
30 31
@@ -45,8 +46,7 @@ struct stv6110_config {
45 u8 clk_div; /* divisor value for the output clock */ 46 u8 clk_div; /* divisor value for the output clock */
46}; 47};
47 48
48#if defined(CONFIG_DVB_STV6110) || (defined(CONFIG_DVB_STV6110_MODULE) \ 49#if IS_ENABLED(CONFIG_DVB_STV6110)
49 && defined(MODULE))
50extern struct dvb_frontend *stv6110_attach(struct dvb_frontend *fe, 50extern struct dvb_frontend *stv6110_attach(struct dvb_frontend *fe,
51 const struct stv6110_config *config, 51 const struct stv6110_config *config,
52 struct i2c_adapter *i2c); 52 struct i2c_adapter *i2c);
diff --git a/drivers/media/dvb-frontends/tda10048.h b/drivers/media/dvb-frontends/tda10048.h
index fb2ef5ac9487..5e7bf4e47cb3 100644
--- a/drivers/media/dvb-frontends/tda10048.h
+++ b/drivers/media/dvb-frontends/tda10048.h
@@ -22,6 +22,7 @@
22#ifndef TDA10048_H 22#ifndef TDA10048_H
23#define TDA10048_H 23#define TDA10048_H
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26#include <linux/firmware.h> 27#include <linux/firmware.h>
27 28
@@ -72,8 +73,7 @@ struct tda10048_config {
72 u8 pll_n; 73 u8 pll_n;
73}; 74};
74 75
75#if defined(CONFIG_DVB_TDA10048) || \ 76#if IS_ENABLED(CONFIG_DVB_TDA10048)
76 (defined(CONFIG_DVB_TDA10048_MODULE) && defined(MODULE))
77extern struct dvb_frontend *tda10048_attach( 77extern struct dvb_frontend *tda10048_attach(
78 const struct tda10048_config *config, 78 const struct tda10048_config *config,
79 struct i2c_adapter *i2c); 79 struct i2c_adapter *i2c);
diff --git a/drivers/media/dvb-frontends/tda10071.h b/drivers/media/dvb-frontends/tda10071.h
index bff1c38df802..f9542f68fe78 100644
--- a/drivers/media/dvb-frontends/tda10071.h
+++ b/drivers/media/dvb-frontends/tda10071.h
@@ -21,6 +21,7 @@
21#ifndef TDA10071_H 21#ifndef TDA10071_H
22#define TDA10071_H 22#define TDA10071_H
23 23
24#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
25 26
26struct tda10071_config { 27struct tda10071_config {
@@ -71,8 +72,7 @@ struct tda10071_config {
71}; 72};
72 73
73 74
74#if defined(CONFIG_DVB_TDA10071) || \ 75#if IS_ENABLED(CONFIG_DVB_TDA10071)
75 (defined(CONFIG_DVB_TDA10071_MODULE) && defined(MODULE))
76extern struct dvb_frontend *tda10071_attach( 76extern struct dvb_frontend *tda10071_attach(
77 const struct tda10071_config *config, struct i2c_adapter *i2c); 77 const struct tda10071_config *config, struct i2c_adapter *i2c);
78#else 78#else
diff --git a/drivers/media/dvb-frontends/tda18271c2dd.h b/drivers/media/dvb-frontends/tda18271c2dd.h
index 1389c74e12ce..dd84f7b69bec 100644
--- a/drivers/media/dvb-frontends/tda18271c2dd.h
+++ b/drivers/media/dvb-frontends/tda18271c2dd.h
@@ -1,7 +1,9 @@
1#ifndef _TDA18271C2DD_H_ 1#ifndef _TDA18271C2DD_H_
2#define _TDA18271C2DD_H_ 2#define _TDA18271C2DD_H_
3#if defined(CONFIG_DVB_TDA18271C2DD) || (defined(CONFIG_DVB_TDA18271C2DD_MODULE) \ 3
4 && defined(MODULE)) 4#include <linux/kconfig.h>
5
6#if IS_ENABLED(CONFIG_DVB_TDA18271C2DD)
5struct dvb_frontend *tda18271c2dd_attach(struct dvb_frontend *fe, 7struct dvb_frontend *tda18271c2dd_attach(struct dvb_frontend *fe,
6 struct i2c_adapter *i2c, u8 adr); 8 struct i2c_adapter *i2c, u8 adr);
7#else 9#else
diff --git a/drivers/media/dvb-frontends/ts2020.h b/drivers/media/dvb-frontends/ts2020.h
index c7e64afa614a..5bcb9a71ca80 100644
--- a/drivers/media/dvb-frontends/ts2020.h
+++ b/drivers/media/dvb-frontends/ts2020.h
@@ -22,6 +22,7 @@
22#ifndef TS2020_H 22#ifndef TS2020_H
23#define TS2020_H 23#define TS2020_H
24 24
25#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
26 27
27struct ts2020_config { 28struct ts2020_config {
@@ -29,8 +30,7 @@ struct ts2020_config {
29 u8 clk_out_div; 30 u8 clk_out_div;
30}; 31};
31 32
32#if defined(CONFIG_DVB_TS2020) || \ 33#if IS_ENABLED(CONFIG_DVB_TS2020)
33 (defined(CONFIG_DVB_TS2020_MODULE) && defined(MODULE))
34 34
35extern struct dvb_frontend *ts2020_attach( 35extern struct dvb_frontend *ts2020_attach(
36 struct dvb_frontend *fe, 36 struct dvb_frontend *fe,
diff --git a/drivers/media/dvb-frontends/zl10036.h b/drivers/media/dvb-frontends/zl10036.h
index d84b8f8215e9..5f1e8217eeb6 100644
--- a/drivers/media/dvb-frontends/zl10036.h
+++ b/drivers/media/dvb-frontends/zl10036.h
@@ -21,6 +21,7 @@
21#ifndef DVB_ZL10036_H 21#ifndef DVB_ZL10036_H
22#define DVB_ZL10036_H 22#define DVB_ZL10036_H
23 23
24#include <linux/kconfig.h>
24#include <linux/i2c.h> 25#include <linux/i2c.h>
25#include "dvb_frontend.h" 26#include "dvb_frontend.h"
26 27
@@ -37,8 +38,7 @@ struct zl10036_config {
37 int rf_loop_enable; 38 int rf_loop_enable;
38}; 39};
39 40
40#if defined(CONFIG_DVB_ZL10036) || \ 41#if IS_ENABLED(CONFIG_DVB_ZL10036)
41 (defined(CONFIG_DVB_ZL10036_MODULE) && defined(MODULE))
42extern struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe, 42extern struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
43 const struct zl10036_config *config, struct i2c_adapter *i2c); 43 const struct zl10036_config *config, struct i2c_adapter *i2c);
44#else 44#else
diff --git a/drivers/media/dvb-frontends/zl10039.h b/drivers/media/dvb-frontends/zl10039.h
index 5eee7ea162a1..750b9bca9d02 100644
--- a/drivers/media/dvb-frontends/zl10039.h
+++ b/drivers/media/dvb-frontends/zl10039.h
@@ -22,8 +22,9 @@
22#ifndef ZL10039_H 22#ifndef ZL10039_H
23#define ZL10039_H 23#define ZL10039_H
24 24
25#if defined(CONFIG_DVB_ZL10039) || (defined(CONFIG_DVB_ZL10039_MODULE) \ 25#include <linux/kconfig.h>
26 && defined(MODULE)) 26
27#if IS_ENABLED(CONFIG_DVB_ZL10039)
27struct dvb_frontend *zl10039_attach(struct dvb_frontend *fe, 28struct dvb_frontend *zl10039_attach(struct dvb_frontend *fe,
28 u8 i2c_addr, 29 u8 i2c_addr,
29 struct i2c_adapter *i2c); 30 struct i2c_adapter *i2c);
diff --git a/drivers/media/firewire/firedtv-dvb.c b/drivers/media/firewire/firedtv-dvb.c
index eb7496eab130..f710e17953e3 100644
--- a/drivers/media/firewire/firedtv-dvb.c
+++ b/drivers/media/firewire/firedtv-dvb.c
@@ -71,11 +71,11 @@ int fdtv_start_feed(struct dvb_demux_feed *dvbdmxfeed)
71 71
72 if (dvbdmxfeed->type == DMX_TYPE_TS) { 72 if (dvbdmxfeed->type == DMX_TYPE_TS) {
73 switch (dvbdmxfeed->pes_type) { 73 switch (dvbdmxfeed->pes_type) {
74 case DMX_TS_PES_VIDEO: 74 case DMX_PES_VIDEO:
75 case DMX_TS_PES_AUDIO: 75 case DMX_PES_AUDIO:
76 case DMX_TS_PES_TELETEXT: 76 case DMX_PES_TELETEXT:
77 case DMX_TS_PES_PCR: 77 case DMX_PES_PCR:
78 case DMX_TS_PES_OTHER: 78 case DMX_PES_OTHER:
79 c = alloc_channel(fdtv); 79 c = alloc_channel(fdtv);
80 break; 80 break;
81 default: 81 default:
@@ -132,7 +132,7 @@ int fdtv_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
132 (demux->dmx.frontend->source != DMX_MEMORY_FE))) { 132 (demux->dmx.frontend->source != DMX_MEMORY_FE))) {
133 133
134 if (dvbdmxfeed->ts_type & TS_DECODER) { 134 if (dvbdmxfeed->ts_type & TS_DECODER) {
135 if (dvbdmxfeed->pes_type >= DMX_TS_PES_OTHER || 135 if (dvbdmxfeed->pes_type >= DMX_PES_OTHER ||
136 !demux->pesfilter[dvbdmxfeed->pes_type]) 136 !demux->pesfilter[dvbdmxfeed->pes_type])
137 return -EINVAL; 137 return -EINVAL;
138 138
@@ -141,7 +141,7 @@ int fdtv_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
141 } 141 }
142 142
143 if (!(dvbdmxfeed->ts_type & TS_DECODER && 143 if (!(dvbdmxfeed->ts_type & TS_DECODER &&
144 dvbdmxfeed->pes_type < DMX_TS_PES_OTHER)) 144 dvbdmxfeed->pes_type < DMX_PES_OTHER))
145 return 0; 145 return 0;
146 } 146 }
147 147
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 7b771baa2212..f981d50a2a8c 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -112,6 +112,15 @@ config VIDEO_TLV320AIC23B
112 To compile this driver as a module, choose M here: the 112 To compile this driver as a module, choose M here: the
113 module will be called tlv320aic23b. 113 module will be called tlv320aic23b.
114 114
115config VIDEO_UDA1342
116 tristate "Philips UDA1342 audio codec"
117 depends on VIDEO_V4L2 && I2C
118 ---help---
119 Support for the Philips UDA1342 audio codec.
120
121 To compile this driver as a module, choose M here: the
122 module will be called uda1342.
123
115config VIDEO_WM8775 124config VIDEO_WM8775
116 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer" 125 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer"
117 depends on VIDEO_V4L2 && I2C 126 depends on VIDEO_V4L2 && I2C
@@ -133,7 +142,7 @@ config VIDEO_WM8739
133 module will be called wm8739. 142 module will be called wm8739.
134 143
135config VIDEO_VP27SMPX 144config VIDEO_VP27SMPX
136 tristate "Panasonic VP27s internal MPX" 145 tristate "Panasonic VP27's internal MPX"
137 depends on VIDEO_V4L2 && I2C 146 depends on VIDEO_V4L2 && I2C
138 ---help--- 147 ---help---
139 Support for the internal MPX of the Panasonic VP27s tuner. 148 Support for the internal MPX of the Panasonic VP27s tuner.
@@ -141,6 +150,15 @@ config VIDEO_VP27SMPX
141 To compile this driver as a module, choose M here: the 150 To compile this driver as a module, choose M here: the
142 module will be called vp27smpx. 151 module will be called vp27smpx.
143 152
153config VIDEO_SONY_BTF_MPX
154 tristate "Sony BTF's internal MPX"
155 depends on VIDEO_V4L2 && I2C
156 help
157 Support for the internal MPX of the Sony BTF-PG472Z tuner.
158
159 To compile this driver as a module, choose M here: the
160 module will be called sony-btf-mpx.
161
144comment "RDS decoders" 162comment "RDS decoders"
145 163
146config VIDEO_SAA6588 164config VIDEO_SAA6588
@@ -283,6 +301,35 @@ config VIDEO_TVP7002
283 To compile this driver as a module, choose M here: the 301 To compile this driver as a module, choose M here: the
284 module will be called tvp7002. 302 module will be called tvp7002.
285 303
304config VIDEO_TW2804
305 tristate "Techwell TW2804 multiple video decoder"
306 depends on VIDEO_V4L2 && I2C
307 ---help---
308 Support for the Techwell tw2804 multiple video decoder.
309
310 To compile this driver as a module, choose M here: the
311 module will be called tw2804.
312
313config VIDEO_TW9903
314 tristate "Techwell TW9903 video decoder"
315 depends on VIDEO_V4L2 && I2C
316 ---help---
317 Support for the Techwell tw9903 multi-standard video decoder
318 with high quality down scaler.
319
320 To compile this driver as a module, choose M here: the
321 module will be called tw9903.
322
323config VIDEO_TW9906
324 tristate "Techwell TW9906 video decoder"
325 depends on VIDEO_V4L2 && I2C
326 ---help---
327 Support for the Techwell tw9906 enhanced multi-standard comb filter
328 video decoder with YCbCr input support.
329
330 To compile this driver as a module, choose M here: the
331 module will be called tw9906.
332
286config VIDEO_VPX3220 333config VIDEO_VPX3220
287 tristate "vpx3220a, vpx3216b & vpx3214c video decoders" 334 tristate "vpx3220a, vpx3216b & vpx3214c video decoders"
288 depends on VIDEO_V4L2 && I2C 335 depends on VIDEO_V4L2 && I2C
@@ -386,6 +433,17 @@ config VIDEO_APTINA_PLL
386config VIDEO_SMIAPP_PLL 433config VIDEO_SMIAPP_PLL
387 tristate 434 tristate
388 435
436config VIDEO_OV7640
437 tristate "OmniVision OV7640 sensor support"
438 depends on I2C && VIDEO_V4L2
439 depends on MEDIA_CAMERA_SUPPORT
440 ---help---
441 This is a Video4Linux2 sensor-level driver for the OmniVision
442 OV7640 camera.
443
444 To compile this driver as a module, choose M here: the
445 module will be called ov7640.
446
389config VIDEO_OV7670 447config VIDEO_OV7670
390 tristate "OmniVision OV7670 sensor support" 448 tristate "OmniVision OV7670 sensor support"
391 depends on I2C && VIDEO_V4L2 449 depends on I2C && VIDEO_V4L2
@@ -501,8 +559,8 @@ config VIDEO_S5C73M3
501 tristate "Samsung S5C73M3 sensor support" 559 tristate "Samsung S5C73M3 sensor support"
502 depends on I2C && SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API 560 depends on I2C && SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
503 ---help--- 561 ---help---
504 This is a V4L2 sensor-level driver for Samsung S5C73M3 562 This is a V4L2 sensor-level driver for Samsung S5C73M3
505 8 Mpixel camera. 563 8 Mpixel camera.
506 564
507comment "Flash devices" 565comment "Flash devices"
508 566
@@ -550,10 +608,10 @@ config VIDEO_UPD64083
550comment "Miscelaneous helper chips" 608comment "Miscelaneous helper chips"
551 609
552config VIDEO_THS7303 610config VIDEO_THS7303
553 tristate "THS7303 Video Amplifier" 611 tristate "THS7303/53 Video Amplifier"
554 depends on I2C 612 depends on VIDEO_V4L2 && I2C
555 help 613 help
556 Support for TI THS7303 video amplifier 614 Support for TI THS7303/53 video amplifier
557 615
558 To compile this driver as a module, choose M here: the 616 To compile this driver as a module, choose M here: the
559 module will be called ths7303. 617 module will be called ths7303.
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index cfefd30cc1bc..720f42d9d9f4 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -37,16 +37,22 @@ obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
37obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 37obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
38obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o 38obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o
39obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o 39obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o
40obj-$(CONFIG_VIDEO_TW2804) += tw2804.o
41obj-$(CONFIG_VIDEO_TW9903) += tw9903.o
42obj-$(CONFIG_VIDEO_TW9906) += tw9906.o
40obj-$(CONFIG_VIDEO_CS5345) += cs5345.o 43obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
41obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 44obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
42obj-$(CONFIG_VIDEO_M52790) += m52790.o 45obj-$(CONFIG_VIDEO_M52790) += m52790.o
43obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o 46obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o
47obj-$(CONFIG_VIDEO_UDA1342) += uda1342.o
44obj-$(CONFIG_VIDEO_WM8775) += wm8775.o 48obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
45obj-$(CONFIG_VIDEO_WM8739) += wm8739.o 49obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
46obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o 50obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
51obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o
47obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o 52obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
48obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o 53obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
49obj-$(CONFIG_VIDEO_OV7670) += ov7670.o 54obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
55obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
50obj-$(CONFIG_VIDEO_OV9650) += ov9650.o 56obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
51obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o 57obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
52obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o 58obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
index c2886b6a727d..58344b6c3a55 100644
--- a/drivers/media/i2c/ad9389b.c
+++ b/drivers/media/i2c/ad9389b.c
@@ -354,7 +354,7 @@ static int ad9389b_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
354 return 0; 354 return 0;
355} 355}
356 356
357static int ad9389b_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 357static int ad9389b_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
358{ 358{
359 struct i2c_client *client = v4l2_get_subdevdata(sd); 359 struct i2c_client *client = v4l2_get_subdevdata(sd);
360 360
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
index df163800c8e1..ef75abe5984c 100644
--- a/drivers/media/i2c/adp1653.c
+++ b/drivers/media/i2c/adp1653.c
@@ -447,7 +447,7 @@ free_and_quit:
447 return ret; 447 return ret;
448} 448}
449 449
450static int __exit adp1653_remove(struct i2c_client *client) 450static int adp1653_remove(struct i2c_client *client)
451{ 451{
452 struct v4l2_subdev *subdev = i2c_get_clientdata(client); 452 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
453 struct adp1653_flash *flash = to_adp1653_flash(subdev); 453 struct adp1653_flash *flash = to_adp1653_flash(subdev);
@@ -476,7 +476,7 @@ static struct i2c_driver adp1653_i2c_driver = {
476 .pm = &adp1653_pm_ops, 476 .pm = &adp1653_pm_ops,
477 }, 477 },
478 .probe = adp1653_probe, 478 .probe = adp1653_probe,
479 .remove = __exit_p(adp1653_remove), 479 .remove = adp1653_remove,
480 .id_table = adp1653_id_table, 480 .id_table = adp1653_id_table,
481}; 481};
482 482
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 34f39d3b3e3e..afd561ab190d 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -135,6 +135,10 @@ struct adv7180_state {
135 135
136static v4l2_std_id adv7180_std_to_v4l2(u8 status1) 136static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
137{ 137{
138 /* in case V4L2_IN_ST_NO_SIGNAL */
139 if (!(status1 & ADV7180_STATUS1_IN_LOCK))
140 return V4L2_STD_UNKNOWN;
141
138 switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { 142 switch (status1 & ADV7180_STATUS1_AUTOD_MASK) {
139 case ADV7180_STATUS1_AUTOD_NTSM_M_J: 143 case ADV7180_STATUS1_AUTOD_NTSM_M_J:
140 return V4L2_STD_NTSC; 144 return V4L2_STD_NTSC;
diff --git a/drivers/media/i2c/adv7183.c b/drivers/media/i2c/adv7183.c
index 6fed5b74e743..56a1fa4af0fe 100644
--- a/drivers/media/i2c/adv7183.c
+++ b/drivers/media/i2c/adv7183.c
@@ -507,7 +507,7 @@ static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
507 return 0; 507 return 0;
508} 508}
509 509
510static int adv7183_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 510static int adv7183_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
511{ 511{
512 struct i2c_client *client = v4l2_get_subdevdata(sd); 512 struct i2c_client *client = v4l2_get_subdevdata(sd);
513 513
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index f47555b1000a..31a63c9324fe 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -699,7 +699,7 @@ static int adv7604_g_register(struct v4l2_subdev *sd,
699} 699}
700 700
701static int adv7604_s_register(struct v4l2_subdev *sd, 701static int adv7604_s_register(struct v4l2_subdev *sd,
702 struct v4l2_dbg_register *reg) 702 const struct v4l2_dbg_register *reg)
703{ 703{
704 struct i2c_client *client = v4l2_get_subdevdata(sd); 704 struct i2c_client *client = v4l2_get_subdevdata(sd);
705 705
diff --git a/drivers/media/i2c/ak881x.c b/drivers/media/i2c/ak881x.c
index ba674656b10d..fd47465e4f6a 100644
--- a/drivers/media/i2c/ak881x.c
+++ b/drivers/media/i2c/ak881x.c
@@ -101,7 +101,7 @@ static int ak881x_g_register(struct v4l2_subdev *sd,
101} 101}
102 102
103static int ak881x_s_register(struct v4l2_subdev *sd, 103static int ak881x_s_register(struct v4l2_subdev *sd,
104 struct v4l2_dbg_register *reg) 104 const struct v4l2_dbg_register *reg)
105{ 105{
106 struct i2c_client *client = v4l2_get_subdevdata(sd); 106 struct i2c_client *client = v4l2_get_subdevdata(sd);
107 107
diff --git a/drivers/media/i2c/cs5345.c b/drivers/media/i2c/cs5345.c
index c8581e26fa9c..1d2f7c8512b5 100644
--- a/drivers/media/i2c/cs5345.c
+++ b/drivers/media/i2c/cs5345.c
@@ -110,7 +110,7 @@ static int cs5345_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
110 return 0; 110 return 0;
111} 111}
112 112
113static int cs5345_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 113static int cs5345_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
114{ 114{
115 struct i2c_client *client = v4l2_get_subdevdata(sd); 115 struct i2c_client *client = v4l2_get_subdevdata(sd);
116 116
diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c
index f4149eb4d7b4..12fb9b2eb887 100644
--- a/drivers/media/i2c/cx25840/cx25840-core.c
+++ b/drivers/media/i2c/cx25840/cx25840-core.c
@@ -1671,7 +1671,7 @@ static int cx25840_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1671 return 0; 1671 return 0;
1672} 1672}
1673 1673
1674static int cx25840_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1674static int cx25840_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1675{ 1675{
1676 struct i2c_client *client = v4l2_get_subdevdata(sd); 1676 struct i2c_client *client = v4l2_get_subdevdata(sd);
1677 1677
@@ -1835,7 +1835,7 @@ static int cx25840_s_audio_routing(struct v4l2_subdev *sd,
1835 return set_input(client, state->vid_input, input); 1835 return set_input(client, state->vid_input, input);
1836} 1836}
1837 1837
1838static int cx25840_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 1838static int cx25840_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
1839{ 1839{
1840 struct i2c_client *client = v4l2_get_subdevdata(sd); 1840 struct i2c_client *client = v4l2_get_subdevdata(sd);
1841 1841
@@ -1881,7 +1881,7 @@ static int cx25840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1881 return 0; 1881 return 0;
1882} 1882}
1883 1883
1884static int cx25840_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1884static int cx25840_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1885{ 1885{
1886 struct cx25840_state *state = to_state(sd); 1886 struct cx25840_state *state = to_state(sd);
1887 struct i2c_client *client = v4l2_get_subdevdata(sd); 1887 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 08ae067b2b6f..8e2f79cb045e 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -230,7 +230,7 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
230 return 0; 230 return 0;
231 231
232 dprintk(1, "read key 0x%02x/0x%02x\n", key, keygroup); 232 dprintk(1, "read key 0x%02x/0x%02x\n", key, keygroup);
233 if (keygroup < 2 || keygroup > 3) { 233 if (keygroup < 2 || keygroup > 4) {
234 /* Only a warning */ 234 /* Only a warning */
235 dprintk(1, "warning: invalid key group 0x%02x for key 0x%02x\n", 235 dprintk(1, "warning: invalid key group 0x%02x for key 0x%02x\n",
236 keygroup, key); 236 keygroup, key);
@@ -239,6 +239,10 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
239 239
240 *ir_key = key; 240 *ir_key = key;
241 *ir_raw = key; 241 *ir_raw = key;
242 if (!strcmp(ir->ir_codes, RC_MAP_AVERMEDIA_M733A_RM_K6)) {
243 *ir_key |= keygroup << 8;
244 *ir_raw |= keygroup << 8;
245 }
242 return 1; 246 return 1;
243} 247}
244 248
@@ -332,6 +336,13 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
332 rc_type = RC_BIT_OTHER; 336 rc_type = RC_BIT_OTHER;
333 ir_codes = RC_MAP_AVERMEDIA_CARDBUS; 337 ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
334 break; 338 break;
339 case 0x41:
340 name = "AVerMedia EM78P153";
341 ir->get_key = get_key_avermedia_cardbus;
342 rc_type = RC_BIT_OTHER;
343 /* RM-KV remote, seems to be same as RM-K6 */
344 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
345 break;
335 case 0x71: 346 case 0x71:
336 name = "Hauppauge/Zilog Z8"; 347 name = "Hauppauge/Zilog Z8";
337 ir->get_key = get_key_haup_xvr; 348 ir->get_key = get_key_haup_xvr;
@@ -423,6 +434,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
423 */ 434 */
424 rc->map_name = ir->ir_codes; 435 rc->map_name = ir->ir_codes;
425 rc->allowed_protos = rc_type; 436 rc->allowed_protos = rc_type;
437 rc->enabled_protocols = rc_type;
426 if (!rc->driver_name) 438 if (!rc->driver_name)
427 rc->driver_name = MODULE_NAME; 439 rc->driver_name = MODULE_NAME;
428 440
diff --git a/drivers/media/i2c/m52790.c b/drivers/media/i2c/m52790.c
index 0991576f4c82..39f50fd2b8d2 100644
--- a/drivers/media/i2c/m52790.c
+++ b/drivers/media/i2c/m52790.c
@@ -96,7 +96,7 @@ static int m52790_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
96 return 0; 96 return 0;
97} 97}
98 98
99static int m52790_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 99static int m52790_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
100{ 100{
101 struct m52790_state *state = to_state(sd); 101 struct m52790_state *state = to_state(sd);
102 struct i2c_client *client = v4l2_get_subdevdata(sd); 102 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/i2c/msp3400-driver.c b/drivers/media/i2c/msp3400-driver.c
index 766305f69a28..54a9dd394f45 100644
--- a/drivers/media/i2c/msp3400-driver.c
+++ b/drivers/media/i2c/msp3400-driver.c
@@ -445,7 +445,7 @@ static int msp_s_radio(struct v4l2_subdev *sd)
445 return 0; 445 return 0;
446} 446}
447 447
448static int msp_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 448static int msp_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
449{ 449{
450 struct i2c_client *client = v4l2_get_subdevdata(sd); 450 struct i2c_client *client = v4l2_get_subdevdata(sd);
451 451
@@ -535,7 +535,7 @@ static int msp_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
535 return 0; 535 return 0;
536} 536}
537 537
538static int msp_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 538static int msp_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
539{ 539{
540 struct msp_state *state = to_state(sd); 540 struct msp_state *state = to_state(sd);
541 struct i2c_client *client = v4l2_get_subdevdata(sd); 541 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/i2c/mt9m032.c b/drivers/media/i2c/mt9m032.c
index f80c1d7ec884..8edb3d8f7b90 100644
--- a/drivers/media/i2c/mt9m032.c
+++ b/drivers/media/i2c/mt9m032.c
@@ -87,9 +87,27 @@
87#define MT9M032_RESTART 0x0b 87#define MT9M032_RESTART 0x0b
88#define MT9M032_RESET 0x0d 88#define MT9M032_RESET 0x0d
89#define MT9M032_PLL_CONFIG1 0x11 89#define MT9M032_PLL_CONFIG1 0x11
90#define MT9M032_PLL_CONFIG1_OUTDIV_MASK 0x3f 90#define MT9M032_PLL_CONFIG1_PREDIV_MASK 0x3f
91#define MT9M032_PLL_CONFIG1_MUL_SHIFT 8 91#define MT9M032_PLL_CONFIG1_MUL_SHIFT 8
92#define MT9M032_READ_MODE1 0x1e 92#define MT9M032_READ_MODE1 0x1e
93#define MT9M032_READ_MODE1_OUTPUT_BAD_FRAMES (1 << 13)
94#define MT9M032_READ_MODE1_MAINTAIN_FRAME_RATE (1 << 12)
95#define MT9M032_READ_MODE1_XOR_LINE_VALID (1 << 11)
96#define MT9M032_READ_MODE1_CONT_LINE_VALID (1 << 10)
97#define MT9M032_READ_MODE1_INVERT_TRIGGER (1 << 9)
98#define MT9M032_READ_MODE1_SNAPSHOT (1 << 8)
99#define MT9M032_READ_MODE1_GLOBAL_RESET (1 << 7)
100#define MT9M032_READ_MODE1_BULB_EXPOSURE (1 << 6)
101#define MT9M032_READ_MODE1_INVERT_STROBE (1 << 5)
102#define MT9M032_READ_MODE1_STROBE_ENABLE (1 << 4)
103#define MT9M032_READ_MODE1_STROBE_START_TRIG1 (0 << 2)
104#define MT9M032_READ_MODE1_STROBE_START_EXP (1 << 2)
105#define MT9M032_READ_MODE1_STROBE_START_SHUTTER (2 << 2)
106#define MT9M032_READ_MODE1_STROBE_START_TRIG2 (3 << 2)
107#define MT9M032_READ_MODE1_STROBE_END_TRIG1 (0 << 0)
108#define MT9M032_READ_MODE1_STROBE_END_EXP (1 << 0)
109#define MT9M032_READ_MODE1_STROBE_END_SHUTTER (2 << 0)
110#define MT9M032_READ_MODE1_STROBE_END_TRIG2 (3 << 0)
93#define MT9M032_READ_MODE2 0x20 111#define MT9M032_READ_MODE2 0x20
94#define MT9M032_READ_MODE2_VFLIP_SHIFT 15 112#define MT9M032_READ_MODE2_VFLIP_SHIFT 15
95#define MT9M032_READ_MODE2_HFLIP_SHIFT 14 113#define MT9M032_READ_MODE2_HFLIP_SHIFT 14
@@ -106,6 +124,8 @@
106#define MT9M032_GAIN_AMUL_SHIFT 6 124#define MT9M032_GAIN_AMUL_SHIFT 6
107#define MT9M032_GAIN_ANALOG_MASK 0x3f 125#define MT9M032_GAIN_ANALOG_MASK 0x3f
108#define MT9M032_FORMATTER1 0x9e 126#define MT9M032_FORMATTER1 0x9e
127#define MT9M032_FORMATTER1_PLL_P1_6 (1 << 8)
128#define MT9M032_FORMATTER1_PARALLEL (1 << 12)
109#define MT9M032_FORMATTER2 0x9f 129#define MT9M032_FORMATTER2 0x9f
110#define MT9M032_FORMATTER2_DOUT_EN 0x1000 130#define MT9M032_FORMATTER2_DOUT_EN 0x1000
111#define MT9M032_FORMATTER2_PIXCLK_EN 0x2000 131#define MT9M032_FORMATTER2_PIXCLK_EN 0x2000
@@ -121,8 +141,6 @@
121#define MT9P031_PLL_CONTROL_PWROFF 0x0050 141#define MT9P031_PLL_CONTROL_PWROFF 0x0050
122#define MT9P031_PLL_CONTROL_PWRON 0x0051 142#define MT9P031_PLL_CONTROL_PWRON 0x0051
123#define MT9P031_PLL_CONTROL_USEPLL 0x0052 143#define MT9P031_PLL_CONTROL_USEPLL 0x0052
124#define MT9P031_PLL_CONFIG2 0x11
125#define MT9P031_PLL_CONFIG2_P1_DIV_MASK 0x1f
126 144
127struct mt9m032 { 145struct mt9m032 {
128 struct v4l2_subdev subdev; 146 struct v4l2_subdev subdev;
@@ -255,13 +273,14 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
255 .n_max = 64, 273 .n_max = 64,
256 .m_min = 16, 274 .m_min = 16,
257 .m_max = 255, 275 .m_max = 255,
258 .p1_min = 1, 276 .p1_min = 6,
259 .p1_max = 128, 277 .p1_max = 7,
260 }; 278 };
261 279
262 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); 280 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev);
263 struct mt9m032_platform_data *pdata = sensor->pdata; 281 struct mt9m032_platform_data *pdata = sensor->pdata;
264 struct aptina_pll pll; 282 struct aptina_pll pll;
283 u16 reg_val;
265 int ret; 284 int ret;
266 285
267 pll.ext_clock = pdata->ext_clock; 286 pll.ext_clock = pdata->ext_clock;
@@ -274,18 +293,21 @@ static int mt9m032_setup_pll(struct mt9m032 *sensor)
274 sensor->pix_clock = pdata->pix_clock; 293 sensor->pix_clock = pdata->pix_clock;
275 294
276 ret = mt9m032_write(client, MT9M032_PLL_CONFIG1, 295 ret = mt9m032_write(client, MT9M032_PLL_CONFIG1,
277 (pll.m << MT9M032_PLL_CONFIG1_MUL_SHIFT) 296 (pll.m << MT9M032_PLL_CONFIG1_MUL_SHIFT) |
278 | (pll.p1 - 1)); 297 ((pll.n - 1) & MT9M032_PLL_CONFIG1_PREDIV_MASK));
279 if (!ret)
280 ret = mt9m032_write(client, MT9P031_PLL_CONFIG2, pll.n - 1);
281 if (!ret) 298 if (!ret)
282 ret = mt9m032_write(client, MT9P031_PLL_CONTROL, 299 ret = mt9m032_write(client, MT9P031_PLL_CONTROL,
283 MT9P031_PLL_CONTROL_PWRON | 300 MT9P031_PLL_CONTROL_PWRON |
284 MT9P031_PLL_CONTROL_USEPLL); 301 MT9P031_PLL_CONTROL_USEPLL);
285 if (!ret) /* more reserved, Continuous, Master Mode */ 302 if (!ret) /* more reserved, Continuous, Master Mode */
286 ret = mt9m032_write(client, MT9M032_READ_MODE1, 0x8006); 303 ret = mt9m032_write(client, MT9M032_READ_MODE1, 0x8000 |
287 if (!ret) /* Set 14-bit mode, select 7 divider */ 304 MT9M032_READ_MODE1_STROBE_START_EXP |
288 ret = mt9m032_write(client, MT9M032_FORMATTER1, 0x111e); 305 MT9M032_READ_MODE1_STROBE_END_SHUTTER);
306 if (!ret) {
307 reg_val = (pll.p1 == 6 ? MT9M032_FORMATTER1_PLL_P1_6 : 0)
308 | MT9M032_FORMATTER1_PARALLEL | 0x001e; /* 14-bit */
309 ret = mt9m032_write(client, MT9M032_FORMATTER1, reg_val);
310 }
289 311
290 return ret; 312 return ret;
291} 313}
@@ -548,7 +570,7 @@ static int mt9m032_g_register(struct v4l2_subdev *sd,
548} 570}
549 571
550static int mt9m032_s_register(struct v4l2_subdev *sd, 572static int mt9m032_s_register(struct v4l2_subdev *sd,
551 struct v4l2_dbg_register *reg) 573 const struct v4l2_dbg_register *reg)
552{ 574{
553 struct mt9m032 *sensor = to_mt9m032(sd); 575 struct mt9m032 *sensor = to_mt9m032(sd);
554 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); 576 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev);
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index e32833262d32..28cf95b37285 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.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 <linux/clk.h>
15#include <linux/delay.h> 16#include <linux/delay.h>
16#include <linux/device.h> 17#include <linux/device.h>
17#include <linux/gpio.h> 18#include <linux/gpio.h>
@@ -19,6 +20,7 @@
19#include <linux/i2c.h> 20#include <linux/i2c.h>
20#include <linux/log2.h> 21#include <linux/log2.h>
21#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/regulator/consumer.h>
22#include <linux/slab.h> 24#include <linux/slab.h>
23#include <linux/videodev2.h> 25#include <linux/videodev2.h>
24 26
@@ -121,6 +123,11 @@ struct mt9p031 {
121 struct mutex power_lock; /* lock to protect power_count */ 123 struct mutex power_lock; /* lock to protect power_count */
122 int power_count; 124 int power_count;
123 125
126 struct clk *clk;
127 struct regulator *vaa;
128 struct regulator *vdd;
129 struct regulator *vdd_io;
130
124 enum mt9p031_model model; 131 enum mt9p031_model model;
125 struct aptina_pll pll; 132 struct aptina_pll pll;
126 int reset; 133 int reset;
@@ -195,7 +202,7 @@ static int mt9p031_reset(struct mt9p031 *mt9p031)
195 0); 202 0);
196} 203}
197 204
198static int mt9p031_pll_setup(struct mt9p031 *mt9p031) 205static int mt9p031_clk_setup(struct mt9p031 *mt9p031)
199{ 206{
200 static const struct aptina_pll_limits limits = { 207 static const struct aptina_pll_limits limits = {
201 .ext_clock_min = 6000000, 208 .ext_clock_min = 6000000,
@@ -216,6 +223,12 @@ static int mt9p031_pll_setup(struct mt9p031 *mt9p031)
216 struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); 223 struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
217 struct mt9p031_platform_data *pdata = mt9p031->pdata; 224 struct mt9p031_platform_data *pdata = mt9p031->pdata;
218 225
226 mt9p031->clk = devm_clk_get(&client->dev, NULL);
227 if (IS_ERR(mt9p031->clk))
228 return PTR_ERR(mt9p031->clk);
229
230 clk_set_rate(mt9p031->clk, pdata->ext_freq);
231
219 mt9p031->pll.ext_clock = pdata->ext_freq; 232 mt9p031->pll.ext_clock = pdata->ext_freq;
220 mt9p031->pll.pix_clock = pdata->target_freq; 233 mt9p031->pll.pix_clock = pdata->target_freq;
221 234
@@ -264,10 +277,14 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
264 usleep_range(1000, 2000); 277 usleep_range(1000, 2000);
265 } 278 }
266 279
280 /* Bring up the supplies */
281 regulator_enable(mt9p031->vdd);
282 regulator_enable(mt9p031->vdd_io);
283 regulator_enable(mt9p031->vaa);
284
267 /* Emable clock */ 285 /* Emable clock */
268 if (mt9p031->pdata->set_xclk) 286 if (mt9p031->clk)
269 mt9p031->pdata->set_xclk(&mt9p031->subdev, 287 clk_prepare_enable(mt9p031->clk);
270 mt9p031->pdata->ext_freq);
271 288
272 /* Now RESET_BAR must be high */ 289 /* Now RESET_BAR must be high */
273 if (mt9p031->reset != -1) { 290 if (mt9p031->reset != -1) {
@@ -285,8 +302,12 @@ static void mt9p031_power_off(struct mt9p031 *mt9p031)
285 usleep_range(1000, 2000); 302 usleep_range(1000, 2000);
286 } 303 }
287 304
288 if (mt9p031->pdata->set_xclk) 305 regulator_disable(mt9p031->vaa);
289 mt9p031->pdata->set_xclk(&mt9p031->subdev, 0); 306 regulator_disable(mt9p031->vdd_io);
307 regulator_disable(mt9p031->vdd);
308
309 if (mt9p031->clk)
310 clk_disable_unprepare(mt9p031->clk);
290} 311}
291 312
292static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on) 313static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on)
@@ -927,7 +948,7 @@ static int mt9p031_probe(struct i2c_client *client,
927 return -EIO; 948 return -EIO;
928 } 949 }
929 950
930 mt9p031 = kzalloc(sizeof(*mt9p031), GFP_KERNEL); 951 mt9p031 = devm_kzalloc(&client->dev, sizeof(*mt9p031), GFP_KERNEL);
931 if (mt9p031 == NULL) 952 if (mt9p031 == NULL)
932 return -ENOMEM; 953 return -ENOMEM;
933 954
@@ -937,6 +958,16 @@ static int mt9p031_probe(struct i2c_client *client,
937 mt9p031->model = did->driver_data; 958 mt9p031->model = did->driver_data;
938 mt9p031->reset = -1; 959 mt9p031->reset = -1;
939 960
961 mt9p031->vaa = devm_regulator_get(&client->dev, "vaa");
962 mt9p031->vdd = devm_regulator_get(&client->dev, "vdd");
963 mt9p031->vdd_io = devm_regulator_get(&client->dev, "vdd_io");
964
965 if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
966 IS_ERR(mt9p031->vdd_io)) {
967 dev_err(&client->dev, "Unable to get regulators\n");
968 return -ENODEV;
969 }
970
940 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6); 971 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6);
941 972
942 v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, 973 v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
@@ -1001,24 +1032,20 @@ static int mt9p031_probe(struct i2c_client *client,
1001 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; 1032 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB;
1002 1033
1003 if (pdata->reset != -1) { 1034 if (pdata->reset != -1) {
1004 ret = gpio_request_one(pdata->reset, GPIOF_OUT_INIT_LOW, 1035 ret = devm_gpio_request_one(&client->dev, pdata->reset,
1005 "mt9p031_rst"); 1036 GPIOF_OUT_INIT_LOW, "mt9p031_rst");
1006 if (ret < 0) 1037 if (ret < 0)
1007 goto done; 1038 goto done;
1008 1039
1009 mt9p031->reset = pdata->reset; 1040 mt9p031->reset = pdata->reset;
1010 } 1041 }
1011 1042
1012 ret = mt9p031_pll_setup(mt9p031); 1043 ret = mt9p031_clk_setup(mt9p031);
1013 1044
1014done: 1045done:
1015 if (ret < 0) { 1046 if (ret < 0) {
1016 if (mt9p031->reset != -1)
1017 gpio_free(mt9p031->reset);
1018
1019 v4l2_ctrl_handler_free(&mt9p031->ctrls); 1047 v4l2_ctrl_handler_free(&mt9p031->ctrls);
1020 media_entity_cleanup(&mt9p031->subdev.entity); 1048 media_entity_cleanup(&mt9p031->subdev.entity);
1021 kfree(mt9p031);
1022 } 1049 }
1023 1050
1024 return ret; 1051 return ret;
@@ -1032,9 +1059,6 @@ static int mt9p031_remove(struct i2c_client *client)
1032 v4l2_ctrl_handler_free(&mt9p031->ctrls); 1059 v4l2_ctrl_handler_free(&mt9p031->ctrls);
1033 v4l2_device_unregister_subdev(subdev); 1060 v4l2_device_unregister_subdev(subdev);
1034 media_entity_cleanup(&subdev->entity); 1061 media_entity_cleanup(&subdev->entity);
1035 if (mt9p031->reset != -1)
1036 gpio_free(mt9p031->reset);
1037 kfree(mt9p031);
1038 1062
1039 return 0; 1063 return 0;
1040} 1064}
diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
index 73b7688cbebd..3f415fd12de3 100644
--- a/drivers/media/i2c/mt9v011.c
+++ b/drivers/media/i2c/mt9v011.c
@@ -421,7 +421,7 @@ static int mt9v011_g_register(struct v4l2_subdev *sd,
421} 421}
422 422
423static int mt9v011_s_register(struct v4l2_subdev *sd, 423static int mt9v011_s_register(struct v4l2_subdev *sd,
424 struct v4l2_dbg_register *reg) 424 const struct v4l2_dbg_register *reg)
425{ 425{
426 struct i2c_client *client = v4l2_get_subdevdata(sd); 426 struct i2c_client *client = v4l2_get_subdevdata(sd);
427 427
diff --git a/drivers/staging/media/go7007/wis-ov7640.c b/drivers/media/i2c/ov7640.c
index 9f01657f884a..b0cc927e8b19 100644
--- a/drivers/staging/media/go7007/wis-ov7640.c
+++ b/drivers/media/i2c/ov7640.c
@@ -15,21 +15,18 @@
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */ 16 */
17 17
18#include <linux/module.h>
19#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/videodev2.h> 21#include <linux/videodev2.h>
22#include <media/v4l2-device.h>
23#include <media/v4l2-chip-ident.h>
24#include <linux/slab.h>
22 25
23#include "wis-i2c.h" 26MODULE_DESCRIPTION("OmniVision ov7640 sensor driver");
24 27MODULE_LICENSE("GPL v2");
25struct wis_ov7640 {
26 int brightness;
27 int contrast;
28 int saturation;
29 int hue;
30};
31 28
32static u8 initial_registers[] = { 29static const u8 initial_registers[] = {
33 0x12, 0x80, 30 0x12, 0x80,
34 0x12, 0x54, 31 0x12, 0x54,
35 0x14, 0x24, 32 0x14, 0x24,
@@ -39,7 +36,7 @@ static u8 initial_registers[] = {
39 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */ 36 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */
40}; 37};
41 38
42static int write_regs(struct i2c_client *client, u8 *regs) 39static int write_regs(struct i2c_client *client, const u8 *regs)
43{ 40{
44 int i; 41 int i;
45 42
@@ -49,48 +46,61 @@ static int write_regs(struct i2c_client *client, u8 *regs)
49 return 0; 46 return 0;
50} 47}
51 48
52static int wis_ov7640_probe(struct i2c_client *client, 49/* ----------------------------------------------------------------------- */
53 const struct i2c_device_id *id) 50
51static const struct v4l2_subdev_ops ov7640_ops;
52
53static int ov7640_probe(struct i2c_client *client,
54 const struct i2c_device_id *id)
54{ 55{
55 struct i2c_adapter *adapter = client->adapter; 56 struct i2c_adapter *adapter = client->adapter;
57 struct v4l2_subdev *sd;
56 58
57 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 59 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
58 return -ENODEV; 60 return -ENODEV;
59 61
62 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
63 if (sd == NULL)
64 return -ENOMEM;
65 v4l2_i2c_subdev_init(sd, client, &ov7640_ops);
66
60 client->flags = I2C_CLIENT_SCCB; 67 client->flags = I2C_CLIENT_SCCB;
61 68
62 dev_dbg(&client->dev, 69 v4l_info(client, "chip found @ 0x%02x (%s)\n",
63 "wis-ov7640: initializing OV7640 at address %d on %s\n", 70 client->addr << 1, client->adapter->name);
64 client->addr, adapter->name);
65 71
66 if (write_regs(client, initial_registers) < 0) { 72 if (write_regs(client, initial_registers) < 0) {
67 dev_err(&client->dev, "wis-ov7640: error initializing OV7640\n"); 73 v4l_err(client, "error initializing OV7640\n");
74 kfree(sd);
68 return -ENODEV; 75 return -ENODEV;
69 } 76 }
70 77
71 return 0; 78 return 0;
72} 79}
73 80
74static int wis_ov7640_remove(struct i2c_client *client) 81
82static int ov7640_remove(struct i2c_client *client)
75{ 83{
84 struct v4l2_subdev *sd = i2c_get_clientdata(client);
85
86 v4l2_device_unregister_subdev(sd);
87 kfree(sd);
76 return 0; 88 return 0;
77} 89}
78 90
79static const struct i2c_device_id wis_ov7640_id[] = { 91static const struct i2c_device_id ov7640_id[] = {
80 { "wis_ov7640", 0 }, 92 { "ov7640", 0 },
81 { } 93 { }
82}; 94};
83MODULE_DEVICE_TABLE(i2c, wis_ov7640_id); 95MODULE_DEVICE_TABLE(i2c, ov7640_id);
84 96
85static struct i2c_driver wis_ov7640_driver = { 97static struct i2c_driver ov7640_driver = {
86 .driver = { 98 .driver = {
87 .name = "WIS OV7640 I2C driver", 99 .owner = THIS_MODULE,
100 .name = "ov7640",
88 }, 101 },
89 .probe = wis_ov7640_probe, 102 .probe = ov7640_probe,
90 .remove = wis_ov7640_remove, 103 .remove = ov7640_remove,
91 .id_table = wis_ov7640_id, 104 .id_table = ov7640_id,
92}; 105};
93 106module_i2c_driver(ov7640_driver);
94module_i2c_driver(wis_ov7640_driver);
95
96MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 05ed5b8e7f88..617ad3fff4aa 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -1487,7 +1487,7 @@ static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
1487 return ret; 1487 return ret;
1488} 1488}
1489 1489
1490static int ov7670_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1490static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1491{ 1491{
1492 struct i2c_client *client = v4l2_get_subdevdata(sd); 1492 struct i2c_client *client = v4l2_get_subdevdata(sd);
1493 1493
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 5dbb65e1f6b7..cb52438e53ac 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -357,7 +357,7 @@ static int s5c73m3_load_fw(struct v4l2_subdev *sd)
357 return -EINVAL; 357 return -EINVAL;
358 } 358 }
359 359
360 v4l2_info(sd, "Loading firmware (%s, %d B)\n", fw_name, fw->size); 360 v4l2_info(sd, "Loading firmware (%s, %zu B)\n", fw_name, fw->size);
361 361
362 ret = s5c73m3_spi_write(state, fw->data, fw->size, 64); 362 ret = s5c73m3_spi_write(state, fw->data, fw->size, 64);
363 363
@@ -1457,6 +1457,12 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
1457 return ret; 1457 return ret;
1458} 1458}
1459 1459
1460static void s5c73m3_oif_unregistered(struct v4l2_subdev *sd)
1461{
1462 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1463 v4l2_device_unregister_subdev(&state->sensor_sd);
1464}
1465
1460static const struct v4l2_subdev_internal_ops s5c73m3_internal_ops = { 1466static const struct v4l2_subdev_internal_ops s5c73m3_internal_ops = {
1461 .open = s5c73m3_open, 1467 .open = s5c73m3_open,
1462}; 1468};
@@ -1474,6 +1480,7 @@ static const struct v4l2_subdev_ops s5c73m3_subdev_ops = {
1474 1480
1475static const struct v4l2_subdev_internal_ops oif_internal_ops = { 1481static const struct v4l2_subdev_internal_ops oif_internal_ops = {
1476 .registered = s5c73m3_oif_registered, 1482 .registered = s5c73m3_oif_registered,
1483 .unregistered = s5c73m3_oif_unregistered,
1477 .open = s5c73m3_oif_open, 1484 .open = s5c73m3_oif_open,
1478}; 1485};
1479 1486
@@ -1668,13 +1675,17 @@ out_err1:
1668 1675
1669static int s5c73m3_remove(struct i2c_client *client) 1676static int s5c73m3_remove(struct i2c_client *client)
1670{ 1677{
1671 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1678 struct v4l2_subdev *oif_sd = i2c_get_clientdata(client);
1672 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd); 1679 struct s5c73m3 *state = oif_sd_to_s5c73m3(oif_sd);
1680 struct v4l2_subdev *sensor_sd = &state->sensor_sd;
1673 1681
1674 v4l2_device_unregister_subdev(sd); 1682 v4l2_device_unregister_subdev(oif_sd);
1675 1683
1676 v4l2_ctrl_handler_free(sd->ctrl_handler); 1684 v4l2_ctrl_handler_free(oif_sd->ctrl_handler);
1677 media_entity_cleanup(&sd->entity); 1685 media_entity_cleanup(&oif_sd->entity);
1686
1687 v4l2_device_unregister_subdev(sensor_sd);
1688 media_entity_cleanup(&sensor_sd->entity);
1678 1689
1679 s5c73m3_unregister_spi_driver(state); 1690 s5c73m3_unregister_spi_driver(state);
1680 s5c73m3_free_gpios(state); 1691 s5c73m3_free_gpios(state);
diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c
index 0caac50d7cf4..b4e1ccbd87ec 100644
--- a/drivers/media/i2c/saa6588.c
+++ b/drivers/media/i2c/saa6588.c
@@ -435,7 +435,7 @@ static int saa6588_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
435 return 0; 435 return 0;
436} 436}
437 437
438static int saa6588_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 438static int saa6588_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
439{ 439{
440 struct saa6588 *s = to_saa6588(sd); 440 struct saa6588 *s = to_saa6588(sd);
441 441
diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c
index 6b6788cd08f6..52c717d977c9 100644
--- a/drivers/media/i2c/saa7115.c
+++ b/drivers/media/i2c/saa7115.c
@@ -83,9 +83,10 @@ struct saa711x_state {
83 u32 ident; 83 u32 ident;
84 u32 audclk_freq; 84 u32 audclk_freq;
85 u32 crystal_freq; 85 u32 crystal_freq;
86 u8 ucgc; 86 bool ucgc;
87 u8 cgcdiv; 87 u8 cgcdiv;
88 u8 apll; 88 bool apll;
89 bool double_asclk;
89}; 90};
90 91
91static inline struct saa711x_state *to_state(struct v4l2_subdev *sd) 92static inline struct saa711x_state *to_state(struct v4l2_subdev *sd)
@@ -732,8 +733,12 @@ static int saa711x_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
732 if (state->apll) 733 if (state->apll)
733 acc |= 0x08; 734 acc |= 0x08;
734 735
736 if (state->double_asclk) {
737 acpf <<= 1;
738 acni <<= 1;
739 }
735 saa711x_write(sd, R_38_CLK_RATIO_AMXCLK_TO_ASCLK, 0x03); 740 saa711x_write(sd, R_38_CLK_RATIO_AMXCLK_TO_ASCLK, 0x03);
736 saa711x_write(sd, R_39_CLK_RATIO_ASCLK_TO_ALRCLK, 0x10); 741 saa711x_write(sd, R_39_CLK_RATIO_ASCLK_TO_ALRCLK, 0x10 << state->double_asclk);
737 saa711x_write(sd, R_3A_AUD_CLK_GEN_BASIC_SETUP, acc); 742 saa711x_write(sd, R_3A_AUD_CLK_GEN_BASIC_SETUP, acc);
738 743
739 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD, acpf & 0xff); 744 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD, acpf & 0xff);
@@ -1259,6 +1264,12 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1259 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) | 1264 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) |
1260 (state->output & 0x01)); 1265 (state->output & 0x01));
1261 } 1266 }
1267 if (state->ident > V4L2_IDENT_SAA7111A) {
1268 if (config & SAA7115_IDQ_IS_DEFAULT)
1269 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x20);
1270 else
1271 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x21);
1272 }
1262 return 0; 1273 return 0;
1263} 1274}
1264 1275
@@ -1296,9 +1307,10 @@ static int saa711x_s_crystal_freq(struct v4l2_subdev *sd, u32 freq, u32 flags)
1296 if (freq != SAA7115_FREQ_32_11_MHZ && freq != SAA7115_FREQ_24_576_MHZ) 1307 if (freq != SAA7115_FREQ_32_11_MHZ && freq != SAA7115_FREQ_24_576_MHZ)
1297 return -EINVAL; 1308 return -EINVAL;
1298 state->crystal_freq = freq; 1309 state->crystal_freq = freq;
1310 state->double_asclk = flags & SAA7115_FREQ_FL_DOUBLE_ASCLK;
1299 state->cgcdiv = (flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4; 1311 state->cgcdiv = (flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4;
1300 state->ucgc = (flags & SAA7115_FREQ_FL_UCGC) ? 1 : 0; 1312 state->ucgc = flags & SAA7115_FREQ_FL_UCGC;
1301 state->apll = (flags & SAA7115_FREQ_FL_APLL) ? 1 : 0; 1313 state->apll = flags & SAA7115_FREQ_FL_APLL;
1302 saa711x_s_clock_freq(sd, state->audclk_freq); 1314 saa711x_s_clock_freq(sd, state->audclk_freq);
1303 return 0; 1315 return 0;
1304} 1316}
@@ -1354,6 +1366,34 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1354 */ 1366 */
1355 1367
1356 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); 1368 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1369
1370 if (state->ident == V4L2_IDENT_SAA7115) {
1371 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1372
1373 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e);
1374
1375 switch (reg1e & 0x03) {
1376 case 1:
1377 *std &= V4L2_STD_NTSC;
1378 break;
1379 case 2:
1380 /*
1381 * V4L2_STD_PAL just cover the european PAL standards.
1382 * This is wrong, as the device could also be using an
1383 * other PAL standard.
1384 */
1385 *std &= V4L2_STD_PAL | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc |
1386 V4L2_STD_PAL_M | V4L2_STD_PAL_60;
1387 break;
1388 case 3:
1389 *std &= V4L2_STD_SECAM;
1390 break;
1391 default:
1392 /* Can't detect anything */
1393 break;
1394 }
1395 }
1396
1357 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f); 1397 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f);
1358 1398
1359 /* horizontal/vertical not locked */ 1399 /* horizontal/vertical not locked */
@@ -1365,34 +1405,6 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1365 else 1405 else
1366 *std &= V4L2_STD_625_50; 1406 *std &= V4L2_STD_625_50;
1367 1407
1368 if (state->ident != V4L2_IDENT_SAA7115)
1369 goto ret;
1370
1371 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1372
1373 switch (reg1e & 0x03) {
1374 case 1:
1375 *std &= V4L2_STD_NTSC;
1376 break;
1377 case 2:
1378 /*
1379 * V4L2_STD_PAL just cover the european PAL standards.
1380 * This is wrong, as the device could also be using an
1381 * other PAL standard.
1382 */
1383 *std &= V4L2_STD_PAL | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc |
1384 V4L2_STD_PAL_M | V4L2_STD_PAL_60;
1385 break;
1386 case 3:
1387 *std &= V4L2_STD_SECAM;
1388 break;
1389 default:
1390 /* Can't detect anything */
1391 break;
1392 }
1393
1394 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e);
1395
1396ret: 1408ret:
1397 v4l2_dbg(1, debug, sd, "detected std mask = %08Lx\n", *std); 1409 v4l2_dbg(1, debug, sd, "detected std mask = %08Lx\n", *std);
1398 1410
@@ -1428,7 +1440,7 @@ static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1428 return 0; 1440 return 0;
1429} 1441}
1430 1442
1431static int saa711x_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1443static int saa711x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1432{ 1444{
1433 struct i2c_client *client = v4l2_get_subdevdata(sd); 1445 struct i2c_client *client = v4l2_get_subdevdata(sd);
1434 1446
diff --git a/drivers/media/i2c/saa7127.c b/drivers/media/i2c/saa7127.c
index b745f68fbc92..8a47ac10927f 100644
--- a/drivers/media/i2c/saa7127.c
+++ b/drivers/media/i2c/saa7127.c
@@ -672,7 +672,7 @@ static int saa7127_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
672 return 0; 672 return 0;
673} 673}
674 674
675static int saa7127_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 675static int saa7127_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
676{ 676{
677 struct i2c_client *client = v4l2_get_subdevdata(sd); 677 struct i2c_client *client = v4l2_get_subdevdata(sd);
678 678
diff --git a/drivers/media/i2c/saa717x.c b/drivers/media/i2c/saa717x.c
index 1e84466515aa..cf3a0aa7e45e 100644
--- a/drivers/media/i2c/saa717x.c
+++ b/drivers/media/i2c/saa717x.c
@@ -988,7 +988,7 @@ static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
988 return 0; 988 return 0;
989} 989}
990 990
991static int saa717x_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 991static int saa717x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
992{ 992{
993 struct i2c_client *client = v4l2_get_subdevdata(sd); 993 struct i2c_client *client = v4l2_get_subdevdata(sd);
994 u16 addr = reg->reg & 0xffff; 994 u16 addr = reg->reg & 0xffff;
@@ -1113,7 +1113,7 @@ static int saa717x_s_stream(struct v4l2_subdev *sd, int enable)
1113} 1113}
1114 1114
1115/* change audio mode */ 1115/* change audio mode */
1116static int saa717x_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1116static int saa717x_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1117{ 1117{
1118 struct saa717x_state *decoder = to_state(sd); 1118 struct saa717x_state *decoder = to_state(sd);
1119 int audio_mode; 1119 int audio_mode;
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 83c7ed7ffcc2..cae4f4683851 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2833,7 +2833,7 @@ static int smiapp_probe(struct i2c_client *client,
2833 sensor->src->pads, 0); 2833 sensor->src->pads, 0);
2834} 2834}
2835 2835
2836static int __exit smiapp_remove(struct i2c_client *client) 2836static int smiapp_remove(struct i2c_client *client)
2837{ 2837{
2838 struct v4l2_subdev *subdev = i2c_get_clientdata(client); 2838 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
2839 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev); 2839 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
@@ -2881,7 +2881,7 @@ static struct i2c_driver smiapp_i2c_driver = {
2881 .pm = &smiapp_pm_ops, 2881 .pm = &smiapp_pm_ops,
2882 }, 2882 },
2883 .probe = smiapp_probe, 2883 .probe = smiapp_probe,
2884 .remove = __exit_p(smiapp_remove), 2884 .remove = smiapp_remove,
2885 .id_table = smiapp_id_table, 2885 .id_table = smiapp_id_table,
2886}; 2886};
2887 2887
diff --git a/drivers/media/i2c/soc_camera/Kconfig b/drivers/media/i2c/soc_camera/Kconfig
index 6dff2b7ad520..23d352f0adf0 100644
--- a/drivers/media/i2c/soc_camera/Kconfig
+++ b/drivers/media/i2c/soc_camera/Kconfig
@@ -9,7 +9,6 @@ config SOC_CAMERA_IMX074
9config SOC_CAMERA_MT9M001 9config SOC_CAMERA_MT9M001
10 tristate "mt9m001 support" 10 tristate "mt9m001 support"
11 depends on SOC_CAMERA && I2C 11 depends on SOC_CAMERA && I2C
12 select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
13 help 12 help
14 This driver supports MT9M001 cameras from Micron, monochrome 13 This driver supports MT9M001 cameras from Micron, monochrome
15 and colour models. 14 and colour models.
@@ -36,7 +35,6 @@ config SOC_CAMERA_MT9T112
36config SOC_CAMERA_MT9V022 35config SOC_CAMERA_MT9V022
37 tristate "mt9v022 and mt9v024 support" 36 tristate "mt9v022 and mt9v024 support"
38 depends on SOC_CAMERA && I2C 37 depends on SOC_CAMERA && I2C
39 select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
40 help 38 help
41 This driver supports MT9V022 cameras from Micron 39 This driver supports MT9V022 cameras from Micron
42 40
diff --git a/drivers/media/i2c/soc_camera/mt9m001.c b/drivers/media/i2c/soc_camera/mt9m001.c
index bcdc86175549..dd9089805757 100644
--- a/drivers/media/i2c/soc_camera/mt9m001.c
+++ b/drivers/media/i2c/soc_camera/mt9m001.c
@@ -360,7 +360,7 @@ static int mt9m001_g_register(struct v4l2_subdev *sd,
360} 360}
361 361
362static int mt9m001_s_register(struct v4l2_subdev *sd, 362static int mt9m001_s_register(struct v4l2_subdev *sd,
363 struct v4l2_dbg_register *reg) 363 const struct v4l2_dbg_register *reg)
364{ 364{
365 struct i2c_client *client = v4l2_get_subdevdata(sd); 365 struct i2c_client *client = v4l2_get_subdevdata(sd);
366 366
diff --git a/drivers/media/i2c/soc_camera/mt9m111.c b/drivers/media/i2c/soc_camera/mt9m111.c
index bbc4ff99603c..8bd4e0d2ea03 100644
--- a/drivers/media/i2c/soc_camera/mt9m111.c
+++ b/drivers/media/i2c/soc_camera/mt9m111.c
@@ -641,7 +641,7 @@ static int mt9m111_g_register(struct v4l2_subdev *sd,
641} 641}
642 642
643static int mt9m111_s_register(struct v4l2_subdev *sd, 643static int mt9m111_s_register(struct v4l2_subdev *sd,
644 struct v4l2_dbg_register *reg) 644 const struct v4l2_dbg_register *reg)
645{ 645{
646 struct i2c_client *client = v4l2_get_subdevdata(sd); 646 struct i2c_client *client = v4l2_get_subdevdata(sd);
647 647
@@ -701,11 +701,11 @@ static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
701 return reg_write(GLOBAL_GAIN, val); 701 return reg_write(GLOBAL_GAIN, val);
702} 702}
703 703
704static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on) 704static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int val)
705{ 705{
706 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 706 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
707 707
708 if (on) 708 if (val == V4L2_EXPOSURE_AUTO)
709 return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); 709 return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
710 return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); 710 return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
711} 711}
@@ -785,8 +785,6 @@ static int mt9m111_init(struct mt9m111 *mt9m111)
785 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 785 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
786 int ret; 786 int ret;
787 787
788 /* Default HIGHPOWER context */
789 mt9m111->ctx = &context_b;
790 ret = mt9m111_enable(mt9m111); 788 ret = mt9m111_enable(mt9m111);
791 if (!ret) 789 if (!ret)
792 ret = mt9m111_reset(mt9m111); 790 ret = mt9m111_reset(mt9m111);
@@ -975,6 +973,9 @@ static int mt9m111_probe(struct i2c_client *client,
975 if (!mt9m111) 973 if (!mt9m111)
976 return -ENOMEM; 974 return -ENOMEM;
977 975
976 /* Default HIGHPOWER context */
977 mt9m111->ctx = &context_b;
978
978 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); 979 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops);
979 v4l2_ctrl_handler_init(&mt9m111->hdl, 5); 980 v4l2_ctrl_handler_init(&mt9m111->hdl, 5);
980 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, 981 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
diff --git a/drivers/media/i2c/soc_camera/mt9t031.c b/drivers/media/i2c/soc_camera/mt9t031.c
index d80d044ebf15..26a15b87a9a2 100644
--- a/drivers/media/i2c/soc_camera/mt9t031.c
+++ b/drivers/media/i2c/soc_camera/mt9t031.c
@@ -430,7 +430,7 @@ static int mt9t031_g_register(struct v4l2_subdev *sd,
430} 430}
431 431
432static int mt9t031_s_register(struct v4l2_subdev *sd, 432static int mt9t031_s_register(struct v4l2_subdev *sd,
433 struct v4l2_dbg_register *reg) 433 const struct v4l2_dbg_register *reg)
434{ 434{
435 struct i2c_client *client = v4l2_get_subdevdata(sd); 435 struct i2c_client *client = v4l2_get_subdevdata(sd);
436 436
diff --git a/drivers/media/i2c/soc_camera/mt9t112.c b/drivers/media/i2c/soc_camera/mt9t112.c
index 188e29b03273..a7256b732804 100644
--- a/drivers/media/i2c/soc_camera/mt9t112.c
+++ b/drivers/media/i2c/soc_camera/mt9t112.c
@@ -766,7 +766,7 @@ static int mt9t112_g_register(struct v4l2_subdev *sd,
766} 766}
767 767
768static int mt9t112_s_register(struct v4l2_subdev *sd, 768static int mt9t112_s_register(struct v4l2_subdev *sd,
769 struct v4l2_dbg_register *reg) 769 const struct v4l2_dbg_register *reg)
770{ 770{
771 struct i2c_client *client = v4l2_get_subdevdata(sd); 771 struct i2c_client *client = v4l2_get_subdevdata(sd);
772 int ret; 772 int ret;
diff --git a/drivers/media/i2c/soc_camera/mt9v022.c b/drivers/media/i2c/soc_camera/mt9v022.c
index a5e65d6a0781..a295e598486f 100644
--- a/drivers/media/i2c/soc_camera/mt9v022.c
+++ b/drivers/media/i2c/soc_camera/mt9v022.c
@@ -275,6 +275,7 @@ static int mt9v022_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
275 struct i2c_client *client = v4l2_get_subdevdata(sd); 275 struct i2c_client *client = v4l2_get_subdevdata(sd);
276 struct mt9v022 *mt9v022 = to_mt9v022(client); 276 struct mt9v022 *mt9v022 = to_mt9v022(client);
277 struct v4l2_rect rect = a->c; 277 struct v4l2_rect rect = a->c;
278 int min_row, min_blank;
278 int ret; 279 int ret;
279 280
280 /* Bayer format - even size lengths */ 281 /* Bayer format - even size lengths */
@@ -310,13 +311,21 @@ static int mt9v022_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
310 ret = reg_write(client, MT9V022_COLUMN_START, rect.left); 311 ret = reg_write(client, MT9V022_COLUMN_START, rect.left);
311 if (!ret) 312 if (!ret)
312 ret = reg_write(client, MT9V022_ROW_START, rect.top); 313 ret = reg_write(client, MT9V022_ROW_START, rect.top);
314 /*
315 * mt9v022: min total row time is 660 columns, min blanking is 43
316 * mt9v024: min total row time is 690 columns, min blanking is 61
317 */
318 if (is_mt9v024(mt9v022->chip_version)) {
319 min_row = 690;
320 min_blank = 61;
321 } else {
322 min_row = 660;
323 min_blank = 43;
324 }
313 if (!ret) 325 if (!ret)
314 /*
315 * Default 94, Phytec driver says:
316 * "width + horizontal blank >= 660"
317 */
318 ret = v4l2_ctrl_s_ctrl(mt9v022->hblank, 326 ret = v4l2_ctrl_s_ctrl(mt9v022->hblank,
319 rect.width > 660 - 43 ? 43 : 660 - rect.width); 327 rect.width > min_row - min_blank ?
328 min_blank : min_row - rect.width);
320 if (!ret) 329 if (!ret)
321 ret = v4l2_ctrl_s_ctrl(mt9v022->vblank, 45); 330 ret = v4l2_ctrl_s_ctrl(mt9v022->vblank, 45);
322 if (!ret) 331 if (!ret)
@@ -488,7 +497,7 @@ static int mt9v022_g_register(struct v4l2_subdev *sd,
488} 497}
489 498
490static int mt9v022_s_register(struct v4l2_subdev *sd, 499static int mt9v022_s_register(struct v4l2_subdev *sd,
491 struct v4l2_dbg_register *reg) 500 const struct v4l2_dbg_register *reg)
492{ 501{
493 struct i2c_client *client = v4l2_get_subdevdata(sd); 502 struct i2c_client *client = v4l2_get_subdevdata(sd);
494 503
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index 0f520f693b6e..e3168424f9ba 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -756,7 +756,7 @@ static int ov2640_g_register(struct v4l2_subdev *sd,
756} 756}
757 757
758static int ov2640_s_register(struct v4l2_subdev *sd, 758static int ov2640_s_register(struct v4l2_subdev *sd,
759 struct v4l2_dbg_register *reg) 759 const struct v4l2_dbg_register *reg)
760{ 760{
761 struct i2c_client *client = v4l2_get_subdevdata(sd); 761 struct i2c_client *client = v4l2_get_subdevdata(sd);
762 762
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 9d53309619d2..9aa56de69eed 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -708,7 +708,7 @@ static int ov5642_get_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
708 return ret; 708 return ret;
709} 709}
710 710
711static int ov5642_set_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 711static int ov5642_set_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
712{ 712{
713 struct i2c_client *client = v4l2_get_subdevdata(sd); 713 struct i2c_client *client = v4l2_get_subdevdata(sd);
714 714
diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c
index dbe4f564e6b2..991202d4bbae 100644
--- a/drivers/media/i2c/soc_camera/ov6650.c
+++ b/drivers/media/i2c/soc_camera/ov6650.c
@@ -421,7 +421,7 @@ static int ov6650_get_register(struct v4l2_subdev *sd,
421} 421}
422 422
423static int ov6650_set_register(struct v4l2_subdev *sd, 423static int ov6650_set_register(struct v4l2_subdev *sd,
424 struct v4l2_dbg_register *reg) 424 const struct v4l2_dbg_register *reg)
425{ 425{
426 struct i2c_client *client = v4l2_get_subdevdata(sd); 426 struct i2c_client *client = v4l2_get_subdevdata(sd);
427 427
diff --git a/drivers/media/i2c/soc_camera/ov772x.c b/drivers/media/i2c/soc_camera/ov772x.c
index fbeb5b2f3ae5..713d62e349f6 100644
--- a/drivers/media/i2c/soc_camera/ov772x.c
+++ b/drivers/media/i2c/soc_camera/ov772x.c
@@ -652,7 +652,7 @@ static int ov772x_g_register(struct v4l2_subdev *sd,
652} 652}
653 653
654static int ov772x_s_register(struct v4l2_subdev *sd, 654static int ov772x_s_register(struct v4l2_subdev *sd,
655 struct v4l2_dbg_register *reg) 655 const struct v4l2_dbg_register *reg)
656{ 656{
657 struct i2c_client *client = v4l2_get_subdevdata(sd); 657 struct i2c_client *client = v4l2_get_subdevdata(sd);
658 658
diff --git a/drivers/media/i2c/soc_camera/ov9640.c b/drivers/media/i2c/soc_camera/ov9640.c
index 05993041be31..20ca62d371c1 100644
--- a/drivers/media/i2c/soc_camera/ov9640.c
+++ b/drivers/media/i2c/soc_camera/ov9640.c
@@ -322,7 +322,7 @@ static int ov9640_get_register(struct v4l2_subdev *sd,
322} 322}
323 323
324static int ov9640_set_register(struct v4l2_subdev *sd, 324static int ov9640_set_register(struct v4l2_subdev *sd,
325 struct v4l2_dbg_register *reg) 325 const struct v4l2_dbg_register *reg)
326{ 326{
327 struct i2c_client *client = v4l2_get_subdevdata(sd); 327 struct i2c_client *client = v4l2_get_subdevdata(sd);
328 328
diff --git a/drivers/media/i2c/soc_camera/ov9740.c b/drivers/media/i2c/soc_camera/ov9740.c
index 2f236da80165..012bd6271124 100644
--- a/drivers/media/i2c/soc_camera/ov9740.c
+++ b/drivers/media/i2c/soc_camera/ov9740.c
@@ -835,7 +835,7 @@ static int ov9740_get_register(struct v4l2_subdev *sd,
835} 835}
836 836
837static int ov9740_set_register(struct v4l2_subdev *sd, 837static int ov9740_set_register(struct v4l2_subdev *sd,
838 struct v4l2_dbg_register *reg) 838 const struct v4l2_dbg_register *reg)
839{ 839{
840 struct i2c_client *client = v4l2_get_subdevdata(sd); 840 struct i2c_client *client = v4l2_get_subdevdata(sd);
841 841
diff --git a/drivers/media/i2c/soc_camera/rj54n1cb0c.c b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
index 5c92679bfefb..1f9ec3b06b4e 100644
--- a/drivers/media/i2c/soc_camera/rj54n1cb0c.c
+++ b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
@@ -1161,7 +1161,7 @@ static int rj54n1_g_register(struct v4l2_subdev *sd,
1161} 1161}
1162 1162
1163static int rj54n1_s_register(struct v4l2_subdev *sd, 1163static int rj54n1_s_register(struct v4l2_subdev *sd,
1164 struct v4l2_dbg_register *reg) 1164 const struct v4l2_dbg_register *reg)
1165{ 1165{
1166 struct i2c_client *client = v4l2_get_subdevdata(sd); 1166 struct i2c_client *client = v4l2_get_subdevdata(sd);
1167 1167
diff --git a/drivers/media/i2c/soc_camera/tw9910.c b/drivers/media/i2c/soc_camera/tw9910.c
index 7d2074601881..bad90b16a6dd 100644
--- a/drivers/media/i2c/soc_camera/tw9910.c
+++ b/drivers/media/i2c/soc_camera/tw9910.c
@@ -554,7 +554,7 @@ static int tw9910_g_register(struct v4l2_subdev *sd,
554} 554}
555 555
556static int tw9910_s_register(struct v4l2_subdev *sd, 556static int tw9910_s_register(struct v4l2_subdev *sd,
557 struct v4l2_dbg_register *reg) 557 const struct v4l2_dbg_register *reg)
558{ 558{
559 struct i2c_client *client = v4l2_get_subdevdata(sd); 559 struct i2c_client *client = v4l2_get_subdevdata(sd);
560 560
diff --git a/drivers/media/i2c/sony-btf-mpx.c b/drivers/media/i2c/sony-btf-mpx.c
new file mode 100644
index 000000000000..38cbea98764c
--- /dev/null
+++ b/drivers/media/i2c/sony-btf-mpx.c
@@ -0,0 +1,399 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <media/tuner.h>
23#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-device.h>
26#include <linux/slab.h>
27
28MODULE_DESCRIPTION("sony-btf-mpx driver");
29MODULE_LICENSE("GPL v2");
30
31static int debug;
32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "debug level 0=off(default) 1=on\n");
34
35/* #define MPX_DEBUG */
36
37/*
38 * Note:
39 *
40 * AS(IF/MPX) pin: LOW HIGH/OPEN
41 * IF/MPX address: 0x42/0x40 0x43/0x44
42 */
43
44
45static int force_mpx_mode = -1;
46module_param(force_mpx_mode, int, 0644);
47
48struct sony_btf_mpx {
49 struct v4l2_subdev sd;
50 int mpxmode;
51 u32 audmode;
52};
53
54static inline struct sony_btf_mpx *to_state(struct v4l2_subdev *sd)
55{
56 return container_of(sd, struct sony_btf_mpx, sd);
57}
58
59static int mpx_write(struct i2c_client *client, int dev, int addr, int val)
60{
61 u8 buffer[5];
62 struct i2c_msg msg;
63
64 buffer[0] = dev;
65 buffer[1] = addr >> 8;
66 buffer[2] = addr & 0xff;
67 buffer[3] = val >> 8;
68 buffer[4] = val & 0xff;
69 msg.addr = client->addr;
70 msg.flags = 0;
71 msg.len = 5;
72 msg.buf = buffer;
73 i2c_transfer(client->adapter, &msg, 1);
74 return 0;
75}
76
77/*
78 * MPX register values for the BTF-PG472Z:
79 *
80 * FM_ NICAM_ SCART_
81 * MODUS SOURCE ACB PRESCAL PRESCAL PRESCAL SYSTEM VOLUME
82 * 10/0030 12/0008 12/0013 12/000E 12/0010 12/0000 10/0020 12/0000
83 * ---------------------------------------------------------------
84 * Auto 1003 0020 0100 2603 5000 XXXX 0001 7500
85 *
86 * B/G
87 * Mono 1003 0020 0100 2603 5000 XXXX 0003 7500
88 * A2 1003 0020 0100 2601 5000 XXXX 0003 7500
89 * NICAM 1003 0120 0100 2603 5000 XXXX 0008 7500
90 *
91 * I
92 * Mono 1003 0020 0100 2603 7900 XXXX 000A 7500
93 * NICAM 1003 0120 0100 2603 7900 XXXX 000A 7500
94 *
95 * D/K
96 * Mono 1003 0020 0100 2603 5000 XXXX 0004 7500
97 * A2-1 1003 0020 0100 2601 5000 XXXX 0004 7500
98 * A2-2 1003 0020 0100 2601 5000 XXXX 0005 7500
99 * A2-3 1003 0020 0100 2601 5000 XXXX 0007 7500
100 * NICAM 1003 0120 0100 2603 5000 XXXX 000B 7500
101 *
102 * L/L'
103 * Mono 0003 0200 0100 7C03 5000 2200 0009 7500
104 * NICAM 0003 0120 0100 7C03 5000 XXXX 0009 7500
105 *
106 * M
107 * Mono 1003 0200 0100 2B03 5000 2B00 0002 7500
108 *
109 * For Asia, replace the 0x26XX in FM_PRESCALE with 0x14XX.
110 *
111 * Bilingual selection in A2/NICAM:
112 *
113 * High byte of SOURCE Left chan Right chan
114 * 0x01 MAIN SUB
115 * 0x03 MAIN MAIN
116 * 0x04 SUB SUB
117 *
118 * Force mono in NICAM by setting the high byte of SOURCE to 0x02 (L/L') or
119 * 0x00 (all other bands). Force mono in A2 with FMONO_A2:
120 *
121 * FMONO_A2
122 * 10/0022
123 * --------
124 * Forced mono ON 07F0
125 * Forced mono OFF 0190
126 */
127
128static const struct {
129 enum { AUD_MONO, AUD_A2, AUD_NICAM, AUD_NICAM_L } audio_mode;
130 u16 modus;
131 u16 source;
132 u16 acb;
133 u16 fm_prescale;
134 u16 nicam_prescale;
135 u16 scart_prescale;
136 u16 system;
137 u16 volume;
138} mpx_audio_modes[] = {
139 /* Auto */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
140 0x5000, 0x0000, 0x0001, 0x7500 },
141 /* B/G Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
142 0x5000, 0x0000, 0x0003, 0x7500 },
143 /* B/G A2 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
144 0x5000, 0x0000, 0x0003, 0x7500 },
145 /* B/G NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
146 0x5000, 0x0000, 0x0008, 0x7500 },
147 /* I Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
148 0x7900, 0x0000, 0x000A, 0x7500 },
149 /* I NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
150 0x7900, 0x0000, 0x000A, 0x7500 },
151 /* D/K Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
152 0x5000, 0x0000, 0x0004, 0x7500 },
153 /* D/K A2-1 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
154 0x5000, 0x0000, 0x0004, 0x7500 },
155 /* D/K A2-2 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
156 0x5000, 0x0000, 0x0005, 0x7500 },
157 /* D/K A2-3 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
158 0x5000, 0x0000, 0x0007, 0x7500 },
159 /* D/K NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
160 0x5000, 0x0000, 0x000B, 0x7500 },
161 /* L/L' Mono */ { AUD_MONO, 0x0003, 0x0200, 0x0100, 0x7C03,
162 0x5000, 0x2200, 0x0009, 0x7500 },
163 /* L/L' NICAM */{ AUD_NICAM_L, 0x0003, 0x0120, 0x0100, 0x7C03,
164 0x5000, 0x0000, 0x0009, 0x7500 },
165};
166
167#define MPX_NUM_MODES ARRAY_SIZE(mpx_audio_modes)
168
169static int mpx_setup(struct sony_btf_mpx *t)
170{
171 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
172 u16 source = 0;
173 u8 buffer[3];
174 struct i2c_msg msg;
175 int mode = t->mpxmode;
176
177 /* reset MPX */
178 buffer[0] = 0x00;
179 buffer[1] = 0x80;
180 buffer[2] = 0x00;
181 msg.addr = client->addr;
182 msg.flags = 0;
183 msg.len = 3;
184 msg.buf = buffer;
185 i2c_transfer(client->adapter, &msg, 1);
186 buffer[1] = 0x00;
187 i2c_transfer(client->adapter, &msg, 1);
188
189 if (t->audmode != V4L2_TUNER_MODE_MONO)
190 mode++;
191
192 if (mpx_audio_modes[mode].audio_mode != AUD_MONO) {
193 switch (t->audmode) {
194 case V4L2_TUNER_MODE_MONO:
195 switch (mpx_audio_modes[mode].audio_mode) {
196 case AUD_A2:
197 source = mpx_audio_modes[mode].source;
198 break;
199 case AUD_NICAM:
200 source = 0x0000;
201 break;
202 case AUD_NICAM_L:
203 source = 0x0200;
204 break;
205 default:
206 break;
207 }
208 break;
209 case V4L2_TUNER_MODE_STEREO:
210 source = mpx_audio_modes[mode].source;
211 break;
212 case V4L2_TUNER_MODE_LANG1:
213 source = 0x0300;
214 break;
215 case V4L2_TUNER_MODE_LANG2:
216 source = 0x0400;
217 break;
218 }
219 source |= mpx_audio_modes[mode].source & 0x00ff;
220 } else
221 source = mpx_audio_modes[mode].source;
222
223 mpx_write(client, 0x10, 0x0030, mpx_audio_modes[mode].modus);
224 mpx_write(client, 0x12, 0x0008, source);
225 mpx_write(client, 0x12, 0x0013, mpx_audio_modes[mode].acb);
226 mpx_write(client, 0x12, 0x000e,
227 mpx_audio_modes[mode].fm_prescale);
228 mpx_write(client, 0x12, 0x0010,
229 mpx_audio_modes[mode].nicam_prescale);
230 mpx_write(client, 0x12, 0x000d,
231 mpx_audio_modes[mode].scart_prescale);
232 mpx_write(client, 0x10, 0x0020, mpx_audio_modes[mode].system);
233 mpx_write(client, 0x12, 0x0000, mpx_audio_modes[mode].volume);
234 if (mpx_audio_modes[mode].audio_mode == AUD_A2)
235 mpx_write(client, 0x10, 0x0022,
236 t->audmode == V4L2_TUNER_MODE_MONO ? 0x07f0 : 0x0190);
237
238#ifdef MPX_DEBUG
239 {
240 u8 buf1[3], buf2[2];
241 struct i2c_msg msgs[2];
242
243 v4l2_info(client,
244 "MPX registers: %04x %04x %04x %04x %04x %04x %04x %04x\n",
245 mpx_audio_modes[mode].modus,
246 source,
247 mpx_audio_modes[mode].acb,
248 mpx_audio_modes[mode].fm_prescale,
249 mpx_audio_modes[mode].nicam_prescale,
250 mpx_audio_modes[mode].scart_prescale,
251 mpx_audio_modes[mode].system,
252 mpx_audio_modes[mode].volume);
253 buf1[0] = 0x11;
254 buf1[1] = 0x00;
255 buf1[2] = 0x7e;
256 msgs[0].addr = client->addr;
257 msgs[0].flags = 0;
258 msgs[0].len = 3;
259 msgs[0].buf = buf1;
260 msgs[1].addr = client->addr;
261 msgs[1].flags = I2C_M_RD;
262 msgs[1].len = 2;
263 msgs[1].buf = buf2;
264 i2c_transfer(client->adapter, msgs, 2);
265 v4l2_info(client, "MPX system: %02x%02x\n",
266 buf2[0], buf2[1]);
267 buf1[0] = 0x11;
268 buf1[1] = 0x02;
269 buf1[2] = 0x00;
270 i2c_transfer(client->adapter, msgs, 2);
271 v4l2_info(client, "MPX status: %02x%02x\n",
272 buf2[0], buf2[1]);
273 }
274#endif
275 return 0;
276}
277
278
279static int sony_btf_mpx_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
280{
281 struct sony_btf_mpx *t = to_state(sd);
282 int default_mpx_mode = 0;
283
284 if (std & V4L2_STD_PAL_BG)
285 default_mpx_mode = 1;
286 else if (std & V4L2_STD_PAL_I)
287 default_mpx_mode = 4;
288 else if (std & V4L2_STD_PAL_DK)
289 default_mpx_mode = 6;
290 else if (std & V4L2_STD_SECAM_L)
291 default_mpx_mode = 11;
292
293 if (default_mpx_mode != t->mpxmode) {
294 t->mpxmode = default_mpx_mode;
295 mpx_setup(t);
296 }
297 return 0;
298}
299
300static int sony_btf_mpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
301{
302 struct sony_btf_mpx *t = to_state(sd);
303
304 vt->capability = V4L2_TUNER_CAP_NORM |
305 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
306 V4L2_TUNER_CAP_LANG2;
307 vt->rxsubchans = V4L2_TUNER_SUB_MONO |
308 V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_LANG1 |
309 V4L2_TUNER_SUB_LANG2;
310 vt->audmode = t->audmode;
311 return 0;
312}
313
314static int sony_btf_mpx_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
315{
316 struct sony_btf_mpx *t = to_state(sd);
317
318 if (vt->type != V4L2_TUNER_ANALOG_TV)
319 return -EINVAL;
320
321 if (vt->audmode != t->audmode) {
322 t->audmode = vt->audmode;
323 mpx_setup(t);
324 }
325 return 0;
326}
327
328/* --------------------------------------------------------------------------*/
329
330static const struct v4l2_subdev_core_ops sony_btf_mpx_core_ops = {
331 .s_std = sony_btf_mpx_s_std,
332};
333
334static const struct v4l2_subdev_tuner_ops sony_btf_mpx_tuner_ops = {
335 .s_tuner = sony_btf_mpx_s_tuner,
336 .g_tuner = sony_btf_mpx_g_tuner,
337};
338
339static const struct v4l2_subdev_ops sony_btf_mpx_ops = {
340 .core = &sony_btf_mpx_core_ops,
341 .tuner = &sony_btf_mpx_tuner_ops,
342};
343
344/* --------------------------------------------------------------------------*/
345
346static int sony_btf_mpx_probe(struct i2c_client *client,
347 const struct i2c_device_id *id)
348{
349 struct sony_btf_mpx *t;
350 struct v4l2_subdev *sd;
351
352 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
353 return -ENODEV;
354
355 v4l_info(client, "chip found @ 0x%x (%s)\n",
356 client->addr << 1, client->adapter->name);
357
358 t = kzalloc(sizeof(struct sony_btf_mpx), GFP_KERNEL);
359 if (t == NULL)
360 return -ENOMEM;
361
362 sd = &t->sd;
363 v4l2_i2c_subdev_init(sd, client, &sony_btf_mpx_ops);
364
365 /* Initialize sony_btf_mpx */
366 t->mpxmode = 0;
367 t->audmode = V4L2_TUNER_MODE_STEREO;
368
369 return 0;
370}
371
372static int sony_btf_mpx_remove(struct i2c_client *client)
373{
374 struct v4l2_subdev *sd = i2c_get_clientdata(client);
375
376 v4l2_device_unregister_subdev(sd);
377 kfree(to_state(sd));
378
379 return 0;
380}
381
382/* ----------------------------------------------------------------------- */
383
384static const struct i2c_device_id sony_btf_mpx_id[] = {
385 { "sony-btf-mpx", 0 },
386 { }
387};
388MODULE_DEVICE_TABLE(i2c, sony_btf_mpx_id);
389
390static struct i2c_driver sony_btf_mpx_driver = {
391 .driver = {
392 .owner = THIS_MODULE,
393 .name = "sony-btf-mpx",
394 },
395 .probe = sony_btf_mpx_probe,
396 .remove = sony_btf_mpx_remove,
397 .id_table = sony_btf_mpx_id,
398};
399module_i2c_driver(sony_btf_mpx_driver);
diff --git a/drivers/media/i2c/tda7432.c b/drivers/media/i2c/tda7432.c
index f7707e65761e..28b5121881f5 100644
--- a/drivers/media/i2c/tda7432.c
+++ b/drivers/media/i2c/tda7432.c
@@ -35,6 +35,7 @@
35 35
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-ctrls.h>
38#include <media/i2c-addr.h> 39#include <media/i2c-addr.h>
39 40
40#ifndef VIDEO_AUDIO_BALANCE 41#ifndef VIDEO_AUDIO_BALANCE
@@ -60,13 +61,17 @@ MODULE_PARM_DESC(maxvol, "Set maximium volume to +20dB(0) else +0dB(1). Default
60 61
61struct tda7432 { 62struct tda7432 {
62 struct v4l2_subdev sd; 63 struct v4l2_subdev sd;
63 int addr; 64 struct v4l2_ctrl_handler hdl;
64 int input; 65 struct {
65 int volume; 66 /* bass/treble cluster */
66 int muted; 67 struct v4l2_ctrl *bass;
67 int bass, treble; 68 struct v4l2_ctrl *treble;
68 int lf, lr, rf, rr; 69 };
69 int loud; 70 struct {
71 /* mute/balance cluster */
72 struct v4l2_ctrl *mute;
73 struct v4l2_ctrl *balance;
74 };
70}; 75};
71 76
72static inline struct tda7432 *to_state(struct v4l2_subdev *sd) 77static inline struct tda7432 *to_state(struct v4l2_subdev *sd)
@@ -74,6 +79,11 @@ static inline struct tda7432 *to_state(struct v4l2_subdev *sd)
74 return container_of(sd, struct tda7432, sd); 79 return container_of(sd, struct tda7432, sd);
75} 80}
76 81
82static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
83{
84 return &container_of(ctrl->handler, struct tda7432, hdl)->sd;
85}
86
77/* The TDA7432 is made by STS-Thompson 87/* The TDA7432 is made by STS-Thompson
78 * http://www.st.com 88 * http://www.st.com
79 * http://us.st.com/stonline/books/pdf/docs/4056.pdf 89 * http://us.st.com/stonline/books/pdf/docs/4056.pdf
@@ -227,24 +237,22 @@ static int tda7432_write(struct v4l2_subdev *sd, int subaddr, int val)
227static int tda7432_set(struct v4l2_subdev *sd) 237static int tda7432_set(struct v4l2_subdev *sd)
228{ 238{
229 struct i2c_client *client = v4l2_get_subdevdata(sd); 239 struct i2c_client *client = v4l2_get_subdevdata(sd);
230 struct tda7432 *t = to_state(sd);
231 unsigned char buf[16]; 240 unsigned char buf[16];
232 241
233 v4l2_dbg(1, debug, sd,
234 "tda7432: 7432_set(0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
235 t->input, t->volume, t->bass, t->treble, t->lf, t->lr,
236 t->rf, t->rr, t->loud);
237 buf[0] = TDA7432_IN; 242 buf[0] = TDA7432_IN;
238 buf[1] = t->input; 243 buf[1] = TDA7432_STEREO_IN | /* Main (stereo) input */
239 buf[2] = t->volume; 244 TDA7432_BASS_SYM | /* Symmetric bass cut */
240 buf[3] = t->bass; 245 TDA7432_BASS_NORM; /* Normal bass range */
241 buf[4] = t->treble; 246 buf[2] = 0x3b;
242 buf[5] = t->lf; 247 if (loudness) /* Turn loudness on? */
243 buf[6] = t->lr; 248 buf[2] |= TDA7432_LD_ON;
244 buf[7] = t->rf; 249 buf[3] = TDA7432_TREBLE_0DB | (TDA7432_BASS_0DB << 4);
245 buf[8] = t->rr; 250 buf[4] = TDA7432_ATTEN_0DB;
246 buf[9] = t->loud; 251 buf[5] = TDA7432_ATTEN_0DB;
247 if (10 != i2c_master_send(client, buf, 10)) { 252 buf[6] = TDA7432_ATTEN_0DB;
253 buf[7] = TDA7432_ATTEN_0DB;
254 buf[8] = loudness;
255 if (9 != i2c_master_send(client, buf, 9)) {
248 v4l2_err(sd, "I/O error, trying tda7432_set\n"); 256 v4l2_err(sd, "I/O error, trying tda7432_set\n");
249 return -1; 257 return -1;
250 } 258 }
@@ -252,174 +260,86 @@ static int tda7432_set(struct v4l2_subdev *sd)
252 return 0; 260 return 0;
253} 261}
254 262
255static void do_tda7432_init(struct v4l2_subdev *sd) 263static int tda7432_log_status(struct v4l2_subdev *sd)
256{
257 struct tda7432 *t = to_state(sd);
258
259 v4l2_dbg(2, debug, sd, "In tda7432_init\n");
260
261 t->input = TDA7432_STEREO_IN | /* Main (stereo) input */
262 TDA7432_BASS_SYM | /* Symmetric bass cut */
263 TDA7432_BASS_NORM; /* Normal bass range */
264 t->volume = 0x3b ; /* -27dB Volume */
265 if (loudness) /* Turn loudness on? */
266 t->volume |= TDA7432_LD_ON;
267 t->muted = 1;
268 t->treble = TDA7432_TREBLE_0DB; /* 0dB Treble */
269 t->bass = TDA7432_BASS_0DB; /* 0dB Bass */
270 t->lf = TDA7432_ATTEN_0DB; /* 0dB attenuation */
271 t->lr = TDA7432_ATTEN_0DB; /* 0dB attenuation */
272 t->rf = TDA7432_ATTEN_0DB; /* 0dB attenuation */
273 t->rr = TDA7432_ATTEN_0DB; /* 0dB attenuation */
274 t->loud = loudness; /* insmod parameter */
275
276 tda7432_set(sd);
277}
278
279static int tda7432_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
280{ 264{
281 struct tda7432 *t = to_state(sd); 265 struct tda7432 *state = to_state(sd);
282 266
283 switch (ctrl->id) { 267 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
284 case V4L2_CID_AUDIO_MUTE: 268 return 0;
285 ctrl->value=t->muted;
286 return 0;
287 case V4L2_CID_AUDIO_VOLUME:
288 if (!maxvol){ /* max +20db */
289 ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 630;
290 } else { /* max 0db */
291 ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 829;
292 }
293 return 0;
294 case V4L2_CID_AUDIO_BALANCE:
295 {
296 if ( (t->lf) < (t->rf) )
297 /* right is attenuated, balance shifted left */
298 ctrl->value = (32768 - 1057*(t->rf));
299 else
300 /* left is attenuated, balance shifted right */
301 ctrl->value = (32768 + 1057*(t->lf));
302 return 0;
303 }
304 case V4L2_CID_AUDIO_BASS:
305 {
306 /* Bass/treble 4 bits each */
307 int bass=t->bass;
308 if(bass >= 0x8)
309 bass = ~(bass - 0x8) & 0xf;
310 ctrl->value = (bass << 12)+(bass << 8)+(bass << 4)+(bass);
311 return 0;
312 }
313 case V4L2_CID_AUDIO_TREBLE:
314 {
315 int treble=t->treble;
316 if(treble >= 0x8)
317 treble = ~(treble - 0x8) & 0xf;
318 ctrl->value = (treble << 12)+(treble << 8)+(treble << 4)+(treble);
319 return 0;
320 }
321 }
322 return -EINVAL;
323} 269}
324 270
325static int tda7432_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 271static int tda7432_s_ctrl(struct v4l2_ctrl *ctrl)
326{ 272{
273 struct v4l2_subdev *sd = to_sd(ctrl);
327 struct tda7432 *t = to_state(sd); 274 struct tda7432 *t = to_state(sd);
275 u8 bass, treble, volume;
276 u8 lf, lr, rf, rr;
328 277
329 switch (ctrl->id) { 278 switch (ctrl->id) {
330 case V4L2_CID_AUDIO_MUTE: 279 case V4L2_CID_AUDIO_MUTE:
331 t->muted=ctrl->value; 280 if (t->balance->val < 0) {
332 break;
333 case V4L2_CID_AUDIO_VOLUME:
334 if(!maxvol){ /* max +20db */
335 t->volume = 0x6f - ((ctrl->value)/630);
336 } else { /* max 0db */
337 t->volume = 0x6f - ((ctrl->value)/829);
338 }
339 if (loudness) /* Turn on the loudness bit */
340 t->volume |= TDA7432_LD_ON;
341
342 tda7432_write(sd, TDA7432_VL, t->volume);
343 return 0;
344 case V4L2_CID_AUDIO_BALANCE:
345 if (ctrl->value < 32768) {
346 /* shifted to left, attenuate right */ 281 /* shifted to left, attenuate right */
347 t->rr = (32768 - ctrl->value)/1057; 282 rr = rf = -t->balance->val;
348 t->rf = t->rr; 283 lr = lf = TDA7432_ATTEN_0DB;
349 t->lr = TDA7432_ATTEN_0DB; 284 } else if (t->balance->val > 0) {
350 t->lf = TDA7432_ATTEN_0DB;
351 } else if(ctrl->value > 32769) {
352 /* shifted to right, attenuate left */ 285 /* shifted to right, attenuate left */
353 t->lf = (ctrl->value - 32768)/1057; 286 rr = rf = TDA7432_ATTEN_0DB;
354 t->lr = t->lf; 287 lr = lf = t->balance->val;
355 t->rr = TDA7432_ATTEN_0DB;
356 t->rf = TDA7432_ATTEN_0DB;
357 } else { 288 } else {
358 /* centered */ 289 /* centered */
359 t->rr = TDA7432_ATTEN_0DB; 290 rr = rf = TDA7432_ATTEN_0DB;
360 t->rf = TDA7432_ATTEN_0DB; 291 lr = lf = TDA7432_ATTEN_0DB;
361 t->lf = TDA7432_ATTEN_0DB;
362 t->lr = TDA7432_ATTEN_0DB;
363 } 292 }
364 break; 293 if (t->mute->val) {
365 case V4L2_CID_AUDIO_BASS: 294 lf |= TDA7432_MUTE;
366 t->bass = ctrl->value >> 12; 295 lr |= TDA7432_MUTE;
367 if(t->bass>= 0x8) 296 lf |= TDA7432_MUTE;
368 t->bass = (~t->bass & 0xf) + 0x8 ; 297 rr |= TDA7432_MUTE;
369 298 }
370 tda7432_write(sd, TDA7432_TN, 0x10 | (t->bass << 4) | t->treble); 299 /* Mute & update balance*/
300 tda7432_write(sd, TDA7432_LF, lf);
301 tda7432_write(sd, TDA7432_LR, lr);
302 tda7432_write(sd, TDA7432_RF, rf);
303 tda7432_write(sd, TDA7432_RR, rr);
371 return 0; 304 return 0;
372 case V4L2_CID_AUDIO_TREBLE: 305 case V4L2_CID_AUDIO_VOLUME:
373 t->treble= ctrl->value >> 12; 306 volume = 0x6f - ctrl->val;
374 if(t->treble>= 0x8) 307 if (loudness) /* Turn on the loudness bit */
375 t->treble = (~t->treble & 0xf) + 0x8 ; 308 volume |= TDA7432_LD_ON;
376 309
377 tda7432_write(sd, TDA7432_TN, 0x10 | (t->bass << 4) | t->treble); 310 tda7432_write(sd, TDA7432_VL, volume);
378 return 0; 311 return 0;
379 default:
380 return -EINVAL;
381 }
382
383 /* Used for both mute and balance changes */
384 if (t->muted)
385 {
386 /* Mute & update balance*/
387 tda7432_write(sd, TDA7432_LF, t->lf | TDA7432_MUTE);
388 tda7432_write(sd, TDA7432_LR, t->lr | TDA7432_MUTE);
389 tda7432_write(sd, TDA7432_RF, t->rf | TDA7432_MUTE);
390 tda7432_write(sd, TDA7432_RR, t->rr | TDA7432_MUTE);
391 } else {
392 tda7432_write(sd, TDA7432_LF, t->lf);
393 tda7432_write(sd, TDA7432_LR, t->lr);
394 tda7432_write(sd, TDA7432_RF, t->rf);
395 tda7432_write(sd, TDA7432_RR, t->rr);
396 }
397 return 0;
398}
399
400static int tda7432_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
401{
402 switch (qc->id) {
403 case V4L2_CID_AUDIO_VOLUME:
404 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
405 case V4L2_CID_AUDIO_MUTE:
406 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
407 case V4L2_CID_AUDIO_BALANCE:
408 case V4L2_CID_AUDIO_BASS: 312 case V4L2_CID_AUDIO_BASS:
409 case V4L2_CID_AUDIO_TREBLE: 313 bass = t->bass->val;
410 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768); 314 treble = t->treble->val;
315 if (bass >= 0x8)
316 bass = 14 - (bass - 8);
317 if (treble >= 0x8)
318 treble = 14 - (treble - 8);
319
320 tda7432_write(sd, TDA7432_TN, 0x10 | (bass << 4) | treble);
321 return 0;
411 } 322 }
412 return -EINVAL; 323 return -EINVAL;
413} 324}
414 325
415/* ----------------------------------------------------------------------- */ 326/* ----------------------------------------------------------------------- */
416 327
417static const struct v4l2_subdev_core_ops tda7432_core_ops = { 328static const struct v4l2_ctrl_ops tda7432_ctrl_ops = {
418 .queryctrl = tda7432_queryctrl,
419 .g_ctrl = tda7432_g_ctrl,
420 .s_ctrl = tda7432_s_ctrl, 329 .s_ctrl = tda7432_s_ctrl,
421}; 330};
422 331
332static const struct v4l2_subdev_core_ops tda7432_core_ops = {
333 .log_status = tda7432_log_status,
334 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
335 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
336 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
337 .g_ctrl = v4l2_subdev_g_ctrl,
338 .s_ctrl = v4l2_subdev_s_ctrl,
339 .queryctrl = v4l2_subdev_queryctrl,
340 .querymenu = v4l2_subdev_querymenu,
341};
342
423static const struct v4l2_subdev_ops tda7432_ops = { 343static const struct v4l2_subdev_ops tda7432_ops = {
424 .core = &tda7432_core_ops, 344 .core = &tda7432_core_ops,
425}; 345};
@@ -444,6 +364,28 @@ static int tda7432_probe(struct i2c_client *client,
444 return -ENOMEM; 364 return -ENOMEM;
445 sd = &t->sd; 365 sd = &t->sd;
446 v4l2_i2c_subdev_init(sd, client, &tda7432_ops); 366 v4l2_i2c_subdev_init(sd, client, &tda7432_ops);
367 v4l2_ctrl_handler_init(&t->hdl, 5);
368 v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
369 V4L2_CID_AUDIO_VOLUME, 0, maxvol ? 0x68 : 0x4f, 1, maxvol ? 0x5d : 0x47);
370 t->mute = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
371 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
372 t->balance = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
373 V4L2_CID_AUDIO_BALANCE, -31, 31, 1, 0);
374 t->bass = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
375 V4L2_CID_AUDIO_BASS, 0, 14, 1, 7);
376 t->treble = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
377 V4L2_CID_AUDIO_TREBLE, 0, 14, 1, 7);
378 sd->ctrl_handler = &t->hdl;
379 if (t->hdl.error) {
380 int err = t->hdl.error;
381
382 v4l2_ctrl_handler_free(&t->hdl);
383 kfree(t);
384 return err;
385 }
386 v4l2_ctrl_cluster(2, &t->bass);
387 v4l2_ctrl_cluster(2, &t->mute);
388 v4l2_ctrl_handler_setup(&t->hdl);
447 if (loudness < 0 || loudness > 15) { 389 if (loudness < 0 || loudness > 15) {
448 v4l2_warn(sd, "loudness parameter must be between 0 and 15\n"); 390 v4l2_warn(sd, "loudness parameter must be between 0 and 15\n");
449 if (loudness < 0) 391 if (loudness < 0)
@@ -452,17 +394,19 @@ static int tda7432_probe(struct i2c_client *client,
452 loudness = 15; 394 loudness = 15;
453 } 395 }
454 396
455 do_tda7432_init(sd); 397 tda7432_set(sd);
456 return 0; 398 return 0;
457} 399}
458 400
459static int tda7432_remove(struct i2c_client *client) 401static int tda7432_remove(struct i2c_client *client)
460{ 402{
461 struct v4l2_subdev *sd = i2c_get_clientdata(client); 403 struct v4l2_subdev *sd = i2c_get_clientdata(client);
404 struct tda7432 *t = to_state(sd);
462 405
463 do_tda7432_init(sd); 406 tda7432_set(sd);
464 v4l2_device_unregister_subdev(sd); 407 v4l2_device_unregister_subdev(sd);
465 kfree(to_state(sd)); 408 v4l2_ctrl_handler_free(&t->hdl);
409 kfree(t);
466 return 0; 410 return 0;
467} 411}
468 412
diff --git a/drivers/media/i2c/tda9840.c b/drivers/media/i2c/tda9840.c
index 3d7ddd93282d..01441e35d88b 100644
--- a/drivers/media/i2c/tda9840.c
+++ b/drivers/media/i2c/tda9840.c
@@ -87,7 +87,7 @@ static int tda9840_status(struct v4l2_subdev *sd)
87 return byte & 0x60; 87 return byte & 0x60;
88} 88}
89 89
90static int tda9840_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *t) 90static int tda9840_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *t)
91{ 91{
92 int stat = tda9840_status(sd); 92 int stat = tda9840_status(sd);
93 int byte; 93 int byte;
diff --git a/drivers/media/i2c/ths7303.c b/drivers/media/i2c/ths7303.c
index e747524ba6ed..c4339556a2ea 100644
--- a/drivers/media/i2c/ths7303.c
+++ b/drivers/media/i2c/ths7303.c
@@ -1,7 +1,15 @@
1/* 1/*
2 * ths7303- THS7303 Video Amplifier driver 2 * ths7303/53- THS7303/53 Video Amplifier driver
3 * 3 *
4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
5 * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
6 *
7 * Author: Chaithrika U S <chaithrika@ti.com>
8 *
9 * Contributors:
10 * Hans Verkuil <hans.verkuil@cisco.com>
11 * Lad, Prabhakar <prabhakar.lad@ti.com>
12 * Martin Bugge <marbugge@cisco.com>
5 * 13 *
6 * This program is free software; you can redistribute it and/or 14 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 15 * modify it under the terms of the GNU General Public License as
@@ -13,25 +21,27 @@
13 * GNU General Public License for more details. 21 * GNU General Public License for more details.
14 */ 22 */
15 23
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/ctype.h>
19#include <linux/slab.h>
20#include <linux/i2c.h> 24#include <linux/i2c.h>
21#include <linux/device.h>
22#include <linux/delay.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/uaccess.h> 26#include <linux/slab.h>
25#include <linux/videodev2.h>
26 27
27#include <media/v4l2-device.h> 28#include <media/ths7303.h>
28#include <media/v4l2-subdev.h>
29#include <media/v4l2-chip-ident.h> 29#include <media/v4l2-chip-ident.h>
30#include <media/v4l2-device.h>
30 31
31#define THS7303_CHANNEL_1 1 32#define THS7303_CHANNEL_1 1
32#define THS7303_CHANNEL_2 2 33#define THS7303_CHANNEL_2 2
33#define THS7303_CHANNEL_3 3 34#define THS7303_CHANNEL_3 3
34 35
36struct ths7303_state {
37 struct v4l2_subdev sd;
38 struct ths7303_platform_data pdata;
39 struct v4l2_bt_timings bt;
40 int std_id;
41 int stream_on;
42 int driver_data;
43};
44
35enum ths7303_filter_mode { 45enum ths7303_filter_mode {
36 THS7303_FILTER_MODE_480I_576I, 46 THS7303_FILTER_MODE_480I_576I,
37 THS7303_FILTER_MODE_480P_576P, 47 THS7303_FILTER_MODE_480P_576P,
@@ -48,64 +58,84 @@ static int debug;
48module_param(debug, int, 0644); 58module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug, "Debug level 0-1"); 59MODULE_PARM_DESC(debug, "Debug level 0-1");
50 60
61static inline struct ths7303_state *to_state(struct v4l2_subdev *sd)
62{
63 return container_of(sd, struct ths7303_state, sd);
64}
65
66static int ths7303_read(struct v4l2_subdev *sd, u8 reg)
67{
68 struct i2c_client *client = v4l2_get_subdevdata(sd);
69
70 return i2c_smbus_read_byte_data(client, reg);
71}
72
73static int ths7303_write(struct v4l2_subdev *sd, u8 reg, u8 val)
74{
75 struct i2c_client *client = v4l2_get_subdevdata(sd);
76 int ret;
77 int i;
78
79 for (i = 0; i < 3; i++) {
80 ret = i2c_smbus_write_byte_data(client, reg, val);
81 if (ret == 0)
82 return 0;
83 }
84 return ret;
85}
86
51/* following function is used to set ths7303 */ 87/* following function is used to set ths7303 */
52int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode) 88int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode)
53{ 89{
54 u8 input_bias_chroma = 3;
55 u8 input_bias_luma = 3;
56 int disable = 0;
57 int err = 0;
58 u8 val = 0;
59 u8 temp;
60
61 struct i2c_client *client = v4l2_get_subdevdata(sd); 90 struct i2c_client *client = v4l2_get_subdevdata(sd);
91 struct ths7303_state *state = to_state(sd);
92 struct ths7303_platform_data *pdata = &state->pdata;
93 u8 val, sel = 0;
94 int err, disable = 0;
62 95
63 if (!client) 96 if (!client)
64 return -EINVAL; 97 return -EINVAL;
65 98
66 switch (mode) { 99 switch (mode) {
67 case THS7303_FILTER_MODE_1080P: 100 case THS7303_FILTER_MODE_1080P:
68 val = (3 << 6); 101 sel = 0x3; /*1080p and SXGA/UXGA */
69 val |= (3 << 3);
70 break; 102 break;
71 case THS7303_FILTER_MODE_720P_1080I: 103 case THS7303_FILTER_MODE_720P_1080I:
72 val = (2 << 6); 104 sel = 0x2; /*720p, 1080i and SVGA/XGA */
73 val |= (2 << 3);
74 break; 105 break;
75 case THS7303_FILTER_MODE_480P_576P: 106 case THS7303_FILTER_MODE_480P_576P:
76 val = (1 << 6); 107 sel = 0x1; /* EDTV 480p/576p and VGA */
77 val |= (1 << 3);
78 break; 108 break;
79 case THS7303_FILTER_MODE_480I_576I: 109 case THS7303_FILTER_MODE_480I_576I:
110 sel = 0x0; /* SDTV, S-Video, 480i/576i */
80 break; 111 break;
81 case THS7303_FILTER_MODE_DISABLE:
82 pr_info("mode disabled\n");
83 /* disable all channels */
84 disable = 1;
85 default: 112 default:
86 /* disable all channels */ 113 /* disable all channels */
87 disable = 1; 114 disable = 1;
88 } 115 }
89 /* Setup channel 2 - Luma - Green */ 116
90 temp = val; 117 val = (sel << 6) | (sel << 3);
91 if (!disable) 118 if (!disable)
92 val |= input_bias_luma; 119 val |= (pdata->ch_1 & 0x27);
93 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_2, val); 120 err = ths7303_write(sd, THS7303_CHANNEL_1, val);
94 if (err) 121 if (err)
95 goto out; 122 goto out;
96 123
97 /* setup two chroma channels */ 124 val = (sel << 6) | (sel << 3);
98 if (!disable) 125 if (!disable)
99 temp |= input_bias_chroma; 126 val |= (pdata->ch_2 & 0x27);
100 127 err = ths7303_write(sd, THS7303_CHANNEL_2, val);
101 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_1, temp);
102 if (err) 128 if (err)
103 goto out; 129 goto out;
104 130
105 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_3, temp); 131 val = (sel << 6) | (sel << 3);
132 if (!disable)
133 val |= (pdata->ch_3 & 0x27);
134 err = ths7303_write(sd, THS7303_CHANNEL_3, val);
106 if (err) 135 if (err)
107 goto out; 136 goto out;
108 return err; 137
138 return 0;
109out: 139out:
110 pr_info("write byte data failed\n"); 140 pr_info("write byte data failed\n");
111 return err; 141 return err;
@@ -113,49 +143,209 @@ out:
113 143
114static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm) 144static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm)
115{ 145{
116 if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM)) 146 struct ths7303_state *state = to_state(sd);
147
148 if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM)) {
149 state->std_id = 1;
150 state->bt.pixelclock = 0;
117 return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I); 151 return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I);
118 else 152 }
119 return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE); 153
154 return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
120} 155}
121 156
122/* for setting filter for HD output */ 157static int ths7303_config(struct v4l2_subdev *sd)
123static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
124 struct v4l2_dv_timings *dv_timings)
125{ 158{
126 u32 height = dv_timings->bt.height; 159 struct ths7303_state *state = to_state(sd);
127 int interlaced = dv_timings->bt.interlaced; 160 int res;
128 int res = 0; 161
162 if (!state->stream_on) {
163 ths7303_write(sd, THS7303_CHANNEL_1,
164 (ths7303_read(sd, THS7303_CHANNEL_1) & 0xf8) |
165 0x00);
166 ths7303_write(sd, THS7303_CHANNEL_2,
167 (ths7303_read(sd, THS7303_CHANNEL_2) & 0xf8) |
168 0x00);
169 ths7303_write(sd, THS7303_CHANNEL_3,
170 (ths7303_read(sd, THS7303_CHANNEL_3) & 0xf8) |
171 0x00);
172 return 0;
173 }
129 174
130 if (height == 1080 && !interlaced) 175 if (state->bt.pixelclock > 120000000)
131 res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P); 176 res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P);
132 else if ((height == 720 && !interlaced) || 177 else if (state->bt.pixelclock > 70000000)
133 (height == 1080 && interlaced))
134 res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I); 178 res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I);
135 else if ((height == 480 || height == 576) && !interlaced) 179 else if (state->bt.pixelclock > 20000000)
136 res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P); 180 res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P);
181 else if (state->std_id)
182 res = ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I);
137 else 183 else
138 /* disable all channels */ 184 /* disable all channels */
139 res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE); 185 res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
140 186
141 return res; 187 return res;
188
189}
190
191static int ths7303_s_stream(struct v4l2_subdev *sd, int enable)
192{
193 struct ths7303_state *state = to_state(sd);
194
195 state->stream_on = enable;
196
197 return ths7303_config(sd);
198}
199
200/* for setting filter for HD output */
201static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
202 struct v4l2_dv_timings *dv_timings)
203{
204 struct ths7303_state *state = to_state(sd);
205
206 if (!dv_timings || dv_timings->type != V4L2_DV_BT_656_1120)
207 return -EINVAL;
208
209 state->bt = dv_timings->bt;
210 state->std_id = 0;
211
212 return ths7303_config(sd);
142} 213}
143 214
144static int ths7303_g_chip_ident(struct v4l2_subdev *sd, 215static int ths7303_g_chip_ident(struct v4l2_subdev *sd,
145 struct v4l2_dbg_chip_ident *chip) 216 struct v4l2_dbg_chip_ident *chip)
146{ 217{
147 struct i2c_client *client = v4l2_get_subdevdata(sd); 218 struct i2c_client *client = v4l2_get_subdevdata(sd);
219 struct ths7303_state *state = to_state(sd);
148 220
149 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_THS7303, 0); 221 return v4l2_chip_ident_i2c_client(client, chip, state->driver_data, 0);
150} 222}
151 223
152static const struct v4l2_subdev_video_ops ths7303_video_ops = { 224static const struct v4l2_subdev_video_ops ths7303_video_ops = {
225 .s_stream = ths7303_s_stream,
153 .s_std_output = ths7303_s_std_output, 226 .s_std_output = ths7303_s_std_output,
154 .s_dv_timings = ths7303_s_dv_timings, 227 .s_dv_timings = ths7303_s_dv_timings,
155}; 228};
156 229
230#ifdef CONFIG_VIDEO_ADV_DEBUG
231
232static int ths7303_g_register(struct v4l2_subdev *sd,
233 struct v4l2_dbg_register *reg)
234{
235 struct i2c_client *client = v4l2_get_subdevdata(sd);
236
237 if (!v4l2_chip_match_i2c_client(client, &reg->match))
238 return -EINVAL;
239 if (!capable(CAP_SYS_ADMIN))
240 return -EPERM;
241
242 reg->size = 1;
243 reg->val = ths7303_read(sd, reg->reg);
244 return 0;
245}
246
247static int ths7303_s_register(struct v4l2_subdev *sd,
248 const struct v4l2_dbg_register *reg)
249{
250 struct i2c_client *client = v4l2_get_subdevdata(sd);
251
252 if (!v4l2_chip_match_i2c_client(client, &reg->match))
253 return -EINVAL;
254 if (!capable(CAP_SYS_ADMIN))
255 return -EPERM;
256
257 ths7303_write(sd, reg->reg, reg->val);
258 return 0;
259}
260#endif
261
262static const char * const stc_lpf_sel_txt[4] = {
263 "500-kHz Filter",
264 "2.5-MHz Filter",
265 "5-MHz Filter",
266 "5-MHz Filter",
267};
268
269static const char * const in_mux_sel_txt[2] = {
270 "Input A Select",
271 "Input B Select",
272};
273
274static const char * const lpf_freq_sel_txt[4] = {
275 "9-MHz LPF",
276 "16-MHz LPF",
277 "35-MHz LPF",
278 "Bypass LPF",
279};
280
281static const char * const in_bias_sel_dis_cont_txt[8] = {
282 "Disable Channel",
283 "Mute Function - No Output",
284 "DC Bias Select",
285 "DC Bias + 250 mV Offset Select",
286 "AC Bias Select",
287 "Sync Tip Clamp with low bias",
288 "Sync Tip Clamp with mid bias",
289 "Sync Tip Clamp with high bias",
290};
291
292static void ths7303_log_channel_status(struct v4l2_subdev *sd, u8 reg)
293{
294 u8 val = ths7303_read(sd, reg);
295
296 if ((val & 0x7) == 0) {
297 v4l2_info(sd, "Channel %d Off\n", reg);
298 return;
299 }
300
301 v4l2_info(sd, "Channel %d On\n", reg);
302 v4l2_info(sd, " value 0x%x\n", val);
303 v4l2_info(sd, " %s\n", stc_lpf_sel_txt[(val >> 6) & 0x3]);
304 v4l2_info(sd, " %s\n", in_mux_sel_txt[(val >> 5) & 0x1]);
305 v4l2_info(sd, " %s\n", lpf_freq_sel_txt[(val >> 3) & 0x3]);
306 v4l2_info(sd, " %s\n", in_bias_sel_dis_cont_txt[(val >> 0) & 0x7]);
307}
308
309static int ths7303_log_status(struct v4l2_subdev *sd)
310{
311 struct ths7303_state *state = to_state(sd);
312
313 v4l2_info(sd, "stream %s\n", state->stream_on ? "On" : "Off");
314
315 if (state->bt.pixelclock) {
316 struct v4l2_bt_timings *bt = bt = &state->bt;
317 u32 frame_width, frame_height;
318
319 frame_width = bt->width + bt->hfrontporch +
320 bt->hsync + bt->hbackporch;
321 frame_height = bt->height + bt->vfrontporch +
322 bt->vsync + bt->vbackporch;
323 v4l2_info(sd,
324 "timings: %dx%d%s%d (%dx%d). Pix freq. = %d Hz. Polarities = 0x%x\n",
325 bt->width, bt->height, bt->interlaced ? "i" : "p",
326 (frame_height * frame_width) > 0 ?
327 (int)bt->pixelclock /
328 (frame_height * frame_width) : 0,
329 frame_width, frame_height,
330 (int)bt->pixelclock, bt->polarities);
331 } else {
332 v4l2_info(sd, "no timings set\n");
333 }
334
335 ths7303_log_channel_status(sd, THS7303_CHANNEL_1);
336 ths7303_log_channel_status(sd, THS7303_CHANNEL_2);
337 ths7303_log_channel_status(sd, THS7303_CHANNEL_3);
338
339 return 0;
340}
341
157static const struct v4l2_subdev_core_ops ths7303_core_ops = { 342static const struct v4l2_subdev_core_ops ths7303_core_ops = {
158 .g_chip_ident = ths7303_g_chip_ident, 343 .g_chip_ident = ths7303_g_chip_ident,
344 .log_status = ths7303_log_status,
345#ifdef CONFIG_VIDEO_ADV_DEBUG
346 .g_register = ths7303_g_register,
347 .s_register = ths7303_s_register,
348#endif
159}; 349};
160 350
161static const struct v4l2_subdev_ops ths7303_ops = { 351static const struct v4l2_subdev_ops ths7303_ops = {
@@ -163,11 +353,38 @@ static const struct v4l2_subdev_ops ths7303_ops = {
163 .video = &ths7303_video_ops, 353 .video = &ths7303_video_ops,
164}; 354};
165 355
356static int ths7303_setup(struct v4l2_subdev *sd)
357{
358 struct ths7303_state *state = to_state(sd);
359 struct ths7303_platform_data *pdata = &state->pdata;
360 int ret;
361 u8 mask;
362
363 state->stream_on = pdata->init_enable;
364
365 mask = state->stream_on ? 0xff : 0xf8;
366
367 ret = ths7303_write(sd, THS7303_CHANNEL_1, pdata->ch_1 & mask);
368 if (ret)
369 return ret;
370
371 ret = ths7303_write(sd, THS7303_CHANNEL_2, pdata->ch_2 & mask);
372 if (ret)
373 return ret;
374
375 ret = ths7303_write(sd, THS7303_CHANNEL_3, pdata->ch_3 & mask);
376 if (ret)
377 return ret;
378
379 return 0;
380}
381
166static int ths7303_probe(struct i2c_client *client, 382static int ths7303_probe(struct i2c_client *client,
167 const struct i2c_device_id *id) 383 const struct i2c_device_id *id)
168{ 384{
385 struct ths7303_platform_data *pdata = client->dev.platform_data;
386 struct ths7303_state *state;
169 struct v4l2_subdev *sd; 387 struct v4l2_subdev *sd;
170 v4l2_std_id std_id = V4L2_STD_NTSC;
171 388
172 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 389 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
173 return -ENODEV; 390 return -ENODEV;
@@ -175,13 +392,28 @@ static int ths7303_probe(struct i2c_client *client,
175 v4l_info(client, "chip found @ 0x%x (%s)\n", 392 v4l_info(client, "chip found @ 0x%x (%s)\n",
176 client->addr << 1, client->adapter->name); 393 client->addr << 1, client->adapter->name);
177 394
178 sd = devm_kzalloc(&client->dev, sizeof(struct v4l2_subdev), GFP_KERNEL); 395 state = devm_kzalloc(&client->dev, sizeof(struct ths7303_state),
179 if (sd == NULL) 396 GFP_KERNEL);
397 if (!state)
180 return -ENOMEM; 398 return -ENOMEM;
181 399
400 if (!pdata)
401 v4l_warn(client, "No platform data, using default data!\n");
402 else
403 state->pdata = *pdata;
404
405 sd = &state->sd;
182 v4l2_i2c_subdev_init(sd, client, &ths7303_ops); 406 v4l2_i2c_subdev_init(sd, client, &ths7303_ops);
183 407
184 return ths7303_s_std_output(sd, std_id); 408 /* store the driver data to differntiate the chip */
409 state->driver_data = (int)id->driver_data;
410
411 if (ths7303_setup(sd) < 0) {
412 v4l_err(client, "init failed\n");
413 return -EIO;
414 }
415
416 return 0;
185} 417}
186 418
187static int ths7303_remove(struct i2c_client *client) 419static int ths7303_remove(struct i2c_client *client)
@@ -194,7 +426,8 @@ static int ths7303_remove(struct i2c_client *client)
194} 426}
195 427
196static const struct i2c_device_id ths7303_id[] = { 428static const struct i2c_device_id ths7303_id[] = {
197 {"ths7303", 0}, 429 {"ths7303", V4L2_IDENT_THS7303},
430 {"ths7353", V4L2_IDENT_THS7353},
198 {}, 431 {},
199}; 432};
200 433
@@ -203,7 +436,7 @@ MODULE_DEVICE_TABLE(i2c, ths7303_id);
203static struct i2c_driver ths7303_driver = { 436static struct i2c_driver ths7303_driver = {
204 .driver = { 437 .driver = {
205 .owner = THIS_MODULE, 438 .owner = THIS_MODULE,
206 .name = "ths7303", 439 .name = "ths73x3",
207 }, 440 },
208 .probe = ths7303_probe, 441 .probe = ths7303_probe,
209 .remove = ths7303_remove, 442 .remove = ths7303_remove,
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index e3b33b78dd21..b72a59d3216a 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -1761,7 +1761,7 @@ static int tvaudio_s_routing(struct v4l2_subdev *sd,
1761 return 0; 1761 return 0;
1762} 1762}
1763 1763
1764static int tvaudio_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1764static int tvaudio_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1765{ 1765{
1766 struct CHIPSTATE *chip = to_state(sd); 1766 struct CHIPSTATE *chip = to_state(sd);
1767 struct CHIPDESC *desc = chip->desc; 1767 struct CHIPDESC *desc = chip->desc;
@@ -1803,7 +1803,7 @@ static int tvaudio_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1803 1803
1804 vt->audmode = chip->audmode; 1804 vt->audmode = chip->audmode;
1805 vt->rxsubchans = desc->getrxsubchans(chip); 1805 vt->rxsubchans = desc->getrxsubchans(chip);
1806 vt->capability = V4L2_TUNER_CAP_STEREO | 1806 vt->capability |= V4L2_TUNER_CAP_STEREO |
1807 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; 1807 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
1808 1808
1809 return 0; 1809 return 0;
@@ -1817,7 +1817,7 @@ static int tvaudio_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1817 return 0; 1817 return 0;
1818} 1818}
1819 1819
1820static int tvaudio_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 1820static int tvaudio_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
1821{ 1821{
1822 struct CHIPSTATE *chip = to_state(sd); 1822 struct CHIPSTATE *chip = to_state(sd);
1823 struct CHIPDESC *desc = chip->desc; 1823 struct CHIPDESC *desc = chip->desc;
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index aa94ebc2d755..ab8f3fee7e94 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -12,6 +12,7 @@
12 * Hardik Shah <hardik.shah@ti.com> 12 * Hardik Shah <hardik.shah@ti.com>
13 * Manjunath Hadli <mrh@ti.com> 13 * Manjunath Hadli <mrh@ti.com>
14 * Karicheri Muralidharan <m-karicheri2@ti.com> 14 * Karicheri Muralidharan <m-karicheri2@ti.com>
15 * Prabhakar Lad <prabhakar.lad@ti.com>
15 * 16 *
16 * This package is free software; you can redistribute it and/or modify 17 * This package is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as 18 * it under the terms of the GNU General Public License version 2 as
@@ -33,6 +34,7 @@
33#include <linux/delay.h> 34#include <linux/delay.h>
34#include <linux/videodev2.h> 35#include <linux/videodev2.h>
35#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/v4l2-mediabus.h>
36 38
37#include <media/v4l2-device.h> 39#include <media/v4l2-device.h>
38#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
@@ -40,12 +42,10 @@
40#include <media/v4l2-chip-ident.h> 42#include <media/v4l2-chip-ident.h>
41#include <media/v4l2-ctrls.h> 43#include <media/v4l2-ctrls.h>
42#include <media/tvp514x.h> 44#include <media/tvp514x.h>
45#include <media/media-entity.h>
43 46
44#include "tvp514x_regs.h" 47#include "tvp514x_regs.h"
45 48
46/* Module Name */
47#define TVP514X_MODULE_NAME "tvp514x"
48
49/* Private macros for TVP */ 49/* Private macros for TVP */
50#define I2C_RETRY_COUNT (5) 50#define I2C_RETRY_COUNT (5)
51#define LOCK_RETRY_COUNT (5) 51#define LOCK_RETRY_COUNT (5)
@@ -91,6 +91,9 @@ static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
91 * @pdata: Board specific 91 * @pdata: Board specific
92 * @ver: Chip version 92 * @ver: Chip version
93 * @streaming: TVP5146/47 decoder streaming - enabled or disabled. 93 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
94 * @pix: Current pixel format
95 * @num_fmts: Number of formats
96 * @fmt_list: Format list
94 * @current_std: Current standard 97 * @current_std: Current standard
95 * @num_stds: Number of standards 98 * @num_stds: Number of standards
96 * @std_list: Standards list 99 * @std_list: Standards list
@@ -106,12 +109,20 @@ struct tvp514x_decoder {
106 int ver; 109 int ver;
107 int streaming; 110 int streaming;
108 111
112 struct v4l2_pix_format pix;
113 int num_fmts;
114 const struct v4l2_fmtdesc *fmt_list;
115
109 enum tvp514x_std current_std; 116 enum tvp514x_std current_std;
110 int num_stds; 117 int num_stds;
111 const struct tvp514x_std_info *std_list; 118 const struct tvp514x_std_info *std_list;
112 /* Input and Output Routing parameters */ 119 /* Input and Output Routing parameters */
113 u32 input; 120 u32 input;
114 u32 output; 121 u32 output;
122
123 /* mc related members */
124 struct media_pad pad;
125 struct v4l2_mbus_framefmt format;
115}; 126};
116 127
117/* TVP514x default register values */ 128/* TVP514x default register values */
@@ -200,6 +211,21 @@ static struct tvp514x_reg tvp514x_reg_list_default[] = {
200}; 211};
201 212
202/** 213/**
214 * List of image formats supported by TVP5146/47 decoder
215 * Currently we are using 8 bit mode only, but can be
216 * extended to 10/20 bit mode.
217 */
218static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
219 {
220 .index = 0,
221 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
222 .flags = 0,
223 .description = "8-bit UYVY 4:2:2 Format",
224 .pixelformat = V4L2_PIX_FMT_UYVY,
225 },
226};
227
228/**
203 * Supported standards - 229 * Supported standards -
204 * 230 *
205 * Currently supports two standards only, need to add support for rest of the 231 * Currently supports two standards only, need to add support for rest of the
@@ -733,7 +759,7 @@ tvp514x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
733} 759}
734 760
735/** 761/**
736 * tvp514x_mbus_fmt_cap() - V4L2 decoder interface handler for try/s/g_mbus_fmt 762 * tvp514x_mbus_fmt() - V4L2 decoder interface handler for try/s/g_mbus_fmt
737 * @sd: pointer to standard V4L2 sub-device structure 763 * @sd: pointer to standard V4L2 sub-device structure
738 * @f: pointer to the mediabus format structure 764 * @f: pointer to the mediabus format structure
739 * 765 *
@@ -751,12 +777,11 @@ tvp514x_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
751 /* Calculate height and width based on current standard */ 777 /* Calculate height and width based on current standard */
752 current_std = decoder->current_std; 778 current_std = decoder->current_std;
753 779
754 f->code = V4L2_MBUS_FMT_YUYV10_2X10; 780 f->code = V4L2_MBUS_FMT_YUYV8_2X8;
755 f->width = decoder->std_list[current_std].width; 781 f->width = decoder->std_list[current_std].width;
756 f->height = decoder->std_list[current_std].height; 782 f->height = decoder->std_list[current_std].height;
757 f->field = V4L2_FIELD_INTERLACED; 783 f->field = V4L2_FIELD_INTERLACED;
758 f->colorspace = V4L2_COLORSPACE_SMPTE170M; 784 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
759
760 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n", 785 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n",
761 f->width, f->height); 786 f->width, f->height);
762 return 0; 787 return 0;
@@ -892,6 +917,88 @@ static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = {
892 .s_ctrl = tvp514x_s_ctrl, 917 .s_ctrl = tvp514x_s_ctrl,
893}; 918};
894 919
920/**
921 * tvp514x_enum_mbus_code() - V4L2 decoder interface handler for enum_mbus_code
922 * @sd: pointer to standard V4L2 sub-device structure
923 * @fh: file handle
924 * @code: pointer to v4l2_subdev_mbus_code_enum structure
925 *
926 * Enumertaes mbus codes supported
927 */
928static int tvp514x_enum_mbus_code(struct v4l2_subdev *sd,
929 struct v4l2_subdev_fh *fh,
930 struct v4l2_subdev_mbus_code_enum *code)
931{
932 u32 pad = code->pad;
933 u32 index = code->index;
934
935 memset(code, 0, sizeof(*code));
936 code->index = index;
937 code->pad = pad;
938
939 if (index != 0)
940 return -EINVAL;
941
942 code->code = V4L2_MBUS_FMT_YUYV8_2X8;
943
944 return 0;
945}
946
947/**
948 * tvp514x_get_pad_format() - V4L2 decoder interface handler for get pad format
949 * @sd: pointer to standard V4L2 sub-device structure
950 * @fh: file handle
951 * @format: pointer to v4l2_subdev_format structure
952 *
953 * Retrieves pad format which is active or tried based on requirement
954 */
955static int tvp514x_get_pad_format(struct v4l2_subdev *sd,
956 struct v4l2_subdev_fh *fh,
957 struct v4l2_subdev_format *format)
958{
959 struct tvp514x_decoder *decoder = to_decoder(sd);
960 __u32 which = format->which;
961
962 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
963 format->format = decoder->format;
964 return 0;
965 }
966
967 format->format.code = V4L2_MBUS_FMT_YUYV8_2X8;
968 format->format.width = tvp514x_std_list[decoder->current_std].width;
969 format->format.height = tvp514x_std_list[decoder->current_std].height;
970 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
971 format->format.field = V4L2_FIELD_INTERLACED;
972
973 return 0;
974}
975
976/**
977 * tvp514x_set_pad_format() - V4L2 decoder interface handler for set pad format
978 * @sd: pointer to standard V4L2 sub-device structure
979 * @fh: file handle
980 * @format: pointer to v4l2_subdev_format structure
981 *
982 * Set pad format for the output pad
983 */
984static int tvp514x_set_pad_format(struct v4l2_subdev *sd,
985 struct v4l2_subdev_fh *fh,
986 struct v4l2_subdev_format *fmt)
987{
988 struct tvp514x_decoder *decoder = to_decoder(sd);
989
990 if (fmt->format.field != V4L2_FIELD_INTERLACED ||
991 fmt->format.code != V4L2_MBUS_FMT_YUYV8_2X8 ||
992 fmt->format.colorspace != V4L2_COLORSPACE_SMPTE170M ||
993 fmt->format.width != tvp514x_std_list[decoder->current_std].width ||
994 fmt->format.height != tvp514x_std_list[decoder->current_std].height)
995 return -EINVAL;
996
997 decoder->format = fmt->format;
998
999 return 0;
1000}
1001
895static const struct v4l2_subdev_core_ops tvp514x_core_ops = { 1002static const struct v4l2_subdev_core_ops tvp514x_core_ops = {
896 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 1003 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
897 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 1004 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
@@ -915,13 +1022,33 @@ static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
915 .s_stream = tvp514x_s_stream, 1022 .s_stream = tvp514x_s_stream,
916}; 1023};
917 1024
1025static const struct v4l2_subdev_pad_ops tvp514x_pad_ops = {
1026 .enum_mbus_code = tvp514x_enum_mbus_code,
1027 .get_fmt = tvp514x_get_pad_format,
1028 .set_fmt = tvp514x_set_pad_format,
1029};
1030
918static const struct v4l2_subdev_ops tvp514x_ops = { 1031static const struct v4l2_subdev_ops tvp514x_ops = {
919 .core = &tvp514x_core_ops, 1032 .core = &tvp514x_core_ops,
920 .video = &tvp514x_video_ops, 1033 .video = &tvp514x_video_ops,
1034 .pad = &tvp514x_pad_ops,
921}; 1035};
922 1036
923static struct tvp514x_decoder tvp514x_dev = { 1037static struct tvp514x_decoder tvp514x_dev = {
924 .streaming = 0, 1038 .streaming = 0,
1039 .fmt_list = tvp514x_fmt_list,
1040 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
1041 .pix = {
1042 /* Default to NTSC 8-bit YUV 422 */
1043 .width = NTSC_NUM_ACTIVE_PIXELS,
1044 .height = NTSC_NUM_ACTIVE_LINES,
1045 .pixelformat = V4L2_PIX_FMT_UYVY,
1046 .field = V4L2_FIELD_INTERLACED,
1047 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
1048 .sizeimage = NTSC_NUM_ACTIVE_PIXELS * 2 *
1049 NTSC_NUM_ACTIVE_LINES,
1050 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1051 },
925 .current_std = STD_NTSC_MJ, 1052 .current_std = STD_NTSC_MJ,
926 .std_list = tvp514x_std_list, 1053 .std_list = tvp514x_std_list,
927 .num_stds = ARRAY_SIZE(tvp514x_std_list), 1054 .num_stds = ARRAY_SIZE(tvp514x_std_list),
@@ -941,6 +1068,7 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
941{ 1068{
942 struct tvp514x_decoder *decoder; 1069 struct tvp514x_decoder *decoder;
943 struct v4l2_subdev *sd; 1070 struct v4l2_subdev *sd;
1071 int ret;
944 1072
945 /* Check if the adapter supports the needed features */ 1073 /* Check if the adapter supports the needed features */
946 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1074 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -981,7 +1109,21 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
981 /* Register with V4L2 layer as slave device */ 1109 /* Register with V4L2 layer as slave device */
982 sd = &decoder->sd; 1110 sd = &decoder->sd;
983 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); 1111 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
984 1112 strlcpy(sd->name, TVP514X_MODULE_NAME, sizeof(sd->name));
1113
1114#if defined(CONFIG_MEDIA_CONTROLLER)
1115 decoder->pad.flags = MEDIA_PAD_FL_SOURCE;
1116 decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1117 decoder->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
1118
1119 ret = media_entity_init(&decoder->sd.entity, 1, &decoder->pad, 0);
1120 if (ret < 0) {
1121 v4l2_err(sd, "%s decoder driver failed to register !!\n",
1122 sd->name);
1123 kfree(decoder);
1124 return ret;
1125 }
1126#endif
985 v4l2_ctrl_handler_init(&decoder->hdl, 5); 1127 v4l2_ctrl_handler_init(&decoder->hdl, 5);
986 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1128 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
987 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); 1129 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
@@ -995,10 +1137,10 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
995 V4L2_CID_AUTOGAIN, 0, 1, 1, 1); 1137 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
996 sd->ctrl_handler = &decoder->hdl; 1138 sd->ctrl_handler = &decoder->hdl;
997 if (decoder->hdl.error) { 1139 if (decoder->hdl.error) {
998 int err = decoder->hdl.error; 1140 ret = decoder->hdl.error;
999 1141
1000 v4l2_ctrl_handler_free(&decoder->hdl); 1142 v4l2_ctrl_handler_free(&decoder->hdl);
1001 return err; 1143 return ret;
1002 } 1144 }
1003 v4l2_ctrl_handler_setup(&decoder->hdl); 1145 v4l2_ctrl_handler_setup(&decoder->hdl);
1004 1146
@@ -1021,6 +1163,9 @@ static int tvp514x_remove(struct i2c_client *client)
1021 struct tvp514x_decoder *decoder = to_decoder(sd); 1163 struct tvp514x_decoder *decoder = to_decoder(sd);
1022 1164
1023 v4l2_device_unregister_subdev(sd); 1165 v4l2_device_unregister_subdev(sd);
1166#if defined(CONFIG_MEDIA_CONTROLLER)
1167 media_entity_cleanup(&decoder->sd.entity);
1168#endif
1024 v4l2_ctrl_handler_free(&decoder->hdl); 1169 v4l2_ctrl_handler_free(&decoder->hdl);
1025 return 0; 1170 return 0;
1026} 1171}
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 5967e1a0c809..485159a3c0b7 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -1067,7 +1067,7 @@ static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1067 return 0; 1067 return 0;
1068} 1068}
1069 1069
1070static int tvp5150_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1070static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1071{ 1071{
1072 struct i2c_client *client = v4l2_get_subdevdata(sd); 1072 struct i2c_client *client = v4l2_get_subdevdata(sd);
1073 1073
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 537f6b4d4918..027809cca5f5 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -326,9 +326,8 @@ static const struct i2c_reg_value tvp7002_parms_720P50[] = {
326 { TVP7002_EOR, 0xff, TVP7002_RESERVED } 326 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
327}; 327};
328 328
329/* Preset definition for handling device operation */ 329/* Timings definition for handling device operation */
330struct tvp7002_preset_definition { 330struct tvp7002_timings_definition {
331 u32 preset;
332 struct v4l2_dv_timings timings; 331 struct v4l2_dv_timings timings;
333 const struct i2c_reg_value *p_settings; 332 const struct i2c_reg_value *p_settings;
334 enum v4l2_colorspace color_space; 333 enum v4l2_colorspace color_space;
@@ -339,10 +338,9 @@ struct tvp7002_preset_definition {
339 u16 cpl_max; 338 u16 cpl_max;
340}; 339};
341 340
342/* Struct list for digital video presets */ 341/* Struct list for digital video timings */
343static const struct tvp7002_preset_definition tvp7002_presets[] = { 342static const struct tvp7002_timings_definition tvp7002_timings[] = {
344 { 343 {
345 V4L2_DV_720P60,
346 V4L2_DV_BT_CEA_1280X720P60, 344 V4L2_DV_BT_CEA_1280X720P60,
347 tvp7002_parms_720P60, 345 tvp7002_parms_720P60,
348 V4L2_COLORSPACE_REC709, 346 V4L2_COLORSPACE_REC709,
@@ -353,7 +351,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
353 153 351 153
354 }, 352 },
355 { 353 {
356 V4L2_DV_1080I60,
357 V4L2_DV_BT_CEA_1920X1080I60, 354 V4L2_DV_BT_CEA_1920X1080I60,
358 tvp7002_parms_1080I60, 355 tvp7002_parms_1080I60,
359 V4L2_COLORSPACE_REC709, 356 V4L2_COLORSPACE_REC709,
@@ -364,7 +361,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
364 205 361 205
365 }, 362 },
366 { 363 {
367 V4L2_DV_1080I50,
368 V4L2_DV_BT_CEA_1920X1080I50, 364 V4L2_DV_BT_CEA_1920X1080I50,
369 tvp7002_parms_1080I50, 365 tvp7002_parms_1080I50,
370 V4L2_COLORSPACE_REC709, 366 V4L2_COLORSPACE_REC709,
@@ -375,7 +371,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
375 245 371 245
376 }, 372 },
377 { 373 {
378 V4L2_DV_720P50,
379 V4L2_DV_BT_CEA_1280X720P50, 374 V4L2_DV_BT_CEA_1280X720P50,
380 tvp7002_parms_720P50, 375 tvp7002_parms_720P50,
381 V4L2_COLORSPACE_REC709, 376 V4L2_COLORSPACE_REC709,
@@ -386,7 +381,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
386 183 381 183
387 }, 382 },
388 { 383 {
389 V4L2_DV_1080P60,
390 V4L2_DV_BT_CEA_1920X1080P60, 384 V4L2_DV_BT_CEA_1920X1080P60,
391 tvp7002_parms_1080P60, 385 tvp7002_parms_1080P60,
392 V4L2_COLORSPACE_REC709, 386 V4L2_COLORSPACE_REC709,
@@ -397,7 +391,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
397 102 391 102
398 }, 392 },
399 { 393 {
400 V4L2_DV_480P59_94,
401 V4L2_DV_BT_CEA_720X480P59_94, 394 V4L2_DV_BT_CEA_720X480P59_94,
402 tvp7002_parms_480P, 395 tvp7002_parms_480P,
403 V4L2_COLORSPACE_SMPTE170M, 396 V4L2_COLORSPACE_SMPTE170M,
@@ -408,7 +401,6 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
408 0xffff 401 0xffff
409 }, 402 },
410 { 403 {
411 V4L2_DV_576P50,
412 V4L2_DV_BT_CEA_720X576P50, 404 V4L2_DV_BT_CEA_720X576P50,
413 tvp7002_parms_576P, 405 tvp7002_parms_576P,
414 V4L2_COLORSPACE_SMPTE170M, 406 V4L2_COLORSPACE_SMPTE170M,
@@ -420,7 +412,7 @@ static const struct tvp7002_preset_definition tvp7002_presets[] = {
420 } 412 }
421}; 413};
422 414
423#define NUM_PRESETS ARRAY_SIZE(tvp7002_presets) 415#define NUM_TIMINGS ARRAY_SIZE(tvp7002_timings)
424 416
425/* Device definition */ 417/* Device definition */
426struct tvp7002 { 418struct tvp7002 {
@@ -431,7 +423,7 @@ struct tvp7002 {
431 int ver; 423 int ver;
432 int streaming; 424 int streaming;
433 425
434 const struct tvp7002_preset_definition *current_preset; 426 const struct tvp7002_timings_definition *current_timings;
435}; 427};
436 428
437/* 429/*
@@ -588,32 +580,6 @@ static int tvp7002_write_inittab(struct v4l2_subdev *sd,
588 return error; 580 return error;
589} 581}
590 582
591/*
592 * tvp7002_s_dv_preset() - Set digital video preset
593 * @sd: ptr to v4l2_subdev struct
594 * @dv_preset: ptr to v4l2_dv_preset struct
595 *
596 * Set the digital video preset for a TVP7002 decoder device.
597 * Returns zero when successful or -EINVAL if register access fails.
598 */
599static int tvp7002_s_dv_preset(struct v4l2_subdev *sd,
600 struct v4l2_dv_preset *dv_preset)
601{
602 struct tvp7002 *device = to_tvp7002(sd);
603 u32 preset;
604 int i;
605
606 for (i = 0; i < NUM_PRESETS; i++) {
607 preset = tvp7002_presets[i].preset;
608 if (preset == dv_preset->preset) {
609 device->current_preset = &tvp7002_presets[i];
610 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings);
611 }
612 }
613
614 return -EINVAL;
615}
616
617static int tvp7002_s_dv_timings(struct v4l2_subdev *sd, 583static int tvp7002_s_dv_timings(struct v4l2_subdev *sd,
618 struct v4l2_dv_timings *dv_timings) 584 struct v4l2_dv_timings *dv_timings)
619{ 585{
@@ -623,12 +589,12 @@ static int tvp7002_s_dv_timings(struct v4l2_subdev *sd,
623 589
624 if (dv_timings->type != V4L2_DV_BT_656_1120) 590 if (dv_timings->type != V4L2_DV_BT_656_1120)
625 return -EINVAL; 591 return -EINVAL;
626 for (i = 0; i < NUM_PRESETS; i++) { 592 for (i = 0; i < NUM_TIMINGS; i++) {
627 const struct v4l2_bt_timings *t = &tvp7002_presets[i].timings.bt; 593 const struct v4l2_bt_timings *t = &tvp7002_timings[i].timings.bt;
628 594
629 if (!memcmp(bt, t, &bt->standards - &bt->width)) { 595 if (!memcmp(bt, t, &bt->standards - &bt->width)) {
630 device->current_preset = &tvp7002_presets[i]; 596 device->current_timings = &tvp7002_timings[i];
631 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings); 597 return tvp7002_write_inittab(sd, tvp7002_timings[i].p_settings);
632 } 598 }
633 } 599 }
634 return -EINVAL; 600 return -EINVAL;
@@ -639,7 +605,7 @@ static int tvp7002_g_dv_timings(struct v4l2_subdev *sd,
639{ 605{
640 struct tvp7002 *device = to_tvp7002(sd); 606 struct tvp7002 *device = to_tvp7002(sd);
641 607
642 *dv_timings = device->current_preset->timings; 608 *dv_timings = device->current_timings->timings;
643 return 0; 609 return 0;
644} 610}
645 611
@@ -677,19 +643,13 @@ static int tvp7002_s_ctrl(struct v4l2_ctrl *ctrl)
677static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) 643static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
678{ 644{
679 struct tvp7002 *device = to_tvp7002(sd); 645 struct tvp7002 *device = to_tvp7002(sd);
680 struct v4l2_dv_enum_preset e_preset; 646 const struct v4l2_bt_timings *bt = &device->current_timings->timings.bt;
681 int error;
682 647
683 /* Calculate height and width based on current standard */ 648 f->width = bt->width;
684 error = v4l_fill_dv_preset_info(device->current_preset->preset, &e_preset); 649 f->height = bt->height;
685 if (error)
686 return error;
687
688 f->width = e_preset.width;
689 f->height = e_preset.height;
690 f->code = V4L2_MBUS_FMT_YUYV10_1X20; 650 f->code = V4L2_MBUS_FMT_YUYV10_1X20;
691 f->field = device->current_preset->scanmode; 651 f->field = device->current_timings->scanmode;
692 f->colorspace = device->current_preset->color_space; 652 f->colorspace = device->current_timings->color_space;
693 653
694 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d", 654 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d",
695 f->width, f->height); 655 f->width, f->height);
@@ -697,16 +657,16 @@ static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f
697} 657}
698 658
699/* 659/*
700 * tvp7002_query_dv_preset() - query DV preset 660 * tvp7002_query_dv() - query DV timings
701 * @sd: pointer to standard V4L2 sub-device structure 661 * @sd: pointer to standard V4L2 sub-device structure
702 * @qpreset: standard V4L2 v4l2_dv_preset structure 662 * @index: index into the tvp7002_timings array
703 * 663 *
704 * Returns the current DV preset by TVP7002. If no active input is 664 * Returns the current DV timings detected by TVP7002. If no active input is
705 * detected, returns -EINVAL 665 * detected, returns -EINVAL
706 */ 666 */
707static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index) 667static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
708{ 668{
709 const struct tvp7002_preset_definition *presets = tvp7002_presets; 669 const struct tvp7002_timings_definition *timings = tvp7002_timings;
710 u8 progressive; 670 u8 progressive;
711 u32 lpfr; 671 u32 lpfr;
712 u32 cpln; 672 u32 cpln;
@@ -717,7 +677,7 @@ static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
717 u8 cpl_msb; 677 u8 cpl_msb;
718 678
719 /* Return invalid index if no active input is detected */ 679 /* Return invalid index if no active input is detected */
720 *index = NUM_PRESETS; 680 *index = NUM_TIMINGS;
721 681
722 /* Read standards from device registers */ 682 /* Read standards from device registers */
723 tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_LSBS, &lpf_lsb, &error); 683 tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_LSBS, &lpf_lsb, &error);
@@ -738,39 +698,23 @@ static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
738 progressive = (lpf_msb & TVP7002_INPR_MASK) >> TVP7002_IP_SHIFT; 698 progressive = (lpf_msb & TVP7002_INPR_MASK) >> TVP7002_IP_SHIFT;
739 699
740 /* Do checking of video modes */ 700 /* Do checking of video modes */
741 for (*index = 0; *index < NUM_PRESETS; (*index)++, presets++) 701 for (*index = 0; *index < NUM_TIMINGS; (*index)++, timings++)
742 if (lpfr == presets->lines_per_frame && 702 if (lpfr == timings->lines_per_frame &&
743 progressive == presets->progressive) { 703 progressive == timings->progressive) {
744 if (presets->cpl_min == 0xffff) 704 if (timings->cpl_min == 0xffff)
745 break; 705 break;
746 if (cpln >= presets->cpl_min && cpln <= presets->cpl_max) 706 if (cpln >= timings->cpl_min && cpln <= timings->cpl_max)
747 break; 707 break;
748 } 708 }
749 709
750 if (*index == NUM_PRESETS) { 710 if (*index == NUM_TIMINGS) {
751 v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n", 711 v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n",
752 lpfr, cpln); 712 lpfr, cpln);
753 return -ENOLINK; 713 return -ENOLINK;
754 } 714 }
755 715
756 /* Update lines per frame and clocks per line info */ 716 /* Update lines per frame and clocks per line info */
757 v4l2_dbg(1, debug, sd, "detected preset: %d\n", *index); 717 v4l2_dbg(1, debug, sd, "detected timings: %d\n", *index);
758 return 0;
759}
760
761static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
762 struct v4l2_dv_preset *qpreset)
763{
764 int index;
765 int err = tvp7002_query_dv(sd, &index);
766
767 if (err || index == NUM_PRESETS) {
768 qpreset->preset = V4L2_DV_INVALID;
769 if (err == -ENOLINK)
770 err = 0;
771 return err;
772 }
773 qpreset->preset = tvp7002_presets[index].preset;
774 return 0; 718 return 0;
775} 719}
776 720
@@ -782,7 +726,7 @@ static int tvp7002_query_dv_timings(struct v4l2_subdev *sd,
782 726
783 if (err) 727 if (err)
784 return err; 728 return err;
785 *timings = tvp7002_presets[index].timings; 729 *timings = tvp7002_timings[index].timings;
786 return 0; 730 return 0;
787} 731}
788 732
@@ -824,7 +768,7 @@ static int tvp7002_g_register(struct v4l2_subdev *sd,
824 * -EPERM if call not allowed. 768 * -EPERM if call not allowed.
825 */ 769 */
826static int tvp7002_s_register(struct v4l2_subdev *sd, 770static int tvp7002_s_register(struct v4l2_subdev *sd,
827 struct v4l2_dbg_register *reg) 771 const struct v4l2_dbg_register *reg)
828{ 772{
829 struct i2c_client *client = v4l2_get_subdevdata(sd); 773 struct i2c_client *client = v4l2_get_subdevdata(sd);
830 774
@@ -896,35 +840,21 @@ static int tvp7002_s_stream(struct v4l2_subdev *sd, int enable)
896 */ 840 */
897static int tvp7002_log_status(struct v4l2_subdev *sd) 841static int tvp7002_log_status(struct v4l2_subdev *sd)
898{ 842{
899 const struct tvp7002_preset_definition *presets = tvp7002_presets;
900 struct tvp7002 *device = to_tvp7002(sd); 843 struct tvp7002 *device = to_tvp7002(sd);
901 struct v4l2_dv_enum_preset e_preset; 844 const struct v4l2_bt_timings *bt;
902 struct v4l2_dv_preset detected; 845 int detected;
903 int i;
904
905 detected.preset = V4L2_DV_INVALID;
906 /* Find my current standard*/
907 tvp7002_query_dv_preset(sd, &detected);
908 846
909 /* Print standard related code values */ 847 /* Find my current timings */
910 for (i = 0; i < NUM_PRESETS; i++, presets++) 848 tvp7002_query_dv(sd, &detected);
911 if (presets->preset == detected.preset)
912 break;
913 849
914 if (v4l_fill_dv_preset_info(device->current_preset->preset, &e_preset)) 850 bt = &device->current_timings->timings.bt;
915 return -EINVAL; 851 v4l2_info(sd, "Selected DV Timings: %ux%u\n", bt->width, bt->height);
916 852 if (detected == NUM_TIMINGS) {
917 v4l2_info(sd, "Selected DV Preset: %s\n", e_preset.name); 853 v4l2_info(sd, "Detected DV Timings: None\n");
918 v4l2_info(sd, " Pixels per line: %u\n", e_preset.width);
919 v4l2_info(sd, " Lines per frame: %u\n\n", e_preset.height);
920 if (i == NUM_PRESETS) {
921 v4l2_info(sd, "Detected DV Preset: None\n");
922 } else { 854 } else {
923 if (v4l_fill_dv_preset_info(presets->preset, &e_preset)) 855 bt = &tvp7002_timings[detected].timings.bt;
924 return -EINVAL; 856 v4l2_info(sd, "Detected DV Timings: %ux%u\n",
925 v4l2_info(sd, "Detected DV Preset: %s\n", e_preset.name); 857 bt->width, bt->height);
926 v4l2_info(sd, " Pixels per line: %u\n", e_preset.width);
927 v4l2_info(sd, " Lines per frame: %u\n\n", e_preset.height);
928 } 858 }
929 v4l2_info(sd, "Streaming enabled: %s\n", 859 v4l2_info(sd, "Streaming enabled: %s\n",
930 device->streaming ? "yes" : "no"); 860 device->streaming ? "yes" : "no");
@@ -935,31 +865,14 @@ static int tvp7002_log_status(struct v4l2_subdev *sd)
935 return 0; 865 return 0;
936} 866}
937 867
938/*
939 * tvp7002_enum_dv_presets() - Enum supported digital video formats
940 * @sd: pointer to standard V4L2 sub-device structure
941 * @preset: pointer to format struct
942 *
943 * Enumerate supported digital video formats.
944 */
945static int tvp7002_enum_dv_presets(struct v4l2_subdev *sd,
946 struct v4l2_dv_enum_preset *preset)
947{
948 /* Check requested format index is within range */
949 if (preset->index >= NUM_PRESETS)
950 return -EINVAL;
951
952 return v4l_fill_dv_preset_info(tvp7002_presets[preset->index].preset, preset);
953}
954
955static int tvp7002_enum_dv_timings(struct v4l2_subdev *sd, 868static int tvp7002_enum_dv_timings(struct v4l2_subdev *sd,
956 struct v4l2_enum_dv_timings *timings) 869 struct v4l2_enum_dv_timings *timings)
957{ 870{
958 /* Check requested format index is within range */ 871 /* Check requested format index is within range */
959 if (timings->index >= NUM_PRESETS) 872 if (timings->index >= NUM_TIMINGS)
960 return -EINVAL; 873 return -EINVAL;
961 874
962 timings->timings = tvp7002_presets[timings->index].timings; 875 timings->timings = tvp7002_timings[timings->index].timings;
963 return 0; 876 return 0;
964} 877}
965 878
@@ -986,9 +899,6 @@ static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
986 899
987/* Specific video subsystem operation handlers */ 900/* Specific video subsystem operation handlers */
988static const struct v4l2_subdev_video_ops tvp7002_video_ops = { 901static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
989 .enum_dv_presets = tvp7002_enum_dv_presets,
990 .s_dv_preset = tvp7002_s_dv_preset,
991 .query_dv_preset = tvp7002_query_dv_preset,
992 .g_dv_timings = tvp7002_g_dv_timings, 902 .g_dv_timings = tvp7002_g_dv_timings,
993 .s_dv_timings = tvp7002_s_dv_timings, 903 .s_dv_timings = tvp7002_s_dv_timings,
994 .enum_dv_timings = tvp7002_enum_dv_timings, 904 .enum_dv_timings = tvp7002_enum_dv_timings,
@@ -1019,7 +929,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1019{ 929{
1020 struct v4l2_subdev *sd; 930 struct v4l2_subdev *sd;
1021 struct tvp7002 *device; 931 struct tvp7002 *device;
1022 struct v4l2_dv_preset preset; 932 struct v4l2_dv_timings timings;
1023 int polarity_a; 933 int polarity_a;
1024 int polarity_b; 934 int polarity_b;
1025 u8 revision; 935 u8 revision;
@@ -1043,7 +953,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1043 953
1044 sd = &device->sd; 954 sd = &device->sd;
1045 device->pdata = c->dev.platform_data; 955 device->pdata = c->dev.platform_data;
1046 device->current_preset = tvp7002_presets; 956 device->current_timings = tvp7002_timings;
1047 957
1048 /* Tell v4l2 the device is ready */ 958 /* Tell v4l2 the device is ready */
1049 v4l2_i2c_subdev_init(sd, c, &tvp7002_ops); 959 v4l2_i2c_subdev_init(sd, c, &tvp7002_ops);
@@ -1080,8 +990,8 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1080 return error; 990 return error;
1081 991
1082 /* Set registers according to default video mode */ 992 /* Set registers according to default video mode */
1083 preset.preset = device->current_preset->preset; 993 timings = device->current_timings->timings;
1084 error = tvp7002_s_dv_preset(sd, &preset); 994 error = tvp7002_s_dv_timings(sd, &timings);
1085 995
1086 v4l2_ctrl_handler_init(&device->hdl, 1); 996 v4l2_ctrl_handler_init(&device->hdl, 1);
1087 v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops, 997 v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
diff --git a/drivers/media/i2c/tw2804.c b/drivers/media/i2c/tw2804.c
new file mode 100644
index 000000000000..c5dc2c3bf2d7
--- /dev/null
+++ b/drivers/media/i2c/tw2804.c
@@ -0,0 +1,453 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24#include <media/v4l2-subdev.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-ctrls.h>
28
29#define TW2804_REG_AUTOGAIN 0x02
30#define TW2804_REG_HUE 0x0f
31#define TW2804_REG_SATURATION 0x10
32#define TW2804_REG_CONTRAST 0x11
33#define TW2804_REG_BRIGHTNESS 0x12
34#define TW2804_REG_COLOR_KILLER 0x14
35#define TW2804_REG_GAIN 0x3c
36#define TW2804_REG_CHROMA_GAIN 0x3d
37#define TW2804_REG_BLUE_BALANCE 0x3e
38#define TW2804_REG_RED_BALANCE 0x3f
39
40struct tw2804 {
41 struct v4l2_subdev sd;
42 struct v4l2_ctrl_handler hdl;
43 u8 channel:2;
44 u8 input:1;
45 int norm;
46};
47
48static const u8 global_registers[] = {
49 0x39, 0x00,
50 0x3a, 0xff,
51 0x3b, 0x84,
52 0x3c, 0x80,
53 0x3d, 0x80,
54 0x3e, 0x82,
55 0x3f, 0x82,
56 0x78, 0x00,
57 0xff, 0xff, /* Terminator (reg 0xff does not exist) */
58};
59
60static const u8 channel_registers[] = {
61 0x01, 0xc4,
62 0x02, 0xa5,
63 0x03, 0x20,
64 0x04, 0xd0,
65 0x05, 0x20,
66 0x06, 0xd0,
67 0x07, 0x88,
68 0x08, 0x20,
69 0x09, 0x07,
70 0x0a, 0xf0,
71 0x0b, 0x07,
72 0x0c, 0xf0,
73 0x0d, 0x40,
74 0x0e, 0xd2,
75 0x0f, 0x80,
76 0x10, 0x80,
77 0x11, 0x80,
78 0x12, 0x80,
79 0x13, 0x1f,
80 0x14, 0x00,
81 0x15, 0x00,
82 0x16, 0x00,
83 0x17, 0x00,
84 0x18, 0xff,
85 0x19, 0xff,
86 0x1a, 0xff,
87 0x1b, 0xff,
88 0x1c, 0xff,
89 0x1d, 0xff,
90 0x1e, 0xff,
91 0x1f, 0xff,
92 0x20, 0x07,
93 0x21, 0x07,
94 0x22, 0x00,
95 0x23, 0x91,
96 0x24, 0x51,
97 0x25, 0x03,
98 0x26, 0x00,
99 0x27, 0x00,
100 0x28, 0x00,
101 0x29, 0x00,
102 0x2a, 0x00,
103 0x2b, 0x00,
104 0x2c, 0x00,
105 0x2d, 0x00,
106 0x2e, 0x00,
107 0x2f, 0x00,
108 0x30, 0x00,
109 0x31, 0x00,
110 0x32, 0x00,
111 0x33, 0x00,
112 0x34, 0x00,
113 0x35, 0x00,
114 0x36, 0x00,
115 0x37, 0x00,
116 0xff, 0xff, /* Terminator (reg 0xff does not exist) */
117};
118
119static int write_reg(struct i2c_client *client, u8 reg, u8 value, u8 channel)
120{
121 return i2c_smbus_write_byte_data(client, reg | (channel << 6), value);
122}
123
124static int write_regs(struct i2c_client *client, const u8 *regs, u8 channel)
125{
126 int ret;
127 int i;
128
129 for (i = 0; regs[i] != 0xff; i += 2) {
130 ret = i2c_smbus_write_byte_data(client,
131 regs[i] | (channel << 6), regs[i + 1]);
132 if (ret < 0)
133 return ret;
134 }
135 return 0;
136}
137
138static int read_reg(struct i2c_client *client, u8 reg, u8 channel)
139{
140 return i2c_smbus_read_byte_data(client, (reg) | (channel << 6));
141}
142
143static inline struct tw2804 *to_state(struct v4l2_subdev *sd)
144{
145 return container_of(sd, struct tw2804, sd);
146}
147
148static inline struct tw2804 *to_state_from_ctrl(struct v4l2_ctrl *ctrl)
149{
150 return container_of(ctrl->handler, struct tw2804, hdl);
151}
152
153static int tw2804_log_status(struct v4l2_subdev *sd)
154{
155 struct tw2804 *state = to_state(sd);
156
157 v4l2_info(sd, "Standard: %s\n",
158 state->norm & V4L2_STD_525_60 ? "60 Hz" : "50 Hz");
159 v4l2_info(sd, "Channel: %d\n", state->channel);
160 v4l2_info(sd, "Input: %d\n", state->input);
161 return v4l2_ctrl_subdev_log_status(sd);
162}
163
164/*
165 * These volatile controls are needed because all four channels share
166 * these controls. So a change made to them through one channel would
167 * require another channel to be updated.
168 *
169 * Normally this would have been done in a different way, but since the one
170 * board that uses this driver sees this single chip as if it was on four
171 * different i2c adapters (each adapter belonging to a separate instance of
172 * the same USB driver) there is no reliable method that I have found to let
173 * the instances know about each other.
174 *
175 * So implementing these global registers as volatile is the best we can do.
176 */
177static int tw2804_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
178{
179 struct tw2804 *state = to_state_from_ctrl(ctrl);
180 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
181
182 switch (ctrl->id) {
183 case V4L2_CID_GAIN:
184 ctrl->val = read_reg(client, TW2804_REG_GAIN, 0);
185 return 0;
186
187 case V4L2_CID_CHROMA_GAIN:
188 ctrl->val = read_reg(client, TW2804_REG_CHROMA_GAIN, 0);
189 return 0;
190
191 case V4L2_CID_BLUE_BALANCE:
192 ctrl->val = read_reg(client, TW2804_REG_BLUE_BALANCE, 0);
193 return 0;
194
195 case V4L2_CID_RED_BALANCE:
196 ctrl->val = read_reg(client, TW2804_REG_RED_BALANCE, 0);
197 return 0;
198 }
199 return 0;
200}
201
202static int tw2804_s_ctrl(struct v4l2_ctrl *ctrl)
203{
204 struct tw2804 *state = to_state_from_ctrl(ctrl);
205 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
206 int addr;
207 int reg;
208
209 switch (ctrl->id) {
210 case V4L2_CID_AUTOGAIN:
211 addr = TW2804_REG_AUTOGAIN;
212 reg = read_reg(client, addr, state->channel);
213 if (reg < 0)
214 return reg;
215 if (ctrl->val == 0)
216 reg &= ~(1 << 7);
217 else
218 reg |= 1 << 7;
219 return write_reg(client, addr, reg, state->channel);
220
221 case V4L2_CID_COLOR_KILLER:
222 addr = TW2804_REG_COLOR_KILLER;
223 reg = read_reg(client, addr, state->channel);
224 if (reg < 0)
225 return reg;
226 reg = (reg & ~(0x03)) | (ctrl->val == 0 ? 0x02 : 0x03);
227 return write_reg(client, addr, reg, state->channel);
228
229 case V4L2_CID_GAIN:
230 return write_reg(client, TW2804_REG_GAIN, ctrl->val, 0);
231
232 case V4L2_CID_CHROMA_GAIN:
233 return write_reg(client, TW2804_REG_CHROMA_GAIN, ctrl->val, 0);
234
235 case V4L2_CID_BLUE_BALANCE:
236 return write_reg(client, TW2804_REG_BLUE_BALANCE, ctrl->val, 0);
237
238 case V4L2_CID_RED_BALANCE:
239 return write_reg(client, TW2804_REG_RED_BALANCE, ctrl->val, 0);
240
241 case V4L2_CID_BRIGHTNESS:
242 return write_reg(client, TW2804_REG_BRIGHTNESS,
243 ctrl->val, state->channel);
244
245 case V4L2_CID_CONTRAST:
246 return write_reg(client, TW2804_REG_CONTRAST,
247 ctrl->val, state->channel);
248
249 case V4L2_CID_SATURATION:
250 return write_reg(client, TW2804_REG_SATURATION,
251 ctrl->val, state->channel);
252
253 case V4L2_CID_HUE:
254 return write_reg(client, TW2804_REG_HUE,
255 ctrl->val, state->channel);
256
257 default:
258 break;
259 }
260 return -EINVAL;
261}
262
263static int tw2804_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
264{
265 struct tw2804 *dec = to_state(sd);
266 struct i2c_client *client = v4l2_get_subdevdata(sd);
267 bool is_60hz = norm & V4L2_STD_525_60;
268 u8 regs[] = {
269 0x01, is_60hz ? 0xc4 : 0x84,
270 0x09, is_60hz ? 0x07 : 0x04,
271 0x0a, is_60hz ? 0xf0 : 0x20,
272 0x0b, is_60hz ? 0x07 : 0x04,
273 0x0c, is_60hz ? 0xf0 : 0x20,
274 0x0d, is_60hz ? 0x40 : 0x4a,
275 0x16, is_60hz ? 0x00 : 0x40,
276 0x17, is_60hz ? 0x00 : 0x40,
277 0x20, is_60hz ? 0x07 : 0x0f,
278 0x21, is_60hz ? 0x07 : 0x0f,
279 0xff, 0xff,
280 };
281
282 write_regs(client, regs, dec->channel);
283 dec->norm = norm;
284 return 0;
285}
286
287static int tw2804_s_video_routing(struct v4l2_subdev *sd, u32 input, u32 output,
288 u32 config)
289{
290 struct tw2804 *dec = to_state(sd);
291 struct i2c_client *client = v4l2_get_subdevdata(sd);
292 int reg;
293
294 if (config && config - 1 != dec->channel) {
295 if (config > 4) {
296 dev_err(&client->dev,
297 "channel %d is not between 1 and 4!\n", config);
298 return -EINVAL;
299 }
300 dec->channel = config - 1;
301 dev_dbg(&client->dev, "initializing TW2804 channel %d\n",
302 dec->channel);
303 if (dec->channel == 0 &&
304 write_regs(client, global_registers, 0) < 0) {
305 dev_err(&client->dev,
306 "error initializing TW2804 global registers\n");
307 return -EIO;
308 }
309 if (write_regs(client, channel_registers, dec->channel) < 0) {
310 dev_err(&client->dev,
311 "error initializing TW2804 channel %d\n",
312 dec->channel);
313 return -EIO;
314 }
315 }
316
317 if (input > 1)
318 return -EINVAL;
319
320 if (input == dec->input)
321 return 0;
322
323 reg = read_reg(client, 0x22, dec->channel);
324
325 if (reg >= 0) {
326 if (input == 0)
327 reg &= ~(1 << 2);
328 else
329 reg |= 1 << 2;
330 reg = write_reg(client, 0x22, reg, dec->channel);
331 }
332
333 if (reg >= 0)
334 dec->input = input;
335 else
336 return reg;
337 return 0;
338}
339
340static const struct v4l2_ctrl_ops tw2804_ctrl_ops = {
341 .g_volatile_ctrl = tw2804_g_volatile_ctrl,
342 .s_ctrl = tw2804_s_ctrl,
343};
344
345static const struct v4l2_subdev_video_ops tw2804_video_ops = {
346 .s_routing = tw2804_s_video_routing,
347};
348
349static const struct v4l2_subdev_core_ops tw2804_core_ops = {
350 .log_status = tw2804_log_status,
351 .s_std = tw2804_s_std,
352};
353
354static const struct v4l2_subdev_ops tw2804_ops = {
355 .core = &tw2804_core_ops,
356 .video = &tw2804_video_ops,
357};
358
359static int tw2804_probe(struct i2c_client *client,
360 const struct i2c_device_id *id)
361{
362 struct i2c_adapter *adapter = client->adapter;
363 struct tw2804 *state;
364 struct v4l2_subdev *sd;
365 struct v4l2_ctrl *ctrl;
366 int err;
367
368 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
369 return -ENODEV;
370
371 state = kzalloc(sizeof(struct tw2804), GFP_KERNEL);
372
373 if (state == NULL)
374 return -ENOMEM;
375 sd = &state->sd;
376 v4l2_i2c_subdev_init(sd, client, &tw2804_ops);
377 state->channel = -1;
378 state->norm = V4L2_STD_NTSC;
379
380 v4l2_ctrl_handler_init(&state->hdl, 10);
381 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
382 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
383 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
384 V4L2_CID_CONTRAST, 0, 255, 1, 128);
385 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
386 V4L2_CID_SATURATION, 0, 255, 1, 128);
387 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
388 V4L2_CID_HUE, 0, 255, 1, 128);
389 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
390 V4L2_CID_COLOR_KILLER, 0, 1, 1, 0);
391 v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
392 V4L2_CID_AUTOGAIN, 0, 1, 1, 0);
393 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
394 V4L2_CID_GAIN, 0, 255, 1, 128);
395 if (ctrl)
396 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
397 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
398 V4L2_CID_CHROMA_GAIN, 0, 255, 1, 128);
399 if (ctrl)
400 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
401 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
402 V4L2_CID_BLUE_BALANCE, 0, 255, 1, 122);
403 if (ctrl)
404 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
405 ctrl = v4l2_ctrl_new_std(&state->hdl, &tw2804_ctrl_ops,
406 V4L2_CID_RED_BALANCE, 0, 255, 1, 122);
407 if (ctrl)
408 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
409 sd->ctrl_handler = &state->hdl;
410 err = state->hdl.error;
411 if (err) {
412 v4l2_ctrl_handler_free(&state->hdl);
413 kfree(state);
414 return err;
415 }
416
417 v4l_info(client, "chip found @ 0x%02x (%s)\n",
418 client->addr << 1, client->adapter->name);
419
420 return 0;
421}
422
423static int tw2804_remove(struct i2c_client *client)
424{
425 struct v4l2_subdev *sd = i2c_get_clientdata(client);
426 struct tw2804 *state = to_state(sd);
427
428 v4l2_device_unregister_subdev(sd);
429 v4l2_ctrl_handler_free(&state->hdl);
430 kfree(state);
431 return 0;
432}
433
434static const struct i2c_device_id tw2804_id[] = {
435 { "tw2804", 0 },
436 { }
437};
438MODULE_DEVICE_TABLE(i2c, tw2804_id);
439
440static struct i2c_driver tw2804_driver = {
441 .driver = {
442 .name = "tw2804",
443 },
444 .probe = tw2804_probe,
445 .remove = tw2804_remove,
446 .id_table = tw2804_id,
447};
448
449module_i2c_driver(tw2804_driver);
450
451MODULE_LICENSE("GPL v2");
452MODULE_DESCRIPTION("TW2804/TW2802 V4L2 i2c driver");
453MODULE_AUTHOR("Micronas USA Inc");
diff --git a/drivers/media/i2c/tw9903.c b/drivers/media/i2c/tw9903.c
new file mode 100644
index 000000000000..87880b19d8c3
--- /dev/null
+++ b/drivers/media/i2c/tw9903.c
@@ -0,0 +1,279 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <media/v4l2-device.h>
24#include <media/v4l2-ctrls.h>
25#include <linux/slab.h>
26
27MODULE_DESCRIPTION("TW9903 I2C subdev driver");
28MODULE_LICENSE("GPL v2");
29
30/*
31 * This driver is based on the wis-tw9903.c source that was in
32 * drivers/staging/media/go7007. That source had commented out code for
33 * saturation and scaling (neither seemed to work). If anyone ever gets
34 * hardware to test this driver, then that code might be useful to look at.
35 * You need to get the kernel sources of, say, kernel 3.8 where that
36 * wis-tw9903 driver is still present.
37 */
38
39struct tw9903 {
40 struct v4l2_subdev sd;
41 struct v4l2_ctrl_handler hdl;
42 v4l2_std_id norm;
43};
44
45static inline struct tw9903 *to_state(struct v4l2_subdev *sd)
46{
47 return container_of(sd, struct tw9903, sd);
48}
49
50static const u8 initial_registers[] = {
51 0x02, 0x44, /* input 1, composite */
52 0x03, 0x92, /* correct digital format */
53 0x04, 0x00,
54 0x05, 0x80, /* or 0x00 for PAL */
55 0x06, 0x40, /* second internal current reference */
56 0x07, 0x02, /* window */
57 0x08, 0x14, /* window */
58 0x09, 0xf0, /* window */
59 0x0a, 0x81, /* window */
60 0x0b, 0xd0, /* window */
61 0x0c, 0x8c,
62 0x0d, 0x00, /* scaling */
63 0x0e, 0x11, /* scaling */
64 0x0f, 0x00, /* scaling */
65 0x10, 0x00, /* brightness */
66 0x11, 0x60, /* contrast */
67 0x12, 0x01, /* sharpness */
68 0x13, 0x7f, /* U gain */
69 0x14, 0x5a, /* V gain */
70 0x15, 0x00, /* hue */
71 0x16, 0xc3, /* sharpness */
72 0x18, 0x00,
73 0x19, 0x58, /* vbi */
74 0x1a, 0x80,
75 0x1c, 0x0f, /* video norm */
76 0x1d, 0x7f, /* video norm */
77 0x20, 0xa0, /* clamping gain (working 0x50) */
78 0x21, 0x22,
79 0x22, 0xf0,
80 0x23, 0xfe,
81 0x24, 0x3c,
82 0x25, 0x38,
83 0x26, 0x44,
84 0x27, 0x20,
85 0x28, 0x00,
86 0x29, 0x15,
87 0x2a, 0xa0,
88 0x2b, 0x44,
89 0x2c, 0x37,
90 0x2d, 0x00,
91 0x2e, 0xa5, /* burst PLL control (working: a9) */
92 0x2f, 0xe0, /* 0xea is blue test frame -- 0xe0 for normal */
93 0x31, 0x00,
94 0x33, 0x22,
95 0x34, 0x11,
96 0x35, 0x35,
97 0x3b, 0x05,
98 0x06, 0xc0, /* reset device */
99 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
100};
101
102static int write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
103{
104 struct i2c_client *client = v4l2_get_subdevdata(sd);
105
106 return i2c_smbus_write_byte_data(client, reg, value);
107}
108
109static int write_regs(struct v4l2_subdev *sd, const u8 *regs)
110{
111 int i;
112
113 for (i = 0; regs[i] != 0x00; i += 2)
114 if (write_reg(sd, regs[i], regs[i + 1]) < 0)
115 return -1;
116 return 0;
117}
118
119static int tw9903_s_video_routing(struct v4l2_subdev *sd, u32 input,
120 u32 output, u32 config)
121{
122 write_reg(sd, 0x02, 0x40 | (input << 1));
123 return 0;
124}
125
126static int tw9903_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
127{
128 struct tw9903 *dec = to_state(sd);
129 bool is_60hz = norm & V4L2_STD_525_60;
130 static const u8 config_60hz[] = {
131 0x05, 0x80,
132 0x07, 0x02,
133 0x08, 0x14,
134 0x09, 0xf0,
135 0, 0,
136 };
137 static const u8 config_50hz[] = {
138 0x05, 0x00,
139 0x07, 0x12,
140 0x08, 0x18,
141 0x09, 0x20,
142 0, 0,
143 };
144
145 write_regs(sd, is_60hz ? config_60hz : config_50hz);
146 dec->norm = norm;
147 return 0;
148}
149
150
151static int tw9903_s_ctrl(struct v4l2_ctrl *ctrl)
152{
153 struct tw9903 *dec = container_of(ctrl->handler, struct tw9903, hdl);
154 struct v4l2_subdev *sd = &dec->sd;
155
156 switch (ctrl->id) {
157 case V4L2_CID_BRIGHTNESS:
158 write_reg(sd, 0x10, ctrl->val);
159 break;
160 case V4L2_CID_CONTRAST:
161 write_reg(sd, 0x11, ctrl->val);
162 break;
163 case V4L2_CID_HUE:
164 write_reg(sd, 0x15, ctrl->val);
165 break;
166 default:
167 return -EINVAL;
168 }
169 return 0;
170}
171
172static int tw9903_log_status(struct v4l2_subdev *sd)
173{
174 struct tw9903 *dec = to_state(sd);
175 bool is_60hz = dec->norm & V4L2_STD_525_60;
176
177 v4l2_info(sd, "Standard: %d Hz\n", is_60hz ? 60 : 50);
178 v4l2_ctrl_subdev_log_status(sd);
179 return 0;
180}
181
182/* --------------------------------------------------------------------------*/
183
184static const struct v4l2_ctrl_ops tw9903_ctrl_ops = {
185 .s_ctrl = tw9903_s_ctrl,
186};
187
188static const struct v4l2_subdev_core_ops tw9903_core_ops = {
189 .log_status = tw9903_log_status,
190 .s_std = tw9903_s_std,
191};
192
193static const struct v4l2_subdev_video_ops tw9903_video_ops = {
194 .s_routing = tw9903_s_video_routing,
195};
196
197static const struct v4l2_subdev_ops tw9903_ops = {
198 .core = &tw9903_core_ops,
199 .video = &tw9903_video_ops,
200};
201
202/* --------------------------------------------------------------------------*/
203
204static int tw9903_probe(struct i2c_client *client,
205 const struct i2c_device_id *id)
206{
207 struct tw9903 *dec;
208 struct v4l2_subdev *sd;
209 struct v4l2_ctrl_handler *hdl;
210
211 /* Check if the adapter supports the needed features */
212 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
213 return -EIO;
214
215 v4l_info(client, "chip found @ 0x%02x (%s)\n",
216 client->addr << 1, client->adapter->name);
217
218 dec = kzalloc(sizeof(struct tw9903), GFP_KERNEL);
219 if (dec == NULL)
220 return -ENOMEM;
221 sd = &dec->sd;
222 v4l2_i2c_subdev_init(sd, client, &tw9903_ops);
223 hdl = &dec->hdl;
224 v4l2_ctrl_handler_init(hdl, 4);
225 v4l2_ctrl_new_std(hdl, &tw9903_ctrl_ops,
226 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
227 v4l2_ctrl_new_std(hdl, &tw9903_ctrl_ops,
228 V4L2_CID_CONTRAST, 0, 255, 1, 0x60);
229 v4l2_ctrl_new_std(hdl, &tw9903_ctrl_ops,
230 V4L2_CID_HUE, -128, 127, 1, 0);
231 sd->ctrl_handler = hdl;
232 if (hdl->error) {
233 int err = hdl->error;
234
235 v4l2_ctrl_handler_free(hdl);
236 kfree(dec);
237 return err;
238 }
239
240 /* Initialize tw9903 */
241 dec->norm = V4L2_STD_NTSC;
242
243 if (write_regs(sd, initial_registers) < 0) {
244 v4l2_err(client, "error initializing TW9903\n");
245 kfree(dec);
246 return -EINVAL;
247 }
248
249 return 0;
250}
251
252static int tw9903_remove(struct i2c_client *client)
253{
254 struct v4l2_subdev *sd = i2c_get_clientdata(client);
255
256 v4l2_device_unregister_subdev(sd);
257 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
258 kfree(to_state(sd));
259 return 0;
260}
261
262/* ----------------------------------------------------------------------- */
263
264static const struct i2c_device_id tw9903_id[] = {
265 { "tw9903", 0 },
266 { }
267};
268MODULE_DEVICE_TABLE(i2c, tw9903_id);
269
270static struct i2c_driver tw9903_driver = {
271 .driver = {
272 .owner = THIS_MODULE,
273 .name = "tw9903",
274 },
275 .probe = tw9903_probe,
276 .remove = tw9903_remove,
277 .id_table = tw9903_id,
278};
279module_i2c_driver(tw9903_driver);
diff --git a/drivers/media/i2c/tw9906.c b/drivers/media/i2c/tw9906.c
new file mode 100644
index 000000000000..accd79e5a7fd
--- /dev/null
+++ b/drivers/media/i2c/tw9906.c
@@ -0,0 +1,247 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24#include <media/v4l2-device.h>
25#include <media/v4l2-ctrls.h>
26
27MODULE_DESCRIPTION("TW9906 I2C subdev driver");
28MODULE_LICENSE("GPL v2");
29
30struct tw9906 {
31 struct v4l2_subdev sd;
32 struct v4l2_ctrl_handler hdl;
33 v4l2_std_id norm;
34};
35
36static inline struct tw9906 *to_state(struct v4l2_subdev *sd)
37{
38 return container_of(sd, struct tw9906, sd);
39}
40
41static const u8 initial_registers[] = {
42 0x02, 0x40, /* input 0, composite */
43 0x03, 0xa2, /* correct digital format */
44 0x05, 0x81, /* or 0x01 for PAL */
45 0x07, 0x02, /* window */
46 0x08, 0x14, /* window */
47 0x09, 0xf0, /* window */
48 0x0a, 0x10, /* window */
49 0x0b, 0xd0, /* window */
50 0x0d, 0x00, /* scaling */
51 0x0e, 0x11, /* scaling */
52 0x0f, 0x00, /* scaling */
53 0x10, 0x00, /* brightness */
54 0x11, 0x60, /* contrast */
55 0x12, 0x11, /* sharpness */
56 0x13, 0x7e, /* U gain */
57 0x14, 0x7e, /* V gain */
58 0x15, 0x00, /* hue */
59 0x19, 0x57, /* vbi */
60 0x1a, 0x0f,
61 0x1b, 0x40,
62 0x29, 0x03,
63 0x55, 0x00,
64 0x6b, 0x26,
65 0x6c, 0x36,
66 0x6d, 0xf0,
67 0x6e, 0x41,
68 0x6f, 0x13,
69 0xad, 0x70,
70 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
71};
72
73static int write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
74{
75 struct i2c_client *client = v4l2_get_subdevdata(sd);
76
77 return i2c_smbus_write_byte_data(client, reg, value);
78}
79
80static int write_regs(struct v4l2_subdev *sd, const u8 *regs)
81{
82 int i;
83
84 for (i = 0; regs[i] != 0x00; i += 2)
85 if (write_reg(sd, regs[i], regs[i + 1]) < 0)
86 return -1;
87 return 0;
88}
89
90static int tw9906_s_video_routing(struct v4l2_subdev *sd, u32 input,
91 u32 output, u32 config)
92{
93 write_reg(sd, 0x02, 0x40 | (input << 1));
94 return 0;
95}
96
97static int tw9906_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
98{
99 struct tw9906 *dec = to_state(sd);
100 bool is_60hz = norm & V4L2_STD_525_60;
101 static const u8 config_60hz[] = {
102 0x05, 0x81,
103 0x07, 0x02,
104 0x08, 0x14,
105 0x09, 0xf0,
106 0, 0,
107 };
108 static const u8 config_50hz[] = {
109 0x05, 0x01,
110 0x07, 0x12,
111 0x08, 0x18,
112 0x09, 0x20,
113 0, 0,
114 };
115
116 write_regs(sd, is_60hz ? config_60hz : config_50hz);
117 dec->norm = norm;
118 return 0;
119}
120
121static int tw9906_s_ctrl(struct v4l2_ctrl *ctrl)
122{
123 struct tw9906 *dec = container_of(ctrl->handler, struct tw9906, hdl);
124 struct v4l2_subdev *sd = &dec->sd;
125
126 switch (ctrl->id) {
127 case V4L2_CID_BRIGHTNESS:
128 write_reg(sd, 0x10, ctrl->val);
129 break;
130 case V4L2_CID_CONTRAST:
131 write_reg(sd, 0x11, ctrl->val);
132 break;
133 case V4L2_CID_HUE:
134 write_reg(sd, 0x15, ctrl->val);
135 break;
136 default:
137 return -EINVAL;
138 }
139 return 0;
140}
141
142static int tw9906_log_status(struct v4l2_subdev *sd)
143{
144 struct tw9906 *dec = to_state(sd);
145 bool is_60hz = dec->norm & V4L2_STD_525_60;
146
147 v4l2_info(sd, "Standard: %d Hz\n", is_60hz ? 60 : 50);
148 v4l2_ctrl_subdev_log_status(sd);
149 return 0;
150}
151
152/* --------------------------------------------------------------------------*/
153
154static const struct v4l2_ctrl_ops tw9906_ctrl_ops = {
155 .s_ctrl = tw9906_s_ctrl,
156};
157
158static const struct v4l2_subdev_core_ops tw9906_core_ops = {
159 .log_status = tw9906_log_status,
160 .s_std = tw9906_s_std,
161};
162
163static const struct v4l2_subdev_video_ops tw9906_video_ops = {
164 .s_routing = tw9906_s_video_routing,
165};
166
167static const struct v4l2_subdev_ops tw9906_ops = {
168 .core = &tw9906_core_ops,
169 .video = &tw9906_video_ops,
170};
171
172static int tw9906_probe(struct i2c_client *client,
173 const struct i2c_device_id *id)
174{
175 struct tw9906 *dec;
176 struct v4l2_subdev *sd;
177 struct v4l2_ctrl_handler *hdl;
178
179 /* Check if the adapter supports the needed features */
180 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
181 return -EIO;
182
183 v4l_info(client, "chip found @ 0x%02x (%s)\n",
184 client->addr << 1, client->adapter->name);
185
186 dec = kzalloc(sizeof(struct tw9906), GFP_KERNEL);
187 if (dec == NULL)
188 return -ENOMEM;
189 sd = &dec->sd;
190 v4l2_i2c_subdev_init(sd, client, &tw9906_ops);
191 hdl = &dec->hdl;
192 v4l2_ctrl_handler_init(hdl, 4);
193 v4l2_ctrl_new_std(hdl, &tw9906_ctrl_ops,
194 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
195 v4l2_ctrl_new_std(hdl, &tw9906_ctrl_ops,
196 V4L2_CID_CONTRAST, 0, 255, 1, 0x60);
197 v4l2_ctrl_new_std(hdl, &tw9906_ctrl_ops,
198 V4L2_CID_HUE, -128, 127, 1, 0);
199 sd->ctrl_handler = hdl;
200 if (hdl->error) {
201 int err = hdl->error;
202
203 v4l2_ctrl_handler_free(hdl);
204 kfree(dec);
205 return err;
206 }
207
208 /* Initialize tw9906 */
209 dec->norm = V4L2_STD_NTSC;
210
211 if (write_regs(sd, initial_registers) < 0) {
212 v4l2_err(client, "error initializing TW9906\n");
213 kfree(dec);
214 return -EINVAL;
215 }
216
217 return 0;
218}
219
220static int tw9906_remove(struct i2c_client *client)
221{
222 struct v4l2_subdev *sd = i2c_get_clientdata(client);
223
224 v4l2_device_unregister_subdev(sd);
225 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
226 kfree(to_state(sd));
227 return 0;
228}
229
230/* ----------------------------------------------------------------------- */
231
232static const struct i2c_device_id tw9906_id[] = {
233 { "tw9906", 0 },
234 { }
235};
236MODULE_DEVICE_TABLE(i2c, tw9906_id);
237
238static struct i2c_driver tw9906_driver = {
239 .driver = {
240 .owner = THIS_MODULE,
241 .name = "tw9906",
242 },
243 .probe = tw9906_probe,
244 .remove = tw9906_remove,
245 .id_table = tw9906_id,
246};
247module_i2c_driver(tw9906_driver);
diff --git a/drivers/staging/media/go7007/wis-uda1342.c b/drivers/media/i2c/uda1342.c
index 582ea120a531..3af408556d27 100644
--- a/drivers/staging/media/go7007/wis-uda1342.c
+++ b/drivers/media/i2c/uda1342.c
@@ -19,10 +19,9 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/videodev2.h> 21#include <linux/videodev2.h>
22#include <media/tvaudio.h> 22#include <media/v4l2-device.h>
23#include <media/v4l2-common.h> 23#include <media/uda1342.h>
24 24#include <linux/slab.h>
25#include "wis-i2c.h"
26 25
27static int write_reg(struct i2c_client *client, int reg, int value) 26static int write_reg(struct i2c_client *client, int reg, int value)
28{ 27{
@@ -31,38 +30,38 @@ static int write_reg(struct i2c_client *client, int reg, int value)
31 return 0; 30 return 0;
32} 31}
33 32
34static int wis_uda1342_command(struct i2c_client *client, 33static int uda1342_s_routing(struct v4l2_subdev *sd,
35 unsigned int cmd, void *arg) 34 u32 input, u32 output, u32 config)
36{ 35{
37 switch (cmd) { 36 struct i2c_client *client = v4l2_get_subdevdata(sd);
38 case VIDIOC_S_AUDIO: 37
39 { 38 switch (input) {
40 int *inp = arg; 39 case UDA1342_IN1:
41 40 write_reg(client, 0x00, 0x1241); /* select input 1 */
42 switch (*inp) { 41 break;
43 case TVAUDIO_INPUT_TUNER: 42 case UDA1342_IN2:
44 write_reg(client, 0x00, 0x1441); /* select input 2 */ 43 write_reg(client, 0x00, 0x1441); /* select input 2 */
45 break;
46 case TVAUDIO_INPUT_EXTERN:
47 write_reg(client, 0x00, 0x1241); /* select input 1 */
48 break;
49 default:
50 dev_err(&client->dev, "input %d not supported\n",
51 *inp);
52 break;
53 }
54 break; 44 break;
55 }
56 default: 45 default:
46 v4l2_err(sd, "input %d not supported\n", input);
57 break; 47 break;
58 } 48 }
59 return 0; 49 return 0;
60} 50}
61 51
62static int wis_uda1342_probe(struct i2c_client *client, 52static const struct v4l2_subdev_audio_ops uda1342_audio_ops = {
53 .s_routing = uda1342_s_routing,
54};
55
56static const struct v4l2_subdev_ops uda1342_ops = {
57 .audio = &uda1342_audio_ops,
58};
59
60static int uda1342_probe(struct i2c_client *client,
63 const struct i2c_device_id *id) 61 const struct i2c_device_id *id)
64{ 62{
65 struct i2c_adapter *adapter = client->adapter; 63 struct i2c_adapter *adapter = client->adapter;
64 struct v4l2_subdev *sd;
66 65
67 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 66 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
68 return -ENODEV; 67 return -ENODEV;
@@ -70,33 +69,45 @@ static int wis_uda1342_probe(struct i2c_client *client,
70 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n", 69 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
71 client->addr, adapter->name); 70 client->addr, adapter->name);
72 71
72 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
73 if (sd == NULL)
74 return -ENOMEM;
75
76 v4l2_i2c_subdev_init(sd, client, &uda1342_ops);
77
73 write_reg(client, 0x00, 0x8000); /* reset registers */ 78 write_reg(client, 0x00, 0x8000); /* reset registers */
74 write_reg(client, 0x00, 0x1241); /* select input 1 */ 79 write_reg(client, 0x00, 0x1241); /* select input 1 */
75 80
81 v4l_info(client, "chip found @ 0x%02x (%s)\n",
82 client->addr << 1, client->adapter->name);
83
76 return 0; 84 return 0;
77} 85}
78 86
79static int wis_uda1342_remove(struct i2c_client *client) 87static int uda1342_remove(struct i2c_client *client)
80{ 88{
89 struct v4l2_subdev *sd = i2c_get_clientdata(client);
90
91 v4l2_device_unregister_subdev(sd);
92 kfree(sd);
81 return 0; 93 return 0;
82} 94}
83 95
84static const struct i2c_device_id wis_uda1342_id[] = { 96static const struct i2c_device_id uda1342_id[] = {
85 { "wis_uda1342", 0 }, 97 { "uda1342", 0 },
86 { } 98 { }
87}; 99};
88MODULE_DEVICE_TABLE(i2c, wis_uda1342_id); 100MODULE_DEVICE_TABLE(i2c, uda1342_id);
89 101
90static struct i2c_driver wis_uda1342_driver = { 102static struct i2c_driver uda1342_driver = {
91 .driver = { 103 .driver = {
92 .name = "WIS UDA1342 I2C driver", 104 .name = "uda1342",
93 }, 105 },
94 .probe = wis_uda1342_probe, 106 .probe = uda1342_probe,
95 .remove = wis_uda1342_remove, 107 .remove = uda1342_remove,
96 .command = wis_uda1342_command, 108 .id_table = uda1342_id,
97 .id_table = wis_uda1342_id,
98}; 109};
99 110
100module_i2c_driver(wis_uda1342_driver); 111module_i2c_driver(uda1342_driver);
101 112
102MODULE_LICENSE("GPL v2"); 113MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/i2c/upd64031a.c b/drivers/media/i2c/upd64031a.c
index 1e7446542091..f0a09214c519 100644
--- a/drivers/media/i2c/upd64031a.c
+++ b/drivers/media/i2c/upd64031a.c
@@ -111,7 +111,7 @@ static void upd64031a_write(struct v4l2_subdev *sd, u8 reg, u8 val)
111/* ------------------------------------------------------------------------ */ 111/* ------------------------------------------------------------------------ */
112 112
113/* The input changed due to new input or channel changed */ 113/* The input changed due to new input or channel changed */
114static int upd64031a_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 114static int upd64031a_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
115{ 115{
116 struct upd64031a_state *state = to_state(sd); 116 struct upd64031a_state *state = to_state(sd);
117 u8 reg = state->regs[R00]; 117 u8 reg = state->regs[R00];
@@ -175,7 +175,7 @@ static int upd64031a_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
175 return 0; 175 return 0;
176} 176}
177 177
178static int upd64031a_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 178static int upd64031a_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
179{ 179{
180 struct i2c_client *client = v4l2_get_subdevdata(sd); 180 struct i2c_client *client = v4l2_get_subdevdata(sd);
181 181
diff --git a/drivers/media/i2c/upd64083.c b/drivers/media/i2c/upd64083.c
index 75d6acc62018..343e0215f74c 100644
--- a/drivers/media/i2c/upd64083.c
+++ b/drivers/media/i2c/upd64083.c
@@ -133,7 +133,7 @@ static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
133 return 0; 133 return 0;
134} 134}
135 135
136static int upd64083_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 136static int upd64083_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
137{ 137{
138 struct i2c_client *client = v4l2_get_subdevdata(sd); 138 struct i2c_client *client = v4l2_get_subdevdata(sd);
139 139
diff --git a/drivers/media/i2c/vp27smpx.c b/drivers/media/i2c/vp27smpx.c
index 7cfbc9d94a48..e71f139695af 100644
--- a/drivers/media/i2c/vp27smpx.c
+++ b/drivers/media/i2c/vp27smpx.c
@@ -90,7 +90,7 @@ static int vp27smpx_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
90 return 0; 90 return 0;
91} 91}
92 92
93static int vp27smpx_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 93static int vp27smpx_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
94{ 94{
95 struct vp27smpx_state *state = to_state(sd); 95 struct vp27smpx_state *state = to_state(sd);
96 96
diff --git a/drivers/media/i2c/vs6624.c b/drivers/media/i2c/vs6624.c
index 9ac1b8c3a837..f366fad6269e 100644
--- a/drivers/media/i2c/vs6624.c
+++ b/drivers/media/i2c/vs6624.c
@@ -748,7 +748,7 @@ static int vs6624_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
748 return 0; 748 return 0;
749} 749}
750 750
751static int vs6624_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 751static int vs6624_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
752{ 752{
753 struct i2c_client *client = v4l2_get_subdevdata(sd); 753 struct i2c_client *client = v4l2_get_subdevdata(sd);
754 754
diff --git a/drivers/media/i2c/wm8775.c b/drivers/media/i2c/wm8775.c
index bee77ea9f49e..27c27b4ae238 100644
--- a/drivers/media/i2c/wm8775.c
+++ b/drivers/media/i2c/wm8775.c
@@ -174,7 +174,7 @@ static int wm8775_log_status(struct v4l2_subdev *sd)
174 return 0; 174 return 0;
175} 175}
176 176
177static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 177static int wm8775_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *freq)
178{ 178{
179 wm8775_set_audio(sd, 0); 179 wm8775_set_audio(sd, 0);
180 return 0; 180 return 0;
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index d01fcb7e87c2..1957c0df08fd 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -20,10 +20,11 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#include <linux/types.h> 23#include <linux/compat.h>
24#include <linux/export.h>
24#include <linux/ioctl.h> 25#include <linux/ioctl.h>
25#include <linux/media.h> 26#include <linux/media.h>
26#include <linux/export.h> 27#include <linux/types.h>
27 28
28#include <media/media-device.h> 29#include <media/media-device.h>
29#include <media/media-devnode.h> 30#include <media/media-devnode.h>
@@ -101,9 +102,12 @@ static long media_device_enum_entities(struct media_device *mdev,
101 return -EINVAL; 102 return -EINVAL;
102 103
103 u_ent.id = ent->id; 104 u_ent.id = ent->id;
104 u_ent.name[0] = '\0'; 105 if (ent->name) {
105 if (ent->name) 106 strncpy(u_ent.name, ent->name, sizeof(u_ent.name));
106 strlcpy(u_ent.name, ent->name, sizeof(u_ent.name)); 107 u_ent.name[sizeof(u_ent.name) - 1] = '\0';
108 } else {
109 memset(u_ent.name, 0, sizeof(u_ent.name));
110 }
107 u_ent.type = ent->type; 111 u_ent.type = ent->type;
108 u_ent.revision = ent->revision; 112 u_ent.revision = ent->revision;
109 u_ent.flags = ent->flags; 113 u_ent.flags = ent->flags;
@@ -124,35 +128,31 @@ static void media_device_kpad_to_upad(const struct media_pad *kpad,
124 upad->flags = kpad->flags; 128 upad->flags = kpad->flags;
125} 129}
126 130
127static long media_device_enum_links(struct media_device *mdev, 131static long __media_device_enum_links(struct media_device *mdev,
128 struct media_links_enum __user *ulinks) 132 struct media_links_enum *links)
129{ 133{
130 struct media_entity *entity; 134 struct media_entity *entity;
131 struct media_links_enum links;
132 135
133 if (copy_from_user(&links, ulinks, sizeof(links))) 136 entity = find_entity(mdev, links->entity);
134 return -EFAULT;
135
136 entity = find_entity(mdev, links.entity);
137 if (entity == NULL) 137 if (entity == NULL)
138 return -EINVAL; 138 return -EINVAL;
139 139
140 if (links.pads) { 140 if (links->pads) {
141 unsigned int p; 141 unsigned int p;
142 142
143 for (p = 0; p < entity->num_pads; p++) { 143 for (p = 0; p < entity->num_pads; p++) {
144 struct media_pad_desc pad; 144 struct media_pad_desc pad;
145 media_device_kpad_to_upad(&entity->pads[p], &pad); 145 media_device_kpad_to_upad(&entity->pads[p], &pad);
146 if (copy_to_user(&links.pads[p], &pad, sizeof(pad))) 146 if (copy_to_user(&links->pads[p], &pad, sizeof(pad)))
147 return -EFAULT; 147 return -EFAULT;
148 } 148 }
149 } 149 }
150 150
151 if (links.links) { 151 if (links->links) {
152 struct media_link_desc __user *ulink; 152 struct media_link_desc __user *ulink;
153 unsigned int l; 153 unsigned int l;
154 154
155 for (l = 0, ulink = links.links; l < entity->num_links; l++) { 155 for (l = 0, ulink = links->links; l < entity->num_links; l++) {
156 struct media_link_desc link; 156 struct media_link_desc link;
157 157
158 /* Ignore backlinks. */ 158 /* Ignore backlinks. */
@@ -169,8 +169,26 @@ static long media_device_enum_links(struct media_device *mdev,
169 ulink++; 169 ulink++;
170 } 170 }
171 } 171 }
172
173 return 0;
174}
175
176static long media_device_enum_links(struct media_device *mdev,
177 struct media_links_enum __user *ulinks)
178{
179 struct media_links_enum links;
180 int rval;
181
182 if (copy_from_user(&links, ulinks, sizeof(links)))
183 return -EFAULT;
184
185 rval = __media_device_enum_links(mdev, &links);
186 if (rval < 0)
187 return rval;
188
172 if (copy_to_user(ulinks, &links, sizeof(*ulinks))) 189 if (copy_to_user(ulinks, &links, sizeof(*ulinks)))
173 return -EFAULT; 190 return -EFAULT;
191
174 return 0; 192 return 0;
175} 193}
176 194
@@ -251,10 +269,71 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
251 return ret; 269 return ret;
252} 270}
253 271
272#ifdef CONFIG_COMPAT
273
274struct media_links_enum32 {
275 __u32 entity;
276 compat_uptr_t pads; /* struct media_pad_desc * */
277 compat_uptr_t links; /* struct media_link_desc * */
278 __u32 reserved[4];
279};
280
281static long media_device_enum_links32(struct media_device *mdev,
282 struct media_links_enum32 __user *ulinks)
283{
284 struct media_links_enum links;
285 compat_uptr_t pads_ptr, links_ptr;
286
287 memset(&links, 0, sizeof(links));
288
289 if (get_user(links.entity, &ulinks->entity)
290 || get_user(pads_ptr, &ulinks->pads)
291 || get_user(links_ptr, &ulinks->links))
292 return -EFAULT;
293
294 links.pads = compat_ptr(pads_ptr);
295 links.links = compat_ptr(links_ptr);
296
297 return __media_device_enum_links(mdev, &links);
298}
299
300#define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct media_links_enum32)
301
302static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
303 unsigned long arg)
304{
305 struct media_devnode *devnode = media_devnode_data(filp);
306 struct media_device *dev = to_media_device(devnode);
307 long ret;
308
309 switch (cmd) {
310 case MEDIA_IOC_DEVICE_INFO:
311 case MEDIA_IOC_ENUM_ENTITIES:
312 case MEDIA_IOC_SETUP_LINK:
313 return media_device_ioctl(filp, cmd, arg);
314
315 case MEDIA_IOC_ENUM_LINKS32:
316 mutex_lock(&dev->graph_mutex);
317 ret = media_device_enum_links32(dev,
318 (struct media_links_enum32 __user *)arg);
319 mutex_unlock(&dev->graph_mutex);
320 break;
321
322 default:
323 ret = -ENOIOCTLCMD;
324 }
325
326 return ret;
327}
328#endif /* CONFIG_COMPAT */
329
254static const struct media_file_operations media_device_fops = { 330static const struct media_file_operations media_device_fops = {
255 .owner = THIS_MODULE, 331 .owner = THIS_MODULE,
256 .open = media_device_open, 332 .open = media_device_open,
257 .ioctl = media_device_ioctl, 333 .ioctl = media_device_ioctl,
334#ifdef CONFIG_COMPAT
335 .compat_ioctl = media_device_compat_ioctl,
336#endif /* CONFIG_COMPAT */
258 .release = media_device_close, 337 .release = media_device_close,
259}; 338};
260 339
diff --git a/drivers/media/media-devnode.c b/drivers/media/media-devnode.c
index 023b2a1cbb9b..fb0f0469fad7 100644
--- a/drivers/media/media-devnode.c
+++ b/drivers/media/media-devnode.c
@@ -116,19 +116,41 @@ static unsigned int media_poll(struct file *filp,
116 return mdev->fops->poll(filp, poll); 116 return mdev->fops->poll(filp, poll);
117} 117}
118 118
119static long media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 119static long
120__media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg,
121 long (*ioctl_func)(struct file *filp, unsigned int cmd,
122 unsigned long arg))
120{ 123{
121 struct media_devnode *mdev = media_devnode_data(filp); 124 struct media_devnode *mdev = media_devnode_data(filp);
122 125
123 if (!mdev->fops->ioctl) 126 if (!ioctl_func)
124 return -ENOTTY; 127 return -ENOTTY;
125 128
126 if (!media_devnode_is_registered(mdev)) 129 if (!media_devnode_is_registered(mdev))
127 return -EIO; 130 return -EIO;
128 131
129 return mdev->fops->ioctl(filp, cmd, arg); 132 return ioctl_func(filp, cmd, arg);
133}
134
135static long media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
136{
137 struct media_devnode *mdev = media_devnode_data(filp);
138
139 return __media_ioctl(filp, cmd, arg, mdev->fops->ioctl);
130} 140}
131 141
142#ifdef CONFIG_COMPAT
143
144static long media_compat_ioctl(struct file *filp, unsigned int cmd,
145 unsigned long arg)
146{
147 struct media_devnode *mdev = media_devnode_data(filp);
148
149 return __media_ioctl(filp, cmd, arg, mdev->fops->compat_ioctl);
150}
151
152#endif /* CONFIG_COMPAT */
153
132/* Override for the open function */ 154/* Override for the open function */
133static int media_open(struct inode *inode, struct file *filp) 155static int media_open(struct inode *inode, struct file *filp)
134{ 156{
@@ -188,6 +210,9 @@ static const struct file_operations media_devnode_fops = {
188 .write = media_write, 210 .write = media_write,
189 .open = media_open, 211 .open = media_open,
190 .unlocked_ioctl = media_ioctl, 212 .unlocked_ioctl = media_ioctl,
213#ifdef CONFIG_COMPAT
214 .compat_ioctl = media_compat_ioctl,
215#endif /* CONFIG_COMPAT */
191 .release = media_release, 216 .release = media_release,
192 .poll = media_poll, 217 .poll = media_poll,
193 .llseek = no_llseek, 218 .llseek = no_llseek,
diff --git a/drivers/media/mmc/siano/smssdio.c b/drivers/media/mmc/siano/smssdio.c
index 15d34935e00b..912c2814c6cf 100644
--- a/drivers/media/mmc/siano/smssdio.c
+++ b/drivers/media/mmc/siano/smssdio.c
@@ -43,6 +43,7 @@
43 43
44#include "smscoreapi.h" 44#include "smscoreapi.h"
45#include "sms-cards.h" 45#include "sms-cards.h"
46#include "smsendian.h"
46 47
47/* Registers */ 48/* Registers */
48 49
@@ -61,6 +62,16 @@ static const struct sdio_device_id smssdio_ids[] = {
61 .driver_data = SMS1XXX_BOARD_SIANO_VEGA}, 62 .driver_data = SMS1XXX_BOARD_SIANO_VEGA},
62 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VENICE), 63 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VENICE),
63 .driver_data = SMS1XXX_BOARD_SIANO_VEGA}, 64 .driver_data = SMS1XXX_BOARD_SIANO_VEGA},
65 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x302),
66 .driver_data = SMS1XXX_BOARD_SIANO_MING},
67 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x500),
68 .driver_data = SMS1XXX_BOARD_SIANO_PELE},
69 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x600),
70 .driver_data = SMS1XXX_BOARD_SIANO_RIO},
71 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x700),
72 .driver_data = SMS1XXX_BOARD_SIANO_DENVER_2160},
73 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x800),
74 .driver_data = SMS1XXX_BOARD_SIANO_DENVER_1530},
64 { /* end: all zeroes */ }, 75 { /* end: all zeroes */ },
65}; 76};
66 77
@@ -87,6 +98,7 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size)
87 98
88 sdio_claim_host(smsdev->func); 99 sdio_claim_host(smsdev->func);
89 100
101 smsendian_handle_tx_message((struct sms_msg_data *) buffer);
90 while (size >= smsdev->func->cur_blksize) { 102 while (size >= smsdev->func->cur_blksize) {
91 ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA, 103 ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
92 buffer, smsdev->func->cur_blksize); 104 buffer, smsdev->func->cur_blksize);
@@ -118,7 +130,7 @@ static void smssdio_interrupt(struct sdio_func *func)
118 130
119 struct smssdio_device *smsdev; 131 struct smssdio_device *smsdev;
120 struct smscore_buffer_t *cb; 132 struct smscore_buffer_t *cb;
121 struct SmsMsgHdr_ST *hdr; 133 struct sms_msg_hdr *hdr;
122 size_t size; 134 size_t size;
123 135
124 smsdev = sdio_get_drvdata(func); 136 smsdev = sdio_get_drvdata(func);
@@ -151,20 +163,20 @@ static void smssdio_interrupt(struct sdio_func *func)
151 163
152 hdr = cb->p; 164 hdr = cb->p;
153 165
154 if (hdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG) { 166 if (hdr->msg_flags & MSG_HDR_FLAG_SPLIT_MSG) {
155 smsdev->split_cb = cb; 167 smsdev->split_cb = cb;
156 return; 168 return;
157 } 169 }
158 170
159 if (hdr->msgLength > smsdev->func->cur_blksize) 171 if (hdr->msg_length > smsdev->func->cur_blksize)
160 size = hdr->msgLength - smsdev->func->cur_blksize; 172 size = hdr->msg_length - smsdev->func->cur_blksize;
161 else 173 else
162 size = 0; 174 size = 0;
163 } else { 175 } else {
164 cb = smsdev->split_cb; 176 cb = smsdev->split_cb;
165 hdr = cb->p; 177 hdr = cb->p;
166 178
167 size = hdr->msgLength - sizeof(struct SmsMsgHdr_ST); 179 size = hdr->msg_length - sizeof(struct sms_msg_hdr);
168 180
169 smsdev->split_cb = NULL; 181 smsdev->split_cb = NULL;
170 } 182 }
@@ -172,7 +184,7 @@ static void smssdio_interrupt(struct sdio_func *func)
172 if (size) { 184 if (size) {
173 void *buffer; 185 void *buffer;
174 186
175 buffer = cb->p + (hdr->msgLength - size); 187 buffer = cb->p + (hdr->msg_length - size);
176 size = ALIGN(size, SMSSDIO_BLOCK_SIZE); 188 size = ALIGN(size, SMSSDIO_BLOCK_SIZE);
177 189
178 BUG_ON(smsdev->func->cur_blksize != SMSSDIO_BLOCK_SIZE); 190 BUG_ON(smsdev->func->cur_blksize != SMSSDIO_BLOCK_SIZE);
@@ -218,9 +230,10 @@ static void smssdio_interrupt(struct sdio_func *func)
218 } 230 }
219 } 231 }
220 232
221 cb->size = hdr->msgLength; 233 cb->size = hdr->msg_length;
222 cb->offset = 0; 234 cb->offset = 0;
223 235
236 smsendian_handle_rx_message((struct sms_msg_data *) cb->p);
224 smscore_onresponse(smsdev->coredev, cb); 237 smscore_onresponse(smsdev->coredev, cb);
225} 238}
226 239
diff --git a/drivers/media/parport/pms.c b/drivers/media/parport/pms.c
index 77f9c92186f4..66c957a02ba7 100644
--- a/drivers/media/parport/pms.c
+++ b/drivers/media/parport/pms.c
@@ -735,12 +735,12 @@ static int pms_g_std(struct file *file, void *fh, v4l2_std_id *std)
735 return 0; 735 return 0;
736} 736}
737 737
738static int pms_s_std(struct file *file, void *fh, v4l2_std_id *std) 738static int pms_s_std(struct file *file, void *fh, v4l2_std_id std)
739{ 739{
740 struct pms *dev = video_drvdata(file); 740 struct pms *dev = video_drvdata(file);
741 int ret = 0; 741 int ret = 0;
742 742
743 dev->std = *std; 743 dev->std = std;
744 if (dev->std & V4L2_STD_NTSC) { 744 if (dev->std & V4L2_STD_NTSC) {
745 pms_framerate(dev, 30); 745 pms_framerate(dev, 30);
746 pms_secamcross(dev, 0); 746 pms_secamcross(dev, 0);
diff --git a/drivers/media/pci/bt8xx/bttv-cards.c b/drivers/media/pci/bt8xx/bttv-cards.c
index c4c59175e52c..b7dc921e1b91 100644
--- a/drivers/media/pci/bt8xx/bttv-cards.c
+++ b/drivers/media/pci/bt8xx/bttv-cards.c
@@ -3547,6 +3547,16 @@ void bttv_init_card2(struct bttv *btv)
3547 if (btv->sd_msp34xx) 3547 if (btv->sd_msp34xx)
3548 return; 3548 return;
3549 3549
3550 /* Now see if we can find one of the tvaudio devices. */
3551 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3552 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3553 if (btv->sd_tvaudio) {
3554 /* There may be two tvaudio chips on the card, so try to
3555 find another. */
3556 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3557 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3558 }
3559
3550 /* it might also be a tda7432. */ 3560 /* it might also be a tda7432. */
3551 if (!bttv_tvcards[btv->c.type].no_tda7432) { 3561 if (!bttv_tvcards[btv->c.type].no_tda7432) {
3552 static const unsigned short addrs[] = { 3562 static const unsigned short addrs[] = {
@@ -3554,14 +3564,11 @@ void bttv_init_card2(struct bttv *btv)
3554 I2C_CLIENT_END 3564 I2C_CLIENT_END
3555 }; 3565 };
3556 3566
3557 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3567 btv->sd_tda7432 = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3558 &btv->c.i2c_adap, "tda7432", 0, addrs)) 3568 &btv->c.i2c_adap, "tda7432", 0, addrs);
3569 if (btv->sd_tda7432)
3559 return; 3570 return;
3560 } 3571 }
3561
3562 /* Now see if we can find one of the tvaudio devices. */
3563 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3564 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3565 if (btv->sd_tvaudio) 3572 if (btv->sd_tvaudio)
3566 return; 3573 return;
3567 3574
@@ -3940,7 +3947,7 @@ static void avermedia_eeprom(struct bttv *btv)
3940u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits) 3947u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits)
3941{ 3948{
3942 3949
3943 if (btv->audio == TVAUDIO_INPUT_TUNER) { 3950 if (btv->audio_input == TVAUDIO_INPUT_TUNER) {
3944 if (bttv_tvnorms[btv->tvnorm].v4l2_id & V4L2_STD_MN) 3951 if (bttv_tvnorms[btv->tvnorm].v4l2_id & V4L2_STD_MN)
3945 gpiobits |= 0x10000; 3952 gpiobits |= 0x10000;
3946 else 3953 else
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 54579e4c740b..e7d088413411 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -49,6 +49,8 @@
49#include "bttvp.h" 49#include "bttvp.h"
50#include <media/v4l2-common.h> 50#include <media/v4l2-common.h>
51#include <media/v4l2-ioctl.h> 51#include <media/v4l2-ioctl.h>
52#include <media/v4l2-event.h>
53#include <media/v4l2-chip-ident.h>
52#include <media/tvaudio.h> 54#include <media/tvaudio.h>
53#include <media/msp3400.h> 55#include <media/msp3400.h>
54 56
@@ -93,7 +95,7 @@ static unsigned int combfilter;
93static unsigned int lumafilter; 95static unsigned int lumafilter;
94static unsigned int automute = 1; 96static unsigned int automute = 1;
95static unsigned int chroma_agc; 97static unsigned int chroma_agc;
96static unsigned int adc_crush = 1; 98static unsigned int agc_crush = 1;
97static unsigned int whitecrush_upper = 0xCF; 99static unsigned int whitecrush_upper = 0xCF;
98static unsigned int whitecrush_lower = 0x7F; 100static unsigned int whitecrush_lower = 0x7F;
99static unsigned int vcr_hack; 101static unsigned int vcr_hack;
@@ -125,7 +127,7 @@ module_param(combfilter, int, 0444);
125module_param(lumafilter, int, 0444); 127module_param(lumafilter, int, 0444);
126module_param(automute, int, 0444); 128module_param(automute, int, 0444);
127module_param(chroma_agc, int, 0444); 129module_param(chroma_agc, int, 0444);
128module_param(adc_crush, int, 0444); 130module_param(agc_crush, int, 0444);
129module_param(whitecrush_upper, int, 0444); 131module_param(whitecrush_upper, int, 0444);
130module_param(whitecrush_lower, int, 0444); 132module_param(whitecrush_lower, int, 0444);
131module_param(vcr_hack, int, 0444); 133module_param(vcr_hack, int, 0444);
@@ -138,27 +140,27 @@ module_param_array(video_nr, int, NULL, 0444);
138module_param_array(radio_nr, int, NULL, 0444); 140module_param_array(radio_nr, int, NULL, 0444);
139module_param_array(vbi_nr, int, NULL, 0444); 141module_param_array(vbi_nr, int, NULL, 0444);
140 142
141MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)"); 143MODULE_PARM_DESC(radio, "The TV card supports radio, default is 0 (no)");
142MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian"); 144MODULE_PARM_DESC(bigendian, "byte order of the framebuffer, default is native endian");
143MODULE_PARM_DESC(bttv_verbose,"verbose startup messages, default is 1 (yes)"); 145MODULE_PARM_DESC(bttv_verbose, "verbose startup messages, default is 1 (yes)");
144MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)"); 146MODULE_PARM_DESC(bttv_gpio, "log gpio changes, default is 0 (no)");
145MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)"); 147MODULE_PARM_DESC(bttv_debug, "debug messages, default is 0 (no)");
146MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)"); 148MODULE_PARM_DESC(irq_debug, "irq handler debug messages, default is 0 (no)");
147MODULE_PARM_DESC(disable_ir, "disable infrared remote support"); 149MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
148MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8"); 150MODULE_PARM_DESC(gbuffers, "number of capture buffers. range 2-32, default 8");
149MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000"); 151MODULE_PARM_DESC(gbufsize, "size of the capture buffers, default is 0x208000");
150MODULE_PARM_DESC(reset_crop,"reset cropping parameters at open(), default " 152MODULE_PARM_DESC(reset_crop, "reset cropping parameters at open(), default "
151 "is 1 (yes) for compatibility with older applications"); 153 "is 1 (yes) for compatibility with older applications");
152MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)"); 154MODULE_PARM_DESC(automute, "mute audio on bad/missing video signal, default is 1 (yes)");
153MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)"); 155MODULE_PARM_DESC(chroma_agc, "enables the AGC of chroma signal, default is 0 (no)");
154MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)"); 156MODULE_PARM_DESC(agc_crush, "enables the luminance AGC crush, default is 1 (yes)");
155MODULE_PARM_DESC(whitecrush_upper,"sets the white crush upper value, default is 207"); 157MODULE_PARM_DESC(whitecrush_upper, "sets the white crush upper value, default is 207");
156MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127"); 158MODULE_PARM_DESC(whitecrush_lower, "sets the white crush lower value, default is 127");
157MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)"); 159MODULE_PARM_DESC(vcr_hack, "enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)");
158MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler"); 160MODULE_PARM_DESC(irq_iswitch, "switch inputs in irq handler");
159MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50"); 161MODULE_PARM_DESC(uv_ratio, "ratio between u and v gains, default is 50");
160MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)"); 162MODULE_PARM_DESC(full_luma_range, "use the full luma range, default is 0 (no)");
161MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)"); 163MODULE_PARM_DESC(coring, "set the luma coring level, default is 0 (no)");
162MODULE_PARM_DESC(video_nr, "video device numbers"); 164MODULE_PARM_DESC(video_nr, "video device numbers");
163MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); 165MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
164MODULE_PARM_DESC(radio_nr, "radio device numbers"); 166MODULE_PARM_DESC(radio_nr, "radio device numbers");
@@ -168,6 +170,17 @@ MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
168MODULE_LICENSE("GPL"); 170MODULE_LICENSE("GPL");
169MODULE_VERSION(BTTV_VERSION); 171MODULE_VERSION(BTTV_VERSION);
170 172
173#define V4L2_CID_PRIVATE_COMBFILTER (V4L2_CID_USER_BTTV_BASE + 0)
174#define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_USER_BTTV_BASE + 1)
175#define V4L2_CID_PRIVATE_LUMAFILTER (V4L2_CID_USER_BTTV_BASE + 2)
176#define V4L2_CID_PRIVATE_AGC_CRUSH (V4L2_CID_USER_BTTV_BASE + 3)
177#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_USER_BTTV_BASE + 4)
178#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_USER_BTTV_BASE + 5)
179#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_USER_BTTV_BASE + 6)
180#define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_USER_BTTV_BASE + 7)
181#define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_USER_BTTV_BASE + 8)
182#define V4L2_CID_PRIVATE_CORING (V4L2_CID_USER_BTTV_BASE + 9)
183
171/* ----------------------------------------------------------------------- */ 184/* ----------------------------------------------------------------------- */
172/* sysfs */ 185/* sysfs */
173 186
@@ -632,198 +645,6 @@ static const struct bttv_format formats[] = {
632static const unsigned int FORMATS = ARRAY_SIZE(formats); 645static const unsigned int FORMATS = ARRAY_SIZE(formats);
633 646
634/* ----------------------------------------------------------------------- */ 647/* ----------------------------------------------------------------------- */
635
636#define V4L2_CID_PRIVATE_CHROMA_AGC (V4L2_CID_PRIVATE_BASE + 0)
637#define V4L2_CID_PRIVATE_COMBFILTER (V4L2_CID_PRIVATE_BASE + 1)
638#define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 2)
639#define V4L2_CID_PRIVATE_LUMAFILTER (V4L2_CID_PRIVATE_BASE + 3)
640#define V4L2_CID_PRIVATE_AGC_CRUSH (V4L2_CID_PRIVATE_BASE + 4)
641#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5)
642#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6)
643#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7)
644#define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_PRIVATE_BASE + 8)
645#define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_PRIVATE_BASE + 9)
646#define V4L2_CID_PRIVATE_CORING (V4L2_CID_PRIVATE_BASE + 10)
647#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 11)
648
649static const struct v4l2_queryctrl no_ctl = {
650 .name = "42",
651 .flags = V4L2_CTRL_FLAG_DISABLED,
652};
653static const struct v4l2_queryctrl bttv_ctls[] = {
654 /* --- video --- */
655 {
656 .id = V4L2_CID_BRIGHTNESS,
657 .name = "Brightness",
658 .minimum = 0,
659 .maximum = 65535,
660 .step = 256,
661 .default_value = 32768,
662 .type = V4L2_CTRL_TYPE_INTEGER,
663 },{
664 .id = V4L2_CID_CONTRAST,
665 .name = "Contrast",
666 .minimum = 0,
667 .maximum = 65535,
668 .step = 128,
669 .default_value = 27648,
670 .type = V4L2_CTRL_TYPE_INTEGER,
671 },{
672 .id = V4L2_CID_SATURATION,
673 .name = "Saturation",
674 .minimum = 0,
675 .maximum = 65535,
676 .step = 128,
677 .default_value = 32768,
678 .type = V4L2_CTRL_TYPE_INTEGER,
679 },{
680 .id = V4L2_CID_COLOR_KILLER,
681 .name = "Color killer",
682 .minimum = 0,
683 .maximum = 1,
684 .type = V4L2_CTRL_TYPE_BOOLEAN,
685 }, {
686 .id = V4L2_CID_HUE,
687 .name = "Hue",
688 .minimum = 0,
689 .maximum = 65535,
690 .step = 256,
691 .default_value = 32768,
692 .type = V4L2_CTRL_TYPE_INTEGER,
693 },
694 /* --- audio --- */
695 {
696 .id = V4L2_CID_AUDIO_MUTE,
697 .name = "Mute",
698 .minimum = 0,
699 .maximum = 1,
700 .type = V4L2_CTRL_TYPE_BOOLEAN,
701 },{
702 .id = V4L2_CID_AUDIO_VOLUME,
703 .name = "Volume",
704 .minimum = 0,
705 .maximum = 65535,
706 .step = 65535/100,
707 .default_value = 65535,
708 .type = V4L2_CTRL_TYPE_INTEGER,
709 },{
710 .id = V4L2_CID_AUDIO_BALANCE,
711 .name = "Balance",
712 .minimum = 0,
713 .maximum = 65535,
714 .step = 65535/100,
715 .default_value = 32768,
716 .type = V4L2_CTRL_TYPE_INTEGER,
717 },{
718 .id = V4L2_CID_AUDIO_BASS,
719 .name = "Bass",
720 .minimum = 0,
721 .maximum = 65535,
722 .step = 65535/100,
723 .default_value = 32768,
724 .type = V4L2_CTRL_TYPE_INTEGER,
725 },{
726 .id = V4L2_CID_AUDIO_TREBLE,
727 .name = "Treble",
728 .minimum = 0,
729 .maximum = 65535,
730 .step = 65535/100,
731 .default_value = 32768,
732 .type = V4L2_CTRL_TYPE_INTEGER,
733 },
734 /* --- private --- */
735 {
736 .id = V4L2_CID_PRIVATE_CHROMA_AGC,
737 .name = "chroma agc",
738 .minimum = 0,
739 .maximum = 1,
740 .type = V4L2_CTRL_TYPE_BOOLEAN,
741 },{
742 .id = V4L2_CID_PRIVATE_COMBFILTER,
743 .name = "combfilter",
744 .minimum = 0,
745 .maximum = 1,
746 .type = V4L2_CTRL_TYPE_BOOLEAN,
747 },{
748 .id = V4L2_CID_PRIVATE_AUTOMUTE,
749 .name = "automute",
750 .minimum = 0,
751 .maximum = 1,
752 .type = V4L2_CTRL_TYPE_BOOLEAN,
753 },{
754 .id = V4L2_CID_PRIVATE_LUMAFILTER,
755 .name = "luma decimation filter",
756 .minimum = 0,
757 .maximum = 1,
758 .type = V4L2_CTRL_TYPE_BOOLEAN,
759 },{
760 .id = V4L2_CID_PRIVATE_AGC_CRUSH,
761 .name = "agc crush",
762 .minimum = 0,
763 .maximum = 1,
764 .type = V4L2_CTRL_TYPE_BOOLEAN,
765 },{
766 .id = V4L2_CID_PRIVATE_VCR_HACK,
767 .name = "vcr hack",
768 .minimum = 0,
769 .maximum = 1,
770 .type = V4L2_CTRL_TYPE_BOOLEAN,
771 },{
772 .id = V4L2_CID_PRIVATE_WHITECRUSH_UPPER,
773 .name = "whitecrush upper",
774 .minimum = 0,
775 .maximum = 255,
776 .step = 1,
777 .default_value = 0xCF,
778 .type = V4L2_CTRL_TYPE_INTEGER,
779 },{
780 .id = V4L2_CID_PRIVATE_WHITECRUSH_LOWER,
781 .name = "whitecrush lower",
782 .minimum = 0,
783 .maximum = 255,
784 .step = 1,
785 .default_value = 0x7F,
786 .type = V4L2_CTRL_TYPE_INTEGER,
787 },{
788 .id = V4L2_CID_PRIVATE_UV_RATIO,
789 .name = "uv ratio",
790 .minimum = 0,
791 .maximum = 100,
792 .step = 1,
793 .default_value = 50,
794 .type = V4L2_CTRL_TYPE_INTEGER,
795 },{
796 .id = V4L2_CID_PRIVATE_FULL_LUMA_RANGE,
797 .name = "full luma range",
798 .minimum = 0,
799 .maximum = 1,
800 .type = V4L2_CTRL_TYPE_BOOLEAN,
801 },{
802 .id = V4L2_CID_PRIVATE_CORING,
803 .name = "coring",
804 .minimum = 0,
805 .maximum = 3,
806 .step = 1,
807 .default_value = 0,
808 .type = V4L2_CTRL_TYPE_INTEGER,
809 }
810
811
812
813};
814
815static const struct v4l2_queryctrl *ctrl_by_id(int id)
816{
817 int i;
818
819 for (i = 0; i < ARRAY_SIZE(bttv_ctls); i++)
820 if (bttv_ctls[i].id == id)
821 return bttv_ctls+i;
822
823 return NULL;
824}
825
826/* ----------------------------------------------------------------------- */
827/* resource management */ 648/* resource management */
828 649
829/* 650/*
@@ -1178,23 +999,20 @@ static char *audio_modes[] = {
1178 "audio: intern", "audio: mute" 999 "audio: intern", "audio: mute"
1179}; 1000};
1180 1001
1181static int 1002static void
1182audio_mux(struct bttv *btv, int input, int mute) 1003audio_mux_gpio(struct bttv *btv, int input, int mute)
1183{ 1004{
1184 int gpio_val, signal; 1005 int gpio_val, signal, mute_gpio;
1185 struct v4l2_control ctrl;
1186 1006
1187 gpio_inout(bttv_tvcards[btv->c.type].gpiomask, 1007 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
1188 bttv_tvcards[btv->c.type].gpiomask); 1008 bttv_tvcards[btv->c.type].gpiomask);
1189 signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC; 1009 signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC;
1190 1010
1191 btv->mute = mute;
1192 btv->audio = input;
1193
1194 /* automute */ 1011 /* automute */
1195 mute = mute || (btv->opt_automute && !signal && !btv->radio_user); 1012 mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users)
1013 && !btv->has_radio_tuner);
1196 1014
1197 if (mute) 1015 if (mute_gpio)
1198 gpio_val = bttv_tvcards[btv->c.type].gpiomute; 1016 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
1199 else 1017 else
1200 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input]; 1018 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
@@ -1210,13 +1028,39 @@ audio_mux(struct bttv *btv, int input, int mute)
1210 } 1028 }
1211 1029
1212 if (bttv_gpio) 1030 if (bttv_gpio)
1213 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]); 1031 bttv_gpio_tracking(btv, audio_modes[mute_gpio ? 4 : input]);
1214 if (in_interrupt()) 1032}
1215 return 0; 1033
1034static int
1035audio_mute(struct bttv *btv, int mute)
1036{
1037 struct v4l2_ctrl *ctrl;
1038
1039 audio_mux_gpio(btv, btv->audio_input, mute);
1040
1041 if (btv->sd_msp34xx) {
1042 ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1043 if (ctrl)
1044 v4l2_ctrl_s_ctrl(ctrl, mute);
1045 }
1046 if (btv->sd_tvaudio) {
1047 ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1048 if (ctrl)
1049 v4l2_ctrl_s_ctrl(ctrl, mute);
1050 }
1051 if (btv->sd_tda7432) {
1052 ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1053 if (ctrl)
1054 v4l2_ctrl_s_ctrl(ctrl, mute);
1055 }
1056 return 0;
1057}
1058
1059static int
1060audio_input(struct bttv *btv, int input)
1061{
1062 audio_mux_gpio(btv, input, btv->mute);
1216 1063
1217 ctrl.id = V4L2_CID_AUDIO_MUTE;
1218 ctrl.value = btv->mute;
1219 bttv_call_all(btv, core, s_ctrl, &ctrl);
1220 if (btv->sd_msp34xx) { 1064 if (btv->sd_msp34xx) {
1221 u32 in; 1065 u32 in;
1222 1066
@@ -1265,23 +1109,11 @@ audio_mux(struct bttv *btv, int input, int mute)
1265 } 1109 }
1266 if (btv->sd_tvaudio) { 1110 if (btv->sd_tvaudio) {
1267 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing, 1111 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
1268 input, 0, 0); 1112 input, 0, 0);
1269 } 1113 }
1270 return 0; 1114 return 0;
1271} 1115}
1272 1116
1273static inline int
1274audio_mute(struct bttv *btv, int mute)
1275{
1276 return audio_mux(btv, btv->audio, mute);
1277}
1278
1279static inline int
1280audio_input(struct bttv *btv, int input)
1281{
1282 return audio_mux(btv, input, btv->mute);
1283}
1284
1285static void 1117static void
1286bttv_crop_calc_limits(struct bttv_crop *c) 1118bttv_crop_calc_limits(struct bttv_crop *c)
1287{ 1119{
@@ -1375,8 +1207,9 @@ set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1375 } else { 1207 } else {
1376 video_mux(btv,input); 1208 video_mux(btv,input);
1377 } 1209 }
1378 audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ? 1210 btv->audio_input = (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1379 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN); 1211 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN;
1212 audio_input(btv, btv->audio_input);
1380 set_tvnorm(btv, norm); 1213 set_tvnorm(btv, norm);
1381} 1214}
1382 1215
@@ -1404,8 +1237,6 @@ static void init_irqreg(struct bttv *btv)
1404 1237
1405static void init_bt848(struct bttv *btv) 1238static void init_bt848(struct bttv *btv)
1406{ 1239{
1407 int val;
1408
1409 if (bttv_tvcards[btv->c.type].no_video) { 1240 if (bttv_tvcards[btv->c.type].no_video) {
1410 /* very basic init only */ 1241 /* very basic init only */
1411 init_irqreg(btv); 1242 init_irqreg(btv);
@@ -1425,30 +1256,10 @@ static void init_bt848(struct bttv *btv)
1425 BT848_GPIO_DMA_CTL_GPINTI, 1256 BT848_GPIO_DMA_CTL_GPINTI,
1426 BT848_GPIO_DMA_CTL); 1257 BT848_GPIO_DMA_CTL);
1427 1258
1428 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1429 btwrite(val, BT848_E_SCLOOP);
1430 btwrite(val, BT848_O_SCLOOP);
1431
1432 btwrite(0x20, BT848_E_VSCALE_HI); 1259 btwrite(0x20, BT848_E_VSCALE_HI);
1433 btwrite(0x20, BT848_O_VSCALE_HI); 1260 btwrite(0x20, BT848_O_VSCALE_HI);
1434 btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1435 BT848_ADC);
1436
1437 btwrite(whitecrush_upper, BT848_WC_UP);
1438 btwrite(whitecrush_lower, BT848_WC_DOWN);
1439
1440 if (btv->opt_lumafilter) {
1441 btwrite(0, BT848_E_CONTROL);
1442 btwrite(0, BT848_O_CONTROL);
1443 } else {
1444 btwrite(BT848_CONTROL_LDEC, BT848_E_CONTROL);
1445 btwrite(BT848_CONTROL_LDEC, BT848_O_CONTROL);
1446 }
1447 1261
1448 bt848_bright(btv, btv->bright); 1262 v4l2_ctrl_handler_setup(&btv->ctrl_handler);
1449 bt848_hue(btv, btv->hue);
1450 bt848_contrast(btv, btv->contrast);
1451 bt848_sat(btv, btv->saturation);
1452 1263
1453 /* interrupt */ 1264 /* interrupt */
1454 init_irqreg(btv); 1265 init_irqreg(btv);
@@ -1470,103 +1281,26 @@ static void bttv_reinit_bt848(struct bttv *btv)
1470 set_input(btv, btv->input, btv->tvnorm); 1281 set_input(btv, btv->input, btv->tvnorm);
1471} 1282}
1472 1283
1473static int bttv_g_ctrl(struct file *file, void *priv, 1284static int bttv_s_ctrl(struct v4l2_ctrl *c)
1474 struct v4l2_control *c)
1475{ 1285{
1476 struct bttv_fh *fh = priv; 1286 struct bttv *btv = container_of(c->handler, struct bttv, ctrl_handler);
1477 struct bttv *btv = fh->btv; 1287 int val;
1478
1479 switch (c->id) {
1480 case V4L2_CID_BRIGHTNESS:
1481 c->value = btv->bright;
1482 break;
1483 case V4L2_CID_HUE:
1484 c->value = btv->hue;
1485 break;
1486 case V4L2_CID_CONTRAST:
1487 c->value = btv->contrast;
1488 break;
1489 case V4L2_CID_SATURATION:
1490 c->value = btv->saturation;
1491 break;
1492 case V4L2_CID_COLOR_KILLER:
1493 c->value = btv->opt_color_killer;
1494 break;
1495
1496 case V4L2_CID_AUDIO_MUTE:
1497 case V4L2_CID_AUDIO_VOLUME:
1498 case V4L2_CID_AUDIO_BALANCE:
1499 case V4L2_CID_AUDIO_BASS:
1500 case V4L2_CID_AUDIO_TREBLE:
1501 bttv_call_all(btv, core, g_ctrl, c);
1502 break;
1503
1504 case V4L2_CID_PRIVATE_CHROMA_AGC:
1505 c->value = btv->opt_chroma_agc;
1506 break;
1507 case V4L2_CID_PRIVATE_COMBFILTER:
1508 c->value = btv->opt_combfilter;
1509 break;
1510 case V4L2_CID_PRIVATE_LUMAFILTER:
1511 c->value = btv->opt_lumafilter;
1512 break;
1513 case V4L2_CID_PRIVATE_AUTOMUTE:
1514 c->value = btv->opt_automute;
1515 break;
1516 case V4L2_CID_PRIVATE_AGC_CRUSH:
1517 c->value = btv->opt_adc_crush;
1518 break;
1519 case V4L2_CID_PRIVATE_VCR_HACK:
1520 c->value = btv->opt_vcr_hack;
1521 break;
1522 case V4L2_CID_PRIVATE_WHITECRUSH_UPPER:
1523 c->value = btv->opt_whitecrush_upper;
1524 break;
1525 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER:
1526 c->value = btv->opt_whitecrush_lower;
1527 break;
1528 case V4L2_CID_PRIVATE_UV_RATIO:
1529 c->value = btv->opt_uv_ratio;
1530 break;
1531 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1532 c->value = btv->opt_full_luma_range;
1533 break;
1534 case V4L2_CID_PRIVATE_CORING:
1535 c->value = btv->opt_coring;
1536 break;
1537 default:
1538 return -EINVAL;
1539 }
1540 return 0;
1541}
1542
1543static int bttv_s_ctrl(struct file *file, void *f,
1544 struct v4l2_control *c)
1545{
1546 int err;
1547 struct bttv_fh *fh = f;
1548 struct bttv *btv = fh->btv;
1549
1550 err = v4l2_prio_check(&btv->prio, fh->prio);
1551 if (0 != err)
1552 return err;
1553 1288
1554 switch (c->id) { 1289 switch (c->id) {
1555 case V4L2_CID_BRIGHTNESS: 1290 case V4L2_CID_BRIGHTNESS:
1556 bt848_bright(btv, c->value); 1291 bt848_bright(btv, c->val);
1557 break; 1292 break;
1558 case V4L2_CID_HUE: 1293 case V4L2_CID_HUE:
1559 bt848_hue(btv, c->value); 1294 bt848_hue(btv, c->val);
1560 break; 1295 break;
1561 case V4L2_CID_CONTRAST: 1296 case V4L2_CID_CONTRAST:
1562 bt848_contrast(btv, c->value); 1297 bt848_contrast(btv, c->val);
1563 break; 1298 break;
1564 case V4L2_CID_SATURATION: 1299 case V4L2_CID_SATURATION:
1565 bt848_sat(btv, c->value); 1300 bt848_sat(btv, c->val);
1566 break; 1301 break;
1567 case V4L2_CID_COLOR_KILLER: 1302 case V4L2_CID_COLOR_KILLER:
1568 btv->opt_color_killer = c->value; 1303 if (c->val) {
1569 if (btv->opt_color_killer) {
1570 btor(BT848_SCLOOP_CKILL, BT848_E_SCLOOP); 1304 btor(BT848_SCLOOP_CKILL, BT848_E_SCLOOP);
1571 btor(BT848_SCLOOP_CKILL, BT848_O_SCLOOP); 1305 btor(BT848_SCLOOP_CKILL, BT848_O_SCLOOP);
1572 } else { 1306 } else {
@@ -1575,36 +1309,23 @@ static int bttv_s_ctrl(struct file *file, void *f,
1575 } 1309 }
1576 break; 1310 break;
1577 case V4L2_CID_AUDIO_MUTE: 1311 case V4L2_CID_AUDIO_MUTE:
1578 audio_mute(btv, c->value); 1312 audio_mute(btv, c->val);
1579 /* fall through */ 1313 btv->mute = c->val;
1580 case V4L2_CID_AUDIO_VOLUME:
1581 if (btv->volume_gpio)
1582 btv->volume_gpio(btv, c->value);
1583
1584 bttv_call_all(btv, core, s_ctrl, c);
1585 break; 1314 break;
1586 case V4L2_CID_AUDIO_BALANCE: 1315 case V4L2_CID_AUDIO_VOLUME:
1587 case V4L2_CID_AUDIO_BASS: 1316 btv->volume_gpio(btv, c->val);
1588 case V4L2_CID_AUDIO_TREBLE:
1589 bttv_call_all(btv, core, s_ctrl, c);
1590 break; 1317 break;
1591 1318
1592 case V4L2_CID_PRIVATE_CHROMA_AGC: 1319 case V4L2_CID_CHROMA_AGC:
1593 btv->opt_chroma_agc = c->value; 1320 val = c->val ? BT848_SCLOOP_CAGC : 0;
1594 if (btv->opt_chroma_agc) { 1321 btwrite(val, BT848_E_SCLOOP);
1595 btor(BT848_SCLOOP_CAGC, BT848_E_SCLOOP); 1322 btwrite(val, BT848_O_SCLOOP);
1596 btor(BT848_SCLOOP_CAGC, BT848_O_SCLOOP);
1597 } else {
1598 btand(~BT848_SCLOOP_CAGC, BT848_E_SCLOOP);
1599 btand(~BT848_SCLOOP_CAGC, BT848_O_SCLOOP);
1600 }
1601 break; 1323 break;
1602 case V4L2_CID_PRIVATE_COMBFILTER: 1324 case V4L2_CID_PRIVATE_COMBFILTER:
1603 btv->opt_combfilter = c->value; 1325 btv->opt_combfilter = c->val;
1604 break; 1326 break;
1605 case V4L2_CID_PRIVATE_LUMAFILTER: 1327 case V4L2_CID_PRIVATE_LUMAFILTER:
1606 btv->opt_lumafilter = c->value; 1328 if (c->val) {
1607 if (btv->opt_lumafilter) {
1608 btand(~BT848_CONTROL_LDEC, BT848_E_CONTROL); 1329 btand(~BT848_CONTROL_LDEC, BT848_E_CONTROL);
1609 btand(~BT848_CONTROL_LDEC, BT848_O_CONTROL); 1330 btand(~BT848_CONTROL_LDEC, BT848_O_CONTROL);
1610 } else { 1331 } else {
@@ -1613,36 +1334,31 @@ static int bttv_s_ctrl(struct file *file, void *f,
1613 } 1334 }
1614 break; 1335 break;
1615 case V4L2_CID_PRIVATE_AUTOMUTE: 1336 case V4L2_CID_PRIVATE_AUTOMUTE:
1616 btv->opt_automute = c->value; 1337 btv->opt_automute = c->val;
1617 break; 1338 break;
1618 case V4L2_CID_PRIVATE_AGC_CRUSH: 1339 case V4L2_CID_PRIVATE_AGC_CRUSH:
1619 btv->opt_adc_crush = c->value;
1620 btwrite(BT848_ADC_RESERVED | 1340 btwrite(BT848_ADC_RESERVED |
1621 (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0), 1341 (c->val ? BT848_ADC_CRUSH : 0),
1622 BT848_ADC); 1342 BT848_ADC);
1623 break; 1343 break;
1624 case V4L2_CID_PRIVATE_VCR_HACK: 1344 case V4L2_CID_PRIVATE_VCR_HACK:
1625 btv->opt_vcr_hack = c->value; 1345 btv->opt_vcr_hack = c->val;
1626 break; 1346 break;
1627 case V4L2_CID_PRIVATE_WHITECRUSH_UPPER: 1347 case V4L2_CID_PRIVATE_WHITECRUSH_UPPER:
1628 btv->opt_whitecrush_upper = c->value; 1348 btwrite(c->val, BT848_WC_UP);
1629 btwrite(c->value, BT848_WC_UP);
1630 break; 1349 break;
1631 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER: 1350 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER:
1632 btv->opt_whitecrush_lower = c->value; 1351 btwrite(c->val, BT848_WC_DOWN);
1633 btwrite(c->value, BT848_WC_DOWN);
1634 break; 1352 break;
1635 case V4L2_CID_PRIVATE_UV_RATIO: 1353 case V4L2_CID_PRIVATE_UV_RATIO:
1636 btv->opt_uv_ratio = c->value; 1354 btv->opt_uv_ratio = c->val;
1637 bt848_sat(btv, btv->saturation); 1355 bt848_sat(btv, btv->saturation);
1638 break; 1356 break;
1639 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE: 1357 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1640 btv->opt_full_luma_range = c->value; 1358 btaor((c->val << 7), ~BT848_OFORM_RANGE, BT848_OFORM);
1641 btaor((c->value<<7), ~BT848_OFORM_RANGE, BT848_OFORM);
1642 break; 1359 break;
1643 case V4L2_CID_PRIVATE_CORING: 1360 case V4L2_CID_PRIVATE_CORING:
1644 btv->opt_coring = c->value; 1361 btaor((c->val << 5), ~BT848_OFORM_CORE32, BT848_OFORM);
1645 btaor((c->value<<5), ~BT848_OFORM_CORE32, BT848_OFORM);
1646 break; 1362 break;
1647 default: 1363 default:
1648 return -EINVAL; 1364 return -EINVAL;
@@ -1652,6 +1368,121 @@ static int bttv_s_ctrl(struct file *file, void *f,
1652 1368
1653/* ----------------------------------------------------------------------- */ 1369/* ----------------------------------------------------------------------- */
1654 1370
1371static const struct v4l2_ctrl_ops bttv_ctrl_ops = {
1372 .s_ctrl = bttv_s_ctrl,
1373};
1374
1375static struct v4l2_ctrl_config bttv_ctrl_combfilter = {
1376 .ops = &bttv_ctrl_ops,
1377 .id = V4L2_CID_PRIVATE_COMBFILTER,
1378 .name = "Comb Filter",
1379 .type = V4L2_CTRL_TYPE_BOOLEAN,
1380 .min = 0,
1381 .max = 1,
1382 .step = 1,
1383 .def = 1,
1384};
1385
1386static struct v4l2_ctrl_config bttv_ctrl_automute = {
1387 .ops = &bttv_ctrl_ops,
1388 .id = V4L2_CID_PRIVATE_AUTOMUTE,
1389 .name = "Auto Mute",
1390 .type = V4L2_CTRL_TYPE_BOOLEAN,
1391 .min = 0,
1392 .max = 1,
1393 .step = 1,
1394 .def = 1,
1395};
1396
1397static struct v4l2_ctrl_config bttv_ctrl_lumafilter = {
1398 .ops = &bttv_ctrl_ops,
1399 .id = V4L2_CID_PRIVATE_LUMAFILTER,
1400 .name = "Luma Decimation Filter",
1401 .type = V4L2_CTRL_TYPE_BOOLEAN,
1402 .min = 0,
1403 .max = 1,
1404 .step = 1,
1405 .def = 1,
1406};
1407
1408static struct v4l2_ctrl_config bttv_ctrl_agc_crush = {
1409 .ops = &bttv_ctrl_ops,
1410 .id = V4L2_CID_PRIVATE_AGC_CRUSH,
1411 .name = "AGC Crush",
1412 .type = V4L2_CTRL_TYPE_BOOLEAN,
1413 .min = 0,
1414 .max = 1,
1415 .step = 1,
1416 .def = 1,
1417};
1418
1419static struct v4l2_ctrl_config bttv_ctrl_vcr_hack = {
1420 .ops = &bttv_ctrl_ops,
1421 .id = V4L2_CID_PRIVATE_VCR_HACK,
1422 .name = "VCR Hack",
1423 .type = V4L2_CTRL_TYPE_BOOLEAN,
1424 .min = 0,
1425 .max = 1,
1426 .step = 1,
1427 .def = 1,
1428};
1429
1430static struct v4l2_ctrl_config bttv_ctrl_whitecrush_lower = {
1431 .ops = &bttv_ctrl_ops,
1432 .id = V4L2_CID_PRIVATE_WHITECRUSH_LOWER,
1433 .name = "Whitecrush Lower",
1434 .type = V4L2_CTRL_TYPE_INTEGER,
1435 .min = 0,
1436 .max = 255,
1437 .step = 1,
1438 .def = 0x7f,
1439};
1440
1441static struct v4l2_ctrl_config bttv_ctrl_whitecrush_upper = {
1442 .ops = &bttv_ctrl_ops,
1443 .id = V4L2_CID_PRIVATE_WHITECRUSH_UPPER,
1444 .name = "Whitecrush Upper",
1445 .type = V4L2_CTRL_TYPE_INTEGER,
1446 .min = 0,
1447 .max = 255,
1448 .step = 1,
1449 .def = 0xcf,
1450};
1451
1452static struct v4l2_ctrl_config bttv_ctrl_uv_ratio = {
1453 .ops = &bttv_ctrl_ops,
1454 .id = V4L2_CID_PRIVATE_UV_RATIO,
1455 .name = "UV Ratio",
1456 .type = V4L2_CTRL_TYPE_INTEGER,
1457 .min = 0,
1458 .max = 100,
1459 .step = 1,
1460 .def = 50,
1461};
1462
1463static struct v4l2_ctrl_config bttv_ctrl_full_luma = {
1464 .ops = &bttv_ctrl_ops,
1465 .id = V4L2_CID_PRIVATE_FULL_LUMA_RANGE,
1466 .name = "Full Luma Range",
1467 .type = V4L2_CTRL_TYPE_BOOLEAN,
1468 .min = 0,
1469 .max = 1,
1470 .step = 1,
1471};
1472
1473static struct v4l2_ctrl_config bttv_ctrl_coring = {
1474 .ops = &bttv_ctrl_ops,
1475 .id = V4L2_CID_PRIVATE_CORING,
1476 .name = "Coring",
1477 .type = V4L2_CTRL_TYPE_INTEGER,
1478 .min = 0,
1479 .max = 3,
1480 .step = 1,
1481};
1482
1483
1484/* ----------------------------------------------------------------------- */
1485
1655void bttv_gpio_tracking(struct bttv *btv, char *comment) 1486void bttv_gpio_tracking(struct bttv *btv, char *comment)
1656{ 1487{
1657 unsigned int outbits, data; 1488 unsigned int outbits, data;
@@ -1881,25 +1712,33 @@ static struct videobuf_queue_ops bttv_video_qops = {
1881 .buf_release = buffer_release, 1712 .buf_release = buffer_release,
1882}; 1713};
1883 1714
1884static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id) 1715static void radio_enable(struct bttv *btv)
1716{
1717 /* Switch to the radio tuner */
1718 if (!btv->has_radio_tuner) {
1719 btv->has_radio_tuner = 1;
1720 bttv_call_all(btv, tuner, s_radio);
1721 btv->audio_input = TVAUDIO_INPUT_RADIO;
1722 audio_input(btv, btv->audio_input);
1723 }
1724}
1725
1726static int bttv_s_std(struct file *file, void *priv, v4l2_std_id id)
1885{ 1727{
1886 struct bttv_fh *fh = priv; 1728 struct bttv_fh *fh = priv;
1887 struct bttv *btv = fh->btv; 1729 struct bttv *btv = fh->btv;
1888 unsigned int i; 1730 unsigned int i;
1889 int err; 1731 int err = 0;
1890
1891 err = v4l2_prio_check(&btv->prio, fh->prio);
1892 if (err)
1893 goto err;
1894 1732
1895 for (i = 0; i < BTTV_TVNORMS; i++) 1733 for (i = 0; i < BTTV_TVNORMS; i++)
1896 if (*id & bttv_tvnorms[i].v4l2_id) 1734 if (id & bttv_tvnorms[i].v4l2_id)
1897 break; 1735 break;
1898 if (i == BTTV_TVNORMS) { 1736 if (i == BTTV_TVNORMS) {
1899 err = -EINVAL; 1737 err = -EINVAL;
1900 goto err; 1738 goto err;
1901 } 1739 }
1902 1740
1741 btv->std = id;
1903 set_tvnorm(btv, i); 1742 set_tvnorm(btv, i);
1904 1743
1905err: 1744err:
@@ -1907,6 +1746,15 @@ err:
1907 return err; 1746 return err;
1908} 1747}
1909 1748
1749static int bttv_g_std(struct file *file, void *priv, v4l2_std_id *id)
1750{
1751 struct bttv_fh *fh = priv;
1752 struct bttv *btv = fh->btv;
1753
1754 *id = btv->std;
1755 return 0;
1756}
1757
1910static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id) 1758static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id)
1911{ 1759{
1912 struct bttv_fh *fh = f; 1760 struct bttv_fh *fh = f;
@@ -1932,7 +1780,7 @@ static int bttv_enum_input(struct file *file, void *priv,
1932 } 1780 }
1933 1781
1934 i->type = V4L2_INPUT_TYPE_CAMERA; 1782 i->type = V4L2_INPUT_TYPE_CAMERA;
1935 i->audioset = 1; 1783 i->audioset = 0;
1936 1784
1937 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) { 1785 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) {
1938 sprintf(i->name, "Television"); 1786 sprintf(i->name, "Television");
@@ -1974,49 +1822,29 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i)
1974 struct bttv_fh *fh = priv; 1822 struct bttv_fh *fh = priv;
1975 struct bttv *btv = fh->btv; 1823 struct bttv *btv = fh->btv;
1976 1824
1977 int err; 1825 if (i >= bttv_tvcards[btv->c.type].video_inputs)
1978 1826 return -EINVAL;
1979 err = v4l2_prio_check(&btv->prio, fh->prio);
1980 if (unlikely(err))
1981 goto err;
1982
1983 if (i > bttv_tvcards[btv->c.type].video_inputs) {
1984 err = -EINVAL;
1985 goto err;
1986 }
1987 1827
1988 set_input(btv, i, btv->tvnorm); 1828 set_input(btv, i, btv->tvnorm);
1989
1990err:
1991 return 0; 1829 return 0;
1992} 1830}
1993 1831
1994static int bttv_s_tuner(struct file *file, void *priv, 1832static int bttv_s_tuner(struct file *file, void *priv,
1995 struct v4l2_tuner *t) 1833 const struct v4l2_tuner *t)
1996{ 1834{
1997 struct bttv_fh *fh = priv; 1835 struct bttv_fh *fh = priv;
1998 struct bttv *btv = fh->btv; 1836 struct bttv *btv = fh->btv;
1999 int err;
2000 1837
2001 if (unlikely(0 != t->index)) 1838 if (t->index)
2002 return -EINVAL; 1839 return -EINVAL;
2003 1840
2004 if (unlikely(btv->tuner_type == TUNER_ABSENT)) {
2005 err = -EINVAL;
2006 goto err;
2007 }
2008
2009 err = v4l2_prio_check(&btv->prio, fh->prio);
2010 if (unlikely(err))
2011 goto err;
2012
2013 bttv_call_all(btv, tuner, s_tuner, t); 1841 bttv_call_all(btv, tuner, s_tuner, t);
2014 1842
2015 if (btv->audio_mode_gpio) 1843 if (btv->audio_mode_gpio) {
2016 btv->audio_mode_gpio(btv, t, 1); 1844 struct v4l2_tuner copy = *t;
2017
2018err:
2019 1845
1846 btv->audio_mode_gpio(btv, &copy, 1);
1847 }
2020 return 0; 1848 return 0;
2021} 1849}
2022 1850
@@ -2026,49 +1854,81 @@ static int bttv_g_frequency(struct file *file, void *priv,
2026 struct bttv_fh *fh = priv; 1854 struct bttv_fh *fh = priv;
2027 struct bttv *btv = fh->btv; 1855 struct bttv *btv = fh->btv;
2028 1856
2029 f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1857 if (f->tuner)
2030 f->frequency = btv->freq; 1858 return -EINVAL;
1859
1860 if (f->type == V4L2_TUNER_RADIO)
1861 radio_enable(btv);
1862 f->frequency = f->type == V4L2_TUNER_RADIO ?
1863 btv->radio_freq : btv->tv_freq;
2031 1864
2032 return 0; 1865 return 0;
2033} 1866}
2034 1867
1868static void bttv_set_frequency(struct bttv *btv, const struct v4l2_frequency *f)
1869{
1870 struct v4l2_frequency new_freq = *f;
1871
1872 bttv_call_all(btv, tuner, s_frequency, f);
1873 /* s_frequency may clamp the frequency, so get the actual
1874 frequency before assigning radio/tv_freq. */
1875 bttv_call_all(btv, tuner, g_frequency, &new_freq);
1876 if (new_freq.type == V4L2_TUNER_RADIO) {
1877 radio_enable(btv);
1878 btv->radio_freq = new_freq.frequency;
1879 if (btv->has_matchbox)
1880 tea5757_set_freq(btv, btv->radio_freq);
1881 } else {
1882 btv->tv_freq = new_freq.frequency;
1883 }
1884}
1885
2035static int bttv_s_frequency(struct file *file, void *priv, 1886static int bttv_s_frequency(struct file *file, void *priv,
2036 struct v4l2_frequency *f) 1887 const struct v4l2_frequency *f)
2037{ 1888{
2038 struct bttv_fh *fh = priv; 1889 struct bttv_fh *fh = priv;
2039 struct bttv *btv = fh->btv; 1890 struct bttv *btv = fh->btv;
2040 int err;
2041 1891
2042 if (unlikely(f->tuner != 0)) 1892 if (f->tuner)
2043 return -EINVAL; 1893 return -EINVAL;
2044 1894
2045 err = v4l2_prio_check(&btv->prio, fh->prio); 1895 bttv_set_frequency(btv, f);
2046 if (unlikely(err))
2047 goto err;
2048
2049 if (unlikely(f->type != (btv->radio_user
2050 ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV))) {
2051 err = -EINVAL;
2052 goto err;
2053 }
2054 btv->freq = f->frequency;
2055 bttv_call_all(btv, tuner, s_frequency, f);
2056 if (btv->has_matchbox && btv->radio_user)
2057 tea5757_set_freq(btv, btv->freq);
2058err:
2059
2060 return 0; 1896 return 0;
2061} 1897}
2062 1898
2063static int bttv_log_status(struct file *file, void *f) 1899static int bttv_log_status(struct file *file, void *f)
2064{ 1900{
1901 struct video_device *vdev = video_devdata(file);
2065 struct bttv_fh *fh = f; 1902 struct bttv_fh *fh = f;
2066 struct bttv *btv = fh->btv; 1903 struct bttv *btv = fh->btv;
2067 1904
1905 v4l2_ctrl_handler_log_status(vdev->ctrl_handler, btv->c.v4l2_dev.name);
2068 bttv_call_all(btv, core, log_status); 1906 bttv_call_all(btv, core, log_status);
2069 return 0; 1907 return 0;
2070} 1908}
2071 1909
1910static int bttv_g_chip_ident(struct file *file, void *f, struct v4l2_dbg_chip_ident *chip)
1911{
1912 struct bttv_fh *fh = f;
1913 struct bttv *btv = fh->btv;
1914
1915 chip->ident = V4L2_IDENT_NONE;
1916 chip->revision = 0;
1917 if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
1918 if (v4l2_chip_match_host(&chip->match)) {
1919 chip->ident = btv->id;
1920 if (chip->ident == PCI_DEVICE_ID_FUSION879)
1921 chip->ident = V4L2_IDENT_BT879;
1922 }
1923 return 0;
1924 }
1925 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1926 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1927 return -EINVAL;
1928 /* TODO: is this correct? */
1929 return bttv_call_all_err(btv, core, g_chip_ident, chip);
1930}
1931
2072#ifdef CONFIG_VIDEO_ADV_DEBUG 1932#ifdef CONFIG_VIDEO_ADV_DEBUG
2073static int bttv_g_register(struct file *file, void *f, 1933static int bttv_g_register(struct file *file, void *f,
2074 struct v4l2_dbg_register *reg) 1934 struct v4l2_dbg_register *reg)
@@ -2079,8 +1939,12 @@ static int bttv_g_register(struct file *file, void *f,
2079 if (!capable(CAP_SYS_ADMIN)) 1939 if (!capable(CAP_SYS_ADMIN))
2080 return -EPERM; 1940 return -EPERM;
2081 1941
2082 if (!v4l2_chip_match_host(&reg->match)) 1942 if (!v4l2_chip_match_host(&reg->match)) {
2083 return -EINVAL; 1943 /* TODO: subdev errors should not be ignored, this should become a
1944 subdev helper function. */
1945 bttv_call_all(btv, core, g_register, reg);
1946 return 0;
1947 }
2084 1948
2085 /* bt848 has a 12-bit register space */ 1949 /* bt848 has a 12-bit register space */
2086 reg->reg &= 0xfff; 1950 reg->reg &= 0xfff;
@@ -2091,7 +1955,7 @@ static int bttv_g_register(struct file *file, void *f,
2091} 1955}
2092 1956
2093static int bttv_s_register(struct file *file, void *f, 1957static int bttv_s_register(struct file *file, void *f,
2094 struct v4l2_dbg_register *reg) 1958 const struct v4l2_dbg_register *reg)
2095{ 1959{
2096 struct bttv_fh *fh = f; 1960 struct bttv_fh *fh = f;
2097 struct bttv *btv = fh->btv; 1961 struct bttv *btv = fh->btv;
@@ -2099,12 +1963,15 @@ static int bttv_s_register(struct file *file, void *f,
2099 if (!capable(CAP_SYS_ADMIN)) 1963 if (!capable(CAP_SYS_ADMIN))
2100 return -EPERM; 1964 return -EPERM;
2101 1965
2102 if (!v4l2_chip_match_host(&reg->match)) 1966 if (!v4l2_chip_match_host(&reg->match)) {
2103 return -EINVAL; 1967 /* TODO: subdev errors should not be ignored, this should become a
1968 subdev helper function. */
1969 bttv_call_all(btv, core, s_register, reg);
1970 return 0;
1971 }
2104 1972
2105 /* bt848 has a 12-bit register space */ 1973 /* bt848 has a 12-bit register space */
2106 reg->reg &= 0xfff; 1974 btwrite(reg->val, reg->reg & 0xfff);
2107 btwrite(reg->val, reg->reg);
2108 1975
2109 return 0; 1976 return 0;
2110} 1977}
@@ -2273,22 +2140,33 @@ limit_scaled_size_lock (struct bttv_fh * fh,
2273 may also adjust the current cropping parameters to get closer 2140 may also adjust the current cropping parameters to get closer
2274 to the desired window size. */ 2141 to the desired window size. */
2275static int 2142static int
2276verify_window_lock (struct bttv_fh * fh, 2143verify_window_lock(struct bttv_fh *fh, struct v4l2_window *win,
2277 struct v4l2_window * win, 2144 int adjust_size, int adjust_crop)
2278 int adjust_size,
2279 int adjust_crop)
2280{ 2145{
2281 enum v4l2_field field; 2146 enum v4l2_field field;
2282 unsigned int width_mask; 2147 unsigned int width_mask;
2283 int rc; 2148 int rc;
2284 2149
2285 if (win->w.width < 48 || win->w.height < 32) 2150 if (win->w.width < 48)
2286 return -EINVAL; 2151 win->w.width = 48;
2152 if (win->w.height < 32)
2153 win->w.height = 32;
2287 if (win->clipcount > 2048) 2154 if (win->clipcount > 2048)
2288 return -EINVAL; 2155 win->clipcount = 2048;
2289 2156
2157 win->chromakey = 0;
2158 win->global_alpha = 0;
2290 field = win->field; 2159 field = win->field;
2291 2160
2161 switch (field) {
2162 case V4L2_FIELD_TOP:
2163 case V4L2_FIELD_BOTTOM:
2164 case V4L2_FIELD_INTERLACED:
2165 break;
2166 default:
2167 field = V4L2_FIELD_ANY;
2168 break;
2169 }
2292 if (V4L2_FIELD_ANY == field) { 2170 if (V4L2_FIELD_ANY == field) {
2293 __s32 height2; 2171 __s32 height2;
2294 2172
@@ -2297,18 +2175,11 @@ verify_window_lock (struct bttv_fh * fh,
2297 ? V4L2_FIELD_INTERLACED 2175 ? V4L2_FIELD_INTERLACED
2298 : V4L2_FIELD_TOP; 2176 : V4L2_FIELD_TOP;
2299 } 2177 }
2300 switch (field) { 2178 win->field = field;
2301 case V4L2_FIELD_TOP:
2302 case V4L2_FIELD_BOTTOM:
2303 case V4L2_FIELD_INTERLACED:
2304 break;
2305 default:
2306 return -EINVAL;
2307 }
2308 2179
2309 /* 4-byte alignment. */
2310 if (NULL == fh->ovfmt) 2180 if (NULL == fh->ovfmt)
2311 return -EINVAL; 2181 return -EINVAL;
2182 /* 4-byte alignment. */
2312 width_mask = ~0; 2183 width_mask = ~0;
2313 switch (fh->ovfmt->depth) { 2184 switch (fh->ovfmt->depth) {
2314 case 8: 2185 case 8:
@@ -2333,8 +2204,6 @@ verify_window_lock (struct bttv_fh * fh,
2333 adjust_size, adjust_crop); 2204 adjust_size, adjust_crop);
2334 if (0 != rc) 2205 if (0 != rc)
2335 return rc; 2206 return rc;
2336
2337 win->field = field;
2338 return 0; 2207 return 0;
2339} 2208}
2340 2209
@@ -2491,6 +2360,7 @@ static int bttv_g_fmt_vid_cap(struct file *file, void *priv,
2491 fh->width, fh->height); 2360 fh->width, fh->height);
2492 f->fmt.pix.field = fh->cap.field; 2361 f->fmt.pix.field = fh->cap.field;
2493 f->fmt.pix.pixelformat = fh->fmt->fourcc; 2362 f->fmt.pix.pixelformat = fh->fmt->fourcc;
2363 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
2494 2364
2495 return 0; 2365 return 0;
2496} 2366}
@@ -2514,6 +2384,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv,
2514 struct bttv *btv = fh->btv; 2384 struct bttv *btv = fh->btv;
2515 enum v4l2_field field; 2385 enum v4l2_field field;
2516 __s32 width, height; 2386 __s32 width, height;
2387 __s32 height2;
2517 int rc; 2388 int rc;
2518 2389
2519 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 2390 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
@@ -2522,30 +2393,25 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv,
2522 2393
2523 field = f->fmt.pix.field; 2394 field = f->fmt.pix.field;
2524 2395
2525 if (V4L2_FIELD_ANY == field) {
2526 __s32 height2;
2527
2528 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2529 field = (f->fmt.pix.height > height2)
2530 ? V4L2_FIELD_INTERLACED
2531 : V4L2_FIELD_BOTTOM;
2532 }
2533
2534 if (V4L2_FIELD_SEQ_BT == field)
2535 field = V4L2_FIELD_SEQ_TB;
2536
2537 switch (field) { 2396 switch (field) {
2538 case V4L2_FIELD_TOP: 2397 case V4L2_FIELD_TOP:
2539 case V4L2_FIELD_BOTTOM: 2398 case V4L2_FIELD_BOTTOM:
2540 case V4L2_FIELD_ALTERNATE: 2399 case V4L2_FIELD_ALTERNATE:
2541 case V4L2_FIELD_INTERLACED: 2400 case V4L2_FIELD_INTERLACED:
2542 break; 2401 break;
2402 case V4L2_FIELD_SEQ_BT:
2543 case V4L2_FIELD_SEQ_TB: 2403 case V4L2_FIELD_SEQ_TB:
2544 if (fmt->flags & FORMAT_FLAGS_PLANAR) 2404 if (!(fmt->flags & FORMAT_FLAGS_PLANAR)) {
2545 return -EINVAL; 2405 field = V4L2_FIELD_SEQ_TB;
2406 break;
2407 }
2408 /* fall through */
2409 default: /* FIELD_ANY case */
2410 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2411 field = (f->fmt.pix.height > height2)
2412 ? V4L2_FIELD_INTERLACED
2413 : V4L2_FIELD_BOTTOM;
2546 break; 2414 break;
2547 default:
2548 return -EINVAL;
2549 } 2415 }
2550 2416
2551 width = f->fmt.pix.width; 2417 width = f->fmt.pix.width;
@@ -2562,6 +2428,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv,
2562 /* update data for the application */ 2428 /* update data for the application */
2563 f->fmt.pix.field = field; 2429 f->fmt.pix.field = field;
2564 pix_format_set_size(&f->fmt.pix, fmt, width, height); 2430 pix_format_set_size(&f->fmt.pix, fmt, width, height);
2431 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
2565 2432
2566 return 0; 2433 return 0;
2567} 2434}
@@ -2571,9 +2438,10 @@ static int bttv_try_fmt_vid_overlay(struct file *file, void *priv,
2571{ 2438{
2572 struct bttv_fh *fh = priv; 2439 struct bttv_fh *fh = priv;
2573 2440
2574 return verify_window_lock(fh, &f->fmt.win, 2441 verify_window_lock(fh, &f->fmt.win,
2575 /* adjust_size */ 1, 2442 /* adjust_size */ 1,
2576 /* adjust_crop */ 0); 2443 /* adjust_crop */ 0);
2444 return 0;
2577} 2445}
2578 2446
2579static int bttv_s_fmt_vid_cap(struct file *file, void *priv, 2447static int bttv_s_fmt_vid_cap(struct file *file, void *priv,
@@ -2640,6 +2508,7 @@ static int bttv_s_fmt_vid_overlay(struct file *file, void *priv,
2640static int bttv_querycap(struct file *file, void *priv, 2508static int bttv_querycap(struct file *file, void *priv,
2641 struct v4l2_capability *cap) 2509 struct v4l2_capability *cap)
2642{ 2510{
2511 struct video_device *vdev = video_devdata(file);
2643 struct bttv_fh *fh = priv; 2512 struct bttv_fh *fh = priv;
2644 struct bttv *btv = fh->btv; 2513 struct bttv *btv = fh->btv;
2645 2514
@@ -2652,11 +2521,15 @@ static int bttv_querycap(struct file *file, void *priv,
2652 "PCI:%s", pci_name(btv->c.pci)); 2521 "PCI:%s", pci_name(btv->c.pci));
2653 cap->capabilities = 2522 cap->capabilities =
2654 V4L2_CAP_VIDEO_CAPTURE | 2523 V4L2_CAP_VIDEO_CAPTURE |
2655 V4L2_CAP_VBI_CAPTURE |
2656 V4L2_CAP_READWRITE | 2524 V4L2_CAP_READWRITE |
2657 V4L2_CAP_STREAMING; 2525 V4L2_CAP_STREAMING |
2526 V4L2_CAP_DEVICE_CAPS;
2658 if (no_overlay <= 0) 2527 if (no_overlay <= 0)
2659 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; 2528 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
2529 if (btv->vbi_dev)
2530 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
2531 if (btv->radio_dev)
2532 cap->capabilities |= V4L2_CAP_RADIO;
2660 2533
2661 /* 2534 /*
2662 * No need to lock here: those vars are initialized during board 2535 * No need to lock here: those vars are initialized during board
@@ -2666,6 +2539,25 @@ static int bttv_querycap(struct file *file, void *priv,
2666 cap->capabilities |= V4L2_CAP_RDS_CAPTURE; 2539 cap->capabilities |= V4L2_CAP_RDS_CAPTURE;
2667 if (btv->tuner_type != TUNER_ABSENT) 2540 if (btv->tuner_type != TUNER_ABSENT)
2668 cap->capabilities |= V4L2_CAP_TUNER; 2541 cap->capabilities |= V4L2_CAP_TUNER;
2542 if (vdev->vfl_type == VFL_TYPE_GRABBER)
2543 cap->device_caps = cap->capabilities &
2544 (V4L2_CAP_VIDEO_CAPTURE |
2545 V4L2_CAP_READWRITE |
2546 V4L2_CAP_STREAMING |
2547 V4L2_CAP_VIDEO_OVERLAY |
2548 V4L2_CAP_TUNER);
2549 else if (vdev->vfl_type == VFL_TYPE_VBI)
2550 cap->device_caps = cap->capabilities &
2551 (V4L2_CAP_VBI_CAPTURE |
2552 V4L2_CAP_READWRITE |
2553 V4L2_CAP_STREAMING |
2554 V4L2_CAP_TUNER);
2555 else {
2556 cap->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
2557 if (btv->has_saa6588)
2558 cap->device_caps |= V4L2_CAP_READWRITE |
2559 V4L2_CAP_RDS_CAPTURE;
2560 }
2669 return 0; 2561 return 0;
2670} 2562}
2671 2563
@@ -2728,6 +2620,7 @@ static int bttv_g_fbuf(struct file *file, void *f,
2728 2620
2729 *fb = btv->fbuf; 2621 *fb = btv->fbuf;
2730 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; 2622 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
2623 fb->flags = V4L2_FBUF_FLAG_PRIMARY;
2731 if (fh->ovfmt) 2624 if (fh->ovfmt)
2732 fb->fmt.pixelformat = fh->ovfmt->fourcc; 2625 fb->fmt.pixelformat = fh->ovfmt->fourcc;
2733 return 0; 2626 return 0;
@@ -2901,36 +2794,15 @@ static int bttv_streamoff(struct file *file, void *priv,
2901 return 0; 2794 return 0;
2902} 2795}
2903 2796
2904static int bttv_queryctrl(struct file *file, void *priv,
2905 struct v4l2_queryctrl *c)
2906{
2907 struct bttv_fh *fh = priv;
2908 struct bttv *btv = fh->btv;
2909 const struct v4l2_queryctrl *ctrl;
2910
2911 if ((c->id < V4L2_CID_BASE ||
2912 c->id >= V4L2_CID_LASTP1) &&
2913 (c->id < V4L2_CID_PRIVATE_BASE ||
2914 c->id >= V4L2_CID_PRIVATE_LASTP1))
2915 return -EINVAL;
2916
2917 if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME))
2918 *c = no_ctl;
2919 else {
2920 ctrl = ctrl_by_id(c->id);
2921
2922 *c = (NULL != ctrl) ? *ctrl : no_ctl;
2923 }
2924
2925 return 0;
2926}
2927
2928static int bttv_g_parm(struct file *file, void *f, 2797static int bttv_g_parm(struct file *file, void *f,
2929 struct v4l2_streamparm *parm) 2798 struct v4l2_streamparm *parm)
2930{ 2799{
2931 struct bttv_fh *fh = f; 2800 struct bttv_fh *fh = f;
2932 struct bttv *btv = fh->btv; 2801 struct bttv *btv = fh->btv;
2933 2802
2803 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2804 return -EINVAL;
2805 parm->parm.capture.readbuffers = gbuffers;
2934 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, 2806 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2935 &parm->parm.capture.timeperframe); 2807 &parm->parm.capture.timeperframe);
2936 2808
@@ -2943,15 +2815,13 @@ static int bttv_g_tuner(struct file *file, void *priv,
2943 struct bttv_fh *fh = priv; 2815 struct bttv_fh *fh = priv;
2944 struct bttv *btv = fh->btv; 2816 struct bttv *btv = fh->btv;
2945 2817
2946 if (btv->tuner_type == TUNER_ABSENT)
2947 return -EINVAL;
2948 if (0 != t->index) 2818 if (0 != t->index)
2949 return -EINVAL; 2819 return -EINVAL;
2950 2820
2951 t->rxsubchans = V4L2_TUNER_SUB_MONO; 2821 t->rxsubchans = V4L2_TUNER_SUB_MONO;
2822 t->capability = V4L2_TUNER_CAP_NORM;
2952 bttv_call_all(btv, tuner, g_tuner, t); 2823 bttv_call_all(btv, tuner, g_tuner, t);
2953 strcpy(t->name, "Television"); 2824 strcpy(t->name, "Television");
2954 t->capability = V4L2_TUNER_CAP_NORM;
2955 t->type = V4L2_TUNER_ANALOG_TV; 2825 t->type = V4L2_TUNER_ANALOG_TV;
2956 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC) 2826 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC)
2957 t->signal = 0xffff; 2827 t->signal = 0xffff;
@@ -2962,28 +2832,6 @@ static int bttv_g_tuner(struct file *file, void *priv,
2962 return 0; 2832 return 0;
2963} 2833}
2964 2834
2965static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p)
2966{
2967 struct bttv_fh *fh = f;
2968 struct bttv *btv = fh->btv;
2969
2970 *p = v4l2_prio_max(&btv->prio);
2971
2972 return 0;
2973}
2974
2975static int bttv_s_priority(struct file *file, void *f,
2976 enum v4l2_priority prio)
2977{
2978 struct bttv_fh *fh = f;
2979 struct bttv *btv = fh->btv;
2980 int rc;
2981
2982 rc = v4l2_prio_change(&btv->prio, &fh->prio, prio);
2983
2984 return rc;
2985}
2986
2987static int bttv_cropcap(struct file *file, void *priv, 2835static int bttv_cropcap(struct file *file, void *priv,
2988 struct v4l2_cropcap *cap) 2836 struct v4l2_cropcap *cap)
2989{ 2837{
@@ -3036,11 +2884,6 @@ static int bttv_s_crop(struct file *file, void *f, const struct v4l2_crop *crop)
3036 /* Make sure tvnorm, vbi_end and the current cropping 2884 /* Make sure tvnorm, vbi_end and the current cropping
3037 parameters remain consistent until we're done. Note 2885 parameters remain consistent until we're done. Note
3038 read() may change vbi_end in check_alloc_btres_lock(). */ 2886 read() may change vbi_end in check_alloc_btres_lock(). */
3039 retval = v4l2_prio_check(&btv->prio, fh->prio);
3040 if (0 != retval) {
3041 return retval;
3042 }
3043
3044 retval = -EBUSY; 2887 retval = -EBUSY;
3045 2888
3046 if (locked_btres(fh->btv, VIDEO_RESOURCES)) { 2889 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
@@ -3098,23 +2941,6 @@ static int bttv_s_crop(struct file *file, void *f, const struct v4l2_crop *crop)
3098 return 0; 2941 return 0;
3099} 2942}
3100 2943
3101static int bttv_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
3102{
3103 if (unlikely(a->index))
3104 return -EINVAL;
3105
3106 strcpy(a->name, "audio");
3107 return 0;
3108}
3109
3110static int bttv_s_audio(struct file *file, void *priv, const struct v4l2_audio *a)
3111{
3112 if (unlikely(a->index))
3113 return -EINVAL;
3114
3115 return 0;
3116}
3117
3118static ssize_t bttv_read(struct file *file, char __user *data, 2944static ssize_t bttv_read(struct file *file, char __user *data,
3119 size_t count, loff_t *ppos) 2945 size_t count, loff_t *ppos)
3120{ 2946{
@@ -3154,34 +2980,43 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3154 struct bttv_fh *fh = file->private_data; 2980 struct bttv_fh *fh = file->private_data;
3155 struct bttv_buffer *buf; 2981 struct bttv_buffer *buf;
3156 enum v4l2_field field; 2982 enum v4l2_field field;
3157 unsigned int rc = POLLERR; 2983 unsigned int rc = 0;
2984 unsigned long req_events = poll_requested_events(wait);
2985
2986 if (v4l2_event_pending(&fh->fh))
2987 rc = POLLPRI;
2988 else if (req_events & POLLPRI)
2989 poll_wait(file, &fh->fh.wait, wait);
2990
2991 if (!(req_events & (POLLIN | POLLRDNORM)))
2992 return rc;
3158 2993
3159 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { 2994 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
3160 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) 2995 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI))
3161 return POLLERR; 2996 return rc | POLLERR;
3162 return videobuf_poll_stream(file, &fh->vbi, wait); 2997 return rc | videobuf_poll_stream(file, &fh->vbi, wait);
3163 } 2998 }
3164 2999
3165 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { 3000 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) {
3166 /* streaming capture */ 3001 /* streaming capture */
3167 if (list_empty(&fh->cap.stream)) 3002 if (list_empty(&fh->cap.stream))
3168 goto err; 3003 return rc | POLLERR;
3169 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); 3004 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream);
3170 } else { 3005 } else {
3171 /* read() capture */ 3006 /* read() capture */
3172 if (NULL == fh->cap.read_buf) { 3007 if (NULL == fh->cap.read_buf) {
3173 /* need to capture a new frame */ 3008 /* need to capture a new frame */
3174 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) 3009 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM))
3175 goto err; 3010 return rc | POLLERR;
3176 fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize); 3011 fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize);
3177 if (NULL == fh->cap.read_buf) 3012 if (NULL == fh->cap.read_buf)
3178 goto err; 3013 return rc | POLLERR;
3179 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; 3014 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR;
3180 field = videobuf_next_field(&fh->cap); 3015 field = videobuf_next_field(&fh->cap);
3181 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) { 3016 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) {
3182 kfree (fh->cap.read_buf); 3017 kfree (fh->cap.read_buf);
3183 fh->cap.read_buf = NULL; 3018 fh->cap.read_buf = NULL;
3184 goto err; 3019 return rc | POLLERR;
3185 } 3020 }
3186 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); 3021 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
3187 fh->cap.read_off = 0; 3022 fh->cap.read_off = 0;
@@ -3192,10 +3027,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3192 poll_wait(file, &buf->vb.done, wait); 3027 poll_wait(file, &buf->vb.done, wait);
3193 if (buf->vb.state == VIDEOBUF_DONE || 3028 if (buf->vb.state == VIDEOBUF_DONE ||
3194 buf->vb.state == VIDEOBUF_ERROR) 3029 buf->vb.state == VIDEOBUF_ERROR)
3195 rc = POLLIN|POLLRDNORM; 3030 rc = rc | POLLIN|POLLRDNORM;
3196 else
3197 rc = 0;
3198err:
3199 return rc; 3031 return rc;
3200} 3032}
3201 3033
@@ -3224,15 +3056,15 @@ static int bttv_open(struct file *file)
3224 fh = kmalloc(sizeof(*fh), GFP_KERNEL); 3056 fh = kmalloc(sizeof(*fh), GFP_KERNEL);
3225 if (unlikely(!fh)) 3057 if (unlikely(!fh))
3226 return -ENOMEM; 3058 return -ENOMEM;
3059 btv->users++;
3227 file->private_data = fh; 3060 file->private_data = fh;
3228 3061
3229 *fh = btv->init; 3062 *fh = btv->init;
3063 v4l2_fh_init(&fh->fh, vdev);
3230 3064
3231 fh->type = type; 3065 fh->type = type;
3232 fh->ov.setup_ok = 0; 3066 fh->ov.setup_ok = 0;
3233 3067
3234 v4l2_prio_open(&btv->prio, &fh->prio);
3235
3236 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, 3068 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops,
3237 &btv->c.pci->dev, &btv->s_lock, 3069 &btv->c.pci->dev, &btv->s_lock,
3238 V4L2_BUF_TYPE_VIDEO_CAPTURE, 3070 V4L2_BUF_TYPE_VIDEO_CAPTURE,
@@ -3247,8 +3079,7 @@ static int bttv_open(struct file *file)
3247 fh, &btv->lock); 3079 fh, &btv->lock);
3248 set_tvnorm(btv,btv->tvnorm); 3080 set_tvnorm(btv,btv->tvnorm);
3249 set_input(btv, btv->input, btv->tvnorm); 3081 set_input(btv, btv->input, btv->tvnorm);
3250 3082 audio_mute(btv, btv->mute);
3251 btv->users++;
3252 3083
3253 /* The V4L2 spec requires one global set of cropping parameters 3084 /* The V4L2 spec requires one global set of cropping parameters
3254 which only change on request. These are stored in btv->crop[1]. 3085 which only change on request. These are stored in btv->crop[1].
@@ -3267,6 +3098,7 @@ static int bttv_open(struct file *file)
3267 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); 3098 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3268 3099
3269 bttv_field_count(btv); 3100 bttv_field_count(btv);
3101 v4l2_fh_add(&fh->fh);
3270 return 0; 3102 return 0;
3271} 3103}
3272 3104
@@ -3302,16 +3134,17 @@ static int bttv_release(struct file *file)
3302 3134
3303 videobuf_mmap_free(&fh->cap); 3135 videobuf_mmap_free(&fh->cap);
3304 videobuf_mmap_free(&fh->vbi); 3136 videobuf_mmap_free(&fh->vbi);
3305 v4l2_prio_close(&btv->prio, fh->prio);
3306 file->private_data = NULL; 3137 file->private_data = NULL;
3307 kfree(fh);
3308 3138
3309 btv->users--; 3139 btv->users--;
3310 bttv_field_count(btv); 3140 bttv_field_count(btv);
3311 3141
3312 if (!btv->users) 3142 if (!btv->users)
3313 audio_mute(btv, 1); 3143 audio_mute(btv, btv->mute);
3314 3144
3145 v4l2_fh_del(&fh->fh);
3146 v4l2_fh_exit(&fh->fh);
3147 kfree(fh);
3315 return 0; 3148 return 0;
3316} 3149}
3317 3150
@@ -3350,20 +3183,16 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3350 .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap, 3183 .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap,
3351 .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap, 3184 .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap,
3352 .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap, 3185 .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap,
3353 .vidioc_g_audio = bttv_g_audio,
3354 .vidioc_s_audio = bttv_s_audio,
3355 .vidioc_cropcap = bttv_cropcap, 3186 .vidioc_cropcap = bttv_cropcap,
3356 .vidioc_reqbufs = bttv_reqbufs, 3187 .vidioc_reqbufs = bttv_reqbufs,
3357 .vidioc_querybuf = bttv_querybuf, 3188 .vidioc_querybuf = bttv_querybuf,
3358 .vidioc_qbuf = bttv_qbuf, 3189 .vidioc_qbuf = bttv_qbuf,
3359 .vidioc_dqbuf = bttv_dqbuf, 3190 .vidioc_dqbuf = bttv_dqbuf,
3360 .vidioc_s_std = bttv_s_std, 3191 .vidioc_s_std = bttv_s_std,
3192 .vidioc_g_std = bttv_g_std,
3361 .vidioc_enum_input = bttv_enum_input, 3193 .vidioc_enum_input = bttv_enum_input,
3362 .vidioc_g_input = bttv_g_input, 3194 .vidioc_g_input = bttv_g_input,
3363 .vidioc_s_input = bttv_s_input, 3195 .vidioc_s_input = bttv_s_input,
3364 .vidioc_queryctrl = bttv_queryctrl,
3365 .vidioc_g_ctrl = bttv_g_ctrl,
3366 .vidioc_s_ctrl = bttv_s_ctrl,
3367 .vidioc_streamon = bttv_streamon, 3196 .vidioc_streamon = bttv_streamon,
3368 .vidioc_streamoff = bttv_streamoff, 3197 .vidioc_streamoff = bttv_streamoff,
3369 .vidioc_g_tuner = bttv_g_tuner, 3198 .vidioc_g_tuner = bttv_g_tuner,
@@ -3373,13 +3202,14 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3373 .vidioc_g_fbuf = bttv_g_fbuf, 3202 .vidioc_g_fbuf = bttv_g_fbuf,
3374 .vidioc_s_fbuf = bttv_s_fbuf, 3203 .vidioc_s_fbuf = bttv_s_fbuf,
3375 .vidioc_overlay = bttv_overlay, 3204 .vidioc_overlay = bttv_overlay,
3376 .vidioc_g_priority = bttv_g_priority,
3377 .vidioc_s_priority = bttv_s_priority,
3378 .vidioc_g_parm = bttv_g_parm, 3205 .vidioc_g_parm = bttv_g_parm,
3379 .vidioc_g_frequency = bttv_g_frequency, 3206 .vidioc_g_frequency = bttv_g_frequency,
3380 .vidioc_s_frequency = bttv_s_frequency, 3207 .vidioc_s_frequency = bttv_s_frequency,
3381 .vidioc_log_status = bttv_log_status, 3208 .vidioc_log_status = bttv_log_status,
3382 .vidioc_querystd = bttv_querystd, 3209 .vidioc_querystd = bttv_querystd,
3210 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
3211 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
3212 .vidioc_g_chip_ident = bttv_g_chip_ident,
3383#ifdef CONFIG_VIDEO_ADV_DEBUG 3213#ifdef CONFIG_VIDEO_ADV_DEBUG
3384 .vidioc_g_register = bttv_g_register, 3214 .vidioc_g_register = bttv_g_register,
3385 .vidioc_s_register = bttv_s_register, 3215 .vidioc_s_register = bttv_s_register,
@@ -3390,7 +3220,6 @@ static struct video_device bttv_video_template = {
3390 .fops = &bttv_fops, 3220 .fops = &bttv_fops,
3391 .ioctl_ops = &bttv_ioctl_ops, 3221 .ioctl_ops = &bttv_ioctl_ops,
3392 .tvnorms = BTTV_NORMS, 3222 .tvnorms = BTTV_NORMS,
3393 .current_norm = V4L2_STD_PAL,
3394}; 3223};
3395 3224
3396/* ----------------------------------------------------------------------- */ 3225/* ----------------------------------------------------------------------- */
@@ -3412,13 +3241,12 @@ static int radio_open(struct file *file)
3412 return -ENOMEM; 3241 return -ENOMEM;
3413 file->private_data = fh; 3242 file->private_data = fh;
3414 *fh = btv->init; 3243 *fh = btv->init;
3415 3244 v4l2_fh_init(&fh->fh, vdev);
3416 v4l2_prio_open(&btv->prio, &fh->prio);
3417 3245
3418 btv->radio_user++; 3246 btv->radio_user++;
3247 audio_mute(btv, btv->mute);
3419 3248
3420 bttv_call_all(btv, tuner, s_radio); 3249 v4l2_fh_add(&fh->fh);
3421 audio_input(btv,TVAUDIO_INPUT_RADIO);
3422 3250
3423 return 0; 3251 return 0;
3424} 3252}
@@ -3429,28 +3257,17 @@ static int radio_release(struct file *file)
3429 struct bttv *btv = fh->btv; 3257 struct bttv *btv = fh->btv;
3430 struct saa6588_command cmd; 3258 struct saa6588_command cmd;
3431 3259
3432 v4l2_prio_close(&btv->prio, fh->prio);
3433 file->private_data = NULL; 3260 file->private_data = NULL;
3261 v4l2_fh_del(&fh->fh);
3262 v4l2_fh_exit(&fh->fh);
3434 kfree(fh); 3263 kfree(fh);
3435 3264
3436 btv->radio_user--; 3265 btv->radio_user--;
3437 3266
3438 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd); 3267 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
3439 3268
3440 return 0; 3269 if (btv->radio_user == 0)
3441} 3270 btv->has_radio_tuner = 0;
3442
3443static int radio_querycap(struct file *file, void *priv,
3444 struct v4l2_capability *cap)
3445{
3446 struct bttv_fh *fh = priv;
3447 struct bttv *btv = fh->btv;
3448
3449 strcpy(cap->driver, "bttv");
3450 strlcpy(cap->card, btv->radio_dev->name, sizeof(cap->card));
3451 sprintf(cap->bus_info, "PCI:%s", pci_name(btv->c.pci));
3452 cap->capabilities = V4L2_CAP_TUNER;
3453
3454 return 0; 3271 return 0;
3455} 3272}
3456 3273
@@ -3459,12 +3276,11 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3459 struct bttv_fh *fh = priv; 3276 struct bttv_fh *fh = priv;
3460 struct bttv *btv = fh->btv; 3277 struct bttv *btv = fh->btv;
3461 3278
3462 if (btv->tuner_type == TUNER_ABSENT)
3463 return -EINVAL;
3464 if (0 != t->index) 3279 if (0 != t->index)
3465 return -EINVAL; 3280 return -EINVAL;
3466 strcpy(t->name, "Radio"); 3281 strcpy(t->name, "Radio");
3467 t->type = V4L2_TUNER_RADIO; 3282 t->type = V4L2_TUNER_RADIO;
3283 radio_enable(btv);
3468 3284
3469 bttv_call_all(btv, tuner, g_tuner, t); 3285 bttv_call_all(btv, tuner, g_tuner, t);
3470 3286
@@ -3474,31 +3290,8 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3474 return 0; 3290 return 0;
3475} 3291}
3476 3292
3477static int radio_enum_input(struct file *file, void *priv,
3478 struct v4l2_input *i)
3479{
3480 if (i->index != 0)
3481 return -EINVAL;
3482
3483 strcpy(i->name, "Radio");
3484 i->type = V4L2_INPUT_TYPE_TUNER;
3485
3486 return 0;
3487}
3488
3489static int radio_g_audio(struct file *file, void *priv,
3490 struct v4l2_audio *a)
3491{
3492 if (unlikely(a->index))
3493 return -EINVAL;
3494
3495 strcpy(a->name, "Radio");
3496
3497 return 0;
3498}
3499
3500static int radio_s_tuner(struct file *file, void *priv, 3293static int radio_s_tuner(struct file *file, void *priv,
3501 struct v4l2_tuner *t) 3294 const struct v4l2_tuner *t)
3502{ 3295{
3503 struct bttv_fh *fh = priv; 3296 struct bttv_fh *fh = priv;
3504 struct bttv *btv = fh->btv; 3297 struct bttv *btv = fh->btv;
@@ -3506,56 +3299,11 @@ static int radio_s_tuner(struct file *file, void *priv,
3506 if (0 != t->index) 3299 if (0 != t->index)
3507 return -EINVAL; 3300 return -EINVAL;
3508 3301
3302 radio_enable(btv);
3509 bttv_call_all(btv, tuner, s_tuner, t); 3303 bttv_call_all(btv, tuner, s_tuner, t);
3510 return 0; 3304 return 0;
3511} 3305}
3512 3306
3513static int radio_s_audio(struct file *file, void *priv,
3514 const struct v4l2_audio *a)
3515{
3516 if (unlikely(a->index))
3517 return -EINVAL;
3518
3519 return 0;
3520}
3521
3522static int radio_s_input(struct file *filp, void *priv, unsigned int i)
3523{
3524 if (unlikely(i))
3525 return -EINVAL;
3526
3527 return 0;
3528}
3529
3530static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
3531{
3532 return 0;
3533}
3534
3535static int radio_queryctrl(struct file *file, void *priv,
3536 struct v4l2_queryctrl *c)
3537{
3538 const struct v4l2_queryctrl *ctrl;
3539
3540 if (c->id < V4L2_CID_BASE ||
3541 c->id >= V4L2_CID_LASTP1)
3542 return -EINVAL;
3543
3544 if (c->id == V4L2_CID_AUDIO_MUTE) {
3545 ctrl = ctrl_by_id(c->id);
3546 *c = *ctrl;
3547 } else
3548 *c = no_ctl;
3549
3550 return 0;
3551}
3552
3553static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
3554{
3555 *i = 0;
3556 return 0;
3557}
3558
3559static ssize_t radio_read(struct file *file, char __user *data, 3307static ssize_t radio_read(struct file *file, char __user *data,
3560 size_t count, loff_t *ppos) 3308 size_t count, loff_t *ppos)
3561{ 3309{
@@ -3566,6 +3314,7 @@ static ssize_t radio_read(struct file *file, char __user *data,
3566 cmd.buffer = data; 3314 cmd.buffer = data;
3567 cmd.instance = file; 3315 cmd.instance = file;
3568 cmd.result = -ENODEV; 3316 cmd.result = -ENODEV;
3317 radio_enable(btv);
3569 3318
3570 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd); 3319 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd);
3571 3320
@@ -3576,10 +3325,18 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
3576{ 3325{
3577 struct bttv_fh *fh = file->private_data; 3326 struct bttv_fh *fh = file->private_data;
3578 struct bttv *btv = fh->btv; 3327 struct bttv *btv = fh->btv;
3328 unsigned long req_events = poll_requested_events(wait);
3579 struct saa6588_command cmd; 3329 struct saa6588_command cmd;
3330 unsigned int res = 0;
3331
3332 if (v4l2_event_pending(&fh->fh))
3333 res = POLLPRI;
3334 else if (req_events & POLLPRI)
3335 poll_wait(file, &fh->fh.wait, wait);
3336 radio_enable(btv);
3580 cmd.instance = file; 3337 cmd.instance = file;
3581 cmd.event_list = wait; 3338 cmd.event_list = wait;
3582 cmd.result = -ENODEV; 3339 cmd.result = res;
3583 bttv_call_all(btv, core, ioctl, SAA6588_CMD_POLL, &cmd); 3340 bttv_call_all(btv, core, ioctl, SAA6588_CMD_POLL, &cmd);
3584 3341
3585 return cmd.result; 3342 return cmd.result;
@@ -3596,20 +3353,14 @@ static const struct v4l2_file_operations radio_fops =
3596}; 3353};
3597 3354
3598static const struct v4l2_ioctl_ops radio_ioctl_ops = { 3355static const struct v4l2_ioctl_ops radio_ioctl_ops = {
3599 .vidioc_querycap = radio_querycap, 3356 .vidioc_querycap = bttv_querycap,
3357 .vidioc_log_status = bttv_log_status,
3600 .vidioc_g_tuner = radio_g_tuner, 3358 .vidioc_g_tuner = radio_g_tuner,
3601 .vidioc_enum_input = radio_enum_input,
3602 .vidioc_g_audio = radio_g_audio,
3603 .vidioc_s_tuner = radio_s_tuner, 3359 .vidioc_s_tuner = radio_s_tuner,
3604 .vidioc_s_audio = radio_s_audio,
3605 .vidioc_s_input = radio_s_input,
3606 .vidioc_s_std = radio_s_std,
3607 .vidioc_queryctrl = radio_queryctrl,
3608 .vidioc_g_input = radio_g_input,
3609 .vidioc_g_ctrl = bttv_g_ctrl,
3610 .vidioc_s_ctrl = bttv_s_ctrl,
3611 .vidioc_g_frequency = bttv_g_frequency, 3360 .vidioc_g_frequency = bttv_g_frequency,
3612 .vidioc_s_frequency = bttv_s_frequency, 3361 .vidioc_s_frequency = bttv_s_frequency,
3362 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
3363 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
3613}; 3364};
3614 3365
3615static struct video_device radio_template = { 3366static struct video_device radio_template = {
@@ -4112,7 +3863,8 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4112 bttv_irq_switch_video(btv); 3863 bttv_irq_switch_video(btv);
4113 3864
4114 if ((astat & BT848_INT_HLOCK) && btv->opt_automute) 3865 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
4115 audio_mute(btv, btv->mute); /* trigger automute */ 3866 /* trigger automute */
3867 audio_mux_gpio(btv, btv->audio_input, btv->mute);
4116 3868
4117 if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) { 3869 if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) {
4118 pr_info("%d: %s%s @ %08x,", 3870 pr_info("%d: %s%s @ %08x,",
@@ -4161,7 +3913,7 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4161 3913
4162 3914
4163/* ----------------------------------------------------------------------- */ 3915/* ----------------------------------------------------------------------- */
4164/* initialitation */ 3916/* initialization */
4165 3917
4166static struct video_device *vdev_init(struct bttv *btv, 3918static struct video_device *vdev_init(struct bttv *btv,
4167 const struct video_device *template, 3919 const struct video_device *template,
@@ -4176,10 +3928,17 @@ static struct video_device *vdev_init(struct bttv *btv,
4176 vfd->v4l2_dev = &btv->c.v4l2_dev; 3928 vfd->v4l2_dev = &btv->c.v4l2_dev;
4177 vfd->release = video_device_release; 3929 vfd->release = video_device_release;
4178 vfd->debug = bttv_debug; 3930 vfd->debug = bttv_debug;
3931 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
4179 video_set_drvdata(vfd, btv); 3932 video_set_drvdata(vfd, btv);
4180 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", 3933 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
4181 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", 3934 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4182 type_name, bttv_tvcards[btv->c.type].name); 3935 type_name, bttv_tvcards[btv->c.type].name);
3936 if (btv->tuner_type == TUNER_ABSENT) {
3937 v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
3938 v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY);
3939 v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER);
3940 v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER);
3941 }
4183 return vfd; 3942 return vfd;
4184} 3943}
4185 3944
@@ -4247,6 +4006,7 @@ static int bttv_register_video(struct bttv *btv)
4247 btv->radio_dev = vdev_init(btv, &radio_template, "radio"); 4006 btv->radio_dev = vdev_init(btv, &radio_template, "radio");
4248 if (NULL == btv->radio_dev) 4007 if (NULL == btv->radio_dev)
4249 goto err; 4008 goto err;
4009 btv->radio_dev->ctrl_handler = &btv->radio_ctrl_handler;
4250 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO, 4010 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,
4251 radio_nr[btv->c.nr]) < 0) 4011 radio_nr[btv->c.nr]) < 0)
4252 goto err; 4012 goto err;
@@ -4277,9 +4037,15 @@ static void pci_set_command(struct pci_dev *dev)
4277 4037
4278static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) 4038static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4279{ 4039{
4040 struct v4l2_frequency init_freq = {
4041 .tuner = 0,
4042 .type = V4L2_TUNER_ANALOG_TV,
4043 .frequency = 980,
4044 };
4280 int result; 4045 int result;
4281 unsigned char lat; 4046 unsigned char lat;
4282 struct bttv *btv; 4047 struct bttv *btv;
4048 struct v4l2_ctrl_handler *hdl;
4283 4049
4284 if (bttv_num == BTTV_MAX) 4050 if (bttv_num == BTTV_MAX)
4285 return -ENOMEM; 4051 return -ENOMEM;
@@ -4301,7 +4067,6 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4301 INIT_LIST_HEAD(&btv->c.subs); 4067 INIT_LIST_HEAD(&btv->c.subs);
4302 INIT_LIST_HEAD(&btv->capture); 4068 INIT_LIST_HEAD(&btv->capture);
4303 INIT_LIST_HEAD(&btv->vcapture); 4069 INIT_LIST_HEAD(&btv->vcapture);
4304 v4l2_prio_init(&btv->prio);
4305 4070
4306 init_timer(&btv->timeout); 4071 init_timer(&btv->timeout);
4307 btv->timeout.function = bttv_irq_timeout; 4072 btv->timeout.function = bttv_irq_timeout;
@@ -4339,6 +4104,10 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4339 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr); 4104 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr);
4340 goto fail0; 4105 goto fail0;
4341 } 4106 }
4107 hdl = &btv->ctrl_handler;
4108 v4l2_ctrl_handler_init(hdl, 20);
4109 btv->c.v4l2_dev.ctrl_handler = hdl;
4110 v4l2_ctrl_handler_init(&btv->radio_ctrl_handler, 6);
4342 4111
4343 btv->revision = dev->revision; 4112 btv->revision = dev->revision;
4344 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); 4113 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
@@ -4375,16 +4144,19 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4375 4144
4376 /* init options from insmod args */ 4145 /* init options from insmod args */
4377 btv->opt_combfilter = combfilter; 4146 btv->opt_combfilter = combfilter;
4378 btv->opt_lumafilter = lumafilter; 4147 bttv_ctrl_combfilter.def = combfilter;
4148 bttv_ctrl_lumafilter.def = lumafilter;
4379 btv->opt_automute = automute; 4149 btv->opt_automute = automute;
4380 btv->opt_chroma_agc = chroma_agc; 4150 bttv_ctrl_automute.def = automute;
4381 btv->opt_adc_crush = adc_crush; 4151 bttv_ctrl_agc_crush.def = agc_crush;
4382 btv->opt_vcr_hack = vcr_hack; 4152 btv->opt_vcr_hack = vcr_hack;
4383 btv->opt_whitecrush_upper = whitecrush_upper; 4153 bttv_ctrl_vcr_hack.def = vcr_hack;
4384 btv->opt_whitecrush_lower = whitecrush_lower; 4154 bttv_ctrl_whitecrush_upper.def = whitecrush_upper;
4155 bttv_ctrl_whitecrush_lower.def = whitecrush_lower;
4385 btv->opt_uv_ratio = uv_ratio; 4156 btv->opt_uv_ratio = uv_ratio;
4386 btv->opt_full_luma_range = full_luma_range; 4157 bttv_ctrl_uv_ratio.def = uv_ratio;
4387 btv->opt_coring = coring; 4158 bttv_ctrl_full_luma.def = full_luma_range;
4159 bttv_ctrl_coring.def = coring;
4388 4160
4389 /* fill struct bttv with some useful defaults */ 4161 /* fill struct bttv with some useful defaults */
4390 btv->init.btv = btv; 4162 btv->init.btv = btv;
@@ -4393,8 +4165,39 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4393 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); 4165 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
4394 btv->init.width = 320; 4166 btv->init.width = 320;
4395 btv->init.height = 240; 4167 btv->init.height = 240;
4168 btv->init.ov.w.width = 320;
4169 btv->init.ov.w.height = 240;
4170 btv->init.ov.field = V4L2_FIELD_INTERLACED;
4396 btv->input = 0; 4171 btv->input = 0;
4397 4172
4173 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4174 V4L2_CID_BRIGHTNESS, 0, 0xff00, 0x100, 32768);
4175 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4176 V4L2_CID_CONTRAST, 0, 0xff80, 0x80, 0x6c00);
4177 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4178 V4L2_CID_SATURATION, 0, 0xff80, 0x80, 32768);
4179 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4180 V4L2_CID_COLOR_KILLER, 0, 1, 1, 0);
4181 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4182 V4L2_CID_HUE, 0, 0xff00, 0x100, 32768);
4183 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4184 V4L2_CID_CHROMA_AGC, 0, 1, 1, !!chroma_agc);
4185 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4186 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
4187 if (btv->volume_gpio)
4188 v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops,
4189 V4L2_CID_AUDIO_VOLUME, 0, 0xff00, 0x100, 0xff00);
4190 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_combfilter, NULL);
4191 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_automute, NULL);
4192 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_lumafilter, NULL);
4193 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_agc_crush, NULL);
4194 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_vcr_hack, NULL);
4195 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_whitecrush_lower, NULL);
4196 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_whitecrush_upper, NULL);
4197 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_uv_ratio, NULL);
4198 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_full_luma, NULL);
4199 v4l2_ctrl_new_custom(hdl, &bttv_ctrl_coring, NULL);
4200
4398 /* initialize hardware */ 4201 /* initialize hardware */
4399 if (bttv_gpio) 4202 if (bttv_gpio)
4400 bttv_gpio_tracking(btv,"pre-init"); 4203 bttv_gpio_tracking(btv,"pre-init");
@@ -4417,21 +4220,34 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4417 /* some card-specific stuff (needs working i2c) */ 4220 /* some card-specific stuff (needs working i2c) */
4418 bttv_init_card2(btv); 4221 bttv_init_card2(btv);
4419 bttv_init_tuner(btv); 4222 bttv_init_tuner(btv);
4223 if (btv->tuner_type != TUNER_ABSENT) {
4224 bttv_set_frequency(btv, &init_freq);
4225 btv->radio_freq = 90500 * 16; /* 90.5Mhz default */
4226 }
4227 btv->std = V4L2_STD_PAL;
4420 init_irqreg(btv); 4228 init_irqreg(btv);
4229 v4l2_ctrl_handler_setup(hdl);
4230 if (hdl->error) {
4231 result = hdl->error;
4232 goto fail2;
4233 }
4234 /* mute device */
4235 audio_mute(btv, 1);
4421 4236
4422 /* register video4linux + input */ 4237 /* register video4linux + input */
4423 if (!bttv_tvcards[btv->c.type].no_video) { 4238 if (!bttv_tvcards[btv->c.type].no_video) {
4424 bttv_register_video(btv); 4239 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl,
4425 bt848_bright(btv,32768); 4240 v4l2_ctrl_radio_filter);
4426 bt848_contrast(btv, 27648); 4241 if (btv->radio_ctrl_handler.error) {
4427 bt848_hue(btv,32768); 4242 result = btv->radio_ctrl_handler.error;
4428 bt848_sat(btv,32768); 4243 goto fail2;
4429 audio_mute(btv, 1); 4244 }
4430 set_input(btv, 0, btv->tvnorm); 4245 set_input(btv, 0, btv->tvnorm);
4431 bttv_crop_reset(&btv->crop[0], btv->tvnorm); 4246 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4432 btv->crop[1] = btv->crop[0]; /* current = default */ 4247 btv->crop[1] = btv->crop[0]; /* current = default */
4433 disclaim_vbi_lines(btv); 4248 disclaim_vbi_lines(btv);
4434 disclaim_video_lines(btv); 4249 disclaim_video_lines(btv);
4250 bttv_register_video(btv);
4435 } 4251 }
4436 4252
4437 /* add subdevices and autoload dvb-bt8xx if needed */ 4253 /* add subdevices and autoload dvb-bt8xx if needed */
@@ -4453,6 +4269,8 @@ fail2:
4453 free_irq(btv->c.pci->irq,btv); 4269 free_irq(btv->c.pci->irq,btv);
4454 4270
4455fail1: 4271fail1:
4272 v4l2_ctrl_handler_free(&btv->ctrl_handler);
4273 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler);
4456 v4l2_device_unregister(&btv->c.v4l2_dev); 4274 v4l2_device_unregister(&btv->c.v4l2_dev);
4457 4275
4458fail0: 4276fail0:
@@ -4494,9 +4312,11 @@ static void bttv_remove(struct pci_dev *pci_dev)
4494 bttv_unregister_video(btv); 4312 bttv_unregister_video(btv);
4495 4313
4496 /* free allocated memory */ 4314 /* free allocated memory */
4315 v4l2_ctrl_handler_free(&btv->ctrl_handler);
4316 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler);
4497 btcx_riscmem_free(btv->c.pci,&btv->main); 4317 btcx_riscmem_free(btv->c.pci,&btv->main);
4498 4318
4499 /* free ressources */ 4319 /* free resources */
4500 free_irq(btv->c.pci->irq,btv); 4320 free_irq(btv->c.pci->irq,btv);
4501 iounmap(btv->bt848_mmio); 4321 iounmap(btv->bt848_mmio);
4502 release_mem_region(pci_resource_start(btv->c.pci,0), 4322 release_mem_region(pci_resource_start(btv->c.pci,0),
diff --git a/drivers/media/pci/bt8xx/bttv-i2c.c b/drivers/media/pci/bt8xx/bttv-i2c.c
index c63c643ed1f8..b7c52dc8999c 100644
--- a/drivers/media/pci/bt8xx/bttv-i2c.c
+++ b/drivers/media/pci/bt8xx/bttv-i2c.c
@@ -394,3 +394,11 @@ int init_bttv_i2c(struct bttv *btv)
394 394
395 return btv->i2c_rc; 395 return btv->i2c_rc;
396} 396}
397
398int fini_bttv_i2c(struct bttv *btv)
399{
400 if (0 != btv->i2c_rc)
401 return 0;
402
403 return i2c_del_adapter(&btv->c.i2c_adap);
404}
diff --git a/drivers/media/pci/bt8xx/bttv-input.c b/drivers/media/pci/bt8xx/bttv-input.c
index 04207a799055..f36821367d8d 100644
--- a/drivers/media/pci/bt8xx/bttv-input.c
+++ b/drivers/media/pci/bt8xx/bttv-input.c
@@ -375,6 +375,7 @@ void init_bttv_i2c_ir(struct bttv *btv)
375 I2C_CLIENT_END 375 I2C_CLIENT_END
376 }; 376 };
377 struct i2c_board_info info; 377 struct i2c_board_info info;
378 struct i2c_client *i2c_dev;
378 379
379 if (0 != btv->i2c_rc) 380 if (0 != btv->i2c_rc)
380 return; 381 return;
@@ -390,7 +391,12 @@ void init_bttv_i2c_ir(struct bttv *btv)
390 btv->init_data.ir_codes = RC_MAP_PV951; 391 btv->init_data.ir_codes = RC_MAP_PV951;
391 info.addr = 0x4b; 392 info.addr = 0x4b;
392 break; 393 break;
393 default: 394 }
395
396 if (btv->init_data.name) {
397 info.platform_data = &btv->init_data;
398 i2c_dev = i2c_new_device(&btv->c.i2c_adap, &info);
399 } else {
394 /* 400 /*
395 * The external IR receiver is at i2c address 0x34 (0x35 for 401 * The external IR receiver is at i2c address 0x34 (0x35 for
396 * reads). Future Hauppauge cards will have an internal 402 * reads). Future Hauppauge cards will have an internal
@@ -399,24 +405,14 @@ void init_bttv_i2c_ir(struct bttv *btv)
399 * internal. 405 * internal.
400 * That's why we probe 0x1a (~0x34) first. CB 406 * That's why we probe 0x1a (~0x34) first. CB
401 */ 407 */
402 408 i2c_dev = i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
403 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
404 return;
405 } 409 }
410 if (NULL == i2c_dev)
411 return;
406 412
407 if (btv->init_data.name) 413#if defined(CONFIG_MODULES) && defined(MODULE)
408 info.platform_data = &btv->init_data; 414 request_module("ir-kbd-i2c");
409 i2c_new_device(&btv->c.i2c_adap, &info); 415#endif
410
411 return;
412}
413
414int fini_bttv_i2c(struct bttv *btv)
415{
416 if (0 != btv->i2c_rc)
417 return 0;
418
419 return i2c_del_adapter(&btv->c.i2c_adap);
420} 416}
421 417
422int bttv_input_init(struct bttv *btv) 418int bttv_input_init(struct bttv *btv)
diff --git a/drivers/media/pci/bt8xx/bttv.h b/drivers/media/pci/bt8xx/bttv.h
index 79a11240a590..6139ce26dc2c 100644
--- a/drivers/media/pci/bt8xx/bttv.h
+++ b/drivers/media/pci/bt8xx/bttv.h
@@ -359,6 +359,9 @@ void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits);
359#define bttv_call_all(btv, o, f, args...) \ 359#define bttv_call_all(btv, o, f, args...) \
360 v4l2_device_call_all(&btv->c.v4l2_dev, 0, o, f, ##args) 360 v4l2_device_call_all(&btv->c.v4l2_dev, 0, o, f, ##args)
361 361
362#define bttv_call_all_err(btv, o, f, args...) \
363 v4l2_device_call_until_err(&btv->c.v4l2_dev, 0, o, f, ##args)
364
362extern int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for); 365extern int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for);
363extern int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1, 366extern int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
364 unsigned char b2, int both); 367 unsigned char b2, int both);
diff --git a/drivers/media/pci/bt8xx/bttvp.h b/drivers/media/pci/bt8xx/bttvp.h
index 9ec0adba236c..9c1cc2c50ee2 100644
--- a/drivers/media/pci/bt8xx/bttvp.h
+++ b/drivers/media/pci/bt8xx/bttvp.h
@@ -33,9 +33,11 @@
33#include <linux/input.h> 33#include <linux/input.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/scatterlist.h> 35#include <linux/scatterlist.h>
36#include <linux/device.h>
36#include <asm/io.h> 37#include <asm/io.h>
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
38#include <linux/device.h> 39#include <media/v4l2-ctrls.h>
40#include <media/v4l2-fh.h>
39#include <media/videobuf-dma-sg.h> 41#include <media/videobuf-dma-sg.h>
40#include <media/tveeprom.h> 42#include <media/tveeprom.h>
41#include <media/rc-core.h> 43#include <media/rc-core.h>
@@ -214,11 +216,11 @@ struct bttv_crop {
214}; 216};
215 217
216struct bttv_fh { 218struct bttv_fh {
219 /* This must be the first field in this struct */
220 struct v4l2_fh fh;
221
217 struct bttv *btv; 222 struct bttv *btv;
218 int resources; 223 int resources;
219#ifdef VIDIOC_G_PRIORITY
220 enum v4l2_priority prio;
221#endif
222 enum v4l2_buf_type type; 224 enum v4l2_buf_type type;
223 225
224 /* video capture */ 226 /* video capture */
@@ -298,6 +300,10 @@ extern int no_overlay;
298/* bttv-input.c */ 300/* bttv-input.c */
299 301
300extern void init_bttv_i2c_ir(struct bttv *btv); 302extern void init_bttv_i2c_ir(struct bttv *btv);
303
304/* ---------------------------------------------------------- */
305/* bttv-i2c.c */
306extern int init_bttv_i2c(struct bttv *btv);
301extern int fini_bttv_i2c(struct bttv *btv); 307extern int fini_bttv_i2c(struct bttv *btv);
302 308
303/* ---------------------------------------------------------- */ 309/* ---------------------------------------------------------- */
@@ -308,7 +314,6 @@ extern unsigned int bttv_verbose;
308extern unsigned int bttv_debug; 314extern unsigned int bttv_debug;
309extern unsigned int bttv_gpio; 315extern unsigned int bttv_gpio;
310extern void bttv_gpio_tracking(struct bttv *btv, char *comment); 316extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
311extern int init_bttv_i2c(struct bttv *btv);
312 317
313#define dprintk(fmt, ...) \ 318#define dprintk(fmt, ...) \
314do { \ 319do { \
@@ -393,12 +398,17 @@ struct bttv {
393 wait_queue_head_t i2c_queue; 398 wait_queue_head_t i2c_queue;
394 struct v4l2_subdev *sd_msp34xx; 399 struct v4l2_subdev *sd_msp34xx;
395 struct v4l2_subdev *sd_tvaudio; 400 struct v4l2_subdev *sd_tvaudio;
401 struct v4l2_subdev *sd_tda7432;
396 402
397 /* video4linux (1) */ 403 /* video4linux (1) */
398 struct video_device *video_dev; 404 struct video_device *video_dev;
399 struct video_device *radio_dev; 405 struct video_device *radio_dev;
400 struct video_device *vbi_dev; 406 struct video_device *vbi_dev;
401 407
408 /* controls */
409 struct v4l2_ctrl_handler ctrl_handler;
410 struct v4l2_ctrl_handler radio_ctrl_handler;
411
402 /* infrared remote */ 412 /* infrared remote */
403 int has_remote; 413 int has_remote;
404 struct bttv_ir *remote; 414 struct bttv_ir *remote;
@@ -410,38 +420,30 @@ struct bttv {
410 spinlock_t s_lock; 420 spinlock_t s_lock;
411 struct mutex lock; 421 struct mutex lock;
412 int resources; 422 int resources;
413#ifdef VIDIOC_G_PRIORITY
414 struct v4l2_prio_state prio;
415#endif
416 423
417 /* video state */ 424 /* video state */
418 unsigned int input; 425 unsigned int input;
419 unsigned int audio; 426 unsigned int audio_input;
420 unsigned int mute; 427 unsigned int mute;
421 unsigned long freq; 428 unsigned long tv_freq;
422 unsigned int tvnorm; 429 unsigned int tvnorm;
430 v4l2_std_id std;
423 int hue, contrast, bright, saturation; 431 int hue, contrast, bright, saturation;
424 struct v4l2_framebuffer fbuf; 432 struct v4l2_framebuffer fbuf;
425 unsigned int field_count; 433 unsigned int field_count;
426 434
427 /* various options */ 435 /* various options */
428 int opt_combfilter; 436 int opt_combfilter;
429 int opt_lumafilter;
430 int opt_automute; 437 int opt_automute;
431 int opt_chroma_agc;
432 int opt_color_killer;
433 int opt_adc_crush;
434 int opt_vcr_hack; 438 int opt_vcr_hack;
435 int opt_whitecrush_upper;
436 int opt_whitecrush_lower;
437 int opt_uv_ratio; 439 int opt_uv_ratio;
438 int opt_full_luma_range;
439 int opt_coring;
440 440
441 /* radio data/state */ 441 /* radio data/state */
442 int has_radio; 442 int has_radio;
443 int has_radio_tuner;
443 int radio_user; 444 int radio_user;
444 int radio_uses_msp_demodulator; 445 int radio_uses_msp_demodulator;
446 unsigned long radio_freq;
445 447
446 /* miro/pinnacle + Aimslab VHX 448 /* miro/pinnacle + Aimslab VHX
447 philips matchbox (tea5757 radio tuner) support */ 449 philips matchbox (tea5757 radio tuner) support */
diff --git a/drivers/media/pci/cx18/cx18-av-core.c b/drivers/media/pci/cx18/cx18-av-core.c
index f164b7f610a5..38b1d64ffc27 100644
--- a/drivers/media/pci/cx18/cx18-av-core.c
+++ b/drivers/media/pci/cx18/cx18-av-core.c
@@ -576,7 +576,7 @@ static void input_change(struct cx18 *cx)
576} 576}
577 577
578static int cx18_av_s_frequency(struct v4l2_subdev *sd, 578static int cx18_av_s_frequency(struct v4l2_subdev *sd,
579 struct v4l2_frequency *freq) 579 const struct v4l2_frequency *freq)
580{ 580{
581 struct cx18 *cx = v4l2_get_subdevdata(sd); 581 struct cx18 *cx = v4l2_get_subdevdata(sd);
582 input_change(cx); 582 input_change(cx);
@@ -809,7 +809,7 @@ static int cx18_av_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
809 return 0; 809 return 0;
810} 810}
811 811
812static int cx18_av_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 812static int cx18_av_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
813{ 813{
814 struct cx18_av_state *state = to_cx18_av_state(sd); 814 struct cx18_av_state *state = to_cx18_av_state(sd);
815 struct cx18 *cx = v4l2_get_subdevdata(sd); 815 struct cx18 *cx = v4l2_get_subdevdata(sd);
@@ -1266,7 +1266,7 @@ static int cx18_av_g_register(struct v4l2_subdev *sd,
1266} 1266}
1267 1267
1268static int cx18_av_s_register(struct v4l2_subdev *sd, 1268static int cx18_av_s_register(struct v4l2_subdev *sd,
1269 struct v4l2_dbg_register *reg) 1269 const struct v4l2_dbg_register *reg)
1270{ 1270{
1271 struct cx18 *cx = v4l2_get_subdevdata(sd); 1271 struct cx18 *cx = v4l2_get_subdevdata(sd);
1272 1272
diff --git a/drivers/media/pci/cx18/cx18-driver.c b/drivers/media/pci/cx18/cx18-driver.c
index 613e5ae7d5ca..67b61cf3e03a 100644
--- a/drivers/media/pci/cx18/cx18-driver.c
+++ b/drivers/media/pci/cx18/cx18-driver.c
@@ -1243,7 +1243,7 @@ int cx18_init_on_first_open(struct cx18 *cx)
1243 in one place. */ 1243 in one place. */
1244 cx->std++; /* Force full standard initialization */ 1244 cx->std++; /* Force full standard initialization */
1245 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std; 1245 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std;
1246 cx18_s_std(NULL, &fh, &std); 1246 cx18_s_std(NULL, &fh, std);
1247 cx18_s_frequency(NULL, &fh, &vf); 1247 cx18_s_frequency(NULL, &fh, &vf);
1248 return 0; 1248 return 0;
1249} 1249}
diff --git a/drivers/media/pci/cx18/cx18-ioctl.c b/drivers/media/pci/cx18/cx18-ioctl.c
index cd8d2c2b1624..aee7b6dacbfe 100644
--- a/drivers/media/pci/cx18/cx18-ioctl.c
+++ b/drivers/media/pci/cx18/cx18-ioctl.c
@@ -415,42 +415,34 @@ static int cx18_g_chip_ident(struct file *file, void *fh,
415} 415}
416 416
417#ifdef CONFIG_VIDEO_ADV_DEBUG 417#ifdef CONFIG_VIDEO_ADV_DEBUG
418static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
419{
420 struct v4l2_dbg_register *regs = arg;
421
422 if (!capable(CAP_SYS_ADMIN))
423 return -EPERM;
424 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
425 return -EINVAL;
426
427 regs->size = 4;
428 if (cmd == VIDIOC_DBG_S_REGISTER)
429 cx18_write_enc(cx, regs->val, regs->reg);
430 else
431 regs->val = cx18_read_enc(cx, regs->reg);
432 return 0;
433}
434
435static int cx18_g_register(struct file *file, void *fh, 418static int cx18_g_register(struct file *file, void *fh,
436 struct v4l2_dbg_register *reg) 419 struct v4l2_dbg_register *reg)
437{ 420{
438 struct cx18 *cx = fh2id(fh)->cx; 421 struct cx18 *cx = fh2id(fh)->cx;
439 422
440 if (v4l2_chip_match_host(&reg->match)) 423 if (v4l2_chip_match_host(&reg->match)) {
441 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg); 424 if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
425 return -EINVAL;
426 reg->size = 4;
427 reg->val = cx18_read_enc(cx, reg->reg);
428 return 0;
429 }
442 /* FIXME - errors shouldn't be ignored */ 430 /* FIXME - errors shouldn't be ignored */
443 cx18_call_all(cx, core, g_register, reg); 431 cx18_call_all(cx, core, g_register, reg);
444 return 0; 432 return 0;
445} 433}
446 434
447static int cx18_s_register(struct file *file, void *fh, 435static int cx18_s_register(struct file *file, void *fh,
448 struct v4l2_dbg_register *reg) 436 const struct v4l2_dbg_register *reg)
449{ 437{
450 struct cx18 *cx = fh2id(fh)->cx; 438 struct cx18 *cx = fh2id(fh)->cx;
451 439
452 if (v4l2_chip_match_host(&reg->match)) 440 if (v4l2_chip_match_host(&reg->match)) {
453 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg); 441 if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
442 return -EINVAL;
443 cx18_write_enc(cx, reg->val, reg->reg);
444 return 0;
445 }
454 /* FIXME - errors shouldn't be ignored */ 446 /* FIXME - errors shouldn't be ignored */
455 cx18_call_all(cx, core, s_register, reg); 447 cx18_call_all(cx, core, s_register, reg);
456 return 0; 448 return 0;
@@ -614,7 +606,7 @@ static int cx18_g_frequency(struct file *file, void *fh,
614 return 0; 606 return 0;
615} 607}
616 608
617int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf) 609int cx18_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf)
618{ 610{
619 struct cx18_open_id *id = fh2id(fh); 611 struct cx18_open_id *id = fh2id(fh);
620 struct cx18 *cx = id->cx; 612 struct cx18 *cx = id->cx;
@@ -637,15 +629,15 @@ static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
637 return 0; 629 return 0;
638} 630}
639 631
640int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std) 632int cx18_s_std(struct file *file, void *fh, v4l2_std_id std)
641{ 633{
642 struct cx18_open_id *id = fh2id(fh); 634 struct cx18_open_id *id = fh2id(fh);
643 struct cx18 *cx = id->cx; 635 struct cx18 *cx = id->cx;
644 636
645 if ((*std & V4L2_STD_ALL) == 0) 637 if ((std & V4L2_STD_ALL) == 0)
646 return -EINVAL; 638 return -EINVAL;
647 639
648 if (*std == cx->std) 640 if (std == cx->std)
649 return 0; 641 return 0;
650 642
651 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) || 643 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
@@ -656,8 +648,8 @@ int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
656 return -EBUSY; 648 return -EBUSY;
657 } 649 }
658 650
659 cx->std = *std; 651 cx->std = std;
660 cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; 652 cx->is_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
661 cx->is_50hz = !cx->is_60hz; 653 cx->is_50hz = !cx->is_60hz;
662 cx2341x_handler_set_50hz(&cx->cxhdl, cx->is_50hz); 654 cx2341x_handler_set_50hz(&cx->cxhdl, cx->is_50hz);
663 cx->cxhdl.width = 720; 655 cx->cxhdl.width = 720;
@@ -673,7 +665,7 @@ int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
673 return 0; 665 return 0;
674} 666}
675 667
676static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) 668static int cx18_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
677{ 669{
678 struct cx18_open_id *id = fh2id(fh); 670 struct cx18_open_id *id = fh2id(fh);
679 struct cx18 *cx = id->cx; 671 struct cx18 *cx = id->cx;
@@ -1118,7 +1110,7 @@ static int cx18_log_status(struct file *file, void *fh)
1118} 1110}
1119 1111
1120static long cx18_default(struct file *file, void *fh, bool valid_prio, 1112static long cx18_default(struct file *file, void *fh, bool valid_prio,
1121 int cmd, void *arg) 1113 unsigned int cmd, void *arg)
1122{ 1114{
1123 struct cx18 *cx = fh2id(fh)->cx; 1115 struct cx18 *cx = fh2id(fh)->cx;
1124 1116
diff --git a/drivers/media/pci/cx18/cx18-ioctl.h b/drivers/media/pci/cx18/cx18-ioctl.h
index 2f9dd591ee0f..43433969d633 100644
--- a/drivers/media/pci/cx18/cx18-ioctl.h
+++ b/drivers/media/pci/cx18/cx18-ioctl.h
@@ -26,6 +26,6 @@ u16 cx18_service2vbi(int type);
26void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal); 26void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal);
27u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt); 27u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt);
28void cx18_set_funcs(struct video_device *vdev); 28void cx18_set_funcs(struct video_device *vdev);
29int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std); 29int cx18_s_std(struct file *file, void *fh, v4l2_std_id std);
30int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf); 30int cx18_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf);
31int cx18_s_input(struct file *file, void *fh, unsigned int inp); 31int cx18_s_input(struct file *file, void *fh, unsigned int inp);
diff --git a/drivers/media/pci/cx23885/altera-ci.h b/drivers/media/pci/cx23885/altera-ci.h
index 70e4fd69ad9e..4998c96caebe 100644
--- a/drivers/media/pci/cx23885/altera-ci.h
+++ b/drivers/media/pci/cx23885/altera-ci.h
@@ -24,6 +24,8 @@
24#ifndef __ALTERA_CI_H 24#ifndef __ALTERA_CI_H
25#define __ALTERA_CI_H 25#define __ALTERA_CI_H
26 26
27#include <linux/kconfig.h>
28
27#define ALT_DATA 0x000000ff 29#define ALT_DATA 0x000000ff
28#define ALT_TDI 0x00008000 30#define ALT_TDI 0x00008000
29#define ALT_TDO 0x00004000 31#define ALT_TDO 0x00004000
@@ -41,8 +43,7 @@ struct altera_ci_config {
41 int (*fpga_rw) (void *dev, int ad_rg, int val, int rw); 43 int (*fpga_rw) (void *dev, int ad_rg, int val, int rw);
42}; 44};
43 45
44#if defined(CONFIG_MEDIA_ALTERA_CI) || (defined(CONFIG_MEDIA_ALTERA_CI_MODULE) \ 46#if IS_ENABLED(CONFIG_MEDIA_ALTERA_CI)
45 && defined(MODULE))
46 47
47extern int altera_ci_init(struct altera_ci_config *config, int ci_nr); 48extern int altera_ci_init(struct altera_ci_config *config, int ci_nr);
48extern void altera_ci_release(void *dev, int ci_nr); 49extern void altera_ci_release(void *dev, int ci_nr);
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c
index 5d5052d0253f..6dea11a7a858 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1222,14 +1222,14 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1222 return 0; 1222 return 0;
1223} 1223}
1224 1224
1225static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 1225static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
1226{ 1226{
1227 struct cx23885_fh *fh = file->private_data; 1227 struct cx23885_fh *fh = file->private_data;
1228 struct cx23885_dev *dev = fh->dev; 1228 struct cx23885_dev *dev = fh->dev;
1229 unsigned int i; 1229 unsigned int i;
1230 1230
1231 for (i = 0; i < ARRAY_SIZE(cx23885_tvnorms); i++) 1231 for (i = 0; i < ARRAY_SIZE(cx23885_tvnorms); i++)
1232 if (*id & cx23885_tvnorms[i].id) 1232 if (id & cx23885_tvnorms[i].id)
1233 break; 1233 break;
1234 if (i == ARRAY_SIZE(cx23885_tvnorms)) 1234 if (i == ARRAY_SIZE(cx23885_tvnorms))
1235 return -EINVAL; 1235 return -EINVAL;
@@ -1237,7 +1237,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
1237 1237
1238 /* Have the drier core notify the subdevices */ 1238 /* Have the drier core notify the subdevices */
1239 mutex_lock(&dev->lock); 1239 mutex_lock(&dev->lock);
1240 cx23885_set_tvnorm(dev, *id); 1240 cx23885_set_tvnorm(dev, id);
1241 mutex_unlock(&dev->lock); 1241 mutex_unlock(&dev->lock);
1242 1242
1243 return 0; 1243 return 0;
@@ -1280,7 +1280,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1280} 1280}
1281 1281
1282static int vidioc_s_tuner(struct file *file, void *priv, 1282static int vidioc_s_tuner(struct file *file, void *priv,
1283 struct v4l2_tuner *t) 1283 const struct v4l2_tuner *t)
1284{ 1284{
1285 struct cx23885_fh *fh = file->private_data; 1285 struct cx23885_fh *fh = file->private_data;
1286 struct cx23885_dev *dev = fh->dev; 1286 struct cx23885_dev *dev = fh->dev;
@@ -1311,7 +1311,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1311} 1311}
1312 1312
1313static int vidioc_s_frequency(struct file *file, void *priv, 1313static int vidioc_s_frequency(struct file *file, void *priv,
1314 struct v4l2_frequency *f) 1314 const struct v4l2_frequency *f)
1315{ 1315{
1316 return cx23885_set_frequency(file, priv, f); 1316 return cx23885_set_frequency(file, priv, f);
1317} 1317}
diff --git a/drivers/media/pci/cx23885/cx23885-ioctl.c b/drivers/media/pci/cx23885/cx23885-ioctl.c
index ea9a614f3bbf..acdb6d58db58 100644
--- a/drivers/media/pci/cx23885/cx23885-ioctl.c
+++ b/drivers/media/pci/cx23885/cx23885-ioctl.c
@@ -158,18 +158,17 @@ int cx23885_g_register(struct file *file, void *fh,
158} 158}
159 159
160static int cx23885_s_host_register(struct cx23885_dev *dev, 160static int cx23885_s_host_register(struct cx23885_dev *dev,
161 struct v4l2_dbg_register *reg) 161 const struct v4l2_dbg_register *reg)
162{ 162{
163 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0)) 163 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
164 return -EINVAL; 164 return -EINVAL;
165 165
166 reg->size = 4;
167 cx_write(reg->reg, reg->val); 166 cx_write(reg->reg, reg->val);
168 return 0; 167 return 0;
169} 168}
170 169
171static int cx23417_s_register(struct cx23885_dev *dev, 170static int cx23417_s_register(struct cx23885_dev *dev,
172 struct v4l2_dbg_register *reg) 171 const struct v4l2_dbg_register *reg)
173{ 172{
174 if (dev->v4l_device == NULL) 173 if (dev->v4l_device == NULL)
175 return -EINVAL; 174 return -EINVAL;
@@ -179,13 +178,11 @@ static int cx23417_s_register(struct cx23885_dev *dev,
179 178
180 if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val)) 179 if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
181 return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */ 180 return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
182
183 reg->size = 4;
184 return 0; 181 return 0;
185} 182}
186 183
187int cx23885_s_register(struct file *file, void *fh, 184int cx23885_s_register(struct file *file, void *fh,
188 struct v4l2_dbg_register *reg) 185 const struct v4l2_dbg_register *reg)
189{ 186{
190 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; 187 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
191 188
diff --git a/drivers/media/pci/cx23885/cx23885-ioctl.h b/drivers/media/pci/cx23885/cx23885-ioctl.h
index 315be0ca5a04..a6080964a9ee 100644
--- a/drivers/media/pci/cx23885/cx23885-ioctl.h
+++ b/drivers/media/pci/cx23885/cx23885-ioctl.h
@@ -33,7 +33,7 @@ int cx23885_g_register(struct file *file, void *fh,
33 33
34 34
35int cx23885_s_register(struct file *file, void *fh, 35int cx23885_s_register(struct file *file, void *fh,
36 struct v4l2_dbg_register *reg); 36 const struct v4l2_dbg_register *reg);
37 37
38#endif 38#endif
39#endif 39#endif
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index 5991bc8dc158..ed08c89adde0 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -1259,13 +1259,13 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1259 return 0; 1259 return 0;
1260} 1260}
1261 1261
1262static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms) 1262static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id tvnorms)
1263{ 1263{
1264 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1264 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1265 dprintk(1, "%s()\n", __func__); 1265 dprintk(1, "%s()\n", __func__);
1266 1266
1267 mutex_lock(&dev->lock); 1267 mutex_lock(&dev->lock);
1268 cx23885_set_tvnorm(dev, *tvnorms); 1268 cx23885_set_tvnorm(dev, tvnorms);
1269 mutex_unlock(&dev->lock); 1269 mutex_unlock(&dev->lock);
1270 1270
1271 return 0; 1271 return 0;
@@ -1486,7 +1486,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1486} 1486}
1487 1487
1488static int vidioc_s_tuner(struct file *file, void *priv, 1488static int vidioc_s_tuner(struct file *file, void *priv,
1489 struct v4l2_tuner *t) 1489 const struct v4l2_tuner *t)
1490{ 1490{
1491 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1491 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1492 1492
@@ -1518,7 +1518,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1518 return 0; 1518 return 0;
1519} 1519}
1520 1520
1521static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f) 1521static int cx23885_set_freq(struct cx23885_dev *dev, const struct v4l2_frequency *f)
1522{ 1522{
1523 struct v4l2_control ctrl; 1523 struct v4l2_control ctrl;
1524 1524
@@ -1550,7 +1550,7 @@ static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1550} 1550}
1551 1551
1552static int cx23885_set_freq_via_ops(struct cx23885_dev *dev, 1552static int cx23885_set_freq_via_ops(struct cx23885_dev *dev,
1553 struct v4l2_frequency *f) 1553 const struct v4l2_frequency *f)
1554{ 1554{
1555 struct v4l2_control ctrl; 1555 struct v4l2_control ctrl;
1556 struct videobuf_dvb_frontend *vfe; 1556 struct videobuf_dvb_frontend *vfe;
@@ -1608,7 +1608,7 @@ static int cx23885_set_freq_via_ops(struct cx23885_dev *dev,
1608} 1608}
1609 1609
1610int cx23885_set_frequency(struct file *file, void *priv, 1610int cx23885_set_frequency(struct file *file, void *priv,
1611 struct v4l2_frequency *f) 1611 const struct v4l2_frequency *f)
1612{ 1612{
1613 struct cx23885_fh *fh = priv; 1613 struct cx23885_fh *fh = priv;
1614 struct cx23885_dev *dev = fh->dev; 1614 struct cx23885_dev *dev = fh->dev;
@@ -1628,7 +1628,7 @@ int cx23885_set_frequency(struct file *file, void *priv,
1628} 1628}
1629 1629
1630static int vidioc_s_frequency(struct file *file, void *priv, 1630static int vidioc_s_frequency(struct file *file, void *priv,
1631 struct v4l2_frequency *f) 1631 const struct v4l2_frequency *f)
1632{ 1632{
1633 return cx23885_set_frequency(file, priv, f); 1633 return cx23885_set_frequency(file, priv, f);
1634} 1634}
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index 59c322d870f2..5687d3f678db 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -587,7 +587,7 @@ extern void cx23885_video_wakeup(struct cx23885_dev *dev,
587int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i); 587int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i);
588int cx23885_set_input(struct file *file, void *priv, unsigned int i); 588int cx23885_set_input(struct file *file, void *priv, unsigned int i);
589int cx23885_get_input(struct file *file, void *priv, unsigned int *i); 589int cx23885_get_input(struct file *file, void *priv, unsigned int *i);
590int cx23885_set_frequency(struct file *file, void *priv, struct v4l2_frequency *f); 590int cx23885_set_frequency(struct file *file, void *priv, const struct v4l2_frequency *f);
591int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl); 591int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl);
592int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl); 592int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl);
593int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm); 593int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm);
diff --git a/drivers/media/pci/cx23885/cx23888-ir.c b/drivers/media/pci/cx23885/cx23888-ir.c
index d51eed051d59..fa672fe41079 100644
--- a/drivers/media/pci/cx23885/cx23888-ir.c
+++ b/drivers/media/pci/cx23885/cx23888-ir.c
@@ -1124,7 +1124,7 @@ static int cx23888_ir_g_register(struct v4l2_subdev *sd,
1124} 1124}
1125 1125
1126static int cx23888_ir_s_register(struct v4l2_subdev *sd, 1126static int cx23888_ir_s_register(struct v4l2_subdev *sd,
1127 struct v4l2_dbg_register *reg) 1127 const struct v4l2_dbg_register *reg)
1128{ 1128{
1129 struct cx23888_ir_state *state = to_state(sd); 1129 struct cx23888_ir_state *state = to_state(sd);
1130 u32 addr = CX23888_IR_REG_BASE + (u32) reg->reg; 1130 u32 addr = CX23888_IR_REG_BASE + (u32) reg->reg;
diff --git a/drivers/media/pci/cx25821/Kconfig b/drivers/media/pci/cx25821/Kconfig
index 4017c9420348..6439a847680c 100644
--- a/drivers/media/pci/cx25821/Kconfig
+++ b/drivers/media/pci/cx25821/Kconfig
@@ -1,14 +1,9 @@
1config VIDEO_CX25821 1config VIDEO_CX25821
2 tristate "Conexant cx25821 support" 2 tristate "Conexant cx25821 support"
3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C 3 depends on VIDEO_DEV && PCI && I2C
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEO_TVEEPROM
7 depends on RC_CORE
8 select VIDEOBUF_DVB
9 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
10 select VIDEO_CX25840
11 select VIDEO_CX2341X
12 ---help--- 7 ---help---
13 This is a video4linux driver for Conexant 25821 based 8 This is a video4linux driver for Conexant 25821 based
14 TV cards. 9 TV cards.
diff --git a/drivers/media/pci/cx25821/Makefile b/drivers/media/pci/cx25821/Makefile
index caa32b7b51f8..fb76c3d3713a 100644
--- a/drivers/media/pci/cx25821/Makefile
+++ b/drivers/media/pci/cx25821/Makefile
@@ -1,14 +1,9 @@
1cx25821-y := cx25821-core.o cx25821-cards.o cx25821-i2c.o \ 1cx25821-y := cx25821-core.o cx25821-cards.o cx25821-i2c.o \
2 cx25821-gpio.o cx25821-medusa-video.o \ 2 cx25821-gpio.o cx25821-medusa-video.o \
3 cx25821-video.o cx25821-video-upstream.o \ 3 cx25821-video.o cx25821-video-upstream.o
4 cx25821-video-upstream-ch2.o \
5 cx25821-audio-upstream.o
6 4
7obj-$(CONFIG_VIDEO_CX25821) += cx25821.o 5obj-$(CONFIG_VIDEO_CX25821) += cx25821.o
8obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o 6obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o
9 7
10ccflags-y += -Idrivers/media/i2c 8ccflags-y += -Idrivers/media/i2c
11ccflags-y += -Idrivers/media/common 9ccflags-y += -Idrivers/media/common
12ccflags-y += -Idrivers/media/tuners
13ccflags-y += -Idrivers/media/dvb-core
14ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/pci/cx25821/cx25821-alsa.c b/drivers/media/pci/cx25821/cx25821-alsa.c
index 1858a45dd081..6e91e84d6bf9 100644
--- a/drivers/media/pci/cx25821/cx25821-alsa.c
+++ b/drivers/media/pci/cx25821/cx25821-alsa.c
@@ -59,7 +59,6 @@ do { \
59 Data type declarations - Can be moded to a header file later 59 Data type declarations - Can be moded to a header file later
60 ****************************************************************************/ 60 ****************************************************************************/
61 61
62static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
63static int devno; 62static int devno;
64 63
65struct cx25821_audio_buffer { 64struct cx25821_audio_buffer {
@@ -151,7 +150,7 @@ static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip)
151{ 150{
152 struct cx25821_audio_buffer *buf = chip->buf; 151 struct cx25821_audio_buffer *buf = chip->buf;
153 struct cx25821_dev *dev = chip->dev; 152 struct cx25821_dev *dev = chip->dev;
154 struct sram_channel *audio_ch = 153 const struct sram_channel *audio_ch =
155 &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]; 154 &cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
156 u32 tmp = 0; 155 u32 tmp = 0;
157 156
@@ -627,34 +626,6 @@ static DEFINE_PCI_DEVICE_TABLE(cx25821_audio_pci_tbl) = {
627MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl); 626MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
628 627
629/* 628/*
630 * Not used in the function snd_cx25821_dev_free so removing
631 * from the file.
632 */
633/*
634static int snd_cx25821_free(struct cx25821_audio_dev *chip)
635{
636 if (chip->irq >= 0)
637 free_irq(chip->irq, chip);
638
639 cx25821_dev_unregister(chip->dev);
640 pci_disable_device(chip->pci);
641
642 return 0;
643}
644*/
645
646/*
647 * Component Destructor
648 */
649static void snd_cx25821_dev_free(struct snd_card *card)
650{
651 struct cx25821_audio_dev *chip = card->private_data;
652
653 /* snd_cx25821_free(chip); */
654 snd_card_free(chip->card);
655}
656
657/*
658 * Alsa Constructor - Component probe 629 * Alsa Constructor - Component probe
659 */ 630 */
660static int cx25821_audio_initdev(struct cx25821_dev *dev) 631static int cx25821_audio_initdev(struct cx25821_dev *dev)
@@ -685,7 +656,6 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
685 strcpy(card->driver, "cx25821"); 656 strcpy(card->driver, "cx25821");
686 657
687 /* Card "creation" */ 658 /* Card "creation" */
688 card->private_free = snd_cx25821_dev_free;
689 chip = card->private_data; 659 chip = card->private_data;
690 spin_lock_init(&chip->reg_lock); 660 spin_lock_init(&chip->reg_lock);
691 661
@@ -729,8 +699,7 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
729 goto error; 699 goto error;
730 } 700 }
731 701
732 snd_cx25821_cards[devno] = card; 702 dev->card = card;
733
734 devno++; 703 devno++;
735 return 0; 704 return 0;
736 705
@@ -742,9 +711,33 @@ error:
742/**************************************************************************** 711/****************************************************************************
743 LINUX MODULE INIT 712 LINUX MODULE INIT
744 ****************************************************************************/ 713 ****************************************************************************/
714
715static int cx25821_alsa_exit_callback(struct device *dev, void *data)
716{
717 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
718 struct cx25821_dev *cxdev = get_cx25821(v4l2_dev);
719
720 snd_card_free(cxdev->card);
721 return 0;
722}
723
745static void cx25821_audio_fini(void) 724static void cx25821_audio_fini(void)
746{ 725{
747 snd_card_free(snd_cx25821_cards[0]); 726 struct device_driver *drv = driver_find("cx25821", &pci_bus_type);
727 int ret;
728
729 ret = driver_for_each_device(drv, NULL, NULL, cx25821_alsa_exit_callback);
730 if (ret)
731 pr_err("%s failed to find a cx25821 driver.\n", __func__);
732}
733
734static int cx25821_alsa_init_callback(struct device *dev, void *data)
735{
736 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
737 struct cx25821_dev *cxdev = get_cx25821(v4l2_dev);
738
739 cx25821_audio_initdev(cxdev);
740 return 0;
748} 741}
749 742
750/* 743/*
@@ -756,29 +749,11 @@ static void cx25821_audio_fini(void)
756 */ 749 */
757static int cx25821_alsa_init(void) 750static int cx25821_alsa_init(void)
758{ 751{
759 struct cx25821_dev *dev = NULL; 752 struct device_driver *drv = driver_find("cx25821", &pci_bus_type);
760 struct list_head *list;
761 753
762 mutex_lock(&cx25821_devlist_mutex); 754 return driver_for_each_device(drv, NULL, NULL, cx25821_alsa_init_callback);
763 list_for_each(list, &cx25821_devlist) {
764 dev = list_entry(list, struct cx25821_dev, devlist);
765 cx25821_audio_initdev(dev);
766 }
767 mutex_unlock(&cx25821_devlist_mutex);
768
769 if (dev == NULL)
770 pr_info("ERROR ALSA: no cx25821 cards found\n");
771
772 return 0;
773 755
774} 756}
775 757
776late_initcall(cx25821_alsa_init); 758late_initcall(cx25821_alsa_init);
777module_exit(cx25821_audio_fini); 759module_exit(cx25821_audio_fini);
778
779/* ----------------------------------------------------------- */
780/*
781 * Local variables:
782 * c-basic-offset: 8
783 * End:
784 */
diff --git a/drivers/media/pci/cx25821/cx25821-audio-upstream.c b/drivers/media/pci/cx25821/cx25821-audio-upstream.c
index 87491ca05ee5..b9be535e32b8 100644
--- a/drivers/media/pci/cx25821/cx25821-audio-upstream.c
+++ b/drivers/media/pci/cx25821/cx25821-audio-upstream.c
@@ -45,7 +45,7 @@ static int _intr_msk = FLD_AUD_SRC_RISCI1 | FLD_AUD_SRC_OF |
45 FLD_AUD_SRC_SYNC | FLD_AUD_SRC_OPC_ERR; 45 FLD_AUD_SRC_SYNC | FLD_AUD_SRC_OPC_ERR;
46 46
47static int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev, 47static int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
48 struct sram_channel *ch, 48 const struct sram_channel *ch,
49 unsigned int bpl, u32 risc) 49 unsigned int bpl, u32 risc)
50{ 50{
51 unsigned int i, lines; 51 unsigned int i, lines;
@@ -106,7 +106,7 @@ static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
106 int fifo_enable) 106 int fifo_enable)
107{ 107{
108 unsigned int line; 108 unsigned int line;
109 struct sram_channel *sram_ch = 109 const struct sram_channel *sram_ch =
110 dev->channels[dev->_audio_upstream_channel].sram_channels; 110 dev->channels[dev->_audio_upstream_channel].sram_channels;
111 int offset = 0; 111 int offset = 0;
112 112
@@ -215,7 +215,7 @@ static void cx25821_free_memory_audio(struct cx25821_dev *dev)
215 215
216void cx25821_stop_upstream_audio(struct cx25821_dev *dev) 216void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
217{ 217{
218 struct sram_channel *sram_ch = 218 const struct sram_channel *sram_ch =
219 dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels; 219 dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels;
220 u32 tmp = 0; 220 u32 tmp = 0;
221 221
@@ -257,7 +257,7 @@ void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev)
257} 257}
258 258
259static int cx25821_get_audio_data(struct cx25821_dev *dev, 259static int cx25821_get_audio_data(struct cx25821_dev *dev,
260 struct sram_channel *sram_ch) 260 const struct sram_channel *sram_ch)
261{ 261{
262 struct file *myfile; 262 struct file *myfile;
263 int frame_index_temp = dev->_audioframe_index; 263 int frame_index_temp = dev->_audioframe_index;
@@ -352,7 +352,7 @@ static void cx25821_audioups_handler(struct work_struct *work)
352} 352}
353 353
354static int cx25821_openfile_audio(struct cx25821_dev *dev, 354static int cx25821_openfile_audio(struct cx25821_dev *dev,
355 struct sram_channel *sram_ch) 355 const struct sram_channel *sram_ch)
356{ 356{
357 struct file *myfile; 357 struct file *myfile;
358 int i = 0, j = 0; 358 int i = 0, j = 0;
@@ -433,7 +433,7 @@ static int cx25821_openfile_audio(struct cx25821_dev *dev,
433} 433}
434 434
435static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev, 435static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
436 struct sram_channel *sram_ch, 436 const struct sram_channel *sram_ch,
437 int bpl) 437 int bpl)
438{ 438{
439 int ret = 0; 439 int ret = 0;
@@ -495,7 +495,7 @@ static int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
495{ 495{
496 int i = 0; 496 int i = 0;
497 u32 int_msk_tmp; 497 u32 int_msk_tmp;
498 struct sram_channel *channel = dev->channels[chan_num].sram_channels; 498 const struct sram_channel *channel = dev->channels[chan_num].sram_channels;
499 dma_addr_t risc_phys_jump_addr; 499 dma_addr_t risc_phys_jump_addr;
500 __le32 *rp; 500 __le32 *rp;
501 501
@@ -587,7 +587,7 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
587 struct cx25821_dev *dev = dev_id; 587 struct cx25821_dev *dev = dev_id;
588 u32 audio_status; 588 u32 audio_status;
589 int handled = 0; 589 int handled = 0;
590 struct sram_channel *sram_ch; 590 const struct sram_channel *sram_ch;
591 591
592 if (!dev) 592 if (!dev)
593 return -1; 593 return -1;
@@ -611,7 +611,7 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
611} 611}
612 612
613static void cx25821_wait_fifo_enable(struct cx25821_dev *dev, 613static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
614 struct sram_channel *sram_ch) 614 const struct sram_channel *sram_ch)
615{ 615{
616 int count = 0; 616 int count = 0;
617 u32 tmp; 617 u32 tmp;
@@ -635,7 +635,7 @@ static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
635} 635}
636 636
637static int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev, 637static int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
638 struct sram_channel *sram_ch) 638 const struct sram_channel *sram_ch)
639{ 639{
640 u32 tmp = 0; 640 u32 tmp = 0;
641 int err = 0; 641 int err = 0;
@@ -699,7 +699,7 @@ fail_irq:
699 699
700int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select) 700int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
701{ 701{
702 struct sram_channel *sram_ch; 702 const struct sram_channel *sram_ch;
703 int err = 0; 703 int err = 0;
704 704
705 if (dev->_audio_is_running) { 705 if (dev->_audio_is_running) {
@@ -728,26 +728,17 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
728 dev->_audio_lines_count = LINES_PER_AUDIO_BUFFER; 728 dev->_audio_lines_count = LINES_PER_AUDIO_BUFFER;
729 _line_size = AUDIO_LINE_SIZE; 729 _line_size = AUDIO_LINE_SIZE;
730 730
731 if (dev->input_audiofilename) { 731 if ((dev->input_audiofilename) &&
732 (strcmp(dev->input_audiofilename, "") != 0))
732 dev->_audiofilename = kstrdup(dev->input_audiofilename, 733 dev->_audiofilename = kstrdup(dev->input_audiofilename,
733 GFP_KERNEL); 734 GFP_KERNEL);
734 735 else
735 if (!dev->_audiofilename) {
736 err = -ENOMEM;
737 goto error;
738 }
739
740 /* Default if filename is empty string */
741 if (strcmp(dev->input_audiofilename, "") == 0)
742 dev->_audiofilename = "/root/audioGOOD.wav";
743 } else {
744 dev->_audiofilename = kstrdup(_defaultAudioName, 736 dev->_audiofilename = kstrdup(_defaultAudioName,
745 GFP_KERNEL); 737 GFP_KERNEL);
746 738
747 if (!dev->_audiofilename) { 739 if (!dev->_audiofilename) {
748 err = -ENOMEM; 740 err = -ENOMEM;
749 goto error; 741 goto error;
750 }
751 } 742 }
752 743
753 cx25821_sram_channel_setup_upstream_audio(dev, sram_ch, 744 cx25821_sram_channel_setup_upstream_audio(dev, sram_ch,
diff --git a/drivers/media/pci/cx25821/cx25821-cards.c b/drivers/media/pci/cx25821/cx25821-cards.c
index 99988c988095..3b409feb03d8 100644
--- a/drivers/media/pci/cx25821/cx25821-cards.c
+++ b/drivers/media/pci/cx25821/cx25821-cards.c
@@ -26,11 +26,8 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <media/cx25840.h>
31 29
32#include "cx25821.h" 30#include "cx25821.h"
33#include "tuner-xc2028.h"
34 31
35/* board config info */ 32/* board config info */
36 33
@@ -45,28 +42,8 @@ struct cx25821_board cx25821_boards[] = {
45 .name = "CX25821", 42 .name = "CX25821",
46 .portb = CX25821_RAW, 43 .portb = CX25821_RAW,
47 .portc = CX25821_264, 44 .portc = CX25821_264,
48 .input[0].type = CX25821_VMUX_COMPOSITE,
49 }, 45 },
50 46
51}; 47};
52 48
53const unsigned int cx25821_bcount = ARRAY_SIZE(cx25821_boards); 49const unsigned int cx25821_bcount = ARRAY_SIZE(cx25821_boards);
54
55struct cx25821_subid cx25821_subids[] = {
56 {
57 .subvendor = 0x14f1,
58 .subdevice = 0x0920,
59 .card = CX25821_BOARD,
60 },
61};
62
63void cx25821_card_setup(struct cx25821_dev *dev)
64{
65 static u8 eeprom[256];
66
67 if (dev->i2c_bus[0].i2c_rc == 0) {
68 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
69 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
70 sizeof(eeprom));
71 }
72}
diff --git a/drivers/media/pci/cx25821/cx25821-core.c b/drivers/media/pci/cx25821/cx25821-core.c
index 1884e2cc35e9..b762c5b2ca10 100644
--- a/drivers/media/pci/cx25821/cx25821-core.c
+++ b/drivers/media/pci/cx25821/cx25821-core.c
@@ -41,14 +41,7 @@ static unsigned int card[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
41module_param_array(card, int, NULL, 0444); 41module_param_array(card, int, NULL, 0444);
42MODULE_PARM_DESC(card, "card type"); 42MODULE_PARM_DESC(card, "card type");
43 43
44static unsigned int cx25821_devcount; 44const struct sram_channel cx25821_sram_channels[] = {
45
46DEFINE_MUTEX(cx25821_devlist_mutex);
47EXPORT_SYMBOL(cx25821_devlist_mutex);
48LIST_HEAD(cx25821_devlist);
49EXPORT_SYMBOL(cx25821_devlist);
50
51struct sram_channel cx25821_sram_channels[] = {
52 [SRAM_CH00] = { 45 [SRAM_CH00] = {
53 .i = SRAM_CH00, 46 .i = SRAM_CH00,
54 .name = "VID A", 47 .name = "VID A",
@@ -317,20 +310,6 @@ struct sram_channel cx25821_sram_channels[] = {
317}; 310};
318EXPORT_SYMBOL(cx25821_sram_channels); 311EXPORT_SYMBOL(cx25821_sram_channels);
319 312
320struct sram_channel *channel0 = &cx25821_sram_channels[SRAM_CH00];
321struct sram_channel *channel1 = &cx25821_sram_channels[SRAM_CH01];
322struct sram_channel *channel2 = &cx25821_sram_channels[SRAM_CH02];
323struct sram_channel *channel3 = &cx25821_sram_channels[SRAM_CH03];
324struct sram_channel *channel4 = &cx25821_sram_channels[SRAM_CH04];
325struct sram_channel *channel5 = &cx25821_sram_channels[SRAM_CH05];
326struct sram_channel *channel6 = &cx25821_sram_channels[SRAM_CH06];
327struct sram_channel *channel7 = &cx25821_sram_channels[SRAM_CH07];
328struct sram_channel *channel9 = &cx25821_sram_channels[SRAM_CH09];
329struct sram_channel *channel10 = &cx25821_sram_channels[SRAM_CH10];
330struct sram_channel *channel11 = &cx25821_sram_channels[SRAM_CH11];
331
332struct cx25821_dmaqueue mpegq;
333
334static int cx25821_risc_decode(u32 risc) 313static int cx25821_risc_decode(u32 risc)
335{ 314{
336 static const char * const instr[16] = { 315 static const char * const instr[16] = {
@@ -457,7 +436,7 @@ static void cx25821_registers_init(struct cx25821_dev *dev)
457} 436}
458 437
459int cx25821_sram_channel_setup(struct cx25821_dev *dev, 438int cx25821_sram_channel_setup(struct cx25821_dev *dev,
460 struct sram_channel *ch, 439 const struct sram_channel *ch,
461 unsigned int bpl, u32 risc) 440 unsigned int bpl, u32 risc)
462{ 441{
463 unsigned int i, lines; 442 unsigned int i, lines;
@@ -523,10 +502,9 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
523 502
524 return 0; 503 return 0;
525} 504}
526EXPORT_SYMBOL(cx25821_sram_channel_setup);
527 505
528int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev, 506int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
529 struct sram_channel *ch, 507 const struct sram_channel *ch,
530 unsigned int bpl, u32 risc) 508 unsigned int bpl, u32 risc)
531{ 509{
532 unsigned int i, lines; 510 unsigned int i, lines;
@@ -592,7 +570,7 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
592} 570}
593EXPORT_SYMBOL(cx25821_sram_channel_setup_audio); 571EXPORT_SYMBOL(cx25821_sram_channel_setup_audio);
594 572
595void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch) 573void cx25821_sram_channel_dump(struct cx25821_dev *dev, const struct sram_channel *ch)
596{ 574{
597 static char *name[] = { 575 static char *name[] = {
598 "init risc lo", 576 "init risc lo",
@@ -652,10 +630,9 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
652 pr_warn(" : cnt2_reg: 0x%08x\n", 630 pr_warn(" : cnt2_reg: 0x%08x\n",
653 cx_read(ch->cnt2_reg)); 631 cx_read(ch->cnt2_reg));
654} 632}
655EXPORT_SYMBOL(cx25821_sram_channel_dump);
656 633
657void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, 634void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
658 struct sram_channel *ch) 635 const struct sram_channel *ch)
659{ 636{
660 static const char * const name[] = { 637 static const char * const name[] = {
661 "init risc lo", 638 "init risc lo",
@@ -798,12 +775,12 @@ void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select,
798 if (channel_select <= 7 && channel_select >= 0) { 775 if (channel_select <= 7 && channel_select >= 0) {
799 cx_write(dev->channels[channel_select].sram_channels->pix_frmt, 776 cx_write(dev->channels[channel_select].sram_channels->pix_frmt,
800 format); 777 format);
801 dev->channels[channel_select].pixel_formats = format;
802 } 778 }
779 dev->channels[channel_select].pixel_formats = format;
803} 780}
804 781
805static void cx25821_set_vip_mode(struct cx25821_dev *dev, 782static void cx25821_set_vip_mode(struct cx25821_dev *dev,
806 struct sram_channel *ch) 783 const struct sram_channel *ch)
807{ 784{
808 cx_write(ch->pix_frmt, PIXEL_FRMT_422); 785 cx_write(ch->pix_frmt, PIXEL_FRMT_422);
809 cx_write(ch->vip_ctl, PIXEL_ENGINE_VIP1); 786 cx_write(ch->vip_ctl, PIXEL_ENGINE_VIP1);
@@ -837,12 +814,13 @@ static void cx25821_initialize(struct cx25821_dev *dev)
837 cx25821_sram_channel_setup(dev, dev->channels[i].sram_channels, 814 cx25821_sram_channel_setup(dev, dev->channels[i].sram_channels,
838 1440, 0); 815 1440, 0);
839 dev->channels[i].pixel_formats = PIXEL_FRMT_422; 816 dev->channels[i].pixel_formats = PIXEL_FRMT_422;
840 dev->channels[i].use_cif_resolution = FALSE; 817 dev->channels[i].use_cif_resolution = 0;
841 } 818 }
842 819
843 /* Probably only affect Downstream */ 820 /* Probably only affect Downstream */
844 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; 821 for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
845 i <= VID_UPSTREAM_SRAM_CHANNEL_J; i++) { 822 i <= VID_UPSTREAM_SRAM_CHANNEL_J; i++) {
823 dev->channels[i].pixel_formats = PIXEL_FRMT_422;
846 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels); 824 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
847 } 825 }
848 826
@@ -868,8 +846,7 @@ static void cx25821_dev_checkrevision(struct cx25821_dev *dev)
868{ 846{
869 dev->hwrevision = cx_read(RDR_CFG2) & 0xff; 847 dev->hwrevision = cx_read(RDR_CFG2) & 0xff;
870 848
871 pr_info("%s(): Hardware revision = 0x%02x\n", 849 pr_info("Hardware revision = 0x%02x\n", dev->hwrevision);
872 __func__, dev->hwrevision);
873} 850}
874 851
875static void cx25821_iounmap(struct cx25821_dev *dev) 852static void cx25821_iounmap(struct cx25821_dev *dev)
@@ -879,7 +856,6 @@ static void cx25821_iounmap(struct cx25821_dev *dev)
879 856
880 /* Releasing IO memory */ 857 /* Releasing IO memory */
881 if (dev->lmmio != NULL) { 858 if (dev->lmmio != NULL) {
882 CX25821_INFO("Releasing lmmio.\n");
883 iounmap(dev->lmmio); 859 iounmap(dev->lmmio);
884 dev->lmmio = NULL; 860 dev->lmmio = NULL;
885 } 861 }
@@ -887,23 +863,14 @@ static void cx25821_iounmap(struct cx25821_dev *dev)
887 863
888static int cx25821_dev_setup(struct cx25821_dev *dev) 864static int cx25821_dev_setup(struct cx25821_dev *dev)
889{ 865{
866 static unsigned int cx25821_devcount;
890 int i; 867 int i;
891 868
892 pr_info("\n***********************************\n");
893 pr_info("cx25821 set up\n");
894 pr_info("***********************************\n\n");
895
896 mutex_init(&dev->lock); 869 mutex_init(&dev->lock);
897 870
898 atomic_inc(&dev->refcount);
899
900 dev->nr = ++cx25821_devcount; 871 dev->nr = ++cx25821_devcount;
901 sprintf(dev->name, "cx25821[%d]", dev->nr); 872 sprintf(dev->name, "cx25821[%d]", dev->nr);
902 873
903 mutex_lock(&cx25821_devlist_mutex);
904 list_add_tail(&dev->devlist, &cx25821_devlist);
905 mutex_unlock(&cx25821_devlist_mutex);
906
907 if (dev->pci->device != 0x8210) { 874 if (dev->pci->device != 0x8210) {
908 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n", 875 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
909 __func__, dev->pci->device); 876 __func__, dev->pci->device);
@@ -914,8 +881,11 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
914 881
915 /* Apply a sensible clock frequency for the PCIe bridge */ 882 /* Apply a sensible clock frequency for the PCIe bridge */
916 dev->clk_freq = 28000000; 883 dev->clk_freq = 28000000;
917 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) 884 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) {
885 dev->channels[i].dev = dev;
886 dev->channels[i].id = i;
918 dev->channels[i].sram_channels = &cx25821_sram_channels[i]; 887 dev->channels[i].sram_channels = &cx25821_sram_channels[i];
888 }
919 889
920 if (dev->nr > 1) 890 if (dev->nr > 1)
921 CX25821_INFO("dev->nr > 1!"); 891 CX25821_INFO("dev->nr > 1!");
@@ -978,63 +948,15 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
978/* cx25821_i2c_register(&dev->i2c_bus[1]); 948/* cx25821_i2c_register(&dev->i2c_bus[1]);
979 * cx25821_i2c_register(&dev->i2c_bus[2]); */ 949 * cx25821_i2c_register(&dev->i2c_bus[2]); */
980 950
981 CX25821_INFO("i2c register! bus->i2c_rc = %d\n",
982 dev->i2c_bus[0].i2c_rc);
983
984 cx25821_card_setup(dev);
985
986 if (medusa_video_init(dev) < 0) 951 if (medusa_video_init(dev) < 0)
987 CX25821_ERR("%s(): Failed to initialize medusa!\n", __func__); 952 CX25821_ERR("%s(): Failed to initialize medusa!\n", __func__);
988 953
989 cx25821_video_register(dev); 954 cx25821_video_register(dev);
990 955
991 /* register IOCTL device */
992 dev->ioctl_dev = cx25821_vdev_init(dev, dev->pci,
993 &cx25821_videoioctl_template, "video");
994
995 if (video_register_device
996 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) {
997 cx25821_videoioctl_unregister(dev);
998 pr_err("%s(): Failed to register video adapter for IOCTL, so unregistering videoioctl device\n",
999 __func__);
1000 }
1001
1002 cx25821_dev_checkrevision(dev); 956 cx25821_dev_checkrevision(dev);
1003 CX25821_INFO("setup done!\n");
1004
1005 return 0; 957 return 0;
1006} 958}
1007 959
1008void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
1009 struct upstream_user_struct *up_data)
1010{
1011 dev->_isNTSC = !strcmp(dev->vid_stdname, "NTSC") ? 1 : 0;
1012
1013 dev->tvnorm = !dev->_isNTSC ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
1014 medusa_set_videostandard(dev);
1015
1016 cx25821_vidupstream_init_ch1(dev, dev->channel_select,
1017 dev->pixel_format);
1018}
1019
1020void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
1021 struct upstream_user_struct *up_data)
1022{
1023 dev->_isNTSC_ch2 = !strcmp(dev->vid_stdname_ch2, "NTSC") ? 1 : 0;
1024
1025 dev->tvnorm = !dev->_isNTSC_ch2 ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
1026 medusa_set_videostandard(dev);
1027
1028 cx25821_vidupstream_init_ch2(dev, dev->channel_select_ch2,
1029 dev->pixel_format_ch2);
1030}
1031
1032void cx25821_start_upstream_audio(struct cx25821_dev *dev,
1033 struct upstream_user_struct *up_data)
1034{
1035 cx25821_audio_upstream_init(dev, AUDIO_UPSTREAM_SRAM_CHANNEL_B);
1036}
1037
1038void cx25821_dev_unregister(struct cx25821_dev *dev) 960void cx25821_dev_unregister(struct cx25821_dev *dev)
1039{ 961{
1040 int i; 962 int i;
@@ -1042,25 +964,16 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
1042 if (!dev->base_io_addr) 964 if (!dev->base_io_addr)
1043 return; 965 return;
1044 966
1045 cx25821_free_mem_upstream_ch1(dev);
1046 cx25821_free_mem_upstream_ch2(dev);
1047 cx25821_free_mem_upstream_audio(dev);
1048
1049 release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0)); 967 release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0));
1050 968
1051 if (!atomic_dec_and_test(&dev->refcount)) 969 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; i++) {
1052 return; 970 if (i == SRAM_CH08) /* audio channel */
1053 971 continue;
1054 for (i = 0; i < VID_CHANNEL_NUM; i++) 972 if (i == SRAM_CH09 || i == SRAM_CH10)
1055 cx25821_video_unregister(dev, i); 973 cx25821_free_mem_upstream(&dev->channels[i]);
1056
1057 for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
1058 i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
1059 cx25821_video_unregister(dev, i); 974 cx25821_video_unregister(dev, i);
1060 } 975 }
1061 976
1062 cx25821_videoioctl_unregister(dev);
1063
1064 cx25821_i2c_unregister(&dev->i2c_bus[0]); 977 cx25821_i2c_unregister(&dev->i2c_bus[0]);
1065 cx25821_iounmap(dev); 978 cx25821_iounmap(dev);
1066} 979}
@@ -1385,8 +1298,6 @@ static int cx25821_initdev(struct pci_dev *pci_dev,
1385 goto fail_unregister_device; 1298 goto fail_unregister_device;
1386 } 1299 }
1387 1300
1388 pr_info("Athena pci enable !\n");
1389
1390 err = cx25821_dev_setup(dev); 1301 err = cx25821_dev_setup(dev);
1391 if (err) { 1302 if (err) {
1392 if (err == -EBUSY) 1303 if (err == -EBUSY)
@@ -1445,10 +1356,6 @@ static void cx25821_finidev(struct pci_dev *pci_dev)
1445 if (pci_dev->irq) 1356 if (pci_dev->irq)
1446 free_irq(pci_dev->irq, dev); 1357 free_irq(pci_dev->irq, dev);
1447 1358
1448 mutex_lock(&cx25821_devlist_mutex);
1449 list_del(&dev->devlist);
1450 mutex_unlock(&cx25821_devlist_mutex);
1451
1452 cx25821_dev_unregister(dev); 1359 cx25821_dev_unregister(dev);
1453 v4l2_device_unregister(v4l2_dev); 1360 v4l2_device_unregister(v4l2_dev);
1454 kfree(dev); 1361 kfree(dev);
diff --git a/drivers/media/pci/cx25821/cx25821-gpio.c b/drivers/media/pci/cx25821/cx25821-gpio.c
index 29e43b03c85e..95e8ddf62947 100644
--- a/drivers/media/pci/cx25821/cx25821-gpio.c
+++ b/drivers/media/pci/cx25821/cx25821-gpio.c
@@ -20,6 +20,7 @@
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#include <linux/module.h>
23#include "cx25821.h" 24#include "cx25821.h"
24 25
25/********************* GPIO stuffs *********************/ 26/********************* GPIO stuffs *********************/
diff --git a/drivers/media/pci/cx25821/cx25821-i2c.c b/drivers/media/pci/cx25821/cx25821-i2c.c
index a8dc945bbe17..dca37c7dba73 100644
--- a/drivers/media/pci/cx25821/cx25821-i2c.c
+++ b/drivers/media/pci/cx25821/cx25821-i2c.c
@@ -23,8 +23,9 @@
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 25
26#include "cx25821.h" 26#include <linux/module.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include "cx25821.h"
28 29
29static unsigned int i2c_debug; 30static unsigned int i2c_debug;
30module_param(i2c_debug, int, 0644); 31module_param(i2c_debug, int, 0644);
diff --git a/drivers/media/pci/cx25821/cx25821-medusa-video.c b/drivers/media/pci/cx25821/cx25821-medusa-video.c
index 6a92e5c70c2a..22fa04415ccc 100644
--- a/drivers/media/pci/cx25821/cx25821-medusa-video.c
+++ b/drivers/media/pci/cx25821/cx25821-medusa-video.c
@@ -94,8 +94,6 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
94 u32 value = 0; 94 u32 value = 0;
95 u32 tmp = 0; 95 u32 tmp = 0;
96 96
97 mutex_lock(&dev->lock);
98
99 for (i = 0; i < MAX_DECODERS; i++) { 97 for (i = 0; i < MAX_DECODERS; i++) {
100 /* set video format NTSC-M */ 98 /* set video format NTSC-M */
101 value = cx25821_i2c_read(&dev->i2c_bus[0], 99 value = cx25821_i2c_read(&dev->i2c_bus[0],
@@ -222,8 +220,6 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
222 value |= 0x00080200; 220 value |= 0x00080200;
223 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value); 221 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value);
224 222
225 mutex_unlock(&dev->lock);
226
227 return ret_val; 223 return ret_val;
228} 224}
229 225
@@ -265,8 +261,6 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
265 u32 value = 0; 261 u32 value = 0;
266 u32 tmp = 0; 262 u32 tmp = 0;
267 263
268 mutex_lock(&dev->lock);
269
270 for (i = 0; i < MAX_DECODERS; i++) { 264 for (i = 0; i < MAX_DECODERS; i++) {
271 /* set video format PAL-BDGHI */ 265 /* set video format PAL-BDGHI */
272 value = cx25821_i2c_read(&dev->i2c_bus[0], 266 value = cx25821_i2c_read(&dev->i2c_bus[0],
@@ -397,14 +391,12 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
397 value &= 0xFFF7FDFF; 391 value &= 0xFFF7FDFF;
398 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value); 392 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value);
399 393
400 mutex_unlock(&dev->lock);
401
402 return ret_val; 394 return ret_val;
403} 395}
404 396
405int medusa_set_videostandard(struct cx25821_dev *dev) 397int medusa_set_videostandard(struct cx25821_dev *dev)
406{ 398{
407 int status = STATUS_SUCCESS; 399 int status = 0;
408 u32 value = 0, tmp = 0; 400 u32 value = 0, tmp = 0;
409 401
410 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) 402 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
@@ -434,8 +426,6 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
434 u32 vscale = 0x0; 426 u32 vscale = 0x0;
435 const int MAX_WIDTH = 720; 427 const int MAX_WIDTH = 720;
436 428
437 mutex_lock(&dev->lock);
438
439 /* validate the width */ 429 /* validate the width */
440 if (width > MAX_WIDTH) { 430 if (width > MAX_WIDTH) {
441 pr_info("%s(): width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH\n", 431 pr_info("%s(): width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH\n",
@@ -485,8 +475,6 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
485 cx25821_i2c_write(&dev->i2c_bus[0], 475 cx25821_i2c_write(&dev->i2c_bus[0],
486 VSCALE_CTRL + (0x200 * decoder), vscale); 476 VSCALE_CTRL + (0x200 * decoder), vscale);
487 } 477 }
488
489 mutex_unlock(&dev->lock);
490} 478}
491 479
492static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, 480static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
@@ -496,11 +484,8 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
496 u32 tmp = 0; 484 u32 tmp = 0;
497 u32 disp_cnt_reg = DISP_AB_CNT; 485 u32 disp_cnt_reg = DISP_AB_CNT;
498 486
499 mutex_lock(&dev->lock);
500
501 /* no support */ 487 /* no support */
502 if (decoder < VDEC_A || decoder > VDEC_H) { 488 if (decoder < VDEC_A || decoder > VDEC_H) {
503 mutex_unlock(&dev->lock);
504 return; 489 return;
505 } 490 }
506 491
@@ -535,8 +520,6 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
535 } 520 }
536 521
537 cx25821_i2c_write(&dev->i2c_bus[0], disp_cnt_reg, fld_cnt); 522 cx25821_i2c_write(&dev->i2c_bus[0], disp_cnt_reg, fld_cnt);
538
539 mutex_unlock(&dev->lock);
540} 523}
541 524
542/* Map to Medusa register setting */ 525/* Map to Medusa register setting */
@@ -587,10 +570,8 @@ int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder)
587 int value = 0; 570 int value = 0;
588 u32 val = 0, tmp = 0; 571 u32 val = 0, tmp = 0;
589 572
590 mutex_lock(&dev->lock);
591 if ((brightness > VIDEO_PROCAMP_MAX) || 573 if ((brightness > VIDEO_PROCAMP_MAX) ||
592 (brightness < VIDEO_PROCAMP_MIN)) { 574 (brightness < VIDEO_PROCAMP_MIN)) {
593 mutex_unlock(&dev->lock);
594 return -1; 575 return -1;
595 } 576 }
596 ret_val = mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, brightness, 577 ret_val = mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, brightness,
@@ -601,7 +582,6 @@ int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder)
601 val &= 0xFFFFFF00; 582 val &= 0xFFFFFF00;
602 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], 583 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0],
603 VDEC_A_BRITE_CTRL + (0x200 * decoder), val | value); 584 VDEC_A_BRITE_CTRL + (0x200 * decoder), val | value);
604 mutex_unlock(&dev->lock);
605 return ret_val; 585 return ret_val;
606} 586}
607 587
@@ -611,10 +591,7 @@ int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder)
611 int value = 0; 591 int value = 0;
612 u32 val = 0, tmp = 0; 592 u32 val = 0, tmp = 0;
613 593
614 mutex_lock(&dev->lock);
615
616 if ((contrast > VIDEO_PROCAMP_MAX) || (contrast < VIDEO_PROCAMP_MIN)) { 594 if ((contrast > VIDEO_PROCAMP_MAX) || (contrast < VIDEO_PROCAMP_MIN)) {
617 mutex_unlock(&dev->lock);
618 return -1; 595 return -1;
619 } 596 }
620 597
@@ -626,7 +603,6 @@ int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder)
626 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], 603 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0],
627 VDEC_A_CNTRST_CTRL + (0x200 * decoder), val | value); 604 VDEC_A_CNTRST_CTRL + (0x200 * decoder), val | value);
628 605
629 mutex_unlock(&dev->lock);
630 return ret_val; 606 return ret_val;
631} 607}
632 608
@@ -636,10 +612,7 @@ int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder)
636 int value = 0; 612 int value = 0;
637 u32 val = 0, tmp = 0; 613 u32 val = 0, tmp = 0;
638 614
639 mutex_lock(&dev->lock);
640
641 if ((hue > VIDEO_PROCAMP_MAX) || (hue < VIDEO_PROCAMP_MIN)) { 615 if ((hue > VIDEO_PROCAMP_MAX) || (hue < VIDEO_PROCAMP_MIN)) {
642 mutex_unlock(&dev->lock);
643 return -1; 616 return -1;
644 } 617 }
645 618
@@ -654,7 +627,6 @@ int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder)
654 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], 627 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0],
655 VDEC_A_HUE_CTRL + (0x200 * decoder), val | value); 628 VDEC_A_HUE_CTRL + (0x200 * decoder), val | value);
656 629
657 mutex_unlock(&dev->lock);
658 return ret_val; 630 return ret_val;
659} 631}
660 632
@@ -664,11 +636,8 @@ int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
664 int value = 0; 636 int value = 0;
665 u32 val = 0, tmp = 0; 637 u32 val = 0, tmp = 0;
666 638
667 mutex_lock(&dev->lock);
668
669 if ((saturation > VIDEO_PROCAMP_MAX) || 639 if ((saturation > VIDEO_PROCAMP_MAX) ||
670 (saturation < VIDEO_PROCAMP_MIN)) { 640 (saturation < VIDEO_PROCAMP_MIN)) {
671 mutex_unlock(&dev->lock);
672 return -1; 641 return -1;
673 } 642 }
674 643
@@ -687,7 +656,6 @@ int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
687 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0], 656 ret_val |= cx25821_i2c_write(&dev->i2c_bus[0],
688 VDEC_A_VSAT_CTRL + (0x200 * decoder), val | value); 657 VDEC_A_VSAT_CTRL + (0x200 * decoder), val | value);
689 658
690 mutex_unlock(&dev->lock);
691 return ret_val; 659 return ret_val;
692} 660}
693 661
@@ -699,8 +667,6 @@ int medusa_video_init(struct cx25821_dev *dev)
699 int ret_val = 0; 667 int ret_val = 0;
700 int i = 0; 668 int i = 0;
701 669
702 mutex_lock(&dev->lock);
703
704 _num_decoders = dev->_max_num_decoders; 670 _num_decoders = dev->_max_num_decoders;
705 671
706 /* disable Auto source selection on all video decoders */ 672 /* disable Auto source selection on all video decoders */
@@ -719,13 +685,9 @@ int medusa_video_init(struct cx25821_dev *dev)
719 if (ret_val < 0) 685 if (ret_val < 0)
720 goto error; 686 goto error;
721 687
722 mutex_unlock(&dev->lock);
723
724 for (i = 0; i < _num_decoders; i++) 688 for (i = 0; i < _num_decoders; i++)
725 medusa_set_decoderduration(dev, i, _display_field_cnt[i]); 689 medusa_set_decoderduration(dev, i, _display_field_cnt[i]);
726 690
727 mutex_lock(&dev->lock);
728
729 /* Select monitor as DENC A input, power up the DAC */ 691 /* Select monitor as DENC A input, power up the DAC */
730 value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp); 692 value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp);
731 value &= 0xFF70FF70; 693 value &= 0xFF70FF70;
@@ -774,14 +736,8 @@ int medusa_video_init(struct cx25821_dev *dev)
774 if (ret_val < 0) 736 if (ret_val < 0)
775 goto error; 737 goto error;
776 738
777
778 mutex_unlock(&dev->lock);
779
780 ret_val = medusa_set_videostandard(dev); 739 ret_val = medusa_set_videostandard(dev);
781 740
782 return ret_val;
783
784error: 741error:
785 mutex_unlock(&dev->lock);
786 return ret_val; 742 return ret_val;
787} 743}
diff --git a/drivers/media/pci/cx25821/cx25821-video-upstream-ch2.c b/drivers/media/pci/cx25821/cx25821-video-upstream-ch2.c
deleted file mode 100644
index cf2723c7197f..000000000000
--- a/drivers/media/pci/cx25821/cx25821-video-upstream-ch2.c
+++ /dev/null
@@ -1,800 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.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 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
25#include "cx25821-video.h"
26#include "cx25821-video-upstream-ch2.h"
27
28#include <linux/fs.h>
29#include <linux/errno.h>
30#include <linux/kernel.h>
31#include <linux/init.h>
32#include <linux/module.h>
33#include <linux/syscalls.h>
34#include <linux/file.h>
35#include <linux/fcntl.h>
36#include <linux/slab.h>
37#include <linux/uaccess.h>
38
39MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
40MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
41MODULE_LICENSE("GPL");
42
43static int _intr_msk = FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC |
44 FLD_VID_SRC_OPC_ERR;
45
46static __le32 *cx25821_update_riscprogram_ch2(struct cx25821_dev *dev,
47 __le32 *rp, unsigned int offset,
48 unsigned int bpl, u32 sync_line,
49 unsigned int lines,
50 int fifo_enable, int field_type)
51{
52 unsigned int line, i;
53 int dist_betwn_starts = bpl * 2;
54
55 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
56
57 if (USE_RISC_NOOP_VIDEO) {
58 for (i = 0; i < NUM_NO_OPS; i++)
59 *(rp++) = cpu_to_le32(RISC_NOOP);
60 }
61
62 /* scan lines */
63 for (line = 0; line < lines; line++) {
64 *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
65 *(rp++) = cpu_to_le32(dev->_data_buf_phys_addr_ch2 + offset);
66 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
67
68 if ((lines <= NTSC_FIELD_HEIGHT) ||
69 (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC_ch2)) {
70 offset += dist_betwn_starts;
71 }
72 }
73
74 return rp;
75}
76
77static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
78 __le32 *rp,
79 dma_addr_t databuf_phys_addr,
80 unsigned int offset,
81 u32 sync_line, unsigned int bpl,
82 unsigned int lines,
83 int fifo_enable, int field_type)
84{
85 unsigned int line, i;
86 struct sram_channel *sram_ch =
87 dev->channels[dev->_channel2_upstream_select].sram_channels;
88 int dist_betwn_starts = bpl * 2;
89
90 /* sync instruction */
91 if (sync_line != NO_SYNC_LINE)
92 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
93
94 if (USE_RISC_NOOP_VIDEO) {
95 for (i = 0; i < NUM_NO_OPS; i++)
96 *(rp++) = cpu_to_le32(RISC_NOOP);
97 }
98
99 /* scan lines */
100 for (line = 0; line < lines; line++) {
101 *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
102 *(rp++) = cpu_to_le32(databuf_phys_addr + offset);
103 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
104
105 if ((lines <= NTSC_FIELD_HEIGHT) ||
106 (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC_ch2)) {
107 offset += dist_betwn_starts;
108 }
109
110 /*
111 check if we need to enable the FIFO after the first 4 lines
112 For the upstream video channel, the risc engine will enable
113 the FIFO.
114 */
115 if (fifo_enable && line == 3) {
116 *(rp++) = RISC_WRITECR;
117 *(rp++) = sram_ch->dma_ctl;
118 *(rp++) = FLD_VID_FIFO_EN;
119 *(rp++) = 0x00000001;
120 }
121 }
122
123 return rp;
124}
125
126static int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
127 struct pci_dev *pci,
128 unsigned int top_offset,
129 unsigned int bpl,
130 unsigned int lines)
131{
132 __le32 *rp;
133 int fifo_enable = 0;
134 int singlefield_lines = lines >> 1; /*get line count for single field */
135 int odd_num_lines = singlefield_lines;
136 int frame = 0;
137 int frame_size = 0;
138 int databuf_offset = 0;
139 int risc_program_size = 0;
140 int risc_flag = RISC_CNT_RESET;
141 unsigned int bottom_offset = bpl;
142 dma_addr_t risc_phys_jump_addr;
143
144 if (dev->_isNTSC_ch2) {
145 odd_num_lines = singlefield_lines + 1;
146 risc_program_size = FRAME1_VID_PROG_SIZE;
147 if (bpl == Y411_LINE_SZ)
148 frame_size = FRAME_SIZE_NTSC_Y411;
149 else
150 frame_size = FRAME_SIZE_NTSC_Y422;
151 } else {
152 risc_program_size = PAL_VID_PROG_SIZE;
153 if (bpl == Y411_LINE_SZ)
154 frame_size = FRAME_SIZE_PAL_Y411;
155 else
156 frame_size = FRAME_SIZE_PAL_Y422;
157 }
158
159 /* Virtual address of Risc buffer program */
160 rp = dev->_dma_virt_addr_ch2;
161
162 for (frame = 0; frame < NUM_FRAMES; frame++) {
163 databuf_offset = frame_size * frame;
164
165 if (UNSET != top_offset) {
166 fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE;
167 rp = cx25821_risc_field_upstream_ch2(dev, rp,
168 dev->_data_buf_phys_addr_ch2 + databuf_offset,
169 top_offset, 0, bpl, odd_num_lines, fifo_enable,
170 ODD_FIELD);
171 }
172
173 fifo_enable = FIFO_DISABLE;
174
175 /* Even field */
176 rp = cx25821_risc_field_upstream_ch2(dev, rp,
177 dev->_data_buf_phys_addr_ch2 + databuf_offset,
178 bottom_offset, 0x200, bpl, singlefield_lines,
179 fifo_enable, EVEN_FIELD);
180
181 if (frame == 0) {
182 risc_flag = RISC_CNT_RESET;
183 risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2 +
184 risc_program_size;
185 } else {
186 risc_flag = RISC_CNT_INC;
187 risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2;
188 }
189
190 /*
191 * Loop to 2ndFrameRISC or to Start of
192 * Risc program & generate IRQ
193 */
194 *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
195 *(rp++) = cpu_to_le32(risc_phys_jump_addr);
196 *(rp++) = cpu_to_le32(0);
197 }
198
199 return 0;
200}
201
202void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
203{
204 struct sram_channel *sram_ch =
205 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_J].sram_channels;
206 u32 tmp = 0;
207
208 if (!dev->_is_running_ch2) {
209 pr_info("No video file is currently running so return!\n");
210 return;
211 }
212 /* Disable RISC interrupts */
213 tmp = cx_read(sram_ch->int_msk);
214 cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
215
216 /* Turn OFF risc and fifo */
217 tmp = cx_read(sram_ch->dma_ctl);
218 cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN));
219
220 /* Clear data buffer memory */
221 if (dev->_data_buf_virt_addr_ch2)
222 memset(dev->_data_buf_virt_addr_ch2, 0,
223 dev->_data_buf_size_ch2);
224
225 dev->_is_running_ch2 = 0;
226 dev->_is_first_frame_ch2 = 0;
227 dev->_frame_count_ch2 = 0;
228 dev->_file_status_ch2 = END_OF_FILE;
229
230 kfree(dev->_irq_queues_ch2);
231 dev->_irq_queues_ch2 = NULL;
232
233 kfree(dev->_filename_ch2);
234
235 tmp = cx_read(VID_CH_MODE_SEL);
236 cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
237}
238
239void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev)
240{
241 if (dev->_is_running_ch2)
242 cx25821_stop_upstream_video_ch2(dev);
243
244 if (dev->_dma_virt_addr_ch2) {
245 pci_free_consistent(dev->pci, dev->_risc_size_ch2,
246 dev->_dma_virt_addr_ch2,
247 dev->_dma_phys_addr_ch2);
248 dev->_dma_virt_addr_ch2 = NULL;
249 }
250
251 if (dev->_data_buf_virt_addr_ch2) {
252 pci_free_consistent(dev->pci, dev->_data_buf_size_ch2,
253 dev->_data_buf_virt_addr_ch2,
254 dev->_data_buf_phys_addr_ch2);
255 dev->_data_buf_virt_addr_ch2 = NULL;
256 }
257}
258
259static int cx25821_get_frame_ch2(struct cx25821_dev *dev,
260 struct sram_channel *sram_ch)
261{
262 struct file *myfile;
263 int frame_index_temp = dev->_frame_index_ch2;
264 int i = 0;
265 int line_size = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ?
266 Y411_LINE_SZ : Y422_LINE_SZ;
267 int frame_size = 0;
268 int frame_offset = 0;
269 ssize_t vfs_read_retval = 0;
270 char mybuf[line_size];
271 loff_t file_offset;
272 loff_t pos;
273 mm_segment_t old_fs;
274
275 if (dev->_file_status_ch2 == END_OF_FILE)
276 return 0;
277
278 if (dev->_isNTSC_ch2) {
279 frame_size = (line_size == Y411_LINE_SZ) ?
280 FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422;
281 } else {
282 frame_size = (line_size == Y411_LINE_SZ) ?
283 FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
284 }
285
286 frame_offset = (frame_index_temp > 0) ? frame_size : 0;
287 file_offset = dev->_frame_count_ch2 * frame_size;
288
289 myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0);
290 if (IS_ERR(myfile)) {
291 const int open_errno = -PTR_ERR(myfile);
292 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
293 __func__, dev->_filename_ch2, open_errno);
294 return PTR_ERR(myfile);
295 } else {
296 if (!(myfile->f_op)) {
297 pr_err("%s(): File has no file operations registered!\n",
298 __func__);
299 filp_close(myfile, NULL);
300 return -EIO;
301 }
302
303 if (!myfile->f_op->read) {
304 pr_err("%s(): File has no READ operations registered!\n",
305 __func__);
306 filp_close(myfile, NULL);
307 return -EIO;
308 }
309
310 pos = myfile->f_pos;
311 old_fs = get_fs();
312 set_fs(KERNEL_DS);
313
314 for (i = 0; i < dev->_lines_count_ch2; i++) {
315 pos = file_offset;
316
317 vfs_read_retval = vfs_read(myfile, mybuf, line_size,
318 &pos);
319
320 if (vfs_read_retval > 0 && vfs_read_retval == line_size
321 && dev->_data_buf_virt_addr_ch2 != NULL) {
322 memcpy((void *)(dev->_data_buf_virt_addr_ch2 +
323 frame_offset / 4), mybuf,
324 vfs_read_retval);
325 }
326
327 file_offset += vfs_read_retval;
328 frame_offset += vfs_read_retval;
329
330 if (vfs_read_retval < line_size) {
331 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
332 __func__);
333 break;
334 }
335 }
336
337 if (i > 0)
338 dev->_frame_count_ch2++;
339
340 dev->_file_status_ch2 = (vfs_read_retval == line_size) ?
341 IN_PROGRESS : END_OF_FILE;
342
343 set_fs(old_fs);
344 filp_close(myfile, NULL);
345 }
346
347 return 0;
348}
349
350static void cx25821_vidups_handler_ch2(struct work_struct *work)
351{
352 struct cx25821_dev *dev = container_of(work, struct cx25821_dev,
353 _irq_work_entry_ch2);
354
355 if (!dev) {
356 pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
357 __func__);
358 return;
359 }
360
361 cx25821_get_frame_ch2(dev, dev->channels[dev->
362 _channel2_upstream_select].sram_channels);
363}
364
365static int cx25821_openfile_ch2(struct cx25821_dev *dev,
366 struct sram_channel *sram_ch)
367{
368 struct file *myfile;
369 int i = 0, j = 0;
370 int line_size = (dev->_pixel_format_ch2 == PIXEL_FRMT_411) ?
371 Y411_LINE_SZ : Y422_LINE_SZ;
372 ssize_t vfs_read_retval = 0;
373 char mybuf[line_size];
374 loff_t pos;
375 loff_t offset = (unsigned long)0;
376 mm_segment_t old_fs;
377
378 myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0);
379
380 if (IS_ERR(myfile)) {
381 const int open_errno = -PTR_ERR(myfile);
382 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
383 __func__, dev->_filename_ch2, open_errno);
384 return PTR_ERR(myfile);
385 } else {
386 if (!(myfile->f_op)) {
387 pr_err("%s(): File has no file operations registered!\n",
388 __func__);
389 filp_close(myfile, NULL);
390 return -EIO;
391 }
392
393 if (!myfile->f_op->read) {
394 pr_err("%s(): File has no READ operations registered! Returning\n",
395 __func__);
396 filp_close(myfile, NULL);
397 return -EIO;
398 }
399
400 pos = myfile->f_pos;
401 old_fs = get_fs();
402 set_fs(KERNEL_DS);
403
404 for (j = 0; j < NUM_FRAMES; j++) {
405 for (i = 0; i < dev->_lines_count_ch2; i++) {
406 pos = offset;
407
408 vfs_read_retval = vfs_read(myfile, mybuf,
409 line_size, &pos);
410
411 if (vfs_read_retval > 0 &&
412 vfs_read_retval == line_size &&
413 dev->_data_buf_virt_addr_ch2 != NULL) {
414 memcpy((void *)(dev->
415 _data_buf_virt_addr_ch2
416 + offset / 4), mybuf,
417 vfs_read_retval);
418 }
419
420 offset += vfs_read_retval;
421
422 if (vfs_read_retval < line_size) {
423 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
424 __func__);
425 break;
426 }
427 }
428
429 if (i > 0)
430 dev->_frame_count_ch2++;
431
432 if (vfs_read_retval < line_size)
433 break;
434 }
435
436 dev->_file_status_ch2 = (vfs_read_retval == line_size) ?
437 IN_PROGRESS : END_OF_FILE;
438
439 set_fs(old_fs);
440 myfile->f_pos = 0;
441 filp_close(myfile, NULL);
442 }
443
444 return 0;
445}
446
447static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
448 struct sram_channel *sram_ch,
449 int bpl)
450{
451 int ret = 0;
452 dma_addr_t dma_addr;
453 dma_addr_t data_dma_addr;
454
455 if (dev->_dma_virt_addr_ch2 != NULL) {
456 pci_free_consistent(dev->pci, dev->upstream_riscbuf_size_ch2,
457 dev->_dma_virt_addr_ch2,
458 dev->_dma_phys_addr_ch2);
459 }
460
461 dev->_dma_virt_addr_ch2 = pci_alloc_consistent(dev->pci,
462 dev->upstream_riscbuf_size_ch2, &dma_addr);
463 dev->_dma_virt_start_addr_ch2 = dev->_dma_virt_addr_ch2;
464 dev->_dma_phys_start_addr_ch2 = dma_addr;
465 dev->_dma_phys_addr_ch2 = dma_addr;
466 dev->_risc_size_ch2 = dev->upstream_riscbuf_size_ch2;
467
468 if (!dev->_dma_virt_addr_ch2) {
469 pr_err("FAILED to allocate memory for Risc buffer! Returning\n");
470 return -ENOMEM;
471 }
472
473 /* Iniitize at this address until n bytes to 0 */
474 memset(dev->_dma_virt_addr_ch2, 0, dev->_risc_size_ch2);
475
476 if (dev->_data_buf_virt_addr_ch2 != NULL) {
477 pci_free_consistent(dev->pci, dev->upstream_databuf_size_ch2,
478 dev->_data_buf_virt_addr_ch2,
479 dev->_data_buf_phys_addr_ch2);
480 }
481 /* For Video Data buffer allocation */
482 dev->_data_buf_virt_addr_ch2 = pci_alloc_consistent(dev->pci,
483 dev->upstream_databuf_size_ch2, &data_dma_addr);
484 dev->_data_buf_phys_addr_ch2 = data_dma_addr;
485 dev->_data_buf_size_ch2 = dev->upstream_databuf_size_ch2;
486
487 if (!dev->_data_buf_virt_addr_ch2) {
488 pr_err("FAILED to allocate memory for data buffer! Returning\n");
489 return -ENOMEM;
490 }
491
492 /* Initialize at this address until n bytes to 0 */
493 memset(dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2);
494
495 ret = cx25821_openfile_ch2(dev, sram_ch);
496 if (ret < 0)
497 return ret;
498
499 /* Creating RISC programs */
500 ret = cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl,
501 dev->_lines_count_ch2);
502 if (ret < 0) {
503 pr_info("Failed creating Video Upstream Risc programs!\n");
504 goto error;
505 }
506
507 return 0;
508
509error:
510 return ret;
511}
512
513static int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev,
514 int chan_num,
515 u32 status)
516{
517 u32 int_msk_tmp;
518 struct sram_channel *channel = dev->channels[chan_num].sram_channels;
519 int singlefield_lines = NTSC_FIELD_HEIGHT;
520 int line_size_in_bytes = Y422_LINE_SZ;
521 int odd_risc_prog_size = 0;
522 dma_addr_t risc_phys_jump_addr;
523 __le32 *rp;
524
525 if (status & FLD_VID_SRC_RISC1) {
526 /* We should only process one program per call */
527 u32 prog_cnt = cx_read(channel->gpcnt);
528
529 /*
530 * Since we've identified our IRQ, clear our bits from the
531 * interrupt mask and interrupt status registers
532 */
533 int_msk_tmp = cx_read(channel->int_msk);
534 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
535 cx_write(channel->int_stat, _intr_msk);
536
537 spin_lock(&dev->slock);
538
539 dev->_frame_index_ch2 = prog_cnt;
540
541 queue_work(dev->_irq_queues_ch2, &dev->_irq_work_entry_ch2);
542
543 if (dev->_is_first_frame_ch2) {
544 dev->_is_first_frame_ch2 = 0;
545
546 if (dev->_isNTSC_ch2) {
547 singlefield_lines += 1;
548 odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE;
549 } else {
550 singlefield_lines = PAL_FIELD_HEIGHT;
551 odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE;
552 }
553
554 if (dev->_dma_virt_start_addr_ch2 != NULL) {
555 if (dev->_pixel_format_ch2 == PIXEL_FRMT_411)
556 line_size_in_bytes = Y411_LINE_SZ;
557 else
558 line_size_in_bytes = Y422_LINE_SZ;
559 risc_phys_jump_addr =
560 dev->_dma_phys_start_addr_ch2 +
561 odd_risc_prog_size;
562
563 rp = cx25821_update_riscprogram_ch2(dev,
564 dev->_dma_virt_start_addr_ch2,
565 TOP_OFFSET, line_size_in_bytes,
566 0x0, singlefield_lines,
567 FIFO_DISABLE, ODD_FIELD);
568
569 /* Jump to Even Risc program of 1st Frame */
570 *(rp++) = cpu_to_le32(RISC_JUMP);
571 *(rp++) = cpu_to_le32(risc_phys_jump_addr);
572 *(rp++) = cpu_to_le32(0);
573 }
574 }
575
576 spin_unlock(&dev->slock);
577 }
578
579 if (dev->_file_status_ch2 == END_OF_FILE) {
580 pr_info("EOF Channel 2 Framecount = %d\n",
581 dev->_frame_count_ch2);
582 return -1;
583 }
584 /* ElSE, set the interrupt mask register, re-enable irq. */
585 int_msk_tmp = cx_read(channel->int_msk);
586 cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
587
588 return 0;
589}
590
591static irqreturn_t cx25821_upstream_irq_ch2(int irq, void *dev_id)
592{
593 struct cx25821_dev *dev = dev_id;
594 u32 vid_status;
595 int handled = 0;
596 int channel_num = 0;
597 struct sram_channel *sram_ch;
598
599 if (!dev)
600 return -1;
601
602 channel_num = VID_UPSTREAM_SRAM_CHANNEL_J;
603 sram_ch = dev->channels[channel_num].sram_channels;
604
605 vid_status = cx_read(sram_ch->int_stat);
606
607 /* Only deal with our interrupt */
608 if (vid_status)
609 handled = cx25821_video_upstream_irq_ch2(dev, channel_num,
610 vid_status);
611
612 if (handled < 0)
613 cx25821_stop_upstream_video_ch2(dev);
614 else
615 handled += handled;
616
617 return IRQ_RETVAL(handled);
618}
619
620static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev,
621 struct sram_channel *ch, int pix_format)
622{
623 int width = WIDTH_D1;
624 int height = dev->_lines_count_ch2;
625 int num_lines, odd_num_lines;
626 u32 value;
627 int vip_mode = PIXEL_ENGINE_VIP1;
628
629 value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7);
630 value &= 0xFFFFFFEF;
631 value |= dev->_isNTSC_ch2 ? 0 : 0x10;
632 cx_write(ch->vid_fmt_ctl, value);
633
634 /*
635 * set number of active pixels in each line. Default is 720
636 * pixels in both NTSC and PAL format
637 */
638 cx_write(ch->vid_active_ctl1, width);
639
640 num_lines = (height / 2) & 0x3FF;
641 odd_num_lines = num_lines;
642
643 if (dev->_isNTSC_ch2)
644 odd_num_lines += 1;
645
646 value = (num_lines << 16) | odd_num_lines;
647
648 /* set number of active lines in field 0 (top) and field 1 (bottom) */
649 cx_write(ch->vid_active_ctl2, value);
650
651 cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3);
652}
653
654static int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
655 struct sram_channel *sram_ch)
656{
657 u32 tmp = 0;
658 int err = 0;
659
660 /*
661 * 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface
662 * for channel A-C
663 */
664 tmp = cx_read(VID_CH_MODE_SEL);
665 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
666
667 /*
668 * Set the physical start address of the RISC program in the initial
669 * program counter(IPC) member of the cmds.
670 */
671 cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2);
672 cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */
673
674 /* reset counter */
675 cx_write(sram_ch->gpcnt_ctl, 3);
676
677 /* Clear our bits from the interrupt status register. */
678 cx_write(sram_ch->int_stat, _intr_msk);
679
680 /* Set the interrupt mask register, enable irq. */
681 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
682 tmp = cx_read(sram_ch->int_msk);
683 cx_write(sram_ch->int_msk, tmp |= _intr_msk);
684
685 err = request_irq(dev->pci->irq, cx25821_upstream_irq_ch2,
686 IRQF_SHARED, dev->name, dev);
687 if (err < 0) {
688 pr_err("%s: can't get upstream IRQ %d\n",
689 dev->name, dev->pci->irq);
690 goto fail_irq;
691 }
692 /* Start the DMA engine */
693 tmp = cx_read(sram_ch->dma_ctl);
694 cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
695
696 dev->_is_running_ch2 = 1;
697 dev->_is_first_frame_ch2 = 1;
698
699 return 0;
700
701fail_irq:
702 cx25821_dev_unregister(dev);
703 return err;
704}
705
706int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
707 int pixel_format)
708{
709 struct sram_channel *sram_ch;
710 u32 tmp;
711 int err = 0;
712 int data_frame_size = 0;
713 int risc_buffer_size = 0;
714
715 if (dev->_is_running_ch2) {
716 pr_info("Video Channel is still running so return!\n");
717 return 0;
718 }
719
720 dev->_channel2_upstream_select = channel_select;
721 sram_ch = dev->channels[channel_select].sram_channels;
722
723 INIT_WORK(&dev->_irq_work_entry_ch2, cx25821_vidups_handler_ch2);
724 dev->_irq_queues_ch2 =
725 create_singlethread_workqueue("cx25821_workqueue2");
726
727 if (!dev->_irq_queues_ch2) {
728 pr_err("create_singlethread_workqueue() for Video FAILED!\n");
729 return -ENOMEM;
730 }
731 /*
732 * 656/VIP SRC Upstream Channel I & J and 7 -
733 * Host Bus Interface for channel A-C
734 */
735 tmp = cx_read(VID_CH_MODE_SEL);
736 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
737
738 dev->_is_running_ch2 = 0;
739 dev->_frame_count_ch2 = 0;
740 dev->_file_status_ch2 = RESET_STATUS;
741 dev->_lines_count_ch2 = dev->_isNTSC_ch2 ? 480 : 576;
742 dev->_pixel_format_ch2 = pixel_format;
743 dev->_line_size_ch2 = (dev->_pixel_format_ch2 == PIXEL_FRMT_422) ?
744 (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2;
745 data_frame_size = dev->_isNTSC_ch2 ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ;
746 risc_buffer_size = dev->_isNTSC_ch2 ?
747 NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE;
748
749 if (dev->input_filename_ch2)
750 dev->_filename_ch2 = kstrdup(dev->input_filename_ch2,
751 GFP_KERNEL);
752 else
753 dev->_filename_ch2 = kstrdup(dev->_defaultname_ch2,
754 GFP_KERNEL);
755
756 if (!dev->_filename_ch2) {
757 err = -ENOENT;
758 goto error;
759 }
760
761 /* Default if filename is empty string */
762 if (strcmp(dev->_filename_ch2, "") == 0) {
763 if (dev->_isNTSC_ch2) {
764 dev->_filename_ch2 = (dev->_pixel_format_ch2 ==
765 PIXEL_FRMT_411) ? "/root/vid411.yuv" :
766 "/root/vidtest.yuv";
767 } else {
768 dev->_filename_ch2 = (dev->_pixel_format_ch2 ==
769 PIXEL_FRMT_411) ? "/root/pal411.yuv" :
770 "/root/pal422.yuv";
771 }
772 }
773
774 err = cx25821_sram_channel_setup_upstream(dev, sram_ch,
775 dev->_line_size_ch2, 0);
776
777 /* setup fifo + format */
778 cx25821_set_pixelengine_ch2(dev, sram_ch, dev->_pixel_format_ch2);
779
780 dev->upstream_riscbuf_size_ch2 = risc_buffer_size * 2;
781 dev->upstream_databuf_size_ch2 = data_frame_size * 2;
782
783 /* Allocating buffers and prepare RISC program */
784 err = cx25821_upstream_buffer_prepare_ch2(dev, sram_ch,
785 dev->_line_size_ch2);
786 if (err < 0) {
787 pr_err("%s: Failed to set up Video upstream buffers!\n",
788 dev->name);
789 goto error;
790 }
791
792 cx25821_start_video_dma_upstream_ch2(dev, sram_ch);
793
794 return 0;
795
796error:
797 cx25821_dev_unregister(dev);
798
799 return err;
800}
diff --git a/drivers/media/pci/cx25821/cx25821-video-upstream-ch2.h b/drivers/media/pci/cx25821/cx25821-video-upstream-ch2.h
deleted file mode 100644
index d42dab59b663..000000000000
--- a/drivers/media/pci/cx25821/cx25821-video-upstream-ch2.h
+++ /dev/null
@@ -1,138 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.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 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/mutex.h>
24#include <linux/workqueue.h>
25
26#define OPEN_FILE_1 0
27#define NUM_PROGS 8
28#define NUM_FRAMES 2
29#define ODD_FIELD 0
30#define EVEN_FIELD 1
31#define TOP_OFFSET 0
32#define FIFO_DISABLE 0
33#define FIFO_ENABLE 1
34#define TEST_FRAMES 5
35#define END_OF_FILE 0
36#define IN_PROGRESS 1
37#define RESET_STATUS -1
38#define NUM_NO_OPS 5
39
40/* PAL and NTSC line sizes and number of lines. */
41#define WIDTH_D1 720
42#define NTSC_LINES_PER_FRAME 480
43#define PAL_LINES_PER_FRAME 576
44#define PAL_LINE_SZ 1440
45#define Y422_LINE_SZ 1440
46#define Y411_LINE_SZ 1080
47#define NTSC_FIELD_HEIGHT 240
48#define NTSC_ODD_FLD_LINES 241
49#define PAL_FIELD_HEIGHT 288
50
51#define FRAME_SIZE_NTSC_Y422 (NTSC_LINES_PER_FRAME * Y422_LINE_SZ)
52#define FRAME_SIZE_NTSC_Y411 (NTSC_LINES_PER_FRAME * Y411_LINE_SZ)
53#define FRAME_SIZE_PAL_Y422 (PAL_LINES_PER_FRAME * Y422_LINE_SZ)
54#define FRAME_SIZE_PAL_Y411 (PAL_LINES_PER_FRAME * Y411_LINE_SZ)
55
56#define NTSC_DATA_BUF_SZ (Y422_LINE_SZ * NTSC_LINES_PER_FRAME)
57#define PAL_DATA_BUF_SZ (Y422_LINE_SZ * PAL_LINES_PER_FRAME)
58
59#define RISC_WRITECR_INSTRUCTION_SIZE 16
60#define RISC_SYNC_INSTRUCTION_SIZE 4
61#define JUMP_INSTRUCTION_SIZE 12
62#define MAXSIZE_NO_OPS 36
63#define DWORD_SIZE 4
64
65#define USE_RISC_NOOP_VIDEO 1
66
67#ifdef USE_RISC_NOOP_VIDEO
68#define PAL_US_VID_PROG_SIZE \
69 (PAL_FIELD_HEIGHT * 3 * DWORD_SIZE + \
70 RISC_WRITECR_INSTRUCTION_SIZE + RISC_SYNC_INSTRUCTION_SIZE + \
71 NUM_NO_OPS * DWORD_SIZE)
72
73#define PAL_RISC_BUF_SIZE (2 * PAL_US_VID_PROG_SIZE)
74
75#define PAL_VID_PROG_SIZE \
76 ((PAL_FIELD_HEIGHT * 2) * 3 * DWORD_SIZE + \
77 2 * RISC_SYNC_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \
78 JUMP_INSTRUCTION_SIZE + 2 * NUM_NO_OPS * DWORD_SIZE)
79
80#define ODD_FLD_PAL_PROG_SIZE \
81 (PAL_FIELD_HEIGHT * 3 * DWORD_SIZE + \
82 RISC_SYNC_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \
83 NUM_NO_OPS * DWORD_SIZE)
84
85#define NTSC_US_VID_PROG_SIZE \
86 ((NTSC_ODD_FLD_LINES + 1) * 3 * DWORD_SIZE + \
87 RISC_WRITECR_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE + \
88 NUM_NO_OPS * DWORD_SIZE)
89
90#define NTSC_RISC_BUF_SIZE \
91 (2 * (RISC_SYNC_INSTRUCTION_SIZE + NTSC_US_VID_PROG_SIZE))
92
93#define FRAME1_VID_PROG_SIZE \
94 ((NTSC_ODD_FLD_LINES + NTSC_FIELD_HEIGHT) * \
95 3 * DWORD_SIZE + 2 * RISC_SYNC_INSTRUCTION_SIZE + \
96 RISC_WRITECR_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE + \
97 2 * NUM_NO_OPS * DWORD_SIZE)
98
99#define ODD_FLD_NTSC_PROG_SIZE \
100 (NTSC_ODD_FLD_LINES * 3 * DWORD_SIZE + \
101 RISC_SYNC_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \
102 NUM_NO_OPS * DWORD_SIZE)
103#endif
104
105#ifndef USE_RISC_NOOP_VIDEO
106#define PAL_US_VID_PROG_SIZE \
107 ((PAL_FIELD_HEIGHT + 1) * 3 * DWORD_SIZE + \
108 RISC_WRITECR_INSTRUCTION_SIZE)
109
110#define PAL_RISC_BUF_SIZE \
111 (2 * (RISC_SYNC_INSTRUCTION_SIZE + PAL_US_VID_PROG_SIZE))
112
113#define PAL_VID_PROG_SIZE \
114 ((PAL_FIELD_HEIGHT * 2) * 3 * DWORD_SIZE + \
115 2 * RISC_SYNC_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE + \
116 JUMP_INSTRUCTION_SIZE)
117
118#define ODD_FLD_PAL_PROG_SIZE \
119 (PAL_FIELD_HEIGHT * 3 * DWORD_SIZE + \
120 RISC_SYNC_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE)
121
122#define ODD_FLD_NTSC_PROG_SIZE \
123 (NTSC_ODD_FLD_LINES * 3 * DWORD_SIZE + \
124 RISC_SYNC_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE)
125
126#define NTSC_US_VID_PROG_SIZE \
127 ((NTSC_ODD_FLD_LINES + 1) * 3 * DWORD_SIZE + \
128 RISC_WRITECR_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE)
129
130#define NTSC_RISC_BUF_SIZE \
131 (2 * (RISC_SYNC_INSTRUCTION_SIZE + NTSC_US_VID_PROG_SIZE))
132
133#define FRAME1_VID_PROG_SIZE \
134 ((NTSC_ODD_FLD_LINES + NTSC_FIELD_HEIGHT) * \
135 3 * DWORD_SIZE + 2 * RISC_SYNC_INSTRUCTION_SIZE + \
136 RISC_WRITECR_INSTRUCTION_SIZE + JUMP_INSTRUCTION_SIZE)
137
138#endif
diff --git a/drivers/media/pci/cx25821/cx25821-video-upstream.c b/drivers/media/pci/cx25821/cx25821-video-upstream.c
index 7fc97110d973..88ffef410c50 100644
--- a/drivers/media/pci/cx25821/cx25821-video-upstream.c
+++ b/drivers/media/pci/cx25821/cx25821-video-upstream.c
@@ -25,16 +25,11 @@
25#include "cx25821-video.h" 25#include "cx25821-video.h"
26#include "cx25821-video-upstream.h" 26#include "cx25821-video-upstream.h"
27 27
28#include <linux/fs.h>
29#include <linux/errno.h> 28#include <linux/errno.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/syscalls.h>
34#include <linux/file.h>
35#include <linux/fcntl.h>
36#include <linux/slab.h> 32#include <linux/slab.h>
37#include <linux/uaccess.h>
38 33
39MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); 34MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
40MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); 35MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
@@ -44,7 +39,7 @@ static int _intr_msk = FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC |
44 FLD_VID_SRC_OPC_ERR; 39 FLD_VID_SRC_OPC_ERR;
45 40
46int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev, 41int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
47 struct sram_channel *ch, 42 const struct sram_channel *ch,
48 unsigned int bpl, u32 risc) 43 unsigned int bpl, u32 risc)
49{ 44{
50 unsigned int i, lines; 45 unsigned int i, lines;
@@ -97,12 +92,13 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
97 return 0; 92 return 0;
98} 93}
99 94
100static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev, 95static __le32 *cx25821_update_riscprogram(struct cx25821_channel *chan,
101 __le32 *rp, unsigned int offset, 96 __le32 *rp, unsigned int offset,
102 unsigned int bpl, u32 sync_line, 97 unsigned int bpl, u32 sync_line,
103 unsigned int lines, int fifo_enable, 98 unsigned int lines, int fifo_enable,
104 int field_type) 99 int field_type)
105{ 100{
101 struct cx25821_video_out_data *out = chan->out;
106 unsigned int line, i; 102 unsigned int line, i;
107 int dist_betwn_starts = bpl * 2; 103 int dist_betwn_starts = bpl * 2;
108 104
@@ -116,11 +112,11 @@ static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev,
116 /* scan lines */ 112 /* scan lines */
117 for (line = 0; line < lines; line++) { 113 for (line = 0; line < lines; line++) {
118 *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); 114 *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl);
119 *(rp++) = cpu_to_le32(dev->_data_buf_phys_addr + offset); 115 *(rp++) = cpu_to_le32(out->_data_buf_phys_addr + offset);
120 *(rp++) = cpu_to_le32(0); /* bits 63-32 */ 116 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
121 117
122 if ((lines <= NTSC_FIELD_HEIGHT) 118 if ((lines <= NTSC_FIELD_HEIGHT)
123 || (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC)) { 119 || (line < (NTSC_FIELD_HEIGHT - 1)) || !(out->is_60hz)) {
124 offset += dist_betwn_starts; 120 offset += dist_betwn_starts;
125 } 121 }
126 } 122 }
@@ -128,15 +124,15 @@ static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev,
128 return rp; 124 return rp;
129} 125}
130 126
131static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp, 127static __le32 *cx25821_risc_field_upstream(struct cx25821_channel *chan, __le32 *rp,
132 dma_addr_t databuf_phys_addr, 128 dma_addr_t databuf_phys_addr,
133 unsigned int offset, u32 sync_line, 129 unsigned int offset, u32 sync_line,
134 unsigned int bpl, unsigned int lines, 130 unsigned int bpl, unsigned int lines,
135 int fifo_enable, int field_type) 131 int fifo_enable, int field_type)
136{ 132{
133 struct cx25821_video_out_data *out = chan->out;
137 unsigned int line, i; 134 unsigned int line, i;
138 struct sram_channel *sram_ch = 135 const struct sram_channel *sram_ch = chan->sram_channels;
139 dev->channels[dev->_channel_upstream_select].sram_channels;
140 int dist_betwn_starts = bpl * 2; 136 int dist_betwn_starts = bpl * 2;
141 137
142 /* sync instruction */ 138 /* sync instruction */
@@ -155,7 +151,7 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
155 *(rp++) = cpu_to_le32(0); /* bits 63-32 */ 151 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
156 152
157 if ((lines <= NTSC_FIELD_HEIGHT) 153 if ((lines <= NTSC_FIELD_HEIGHT)
158 || (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC)) 154 || (line < (NTSC_FIELD_HEIGHT - 1)) || !(out->is_60hz))
159 /* to skip the other field line */ 155 /* to skip the other field line */
160 offset += dist_betwn_starts; 156 offset += dist_betwn_starts;
161 157
@@ -173,11 +169,12 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
173 return rp; 169 return rp;
174} 170}
175 171
176static int cx25821_risc_buffer_upstream(struct cx25821_dev *dev, 172static int cx25821_risc_buffer_upstream(struct cx25821_channel *chan,
177 struct pci_dev *pci, 173 struct pci_dev *pci,
178 unsigned int top_offset, 174 unsigned int top_offset,
179 unsigned int bpl, unsigned int lines) 175 unsigned int bpl, unsigned int lines)
180{ 176{
177 struct cx25821_video_out_data *out = chan->out;
181 __le32 *rp; 178 __le32 *rp;
182 int fifo_enable = 0; 179 int fifo_enable = 0;
183 /* get line count for single field */ 180 /* get line count for single field */
@@ -191,7 +188,7 @@ static int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
191 unsigned int bottom_offset = bpl; 188 unsigned int bottom_offset = bpl;
192 dma_addr_t risc_phys_jump_addr; 189 dma_addr_t risc_phys_jump_addr;
193 190
194 if (dev->_isNTSC) { 191 if (out->is_60hz) {
195 odd_num_lines = singlefield_lines + 1; 192 odd_num_lines = singlefield_lines + 1;
196 risc_program_size = FRAME1_VID_PROG_SIZE; 193 risc_program_size = FRAME1_VID_PROG_SIZE;
197 frame_size = (bpl == Y411_LINE_SZ) ? 194 frame_size = (bpl == Y411_LINE_SZ) ?
@@ -203,15 +200,15 @@ static int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
203 } 200 }
204 201
205 /* Virtual address of Risc buffer program */ 202 /* Virtual address of Risc buffer program */
206 rp = dev->_dma_virt_addr; 203 rp = out->_dma_virt_addr;
207 204
208 for (frame = 0; frame < NUM_FRAMES; frame++) { 205 for (frame = 0; frame < NUM_FRAMES; frame++) {
209 databuf_offset = frame_size * frame; 206 databuf_offset = frame_size * frame;
210 207
211 if (UNSET != top_offset) { 208 if (UNSET != top_offset) {
212 fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE; 209 fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE;
213 rp = cx25821_risc_field_upstream(dev, rp, 210 rp = cx25821_risc_field_upstream(chan, rp,
214 dev->_data_buf_phys_addr + 211 out->_data_buf_phys_addr +
215 databuf_offset, top_offset, 0, bpl, 212 databuf_offset, top_offset, 0, bpl,
216 odd_num_lines, fifo_enable, ODD_FIELD); 213 odd_num_lines, fifo_enable, ODD_FIELD);
217 } 214 }
@@ -219,18 +216,18 @@ static int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
219 fifo_enable = FIFO_DISABLE; 216 fifo_enable = FIFO_DISABLE;
220 217
221 /* Even Field */ 218 /* Even Field */
222 rp = cx25821_risc_field_upstream(dev, rp, 219 rp = cx25821_risc_field_upstream(chan, rp,
223 dev->_data_buf_phys_addr + 220 out->_data_buf_phys_addr +
224 databuf_offset, bottom_offset, 221 databuf_offset, bottom_offset,
225 0x200, bpl, singlefield_lines, 222 0x200, bpl, singlefield_lines,
226 fifo_enable, EVEN_FIELD); 223 fifo_enable, EVEN_FIELD);
227 224
228 if (frame == 0) { 225 if (frame == 0) {
229 risc_flag = RISC_CNT_RESET; 226 risc_flag = RISC_CNT_RESET;
230 risc_phys_jump_addr = dev->_dma_phys_start_addr + 227 risc_phys_jump_addr = out->_dma_phys_start_addr +
231 risc_program_size; 228 risc_program_size;
232 } else { 229 } else {
233 risc_phys_jump_addr = dev->_dma_phys_start_addr; 230 risc_phys_jump_addr = out->_dma_phys_start_addr;
234 risc_flag = RISC_CNT_INC; 231 risc_flag = RISC_CNT_INC;
235 } 232 }
236 233
@@ -245,16 +242,21 @@ static int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
245 return 0; 242 return 0;
246} 243}
247 244
248void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev) 245void cx25821_stop_upstream_video(struct cx25821_channel *chan)
249{ 246{
250 struct sram_channel *sram_ch = 247 struct cx25821_video_out_data *out = chan->out;
251 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_I].sram_channels; 248 struct cx25821_dev *dev = chan->dev;
249 const struct sram_channel *sram_ch = chan->sram_channels;
252 u32 tmp = 0; 250 u32 tmp = 0;
253 251
254 if (!dev->_is_running) { 252 if (!out->_is_running) {
255 pr_info("No video file is currently running so return!\n"); 253 pr_info("No video file is currently running so return!\n");
256 return; 254 return;
257 } 255 }
256
257 /* Set the interrupt mask register, disable irq. */
258 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) & ~(1 << sram_ch->irq_bit));
259
258 /* Disable RISC interrupts */ 260 /* Disable RISC interrupts */
259 tmp = cx_read(sram_ch->int_msk); 261 tmp = cx_read(sram_ch->int_msk);
260 cx_write(sram_ch->int_msk, tmp & ~_intr_msk); 262 cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
@@ -263,283 +265,133 @@ void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
263 tmp = cx_read(sram_ch->dma_ctl); 265 tmp = cx_read(sram_ch->dma_ctl);
264 cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN)); 266 cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN));
265 267
266 /* Clear data buffer memory */ 268 free_irq(dev->pci->irq, chan);
267 if (dev->_data_buf_virt_addr)
268 memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size);
269 269
270 dev->_is_running = 0; 270 /* Clear data buffer memory */
271 dev->_is_first_frame = 0; 271 if (out->_data_buf_virt_addr)
272 dev->_frame_count = 0; 272 memset(out->_data_buf_virt_addr, 0, out->_data_buf_size);
273 dev->_file_status = END_OF_FILE;
274
275 kfree(dev->_irq_queues);
276 dev->_irq_queues = NULL;
277 273
278 kfree(dev->_filename); 274 out->_is_running = 0;
275 out->_is_first_frame = 0;
276 out->_frame_count = 0;
277 out->_file_status = END_OF_FILE;
279 278
280 tmp = cx_read(VID_CH_MODE_SEL); 279 tmp = cx_read(VID_CH_MODE_SEL);
281 cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); 280 cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
282} 281}
283 282
284void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev) 283void cx25821_free_mem_upstream(struct cx25821_channel *chan)
285{ 284{
286 if (dev->_is_running) 285 struct cx25821_video_out_data *out = chan->out;
287 cx25821_stop_upstream_video_ch1(dev); 286 struct cx25821_dev *dev = chan->dev;
288 287
289 if (dev->_dma_virt_addr) { 288 if (out->_is_running)
290 pci_free_consistent(dev->pci, dev->_risc_size, 289 cx25821_stop_upstream_video(chan);
291 dev->_dma_virt_addr, dev->_dma_phys_addr); 290
292 dev->_dma_virt_addr = NULL; 291 if (out->_dma_virt_addr) {
292 pci_free_consistent(dev->pci, out->_risc_size,
293 out->_dma_virt_addr, out->_dma_phys_addr);
294 out->_dma_virt_addr = NULL;
293 } 295 }
294 296
295 if (dev->_data_buf_virt_addr) { 297 if (out->_data_buf_virt_addr) {
296 pci_free_consistent(dev->pci, dev->_data_buf_size, 298 pci_free_consistent(dev->pci, out->_data_buf_size,
297 dev->_data_buf_virt_addr, 299 out->_data_buf_virt_addr,
298 dev->_data_buf_phys_addr); 300 out->_data_buf_phys_addr);
299 dev->_data_buf_virt_addr = NULL; 301 out->_data_buf_virt_addr = NULL;
300 } 302 }
301} 303}
302 304
303static int cx25821_get_frame(struct cx25821_dev *dev, 305int cx25821_write_frame(struct cx25821_channel *chan,
304 struct sram_channel *sram_ch) 306 const char __user *data, size_t count)
305{ 307{
306 struct file *myfile; 308 struct cx25821_video_out_data *out = chan->out;
307 int frame_index_temp = dev->_frame_index; 309 int line_size = (out->_pixel_format == PIXEL_FRMT_411) ?
308 int i = 0;
309 int line_size = (dev->_pixel_format == PIXEL_FRMT_411) ?
310 Y411_LINE_SZ : Y422_LINE_SZ; 310 Y411_LINE_SZ : Y422_LINE_SZ;
311 int frame_size = 0; 311 int frame_size = 0;
312 int frame_offset = 0; 312 int frame_offset = 0;
313 ssize_t vfs_read_retval = 0; 313 int curpos = out->curpos;
314 char mybuf[line_size];
315 loff_t file_offset;
316 loff_t pos;
317 mm_segment_t old_fs;
318
319 if (dev->_file_status == END_OF_FILE)
320 return 0;
321 314
322 if (dev->_isNTSC) 315 if (out->is_60hz)
323 frame_size = (line_size == Y411_LINE_SZ) ? 316 frame_size = (line_size == Y411_LINE_SZ) ?
324 FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; 317 FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422;
325 else 318 else
326 frame_size = (line_size == Y411_LINE_SZ) ? 319 frame_size = (line_size == Y411_LINE_SZ) ?
327 FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; 320 FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422;
328 321
329 frame_offset = (frame_index_temp > 0) ? frame_size : 0; 322 if (curpos == 0) {
330 file_offset = dev->_frame_count * frame_size; 323 out->cur_frame_index = out->_frame_index;
331 324 if (wait_event_interruptible(out->waitq, out->cur_frame_index != out->_frame_index))
332 myfile = filp_open(dev->_filename, O_RDONLY | O_LARGEFILE, 0); 325 return -EINTR;
333 326 out->cur_frame_index = out->_frame_index;
334 if (IS_ERR(myfile)) {
335 const int open_errno = -PTR_ERR(myfile);
336 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
337 __func__, dev->_filename, open_errno);
338 return PTR_ERR(myfile);
339 } else {
340 if (!(myfile->f_op)) {
341 pr_err("%s(): File has no file operations registered!\n",
342 __func__);
343 filp_close(myfile, NULL);
344 return -EIO;
345 }
346
347 if (!myfile->f_op->read) {
348 pr_err("%s(): File has no READ operations registered!\n",
349 __func__);
350 filp_close(myfile, NULL);
351 return -EIO;
352 }
353
354 pos = myfile->f_pos;
355 old_fs = get_fs();
356 set_fs(KERNEL_DS);
357
358 for (i = 0; i < dev->_lines_count; i++) {
359 pos = file_offset;
360
361 vfs_read_retval = vfs_read(myfile, mybuf, line_size,
362 &pos);
363
364 if (vfs_read_retval > 0 && vfs_read_retval == line_size
365 && dev->_data_buf_virt_addr != NULL) {
366 memcpy((void *)(dev->_data_buf_virt_addr +
367 frame_offset / 4), mybuf,
368 vfs_read_retval);
369 }
370
371 file_offset += vfs_read_retval;
372 frame_offset += vfs_read_retval;
373
374 if (vfs_read_retval < line_size) {
375 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
376 __func__);
377 break;
378 }
379 }
380
381 if (i > 0)
382 dev->_frame_count++;
383
384 dev->_file_status = (vfs_read_retval == line_size) ?
385 IN_PROGRESS : END_OF_FILE;
386
387 set_fs(old_fs);
388 filp_close(myfile, NULL);
389 }
390
391 return 0;
392}
393
394static void cx25821_vidups_handler(struct work_struct *work)
395{
396 struct cx25821_dev *dev = container_of(work, struct cx25821_dev,
397 _irq_work_entry);
398
399 if (!dev) {
400 pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
401 __func__);
402 return;
403 } 327 }
404 328
405 cx25821_get_frame(dev, dev->channels[dev->_channel_upstream_select]. 329 frame_offset = out->cur_frame_index ? frame_size : 0;
406 sram_channels);
407}
408
409static int cx25821_openfile(struct cx25821_dev *dev,
410 struct sram_channel *sram_ch)
411{
412 struct file *myfile;
413 int i = 0, j = 0;
414 int line_size = (dev->_pixel_format == PIXEL_FRMT_411) ?
415 Y411_LINE_SZ : Y422_LINE_SZ;
416 ssize_t vfs_read_retval = 0;
417 char mybuf[line_size];
418 loff_t pos;
419 loff_t offset = (unsigned long)0;
420 mm_segment_t old_fs;
421
422 myfile = filp_open(dev->_filename, O_RDONLY | O_LARGEFILE, 0);
423
424 if (IS_ERR(myfile)) {
425 const int open_errno = -PTR_ERR(myfile);
426 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
427 __func__, dev->_filename, open_errno);
428 return PTR_ERR(myfile);
429 } else {
430 if (!(myfile->f_op)) {
431 pr_err("%s(): File has no file operations registered!\n",
432 __func__);
433 filp_close(myfile, NULL);
434 return -EIO;
435 }
436
437 if (!myfile->f_op->read) {
438 pr_err("%s(): File has no READ operations registered! Returning\n",
439 __func__);
440 filp_close(myfile, NULL);
441 return -EIO;
442 }
443
444 pos = myfile->f_pos;
445 old_fs = get_fs();
446 set_fs(KERNEL_DS);
447
448 for (j = 0; j < NUM_FRAMES; j++) {
449 for (i = 0; i < dev->_lines_count; i++) {
450 pos = offset;
451
452 vfs_read_retval = vfs_read(myfile, mybuf,
453 line_size, &pos);
454
455 if (vfs_read_retval > 0
456 && vfs_read_retval == line_size
457 && dev->_data_buf_virt_addr != NULL) {
458 memcpy((void *)(dev->
459 _data_buf_virt_addr +
460 offset / 4), mybuf,
461 vfs_read_retval);
462 }
463
464 offset += vfs_read_retval;
465
466 if (vfs_read_retval < line_size) {
467 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
468 __func__);
469 break;
470 }
471 }
472 330
473 if (i > 0) 331 if (frame_size - curpos < count)
474 dev->_frame_count++; 332 count = frame_size - curpos;
475 333 memcpy((char *)out->_data_buf_virt_addr + frame_offset + curpos,
476 if (vfs_read_retval < line_size) 334 data, count);
477 break; 335 curpos += count;
478 } 336 if (curpos == frame_size) {
479 337 out->_frame_count++;
480 dev->_file_status = (vfs_read_retval == line_size) ? 338 curpos = 0;
481 IN_PROGRESS : END_OF_FILE;
482
483 set_fs(old_fs);
484 myfile->f_pos = 0;
485 filp_close(myfile, NULL);
486 } 339 }
340 out->curpos = curpos;
487 341
488 return 0; 342 return count;
489} 343}
490 344
491static int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev, 345static int cx25821_upstream_buffer_prepare(struct cx25821_channel *chan,
492 struct sram_channel *sram_ch, 346 const struct sram_channel *sram_ch,
493 int bpl) 347 int bpl)
494{ 348{
349 struct cx25821_video_out_data *out = chan->out;
350 struct cx25821_dev *dev = chan->dev;
495 int ret = 0; 351 int ret = 0;
496 dma_addr_t dma_addr; 352 dma_addr_t dma_addr;
497 dma_addr_t data_dma_addr; 353 dma_addr_t data_dma_addr;
498 354
499 if (dev->_dma_virt_addr != NULL) 355 if (out->_dma_virt_addr != NULL)
500 pci_free_consistent(dev->pci, dev->upstream_riscbuf_size, 356 pci_free_consistent(dev->pci, out->upstream_riscbuf_size,
501 dev->_dma_virt_addr, dev->_dma_phys_addr); 357 out->_dma_virt_addr, out->_dma_phys_addr);
502 358
503 dev->_dma_virt_addr = pci_alloc_consistent(dev->pci, 359 out->_dma_virt_addr = pci_alloc_consistent(dev->pci,
504 dev->upstream_riscbuf_size, &dma_addr); 360 out->upstream_riscbuf_size, &dma_addr);
505 dev->_dma_virt_start_addr = dev->_dma_virt_addr; 361 out->_dma_virt_start_addr = out->_dma_virt_addr;
506 dev->_dma_phys_start_addr = dma_addr; 362 out->_dma_phys_start_addr = dma_addr;
507 dev->_dma_phys_addr = dma_addr; 363 out->_dma_phys_addr = dma_addr;
508 dev->_risc_size = dev->upstream_riscbuf_size; 364 out->_risc_size = out->upstream_riscbuf_size;
509 365
510 if (!dev->_dma_virt_addr) { 366 if (!out->_dma_virt_addr) {
511 pr_err("FAILED to allocate memory for Risc buffer! Returning\n"); 367 pr_err("FAILED to allocate memory for Risc buffer! Returning\n");
512 return -ENOMEM; 368 return -ENOMEM;
513 } 369 }
514 370
515 /* Clear memory at address */ 371 /* Clear memory at address */
516 memset(dev->_dma_virt_addr, 0, dev->_risc_size); 372 memset(out->_dma_virt_addr, 0, out->_risc_size);
517 373
518 if (dev->_data_buf_virt_addr != NULL) 374 if (out->_data_buf_virt_addr != NULL)
519 pci_free_consistent(dev->pci, dev->upstream_databuf_size, 375 pci_free_consistent(dev->pci, out->upstream_databuf_size,
520 dev->_data_buf_virt_addr, 376 out->_data_buf_virt_addr,
521 dev->_data_buf_phys_addr); 377 out->_data_buf_phys_addr);
522 /* For Video Data buffer allocation */ 378 /* For Video Data buffer allocation */
523 dev->_data_buf_virt_addr = pci_alloc_consistent(dev->pci, 379 out->_data_buf_virt_addr = pci_alloc_consistent(dev->pci,
524 dev->upstream_databuf_size, &data_dma_addr); 380 out->upstream_databuf_size, &data_dma_addr);
525 dev->_data_buf_phys_addr = data_dma_addr; 381 out->_data_buf_phys_addr = data_dma_addr;
526 dev->_data_buf_size = dev->upstream_databuf_size; 382 out->_data_buf_size = out->upstream_databuf_size;
527 383
528 if (!dev->_data_buf_virt_addr) { 384 if (!out->_data_buf_virt_addr) {
529 pr_err("FAILED to allocate memory for data buffer! Returning\n"); 385 pr_err("FAILED to allocate memory for data buffer! Returning\n");
530 return -ENOMEM; 386 return -ENOMEM;
531 } 387 }
532 388
533 /* Clear memory at address */ 389 /* Clear memory at address */
534 memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size); 390 memset(out->_data_buf_virt_addr, 0, out->_data_buf_size);
535
536 ret = cx25821_openfile(dev, sram_ch);
537 if (ret < 0)
538 return ret;
539 391
540 /* Create RISC programs */ 392 /* Create RISC programs */
541 ret = cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl, 393 ret = cx25821_risc_buffer_upstream(chan, dev->pci, 0, bpl,
542 dev->_lines_count); 394 out->_lines_count);
543 if (ret < 0) { 395 if (ret < 0) {
544 pr_info("Failed creating Video Upstream Risc programs!\n"); 396 pr_info("Failed creating Video Upstream Risc programs!\n");
545 goto error; 397 goto error;
@@ -551,11 +403,12 @@ error:
551 return ret; 403 return ret;
552} 404}
553 405
554static int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num, 406static int cx25821_video_upstream_irq(struct cx25821_channel *chan, u32 status)
555 u32 status)
556{ 407{
408 struct cx25821_video_out_data *out = chan->out;
409 struct cx25821_dev *dev = chan->dev;
557 u32 int_msk_tmp; 410 u32 int_msk_tmp;
558 struct sram_channel *channel = dev->channels[chan_num].sram_channels; 411 const struct sram_channel *channel = chan->sram_channels;
559 int singlefield_lines = NTSC_FIELD_HEIGHT; 412 int singlefield_lines = NTSC_FIELD_HEIGHT;
560 int line_size_in_bytes = Y422_LINE_SZ; 413 int line_size_in_bytes = Y422_LINE_SZ;
561 int odd_risc_prog_size = 0; 414 int odd_risc_prog_size = 0;
@@ -572,16 +425,16 @@ static int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
572 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk); 425 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
573 cx_write(channel->int_stat, _intr_msk); 426 cx_write(channel->int_stat, _intr_msk);
574 427
575 spin_lock(&dev->slock); 428 wake_up(&out->waitq);
576 429
577 dev->_frame_index = prog_cnt; 430 spin_lock(&dev->slock);
578 431
579 queue_work(dev->_irq_queues, &dev->_irq_work_entry); 432 out->_frame_index = prog_cnt;
580 433
581 if (dev->_is_first_frame) { 434 if (out->_is_first_frame) {
582 dev->_is_first_frame = 0; 435 out->_is_first_frame = 0;
583 436
584 if (dev->_isNTSC) { 437 if (out->is_60hz) {
585 singlefield_lines += 1; 438 singlefield_lines += 1;
586 odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE; 439 odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE;
587 } else { 440 } else {
@@ -589,17 +442,17 @@ static int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
589 odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE; 442 odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE;
590 } 443 }
591 444
592 if (dev->_dma_virt_start_addr != NULL) { 445 if (out->_dma_virt_start_addr != NULL) {
593 line_size_in_bytes = 446 line_size_in_bytes =
594 (dev->_pixel_format == 447 (out->_pixel_format ==
595 PIXEL_FRMT_411) ? Y411_LINE_SZ : 448 PIXEL_FRMT_411) ? Y411_LINE_SZ :
596 Y422_LINE_SZ; 449 Y422_LINE_SZ;
597 risc_phys_jump_addr = 450 risc_phys_jump_addr =
598 dev->_dma_phys_start_addr + 451 out->_dma_phys_start_addr +
599 odd_risc_prog_size; 452 odd_risc_prog_size;
600 453
601 rp = cx25821_update_riscprogram(dev, 454 rp = cx25821_update_riscprogram(chan,
602 dev->_dma_virt_start_addr, TOP_OFFSET, 455 out->_dma_virt_start_addr, TOP_OFFSET,
603 line_size_in_bytes, 0x0, 456 line_size_in_bytes, 0x0,
604 singlefield_lines, FIFO_DISABLE, 457 singlefield_lines, FIFO_DISABLE,
605 ODD_FIELD); 458 ODD_FIELD);
@@ -626,8 +479,8 @@ static int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
626 __func__); 479 __func__);
627 } 480 }
628 481
629 if (dev->_file_status == END_OF_FILE) { 482 if (out->_file_status == END_OF_FILE) {
630 pr_err("EOF Channel 1 Framecount = %d\n", dev->_frame_count); 483 pr_err("EOF Channel 1 Framecount = %d\n", out->_frame_count);
631 return -1; 484 return -1;
632 } 485 }
633 /* ElSE, set the interrupt mask register, re-enable irq. */ 486 /* ElSE, set the interrupt mask register, re-enable irq. */
@@ -639,47 +492,41 @@ static int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
639 492
640static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id) 493static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
641{ 494{
642 struct cx25821_dev *dev = dev_id; 495 struct cx25821_channel *chan = dev_id;
496 struct cx25821_dev *dev = chan->dev;
643 u32 vid_status; 497 u32 vid_status;
644 int handled = 0; 498 int handled = 0;
645 int channel_num = 0; 499 const struct sram_channel *sram_ch;
646 struct sram_channel *sram_ch;
647 500
648 if (!dev) 501 if (!dev)
649 return -1; 502 return -1;
650 503
651 channel_num = VID_UPSTREAM_SRAM_CHANNEL_I; 504 sram_ch = chan->sram_channels;
652
653 sram_ch = dev->channels[channel_num].sram_channels;
654 505
655 vid_status = cx_read(sram_ch->int_stat); 506 vid_status = cx_read(sram_ch->int_stat);
656 507
657 /* Only deal with our interrupt */ 508 /* Only deal with our interrupt */
658 if (vid_status) 509 if (vid_status)
659 handled = cx25821_video_upstream_irq(dev, channel_num, 510 handled = cx25821_video_upstream_irq(chan, vid_status);
660 vid_status);
661
662 if (handled < 0)
663 cx25821_stop_upstream_video_ch1(dev);
664 else
665 handled += handled;
666 511
667 return IRQ_RETVAL(handled); 512 return IRQ_RETVAL(handled);
668} 513}
669 514
670static void cx25821_set_pixelengine(struct cx25821_dev *dev, 515static void cx25821_set_pixelengine(struct cx25821_channel *chan,
671 struct sram_channel *ch, 516 const struct sram_channel *ch,
672 int pix_format) 517 int pix_format)
673{ 518{
519 struct cx25821_video_out_data *out = chan->out;
520 struct cx25821_dev *dev = chan->dev;
674 int width = WIDTH_D1; 521 int width = WIDTH_D1;
675 int height = dev->_lines_count; 522 int height = out->_lines_count;
676 int num_lines, odd_num_lines; 523 int num_lines, odd_num_lines;
677 u32 value; 524 u32 value;
678 int vip_mode = OUTPUT_FRMT_656; 525 int vip_mode = OUTPUT_FRMT_656;
679 526
680 value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7); 527 value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7);
681 value &= 0xFFFFFFEF; 528 value &= 0xFFFFFFEF;
682 value |= dev->_isNTSC ? 0 : 0x10; 529 value |= out->is_60hz ? 0 : 0x10;
683 cx_write(ch->vid_fmt_ctl, value); 530 cx_write(ch->vid_fmt_ctl, value);
684 531
685 /* set number of active pixels in each line. 532 /* set number of active pixels in each line.
@@ -689,7 +536,7 @@ static void cx25821_set_pixelengine(struct cx25821_dev *dev,
689 num_lines = (height / 2) & 0x3FF; 536 num_lines = (height / 2) & 0x3FF;
690 odd_num_lines = num_lines; 537 odd_num_lines = num_lines;
691 538
692 if (dev->_isNTSC) 539 if (out->is_60hz)
693 odd_num_lines += 1; 540 odd_num_lines += 1;
694 541
695 value = (num_lines << 16) | odd_num_lines; 542 value = (num_lines << 16) | odd_num_lines;
@@ -700,9 +547,11 @@ static void cx25821_set_pixelengine(struct cx25821_dev *dev,
700 cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3); 547 cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3);
701} 548}
702 549
703static int cx25821_start_video_dma_upstream(struct cx25821_dev *dev, 550static int cx25821_start_video_dma_upstream(struct cx25821_channel *chan,
704 struct sram_channel *sram_ch) 551 const struct sram_channel *sram_ch)
705{ 552{
553 struct cx25821_video_out_data *out = chan->out;
554 struct cx25821_dev *dev = chan->dev;
706 u32 tmp = 0; 555 u32 tmp = 0;
707 int err = 0; 556 int err = 0;
708 557
@@ -715,7 +564,7 @@ static int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
715 /* Set the physical start address of the RISC program in the initial 564 /* Set the physical start address of the RISC program in the initial
716 * program counter(IPC) member of the cmds. 565 * program counter(IPC) member of the cmds.
717 */ 566 */
718 cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr); 567 cx_write(sram_ch->cmds_start + 0, out->_dma_phys_addr);
719 /* Risc IPC High 64 bits 63-32 */ 568 /* Risc IPC High 64 bits 63-32 */
720 cx_write(sram_ch->cmds_start + 4, 0); 569 cx_write(sram_ch->cmds_start + 4, 0);
721 570
@@ -731,7 +580,7 @@ static int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
731 cx_write(sram_ch->int_msk, tmp |= _intr_msk); 580 cx_write(sram_ch->int_msk, tmp |= _intr_msk);
732 581
733 err = request_irq(dev->pci->irq, cx25821_upstream_irq, 582 err = request_irq(dev->pci->irq, cx25821_upstream_irq,
734 IRQF_SHARED, dev->name, dev); 583 IRQF_SHARED, dev->name, chan);
735 if (err < 0) { 584 if (err < 0) {
736 pr_err("%s: can't get upstream IRQ %d\n", 585 pr_err("%s: can't get upstream IRQ %d\n",
737 dev->name, dev->pci->irq); 586 dev->name, dev->pci->irq);
@@ -742,8 +591,8 @@ static int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
742 tmp = cx_read(sram_ch->dma_ctl); 591 tmp = cx_read(sram_ch->dma_ctl);
743 cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN); 592 cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
744 593
745 dev->_is_running = 1; 594 out->_is_running = 1;
746 dev->_is_first_frame = 1; 595 out->_is_first_frame = 1;
747 596
748 return 0; 597 return 0;
749 598
@@ -752,107 +601,71 @@ fail_irq:
752 return err; 601 return err;
753} 602}
754 603
755int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select, 604int cx25821_vidupstream_init(struct cx25821_channel *chan,
756 int pixel_format) 605 int pixel_format)
757{ 606{
758 struct sram_channel *sram_ch; 607 struct cx25821_video_out_data *out = chan->out;
608 struct cx25821_dev *dev = chan->dev;
609 const struct sram_channel *sram_ch;
759 u32 tmp; 610 u32 tmp;
760 int err = 0; 611 int err = 0;
761 int data_frame_size = 0; 612 int data_frame_size = 0;
762 int risc_buffer_size = 0; 613 int risc_buffer_size = 0;
763 int str_length = 0;
764 614
765 if (dev->_is_running) { 615 if (out->_is_running) {
766 pr_info("Video Channel is still running so return!\n"); 616 pr_info("Video Channel is still running so return!\n");
767 return 0; 617 return 0;
768 } 618 }
769 619
770 dev->_channel_upstream_select = channel_select; 620 sram_ch = chan->sram_channels;
771 sram_ch = dev->channels[channel_select].sram_channels;
772 621
773 INIT_WORK(&dev->_irq_work_entry, cx25821_vidups_handler); 622 out->is_60hz = dev->tvnorm & V4L2_STD_525_60;
774 dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue");
775 623
776 if (!dev->_irq_queues) {
777 pr_err("create_singlethread_workqueue() for Video FAILED!\n");
778 return -ENOMEM;
779 }
780 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for 624 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
781 * channel A-C 625 * channel A-C
782 */ 626 */
783 tmp = cx_read(VID_CH_MODE_SEL); 627 tmp = cx_read(VID_CH_MODE_SEL);
784 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); 628 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
785 629
786 dev->_is_running = 0; 630 out->_is_running = 0;
787 dev->_frame_count = 0; 631 out->_frame_count = 0;
788 dev->_file_status = RESET_STATUS; 632 out->_file_status = RESET_STATUS;
789 dev->_lines_count = dev->_isNTSC ? 480 : 576; 633 out->_lines_count = out->is_60hz ? 480 : 576;
790 dev->_pixel_format = pixel_format; 634 out->_pixel_format = pixel_format;
791 dev->_line_size = (dev->_pixel_format == PIXEL_FRMT_422) ? 635 out->_line_size = (out->_pixel_format == PIXEL_FRMT_422) ?
792 (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; 636 (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2;
793 data_frame_size = dev->_isNTSC ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ; 637 data_frame_size = out->is_60hz ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ;
794 risc_buffer_size = dev->_isNTSC ? 638 risc_buffer_size = out->is_60hz ?
795 NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE; 639 NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE;
796 640
797 if (dev->input_filename) { 641 out->_is_running = 0;
798 str_length = strlen(dev->input_filename); 642 out->_frame_count = 0;
799 dev->_filename = kmemdup(dev->input_filename, str_length + 1, 643 out->_file_status = RESET_STATUS;
800 GFP_KERNEL); 644 out->_lines_count = out->is_60hz ? 480 : 576;
801 645 out->_pixel_format = pixel_format;
802 if (!dev->_filename) { 646 out->_line_size = (out->_pixel_format == PIXEL_FRMT_422) ?
803 err = -ENOENT;
804 goto error;
805 }
806 } else {
807 str_length = strlen(dev->_defaultname);
808 dev->_filename = kmemdup(dev->_defaultname, str_length + 1,
809 GFP_KERNEL);
810
811 if (!dev->_filename) {
812 err = -ENOENT;
813 goto error;
814 }
815 }
816
817 /* Default if filename is empty string */
818 if (strcmp(dev->_filename, "") == 0) {
819 if (dev->_isNTSC) {
820 dev->_filename =
821 (dev->_pixel_format == PIXEL_FRMT_411) ?
822 "/root/vid411.yuv" : "/root/vidtest.yuv";
823 } else {
824 dev->_filename =
825 (dev->_pixel_format == PIXEL_FRMT_411) ?
826 "/root/pal411.yuv" : "/root/pal422.yuv";
827 }
828 }
829
830 dev->_is_running = 0;
831 dev->_frame_count = 0;
832 dev->_file_status = RESET_STATUS;
833 dev->_lines_count = dev->_isNTSC ? 480 : 576;
834 dev->_pixel_format = pixel_format;
835 dev->_line_size = (dev->_pixel_format == PIXEL_FRMT_422) ?
836 (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; 647 (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2;
648 out->curpos = 0;
649 init_waitqueue_head(&out->waitq);
837 650
838 err = cx25821_sram_channel_setup_upstream(dev, sram_ch, 651 err = cx25821_sram_channel_setup_upstream(dev, sram_ch,
839 dev->_line_size, 0); 652 out->_line_size, 0);
840 653
841 /* setup fifo + format */ 654 /* setup fifo + format */
842 cx25821_set_pixelengine(dev, sram_ch, dev->_pixel_format); 655 cx25821_set_pixelengine(chan, sram_ch, out->_pixel_format);
843 656
844 dev->upstream_riscbuf_size = risc_buffer_size * 2; 657 out->upstream_riscbuf_size = risc_buffer_size * 2;
845 dev->upstream_databuf_size = data_frame_size * 2; 658 out->upstream_databuf_size = data_frame_size * 2;
846 659
847 /* Allocating buffers and prepare RISC program */ 660 /* Allocating buffers and prepare RISC program */
848 err = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size); 661 err = cx25821_upstream_buffer_prepare(chan, sram_ch, out->_line_size);
849 if (err < 0) { 662 if (err < 0) {
850 pr_err("%s: Failed to set up Video upstream buffers!\n", 663 pr_err("%s: Failed to set up Video upstream buffers!\n",
851 dev->name); 664 dev->name);
852 goto error; 665 goto error;
853 } 666 }
854 667
855 cx25821_start_video_dma_upstream(dev, sram_ch); 668 cx25821_start_video_dma_upstream(chan, sram_ch);
856 669
857 return 0; 670 return 0;
858 671
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index 31ce7698acb9..d270819fd875 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -33,13 +33,10 @@ MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
33MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
34 34
35static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET }; 35static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
36static unsigned int radio_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
37 36
38module_param_array(video_nr, int, NULL, 0444); 37module_param_array(video_nr, int, NULL, 0444);
39module_param_array(radio_nr, int, NULL, 0444);
40 38
41MODULE_PARM_DESC(video_nr, "video device numbers"); 39MODULE_PARM_DESC(video_nr, "video device numbers");
42MODULE_PARM_DESC(radio_nr, "radio device numbers");
43 40
44static unsigned int video_debug = VIDEO_DEBUG; 41static unsigned int video_debug = VIDEO_DEBUG;
45module_param(video_debug, int, 0644); 42module_param(video_debug, int, 0644);
@@ -49,24 +46,14 @@ static unsigned int irq_debug;
49module_param(irq_debug, int, 0644); 46module_param(irq_debug, int, 0644);
50MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]"); 47MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
51 48
52unsigned int vid_limit = 16; 49static unsigned int vid_limit = 16;
53module_param(vid_limit, int, 0644); 50module_param(vid_limit, int, 0644);
54MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); 51MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
55 52
56static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num);
57
58static const struct v4l2_file_operations video_fops;
59static const struct v4l2_ioctl_ops video_ioctl_ops;
60
61#define FORMAT_FLAGS_PACKED 0x01 53#define FORMAT_FLAGS_PACKED 0x01
62 54
63struct cx25821_fmt formats[] = { 55static const struct cx25821_fmt formats[] = {
64 { 56 {
65 .name = "8 bpp, gray",
66 .fourcc = V4L2_PIX_FMT_GREY,
67 .depth = 8,
68 .flags = FORMAT_FLAGS_PACKED,
69 }, {
70 .name = "4:1:1, packed, Y41P", 57 .name = "4:1:1, packed, Y41P",
71 .fourcc = V4L2_PIX_FMT_Y41P, 58 .fourcc = V4L2_PIX_FMT_Y41P,
72 .depth = 12, 59 .depth = 12,
@@ -76,36 +63,16 @@ struct cx25821_fmt formats[] = {
76 .fourcc = V4L2_PIX_FMT_YUYV, 63 .fourcc = V4L2_PIX_FMT_YUYV,
77 .depth = 16, 64 .depth = 16,
78 .flags = FORMAT_FLAGS_PACKED, 65 .flags = FORMAT_FLAGS_PACKED,
79 }, {
80 .name = "4:2:2, packed, UYVY",
81 .fourcc = V4L2_PIX_FMT_UYVY,
82 .depth = 16,
83 .flags = FORMAT_FLAGS_PACKED,
84 }, {
85 .name = "4:2:0, YUV",
86 .fourcc = V4L2_PIX_FMT_YUV420,
87 .depth = 12,
88 .flags = FORMAT_FLAGS_PACKED,
89 }, 66 },
90}; 67};
91 68
92int cx25821_get_format_size(void) 69static const struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
93{
94 return ARRAY_SIZE(formats);
95}
96
97struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
98{ 70{
99 unsigned int i; 71 unsigned int i;
100 72
101 if (fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P)
102 return formats + 1;
103
104 for (i = 0; i < ARRAY_SIZE(formats); i++) 73 for (i = 0; i < ARRAY_SIZE(formats); i++)
105 if (formats[i].fourcc == fourcc) 74 if (formats[i].fourcc == fourcc)
106 return formats + i; 75 return formats + i;
107
108 pr_err("%s(0x%08x) NOT FOUND\n", __func__, fourcc);
109 return NULL; 76 return NULL;
110} 77}
111 78
@@ -144,129 +111,10 @@ void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
144 pr_err("%s: %d buffers handled (should be 1)\n", __func__, bc); 111 pr_err("%s: %d buffers handled (should be 1)\n", __func__, bc);
145} 112}
146 113
147#ifdef TUNER_FLAG
148int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm)
149{
150 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
151 __func__, (unsigned int)norm, v4l2_norm_to_name(norm));
152
153 dev->tvnorm = norm;
154
155 /* Tell the internal A/V decoder */
156 cx25821_call_all(dev, core, s_std, norm);
157
158 return 0;
159}
160#endif
161
162struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
163 struct pci_dev *pci,
164 struct video_device *template,
165 char *type)
166{
167 struct video_device *vfd;
168 dprintk(1, "%s()\n", __func__);
169
170 vfd = video_device_alloc();
171 if (NULL == vfd)
172 return NULL;
173 *vfd = *template;
174 vfd->v4l2_dev = &dev->v4l2_dev;
175 vfd->release = video_device_release;
176 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, type,
177 cx25821_boards[dev->board].name);
178 video_set_drvdata(vfd, dev);
179 return vfd;
180}
181
182/*
183static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
184{
185 int i;
186
187 if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1)
188 return -EINVAL;
189 for (i = 0; i < CX25821_CTLS; i++)
190 if (cx25821_ctls[i].v.id == qctrl->id)
191 break;
192 if (i == CX25821_CTLS) {
193 *qctrl = no_ctl;
194 return 0;
195 }
196 *qctrl = cx25821_ctls[i].v;
197 return 0;
198}
199*/
200
201/* resource management */
202int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh,
203 unsigned int bit)
204{
205 dprintk(1, "%s()\n", __func__);
206 if (fh->resources & bit)
207 /* have it already allocated */
208 return 1;
209
210 /* is it free? */
211 mutex_lock(&dev->lock);
212 if (dev->channels[fh->channel_id].resources & bit) {
213 /* no, someone else uses it */
214 mutex_unlock(&dev->lock);
215 return 0;
216 }
217 /* it's free, grab it */
218 fh->resources |= bit;
219 dev->channels[fh->channel_id].resources |= bit;
220 dprintk(1, "res: get %d\n", bit);
221 mutex_unlock(&dev->lock);
222 return 1;
223}
224
225int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit)
226{
227 return fh->resources & bit;
228}
229
230int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit)
231{
232 return fh->dev->channels[fh->channel_id].resources & bit;
233}
234
235void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh,
236 unsigned int bits)
237{
238 BUG_ON((fh->resources & bits) != bits);
239 dprintk(1, "%s()\n", __func__);
240
241 mutex_lock(&dev->lock);
242 fh->resources &= ~bits;
243 dev->channels[fh->channel_id].resources &= ~bits;
244 dprintk(1, "res: put %d\n", bits);
245 mutex_unlock(&dev->lock);
246}
247
248int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input)
249{
250 struct v4l2_routing route;
251 memset(&route, 0, sizeof(route));
252
253 dprintk(1, "%s(): video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
254 __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0,
255 INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3);
256 dev->input = input;
257
258 route.input = INPUT(input)->vmux;
259
260 /* Tell the internal A/V decoder */
261 cx25821_call_all(dev, video, s_routing, INPUT(input)->vmux, 0, 0);
262
263 return 0;
264}
265
266int cx25821_start_video_dma(struct cx25821_dev *dev, 114int cx25821_start_video_dma(struct cx25821_dev *dev,
267 struct cx25821_dmaqueue *q, 115 struct cx25821_dmaqueue *q,
268 struct cx25821_buffer *buf, 116 struct cx25821_buffer *buf,
269 struct sram_channel *channel) 117 const struct sram_channel *channel)
270{ 118{
271 int tmp = 0; 119 int tmp = 0;
272 120
@@ -293,7 +141,7 @@ int cx25821_start_video_dma(struct cx25821_dev *dev,
293 141
294static int cx25821_restart_video_queue(struct cx25821_dev *dev, 142static int cx25821_restart_video_queue(struct cx25821_dev *dev,
295 struct cx25821_dmaqueue *q, 143 struct cx25821_dmaqueue *q,
296 struct sram_channel *channel) 144 const struct sram_channel *channel)
297{ 145{
298 struct cx25821_buffer *buf, *prev; 146 struct cx25821_buffer *buf, *prev;
299 struct list_head *item; 147 struct list_head *item;
@@ -346,8 +194,8 @@ static void cx25821_vid_timeout(unsigned long data)
346{ 194{
347 struct cx25821_data *timeout_data = (struct cx25821_data *)data; 195 struct cx25821_data *timeout_data = (struct cx25821_data *)data;
348 struct cx25821_dev *dev = timeout_data->dev; 196 struct cx25821_dev *dev = timeout_data->dev;
349 struct sram_channel *channel = timeout_data->channel; 197 const struct sram_channel *channel = timeout_data->channel;
350 struct cx25821_dmaqueue *q = &dev->channels[channel->i].vidq; 198 struct cx25821_dmaqueue *q = &dev->channels[channel->i].dma_vidq;
351 struct cx25821_buffer *buf; 199 struct cx25821_buffer *buf;
352 unsigned long flags; 200 unsigned long flags;
353 201
@@ -373,7 +221,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
373 u32 count = 0; 221 u32 count = 0;
374 int handled = 0; 222 int handled = 0;
375 u32 mask; 223 u32 mask;
376 struct sram_channel *channel = dev->channels[chan_num].sram_channels; 224 const struct sram_channel *channel = dev->channels[chan_num].sram_channels;
377 225
378 mask = cx_read(channel->int_msk); 226 mask = cx_read(channel->int_msk);
379 if (0 == (status & mask)) 227 if (0 == (status & mask))
@@ -393,7 +241,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
393 if (status & FLD_VID_DST_RISC1) { 241 if (status & FLD_VID_DST_RISC1) {
394 spin_lock(&dev->slock); 242 spin_lock(&dev->slock);
395 count = cx_read(channel->gpcnt); 243 count = cx_read(channel->gpcnt);
396 cx25821_video_wakeup(dev, &dev->channels[channel->i].vidq, 244 cx25821_video_wakeup(dev, &dev->channels[channel->i].dma_vidq,
397 count); 245 count);
398 spin_unlock(&dev->slock); 246 spin_unlock(&dev->slock);
399 handled++; 247 handled++;
@@ -404,122 +252,19 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
404 dprintk(2, "stopper video\n"); 252 dprintk(2, "stopper video\n");
405 spin_lock(&dev->slock); 253 spin_lock(&dev->slock);
406 cx25821_restart_video_queue(dev, 254 cx25821_restart_video_queue(dev,
407 &dev->channels[channel->i].vidq, channel); 255 &dev->channels[channel->i].dma_vidq, channel);
408 spin_unlock(&dev->slock); 256 spin_unlock(&dev->slock);
409 handled++; 257 handled++;
410 } 258 }
411 return handled; 259 return handled;
412} 260}
413 261
414void cx25821_videoioctl_unregister(struct cx25821_dev *dev) 262static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
415{
416 if (dev->ioctl_dev) {
417 if (video_is_registered(dev->ioctl_dev))
418 video_unregister_device(dev->ioctl_dev);
419 else
420 video_device_release(dev->ioctl_dev);
421
422 dev->ioctl_dev = NULL;
423 }
424}
425
426void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
427{
428 cx_clear(PCI_INT_MSK, 1);
429
430 if (dev->channels[chan_num].video_dev) {
431 if (video_is_registered(dev->channels[chan_num].video_dev))
432 video_unregister_device(
433 dev->channels[chan_num].video_dev);
434 else
435 video_device_release(
436 dev->channels[chan_num].video_dev);
437
438 dev->channels[chan_num].video_dev = NULL;
439
440 btcx_riscmem_free(dev->pci,
441 &dev->channels[chan_num].vidq.stopper);
442
443 pr_warn("device %d released!\n", chan_num);
444 }
445
446}
447
448int cx25821_video_register(struct cx25821_dev *dev)
449{
450 int err;
451 int i;
452
453 struct video_device cx25821_video_device = {
454 .name = "cx25821-video",
455 .fops = &video_fops,
456 .minor = -1,
457 .ioctl_ops = &video_ioctl_ops,
458 .tvnorms = CX25821_NORMS,
459 .current_norm = V4L2_STD_NTSC_M,
460 };
461
462 spin_lock_init(&dev->slock);
463
464 for (i = 0; i < VID_CHANNEL_NUM; ++i) {
465 cx25821_init_controls(dev, i);
466
467 cx25821_risc_stopper(dev->pci, &dev->channels[i].vidq.stopper,
468 dev->channels[i].sram_channels->dma_ctl, 0x11, 0);
469
470 dev->channels[i].sram_channels = &cx25821_sram_channels[i];
471 dev->channels[i].video_dev = NULL;
472 dev->channels[i].resources = 0;
473
474 cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff);
475
476 INIT_LIST_HEAD(&dev->channels[i].vidq.active);
477 INIT_LIST_HEAD(&dev->channels[i].vidq.queued);
478
479 dev->channels[i].timeout_data.dev = dev;
480 dev->channels[i].timeout_data.channel =
481 &cx25821_sram_channels[i];
482 dev->channels[i].vidq.timeout.function = cx25821_vid_timeout;
483 dev->channels[i].vidq.timeout.data =
484 (unsigned long)&dev->channels[i].timeout_data;
485 init_timer(&dev->channels[i].vidq.timeout);
486
487 /* register v4l devices */
488 dev->channels[i].video_dev = cx25821_vdev_init(dev, dev->pci,
489 &cx25821_video_device, "video");
490
491 err = video_register_device(dev->channels[i].video_dev,
492 VFL_TYPE_GRABBER, video_nr[dev->nr]);
493
494 if (err < 0)
495 goto fail_unreg;
496
497 }
498
499 /* set PCI interrupt */
500 cx_set(PCI_INT_MSK, 0xff);
501
502 /* initial device configuration */
503 mutex_lock(&dev->lock);
504#ifdef TUNER_FLAG
505 dev->tvnorm = cx25821_video_device.current_norm;
506 cx25821_set_tvnorm(dev, dev->tvnorm);
507#endif
508 mutex_unlock(&dev->lock);
509
510 return 0;
511
512fail_unreg:
513 cx25821_video_unregister(dev, i);
514 return err;
515}
516
517int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
518 unsigned int *size) 263 unsigned int *size)
519{ 264{
520 struct cx25821_fh *fh = q->priv_data; 265 struct cx25821_channel *chan = q->priv_data;
521 266
522 *size = fh->fmt->depth * fh->width * fh->height >> 3; 267 *size = chan->fmt->depth * chan->width * chan->height >> 3;
523 268
524 if (0 == *count) 269 if (0 == *count)
525 *count = 32; 270 *count = 32;
@@ -530,35 +275,34 @@ int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
530 return 0; 275 return 0;
531} 276}
532 277
533int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, 278static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
534 enum v4l2_field field) 279 enum v4l2_field field)
535{ 280{
536 struct cx25821_fh *fh = q->priv_data; 281 struct cx25821_channel *chan = q->priv_data;
537 struct cx25821_dev *dev = fh->dev; 282 struct cx25821_dev *dev = chan->dev;
538 struct cx25821_buffer *buf = 283 struct cx25821_buffer *buf =
539 container_of(vb, struct cx25821_buffer, vb); 284 container_of(vb, struct cx25821_buffer, vb);
540 int rc, init_buffer = 0; 285 int rc, init_buffer = 0;
541 u32 line0_offset; 286 u32 line0_offset;
542 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); 287 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
543 int bpl_local = LINE_SIZE_D1; 288 int bpl_local = LINE_SIZE_D1;
544 int channel_opened = fh->channel_id;
545 289
546 BUG_ON(NULL == fh->fmt); 290 BUG_ON(NULL == chan->fmt);
547 if (fh->width < 48 || fh->width > 720 || 291 if (chan->width < 48 || chan->width > 720 ||
548 fh->height < 32 || fh->height > 576) 292 chan->height < 32 || chan->height > 576)
549 return -EINVAL; 293 return -EINVAL;
550 294
551 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; 295 buf->vb.size = (chan->width * chan->height * chan->fmt->depth) >> 3;
552 296
553 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 297 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
554 return -EINVAL; 298 return -EINVAL;
555 299
556 if (buf->fmt != fh->fmt || 300 if (buf->fmt != chan->fmt ||
557 buf->vb.width != fh->width || 301 buf->vb.width != chan->width ||
558 buf->vb.height != fh->height || buf->vb.field != field) { 302 buf->vb.height != chan->height || buf->vb.field != field) {
559 buf->fmt = fh->fmt; 303 buf->fmt = chan->fmt;
560 buf->vb.width = fh->width; 304 buf->vb.width = chan->width;
561 buf->vb.height = fh->height; 305 buf->vb.height = chan->height;
562 buf->vb.field = field; 306 buf->vb.field = field;
563 init_buffer = 1; 307 init_buffer = 1;
564 } 308 }
@@ -575,34 +319,21 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
575 dprintk(1, "init_buffer=%d\n", init_buffer); 319 dprintk(1, "init_buffer=%d\n", init_buffer);
576 320
577 if (init_buffer) { 321 if (init_buffer) {
578 322 if (chan->pixel_formats == PIXEL_FRMT_411)
579 channel_opened = dev->channel_opened;
580 if (channel_opened < 0 || channel_opened > 7)
581 channel_opened = 7;
582
583 if (dev->channels[channel_opened].pixel_formats ==
584 PIXEL_FRMT_411)
585 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; 323 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
586 else 324 else
587 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); 325 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
588 326
589 if (dev->channels[channel_opened].pixel_formats == 327 if (chan->pixel_formats == PIXEL_FRMT_411) {
590 PIXEL_FRMT_411) {
591 bpl_local = buf->bpl; 328 bpl_local = buf->bpl;
592 } else { 329 } else {
593 bpl_local = buf->bpl; /* Default */ 330 bpl_local = buf->bpl; /* Default */
594 331
595 if (channel_opened >= 0 && channel_opened <= 7) { 332 if (chan->use_cif_resolution) {
596 if (dev->channels[channel_opened] 333 if (dev->tvnorm & V4L2_STD_625_50)
597 .use_cif_resolution) { 334 bpl_local = 352 << 1;
598 if (dev->tvnorm & V4L2_STD_PAL_BG || 335 else
599 dev->tvnorm & V4L2_STD_PAL_DK) 336 bpl_local = chan->cif_width << 1;
600 bpl_local = 352 << 1;
601 else
602 bpl_local = dev->channels[
603 channel_opened].
604 cif_width << 1;
605 }
606 } 337 }
607 } 338 }
608 339
@@ -645,8 +376,8 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
645 } 376 }
646 377
647 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", 378 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
648 buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, 379 buf, buf->vb.i, chan->width, chan->height, chan->fmt->depth,
649 fh->fmt->name, (unsigned long)buf->risc.dma); 380 chan->fmt->name, (unsigned long)buf->risc.dma);
650 381
651 buf->vb.state = VIDEOBUF_PREPARED; 382 buf->vb.state = VIDEOBUF_PREPARED;
652 383
@@ -657,7 +388,7 @@ fail:
657 return rc; 388 return rc;
658} 389}
659 390
660void cx25821_buffer_release(struct videobuf_queue *q, 391static void cx25821_buffer_release(struct videobuf_queue *q,
661 struct videobuf_buffer *vb) 392 struct videobuf_buffer *vb)
662{ 393{
663 struct cx25821_buffer *buf = 394 struct cx25821_buffer *buf =
@@ -666,33 +397,11 @@ void cx25821_buffer_release(struct videobuf_queue *q,
666 cx25821_free_buffer(q, buf); 397 cx25821_free_buffer(q, buf);
667} 398}
668 399
669struct videobuf_queue *get_queue(struct cx25821_fh *fh) 400static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
670{ 401{
671 switch (fh->type) { 402 struct cx25821_channel *chan = video_drvdata(file);
672 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
673 return &fh->vidq;
674 default:
675 BUG();
676 return NULL;
677 }
678}
679 403
680int cx25821_get_resource(struct cx25821_fh *fh, int resource) 404 return videobuf_mmap_mapper(&chan->vidq, vma);
681{
682 switch (fh->type) {
683 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
684 return resource;
685 default:
686 BUG();
687 return 0;
688 }
689}
690
691int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
692{
693 struct cx25821_fh *fh = file->private_data;
694
695 return videobuf_mmap_mapper(get_queue(fh), vma);
696} 405}
697 406
698 407
@@ -701,9 +410,9 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
701 struct cx25821_buffer *buf = 410 struct cx25821_buffer *buf =
702 container_of(vb, struct cx25821_buffer, vb); 411 container_of(vb, struct cx25821_buffer, vb);
703 struct cx25821_buffer *prev; 412 struct cx25821_buffer *prev;
704 struct cx25821_fh *fh = vq->priv_data; 413 struct cx25821_channel *chan = vq->priv_data;
705 struct cx25821_dev *dev = fh->dev; 414 struct cx25821_dev *dev = chan->dev;
706 struct cx25821_dmaqueue *q = &dev->channels[fh->channel_id].vidq; 415 struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq;
707 416
708 /* add jump to stopper */ 417 /* add jump to stopper */
709 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); 418 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
@@ -720,8 +429,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
720 429
721 } else if (list_empty(&q->active)) { 430 } else if (list_empty(&q->active)) {
722 list_add_tail(&buf->vb.queue, &q->active); 431 list_add_tail(&buf->vb.queue, &q->active);
723 cx25821_start_video_dma(dev, q, buf, 432 cx25821_start_video_dma(dev, q, buf, chan->sram_channels);
724 dev->channels[fh->channel_id].sram_channels);
725 buf->vb.state = VIDEOBUF_ACTIVE; 433 buf->vb.state = VIDEOBUF_ACTIVE;
726 buf->count = q->count++; 434 buf->count = q->count++;
727 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); 435 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
@@ -762,1183 +470,487 @@ static struct videobuf_queue_ops cx25821_video_qops = {
762 .buf_release = cx25821_buffer_release, 470 .buf_release = cx25821_buffer_release,
763}; 471};
764 472
765static int video_open(struct file *file)
766{
767 struct video_device *vdev = video_devdata(file);
768 struct cx25821_dev *h, *dev = video_drvdata(file);
769 struct cx25821_fh *fh;
770 struct list_head *list;
771 int minor = video_devdata(file)->minor;
772 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
773 u32 pix_format;
774 int ch_id = 0;
775 int i;
776
777 dprintk(1, "open dev=%s type=%s\n", video_device_node_name(vdev),
778 v4l2_type_names[type]);
779
780 /* allocate + initialize per filehandle data */
781 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
782 if (NULL == fh)
783 return -ENOMEM;
784
785 mutex_lock(&cx25821_devlist_mutex);
786
787 list_for_each(list, &cx25821_devlist)
788 {
789 h = list_entry(list, struct cx25821_dev, devlist);
790
791 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) {
792 if (h->channels[i].video_dev &&
793 h->channels[i].video_dev->minor == minor) {
794 dev = h;
795 ch_id = i;
796 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
797 }
798 }
799 }
800
801 if (NULL == dev) {
802 mutex_unlock(&cx25821_devlist_mutex);
803 kfree(fh);
804 return -ENODEV;
805 }
806
807 file->private_data = fh;
808 fh->dev = dev;
809 fh->type = type;
810 fh->width = 720;
811 fh->channel_id = ch_id;
812
813 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
814 fh->height = 576;
815 else
816 fh->height = 480;
817
818 dev->channel_opened = fh->channel_id;
819 if (dev->channels[ch_id].pixel_formats == PIXEL_FRMT_411)
820 pix_format = V4L2_PIX_FMT_Y41P;
821 else
822 pix_format = V4L2_PIX_FMT_YUYV;
823 fh->fmt = cx25821_format_by_fourcc(pix_format);
824
825 v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio);
826
827 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, &dev->pci->dev,
828 &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
829 V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer),
830 fh, NULL);
831
832 dprintk(1, "post videobuf_queue_init()\n");
833 mutex_unlock(&cx25821_devlist_mutex);
834
835 return 0;
836}
837
838static ssize_t video_read(struct file *file, char __user * data, size_t count, 473static ssize_t video_read(struct file *file, char __user * data, size_t count,
839 loff_t *ppos) 474 loff_t *ppos)
840{ 475{
841 struct cx25821_fh *fh = file->private_data; 476 struct v4l2_fh *fh = file->private_data;
842 477 struct cx25821_channel *chan = video_drvdata(file);
843 switch (fh->type) { 478 struct cx25821_dev *dev = chan->dev;
844 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 479 int err = 0;
845 if (cx25821_res_locked(fh, RESOURCE_VIDEO0))
846 return -EBUSY;
847 480
848 return videobuf_read_one(&fh->vidq, data, count, ppos, 481 if (mutex_lock_interruptible(&dev->lock))
849 file->f_flags & O_NONBLOCK); 482 return -ERESTARTSYS;
850 483 if (chan->streaming_fh && chan->streaming_fh != fh) {
851 default: 484 err = -EBUSY;
852 BUG(); 485 goto unlock;
853 return 0;
854 } 486 }
487 chan->streaming_fh = fh;
488
489 err = videobuf_read_one(&chan->vidq, data, count, ppos,
490 file->f_flags & O_NONBLOCK);
491unlock:
492 mutex_unlock(&dev->lock);
493 return err;
855} 494}
856 495
857static unsigned int video_poll(struct file *file, 496static unsigned int video_poll(struct file *file,
858 struct poll_table_struct *wait) 497 struct poll_table_struct *wait)
859{ 498{
860 struct cx25821_fh *fh = file->private_data; 499 struct cx25821_channel *chan = video_drvdata(file);
861 struct cx25821_buffer *buf; 500 unsigned long req_events = poll_requested_events(wait);
862 501 unsigned int res = v4l2_ctrl_poll(file, wait);
863 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { 502
864 /* streaming capture */ 503 if (req_events & (POLLIN | POLLRDNORM))
865 if (list_empty(&fh->vidq.stream)) 504 res |= videobuf_poll_stream(file, &chan->vidq, wait);
866 return POLLERR; 505 return res;
867 buf = list_entry(fh->vidq.stream.next, 506
868 struct cx25821_buffer, vb.stream); 507 /* This doesn't belong in poll(). This can be done
869 } else { 508 * much better with vb2. We keep this code here as a
870 /* read() capture */ 509 * reminder.
871 buf = (struct cx25821_buffer *)fh->vidq.read_buf; 510 if ((res & POLLIN) && buf->vb.state == VIDEOBUF_DONE) {
872 if (NULL == buf) 511 struct cx25821_dev *dev = chan->dev;
873 return POLLERR; 512
874 } 513 if (dev && chan->use_cif_resolution) {
875 514 u8 cam_id = *((char *)buf->vb.baddr + 3);
876 poll_wait(file, &buf->vb.done, wait); 515 memcpy((char *)buf->vb.baddr,
877 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) { 516 (char *)buf->vb.baddr + (chan->width * 2),
878 if (buf->vb.state == VIDEOBUF_DONE) { 517 (chan->width * 2));
879 struct cx25821_dev *dev = fh->dev; 518 *((char *)buf->vb.baddr + 3) = cam_id;
880
881 if (dev && dev->channels[fh->channel_id]
882 .use_cif_resolution) {
883 u8 cam_id = *((char *)buf->vb.baddr + 3);
884 memcpy((char *)buf->vb.baddr,
885 (char *)buf->vb.baddr + (fh->width * 2),
886 (fh->width * 2));
887 *((char *)buf->vb.baddr + 3) = cam_id;
888 }
889 } 519 }
890
891 return POLLIN | POLLRDNORM;
892 } 520 }
893 521 */
894 return 0;
895} 522}
896 523
897static int video_release(struct file *file) 524static int video_release(struct file *file)
898{ 525{
899 struct cx25821_fh *fh = file->private_data; 526 struct cx25821_channel *chan = video_drvdata(file);
900 struct cx25821_dev *dev = fh->dev; 527 struct v4l2_fh *fh = file->private_data;
528 struct cx25821_dev *dev = chan->dev;
529 const struct sram_channel *sram_ch =
530 dev->channels[0].sram_channels;
901 531
532 mutex_lock(&dev->lock);
902 /* stop the risc engine and fifo */ 533 /* stop the risc engine and fifo */
903 cx_write(channel0->dma_ctl, 0); /* FIFO and RISC disable */ 534 cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */
904 535
905 /* stop video capture */ 536 /* stop video capture */
906 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { 537 if (chan->streaming_fh == fh) {
907 videobuf_queue_cancel(&fh->vidq); 538 videobuf_queue_cancel(&chan->vidq);
908 cx25821_res_free(dev, fh, RESOURCE_VIDEO0); 539 chan->streaming_fh = NULL;
909 } 540 }
910 541
911 if (fh->vidq.read_buf) { 542 if (chan->vidq.read_buf) {
912 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf); 543 cx25821_buffer_release(&chan->vidq, chan->vidq.read_buf);
913 kfree(fh->vidq.read_buf); 544 kfree(chan->vidq.read_buf);
914 } 545 }
915 546
916 videobuf_mmap_free(&fh->vidq); 547 videobuf_mmap_free(&chan->vidq);
917 548 mutex_unlock(&dev->lock);
918 v4l2_prio_close(&dev->channels[fh->channel_id].prio, fh->prio);
919 file->private_data = NULL;
920 kfree(fh);
921 549
922 return 0; 550 return v4l2_fh_release(file);
923} 551}
924 552
925static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 553/* VIDEO IOCTLS */
926{
927 struct cx25821_fh *fh = priv;
928 struct cx25821_dev *dev = fh->dev;
929 554
930 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) 555static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
556 struct v4l2_fmtdesc *f)
557{
558 if (unlikely(f->index >= ARRAY_SIZE(formats)))
931 return -EINVAL; 559 return -EINVAL;
932 560
933 if (unlikely(i != fh->type)) 561 strlcpy(f->description, formats[f->index].name, sizeof(f->description));
934 return -EINVAL; 562 f->pixelformat = formats[f->index].fourcc;
935 563
936 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, 564 return 0;
937 RESOURCE_VIDEO0)))) 565}
938 return -EBUSY; 566
567static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
568 struct v4l2_format *f)
569{
570 struct cx25821_channel *chan = video_drvdata(file);
571
572 f->fmt.pix.width = chan->width;
573 f->fmt.pix.height = chan->height;
574 f->fmt.pix.field = chan->vidq.field;
575 f->fmt.pix.pixelformat = chan->fmt->fourcc;
576 f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3;
577 f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline;
578 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
579 f->fmt.pix.priv = 0;
939 580
940 return videobuf_streamon(get_queue(fh)); 581 return 0;
941} 582}
942 583
943static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) 584static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
585 struct v4l2_format *f)
944{ 586{
945 struct cx25821_fh *fh = priv; 587 struct cx25821_channel *chan = video_drvdata(file);
946 struct cx25821_dev *dev = fh->dev; 588 struct cx25821_dev *dev = chan->dev;
947 int err, res; 589 const struct cx25821_fmt *fmt;
590 enum v4l2_field field = f->fmt.pix.field;
591 unsigned int maxh;
592 unsigned w;
948 593
949 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 594 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
950 return -EINVAL; 595 if (NULL == fmt)
951 if (i != fh->type)
952 return -EINVAL; 596 return -EINVAL;
597 maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
598
599 w = f->fmt.pix.width;
600 if (field != V4L2_FIELD_BOTTOM)
601 field = V4L2_FIELD_TOP;
602 if (w < 352) {
603 w = 176;
604 f->fmt.pix.height = maxh / 4;
605 } else if (w < 720) {
606 w = 352;
607 f->fmt.pix.height = maxh / 2;
608 } else {
609 w = 720;
610 f->fmt.pix.height = maxh;
611 field = V4L2_FIELD_INTERLACED;
612 }
613 f->fmt.pix.field = field;
614 f->fmt.pix.width = w;
615 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
616 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
617 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
618 f->fmt.pix.priv = 0;
953 619
954 res = cx25821_get_resource(fh, RESOURCE_VIDEO0);
955 err = videobuf_streamoff(get_queue(fh));
956 if (err < 0)
957 return err;
958 cx25821_res_free(dev, fh, res);
959 return 0; 620 return 0;
960} 621}
961 622
962static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 623static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
963 struct v4l2_format *f) 624 struct v4l2_format *f)
964{ 625{
965 struct cx25821_fh *fh = priv; 626 struct cx25821_channel *chan = video_drvdata(file);
966 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 627 struct cx25821_dev *dev = chan->dev;
967 struct v4l2_mbus_framefmt mbus_fmt;
968 int err;
969 int pix_format = PIXEL_FRMT_422; 628 int pix_format = PIXEL_FRMT_422;
629 int err;
970 630
971 if (fh) {
972 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio,
973 fh->prio);
974 if (0 != err)
975 return err;
976 }
977
978 dprintk(2, "%s()\n", __func__);
979 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); 631 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
980 632
981 if (0 != err) 633 if (0 != err)
982 return err; 634 return err;
983 635
984 fh->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); 636 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
985 fh->vidq.field = f->fmt.pix.field; 637 chan->vidq.field = f->fmt.pix.field;
986 638 chan->width = f->fmt.pix.width;
987 /* check if width and height is valid based on set standard */ 639 chan->height = f->fmt.pix.height;
988 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm))
989 fh->width = f->fmt.pix.width;
990
991 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm))
992 fh->height = f->fmt.pix.height;
993 640
994 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) 641 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
995 pix_format = PIXEL_FRMT_411; 642 pix_format = PIXEL_FRMT_411;
996 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
997 pix_format = PIXEL_FRMT_422;
998 else 643 else
999 return -EINVAL; 644 pix_format = PIXEL_FRMT_422;
1000 645
1001 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); 646 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
1002 647
1003 /* check if cif resolution */ 648 /* check if cif resolution */
1004 if (fh->width == 320 || fh->width == 352) 649 if (chan->width == 320 || chan->width == 352)
1005 dev->channels[fh->channel_id].use_cif_resolution = 1; 650 chan->use_cif_resolution = 1;
1006 else 651 else
1007 dev->channels[fh->channel_id].use_cif_resolution = 0; 652 chan->use_cif_resolution = 0;
1008
1009 dev->channels[fh->channel_id].cif_width = fh->width;
1010 medusa_set_resolution(dev, fh->width, SRAM_CH00);
1011
1012 dprintk(2, "%s(): width=%d height=%d field=%d\n", __func__, fh->width,
1013 fh->height, fh->vidq.field);
1014 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
1015 cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1016 653
654 chan->cif_width = chan->width;
655 medusa_set_resolution(dev, chan->width, SRAM_CH00);
1017 return 0; 656 return 0;
1018} 657}
1019 658
1020static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) 659static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1021{ 660{
1022 int ret_val = 0; 661 struct cx25821_channel *chan = video_drvdata(file);
1023 struct cx25821_fh *fh = priv;
1024 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1025 662
1026 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); 663 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
664 return -EINVAL;
1027 665
1028 p->sequence = dev->channels[fh->channel_id].vidq.count; 666 if (chan->streaming_fh && chan->streaming_fh != priv)
667 return -EBUSY;
668 chan->streaming_fh = priv;
1029 669
1030 return ret_val; 670 return videobuf_streamon(&chan->vidq);
1031} 671}
1032 672
1033static int vidioc_log_status(struct file *file, void *priv) 673static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1034{ 674{
1035 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 675 struct cx25821_channel *chan = video_drvdata(file);
1036 struct cx25821_fh *fh = priv;
1037 char name[32 + 2];
1038 676
1039 struct sram_channel *sram_ch = dev->channels[fh->channel_id] 677 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1040 .sram_channels; 678 return -EINVAL;
1041 u32 tmp = 0;
1042
1043 snprintf(name, sizeof(name), "%s/2", dev->name);
1044 pr_info("%s/2: ============ START LOG STATUS ============\n",
1045 dev->name);
1046 cx25821_call_all(dev, core, log_status);
1047 tmp = cx_read(sram_ch->dma_ctl);
1048 pr_info("Video input 0 is %s\n",
1049 (tmp & 0x11) ? "streaming" : "stopped");
1050 pr_info("%s/2: ============= END LOG STATUS =============\n",
1051 dev->name);
1052 return 0;
1053}
1054
1055static int vidioc_s_ctrl(struct file *file, void *priv,
1056 struct v4l2_control *ctl)
1057{
1058 struct cx25821_fh *fh = priv;
1059 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1060 int err;
1061 679
1062 if (fh) { 680 if (chan->streaming_fh && chan->streaming_fh != priv)
1063 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, 681 return -EBUSY;
1064 fh->prio); 682 if (chan->streaming_fh == NULL)
1065 if (0 != err) 683 return 0;
1066 return err;
1067 }
1068 684
1069 return cx25821_set_control(dev, ctl, fh->channel_id); 685 chan->streaming_fh = NULL;
686 return videobuf_streamoff(&chan->vidq);
1070} 687}
1071 688
1072/* VIDEO IOCTLS */ 689static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1073int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1074 struct v4l2_format *f)
1075{ 690{
1076 struct cx25821_fh *fh = priv; 691 int ret_val = 0;
692 struct cx25821_channel *chan = video_drvdata(file);
1077 693
1078 f->fmt.pix.width = fh->width; 694 ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK);
1079 f->fmt.pix.height = fh->height; 695 p->sequence = chan->dma_vidq.count;
1080 f->fmt.pix.field = fh->vidq.field;
1081 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1082 f->fmt.pix.bytesperline = (f->fmt.pix.width * fh->fmt->depth) >> 3;
1083 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
1084 696
1085 return 0; 697 return ret_val;
1086} 698}
1087 699
1088int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, 700static int vidioc_log_status(struct file *file, void *priv)
1089 struct v4l2_format *f)
1090{ 701{
1091 struct cx25821_fmt *fmt; 702 struct cx25821_channel *chan = video_drvdata(file);
1092 enum v4l2_field field; 703 struct cx25821_dev *dev = chan->dev;
1093 unsigned int maxw, maxh; 704 const struct sram_channel *sram_ch = chan->sram_channels;
1094 705 u32 tmp = 0;
1095 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
1096 if (NULL == fmt)
1097 return -EINVAL;
1098
1099 field = f->fmt.pix.field;
1100 maxw = 720;
1101 maxh = 576;
1102
1103 if (V4L2_FIELD_ANY == field) {
1104 if (f->fmt.pix.height > maxh / 2)
1105 field = V4L2_FIELD_INTERLACED;
1106 else
1107 field = V4L2_FIELD_TOP;
1108 }
1109
1110 switch (field) {
1111 case V4L2_FIELD_TOP:
1112 case V4L2_FIELD_BOTTOM:
1113 maxh = maxh / 2;
1114 break;
1115 case V4L2_FIELD_INTERLACED:
1116 break;
1117 default:
1118 return -EINVAL;
1119 }
1120
1121 f->fmt.pix.field = field;
1122 if (f->fmt.pix.height < 32)
1123 f->fmt.pix.height = 32;
1124 if (f->fmt.pix.height > maxh)
1125 f->fmt.pix.height = maxh;
1126 if (f->fmt.pix.width < 48)
1127 f->fmt.pix.width = 48;
1128 if (f->fmt.pix.width > maxw)
1129 f->fmt.pix.width = maxw;
1130 f->fmt.pix.width &= ~0x03;
1131 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
1132 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
1133 706
707 tmp = cx_read(sram_ch->dma_ctl);
708 pr_info("Video input 0 is %s\n",
709 (tmp & 0x11) ? "streaming" : "stopped");
1134 return 0; 710 return 0;
1135} 711}
1136 712
1137int cx25821_vidioc_querycap(struct file *file, void *priv, 713
714static int cx25821_vidioc_querycap(struct file *file, void *priv,
1138 struct v4l2_capability *cap) 715 struct v4l2_capability *cap)
1139{ 716{
1140 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 717 struct cx25821_channel *chan = video_drvdata(file);
718 struct cx25821_dev *dev = chan->dev;
719 const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE |
720 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
721 const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_READWRITE;
1141 722
1142 strcpy(cap->driver, "cx25821"); 723 strcpy(cap->driver, "cx25821");
1143 strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); 724 strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card));
1144 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); 725 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
1145 cap->version = CX25821_VERSION_CODE; 726 if (chan->id >= VID_CHANNEL_NUM)
1146 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 727 cap->device_caps = cap_output;
1147 V4L2_CAP_STREAMING; 728 else
1148 if (UNSET != dev->tuner_type) 729 cap->device_caps = cap_input;
1149 cap->capabilities |= V4L2_CAP_TUNER; 730 cap->capabilities = cap_input | cap_output | V4L2_CAP_DEVICE_CAPS;
1150 return 0;
1151}
1152
1153int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1154 struct v4l2_fmtdesc *f)
1155{
1156 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1157 return -EINVAL;
1158
1159 strlcpy(f->description, formats[f->index].name, sizeof(f->description));
1160 f->pixelformat = formats[f->index].fourcc;
1161
1162 return 0; 731 return 0;
1163} 732}
1164 733
1165int cx25821_vidioc_reqbufs(struct file *file, void *priv, 734static int cx25821_vidioc_reqbufs(struct file *file, void *priv,
1166 struct v4l2_requestbuffers *p) 735 struct v4l2_requestbuffers *p)
1167{ 736{
1168 struct cx25821_fh *fh = priv; 737 struct cx25821_channel *chan = video_drvdata(file);
1169 return videobuf_reqbufs(get_queue(fh), p); 738
739 return videobuf_reqbufs(&chan->vidq, p);
1170} 740}
1171 741
1172int cx25821_vidioc_querybuf(struct file *file, void *priv, 742static int cx25821_vidioc_querybuf(struct file *file, void *priv,
1173 struct v4l2_buffer *p) 743 struct v4l2_buffer *p)
1174{ 744{
1175 struct cx25821_fh *fh = priv; 745 struct cx25821_channel *chan = video_drvdata(file);
1176 return videobuf_querybuf(get_queue(fh), p);
1177}
1178 746
1179int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) 747 return videobuf_querybuf(&chan->vidq, p);
1180{
1181 struct cx25821_fh *fh = priv;
1182 return videobuf_qbuf(get_queue(fh), p);
1183} 748}
1184 749
1185int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p) 750static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1186{ 751{
1187 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; 752 struct cx25821_channel *chan = video_drvdata(file);
1188 struct cx25821_fh *fh = f;
1189 753
1190 *p = v4l2_prio_max(&dev->channels[fh->channel_id].prio); 754 return videobuf_qbuf(&chan->vidq, p);
1191
1192 return 0;
1193} 755}
1194 756
1195int cx25821_vidioc_s_priority(struct file *file, void *f, 757static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1196 enum v4l2_priority prio)
1197{ 758{
1198 struct cx25821_fh *fh = f; 759 struct cx25821_channel *chan = video_drvdata(file);
1199 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
1200 760
1201 return v4l2_prio_change(&dev->channels[fh->channel_id].prio, &fh->prio, 761 *tvnorms = chan->dev->tvnorm;
1202 prio); 762 return 0;
1203} 763}
1204 764
1205#ifdef TUNER_FLAG 765static int cx25821_vidioc_s_std(struct file *file, void *priv,
1206int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms) 766 v4l2_std_id tvnorms)
1207{ 767{
1208 struct cx25821_fh *fh = priv; 768 struct cx25821_channel *chan = video_drvdata(file);
1209 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 769 struct cx25821_dev *dev = chan->dev;
1210 int err;
1211
1212 dprintk(1, "%s()\n", __func__);
1213
1214 if (fh) {
1215 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio,
1216 fh->prio);
1217 if (0 != err)
1218 return err;
1219 }
1220 770
1221 if (dev->tvnorm == *tvnorms) 771 if (dev->tvnorm == tvnorms)
1222 return 0; 772 return 0;
1223 773
1224 mutex_lock(&dev->lock); 774 dev->tvnorm = tvnorms;
1225 cx25821_set_tvnorm(dev, *tvnorms); 775 chan->width = 720;
1226 mutex_unlock(&dev->lock); 776 chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
1227 777
1228 medusa_set_videostandard(dev); 778 medusa_set_videostandard(dev);
1229 779
1230 return 0; 780 return 0;
1231} 781}
1232#endif
1233 782
1234int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i) 783static int cx25821_vidioc_enum_input(struct file *file, void *priv,
784 struct v4l2_input *i)
1235{ 785{
1236 static const char * const iname[] = { 786 if (i->index)
1237 [CX25821_VMUX_COMPOSITE] = "Composite",
1238 [CX25821_VMUX_SVIDEO] = "S-Video",
1239 [CX25821_VMUX_DEBUG] = "for debug only",
1240 };
1241 unsigned int n;
1242 dprintk(1, "%s()\n", __func__);
1243
1244 n = i->index;
1245 if (n >= 2)
1246 return -EINVAL;
1247
1248 if (0 == INPUT(n)->type)
1249 return -EINVAL; 787 return -EINVAL;
1250 788
1251 i->type = V4L2_INPUT_TYPE_CAMERA; 789 i->type = V4L2_INPUT_TYPE_CAMERA;
1252 strcpy(i->name, iname[INPUT(n)->type]);
1253
1254 i->std = CX25821_NORMS; 790 i->std = CX25821_NORMS;
791 strcpy(i->name, "Composite");
1255 return 0; 792 return 0;
1256} 793}
1257 794
1258int cx25821_vidioc_enum_input(struct file *file, void *priv, 795static int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1259 struct v4l2_input *i)
1260{
1261 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1262 dprintk(1, "%s()\n", __func__);
1263 return cx25821_enum_input(dev, i);
1264}
1265
1266int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1267{
1268 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1269
1270 *i = dev->input;
1271 dprintk(1, "%s(): returns %d\n", __func__, *i);
1272 return 0;
1273}
1274
1275int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
1276{
1277 struct cx25821_fh *fh = priv;
1278 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1279 int err;
1280
1281 dprintk(1, "%s(%d)\n", __func__, i);
1282
1283 if (fh) {
1284 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio,
1285 fh->prio);
1286 if (0 != err)
1287 return err;
1288 }
1289
1290 if (i >= CX25821_NR_INPUT) {
1291 dprintk(1, "%s(): -EINVAL\n", __func__);
1292 return -EINVAL;
1293 }
1294
1295 mutex_lock(&dev->lock);
1296 cx25821_video_mux(dev, i);
1297 mutex_unlock(&dev->lock);
1298 return 0;
1299}
1300
1301#ifdef TUNER_FLAG
1302int cx25821_vidioc_g_frequency(struct file *file, void *priv,
1303 struct v4l2_frequency *f)
1304{
1305 struct cx25821_fh *fh = priv;
1306 struct cx25821_dev *dev = fh->dev;
1307
1308 f->frequency = dev->freq;
1309
1310 cx25821_call_all(dev, tuner, g_frequency, f);
1311
1312 return 0;
1313}
1314
1315int cx25821_set_freq(struct cx25821_dev *dev, struct v4l2_frequency *f)
1316{
1317 mutex_lock(&dev->lock);
1318 dev->freq = f->frequency;
1319
1320 cx25821_call_all(dev, tuner, s_frequency, f);
1321
1322 /* When changing channels it is required to reset TVAUDIO */
1323 msleep(10);
1324
1325 mutex_unlock(&dev->lock);
1326
1327 return 0;
1328}
1329
1330int cx25821_vidioc_s_frequency(struct file *file, void *priv,
1331 struct v4l2_frequency *f)
1332{
1333 struct cx25821_fh *fh = priv;
1334 struct cx25821_dev *dev;
1335 int err;
1336
1337 if (fh) {
1338 dev = fh->dev;
1339 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio,
1340 fh->prio);
1341 if (0 != err)
1342 return err;
1343 } else {
1344 pr_err("Invalid fh pointer!\n");
1345 return -EINVAL;
1346 }
1347
1348 return cx25821_set_freq(dev, f);
1349}
1350#endif
1351
1352#ifdef CONFIG_VIDEO_ADV_DEBUG
1353int cx25821_vidioc_g_register(struct file *file, void *fh,
1354 struct v4l2_dbg_register *reg)
1355{
1356 struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev;
1357
1358 if (!v4l2_chip_match_host(&reg->match))
1359 return -EINVAL;
1360
1361 cx25821_call_all(dev, core, g_register, reg);
1362
1363 return 0;
1364}
1365
1366int cx25821_vidioc_s_register(struct file *file, void *fh,
1367 struct v4l2_dbg_register *reg)
1368{ 796{
1369 struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; 797 *i = 0;
1370
1371 if (!v4l2_chip_match_host(&reg->match))
1372 return -EINVAL;
1373
1374 cx25821_call_all(dev, core, s_register, reg);
1375
1376 return 0; 798 return 0;
1377} 799}
1378 800
1379#endif 801static int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
1380
1381#ifdef TUNER_FLAG
1382int cx25821_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1383{ 802{
1384 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 803 return i ? -EINVAL : 0;
1385
1386 if (unlikely(UNSET == dev->tuner_type))
1387 return -EINVAL;
1388 if (0 != t->index)
1389 return -EINVAL;
1390
1391 strcpy(t->name, "Television");
1392 t->type = V4L2_TUNER_ANALOG_TV;
1393 t->capability = V4L2_TUNER_CAP_NORM;
1394 t->rangehigh = 0xffffffffUL;
1395
1396 t->signal = 0xffff; /* LOCKED */
1397 return 0;
1398} 804}
1399 805
1400int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) 806static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl)
1401{ 807{
1402 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 808 struct cx25821_channel *chan =
1403 struct cx25821_fh *fh = priv; 809 container_of(ctrl->handler, struct cx25821_channel, hdl);
1404 int err; 810 struct cx25821_dev *dev = chan->dev;
1405
1406 if (fh) {
1407 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio,
1408 fh->prio);
1409 if (0 != err)
1410 return err;
1411 }
1412 811
1413 dprintk(1, "%s()\n", __func__); 812 switch (ctrl->id) {
1414 if (UNSET == dev->tuner_type)
1415 return -EINVAL;
1416 if (0 != t->index)
1417 return -EINVAL;
1418
1419 return 0;
1420}
1421
1422#endif
1423/*****************************************************************************/
1424static const struct v4l2_queryctrl no_ctl = {
1425 .name = "42",
1426 .flags = V4L2_CTRL_FLAG_DISABLED,
1427};
1428
1429static struct v4l2_queryctrl cx25821_ctls[] = {
1430 /* --- video --- */
1431 {
1432 .id = V4L2_CID_BRIGHTNESS,
1433 .name = "Brightness",
1434 .minimum = 0,
1435 .maximum = 10000,
1436 .step = 1,
1437 .default_value = 6200,
1438 .type = V4L2_CTRL_TYPE_INTEGER,
1439 }, {
1440 .id = V4L2_CID_CONTRAST,
1441 .name = "Contrast",
1442 .minimum = 0,
1443 .maximum = 10000,
1444 .step = 1,
1445 .default_value = 5000,
1446 .type = V4L2_CTRL_TYPE_INTEGER,
1447 }, {
1448 .id = V4L2_CID_SATURATION,
1449 .name = "Saturation",
1450 .minimum = 0,
1451 .maximum = 10000,
1452 .step = 1,
1453 .default_value = 5000,
1454 .type = V4L2_CTRL_TYPE_INTEGER,
1455 }, {
1456 .id = V4L2_CID_HUE,
1457 .name = "Hue",
1458 .minimum = 0,
1459 .maximum = 10000,
1460 .step = 1,
1461 .default_value = 5000,
1462 .type = V4L2_CTRL_TYPE_INTEGER,
1463 }
1464};
1465static const int CX25821_CTLS = ARRAY_SIZE(cx25821_ctls);
1466
1467static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
1468{
1469 int i;
1470
1471 if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1)
1472 return -EINVAL;
1473 for (i = 0; i < CX25821_CTLS; i++)
1474 if (cx25821_ctls[i].id == qctrl->id)
1475 break;
1476 if (i == CX25821_CTLS) {
1477 *qctrl = no_ctl;
1478 return 0;
1479 }
1480 *qctrl = cx25821_ctls[i];
1481 return 0;
1482}
1483
1484int cx25821_vidioc_queryctrl(struct file *file, void *priv,
1485 struct v4l2_queryctrl *qctrl)
1486{
1487 return cx25821_ctrl_query(qctrl);
1488}
1489
1490/* ------------------------------------------------------------------ */
1491/* VIDEO CTRL IOCTLS */
1492
1493static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
1494{
1495 unsigned int i;
1496
1497 for (i = 0; i < CX25821_CTLS; i++)
1498 if (cx25821_ctls[i].id == id)
1499 return cx25821_ctls + i;
1500 return NULL;
1501}
1502
1503int cx25821_vidioc_g_ctrl(struct file *file, void *priv,
1504 struct v4l2_control *ctl)
1505{
1506 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1507 struct cx25821_fh *fh = priv;
1508
1509 const struct v4l2_queryctrl *ctrl;
1510
1511 ctrl = ctrl_by_id(ctl->id);
1512
1513 if (NULL == ctrl)
1514 return -EINVAL;
1515 switch (ctl->id) {
1516 case V4L2_CID_BRIGHTNESS: 813 case V4L2_CID_BRIGHTNESS:
1517 ctl->value = dev->channels[fh->channel_id].ctl_bright; 814 medusa_set_brightness(dev, ctrl->val, chan->id);
1518 break; 815 break;
1519 case V4L2_CID_HUE: 816 case V4L2_CID_HUE:
1520 ctl->value = dev->channels[fh->channel_id].ctl_hue; 817 medusa_set_hue(dev, ctrl->val, chan->id);
1521 break; 818 break;
1522 case V4L2_CID_CONTRAST: 819 case V4L2_CID_CONTRAST:
1523 ctl->value = dev->channels[fh->channel_id].ctl_contrast; 820 medusa_set_contrast(dev, ctrl->val, chan->id);
1524 break; 821 break;
1525 case V4L2_CID_SATURATION: 822 case V4L2_CID_SATURATION:
1526 ctl->value = dev->channels[fh->channel_id].ctl_saturation; 823 medusa_set_saturation(dev, ctrl->val, chan->id);
1527 break;
1528 }
1529 return 0;
1530}
1531
1532int cx25821_set_control(struct cx25821_dev *dev,
1533 struct v4l2_control *ctl, int chan_num)
1534{
1535 int err;
1536 const struct v4l2_queryctrl *ctrl;
1537
1538 err = -EINVAL;
1539
1540 ctrl = ctrl_by_id(ctl->id);
1541
1542 if (NULL == ctrl)
1543 return err;
1544
1545 switch (ctrl->type) {
1546 case V4L2_CTRL_TYPE_BOOLEAN:
1547 case V4L2_CTRL_TYPE_MENU:
1548 case V4L2_CTRL_TYPE_INTEGER:
1549 if (ctl->value < ctrl->minimum)
1550 ctl->value = ctrl->minimum;
1551 if (ctl->value > ctrl->maximum)
1552 ctl->value = ctrl->maximum;
1553 break; 824 break;
1554 default: 825 default:
1555 /* nothing */ ;
1556 }
1557
1558 switch (ctl->id) {
1559 case V4L2_CID_BRIGHTNESS:
1560 dev->channels[chan_num].ctl_bright = ctl->value;
1561 medusa_set_brightness(dev, ctl->value, chan_num);
1562 break;
1563 case V4L2_CID_HUE:
1564 dev->channels[chan_num].ctl_hue = ctl->value;
1565 medusa_set_hue(dev, ctl->value, chan_num);
1566 break;
1567 case V4L2_CID_CONTRAST:
1568 dev->channels[chan_num].ctl_contrast = ctl->value;
1569 medusa_set_contrast(dev, ctl->value, chan_num);
1570 break;
1571 case V4L2_CID_SATURATION:
1572 dev->channels[chan_num].ctl_saturation = ctl->value;
1573 medusa_set_saturation(dev, ctl->value, chan_num);
1574 break;
1575 }
1576
1577 err = 0;
1578
1579 return err;
1580}
1581
1582static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num)
1583{
1584 struct v4l2_control ctrl;
1585 int i;
1586 for (i = 0; i < CX25821_CTLS; i++) {
1587 ctrl.id = cx25821_ctls[i].id;
1588 ctrl.value = cx25821_ctls[i].default_value;
1589
1590 cx25821_set_control(dev, &ctrl, chan_num);
1591 }
1592}
1593
1594int cx25821_vidioc_cropcap(struct file *file, void *priv,
1595 struct v4l2_cropcap *cropcap)
1596{
1597 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1598
1599 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1600 return -EINVAL; 826 return -EINVAL;
1601 cropcap->bounds.top = 0;
1602 cropcap->bounds.left = 0;
1603 cropcap->bounds.width = 720;
1604 cropcap->bounds.height = dev->tvnorm == V4L2_STD_PAL_BG ? 576 : 480;
1605 cropcap->pixelaspect.numerator =
1606 dev->tvnorm == V4L2_STD_PAL_BG ? 59 : 10;
1607 cropcap->pixelaspect.denominator =
1608 dev->tvnorm == V4L2_STD_PAL_BG ? 54 : 11;
1609 cropcap->defrect = cropcap->bounds;
1610 return 0;
1611}
1612
1613int cx25821_vidioc_s_crop(struct file *file, void *priv, const struct v4l2_crop *crop)
1614{
1615 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1616 struct cx25821_fh *fh = priv;
1617 int err;
1618
1619 if (fh) {
1620 err = v4l2_prio_check(&dev->channels[fh->channel_id].prio,
1621 fh->prio);
1622 if (0 != err)
1623 return err;
1624 } 827 }
1625 /* cx25821_vidioc_s_crop not supported */ 828 return 0;
1626 return -EINVAL;
1627}
1628
1629int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
1630{
1631 /* cx25821_vidioc_g_crop not supported */
1632 return -EINVAL;
1633} 829}
1634 830
1635int cx25821_vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm) 831static int cx25821_vidioc_enum_output(struct file *file, void *priv,
832 struct v4l2_output *o)
1636{ 833{
1637 /* medusa does not support video standard sensing of current input */ 834 if (o->index)
1638 *norm = CX25821_NORMS; 835 return -EINVAL;
1639 836
837 o->type = V4L2_INPUT_TYPE_CAMERA;
838 o->std = CX25821_NORMS;
839 strcpy(o->name, "Composite");
1640 return 0; 840 return 0;
1641} 841}
1642 842
1643int cx25821_is_valid_width(u32 width, v4l2_std_id tvnorm) 843static int cx25821_vidioc_g_output(struct file *file, void *priv, unsigned int *o)
1644{ 844{
1645 if (tvnorm == V4L2_STD_PAL_BG) { 845 *o = 0;
1646 if (width == 352 || width == 720)
1647 return 1;
1648 else
1649 return 0;
1650 }
1651
1652 if (tvnorm == V4L2_STD_NTSC_M) {
1653 if (width == 320 || width == 352 || width == 720)
1654 return 1;
1655 else
1656 return 0;
1657 }
1658 return 0; 846 return 0;
1659} 847}
1660 848
1661int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm) 849static int cx25821_vidioc_s_output(struct file *file, void *priv, unsigned int o)
1662{ 850{
1663 if (tvnorm == V4L2_STD_PAL_BG) { 851 return o ? -EINVAL : 0;
1664 if (height == 576 || height == 288)
1665 return 1;
1666 else
1667 return 0;
1668 }
1669
1670 if (tvnorm == V4L2_STD_NTSC_M) {
1671 if (height == 480 || height == 240)
1672 return 1;
1673 else
1674 return 0;
1675 }
1676
1677 return 0;
1678} 852}
1679 853
1680static long video_ioctl_upstream9(struct file *file, unsigned int cmd, 854static int cx25821_vidioc_try_fmt_vid_out(struct file *file, void *priv,
1681 unsigned long arg) 855 struct v4l2_format *f)
1682{ 856{
1683 struct cx25821_fh *fh = file->private_data; 857 struct cx25821_channel *chan = video_drvdata(file);
1684 struct cx25821_dev *dev = fh->dev; 858 struct cx25821_dev *dev = chan->dev;
1685 int command = 0; 859 const struct cx25821_fmt *fmt;
1686 struct upstream_user_struct *data_from_user;
1687
1688 data_from_user = (struct upstream_user_struct *)arg;
1689
1690 if (!data_from_user) {
1691 pr_err("%s(): Upstream data is INVALID. Returning\n", __func__);
1692 return 0;
1693 }
1694
1695 command = data_from_user->command;
1696
1697 if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO)
1698 return 0;
1699
1700 dev->input_filename = data_from_user->input_filename;
1701 dev->input_audiofilename = data_from_user->input_filename;
1702 dev->vid_stdname = data_from_user->vid_stdname;
1703 dev->pixel_format = data_from_user->pixel_format;
1704 dev->channel_select = data_from_user->channel_select;
1705 dev->command = data_from_user->command;
1706
1707 switch (command) {
1708 case UPSTREAM_START_VIDEO:
1709 cx25821_start_upstream_video_ch1(dev, data_from_user);
1710 break;
1711
1712 case UPSTREAM_STOP_VIDEO:
1713 cx25821_stop_upstream_video_ch1(dev);
1714 break;
1715 }
1716 860
861 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
862 if (NULL == fmt)
863 return -EINVAL;
864 f->fmt.pix.width = 720;
865 f->fmt.pix.height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
866 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
867 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
868 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
869 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
870 f->fmt.pix.priv = 0;
1717 return 0; 871 return 0;
1718} 872}
1719 873
1720static long video_ioctl_upstream10(struct file *file, unsigned int cmd, 874static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
1721 unsigned long arg) 875 struct v4l2_format *f)
1722{ 876{
1723 struct cx25821_fh *fh = file->private_data; 877 struct cx25821_channel *chan = video_drvdata(file);
1724 struct cx25821_dev *dev = fh->dev; 878 int err;
1725 int command = 0;
1726 struct upstream_user_struct *data_from_user;
1727
1728 data_from_user = (struct upstream_user_struct *)arg;
1729
1730 if (!data_from_user) {
1731 pr_err("%s(): Upstream data is INVALID. Returning\n", __func__);
1732 return 0;
1733 }
1734
1735 command = data_from_user->command;
1736
1737 if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO)
1738 return 0;
1739
1740 dev->input_filename_ch2 = data_from_user->input_filename;
1741 dev->input_audiofilename = data_from_user->input_filename;
1742 dev->vid_stdname_ch2 = data_from_user->vid_stdname;
1743 dev->pixel_format_ch2 = data_from_user->pixel_format;
1744 dev->channel_select_ch2 = data_from_user->channel_select;
1745 dev->command_ch2 = data_from_user->command;
1746 879
1747 switch (command) { 880 err = cx25821_vidioc_try_fmt_vid_out(file, priv, f);
1748 case UPSTREAM_START_VIDEO:
1749 cx25821_start_upstream_video_ch2(dev, data_from_user);
1750 break;
1751 881
1752 case UPSTREAM_STOP_VIDEO: 882 if (0 != err)
1753 cx25821_stop_upstream_video_ch2(dev); 883 return err;
1754 break;
1755 }
1756 884
885 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
886 chan->vidq.field = f->fmt.pix.field;
887 chan->width = f->fmt.pix.width;
888 chan->height = f->fmt.pix.height;
889 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
890 chan->pixel_formats = PIXEL_FRMT_411;
891 else
892 chan->pixel_formats = PIXEL_FRMT_422;
1757 return 0; 893 return 0;
1758} 894}
1759 895
1760static long video_ioctl_upstream11(struct file *file, unsigned int cmd, 896static ssize_t video_write(struct file *file, const char __user *data, size_t count,
1761 unsigned long arg) 897 loff_t *ppos)
1762{ 898{
1763 struct cx25821_fh *fh = file->private_data; 899 struct cx25821_channel *chan = video_drvdata(file);
1764 struct cx25821_dev *dev = fh->dev; 900 struct cx25821_dev *dev = chan->dev;
1765 int command = 0; 901 struct v4l2_fh *fh = file->private_data;
1766 struct upstream_user_struct *data_from_user; 902 int err = 0;
1767 903
1768 data_from_user = (struct upstream_user_struct *)arg; 904 if (mutex_lock_interruptible(&dev->lock))
1769 905 return -ERESTARTSYS;
1770 if (!data_from_user) { 906 if (chan->streaming_fh && chan->streaming_fh != fh) {
1771 pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); 907 err = -EBUSY;
1772 return 0; 908 goto unlock;
1773 } 909 }
1774 910 if (!chan->streaming_fh) {
1775 command = data_from_user->command; 911 err = cx25821_vidupstream_init(chan, chan->pixel_formats);
1776 912 if (err)
1777 if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) 913 goto unlock;
1778 return 0; 914 chan->streaming_fh = fh;
1779
1780 dev->input_filename = data_from_user->input_filename;
1781 dev->input_audiofilename = data_from_user->input_filename;
1782 dev->vid_stdname = data_from_user->vid_stdname;
1783 dev->pixel_format = data_from_user->pixel_format;
1784 dev->channel_select = data_from_user->channel_select;
1785 dev->command = data_from_user->command;
1786
1787 switch (command) {
1788 case UPSTREAM_START_AUDIO:
1789 cx25821_start_upstream_audio(dev, data_from_user);
1790 break;
1791
1792 case UPSTREAM_STOP_AUDIO:
1793 cx25821_stop_upstream_audio(dev);
1794 break;
1795 } 915 }
1796 916
1797 return 0; 917 err = cx25821_write_frame(chan, data, count);
918 count -= err;
919 *ppos += err;
920
921unlock:
922 mutex_unlock(&dev->lock);
923 return err;
1798} 924}
1799 925
1800static long video_ioctl_set(struct file *file, unsigned int cmd, 926static int video_out_release(struct file *file)
1801 unsigned long arg)
1802{ 927{
1803 struct cx25821_fh *fh = file->private_data; 928 struct cx25821_channel *chan = video_drvdata(file);
1804 struct cx25821_dev *dev = fh->dev; 929 struct cx25821_dev *dev = chan->dev;
1805 struct downstream_user_struct *data_from_user; 930 struct v4l2_fh *fh = file->private_data;
1806 int command;
1807 int width = 720;
1808 int selected_channel = 0;
1809 int pix_format = 0;
1810 int i = 0;
1811 int cif_enable = 0;
1812 int cif_width = 0;
1813
1814 data_from_user = (struct downstream_user_struct *)arg;
1815
1816 if (!data_from_user) {
1817 pr_err("%s(): User data is INVALID. Returning\n", __func__);
1818 return 0;
1819 }
1820
1821 command = data_from_user->command;
1822
1823 if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
1824 && command != ENABLE_CIF_RESOLUTION && command != REG_READ
1825 && command != REG_WRITE && command != MEDUSA_READ
1826 && command != MEDUSA_WRITE) {
1827 return 0;
1828 }
1829
1830 switch (command) {
1831 case SET_VIDEO_STD:
1832 if (!strcmp(data_from_user->vid_stdname, "PAL"))
1833 dev->tvnorm = V4L2_STD_PAL_BG;
1834 else
1835 dev->tvnorm = V4L2_STD_NTSC_M;
1836 medusa_set_videostandard(dev);
1837 break;
1838
1839 case SET_PIXEL_FORMAT:
1840 selected_channel = data_from_user->decoder_select;
1841 pix_format = data_from_user->pixel_format;
1842
1843 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1844 selected_channel -= 4;
1845 selected_channel = selected_channel % 8;
1846 }
1847
1848 if (selected_channel >= 0)
1849 cx25821_set_pixel_format(dev, selected_channel,
1850 pix_format);
1851
1852 break;
1853
1854 case ENABLE_CIF_RESOLUTION:
1855 selected_channel = data_from_user->decoder_select;
1856 cif_enable = data_from_user->cif_resolution_enable;
1857 cif_width = data_from_user->cif_width;
1858
1859 if (cif_enable) {
1860 if (dev->tvnorm & V4L2_STD_PAL_BG
1861 || dev->tvnorm & V4L2_STD_PAL_DK) {
1862 width = 352;
1863 } else {
1864 width = cif_width;
1865 if (cif_width != 320 && cif_width != 352)
1866 width = 320;
1867 }
1868 }
1869
1870 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1871 selected_channel -= 4;
1872 selected_channel = selected_channel % 8;
1873 }
1874
1875 if (selected_channel <= 7 && selected_channel >= 0) {
1876 dev->channels[selected_channel].use_cif_resolution =
1877 cif_enable;
1878 dev->channels[selected_channel].cif_width = width;
1879 } else {
1880 for (i = 0; i < VID_CHANNEL_NUM; i++) {
1881 dev->channels[i].use_cif_resolution =
1882 cif_enable;
1883 dev->channels[i].cif_width = width;
1884 }
1885 }
1886 931
1887 medusa_set_resolution(dev, width, selected_channel); 932 mutex_lock(&dev->lock);
1888 break; 933 if (chan->streaming_fh == fh) {
1889 case REG_READ: 934 cx25821_stop_upstream_video(chan);
1890 data_from_user->reg_data = cx_read(data_from_user->reg_address); 935 chan->streaming_fh = NULL;
1891 break;
1892 case REG_WRITE:
1893 cx_write(data_from_user->reg_address, data_from_user->reg_data);
1894 break;
1895 case MEDUSA_READ:
1896 cx25821_i2c_read(&dev->i2c_bus[0],
1897 (u16) data_from_user->reg_address,
1898 &data_from_user->reg_data);
1899 break;
1900 case MEDUSA_WRITE:
1901 cx25821_i2c_write(&dev->i2c_bus[0],
1902 (u16) data_from_user->reg_address,
1903 data_from_user->reg_data);
1904 break;
1905 } 936 }
937 mutex_unlock(&dev->lock);
1906 938
1907 return 0; 939 return v4l2_fh_release(file);
1908} 940}
1909 941
1910static long cx25821_video_ioctl(struct file *file, 942static const struct v4l2_ctrl_ops cx25821_ctrl_ops = {
1911 unsigned int cmd, unsigned long arg) 943 .s_ctrl = cx25821_s_ctrl,
1912{ 944};
1913 int ret = 0;
1914
1915 struct cx25821_fh *fh = file->private_data;
1916
1917 /* check to see if it's the video upstream */
1918 if (fh->channel_id == SRAM_CH09) {
1919 ret = video_ioctl_upstream9(file, cmd, arg);
1920 return ret;
1921 } else if (fh->channel_id == SRAM_CH10) {
1922 ret = video_ioctl_upstream10(file, cmd, arg);
1923 return ret;
1924 } else if (fh->channel_id == SRAM_CH11) {
1925 ret = video_ioctl_upstream11(file, cmd, arg);
1926 ret = video_ioctl_set(file, cmd, arg);
1927 return ret;
1928 }
1929
1930 return video_ioctl2(file, cmd, arg);
1931}
1932 945
1933/* exported stuff */
1934static const struct v4l2_file_operations video_fops = { 946static const struct v4l2_file_operations video_fops = {
1935 .owner = THIS_MODULE, 947 .owner = THIS_MODULE,
1936 .open = video_open, 948 .open = v4l2_fh_open,
1937 .release = video_release, 949 .release = video_release,
1938 .read = video_read, 950 .read = video_read,
1939 .poll = video_poll, 951 .poll = video_poll,
1940 .mmap = cx25821_video_mmap, 952 .mmap = cx25821_video_mmap,
1941 .ioctl = cx25821_video_ioctl, 953 .unlocked_ioctl = video_ioctl2,
1942}; 954};
1943 955
1944static const struct v4l2_ioctl_ops video_ioctl_ops = { 956static const struct v4l2_ioctl_ops video_ioctl_ops = {
@@ -1951,40 +963,170 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1951 .vidioc_querybuf = cx25821_vidioc_querybuf, 963 .vidioc_querybuf = cx25821_vidioc_querybuf,
1952 .vidioc_qbuf = cx25821_vidioc_qbuf, 964 .vidioc_qbuf = cx25821_vidioc_qbuf,
1953 .vidioc_dqbuf = vidioc_dqbuf, 965 .vidioc_dqbuf = vidioc_dqbuf,
1954#ifdef TUNER_FLAG 966 .vidioc_g_std = cx25821_vidioc_g_std,
1955 .vidioc_s_std = cx25821_vidioc_s_std, 967 .vidioc_s_std = cx25821_vidioc_s_std,
1956 .vidioc_querystd = cx25821_vidioc_querystd,
1957#endif
1958 .vidioc_cropcap = cx25821_vidioc_cropcap,
1959 .vidioc_s_crop = cx25821_vidioc_s_crop,
1960 .vidioc_g_crop = cx25821_vidioc_g_crop,
1961 .vidioc_enum_input = cx25821_vidioc_enum_input, 968 .vidioc_enum_input = cx25821_vidioc_enum_input,
1962 .vidioc_g_input = cx25821_vidioc_g_input, 969 .vidioc_g_input = cx25821_vidioc_g_input,
1963 .vidioc_s_input = cx25821_vidioc_s_input, 970 .vidioc_s_input = cx25821_vidioc_s_input,
1964 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
1965 .vidioc_s_ctrl = vidioc_s_ctrl,
1966 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
1967 .vidioc_streamon = vidioc_streamon, 971 .vidioc_streamon = vidioc_streamon,
1968 .vidioc_streamoff = vidioc_streamoff, 972 .vidioc_streamoff = vidioc_streamoff,
1969 .vidioc_log_status = vidioc_log_status, 973 .vidioc_log_status = vidioc_log_status,
1970 .vidioc_g_priority = cx25821_vidioc_g_priority, 974 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1971 .vidioc_s_priority = cx25821_vidioc_s_priority, 975 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1972#ifdef TUNER_FLAG
1973 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
1974 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
1975 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
1976 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
1977#endif
1978#ifdef CONFIG_VIDEO_ADV_DEBUG
1979 .vidioc_g_register = cx25821_vidioc_g_register,
1980 .vidioc_s_register = cx25821_vidioc_s_register,
1981#endif
1982}; 976};
1983 977
1984struct video_device cx25821_videoioctl_template = { 978static const struct video_device cx25821_video_device = {
1985 .name = "cx25821-videoioctl", 979 .name = "cx25821-video",
1986 .fops = &video_fops, 980 .fops = &video_fops,
981 .release = video_device_release_empty,
982 .minor = -1,
1987 .ioctl_ops = &video_ioctl_ops, 983 .ioctl_ops = &video_ioctl_ops,
1988 .tvnorms = CX25821_NORMS, 984 .tvnorms = CX25821_NORMS,
1989 .current_norm = V4L2_STD_NTSC_M,
1990}; 985};
986
987static const struct v4l2_file_operations video_out_fops = {
988 .owner = THIS_MODULE,
989 .open = v4l2_fh_open,
990 .write = video_write,
991 .release = video_out_release,
992 .unlocked_ioctl = video_ioctl2,
993};
994
995static const struct v4l2_ioctl_ops video_out_ioctl_ops = {
996 .vidioc_querycap = cx25821_vidioc_querycap,
997 .vidioc_enum_fmt_vid_out = cx25821_vidioc_enum_fmt_vid_cap,
998 .vidioc_g_fmt_vid_out = cx25821_vidioc_g_fmt_vid_cap,
999 .vidioc_try_fmt_vid_out = cx25821_vidioc_try_fmt_vid_out,
1000 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out,
1001 .vidioc_g_std = cx25821_vidioc_g_std,
1002 .vidioc_s_std = cx25821_vidioc_s_std,
1003 .vidioc_enum_output = cx25821_vidioc_enum_output,
1004 .vidioc_g_output = cx25821_vidioc_g_output,
1005 .vidioc_s_output = cx25821_vidioc_s_output,
1006 .vidioc_log_status = vidioc_log_status,
1007};
1008
1009static const struct video_device cx25821_video_out_device = {
1010 .name = "cx25821-video",
1011 .fops = &video_out_fops,
1012 .release = video_device_release_empty,
1013 .minor = -1,
1014 .ioctl_ops = &video_out_ioctl_ops,
1015 .tvnorms = CX25821_NORMS,
1016};
1017
1018void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
1019{
1020 cx_clear(PCI_INT_MSK, 1);
1021
1022 if (video_is_registered(&dev->channels[chan_num].vdev)) {
1023 video_unregister_device(&dev->channels[chan_num].vdev);
1024 v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl);
1025
1026 btcx_riscmem_free(dev->pci,
1027 &dev->channels[chan_num].dma_vidq.stopper);
1028 }
1029}
1030
1031int cx25821_video_register(struct cx25821_dev *dev)
1032{
1033 int err;
1034 int i;
1035
1036 /* initial device configuration */
1037 dev->tvnorm = V4L2_STD_NTSC_M;
1038
1039 spin_lock_init(&dev->slock);
1040
1041 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) {
1042 struct cx25821_channel *chan = &dev->channels[i];
1043 struct video_device *vdev = &chan->vdev;
1044 struct v4l2_ctrl_handler *hdl = &chan->hdl;
1045 bool is_output = i > SRAM_CH08;
1046
1047 if (i == SRAM_CH08) /* audio channel */
1048 continue;
1049
1050 if (!is_output) {
1051 v4l2_ctrl_handler_init(hdl, 4);
1052 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
1053 V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200);
1054 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
1055 V4L2_CID_CONTRAST, 0, 10000, 1, 5000);
1056 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
1057 V4L2_CID_SATURATION, 0, 10000, 1, 5000);
1058 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
1059 V4L2_CID_HUE, 0, 10000, 1, 5000);
1060 if (hdl->error) {
1061 err = hdl->error;
1062 goto fail_unreg;
1063 }
1064 err = v4l2_ctrl_handler_setup(hdl);
1065 if (err)
1066 goto fail_unreg;
1067 } else {
1068 chan->out = &dev->vid_out_data[i - SRAM_CH09];
1069 chan->out->chan = chan;
1070 }
1071
1072 cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper,
1073 chan->sram_channels->dma_ctl, 0x11, 0);
1074
1075 chan->sram_channels = &cx25821_sram_channels[i];
1076 chan->width = 720;
1077 if (dev->tvnorm & V4L2_STD_625_50)
1078 chan->height = 576;
1079 else
1080 chan->height = 480;
1081
1082 if (chan->pixel_formats == PIXEL_FRMT_411)
1083 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P);
1084 else
1085 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV);
1086
1087 cx_write(chan->sram_channels->int_stat, 0xffffffff);
1088
1089 INIT_LIST_HEAD(&chan->dma_vidq.active);
1090 INIT_LIST_HEAD(&chan->dma_vidq.queued);
1091
1092 chan->timeout_data.dev = dev;
1093 chan->timeout_data.channel = &cx25821_sram_channels[i];
1094 chan->dma_vidq.timeout.function = cx25821_vid_timeout;
1095 chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data;
1096 init_timer(&chan->dma_vidq.timeout);
1097
1098 if (!is_output)
1099 videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev,
1100 &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
1101 V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer),
1102 chan, &dev->lock);
1103
1104 /* register v4l devices */
1105 *vdev = is_output ? cx25821_video_out_device : cx25821_video_device;
1106 vdev->v4l2_dev = &dev->v4l2_dev;
1107 if (!is_output)
1108 vdev->ctrl_handler = hdl;
1109 else
1110 vdev->vfl_dir = VFL_DIR_TX;
1111 vdev->lock = &dev->lock;
1112 set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1113 snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i);
1114 video_set_drvdata(vdev, chan);
1115
1116 err = video_register_device(vdev, VFL_TYPE_GRABBER,
1117 video_nr[dev->nr]);
1118
1119 if (err < 0)
1120 goto fail_unreg;
1121 }
1122
1123 /* set PCI interrupt */
1124 cx_set(PCI_INT_MSK, 0xff);
1125
1126 return 0;
1127
1128fail_unreg:
1129 while (i >= 0)
1130 cx25821_video_unregister(dev, i--);
1131 return err;
1132}
diff --git a/drivers/media/pci/cx25821/cx25821-video.h b/drivers/media/pci/cx25821/cx25821-video.h
index c265e35b37c3..ab63b3858acf 100644
--- a/drivers/media/pci/cx25821/cx25821-video.h
+++ b/drivers/media/pci/cx25821/cx25821-video.h
@@ -39,8 +39,7 @@
39#include "cx25821.h" 39#include "cx25821.h"
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/v4l2-ioctl.h> 41#include <media/v4l2-ioctl.h>
42 42#include <media/v4l2-event.h>
43#define TUNER_FLAG
44 43
45#define VIDEO_DEBUG 0 44#define VIDEO_DEBUG 0
46 45
@@ -50,137 +49,17 @@ do { \
50 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ##arg); \ 49 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ##arg); \
51} while (0) 50} while (0)
52 51
53/* For IOCTL to identify running upstream */
54#define UPSTREAM_START_VIDEO 700
55#define UPSTREAM_STOP_VIDEO 701
56#define UPSTREAM_START_AUDIO 702
57#define UPSTREAM_STOP_AUDIO 703
58#define UPSTREAM_DUMP_REGISTERS 702
59#define SET_VIDEO_STD 800
60#define SET_PIXEL_FORMAT 1000
61#define ENABLE_CIF_RESOLUTION 1001
62
63#define REG_READ 900
64#define REG_WRITE 901
65#define MEDUSA_READ 910
66#define MEDUSA_WRITE 911
67
68extern struct sram_channel *channel0;
69extern struct sram_channel *channel1;
70extern struct sram_channel *channel2;
71extern struct sram_channel *channel3;
72extern struct sram_channel *channel4;
73extern struct sram_channel *channel5;
74extern struct sram_channel *channel6;
75extern struct sram_channel *channel7;
76extern struct sram_channel *channel9;
77extern struct sram_channel *channel10;
78extern struct sram_channel *channel11;
79extern struct video_device cx25821_videoioctl_template;
80/* extern const u32 *ctrl_classes[]; */
81
82extern unsigned int vid_limit;
83
84#define FORMAT_FLAGS_PACKED 0x01 52#define FORMAT_FLAGS_PACKED 0x01
85extern struct cx25821_fmt formats[];
86extern struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc);
87extern struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM];
88
89extern void cx25821_video_wakeup(struct cx25821_dev *dev, 53extern void cx25821_video_wakeup(struct cx25821_dev *dev,
90 struct cx25821_dmaqueue *q, u32 count); 54 struct cx25821_dmaqueue *q, u32 count);
91 55
92#ifdef TUNER_FLAG
93extern int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm);
94#endif
95
96extern int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh,
97 unsigned int bit);
98extern int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit);
99extern int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit);
100extern void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh,
101 unsigned int bits);
102extern int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input);
103extern int cx25821_start_video_dma(struct cx25821_dev *dev, 56extern int cx25821_start_video_dma(struct cx25821_dev *dev,
104 struct cx25821_dmaqueue *q, 57 struct cx25821_dmaqueue *q,
105 struct cx25821_buffer *buf, 58 struct cx25821_buffer *buf,
106 struct sram_channel *channel); 59 const struct sram_channel *channel);
107 60
108extern int cx25821_set_scale(struct cx25821_dev *dev, unsigned int width,
109 unsigned int height, enum v4l2_field field);
110extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status); 61extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status);
111extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num); 62extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num);
112extern int cx25821_video_register(struct cx25821_dev *dev); 63extern int cx25821_video_register(struct cx25821_dev *dev);
113extern int cx25821_get_format_size(void);
114
115extern int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
116 unsigned int *size);
117extern int cx25821_buffer_prepare(struct videobuf_queue *q,
118 struct videobuf_buffer *vb,
119 enum v4l2_field field);
120extern void cx25821_buffer_release(struct videobuf_queue *q,
121 struct videobuf_buffer *vb);
122extern struct videobuf_queue *get_queue(struct cx25821_fh *fh);
123extern int cx25821_get_resource(struct cx25821_fh *fh, int resource);
124extern int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma);
125extern int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
126 struct v4l2_format *f);
127extern int cx25821_vidioc_querycap(struct file *file, void *priv,
128 struct v4l2_capability *cap);
129extern int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
130 struct v4l2_fmtdesc *f);
131extern int cx25821_vidioc_reqbufs(struct file *file, void *priv,
132 struct v4l2_requestbuffers *p);
133extern int cx25821_vidioc_querybuf(struct file *file, void *priv,
134 struct v4l2_buffer *p);
135extern int cx25821_vidioc_qbuf(struct file *file, void *priv,
136 struct v4l2_buffer *p);
137extern int cx25821_vidioc_s_std(struct file *file, void *priv,
138 v4l2_std_id *tvnorms);
139extern int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i);
140extern int cx25821_vidioc_enum_input(struct file *file, void *priv,
141 struct v4l2_input *i);
142extern int cx25821_vidioc_g_input(struct file *file, void *priv,
143 unsigned int *i);
144extern int cx25821_vidioc_s_input(struct file *file, void *priv,
145 unsigned int i);
146extern int cx25821_vidioc_g_ctrl(struct file *file, void *priv,
147 struct v4l2_control *ctl);
148extern int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
149 struct v4l2_format *f);
150extern int cx25821_vidioc_g_frequency(struct file *file, void *priv,
151 struct v4l2_frequency *f);
152extern int cx25821_set_freq(struct cx25821_dev *dev, struct v4l2_frequency *f);
153extern int cx25821_vidioc_s_frequency(struct file *file, void *priv,
154 struct v4l2_frequency *f);
155extern int cx25821_vidioc_g_register(struct file *file, void *fh,
156 struct v4l2_dbg_register *reg);
157extern int cx25821_vidioc_s_register(struct file *file, void *fh,
158 struct v4l2_dbg_register *reg);
159extern int cx25821_vidioc_g_tuner(struct file *file, void *priv,
160 struct v4l2_tuner *t);
161extern int cx25821_vidioc_s_tuner(struct file *file, void *priv,
162 struct v4l2_tuner *t);
163
164extern int cx25821_is_valid_width(u32 width, v4l2_std_id tvnorm);
165extern int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm);
166
167extern int cx25821_vidioc_g_priority(struct file *file, void *f,
168 enum v4l2_priority *p);
169extern int cx25821_vidioc_s_priority(struct file *file, void *f,
170 enum v4l2_priority prio);
171
172extern int cx25821_vidioc_queryctrl(struct file *file, void *priv,
173 struct v4l2_queryctrl *qctrl);
174extern int cx25821_set_control(struct cx25821_dev *dev,
175 struct v4l2_control *ctrl, int chan_num);
176
177extern int cx25821_vidioc_cropcap(struct file *file, void *fh,
178 struct v4l2_cropcap *cropcap);
179extern int cx25821_vidioc_s_crop(struct file *file, void *priv,
180 const struct v4l2_crop *crop);
181extern int cx25821_vidioc_g_crop(struct file *file, void *priv,
182 struct v4l2_crop *crop);
183 64
184extern int cx25821_vidioc_querystd(struct file *file, void *priv,
185 v4l2_std_id *norm);
186#endif 65#endif
diff --git a/drivers/media/pci/cx25821/cx25821.h b/drivers/media/pci/cx25821/cx25821.h
index 8a9c0c869412..90bdc196929f 100644
--- a/drivers/media/pci/cx25821/cx25821.h
+++ b/drivers/media/pci/cx25821/cx25821.h
@@ -33,17 +33,14 @@
33 33
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/tuner.h> 36#include <media/v4l2-ctrls.h>
37#include <media/tveeprom.h>
38#include <media/videobuf-dma-sg.h> 37#include <media/videobuf-dma-sg.h>
39#include <media/videobuf-dvb.h>
40 38
41#include "btcx-risc.h" 39#include "btcx-risc.h"
42#include "cx25821-reg.h" 40#include "cx25821-reg.h"
43#include "cx25821-medusa-reg.h" 41#include "cx25821-medusa-reg.h"
44#include "cx25821-sram.h" 42#include "cx25821-sram.h"
45#include "cx25821-audio.h" 43#include "cx25821-audio.h"
46#include "media/cx2341x.h"
47 44
48#include <linux/version.h> 45#include <linux/version.h>
49#include <linux/mutex.h> 46#include <linux/mutex.h>
@@ -55,8 +52,6 @@
55 52
56#define CX25821_MAXBOARDS 2 53#define CX25821_MAXBOARDS 2
57 54
58#define TRUE 1
59#define FALSE 0
60#define LINE_SIZE_D1 1440 55#define LINE_SIZE_D1 1440
61 56
62/* Number of decoders and encoders */ 57/* Number of decoders and encoders */
@@ -67,7 +62,6 @@
67 62
68/* Max number of inputs by card */ 63/* Max number of inputs by card */
69#define MAX_CX25821_INPUT 8 64#define MAX_CX25821_INPUT 8
70#define INPUT(nr) (&cx25821_boards[dev->board].input[nr])
71#define RESOURCE_VIDEO0 1 65#define RESOURCE_VIDEO0 1
72#define RESOURCE_VIDEO1 2 66#define RESOURCE_VIDEO1 2
73#define RESOURCE_VIDEO2 4 67#define RESOURCE_VIDEO2 4
@@ -80,7 +74,6 @@
80#define RESOURCE_VIDEO9 512 74#define RESOURCE_VIDEO9 512
81#define RESOURCE_VIDEO10 1024 75#define RESOURCE_VIDEO10 1024
82#define RESOURCE_VIDEO11 2048 76#define RESOURCE_VIDEO11 2048
83#define RESOURCE_VIDEO_IOCTL 4096
84 77
85#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */ 78#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
86 79
@@ -97,7 +90,6 @@
97#define CX25821_BOARD_CONEXANT_ATHENA10 1 90#define CX25821_BOARD_CONEXANT_ATHENA10 1
98#define MAX_VID_CHANNEL_NUM 12 91#define MAX_VID_CHANNEL_NUM 12
99#define VID_CHANNEL_NUM 8 92#define VID_CHANNEL_NUM 8
100#define CX25821_NR_INPUT 2
101 93
102struct cx25821_fmt { 94struct cx25821_fmt {
103 char *name; 95 char *name;
@@ -107,14 +99,6 @@ struct cx25821_fmt {
107 u32 cxformat; 99 u32 cxformat;
108}; 100};
109 101
110struct cx25821_ctrl {
111 struct v4l2_queryctrl v;
112 u32 off;
113 u32 reg;
114 u32 mask;
115 u32 shift;
116};
117
118struct cx25821_tvnorm { 102struct cx25821_tvnorm {
119 char *name; 103 char *name;
120 v4l2_std_id id; 104 v4l2_std_id id;
@@ -122,40 +106,6 @@ struct cx25821_tvnorm {
122 u32 cxoformat; 106 u32 cxoformat;
123}; 107};
124 108
125struct cx25821_fh {
126 struct cx25821_dev *dev;
127 enum v4l2_buf_type type;
128 int radio;
129 u32 resources;
130
131 enum v4l2_priority prio;
132
133 /* video overlay */
134 struct v4l2_window win;
135 struct v4l2_clip *clips;
136 unsigned int nclips;
137
138 /* video capture */
139 struct cx25821_fmt *fmt;
140 unsigned int width, height;
141 int channel_id;
142
143 /* vbi capture */
144 struct videobuf_queue vidq;
145 struct videobuf_queue vbiq;
146
147 /* H264 Encoder specifics ONLY */
148 struct videobuf_queue mpegq;
149 atomic_t v4l_reading;
150};
151
152enum cx25821_itype {
153 CX25821_VMUX_COMPOSITE = 1,
154 CX25821_VMUX_SVIDEO,
155 CX25821_VMUX_DEBUG,
156 CX25821_RADIO,
157};
158
159enum cx25821_src_sel_type { 109enum cx25821_src_sel_type {
160 CX25821_SRC_SEL_EXT_656_VIDEO = 0, 110 CX25821_SRC_SEL_EXT_656_VIDEO = 0,
161 CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO 111 CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
@@ -169,16 +119,10 @@ struct cx25821_buffer {
169 /* cx25821 specific */ 119 /* cx25821 specific */
170 unsigned int bpl; 120 unsigned int bpl;
171 struct btcx_riscmem risc; 121 struct btcx_riscmem risc;
172 struct cx25821_fmt *fmt; 122 const struct cx25821_fmt *fmt;
173 u32 count; 123 u32 count;
174}; 124};
175 125
176struct cx25821_input {
177 enum cx25821_itype type;
178 unsigned int vmux;
179 u32 gpio0, gpio1, gpio2, gpio3;
180};
181
182enum port { 126enum port {
183 CX25821_UNDEFINED = 0, 127 CX25821_UNDEFINED = 0,
184 CX25821_RAW, 128 CX25821_RAW,
@@ -190,19 +134,8 @@ struct cx25821_board {
190 enum port porta; 134 enum port porta;
191 enum port portb; 135 enum port portb;
192 enum port portc; 136 enum port portc;
193 unsigned int tuner_type;
194 unsigned int radio_type;
195 unsigned char tuner_addr;
196 unsigned char radio_addr;
197 137
198 u32 clk_freq; 138 u32 clk_freq;
199 struct cx25821_input input[CX25821_NR_INPUT];
200};
201
202struct cx25821_subid {
203 u16 subvendor;
204 u16 subdevice;
205 u32 card;
206}; 139};
207 140
208struct cx25821_i2c { 141struct cx25821_i2c {
@@ -234,34 +167,70 @@ struct cx25821_dmaqueue {
234 167
235struct cx25821_data { 168struct cx25821_data {
236 struct cx25821_dev *dev; 169 struct cx25821_dev *dev;
237 struct sram_channel *channel; 170 const struct sram_channel *channel;
171};
172
173struct cx25821_dev;
174
175struct cx25821_channel;
176
177struct cx25821_video_out_data {
178 struct cx25821_channel *chan;
179 int _line_size;
180 int _prog_cnt;
181 int _pixel_format;
182 int _is_first_frame;
183 int _is_running;
184 int _file_status;
185 int _lines_count;
186 int _frame_count;
187 unsigned int _risc_size;
188
189 __le32 *_dma_virt_start_addr;
190 __le32 *_dma_virt_addr;
191 dma_addr_t _dma_phys_addr;
192 dma_addr_t _dma_phys_start_addr;
193
194 unsigned int _data_buf_size;
195 __le32 *_data_buf_virt_addr;
196 dma_addr_t _data_buf_phys_addr;
197
198 u32 upstream_riscbuf_size;
199 u32 upstream_databuf_size;
200 int is_60hz;
201 int _frame_index;
202 int cur_frame_index;
203 int curpos;
204 wait_queue_head_t waitq;
238}; 205};
239 206
240struct cx25821_channel { 207struct cx25821_channel {
241 struct v4l2_prio_state prio; 208 unsigned id;
209 struct cx25821_dev *dev;
210 struct v4l2_fh *streaming_fh;
242 211
243 int ctl_bright; 212 struct v4l2_ctrl_handler hdl;
244 int ctl_contrast;
245 int ctl_hue;
246 int ctl_saturation;
247 struct cx25821_data timeout_data; 213 struct cx25821_data timeout_data;
248 214
249 struct video_device *video_dev; 215 struct video_device vdev;
250 struct cx25821_dmaqueue vidq; 216 struct cx25821_dmaqueue dma_vidq;
251 217 struct videobuf_queue vidq;
252 struct sram_channel *sram_channels;
253 218
254 struct mutex lock; 219 const struct sram_channel *sram_channels;
255 int resources;
256 220
221 const struct cx25821_fmt *fmt;
222 unsigned int width, height;
257 int pixel_formats; 223 int pixel_formats;
258 int use_cif_resolution; 224 int use_cif_resolution;
259 int cif_width; 225 int cif_width;
226
227 /* video output data for the video output channel */
228 struct cx25821_video_out_data *out;
260}; 229};
261 230
231struct snd_card;
232
262struct cx25821_dev { 233struct cx25821_dev {
263 struct list_head devlist;
264 atomic_t refcount;
265 struct v4l2_device v4l2_dev; 234 struct v4l2_device v4l2_dev;
266 235
267 /* pci stuff */ 236 /* pci stuff */
@@ -273,6 +242,8 @@ struct cx25821_dev {
273 u8 __iomem *bmmio; 242 u8 __iomem *bmmio;
274 int pci_irqmask; 243 int pci_irqmask;
275 int hwrevision; 244 int hwrevision;
245 /* used by cx25821-alsa */
246 struct snd_card *card;
276 247
277 u32 clk_freq; 248 u32 clk_freq;
278 249
@@ -289,17 +260,8 @@ struct cx25821_dev {
289 char name[32]; 260 char name[32];
290 261
291 /* Analog video */ 262 /* Analog video */
292 u32 resources;
293 unsigned int input; 263 unsigned int input;
294 u32 tvaudio;
295 v4l2_std_id tvnorm; 264 v4l2_std_id tvnorm;
296 unsigned int tuner_type;
297 unsigned char tuner_addr;
298 unsigned int radio_type;
299 unsigned char radio_addr;
300 unsigned int has_radio;
301 unsigned int videc_type;
302 unsigned char videc_addr;
303 unsigned short _max_num_decoders; 265 unsigned short _max_num_decoders;
304 266
305 /* Analog Audio Upstream */ 267 /* Analog Audio Upstream */
@@ -323,132 +285,26 @@ struct cx25821_dev {
323 __le32 *_audiodata_buf_virt_addr; 285 __le32 *_audiodata_buf_virt_addr;
324 dma_addr_t _audiodata_buf_phys_addr; 286 dma_addr_t _audiodata_buf_phys_addr;
325 char *_audiofilename; 287 char *_audiofilename;
326
327 /* V4l */
328 u32 freq;
329 struct video_device *vbi_dev;
330 struct video_device *radio_dev;
331 struct video_device *ioctl_dev;
332
333 spinlock_t slock;
334
335 /* Video Upstream */
336 int _line_size;
337 int _prog_cnt;
338 int _pixel_format;
339 int _is_first_frame;
340 int _is_running;
341 int _file_status;
342 int _lines_count;
343 int _frame_count;
344 int _channel_upstream_select;
345 unsigned int _risc_size;
346
347 __le32 *_dma_virt_start_addr;
348 __le32 *_dma_virt_addr;
349 dma_addr_t _dma_phys_addr;
350 dma_addr_t _dma_phys_start_addr;
351
352 unsigned int _data_buf_size;
353 __le32 *_data_buf_virt_addr;
354 dma_addr_t _data_buf_phys_addr;
355 char *_filename;
356 char *_defaultname;
357
358 int _line_size_ch2;
359 int _prog_cnt_ch2;
360 int _pixel_format_ch2;
361 int _is_first_frame_ch2;
362 int _is_running_ch2;
363 int _file_status_ch2;
364 int _lines_count_ch2;
365 int _frame_count_ch2;
366 int _channel2_upstream_select;
367 unsigned int _risc_size_ch2;
368
369 __le32 *_dma_virt_start_addr_ch2;
370 __le32 *_dma_virt_addr_ch2;
371 dma_addr_t _dma_phys_addr_ch2;
372 dma_addr_t _dma_phys_start_addr_ch2;
373
374 unsigned int _data_buf_size_ch2;
375 __le32 *_data_buf_virt_addr_ch2;
376 dma_addr_t _data_buf_phys_addr_ch2;
377 char *_filename_ch2;
378 char *_defaultname_ch2;
379
380 /* MPEG Encoder ONLY settings */
381 u32 cx23417_mailbox;
382 struct cx2341x_mpeg_params mpeg_params;
383 struct video_device *v4l_device;
384 atomic_t v4l_reader_count;
385 struct cx25821_tvnorm encodernorm;
386
387 u32 upstream_riscbuf_size;
388 u32 upstream_databuf_size;
389 u32 upstream_riscbuf_size_ch2;
390 u32 upstream_databuf_size_ch2;
391 u32 audio_upstream_riscbuf_size; 288 u32 audio_upstream_riscbuf_size;
392 u32 audio_upstream_databuf_size; 289 u32 audio_upstream_databuf_size;
393 int _isNTSC;
394 int _frame_index;
395 int _audioframe_index; 290 int _audioframe_index;
396 struct workqueue_struct *_irq_queues;
397 struct work_struct _irq_work_entry;
398 struct workqueue_struct *_irq_queues_ch2;
399 struct work_struct _irq_work_entry_ch2;
400 struct workqueue_struct *_irq_audio_queues; 291 struct workqueue_struct *_irq_audio_queues;
401 struct work_struct _audio_work_entry; 292 struct work_struct _audio_work_entry;
402 char *input_filename;
403 char *input_filename_ch2;
404 int _frame_index_ch2;
405 int _isNTSC_ch2;
406 char *vid_stdname_ch2;
407 int pixel_format_ch2;
408 int channel_select_ch2;
409 int command_ch2;
410 char *input_audiofilename; 293 char *input_audiofilename;
411 char *vid_stdname;
412 int pixel_format;
413 int channel_select;
414 int command;
415 int channel_opened;
416};
417 294
418struct upstream_user_struct { 295 /* V4l */
419 char *input_filename; 296 spinlock_t slock;
420 char *vid_stdname;
421 int pixel_format;
422 int channel_select;
423 int command;
424};
425 297
426struct downstream_user_struct { 298 /* Video Upstream */
427 char *vid_stdname; 299 struct cx25821_video_out_data vid_out_data[2];
428 int pixel_format;
429 int cif_resolution_enable;
430 int cif_width;
431 int decoder_select;
432 int command;
433 int reg_address;
434 int reg_data;
435}; 300};
436 301
437extern struct upstream_user_struct *up_data;
438
439static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev) 302static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
440{ 303{
441 return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev); 304 return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
442} 305}
443 306
444#define cx25821_call_all(dev, o, f, args...) \
445 v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
446
447extern struct list_head cx25821_devlist;
448extern struct mutex cx25821_devlist_mutex;
449
450extern struct cx25821_board cx25821_boards[]; 307extern struct cx25821_board cx25821_boards[];
451extern struct cx25821_subid cx25821_subids[];
452 308
453#define SRAM_CH00 0 /* Video A */ 309#define SRAM_CH00 0 /* Video A */
454#define SRAM_CH01 1 /* Video B */ 310#define SRAM_CH01 1 /* Video B */
@@ -467,7 +323,6 @@ extern struct cx25821_subid cx25821_subids[];
467#define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09 323#define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
468#define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10 324#define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
469#define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11 325#define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
470#define VIDEO_IOCTL_CH 11
471 326
472struct sram_channel { 327struct sram_channel {
473 char *name; 328 char *name;
@@ -503,10 +358,8 @@ struct sram_channel {
503 u32 jumponly; 358 u32 jumponly;
504 u32 irq_bit; 359 u32 irq_bit;
505}; 360};
506extern struct sram_channel cx25821_sram_channels[];
507 361
508#define STATUS_SUCCESS 0 362extern const struct sram_channel cx25821_sram_channels[];
509#define STATUS_UNSUCCESSFUL -1
510 363
511#define cx_read(reg) readl(dev->lmmio + ((reg)>>2)) 364#define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
512#define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2)) 365#define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
@@ -529,8 +382,6 @@ extern struct sram_channel cx25821_sram_channels[];
529 pr_info("(%d): " fmt, dev->board, ##args) 382 pr_info("(%d): " fmt, dev->board, ##args)
530 383
531extern int cx25821_i2c_register(struct cx25821_i2c *bus); 384extern int cx25821_i2c_register(struct cx25821_i2c *bus);
532extern void cx25821_card_setup(struct cx25821_dev *dev);
533extern int cx25821_ir_init(struct cx25821_dev *dev);
534extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value); 385extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
535extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value); 386extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
536extern int cx25821_i2c_unregister(struct cx25821_i2c *bus); 387extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
@@ -551,7 +402,7 @@ extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
551 int decoder); 402 int decoder);
552 403
553extern int cx25821_sram_channel_setup(struct cx25821_dev *dev, 404extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
554 struct sram_channel *ch, unsigned int bpl, 405 const struct sram_channel *ch, unsigned int bpl,
555 u32 risc); 406 u32 risc);
556 407
557extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, 408extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
@@ -570,46 +421,31 @@ extern void cx25821_free_buffer(struct videobuf_queue *q,
570extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 421extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
571 u32 reg, u32 mask, u32 value); 422 u32 reg, u32 mask, u32 value);
572extern void cx25821_sram_channel_dump(struct cx25821_dev *dev, 423extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
573 struct sram_channel *ch); 424 const struct sram_channel *ch);
574extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, 425extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
575 struct sram_channel *ch); 426 const struct sram_channel *ch);
576 427
577extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci); 428extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
578extern void cx25821_print_irqbits(char *name, char *tag, char **strings, 429extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
579 int len, u32 bits, u32 mask); 430 int len, u32 bits, u32 mask);
580extern void cx25821_dev_unregister(struct cx25821_dev *dev); 431extern void cx25821_dev_unregister(struct cx25821_dev *dev);
581extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev, 432extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
582 struct sram_channel *ch, 433 const struct sram_channel *ch,
583 unsigned int bpl, u32 risc); 434 unsigned int bpl, u32 risc);
584 435
585extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, 436extern int cx25821_vidupstream_init(struct cx25821_channel *chan, int pixel_format);
586 int channel_select, int pixel_format);
587extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
588 int channel_select, int pixel_format);
589extern int cx25821_audio_upstream_init(struct cx25821_dev *dev, 437extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
590 int channel_select); 438 int channel_select);
591extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev); 439extern int cx25821_write_frame(struct cx25821_channel *chan,
592extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev); 440 const char __user *data, size_t count);
441extern void cx25821_free_mem_upstream(struct cx25821_channel *chan);
593extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev); 442extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
594extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev, 443extern void cx25821_stop_upstream_video(struct cx25821_channel *chan);
595 struct upstream_user_struct
596 *up_data);
597extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
598 struct upstream_user_struct
599 *up_data);
600extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
601 struct upstream_user_struct *up_data);
602extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
603extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
604extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev); 444extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
605extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev, 445extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
606 struct sram_channel *ch, 446 const struct sram_channel *ch,
607 unsigned int bpl, u32 risc); 447 unsigned int bpl, u32 risc);
608extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel, 448extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
609 u32 format); 449 u32 format);
610extern void cx25821_videoioctl_unregister(struct cx25821_dev *dev); 450
611extern struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
612 struct pci_dev *pci,
613 struct video_device *template,
614 char *type);
615#endif 451#endif
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index a6ff8a6f4fc0..150bb76e7839 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -815,7 +815,7 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
815} 815}
816 816
817static int vidioc_s_frequency (struct file *file, void *priv, 817static int vidioc_s_frequency (struct file *file, void *priv,
818 struct v4l2_frequency *f) 818 const struct v4l2_frequency *f)
819{ 819{
820 struct cx8802_fh *fh = priv; 820 struct cx8802_fh *fh = priv;
821 struct cx8802_dev *dev = fh->dev; 821 struct cx8802_dev *dev = fh->dev;
@@ -918,7 +918,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
918} 918}
919 919
920static int vidioc_s_tuner (struct file *file, void *priv, 920static int vidioc_s_tuner (struct file *file, void *priv,
921 struct v4l2_tuner *t) 921 const struct v4l2_tuner *t)
922{ 922{
923 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; 923 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
924 924
@@ -939,12 +939,12 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm)
939 return 0; 939 return 0;
940} 940}
941 941
942static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id) 942static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
943{ 943{
944 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; 944 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
945 945
946 mutex_lock(&core->lock); 946 mutex_lock(&core->lock);
947 cx88_set_tvnorm(core,*id); 947 cx88_set_tvnorm(core, id);
948 mutex_unlock(&core->lock); 948 mutex_unlock(&core->lock);
949 return 0; 949 return 0;
950} 950}
diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c
index e2e0b8faf7a4..a87a0e19593e 100644
--- a/drivers/media/pci/cx88/cx88-cards.c
+++ b/drivers/media/pci/cx88/cx88-cards.c
@@ -59,6 +59,11 @@ MODULE_PARM_DESC(disable_ir, "Disable IR support");
59#define err_printk(core, fmt, arg...) \ 59#define err_printk(core, fmt, arg...) \
60 printk(KERN_ERR "%s: " fmt, core->name , ## arg) 60 printk(KERN_ERR "%s: " fmt, core->name , ## arg)
61 61
62#define dprintk(level,fmt, arg...) do { \
63 if (cx88_core_debug >= level) \
64 printk(KERN_DEBUG "%s: " fmt, core->name , ## arg); \
65 } while(0)
66
62 67
63/* ------------------------------------------------------------------ */ 68/* ------------------------------------------------------------------ */
64/* board config info */ 69/* board config info */
@@ -2855,6 +2860,7 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
2855 core->board.tuner_type = tv.tuner_type; 2860 core->board.tuner_type = tv.tuner_type;
2856 core->tuner_formats = tv.tuner_formats; 2861 core->tuner_formats = tv.tuner_formats;
2857 core->board.radio.type = tv.has_radio ? CX88_RADIO : 0; 2862 core->board.radio.type = tv.has_radio ? CX88_RADIO : 0;
2863 core->model = tv.model;
2858 2864
2859 /* Make sure we support the board model */ 2865 /* Make sure we support the board model */
2860 switch (tv.model) 2866 switch (tv.model)
@@ -3133,7 +3139,7 @@ static int cx88_xc2028_tuner_callback(struct cx88_core *core,
3133 case XC2028_TUNER_RESET: 3139 case XC2028_TUNER_RESET:
3134 switch (INPUT(core->input).type) { 3140 switch (INPUT(core->input).type) {
3135 case CX88_RADIO: 3141 case CX88_RADIO:
3136 info_printk(core, "setting GPIO to radio!\n"); 3142 dprintk(1, "setting GPIO to radio!\n");
3137 cx_write(MO_GP0_IO, 0x4ff); 3143 cx_write(MO_GP0_IO, 0x4ff);
3138 mdelay(250); 3144 mdelay(250);
3139 cx_write(MO_GP2_IO, 0xff); 3145 cx_write(MO_GP2_IO, 0xff);
@@ -3141,7 +3147,7 @@ static int cx88_xc2028_tuner_callback(struct cx88_core *core,
3141 break; 3147 break;
3142 case CX88_VMUX_DVB: /* Digital TV*/ 3148 case CX88_VMUX_DVB: /* Digital TV*/
3143 default: /* Analog TV */ 3149 default: /* Analog TV */
3144 info_printk(core, "setting GPIO to TV!\n"); 3150 dprintk(1, "setting GPIO to TV!\n");
3145 break; 3151 break;
3146 } 3152 }
3147 cx_write(MO_GP1_IO, 0x101010); 3153 cx_write(MO_GP1_IO, 0x101010);
@@ -3199,8 +3205,7 @@ static int cx88_xc5000_tuner_callback(struct cx88_core *core,
3199 not having any tuning at all. */ 3205 not having any tuning at all. */
3200 return 0; 3206 return 0;
3201 } else { 3207 } else {
3202 err_printk(core, "xc5000: unknown tuner " 3208 dprintk(1, "xc5000: unknown tuner callback command.\n");
3203 "callback command.\n");
3204 return -EINVAL; 3209 return -EINVAL;
3205 } 3210 }
3206 break; 3211 break;
@@ -3211,8 +3216,7 @@ static int cx88_xc5000_tuner_callback(struct cx88_core *core,
3211 cx_set(MO_GP0_IO, 0x00000010); 3216 cx_set(MO_GP0_IO, 0x00000010);
3212 return 0; 3217 return 0;
3213 } else { 3218 } else {
3214 printk(KERN_ERR 3219 dprintk(1, "xc5000: unknown tuner callback command.\n");
3215 "xc5000: unknown tuner callback command.\n");
3216 return -EINVAL; 3220 return -EINVAL;
3217 } 3221 }
3218 break; 3222 break;
@@ -3242,13 +3246,13 @@ int cx88_tuner_callback(void *priv, int component, int command, int arg)
3242 3246
3243 switch (core->board.tuner_type) { 3247 switch (core->board.tuner_type) {
3244 case TUNER_XC2028: 3248 case TUNER_XC2028:
3245 info_printk(core, "Calling XC2028/3028 callback\n"); 3249 dprintk(1, "Calling XC2028/3028 callback\n");
3246 return cx88_xc2028_tuner_callback(core, command, arg); 3250 return cx88_xc2028_tuner_callback(core, command, arg);
3247 case TUNER_XC4000: 3251 case TUNER_XC4000:
3248 info_printk(core, "Calling XC4000 callback\n"); 3252 dprintk(1, "Calling XC4000 callback\n");
3249 return cx88_xc4000_tuner_callback(core, command, arg); 3253 return cx88_xc4000_tuner_callback(core, command, arg);
3250 case TUNER_XC5000: 3254 case TUNER_XC5000:
3251 info_printk(core, "Calling XC5000 callback\n"); 3255 dprintk(1, "Calling XC5000 callback\n");
3252 return cx88_xc5000_tuner_callback(core, command, arg); 3256 return cx88_xc5000_tuner_callback(core, command, arg);
3253 } 3257 }
3254 err_printk(core, "Error: Calling callback for tuner %d\n", 3258 err_printk(core, "Error: Calling callback for tuner %d\n",
@@ -3589,8 +3593,8 @@ static void cx88_card_setup(struct cx88_core *core)
3589 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg)); 3593 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
3590 xc2028_cfg.tuner = TUNER_XC2028; 3594 xc2028_cfg.tuner = TUNER_XC2028;
3591 xc2028_cfg.priv = &ctl; 3595 xc2028_cfg.priv = &ctl;
3592 info_printk(core, "Asking xc2028/3028 to load firmware %s\n", 3596 dprintk(1, "Asking xc2028/3028 to load firmware %s\n",
3593 ctl.fname); 3597 ctl.fname);
3594 call_all(core, tuner, s_config, &xc2028_cfg); 3598 call_all(core, tuner, s_config, &xc2028_cfg);
3595 } 3599 }
3596 call_all(core, core, s_power, 0); 3600 call_all(core, core, s_power, 0);
@@ -3759,8 +3763,8 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3759 if (radio[core->nr] != UNSET) 3763 if (radio[core->nr] != UNSET)
3760 core->board.radio_type = radio[core->nr]; 3764 core->board.radio_type = radio[core->nr];
3761 3765
3762 info_printk(core, "TV tuner type %d, Radio tuner type %d\n", 3766 dprintk(1, "TV tuner type %d, Radio tuner type %d\n",
3763 core->board.tuner_type, core->board.radio_type); 3767 core->board.tuner_type, core->board.radio_type);
3764 3768
3765 /* init hardware */ 3769 /* init hardware */
3766 cx88_reset(core); 3770 cx88_reset(core);
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index 39f095c37ffd..c8f3dcc579d4 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -48,9 +48,9 @@ MODULE_LICENSE("GPL");
48 48
49/* ------------------------------------------------------------------ */ 49/* ------------------------------------------------------------------ */
50 50
51static unsigned int core_debug; 51unsigned int cx88_core_debug;
52module_param(core_debug,int,0644); 52module_param_named(core_debug, cx88_core_debug, int, 0644);
53MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 53MODULE_PARM_DESC(core_debug, "enable debug messages [core]");
54 54
55static unsigned int nicam; 55static unsigned int nicam;
56module_param(nicam,int,0644); 56module_param(nicam,int,0644);
@@ -60,8 +60,10 @@ static unsigned int nocomb;
60module_param(nocomb,int,0644); 60module_param(nocomb,int,0644);
61MODULE_PARM_DESC(nocomb,"disable comb filter"); 61MODULE_PARM_DESC(nocomb,"disable comb filter");
62 62
63#define dprintk(level,fmt, arg...) if (core_debug >= level) \ 63#define dprintk(level,fmt, arg...) do { \
64 printk(KERN_DEBUG "%s: " fmt, core->name , ## arg) 64 if (cx88_core_debug >= level) \
65 printk(KERN_DEBUG "%s: " fmt, core->name , ## arg); \
66 } while(0)
65 67
66static unsigned int cx88_devcount; 68static unsigned int cx88_devcount;
67static LIST_HEAD(cx88_devlist); 69static LIST_HEAD(cx88_devlist);
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index 672b267a2d3e..053ed1ba1d85 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -1042,7 +1042,7 @@ static int dvb_register(struct cx8802_dev *dev)
1042 if (!dvb_attach(isl6421_attach, 1042 if (!dvb_attach(isl6421_attach,
1043 fe0->dvb.frontend, 1043 fe0->dvb.frontend,
1044 &dev->core->i2c_adap, 1044 &dev->core->i2c_adap,
1045 0x08, ISL6421_DCL, 0x00)) 1045 0x08, ISL6421_DCL, 0x00, false))
1046 goto frontend_detach; 1046 goto frontend_detach;
1047 } 1047 }
1048 /* MFE frontend 2 */ 1048 /* MFE frontend 2 */
@@ -1279,8 +1279,16 @@ static int dvb_register(struct cx8802_dev *dev)
1279 &hauppauge_novas_config, 1279 &hauppauge_novas_config,
1280 &core->i2c_adap); 1280 &core->i2c_adap);
1281 if (fe0->dvb.frontend) { 1281 if (fe0->dvb.frontend) {
1282 bool override_tone;
1283
1284 if (core->model == 92001)
1285 override_tone = true;
1286 else
1287 override_tone = false;
1288
1282 if (!dvb_attach(isl6421_attach, fe0->dvb.frontend, 1289 if (!dvb_attach(isl6421_attach, fe0->dvb.frontend,
1283 &core->i2c_adap, 0x08, ISL6421_DCL, 0x00)) 1290 &core->i2c_adap, 0x08, ISL6421_DCL, 0x00,
1291 override_tone))
1284 goto frontend_detach; 1292 goto frontend_detach;
1285 } 1293 }
1286 break; 1294 break;
@@ -1403,7 +1411,7 @@ static int dvb_register(struct cx8802_dev *dev)
1403 if (!dvb_attach(isl6421_attach, 1411 if (!dvb_attach(isl6421_attach,
1404 fe0->dvb.frontend, 1412 fe0->dvb.frontend,
1405 &dev->core->i2c_adap, 1413 &dev->core->i2c_adap,
1406 0x08, ISL6421_DCL, 0x00)) 1414 0x08, ISL6421_DCL, 0x00, false))
1407 goto frontend_detach; 1415 goto frontend_detach;
1408 } 1416 }
1409 /* MFE frontend 2 */ 1417 /* MFE frontend 2 */
@@ -1431,7 +1439,7 @@ static int dvb_register(struct cx8802_dev *dev)
1431 if (!dvb_attach(isl6421_attach, 1439 if (!dvb_attach(isl6421_attach,
1432 fe0->dvb.frontend, 1440 fe0->dvb.frontend,
1433 &dev->core->i2c_adap, 1441 &dev->core->i2c_adap,
1434 0x08, ISL6421_DCL, 0x00)) 1442 0x08, ISL6421_DCL, 0x00, false))
1435 goto frontend_detach; 1443 goto frontend_detach;
1436 } 1444 }
1437 break; 1445 break;
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index c9d3182f79d5..2d3507eb4897 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -532,16 +532,17 @@ static int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
532{ 532{
533 struct cx8802_dev *dev = pci_get_drvdata(pci_dev); 533 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
534 struct cx88_core *core = dev->core; 534 struct cx88_core *core = dev->core;
535 unsigned long flags;
535 536
536 /* stop mpeg dma */ 537 /* stop mpeg dma */
537 spin_lock(&dev->slock); 538 spin_lock_irqsave(&dev->slock, flags);
538 if (!list_empty(&dev->mpegq.active)) { 539 if (!list_empty(&dev->mpegq.active)) {
539 dprintk( 2, "suspend\n" ); 540 dprintk( 2, "suspend\n" );
540 printk("%s: suspend mpeg\n", core->name); 541 printk("%s: suspend mpeg\n", core->name);
541 cx8802_stop_dma(dev); 542 cx8802_stop_dma(dev);
542 del_timer(&dev->mpegq.timeout); 543 del_timer(&dev->mpegq.timeout);
543 } 544 }
544 spin_unlock(&dev->slock); 545 spin_unlock_irqrestore(&dev->slock, flags);
545 546
546 /* FIXME -- shutdown device */ 547 /* FIXME -- shutdown device */
547 cx88_shutdown(dev->core); 548 cx88_shutdown(dev->core);
@@ -558,6 +559,7 @@ static int cx8802_resume_common(struct pci_dev *pci_dev)
558{ 559{
559 struct cx8802_dev *dev = pci_get_drvdata(pci_dev); 560 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
560 struct cx88_core *core = dev->core; 561 struct cx88_core *core = dev->core;
562 unsigned long flags;
561 int err; 563 int err;
562 564
563 if (dev->state.disabled) { 565 if (dev->state.disabled) {
@@ -584,12 +586,12 @@ static int cx8802_resume_common(struct pci_dev *pci_dev)
584 cx88_reset(dev->core); 586 cx88_reset(dev->core);
585 587
586 /* restart video+vbi capture */ 588 /* restart video+vbi capture */
587 spin_lock(&dev->slock); 589 spin_lock_irqsave(&dev->slock, flags);
588 if (!list_empty(&dev->mpegq.active)) { 590 if (!list_empty(&dev->mpegq.active)) {
589 printk("%s: resume mpeg\n", core->name); 591 printk("%s: resume mpeg\n", core->name);
590 cx8802_restart_queue(dev,&dev->mpegq); 592 cx8802_restart_queue(dev,&dev->mpegq);
591 } 593 }
592 spin_unlock(&dev->slock); 594 spin_unlock_irqrestore(&dev->slock, flags);
593 595
594 return 0; 596 return 0;
595} 597}
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index bc78354262ac..1b00615fd395 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -1193,12 +1193,12 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm)
1193 return 0; 1193 return 0;
1194} 1194}
1195 1195
1196static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *tvnorms) 1196static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id tvnorms)
1197{ 1197{
1198 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; 1198 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1199 1199
1200 mutex_lock(&core->lock); 1200 mutex_lock(&core->lock);
1201 cx88_set_tvnorm(core,*tvnorms); 1201 cx88_set_tvnorm(core, tvnorms);
1202 mutex_unlock(&core->lock); 1202 mutex_unlock(&core->lock);
1203 1203
1204 return 0; 1204 return 0;
@@ -1289,7 +1289,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
1289} 1289}
1290 1290
1291static int vidioc_s_tuner (struct file *file, void *priv, 1291static int vidioc_s_tuner (struct file *file, void *priv,
1292 struct v4l2_tuner *t) 1292 const struct v4l2_tuner *t)
1293{ 1293{
1294 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; 1294 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1295 1295
@@ -1321,8 +1321,10 @@ static int vidioc_g_frequency (struct file *file, void *priv,
1321} 1321}
1322 1322
1323int cx88_set_freq (struct cx88_core *core, 1323int cx88_set_freq (struct cx88_core *core,
1324 struct v4l2_frequency *f) 1324 const struct v4l2_frequency *f)
1325{ 1325{
1326 struct v4l2_frequency new_freq = *f;
1327
1326 if (unlikely(UNSET == core->board.tuner_type)) 1328 if (unlikely(UNSET == core->board.tuner_type))
1327 return -EINVAL; 1329 return -EINVAL;
1328 if (unlikely(f->tuner != 0)) 1330 if (unlikely(f->tuner != 0))
@@ -1331,8 +1333,8 @@ int cx88_set_freq (struct cx88_core *core,
1331 mutex_lock(&core->lock); 1333 mutex_lock(&core->lock);
1332 cx88_newstation(core); 1334 cx88_newstation(core);
1333 call_all(core, tuner, s_frequency, f); 1335 call_all(core, tuner, s_frequency, f);
1334 call_all(core, tuner, g_frequency, f); 1336 call_all(core, tuner, g_frequency, &new_freq);
1335 core->freq = f->frequency; 1337 core->freq = new_freq.frequency;
1336 1338
1337 /* When changing channels it is required to reset TVAUDIO */ 1339 /* When changing channels it is required to reset TVAUDIO */
1338 msleep (10); 1340 msleep (10);
@@ -1345,7 +1347,7 @@ int cx88_set_freq (struct cx88_core *core,
1345EXPORT_SYMBOL(cx88_set_freq); 1347EXPORT_SYMBOL(cx88_set_freq);
1346 1348
1347static int vidioc_s_frequency (struct file *file, void *priv, 1349static int vidioc_s_frequency (struct file *file, void *priv,
1348 struct v4l2_frequency *f) 1350 const struct v4l2_frequency *f)
1349{ 1351{
1350 struct cx8800_fh *fh = priv; 1352 struct cx8800_fh *fh = priv;
1351 struct cx88_core *core = fh->dev->core; 1353 struct cx88_core *core = fh->dev->core;
@@ -1378,7 +1380,7 @@ static int vidioc_g_register (struct file *file, void *fh,
1378} 1380}
1379 1381
1380static int vidioc_s_register (struct file *file, void *fh, 1382static int vidioc_s_register (struct file *file, void *fh,
1381 struct v4l2_dbg_register *reg) 1383 const struct v4l2_dbg_register *reg)
1382{ 1384{
1383 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; 1385 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1384 1386
@@ -1407,20 +1409,15 @@ static int radio_g_tuner (struct file *file, void *priv,
1407 return 0; 1409 return 0;
1408} 1410}
1409 1411
1410/* FIXME: Should add a standard for radio */
1411
1412static int radio_s_tuner (struct file *file, void *priv, 1412static int radio_s_tuner (struct file *file, void *priv,
1413 struct v4l2_tuner *t) 1413 const struct v4l2_tuner *t)
1414{ 1414{
1415 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; 1415 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1416 1416
1417 if (0 != t->index) 1417 if (0 != t->index)
1418 return -EINVAL; 1418 return -EINVAL;
1419 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1420 t->audmode = V4L2_TUNER_MODE_STEREO;
1421 1419
1422 call_all(core, tuner, s_tuner, t); 1420 call_all(core, tuner, s_tuner, t);
1423
1424 return 0; 1421 return 0;
1425} 1422}
1426 1423
@@ -1957,9 +1954,10 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1957{ 1954{
1958 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 1955 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1959 struct cx88_core *core = dev->core; 1956 struct cx88_core *core = dev->core;
1957 unsigned long flags;
1960 1958
1961 /* stop video+vbi capture */ 1959 /* stop video+vbi capture */
1962 spin_lock(&dev->slock); 1960 spin_lock_irqsave(&dev->slock, flags);
1963 if (!list_empty(&dev->vidq.active)) { 1961 if (!list_empty(&dev->vidq.active)) {
1964 printk("%s/0: suspend video\n", core->name); 1962 printk("%s/0: suspend video\n", core->name);
1965 stop_video_dma(dev); 1963 stop_video_dma(dev);
@@ -1970,7 +1968,7 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1970 cx8800_stop_vbi_dma(dev); 1968 cx8800_stop_vbi_dma(dev);
1971 del_timer(&dev->vbiq.timeout); 1969 del_timer(&dev->vbiq.timeout);
1972 } 1970 }
1973 spin_unlock(&dev->slock); 1971 spin_unlock_irqrestore(&dev->slock, flags);
1974 1972
1975 if (core->ir) 1973 if (core->ir)
1976 cx88_ir_stop(core); 1974 cx88_ir_stop(core);
@@ -1989,6 +1987,7 @@ static int cx8800_resume(struct pci_dev *pci_dev)
1989{ 1987{
1990 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 1988 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1991 struct cx88_core *core = dev->core; 1989 struct cx88_core *core = dev->core;
1990 unsigned long flags;
1992 int err; 1991 int err;
1993 1992
1994 if (dev->state.disabled) { 1993 if (dev->state.disabled) {
@@ -2019,7 +2018,7 @@ static int cx8800_resume(struct pci_dev *pci_dev)
2019 cx_set(MO_PCI_INTMSK, core->pci_irqmask); 2018 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
2020 2019
2021 /* restart video+vbi capture */ 2020 /* restart video+vbi capture */
2022 spin_lock(&dev->slock); 2021 spin_lock_irqsave(&dev->slock, flags);
2023 if (!list_empty(&dev->vidq.active)) { 2022 if (!list_empty(&dev->vidq.active)) {
2024 printk("%s/0: resume video\n", core->name); 2023 printk("%s/0: resume video\n", core->name);
2025 restart_video_queue(dev,&dev->vidq); 2024 restart_video_queue(dev,&dev->vidq);
@@ -2028,7 +2027,7 @@ static int cx8800_resume(struct pci_dev *pci_dev)
2028 printk("%s/0: resume vbi\n", core->name); 2027 printk("%s/0: resume vbi\n", core->name);
2029 cx8800_restart_vbi_queue(dev,&dev->vbiq); 2028 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2030 } 2029 }
2031 spin_unlock(&dev->slock); 2030 spin_unlock_irqrestore(&dev->slock, flags);
2032 2031
2033 return 0; 2032 return 0;
2034} 2033}
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index feff53c0a251..51ce2c0e8bc1 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -334,6 +334,7 @@ struct cx88_core {
334 /* board name */ 334 /* board name */
335 int nr; 335 int nr;
336 char name[32]; 336 char name[32];
337 u32 model;
337 338
338 /* pci stuff */ 339 /* pci stuff */
339 int pci_bus; 340 int pci_bus;
@@ -617,6 +618,8 @@ struct cx8802_dev {
617/* ----------------------------------------------------------- */ 618/* ----------------------------------------------------------- */
618/* cx88-core.c */ 619/* cx88-core.c */
619 620
621extern unsigned int cx88_core_debug;
622
620extern void cx88_print_irqbits(const char *name, const char *tag, const char *strings[], 623extern void cx88_print_irqbits(const char *name, const char *tag, const char *strings[],
621 int len, u32 bits, u32 mask); 624 int len, u32 bits, u32 mask);
622 625
@@ -740,7 +743,7 @@ void cx8802_cancel_buffers(struct cx8802_dev *dev);
740/* ----------------------------------------------------------- */ 743/* ----------------------------------------------------------- */
741/* cx88-video.c*/ 744/* cx88-video.c*/
742int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i); 745int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i);
743int cx88_set_freq (struct cx88_core *core,struct v4l2_frequency *f); 746int cx88_set_freq(struct cx88_core *core, const struct v4l2_frequency *f);
744int cx88_video_mux(struct cx88_core *core, unsigned int input); 747int cx88_video_mux(struct cx88_core *core, unsigned int input);
745void cx88_querycap(struct file *file, struct cx88_core *core, 748void cx88_querycap(struct file *file, struct cx88_core *core,
746 struct v4l2_capability *cap); 749 struct v4l2_capability *cap);
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index 2928e7287da8..07b8460953b6 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -1387,7 +1387,7 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1387 if (!itv->has_cx23415) 1387 if (!itv->has_cx23415)
1388 write_reg_sync(0x03, IVTV_REG_DMACONTROL); 1388 write_reg_sync(0x03, IVTV_REG_DMACONTROL);
1389 1389
1390 ivtv_s_std_enc(itv, &itv->tuner_std); 1390 ivtv_s_std_enc(itv, itv->tuner_std);
1391 1391
1392 /* Default interrupts enabled. For the PVR350 this includes the 1392 /* Default interrupts enabled. For the PVR350 this includes the
1393 decoder VSYNC interrupt, which is always on. It is not only used 1393 decoder VSYNC interrupt, which is always on. It is not only used
@@ -1397,7 +1397,7 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1397 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { 1397 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1398 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT | IVTV_IRQ_DEC_VSYNC); 1398 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT | IVTV_IRQ_DEC_VSYNC);
1399 ivtv_set_osd_alpha(itv); 1399 ivtv_set_osd_alpha(itv);
1400 ivtv_s_std_dec(itv, &itv->tuner_std); 1400 ivtv_s_std_dec(itv, itv->tuner_std);
1401 } else { 1401 } else {
1402 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT); 1402 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT);
1403 } 1403 }
diff --git a/drivers/media/pci/ivtv/ivtv-firmware.c b/drivers/media/pci/ivtv/ivtv-firmware.c
index 68387d4369d6..ed73edd2bcd3 100644
--- a/drivers/media/pci/ivtv/ivtv-firmware.c
+++ b/drivers/media/pci/ivtv/ivtv-firmware.c
@@ -302,7 +302,7 @@ static int ivtv_firmware_restart(struct ivtv *itv)
302 /* Restore encoder video standard */ 302 /* Restore encoder video standard */
303 std = itv->std; 303 std = itv->std;
304 itv->std = 0; 304 itv->std = 0;
305 ivtv_s_std_enc(itv, &std); 305 ivtv_s_std_enc(itv, std);
306 306
307 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { 307 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
308 ivtv_init_mpeg_decoder(itv); 308 ivtv_init_mpeg_decoder(itv);
@@ -310,7 +310,7 @@ static int ivtv_firmware_restart(struct ivtv *itv)
310 /* Restore decoder video standard */ 310 /* Restore decoder video standard */
311 std = itv->std_out; 311 std = itv->std_out;
312 itv->std_out = 0; 312 itv->std_out = 0;
313 ivtv_s_std_dec(itv, &std); 313 ivtv_s_std_dec(itv, std);
314 314
315 /* Restore framebuffer if active */ 315 /* Restore framebuffer if active */
316 if (itv->ivtvfb_restore) 316 if (itv->ivtvfb_restore)
diff --git a/drivers/media/pci/ivtv/ivtv-gpio.c b/drivers/media/pci/ivtv/ivtv-gpio.c
index 8f0d07789053..af52def700cc 100644
--- a/drivers/media/pci/ivtv/ivtv-gpio.c
+++ b/drivers/media/pci/ivtv/ivtv-gpio.c
@@ -192,7 +192,7 @@ static int subdev_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
192 return 0; 192 return 0;
193} 193}
194 194
195static int subdev_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 195static int subdev_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
196{ 196{
197 struct ivtv *itv = sd_to_ivtv(sd); 197 struct ivtv *itv = sd_to_ivtv(sd);
198 u16 mask, data; 198 u16 mask, data;
diff --git a/drivers/media/pci/ivtv/ivtv-ioctl.c b/drivers/media/pci/ivtv/ivtv-ioctl.c
index 7a8b0d0b6127..9cbbce0eaedc 100644
--- a/drivers/media/pci/ivtv/ivtv-ioctl.c
+++ b/drivers/media/pci/ivtv/ivtv-ioctl.c
@@ -711,28 +711,26 @@ static int ivtv_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_i
711} 711}
712 712
713#ifdef CONFIG_VIDEO_ADV_DEBUG 713#ifdef CONFIG_VIDEO_ADV_DEBUG
714static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg) 714static int ivtv_itvc(struct ivtv *itv, bool get, u64 reg, u64 *val)
715{ 715{
716 struct v4l2_dbg_register *regs = arg;
717 volatile u8 __iomem *reg_start; 716 volatile u8 __iomem *reg_start;
718 717
719 if (!capable(CAP_SYS_ADMIN)) 718 if (!capable(CAP_SYS_ADMIN))
720 return -EPERM; 719 return -EPERM;
721 if (regs->reg >= IVTV_REG_OFFSET && regs->reg < IVTV_REG_OFFSET + IVTV_REG_SIZE) 720 if (reg >= IVTV_REG_OFFSET && reg < IVTV_REG_OFFSET + IVTV_REG_SIZE)
722 reg_start = itv->reg_mem - IVTV_REG_OFFSET; 721 reg_start = itv->reg_mem - IVTV_REG_OFFSET;
723 else if (itv->has_cx23415 && regs->reg >= IVTV_DECODER_OFFSET && 722 else if (itv->has_cx23415 && reg >= IVTV_DECODER_OFFSET &&
724 regs->reg < IVTV_DECODER_OFFSET + IVTV_DECODER_SIZE) 723 reg < IVTV_DECODER_OFFSET + IVTV_DECODER_SIZE)
725 reg_start = itv->dec_mem - IVTV_DECODER_OFFSET; 724 reg_start = itv->dec_mem - IVTV_DECODER_OFFSET;
726 else if (regs->reg < IVTV_ENCODER_SIZE) 725 else if (reg < IVTV_ENCODER_SIZE)
727 reg_start = itv->enc_mem; 726 reg_start = itv->enc_mem;
728 else 727 else
729 return -EINVAL; 728 return -EINVAL;
730 729
731 regs->size = 4; 730 if (get)
732 if (cmd == VIDIOC_DBG_G_REGISTER) 731 *val = readl(reg + reg_start);
733 regs->val = readl(regs->reg + reg_start);
734 else 732 else
735 writel(regs->val, regs->reg + reg_start); 733 writel(*val, reg + reg_start);
736 return 0; 734 return 0;
737} 735}
738 736
@@ -740,20 +738,25 @@ static int ivtv_g_register(struct file *file, void *fh, struct v4l2_dbg_register
740{ 738{
741 struct ivtv *itv = fh2id(fh)->itv; 739 struct ivtv *itv = fh2id(fh)->itv;
742 740
743 if (v4l2_chip_match_host(&reg->match)) 741 if (v4l2_chip_match_host(&reg->match)) {
744 return ivtv_itvc(itv, VIDIOC_DBG_G_REGISTER, reg); 742 reg->size = 4;
743 return ivtv_itvc(itv, true, reg->reg, &reg->val);
744 }
745 /* TODO: subdev errors should not be ignored, this should become a 745 /* TODO: subdev errors should not be ignored, this should become a
746 subdev helper function. */ 746 subdev helper function. */
747 ivtv_call_all(itv, core, g_register, reg); 747 ivtv_call_all(itv, core, g_register, reg);
748 return 0; 748 return 0;
749} 749}
750 750
751static int ivtv_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg) 751static int ivtv_s_register(struct file *file, void *fh, const struct v4l2_dbg_register *reg)
752{ 752{
753 struct ivtv *itv = fh2id(fh)->itv; 753 struct ivtv *itv = fh2id(fh)->itv;
754 754
755 if (v4l2_chip_match_host(&reg->match)) 755 if (v4l2_chip_match_host(&reg->match)) {
756 return ivtv_itvc(itv, VIDIOC_DBG_S_REGISTER, reg); 756 u64 val = reg->val;
757
758 return ivtv_itvc(itv, false, reg->reg, &val);
759 }
757 /* TODO: subdev errors should not be ignored, this should become a 760 /* TODO: subdev errors should not be ignored, this should become a
758 subdev helper function. */ 761 subdev helper function. */
759 ivtv_call_all(itv, core, s_register, reg); 762 ivtv_call_all(itv, core, s_register, reg);
@@ -1078,7 +1081,7 @@ static int ivtv_g_frequency(struct file *file, void *fh, struct v4l2_frequency *
1078 return 0; 1081 return 0;
1079} 1082}
1080 1083
1081int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf) 1084int ivtv_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf)
1082{ 1085{
1083 struct ivtv *itv = fh2id(fh)->itv; 1086 struct ivtv *itv = fh2id(fh)->itv;
1084 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type]; 1087 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
@@ -1103,10 +1106,10 @@ static int ivtv_g_std(struct file *file, void *fh, v4l2_std_id *std)
1103 return 0; 1106 return 0;
1104} 1107}
1105 1108
1106void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id *std) 1109void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id std)
1107{ 1110{
1108 itv->std = *std; 1111 itv->std = std;
1109 itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; 1112 itv->is_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
1110 itv->is_50hz = !itv->is_60hz; 1113 itv->is_50hz = !itv->is_60hz;
1111 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz); 1114 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1112 itv->cxhdl.width = 720; 1115 itv->cxhdl.width = 720;
@@ -1122,15 +1125,15 @@ void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id *std)
1122 ivtv_call_all(itv, core, s_std, itv->std); 1125 ivtv_call_all(itv, core, s_std, itv->std);
1123} 1126}
1124 1127
1125void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id *std) 1128void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id std)
1126{ 1129{
1127 struct yuv_playback_info *yi = &itv->yuv_info; 1130 struct yuv_playback_info *yi = &itv->yuv_info;
1128 DEFINE_WAIT(wait); 1131 DEFINE_WAIT(wait);
1129 int f; 1132 int f;
1130 1133
1131 /* set display standard */ 1134 /* set display standard */
1132 itv->std_out = *std; 1135 itv->std_out = std;
1133 itv->is_out_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; 1136 itv->is_out_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
1134 itv->is_out_50hz = !itv->is_out_60hz; 1137 itv->is_out_50hz = !itv->is_out_60hz;
1135 ivtv_call_all(itv, video, s_std_output, itv->std_out); 1138 ivtv_call_all(itv, video, s_std_output, itv->std_out);
1136 1139
@@ -1168,14 +1171,14 @@ void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id *std)
1168 } 1171 }
1169} 1172}
1170 1173
1171static int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std) 1174static int ivtv_s_std(struct file *file, void *fh, v4l2_std_id std)
1172{ 1175{
1173 struct ivtv *itv = fh2id(fh)->itv; 1176 struct ivtv *itv = fh2id(fh)->itv;
1174 1177
1175 if ((*std & V4L2_STD_ALL) == 0) 1178 if ((std & V4L2_STD_ALL) == 0)
1176 return -EINVAL; 1179 return -EINVAL;
1177 1180
1178 if (*std == itv->std) 1181 if (std == itv->std)
1179 return 0; 1182 return 0;
1180 1183
1181 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) || 1184 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ||
@@ -1196,7 +1199,7 @@ static int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1196 return 0; 1199 return 0;
1197} 1200}
1198 1201
1199static int ivtv_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) 1202static int ivtv_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
1200{ 1203{
1201 struct ivtv_open_id *id = fh2id(fh); 1204 struct ivtv_open_id *id = fh2id(fh);
1202 struct ivtv *itv = id->itv; 1205 struct ivtv *itv = id->itv;
@@ -1804,7 +1807,7 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1804} 1807}
1805 1808
1806static long ivtv_default(struct file *file, void *fh, bool valid_prio, 1809static long ivtv_default(struct file *file, void *fh, bool valid_prio,
1807 int cmd, void *arg) 1810 unsigned int cmd, void *arg)
1808{ 1811{
1809 struct ivtv *itv = fh2id(fh)->itv; 1812 struct ivtv *itv = fh2id(fh)->itv;
1810 1813
diff --git a/drivers/media/pci/ivtv/ivtv-ioctl.h b/drivers/media/pci/ivtv/ivtv-ioctl.h
index 7c553d16579b..75c397756116 100644
--- a/drivers/media/pci/ivtv/ivtv-ioctl.h
+++ b/drivers/media/pci/ivtv/ivtv-ioctl.h
@@ -27,9 +27,9 @@ u16 ivtv_get_service_set(struct v4l2_sliced_vbi_format *fmt);
27void ivtv_set_osd_alpha(struct ivtv *itv); 27void ivtv_set_osd_alpha(struct ivtv *itv);
28int ivtv_set_speed(struct ivtv *itv, int speed); 28int ivtv_set_speed(struct ivtv *itv, int speed);
29void ivtv_set_funcs(struct video_device *vdev); 29void ivtv_set_funcs(struct video_device *vdev);
30void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id *std); 30void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id std);
31void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id *std); 31void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id std);
32int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf); 32int ivtv_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf);
33int ivtv_s_input(struct file *file, void *fh, unsigned int inp); 33int ivtv_s_input(struct file *file, void *fh, unsigned int inp);
34 34
35#endif 35#endif
diff --git a/drivers/media/pci/ivtv/ivtvfb.c b/drivers/media/pci/ivtv/ivtvfb.c
index 05b94aa8ba32..9ff1230192e8 100644
--- a/drivers/media/pci/ivtv/ivtvfb.c
+++ b/drivers/media/pci/ivtv/ivtvfb.c
@@ -1171,8 +1171,7 @@ static void ivtvfb_release_buffers (struct ivtv *itv)
1171 fb_dealloc_cmap(&oi->ivtvfb_info.cmap); 1171 fb_dealloc_cmap(&oi->ivtvfb_info.cmap);
1172 1172
1173 /* Release pseudo palette */ 1173 /* Release pseudo palette */
1174 if (oi->ivtvfb_info.pseudo_palette) 1174 kfree(oi->ivtvfb_info.pseudo_palette);
1175 kfree(oi->ivtvfb_info.pseudo_palette);
1176 1175
1177#ifdef CONFIG_MTRR 1176#ifdef CONFIG_MTRR
1178 if (oi->fb_end_aligned_physaddr) { 1177 if (oi->fb_end_aligned_physaddr) {
diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c
index 7859c43479d7..2381b05432e6 100644
--- a/drivers/media/pci/meye/meye.c
+++ b/drivers/media/pci/meye/meye.c
@@ -1410,7 +1410,7 @@ static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
1410} 1410}
1411 1411
1412static long vidioc_default(struct file *file, void *fh, bool valid_prio, 1412static long vidioc_default(struct file *file, void *fh, bool valid_prio,
1413 int cmd, void *arg) 1413 unsigned int cmd, void *arg)
1414{ 1414{
1415 switch (cmd) { 1415 switch (cmd) {
1416 case MEYEIOC_G_PARAMS: 1416 case MEYEIOC_G_PARAMS:
diff --git a/drivers/media/pci/saa7134/saa7134-cards.c b/drivers/media/pci/saa7134/saa7134-cards.c
index dc68cf1070f7..d45e7f6ff332 100644
--- a/drivers/media/pci/saa7134/saa7134-cards.c
+++ b/drivers/media/pci/saa7134/saa7134-cards.c
@@ -50,6 +50,11 @@ static char name_svideo[] = "S-Video";
50/* ------------------------------------------------------------------ */ 50/* ------------------------------------------------------------------ */
51/* board config info */ 51/* board config info */
52 52
53static struct tda18271_std_map aver_a706_std_map = {
54 .fm_radio = { .if_freq = 5500, .fm_rfn = 0, .agc_mode = 3, .std = 0,
55 .if_lvl = 0, .rfagc_top = 0x2c, },
56};
57
53/* If radio_type !=UNSET, radio_addr should be specified 58/* If radio_type !=UNSET, radio_addr should be specified
54 */ 59 */
55 60
@@ -2760,7 +2765,7 @@ struct saa7134_board saa7134_boards[] = {
2760 .radio_type = UNSET, 2765 .radio_type = UNSET,
2761 .tuner_addr = ADDR_UNSET, 2766 .tuner_addr = ADDR_UNSET,
2762 .radio_addr = ADDR_UNSET, 2767 .radio_addr = ADDR_UNSET,
2763 .tuner_config = 0, 2768 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF },
2764 .mpeg = SAA7134_MPEG_DVB, 2769 .mpeg = SAA7134_MPEG_DVB,
2765 .gpiomask = 0x0200000, 2770 .gpiomask = 0x0200000,
2766 .inputs = {{ 2771 .inputs = {{
@@ -3291,7 +3296,7 @@ struct saa7134_board saa7134_boards[] = {
3291 .radio_type = UNSET, 3296 .radio_type = UNSET,
3292 .tuner_addr = ADDR_UNSET, 3297 .tuner_addr = ADDR_UNSET,
3293 .radio_addr = ADDR_UNSET, 3298 .radio_addr = ADDR_UNSET,
3294 .tuner_config = 1, 3299 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_ON },
3295 .mpeg = SAA7134_MPEG_DVB, 3300 .mpeg = SAA7134_MPEG_DVB,
3296 .gpiomask = 0x000200000, 3301 .gpiomask = 0x000200000,
3297 .inputs = {{ 3302 .inputs = {{
@@ -3395,7 +3400,7 @@ struct saa7134_board saa7134_boards[] = {
3395 .radio_type = UNSET, 3400 .radio_type = UNSET,
3396 .tuner_addr = ADDR_UNSET, 3401 .tuner_addr = ADDR_UNSET,
3397 .radio_addr = ADDR_UNSET, 3402 .radio_addr = ADDR_UNSET,
3398 .tuner_config = 1, 3403 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_ON },
3399 .mpeg = SAA7134_MPEG_DVB, 3404 .mpeg = SAA7134_MPEG_DVB,
3400 .gpiomask = 0x0200100, 3405 .gpiomask = 0x0200100,
3401 .inputs = {{ 3406 .inputs = {{
@@ -3426,7 +3431,7 @@ struct saa7134_board saa7134_boards[] = {
3426 .radio_type = UNSET, 3431 .radio_type = UNSET,
3427 .tuner_addr = ADDR_UNSET, 3432 .tuner_addr = ADDR_UNSET,
3428 .radio_addr = ADDR_UNSET, 3433 .radio_addr = ADDR_UNSET,
3429 .tuner_config = 3, 3434 .tda829x_conf = { .lna_cfg = TDA8290_LNA_ON_BRIDGE },
3430 .mpeg = SAA7134_MPEG_DVB, 3435 .mpeg = SAA7134_MPEG_DVB,
3431 .ts_type = SAA7134_MPEG_TS_SERIAL, 3436 .ts_type = SAA7134_MPEG_TS_SERIAL,
3432 .ts_force_val = 1, 3437 .ts_force_val = 1,
@@ -3459,7 +3464,7 @@ struct saa7134_board saa7134_boards[] = {
3459 .radio_type = UNSET, 3464 .radio_type = UNSET,
3460 .tuner_addr = ADDR_UNSET, 3465 .tuner_addr = ADDR_UNSET,
3461 .radio_addr = ADDR_UNSET, 3466 .radio_addr = ADDR_UNSET,
3462 .tuner_config = 3, 3467 .tda829x_conf = { .lna_cfg = TDA8290_LNA_ON_BRIDGE },
3463 .mpeg = SAA7134_MPEG_DVB, 3468 .mpeg = SAA7134_MPEG_DVB,
3464 .ts_type = SAA7134_MPEG_TS_SERIAL, 3469 .ts_type = SAA7134_MPEG_TS_SERIAL,
3465 .gpiomask = 0x0800100, /* GPIO 21 is an INPUT */ 3470 .gpiomask = 0x0800100, /* GPIO 21 is an INPUT */
@@ -3683,7 +3688,7 @@ struct saa7134_board saa7134_boards[] = {
3683 .radio_type = UNSET, 3688 .radio_type = UNSET,
3684 .tuner_addr = ADDR_UNSET, 3689 .tuner_addr = ADDR_UNSET,
3685 .radio_addr = ADDR_UNSET, 3690 .radio_addr = ADDR_UNSET,
3686 .tuner_config = 2, 3691 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
3687 .mpeg = SAA7134_MPEG_DVB, 3692 .mpeg = SAA7134_MPEG_DVB,
3688 .gpiomask = 0x0200000, 3693 .gpiomask = 0x0200000,
3689 .inputs = {{ 3694 .inputs = {{
@@ -3736,7 +3741,7 @@ struct saa7134_board saa7134_boards[] = {
3736 .radio_type = UNSET, 3741 .radio_type = UNSET,
3737 .tuner_addr = ADDR_UNSET, 3742 .tuner_addr = ADDR_UNSET,
3738 .radio_addr = ADDR_UNSET, 3743 .radio_addr = ADDR_UNSET,
3739 .tuner_config = 2, 3744 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
3740 .mpeg = SAA7134_MPEG_DVB, 3745 .mpeg = SAA7134_MPEG_DVB,
3741 .gpiomask = 0x0200000, 3746 .gpiomask = 0x0200000,
3742 .inputs = {{ 3747 .inputs = {{
@@ -3754,7 +3759,7 @@ struct saa7134_board saa7134_boards[] = {
3754 .radio_type = UNSET, 3759 .radio_type = UNSET,
3755 .tuner_addr = ADDR_UNSET, 3760 .tuner_addr = ADDR_UNSET,
3756 .radio_addr = ADDR_UNSET, 3761 .radio_addr = ADDR_UNSET,
3757 .tuner_config = 2, 3762 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
3758 .gpiomask = 1 << 21, 3763 .gpiomask = 1 << 21,
3759 .mpeg = SAA7134_MPEG_DVB, 3764 .mpeg = SAA7134_MPEG_DVB,
3760 .inputs = {{ 3765 .inputs = {{
@@ -3887,7 +3892,7 @@ struct saa7134_board saa7134_boards[] = {
3887 .radio_type = UNSET, 3892 .radio_type = UNSET,
3888 .tuner_addr = ADDR_UNSET, 3893 .tuner_addr = ADDR_UNSET,
3889 .radio_addr = ADDR_UNSET, 3894 .radio_addr = ADDR_UNSET,
3890 .tuner_config = 0, 3895 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF },
3891 .mpeg = SAA7134_MPEG_DVB, 3896 .mpeg = SAA7134_MPEG_DVB,
3892 .inputs = {{ 3897 .inputs = {{
3893 .name = name_tv, /* FIXME: analog tv untested */ 3898 .name = name_tv, /* FIXME: analog tv untested */
@@ -3903,7 +3908,7 @@ struct saa7134_board saa7134_boards[] = {
3903 .radio_type = UNSET, 3908 .radio_type = UNSET,
3904 .tuner_addr = ADDR_UNSET, 3909 .tuner_addr = ADDR_UNSET,
3905 .radio_addr = ADDR_UNSET, 3910 .radio_addr = ADDR_UNSET,
3906 .tuner_config = 2, 3911 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
3907 .gpiomask = 0x020200000, 3912 .gpiomask = 0x020200000,
3908 .inputs = {{ 3913 .inputs = {{
3909 .name = name_tv, 3914 .name = name_tv,
@@ -3937,7 +3942,7 @@ struct saa7134_board saa7134_boards[] = {
3937 .radio_type = UNSET, 3942 .radio_type = UNSET,
3938 .tuner_addr = ADDR_UNSET, 3943 .tuner_addr = ADDR_UNSET,
3939 .radio_addr = ADDR_UNSET, 3944 .radio_addr = ADDR_UNSET,
3940 .tuner_config = 0, 3945 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF },
3941 .gpiomask = 0x020200000, 3946 .gpiomask = 0x020200000,
3942 .inputs = {{ 3947 .inputs = {{
3943 .name = name_tv, 3948 .name = name_tv,
@@ -4737,7 +4742,7 @@ struct saa7134_board saa7134_boards[] = {
4737 .radio_type = UNSET, 4742 .radio_type = UNSET,
4738 .tuner_addr = ADDR_UNSET, 4743 .tuner_addr = ADDR_UNSET,
4739 .radio_addr = ADDR_UNSET, 4744 .radio_addr = ADDR_UNSET,
4740 .tuner_config = 2, 4745 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
4741 .mpeg = SAA7134_MPEG_DVB, 4746 .mpeg = SAA7134_MPEG_DVB,
4742 .gpiomask = 0x0200000, 4747 .gpiomask = 0x0200000,
4743 .inputs = {{ 4748 .inputs = {{
@@ -4823,7 +4828,7 @@ struct saa7134_board saa7134_boards[] = {
4823 .radio_type = UNSET, 4828 .radio_type = UNSET,
4824 .tuner_addr = ADDR_UNSET, 4829 .tuner_addr = ADDR_UNSET,
4825 .radio_addr = ADDR_UNSET, 4830 .radio_addr = ADDR_UNSET,
4826 .tuner_config = 0, 4831 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF },
4827 .mpeg = SAA7134_MPEG_DVB, 4832 .mpeg = SAA7134_MPEG_DVB,
4828 .inputs = {{ 4833 .inputs = {{
4829 .name = name_tv, 4834 .name = name_tv,
@@ -4847,7 +4852,7 @@ struct saa7134_board saa7134_boards[] = {
4847 .radio_type = UNSET, 4852 .radio_type = UNSET,
4848 .tuner_addr = ADDR_UNSET, 4853 .tuner_addr = ADDR_UNSET,
4849 .radio_addr = ADDR_UNSET, 4854 .radio_addr = ADDR_UNSET,
4850 .tuner_config = 2, 4855 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
4851 .mpeg = SAA7134_MPEG_DVB, 4856 .mpeg = SAA7134_MPEG_DVB,
4852 .gpiomask = 0x0200000, 4857 .gpiomask = 0x0200000,
4853 .inputs = { { 4858 .inputs = { {
@@ -5057,7 +5062,7 @@ struct saa7134_board saa7134_boards[] = {
5057 .radio_type = UNSET, 5062 .radio_type = UNSET,
5058 .tuner_addr = ADDR_UNSET, 5063 .tuner_addr = ADDR_UNSET,
5059 .radio_addr = ADDR_UNSET, 5064 .radio_addr = ADDR_UNSET,
5060 .tuner_config = 2, 5065 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
5061 .gpiomask = 1 << 21, 5066 .gpiomask = 1 << 21,
5062 .mpeg = SAA7134_MPEG_DVB, 5067 .mpeg = SAA7134_MPEG_DVB,
5063 .inputs = {{ 5068 .inputs = {{
@@ -5087,7 +5092,7 @@ struct saa7134_board saa7134_boards[] = {
5087 .radio_type = UNSET, 5092 .radio_type = UNSET,
5088 .tuner_addr = ADDR_UNSET, 5093 .tuner_addr = ADDR_UNSET,
5089 .radio_addr = ADDR_UNSET, 5094 .radio_addr = ADDR_UNSET,
5090 .tuner_config = 2, 5095 .tda829x_conf = { .lna_cfg = TDA8290_LNA_GP0_HIGH_OFF },
5091 .gpiomask = 1 << 21, 5096 .gpiomask = 1 << 21,
5092 .mpeg = SAA7134_MPEG_DVB, 5097 .mpeg = SAA7134_MPEG_DVB,
5093 .inputs = {{ 5098 .inputs = {{
@@ -5176,7 +5181,7 @@ struct saa7134_board saa7134_boards[] = {
5176 .radio_type = UNSET, 5181 .radio_type = UNSET,
5177 .tuner_addr = ADDR_UNSET, 5182 .tuner_addr = ADDR_UNSET,
5178 .radio_addr = ADDR_UNSET, 5183 .radio_addr = ADDR_UNSET,
5179 .tuner_config = 0, 5184 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF },
5180 .mpeg = SAA7134_MPEG_DVB, 5185 .mpeg = SAA7134_MPEG_DVB,
5181 .gpiomask = 0x0200000, 5186 .gpiomask = 0x0200000,
5182 .inputs = { { 5187 .inputs = { {
@@ -5406,7 +5411,7 @@ struct saa7134_board saa7134_boards[] = {
5406 .radio_type = UNSET, 5411 .radio_type = UNSET,
5407 .tuner_addr = ADDR_UNSET, 5412 .tuner_addr = ADDR_UNSET,
5408 .radio_addr = ADDR_UNSET, 5413 .radio_addr = ADDR_UNSET,
5409 .tuner_config = 0, 5414 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF },
5410 .mpeg = SAA7134_MPEG_DVB, 5415 .mpeg = SAA7134_MPEG_DVB,
5411 .ts_type = SAA7134_MPEG_TS_PARALLEL, 5416 .ts_type = SAA7134_MPEG_TS_PARALLEL,
5412 .inputs = {{ 5417 .inputs = {{
@@ -5629,7 +5634,7 @@ struct saa7134_board saa7134_boards[] = {
5629 .audio_clock = 0x00187de7, 5634 .audio_clock = 0x00187de7,
5630 .tuner_type = TUNER_PHILIPS_TDA8290, 5635 .tuner_type = TUNER_PHILIPS_TDA8290,
5631 .radio_type = UNSET, 5636 .radio_type = UNSET,
5632 .tuner_config = 3, 5637 .tda829x_conf = { .lna_cfg = TDA8290_LNA_ON_BRIDGE },
5633 .tuner_addr = ADDR_UNSET, 5638 .tuner_addr = ADDR_UNSET,
5634 .radio_addr = ADDR_UNSET, 5639 .radio_addr = ADDR_UNSET,
5635 .gpiomask = 0x02050000, 5640 .gpiomask = 0x02050000,
@@ -5790,6 +5795,38 @@ struct saa7134_board saa7134_boards[] = {
5790 .gpio = 0x6010000, 5795 .gpio = 0x6010000,
5791 } }, 5796 } },
5792 }, 5797 },
5798 [SAA7134_BOARD_AVERMEDIA_A706] = {
5799 .name = "AverMedia AverTV Satellite Hybrid+FM A706",
5800 .audio_clock = 0x00187de7,
5801 .tuner_type = TUNER_PHILIPS_TDA8290,
5802 .radio_type = UNSET,
5803 .tuner_addr = ADDR_UNSET,
5804 .radio_addr = ADDR_UNSET,
5805 .tda829x_conf = { .lna_cfg = TDA8290_LNA_OFF,
5806 .no_i2c_gate = 1,
5807 .tda18271_std_map = &aver_a706_std_map },
5808 .gpiomask = 1 << 11,
5809 .mpeg = SAA7134_MPEG_DVB,
5810 .inputs = {{
5811 .name = name_tv,
5812 .vmux = 1,
5813 .amux = TV,
5814 .tv = 1,
5815 }, {
5816 .name = name_comp,
5817 .vmux = 4,
5818 .amux = LINE1,
5819 }, {
5820 .name = name_svideo,
5821 .vmux = 8,
5822 .amux = LINE1,
5823 } },
5824 .radio = {
5825 .name = name_radio,
5826 .amux = TV,
5827 .gpio = 0x0000800,
5828 },
5829 },
5793 5830
5794}; 5831};
5795 5832
@@ -7037,6 +7074,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
7037 .subdevice = 0x0911, 7074 .subdevice = 0x0911,
7038 .driver_data = SAA7134_BOARD_SENSORAY811_911, 7075 .driver_data = SAA7134_BOARD_SENSORAY811_911,
7039 }, { 7076 }, {
7077 .vendor = PCI_VENDOR_ID_PHILIPS,
7078 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
7079 .subvendor = 0x1461, /* Avermedia Technologies Inc */
7080 .subdevice = 0x2055, /* AverTV Satellite Hybrid+FM A706 */
7081 .driver_data = SAA7134_BOARD_AVERMEDIA_A706,
7082 }, {
7040 /* --- boards without eeprom + subsystem ID --- */ 7083 /* --- boards without eeprom + subsystem ID --- */
7041 .vendor = PCI_VENDOR_ID_PHILIPS, 7084 .vendor = PCI_VENDOR_ID_PHILIPS,
7042 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 7085 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -7585,6 +7628,17 @@ int saa7134_board_init1(struct saa7134_dev *dev)
7585 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100); 7628 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100);
7586 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100); 7629 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100);
7587 break; 7630 break;
7631 case SAA7134_BOARD_AVERMEDIA_A706:
7632 /* radio antenna select: tristate both as in Windows driver */
7633 saa7134_set_gpio(dev, 12, 3); /* TV antenna */
7634 saa7134_set_gpio(dev, 13, 3); /* FM antenna */
7635 dev->has_remote = SAA7134_REMOTE_I2C;
7636 /*
7637 * Disable CE5039 DVB-S tuner now (SLEEP pin high) to prevent
7638 * it from interfering with analog tuner detection
7639 */
7640 saa7134_set_gpio(dev, 23, 1);
7641 break;
7588 case SAA7134_BOARD_VIDEOMATE_S350: 7642 case SAA7134_BOARD_VIDEOMATE_S350:
7589 dev->has_remote = SAA7134_REMOTE_GPIO; 7643 dev->has_remote = SAA7134_REMOTE_GPIO;
7590 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x0000C000, 0x0000C000); 7644 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x0000C000, 0x0000C000);
@@ -7633,7 +7687,7 @@ static void saa7134_tuner_setup(struct saa7134_dev *dev)
7633 if ((dev->tuner_type != TUNER_ABSENT) && (dev->tuner_type != UNSET)) { 7687 if ((dev->tuner_type != TUNER_ABSENT) && (dev->tuner_type != UNSET)) {
7634 tun_setup.type = dev->tuner_type; 7688 tun_setup.type = dev->tuner_type;
7635 tun_setup.addr = dev->tuner_addr; 7689 tun_setup.addr = dev->tuner_addr;
7636 tun_setup.config = saa7134_boards[dev->board].tuner_config; 7690 tun_setup.config = &saa7134_boards[dev->board].tda829x_conf;
7637 tun_setup.tuner_callback = saa7134_tuner_callback; 7691 tun_setup.tuner_callback = saa7134_tuner_callback;
7638 7692
7639 tun_setup.mode_mask = mode_mask; 7693 tun_setup.mode_mask = mode_mask;
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index 8fd24e7c9403..45f0aca597ae 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -805,6 +805,7 @@ static struct video_device *vdev_init(struct saa7134_dev *dev,
805 vfd->debug = video_debug; 805 vfd->debug = video_debug;
806 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 806 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
807 dev->name, type, saa7134_boards[dev->board].name); 807 dev->name, type, saa7134_boards[dev->board].name);
808 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
808 video_set_drvdata(vfd, dev); 809 video_set_drvdata(vfd, dev);
809 return vfd; 810 return vfd;
810} 811}
@@ -1028,8 +1029,6 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1028 } 1029 }
1029 } 1030 }
1030 1031
1031 v4l2_prio_init(&dev->prio);
1032
1033 mutex_lock(&saa7134_devlist_lock); 1032 mutex_lock(&saa7134_devlist_lock);
1034 list_for_each_entry(mops, &mops_list, next) 1033 list_for_each_entry(mops, &mops_list, next)
1035 mpeg_ops_attach(mops, dev); 1034 mpeg_ops_attach(mops, dev);
diff --git a/drivers/media/pci/saa7134/saa7134-dvb.c b/drivers/media/pci/saa7134/saa7134-dvb.c
index 27915e501db9..4a08ae31df2e 100644
--- a/drivers/media/pci/saa7134/saa7134-dvb.c
+++ b/drivers/media/pci/saa7134/saa7134-dvb.c
@@ -1073,6 +1073,10 @@ static struct mt312_config zl10313_compro_s350_config = {
1073 .demod_address = 0x0e, 1073 .demod_address = 0x0e,
1074}; 1074};
1075 1075
1076static struct mt312_config zl10313_avermedia_a706_config = {
1077 .demod_address = 0x0e,
1078};
1079
1076static struct lgdt3305_config hcw_lgdt3305_config = { 1080static struct lgdt3305_config hcw_lgdt3305_config = {
1077 .i2c_addr = 0x0e, 1081 .i2c_addr = 0x0e,
1078 .mpeg_mode = LGDT3305_MPEG_SERIAL, 1082 .mpeg_mode = LGDT3305_MPEG_SERIAL,
@@ -1391,8 +1395,9 @@ static int dvb_init(struct saa7134_dev *dev)
1391 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__); 1395 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
1392 goto detach_frontend; 1396 goto detach_frontend;
1393 } 1397 }
1394 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap, 1398 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1395 0x08, 0, 0) == NULL) { 1399 &dev->i2c_adap,
1400 0x08, 0, 0, false) == NULL) {
1396 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__); 1401 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
1397 goto detach_frontend; 1402 goto detach_frontend;
1398 } 1403 }
@@ -1509,7 +1514,8 @@ static int dvb_init(struct saa7134_dev *dev)
1509 goto detach_frontend; 1514 goto detach_frontend;
1510 } 1515 }
1511 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, 1516 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1512 &dev->i2c_adap, 0x08, 0, 0) == NULL) { 1517 &dev->i2c_adap,
1518 0x08, 0, 0, false) == NULL) {
1513 wprintk("%s: No ISL6421 found!\n", __func__); 1519 wprintk("%s: No ISL6421 found!\n", __func__);
1514 goto detach_frontend; 1520 goto detach_frontend;
1515 } 1521 }
@@ -1820,6 +1826,25 @@ static int dvb_init(struct saa7134_dev *dev)
1820 &prohdtv_pro2_tda18271_config); 1826 &prohdtv_pro2_tda18271_config);
1821 } 1827 }
1822 break; 1828 break;
1829 case SAA7134_BOARD_AVERMEDIA_A706:
1830 /* Enable all DVB-S devices now */
1831 /* CE5039 DVB-S tuner SLEEP pin low */
1832 saa7134_set_gpio(dev, 23, 0);
1833 /* CE6313 DVB-S demod SLEEP pin low */
1834 saa7134_set_gpio(dev, 9, 0);
1835 /* CE6313 DVB-S demod RESET# pin high */
1836 saa7134_set_gpio(dev, 25, 1);
1837 msleep(1);
1838 fe0->dvb.frontend = dvb_attach(mt312_attach,
1839 &zl10313_avermedia_a706_config, &dev->i2c_adap);
1840 if (fe0->dvb.frontend) {
1841 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1842 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1843 0x60, &dev->i2c_adap) == NULL)
1844 wprintk("%s: No zl10039 found!\n",
1845 __func__);
1846 }
1847 break;
1823 default: 1848 default:
1824 wprintk("Huh? unknown DVB card?\n"); 1849 wprintk("Huh? unknown DVB card?\n");
1825 break; 1850 break;
diff --git a/drivers/media/pci/saa7134/saa7134-empress.c b/drivers/media/pci/saa7134/saa7134-empress.c
index 4df79c656909..66a70814004c 100644
--- a/drivers/media/pci/saa7134/saa7134-empress.c
+++ b/drivers/media/pci/saa7134/saa7134-empress.c
@@ -428,7 +428,7 @@ static int empress_g_chip_ident(struct file *file, void *fh,
428 return -EINVAL; 428 return -EINVAL;
429} 429}
430 430
431static int empress_s_std(struct file *file, void *priv, v4l2_std_id *id) 431static int empress_s_std(struct file *file, void *priv, v4l2_std_id id)
432{ 432{
433 struct saa7134_dev *dev = file->private_data; 433 struct saa7134_dev *dev = file->private_data;
434 434
diff --git a/drivers/media/pci/saa7134/saa7134-i2c.c b/drivers/media/pci/saa7134/saa7134-i2c.c
index a176ec3285e0..c68169d75804 100644
--- a/drivers/media/pci/saa7134/saa7134-i2c.c
+++ b/drivers/media/pci/saa7134/saa7134-i2c.c
@@ -256,6 +256,7 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
256 addr |= 1; 256 addr |= 1;
257 if (i > 0 && msgs[i].flags & 257 if (i > 0 && msgs[i].flags &
258 I2C_M_RD && msgs[i].addr != 0x40 && 258 I2C_M_RD && msgs[i].addr != 0x40 &&
259 msgs[i].addr != 0x41 &&
259 msgs[i].addr != 0x19) { 260 msgs[i].addr != 0x19) {
260 /* workaround for a saa7134 i2c bug 261 /* workaround for a saa7134 i2c bug
261 * needed to talk to the mt352 demux 262 * needed to talk to the mt352 demux
diff --git a/drivers/media/pci/saa7134/saa7134-input.c b/drivers/media/pci/saa7134/saa7134-input.c
index e761262f7475..6f4312663bdf 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -997,6 +997,9 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
997 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: 997 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
998 info.addr = 0x40; 998 info.addr = 0x40;
999 break; 999 break;
1000 case SAA7134_BOARD_AVERMEDIA_A706:
1001 info.addr = 0x41;
1002 break;
1000 case SAA7134_BOARD_FLYDVB_TRIO: 1003 case SAA7134_BOARD_FLYDVB_TRIO:
1001 dev->init_data.name = "FlyDVB Trio"; 1004 dev->init_data.name = "FlyDVB Trio";
1002 dev->init_data.get_key = get_key_flydvb_trio; 1005 dev->init_data.get_key = get_key_flydvb_trio;
diff --git a/drivers/media/pci/saa7134/saa7134-tvaudio.c b/drivers/media/pci/saa7134/saa7134-tvaudio.c
index b7a99bee2f98..0f34e09d98dc 100644
--- a/drivers/media/pci/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/pci/saa7134/saa7134-tvaudio.c
@@ -796,6 +796,7 @@ static int tvaudio_thread_ddep(void *data)
796 dprintk("FM Radio\n"); 796 dprintk("FM Radio\n");
797 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) { 797 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) {
798 norms = (0x11 << 2) | 0x01; 798 norms = (0x11 << 2) | 0x01;
799 /* set IF frequency to 5.5 MHz */
799 saa_dsp_writel(dev, 0x42c >> 2, 0x729555); 800 saa_dsp_writel(dev, 0x42c >> 2, 0x729555);
800 } else { 801 } else {
801 norms = (0x0f << 2) | 0x01; 802 norms = (0x0f << 2) | 0x01;
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 7c503fb68526..cc409380ee16 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -1176,14 +1176,6 @@ int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, str
1176 int restart_overlay = 0; 1176 int restart_overlay = 0;
1177 int err; 1177 int err;
1178 1178
1179 /* When called from the empress code fh == NULL.
1180 That needs to be fixed somehow, but for now this is
1181 good enough. */
1182 if (fh) {
1183 err = v4l2_prio_check(&dev->prio, fh->prio);
1184 if (0 != err)
1185 return err;
1186 }
1187 err = -EINVAL; 1179 err = -EINVAL;
1188 1180
1189 mutex_lock(&dev->lock); 1181 mutex_lock(&dev->lock);
@@ -1352,6 +1344,7 @@ static int video_open(struct file *file)
1352 if (NULL == fh) 1344 if (NULL == fh)
1353 return -ENOMEM; 1345 return -ENOMEM;
1354 1346
1347 v4l2_fh_init(&fh->fh, vdev);
1355 file->private_data = fh; 1348 file->private_data = fh;
1356 fh->dev = dev; 1349 fh->dev = dev;
1357 fh->radio = radio; 1350 fh->radio = radio;
@@ -1359,7 +1352,6 @@ static int video_open(struct file *file)
1359 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); 1352 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
1360 fh->width = 720; 1353 fh->width = 720;
1361 fh->height = 576; 1354 fh->height = 576;
1362 v4l2_prio_open(&dev->prio, &fh->prio);
1363 1355
1364 videobuf_queue_sg_init(&fh->cap, &video_qops, 1356 videobuf_queue_sg_init(&fh->cap, &video_qops,
1365 &dev->pci->dev, &dev->slock, 1357 &dev->pci->dev, &dev->slock,
@@ -1384,6 +1376,8 @@ static int video_open(struct file *file)
1384 /* switch to video/vbi mode */ 1376 /* switch to video/vbi mode */
1385 video_mux(dev,dev->ctl_input); 1377 video_mux(dev,dev->ctl_input);
1386 } 1378 }
1379 v4l2_fh_add(&fh->fh);
1380
1387 return 0; 1381 return 0;
1388} 1382}
1389 1383
@@ -1504,7 +1498,8 @@ static int video_release(struct file *file)
1504 saa7134_pgtable_free(dev->pci,&fh->pt_cap); 1498 saa7134_pgtable_free(dev->pci,&fh->pt_cap);
1505 saa7134_pgtable_free(dev->pci,&fh->pt_vbi); 1499 saa7134_pgtable_free(dev->pci,&fh->pt_vbi);
1506 1500
1507 v4l2_prio_close(&dev->prio, fh->prio); 1501 v4l2_fh_del(&fh->fh);
1502 v4l2_fh_exit(&fh->fh);
1508 file->private_data = NULL; 1503 file->private_data = NULL;
1509 kfree(fh); 1504 kfree(fh);
1510 return 0; 1505 return 0;
@@ -1557,6 +1552,7 @@ static int saa7134_try_get_set_fmt_vbi_cap(struct file *file, void *priv,
1557 struct saa7134_dev *dev = fh->dev; 1552 struct saa7134_dev *dev = fh->dev;
1558 struct saa7134_tvnorm *norm = dev->tvnorm; 1553 struct saa7134_tvnorm *norm = dev->tvnorm;
1559 1554
1555 memset(&f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
1560 f->fmt.vbi.sampling_rate = 6750000 * 4; 1556 f->fmt.vbi.sampling_rate = 6750000 * 4;
1561 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */; 1557 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */;
1562 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1558 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
@@ -1755,7 +1751,6 @@ static int saa7134_enum_input(struct file *file, void *priv,
1755 strcpy(i->name, card_in(dev, n).name); 1751 strcpy(i->name, card_in(dev, n).name);
1756 if (card_in(dev, n).tv) 1752 if (card_in(dev, n).tv)
1757 i->type = V4L2_INPUT_TYPE_TUNER; 1753 i->type = V4L2_INPUT_TYPE_TUNER;
1758 i->audioset = 1;
1759 if (n == dev->ctl_input) { 1754 if (n == dev->ctl_input) {
1760 int v1 = saa_readb(SAA7134_STATUS_VIDEO1); 1755 int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
1761 int v2 = saa_readb(SAA7134_STATUS_VIDEO2); 1756 int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
@@ -1784,11 +1779,6 @@ static int saa7134_s_input(struct file *file, void *priv, unsigned int i)
1784{ 1779{
1785 struct saa7134_fh *fh = priv; 1780 struct saa7134_fh *fh = priv;
1786 struct saa7134_dev *dev = fh->dev; 1781 struct saa7134_dev *dev = fh->dev;
1787 int err;
1788
1789 err = v4l2_prio_check(&dev->prio, fh->prio);
1790 if (0 != err)
1791 return err;
1792 1782
1793 if (i >= SAA7134_INPUT_MAX) 1783 if (i >= SAA7134_INPUT_MAX)
1794 return -EINVAL; 1784 return -EINVAL;
@@ -1805,6 +1795,8 @@ static int saa7134_querycap(struct file *file, void *priv,
1805{ 1795{
1806 struct saa7134_fh *fh = priv; 1796 struct saa7134_fh *fh = priv;
1807 struct saa7134_dev *dev = fh->dev; 1797 struct saa7134_dev *dev = fh->dev;
1798 struct video_device *vdev = video_devdata(file);
1799 u32 radio_caps, video_caps, vbi_caps;
1808 1800
1809 unsigned int tuner_type = dev->tuner_type; 1801 unsigned int tuner_type = dev->tuner_type;
1810 1802
@@ -1812,54 +1804,67 @@ static int saa7134_querycap(struct file *file, void *priv,
1812 strlcpy(cap->card, saa7134_boards[dev->board].name, 1804 strlcpy(cap->card, saa7134_boards[dev->board].name,
1813 sizeof(cap->card)); 1805 sizeof(cap->card));
1814 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); 1806 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
1815 cap->capabilities = 1807
1816 V4L2_CAP_VIDEO_CAPTURE | 1808 cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1817 V4L2_CAP_VBI_CAPTURE | 1809 if ((tuner_type != TUNER_ABSENT) && (tuner_type != UNSET))
1818 V4L2_CAP_READWRITE | 1810 cap->device_caps |= V4L2_CAP_TUNER;
1819 V4L2_CAP_STREAMING | 1811
1820 V4L2_CAP_TUNER; 1812 radio_caps = V4L2_CAP_RADIO;
1821 if (dev->has_rds) 1813 if (dev->has_rds)
1822 cap->capabilities |= V4L2_CAP_RDS_CAPTURE; 1814 radio_caps |= V4L2_CAP_RDS_CAPTURE;
1815
1816 video_caps = V4L2_CAP_VIDEO_CAPTURE;
1823 if (saa7134_no_overlay <= 0) 1817 if (saa7134_no_overlay <= 0)
1824 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; 1818 video_caps |= V4L2_CAP_VIDEO_OVERLAY;
1819
1820 vbi_caps = V4L2_CAP_VBI_CAPTURE;
1821
1822 switch (vdev->vfl_type) {
1823 case VFL_TYPE_RADIO:
1824 cap->device_caps |= radio_caps;
1825 break;
1826 case VFL_TYPE_GRABBER:
1827 cap->device_caps |= video_caps;
1828 break;
1829 case VFL_TYPE_VBI:
1830 cap->device_caps |= vbi_caps;
1831 break;
1832 }
1833 cap->capabilities = radio_caps | video_caps | vbi_caps |
1834 cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1835 if (vdev->vfl_type == VFL_TYPE_RADIO) {
1836 cap->device_caps &= ~V4L2_CAP_STREAMING;
1837 if (!dev->has_rds)
1838 cap->device_caps &= ~V4L2_CAP_READWRITE;
1839 }
1825 1840
1826 if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET))
1827 cap->capabilities &= ~V4L2_CAP_TUNER;
1828 return 0; 1841 return 0;
1829} 1842}
1830 1843
1831int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id) 1844int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id id)
1832{ 1845{
1833 unsigned long flags; 1846 unsigned long flags;
1834 unsigned int i; 1847 unsigned int i;
1835 v4l2_std_id fixup; 1848 v4l2_std_id fixup;
1836 int err;
1837 1849
1838 /* When called from the empress code fh == NULL. 1850 if (!fh && res_locked(dev, RESOURCE_OVERLAY)) {
1839 That needs to be fixed somehow, but for now this is
1840 good enough. */
1841 if (fh) {
1842 err = v4l2_prio_check(&dev->prio, fh->prio);
1843 if (0 != err)
1844 return err;
1845 } else if (res_locked(dev, RESOURCE_OVERLAY)) {
1846 /* Don't change the std from the mpeg device 1851 /* Don't change the std from the mpeg device
1847 if overlay is active. */ 1852 if overlay is active. */
1848 return -EBUSY; 1853 return -EBUSY;
1849 } 1854 }
1850 1855
1851 for (i = 0; i < TVNORMS; i++) 1856 for (i = 0; i < TVNORMS; i++)
1852 if (*id == tvnorms[i].id) 1857 if (id == tvnorms[i].id)
1853 break; 1858 break;
1854 1859
1855 if (i == TVNORMS) 1860 if (i == TVNORMS)
1856 for (i = 0; i < TVNORMS; i++) 1861 for (i = 0; i < TVNORMS; i++)
1857 if (*id & tvnorms[i].id) 1862 if (id & tvnorms[i].id)
1858 break; 1863 break;
1859 if (i == TVNORMS) 1864 if (i == TVNORMS)
1860 return -EINVAL; 1865 return -EINVAL;
1861 1866
1862 if ((*id & V4L2_STD_SECAM) && (secam[0] != '-')) { 1867 if ((id & V4L2_STD_SECAM) && (secam[0] != '-')) {
1863 if (secam[0] == 'L' || secam[0] == 'l') { 1868 if (secam[0] == 'L' || secam[0] == 'l') {
1864 if (secam[1] == 'C' || secam[1] == 'c') 1869 if (secam[1] == 'C' || secam[1] == 'c')
1865 fixup = V4L2_STD_SECAM_LC; 1870 fixup = V4L2_STD_SECAM_LC;
@@ -1879,7 +1884,7 @@ int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_
1879 return -EINVAL; 1884 return -EINVAL;
1880 } 1885 }
1881 1886
1882 *id = tvnorms[i].id; 1887 id = tvnorms[i].id;
1883 1888
1884 mutex_lock(&dev->lock); 1889 mutex_lock(&dev->lock);
1885 if (fh && res_check(fh, RESOURCE_OVERLAY)) { 1890 if (fh && res_check(fh, RESOURCE_OVERLAY)) {
@@ -1901,7 +1906,7 @@ int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_
1901} 1906}
1902EXPORT_SYMBOL_GPL(saa7134_s_std_internal); 1907EXPORT_SYMBOL_GPL(saa7134_s_std_internal);
1903 1908
1904static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id) 1909static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id id)
1905{ 1910{
1906 struct saa7134_fh *fh = priv; 1911 struct saa7134_fh *fh = priv;
1907 1912
@@ -2009,11 +2014,11 @@ static int saa7134_g_tuner(struct file *file, void *priv,
2009 if (NULL != card_in(dev, n).name) { 2014 if (NULL != card_in(dev, n).name) {
2010 strcpy(t->name, "Television"); 2015 strcpy(t->name, "Television");
2011 t->type = V4L2_TUNER_ANALOG_TV; 2016 t->type = V4L2_TUNER_ANALOG_TV;
2017 saa_call_all(dev, tuner, g_tuner, t);
2012 t->capability = V4L2_TUNER_CAP_NORM | 2018 t->capability = V4L2_TUNER_CAP_NORM |
2013 V4L2_TUNER_CAP_STEREO | 2019 V4L2_TUNER_CAP_STEREO |
2014 V4L2_TUNER_CAP_LANG1 | 2020 V4L2_TUNER_CAP_LANG1 |
2015 V4L2_TUNER_CAP_LANG2; 2021 V4L2_TUNER_CAP_LANG2;
2016 t->rangehigh = 0xffffffffUL;
2017 t->rxsubchans = saa7134_tvaudio_getstereo(dev); 2022 t->rxsubchans = saa7134_tvaudio_getstereo(dev);
2018 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans); 2023 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
2019 } 2024 }
@@ -2023,15 +2028,14 @@ static int saa7134_g_tuner(struct file *file, void *priv,
2023} 2028}
2024 2029
2025static int saa7134_s_tuner(struct file *file, void *priv, 2030static int saa7134_s_tuner(struct file *file, void *priv,
2026 struct v4l2_tuner *t) 2031 const struct v4l2_tuner *t)
2027{ 2032{
2028 struct saa7134_fh *fh = priv; 2033 struct saa7134_fh *fh = priv;
2029 struct saa7134_dev *dev = fh->dev; 2034 struct saa7134_dev *dev = fh->dev;
2030 int rx, mode, err; 2035 int rx, mode;
2031 2036
2032 err = v4l2_prio_check(&dev->prio, fh->prio); 2037 if (0 != t->index)
2033 if (0 != err) 2038 return -EINVAL;
2034 return err;
2035 2039
2036 mode = dev->thread.mode; 2040 mode = dev->thread.mode;
2037 if (UNSET == mode) { 2041 if (UNSET == mode) {
@@ -2050,22 +2054,20 @@ static int saa7134_g_frequency(struct file *file, void *priv,
2050 struct saa7134_fh *fh = priv; 2054 struct saa7134_fh *fh = priv;
2051 struct saa7134_dev *dev = fh->dev; 2055 struct saa7134_dev *dev = fh->dev;
2052 2056
2057 if (0 != f->tuner)
2058 return -EINVAL;
2059
2053 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 2060 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
2054 f->frequency = dev->ctl_freq; 2061 saa_call_all(dev, tuner, g_frequency, f);
2055 2062
2056 return 0; 2063 return 0;
2057} 2064}
2058 2065
2059static int saa7134_s_frequency(struct file *file, void *priv, 2066static int saa7134_s_frequency(struct file *file, void *priv,
2060 struct v4l2_frequency *f) 2067 const struct v4l2_frequency *f)
2061{ 2068{
2062 struct saa7134_fh *fh = priv; 2069 struct saa7134_fh *fh = priv;
2063 struct saa7134_dev *dev = fh->dev; 2070 struct saa7134_dev *dev = fh->dev;
2064 int err;
2065
2066 err = v4l2_prio_check(&dev->prio, fh->prio);
2067 if (0 != err)
2068 return err;
2069 2071
2070 if (0 != f->tuner) 2072 if (0 != f->tuner)
2071 return -EINVAL; 2073 return -EINVAL;
@@ -2074,7 +2076,6 @@ static int saa7134_s_frequency(struct file *file, void *priv,
2074 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type) 2076 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
2075 return -EINVAL; 2077 return -EINVAL;
2076 mutex_lock(&dev->lock); 2078 mutex_lock(&dev->lock);
2077 dev->ctl_freq = f->frequency;
2078 2079
2079 saa_call_all(dev, tuner, s_frequency, f); 2080 saa_call_all(dev, tuner, s_frequency, f);
2080 2081
@@ -2083,35 +2084,6 @@ static int saa7134_s_frequency(struct file *file, void *priv,
2083 return 0; 2084 return 0;
2084} 2085}
2085 2086
2086static int saa7134_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2087{
2088 strcpy(a->name, "audio");
2089 return 0;
2090}
2091
2092static int saa7134_s_audio(struct file *file, void *priv, const struct v4l2_audio *a)
2093{
2094 return 0;
2095}
2096
2097static int saa7134_g_priority(struct file *file, void *f, enum v4l2_priority *p)
2098{
2099 struct saa7134_fh *fh = f;
2100 struct saa7134_dev *dev = fh->dev;
2101
2102 *p = v4l2_prio_max(&dev->prio);
2103 return 0;
2104}
2105
2106static int saa7134_s_priority(struct file *file, void *f,
2107 enum v4l2_priority prio)
2108{
2109 struct saa7134_fh *fh = f;
2110 struct saa7134_dev *dev = fh->dev;
2111
2112 return v4l2_prio_change(&dev->prio, &fh->prio, prio);
2113}
2114
2115static int saa7134_enum_fmt_vid_cap(struct file *file, void *priv, 2087static int saa7134_enum_fmt_vid_cap(struct file *file, void *priv,
2116 struct v4l2_fmtdesc *f) 2088 struct v4l2_fmtdesc *f)
2117{ 2089{
@@ -2279,12 +2251,6 @@ static int saa7134_streamoff(struct file *file, void *priv,
2279 return 0; 2251 return 0;
2280} 2252}
2281 2253
2282static int saa7134_g_parm(struct file *file, void *fh,
2283 struct v4l2_streamparm *parm)
2284{
2285 return 0;
2286}
2287
2288#ifdef CONFIG_VIDEO_ADV_DEBUG 2254#ifdef CONFIG_VIDEO_ADV_DEBUG
2289static int vidioc_g_register (struct file *file, void *priv, 2255static int vidioc_g_register (struct file *file, void *priv,
2290 struct v4l2_dbg_register *reg) 2256 struct v4l2_dbg_register *reg)
@@ -2300,7 +2266,7 @@ static int vidioc_g_register (struct file *file, void *priv,
2300} 2266}
2301 2267
2302static int vidioc_s_register (struct file *file, void *priv, 2268static int vidioc_s_register (struct file *file, void *priv,
2303 struct v4l2_dbg_register *reg) 2269 const struct v4l2_dbg_register *reg)
2304{ 2270{
2305 struct saa7134_fh *fh = priv; 2271 struct saa7134_fh *fh = priv;
2306 struct saa7134_dev *dev = fh->dev; 2272 struct saa7134_dev *dev = fh->dev;
@@ -2312,19 +2278,6 @@ static int vidioc_s_register (struct file *file, void *priv,
2312} 2278}
2313#endif 2279#endif
2314 2280
2315static int radio_querycap(struct file *file, void *priv,
2316 struct v4l2_capability *cap)
2317{
2318 struct saa7134_fh *fh = file->private_data;
2319 struct saa7134_dev *dev = fh->dev;
2320
2321 strcpy(cap->driver, "saa7134");
2322 strlcpy(cap->card, saa7134_boards[dev->board].name, sizeof(cap->card));
2323 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
2324 cap->capabilities = V4L2_CAP_TUNER;
2325 return 0;
2326}
2327
2328static int radio_g_tuner(struct file *file, void *priv, 2281static int radio_g_tuner(struct file *file, void *priv,
2329 struct v4l2_tuner *t) 2282 struct v4l2_tuner *t)
2330{ 2283{
@@ -2339,6 +2292,7 @@ static int radio_g_tuner(struct file *file, void *priv,
2339 t->type = V4L2_TUNER_RADIO; 2292 t->type = V4L2_TUNER_RADIO;
2340 2293
2341 saa_call_all(dev, tuner, g_tuner, t); 2294 saa_call_all(dev, tuner, g_tuner, t);
2295 t->audmode &= V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO;
2342 if (dev->input->amux == TV) { 2296 if (dev->input->amux == TV) {
2343 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11); 2297 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11);
2344 t->rxsubchans = (saa_readb(0x529) & 0x08) ? 2298 t->rxsubchans = (saa_readb(0x529) & 0x08) ?
@@ -2347,7 +2301,7 @@ static int radio_g_tuner(struct file *file, void *priv,
2347 return 0; 2301 return 0;
2348} 2302}
2349static int radio_s_tuner(struct file *file, void *priv, 2303static int radio_s_tuner(struct file *file, void *priv,
2350 struct v4l2_tuner *t) 2304 const struct v4l2_tuner *t)
2351{ 2305{
2352 struct saa7134_fh *fh = file->private_data; 2306 struct saa7134_fh *fh = file->private_data;
2353 struct saa7134_dev *dev = fh->dev; 2307 struct saa7134_dev *dev = fh->dev;
@@ -2377,26 +2331,12 @@ static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
2377 return 0; 2331 return 0;
2378} 2332}
2379 2333
2380static int radio_g_audio(struct file *file, void *priv,
2381 struct v4l2_audio *a)
2382{
2383 memset(a, 0, sizeof(*a));
2384 strcpy(a->name, "Radio");
2385 return 0;
2386}
2387
2388static int radio_s_audio(struct file *file, void *priv,
2389 const struct v4l2_audio *a)
2390{
2391 return 0;
2392}
2393
2394static int radio_s_input(struct file *filp, void *priv, unsigned int i) 2334static int radio_s_input(struct file *filp, void *priv, unsigned int i)
2395{ 2335{
2396 return 0; 2336 return 0;
2397} 2337}
2398 2338
2399static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm) 2339static int radio_s_std(struct file *file, void *fh, v4l2_std_id norm)
2400{ 2340{
2401 return 0; 2341 return 0;
2402} 2342}
@@ -2441,8 +2381,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2441 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2381 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2442 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2382 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2443 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2383 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2444 .vidioc_g_audio = saa7134_g_audio,
2445 .vidioc_s_audio = saa7134_s_audio,
2446 .vidioc_cropcap = saa7134_cropcap, 2384 .vidioc_cropcap = saa7134_cropcap,
2447 .vidioc_reqbufs = saa7134_reqbufs, 2385 .vidioc_reqbufs = saa7134_reqbufs,
2448 .vidioc_querybuf = saa7134_querybuf, 2386 .vidioc_querybuf = saa7134_querybuf,
@@ -2465,9 +2403,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2465 .vidioc_g_fbuf = saa7134_g_fbuf, 2403 .vidioc_g_fbuf = saa7134_g_fbuf,
2466 .vidioc_s_fbuf = saa7134_s_fbuf, 2404 .vidioc_s_fbuf = saa7134_s_fbuf,
2467 .vidioc_overlay = saa7134_overlay, 2405 .vidioc_overlay = saa7134_overlay,
2468 .vidioc_g_priority = saa7134_g_priority,
2469 .vidioc_s_priority = saa7134_s_priority,
2470 .vidioc_g_parm = saa7134_g_parm,
2471 .vidioc_g_frequency = saa7134_g_frequency, 2406 .vidioc_g_frequency = saa7134_g_frequency,
2472 .vidioc_s_frequency = saa7134_s_frequency, 2407 .vidioc_s_frequency = saa7134_s_frequency,
2473#ifdef CONFIG_VIDEO_ADV_DEBUG 2408#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -2486,12 +2421,10 @@ static const struct v4l2_file_operations radio_fops = {
2486}; 2421};
2487 2422
2488static const struct v4l2_ioctl_ops radio_ioctl_ops = { 2423static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2489 .vidioc_querycap = radio_querycap, 2424 .vidioc_querycap = saa7134_querycap,
2490 .vidioc_g_tuner = radio_g_tuner, 2425 .vidioc_g_tuner = radio_g_tuner,
2491 .vidioc_enum_input = radio_enum_input, 2426 .vidioc_enum_input = radio_enum_input,
2492 .vidioc_g_audio = radio_g_audio,
2493 .vidioc_s_tuner = radio_s_tuner, 2427 .vidioc_s_tuner = radio_s_tuner,
2494 .vidioc_s_audio = radio_s_audio,
2495 .vidioc_s_input = radio_s_input, 2428 .vidioc_s_input = radio_s_input,
2496 .vidioc_s_std = radio_s_std, 2429 .vidioc_s_std = radio_s_std,
2497 .vidioc_queryctrl = radio_queryctrl, 2430 .vidioc_queryctrl = radio_queryctrl,
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index 71eefef5e324..d2ad16c1569a 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -36,6 +36,7 @@
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-fh.h>
39#include <media/tuner.h> 40#include <media/tuner.h>
40#include <media/rc-core.h> 41#include <media/rc-core.h>
41#include <media/ir-kbd-i2c.h> 42#include <media/ir-kbd-i2c.h>
@@ -45,6 +46,7 @@
45#if IS_ENABLED(CONFIG_VIDEO_SAA7134_DVB) 46#if IS_ENABLED(CONFIG_VIDEO_SAA7134_DVB)
46#include <media/videobuf-dvb.h> 47#include <media/videobuf-dvb.h>
47#endif 48#endif
49#include "tda8290.h"
48 50
49#define UNSET (-1U) 51#define UNSET (-1U)
50 52
@@ -334,6 +336,7 @@ struct saa7134_card_ir {
334#define SAA7134_BOARD_KWORLD_PC150U 189 336#define SAA7134_BOARD_KWORLD_PC150U 189
335#define SAA7134_BOARD_ASUSTeK_PS3_100 190 337#define SAA7134_BOARD_ASUSTeK_PS3_100 190
336#define SAA7134_BOARD_HAWELL_HW_9004V1 191 338#define SAA7134_BOARD_HAWELL_HW_9004V1 191
339#define SAA7134_BOARD_AVERMEDIA_A706 192
337 340
338#define SAA7134_MAXBOARDS 32 341#define SAA7134_MAXBOARDS 32
339#define SAA7134_INPUT_MAX 8 342#define SAA7134_INPUT_MAX 8
@@ -390,7 +393,7 @@ struct saa7134_board {
390 unsigned char rds_addr; 393 unsigned char rds_addr;
391 394
392 unsigned int tda9887_conf; 395 unsigned int tda9887_conf;
393 unsigned int tuner_config; 396 struct tda829x_config tda829x_conf;
394 397
395 /* peripheral I/O */ 398 /* peripheral I/O */
396 enum saa7134_video_out video_out; 399 enum saa7134_video_out video_out;
@@ -466,11 +469,11 @@ struct saa7134_dmaqueue {
466 469
467/* video filehandle status */ 470/* video filehandle status */
468struct saa7134_fh { 471struct saa7134_fh {
472 struct v4l2_fh fh;
469 struct saa7134_dev *dev; 473 struct saa7134_dev *dev;
470 unsigned int radio; 474 unsigned int radio;
471 enum v4l2_buf_type type; 475 enum v4l2_buf_type type;
472 unsigned int resources; 476 unsigned int resources;
473 enum v4l2_priority prio;
474 struct pm_qos_request qos_request; 477 struct pm_qos_request qos_request;
475 478
476 /* video overlay */ 479 /* video overlay */
@@ -542,7 +545,6 @@ struct saa7134_dev {
542 struct list_head devlist; 545 struct list_head devlist;
543 struct mutex lock; 546 struct mutex lock;
544 spinlock_t slock; 547 spinlock_t slock;
545 struct v4l2_prio_state prio;
546 struct v4l2_device v4l2_dev; 548 struct v4l2_device v4l2_dev;
547 /* workstruct for loading modules */ 549 /* workstruct for loading modules */
548 struct work_struct request_module_wk; 550 struct work_struct request_module_wk;
@@ -605,7 +607,6 @@ struct saa7134_dev {
605 int ctl_contrast; 607 int ctl_contrast;
606 int ctl_hue; 608 int ctl_hue;
607 int ctl_saturation; 609 int ctl_saturation;
608 int ctl_freq;
609 int ctl_mute; /* audio */ 610 int ctl_mute; /* audio */
610 int ctl_volume; 611 int ctl_volume;
611 int ctl_invert; /* private */ 612 int ctl_invert; /* private */
@@ -766,7 +767,7 @@ extern struct video_device saa7134_radio_template;
766int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c); 767int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
767int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c); 768int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
768int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c); 769int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c);
769int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id); 770int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id id);
770 771
771int saa7134_videoport_init(struct saa7134_dev *dev); 772int saa7134_videoport_init(struct saa7134_dev *dev);
772void saa7134_set_tvnorm_hw(struct saa7134_dev *dev); 773void saa7134_set_tvnorm_hw(struct saa7134_dev *dev);
diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
index 91369daad722..71e8bead321b 100644
--- a/drivers/media/pci/saa7146/mxb.c
+++ b/drivers/media/pci/saa7146/mxb.c
@@ -560,7 +560,7 @@ static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
560 return call_all(dev, tuner, g_tuner, t); 560 return call_all(dev, tuner, g_tuner, t);
561} 561}
562 562
563static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t) 563static int vidioc_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *t)
564{ 564{
565 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 565 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
566 struct mxb *mxb = (struct mxb *)dev->ext_priv; 566 struct mxb *mxb = (struct mxb *)dev->ext_priv;
@@ -595,7 +595,7 @@ static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency
595 return 0; 595 return 0;
596} 596}
597 597
598static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency *f) 598static int vidioc_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *f)
599{ 599{
600 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 600 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
601 struct mxb *mxb = (struct mxb *)dev->ext_priv; 601 struct mxb *mxb = (struct mxb *)dev->ext_priv;
@@ -612,8 +612,8 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency
612 /* tune in desired frequency */ 612 /* tune in desired frequency */
613 tuner_call(mxb, tuner, s_frequency, f); 613 tuner_call(mxb, tuner, s_frequency, f);
614 /* let the tuner subdev clamp the frequency to the tuner range */ 614 /* let the tuner subdev clamp the frequency to the tuner range */
615 tuner_call(mxb, tuner, g_frequency, f);
616 mxb->cur_freq = *f; 615 mxb->cur_freq = *f;
616 tuner_call(mxb, tuner, g_frequency, &mxb->cur_freq);
617 if (mxb->cur_audinput == 0) 617 if (mxb->cur_audinput == 0)
618 mxb_update_audmode(mxb); 618 mxb_update_audmode(mxb);
619 619
@@ -680,7 +680,7 @@ static int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_regist
680 return 0; 680 return 0;
681} 681}
682 682
683static int vidioc_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg) 683static int vidioc_s_register(struct file *file, void *fh, const struct v4l2_dbg_register *reg)
684{ 684{
685 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 685 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
686 686
@@ -688,7 +688,6 @@ static int vidioc_s_register(struct file *file, void *fh, struct v4l2_dbg_regist
688 return -EPERM; 688 return -EPERM;
689 if (v4l2_chip_match_host(&reg->match)) { 689 if (v4l2_chip_match_host(&reg->match)) {
690 saa7146_write(dev, reg->reg, reg->val); 690 saa7146_write(dev, reg->reg, reg->val);
691 reg->size = 4;
692 return 0; 691 return 0;
693 } 692 }
694 return call_all(dev, core, s_register, reg); 693 return call_all(dev, core, s_register, reg);
diff --git a/drivers/media/pci/saa7164/saa7164-encoder.c b/drivers/media/pci/saa7164/saa7164-encoder.c
index 9bb0903ee5f1..0b74fb2300dd 100644
--- a/drivers/media/pci/saa7164/saa7164-encoder.c
+++ b/drivers/media/pci/saa7164/saa7164-encoder.c
@@ -211,17 +211,17 @@ static int saa7164_encoder_initialize(struct saa7164_port *port)
211} 211}
212 212
213/* -- V4L2 --------------------------------------------------------- */ 213/* -- V4L2 --------------------------------------------------------- */
214static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 214static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
215{ 215{
216 struct saa7164_encoder_fh *fh = file->private_data; 216 struct saa7164_encoder_fh *fh = file->private_data;
217 struct saa7164_port *port = fh->port; 217 struct saa7164_port *port = fh->port;
218 struct saa7164_dev *dev = port->dev; 218 struct saa7164_dev *dev = port->dev;
219 unsigned int i; 219 unsigned int i;
220 220
221 dprintk(DBGLVL_ENC, "%s(id=0x%x)\n", __func__, (u32)*id); 221 dprintk(DBGLVL_ENC, "%s(id=0x%x)\n", __func__, (u32)id);
222 222
223 for (i = 0; i < ARRAY_SIZE(saa7164_tvnorms); i++) { 223 for (i = 0; i < ARRAY_SIZE(saa7164_tvnorms); i++) {
224 if (*id & saa7164_tvnorms[i].id) 224 if (id & saa7164_tvnorms[i].id)
225 break; 225 break;
226 } 226 }
227 if (i == ARRAY_SIZE(saa7164_tvnorms)) 227 if (i == ARRAY_SIZE(saa7164_tvnorms))
@@ -234,7 +234,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
234 */ 234 */
235 saa7164_api_set_audio_std(port); 235 saa7164_api_set_audio_std(port);
236 236
237 dprintk(DBGLVL_ENC, "%s(id=0x%x) OK\n", __func__, (u32)*id); 237 dprintk(DBGLVL_ENC, "%s(id=0x%x) OK\n", __func__, (u32)id);
238 238
239 return 0; 239 return 0;
240} 240}
@@ -318,7 +318,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
318} 318}
319 319
320static int vidioc_s_tuner(struct file *file, void *priv, 320static int vidioc_s_tuner(struct file *file, void *priv,
321 struct v4l2_tuner *t) 321 const struct v4l2_tuner *t)
322{ 322{
323 /* Update the A/V core */ 323 /* Update the A/V core */
324 return 0; 324 return 0;
@@ -337,7 +337,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
337} 337}
338 338
339static int vidioc_s_frequency(struct file *file, void *priv, 339static int vidioc_s_frequency(struct file *file, void *priv,
340 struct v4l2_frequency *f) 340 const struct v4l2_frequency *f)
341{ 341{
342 struct saa7164_encoder_fh *fh = file->private_data; 342 struct saa7164_encoder_fh *fh = file->private_data;
343 struct saa7164_port *port = fh->port; 343 struct saa7164_port *port = fh->port;
@@ -1313,7 +1313,7 @@ static int saa7164_g_register(struct file *file, void *fh,
1313} 1313}
1314 1314
1315static int saa7164_s_register(struct file *file, void *fh, 1315static int saa7164_s_register(struct file *file, void *fh,
1316 struct v4l2_dbg_register *reg) 1316 const struct v4l2_dbg_register *reg)
1317{ 1317{
1318 struct saa7164_port *port = ((struct saa7164_encoder_fh *)fh)->port; 1318 struct saa7164_port *port = ((struct saa7164_encoder_fh *)fh)->port;
1319 struct saa7164_dev *dev = port->dev; 1319 struct saa7164_dev *dev = port->dev;
diff --git a/drivers/media/pci/saa7164/saa7164-vbi.c b/drivers/media/pci/saa7164/saa7164-vbi.c
index b4532299c0ed..da224eb39b95 100644
--- a/drivers/media/pci/saa7164/saa7164-vbi.c
+++ b/drivers/media/pci/saa7164/saa7164-vbi.c
@@ -183,17 +183,17 @@ static int saa7164_vbi_initialize(struct saa7164_port *port)
183} 183}
184 184
185/* -- V4L2 --------------------------------------------------------- */ 185/* -- V4L2 --------------------------------------------------------- */
186static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 186static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
187{ 187{
188 struct saa7164_vbi_fh *fh = file->private_data; 188 struct saa7164_vbi_fh *fh = file->private_data;
189 struct saa7164_port *port = fh->port; 189 struct saa7164_port *port = fh->port;
190 struct saa7164_dev *dev = port->dev; 190 struct saa7164_dev *dev = port->dev;
191 unsigned int i; 191 unsigned int i;
192 192
193 dprintk(DBGLVL_VBI, "%s(id=0x%x)\n", __func__, (u32)*id); 193 dprintk(DBGLVL_VBI, "%s(id=0x%x)\n", __func__, (u32)id);
194 194
195 for (i = 0; i < ARRAY_SIZE(saa7164_tvnorms); i++) { 195 for (i = 0; i < ARRAY_SIZE(saa7164_tvnorms); i++) {
196 if (*id & saa7164_tvnorms[i].id) 196 if (id & saa7164_tvnorms[i].id)
197 break; 197 break;
198 } 198 }
199 if (i == ARRAY_SIZE(saa7164_tvnorms)) 199 if (i == ARRAY_SIZE(saa7164_tvnorms))
@@ -206,7 +206,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
206 */ 206 */
207 saa7164_api_set_audio_std(port); 207 saa7164_api_set_audio_std(port);
208 208
209 dprintk(DBGLVL_VBI, "%s(id=0x%x) OK\n", __func__, (u32)*id); 209 dprintk(DBGLVL_VBI, "%s(id=0x%x) OK\n", __func__, (u32)id);
210 210
211 return 0; 211 return 0;
212} 212}
@@ -290,7 +290,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
290} 290}
291 291
292static int vidioc_s_tuner(struct file *file, void *priv, 292static int vidioc_s_tuner(struct file *file, void *priv,
293 struct v4l2_tuner *t) 293 const struct v4l2_tuner *t)
294{ 294{
295 /* Update the A/V core */ 295 /* Update the A/V core */
296 return 0; 296 return 0;
@@ -309,7 +309,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
309} 309}
310 310
311static int vidioc_s_frequency(struct file *file, void *priv, 311static int vidioc_s_frequency(struct file *file, void *priv,
312 struct v4l2_frequency *f) 312 const struct v4l2_frequency *f)
313{ 313{
314 struct saa7164_vbi_fh *fh = file->private_data; 314 struct saa7164_vbi_fh *fh = file->private_data;
315 struct saa7164_port *port = fh->port; 315 struct saa7164_port *port = fh->port;
diff --git a/drivers/media/pci/sta2x11/Kconfig b/drivers/media/pci/sta2x11/Kconfig
index a94ccad02066..03130157db83 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -4,6 +4,7 @@ config STA2X11_VIP
4 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT 4 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
5 select VIDEOBUF2_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 depends on I2C
7 help 8 help
8 Say Y for support for STA2X11 VIP (Video Input Port) capture 9 Say Y for support for STA2X11 VIP (Video Input Port) capture
9 device. 10 device.
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 4b703fe8c953..7005695aa4bd 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -439,22 +439,22 @@ static int vidioc_querycap(struct file *file, void *priv,
439 * 439 *
440 * other, returned from video DAC. 440 * other, returned from video DAC.
441 */ 441 */
442static 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)
443{ 443{
444 struct sta2x11_vip *vip = video_drvdata(file); 444 struct sta2x11_vip *vip = video_drvdata(file);
445 v4l2_std_id oldstd = vip->std, newstd; 445 v4l2_std_id oldstd = vip->std, newstd;
446 int status; 446 int status;
447 447
448 if (V4L2_STD_ALL == *std) { 448 if (V4L2_STD_ALL == std) {
449 v4l2_subdev_call(vip->decoder, core, s_std, *std); 449 v4l2_subdev_call(vip->decoder, core, s_std, std);
450 ssleep(2); 450 ssleep(2);
451 v4l2_subdev_call(vip->decoder, video, querystd, &newstd); 451 v4l2_subdev_call(vip->decoder, video, querystd, &newstd);
452 v4l2_subdev_call(vip->decoder, video, g_input_status, &status); 452 v4l2_subdev_call(vip->decoder, video, g_input_status, &status);
453 if (status & V4L2_IN_ST_NO_SIGNAL) 453 if (status & V4L2_IN_ST_NO_SIGNAL)
454 return -EIO; 454 return -EIO;
455 *std = vip->std = newstd; 455 std = vip->std = newstd;
456 if (oldstd != *std) { 456 if (oldstd != std) {
457 if (V4L2_STD_525_60 & (*std)) 457 if (V4L2_STD_525_60 & std)
458 vip->format = formats_60[0]; 458 vip->format = formats_60[0];
459 else 459 else
460 vip->format = formats_50[0]; 460 vip->format = formats_50[0];
@@ -462,14 +462,14 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
462 return 0; 462 return 0;
463 } 463 }
464 464
465 if (oldstd != *std) { 465 if (oldstd != std) {
466 if (V4L2_STD_525_60 & (*std)) 466 if (V4L2_STD_525_60 & std)
467 vip->format = formats_60[0]; 467 vip->format = formats_60[0];
468 else 468 else
469 vip->format = formats_50[0]; 469 vip->format = formats_50[0];
470 } 470 }
471 471
472 return v4l2_subdev_call(vip->decoder, core, s_std, *std); 472 return v4l2_subdev_call(vip->decoder, core, s_std, std);
473} 473}
474 474
475/** 475/**
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index 3dc7aa9b6f40..f38329d29daa 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -990,7 +990,7 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
990 990
991 if (feed->type == DMX_TYPE_TS) { 991 if (feed->type == DMX_TYPE_TS) {
992 if ((feed->ts_type & TS_DECODER) && 992 if ((feed->ts_type & TS_DECODER) &&
993 (feed->pes_type <= DMX_TS_PES_PCR)) { 993 (feed->pes_type <= DMX_PES_PCR)) {
994 switch (demux->dmx.frontend->source) { 994 switch (demux->dmx.frontend->source) {
995 case DMX_MEMORY_FE: 995 case DMX_MEMORY_FE:
996 if (feed->ts_type & TS_DECODER) 996 if (feed->ts_type & TS_DECODER)
@@ -1051,14 +1051,14 @@ static int av7110_stop_feed(struct dvb_demux_feed *feed)
1051 1051
1052 if (feed->type == DMX_TYPE_TS) { 1052 if (feed->type == DMX_TYPE_TS) {
1053 if (feed->ts_type & TS_DECODER) { 1053 if (feed->ts_type & TS_DECODER) {
1054 if (feed->pes_type >= DMX_TS_PES_OTHER || 1054 if (feed->pes_type >= DMX_PES_OTHER ||
1055 !demux->pesfilter[feed->pes_type]) 1055 !demux->pesfilter[feed->pes_type])
1056 return -EINVAL; 1056 return -EINVAL;
1057 demux->pids[feed->pes_type] |= 0x8000; 1057 demux->pids[feed->pes_type] |= 0x8000;
1058 demux->pesfilter[feed->pes_type] = NULL; 1058 demux->pesfilter[feed->pes_type] = NULL;
1059 } 1059 }
1060 if (feed->ts_type & TS_DECODER && 1060 if (feed->ts_type & TS_DECODER &&
1061 feed->pes_type < DMX_TS_PES_OTHER) { 1061 feed->pes_type < DMX_PES_OTHER) {
1062 ret = dvb_feed_stop_pid(feed); 1062 ret = dvb_feed_stop_pid(feed);
1063 } else 1063 } else
1064 if ((feed->ts_type & TS_PACKET) && 1064 if ((feed->ts_type & TS_PACKET) &&
diff --git a/drivers/media/pci/ttpci/av7110_v4l.c b/drivers/media/pci/ttpci/av7110_v4l.c
index 730e906ea912..6c4076acb131 100644
--- a/drivers/media/pci/ttpci/av7110_v4l.c
+++ b/drivers/media/pci/ttpci/av7110_v4l.c
@@ -366,7 +366,7 @@ static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
366 return 0; 366 return 0;
367} 367}
368 368
369static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t) 369static int vidioc_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *t)
370{ 370{
371 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 371 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
372 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv; 372 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
@@ -426,7 +426,7 @@ static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency
426 return 0; 426 return 0;
427} 427}
428 428
429static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency *f) 429static int vidioc_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *f)
430{ 430{
431 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 431 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
432 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv; 432 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
diff --git a/drivers/media/pci/ttpci/budget.c b/drivers/media/pci/ttpci/budget.c
index 7e6e43ae5c51..6ccc48833fd8 100644
--- a/drivers/media/pci/ttpci/budget.c
+++ b/drivers/media/pci/ttpci/budget.c
@@ -537,6 +537,16 @@ static void frontend_init(struct budget *budget)
537 } 537 }
538 break; 538 break;
539 539
540 case 0x4f52: /* Cards based on Philips Semi Sylt PCI ref. design */
541 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
542 if (budget->dvb_frontend) {
543 printk(KERN_INFO "budget: tuner ALPS BSRU6 in Philips Semi. Sylt detected\n");
544 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
545 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
546 break;
547 }
548 break;
549
540 case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */ 550 case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */
541 { 551 {
542 int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67); 552 int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67);
@@ -818,6 +828,7 @@ MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps front
818MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY); 828MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
819MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY); 829MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
820MAKE_BUDGET_INFO(omicom, "Omicom S2 PCI", BUDGET_TT); 830MAKE_BUDGET_INFO(omicom, "Omicom S2 PCI", BUDGET_TT);
831MAKE_BUDGET_INFO(sylt, "Philips Semi Sylt PCI", BUDGET_TT_HW_DISEQC);
821 832
822static struct pci_device_id pci_tbl[] = { 833static struct pci_device_id pci_tbl[] = {
823 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003), 834 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
@@ -832,6 +843,7 @@ static struct pci_device_id pci_tbl[] = {
832 MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60), 843 MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
833 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61), 844 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
834 MAKE_EXTENSION_PCI(omicom, 0x14c4, 0x1020), 845 MAKE_EXTENSION_PCI(omicom, 0x14c4, 0x1020),
846 MAKE_EXTENSION_PCI(sylt, 0x1131, 0x4f52),
835 { 847 {
836 .vendor = 0, 848 .vendor = 0,
837 } 849 }
diff --git a/drivers/media/pci/zoran/zoran_driver.c b/drivers/media/pci/zoran/zoran_driver.c
index 2e8f518f298f..1168a84a737d 100644
--- a/drivers/media/pci/zoran/zoran_driver.c
+++ b/drivers/media/pci/zoran/zoran_driver.c
@@ -2435,14 +2435,14 @@ static int zoran_g_std(struct file *file, void *__fh, v4l2_std_id *std)
2435 return 0; 2435 return 0;
2436} 2436}
2437 2437
2438static int zoran_s_std(struct file *file, void *__fh, v4l2_std_id *std) 2438static int zoran_s_std(struct file *file, void *__fh, v4l2_std_id std)
2439{ 2439{
2440 struct zoran_fh *fh = __fh; 2440 struct zoran_fh *fh = __fh;
2441 struct zoran *zr = fh->zr; 2441 struct zoran *zr = fh->zr;
2442 int res = 0; 2442 int res = 0;
2443 2443
2444 mutex_lock(&zr->resource_lock); 2444 mutex_lock(&zr->resource_lock);
2445 res = zoran_set_norm(zr, *std); 2445 res = zoran_set_norm(zr, std);
2446 if (res) 2446 if (res)
2447 goto sstd_unlock_and_return; 2447 goto sstd_unlock_and_return;
2448 2448
diff --git a/drivers/media/pci/zoran/zoran_procfs.c b/drivers/media/pci/zoran/zoran_procfs.c
index e084b0a21b1b..1512b5d40533 100644
--- a/drivers/media/pci/zoran/zoran_procfs.c
+++ b/drivers/media/pci/zoran/zoran_procfs.c
@@ -201,7 +201,7 @@ zoran_proc_init (struct zoran *zr)
201 dprintk(2, 201 dprintk(2,
202 KERN_INFO 202 KERN_INFO
203 "%s: procfs entry /proc/%s allocated. data=%p\n", 203 "%s: procfs entry /proc/%s allocated. data=%p\n",
204 ZR_DEVNAME(zr), name, zr->zoran_proc->data); 204 ZR_DEVNAME(zr), name, zr);
205 } else { 205 } else {
206 dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n", 206 dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n",
207 ZR_DEVNAME(zr), name); 207 ZR_DEVNAME(zr), name);
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 26500094de7c..0494d2769fd7 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -122,7 +122,7 @@ config VIDEO_S3C_CAMIF
122 will be called s3c-camif. 122 will be called s3c-camif.
123 123
124source "drivers/media/platform/soc_camera/Kconfig" 124source "drivers/media/platform/soc_camera/Kconfig"
125source "drivers/media/platform/s5p-fimc/Kconfig" 125source "drivers/media/platform/exynos4-is/Kconfig"
126source "drivers/media/platform/s5p-tv/Kconfig" 126source "drivers/media/platform/s5p-tv/Kconfig"
127 127
128endif # V4L_PLATFORM_DRIVERS 128endif # V4L_PLATFORM_DRIVERS
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 42089ba3600f..eee28dd78d7d 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -30,7 +30,7 @@ obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o
30obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE) += m2m-deinterlace.o 30obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE) += m2m-deinterlace.o
31 31
32obj-$(CONFIG_VIDEO_S3C_CAMIF) += s3c-camif/ 32obj-$(CONFIG_VIDEO_S3C_CAMIF) += s3c-camif/
33obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) += s5p-fimc/ 33obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
34obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) += s5p-jpeg/ 34obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) += s5p-jpeg/
35obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC) += s5p-mfc/ 35obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC) += s5p-mfc/
36obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/ 36obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 5f209d5810dc..0e55b087076f 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -384,7 +384,7 @@ static int bcap_start_streaming(struct vb2_queue *vq, unsigned int count)
384 params.ppi_control = bcap_dev->cfg->ppi_control; 384 params.ppi_control = bcap_dev->cfg->ppi_control;
385 params.int_mask = bcap_dev->cfg->int_mask; 385 params.int_mask = bcap_dev->cfg->int_mask;
386 if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities 386 if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
387 & V4L2_IN_CAP_CUSTOM_TIMINGS) { 387 & V4L2_IN_CAP_DV_TIMINGS) {
388 struct v4l2_bt_timings *bt = &bcap_dev->dv_timings.bt; 388 struct v4l2_bt_timings *bt = &bcap_dev->dv_timings.bt;
389 389
390 params.hdelay = bt->hsync + bt->hbackporch; 390 params.hdelay = bt->hsync + bt->hbackporch;
@@ -633,7 +633,7 @@ static int bcap_g_std(struct file *file, void *priv, v4l2_std_id *std)
633 return 0; 633 return 0;
634} 634}
635 635
636static int bcap_s_std(struct file *file, void *priv, v4l2_std_id *std) 636static int bcap_s_std(struct file *file, void *priv, v4l2_std_id std)
637{ 637{
638 struct bcap_device *bcap_dev = video_drvdata(file); 638 struct bcap_device *bcap_dev = video_drvdata(file);
639 int ret; 639 int ret;
@@ -641,11 +641,11 @@ static int bcap_s_std(struct file *file, void *priv, v4l2_std_id *std)
641 if (vb2_is_busy(&bcap_dev->buffer_queue)) 641 if (vb2_is_busy(&bcap_dev->buffer_queue))
642 return -EBUSY; 642 return -EBUSY;
643 643
644 ret = v4l2_subdev_call(bcap_dev->sd, core, s_std, *std); 644 ret = v4l2_subdev_call(bcap_dev->sd, core, s_std, std);
645 if (ret < 0) 645 if (ret < 0)
646 return ret; 646 return ret;
647 647
648 bcap_dev->std = *std; 648 bcap_dev->std = std;
649 return 0; 649 return 0;
650} 650}
651 651
@@ -890,7 +890,7 @@ static int bcap_dbg_g_register(struct file *file, void *priv,
890} 890}
891 891
892static int bcap_dbg_s_register(struct file *file, void *priv, 892static int bcap_dbg_s_register(struct file *file, void *priv,
893 struct v4l2_dbg_register *reg) 893 const struct v4l2_dbg_register *reg)
894{ 894{
895 struct bcap_device *bcap_dev = video_drvdata(file); 895 struct bcap_device *bcap_dev = video_drvdata(file);
896 896
@@ -1029,6 +1029,7 @@ static int bcap_probe(struct platform_device *pdev)
1029 q->buf_struct_size = sizeof(struct bcap_buffer); 1029 q->buf_struct_size = sizeof(struct bcap_buffer);
1030 q->ops = &bcap_video_qops; 1030 q->ops = &bcap_video_qops;
1031 q->mem_ops = &vb2_dma_contig_memops; 1031 q->mem_ops = &vb2_dma_contig_memops;
1032 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1032 1033
1033 vb2_queue_init(q); 1034 vb2_queue_init(q);
1034 1035
@@ -1110,7 +1111,7 @@ static int bcap_probe(struct platform_device *pdev)
1110 } 1111 }
1111 bcap_dev->std = std; 1112 bcap_dev->std = std;
1112 } 1113 }
1113 if (config->inputs[0].capabilities & V4L2_IN_CAP_CUSTOM_TIMINGS) { 1114 if (config->inputs[0].capabilities & V4L2_IN_CAP_DV_TIMINGS) {
1114 struct v4l2_dv_timings dv_timings; 1115 struct v4l2_dv_timings dv_timings;
1115 ret = v4l2_subdev_call(bcap_dev->sd, video, 1116 ret = v4l2_subdev_call(bcap_dev->sd, video,
1116 g_dv_timings, &dv_timings); 1117 g_dv_timings, &dv_timings);
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index b931c2a5c7fc..48b8d7af386d 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -1427,6 +1427,7 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
1427 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 1427 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1428 src_vq->ops = &coda_qops; 1428 src_vq->ops = &coda_qops;
1429 src_vq->mem_ops = &vb2_dma_contig_memops; 1429 src_vq->mem_ops = &vb2_dma_contig_memops;
1430 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1430 1431
1431 ret = vb2_queue_init(src_vq); 1432 ret = vb2_queue_init(src_vq);
1432 if (ret) 1433 if (ret)
@@ -1438,6 +1439,7 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
1438 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 1439 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1439 dst_vq->ops = &coda_qops; 1440 dst_vq->ops = &coda_qops;
1440 dst_vq->mem_ops = &vb2_dma_contig_memops; 1441 dst_vq->mem_ops = &vb2_dma_contig_memops;
1442 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1441 1443
1442 return vb2_queue_init(dst_vq); 1444 return vb2_queue_init(dst_vq);
1443} 1445}
@@ -1633,6 +1635,9 @@ static irqreturn_t coda_irq_handler(int irq, void *data)
1633 dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_KEYFRAME; 1635 dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_KEYFRAME;
1634 } 1636 }
1635 1637
1638 dst_buf->v4l2_buf.timestamp = src_buf->v4l2_buf.timestamp;
1639 dst_buf->v4l2_buf.timecode = src_buf->v4l2_buf.timecode;
1640
1636 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); 1641 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
1637 v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); 1642 v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE);
1638 1643
diff --git a/drivers/media/platform/davinci/Kconfig b/drivers/media/platform/davinci/Kconfig
index ccfde4eb626a..afb3aec1320e 100644
--- a/drivers/media/platform/davinci/Kconfig
+++ b/drivers/media/platform/davinci/Kconfig
@@ -1,79 +1,47 @@
1config VIDEO_DAVINCI_VPIF_DISPLAY 1config VIDEO_DAVINCI_VPIF_DISPLAY
2 tristate "DM646x/DA850/OMAPL138 EVM Video Display" 2 tristate "TI DaVinci VPIF V4L2-Display driver"
3 depends on VIDEO_DEV && (MACH_DAVINCI_DM6467_EVM || MACH_DAVINCI_DA850_EVM) 3 depends on VIDEO_DEV && ARCH_DAVINCI
4 select VIDEOBUF2_DMA_CONTIG 4 select VIDEOBUF2_DMA_CONTIG
5 select VIDEO_DAVINCI_VPIF
6 select VIDEO_ADV7343 if MEDIA_SUBDRV_AUTOSELECT 5 select VIDEO_ADV7343 if MEDIA_SUBDRV_AUTOSELECT
7 select VIDEO_THS7303 if MEDIA_SUBDRV_AUTOSELECT 6 select VIDEO_THS7303 if MEDIA_SUBDRV_AUTOSELECT
8 help 7 help
9 Enables Davinci VPIF module used for display devices. 8 Enables Davinci VPIF module used for display devices.
10 This module is common for following DM6467/DA850/OMAPL138 9 This module is used for display on TI DM6467/DA850/OMAPL138
11 based display devices. 10 SoCs.
12 11
13 To compile this driver as a module, choose M here: the 12 To compile this driver as a module, choose M here. There will
14 module will be called vpif_display. 13 be two modules called vpif.ko and vpif_display.ko
15 14
16config VIDEO_DAVINCI_VPIF_CAPTURE 15config VIDEO_DAVINCI_VPIF_CAPTURE
17 tristate "DM646x/DA850/OMAPL138 EVM Video Capture" 16 tristate "TI DaVinci VPIF video capture driver"
18 depends on VIDEO_DEV && (MACH_DAVINCI_DM6467_EVM || MACH_DAVINCI_DA850_EVM) 17 depends on VIDEO_DEV && ARCH_DAVINCI
19 select VIDEOBUF2_DMA_CONTIG 18 select VIDEOBUF2_DMA_CONTIG
20 select VIDEO_DAVINCI_VPIF
21 help 19 help
22 Enables Davinci VPIF module used for captur devices. 20 Enables Davinci VPIF module used for capture devices.
23 This module is common for following DM6467/DA850/OMAPL138 21 This module is used for capture on TI DM6467/DA850/OMAPL138
24 based capture devices. 22 SoCs.
25 23
26 To compile this driver as a module, choose M here: the 24 To compile this driver as a module, choose M here. There will
27 module will be called vpif_capture. 25 be two modules called vpif.ko and vpif_capture.ko
28 26
29config VIDEO_DAVINCI_VPIF 27config VIDEO_DM6446_CCDC
30 tristate "DaVinci VPIF Driver" 28 tristate "TI DM6446 CCDC video capture driver"
31 depends on VIDEO_DAVINCI_VPIF_DISPLAY || VIDEO_DAVINCI_VPIF_CAPTURE
32 help
33 Support for DaVinci VPIF Driver.
34
35 To compile this driver as a module, choose M here: the
36 module will be called vpif.
37
38config VIDEO_VPSS_SYSTEM
39 tristate "VPSS System module driver"
40 depends on ARCH_DAVINCI
41 help
42 Support for vpss system module for video driver
43
44config VIDEO_VPFE_CAPTURE
45 tristate "VPFE Video Capture Driver"
46 depends on VIDEO_V4L2 && (ARCH_DAVINCI || ARCH_OMAP3) 29 depends on VIDEO_V4L2 && (ARCH_DAVINCI || ARCH_OMAP3)
47 depends on I2C
48 select VIDEOBUF_DMA_CONTIG 30 select VIDEOBUF_DMA_CONTIG
49 help 31 help
50 Support for DMx/AMx VPFE based frame grabber. This is the
51 common V4L2 module for following DMx/AMx SoCs from Texas
52 Instruments:- DM6446, DM365, DM355 & AM3517/05.
53
54 To compile this driver as a module, choose M here: the
55 module will be called vpfe-capture.
56
57config VIDEO_DM6446_CCDC
58 tristate "DM6446 CCDC HW module"
59 depends on VIDEO_VPFE_CAPTURE
60 select VIDEO_VPSS_SYSTEM
61 default y
62 help
63 Enables DaVinci CCD hw module. DaVinci CCDC hw interfaces 32 Enables DaVinci CCD hw module. DaVinci CCDC hw interfaces
64 with decoder modules such as TVP5146 over BT656 or 33 with decoder modules such as TVP5146 over BT656 or
65 sensor module such as MT9T001 over a raw interface. This 34 sensor module such as MT9T001 over a raw interface. This
66 module configures the interface and CCDC/ISIF to do 35 module configures the interface and CCDC/ISIF to do
67 video frame capture from slave decoders. 36 video frame capture from slave decoders.
68 37
69 To compile this driver as a module, choose M here: the 38 To compile this driver as a module, choose M here. There will
70 module will be called vpfe. 39 be three modules called vpfe_capture.ko, vpss.ko and dm644x_ccdc.ko
71 40
72config VIDEO_DM355_CCDC 41config VIDEO_DM355_CCDC
73 tristate "DM355 CCDC HW module" 42 tristate "TI DM355 CCDC video capture driver"
74 depends on ARCH_DAVINCI_DM355 && VIDEO_VPFE_CAPTURE 43 depends on VIDEO_V4L2 && ARCH_DAVINCI
75 select VIDEO_VPSS_SYSTEM 44 select VIDEOBUF_DMA_CONTIG
76 default y
77 help 45 help
78 Enables DM355 CCD hw module. DM355 CCDC hw interfaces 46 Enables DM355 CCD hw module. DM355 CCDC hw interfaces
79 with decoder modules such as TVP5146 over BT656 or 47 with decoder modules such as TVP5146 over BT656 or
@@ -81,31 +49,30 @@ config VIDEO_DM355_CCDC
81 module configures the interface and CCDC/ISIF to do 49 module configures the interface and CCDC/ISIF to do
82 video frame capture from a slave decoders 50 video frame capture from a slave decoders
83 51
84 To compile this driver as a module, choose M here: the 52 To compile this driver as a module, choose M here. There will
85 module will be called vpfe. 53 be three modules called vpfe_capture.ko, vpss.ko and dm355_ccdc.ko
86 54
87config VIDEO_ISIF 55config VIDEO_DM365_ISIF
88 tristate "ISIF HW module" 56 tristate "TI DM365 ISIF video capture driver"
89 depends on ARCH_DAVINCI_DM365 && VIDEO_VPFE_CAPTURE 57 depends on VIDEO_V4L2 && ARCH_DAVINCI
90 select VIDEO_VPSS_SYSTEM 58 select VIDEOBUF_DMA_CONTIG
91 default y
92 help 59 help
93 Enables ISIF hw module. This is the hardware module for 60 Enables ISIF hw module. This is the hardware module for
94 configuring ISIF in VPFE to capture Raw Bayer RGB data from 61 configuring ISIF in VPFE to capture Raw Bayer RGB data from
95 a image sensor or YUV data from a YUV source. 62 a image sensor or YUV data from a YUV source.
96 63
97 To compile this driver as a module, choose M here: the 64 To compile this driver as a module, choose M here. There will
98 module will be called vpfe. 65 be three modules called vpfe_capture.ko, vpss.ko and isif.ko
99 66
100config VIDEO_DAVINCI_VPBE_DISPLAY 67config VIDEO_DAVINCI_VPBE_DISPLAY
101 tristate "DM644X/DM365/DM355 VPBE HW module" 68 tristate "TI DaVinci VPBE V4L2-Display driver"
102 depends on ARCH_DAVINCI_DM644x || ARCH_DAVINCI_DM355 || ARCH_DAVINCI_DM365 69 depends on ARCH_DAVINCI
103 select VIDEO_VPSS_SYSTEM
104 select VIDEOBUF2_DMA_CONTIG 70 select VIDEOBUF2_DMA_CONTIG
105 help 71 help
106 Enables Davinci VPBE module used for display devices. 72 Enables Davinci VPBE module used for display devices.
107 This module is common for following DM644x/DM365/DM355 73 This module is used for display on TI DM644x/DM365/DM355
108 based display devices. 74 based display devices.
109 75
110 To compile this driver as a module, choose M here: the 76 To compile this driver as a module, choose M here. There will
111 module will be called vpbe. 77 be five modules created called vpss.ko, vpbe.ko, vpbe_osd.ko,
78 vpbe_venc.ko and vpbe_display.ko
diff --git a/drivers/media/platform/davinci/Makefile b/drivers/media/platform/davinci/Makefile
index f40f5219ca50..d74d9eeb0e9e 100644
--- a/drivers/media/platform/davinci/Makefile
+++ b/drivers/media/platform/davinci/Makefile
@@ -2,19 +2,14 @@
2# Makefile for the davinci video device drivers. 2# Makefile for the davinci video device drivers.
3# 3#
4 4
5# VPIF
6obj-$(CONFIG_VIDEO_DAVINCI_VPIF) += vpif.o
7
8#VPIF Display driver 5#VPIF Display driver
9obj-$(CONFIG_VIDEO_DAVINCI_VPIF_DISPLAY) += vpif_display.o 6obj-$(CONFIG_VIDEO_DAVINCI_VPIF_DISPLAY) += vpif.o vpif_display.o
10#VPIF Capture driver 7#VPIF Capture driver
11obj-$(CONFIG_VIDEO_DAVINCI_VPIF_CAPTURE) += vpif_capture.o 8obj-$(CONFIG_VIDEO_DAVINCI_VPIF_CAPTURE) += vpif.o vpif_capture.o
12 9
13# Capture: DM6446 and DM355 10# Capture: DM6446 and DM355
14obj-$(CONFIG_VIDEO_VPSS_SYSTEM) += vpss.o 11obj-$(CONFIG_VIDEO_DM6446_CCDC) += vpfe_capture.o vpss.o dm644x_ccdc.o
15obj-$(CONFIG_VIDEO_VPFE_CAPTURE) += vpfe_capture.o 12obj-$(CONFIG_VIDEO_DM355_CCDC) += vpfe_capture.o vpss.o dm355_ccdc.o
16obj-$(CONFIG_VIDEO_DM6446_CCDC) += dm644x_ccdc.o 13obj-$(CONFIG_VIDEO_DM365_ISIF) += vpfe_capture.o vpss.o isif.o
17obj-$(CONFIG_VIDEO_DM355_CCDC) += dm355_ccdc.o 14obj-$(CONFIG_VIDEO_DAVINCI_VPBE_DISPLAY) += vpss.o vpbe.o vpbe_osd.o \
18obj-$(CONFIG_VIDEO_ISIF) += isif.o
19obj-$(CONFIG_VIDEO_DAVINCI_VPBE_DISPLAY) += vpbe.o vpbe_osd.o \
20 vpbe_venc.o vpbe_display.o 15 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 4277e4ad810c..05f8fb7f7b70 100644
--- a/drivers/media/platform/davinci/dm355_ccdc.c
+++ b/drivers/media/platform/davinci/dm355_ccdc.c
@@ -37,7 +37,6 @@
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/videodev2.h> 39#include <linux/videodev2.h>
40#include <linux/clk.h>
41#include <linux/err.h> 40#include <linux/err.h>
42#include <linux/module.h> 41#include <linux/module.h>
43 42
@@ -59,10 +58,6 @@ static struct ccdc_oper_config {
59 struct ccdc_params_raw bayer; 58 struct ccdc_params_raw bayer;
60 /* YCbCr configuration */ 59 /* YCbCr configuration */
61 struct ccdc_params_ycbcr ycbcr; 60 struct ccdc_params_ycbcr ycbcr;
62 /* Master clock */
63 struct clk *mclk;
64 /* slave clock */
65 struct clk *sclk;
66 /* ccdc base address */ 61 /* ccdc base address */
67 void __iomem *base_addr; 62 void __iomem *base_addr;
68} ccdc_cfg = { 63} ccdc_cfg = {
@@ -85,7 +80,7 @@ static struct ccdc_oper_config {
85 .mfilt1 = CCDC_NO_MEDIAN_FILTER1, 80 .mfilt1 = CCDC_NO_MEDIAN_FILTER1,
86 .mfilt2 = CCDC_NO_MEDIAN_FILTER2, 81 .mfilt2 = CCDC_NO_MEDIAN_FILTER2,
87 .alaw = { 82 .alaw = {
88 .gama_wd = 2, 83 .gamma_wd = 2,
89 }, 84 },
90 .blk_clamp = { 85 .blk_clamp = {
91 .sample_pixel = 1, 86 .sample_pixel = 1,
@@ -303,8 +298,8 @@ static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
303 } 298 }
304 299
305 if (ccdcparam->alaw.enable) { 300 if (ccdcparam->alaw.enable) {
306 if (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_13_4 || 301 if (ccdcparam->alaw.gamma_wd < CCDC_GAMMA_BITS_13_4 ||
307 ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) { 302 ccdcparam->alaw.gamma_wd > CCDC_GAMMA_BITS_09_0) {
308 dev_dbg(ccdc_cfg.dev, "Invalid value of ALAW\n"); 303 dev_dbg(ccdc_cfg.dev, "Invalid value of ALAW\n");
309 return -EINVAL; 304 return -EINVAL;
310 } 305 }
@@ -680,8 +675,8 @@ static int ccdc_config_raw(void)
680 /* Enable and configure aLaw register if needed */ 675 /* Enable and configure aLaw register if needed */
681 if (config_params->alaw.enable) { 676 if (config_params->alaw.enable) {
682 val |= (CCDC_ALAW_ENABLE | 677 val |= (CCDC_ALAW_ENABLE |
683 ((config_params->alaw.gama_wd & 678 ((config_params->alaw.gamma_wd &
684 CCDC_ALAW_GAMA_WD_MASK) << 679 CCDC_ALAW_GAMMA_WD_MASK) <<
685 CCDC_GAMMAWD_INPUT_SHIFT)); 680 CCDC_GAMMAWD_INPUT_SHIFT));
686 } 681 }
687 682
@@ -997,32 +992,10 @@ static int dm355_ccdc_probe(struct platform_device *pdev)
997 goto fail_nomem; 992 goto fail_nomem;
998 } 993 }
999 994
1000 /* Get and enable Master clock */
1001 ccdc_cfg.mclk = clk_get(&pdev->dev, "master");
1002 if (IS_ERR(ccdc_cfg.mclk)) {
1003 status = PTR_ERR(ccdc_cfg.mclk);
1004 goto fail_nomap;
1005 }
1006 if (clk_prepare_enable(ccdc_cfg.mclk)) {
1007 status = -ENODEV;
1008 goto fail_mclk;
1009 }
1010
1011 /* Get and enable Slave clock */
1012 ccdc_cfg.sclk = clk_get(&pdev->dev, "slave");
1013 if (IS_ERR(ccdc_cfg.sclk)) {
1014 status = PTR_ERR(ccdc_cfg.sclk);
1015 goto fail_mclk;
1016 }
1017 if (clk_prepare_enable(ccdc_cfg.sclk)) {
1018 status = -ENODEV;
1019 goto fail_sclk;
1020 }
1021
1022 /* Platform data holds setup_pinmux function ptr */ 995 /* Platform data holds setup_pinmux function ptr */
1023 if (NULL == pdev->dev.platform_data) { 996 if (NULL == pdev->dev.platform_data) {
1024 status = -ENODEV; 997 status = -ENODEV;
1025 goto fail_sclk; 998 goto fail_nomap;
1026 } 999 }
1027 setup_pinmux = pdev->dev.platform_data; 1000 setup_pinmux = pdev->dev.platform_data;
1028 /* 1001 /*
@@ -1033,12 +1006,6 @@ static int dm355_ccdc_probe(struct platform_device *pdev)
1033 ccdc_cfg.dev = &pdev->dev; 1006 ccdc_cfg.dev = &pdev->dev;
1034 printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name); 1007 printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name);
1035 return 0; 1008 return 0;
1036fail_sclk:
1037 clk_disable_unprepare(ccdc_cfg.sclk);
1038 clk_put(ccdc_cfg.sclk);
1039fail_mclk:
1040 clk_disable_unprepare(ccdc_cfg.mclk);
1041 clk_put(ccdc_cfg.mclk);
1042fail_nomap: 1009fail_nomap:
1043 iounmap(ccdc_cfg.base_addr); 1010 iounmap(ccdc_cfg.base_addr);
1044fail_nomem: 1011fail_nomem:
@@ -1052,10 +1019,6 @@ static int dm355_ccdc_remove(struct platform_device *pdev)
1052{ 1019{
1053 struct resource *res; 1020 struct resource *res;
1054 1021
1055 clk_disable_unprepare(ccdc_cfg.sclk);
1056 clk_disable_unprepare(ccdc_cfg.mclk);
1057 clk_put(ccdc_cfg.mclk);
1058 clk_put(ccdc_cfg.sclk);
1059 iounmap(ccdc_cfg.base_addr); 1022 iounmap(ccdc_cfg.base_addr);
1060 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1023 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1061 if (res) 1024 if (res)
diff --git a/drivers/media/platform/davinci/dm355_ccdc_regs.h b/drivers/media/platform/davinci/dm355_ccdc_regs.h
index d6d2ef0533b5..2e1946e0b99f 100644
--- a/drivers/media/platform/davinci/dm355_ccdc_regs.h
+++ b/drivers/media/platform/davinci/dm355_ccdc_regs.h
@@ -153,7 +153,7 @@
153#define CCDC_VDHDEN_ENABLE (1 << 16) 153#define CCDC_VDHDEN_ENABLE (1 << 16)
154#define CCDC_LPF_ENABLE (1 << 14) 154#define CCDC_LPF_ENABLE (1 << 14)
155#define CCDC_ALAW_ENABLE 1 155#define CCDC_ALAW_ENABLE 1
156#define CCDC_ALAW_GAMA_WD_MASK 7 156#define CCDC_ALAW_GAMMA_WD_MASK 7
157#define CCDC_REC656IF_BT656_EN 3 157#define CCDC_REC656IF_BT656_EN 3
158 158
159#define CCDC_FMTCFG_FMTMODE_MASK 3 159#define CCDC_FMTCFG_FMTMODE_MASK 3
diff --git a/drivers/media/platform/davinci/dm644x_ccdc.c b/drivers/media/platform/davinci/dm644x_ccdc.c
index 318e80512998..30fa08405d61 100644
--- a/drivers/media/platform/davinci/dm644x_ccdc.c
+++ b/drivers/media/platform/davinci/dm644x_ccdc.c
@@ -38,7 +38,6 @@
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/videodev2.h> 39#include <linux/videodev2.h>
40#include <linux/gfp.h> 40#include <linux/gfp.h>
41#include <linux/clk.h>
42#include <linux/err.h> 41#include <linux/err.h>
43#include <linux/module.h> 42#include <linux/module.h>
44 43
@@ -60,10 +59,6 @@ static struct ccdc_oper_config {
60 struct ccdc_params_raw bayer; 59 struct ccdc_params_raw bayer;
61 /* YCbCr configuration */ 60 /* YCbCr configuration */
62 struct ccdc_params_ycbcr ycbcr; 61 struct ccdc_params_ycbcr ycbcr;
63 /* Master clock */
64 struct clk *mclk;
65 /* slave clock */
66 struct clk *sclk;
67 /* ccdc base address */ 62 /* ccdc base address */
68 void __iomem *base_addr; 63 void __iomem *base_addr;
69} ccdc_cfg = { 64} ccdc_cfg = {
@@ -228,9 +223,12 @@ static void ccdc_readregs(void)
228static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam) 223static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
229{ 224{
230 if (ccdcparam->alaw.enable) { 225 if (ccdcparam->alaw.enable) {
231 if ((ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) || 226 u8 max_gamma = ccdc_gamma_width_max_bit(ccdcparam->alaw.gamma_wd);
232 (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_15_6) || 227 u8 max_data = ccdc_data_size_max_bit(ccdcparam->data_sz);
233 (ccdcparam->alaw.gama_wd < ccdcparam->data_sz)) { 228
229 if ((ccdcparam->alaw.gamma_wd > CCDC_GAMMA_BITS_09_0) ||
230 (ccdcparam->alaw.gamma_wd < CCDC_GAMMA_BITS_15_6) ||
231 (max_gamma > max_data)) {
234 dev_dbg(ccdc_cfg.dev, "\nInvalid data line select"); 232 dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
235 return -1; 233 return -1;
236 } 234 }
@@ -560,8 +558,8 @@ void ccdc_config_raw(void)
560 558
561 /* Enable and configure aLaw register if needed */ 559 /* Enable and configure aLaw register if needed */
562 if (config_params->alaw.enable) { 560 if (config_params->alaw.enable) {
563 val = ((config_params->alaw.gama_wd & 561 val = ((config_params->alaw.gamma_wd &
564 CCDC_ALAW_GAMA_WD_MASK) | CCDC_ALAW_ENABLE); 562 CCDC_ALAW_GAMMA_WD_MASK) | CCDC_ALAW_ENABLE);
565 regw(val, CCDC_ALAW); 563 regw(val, CCDC_ALAW);
566 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to ALAW...\n", val); 564 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to ALAW...\n", val);
567 } 565 }
@@ -988,38 +986,9 @@ static int dm644x_ccdc_probe(struct platform_device *pdev)
988 goto fail_nomem; 986 goto fail_nomem;
989 } 987 }
990 988
991 /* Get and enable Master clock */
992 ccdc_cfg.mclk = clk_get(&pdev->dev, "master");
993 if (IS_ERR(ccdc_cfg.mclk)) {
994 status = PTR_ERR(ccdc_cfg.mclk);
995 goto fail_nomap;
996 }
997 if (clk_prepare_enable(ccdc_cfg.mclk)) {
998 status = -ENODEV;
999 goto fail_mclk;
1000 }
1001
1002 /* Get and enable Slave clock */
1003 ccdc_cfg.sclk = clk_get(&pdev->dev, "slave");
1004 if (IS_ERR(ccdc_cfg.sclk)) {
1005 status = PTR_ERR(ccdc_cfg.sclk);
1006 goto fail_mclk;
1007 }
1008 if (clk_prepare_enable(ccdc_cfg.sclk)) {
1009 status = -ENODEV;
1010 goto fail_sclk;
1011 }
1012 ccdc_cfg.dev = &pdev->dev; 989 ccdc_cfg.dev = &pdev->dev;
1013 printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name); 990 printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name);
1014 return 0; 991 return 0;
1015fail_sclk:
1016 clk_disable_unprepare(ccdc_cfg.sclk);
1017 clk_put(ccdc_cfg.sclk);
1018fail_mclk:
1019 clk_disable_unprepare(ccdc_cfg.mclk);
1020 clk_put(ccdc_cfg.mclk);
1021fail_nomap:
1022 iounmap(ccdc_cfg.base_addr);
1023fail_nomem: 992fail_nomem:
1024 release_mem_region(res->start, resource_size(res)); 993 release_mem_region(res->start, resource_size(res));
1025fail_nores: 994fail_nores:
@@ -1031,10 +1000,6 @@ static int dm644x_ccdc_remove(struct platform_device *pdev)
1031{ 1000{
1032 struct resource *res; 1001 struct resource *res;
1033 1002
1034 clk_disable_unprepare(ccdc_cfg.mclk);
1035 clk_disable_unprepare(ccdc_cfg.sclk);
1036 clk_put(ccdc_cfg.mclk);
1037 clk_put(ccdc_cfg.sclk);
1038 iounmap(ccdc_cfg.base_addr); 1003 iounmap(ccdc_cfg.base_addr);
1039 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1004 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1040 if (res) 1005 if (res)
@@ -1049,18 +1014,12 @@ static int dm644x_ccdc_suspend(struct device *dev)
1049 ccdc_save_context(); 1014 ccdc_save_context();
1050 /* Disable CCDC */ 1015 /* Disable CCDC */
1051 ccdc_enable(0); 1016 ccdc_enable(0);
1052 /* Disable both master and slave clock */
1053 clk_disable_unprepare(ccdc_cfg.mclk);
1054 clk_disable_unprepare(ccdc_cfg.sclk);
1055 1017
1056 return 0; 1018 return 0;
1057} 1019}
1058 1020
1059static int dm644x_ccdc_resume(struct device *dev) 1021static int dm644x_ccdc_resume(struct device *dev)
1060{ 1022{
1061 /* Enable both master and slave clock */
1062 clk_prepare_enable(ccdc_cfg.mclk);
1063 clk_prepare_enable(ccdc_cfg.sclk);
1064 /* Restore CCDC context */ 1023 /* Restore CCDC context */
1065 ccdc_restore_context(); 1024 ccdc_restore_context();
1066 1025
diff --git a/drivers/media/platform/davinci/dm644x_ccdc_regs.h b/drivers/media/platform/davinci/dm644x_ccdc_regs.h
index 90370e414e2c..2b0aca5383f0 100644
--- a/drivers/media/platform/davinci/dm644x_ccdc_regs.h
+++ b/drivers/media/platform/davinci/dm644x_ccdc_regs.h
@@ -84,7 +84,7 @@
84#define CCDC_VDHDEN_ENABLE (1 << 16) 84#define CCDC_VDHDEN_ENABLE (1 << 16)
85#define CCDC_LPF_ENABLE (1 << 14) 85#define CCDC_LPF_ENABLE (1 << 14)
86#define CCDC_ALAW_ENABLE (1 << 3) 86#define CCDC_ALAW_ENABLE (1 << 3)
87#define CCDC_ALAW_GAMA_WD_MASK 7 87#define CCDC_ALAW_GAMMA_WD_MASK 7
88#define CCDC_BLK_CLAMP_ENABLE (1 << 31) 88#define CCDC_BLK_CLAMP_ENABLE (1 << 31)
89#define CCDC_BLK_SGAIN_MASK 0x1F 89#define CCDC_BLK_SGAIN_MASK 0x1F
90#define CCDC_BLK_ST_PXL_MASK 0x7FFF 90#define CCDC_BLK_ST_PXL_MASK 0x7FFF
diff --git a/drivers/media/platform/davinci/isif.c b/drivers/media/platform/davinci/isif.c
index 5050f9265f48..3332cca632e5 100644
--- a/drivers/media/platform/davinci/isif.c
+++ b/drivers/media/platform/davinci/isif.c
@@ -32,7 +32,6 @@
32#include <linux/uaccess.h> 32#include <linux/uaccess.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/videodev2.h> 34#include <linux/videodev2.h>
35#include <linux/clk.h>
36#include <linux/err.h> 35#include <linux/err.h>
37#include <linux/module.h> 36#include <linux/module.h>
38 37
@@ -88,8 +87,6 @@ static struct isif_oper_config {
88 struct isif_ycbcr_config ycbcr; 87 struct isif_ycbcr_config ycbcr;
89 struct isif_params_raw bayer; 88 struct isif_params_raw bayer;
90 enum isif_data_pack data_pack; 89 enum isif_data_pack data_pack;
91 /* Master clock */
92 struct clk *mclk;
93 /* ISIF base address */ 90 /* ISIF base address */
94 void __iomem *base_addr; 91 void __iomem *base_addr;
95 /* ISIF Linear Table 0 */ 92 /* ISIF Linear Table 0 */
@@ -604,7 +601,7 @@ static int isif_config_raw(void)
604 if (module_params->compress.alg == ISIF_ALAW) 601 if (module_params->compress.alg == ISIF_ALAW)
605 val |= ISIF_ALAW_ENABLE; 602 val |= ISIF_ALAW_ENABLE;
606 603
607 val |= (params->data_msb << ISIF_ALAW_GAMA_WD_SHIFT); 604 val |= (params->data_msb << ISIF_ALAW_GAMMA_WD_SHIFT);
608 regw(val, CGAMMAWD); 605 regw(val, CGAMMAWD);
609 606
610 /* Configure DPCM compression settings */ 607 /* Configure DPCM compression settings */
@@ -1039,6 +1036,10 @@ static int isif_probe(struct platform_device *pdev)
1039 void *__iomem addr; 1036 void *__iomem addr;
1040 int status = 0, i; 1037 int status = 0, i;
1041 1038
1039 /* Platform data holds setup_pinmux function ptr */
1040 if (!pdev->dev.platform_data)
1041 return -ENODEV;
1042
1042 /* 1043 /*
1043 * first try to register with vpfe. If not correct platform, then we 1044 * first try to register with vpfe. If not correct platform, then we
1044 * don't have to iomap 1045 * don't have to iomap
@@ -1047,22 +1048,6 @@ static int isif_probe(struct platform_device *pdev)
1047 if (status < 0) 1048 if (status < 0)
1048 return status; 1049 return status;
1049 1050
1050 /* Get and enable Master clock */
1051 isif_cfg.mclk = clk_get(&pdev->dev, "master");
1052 if (IS_ERR(isif_cfg.mclk)) {
1053 status = PTR_ERR(isif_cfg.mclk);
1054 goto fail_mclk;
1055 }
1056 if (clk_prepare_enable(isif_cfg.mclk)) {
1057 status = -ENODEV;
1058 goto fail_mclk;
1059 }
1060
1061 /* Platform data holds setup_pinmux function ptr */
1062 if (NULL == pdev->dev.platform_data) {
1063 status = -ENODEV;
1064 goto fail_mclk;
1065 }
1066 setup_pinmux = pdev->dev.platform_data; 1051 setup_pinmux = pdev->dev.platform_data;
1067 /* 1052 /*
1068 * setup Mux configuration for ccdc which may be different for 1053 * setup Mux configuration for ccdc which may be different for
@@ -1124,9 +1109,6 @@ fail_nobase_res:
1124 release_mem_region(res->start, resource_size(res)); 1109 release_mem_region(res->start, resource_size(res));
1125 i--; 1110 i--;
1126 } 1111 }
1127fail_mclk:
1128 clk_disable_unprepare(isif_cfg.mclk);
1129 clk_put(isif_cfg.mclk);
1130 vpfe_unregister_ccdc_device(&isif_hw_dev); 1112 vpfe_unregister_ccdc_device(&isif_hw_dev);
1131 return status; 1113 return status;
1132} 1114}
@@ -1146,8 +1128,6 @@ static int isif_remove(struct platform_device *pdev)
1146 i++; 1128 i++;
1147 } 1129 }
1148 vpfe_unregister_ccdc_device(&isif_hw_dev); 1130 vpfe_unregister_ccdc_device(&isif_hw_dev);
1149 clk_disable_unprepare(isif_cfg.mclk);
1150 clk_put(isif_cfg.mclk);
1151 return 0; 1131 return 0;
1152} 1132}
1153 1133
diff --git a/drivers/media/platform/davinci/isif_regs.h b/drivers/media/platform/davinci/isif_regs.h
index aa69a463c122..3993aece821b 100644
--- a/drivers/media/platform/davinci/isif_regs.h
+++ b/drivers/media/platform/davinci/isif_regs.h
@@ -203,8 +203,8 @@
203#define ISIF_LPF_MASK 1 203#define ISIF_LPF_MASK 1
204 204
205/* GAMMAWD registers */ 205/* GAMMAWD registers */
206#define ISIF_ALAW_GAMA_WD_MASK 0xF 206#define ISIF_ALAW_GAMMA_WD_MASK 0xF
207#define ISIF_ALAW_GAMA_WD_SHIFT 1 207#define ISIF_ALAW_GAMMA_WD_SHIFT 1
208#define ISIF_ALAW_ENABLE 1 208#define ISIF_ALAW_ENABLE 1
209#define ISIF_GAMMAWD_CFA_SHIFT 5 209#define ISIF_GAMMAWD_CFA_SHIFT 5
210 210
diff --git a/drivers/media/platform/davinci/vpbe.c b/drivers/media/platform/davinci/vpbe.c
index 4ca0f9a2ad8a..33b9660b7f77 100644
--- a/drivers/media/platform/davinci/vpbe.c
+++ b/drivers/media/platform/davinci/vpbe.c
@@ -344,7 +344,7 @@ static int vpbe_s_dv_timings(struct vpbe_device *vpbe_dev,
344 return -EINVAL; 344 return -EINVAL;
345 345
346 for (i = 0; i < output->num_modes; i++) { 346 for (i = 0; i < output->num_modes; i++) {
347 if (output->modes[i].timings_type == VPBE_ENC_CUSTOM_TIMINGS && 347 if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS &&
348 !memcmp(&output->modes[i].dv_timings, 348 !memcmp(&output->modes[i].dv_timings,
349 dv_timings, sizeof(*dv_timings))) 349 dv_timings, sizeof(*dv_timings)))
350 break; 350 break;
@@ -385,7 +385,7 @@ static int vpbe_g_dv_timings(struct vpbe_device *vpbe_dev,
385 struct v4l2_dv_timings *dv_timings) 385 struct v4l2_dv_timings *dv_timings)
386{ 386{
387 if (vpbe_dev->current_timings.timings_type & 387 if (vpbe_dev->current_timings.timings_type &
388 VPBE_ENC_CUSTOM_TIMINGS) { 388 VPBE_ENC_DV_TIMINGS) {
389 *dv_timings = vpbe_dev->current_timings.dv_timings; 389 *dv_timings = vpbe_dev->current_timings.dv_timings;
390 return 0; 390 return 0;
391 } 391 }
@@ -412,7 +412,7 @@ static int vpbe_enum_dv_timings(struct vpbe_device *vpbe_dev,
412 return -EINVAL; 412 return -EINVAL;
413 413
414 for (i = 0; i < output->num_modes; i++) { 414 for (i = 0; i < output->num_modes; i++) {
415 if (output->modes[i].timings_type == VPBE_ENC_CUSTOM_TIMINGS) { 415 if (output->modes[i].timings_type == VPBE_ENC_DV_TIMINGS) {
416 if (j == timings->index) 416 if (j == timings->index)
417 break; 417 break;
418 j++; 418 j++;
@@ -431,7 +431,7 @@ static int vpbe_enum_dv_timings(struct vpbe_device *vpbe_dev,
431 * Sets the standard if supported by the current encoder. Return the status. 431 * Sets the standard if supported by the current encoder. Return the status.
432 * 0 - success & -EINVAL on error 432 * 0 - success & -EINVAL on error
433 */ 433 */
434static int vpbe_s_std(struct vpbe_device *vpbe_dev, v4l2_std_id *std_id) 434static int vpbe_s_std(struct vpbe_device *vpbe_dev, v4l2_std_id std_id)
435{ 435{
436 struct vpbe_config *cfg = vpbe_dev->cfg; 436 struct vpbe_config *cfg = vpbe_dev->cfg;
437 int out_index = vpbe_dev->current_out_index; 437 int out_index = vpbe_dev->current_out_index;
@@ -442,14 +442,14 @@ static int vpbe_s_std(struct vpbe_device *vpbe_dev, v4l2_std_id *std_id)
442 V4L2_OUT_CAP_STD)) 442 V4L2_OUT_CAP_STD))
443 return -EINVAL; 443 return -EINVAL;
444 444
445 ret = vpbe_get_std_info(vpbe_dev, *std_id); 445 ret = vpbe_get_std_info(vpbe_dev, std_id);
446 if (ret) 446 if (ret)
447 return ret; 447 return ret;
448 448
449 mutex_lock(&vpbe_dev->lock); 449 mutex_lock(&vpbe_dev->lock);
450 450
451 ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video, 451 ret = v4l2_subdev_call(vpbe_dev->encoders[sd_index], video,
452 s_std_output, *std_id); 452 s_std_output, std_id);
453 /* set the lcd controller output for the given mode */ 453 /* set the lcd controller output for the given mode */
454 if (!ret) { 454 if (!ret) {
455 struct osd_state *osd_device = vpbe_dev->osd_device; 455 struct osd_state *osd_device = vpbe_dev->osd_device;
@@ -513,9 +513,9 @@ static int vpbe_set_mode(struct vpbe_device *vpbe_dev,
513 */ 513 */
514 if (preset_mode->timings_type & VPBE_ENC_STD) 514 if (preset_mode->timings_type & VPBE_ENC_STD)
515 return vpbe_s_std(vpbe_dev, 515 return vpbe_s_std(vpbe_dev,
516 &preset_mode->std_id); 516 preset_mode->std_id);
517 if (preset_mode->timings_type & 517 if (preset_mode->timings_type &
518 VPBE_ENC_CUSTOM_TIMINGS) { 518 VPBE_ENC_DV_TIMINGS) {
519 dv_timings = 519 dv_timings =
520 preset_mode->dv_timings; 520 preset_mode->dv_timings;
521 return vpbe_s_dv_timings(vpbe_dev, &dv_timings); 521 return vpbe_s_dv_timings(vpbe_dev, &dv_timings);
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index 5e6b0cab514b..1802f11e939f 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -983,7 +983,7 @@ static int vpbe_display_try_fmt(struct file *file, void *priv,
983 * 0 - success & -EINVAL on error 983 * 0 - success & -EINVAL on error
984 */ 984 */
985static int vpbe_display_s_std(struct file *file, void *priv, 985static int vpbe_display_s_std(struct file *file, void *priv,
986 v4l2_std_id *std_id) 986 v4l2_std_id std_id)
987{ 987{
988 struct vpbe_fh *fh = priv; 988 struct vpbe_fh *fh = priv;
989 struct vpbe_layer *layer = fh->layer; 989 struct vpbe_layer *layer = fh->layer;
@@ -1176,10 +1176,6 @@ vpbe_display_s_dv_timings(struct file *file, void *priv,
1176 "Failed to set the dv timings info\n"); 1176 "Failed to set the dv timings info\n");
1177 return -EINVAL; 1177 return -EINVAL;
1178 } 1178 }
1179 /* set the current norm to zero to be consistent. If STD is used
1180 * v4l2 layer will set the norm properly on successful s_std call
1181 */
1182 layer->video_dev.current_norm = 0;
1183 1179
1184 return 0; 1180 return 0;
1185} 1181}
@@ -1202,7 +1198,7 @@ vpbe_display_g_dv_timings(struct file *file, void *priv,
1202 /* Get the given standard in the encoder */ 1198 /* Get the given standard in the encoder */
1203 1199
1204 if (vpbe_dev->current_timings.timings_type & 1200 if (vpbe_dev->current_timings.timings_type &
1205 VPBE_ENC_CUSTOM_TIMINGS) { 1201 VPBE_ENC_DV_TIMINGS) {
1206 *dv_timings = vpbe_dev->current_timings.dv_timings; 1202 *dv_timings = vpbe_dev->current_timings.dv_timings;
1207 } else { 1203 } else {
1208 return -EINVAL; 1204 return -EINVAL;
@@ -1404,6 +1400,7 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1404 q->ops = &video_qops; 1400 q->ops = &video_qops;
1405 q->mem_ops = &vb2_dma_contig_memops; 1401 q->mem_ops = &vb2_dma_contig_memops;
1406 q->buf_struct_size = sizeof(struct vpbe_disp_buffer); 1402 q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
1403 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1407 1404
1408 ret = vb2_queue_init(q); 1405 ret = vb2_queue_init(q);
1409 if (ret) { 1406 if (ret) {
@@ -1600,7 +1597,7 @@ static int vpbe_display_g_register(struct file *file, void *priv,
1600} 1597}
1601 1598
1602static int vpbe_display_s_register(struct file *file, void *priv, 1599static int vpbe_display_s_register(struct file *file, void *priv,
1603 struct v4l2_dbg_register *reg) 1600 const struct v4l2_dbg_register *reg)
1604{ 1601{
1605 return 0; 1602 return 0;
1606} 1603}
@@ -1693,12 +1690,8 @@ static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
1693 vbd->vfl_dir = VFL_DIR_TX; 1690 vbd->vfl_dir = VFL_DIR_TX;
1694 1691
1695 if (disp_dev->vpbe_dev->current_timings.timings_type & 1692 if (disp_dev->vpbe_dev->current_timings.timings_type &
1696 VPBE_ENC_STD) { 1693 VPBE_ENC_STD)
1697 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50); 1694 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50);
1698 vbd->current_norm =
1699 disp_dev->vpbe_dev->current_timings.std_id;
1700 } else
1701 vbd->current_norm = 0;
1702 1695
1703 snprintf(vbd->name, sizeof(vbd->name), 1696 snprintf(vbd->name, sizeof(vbd->name),
1704 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d", 1697 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
diff --git a/drivers/media/platform/davinci/vpbe_osd.c b/drivers/media/platform/davinci/vpbe_osd.c
index 12ad17c52ef3..396a51cbede7 100644
--- a/drivers/media/platform/davinci/vpbe_osd.c
+++ b/drivers/media/platform/davinci/vpbe_osd.c
@@ -52,6 +52,9 @@ static struct platform_device_id vpbe_osd_devtype[] = {
52 .name = DM355_VPBE_OSD_SUBDEV_NAME, 52 .name = DM355_VPBE_OSD_SUBDEV_NAME,
53 .driver_data = VPBE_VERSION_3, 53 .driver_data = VPBE_VERSION_3,
54 }, 54 },
55 {
56 /* sentinel */
57 }
55}; 58};
56 59
57MODULE_DEVICE_TABLE(platform, vpbe_osd_devtype); 60MODULE_DEVICE_TABLE(platform, vpbe_osd_devtype);
diff --git a/drivers/media/platform/davinci/vpbe_venc.c b/drivers/media/platform/davinci/vpbe_venc.c
index bdbebd59df98..87eef9be08ed 100644
--- a/drivers/media/platform/davinci/vpbe_venc.c
+++ b/drivers/media/platform/davinci/vpbe_venc.c
@@ -51,6 +51,9 @@ static struct platform_device_id vpbe_venc_devtype[] = {
51 .name = DM355_VPBE_VENC_SUBDEV_NAME, 51 .name = DM355_VPBE_VENC_SUBDEV_NAME,
52 .driver_data = VPBE_VERSION_3, 52 .driver_data = VPBE_VERSION_3,
53 }, 53 },
54 {
55 /* sentinel */
56 }
54}; 57};
55 58
56MODULE_DEVICE_TABLE(platform, vpbe_venc_devtype); 59MODULE_DEVICE_TABLE(platform, vpbe_venc_devtype);
@@ -199,6 +202,25 @@ static void venc_enabledigitaloutput(struct v4l2_subdev *sd, int benable)
199 } 202 }
200} 203}
201 204
205static void
206venc_enable_vpss_clock(int venc_type,
207 enum vpbe_enc_timings_type type,
208 unsigned int pclock)
209{
210 if (venc_type == VPBE_VERSION_1)
211 return;
212
213 if (venc_type == VPBE_VERSION_2 && (type == VPBE_ENC_STD || (type ==
214 VPBE_ENC_DV_TIMINGS && pclock <= 27000000))) {
215 vpss_enable_clock(VPSS_VENC_CLOCK_SEL, 1);
216 vpss_enable_clock(VPSS_VPBE_CLOCK, 1);
217 return;
218 }
219
220 if (venc_type == VPBE_VERSION_3 && type == VPBE_ENC_STD)
221 vpss_enable_clock(VPSS_VENC_CLOCK_SEL, 0);
222}
223
202#define VDAC_CONFIG_SD_V3 0x0E21A6B6 224#define VDAC_CONFIG_SD_V3 0x0E21A6B6
203#define VDAC_CONFIG_SD_V2 0x081141CF 225#define VDAC_CONFIG_SD_V2 0x081141CF
204/* 226/*
@@ -217,6 +239,7 @@ static int venc_set_ntsc(struct v4l2_subdev *sd)
217 if (pdata->setup_clock(VPBE_ENC_STD, V4L2_STD_525_60) < 0) 239 if (pdata->setup_clock(VPBE_ENC_STD, V4L2_STD_525_60) < 0)
218 return -EINVAL; 240 return -EINVAL;
219 241
242 venc_enable_vpss_clock(venc->venc_type, VPBE_ENC_STD, V4L2_STD_525_60);
220 venc_enabledigitaloutput(sd, 0); 243 venc_enabledigitaloutput(sd, 0);
221 244
222 if (venc->venc_type == VPBE_VERSION_3) { 245 if (venc->venc_type == VPBE_VERSION_3) {
@@ -262,6 +285,7 @@ static int venc_set_pal(struct v4l2_subdev *sd)
262 if (venc->pdata->setup_clock(VPBE_ENC_STD, V4L2_STD_625_50) < 0) 285 if (venc->pdata->setup_clock(VPBE_ENC_STD, V4L2_STD_625_50) < 0)
263 return -EINVAL; 286 return -EINVAL;
264 287
288 venc_enable_vpss_clock(venc->venc_type, VPBE_ENC_STD, V4L2_STD_625_50);
265 venc_enabledigitaloutput(sd, 0); 289 venc_enabledigitaloutput(sd, 0);
266 290
267 if (venc->venc_type == VPBE_VERSION_3) { 291 if (venc->venc_type == VPBE_VERSION_3) {
@@ -313,9 +337,10 @@ static int venc_set_480p59_94(struct v4l2_subdev *sd)
313 return -EINVAL; 337 return -EINVAL;
314 338
315 /* Setup clock at VPSS & VENC for SD */ 339 /* Setup clock at VPSS & VENC for SD */
316 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 27000000) < 0) 340 if (pdata->setup_clock(VPBE_ENC_DV_TIMINGS, 27000000) < 0)
317 return -EINVAL; 341 return -EINVAL;
318 342
343 venc_enable_vpss_clock(venc->venc_type, VPBE_ENC_DV_TIMINGS, 27000000);
319 venc_enabledigitaloutput(sd, 0); 344 venc_enabledigitaloutput(sd, 0);
320 345
321 if (venc->venc_type == VPBE_VERSION_2) 346 if (venc->venc_type == VPBE_VERSION_2)
@@ -360,9 +385,10 @@ static int venc_set_576p50(struct v4l2_subdev *sd)
360 venc->venc_type != VPBE_VERSION_2) 385 venc->venc_type != VPBE_VERSION_2)
361 return -EINVAL; 386 return -EINVAL;
362 /* Setup clock at VPSS & VENC for SD */ 387 /* Setup clock at VPSS & VENC for SD */
363 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 27000000) < 0) 388 if (pdata->setup_clock(VPBE_ENC_DV_TIMINGS, 27000000) < 0)
364 return -EINVAL; 389 return -EINVAL;
365 390
391 venc_enable_vpss_clock(venc->venc_type, VPBE_ENC_DV_TIMINGS, 27000000);
366 venc_enabledigitaloutput(sd, 0); 392 venc_enabledigitaloutput(sd, 0);
367 393
368 if (venc->venc_type == VPBE_VERSION_2) 394 if (venc->venc_type == VPBE_VERSION_2)
@@ -400,9 +426,10 @@ static int venc_set_720p60_internal(struct v4l2_subdev *sd)
400 struct venc_state *venc = to_state(sd); 426 struct venc_state *venc = to_state(sd);
401 struct venc_platform_data *pdata = venc->pdata; 427 struct venc_platform_data *pdata = venc->pdata;
402 428
403 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 74250000) < 0) 429 if (pdata->setup_clock(VPBE_ENC_DV_TIMINGS, 74250000) < 0)
404 return -EINVAL; 430 return -EINVAL;
405 431
432 venc_enable_vpss_clock(venc->venc_type, VPBE_ENC_DV_TIMINGS, 74250000);
406 venc_enabledigitaloutput(sd, 0); 433 venc_enabledigitaloutput(sd, 0);
407 434
408 venc_write(sd, VENC_OSDCLK0, 0); 435 venc_write(sd, VENC_OSDCLK0, 0);
@@ -428,9 +455,10 @@ static int venc_set_1080i30_internal(struct v4l2_subdev *sd)
428 struct venc_state *venc = to_state(sd); 455 struct venc_state *venc = to_state(sd);
429 struct venc_platform_data *pdata = venc->pdata; 456 struct venc_platform_data *pdata = venc->pdata;
430 457
431 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 74250000) < 0) 458 if (pdata->setup_clock(VPBE_ENC_DV_TIMINGS, 74250000) < 0)
432 return -EINVAL; 459 return -EINVAL;
433 460
461 venc_enable_vpss_clock(venc->venc_type, VPBE_ENC_DV_TIMINGS, 74250000);
434 venc_enabledigitaloutput(sd, 0); 462 venc_enabledigitaloutput(sd, 0);
435 463
436 venc_write(sd, VENC_OSDCLK0, 0); 464 venc_write(sd, VENC_OSDCLK0, 0);
diff --git a/drivers/media/platform/davinci/vpfe_capture.c b/drivers/media/platform/davinci/vpfe_capture.c
index 28d019da4c01..8c50d3074866 100644
--- a/drivers/media/platform/davinci/vpfe_capture.c
+++ b/drivers/media/platform/davinci/vpfe_capture.c
@@ -376,7 +376,7 @@ static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe_dev)
376 * values in ccdc 376 * values in ccdc
377 */ 377 */
378static int vpfe_config_image_format(struct vpfe_device *vpfe_dev, 378static int vpfe_config_image_format(struct vpfe_device *vpfe_dev,
379 const v4l2_std_id *std_id) 379 v4l2_std_id std_id)
380{ 380{
381 struct vpfe_subdev_info *sdinfo = vpfe_dev->current_subdev; 381 struct vpfe_subdev_info *sdinfo = vpfe_dev->current_subdev;
382 struct v4l2_mbus_framefmt mbus_fmt; 382 struct v4l2_mbus_framefmt mbus_fmt;
@@ -384,7 +384,7 @@ static int vpfe_config_image_format(struct vpfe_device *vpfe_dev,
384 int i, ret = 0; 384 int i, ret = 0;
385 385
386 for (i = 0; i < ARRAY_SIZE(vpfe_standards); i++) { 386 for (i = 0; i < ARRAY_SIZE(vpfe_standards); i++) {
387 if (vpfe_standards[i].std_id & *std_id) { 387 if (vpfe_standards[i].std_id & std_id) {
388 vpfe_dev->std_info.active_pixels = 388 vpfe_dev->std_info.active_pixels =
389 vpfe_standards[i].width; 389 vpfe_standards[i].width;
390 vpfe_dev->std_info.active_lines = 390 vpfe_dev->std_info.active_lines =
@@ -461,7 +461,7 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe_dev)
461 461
462 /* Configure the default format information */ 462 /* Configure the default format information */
463 ret = vpfe_config_image_format(vpfe_dev, 463 ret = vpfe_config_image_format(vpfe_dev,
464 &vpfe_standards[vpfe_dev->std_index].std_id); 464 vpfe_standards[vpfe_dev->std_index].std_id);
465 if (ret) 465 if (ret)
466 return ret; 466 return ret;
467 467
@@ -1107,6 +1107,7 @@ static int vpfe_g_input(struct file *file, void *priv, unsigned int *index)
1107static int vpfe_s_input(struct file *file, void *priv, unsigned int index) 1107static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1108{ 1108{
1109 struct vpfe_device *vpfe_dev = video_drvdata(file); 1109 struct vpfe_device *vpfe_dev = video_drvdata(file);
1110 struct v4l2_subdev *sd;
1110 struct vpfe_subdev_info *sdinfo; 1111 struct vpfe_subdev_info *sdinfo;
1111 int subdev_index, inp_index; 1112 int subdev_index, inp_index;
1112 struct vpfe_route *route; 1113 struct vpfe_route *route;
@@ -1138,14 +1139,15 @@ static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1138 } 1139 }
1139 1140
1140 sdinfo = &vpfe_dev->cfg->sub_devs[subdev_index]; 1141 sdinfo = &vpfe_dev->cfg->sub_devs[subdev_index];
1142 sd = vpfe_dev->sd[subdev_index];
1141 route = &sdinfo->routes[inp_index]; 1143 route = &sdinfo->routes[inp_index];
1142 if (route && sdinfo->can_route) { 1144 if (route && sdinfo->can_route) {
1143 input = route->input; 1145 input = route->input;
1144 output = route->output; 1146 output = route->output;
1145 } 1147 }
1146 1148
1147 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id, 1149 if (sd)
1148 video, s_routing, input, output, 0); 1150 ret = v4l2_subdev_call(sd, video, s_routing, input, output, 0);
1149 1151
1150 if (ret) { 1152 if (ret) {
1151 v4l2_err(&vpfe_dev->v4l2_dev, 1153 v4l2_err(&vpfe_dev->v4l2_dev,
@@ -1154,6 +1156,8 @@ static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1154 goto unlock_out; 1156 goto unlock_out;
1155 } 1157 }
1156 vpfe_dev->current_subdev = sdinfo; 1158 vpfe_dev->current_subdev = sdinfo;
1159 if (sd)
1160 vpfe_dev->v4l2_dev.ctrl_handler = sd->ctrl_handler;
1157 vpfe_dev->current_input = index; 1161 vpfe_dev->current_input = index;
1158 vpfe_dev->std_index = 0; 1162 vpfe_dev->std_index = 0;
1159 1163
@@ -1164,7 +1168,7 @@ static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1164 1168
1165 /* set the default image parameters in the device */ 1169 /* set the default image parameters in the device */
1166 ret = vpfe_config_image_format(vpfe_dev, 1170 ret = vpfe_config_image_format(vpfe_dev,
1167 &vpfe_standards[vpfe_dev->std_index].std_id); 1171 vpfe_standards[vpfe_dev->std_index].std_id);
1168unlock_out: 1172unlock_out:
1169 mutex_unlock(&vpfe_dev->lock); 1173 mutex_unlock(&vpfe_dev->lock);
1170 return ret; 1174 return ret;
@@ -1189,7 +1193,7 @@ static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
1189 return ret; 1193 return ret;
1190} 1194}
1191 1195
1192static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id *std_id) 1196static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id std_id)
1193{ 1197{
1194 struct vpfe_device *vpfe_dev = video_drvdata(file); 1198 struct vpfe_device *vpfe_dev = video_drvdata(file);
1195 struct vpfe_subdev_info *sdinfo; 1199 struct vpfe_subdev_info *sdinfo;
@@ -1211,7 +1215,7 @@ static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
1211 } 1215 }
1212 1216
1213 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id, 1217 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1214 core, s_std, *std_id); 1218 core, s_std, std_id);
1215 if (ret < 0) { 1219 if (ret < 0) {
1216 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to set standard\n"); 1220 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to set standard\n");
1217 goto unlock_out; 1221 goto unlock_out;
@@ -1439,41 +1443,6 @@ static int vpfe_dqbuf(struct file *file, void *priv,
1439 buf, file->f_flags & O_NONBLOCK); 1443 buf, file->f_flags & O_NONBLOCK);
1440} 1444}
1441 1445
1442static int vpfe_queryctrl(struct file *file, void *priv,
1443 struct v4l2_queryctrl *qctrl)
1444{
1445 struct vpfe_device *vpfe_dev = video_drvdata(file);
1446 struct vpfe_subdev_info *sdinfo;
1447
1448 sdinfo = vpfe_dev->current_subdev;
1449
1450 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1451 core, queryctrl, qctrl);
1452
1453}
1454
1455static int vpfe_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl)
1456{
1457 struct vpfe_device *vpfe_dev = video_drvdata(file);
1458 struct vpfe_subdev_info *sdinfo;
1459
1460 sdinfo = vpfe_dev->current_subdev;
1461
1462 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1463 core, g_ctrl, ctrl);
1464}
1465
1466static int vpfe_s_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl)
1467{
1468 struct vpfe_device *vpfe_dev = video_drvdata(file);
1469 struct vpfe_subdev_info *sdinfo;
1470
1471 sdinfo = vpfe_dev->current_subdev;
1472
1473 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1474 core, s_ctrl, ctrl);
1475}
1476
1477/* 1446/*
1478 * vpfe_calculate_offsets : This function calculates buffers offset 1447 * vpfe_calculate_offsets : This function calculates buffers offset
1479 * for top and bottom field 1448 * for top and bottom field
@@ -1717,7 +1686,7 @@ unlock_out:
1717 1686
1718 1687
1719static long vpfe_param_handler(struct file *file, void *priv, 1688static long vpfe_param_handler(struct file *file, void *priv,
1720 bool valid_prio, int cmd, void *param) 1689 bool valid_prio, unsigned int cmd, void *param)
1721{ 1690{
1722 struct vpfe_device *vpfe_dev = video_drvdata(file); 1691 struct vpfe_device *vpfe_dev = video_drvdata(file);
1723 int ret = 0; 1692 int ret = 0;
@@ -1781,9 +1750,6 @@ static const struct v4l2_ioctl_ops vpfe_ioctl_ops = {
1781 .vidioc_querystd = vpfe_querystd, 1750 .vidioc_querystd = vpfe_querystd,
1782 .vidioc_s_std = vpfe_s_std, 1751 .vidioc_s_std = vpfe_s_std,
1783 .vidioc_g_std = vpfe_g_std, 1752 .vidioc_g_std = vpfe_g_std,
1784 .vidioc_queryctrl = vpfe_queryctrl,
1785 .vidioc_g_ctrl = vpfe_g_ctrl,
1786 .vidioc_s_ctrl = vpfe_s_ctrl,
1787 .vidioc_reqbufs = vpfe_reqbufs, 1753 .vidioc_reqbufs = vpfe_reqbufs,
1788 .vidioc_querybuf = vpfe_querybuf, 1754 .vidioc_querybuf = vpfe_querybuf,
1789 .vidioc_qbuf = vpfe_qbuf, 1755 .vidioc_qbuf = vpfe_qbuf,
@@ -1918,7 +1884,6 @@ static int vpfe_probe(struct platform_device *pdev)
1918 vfd->fops = &vpfe_fops; 1884 vfd->fops = &vpfe_fops;
1919 vfd->ioctl_ops = &vpfe_ioctl_ops; 1885 vfd->ioctl_ops = &vpfe_ioctl_ops;
1920 vfd->tvnorms = 0; 1886 vfd->tvnorms = 0;
1921 vfd->current_norm = V4L2_STD_PAL;
1922 vfd->v4l2_dev = &vpfe_dev->v4l2_dev; 1887 vfd->v4l2_dev = &vpfe_dev->v4l2_dev;
1923 snprintf(vfd->name, sizeof(vfd->name), 1888 snprintf(vfd->name, sizeof(vfd->name),
1924 "%s_V%d.%d.%d", 1889 "%s_V%d.%d.%d",
@@ -2007,6 +1972,7 @@ static int vpfe_probe(struct platform_device *pdev)
2007 1972
2008 /* set first sub device as current one */ 1973 /* set first sub device as current one */
2009 vpfe_dev->current_subdev = &vpfe_cfg->sub_devs[0]; 1974 vpfe_dev->current_subdev = &vpfe_cfg->sub_devs[0];
1975 vpfe_dev->v4l2_dev.ctrl_handler = vpfe_dev->sd[0]->ctrl_handler;
2010 1976
2011 /* We have at least one sub device to work with */ 1977 /* We have at least one sub device to work with */
2012 mutex_unlock(&ccdc_lock); 1978 mutex_unlock(&ccdc_lock);
diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c
index 28638a86f129..ea82a8bd2803 100644
--- a/drivers/media/platform/davinci/vpif.c
+++ b/drivers/media/platform/davinci/vpif.c
@@ -23,8 +23,8 @@
23#include <linux/spinlock.h> 23#include <linux/spinlock.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/clk.h>
27#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/pm_runtime.h>
28#include <linux/v4l2-dv-timings.h> 28#include <linux/v4l2-dv-timings.h>
29 29
30#include <mach/hardware.h> 30#include <mach/hardware.h>
@@ -44,13 +44,13 @@ static struct resource *res;
44spinlock_t vpif_lock; 44spinlock_t vpif_lock;
45 45
46void __iomem *vpif_base; 46void __iomem *vpif_base;
47struct clk *vpif_clk; 47EXPORT_SYMBOL_GPL(vpif_base);
48 48
49/** 49/**
50 * ch_params: video standard configuration parameters for vpif 50 * vpif_ch_params: video standard configuration parameters for vpif
51 * The table must include all presets from supported subdevices. 51 * The table must include all presets from supported subdevices.
52 */ 52 */
53const struct vpif_channel_config_params ch_params[] = { 53const struct vpif_channel_config_params vpif_ch_params[] = {
54 /* HDTV formats */ 54 /* HDTV formats */
55 { 55 {
56 .name = "480p59_94", 56 .name = "480p59_94",
@@ -220,8 +220,10 @@ const struct vpif_channel_config_params ch_params[] = {
220 .stdid = V4L2_STD_625_50, 220 .stdid = V4L2_STD_625_50,
221 }, 221 },
222}; 222};
223EXPORT_SYMBOL_GPL(vpif_ch_params);
223 224
224const unsigned int vpif_ch_params_count = ARRAY_SIZE(ch_params); 225const unsigned int vpif_ch_params_count = ARRAY_SIZE(vpif_ch_params);
226EXPORT_SYMBOL_GPL(vpif_ch_params_count);
225 227
226static inline void vpif_wr_bit(u32 reg, u32 bit, u32 val) 228static inline void vpif_wr_bit(u32 reg, u32 bit, u32 val)
227{ 229{
@@ -439,19 +441,13 @@ static int vpif_probe(struct platform_device *pdev)
439 goto fail; 441 goto fail;
440 } 442 }
441 443
442 vpif_clk = clk_get(&pdev->dev, "vpif"); 444 pm_runtime_enable(&pdev->dev);
443 if (IS_ERR(vpif_clk)) { 445 pm_runtime_get(&pdev->dev);
444 status = PTR_ERR(vpif_clk);
445 goto clk_fail;
446 }
447 clk_prepare_enable(vpif_clk);
448 446
449 spin_lock_init(&vpif_lock); 447 spin_lock_init(&vpif_lock);
450 dev_info(&pdev->dev, "vpif probe success\n"); 448 dev_info(&pdev->dev, "vpif probe success\n");
451 return 0; 449 return 0;
452 450
453clk_fail:
454 iounmap(vpif_base);
455fail: 451fail:
456 release_mem_region(res->start, res_len); 452 release_mem_region(res->start, res_len);
457 return status; 453 return status;
@@ -459,11 +455,7 @@ fail:
459 455
460static int vpif_remove(struct platform_device *pdev) 456static int vpif_remove(struct platform_device *pdev)
461{ 457{
462 if (vpif_clk) { 458 pm_runtime_disable(&pdev->dev);
463 clk_disable_unprepare(vpif_clk);
464 clk_put(vpif_clk);
465 }
466
467 iounmap(vpif_base); 459 iounmap(vpif_base);
468 release_mem_region(res->start, res_len); 460 release_mem_region(res->start, res_len);
469 return 0; 461 return 0;
@@ -472,13 +464,13 @@ static int vpif_remove(struct platform_device *pdev)
472#ifdef CONFIG_PM 464#ifdef CONFIG_PM
473static int vpif_suspend(struct device *dev) 465static int vpif_suspend(struct device *dev)
474{ 466{
475 clk_disable_unprepare(vpif_clk); 467 pm_runtime_put(dev);
476 return 0; 468 return 0;
477} 469}
478 470
479static int vpif_resume(struct device *dev) 471static int vpif_resume(struct device *dev)
480{ 472{
481 clk_prepare_enable(vpif_clk); 473 pm_runtime_get(dev);
482 return 0; 474 return 0;
483} 475}
484 476
diff --git a/drivers/media/platform/davinci/vpif.h b/drivers/media/platform/davinci/vpif.h
index a1ab6a0f4e9e..9956e6788693 100644
--- a/drivers/media/platform/davinci/vpif.h
+++ b/drivers/media/platform/davinci/vpif.h
@@ -638,7 +638,7 @@ struct vpif_channel_config_params {
638}; 638};
639 639
640extern const unsigned int vpif_ch_params_count; 640extern const unsigned int vpif_ch_params_count;
641extern const struct vpif_channel_config_params ch_params[]; 641extern const struct vpif_channel_config_params vpif_ch_params[];
642 642
643struct vpif_video_params; 643struct vpif_video_params;
644struct vpif_params; 644struct vpif_params;
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 5892d2bc8eee..5f98df1fc8a0 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -563,7 +563,7 @@ static int vpif_update_std_info(struct channel_obj *ch)
563 vpif_dbg(2, debug, "vpif_update_std_info\n"); 563 vpif_dbg(2, debug, "vpif_update_std_info\n");
564 564
565 for (index = 0; index < vpif_ch_params_count; index++) { 565 for (index = 0; index < vpif_ch_params_count; index++) {
566 config = &ch_params[index]; 566 config = &vpif_ch_params[index];
567 if (config->hd_sd == 0) { 567 if (config->hd_sd == 0) {
568 vpif_dbg(2, debug, "SD format\n"); 568 vpif_dbg(2, debug, "SD format\n");
569 if (config->stdid & vid_ch->stdid) { 569 if (config->stdid & vid_ch->stdid) {
@@ -1035,6 +1035,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
1035 q->ops = &video_qops; 1035 q->ops = &video_qops;
1036 q->mem_ops = &vb2_dma_contig_memops; 1036 q->mem_ops = &vb2_dma_contig_memops;
1037 q->buf_struct_size = sizeof(struct vpif_cap_buffer); 1037 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1038 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1038 1039
1039 ret = vb2_queue_init(q); 1040 ret = vb2_queue_init(q);
1040 if (ret) { 1041 if (ret) {
@@ -1394,7 +1395,7 @@ static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
1394 * @priv: file handle 1395 * @priv: file handle
1395 * @std_id: ptr to std id 1396 * @std_id: ptr to std id
1396 */ 1397 */
1397static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id) 1398static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
1398{ 1399{
1399 struct vpif_fh *fh = priv; 1400 struct vpif_fh *fh = priv;
1400 struct channel_obj *ch = fh->channel; 1401 struct channel_obj *ch = fh->channel;
@@ -1423,7 +1424,7 @@ static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
1423 fh->initialized = 1; 1424 fh->initialized = 1;
1424 1425
1425 /* Call encoder subdevice function to set the standard */ 1426 /* Call encoder subdevice function to set the standard */
1426 ch->video.stdid = *std_id; 1427 ch->video.stdid = std_id;
1427 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); 1428 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
1428 1429
1429 /* Get the information about the standard */ 1430 /* Get the information about the standard */
@@ -1436,7 +1437,7 @@ static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
1436 vpif_config_format(ch); 1437 vpif_config_format(ch);
1437 1438
1438 /* set standard in the sub device */ 1439 /* set standard in the sub device */
1439 ret = v4l2_subdev_call(ch->sd, core, s_std, *std_id); 1440 ret = v4l2_subdev_call(ch->sd, core, s_std, std_id);
1440 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { 1441 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
1441 vpif_dbg(1, debug, "Failed to set standard for sub devices\n"); 1442 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
1442 return ret; 1443 return ret;
@@ -1923,7 +1924,8 @@ static int vpif_dbg_g_register(struct file *file, void *priv,
1923 * Returns zero or -EINVAL if write operations fails. 1924 * Returns zero or -EINVAL if write operations fails.
1924 */ 1925 */
1925static int vpif_dbg_s_register(struct file *file, void *priv, 1926static int vpif_dbg_s_register(struct file *file, void *priv,
1926 struct v4l2_dbg_register *reg){ 1927 const struct v4l2_dbg_register *reg)
1928{
1927 struct vpif_fh *fh = priv; 1929 struct vpif_fh *fh = priv;
1928 struct channel_obj *ch = fh->channel; 1930 struct channel_obj *ch = fh->channel;
1929 1931
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index dd249c96126d..1b3fb5ca2ad4 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -511,7 +511,7 @@ static int vpif_update_std_info(struct channel_obj *ch)
511 int i; 511 int i;
512 512
513 for (i = 0; i < vpif_ch_params_count; i++) { 513 for (i = 0; i < vpif_ch_params_count; i++) {
514 config = &ch_params[i]; 514 config = &vpif_ch_params[i];
515 if (config->hd_sd == 0) { 515 if (config->hd_sd == 0) {
516 vpif_dbg(2, debug, "SD format\n"); 516 vpif_dbg(2, debug, "SD format\n");
517 if (config->stdid & vid_ch->stdid) { 517 if (config->stdid & vid_ch->stdid) {
@@ -1001,6 +1001,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
1001 q->ops = &video_qops; 1001 q->ops = &video_qops;
1002 q->mem_ops = &vb2_dma_contig_memops; 1002 q->mem_ops = &vb2_dma_contig_memops;
1003 q->buf_struct_size = sizeof(struct vpif_disp_buffer); 1003 q->buf_struct_size = sizeof(struct vpif_disp_buffer);
1004 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1004 1005
1005 ret = vb2_queue_init(q); 1006 ret = vb2_queue_init(q);
1006 if (ret) { 1007 if (ret) {
@@ -1058,14 +1059,14 @@ static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1058 return vb2_qbuf(&common->buffer_queue, buf); 1059 return vb2_qbuf(&common->buffer_queue, buf);
1059} 1060}
1060 1061
1061static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id) 1062static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
1062{ 1063{
1063 struct vpif_fh *fh = priv; 1064 struct vpif_fh *fh = priv;
1064 struct channel_obj *ch = fh->channel; 1065 struct channel_obj *ch = fh->channel;
1065 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; 1066 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1066 int ret = 0; 1067 int ret = 0;
1067 1068
1068 if (!(*std_id & VPIF_V4L2_STD)) 1069 if (!(std_id & VPIF_V4L2_STD))
1069 return -EINVAL; 1070 return -EINVAL;
1070 1071
1071 if (common->started) { 1072 if (common->started) {
@@ -1074,7 +1075,7 @@ static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
1074 } 1075 }
1075 1076
1076 /* Call encoder subdevice function to set the standard */ 1077 /* Call encoder subdevice function to set the standard */
1077 ch->video.stdid = *std_id; 1078 ch->video.stdid = std_id;
1078 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); 1079 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
1079 /* Get the information about the standard */ 1080 /* Get the information about the standard */
1080 if (vpif_update_resolution(ch)) 1081 if (vpif_update_resolution(ch))
@@ -1092,14 +1093,14 @@ static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
1092 vpif_config_format(ch); 1093 vpif_config_format(ch);
1093 1094
1094 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video, 1095 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video,
1095 s_std_output, *std_id); 1096 s_std_output, std_id);
1096 if (ret < 0) { 1097 if (ret < 0) {
1097 vpif_err("Failed to set output standard\n"); 1098 vpif_err("Failed to set output standard\n");
1098 return ret; 1099 return ret;
1099 } 1100 }
1100 1101
1101 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, core, 1102 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, core,
1102 s_std, *std_id); 1103 s_std, std_id);
1103 if (ret < 0) 1104 if (ret < 0)
1104 vpif_err("Failed to set standard for sub devices\n"); 1105 vpif_err("Failed to set standard for sub devices\n");
1105 return ret; 1106 return ret;
@@ -1567,7 +1568,8 @@ static int vpif_dbg_g_register(struct file *file, void *priv,
1567 * Returns zero or -EINVAL if write operations fails. 1568 * Returns zero or -EINVAL if write operations fails.
1568 */ 1569 */
1569static int vpif_dbg_s_register(struct file *file, void *priv, 1570static int vpif_dbg_s_register(struct file *file, void *priv,
1570 struct v4l2_dbg_register *reg){ 1571 const struct v4l2_dbg_register *reg)
1572{
1571 struct vpif_fh *fh = priv; 1573 struct vpif_fh *fh = priv;
1572 struct channel_obj *ch = fh->channel; 1574 struct channel_obj *ch = fh->channel;
1573 1575
diff --git a/drivers/media/platform/davinci/vpss.c b/drivers/media/platform/davinci/vpss.c
index a19c552232d1..8a2f01e344ee 100644
--- a/drivers/media/platform/davinci/vpss.c
+++ b/drivers/media/platform/davinci/vpss.c
@@ -17,14 +17,11 @@
17 * 17 *
18 * common vpss system module platform driver for all video drivers. 18 * common vpss system module platform driver for all video drivers.
19 */ 19 */
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/init.h>
23#include <linux/module.h> 20#include <linux/module.h>
24#include <linux/platform_device.h> 21#include <linux/platform_device.h>
25#include <linux/spinlock.h>
26#include <linux/compiler.h>
27#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/pm_runtime.h>
24
28#include <media/davinci/vpss.h> 25#include <media/davinci/vpss.h>
29 26
30MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
@@ -99,7 +96,7 @@ enum vpss_platform_type {
99 96
100/* 97/*
101 * vpss operations. Depends on platform. Not all functions are available 98 * vpss operations. Depends on platform. Not all functions are available
102 * on all platforms. The api, first check if a functio is available before 99 * on all platforms. The api, first check if a function is available before
103 * invoking it. In the probe, the function ptrs are initialized based on 100 * invoking it. In the probe, the function ptrs are initialized based on
104 * vpss name. vpss name can be "dm355_vpss", "dm644x_vpss" etc. 101 * vpss name. vpss name can be "dm355_vpss", "dm644x_vpss" etc.
105 */ 102 */
@@ -114,7 +111,7 @@ struct vpss_hw_ops {
114 void (*set_sync_pol)(struct vpss_sync_pol); 111 void (*set_sync_pol)(struct vpss_sync_pol);
115 /* set the PG_FRAME_SIZE register*/ 112 /* set the PG_FRAME_SIZE register*/
116 void (*set_pg_frame_size)(struct vpss_pg_frame_size); 113 void (*set_pg_frame_size)(struct vpss_pg_frame_size);
117 /* check and clear interrupt if occured */ 114 /* check and clear interrupt if occurred */
118 int (*dma_complete_interrupt)(void); 115 int (*dma_complete_interrupt)(void);
119}; 116};
120 117
@@ -233,7 +230,7 @@ EXPORT_SYMBOL(vpss_clear_wbl_overflow);
233 230
234/* 231/*
235 * dm355_enable_clock - Enable VPSS Clock 232 * dm355_enable_clock - Enable VPSS Clock
236 * @clock_sel: CLock to be enabled/disabled 233 * @clock_sel: Clock to be enabled/disabled
237 * @en: enable/disable flag 234 * @en: enable/disable flag
238 * 235 *
239 * This is called to enable or disable a vpss clock 236 * This is called to enable or disable a vpss clock
@@ -490,6 +487,10 @@ static int vpss_probe(struct platform_device *pdev)
490 } else 487 } else
491 oper_cfg.hw_ops.clear_wbl_overflow = dm644x_clear_wbl_overflow; 488 oper_cfg.hw_ops.clear_wbl_overflow = dm644x_clear_wbl_overflow;
492 489
490 pm_runtime_enable(&pdev->dev);
491
492 pm_runtime_get(&pdev->dev);
493
493 spin_lock_init(&oper_cfg.vpss_lock); 494 spin_lock_init(&oper_cfg.vpss_lock);
494 dev_info(&pdev->dev, "%s vpss probe success\n", platform_name); 495 dev_info(&pdev->dev, "%s vpss probe success\n", platform_name);
495 return 0; 496 return 0;
@@ -507,6 +508,7 @@ static int vpss_remove(struct platform_device *pdev)
507{ 508{
508 struct resource *res; 509 struct resource *res;
509 510
511 pm_runtime_disable(&pdev->dev);
510 iounmap(oper_cfg.vpss_regs_base0); 512 iounmap(oper_cfg.vpss_regs_base0);
511 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 513 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
512 release_mem_region(res->start, resource_size(res)); 514 release_mem_region(res->start, resource_size(res));
@@ -518,10 +520,28 @@ static int vpss_remove(struct platform_device *pdev)
518 return 0; 520 return 0;
519} 521}
520 522
523static int vpss_suspend(struct device *dev)
524{
525 pm_runtime_put(dev);
526 return 0;
527}
528
529static int vpss_resume(struct device *dev)
530{
531 pm_runtime_get(dev);
532 return 0;
533}
534
535static const struct dev_pm_ops vpss_pm_ops = {
536 .suspend = vpss_suspend,
537 .resume = vpss_resume,
538};
539
521static struct platform_driver vpss_driver = { 540static struct platform_driver vpss_driver = {
522 .driver = { 541 .driver = {
523 .name = "vpss", 542 .name = "vpss",
524 .owner = THIS_MODULE, 543 .owner = THIS_MODULE,
544 .pm = &vpss_pm_ops,
525 }, 545 },
526 .remove = vpss_remove, 546 .remove = vpss_remove,
527 .probe = vpss_probe, 547 .probe = vpss_probe,
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 386c0a7a3a52..40a73f7d20da 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -80,6 +80,9 @@ void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state)
80 dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 80 dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
81 81
82 if (src_vb && dst_vb) { 82 if (src_vb && dst_vb) {
83 src_vb->v4l2_buf.timestamp = dst_vb->v4l2_buf.timestamp;
84 src_vb->v4l2_buf.timecode = dst_vb->v4l2_buf.timecode;
85
83 v4l2_m2m_buf_done(src_vb, vb_state); 86 v4l2_m2m_buf_done(src_vb, vb_state);
84 v4l2_m2m_buf_done(dst_vb, vb_state); 87 v4l2_m2m_buf_done(dst_vb, vb_state);
85 88
@@ -584,6 +587,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
584 src_vq->ops = &gsc_m2m_qops; 587 src_vq->ops = &gsc_m2m_qops;
585 src_vq->mem_ops = &vb2_dma_contig_memops; 588 src_vq->mem_ops = &vb2_dma_contig_memops;
586 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 589 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
590 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
587 591
588 ret = vb2_queue_init(src_vq); 592 ret = vb2_queue_init(src_vq);
589 if (ret) 593 if (ret)
@@ -596,6 +600,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
596 dst_vq->ops = &gsc_m2m_qops; 600 dst_vq->ops = &gsc_m2m_qops;
597 dst_vq->mem_ops = &vb2_dma_contig_memops; 601 dst_vq->mem_ops = &vb2_dma_contig_memops;
598 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 602 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
603 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
599 604
600 return vb2_queue_init(dst_vq); 605 return vb2_queue_init(dst_vq);
601} 606}
diff --git a/drivers/media/platform/exynos-gsc/gsc-regs.c b/drivers/media/platform/exynos-gsc/gsc-regs.c
index 6f5b5a486cf3..e22d147a6940 100644
--- a/drivers/media/platform/exynos-gsc/gsc-regs.c
+++ b/drivers/media/platform/exynos-gsc/gsc-regs.c
@@ -12,7 +12,6 @@
12 12
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <mach/map.h>
16 15
17#include "gsc-core.h" 16#include "gsc-core.h"
18 17
diff --git a/drivers/media/platform/s5p-fimc/Kconfig b/drivers/media/platform/exynos4-is/Kconfig
index f997a5203b7c..6ff99b5849f9 100644
--- a/drivers/media/platform/s5p-fimc/Kconfig
+++ b/drivers/media/platform/exynos4-is/Kconfig
@@ -1,21 +1,22 @@
1 1
2config VIDEO_SAMSUNG_S5P_FIMC 2config VIDEO_SAMSUNG_EXYNOS4_IS
3 bool "Samsung S5P/EXYNOS SoC camera interface driver (experimental)" 3 bool "Samsung S5P/EXYNOS4 SoC series Camera Subsystem driver"
4 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && PLAT_S5P && PM_RUNTIME 4 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && PLAT_S5P && PM_RUNTIME
5 help 5 help
6 Say Y here to enable camera host interface devices for 6 Say Y here to enable camera host interface devices for
7 Samsung S5P and EXYNOS SoC series. 7 Samsung S5P and EXYNOS SoC series.
8 8
9if VIDEO_SAMSUNG_S5P_FIMC 9if VIDEO_SAMSUNG_EXYNOS4_IS
10 10
11config VIDEO_S5P_FIMC 11config VIDEO_S5P_FIMC
12 tristate "S5P/EXYNOS4 FIMC/CAMIF camera interface driver" 12 tristate "S5P/EXYNOS4 FIMC/CAMIF camera interface driver"
13 depends on I2C 13 depends on I2C
14 select VIDEOBUF2_DMA_CONTIG 14 select VIDEOBUF2_DMA_CONTIG
15 select V4L2_MEM2MEM_DEV 15 select V4L2_MEM2MEM_DEV
16 select MFD_SYSCON if OF
16 help 17 help
17 This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC camera host 18 This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC camera host
18 interface and video postprocessor (FIMC and FIMC-LITE) devices. 19 interface and video postprocessor (FIMC) devices.
19 20
20 To compile this driver as a module, choose M here: the 21 To compile this driver as a module, choose M here: the
21 module will be called s5p-fimc. 22 module will be called s5p-fimc.
@@ -45,4 +46,16 @@ config VIDEO_EXYNOS_FIMC_LITE
45 module will be called exynos-fimc-lite. 46 module will be called exynos-fimc-lite.
46endif 47endif
47 48
49config VIDEO_EXYNOS4_FIMC_IS
50 tristate "EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver"
51 select VIDEOBUF2_DMA_CONTIG
52 depends on OF
53 select FW_LOADER
54 help
55 This is a V4L2 driver for Samsung EXYNOS4x12 SoC series
56 FIMC-IS (Imaging Subsystem).
57
58 To compile this driver as a module, choose M here: the
59 module will be called exynos4-fimc-is.
60
48endif # VIDEO_SAMSUNG_S5P_FIMC 61endif # VIDEO_SAMSUNG_S5P_FIMC
diff --git a/drivers/media/platform/s5p-fimc/Makefile b/drivers/media/platform/exynos4-is/Makefile
index 46485143e1ca..f25f46377399 100644
--- a/drivers/media/platform/s5p-fimc/Makefile
+++ b/drivers/media/platform/exynos4-is/Makefile
@@ -1,7 +1,10 @@
1s5p-fimc-objs := fimc-core.o fimc-reg.o fimc-m2m.o fimc-capture.o fimc-mdevice.o 1s5p-fimc-objs := fimc-core.o fimc-reg.o fimc-m2m.o fimc-capture.o media-dev.o
2exynos-fimc-lite-objs += fimc-lite-reg.o fimc-lite.o 2exynos-fimc-lite-objs += fimc-lite-reg.o fimc-lite.o
3exynos-fimc-is-objs := fimc-is.o fimc-isp.o fimc-is-sensor.o fimc-is-regs.o
4exynos-fimc-is-objs += fimc-is-param.o fimc-is-errno.o fimc-is-i2c.o
3s5p-csis-objs := mipi-csis.o 5s5p-csis-objs := mipi-csis.o
4 6
5obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS) += s5p-csis.o 7obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS) += s5p-csis.o
6obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += exynos-fimc-lite.o 8obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += exynos-fimc-lite.o
9obj-$(CONFIG_VIDEO_EXYNOS4_FIMC_IS) += exynos-fimc-is.o
7obj-$(CONFIG_VIDEO_S5P_FIMC) += s5p-fimc.o 10obj-$(CONFIG_VIDEO_S5P_FIMC) += s5p-fimc.o
diff --git a/drivers/media/platform/s5p-fimc/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index f553cc2a8ee8..528f41369364 100644
--- a/drivers/media/platform/s5p-fimc/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -27,32 +27,33 @@
27#include <media/videobuf2-core.h> 27#include <media/videobuf2-core.h>
28#include <media/videobuf2-dma-contig.h> 28#include <media/videobuf2-dma-contig.h>
29 29
30#include "fimc-mdevice.h" 30#include "media-dev.h"
31#include "fimc-core.h" 31#include "fimc-core.h"
32#include "fimc-reg.h" 32#include "fimc-reg.h"
33 33
34static int fimc_capture_hw_init(struct fimc_dev *fimc) 34static int fimc_capture_hw_init(struct fimc_dev *fimc)
35{ 35{
36 struct fimc_source_info *si = &fimc->vid_cap.source_config;
36 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 37 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
37 struct fimc_pipeline *p = &fimc->pipeline; 38 int ret;
38 struct fimc_sensor_info *sensor;
39 unsigned long flags; 39 unsigned long flags;
40 int ret = 0;
41 40
42 if (p->subdevs[IDX_SENSOR] == NULL || ctx == NULL) 41 if (ctx == NULL || ctx->s_frame.fmt == NULL)
43 return -ENXIO;
44 if (ctx->s_frame.fmt == NULL)
45 return -EINVAL; 42 return -EINVAL;
46 43
47 sensor = v4l2_get_subdev_hostdata(p->subdevs[IDX_SENSOR]); 44 if (si->fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) {
45 ret = fimc_hw_camblk_cfg_writeback(fimc);
46 if (ret < 0)
47 return ret;
48 }
48 49
49 spin_lock_irqsave(&fimc->slock, flags); 50 spin_lock_irqsave(&fimc->slock, flags);
50 fimc_prepare_dma_offset(ctx, &ctx->d_frame); 51 fimc_prepare_dma_offset(ctx, &ctx->d_frame);
51 fimc_set_yuv_order(ctx); 52 fimc_set_yuv_order(ctx);
52 53
53 fimc_hw_set_camera_polarity(fimc, &sensor->pdata); 54 fimc_hw_set_camera_polarity(fimc, si);
54 fimc_hw_set_camera_type(fimc, &sensor->pdata); 55 fimc_hw_set_camera_type(fimc, si);
55 fimc_hw_set_camera_source(fimc, &sensor->pdata); 56 fimc_hw_set_camera_source(fimc, si);
56 fimc_hw_set_camera_offset(fimc, &ctx->s_frame); 57 fimc_hw_set_camera_offset(fimc, &ctx->s_frame);
57 58
58 ret = fimc_set_scaler_info(ctx); 59 ret = fimc_set_scaler_info(ctx);
@@ -65,7 +66,7 @@ static int fimc_capture_hw_init(struct fimc_dev *fimc)
65 fimc_hw_set_effect(ctx); 66 fimc_hw_set_effect(ctx);
66 fimc_hw_set_output_path(ctx); 67 fimc_hw_set_output_path(ctx);
67 fimc_hw_set_out_dma(ctx); 68 fimc_hw_set_out_dma(ctx);
68 if (fimc->variant->has_alpha) 69 if (fimc->drv_data->alpha_color)
69 fimc_hw_set_rgb_alpha(ctx); 70 fimc_hw_set_rgb_alpha(ctx);
70 clear_bit(ST_CAPT_APPLY_CFG, &fimc->state); 71 clear_bit(ST_CAPT_APPLY_CFG, &fimc->state);
71 } 72 }
@@ -168,7 +169,7 @@ static int fimc_capture_config_update(struct fimc_ctx *ctx)
168 fimc_hw_set_effect(ctx); 169 fimc_hw_set_effect(ctx);
169 fimc_prepare_dma_offset(ctx, &ctx->d_frame); 170 fimc_prepare_dma_offset(ctx, &ctx->d_frame);
170 fimc_hw_set_out_dma(ctx); 171 fimc_hw_set_out_dma(ctx);
171 if (fimc->variant->has_alpha) 172 if (fimc->drv_data->alpha_color)
172 fimc_hw_set_rgb_alpha(ctx); 173 fimc_hw_set_rgb_alpha(ctx);
173 174
174 clear_bit(ST_CAPT_APPLY_CFG, &fimc->state); 175 clear_bit(ST_CAPT_APPLY_CFG, &fimc->state);
@@ -286,8 +287,8 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
286 fimc_activate_capture(ctx); 287 fimc_activate_capture(ctx);
287 288
288 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state)) 289 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
289 fimc_pipeline_call(fimc, set_stream, 290 return fimc_pipeline_call(fimc, set_stream,
290 &fimc->pipeline, 1); 291 &fimc->pipeline, 1);
291 } 292 }
292 293
293 return 0; 294 return 0;
@@ -443,35 +444,28 @@ static void buffer_queue(struct vb2_buffer *vb)
443 if (vb2_is_streaming(&vid_cap->vbq) && 444 if (vb2_is_streaming(&vid_cap->vbq) &&
444 vid_cap->active_buf_cnt >= min_bufs && 445 vid_cap->active_buf_cnt >= min_bufs &&
445 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) { 446 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
447 int ret;
448
446 fimc_activate_capture(ctx); 449 fimc_activate_capture(ctx);
447 spin_unlock_irqrestore(&fimc->slock, flags); 450 spin_unlock_irqrestore(&fimc->slock, flags);
448 451
449 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state)) 452 if (test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
450 fimc_pipeline_call(fimc, set_stream, 453 return;
451 &fimc->pipeline, 1); 454
455 ret = fimc_pipeline_call(fimc, set_stream, &fimc->pipeline, 1);
456 if (ret < 0)
457 v4l2_err(&vid_cap->vfd, "stream on failed: %d\n", ret);
452 return; 458 return;
453 } 459 }
454 spin_unlock_irqrestore(&fimc->slock, flags); 460 spin_unlock_irqrestore(&fimc->slock, flags);
455} 461}
456 462
457static void fimc_lock(struct vb2_queue *vq)
458{
459 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
460 mutex_lock(&ctx->fimc_dev->lock);
461}
462
463static void fimc_unlock(struct vb2_queue *vq)
464{
465 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
466 mutex_unlock(&ctx->fimc_dev->lock);
467}
468
469static struct vb2_ops fimc_capture_qops = { 463static struct vb2_ops fimc_capture_qops = {
470 .queue_setup = queue_setup, 464 .queue_setup = queue_setup,
471 .buf_prepare = buffer_prepare, 465 .buf_prepare = buffer_prepare,
472 .buf_queue = buffer_queue, 466 .buf_queue = buffer_queue,
473 .wait_prepare = fimc_unlock, 467 .wait_prepare = vb2_ops_wait_prepare,
474 .wait_finish = fimc_lock, 468 .wait_finish = vb2_ops_wait_finish,
475 .start_streaming = start_streaming, 469 .start_streaming = start_streaming,
476 .stop_streaming = stop_streaming, 470 .stop_streaming = stop_streaming,
477}; 471};
@@ -530,7 +524,7 @@ static int fimc_capture_open(struct file *file)
530 goto unlock; 524 goto unlock;
531 } 525 }
532 526
533 if (++fimc->vid_cap.refcnt == 1) { 527 if (v4l2_fh_is_singular_file(file)) {
534 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline, 528 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline,
535 &fimc->vid_cap.vfd.entity, true); 529 &fimc->vid_cap.vfd.entity, true);
536 530
@@ -543,8 +537,9 @@ static int fimc_capture_open(struct file *file)
543 if (ret < 0) { 537 if (ret < 0) {
544 clear_bit(ST_CAPT_BUSY, &fimc->state); 538 clear_bit(ST_CAPT_BUSY, &fimc->state);
545 pm_runtime_put_sync(&fimc->pdev->dev); 539 pm_runtime_put_sync(&fimc->pdev->dev);
546 fimc->vid_cap.refcnt--;
547 v4l2_fh_release(file); 540 v4l2_fh_release(file);
541 } else {
542 fimc->vid_cap.refcnt++;
548 } 543 }
549 } 544 }
550unlock: 545unlock:
@@ -553,59 +548,34 @@ unlock:
553 return ret; 548 return ret;
554} 549}
555 550
556static int fimc_capture_close(struct file *file) 551static int fimc_capture_release(struct file *file)
557{ 552{
558 struct fimc_dev *fimc = video_drvdata(file); 553 struct fimc_dev *fimc = video_drvdata(file);
554 struct fimc_vid_cap *vc = &fimc->vid_cap;
559 int ret; 555 int ret;
560 556
561 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); 557 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
562 558
563 mutex_lock(&fimc->lock); 559 mutex_lock(&fimc->lock);
564 560
565 if (--fimc->vid_cap.refcnt == 0) { 561 if (v4l2_fh_is_singular_file(file)) {
562 if (vc->streaming) {
563 media_entity_pipeline_stop(&vc->vfd.entity);
564 vc->streaming = false;
565 }
566 clear_bit(ST_CAPT_BUSY, &fimc->state); 566 clear_bit(ST_CAPT_BUSY, &fimc->state);
567 fimc_stop_capture(fimc, false); 567 fimc_stop_capture(fimc, false);
568 fimc_pipeline_call(fimc, close, &fimc->pipeline); 568 fimc_pipeline_call(fimc, close, &fimc->pipeline);
569 clear_bit(ST_CAPT_SUSPENDED, &fimc->state); 569 clear_bit(ST_CAPT_SUSPENDED, &fimc->state);
570 fimc->vid_cap.refcnt--;
570 } 571 }
571 572
572 pm_runtime_put(&fimc->pdev->dev); 573 pm_runtime_put(&fimc->pdev->dev);
573 574
574 if (fimc->vid_cap.refcnt == 0) { 575 if (v4l2_fh_is_singular_file(file))
575 vb2_queue_release(&fimc->vid_cap.vbq);
576 fimc_ctrls_delete(fimc->vid_cap.ctx); 576 fimc_ctrls_delete(fimc->vid_cap.ctx);
577 }
578
579 ret = v4l2_fh_release(file);
580
581 mutex_unlock(&fimc->lock);
582 return ret;
583}
584
585static unsigned int fimc_capture_poll(struct file *file,
586 struct poll_table_struct *wait)
587{
588 struct fimc_dev *fimc = video_drvdata(file);
589 int ret;
590
591 if (mutex_lock_interruptible(&fimc->lock))
592 return POLL_ERR;
593 577
594 ret = vb2_poll(&fimc->vid_cap.vbq, file, wait); 578 ret = vb2_fop_release(file);
595 mutex_unlock(&fimc->lock);
596
597 return ret;
598}
599
600static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma)
601{
602 struct fimc_dev *fimc = video_drvdata(file);
603 int ret;
604
605 if (mutex_lock_interruptible(&fimc->lock))
606 return -ERESTARTSYS;
607
608 ret = vb2_mmap(&fimc->vid_cap.vbq, vma);
609 mutex_unlock(&fimc->lock); 579 mutex_unlock(&fimc->lock);
610 580
611 return ret; 581 return ret;
@@ -614,10 +584,10 @@ static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma)
614static const struct v4l2_file_operations fimc_capture_fops = { 584static const struct v4l2_file_operations fimc_capture_fops = {
615 .owner = THIS_MODULE, 585 .owner = THIS_MODULE,
616 .open = fimc_capture_open, 586 .open = fimc_capture_open,
617 .release = fimc_capture_close, 587 .release = fimc_capture_release,
618 .poll = fimc_capture_poll, 588 .poll = vb2_fop_poll,
619 .unlocked_ioctl = video_ioctl2, 589 .unlocked_ioctl = video_ioctl2,
620 .mmap = fimc_capture_mmap, 590 .mmap = vb2_fop_mmap,
621}; 591};
622 592
623/* 593/*
@@ -642,18 +612,22 @@ static struct fimc_fmt *fimc_capture_try_format(struct fimc_ctx *ctx,
642 fimc_fmt_is_user_defined(ctx->s_frame.fmt->color)) 612 fimc_fmt_is_user_defined(ctx->s_frame.fmt->color))
643 *code = ctx->s_frame.fmt->mbus_code; 613 *code = ctx->s_frame.fmt->mbus_code;
644 614
645 if (fourcc && *fourcc != V4L2_PIX_FMT_JPEG && pad != FIMC_SD_PAD_SINK) 615 if (fourcc && *fourcc != V4L2_PIX_FMT_JPEG && pad == FIMC_SD_PAD_SOURCE)
646 mask |= FMT_FLAGS_M2M; 616 mask |= FMT_FLAGS_M2M;
647 617
618 if (pad == FIMC_SD_PAD_SINK_FIFO)
619 mask = FMT_FLAGS_WRITEBACK;
620
648 ffmt = fimc_find_format(fourcc, code, mask, 0); 621 ffmt = fimc_find_format(fourcc, code, mask, 0);
649 if (WARN_ON(!ffmt)) 622 if (WARN_ON(!ffmt))
650 return NULL; 623 return NULL;
624
651 if (code) 625 if (code)
652 *code = ffmt->mbus_code; 626 *code = ffmt->mbus_code;
653 if (fourcc) 627 if (fourcc)
654 *fourcc = ffmt->fourcc; 628 *fourcc = ffmt->fourcc;
655 629
656 if (pad == FIMC_SD_PAD_SINK) { 630 if (pad != FIMC_SD_PAD_SOURCE) {
657 max_w = fimc_fmt_is_user_defined(ffmt->color) ? 631 max_w = fimc_fmt_is_user_defined(ffmt->color) ?
658 pl->scaler_dis_w : pl->scaler_en_w; 632 pl->scaler_dis_w : pl->scaler_en_w;
659 /* Apply the camera input interface pixel constraints */ 633 /* Apply the camera input interface pixel constraints */
@@ -768,16 +742,13 @@ static void fimc_capture_try_selection(struct fimc_ctx *ctx,
768/* 742/*
769 * The video node ioctl operations 743 * The video node ioctl operations
770 */ 744 */
771static int fimc_vidioc_querycap_capture(struct file *file, void *priv, 745static int fimc_cap_querycap(struct file *file, void *priv,
772 struct v4l2_capability *cap) 746 struct v4l2_capability *cap)
773{ 747{
774 struct fimc_dev *fimc = video_drvdata(file); 748 struct fimc_dev *fimc = video_drvdata(file);
775 749
776 strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1); 750 __fimc_vidioc_querycap(&fimc->pdev->dev, cap, V4L2_CAP_STREAMING |
777 strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1); 751 V4L2_CAP_VIDEO_CAPTURE_MPLANE);
778 cap->bus_info[0] = 0;
779 cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE_MPLANE;
780
781 return 0; 752 return 0;
782} 753}
783 754
@@ -887,7 +858,7 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
887 tfmt->width = mf->width; 858 tfmt->width = mf->width;
888 tfmt->height = mf->height; 859 tfmt->height = mf->height;
889 ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height, 860 ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height,
890 NULL, &fcc, FIMC_SD_PAD_SINK); 861 NULL, &fcc, FIMC_SD_PAD_SINK_CAM);
891 ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height, 862 ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height,
892 NULL, &fcc, FIMC_SD_PAD_SOURCE); 863 NULL, &fcc, FIMC_SD_PAD_SOURCE);
893 if (ffmt && ffmt->mbus_code) 864 if (ffmt && ffmt->mbus_code)
@@ -974,7 +945,7 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
974 if (fimc_jpeg_fourcc(pix->pixelformat)) { 945 if (fimc_jpeg_fourcc(pix->pixelformat)) {
975 fimc_capture_try_format(ctx, &pix->width, &pix->height, 946 fimc_capture_try_format(ctx, &pix->width, &pix->height,
976 NULL, &pix->pixelformat, 947 NULL, &pix->pixelformat,
977 FIMC_SD_PAD_SINK); 948 FIMC_SD_PAD_SINK_CAM);
978 ctx->s_frame.f_width = pix->width; 949 ctx->s_frame.f_width = pix->width;
979 ctx->s_frame.f_height = pix->height; 950 ctx->s_frame.f_height = pix->height;
980 } 951 }
@@ -1028,7 +999,7 @@ static int __fimc_capture_set_format(struct fimc_dev *fimc,
1028{ 999{
1029 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 1000 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
1030 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp; 1001 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
1031 struct v4l2_mbus_framefmt *mf = &fimc->vid_cap.mf; 1002 struct v4l2_mbus_framefmt *mf = &fimc->vid_cap.ci_fmt;
1032 struct fimc_frame *ff = &ctx->d_frame; 1003 struct fimc_frame *ff = &ctx->d_frame;
1033 struct fimc_fmt *s_fmt = NULL; 1004 struct fimc_fmt *s_fmt = NULL;
1034 int ret, i; 1005 int ret, i;
@@ -1040,7 +1011,7 @@ static int __fimc_capture_set_format(struct fimc_dev *fimc,
1040 if (fimc_jpeg_fourcc(pix->pixelformat)) { 1011 if (fimc_jpeg_fourcc(pix->pixelformat)) {
1041 fimc_capture_try_format(ctx, &pix->width, &pix->height, 1012 fimc_capture_try_format(ctx, &pix->width, &pix->height,
1042 NULL, &pix->pixelformat, 1013 NULL, &pix->pixelformat,
1043 FIMC_SD_PAD_SINK); 1014 FIMC_SD_PAD_SINK_CAM);
1044 ctx->s_frame.f_width = pix->width; 1015 ctx->s_frame.f_width = pix->width;
1045 ctx->s_frame.f_height = pix->height; 1016 ctx->s_frame.f_height = pix->height;
1046 } 1017 }
@@ -1157,44 +1128,51 @@ static int fimc_cap_g_input(struct file *file, void *priv, unsigned int *i)
1157static int fimc_pipeline_validate(struct fimc_dev *fimc) 1128static int fimc_pipeline_validate(struct fimc_dev *fimc)
1158{ 1129{
1159 struct v4l2_subdev_format sink_fmt, src_fmt; 1130 struct v4l2_subdev_format sink_fmt, src_fmt;
1160 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; 1131 struct fimc_vid_cap *vc = &fimc->vid_cap;
1161 struct v4l2_subdev *sd; 1132 struct v4l2_subdev *sd = &vc->subdev;
1162 struct media_pad *pad; 1133 struct media_pad *sink_pad, *src_pad;
1163 int ret; 1134 int i, ret;
1164
1165 /* Start with the video capture node pad */
1166 pad = media_entity_remote_source(&vid_cap->vd_pad);
1167 if (pad == NULL)
1168 return -EPIPE;
1169 /* FIMC.{N} subdevice */
1170 sd = media_entity_to_v4l2_subdev(pad->entity);
1171 1135
1172 while (1) { 1136 while (1) {
1173 /* Retrieve format at the sink pad */ 1137 /*
1174 pad = &sd->entity.pads[0]; 1138 * Find current entity sink pad and any remote sink pad linked
1175 if (!(pad->flags & MEDIA_PAD_FL_SINK)) 1139 * to it. We stop if there is no sink pad in current entity or
1140 * it is not linked to any other remote entity.
1141 */
1142 src_pad = NULL;
1143
1144 for (i = 0; i < sd->entity.num_pads; i++) {
1145 struct media_pad *p = &sd->entity.pads[i];
1146
1147 if (p->flags & MEDIA_PAD_FL_SINK) {
1148 sink_pad = p;
1149 src_pad = media_entity_remote_source(sink_pad);
1150 if (src_pad)
1151 break;
1152 }
1153 }
1154
1155 if (src_pad == NULL ||
1156 media_entity_type(src_pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
1176 break; 1157 break;
1158
1177 /* Don't call FIMC subdev operation to avoid nested locking */ 1159 /* Don't call FIMC subdev operation to avoid nested locking */
1178 if (sd == &fimc->vid_cap.subdev) { 1160 if (sd == &vc->subdev) {
1179 struct fimc_frame *ff = &vid_cap->ctx->s_frame; 1161 struct fimc_frame *ff = &vc->ctx->s_frame;
1180 sink_fmt.format.width = ff->f_width; 1162 sink_fmt.format.width = ff->f_width;
1181 sink_fmt.format.height = ff->f_height; 1163 sink_fmt.format.height = ff->f_height;
1182 sink_fmt.format.code = ff->fmt ? ff->fmt->mbus_code : 0; 1164 sink_fmt.format.code = ff->fmt ? ff->fmt->mbus_code : 0;
1183 } else { 1165 } else {
1184 sink_fmt.pad = pad->index; 1166 sink_fmt.pad = sink_pad->index;
1185 sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 1167 sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1186 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sink_fmt); 1168 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sink_fmt);
1187 if (ret < 0 && ret != -ENOIOCTLCMD) 1169 if (ret < 0 && ret != -ENOIOCTLCMD)
1188 return -EPIPE; 1170 return -EPIPE;
1189 } 1171 }
1190 /* Retrieve format at the source pad */
1191 pad = media_entity_remote_source(pad);
1192 if (pad == NULL ||
1193 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
1194 break;
1195 1172
1196 sd = media_entity_to_v4l2_subdev(pad->entity); 1173 /* Retrieve format at the source pad */
1197 src_fmt.pad = pad->index; 1174 sd = media_entity_to_v4l2_subdev(src_pad->entity);
1175 src_fmt.pad = src_pad->index;
1198 src_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 1176 src_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1199 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &src_fmt); 1177 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &src_fmt);
1200 if (ret < 0 && ret != -ENOIOCTLCMD) 1178 if (ret < 0 && ret != -ENOIOCTLCMD)
@@ -1208,7 +1186,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
1208 if (sd == fimc->pipeline.subdevs[IDX_SENSOR] && 1186 if (sd == fimc->pipeline.subdevs[IDX_SENSOR] &&
1209 fimc_user_defined_mbus_fmt(src_fmt.format.code)) { 1187 fimc_user_defined_mbus_fmt(src_fmt.format.code)) {
1210 struct v4l2_plane_pix_format plane_fmt[FIMC_MAX_PLANES]; 1188 struct v4l2_plane_pix_format plane_fmt[FIMC_MAX_PLANES];
1211 struct fimc_frame *frame = &vid_cap->ctx->d_frame; 1189 struct fimc_frame *frame = &vc->ctx->d_frame;
1212 unsigned int i; 1190 unsigned int i;
1213 1191
1214 ret = fimc_get_sensor_frame_desc(sd, plane_fmt, 1192 ret = fimc_get_sensor_frame_desc(sd, plane_fmt,
@@ -1230,96 +1208,80 @@ static int fimc_cap_streamon(struct file *file, void *priv,
1230{ 1208{
1231 struct fimc_dev *fimc = video_drvdata(file); 1209 struct fimc_dev *fimc = video_drvdata(file);
1232 struct fimc_pipeline *p = &fimc->pipeline; 1210 struct fimc_pipeline *p = &fimc->pipeline;
1233 struct v4l2_subdev *sd = p->subdevs[IDX_SENSOR]; 1211 struct fimc_vid_cap *vc = &fimc->vid_cap;
1212 struct media_entity *entity = &vc->vfd.entity;
1213 struct fimc_source_info *si = NULL;
1214 struct v4l2_subdev *sd;
1234 int ret; 1215 int ret;
1235 1216
1236 if (fimc_capture_active(fimc)) 1217 if (fimc_capture_active(fimc))
1237 return -EBUSY; 1218 return -EBUSY;
1238 1219
1239 ret = media_entity_pipeline_start(&sd->entity, p->m_pipeline); 1220 ret = media_entity_pipeline_start(entity, p->m_pipeline);
1240 if (ret < 0) 1221 if (ret < 0)
1241 return ret; 1222 return ret;
1242 1223
1243 if (fimc->vid_cap.user_subdev_api) { 1224 sd = p->subdevs[IDX_SENSOR];
1225 if (sd)
1226 si = v4l2_get_subdev_hostdata(sd);
1227
1228 if (si == NULL) {
1229 ret = -EPIPE;
1230 goto err_p_stop;
1231 }
1232 /*
1233 * Save configuration data related to currently attached image
1234 * sensor or other data source, e.g. FIMC-IS.
1235 */
1236 vc->source_config = *si;
1237
1238 if (vc->input == GRP_ID_FIMC_IS)
1239 vc->source_config.fimc_bus_type = FIMC_BUS_TYPE_ISP_WRITEBACK;
1240
1241 if (vc->user_subdev_api) {
1244 ret = fimc_pipeline_validate(fimc); 1242 ret = fimc_pipeline_validate(fimc);
1245 if (ret < 0) { 1243 if (ret < 0)
1246 media_entity_pipeline_stop(&sd->entity); 1244 goto err_p_stop;
1247 return ret;
1248 }
1249 } 1245 }
1250 return vb2_streamon(&fimc->vid_cap.vbq, type); 1246
1247 ret = vb2_ioctl_streamon(file, priv, type);
1248 if (!ret) {
1249 vc->streaming = true;
1250 return ret;
1251 }
1252
1253err_p_stop:
1254 media_entity_pipeline_stop(entity);
1255 return ret;
1251} 1256}
1252 1257
1253static int fimc_cap_streamoff(struct file *file, void *priv, 1258static int fimc_cap_streamoff(struct file *file, void *priv,
1254 enum v4l2_buf_type type) 1259 enum v4l2_buf_type type)
1255{ 1260{
1256 struct fimc_dev *fimc = video_drvdata(file); 1261 struct fimc_dev *fimc = video_drvdata(file);
1257 struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR];
1258 int ret; 1262 int ret;
1259 1263
1260 ret = vb2_streamoff(&fimc->vid_cap.vbq, type); 1264 ret = vb2_ioctl_streamoff(file, priv, type);
1261 if (ret == 0) 1265 if (ret < 0)
1262 media_entity_pipeline_stop(&sd->entity); 1266 return ret;
1263 return ret; 1267
1268 media_entity_pipeline_stop(&fimc->vid_cap.vfd.entity);
1269 fimc->vid_cap.streaming = false;
1270 return 0;
1264} 1271}
1265 1272
1266static int fimc_cap_reqbufs(struct file *file, void *priv, 1273static int fimc_cap_reqbufs(struct file *file, void *priv,
1267 struct v4l2_requestbuffers *reqbufs) 1274 struct v4l2_requestbuffers *reqbufs)
1268{ 1275{
1269 struct fimc_dev *fimc = video_drvdata(file); 1276 struct fimc_dev *fimc = video_drvdata(file);
1270 int ret = vb2_reqbufs(&fimc->vid_cap.vbq, reqbufs); 1277 int ret;
1278
1279 ret = vb2_ioctl_reqbufs(file, priv, reqbufs);
1271 1280
1272 if (!ret) 1281 if (!ret)
1273 fimc->vid_cap.reqbufs_count = reqbufs->count; 1282 fimc->vid_cap.reqbufs_count = reqbufs->count;
1274 return ret;
1275}
1276
1277static int fimc_cap_querybuf(struct file *file, void *priv,
1278 struct v4l2_buffer *buf)
1279{
1280 struct fimc_dev *fimc = video_drvdata(file);
1281
1282 return vb2_querybuf(&fimc->vid_cap.vbq, buf);
1283}
1284
1285static int fimc_cap_qbuf(struct file *file, void *priv,
1286 struct v4l2_buffer *buf)
1287{
1288 struct fimc_dev *fimc = video_drvdata(file);
1289
1290 return vb2_qbuf(&fimc->vid_cap.vbq, buf);
1291}
1292
1293static int fimc_cap_expbuf(struct file *file, void *priv,
1294 struct v4l2_exportbuffer *eb)
1295{
1296 struct fimc_dev *fimc = video_drvdata(file);
1297
1298 return vb2_expbuf(&fimc->vid_cap.vbq, eb);
1299}
1300
1301static int fimc_cap_dqbuf(struct file *file, void *priv,
1302 struct v4l2_buffer *buf)
1303{
1304 struct fimc_dev *fimc = video_drvdata(file);
1305
1306 return vb2_dqbuf(&fimc->vid_cap.vbq, buf, file->f_flags & O_NONBLOCK);
1307}
1308
1309static int fimc_cap_create_bufs(struct file *file, void *priv,
1310 struct v4l2_create_buffers *create)
1311{
1312 struct fimc_dev *fimc = video_drvdata(file);
1313 1283
1314 return vb2_create_bufs(&fimc->vid_cap.vbq, create); 1284 return ret;
1315}
1316
1317static int fimc_cap_prepare_buf(struct file *file, void *priv,
1318 struct v4l2_buffer *b)
1319{
1320 struct fimc_dev *fimc = video_drvdata(file);
1321
1322 return vb2_prepare_buf(&fimc->vid_cap.vbq, b);
1323} 1285}
1324 1286
1325static int fimc_cap_g_selection(struct file *file, void *fh, 1287static int fimc_cap_g_selection(struct file *file, void *fh,
@@ -1410,7 +1372,7 @@ static int fimc_cap_s_selection(struct file *file, void *fh,
1410} 1372}
1411 1373
1412static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = { 1374static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
1413 .vidioc_querycap = fimc_vidioc_querycap_capture, 1375 .vidioc_querycap = fimc_cap_querycap,
1414 1376
1415 .vidioc_enum_fmt_vid_cap_mplane = fimc_cap_enum_fmt_mplane, 1377 .vidioc_enum_fmt_vid_cap_mplane = fimc_cap_enum_fmt_mplane,
1416 .vidioc_try_fmt_vid_cap_mplane = fimc_cap_try_fmt_mplane, 1378 .vidioc_try_fmt_vid_cap_mplane = fimc_cap_try_fmt_mplane,
@@ -1418,14 +1380,12 @@ static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
1418 .vidioc_g_fmt_vid_cap_mplane = fimc_cap_g_fmt_mplane, 1380 .vidioc_g_fmt_vid_cap_mplane = fimc_cap_g_fmt_mplane,
1419 1381
1420 .vidioc_reqbufs = fimc_cap_reqbufs, 1382 .vidioc_reqbufs = fimc_cap_reqbufs,
1421 .vidioc_querybuf = fimc_cap_querybuf, 1383 .vidioc_querybuf = vb2_ioctl_querybuf,
1422 1384 .vidioc_qbuf = vb2_ioctl_qbuf,
1423 .vidioc_qbuf = fimc_cap_qbuf, 1385 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1424 .vidioc_dqbuf = fimc_cap_dqbuf, 1386 .vidioc_expbuf = vb2_ioctl_expbuf,
1425 .vidioc_expbuf = fimc_cap_expbuf, 1387 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
1426 1388 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1427 .vidioc_prepare_buf = fimc_cap_prepare_buf,
1428 .vidioc_create_bufs = fimc_cap_create_bufs,
1429 1389
1430 .vidioc_streamon = fimc_cap_streamon, 1390 .vidioc_streamon = fimc_cap_streamon,
1431 .vidioc_streamoff = fimc_cap_streamoff, 1391 .vidioc_streamoff = fimc_cap_streamoff,
@@ -1487,7 +1447,7 @@ static const struct media_entity_operations fimc_sd_media_ops = {
1487void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification, 1447void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
1488 void *arg) 1448 void *arg)
1489{ 1449{
1490 struct fimc_sensor_info *sensor; 1450 struct fimc_source_info *si;
1491 struct fimc_vid_buffer *buf; 1451 struct fimc_vid_buffer *buf;
1492 struct fimc_md *fmd; 1452 struct fimc_md *fmd;
1493 struct fimc_dev *fimc; 1453 struct fimc_dev *fimc;
@@ -1496,11 +1456,12 @@ void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
1496 if (sd == NULL) 1456 if (sd == NULL)
1497 return; 1457 return;
1498 1458
1499 sensor = v4l2_get_subdev_hostdata(sd); 1459 si = v4l2_get_subdev_hostdata(sd);
1500 fmd = entity_to_fimc_mdev(&sd->entity); 1460 fmd = entity_to_fimc_mdev(&sd->entity);
1501 1461
1502 spin_lock_irqsave(&fmd->slock, flags); 1462 spin_lock_irqsave(&fmd->slock, flags);
1503 fimc = sensor ? sensor->host : NULL; 1463
1464 fimc = si ? source_to_sensor_info(si)->host : NULL;
1504 1465
1505 if (fimc && arg && notification == S5P_FIMC_TX_END_NOTIFY && 1466 if (fimc && arg && notification == S5P_FIMC_TX_END_NOTIFY &&
1506 test_bit(ST_CAPT_PEND, &fimc->state)) { 1467 test_bit(ST_CAPT_PEND, &fimc->state)) {
@@ -1537,25 +1498,37 @@ static int fimc_subdev_get_fmt(struct v4l2_subdev *sd,
1537{ 1498{
1538 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); 1499 struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
1539 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 1500 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
1501 struct fimc_frame *ff = &ctx->s_frame;
1540 struct v4l2_mbus_framefmt *mf; 1502 struct v4l2_mbus_framefmt *mf;
1541 struct fimc_frame *ff;
1542 1503
1543 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 1504 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1544 mf = v4l2_subdev_get_try_format(fh, fmt->pad); 1505 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1545 fmt->format = *mf; 1506 fmt->format = *mf;
1546 return 0; 1507 return 0;
1547 } 1508 }
1548 mf = &fmt->format;
1549 mf->colorspace = V4L2_COLORSPACE_JPEG;
1550 ff = fmt->pad == FIMC_SD_PAD_SINK ? &ctx->s_frame : &ctx->d_frame;
1551 1509
1510 mf = &fmt->format;
1552 mutex_lock(&fimc->lock); 1511 mutex_lock(&fimc->lock);
1553 /* The pixel code is same on both input and output pad */ 1512
1554 if (!WARN_ON(ctx->s_frame.fmt == NULL)) 1513 switch (fmt->pad) {
1555 mf->code = ctx->s_frame.fmt->mbus_code; 1514 case FIMC_SD_PAD_SOURCE:
1556 mf->width = ff->f_width; 1515 if (!WARN_ON(ff->fmt == NULL))
1557 mf->height = ff->f_height; 1516 mf->code = ff->fmt->mbus_code;
1517 /* Sink pads crop rectangle size */
1518 mf->width = ff->width;
1519 mf->height = ff->height;
1520 break;
1521 case FIMC_SD_PAD_SINK_FIFO:
1522 *mf = fimc->vid_cap.wb_fmt;
1523 break;
1524 case FIMC_SD_PAD_SINK_CAM:
1525 default:
1526 *mf = fimc->vid_cap.ci_fmt;
1527 break;
1528 }
1529
1558 mutex_unlock(&fimc->lock); 1530 mutex_unlock(&fimc->lock);
1531 mf->colorspace = V4L2_COLORSPACE_JPEG;
1559 1532
1560 return 0; 1533 return 0;
1561} 1534}
@@ -1566,15 +1539,15 @@ static int fimc_subdev_set_fmt(struct v4l2_subdev *sd,
1566{ 1539{
1567 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); 1540 struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
1568 struct v4l2_mbus_framefmt *mf = &fmt->format; 1541 struct v4l2_mbus_framefmt *mf = &fmt->format;
1569 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 1542 struct fimc_vid_cap *vc = &fimc->vid_cap;
1543 struct fimc_ctx *ctx = vc->ctx;
1570 struct fimc_frame *ff; 1544 struct fimc_frame *ff;
1571 struct fimc_fmt *ffmt; 1545 struct fimc_fmt *ffmt;
1572 1546
1573 dbg("pad%d: code: 0x%x, %dx%d", 1547 dbg("pad%d: code: 0x%x, %dx%d",
1574 fmt->pad, mf->code, mf->width, mf->height); 1548 fmt->pad, mf->code, mf->width, mf->height);
1575 1549
1576 if (fmt->pad == FIMC_SD_PAD_SOURCE && 1550 if (fmt->pad == FIMC_SD_PAD_SOURCE && vb2_is_busy(&vc->vbq))
1577 vb2_is_busy(&fimc->vid_cap.vbq))
1578 return -EBUSY; 1551 return -EBUSY;
1579 1552
1580 mutex_lock(&fimc->lock); 1553 mutex_lock(&fimc->lock);
@@ -1596,21 +1569,32 @@ static int fimc_subdev_set_fmt(struct v4l2_subdev *sd,
1596 fimc_alpha_ctrl_update(ctx); 1569 fimc_alpha_ctrl_update(ctx);
1597 1570
1598 fimc_capture_mark_jpeg_xfer(ctx, ffmt->color); 1571 fimc_capture_mark_jpeg_xfer(ctx, ffmt->color);
1599 1572 if (fmt->pad == FIMC_SD_PAD_SOURCE) {
1600 ff = fmt->pad == FIMC_SD_PAD_SINK ? 1573 ff = &ctx->d_frame;
1601 &ctx->s_frame : &ctx->d_frame; 1574 /* Sink pads crop rectangle size */
1575 mf->width = ctx->s_frame.width;
1576 mf->height = ctx->s_frame.height;
1577 } else {
1578 ff = &ctx->s_frame;
1579 }
1602 1580
1603 mutex_lock(&fimc->lock); 1581 mutex_lock(&fimc->lock);
1604 set_frame_bounds(ff, mf->width, mf->height); 1582 set_frame_bounds(ff, mf->width, mf->height);
1605 fimc->vid_cap.mf = *mf; 1583
1584 if (fmt->pad == FIMC_SD_PAD_SINK_FIFO)
1585 vc->wb_fmt = *mf;
1586 else if (fmt->pad == FIMC_SD_PAD_SINK_CAM)
1587 vc->ci_fmt = *mf;
1588
1606 ff->fmt = ffmt; 1589 ff->fmt = ffmt;
1607 1590
1608 /* Reset the crop rectangle if required. */ 1591 /* Reset the crop rectangle if required. */
1609 if (!(fmt->pad == FIMC_SD_PAD_SOURCE && (ctx->state & FIMC_COMPOSE))) 1592 if (!(fmt->pad == FIMC_SD_PAD_SOURCE && (ctx->state & FIMC_COMPOSE)))
1610 set_frame_crop(ff, 0, 0, mf->width, mf->height); 1593 set_frame_crop(ff, 0, 0, mf->width, mf->height);
1611 1594
1612 if (fmt->pad == FIMC_SD_PAD_SINK) 1595 if (fmt->pad != FIMC_SD_PAD_SOURCE)
1613 ctx->state &= ~FIMC_COMPOSE; 1596 ctx->state &= ~FIMC_COMPOSE;
1597
1614 mutex_unlock(&fimc->lock); 1598 mutex_unlock(&fimc->lock);
1615 return 0; 1599 return 0;
1616} 1600}
@@ -1625,7 +1609,7 @@ static int fimc_subdev_get_selection(struct v4l2_subdev *sd,
1625 struct v4l2_rect *r = &sel->r; 1609 struct v4l2_rect *r = &sel->r;
1626 struct v4l2_rect *try_sel; 1610 struct v4l2_rect *try_sel;
1627 1611
1628 if (sel->pad != FIMC_SD_PAD_SINK) 1612 if (sel->pad == FIMC_SD_PAD_SOURCE)
1629 return -EINVAL; 1613 return -EINVAL;
1630 1614
1631 mutex_lock(&fimc->lock); 1615 mutex_lock(&fimc->lock);
@@ -1681,7 +1665,7 @@ static int fimc_subdev_set_selection(struct v4l2_subdev *sd,
1681 struct v4l2_rect *try_sel; 1665 struct v4l2_rect *try_sel;
1682 unsigned long flags; 1666 unsigned long flags;
1683 1667
1684 if (sel->pad != FIMC_SD_PAD_SINK) 1668 if (sel->pad == FIMC_SD_PAD_SOURCE)
1685 return -EINVAL; 1669 return -EINVAL;
1686 1670
1687 mutex_lock(&fimc->lock); 1671 mutex_lock(&fimc->lock);
@@ -1752,9 +1736,9 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
1752 struct v4l2_device *v4l2_dev) 1736 struct v4l2_device *v4l2_dev)
1753{ 1737{
1754 struct video_device *vfd = &fimc->vid_cap.vfd; 1738 struct video_device *vfd = &fimc->vid_cap.vfd;
1755 struct fimc_vid_cap *vid_cap; 1739 struct vb2_queue *q = &fimc->vid_cap.vbq;
1756 struct fimc_ctx *ctx; 1740 struct fimc_ctx *ctx;
1757 struct vb2_queue *q; 1741 struct fimc_vid_cap *vid_cap;
1758 int ret = -ENOMEM; 1742 int ret = -ENOMEM;
1759 1743
1760 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 1744 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -1776,27 +1760,27 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
1776 vfd->v4l2_dev = v4l2_dev; 1760 vfd->v4l2_dev = v4l2_dev;
1777 vfd->minor = -1; 1761 vfd->minor = -1;
1778 vfd->release = video_device_release_empty; 1762 vfd->release = video_device_release_empty;
1763 vfd->queue = q;
1779 vfd->lock = &fimc->lock; 1764 vfd->lock = &fimc->lock;
1780 1765
1781 video_set_drvdata(vfd, fimc); 1766 video_set_drvdata(vfd, fimc);
1782
1783 vid_cap = &fimc->vid_cap; 1767 vid_cap = &fimc->vid_cap;
1784 vid_cap->active_buf_cnt = 0; 1768 vid_cap->active_buf_cnt = 0;
1785 vid_cap->reqbufs_count = 0; 1769 vid_cap->reqbufs_count = 0;
1786 vid_cap->refcnt = 0; 1770 vid_cap->ctx = ctx;
1787 1771
1788 INIT_LIST_HEAD(&vid_cap->pending_buf_q); 1772 INIT_LIST_HEAD(&vid_cap->pending_buf_q);
1789 INIT_LIST_HEAD(&vid_cap->active_buf_q); 1773 INIT_LIST_HEAD(&vid_cap->active_buf_q);
1790 vid_cap->ctx = ctx;
1791 1774
1792 q = &fimc->vid_cap.vbq;
1793 memset(q, 0, sizeof(*q)); 1775 memset(q, 0, sizeof(*q));
1794 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1776 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1795 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 1777 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1796 q->drv_priv = fimc->vid_cap.ctx; 1778 q->drv_priv = ctx;
1797 q->ops = &fimc_capture_qops; 1779 q->ops = &fimc_capture_qops;
1798 q->mem_ops = &vb2_dma_contig_memops; 1780 q->mem_ops = &vb2_dma_contig_memops;
1799 q->buf_struct_size = sizeof(struct fimc_vid_buffer); 1781 q->buf_struct_size = sizeof(struct fimc_vid_buffer);
1782 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1783 q->lock = &fimc->lock;
1800 1784
1801 ret = vb2_queue_init(q); 1785 ret = vb2_queue_init(q);
1802 if (ret) 1786 if (ret)
@@ -1882,10 +1866,11 @@ int fimc_initialize_capture_subdev(struct fimc_dev *fimc)
1882 int ret; 1866 int ret;
1883 1867
1884 v4l2_subdev_init(sd, &fimc_subdev_ops); 1868 v4l2_subdev_init(sd, &fimc_subdev_ops);
1885 sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE; 1869 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1886 snprintf(sd->name, sizeof(sd->name), "FIMC.%d", fimc->pdev->id); 1870 snprintf(sd->name, sizeof(sd->name), "FIMC.%d", fimc->id);
1887 1871
1888 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK; 1872 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK_CAM].flags = MEDIA_PAD_FL_SINK;
1873 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK_FIFO].flags = MEDIA_PAD_FL_SINK;
1889 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; 1874 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1890 ret = media_entity_init(&sd->entity, FIMC_SD_PADS_NUM, 1875 ret = media_entity_init(&sd->entity, FIMC_SD_PADS_NUM,
1891 fimc->vid_cap.sd_pads, 0); 1876 fimc->vid_cap.sd_pads, 0);
diff --git a/drivers/media/platform/s5p-fimc/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c
index 0f513dd19f86..379a5e9d52a7 100644
--- a/drivers/media/platform/s5p-fimc/fimc-core.c
+++ b/drivers/media/platform/exynos4-is/fimc-core.c
@@ -20,7 +20,10 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
22#include <linux/list.h> 22#include <linux/list.h>
23#include <linux/mfd/syscon.h>
23#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/of.h>
26#include <linux/of_device.h>
24#include <linux/slab.h> 27#include <linux/slab.h>
25#include <linux/clk.h> 28#include <linux/clk.h>
26#include <media/v4l2-ioctl.h> 29#include <media/v4l2-ioctl.h>
@@ -29,7 +32,7 @@
29 32
30#include "fimc-core.h" 33#include "fimc-core.h"
31#include "fimc-reg.h" 34#include "fimc-reg.h"
32#include "fimc-mdevice.h" 35#include "media-dev.h"
33 36
34static char *fimc_clocks[MAX_FIMC_CLOCKS] = { 37static char *fimc_clocks[MAX_FIMC_CLOCKS] = {
35 "sclk_fimc", "fimc" 38 "sclk_fimc", "fimc"
@@ -77,6 +80,10 @@ static struct fimc_fmt fimc_formats[] = {
77 .colplanes = 1, 80 .colplanes = 1,
78 .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA, 81 .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
79 }, { 82 }, {
83 .name = "YUV 4:4:4",
84 .mbus_code = V4L2_MBUS_FMT_YUV10_1X30,
85 .flags = FMT_FLAGS_WRITEBACK,
86 }, {
80 .name = "YUV 4:2:2 packed, YCbYCr", 87 .name = "YUV 4:2:2 packed, YCbYCr",
81 .fourcc = V4L2_PIX_FMT_YUYV, 88 .fourcc = V4L2_PIX_FMT_YUYV,
82 .depth = { 16 }, 89 .depth = { 16 },
@@ -206,6 +213,17 @@ struct fimc_fmt *fimc_get_format(unsigned int index)
206 return &fimc_formats[index]; 213 return &fimc_formats[index];
207} 214}
208 215
216void __fimc_vidioc_querycap(struct device *dev, struct v4l2_capability *cap,
217 unsigned int caps)
218{
219 strlcpy(cap->driver, dev->driver->name, sizeof(cap->driver));
220 strlcpy(cap->card, dev->driver->name, sizeof(cap->card));
221 snprintf(cap->bus_info, sizeof(cap->bus_info),
222 "platform:%s", dev_name(dev));
223 cap->device_caps = caps;
224 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
225}
226
209int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh, 227int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
210 int dw, int dh, int rotation) 228 int dw, int dh, int rotation)
211{ 229{
@@ -405,34 +423,34 @@ void fimc_set_yuv_order(struct fimc_ctx *ctx)
405 /* Set order for 1 plane input formats. */ 423 /* Set order for 1 plane input formats. */
406 switch (ctx->s_frame.fmt->color) { 424 switch (ctx->s_frame.fmt->color) {
407 case FIMC_FMT_YCRYCB422: 425 case FIMC_FMT_YCRYCB422:
408 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY; 426 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB;
409 break; 427 break;
410 case FIMC_FMT_CBYCRY422: 428 case FIMC_FMT_CBYCRY422:
411 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB; 429 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY;
412 break; 430 break;
413 case FIMC_FMT_CRYCBY422: 431 case FIMC_FMT_CRYCBY422:
414 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR; 432 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY;
415 break; 433 break;
416 case FIMC_FMT_YCBYCR422: 434 case FIMC_FMT_YCBYCR422:
417 default: 435 default:
418 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY; 436 ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR;
419 break; 437 break;
420 } 438 }
421 dbg("ctx->in_order_1p= %d", ctx->in_order_1p); 439 dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
422 440
423 switch (ctx->d_frame.fmt->color) { 441 switch (ctx->d_frame.fmt->color) {
424 case FIMC_FMT_YCRYCB422: 442 case FIMC_FMT_YCRYCB422:
425 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY; 443 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB;
426 break; 444 break;
427 case FIMC_FMT_CBYCRY422: 445 case FIMC_FMT_CBYCRY422:
428 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB; 446 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY;
429 break; 447 break;
430 case FIMC_FMT_CRYCBY422: 448 case FIMC_FMT_CRYCBY422:
431 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR; 449 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY;
432 break; 450 break;
433 case FIMC_FMT_YCBYCR422: 451 case FIMC_FMT_YCBYCR422:
434 default: 452 default:
435 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY; 453 ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR;
436 break; 454 break;
437 } 455 }
438 dbg("ctx->out_order_1p= %d", ctx->out_order_1p); 456 dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
@@ -440,14 +458,14 @@ void fimc_set_yuv_order(struct fimc_ctx *ctx)
440 458
441void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f) 459void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
442{ 460{
443 const struct fimc_variant *variant = ctx->fimc_dev->variant; 461 bool pix_hoff = ctx->fimc_dev->drv_data->dma_pix_hoff;
444 u32 i, depth = 0; 462 u32 i, depth = 0;
445 463
446 for (i = 0; i < f->fmt->colplanes; i++) 464 for (i = 0; i < f->fmt->colplanes; i++)
447 depth += f->fmt->depth[i]; 465 depth += f->fmt->depth[i];
448 466
449 f->dma_offset.y_h = f->offs_h; 467 f->dma_offset.y_h = f->offs_h;
450 if (!variant->pix_hoff) 468 if (!pix_hoff)
451 f->dma_offset.y_h *= (depth >> 3); 469 f->dma_offset.y_h *= (depth >> 3);
452 470
453 f->dma_offset.y_v = f->offs_v; 471 f->dma_offset.y_v = f->offs_v;
@@ -458,7 +476,7 @@ void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
458 f->dma_offset.cr_h = f->offs_h; 476 f->dma_offset.cr_h = f->offs_h;
459 f->dma_offset.cr_v = f->offs_v; 477 f->dma_offset.cr_v = f->offs_v;
460 478
461 if (!variant->pix_hoff) { 479 if (!pix_hoff) {
462 if (f->fmt->colplanes == 3) { 480 if (f->fmt->colplanes == 3) {
463 f->dma_offset.cb_h >>= 1; 481 f->dma_offset.cb_h >>= 1;
464 f->dma_offset.cr_h >>= 1; 482 f->dma_offset.cr_h >>= 1;
@@ -589,7 +607,6 @@ static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
589 607
590int fimc_ctrls_create(struct fimc_ctx *ctx) 608int fimc_ctrls_create(struct fimc_ctx *ctx)
591{ 609{
592 const struct fimc_variant *variant = ctx->fimc_dev->variant;
593 unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt); 610 unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt);
594 struct fimc_ctrls *ctrls = &ctx->ctrls; 611 struct fimc_ctrls *ctrls = &ctx->ctrls;
595 struct v4l2_ctrl_handler *handler = &ctrls->handler; 612 struct v4l2_ctrl_handler *handler = &ctrls->handler;
@@ -606,7 +623,7 @@ int fimc_ctrls_create(struct fimc_ctx *ctx)
606 ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, 623 ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
607 V4L2_CID_VFLIP, 0, 1, 1, 0); 624 V4L2_CID_VFLIP, 0, 1, 1, 0);
608 625
609 if (variant->has_alpha) 626 if (ctx->fimc_dev->drv_data->alpha_color)
610 ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, 627 ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
611 V4L2_CID_ALPHA_COMPONENT, 628 V4L2_CID_ALPHA_COMPONENT,
612 0, max_alpha, 1, 0); 629 0, max_alpha, 1, 0);
@@ -677,7 +694,7 @@ void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
677 struct fimc_dev *fimc = ctx->fimc_dev; 694 struct fimc_dev *fimc = ctx->fimc_dev;
678 struct v4l2_ctrl *ctrl = ctx->ctrls.alpha; 695 struct v4l2_ctrl *ctrl = ctx->ctrls.alpha;
679 696
680 if (ctrl == NULL || !fimc->variant->has_alpha) 697 if (ctrl == NULL || !fimc->drv_data->alpha_color)
681 return; 698 return;
682 699
683 v4l2_ctrl_lock(ctrl); 700 v4l2_ctrl_lock(ctrl);
@@ -865,43 +882,113 @@ static int fimc_m2m_resume(struct fimc_dev *fimc)
865 return 0; 882 return 0;
866} 883}
867 884
885static const struct of_device_id fimc_of_match[];
886
887static int fimc_parse_dt(struct fimc_dev *fimc, u32 *clk_freq)
888{
889 struct device *dev = &fimc->pdev->dev;
890 struct device_node *node = dev->of_node;
891 const struct of_device_id *of_id;
892 struct fimc_variant *v;
893 struct fimc_pix_limit *lim;
894 u32 args[FIMC_PIX_LIMITS_MAX];
895 int ret;
896
897 if (of_property_read_bool(node, "samsung,lcd-wb"))
898 return -ENODEV;
899
900 v = devm_kzalloc(dev, sizeof(*v) + sizeof(*lim), GFP_KERNEL);
901 if (!v)
902 return -ENOMEM;
903
904 of_id = of_match_node(fimc_of_match, node);
905 if (!of_id)
906 return -EINVAL;
907 fimc->drv_data = of_id->data;
908 ret = of_property_read_u32_array(node, "samsung,pix-limits",
909 args, FIMC_PIX_LIMITS_MAX);
910 if (ret < 0)
911 return ret;
912
913 lim = (struct fimc_pix_limit *)&v[1];
914
915 lim->scaler_en_w = args[0];
916 lim->scaler_dis_w = args[1];
917 lim->out_rot_en_w = args[2];
918 lim->out_rot_dis_w = args[3];
919 v->pix_limit = lim;
920
921 ret = of_property_read_u32_array(node, "samsung,min-pix-sizes",
922 args, 2);
923 v->min_inp_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[0];
924 v->min_out_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[1];
925 ret = of_property_read_u32_array(node, "samsung,min-pix-alignment",
926 args, 2);
927 v->min_vsize_align = ret ? FIMC_DEF_HEIGHT_ALIGN : args[0];
928 v->hor_offs_align = ret ? FIMC_DEF_HOR_OFFS_ALIGN : args[1];
929
930 ret = of_property_read_u32(node, "samsung,rotators", &args[1]);
931 v->has_inp_rot = ret ? 1 : args[1] & 0x01;
932 v->has_out_rot = ret ? 1 : args[1] & 0x10;
933 v->has_mainscaler_ext = of_property_read_bool(node,
934 "samsung,mainscaler-ext");
935
936 v->has_isp_wb = of_property_read_bool(node, "samsung,isp-wb");
937 v->has_cam_if = of_property_read_bool(node, "samsung,cam-if");
938 of_property_read_u32(node, "clock-frequency", clk_freq);
939 fimc->id = of_alias_get_id(node, "fimc");
940
941 fimc->variant = v;
942 return 0;
943}
944
868static int fimc_probe(struct platform_device *pdev) 945static int fimc_probe(struct platform_device *pdev)
869{ 946{
870 const struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev); 947 struct device *dev = &pdev->dev;
871 struct s5p_platform_fimc *pdata; 948 u32 lclk_freq = 0;
872 struct fimc_dev *fimc; 949 struct fimc_dev *fimc;
873 struct resource *res; 950 struct resource *res;
874 int ret = 0; 951 int ret = 0;
875 952
876 if (pdev->id >= drv_data->num_entities) { 953 fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL);
877 dev_err(&pdev->dev, "Invalid platform device id: %d\n",
878 pdev->id);
879 return -EINVAL;
880 }
881
882 fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL);
883 if (!fimc) 954 if (!fimc)
884 return -ENOMEM; 955 return -ENOMEM;
885 956
886 fimc->id = pdev->id;
887
888 fimc->variant = drv_data->variant[fimc->id];
889 fimc->pdev = pdev; 957 fimc->pdev = pdev;
890 pdata = pdev->dev.platform_data; 958
891 fimc->pdata = pdata; 959 if (dev->of_node) {
960 ret = fimc_parse_dt(fimc, &lclk_freq);
961 if (ret < 0)
962 return ret;
963 } else {
964 fimc->drv_data = fimc_get_drvdata(pdev);
965 fimc->id = pdev->id;
966 }
967 if (!fimc->drv_data || fimc->id >= fimc->drv_data->num_entities ||
968 fimc->id < 0) {
969 dev_err(dev, "Invalid driver data or device id (%d)\n",
970 fimc->id);
971 return -EINVAL;
972 }
973 if (!dev->of_node)
974 fimc->variant = fimc->drv_data->variant[fimc->id];
892 975
893 init_waitqueue_head(&fimc->irq_queue); 976 init_waitqueue_head(&fimc->irq_queue);
894 spin_lock_init(&fimc->slock); 977 spin_lock_init(&fimc->slock);
895 mutex_init(&fimc->lock); 978 mutex_init(&fimc->lock);
896 979
980 fimc->sysreg = fimc_get_sysreg_regmap(dev->of_node);
981 if (IS_ERR(fimc->sysreg))
982 return PTR_ERR(fimc->sysreg);
983
897 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 984 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
898 fimc->regs = devm_ioremap_resource(&pdev->dev, res); 985 fimc->regs = devm_ioremap_resource(dev, res);
899 if (IS_ERR(fimc->regs)) 986 if (IS_ERR(fimc->regs))
900 return PTR_ERR(fimc->regs); 987 return PTR_ERR(fimc->regs);
901 988
902 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 989 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
903 if (res == NULL) { 990 if (res == NULL) {
904 dev_err(&pdev->dev, "Failed to get IRQ resource\n"); 991 dev_err(dev, "Failed to get IRQ resource\n");
905 return -ENXIO; 992 return -ENXIO;
906 } 993 }
907 994
@@ -909,7 +996,10 @@ static int fimc_probe(struct platform_device *pdev)
909 if (ret) 996 if (ret)
910 return ret; 997 return ret;
911 998
912 ret = clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency); 999 if (lclk_freq == 0)
1000 lclk_freq = fimc->drv_data->lclk_frequency;
1001
1002 ret = clk_set_rate(fimc->clock[CLK_BUS], lclk_freq);
913 if (ret < 0) 1003 if (ret < 0)
914 return ret; 1004 return ret;
915 1005
@@ -917,10 +1007,10 @@ static int fimc_probe(struct platform_device *pdev)
917 if (ret < 0) 1007 if (ret < 0)
918 return ret; 1008 return ret;
919 1009
920 ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler, 1010 ret = devm_request_irq(dev, res->start, fimc_irq_handler,
921 0, dev_name(&pdev->dev), fimc); 1011 0, dev_name(dev), fimc);
922 if (ret) { 1012 if (ret) {
923 dev_err(&pdev->dev, "failed to install irq (%d)\n", ret); 1013 dev_err(dev, "failed to install irq (%d)\n", ret);
924 goto err_clk; 1014 goto err_clk;
925 } 1015 }
926 1016
@@ -929,23 +1019,23 @@ static int fimc_probe(struct platform_device *pdev)
929 goto err_clk; 1019 goto err_clk;
930 1020
931 platform_set_drvdata(pdev, fimc); 1021 platform_set_drvdata(pdev, fimc);
932 pm_runtime_enable(&pdev->dev); 1022 pm_runtime_enable(dev);
933 ret = pm_runtime_get_sync(&pdev->dev); 1023 ret = pm_runtime_get_sync(dev);
934 if (ret < 0) 1024 if (ret < 0)
935 goto err_sd; 1025 goto err_sd;
936 /* Initialize contiguous memory allocator */ 1026 /* Initialize contiguous memory allocator */
937 fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1027 fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev);
938 if (IS_ERR(fimc->alloc_ctx)) { 1028 if (IS_ERR(fimc->alloc_ctx)) {
939 ret = PTR_ERR(fimc->alloc_ctx); 1029 ret = PTR_ERR(fimc->alloc_ctx);
940 goto err_pm; 1030 goto err_pm;
941 } 1031 }
942 1032
943 dev_dbg(&pdev->dev, "FIMC.%d registered successfully\n", fimc->id); 1033 dev_dbg(dev, "FIMC.%d registered successfully\n", fimc->id);
944 1034
945 pm_runtime_put(&pdev->dev); 1035 pm_runtime_put(dev);
946 return 0; 1036 return 0;
947err_pm: 1037err_pm:
948 pm_runtime_put(&pdev->dev); 1038 pm_runtime_put(dev);
949err_sd: 1039err_sd:
950 fimc_unregister_capture_subdev(fimc); 1040 fimc_unregister_capture_subdev(fimc);
951err_clk: 1041err_clk:
@@ -1048,35 +1138,21 @@ static const struct fimc_pix_limit s5p_pix_limit[4] = {
1048 [0] = { 1138 [0] = {
1049 .scaler_en_w = 3264, 1139 .scaler_en_w = 3264,
1050 .scaler_dis_w = 8192, 1140 .scaler_dis_w = 8192,
1051 .in_rot_en_h = 1920,
1052 .in_rot_dis_w = 8192,
1053 .out_rot_en_w = 1920, 1141 .out_rot_en_w = 1920,
1054 .out_rot_dis_w = 4224, 1142 .out_rot_dis_w = 4224,
1055 }, 1143 },
1056 [1] = { 1144 [1] = {
1057 .scaler_en_w = 4224, 1145 .scaler_en_w = 4224,
1058 .scaler_dis_w = 8192, 1146 .scaler_dis_w = 8192,
1059 .in_rot_en_h = 1920,
1060 .in_rot_dis_w = 8192,
1061 .out_rot_en_w = 1920, 1147 .out_rot_en_w = 1920,
1062 .out_rot_dis_w = 4224, 1148 .out_rot_dis_w = 4224,
1063 }, 1149 },
1064 [2] = { 1150 [2] = {
1065 .scaler_en_w = 1920, 1151 .scaler_en_w = 1920,
1066 .scaler_dis_w = 8192, 1152 .scaler_dis_w = 8192,
1067 .in_rot_en_h = 1280,
1068 .in_rot_dis_w = 8192,
1069 .out_rot_en_w = 1280, 1153 .out_rot_en_w = 1280,
1070 .out_rot_dis_w = 1920, 1154 .out_rot_dis_w = 1920,
1071 }, 1155 },
1072 [3] = {
1073 .scaler_en_w = 1920,
1074 .scaler_dis_w = 8192,
1075 .in_rot_en_h = 1366,
1076 .in_rot_dis_w = 8192,
1077 .out_rot_en_w = 1366,
1078 .out_rot_dis_w = 1920,
1079 },
1080}; 1156};
1081 1157
1082static const struct fimc_variant fimc0_variant_s5p = { 1158static const struct fimc_variant fimc0_variant_s5p = {
@@ -1087,7 +1163,6 @@ static const struct fimc_variant fimc0_variant_s5p = {
1087 .min_out_pixsize = 16, 1163 .min_out_pixsize = 16,
1088 .hor_offs_align = 8, 1164 .hor_offs_align = 8,
1089 .min_vsize_align = 16, 1165 .min_vsize_align = 16,
1090 .out_buf_count = 4,
1091 .pix_limit = &s5p_pix_limit[0], 1166 .pix_limit = &s5p_pix_limit[0],
1092}; 1167};
1093 1168
@@ -1097,12 +1172,10 @@ static const struct fimc_variant fimc2_variant_s5p = {
1097 .min_out_pixsize = 16, 1172 .min_out_pixsize = 16,
1098 .hor_offs_align = 8, 1173 .hor_offs_align = 8,
1099 .min_vsize_align = 16, 1174 .min_vsize_align = 16,
1100 .out_buf_count = 4,
1101 .pix_limit = &s5p_pix_limit[1], 1175 .pix_limit = &s5p_pix_limit[1],
1102}; 1176};
1103 1177
1104static const struct fimc_variant fimc0_variant_s5pv210 = { 1178static const struct fimc_variant fimc0_variant_s5pv210 = {
1105 .pix_hoff = 1,
1106 .has_inp_rot = 1, 1179 .has_inp_rot = 1,
1107 .has_out_rot = 1, 1180 .has_out_rot = 1,
1108 .has_cam_if = 1, 1181 .has_cam_if = 1,
@@ -1110,12 +1183,10 @@ static const struct fimc_variant fimc0_variant_s5pv210 = {
1110 .min_out_pixsize = 16, 1183 .min_out_pixsize = 16,
1111 .hor_offs_align = 8, 1184 .hor_offs_align = 8,
1112 .min_vsize_align = 16, 1185 .min_vsize_align = 16,
1113 .out_buf_count = 4,
1114 .pix_limit = &s5p_pix_limit[1], 1186 .pix_limit = &s5p_pix_limit[1],
1115}; 1187};
1116 1188
1117static const struct fimc_variant fimc1_variant_s5pv210 = { 1189static const struct fimc_variant fimc1_variant_s5pv210 = {
1118 .pix_hoff = 1,
1119 .has_inp_rot = 1, 1190 .has_inp_rot = 1,
1120 .has_out_rot = 1, 1191 .has_out_rot = 1,
1121 .has_cam_if = 1, 1192 .has_cam_if = 1,
@@ -1124,80 +1195,18 @@ static const struct fimc_variant fimc1_variant_s5pv210 = {
1124 .min_out_pixsize = 16, 1195 .min_out_pixsize = 16,
1125 .hor_offs_align = 1, 1196 .hor_offs_align = 1,
1126 .min_vsize_align = 1, 1197 .min_vsize_align = 1,
1127 .out_buf_count = 4,
1128 .pix_limit = &s5p_pix_limit[2], 1198 .pix_limit = &s5p_pix_limit[2],
1129}; 1199};
1130 1200
1131static const struct fimc_variant fimc2_variant_s5pv210 = { 1201static const struct fimc_variant fimc2_variant_s5pv210 = {
1132 .has_cam_if = 1, 1202 .has_cam_if = 1,
1133 .pix_hoff = 1,
1134 .min_inp_pixsize = 16, 1203 .min_inp_pixsize = 16,
1135 .min_out_pixsize = 16, 1204 .min_out_pixsize = 16,
1136 .hor_offs_align = 8, 1205 .hor_offs_align = 8,
1137 .min_vsize_align = 16, 1206 .min_vsize_align = 16,
1138 .out_buf_count = 4,
1139 .pix_limit = &s5p_pix_limit[2], 1207 .pix_limit = &s5p_pix_limit[2],
1140}; 1208};
1141 1209
1142static const struct fimc_variant fimc0_variant_exynos4210 = {
1143 .pix_hoff = 1,
1144 .has_inp_rot = 1,
1145 .has_out_rot = 1,
1146 .has_cam_if = 1,
1147 .has_cistatus2 = 1,
1148 .has_mainscaler_ext = 1,
1149 .has_alpha = 1,
1150 .min_inp_pixsize = 16,
1151 .min_out_pixsize = 16,
1152 .hor_offs_align = 2,
1153 .min_vsize_align = 1,
1154 .out_buf_count = 32,
1155 .pix_limit = &s5p_pix_limit[1],
1156};
1157
1158static const struct fimc_variant fimc3_variant_exynos4210 = {
1159 .pix_hoff = 1,
1160 .has_cistatus2 = 1,
1161 .has_mainscaler_ext = 1,
1162 .has_alpha = 1,
1163 .min_inp_pixsize = 16,
1164 .min_out_pixsize = 16,
1165 .hor_offs_align = 2,
1166 .min_vsize_align = 1,
1167 .out_buf_count = 32,
1168 .pix_limit = &s5p_pix_limit[3],
1169};
1170
1171static const struct fimc_variant fimc0_variant_exynos4x12 = {
1172 .pix_hoff = 1,
1173 .has_inp_rot = 1,
1174 .has_out_rot = 1,
1175 .has_cam_if = 1,
1176 .has_isp_wb = 1,
1177 .has_cistatus2 = 1,
1178 .has_mainscaler_ext = 1,
1179 .has_alpha = 1,
1180 .min_inp_pixsize = 16,
1181 .min_out_pixsize = 16,
1182 .hor_offs_align = 2,
1183 .min_vsize_align = 1,
1184 .out_buf_count = 32,
1185 .pix_limit = &s5p_pix_limit[1],
1186};
1187
1188static const struct fimc_variant fimc3_variant_exynos4x12 = {
1189 .pix_hoff = 1,
1190 .has_cistatus2 = 1,
1191 .has_mainscaler_ext = 1,
1192 .has_alpha = 1,
1193 .min_inp_pixsize = 16,
1194 .min_out_pixsize = 16,
1195 .hor_offs_align = 2,
1196 .min_vsize_align = 1,
1197 .out_buf_count = 32,
1198 .pix_limit = &s5p_pix_limit[3],
1199};
1200
1201/* S5PC100 */ 1210/* S5PC100 */
1202static const struct fimc_drvdata fimc_drvdata_s5p = { 1211static const struct fimc_drvdata fimc_drvdata_s5p = {
1203 .variant = { 1212 .variant = {
@@ -1205,8 +1214,9 @@ static const struct fimc_drvdata fimc_drvdata_s5p = {
1205 [1] = &fimc0_variant_s5p, 1214 [1] = &fimc0_variant_s5p,
1206 [2] = &fimc2_variant_s5p, 1215 [2] = &fimc2_variant_s5p,
1207 }, 1216 },
1208 .num_entities = 3, 1217 .num_entities = 3,
1209 .lclk_frequency = 133000000UL, 1218 .lclk_frequency = 133000000UL,
1219 .out_buf_count = 4,
1210}; 1220};
1211 1221
1212/* S5PV210, S5PC110 */ 1222/* S5PV210, S5PC110 */
@@ -1216,32 +1226,30 @@ static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
1216 [1] = &fimc1_variant_s5pv210, 1226 [1] = &fimc1_variant_s5pv210,
1217 [2] = &fimc2_variant_s5pv210, 1227 [2] = &fimc2_variant_s5pv210,
1218 }, 1228 },
1219 .num_entities = 3, 1229 .num_entities = 3,
1220 .lclk_frequency = 166000000UL, 1230 .lclk_frequency = 166000000UL,
1231 .out_buf_count = 4,
1232 .dma_pix_hoff = 1,
1221}; 1233};
1222 1234
1223/* EXYNOS4210, S5PV310, S5PC210 */ 1235/* EXYNOS4210, S5PV310, S5PC210 */
1224static const struct fimc_drvdata fimc_drvdata_exynos4210 = { 1236static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
1225 .variant = { 1237 .num_entities = 4,
1226 [0] = &fimc0_variant_exynos4210,
1227 [1] = &fimc0_variant_exynos4210,
1228 [2] = &fimc0_variant_exynos4210,
1229 [3] = &fimc3_variant_exynos4210,
1230 },
1231 .num_entities = 4,
1232 .lclk_frequency = 166000000UL, 1238 .lclk_frequency = 166000000UL,
1239 .dma_pix_hoff = 1,
1240 .cistatus2 = 1,
1241 .alpha_color = 1,
1242 .out_buf_count = 32,
1233}; 1243};
1234 1244
1235/* EXYNOS4212, EXYNOS4412 */ 1245/* EXYNOS4212, EXYNOS4412 */
1236static const struct fimc_drvdata fimc_drvdata_exynos4x12 = { 1246static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
1237 .variant = { 1247 .num_entities = 4,
1238 [0] = &fimc0_variant_exynos4x12, 1248 .lclk_frequency = 166000000UL,
1239 [1] = &fimc0_variant_exynos4x12, 1249 .dma_pix_hoff = 1,
1240 [2] = &fimc0_variant_exynos4x12, 1250 .cistatus2 = 1,
1241 [3] = &fimc3_variant_exynos4x12, 1251 .alpha_color = 1,
1242 }, 1252 .out_buf_count = 32,
1243 .num_entities = 4,
1244 .lclk_frequency = 166000000UL,
1245}; 1253};
1246 1254
1247static const struct platform_device_id fimc_driver_ids[] = { 1255static const struct platform_device_id fimc_driver_ids[] = {
@@ -1258,9 +1266,22 @@ static const struct platform_device_id fimc_driver_ids[] = {
1258 .name = "exynos4x12-fimc", 1266 .name = "exynos4x12-fimc",
1259 .driver_data = (unsigned long)&fimc_drvdata_exynos4x12, 1267 .driver_data = (unsigned long)&fimc_drvdata_exynos4x12,
1260 }, 1268 },
1261 {}, 1269 { },
1270};
1271
1272static const struct of_device_id fimc_of_match[] = {
1273 {
1274 .compatible = "samsung,s5pv210-fimc",
1275 .data = &fimc_drvdata_s5pv210,
1276 }, {
1277 .compatible = "samsung,exynos4210-fimc",
1278 .data = &fimc_drvdata_exynos4210,
1279 }, {
1280 .compatible = "samsung,exynos4212-fimc",
1281 .data = &fimc_drvdata_exynos4x12,
1282 },
1283 { /* sentinel */ },
1262}; 1284};
1263MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
1264 1285
1265static const struct dev_pm_ops fimc_pm_ops = { 1286static const struct dev_pm_ops fimc_pm_ops = {
1266 SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume) 1287 SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
@@ -1272,9 +1293,10 @@ static struct platform_driver fimc_driver = {
1272 .remove = fimc_remove, 1293 .remove = fimc_remove,
1273 .id_table = fimc_driver_ids, 1294 .id_table = fimc_driver_ids,
1274 .driver = { 1295 .driver = {
1275 .name = FIMC_MODULE_NAME, 1296 .of_match_table = fimc_of_match,
1276 .owner = THIS_MODULE, 1297 .name = FIMC_DRIVER_NAME,
1277 .pm = &fimc_pm_ops, 1298 .owner = THIS_MODULE,
1299 .pm = &fimc_pm_ops,
1278 } 1300 }
1279}; 1301};
1280 1302
diff --git a/drivers/media/platform/s5p-fimc/fimc-core.h b/drivers/media/platform/exynos4-is/fimc-core.h
index 412d50708f75..539a3f71c16a 100644
--- a/drivers/media/platform/s5p-fimc/fimc-core.h
+++ b/drivers/media/platform/exynos4-is/fimc-core.h
@@ -12,8 +12,10 @@
12/*#define DEBUG*/ 12/*#define DEBUG*/
13 13
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/regmap.h>
15#include <linux/sched.h> 16#include <linux/sched.h>
16#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/mfd/syscon.h>
17#include <linux/types.h> 19#include <linux/types.h>
18#include <linux/videodev2.h> 20#include <linux/videodev2.h>
19#include <linux/io.h> 21#include <linux/io.h>
@@ -33,7 +35,7 @@
33/* Time to wait for next frame VSYNC interrupt while stopping operation. */ 35/* Time to wait for next frame VSYNC interrupt while stopping operation. */
34#define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000) 36#define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000)
35#define MAX_FIMC_CLOCKS 2 37#define MAX_FIMC_CLOCKS 2
36#define FIMC_MODULE_NAME "s5p-fimc" 38#define FIMC_DRIVER_NAME "exynos4-fimc"
37#define FIMC_MAX_DEVS 4 39#define FIMC_MAX_DEVS 4
38#define FIMC_MAX_OUT_BUFS 4 40#define FIMC_MAX_OUT_BUFS 4
39#define SCALER_MAX_HRATIO 64 41#define SCALER_MAX_HRATIO 64
@@ -42,6 +44,10 @@
42#define FIMC_CAMIF_MAX_HEIGHT 0x2000 44#define FIMC_CAMIF_MAX_HEIGHT 0x2000
43#define FIMC_MAX_JPEG_BUF_SIZE (10 * SZ_1M) 45#define FIMC_MAX_JPEG_BUF_SIZE (10 * SZ_1M)
44#define FIMC_MAX_PLANES 3 46#define FIMC_MAX_PLANES 3
47#define FIMC_PIX_LIMITS_MAX 4
48#define FIMC_DEF_MIN_SIZE 16
49#define FIMC_DEF_HEIGHT_ALIGN 2
50#define FIMC_DEF_HOR_OFFS_ALIGN 1
45 51
46/* indices to the clocks array */ 52/* indices to the clocks array */
47enum { 53enum {
@@ -132,36 +138,6 @@ enum fimc_color_fmt {
132#define FIMC_COLOR_RANGE_NARROW (1 << 3) 138#define FIMC_COLOR_RANGE_NARROW (1 << 3)
133 139
134/** 140/**
135 * struct fimc_fmt - the driver's internal color format data
136 * @mbus_code: Media Bus pixel code, -1 if not applicable
137 * @name: format description
138 * @fourcc: the fourcc code for this format, 0 if not applicable
139 * @color: the corresponding fimc_color_fmt
140 * @memplanes: number of physically non-contiguous data planes
141 * @colplanes: number of physically contiguous data planes
142 * @depth: per plane driver's private 'number of bits per pixel'
143 * @mdataplanes: bitmask indicating meta data plane(s), (1 << plane_no)
144 * @flags: flags indicating which operation mode format applies to
145 */
146struct fimc_fmt {
147 enum v4l2_mbus_pixelcode mbus_code;
148 char *name;
149 u32 fourcc;
150 u32 color;
151 u16 memplanes;
152 u16 colplanes;
153 u8 depth[VIDEO_MAX_PLANES];
154 u16 mdataplanes;
155 u16 flags;
156#define FMT_FLAGS_CAM (1 << 0)
157#define FMT_FLAGS_M2M_IN (1 << 1)
158#define FMT_FLAGS_M2M_OUT (1 << 2)
159#define FMT_FLAGS_M2M (1 << 1 | 1 << 2)
160#define FMT_HAS_ALPHA (1 << 3)
161#define FMT_FLAGS_COMPRESSED (1 << 4)
162};
163
164/**
165 * struct fimc_dma_offset - pixel offset information for DMA 141 * struct fimc_dma_offset - pixel offset information for DMA
166 * @y_h: y value horizontal offset 142 * @y_h: y value horizontal offset
167 * @y_v: y value vertical offset 143 * @y_v: y value vertical offset
@@ -299,9 +275,10 @@ struct fimc_m2m_device {
299 int refcnt; 275 int refcnt;
300}; 276};
301 277
302#define FIMC_SD_PAD_SINK 0 278#define FIMC_SD_PAD_SINK_CAM 0
303#define FIMC_SD_PAD_SOURCE 1 279#define FIMC_SD_PAD_SINK_FIFO 1
304#define FIMC_SD_PADS_NUM 2 280#define FIMC_SD_PAD_SOURCE 2
281#define FIMC_SD_PADS_NUM 3
305 282
306/** 283/**
307 * struct fimc_vid_cap - camera capture device information 284 * struct fimc_vid_cap - camera capture device information
@@ -310,7 +287,9 @@ struct fimc_m2m_device {
310 * @subdev: subdev exposing the FIMC processing block 287 * @subdev: subdev exposing the FIMC processing block
311 * @vd_pad: fimc video capture node pad 288 * @vd_pad: fimc video capture node pad
312 * @sd_pads: fimc video processing block pads 289 * @sd_pads: fimc video processing block pads
313 * @mf: media bus format at the FIMC camera input (and the scaler output) pad 290 * @ci_fmt: image format at the FIMC camera input (and the scaler output)
291 * @wb_fmt: image format at the FIMC ISP Writeback input
292 * @source_config: external image source related configuration structure
314 * @pending_buf_q: the pending buffer queue head 293 * @pending_buf_q: the pending buffer queue head
315 * @active_buf_q: the queue head of buffers scheduled in hardware 294 * @active_buf_q: the queue head of buffers scheduled in hardware
316 * @vbq: the capture am video buffer queue 295 * @vbq: the capture am video buffer queue
@@ -329,8 +308,10 @@ struct fimc_vid_cap {
329 struct video_device vfd; 308 struct video_device vfd;
330 struct v4l2_subdev subdev; 309 struct v4l2_subdev subdev;
331 struct media_pad vd_pad; 310 struct media_pad vd_pad;
332 struct v4l2_mbus_framefmt mf;
333 struct media_pad sd_pads[FIMC_SD_PADS_NUM]; 311 struct media_pad sd_pads[FIMC_SD_PADS_NUM];
312 struct v4l2_mbus_framefmt ci_fmt;
313 struct v4l2_mbus_framefmt wb_fmt;
314 struct fimc_source_info source_config;
334 struct list_head pending_buf_q; 315 struct list_head pending_buf_q;
335 struct list_head active_buf_q; 316 struct list_head active_buf_q;
336 struct vb2_queue vbq; 317 struct vb2_queue vbq;
@@ -338,6 +319,7 @@ struct fimc_vid_cap {
338 int buf_index; 319 int buf_index;
339 unsigned int frame_count; 320 unsigned int frame_count;
340 unsigned int reqbufs_count; 321 unsigned int reqbufs_count;
322 bool streaming;
341 int input_index; 323 int input_index;
342 int refcnt; 324 int refcnt;
343 u32 input; 325 u32 input;
@@ -365,10 +347,8 @@ struct fimc_pix_limit {
365 347
366/** 348/**
367 * struct fimc_variant - FIMC device variant information 349 * struct fimc_variant - FIMC device variant information
368 * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
369 * @has_inp_rot: set if has input rotator 350 * @has_inp_rot: set if has input rotator
370 * @has_out_rot: set if has output rotator 351 * @has_out_rot: set if has output rotator
371 * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision
372 * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register 352 * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register
373 * are present in this IP revision 353 * are present in this IP revision
374 * @has_cam_if: set if this instance has a camera input interface 354 * @has_cam_if: set if this instance has a camera input interface
@@ -378,23 +358,18 @@ struct fimc_pix_limit {
378 * @min_out_pixsize: minimum output pixel size 358 * @min_out_pixsize: minimum output pixel size
379 * @hor_offs_align: horizontal pixel offset aligment 359 * @hor_offs_align: horizontal pixel offset aligment
380 * @min_vsize_align: minimum vertical pixel size alignment 360 * @min_vsize_align: minimum vertical pixel size alignment
381 * @out_buf_count: the number of buffers in output DMA sequence
382 */ 361 */
383struct fimc_variant { 362struct fimc_variant {
384 unsigned int pix_hoff:1;
385 unsigned int has_inp_rot:1; 363 unsigned int has_inp_rot:1;
386 unsigned int has_out_rot:1; 364 unsigned int has_out_rot:1;
387 unsigned int has_cistatus2:1;
388 unsigned int has_mainscaler_ext:1; 365 unsigned int has_mainscaler_ext:1;
389 unsigned int has_cam_if:1; 366 unsigned int has_cam_if:1;
390 unsigned int has_isp_wb:1; 367 unsigned int has_isp_wb:1;
391 unsigned int has_alpha:1;
392 const struct fimc_pix_limit *pix_limit; 368 const struct fimc_pix_limit *pix_limit;
393 u16 min_inp_pixsize; 369 u16 min_inp_pixsize;
394 u16 min_out_pixsize; 370 u16 min_out_pixsize;
395 u16 hor_offs_align; 371 u16 hor_offs_align;
396 u16 min_vsize_align; 372 u16 min_vsize_align;
397 u16 out_buf_count;
398}; 373};
399 374
400/** 375/**
@@ -402,11 +377,20 @@ struct fimc_variant {
402 * @variant: variant information for this device 377 * @variant: variant information for this device
403 * @num_entities: number of fimc instances available in a SoC 378 * @num_entities: number of fimc instances available in a SoC
404 * @lclk_frequency: local bus clock frequency 379 * @lclk_frequency: local bus clock frequency
380 * @cistatus2: 1 if the FIMC IPs have CISTATUS2 register
381 * @dma_pix_hoff: the horizontal DMA offset unit: 1 - pixels, 0 - bytes
382 * @alpha_color: 1 if alpha color component is supported
383 * @out_buf_count: maximum number of output DMA buffers supported
405 */ 384 */
406struct fimc_drvdata { 385struct fimc_drvdata {
407 const struct fimc_variant *variant[FIMC_MAX_DEVS]; 386 const struct fimc_variant *variant[FIMC_MAX_DEVS];
408 int num_entities; 387 int num_entities;
409 unsigned long lclk_frequency; 388 unsigned long lclk_frequency;
389 /* Fields common to all FIMC IP instances */
390 u8 cistatus2;
391 u8 dma_pix_hoff;
392 u8 alpha_color;
393 u8 out_buf_count;
410}; 394};
411 395
412#define fimc_get_drvdata(_pdev) \ 396#define fimc_get_drvdata(_pdev) \
@@ -420,6 +404,7 @@ struct fimc_ctx;
420 * @lock: the mutex protecting this data structure 404 * @lock: the mutex protecting this data structure
421 * @pdev: pointer to the FIMC platform device 405 * @pdev: pointer to the FIMC platform device
422 * @pdata: pointer to the device platform data 406 * @pdata: pointer to the device platform data
407 * @sysreg: pointer to the SYSREG regmap
423 * @variant: the IP variant information 408 * @variant: the IP variant information
424 * @id: FIMC device index (0..FIMC_MAX_DEVS) 409 * @id: FIMC device index (0..FIMC_MAX_DEVS)
425 * @clock: clocks required for FIMC operation 410 * @clock: clocks required for FIMC operation
@@ -437,8 +422,10 @@ struct fimc_dev {
437 struct mutex lock; 422 struct mutex lock;
438 struct platform_device *pdev; 423 struct platform_device *pdev;
439 struct s5p_platform_fimc *pdata; 424 struct s5p_platform_fimc *pdata;
425 struct regmap *sysreg;
440 const struct fimc_variant *variant; 426 const struct fimc_variant *variant;
441 u16 id; 427 const struct fimc_drvdata *drv_data;
428 int id;
442 struct clk *clock[MAX_FIMC_CLOCKS]; 429 struct clk *clock[MAX_FIMC_CLOCKS];
443 void __iomem *regs; 430 void __iomem *regs;
444 wait_queue_head_t irq_queue; 431 wait_queue_head_t irq_queue;
@@ -633,6 +620,8 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
633/* fimc-core.c */ 620/* fimc-core.c */
634int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv, 621int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
635 struct v4l2_fmtdesc *f); 622 struct v4l2_fmtdesc *f);
623void __fimc_vidioc_querycap(struct device *dev, struct v4l2_capability *cap,
624 unsigned int caps);
636int fimc_ctrls_create(struct fimc_ctx *ctx); 625int fimc_ctrls_create(struct fimc_ctx *ctx);
637void fimc_ctrls_delete(struct fimc_ctx *ctx); 626void fimc_ctrls_delete(struct fimc_ctx *ctx);
638void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active); 627void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
@@ -660,6 +649,15 @@ void fimc_unregister_m2m_device(struct fimc_dev *fimc);
660int fimc_register_driver(void); 649int fimc_register_driver(void);
661void fimc_unregister_driver(void); 650void fimc_unregister_driver(void);
662 651
652#ifdef CONFIG_MFD_SYSCON
653static inline struct regmap * fimc_get_sysreg_regmap(struct device_node *node)
654{
655 return syscon_regmap_lookup_by_phandle(node, "samsung,sysreg");
656}
657#else
658#define fimc_get_sysreg_regmap(node) (NULL)
659#endif
660
663/* -----------------------------------------------------*/ 661/* -----------------------------------------------------*/
664/* fimc-m2m.c */ 662/* fimc-m2m.c */
665void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state); 663void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state);
diff --git a/drivers/media/platform/exynos4-is/fimc-is-command.h b/drivers/media/platform/exynos4-is/fimc-is-command.h
new file mode 100644
index 000000000000..0d1f52e394b1
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-command.h
@@ -0,0 +1,137 @@
1/*
2 * Samsung Exynos4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * FIMC-IS command set definitions
5 *
6 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
7 *
8 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
9 * Sylwester Nawrocki <s.nawrocki@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#ifndef FIMC_IS_CMD_H_
17#define FIMC_IS_CMD_H_
18
19#define FIMC_IS_COMMAND_VER 110 /* FIMC-IS command set version 1.10 */
20
21/* Enumeration of commands beetween the FIMC-IS and the host processor. */
22
23/* HOST to FIMC-IS */
24#define HIC_PREVIEW_STILL 0x0001
25#define HIC_PREVIEW_VIDEO 0x0002
26#define HIC_CAPTURE_STILL 0x0003
27#define HIC_CAPTURE_VIDEO 0x0004
28#define HIC_STREAM_ON 0x0005
29#define HIC_STREAM_OFF 0x0006
30#define HIC_SET_PARAMETER 0x0007
31#define HIC_GET_PARAMETER 0x0008
32#define HIC_SET_TUNE 0x0009
33#define HIC_GET_STATUS 0x000b
34/* Sensor part */
35#define HIC_OPEN_SENSOR 0x000c
36#define HIC_CLOSE_SENSOR 0x000d
37#define HIC_SIMMIAN_INIT 0x000e
38#define HIC_SIMMIAN_WRITE 0x000f
39#define HIC_SIMMIAN_READ 0x0010
40#define HIC_POWER_DOWN 0x0011
41#define HIC_GET_SET_FILE_ADDR 0x0012
42#define HIC_LOAD_SET_FILE 0x0013
43#define HIC_MSG_CONFIG 0x0014
44#define HIC_MSG_TEST 0x0015
45/* FIMC-IS to HOST */
46#define IHC_GET_SENSOR_NUM 0x1000
47#define IHC_SET_SHOT_MARK 0x1001
48/* parameter1: frame number */
49/* parameter2: confidence level (smile 0~100) */
50/* parameter3: confidence level (blink 0~100) */
51#define IHC_SET_FACE_MARK 0x1002
52/* parameter1: coordinate count */
53/* parameter2: coordinate buffer address */
54#define IHC_FRAME_DONE 0x1003
55/* parameter1: frame start number */
56/* parameter2: frame count */
57#define IHC_AA_DONE 0x1004
58#define IHC_NOT_READY 0x1005
59
60#define IH_REPLY_DONE 0x2000
61#define IH_REPLY_NOT_DONE 0x2001
62
63enum fimc_is_scenario {
64 IS_SC_PREVIEW_STILL,
65 IS_SC_PREVIEW_VIDEO,
66 IS_SC_CAPTURE_STILL,
67 IS_SC_CAPTURE_VIDEO,
68 IS_SC_MAX
69};
70
71enum fimc_is_sub_scenario {
72 IS_SC_SUB_DEFAULT,
73 IS_SC_SUB_PS_VTCALL,
74 IS_SC_SUB_CS_VTCALL,
75 IS_SC_SUB_PV_VTCALL,
76 IS_SC_SUB_CV_VTCALL,
77};
78
79struct is_common_regs {
80 u32 hicmd;
81 u32 hic_sensorid;
82 u32 hic_param[4];
83 u32 reserved1[4];
84
85 u32 ihcmd;
86 u32 ihc_sensorid;
87 u32 ihc_param[4];
88 u32 reserved2[4];
89
90 u32 isp_sensor_id;
91 u32 isp_param[2];
92 u32 reserved3[1];
93
94 u32 scc_sensor_id;
95 u32 scc_param[2];
96 u32 reserved4[1];
97
98 u32 dnr_sensor_id;
99 u32 dnr_param[2];
100 u32 reserved5[1];
101
102 u32 scp_sensor_id;
103 u32 scp_param[2];
104 u32 reserved6[29];
105} __packed;
106
107struct is_mcuctl_reg {
108 u32 mcuctl;
109 u32 bboar;
110
111 u32 intgr0;
112 u32 intcr0;
113 u32 intmr0;
114 u32 intsr0;
115 u32 intmsr0;
116
117 u32 intgr1;
118 u32 intcr1;
119 u32 intmr1;
120 u32 intsr1;
121 u32 intmsr1;
122
123 u32 intcr2;
124 u32 intmr2;
125 u32 intsr2;
126 u32 intmsr2;
127
128 u32 gpoctrl;
129 u32 cpoenctlr;
130 u32 gpictlr;
131
132 u32 reserved[0xd];
133
134 struct is_common_regs common;
135} __packed;
136
137#endif /* FIMC_IS_CMD_H_ */
diff --git a/drivers/media/platform/exynos4-is/fimc-is-errno.c b/drivers/media/platform/exynos4-is/fimc-is-errno.c
new file mode 100644
index 000000000000..e8519e151c1a
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-errno.c
@@ -0,0 +1,272 @@
1/*
2 * Samsung Exynos4 SoC series FIMC-IS slave interface driver
3 *
4 * Error log interface functions
5 *
6 * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
7 *
8 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
9 * Sylwester Nawrocki <s.nawrocki@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include "fimc-is-errno.h"
17
18const char * const fimc_is_param_strerr(unsigned int error)
19{
20 switch (error) {
21 case ERROR_COMMON_CMD:
22 return "ERROR_COMMON_CMD: Invalid Command";
23 case ERROR_COMMON_PARAMETER:
24 return "ERROR_COMMON_PARAMETER: Invalid Parameter";
25 case ERROR_COMMON_SETFILE_LOAD:
26 return "ERROR_COMMON_SETFILE_LOAD: Illegal Setfile Loading";
27 case ERROR_COMMON_SETFILE_ADJUST:
28 return "ERROR_COMMON_SETFILE_ADJUST: Setfile isn't adjusted";
29 case ERROR_COMMON_SETFILE_INDEX:
30 return "ERROR_COMMON_SETFILE_INDEX: Invalid setfile index";
31 case ERROR_COMMON_INPUT_PATH:
32 return "ERROR_COMMON_INPUT_PATH: Input path can be changed in ready state";
33 case ERROR_COMMON_INPUT_INIT:
34 return "ERROR_COMMON_INPUT_INIT: IP can not start if input path is not set";
35 case ERROR_COMMON_OUTPUT_PATH:
36 return "ERROR_COMMON_OUTPUT_PATH: Output path can be changed in ready state (stop)";
37 case ERROR_COMMON_OUTPUT_INIT:
38 return "ERROR_COMMON_OUTPUT_INIT: IP can not start if output path is not set";
39 case ERROR_CONTROL_BYPASS:
40 return "ERROR_CONTROL_BYPASS";
41 case ERROR_OTF_INPUT_FORMAT:
42 return "ERROR_OTF_INPUT_FORMAT: Invalid format (DRC: YUV444, FD: YUV444, 422, 420)";
43 case ERROR_OTF_INPUT_WIDTH:
44 return "ERROR_OTF_INPUT_WIDTH: Invalid width (DRC: 128~8192, FD: 32~8190)";
45 case ERROR_OTF_INPUT_HEIGHT:
46 return "ERROR_OTF_INPUT_HEIGHT: Invalid bit-width (DRC: 8~12bits, FD: 8bit)";
47 case ERROR_OTF_INPUT_BIT_WIDTH:
48 return "ERROR_OTF_INPUT_BIT_WIDTH: Invalid bit-width (DRC: 8~12bits, FD: 8bit)";
49 case ERROR_DMA_INPUT_WIDTH:
50 return "ERROR_DMA_INPUT_WIDTH: Invalid width (DRC: 128~8192, FD: 32~8190)";
51 case ERROR_DMA_INPUT_HEIGHT:
52 return "ERROR_DMA_INPUT_HEIGHT: Invalid height (DRC: 64~8192, FD: 16~8190)";
53 case ERROR_DMA_INPUT_FORMAT:
54 return "ERROR_DMA_INPUT_FORMAT: Invalid format (DRC: YUV444 or YUV422, FD: YUV444,422,420)";
55 case ERROR_DMA_INPUT_BIT_WIDTH:
56 return "ERROR_DMA_INPUT_BIT_WIDTH: Invalid bit-width (DRC: 8~12bits, FD: 8bit)";
57 case ERROR_DMA_INPUT_ORDER:
58 return "ERROR_DMA_INPUT_ORDER: Invalid order(DRC: YYCbCr,YCbYCr,FD:NO,YYCbCr,YCbYCr,CbCr,CrCb)";
59 case ERROR_DMA_INPUT_PLANE:
60 return "ERROR_DMA_INPUT_PLANE: Invalid palne (DRC: 3, FD: 1, 2, 3)";
61 case ERROR_OTF_OUTPUT_WIDTH:
62 return "ERROR_OTF_OUTPUT_WIDTH: Invalid width (DRC: 128~8192)";
63 case ERROR_OTF_OUTPUT_HEIGHT:
64 return "ERROR_OTF_OUTPUT_HEIGHT: Invalid height (DRC: 64~8192)";
65 case ERROR_OTF_OUTPUT_FORMAT:
66 return "ERROR_OTF_OUTPUT_FORMAT: Invalid format (DRC: YUV444)";
67 case ERROR_OTF_OUTPUT_BIT_WIDTH:
68 return "ERROR_OTF_OUTPUT_BIT_WIDTH: Invalid bit-width (DRC: 8~12bits, FD: 8bit)";
69 case ERROR_DMA_OUTPUT_WIDTH:
70 return "ERROR_DMA_OUTPUT_WIDTH";
71 case ERROR_DMA_OUTPUT_HEIGHT:
72 return "ERROR_DMA_OUTPUT_HEIGHT";
73 case ERROR_DMA_OUTPUT_FORMAT:
74 return "ERROR_DMA_OUTPUT_FORMAT";
75 case ERROR_DMA_OUTPUT_BIT_WIDTH:
76 return "ERROR_DMA_OUTPUT_BIT_WIDTH";
77 case ERROR_DMA_OUTPUT_PLANE:
78 return "ERROR_DMA_OUTPUT_PLANE";
79 case ERROR_DMA_OUTPUT_ORDER:
80 return "ERROR_DMA_OUTPUT_ORDER";
81
82 /* Sensor Error(100~199) */
83 case ERROR_SENSOR_I2C_FAIL:
84 return "ERROR_SENSOR_I2C_FAIL";
85 case ERROR_SENSOR_INVALID_FRAMERATE:
86 return "ERROR_SENSOR_INVALID_FRAMERATE";
87 case ERROR_SENSOR_INVALID_EXPOSURETIME:
88 return "ERROR_SENSOR_INVALID_EXPOSURETIME";
89 case ERROR_SENSOR_INVALID_SIZE:
90 return "ERROR_SENSOR_INVALID_SIZE";
91 case ERROR_SENSOR_INVALID_SETTING:
92 return "ERROR_SENSOR_INVALID_SETTING";
93 case ERROR_SENSOR_ACTURATOR_INIT_FAIL:
94 return "ERROR_SENSOR_ACTURATOR_INIT_FAIL";
95 case ERROR_SENSOR_INVALID_AF_POS:
96 return "ERROR_SENSOR_INVALID_AF_POS";
97 case ERROR_SENSOR_UNSUPPORT_FUNC:
98 return "ERROR_SENSOR_UNSUPPORT_FUNC";
99 case ERROR_SENSOR_UNSUPPORT_PERI:
100 return "ERROR_SENSOR_UNSUPPORT_PERI";
101 case ERROR_SENSOR_UNSUPPORT_AF:
102 return "ERROR_SENSOR_UNSUPPORT_AF";
103
104 /* ISP Error (200~299) */
105 case ERROR_ISP_AF_BUSY:
106 return "ERROR_ISP_AF_BUSY";
107 case ERROR_ISP_AF_INVALID_COMMAND:
108 return "ERROR_ISP_AF_INVALID_COMMAND";
109 case ERROR_ISP_AF_INVALID_MODE:
110 return "ERROR_ISP_AF_INVALID_MODE";
111
112 /* DRC Error (300~399) */
113 /* FD Error (400~499) */
114 case ERROR_FD_CONFIG_MAX_NUMBER_STATE:
115 return "ERROR_FD_CONFIG_MAX_NUMBER_STATE";
116 case ERROR_FD_CONFIG_MAX_NUMBER_INVALID:
117 return "ERROR_FD_CONFIG_MAX_NUMBER_INVALID";
118 case ERROR_FD_CONFIG_YAW_ANGLE_STATE:
119 return "ERROR_FD_CONFIG_YAW_ANGLE_STATE";
120 case ERROR_FD_CONFIG_YAW_ANGLE_INVALID:
121 return "ERROR_FD_CONFIG_YAW_ANGLE_INVALID\n";
122 case ERROR_FD_CONFIG_ROLL_ANGLE_STATE:
123 return "ERROR_FD_CONFIG_ROLL_ANGLE_STATE";
124 case ERROR_FD_CONFIG_ROLL_ANGLE_INVALID:
125 return "ERROR_FD_CONFIG_ROLL_ANGLE_INVALID";
126 case ERROR_FD_CONFIG_SMILE_MODE_INVALID:
127 return "ERROR_FD_CONFIG_SMILE_MODE_INVALID";
128 case ERROR_FD_CONFIG_BLINK_MODE_INVALID:
129 return "ERROR_FD_CONFIG_BLINK_MODE_INVALID";
130 case ERROR_FD_CONFIG_EYES_DETECT_INVALID:
131 return "ERROR_FD_CONFIG_EYES_DETECT_INVALID";
132 case ERROR_FD_CONFIG_MOUTH_DETECT_INVALID:
133 return "ERROR_FD_CONFIG_MOUTH_DETECT_INVALID";
134 case ERROR_FD_CONFIG_ORIENTATION_STATE:
135 return "ERROR_FD_CONFIG_ORIENTATION_STATE";
136 case ERROR_FD_CONFIG_ORIENTATION_INVALID:
137 return "ERROR_FD_CONFIG_ORIENTATION_INVALID";
138 case ERROR_FD_CONFIG_ORIENTATION_VALUE_INVALID:
139 return "ERROR_FD_CONFIG_ORIENTATION_VALUE_INVALID";
140 case ERROR_FD_RESULT:
141 return "ERROR_FD_RESULT";
142 case ERROR_FD_MODE:
143 return "ERROR_FD_MODE";
144 default:
145 return "Unknown";
146 }
147}
148
149const char * const fimc_is_strerr(unsigned int error)
150{
151 error &= ~IS_ERROR_TIME_OUT_FLAG;
152
153 switch (error) {
154 /* General */
155 case IS_ERROR_INVALID_COMMAND:
156 return "IS_ERROR_INVALID_COMMAND";
157 case IS_ERROR_REQUEST_FAIL:
158 return "IS_ERROR_REQUEST_FAIL";
159 case IS_ERROR_INVALID_SCENARIO:
160 return "IS_ERROR_INVALID_SCENARIO";
161 case IS_ERROR_INVALID_SENSORID:
162 return "IS_ERROR_INVALID_SENSORID";
163 case IS_ERROR_INVALID_MODE_CHANGE:
164 return "IS_ERROR_INVALID_MODE_CHANGE";
165 case IS_ERROR_INVALID_MAGIC_NUMBER:
166 return "IS_ERROR_INVALID_MAGIC_NUMBER";
167 case IS_ERROR_INVALID_SETFILE_HDR:
168 return "IS_ERROR_INVALID_SETFILE_HDR";
169 case IS_ERROR_BUSY:
170 return "IS_ERROR_BUSY";
171 case IS_ERROR_SET_PARAMETER:
172 return "IS_ERROR_SET_PARAMETER";
173 case IS_ERROR_INVALID_PATH:
174 return "IS_ERROR_INVALID_PATH";
175 case IS_ERROR_OPEN_SENSOR_FAIL:
176 return "IS_ERROR_OPEN_SENSOR_FAIL";
177 case IS_ERROR_ENTRY_MSG_THREAD_DOWN:
178 return "IS_ERROR_ENTRY_MSG_THREAD_DOWN";
179 case IS_ERROR_ISP_FRAME_END_NOT_DONE:
180 return "IS_ERROR_ISP_FRAME_END_NOT_DONE";
181 case IS_ERROR_DRC_FRAME_END_NOT_DONE:
182 return "IS_ERROR_DRC_FRAME_END_NOT_DONE";
183 case IS_ERROR_SCALERC_FRAME_END_NOT_DONE:
184 return "IS_ERROR_SCALERC_FRAME_END_NOT_DONE";
185 case IS_ERROR_ODC_FRAME_END_NOT_DONE:
186 return "IS_ERROR_ODC_FRAME_END_NOT_DONE";
187 case IS_ERROR_DIS_FRAME_END_NOT_DONE:
188 return "IS_ERROR_DIS_FRAME_END_NOT_DONE";
189 case IS_ERROR_TDNR_FRAME_END_NOT_DONE:
190 return "IS_ERROR_TDNR_FRAME_END_NOT_DONE";
191 case IS_ERROR_SCALERP_FRAME_END_NOT_DONE:
192 return "IS_ERROR_SCALERP_FRAME_END_NOT_DONE";
193 case IS_ERROR_WAIT_STREAM_OFF_NOT_DONE:
194 return "IS_ERROR_WAIT_STREAM_OFF_NOT_DONE";
195 case IS_ERROR_NO_MSG_IS_RECEIVED:
196 return "IS_ERROR_NO_MSG_IS_RECEIVED";
197 case IS_ERROR_SENSOR_MSG_FAIL:
198 return "IS_ERROR_SENSOR_MSG_FAIL";
199 case IS_ERROR_ISP_MSG_FAIL:
200 return "IS_ERROR_ISP_MSG_FAIL";
201 case IS_ERROR_DRC_MSG_FAIL:
202 return "IS_ERROR_DRC_MSG_FAIL";
203 case IS_ERROR_LHFD_MSG_FAIL:
204 return "IS_ERROR_LHFD_MSG_FAIL";
205 case IS_ERROR_UNKNOWN:
206 return "IS_ERROR_UNKNOWN";
207
208 /* Sensor */
209 case IS_ERROR_SENSOR_PWRDN_FAIL:
210 return "IS_ERROR_SENSOR_PWRDN_FAIL";
211
212 /* ISP */
213 case IS_ERROR_ISP_PWRDN_FAIL:
214 return "IS_ERROR_ISP_PWRDN_FAIL";
215 case IS_ERROR_ISP_MULTIPLE_INPUT:
216 return "IS_ERROR_ISP_MULTIPLE_INPUT";
217 case IS_ERROR_ISP_ABSENT_INPUT:
218 return "IS_ERROR_ISP_ABSENT_INPUT";
219 case IS_ERROR_ISP_ABSENT_OUTPUT:
220 return "IS_ERROR_ISP_ABSENT_OUTPUT";
221 case IS_ERROR_ISP_NONADJACENT_OUTPUT:
222 return "IS_ERROR_ISP_NONADJACENT_OUTPUT";
223 case IS_ERROR_ISP_FORMAT_MISMATCH:
224 return "IS_ERROR_ISP_FORMAT_MISMATCH";
225 case IS_ERROR_ISP_WIDTH_MISMATCH:
226 return "IS_ERROR_ISP_WIDTH_MISMATCH";
227 case IS_ERROR_ISP_HEIGHT_MISMATCH:
228 return "IS_ERROR_ISP_HEIGHT_MISMATCH";
229 case IS_ERROR_ISP_BITWIDTH_MISMATCH:
230 return "IS_ERROR_ISP_BITWIDTH_MISMATCH";
231 case IS_ERROR_ISP_FRAME_END_TIME_OUT:
232 return "IS_ERROR_ISP_FRAME_END_TIME_OUT";
233
234 /* DRC */
235 case IS_ERROR_DRC_PWRDN_FAIL:
236 return "IS_ERROR_DRC_PWRDN_FAIL";
237 case IS_ERROR_DRC_MULTIPLE_INPUT:
238 return "IS_ERROR_DRC_MULTIPLE_INPUT";
239 case IS_ERROR_DRC_ABSENT_INPUT:
240 return "IS_ERROR_DRC_ABSENT_INPUT";
241 case IS_ERROR_DRC_NONADJACENT_INPUT:
242 return "IS_ERROR_DRC_NONADJACENT_INPUT";
243 case IS_ERROR_DRC_ABSENT_OUTPUT:
244 return "IS_ERROR_DRC_ABSENT_OUTPUT";
245 case IS_ERROR_DRC_NONADJACENT_OUTPUT:
246 return "IS_ERROR_DRC_NONADJACENT_OUTPUT";
247 case IS_ERROR_DRC_FORMAT_MISMATCH:
248 return "IS_ERROR_DRC_FORMAT_MISMATCH";
249 case IS_ERROR_DRC_WIDTH_MISMATCH:
250 return "IS_ERROR_DRC_WIDTH_MISMATCH";
251 case IS_ERROR_DRC_HEIGHT_MISMATCH:
252 return "IS_ERROR_DRC_HEIGHT_MISMATCH";
253 case IS_ERROR_DRC_BITWIDTH_MISMATCH:
254 return "IS_ERROR_DRC_BITWIDTH_MISMATCH";
255 case IS_ERROR_DRC_FRAME_END_TIME_OUT:
256 return "IS_ERROR_DRC_FRAME_END_TIME_OUT";
257
258 /* FD */
259 case IS_ERROR_FD_PWRDN_FAIL:
260 return "IS_ERROR_FD_PWRDN_FAIL";
261 case IS_ERROR_FD_MULTIPLE_INPUT:
262 return "IS_ERROR_FD_MULTIPLE_INPUT";
263 case IS_ERROR_FD_ABSENT_INPUT:
264 return "IS_ERROR_FD_ABSENT_INPUT";
265 case IS_ERROR_FD_NONADJACENT_INPUT:
266 return "IS_ERROR_FD_NONADJACENT_INPUT";
267 case IS_ERROR_LHFD_FRAME_END_TIME_OUT:
268 return "IS_ERROR_LHFD_FRAME_END_TIME_OUT";
269 default:
270 return "Unknown";
271 }
272}
diff --git a/drivers/media/platform/exynos4-is/fimc-is-errno.h b/drivers/media/platform/exynos4-is/fimc-is-errno.h
new file mode 100644
index 000000000000..3de6f6da6f87
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-errno.h
@@ -0,0 +1,248 @@
1/*
2 * Samsung Exynos4 SoC series FIMC-IS slave interface driver
3 *
4 * FIMC-IS error code definition
5 *
6 * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
7 *
8 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
9 * Sylwester Nawrocki <s.nawrocki@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14*/
15
16#ifndef FIMC_IS_ERR_H_
17#define FIMC_IS_ERR_H_
18
19#define IS_ERROR_VER 011 /* IS ERROR VERSION 0.11 */
20
21enum {
22 IS_ERROR_NONE,
23
24 /* General 1 ~ 99 */
25 IS_ERROR_INVALID_COMMAND,
26 IS_ERROR_REQUEST_FAIL,
27 IS_ERROR_INVALID_SCENARIO,
28 IS_ERROR_INVALID_SENSORID,
29 IS_ERROR_INVALID_MODE_CHANGE,
30 IS_ERROR_INVALID_MAGIC_NUMBER,
31 IS_ERROR_INVALID_SETFILE_HDR,
32 IS_ERROR_BUSY,
33 IS_ERROR_SET_PARAMETER,
34 IS_ERROR_INVALID_PATH,
35 IS_ERROR_OPEN_SENSOR_FAIL,
36 IS_ERROR_ENTRY_MSG_THREAD_DOWN,
37 IS_ERROR_ISP_FRAME_END_NOT_DONE,
38 IS_ERROR_DRC_FRAME_END_NOT_DONE,
39 IS_ERROR_SCALERC_FRAME_END_NOT_DONE,
40 IS_ERROR_ODC_FRAME_END_NOT_DONE,
41 IS_ERROR_DIS_FRAME_END_NOT_DONE,
42 IS_ERROR_TDNR_FRAME_END_NOT_DONE,
43 IS_ERROR_SCALERP_FRAME_END_NOT_DONE,
44 IS_ERROR_WAIT_STREAM_OFF_NOT_DONE,
45 IS_ERROR_NO_MSG_IS_RECEIVED,
46 IS_ERROR_SENSOR_MSG_FAIL,
47 IS_ERROR_ISP_MSG_FAIL,
48 IS_ERROR_DRC_MSG_FAIL,
49 IS_ERROR_SCALERC_MSG_FAIL,
50 IS_ERROR_ODC_MSG_FAIL,
51 IS_ERROR_DIS_MSG_FAIL,
52 IS_ERROR_TDNR_MSG_FAIL,
53 IS_ERROR_SCALERP_MSG_FAIL,
54 IS_ERROR_LHFD_MSG_FAIL,
55 IS_ERROR_LHFD_INTERNAL_STOP,
56
57 /* Sensor 100 ~ 199 */
58 IS_ERROR_SENSOR_PWRDN_FAIL = 100,
59 IS_ERROR_SENSOR_STREAM_ON_FAIL,
60 IS_ERROR_SENSOR_STREAM_OFF_FAIL,
61
62 /* ISP 200 ~ 299 */
63 IS_ERROR_ISP_PWRDN_FAIL = 200,
64 IS_ERROR_ISP_MULTIPLE_INPUT,
65 IS_ERROR_ISP_ABSENT_INPUT,
66 IS_ERROR_ISP_ABSENT_OUTPUT,
67 IS_ERROR_ISP_NONADJACENT_OUTPUT,
68 IS_ERROR_ISP_FORMAT_MISMATCH,
69 IS_ERROR_ISP_WIDTH_MISMATCH,
70 IS_ERROR_ISP_HEIGHT_MISMATCH,
71 IS_ERROR_ISP_BITWIDTH_MISMATCH,
72 IS_ERROR_ISP_FRAME_END_TIME_OUT,
73
74 /* DRC 300 ~ 399 */
75 IS_ERROR_DRC_PWRDN_FAIL = 300,
76 IS_ERROR_DRC_MULTIPLE_INPUT,
77 IS_ERROR_DRC_ABSENT_INPUT,
78 IS_ERROR_DRC_NONADJACENT_INPUT,
79 IS_ERROR_DRC_ABSENT_OUTPUT,
80 IS_ERROR_DRC_NONADJACENT_OUTPUT,
81 IS_ERROR_DRC_FORMAT_MISMATCH,
82 IS_ERROR_DRC_WIDTH_MISMATCH,
83 IS_ERROR_DRC_HEIGHT_MISMATCH,
84 IS_ERROR_DRC_BITWIDTH_MISMATCH,
85 IS_ERROR_DRC_FRAME_END_TIME_OUT,
86
87 /* SCALERC 400 ~ 499 */
88 IS_ERROR_SCALERC_PWRDN_FAIL = 400,
89
90 /* ODC 500 ~ 599 */
91 IS_ERROR_ODC_PWRDN_FAIL = 500,
92
93 /* DIS 600 ~ 699 */
94 IS_ERROR_DIS_PWRDN_FAIL = 600,
95
96 /* TDNR 700 ~ 799 */
97 IS_ERROR_TDNR_PWRDN_FAIL = 700,
98
99 /* SCALERC 800 ~ 899 */
100 IS_ERROR_SCALERP_PWRDN_FAIL = 800,
101
102 /* FD 900 ~ 999 */
103 IS_ERROR_FD_PWRDN_FAIL = 900,
104 IS_ERROR_FD_MULTIPLE_INPUT,
105 IS_ERROR_FD_ABSENT_INPUT,
106 IS_ERROR_FD_NONADJACENT_INPUT,
107 IS_ERROR_LHFD_FRAME_END_TIME_OUT,
108
109 IS_ERROR_UNKNOWN = 1000,
110};
111
112#define IS_ERROR_TIME_OUT_FLAG 0x80000000
113
114/* Set parameter error enum */
115enum fimc_is_error {
116 /* Common error (0~99) */
117 ERROR_COMMON_NONE = 0,
118 ERROR_COMMON_CMD = 1, /* Invalid command */
119 ERROR_COMMON_PARAMETER = 2, /* Invalid parameter */
120 /* setfile is not loaded before adjusting */
121 ERROR_COMMON_SETFILE_LOAD = 3,
122 /* setfile is not Adjusted before runnng. */
123 ERROR_COMMON_SETFILE_ADJUST = 4,
124 /* Index of setfile is not valid (0~MAX_SETFILE_NUM-1) */
125 ERROR_COMMON_SETFILE_INDEX = 5,
126 /* Input path can be changed in ready state(stop) */
127 ERROR_COMMON_INPUT_PATH = 6,
128 /* IP can not start if input path is not set */
129 ERROR_COMMON_INPUT_INIT = 7,
130 /* Output path can be changed in ready state (stop) */
131 ERROR_COMMON_OUTPUT_PATH = 8,
132 /* IP can not start if output path is not set */
133 ERROR_COMMON_OUTPUT_INIT = 9,
134
135 ERROR_CONTROL_NONE = ERROR_COMMON_NONE,
136 ERROR_CONTROL_BYPASS = 11, /* Enable or Disable */
137
138 ERROR_OTF_INPUT_NONE = ERROR_COMMON_NONE,
139 ERROR_OTF_INPUT_CMD = 21,
140 /* invalid format (DRC: YUV444, FD: YUV444, 422, 420) */
141 ERROR_OTF_INPUT_FORMAT = 22,
142 /* invalid width (DRC: 128~8192, FD: 32~8190) */
143 ERROR_OTF_INPUT_WIDTH = 23,
144 /* invalid height (DRC: 64~8192, FD: 16~8190) */
145 ERROR_OTF_INPUT_HEIGHT = 24,
146 /* invalid bit-width (DRC: 8~12bits, FD: 8bit) */
147 ERROR_OTF_INPUT_BIT_WIDTH = 25,
148 /* invalid FrameTime for ISP */
149 ERROR_OTF_INPUT_USER_FRAMETIIME = 26,
150
151 ERROR_DMA_INPUT_NONE = ERROR_COMMON_NONE,
152 /* invalid width (DRC: 128~8192, FD: 32~8190) */
153 ERROR_DMA_INPUT_WIDTH = 31,
154 /* invalid height (DRC: 64~8192, FD: 16~8190) */
155 ERROR_DMA_INPUT_HEIGHT = 32,
156 /* invalid format (DRC: YUV444 or YUV422, FD: YUV444, 422, 420) */
157 ERROR_DMA_INPUT_FORMAT = 33,
158 /* invalid bit-width (DRC: 8~12bit, FD: 8bit) */
159 ERROR_DMA_INPUT_BIT_WIDTH = 34,
160 /* invalid order(DRC: YYCbCrorYCbYCr, FD:NO,YYCbCr,YCbYCr,CbCr,CrCb) */
161 ERROR_DMA_INPUT_ORDER = 35,
162 /* invalid palne (DRC: 3, FD: 1, 2, 3) */
163 ERROR_DMA_INPUT_PLANE = 36,
164
165 ERROR_OTF_OUTPUT_NONE = ERROR_COMMON_NONE,
166 /* invalid width (DRC: 128~8192) */
167 ERROR_OTF_OUTPUT_WIDTH = 41,
168 /* invalid height (DRC: 64~8192) */
169 ERROR_OTF_OUTPUT_HEIGHT = 42,
170 /* invalid format (DRC: YUV444) */
171 ERROR_OTF_OUTPUT_FORMAT = 43,
172 /* invalid bit-width (DRC: 8~12bits) */
173 ERROR_OTF_OUTPUT_BIT_WIDTH = 44,
174
175 ERROR_DMA_OUTPUT_NONE = ERROR_COMMON_NONE,
176 ERROR_DMA_OUTPUT_WIDTH = 51, /* invalid width */
177 ERROR_DMA_OUTPUT_HEIGHT = 52, /* invalid height */
178 ERROR_DMA_OUTPUT_FORMAT = 53, /* invalid format */
179 ERROR_DMA_OUTPUT_BIT_WIDTH = 54, /* invalid bit-width */
180 ERROR_DMA_OUTPUT_PLANE = 55, /* invalid plane */
181 ERROR_DMA_OUTPUT_ORDER = 56, /* invalid order */
182
183 ERROR_GLOBAL_SHOTMODE_NONE = ERROR_COMMON_NONE,
184
185 /* SENSOR Error(100~199) */
186 ERROR_SENSOR_NONE = ERROR_COMMON_NONE,
187 ERROR_SENSOR_I2C_FAIL = 101,
188 ERROR_SENSOR_INVALID_FRAMERATE,
189 ERROR_SENSOR_INVALID_EXPOSURETIME,
190 ERROR_SENSOR_INVALID_SIZE,
191 ERROR_SENSOR_INVALID_SETTING,
192 ERROR_SENSOR_ACTURATOR_INIT_FAIL,
193 ERROR_SENSOR_INVALID_AF_POS,
194 ERROR_SENSOR_UNSUPPORT_FUNC,
195 ERROR_SENSOR_UNSUPPORT_PERI,
196 ERROR_SENSOR_UNSUPPORT_AF,
197
198 /* ISP Error (200~299) */
199 ERROR_ISP_AF_NONE = ERROR_COMMON_NONE,
200 ERROR_ISP_AF_BUSY = 201,
201 ERROR_ISP_AF_INVALID_COMMAND = 202,
202 ERROR_ISP_AF_INVALID_MODE = 203,
203 ERROR_ISP_FLASH_NONE = ERROR_COMMON_NONE,
204 ERROR_ISP_AWB_NONE = ERROR_COMMON_NONE,
205 ERROR_ISP_IMAGE_EFFECT_NONE = ERROR_COMMON_NONE,
206 ERROR_ISP_ISO_NONE = ERROR_COMMON_NONE,
207 ERROR_ISP_ADJUST_NONE = ERROR_COMMON_NONE,
208 ERROR_ISP_METERING_NONE = ERROR_COMMON_NONE,
209 ERROR_ISP_AFC_NONE = ERROR_COMMON_NONE,
210
211 /* DRC Error (300~399) */
212
213 /* FD Error (400~499) */
214 ERROR_FD_NONE = ERROR_COMMON_NONE,
215 /* Invalid max number (1~16) */
216 ERROR_FD_CONFIG_MAX_NUMBER_STATE = 401,
217 ERROR_FD_CONFIG_MAX_NUMBER_INVALID = 402,
218 ERROR_FD_CONFIG_YAW_ANGLE_STATE = 403,
219 ERROR_FD_CONFIG_YAW_ANGLE_INVALID = 404,
220 ERROR_FD_CONFIG_ROLL_ANGLE_STATE = 405,
221 ERROR_FD_CONFIG_ROLL_ANGLE_INVALID = 406,
222 ERROR_FD_CONFIG_SMILE_MODE_INVALID = 407,
223 ERROR_FD_CONFIG_BLINK_MODE_INVALID = 408,
224 ERROR_FD_CONFIG_EYES_DETECT_INVALID = 409,
225 ERROR_FD_CONFIG_MOUTH_DETECT_INVALID = 410,
226 ERROR_FD_CONFIG_ORIENTATION_STATE = 411,
227 ERROR_FD_CONFIG_ORIENTATION_INVALID = 412,
228 ERROR_FD_CONFIG_ORIENTATION_VALUE_INVALID = 413,
229 /* PARAM_FdResultStr can be only applied in ready-state or stream off */
230 ERROR_FD_RESULT = 414,
231 /* PARAM_FdModeStr can be only applied in ready-state or stream off */
232 ERROR_FD_MODE = 415,
233 /* Scaler Error (500 ~ 599) */
234 ERROR_SCALER_NO_NONE = ERROR_COMMON_NONE,
235 ERROR_SCALER_DMA_OUTSEL = 501,
236 ERROR_SCALER_H_RATIO = 502,
237 ERROR_SCALER_V_RATIO = 503,
238
239 ERROR_SCALER_IMAGE_EFFECT = 510,
240
241 ERROR_SCALER_ROTATE = 520,
242 ERROR_SCALER_FLIP = 521,
243};
244
245const char * const fimc_is_strerr(unsigned int error);
246const char * const fimc_is_param_strerr(unsigned int error);
247
248#endif /* FIMC_IS_ERR_H_ */
diff --git a/drivers/media/platform/exynos4-is/fimc-is-i2c.c b/drivers/media/platform/exynos4-is/fimc-is-i2c.c
new file mode 100644
index 000000000000..c397777d7cbb
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-i2c.c
@@ -0,0 +1,126 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Author: Sylwester Nawrocki <s.nawrocki@samsung.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 version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/clk.h>
14#include <linux/module.h>
15#include <linux/of_i2c.h>
16#include <linux/platform_device.h>
17#include <linux/pm_runtime.h>
18#include <linux/slab.h>
19#include "fimc-is-i2c.h"
20
21struct fimc_is_i2c {
22 struct i2c_adapter adapter;
23 struct clk *clock;
24};
25
26/*
27 * An empty algorithm is used as the actual I2C bus controller driver
28 * is implemented in the FIMC-IS subsystem firmware and the host CPU
29 * doesn't access the I2C bus controller.
30 */
31static const struct i2c_algorithm fimc_is_i2c_algorithm;
32
33static int fimc_is_i2c_probe(struct platform_device *pdev)
34{
35 struct device_node *node = pdev->dev.of_node;
36 struct fimc_is_i2c *isp_i2c;
37 struct i2c_adapter *i2c_adap;
38 int ret;
39
40 isp_i2c = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c), GFP_KERNEL);
41 if (!isp_i2c)
42 return -ENOMEM;
43
44 isp_i2c->clock = devm_clk_get(&pdev->dev, "i2c_isp");
45 if (IS_ERR(isp_i2c->clock)) {
46 dev_err(&pdev->dev, "failed to get the clock\n");
47 return PTR_ERR(isp_i2c->clock);
48 }
49
50 i2c_adap = &isp_i2c->adapter;
51 i2c_adap->dev.of_node = node;
52 i2c_adap->dev.parent = &pdev->dev;
53 strlcpy(i2c_adap->name, "exynos4x12-isp-i2c", sizeof(i2c_adap->name));
54 i2c_adap->owner = THIS_MODULE;
55 i2c_adap->algo = &fimc_is_i2c_algorithm;
56 i2c_adap->class = I2C_CLASS_SPD;
57
58 ret = i2c_add_adapter(i2c_adap);
59 if (ret < 0) {
60 dev_err(&pdev->dev, "failed to add I2C bus %s\n",
61 node->full_name);
62 return ret;
63 }
64
65 platform_set_drvdata(pdev, isp_i2c);
66
67 pm_runtime_enable(&pdev->dev);
68 pm_runtime_enable(&i2c_adap->dev);
69
70 of_i2c_register_devices(i2c_adap);
71
72 return 0;
73}
74
75static int fimc_is_i2c_remove(struct platform_device *pdev)
76{
77 struct fimc_is_i2c *isp_i2c = platform_get_drvdata(pdev);
78
79 pm_runtime_disable(&isp_i2c->adapter.dev);
80 pm_runtime_disable(&pdev->dev);
81 i2c_del_adapter(&isp_i2c->adapter);
82
83 return 0;
84}
85
86static int fimc_is_i2c_suspend(struct device *dev)
87{
88 struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);
89 clk_disable_unprepare(isp_i2c->clock);
90 return 0;
91}
92
93static int fimc_is_i2c_resume(struct device *dev)
94{
95 struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);
96 return clk_prepare_enable(isp_i2c->clock);
97}
98
99UNIVERSAL_DEV_PM_OPS(fimc_is_i2c_pm_ops, fimc_is_i2c_suspend,
100 fimc_is_i2c_resume, NULL);
101
102static const struct of_device_id fimc_is_i2c_of_match[] = {
103 { .compatible = FIMC_IS_I2C_COMPATIBLE },
104 { },
105};
106
107static struct platform_driver fimc_is_i2c_driver = {
108 .probe = fimc_is_i2c_probe,
109 .remove = fimc_is_i2c_remove,
110 .driver = {
111 .of_match_table = fimc_is_i2c_of_match,
112 .name = "fimc-isp-i2c",
113 .owner = THIS_MODULE,
114 .pm = &fimc_is_i2c_pm_ops,
115 }
116};
117
118int fimc_is_register_i2c_driver(void)
119{
120 return platform_driver_register(&fimc_is_i2c_driver);
121}
122
123void fimc_is_unregister_i2c_driver(void)
124{
125 platform_driver_unregister(&fimc_is_i2c_driver);
126}
diff --git a/drivers/media/platform/exynos4-is/fimc-is-i2c.h b/drivers/media/platform/exynos4-is/fimc-is-i2c.h
new file mode 100644
index 000000000000..0d38d6bb963b
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-i2c.h
@@ -0,0 +1,15 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#define FIMC_IS_I2C_COMPATIBLE "samsung,exynos4212-i2c-isp"
13
14int fimc_is_register_i2c_driver(void);
15void fimc_is_unregister_i2c_driver(void);
diff --git a/drivers/media/platform/exynos4-is/fimc-is-param.c b/drivers/media/platform/exynos4-is/fimc-is-param.c
new file mode 100644
index 000000000000..53fe2a2b4db3
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-param.c
@@ -0,0 +1,900 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
7 * Sylwester Nawrocki <s.nawrocki@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__
14
15#include <linux/bitops.h>
16#include <linux/bug.h>
17#include <linux/device.h>
18#include <linux/errno.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/types.h>
24#include <linux/videodev2.h>
25
26#include <media/v4l2-device.h>
27#include <media/v4l2-ioctl.h>
28
29#include "fimc-is.h"
30#include "fimc-is-command.h"
31#include "fimc-is-errno.h"
32#include "fimc-is-param.h"
33#include "fimc-is-regs.h"
34#include "fimc-is-sensor.h"
35
36static void __hw_param_copy(void *dst, void *src)
37{
38 memcpy(dst, src, FIMC_IS_PARAM_MAX_SIZE);
39}
40
41void __fimc_is_hw_update_param_global_shotmode(struct fimc_is *is)
42{
43 struct param_global_shotmode *dst, *src;
44
45 dst = &is->is_p_region->parameter.global.shotmode;
46 src = &is->config[is->config_index].global.shotmode;
47 __hw_param_copy(dst, src);
48}
49
50void __fimc_is_hw_update_param_sensor_framerate(struct fimc_is *is)
51{
52 struct param_sensor_framerate *dst, *src;
53
54 dst = &is->is_p_region->parameter.sensor.frame_rate;
55 src = &is->config[is->config_index].sensor.frame_rate;
56 __hw_param_copy(dst, src);
57}
58
59int __fimc_is_hw_update_param(struct fimc_is *is, u32 offset)
60{
61 struct is_param_region *par = &is->is_p_region->parameter;
62 struct chain_config *cfg = &is->config[is->config_index];
63
64 switch (offset) {
65 case PARAM_ISP_CONTROL:
66 __hw_param_copy(&par->isp.control, &cfg->isp.control);
67 break;
68
69 case PARAM_ISP_OTF_INPUT:
70 __hw_param_copy(&par->isp.otf_input, &cfg->isp.otf_input);
71 break;
72
73 case PARAM_ISP_DMA1_INPUT:
74 __hw_param_copy(&par->isp.dma1_input, &cfg->isp.dma1_input);
75 break;
76
77 case PARAM_ISP_DMA2_INPUT:
78 __hw_param_copy(&par->isp.dma2_input, &cfg->isp.dma2_input);
79 break;
80
81 case PARAM_ISP_AA:
82 __hw_param_copy(&par->isp.aa, &cfg->isp.aa);
83 break;
84
85 case PARAM_ISP_FLASH:
86 __hw_param_copy(&par->isp.flash, &cfg->isp.flash);
87 break;
88
89 case PARAM_ISP_AWB:
90 __hw_param_copy(&par->isp.awb, &cfg->isp.awb);
91 break;
92
93 case PARAM_ISP_IMAGE_EFFECT:
94 __hw_param_copy(&par->isp.effect, &cfg->isp.effect);
95 break;
96
97 case PARAM_ISP_ISO:
98 __hw_param_copy(&par->isp.iso, &cfg->isp.iso);
99 break;
100
101 case PARAM_ISP_ADJUST:
102 __hw_param_copy(&par->isp.adjust, &cfg->isp.adjust);
103 break;
104
105 case PARAM_ISP_METERING:
106 __hw_param_copy(&par->isp.metering, &cfg->isp.metering);
107 break;
108
109 case PARAM_ISP_AFC:
110 __hw_param_copy(&par->isp.afc, &cfg->isp.afc);
111 break;
112
113 case PARAM_ISP_OTF_OUTPUT:
114 __hw_param_copy(&par->isp.otf_output, &cfg->isp.otf_output);
115 break;
116
117 case PARAM_ISP_DMA1_OUTPUT:
118 __hw_param_copy(&par->isp.dma1_output, &cfg->isp.dma1_output);
119 break;
120
121 case PARAM_ISP_DMA2_OUTPUT:
122 __hw_param_copy(&par->isp.dma2_output, &cfg->isp.dma2_output);
123 break;
124
125 case PARAM_DRC_CONTROL:
126 __hw_param_copy(&par->drc.control, &cfg->drc.control);
127 break;
128
129 case PARAM_DRC_OTF_INPUT:
130 __hw_param_copy(&par->drc.otf_input, &cfg->drc.otf_input);
131 break;
132
133 case PARAM_DRC_DMA_INPUT:
134 __hw_param_copy(&par->drc.dma_input, &cfg->drc.dma_input);
135 break;
136
137 case PARAM_DRC_OTF_OUTPUT:
138 __hw_param_copy(&par->drc.otf_output, &cfg->drc.otf_output);
139 break;
140
141 case PARAM_FD_CONTROL:
142 __hw_param_copy(&par->fd.control, &cfg->fd.control);
143 break;
144
145 case PARAM_FD_OTF_INPUT:
146 __hw_param_copy(&par->fd.otf_input, &cfg->fd.otf_input);
147 break;
148
149 case PARAM_FD_DMA_INPUT:
150 __hw_param_copy(&par->fd.dma_input, &cfg->fd.dma_input);
151 break;
152
153 case PARAM_FD_CONFIG:
154 __hw_param_copy(&par->fd.config, &cfg->fd.config);
155 break;
156
157 default:
158 return -EINVAL;
159 }
160
161 return 0;
162}
163
164unsigned int __get_pending_param_count(struct fimc_is *is)
165{
166 struct chain_config *config = &is->config[is->config_index];
167 unsigned long flags;
168 unsigned int count;
169
170 spin_lock_irqsave(&is->slock, flags);
171 count = hweight32(config->p_region_index1);
172 count += hweight32(config->p_region_index2);
173 spin_unlock_irqrestore(&is->slock, flags);
174
175 return count;
176}
177
178int __is_hw_update_params(struct fimc_is *is)
179{
180 unsigned long *p_index1, *p_index2;
181 int i, id, ret = 0;
182
183 id = is->config_index;
184 p_index1 = &is->config[id].p_region_index1;
185 p_index2 = &is->config[id].p_region_index2;
186
187 if (test_bit(PARAM_GLOBAL_SHOTMODE, p_index1))
188 __fimc_is_hw_update_param_global_shotmode(is);
189
190 if (test_bit(PARAM_SENSOR_FRAME_RATE, p_index1))
191 __fimc_is_hw_update_param_sensor_framerate(is);
192
193 for (i = PARAM_ISP_CONTROL; i < PARAM_DRC_CONTROL; i++) {
194 if (test_bit(i, p_index1))
195 ret = __fimc_is_hw_update_param(is, i);
196 }
197
198 for (i = PARAM_DRC_CONTROL; i < PARAM_SCALERC_CONTROL; i++) {
199 if (test_bit(i, p_index1))
200 ret = __fimc_is_hw_update_param(is, i);
201 }
202
203 for (i = PARAM_FD_CONTROL; i <= PARAM_FD_CONFIG; i++) {
204 if (test_bit((i - 32), p_index2))
205 ret = __fimc_is_hw_update_param(is, i);
206 }
207
208 return ret;
209}
210
211void __is_get_frame_size(struct fimc_is *is, struct v4l2_mbus_framefmt *mf)
212{
213 struct isp_param *isp;
214
215 isp = &is->config[is->config_index].isp;
216 mf->width = isp->otf_input.width;
217 mf->height = isp->otf_input.height;
218}
219
220void __is_set_frame_size(struct fimc_is *is, struct v4l2_mbus_framefmt *mf)
221{
222 unsigned int index = is->config_index;
223 struct isp_param *isp;
224 struct drc_param *drc;
225 struct fd_param *fd;
226
227 isp = &is->config[index].isp;
228 drc = &is->config[index].drc;
229 fd = &is->config[index].fd;
230
231 /* Update isp size info (OTF only) */
232 isp->otf_input.width = mf->width;
233 isp->otf_input.height = mf->height;
234 isp->otf_output.width = mf->width;
235 isp->otf_output.height = mf->height;
236 /* Update drc size info (OTF only) */
237 drc->otf_input.width = mf->width;
238 drc->otf_input.height = mf->height;
239 drc->otf_output.width = mf->width;
240 drc->otf_output.height = mf->height;
241 /* Update fd size info (OTF only) */
242 fd->otf_input.width = mf->width;
243 fd->otf_input.height = mf->height;
244
245 if (test_bit(PARAM_ISP_OTF_INPUT,
246 &is->config[index].p_region_index1))
247 return;
248
249 /* Update field */
250 fimc_is_set_param_bit(is, PARAM_ISP_OTF_INPUT);
251 fimc_is_set_param_bit(is, PARAM_ISP_OTF_OUTPUT);
252 fimc_is_set_param_bit(is, PARAM_DRC_OTF_INPUT);
253 fimc_is_set_param_bit(is, PARAM_DRC_OTF_OUTPUT);
254 fimc_is_set_param_bit(is, PARAM_FD_OTF_INPUT);
255}
256
257int fimc_is_hw_get_sensor_max_framerate(struct fimc_is *is)
258{
259 switch (is->sensor->drvdata->id) {
260 case FIMC_IS_SENSOR_ID_S5K6A3:
261 return 30;
262 default:
263 return 15;
264 }
265}
266
267void __is_set_sensor(struct fimc_is *is, int fps)
268{
269 unsigned int index = is->config_index;
270 struct sensor_param *sensor;
271 struct isp_param *isp;
272
273 sensor = &is->config[index].sensor;
274 isp = &is->config[index].isp;
275
276 if (fps == 0) {
277 sensor->frame_rate.frame_rate =
278 fimc_is_hw_get_sensor_max_framerate(is);
279 isp->otf_input.frametime_min = 0;
280 isp->otf_input.frametime_max = 66666;
281 } else {
282 sensor->frame_rate.frame_rate = fps;
283 isp->otf_input.frametime_min = 0;
284 isp->otf_input.frametime_max = (u32)1000000 / fps;
285 }
286
287 fimc_is_set_param_bit(is, PARAM_SENSOR_FRAME_RATE);
288 fimc_is_set_param_bit(is, PARAM_ISP_OTF_INPUT);
289}
290
291void __is_set_init_isp_aa(struct fimc_is *is)
292{
293 struct isp_param *isp;
294
295 isp = &is->config[is->config_index].isp;
296
297 isp->aa.cmd = ISP_AA_COMMAND_START;
298 isp->aa.target = ISP_AA_TARGET_AF | ISP_AA_TARGET_AE |
299 ISP_AA_TARGET_AWB;
300 isp->aa.mode = 0;
301 isp->aa.scene = 0;
302 isp->aa.sleep = 0;
303 isp->aa.face = 0;
304 isp->aa.touch_x = 0;
305 isp->aa.touch_y = 0;
306 isp->aa.manual_af_setting = 0;
307 isp->aa.err = ISP_AF_ERROR_NONE;
308
309 fimc_is_set_param_bit(is, PARAM_ISP_AA);
310}
311
312void __is_set_isp_flash(struct fimc_is *is, u32 cmd, u32 redeye)
313{
314 unsigned int index = is->config_index;
315 struct isp_param *isp = &is->config[index].isp;
316
317 isp->flash.cmd = cmd;
318 isp->flash.redeye = redeye;
319 isp->flash.err = ISP_FLASH_ERROR_NONE;
320
321 fimc_is_set_param_bit(is, PARAM_ISP_FLASH);
322}
323
324void __is_set_isp_awb(struct fimc_is *is, u32 cmd, u32 val)
325{
326 unsigned int index = is->config_index;
327 struct isp_param *isp;
328
329 isp = &is->config[index].isp;
330
331 isp->awb.cmd = cmd;
332 isp->awb.illumination = val;
333 isp->awb.err = ISP_AWB_ERROR_NONE;
334
335 fimc_is_set_param_bit(is, PARAM_ISP_AWB);
336}
337
338void __is_set_isp_effect(struct fimc_is *is, u32 cmd)
339{
340 unsigned int index = is->config_index;
341 struct isp_param *isp;
342
343 isp = &is->config[index].isp;
344
345 isp->effect.cmd = cmd;
346 isp->effect.err = ISP_IMAGE_EFFECT_ERROR_NONE;
347
348 fimc_is_set_param_bit(is, PARAM_ISP_IMAGE_EFFECT);
349}
350
351void __is_set_isp_iso(struct fimc_is *is, u32 cmd, u32 val)
352{
353 unsigned int index = is->config_index;
354 struct isp_param *isp;
355
356 isp = &is->config[index].isp;
357
358 isp->iso.cmd = cmd;
359 isp->iso.value = val;
360 isp->iso.err = ISP_ISO_ERROR_NONE;
361
362 fimc_is_set_param_bit(is, PARAM_ISP_ISO);
363}
364
365void __is_set_isp_adjust(struct fimc_is *is, u32 cmd, u32 val)
366{
367 unsigned int index = is->config_index;
368 unsigned long *p_index;
369 struct isp_param *isp;
370
371 p_index = &is->config[index].p_region_index1;
372 isp = &is->config[index].isp;
373
374 switch (cmd) {
375 case ISP_ADJUST_COMMAND_MANUAL_CONTRAST:
376 isp->adjust.contrast = val;
377 break;
378 case ISP_ADJUST_COMMAND_MANUAL_SATURATION:
379 isp->adjust.saturation = val;
380 break;
381 case ISP_ADJUST_COMMAND_MANUAL_SHARPNESS:
382 isp->adjust.sharpness = val;
383 break;
384 case ISP_ADJUST_COMMAND_MANUAL_EXPOSURE:
385 isp->adjust.exposure = val;
386 break;
387 case ISP_ADJUST_COMMAND_MANUAL_BRIGHTNESS:
388 isp->adjust.brightness = val;
389 break;
390 case ISP_ADJUST_COMMAND_MANUAL_HUE:
391 isp->adjust.hue = val;
392 break;
393 case ISP_ADJUST_COMMAND_AUTO:
394 isp->adjust.contrast = 0;
395 isp->adjust.saturation = 0;
396 isp->adjust.sharpness = 0;
397 isp->adjust.exposure = 0;
398 isp->adjust.brightness = 0;
399 isp->adjust.hue = 0;
400 break;
401 }
402
403 if (!test_bit(PARAM_ISP_ADJUST, p_index)) {
404 isp->adjust.cmd = cmd;
405 isp->adjust.err = ISP_ADJUST_ERROR_NONE;
406 fimc_is_set_param_bit(is, PARAM_ISP_ADJUST);
407 } else {
408 isp->adjust.cmd |= cmd;
409 }
410}
411
412void __is_set_isp_metering(struct fimc_is *is, u32 id, u32 val)
413{
414 unsigned int index = is->config_index;
415 struct isp_param *isp;
416 unsigned long *p_index;
417
418 p_index = &is->config[index].p_region_index1;
419 isp = &is->config[index].isp;
420
421 switch (id) {
422 case IS_METERING_CONFIG_CMD:
423 isp->metering.cmd = val;
424 break;
425 case IS_METERING_CONFIG_WIN_POS_X:
426 isp->metering.win_pos_x = val;
427 break;
428 case IS_METERING_CONFIG_WIN_POS_Y:
429 isp->metering.win_pos_y = val;
430 break;
431 case IS_METERING_CONFIG_WIN_WIDTH:
432 isp->metering.win_width = val;
433 break;
434 case IS_METERING_CONFIG_WIN_HEIGHT:
435 isp->metering.win_height = val;
436 break;
437 default:
438 return;
439 }
440
441 if (!test_bit(PARAM_ISP_METERING, p_index)) {
442 isp->metering.err = ISP_METERING_ERROR_NONE;
443 fimc_is_set_param_bit(is, PARAM_ISP_METERING);
444 }
445}
446
447void __is_set_isp_afc(struct fimc_is *is, u32 cmd, u32 val)
448{
449 unsigned int index = is->config_index;
450 struct isp_param *isp;
451
452 isp = &is->config[index].isp;
453
454 isp->afc.cmd = cmd;
455 isp->afc.manual = val;
456 isp->afc.err = ISP_AFC_ERROR_NONE;
457
458 fimc_is_set_param_bit(is, PARAM_ISP_AFC);
459}
460
461void __is_set_drc_control(struct fimc_is *is, u32 val)
462{
463 unsigned int index = is->config_index;
464 struct drc_param *drc;
465
466 drc = &is->config[index].drc;
467
468 drc->control.bypass = val;
469
470 fimc_is_set_param_bit(is, PARAM_DRC_CONTROL);
471}
472
473void __is_set_fd_control(struct fimc_is *is, u32 val)
474{
475 unsigned int index = is->config_index;
476 struct fd_param *fd;
477 unsigned long *p_index;
478
479 p_index = &is->config[index].p_region_index2;
480 fd = &is->config[index].fd;
481
482 fd->control.cmd = val;
483
484 if (!test_bit((PARAM_FD_CONFIG - 32), p_index))
485 fimc_is_set_param_bit(is, PARAM_FD_CONTROL);
486}
487
488void __is_set_fd_config_maxface(struct fimc_is *is, u32 val)
489{
490 unsigned int index = is->config_index;
491 struct fd_param *fd;
492 unsigned long *p_index;
493
494 p_index = &is->config[index].p_region_index2;
495 fd = &is->config[index].fd;
496
497 fd->config.max_number = val;
498
499 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
500 fd->config.cmd = FD_CONFIG_COMMAND_MAXIMUM_NUMBER;
501 fd->config.err = ERROR_FD_NONE;
502 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
503 } else {
504 fd->config.cmd |= FD_CONFIG_COMMAND_MAXIMUM_NUMBER;
505 }
506}
507
508void __is_set_fd_config_rollangle(struct fimc_is *is, u32 val)
509{
510 unsigned int index = is->config_index;
511 struct fd_param *fd;
512 unsigned long *p_index;
513
514 p_index = &is->config[index].p_region_index2;
515 fd = &is->config[index].fd;
516
517 fd->config.roll_angle = val;
518
519 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
520 fd->config.cmd = FD_CONFIG_COMMAND_ROLL_ANGLE;
521 fd->config.err = ERROR_FD_NONE;
522 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
523 } else {
524 fd->config.cmd |= FD_CONFIG_COMMAND_ROLL_ANGLE;
525 }
526}
527
528void __is_set_fd_config_yawangle(struct fimc_is *is, u32 val)
529{
530 unsigned int index = is->config_index;
531 struct fd_param *fd;
532 unsigned long *p_index;
533
534 p_index = &is->config[index].p_region_index2;
535 fd = &is->config[index].fd;
536
537 fd->config.yaw_angle = val;
538
539 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
540 fd->config.cmd = FD_CONFIG_COMMAND_YAW_ANGLE;
541 fd->config.err = ERROR_FD_NONE;
542 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
543 } else {
544 fd->config.cmd |= FD_CONFIG_COMMAND_YAW_ANGLE;
545 }
546}
547
548void __is_set_fd_config_smilemode(struct fimc_is *is, u32 val)
549{
550 unsigned int index = is->config_index;
551 struct fd_param *fd;
552 unsigned long *p_index;
553
554 p_index = &is->config[index].p_region_index2;
555 fd = &is->config[index].fd;
556
557 fd->config.smile_mode = val;
558
559 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
560 fd->config.cmd = FD_CONFIG_COMMAND_SMILE_MODE;
561 fd->config.err = ERROR_FD_NONE;
562 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
563 } else {
564 fd->config.cmd |= FD_CONFIG_COMMAND_SMILE_MODE;
565 }
566}
567
568void __is_set_fd_config_blinkmode(struct fimc_is *is, u32 val)
569{
570 unsigned int index = is->config_index;
571 struct fd_param *fd;
572 unsigned long *p_index;
573
574 p_index = &is->config[index].p_region_index2;
575 fd = &is->config[index].fd;
576
577 fd->config.blink_mode = val;
578
579 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
580 fd->config.cmd = FD_CONFIG_COMMAND_BLINK_MODE;
581 fd->config.err = ERROR_FD_NONE;
582 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
583 } else {
584 fd->config.cmd |= FD_CONFIG_COMMAND_BLINK_MODE;
585 }
586}
587
588void __is_set_fd_config_eyedetect(struct fimc_is *is, u32 val)
589{
590 unsigned int index = is->config_index;
591 struct fd_param *fd;
592 unsigned long *p_index;
593
594 p_index = &is->config[index].p_region_index2;
595 fd = &is->config[index].fd;
596
597 fd->config.eye_detect = val;
598
599 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
600 fd->config.cmd = FD_CONFIG_COMMAND_EYES_DETECT;
601 fd->config.err = ERROR_FD_NONE;
602 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
603 } else {
604 fd->config.cmd |= FD_CONFIG_COMMAND_EYES_DETECT;
605 }
606}
607
608void __is_set_fd_config_mouthdetect(struct fimc_is *is, u32 val)
609{
610 unsigned int index = is->config_index;
611 struct fd_param *fd;
612 unsigned long *p_index;
613
614 p_index = &is->config[index].p_region_index2;
615 fd = &is->config[index].fd;
616
617 fd->config.mouth_detect = val;
618
619 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
620 fd->config.cmd = FD_CONFIG_COMMAND_MOUTH_DETECT;
621 fd->config.err = ERROR_FD_NONE;
622 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
623 } else {
624 fd->config.cmd |= FD_CONFIG_COMMAND_MOUTH_DETECT;
625 }
626}
627
628void __is_set_fd_config_orientation(struct fimc_is *is, u32 val)
629{
630 unsigned int index = is->config_index;
631 struct fd_param *fd;
632 unsigned long *p_index;
633
634 p_index = &is->config[index].p_region_index2;
635 fd = &is->config[index].fd;
636
637 fd->config.orientation = val;
638
639 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
640 fd->config.cmd = FD_CONFIG_COMMAND_ORIENTATION;
641 fd->config.err = ERROR_FD_NONE;
642 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
643 } else {
644 fd->config.cmd |= FD_CONFIG_COMMAND_ORIENTATION;
645 }
646}
647
648void __is_set_fd_config_orientation_val(struct fimc_is *is, u32 val)
649{
650 unsigned int index = is->config_index;
651 struct fd_param *fd;
652 unsigned long *p_index;
653
654 p_index = &is->config[index].p_region_index2;
655 fd = &is->config[index].fd;
656
657 fd->config.orientation_value = val;
658
659 if (!test_bit((PARAM_FD_CONFIG - 32), p_index)) {
660 fd->config.cmd = FD_CONFIG_COMMAND_ORIENTATION_VALUE;
661 fd->config.err = ERROR_FD_NONE;
662 fimc_is_set_param_bit(is, PARAM_FD_CONFIG);
663 } else {
664 fd->config.cmd |= FD_CONFIG_COMMAND_ORIENTATION_VALUE;
665 }
666}
667
668void fimc_is_set_initial_params(struct fimc_is *is)
669{
670 struct global_param *global;
671 struct sensor_param *sensor;
672 struct isp_param *isp;
673 struct drc_param *drc;
674 struct fd_param *fd;
675 unsigned long *p_index1, *p_index2;
676 unsigned int index;
677
678 index = is->config_index;
679 global = &is->config[index].global;
680 sensor = &is->config[index].sensor;
681 isp = &is->config[index].isp;
682 drc = &is->config[index].drc;
683 fd = &is->config[index].fd;
684 p_index1 = &is->config[index].p_region_index1;
685 p_index2 = &is->config[index].p_region_index2;
686
687 /* Global */
688 global->shotmode.cmd = 1;
689 fimc_is_set_param_bit(is, PARAM_GLOBAL_SHOTMODE);
690
691 /* ISP */
692 isp->control.cmd = CONTROL_COMMAND_START;
693 isp->control.bypass = CONTROL_BYPASS_DISABLE;
694 isp->control.err = CONTROL_ERROR_NONE;
695 fimc_is_set_param_bit(is, PARAM_ISP_CONTROL);
696
697 isp->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE;
698 if (!test_bit(PARAM_ISP_OTF_INPUT, p_index1)) {
699 isp->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH;
700 isp->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT;
701 fimc_is_set_param_bit(is, PARAM_ISP_OTF_INPUT);
702 }
703 if (is->sensor->test_pattern)
704 isp->otf_input.format = OTF_INPUT_FORMAT_STRGEN_COLORBAR_BAYER;
705 else
706 isp->otf_input.format = OTF_INPUT_FORMAT_BAYER;
707 isp->otf_input.bitwidth = 10;
708 isp->otf_input.order = OTF_INPUT_ORDER_BAYER_GR_BG;
709 isp->otf_input.crop_offset_x = 0;
710 isp->otf_input.crop_offset_y = 0;
711 isp->otf_input.err = OTF_INPUT_ERROR_NONE;
712
713 isp->dma1_input.cmd = DMA_INPUT_COMMAND_DISABLE;
714 isp->dma1_input.width = 0;
715 isp->dma1_input.height = 0;
716 isp->dma1_input.format = 0;
717 isp->dma1_input.bitwidth = 0;
718 isp->dma1_input.plane = 0;
719 isp->dma1_input.order = 0;
720 isp->dma1_input.buffer_number = 0;
721 isp->dma1_input.width = 0;
722 isp->dma1_input.err = DMA_INPUT_ERROR_NONE;
723 fimc_is_set_param_bit(is, PARAM_ISP_DMA1_INPUT);
724
725 isp->dma2_input.cmd = DMA_INPUT_COMMAND_DISABLE;
726 isp->dma2_input.width = 0;
727 isp->dma2_input.height = 0;
728 isp->dma2_input.format = 0;
729 isp->dma2_input.bitwidth = 0;
730 isp->dma2_input.plane = 0;
731 isp->dma2_input.order = 0;
732 isp->dma2_input.buffer_number = 0;
733 isp->dma2_input.width = 0;
734 isp->dma2_input.err = DMA_INPUT_ERROR_NONE;
735 fimc_is_set_param_bit(is, PARAM_ISP_DMA2_INPUT);
736
737 isp->aa.cmd = ISP_AA_COMMAND_START;
738 isp->aa.target = ISP_AA_TARGET_AE | ISP_AA_TARGET_AWB;
739 fimc_is_set_param_bit(is, PARAM_ISP_AA);
740
741 if (!test_bit(PARAM_ISP_FLASH, p_index1))
742 __is_set_isp_flash(is, ISP_FLASH_COMMAND_DISABLE,
743 ISP_FLASH_REDEYE_DISABLE);
744
745 if (!test_bit(PARAM_ISP_AWB, p_index1))
746 __is_set_isp_awb(is, ISP_AWB_COMMAND_AUTO, 0);
747
748 if (!test_bit(PARAM_ISP_IMAGE_EFFECT, p_index1))
749 __is_set_isp_effect(is, ISP_IMAGE_EFFECT_DISABLE);
750
751 if (!test_bit(PARAM_ISP_ISO, p_index1))
752 __is_set_isp_iso(is, ISP_ISO_COMMAND_AUTO, 0);
753
754 if (!test_bit(PARAM_ISP_ADJUST, p_index1)) {
755 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_CONTRAST, 0);
756 __is_set_isp_adjust(is,
757 ISP_ADJUST_COMMAND_MANUAL_SATURATION, 0);
758 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_SHARPNESS, 0);
759 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_EXPOSURE, 0);
760 __is_set_isp_adjust(is,
761 ISP_ADJUST_COMMAND_MANUAL_BRIGHTNESS, 0);
762 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_HUE, 0);
763 }
764
765 if (!test_bit(PARAM_ISP_METERING, p_index1)) {
766 __is_set_isp_metering(is, 0, ISP_METERING_COMMAND_CENTER);
767 __is_set_isp_metering(is, 1, 0);
768 __is_set_isp_metering(is, 2, 0);
769 __is_set_isp_metering(is, 3, 0);
770 __is_set_isp_metering(is, 4, 0);
771 }
772
773 if (!test_bit(PARAM_ISP_AFC, p_index1))
774 __is_set_isp_afc(is, ISP_AFC_COMMAND_AUTO, 0);
775
776 isp->otf_output.cmd = OTF_OUTPUT_COMMAND_ENABLE;
777 if (!test_bit(PARAM_ISP_OTF_OUTPUT, p_index1)) {
778 isp->otf_output.width = DEFAULT_PREVIEW_STILL_WIDTH;
779 isp->otf_output.height = DEFAULT_PREVIEW_STILL_HEIGHT;
780 fimc_is_set_param_bit(is, PARAM_ISP_OTF_OUTPUT);
781 }
782 isp->otf_output.format = OTF_OUTPUT_FORMAT_YUV444;
783 isp->otf_output.bitwidth = 12;
784 isp->otf_output.order = 0;
785 isp->otf_output.err = OTF_OUTPUT_ERROR_NONE;
786
787 if (!test_bit(PARAM_ISP_DMA1_OUTPUT, p_index1)) {
788 isp->dma1_output.cmd = DMA_OUTPUT_COMMAND_DISABLE;
789 isp->dma1_output.width = 0;
790 isp->dma1_output.height = 0;
791 isp->dma1_output.format = 0;
792 isp->dma1_output.bitwidth = 0;
793 isp->dma1_output.plane = 0;
794 isp->dma1_output.order = 0;
795 isp->dma1_output.buffer_number = 0;
796 isp->dma1_output.buffer_address = 0;
797 isp->dma1_output.notify_dma_done = 0;
798 isp->dma1_output.dma_out_mask = 0;
799 isp->dma1_output.err = DMA_OUTPUT_ERROR_NONE;
800 fimc_is_set_param_bit(is, PARAM_ISP_DMA1_OUTPUT);
801 }
802
803 if (!test_bit(PARAM_ISP_DMA2_OUTPUT, p_index1)) {
804 isp->dma2_output.cmd = DMA_OUTPUT_COMMAND_DISABLE;
805 isp->dma2_output.width = 0;
806 isp->dma2_output.height = 0;
807 isp->dma2_output.format = 0;
808 isp->dma2_output.bitwidth = 0;
809 isp->dma2_output.plane = 0;
810 isp->dma2_output.order = 0;
811 isp->dma2_output.buffer_number = 0;
812 isp->dma2_output.buffer_address = 0;
813 isp->dma2_output.notify_dma_done = 0;
814 isp->dma2_output.dma_out_mask = 0;
815 isp->dma2_output.err = DMA_OUTPUT_ERROR_NONE;
816 fimc_is_set_param_bit(is, PARAM_ISP_DMA2_OUTPUT);
817 }
818
819 /* Sensor */
820 if (!test_bit(PARAM_SENSOR_FRAME_RATE, p_index1)) {
821 if (is->config_index == 0)
822 __is_set_sensor(is, 0);
823 }
824
825 /* DRC */
826 drc->control.cmd = CONTROL_COMMAND_START;
827 __is_set_drc_control(is, CONTROL_BYPASS_ENABLE);
828
829 drc->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE;
830 if (!test_bit(PARAM_DRC_OTF_INPUT, p_index1)) {
831 drc->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH;
832 drc->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT;
833 fimc_is_set_param_bit(is, PARAM_DRC_OTF_INPUT);
834 }
835 drc->otf_input.format = OTF_INPUT_FORMAT_YUV444;
836 drc->otf_input.bitwidth = 12;
837 drc->otf_input.order = 0;
838 drc->otf_input.err = OTF_INPUT_ERROR_NONE;
839
840 drc->dma_input.cmd = DMA_INPUT_COMMAND_DISABLE;
841 drc->dma_input.width = 0;
842 drc->dma_input.height = 0;
843 drc->dma_input.format = 0;
844 drc->dma_input.bitwidth = 0;
845 drc->dma_input.plane = 0;
846 drc->dma_input.order = 0;
847 drc->dma_input.buffer_number = 0;
848 drc->dma_input.width = 0;
849 drc->dma_input.err = DMA_INPUT_ERROR_NONE;
850 fimc_is_set_param_bit(is, PARAM_DRC_DMA_INPUT);
851
852 drc->otf_output.cmd = OTF_OUTPUT_COMMAND_ENABLE;
853 if (!test_bit(PARAM_DRC_OTF_OUTPUT, p_index1)) {
854 drc->otf_output.width = DEFAULT_PREVIEW_STILL_WIDTH;
855 drc->otf_output.height = DEFAULT_PREVIEW_STILL_HEIGHT;
856 fimc_is_set_param_bit(is, PARAM_DRC_OTF_OUTPUT);
857 }
858 drc->otf_output.format = OTF_OUTPUT_FORMAT_YUV444;
859 drc->otf_output.bitwidth = 8;
860 drc->otf_output.order = 0;
861 drc->otf_output.err = OTF_OUTPUT_ERROR_NONE;
862
863 /* FD */
864 __is_set_fd_control(is, CONTROL_COMMAND_STOP);
865 fd->control.bypass = CONTROL_BYPASS_DISABLE;
866
867 fd->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE;
868 if (!test_bit((PARAM_FD_OTF_INPUT - 32), p_index2)) {
869 fd->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH;
870 fd->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT;
871 fimc_is_set_param_bit(is, PARAM_FD_OTF_INPUT);
872 }
873
874 fd->otf_input.format = OTF_INPUT_FORMAT_YUV444;
875 fd->otf_input.bitwidth = 8;
876 fd->otf_input.order = 0;
877 fd->otf_input.err = OTF_INPUT_ERROR_NONE;
878
879 fd->dma_input.cmd = DMA_INPUT_COMMAND_DISABLE;
880 fd->dma_input.width = 0;
881 fd->dma_input.height = 0;
882 fd->dma_input.format = 0;
883 fd->dma_input.bitwidth = 0;
884 fd->dma_input.plane = 0;
885 fd->dma_input.order = 0;
886 fd->dma_input.buffer_number = 0;
887 fd->dma_input.width = 0;
888 fd->dma_input.err = DMA_INPUT_ERROR_NONE;
889 fimc_is_set_param_bit(is, PARAM_FD_DMA_INPUT);
890
891 __is_set_fd_config_maxface(is, 5);
892 __is_set_fd_config_rollangle(is, FD_CONFIG_ROLL_ANGLE_FULL);
893 __is_set_fd_config_yawangle(is, FD_CONFIG_YAW_ANGLE_45_90);
894 __is_set_fd_config_smilemode(is, FD_CONFIG_SMILE_MODE_DISABLE);
895 __is_set_fd_config_blinkmode(is, FD_CONFIG_BLINK_MODE_DISABLE);
896 __is_set_fd_config_eyedetect(is, FD_CONFIG_EYES_DETECT_ENABLE);
897 __is_set_fd_config_mouthdetect(is, FD_CONFIG_MOUTH_DETECT_DISABLE);
898 __is_set_fd_config_orientation(is, FD_CONFIG_ORIENTATION_DISABLE);
899 __is_set_fd_config_orientation_val(is, 0);
900}
diff --git a/drivers/media/platform/exynos4-is/fimc-is-param.h b/drivers/media/platform/exynos4-is/fimc-is-param.h
new file mode 100644
index 000000000000..f9358c27ae2d
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-param.h
@@ -0,0 +1,1020 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
7 * Sylwester Nawrocki <s.nawrocki@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef FIMC_IS_PARAM_H_
14#define FIMC_IS_PARAM_H_
15
16#include <linux/compiler.h>
17
18#define FIMC_IS_CONFIG_TIMEOUT 3000 /* ms */
19#define IS_DEFAULT_WIDTH 1280
20#define IS_DEFAULT_HEIGHT 720
21
22#define DEFAULT_PREVIEW_STILL_WIDTH IS_DEFAULT_WIDTH
23#define DEFAULT_PREVIEW_STILL_HEIGHT IS_DEFAULT_HEIGHT
24#define DEFAULT_CAPTURE_STILL_WIDTH IS_DEFAULT_WIDTH
25#define DEFAULT_CAPTURE_STILL_HEIGHT IS_DEFAULT_HEIGHT
26#define DEFAULT_PREVIEW_VIDEO_WIDTH IS_DEFAULT_WIDTH
27#define DEFAULT_PREVIEW_VIDEO_HEIGHT IS_DEFAULT_HEIGHT
28#define DEFAULT_CAPTURE_VIDEO_WIDTH IS_DEFAULT_WIDTH
29#define DEFAULT_CAPTURE_VIDEO_HEIGHT IS_DEFAULT_HEIGHT
30
31#define DEFAULT_PREVIEW_STILL_FRAMERATE 30
32#define DEFAULT_CAPTURE_STILL_FRAMERATE 15
33#define DEFAULT_PREVIEW_VIDEO_FRAMERATE 30
34#define DEFAULT_CAPTURE_VIDEO_FRAMERATE 30
35
36#define FIMC_IS_REGION_VER 124 /* IS REGION VERSION 1.24 */
37#define FIMC_IS_PARAM_SIZE (FIMC_IS_REGION_SIZE + 1)
38#define FIMC_IS_MAGIC_NUMBER 0x01020304
39#define FIMC_IS_PARAM_MAX_SIZE 64 /* in bytes */
40#define FIMC_IS_PARAM_MAX_ENTRIES (FIMC_IS_PARAM_MAX_SIZE / 4)
41
42/* The parameter bitmask bit definitions. */
43enum is_param_bit {
44 PARAM_GLOBAL_SHOTMODE,
45 PARAM_SENSOR_CONTROL,
46 PARAM_SENSOR_OTF_OUTPUT,
47 PARAM_SENSOR_FRAME_RATE,
48 PARAM_BUFFER_CONTROL,
49 PARAM_BUFFER_OTF_INPUT,
50 PARAM_BUFFER_OTF_OUTPUT,
51 PARAM_ISP_CONTROL,
52 PARAM_ISP_OTF_INPUT,
53 PARAM_ISP_DMA1_INPUT,
54 /* 10 */
55 PARAM_ISP_DMA2_INPUT,
56 PARAM_ISP_AA,
57 PARAM_ISP_FLASH,
58 PARAM_ISP_AWB,
59 PARAM_ISP_IMAGE_EFFECT,
60 PARAM_ISP_ISO,
61 PARAM_ISP_ADJUST,
62 PARAM_ISP_METERING,
63 PARAM_ISP_AFC,
64 PARAM_ISP_OTF_OUTPUT,
65 /* 20 */
66 PARAM_ISP_DMA1_OUTPUT,
67 PARAM_ISP_DMA2_OUTPUT,
68 PARAM_DRC_CONTROL,
69 PARAM_DRC_OTF_INPUT,
70 PARAM_DRC_DMA_INPUT,
71 PARAM_DRC_OTF_OUTPUT,
72 PARAM_SCALERC_CONTROL,
73 PARAM_SCALERC_OTF_INPUT,
74 PARAM_SCALERC_IMAGE_EFFECT,
75 PARAM_SCALERC_INPUT_CROP,
76 /* 30 */
77 PARAM_SCALERC_OUTPUT_CROP,
78 PARAM_SCALERC_OTF_OUTPUT,
79 PARAM_SCALERC_DMA_OUTPUT,
80 PARAM_ODC_CONTROL,
81 PARAM_ODC_OTF_INPUT,
82 PARAM_ODC_OTF_OUTPUT,
83 PARAM_DIS_CONTROL,
84 PARAM_DIS_OTF_INPUT,
85 PARAM_DIS_OTF_OUTPUT,
86 PARAM_TDNR_CONTROL,
87 /* 40 */
88 PARAM_TDNR_OTF_INPUT,
89 PARAM_TDNR_1ST_FRAME,
90 PARAM_TDNR_OTF_OUTPUT,
91 PARAM_TDNR_DMA_OUTPUT,
92 PARAM_SCALERP_CONTROL,
93 PARAM_SCALERP_OTF_INPUT,
94 PARAM_SCALERP_IMAGE_EFFECT,
95 PARAM_SCALERP_INPUT_CROP,
96 PARAM_SCALERP_OUTPUT_CROP,
97 PARAM_SCALERP_ROTATION,
98 /* 50 */
99 PARAM_SCALERP_FLIP,
100 PARAM_SCALERP_OTF_OUTPUT,
101 PARAM_SCALERP_DMA_OUTPUT,
102 PARAM_FD_CONTROL,
103 PARAM_FD_OTF_INPUT,
104 PARAM_FD_DMA_INPUT,
105 PARAM_FD_CONFIG,
106};
107
108/* Interrupt map */
109#define FIMC_IS_INT_GENERAL 0
110#define FIMC_IS_INT_FRAME_DONE_ISP 1
111
112/* Input */
113
114#define CONTROL_COMMAND_STOP 0
115#define CONTROL_COMMAND_START 1
116
117#define CONTROL_BYPASS_DISABLE 0
118#define CONTROL_BYPASS_ENABLE 1
119
120#define CONTROL_ERROR_NONE 0
121
122/* OTF (On-The-Fly) input interface commands */
123#define OTF_INPUT_COMMAND_DISABLE 0
124#define OTF_INPUT_COMMAND_ENABLE 1
125
126/* OTF input interface color formats */
127enum oft_input_fmt {
128 OTF_INPUT_FORMAT_BAYER = 0, /* 1 channel */
129 OTF_INPUT_FORMAT_YUV444 = 1, /* 3 channels */
130 OTF_INPUT_FORMAT_YUV422 = 2, /* 3 channels */
131 OTF_INPUT_FORMAT_YUV420 = 3, /* 3 channels */
132 OTF_INPUT_FORMAT_STRGEN_COLORBAR_BAYER = 10,
133 OTF_INPUT_FORMAT_BAYER_DMA = 11,
134};
135
136#define OTF_INPUT_ORDER_BAYER_GR_BG 0
137
138/* OTF input error codes */
139#define OTF_INPUT_ERROR_NONE 0 /* Input setting is done */
140
141/* DMA input commands */
142#define DMA_INPUT_COMMAND_DISABLE 0
143#define DMA_INPUT_COMMAND_ENABLE 1
144
145/* DMA input color formats */
146enum dma_input_fmt {
147 DMA_INPUT_FORMAT_BAYER = 0,
148 DMA_INPUT_FORMAT_YUV444 = 1,
149 DMA_INPUT_FORMAT_YUV422 = 2,
150 DMA_INPUT_FORMAT_YUV420 = 3,
151};
152
153enum dma_input_order {
154 /* (for DMA_INPUT_PLANE_3) */
155 DMA_INPUT_ORDER_NO = 0,
156 /* (only valid at DMA_INPUT_PLANE_2) */
157 DMA_INPUT_ORDER_CBCR = 1,
158 /* (only valid at DMA_INPUT_PLANE_2) */
159 DMA_INPUT_ORDER_CRCB = 2,
160 /* (only valid at DMA_INPUT_PLANE_1 & DMA_INPUT_FORMAT_YUV444) */
161 DMA_INPUT_ORDER_YCBCR = 3,
162 /* (only valid at DMA_INPUT_FORMAT_YUV422 & DMA_INPUT_PLANE_1) */
163 DMA_INPUT_ORDER_YYCBCR = 4,
164 /* (only valid at DMA_INPUT_FORMAT_YUV422 & DMA_INPUT_PLANE_1) */
165 DMA_INPUT_ORDER_YCBYCR = 5,
166 /* (only valid at DMA_INPUT_FORMAT_YUV422 & DMA_INPUT_PLANE_1) */
167 DMA_INPUT_ORDER_YCRYCB = 6,
168 /* (only valid at DMA_INPUT_FORMAT_YUV422 & DMA_INPUT_PLANE_1) */
169 DMA_INPUT_ORDER_CBYCRY = 7,
170 /* (only valid at DMA_INPUT_FORMAT_YUV422 & DMA_INPUT_PLANE_1) */
171 DMA_INPUT_ORDER_CRYCBY = 8,
172 /* (only valid at DMA_INPUT_FORMAT_BAYER) */
173 DMA_INPUT_ORDER_GR_BG = 9
174};
175
176#define DMA_INPUT_ERROR_NONE 0 /* DMA input setting
177 is done */
178/*
179 * Data output parameter definitions
180 */
181#define OTF_OUTPUT_CROP_DISABLE 0
182#define OTF_OUTPUT_CROP_ENABLE 1
183
184#define OTF_OUTPUT_COMMAND_DISABLE 0
185#define OTF_OUTPUT_COMMAND_ENABLE 1
186
187enum otf_output_fmt {
188 OTF_OUTPUT_FORMAT_YUV444 = 1,
189 OTF_OUTPUT_FORMAT_YUV422 = 2,
190 OTF_OUTPUT_FORMAT_YUV420 = 3,
191 OTF_OUTPUT_FORMAT_RGB = 4,
192};
193
194#define OTF_OUTPUT_ORDER_BAYER_GR_BG 0
195
196#define OTF_OUTPUT_ERROR_NONE 0 /* Output Setting is done */
197
198#define DMA_OUTPUT_COMMAND_DISABLE 0
199#define DMA_OUTPUT_COMMAND_ENABLE 1
200
201enum dma_output_fmt {
202 DMA_OUTPUT_FORMAT_BAYER = 0,
203 DMA_OUTPUT_FORMAT_YUV444 = 1,
204 DMA_OUTPUT_FORMAT_YUV422 = 2,
205 DMA_OUTPUT_FORMAT_YUV420 = 3,
206 DMA_OUTPUT_FORMAT_RGB = 4,
207};
208
209enum dma_output_order {
210 DMA_OUTPUT_ORDER_NO = 0,
211 /* for DMA_OUTPUT_PLANE_3 */
212 DMA_OUTPUT_ORDER_CBCR = 1,
213 /* only valid at DMA_INPUT_PLANE_2) */
214 DMA_OUTPUT_ORDER_CRCB = 2,
215 /* only valid at DMA_OUTPUT_PLANE_2) */
216 DMA_OUTPUT_ORDER_YYCBCR = 3,
217 /* only valid at DMA_OUTPUT_FORMAT_YUV422 & DMA_OUTPUT_PLANE_1 */
218 DMA_OUTPUT_ORDER_YCBYCR = 4,
219 /* only valid at DMA_OUTPUT_FORMAT_YUV422 & DMA_OUTPUT_PLANE_1 */
220 DMA_OUTPUT_ORDER_YCRYCB = 5,
221 /* only valid at DMA_OUTPUT_FORMAT_YUV422 & DMA_OUTPUT_PLANE_1 */
222 DMA_OUTPUT_ORDER_CBYCRY = 6,
223 /* only valid at DMA_OUTPUT_FORMAT_YUV422 & DMA_OUTPUT_PLANE_1 */
224 DMA_OUTPUT_ORDER_CRYCBY = 7,
225 /* only valid at DMA_OUTPUT_FORMAT_YUV422 & DMA_OUTPUT_PLANE_1 */
226 DMA_OUTPUT_ORDER_YCBCR = 8,
227 /* only valid at DMA_OUTPUT_FORMAT_YUV444 & DMA_OUPUT_PLANE_1 */
228 DMA_OUTPUT_ORDER_CRYCB = 9,
229 /* only valid at DMA_OUTPUT_FORMAT_YUV444 & DMA_OUPUT_PLANE_1 */
230 DMA_OUTPUT_ORDER_CRCBY = 10,
231 /* only valid at DMA_OUTPUT_FORMAT_YUV444 & DMA_OUPUT_PLANE_1 */
232 DMA_OUTPUT_ORDER_CBYCR = 11,
233 /* only valid at DMA_OUTPUT_FORMAT_YUV444 & DMA_OUPUT_PLANE_1 */
234 DMA_OUTPUT_ORDER_YCRCB = 12,
235 /* only valid at DMA_OUTPUT_FORMAT_YUV444 & DMA_OUPUT_PLANE_1 */
236 DMA_OUTPUT_ORDER_CBCRY = 13,
237 /* only valid at DMA_OUTPUT_FORMAT_YUV444 & DMA_OUPUT_PLANE_1 */
238 DMA_OUTPUT_ORDER_BGR = 14,
239 /* only valid at DMA_OUTPUT_FORMAT_RGB */
240 DMA_OUTPUT_ORDER_GB_BG = 15
241 /* only valid at DMA_OUTPUT_FORMAT_BAYER */
242};
243
244/* enum dma_output_notify_dma_done */
245#define DMA_OUTPUT_NOTIFY_DMA_DONE_DISABLE 0
246#define DMA_OUTPUT_NOTIFY_DMA_DONE_ENABLE 1
247
248/* DMA output error codes */
249#define DMA_OUTPUT_ERROR_NONE 0 /* DMA output setting
250 is done */
251
252/* ---------------------- Global ----------------------------------- */
253#define GLOBAL_SHOTMODE_ERROR_NONE 0 /* shot-mode setting
254 is done */
255/* 3A lock commands */
256#define ISP_AA_COMMAND_START 0
257#define ISP_AA_COMMAND_STOP 1
258
259/* 3A lock target */
260#define ISP_AA_TARGET_AF 1
261#define ISP_AA_TARGET_AE 2
262#define ISP_AA_TARGET_AWB 4
263
264enum isp_af_mode {
265 ISP_AF_MODE_MANUAL = 0,
266 ISP_AF_MODE_SINGLE = 1,
267 ISP_AF_MODE_CONTINUOUS = 2,
268 ISP_AF_MODE_TOUCH = 3,
269 ISP_AF_MODE_SLEEP = 4,
270 ISP_AF_MODE_INIT = 5,
271 ISP_AF_MODE_SET_CENTER_WINDOW = 6,
272 ISP_AF_MODE_SET_TOUCH_WINDOW = 7
273};
274
275/* Face AF commands */
276#define ISP_AF_FACE_DISABLE 0
277#define ISP_AF_FACE_ENABLE 1
278
279/* AF range */
280#define ISP_AF_RANGE_NORMAL 0
281#define ISP_AF_RANGE_MACRO 1
282
283/* AF sleep */
284#define ISP_AF_SLEEP_OFF 0
285#define ISP_AF_SLEEP_ON 1
286
287/* Continuous AF commands */
288#define ISP_AF_CONTINUOUS_DISABLE 0
289#define ISP_AF_CONTINUOUS_ENABLE 1
290
291/* ISP AF error codes */
292#define ISP_AF_ERROR_NONE 0 /* AF mode change is done */
293#define ISP_AF_ERROR_NONE_LOCK_DONE 1 /* AF lock is done */
294
295/* Flash commands */
296#define ISP_FLASH_COMMAND_DISABLE 0
297#define ISP_FLASH_COMMAND_MANUAL_ON 1 /* (forced flash) */
298#define ISP_FLASH_COMMAND_AUTO 2
299#define ISP_FLASH_COMMAND_TORCH 3 /* 3 sec */
300
301/* Flash red-eye commads */
302#define ISP_FLASH_REDEYE_DISABLE 0
303#define ISP_FLASH_REDEYE_ENABLE 1
304
305/* Flash error codes */
306#define ISP_FLASH_ERROR_NONE 0 /* Flash setting is done */
307
308/* -------------------------- AWB ------------------------------------ */
309enum isp_awb_command {
310 ISP_AWB_COMMAND_AUTO = 0,
311 ISP_AWB_COMMAND_ILLUMINATION = 1,
312 ISP_AWB_COMMAND_MANUAL = 2
313};
314
315enum isp_awb_illumination {
316 ISP_AWB_ILLUMINATION_DAYLIGHT = 0,
317 ISP_AWB_ILLUMINATION_CLOUDY = 1,
318 ISP_AWB_ILLUMINATION_TUNGSTEN = 2,
319 ISP_AWB_ILLUMINATION_FLUORESCENT = 3
320};
321
322/* ISP AWN error codes */
323#define ISP_AWB_ERROR_NONE 0 /* AWB setting is done */
324
325/* -------------------------- Effect ----------------------------------- */
326enum isp_imageeffect_command {
327 ISP_IMAGE_EFFECT_DISABLE = 0,
328 ISP_IMAGE_EFFECT_MONOCHROME = 1,
329 ISP_IMAGE_EFFECT_NEGATIVE_MONO = 2,
330 ISP_IMAGE_EFFECT_NEGATIVE_COLOR = 3,
331 ISP_IMAGE_EFFECT_SEPIA = 4
332};
333
334/* Image effect error codes */
335#define ISP_IMAGE_EFFECT_ERROR_NONE 0 /* Image effect setting
336 is done */
337/* ISO commands */
338#define ISP_ISO_COMMAND_AUTO 0
339#define ISP_ISO_COMMAND_MANUAL 1
340
341/* ISO error codes */
342#define ISP_ISO_ERROR_NONE 0 /* ISO setting is done */
343
344/* ISP adjust commands */
345#define ISP_ADJUST_COMMAND_AUTO (0 << 0)
346#define ISP_ADJUST_COMMAND_MANUAL_CONTRAST (1 << 0)
347#define ISP_ADJUST_COMMAND_MANUAL_SATURATION (1 << 1)
348#define ISP_ADJUST_COMMAND_MANUAL_SHARPNESS (1 << 2)
349#define ISP_ADJUST_COMMAND_MANUAL_EXPOSURE (1 << 3)
350#define ISP_ADJUST_COMMAND_MANUAL_BRIGHTNESS (1 << 4)
351#define ISP_ADJUST_COMMAND_MANUAL_HUE (1 << 5)
352#define ISP_ADJUST_COMMAND_MANUAL_ALL 0x7f
353
354/* ISP adjustment error codes */
355#define ISP_ADJUST_ERROR_NONE 0 /* Adjust setting is done */
356
357/*
358 * Exposure metering
359 */
360enum isp_metering_command {
361 ISP_METERING_COMMAND_AVERAGE = 0,
362 ISP_METERING_COMMAND_SPOT = 1,
363 ISP_METERING_COMMAND_MATRIX = 2,
364 ISP_METERING_COMMAND_CENTER = 3
365};
366
367/* ISP metering error codes */
368#define ISP_METERING_ERROR_NONE 0 /* Metering setting is done */
369
370/*
371 * AFC
372 */
373enum isp_afc_command {
374 ISP_AFC_COMMAND_DISABLE = 0,
375 ISP_AFC_COMMAND_AUTO = 1,
376 ISP_AFC_COMMAND_MANUAL = 2,
377};
378
379#define ISP_AFC_MANUAL_50HZ 50
380#define ISP_AFC_MANUAL_60HZ 60
381
382/* ------------------------ SCENE MODE--------------------------------- */
383enum isp_scene_mode {
384 ISP_SCENE_NONE = 0,
385 ISP_SCENE_PORTRAIT = 1,
386 ISP_SCENE_LANDSCAPE = 2,
387 ISP_SCENE_SPORTS = 3,
388 ISP_SCENE_PARTYINDOOR = 4,
389 ISP_SCENE_BEACHSNOW = 5,
390 ISP_SCENE_SUNSET = 6,
391 ISP_SCENE_DAWN = 7,
392 ISP_SCENE_FALL = 8,
393 ISP_SCENE_NIGHT = 9,
394 ISP_SCENE_AGAINSTLIGHTWLIGHT = 10,
395 ISP_SCENE_AGAINSTLIGHTWOLIGHT = 11,
396 ISP_SCENE_FIRE = 12,
397 ISP_SCENE_TEXT = 13,
398 ISP_SCENE_CANDLE = 14
399};
400
401/* AFC error codes */
402#define ISP_AFC_ERROR_NONE 0 /* AFC setting is done */
403
404/* ---------------------------- FD ------------------------------------- */
405enum fd_config_command {
406 FD_CONFIG_COMMAND_MAXIMUM_NUMBER = 0x1,
407 FD_CONFIG_COMMAND_ROLL_ANGLE = 0x2,
408 FD_CONFIG_COMMAND_YAW_ANGLE = 0x4,
409 FD_CONFIG_COMMAND_SMILE_MODE = 0x8,
410 FD_CONFIG_COMMAND_BLINK_MODE = 0x10,
411 FD_CONFIG_COMMAND_EYES_DETECT = 0x20,
412 FD_CONFIG_COMMAND_MOUTH_DETECT = 0x40,
413 FD_CONFIG_COMMAND_ORIENTATION = 0x80,
414 FD_CONFIG_COMMAND_ORIENTATION_VALUE = 0x100
415};
416
417enum fd_config_roll_angle {
418 FD_CONFIG_ROLL_ANGLE_BASIC = 0,
419 FD_CONFIG_ROLL_ANGLE_PRECISE_BASIC = 1,
420 FD_CONFIG_ROLL_ANGLE_SIDES = 2,
421 FD_CONFIG_ROLL_ANGLE_PRECISE_SIDES = 3,
422 FD_CONFIG_ROLL_ANGLE_FULL = 4,
423 FD_CONFIG_ROLL_ANGLE_PRECISE_FULL = 5,
424};
425
426enum fd_config_yaw_angle {
427 FD_CONFIG_YAW_ANGLE_0 = 0,
428 FD_CONFIG_YAW_ANGLE_45 = 1,
429 FD_CONFIG_YAW_ANGLE_90 = 2,
430 FD_CONFIG_YAW_ANGLE_45_90 = 3,
431};
432
433/* Smile mode configuration */
434#define FD_CONFIG_SMILE_MODE_DISABLE 0
435#define FD_CONFIG_SMILE_MODE_ENABLE 1
436
437/* Blink mode configuration */
438#define FD_CONFIG_BLINK_MODE_DISABLE 0
439#define FD_CONFIG_BLINK_MODE_ENABLE 1
440
441/* Eyes detection configuration */
442#define FD_CONFIG_EYES_DETECT_DISABLE 0
443#define FD_CONFIG_EYES_DETECT_ENABLE 1
444
445/* Mouth detection configuration */
446#define FD_CONFIG_MOUTH_DETECT_DISABLE 0
447#define FD_CONFIG_MOUTH_DETECT_ENABLE 1
448
449#define FD_CONFIG_ORIENTATION_DISABLE 0
450#define FD_CONFIG_ORIENTATION_ENABLE 1
451
452struct param_control {
453 u32 cmd;
454 u32 bypass;
455 u32 buffer_address;
456 u32 buffer_size;
457 u32 skip_frames; /* only valid at ISP */
458 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 6];
459 u32 err;
460};
461
462struct param_otf_input {
463 u32 cmd;
464 u32 width;
465 u32 height;
466 u32 format;
467 u32 bitwidth;
468 u32 order;
469 u32 crop_offset_x;
470 u32 crop_offset_y;
471 u32 crop_width;
472 u32 crop_height;
473 u32 frametime_min;
474 u32 frametime_max;
475 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 13];
476 u32 err;
477};
478
479struct param_dma_input {
480 u32 cmd;
481 u32 width;
482 u32 height;
483 u32 format;
484 u32 bitwidth;
485 u32 plane;
486 u32 order;
487 u32 buffer_number;
488 u32 buffer_address;
489 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 10];
490 u32 err;
491};
492
493struct param_otf_output {
494 u32 cmd;
495 u32 width;
496 u32 height;
497 u32 format;
498 u32 bitwidth;
499 u32 order;
500 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 7];
501 u32 err;
502};
503
504struct param_dma_output {
505 u32 cmd;
506 u32 width;
507 u32 height;
508 u32 format;
509 u32 bitwidth;
510 u32 plane;
511 u32 order;
512 u32 buffer_number;
513 u32 buffer_address;
514 u32 notify_dma_done;
515 u32 dma_out_mask;
516 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 12];
517 u32 err;
518};
519
520struct param_global_shotmode {
521 u32 cmd;
522 u32 skip_frames;
523 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 3];
524 u32 err;
525};
526
527struct param_sensor_framerate {
528 u32 frame_rate;
529 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 2];
530 u32 err;
531};
532
533struct param_isp_aa {
534 u32 cmd;
535 u32 target;
536 u32 mode;
537 u32 scene;
538 u32 sleep;
539 u32 face;
540 u32 touch_x;
541 u32 touch_y;
542 u32 manual_af_setting;
543 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 10];
544 u32 err;
545};
546
547struct param_isp_flash {
548 u32 cmd;
549 u32 redeye;
550 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 3];
551 u32 err;
552};
553
554struct param_isp_awb {
555 u32 cmd;
556 u32 illumination;
557 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 3];
558 u32 err;
559};
560
561struct param_isp_imageeffect {
562 u32 cmd;
563 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 2];
564 u32 err;
565};
566
567struct param_isp_iso {
568 u32 cmd;
569 u32 value;
570 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 3];
571 u32 err;
572};
573
574struct param_isp_adjust {
575 u32 cmd;
576 s32 contrast;
577 s32 saturation;
578 s32 sharpness;
579 s32 exposure;
580 s32 brightness;
581 s32 hue;
582 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 8];
583 u32 err;
584};
585
586struct param_isp_metering {
587 u32 cmd;
588 u32 win_pos_x;
589 u32 win_pos_y;
590 u32 win_width;
591 u32 win_height;
592 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 6];
593 u32 err;
594};
595
596struct param_isp_afc {
597 u32 cmd;
598 u32 manual;
599 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 3];
600 u32 err;
601};
602
603struct param_scaler_imageeffect {
604 u32 cmd;
605 u32 arbitrary_cb;
606 u32 arbitrary_cr;
607 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 4];
608 u32 err;
609};
610
611struct param_scaler_input_crop {
612 u32 cmd;
613 u32 crop_offset_x;
614 u32 crop_offset_y;
615 u32 crop_width;
616 u32 crop_height;
617 u32 in_width;
618 u32 in_height;
619 u32 out_width;
620 u32 out_height;
621 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 10];
622 u32 err;
623};
624
625struct param_scaler_output_crop {
626 u32 cmd;
627 u32 crop_offset_x;
628 u32 crop_offset_y;
629 u32 crop_width;
630 u32 crop_height;
631 u32 out_format;
632 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 7];
633 u32 err;
634};
635
636struct param_scaler_rotation {
637 u32 cmd;
638 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 2];
639 u32 err;
640};
641
642struct param_scaler_flip {
643 u32 cmd;
644 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 2];
645 u32 err;
646};
647
648struct param_3dnr_1stframe {
649 u32 cmd;
650 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 2];
651 u32 err;
652};
653
654struct param_fd_config {
655 u32 cmd;
656 u32 max_number;
657 u32 roll_angle;
658 u32 yaw_angle;
659 u32 smile_mode;
660 u32 blink_mode;
661 u32 eye_detect;
662 u32 mouth_detect;
663 u32 orientation;
664 u32 orientation_value;
665 u32 reserved[FIMC_IS_PARAM_MAX_ENTRIES - 11];
666 u32 err;
667};
668
669struct global_param {
670 struct param_global_shotmode shotmode;
671};
672
673struct sensor_param {
674 struct param_control control;
675 struct param_otf_output otf_output;
676 struct param_sensor_framerate frame_rate;
677} __packed;
678
679struct buffer_param {
680 struct param_control control;
681 struct param_otf_input otf_input;
682 struct param_otf_output otf_output;
683} __packed;
684
685struct isp_param {
686 struct param_control control;
687 struct param_otf_input otf_input;
688 struct param_dma_input dma1_input;
689 struct param_dma_input dma2_input;
690 struct param_isp_aa aa;
691 struct param_isp_flash flash;
692 struct param_isp_awb awb;
693 struct param_isp_imageeffect effect;
694 struct param_isp_iso iso;
695 struct param_isp_adjust adjust;
696 struct param_isp_metering metering;
697 struct param_isp_afc afc;
698 struct param_otf_output otf_output;
699 struct param_dma_output dma1_output;
700 struct param_dma_output dma2_output;
701} __packed;
702
703struct drc_param {
704 struct param_control control;
705 struct param_otf_input otf_input;
706 struct param_dma_input dma_input;
707 struct param_otf_output otf_output;
708} __packed;
709
710struct scalerc_param {
711 struct param_control control;
712 struct param_otf_input otf_input;
713 struct param_scaler_imageeffect effect;
714 struct param_scaler_input_crop input_crop;
715 struct param_scaler_output_crop output_crop;
716 struct param_otf_output otf_output;
717 struct param_dma_output dma_output;
718} __packed;
719
720struct odc_param {
721 struct param_control control;
722 struct param_otf_input otf_input;
723 struct param_otf_output otf_output;
724} __packed;
725
726struct dis_param {
727 struct param_control control;
728 struct param_otf_output otf_input;
729 struct param_otf_output otf_output;
730} __packed;
731
732struct tdnr_param {
733 struct param_control control;
734 struct param_otf_input otf_input;
735 struct param_3dnr_1stframe frame;
736 struct param_otf_output otf_output;
737 struct param_dma_output dma_output;
738} __packed;
739
740struct scalerp_param {
741 struct param_control control;
742 struct param_otf_input otf_input;
743 struct param_scaler_imageeffect effect;
744 struct param_scaler_input_crop input_crop;
745 struct param_scaler_output_crop output_crop;
746 struct param_scaler_rotation rotation;
747 struct param_scaler_flip flip;
748 struct param_otf_output otf_output;
749 struct param_dma_output dma_output;
750} __packed;
751
752struct fd_param {
753 struct param_control control;
754 struct param_otf_input otf_input;
755 struct param_dma_input dma_input;
756 struct param_fd_config config;
757} __packed;
758
759struct is_param_region {
760 struct global_param global;
761 struct sensor_param sensor;
762 struct buffer_param buf;
763 struct isp_param isp;
764 struct drc_param drc;
765 struct scalerc_param scalerc;
766 struct odc_param odc;
767 struct dis_param dis;
768 struct tdnr_param tdnr;
769 struct scalerp_param scalerp;
770 struct fd_param fd;
771} __packed;
772
773#define NUMBER_OF_GAMMA_CURVE_POINTS 32
774
775struct is_tune_sensor {
776 u32 exposure;
777 u32 analog_gain;
778 u32 frame_rate;
779 u32 actuator_position;
780};
781
782struct is_tune_gammacurve {
783 u32 num_pts_x[NUMBER_OF_GAMMA_CURVE_POINTS];
784 u32 num_pts_y_r[NUMBER_OF_GAMMA_CURVE_POINTS];
785 u32 num_pts_y_g[NUMBER_OF_GAMMA_CURVE_POINTS];
786 u32 num_pts_y_b[NUMBER_OF_GAMMA_CURVE_POINTS];
787};
788
789struct is_tune_isp {
790 /* Brightness level: range 0...100, default 7. */
791 u32 brightness_level;
792 /* Contrast level: range -127...127, default 0. */
793 s32 contrast_level;
794 /* Saturation level: range -127...127, default 0. */
795 s32 saturation_level;
796 s32 gamma_level;
797 struct is_tune_gammacurve gamma_curve[4];
798 /* Hue: range -127...127, default 0. */
799 s32 hue;
800 /* Sharpness blur: range -127...127, default 0. */
801 s32 sharpness_blur;
802 /* Despeckle : range -127~127, default : 0 */
803 s32 despeckle;
804 /* Edge color supression: range -127...127, default 0. */
805 s32 edge_color_supression;
806 /* Noise reduction: range -127...127, default 0. */
807 s32 noise_reduction;
808 /* (32 * 4 + 9) * 4 = 548 bytes */
809} __packed;
810
811struct is_tune_region {
812 struct is_tune_sensor sensor;
813 struct is_tune_isp isp;
814} __packed;
815
816struct rational {
817 u32 num;
818 u32 den;
819};
820
821struct srational {
822 s32 num;
823 s32 den;
824};
825
826#define FLASH_FIRED_SHIFT 0
827#define FLASH_NOT_FIRED 0
828#define FLASH_FIRED 1
829
830#define FLASH_STROBE_SHIFT 1
831#define FLASH_STROBE_NO_DETECTION 0
832#define FLASH_STROBE_RESERVED 1
833#define FLASH_STROBE_RETURN_LIGHT_NOT_DETECTED 2
834#define FLASH_STROBE_RETURN_LIGHT_DETECTED 3
835
836#define FLASH_MODE_SHIFT 3
837#define FLASH_MODE_UNKNOWN 0
838#define FLASH_MODE_COMPULSORY_FLASH_FIRING 1
839#define FLASH_MODE_COMPULSORY_FLASH_SUPPRESSION 2
840#define FLASH_MODE_AUTO_MODE 3
841
842#define FLASH_FUNCTION_SHIFT 5
843#define FLASH_FUNCTION_PRESENT 0
844#define FLASH_FUNCTION_NONE 1
845
846#define FLASH_RED_EYE_SHIFT 6
847#define FLASH_RED_EYE_DISABLED 0
848#define FLASH_RED_EYE_SUPPORTED 1
849
850enum apex_aperture_value {
851 F1_0 = 0,
852 F1_4 = 1,
853 F2_0 = 2,
854 F2_8 = 3,
855 F4_0 = 4,
856 F5_6 = 5,
857 F8_9 = 6,
858 F11_0 = 7,
859 F16_0 = 8,
860 F22_0 = 9,
861 F32_0 = 10,
862};
863
864struct exif_attribute {
865 struct rational exposure_time;
866 struct srational shutter_speed;
867 u32 iso_speed_rating;
868 u32 flash;
869 struct srational brightness;
870} __packed;
871
872struct is_frame_header {
873 u32 valid;
874 u32 bad_mark;
875 u32 captured;
876 u32 frame_number;
877 struct exif_attribute exif;
878} __packed;
879
880struct is_fd_rect {
881 u32 offset_x;
882 u32 offset_y;
883 u32 width;
884 u32 height;
885};
886
887struct is_face_marker {
888 u32 frame_number;
889 struct is_fd_rect face;
890 struct is_fd_rect left_eye;
891 struct is_fd_rect right_eye;
892 struct is_fd_rect mouth;
893 u32 roll_angle;
894 u32 yaw_angle;
895 u32 confidence;
896 s32 smile_level;
897 s32 blink_level;
898} __packed;
899
900#define MAX_FRAME_COUNT 8
901#define MAX_FRAME_COUNT_PREVIEW 4
902#define MAX_FRAME_COUNT_CAPTURE 1
903#define MAX_FACE_COUNT 16
904#define MAX_SHARED_COUNT 500
905
906struct is_region {
907 struct is_param_region parameter;
908 struct is_tune_region tune;
909 struct is_frame_header header[MAX_FRAME_COUNT];
910 struct is_face_marker face[MAX_FACE_COUNT];
911 u32 shared[MAX_SHARED_COUNT];
912} __packed;
913
914struct is_debug_frame_descriptor {
915 u32 sensor_frame_time;
916 u32 sensor_exposure_time;
917 s32 sensor_analog_gain;
918 /* monitor for AA */
919 u32 req_lei;
920
921 u32 next_next_lei_exp;
922 u32 next_next_lei_a_gain;
923 u32 next_next_lei_d_gain;
924 u32 next_next_lei_statlei;
925 u32 next_next_lei_lei;
926
927 u32 dummy0;
928};
929
930#define MAX_FRAMEDESCRIPTOR_CONTEXT_NUM (30*20) /* 600 frames */
931#define MAX_VERSION_DISPLAY_BUF 32
932
933struct is_share_region {
934 u32 frame_time;
935 u32 exposure_time;
936 s32 analog_gain;
937
938 u32 r_gain;
939 u32 g_gain;
940 u32 b_gain;
941
942 u32 af_position;
943 u32 af_status;
944 /* 0 : SIRC_ISP_CAMERA_AUTOFOCUSMESSAGE_NOMESSAGE */
945 /* 1 : SIRC_ISP_CAMERA_AUTOFOCUSMESSAGE_REACHED */
946 /* 2 : SIRC_ISP_CAMERA_AUTOFOCUSMESSAGE_UNABLETOREACH */
947 /* 3 : SIRC_ISP_CAMERA_AUTOFOCUSMESSAGE_LOST */
948 /* default : unknown */
949 u32 af_scene_type;
950
951 u32 frame_descp_onoff_control;
952 u32 frame_descp_update_done;
953 u32 frame_descp_idx;
954 u32 frame_descp_max_idx;
955 struct is_debug_frame_descriptor
956 dbg_frame_descp_ctx[MAX_FRAMEDESCRIPTOR_CONTEXT_NUM];
957
958 u32 chip_id;
959 u32 chip_rev_no;
960 u8 isp_fw_ver_no[MAX_VERSION_DISPLAY_BUF];
961 u8 isp_fw_ver_date[MAX_VERSION_DISPLAY_BUF];
962 u8 sirc_sdk_ver_no[MAX_VERSION_DISPLAY_BUF];
963 u8 sirc_sdk_rev_no[MAX_VERSION_DISPLAY_BUF];
964 u8 sirc_sdk_rev_date[MAX_VERSION_DISPLAY_BUF];
965} __packed;
966
967struct is_debug_control {
968 u32 write_point; /* 0~ 500KB boundary */
969 u32 assert_flag; /* 0: Not invoked, 1: Invoked */
970 u32 pabort_flag; /* 0: Not invoked, 1: Invoked */
971 u32 dabort_flag; /* 0: Not invoked, 1: Invoked */
972};
973
974struct sensor_open_extended {
975 u32 actuator_type;
976 u32 mclk;
977 u32 mipi_lane_num;
978 u32 mipi_speed;
979 /* Skip setfile loading when fast_open_sensor is not 0 */
980 u32 fast_open_sensor;
981 /* Activating sensor self calibration mode (6A3) */
982 u32 self_calibration_mode;
983 /* This field is to adjust I2c clock based on ACLK200 */
984 /* This value is varied in case of rev 0.2 */
985 u32 i2c_sclk;
986};
987
988struct fimc_is;
989
990int fimc_is_hw_get_sensor_max_framerate(struct fimc_is *is);
991void fimc_is_set_initial_params(struct fimc_is *is);
992unsigned int __get_pending_param_count(struct fimc_is *is);
993
994int __is_hw_update_params(struct fimc_is *is);
995void __is_get_frame_size(struct fimc_is *is, struct v4l2_mbus_framefmt *mf);
996void __is_set_frame_size(struct fimc_is *is, struct v4l2_mbus_framefmt *mf);
997void __is_set_sensor(struct fimc_is *is, int fps);
998void __is_set_isp_aa_ae(struct fimc_is *is);
999void __is_set_isp_flash(struct fimc_is *is, u32 cmd, u32 redeye);
1000void __is_set_isp_awb(struct fimc_is *is, u32 cmd, u32 val);
1001void __is_set_isp_effect(struct fimc_is *is, u32 cmd);
1002void __is_set_isp_iso(struct fimc_is *is, u32 cmd, u32 val);
1003void __is_set_isp_adjust(struct fimc_is *is, u32 cmd, u32 val);
1004void __is_set_isp_metering(struct fimc_is *is, u32 id, u32 val);
1005void __is_set_isp_afc(struct fimc_is *is, u32 cmd, u32 val);
1006void __is_set_drc_control(struct fimc_is *is, u32 val);
1007void __is_set_fd_control(struct fimc_is *is, u32 val);
1008void __is_set_fd_config_maxface(struct fimc_is *is, u32 val);
1009void __is_set_fd_config_rollangle(struct fimc_is *is, u32 val);
1010void __is_set_fd_config_yawangle(struct fimc_is *is, u32 val);
1011void __is_set_fd_config_smilemode(struct fimc_is *is, u32 val);
1012void __is_set_fd_config_blinkmode(struct fimc_is *is, u32 val);
1013void __is_set_fd_config_eyedetect(struct fimc_is *is, u32 val);
1014void __is_set_fd_config_mouthdetect(struct fimc_is *is, u32 val);
1015void __is_set_fd_config_orientation(struct fimc_is *is, u32 val);
1016void __is_set_fd_config_orientation_val(struct fimc_is *is, u32 val);
1017void __is_set_isp_aa_af_mode(struct fimc_is *is, int cmd);
1018void __is_set_isp_aa_af_start_stop(struct fimc_is *is, int cmd);
1019
1020#endif
diff --git a/drivers/media/platform/exynos4-is/fimc-is-regs.c b/drivers/media/platform/exynos4-is/fimc-is-regs.c
new file mode 100644
index 000000000000..b0ff67bc1b05
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-regs.c
@@ -0,0 +1,243 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
7 * Sylwester Nawrocki <s.nawrocki@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <linux/delay.h>
14
15#include "fimc-is.h"
16#include "fimc-is-command.h"
17#include "fimc-is-regs.h"
18#include "fimc-is-sensor.h"
19
20void fimc_is_fw_clear_irq1(struct fimc_is *is, unsigned int nr)
21{
22 mcuctl_write(1UL << nr, is, MCUCTL_REG_INTCR1);
23}
24
25void fimc_is_fw_clear_irq2(struct fimc_is *is)
26{
27 u32 cfg = mcuctl_read(is, MCUCTL_REG_INTSR2);
28 mcuctl_write(cfg, is, MCUCTL_REG_INTCR2);
29}
30
31void fimc_is_hw_set_intgr0_gd0(struct fimc_is *is)
32{
33 mcuctl_write(INTGR0_INTGD(0), is, MCUCTL_REG_INTGR0);
34}
35
36int fimc_is_hw_wait_intsr0_intsd0(struct fimc_is *is)
37{
38 unsigned int timeout = 2000;
39 u32 cfg, status;
40
41 cfg = mcuctl_read(is, MCUCTL_REG_INTSR0);
42 status = INTSR0_GET_INTSD(0, cfg);
43
44 while (status) {
45 cfg = mcuctl_read(is, MCUCTL_REG_INTSR0);
46 status = INTSR0_GET_INTSD(0, cfg);
47 if (timeout == 0) {
48 dev_warn(&is->pdev->dev, "%s timeout\n",
49 __func__);
50 return -ETIME;
51 }
52 timeout--;
53 udelay(1);
54 }
55 return 0;
56}
57
58int fimc_is_hw_wait_intmsr0_intmsd0(struct fimc_is *is)
59{
60 unsigned int timeout = 2000;
61 u32 cfg, status;
62
63 cfg = mcuctl_read(is, MCUCTL_REG_INTMSR0);
64 status = INTMSR0_GET_INTMSD(0, cfg);
65
66 while (status) {
67 cfg = mcuctl_read(is, MCUCTL_REG_INTMSR0);
68 status = INTMSR0_GET_INTMSD(0, cfg);
69 if (timeout == 0) {
70 dev_warn(&is->pdev->dev, "%s timeout\n",
71 __func__);
72 return -ETIME;
73 }
74 timeout--;
75 udelay(1);
76 }
77 return 0;
78}
79
80int fimc_is_hw_set_param(struct fimc_is *is)
81{
82 struct chain_config *config = &is->config[is->config_index];
83 unsigned int param_count = __get_pending_param_count(is);
84
85 fimc_is_hw_wait_intmsr0_intmsd0(is);
86
87 mcuctl_write(HIC_SET_PARAMETER, is, MCUCTL_REG_ISSR(0));
88 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
89 mcuctl_write(is->config_index, is, MCUCTL_REG_ISSR(2));
90
91 mcuctl_write(param_count, is, MCUCTL_REG_ISSR(3));
92 mcuctl_write(config->p_region_index1, is, MCUCTL_REG_ISSR(4));
93 mcuctl_write(config->p_region_index2, is, MCUCTL_REG_ISSR(5));
94
95 fimc_is_hw_set_intgr0_gd0(is);
96 return 0;
97}
98
99int fimc_is_hw_set_tune(struct fimc_is *is)
100{
101 fimc_is_hw_wait_intmsr0_intmsd0(is);
102
103 mcuctl_write(HIC_SET_TUNE, is, MCUCTL_REG_ISSR(0));
104 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
105 mcuctl_write(is->h2i_cmd.entry_id, is, MCUCTL_REG_ISSR(2));
106
107 fimc_is_hw_set_intgr0_gd0(is);
108 return 0;
109}
110
111#define FIMC_IS_MAX_PARAMS 4
112
113int fimc_is_hw_get_params(struct fimc_is *is, unsigned int num_args)
114{
115 int i;
116
117 if (num_args > FIMC_IS_MAX_PARAMS)
118 return -EINVAL;
119
120 is->i2h_cmd.num_args = num_args;
121
122 for (i = 0; i < FIMC_IS_MAX_PARAMS; i++) {
123 if (i < num_args)
124 is->i2h_cmd.args[i] = mcuctl_read(is,
125 MCUCTL_REG_ISSR(12 + i));
126 else
127 is->i2h_cmd.args[i] = 0;
128 }
129 return 0;
130}
131
132void fimc_is_hw_set_sensor_num(struct fimc_is *is)
133{
134 pr_debug("setting sensor index to: %d\n", is->sensor_index);
135
136 mcuctl_write(IH_REPLY_DONE, is, MCUCTL_REG_ISSR(0));
137 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
138 mcuctl_write(IHC_GET_SENSOR_NUM, is, MCUCTL_REG_ISSR(2));
139 mcuctl_write(FIMC_IS_SENSOR_NUM, is, MCUCTL_REG_ISSR(3));
140}
141
142void fimc_is_hw_close_sensor(struct fimc_is *is, unsigned int index)
143{
144 if (is->sensor_index != index)
145 return;
146
147 fimc_is_hw_wait_intmsr0_intmsd0(is);
148 mcuctl_write(HIC_CLOSE_SENSOR, is, MCUCTL_REG_ISSR(0));
149 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
150 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(2));
151 fimc_is_hw_set_intgr0_gd0(is);
152}
153
154void fimc_is_hw_get_setfile_addr(struct fimc_is *is)
155{
156 fimc_is_hw_wait_intmsr0_intmsd0(is);
157 mcuctl_write(HIC_GET_SET_FILE_ADDR, is, MCUCTL_REG_ISSR(0));
158 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
159 fimc_is_hw_set_intgr0_gd0(is);
160}
161
162void fimc_is_hw_load_setfile(struct fimc_is *is)
163{
164 fimc_is_hw_wait_intmsr0_intmsd0(is);
165 mcuctl_write(HIC_LOAD_SET_FILE, is, MCUCTL_REG_ISSR(0));
166 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
167 fimc_is_hw_set_intgr0_gd0(is);
168}
169
170int fimc_is_hw_change_mode(struct fimc_is *is)
171{
172 const u8 cmd[] = {
173 HIC_PREVIEW_STILL, HIC_PREVIEW_VIDEO,
174 HIC_CAPTURE_STILL, HIC_CAPTURE_VIDEO,
175 };
176
177 if (WARN_ON(is->config_index > ARRAY_SIZE(cmd)))
178 return -EINVAL;
179
180 mcuctl_write(cmd[is->config_index], is, MCUCTL_REG_ISSR(0));
181 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
182 mcuctl_write(is->setfile.sub_index, is, MCUCTL_REG_ISSR(2));
183 fimc_is_hw_set_intgr0_gd0(is);
184 return 0;
185}
186
187void fimc_is_hw_stream_on(struct fimc_is *is)
188{
189 fimc_is_hw_wait_intmsr0_intmsd0(is);
190 mcuctl_write(HIC_STREAM_ON, is, MCUCTL_REG_ISSR(0));
191 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
192 mcuctl_write(0, is, MCUCTL_REG_ISSR(2));
193 fimc_is_hw_set_intgr0_gd0(is);
194}
195
196void fimc_is_hw_stream_off(struct fimc_is *is)
197{
198 fimc_is_hw_wait_intmsr0_intmsd0(is);
199 mcuctl_write(HIC_STREAM_OFF, is, MCUCTL_REG_ISSR(0));
200 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
201 fimc_is_hw_set_intgr0_gd0(is);
202}
203
204void fimc_is_hw_subip_power_off(struct fimc_is *is)
205{
206 fimc_is_hw_wait_intmsr0_intmsd0(is);
207 mcuctl_write(HIC_POWER_DOWN, is, MCUCTL_REG_ISSR(0));
208 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
209 fimc_is_hw_set_intgr0_gd0(is);
210}
211
212int fimc_is_itf_s_param(struct fimc_is *is, bool update)
213{
214 int ret;
215
216 if (update)
217 __is_hw_update_params(is);
218
219 fimc_is_mem_barrier();
220
221 clear_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
222 fimc_is_hw_set_param(is);
223 ret = fimc_is_wait_event(is, IS_ST_BLOCK_CMD_CLEARED, 1,
224 FIMC_IS_CONFIG_TIMEOUT);
225 if (ret < 0)
226 dev_err(&is->pdev->dev, "%s() timeout\n", __func__);
227
228 return ret;
229}
230
231int fimc_is_itf_mode_change(struct fimc_is *is)
232{
233 int ret;
234
235 clear_bit(IS_ST_CHANGE_MODE, &is->state);
236 fimc_is_hw_change_mode(is);
237 ret = fimc_is_wait_event(is, IS_ST_CHANGE_MODE, 1,
238 FIMC_IS_CONFIG_TIMEOUT);
239 if (!ret < 0)
240 dev_err(&is->pdev->dev, "%s(): mode change (%d) timeout\n",
241 __func__, is->config_index);
242 return ret;
243}
diff --git a/drivers/media/platform/exynos4-is/fimc-is-regs.h b/drivers/media/platform/exynos4-is/fimc-is-regs.h
new file mode 100644
index 000000000000..5fa2fda46742
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-regs.h
@@ -0,0 +1,164 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com>
7 * Younghwan Joo <yhwan.joo@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef FIMC_IS_REG_H_
14#define FIMC_IS_REG_H_
15
16/* WDT_ISP register */
17#define REG_WDT_ISP 0x00170000
18
19/* MCUCTL registers base offset */
20#define MCUCTL_BASE 0x00180000
21
22/* MCU Controller Register */
23#define MCUCTL_REG_MCUCTRL (MCUCTL_BASE + 0x00)
24#define MCUCTRL_MSWRST (1 << 0)
25
26/* Boot Base Offset Address Register */
27#define MCUCTL_REG_BBOAR (MCUCTL_BASE + 0x04)
28
29/* Interrupt Generation Register 0 from Host CPU to VIC */
30#define MCUCTL_REG_INTGR0 (MCUCTL_BASE + 0x08)
31/* __n = 0...9 */
32#define INTGR0_INTGC(__n) (1 << ((__n) + 16))
33/* __n = 0...5 */
34#define INTGR0_INTGD(__n) (1 << (__n))
35
36/* Interrupt Clear Register 0 from Host CPU to VIC */
37#define MCUCTL_REG_INTCR0 (MCUCTL_BASE + 0x0c)
38/* __n = 0...9 */
39#define INTCR0_INTGC(__n) (1 << ((__n) + 16))
40/* __n = 0...5 */
41#define INTCR0_INTCD(__n) (1 << ((__n) + 16))
42
43/* Interrupt Mask Register 0 from Host CPU to VIC */
44#define MCUCTL_REG_INTMR0 (MCUCTL_BASE + 0x10)
45/* __n = 0...9 */
46#define INTMR0_INTMC(__n) (1 << ((__n) + 16))
47/* __n = 0...5 */
48#define INTMR0_INTMD(__n) (1 << (__n))
49
50/* Interrupt Status Register 0 from Host CPU to VIC */
51#define MCUCTL_REG_INTSR0 (MCUCTL_BASE + 0x14)
52/* __n (bit number) = 0...4 */
53#define INTSR0_GET_INTSD(x, __n) (((x) >> (__n)) & 0x1)
54/* __n (bit number) = 0...9 */
55#define INTSR0_GET_INTSC(x, __n) (((x) >> ((__n) + 16)) & 0x1)
56
57/* Interrupt Mask Status Register 0 from Host CPU to VIC */
58#define MCUCTL_REG_INTMSR0 (MCUCTL_BASE + 0x18)
59/* __n (bit number) = 0...4 */
60#define INTMSR0_GET_INTMSD(x, __n) (((x) >> (__n)) & 0x1)
61/* __n (bit number) = 0...9 */
62#define INTMSR0_GET_INTMSC(x, __n) (((x) >> ((__n) + 16)) & 0x1)
63
64/* Interrupt Generation Register 1 from ISP CPU to Host IC */
65#define MCUCTL_REG_INTGR1 (MCUCTL_BASE + 0x1c)
66/* __n = 0...9 */
67#define INTGR1_INTGC(__n) (1 << (__n))
68
69/* Interrupt Clear Register 1 from ISP CPU to Host IC */
70#define MCUCTL_REG_INTCR1 (MCUCTL_BASE + 0x20)
71/* __n = 0...9 */
72#define INTCR1_INTCC(__n) (1 << (__n))
73
74/* Interrupt Mask Register 1 from ISP CPU to Host IC */
75#define MCUCTL_REG_INTMR1 (MCUCTL_BASE + 0x24)
76/* __n = 0...9 */
77#define INTMR1_INTMC(__n) (1 << (__n))
78
79/* Interrupt Status Register 1 from ISP CPU to Host IC */
80#define MCUCTL_REG_INTSR1 (MCUCTL_BASE + 0x28)
81/* Interrupt Mask Status Register 1 from ISP CPU to Host IC */
82#define MCUCTL_REG_INTMSR1 (MCUCTL_BASE + 0x2c)
83
84/* Interrupt Clear Register 2 from ISP BLK's interrupts to Host IC */
85#define MCUCTL_REG_INTCR2 (MCUCTL_BASE + 0x30)
86/* __n = 0...5 */
87#define INTCR2_INTCC(__n) (1 << ((__n) + 16))
88
89/* Interrupt Mask Register 2 from ISP BLK's interrupts to Host IC */
90#define MCUCTL_REG_INTMR2 (MCUCTL_BASE + 0x34)
91/* __n = 0...25 */
92#define INTMR2_INTMCIS(__n) (1 << (__n))
93
94/* Interrupt Status Register 2 from ISP BLK's interrupts to Host IC */
95#define MCUCTL_REG_INTSR2 (MCUCTL_BASE + 0x38)
96/* Interrupt Mask Status Register 2 from ISP BLK's interrupts to Host IC */
97#define MCUCTL_REG_INTMSR2 (MCUCTL_BASE + 0x3c)
98
99/* General Purpose Output Control Register (0~17) */
100#define MCUCTL_REG_GPOCTLR (MCUCTL_BASE + 0x40)
101/* __n = 0...17 */
102#define GPOCTLR_GPOG(__n) (1 << (__n))
103
104/* General Purpose Pad Output Enable Register (0~17) */
105#define MCUCTL_REG_GPOENCTLR (MCUCTL_BASE + 0x44)
106/* __n = 0...17 */
107#define GPOENCTLR_GPOEN(__n) (1 << (__n))
108
109/* General Purpose Input Control Register (0~17) */
110#define MCUCTL_REG_GPICTLR (MCUCTL_BASE + 0x48)
111
112/* Shared registers between ISP CPU and the host CPU - ISSRxx */
113
114/* ISSR(1): Command Host -> IS */
115/* ISSR(1): Sensor ID for Command, ISSR2...5 = Parameter 1...4 */
116
117/* ISSR(10): Reply IS -> Host */
118/* ISSR(11): Sensor ID for Reply, ISSR12...15 = Parameter 1...4 */
119
120/* ISSR(20): ISP_FRAME_DONE : SENSOR ID */
121/* ISSR(21): ISP_FRAME_DONE : PARAMETER 1 */
122
123/* ISSR(24): SCALERC_FRAME_DONE : SENSOR ID */
124/* ISSR(25): SCALERC_FRAME_DONE : PARAMETER 1 */
125
126/* ISSR(28): 3DNR_FRAME_DONE : SENSOR ID */
127/* ISSR(29): 3DNR_FRAME_DONE : PARAMETER 1 */
128
129/* ISSR(32): SCALERP_FRAME_DONE : SENSOR ID */
130/* ISSR(33): SCALERP_FRAME_DONE : PARAMETER 1 */
131
132/* __n = 0...63 */
133#define MCUCTL_REG_ISSR(__n) (MCUCTL_BASE + 0x80 + ((__n) * 4))
134
135/* PMU ISP register offsets */
136#define REG_CMU_RESET_ISP_SYS_PWR_REG 0x1174
137#define REG_CMU_SYSCLK_ISP_SYS_PWR_REG 0x13b8
138#define REG_PMU_ISP_ARM_SYS 0x1050
139#define REG_PMU_ISP_ARM_CONFIGURATION 0x2280
140#define REG_PMU_ISP_ARM_STATUS 0x2284
141#define REG_PMU_ISP_ARM_OPTION 0x2288
142
143void fimc_is_fw_clear_irq1(struct fimc_is *is, unsigned int bit);
144void fimc_is_fw_clear_irq2(struct fimc_is *is);
145int fimc_is_hw_get_params(struct fimc_is *is, unsigned int num);
146
147void fimc_is_hw_set_intgr0_gd0(struct fimc_is *is);
148int fimc_is_hw_wait_intsr0_intsd0(struct fimc_is *is);
149int fimc_is_hw_wait_intmsr0_intmsd0(struct fimc_is *is);
150void fimc_is_hw_set_sensor_num(struct fimc_is *is);
151void fimc_is_hw_stream_on(struct fimc_is *is);
152void fimc_is_hw_stream_off(struct fimc_is *is);
153int fimc_is_hw_set_param(struct fimc_is *is);
154int fimc_is_hw_change_mode(struct fimc_is *is);
155
156void fimc_is_hw_close_sensor(struct fimc_is *is, unsigned int index);
157void fimc_is_hw_get_setfile_addr(struct fimc_is *is);
158void fimc_is_hw_load_setfile(struct fimc_is *is);
159void fimc_is_hw_subip_power_off(struct fimc_is *is);
160
161int fimc_is_itf_s_param(struct fimc_is *is, bool update);
162int fimc_is_itf_mode_change(struct fimc_is *is);
163
164#endif /* FIMC_IS_REG_H_ */
diff --git a/drivers/media/platform/exynos4-is/fimc-is-sensor.c b/drivers/media/platform/exynos4-is/fimc-is-sensor.c
new file mode 100644
index 000000000000..6647421e5d3a
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-sensor.c
@@ -0,0 +1,305 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Author: Sylwester Nawrocki <s.nawrocki@samsung.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 version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/delay.h>
13#include <linux/device.h>
14#include <linux/errno.h>
15#include <linux/gpio.h>
16#include <linux/i2c.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/of_gpio.h>
20#include <linux/pm_runtime.h>
21#include <linux/regulator/consumer.h>
22#include <linux/slab.h>
23#include <media/v4l2-subdev.h>
24
25#include "fimc-is.h"
26#include "fimc-is-sensor.h"
27
28#define DRIVER_NAME "FIMC-IS-SENSOR"
29
30static const char * const sensor_supply_names[] = {
31 "svdda",
32 "svddio",
33};
34
35static const struct v4l2_mbus_framefmt fimc_is_sensor_formats[] = {
36 {
37 .code = V4L2_MBUS_FMT_SGRBG10_1X10,
38 .colorspace = V4L2_COLORSPACE_SRGB,
39 .field = V4L2_FIELD_NONE,
40 }
41};
42
43static const struct v4l2_mbus_framefmt *find_sensor_format(
44 struct v4l2_mbus_framefmt *mf)
45{
46 int i;
47
48 for (i = 0; i < ARRAY_SIZE(fimc_is_sensor_formats); i++)
49 if (mf->code == fimc_is_sensor_formats[i].code)
50 return &fimc_is_sensor_formats[i];
51
52 return &fimc_is_sensor_formats[0];
53}
54
55static int fimc_is_sensor_enum_mbus_code(struct v4l2_subdev *sd,
56 struct v4l2_subdev_fh *fh,
57 struct v4l2_subdev_mbus_code_enum *code)
58{
59 if (code->index >= ARRAY_SIZE(fimc_is_sensor_formats))
60 return -EINVAL;
61
62 code->code = fimc_is_sensor_formats[code->index].code;
63 return 0;
64}
65
66static void fimc_is_sensor_try_format(struct fimc_is_sensor *sensor,
67 struct v4l2_mbus_framefmt *mf)
68{
69 const struct sensor_drv_data *dd = sensor->drvdata;
70 const struct v4l2_mbus_framefmt *fmt;
71
72 fmt = find_sensor_format(mf);
73 mf->code = fmt->code;
74 v4l_bound_align_image(&mf->width, 16 + 8, dd->width, 0,
75 &mf->height, 12 + 8, dd->height, 0, 0);
76}
77
78static struct v4l2_mbus_framefmt *__fimc_is_sensor_get_format(
79 struct fimc_is_sensor *sensor, struct v4l2_subdev_fh *fh,
80 u32 pad, enum v4l2_subdev_format_whence which)
81{
82 if (which == V4L2_SUBDEV_FORMAT_TRY)
83 return fh ? v4l2_subdev_get_try_format(fh, pad) : NULL;
84
85 return &sensor->format;
86}
87
88static int fimc_is_sensor_set_fmt(struct v4l2_subdev *sd,
89 struct v4l2_subdev_fh *fh,
90 struct v4l2_subdev_format *fmt)
91{
92 struct fimc_is_sensor *sensor = sd_to_fimc_is_sensor(sd);
93 struct v4l2_mbus_framefmt *mf;
94
95 fimc_is_sensor_try_format(sensor, &fmt->format);
96
97 mf = __fimc_is_sensor_get_format(sensor, fh, fmt->pad, fmt->which);
98 if (mf) {
99 mutex_lock(&sensor->lock);
100 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
101 *mf = fmt->format;
102 mutex_unlock(&sensor->lock);
103 }
104 return 0;
105}
106
107static int fimc_is_sensor_get_fmt(struct v4l2_subdev *sd,
108 struct v4l2_subdev_fh *fh,
109 struct v4l2_subdev_format *fmt)
110{
111 struct fimc_is_sensor *sensor = sd_to_fimc_is_sensor(sd);
112 struct v4l2_mbus_framefmt *mf;
113
114 mf = __fimc_is_sensor_get_format(sensor, fh, fmt->pad, fmt->which);
115
116 mutex_lock(&sensor->lock);
117 fmt->format = *mf;
118 mutex_unlock(&sensor->lock);
119 return 0;
120}
121
122static struct v4l2_subdev_pad_ops fimc_is_sensor_pad_ops = {
123 .enum_mbus_code = fimc_is_sensor_enum_mbus_code,
124 .get_fmt = fimc_is_sensor_get_fmt,
125 .set_fmt = fimc_is_sensor_set_fmt,
126};
127
128static int fimc_is_sensor_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
129{
130 struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(fh, 0);
131
132 *format = fimc_is_sensor_formats[0];
133 format->width = FIMC_IS_SENSOR_DEF_PIX_WIDTH;
134 format->height = FIMC_IS_SENSOR_DEF_PIX_HEIGHT;
135
136 return 0;
137}
138
139static const struct v4l2_subdev_internal_ops fimc_is_sensor_sd_internal_ops = {
140 .open = fimc_is_sensor_open,
141};
142
143static int fimc_is_sensor_s_power(struct v4l2_subdev *sd, int on)
144{
145 struct fimc_is_sensor *sensor = sd_to_fimc_is_sensor(sd);
146 int gpio = sensor->gpio_reset;
147 int ret;
148
149 if (on) {
150 ret = pm_runtime_get(sensor->dev);
151 if (ret < 0)
152 return ret;
153
154 ret = regulator_bulk_enable(SENSOR_NUM_SUPPLIES,
155 sensor->supplies);
156 if (ret < 0) {
157 pm_runtime_put(sensor->dev);
158 return ret;
159 }
160 if (gpio_is_valid(gpio)) {
161 gpio_set_value(gpio, 1);
162 usleep_range(600, 800);
163 gpio_set_value(gpio, 0);
164 usleep_range(10000, 11000);
165 gpio_set_value(gpio, 1);
166 }
167
168 /* A delay needed for the sensor initialization. */
169 msleep(20);
170 } else {
171 if (gpio_is_valid(gpio))
172 gpio_set_value(gpio, 0);
173
174 ret = regulator_bulk_disable(SENSOR_NUM_SUPPLIES,
175 sensor->supplies);
176 if (!ret)
177 pm_runtime_put(sensor->dev);
178 }
179
180 pr_info("%s:%d: on: %d, ret: %d\n", __func__, __LINE__, on, ret);
181
182 return ret;
183}
184
185static struct v4l2_subdev_core_ops fimc_is_sensor_core_ops = {
186 .s_power = fimc_is_sensor_s_power,
187};
188
189static struct v4l2_subdev_ops fimc_is_sensor_subdev_ops = {
190 .core = &fimc_is_sensor_core_ops,
191 .pad = &fimc_is_sensor_pad_ops,
192};
193
194static const struct of_device_id fimc_is_sensor_of_match[];
195
196static int fimc_is_sensor_probe(struct i2c_client *client,
197 const struct i2c_device_id *id)
198{
199 struct device *dev = &client->dev;
200 struct fimc_is_sensor *sensor;
201 const struct of_device_id *of_id;
202 struct v4l2_subdev *sd;
203 int gpio, i, ret;
204
205 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
206 if (!sensor)
207 return -ENOMEM;
208
209 mutex_init(&sensor->lock);
210 sensor->gpio_reset = -EINVAL;
211
212 gpio = of_get_gpio_flags(dev->of_node, 0, NULL);
213 if (gpio_is_valid(gpio)) {
214 ret = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_LOW,
215 DRIVER_NAME);
216 if (ret < 0)
217 return ret;
218 }
219 sensor->gpio_reset = gpio;
220
221 for (i = 0; i < SENSOR_NUM_SUPPLIES; i++)
222 sensor->supplies[i].supply = sensor_supply_names[i];
223
224 ret = devm_regulator_bulk_get(&client->dev, SENSOR_NUM_SUPPLIES,
225 sensor->supplies);
226 if (ret < 0)
227 return ret;
228
229 of_id = of_match_node(fimc_is_sensor_of_match, dev->of_node);
230 if (!of_id)
231 return -ENODEV;
232
233 sensor->drvdata = of_id->data;
234 sensor->dev = dev;
235
236 sd = &sensor->subdev;
237 v4l2_i2c_subdev_init(sd, client, &fimc_is_sensor_subdev_ops);
238 snprintf(sd->name, sizeof(sd->name), sensor->drvdata->subdev_name);
239 sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
240
241 sensor->format.code = fimc_is_sensor_formats[0].code;
242 sensor->format.width = FIMC_IS_SENSOR_DEF_PIX_WIDTH;
243 sensor->format.height = FIMC_IS_SENSOR_DEF_PIX_HEIGHT;
244
245 sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
246 ret = media_entity_init(&sd->entity, 1, &sensor->pad, 0);
247 if (ret < 0)
248 return ret;
249
250 pm_runtime_no_callbacks(dev);
251 pm_runtime_enable(dev);
252
253 return ret;
254}
255
256static int fimc_is_sensor_remove(struct i2c_client *client)
257{
258 struct v4l2_subdev *sd = i2c_get_clientdata(client);
259 media_entity_cleanup(&sd->entity);
260 return 0;
261}
262
263static const struct i2c_device_id fimc_is_sensor_ids[] = {
264 { }
265};
266
267static const struct sensor_drv_data s5k6a3_drvdata = {
268 .id = FIMC_IS_SENSOR_ID_S5K6A3,
269 .subdev_name = "S5K6A3",
270 .width = S5K6A3_SENSOR_WIDTH,
271 .height = S5K6A3_SENSOR_HEIGHT,
272};
273
274static const struct of_device_id fimc_is_sensor_of_match[] = {
275 {
276 .compatible = "samsung,s5k6a3",
277 .data = &s5k6a3_drvdata,
278 },
279 { }
280};
281
282static struct i2c_driver fimc_is_sensor_driver = {
283 .driver = {
284 .of_match_table = fimc_is_sensor_of_match,
285 .name = DRIVER_NAME,
286 .owner = THIS_MODULE,
287 },
288 .probe = fimc_is_sensor_probe,
289 .remove = fimc_is_sensor_remove,
290 .id_table = fimc_is_sensor_ids,
291};
292
293int fimc_is_register_sensor_driver(void)
294{
295 return i2c_add_driver(&fimc_is_sensor_driver);
296}
297
298void fimc_is_unregister_sensor_driver(void)
299{
300 i2c_del_driver(&fimc_is_sensor_driver);
301}
302
303MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
304MODULE_DESCRIPTION("Exynos4x12 FIMC-IS image sensor subdev driver");
305MODULE_LICENSE("GPL");
diff --git a/drivers/media/platform/exynos4-is/fimc-is-sensor.h b/drivers/media/platform/exynos4-is/fimc-is-sensor.h
new file mode 100644
index 000000000000..6036d49a6c68
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is-sensor.h
@@ -0,0 +1,89 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com>
7 * Younghwan Joo <yhwan.joo@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef FIMC_IS_SENSOR_H_
14#define FIMC_IS_SENSOR_H_
15
16#include <linux/clk.h>
17#include <linux/device.h>
18#include <linux/kernel.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/consumer.h>
21#include <linux/videodev2.h>
22#include <media/v4l2-subdev.h>
23
24#define FIMC_IS_SENSOR_OPEN_TIMEOUT 2000 /* ms */
25
26#define FIMC_IS_SENSOR_DEF_PIX_WIDTH 1296
27#define FIMC_IS_SENSOR_DEF_PIX_HEIGHT 732
28
29#define S5K6A3_SENSOR_WIDTH 1392
30#define S5K6A3_SENSOR_HEIGHT 1392
31
32#define SENSOR_NUM_SUPPLIES 2
33
34enum fimc_is_sensor_id {
35 FIMC_IS_SENSOR_ID_S5K3H2 = 1,
36 FIMC_IS_SENSOR_ID_S5K6A3,
37 FIMC_IS_SENSOR_ID_S5K4E5,
38 FIMC_IS_SENSOR_ID_S5K3H7,
39 FIMC_IS_SENSOR_ID_CUSTOM,
40 FIMC_IS_SENSOR_ID_END
41};
42
43#define IS_SENSOR_CTRL_BUS_I2C0 0
44#define IS_SENSOR_CTRL_BUS_I2C1 1
45
46struct sensor_drv_data {
47 enum fimc_is_sensor_id id;
48 const char * const subdev_name;
49 unsigned int width;
50 unsigned int height;
51};
52
53/**
54 * struct fimc_is_sensor - fimc-is sensor data structure
55 * @dev: pointer to this I2C client device structure
56 * @subdev: the image sensor's v4l2 subdev
57 * @pad: subdev media source pad
58 * @supplies: image sensor's voltage regulator supplies
59 * @gpio_reset: GPIO connected to the sensor's reset pin
60 * @drvdata: a pointer to the sensor's parameters data structure
61 * @i2c_bus: ISP I2C bus index (0...1)
62 * @test_pattern: true to enable video test pattern
63 * @lock: mutex protecting the structure's members below
64 * @format: media bus format at the sensor's source pad
65 */
66struct fimc_is_sensor {
67 struct device *dev;
68 struct v4l2_subdev subdev;
69 struct media_pad pad;
70 struct regulator_bulk_data supplies[SENSOR_NUM_SUPPLIES];
71 int gpio_reset;
72 const struct sensor_drv_data *drvdata;
73 unsigned int i2c_bus;
74 bool test_pattern;
75
76 struct mutex lock;
77 struct v4l2_mbus_framefmt format;
78};
79
80static inline
81struct fimc_is_sensor *sd_to_fimc_is_sensor(struct v4l2_subdev *sd)
82{
83 return container_of(sd, struct fimc_is_sensor, subdev);
84}
85
86int fimc_is_register_sensor_driver(void);
87void fimc_is_unregister_sensor_driver(void);
88
89#endif /* FIMC_IS_SENSOR_H_ */
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
new file mode 100644
index 000000000000..47c6363d04e2
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -0,0 +1,1007 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com>
7 * Younghwan Joo <yhwan.joo@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__
14
15#include <linux/device.h>
16#include <linux/debugfs.h>
17#include <linux/delay.h>
18#include <linux/dma-contiguous.h>
19#include <linux/errno.h>
20#include <linux/firmware.h>
21#include <linux/interrupt.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/of_i2c.h>
25#include <linux/of_irq.h>
26#include <linux/of_address.h>
27#include <linux/of_platform.h>
28#include <linux/platform_device.h>
29#include <linux/pm_runtime.h>
30#include <linux/slab.h>
31#include <linux/types.h>
32#include <linux/videodev2.h>
33#include <media/v4l2-of.h>
34#include <media/videobuf2-dma-contig.h>
35
36#include "media-dev.h"
37#include "fimc-is.h"
38#include "fimc-is-command.h"
39#include "fimc-is-errno.h"
40#include "fimc-is-i2c.h"
41#include "fimc-is-param.h"
42#include "fimc-is-regs.h"
43
44
45static char *fimc_is_clocks[ISS_CLKS_MAX] = {
46 [ISS_CLK_PPMUISPX] = "ppmuispx",
47 [ISS_CLK_PPMUISPMX] = "ppmuispmx",
48 [ISS_CLK_LITE0] = "lite0",
49 [ISS_CLK_LITE1] = "lite1",
50 [ISS_CLK_MPLL] = "mpll",
51 [ISS_CLK_SYSREG] = "sysreg",
52 [ISS_CLK_ISP] = "isp",
53 [ISS_CLK_DRC] = "drc",
54 [ISS_CLK_FD] = "fd",
55 [ISS_CLK_MCUISP] = "mcuisp",
56 [ISS_CLK_UART] = "uart",
57 [ISS_CLK_ISP_DIV0] = "ispdiv0",
58 [ISS_CLK_ISP_DIV1] = "ispdiv1",
59 [ISS_CLK_MCUISP_DIV0] = "mcuispdiv0",
60 [ISS_CLK_MCUISP_DIV1] = "mcuispdiv1",
61 [ISS_CLK_ACLK200] = "aclk200",
62 [ISS_CLK_ACLK200_DIV] = "div_aclk200",
63 [ISS_CLK_ACLK400MCUISP] = "aclk400mcuisp",
64 [ISS_CLK_ACLK400MCUISP_DIV] = "div_aclk400mcuisp",
65};
66
67static void fimc_is_put_clocks(struct fimc_is *is)
68{
69 int i;
70
71 for (i = 0; i < ISS_CLKS_MAX; i++) {
72 if (IS_ERR(is->clocks[i]))
73 continue;
74 clk_unprepare(is->clocks[i]);
75 clk_put(is->clocks[i]);
76 is->clocks[i] = ERR_PTR(-EINVAL);
77 }
78}
79
80static int fimc_is_get_clocks(struct fimc_is *is)
81{
82 int i, ret;
83
84 for (i = 0; i < ISS_CLKS_MAX; i++)
85 is->clocks[i] = ERR_PTR(-EINVAL);
86
87 for (i = 0; i < ISS_CLKS_MAX; i++) {
88 is->clocks[i] = clk_get(&is->pdev->dev, fimc_is_clocks[i]);
89 if (IS_ERR(is->clocks[i])) {
90 ret = PTR_ERR(is->clocks[i]);
91 goto err;
92 }
93 ret = clk_prepare(is->clocks[i]);
94 if (ret < 0) {
95 clk_put(is->clocks[i]);
96 is->clocks[i] = ERR_PTR(-EINVAL);
97 goto err;
98 }
99 }
100
101 return 0;
102err:
103 fimc_is_put_clocks(is);
104 dev_err(&is->pdev->dev, "failed to get clock: %s\n",
105 fimc_is_clocks[i]);
106 return -ENXIO;
107}
108
109static int fimc_is_setup_clocks(struct fimc_is *is)
110{
111 int ret;
112
113 ret = clk_set_parent(is->clocks[ISS_CLK_ACLK200],
114 is->clocks[ISS_CLK_ACLK200_DIV]);
115 if (ret < 0)
116 return ret;
117
118 ret = clk_set_parent(is->clocks[ISS_CLK_ACLK400MCUISP],
119 is->clocks[ISS_CLK_ACLK400MCUISP_DIV]);
120 if (ret < 0)
121 return ret;
122
123 ret = clk_set_rate(is->clocks[ISS_CLK_ISP_DIV0], ACLK_AXI_FREQUENCY);
124 if (ret < 0)
125 return ret;
126
127 ret = clk_set_rate(is->clocks[ISS_CLK_ISP_DIV1], ACLK_AXI_FREQUENCY);
128 if (ret < 0)
129 return ret;
130
131 ret = clk_set_rate(is->clocks[ISS_CLK_MCUISP_DIV0],
132 ATCLK_MCUISP_FREQUENCY);
133 if (ret < 0)
134 return ret;
135
136 return clk_set_rate(is->clocks[ISS_CLK_MCUISP_DIV1],
137 ATCLK_MCUISP_FREQUENCY);
138}
139
140int fimc_is_enable_clocks(struct fimc_is *is)
141{
142 int i, ret;
143
144 for (i = 0; i < ISS_GATE_CLKS_MAX; i++) {
145 if (IS_ERR(is->clocks[i]))
146 continue;
147 ret = clk_enable(is->clocks[i]);
148 if (ret < 0) {
149 dev_err(&is->pdev->dev, "clock %s enable failed\n",
150 fimc_is_clocks[i]);
151 for (--i; i >= 0; i--)
152 clk_disable(is->clocks[i]);
153 return ret;
154 }
155 pr_debug("enabled clock: %s\n", fimc_is_clocks[i]);
156 }
157 return 0;
158}
159
160void fimc_is_disable_clocks(struct fimc_is *is)
161{
162 int i;
163
164 for (i = 0; i < ISS_GATE_CLKS_MAX; i++) {
165 if (!IS_ERR(is->clocks[i])) {
166 clk_disable(is->clocks[i]);
167 pr_debug("disabled clock: %s\n", fimc_is_clocks[i]);
168 }
169 }
170}
171
172static int fimc_is_parse_sensor_config(struct fimc_is_sensor *sensor,
173 struct device_node *np)
174{
175 u32 tmp = 0;
176 int ret;
177
178 np = v4l2_of_get_next_endpoint(np, NULL);
179 if (!np)
180 return -ENXIO;
181 np = v4l2_of_get_remote_port(np);
182 if (!np)
183 return -ENXIO;
184
185 /* Use MIPI-CSIS channel id to determine the ISP I2C bus index. */
186 ret = of_property_read_u32(np, "reg", &tmp);
187 sensor->i2c_bus = tmp - FIMC_INPUT_MIPI_CSI2_0;
188
189 return ret;
190}
191
192static int fimc_is_register_subdevs(struct fimc_is *is)
193{
194 struct device_node *adapter, *child;
195 int ret;
196
197 ret = fimc_isp_subdev_create(&is->isp);
198 if (ret < 0)
199 return ret;
200
201 for_each_compatible_node(adapter, NULL, FIMC_IS_I2C_COMPATIBLE) {
202 if (!of_find_device_by_node(adapter)) {
203 of_node_put(adapter);
204 return -EPROBE_DEFER;
205 }
206
207 for_each_available_child_of_node(adapter, child) {
208 struct i2c_client *client;
209 struct v4l2_subdev *sd;
210
211 client = of_find_i2c_device_by_node(child);
212 if (!client)
213 goto e_retry;
214
215 sd = i2c_get_clientdata(client);
216 if (!sd)
217 goto e_retry;
218
219 /* FIXME: Add support for multiple sensors. */
220 if (WARN_ON(is->sensor))
221 continue;
222
223 is->sensor = sd_to_fimc_is_sensor(sd);
224
225 if (fimc_is_parse_sensor_config(is->sensor, child)) {
226 dev_warn(&is->pdev->dev, "DT parse error: %s\n",
227 child->full_name);
228 }
229 pr_debug("%s(): registered subdev: %p\n",
230 __func__, sd->name);
231 }
232 }
233 return 0;
234
235e_retry:
236 of_node_put(child);
237 return -EPROBE_DEFER;
238}
239
240static int fimc_is_unregister_subdevs(struct fimc_is *is)
241{
242 fimc_isp_subdev_destroy(&is->isp);
243 is->sensor = NULL;
244 return 0;
245}
246
247static int fimc_is_load_setfile(struct fimc_is *is, char *file_name)
248{
249 const struct firmware *fw;
250 void *buf;
251 int ret;
252
253 ret = request_firmware(&fw, file_name, &is->pdev->dev);
254 if (ret < 0) {
255 dev_err(&is->pdev->dev, "firmware request failed (%d)\n", ret);
256 return ret;
257 }
258 buf = is->memory.vaddr + is->setfile.base;
259 memcpy(buf, fw->data, fw->size);
260 fimc_is_mem_barrier();
261 is->setfile.size = fw->size;
262
263 pr_debug("mem vaddr: %p, setfile buf: %p\n", is->memory.vaddr, buf);
264
265 memcpy(is->fw.setfile_info,
266 fw->data + fw->size - FIMC_IS_SETFILE_INFO_LEN,
267 FIMC_IS_SETFILE_INFO_LEN - 1);
268
269 is->fw.setfile_info[FIMC_IS_SETFILE_INFO_LEN - 1] = '\0';
270 is->setfile.state = 1;
271
272 pr_debug("FIMC-IS setfile loaded: base: %#x, size: %zu B\n",
273 is->setfile.base, fw->size);
274
275 release_firmware(fw);
276 return ret;
277}
278
279int fimc_is_cpu_set_power(struct fimc_is *is, int on)
280{
281 unsigned int timeout = FIMC_IS_POWER_ON_TIMEOUT;
282
283 if (on) {
284 /* Disable watchdog */
285 mcuctl_write(0, is, REG_WDT_ISP);
286
287 /* Cortex-A5 start address setting */
288 mcuctl_write(is->memory.paddr, is, MCUCTL_REG_BBOAR);
289
290 /* Enable and start Cortex-A5 */
291 pmuisp_write(0x18000, is, REG_PMU_ISP_ARM_OPTION);
292 pmuisp_write(0x1, is, REG_PMU_ISP_ARM_CONFIGURATION);
293 } else {
294 /* A5 power off */
295 pmuisp_write(0x10000, is, REG_PMU_ISP_ARM_OPTION);
296 pmuisp_write(0x0, is, REG_PMU_ISP_ARM_CONFIGURATION);
297
298 while (pmuisp_read(is, REG_PMU_ISP_ARM_STATUS) & 1) {
299 if (timeout == 0)
300 return -ETIME;
301 timeout--;
302 udelay(1);
303 }
304 }
305
306 return 0;
307}
308
309/* Wait until @bit of @is->state is set to @state in the interrupt handler. */
310int fimc_is_wait_event(struct fimc_is *is, unsigned long bit,
311 unsigned int state, unsigned int timeout)
312{
313
314 int ret = wait_event_timeout(is->irq_queue,
315 !state ^ test_bit(bit, &is->state),
316 timeout);
317 if (ret == 0) {
318 dev_WARN(&is->pdev->dev, "%s() timed out\n", __func__);
319 return -ETIME;
320 }
321 return 0;
322}
323
324int fimc_is_start_firmware(struct fimc_is *is)
325{
326 struct device *dev = &is->pdev->dev;
327 int ret;
328
329 memcpy(is->memory.vaddr, is->fw.f_w->data, is->fw.f_w->size);
330 wmb();
331
332 ret = fimc_is_cpu_set_power(is, 1);
333 if (ret < 0)
334 return ret;
335
336 ret = fimc_is_wait_event(is, IS_ST_A5_PWR_ON, 1,
337 msecs_to_jiffies(FIMC_IS_FW_LOAD_TIMEOUT));
338 if (ret < 0)
339 dev_err(dev, "FIMC-IS CPU power on failed\n");
340
341 return ret;
342}
343
344/* Allocate working memory for the FIMC-IS CPU. */
345static int fimc_is_alloc_cpu_memory(struct fimc_is *is)
346{
347 struct device *dev = &is->pdev->dev;
348
349 is->memory.vaddr = dma_alloc_coherent(dev, FIMC_IS_CPU_MEM_SIZE,
350 &is->memory.paddr, GFP_KERNEL);
351 if (is->memory.vaddr == NULL)
352 return -ENOMEM;
353
354 is->memory.size = FIMC_IS_CPU_MEM_SIZE;
355 memset(is->memory.vaddr, 0, is->memory.size);
356
357 dev_info(dev, "FIMC-IS CPU memory base: %#x\n", (u32)is->memory.paddr);
358
359 if (((u32)is->memory.paddr) & FIMC_IS_FW_ADDR_MASK) {
360 dev_err(dev, "invalid firmware memory alignment: %#x\n",
361 (u32)is->memory.paddr);
362 dma_free_coherent(dev, is->memory.size, is->memory.vaddr,
363 is->memory.paddr);
364 return -EIO;
365 }
366
367 is->is_p_region = (struct is_region *)(is->memory.vaddr +
368 FIMC_IS_CPU_MEM_SIZE - FIMC_IS_REGION_SIZE);
369
370 is->is_dma_p_region = is->memory.paddr +
371 FIMC_IS_CPU_MEM_SIZE - FIMC_IS_REGION_SIZE;
372
373 is->is_shared_region = (struct is_share_region *)(is->memory.vaddr +
374 FIMC_IS_SHARED_REGION_OFFSET);
375 return 0;
376}
377
378static void fimc_is_free_cpu_memory(struct fimc_is *is)
379{
380 struct device *dev = &is->pdev->dev;
381
382 dma_free_coherent(dev, is->memory.size, is->memory.vaddr,
383 is->memory.paddr);
384}
385
386static void fimc_is_load_firmware(const struct firmware *fw, void *context)
387{
388 struct fimc_is *is = context;
389 struct device *dev = &is->pdev->dev;
390 void *buf;
391 int ret;
392
393 if (fw == NULL) {
394 dev_err(dev, "firmware request failed\n");
395 return;
396 }
397 mutex_lock(&is->lock);
398
399 if (fw->size < FIMC_IS_FW_SIZE_MIN || fw->size > FIMC_IS_FW_SIZE_MAX) {
400 dev_err(dev, "wrong firmware size: %d\n", fw->size);
401 goto done;
402 }
403
404 is->fw.size = fw->size;
405
406 ret = fimc_is_alloc_cpu_memory(is);
407 if (ret < 0) {
408 dev_err(dev, "failed to allocate FIMC-IS CPU memory\n");
409 goto done;
410 }
411
412 memcpy(is->memory.vaddr, fw->data, fw->size);
413 wmb();
414
415 /* Read firmware description. */
416 buf = (void *)(is->memory.vaddr + fw->size - FIMC_IS_FW_DESC_LEN);
417 memcpy(&is->fw.info, buf, FIMC_IS_FW_INFO_LEN);
418 is->fw.info[FIMC_IS_FW_INFO_LEN] = 0;
419
420 buf = (void *)(is->memory.vaddr + fw->size - FIMC_IS_FW_VER_LEN);
421 memcpy(&is->fw.version, buf, FIMC_IS_FW_VER_LEN);
422 is->fw.version[FIMC_IS_FW_VER_LEN - 1] = 0;
423
424 is->fw.state = 1;
425
426 dev_info(dev, "loaded firmware: %s, rev. %s\n",
427 is->fw.info, is->fw.version);
428 dev_dbg(dev, "FW size: %d, paddr: %#x\n", fw->size, is->memory.paddr);
429
430 is->is_shared_region->chip_id = 0xe4412;
431 is->is_shared_region->chip_rev_no = 1;
432
433 fimc_is_mem_barrier();
434
435 /*
436 * FIXME: The firmware is not being released for now, as it is
437 * needed around for copying to the IS working memory every
438 * time before the Cortex-A5 is restarted.
439 */
440 if (is->fw.f_w)
441 release_firmware(is->fw.f_w);
442 is->fw.f_w = fw;
443done:
444 mutex_unlock(&is->lock);
445}
446
447static int fimc_is_request_firmware(struct fimc_is *is, const char *fw_name)
448{
449 return request_firmware_nowait(THIS_MODULE,
450 FW_ACTION_HOTPLUG, fw_name, &is->pdev->dev,
451 GFP_KERNEL, is, fimc_is_load_firmware);
452}
453
454/* General IS interrupt handler */
455static void fimc_is_general_irq_handler(struct fimc_is *is)
456{
457 is->i2h_cmd.cmd = mcuctl_read(is, MCUCTL_REG_ISSR(10));
458
459 switch (is->i2h_cmd.cmd) {
460 case IHC_GET_SENSOR_NUM:
461 fimc_is_hw_get_params(is, 1);
462 fimc_is_hw_wait_intmsr0_intmsd0(is);
463 fimc_is_hw_set_sensor_num(is);
464 pr_debug("ISP FW version: %#x\n", is->i2h_cmd.args[0]);
465 break;
466 case IHC_SET_FACE_MARK:
467 case IHC_FRAME_DONE:
468 fimc_is_hw_get_params(is, 2);
469 break;
470 case IHC_SET_SHOT_MARK:
471 case IHC_AA_DONE:
472 case IH_REPLY_DONE:
473 fimc_is_hw_get_params(is, 3);
474 break;
475 case IH_REPLY_NOT_DONE:
476 fimc_is_hw_get_params(is, 4);
477 break;
478 case IHC_NOT_READY:
479 break;
480 default:
481 pr_info("unknown command: %#x\n", is->i2h_cmd.cmd);
482 }
483
484 fimc_is_fw_clear_irq1(is, FIMC_IS_INT_GENERAL);
485
486 switch (is->i2h_cmd.cmd) {
487 case IHC_GET_SENSOR_NUM:
488 fimc_is_hw_set_intgr0_gd0(is);
489 set_bit(IS_ST_A5_PWR_ON, &is->state);
490 break;
491
492 case IHC_SET_SHOT_MARK:
493 break;
494
495 case IHC_SET_FACE_MARK:
496 is->fd_header.count = is->i2h_cmd.args[0];
497 is->fd_header.index = is->i2h_cmd.args[1];
498 is->fd_header.offset = 0;
499 break;
500
501 case IHC_FRAME_DONE:
502 break;
503
504 case IHC_AA_DONE:
505 pr_debug("AA_DONE - %d, %d, %d\n", is->i2h_cmd.args[0],
506 is->i2h_cmd.args[1], is->i2h_cmd.args[2]);
507 break;
508
509 case IH_REPLY_DONE:
510 pr_debug("ISR_DONE: args[0]: %#x\n", is->i2h_cmd.args[0]);
511
512 switch (is->i2h_cmd.args[0]) {
513 case HIC_PREVIEW_STILL...HIC_CAPTURE_VIDEO:
514 /* Get CAC margin */
515 set_bit(IS_ST_CHANGE_MODE, &is->state);
516 is->isp.cac_margin_x = is->i2h_cmd.args[1];
517 is->isp.cac_margin_y = is->i2h_cmd.args[2];
518 pr_debug("CAC margin (x,y): (%d,%d)\n",
519 is->isp.cac_margin_x, is->isp.cac_margin_y);
520 break;
521
522 case HIC_STREAM_ON:
523 clear_bit(IS_ST_STREAM_OFF, &is->state);
524 set_bit(IS_ST_STREAM_ON, &is->state);
525 break;
526
527 case HIC_STREAM_OFF:
528 clear_bit(IS_ST_STREAM_ON, &is->state);
529 set_bit(IS_ST_STREAM_OFF, &is->state);
530 break;
531
532 case HIC_SET_PARAMETER:
533 is->config[is->config_index].p_region_index1 = 0;
534 is->config[is->config_index].p_region_index2 = 0;
535 set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
536 pr_debug("HIC_SET_PARAMETER\n");
537 break;
538
539 case HIC_GET_PARAMETER:
540 break;
541
542 case HIC_SET_TUNE:
543 break;
544
545 case HIC_GET_STATUS:
546 break;
547
548 case HIC_OPEN_SENSOR:
549 set_bit(IS_ST_OPEN_SENSOR, &is->state);
550 pr_debug("data lanes: %d, settle line: %d\n",
551 is->i2h_cmd.args[2], is->i2h_cmd.args[1]);
552 break;
553
554 case HIC_CLOSE_SENSOR:
555 clear_bit(IS_ST_OPEN_SENSOR, &is->state);
556 is->sensor_index = 0;
557 break;
558
559 case HIC_MSG_TEST:
560 pr_debug("config MSG level completed\n");
561 break;
562
563 case HIC_POWER_DOWN:
564 clear_bit(IS_ST_PWR_SUBIP_ON, &is->state);
565 break;
566
567 case HIC_GET_SET_FILE_ADDR:
568 is->setfile.base = is->i2h_cmd.args[1];
569 set_bit(IS_ST_SETFILE_LOADED, &is->state);
570 break;
571
572 case HIC_LOAD_SET_FILE:
573 set_bit(IS_ST_SETFILE_LOADED, &is->state);
574 break;
575 }
576 break;
577
578 case IH_REPLY_NOT_DONE:
579 pr_err("ISR_NDONE: %d: %#x, %s\n", is->i2h_cmd.args[0],
580 is->i2h_cmd.args[1],
581 fimc_is_strerr(is->i2h_cmd.args[1]));
582
583 if (is->i2h_cmd.args[1] & IS_ERROR_TIME_OUT_FLAG)
584 pr_err("IS_ERROR_TIME_OUT\n");
585
586 switch (is->i2h_cmd.args[1]) {
587 case IS_ERROR_SET_PARAMETER:
588 fimc_is_mem_barrier();
589 }
590
591 switch (is->i2h_cmd.args[0]) {
592 case HIC_SET_PARAMETER:
593 is->config[is->config_index].p_region_index1 = 0;
594 is->config[is->config_index].p_region_index2 = 0;
595 set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
596 break;
597 }
598 break;
599
600 case IHC_NOT_READY:
601 pr_err("IS control sequence error: Not Ready\n");
602 break;
603 }
604
605 wake_up(&is->irq_queue);
606}
607
608static irqreturn_t fimc_is_irq_handler(int irq, void *priv)
609{
610 struct fimc_is *is = priv;
611 unsigned long flags;
612 u32 status;
613
614 spin_lock_irqsave(&is->slock, flags);
615 status = mcuctl_read(is, MCUCTL_REG_INTSR1);
616
617 if (status & (1UL << FIMC_IS_INT_GENERAL))
618 fimc_is_general_irq_handler(is);
619
620 if (status & (1UL << FIMC_IS_INT_FRAME_DONE_ISP))
621 fimc_isp_irq_handler(is);
622
623 spin_unlock_irqrestore(&is->slock, flags);
624 return IRQ_HANDLED;
625}
626
627static int fimc_is_hw_open_sensor(struct fimc_is *is,
628 struct fimc_is_sensor *sensor)
629{
630 struct sensor_open_extended *soe = (void *)&is->is_p_region->shared;
631
632 fimc_is_hw_wait_intmsr0_intmsd0(is);
633
634 soe->self_calibration_mode = 1;
635 soe->actuator_type = 0;
636 soe->mipi_lane_num = 0;
637 soe->mclk = 0;
638 soe->mipi_speed = 0;
639 soe->fast_open_sensor = 0;
640 soe->i2c_sclk = 88000000;
641
642 fimc_is_mem_barrier();
643
644 mcuctl_write(HIC_OPEN_SENSOR, is, MCUCTL_REG_ISSR(0));
645 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
646 mcuctl_write(sensor->drvdata->id, is, MCUCTL_REG_ISSR(2));
647 mcuctl_write(sensor->i2c_bus, is, MCUCTL_REG_ISSR(3));
648 mcuctl_write(is->is_dma_p_region, is, MCUCTL_REG_ISSR(4));
649
650 fimc_is_hw_set_intgr0_gd0(is);
651
652 return fimc_is_wait_event(is, IS_ST_OPEN_SENSOR, 1,
653 FIMC_IS_SENSOR_OPEN_TIMEOUT);
654}
655
656
657int fimc_is_hw_initialize(struct fimc_is *is)
658{
659 const int config_ids[] = {
660 IS_SC_PREVIEW_STILL, IS_SC_PREVIEW_VIDEO,
661 IS_SC_CAPTURE_STILL, IS_SC_CAPTURE_VIDEO
662 };
663 struct device *dev = &is->pdev->dev;
664 u32 prev_id;
665 int i, ret;
666
667 /* Sensor initialization. */
668 ret = fimc_is_hw_open_sensor(is, is->sensor);
669 if (ret < 0)
670 return ret;
671
672 /* Get the setfile address. */
673 fimc_is_hw_get_setfile_addr(is);
674
675 ret = fimc_is_wait_event(is, IS_ST_SETFILE_LOADED, 1,
676 FIMC_IS_CONFIG_TIMEOUT);
677 if (ret < 0) {
678 dev_err(dev, "get setfile address timed out\n");
679 return ret;
680 }
681 pr_debug("setfile.base: %#x\n", is->setfile.base);
682
683 /* Load the setfile. */
684 fimc_is_load_setfile(is, FIMC_IS_SETFILE_6A3);
685 clear_bit(IS_ST_SETFILE_LOADED, &is->state);
686 fimc_is_hw_load_setfile(is);
687 ret = fimc_is_wait_event(is, IS_ST_SETFILE_LOADED, 1,
688 FIMC_IS_CONFIG_TIMEOUT);
689 if (ret < 0) {
690 dev_err(dev, "loading setfile timed out\n");
691 return ret;
692 }
693
694 pr_debug("setfile: base: %#x, size: %d\n",
695 is->setfile.base, is->setfile.size);
696 pr_info("FIMC-IS Setfile info: %s\n", is->fw.setfile_info);
697
698 /* Check magic number. */
699 if (is->is_p_region->shared[MAX_SHARED_COUNT - 1] !=
700 FIMC_IS_MAGIC_NUMBER) {
701 dev_err(dev, "magic number error!\n");
702 return -EIO;
703 }
704
705 pr_debug("shared region: %#x, parameter region: %#x\n",
706 is->memory.paddr + FIMC_IS_SHARED_REGION_OFFSET,
707 is->is_dma_p_region);
708
709 is->setfile.sub_index = 0;
710
711 /* Stream off. */
712 fimc_is_hw_stream_off(is);
713 ret = fimc_is_wait_event(is, IS_ST_STREAM_OFF, 1,
714 FIMC_IS_CONFIG_TIMEOUT);
715 if (ret < 0) {
716 dev_err(dev, "stream off timeout\n");
717 return ret;
718 }
719
720 /* Preserve previous mode. */
721 prev_id = is->config_index;
722
723 /* Set initial parameter values. */
724 for (i = 0; i < ARRAY_SIZE(config_ids); i++) {
725 is->config_index = config_ids[i];
726 fimc_is_set_initial_params(is);
727 ret = fimc_is_itf_s_param(is, true);
728 if (ret < 0) {
729 is->config_index = prev_id;
730 return ret;
731 }
732 }
733 is->config_index = prev_id;
734
735 set_bit(IS_ST_INIT_DONE, &is->state);
736 dev_info(dev, "initialization sequence completed (%d)\n",
737 is->config_index);
738 return 0;
739}
740
741static int fimc_is_log_show(struct seq_file *s, void *data)
742{
743 struct fimc_is *is = s->private;
744 const u8 *buf = is->memory.vaddr + FIMC_IS_DEBUG_REGION_OFFSET;
745
746 if (is->memory.vaddr == NULL) {
747 dev_err(&is->pdev->dev, "firmware memory is not initialized\n");
748 return -EIO;
749 }
750
751 seq_printf(s, "%s\n", buf);
752 return 0;
753}
754
755static int fimc_is_debugfs_open(struct inode *inode, struct file *file)
756{
757 return single_open(file, fimc_is_log_show, inode->i_private);
758}
759
760static const struct file_operations fimc_is_debugfs_fops = {
761 .open = fimc_is_debugfs_open,
762 .read = seq_read,
763 .llseek = seq_lseek,
764 .release = single_release,
765};
766
767static void fimc_is_debugfs_remove(struct fimc_is *is)
768{
769 debugfs_remove_recursive(is->debugfs_entry);
770 is->debugfs_entry = NULL;
771}
772
773static int fimc_is_debugfs_create(struct fimc_is *is)
774{
775 struct dentry *dentry;
776
777 is->debugfs_entry = debugfs_create_dir("fimc_is", NULL);
778
779 dentry = debugfs_create_file("fw_log", S_IRUGO, is->debugfs_entry,
780 is, &fimc_is_debugfs_fops);
781 if (!dentry)
782 fimc_is_debugfs_remove(is);
783
784 return is->debugfs_entry == NULL ? -EIO : 0;
785}
786
787static int fimc_is_probe(struct platform_device *pdev)
788{
789 struct device *dev = &pdev->dev;
790 struct fimc_is *is;
791 struct resource res;
792 struct device_node *node;
793 int ret;
794
795 is = devm_kzalloc(&pdev->dev, sizeof(*is), GFP_KERNEL);
796 if (!is)
797 return -ENOMEM;
798
799 is->pdev = pdev;
800 is->isp.pdev = pdev;
801
802 init_waitqueue_head(&is->irq_queue);
803 spin_lock_init(&is->slock);
804 mutex_init(&is->lock);
805
806 ret = of_address_to_resource(dev->of_node, 0, &res);
807 if (ret < 0)
808 return ret;
809
810 is->regs = devm_ioremap_resource(dev, &res);
811 if (IS_ERR(is->regs))
812 return PTR_ERR(is->regs);
813
814 node = of_get_child_by_name(dev->of_node, "pmu");
815 if (!node)
816 return -ENODEV;
817
818 is->pmu_regs = of_iomap(node, 0);
819 if (!is->pmu_regs)
820 return -ENOMEM;
821
822 is->irq = irq_of_parse_and_map(dev->of_node, 0);
823 if (is->irq < 0) {
824 dev_err(dev, "no irq found\n");
825 return is->irq;
826 }
827
828 ret = fimc_is_get_clocks(is);
829 if (ret < 0)
830 return ret;
831
832 platform_set_drvdata(pdev, is);
833
834 ret = request_irq(is->irq, fimc_is_irq_handler, 0, dev_name(dev), is);
835 if (ret < 0) {
836 dev_err(dev, "irq request failed\n");
837 goto err_clk;
838 }
839 pm_runtime_enable(dev);
840 /*
841 * Enable only the ISP power domain, keep FIMC-IS clocks off until
842 * the whole clock tree is configured. The ISP power domain needs
843 * be active in order to acces any CMU_ISP clock registers.
844 */
845 ret = pm_runtime_get_sync(dev);
846 if (ret < 0)
847 goto err_irq;
848
849 ret = fimc_is_setup_clocks(is);
850 pm_runtime_put_sync(dev);
851
852 if (ret < 0)
853 goto err_irq;
854
855 is->clk_init = true;
856
857 is->alloc_ctx = vb2_dma_contig_init_ctx(dev);
858 if (IS_ERR(is->alloc_ctx)) {
859 ret = PTR_ERR(is->alloc_ctx);
860 goto err_irq;
861 }
862 /*
863 * Register FIMC-IS V4L2 subdevs to this driver. The video nodes
864 * will be created within the subdev's registered() callback.
865 */
866 ret = fimc_is_register_subdevs(is);
867 if (ret < 0)
868 goto err_vb;
869
870 ret = fimc_is_debugfs_create(is);
871 if (ret < 0)
872 goto err_sd;
873
874 ret = fimc_is_request_firmware(is, FIMC_IS_FW_FILENAME);
875 if (ret < 0)
876 goto err_dfs;
877
878 dev_dbg(dev, "FIMC-IS registered successfully\n");
879 return 0;
880
881err_dfs:
882 fimc_is_debugfs_remove(is);
883err_vb:
884 vb2_dma_contig_cleanup_ctx(is->alloc_ctx);
885err_sd:
886 fimc_is_unregister_subdevs(is);
887err_irq:
888 free_irq(is->irq, is);
889err_clk:
890 fimc_is_put_clocks(is);
891 return ret;
892}
893
894static int fimc_is_runtime_resume(struct device *dev)
895{
896 struct fimc_is *is = dev_get_drvdata(dev);
897
898 if (!is->clk_init)
899 return 0;
900
901 return fimc_is_enable_clocks(is);
902}
903
904static int fimc_is_runtime_suspend(struct device *dev)
905{
906 struct fimc_is *is = dev_get_drvdata(dev);
907
908 if (is->clk_init)
909 fimc_is_disable_clocks(is);
910
911 return 0;
912}
913
914#ifdef CONFIG_PM_SLEEP
915static int fimc_is_resume(struct device *dev)
916{
917 /* TODO: */
918 return 0;
919}
920
921static int fimc_is_suspend(struct device *dev)
922{
923 struct fimc_is *is = dev_get_drvdata(dev);
924
925 /* TODO: */
926 if (test_bit(IS_ST_A5_PWR_ON, &is->state))
927 return -EBUSY;
928
929 return 0;
930}
931#endif /* CONFIG_PM_SLEEP */
932
933static int fimc_is_remove(struct platform_device *pdev)
934{
935 struct fimc_is *is = platform_get_drvdata(pdev);
936
937 pm_runtime_disable(&pdev->dev);
938 pm_runtime_set_suspended(&pdev->dev);
939 free_irq(is->irq, is);
940 fimc_is_unregister_subdevs(is);
941 vb2_dma_contig_cleanup_ctx(is->alloc_ctx);
942 fimc_is_put_clocks(is);
943 fimc_is_debugfs_remove(is);
944 release_firmware(is->fw.f_w);
945 fimc_is_free_cpu_memory(is);
946
947 return 0;
948}
949
950static const struct of_device_id fimc_is_of_match[] = {
951 { .compatible = "samsung,exynos4212-fimc-is" },
952 { /* sentinel */ },
953};
954MODULE_DEVICE_TABLE(of, fimc_is_of_match);
955
956static const struct dev_pm_ops fimc_is_pm_ops = {
957 SET_SYSTEM_SLEEP_PM_OPS(fimc_is_suspend, fimc_is_resume)
958 SET_RUNTIME_PM_OPS(fimc_is_runtime_suspend, fimc_is_runtime_resume,
959 NULL)
960};
961
962static struct platform_driver fimc_is_driver = {
963 .probe = fimc_is_probe,
964 .remove = fimc_is_remove,
965 .driver = {
966 .of_match_table = fimc_is_of_match,
967 .name = FIMC_IS_DRV_NAME,
968 .owner = THIS_MODULE,
969 .pm = &fimc_is_pm_ops,
970 }
971};
972
973static int fimc_is_module_init(void)
974{
975 int ret;
976
977 ret = fimc_is_register_sensor_driver();
978 if (ret < 0)
979 return ret;
980
981 ret = fimc_is_register_i2c_driver();
982 if (ret < 0)
983 goto err_sens;
984
985 ret = platform_driver_register(&fimc_is_driver);
986 if (!ret)
987 return ret;
988
989 fimc_is_unregister_i2c_driver();
990err_sens:
991 fimc_is_unregister_sensor_driver();
992 return ret;
993}
994
995static void fimc_is_module_exit(void)
996{
997 fimc_is_unregister_sensor_driver();
998 fimc_is_unregister_i2c_driver();
999 platform_driver_unregister(&fimc_is_driver);
1000}
1001
1002module_init(fimc_is_module_init);
1003module_exit(fimc_is_module_exit);
1004
1005MODULE_ALIAS("platform:" FIMC_IS_DRV_NAME);
1006MODULE_AUTHOR("Younghwan Joo <yhwan.joo@samsung.com>");
1007MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
diff --git a/drivers/media/platform/exynos4-is/fimc-is.h b/drivers/media/platform/exynos4-is/fimc-is.h
new file mode 100644
index 000000000000..f5275a5b0156
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-is.h
@@ -0,0 +1,345 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
7 * Sylwester Nawrocki <s.nawrocki@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef FIMC_IS_H_
14#define FIMC_IS_H_
15
16#include <asm/barrier.h>
17#include <linux/clk.h>
18#include <linux/device.h>
19#include <linux/kernel.h>
20#include <linux/pinctrl/consumer.h>
21#include <linux/platform_device.h>
22#include <linux/sizes.h>
23#include <linux/spinlock.h>
24#include <linux/types.h>
25#include <media/videobuf2-core.h>
26#include <media/v4l2-ctrls.h>
27
28#include "fimc-isp.h"
29#include "fimc-is-command.h"
30#include "fimc-is-sensor.h"
31#include "fimc-is-param.h"
32#include "fimc-is-regs.h"
33
34#define FIMC_IS_DRV_NAME "exynos4-fimc-is"
35
36#define FIMC_IS_FW_FILENAME "fimc_is_fw.bin"
37#define FIMC_IS_SETFILE_6A3 "setfile.bin"
38
39#define FIMC_IS_FW_LOAD_TIMEOUT 1000 /* ms */
40#define FIMC_IS_POWER_ON_TIMEOUT 1000 /* us */
41
42#define FIMC_IS_SENSOR_NUM 2
43
44/* Memory definitions */
45#define FIMC_IS_CPU_MEM_SIZE (0xa00000)
46#define FIMC_IS_CPU_BASE_MASK ((1 << 26) - 1)
47#define FIMC_IS_REGION_SIZE 0x5000
48
49#define FIMC_IS_DEBUG_REGION_OFFSET 0x0084b000
50#define FIMC_IS_SHARED_REGION_OFFSET 0x008c0000
51#define FIMC_IS_FW_INFO_LEN 31
52#define FIMC_IS_FW_VER_LEN 7
53#define FIMC_IS_FW_DESC_LEN (FIMC_IS_FW_INFO_LEN + \
54 FIMC_IS_FW_VER_LEN)
55#define FIMC_IS_SETFILE_INFO_LEN 39
56
57#define FIMC_IS_EXTRA_MEM_SIZE (FIMC_IS_EXTRA_FW_SIZE + \
58 FIMC_IS_EXTRA_SETFILE_SIZE + 0x1000)
59#define FIMC_IS_EXTRA_FW_SIZE 0x180000
60#define FIMC_IS_EXTRA_SETFILE_SIZE 0x4b000
61
62/* TODO: revisit */
63#define FIMC_IS_FW_ADDR_MASK ((1 << 26) - 1)
64#define FIMC_IS_FW_SIZE_MAX (SZ_4M)
65#define FIMC_IS_FW_SIZE_MIN (SZ_32K)
66
67#define ATCLK_MCUISP_FREQUENCY 100000000UL
68#define ACLK_AXI_FREQUENCY 100000000UL
69
70enum {
71 ISS_CLK_PPMUISPX,
72 ISS_CLK_PPMUISPMX,
73 ISS_CLK_LITE0,
74 ISS_CLK_LITE1,
75 ISS_CLK_MPLL,
76 ISS_CLK_SYSREG,
77 ISS_CLK_ISP,
78 ISS_CLK_DRC,
79 ISS_CLK_FD,
80 ISS_CLK_MCUISP,
81 ISS_CLK_UART,
82 ISS_GATE_CLKS_MAX,
83 ISS_CLK_ISP_DIV0 = ISS_GATE_CLKS_MAX,
84 ISS_CLK_ISP_DIV1,
85 ISS_CLK_MCUISP_DIV0,
86 ISS_CLK_MCUISP_DIV1,
87 ISS_CLK_ACLK200,
88 ISS_CLK_ACLK200_DIV,
89 ISS_CLK_ACLK400MCUISP,
90 ISS_CLK_ACLK400MCUISP_DIV,
91 ISS_CLKS_MAX
92};
93
94/* The driver's internal state flags */
95enum {
96 IS_ST_IDLE,
97 IS_ST_PWR_ON,
98 IS_ST_A5_PWR_ON,
99 IS_ST_FW_LOADED,
100 IS_ST_OPEN_SENSOR,
101 IS_ST_SETFILE_LOADED,
102 IS_ST_INIT_DONE,
103 IS_ST_STREAM_ON,
104 IS_ST_STREAM_OFF,
105 IS_ST_CHANGE_MODE,
106 IS_ST_BLOCK_CMD_CLEARED,
107 IS_ST_SET_ZOOM,
108 IS_ST_PWR_SUBIP_ON,
109 IS_ST_END,
110};
111
112enum af_state {
113 FIMC_IS_AF_IDLE = 0,
114 FIMC_IS_AF_SETCONFIG = 1,
115 FIMC_IS_AF_RUNNING = 2,
116 FIMC_IS_AF_LOCK = 3,
117 FIMC_IS_AF_ABORT = 4,
118 FIMC_IS_AF_FAILED = 5,
119};
120
121enum af_lock_state {
122 FIMC_IS_AF_UNLOCKED = 0,
123 FIMC_IS_AF_LOCKED = 2
124};
125
126enum ae_lock_state {
127 FIMC_IS_AE_UNLOCKED = 0,
128 FIMC_IS_AE_LOCKED = 1
129};
130
131enum awb_lock_state {
132 FIMC_IS_AWB_UNLOCKED = 0,
133 FIMC_IS_AWB_LOCKED = 1
134};
135
136enum {
137 IS_METERING_CONFIG_CMD,
138 IS_METERING_CONFIG_WIN_POS_X,
139 IS_METERING_CONFIG_WIN_POS_Y,
140 IS_METERING_CONFIG_WIN_WIDTH,
141 IS_METERING_CONFIG_WIN_HEIGHT,
142 IS_METERING_CONFIG_MAX
143};
144
145struct is_setfile {
146 const struct firmware *info;
147 int state;
148 u32 sub_index;
149 u32 base;
150 size_t size;
151};
152
153struct is_fd_result_header {
154 u32 offset;
155 u32 count;
156 u32 index;
157 u32 curr_index;
158 u32 width;
159 u32 height;
160};
161
162struct is_af_info {
163 u16 mode;
164 u32 af_state;
165 u32 af_lock_state;
166 u32 ae_lock_state;
167 u32 awb_lock_state;
168 u16 pos_x;
169 u16 pos_y;
170 u16 prev_pos_x;
171 u16 prev_pos_y;
172 u16 use_af;
173};
174
175struct fimc_is_firmware {
176 const struct firmware *f_w;
177
178 dma_addr_t paddr;
179 void *vaddr;
180 unsigned int size;
181
182 char info[FIMC_IS_FW_INFO_LEN + 1];
183 char version[FIMC_IS_FW_VER_LEN + 1];
184 char setfile_info[FIMC_IS_SETFILE_INFO_LEN + 1];
185 u8 state;
186};
187
188struct fimc_is_memory {
189 /* physical base address */
190 dma_addr_t paddr;
191 /* virtual base address */
192 void *vaddr;
193 /* total length */
194 unsigned int size;
195};
196
197#define FIMC_IS_I2H_MAX_ARGS 12
198
199struct i2h_cmd {
200 u32 cmd;
201 u32 sensor_id;
202 u16 num_args;
203 u32 args[FIMC_IS_I2H_MAX_ARGS];
204};
205
206struct h2i_cmd {
207 u16 cmd_type;
208 u32 entry_id;
209};
210
211#define FIMC_IS_DEBUG_MSG 0x3f
212#define FIMC_IS_DEBUG_LEVEL 3
213
214struct fimc_is_setfile {
215 const struct firmware *info;
216 unsigned int state;
217 unsigned int size;
218 u32 sub_index;
219 u32 base;
220};
221
222struct chain_config {
223 struct global_param global;
224 struct sensor_param sensor;
225 struct isp_param isp;
226 struct drc_param drc;
227 struct fd_param fd;
228
229 unsigned long p_region_index1;
230 unsigned long p_region_index2;
231};
232
233/**
234 * struct fimc_is - fimc-is data structure
235 * @pdev: pointer to FIMC-IS platform device
236 * @pctrl: pointer to pinctrl structure for this device
237 * @v4l2_dev: pointer to top the level v4l2_device
238 * @alloc_ctx: videobuf2 memory allocator context
239 * @lock: mutex serializing video device and the subdev operations
240 * @slock: spinlock protecting this data structure and the hw registers
241 * @clocks: FIMC-LITE gate clock
242 * @regs: MCUCTL mmapped registers region
243 * @pmu_regs: PMU ISP mmapped registers region
244 * @irq_queue: interrupt handling waitqueue
245 * @lpm: low power mode flag
246 * @state: internal driver's state flags
247 */
248struct fimc_is {
249 struct platform_device *pdev;
250 struct pinctrl *pctrl;
251 struct v4l2_device *v4l2_dev;
252
253 struct fimc_is_firmware fw;
254 struct fimc_is_memory memory;
255 struct firmware *f_w;
256
257 struct fimc_isp isp;
258 struct fimc_is_sensor *sensor;
259 struct fimc_is_setfile setfile;
260
261 struct vb2_alloc_ctx *alloc_ctx;
262 struct v4l2_ctrl_handler ctrl_handler;
263
264 struct mutex lock;
265 spinlock_t slock;
266
267 struct clk *clocks[ISS_CLKS_MAX];
268 bool clk_init;
269 void __iomem *regs;
270 void __iomem *pmu_regs;
271 int irq;
272 wait_queue_head_t irq_queue;
273 u8 lpm;
274
275 unsigned long state;
276 unsigned int sensor_index;
277
278 struct i2h_cmd i2h_cmd;
279 struct h2i_cmd h2i_cmd;
280 struct is_fd_result_header fd_header;
281
282 struct chain_config config[IS_SC_MAX];
283 unsigned config_index;
284
285 struct is_region *is_p_region;
286 dma_addr_t is_dma_p_region;
287 struct is_share_region *is_shared_region;
288 struct is_af_info af;
289
290 struct dentry *debugfs_entry;
291};
292
293static inline struct fimc_is *fimc_isp_to_is(struct fimc_isp *isp)
294{
295 return container_of(isp, struct fimc_is, isp);
296}
297
298static inline void fimc_is_mem_barrier(void)
299{
300 mb();
301}
302
303static inline void fimc_is_set_param_bit(struct fimc_is *is, int num)
304{
305 struct chain_config *cfg = &is->config[is->config_index];
306
307 if (num >= 32)
308 set_bit(num - 32, &cfg->p_region_index2);
309 else
310 set_bit(num, &cfg->p_region_index1);
311}
312
313static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd)
314{
315 is->is_p_region->parameter.isp.control.cmd = cmd;
316}
317
318static inline void mcuctl_write(u32 v, struct fimc_is *is, unsigned int offset)
319{
320 writel(v, is->regs + offset);
321}
322
323static inline u32 mcuctl_read(struct fimc_is *is, unsigned int offset)
324{
325 return readl(is->regs + offset);
326}
327
328static inline void pmuisp_write(u32 v, struct fimc_is *is, unsigned int offset)
329{
330 writel(v, is->pmu_regs + offset);
331}
332
333static inline u32 pmuisp_read(struct fimc_is *is, unsigned int offset)
334{
335 return readl(is->pmu_regs + offset);
336}
337
338int fimc_is_wait_event(struct fimc_is *is, unsigned long bit,
339 unsigned int state, unsigned int timeout);
340int fimc_is_cpu_set_power(struct fimc_is *is, int on);
341int fimc_is_start_firmware(struct fimc_is *is);
342int fimc_is_hw_initialize(struct fimc_is *is);
343void fimc_is_log_dump(const char *level, const void *buf, size_t len);
344
345#endif /* FIMC_IS_H_ */
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
new file mode 100644
index 000000000000..d63947f7b302
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -0,0 +1,703 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com>
7 * Younghwan Joo <yhwan.joo@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__
14
15#include <linux/device.h>
16#include <linux/errno.h>
17#include <linux/kernel.h>
18#include <linux/list.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/printk.h>
22#include <linux/pm_runtime.h>
23#include <linux/slab.h>
24#include <linux/types.h>
25#include <media/v4l2-device.h>
26
27#include "media-dev.h"
28#include "fimc-is-command.h"
29#include "fimc-is-param.h"
30#include "fimc-is-regs.h"
31#include "fimc-is.h"
32
33static int debug;
34module_param_named(debug_isp, debug, int, S_IRUGO | S_IWUSR);
35
36static const struct fimc_fmt fimc_isp_formats[FIMC_ISP_NUM_FORMATS] = {
37 {
38 .name = "RAW8 (GRBG)",
39 .fourcc = V4L2_PIX_FMT_SGRBG8,
40 .depth = { 8 },
41 .color = FIMC_FMT_RAW8,
42 .memplanes = 1,
43 .mbus_code = V4L2_MBUS_FMT_SGRBG8_1X8,
44 }, {
45 .name = "RAW10 (GRBG)",
46 .fourcc = V4L2_PIX_FMT_SGRBG10,
47 .depth = { 10 },
48 .color = FIMC_FMT_RAW10,
49 .memplanes = 1,
50 .mbus_code = V4L2_MBUS_FMT_SGRBG10_1X10,
51 }, {
52 .name = "RAW12 (GRBG)",
53 .fourcc = V4L2_PIX_FMT_SGRBG12,
54 .depth = { 12 },
55 .color = FIMC_FMT_RAW12,
56 .memplanes = 1,
57 .mbus_code = V4L2_MBUS_FMT_SGRBG12_1X12,
58 },
59};
60
61/**
62 * fimc_isp_find_format - lookup color format by fourcc or media bus code
63 * @pixelformat: fourcc to match, ignored if null
64 * @mbus_code: media bus code to match, ignored if null
65 * @index: index to the fimc_isp_formats array, ignored if negative
66 */
67const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat,
68 const u32 *mbus_code, int index)
69{
70 const struct fimc_fmt *fmt, *def_fmt = NULL;
71 unsigned int i;
72 int id = 0;
73
74 if (index >= (int)ARRAY_SIZE(fimc_isp_formats))
75 return NULL;
76
77 for (i = 0; i < ARRAY_SIZE(fimc_isp_formats); ++i) {
78 fmt = &fimc_isp_formats[i];
79 if (pixelformat && fmt->fourcc == *pixelformat)
80 return fmt;
81 if (mbus_code && fmt->mbus_code == *mbus_code)
82 return fmt;
83 if (index == id)
84 def_fmt = fmt;
85 id++;
86 }
87 return def_fmt;
88}
89
90void fimc_isp_irq_handler(struct fimc_is *is)
91{
92 is->i2h_cmd.args[0] = mcuctl_read(is, MCUCTL_REG_ISSR(20));
93 is->i2h_cmd.args[1] = mcuctl_read(is, MCUCTL_REG_ISSR(21));
94
95 fimc_is_fw_clear_irq1(is, FIMC_IS_INT_FRAME_DONE_ISP);
96
97 /* TODO: Complete ISP DMA interrupt handler */
98 wake_up(&is->irq_queue);
99}
100
101/* Capture subdev media entity operations */
102static int fimc_is_link_setup(struct media_entity *entity,
103 const struct media_pad *local,
104 const struct media_pad *remote, u32 flags)
105{
106 return 0;
107}
108
109static const struct media_entity_operations fimc_is_subdev_media_ops = {
110 .link_setup = fimc_is_link_setup,
111};
112
113static int fimc_is_subdev_enum_mbus_code(struct v4l2_subdev *sd,
114 struct v4l2_subdev_fh *fh,
115 struct v4l2_subdev_mbus_code_enum *code)
116{
117 const struct fimc_fmt *fmt;
118
119 fmt = fimc_isp_find_format(NULL, NULL, code->index);
120 if (!fmt)
121 return -EINVAL;
122 code->code = fmt->mbus_code;
123 return 0;
124}
125
126static int fimc_isp_subdev_get_fmt(struct v4l2_subdev *sd,
127 struct v4l2_subdev_fh *fh,
128 struct v4l2_subdev_format *fmt)
129{
130 struct fimc_isp *isp = v4l2_get_subdevdata(sd);
131 struct fimc_is *is = fimc_isp_to_is(isp);
132 struct v4l2_mbus_framefmt *mf = &fmt->format;
133 struct v4l2_mbus_framefmt cur_fmt;
134
135 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
136 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
137 fmt->format = *mf;
138 return 0;
139 }
140
141 mf->colorspace = V4L2_COLORSPACE_JPEG;
142
143 mutex_lock(&isp->subdev_lock);
144 __is_get_frame_size(is, &cur_fmt);
145
146 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) {
147 /* full camera input frame size */
148 mf->width = cur_fmt.width + FIMC_ISP_CAC_MARGIN_WIDTH;
149 mf->height = cur_fmt.height + FIMC_ISP_CAC_MARGIN_HEIGHT;
150 mf->code = V4L2_MBUS_FMT_SGRBG10_1X10;
151 } else {
152 /* crop size */
153 mf->width = cur_fmt.width;
154 mf->height = cur_fmt.height;
155 mf->code = V4L2_MBUS_FMT_YUV10_1X30;
156 }
157
158 mutex_unlock(&isp->subdev_lock);
159
160 v4l2_dbg(1, debug, sd, "%s: pad%d: fmt: 0x%x, %dx%d\n",
161 __func__, fmt->pad, mf->code, mf->width, mf->height);
162
163 return 0;
164}
165
166static void __isp_subdev_try_format(struct fimc_isp *isp,
167 struct v4l2_subdev_format *fmt)
168{
169 struct v4l2_mbus_framefmt *mf = &fmt->format;
170
171 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) {
172 v4l_bound_align_image(&mf->width, FIMC_ISP_SINK_WIDTH_MIN,
173 FIMC_ISP_SINK_WIDTH_MAX, 0,
174 &mf->height, FIMC_ISP_SINK_HEIGHT_MIN,
175 FIMC_ISP_SINK_HEIGHT_MAX, 0, 0);
176 isp->subdev_fmt = *mf;
177 } else {
178 /* Allow changing format only on sink pad */
179 mf->width = isp->subdev_fmt.width - FIMC_ISP_CAC_MARGIN_WIDTH;
180 mf->height = isp->subdev_fmt.height - FIMC_ISP_CAC_MARGIN_HEIGHT;
181 mf->code = isp->subdev_fmt.code;
182 }
183}
184
185static int fimc_isp_subdev_set_fmt(struct v4l2_subdev *sd,
186 struct v4l2_subdev_fh *fh,
187 struct v4l2_subdev_format *fmt)
188{
189 struct fimc_isp *isp = v4l2_get_subdevdata(sd);
190 struct fimc_is *is = fimc_isp_to_is(isp);
191 struct v4l2_mbus_framefmt *mf = &fmt->format;
192 int ret = 0;
193
194 v4l2_dbg(1, debug, sd, "%s: pad%d: code: 0x%x, %dx%d\n",
195 __func__, fmt->pad, mf->code, mf->width, mf->height);
196
197 mf->colorspace = V4L2_COLORSPACE_JPEG;
198
199 mutex_lock(&isp->subdev_lock);
200 __isp_subdev_try_format(isp, fmt);
201
202 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
203 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
204 *mf = fmt->format;
205 mutex_unlock(&isp->subdev_lock);
206 return 0;
207 }
208
209 if (sd->entity.stream_count == 0)
210 __is_set_frame_size(is, mf);
211 else
212 ret = -EBUSY;
213 mutex_unlock(&isp->subdev_lock);
214
215 return ret;
216}
217
218static int fimc_isp_subdev_s_stream(struct v4l2_subdev *sd, int on)
219{
220 struct fimc_isp *isp = v4l2_get_subdevdata(sd);
221 struct fimc_is *is = fimc_isp_to_is(isp);
222 int ret;
223
224 v4l2_dbg(1, debug, sd, "%s: on: %d\n", __func__, on);
225
226 if (!test_bit(IS_ST_INIT_DONE, &is->state))
227 return -EBUSY;
228
229 fimc_is_mem_barrier();
230
231 if (on) {
232 if (__get_pending_param_count(is)) {
233 ret = fimc_is_itf_s_param(is, true);
234 if (ret < 0)
235 return ret;
236 }
237
238 v4l2_dbg(1, debug, sd, "changing mode to %d\n",
239 is->config_index);
240 ret = fimc_is_itf_mode_change(is);
241 if (ret)
242 return -EINVAL;
243
244 clear_bit(IS_ST_STREAM_ON, &is->state);
245 fimc_is_hw_stream_on(is);
246 ret = fimc_is_wait_event(is, IS_ST_STREAM_ON, 1,
247 FIMC_IS_CONFIG_TIMEOUT);
248 if (ret < 0) {
249 v4l2_err(sd, "stream on timeout\n");
250 return ret;
251 }
252 } else {
253 clear_bit(IS_ST_STREAM_OFF, &is->state);
254 fimc_is_hw_stream_off(is);
255 ret = fimc_is_wait_event(is, IS_ST_STREAM_OFF, 1,
256 FIMC_IS_CONFIG_TIMEOUT);
257 if (ret < 0) {
258 v4l2_err(sd, "stream off timeout\n");
259 return ret;
260 }
261 is->setfile.sub_index = 0;
262 }
263
264 return 0;
265}
266
267static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
268{
269 struct fimc_isp *isp = v4l2_get_subdevdata(sd);
270 struct fimc_is *is = fimc_isp_to_is(isp);
271 int ret = 0;
272
273 pr_debug("on: %d\n", on);
274
275 if (on) {
276 ret = pm_runtime_get_sync(&is->pdev->dev);
277 if (ret < 0)
278 return ret;
279 set_bit(IS_ST_PWR_ON, &is->state);
280
281 ret = fimc_is_start_firmware(is);
282 if (ret < 0) {
283 v4l2_err(sd, "firmware booting failed\n");
284 pm_runtime_put(&is->pdev->dev);
285 return ret;
286 }
287 set_bit(IS_ST_PWR_SUBIP_ON, &is->state);
288
289 ret = fimc_is_hw_initialize(is);
290 } else {
291 /* Close sensor */
292 if (!test_bit(IS_ST_PWR_ON, &is->state)) {
293 fimc_is_hw_close_sensor(is, 0);
294
295 ret = fimc_is_wait_event(is, IS_ST_OPEN_SENSOR, 0,
296 FIMC_IS_CONFIG_TIMEOUT);
297 if (ret < 0) {
298 v4l2_err(sd, "sensor close timeout\n");
299 return ret;
300 }
301 }
302
303 /* SUB IP power off */
304 if (test_bit(IS_ST_PWR_SUBIP_ON, &is->state)) {
305 fimc_is_hw_subip_power_off(is);
306 ret = fimc_is_wait_event(is, IS_ST_PWR_SUBIP_ON, 0,
307 FIMC_IS_CONFIG_TIMEOUT);
308 if (ret < 0) {
309 v4l2_err(sd, "sub-IP power off timeout\n");
310 return ret;
311 }
312 }
313
314 fimc_is_cpu_set_power(is, 0);
315 pm_runtime_put_sync(&is->pdev->dev);
316
317 clear_bit(IS_ST_PWR_ON, &is->state);
318 clear_bit(IS_ST_INIT_DONE, &is->state);
319 is->state = 0;
320 is->config[is->config_index].p_region_index1 = 0;
321 is->config[is->config_index].p_region_index2 = 0;
322 set_bit(IS_ST_IDLE, &is->state);
323 wmb();
324 }
325
326 return ret;
327}
328
329static int fimc_isp_subdev_open(struct v4l2_subdev *sd,
330 struct v4l2_subdev_fh *fh)
331{
332 struct v4l2_mbus_framefmt fmt;
333 struct v4l2_mbus_framefmt *format;
334
335 format = v4l2_subdev_get_try_format(fh, FIMC_ISP_SD_PAD_SINK);
336
337 fmt.colorspace = V4L2_COLORSPACE_SRGB;
338 fmt.code = fimc_isp_formats[0].mbus_code;
339 fmt.width = DEFAULT_PREVIEW_STILL_WIDTH + FIMC_ISP_CAC_MARGIN_WIDTH;
340 fmt.height = DEFAULT_PREVIEW_STILL_HEIGHT + FIMC_ISP_CAC_MARGIN_HEIGHT;
341 fmt.field = V4L2_FIELD_NONE;
342 *format = fmt;
343
344 format = v4l2_subdev_get_try_format(fh, FIMC_ISP_SD_PAD_SRC_FIFO);
345 fmt.width = DEFAULT_PREVIEW_STILL_WIDTH;
346 fmt.height = DEFAULT_PREVIEW_STILL_HEIGHT;
347 *format = fmt;
348
349 format = v4l2_subdev_get_try_format(fh, FIMC_ISP_SD_PAD_SRC_DMA);
350 *format = fmt;
351
352 return 0;
353}
354
355static const struct v4l2_subdev_internal_ops fimc_is_subdev_internal_ops = {
356 .open = fimc_isp_subdev_open,
357};
358
359static const struct v4l2_subdev_pad_ops fimc_is_subdev_pad_ops = {
360 .enum_mbus_code = fimc_is_subdev_enum_mbus_code,
361 .get_fmt = fimc_isp_subdev_get_fmt,
362 .set_fmt = fimc_isp_subdev_set_fmt,
363};
364
365static const struct v4l2_subdev_video_ops fimc_is_subdev_video_ops = {
366 .s_stream = fimc_isp_subdev_s_stream,
367};
368
369static const struct v4l2_subdev_core_ops fimc_is_core_ops = {
370 .s_power = fimc_isp_subdev_s_power,
371};
372
373static struct v4l2_subdev_ops fimc_is_subdev_ops = {
374 .core = &fimc_is_core_ops,
375 .video = &fimc_is_subdev_video_ops,
376 .pad = &fimc_is_subdev_pad_ops,
377};
378
379static int __ctrl_set_white_balance(struct fimc_is *is, int value)
380{
381 switch (value) {
382 case V4L2_WHITE_BALANCE_AUTO:
383 __is_set_isp_awb(is, ISP_AWB_COMMAND_AUTO, 0);
384 break;
385 case V4L2_WHITE_BALANCE_DAYLIGHT:
386 __is_set_isp_awb(is, ISP_AWB_COMMAND_ILLUMINATION,
387 ISP_AWB_ILLUMINATION_DAYLIGHT);
388 break;
389 case V4L2_WHITE_BALANCE_CLOUDY:
390 __is_set_isp_awb(is, ISP_AWB_COMMAND_ILLUMINATION,
391 ISP_AWB_ILLUMINATION_CLOUDY);
392 break;
393 case V4L2_WHITE_BALANCE_INCANDESCENT:
394 __is_set_isp_awb(is, ISP_AWB_COMMAND_ILLUMINATION,
395 ISP_AWB_ILLUMINATION_TUNGSTEN);
396 break;
397 case V4L2_WHITE_BALANCE_FLUORESCENT:
398 __is_set_isp_awb(is, ISP_AWB_COMMAND_ILLUMINATION,
399 ISP_AWB_ILLUMINATION_FLUORESCENT);
400 break;
401 default:
402 return -EINVAL;
403 }
404
405 return 0;
406}
407
408static int __ctrl_set_aewb_lock(struct fimc_is *is,
409 struct v4l2_ctrl *ctrl)
410{
411 bool awb_lock = ctrl->val & V4L2_LOCK_WHITE_BALANCE;
412 bool ae_lock = ctrl->val & V4L2_LOCK_EXPOSURE;
413 struct isp_param *isp = &is->is_p_region->parameter.isp;
414 int cmd, ret;
415
416 cmd = ae_lock ? ISP_AA_COMMAND_STOP : ISP_AA_COMMAND_START;
417 isp->aa.cmd = cmd;
418 isp->aa.target = ISP_AA_TARGET_AE;
419 fimc_is_set_param_bit(is, PARAM_ISP_AA);
420 is->af.ae_lock_state = ae_lock;
421 wmb();
422
423 ret = fimc_is_itf_s_param(is, false);
424 if (ret < 0)
425 return ret;
426
427 cmd = awb_lock ? ISP_AA_COMMAND_STOP : ISP_AA_COMMAND_START;
428 isp->aa.cmd = cmd;
429 isp->aa.target = ISP_AA_TARGET_AE;
430 fimc_is_set_param_bit(is, PARAM_ISP_AA);
431 is->af.awb_lock_state = awb_lock;
432 wmb();
433
434 return fimc_is_itf_s_param(is, false);
435}
436
437/* Supported manual ISO values */
438static const s64 iso_qmenu[] = {
439 50, 100, 200, 400, 800,
440};
441
442static int __ctrl_set_iso(struct fimc_is *is, int value)
443{
444 unsigned int idx, iso;
445
446 if (value == V4L2_ISO_SENSITIVITY_AUTO) {
447 __is_set_isp_iso(is, ISP_ISO_COMMAND_AUTO, 0);
448 return 0;
449 }
450 idx = is->isp.ctrls.iso->val;
451 if (idx >= ARRAY_SIZE(iso_qmenu))
452 return -EINVAL;
453
454 iso = iso_qmenu[idx];
455 __is_set_isp_iso(is, ISP_ISO_COMMAND_MANUAL, iso);
456 return 0;
457}
458
459static int __ctrl_set_metering(struct fimc_is *is, unsigned int value)
460{
461 unsigned int val;
462
463 switch (value) {
464 case V4L2_EXPOSURE_METERING_AVERAGE:
465 val = ISP_METERING_COMMAND_AVERAGE;
466 break;
467 case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
468 val = ISP_METERING_COMMAND_CENTER;
469 break;
470 case V4L2_EXPOSURE_METERING_SPOT:
471 val = ISP_METERING_COMMAND_SPOT;
472 break;
473 case V4L2_EXPOSURE_METERING_MATRIX:
474 val = ISP_METERING_COMMAND_MATRIX;
475 break;
476 default:
477 return -EINVAL;
478 };
479
480 __is_set_isp_metering(is, IS_METERING_CONFIG_CMD, val);
481 return 0;
482}
483
484static int __ctrl_set_afc(struct fimc_is *is, int value)
485{
486 switch (value) {
487 case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
488 __is_set_isp_afc(is, ISP_AFC_COMMAND_DISABLE, 0);
489 break;
490 case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
491 __is_set_isp_afc(is, ISP_AFC_COMMAND_MANUAL, 50);
492 break;
493 case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
494 __is_set_isp_afc(is, ISP_AFC_COMMAND_MANUAL, 60);
495 break;
496 case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
497 __is_set_isp_afc(is, ISP_AFC_COMMAND_AUTO, 0);
498 break;
499 default:
500 return -EINVAL;
501 }
502
503 return 0;
504}
505
506static int __ctrl_set_image_effect(struct fimc_is *is, int value)
507{
508 static const u8 effects[][2] = {
509 { V4L2_COLORFX_NONE, ISP_IMAGE_EFFECT_DISABLE },
510 { V4L2_COLORFX_BW, ISP_IMAGE_EFFECT_MONOCHROME },
511 { V4L2_COLORFX_SEPIA, ISP_IMAGE_EFFECT_SEPIA },
512 { V4L2_COLORFX_NEGATIVE, ISP_IMAGE_EFFECT_NEGATIVE_MONO },
513 { 16 /* TODO */, ISP_IMAGE_EFFECT_NEGATIVE_COLOR },
514 };
515 int i;
516
517 for (i = 0; i < ARRAY_SIZE(effects); i++) {
518 if (effects[i][0] != value)
519 continue;
520
521 __is_set_isp_effect(is, effects[i][1]);
522 return 0;
523 }
524
525 return -EINVAL;
526}
527
528static int fimc_is_s_ctrl(struct v4l2_ctrl *ctrl)
529{
530 struct fimc_isp *isp = ctrl_to_fimc_isp(ctrl);
531 struct fimc_is *is = fimc_isp_to_is(isp);
532 bool set_param = true;
533 int ret = 0;
534
535 switch (ctrl->id) {
536 case V4L2_CID_CONTRAST:
537 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_CONTRAST,
538 ctrl->val);
539 break;
540
541 case V4L2_CID_SATURATION:
542 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_SATURATION,
543 ctrl->val);
544 break;
545
546 case V4L2_CID_SHARPNESS:
547 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_SHARPNESS,
548 ctrl->val);
549 break;
550
551 case V4L2_CID_EXPOSURE_ABSOLUTE:
552 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_EXPOSURE,
553 ctrl->val);
554 break;
555
556 case V4L2_CID_BRIGHTNESS:
557 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_BRIGHTNESS,
558 ctrl->val);
559 break;
560
561 case V4L2_CID_HUE:
562 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_HUE,
563 ctrl->val);
564 break;
565
566 case V4L2_CID_EXPOSURE_METERING:
567 ret = __ctrl_set_metering(is, ctrl->val);
568 break;
569
570 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
571 ret = __ctrl_set_white_balance(is, ctrl->val);
572 break;
573
574 case V4L2_CID_3A_LOCK:
575 ret = __ctrl_set_aewb_lock(is, ctrl);
576 set_param = false;
577 break;
578
579 case V4L2_CID_ISO_SENSITIVITY_AUTO:
580 ret = __ctrl_set_iso(is, ctrl->val);
581 break;
582
583 case V4L2_CID_POWER_LINE_FREQUENCY:
584 ret = __ctrl_set_afc(is, ctrl->val);
585 break;
586
587 case V4L2_CID_COLORFX:
588 __ctrl_set_image_effect(is, ctrl->val);
589 break;
590
591 default:
592 ret = -EINVAL;
593 break;
594 }
595
596 if (ret < 0) {
597 v4l2_err(&isp->subdev, "Failed to set control: %s (%d)\n",
598 ctrl->name, ctrl->val);
599 return ret;
600 }
601
602 if (set_param && test_bit(IS_ST_STREAM_ON, &is->state))
603 return fimc_is_itf_s_param(is, true);
604
605 return 0;
606}
607
608static const struct v4l2_ctrl_ops fimc_isp_ctrl_ops = {
609 .s_ctrl = fimc_is_s_ctrl,
610};
611
612int fimc_isp_subdev_create(struct fimc_isp *isp)
613{
614 const struct v4l2_ctrl_ops *ops = &fimc_isp_ctrl_ops;
615 struct v4l2_ctrl_handler *handler = &isp->ctrls.handler;
616 struct v4l2_subdev *sd = &isp->subdev;
617 struct fimc_isp_ctrls *ctrls = &isp->ctrls;
618 int ret;
619
620 mutex_init(&isp->subdev_lock);
621
622 v4l2_subdev_init(sd, &fimc_is_subdev_ops);
623 sd->grp_id = GRP_ID_FIMC_IS;
624 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
625 snprintf(sd->name, sizeof(sd->name), "FIMC-IS-ISP");
626
627 isp->subdev_pads[FIMC_ISP_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
628 isp->subdev_pads[FIMC_ISP_SD_PAD_SRC_FIFO].flags = MEDIA_PAD_FL_SOURCE;
629 isp->subdev_pads[FIMC_ISP_SD_PAD_SRC_DMA].flags = MEDIA_PAD_FL_SOURCE;
630 ret = media_entity_init(&sd->entity, FIMC_ISP_SD_PADS_NUM,
631 isp->subdev_pads, 0);
632 if (ret)
633 return ret;
634
635 v4l2_ctrl_handler_init(handler, 20);
636
637 ctrls->saturation = v4l2_ctrl_new_std(handler, ops, V4L2_CID_SATURATION,
638 -2, 2, 1, 0);
639 ctrls->brightness = v4l2_ctrl_new_std(handler, ops, V4L2_CID_BRIGHTNESS,
640 -4, 4, 1, 0);
641 ctrls->contrast = v4l2_ctrl_new_std(handler, ops, V4L2_CID_CONTRAST,
642 -2, 2, 1, 0);
643 ctrls->sharpness = v4l2_ctrl_new_std(handler, ops, V4L2_CID_SHARPNESS,
644 -2, 2, 1, 0);
645 ctrls->hue = v4l2_ctrl_new_std(handler, ops, V4L2_CID_HUE,
646 -2, 2, 1, 0);
647
648 ctrls->auto_wb = v4l2_ctrl_new_std_menu(handler, ops,
649 V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
650 8, ~0x14e, V4L2_WHITE_BALANCE_AUTO);
651
652 ctrls->exposure = v4l2_ctrl_new_std(handler, ops,
653 V4L2_CID_EXPOSURE_ABSOLUTE,
654 -4, 4, 1, 0);
655
656 ctrls->exp_metering = v4l2_ctrl_new_std_menu(handler, ops,
657 V4L2_CID_EXPOSURE_METERING, 3,
658 ~0xf, V4L2_EXPOSURE_METERING_AVERAGE);
659
660 v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_POWER_LINE_FREQUENCY,
661 V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
662 V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
663 /* ISO sensitivity */
664 ctrls->auto_iso = v4l2_ctrl_new_std_menu(handler, ops,
665 V4L2_CID_ISO_SENSITIVITY_AUTO, 1, 0,
666 V4L2_ISO_SENSITIVITY_AUTO);
667
668 ctrls->iso = v4l2_ctrl_new_int_menu(handler, ops,
669 V4L2_CID_ISO_SENSITIVITY, ARRAY_SIZE(iso_qmenu) - 1,
670 ARRAY_SIZE(iso_qmenu)/2 - 1, iso_qmenu);
671
672 ctrls->aewb_lock = v4l2_ctrl_new_std(handler, ops,
673 V4L2_CID_3A_LOCK, 0, 0x3, 0, 0);
674
675 /* TODO: Add support for NEGATIVE_COLOR option */
676 ctrls->colorfx = v4l2_ctrl_new_std_menu(handler, ops, V4L2_CID_COLORFX,
677 V4L2_COLORFX_SET_CBCR + 1, ~0x1000f, V4L2_COLORFX_NONE);
678
679 if (handler->error) {
680 media_entity_cleanup(&sd->entity);
681 return handler->error;
682 }
683
684 v4l2_ctrl_auto_cluster(2, &ctrls->auto_iso,
685 V4L2_ISO_SENSITIVITY_MANUAL, false);
686
687 sd->ctrl_handler = handler;
688 sd->internal_ops = &fimc_is_subdev_internal_ops;
689 sd->entity.ops = &fimc_is_subdev_media_ops;
690 v4l2_set_subdevdata(sd, isp);
691
692 return 0;
693}
694
695void fimc_isp_subdev_destroy(struct fimc_isp *isp)
696{
697 struct v4l2_subdev *sd = &isp->subdev;
698
699 v4l2_device_unregister_subdev(sd);
700 media_entity_cleanup(&sd->entity);
701 v4l2_ctrl_handler_free(&isp->ctrls.handler);
702 v4l2_set_subdevdata(sd, NULL);
703}
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.h b/drivers/media/platform/exynos4-is/fimc-isp.h
new file mode 100644
index 000000000000..800aba7ab4a7
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/fimc-isp.h
@@ -0,0 +1,181 @@
1/*
2 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 *
6 * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com>
7 * Younghwan Joo <yhwan.joo@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef FIMC_ISP_H_
14#define FIMC_ISP_H_
15
16#include <linux/io.h>
17#include <linux/platform_device.h>
18#include <linux/sched.h>
19#include <linux/spinlock.h>
20#include <linux/types.h>
21#include <linux/videodev2.h>
22
23#include <media/media-entity.h>
24#include <media/videobuf2-core.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-mediabus.h>
27#include <media/s5p_fimc.h>
28
29/* FIXME: revisit these constraints */
30#define FIMC_ISP_SINK_WIDTH_MIN (16 + 8)
31#define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8)
32#define FIMC_ISP_SOURCE_WIDTH_MIN 8
33#define FIMC_ISP_SOURC_HEIGHT_MIN 8
34#define FIMC_ISP_CAC_MARGIN_WIDTH 16
35#define FIMC_ISP_CAC_MARGIN_HEIGHT 12
36
37#define FIMC_ISP_SINK_WIDTH_MAX (4000 - 16)
38#define FIMC_ISP_SINK_HEIGHT_MAX (4000 + 12)
39#define FIMC_ISP_SOURCE_WIDTH_MAX 4000
40#define FIMC_ISP_SOURC_HEIGHT_MAX 4000
41
42#define FIMC_ISP_NUM_FORMATS 3
43#define FIMC_ISP_REQ_BUFS_MIN 2
44
45#define FIMC_ISP_SD_PAD_SINK 0
46#define FIMC_ISP_SD_PAD_SRC_FIFO 1
47#define FIMC_ISP_SD_PAD_SRC_DMA 2
48#define FIMC_ISP_SD_PADS_NUM 3
49#define FIMC_ISP_MAX_PLANES 1
50
51/**
52 * struct fimc_isp_frame - source/target frame properties
53 * @width: full image width
54 * @height: full image height
55 * @rect: crop/composition rectangle
56 */
57struct fimc_isp_frame {
58 u16 width;
59 u16 height;
60 struct v4l2_rect rect;
61};
62
63struct fimc_isp_ctrls {
64 struct v4l2_ctrl_handler handler;
65
66 /* Auto white balance */
67 struct v4l2_ctrl *auto_wb;
68 /* Auto ISO control cluster */
69 struct {
70 struct v4l2_ctrl *auto_iso;
71 struct v4l2_ctrl *iso;
72 };
73 /* Adjust - contrast */
74 struct v4l2_ctrl *contrast;
75 /* Adjust - saturation */
76 struct v4l2_ctrl *saturation;
77 /* Adjust - sharpness */
78 struct v4l2_ctrl *sharpness;
79 /* Adjust - brightness */
80 struct v4l2_ctrl *brightness;
81 /* Adjust - hue */
82 struct v4l2_ctrl *hue;
83
84 /* Auto/manual exposure */
85 struct v4l2_ctrl *auto_exp;
86 /* Manual exposure value */
87 struct v4l2_ctrl *exposure;
88 /* AE/AWB lock/unlock */
89 struct v4l2_ctrl *aewb_lock;
90 /* Exposure metering mode */
91 struct v4l2_ctrl *exp_metering;
92 /* AFC */
93 struct v4l2_ctrl *afc;
94 /* ISP image effect */
95 struct v4l2_ctrl *colorfx;
96};
97
98/**
99 * struct fimc_is_video - fimc-is video device structure
100 * @vdev: video_device structure
101 * @type: video device type (CAPTURE/OUTPUT)
102 * @pad: video device media (sink) pad
103 * @pending_buf_q: pending buffers queue head
104 * @active_buf_q: a queue head of buffers scheduled in hardware
105 * @vb_queue: vb2 buffer queue
106 * @active_buf_count: number of video buffers scheduled in hardware
107 * @frame_count: counter of frames dequeued to user space
108 * @reqbufs_count: number of buffers requested with REQBUFS ioctl
109 * @format: current pixel format
110 */
111struct fimc_is_video {
112 struct video_device vdev;
113 enum v4l2_buf_type type;
114 struct media_pad pad;
115 struct list_head pending_buf_q;
116 struct list_head active_buf_q;
117 struct vb2_queue vb_queue;
118 unsigned int frame_count;
119 unsigned int reqbufs_count;
120 int streaming;
121 unsigned long payload[FIMC_ISP_MAX_PLANES];
122 const struct fimc_fmt *format;
123};
124
125/**
126 * struct fimc_isp - FIMC-IS ISP data structure
127 * @pdev: pointer to FIMC-IS platform device
128 * @alloc_ctx: videobuf2 memory allocator context
129 * @subdev: ISP v4l2_subdev
130 * @subdev_pads: the ISP subdev media pads
131 * @ctrl_handler: v4l2 controls handler
132 * @test_pattern: test pattern controls
133 * @pipeline: video capture pipeline data structure
134 * @video_lock: mutex serializing video device and the subdev operations
135 * @fmt: pointer to color format description structure
136 * @payload: image size in bytes (w x h x bpp)
137 * @inp_frame: camera input frame structure
138 * @out_frame: DMA output frame structure
139 * @source_subdev_grp_id: group id of remote source subdev
140 * @cac_margin_x: horizontal CAC margin in pixels
141 * @cac_margin_y: vertical CAC margin in pixels
142 * @state: driver state flags
143 * @video_capture: the ISP block video capture device
144 */
145struct fimc_isp {
146 struct platform_device *pdev;
147 struct vb2_alloc_ctx *alloc_ctx;
148 struct v4l2_subdev subdev;
149 struct media_pad subdev_pads[FIMC_ISP_SD_PADS_NUM];
150 struct v4l2_mbus_framefmt subdev_fmt;
151 struct v4l2_ctrl *test_pattern;
152 struct fimc_isp_ctrls ctrls;
153
154 struct mutex video_lock;
155 struct mutex subdev_lock;
156
157 struct fimc_isp_frame inp_frame;
158 struct fimc_isp_frame out_frame;
159 unsigned int source_subdev_grp_id;
160
161 unsigned int cac_margin_x;
162 unsigned int cac_margin_y;
163
164 unsigned long state;
165
166 struct fimc_is_video video_capture;
167};
168
169#define ctrl_to_fimc_isp(_ctrl) \
170 container_of(ctrl->handler, struct fimc_isp, ctrls.handler)
171
172struct fimc_is;
173
174int fimc_isp_subdev_create(struct fimc_isp *isp);
175void fimc_isp_subdev_destroy(struct fimc_isp *isp);
176void fimc_isp_irq_handler(struct fimc_is *is);
177int fimc_is_create_controls(struct fimc_isp *isp);
178int fimc_is_delete_controls(struct fimc_isp *isp);
179const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat,
180 const u32 *mbus_code, int index);
181#endif /* FIMC_ISP_H_ */
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite-reg.c b/drivers/media/platform/exynos4-is/fimc-lite-reg.c
index ac9663ce2a49..8cc0d39a2fea 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite-reg.c
@@ -127,7 +127,7 @@ static const u32 src_pixfmt_map[8][3] = {
127/* Set camera input pixel format and resolution */ 127/* Set camera input pixel format and resolution */
128void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f) 128void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f)
129{ 129{
130 enum v4l2_mbus_pixelcode pixelcode = dev->fmt->mbus_code; 130 enum v4l2_mbus_pixelcode pixelcode = f->fmt->mbus_code;
131 int i = ARRAY_SIZE(src_pixfmt_map); 131 int i = ARRAY_SIZE(src_pixfmt_map);
132 u32 cfg; 132 u32 cfg;
133 133
@@ -227,7 +227,7 @@ static void flite_hw_set_out_order(struct fimc_lite *dev, struct flite_frame *f)
227 int i = ARRAY_SIZE(pixcode); 227 int i = ARRAY_SIZE(pixcode);
228 228
229 while (--i >= 0) 229 while (--i >= 0)
230 if (pixcode[i][0] == dev->fmt->mbus_code) 230 if (pixcode[i][0] == f->fmt->mbus_code)
231 break; 231 break;
232 cfg &= ~FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK; 232 cfg &= ~FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK;
233 writel(cfg | pixcode[i][1], dev->regs + FLITE_REG_CIODMAFMT); 233 writel(cfg | pixcode[i][1], dev->regs + FLITE_REG_CIODMAFMT);
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite-reg.h b/drivers/media/platform/exynos4-is/fimc-lite-reg.h
index 0e345844c13a..390383941c19 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite-reg.h
+++ b/drivers/media/platform/exynos4-is/fimc-lite-reg.h
@@ -72,10 +72,10 @@
72#define FLITE_REG_CIODMAFMT 0x18 72#define FLITE_REG_CIODMAFMT 0x18
73#define FLITE_REG_CIODMAFMT_RAW_CON (1 << 15) 73#define FLITE_REG_CIODMAFMT_RAW_CON (1 << 15)
74#define FLITE_REG_CIODMAFMT_PACK12 (1 << 14) 74#define FLITE_REG_CIODMAFMT_PACK12 (1 << 14)
75#define FLITE_REG_CIODMAFMT_CRYCBY (0 << 4) 75#define FLITE_REG_CIODMAFMT_YCBYCR (0 << 4)
76#define FLITE_REG_CIODMAFMT_CBYCRY (1 << 4) 76#define FLITE_REG_CIODMAFMT_YCRYCB (1 << 4)
77#define FLITE_REG_CIODMAFMT_YCRYCB (2 << 4) 77#define FLITE_REG_CIODMAFMT_CBYCRY (2 << 4)
78#define FLITE_REG_CIODMAFMT_YCBYCR (3 << 4) 78#define FLITE_REG_CIODMAFMT_CRYCBY (3 << 4)
79#define FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK (0x3 << 4) 79#define FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK (0x3 << 4)
80 80
81/* Camera Output Canvas */ 81/* Camera Output Canvas */
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index bbc35de7db27..14bb7bc8adbe 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -11,12 +11,14 @@
11#define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__ 11#define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__
12 12
13#include <linux/bug.h> 13#include <linux/bug.h>
14#include <linux/clk.h>
14#include <linux/device.h> 15#include <linux/device.h>
15#include <linux/errno.h> 16#include <linux/errno.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/list.h> 19#include <linux/list.h>
19#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/of.h>
20#include <linux/types.h> 22#include <linux/types.h>
21#include <linux/platform_device.h> 23#include <linux/platform_device.h>
22#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
@@ -30,7 +32,6 @@
30#include <media/videobuf2-dma-contig.h> 32#include <media/videobuf2-dma-contig.h>
31#include <media/s5p_fimc.h> 33#include <media/s5p_fimc.h>
32 34
33#include "fimc-mdevice.h"
34#include "fimc-core.h" 35#include "fimc-core.h"
35#include "fimc-lite.h" 36#include "fimc-lite.h"
36#include "fimc-lite-reg.h" 37#include "fimc-lite-reg.h"
@@ -46,6 +47,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
46 .color = FIMC_FMT_YCBYCR422, 47 .color = FIMC_FMT_YCBYCR422,
47 .memplanes = 1, 48 .memplanes = 1,
48 .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8, 49 .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
50 .flags = FMT_FLAGS_YUV,
49 }, { 51 }, {
50 .name = "YUV 4:2:2 packed, CbYCrY", 52 .name = "YUV 4:2:2 packed, CbYCrY",
51 .fourcc = V4L2_PIX_FMT_UYVY, 53 .fourcc = V4L2_PIX_FMT_UYVY,
@@ -53,6 +55,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
53 .color = FIMC_FMT_CBYCRY422, 55 .color = FIMC_FMT_CBYCRY422,
54 .memplanes = 1, 56 .memplanes = 1,
55 .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8, 57 .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
58 .flags = FMT_FLAGS_YUV,
56 }, { 59 }, {
57 .name = "YUV 4:2:2 packed, CrYCbY", 60 .name = "YUV 4:2:2 packed, CrYCbY",
58 .fourcc = V4L2_PIX_FMT_VYUY, 61 .fourcc = V4L2_PIX_FMT_VYUY,
@@ -60,6 +63,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
60 .color = FIMC_FMT_CRYCBY422, 63 .color = FIMC_FMT_CRYCBY422,
61 .memplanes = 1, 64 .memplanes = 1,
62 .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8, 65 .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8,
66 .flags = FMT_FLAGS_YUV,
63 }, { 67 }, {
64 .name = "YUV 4:2:2 packed, YCrYCb", 68 .name = "YUV 4:2:2 packed, YCrYCb",
65 .fourcc = V4L2_PIX_FMT_YVYU, 69 .fourcc = V4L2_PIX_FMT_YVYU,
@@ -67,6 +71,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
67 .color = FIMC_FMT_YCRYCB422, 71 .color = FIMC_FMT_YCRYCB422,
68 .memplanes = 1, 72 .memplanes = 1,
69 .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8, 73 .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8,
74 .flags = FMT_FLAGS_YUV,
70 }, { 75 }, {
71 .name = "RAW8 (GRBG)", 76 .name = "RAW8 (GRBG)",
72 .fourcc = V4L2_PIX_FMT_SGRBG8, 77 .fourcc = V4L2_PIX_FMT_SGRBG8,
@@ -74,6 +79,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
74 .color = FIMC_FMT_RAW8, 79 .color = FIMC_FMT_RAW8,
75 .memplanes = 1, 80 .memplanes = 1,
76 .mbus_code = V4L2_MBUS_FMT_SGRBG8_1X8, 81 .mbus_code = V4L2_MBUS_FMT_SGRBG8_1X8,
82 .flags = FMT_FLAGS_RAW_BAYER,
77 }, { 83 }, {
78 .name = "RAW10 (GRBG)", 84 .name = "RAW10 (GRBG)",
79 .fourcc = V4L2_PIX_FMT_SGRBG10, 85 .fourcc = V4L2_PIX_FMT_SGRBG10,
@@ -81,6 +87,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
81 .color = FIMC_FMT_RAW10, 87 .color = FIMC_FMT_RAW10,
82 .memplanes = 1, 88 .memplanes = 1,
83 .mbus_code = V4L2_MBUS_FMT_SGRBG10_1X10, 89 .mbus_code = V4L2_MBUS_FMT_SGRBG10_1X10,
90 .flags = FMT_FLAGS_RAW_BAYER,
84 }, { 91 }, {
85 .name = "RAW12 (GRBG)", 92 .name = "RAW12 (GRBG)",
86 .fourcc = V4L2_PIX_FMT_SGRBG12, 93 .fourcc = V4L2_PIX_FMT_SGRBG12,
@@ -88,6 +95,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
88 .color = FIMC_FMT_RAW12, 95 .color = FIMC_FMT_RAW12,
89 .memplanes = 1, 96 .memplanes = 1,
90 .mbus_code = V4L2_MBUS_FMT_SGRBG12_1X12, 97 .mbus_code = V4L2_MBUS_FMT_SGRBG12_1X12,
98 .flags = FMT_FLAGS_RAW_BAYER,
91 }, 99 },
92}; 100};
93 101
@@ -95,10 +103,11 @@ static const struct fimc_fmt fimc_lite_formats[] = {
95 * fimc_lite_find_format - lookup fimc color format by fourcc or media bus code 103 * fimc_lite_find_format - lookup fimc color format by fourcc or media bus code
96 * @pixelformat: fourcc to match, ignored if null 104 * @pixelformat: fourcc to match, ignored if null
97 * @mbus_code: media bus code to match, ignored if null 105 * @mbus_code: media bus code to match, ignored if null
106 * @mask: the color format flags to match
98 * @index: index to the fimc_lite_formats array, ignored if negative 107 * @index: index to the fimc_lite_formats array, ignored if negative
99 */ 108 */
100static const struct fimc_fmt *fimc_lite_find_format(const u32 *pixelformat, 109static const struct fimc_fmt *fimc_lite_find_format(const u32 *pixelformat,
101 const u32 *mbus_code, int index) 110 const u32 *mbus_code, unsigned int mask, int index)
102{ 111{
103 const struct fimc_fmt *fmt, *def_fmt = NULL; 112 const struct fimc_fmt *fmt, *def_fmt = NULL;
104 unsigned int i; 113 unsigned int i;
@@ -109,6 +118,8 @@ static const struct fimc_fmt *fimc_lite_find_format(const u32 *pixelformat,
109 118
110 for (i = 0; i < ARRAY_SIZE(fimc_lite_formats); ++i) { 119 for (i = 0; i < ARRAY_SIZE(fimc_lite_formats); ++i) {
111 fmt = &fimc_lite_formats[i]; 120 fmt = &fimc_lite_formats[i];
121 if (mask && !(fmt->flags & mask))
122 continue;
112 if (pixelformat && fmt->fourcc == *pixelformat) 123 if (pixelformat && fmt->fourcc == *pixelformat)
113 return fmt; 124 return fmt;
114 if (mbus_code && fmt->mbus_code == *mbus_code) 125 if (mbus_code && fmt->mbus_code == *mbus_code)
@@ -120,26 +131,49 @@ static const struct fimc_fmt *fimc_lite_find_format(const u32 *pixelformat,
120 return def_fmt; 131 return def_fmt;
121} 132}
122 133
134/* Called with the media graph mutex held or @me stream_count > 0. */
135static struct v4l2_subdev *__find_remote_sensor(struct media_entity *me)
136{
137 struct media_pad *pad = &me->pads[0];
138 struct v4l2_subdev *sd;
139
140 while (pad->flags & MEDIA_PAD_FL_SINK) {
141 /* source pad */
142 pad = media_entity_remote_source(pad);
143 if (pad == NULL ||
144 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
145 break;
146
147 sd = media_entity_to_v4l2_subdev(pad->entity);
148
149 if (sd->grp_id == GRP_ID_FIMC_IS_SENSOR ||
150 sd->grp_id == GRP_ID_SENSOR)
151 return sd;
152 /* sink pad */
153 pad = &sd->entity.pads[0];
154 }
155 return NULL;
156}
157
123static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output) 158static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output)
124{ 159{
125 struct fimc_pipeline *pipeline = &fimc->pipeline; 160 struct fimc_source_info *si;
126 struct v4l2_subdev *sensor;
127 struct fimc_sensor_info *si;
128 unsigned long flags; 161 unsigned long flags;
129 162
130 sensor = isp_output ? fimc->sensor : pipeline->subdevs[IDX_SENSOR]; 163 if (fimc->sensor == NULL)
131
132 if (sensor == NULL)
133 return -ENXIO; 164 return -ENXIO;
134 165
135 if (fimc->fmt == NULL) 166 if (fimc->inp_frame.fmt == NULL || fimc->out_frame.fmt == NULL)
136 return -EINVAL; 167 return -EINVAL;
137 168
138 /* Get sensor configuration data from the sensor subdev */ 169 /* Get sensor configuration data from the sensor subdev */
139 si = v4l2_get_subdev_hostdata(sensor); 170 si = v4l2_get_subdev_hostdata(fimc->sensor);
171 if (!si)
172 return -EINVAL;
173
140 spin_lock_irqsave(&fimc->slock, flags); 174 spin_lock_irqsave(&fimc->slock, flags);
141 175
142 flite_hw_set_camera_bus(fimc, &si->pdata); 176 flite_hw_set_camera_bus(fimc, si);
143 flite_hw_set_source_format(fimc, &fimc->inp_frame); 177 flite_hw_set_source_format(fimc, &fimc->inp_frame);
144 flite_hw_set_window_offset(fimc, &fimc->inp_frame); 178 flite_hw_set_window_offset(fimc, &fimc->inp_frame);
145 flite_hw_set_output_dma(fimc, &fimc->out_frame, !isp_output); 179 flite_hw_set_output_dma(fimc, &fimc->out_frame, !isp_output);
@@ -339,13 +373,13 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
339 const struct v4l2_pix_format_mplane *pixm = NULL; 373 const struct v4l2_pix_format_mplane *pixm = NULL;
340 struct fimc_lite *fimc = vq->drv_priv; 374 struct fimc_lite *fimc = vq->drv_priv;
341 struct flite_frame *frame = &fimc->out_frame; 375 struct flite_frame *frame = &fimc->out_frame;
342 const struct fimc_fmt *fmt = fimc->fmt; 376 const struct fimc_fmt *fmt = frame->fmt;
343 unsigned long wh; 377 unsigned long wh;
344 int i; 378 int i;
345 379
346 if (pfmt) { 380 if (pfmt) {
347 pixm = &pfmt->fmt.pix_mp; 381 pixm = &pfmt->fmt.pix_mp;
348 fmt = fimc_lite_find_format(&pixm->pixelformat, NULL, -1); 382 fmt = fimc_lite_find_format(&pixm->pixelformat, NULL, 0, -1);
349 wh = pixm->width * pixm->height; 383 wh = pixm->width * pixm->height;
350 } else { 384 } else {
351 wh = frame->f_width * frame->f_height; 385 wh = frame->f_width * frame->f_height;
@@ -374,10 +408,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
374 struct fimc_lite *fimc = vq->drv_priv; 408 struct fimc_lite *fimc = vq->drv_priv;
375 int i; 409 int i;
376 410
377 if (fimc->fmt == NULL) 411 if (fimc->out_frame.fmt == NULL)
378 return -EINVAL; 412 return -EINVAL;
379 413
380 for (i = 0; i < fimc->fmt->memplanes; i++) { 414 for (i = 0; i < fimc->out_frame.fmt->memplanes; i++) {
381 unsigned long size = fimc->payload[i]; 415 unsigned long size = fimc->payload[i];
382 416
383 if (vb2_plane_size(vb, i) < size) { 417 if (vb2_plane_size(vb, i) < size) {
@@ -425,24 +459,12 @@ static void buffer_queue(struct vb2_buffer *vb)
425 spin_unlock_irqrestore(&fimc->slock, flags); 459 spin_unlock_irqrestore(&fimc->slock, flags);
426} 460}
427 461
428static void fimc_lock(struct vb2_queue *vq)
429{
430 struct fimc_lite *fimc = vb2_get_drv_priv(vq);
431 mutex_lock(&fimc->lock);
432}
433
434static void fimc_unlock(struct vb2_queue *vq)
435{
436 struct fimc_lite *fimc = vb2_get_drv_priv(vq);
437 mutex_unlock(&fimc->lock);
438}
439
440static const struct vb2_ops fimc_lite_qops = { 462static const struct vb2_ops fimc_lite_qops = {
441 .queue_setup = queue_setup, 463 .queue_setup = queue_setup,
442 .buf_prepare = buffer_prepare, 464 .buf_prepare = buffer_prepare,
443 .buf_queue = buffer_queue, 465 .buf_queue = buffer_queue,
444 .wait_prepare = fimc_unlock, 466 .wait_prepare = vb2_ops_wait_prepare,
445 .wait_finish = fimc_lock, 467 .wait_finish = vb2_ops_wait_finish,
446 .start_streaming = start_streaming, 468 .start_streaming = start_streaming,
447 .stop_streaming = stop_streaming, 469 .stop_streaming = stop_streaming,
448}; 470};
@@ -467,99 +489,73 @@ static int fimc_lite_open(struct file *file)
467 mutex_lock(&fimc->lock); 489 mutex_lock(&fimc->lock);
468 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) { 490 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) {
469 ret = -EBUSY; 491 ret = -EBUSY;
470 goto done; 492 goto unlock;
471 } 493 }
472 494
473 set_bit(ST_FLITE_IN_USE, &fimc->state); 495 set_bit(ST_FLITE_IN_USE, &fimc->state);
474 ret = pm_runtime_get_sync(&fimc->pdev->dev); 496 ret = pm_runtime_get_sync(&fimc->pdev->dev);
475 if (ret < 0) 497 if (ret < 0)
476 goto done; 498 goto unlock;
477 499
478 ret = v4l2_fh_open(file); 500 ret = v4l2_fh_open(file);
479 if (ret < 0) 501 if (ret < 0)
480 goto done; 502 goto err_pm;
481 503
482 if (++fimc->ref_count == 1 && 504 if (!v4l2_fh_is_singular_file(file) ||
483 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { 505 atomic_read(&fimc->out_path) != FIMC_IO_DMA)
484 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline, 506 goto unlock;
485 &fimc->vfd.entity, true);
486 if (ret < 0) {
487 pm_runtime_put_sync(&fimc->pdev->dev);
488 fimc->ref_count--;
489 v4l2_fh_release(file);
490 clear_bit(ST_FLITE_IN_USE, &fimc->state);
491 }
492 507
508 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline,
509 me, true);
510 if (!ret) {
493 fimc_lite_clear_event_counters(fimc); 511 fimc_lite_clear_event_counters(fimc);
512 fimc->ref_count++;
513 goto unlock;
494 } 514 }
495done: 515
516 v4l2_fh_release(file);
517err_pm:
518 pm_runtime_put_sync(&fimc->pdev->dev);
519 clear_bit(ST_FLITE_IN_USE, &fimc->state);
520unlock:
496 mutex_unlock(&fimc->lock); 521 mutex_unlock(&fimc->lock);
497 mutex_unlock(&me->parent->graph_mutex); 522 mutex_unlock(&me->parent->graph_mutex);
498 return ret; 523 return ret;
499} 524}
500 525
501static int fimc_lite_close(struct file *file) 526static int fimc_lite_release(struct file *file)
502{ 527{
503 struct fimc_lite *fimc = video_drvdata(file); 528 struct fimc_lite *fimc = video_drvdata(file);
504 int ret;
505 529
506 mutex_lock(&fimc->lock); 530 mutex_lock(&fimc->lock);
507 531
508 if (--fimc->ref_count == 0 && 532 if (v4l2_fh_is_singular_file(file) &&
509 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { 533 atomic_read(&fimc->out_path) == FIMC_IO_DMA) {
534 if (fimc->streaming) {
535 media_entity_pipeline_stop(&fimc->vfd.entity);
536 fimc->streaming = false;
537 }
510 clear_bit(ST_FLITE_IN_USE, &fimc->state); 538 clear_bit(ST_FLITE_IN_USE, &fimc->state);
511 fimc_lite_stop_capture(fimc, false); 539 fimc_lite_stop_capture(fimc, false);
512 fimc_pipeline_call(fimc, close, &fimc->pipeline); 540 fimc_pipeline_call(fimc, close, &fimc->pipeline);
513 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); 541 fimc->ref_count--;
514 } 542 }
515 543
544 vb2_fop_release(file);
516 pm_runtime_put(&fimc->pdev->dev); 545 pm_runtime_put(&fimc->pdev->dev);
546 clear_bit(ST_FLITE_SUSPENDED, &fimc->state);
517 547
518 if (fimc->ref_count == 0)
519 vb2_queue_release(&fimc->vb_queue);
520
521 ret = v4l2_fh_release(file);
522
523 mutex_unlock(&fimc->lock);
524 return ret;
525}
526
527static unsigned int fimc_lite_poll(struct file *file,
528 struct poll_table_struct *wait)
529{
530 struct fimc_lite *fimc = video_drvdata(file);
531 int ret;
532
533 if (mutex_lock_interruptible(&fimc->lock))
534 return POLL_ERR;
535
536 ret = vb2_poll(&fimc->vb_queue, file, wait);
537 mutex_unlock(&fimc->lock);
538
539 return ret;
540}
541
542static int fimc_lite_mmap(struct file *file, struct vm_area_struct *vma)
543{
544 struct fimc_lite *fimc = video_drvdata(file);
545 int ret;
546
547 if (mutex_lock_interruptible(&fimc->lock))
548 return -ERESTARTSYS;
549
550 ret = vb2_mmap(&fimc->vb_queue, vma);
551 mutex_unlock(&fimc->lock); 548 mutex_unlock(&fimc->lock);
552 549 return 0;
553 return ret;
554} 550}
555 551
556static const struct v4l2_file_operations fimc_lite_fops = { 552static const struct v4l2_file_operations fimc_lite_fops = {
557 .owner = THIS_MODULE, 553 .owner = THIS_MODULE,
558 .open = fimc_lite_open, 554 .open = fimc_lite_open,
559 .release = fimc_lite_close, 555 .release = fimc_lite_release,
560 .poll = fimc_lite_poll, 556 .poll = vb2_fop_poll,
561 .unlocked_ioctl = video_ioctl2, 557 .unlocked_ioctl = video_ioctl2,
562 .mmap = fimc_lite_mmap, 558 .mmap = vb2_fop_mmap,
563}; 559};
564 560
565/* 561/*
@@ -570,10 +566,23 @@ static const struct fimc_fmt *fimc_lite_try_format(struct fimc_lite *fimc,
570 u32 *width, u32 *height, 566 u32 *width, u32 *height,
571 u32 *code, u32 *fourcc, int pad) 567 u32 *code, u32 *fourcc, int pad)
572{ 568{
573 struct flite_variant *variant = fimc->variant; 569 struct flite_drvdata *dd = fimc->dd;
574 const struct fimc_fmt *fmt; 570 const struct fimc_fmt *fmt;
571 unsigned int flags = 0;
575 572
576 fmt = fimc_lite_find_format(fourcc, code, 0); 573 if (pad == FLITE_SD_PAD_SINK) {
574 v4l_bound_align_image(width, 8, dd->max_width,
575 ffs(dd->out_width_align) - 1,
576 height, 0, dd->max_height, 0, 0);
577 } else {
578 v4l_bound_align_image(width, 8, fimc->inp_frame.rect.width,
579 ffs(dd->out_width_align) - 1,
580 height, 0, fimc->inp_frame.rect.height,
581 0, 0);
582 flags = fimc->inp_frame.fmt->flags;
583 }
584
585 fmt = fimc_lite_find_format(fourcc, code, flags, 0);
577 if (WARN_ON(!fmt)) 586 if (WARN_ON(!fmt))
578 return NULL; 587 return NULL;
579 588
@@ -582,17 +591,6 @@ static const struct fimc_fmt *fimc_lite_try_format(struct fimc_lite *fimc,
582 if (fourcc) 591 if (fourcc)
583 *fourcc = fmt->fourcc; 592 *fourcc = fmt->fourcc;
584 593
585 if (pad == FLITE_SD_PAD_SINK) {
586 v4l_bound_align_image(width, 8, variant->max_width,
587 ffs(variant->out_width_align) - 1,
588 height, 0, variant->max_height, 0, 0);
589 } else {
590 v4l_bound_align_image(width, 8, fimc->inp_frame.rect.width,
591 ffs(variant->out_width_align) - 1,
592 height, 0, fimc->inp_frame.rect.height,
593 0, 0);
594 }
595
596 v4l2_dbg(1, debug, &fimc->subdev, "code: 0x%x, %dx%d\n", 594 v4l2_dbg(1, debug, &fimc->subdev, "code: 0x%x, %dx%d\n",
597 code ? *code : 0, *width, *height); 595 code ? *code : 0, *width, *height);
598 596
@@ -608,7 +606,7 @@ static void fimc_lite_try_crop(struct fimc_lite *fimc, struct v4l2_rect *r)
608 606
609 /* Adjust left/top if cropping rectangle got out of bounds */ 607 /* Adjust left/top if cropping rectangle got out of bounds */
610 r->left = clamp_t(u32, r->left, 0, frame->f_width - r->width); 608 r->left = clamp_t(u32, r->left, 0, frame->f_width - r->width);
611 r->left = round_down(r->left, fimc->variant->win_hor_offs_align); 609 r->left = round_down(r->left, fimc->dd->win_hor_offs_align);
612 r->top = clamp_t(u32, r->top, 0, frame->f_height - r->height); 610 r->top = clamp_t(u32, r->top, 0, frame->f_height - r->height);
613 611
614 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, sink fmt: %dx%d\n", 612 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, sink fmt: %dx%d\n",
@@ -628,7 +626,7 @@ static void fimc_lite_try_compose(struct fimc_lite *fimc, struct v4l2_rect *r)
628 626
629 /* Adjust left/top if the composing rectangle got out of bounds */ 627 /* Adjust left/top if the composing rectangle got out of bounds */
630 r->left = clamp_t(u32, r->left, 0, frame->f_width - r->width); 628 r->left = clamp_t(u32, r->left, 0, frame->f_width - r->width);
631 r->left = round_down(r->left, fimc->variant->out_hor_offs_align); 629 r->left = round_down(r->left, fimc->dd->out_hor_offs_align);
632 r->top = clamp_t(u32, r->top, 0, fimc->out_frame.f_height - r->height); 630 r->top = clamp_t(u32, r->top, 0, fimc->out_frame.f_height - r->height);
633 631
634 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, source fmt: %dx%d\n", 632 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, source fmt: %dx%d\n",
@@ -671,7 +669,7 @@ static int fimc_lite_g_fmt_mplane(struct file *file, void *fh,
671 struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; 669 struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
672 struct v4l2_plane_pix_format *plane_fmt = &pixm->plane_fmt[0]; 670 struct v4l2_plane_pix_format *plane_fmt = &pixm->plane_fmt[0];
673 struct flite_frame *frame = &fimc->out_frame; 671 struct flite_frame *frame = &fimc->out_frame;
674 const struct fimc_fmt *fmt = fimc->fmt; 672 const struct fimc_fmt *fmt = frame->fmt;
675 673
676 plane_fmt->bytesperline = (frame->f_width * fmt->depth[0]) / 8; 674 plane_fmt->bytesperline = (frame->f_width * fmt->depth[0]) / 8;
677 plane_fmt->sizeimage = plane_fmt->bytesperline * frame->f_height; 675 plane_fmt->sizeimage = plane_fmt->bytesperline * frame->f_height;
@@ -689,18 +687,31 @@ static int fimc_lite_try_fmt(struct fimc_lite *fimc,
689 struct v4l2_pix_format_mplane *pixm, 687 struct v4l2_pix_format_mplane *pixm,
690 const struct fimc_fmt **ffmt) 688 const struct fimc_fmt **ffmt)
691{ 689{
692 struct flite_variant *variant = fimc->variant;
693 u32 bpl = pixm->plane_fmt[0].bytesperline; 690 u32 bpl = pixm->plane_fmt[0].bytesperline;
691 struct flite_drvdata *dd = fimc->dd;
692 const struct fimc_fmt *inp_fmt = fimc->inp_frame.fmt;
694 const struct fimc_fmt *fmt; 693 const struct fimc_fmt *fmt;
695 694
696 fmt = fimc_lite_find_format(&pixm->pixelformat, NULL, 0); 695 if (WARN_ON(inp_fmt == NULL))
696 return -EINVAL;
697 /*
698 * We allow some flexibility only for YUV formats. In case of raw
699 * raw Bayer the FIMC-LITE's output format must match its camera
700 * interface input format.
701 */
702 if (inp_fmt->flags & FMT_FLAGS_YUV)
703 fmt = fimc_lite_find_format(&pixm->pixelformat, NULL,
704 inp_fmt->flags, 0);
705 else
706 fmt = inp_fmt;
707
697 if (WARN_ON(fmt == NULL)) 708 if (WARN_ON(fmt == NULL))
698 return -EINVAL; 709 return -EINVAL;
699 if (ffmt) 710 if (ffmt)
700 *ffmt = fmt; 711 *ffmt = fmt;
701 v4l_bound_align_image(&pixm->width, 8, variant->max_width, 712 v4l_bound_align_image(&pixm->width, 8, dd->max_width,
702 ffs(variant->out_width_align) - 1, 713 ffs(dd->out_width_align) - 1,
703 &pixm->height, 0, variant->max_height, 0, 0); 714 &pixm->height, 0, dd->max_height, 0, 0);
704 715
705 if ((bpl == 0 || ((bpl * 8) / fmt->depth[0]) < pixm->width)) 716 if ((bpl == 0 || ((bpl * 8) / fmt->depth[0]) < pixm->width))
706 pixm->plane_fmt[0].bytesperline = (pixm->width * 717 pixm->plane_fmt[0].bytesperline = (pixm->width *
@@ -720,7 +731,6 @@ static int fimc_lite_try_fmt_mplane(struct file *file, void *fh,
720 struct v4l2_format *f) 731 struct v4l2_format *f)
721{ 732{
722 struct fimc_lite *fimc = video_drvdata(file); 733 struct fimc_lite *fimc = video_drvdata(file);
723
724 return fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, NULL); 734 return fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, NULL);
725} 735}
726 736
@@ -740,7 +750,7 @@ static int fimc_lite_s_fmt_mplane(struct file *file, void *priv,
740 if (ret < 0) 750 if (ret < 0)
741 return ret; 751 return ret;
742 752
743 fimc->fmt = fmt; 753 frame->fmt = fmt;
744 fimc->payload[0] = max((pixm->width * pixm->height * fmt->depth[0]) / 8, 754 fimc->payload[0] = max((pixm->width * pixm->height * fmt->depth[0]) / 8,
745 pixm->plane_fmt[0].sizeimage); 755 pixm->plane_fmt[0].sizeimage);
746 frame->f_width = pixm->width; 756 frame->f_width = pixm->width;
@@ -766,7 +776,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
766 struct flite_frame *ff = &fimc->out_frame; 776 struct flite_frame *ff = &fimc->out_frame;
767 sink_fmt.format.width = ff->f_width; 777 sink_fmt.format.width = ff->f_width;
768 sink_fmt.format.height = ff->f_height; 778 sink_fmt.format.height = ff->f_height;
769 sink_fmt.format.code = fimc->fmt->mbus_code; 779 sink_fmt.format.code = fimc->inp_frame.fmt->mbus_code;
770 } else { 780 } else {
771 sink_fmt.pad = pad->index; 781 sink_fmt.pad = pad->index;
772 sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 782 sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
@@ -800,37 +810,47 @@ static int fimc_lite_streamon(struct file *file, void *priv,
800 enum v4l2_buf_type type) 810 enum v4l2_buf_type type)
801{ 811{
802 struct fimc_lite *fimc = video_drvdata(file); 812 struct fimc_lite *fimc = video_drvdata(file);
803 struct v4l2_subdev *sensor = fimc->pipeline.subdevs[IDX_SENSOR]; 813 struct media_entity *entity = &fimc->vfd.entity;
804 struct fimc_pipeline *p = &fimc->pipeline; 814 struct fimc_pipeline *p = &fimc->pipeline;
805 int ret; 815 int ret;
806 816
807 if (fimc_lite_active(fimc)) 817 if (fimc_lite_active(fimc))
808 return -EBUSY; 818 return -EBUSY;
809 819
810 ret = media_entity_pipeline_start(&sensor->entity, p->m_pipeline); 820 ret = media_entity_pipeline_start(entity, p->m_pipeline);
811 if (ret < 0) 821 if (ret < 0)
812 return ret; 822 return ret;
813 823
814 ret = fimc_pipeline_validate(fimc); 824 ret = fimc_pipeline_validate(fimc);
815 if (ret) { 825 if (ret < 0)
816 media_entity_pipeline_stop(&sensor->entity); 826 goto err_p_stop;
827
828 fimc->sensor = __find_remote_sensor(&fimc->subdev.entity);
829
830 ret = vb2_ioctl_streamon(file, priv, type);
831 if (!ret) {
832 fimc->streaming = true;
817 return ret; 833 return ret;
818 } 834 }
819 835
820 return vb2_streamon(&fimc->vb_queue, type); 836err_p_stop:
837 media_entity_pipeline_stop(entity);
838 return 0;
821} 839}
822 840
823static int fimc_lite_streamoff(struct file *file, void *priv, 841static int fimc_lite_streamoff(struct file *file, void *priv,
824 enum v4l2_buf_type type) 842 enum v4l2_buf_type type)
825{ 843{
826 struct fimc_lite *fimc = video_drvdata(file); 844 struct fimc_lite *fimc = video_drvdata(file);
827 struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR];
828 int ret; 845 int ret;
829 846
830 ret = vb2_streamoff(&fimc->vb_queue, type); 847 ret = vb2_ioctl_streamoff(file, priv, type);
831 if (ret == 0) 848 if (ret < 0)
832 media_entity_pipeline_stop(&sd->entity); 849 return ret;
833 return ret; 850
851 media_entity_pipeline_stop(&fimc->vfd.entity);
852 fimc->streaming = false;
853 return 0;
834} 854}
835 855
836static int fimc_lite_reqbufs(struct file *file, void *priv, 856static int fimc_lite_reqbufs(struct file *file, void *priv,
@@ -840,53 +860,13 @@ static int fimc_lite_reqbufs(struct file *file, void *priv,
840 int ret; 860 int ret;
841 861
842 reqbufs->count = max_t(u32, FLITE_REQ_BUFS_MIN, reqbufs->count); 862 reqbufs->count = max_t(u32, FLITE_REQ_BUFS_MIN, reqbufs->count);
843 ret = vb2_reqbufs(&fimc->vb_queue, reqbufs); 863 ret = vb2_ioctl_reqbufs(file, priv, reqbufs);
844 if (!ret) 864 if (!ret)
845 fimc->reqbufs_count = reqbufs->count; 865 fimc->reqbufs_count = reqbufs->count;
846 866
847 return ret; 867 return ret;
848} 868}
849 869
850static int fimc_lite_querybuf(struct file *file, void *priv,
851 struct v4l2_buffer *buf)
852{
853 struct fimc_lite *fimc = video_drvdata(file);
854
855 return vb2_querybuf(&fimc->vb_queue, buf);
856}
857
858static int fimc_lite_qbuf(struct file *file, void *priv,
859 struct v4l2_buffer *buf)
860{
861 struct fimc_lite *fimc = video_drvdata(file);
862
863 return vb2_qbuf(&fimc->vb_queue, buf);
864}
865
866static int fimc_lite_dqbuf(struct file *file, void *priv,
867 struct v4l2_buffer *buf)
868{
869 struct fimc_lite *fimc = video_drvdata(file);
870
871 return vb2_dqbuf(&fimc->vb_queue, buf, file->f_flags & O_NONBLOCK);
872}
873
874static int fimc_lite_create_bufs(struct file *file, void *priv,
875 struct v4l2_create_buffers *create)
876{
877 struct fimc_lite *fimc = video_drvdata(file);
878
879 return vb2_create_bufs(&fimc->vb_queue, create);
880}
881
882static int fimc_lite_prepare_buf(struct file *file, void *priv,
883 struct v4l2_buffer *b)
884{
885 struct fimc_lite *fimc = video_drvdata(file);
886
887 return vb2_prepare_buf(&fimc->vb_queue, b);
888}
889
890/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */ 870/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
891static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b) 871static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
892{ 872{
@@ -966,38 +946,15 @@ static const struct v4l2_ioctl_ops fimc_lite_ioctl_ops = {
966 .vidioc_g_selection = fimc_lite_g_selection, 946 .vidioc_g_selection = fimc_lite_g_selection,
967 .vidioc_s_selection = fimc_lite_s_selection, 947 .vidioc_s_selection = fimc_lite_s_selection,
968 .vidioc_reqbufs = fimc_lite_reqbufs, 948 .vidioc_reqbufs = fimc_lite_reqbufs,
969 .vidioc_querybuf = fimc_lite_querybuf, 949 .vidioc_querybuf = vb2_ioctl_querybuf,
970 .vidioc_prepare_buf = fimc_lite_prepare_buf, 950 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
971 .vidioc_create_bufs = fimc_lite_create_bufs, 951 .vidioc_create_bufs = vb2_ioctl_create_bufs,
972 .vidioc_qbuf = fimc_lite_qbuf, 952 .vidioc_qbuf = vb2_ioctl_qbuf,
973 .vidioc_dqbuf = fimc_lite_dqbuf, 953 .vidioc_dqbuf = vb2_ioctl_dqbuf,
974 .vidioc_streamon = fimc_lite_streamon, 954 .vidioc_streamon = fimc_lite_streamon,
975 .vidioc_streamoff = fimc_lite_streamoff, 955 .vidioc_streamoff = fimc_lite_streamoff,
976}; 956};
977 957
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
1001/* Capture subdev media entity operations */ 958/* Capture subdev media entity operations */
1002static int fimc_lite_link_setup(struct media_entity *entity, 959static int fimc_lite_link_setup(struct media_entity *entity,
1003 const struct media_pad *local, 960 const struct media_pad *local,
@@ -1072,7 +1029,7 @@ static int fimc_lite_subdev_enum_mbus_code(struct v4l2_subdev *sd,
1072{ 1029{
1073 const struct fimc_fmt *fmt; 1030 const struct fimc_fmt *fmt;
1074 1031
1075 fmt = fimc_lite_find_format(NULL, NULL, code->index); 1032 fmt = fimc_lite_find_format(NULL, NULL, 0, code->index);
1076 if (!fmt) 1033 if (!fmt)
1077 return -EINVAL; 1034 return -EINVAL;
1078 code->code = fmt->mbus_code; 1035 code->code = fmt->mbus_code;
@@ -1085,7 +1042,7 @@ static int fimc_lite_subdev_get_fmt(struct v4l2_subdev *sd,
1085{ 1042{
1086 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); 1043 struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
1087 struct v4l2_mbus_framefmt *mf = &fmt->format; 1044 struct v4l2_mbus_framefmt *mf = &fmt->format;
1088 struct flite_frame *f = &fimc->out_frame; 1045 struct flite_frame *f = &fimc->inp_frame;
1089 1046
1090 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 1047 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1091 mf = v4l2_subdev_get_try_format(fh, fmt->pad); 1048 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
@@ -1095,7 +1052,7 @@ static int fimc_lite_subdev_get_fmt(struct v4l2_subdev *sd,
1095 mf->colorspace = V4L2_COLORSPACE_JPEG; 1052 mf->colorspace = V4L2_COLORSPACE_JPEG;
1096 1053
1097 mutex_lock(&fimc->lock); 1054 mutex_lock(&fimc->lock);
1098 mf->code = fimc->fmt->mbus_code; 1055 mf->code = f->fmt->mbus_code;
1099 1056
1100 if (fmt->pad == FLITE_SD_PAD_SINK) { 1057 if (fmt->pad == FLITE_SD_PAD_SINK) {
1101 /* full camera input frame size */ 1058 /* full camera input frame size */
@@ -1147,7 +1104,7 @@ static int fimc_lite_subdev_set_fmt(struct v4l2_subdev *sd,
1147 if (fmt->pad == FLITE_SD_PAD_SINK) { 1104 if (fmt->pad == FLITE_SD_PAD_SINK) {
1148 sink->f_width = mf->width; 1105 sink->f_width = mf->width;
1149 sink->f_height = mf->height; 1106 sink->f_height = mf->height;
1150 fimc->fmt = ffmt; 1107 sink->fmt = ffmt;
1151 /* Set sink crop rectangle */ 1108 /* Set sink crop rectangle */
1152 sink->rect.width = mf->width; 1109 sink->rect.width = mf->width;
1153 sink->rect.height = mf->height; 1110 sink->rect.height = mf->height;
@@ -1159,7 +1116,7 @@ static int fimc_lite_subdev_set_fmt(struct v4l2_subdev *sd,
1159 source->f_height = mf->height; 1116 source->f_height = mf->height;
1160 } else { 1117 } else {
1161 /* Allow changing format only on sink pad */ 1118 /* Allow changing format only on sink pad */
1162 mf->code = fimc->fmt->mbus_code; 1119 mf->code = sink->fmt->mbus_code;
1163 mf->width = sink->rect.width; 1120 mf->width = sink->rect.width;
1164 mf->height = sink->rect.height; 1121 mf->height = sink->rect.height;
1165 } 1122 }
@@ -1300,7 +1257,8 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1300 1257
1301 memset(vfd, 0, sizeof(*vfd)); 1258 memset(vfd, 0, sizeof(*vfd));
1302 1259
1303 fimc->fmt = &fimc_lite_formats[0]; 1260 fimc->inp_frame.fmt = &fimc_lite_formats[0];
1261 fimc->out_frame.fmt = &fimc_lite_formats[0];
1304 atomic_set(&fimc->out_path, FIMC_IO_DMA); 1262 atomic_set(&fimc->out_path, FIMC_IO_DMA);
1305 1263
1306 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture", 1264 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture",
@@ -1311,8 +1269,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1311 vfd->v4l2_dev = sd->v4l2_dev; 1269 vfd->v4l2_dev = sd->v4l2_dev;
1312 vfd->minor = -1; 1270 vfd->minor = -1;
1313 vfd->release = video_device_release_empty; 1271 vfd->release = video_device_release_empty;
1314 vfd->lock = &fimc->lock; 1272 vfd->queue = q;
1315 fimc->ref_count = 0;
1316 fimc->reqbufs_count = 0; 1273 fimc->reqbufs_count = 0;
1317 1274
1318 INIT_LIST_HEAD(&fimc->pending_buf_q); 1275 INIT_LIST_HEAD(&fimc->pending_buf_q);
@@ -1325,6 +1282,8 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1325 q->mem_ops = &vb2_dma_contig_memops; 1282 q->mem_ops = &vb2_dma_contig_memops;
1326 q->buf_struct_size = sizeof(struct flite_buffer); 1283 q->buf_struct_size = sizeof(struct flite_buffer);
1327 q->drv_priv = fimc; 1284 q->drv_priv = fimc;
1285 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1286 q->lock = &fimc->lock;
1328 1287
1329 ret = vb2_queue_init(q); 1288 ret = vb2_queue_init(q);
1330 if (ret < 0) 1289 if (ret < 0)
@@ -1418,7 +1377,7 @@ static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc)
1418 int ret; 1377 int ret;
1419 1378
1420 v4l2_subdev_init(sd, &fimc_lite_subdev_ops); 1379 v4l2_subdev_init(sd, &fimc_lite_subdev_ops);
1421 sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE; 1380 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1422 snprintf(sd->name, sizeof(sd->name), "FIMC-LITE.%d", fimc->index); 1381 snprintf(sd->name, sizeof(sd->name), "FIMC-LITE.%d", fimc->index);
1423 1382
1424 fimc->subdev_pads[FLITE_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK; 1383 fimc->subdev_pads[FLITE_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
@@ -1440,6 +1399,7 @@ static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc)
1440 sd->ctrl_handler = handler; 1399 sd->ctrl_handler = handler;
1441 sd->internal_ops = &fimc_lite_subdev_internal_ops; 1400 sd->internal_ops = &fimc_lite_subdev_internal_ops;
1442 sd->entity.ops = &fimc_lite_subdev_media_ops; 1401 sd->entity.ops = &fimc_lite_subdev_media_ops;
1402 sd->owner = THIS_MODULE;
1443 v4l2_set_subdevdata(sd, fimc); 1403 v4l2_set_subdevdata(sd, fimc);
1444 1404
1445 return 0; 1405 return 0;
@@ -1481,19 +1441,35 @@ static int fimc_lite_clk_get(struct fimc_lite *fimc)
1481 return ret; 1441 return ret;
1482} 1442}
1483 1443
1444static const struct of_device_id flite_of_match[];
1445
1484static int fimc_lite_probe(struct platform_device *pdev) 1446static int fimc_lite_probe(struct platform_device *pdev)
1485{ 1447{
1486 struct flite_drvdata *drv_data = fimc_lite_get_drvdata(pdev); 1448 struct flite_drvdata *drv_data = NULL;
1449 struct device *dev = &pdev->dev;
1450 const struct of_device_id *of_id;
1487 struct fimc_lite *fimc; 1451 struct fimc_lite *fimc;
1488 struct resource *res; 1452 struct resource *res;
1489 int ret; 1453 int ret;
1490 1454
1491 fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL); 1455 fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL);
1492 if (!fimc) 1456 if (!fimc)
1493 return -ENOMEM; 1457 return -ENOMEM;
1494 1458
1495 fimc->index = pdev->id; 1459 if (dev->of_node) {
1496 fimc->variant = drv_data->variant[fimc->index]; 1460 of_id = of_match_node(flite_of_match, dev->of_node);
1461 if (of_id)
1462 drv_data = (struct flite_drvdata *)of_id->data;
1463 fimc->index = of_alias_get_id(dev->of_node, "fimc-lite");
1464 } else {
1465 drv_data = fimc_lite_get_drvdata(pdev);
1466 fimc->index = pdev->id;
1467 }
1468
1469 if (!drv_data || fimc->index < 0 || fimc->index >= FIMC_LITE_MAX_DEVS)
1470 return -EINVAL;
1471
1472 fimc->dd = drv_data;
1497 fimc->pdev = pdev; 1473 fimc->pdev = pdev;
1498 1474
1499 init_waitqueue_head(&fimc->irq_queue); 1475 init_waitqueue_head(&fimc->irq_queue);
@@ -1501,13 +1477,13 @@ static int fimc_lite_probe(struct platform_device *pdev)
1501 mutex_init(&fimc->lock); 1477 mutex_init(&fimc->lock);
1502 1478
1503 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1479 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1504 fimc->regs = devm_ioremap_resource(&pdev->dev, res); 1480 fimc->regs = devm_ioremap_resource(dev, res);
1505 if (IS_ERR(fimc->regs)) 1481 if (IS_ERR(fimc->regs))
1506 return PTR_ERR(fimc->regs); 1482 return PTR_ERR(fimc->regs);
1507 1483
1508 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1484 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1509 if (res == NULL) { 1485 if (res == NULL) {
1510 dev_err(&pdev->dev, "Failed to get IRQ resource\n"); 1486 dev_err(dev, "Failed to get IRQ resource\n");
1511 return -ENXIO; 1487 return -ENXIO;
1512 } 1488 }
1513 1489
@@ -1515,10 +1491,10 @@ static int fimc_lite_probe(struct platform_device *pdev)
1515 if (ret) 1491 if (ret)
1516 return ret; 1492 return ret;
1517 1493
1518 ret = devm_request_irq(&pdev->dev, res->start, flite_irq_handler, 1494 ret = devm_request_irq(dev, res->start, flite_irq_handler,
1519 0, dev_name(&pdev->dev), fimc); 1495 0, dev_name(dev), fimc);
1520 if (ret) { 1496 if (ret) {
1521 dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret); 1497 dev_err(dev, "Failed to install irq (%d)\n", ret);
1522 goto err_clk; 1498 goto err_clk;
1523 } 1499 }
1524 1500
@@ -1528,23 +1504,23 @@ static int fimc_lite_probe(struct platform_device *pdev)
1528 goto err_clk; 1504 goto err_clk;
1529 1505
1530 platform_set_drvdata(pdev, fimc); 1506 platform_set_drvdata(pdev, fimc);
1531 pm_runtime_enable(&pdev->dev); 1507 pm_runtime_enable(dev);
1532 ret = pm_runtime_get_sync(&pdev->dev); 1508 ret = pm_runtime_get_sync(dev);
1533 if (ret < 0) 1509 if (ret < 0)
1534 goto err_sd; 1510 goto err_sd;
1535 1511
1536 fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1512 fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev);
1537 if (IS_ERR(fimc->alloc_ctx)) { 1513 if (IS_ERR(fimc->alloc_ctx)) {
1538 ret = PTR_ERR(fimc->alloc_ctx); 1514 ret = PTR_ERR(fimc->alloc_ctx);
1539 goto err_pm; 1515 goto err_pm;
1540 } 1516 }
1541 pm_runtime_put(&pdev->dev); 1517 pm_runtime_put(dev);
1542 1518
1543 dev_dbg(&pdev->dev, "FIMC-LITE.%d registered successfully\n", 1519 dev_dbg(dev, "FIMC-LITE.%d registered successfully\n",
1544 fimc->index); 1520 fimc->index);
1545 return 0; 1521 return 0;
1546err_pm: 1522err_pm:
1547 pm_runtime_put(&pdev->dev); 1523 pm_runtime_put(dev);
1548err_sd: 1524err_sd:
1549 fimc_lite_unregister_capture_subdev(fimc); 1525 fimc_lite_unregister_capture_subdev(fimc);
1550err_clk: 1526err_clk:
@@ -1635,7 +1611,14 @@ static int fimc_lite_remove(struct platform_device *pdev)
1635 return 0; 1611 return 0;
1636} 1612}
1637 1613
1638static struct flite_variant fimc_lite0_variant_exynos4 = { 1614static const struct dev_pm_ops fimc_lite_pm_ops = {
1615 SET_SYSTEM_SLEEP_PM_OPS(fimc_lite_suspend, fimc_lite_resume)
1616 SET_RUNTIME_PM_OPS(fimc_lite_runtime_suspend, fimc_lite_runtime_resume,
1617 NULL)
1618};
1619
1620/* EXYNOS4212, EXYNOS4412 */
1621static struct flite_drvdata fimc_lite_drvdata_exynos4 = {
1639 .max_width = 8192, 1622 .max_width = 8192,
1640 .max_height = 8192, 1623 .max_height = 8192,
1641 .out_width_align = 8, 1624 .out_width_align = 8,
@@ -1643,14 +1626,6 @@ static struct flite_variant fimc_lite0_variant_exynos4 = {
1643 .out_hor_offs_align = 8, 1626 .out_hor_offs_align = 8,
1644}; 1627};
1645 1628
1646/* EXYNOS4212, EXYNOS4412 */
1647static struct flite_drvdata fimc_lite_drvdata_exynos4 = {
1648 .variant = {
1649 [0] = &fimc_lite0_variant_exynos4,
1650 [1] = &fimc_lite0_variant_exynos4,
1651 },
1652};
1653
1654static struct platform_device_id fimc_lite_driver_ids[] = { 1629static struct platform_device_id fimc_lite_driver_ids[] = {
1655 { 1630 {
1656 .name = "exynos-fimc-lite", 1631 .name = "exynos-fimc-lite",
@@ -1660,17 +1635,21 @@ static struct platform_device_id fimc_lite_driver_ids[] = {
1660}; 1635};
1661MODULE_DEVICE_TABLE(platform, fimc_lite_driver_ids); 1636MODULE_DEVICE_TABLE(platform, fimc_lite_driver_ids);
1662 1637
1663static const struct dev_pm_ops fimc_lite_pm_ops = { 1638static const struct of_device_id flite_of_match[] = {
1664 SET_SYSTEM_SLEEP_PM_OPS(fimc_lite_suspend, fimc_lite_resume) 1639 {
1665 SET_RUNTIME_PM_OPS(fimc_lite_runtime_suspend, fimc_lite_runtime_resume, 1640 .compatible = "samsung,exynos4212-fimc-lite",
1666 NULL) 1641 .data = &fimc_lite_drvdata_exynos4,
1642 },
1643 { /* sentinel */ },
1667}; 1644};
1645MODULE_DEVICE_TABLE(of, flite_of_match);
1668 1646
1669static struct platform_driver fimc_lite_driver = { 1647static struct platform_driver fimc_lite_driver = {
1670 .probe = fimc_lite_probe, 1648 .probe = fimc_lite_probe,
1671 .remove = fimc_lite_remove, 1649 .remove = fimc_lite_remove,
1672 .id_table = fimc_lite_driver_ids, 1650 .id_table = fimc_lite_driver_ids,
1673 .driver = { 1651 .driver = {
1652 .of_match_table = flite_of_match,
1674 .name = FIMC_LITE_DRV_NAME, 1653 .name = FIMC_LITE_DRV_NAME,
1675 .owner = THIS_MODULE, 1654 .owner = THIS_MODULE,
1676 .pm = &fimc_lite_pm_ops, 1655 .pm = &fimc_lite_pm_ops,
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h
index 7085761f8c4b..47da5e049247 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite.h
+++ b/drivers/media/platform/exynos4-is/fimc-lite.h
@@ -20,12 +20,11 @@
20 20
21#include <media/media-entity.h> 21#include <media/media-entity.h>
22#include <media/videobuf2-core.h> 22#include <media/videobuf2-core.h>
23#include <media/v4l2-ctrls.h>
23#include <media/v4l2-device.h> 24#include <media/v4l2-device.h>
24#include <media/v4l2-mediabus.h> 25#include <media/v4l2-mediabus.h>
25#include <media/s5p_fimc.h> 26#include <media/s5p_fimc.h>
26 27
27#include "fimc-core.h"
28
29#define FIMC_LITE_DRV_NAME "exynos-fimc-lite" 28#define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
30#define FLITE_CLK_NAME "flite" 29#define FLITE_CLK_NAME "flite"
31#define FIMC_LITE_MAX_DEVS 2 30#define FIMC_LITE_MAX_DEVS 2
@@ -49,7 +48,7 @@ enum {
49#define FLITE_SD_PAD_SOURCE_ISP 2 48#define FLITE_SD_PAD_SOURCE_ISP 2
50#define FLITE_SD_PADS_NUM 3 49#define FLITE_SD_PADS_NUM 3
51 50
52struct flite_variant { 51struct flite_drvdata {
53 unsigned short max_width; 52 unsigned short max_width;
54 unsigned short max_height; 53 unsigned short max_height;
55 unsigned short out_width_align; 54 unsigned short out_width_align;
@@ -57,10 +56,6 @@ struct flite_variant {
57 unsigned short out_hor_offs_align; 56 unsigned short out_hor_offs_align;
58}; 57};
59 58
60struct flite_drvdata {
61 struct flite_variant *variant[FIMC_LITE_MAX_DEVS];
62};
63
64#define fimc_lite_get_drvdata(_pdev) \ 59#define fimc_lite_get_drvdata(_pdev) \
65 ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data) 60 ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data)
66 61
@@ -75,11 +70,13 @@ struct fimc_lite_events {
75 * @f_width: full pixel width 70 * @f_width: full pixel width
76 * @f_height: full pixel height 71 * @f_height: full pixel height
77 * @rect: crop/composition rectangle 72 * @rect: crop/composition rectangle
73 * @fmt: pointer to pixel format description data structure
78 */ 74 */
79struct flite_frame { 75struct flite_frame {
80 u16 f_width; 76 u16 f_width;
81 u16 f_height; 77 u16 f_height;
82 struct v4l2_rect rect; 78 struct v4l2_rect rect;
79 const struct fimc_fmt *fmt;
83}; 80};
84 81
85/** 82/**
@@ -97,7 +94,7 @@ struct flite_buffer {
97/** 94/**
98 * struct fimc_lite - fimc lite structure 95 * struct fimc_lite - fimc lite structure
99 * @pdev: pointer to FIMC-LITE platform device 96 * @pdev: pointer to FIMC-LITE platform device
100 * @variant: variant information for this IP 97 * @dd: SoC specific driver data structure
101 * @v4l2_dev: pointer to top the level v4l2_device 98 * @v4l2_dev: pointer to top the level v4l2_device
102 * @vfd: video device node 99 * @vfd: video device node
103 * @fh: v4l2 file handle 100 * @fh: v4l2 file handle
@@ -116,7 +113,6 @@ struct flite_buffer {
116 * @clock: FIMC-LITE gate clock 113 * @clock: FIMC-LITE gate clock
117 * @regs: memory mapped io registers 114 * @regs: memory mapped io registers
118 * @irq_queue: interrupt handler waitqueue 115 * @irq_queue: interrupt handler waitqueue
119 * @fmt: pointer to color format description structure
120 * @payload: image size in bytes (w x h x bpp) 116 * @payload: image size in bytes (w x h x bpp)
121 * @inp_frame: camera input frame structure 117 * @inp_frame: camera input frame structure
122 * @out_frame: DMA output frame structure 118 * @out_frame: DMA output frame structure
@@ -133,7 +129,7 @@ struct flite_buffer {
133 */ 129 */
134struct fimc_lite { 130struct fimc_lite {
135 struct platform_device *pdev; 131 struct platform_device *pdev;
136 struct flite_variant *variant; 132 struct flite_drvdata *dd;
137 struct v4l2_device *v4l2_dev; 133 struct v4l2_device *v4l2_dev;
138 struct video_device vfd; 134 struct video_device vfd;
139 struct v4l2_fh fh; 135 struct v4l2_fh fh;
@@ -144,7 +140,7 @@ struct fimc_lite {
144 struct v4l2_subdev *sensor; 140 struct v4l2_subdev *sensor;
145 struct v4l2_ctrl_handler ctrl_handler; 141 struct v4l2_ctrl_handler ctrl_handler;
146 struct v4l2_ctrl *test_pattern; 142 struct v4l2_ctrl *test_pattern;
147 u32 index; 143 int index;
148 struct fimc_pipeline pipeline; 144 struct fimc_pipeline pipeline;
149 const struct fimc_pipeline_ops *pipeline_ops; 145 const struct fimc_pipeline_ops *pipeline_ops;
150 146
@@ -155,7 +151,6 @@ struct fimc_lite {
155 void __iomem *regs; 151 void __iomem *regs;
156 wait_queue_head_t irq_queue; 152 wait_queue_head_t irq_queue;
157 153
158 const struct fimc_fmt *fmt;
159 unsigned long payload[FLITE_MAX_PLANES]; 154 unsigned long payload[FLITE_MAX_PLANES];
160 struct flite_frame inp_frame; 155 struct flite_frame inp_frame;
161 struct flite_frame out_frame; 156 struct flite_frame out_frame;
@@ -171,6 +166,7 @@ struct fimc_lite {
171 int ref_count; 166 int ref_count;
172 167
173 struct fimc_lite_events events; 168 struct fimc_lite_events events;
169 bool streaming;
174}; 170};
175 171
176static inline bool fimc_lite_active(struct fimc_lite *fimc) 172static inline bool fimc_lite_active(struct fimc_lite *fimc)
diff --git a/drivers/media/platform/s5p-fimc/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index f3d535cdd87f..bde1f47f7ed3 100644
--- a/drivers/media/platform/s5p-fimc/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -29,8 +29,7 @@
29 29
30#include "fimc-core.h" 30#include "fimc-core.h"
31#include "fimc-reg.h" 31#include "fimc-reg.h"
32#include "fimc-mdevice.h" 32#include "media-dev.h"
33
34 33
35static unsigned int get_m2m_fmt_flags(unsigned int stream_type) 34static unsigned int get_m2m_fmt_flags(unsigned int stream_type)
36{ 35{
@@ -100,7 +99,7 @@ static int stop_streaming(struct vb2_queue *q)
100 99
101static void fimc_device_run(void *priv) 100static void fimc_device_run(void *priv)
102{ 101{
103 struct vb2_buffer *vb = NULL; 102 struct vb2_buffer *src_vb, *dst_vb;
104 struct fimc_ctx *ctx = priv; 103 struct fimc_ctx *ctx = priv;
105 struct fimc_frame *sf, *df; 104 struct fimc_frame *sf, *df;
106 struct fimc_dev *fimc; 105 struct fimc_dev *fimc;
@@ -123,16 +122,18 @@ static void fimc_device_run(void *priv)
123 fimc_prepare_dma_offset(ctx, df); 122 fimc_prepare_dma_offset(ctx, df);
124 } 123 }
125 124
126 vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 125 src_vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
127 ret = fimc_prepare_addr(ctx, vb, sf, &sf->paddr); 126 ret = fimc_prepare_addr(ctx, src_vb, sf, &sf->paddr);
128 if (ret) 127 if (ret)
129 goto dma_unlock; 128 goto dma_unlock;
130 129
131 vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 130 dst_vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
132 ret = fimc_prepare_addr(ctx, vb, df, &df->paddr); 131 ret = fimc_prepare_addr(ctx, dst_vb, df, &df->paddr);
133 if (ret) 132 if (ret)
134 goto dma_unlock; 133 goto dma_unlock;
135 134
135 dst_vb->v4l2_buf.timestamp = src_vb->v4l2_buf.timestamp;
136
136 /* Reconfigure hardware if the context has changed. */ 137 /* Reconfigure hardware if the context has changed. */
137 if (fimc->m2m.ctx != ctx) { 138 if (fimc->m2m.ctx != ctx) {
138 ctx->state |= FIMC_PARAMS; 139 ctx->state |= FIMC_PARAMS;
@@ -152,7 +153,7 @@ static void fimc_device_run(void *priv)
152 fimc_hw_set_rotation(ctx); 153 fimc_hw_set_rotation(ctx);
153 fimc_hw_set_effect(ctx); 154 fimc_hw_set_effect(ctx);
154 fimc_hw_set_out_dma(ctx); 155 fimc_hw_set_out_dma(ctx);
155 if (fimc->variant->has_alpha) 156 if (fimc->drv_data->alpha_color)
156 fimc_hw_set_rgb_alpha(ctx); 157 fimc_hw_set_rgb_alpha(ctx);
157 fimc_hw_set_output_path(ctx); 158 fimc_hw_set_output_path(ctx);
158 } 159 }
@@ -250,22 +251,20 @@ static struct vb2_ops fimc_qops = {
250 * V4L2 ioctl handlers 251 * V4L2 ioctl handlers
251 */ 252 */
252static int fimc_m2m_querycap(struct file *file, void *fh, 253static int fimc_m2m_querycap(struct file *file, void *fh,
253 struct v4l2_capability *cap) 254 struct v4l2_capability *cap)
254{ 255{
255 struct fimc_ctx *ctx = fh_to_ctx(fh); 256 struct fimc_dev *fimc = video_drvdata(file);
256 struct fimc_dev *fimc = ctx->fimc_dev; 257 unsigned int caps;
257 258
258 strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
259 strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
260 cap->bus_info[0] = 0;
261 /* 259 /*
262 * This is only a mem-to-mem video device. The capture and output 260 * This is only a mem-to-mem video device. The capture and output
263 * device capability flags are left only for backward compatibility 261 * device capability flags are left only for backward compatibility
264 * and are scheduled for removal. 262 * and are scheduled for removal.
265 */ 263 */
266 cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE | 264 caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE |
267 V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE; 265 V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE;
268 266
267 __fimc_vidioc_querycap(&fimc->pdev->dev, cap, caps);
269 return 0; 268 return 0;
270} 269}
271 270
@@ -623,6 +622,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
623 src_vq->ops = &fimc_qops; 622 src_vq->ops = &fimc_qops;
624 src_vq->mem_ops = &vb2_dma_contig_memops; 623 src_vq->mem_ops = &vb2_dma_contig_memops;
625 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 624 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
625 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
626 626
627 ret = vb2_queue_init(src_vq); 627 ret = vb2_queue_init(src_vq);
628 if (ret) 628 if (ret)
@@ -634,6 +634,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
634 dst_vq->ops = &fimc_qops; 634 dst_vq->ops = &fimc_qops;
635 dst_vq->mem_ops = &vb2_dma_contig_memops; 635 dst_vq->mem_ops = &vb2_dma_contig_memops;
636 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 636 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
637 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
637 638
638 return vb2_queue_init(dst_vq); 639 return vb2_queue_init(dst_vq);
639} 640}
@@ -667,16 +668,15 @@ static int fimc_m2m_open(struct file *file)
667 struct fimc_ctx *ctx; 668 struct fimc_ctx *ctx;
668 int ret = -EBUSY; 669 int ret = -EBUSY;
669 670
670 dbg("pid: %d, state: 0x%lx, refcnt: %d", 671 pr_debug("pid: %d, state: %#lx\n", task_pid_nr(current), fimc->state);
671 task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt);
672 672
673 if (mutex_lock_interruptible(&fimc->lock)) 673 if (mutex_lock_interruptible(&fimc->lock))
674 return -ERESTARTSYS; 674 return -ERESTARTSYS;
675 /* 675 /*
676 * Return if the corresponding video capture node 676 * Don't allow simultaneous open() of the mem-to-mem and the
677 * is already opened. 677 * capture video node that belong to same FIMC IP instance.
678 */ 678 */
679 if (fimc->vid_cap.refcnt > 0) 679 if (test_bit(ST_CAPT_BUSY, &fimc->state))
680 goto unlock; 680 goto unlock;
681 681
682 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 682 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
diff --git a/drivers/media/platform/s5p-fimc/fimc-reg.c b/drivers/media/platform/exynos4-is/fimc-reg.c
index 50b97c75b956..f079f36099de 100644
--- a/drivers/media/platform/s5p-fimc/fimc-reg.c
+++ b/drivers/media/platform/exynos4-is/fimc-reg.c
@@ -1,22 +1,24 @@
1/* 1/*
2 * Register interface file for Samsung Camera Interface (FIMC) driver 2 * Register interface file for Samsung Camera Interface (FIMC) driver
3 * 3 *
4 * Copyright (C) 2010 - 2012 Samsung Electronics Co., Ltd. 4 * Copyright (C) 2010 - 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 version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10*/ 10*/
11 11
12#include <linux/io.h>
13#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/io.h>
14#include <linux/regmap.h>
15
14#include <media/s5p_fimc.h> 16#include <media/s5p_fimc.h>
17#include "media-dev.h"
15 18
16#include "fimc-reg.h" 19#include "fimc-reg.h"
17#include "fimc-core.h" 20#include "fimc-core.h"
18 21
19
20void fimc_hw_reset(struct fimc_dev *dev) 22void fimc_hw_reset(struct fimc_dev *dev)
21{ 23{
22 u32 cfg; 24 u32 cfg;
@@ -35,7 +37,7 @@ void fimc_hw_reset(struct fimc_dev *dev)
35 cfg &= ~FIMC_REG_CIGCTRL_SWRST; 37 cfg &= ~FIMC_REG_CIGCTRL_SWRST;
36 writel(cfg, dev->regs + FIMC_REG_CIGCTRL); 38 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
37 39
38 if (dev->variant->out_buf_count > 4) 40 if (dev->drv_data->out_buf_count > 4)
39 fimc_hw_set_dma_seq(dev, 0xF); 41 fimc_hw_set_dma_seq(dev, 0xF);
40} 42}
41 43
@@ -447,7 +449,8 @@ void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
447 | FIMC_REG_MSCTRL_IN_BURST_COUNT_MASK 449 | FIMC_REG_MSCTRL_IN_BURST_COUNT_MASK
448 | FIMC_REG_MSCTRL_INPUT_MASK 450 | FIMC_REG_MSCTRL_INPUT_MASK
449 | FIMC_REG_MSCTRL_C_INT_IN_MASK 451 | FIMC_REG_MSCTRL_C_INT_IN_MASK
450 | FIMC_REG_MSCTRL_2P_IN_ORDER_MASK); 452 | FIMC_REG_MSCTRL_2P_IN_ORDER_MASK
453 | FIMC_REG_MSCTRL_ORDER422_MASK);
451 454
452 cfg |= (FIMC_REG_MSCTRL_IN_BURST_COUNT(4) 455 cfg |= (FIMC_REG_MSCTRL_IN_BURST_COUNT(4)
453 | FIMC_REG_MSCTRL_INPUT_MEMORY 456 | FIMC_REG_MSCTRL_INPUT_MEMORY
@@ -598,7 +601,8 @@ static const struct mbus_pixfmt_desc pix_desc[] = {
598int fimc_hw_set_camera_source(struct fimc_dev *fimc, 601int fimc_hw_set_camera_source(struct fimc_dev *fimc,
599 struct fimc_source_info *source) 602 struct fimc_source_info *source)
600{ 603{
601 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; 604 struct fimc_vid_cap *vc = &fimc->vid_cap;
605 struct fimc_frame *f = &vc->ctx->s_frame;
602 u32 bus_width, cfg = 0; 606 u32 bus_width, cfg = 0;
603 int i; 607 int i;
604 608
@@ -606,7 +610,7 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
606 case FIMC_BUS_TYPE_ITU_601: 610 case FIMC_BUS_TYPE_ITU_601:
607 case FIMC_BUS_TYPE_ITU_656: 611 case FIMC_BUS_TYPE_ITU_656:
608 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) { 612 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
609 if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) { 613 if (vc->ci_fmt.code == pix_desc[i].pixelcode) {
610 cfg = pix_desc[i].cisrcfmt; 614 cfg = pix_desc[i].cisrcfmt;
611 bus_width = pix_desc[i].bus_width; 615 bus_width = pix_desc[i].bus_width;
612 break; 616 break;
@@ -614,9 +618,9 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
614 } 618 }
615 619
616 if (i == ARRAY_SIZE(pix_desc)) { 620 if (i == ARRAY_SIZE(pix_desc)) {
617 v4l2_err(&fimc->vid_cap.vfd, 621 v4l2_err(&vc->vfd,
618 "Camera color format not supported: %d\n", 622 "Camera color format not supported: %d\n",
619 fimc->vid_cap.mf.code); 623 vc->ci_fmt.code);
620 return -EINVAL; 624 return -EINVAL;
621 } 625 }
622 626
@@ -631,6 +635,10 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
631 if (fimc_fmt_is_user_defined(f->fmt->color)) 635 if (fimc_fmt_is_user_defined(f->fmt->color))
632 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; 636 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
633 break; 637 break;
638 default:
639 case FIMC_BUS_TYPE_ISP_WRITEBACK:
640 /* Anything to do here ? */
641 break;
634 } 642 }
635 643
636 cfg |= (f->o_width << 16) | f->o_height; 644 cfg |= (f->o_width << 16) | f->o_height;
@@ -660,16 +668,17 @@ void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
660int fimc_hw_set_camera_type(struct fimc_dev *fimc, 668int fimc_hw_set_camera_type(struct fimc_dev *fimc,
661 struct fimc_source_info *source) 669 struct fimc_source_info *source)
662{ 670{
663 u32 cfg, tmp;
664 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; 671 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
665 u32 csis_data_alignment = 32; 672 u32 csis_data_alignment = 32;
673 u32 cfg, tmp;
666 674
667 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL); 675 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL);
668 676
669 /* Select ITU B interface, disable Writeback path and test pattern. */ 677 /* Select ITU B interface, disable Writeback path and test pattern. */
670 cfg &= ~(FIMC_REG_CIGCTRL_TESTPAT_MASK | FIMC_REG_CIGCTRL_SELCAM_ITU_A | 678 cfg &= ~(FIMC_REG_CIGCTRL_TESTPAT_MASK | FIMC_REG_CIGCTRL_SELCAM_ITU_A |
671 FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB | 679 FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB |
672 FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG); 680 FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG |
681 FIMC_REG_CIGCTRL_SELWB_A);
673 682
674 switch (source->fimc_bus_type) { 683 switch (source->fimc_bus_type) {
675 case FIMC_BUS_TYPE_MIPI_CSI2: 684 case FIMC_BUS_TYPE_MIPI_CSI2:
@@ -679,7 +688,7 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
679 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A; 688 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A;
680 689
681 /* TODO: add remaining supported formats. */ 690 /* TODO: add remaining supported formats. */
682 switch (vid_cap->mf.code) { 691 switch (vid_cap->ci_fmt.code) {
683 case V4L2_MBUS_FMT_VYUY8_2X8: 692 case V4L2_MBUS_FMT_VYUY8_2X8:
684 tmp = FIMC_REG_CSIIMGFMT_YCBCR422_8BIT; 693 tmp = FIMC_REG_CSIIMGFMT_YCBCR422_8BIT;
685 break; 694 break;
@@ -691,7 +700,7 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
691 default: 700 default:
692 v4l2_err(&vid_cap->vfd, 701 v4l2_err(&vid_cap->vfd,
693 "Not supported camera pixel format: %#x\n", 702 "Not supported camera pixel format: %#x\n",
694 vid_cap->mf.code); 703 vid_cap->ci_fmt.code);
695 return -EINVAL; 704 return -EINVAL;
696 } 705 }
697 tmp |= (csis_data_alignment == 32) << 8; 706 tmp |= (csis_data_alignment == 32) << 8;
@@ -704,6 +713,12 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
704 break; 713 break;
705 case FIMC_BUS_TYPE_LCD_WRITEBACK_A: 714 case FIMC_BUS_TYPE_LCD_WRITEBACK_A:
706 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB; 715 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB;
716 /* fall through */
717 case FIMC_BUS_TYPE_ISP_WRITEBACK:
718 if (fimc->variant->has_isp_wb)
719 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB;
720 else
721 WARN_ONCE(1, "ISP Writeback input is not supported\n");
707 break; 722 break;
708 default: 723 default:
709 v4l2_err(&vid_cap->vfd, "Invalid FIMC bus type selected: %d\n", 724 v4l2_err(&vid_cap->vfd, "Invalid FIMC bus type selected: %d\n",
@@ -747,7 +762,7 @@ s32 fimc_hw_get_frame_index(struct fimc_dev *dev)
747{ 762{
748 s32 reg; 763 s32 reg;
749 764
750 if (dev->variant->has_cistatus2) { 765 if (dev->drv_data->cistatus2) {
751 reg = readl(dev->regs + FIMC_REG_CISTATUS2) & 0x3f; 766 reg = readl(dev->regs + FIMC_REG_CISTATUS2) & 0x3f;
752 return reg - 1; 767 return reg - 1;
753 } 768 }
@@ -763,7 +778,7 @@ s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev)
763{ 778{
764 s32 reg; 779 s32 reg;
765 780
766 if (!dev->variant->has_cistatus2) 781 if (!dev->drv_data->cistatus2)
767 return -1; 782 return -1;
768 783
769 reg = readl(dev->regs + FIMC_REG_CISTATUS2); 784 reg = readl(dev->regs + FIMC_REG_CISTATUS2);
@@ -784,3 +799,43 @@ void fimc_deactivate_capture(struct fimc_dev *fimc)
784 fimc_hw_enable_scaler(fimc, false); 799 fimc_hw_enable_scaler(fimc, false);
785 fimc_hw_en_lastirq(fimc, false); 800 fimc_hw_en_lastirq(fimc, false);
786} 801}
802
803int fimc_hw_camblk_cfg_writeback(struct fimc_dev *fimc)
804{
805 struct regmap *map = fimc->sysreg;
806 unsigned int mask, val, camblk_cfg;
807 int ret;
808
809 if (map == NULL)
810 return 0;
811
812 ret = regmap_read(map, SYSREG_CAMBLK, &camblk_cfg);
813 if (ret < 0 || ((camblk_cfg & 0x00700000) >> 20 != 0x3))
814 return ret;
815
816 if (!WARN(fimc->id >= 3, "not supported id: %d\n", fimc->id))
817 val = 0x1 << (fimc->id + 20);
818 else
819 val = 0;
820
821 mask = SYSREG_CAMBLK_FIFORST_ISP | SYSREG_CAMBLK_ISPWB_FULL_EN;
822 ret = regmap_update_bits(map, SYSREG_CAMBLK, mask, val);
823 if (ret < 0)
824 return ret;
825
826 usleep_range(1000, 2000);
827
828 val |= SYSREG_CAMBLK_FIFORST_ISP;
829 ret = regmap_update_bits(map, SYSREG_CAMBLK, mask, val);
830 if (ret < 0)
831 return ret;
832
833 mask = SYSREG_ISPBLK_FIFORST_CAM_BLK;
834 ret = regmap_update_bits(map, SYSREG_ISPBLK, mask, ~mask);
835 if (ret < 0)
836 return ret;
837
838 usleep_range(1000, 2000);
839
840 return regmap_update_bits(map, SYSREG_ISPBLK, mask, mask);
841}
diff --git a/drivers/media/platform/s5p-fimc/fimc-reg.h b/drivers/media/platform/exynos4-is/fimc-reg.h
index 1a40df6d1a80..6c97798c75a5 100644
--- a/drivers/media/platform/s5p-fimc/fimc-reg.h
+++ b/drivers/media/platform/exynos4-is/fimc-reg.h
@@ -52,6 +52,8 @@
52#define FIMC_REG_CIGCTRL_IRQ_CLR (1 << 19) 52#define FIMC_REG_CIGCTRL_IRQ_CLR (1 << 19)
53#define FIMC_REG_CIGCTRL_IRQ_ENABLE (1 << 16) 53#define FIMC_REG_CIGCTRL_IRQ_ENABLE (1 << 16)
54#define FIMC_REG_CIGCTRL_SHDW_DISABLE (1 << 12) 54#define FIMC_REG_CIGCTRL_SHDW_DISABLE (1 << 12)
55/* 0 - selects Writeback A (LCD), 1 - selects Writeback B (LCD/ISP) */
56#define FIMC_REG_CIGCTRL_SELWB_A (1 << 10)
55#define FIMC_REG_CIGCTRL_CAM_JPEG (1 << 8) 57#define FIMC_REG_CIGCTRL_CAM_JPEG (1 << 8)
56#define FIMC_REG_CIGCTRL_SELCAM_MIPI_A (1 << 7) 58#define FIMC_REG_CIGCTRL_SELCAM_MIPI_A (1 << 7)
57#define FIMC_REG_CIGCTRL_CAMIF_SELWB (1 << 6) 59#define FIMC_REG_CIGCTRL_CAMIF_SELWB (1 << 6)
@@ -93,10 +95,10 @@
93/* Output DMA control */ 95/* Output DMA control */
94#define FIMC_REG_CIOCTRL 0x4c 96#define FIMC_REG_CIOCTRL 0x4c
95#define FIMC_REG_CIOCTRL_ORDER422_MASK (3 << 0) 97#define FIMC_REG_CIOCTRL_ORDER422_MASK (3 << 0)
96#define FIMC_REG_CIOCTRL_ORDER422_CRYCBY (0 << 0) 98#define FIMC_REG_CIOCTRL_ORDER422_YCBYCR (0 << 0)
97#define FIMC_REG_CIOCTRL_ORDER422_CBYCRY (1 << 0) 99#define FIMC_REG_CIOCTRL_ORDER422_YCRYCB (1 << 0)
98#define FIMC_REG_CIOCTRL_ORDER422_YCRYCB (2 << 0) 100#define FIMC_REG_CIOCTRL_ORDER422_CBYCRY (2 << 0)
99#define FIMC_REG_CIOCTRL_ORDER422_YCBYCR (3 << 0) 101#define FIMC_REG_CIOCTRL_ORDER422_CRYCBY (3 << 0)
100#define FIMC_REG_CIOCTRL_LASTIRQ_ENABLE (1 << 2) 102#define FIMC_REG_CIOCTRL_LASTIRQ_ENABLE (1 << 2)
101#define FIMC_REG_CIOCTRL_YCBCR_3PLANE (0 << 3) 103#define FIMC_REG_CIOCTRL_YCBCR_3PLANE (0 << 3)
102#define FIMC_REG_CIOCTRL_YCBCR_2PLANE (1 << 3) 104#define FIMC_REG_CIOCTRL_YCBCR_2PLANE (1 << 3)
@@ -218,10 +220,10 @@
218#define FIMC_REG_MSCTRL_FLIP_180 (3 << 13) 220#define FIMC_REG_MSCTRL_FLIP_180 (3 << 13)
219#define FIMC_REG_MSCTRL_FIFO_CTRL_FULL (1 << 12) 221#define FIMC_REG_MSCTRL_FIFO_CTRL_FULL (1 << 12)
220#define FIMC_REG_MSCTRL_ORDER422_SHIFT 4 222#define FIMC_REG_MSCTRL_ORDER422_SHIFT 4
221#define FIMC_REG_MSCTRL_ORDER422_YCBYCR (0 << 4) 223#define FIMC_REG_MSCTRL_ORDER422_CRYCBY (0 << 4)
222#define FIMC_REG_MSCTRL_ORDER422_CBYCRY (1 << 4) 224#define FIMC_REG_MSCTRL_ORDER422_YCRYCB (1 << 4)
223#define FIMC_REG_MSCTRL_ORDER422_YCRYCB (2 << 4) 225#define FIMC_REG_MSCTRL_ORDER422_CBYCRY (2 << 4)
224#define FIMC_REG_MSCTRL_ORDER422_CRYCBY (3 << 4) 226#define FIMC_REG_MSCTRL_ORDER422_YCBYCR (3 << 4)
225#define FIMC_REG_MSCTRL_ORDER422_MASK (3 << 4) 227#define FIMC_REG_MSCTRL_ORDER422_MASK (3 << 4)
226#define FIMC_REG_MSCTRL_INPUT_EXTCAM (0 << 3) 228#define FIMC_REG_MSCTRL_INPUT_EXTCAM (0 << 3)
227#define FIMC_REG_MSCTRL_INPUT_MEMORY (1 << 3) 229#define FIMC_REG_MSCTRL_INPUT_MEMORY (1 << 3)
@@ -276,6 +278,14 @@
276/* Output frame buffer sequence mask */ 278/* Output frame buffer sequence mask */
277#define FIMC_REG_CIFCNTSEQ 0x1fc 279#define FIMC_REG_CIFCNTSEQ 0x1fc
278 280
281/* SYSREG ISP Writeback register address offsets */
282#define SYSREG_ISPBLK 0x020c
283#define SYSREG_ISPBLK_FIFORST_CAM_BLK (1 << 7)
284
285#define SYSREG_CAMBLK 0x0218
286#define SYSREG_CAMBLK_FIFORST_ISP (1 << 15)
287#define SYSREG_CAMBLK_ISPWB_FULL_EN (7 << 20)
288
279/* 289/*
280 * Function declarations 290 * Function declarations
281 */ 291 */
@@ -309,6 +319,7 @@ void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on);
309void fimc_hw_disable_capture(struct fimc_dev *dev); 319void fimc_hw_disable_capture(struct fimc_dev *dev);
310s32 fimc_hw_get_frame_index(struct fimc_dev *dev); 320s32 fimc_hw_get_frame_index(struct fimc_dev *dev);
311s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev); 321s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev);
322int fimc_hw_camblk_cfg_writeback(struct fimc_dev *fimc);
312void fimc_activate_capture(struct fimc_ctx *ctx); 323void fimc_activate_capture(struct fimc_ctx *ctx);
313void fimc_deactivate_capture(struct fimc_dev *fimc); 324void fimc_deactivate_capture(struct fimc_dev *fimc);
314 325
diff --git a/drivers/media/platform/s5p-fimc/fimc-mdevice.c b/drivers/media/platform/exynos4-is/media-dev.c
index cd38d708ab58..15ef8f28239b 100644
--- a/drivers/media/platform/s5p-fimc/fimc-mdevice.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -17,32 +17,37 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/of.h>
21#include <linux/of_platform.h>
22#include <linux/of_device.h>
23#include <linux/of_i2c.h>
20#include <linux/platform_device.h> 24#include <linux/platform_device.h>
21#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
22#include <linux/types.h> 26#include <linux/types.h>
23#include <linux/slab.h> 27#include <linux/slab.h>
24#include <media/v4l2-ctrls.h> 28#include <media/v4l2-ctrls.h>
29#include <media/v4l2-of.h>
25#include <media/media-device.h> 30#include <media/media-device.h>
26#include <media/s5p_fimc.h> 31#include <media/s5p_fimc.h>
27 32
33#include "media-dev.h"
28#include "fimc-core.h" 34#include "fimc-core.h"
35#include "fimc-is.h"
29#include "fimc-lite.h" 36#include "fimc-lite.h"
30#include "fimc-mdevice.h"
31#include "mipi-csis.h" 37#include "mipi-csis.h"
32 38
33static int __fimc_md_set_camclk(struct fimc_md *fmd, 39static int __fimc_md_set_camclk(struct fimc_md *fmd,
34 struct fimc_sensor_info *s_info, 40 struct fimc_source_info *si,
35 bool on); 41 bool on);
36/** 42/**
37 * fimc_pipeline_prepare - update pipeline information with subdevice pointers 43 * fimc_pipeline_prepare - update pipeline information with subdevice pointers
38 * @fimc: fimc device terminating the pipeline 44 * @me: media entity terminating the pipeline
39 * 45 *
40 * Caller holds the graph mutex. 46 * Caller holds the graph mutex.
41 */ 47 */
42static void fimc_pipeline_prepare(struct fimc_pipeline *p, 48static void fimc_pipeline_prepare(struct fimc_pipeline *p,
43 struct media_entity *me) 49 struct media_entity *me)
44{ 50{
45 struct media_pad *pad = &me->pads[0];
46 struct v4l2_subdev *sd; 51 struct v4l2_subdev *sd;
47 int i; 52 int i;
48 53
@@ -50,15 +55,21 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
50 p->subdevs[i] = NULL; 55 p->subdevs[i] = NULL;
51 56
52 while (1) { 57 while (1) {
53 if (!(pad->flags & MEDIA_PAD_FL_SINK)) 58 struct media_pad *pad = NULL;
54 break; 59
60 /* Find remote source pad */
61 for (i = 0; i < me->num_pads; i++) {
62 struct media_pad *spad = &me->pads[i];
63 if (!(spad->flags & MEDIA_PAD_FL_SINK))
64 continue;
65 pad = media_entity_remote_source(spad);
66 if (pad)
67 break;
68 }
55 69
56 /* source pad */
57 pad = media_entity_remote_source(pad);
58 if (pad == NULL || 70 if (pad == NULL ||
59 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 71 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
60 break; 72 break;
61
62 sd = media_entity_to_v4l2_subdev(pad->entity); 73 sd = media_entity_to_v4l2_subdev(pad->entity);
63 74
64 switch (sd->grp_id) { 75 switch (sd->grp_id) {
@@ -75,12 +86,15 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
75 case GRP_ID_FIMC: 86 case GRP_ID_FIMC:
76 /* No need to control FIMC subdev through subdev ops */ 87 /* No need to control FIMC subdev through subdev ops */
77 break; 88 break;
89 case GRP_ID_FIMC_IS:
90 p->subdevs[IDX_IS_ISP] = sd;
91 break;
78 default: 92 default:
79 pr_warn("%s: Unknown subdev grp_id: %#x\n", 93 break;
80 __func__, sd->grp_id);
81 } 94 }
82 /* sink pad */ 95 me = &sd->entity;
83 pad = &sd->entity.pads[0]; 96 if (me->num_pads == 1)
97 break;
84 } 98 }
85} 99}
86 100
@@ -117,49 +131,81 @@ static int __subdev_set_power(struct v4l2_subdev *sd, int on)
117 * 131 *
118 * Needs to be called with the graph mutex held. 132 * Needs to be called with the graph mutex held.
119 */ 133 */
120static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool state) 134static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool on)
121{ 135{
122 unsigned int i; 136 static const u8 seq[2][IDX_MAX - 1] = {
123 int ret; 137 { IDX_IS_ISP, IDX_SENSOR, IDX_CSIS, IDX_FLITE },
138 { IDX_CSIS, IDX_FLITE, IDX_SENSOR, IDX_IS_ISP },
139 };
140 int i, ret = 0;
124 141
125 if (p->subdevs[IDX_SENSOR] == NULL) 142 if (p->subdevs[IDX_SENSOR] == NULL)
126 return -ENXIO; 143 return -ENXIO;
127 144
128 for (i = 0; i < IDX_MAX; i++) { 145 for (i = 0; i < IDX_MAX - 1; i++) {
129 unsigned int idx = state ? (IDX_MAX - 1) - i : i; 146 unsigned int idx = seq[on][i];
147
148 ret = __subdev_set_power(p->subdevs[idx], on);
149
130 150
131 ret = __subdev_set_power(p->subdevs[idx], state);
132 if (ret < 0 && ret != -ENXIO) 151 if (ret < 0 && ret != -ENXIO)
133 return ret; 152 goto error;
134 } 153 }
135
136 return 0; 154 return 0;
155error:
156 for (; i >= 0; i--) {
157 unsigned int idx = seq[on][i];
158 __subdev_set_power(p->subdevs[idx], !on);
159 }
160 return ret;
137} 161}
138 162
139/** 163/**
140 * __fimc_pipeline_open - update the pipeline information, enable power 164 * __fimc_pipeline_open - update the pipeline information, enable power
141 * of all pipeline subdevs and the sensor clock 165 * of all pipeline subdevs and the sensor clock
142 * @me: media entity to start graph walk with 166 * @me: media entity to start graph walk with
143 * @prep: true to acquire sensor (and csis) subdevs 167 * @prepare: true to walk the current pipeline and acquire all subdevs
144 * 168 *
145 * Called with the graph mutex held. 169 * Called with the graph mutex held.
146 */ 170 */
147static int __fimc_pipeline_open(struct fimc_pipeline *p, 171static int __fimc_pipeline_open(struct fimc_pipeline *p,
148 struct media_entity *me, bool prep) 172 struct media_entity *me, bool prepare)
149{ 173{
174 struct fimc_md *fmd = entity_to_fimc_mdev(me);
175 struct v4l2_subdev *sd;
150 int ret; 176 int ret;
151 177
152 if (prep) 178 if (WARN_ON(p == NULL || me == NULL))
179 return -EINVAL;
180
181 if (prepare)
153 fimc_pipeline_prepare(p, me); 182 fimc_pipeline_prepare(p, me);
154 183
155 if (p->subdevs[IDX_SENSOR] == NULL) 184 sd = p->subdevs[IDX_SENSOR];
185 if (sd == NULL)
156 return -EINVAL; 186 return -EINVAL;
157 187
158 ret = fimc_md_set_camclk(p->subdevs[IDX_SENSOR], true); 188 /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */
159 if (ret) 189 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) {
160 return ret; 190 ret = clk_prepare_enable(fmd->wbclk[CLK_IDX_WB_B]);
191 if (ret < 0)
192 return ret;
193 }
194 ret = fimc_md_set_camclk(sd, true);
195 if (ret < 0)
196 goto err_wbclk;
197
198 ret = fimc_pipeline_s_power(p, 1);
199 if (!ret)
200 return 0;
201
202 fimc_md_set_camclk(sd, false);
203
204err_wbclk:
205 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP])
206 clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]);
161 207
162 return fimc_pipeline_s_power(p, 1); 208 return ret;
163} 209}
164 210
165/** 211/**
@@ -170,41 +216,58 @@ static int __fimc_pipeline_open(struct fimc_pipeline *p,
170 */ 216 */
171static int __fimc_pipeline_close(struct fimc_pipeline *p) 217static int __fimc_pipeline_close(struct fimc_pipeline *p)
172{ 218{
219 struct v4l2_subdev *sd = p ? p->subdevs[IDX_SENSOR] : NULL;
220 struct fimc_md *fmd;
173 int ret = 0; 221 int ret = 0;
174 222
175 if (!p || !p->subdevs[IDX_SENSOR]) 223 if (WARN_ON(sd == NULL))
176 return -EINVAL; 224 return -EINVAL;
177 225
178 if (p->subdevs[IDX_SENSOR]) { 226 if (p->subdevs[IDX_SENSOR]) {
179 ret = fimc_pipeline_s_power(p, 0); 227 ret = fimc_pipeline_s_power(p, 0);
180 fimc_md_set_camclk(p->subdevs[IDX_SENSOR], false); 228 fimc_md_set_camclk(sd, false);
181 } 229 }
230
231 fmd = entity_to_fimc_mdev(&sd->entity);
232
233 /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */
234 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP])
235 clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]);
236
182 return ret == -ENXIO ? 0 : ret; 237 return ret == -ENXIO ? 0 : ret;
183} 238}
184 239
185/** 240/**
186 * __fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs 241 * __fimc_pipeline_s_stream - call s_stream() on pipeline subdevs
187 * @pipeline: video pipeline structure 242 * @pipeline: video pipeline structure
188 * @on: passed as the s_stream call argument 243 * @on: passed as the s_stream() callback argument
189 */ 244 */
190static int __fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on) 245static int __fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on)
191{ 246{
192 int i, ret; 247 static const u8 seq[2][IDX_MAX] = {
248 { IDX_FIMC, IDX_SENSOR, IDX_IS_ISP, IDX_CSIS, IDX_FLITE },
249 { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP },
250 };
251 int i, ret = 0;
193 252
194 if (p->subdevs[IDX_SENSOR] == NULL) 253 if (p->subdevs[IDX_SENSOR] == NULL)
195 return -ENODEV; 254 return -ENODEV;
196 255
197 for (i = 0; i < IDX_MAX; i++) { 256 for (i = 0; i < IDX_MAX; i++) {
198 unsigned int idx = on ? (IDX_MAX - 1) - i : i; 257 unsigned int idx = seq[on][i];
199 258
200 ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on); 259 ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on);
201 260
202 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) 261 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
203 return ret; 262 goto error;
204 } 263 }
205
206 return 0; 264 return 0;
207 265error:
266 for (; i >= 0; i--) {
267 unsigned int idx = seq[on][i];
268 v4l2_subdev_call(p->subdevs[idx], video, s_stream, !on);
269 }
270 return ret;
208} 271}
209 272
210/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */ 273/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */
@@ -218,35 +281,40 @@ static const struct fimc_pipeline_ops fimc_pipeline_ops = {
218 * Sensor subdevice helper functions 281 * Sensor subdevice helper functions
219 */ 282 */
220static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd, 283static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd,
221 struct fimc_sensor_info *s_info) 284 struct fimc_source_info *si)
222{ 285{
223 struct i2c_adapter *adapter; 286 struct i2c_adapter *adapter;
224 struct v4l2_subdev *sd = NULL; 287 struct v4l2_subdev *sd = NULL;
225 288
226 if (!s_info || !fmd) 289 if (!si || !fmd)
227 return NULL; 290 return NULL;
291 /*
292 * If FIMC bus type is not Writeback FIFO assume it is same
293 * as sensor_bus_type.
294 */
295 si->fimc_bus_type = si->sensor_bus_type;
228 296
229 adapter = i2c_get_adapter(s_info->pdata.i2c_bus_num); 297 adapter = i2c_get_adapter(si->i2c_bus_num);
230 if (!adapter) { 298 if (!adapter) {
231 v4l2_warn(&fmd->v4l2_dev, 299 v4l2_warn(&fmd->v4l2_dev,
232 "Failed to get I2C adapter %d, deferring probe\n", 300 "Failed to get I2C adapter %d, deferring probe\n",
233 s_info->pdata.i2c_bus_num); 301 si->i2c_bus_num);
234 return ERR_PTR(-EPROBE_DEFER); 302 return ERR_PTR(-EPROBE_DEFER);
235 } 303 }
236 sd = v4l2_i2c_new_subdev_board(&fmd->v4l2_dev, adapter, 304 sd = v4l2_i2c_new_subdev_board(&fmd->v4l2_dev, adapter,
237 s_info->pdata.board_info, NULL); 305 si->board_info, NULL);
238 if (IS_ERR_OR_NULL(sd)) { 306 if (IS_ERR_OR_NULL(sd)) {
239 i2c_put_adapter(adapter); 307 i2c_put_adapter(adapter);
240 v4l2_warn(&fmd->v4l2_dev, 308 v4l2_warn(&fmd->v4l2_dev,
241 "Failed to acquire subdev %s, deferring probe\n", 309 "Failed to acquire subdev %s, deferring probe\n",
242 s_info->pdata.board_info->type); 310 si->board_info->type);
243 return ERR_PTR(-EPROBE_DEFER); 311 return ERR_PTR(-EPROBE_DEFER);
244 } 312 }
245 v4l2_set_subdev_hostdata(sd, s_info); 313 v4l2_set_subdev_hostdata(sd, si);
246 sd->grp_id = GRP_ID_SENSOR; 314 sd->grp_id = GRP_ID_SENSOR;
247 315
248 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n", 316 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n",
249 s_info->pdata.board_info->type); 317 sd->name);
250 return sd; 318 return sd;
251} 319}
252 320
@@ -257,57 +325,262 @@ static void fimc_md_unregister_sensor(struct v4l2_subdev *sd)
257 325
258 if (!client) 326 if (!client)
259 return; 327 return;
328
260 v4l2_device_unregister_subdev(sd); 329 v4l2_device_unregister_subdev(sd);
261 adapter = client->adapter; 330
262 i2c_unregister_device(client); 331 if (!client->dev.of_node) {
263 if (adapter) 332 adapter = client->adapter;
264 i2c_put_adapter(adapter); 333 i2c_unregister_device(client);
334 if (adapter)
335 i2c_put_adapter(adapter);
336 }
337}
338
339#ifdef CONFIG_OF
340/* Register I2C client subdev associated with @node. */
341static int fimc_md_of_add_sensor(struct fimc_md *fmd,
342 struct device_node *node, int index)
343{
344 struct fimc_sensor_info *si;
345 struct i2c_client *client;
346 struct v4l2_subdev *sd;
347 int ret;
348
349 if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor)))
350 return -EINVAL;
351 si = &fmd->sensor[index];
352
353 client = of_find_i2c_device_by_node(node);
354 if (!client)
355 return -EPROBE_DEFER;
356
357 device_lock(&client->dev);
358
359 if (!client->driver ||
360 !try_module_get(client->driver->driver.owner)) {
361 ret = -EPROBE_DEFER;
362 v4l2_info(&fmd->v4l2_dev, "No driver found for %s\n",
363 node->full_name);
364 goto dev_put;
365 }
366
367 /* Enable sensor's master clock */
368 ret = __fimc_md_set_camclk(fmd, &si->pdata, true);
369 if (ret < 0)
370 goto mod_put;
371 sd = i2c_get_clientdata(client);
372
373 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
374 __fimc_md_set_camclk(fmd, &si->pdata, false);
375 if (ret < 0)
376 goto mod_put;
377
378 v4l2_set_subdev_hostdata(sd, &si->pdata);
379 if (si->pdata.fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK)
380 sd->grp_id = GRP_ID_FIMC_IS_SENSOR;
381 else
382 sd->grp_id = GRP_ID_SENSOR;
383
384 si->subdev = sd;
385 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice: %s (%d)\n",
386 sd->name, fmd->num_sensors);
387 fmd->num_sensors++;
388
389mod_put:
390 module_put(client->driver->driver.owner);
391dev_put:
392 device_unlock(&client->dev);
393 put_device(&client->dev);
394 return ret;
395}
396
397/* Parse port node and register as a sub-device any sensor specified there. */
398static int fimc_md_parse_port_node(struct fimc_md *fmd,
399 struct device_node *port,
400 unsigned int index)
401{
402 struct device_node *rem, *ep, *np;
403 struct fimc_source_info *pd;
404 struct v4l2_of_endpoint endpoint;
405 int ret;
406 u32 val;
407
408 pd = &fmd->sensor[index].pdata;
409
410 /* Assume here a port node can have only one endpoint node. */
411 ep = of_get_next_child(port, NULL);
412 if (!ep)
413 return 0;
414
415 v4l2_of_parse_endpoint(ep, &endpoint);
416 if (WARN_ON(endpoint.port == 0) || index >= FIMC_MAX_SENSORS)
417 return -EINVAL;
418
419 pd->mux_id = (endpoint.port - 1) & 0x1;
420
421 rem = v4l2_of_get_remote_port_parent(ep);
422 of_node_put(ep);
423 if (rem == NULL) {
424 v4l2_info(&fmd->v4l2_dev, "Remote device at %s not found\n",
425 ep->full_name);
426 return 0;
427 }
428 if (!of_property_read_u32(rem, "samsung,camclk-out", &val))
429 pd->clk_id = val;
430
431 if (!of_property_read_u32(rem, "clock-frequency", &val))
432 pd->clk_frequency = val;
433
434 if (pd->clk_frequency == 0) {
435 v4l2_err(&fmd->v4l2_dev, "Wrong clock frequency at node %s\n",
436 rem->full_name);
437 of_node_put(rem);
438 return -EINVAL;
439 }
440
441 if (fimc_input_is_parallel(endpoint.port)) {
442 if (endpoint.bus_type == V4L2_MBUS_PARALLEL)
443 pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_601;
444 else
445 pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_656;
446 pd->flags = endpoint.bus.parallel.flags;
447 } else if (fimc_input_is_mipi_csi(endpoint.port)) {
448 /*
449 * MIPI CSI-2: only input mux selection and
450 * the sensor's clock frequency is needed.
451 */
452 pd->sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2;
453 } else {
454 v4l2_err(&fmd->v4l2_dev, "Wrong port id (%u) at node %s\n",
455 endpoint.port, rem->full_name);
456 }
457 /*
458 * For FIMC-IS handled sensors, that are placed under i2c-isp device
459 * node, FIMC is connected to the FIMC-IS through its ISP Writeback
460 * input. Sensors are attached to the FIMC-LITE hostdata interface
461 * directly or through MIPI-CSIS, depending on the external media bus
462 * used. This needs to be handled in a more reliable way, not by just
463 * checking parent's node name.
464 */
465 np = of_get_parent(rem);
466
467 if (np && !of_node_cmp(np->name, "i2c-isp"))
468 pd->fimc_bus_type = FIMC_BUS_TYPE_ISP_WRITEBACK;
469 else
470 pd->fimc_bus_type = pd->sensor_bus_type;
471
472 ret = fimc_md_of_add_sensor(fmd, rem, index);
473 of_node_put(rem);
474
475 return ret;
476}
477
478/* Register all SoC external sub-devices */
479static int fimc_md_of_sensors_register(struct fimc_md *fmd,
480 struct device_node *np)
481{
482 struct device_node *parent = fmd->pdev->dev.of_node;
483 struct device_node *node, *ports;
484 int index = 0;
485 int ret;
486
487 /* Attach sensors linked to MIPI CSI-2 receivers */
488 for_each_available_child_of_node(parent, node) {
489 struct device_node *port;
490
491 if (of_node_cmp(node->name, "csis"))
492 continue;
493 /* The csis node can have only port subnode. */
494 port = of_get_next_child(node, NULL);
495 if (!port)
496 continue;
497
498 ret = fimc_md_parse_port_node(fmd, port, index);
499 if (ret < 0)
500 return ret;
501 index++;
502 }
503
504 /* Attach sensors listed in the parallel-ports node */
505 ports = of_get_child_by_name(parent, "parallel-ports");
506 if (!ports)
507 return 0;
508
509 for_each_child_of_node(ports, node) {
510 ret = fimc_md_parse_port_node(fmd, node, index);
511 if (ret < 0)
512 break;
513 index++;
514 }
515
516 return 0;
517}
518
519static int __of_get_csis_id(struct device_node *np)
520{
521 u32 reg = 0;
522
523 np = of_get_child_by_name(np, "port");
524 if (!np)
525 return -EINVAL;
526 of_property_read_u32(np, "reg", &reg);
527 return reg - FIMC_INPUT_MIPI_CSI2_0;
265} 528}
529#else
530#define fimc_md_of_sensors_register(fmd, np) (-ENOSYS)
531#define __of_get_csis_id(np) (-ENOSYS)
532#endif
266 533
267static int fimc_md_register_sensor_entities(struct fimc_md *fmd) 534static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
268{ 535{
269 struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data; 536 struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data;
270 struct fimc_dev *fd = NULL; 537 struct device_node *of_node = fmd->pdev->dev.of_node;
271 int num_clients, ret, i; 538 int num_clients = 0;
539 int ret, i;
272 540
273 /* 541 /*
274 * Runtime resume one of the FIMC entities to make sure 542 * Runtime resume one of the FIMC entities to make sure
275 * the sclk_cam clocks are not globally disabled. 543 * the sclk_cam clocks are not globally disabled.
276 */ 544 */
277 for (i = 0; !fd && i < ARRAY_SIZE(fmd->fimc); i++) 545 if (!fmd->pmf)
278 if (fmd->fimc[i])
279 fd = fmd->fimc[i];
280 if (!fd)
281 return -ENXIO; 546 return -ENXIO;
282 ret = pm_runtime_get_sync(&fd->pdev->dev); 547
548 ret = pm_runtime_get_sync(fmd->pmf);
283 if (ret < 0) 549 if (ret < 0)
284 return ret; 550 return ret;
285 551
286 WARN_ON(pdata->num_clients > ARRAY_SIZE(fmd->sensor)); 552 if (of_node) {
287 num_clients = min_t(u32, pdata->num_clients, ARRAY_SIZE(fmd->sensor)); 553 fmd->num_sensors = 0;
288 554 ret = fimc_md_of_sensors_register(fmd, of_node);
289 fmd->num_sensors = num_clients; 555 } else if (pdata) {
290 for (i = 0; i < num_clients; i++) { 556 WARN_ON(pdata->num_clients > ARRAY_SIZE(fmd->sensor));
291 struct v4l2_subdev *sd; 557 num_clients = min_t(u32, pdata->num_clients,
292 558 ARRAY_SIZE(fmd->sensor));
293 fmd->sensor[i].pdata = pdata->source_info[i]; 559 fmd->num_sensors = num_clients;
294 ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], true); 560
295 if (ret) 561 for (i = 0; i < num_clients; i++) {
296 break; 562 struct fimc_sensor_info *si = &fmd->sensor[i];
297 sd = fimc_md_register_sensor(fmd, &fmd->sensor[i]); 563 struct v4l2_subdev *sd;
298 ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], false); 564
299 565 si->pdata = pdata->source_info[i];
300 if (!IS_ERR(sd)) { 566 ret = __fimc_md_set_camclk(fmd, &si->pdata, true);
301 fmd->sensor[i].subdev = sd; 567 if (ret)
302 } else { 568 break;
303 fmd->sensor[i].subdev = NULL; 569 sd = fimc_md_register_sensor(fmd, &si->pdata);
304 ret = PTR_ERR(sd); 570 ret = __fimc_md_set_camclk(fmd, &si->pdata, false);
305 break; 571
572 if (IS_ERR(sd)) {
573 si->subdev = NULL;
574 ret = PTR_ERR(sd);
575 break;
576 }
577 si->subdev = sd;
578 if (ret)
579 break;
306 } 580 }
307 if (ret)
308 break;
309 } 581 }
310 pm_runtime_put(&fd->pdev->dev); 582
583 pm_runtime_put(fmd->pmf);
311 return ret; 584 return ret;
312} 585}
313 586
@@ -352,6 +625,8 @@ static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc)
352 625
353 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); 626 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
354 if (!ret) { 627 if (!ret) {
628 if (!fmd->pmf && fimc->pdev)
629 fmd->pmf = &fimc->pdev->dev;
355 fmd->fimc[fimc->id] = fimc; 630 fmd->fimc[fimc->id] = fimc;
356 fimc->vid_cap.user_subdev_api = fmd->user_subdev_api; 631 fimc->vid_cap.user_subdev_api = fmd->user_subdev_api;
357 } else { 632 } else {
@@ -368,13 +643,13 @@ static int register_csis_entity(struct fimc_md *fmd,
368 struct device_node *node = pdev->dev.of_node; 643 struct device_node *node = pdev->dev.of_node;
369 int id, ret; 644 int id, ret;
370 645
371 id = node ? of_alias_get_id(node, "csis") : max(0, pdev->id); 646 id = node ? __of_get_csis_id(node) : max(0, pdev->id);
372 647
373 if (WARN_ON(id >= CSIS_MAX_ENTITIES || fmd->csis[id].sd)) 648 if (WARN_ON(id < 0 || id >= CSIS_MAX_ENTITIES))
374 return -EBUSY; 649 return -ENOENT;
375 650
376 if (WARN_ON(id >= CSIS_MAX_ENTITIES)) 651 if (WARN_ON(fmd->csis[id].sd))
377 return 0; 652 return -EBUSY;
378 653
379 sd->grp_id = GRP_ID_CSIS; 654 sd->grp_id = GRP_ID_CSIS;
380 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); 655 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
@@ -386,6 +661,22 @@ static int register_csis_entity(struct fimc_md *fmd,
386 return ret; 661 return ret;
387} 662}
388 663
664static int register_fimc_is_entity(struct fimc_md *fmd, struct fimc_is *is)
665{
666 struct v4l2_subdev *sd = &is->isp.subdev;
667 int ret;
668
669 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
670 if (ret) {
671 v4l2_err(&fmd->v4l2_dev,
672 "Failed to register FIMC-ISP (%d)\n", ret);
673 return ret;
674 }
675
676 fmd->fimc_is = is;
677 return 0;
678}
679
389static int fimc_md_register_platform_entity(struct fimc_md *fmd, 680static int fimc_md_register_platform_entity(struct fimc_md *fmd,
390 struct platform_device *pdev, 681 struct platform_device *pdev,
391 int plat_entity) 682 int plat_entity)
@@ -413,6 +704,9 @@ static int fimc_md_register_platform_entity(struct fimc_md *fmd,
413 case IDX_CSIS: 704 case IDX_CSIS:
414 ret = register_csis_entity(fmd, pdev, drvdata); 705 ret = register_csis_entity(fmd, pdev, drvdata);
415 break; 706 break;
707 case IDX_IS_ISP:
708 ret = register_fimc_is_entity(fmd, drvdata);
709 break;
416 default: 710 default:
417 ret = -ENODEV; 711 ret = -ENODEV;
418 } 712 }
@@ -457,6 +751,47 @@ static int fimc_md_pdev_match(struct device *dev, void *data)
457 return 0; 751 return 0;
458} 752}
459 753
754/* Register FIMC, FIMC-LITE and CSIS media entities */
755#ifdef CONFIG_OF
756static int fimc_md_register_of_platform_entities(struct fimc_md *fmd,
757 struct device_node *parent)
758{
759 struct device_node *node;
760 int ret = 0;
761
762 for_each_available_child_of_node(parent, node) {
763 struct platform_device *pdev;
764 int plat_entity = -1;
765
766 pdev = of_find_device_by_node(node);
767 if (!pdev)
768 continue;
769
770 /* If driver of any entity isn't ready try all again later. */
771 if (!strcmp(node->name, CSIS_OF_NODE_NAME))
772 plat_entity = IDX_CSIS;
773 else if (!strcmp(node->name, FIMC_IS_OF_NODE_NAME))
774 plat_entity = IDX_IS_ISP;
775 else if (!strcmp(node->name, FIMC_LITE_OF_NODE_NAME))
776 plat_entity = IDX_FLITE;
777 else if (!strcmp(node->name, FIMC_OF_NODE_NAME) &&
778 !of_property_read_bool(node, "samsung,lcd-wb"))
779 plat_entity = IDX_FIMC;
780
781 if (plat_entity >= 0)
782 ret = fimc_md_register_platform_entity(fmd, pdev,
783 plat_entity);
784 put_device(&pdev->dev);
785 if (ret < 0)
786 break;
787 }
788
789 return ret;
790}
791#else
792#define fimc_md_register_of_platform_entities(fmd, node) (-ENOSYS)
793#endif
794
460static void fimc_md_unregister_entities(struct fimc_md *fmd) 795static void fimc_md_unregister_entities(struct fimc_md *fmd)
461{ 796{
462 int i; 797 int i;
@@ -479,7 +814,6 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd)
479 if (fmd->csis[i].sd == NULL) 814 if (fmd->csis[i].sd == NULL)
480 continue; 815 continue;
481 v4l2_device_unregister_subdev(fmd->csis[i].sd); 816 v4l2_device_unregister_subdev(fmd->csis[i].sd);
482 module_put(fmd->csis[i].sd->owner);
483 fmd->csis[i].sd = NULL; 817 fmd->csis[i].sd = NULL;
484 } 818 }
485 for (i = 0; i < fmd->num_sensors; i++) { 819 for (i = 0; i < fmd->num_sensors; i++) {
@@ -488,6 +822,10 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd)
488 fimc_md_unregister_sensor(fmd->sensor[i].subdev); 822 fimc_md_unregister_sensor(fmd->sensor[i].subdev);
489 fmd->sensor[i].subdev = NULL; 823 fmd->sensor[i].subdev = NULL;
490 } 824 }
825
826 if (fmd->fimc_is)
827 v4l2_device_unregister_subdev(&fmd->fimc_is->isp.subdev);
828
491 v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n"); 829 v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n");
492} 830}
493 831
@@ -504,12 +842,19 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
504 struct v4l2_subdev *sensor, 842 struct v4l2_subdev *sensor,
505 int pad, int link_mask) 843 int pad, int link_mask)
506{ 844{
507 struct fimc_sensor_info *s_info = NULL; 845 struct fimc_source_info *si = NULL;
508 struct media_entity *sink; 846 struct media_entity *sink;
509 unsigned int flags = 0; 847 unsigned int flags = 0;
510 int ret, i; 848 int i, ret = 0;
511 849
512 for (i = 0; i < FIMC_MAX_DEVS; i++) { 850 if (sensor) {
851 si = v4l2_get_subdev_hostdata(sensor);
852 /* Skip direct FIMC links in the logical FIMC-IS sensor path */
853 if (si && si->fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK)
854 ret = 1;
855 }
856
857 for (i = 0; !ret && i < FIMC_MAX_DEVS; i++) {
513 if (!fmd->fimc[i]) 858 if (!fmd->fimc[i])
514 continue; 859 continue;
515 /* 860 /*
@@ -523,7 +868,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
523 868
524 sink = &fmd->fimc[i]->vid_cap.subdev.entity; 869 sink = &fmd->fimc[i]->vid_cap.subdev.entity;
525 ret = media_entity_create_link(source, pad, sink, 870 ret = media_entity_create_link(source, pad, sink,
526 FIMC_SD_PAD_SINK, flags); 871 FIMC_SD_PAD_SINK_CAM, flags);
527 if (ret) 872 if (ret)
528 return ret; 873 return ret;
529 874
@@ -538,11 +883,13 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
538 883
539 if (flags == 0 || sensor == NULL) 884 if (flags == 0 || sensor == NULL)
540 continue; 885 continue;
541 s_info = v4l2_get_subdev_hostdata(sensor); 886
542 if (!WARN_ON(s_info == NULL)) { 887 if (!WARN_ON(si == NULL)) {
543 unsigned long irq_flags; 888 unsigned long irq_flags;
889 struct fimc_sensor_info *inf = source_to_sensor_info(si);
890
544 spin_lock_irqsave(&fmd->slock, irq_flags); 891 spin_lock_irqsave(&fmd->slock, irq_flags);
545 s_info->host = fmd->fimc[i]; 892 inf->host = fmd->fimc[i];
546 spin_unlock_irqrestore(&fmd->slock, irq_flags); 893 spin_unlock_irqrestore(&fmd->slock, irq_flags);
547 } 894 }
548 } 895 }
@@ -551,25 +898,20 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
551 if (!fmd->fimc_lite[i]) 898 if (!fmd->fimc_lite[i])
552 continue; 899 continue;
553 900
554 if (link_mask & (1 << (i + FIMC_MAX_DEVS)))
555 flags = MEDIA_LNK_FL_ENABLED;
556 else
557 flags = 0;
558
559 sink = &fmd->fimc_lite[i]->subdev.entity; 901 sink = &fmd->fimc_lite[i]->subdev.entity;
560 ret = media_entity_create_link(source, pad, sink, 902 ret = media_entity_create_link(source, pad, sink,
561 FLITE_SD_PAD_SINK, flags); 903 FLITE_SD_PAD_SINK, 0);
562 if (ret) 904 if (ret)
563 return ret; 905 return ret;
564 906
565 /* Notify FIMC-LITE subdev entity */ 907 /* Notify FIMC-LITE subdev entity */
566 ret = media_entity_call(sink, link_setup, &sink->pads[0], 908 ret = media_entity_call(sink, link_setup, &sink->pads[0],
567 &source->pads[pad], flags); 909 &source->pads[pad], 0);
568 if (ret) 910 if (ret)
569 break; 911 break;
570 912
571 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n", 913 v4l2_info(&fmd->v4l2_dev, "created link [%s] -> [%s]\n",
572 source->name, flags ? '=' : '-', sink->name); 914 source->name, sink->name);
573 } 915 }
574 return 0; 916 return 0;
575} 917}
@@ -578,21 +920,50 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
578static int __fimc_md_create_flite_source_links(struct fimc_md *fmd) 920static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
579{ 921{
580 struct media_entity *source, *sink; 922 struct media_entity *source, *sink;
581 unsigned int flags = MEDIA_LNK_FL_ENABLED;
582 int i, ret = 0; 923 int i, ret = 0;
583 924
584 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { 925 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) {
585 struct fimc_lite *fimc = fmd->fimc_lite[i]; 926 struct fimc_lite *fimc = fmd->fimc_lite[i];
927
586 if (fimc == NULL) 928 if (fimc == NULL)
587 continue; 929 continue;
930
588 source = &fimc->subdev.entity; 931 source = &fimc->subdev.entity;
589 sink = &fimc->vfd.entity; 932 sink = &fimc->vfd.entity;
590 /* FIMC-LITE's subdev and video node */ 933 /* FIMC-LITE's subdev and video node */
591 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA, 934 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
592 sink, 0, flags); 935 sink, 0, 0);
936 if (ret)
937 break;
938 /* Link from FIMC-LITE to IS-ISP subdev */
939 sink = &fmd->fimc_is->isp.subdev.entity;
940 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
941 sink, 0, 0);
593 if (ret) 942 if (ret)
594 break; 943 break;
595 /* TODO: create links to other entities */ 944 }
945
946 return ret;
947}
948
949/* Create FIMC-IS links */
950static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
951{
952 struct media_entity *source, *sink;
953 int i, ret;
954
955 source = &fmd->fimc_is->isp.subdev.entity;
956
957 for (i = 0; i < FIMC_MAX_DEVS; i++) {
958 if (fmd->fimc[i] == NULL)
959 continue;
960
961 /* Link from IS-ISP subdev to FIMC */
962 sink = &fmd->fimc[i]->vid_cap.subdev.entity;
963 ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
964 sink, FIMC_SD_PAD_SINK_FIFO, 0);
965 if (ret)
966 return ret;
596 } 967 }
597 968
598 return ret; 969 return ret;
@@ -615,7 +986,6 @@ static int fimc_md_create_links(struct fimc_md *fmd)
615 struct v4l2_subdev *csi_sensors[CSIS_MAX_ENTITIES] = { NULL }; 986 struct v4l2_subdev *csi_sensors[CSIS_MAX_ENTITIES] = { NULL };
616 struct v4l2_subdev *sensor, *csis; 987 struct v4l2_subdev *sensor, *csis;
617 struct fimc_source_info *pdata; 988 struct fimc_source_info *pdata;
618 struct fimc_sensor_info *s_info;
619 struct media_entity *source, *sink; 989 struct media_entity *source, *sink;
620 int i, pad, fimc_id = 0, ret = 0; 990 int i, pad, fimc_id = 0, ret = 0;
621 u32 flags, link_mask = 0; 991 u32 flags, link_mask = 0;
@@ -625,12 +995,11 @@ static int fimc_md_create_links(struct fimc_md *fmd)
625 continue; 995 continue;
626 996
627 sensor = fmd->sensor[i].subdev; 997 sensor = fmd->sensor[i].subdev;
628 s_info = v4l2_get_subdev_hostdata(sensor); 998 pdata = v4l2_get_subdev_hostdata(sensor);
629 if (!s_info) 999 if (!pdata)
630 continue; 1000 continue;
631 1001
632 source = NULL; 1002 source = NULL;
633 pdata = &s_info->pdata;
634 1003
635 switch (pdata->sensor_bus_type) { 1004 switch (pdata->sensor_bus_type) {
636 case FIMC_BUS_TYPE_MIPI_CSI2: 1005 case FIMC_BUS_TYPE_MIPI_CSI2:
@@ -680,6 +1049,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
680 for (i = 0; i < CSIS_MAX_ENTITIES; i++) { 1049 for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
681 if (fmd->csis[i].sd == NULL) 1050 if (fmd->csis[i].sd == NULL)
682 continue; 1051 continue;
1052
683 source = &fmd->csis[i].sd->entity; 1053 source = &fmd->csis[i].sd->entity;
684 pad = CSIS_PAD_SOURCE; 1054 pad = CSIS_PAD_SOURCE;
685 sensor = csi_sensors[i]; 1055 sensor = csi_sensors[i];
@@ -694,19 +1064,28 @@ static int fimc_md_create_links(struct fimc_md *fmd)
694 for (i = 0; i < FIMC_MAX_DEVS; i++) { 1064 for (i = 0; i < FIMC_MAX_DEVS; i++) {
695 if (!fmd->fimc[i]) 1065 if (!fmd->fimc[i])
696 continue; 1066 continue;
1067
697 source = &fmd->fimc[i]->vid_cap.subdev.entity; 1068 source = &fmd->fimc[i]->vid_cap.subdev.entity;
698 sink = &fmd->fimc[i]->vid_cap.vfd.entity; 1069 sink = &fmd->fimc[i]->vid_cap.vfd.entity;
1070
699 ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, 1071 ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
700 sink, 0, flags); 1072 sink, 0, flags);
701 if (ret) 1073 if (ret)
702 break; 1074 break;
703 } 1075 }
704 1076
705 return __fimc_md_create_flite_source_links(fmd); 1077 ret = __fimc_md_create_flite_source_links(fmd);
1078 if (ret < 0)
1079 return ret;
1080
1081 if (fmd->use_isp)
1082 ret = __fimc_md_create_fimc_is_links(fmd);
1083
1084 return ret;
706} 1085}
707 1086
708/* 1087/*
709 * The peripheral sensor clock management. 1088 * The peripheral sensor and CAM_BLK (PIXELASYNCMx) clocks management.
710 */ 1089 */
711static void fimc_md_put_clocks(struct fimc_md *fmd) 1090static void fimc_md_put_clocks(struct fimc_md *fmd)
712{ 1091{
@@ -719,6 +1098,14 @@ static void fimc_md_put_clocks(struct fimc_md *fmd)
719 clk_put(fmd->camclk[i].clock); 1098 clk_put(fmd->camclk[i].clock);
720 fmd->camclk[i].clock = ERR_PTR(-EINVAL); 1099 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
721 } 1100 }
1101
1102 /* Writeback (PIXELASYNCMx) clocks */
1103 for (i = 0; i < FIMC_MAX_WBCLKS; i++) {
1104 if (IS_ERR(fmd->wbclk[i]))
1105 continue;
1106 clk_put(fmd->wbclk[i]);
1107 fmd->wbclk[i] = ERR_PTR(-EINVAL);
1108 }
722} 1109}
723 1110
724static int fimc_md_get_clocks(struct fimc_md *fmd) 1111static int fimc_md_get_clocks(struct fimc_md *fmd)
@@ -755,35 +1142,59 @@ static int fimc_md_get_clocks(struct fimc_md *fmd)
755 if (ret) 1142 if (ret)
756 fimc_md_put_clocks(fmd); 1143 fimc_md_put_clocks(fmd);
757 1144
1145 if (!fmd->use_isp)
1146 return 0;
1147 /*
1148 * For now get only PIXELASYNCM1 clock (Writeback B/ISP),
1149 * leave PIXELASYNCM0 out for the LCD Writeback driver.
1150 */
1151 fmd->wbclk[CLK_IDX_WB_A] = ERR_PTR(-EINVAL);
1152
1153 for (i = CLK_IDX_WB_B; i < FIMC_MAX_WBCLKS; i++) {
1154 snprintf(clk_name, sizeof(clk_name), "pxl_async%u", i);
1155 clock = clk_get(dev, clk_name);
1156 if (IS_ERR(clock)) {
1157 v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s\n",
1158 clk_name);
1159 ret = PTR_ERR(clock);
1160 break;
1161 }
1162 fmd->wbclk[i] = clock;
1163 }
1164 if (ret)
1165 fimc_md_put_clocks(fmd);
1166
758 return ret; 1167 return ret;
759} 1168}
760 1169
761static int __fimc_md_set_camclk(struct fimc_md *fmd, 1170static int __fimc_md_set_camclk(struct fimc_md *fmd,
762 struct fimc_sensor_info *s_info, 1171 struct fimc_source_info *si,
763 bool on) 1172 bool on)
764{ 1173{
765 struct fimc_source_info *pdata = &s_info->pdata;
766 struct fimc_camclk_info *camclk; 1174 struct fimc_camclk_info *camclk;
767 int ret = 0; 1175 int ret = 0;
768 1176
769 if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL) 1177 if (WARN_ON(si->clk_id >= FIMC_MAX_CAMCLKS) || !fmd || !fmd->pmf)
770 return -EINVAL; 1178 return -EINVAL;
771 1179
772 camclk = &fmd->camclk[pdata->clk_id]; 1180 camclk = &fmd->camclk[si->clk_id];
773 1181
774 dbg("camclk %d, f: %lu, use_count: %d, on: %d", 1182 dbg("camclk %d, f: %lu, use_count: %d, on: %d",
775 pdata->clk_id, pdata->clk_frequency, camclk->use_count, on); 1183 si->clk_id, si->clk_frequency, camclk->use_count, on);
776 1184
777 if (on) { 1185 if (on) {
778 if (camclk->use_count > 0 && 1186 if (camclk->use_count > 0 &&
779 camclk->frequency != pdata->clk_frequency) 1187 camclk->frequency != si->clk_frequency)
780 return -EINVAL; 1188 return -EINVAL;
781 1189
782 if (camclk->use_count++ == 0) { 1190 if (camclk->use_count++ == 0) {
783 clk_set_rate(camclk->clock, pdata->clk_frequency); 1191 clk_set_rate(camclk->clock, si->clk_frequency);
784 camclk->frequency = pdata->clk_frequency; 1192 camclk->frequency = si->clk_frequency;
1193 ret = pm_runtime_get_sync(fmd->pmf);
1194 if (ret < 0)
1195 return ret;
785 ret = clk_enable(camclk->clock); 1196 ret = clk_enable(camclk->clock);
786 dbg("Enabled camclk %d: f: %lu", pdata->clk_id, 1197 dbg("Enabled camclk %d: f: %lu", si->clk_id,
787 clk_get_rate(camclk->clock)); 1198 clk_get_rate(camclk->clock));
788 } 1199 }
789 return ret; 1200 return ret;
@@ -794,7 +1205,8 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
794 1205
795 if (--camclk->use_count == 0) { 1206 if (--camclk->use_count == 0) {
796 clk_disable(camclk->clock); 1207 clk_disable(camclk->clock);
797 dbg("Disabled camclk %d", pdata->clk_id); 1208 pm_runtime_put(fmd->pmf);
1209 dbg("Disabled camclk %d", si->clk_id);
798 } 1210 }
799 return ret; 1211 return ret;
800} 1212}
@@ -813,10 +1225,10 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
813 */ 1225 */
814int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) 1226int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on)
815{ 1227{
816 struct fimc_sensor_info *s_info = v4l2_get_subdev_hostdata(sd); 1228 struct fimc_source_info *si = v4l2_get_subdev_hostdata(sd);
817 struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity); 1229 struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity);
818 1230
819 return __fimc_md_set_camclk(fmd, s_info, on); 1231 return __fimc_md_set_camclk(fmd, si, on);
820} 1232}
821 1233
822static int fimc_md_link_notify(struct media_pad *source, 1234static int fimc_md_link_notify(struct media_pad *source,
@@ -926,13 +1338,33 @@ static ssize_t fimc_md_sysfs_store(struct device *dev,
926static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO, 1338static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO,
927 fimc_md_sysfs_show, fimc_md_sysfs_store); 1339 fimc_md_sysfs_show, fimc_md_sysfs_store);
928 1340
1341static int fimc_md_get_pinctrl(struct fimc_md *fmd)
1342{
1343 struct device *dev = &fmd->pdev->dev;
1344 struct fimc_pinctrl *pctl = &fmd->pinctl;
1345
1346 pctl->pinctrl = devm_pinctrl_get(dev);
1347 if (IS_ERR(pctl->pinctrl))
1348 return PTR_ERR(pctl->pinctrl);
1349
1350 pctl->state_default = pinctrl_lookup_state(pctl->pinctrl,
1351 PINCTRL_STATE_DEFAULT);
1352 if (IS_ERR(pctl->state_default))
1353 return PTR_ERR(pctl->state_default);
1354
1355 pctl->state_idle = pinctrl_lookup_state(pctl->pinctrl,
1356 PINCTRL_STATE_IDLE);
1357 return 0;
1358}
1359
929static int fimc_md_probe(struct platform_device *pdev) 1360static int fimc_md_probe(struct platform_device *pdev)
930{ 1361{
1362 struct device *dev = &pdev->dev;
931 struct v4l2_device *v4l2_dev; 1363 struct v4l2_device *v4l2_dev;
932 struct fimc_md *fmd; 1364 struct fimc_md *fmd;
933 int ret; 1365 int ret;
934 1366
935 fmd = devm_kzalloc(&pdev->dev, sizeof(*fmd), GFP_KERNEL); 1367 fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL);
936 if (!fmd) 1368 if (!fmd)
937 return -ENOMEM; 1369 return -ENOMEM;
938 1370
@@ -942,15 +1374,16 @@ static int fimc_md_probe(struct platform_device *pdev)
942 strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC", 1374 strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC",
943 sizeof(fmd->media_dev.model)); 1375 sizeof(fmd->media_dev.model));
944 fmd->media_dev.link_notify = fimc_md_link_notify; 1376 fmd->media_dev.link_notify = fimc_md_link_notify;
945 fmd->media_dev.dev = &pdev->dev; 1377 fmd->media_dev.dev = dev;
946 1378
947 v4l2_dev = &fmd->v4l2_dev; 1379 v4l2_dev = &fmd->v4l2_dev;
948 v4l2_dev->mdev = &fmd->media_dev; 1380 v4l2_dev->mdev = &fmd->media_dev;
949 v4l2_dev->notify = fimc_sensor_notify; 1381 v4l2_dev->notify = fimc_sensor_notify;
950 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s", 1382 strlcpy(v4l2_dev->name, "s5p-fimc-md", sizeof(v4l2_dev->name));
951 dev_name(&pdev->dev));
952 1383
953 ret = v4l2_device_register(&pdev->dev, &fmd->v4l2_dev); 1384 fmd->use_isp = fimc_md_is_isp_available(dev->of_node);
1385
1386 ret = v4l2_device_register(dev, &fmd->v4l2_dev);
954 if (ret < 0) { 1387 if (ret < 0) {
955 v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret); 1388 v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret);
956 return ret; 1389 return ret;
@@ -964,21 +1397,32 @@ static int fimc_md_probe(struct platform_device *pdev)
964 if (ret) 1397 if (ret)
965 goto err_clk; 1398 goto err_clk;
966 1399
967 fmd->user_subdev_api = false; 1400 fmd->user_subdev_api = (dev->of_node != NULL);
968 1401
969 /* Protect the media graph while we're registering entities */ 1402 /* Protect the media graph while we're registering entities */
970 mutex_lock(&fmd->media_dev.graph_mutex); 1403 mutex_lock(&fmd->media_dev.graph_mutex);
971 1404
972 ret = bus_for_each_dev(&platform_bus_type, NULL, fmd, 1405 ret = fimc_md_get_pinctrl(fmd);
973 fimc_md_pdev_match); 1406 if (ret < 0) {
1407 if (ret != EPROBE_DEFER)
1408 dev_err(dev, "Failed to get pinctrl: %d\n", ret);
1409 goto err_unlock;
1410 }
1411
1412 if (dev->of_node)
1413 ret = fimc_md_register_of_platform_entities(fmd, dev->of_node);
1414 else
1415 ret = bus_for_each_dev(&platform_bus_type, NULL, fmd,
1416 fimc_md_pdev_match);
974 if (ret) 1417 if (ret)
975 goto err_unlock; 1418 goto err_unlock;
976 1419
977 if (pdev->dev.platform_data) { 1420 if (dev->platform_data || dev->of_node) {
978 ret = fimc_md_register_sensor_entities(fmd); 1421 ret = fimc_md_register_sensor_entities(fmd);
979 if (ret) 1422 if (ret)
980 goto err_unlock; 1423 goto err_unlock;
981 } 1424 }
1425
982 ret = fimc_md_create_links(fmd); 1426 ret = fimc_md_create_links(fmd);
983 if (ret) 1427 if (ret)
984 goto err_unlock; 1428 goto err_unlock;
@@ -1018,12 +1462,25 @@ static int fimc_md_remove(struct platform_device *pdev)
1018 return 0; 1462 return 0;
1019} 1463}
1020 1464
1465static struct platform_device_id fimc_driver_ids[] __always_unused = {
1466 { .name = "s5p-fimc-md" },
1467 { },
1468};
1469MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
1470
1471static const struct of_device_id fimc_md_of_match[] = {
1472 { .compatible = "samsung,fimc" },
1473 { },
1474};
1475MODULE_DEVICE_TABLE(of, fimc_md_of_match);
1476
1021static struct platform_driver fimc_md_driver = { 1477static struct platform_driver fimc_md_driver = {
1022 .probe = fimc_md_probe, 1478 .probe = fimc_md_probe,
1023 .remove = fimc_md_remove, 1479 .remove = fimc_md_remove,
1024 .driver = { 1480 .driver = {
1025 .name = "s5p-fimc-md", 1481 .of_match_table = of_match_ptr(fimc_md_of_match),
1026 .owner = THIS_MODULE, 1482 .name = "s5p-fimc-md",
1483 .owner = THIS_MODULE,
1027 } 1484 }
1028}; 1485};
1029 1486
diff --git a/drivers/media/platform/s5p-fimc/fimc-mdevice.h b/drivers/media/platform/exynos4-is/media-dev.h
index 06b0d8276fd2..44d86b61d660 100644
--- a/drivers/media/platform/s5p-fimc/fimc-mdevice.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -12,6 +12,8 @@
12#include <linux/clk.h> 12#include <linux/clk.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/mutex.h> 14#include <linux/mutex.h>
15#include <linux/of.h>
16#include <linux/pinctrl/consumer.h>
15#include <media/media-device.h> 17#include <media/media-device.h>
16#include <media/media-entity.h> 18#include <media/media-entity.h>
17#include <media/v4l2-device.h> 19#include <media/v4l2-device.h>
@@ -21,18 +23,23 @@
21#include "fimc-lite.h" 23#include "fimc-lite.h"
22#include "mipi-csis.h" 24#include "mipi-csis.h"
23 25
24/* Group IDs of sensor, MIPI-CSIS, FIMC-LITE and the writeback subdevs. */ 26#define FIMC_OF_NODE_NAME "fimc"
25#define GRP_ID_SENSOR (1 << 8) 27#define FIMC_LITE_OF_NODE_NAME "fimc-lite"
26#define GRP_ID_FIMC_IS_SENSOR (1 << 9) 28#define FIMC_IS_OF_NODE_NAME "fimc-is"
27#define GRP_ID_WRITEBACK (1 << 10) 29#define CSIS_OF_NODE_NAME "csis"
28#define GRP_ID_CSIS (1 << 11) 30
29#define GRP_ID_FIMC (1 << 12) 31#define PINCTRL_STATE_IDLE "idle"
30#define GRP_ID_FLITE (1 << 13)
31#define GRP_ID_FIMC_IS (1 << 14)
32 32
33#define FIMC_MAX_SENSORS 8 33#define FIMC_MAX_SENSORS 8
34#define FIMC_MAX_CAMCLKS 2 34#define FIMC_MAX_CAMCLKS 2
35 35
36/* LCD/ISP Writeback clocks (PIXELASYNCMx) */
37enum {
38 CLK_IDX_WB_A,
39 CLK_IDX_WB_B,
40 FIMC_MAX_WBCLKS
41};
42
36struct fimc_csis_info { 43struct fimc_csis_info {
37 struct v4l2_subdev *sd; 44 struct v4l2_subdev *sd;
38 int id; 45 int id;
@@ -65,9 +72,15 @@ struct fimc_sensor_info {
65 * @num_sensors: actual number of registered sensors 72 * @num_sensors: actual number of registered sensors
66 * @camclk: external sensor clock information 73 * @camclk: external sensor clock information
67 * @fimc: array of registered fimc devices 74 * @fimc: array of registered fimc devices
75 * @fimc_is: fimc-is data structure
76 * @use_isp: set to true when FIMC-IS subsystem is used
77 * @pmf: handle to the CAMCLK clock control FIMC helper device
68 * @media_dev: top level media device 78 * @media_dev: top level media device
69 * @v4l2_dev: top level v4l2_device holding up the subdevs 79 * @v4l2_dev: top level v4l2_device holding up the subdevs
70 * @pdev: platform device this media device is hooked up into 80 * @pdev: platform device this media device is hooked up into
81 * @pinctrl: camera port pinctrl handle
82 * @state_default: pinctrl default state handle
83 * @state_idle: pinctrl idle state handle
71 * @user_subdev_api: true if subdevs are not configured by the host driver 84 * @user_subdev_api: true if subdevs are not configured by the host driver
72 * @slock: spinlock protecting @sensor array 85 * @slock: spinlock protecting @sensor array
73 */ 86 */
@@ -76,11 +89,20 @@ struct fimc_md {
76 struct fimc_sensor_info sensor[FIMC_MAX_SENSORS]; 89 struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
77 int num_sensors; 90 int num_sensors;
78 struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS]; 91 struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
92 struct clk *wbclk[FIMC_MAX_WBCLKS];
79 struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS]; 93 struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
80 struct fimc_dev *fimc[FIMC_MAX_DEVS]; 94 struct fimc_dev *fimc[FIMC_MAX_DEVS];
95 struct fimc_is *fimc_is;
96 bool use_isp;
97 struct device *pmf;
81 struct media_device media_dev; 98 struct media_device media_dev;
82 struct v4l2_device v4l2_dev; 99 struct v4l2_device v4l2_dev;
83 struct platform_device *pdev; 100 struct platform_device *pdev;
101 struct fimc_pinctrl {
102 struct pinctrl *pinctrl;
103 struct pinctrl_state *state_default;
104 struct pinctrl_state *state_idle;
105 } pinctl;
84 bool user_subdev_api; 106 bool user_subdev_api;
85 spinlock_t slock; 107 spinlock_t slock;
86}; 108};
@@ -93,6 +115,12 @@ struct fimc_md {
93 115
94#define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE) 116#define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)
95 117
118static inline
119struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
120{
121 return container_of(si, struct fimc_sensor_info, pdata);
122}
123
96static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me) 124static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
97{ 125{
98 return me->parent == NULL ? NULL : 126 return me->parent == NULL ? NULL :
@@ -111,4 +139,14 @@ static inline void fimc_md_graph_unlock(struct fimc_dev *fimc)
111 139
112int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); 140int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
113 141
142#ifdef CONFIG_OF
143static inline bool fimc_md_is_isp_available(struct device_node *node)
144{
145 node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
146 return node ? of_device_is_available(node) : false;
147}
148#else
149#define fimc_md_is_isp_available(node) (false)
150#endif /* CONFIG_OF */
151
114#endif 152#endif
diff --git a/drivers/media/platform/s5p-fimc/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 981863d05aaa..a2eda9d5ac87 100644
--- a/drivers/media/platform/s5p-fimc/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -19,14 +19,18 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/memory.h> 20#include <linux/memory.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/of.h>
23#include <linux/platform_data/mipi-csis.h>
22#include <linux/platform_device.h> 24#include <linux/platform_device.h>
23#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
24#include <linux/regulator/consumer.h> 26#include <linux/regulator/consumer.h>
25#include <linux/slab.h> 27#include <linux/slab.h>
26#include <linux/spinlock.h> 28#include <linux/spinlock.h>
27#include <linux/videodev2.h> 29#include <linux/videodev2.h>
30#include <media/s5p_fimc.h>
31#include <media/v4l2-of.h>
28#include <media/v4l2-subdev.h> 32#include <media/v4l2-subdev.h>
29#include <linux/platform_data/mipi-csis.h> 33
30#include "mipi-csis.h" 34#include "mipi-csis.h"
31 35
32static int debug; 36static int debug;
@@ -113,6 +117,7 @@ static char *csi_clock_name[] = {
113 [CSIS_CLK_GATE] = "csis", 117 [CSIS_CLK_GATE] = "csis",
114}; 118};
115#define NUM_CSIS_CLOCKS ARRAY_SIZE(csi_clock_name) 119#define NUM_CSIS_CLOCKS ARRAY_SIZE(csi_clock_name)
120#define DEFAULT_SCLK_CSIS_FREQ 166000000UL
116 121
117static const char * const csis_supply_name[] = { 122static const char * const csis_supply_name[] = {
118 "vddcore", /* CSIS Core (1.0V, 1.1V or 1.2V) suppply */ 123 "vddcore", /* CSIS Core (1.0V, 1.1V or 1.2V) suppply */
@@ -167,6 +172,11 @@ struct csis_pktbuf {
167 * @clock: CSIS clocks 172 * @clock: CSIS clocks
168 * @irq: requested s5p-mipi-csis irq number 173 * @irq: requested s5p-mipi-csis irq number
169 * @flags: the state variable for power and streaming control 174 * @flags: the state variable for power and streaming control
175 * @clock_frequency: device bus clock frequency
176 * @hs_settle: HS-RX settle time
177 * @num_lanes: number of MIPI-CSI data lanes used
178 * @max_num_lanes: maximum number of MIPI-CSI data lanes supported
179 * @wclk_ext: CSI wrapper clock: 0 - bus clock, 1 - external SCLK_CAM
170 * @csis_fmt: current CSIS pixel format 180 * @csis_fmt: current CSIS pixel format
171 * @format: common media bus format for the source and sink pad 181 * @format: common media bus format for the source and sink pad
172 * @slock: spinlock protecting structure members below 182 * @slock: spinlock protecting structure members below
@@ -184,6 +194,13 @@ struct csis_state {
184 struct clk *clock[NUM_CSIS_CLOCKS]; 194 struct clk *clock[NUM_CSIS_CLOCKS];
185 int irq; 195 int irq;
186 u32 flags; 196 u32 flags;
197
198 u32 clk_frequency;
199 u32 hs_settle;
200 u32 num_lanes;
201 u32 max_num_lanes;
202 u8 wclk_ext;
203
187 const struct csis_pix_format *csis_fmt; 204 const struct csis_pix_format *csis_fmt;
188 struct v4l2_mbus_framefmt format; 205 struct v4l2_mbus_framefmt format;
189 206
@@ -273,7 +290,6 @@ static void s5pcsis_reset(struct csis_state *state)
273 290
274static void s5pcsis_system_enable(struct csis_state *state, int on) 291static void s5pcsis_system_enable(struct csis_state *state, int on)
275{ 292{
276 struct s5p_platform_mipi_csis *pdata = state->pdev->dev.platform_data;
277 u32 val, mask; 293 u32 val, mask;
278 294
279 val = s5pcsis_read(state, S5PCSIS_CTRL); 295 val = s5pcsis_read(state, S5PCSIS_CTRL);
@@ -286,7 +302,7 @@ static void s5pcsis_system_enable(struct csis_state *state, int on)
286 val = s5pcsis_read(state, S5PCSIS_DPHYCTRL); 302 val = s5pcsis_read(state, S5PCSIS_DPHYCTRL);
287 val &= ~S5PCSIS_DPHYCTRL_ENABLE; 303 val &= ~S5PCSIS_DPHYCTRL_ENABLE;
288 if (on) { 304 if (on) {
289 mask = (1 << (pdata->lanes + 1)) - 1; 305 mask = (1 << (state->num_lanes + 1)) - 1;
290 val |= (mask & S5PCSIS_DPHYCTRL_ENABLE); 306 val |= (mask & S5PCSIS_DPHYCTRL_ENABLE);
291 } 307 }
292 s5pcsis_write(state, S5PCSIS_DPHYCTRL, val); 308 s5pcsis_write(state, S5PCSIS_DPHYCTRL, val);
@@ -321,15 +337,14 @@ static void s5pcsis_set_hsync_settle(struct csis_state *state, int settle)
321 337
322static void s5pcsis_set_params(struct csis_state *state) 338static void s5pcsis_set_params(struct csis_state *state)
323{ 339{
324 struct s5p_platform_mipi_csis *pdata = state->pdev->dev.platform_data;
325 u32 val; 340 u32 val;
326 341
327 val = s5pcsis_read(state, S5PCSIS_CONFIG); 342 val = s5pcsis_read(state, S5PCSIS_CONFIG);
328 val = (val & ~S5PCSIS_CFG_NR_LANE_MASK) | (pdata->lanes - 1); 343 val = (val & ~S5PCSIS_CFG_NR_LANE_MASK) | (state->num_lanes - 1);
329 s5pcsis_write(state, S5PCSIS_CONFIG, val); 344 s5pcsis_write(state, S5PCSIS_CONFIG, val);
330 345
331 __s5pcsis_set_format(state); 346 __s5pcsis_set_format(state);
332 s5pcsis_set_hsync_settle(state, pdata->hs_settle); 347 s5pcsis_set_hsync_settle(state, state->hs_settle);
333 348
334 val = s5pcsis_read(state, S5PCSIS_CTRL); 349 val = s5pcsis_read(state, S5PCSIS_CTRL);
335 if (state->csis_fmt->data_alignment == 32) 350 if (state->csis_fmt->data_alignment == 32)
@@ -338,7 +353,7 @@ static void s5pcsis_set_params(struct csis_state *state)
338 val &= ~S5PCSIS_CTRL_ALIGN_32BIT; 353 val &= ~S5PCSIS_CTRL_ALIGN_32BIT;
339 354
340 val &= ~S5PCSIS_CTRL_WCLK_EXTCLK; 355 val &= ~S5PCSIS_CTRL_WCLK_EXTCLK;
341 if (pdata->wclk_source) 356 if (state->wclk_ext)
342 val |= S5PCSIS_CTRL_WCLK_EXTCLK; 357 val |= S5PCSIS_CTRL_WCLK_EXTCLK;
343 s5pcsis_write(state, S5PCSIS_CTRL, val); 358 s5pcsis_write(state, S5PCSIS_CTRL, val);
344 359
@@ -534,10 +549,10 @@ static struct csis_pix_format const *s5pcsis_try_format(
534 549
535static struct v4l2_mbus_framefmt *__s5pcsis_get_format( 550static struct v4l2_mbus_framefmt *__s5pcsis_get_format(
536 struct csis_state *state, struct v4l2_subdev_fh *fh, 551 struct csis_state *state, struct v4l2_subdev_fh *fh,
537 u32 pad, enum v4l2_subdev_format_whence which) 552 enum v4l2_subdev_format_whence which)
538{ 553{
539 if (which == V4L2_SUBDEV_FORMAT_TRY) 554 if (which == V4L2_SUBDEV_FORMAT_TRY)
540 return fh ? v4l2_subdev_get_try_format(fh, pad) : NULL; 555 return fh ? v4l2_subdev_get_try_format(fh, 0) : NULL;
541 556
542 return &state->format; 557 return &state->format;
543} 558}
@@ -549,10 +564,7 @@ static int s5pcsis_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
549 struct csis_pix_format const *csis_fmt; 564 struct csis_pix_format const *csis_fmt;
550 struct v4l2_mbus_framefmt *mf; 565 struct v4l2_mbus_framefmt *mf;
551 566
552 if (fmt->pad != CSIS_PAD_SOURCE && fmt->pad != CSIS_PAD_SINK) 567 mf = __s5pcsis_get_format(state, fh, fmt->which);
553 return -EINVAL;
554
555 mf = __s5pcsis_get_format(state, fh, fmt->pad, fmt->which);
556 568
557 if (fmt->pad == CSIS_PAD_SOURCE) { 569 if (fmt->pad == CSIS_PAD_SOURCE) {
558 if (mf) { 570 if (mf) {
@@ -579,10 +591,7 @@ static int s5pcsis_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
579 struct csis_state *state = sd_to_csis_state(sd); 591 struct csis_state *state = sd_to_csis_state(sd);
580 struct v4l2_mbus_framefmt *mf; 592 struct v4l2_mbus_framefmt *mf;
581 593
582 if (fmt->pad != CSIS_PAD_SOURCE && fmt->pad != CSIS_PAD_SINK) 594 mf = __s5pcsis_get_format(state, fh, fmt->which);
583 return -EINVAL;
584
585 mf = __s5pcsis_get_format(state, fh, fmt->pad, fmt->which);
586 if (!mf) 595 if (!mf)
587 return -EINVAL; 596 return -EINVAL;
588 597
@@ -701,52 +710,111 @@ static irqreturn_t s5pcsis_irq_handler(int irq, void *dev_id)
701 return IRQ_HANDLED; 710 return IRQ_HANDLED;
702} 711}
703 712
713static int s5pcsis_get_platform_data(struct platform_device *pdev,
714 struct csis_state *state)
715{
716 struct s5p_platform_mipi_csis *pdata = pdev->dev.platform_data;
717
718 if (pdata == NULL) {
719 dev_err(&pdev->dev, "Platform data not specified\n");
720 return -EINVAL;
721 }
722
723 state->clk_frequency = pdata->clk_rate;
724 state->num_lanes = pdata->lanes;
725 state->hs_settle = pdata->hs_settle;
726 state->index = max(0, pdev->id);
727 state->max_num_lanes = state->index ? CSIS1_MAX_LANES :
728 CSIS0_MAX_LANES;
729 return 0;
730}
731
732#ifdef CONFIG_OF
733static int s5pcsis_parse_dt(struct platform_device *pdev,
734 struct csis_state *state)
735{
736 struct device_node *node = pdev->dev.of_node;
737 struct v4l2_of_endpoint endpoint;
738
739 if (of_property_read_u32(node, "clock-frequency",
740 &state->clk_frequency))
741 state->clk_frequency = DEFAULT_SCLK_CSIS_FREQ;
742 if (of_property_read_u32(node, "bus-width",
743 &state->max_num_lanes))
744 return -EINVAL;
745
746 node = v4l2_of_get_next_endpoint(node, NULL);
747 if (!node) {
748 dev_err(&pdev->dev, "No port node at %s\n",
749 node->full_name);
750 return -EINVAL;
751 }
752 /* Get port node and validate MIPI-CSI channel id. */
753 v4l2_of_parse_endpoint(node, &endpoint);
754
755 state->index = endpoint.port - FIMC_INPUT_MIPI_CSI2_0;
756 if (state->index < 0 || state->index >= CSIS_MAX_ENTITIES)
757 return -ENXIO;
758
759 /* Get MIPI CSI-2 bus configration from the endpoint node. */
760 of_property_read_u32(node, "samsung,csis-hs-settle",
761 &state->hs_settle);
762 state->wclk_ext = of_property_read_bool(node,
763 "samsung,csis-wclk");
764
765 state->num_lanes = endpoint.bus.mipi_csi2.num_data_lanes;
766
767 of_node_put(node);
768 return 0;
769}
770#else
771#define s5pcsis_parse_dt(pdev, state) (-ENOSYS)
772#endif
773
704static int s5pcsis_probe(struct platform_device *pdev) 774static int s5pcsis_probe(struct platform_device *pdev)
705{ 775{
706 struct s5p_platform_mipi_csis *pdata; 776 struct device *dev = &pdev->dev;
707 struct resource *mem_res; 777 struct resource *mem_res;
708 struct csis_state *state; 778 struct csis_state *state;
709 int ret = -ENOMEM; 779 int ret = -ENOMEM;
710 int i; 780 int i;
711 781
712 state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); 782 state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
713 if (!state) 783 if (!state)
714 return -ENOMEM; 784 return -ENOMEM;
715 785
716 mutex_init(&state->lock); 786 mutex_init(&state->lock);
717 spin_lock_init(&state->slock); 787 spin_lock_init(&state->slock);
718
719 state->pdev = pdev; 788 state->pdev = pdev;
720 state->index = max(0, pdev->id);
721 789
722 pdata = pdev->dev.platform_data; 790 if (dev->of_node)
723 if (pdata == NULL) { 791 ret = s5pcsis_parse_dt(pdev, state);
724 dev_err(&pdev->dev, "Platform data not fully specified\n"); 792 else
725 return -EINVAL; 793 ret = s5pcsis_get_platform_data(pdev, state);
726 } 794 if (ret < 0)
795 return ret;
727 796
728 if ((state->index == 1 && pdata->lanes > CSIS1_MAX_LANES) || 797 if (state->num_lanes == 0 || state->num_lanes > state->max_num_lanes) {
729 pdata->lanes > CSIS0_MAX_LANES) { 798 dev_err(dev, "Unsupported number of data lanes: %d (max. %d)\n",
730 dev_err(&pdev->dev, "Unsupported number of data lanes: %d\n", 799 state->num_lanes, state->max_num_lanes);
731 pdata->lanes);
732 return -EINVAL; 800 return -EINVAL;
733 } 801 }
734 802
735 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 803 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
736 state->regs = devm_ioremap_resource(&pdev->dev, mem_res); 804 state->regs = devm_ioremap_resource(dev, mem_res);
737 if (IS_ERR(state->regs)) 805 if (IS_ERR(state->regs))
738 return PTR_ERR(state->regs); 806 return PTR_ERR(state->regs);
739 807
740 state->irq = platform_get_irq(pdev, 0); 808 state->irq = platform_get_irq(pdev, 0);
741 if (state->irq < 0) { 809 if (state->irq < 0) {
742 dev_err(&pdev->dev, "Failed to get irq\n"); 810 dev_err(dev, "Failed to get irq\n");
743 return state->irq; 811 return state->irq;
744 } 812 }
745 813
746 for (i = 0; i < CSIS_NUM_SUPPLIES; i++) 814 for (i = 0; i < CSIS_NUM_SUPPLIES; i++)
747 state->supplies[i].supply = csis_supply_name[i]; 815 state->supplies[i].supply = csis_supply_name[i];
748 816
749 ret = devm_regulator_bulk_get(&pdev->dev, CSIS_NUM_SUPPLIES, 817 ret = devm_regulator_bulk_get(dev, CSIS_NUM_SUPPLIES,
750 state->supplies); 818 state->supplies);
751 if (ret) 819 if (ret)
752 return ret; 820 return ret;
@@ -755,11 +823,11 @@ static int s5pcsis_probe(struct platform_device *pdev)
755 if (ret < 0) 823 if (ret < 0)
756 return ret; 824 return ret;
757 825
758 if (pdata->clk_rate) 826 if (state->clk_frequency)
759 ret = clk_set_rate(state->clock[CSIS_CLK_MUX], 827 ret = clk_set_rate(state->clock[CSIS_CLK_MUX],
760 pdata->clk_rate); 828 state->clk_frequency);
761 else 829 else
762 dev_WARN(&pdev->dev, "No clock frequency specified!\n"); 830 dev_WARN(dev, "No clock frequency specified!\n");
763 if (ret < 0) 831 if (ret < 0)
764 goto e_clkput; 832 goto e_clkput;
765 833
@@ -767,16 +835,17 @@ static int s5pcsis_probe(struct platform_device *pdev)
767 if (ret < 0) 835 if (ret < 0)
768 goto e_clkput; 836 goto e_clkput;
769 837
770 ret = devm_request_irq(&pdev->dev, state->irq, s5pcsis_irq_handler, 838 ret = devm_request_irq(dev, state->irq, s5pcsis_irq_handler,
771 0, dev_name(&pdev->dev), state); 839 0, dev_name(dev), state);
772 if (ret) { 840 if (ret) {
773 dev_err(&pdev->dev, "Interrupt request failed\n"); 841 dev_err(dev, "Interrupt request failed\n");
774 goto e_clkdis; 842 goto e_clkdis;
775 } 843 }
776 844
777 v4l2_subdev_init(&state->sd, &s5pcsis_subdev_ops); 845 v4l2_subdev_init(&state->sd, &s5pcsis_subdev_ops);
778 state->sd.owner = THIS_MODULE; 846 state->sd.owner = THIS_MODULE;
779 strlcpy(state->sd.name, dev_name(&pdev->dev), sizeof(state->sd.name)); 847 snprintf(state->sd.name, sizeof(state->sd.name), "%s.%d",
848 CSIS_SUBDEV_NAME, state->index);
780 state->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 849 state->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
781 state->csis_fmt = &s5pcsis_formats[0]; 850 state->csis_fmt = &s5pcsis_formats[0];
782 851
@@ -796,10 +865,12 @@ static int s5pcsis_probe(struct platform_device *pdev)
796 865
797 /* .. and a pointer to the subdev. */ 866 /* .. and a pointer to the subdev. */
798 platform_set_drvdata(pdev, &state->sd); 867 platform_set_drvdata(pdev, &state->sd);
799
800 memcpy(state->events, s5pcsis_events, sizeof(state->events)); 868 memcpy(state->events, s5pcsis_events, sizeof(state->events));
869 pm_runtime_enable(dev);
801 870
802 pm_runtime_enable(&pdev->dev); 871 dev_info(&pdev->dev, "lanes: %d, hs_settle: %d, wclk: %d, freq: %u\n",
872 state->num_lanes, state->hs_settle, state->wclk_ext,
873 state->clk_frequency);
803 return 0; 874 return 0;
804 875
805e_clkdis: 876e_clkdis:
@@ -923,13 +994,21 @@ static const struct dev_pm_ops s5pcsis_pm_ops = {
923 SET_SYSTEM_SLEEP_PM_OPS(s5pcsis_suspend, s5pcsis_resume) 994 SET_SYSTEM_SLEEP_PM_OPS(s5pcsis_suspend, s5pcsis_resume)
924}; 995};
925 996
997static const struct of_device_id s5pcsis_of_match[] = {
998 { .compatible = "samsung,s5pv210-csis" },
999 { .compatible = "samsung,exynos4210-csis" },
1000 { /* sentinel */ },
1001};
1002MODULE_DEVICE_TABLE(of, s5pcsis_of_match);
1003
926static struct platform_driver s5pcsis_driver = { 1004static struct platform_driver s5pcsis_driver = {
927 .probe = s5pcsis_probe, 1005 .probe = s5pcsis_probe,
928 .remove = s5pcsis_remove, 1006 .remove = s5pcsis_remove,
929 .driver = { 1007 .driver = {
930 .name = CSIS_DRIVER_NAME, 1008 .of_match_table = s5pcsis_of_match,
931 .owner = THIS_MODULE, 1009 .name = CSIS_DRIVER_NAME,
932 .pm = &s5pcsis_pm_ops, 1010 .owner = THIS_MODULE,
1011 .pm = &s5pcsis_pm_ops,
933 }, 1012 },
934}; 1013};
935 1014
diff --git a/drivers/media/platform/s5p-fimc/mipi-csis.h b/drivers/media/platform/exynos4-is/mipi-csis.h
index 2709286396e1..28c11c4085d8 100644
--- a/drivers/media/platform/s5p-fimc/mipi-csis.h
+++ b/drivers/media/platform/exynos4-is/mipi-csis.h
@@ -11,6 +11,7 @@
11#define S5P_MIPI_CSIS_H_ 11#define S5P_MIPI_CSIS_H_
12 12
13#define CSIS_DRIVER_NAME "s5p-mipi-csis" 13#define CSIS_DRIVER_NAME "s5p-mipi-csis"
14#define CSIS_SUBDEV_NAME CSIS_DRIVER_NAME
14#define CSIS_MAX_ENTITIES 2 15#define CSIS_MAX_ENTITIES 2
15#define CSIS0_MAX_LANES 4 16#define CSIS0_MAX_LANES 4
16#define CSIS1_MAX_LANES 2 17#define CSIS1_MAX_LANES 2
diff --git a/drivers/media/platform/fsl-viu.c b/drivers/media/platform/fsl-viu.c
index 5f7db3f1f6f5..3a6a0dcdc3e4 100644
--- a/drivers/media/platform/fsl-viu.c
+++ b/drivers/media/platform/fsl-viu.c
@@ -957,12 +957,12 @@ static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
957 return 0; 957 return 0;
958} 958}
959 959
960static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 960static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
961{ 961{
962 struct viu_fh *fh = priv; 962 struct viu_fh *fh = priv;
963 963
964 fh->dev->std = *id; 964 fh->dev->std = id;
965 decoder_call(fh->dev, core, s_std, *id); 965 decoder_call(fh->dev, core, s_std, id);
966 return 0; 966 return 0;
967} 967}
968 968
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 6c4db9b98989..758564649589 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -207,6 +207,9 @@ static void dma_callback(void *data)
207 src_vb = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx); 207 src_vb = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx);
208 dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx); 208 dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx);
209 209
210 src_vb->v4l2_buf.timestamp = dst_vb->v4l2_buf.timestamp;
211 src_vb->v4l2_buf.timecode = dst_vb->v4l2_buf.timecode;
212
210 v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE); 213 v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
211 v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE); 214 v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
212 215
@@ -866,6 +869,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
866 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 869 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
867 src_vq->ops = &deinterlace_qops; 870 src_vq->ops = &deinterlace_qops;
868 src_vq->mem_ops = &vb2_dma_contig_memops; 871 src_vq->mem_ops = &vb2_dma_contig_memops;
872 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
869 q_data[V4L2_M2M_SRC].fmt = &formats[0]; 873 q_data[V4L2_M2M_SRC].fmt = &formats[0];
870 q_data[V4L2_M2M_SRC].width = 640; 874 q_data[V4L2_M2M_SRC].width = 640;
871 q_data[V4L2_M2M_SRC].height = 480; 875 q_data[V4L2_M2M_SRC].height = 480;
@@ -882,6 +886,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
882 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 886 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
883 dst_vq->ops = &deinterlace_qops; 887 dst_vq->ops = &deinterlace_qops;
884 dst_vq->mem_ops = &vb2_dma_contig_memops; 888 dst_vq->mem_ops = &vb2_dma_contig_memops;
889 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
885 q_data[V4L2_M2M_DST].fmt = &formats[0]; 890 q_data[V4L2_M2M_DST].fmt = &formats[0];
886 q_data[V4L2_M2M_DST].width = 640; 891 q_data[V4L2_M2M_DST].width = 640;
887 q_data[V4L2_M2M_DST].height = 480; 892 q_data[V4L2_M2M_DST].height = 480;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 92a33f081852..64ab91edfb81 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1357,7 +1357,7 @@ static int mcam_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
1357} 1357}
1358 1358
1359/* from vivi.c */ 1359/* from vivi.c */
1360static int mcam_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a) 1360static int mcam_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id a)
1361{ 1361{
1362 return 0; 1362 return 0;
1363} 1363}
@@ -1445,7 +1445,7 @@ static int mcam_vidioc_g_register(struct file *file, void *priv,
1445} 1445}
1446 1446
1447static int mcam_vidioc_s_register(struct file *file, void *priv, 1447static int mcam_vidioc_s_register(struct file *file, void *priv,
1448 struct v4l2_dbg_register *reg) 1448 const struct v4l2_dbg_register *reg)
1449{ 1449{
1450 struct mcam_camera *cam = priv; 1450 struct mcam_camera *cam = priv;
1451 1451
diff --git a/drivers/media/platform/mem2mem_testdev.c b/drivers/media/platform/mem2mem_testdev.c
index 7487d7208dea..4cc7f65d7d76 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -38,6 +38,10 @@ MODULE_AUTHOR("Pawel Osciak, <pawel@osciak.com>");
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39MODULE_VERSION("0.1.1"); 39MODULE_VERSION("0.1.1");
40 40
41static unsigned debug;
42module_param(debug, uint, 0644);
43MODULE_PARM_DESC(debug, "activates debug info");
44
41#define MIN_W 32 45#define MIN_W 32
42#define MIN_H 32 46#define MIN_H 32
43#define MAX_W 640 47#define MAX_W 640
@@ -67,7 +71,7 @@ MODULE_VERSION("0.1.1");
67#define MEM2MEM_VFLIP (1 << 1) 71#define MEM2MEM_VFLIP (1 << 1)
68 72
69#define dprintk(dev, fmt, arg...) \ 73#define dprintk(dev, fmt, arg...) \
70 v4l2_dbg(1, 1, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg) 74 v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
71 75
72 76
73static void m2mtest_dev_release(struct device *dev) 77static void m2mtest_dev_release(struct device *dev)
@@ -234,6 +238,10 @@ static int device_process(struct m2mtest_ctx *ctx,
234 bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES; 238 bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES;
235 w = 0; 239 w = 0;
236 240
241 memcpy(&out_vb->v4l2_buf.timestamp,
242 &in_vb->v4l2_buf.timestamp,
243 sizeof(struct timeval));
244
237 switch (ctx->mode) { 245 switch (ctx->mode) {
238 case MEM2MEM_HFLIP | MEM2MEM_VFLIP: 246 case MEM2MEM_HFLIP | MEM2MEM_VFLIP:
239 p_out += bytesperline * height - bytes_left; 247 p_out += bytesperline * height - bytes_left;
@@ -844,6 +852,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *ds
844 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 852 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
845 src_vq->ops = &m2mtest_qops; 853 src_vq->ops = &m2mtest_qops;
846 src_vq->mem_ops = &vb2_vmalloc_memops; 854 src_vq->mem_ops = &vb2_vmalloc_memops;
855 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
847 856
848 ret = vb2_queue_init(src_vq); 857 ret = vb2_queue_init(src_vq);
849 if (ret) 858 if (ret)
@@ -855,6 +864,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *ds
855 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 864 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
856 dst_vq->ops = &m2mtest_qops; 865 dst_vq->ops = &m2mtest_qops;
857 dst_vq->mem_ops = &vb2_vmalloc_memops; 866 dst_vq->mem_ops = &vb2_vmalloc_memops;
867 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
858 868
859 return vb2_queue_init(dst_vq); 869 return vb2_queue_init(dst_vq);
860} 870}
diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c
index 4b9e0a28616a..f7440e585b6b 100644
--- a/drivers/media/platform/mx2_emmaprp.c
+++ b/drivers/media/platform/mx2_emmaprp.c
@@ -377,6 +377,9 @@ static irqreturn_t emmaprp_irq(int irq_emma, void *data)
377 src_vb = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx); 377 src_vb = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx);
378 dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx); 378 dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx);
379 379
380 src_vb->v4l2_buf.timestamp = dst_vb->v4l2_buf.timestamp;
381 src_vb->v4l2_buf.timecode = dst_vb->v4l2_buf.timecode;
382
380 spin_lock_irqsave(&pcdev->irqlock, flags); 383 spin_lock_irqsave(&pcdev->irqlock, flags);
381 v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE); 384 v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
382 v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE); 385 v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
@@ -763,6 +766,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
763 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 766 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
764 src_vq->ops = &emmaprp_qops; 767 src_vq->ops = &emmaprp_qops;
765 src_vq->mem_ops = &vb2_dma_contig_memops; 768 src_vq->mem_ops = &vb2_dma_contig_memops;
769 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
766 770
767 ret = vb2_queue_init(src_vq); 771 ret = vb2_queue_init(src_vq);
768 if (ret) 772 if (ret)
@@ -774,6 +778,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
774 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 778 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
775 dst_vq->ops = &emmaprp_qops; 779 dst_vq->ops = &emmaprp_qops;
776 dst_vq->mem_ops = &vb2_dma_contig_memops; 780 dst_vq->mem_ops = &vb2_dma_contig_memops;
781 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
777 782
778 return vb2_queue_init(dst_vq); 783 return vb2_queue_init(dst_vq);
779} 784}
diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
index 96c4a17e4280..477268a2415f 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -648,9 +648,12 @@ static void omap_vout_isr(void *arg, unsigned int irqstatus)
648 648
649 /* First save the configuration in ovelray structure */ 649 /* First save the configuration in ovelray structure */
650 ret = omapvid_init(vout, addr); 650 ret = omapvid_init(vout, addr);
651 if (ret) 651 if (ret) {
652 printk(KERN_ERR VOUT_NAME 652 printk(KERN_ERR VOUT_NAME
653 "failed to set overlay info\n"); 653 "failed to set overlay info\n");
654 goto vout_isr_err;
655 }
656
654 /* Enable the pipeline and set the Go bit */ 657 /* Enable the pipeline and set the Go bit */
655 ret = omapvid_apply_changes(vout); 658 ret = omapvid_apply_changes(vout);
656 if (ret) 659 if (ret)
@@ -1660,13 +1663,16 @@ static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
1660 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD 1663 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD
1661 | DISPC_IRQ_VSYNC2; 1664 | DISPC_IRQ_VSYNC2;
1662 1665
1663 omap_dispc_register_isr(omap_vout_isr, vout, mask);
1664
1665 /* First save the configuration in ovelray structure */ 1666 /* First save the configuration in ovelray structure */
1666 ret = omapvid_init(vout, addr); 1667 ret = omapvid_init(vout, addr);
1667 if (ret) 1668 if (ret) {
1668 v4l2_err(&vout->vid_dev->v4l2_dev, 1669 v4l2_err(&vout->vid_dev->v4l2_dev,
1669 "failed to set overlay info\n"); 1670 "failed to set overlay info\n");
1671 goto streamon_err1;
1672 }
1673
1674 omap_dispc_register_isr(omap_vout_isr, vout, mask);
1675
1670 /* Enable the pipeline and set the Go bit */ 1676 /* Enable the pipeline and set the Go bit */
1671 ret = omapvid_apply_changes(vout); 1677 ret = omapvid_apply_changes(vout);
1672 if (ret) 1678 if (ret)
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index a55793c3d811..70438a0f62ae 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -934,12 +934,19 @@ static int s3c_camif_reqbufs(struct file *file, void *priv,
934 vp->owner = NULL; 934 vp->owner = NULL;
935 935
936 ret = vb2_reqbufs(&vp->vb_queue, rb); 936 ret = vb2_reqbufs(&vp->vb_queue, rb);
937 if (!ret) { 937 if (ret < 0)
938 vp->reqbufs_count = rb->count; 938 return ret;
939 if (vp->owner == NULL && rb->count > 0) 939
940 vp->owner = priv; 940 if (rb->count && rb->count < CAMIF_REQ_BUFS_MIN) {
941 rb->count = 0;
942 vb2_reqbufs(&vp->vb_queue, rb);
943 ret = -ENOMEM;
941 } 944 }
942 945
946 vp->reqbufs_count = rb->count;
947 if (vp->owner == NULL && rb->count > 0)
948 vp->owner = priv;
949
943 return ret; 950 return ret;
944} 951}
945 952
@@ -1153,6 +1160,7 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
1153 q->mem_ops = &vb2_dma_contig_memops; 1160 q->mem_ops = &vb2_dma_contig_memops;
1154 q->buf_struct_size = sizeof(struct camif_buffer); 1161 q->buf_struct_size = sizeof(struct camif_buffer);
1155 q->drv_priv = vp; 1162 q->drv_priv = vp;
1163 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1156 1164
1157 ret = vb2_queue_init(q); 1165 ret = vb2_queue_init(q);
1158 if (ret) 1166 if (ret)
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index aaaf276a5a6c..553d87e5ceab 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/clk.h> 19#include <linux/clk.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/of.h>
21 22
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <media/v4l2-mem2mem.h> 24#include <media/v4l2-mem2mem.h>
@@ -157,6 +158,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
157 src_vq->ops = &g2d_qops; 158 src_vq->ops = &g2d_qops;
158 src_vq->mem_ops = &vb2_dma_contig_memops; 159 src_vq->mem_ops = &vb2_dma_contig_memops;
159 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 160 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
161 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
160 162
161 ret = vb2_queue_init(src_vq); 163 ret = vb2_queue_init(src_vq);
162 if (ret) 164 if (ret)
@@ -168,6 +170,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
168 dst_vq->ops = &g2d_qops; 170 dst_vq->ops = &g2d_qops;
169 dst_vq->mem_ops = &vb2_dma_contig_memops; 171 dst_vq->mem_ops = &vb2_dma_contig_memops;
170 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 172 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
173 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
171 174
172 return vb2_queue_init(dst_vq); 175 return vb2_queue_init(dst_vq);
173} 176}
@@ -634,6 +637,9 @@ static irqreturn_t g2d_isr(int irq, void *prv)
634 BUG_ON(src == NULL); 637 BUG_ON(src == NULL);
635 BUG_ON(dst == NULL); 638 BUG_ON(dst == NULL);
636 639
640 dst->v4l2_buf.timecode = src->v4l2_buf.timecode;
641 dst->v4l2_buf.timestamp = src->v4l2_buf.timestamp;
642
637 v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE); 643 v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE);
638 v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE); 644 v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE);
639 v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx); 645 v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx);
@@ -695,11 +701,14 @@ static struct v4l2_m2m_ops g2d_m2m_ops = {
695 .unlock = g2d_unlock, 701 .unlock = g2d_unlock,
696}; 702};
697 703
704static const struct of_device_id exynos_g2d_match[];
705
698static int g2d_probe(struct platform_device *pdev) 706static int g2d_probe(struct platform_device *pdev)
699{ 707{
700 struct g2d_dev *dev; 708 struct g2d_dev *dev;
701 struct video_device *vfd; 709 struct video_device *vfd;
702 struct resource *res; 710 struct resource *res;
711 const struct of_device_id *of_id;
703 int ret = 0; 712 int ret = 0;
704 713
705 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 714 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
@@ -794,7 +803,17 @@ static int g2d_probe(struct platform_device *pdev)
794 } 803 }
795 804
796 def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3; 805 def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3;
797 dev->variant = g2d_get_drv_data(pdev); 806
807 if (!pdev->dev.of_node) {
808 dev->variant = g2d_get_drv_data(pdev);
809 } else {
810 of_id = of_match_node(exynos_g2d_match, pdev->dev.of_node);
811 if (!of_id) {
812 ret = -ENODEV;
813 goto unreg_video_dev;
814 }
815 dev->variant = (struct g2d_variant *)of_id->data;
816 }
798 817
799 return 0; 818 return 0;
800 819
@@ -835,13 +854,25 @@ static int g2d_remove(struct platform_device *pdev)
835} 854}
836 855
837static struct g2d_variant g2d_drvdata_v3x = { 856static struct g2d_variant g2d_drvdata_v3x = {
838 .hw_rev = TYPE_G2D_3X, 857 .hw_rev = TYPE_G2D_3X, /* Revision 3.0 for S5PV210 and Exynos4210 */
839}; 858};
840 859
841static struct g2d_variant g2d_drvdata_v4x = { 860static struct g2d_variant g2d_drvdata_v4x = {
842 .hw_rev = TYPE_G2D_4X, /* Revision 4.1 for Exynos4X12 and Exynos5 */ 861 .hw_rev = TYPE_G2D_4X, /* Revision 4.1 for Exynos4X12 and Exynos5 */
843}; 862};
844 863
864static const struct of_device_id exynos_g2d_match[] = {
865 {
866 .compatible = "samsung,s5pv210-g2d",
867 .data = &g2d_drvdata_v3x,
868 }, {
869 .compatible = "samsung,exynos4212-g2d",
870 .data = &g2d_drvdata_v4x,
871 },
872 {},
873};
874MODULE_DEVICE_TABLE(of, exynos_g2d_match);
875
845static struct platform_device_id g2d_driver_ids[] = { 876static struct platform_device_id g2d_driver_ids[] = {
846 { 877 {
847 .name = "s5p-g2d", 878 .name = "s5p-g2d",
@@ -861,6 +892,7 @@ static struct platform_driver g2d_pdrv = {
861 .driver = { 892 .driver = {
862 .name = G2D_NAME, 893 .name = G2D_NAME,
863 .owner = THIS_MODULE, 894 .owner = THIS_MODULE,
895 .of_match_table = exynos_g2d_match,
864 }, 896 },
865}; 897};
866 898
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 3b023752bcb4..15d23968d1de 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1229,6 +1229,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
1229 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 1229 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1230 src_vq->ops = &s5p_jpeg_qops; 1230 src_vq->ops = &s5p_jpeg_qops;
1231 src_vq->mem_ops = &vb2_dma_contig_memops; 1231 src_vq->mem_ops = &vb2_dma_contig_memops;
1232 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1232 1233
1233 ret = vb2_queue_init(src_vq); 1234 ret = vb2_queue_init(src_vq);
1234 if (ret) 1235 if (ret)
@@ -1240,6 +1241,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
1240 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 1241 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1241 dst_vq->ops = &s5p_jpeg_qops; 1242 dst_vq->ops = &s5p_jpeg_qops;
1242 dst_vq->mem_ops = &vb2_dma_contig_memops; 1243 dst_vq->mem_ops = &vb2_dma_contig_memops;
1244 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1243 1245
1244 return vb2_queue_init(dst_vq); 1246 return vb2_queue_init(dst_vq);
1245} 1247}
@@ -1287,6 +1289,9 @@ static irqreturn_t s5p_jpeg_irq(int irq, void *dev_id)
1287 payload_size = jpeg_compressed_size(jpeg->regs); 1289 payload_size = jpeg_compressed_size(jpeg->regs);
1288 } 1290 }
1289 1291
1292 dst_buf->v4l2_buf.timecode = src_buf->v4l2_buf.timecode;
1293 dst_buf->v4l2_buf.timestamp = src_buf->v4l2_buf.timestamp;
1294
1290 v4l2_m2m_buf_done(src_buf, state); 1295 v4l2_m2m_buf_done(src_buf, state);
1291 if (curr_ctx->mode == S5P_JPEG_ENCODE) 1296 if (curr_ctx->mode == S5P_JPEG_ENCODE)
1292 vb2_set_plane_payload(dst_buf, 0, payload_size); 1297 vb2_set_plane_payload(dst_buf, 0, payload_size);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 1cb6d57987c6..01f9ae0dadb0 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -243,12 +243,10 @@ static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx)
243 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list); 243 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
244 list_for_each_entry(dst_buf, &ctx->dst_queue, list) { 244 list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
245 if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dec_y_addr) { 245 if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dec_y_addr) {
246 memcpy(&dst_buf->b->v4l2_buf.timecode, 246 dst_buf->b->v4l2_buf.timecode =
247 &src_buf->b->v4l2_buf.timecode, 247 src_buf->b->v4l2_buf.timecode;
248 sizeof(struct v4l2_timecode)); 248 dst_buf->b->v4l2_buf.timestamp =
249 memcpy(&dst_buf->b->v4l2_buf.timestamp, 249 src_buf->b->v4l2_buf.timestamp;
250 &src_buf->b->v4l2_buf.timestamp,
251 sizeof(struct timeval));
252 switch (frame_type) { 250 switch (frame_type) {
253 case S5P_FIMV_DECODE_FRAME_I_FRAME: 251 case S5P_FIMV_DECODE_FRAME_I_FRAME:
254 dst_buf->b->v4l2_buf.flags |= 252 dst_buf->b->v4l2_buf.flags |=
@@ -386,6 +384,8 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
386 } else { 384 } else {
387 mfc_debug(2, "MFC needs next buffer\n"); 385 mfc_debug(2, "MFC needs next buffer\n");
388 ctx->consumed_stream = 0; 386 ctx->consumed_stream = 0;
387 if (src_buf->flags & MFC_BUF_FLAG_EOS)
388 ctx->state = MFCINST_FINISHING;
389 list_del(&src_buf->list); 389 list_del(&src_buf->list);
390 ctx->src_queue_cnt--; 390 ctx->src_queue_cnt--;
391 if (s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) > 0) 391 if (s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) > 0)
@@ -804,6 +804,7 @@ static int s5p_mfc_open(struct file *file)
804 goto err_queue_init; 804 goto err_queue_init;
805 } 805 }
806 q->mem_ops = (struct vb2_mem_ops *)&vb2_dma_contig_memops; 806 q->mem_ops = (struct vb2_mem_ops *)&vb2_dma_contig_memops;
807 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
807 ret = vb2_queue_init(q); 808 ret = vb2_queue_init(q);
808 if (ret) { 809 if (ret) {
809 mfc_err("Failed to initialize videobuf2 queue(capture)\n"); 810 mfc_err("Failed to initialize videobuf2 queue(capture)\n");
@@ -825,6 +826,7 @@ static int s5p_mfc_open(struct file *file)
825 goto err_queue_init; 826 goto err_queue_init;
826 } 827 }
827 q->mem_ops = (struct vb2_mem_ops *)&vb2_dma_contig_memops; 828 q->mem_ops = (struct vb2_mem_ops *)&vb2_dma_contig_memops;
829 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
828 ret = vb2_queue_init(q); 830 ret = vb2_queue_init(q);
829 if (ret) { 831 if (ret) {
830 mfc_err("Failed to initialize videobuf2 queue(output)\n"); 832 mfc_err("Failed to initialize videobuf2 queue(output)\n");
@@ -1016,7 +1018,7 @@ static void *mfc_get_drv_data(struct platform_device *pdev);
1016 1018
1017static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev) 1019static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
1018{ 1020{
1019 unsigned int mem_info[2]; 1021 unsigned int mem_info[2] = { };
1020 1022
1021 dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev, 1023 dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev,
1022 sizeof(struct device), GFP_KERNEL); 1024 sizeof(struct device), GFP_KERNEL);
@@ -1106,7 +1108,8 @@ static int s5p_mfc_probe(struct platform_device *pdev)
1106 } 1108 }
1107 1109
1108 if (pdev->dev.of_node) { 1110 if (pdev->dev.of_node) {
1109 if (s5p_mfc_alloc_memdevs(dev) < 0) 1111 ret = s5p_mfc_alloc_memdevs(dev);
1112 if (ret < 0)
1110 goto err_res; 1113 goto err_res;
1111 } else { 1114 } else {
1112 dev->mem_dev_l = device_find_child(&dev->plat_dev->dev, 1115 dev->mem_dev_l = device_find_child(&dev->plat_dev->dev,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
index 138778083c63..ad4f1df0a18e 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
@@ -16,7 +16,7 @@
16#include "s5p_mfc_debug.h" 16#include "s5p_mfc_debug.h"
17 17
18/* This function is used to send a command to the MFC */ 18/* This function is used to send a command to the MFC */
19int s5p_mfc_cmd_host2risc_v5(struct s5p_mfc_dev *dev, int cmd, 19static int s5p_mfc_cmd_host2risc_v5(struct s5p_mfc_dev *dev, int cmd,
20 struct s5p_mfc_cmd_args *args) 20 struct s5p_mfc_cmd_args *args)
21{ 21{
22 int cur_cmd; 22 int cur_cmd;
@@ -41,7 +41,7 @@ int s5p_mfc_cmd_host2risc_v5(struct s5p_mfc_dev *dev, int cmd,
41} 41}
42 42
43/* Initialize the MFC */ 43/* Initialize the MFC */
44int s5p_mfc_sys_init_cmd_v5(struct s5p_mfc_dev *dev) 44static int s5p_mfc_sys_init_cmd_v5(struct s5p_mfc_dev *dev)
45{ 45{
46 struct s5p_mfc_cmd_args h2r_args; 46 struct s5p_mfc_cmd_args h2r_args;
47 47
@@ -52,7 +52,7 @@ int s5p_mfc_sys_init_cmd_v5(struct s5p_mfc_dev *dev)
52} 52}
53 53
54/* Suspend the MFC hardware */ 54/* Suspend the MFC hardware */
55int s5p_mfc_sleep_cmd_v5(struct s5p_mfc_dev *dev) 55static int s5p_mfc_sleep_cmd_v5(struct s5p_mfc_dev *dev)
56{ 56{
57 struct s5p_mfc_cmd_args h2r_args; 57 struct s5p_mfc_cmd_args h2r_args;
58 58
@@ -61,7 +61,7 @@ int s5p_mfc_sleep_cmd_v5(struct s5p_mfc_dev *dev)
61} 61}
62 62
63/* Wake up the MFC hardware */ 63/* Wake up the MFC hardware */
64int s5p_mfc_wakeup_cmd_v5(struct s5p_mfc_dev *dev) 64static int s5p_mfc_wakeup_cmd_v5(struct s5p_mfc_dev *dev)
65{ 65{
66 struct s5p_mfc_cmd_args h2r_args; 66 struct s5p_mfc_cmd_args h2r_args;
67 67
@@ -71,7 +71,7 @@ int s5p_mfc_wakeup_cmd_v5(struct s5p_mfc_dev *dev)
71} 71}
72 72
73 73
74int s5p_mfc_open_inst_cmd_v5(struct s5p_mfc_ctx *ctx) 74static int s5p_mfc_open_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
75{ 75{
76 struct s5p_mfc_dev *dev = ctx->dev; 76 struct s5p_mfc_dev *dev = ctx->dev;
77 struct s5p_mfc_cmd_args h2r_args; 77 struct s5p_mfc_cmd_args h2r_args;
@@ -124,7 +124,7 @@ int s5p_mfc_open_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
124 return ret; 124 return ret;
125} 125}
126 126
127int s5p_mfc_close_inst_cmd_v5(struct s5p_mfc_ctx *ctx) 127static int s5p_mfc_close_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
128{ 128{
129 struct s5p_mfc_dev *dev = ctx->dev; 129 struct s5p_mfc_dev *dev = ctx->dev;
130 struct s5p_mfc_cmd_args h2r_args; 130 struct s5p_mfc_cmd_args h2r_args;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
index 754bfbcb1c43..5708fc3d9b4d 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
@@ -17,7 +17,7 @@
17#include "s5p_mfc_intr.h" 17#include "s5p_mfc_intr.h"
18#include "s5p_mfc_opr.h" 18#include "s5p_mfc_opr.h"
19 19
20int s5p_mfc_cmd_host2risc_v6(struct s5p_mfc_dev *dev, int cmd, 20static int s5p_mfc_cmd_host2risc_v6(struct s5p_mfc_dev *dev, int cmd,
21 struct s5p_mfc_cmd_args *args) 21 struct s5p_mfc_cmd_args *args)
22{ 22{
23 mfc_debug(2, "Issue the command: %d\n", cmd); 23 mfc_debug(2, "Issue the command: %d\n", cmd);
@@ -32,7 +32,7 @@ int s5p_mfc_cmd_host2risc_v6(struct s5p_mfc_dev *dev, int cmd,
32 return 0; 32 return 0;
33} 33}
34 34
35int s5p_mfc_sys_init_cmd_v6(struct s5p_mfc_dev *dev) 35static int s5p_mfc_sys_init_cmd_v6(struct s5p_mfc_dev *dev)
36{ 36{
37 struct s5p_mfc_cmd_args h2r_args; 37 struct s5p_mfc_cmd_args h2r_args;
38 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv; 38 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
@@ -44,7 +44,7 @@ int s5p_mfc_sys_init_cmd_v6(struct s5p_mfc_dev *dev)
44 &h2r_args); 44 &h2r_args);
45} 45}
46 46
47int s5p_mfc_sleep_cmd_v6(struct s5p_mfc_dev *dev) 47static int s5p_mfc_sleep_cmd_v6(struct s5p_mfc_dev *dev)
48{ 48{
49 struct s5p_mfc_cmd_args h2r_args; 49 struct s5p_mfc_cmd_args h2r_args;
50 50
@@ -53,7 +53,7 @@ int s5p_mfc_sleep_cmd_v6(struct s5p_mfc_dev *dev)
53 &h2r_args); 53 &h2r_args);
54} 54}
55 55
56int s5p_mfc_wakeup_cmd_v6(struct s5p_mfc_dev *dev) 56static int s5p_mfc_wakeup_cmd_v6(struct s5p_mfc_dev *dev)
57{ 57{
58 struct s5p_mfc_cmd_args h2r_args; 58 struct s5p_mfc_cmd_args h2r_args;
59 59
@@ -63,7 +63,7 @@ int s5p_mfc_wakeup_cmd_v6(struct s5p_mfc_dev *dev)
63} 63}
64 64
65/* Open a new instance and get its number */ 65/* Open a new instance and get its number */
66int s5p_mfc_open_inst_cmd_v6(struct s5p_mfc_ctx *ctx) 66static int s5p_mfc_open_inst_cmd_v6(struct s5p_mfc_ctx *ctx)
67{ 67{
68 struct s5p_mfc_dev *dev = ctx->dev; 68 struct s5p_mfc_dev *dev = ctx->dev;
69 struct s5p_mfc_cmd_args h2r_args; 69 struct s5p_mfc_cmd_args h2r_args;
@@ -121,7 +121,7 @@ int s5p_mfc_open_inst_cmd_v6(struct s5p_mfc_ctx *ctx)
121} 121}
122 122
123/* Close instance */ 123/* Close instance */
124int s5p_mfc_close_inst_cmd_v6(struct s5p_mfc_ctx *ctx) 124static int s5p_mfc_close_inst_cmd_v6(struct s5p_mfc_ctx *ctx)
125{ 125{
126 struct s5p_mfc_dev *dev = ctx->dev; 126 struct s5p_mfc_dev *dev = ctx->dev;
127 struct s5p_mfc_cmd_args h2r_args; 127 struct s5p_mfc_cmd_args h2r_args;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 4582473978ca..4af53bd2f182 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -22,6 +22,7 @@
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <media/v4l2-ctrls.h> 24#include <media/v4l2-ctrls.h>
25#include <media/v4l2-event.h>
25#include <media/videobuf2-core.h> 26#include <media/videobuf2-core.h>
26#include "s5p_mfc_common.h" 27#include "s5p_mfc_common.h"
27#include "s5p_mfc_debug.h" 28#include "s5p_mfc_debug.h"
@@ -623,17 +624,27 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
623/* Dequeue a buffer */ 624/* Dequeue a buffer */
624static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 625static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
625{ 626{
627 const struct v4l2_event ev = {
628 .type = V4L2_EVENT_EOS
629 };
626 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); 630 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
631 int ret;
627 632
628 if (ctx->state == MFCINST_ERROR) { 633 if (ctx->state == MFCINST_ERROR) {
629 mfc_err("Call on DQBUF after unrecoverable error\n"); 634 mfc_err("Call on DQBUF after unrecoverable error\n");
630 return -EIO; 635 return -EIO;
631 } 636 }
632 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 637 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
633 return vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK); 638 ret = vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
634 else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 639 else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
635 return vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK); 640 ret = vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
636 return -EINVAL; 641 if (ret == 0 && ctx->state == MFCINST_FINISHED &&
642 list_empty(&ctx->vq_dst.done_list))
643 v4l2_event_queue_fh(&ctx->fh, &ev);
644 } else {
645 ret = -EINVAL;
646 }
647 return ret;
637} 648}
638 649
639/* Export DMA buffer */ 650/* Export DMA buffer */
@@ -809,6 +820,59 @@ static int vidioc_g_crop(struct file *file, void *priv,
809 return 0; 820 return 0;
810} 821}
811 822
823int vidioc_decoder_cmd(struct file *file, void *priv,
824 struct v4l2_decoder_cmd *cmd)
825{
826 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
827 struct s5p_mfc_dev *dev = ctx->dev;
828 struct s5p_mfc_buf *buf;
829 unsigned long flags;
830
831 switch (cmd->cmd) {
832 case V4L2_ENC_CMD_STOP:
833 if (cmd->flags != 0)
834 return -EINVAL;
835
836 if (!ctx->vq_src.streaming)
837 return -EINVAL;
838
839 spin_lock_irqsave(&dev->irqlock, flags);
840 if (list_empty(&ctx->src_queue)) {
841 mfc_err("EOS: empty src queue, entering finishing state");
842 ctx->state = MFCINST_FINISHING;
843 if (s5p_mfc_ctx_ready(ctx))
844 set_work_bit_irqsave(ctx);
845 spin_unlock_irqrestore(&dev->irqlock, flags);
846 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
847 } else {
848 mfc_err("EOS: marking last buffer of stream");
849 buf = list_entry(ctx->src_queue.prev,
850 struct s5p_mfc_buf, list);
851 if (buf->flags & MFC_BUF_FLAG_USED)
852 ctx->state = MFCINST_FINISHING;
853 else
854 buf->flags |= MFC_BUF_FLAG_EOS;
855 spin_unlock_irqrestore(&dev->irqlock, flags);
856 }
857 break;
858 default:
859 return -EINVAL;
860 }
861 return 0;
862}
863
864static int vidioc_subscribe_event(struct v4l2_fh *fh,
865 const struct v4l2_event_subscription *sub)
866{
867 switch (sub->type) {
868 case V4L2_EVENT_EOS:
869 return v4l2_event_subscribe(fh, sub, 2, NULL);
870 default:
871 return -EINVAL;
872 }
873}
874
875
812/* v4l2_ioctl_ops */ 876/* v4l2_ioctl_ops */
813static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = { 877static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
814 .vidioc_querycap = vidioc_querycap, 878 .vidioc_querycap = vidioc_querycap,
@@ -830,6 +894,9 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
830 .vidioc_streamon = vidioc_streamon, 894 .vidioc_streamon = vidioc_streamon,
831 .vidioc_streamoff = vidioc_streamoff, 895 .vidioc_streamoff = vidioc_streamoff,
832 .vidioc_g_crop = vidioc_g_crop, 896 .vidioc_g_crop = vidioc_g_crop,
897 .vidioc_decoder_cmd = vidioc_decoder_cmd,
898 .vidioc_subscribe_event = vidioc_subscribe_event,
899 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
833}; 900};
834 901
835static int s5p_mfc_queue_setup(struct vb2_queue *vq, 902static int s5p_mfc_queue_setup(struct vb2_queue *vq,
@@ -1147,3 +1214,4 @@ void s5p_mfc_dec_init(struct s5p_mfc_ctx *ctx)
1147 mfc_debug(2, "Default src_fmt is %x, dest_fmt is %x\n", 1214 mfc_debug(2, "Default src_fmt is %x, dest_fmt is %x\n",
1148 (unsigned int)ctx->src_fmt, (unsigned int)ctx->dst_fmt); 1215 (unsigned int)ctx->src_fmt, (unsigned int)ctx->dst_fmt);
1149} 1216}
1217
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 f61dba837899..0af05a2d1cd4 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -34,7 +34,7 @@
34#define OFFSETB(x) (((x) - dev->bank2) >> MFC_OFFSET_SHIFT) 34#define OFFSETB(x) (((x) - dev->bank2) >> MFC_OFFSET_SHIFT)
35 35
36/* Allocate temporary buffers for decoding */ 36/* Allocate temporary buffers for decoding */
37int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx) 37static 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;
@@ -55,13 +55,13 @@ int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx)
55 55
56 56
57/* Release temporary buffers for decoding */ 57/* Release temporary buffers for decoding */
58void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx) 58static void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx)
59{ 59{
60 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->dsc); 60 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->dsc);
61} 61}
62 62
63/* Allocate codec buffers */ 63/* Allocate codec buffers */
64int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx) 64static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
65{ 65{
66 struct s5p_mfc_dev *dev = ctx->dev; 66 struct s5p_mfc_dev *dev = ctx->dev;
67 unsigned int enc_ref_y_size = 0; 67 unsigned int enc_ref_y_size = 0;
@@ -193,14 +193,14 @@ int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
193} 193}
194 194
195/* Release buffers allocated for codec */ 195/* Release buffers allocated for codec */
196void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx) 196static void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
197{ 197{
198 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1); 198 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
199 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_r, &ctx->bank2); 199 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_r, &ctx->bank2);
200} 200}
201 201
202/* Allocate memory for instance data buffer */ 202/* Allocate memory for instance data buffer */
203int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx) 203static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
204{ 204{
205 struct s5p_mfc_dev *dev = ctx->dev; 205 struct s5p_mfc_dev *dev = ctx->dev;
206 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;
@@ -241,20 +241,20 @@ int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
241} 241}
242 242
243/* Release instance buffer */ 243/* Release instance buffer */
244void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx) 244static void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
245{ 245{
246 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx); 246 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
247 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->shm); 247 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->shm);
248} 248}
249 249
250int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev) 250static int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
251{ 251{
252 /* NOP */ 252 /* NOP */
253 253
254 return 0; 254 return 0;
255} 255}
256 256
257void s5p_mfc_release_dev_context_buffer_v5(struct s5p_mfc_dev *dev) 257static void s5p_mfc_release_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
258{ 258{
259 /* NOP */ 259 /* NOP */
260} 260}
@@ -273,7 +273,7 @@ static unsigned int s5p_mfc_read_info_v5(struct s5p_mfc_ctx *ctx,
273 return readl(ctx->shm.virt + ofs); 273 return readl(ctx->shm.virt + ofs);
274} 274}
275 275
276void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx *ctx) 276static void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx *ctx)
277{ 277{
278 unsigned int guard_width, guard_height; 278 unsigned int guard_width, guard_height;
279 279
@@ -315,7 +315,7 @@ void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx *ctx)
315 } 315 }
316} 316}
317 317
318void s5p_mfc_enc_calc_src_size_v5(struct s5p_mfc_ctx *ctx) 318static void s5p_mfc_enc_calc_src_size_v5(struct s5p_mfc_ctx *ctx)
319{ 319{
320 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) { 320 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
321 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN); 321 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN);
@@ -361,8 +361,9 @@ static void s5p_mfc_set_shared_buffer(struct s5p_mfc_ctx *ctx)
361} 361}
362 362
363/* Set registers for decoding stream buffer */ 363/* Set registers for decoding stream buffer */
364int s5p_mfc_set_dec_stream_buffer_v5(struct s5p_mfc_ctx *ctx, int buf_addr, 364static int s5p_mfc_set_dec_stream_buffer_v5(struct s5p_mfc_ctx *ctx,
365 unsigned int start_num_byte, unsigned int buf_size) 365 int buf_addr, unsigned int start_num_byte,
366 unsigned int buf_size)
366{ 367{
367 struct s5p_mfc_dev *dev = ctx->dev; 368 struct s5p_mfc_dev *dev = ctx->dev;
368 369
@@ -374,7 +375,7 @@ int s5p_mfc_set_dec_stream_buffer_v5(struct s5p_mfc_ctx *ctx, int buf_addr,
374} 375}
375 376
376/* Set decoding frame buffer */ 377/* Set decoding frame buffer */
377int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx *ctx) 378static int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx *ctx)
378{ 379{
379 unsigned int frame_size, i; 380 unsigned int frame_size, i;
380 unsigned int frame_size_ch, frame_size_mv; 381 unsigned int frame_size_ch, frame_size_mv;
@@ -506,7 +507,7 @@ int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx *ctx)
506} 507}
507 508
508/* Set registers for encoding stream buffer */ 509/* Set registers for encoding stream buffer */
509int s5p_mfc_set_enc_stream_buffer_v5(struct s5p_mfc_ctx *ctx, 510static int s5p_mfc_set_enc_stream_buffer_v5(struct s5p_mfc_ctx *ctx,
510 unsigned long addr, unsigned int size) 511 unsigned long addr, unsigned int size)
511{ 512{
512 struct s5p_mfc_dev *dev = ctx->dev; 513 struct s5p_mfc_dev *dev = ctx->dev;
@@ -516,7 +517,7 @@ int s5p_mfc_set_enc_stream_buffer_v5(struct s5p_mfc_ctx *ctx,
516 return 0; 517 return 0;
517} 518}
518 519
519void s5p_mfc_set_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx, 520static void s5p_mfc_set_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx,
520 unsigned long y_addr, unsigned long c_addr) 521 unsigned long y_addr, unsigned long c_addr)
521{ 522{
522 struct s5p_mfc_dev *dev = ctx->dev; 523 struct s5p_mfc_dev *dev = ctx->dev;
@@ -525,7 +526,7 @@ void s5p_mfc_set_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx,
525 mfc_write(dev, OFFSETB(c_addr), S5P_FIMV_ENC_SI_CH0_CUR_C_ADR); 526 mfc_write(dev, OFFSETB(c_addr), S5P_FIMV_ENC_SI_CH0_CUR_C_ADR);
526} 527}
527 528
528void s5p_mfc_get_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx, 529static void s5p_mfc_get_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx,
529 unsigned long *y_addr, unsigned long *c_addr) 530 unsigned long *y_addr, unsigned long *c_addr)
530{ 531{
531 struct s5p_mfc_dev *dev = ctx->dev; 532 struct s5p_mfc_dev *dev = ctx->dev;
@@ -537,7 +538,7 @@ void s5p_mfc_get_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx,
537} 538}
538 539
539/* Set encoding ref & codec buffer */ 540/* Set encoding ref & codec buffer */
540int s5p_mfc_set_enc_ref_buffer_v5(struct s5p_mfc_ctx *ctx) 541static int s5p_mfc_set_enc_ref_buffer_v5(struct s5p_mfc_ctx *ctx)
541{ 542{
542 struct s5p_mfc_dev *dev = ctx->dev; 543 struct s5p_mfc_dev *dev = ctx->dev;
543 size_t buf_addr1, buf_addr2; 544 size_t buf_addr1, buf_addr2;
@@ -1041,7 +1042,7 @@ static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
1041} 1042}
1042 1043
1043/* Initialize decoding */ 1044/* Initialize decoding */
1044int s5p_mfc_init_decode_v5(struct s5p_mfc_ctx *ctx) 1045static int s5p_mfc_init_decode_v5(struct s5p_mfc_ctx *ctx)
1045{ 1046{
1046 struct s5p_mfc_dev *dev = ctx->dev; 1047 struct s5p_mfc_dev *dev = ctx->dev;
1047 1048
@@ -1077,7 +1078,7 @@ static void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
1077} 1078}
1078 1079
1079/* Decode a single frame */ 1080/* Decode a single frame */
1080int s5p_mfc_decode_one_frame_v5(struct s5p_mfc_ctx *ctx, 1081static int s5p_mfc_decode_one_frame_v5(struct s5p_mfc_ctx *ctx,
1081 enum s5p_mfc_decode_arg last_frame) 1082 enum s5p_mfc_decode_arg last_frame)
1082{ 1083{
1083 struct s5p_mfc_dev *dev = ctx->dev; 1084 struct s5p_mfc_dev *dev = ctx->dev;
@@ -1106,7 +1107,7 @@ int s5p_mfc_decode_one_frame_v5(struct s5p_mfc_ctx *ctx,
1106 return 0; 1107 return 0;
1107} 1108}
1108 1109
1109int s5p_mfc_init_encode_v5(struct s5p_mfc_ctx *ctx) 1110static int s5p_mfc_init_encode_v5(struct s5p_mfc_ctx *ctx)
1110{ 1111{
1111 struct s5p_mfc_dev *dev = ctx->dev; 1112 struct s5p_mfc_dev *dev = ctx->dev;
1112 1113
@@ -1128,7 +1129,7 @@ int s5p_mfc_init_encode_v5(struct s5p_mfc_ctx *ctx)
1128} 1129}
1129 1130
1130/* Encode a single frame */ 1131/* Encode a single frame */
1131int s5p_mfc_encode_one_frame_v5(struct s5p_mfc_ctx *ctx) 1132static int s5p_mfc_encode_one_frame_v5(struct s5p_mfc_ctx *ctx)
1132{ 1133{
1133 struct s5p_mfc_dev *dev = ctx->dev; 1134 struct s5p_mfc_dev *dev = ctx->dev;
1134 int cmd; 1135 int cmd;
@@ -1187,6 +1188,15 @@ static int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx, int last_frame)
1187 unsigned long flags; 1188 unsigned long flags;
1188 unsigned int index; 1189 unsigned int index;
1189 1190
1191 if (ctx->state == MFCINST_FINISHING) {
1192 last_frame = MFC_DEC_LAST_FRAME;
1193 s5p_mfc_set_dec_stream_buffer_v5(ctx, 0, 0, 0);
1194 dev->curr_ctx = ctx->num;
1195 s5p_mfc_clean_ctx_int_flags(ctx);
1196 s5p_mfc_decode_one_frame_v5(ctx, last_frame);
1197 return 0;
1198 }
1199
1190 spin_lock_irqsave(&dev->irqlock, flags); 1200 spin_lock_irqsave(&dev->irqlock, flags);
1191 /* Frames are being decoded */ 1201 /* Frames are being decoded */
1192 if (list_empty(&ctx->src_queue)) { 1202 if (list_empty(&ctx->src_queue)) {
@@ -1353,7 +1363,7 @@ static int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
1353} 1363}
1354 1364
1355/* Try running an operation on hardware */ 1365/* Try running an operation on hardware */
1356void s5p_mfc_try_run_v5(struct s5p_mfc_dev *dev) 1366static void s5p_mfc_try_run_v5(struct s5p_mfc_dev *dev)
1357{ 1367{
1358 struct s5p_mfc_ctx *ctx; 1368 struct s5p_mfc_ctx *ctx;
1359 int new_ctx; 1369 int new_ctx;
@@ -1469,7 +1479,7 @@ void s5p_mfc_try_run_v5(struct s5p_mfc_dev *dev)
1469} 1479}
1470 1480
1471 1481
1472void s5p_mfc_cleanup_queue_v5(struct list_head *lh, struct vb2_queue *vq) 1482static void s5p_mfc_cleanup_queue_v5(struct list_head *lh, struct vb2_queue *vq)
1473{ 1483{
1474 struct s5p_mfc_buf *b; 1484 struct s5p_mfc_buf *b;
1475 int i; 1485 int i;
@@ -1483,52 +1493,52 @@ void s5p_mfc_cleanup_queue_v5(struct list_head *lh, struct vb2_queue *vq)
1483 } 1493 }
1484} 1494}
1485 1495
1486void s5p_mfc_clear_int_flags_v5(struct s5p_mfc_dev *dev) 1496static void s5p_mfc_clear_int_flags_v5(struct s5p_mfc_dev *dev)
1487{ 1497{
1488 mfc_write(dev, 0, S5P_FIMV_RISC_HOST_INT); 1498 mfc_write(dev, 0, S5P_FIMV_RISC_HOST_INT);
1489 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD); 1499 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD);
1490 mfc_write(dev, 0xffff, S5P_FIMV_SI_RTN_CHID); 1500 mfc_write(dev, 0xffff, S5P_FIMV_SI_RTN_CHID);
1491} 1501}
1492 1502
1493int s5p_mfc_get_dspl_y_adr_v5(struct s5p_mfc_dev *dev) 1503static int s5p_mfc_get_dspl_y_adr_v5(struct s5p_mfc_dev *dev)
1494{ 1504{
1495 return mfc_read(dev, S5P_FIMV_SI_DISPLAY_Y_ADR) << MFC_OFFSET_SHIFT; 1505 return mfc_read(dev, S5P_FIMV_SI_DISPLAY_Y_ADR) << MFC_OFFSET_SHIFT;
1496} 1506}
1497 1507
1498int s5p_mfc_get_dec_y_adr_v5(struct s5p_mfc_dev *dev) 1508static int s5p_mfc_get_dec_y_adr_v5(struct s5p_mfc_dev *dev)
1499{ 1509{
1500 return mfc_read(dev, S5P_FIMV_SI_DECODE_Y_ADR) << MFC_OFFSET_SHIFT; 1510 return mfc_read(dev, S5P_FIMV_SI_DECODE_Y_ADR) << MFC_OFFSET_SHIFT;
1501} 1511}
1502 1512
1503int s5p_mfc_get_dspl_status_v5(struct s5p_mfc_dev *dev) 1513static int s5p_mfc_get_dspl_status_v5(struct s5p_mfc_dev *dev)
1504{ 1514{
1505 return mfc_read(dev, S5P_FIMV_SI_DISPLAY_STATUS); 1515 return mfc_read(dev, S5P_FIMV_SI_DISPLAY_STATUS);
1506} 1516}
1507 1517
1508int s5p_mfc_get_dec_status_v5(struct s5p_mfc_dev *dev) 1518static int s5p_mfc_get_dec_status_v5(struct s5p_mfc_dev *dev)
1509{ 1519{
1510 return mfc_read(dev, S5P_FIMV_SI_DECODE_STATUS); 1520 return mfc_read(dev, S5P_FIMV_SI_DECODE_STATUS);
1511} 1521}
1512 1522
1513int s5p_mfc_get_dec_frame_type_v5(struct s5p_mfc_dev *dev) 1523static int s5p_mfc_get_dec_frame_type_v5(struct s5p_mfc_dev *dev)
1514{ 1524{
1515 return mfc_read(dev, S5P_FIMV_DECODE_FRAME_TYPE) & 1525 return mfc_read(dev, S5P_FIMV_DECODE_FRAME_TYPE) &
1516 S5P_FIMV_DECODE_FRAME_MASK; 1526 S5P_FIMV_DECODE_FRAME_MASK;
1517} 1527}
1518 1528
1519int s5p_mfc_get_disp_frame_type_v5(struct s5p_mfc_ctx *ctx) 1529static int s5p_mfc_get_disp_frame_type_v5(struct s5p_mfc_ctx *ctx)
1520{ 1530{
1521 return (s5p_mfc_read_info_v5(ctx, DISP_PIC_FRAME_TYPE) >> 1531 return (s5p_mfc_read_info_v5(ctx, DISP_PIC_FRAME_TYPE) >>
1522 S5P_FIMV_SHARED_DISP_FRAME_TYPE_SHIFT) & 1532 S5P_FIMV_SHARED_DISP_FRAME_TYPE_SHIFT) &
1523 S5P_FIMV_DECODE_FRAME_MASK; 1533 S5P_FIMV_DECODE_FRAME_MASK;
1524} 1534}
1525 1535
1526int s5p_mfc_get_consumed_stream_v5(struct s5p_mfc_dev *dev) 1536static int s5p_mfc_get_consumed_stream_v5(struct s5p_mfc_dev *dev)
1527{ 1537{
1528 return mfc_read(dev, S5P_FIMV_SI_CONSUMED_BYTES); 1538 return mfc_read(dev, S5P_FIMV_SI_CONSUMED_BYTES);
1529} 1539}
1530 1540
1531int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev *dev) 1541static int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev *dev)
1532{ 1542{
1533 int reason; 1543 int reason;
1534 reason = mfc_read(dev, S5P_FIMV_RISC2HOST_CMD) & 1544 reason = mfc_read(dev, S5P_FIMV_RISC2HOST_CMD) &
@@ -1576,98 +1586,98 @@ int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev *dev)
1576 return reason; 1586 return reason;
1577} 1587}
1578 1588
1579int s5p_mfc_get_int_err_v5(struct s5p_mfc_dev *dev) 1589static int s5p_mfc_get_int_err_v5(struct s5p_mfc_dev *dev)
1580{ 1590{
1581 return mfc_read(dev, S5P_FIMV_RISC2HOST_ARG2); 1591 return mfc_read(dev, S5P_FIMV_RISC2HOST_ARG2);
1582} 1592}
1583 1593
1584int s5p_mfc_err_dec_v5(unsigned int err) 1594static int s5p_mfc_err_dec_v5(unsigned int err)
1585{ 1595{
1586 return (err & S5P_FIMV_ERR_DEC_MASK) >> S5P_FIMV_ERR_DEC_SHIFT; 1596 return (err & S5P_FIMV_ERR_DEC_MASK) >> S5P_FIMV_ERR_DEC_SHIFT;
1587} 1597}
1588 1598
1589int s5p_mfc_err_dspl_v5(unsigned int err) 1599static int s5p_mfc_err_dspl_v5(unsigned int err)
1590{ 1600{
1591 return (err & S5P_FIMV_ERR_DSPL_MASK) >> S5P_FIMV_ERR_DSPL_SHIFT; 1601 return (err & S5P_FIMV_ERR_DSPL_MASK) >> S5P_FIMV_ERR_DSPL_SHIFT;
1592} 1602}
1593 1603
1594int s5p_mfc_get_img_width_v5(struct s5p_mfc_dev *dev) 1604static int s5p_mfc_get_img_width_v5(struct s5p_mfc_dev *dev)
1595{ 1605{
1596 return mfc_read(dev, S5P_FIMV_SI_HRESOL); 1606 return mfc_read(dev, S5P_FIMV_SI_HRESOL);
1597} 1607}
1598 1608
1599int s5p_mfc_get_img_height_v5(struct s5p_mfc_dev *dev) 1609static int s5p_mfc_get_img_height_v5(struct s5p_mfc_dev *dev)
1600{ 1610{
1601 return mfc_read(dev, S5P_FIMV_SI_VRESOL); 1611 return mfc_read(dev, S5P_FIMV_SI_VRESOL);
1602} 1612}
1603 1613
1604int s5p_mfc_get_dpb_count_v5(struct s5p_mfc_dev *dev) 1614static int s5p_mfc_get_dpb_count_v5(struct s5p_mfc_dev *dev)
1605{ 1615{
1606 return mfc_read(dev, S5P_FIMV_SI_BUF_NUMBER); 1616 return mfc_read(dev, S5P_FIMV_SI_BUF_NUMBER);
1607} 1617}
1608 1618
1609int s5p_mfc_get_mv_count_v5(struct s5p_mfc_dev *dev) 1619static int s5p_mfc_get_mv_count_v5(struct s5p_mfc_dev *dev)
1610{ 1620{
1611 /* NOP */ 1621 /* NOP */
1612 return -1; 1622 return -1;
1613} 1623}
1614 1624
1615int s5p_mfc_get_inst_no_v5(struct s5p_mfc_dev *dev) 1625static int s5p_mfc_get_inst_no_v5(struct s5p_mfc_dev *dev)
1616{ 1626{
1617 return mfc_read(dev, S5P_FIMV_RISC2HOST_ARG1); 1627 return mfc_read(dev, S5P_FIMV_RISC2HOST_ARG1);
1618} 1628}
1619 1629
1620int s5p_mfc_get_enc_strm_size_v5(struct s5p_mfc_dev *dev) 1630static int s5p_mfc_get_enc_strm_size_v5(struct s5p_mfc_dev *dev)
1621{ 1631{
1622 return mfc_read(dev, S5P_FIMV_ENC_SI_STRM_SIZE); 1632 return mfc_read(dev, S5P_FIMV_ENC_SI_STRM_SIZE);
1623} 1633}
1624 1634
1625int s5p_mfc_get_enc_slice_type_v5(struct s5p_mfc_dev *dev) 1635static int s5p_mfc_get_enc_slice_type_v5(struct s5p_mfc_dev *dev)
1626{ 1636{
1627 return mfc_read(dev, S5P_FIMV_ENC_SI_SLICE_TYPE); 1637 return mfc_read(dev, S5P_FIMV_ENC_SI_SLICE_TYPE);
1628} 1638}
1629 1639
1630int s5p_mfc_get_enc_dpb_count_v5(struct s5p_mfc_dev *dev) 1640static int s5p_mfc_get_enc_dpb_count_v5(struct s5p_mfc_dev *dev)
1631{ 1641{
1632 return -1; 1642 return -1;
1633} 1643}
1634 1644
1635int s5p_mfc_get_enc_pic_count_v5(struct s5p_mfc_dev *dev) 1645static int s5p_mfc_get_enc_pic_count_v5(struct s5p_mfc_dev *dev)
1636{ 1646{
1637 return mfc_read(dev, S5P_FIMV_ENC_SI_PIC_CNT); 1647 return mfc_read(dev, S5P_FIMV_ENC_SI_PIC_CNT);
1638} 1648}
1639 1649
1640int s5p_mfc_get_sei_avail_status_v5(struct s5p_mfc_ctx *ctx) 1650static int s5p_mfc_get_sei_avail_status_v5(struct s5p_mfc_ctx *ctx)
1641{ 1651{
1642 return s5p_mfc_read_info_v5(ctx, FRAME_PACK_SEI_AVAIL); 1652 return s5p_mfc_read_info_v5(ctx, FRAME_PACK_SEI_AVAIL);
1643} 1653}
1644 1654
1645int s5p_mfc_get_mvc_num_views_v5(struct s5p_mfc_dev *dev) 1655static int s5p_mfc_get_mvc_num_views_v5(struct s5p_mfc_dev *dev)
1646{ 1656{
1647 return -1; 1657 return -1;
1648} 1658}
1649 1659
1650int s5p_mfc_get_mvc_view_id_v5(struct s5p_mfc_dev *dev) 1660static int s5p_mfc_get_mvc_view_id_v5(struct s5p_mfc_dev *dev)
1651{ 1661{
1652 return -1; 1662 return -1;
1653} 1663}
1654 1664
1655unsigned int s5p_mfc_get_pic_type_top_v5(struct s5p_mfc_ctx *ctx) 1665static unsigned int s5p_mfc_get_pic_type_top_v5(struct s5p_mfc_ctx *ctx)
1656{ 1666{
1657 return s5p_mfc_read_info_v5(ctx, PIC_TIME_TOP); 1667 return s5p_mfc_read_info_v5(ctx, PIC_TIME_TOP);
1658} 1668}
1659 1669
1660unsigned int s5p_mfc_get_pic_type_bot_v5(struct s5p_mfc_ctx *ctx) 1670static unsigned int s5p_mfc_get_pic_type_bot_v5(struct s5p_mfc_ctx *ctx)
1661{ 1671{
1662 return s5p_mfc_read_info_v5(ctx, PIC_TIME_BOT); 1672 return s5p_mfc_read_info_v5(ctx, PIC_TIME_BOT);
1663} 1673}
1664 1674
1665unsigned int s5p_mfc_get_crop_info_h_v5(struct s5p_mfc_ctx *ctx) 1675static unsigned int s5p_mfc_get_crop_info_h_v5(struct s5p_mfc_ctx *ctx)
1666{ 1676{
1667 return s5p_mfc_read_info_v5(ctx, CROP_INFO_H); 1677 return s5p_mfc_read_info_v5(ctx, CROP_INFO_H);
1668} 1678}
1669 1679
1670unsigned int s5p_mfc_get_crop_info_v_v5(struct s5p_mfc_ctx *ctx) 1680static unsigned int s5p_mfc_get_crop_info_v_v5(struct s5p_mfc_ctx *ctx)
1671{ 1681{
1672 return s5p_mfc_read_info_v5(ctx, CROP_INFO_V); 1682 return s5p_mfc_read_info_v5(ctx, CROP_INFO_V);
1673} 1683}
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 98a9c093a6b9..7e76fce2e524 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -49,7 +49,7 @@
49#define OFFSETB(x) (((x) - dev->port_b) >> S5P_FIMV_MEM_OFFSET) 49#define OFFSETB(x) (((x) - dev->port_b) >> S5P_FIMV_MEM_OFFSET)
50 50
51/* Allocate temporary buffers for decoding */ 51/* Allocate temporary buffers for decoding */
52int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx) 52static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
53{ 53{
54 /* NOP */ 54 /* NOP */
55 55
@@ -57,19 +57,19 @@ int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
57} 57}
58 58
59/* Release temproary buffers for decoding */ 59/* Release temproary buffers for decoding */
60void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx) 60static void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
61{ 61{
62 /* NOP */ 62 /* NOP */
63} 63}
64 64
65int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev) 65static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
66{ 66{
67 /* NOP */ 67 /* NOP */
68 return -1; 68 return -1;
69} 69}
70 70
71/* Allocate codec buffers */ 71/* Allocate codec buffers */
72int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx) 72static 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;
@@ -203,13 +203,13 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
203} 203}
204 204
205/* Release buffers allocated for codec */ 205/* Release buffers allocated for codec */
206void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx) 206static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
207{ 207{
208 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1); 208 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
209} 209}
210 210
211/* Allocate memory for instance data buffer */ 211/* Allocate memory for instance data buffer */
212int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx) 212static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
213{ 213{
214 struct s5p_mfc_dev *dev = ctx->dev; 214 struct s5p_mfc_dev *dev = ctx->dev;
215 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;
@@ -258,13 +258,13 @@ int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
258} 258}
259 259
260/* Release instance buffer */ 260/* Release instance buffer */
261void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx) 261static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
262{ 262{
263 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx); 263 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
264} 264}
265 265
266/* Allocate context buffers for SYS_INIT */ 266/* Allocate context buffers for SYS_INIT */
267int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev) 267static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
268{ 268{
269 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; 270 int ret;
@@ -287,7 +287,7 @@ int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
287} 287}
288 288
289/* Release context buffers for SYS_INIT */ 289/* Release context buffers for SYS_INIT */
290void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev) 290static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
291{ 291{
292 s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf); 292 s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
293} 293}
@@ -306,7 +306,7 @@ static int calc_plane(int width, int height)
306 (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6); 306 (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
307} 307}
308 308
309void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx) 309static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
310{ 310{
311 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6); 311 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
312 ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6); 312 ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
@@ -326,7 +326,7 @@ void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
326 } 326 }
327} 327}
328 328
329void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx) 329static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
330{ 330{
331 unsigned int mb_width, mb_height; 331 unsigned int mb_width, mb_height;
332 332
@@ -339,8 +339,9 @@ void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
339} 339}
340 340
341/* Set registers for decoding stream buffer */ 341/* Set registers for decoding stream buffer */
342int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx, int buf_addr, 342static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
343 unsigned int start_num_byte, unsigned int strm_size) 343 int buf_addr, unsigned int start_num_byte,
344 unsigned int strm_size)
344{ 345{
345 struct s5p_mfc_dev *dev = ctx->dev; 346 struct s5p_mfc_dev *dev = ctx->dev;
346 struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size; 347 struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
@@ -359,7 +360,7 @@ int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx, int buf_addr,
359} 360}
360 361
361/* Set decoding frame buffer */ 362/* Set decoding frame buffer */
362int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx) 363static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
363{ 364{
364 unsigned int frame_size, i; 365 unsigned int frame_size, i;
365 unsigned int frame_size_ch, frame_size_mv; 366 unsigned int frame_size_ch, frame_size_mv;
@@ -440,7 +441,7 @@ int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
440} 441}
441 442
442/* Set registers for encoding stream buffer */ 443/* Set registers for encoding stream buffer */
443int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx, 444static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
444 unsigned long addr, unsigned int size) 445 unsigned long addr, unsigned int size)
445{ 446{
446 struct s5p_mfc_dev *dev = ctx->dev; 447 struct s5p_mfc_dev *dev = ctx->dev;
@@ -454,7 +455,7 @@ int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
454 return 0; 455 return 0;
455} 456}
456 457
457void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx, 458static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
458 unsigned long y_addr, unsigned long c_addr) 459 unsigned long y_addr, unsigned long c_addr)
459{ 460{
460 struct s5p_mfc_dev *dev = ctx->dev; 461 struct s5p_mfc_dev *dev = ctx->dev;
@@ -466,7 +467,7 @@ void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
466 mfc_debug(2, "enc src c buf addr: 0x%08lx", c_addr); 467 mfc_debug(2, "enc src c buf addr: 0x%08lx", c_addr);
467} 468}
468 469
469void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx, 470static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
470 unsigned long *y_addr, unsigned long *c_addr) 471 unsigned long *y_addr, unsigned long *c_addr)
471{ 472{
472 struct s5p_mfc_dev *dev = ctx->dev; 473 struct s5p_mfc_dev *dev = ctx->dev;
@@ -483,7 +484,7 @@ void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
483} 484}
484 485
485/* Set encoding ref & codec buffer */ 486/* Set encoding ref & codec buffer */
486int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx) 487static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
487{ 488{
488 struct s5p_mfc_dev *dev = ctx->dev; 489 struct s5p_mfc_dev *dev = ctx->dev;
489 size_t buf_addr1; 490 size_t buf_addr1;
@@ -1147,7 +1148,7 @@ static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
1147} 1148}
1148 1149
1149/* Initialize decoding */ 1150/* Initialize decoding */
1150int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx) 1151static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
1151{ 1152{
1152 struct s5p_mfc_dev *dev = ctx->dev; 1153 struct s5p_mfc_dev *dev = ctx->dev;
1153 unsigned int reg = 0; 1154 unsigned int reg = 0;
@@ -1215,7 +1216,7 @@ static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
1215} 1216}
1216 1217
1217/* Decode a single frame */ 1218/* Decode a single frame */
1218int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx, 1219static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
1219 enum s5p_mfc_decode_arg last_frame) 1220 enum s5p_mfc_decode_arg last_frame)
1220{ 1221{
1221 struct s5p_mfc_dev *dev = ctx->dev; 1222 struct s5p_mfc_dev *dev = ctx->dev;
@@ -1244,7 +1245,7 @@ int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
1244 return 0; 1245 return 0;
1245} 1246}
1246 1247
1247int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx) 1248static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
1248{ 1249{
1249 struct s5p_mfc_dev *dev = ctx->dev; 1250 struct s5p_mfc_dev *dev = ctx->dev;
1250 1251
@@ -1267,7 +1268,7 @@ int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
1267 return 0; 1268 return 0;
1268} 1269}
1269 1270
1270int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx) 1271static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
1271{ 1272{
1272 struct s5p_mfc_dev *dev = ctx->dev; 1273 struct s5p_mfc_dev *dev = ctx->dev;
1273 struct s5p_mfc_enc_params *p = &ctx->enc_params; 1274 struct s5p_mfc_enc_params *p = &ctx->enc_params;
@@ -1283,7 +1284,7 @@ int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
1283} 1284}
1284 1285
1285/* Encode a single frame */ 1286/* Encode a single frame */
1286int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx) 1287static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
1287{ 1288{
1288 struct s5p_mfc_dev *dev = ctx->dev; 1289 struct s5p_mfc_dev *dev = ctx->dev;
1289 1290
@@ -1362,8 +1363,16 @@ static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
1362 unsigned long flags; 1363 unsigned long flags;
1363 int last_frame = 0; 1364 int last_frame = 0;
1364 1365
1365 spin_lock_irqsave(&dev->irqlock, flags); 1366 if (ctx->state == MFCINST_FINISHING) {
1367 last_frame = MFC_DEC_LAST_FRAME;
1368 s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
1369 dev->curr_ctx = ctx->num;
1370 s5p_mfc_clean_ctx_int_flags(ctx);
1371 s5p_mfc_decode_one_frame_v6(ctx, last_frame);
1372 return 0;
1373 }
1366 1374
1375 spin_lock_irqsave(&dev->irqlock, flags);
1367 /* Frames are being decoded */ 1376 /* Frames are being decoded */
1368 if (list_empty(&ctx->src_queue)) { 1377 if (list_empty(&ctx->src_queue)) {
1369 mfc_debug(2, "No src buffers.\n"); 1378 mfc_debug(2, "No src buffers.\n");
@@ -1540,7 +1549,7 @@ static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
1540} 1549}
1541 1550
1542/* Try running an operation on hardware */ 1551/* Try running an operation on hardware */
1543void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev) 1552static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
1544{ 1553{
1545 struct s5p_mfc_ctx *ctx; 1554 struct s5p_mfc_ctx *ctx;
1546 int new_ctx; 1555 int new_ctx;
@@ -1663,7 +1672,7 @@ void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
1663} 1672}
1664 1673
1665 1674
1666void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq) 1675static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
1667{ 1676{
1668 struct s5p_mfc_buf *b; 1677 struct s5p_mfc_buf *b;
1669 int i; 1678 int i;
@@ -1677,13 +1686,13 @@ void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
1677 } 1686 }
1678} 1687}
1679 1688
1680void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev) 1689static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
1681{ 1690{
1682 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD_V6); 1691 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD_V6);
1683 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_INT_V6); 1692 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_INT_V6);
1684} 1693}
1685 1694
1686void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data, 1695static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
1687 unsigned int ofs) 1696 unsigned int ofs)
1688{ 1697{
1689 struct s5p_mfc_dev *dev = ctx->dev; 1698 struct s5p_mfc_dev *dev = ctx->dev;
@@ -1693,7 +1702,8 @@ void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
1693 s5p_mfc_clock_off(); 1702 s5p_mfc_clock_off();
1694} 1703}
1695 1704
1696unsigned int s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs) 1705static unsigned int
1706s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
1697{ 1707{
1698 struct s5p_mfc_dev *dev = ctx->dev; 1708 struct s5p_mfc_dev *dev = ctx->dev;
1699 int ret; 1709 int ret;
@@ -1705,140 +1715,140 @@ unsigned int s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
1705 return ret; 1715 return ret;
1706} 1716}
1707 1717
1708int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev) 1718static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
1709{ 1719{
1710 return mfc_read(dev, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6); 1720 return mfc_read(dev, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
1711} 1721}
1712 1722
1713int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev) 1723static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
1714{ 1724{
1715 return mfc_read(dev, S5P_FIMV_D_DECODED_LUMA_ADDR_V6); 1725 return mfc_read(dev, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
1716} 1726}
1717 1727
1718int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev) 1728static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
1719{ 1729{
1720 return mfc_read(dev, S5P_FIMV_D_DISPLAY_STATUS_V6); 1730 return mfc_read(dev, S5P_FIMV_D_DISPLAY_STATUS_V6);
1721} 1731}
1722 1732
1723int s5p_mfc_get_decoded_status_v6(struct s5p_mfc_dev *dev) 1733static int s5p_mfc_get_decoded_status_v6(struct s5p_mfc_dev *dev)
1724{ 1734{
1725 return mfc_read(dev, S5P_FIMV_D_DECODED_STATUS_V6); 1735 return mfc_read(dev, S5P_FIMV_D_DECODED_STATUS_V6);
1726} 1736}
1727 1737
1728int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev) 1738static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
1729{ 1739{
1730 return mfc_read(dev, S5P_FIMV_D_DECODED_FRAME_TYPE_V6) & 1740 return mfc_read(dev, S5P_FIMV_D_DECODED_FRAME_TYPE_V6) &
1731 S5P_FIMV_DECODE_FRAME_MASK_V6; 1741 S5P_FIMV_DECODE_FRAME_MASK_V6;
1732} 1742}
1733 1743
1734int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx) 1744static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
1735{ 1745{
1736 return mfc_read(ctx->dev, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6) & 1746 return mfc_read(ctx->dev, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6) &
1737 S5P_FIMV_DECODE_FRAME_MASK_V6; 1747 S5P_FIMV_DECODE_FRAME_MASK_V6;
1738} 1748}
1739 1749
1740int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev) 1750static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
1741{ 1751{
1742 return mfc_read(dev, S5P_FIMV_D_DECODED_NAL_SIZE_V6); 1752 return mfc_read(dev, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
1743} 1753}
1744 1754
1745int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev) 1755static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
1746{ 1756{
1747 return mfc_read(dev, S5P_FIMV_RISC2HOST_CMD_V6) & 1757 return mfc_read(dev, S5P_FIMV_RISC2HOST_CMD_V6) &
1748 S5P_FIMV_RISC2HOST_CMD_MASK; 1758 S5P_FIMV_RISC2HOST_CMD_MASK;
1749} 1759}
1750 1760
1751int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev) 1761static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
1752{ 1762{
1753 return mfc_read(dev, S5P_FIMV_ERROR_CODE_V6); 1763 return mfc_read(dev, S5P_FIMV_ERROR_CODE_V6);
1754} 1764}
1755 1765
1756int s5p_mfc_err_dec_v6(unsigned int err) 1766static int s5p_mfc_err_dec_v6(unsigned int err)
1757{ 1767{
1758 return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6; 1768 return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
1759} 1769}
1760 1770
1761int s5p_mfc_err_dspl_v6(unsigned int err) 1771static int s5p_mfc_err_dspl_v6(unsigned int err)
1762{ 1772{
1763 return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6; 1773 return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
1764} 1774}
1765 1775
1766int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev) 1776static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
1767{ 1777{
1768 return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6); 1778 return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
1769} 1779}
1770 1780
1771int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev) 1781static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
1772{ 1782{
1773 return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6); 1783 return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
1774} 1784}
1775 1785
1776int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev) 1786static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
1777{ 1787{
1778 return mfc_read(dev, S5P_FIMV_D_MIN_NUM_DPB_V6); 1788 return mfc_read(dev, S5P_FIMV_D_MIN_NUM_DPB_V6);
1779} 1789}
1780 1790
1781int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev) 1791static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
1782{ 1792{
1783 return mfc_read(dev, S5P_FIMV_D_MIN_NUM_MV_V6); 1793 return mfc_read(dev, S5P_FIMV_D_MIN_NUM_MV_V6);
1784} 1794}
1785 1795
1786int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev) 1796static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
1787{ 1797{
1788 return mfc_read(dev, S5P_FIMV_RET_INSTANCE_ID_V6); 1798 return mfc_read(dev, S5P_FIMV_RET_INSTANCE_ID_V6);
1789} 1799}
1790 1800
1791int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev) 1801static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
1792{ 1802{
1793 return mfc_read(dev, S5P_FIMV_E_NUM_DPB_V6); 1803 return mfc_read(dev, S5P_FIMV_E_NUM_DPB_V6);
1794} 1804}
1795 1805
1796int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev) 1806static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
1797{ 1807{
1798 return mfc_read(dev, S5P_FIMV_E_STREAM_SIZE_V6); 1808 return mfc_read(dev, S5P_FIMV_E_STREAM_SIZE_V6);
1799} 1809}
1800 1810
1801int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev) 1811static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
1802{ 1812{
1803 return mfc_read(dev, S5P_FIMV_E_SLICE_TYPE_V6); 1813 return mfc_read(dev, S5P_FIMV_E_SLICE_TYPE_V6);
1804} 1814}
1805 1815
1806int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev) 1816static int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
1807{ 1817{
1808 return mfc_read(dev, S5P_FIMV_E_PICTURE_COUNT_V6); 1818 return mfc_read(dev, S5P_FIMV_E_PICTURE_COUNT_V6);
1809} 1819}
1810 1820
1811int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx) 1821static int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
1812{ 1822{
1813 return mfc_read(ctx->dev, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6); 1823 return mfc_read(ctx->dev, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
1814} 1824}
1815 1825
1816int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev) 1826static int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
1817{ 1827{
1818 return mfc_read(dev, S5P_FIMV_D_MVC_NUM_VIEWS_V6); 1828 return mfc_read(dev, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
1819} 1829}
1820 1830
1821int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev) 1831static int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
1822{ 1832{
1823 return mfc_read(dev, S5P_FIMV_D_MVC_VIEW_ID_V6); 1833 return mfc_read(dev, S5P_FIMV_D_MVC_VIEW_ID_V6);
1824} 1834}
1825 1835
1826unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx) 1836static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
1827{ 1837{
1828 return s5p_mfc_read_info_v6(ctx, PIC_TIME_TOP_V6); 1838 return s5p_mfc_read_info_v6(ctx, PIC_TIME_TOP_V6);
1829} 1839}
1830 1840
1831unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx) 1841static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
1832{ 1842{
1833 return s5p_mfc_read_info_v6(ctx, PIC_TIME_BOT_V6); 1843 return s5p_mfc_read_info_v6(ctx, PIC_TIME_BOT_V6);
1834} 1844}
1835 1845
1836unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx) 1846static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
1837{ 1847{
1838 return s5p_mfc_read_info_v6(ctx, CROP_INFO_H_V6); 1848 return s5p_mfc_read_info_v6(ctx, CROP_INFO_H_V6);
1839} 1849}
1840 1850
1841unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx) 1851static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
1842{ 1852{
1843 return s5p_mfc_read_info_v6(ctx, CROP_INFO_V_V6); 1853 return s5p_mfc_read_info_v6(ctx, CROP_INFO_V_V6);
1844} 1854}
diff --git a/drivers/media/platform/s5p-tv/hdmi_drv.c b/drivers/media/platform/s5p-tv/hdmi_drv.c
index 8de1b3dce459..4e86626dad4b 100644
--- a/drivers/media/platform/s5p-tv/hdmi_drv.c
+++ b/drivers/media/platform/s5p-tv/hdmi_drv.c
@@ -31,6 +31,7 @@
31#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <linux/regulator/consumer.h> 33#include <linux/regulator/consumer.h>
34#include <linux/v4l2-dv-timings.h>
34 35
35#include <media/s5p_hdmi.h> 36#include <media/s5p_hdmi.h>
36#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
@@ -43,9 +44,6 @@ MODULE_AUTHOR("Tomasz Stanislawski, <t.stanislaws@samsung.com>");
43MODULE_DESCRIPTION("Samsung HDMI"); 44MODULE_DESCRIPTION("Samsung HDMI");
44MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
45 46
46/* default preset configured on probe */
47#define HDMI_DEFAULT_PRESET V4L2_DV_480P59_94
48
49struct hdmi_pulse { 47struct hdmi_pulse {
50 u32 beg; 48 u32 beg;
51 u32 end; 49 u32 end;
@@ -91,8 +89,8 @@ struct hdmi_device {
91 const struct hdmi_timings *cur_conf; 89 const struct hdmi_timings *cur_conf;
92 /** flag indicating that timings are dirty */ 90 /** flag indicating that timings are dirty */
93 int cur_conf_dirty; 91 int cur_conf_dirty;
94 /** current preset */ 92 /** current timings */
95 u32 cur_preset; 93 struct v4l2_dv_timings cur_timings;
96 /** other resources */ 94 /** other resources */
97 struct hdmi_resources res; 95 struct hdmi_resources res;
98}; 96};
@@ -252,7 +250,6 @@ static int hdmi_conf_apply(struct hdmi_device *hdmi_dev)
252{ 250{
253 struct device *dev = hdmi_dev->dev; 251 struct device *dev = hdmi_dev->dev;
254 const struct hdmi_timings *conf = hdmi_dev->cur_conf; 252 const struct hdmi_timings *conf = hdmi_dev->cur_conf;
255 struct v4l2_dv_preset preset;
256 int ret; 253 int ret;
257 254
258 dev_dbg(dev, "%s\n", __func__); 255 dev_dbg(dev, "%s\n", __func__);
@@ -267,11 +264,11 @@ static int hdmi_conf_apply(struct hdmi_device *hdmi_dev)
267 hdmi_write_mask(hdmi_dev, HDMI_PHY_RSTOUT, 0, HDMI_PHY_SW_RSTOUT); 264 hdmi_write_mask(hdmi_dev, HDMI_PHY_RSTOUT, 0, HDMI_PHY_SW_RSTOUT);
268 mdelay(10); 265 mdelay(10);
269 266
270 /* configure presets */ 267 /* configure timings */
271 preset.preset = hdmi_dev->cur_preset; 268 ret = v4l2_subdev_call(hdmi_dev->phy_sd, video, s_dv_timings,
272 ret = v4l2_subdev_call(hdmi_dev->phy_sd, video, s_dv_preset, &preset); 269 &hdmi_dev->cur_timings);
273 if (ret) { 270 if (ret) {
274 dev_err(dev, "failed to set preset (%u)\n", preset.preset); 271 dev_err(dev, "failed to set timings\n");
275 return ret; 272 return ret;
276 } 273 }
277 274
@@ -475,33 +472,26 @@ static const struct hdmi_timings hdmi_timings_1080p50 = {
475 .vsyn[0] = { .beg = 0 + 4, .end = 5 + 4}, 472 .vsyn[0] = { .beg = 0 + 4, .end = 5 + 4},
476}; 473};
477 474
475/* default hdmi_timings index of the timings configured on probe */
476#define HDMI_DEFAULT_TIMINGS_IDX (0)
477
478static const struct { 478static const struct {
479 u32 preset; 479 bool reduced_fps;
480 const struct hdmi_timings *timings; 480 const struct v4l2_dv_timings dv_timings;
481 const struct hdmi_timings *hdmi_timings;
481} hdmi_timings[] = { 482} hdmi_timings[] = {
482 { V4L2_DV_480P59_94, &hdmi_timings_480p }, 483 { false, V4L2_DV_BT_CEA_720X480P59_94, &hdmi_timings_480p },
483 { V4L2_DV_576P50, &hdmi_timings_576p50 }, 484 { false, V4L2_DV_BT_CEA_720X576P50, &hdmi_timings_576p50 },
484 { V4L2_DV_720P50, &hdmi_timings_720p50 }, 485 { false, V4L2_DV_BT_CEA_1280X720P50, &hdmi_timings_720p50 },
485 { V4L2_DV_720P59_94, &hdmi_timings_720p60 }, 486 { true, V4L2_DV_BT_CEA_1280X720P60, &hdmi_timings_720p60 },
486 { V4L2_DV_720P60, &hdmi_timings_720p60 }, 487 { false, V4L2_DV_BT_CEA_1920X1080P24, &hdmi_timings_1080p24 },
487 { V4L2_DV_1080P24, &hdmi_timings_1080p24 }, 488 { false, V4L2_DV_BT_CEA_1920X1080P30, &hdmi_timings_1080p60 },
488 { V4L2_DV_1080P30, &hdmi_timings_1080p60 }, 489 { false, V4L2_DV_BT_CEA_1920X1080P50, &hdmi_timings_1080p50 },
489 { V4L2_DV_1080P50, &hdmi_timings_1080p50 }, 490 { false, V4L2_DV_BT_CEA_1920X1080I50, &hdmi_timings_1080i50 },
490 { V4L2_DV_1080I50, &hdmi_timings_1080i50 }, 491 { false, V4L2_DV_BT_CEA_1920X1080I60, &hdmi_timings_1080i60 },
491 { V4L2_DV_1080I60, &hdmi_timings_1080i60 }, 492 { false, V4L2_DV_BT_CEA_1920X1080P60, &hdmi_timings_1080p60 },
492 { V4L2_DV_1080P60, &hdmi_timings_1080p60 },
493}; 493};
494 494
495static const struct hdmi_timings *hdmi_preset2timings(u32 preset)
496{
497 int i;
498
499 for (i = 0; i < ARRAY_SIZE(hdmi_timings); ++i)
500 if (hdmi_timings[i].preset == preset)
501 return hdmi_timings[i].timings;
502 return NULL;
503}
504
505static int hdmi_streamon(struct hdmi_device *hdev) 495static int hdmi_streamon(struct hdmi_device *hdev)
506{ 496{
507 struct device *dev = hdev->dev; 497 struct device *dev = hdev->dev;
@@ -621,29 +611,33 @@ static int hdmi_s_power(struct v4l2_subdev *sd, int on)
621 return IS_ERR_VALUE(ret) ? ret : 0; 611 return IS_ERR_VALUE(ret) ? ret : 0;
622} 612}
623 613
624static int hdmi_s_dv_preset(struct v4l2_subdev *sd, 614static int hdmi_s_dv_timings(struct v4l2_subdev *sd,
625 struct v4l2_dv_preset *preset) 615 struct v4l2_dv_timings *timings)
626{ 616{
627 struct hdmi_device *hdev = sd_to_hdmi_dev(sd); 617 struct hdmi_device *hdev = sd_to_hdmi_dev(sd);
628 struct device *dev = hdev->dev; 618 struct device *dev = hdev->dev;
629 const struct hdmi_timings *conf; 619 int i;
630 620
631 conf = hdmi_preset2timings(preset->preset); 621 for (i = 0; i < ARRAY_SIZE(hdmi_timings); i++)
632 if (conf == NULL) { 622 if (v4l_match_dv_timings(&hdmi_timings[i].dv_timings,
633 dev_err(dev, "preset (%u) not supported\n", preset->preset); 623 timings, 0))
624 break;
625 if (i == ARRAY_SIZE(hdmi_timings)) {
626 dev_err(dev, "timings not supported\n");
634 return -EINVAL; 627 return -EINVAL;
635 } 628 }
636 hdev->cur_conf = conf; 629 hdev->cur_conf = hdmi_timings[i].hdmi_timings;
637 hdev->cur_conf_dirty = 1; 630 hdev->cur_conf_dirty = 1;
638 hdev->cur_preset = preset->preset; 631 hdev->cur_timings = *timings;
632 if (!hdmi_timings[i].reduced_fps)
633 hdev->cur_timings.bt.flags &= ~V4L2_DV_FL_CAN_REDUCE_FPS;
639 return 0; 634 return 0;
640} 635}
641 636
642static int hdmi_g_dv_preset(struct v4l2_subdev *sd, 637static int hdmi_g_dv_timings(struct v4l2_subdev *sd,
643 struct v4l2_dv_preset *preset) 638 struct v4l2_dv_timings *timings)
644{ 639{
645 memset(preset, 0, sizeof(*preset)); 640 *timings = sd_to_hdmi_dev(sd)->cur_timings;
646 preset->preset = sd_to_hdmi_dev(sd)->cur_preset;
647 return 0; 641 return 0;
648} 642}
649 643
@@ -670,13 +664,33 @@ static int hdmi_g_mbus_fmt(struct v4l2_subdev *sd,
670 return 0; 664 return 0;
671} 665}
672 666
673static int hdmi_enum_dv_presets(struct v4l2_subdev *sd, 667static int hdmi_enum_dv_timings(struct v4l2_subdev *sd,
674 struct v4l2_dv_enum_preset *preset) 668 struct v4l2_enum_dv_timings *timings)
675{ 669{
676 if (preset->index >= ARRAY_SIZE(hdmi_timings)) 670 if (timings->index >= ARRAY_SIZE(hdmi_timings))
677 return -EINVAL; 671 return -EINVAL;
678 return v4l_fill_dv_preset_info(hdmi_timings[preset->index].preset, 672 timings->timings = hdmi_timings[timings->index].dv_timings;
679 preset); 673 if (!hdmi_timings[timings->index].reduced_fps)
674 timings->timings.bt.flags &= ~V4L2_DV_FL_CAN_REDUCE_FPS;
675 return 0;
676}
677
678static int hdmi_dv_timings_cap(struct v4l2_subdev *sd,
679 struct v4l2_dv_timings_cap *cap)
680{
681 struct hdmi_device *hdev = sd_to_hdmi_dev(sd);
682
683 /* Let the phy fill in the pixelclock range */
684 v4l2_subdev_call(hdev->phy_sd, video, dv_timings_cap, cap);
685 cap->type = V4L2_DV_BT_656_1120;
686 cap->bt.min_width = 720;
687 cap->bt.max_width = 1920;
688 cap->bt.min_height = 480;
689 cap->bt.max_height = 1080;
690 cap->bt.standards = V4L2_DV_BT_STD_CEA861;
691 cap->bt.capabilities = V4L2_DV_BT_CAP_INTERLACED |
692 V4L2_DV_BT_CAP_PROGRESSIVE;
693 return 0;
680} 694}
681 695
682static const struct v4l2_subdev_core_ops hdmi_sd_core_ops = { 696static const struct v4l2_subdev_core_ops hdmi_sd_core_ops = {
@@ -684,9 +698,10 @@ static const struct v4l2_subdev_core_ops hdmi_sd_core_ops = {
684}; 698};
685 699
686static const struct v4l2_subdev_video_ops hdmi_sd_video_ops = { 700static const struct v4l2_subdev_video_ops hdmi_sd_video_ops = {
687 .s_dv_preset = hdmi_s_dv_preset, 701 .s_dv_timings = hdmi_s_dv_timings,
688 .g_dv_preset = hdmi_g_dv_preset, 702 .g_dv_timings = hdmi_g_dv_timings,
689 .enum_dv_presets = hdmi_enum_dv_presets, 703 .enum_dv_timings = hdmi_enum_dv_timings,
704 .dv_timings_cap = hdmi_dv_timings_cap,
690 .g_mbus_fmt = hdmi_g_mbus_fmt, 705 .g_mbus_fmt = hdmi_g_mbus_fmt,
691 .s_stream = hdmi_s_stream, 706 .s_stream = hdmi_s_stream,
692}; 707};
@@ -956,9 +971,11 @@ static int hdmi_probe(struct platform_device *pdev)
956 sd->owner = THIS_MODULE; 971 sd->owner = THIS_MODULE;
957 972
958 strlcpy(sd->name, "s5p-hdmi", sizeof(sd->name)); 973 strlcpy(sd->name, "s5p-hdmi", sizeof(sd->name));
959 hdmi_dev->cur_preset = HDMI_DEFAULT_PRESET; 974 hdmi_dev->cur_timings =
960 /* FIXME: missing fail preset is not supported */ 975 hdmi_timings[HDMI_DEFAULT_TIMINGS_IDX].dv_timings;
961 hdmi_dev->cur_conf = hdmi_preset2timings(hdmi_dev->cur_preset); 976 /* FIXME: missing fail timings is not supported */
977 hdmi_dev->cur_conf =
978 hdmi_timings[HDMI_DEFAULT_TIMINGS_IDX].hdmi_timings;
962 hdmi_dev->cur_conf_dirty = 1; 979 hdmi_dev->cur_conf_dirty = 1;
963 980
964 /* storing subdev for call that have only access to struct device */ 981 /* storing subdev for call that have only access to struct device */
diff --git a/drivers/media/platform/s5p-tv/hdmiphy_drv.c b/drivers/media/platform/s5p-tv/hdmiphy_drv.c
index 80717cec76ae..e19a0af1ea4f 100644
--- a/drivers/media/platform/s5p-tv/hdmiphy_drv.c
+++ b/drivers/media/platform/s5p-tv/hdmiphy_drv.c
@@ -176,35 +176,9 @@ static inline struct hdmiphy_ctx *sd_to_ctx(struct v4l2_subdev *sd)
176 return container_of(sd, struct hdmiphy_ctx, sd); 176 return container_of(sd, struct hdmiphy_ctx, sd);
177} 177}
178 178
179static unsigned long hdmiphy_preset_to_pixclk(u32 preset) 179static const u8 *hdmiphy_find_conf(unsigned long pixclk,
180 const struct hdmiphy_conf *conf)
180{ 181{
181 static const unsigned long pixclk[] = {
182 [V4L2_DV_480P59_94] = 27000000,
183 [V4L2_DV_576P50] = 27000000,
184 [V4L2_DV_720P59_94] = 74176000,
185 [V4L2_DV_720P50] = 74250000,
186 [V4L2_DV_720P60] = 74250000,
187 [V4L2_DV_1080P24] = 74250000,
188 [V4L2_DV_1080P30] = 74250000,
189 [V4L2_DV_1080I50] = 74250000,
190 [V4L2_DV_1080I60] = 74250000,
191 [V4L2_DV_1080P50] = 148500000,
192 [V4L2_DV_1080P60] = 148500000,
193 };
194 if (preset < ARRAY_SIZE(pixclk))
195 return pixclk[preset];
196 else
197 return 0;
198}
199
200static const u8 *hdmiphy_find_conf(u32 preset, const struct hdmiphy_conf *conf)
201{
202 unsigned long pixclk;
203
204 pixclk = hdmiphy_preset_to_pixclk(preset);
205 if (!pixclk)
206 return NULL;
207
208 for (; conf->pixclk; ++conf) 182 for (; conf->pixclk; ++conf)
209 if (conf->pixclk == pixclk) 183 if (conf->pixclk == pixclk)
210 return conf->data; 184 return conf->data;
@@ -217,8 +191,8 @@ static int hdmiphy_s_power(struct v4l2_subdev *sd, int on)
217 return 0; 191 return 0;
218} 192}
219 193
220static int hdmiphy_s_dv_preset(struct v4l2_subdev *sd, 194static int hdmiphy_s_dv_timings(struct v4l2_subdev *sd,
221 struct v4l2_dv_preset *preset) 195 struct v4l2_dv_timings *timings)
222{ 196{
223 const u8 *data; 197 const u8 *data;
224 u8 buffer[32]; 198 u8 buffer[32];
@@ -226,9 +200,12 @@ static int hdmiphy_s_dv_preset(struct v4l2_subdev *sd,
226 struct hdmiphy_ctx *ctx = sd_to_ctx(sd); 200 struct hdmiphy_ctx *ctx = sd_to_ctx(sd);
227 struct i2c_client *client = v4l2_get_subdevdata(sd); 201 struct i2c_client *client = v4l2_get_subdevdata(sd);
228 struct device *dev = &client->dev; 202 struct device *dev = &client->dev;
203 unsigned long pixclk = timings->bt.pixelclock;
229 204
230 dev_info(dev, "s_dv_preset(preset = %d)\n", preset->preset); 205 dev_info(dev, "s_dv_timings\n");
231 data = hdmiphy_find_conf(preset->preset, ctx->conf_tab); 206 if ((timings->bt.flags & V4L2_DV_FL_REDUCED_FPS) && pixclk == 74250000)
207 pixclk = 74176000;
208 data = hdmiphy_find_conf(pixclk, ctx->conf_tab);
232 if (!data) { 209 if (!data) {
233 dev_err(dev, "format not supported\n"); 210 dev_err(dev, "format not supported\n");
234 return -EINVAL; 211 return -EINVAL;
@@ -245,6 +222,17 @@ static int hdmiphy_s_dv_preset(struct v4l2_subdev *sd,
245 return 0; 222 return 0;
246} 223}
247 224
225static int hdmiphy_dv_timings_cap(struct v4l2_subdev *sd,
226 struct v4l2_dv_timings_cap *cap)
227{
228 cap->type = V4L2_DV_BT_656_1120;
229 /* The phy only determines the pixelclock, leave the other values
230 * at 0 to signify that we have no information for them. */
231 cap->bt.min_pixelclock = 27000000;
232 cap->bt.max_pixelclock = 148500000;
233 return 0;
234}
235
248static int hdmiphy_s_stream(struct v4l2_subdev *sd, int enable) 236static int hdmiphy_s_stream(struct v4l2_subdev *sd, int enable)
249{ 237{
250 struct i2c_client *client = v4l2_get_subdevdata(sd); 238 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -270,7 +258,8 @@ static const struct v4l2_subdev_core_ops hdmiphy_core_ops = {
270}; 258};
271 259
272static const struct v4l2_subdev_video_ops hdmiphy_video_ops = { 260static const struct v4l2_subdev_video_ops hdmiphy_video_ops = {
273 .s_dv_preset = hdmiphy_s_dv_preset, 261 .s_dv_timings = hdmiphy_s_dv_timings,
262 .dv_timings_cap = hdmiphy_dv_timings_cap,
274 .s_stream = hdmiphy_s_stream, 263 .s_stream = hdmiphy_s_stream,
275}; 264};
276 265
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index 82142a2d6d93..ef0efdf422fe 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -501,8 +501,8 @@ fail:
501 return -ERANGE; 501 return -ERANGE;
502} 502}
503 503
504static int mxr_enum_dv_presets(struct file *file, void *fh, 504static int mxr_enum_dv_timings(struct file *file, void *fh,
505 struct v4l2_dv_enum_preset *preset) 505 struct v4l2_enum_dv_timings *timings)
506{ 506{
507 struct mxr_layer *layer = video_drvdata(file); 507 struct mxr_layer *layer = video_drvdata(file);
508 struct mxr_device *mdev = layer->mdev; 508 struct mxr_device *mdev = layer->mdev;
@@ -510,14 +510,14 @@ static int mxr_enum_dv_presets(struct file *file, void *fh,
510 510
511 /* lock protects from changing sd_out */ 511 /* lock protects from changing sd_out */
512 mutex_lock(&mdev->mutex); 512 mutex_lock(&mdev->mutex);
513 ret = v4l2_subdev_call(to_outsd(mdev), video, enum_dv_presets, preset); 513 ret = v4l2_subdev_call(to_outsd(mdev), video, enum_dv_timings, timings);
514 mutex_unlock(&mdev->mutex); 514 mutex_unlock(&mdev->mutex);
515 515
516 return ret ? -EINVAL : 0; 516 return ret ? -EINVAL : 0;
517} 517}
518 518
519static int mxr_s_dv_preset(struct file *file, void *fh, 519static int mxr_s_dv_timings(struct file *file, void *fh,
520 struct v4l2_dv_preset *preset) 520 struct v4l2_dv_timings *timings)
521{ 521{
522 struct mxr_layer *layer = video_drvdata(file); 522 struct mxr_layer *layer = video_drvdata(file);
523 struct mxr_device *mdev = layer->mdev; 523 struct mxr_device *mdev = layer->mdev;
@@ -526,7 +526,7 @@ static int mxr_s_dv_preset(struct file *file, void *fh,
526 /* lock protects from changing sd_out */ 526 /* lock protects from changing sd_out */
527 mutex_lock(&mdev->mutex); 527 mutex_lock(&mdev->mutex);
528 528
529 /* preset change cannot be done while there is an entity 529 /* timings change cannot be done while there is an entity
530 * dependant on output configuration 530 * dependant on output configuration
531 */ 531 */
532 if (mdev->n_output > 0) { 532 if (mdev->n_output > 0) {
@@ -534,7 +534,7 @@ static int mxr_s_dv_preset(struct file *file, void *fh,
534 return -EBUSY; 534 return -EBUSY;
535 } 535 }
536 536
537 ret = v4l2_subdev_call(to_outsd(mdev), video, s_dv_preset, preset); 537 ret = v4l2_subdev_call(to_outsd(mdev), video, s_dv_timings, timings);
538 538
539 mutex_unlock(&mdev->mutex); 539 mutex_unlock(&mdev->mutex);
540 540
@@ -544,8 +544,8 @@ static int mxr_s_dv_preset(struct file *file, void *fh,
544 return ret ? -EINVAL : 0; 544 return ret ? -EINVAL : 0;
545} 545}
546 546
547static int mxr_g_dv_preset(struct file *file, void *fh, 547static int mxr_g_dv_timings(struct file *file, void *fh,
548 struct v4l2_dv_preset *preset) 548 struct v4l2_dv_timings *timings)
549{ 549{
550 struct mxr_layer *layer = video_drvdata(file); 550 struct mxr_layer *layer = video_drvdata(file);
551 struct mxr_device *mdev = layer->mdev; 551 struct mxr_device *mdev = layer->mdev;
@@ -553,13 +553,28 @@ static int mxr_g_dv_preset(struct file *file, void *fh,
553 553
554 /* lock protects from changing sd_out */ 554 /* lock protects from changing sd_out */
555 mutex_lock(&mdev->mutex); 555 mutex_lock(&mdev->mutex);
556 ret = v4l2_subdev_call(to_outsd(mdev), video, g_dv_preset, preset); 556 ret = v4l2_subdev_call(to_outsd(mdev), video, g_dv_timings, timings);
557 mutex_unlock(&mdev->mutex); 557 mutex_unlock(&mdev->mutex);
558 558
559 return ret ? -EINVAL : 0; 559 return ret ? -EINVAL : 0;
560} 560}
561 561
562static int mxr_s_std(struct file *file, void *fh, v4l2_std_id *norm) 562static int mxr_dv_timings_cap(struct file *file, void *fh,
563 struct v4l2_dv_timings_cap *cap)
564{
565 struct mxr_layer *layer = video_drvdata(file);
566 struct mxr_device *mdev = layer->mdev;
567 int ret;
568
569 /* lock protects from changing sd_out */
570 mutex_lock(&mdev->mutex);
571 ret = v4l2_subdev_call(to_outsd(mdev), video, dv_timings_cap, cap);
572 mutex_unlock(&mdev->mutex);
573
574 return ret ? -EINVAL : 0;
575}
576
577static int mxr_s_std(struct file *file, void *fh, v4l2_std_id norm)
563{ 578{
564 struct mxr_layer *layer = video_drvdata(file); 579 struct mxr_layer *layer = video_drvdata(file);
565 struct mxr_device *mdev = layer->mdev; 580 struct mxr_device *mdev = layer->mdev;
@@ -576,7 +591,7 @@ static int mxr_s_std(struct file *file, void *fh, v4l2_std_id *norm)
576 return -EBUSY; 591 return -EBUSY;
577 } 592 }
578 593
579 ret = v4l2_subdev_call(to_outsd(mdev), video, s_std_output, *norm); 594 ret = v4l2_subdev_call(to_outsd(mdev), video, s_std_output, norm);
580 595
581 mutex_unlock(&mdev->mutex); 596 mutex_unlock(&mdev->mutex);
582 597
@@ -616,8 +631,8 @@ static int mxr_enum_output(struct file *file, void *fh, struct v4l2_output *a)
616 /* try to obtain supported tv norms */ 631 /* try to obtain supported tv norms */
617 v4l2_subdev_call(sd, video, g_tvnorms_output, &a->std); 632 v4l2_subdev_call(sd, video, g_tvnorms_output, &a->std);
618 a->capabilities = 0; 633 a->capabilities = 0;
619 if (sd->ops->video && sd->ops->video->s_dv_preset) 634 if (sd->ops->video && sd->ops->video->s_dv_timings)
620 a->capabilities |= V4L2_OUT_CAP_PRESETS; 635 a->capabilities |= V4L2_OUT_CAP_DV_TIMINGS;
621 if (sd->ops->video && sd->ops->video->s_std_output) 636 if (sd->ops->video && sd->ops->video->s_std_output)
622 a->capabilities |= V4L2_OUT_CAP_STD; 637 a->capabilities |= V4L2_OUT_CAP_STD;
623 a->type = V4L2_OUTPUT_TYPE_ANALOG; 638 a->type = V4L2_OUTPUT_TYPE_ANALOG;
@@ -738,10 +753,11 @@ static const struct v4l2_ioctl_ops mxr_ioctl_ops = {
738 /* Streaming control */ 753 /* Streaming control */
739 .vidioc_streamon = mxr_streamon, 754 .vidioc_streamon = mxr_streamon,
740 .vidioc_streamoff = mxr_streamoff, 755 .vidioc_streamoff = mxr_streamoff,
741 /* Preset functions */ 756 /* DV Timings functions */
742 .vidioc_enum_dv_presets = mxr_enum_dv_presets, 757 .vidioc_enum_dv_timings = mxr_enum_dv_timings,
743 .vidioc_s_dv_preset = mxr_s_dv_preset, 758 .vidioc_s_dv_timings = mxr_s_dv_timings,
744 .vidioc_g_dv_preset = mxr_g_dv_preset, 759 .vidioc_g_dv_timings = mxr_g_dv_timings,
760 .vidioc_dv_timings_cap = mxr_dv_timings_cap,
745 /* analog TV standard functions */ 761 /* analog TV standard functions */
746 .vidioc_s_std = mxr_s_std, 762 .vidioc_s_std = mxr_s_std,
747 .vidioc_g_std = mxr_g_std, 763 .vidioc_g_std = mxr_g_std,
diff --git a/drivers/media/platform/s5p-tv/sii9234_drv.c b/drivers/media/platform/s5p-tv/sii9234_drv.c
index d90d2286090b..39b77d24b9c2 100644
--- a/drivers/media/platform/s5p-tv/sii9234_drv.c
+++ b/drivers/media/platform/s5p-tv/sii9234_drv.c
@@ -23,9 +23,6 @@
23#include <linux/regulator/machine.h> 23#include <linux/regulator/machine.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25 25
26#include <mach/gpio.h>
27#include <plat/gpio-cfg.h>
28
29#include <media/sii9234.h> 26#include <media/sii9234.h>
30#include <media/v4l2-subdev.h> 27#include <media/v4l2-subdev.h>
31 28
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index cb54c69d5748..0b32cc3f6a47 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -10,6 +10,7 @@
10 * published by the Free Software Foundation 10 * published by the Free Software Foundation
11 */ 11 */
12 12
13#include <linux/err.h>
13#include <linux/fs.h> 14#include <linux/fs.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/module.h> 16#include <linux/module.h>
@@ -1164,9 +1165,9 @@ static int sh_veu_probe(struct platform_device *pdev)
1164 1165
1165 veu->is_2h = resource_size(reg_res) == 0x22c; 1166 veu->is_2h = resource_size(reg_res) == 0x22c;
1166 1167
1167 veu->base = devm_request_and_ioremap(&pdev->dev, reg_res); 1168 veu->base = devm_ioremap_resource(&pdev->dev, reg_res);
1168 if (!veu->base) 1169 if (IS_ERR(veu->base))
1169 return -ENOMEM; 1170 return PTR_ERR(veu->base);
1170 1171
1171 ret = devm_request_threaded_irq(&pdev->dev, irq, sh_veu_isr, sh_veu_bh, 1172 ret = devm_request_threaded_irq(&pdev->dev, irq, sh_veu_isr, sh_veu_bh,
1172 0, "veu", veu); 1173 0, "veu", veu);
@@ -1248,18 +1249,7 @@ static struct platform_driver __refdata sh_veu_pdrv = {
1248 }, 1249 },
1249}; 1250};
1250 1251
1251static int __init sh_veu_init(void) 1252module_platform_driver_probe(sh_veu_pdrv, sh_veu_probe);
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 1253
1264MODULE_DESCRIPTION("sh-mobile VEU mem2mem driver"); 1254MODULE_DESCRIPTION("sh-mobile VEU mem2mem driver");
1265MODULE_AUTHOR("Guennadi Liakhovetski, <g.liakhovetski@gmx.de>"); 1255MODULE_AUTHOR("Guennadi Liakhovetski, <g.liakhovetski@gmx.de>");
diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index 66c8da18df84..7d0235069c87 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -881,29 +881,29 @@ static u32 sh_vou_ntsc_mode(enum sh_vou_bus_fmt bus_fmt)
881 } 881 }
882} 882}
883 883
884static 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)
885{ 885{
886 struct sh_vou_device *vou_dev = video_drvdata(file); 886 struct sh_vou_device *vou_dev = video_drvdata(file);
887 int ret; 887 int ret;
888 888
889 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);
890 890
891 if (*std_id & ~vou_dev->vdev->tvnorms) 891 if (std_id & ~vou_dev->vdev->tvnorms)
892 return -EINVAL; 892 return -EINVAL;
893 893
894 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,
895 s_std_output, *std_id); 895 s_std_output, std_id);
896 /* Shall we continue, if the subdev doesn't support .s_std_output()? */ 896 /* Shall we continue, if the subdev doesn't support .s_std_output()? */
897 if (ret < 0 && ret != -ENOIOCTLCMD) 897 if (ret < 0 && ret != -ENOIOCTLCMD)
898 return ret; 898 return ret;
899 899
900 if (*std_id & V4L2_STD_525_60) 900 if (std_id & V4L2_STD_525_60)
901 sh_vou_reg_ab_set(vou_dev, VOUCR, 901 sh_vou_reg_ab_set(vou_dev, VOUCR,
902 sh_vou_ntsc_mode(vou_dev->pdata->bus_fmt) << 29, 7 << 29); 902 sh_vou_ntsc_mode(vou_dev->pdata->bus_fmt) << 29, 7 << 29);
903 else 903 else
904 sh_vou_reg_ab_set(vou_dev, VOUCR, 5 << 29, 7 << 29); 904 sh_vou_reg_ab_set(vou_dev, VOUCR, 5 << 29, 7 << 29);
905 905
906 vou_dev->std = *std_id; 906 vou_dev->std = std_id;
907 907
908 return 0; 908 return 0;
909} 909}
@@ -1266,7 +1266,7 @@ static int sh_vou_g_register(struct file *file, void *fh,
1266} 1266}
1267 1267
1268static int sh_vou_s_register(struct file *file, void *fh, 1268static int sh_vou_s_register(struct file *file, void *fh,
1269 struct v4l2_dbg_register *reg) 1269 const struct v4l2_dbg_register *reg)
1270{ 1270{
1271 struct sh_vou_device *vou_dev = video_drvdata(file); 1271 struct sh_vou_device *vou_dev = video_drvdata(file);
1272 1272
@@ -1485,18 +1485,7 @@ static struct platform_driver __refdata sh_vou = {
1485 }, 1485 },
1486}; 1486};
1487 1487
1488static int __init sh_vou_init(void) 1488module_platform_driver_probe(sh_vou, sh_vou_probe);
1489{
1490 return platform_driver_probe(&sh_vou, sh_vou_probe);
1491}
1492
1493static void __exit sh_vou_exit(void)
1494{
1495 platform_driver_unregister(&sh_vou);
1496}
1497
1498module_init(sh_vou_init);
1499module_exit(sh_vou_exit);
1500 1489
1501MODULE_DESCRIPTION("SuperH VOU driver"); 1490MODULE_DESCRIPTION("SuperH VOU driver");
1502MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>"); 1491MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index 82dbf99d347c..1abbb36d0755 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -514,6 +514,7 @@ static int isi_camera_init_videobuf(struct vb2_queue *q,
514 q->buf_struct_size = sizeof(struct frame_buffer); 514 q->buf_struct_size = sizeof(struct frame_buffer);
515 q->ops = &isi_video_qops; 515 q->ops = &isi_video_qops;
516 q->mem_ops = &vb2_dma_contig_memops; 516 q->mem_ops = &vb2_dma_contig_memops;
517 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
517 518
518 return vb2_queue_init(q); 519 return vb2_queue_init(q);
519} 520}
@@ -1020,7 +1021,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
1020 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS); 1021 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
1021 1022
1022 irq = platform_get_irq(pdev, 0); 1023 irq = platform_get_irq(pdev, 0);
1023 if (irq < 0) { 1024 if (IS_ERR_VALUE(irq)) {
1024 ret = irq; 1025 ret = irq;
1025 goto err_req_irq; 1026 goto err_req_irq;
1026 } 1027 }
@@ -1073,7 +1074,6 @@ err_clk_prepare_pclk:
1073} 1074}
1074 1075
1075static struct platform_driver atmel_isi_driver = { 1076static struct platform_driver atmel_isi_driver = {
1076 .probe = atmel_isi_probe,
1077 .remove = atmel_isi_remove, 1077 .remove = atmel_isi_remove,
1078 .driver = { 1078 .driver = {
1079 .name = "atmel_isi", 1079 .name = "atmel_isi",
@@ -1081,17 +1081,7 @@ static struct platform_driver atmel_isi_driver = {
1081 }, 1081 },
1082}; 1082};
1083 1083
1084static int __init atmel_isi_init_module(void) 1084module_platform_driver_probe(atmel_isi_driver, atmel_isi_probe);
1085{
1086 return platform_driver_probe(&atmel_isi_driver, &atmel_isi_probe);
1087}
1088
1089static void __exit atmel_isi_exit(void)
1090{
1091 platform_driver_unregister(&atmel_isi_driver);
1092}
1093module_init(atmel_isi_init_module);
1094module_exit(atmel_isi_exit);
1095 1085
1096MODULE_AUTHOR("Josh Wu <josh.wu@atmel.com>"); 1086MODULE_AUTHOR("Josh Wu <josh.wu@atmel.com>");
1097MODULE_DESCRIPTION("The V4L2 driver for Atmel Linux"); 1087MODULE_DESCRIPTION("The V4L2 driver for Atmel Linux");
diff --git a/drivers/media/platform/soc_camera/mx1_camera.c b/drivers/media/platform/soc_camera/mx1_camera.c
index 25b2a285dc86..a3fd8d63546c 100644
--- a/drivers/media/platform/soc_camera/mx1_camera.c
+++ b/drivers/media/platform/soc_camera/mx1_camera.c
@@ -776,7 +776,7 @@ static int __init mx1_camera_probe(struct platform_device *pdev)
776 /* request irq */ 776 /* request irq */
777 err = claim_fiq(&fh); 777 err = claim_fiq(&fh);
778 if (err) { 778 if (err) {
779 dev_err(&pdev->dev, "Camera interrupt register failed \n"); 779 dev_err(&pdev->dev, "Camera interrupt register failed\n");
780 goto exit_free_dma; 780 goto exit_free_dma;
781 } 781 }
782 782
@@ -853,24 +853,13 @@ static int __exit mx1_camera_remove(struct platform_device *pdev)
853} 853}
854 854
855static struct platform_driver mx1_camera_driver = { 855static struct platform_driver mx1_camera_driver = {
856 .driver = { 856 .driver = {
857 .name = DRIVER_NAME, 857 .name = DRIVER_NAME,
858 }, 858 },
859 .remove = __exit_p(mx1_camera_remove), 859 .remove = __exit_p(mx1_camera_remove),
860}; 860};
861 861
862static int __init mx1_camera_init(void) 862module_platform_driver_probe(mx1_camera_driver, mx1_camera_probe);
863{
864 return platform_driver_probe(&mx1_camera_driver, mx1_camera_probe);
865}
866
867static void __exit mx1_camera_exit(void)
868{
869 return platform_driver_unregister(&mx1_camera_driver);
870}
871
872module_init(mx1_camera_init);
873module_exit(mx1_camera_exit);
874 863
875MODULE_DESCRIPTION("i.MX1/i.MXL SoC Camera Host driver"); 864MODULE_DESCRIPTION("i.MX1/i.MXL SoC Camera Host driver");
876MODULE_AUTHOR("Paulius Zaleckas <paulius.zaleckas@teltonika.lt>"); 865MODULE_AUTHOR("Paulius Zaleckas <paulius.zaleckas@teltonika.lt>");
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index ffba7d91f413..5bbeb43e4531 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -797,6 +797,7 @@ static int mx2_camera_init_videobuf(struct vb2_queue *q,
797 q->ops = &mx2_videobuf_ops; 797 q->ops = &mx2_videobuf_ops;
798 q->mem_ops = &vb2_dma_contig_memops; 798 q->mem_ops = &vb2_dma_contig_memops;
799 q->buf_struct_size = sizeof(struct mx2_buffer); 799 q->buf_struct_size = sizeof(struct mx2_buffer);
800 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
800 801
801 return vb2_queue_init(q); 802 return vb2_queue_init(q);
802} 803}
@@ -1453,7 +1454,7 @@ static int mx27_camera_emma_init(struct platform_device *pdev)
1453 err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0, 1454 err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0,
1454 MX2_CAM_DRV_NAME, pcdev); 1455 MX2_CAM_DRV_NAME, pcdev);
1455 if (err) { 1456 if (err) {
1456 dev_err(pcdev->dev, "Camera EMMA interrupt register failed \n"); 1457 dev_err(pcdev->dev, "Camera EMMA interrupt register failed\n");
1457 goto out; 1458 goto out;
1458 } 1459 }
1459 1460
@@ -1614,15 +1615,14 @@ static int mx2_camera_remove(struct platform_device *pdev)
1614} 1615}
1615 1616
1616static struct platform_driver mx2_camera_driver = { 1617static struct platform_driver mx2_camera_driver = {
1617 .driver = { 1618 .driver = {
1618 .name = MX2_CAM_DRV_NAME, 1619 .name = MX2_CAM_DRV_NAME,
1619 }, 1620 },
1620 .id_table = mx2_camera_devtype, 1621 .id_table = mx2_camera_devtype,
1621 .remove = mx2_camera_remove, 1622 .remove = mx2_camera_remove,
1622 .probe = mx2_camera_probe,
1623}; 1623};
1624 1624
1625module_platform_driver(mx2_camera_driver); 1625module_platform_driver_probe(mx2_camera_driver, mx2_camera_probe);
1626 1626
1627MODULE_DESCRIPTION("i.MX27 SoC Camera Host driver"); 1627MODULE_DESCRIPTION("i.MX27 SoC Camera Host driver");
1628MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>"); 1628MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>");
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index f5cbb92db545..5da337736cd8 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -455,6 +455,7 @@ static int mx3_camera_init_videobuf(struct vb2_queue *q,
455 q->ops = &mx3_videobuf_ops; 455 q->ops = &mx3_videobuf_ops;
456 q->mem_ops = &vb2_dma_contig_memops; 456 q->mem_ops = &vb2_dma_contig_memops;
457 q->buf_struct_size = sizeof(struct mx3_camera_buffer); 457 q->buf_struct_size = sizeof(struct mx3_camera_buffer);
458 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
458 459
459 return vb2_queue_init(q); 460 return vb2_queue_init(q);
460} 461}
@@ -1275,7 +1276,7 @@ static int mx3_camera_remove(struct platform_device *pdev)
1275} 1276}
1276 1277
1277static struct platform_driver mx3_camera_driver = { 1278static struct platform_driver mx3_camera_driver = {
1278 .driver = { 1279 .driver = {
1279 .name = MX3_CAM_DRV_NAME, 1280 .name = MX3_CAM_DRV_NAME,
1280 }, 1281 },
1281 .probe = mx3_camera_probe, 1282 .probe = mx3_camera_probe,
diff --git a/drivers/media/platform/soc_camera/omap1_camera.c b/drivers/media/platform/soc_camera/omap1_camera.c
index 2547bf88f79f..9689a6e89b7f 100644
--- a/drivers/media/platform/soc_camera/omap1_camera.c
+++ b/drivers/media/platform/soc_camera/omap1_camera.c
@@ -1546,7 +1546,7 @@ static struct soc_camera_host_ops omap1_host_ops = {
1546 .poll = omap1_cam_poll, 1546 .poll = omap1_cam_poll,
1547}; 1547};
1548 1548
1549static int __init omap1_cam_probe(struct platform_device *pdev) 1549static int omap1_cam_probe(struct platform_device *pdev)
1550{ 1550{
1551 struct omap1_cam_dev *pcdev; 1551 struct omap1_cam_dev *pcdev;
1552 struct resource *res; 1552 struct resource *res;
@@ -1677,7 +1677,7 @@ exit:
1677 return err; 1677 return err;
1678} 1678}
1679 1679
1680static int __exit omap1_cam_remove(struct platform_device *pdev) 1680static int omap1_cam_remove(struct platform_device *pdev)
1681{ 1681{
1682 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); 1682 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
1683 struct omap1_cam_dev *pcdev = container_of(soc_host, 1683 struct omap1_cam_dev *pcdev = container_of(soc_host,
@@ -1709,7 +1709,7 @@ static struct platform_driver omap1_cam_driver = {
1709 .name = DRIVER_NAME, 1709 .name = DRIVER_NAME,
1710 }, 1710 },
1711 .probe = omap1_cam_probe, 1711 .probe = omap1_cam_probe,
1712 .remove = __exit_p(omap1_cam_remove), 1712 .remove = omap1_cam_remove,
1713}; 1713};
1714 1714
1715module_platform_driver(omap1_cam_driver); 1715module_platform_driver(omap1_cam_driver);
diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c
index 395e2e043615..d665242e8207 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -15,6 +15,7 @@
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <linux/err.h>
18#include <linux/errno.h> 19#include <linux/errno.h>
19#include <linux/fs.h> 20#include <linux/fs.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
@@ -1710,9 +1711,10 @@ static int pxa_camera_probe(struct platform_device *pdev)
1710 /* 1711 /*
1711 * Request the regions. 1712 * Request the regions.
1712 */ 1713 */
1713 base = devm_request_and_ioremap(&pdev->dev, res); 1714 base = devm_ioremap_resource(&pdev->dev, res);
1714 if (!base) 1715 if (IS_ERR(base))
1715 return -ENOMEM; 1716 return PTR_ERR(base);
1717
1716 pcdev->irq = irq; 1718 pcdev->irq = irq;
1717 pcdev->base = base; 1719 pcdev->base = base;
1718 1720
@@ -1794,13 +1796,13 @@ static int pxa_camera_remove(struct platform_device *pdev)
1794 return 0; 1796 return 0;
1795} 1797}
1796 1798
1797static struct dev_pm_ops pxa_camera_pm = { 1799static const struct dev_pm_ops pxa_camera_pm = {
1798 .suspend = pxa_camera_suspend, 1800 .suspend = pxa_camera_suspend,
1799 .resume = pxa_camera_resume, 1801 .resume = pxa_camera_resume,
1800}; 1802};
1801 1803
1802static struct platform_driver pxa_camera_driver = { 1804static struct platform_driver pxa_camera_driver = {
1803 .driver = { 1805 .driver = {
1804 .name = PXA_CAM_DRV_NAME, 1806 .name = PXA_CAM_DRV_NAME,
1805 .pm = &pxa_camera_pm, 1807 .pm = &pxa_camera_pm,
1806 }, 1808 },
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 bb08a46432f4..143d29fe0137 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -20,6 +20,7 @@
20#include <linux/completion.h> 20#include <linux/completion.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/err.h>
23#include <linux/errno.h> 24#include <linux/errno.h>
24#include <linux/fs.h> 25#include <linux/fs.h>
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
@@ -2026,6 +2027,7 @@ static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
2026 q->ops = &sh_mobile_ceu_videobuf_ops; 2027 q->ops = &sh_mobile_ceu_videobuf_ops;
2027 q->mem_ops = &vb2_dma_contig_memops; 2028 q->mem_ops = &vb2_dma_contig_memops;
2028 q->buf_struct_size = sizeof(struct sh_mobile_ceu_buffer); 2029 q->buf_struct_size = sizeof(struct sh_mobile_ceu_buffer);
2030 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2029 2031
2030 return vb2_queue_init(q); 2032 return vb2_queue_init(q);
2031} 2033}
@@ -2110,11 +2112,9 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2110 pcdev->max_width = pcdev->pdata->max_width ? : 2560; 2112 pcdev->max_width = pcdev->pdata->max_width ? : 2560;
2111 pcdev->max_height = pcdev->pdata->max_height ? : 1920; 2113 pcdev->max_height = pcdev->pdata->max_height ? : 1920;
2112 2114
2113 base = devm_request_and_ioremap(&pdev->dev, res); 2115 base = devm_ioremap_resource(&pdev->dev, res);
2114 if (!base) { 2116 if (IS_ERR(base))
2115 dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n"); 2117 return PTR_ERR(base);
2116 return -ENXIO;
2117 }
2118 2118
2119 pcdev->irq = irq; 2119 pcdev->irq = irq;
2120 pcdev->base = base; 2120 pcdev->base = base;
@@ -2288,7 +2288,7 @@ static const struct dev_pm_ops sh_mobile_ceu_dev_pm_ops = {
2288}; 2288};
2289 2289
2290static struct platform_driver sh_mobile_ceu_driver = { 2290static struct platform_driver sh_mobile_ceu_driver = {
2291 .driver = { 2291 .driver = {
2292 .name = "sh_mobile_ceu", 2292 .name = "sh_mobile_ceu",
2293 .pm = &sh_mobile_ceu_dev_pm_ops, 2293 .pm = &sh_mobile_ceu_dev_pm_ops,
2294 }, 2294 },
diff --git a/drivers/media/platform/soc_camera/sh_mobile_csi2.c b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
index 42c559eb4937..09cb4fc88f34 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_csi2.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/err.h>
12#include <linux/i2c.h> 13#include <linux/i2c.h>
13#include <linux/io.h> 14#include <linux/io.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
@@ -324,11 +325,9 @@ static int sh_csi2_probe(struct platform_device *pdev)
324 325
325 priv->irq = irq; 326 priv->irq = irq;
326 327
327 priv->base = devm_request_and_ioremap(&pdev->dev, res); 328 priv->base = devm_ioremap_resource(&pdev->dev, res);
328 if (!priv->base) { 329 if (IS_ERR(priv->base))
329 dev_err(&pdev->dev, "Unable to ioremap CSI2 registers.\n"); 330 return PTR_ERR(priv->base);
330 return -ENXIO;
331 }
332 331
333 priv->pdev = pdev; 332 priv->pdev = pdev;
334 platform_set_drvdata(pdev, priv); 333 platform_set_drvdata(pdev, priv);
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 8ec98051ea73..eea832c5fd01 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -256,12 +256,12 @@ static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
256 return 0; 256 return 0;
257} 257}
258 258
259static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a) 259static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id a)
260{ 260{
261 struct soc_camera_device *icd = file->private_data; 261 struct soc_camera_device *icd = file->private_data;
262 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 262 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
263 263
264 return v4l2_subdev_call(sd, core, s_std, *a); 264 return v4l2_subdev_call(sd, core, s_std, a);
265} 265}
266 266
267static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a) 267static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a)
@@ -508,36 +508,49 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd,
508static int soc_camera_open(struct file *file) 508static 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;
512 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
513 struct soc_camera_host *ici; 512 struct soc_camera_host *ici;
514 int ret; 513 int ret;
515 514
516 if (!to_soc_camera_control(icd))
517 /* No device driver attached */
518 return -ENODEV;
519
520 /* 515 /*
521 * Don't mess with the host during probe: wait until the loop in 516 * Don't mess with the host during probe: wait until the loop in
522 * scan_add_host() completes 517 * scan_add_host() completes. Also protect against a race with
518 * soc_camera_host_unregister().
523 */ 519 */
524 if (mutex_lock_interruptible(&list_lock)) 520 if (mutex_lock_interruptible(&list_lock))
525 return -ERESTARTSYS; 521 return -ERESTARTSYS;
522
523 if (!vdev || !video_is_registered(vdev)) {
524 mutex_unlock(&list_lock);
525 return -ENODEV;
526 }
527
528 icd = dev_get_drvdata(vdev->parent);
526 ici = to_soc_camera_host(icd->parent); 529 ici = to_soc_camera_host(icd->parent);
530
531 ret = try_module_get(ici->ops->owner) ? 0 : -ENODEV;
527 mutex_unlock(&list_lock); 532 mutex_unlock(&list_lock);
528 533
529 if (mutex_lock_interruptible(&ici->host_lock)) 534 if (ret < 0) {
530 return -ERESTARTSYS;
531 if (!try_module_get(ici->ops->owner)) {
532 dev_err(icd->pdev, "Couldn't lock capture bus driver.\n"); 535 dev_err(icd->pdev, "Couldn't lock capture bus driver.\n");
533 ret = -EINVAL; 536 return ret;
534 goto emodule;
535 } 537 }
536 538
539 if (!to_soc_camera_control(icd)) {
540 /* No device driver attached */
541 ret = -ENODEV;
542 goto econtrol;
543 }
544
545 if (mutex_lock_interruptible(&ici->host_lock)) {
546 ret = -ERESTARTSYS;
547 goto elockhost;
548 }
537 icd->use_count++; 549 icd->use_count++;
538 550
539 /* Now we really have to activate the camera */ 551 /* Now we really have to activate the camera */
540 if (icd->use_count == 1) { 552 if (icd->use_count == 1) {
553 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
541 /* Restore parameters before the last close() per V4L2 API */ 554 /* Restore parameters before the last close() per V4L2 API */
542 struct v4l2_format f = { 555 struct v4l2_format f = {
543 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, 556 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
@@ -609,9 +622,10 @@ epower:
609 ici->ops->remove(icd); 622 ici->ops->remove(icd);
610eiciadd: 623eiciadd:
611 icd->use_count--; 624 icd->use_count--;
612 module_put(ici->ops->owner);
613emodule:
614 mutex_unlock(&ici->host_lock); 625 mutex_unlock(&ici->host_lock);
626elockhost:
627econtrol:
628 module_put(ici->ops->owner);
615 629
616 return ret; 630 return ret;
617} 631}
@@ -1042,7 +1056,7 @@ static int soc_camera_g_register(struct file *file, void *fh,
1042} 1056}
1043 1057
1044static int soc_camera_s_register(struct file *file, void *fh, 1058static int soc_camera_s_register(struct file *file, void *fh,
1045 struct v4l2_dbg_register *reg) 1059 const struct v4l2_dbg_register *reg)
1046{ 1060{
1047 struct soc_camera_device *icd = file->private_data; 1061 struct soc_camera_device *icd = file->private_data;
1048 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1062 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
diff --git a/drivers/media/platform/soc_camera/soc_camera_platform.c b/drivers/media/platform/soc_camera/soc_camera_platform.c
index ce3b1d6a4734..1b7a88ca195b 100644
--- a/drivers/media/platform/soc_camera/soc_camera_platform.c
+++ b/drivers/media/platform/soc_camera/soc_camera_platform.c
@@ -188,7 +188,7 @@ static int soc_camera_platform_remove(struct platform_device *pdev)
188} 188}
189 189
190static struct platform_driver soc_camera_platform_driver = { 190static struct platform_driver soc_camera_platform_driver = {
191 .driver = { 191 .driver = {
192 .name = "soc_camera_platform", 192 .name = "soc_camera_platform",
193 .owner = THIS_MODULE, 193 .owner = THIS_MODULE,
194 }, 194 },
diff --git a/drivers/media/platform/soc_camera/soc_mediabus.c b/drivers/media/platform/soc_camera/soc_mediabus.c
index 89dce097a827..dc02deca7563 100644
--- a/drivers/media/platform/soc_camera/soc_mediabus.c
+++ b/drivers/media/platform/soc_camera/soc_mediabus.c
@@ -73,7 +73,7 @@ static const struct soc_mbus_lookup mbus_fmt[] = {
73 .name = "RGB555X", 73 .name = "RGB555X",
74 .bits_per_sample = 8, 74 .bits_per_sample = 8,
75 .packing = SOC_MBUS_PACKING_2X8_PADHI, 75 .packing = SOC_MBUS_PACKING_2X8_PADHI,
76 .order = SOC_MBUS_ORDER_LE, 76 .order = SOC_MBUS_ORDER_BE,
77 .layout = SOC_MBUS_LAYOUT_PACKED, 77 .layout = SOC_MBUS_LAYOUT_PACKED,
78 }, 78 },
79}, { 79}, {
@@ -93,10 +93,46 @@ static const struct soc_mbus_lookup mbus_fmt[] = {
93 .name = "RGB565X", 93 .name = "RGB565X",
94 .bits_per_sample = 8, 94 .bits_per_sample = 8,
95 .packing = SOC_MBUS_PACKING_2X8_PADHI, 95 .packing = SOC_MBUS_PACKING_2X8_PADHI,
96 .order = SOC_MBUS_ORDER_LE, 96 .order = SOC_MBUS_ORDER_BE,
97 .layout = SOC_MBUS_LAYOUT_PACKED, 97 .layout = SOC_MBUS_LAYOUT_PACKED,
98 }, 98 },
99}, { 99}, {
100 .code = V4L2_MBUS_FMT_RGB666_1X18,
101 .fmt = {
102 .fourcc = V4L2_PIX_FMT_RGB32,
103 .name = "RGB666/32bpp",
104 .bits_per_sample = 18,
105 .packing = SOC_MBUS_PACKING_EXTEND32,
106 .order = SOC_MBUS_ORDER_LE,
107 },
108}, {
109 .code = V4L2_MBUS_FMT_RGB888_1X24,
110 .fmt = {
111 .fourcc = V4L2_PIX_FMT_RGB32,
112 .name = "RGB888/32bpp",
113 .bits_per_sample = 24,
114 .packing = SOC_MBUS_PACKING_EXTEND32,
115 .order = SOC_MBUS_ORDER_LE,
116 },
117}, {
118 .code = V4L2_MBUS_FMT_RGB888_2X12_BE,
119 .fmt = {
120 .fourcc = V4L2_PIX_FMT_RGB32,
121 .name = "RGB888/32bpp",
122 .bits_per_sample = 12,
123 .packing = SOC_MBUS_PACKING_EXTEND32,
124 .order = SOC_MBUS_ORDER_BE,
125 },
126}, {
127 .code = V4L2_MBUS_FMT_RGB888_2X12_LE,
128 .fmt = {
129 .fourcc = V4L2_PIX_FMT_RGB32,
130 .name = "RGB888/32bpp",
131 .bits_per_sample = 12,
132 .packing = SOC_MBUS_PACKING_EXTEND32,
133 .order = SOC_MBUS_ORDER_LE,
134 },
135}, {
100 .code = V4L2_MBUS_FMT_SBGGR8_1X8, 136 .code = V4L2_MBUS_FMT_SBGGR8_1X8,
101 .fmt = { 137 .fmt = {
102 .fourcc = V4L2_PIX_FMT_SBGGR8, 138 .fourcc = V4L2_PIX_FMT_SBGGR8,
@@ -358,6 +394,10 @@ int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf,
358 *numerator = 1; 394 *numerator = 1;
359 *denominator = 1; 395 *denominator = 1;
360 return 0; 396 return 0;
397 case SOC_MBUS_PACKING_EXTEND32:
398 *numerator = 1;
399 *denominator = 1;
400 return 0;
361 case SOC_MBUS_PACKING_2X8_PADHI: 401 case SOC_MBUS_PACKING_2X8_PADHI:
362 case SOC_MBUS_PACKING_2X8_PADLO: 402 case SOC_MBUS_PACKING_2X8_PADLO:
363 *numerator = 2; 403 *numerator = 2;
@@ -392,6 +432,8 @@ s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
392 return width * 3 / 2; 432 return width * 3 / 2;
393 case SOC_MBUS_PACKING_VARIABLE: 433 case SOC_MBUS_PACKING_VARIABLE:
394 return 0; 434 return 0;
435 case SOC_MBUS_PACKING_EXTEND32:
436 return width * 4;
395 } 437 }
396 return -EINVAL; 438 return -EINVAL;
397} 439}
diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
index c3a2a4484401..a2f7bdd5104f 100644
--- a/drivers/media/platform/timblogiw.c
+++ b/drivers/media/platform/timblogiw.c
@@ -78,7 +78,7 @@ struct timblogiw_buffer {
78 struct timblogiw_fh *fh; 78 struct timblogiw_fh *fh;
79}; 79};
80 80
81const struct timblogiw_tvnorm timblogiw_tvnorms[] = { 81static const struct timblogiw_tvnorm timblogiw_tvnorms[] = {
82 { 82 {
83 .std = V4L2_STD_PAL, 83 .std = V4L2_STD_PAL,
84 .width = 720, 84 .width = 720,
@@ -336,7 +336,7 @@ static int timblogiw_g_std(struct file *file, void *priv, v4l2_std_id *std)
336 return 0; 336 return 0;
337} 337}
338 338
339static int timblogiw_s_std(struct file *file, void *priv, v4l2_std_id *std) 339static int timblogiw_s_std(struct file *file, void *priv, v4l2_std_id std)
340{ 340{
341 struct video_device *vdev = video_devdata(file); 341 struct video_device *vdev = video_devdata(file);
342 struct timblogiw *lw = video_get_drvdata(vdev); 342 struct timblogiw *lw = video_get_drvdata(vdev);
@@ -348,10 +348,10 @@ static int timblogiw_s_std(struct file *file, void *priv, v4l2_std_id *std)
348 mutex_lock(&lw->lock); 348 mutex_lock(&lw->lock);
349 349
350 if (TIMBLOGIW_HAS_DECODER(lw)) 350 if (TIMBLOGIW_HAS_DECODER(lw))
351 err = v4l2_subdev_call(lw->sd_enc, core, s_std, *std); 351 err = v4l2_subdev_call(lw->sd_enc, core, s_std, std);
352 352
353 if (!err) 353 if (!err)
354 fh->cur_norm = timblogiw_get_norm(*std); 354 fh->cur_norm = timblogiw_get_norm(std);
355 355
356 mutex_unlock(&lw->lock); 356 mutex_unlock(&lw->lock);
357 357
diff --git a/drivers/media/platform/via-camera.c b/drivers/media/platform/via-camera.c
index b051c4a28554..a794cd6c4441 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -847,7 +847,7 @@ static int viacam_s_input(struct file *filp, void *priv, unsigned int i)
847 return 0; 847 return 0;
848} 848}
849 849
850static int viacam_s_std(struct file *filp, void *priv, v4l2_std_id *std) 850static int viacam_s_std(struct file *filp, void *priv, v4l2_std_id std)
851{ 851{
852 return 0; 852 return 0;
853} 853}
diff --git a/drivers/media/platform/vino.c b/drivers/media/platform/vino.c
index eb5d6f955709..c6af974c5b45 100644
--- a/drivers/media/platform/vino.c
+++ b/drivers/media/platform/vino.c
@@ -3042,7 +3042,7 @@ static int vino_g_std(struct file *file, void *__fh,
3042} 3042}
3043 3043
3044static int vino_s_std(struct file *file, void *__fh, 3044static int vino_s_std(struct file *file, void *__fh,
3045 v4l2_std_id *std) 3045 v4l2_std_id std)
3046{ 3046{
3047 struct vino_channel_settings *vcs = video_drvdata(file); 3047 struct vino_channel_settings *vcs = video_drvdata(file);
3048 unsigned long flags; 3048 unsigned long flags;
@@ -3056,7 +3056,7 @@ static int vino_s_std(struct file *file, void *__fh,
3056 } 3056 }
3057 3057
3058 /* check if the standard is valid for the current input */ 3058 /* check if the standard is valid for the current input */
3059 if ((*std) & vino_inputs[vcs->input].std) { 3059 if (std & vino_inputs[vcs->input].std) {
3060 dprintk("standard accepted\n"); 3060 dprintk("standard accepted\n");
3061 3061
3062 /* change the video norm for SAA7191 3062 /* change the video norm for SAA7191
@@ -3065,13 +3065,13 @@ static int vino_s_std(struct file *file, void *__fh,
3065 if (vcs->input == VINO_INPUT_D1) 3065 if (vcs->input == VINO_INPUT_D1)
3066 goto out; 3066 goto out;
3067 3067
3068 if ((*std) & V4L2_STD_PAL) { 3068 if (std & V4L2_STD_PAL) {
3069 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL, 3069 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL,
3070 &flags); 3070 &flags);
3071 } else if ((*std) & V4L2_STD_NTSC) { 3071 } else if (std & V4L2_STD_NTSC) {
3072 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC, 3072 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC,
3073 &flags); 3073 &flags);
3074 } else if ((*std) & V4L2_STD_SECAM) { 3074 } else if (std & V4L2_STD_SECAM) {
3075 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM, 3075 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM,
3076 &flags); 3076 &flags);
3077 } else { 3077 } else {
diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index 8a33a712f480..85bc314382d3 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -1093,6 +1093,15 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1093 return 0; 1093 return 0;
1094 1094
1095 dev->input = i; 1095 dev->input = i;
1096 /*
1097 * Modify the brightness range depending on the input.
1098 * This makes it easy to use vivi to test if applications can
1099 * handle control range modifications and is also how this is
1100 * typically used in practice as different inputs may be hooked
1101 * up to different receivers with different control ranges.
1102 */
1103 v4l2_ctrl_modify_range(dev->brightness,
1104 128 * i, 255 + 128 * i, 1, 127 + 128 * i);
1096 precalculate_bars(dev); 1105 precalculate_bars(dev);
1097 precalculate_line(dev); 1106 precalculate_line(dev);
1098 return 0; 1107 return 0;
@@ -1429,6 +1438,7 @@ static int __init vivi_create_instance(int inst)
1429 q->buf_struct_size = sizeof(struct vivi_buffer); 1438 q->buf_struct_size = sizeof(struct vivi_buffer);
1430 q->ops = &vivi_video_qops; 1439 q->ops = &vivi_video_qops;
1431 q->mem_ops = &vb2_vmalloc_memops; 1440 q->mem_ops = &vb2_vmalloc_memops;
1441 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1432 1442
1433 ret = vb2_queue_init(q); 1443 ret = vb2_queue_init(q);
1434 if (ret) 1444 if (ret)
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 24e64a09884c..c0beee2fa37c 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -18,6 +18,22 @@ config RADIO_SI470X
18 18
19source "drivers/media/radio/si470x/Kconfig" 19source "drivers/media/radio/si470x/Kconfig"
20 20
21config RADIO_SI476X
22 tristate "Silicon Laboratories Si476x I2C FM Radio"
23 depends on I2C && VIDEO_V4L2
24 depends on MFD_SI476X_CORE
25 select SND_SOC_SI476X
26 ---help---
27 Choose Y here if you have this FM radio chip.
28
29 In order to control your radio card, you will need to use programs
30 that are compatible with the Video For Linux 2 API. Information on
31 this API and pointers to "v4l2" programs may be found at
32 <file:Documentation/video4linux/API.html>.
33
34 To compile this driver as a module, choose M here: the
35 module will be called radio-si476x.
36
21config USB_MR800 37config USB_MR800
22 tristate "AverMedia MR 800 USB FM radio support" 38 tristate "AverMedia MR 800 USB FM radio support"
23 depends on USB && VIDEO_V4L2 39 depends on USB && VIDEO_V4L2
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index 303eaebdb85a..0dcdb320cfc7 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_RADIO_GEMTEK) += radio-gemtek.o
19obj-$(CONFIG_RADIO_TRUST) += radio-trust.o 19obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
20obj-$(CONFIG_I2C_SI4713) += si4713-i2c.o 20obj-$(CONFIG_I2C_SI4713) += si4713-i2c.o
21obj-$(CONFIG_RADIO_SI4713) += radio-si4713.o 21obj-$(CONFIG_RADIO_SI4713) += radio-si4713.o
22obj-$(CONFIG_RADIO_SI476X) += radio-si476x.o
22obj-$(CONFIG_RADIO_MIROPCM20) += radio-miropcm20.o 23obj-$(CONFIG_RADIO_MIROPCM20) += radio-miropcm20.o
23obj-$(CONFIG_USB_DSBR) += dsbr100.o 24obj-$(CONFIG_USB_DSBR) += dsbr100.o
24obj-$(CONFIG_RADIO_SI470X) += si470x/ 25obj-$(CONFIG_RADIO_SI470X) += si470x/
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index 63b112b555b2..142c2ee64d31 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -208,13 +208,13 @@ static int vidioc_g_tuner(struct file *file, void *priv,
208} 208}
209 209
210static int vidioc_s_tuner(struct file *file, void *priv, 210static int vidioc_s_tuner(struct file *file, void *priv,
211 struct v4l2_tuner *v) 211 const struct v4l2_tuner *v)
212{ 212{
213 return v->index ? -EINVAL : 0; 213 return v->index ? -EINVAL : 0;
214} 214}
215 215
216static int vidioc_s_frequency(struct file *file, void *priv, 216static int vidioc_s_frequency(struct file *file, void *priv,
217 struct v4l2_frequency *f) 217 const struct v4l2_frequency *f)
218{ 218{
219 struct dsbr100_device *radio = video_drvdata(file); 219 struct dsbr100_device *radio = video_drvdata(file);
220 220
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 643d80ac28fb..545c04cf7226 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -90,6 +90,26 @@ static u16 sigtable[2][4] = {
90 { 2185, 4369, 13107, 65535 }, 90 { 2185, 4369, 13107, 65535 },
91}; 91};
92 92
93static const struct v4l2_frequency_band bands[] = {
94 {
95 .index = 0,
96 .type = V4L2_TUNER_RADIO,
97 .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
98 .rangelow = 8320, /* 520 kHz */
99 .rangehigh = 26400, /* 1650 kHz */
100 .modulation = V4L2_BAND_MODULATION_AM,
101 }, {
102 .index = 1,
103 .type = V4L2_TUNER_RADIO,
104 .capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS |
105 V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_LOW |
106 V4L2_TUNER_CAP_FREQ_BANDS,
107 .rangelow = 1400000, /* 87.5 MHz */
108 .rangehigh = 1728000, /* 108.0 MHz */
109 .modulation = V4L2_BAND_MODULATION_FM,
110 },
111};
112
93 113
94static int cadet_getstereo(struct cadet *dev) 114static int cadet_getstereo(struct cadet *dev)
95{ 115{
@@ -196,6 +216,8 @@ static void cadet_setfreq(struct cadet *dev, unsigned freq)
196 int i, j, test; 216 int i, j, test;
197 int curvol; 217 int curvol;
198 218
219 freq = clamp(freq, bands[dev->is_fm_band].rangelow,
220 bands[dev->is_fm_band].rangehigh);
199 dev->curfreq = freq; 221 dev->curfreq = freq;
200 /* 222 /*
201 * Formulate a fifo command 223 * Formulate a fifo command
@@ -337,26 +359,6 @@ static int vidioc_querycap(struct file *file, void *priv,
337 return 0; 359 return 0;
338} 360}
339 361
340static const struct v4l2_frequency_band bands[] = {
341 {
342 .index = 0,
343 .type = V4L2_TUNER_RADIO,
344 .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
345 .rangelow = 8320, /* 520 kHz */
346 .rangehigh = 26400, /* 1650 kHz */
347 .modulation = V4L2_BAND_MODULATION_AM,
348 }, {
349 .index = 1,
350 .type = V4L2_TUNER_RADIO,
351 .capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS |
352 V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_LOW |
353 V4L2_TUNER_CAP_FREQ_BANDS,
354 .rangelow = 1400000, /* 87.5 MHz */
355 .rangehigh = 1728000, /* 108.0 MHz */
356 .modulation = V4L2_BAND_MODULATION_FM,
357 },
358};
359
360static int vidioc_g_tuner(struct file *file, void *priv, 362static int vidioc_g_tuner(struct file *file, void *priv,
361 struct v4l2_tuner *v) 363 struct v4l2_tuner *v)
362{ 364{
@@ -388,7 +390,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
388} 390}
389 391
390static int vidioc_s_tuner(struct file *file, void *priv, 392static int vidioc_s_tuner(struct file *file, void *priv,
391 struct v4l2_tuner *v) 393 const struct v4l2_tuner *v)
392{ 394{
393 return v->index ? -EINVAL : 0; 395 return v->index ? -EINVAL : 0;
394} 396}
@@ -418,7 +420,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
418 420
419 421
420static int vidioc_s_frequency(struct file *file, void *priv, 422static int vidioc_s_frequency(struct file *file, void *priv,
421 struct v4l2_frequency *f) 423 const struct v4l2_frequency *f)
422{ 424{
423 struct cadet *dev = video_drvdata(file); 425 struct cadet *dev = video_drvdata(file);
424 426
@@ -426,8 +428,6 @@ static int vidioc_s_frequency(struct file *file, void *priv,
426 return -EINVAL; 428 return -EINVAL;
427 dev->is_fm_band = 429 dev->is_fm_band =
428 f->frequency >= (bands[0].rangehigh + bands[1].rangelow) / 2; 430 f->frequency >= (bands[0].rangehigh + bands[1].rangelow) / 2;
429 clamp(f->frequency, bands[dev->is_fm_band].rangelow,
430 bands[dev->is_fm_band].rangehigh);
431 cadet_setfreq(dev, f->frequency); 431 cadet_setfreq(dev, f->frequency);
432 return 0; 432 return 0;
433} 433}
diff --git a/drivers/media/radio/radio-isa.c b/drivers/media/radio/radio-isa.c
index 84b7b9f4385e..6ff350831d56 100644
--- a/drivers/media/radio/radio-isa.c
+++ b/drivers/media/radio/radio-isa.c
@@ -51,8 +51,8 @@ static int radio_isa_querycap(struct file *file, void *priv,
51 strlcpy(v->card, isa->drv->card, sizeof(v->card)); 51 strlcpy(v->card, isa->drv->card, sizeof(v->card));
52 snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", isa->v4l2_dev.name); 52 snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", isa->v4l2_dev.name);
53 53
54 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 54 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
55 v->device_caps = v->capabilities | V4L2_CAP_DEVICE_CAPS; 55 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
56 return 0; 56 return 0;
57} 57}
58 58
@@ -87,7 +87,7 @@ static int radio_isa_g_tuner(struct file *file, void *priv,
87} 87}
88 88
89static int radio_isa_s_tuner(struct file *file, void *priv, 89static int radio_isa_s_tuner(struct file *file, void *priv,
90 struct v4l2_tuner *v) 90 const struct v4l2_tuner *v)
91{ 91{
92 struct radio_isa_card *isa = video_drvdata(file); 92 struct radio_isa_card *isa = video_drvdata(file);
93 const struct radio_isa_ops *ops = isa->drv->ops; 93 const struct radio_isa_ops *ops = isa->drv->ops;
@@ -102,17 +102,18 @@ static int radio_isa_s_tuner(struct file *file, void *priv,
102} 102}
103 103
104static int radio_isa_s_frequency(struct file *file, void *priv, 104static int radio_isa_s_frequency(struct file *file, void *priv,
105 struct v4l2_frequency *f) 105 const struct v4l2_frequency *f)
106{ 106{
107 struct radio_isa_card *isa = video_drvdata(file); 107 struct radio_isa_card *isa = video_drvdata(file);
108 u32 freq = f->frequency;
108 int res; 109 int res;
109 110
110 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 111 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
111 return -EINVAL; 112 return -EINVAL;
112 f->frequency = clamp(f->frequency, FREQ_LOW, FREQ_HIGH); 113 freq = clamp(freq, FREQ_LOW, FREQ_HIGH);
113 res = isa->drv->ops->s_frequency(isa, f->frequency); 114 res = isa->drv->ops->s_frequency(isa, freq);
114 if (res == 0) 115 if (res == 0)
115 isa->freq = f->frequency; 116 isa->freq = freq;
116 return res; 117 return res;
117} 118}
118 119
diff --git a/drivers/media/radio/radio-keene.c b/drivers/media/radio/radio-keene.c
index 296941a9ae25..4c9ae767fb31 100644
--- a/drivers/media/radio/radio-keene.c
+++ b/drivers/media/radio/radio-keene.c
@@ -215,15 +215,15 @@ static int vidioc_s_modulator(struct file *file, void *priv,
215} 215}
216 216
217static int vidioc_s_frequency(struct file *file, void *priv, 217static int vidioc_s_frequency(struct file *file, void *priv,
218 struct v4l2_frequency *f) 218 const struct v4l2_frequency *f)
219{ 219{
220 struct keene_device *radio = video_drvdata(file); 220 struct keene_device *radio = video_drvdata(file);
221 unsigned freq = f->frequency;
221 222
222 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 223 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
223 return -EINVAL; 224 return -EINVAL;
224 f->frequency = clamp(f->frequency, 225 freq = clamp(freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
225 FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL); 226 return keene_cmd_main(radio, freq, true);
226 return keene_cmd_main(radio, f->frequency, true);
227} 227}
228 228
229static int vidioc_g_frequency(struct file *file, void *priv, 229static int vidioc_g_frequency(struct file *file, void *priv,
diff --git a/drivers/media/radio/radio-ma901.c b/drivers/media/radio/radio-ma901.c
index 348dafc0318a..a85b064cb7be 100644
--- a/drivers/media/radio/radio-ma901.c
+++ b/drivers/media/radio/radio-ma901.c
@@ -239,7 +239,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
239 239
240/* vidioc_s_tuner - set tuner attributes */ 240/* vidioc_s_tuner - set tuner attributes */
241static int vidioc_s_tuner(struct file *file, void *priv, 241static int vidioc_s_tuner(struct file *file, void *priv,
242 struct v4l2_tuner *v) 242 const struct v4l2_tuner *v)
243{ 243{
244 struct ma901radio_device *radio = video_drvdata(file); 244 struct ma901radio_device *radio = video_drvdata(file);
245 245
@@ -257,7 +257,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
257 257
258/* vidioc_s_frequency - set tuner radio frequency */ 258/* vidioc_s_frequency - set tuner radio frequency */
259static int vidioc_s_frequency(struct file *file, void *priv, 259static int vidioc_s_frequency(struct file *file, void *priv,
260 struct v4l2_frequency *f) 260 const struct v4l2_frequency *f)
261{ 261{
262 struct ma901radio_device *radio = video_drvdata(file); 262 struct ma901radio_device *radio = video_drvdata(file);
263 263
diff --git a/drivers/media/radio/radio-miropcm20.c b/drivers/media/radio/radio-miropcm20.c
index 3d0ff4404d12..a7e93d7477dd 100644
--- a/drivers/media/radio/radio-miropcm20.c
+++ b/drivers/media/radio/radio-miropcm20.c
@@ -103,16 +103,18 @@ static int vidioc_g_tuner(struct file *file, void *priv,
103} 103}
104 104
105static int vidioc_s_tuner(struct file *file, void *priv, 105static int vidioc_s_tuner(struct file *file, void *priv,
106 struct v4l2_tuner *v) 106 const struct v4l2_tuner *v)
107{ 107{
108 struct pcm20 *dev = video_drvdata(file); 108 struct pcm20 *dev = video_drvdata(file);
109 109
110 if (v->index) 110 if (v->index)
111 return -EINVAL; 111 return -EINVAL;
112 if (v->audmode > V4L2_TUNER_MODE_STEREO) 112 if (v->audmode > V4L2_TUNER_MODE_STEREO)
113 v->audmode = V4L2_TUNER_MODE_STEREO; 113 dev->audmode = V4L2_TUNER_MODE_STEREO;
114 else
115 dev->audmode = v->audmode;
114 snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, 116 snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
115 v->audmode == V4L2_TUNER_MODE_MONO, -1); 117 dev->audmode == V4L2_TUNER_MODE_MONO, -1);
116 return 0; 118 return 0;
117} 119}
118 120
@@ -131,14 +133,14 @@ static int vidioc_g_frequency(struct file *file, void *priv,
131 133
132 134
133static int vidioc_s_frequency(struct file *file, void *priv, 135static int vidioc_s_frequency(struct file *file, void *priv,
134 struct v4l2_frequency *f) 136 const struct v4l2_frequency *f)
135{ 137{
136 struct pcm20 *dev = video_drvdata(file); 138 struct pcm20 *dev = video_drvdata(file);
137 139
138 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 140 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
139 return -EINVAL; 141 return -EINVAL;
140 142
141 dev->freq = clamp(f->frequency, 87 * 16000U, 108 * 16000U); 143 dev->freq = clamp_t(u32, f->frequency, 87 * 16000U, 108 * 16000U);
142 pcm20_setfreq(dev, dev->freq); 144 pcm20_setfreq(dev, dev->freq);
143 return 0; 145 return 0;
144} 146}
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index 9c5a267b60b4..a360227ca3ab 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -203,10 +203,14 @@ static int amradio_set_mute(struct amradio_device *radio, bool mute)
203/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ 203/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
204static int amradio_set_freq(struct amradio_device *radio, int freq) 204static int amradio_set_freq(struct amradio_device *radio, int freq)
205{ 205{
206 unsigned short freq_send = 0x10 + (freq >> 3) / 25; 206 unsigned short freq_send;
207 u8 buf[3]; 207 u8 buf[3];
208 int retval; 208 int retval;
209 209
210 /* we need to be sure that frequency isn't out of range */
211 freq = clamp_t(unsigned, freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
212 freq_send = 0x10 + (freq >> 3) / 25;
213
210 /* frequency is calculated from freq_send and placed in first 2 bytes */ 214 /* frequency is calculated from freq_send and placed in first 2 bytes */
211 buf[0] = (freq_send >> 8) & 0xff; 215 buf[0] = (freq_send >> 8) & 0xff;
212 buf[1] = freq_send & 0xff; 216 buf[1] = freq_send & 0xff;
@@ -305,7 +309,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
305 309
306/* vidioc_s_tuner - set tuner attributes */ 310/* vidioc_s_tuner - set tuner attributes */
307static int vidioc_s_tuner(struct file *file, void *priv, 311static int vidioc_s_tuner(struct file *file, void *priv,
308 struct v4l2_tuner *v) 312 const struct v4l2_tuner *v)
309{ 313{
310 struct amradio_device *radio = video_drvdata(file); 314 struct amradio_device *radio = video_drvdata(file);
311 315
@@ -323,14 +327,13 @@ static int vidioc_s_tuner(struct file *file, void *priv,
323 327
324/* vidioc_s_frequency - set tuner radio frequency */ 328/* vidioc_s_frequency - set tuner radio frequency */
325static int vidioc_s_frequency(struct file *file, void *priv, 329static int vidioc_s_frequency(struct file *file, void *priv,
326 struct v4l2_frequency *f) 330 const struct v4l2_frequency *f)
327{ 331{
328 struct amradio_device *radio = video_drvdata(file); 332 struct amradio_device *radio = video_drvdata(file);
329 333
330 if (f->tuner != 0) 334 if (f->tuner != 0)
331 return -EINVAL; 335 return -EINVAL;
332 return amradio_set_freq(radio, clamp_t(unsigned, f->frequency, 336 return amradio_set_freq(radio, f->frequency);
333 FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL));
334} 337}
335 338
336/* vidioc_g_frequency - get tuner radio frequency */ 339/* vidioc_g_frequency - get tuner radio frequency */
@@ -389,6 +392,7 @@ static int vidioc_s_hw_freq_seek(struct file *file, void *priv,
389 continue; 392 continue;
390 amradio_send_cmd(radio, AMRADIO_GET_FREQ, 0, NULL, 0, true); 393 amradio_send_cmd(radio, AMRADIO_GET_FREQ, 0, NULL, 0, true);
391 if (radio->buffer[1] || radio->buffer[2]) { 394 if (radio->buffer[1] || radio->buffer[2]) {
395 /* To check: sometimes radio->curfreq is set to out of range value */
392 radio->curfreq = (radio->buffer[1] << 8) | radio->buffer[2]; 396 radio->curfreq = (radio->buffer[1] << 8) | radio->buffer[2];
393 radio->curfreq = (radio->curfreq - 0x10) * 200; 397 radio->curfreq = (radio->curfreq - 0x10) * 200;
394 amradio_send_cmd(radio, AMRADIO_STOP_SEARCH, 398 amradio_send_cmd(radio, AMRADIO_STOP_SEARCH,
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index b1f844c64fde..09cfbc373c92 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -8,6 +8,8 @@
8 * 8 *
9 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com> 9 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
10 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> 10 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
11 *
12 * Fully tested with actual hardware and the v4l2-compliance tool.
11 */ 13 */
12 14
13#include <linux/module.h> /* Modules */ 15#include <linux/module.h> /* Modules */
@@ -81,8 +83,7 @@ static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
81 zero(isa); 83 zero(isa);
82 84
83 outb_p(0xc8, isa->io); 85 outb_p(0xc8, isa->io);
84 if (!v4l2_ctrl_g_ctrl(isa->mute)) 86 outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
85 outb_p(0, isa->io);
86 return 0; 87 return 0;
87} 88}
88 89
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 637a55564958..adfcc61bdf0b 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -145,13 +145,13 @@ static int vidioc_g_tuner(struct file *file, void *priv,
145} 145}
146 146
147static int vidioc_s_tuner(struct file *file, void *priv, 147static int vidioc_s_tuner(struct file *file, void *priv,
148 struct v4l2_tuner *v) 148 const struct v4l2_tuner *v)
149{ 149{
150 return v->index ? -EINVAL : 0; 150 return v->index ? -EINVAL : 0;
151} 151}
152 152
153static int vidioc_s_frequency(struct file *file, void *priv, 153static int vidioc_s_frequency(struct file *file, void *priv,
154 struct v4l2_frequency *f) 154 const struct v4l2_frequency *f)
155{ 155{
156 struct fmi *fmi = video_drvdata(file); 156 struct fmi *fmi = video_drvdata(file);
157 157
diff --git a/drivers/media/radio/radio-si4713.c b/drivers/media/radio/radio-si4713.c
index 1507c9d508d7..ba4cfc946868 100644
--- a/drivers/media/radio/radio-si4713.c
+++ b/drivers/media/radio/radio-si4713.c
@@ -31,6 +31,9 @@
31#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-ioctl.h> 33#include <media/v4l2-ioctl.h>
34#include <media/v4l2-fh.h>
35#include <media/v4l2-ctrls.h>
36#include <media/v4l2-event.h>
34#include <media/radio-si4713.h> 37#include <media/radio-si4713.h>
35 38
36/* module parameters */ 39/* module parameters */
@@ -39,54 +42,30 @@ module_param(radio_nr, int, 0);
39MODULE_PARM_DESC(radio_nr, 42MODULE_PARM_DESC(radio_nr,
40 "Minor number for radio device (-1 ==> auto assign)"); 43 "Minor number for radio device (-1 ==> auto assign)");
41 44
42MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL v2");
43MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>"); 46MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
44MODULE_DESCRIPTION("Platform driver for Si4713 FM Radio Transmitter"); 47MODULE_DESCRIPTION("Platform driver for Si4713 FM Radio Transmitter");
45MODULE_VERSION("0.0.1"); 48MODULE_VERSION("0.0.1");
49MODULE_ALIAS("platform:radio-si4713");
46 50
47/* Driver state struct */ 51/* Driver state struct */
48struct radio_si4713_device { 52struct radio_si4713_device {
49 struct v4l2_device v4l2_dev; 53 struct v4l2_device v4l2_dev;
50 struct video_device *radio_dev; 54 struct video_device radio_dev;
55 struct mutex lock;
51}; 56};
52 57
53/* radio_si4713_fops - file operations interface */ 58/* radio_si4713_fops - file operations interface */
54static const struct v4l2_file_operations radio_si4713_fops = { 59static const struct v4l2_file_operations radio_si4713_fops = {
55 .owner = THIS_MODULE, 60 .owner = THIS_MODULE,
61 .open = v4l2_fh_open,
62 .release = v4l2_fh_release,
63 .poll = v4l2_ctrl_poll,
56 /* Note: locking is done at the subdev level in the i2c driver. */ 64 /* Note: locking is done at the subdev level in the i2c driver. */
57 .unlocked_ioctl = video_ioctl2, 65 .unlocked_ioctl = video_ioctl2,
58}; 66};
59 67
60/* Video4Linux Interface */ 68/* Video4Linux Interface */
61static int radio_si4713_fill_audout(struct v4l2_audioout *vao)
62{
63 /* TODO: check presence of audio output */
64 strlcpy(vao->name, "FM Modulator Audio Out", 32);
65
66 return 0;
67}
68
69static int radio_si4713_enumaudout(struct file *file, void *priv,
70 struct v4l2_audioout *vao)
71{
72 return radio_si4713_fill_audout(vao);
73}
74
75static int radio_si4713_g_audout(struct file *file, void *priv,
76 struct v4l2_audioout *vao)
77{
78 int rval = radio_si4713_fill_audout(vao);
79
80 vao->index = 0;
81
82 return rval;
83}
84
85static int radio_si4713_s_audout(struct file *file, void *priv,
86 const struct v4l2_audioout *vao)
87{
88 return vao->index ? -EINVAL : 0;
89}
90 69
91/* radio_si4713_querycap - query device capabilities */ 70/* radio_si4713_querycap - query device capabilities */
92static int radio_si4713_querycap(struct file *file, void *priv, 71static int radio_si4713_querycap(struct file *file, void *priv,
@@ -94,67 +73,15 @@ static int radio_si4713_querycap(struct file *file, void *priv,
94{ 73{
95 strlcpy(capability->driver, "radio-si4713", sizeof(capability->driver)); 74 strlcpy(capability->driver, "radio-si4713", sizeof(capability->driver));
96 strlcpy(capability->card, "Silicon Labs Si4713 Modulator", 75 strlcpy(capability->card, "Silicon Labs Si4713 Modulator",
97 sizeof(capability->card)); 76 sizeof(capability->card));
98 capability->capabilities = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT; 77 strlcpy(capability->bus_info, "platform:radio-si4713",
78 sizeof(capability->bus_info));
79 capability->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
80 capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
99 81
100 return 0; 82 return 0;
101} 83}
102 84
103/* radio_si4713_queryctrl - enumerate control items */
104static int radio_si4713_queryctrl(struct file *file, void *priv,
105 struct v4l2_queryctrl *qc)
106{
107 /* Must be sorted from low to high control ID! */
108 static const u32 user_ctrls[] = {
109 V4L2_CID_USER_CLASS,
110 V4L2_CID_AUDIO_MUTE,
111 0
112 };
113
114 /* Must be sorted from low to high control ID! */
115 static const u32 fmtx_ctrls[] = {
116 V4L2_CID_FM_TX_CLASS,
117 V4L2_CID_RDS_TX_DEVIATION,
118 V4L2_CID_RDS_TX_PI,
119 V4L2_CID_RDS_TX_PTY,
120 V4L2_CID_RDS_TX_PS_NAME,
121 V4L2_CID_RDS_TX_RADIO_TEXT,
122 V4L2_CID_AUDIO_LIMITER_ENABLED,
123 V4L2_CID_AUDIO_LIMITER_RELEASE_TIME,
124 V4L2_CID_AUDIO_LIMITER_DEVIATION,
125 V4L2_CID_AUDIO_COMPRESSION_ENABLED,
126 V4L2_CID_AUDIO_COMPRESSION_GAIN,
127 V4L2_CID_AUDIO_COMPRESSION_THRESHOLD,
128 V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME,
129 V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME,
130 V4L2_CID_PILOT_TONE_ENABLED,
131 V4L2_CID_PILOT_TONE_DEVIATION,
132 V4L2_CID_PILOT_TONE_FREQUENCY,
133 V4L2_CID_TUNE_PREEMPHASIS,
134 V4L2_CID_TUNE_POWER_LEVEL,
135 V4L2_CID_TUNE_ANTENNA_CAPACITOR,
136 0
137 };
138 static const u32 *ctrl_classes[] = {
139 user_ctrls,
140 fmtx_ctrls,
141 NULL
142 };
143 struct radio_si4713_device *rsdev;
144
145 rsdev = video_get_drvdata(video_devdata(file));
146
147 qc->id = v4l2_ctrl_next(ctrl_classes, qc->id);
148 if (qc->id == 0)
149 return -EINVAL;
150
151 if (qc->id == V4L2_CID_USER_CLASS || qc->id == V4L2_CID_FM_TX_CLASS)
152 return v4l2_ctrl_query_fill(qc, 0, 0, 0, 0);
153
154 return v4l2_device_call_until_err(&rsdev->v4l2_dev, 0, core,
155 queryctrl, qc);
156}
157
158/* 85/*
159 * v4l2 ioctl call backs. 86 * v4l2 ioctl call backs.
160 * we are just a wrapper for v4l2_sub_devs. 87 * we are just a wrapper for v4l2_sub_devs.
@@ -164,83 +91,50 @@ static inline struct v4l2_device *get_v4l2_dev(struct file *file)
164 return &((struct radio_si4713_device *)video_drvdata(file))->v4l2_dev; 91 return &((struct radio_si4713_device *)video_drvdata(file))->v4l2_dev;
165} 92}
166 93
167static int radio_si4713_g_ext_ctrls(struct file *file, void *p,
168 struct v4l2_ext_controls *vecs)
169{
170 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
171 g_ext_ctrls, vecs);
172}
173
174static int radio_si4713_s_ext_ctrls(struct file *file, void *p,
175 struct v4l2_ext_controls *vecs)
176{
177 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
178 s_ext_ctrls, vecs);
179}
180
181static int radio_si4713_g_ctrl(struct file *file, void *p,
182 struct v4l2_control *vc)
183{
184 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
185 g_ctrl, vc);
186}
187
188static int radio_si4713_s_ctrl(struct file *file, void *p,
189 struct v4l2_control *vc)
190{
191 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
192 s_ctrl, vc);
193}
194
195static int radio_si4713_g_modulator(struct file *file, void *p, 94static int radio_si4713_g_modulator(struct file *file, void *p,
196 struct v4l2_modulator *vm) 95 struct v4l2_modulator *vm)
197{ 96{
198 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner, 97 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
199 g_modulator, vm); 98 g_modulator, vm);
200} 99}
201 100
202static int radio_si4713_s_modulator(struct file *file, void *p, 101static int radio_si4713_s_modulator(struct file *file, void *p,
203 const struct v4l2_modulator *vm) 102 const struct v4l2_modulator *vm)
204{ 103{
205 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner, 104 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
206 s_modulator, vm); 105 s_modulator, vm);
207} 106}
208 107
209static int radio_si4713_g_frequency(struct file *file, void *p, 108static int radio_si4713_g_frequency(struct file *file, void *p,
210 struct v4l2_frequency *vf) 109 struct v4l2_frequency *vf)
211{ 110{
212 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner, 111 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
213 g_frequency, vf); 112 g_frequency, vf);
214} 113}
215 114
216static int radio_si4713_s_frequency(struct file *file, void *p, 115static int radio_si4713_s_frequency(struct file *file, void *p,
217 struct v4l2_frequency *vf) 116 const struct v4l2_frequency *vf)
218{ 117{
219 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner, 118 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
220 s_frequency, vf); 119 s_frequency, vf);
221} 120}
222 121
223static long radio_si4713_default(struct file *file, void *p, 122static long radio_si4713_default(struct file *file, void *p,
224 bool valid_prio, int cmd, void *arg) 123 bool valid_prio, unsigned int cmd, void *arg)
225{ 124{
226 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core, 125 return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
227 ioctl, cmd, arg); 126 ioctl, cmd, arg);
228} 127}
229 128
230static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = { 129static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
231 .vidioc_enumaudout = radio_si4713_enumaudout,
232 .vidioc_g_audout = radio_si4713_g_audout,
233 .vidioc_s_audout = radio_si4713_s_audout,
234 .vidioc_querycap = radio_si4713_querycap, 130 .vidioc_querycap = radio_si4713_querycap,
235 .vidioc_queryctrl = radio_si4713_queryctrl,
236 .vidioc_g_ext_ctrls = radio_si4713_g_ext_ctrls,
237 .vidioc_s_ext_ctrls = radio_si4713_s_ext_ctrls,
238 .vidioc_g_ctrl = radio_si4713_g_ctrl,
239 .vidioc_s_ctrl = radio_si4713_s_ctrl,
240 .vidioc_g_modulator = radio_si4713_g_modulator, 131 .vidioc_g_modulator = radio_si4713_g_modulator,
241 .vidioc_s_modulator = radio_si4713_s_modulator, 132 .vidioc_s_modulator = radio_si4713_s_modulator,
242 .vidioc_g_frequency = radio_si4713_g_frequency, 133 .vidioc_g_frequency = radio_si4713_g_frequency,
243 .vidioc_s_frequency = radio_si4713_s_frequency, 134 .vidioc_s_frequency = radio_si4713_s_frequency,
135 .vidioc_log_status = v4l2_ctrl_log_status,
136 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
137 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
244 .vidioc_default = radio_si4713_default, 138 .vidioc_default = radio_si4713_default,
245}; 139};
246 140
@@ -248,7 +142,7 @@ static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
248static struct video_device radio_si4713_vdev_template = { 142static struct video_device radio_si4713_vdev_template = {
249 .fops = &radio_si4713_fops, 143 .fops = &radio_si4713_fops,
250 .name = "radio-si4713", 144 .name = "radio-si4713",
251 .release = video_device_release, 145 .release = video_device_release_empty,
252 .ioctl_ops = &radio_si4713_ioctl_ops, 146 .ioctl_ops = &radio_si4713_ioctl_ops,
253 .vfl_dir = VFL_DIR_TX, 147 .vfl_dir = VFL_DIR_TX,
254}; 148};
@@ -275,6 +169,7 @@ static int radio_si4713_pdriver_probe(struct platform_device *pdev)
275 rval = -ENOMEM; 169 rval = -ENOMEM;
276 goto exit; 170 goto exit;
277 } 171 }
172 mutex_init(&rsdev->lock);
278 173
279 rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev); 174 rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev);
280 if (rval) { 175 if (rval) {
@@ -285,40 +180,35 @@ static int radio_si4713_pdriver_probe(struct platform_device *pdev)
285 adapter = i2c_get_adapter(pdata->i2c_bus); 180 adapter = i2c_get_adapter(pdata->i2c_bus);
286 if (!adapter) { 181 if (!adapter) {
287 dev_err(&pdev->dev, "Cannot get i2c adapter %d\n", 182 dev_err(&pdev->dev, "Cannot get i2c adapter %d\n",
288 pdata->i2c_bus); 183 pdata->i2c_bus);
289 rval = -ENODEV; 184 rval = -ENODEV;
290 goto unregister_v4l2_dev; 185 goto unregister_v4l2_dev;
291 } 186 }
292 187
293 sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter, 188 sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter,
294 pdata->subdev_board_info, NULL); 189 pdata->subdev_board_info, NULL);
295 if (!sd) { 190 if (!sd) {
296 dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n"); 191 dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n");
297 rval = -ENODEV; 192 rval = -ENODEV;
298 goto put_adapter; 193 goto put_adapter;
299 } 194 }
300 195
301 rsdev->radio_dev = video_device_alloc(); 196 rsdev->radio_dev = radio_si4713_vdev_template;
302 if (!rsdev->radio_dev) { 197 rsdev->radio_dev.v4l2_dev = &rsdev->v4l2_dev;
303 dev_err(&pdev->dev, "Failed to alloc video device.\n"); 198 rsdev->radio_dev.ctrl_handler = sd->ctrl_handler;
304 rval = -ENOMEM; 199 set_bit(V4L2_FL_USE_FH_PRIO, &rsdev->radio_dev.flags);
305 goto put_adapter; 200 /* Serialize all access to the si4713 */
306 } 201 rsdev->radio_dev.lock = &rsdev->lock;
307 202 video_set_drvdata(&rsdev->radio_dev, rsdev);
308 memcpy(rsdev->radio_dev, &radio_si4713_vdev_template, 203 if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
309 sizeof(radio_si4713_vdev_template));
310 video_set_drvdata(rsdev->radio_dev, rsdev);
311 if (video_register_device(rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
312 dev_err(&pdev->dev, "Could not register video device.\n"); 204 dev_err(&pdev->dev, "Could not register video device.\n");
313 rval = -EIO; 205 rval = -EIO;
314 goto free_vdev; 206 goto put_adapter;
315 } 207 }
316 dev_info(&pdev->dev, "New device successfully probed\n"); 208 dev_info(&pdev->dev, "New device successfully probed\n");
317 209
318 goto exit; 210 goto exit;
319 211
320free_vdev:
321 video_device_release(rsdev->radio_dev);
322put_adapter: 212put_adapter:
323 i2c_put_adapter(adapter); 213 i2c_put_adapter(adapter);
324unregister_v4l2_dev: 214unregister_v4l2_dev:
@@ -328,17 +218,16 @@ exit:
328} 218}
329 219
330/* radio_si4713_pdriver_remove - remove the device */ 220/* radio_si4713_pdriver_remove - remove the device */
331static int __exit radio_si4713_pdriver_remove(struct platform_device *pdev) 221static int radio_si4713_pdriver_remove(struct platform_device *pdev)
332{ 222{
333 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev); 223 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
334 struct radio_si4713_device *rsdev = container_of(v4l2_dev,
335 struct radio_si4713_device,
336 v4l2_dev);
337 struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next, 224 struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next,
338 struct v4l2_subdev, list); 225 struct v4l2_subdev, list);
339 struct i2c_client *client = v4l2_get_subdevdata(sd); 226 struct i2c_client *client = v4l2_get_subdevdata(sd);
227 struct radio_si4713_device *rsdev;
340 228
341 video_unregister_device(rsdev->radio_dev); 229 rsdev = container_of(v4l2_dev, struct radio_si4713_device, v4l2_dev);
230 video_unregister_device(&rsdev->radio_dev);
342 i2c_put_adapter(client->adapter); 231 i2c_put_adapter(client->adapter);
343 v4l2_device_unregister(&rsdev->v4l2_dev); 232 v4l2_device_unregister(&rsdev->v4l2_dev);
344 233
@@ -348,9 +237,10 @@ static int __exit radio_si4713_pdriver_remove(struct platform_device *pdev)
348static struct platform_driver radio_si4713_pdriver = { 237static struct platform_driver radio_si4713_pdriver = {
349 .driver = { 238 .driver = {
350 .name = "radio-si4713", 239 .name = "radio-si4713",
240 .owner = THIS_MODULE,
351 }, 241 },
352 .probe = radio_si4713_pdriver_probe, 242 .probe = radio_si4713_pdriver_probe,
353 .remove = __exit_p(radio_si4713_pdriver_remove), 243 .remove = radio_si4713_pdriver_remove,
354}; 244};
355 245
356module_platform_driver(radio_si4713_pdriver); 246module_platform_driver(radio_si4713_pdriver);
diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
new file mode 100644
index 000000000000..9430c6a29937
--- /dev/null
+++ b/drivers/media/radio/radio-si476x.c
@@ -0,0 +1,1599 @@
1/*
2 * drivers/media/radio/radio-si476x.c -- V4L2 driver for SI476X chips
3 *
4 * Copyright (C) 2012 Innovative Converged Devices(ICD)
5 * Copyright (C) 2013 Andrey Smirnov
6 *
7 * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/interrupt.h>
23#include <linux/slab.h>
24#include <linux/atomic.h>
25#include <linux/videodev2.h>
26#include <linux/mutex.h>
27#include <linux/debugfs.h>
28#include <media/v4l2-common.h>
29#include <media/v4l2-ioctl.h>
30#include <media/v4l2-ctrls.h>
31#include <media/v4l2-event.h>
32#include <media/v4l2-device.h>
33
34#include <media/si476x.h>
35#include <linux/mfd/si476x-core.h>
36
37#define FM_FREQ_RANGE_LOW 64000000
38#define FM_FREQ_RANGE_HIGH 108000000
39
40#define AM_FREQ_RANGE_LOW 520000
41#define AM_FREQ_RANGE_HIGH 30000000
42
43#define PWRLINEFLTR (1 << 8)
44
45#define FREQ_MUL (10000000 / 625)
46
47#define SI476X_PHDIV_STATUS_LINK_LOCKED(status) (0b10000000 & (status))
48
49#define DRIVER_NAME "si476x-radio"
50#define DRIVER_CARD "SI476x AM/FM Receiver"
51
52enum si476x_freq_bands {
53 SI476X_BAND_FM,
54 SI476X_BAND_AM,
55};
56
57static const struct v4l2_frequency_band si476x_bands[] = {
58 [SI476X_BAND_FM] = {
59 .type = V4L2_TUNER_RADIO,
60 .index = SI476X_BAND_FM,
61 .capability = V4L2_TUNER_CAP_LOW
62 | V4L2_TUNER_CAP_STEREO
63 | V4L2_TUNER_CAP_RDS
64 | V4L2_TUNER_CAP_RDS_BLOCK_IO
65 | V4L2_TUNER_CAP_FREQ_BANDS,
66 .rangelow = 64 * FREQ_MUL,
67 .rangehigh = 108 * FREQ_MUL,
68 .modulation = V4L2_BAND_MODULATION_FM,
69 },
70 [SI476X_BAND_AM] = {
71 .type = V4L2_TUNER_RADIO,
72 .index = SI476X_BAND_AM,
73 .capability = V4L2_TUNER_CAP_LOW
74 | V4L2_TUNER_CAP_FREQ_BANDS,
75 .rangelow = 0.52 * FREQ_MUL,
76 .rangehigh = 30 * FREQ_MUL,
77 .modulation = V4L2_BAND_MODULATION_AM,
78 },
79};
80
81static inline bool si476x_radio_freq_is_inside_of_the_band(u32 freq, int band)
82{
83 return freq >= si476x_bands[band].rangelow &&
84 freq <= si476x_bands[band].rangehigh;
85}
86
87static inline bool si476x_radio_range_is_inside_of_the_band(u32 low, u32 high,
88 int band)
89{
90 return low >= si476x_bands[band].rangelow &&
91 high <= si476x_bands[band].rangehigh;
92}
93
94static int si476x_radio_s_ctrl(struct v4l2_ctrl *ctrl);
95static int si476x_radio_g_volatile_ctrl(struct v4l2_ctrl *ctrl);
96
97enum phase_diversity_modes_idx {
98 SI476X_IDX_PHDIV_DISABLED,
99 SI476X_IDX_PHDIV_PRIMARY_COMBINING,
100 SI476X_IDX_PHDIV_PRIMARY_ANTENNA,
101 SI476X_IDX_PHDIV_SECONDARY_ANTENNA,
102 SI476X_IDX_PHDIV_SECONDARY_COMBINING,
103};
104
105static const char * const phase_diversity_modes[] = {
106 [SI476X_IDX_PHDIV_DISABLED] = "Disabled",
107 [SI476X_IDX_PHDIV_PRIMARY_COMBINING] = "Primary with Secondary",
108 [SI476X_IDX_PHDIV_PRIMARY_ANTENNA] = "Primary Antenna",
109 [SI476X_IDX_PHDIV_SECONDARY_ANTENNA] = "Secondary Antenna",
110 [SI476X_IDX_PHDIV_SECONDARY_COMBINING] = "Secondary with Primary",
111};
112
113static inline enum phase_diversity_modes_idx
114si476x_phase_diversity_mode_to_idx(enum si476x_phase_diversity_mode mode)
115{
116 switch (mode) {
117 default: /* FALLTHROUGH */
118 case SI476X_PHDIV_DISABLED:
119 return SI476X_IDX_PHDIV_DISABLED;
120 case SI476X_PHDIV_PRIMARY_COMBINING:
121 return SI476X_IDX_PHDIV_PRIMARY_COMBINING;
122 case SI476X_PHDIV_PRIMARY_ANTENNA:
123 return SI476X_IDX_PHDIV_PRIMARY_ANTENNA;
124 case SI476X_PHDIV_SECONDARY_ANTENNA:
125 return SI476X_IDX_PHDIV_SECONDARY_ANTENNA;
126 case SI476X_PHDIV_SECONDARY_COMBINING:
127 return SI476X_IDX_PHDIV_SECONDARY_COMBINING;
128 }
129}
130
131static inline enum si476x_phase_diversity_mode
132si476x_phase_diversity_idx_to_mode(enum phase_diversity_modes_idx idx)
133{
134 static const int idx_to_value[] = {
135 [SI476X_IDX_PHDIV_DISABLED] = SI476X_PHDIV_DISABLED,
136 [SI476X_IDX_PHDIV_PRIMARY_COMBINING] = SI476X_PHDIV_PRIMARY_COMBINING,
137 [SI476X_IDX_PHDIV_PRIMARY_ANTENNA] = SI476X_PHDIV_PRIMARY_ANTENNA,
138 [SI476X_IDX_PHDIV_SECONDARY_ANTENNA] = SI476X_PHDIV_SECONDARY_ANTENNA,
139 [SI476X_IDX_PHDIV_SECONDARY_COMBINING] = SI476X_PHDIV_SECONDARY_COMBINING,
140 };
141
142 return idx_to_value[idx];
143}
144
145static const struct v4l2_ctrl_ops si476x_ctrl_ops = {
146 .g_volatile_ctrl = si476x_radio_g_volatile_ctrl,
147 .s_ctrl = si476x_radio_s_ctrl,
148};
149
150
151enum si476x_ctrl_idx {
152 SI476X_IDX_RSSI_THRESHOLD,
153 SI476X_IDX_SNR_THRESHOLD,
154 SI476X_IDX_MAX_TUNE_ERROR,
155 SI476X_IDX_HARMONICS_COUNT,
156 SI476X_IDX_DIVERSITY_MODE,
157 SI476X_IDX_INTERCHIP_LINK,
158};
159static struct v4l2_ctrl_config si476x_ctrls[] = {
160
161 /**
162 * SI476X during its station seeking(or tuning) process uses several
163 * parameters to detrmine if "the station" is valid:
164 *
165 * - Signal's SNR(in dBuV) must be lower than
166 * #V4L2_CID_SI476X_SNR_THRESHOLD
167 * - Signal's RSSI(in dBuV) must be greater than
168 * #V4L2_CID_SI476X_RSSI_THRESHOLD
169 * - Signal's frequency deviation(in units of 2ppm) must not be
170 * more than #V4L2_CID_SI476X_MAX_TUNE_ERROR
171 */
172 [SI476X_IDX_RSSI_THRESHOLD] = {
173 .ops = &si476x_ctrl_ops,
174 .id = V4L2_CID_SI476X_RSSI_THRESHOLD,
175 .name = "Valid RSSI Threshold",
176 .type = V4L2_CTRL_TYPE_INTEGER,
177 .min = -128,
178 .max = 127,
179 .step = 1,
180 },
181 [SI476X_IDX_SNR_THRESHOLD] = {
182 .ops = &si476x_ctrl_ops,
183 .id = V4L2_CID_SI476X_SNR_THRESHOLD,
184 .type = V4L2_CTRL_TYPE_INTEGER,
185 .name = "Valid SNR Threshold",
186 .min = -128,
187 .max = 127,
188 .step = 1,
189 },
190 [SI476X_IDX_MAX_TUNE_ERROR] = {
191 .ops = &si476x_ctrl_ops,
192 .id = V4L2_CID_SI476X_MAX_TUNE_ERROR,
193 .type = V4L2_CTRL_TYPE_INTEGER,
194 .name = "Max Tune Errors",
195 .min = 0,
196 .max = 126 * 2,
197 .step = 2,
198 },
199
200 /**
201 * #V4L2_CID_SI476X_HARMONICS_COUNT -- number of harmonics
202 * built-in power-line noise supression filter is to reject
203 * during AM-mode operation.
204 */
205 [SI476X_IDX_HARMONICS_COUNT] = {
206 .ops = &si476x_ctrl_ops,
207 .id = V4L2_CID_SI476X_HARMONICS_COUNT,
208 .type = V4L2_CTRL_TYPE_INTEGER,
209
210 .name = "Count of Harmonics to Reject",
211 .min = 0,
212 .max = 20,
213 .step = 1,
214 },
215
216 /**
217 * #V4L2_CID_SI476X_DIVERSITY_MODE -- configuration which
218 * two tuners working in diversity mode are to work in.
219 *
220 * - #SI476X_IDX_PHDIV_DISABLED diversity mode disabled
221 * - #SI476X_IDX_PHDIV_PRIMARY_COMBINING diversity mode is
222 * on, primary tuner's antenna is the main one.
223 * - #SI476X_IDX_PHDIV_PRIMARY_ANTENNA diversity mode is
224 * off, primary tuner's antenna is the main one.
225 * - #SI476X_IDX_PHDIV_SECONDARY_ANTENNA diversity mode is
226 * off, secondary tuner's antenna is the main one.
227 * - #SI476X_IDX_PHDIV_SECONDARY_COMBINING diversity mode is
228 * on, secondary tuner's antenna is the main one.
229 */
230 [SI476X_IDX_DIVERSITY_MODE] = {
231 .ops = &si476x_ctrl_ops,
232 .id = V4L2_CID_SI476X_DIVERSITY_MODE,
233 .type = V4L2_CTRL_TYPE_MENU,
234 .name = "Phase Diversity Mode",
235 .qmenu = phase_diversity_modes,
236 .min = 0,
237 .max = ARRAY_SIZE(phase_diversity_modes) - 1,
238 },
239
240 /**
241 * #V4L2_CID_SI476X_INTERCHIP_LINK -- inter-chip link in
242 * diversity mode indicator. Allows user to determine if two
243 * chips working in diversity mode have established a link
244 * between each other and if the system as a whole uses
245 * signals from both antennas to receive FM radio.
246 */
247 [SI476X_IDX_INTERCHIP_LINK] = {
248 .ops = &si476x_ctrl_ops,
249 .id = V4L2_CID_SI476X_INTERCHIP_LINK,
250 .type = V4L2_CTRL_TYPE_BOOLEAN,
251 .flags = V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_VOLATILE,
252 .name = "Inter-Chip Link",
253 .min = 0,
254 .max = 1,
255 .step = 1,
256 },
257};
258
259struct si476x_radio;
260
261/**
262 * struct si476x_radio_ops - vtable of tuner functions
263 *
264 * This table holds pointers to functions implementing particular
265 * operations depending on the mode in which the tuner chip was
266 * configured to start in. If the function is not supported
267 * corresponding element is set to #NULL.
268 *
269 * @tune_freq: Tune chip to a specific frequency
270 * @seek_start: Star station seeking
271 * @rsq_status: Get Recieved Signal Quality(RSQ) status
272 * @rds_blckcnt: Get recived RDS blocks count
273 * @phase_diversity: Change phase diversity mode of the tuner
274 * @phase_div_status: Get phase diversity mode status
275 * @acf_status: Get the status of Automatically Controlled
276 * Features(ACF)
277 * @agc_status: Get Automatic Gain Control(AGC) status
278 */
279struct si476x_radio_ops {
280 int (*tune_freq)(struct si476x_core *, struct si476x_tune_freq_args *);
281 int (*seek_start)(struct si476x_core *, bool, bool);
282 int (*rsq_status)(struct si476x_core *, struct si476x_rsq_status_args *,
283 struct si476x_rsq_status_report *);
284 int (*rds_blckcnt)(struct si476x_core *, bool,
285 struct si476x_rds_blockcount_report *);
286
287 int (*phase_diversity)(struct si476x_core *,
288 enum si476x_phase_diversity_mode);
289 int (*phase_div_status)(struct si476x_core *);
290 int (*acf_status)(struct si476x_core *,
291 struct si476x_acf_status_report *);
292 int (*agc_status)(struct si476x_core *,
293 struct si476x_agc_status_report *);
294};
295
296/**
297 * struct si476x_radio - radio device
298 *
299 * @core: Pointer to underlying core device
300 * @videodev: Pointer to video device created by V4L2 subsystem
301 * @ops: Vtable of functions. See struct si476x_radio_ops for details
302 * @kref: Reference counter
303 * @core_lock: An r/w semaphore to brebvent the deletion of underlying
304 * core structure is the radio device is being used
305 */
306struct si476x_radio {
307 struct v4l2_device v4l2dev;
308 struct video_device videodev;
309 struct v4l2_ctrl_handler ctrl_handler;
310
311 struct si476x_core *core;
312 /* This field should not be accesses unless core lock is held */
313 const struct si476x_radio_ops *ops;
314
315 struct dentry *debugfs;
316 u32 audmode;
317};
318
319static inline struct si476x_radio *
320v4l2_dev_to_radio(struct v4l2_device *d)
321{
322 return container_of(d, struct si476x_radio, v4l2dev);
323}
324
325static inline struct si476x_radio *
326v4l2_ctrl_handler_to_radio(struct v4l2_ctrl_handler *d)
327{
328 return container_of(d, struct si476x_radio, ctrl_handler);
329}
330
331/*
332 * si476x_vidioc_querycap - query device capabilities
333 */
334static int si476x_radio_querycap(struct file *file, void *priv,
335 struct v4l2_capability *capability)
336{
337 struct si476x_radio *radio = video_drvdata(file);
338
339 strlcpy(capability->driver, radio->v4l2dev.name,
340 sizeof(capability->driver));
341 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
342 snprintf(capability->bus_info, sizeof(capability->bus_info),
343 "platform:%s", radio->v4l2dev.name);
344
345 capability->device_caps = V4L2_CAP_TUNER
346 | V4L2_CAP_RADIO
347 | V4L2_CAP_HW_FREQ_SEEK;
348
349 si476x_core_lock(radio->core);
350 if (!si476x_core_is_a_secondary_tuner(radio->core))
351 capability->device_caps |= V4L2_CAP_RDS_CAPTURE
352 | V4L2_CAP_READWRITE;
353 si476x_core_unlock(radio->core);
354
355 capability->capabilities = capability->device_caps
356 | V4L2_CAP_DEVICE_CAPS;
357 return 0;
358}
359
360static int si476x_radio_enum_freq_bands(struct file *file, void *priv,
361 struct v4l2_frequency_band *band)
362{
363 int err;
364 struct si476x_radio *radio = video_drvdata(file);
365
366 if (band->tuner != 0)
367 return -EINVAL;
368
369 switch (radio->core->chip_id) {
370 /* AM/FM tuners -- all bands are supported */
371 case SI476X_CHIP_SI4761:
372 case SI476X_CHIP_SI4764:
373 if (band->index < ARRAY_SIZE(si476x_bands)) {
374 *band = si476x_bands[band->index];
375 err = 0;
376 } else {
377 err = -EINVAL;
378 }
379 break;
380 /* FM companion tuner chips -- only FM bands are
381 * supported */
382 case SI476X_CHIP_SI4768:
383 if (band->index == SI476X_BAND_FM) {
384 *band = si476x_bands[band->index];
385 err = 0;
386 } else {
387 err = -EINVAL;
388 }
389 break;
390 default:
391 err = -EINVAL;
392 }
393
394 return err;
395}
396
397static int si476x_radio_g_tuner(struct file *file, void *priv,
398 struct v4l2_tuner *tuner)
399{
400 int err;
401 struct si476x_rsq_status_report report;
402 struct si476x_radio *radio = video_drvdata(file);
403
404 struct si476x_rsq_status_args args = {
405 .primary = false,
406 .rsqack = false,
407 .attune = false,
408 .cancel = false,
409 .stcack = false,
410 };
411
412 if (tuner->index != 0)
413 return -EINVAL;
414
415 tuner->type = V4L2_TUNER_RADIO;
416 tuner->capability = V4L2_TUNER_CAP_LOW /* Measure frequencies
417 * in multiples of
418 * 62.5 Hz */
419 | V4L2_TUNER_CAP_STEREO
420 | V4L2_TUNER_CAP_HWSEEK_BOUNDED
421 | V4L2_TUNER_CAP_HWSEEK_WRAP
422 | V4L2_TUNER_CAP_HWSEEK_PROG_LIM;
423
424 si476x_core_lock(radio->core);
425
426 if (si476x_core_is_a_secondary_tuner(radio->core)) {
427 strlcpy(tuner->name, "FM (secondary)", sizeof(tuner->name));
428 tuner->rxsubchans = 0;
429 tuner->rangelow = si476x_bands[SI476X_BAND_FM].rangelow;
430 } else if (si476x_core_has_am(radio->core)) {
431 if (si476x_core_is_a_primary_tuner(radio->core))
432 strlcpy(tuner->name, "AM/FM (primary)",
433 sizeof(tuner->name));
434 else
435 strlcpy(tuner->name, "AM/FM", sizeof(tuner->name));
436
437 tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO
438 | V4L2_TUNER_SUB_RDS;
439 tuner->capability |= V4L2_TUNER_CAP_RDS
440 | V4L2_TUNER_CAP_RDS_BLOCK_IO
441 | V4L2_TUNER_CAP_FREQ_BANDS;
442
443 tuner->rangelow = si476x_bands[SI476X_BAND_AM].rangelow;
444 } else {
445 strlcpy(tuner->name, "FM", sizeof(tuner->name));
446 tuner->rxsubchans = V4L2_TUNER_SUB_RDS;
447 tuner->capability |= V4L2_TUNER_CAP_RDS
448 | V4L2_TUNER_CAP_RDS_BLOCK_IO
449 | V4L2_TUNER_CAP_FREQ_BANDS;
450 tuner->rangelow = si476x_bands[SI476X_BAND_FM].rangelow;
451 }
452
453 tuner->audmode = radio->audmode;
454
455 tuner->afc = 1;
456 tuner->rangehigh = si476x_bands[SI476X_BAND_FM].rangehigh;
457
458 err = radio->ops->rsq_status(radio->core,
459 &args, &report);
460 if (err < 0) {
461 tuner->signal = 0;
462 } else {
463 /*
464 * tuner->signal value range: 0x0000 .. 0xFFFF,
465 * report.rssi: -128 .. 127
466 */
467 tuner->signal = (report.rssi + 128) * 257;
468 }
469 si476x_core_unlock(radio->core);
470
471 return err;
472}
473
474static int si476x_radio_s_tuner(struct file *file, void *priv,
475 const struct v4l2_tuner *tuner)
476{
477 struct si476x_radio *radio = video_drvdata(file);
478
479 if (tuner->index != 0)
480 return -EINVAL;
481
482 if (tuner->audmode == V4L2_TUNER_MODE_MONO ||
483 tuner->audmode == V4L2_TUNER_MODE_STEREO)
484 radio->audmode = tuner->audmode;
485 else
486 radio->audmode = V4L2_TUNER_MODE_STEREO;
487
488 return 0;
489}
490
491static int si476x_radio_init_vtable(struct si476x_radio *radio,
492 enum si476x_func func)
493{
494 static const struct si476x_radio_ops fm_ops = {
495 .tune_freq = si476x_core_cmd_fm_tune_freq,
496 .seek_start = si476x_core_cmd_fm_seek_start,
497 .rsq_status = si476x_core_cmd_fm_rsq_status,
498 .rds_blckcnt = si476x_core_cmd_fm_rds_blockcount,
499 .phase_diversity = si476x_core_cmd_fm_phase_diversity,
500 .phase_div_status = si476x_core_cmd_fm_phase_div_status,
501 .acf_status = si476x_core_cmd_fm_acf_status,
502 .agc_status = si476x_core_cmd_agc_status,
503 };
504
505 static const struct si476x_radio_ops am_ops = {
506 .tune_freq = si476x_core_cmd_am_tune_freq,
507 .seek_start = si476x_core_cmd_am_seek_start,
508 .rsq_status = si476x_core_cmd_am_rsq_status,
509 .rds_blckcnt = NULL,
510 .phase_diversity = NULL,
511 .phase_div_status = NULL,
512 .acf_status = si476x_core_cmd_am_acf_status,
513 .agc_status = NULL,
514 };
515
516 switch (func) {
517 case SI476X_FUNC_FM_RECEIVER:
518 radio->ops = &fm_ops;
519 return 0;
520
521 case SI476X_FUNC_AM_RECEIVER:
522 radio->ops = &am_ops;
523 return 0;
524 default:
525 WARN(1, "Unexpected tuner function value\n");
526 return -EINVAL;
527 }
528}
529
530static int si476x_radio_pretune(struct si476x_radio *radio,
531 enum si476x_func func)
532{
533 int retval;
534
535 struct si476x_tune_freq_args args = {
536 .zifsr = false,
537 .hd = false,
538 .injside = SI476X_INJSIDE_AUTO,
539 .tunemode = SI476X_TM_VALIDATED_NORMAL_TUNE,
540 .smoothmetrics = SI476X_SM_INITIALIZE_AUDIO,
541 .antcap = 0,
542 };
543
544 switch (func) {
545 case SI476X_FUNC_FM_RECEIVER:
546 args.freq = v4l2_to_si476x(radio->core,
547 92 * FREQ_MUL);
548 retval = radio->ops->tune_freq(radio->core, &args);
549 break;
550 case SI476X_FUNC_AM_RECEIVER:
551 args.freq = v4l2_to_si476x(radio->core,
552 0.6 * FREQ_MUL);
553 retval = radio->ops->tune_freq(radio->core, &args);
554 break;
555 default:
556 WARN(1, "Unexpected tuner function value\n");
557 retval = -EINVAL;
558 }
559
560 return retval;
561}
562static int si476x_radio_do_post_powerup_init(struct si476x_radio *radio,
563 enum si476x_func func)
564{
565 int err;
566
567 /* regcache_mark_dirty(radio->core->regmap); */
568 err = regcache_sync_region(radio->core->regmap,
569 SI476X_PROP_DIGITAL_IO_INPUT_SAMPLE_RATE,
570 SI476X_PROP_DIGITAL_IO_OUTPUT_FORMAT);
571 if (err < 0)
572 return err;
573
574 err = regcache_sync_region(radio->core->regmap,
575 SI476X_PROP_AUDIO_DEEMPHASIS,
576 SI476X_PROP_AUDIO_PWR_LINE_FILTER);
577 if (err < 0)
578 return err;
579
580 err = regcache_sync_region(radio->core->regmap,
581 SI476X_PROP_INT_CTL_ENABLE,
582 SI476X_PROP_INT_CTL_ENABLE);
583 if (err < 0)
584 return err;
585
586 /*
587 * Is there any point in restoring SNR and the like
588 * when switching between AM/FM?
589 */
590 err = regcache_sync_region(radio->core->regmap,
591 SI476X_PROP_VALID_MAX_TUNE_ERROR,
592 SI476X_PROP_VALID_MAX_TUNE_ERROR);
593 if (err < 0)
594 return err;
595
596 err = regcache_sync_region(radio->core->regmap,
597 SI476X_PROP_VALID_SNR_THRESHOLD,
598 SI476X_PROP_VALID_RSSI_THRESHOLD);
599 if (err < 0)
600 return err;
601
602 if (func == SI476X_FUNC_FM_RECEIVER) {
603 if (si476x_core_has_diversity(radio->core)) {
604 err = si476x_core_cmd_fm_phase_diversity(radio->core,
605 radio->core->diversity_mode);
606 if (err < 0)
607 return err;
608 }
609
610 err = regcache_sync_region(radio->core->regmap,
611 SI476X_PROP_FM_RDS_INTERRUPT_SOURCE,
612 SI476X_PROP_FM_RDS_CONFIG);
613 if (err < 0)
614 return err;
615 }
616
617 return si476x_radio_init_vtable(radio, func);
618
619}
620
621static int si476x_radio_change_func(struct si476x_radio *radio,
622 enum si476x_func func)
623{
624 int err;
625 bool soft;
626 /*
627 * Since power/up down is a very time consuming operation,
628 * try to avoid doing it if the requested mode matches the one
629 * the tuner is in
630 */
631 if (func == radio->core->power_up_parameters.func)
632 return 0;
633
634 soft = true;
635 err = si476x_core_stop(radio->core, soft);
636 if (err < 0) {
637 /*
638 * OK, if the chip does not want to play nice let's
639 * try to reset it in more brutal way
640 */
641 soft = false;
642 err = si476x_core_stop(radio->core, soft);
643 if (err < 0)
644 return err;
645 }
646 /*
647 Set the desired radio tuner function
648 */
649 radio->core->power_up_parameters.func = func;
650
651 err = si476x_core_start(radio->core, soft);
652 if (err < 0)
653 return err;
654
655 /*
656 * No need to do the rest of manipulations for the bootlader
657 * mode
658 */
659 if (func != SI476X_FUNC_FM_RECEIVER &&
660 func != SI476X_FUNC_AM_RECEIVER)
661 return err;
662
663 return si476x_radio_do_post_powerup_init(radio, func);
664}
665
666static int si476x_radio_g_frequency(struct file *file, void *priv,
667 struct v4l2_frequency *f)
668{
669 int err;
670 struct si476x_radio *radio = video_drvdata(file);
671
672 if (f->tuner != 0 ||
673 f->type != V4L2_TUNER_RADIO)
674 return -EINVAL;
675
676 si476x_core_lock(radio->core);
677
678 if (radio->ops->rsq_status) {
679 struct si476x_rsq_status_report report;
680 struct si476x_rsq_status_args args = {
681 .primary = false,
682 .rsqack = false,
683 .attune = true,
684 .cancel = false,
685 .stcack = false,
686 };
687
688 err = radio->ops->rsq_status(radio->core, &args, &report);
689 if (!err)
690 f->frequency = si476x_to_v4l2(radio->core,
691 report.readfreq);
692 } else {
693 err = -EINVAL;
694 }
695
696 si476x_core_unlock(radio->core);
697
698 return err;
699}
700
701static int si476x_radio_s_frequency(struct file *file, void *priv,
702 const struct v4l2_frequency *f)
703{
704 int err;
705 u32 freq = f->frequency;
706 struct si476x_tune_freq_args args;
707 struct si476x_radio *radio = video_drvdata(file);
708
709 const u32 midrange = (si476x_bands[SI476X_BAND_AM].rangehigh +
710 si476x_bands[SI476X_BAND_FM].rangelow) / 2;
711 const int band = (freq > midrange) ?
712 SI476X_BAND_FM : SI476X_BAND_AM;
713 const enum si476x_func func = (band == SI476X_BAND_AM) ?
714 SI476X_FUNC_AM_RECEIVER : SI476X_FUNC_FM_RECEIVER;
715
716 if (f->tuner != 0 ||
717 f->type != V4L2_TUNER_RADIO)
718 return -EINVAL;
719
720 si476x_core_lock(radio->core);
721
722 freq = clamp(freq,
723 si476x_bands[band].rangelow,
724 si476x_bands[band].rangehigh);
725
726 if (si476x_radio_freq_is_inside_of_the_band(freq,
727 SI476X_BAND_AM) &&
728 (!si476x_core_has_am(radio->core) ||
729 si476x_core_is_a_secondary_tuner(radio->core))) {
730 err = -EINVAL;
731 goto unlock;
732 }
733
734 err = si476x_radio_change_func(radio, func);
735 if (err < 0)
736 goto unlock;
737
738 args.zifsr = false;
739 args.hd = false;
740 args.injside = SI476X_INJSIDE_AUTO;
741 args.freq = v4l2_to_si476x(radio->core, freq);
742 args.tunemode = SI476X_TM_VALIDATED_NORMAL_TUNE;
743 args.smoothmetrics = SI476X_SM_INITIALIZE_AUDIO;
744 args.antcap = 0;
745
746 err = radio->ops->tune_freq(radio->core, &args);
747
748unlock:
749 si476x_core_unlock(radio->core);
750 return err;
751}
752
753static int si476x_radio_s_hw_freq_seek(struct file *file, void *priv,
754 const struct v4l2_hw_freq_seek *seek)
755{
756 int err;
757 enum si476x_func func;
758 u32 rangelow, rangehigh;
759 struct si476x_radio *radio = video_drvdata(file);
760
761 if (file->f_flags & O_NONBLOCK)
762 return -EAGAIN;
763
764 if (seek->tuner != 0 ||
765 seek->type != V4L2_TUNER_RADIO)
766 return -EINVAL;
767
768 si476x_core_lock(radio->core);
769
770 if (!seek->rangelow) {
771 err = regmap_read(radio->core->regmap,
772 SI476X_PROP_SEEK_BAND_BOTTOM,
773 &rangelow);
774 if (!err)
775 rangelow = si476x_to_v4l2(radio->core, rangelow);
776 else
777 goto unlock;
778 }
779 if (!seek->rangehigh) {
780 err = regmap_read(radio->core->regmap,
781 SI476X_PROP_SEEK_BAND_TOP,
782 &rangehigh);
783 if (!err)
784 rangehigh = si476x_to_v4l2(radio->core, rangehigh);
785 else
786 goto unlock;
787 }
788
789 if (rangelow > rangehigh) {
790 err = -EINVAL;
791 goto unlock;
792 }
793
794 if (si476x_radio_range_is_inside_of_the_band(rangelow, rangehigh,
795 SI476X_BAND_FM)) {
796 func = SI476X_FUNC_FM_RECEIVER;
797
798 } else if (si476x_core_has_am(radio->core) &&
799 si476x_radio_range_is_inside_of_the_band(rangelow, rangehigh,
800 SI476X_BAND_AM)) {
801 func = SI476X_FUNC_AM_RECEIVER;
802 } else {
803 err = -EINVAL;
804 goto unlock;
805 }
806
807 err = si476x_radio_change_func(radio, func);
808 if (err < 0)
809 goto unlock;
810
811 if (seek->rangehigh) {
812 err = regmap_write(radio->core->regmap,
813 SI476X_PROP_SEEK_BAND_TOP,
814 v4l2_to_si476x(radio->core,
815 seek->rangehigh));
816 if (err)
817 goto unlock;
818 }
819 if (seek->rangelow) {
820 err = regmap_write(radio->core->regmap,
821 SI476X_PROP_SEEK_BAND_BOTTOM,
822 v4l2_to_si476x(radio->core,
823 seek->rangelow));
824 if (err)
825 goto unlock;
826 }
827 if (seek->spacing) {
828 err = regmap_write(radio->core->regmap,
829 SI476X_PROP_SEEK_FREQUENCY_SPACING,
830 v4l2_to_si476x(radio->core,
831 seek->spacing));
832 if (err)
833 goto unlock;
834 }
835
836 err = radio->ops->seek_start(radio->core,
837 seek->seek_upward,
838 seek->wrap_around);
839unlock:
840 si476x_core_unlock(radio->core);
841
842
843
844 return err;
845}
846
847static int si476x_radio_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
848{
849 int retval;
850 struct si476x_radio *radio = v4l2_ctrl_handler_to_radio(ctrl->handler);
851
852 si476x_core_lock(radio->core);
853
854 switch (ctrl->id) {
855 case V4L2_CID_SI476X_INTERCHIP_LINK:
856 if (si476x_core_has_diversity(radio->core)) {
857 if (radio->ops->phase_diversity) {
858 retval = radio->ops->phase_div_status(radio->core);
859 if (retval < 0)
860 break;
861
862 ctrl->val = !!SI476X_PHDIV_STATUS_LINK_LOCKED(retval);
863 retval = 0;
864 break;
865 } else {
866 retval = -ENOTTY;
867 break;
868 }
869 }
870 retval = -EINVAL;
871 break;
872 default:
873 retval = -EINVAL;
874 break;
875 }
876 si476x_core_unlock(radio->core);
877 return retval;
878
879}
880
881static int si476x_radio_s_ctrl(struct v4l2_ctrl *ctrl)
882{
883 int retval;
884 enum si476x_phase_diversity_mode mode;
885 struct si476x_radio *radio = v4l2_ctrl_handler_to_radio(ctrl->handler);
886
887 si476x_core_lock(radio->core);
888
889 switch (ctrl->id) {
890 case V4L2_CID_SI476X_HARMONICS_COUNT:
891 retval = regmap_update_bits(radio->core->regmap,
892 SI476X_PROP_AUDIO_PWR_LINE_FILTER,
893 SI476X_PROP_PWR_HARMONICS_MASK,
894 ctrl->val);
895 break;
896 case V4L2_CID_POWER_LINE_FREQUENCY:
897 switch (ctrl->val) {
898 case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
899 retval = regmap_update_bits(radio->core->regmap,
900 SI476X_PROP_AUDIO_PWR_LINE_FILTER,
901 SI476X_PROP_PWR_ENABLE_MASK,
902 0);
903 break;
904 case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
905 retval = regmap_update_bits(radio->core->regmap,
906 SI476X_PROP_AUDIO_PWR_LINE_FILTER,
907 SI476X_PROP_PWR_GRID_MASK,
908 SI476X_PROP_PWR_GRID_50HZ);
909 break;
910 case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
911 retval = regmap_update_bits(radio->core->regmap,
912 SI476X_PROP_AUDIO_PWR_LINE_FILTER,
913 SI476X_PROP_PWR_GRID_MASK,
914 SI476X_PROP_PWR_GRID_60HZ);
915 break;
916 default:
917 retval = -EINVAL;
918 break;
919 }
920 break;
921 case V4L2_CID_SI476X_RSSI_THRESHOLD:
922 retval = regmap_write(radio->core->regmap,
923 SI476X_PROP_VALID_RSSI_THRESHOLD,
924 ctrl->val);
925 break;
926 case V4L2_CID_SI476X_SNR_THRESHOLD:
927 retval = regmap_write(radio->core->regmap,
928 SI476X_PROP_VALID_SNR_THRESHOLD,
929 ctrl->val);
930 break;
931 case V4L2_CID_SI476X_MAX_TUNE_ERROR:
932 retval = regmap_write(radio->core->regmap,
933 SI476X_PROP_VALID_MAX_TUNE_ERROR,
934 ctrl->val);
935 break;
936 case V4L2_CID_RDS_RECEPTION:
937 /*
938 * It looks like RDS related properties are
939 * inaccesable when tuner is in AM mode, so cache the
940 * changes
941 */
942 if (si476x_core_is_in_am_receiver_mode(radio->core))
943 regcache_cache_only(radio->core->regmap, true);
944
945 if (ctrl->val) {
946 retval = regmap_write(radio->core->regmap,
947 SI476X_PROP_FM_RDS_INTERRUPT_FIFO_COUNT,
948 radio->core->rds_fifo_depth);
949 if (retval < 0)
950 break;
951
952 if (radio->core->client->irq) {
953 retval = regmap_write(radio->core->regmap,
954 SI476X_PROP_FM_RDS_INTERRUPT_SOURCE,
955 SI476X_RDSRECV);
956 if (retval < 0)
957 break;
958 }
959
960 /* Drain RDS FIFO before enabling RDS processing */
961 retval = si476x_core_cmd_fm_rds_status(radio->core,
962 false,
963 true,
964 true,
965 NULL);
966 if (retval < 0)
967 break;
968
969 retval = regmap_update_bits(radio->core->regmap,
970 SI476X_PROP_FM_RDS_CONFIG,
971 SI476X_PROP_RDSEN_MASK,
972 SI476X_PROP_RDSEN);
973 } else {
974 retval = regmap_update_bits(radio->core->regmap,
975 SI476X_PROP_FM_RDS_CONFIG,
976 SI476X_PROP_RDSEN_MASK,
977 !SI476X_PROP_RDSEN);
978 }
979
980 if (si476x_core_is_in_am_receiver_mode(radio->core))
981 regcache_cache_only(radio->core->regmap, false);
982 break;
983 case V4L2_CID_TUNE_DEEMPHASIS:
984 retval = regmap_write(radio->core->regmap,
985 SI476X_PROP_AUDIO_DEEMPHASIS,
986 ctrl->val);
987 break;
988
989 case V4L2_CID_SI476X_DIVERSITY_MODE:
990 mode = si476x_phase_diversity_idx_to_mode(ctrl->val);
991
992 if (mode == radio->core->diversity_mode) {
993 retval = 0;
994 break;
995 }
996
997 if (si476x_core_is_in_am_receiver_mode(radio->core)) {
998 /*
999 * Diversity cannot be configured while tuner
1000 * is in AM mode so save the changes and carry on.
1001 */
1002 radio->core->diversity_mode = mode;
1003 retval = 0;
1004 } else {
1005 retval = radio->ops->phase_diversity(radio->core, mode);
1006 if (!retval)
1007 radio->core->diversity_mode = mode;
1008 }
1009 break;
1010
1011 default:
1012 retval = -EINVAL;
1013 break;
1014 }
1015
1016 si476x_core_unlock(radio->core);
1017
1018 return retval;
1019}
1020
1021static int si476x_radio_g_chip_ident(struct file *file, void *fh,
1022 struct v4l2_dbg_chip_ident *chip)
1023{
1024 if (chip->match.type == V4L2_CHIP_MATCH_HOST &&
1025 v4l2_chip_match_host(&chip->match))
1026 return 0;
1027 return -EINVAL;
1028}
1029
1030
1031#ifdef CONFIG_VIDEO_ADV_DEBUG
1032static int si476x_radio_g_register(struct file *file, void *fh,
1033 struct v4l2_dbg_register *reg)
1034{
1035 int err;
1036 unsigned int value;
1037 struct si476x_radio *radio = video_drvdata(file);
1038
1039 si476x_core_lock(radio->core);
1040 reg->size = 2;
1041 err = regmap_read(radio->core->regmap,
1042 (unsigned int)reg->reg, &value);
1043 reg->val = value;
1044 si476x_core_unlock(radio->core);
1045
1046 return err;
1047}
1048static int si476x_radio_s_register(struct file *file, void *fh,
1049 const struct v4l2_dbg_register *reg)
1050{
1051
1052 int err;
1053 struct si476x_radio *radio = video_drvdata(file);
1054
1055 si476x_core_lock(radio->core);
1056 err = regmap_write(radio->core->regmap,
1057 (unsigned int)reg->reg,
1058 (unsigned int)reg->val);
1059 si476x_core_unlock(radio->core);
1060
1061 return err;
1062}
1063#endif
1064
1065static int si476x_radio_fops_open(struct file *file)
1066{
1067 struct si476x_radio *radio = video_drvdata(file);
1068 int err;
1069
1070 err = v4l2_fh_open(file);
1071 if (err)
1072 return err;
1073
1074 if (v4l2_fh_is_singular_file(file)) {
1075 si476x_core_lock(radio->core);
1076 err = si476x_core_set_power_state(radio->core,
1077 SI476X_POWER_UP_FULL);
1078 if (err < 0)
1079 goto done;
1080
1081 err = si476x_radio_do_post_powerup_init(radio,
1082 radio->core->power_up_parameters.func);
1083 if (err < 0)
1084 goto power_down;
1085
1086 err = si476x_radio_pretune(radio,
1087 radio->core->power_up_parameters.func);
1088 if (err < 0)
1089 goto power_down;
1090
1091 si476x_core_unlock(radio->core);
1092 /*Must be done after si476x_core_unlock to prevent a deadlock*/
1093 v4l2_ctrl_handler_setup(&radio->ctrl_handler);
1094 }
1095
1096 return err;
1097
1098power_down:
1099 si476x_core_set_power_state(radio->core,
1100 SI476X_POWER_DOWN);
1101done:
1102 si476x_core_unlock(radio->core);
1103 v4l2_fh_release(file);
1104
1105 return err;
1106}
1107
1108static int si476x_radio_fops_release(struct file *file)
1109{
1110 int err;
1111 struct si476x_radio *radio = video_drvdata(file);
1112
1113 if (v4l2_fh_is_singular_file(file) &&
1114 atomic_read(&radio->core->is_alive))
1115 si476x_core_set_power_state(radio->core,
1116 SI476X_POWER_DOWN);
1117
1118 err = v4l2_fh_release(file);
1119
1120 return err;
1121}
1122
1123static ssize_t si476x_radio_fops_read(struct file *file, char __user *buf,
1124 size_t count, loff_t *ppos)
1125{
1126 ssize_t rval;
1127 size_t fifo_len;
1128 unsigned int copied;
1129
1130 struct si476x_radio *radio = video_drvdata(file);
1131
1132 /* block if no new data available */
1133 if (kfifo_is_empty(&radio->core->rds_fifo)) {
1134 if (file->f_flags & O_NONBLOCK)
1135 return -EWOULDBLOCK;
1136
1137 rval = wait_event_interruptible(radio->core->rds_read_queue,
1138 (!kfifo_is_empty(&radio->core->rds_fifo) ||
1139 !atomic_read(&radio->core->is_alive)));
1140 if (rval < 0)
1141 return -EINTR;
1142
1143 if (!atomic_read(&radio->core->is_alive))
1144 return -ENODEV;
1145 }
1146
1147 fifo_len = kfifo_len(&radio->core->rds_fifo);
1148
1149 if (kfifo_to_user(&radio->core->rds_fifo, buf,
1150 min(fifo_len, count),
1151 &copied) != 0) {
1152 dev_warn(&radio->videodev.dev,
1153 "Error during FIFO to userspace copy\n");
1154 rval = -EIO;
1155 } else {
1156 rval = (ssize_t)copied;
1157 }
1158
1159 return rval;
1160}
1161
1162static unsigned int si476x_radio_fops_poll(struct file *file,
1163 struct poll_table_struct *pts)
1164{
1165 struct si476x_radio *radio = video_drvdata(file);
1166 unsigned long req_events = poll_requested_events(pts);
1167 unsigned int err = v4l2_ctrl_poll(file, pts);
1168
1169 if (req_events & (POLLIN | POLLRDNORM)) {
1170 if (atomic_read(&radio->core->is_alive))
1171 poll_wait(file, &radio->core->rds_read_queue, pts);
1172
1173 if (!atomic_read(&radio->core->is_alive))
1174 err = POLLHUP;
1175
1176 if (!kfifo_is_empty(&radio->core->rds_fifo))
1177 err = POLLIN | POLLRDNORM;
1178 }
1179
1180 return err;
1181}
1182
1183static const struct v4l2_file_operations si476x_fops = {
1184 .owner = THIS_MODULE,
1185 .read = si476x_radio_fops_read,
1186 .poll = si476x_radio_fops_poll,
1187 .unlocked_ioctl = video_ioctl2,
1188 .open = si476x_radio_fops_open,
1189 .release = si476x_radio_fops_release,
1190};
1191
1192
1193static const struct v4l2_ioctl_ops si4761_ioctl_ops = {
1194 .vidioc_querycap = si476x_radio_querycap,
1195 .vidioc_g_tuner = si476x_radio_g_tuner,
1196 .vidioc_s_tuner = si476x_radio_s_tuner,
1197
1198 .vidioc_g_frequency = si476x_radio_g_frequency,
1199 .vidioc_s_frequency = si476x_radio_s_frequency,
1200 .vidioc_s_hw_freq_seek = si476x_radio_s_hw_freq_seek,
1201 .vidioc_enum_freq_bands = si476x_radio_enum_freq_bands,
1202
1203 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1204 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1205
1206 .vidioc_g_chip_ident = si476x_radio_g_chip_ident,
1207#ifdef CONFIG_VIDEO_ADV_DEBUG
1208 .vidioc_g_register = si476x_radio_g_register,
1209 .vidioc_s_register = si476x_radio_s_register,
1210#endif
1211};
1212
1213
1214static const struct video_device si476x_viddev_template = {
1215 .fops = &si476x_fops,
1216 .name = DRIVER_NAME,
1217 .release = video_device_release_empty,
1218};
1219
1220
1221
1222static ssize_t si476x_radio_read_acf_blob(struct file *file,
1223 char __user *user_buf,
1224 size_t count, loff_t *ppos)
1225{
1226 int err;
1227 struct si476x_radio *radio = file->private_data;
1228 struct si476x_acf_status_report report;
1229
1230 si476x_core_lock(radio->core);
1231 if (radio->ops->acf_status)
1232 err = radio->ops->acf_status(radio->core, &report);
1233 else
1234 err = -ENOENT;
1235 si476x_core_unlock(radio->core);
1236
1237 if (err < 0)
1238 return err;
1239
1240 return simple_read_from_buffer(user_buf, count, ppos, &report,
1241 sizeof(report));
1242}
1243
1244static const struct file_operations radio_acf_fops = {
1245 .open = simple_open,
1246 .llseek = default_llseek,
1247 .read = si476x_radio_read_acf_blob,
1248};
1249
1250static ssize_t si476x_radio_read_rds_blckcnt_blob(struct file *file,
1251 char __user *user_buf,
1252 size_t count, loff_t *ppos)
1253{
1254 int err;
1255 struct si476x_radio *radio = file->private_data;
1256 struct si476x_rds_blockcount_report report;
1257
1258 si476x_core_lock(radio->core);
1259 if (radio->ops->rds_blckcnt)
1260 err = radio->ops->rds_blckcnt(radio->core, true,
1261 &report);
1262 else
1263 err = -ENOENT;
1264 si476x_core_unlock(radio->core);
1265
1266 if (err < 0)
1267 return err;
1268
1269 return simple_read_from_buffer(user_buf, count, ppos, &report,
1270 sizeof(report));
1271}
1272
1273static const struct file_operations radio_rds_blckcnt_fops = {
1274 .open = simple_open,
1275 .llseek = default_llseek,
1276 .read = si476x_radio_read_rds_blckcnt_blob,
1277};
1278
1279static ssize_t si476x_radio_read_agc_blob(struct file *file,
1280 char __user *user_buf,
1281 size_t count, loff_t *ppos)
1282{
1283 int err;
1284 struct si476x_radio *radio = file->private_data;
1285 struct si476x_agc_status_report report;
1286
1287 si476x_core_lock(radio->core);
1288 if (radio->ops->rds_blckcnt)
1289 err = radio->ops->agc_status(radio->core, &report);
1290 else
1291 err = -ENOENT;
1292 si476x_core_unlock(radio->core);
1293
1294 if (err < 0)
1295 return err;
1296
1297 return simple_read_from_buffer(user_buf, count, ppos, &report,
1298 sizeof(report));
1299}
1300
1301static const struct file_operations radio_agc_fops = {
1302 .open = simple_open,
1303 .llseek = default_llseek,
1304 .read = si476x_radio_read_agc_blob,
1305};
1306
1307static ssize_t si476x_radio_read_rsq_blob(struct file *file,
1308 char __user *user_buf,
1309 size_t count, loff_t *ppos)
1310{
1311 int err;
1312 struct si476x_radio *radio = file->private_data;
1313 struct si476x_rsq_status_report report;
1314 struct si476x_rsq_status_args args = {
1315 .primary = false,
1316 .rsqack = false,
1317 .attune = false,
1318 .cancel = false,
1319 .stcack = false,
1320 };
1321
1322 si476x_core_lock(radio->core);
1323 if (radio->ops->rds_blckcnt)
1324 err = radio->ops->rsq_status(radio->core, &args, &report);
1325 else
1326 err = -ENOENT;
1327 si476x_core_unlock(radio->core);
1328
1329 if (err < 0)
1330 return err;
1331
1332 return simple_read_from_buffer(user_buf, count, ppos, &report,
1333 sizeof(report));
1334}
1335
1336static const struct file_operations radio_rsq_fops = {
1337 .open = simple_open,
1338 .llseek = default_llseek,
1339 .read = si476x_radio_read_rsq_blob,
1340};
1341
1342static ssize_t si476x_radio_read_rsq_primary_blob(struct file *file,
1343 char __user *user_buf,
1344 size_t count, loff_t *ppos)
1345{
1346 int err;
1347 struct si476x_radio *radio = file->private_data;
1348 struct si476x_rsq_status_report report;
1349 struct si476x_rsq_status_args args = {
1350 .primary = true,
1351 .rsqack = false,
1352 .attune = false,
1353 .cancel = false,
1354 .stcack = false,
1355 };
1356
1357 si476x_core_lock(radio->core);
1358 if (radio->ops->rds_blckcnt)
1359 err = radio->ops->rsq_status(radio->core, &args, &report);
1360 else
1361 err = -ENOENT;
1362 si476x_core_unlock(radio->core);
1363
1364 if (err < 0)
1365 return err;
1366
1367 return simple_read_from_buffer(user_buf, count, ppos, &report,
1368 sizeof(report));
1369}
1370
1371static const struct file_operations radio_rsq_primary_fops = {
1372 .open = simple_open,
1373 .llseek = default_llseek,
1374 .read = si476x_radio_read_rsq_primary_blob,
1375};
1376
1377
1378static int si476x_radio_init_debugfs(struct si476x_radio *radio)
1379{
1380 struct dentry *dentry;
1381 int ret;
1382
1383 dentry = debugfs_create_dir(dev_name(radio->v4l2dev.dev), NULL);
1384 if (IS_ERR(dentry)) {
1385 ret = PTR_ERR(dentry);
1386 goto exit;
1387 }
1388 radio->debugfs = dentry;
1389
1390 dentry = debugfs_create_file("acf", S_IRUGO,
1391 radio->debugfs, radio, &radio_acf_fops);
1392 if (IS_ERR(dentry)) {
1393 ret = PTR_ERR(dentry);
1394 goto cleanup;
1395 }
1396
1397 dentry = debugfs_create_file("rds_blckcnt", S_IRUGO,
1398 radio->debugfs, radio,
1399 &radio_rds_blckcnt_fops);
1400 if (IS_ERR(dentry)) {
1401 ret = PTR_ERR(dentry);
1402 goto cleanup;
1403 }
1404
1405 dentry = debugfs_create_file("agc", S_IRUGO,
1406 radio->debugfs, radio, &radio_agc_fops);
1407 if (IS_ERR(dentry)) {
1408 ret = PTR_ERR(dentry);
1409 goto cleanup;
1410 }
1411
1412 dentry = debugfs_create_file("rsq", S_IRUGO,
1413 radio->debugfs, radio, &radio_rsq_fops);
1414 if (IS_ERR(dentry)) {
1415 ret = PTR_ERR(dentry);
1416 goto cleanup;
1417 }
1418
1419 dentry = debugfs_create_file("rsq_primary", S_IRUGO,
1420 radio->debugfs, radio,
1421 &radio_rsq_primary_fops);
1422 if (IS_ERR(dentry)) {
1423 ret = PTR_ERR(dentry);
1424 goto cleanup;
1425 }
1426
1427 return 0;
1428cleanup:
1429 debugfs_remove_recursive(radio->debugfs);
1430exit:
1431 return ret;
1432}
1433
1434
1435static int si476x_radio_add_new_custom(struct si476x_radio *radio,
1436 enum si476x_ctrl_idx idx)
1437{
1438 int rval;
1439 struct v4l2_ctrl *ctrl;
1440
1441 ctrl = v4l2_ctrl_new_custom(&radio->ctrl_handler,
1442 &si476x_ctrls[idx],
1443 NULL);
1444 rval = radio->ctrl_handler.error;
1445 if (ctrl == NULL && rval)
1446 dev_err(radio->v4l2dev.dev,
1447 "Could not initialize '%s' control %d\n",
1448 si476x_ctrls[idx].name, rval);
1449
1450 return rval;
1451}
1452
1453static int si476x_radio_probe(struct platform_device *pdev)
1454{
1455 int rval;
1456 struct si476x_radio *radio;
1457 struct v4l2_ctrl *ctrl;
1458
1459 static atomic_t instance = ATOMIC_INIT(0);
1460
1461 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
1462 if (!radio)
1463 return -ENOMEM;
1464
1465 radio->core = i2c_mfd_cell_to_core(&pdev->dev);
1466
1467 v4l2_device_set_name(&radio->v4l2dev, DRIVER_NAME, &instance);
1468
1469 rval = v4l2_device_register(&pdev->dev, &radio->v4l2dev);
1470 if (rval) {
1471 dev_err(&pdev->dev, "Cannot register v4l2_device.\n");
1472 return rval;
1473 }
1474
1475 memcpy(&radio->videodev, &si476x_viddev_template,
1476 sizeof(struct video_device));
1477
1478 radio->videodev.v4l2_dev = &radio->v4l2dev;
1479 radio->videodev.ioctl_ops = &si4761_ioctl_ops;
1480
1481 video_set_drvdata(&radio->videodev, radio);
1482 platform_set_drvdata(pdev, radio);
1483
1484 set_bit(V4L2_FL_USE_FH_PRIO, &radio->videodev.flags);
1485
1486 radio->v4l2dev.ctrl_handler = &radio->ctrl_handler;
1487 v4l2_ctrl_handler_init(&radio->ctrl_handler,
1488 1 + ARRAY_SIZE(si476x_ctrls));
1489
1490 if (si476x_core_has_am(radio->core)) {
1491 ctrl = v4l2_ctrl_new_std_menu(&radio->ctrl_handler,
1492 &si476x_ctrl_ops,
1493 V4L2_CID_POWER_LINE_FREQUENCY,
1494 V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
1495 0, 0);
1496 rval = radio->ctrl_handler.error;
1497 if (ctrl == NULL && rval) {
1498 dev_err(&pdev->dev, "Could not initialize V4L2_CID_POWER_LINE_FREQUENCY control %d\n",
1499 rval);
1500 goto exit;
1501 }
1502
1503 rval = si476x_radio_add_new_custom(radio,
1504 SI476X_IDX_HARMONICS_COUNT);
1505 if (rval < 0)
1506 goto exit;
1507 }
1508
1509 rval = si476x_radio_add_new_custom(radio, SI476X_IDX_RSSI_THRESHOLD);
1510 if (rval < 0)
1511 goto exit;
1512
1513 rval = si476x_radio_add_new_custom(radio, SI476X_IDX_SNR_THRESHOLD);
1514 if (rval < 0)
1515 goto exit;
1516
1517 rval = si476x_radio_add_new_custom(radio, SI476X_IDX_MAX_TUNE_ERROR);
1518 if (rval < 0)
1519 goto exit;
1520
1521 ctrl = v4l2_ctrl_new_std_menu(&radio->ctrl_handler,
1522 &si476x_ctrl_ops,
1523 V4L2_CID_TUNE_DEEMPHASIS,
1524 V4L2_DEEMPHASIS_75_uS, 0, 0);
1525 rval = radio->ctrl_handler.error;
1526 if (ctrl == NULL && rval) {
1527 dev_err(&pdev->dev, "Could not initialize V4L2_CID_TUNE_DEEMPHASIS control %d\n",
1528 rval);
1529 goto exit;
1530 }
1531
1532 ctrl = v4l2_ctrl_new_std(&radio->ctrl_handler, &si476x_ctrl_ops,
1533 V4L2_CID_RDS_RECEPTION,
1534 0, 1, 1, 1);
1535 rval = radio->ctrl_handler.error;
1536 if (ctrl == NULL && rval) {
1537 dev_err(&pdev->dev, "Could not initialize V4L2_CID_RDS_RECEPTION control %d\n",
1538 rval);
1539 goto exit;
1540 }
1541
1542 if (si476x_core_has_diversity(radio->core)) {
1543 si476x_ctrls[SI476X_IDX_DIVERSITY_MODE].def =
1544 si476x_phase_diversity_mode_to_idx(radio->core->diversity_mode);
1545 si476x_radio_add_new_custom(radio, SI476X_IDX_DIVERSITY_MODE);
1546 if (rval < 0)
1547 goto exit;
1548
1549 si476x_radio_add_new_custom(radio, SI476X_IDX_INTERCHIP_LINK);
1550 if (rval < 0)
1551 goto exit;
1552 }
1553
1554 /* register video device */
1555 rval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, -1);
1556 if (rval < 0) {
1557 dev_err(&pdev->dev, "Could not register video device\n");
1558 goto exit;
1559 }
1560
1561 rval = si476x_radio_init_debugfs(radio);
1562 if (rval < 0) {
1563 dev_err(&pdev->dev, "Could not creat debugfs interface\n");
1564 goto exit;
1565 }
1566
1567 return 0;
1568exit:
1569 v4l2_ctrl_handler_free(radio->videodev.ctrl_handler);
1570 return rval;
1571}
1572
1573static int si476x_radio_remove(struct platform_device *pdev)
1574{
1575 struct si476x_radio *radio = platform_get_drvdata(pdev);
1576
1577 v4l2_ctrl_handler_free(radio->videodev.ctrl_handler);
1578 video_unregister_device(&radio->videodev);
1579 v4l2_device_unregister(&radio->v4l2dev);
1580 debugfs_remove_recursive(radio->debugfs);
1581
1582 return 0;
1583}
1584
1585MODULE_ALIAS("platform:si476x-radio");
1586
1587static struct platform_driver si476x_radio_driver = {
1588 .driver = {
1589 .name = DRIVER_NAME,
1590 .owner = THIS_MODULE,
1591 },
1592 .probe = si476x_radio_probe,
1593 .remove = si476x_radio_remove,
1594};
1595module_platform_driver(si476x_radio_driver);
1596
1597MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
1598MODULE_DESCRIPTION("Driver for Si4761/64/68 AM/FM Radio MFD Cell");
1599MODULE_LICENSE("GPL");
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c
index 1978516af67e..38d563d62595 100644
--- a/drivers/media/radio/radio-tea5764.c
+++ b/drivers/media/radio/radio-tea5764.c
@@ -339,7 +339,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
339} 339}
340 340
341static int vidioc_s_tuner(struct file *file, void *priv, 341static int vidioc_s_tuner(struct file *file, void *priv,
342 struct v4l2_tuner *v) 342 const struct v4l2_tuner *v)
343{ 343{
344 struct tea5764_device *radio = video_drvdata(file); 344 struct tea5764_device *radio = video_drvdata(file);
345 345
@@ -351,7 +351,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
351} 351}
352 352
353static int vidioc_s_frequency(struct file *file, void *priv, 353static int vidioc_s_frequency(struct file *file, void *priv,
354 struct v4l2_frequency *f) 354 const struct v4l2_frequency *f)
355{ 355{
356 struct tea5764_device *radio = video_drvdata(file); 356 struct tea5764_device *radio = video_drvdata(file);
357 357
diff --git a/drivers/media/radio/radio-tea5777.c b/drivers/media/radio/radio-tea5777.c
index 4b5190d4fea5..e2455970725a 100644
--- a/drivers/media/radio/radio-tea5777.c
+++ b/drivers/media/radio/radio-tea5777.c
@@ -336,7 +336,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
336} 336}
337 337
338static int vidioc_s_tuner(struct file *file, void *priv, 338static int vidioc_s_tuner(struct file *file, void *priv,
339 struct v4l2_tuner *v) 339 const struct v4l2_tuner *v)
340{ 340{
341 struct radio_tea5777 *tea = video_drvdata(file); 341 struct radio_tea5777 *tea = video_drvdata(file);
342 u32 orig_audmode = tea->audmode; 342 u32 orig_audmode = tea->audmode;
@@ -344,10 +344,9 @@ static int vidioc_s_tuner(struct file *file, void *priv,
344 if (v->index) 344 if (v->index)
345 return -EINVAL; 345 return -EINVAL;
346 346
347 if (v->audmode > V4L2_TUNER_MODE_STEREO)
348 v->audmode = V4L2_TUNER_MODE_STEREO;
349
350 tea->audmode = v->audmode; 347 tea->audmode = v->audmode;
348 if (tea->audmode > V4L2_TUNER_MODE_STEREO)
349 tea->audmode = V4L2_TUNER_MODE_STEREO;
351 350
352 if (tea->audmode != orig_audmode && tea->band == BAND_FM) 351 if (tea->audmode != orig_audmode && tea->band == BAND_FM)
353 return radio_tea5777_set_freq(tea); 352 return radio_tea5777_set_freq(tea);
@@ -368,7 +367,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
368} 367}
369 368
370static int vidioc_s_frequency(struct file *file, void *priv, 369static int vidioc_s_frequency(struct file *file, void *priv,
371 struct v4l2_frequency *f) 370 const struct v4l2_frequency *f)
372{ 371{
373 struct radio_tea5777 *tea = video_drvdata(file); 372 struct radio_tea5777 *tea = video_drvdata(file);
374 373
diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c
index b87effeb5dc6..bb7b143b65d1 100644
--- a/drivers/media/radio/radio-timb.c
+++ b/drivers/media/radio/radio-timb.c
@@ -56,7 +56,7 @@ static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
56} 56}
57 57
58static int timbradio_vidioc_s_tuner(struct file *file, void *priv, 58static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
59 struct v4l2_tuner *v) 59 const struct v4l2_tuner *v)
60{ 60{
61 struct timbradio *tr = video_drvdata(file); 61 struct timbradio *tr = video_drvdata(file);
62 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v); 62 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
@@ -91,7 +91,7 @@ static int timbradio_vidioc_s_audio(struct file *file, void *priv,
91} 91}
92 92
93static int timbradio_vidioc_s_frequency(struct file *file, void *priv, 93static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
94 struct v4l2_frequency *f) 94 const struct v4l2_frequency *f)
95{ 95{
96 struct timbradio *tr = video_drvdata(file); 96 struct timbradio *tr = video_drvdata(file);
97 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f); 97 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
diff --git a/drivers/media/radio/radio-wl1273.c b/drivers/media/radio/radio-wl1273.c
index 02151e0e6e63..97c2c18803ef 100644
--- a/drivers/media/radio/radio-wl1273.c
+++ b/drivers/media/radio/radio-wl1273.c
@@ -1559,7 +1559,7 @@ out:
1559} 1559}
1560 1560
1561static int wl1273_fm_vidioc_s_tuner(struct file *file, void *priv, 1561static int wl1273_fm_vidioc_s_tuner(struct file *file, void *priv,
1562 struct v4l2_tuner *tuner) 1562 const struct v4l2_tuner *tuner)
1563{ 1563{
1564 struct wl1273_device *radio = video_get_drvdata(video_devdata(file)); 1564 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1565 struct wl1273_core *core = radio->core; 1565 struct wl1273_core *core = radio->core;
@@ -1640,7 +1640,7 @@ static int wl1273_fm_vidioc_g_frequency(struct file *file, void *priv,
1640} 1640}
1641 1641
1642static int wl1273_fm_vidioc_s_frequency(struct file *file, void *priv, 1642static int wl1273_fm_vidioc_s_frequency(struct file *file, void *priv,
1643 struct v4l2_frequency *freq) 1643 const struct v4l2_frequency *freq)
1644{ 1644{
1645 struct wl1273_device *radio = video_get_drvdata(video_devdata(file)); 1645 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1646 struct wl1273_core *core = radio->core; 1646 struct wl1273_core *core = radio->core;
diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c
index 18989388ddc1..5c57e5b0f949 100644
--- a/drivers/media/radio/si470x/radio-si470x-common.c
+++ b/drivers/media/radio/si470x/radio-si470x-common.c
@@ -636,7 +636,7 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv,
636 * si470x_vidioc_s_tuner - set tuner attributes 636 * si470x_vidioc_s_tuner - set tuner attributes
637 */ 637 */
638static int si470x_vidioc_s_tuner(struct file *file, void *priv, 638static int si470x_vidioc_s_tuner(struct file *file, void *priv,
639 struct v4l2_tuner *tuner) 639 const struct v4l2_tuner *tuner)
640{ 640{
641 struct si470x_device *radio = video_drvdata(file); 641 struct si470x_device *radio = video_drvdata(file);
642 642
@@ -678,7 +678,7 @@ static int si470x_vidioc_g_frequency(struct file *file, void *priv,
678 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency 678 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
679 */ 679 */
680static int si470x_vidioc_s_frequency(struct file *file, void *priv, 680static int si470x_vidioc_s_frequency(struct file *file, void *priv,
681 struct v4l2_frequency *freq) 681 const struct v4l2_frequency *freq)
682{ 682{
683 struct si470x_device *radio = video_drvdata(file); 683 struct si470x_device *radio = video_drvdata(file);
684 int retval; 684 int retval;
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
index bd61b3bd0ca3..fe160882ee10 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713-i2c.c
@@ -21,7 +21,6 @@
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 23
24#include <linux/mutex.h>
25#include <linux/completion.h> 24#include <linux/completion.h>
26#include <linux/delay.h> 25#include <linux/delay.h>
27#include <linux/interrupt.h> 26#include <linux/interrupt.h>
@@ -53,8 +52,6 @@ static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
53 52
54#define DEFAULT_RDS_PI 0x00 53#define DEFAULT_RDS_PI 0x00
55#define DEFAULT_RDS_PTY 0x00 54#define DEFAULT_RDS_PTY 0x00
56#define DEFAULT_RDS_PS_NAME ""
57#define DEFAULT_RDS_RADIO_TEXT DEFAULT_RDS_PS_NAME
58#define DEFAULT_RDS_DEVIATION 0x00C8 55#define DEFAULT_RDS_DEVIATION 0x00C8
59#define DEFAULT_RDS_PS_REPEAT_COUNT 0x0003 56#define DEFAULT_RDS_PS_REPEAT_COUNT 0x0003
60#define DEFAULT_LIMITER_RTIME 0x1392 57#define DEFAULT_LIMITER_RTIME 0x1392
@@ -108,7 +105,6 @@ static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
108 (status & SI4713_ERR)) 105 (status & SI4713_ERR))
109/* mute definition */ 106/* mute definition */
110#define set_mute(p) ((p & 1) | ((p & 1) << 1)); 107#define set_mute(p) ((p & 1) | ((p & 1) << 1));
111#define get_mute(p) (p & 0x01)
112 108
113#ifdef DEBUG 109#ifdef DEBUG
114#define DBG_BUFFER(device, message, buffer, size) \ 110#define DBG_BUFFER(device, message, buffer, size) \
@@ -190,21 +186,6 @@ static int usecs_to_dev(unsigned long usecs, unsigned long const array[],
190 return rval; 186 return rval;
191} 187}
192 188
193static unsigned long dev_to_usecs(int value, unsigned long const array[],
194 int size)
195{
196 int i;
197 int rval = -EINVAL;
198
199 for (i = 0; i < size / 2; i++)
200 if (array[i * 2] == value) {
201 rval = array[(i * 2) + 1];
202 break;
203 }
204
205 return rval;
206}
207
208/* si4713_handler: IRQ handler, just complete work */ 189/* si4713_handler: IRQ handler, just complete work */
209static irqreturn_t si4713_handler(int irq, void *dev) 190static irqreturn_t si4713_handler(int irq, void *dev)
210{ 191{
@@ -458,15 +439,13 @@ static int si4713_checkrev(struct si4713_device *sdev)
458 int rval; 439 int rval;
459 u8 resp[SI4713_GETREV_NRESP]; 440 u8 resp[SI4713_GETREV_NRESP];
460 441
461 mutex_lock(&sdev->mutex);
462
463 rval = si4713_send_command(sdev, SI4713_CMD_GET_REV, 442 rval = si4713_send_command(sdev, SI4713_CMD_GET_REV,
464 NULL, 0, 443 NULL, 0,
465 resp, ARRAY_SIZE(resp), 444 resp, ARRAY_SIZE(resp),
466 DEFAULT_TIMEOUT); 445 DEFAULT_TIMEOUT);
467 446
468 if (rval < 0) 447 if (rval < 0)
469 goto unlock; 448 return rval;
470 449
471 if (resp[1] == SI4713_PRODUCT_NUMBER) { 450 if (resp[1] == SI4713_PRODUCT_NUMBER) {
472 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n", 451 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
@@ -475,9 +454,6 @@ static int si4713_checkrev(struct si4713_device *sdev)
475 v4l2_err(&sdev->sd, "Invalid product number\n"); 454 v4l2_err(&sdev->sd, "Invalid product number\n");
476 rval = -EINVAL; 455 rval = -EINVAL;
477 } 456 }
478
479unlock:
480 mutex_unlock(&sdev->mutex);
481 return rval; 457 return rval;
482} 458}
483 459
@@ -778,17 +754,9 @@ static int si4713_tx_rds_ps(struct si4713_device *sdev, u8 psid,
778 754
779static int si4713_set_power_state(struct si4713_device *sdev, u8 value) 755static int si4713_set_power_state(struct si4713_device *sdev, u8 value)
780{ 756{
781 int rval;
782
783 mutex_lock(&sdev->mutex);
784
785 if (value) 757 if (value)
786 rval = si4713_powerup(sdev); 758 return si4713_powerup(sdev);
787 else 759 return si4713_powerdown(sdev);
788 rval = si4713_powerdown(sdev);
789
790 mutex_unlock(&sdev->mutex);
791 return rval;
792} 760}
793 761
794static int si4713_set_mute(struct si4713_device *sdev, u16 mute) 762static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
@@ -797,17 +765,10 @@ static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
797 765
798 mute = set_mute(mute); 766 mute = set_mute(mute);
799 767
800 mutex_lock(&sdev->mutex);
801
802 if (sdev->power_state) 768 if (sdev->power_state)
803 rval = si4713_write_property(sdev, 769 rval = si4713_write_property(sdev,
804 SI4713_TX_LINE_INPUT_MUTE, mute); 770 SI4713_TX_LINE_INPUT_MUTE, mute);
805 771
806 if (rval >= 0)
807 sdev->mute = get_mute(mute);
808
809 mutex_unlock(&sdev->mutex);
810
811 return rval; 772 return rval;
812} 773}
813 774
@@ -820,15 +781,13 @@ static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
820 if (!strlen(ps_name)) 781 if (!strlen(ps_name))
821 memset(ps_name, 0, MAX_RDS_PS_NAME + 1); 782 memset(ps_name, 0, MAX_RDS_PS_NAME + 1);
822 783
823 mutex_lock(&sdev->mutex);
824
825 if (sdev->power_state) { 784 if (sdev->power_state) {
826 /* Write the new ps name and clear the padding */ 785 /* Write the new ps name and clear the padding */
827 for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) { 786 for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) {
828 rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)), 787 rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)),
829 ps_name + i); 788 ps_name + i);
830 if (rval < 0) 789 if (rval < 0)
831 goto unlock; 790 return rval;
832 } 791 }
833 792
834 /* Setup the size to be sent */ 793 /* Setup the size to be sent */
@@ -841,19 +800,15 @@ static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
841 SI4713_TX_RDS_PS_MESSAGE_COUNT, 800 SI4713_TX_RDS_PS_MESSAGE_COUNT,
842 rds_ps_nblocks(len)); 801 rds_ps_nblocks(len));
843 if (rval < 0) 802 if (rval < 0)
844 goto unlock; 803 return rval;
845 804
846 rval = si4713_write_property(sdev, 805 rval = si4713_write_property(sdev,
847 SI4713_TX_RDS_PS_REPEAT_COUNT, 806 SI4713_TX_RDS_PS_REPEAT_COUNT,
848 DEFAULT_RDS_PS_REPEAT_COUNT * 2); 807 DEFAULT_RDS_PS_REPEAT_COUNT * 2);
849 if (rval < 0) 808 if (rval < 0)
850 goto unlock; 809 return rval;
851 } 810 }
852 811
853 strncpy(sdev->rds_info.ps_name, ps_name, MAX_RDS_PS_NAME);
854
855unlock:
856 mutex_unlock(&sdev->mutex);
857 return rval; 812 return rval;
858} 813}
859 814
@@ -864,27 +819,24 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
864 u8 b_index = 0, cr_inserted = 0; 819 u8 b_index = 0, cr_inserted = 0;
865 s8 left; 820 s8 left;
866 821
867 mutex_lock(&sdev->mutex);
868
869 if (!sdev->power_state) 822 if (!sdev->power_state)
870 goto copy; 823 return rval;
871 824
872 rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left); 825 rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left);
873 if (rval < 0) 826 if (rval < 0)
874 goto unlock; 827 return rval;
875 828
876 if (!strlen(rt)) 829 if (!strlen(rt))
877 goto copy; 830 return rval;
878 831
879 do { 832 do {
880 /* RDS spec says that if the last block isn't used, 833 /* RDS spec says that if the last block isn't used,
881 * then apply a carriage return 834 * then apply a carriage return
882 */ 835 */
883 if (t_index < (RDS_RADIOTEXT_INDEX_MAX * 836 if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {
884 RDS_RADIOTEXT_BLK_SIZE)) {
885 for (i = 0; i < RDS_RADIOTEXT_BLK_SIZE; i++) { 837 for (i = 0; i < RDS_RADIOTEXT_BLK_SIZE; i++) {
886 if (!rt[t_index + i] || rt[t_index + i] == 838 if (!rt[t_index + i] ||
887 RDS_CARRIAGE_RETURN) { 839 rt[t_index + i] == RDS_CARRIAGE_RETURN) {
888 rt[t_index + i] = RDS_CARRIAGE_RETURN; 840 rt[t_index + i] = RDS_CARRIAGE_RETURN;
889 cr_inserted = 1; 841 cr_inserted = 1;
890 break; 842 break;
@@ -898,7 +850,7 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
898 compose_u16(rt[t_index + 2], rt[t_index + 3]), 850 compose_u16(rt[t_index + 2], rt[t_index + 3]),
899 &left); 851 &left);
900 if (rval < 0) 852 if (rval < 0)
901 goto unlock; 853 return rval;
902 854
903 t_index += RDS_RADIOTEXT_BLK_SIZE; 855 t_index += RDS_RADIOTEXT_BLK_SIZE;
904 856
@@ -906,16 +858,38 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
906 break; 858 break;
907 } while (left > 0); 859 } while (left > 0);
908 860
909copy: 861 return rval;
910 strncpy(sdev->rds_info.radio_text, rt, MAX_RDS_RADIO_TEXT); 862}
911 863
912unlock: 864/*
913 mutex_unlock(&sdev->mutex); 865 * si4713_update_tune_status - update properties from tx_tune_status
866 * command. Must be called with sdev->mutex held.
867 * @sdev: si4713_device structure for the device we are communicating
868 */
869static int si4713_update_tune_status(struct si4713_device *sdev)
870{
871 int rval;
872 u16 f = 0;
873 u8 p = 0, a = 0, n = 0;
874
875 rval = si4713_tx_tune_status(sdev, 0x00, &f, &p, &a, &n);
876
877 if (rval < 0)
878 goto exit;
879
880/* TODO: check that power_level and antenna_capacitor really are not
881 changed by the hardware. If they are, then these controls should become
882 volatiles.
883 sdev->power_level = p;
884 sdev->antenna_capacitor = a;*/
885 sdev->tune_rnl = n;
886
887exit:
914 return rval; 888 return rval;
915} 889}
916 890
917static int si4713_choose_econtrol_action(struct si4713_device *sdev, u32 id, 891static int si4713_choose_econtrol_action(struct si4713_device *sdev, u32 id,
918 u32 **shadow, s32 *bit, s32 *mask, u16 *property, int *mul, 892 s32 *bit, s32 *mask, u16 *property, int *mul,
919 unsigned long **table, int *size) 893 unsigned long **table, int *size)
920{ 894{
921 s32 rval = 0; 895 s32 rval = 0;
@@ -925,157 +899,71 @@ static int si4713_choose_econtrol_action(struct si4713_device *sdev, u32 id,
925 case V4L2_CID_RDS_TX_PI: 899 case V4L2_CID_RDS_TX_PI:
926 *property = SI4713_TX_RDS_PI; 900 *property = SI4713_TX_RDS_PI;
927 *mul = 1; 901 *mul = 1;
928 *shadow = &sdev->rds_info.pi;
929 break; 902 break;
930 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: 903 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
931 *property = SI4713_TX_ACOMP_THRESHOLD; 904 *property = SI4713_TX_ACOMP_THRESHOLD;
932 *mul = 1; 905 *mul = 1;
933 *shadow = &sdev->acomp_info.threshold;
934 break; 906 break;
935 case V4L2_CID_AUDIO_COMPRESSION_GAIN: 907 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
936 *property = SI4713_TX_ACOMP_GAIN; 908 *property = SI4713_TX_ACOMP_GAIN;
937 *mul = 1; 909 *mul = 1;
938 *shadow = &sdev->acomp_info.gain;
939 break; 910 break;
940 case V4L2_CID_PILOT_TONE_FREQUENCY: 911 case V4L2_CID_PILOT_TONE_FREQUENCY:
941 *property = SI4713_TX_PILOT_FREQUENCY; 912 *property = SI4713_TX_PILOT_FREQUENCY;
942 *mul = 1; 913 *mul = 1;
943 *shadow = &sdev->pilot_info.frequency;
944 break; 914 break;
945 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: 915 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
946 *property = SI4713_TX_ACOMP_ATTACK_TIME; 916 *property = SI4713_TX_ACOMP_ATTACK_TIME;
947 *mul = ATTACK_TIME_UNIT; 917 *mul = ATTACK_TIME_UNIT;
948 *shadow = &sdev->acomp_info.attack_time;
949 break; 918 break;
950 case V4L2_CID_PILOT_TONE_DEVIATION: 919 case V4L2_CID_PILOT_TONE_DEVIATION:
951 *property = SI4713_TX_PILOT_DEVIATION; 920 *property = SI4713_TX_PILOT_DEVIATION;
952 *mul = 10; 921 *mul = 10;
953 *shadow = &sdev->pilot_info.deviation;
954 break; 922 break;
955 case V4L2_CID_AUDIO_LIMITER_DEVIATION: 923 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
956 *property = SI4713_TX_AUDIO_DEVIATION; 924 *property = SI4713_TX_AUDIO_DEVIATION;
957 *mul = 10; 925 *mul = 10;
958 *shadow = &sdev->limiter_info.deviation;
959 break; 926 break;
960 case V4L2_CID_RDS_TX_DEVIATION: 927 case V4L2_CID_RDS_TX_DEVIATION:
961 *property = SI4713_TX_RDS_DEVIATION; 928 *property = SI4713_TX_RDS_DEVIATION;
962 *mul = 1; 929 *mul = 1;
963 *shadow = &sdev->rds_info.deviation;
964 break; 930 break;
965 931
966 case V4L2_CID_RDS_TX_PTY: 932 case V4L2_CID_RDS_TX_PTY:
967 *property = SI4713_TX_RDS_PS_MISC; 933 *property = SI4713_TX_RDS_PS_MISC;
968 *bit = 5; 934 *bit = 5;
969 *mask = 0x1F << 5; 935 *mask = 0x1F << 5;
970 *shadow = &sdev->rds_info.pty;
971 break; 936 break;
972 case V4L2_CID_AUDIO_LIMITER_ENABLED: 937 case V4L2_CID_AUDIO_LIMITER_ENABLED:
973 *property = SI4713_TX_ACOMP_ENABLE; 938 *property = SI4713_TX_ACOMP_ENABLE;
974 *bit = 1; 939 *bit = 1;
975 *mask = 1 << 1; 940 *mask = 1 << 1;
976 *shadow = &sdev->limiter_info.enabled;
977 break; 941 break;
978 case V4L2_CID_AUDIO_COMPRESSION_ENABLED: 942 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
979 *property = SI4713_TX_ACOMP_ENABLE; 943 *property = SI4713_TX_ACOMP_ENABLE;
980 *bit = 0; 944 *bit = 0;
981 *mask = 1 << 0; 945 *mask = 1 << 0;
982 *shadow = &sdev->acomp_info.enabled;
983 break; 946 break;
984 case V4L2_CID_PILOT_TONE_ENABLED: 947 case V4L2_CID_PILOT_TONE_ENABLED:
985 *property = SI4713_TX_COMPONENT_ENABLE; 948 *property = SI4713_TX_COMPONENT_ENABLE;
986 *bit = 0; 949 *bit = 0;
987 *mask = 1 << 0; 950 *mask = 1 << 0;
988 *shadow = &sdev->pilot_info.enabled;
989 break; 951 break;
990 952
991 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: 953 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
992 *property = SI4713_TX_LIMITER_RELEASE_TIME; 954 *property = SI4713_TX_LIMITER_RELEASE_TIME;
993 *table = limiter_times; 955 *table = limiter_times;
994 *size = ARRAY_SIZE(limiter_times); 956 *size = ARRAY_SIZE(limiter_times);
995 *shadow = &sdev->limiter_info.release_time;
996 break; 957 break;
997 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: 958 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
998 *property = SI4713_TX_ACOMP_RELEASE_TIME; 959 *property = SI4713_TX_ACOMP_RELEASE_TIME;
999 *table = acomp_rtimes; 960 *table = acomp_rtimes;
1000 *size = ARRAY_SIZE(acomp_rtimes); 961 *size = ARRAY_SIZE(acomp_rtimes);
1001 *shadow = &sdev->acomp_info.release_time;
1002 break; 962 break;
1003 case V4L2_CID_TUNE_PREEMPHASIS: 963 case V4L2_CID_TUNE_PREEMPHASIS:
1004 *property = SI4713_TX_PREEMPHASIS; 964 *property = SI4713_TX_PREEMPHASIS;
1005 *table = preemphasis_values; 965 *table = preemphasis_values;
1006 *size = ARRAY_SIZE(preemphasis_values); 966 *size = ARRAY_SIZE(preemphasis_values);
1007 *shadow = &sdev->preemphasis;
1008 break;
1009
1010 default:
1011 rval = -EINVAL;
1012 }
1013
1014 return rval;
1015}
1016
1017static int si4713_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
1018
1019/* write string property */
1020static int si4713_write_econtrol_string(struct si4713_device *sdev,
1021 struct v4l2_ext_control *control)
1022{
1023 struct v4l2_queryctrl vqc;
1024 int len;
1025 s32 rval = 0;
1026
1027 vqc.id = control->id;
1028 rval = si4713_queryctrl(&sdev->sd, &vqc);
1029 if (rval < 0)
1030 goto exit;
1031
1032 switch (control->id) {
1033 case V4L2_CID_RDS_TX_PS_NAME: {
1034 char ps_name[MAX_RDS_PS_NAME + 1];
1035
1036 len = control->size - 1;
1037 if (len < 0 || len > MAX_RDS_PS_NAME) {
1038 rval = -ERANGE;
1039 goto exit;
1040 }
1041 rval = copy_from_user(ps_name, control->string, len);
1042 if (rval) {
1043 rval = -EFAULT;
1044 goto exit;
1045 }
1046 ps_name[len] = '\0';
1047
1048 if (strlen(ps_name) % vqc.step) {
1049 rval = -ERANGE;
1050 goto exit;
1051 }
1052
1053 rval = si4713_set_rds_ps_name(sdev, ps_name);
1054 }
1055 break;
1056
1057 case V4L2_CID_RDS_TX_RADIO_TEXT: {
1058 char radio_text[MAX_RDS_RADIO_TEXT + 1];
1059
1060 len = control->size - 1;
1061 if (len < 0 || len > MAX_RDS_RADIO_TEXT) {
1062 rval = -ERANGE;
1063 goto exit;
1064 }
1065 rval = copy_from_user(radio_text, control->string, len);
1066 if (rval) {
1067 rval = -EFAULT;
1068 goto exit;
1069 }
1070 radio_text[len] = '\0';
1071
1072 if (strlen(radio_text) % vqc.step) {
1073 rval = -ERANGE;
1074 goto exit;
1075 }
1076
1077 rval = si4713_set_rds_radio_text(sdev, radio_text);
1078 }
1079 break; 967 break;
1080 968
1081 default: 969 default:
@@ -1083,136 +971,10 @@ static int si4713_write_econtrol_string(struct si4713_device *sdev,
1083 break; 971 break;
1084 } 972 }
1085 973
1086exit:
1087 return rval;
1088}
1089
1090static int validate_range(struct v4l2_subdev *sd,
1091 struct v4l2_ext_control *control)
1092{
1093 struct v4l2_queryctrl vqc;
1094 int rval;
1095
1096 vqc.id = control->id;
1097 rval = si4713_queryctrl(sd, &vqc);
1098 if (rval < 0)
1099 goto exit;
1100
1101 if (control->value < vqc.minimum || control->value > vqc.maximum)
1102 rval = -ERANGE;
1103
1104exit:
1105 return rval;
1106}
1107
1108/* properties which use tx_tune_power*/
1109static int si4713_write_econtrol_tune(struct si4713_device *sdev,
1110 struct v4l2_ext_control *control)
1111{
1112 s32 rval = 0;
1113 u8 power, antcap;
1114
1115 rval = validate_range(&sdev->sd, control);
1116 if (rval < 0)
1117 goto exit;
1118
1119 mutex_lock(&sdev->mutex);
1120
1121 switch (control->id) {
1122 case V4L2_CID_TUNE_POWER_LEVEL:
1123 power = control->value;
1124 antcap = sdev->antenna_capacitor;
1125 break;
1126 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1127 power = sdev->power_level;
1128 antcap = control->value;
1129 break;
1130 default:
1131 rval = -EINVAL;
1132 goto unlock;
1133 }
1134
1135 if (sdev->power_state)
1136 rval = si4713_tx_tune_power(sdev, power, antcap);
1137
1138 if (rval == 0) {
1139 sdev->power_level = power;
1140 sdev->antenna_capacitor = antcap;
1141 }
1142
1143unlock:
1144 mutex_unlock(&sdev->mutex);
1145exit:
1146 return rval;
1147}
1148
1149static int si4713_write_econtrol_integers(struct si4713_device *sdev,
1150 struct v4l2_ext_control *control)
1151{
1152 s32 rval;
1153 u32 *shadow = NULL, val = 0;
1154 s32 bit = 0, mask = 0;
1155 u16 property = 0;
1156 int mul = 0;
1157 unsigned long *table = NULL;
1158 int size = 0;
1159
1160 rval = validate_range(&sdev->sd, control);
1161 if (rval < 0)
1162 goto exit;
1163
1164 rval = si4713_choose_econtrol_action(sdev, control->id, &shadow, &bit,
1165 &mask, &property, &mul, &table, &size);
1166 if (rval < 0)
1167 goto exit;
1168
1169 val = control->value;
1170 if (mul) {
1171 val = control->value / mul;
1172 } else if (table) {
1173 rval = usecs_to_dev(control->value, table, size);
1174 if (rval < 0)
1175 goto exit;
1176 val = rval;
1177 rval = 0;
1178 }
1179
1180 mutex_lock(&sdev->mutex);
1181
1182 if (sdev->power_state) {
1183 if (mask) {
1184 rval = si4713_read_property(sdev, property, &val);
1185 if (rval < 0)
1186 goto unlock;
1187 val = set_bits(val, control->value, bit, mask);
1188 }
1189
1190 rval = si4713_write_property(sdev, property, val);
1191 if (rval < 0)
1192 goto unlock;
1193 if (mask)
1194 val = control->value;
1195 }
1196
1197 if (mul) {
1198 *shadow = val * mul;
1199 } else if (table) {
1200 rval = dev_to_usecs(val, table, size);
1201 if (rval < 0)
1202 goto unlock;
1203 *shadow = rval;
1204 rval = 0;
1205 } else {
1206 *shadow = val;
1207 }
1208
1209unlock:
1210 mutex_unlock(&sdev->mutex);
1211exit:
1212 return rval; 974 return rval;
1213} 975}
1214 976
1215static int si4713_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f); 977static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);
1216static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *); 978static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);
1217/* 979/*
1218 * si4713_setup - Sets the device up with current configuration. 980 * si4713_setup - Sets the device up with current configuration.
@@ -1220,111 +982,25 @@ static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulato
1220 */ 982 */
1221static int si4713_setup(struct si4713_device *sdev) 983static int si4713_setup(struct si4713_device *sdev)
1222{ 984{
1223 struct v4l2_ext_control ctrl;
1224 struct v4l2_frequency f; 985 struct v4l2_frequency f;
1225 struct v4l2_modulator vm; 986 struct v4l2_modulator vm;
1226 struct si4713_device *tmp; 987 int rval;
1227 int rval = 0;
1228
1229 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
1230 if (!tmp)
1231 return -ENOMEM;
1232
1233 /* Get a local copy to avoid race */
1234 mutex_lock(&sdev->mutex);
1235 memcpy(tmp, sdev, sizeof(*sdev));
1236 mutex_unlock(&sdev->mutex);
1237
1238 ctrl.id = V4L2_CID_RDS_TX_PI;
1239 ctrl.value = tmp->rds_info.pi;
1240 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1241
1242 ctrl.id = V4L2_CID_AUDIO_COMPRESSION_THRESHOLD;
1243 ctrl.value = tmp->acomp_info.threshold;
1244 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1245
1246 ctrl.id = V4L2_CID_AUDIO_COMPRESSION_GAIN;
1247 ctrl.value = tmp->acomp_info.gain;
1248 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1249
1250 ctrl.id = V4L2_CID_PILOT_TONE_FREQUENCY;
1251 ctrl.value = tmp->pilot_info.frequency;
1252 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1253
1254 ctrl.id = V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME;
1255 ctrl.value = tmp->acomp_info.attack_time;
1256 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1257
1258 ctrl.id = V4L2_CID_PILOT_TONE_DEVIATION;
1259 ctrl.value = tmp->pilot_info.deviation;
1260 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1261
1262 ctrl.id = V4L2_CID_AUDIO_LIMITER_DEVIATION;
1263 ctrl.value = tmp->limiter_info.deviation;
1264 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1265
1266 ctrl.id = V4L2_CID_RDS_TX_DEVIATION;
1267 ctrl.value = tmp->rds_info.deviation;
1268 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1269
1270 ctrl.id = V4L2_CID_RDS_TX_PTY;
1271 ctrl.value = tmp->rds_info.pty;
1272 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1273
1274 ctrl.id = V4L2_CID_AUDIO_LIMITER_ENABLED;
1275 ctrl.value = tmp->limiter_info.enabled;
1276 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1277
1278 ctrl.id = V4L2_CID_AUDIO_COMPRESSION_ENABLED;
1279 ctrl.value = tmp->acomp_info.enabled;
1280 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1281
1282 ctrl.id = V4L2_CID_PILOT_TONE_ENABLED;
1283 ctrl.value = tmp->pilot_info.enabled;
1284 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1285
1286 ctrl.id = V4L2_CID_AUDIO_LIMITER_RELEASE_TIME;
1287 ctrl.value = tmp->limiter_info.release_time;
1288 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1289
1290 ctrl.id = V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME;
1291 ctrl.value = tmp->acomp_info.release_time;
1292 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1293
1294 ctrl.id = V4L2_CID_TUNE_PREEMPHASIS;
1295 ctrl.value = tmp->preemphasis;
1296 rval |= si4713_write_econtrol_integers(sdev, &ctrl);
1297
1298 ctrl.id = V4L2_CID_RDS_TX_PS_NAME;
1299 rval |= si4713_set_rds_ps_name(sdev, tmp->rds_info.ps_name);
1300
1301 ctrl.id = V4L2_CID_RDS_TX_RADIO_TEXT;
1302 rval |= si4713_set_rds_radio_text(sdev, tmp->rds_info.radio_text);
1303 988
1304 /* Device procedure needs to set frequency first */ 989 /* Device procedure needs to set frequency first */
1305 f.frequency = tmp->frequency ? tmp->frequency : DEFAULT_FREQUENCY; 990 f.tuner = 0;
991 f.frequency = sdev->frequency ? sdev->frequency : DEFAULT_FREQUENCY;
1306 f.frequency = si4713_to_v4l2(f.frequency); 992 f.frequency = si4713_to_v4l2(f.frequency);
1307 rval |= si4713_s_frequency(&sdev->sd, &f); 993 rval = si4713_s_frequency(&sdev->sd, &f);
1308
1309 ctrl.id = V4L2_CID_TUNE_POWER_LEVEL;
1310 ctrl.value = tmp->power_level;
1311 rval |= si4713_write_econtrol_tune(sdev, &ctrl);
1312
1313 ctrl.id = V4L2_CID_TUNE_ANTENNA_CAPACITOR;
1314 ctrl.value = tmp->antenna_capacitor;
1315 rval |= si4713_write_econtrol_tune(sdev, &ctrl);
1316 994
1317 vm.index = 0; 995 vm.index = 0;
1318 if (tmp->stereo) 996 if (sdev->stereo)
1319 vm.txsubchans = V4L2_TUNER_SUB_STEREO; 997 vm.txsubchans = V4L2_TUNER_SUB_STEREO;
1320 else 998 else
1321 vm.txsubchans = V4L2_TUNER_SUB_MONO; 999 vm.txsubchans = V4L2_TUNER_SUB_MONO;
1322 if (tmp->rds_info.enabled) 1000 if (sdev->rds_enabled)
1323 vm.txsubchans |= V4L2_TUNER_SUB_RDS; 1001 vm.txsubchans |= V4L2_TUNER_SUB_RDS;
1324 si4713_s_modulator(&sdev->sd, &vm); 1002 si4713_s_modulator(&sdev->sd, &vm);
1325 1003
1326 kfree(tmp);
1327
1328 return rval; 1004 return rval;
1329} 1005}
1330 1006
@@ -1338,434 +1014,126 @@ static int si4713_initialize(struct si4713_device *sdev)
1338 1014
1339 rval = si4713_set_power_state(sdev, POWER_ON); 1015 rval = si4713_set_power_state(sdev, POWER_ON);
1340 if (rval < 0) 1016 if (rval < 0)
1341 goto exit; 1017 return rval;
1342 1018
1343 rval = si4713_checkrev(sdev); 1019 rval = si4713_checkrev(sdev);
1344 if (rval < 0) 1020 if (rval < 0)
1345 goto exit; 1021 return rval;
1346 1022
1347 rval = si4713_set_power_state(sdev, POWER_OFF); 1023 rval = si4713_set_power_state(sdev, POWER_OFF);
1348 if (rval < 0) 1024 if (rval < 0)
1349 goto exit; 1025 return rval;
1350
1351 mutex_lock(&sdev->mutex);
1352
1353 sdev->rds_info.pi = DEFAULT_RDS_PI;
1354 sdev->rds_info.pty = DEFAULT_RDS_PTY;
1355 sdev->rds_info.deviation = DEFAULT_RDS_DEVIATION;
1356 strlcpy(sdev->rds_info.ps_name, DEFAULT_RDS_PS_NAME, MAX_RDS_PS_NAME);
1357 strlcpy(sdev->rds_info.radio_text, DEFAULT_RDS_RADIO_TEXT,
1358 MAX_RDS_RADIO_TEXT);
1359 sdev->rds_info.enabled = 1;
1360
1361 sdev->limiter_info.release_time = DEFAULT_LIMITER_RTIME;
1362 sdev->limiter_info.deviation = DEFAULT_LIMITER_DEV;
1363 sdev->limiter_info.enabled = 1;
1364
1365 sdev->pilot_info.deviation = DEFAULT_PILOT_DEVIATION;
1366 sdev->pilot_info.frequency = DEFAULT_PILOT_FREQUENCY;
1367 sdev->pilot_info.enabled = 1;
1368 1026
1369 sdev->acomp_info.release_time = DEFAULT_ACOMP_RTIME;
1370 sdev->acomp_info.attack_time = DEFAULT_ACOMP_ATIME;
1371 sdev->acomp_info.threshold = DEFAULT_ACOMP_THRESHOLD;
1372 sdev->acomp_info.gain = DEFAULT_ACOMP_GAIN;
1373 sdev->acomp_info.enabled = 1;
1374 1027
1375 sdev->frequency = DEFAULT_FREQUENCY; 1028 sdev->frequency = DEFAULT_FREQUENCY;
1376 sdev->preemphasis = DEFAULT_PREEMPHASIS;
1377 sdev->mute = DEFAULT_MUTE;
1378 sdev->power_level = DEFAULT_POWER_LEVEL;
1379 sdev->antenna_capacitor = 0;
1380 sdev->stereo = 1; 1029 sdev->stereo = 1;
1381 sdev->tune_rnl = DEFAULT_TUNE_RNL; 1030 sdev->tune_rnl = DEFAULT_TUNE_RNL;
1382 1031 return 0;
1383 mutex_unlock(&sdev->mutex);
1384
1385exit:
1386 return rval;
1387}
1388
1389/* read string property */
1390static int si4713_read_econtrol_string(struct si4713_device *sdev,
1391 struct v4l2_ext_control *control)
1392{
1393 s32 rval = 0;
1394
1395 switch (control->id) {
1396 case V4L2_CID_RDS_TX_PS_NAME:
1397 if (strlen(sdev->rds_info.ps_name) + 1 > control->size) {
1398 control->size = MAX_RDS_PS_NAME + 1;
1399 rval = -ENOSPC;
1400 goto exit;
1401 }
1402 rval = copy_to_user(control->string, sdev->rds_info.ps_name,
1403 strlen(sdev->rds_info.ps_name) + 1);
1404 if (rval)
1405 rval = -EFAULT;
1406 break;
1407
1408 case V4L2_CID_RDS_TX_RADIO_TEXT:
1409 if (strlen(sdev->rds_info.radio_text) + 1 > control->size) {
1410 control->size = MAX_RDS_RADIO_TEXT + 1;
1411 rval = -ENOSPC;
1412 goto exit;
1413 }
1414 rval = copy_to_user(control->string, sdev->rds_info.radio_text,
1415 strlen(sdev->rds_info.radio_text) + 1);
1416 if (rval)
1417 rval = -EFAULT;
1418 break;
1419
1420 default:
1421 rval = -EINVAL;
1422 break;
1423 }
1424
1425exit:
1426 return rval;
1427}
1428
1429/*
1430 * si4713_update_tune_status - update properties from tx_tune_status
1431 * command. Must be called with sdev->mutex held.
1432 * @sdev: si4713_device structure for the device we are communicating
1433 */
1434static int si4713_update_tune_status(struct si4713_device *sdev)
1435{
1436 int rval;
1437 u16 f = 0;
1438 u8 p = 0, a = 0, n = 0;
1439
1440 rval = si4713_tx_tune_status(sdev, 0x00, &f, &p, &a, &n);
1441
1442 if (rval < 0)
1443 goto exit;
1444
1445 sdev->power_level = p;
1446 sdev->antenna_capacitor = a;
1447 sdev->tune_rnl = n;
1448
1449exit:
1450 return rval;
1451}
1452
1453/* properties which use tx_tune_status */
1454static int si4713_read_econtrol_tune(struct si4713_device *sdev,
1455 struct v4l2_ext_control *control)
1456{
1457 s32 rval = 0;
1458
1459 mutex_lock(&sdev->mutex);
1460
1461 if (sdev->power_state) {
1462 rval = si4713_update_tune_status(sdev);
1463 if (rval < 0)
1464 goto unlock;
1465 }
1466
1467 switch (control->id) {
1468 case V4L2_CID_TUNE_POWER_LEVEL:
1469 control->value = sdev->power_level;
1470 break;
1471 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1472 control->value = sdev->antenna_capacitor;
1473 break;
1474 default:
1475 rval = -EINVAL;
1476 }
1477
1478unlock:
1479 mutex_unlock(&sdev->mutex);
1480 return rval;
1481} 1032}
1482 1033
1483static int si4713_read_econtrol_integers(struct si4713_device *sdev, 1034/* si4713_s_ctrl - set the value of a control */
1484 struct v4l2_ext_control *control) 1035static int si4713_s_ctrl(struct v4l2_ctrl *ctrl)
1485{ 1036{
1486 s32 rval; 1037 struct si4713_device *sdev =
1487 u32 *shadow = NULL, val = 0; 1038 container_of(ctrl->handler, struct si4713_device, ctrl_handler);
1039 u32 val = 0;
1488 s32 bit = 0, mask = 0; 1040 s32 bit = 0, mask = 0;
1489 u16 property = 0; 1041 u16 property = 0;
1490 int mul = 0; 1042 int mul = 0;
1491 unsigned long *table = NULL; 1043 unsigned long *table = NULL;
1492 int size = 0; 1044 int size = 0;
1045 bool force = false;
1046 int c;
1047 int ret = 0;
1493 1048
1494 rval = si4713_choose_econtrol_action(sdev, control->id, &shadow, &bit, 1049 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
1495 &mask, &property, &mul, &table, &size);
1496 if (rval < 0)
1497 goto exit;
1498
1499 mutex_lock(&sdev->mutex);
1500
1501 if (sdev->power_state) {
1502 rval = si4713_read_property(sdev, property, &val);
1503 if (rval < 0)
1504 goto unlock;
1505
1506 /* Keep negative values for threshold */
1507 if (control->id == V4L2_CID_AUDIO_COMPRESSION_THRESHOLD)
1508 *shadow = (s16)val;
1509 else if (mask)
1510 *shadow = get_status_bit(val, bit, mask);
1511 else if (mul)
1512 *shadow = val * mul;
1513 else
1514 *shadow = dev_to_usecs(val, table, size);
1515 }
1516
1517 control->value = *shadow;
1518
1519unlock:
1520 mutex_unlock(&sdev->mutex);
1521exit:
1522 return rval;
1523}
1524
1525/*
1526 * Video4Linux Subdev Interface
1527 */
1528/* si4713_s_ext_ctrls - set extended controls value */
1529static int si4713_s_ext_ctrls(struct v4l2_subdev *sd,
1530 struct v4l2_ext_controls *ctrls)
1531{
1532 struct si4713_device *sdev = to_si4713_device(sd);
1533 int i;
1534
1535 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_FM_TX)
1536 return -EINVAL; 1050 return -EINVAL;
1537 1051 if (ctrl->is_new) {
1538 for (i = 0; i < ctrls->count; i++) { 1052 if (ctrl->val) {
1539 int err; 1053 ret = si4713_set_mute(sdev, ctrl->val);
1540 1054 if (!ret)
1541 switch ((ctrls->controls + i)->id) { 1055 ret = si4713_set_power_state(sdev, POWER_DOWN);
1542 case V4L2_CID_RDS_TX_PS_NAME: 1056 return ret;
1543 case V4L2_CID_RDS_TX_RADIO_TEXT:
1544 err = si4713_write_econtrol_string(sdev,
1545 ctrls->controls + i);
1546 break;
1547 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1548 case V4L2_CID_TUNE_POWER_LEVEL:
1549 err = si4713_write_econtrol_tune(sdev,
1550 ctrls->controls + i);
1551 break;
1552 default:
1553 err = si4713_write_econtrol_integers(sdev,
1554 ctrls->controls + i);
1555 }
1556
1557 if (err < 0) {
1558 ctrls->error_idx = i;
1559 return err;
1560 } 1057 }
1058 ret = si4713_set_power_state(sdev, POWER_UP);
1059 if (!ret)
1060 ret = si4713_set_mute(sdev, ctrl->val);
1061 if (!ret)
1062 ret = si4713_setup(sdev);
1063 if (ret)
1064 return ret;
1065 force = true;
1561 } 1066 }
1562 1067
1563 return 0; 1068 if (!sdev->power_state)
1564} 1069 return 0;
1565 1070
1566/* si4713_g_ext_ctrls - get extended controls value */ 1071 for (c = 1; !ret && c < ctrl->ncontrols; c++) {
1567static int si4713_g_ext_ctrls(struct v4l2_subdev *sd, 1072 ctrl = ctrl->cluster[c];
1568 struct v4l2_ext_controls *ctrls)
1569{
1570 struct si4713_device *sdev = to_si4713_device(sd);
1571 int i;
1572 1073
1573 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_FM_TX) 1074 if (!force && !ctrl->is_new)
1574 return -EINVAL; 1075 continue;
1575 1076
1576 for (i = 0; i < ctrls->count; i++) { 1077 switch (ctrl->id) {
1577 int err;
1578
1579 switch ((ctrls->controls + i)->id) {
1580 case V4L2_CID_RDS_TX_PS_NAME: 1078 case V4L2_CID_RDS_TX_PS_NAME:
1079 ret = si4713_set_rds_ps_name(sdev, ctrl->string);
1080 break;
1081
1581 case V4L2_CID_RDS_TX_RADIO_TEXT: 1082 case V4L2_CID_RDS_TX_RADIO_TEXT:
1582 err = si4713_read_econtrol_string(sdev, 1083 ret = si4713_set_rds_radio_text(sdev, ctrl->string);
1583 ctrls->controls + i);
1584 break; 1084 break;
1085
1585 case V4L2_CID_TUNE_ANTENNA_CAPACITOR: 1086 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1087 /* don't handle this control if we force setting all
1088 * controls since in that case it will be handled by
1089 * V4L2_CID_TUNE_POWER_LEVEL. */
1090 if (force)
1091 break;
1092 /* fall through */
1586 case V4L2_CID_TUNE_POWER_LEVEL: 1093 case V4L2_CID_TUNE_POWER_LEVEL:
1587 err = si4713_read_econtrol_tune(sdev, 1094 ret = si4713_tx_tune_power(sdev,
1588 ctrls->controls + i); 1095 sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);
1096 if (!ret) {
1097 /* Make sure we don't set this twice */
1098 sdev->tune_ant_cap->is_new = false;
1099 sdev->tune_pwr_level->is_new = false;
1100 }
1589 break; 1101 break;
1590 default:
1591 err = si4713_read_econtrol_integers(sdev,
1592 ctrls->controls + i);
1593 }
1594
1595 if (err < 0) {
1596 ctrls->error_idx = i;
1597 return err;
1598 }
1599 }
1600
1601 return 0;
1602}
1603
1604/* si4713_queryctrl - enumerate control items */
1605static int si4713_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1606{
1607 int rval = 0;
1608
1609 switch (qc->id) {
1610 /* User class controls */
1611 case V4L2_CID_AUDIO_MUTE:
1612 rval = v4l2_ctrl_query_fill(qc, 0, 1, 1, DEFAULT_MUTE);
1613 break;
1614 /* FM_TX class controls */
1615 case V4L2_CID_RDS_TX_PI:
1616 rval = v4l2_ctrl_query_fill(qc, 0, 0xFFFF, 1, DEFAULT_RDS_PI);
1617 break;
1618 case V4L2_CID_RDS_TX_PTY:
1619 rval = v4l2_ctrl_query_fill(qc, 0, 31, 1, DEFAULT_RDS_PTY);
1620 break;
1621 case V4L2_CID_RDS_TX_DEVIATION:
1622 rval = v4l2_ctrl_query_fill(qc, 0, MAX_RDS_DEVIATION,
1623 10, DEFAULT_RDS_DEVIATION);
1624 break;
1625 case V4L2_CID_RDS_TX_PS_NAME:
1626 /*
1627 * Report step as 8. From RDS spec, psname
1628 * should be 8. But there are receivers which scroll strings
1629 * sized as 8xN.
1630 */
1631 rval = v4l2_ctrl_query_fill(qc, 0, MAX_RDS_PS_NAME, 8, 0);
1632 break;
1633 case V4L2_CID_RDS_TX_RADIO_TEXT:
1634 /*
1635 * Report step as 32 (2A block). From RDS spec,
1636 * radio text should be 32 for 2A block. But there are receivers
1637 * which scroll strings sized as 32xN. Setting default to 32.
1638 */
1639 rval = v4l2_ctrl_query_fill(qc, 0, MAX_RDS_RADIO_TEXT, 32, 0);
1640 break;
1641
1642 case V4L2_CID_AUDIO_LIMITER_ENABLED:
1643 rval = v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1644 break;
1645 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
1646 rval = v4l2_ctrl_query_fill(qc, 250, MAX_LIMITER_RELEASE_TIME,
1647 50, DEFAULT_LIMITER_RTIME);
1648 break;
1649 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
1650 rval = v4l2_ctrl_query_fill(qc, 0, MAX_LIMITER_DEVIATION,
1651 10, DEFAULT_LIMITER_DEV);
1652 break;
1653
1654 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
1655 rval = v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1656 break;
1657 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
1658 rval = v4l2_ctrl_query_fill(qc, 0, MAX_ACOMP_GAIN, 1,
1659 DEFAULT_ACOMP_GAIN);
1660 break;
1661 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
1662 rval = v4l2_ctrl_query_fill(qc, MIN_ACOMP_THRESHOLD,
1663 MAX_ACOMP_THRESHOLD, 1,
1664 DEFAULT_ACOMP_THRESHOLD);
1665 break;
1666 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
1667 rval = v4l2_ctrl_query_fill(qc, 0, MAX_ACOMP_ATTACK_TIME,
1668 500, DEFAULT_ACOMP_ATIME);
1669 break;
1670 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
1671 rval = v4l2_ctrl_query_fill(qc, 100000, MAX_ACOMP_RELEASE_TIME,
1672 100000, DEFAULT_ACOMP_RTIME);
1673 break;
1674
1675 case V4L2_CID_PILOT_TONE_ENABLED:
1676 rval = v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1677 break;
1678 case V4L2_CID_PILOT_TONE_DEVIATION:
1679 rval = v4l2_ctrl_query_fill(qc, 0, MAX_PILOT_DEVIATION,
1680 10, DEFAULT_PILOT_DEVIATION);
1681 break;
1682 case V4L2_CID_PILOT_TONE_FREQUENCY:
1683 rval = v4l2_ctrl_query_fill(qc, 0, MAX_PILOT_FREQUENCY,
1684 1, DEFAULT_PILOT_FREQUENCY);
1685 break;
1686
1687 case V4L2_CID_TUNE_PREEMPHASIS:
1688 rval = v4l2_ctrl_query_fill(qc, V4L2_PREEMPHASIS_DISABLED,
1689 V4L2_PREEMPHASIS_75_uS, 1,
1690 V4L2_PREEMPHASIS_50_uS);
1691 break;
1692 case V4L2_CID_TUNE_POWER_LEVEL:
1693 rval = v4l2_ctrl_query_fill(qc, 0, 120, 1, DEFAULT_POWER_LEVEL);
1694 break;
1695 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1696 rval = v4l2_ctrl_query_fill(qc, 0, 191, 1, 0);
1697 break;
1698 default:
1699 rval = -EINVAL;
1700 break;
1701 }
1702
1703 return rval;
1704}
1705
1706/* si4713_g_ctrl - get the value of a control */
1707static int si4713_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1708{
1709 struct si4713_device *sdev = to_si4713_device(sd);
1710 int rval = 0;
1711
1712 if (!sdev)
1713 return -ENODEV;
1714
1715 mutex_lock(&sdev->mutex);
1716
1717 if (sdev->power_state) {
1718 rval = si4713_read_property(sdev, SI4713_TX_LINE_INPUT_MUTE,
1719 &sdev->mute);
1720
1721 if (rval < 0)
1722 goto unlock;
1723 }
1724
1725 switch (ctrl->id) {
1726 case V4L2_CID_AUDIO_MUTE:
1727 ctrl->value = get_mute(sdev->mute);
1728 break;
1729 }
1730
1731unlock:
1732 mutex_unlock(&sdev->mutex);
1733 return rval;
1734}
1735
1736/* si4713_s_ctrl - set the value of a control */
1737static int si4713_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1738{
1739 struct si4713_device *sdev = to_si4713_device(sd);
1740 int rval = 0;
1741
1742 if (!sdev)
1743 return -ENODEV;
1744
1745 switch (ctrl->id) {
1746 case V4L2_CID_AUDIO_MUTE:
1747 if (ctrl->value) {
1748 rval = si4713_set_mute(sdev, ctrl->value);
1749 if (rval < 0)
1750 goto exit;
1751 1102
1752 rval = si4713_set_power_state(sdev, POWER_DOWN); 1103 default:
1753 } else { 1104 ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,
1754 rval = si4713_set_power_state(sdev, POWER_UP); 1105 &mask, &property, &mul, &table, &size);
1755 if (rval < 0) 1106 if (ret < 0)
1756 goto exit; 1107 break;
1108
1109 val = ctrl->val;
1110 if (mul) {
1111 val = val / mul;
1112 } else if (table) {
1113 ret = usecs_to_dev(val, table, size);
1114 if (ret < 0)
1115 break;
1116 val = ret;
1117 ret = 0;
1118 }
1757 1119
1758 rval = si4713_setup(sdev); 1120 if (mask) {
1759 if (rval < 0) 1121 ret = si4713_read_property(sdev, property, &val);
1760 goto exit; 1122 if (ret < 0)
1123 break;
1124 val = set_bits(val, ctrl->val, bit, mask);
1125 }
1761 1126
1762 rval = si4713_set_mute(sdev, ctrl->value); 1127 ret = si4713_write_property(sdev, property, val);
1128 if (ret < 0)
1129 break;
1130 if (mask)
1131 val = ctrl->val;
1132 break;
1763 } 1133 }
1764 break;
1765 } 1134 }
1766 1135
1767exit: 1136 return ret;
1768 return rval;
1769} 1137}
1770 1138
1771/* si4713_ioctl - deal with private ioctls (only rnl for now) */ 1139/* si4713_ioctl - deal with private ioctls (only rnl for now) */
@@ -1779,7 +1147,6 @@ static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1779 if (!arg) 1147 if (!arg)
1780 return -EINVAL; 1148 return -EINVAL;
1781 1149
1782 mutex_lock(&sdev->mutex);
1783 switch (cmd) { 1150 switch (cmd) {
1784 case SI4713_IOC_MEASURE_RNL: 1151 case SI4713_IOC_MEASURE_RNL:
1785 frequency = v4l2_to_si4713(rnl->frequency); 1152 frequency = v4l2_to_si4713(rnl->frequency);
@@ -1788,11 +1155,11 @@ static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1788 /* Set desired measurement frequency */ 1155 /* Set desired measurement frequency */
1789 rval = si4713_tx_tune_measure(sdev, frequency, 0); 1156 rval = si4713_tx_tune_measure(sdev, frequency, 0);
1790 if (rval < 0) 1157 if (rval < 0)
1791 goto unlock; 1158 return rval;
1792 /* get results from tune status */ 1159 /* get results from tune status */
1793 rval = si4713_update_tune_status(sdev); 1160 rval = si4713_update_tune_status(sdev);
1794 if (rval < 0) 1161 if (rval < 0)
1795 goto unlock; 1162 return rval;
1796 } 1163 }
1797 rnl->rnl = sdev->tune_rnl; 1164 rnl->rnl = sdev->tune_rnl;
1798 break; 1165 break;
@@ -1802,35 +1169,20 @@ static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1802 rval = -ENOIOCTLCMD; 1169 rval = -ENOIOCTLCMD;
1803 } 1170 }
1804 1171
1805unlock:
1806 mutex_unlock(&sdev->mutex);
1807 return rval; 1172 return rval;
1808} 1173}
1809 1174
1810static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = {
1811 .queryctrl = si4713_queryctrl,
1812 .g_ext_ctrls = si4713_g_ext_ctrls,
1813 .s_ext_ctrls = si4713_s_ext_ctrls,
1814 .g_ctrl = si4713_g_ctrl,
1815 .s_ctrl = si4713_s_ctrl,
1816 .ioctl = si4713_ioctl,
1817};
1818
1819/* si4713_g_modulator - get modulator attributes */ 1175/* si4713_g_modulator - get modulator attributes */
1820static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm) 1176static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1821{ 1177{
1822 struct si4713_device *sdev = to_si4713_device(sd); 1178 struct si4713_device *sdev = to_si4713_device(sd);
1823 int rval = 0; 1179 int rval = 0;
1824 1180
1825 if (!sdev) { 1181 if (!sdev)
1826 rval = -ENODEV; 1182 return -ENODEV;
1827 goto exit;
1828 }
1829 1183
1830 if (vm->index > 0) { 1184 if (vm->index > 0)
1831 rval = -EINVAL; 1185 return -EINVAL;
1832 goto exit;
1833 }
1834 1186
1835 strncpy(vm->name, "FM Modulator", 32); 1187 strncpy(vm->name, "FM Modulator", 32);
1836 vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW | 1188 vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW |
@@ -1840,18 +1192,15 @@ static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1840 vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW); 1192 vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW);
1841 vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH); 1193 vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH);
1842 1194
1843 mutex_lock(&sdev->mutex);
1844
1845 if (sdev->power_state) { 1195 if (sdev->power_state) {
1846 u32 comp_en = 0; 1196 u32 comp_en = 0;
1847 1197
1848 rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE, 1198 rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE,
1849 &comp_en); 1199 &comp_en);
1850 if (rval < 0) 1200 if (rval < 0)
1851 goto unlock; 1201 return rval;
1852 1202
1853 sdev->stereo = get_status_bit(comp_en, 1, 1 << 1); 1203 sdev->stereo = get_status_bit(comp_en, 1, 1 << 1);
1854 sdev->rds_info.enabled = get_status_bit(comp_en, 2, 1 << 2);
1855 } 1204 }
1856 1205
1857 /* Report current audio mode: mono or stereo */ 1206 /* Report current audio mode: mono or stereo */
@@ -1861,14 +1210,11 @@ static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1861 vm->txsubchans = V4L2_TUNER_SUB_MONO; 1210 vm->txsubchans = V4L2_TUNER_SUB_MONO;
1862 1211
1863 /* Report rds feature status */ 1212 /* Report rds feature status */
1864 if (sdev->rds_info.enabled) 1213 if (sdev->rds_enabled)
1865 vm->txsubchans |= V4L2_TUNER_SUB_RDS; 1214 vm->txsubchans |= V4L2_TUNER_SUB_RDS;
1866 else 1215 else
1867 vm->txsubchans &= ~V4L2_TUNER_SUB_RDS; 1216 vm->txsubchans &= ~V4L2_TUNER_SUB_RDS;
1868 1217
1869unlock:
1870 mutex_unlock(&sdev->mutex);
1871exit:
1872 return rval; 1218 return rval;
1873} 1219}
1874 1220
@@ -1896,13 +1242,11 @@ static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulato
1896 1242
1897 rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS); 1243 rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS);
1898 1244
1899 mutex_lock(&sdev->mutex);
1900
1901 if (sdev->power_state) { 1245 if (sdev->power_state) {
1902 rval = si4713_read_property(sdev, 1246 rval = si4713_read_property(sdev,
1903 SI4713_TX_COMPONENT_ENABLE, &p); 1247 SI4713_TX_COMPONENT_ENABLE, &p);
1904 if (rval < 0) 1248 if (rval < 0)
1905 goto unlock; 1249 return rval;
1906 1250
1907 p = set_bits(p, stereo, 1, 1 << 1); 1251 p = set_bits(p, stereo, 1, 1 << 1);
1908 p = set_bits(p, rds, 2, 1 << 2); 1252 p = set_bits(p, rds, 2, 1 << 2);
@@ -1910,14 +1254,12 @@ static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulato
1910 rval = si4713_write_property(sdev, 1254 rval = si4713_write_property(sdev,
1911 SI4713_TX_COMPONENT_ENABLE, p); 1255 SI4713_TX_COMPONENT_ENABLE, p);
1912 if (rval < 0) 1256 if (rval < 0)
1913 goto unlock; 1257 return rval;
1914 } 1258 }
1915 1259
1916 sdev->stereo = stereo; 1260 sdev->stereo = stereo;
1917 sdev->rds_info.enabled = rds; 1261 sdev->rds_enabled = rds;
1918 1262
1919unlock:
1920 mutex_unlock(&sdev->mutex);
1921 return rval; 1263 return rval;
1922} 1264}
1923 1265
@@ -1927,9 +1269,8 @@ static int si4713_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
1927 struct si4713_device *sdev = to_si4713_device(sd); 1269 struct si4713_device *sdev = to_si4713_device(sd);
1928 int rval = 0; 1270 int rval = 0;
1929 1271
1930 f->type = V4L2_TUNER_RADIO; 1272 if (f->tuner)
1931 1273 return -EINVAL;
1932 mutex_lock(&sdev->mutex);
1933 1274
1934 if (sdev->power_state) { 1275 if (sdev->power_state) {
1935 u16 freq; 1276 u16 freq;
@@ -1937,46 +1278,49 @@ static int si4713_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
1937 1278
1938 rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n); 1279 rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n);
1939 if (rval < 0) 1280 if (rval < 0)
1940 goto unlock; 1281 return rval;
1941 1282
1942 sdev->frequency = freq; 1283 sdev->frequency = freq;
1943 } 1284 }
1944 1285
1945 f->frequency = si4713_to_v4l2(sdev->frequency); 1286 f->frequency = si4713_to_v4l2(sdev->frequency);
1946 1287
1947unlock:
1948 mutex_unlock(&sdev->mutex);
1949 return rval; 1288 return rval;
1950} 1289}
1951 1290
1952/* si4713_s_frequency - set tuner or modulator radio frequency */ 1291/* si4713_s_frequency - set tuner or modulator radio frequency */
1953static int si4713_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) 1292static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
1954{ 1293{
1955 struct si4713_device *sdev = to_si4713_device(sd); 1294 struct si4713_device *sdev = to_si4713_device(sd);
1956 int rval = 0; 1295 int rval = 0;
1957 u16 frequency = v4l2_to_si4713(f->frequency); 1296 u16 frequency = v4l2_to_si4713(f->frequency);
1958 1297
1959 /* Check frequency range */ 1298 if (f->tuner)
1960 if (frequency < FREQ_RANGE_LOW || frequency > FREQ_RANGE_HIGH) 1299 return -EINVAL;
1961 return -EDOM;
1962 1300
1963 mutex_lock(&sdev->mutex); 1301 /* Check frequency range */
1302 frequency = clamp_t(u16, frequency, FREQ_RANGE_LOW, FREQ_RANGE_HIGH);
1964 1303
1965 if (sdev->power_state) { 1304 if (sdev->power_state) {
1966 rval = si4713_tx_tune_freq(sdev, frequency); 1305 rval = si4713_tx_tune_freq(sdev, frequency);
1967 if (rval < 0) 1306 if (rval < 0)
1968 goto unlock; 1307 return rval;
1969 frequency = rval; 1308 frequency = rval;
1970 rval = 0; 1309 rval = 0;
1971 } 1310 }
1972 sdev->frequency = frequency; 1311 sdev->frequency = frequency;
1973 f->frequency = si4713_to_v4l2(frequency);
1974 1312
1975unlock:
1976 mutex_unlock(&sdev->mutex);
1977 return rval; 1313 return rval;
1978} 1314}
1979 1315
1316static const struct v4l2_ctrl_ops si4713_ctrl_ops = {
1317 .s_ctrl = si4713_s_ctrl,
1318};
1319
1320static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = {
1321 .ioctl = si4713_ioctl,
1322};
1323
1980static const struct v4l2_subdev_tuner_ops si4713_subdev_tuner_ops = { 1324static const struct v4l2_subdev_tuner_ops si4713_subdev_tuner_ops = {
1981 .g_frequency = si4713_g_frequency, 1325 .g_frequency = si4713_g_frequency,
1982 .s_frequency = si4713_s_frequency, 1326 .s_frequency = si4713_s_frequency,
@@ -1998,6 +1342,7 @@ static int si4713_probe(struct i2c_client *client,
1998{ 1342{
1999 struct si4713_device *sdev; 1343 struct si4713_device *sdev;
2000 struct si4713_platform_data *pdata = client->dev.platform_data; 1344 struct si4713_platform_data *pdata = client->dev.platform_data;
1345 struct v4l2_ctrl_handler *hdl;
2001 int rval, i; 1346 int rval, i;
2002 1347
2003 sdev = kzalloc(sizeof *sdev, GFP_KERNEL); 1348 sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
@@ -2031,9 +1376,84 @@ static int si4713_probe(struct i2c_client *client,
2031 1376
2032 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); 1377 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops);
2033 1378
2034 mutex_init(&sdev->mutex);
2035 init_completion(&sdev->work); 1379 init_completion(&sdev->work);
2036 1380
1381 hdl = &sdev->ctrl_handler;
1382 v4l2_ctrl_handler_init(hdl, 20);
1383 sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1384 V4L2_CID_AUDIO_MUTE, 0, 1, 1, DEFAULT_MUTE);
1385
1386 sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1387 V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, DEFAULT_RDS_PI);
1388 sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1389 V4L2_CID_RDS_TX_PTY, 0, 31, 1, DEFAULT_RDS_PTY);
1390 sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1391 V4L2_CID_RDS_TX_DEVIATION, 0, MAX_RDS_DEVIATION,
1392 10, DEFAULT_RDS_DEVIATION);
1393 /*
1394 * Report step as 8. From RDS spec, psname
1395 * should be 8. But there are receivers which scroll strings
1396 * sized as 8xN.
1397 */
1398 sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1399 V4L2_CID_RDS_TX_PS_NAME, 0, MAX_RDS_PS_NAME, 8, 0);
1400 /*
1401 * Report step as 32 (2A block). From RDS spec,
1402 * radio text should be 32 for 2A block. But there are receivers
1403 * which scroll strings sized as 32xN. Setting default to 32.
1404 */
1405 sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1406 V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);
1407
1408 sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1409 V4L2_CID_AUDIO_LIMITER_ENABLED, 0, 1, 1, 1);
1410 sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1411 V4L2_CID_AUDIO_LIMITER_RELEASE_TIME, 250,
1412 MAX_LIMITER_RELEASE_TIME, 10, DEFAULT_LIMITER_RTIME);
1413 sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1414 V4L2_CID_AUDIO_LIMITER_DEVIATION, 0,
1415 MAX_LIMITER_DEVIATION, 10, DEFAULT_LIMITER_DEV);
1416
1417 sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1418 V4L2_CID_AUDIO_COMPRESSION_ENABLED, 0, 1, 1, 1);
1419 sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1420 V4L2_CID_AUDIO_COMPRESSION_GAIN, 0, MAX_ACOMP_GAIN, 1,
1421 DEFAULT_ACOMP_GAIN);
1422 sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1423 V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,
1424 MAX_ACOMP_THRESHOLD, 1,
1425 DEFAULT_ACOMP_THRESHOLD);
1426 sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1427 V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME, 0,
1428 MAX_ACOMP_ATTACK_TIME, 500, DEFAULT_ACOMP_ATIME);
1429 sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1430 V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME, 100000,
1431 MAX_ACOMP_RELEASE_TIME, 100000, DEFAULT_ACOMP_RTIME);
1432
1433 sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1434 V4L2_CID_PILOT_TONE_ENABLED, 0, 1, 1, 1);
1435 sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1436 V4L2_CID_PILOT_TONE_DEVIATION, 0, MAX_PILOT_DEVIATION,
1437 10, DEFAULT_PILOT_DEVIATION);
1438 sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1439 V4L2_CID_PILOT_TONE_FREQUENCY, 0, MAX_PILOT_FREQUENCY,
1440 1, DEFAULT_PILOT_FREQUENCY);
1441
1442 sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops,
1443 V4L2_CID_TUNE_PREEMPHASIS,
1444 V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
1445 sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1446 V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);
1447 sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1448 V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, 191, 1, 0);
1449
1450 if (hdl->error) {
1451 rval = hdl->error;
1452 goto free_ctrls;
1453 }
1454 v4l2_ctrl_cluster(20, &sdev->mute);
1455 sdev->sd.ctrl_handler = hdl;
1456
2037 if (client->irq) { 1457 if (client->irq) {
2038 rval = request_irq(client->irq, 1458 rval = request_irq(client->irq,
2039 si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED, 1459 si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED,
@@ -2058,6 +1478,8 @@ static int si4713_probe(struct i2c_client *client,
2058free_irq: 1478free_irq:
2059 if (client->irq) 1479 if (client->irq)
2060 free_irq(client->irq, sdev); 1480 free_irq(client->irq, sdev);
1481free_ctrls:
1482 v4l2_ctrl_handler_free(hdl);
2061put_reg: 1483put_reg:
2062 regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies); 1484 regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
2063free_gpio: 1485free_gpio:
@@ -2082,6 +1504,7 @@ static int si4713_remove(struct i2c_client *client)
2082 free_irq(client->irq, sdev); 1504 free_irq(client->irq, sdev);
2083 1505
2084 v4l2_device_unregister_subdev(sd); 1506 v4l2_device_unregister_subdev(sd);
1507 v4l2_ctrl_handler_free(sd->ctrl_handler);
2085 regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies); 1508 regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
2086 if (gpio_is_valid(sdev->gpio_reset)) 1509 if (gpio_is_valid(sdev->gpio_reset))
2087 gpio_free(sdev->gpio_reset); 1510 gpio_free(sdev->gpio_reset);
diff --git a/drivers/media/radio/si4713-i2c.h b/drivers/media/radio/si4713-i2c.h
index c6dfa7fb101c..25cdea26343b 100644
--- a/drivers/media/radio/si4713-i2c.h
+++ b/drivers/media/radio/si4713-i2c.h
@@ -16,6 +16,7 @@
16#define SI4713_I2C_H 16#define SI4713_I2C_H
17 17
18#include <media/v4l2-subdev.h> 18#include <media/v4l2-subdev.h>
19#include <media/v4l2-ctrls.h>
19#include <media/si4713.h> 20#include <media/si4713.h>
20 21
21#define SI4713_PRODUCT_NUMBER 0x0D 22#define SI4713_PRODUCT_NUMBER 0x0D
@@ -160,56 +161,33 @@
160#define POWER_UP 0x01 161#define POWER_UP 0x01
161#define POWER_DOWN 0x00 162#define POWER_DOWN 0x00
162 163
163struct rds_info {
164 u32 pi;
165#define MAX_RDS_PTY 31 164#define MAX_RDS_PTY 31
166 u32 pty;
167#define MAX_RDS_DEVIATION 90000 165#define MAX_RDS_DEVIATION 90000
168 u32 deviation; 166
169/* 167/*
170 * PSNAME is known to be defined as 8 character sized (RDS Spec). 168 * PSNAME is known to be defined as 8 character sized (RDS Spec).
171 * However, there is receivers which scroll PSNAME 8xN sized. 169 * However, there is receivers which scroll PSNAME 8xN sized.
172 */ 170 */
173#define MAX_RDS_PS_NAME 96 171#define MAX_RDS_PS_NAME 96
174 u8 ps_name[MAX_RDS_PS_NAME + 1]; 172
175/* 173/*
176 * MAX_RDS_RADIO_TEXT is known to be defined as 32 (2A group) or 64 (2B group) 174 * MAX_RDS_RADIO_TEXT is known to be defined as 32 (2A group) or 64 (2B group)
177 * character sized (RDS Spec). 175 * character sized (RDS Spec).
178 * However, there is receivers which scroll them as well. 176 * However, there is receivers which scroll them as well.
179 */ 177 */
180#define MAX_RDS_RADIO_TEXT 384 178#define MAX_RDS_RADIO_TEXT 384
181 u8 radio_text[MAX_RDS_RADIO_TEXT + 1];
182 u32 enabled;
183};
184 179
185struct limiter_info {
186#define MAX_LIMITER_RELEASE_TIME 102390 180#define MAX_LIMITER_RELEASE_TIME 102390
187 u32 release_time;
188#define MAX_LIMITER_DEVIATION 90000 181#define MAX_LIMITER_DEVIATION 90000
189 u32 deviation;
190 u32 enabled;
191};
192 182
193struct pilot_info {
194#define MAX_PILOT_DEVIATION 90000 183#define MAX_PILOT_DEVIATION 90000
195 u32 deviation;
196#define MAX_PILOT_FREQUENCY 19000 184#define MAX_PILOT_FREQUENCY 19000
197 u32 frequency;
198 u32 enabled;
199};
200 185
201struct acomp_info {
202#define MAX_ACOMP_RELEASE_TIME 1000000 186#define MAX_ACOMP_RELEASE_TIME 1000000
203 u32 release_time;
204#define MAX_ACOMP_ATTACK_TIME 5000 187#define MAX_ACOMP_ATTACK_TIME 5000
205 u32 attack_time;
206#define MAX_ACOMP_THRESHOLD 0 188#define MAX_ACOMP_THRESHOLD 0
207#define MIN_ACOMP_THRESHOLD (-40) 189#define MIN_ACOMP_THRESHOLD (-40)
208 s32 threshold;
209#define MAX_ACOMP_GAIN 20 190#define MAX_ACOMP_GAIN 20
210 u32 gain;
211 u32 enabled;
212};
213 191
214#define SI4713_NUM_SUPPLIES 2 192#define SI4713_NUM_SUPPLIES 2
215 193
@@ -219,21 +197,41 @@ struct acomp_info {
219struct si4713_device { 197struct si4713_device {
220 /* v4l2_subdev and i2c reference (v4l2_subdev priv data) */ 198 /* v4l2_subdev and i2c reference (v4l2_subdev priv data) */
221 struct v4l2_subdev sd; 199 struct v4l2_subdev sd;
200 struct v4l2_ctrl_handler ctrl_handler;
222 /* private data structures */ 201 /* private data structures */
223 struct mutex mutex; 202 struct { /* si4713 control cluster */
203 /* This is one big cluster since the mute control
204 * powers off the device and after unmuting again all
205 * controls need to be set at once. The only way of doing
206 * that is by making it one big cluster. */
207 struct v4l2_ctrl *mute;
208 struct v4l2_ctrl *rds_ps_name;
209 struct v4l2_ctrl *rds_radio_text;
210 struct v4l2_ctrl *rds_pi;
211 struct v4l2_ctrl *rds_deviation;
212 struct v4l2_ctrl *rds_pty;
213 struct v4l2_ctrl *compression_enabled;
214 struct v4l2_ctrl *compression_threshold;
215 struct v4l2_ctrl *compression_gain;
216 struct v4l2_ctrl *compression_attack_time;
217 struct v4l2_ctrl *compression_release_time;
218 struct v4l2_ctrl *pilot_tone_enabled;
219 struct v4l2_ctrl *pilot_tone_freq;
220 struct v4l2_ctrl *pilot_tone_deviation;
221 struct v4l2_ctrl *limiter_enabled;
222 struct v4l2_ctrl *limiter_deviation;
223 struct v4l2_ctrl *limiter_release_time;
224 struct v4l2_ctrl *tune_preemphasis;
225 struct v4l2_ctrl *tune_pwr_level;
226 struct v4l2_ctrl *tune_ant_cap;
227 };
224 struct completion work; 228 struct completion work;
225 struct rds_info rds_info;
226 struct limiter_info limiter_info;
227 struct pilot_info pilot_info;
228 struct acomp_info acomp_info;
229 struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES]; 229 struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
230 int gpio_reset; 230 int gpio_reset;
231 u32 power_state;
232 u32 rds_enabled;
231 u32 frequency; 233 u32 frequency;
232 u32 preemphasis; 234 u32 preemphasis;
233 u32 mute;
234 u32 power_level;
235 u32 power_state;
236 u32 antenna_capacitor;
237 u32 stereo; 235 u32 stereo;
238 u32 tune_rnl; 236 u32 tune_rnl;
239}; 237};
diff --git a/drivers/media/radio/tef6862.c b/drivers/media/radio/tef6862.c
index b18c2dc268ba..82c6c9475d7c 100644
--- a/drivers/media/radio/tef6862.c
+++ b/drivers/media/radio/tef6862.c
@@ -96,12 +96,12 @@ static int tef6862_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
96 return 0; 96 return 0;
97} 97}
98 98
99static int tef6862_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v) 99static int tef6862_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
100{ 100{
101 return v->index ? -EINVAL : 0; 101 return v->index ? -EINVAL : 0;
102} 102}
103 103
104static int tef6862_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) 104static int tef6862_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
105{ 105{
106 struct tef6862_state *state = to_state(sd); 106 struct tef6862_state *state = to_state(sd);
107 struct i2c_client *client = v4l2_get_subdevdata(sd); 107 struct i2c_client *client = v4l2_get_subdevdata(sd);
diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c
index 0a8ee8fab924..5dec323f4247 100644
--- a/drivers/media/radio/wl128x/fmdrv_v4l2.c
+++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c
@@ -331,7 +331,7 @@ static int fm_v4l2_vidioc_g_tuner(struct file *file, void *priv,
331 * Should we set other tuner attributes, too? 331 * Should we set other tuner attributes, too?
332 */ 332 */
333static int fm_v4l2_vidioc_s_tuner(struct file *file, void *priv, 333static int fm_v4l2_vidioc_s_tuner(struct file *file, void *priv,
334 struct v4l2_tuner *tuner) 334 const struct v4l2_tuner *tuner)
335{ 335{
336 struct fmdev *fmdev = video_drvdata(file); 336 struct fmdev *fmdev = video_drvdata(file);
337 u16 aud_mode; 337 u16 aud_mode;
@@ -388,7 +388,7 @@ static int fm_v4l2_vidioc_g_freq(struct file *file, void *priv,
388 388
389/* Set tuner or modulator radio frequency */ 389/* Set tuner or modulator radio frequency */
390static int fm_v4l2_vidioc_s_freq(struct file *file, void *priv, 390static int fm_v4l2_vidioc_s_freq(struct file *file, void *priv,
391 struct v4l2_frequency *freq) 391 const struct v4l2_frequency *freq)
392{ 392{
393 struct fmdev *fmdev = video_drvdata(file); 393 struct fmdev *fmdev = video_drvdata(file);
394 394
@@ -396,9 +396,7 @@ static int fm_v4l2_vidioc_s_freq(struct file *file, void *priv,
396 * As V4L2_TUNER_CAP_LOW is set 1 user sends the frequency 396 * As V4L2_TUNER_CAP_LOW is set 1 user sends the frequency
397 * in units of 62.5 Hz. 397 * in units of 62.5 Hz.
398 */ 398 */
399 freq->frequency = (u32)(freq->frequency / 16); 399 return fmc_set_freq(fmdev, freq->frequency / 16);
400
401 return fmc_set_freq(fmdev, freq->frequency);
402} 400}
403 401
404/* Set hardware frequency seek. If current mode is NOT RX, set it RX. */ 402/* Set hardware frequency seek. If current mode is NOT RX, set it RX. */
diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
index ee6c984cade2..ed184f68c17c 100644
--- a/drivers/media/rc/ene_ir.c
+++ b/drivers/media/rc/ene_ir.c
@@ -1098,6 +1098,7 @@ exit_release_hw_io:
1098 release_region(dev->hw_io, ENE_IO_SIZE); 1098 release_region(dev->hw_io, ENE_IO_SIZE);
1099exit_unregister_device: 1099exit_unregister_device:
1100 rc_unregister_device(rdev); 1100 rc_unregister_device(rdev);
1101 rdev = NULL;
1101exit_free_dev_rdev: 1102exit_free_dev_rdev:
1102 rc_free_device(rdev); 1103 rc_free_device(rdev);
1103 kfree(dev); 1104 kfree(dev);
diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index dec203bb06f6..72e3fa652481 100644
--- a/drivers/media/rc/imon.c
+++ b/drivers/media/rc/imon.c
@@ -112,6 +112,7 @@ struct imon_context {
112 bool tx_control; 112 bool tx_control;
113 unsigned char usb_rx_buf[8]; 113 unsigned char usb_rx_buf[8];
114 unsigned char usb_tx_buf[8]; 114 unsigned char usb_tx_buf[8];
115 unsigned int send_packet_delay;
115 116
116 struct tx_t { 117 struct tx_t {
117 unsigned char data_buf[35]; /* user data buffer */ 118 unsigned char data_buf[35]; /* user data buffer */
@@ -185,6 +186,10 @@ enum {
185 IMON_KEY_PANEL = 2, 186 IMON_KEY_PANEL = 2,
186}; 187};
187 188
189enum {
190 IMON_NEED_20MS_PKT_DELAY = 1
191};
192
188/* 193/*
189 * USB Device ID for iMON USB Control Boards 194 * USB Device ID for iMON USB Control Boards
190 * 195 *
@@ -215,7 +220,7 @@ static struct usb_device_id imon_usb_id_table[] = {
215 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */ 220 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */
216 { USB_DEVICE(0x15c2, 0x0035) }, 221 { USB_DEVICE(0x15c2, 0x0035) },
217 /* SoundGraph iMON OEM VFD (IR & VFD) */ 222 /* SoundGraph iMON OEM VFD (IR & VFD) */
218 { USB_DEVICE(0x15c2, 0x0036) }, 223 { USB_DEVICE(0x15c2, 0x0036), .driver_info = IMON_NEED_20MS_PKT_DELAY },
219 /* device specifics unknown */ 224 /* device specifics unknown */
220 { USB_DEVICE(0x15c2, 0x0037) }, 225 { USB_DEVICE(0x15c2, 0x0037) },
221 /* SoundGraph iMON OEM LCD (IR & LCD) */ 226 /* SoundGraph iMON OEM LCD (IR & LCD) */
@@ -523,8 +528,10 @@ static int send_packet(struct imon_context *ictx)
523 mutex_unlock(&ictx->lock); 528 mutex_unlock(&ictx->lock);
524 retval = wait_for_completion_interruptible( 529 retval = wait_for_completion_interruptible(
525 &ictx->tx.finished); 530 &ictx->tx.finished);
526 if (retval) 531 if (retval) {
532 usb_kill_urb(ictx->tx_urb);
527 pr_err_ratelimited("task interrupted\n"); 533 pr_err_ratelimited("task interrupted\n");
534 }
528 mutex_lock(&ictx->lock); 535 mutex_lock(&ictx->lock);
529 536
530 retval = ictx->tx.status; 537 retval = ictx->tx.status;
@@ -535,12 +542,12 @@ static int send_packet(struct imon_context *ictx)
535 kfree(control_req); 542 kfree(control_req);
536 543
537 /* 544 /*
538 * Induce a mandatory 5ms delay before returning, as otherwise, 545 * Induce a mandatory delay before returning, as otherwise,
539 * send_packet can get called so rapidly as to overwhelm the device, 546 * send_packet can get called so rapidly as to overwhelm the device,
540 * particularly on faster systems and/or those with quirky usb. 547 * particularly on faster systems and/or those with quirky usb.
541 */ 548 */
542 timeout = msecs_to_jiffies(5); 549 timeout = msecs_to_jiffies(ictx->send_packet_delay);
543 set_current_state(TASK_UNINTERRUPTIBLE); 550 set_current_state(TASK_INTERRUPTIBLE);
544 schedule_timeout(timeout); 551 schedule_timeout(timeout);
545 552
546 return retval; 553 return retval;
@@ -1568,11 +1575,6 @@ static void imon_incoming_packet(struct imon_context *ictx,
1568 if (press_type < 0) 1575 if (press_type < 0)
1569 goto not_input_data; 1576 goto not_input_data;
1570 1577
1571 spin_lock_irqsave(&ictx->kc_lock, flags);
1572 if (ictx->kc == KEY_UNKNOWN)
1573 goto unknown_key;
1574 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1575
1576 if (ktype != IMON_KEY_PANEL) { 1578 if (ktype != IMON_KEY_PANEL) {
1577 if (press_type == 0) 1579 if (press_type == 0)
1578 rc_keyup(ictx->rdev); 1580 rc_keyup(ictx->rdev);
@@ -1615,12 +1617,6 @@ static void imon_incoming_packet(struct imon_context *ictx,
1615 1617
1616 return; 1618 return;
1617 1619
1618unknown_key:
1619 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1620 dev_info(dev, "%s: unknown keypress, code 0x%llx\n", __func__,
1621 (long long)scancode);
1622 return;
1623
1624not_input_data: 1620not_input_data:
1625 if (len != 8) { 1621 if (len != 8) {
1626 dev_warn(dev, "imon %s: invalid incoming packet " 1622 dev_warn(dev, "imon %s: invalid incoming packet "
@@ -2099,7 +2095,8 @@ static bool imon_find_endpoints(struct imon_context *ictx,
2099 2095
2100} 2096}
2101 2097
2102static struct imon_context *imon_init_intf0(struct usb_interface *intf) 2098static struct imon_context *imon_init_intf0(struct usb_interface *intf,
2099 const struct usb_device_id *id)
2103{ 2100{
2104 struct imon_context *ictx; 2101 struct imon_context *ictx;
2105 struct urb *rx_urb; 2102 struct urb *rx_urb;
@@ -2139,6 +2136,10 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
2139 ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor); 2136 ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor);
2140 ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct); 2137 ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct);
2141 2138
2139 /* default send_packet delay is 5ms but some devices need more */
2140 ictx->send_packet_delay = id->driver_info & IMON_NEED_20MS_PKT_DELAY ?
2141 20 : 5;
2142
2142 ret = -ENODEV; 2143 ret = -ENODEV;
2143 iface_desc = intf->cur_altsetting; 2144 iface_desc = intf->cur_altsetting;
2144 if (!imon_find_endpoints(ictx, iface_desc)) { 2145 if (!imon_find_endpoints(ictx, iface_desc)) {
@@ -2317,7 +2318,7 @@ static int imon_probe(struct usb_interface *interface,
2317 first_if_ctx = usb_get_intfdata(first_if); 2318 first_if_ctx = usb_get_intfdata(first_if);
2318 2319
2319 if (ifnum == 0) { 2320 if (ifnum == 0) {
2320 ictx = imon_init_intf0(interface); 2321 ictx = imon_init_intf0(interface, id);
2321 if (!ictx) { 2322 if (!ictx) {
2322 pr_err("failed to initialize context!\n"); 2323 pr_err("failed to initialize context!\n");
2323 ret = -ENODEV; 2324 ret = -ENODEV;
@@ -2325,7 +2326,14 @@ static int imon_probe(struct usb_interface *interface,
2325 } 2326 }
2326 2327
2327 } else { 2328 } else {
2328 /* this is the secondary interface on the device */ 2329 /* this is the secondary interface on the device */
2330
2331 /* fail early if first intf failed to register */
2332 if (!first_if_ctx) {
2333 ret = -ENODEV;
2334 goto fail;
2335 }
2336
2329 ictx = imon_init_intf1(interface, first_if_ctx); 2337 ictx = imon_init_intf1(interface, first_if_ctx);
2330 if (!ictx) { 2338 if (!ictx) {
2331 pr_err("failed to attach to context!\n"); 2339 pr_err("failed to attach to context!\n");
diff --git a/drivers/media/rc/ir-jvc-decoder.c b/drivers/media/rc/ir-jvc-decoder.c
index 69edffb9fe9a..3948138ca870 100644
--- a/drivers/media/rc/ir-jvc-decoder.c
+++ b/drivers/media/rc/ir-jvc-decoder.c
@@ -47,7 +47,7 @@ static int ir_jvc_decode(struct rc_dev *dev, struct ir_raw_event ev)
47{ 47{
48 struct jvc_dec *data = &dev->raw->jvc; 48 struct jvc_dec *data = &dev->raw->jvc;
49 49
50 if (!(dev->raw->enabled_protocols & RC_BIT_JVC)) 50 if (!(dev->enabled_protocols & RC_BIT_JVC))
51 return 0; 51 return 0;
52 52
53 if (!is_timing_event(ev)) { 53 if (!is_timing_event(ev)) {
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 9945e5e7f61a..ff4d93d1907f 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -35,7 +35,7 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
35 struct lirc_codec *lirc = &dev->raw->lirc; 35 struct lirc_codec *lirc = &dev->raw->lirc;
36 int sample; 36 int sample;
37 37
38 if (!(dev->raw->enabled_protocols & RC_BIT_LIRC)) 38 if (!(dev->enabled_protocols & RC_BIT_LIRC))
39 return 0; 39 return 0;
40 40
41 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf) 41 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf)
diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c b/drivers/media/rc/ir-mce_kbd-decoder.c
index 33fafa4cf7cb..9f3c9b59f30c 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -216,7 +216,7 @@ static int ir_mce_kbd_decode(struct rc_dev *dev, struct ir_raw_event ev)
216 u32 scancode; 216 u32 scancode;
217 unsigned long delay; 217 unsigned long delay;
218 218
219 if (!(dev->raw->enabled_protocols & RC_BIT_MCE_KBD)) 219 if (!(dev->enabled_protocols & RC_BIT_MCE_KBD))
220 return 0; 220 return 0;
221 221
222 if (!is_timing_event(ev)) { 222 if (!is_timing_event(ev)) {
diff --git a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c
index a47ee3634969..9a9009411439 100644
--- a/drivers/media/rc/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -52,7 +52,7 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
52 u8 address, not_address, command, not_command; 52 u8 address, not_address, command, not_command;
53 bool send_32bits = false; 53 bool send_32bits = false;
54 54
55 if (!(dev->raw->enabled_protocols & RC_BIT_NEC)) 55 if (!(dev->enabled_protocols & RC_BIT_NEC))
56 return 0; 56 return 0;
57 57
58 if (!is_timing_event(ev)) { 58 if (!is_timing_event(ev)) {
diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index 17c94be9f24c..5c42750c7b71 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -256,7 +256,7 @@ int ir_raw_event_register(struct rc_dev *dev)
256 return -ENOMEM; 256 return -ENOMEM;
257 257
258 dev->raw->dev = dev; 258 dev->raw->dev = dev;
259 dev->raw->enabled_protocols = ~0; 259 dev->enabled_protocols = ~0;
260 rc = kfifo_alloc(&dev->raw->kfifo, 260 rc = kfifo_alloc(&dev->raw->kfifo,
261 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE, 261 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE,
262 GFP_KERNEL); 262 GFP_KERNEL);
diff --git a/drivers/media/rc/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c
index 5b4d1ddeac4e..4e53a319c5d8 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -52,7 +52,7 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
52 u8 toggle; 52 u8 toggle;
53 u32 scancode; 53 u32 scancode;
54 54
55 if (!(dev->raw->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X))) 55 if (!(dev->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X)))
56 return 0; 56 return 0;
57 57
58 if (!is_timing_event(ev)) { 58 if (!is_timing_event(ev)) {
@@ -128,7 +128,7 @@ again:
128 if (data->wanted_bits == RC5X_NBITS) { 128 if (data->wanted_bits == RC5X_NBITS) {
129 /* RC5X */ 129 /* RC5X */
130 u8 xdata, command, system; 130 u8 xdata, command, system;
131 if (!(dev->raw->enabled_protocols & RC_BIT_RC5X)) { 131 if (!(dev->enabled_protocols & RC_BIT_RC5X)) {
132 data->state = STATE_INACTIVE; 132 data->state = STATE_INACTIVE;
133 return 0; 133 return 0;
134 } 134 }
@@ -145,7 +145,7 @@ again:
145 } else { 145 } else {
146 /* RC5 */ 146 /* RC5 */
147 u8 command, system; 147 u8 command, system;
148 if (!(dev->raw->enabled_protocols & RC_BIT_RC5)) { 148 if (!(dev->enabled_protocols & RC_BIT_RC5)) {
149 data->state = STATE_INACTIVE; 149 data->state = STATE_INACTIVE;
150 return 0; 150 return 0;
151 } 151 }
diff --git a/drivers/media/rc/ir-rc5-sz-decoder.c b/drivers/media/rc/ir-rc5-sz-decoder.c
index fd807a8308d8..865fe84fd854 100644
--- a/drivers/media/rc/ir-rc5-sz-decoder.c
+++ b/drivers/media/rc/ir-rc5-sz-decoder.c
@@ -48,7 +48,7 @@ static int ir_rc5_sz_decode(struct rc_dev *dev, struct ir_raw_event ev)
48 u8 toggle, command, system; 48 u8 toggle, command, system;
49 u32 scancode; 49 u32 scancode;
50 50
51 if (!(dev->raw->enabled_protocols & RC_BIT_RC5_SZ)) 51 if (!(dev->enabled_protocols & RC_BIT_RC5_SZ))
52 return 0; 52 return 0;
53 53
54 if (!is_timing_event(ev)) { 54 if (!is_timing_event(ev)) {
diff --git a/drivers/media/rc/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c
index e19072ffb36c..7cba7d33a3fa 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -89,7 +89,7 @@ static int ir_rc6_decode(struct rc_dev *dev, struct ir_raw_event ev)
89 u32 scancode; 89 u32 scancode;
90 u8 toggle; 90 u8 toggle;
91 91
92 if (!(dev->raw->enabled_protocols & 92 if (!(dev->enabled_protocols &
93 (RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 | RC_BIT_RC6_6A_24 | 93 (RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 | RC_BIT_RC6_6A_24 |
94 RC_BIT_RC6_6A_32 | RC_BIT_RC6_MCE))) 94 RC_BIT_RC6_6A_32 | RC_BIT_RC6_MCE)))
95 return 0; 95 return 0;
diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
index 8ead492d03aa..31b955bf7664 100644
--- a/drivers/media/rc/ir-rx51.c
+++ b/drivers/media/rc/ir-rx51.c
@@ -464,14 +464,14 @@ static int lirc_rx51_probe(struct platform_device *dev)
464 return 0; 464 return 0;
465} 465}
466 466
467static int __exit lirc_rx51_remove(struct platform_device *dev) 467static int lirc_rx51_remove(struct platform_device *dev)
468{ 468{
469 return lirc_unregister_driver(lirc_rx51_driver.minor); 469 return lirc_unregister_driver(lirc_rx51_driver.minor);
470} 470}
471 471
472struct platform_driver lirc_rx51_platform_driver = { 472struct platform_driver lirc_rx51_platform_driver = {
473 .probe = lirc_rx51_probe, 473 .probe = lirc_rx51_probe,
474 .remove = __exit_p(lirc_rx51_remove), 474 .remove = lirc_rx51_remove,
475 .suspend = lirc_rx51_suspend, 475 .suspend = lirc_rx51_suspend,
476 .resume = lirc_rx51_resume, 476 .resume = lirc_rx51_resume,
477 .driver = { 477 .driver = {
diff --git a/drivers/media/rc/ir-sanyo-decoder.c b/drivers/media/rc/ir-sanyo-decoder.c
index 7e69a3b65370..0a06205b5677 100644
--- a/drivers/media/rc/ir-sanyo-decoder.c
+++ b/drivers/media/rc/ir-sanyo-decoder.c
@@ -58,7 +58,7 @@ static int ir_sanyo_decode(struct rc_dev *dev, struct ir_raw_event ev)
58 u32 scancode; 58 u32 scancode;
59 u8 address, command, not_command; 59 u8 address, command, not_command;
60 60
61 if (!(dev->raw->enabled_protocols & RC_BIT_SANYO)) 61 if (!(dev->enabled_protocols & RC_BIT_SANYO))
62 return 0; 62 return 0;
63 63
64 if (!is_timing_event(ev)) { 64 if (!is_timing_event(ev)) {
diff --git a/drivers/media/rc/ir-sony-decoder.c b/drivers/media/rc/ir-sony-decoder.c
index fb914342cf4d..29ab9c2db060 100644
--- a/drivers/media/rc/ir-sony-decoder.c
+++ b/drivers/media/rc/ir-sony-decoder.c
@@ -45,7 +45,7 @@ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
45 u32 scancode; 45 u32 scancode;
46 u8 device, subdevice, function; 46 u8 device, subdevice, function;
47 47
48 if (!(dev->raw->enabled_protocols & 48 if (!(dev->enabled_protocols &
49 (RC_BIT_SONY12 | RC_BIT_SONY15 | RC_BIT_SONY20))) 49 (RC_BIT_SONY12 | RC_BIT_SONY15 | RC_BIT_SONY20)))
50 return 0; 50 return 0;
51 51
@@ -124,7 +124,7 @@ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
124 124
125 switch (data->count) { 125 switch (data->count) {
126 case 12: 126 case 12:
127 if (!(dev->raw->enabled_protocols & RC_BIT_SONY12)) { 127 if (!(dev->enabled_protocols & RC_BIT_SONY12)) {
128 data->state = STATE_INACTIVE; 128 data->state = STATE_INACTIVE;
129 return 0; 129 return 0;
130 } 130 }
@@ -133,7 +133,7 @@ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
133 function = bitrev8((data->bits >> 4) & 0xFE); 133 function = bitrev8((data->bits >> 4) & 0xFE);
134 break; 134 break;
135 case 15: 135 case 15:
136 if (!(dev->raw->enabled_protocols & RC_BIT_SONY15)) { 136 if (!(dev->enabled_protocols & RC_BIT_SONY15)) {
137 data->state = STATE_INACTIVE; 137 data->state = STATE_INACTIVE;
138 return 0; 138 return 0;
139 } 139 }
@@ -142,7 +142,7 @@ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
142 function = bitrev8((data->bits >> 7) & 0xFE); 142 function = bitrev8((data->bits >> 7) & 0xFE);
143 break; 143 break;
144 case 20: 144 case 20:
145 if (!(dev->raw->enabled_protocols & RC_BIT_SONY20)) { 145 if (!(dev->enabled_protocols & RC_BIT_SONY20)) {
146 data->state = STATE_INACTIVE; 146 data->state = STATE_INACTIVE;
147 return 0; 147 return 0;
148 } 148 }
diff --git a/drivers/media/rc/ite-cir.c b/drivers/media/rc/ite-cir.c
index dd8237324c09..63b42252166a 100644
--- a/drivers/media/rc/ite-cir.c
+++ b/drivers/media/rc/ite-cir.c
@@ -1613,6 +1613,7 @@ exit_release_cir_addr:
1613 release_region(itdev->cir_addr, itdev->params.io_region_size); 1613 release_region(itdev->cir_addr, itdev->params.io_region_size);
1614exit_unregister_device: 1614exit_unregister_device:
1615 rc_unregister_device(rdev); 1615 rc_unregister_device(rdev);
1616 rdev = NULL;
1616exit_free_dev_rdev: 1617exit_free_dev_rdev:
1617 rc_free_device(rdev); 1618 rc_free_device(rdev);
1618 kfree(itdev); 1619 kfree(itdev);
diff --git a/drivers/media/rc/keymaps/Makefile b/drivers/media/rc/keymaps/Makefile
index 778661971aed..5ab94ea4bc28 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
78 rc-hauppauge.o \ 78 rc-hauppauge.o \
79 rc-rc6-mce.o \ 79 rc-rc6-mce.o \
80 rc-real-audio-220-32-keys.o \ 80 rc-real-audio-220-32-keys.o \
81 rc-reddo.o \
81 rc-snapstream-firefly.o \ 82 rc-snapstream-firefly.o \
82 rc-streamzap.o \ 83 rc-streamzap.o \
83 rc-tbs-nec.o \ 84 rc-tbs-nec.o \
@@ -88,7 +89,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
88 rc-tevii-nec.o \ 89 rc-tevii-nec.o \
89 rc-tivo.o \ 90 rc-tivo.o \
90 rc-total-media-in-hand.o \ 91 rc-total-media-in-hand.o \
91 rc-total-media-in-hand-02.o \ 92 rc-total-media-in-hand-02.o \
92 rc-trekstor.o \ 93 rc-trekstor.o \
93 rc-tt-1500.o \ 94 rc-tt-1500.o \
94 rc-twinhan1027.o \ 95 rc-twinhan1027.o \
diff --git a/drivers/media/rc/keymaps/rc-reddo.c b/drivers/media/rc/keymaps/rc-reddo.c
new file mode 100644
index 000000000000..b80b336e9284
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-reddo.c
@@ -0,0 +1,86 @@
1/*
2 * MSI DIGIVOX mini III remote controller keytable
3 *
4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
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/*
25 * Derived from MSI DIGIVOX mini III remote (rc-msi-digivox-iii.c)
26 *
27 * Differences between these remotes are:
28 *
29 * 1) scancode 0x61d601 is mapped to different button:
30 * MSI DIGIVOX mini III "Source" = KEY_VIDEO
31 * Reddo "EPG" = KEY_EPG
32 *
33 * 2) Reddo remote has less buttons. Missing buttons are: colored buttons,
34 * navigation buttons and main power button.
35 */
36
37static struct rc_map_table reddo[] = {
38 { 0x61d601, KEY_EPG }, /* EPG */
39 { 0x61d602, KEY_3 },
40 { 0x61d604, KEY_1 },
41 { 0x61d605, KEY_5 },
42 { 0x61d606, KEY_6 },
43 { 0x61d607, KEY_CHANNELDOWN }, /* CH- */
44 { 0x61d608, KEY_2 },
45 { 0x61d609, KEY_CHANNELUP }, /* CH+ */
46 { 0x61d60a, KEY_9 },
47 { 0x61d60b, KEY_ZOOM }, /* Zoom */
48 { 0x61d60c, KEY_7 },
49 { 0x61d60d, KEY_8 },
50 { 0x61d60e, KEY_VOLUMEUP }, /* Vol+ */
51 { 0x61d60f, KEY_4 },
52 { 0x61d610, KEY_ESC }, /* [back up arrow] */
53 { 0x61d611, KEY_0 },
54 { 0x61d612, KEY_OK }, /* [enter arrow] */
55 { 0x61d613, KEY_VOLUMEDOWN }, /* Vol- */
56 { 0x61d614, KEY_RECORD }, /* Rec */
57 { 0x61d615, KEY_STOP }, /* Stop */
58 { 0x61d616, KEY_PLAY }, /* Play */
59 { 0x61d617, KEY_MUTE }, /* Mute */
60 { 0x61d643, KEY_POWER2 }, /* [red power button] */
61};
62
63static struct rc_map_list reddo_map = {
64 .map = {
65 .scan = reddo,
66 .size = ARRAY_SIZE(reddo),
67 .rc_type = RC_TYPE_NEC,
68 .name = RC_MAP_REDDO,
69 }
70};
71
72static int __init init_rc_map_reddo(void)
73{
74 return rc_map_register(&reddo_map);
75}
76
77static void __exit exit_rc_map_reddo(void)
78{
79 rc_map_unregister(&reddo_map);
80}
81
82module_init(init_rc_map_reddo)
83module_exit(exit_rc_map_reddo)
84
85MODULE_LICENSE("GPL");
86MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
index 5b5b6e6f79e8..3c761014d3ce 100644
--- a/drivers/media/rc/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -482,7 +482,7 @@ static char SET_RX_SENSOR[] = {MCE_CMD_PORT_IR,
482 MCE_RSP_EQIRRXPORTEN, 0x00}; 482 MCE_RSP_EQIRRXPORTEN, 0x00};
483*/ 483*/
484 484
485static int mceusb_cmdsize(u8 cmd, u8 subcmd) 485static int mceusb_cmd_datasize(u8 cmd, u8 subcmd)
486{ 486{
487 int datasize = 0; 487 int datasize = 0;
488 488
@@ -493,6 +493,9 @@ static int mceusb_cmdsize(u8 cmd, u8 subcmd)
493 break; 493 break;
494 case MCE_CMD_PORT_SYS: 494 case MCE_CMD_PORT_SYS:
495 switch (subcmd) { 495 switch (subcmd) {
496 case MCE_RSP_GETPORTSTATUS:
497 datasize = 5;
498 break;
496 case MCE_RSP_EQWAKEVERSION: 499 case MCE_RSP_EQWAKEVERSION:
497 datasize = 4; 500 datasize = 4;
498 break; 501 break;
@@ -500,6 +503,9 @@ static int mceusb_cmdsize(u8 cmd, u8 subcmd)
500 datasize = 2; 503 datasize = 2;
501 break; 504 break;
502 case MCE_RSP_EQWAKESUPPORT: 505 case MCE_RSP_EQWAKESUPPORT:
506 case MCE_RSP_GETWAKESOURCE:
507 case MCE_RSP_EQDEVDETAILS:
508 case MCE_RSP_EQEMVER:
503 datasize = 1; 509 datasize = 1;
504 break; 510 break;
505 } 511 }
@@ -509,6 +515,7 @@ static int mceusb_cmdsize(u8 cmd, u8 subcmd)
509 case MCE_RSP_EQIRCFS: 515 case MCE_RSP_EQIRCFS:
510 case MCE_RSP_EQIRTIMEOUT: 516 case MCE_RSP_EQIRTIMEOUT:
511 case MCE_RSP_EQIRRXCFCNT: 517 case MCE_RSP_EQIRRXCFCNT:
518 case MCE_RSP_EQIRNUMPORTS:
512 datasize = 2; 519 datasize = 2;
513 break; 520 break;
514 case MCE_CMD_SIG_END: 521 case MCE_CMD_SIG_END:
@@ -968,7 +975,7 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
968 for (; i < buf_len; i++) { 975 for (; i < buf_len; i++) {
969 switch (ir->parser_state) { 976 switch (ir->parser_state) {
970 case SUBCMD: 977 case SUBCMD:
971 ir->rem = mceusb_cmdsize(ir->cmd, ir->buf_in[i]); 978 ir->rem = mceusb_cmd_datasize(ir->cmd, ir->buf_in[i]);
972 mceusb_dev_printdata(ir, ir->buf_in, i - 1, 979 mceusb_dev_printdata(ir, ir->buf_in, i - 1,
973 ir->rem + 2, false); 980 ir->rem + 2, false);
974 mceusb_handle_command(ir, i); 981 mceusb_handle_command(ir, i);
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index 40125d779049..21ee0dc1b7ec 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -1107,6 +1107,7 @@ exit_release_cir_addr:
1107 release_region(nvt->cir_addr, CIR_IOREG_LENGTH); 1107 release_region(nvt->cir_addr, CIR_IOREG_LENGTH);
1108exit_unregister_device: 1108exit_unregister_device:
1109 rc_unregister_device(rdev); 1109 rc_unregister_device(rdev);
1110 rdev = NULL;
1110exit_free_dev_rdev: 1111exit_free_dev_rdev:
1111 rc_free_device(rdev); 1112 rc_free_device(rdev);
1112 kfree(nvt); 1113 kfree(nvt);
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 5d87287ed372..70a180bb0bd0 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -39,7 +39,6 @@ struct ir_raw_event_ctrl {
39 ktime_t last_event; /* when last event occurred */ 39 ktime_t last_event; /* when last event occurred */
40 enum raw_event_type last_type; /* last event type */ 40 enum raw_event_type last_type; /* last event type */
41 struct rc_dev *dev; /* pointer to the parent rc_dev */ 41 struct rc_dev *dev; /* pointer to the parent rc_dev */
42 u64 enabled_protocols; /* enabled raw protocol decoders */
43 42
44 /* raw decoder state follows */ 43 /* raw decoder state follows */
45 struct ir_raw_event prev_ev; 44 struct ir_raw_event prev_ev;
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 759a40a42eaa..1cf382a0b277 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -715,14 +715,14 @@ static void ir_close(struct input_dev *idev)
715} 715}
716 716
717/* class for /sys/class/rc */ 717/* class for /sys/class/rc */
718static char *ir_devnode(struct device *dev, umode_t *mode) 718static char *rc_devnode(struct device *dev, umode_t *mode)
719{ 719{
720 return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev)); 720 return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev));
721} 721}
722 722
723static struct class ir_input_class = { 723static struct class rc_class = {
724 .name = "rc", 724 .name = "rc",
725 .devnode = ir_devnode, 725 .devnode = rc_devnode,
726}; 726};
727 727
728/* 728/*
@@ -783,13 +783,12 @@ static ssize_t show_protocols(struct device *device,
783 783
784 mutex_lock(&dev->lock); 784 mutex_lock(&dev->lock);
785 785
786 if (dev->driver_type == RC_DRIVER_SCANCODE) { 786 enabled = dev->enabled_protocols;
787 enabled = dev->rc_map.rc_type; 787 if (dev->driver_type == RC_DRIVER_SCANCODE)
788 allowed = dev->allowed_protos; 788 allowed = dev->allowed_protos;
789 } else if (dev->raw) { 789 else if (dev->raw)
790 enabled = dev->raw->enabled_protocols;
791 allowed = ir_raw_get_allowed_protocols(); 790 allowed = ir_raw_get_allowed_protocols();
792 } else { 791 else {
793 mutex_unlock(&dev->lock); 792 mutex_unlock(&dev->lock);
794 return -ENODEV; 793 return -ENODEV;
795 } 794 }
@@ -847,7 +846,6 @@ static ssize_t store_protocols(struct device *device,
847 u64 type; 846 u64 type;
848 u64 mask; 847 u64 mask;
849 int rc, i, count = 0; 848 int rc, i, count = 0;
850 unsigned long flags;
851 ssize_t ret; 849 ssize_t ret;
852 850
853 /* Device is being removed */ 851 /* Device is being removed */
@@ -856,15 +854,12 @@ static ssize_t store_protocols(struct device *device,
856 854
857 mutex_lock(&dev->lock); 855 mutex_lock(&dev->lock);
858 856
859 if (dev->driver_type == RC_DRIVER_SCANCODE) 857 if (dev->driver_type != RC_DRIVER_SCANCODE && !dev->raw) {
860 type = dev->rc_map.rc_type;
861 else if (dev->raw)
862 type = dev->raw->enabled_protocols;
863 else {
864 IR_dprintk(1, "Protocol switching not supported\n"); 858 IR_dprintk(1, "Protocol switching not supported\n");
865 ret = -EINVAL; 859 ret = -EINVAL;
866 goto out; 860 goto out;
867 } 861 }
862 type = dev->enabled_protocols;
868 863
869 while ((tmp = strsep((char **) &data, " \n")) != NULL) { 864 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
870 if (!*tmp) 865 if (!*tmp)
@@ -922,14 +917,7 @@ static ssize_t store_protocols(struct device *device,
922 } 917 }
923 } 918 }
924 919
925 if (dev->driver_type == RC_DRIVER_SCANCODE) { 920 dev->enabled_protocols = type;
926 spin_lock_irqsave(&dev->rc_map.lock, flags);
927 dev->rc_map.rc_type = type;
928 spin_unlock_irqrestore(&dev->rc_map.lock, flags);
929 } else {
930 dev->raw->enabled_protocols = type;
931 }
932
933 IR_dprintk(1, "Current protocol(s): 0x%llx\n", 921 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
934 (long long)type); 922 (long long)type);
935 923
@@ -1016,7 +1004,7 @@ struct rc_dev *rc_allocate_device(void)
1016 setup_timer(&dev->timer_keyup, ir_timer_keyup, (unsigned long)dev); 1004 setup_timer(&dev->timer_keyup, ir_timer_keyup, (unsigned long)dev);
1017 1005
1018 dev->dev.type = &rc_dev_type; 1006 dev->dev.type = &rc_dev_type;
1019 dev->dev.class = &ir_input_class; 1007 dev->dev.class = &rc_class;
1020 device_initialize(&dev->dev); 1008 device_initialize(&dev->dev);
1021 1009
1022 __module_get(THIS_MODULE); 1010 __module_get(THIS_MODULE);
@@ -1068,9 +1056,8 @@ int rc_register_device(struct rc_dev *dev)
1068 /* 1056 /*
1069 * Take the lock here, as the device sysfs node will appear 1057 * Take the lock here, as the device sysfs node will appear
1070 * when device_add() is called, which may trigger an ir-keytable udev 1058 * when device_add() is called, which may trigger an ir-keytable udev
1071 * rule, which will in turn call show_protocols and access either 1059 * rule, which will in turn call show_protocols and access
1072 * dev->rc_map.rc_type or dev->raw->enabled_protocols before it has 1060 * dev->enabled_protocols before it has been initialized.
1073 * been initialized.
1074 */ 1061 */
1075 mutex_lock(&dev->lock); 1062 mutex_lock(&dev->lock);
1076 1063
@@ -1132,6 +1119,7 @@ int rc_register_device(struct rc_dev *dev)
1132 rc = dev->change_protocol(dev, &rc_type); 1119 rc = dev->change_protocol(dev, &rc_type);
1133 if (rc < 0) 1120 if (rc < 0)
1134 goto out_raw; 1121 goto out_raw;
1122 dev->enabled_protocols = rc_type;
1135 } 1123 }
1136 1124
1137 mutex_unlock(&dev->lock); 1125 mutex_unlock(&dev->lock);
@@ -1190,7 +1178,7 @@ EXPORT_SYMBOL_GPL(rc_unregister_device);
1190 1178
1191static int __init rc_core_init(void) 1179static int __init rc_core_init(void)
1192{ 1180{
1193 int rc = class_register(&ir_input_class); 1181 int rc = class_register(&rc_class);
1194 if (rc) { 1182 if (rc) {
1195 printk(KERN_ERR "rc_core: unable to register rc class\n"); 1183 printk(KERN_ERR "rc_core: unable to register rc class\n");
1196 return rc; 1184 return rc;
@@ -1203,11 +1191,11 @@ static int __init rc_core_init(void)
1203 1191
1204static void __exit rc_core_exit(void) 1192static void __exit rc_core_exit(void)
1205{ 1193{
1206 class_unregister(&ir_input_class); 1194 class_unregister(&rc_class);
1207 rc_map_unregister(&empty_map); 1195 rc_map_unregister(&empty_map);
1208} 1196}
1209 1197
1210module_init(rc_core_init); 1198subsys_initcall(rc_core_init);
1211module_exit(rc_core_exit); 1199module_exit(rc_core_exit);
1212 1200
1213int rc_core_debug; /* ir_debug level (0,1,2) */ 1201int rc_core_debug; /* ir_debug level (0,1,2) */
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 1b37fe2779f8..12167a6b5472 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -45,6 +45,7 @@
45 * 45 *
46 */ 46 */
47 47
48#include <asm/unaligned.h>
48#include <linux/device.h> 49#include <linux/device.h>
49#include <linux/module.h> 50#include <linux/module.h>
50#include <linux/slab.h> 51#include <linux/slab.h>
@@ -53,7 +54,6 @@
53#include <media/rc-core.h> 54#include <media/rc-core.h>
54 55
55/* Driver Information */ 56/* Driver Information */
56#define DRIVER_VERSION "0.70"
57#define DRIVER_AUTHOR "Jarod Wilson <jarod@redhat.com>" 57#define DRIVER_AUTHOR "Jarod Wilson <jarod@redhat.com>"
58#define DRIVER_AUTHOR2 "The Dweller, Stephen Cox" 58#define DRIVER_AUTHOR2 "The Dweller, Stephen Cox"
59#define DRIVER_DESC "RedRat3 USB IR Transceiver Driver" 59#define DRIVER_DESC "RedRat3 USB IR Transceiver Driver"
@@ -129,25 +129,11 @@ static int debug;
129/* USB bulk-in IR data endpoint address */ 129/* USB bulk-in IR data endpoint address */
130#define RR3_BULK_IN_EP_ADDR 0x82 130#define RR3_BULK_IN_EP_ADDR 0x82
131 131
132/* Raw Modulated signal data value offsets */
133#define RR3_PAUSE_OFFSET 0
134#define RR3_FREQ_COUNT_OFFSET 4
135#define RR3_NUM_PERIOD_OFFSET 6
136#define RR3_MAX_LENGTHS_OFFSET 8
137#define RR3_NUM_LENGTHS_OFFSET 9
138#define RR3_MAX_SIGS_OFFSET 10
139#define RR3_NUM_SIGS_OFFSET 12
140#define RR3_REPEATS_OFFSET 14
141
142/* Size of the fixed-length portion of the signal */ 132/* Size of the fixed-length portion of the signal */
143#define RR3_HEADER_LENGTH 15
144#define RR3_DRIVER_MAXLENS 128 133#define RR3_DRIVER_MAXLENS 128
145#define RR3_MAX_SIG_SIZE 512 134#define RR3_MAX_SIG_SIZE 512
146#define RR3_MAX_BUF_SIZE \
147 ((2 * RR3_HEADER_LENGTH) + RR3_DRIVER_MAXLENS + RR3_MAX_SIG_SIZE)
148#define RR3_TIME_UNIT 50 135#define RR3_TIME_UNIT 50
149#define RR3_END_OF_SIGNAL 0x7f 136#define RR3_END_OF_SIGNAL 0x7f
150#define RR3_TX_HEADER_OFFSET 4
151#define RR3_TX_TRAILER_LEN 2 137#define RR3_TX_TRAILER_LEN 2
152#define RR3_RX_MIN_TIMEOUT 5 138#define RR3_RX_MIN_TIMEOUT 5
153#define RR3_RX_MAX_TIMEOUT 2000 139#define RR3_RX_MAX_TIMEOUT 2000
@@ -159,6 +145,32 @@ static int debug;
159#define USB_RR3USB_PRODUCT_ID 0x0001 145#define USB_RR3USB_PRODUCT_ID 0x0001
160#define USB_RR3IIUSB_PRODUCT_ID 0x0005 146#define USB_RR3IIUSB_PRODUCT_ID 0x0005
161 147
148struct redrat3_header {
149 __be16 length;
150 __be16 transfer_type;
151} __packed;
152
153/* sending and receiving irdata */
154struct redrat3_irdata {
155 struct redrat3_header header;
156 __be32 pause;
157 __be16 mod_freq_count;
158 __be16 num_periods;
159 __u8 max_lengths;
160 __u8 no_lengths;
161 __be16 max_sig_size;
162 __be16 sig_size;
163 __u8 no_repeats;
164 __be16 lens[RR3_DRIVER_MAXLENS]; /* not aligned */
165 __u8 sigdata[RR3_MAX_SIG_SIZE];
166} __packed;
167
168/* firmware errors */
169struct redrat3_error {
170 struct redrat3_header header;
171 __be16 fw_error;
172} __packed;
173
162/* table of devices that work with this driver */ 174/* table of devices that work with this driver */
163static struct usb_device_id redrat3_dev_table[] = { 175static struct usb_device_id redrat3_dev_table[] = {
164 /* Original version of the RedRat3 */ 176 /* Original version of the RedRat3 */
@@ -180,20 +192,15 @@ struct redrat3_dev {
180 /* the receive endpoint */ 192 /* the receive endpoint */
181 struct usb_endpoint_descriptor *ep_in; 193 struct usb_endpoint_descriptor *ep_in;
182 /* the buffer to receive data */ 194 /* the buffer to receive data */
183 unsigned char *bulk_in_buf; 195 void *bulk_in_buf;
184 /* urb used to read ir data */ 196 /* urb used to read ir data */
185 struct urb *read_urb; 197 struct urb *read_urb;
186 198
187 /* the send endpoint */ 199 /* the send endpoint */
188 struct usb_endpoint_descriptor *ep_out; 200 struct usb_endpoint_descriptor *ep_out;
189 /* the buffer to send data */
190 unsigned char *bulk_out_buf;
191 /* the urb used to send data */
192 struct urb *write_urb;
193 201
194 /* usb dma */ 202 /* usb dma */
195 dma_addr_t dma_in; 203 dma_addr_t dma_in;
196 dma_addr_t dma_out;
197 204
198 /* rx signal timeout timer */ 205 /* rx signal timeout timer */
199 struct timer_list rx_timeout; 206 struct timer_list rx_timeout;
@@ -205,72 +212,15 @@ struct redrat3_dev {
205 bool transmitting; 212 bool transmitting;
206 213
207 /* store for current packet */ 214 /* store for current packet */
208 char pbuf[RR3_MAX_BUF_SIZE]; 215 struct redrat3_irdata irdata;
209 u16 pktlen;
210 u16 pkttype;
211 u16 bytes_read; 216 u16 bytes_read;
212 /* indicate whether we are going to reprocess
213 * the USB callback with a bigger buffer */
214 int buftoosmall;
215 char *datap;
216 217
217 u32 carrier; 218 u32 carrier;
218 219
219 char name[128]; 220 char name[64];
220 char phys[64]; 221 char phys[64];
221}; 222};
222 223
223/* All incoming data buffers adhere to a very specific data format */
224struct redrat3_signal_header {
225 u16 length; /* Length of data being transferred */
226 u16 transfer_type; /* Type of data transferred */
227 u32 pause; /* Pause between main and repeat signals */
228 u16 mod_freq_count; /* Value of timer on mod. freq. measurement */
229 u16 no_periods; /* No. of periods over which mod. freq. is measured */
230 u8 max_lengths; /* Max no. of lengths (i.e. size of array) */
231 u8 no_lengths; /* Actual no. of elements in lengths array */
232 u16 max_sig_size; /* Max no. of values in signal data array */
233 u16 sig_size; /* Acuto no. of values in signal data array */
234 u8 no_repeats; /* No. of repeats of repeat signal section */
235 /* Here forward is the lengths and signal data */
236};
237
238static void redrat3_dump_signal_header(struct redrat3_signal_header *header)
239{
240 pr_info("%s:\n", __func__);
241 pr_info(" * length: %u, transfer_type: 0x%02x\n",
242 header->length, header->transfer_type);
243 pr_info(" * pause: %u, freq_count: %u, no_periods: %u\n",
244 header->pause, header->mod_freq_count, header->no_periods);
245 pr_info(" * lengths: %u (max: %u)\n",
246 header->no_lengths, header->max_lengths);
247 pr_info(" * sig_size: %u (max: %u)\n",
248 header->sig_size, header->max_sig_size);
249 pr_info(" * repeats: %u\n", header->no_repeats);
250}
251
252static void redrat3_dump_signal_data(char *buffer, u16 len)
253{
254 int offset, i;
255 char *data_vals;
256
257 pr_info("%s:", __func__);
258
259 offset = RR3_TX_HEADER_OFFSET + RR3_HEADER_LENGTH
260 + (RR3_DRIVER_MAXLENS * sizeof(u16));
261
262 /* read RR3_DRIVER_MAXLENS from ctrl msg */
263 data_vals = buffer + offset;
264
265 for (i = 0; i < len; i++) {
266 if (i % 10 == 0)
267 pr_cont("\n * ");
268 pr_cont("%02x ", *data_vals++);
269 }
270
271 pr_cont("\n");
272}
273
274/* 224/*
275 * redrat3_issue_async 225 * redrat3_issue_async
276 * 226 *
@@ -283,7 +233,6 @@ static void redrat3_issue_async(struct redrat3_dev *rr3)
283 233
284 rr3_ftr(rr3->dev, "Entering %s\n", __func__); 234 rr3_ftr(rr3->dev, "Entering %s\n", __func__);
285 235
286 memset(rr3->bulk_in_buf, 0, rr3->ep_in->wMaxPacketSize);
287 res = usb_submit_urb(rr3->read_urb, GFP_ATOMIC); 236 res = usb_submit_urb(rr3->read_urb, GFP_ATOMIC);
288 if (res) 237 if (res)
289 rr3_dbg(rr3->dev, "%s: receive request FAILED! " 238 rr3_dbg(rr3->dev, "%s: receive request FAILED! "
@@ -352,13 +301,14 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)
352 } 301 }
353} 302}
354 303
355static u32 redrat3_val_to_mod_freq(struct redrat3_signal_header *ph) 304static u32 redrat3_val_to_mod_freq(struct redrat3_irdata *irdata)
356{ 305{
357 u32 mod_freq = 0; 306 u32 mod_freq = 0;
307 u16 mod_freq_count = be16_to_cpu(irdata->mod_freq_count);
358 308
359 if (ph->mod_freq_count != 0) 309 if (mod_freq_count != 0)
360 mod_freq = (RR3_CLK * ph->no_periods) / 310 mod_freq = (RR3_CLK * be16_to_cpu(irdata->num_periods)) /
361 (ph->mod_freq_count * RR3_CLK_PER_COUNT); 311 (mod_freq_count * RR3_CLK_PER_COUNT);
362 312
363 return mod_freq; 313 return mod_freq;
364} 314}
@@ -396,7 +346,6 @@ static u32 redrat3_us_to_len(u32 microsec)
396 346
397 /* don't allow zero lengths to go back, breaks lirc */ 347 /* don't allow zero lengths to go back, breaks lirc */
398 return result ? result : 1; 348 return result ? result : 1;
399
400} 349}
401 350
402/* timer callback to send reset event */ 351/* timer callback to send reset event */
@@ -411,16 +360,11 @@ static void redrat3_rx_timeout(unsigned long data)
411static void redrat3_process_ir_data(struct redrat3_dev *rr3) 360static void redrat3_process_ir_data(struct redrat3_dev *rr3)
412{ 361{
413 DEFINE_IR_RAW_EVENT(rawir); 362 DEFINE_IR_RAW_EVENT(rawir);
414 struct redrat3_signal_header header;
415 struct device *dev; 363 struct device *dev;
416 int i, trailer = 0; 364 unsigned i, trailer = 0;
365 unsigned sig_size, single_len, offset, val;
417 unsigned long delay; 366 unsigned long delay;
418 u32 mod_freq, single_len; 367 u32 mod_freq;
419 u16 *len_vals;
420 u8 *data_vals;
421 u32 tmp32;
422 u16 tmp16;
423 char *sig_data;
424 368
425 if (!rr3) { 369 if (!rr3) {
426 pr_err("%s called with no context!\n", __func__); 370 pr_err("%s called with no context!\n", __func__);
@@ -430,57 +374,20 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)
430 rr3_ftr(rr3->dev, "Entered %s\n", __func__); 374 rr3_ftr(rr3->dev, "Entered %s\n", __func__);
431 375
432 dev = rr3->dev; 376 dev = rr3->dev;
433 sig_data = rr3->pbuf;
434
435 header.length = rr3->pktlen;
436 header.transfer_type = rr3->pkttype;
437
438 /* Sanity check */
439 if (!(header.length >= RR3_HEADER_LENGTH))
440 dev_warn(dev, "read returned less than rr3 header len\n");
441 377
442 /* Make sure we reset the IR kfifo after a bit of inactivity */ 378 /* Make sure we reset the IR kfifo after a bit of inactivity */
443 delay = usecs_to_jiffies(rr3->hw_timeout); 379 delay = usecs_to_jiffies(rr3->hw_timeout);
444 mod_timer(&rr3->rx_timeout, jiffies + delay); 380 mod_timer(&rr3->rx_timeout, jiffies + delay);
445 381
446 memcpy(&tmp32, sig_data + RR3_PAUSE_OFFSET, sizeof(tmp32)); 382 mod_freq = redrat3_val_to_mod_freq(&rr3->irdata);
447 header.pause = be32_to_cpu(tmp32);
448
449 memcpy(&tmp16, sig_data + RR3_FREQ_COUNT_OFFSET, sizeof(tmp16));
450 header.mod_freq_count = be16_to_cpu(tmp16);
451
452 memcpy(&tmp16, sig_data + RR3_NUM_PERIOD_OFFSET, sizeof(tmp16));
453 header.no_periods = be16_to_cpu(tmp16);
454
455 header.max_lengths = sig_data[RR3_MAX_LENGTHS_OFFSET];
456 header.no_lengths = sig_data[RR3_NUM_LENGTHS_OFFSET];
457
458 memcpy(&tmp16, sig_data + RR3_MAX_SIGS_OFFSET, sizeof(tmp16));
459 header.max_sig_size = be16_to_cpu(tmp16);
460
461 memcpy(&tmp16, sig_data + RR3_NUM_SIGS_OFFSET, sizeof(tmp16));
462 header.sig_size = be16_to_cpu(tmp16);
463
464 header.no_repeats= sig_data[RR3_REPEATS_OFFSET];
465
466 if (debug) {
467 redrat3_dump_signal_header(&header);
468 redrat3_dump_signal_data(sig_data, header.sig_size);
469 }
470
471 mod_freq = redrat3_val_to_mod_freq(&header);
472 rr3_dbg(dev, "Got mod_freq of %u\n", mod_freq); 383 rr3_dbg(dev, "Got mod_freq of %u\n", mod_freq);
473 384
474 /* Here we pull out the 'length' values from the signal */
475 len_vals = (u16 *)(sig_data + RR3_HEADER_LENGTH);
476
477 data_vals = sig_data + RR3_HEADER_LENGTH +
478 (header.max_lengths * sizeof(u16));
479
480 /* process each rr3 encoded byte into an int */ 385 /* process each rr3 encoded byte into an int */
481 for (i = 0; i < header.sig_size; i++) { 386 sig_size = be16_to_cpu(rr3->irdata.sig_size);
482 u16 val = len_vals[data_vals[i]]; 387 for (i = 0; i < sig_size; i++) {
483 single_len = redrat3_len_to_us((u32)be16_to_cpu(val)); 388 offset = rr3->irdata.sigdata[i];
389 val = get_unaligned_be16(&rr3->irdata.lens[offset]);
390 single_len = redrat3_len_to_us(val);
484 391
485 /* we should always get pulse/space/pulse/space samples */ 392 /* we should always get pulse/space/pulse/space samples */
486 if (i % 2) 393 if (i % 2)
@@ -515,8 +422,6 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)
515 422
516 rr3_dbg(dev, "calling ir_raw_event_handle\n"); 423 rr3_dbg(dev, "calling ir_raw_event_handle\n");
517 ir_raw_event_handle(rr3->rc); 424 ir_raw_event_handle(rr3->rc);
518
519 return;
520} 425}
521 426
522/* Util fn to send rr3 cmds */ 427/* Util fn to send rr3 cmds */
@@ -540,7 +445,7 @@ static u8 redrat3_send_cmd(int cmd, struct redrat3_dev *rr3)
540 __func__, res, *data); 445 __func__, res, *data);
541 res = -EIO; 446 res = -EIO;
542 } else 447 } else
543 res = (u8)data[0]; 448 res = data[0];
544 449
545 kfree(data); 450 kfree(data);
546 451
@@ -598,22 +503,18 @@ static inline void redrat3_delete(struct redrat3_dev *rr3,
598{ 503{
599 rr3_ftr(rr3->dev, "%s cleaning up\n", __func__); 504 rr3_ftr(rr3->dev, "%s cleaning up\n", __func__);
600 usb_kill_urb(rr3->read_urb); 505 usb_kill_urb(rr3->read_urb);
601 usb_kill_urb(rr3->write_urb);
602 506
603 usb_free_urb(rr3->read_urb); 507 usb_free_urb(rr3->read_urb);
604 usb_free_urb(rr3->write_urb);
605 508
606 usb_free_coherent(udev, rr3->ep_in->wMaxPacketSize, 509 usb_free_coherent(udev, le16_to_cpu(rr3->ep_in->wMaxPacketSize),
607 rr3->bulk_in_buf, rr3->dma_in); 510 rr3->bulk_in_buf, rr3->dma_in);
608 usb_free_coherent(udev, rr3->ep_out->wMaxPacketSize,
609 rr3->bulk_out_buf, rr3->dma_out);
610 511
611 kfree(rr3); 512 kfree(rr3);
612} 513}
613 514
614static u32 redrat3_get_timeout(struct redrat3_dev *rr3) 515static u32 redrat3_get_timeout(struct redrat3_dev *rr3)
615{ 516{
616 u32 *tmp; 517 __be32 *tmp;
617 u32 timeout = MS_TO_US(150); /* a sane default, if things go haywire */ 518 u32 timeout = MS_TO_US(150); /* a sane default, if things go haywire */
618 int len, ret, pipe; 519 int len, ret, pipe;
619 520
@@ -628,14 +529,16 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3)
628 ret = usb_control_msg(rr3->udev, pipe, RR3_GET_IR_PARAM, 529 ret = usb_control_msg(rr3->udev, pipe, RR3_GET_IR_PARAM,
629 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 530 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
630 RR3_IR_IO_SIG_TIMEOUT, 0, tmp, len, HZ * 5); 531 RR3_IR_IO_SIG_TIMEOUT, 0, tmp, len, HZ * 5);
631 if (ret != len) { 532 if (ret != len)
632 dev_warn(rr3->dev, "Failed to read timeout from hardware\n"); 533 dev_warn(rr3->dev, "Failed to read timeout from hardware\n");
633 return timeout; 534 else {
535 timeout = redrat3_len_to_us(be32_to_cpup(tmp));
536
537 rr3_dbg(rr3->dev, "Got timeout of %d ms\n", timeout / 1000);
634 } 538 }
635 539
636 timeout = redrat3_len_to_us(be32_to_cpu(*tmp)); 540 kfree(tmp);
637 541
638 rr3_dbg(rr3->dev, "Got timeout of %d ms\n", timeout / 1000);
639 return timeout; 542 return timeout;
640} 543}
641 544
@@ -652,7 +555,7 @@ static void redrat3_reset(struct redrat3_dev *rr3)
652 rxpipe = usb_rcvctrlpipe(udev, 0); 555 rxpipe = usb_rcvctrlpipe(udev, 0);
653 txpipe = usb_sndctrlpipe(udev, 0); 556 txpipe = usb_sndctrlpipe(udev, 0);
654 557
655 val = kzalloc(len, GFP_KERNEL); 558 val = kmalloc(len, GFP_KERNEL);
656 if (!val) { 559 if (!val) {
657 dev_err(dev, "Memory allocation failure\n"); 560 dev_err(dev, "Memory allocation failure\n");
658 return; 561 return;
@@ -706,82 +609,74 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
706 rr3_ftr(rr3->dev, "Exiting %s\n", __func__); 609 rr3_ftr(rr3->dev, "Exiting %s\n", __func__);
707} 610}
708 611
709static void redrat3_read_packet_start(struct redrat3_dev *rr3, int len) 612static void redrat3_read_packet_start(struct redrat3_dev *rr3, unsigned len)
710{ 613{
711 u16 tx_error; 614 struct redrat3_header *header = rr3->bulk_in_buf;
712 u16 hdrlen; 615 unsigned pktlen, pkttype;
713 616
714 rr3_ftr(rr3->dev, "Entering %s\n", __func__); 617 rr3_ftr(rr3->dev, "Entering %s\n", __func__);
715 618
716 /* grab the Length and type of transfer */ 619 /* grab the Length and type of transfer */
717 memcpy(&(rr3->pktlen), (unsigned char *) rr3->bulk_in_buf, 620 pktlen = be16_to_cpu(header->length);
718 sizeof(rr3->pktlen)); 621 pkttype = be16_to_cpu(header->transfer_type);
719 memcpy(&(rr3->pkttype), ((unsigned char *) rr3->bulk_in_buf +
720 sizeof(rr3->pktlen)),
721 sizeof(rr3->pkttype));
722 622
723 /*data needs conversion to know what its real values are*/ 623 if (pktlen > sizeof(rr3->irdata)) {
724 rr3->pktlen = be16_to_cpu(rr3->pktlen); 624 dev_warn(rr3->dev, "packet length %u too large\n", pktlen);
725 rr3->pkttype = be16_to_cpu(rr3->pkttype); 625 return;
626 }
726 627
727 switch (rr3->pkttype) { 628 switch (pkttype) {
728 case RR3_ERROR: 629 case RR3_ERROR:
729 memcpy(&tx_error, ((unsigned char *)rr3->bulk_in_buf 630 if (len >= sizeof(struct redrat3_error)) {
730 + (sizeof(rr3->pktlen) + sizeof(rr3->pkttype))), 631 struct redrat3_error *error = rr3->bulk_in_buf;
731 sizeof(tx_error)); 632 unsigned fw_error = be16_to_cpu(error->fw_error);
732 tx_error = be16_to_cpu(tx_error); 633 redrat3_dump_fw_error(rr3, fw_error);
733 redrat3_dump_fw_error(rr3, tx_error); 634 }
734 break; 635 break;
735 636
736 case RR3_MOD_SIGNAL_IN: 637 case RR3_MOD_SIGNAL_IN:
737 hdrlen = sizeof(rr3->pktlen) + sizeof(rr3->pkttype); 638 memcpy(&rr3->irdata, rr3->bulk_in_buf, len);
738 rr3->bytes_read = len; 639 rr3->bytes_read = len;
739 rr3->bytes_read -= hdrlen;
740 rr3->datap = &(rr3->pbuf[0]);
741
742 memcpy(rr3->datap, ((unsigned char *)rr3->bulk_in_buf + hdrlen),
743 rr3->bytes_read);
744 rr3->datap += rr3->bytes_read;
745 rr3_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", 640 rr3_dbg(rr3->dev, "bytes_read %d, pktlen %d\n",
746 rr3->bytes_read, rr3->pktlen); 641 rr3->bytes_read, pktlen);
747 break; 642 break;
748 643
749 default: 644 default:
750 rr3_dbg(rr3->dev, "ignoring packet with type 0x%02x, " 645 rr3_dbg(rr3->dev, "ignoring packet with type 0x%02x, len of %d, 0x%02x\n",
751 "len of %d, 0x%02x\n", rr3->pkttype, len, rr3->pktlen); 646 pkttype, len, pktlen);
752 break; 647 break;
753 } 648 }
754} 649}
755 650
756static void redrat3_read_packet_continue(struct redrat3_dev *rr3, int len) 651static void redrat3_read_packet_continue(struct redrat3_dev *rr3, unsigned len)
757{ 652{
653 void *irdata = &rr3->irdata;
758 654
759 rr3_ftr(rr3->dev, "Entering %s\n", __func__); 655 rr3_ftr(rr3->dev, "Entering %s\n", __func__);
760 656
761 memcpy(rr3->datap, (unsigned char *)rr3->bulk_in_buf, len); 657 if (len + rr3->bytes_read > sizeof(rr3->irdata)) {
762 rr3->datap += len; 658 dev_warn(rr3->dev, "too much data for packet\n");
659 rr3->bytes_read = 0;
660 return;
661 }
662
663 memcpy(irdata + rr3->bytes_read, rr3->bulk_in_buf, len);
763 664
764 rr3->bytes_read += len; 665 rr3->bytes_read += len;
765 rr3_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", 666 rr3_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", rr3->bytes_read,
766 rr3->bytes_read, rr3->pktlen); 667 be16_to_cpu(rr3->irdata.header.length));
767} 668}
768 669
769/* gather IR data from incoming urb, process it when we have enough */ 670/* gather IR data from incoming urb, process it when we have enough */
770static int redrat3_get_ir_data(struct redrat3_dev *rr3, int len) 671static int redrat3_get_ir_data(struct redrat3_dev *rr3, unsigned len)
771{ 672{
772 struct device *dev = rr3->dev; 673 struct device *dev = rr3->dev;
674 unsigned pkttype;
773 int ret = 0; 675 int ret = 0;
774 676
775 rr3_ftr(dev, "Entering %s\n", __func__); 677 rr3_ftr(dev, "Entering %s\n", __func__);
776 678
777 if (rr3->pktlen > RR3_MAX_BUF_SIZE) { 679 if (rr3->bytes_read == 0 && len >= sizeof(struct redrat3_header)) {
778 dev_err(rr3->dev, "error: packet larger than buffer\n");
779 ret = -EINVAL;
780 goto out;
781 }
782
783 if ((rr3->bytes_read == 0) &&
784 (len >= (sizeof(rr3->pkttype) + sizeof(rr3->pktlen)))) {
785 redrat3_read_packet_start(rr3, len); 680 redrat3_read_packet_start(rr3, len);
786 } else if (rr3->bytes_read != 0) { 681 } else if (rr3->bytes_read != 0) {
787 redrat3_read_packet_continue(rr3, len); 682 redrat3_read_packet_continue(rr3, len);
@@ -791,31 +686,25 @@ static int redrat3_get_ir_data(struct redrat3_dev *rr3, int len)
791 goto out; 686 goto out;
792 } 687 }
793 688
794 if (rr3->bytes_read > rr3->pktlen) { 689 if (rr3->bytes_read < be16_to_cpu(rr3->irdata.header.length))
795 dev_err(dev, "bytes_read (%d) greater than pktlen (%d)\n",
796 rr3->bytes_read, rr3->pktlen);
797 ret = -EINVAL;
798 goto out;
799 } else if (rr3->bytes_read < rr3->pktlen)
800 /* we're still accumulating data */ 690 /* we're still accumulating data */
801 return 0; 691 return 0;
802 692
803 /* if we get here, we've got IR data to decode */ 693 /* if we get here, we've got IR data to decode */
804 if (rr3->pkttype == RR3_MOD_SIGNAL_IN) 694 pkttype = be16_to_cpu(rr3->irdata.header.transfer_type);
695 if (pkttype == RR3_MOD_SIGNAL_IN)
805 redrat3_process_ir_data(rr3); 696 redrat3_process_ir_data(rr3);
806 else 697 else
807 rr3_dbg(dev, "discarding non-signal data packet " 698 rr3_dbg(dev, "discarding non-signal data packet (type 0x%02x)\n",
808 "(type 0x%02x)\n", rr3->pkttype); 699 pkttype);
809 700
810out: 701out:
811 rr3->bytes_read = 0; 702 rr3->bytes_read = 0;
812 rr3->pktlen = 0;
813 rr3->pkttype = 0;
814 return ret; 703 return ret;
815} 704}
816 705
817/* callback function from USB when async USB request has completed */ 706/* callback function from USB when async USB request has completed */
818static void redrat3_handle_async(struct urb *urb, struct pt_regs *regs) 707static void redrat3_handle_async(struct urb *urb)
819{ 708{
820 struct redrat3_dev *rr3; 709 struct redrat3_dev *rr3;
821 int ret; 710 int ret;
@@ -851,34 +740,16 @@ static void redrat3_handle_async(struct urb *urb, struct pt_regs *regs)
851 default: 740 default:
852 dev_warn(rr3->dev, "Error: urb status = %d\n", urb->status); 741 dev_warn(rr3->dev, "Error: urb status = %d\n", urb->status);
853 rr3->bytes_read = 0; 742 rr3->bytes_read = 0;
854 rr3->pktlen = 0;
855 rr3->pkttype = 0;
856 break; 743 break;
857 } 744 }
858} 745}
859 746
860static void redrat3_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
861{
862 struct redrat3_dev *rr3;
863 int len;
864
865 if (!urb)
866 return;
867
868 rr3 = urb->context;
869 if (rr3) {
870 len = urb->actual_length;
871 rr3_ftr(rr3->dev, "%s: called (status=%d len=%d)\n",
872 __func__, urb->status, len);
873 }
874}
875
876static u16 mod_freq_to_val(unsigned int mod_freq) 747static u16 mod_freq_to_val(unsigned int mod_freq)
877{ 748{
878 int mult = 6000000; 749 int mult = 6000000;
879 750
880 /* Clk used in mod. freq. generation is CLK24/4. */ 751 /* Clk used in mod. freq. generation is CLK24/4. */
881 return (u16)(65536 - (mult / mod_freq)); 752 return 65536 - (mult / mod_freq);
882} 753}
883 754
884static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier) 755static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
@@ -900,17 +771,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
900{ 771{
901 struct redrat3_dev *rr3 = rcdev->priv; 772 struct redrat3_dev *rr3 = rcdev->priv;
902 struct device *dev = rr3->dev; 773 struct device *dev = rr3->dev;
903 struct redrat3_signal_header header; 774 struct redrat3_irdata *irdata = NULL;
904 int i, j, ret, ret_len, offset; 775 int ret, ret_len;
905 int lencheck, cur_sample_len, pipe; 776 int lencheck, cur_sample_len, pipe;
906 char *buffer = NULL, *sigdata = NULL;
907 int *sample_lens = NULL; 777 int *sample_lens = NULL;
908 u32 tmpi;
909 u16 tmps;
910 u8 *datap;
911 u8 curlencheck = 0; 778 u8 curlencheck = 0;
912 u16 *lengths_ptr; 779 unsigned i, sendbuf_len;
913 int sendbuf_len;
914 780
915 rr3_ftr(dev, "Entering %s\n", __func__); 781 rr3_ftr(dev, "Entering %s\n", __func__);
916 782
@@ -931,8 +797,19 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
931 goto out; 797 goto out;
932 } 798 }
933 799
800 irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
801 if (!irdata) {
802 ret = -ENOMEM;
803 goto out;
804 }
805
934 for (i = 0; i < count; i++) { 806 for (i = 0; i < count; i++) {
935 cur_sample_len = redrat3_us_to_len(txbuf[i]); 807 cur_sample_len = redrat3_us_to_len(txbuf[i]);
808 if (cur_sample_len > 0xffff) {
809 dev_warn(dev, "transmit period of %uus truncated to %uus\n",
810 txbuf[i], redrat3_len_to_us(0xffff));
811 cur_sample_len = 0xffff;
812 }
936 for (lencheck = 0; lencheck < curlencheck; lencheck++) { 813 for (lencheck = 0; lencheck < curlencheck; lencheck++) {
937 if (sample_lens[lencheck] == cur_sample_len) 814 if (sample_lens[lencheck] == cur_sample_len)
938 break; 815 break;
@@ -944,94 +821,41 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
944 /* now convert the value to a proper 821 /* now convert the value to a proper
945 * rr3 value.. */ 822 * rr3 value.. */
946 sample_lens[curlencheck] = cur_sample_len; 823 sample_lens[curlencheck] = cur_sample_len;
824 put_unaligned_be16(cur_sample_len,
825 &irdata->lens[curlencheck]);
947 curlencheck++; 826 curlencheck++;
948 } else { 827 } else {
949 count = i - 1; 828 count = i - 1;
950 break; 829 break;
951 } 830 }
952 } 831 }
832 irdata->sigdata[i] = lencheck;
953 } 833 }
954 834
955 sigdata = kzalloc((count + RR3_TX_TRAILER_LEN), GFP_KERNEL); 835 irdata->sigdata[count] = RR3_END_OF_SIGNAL;
956 if (!sigdata) { 836 irdata->sigdata[count + 1] = RR3_END_OF_SIGNAL;
957 ret = -ENOMEM;
958 goto out;
959 }
960
961 sigdata[count] = RR3_END_OF_SIGNAL;
962 sigdata[count + 1] = RR3_END_OF_SIGNAL;
963 for (i = 0; i < count; i++) {
964 for (j = 0; j < curlencheck; j++) {
965 if (sample_lens[j] == redrat3_us_to_len(txbuf[i]))
966 sigdata[i] = j;
967 }
968 }
969
970 offset = RR3_TX_HEADER_OFFSET;
971 sendbuf_len = RR3_HEADER_LENGTH + (sizeof(u16) * RR3_DRIVER_MAXLENS)
972 + count + RR3_TX_TRAILER_LEN + offset;
973
974 buffer = kzalloc(sendbuf_len, GFP_KERNEL);
975 if (!buffer) {
976 ret = -ENOMEM;
977 goto out;
978 }
979 837
838 sendbuf_len = offsetof(struct redrat3_irdata,
839 sigdata[count + RR3_TX_TRAILER_LEN]);
980 /* fill in our packet header */ 840 /* fill in our packet header */
981 header.length = sendbuf_len - offset; 841 irdata->header.length = cpu_to_be16(sendbuf_len -
982 header.transfer_type = RR3_MOD_SIGNAL_OUT; 842 sizeof(struct redrat3_header));
983 header.pause = redrat3_len_to_us(100); 843 irdata->header.transfer_type = cpu_to_be16(RR3_MOD_SIGNAL_OUT);
984 header.mod_freq_count = mod_freq_to_val(rr3->carrier); 844 irdata->pause = cpu_to_be32(redrat3_len_to_us(100));
985 header.no_periods = 0; /* n/a to transmit */ 845 irdata->mod_freq_count = cpu_to_be16(mod_freq_to_val(rr3->carrier));
986 header.max_lengths = RR3_DRIVER_MAXLENS; 846 irdata->no_lengths = curlencheck;
987 header.no_lengths = curlencheck; 847 irdata->sig_size = cpu_to_be16(count + RR3_TX_TRAILER_LEN);
988 header.max_sig_size = RR3_MAX_SIG_SIZE;
989 header.sig_size = count + RR3_TX_TRAILER_LEN;
990 /* we currently rely on repeat handling in the IR encoding source */
991 header.no_repeats = 0;
992
993 tmps = cpu_to_be16(header.length);
994 memcpy(buffer, &tmps, 2);
995
996 tmps = cpu_to_be16(header.transfer_type);
997 memcpy(buffer + 2, &tmps, 2);
998
999 tmpi = cpu_to_be32(header.pause);
1000 memcpy(buffer + offset, &tmpi, sizeof(tmpi));
1001
1002 tmps = cpu_to_be16(header.mod_freq_count);
1003 memcpy(buffer + offset + RR3_FREQ_COUNT_OFFSET, &tmps, 2);
1004
1005 buffer[offset + RR3_NUM_LENGTHS_OFFSET] = header.no_lengths;
1006
1007 tmps = cpu_to_be16(header.sig_size);
1008 memcpy(buffer + offset + RR3_NUM_SIGS_OFFSET, &tmps, 2);
1009
1010 buffer[offset + RR3_REPEATS_OFFSET] = header.no_repeats;
1011
1012 lengths_ptr = (u16 *)(buffer + offset + RR3_HEADER_LENGTH);
1013 for (i = 0; i < curlencheck; ++i)
1014 lengths_ptr[i] = cpu_to_be16(sample_lens[i]);
1015
1016 datap = (u8 *)(buffer + offset + RR3_HEADER_LENGTH +
1017 (sizeof(u16) * RR3_DRIVER_MAXLENS));
1018 memcpy(datap, sigdata, (count + RR3_TX_TRAILER_LEN));
1019
1020 if (debug) {
1021 redrat3_dump_signal_header(&header);
1022 redrat3_dump_signal_data(buffer, header.sig_size);
1023 }
1024 848
1025 pipe = usb_sndbulkpipe(rr3->udev, rr3->ep_out->bEndpointAddress); 849 pipe = usb_sndbulkpipe(rr3->udev, rr3->ep_out->bEndpointAddress);
1026 tmps = usb_bulk_msg(rr3->udev, pipe, buffer, 850 ret = usb_bulk_msg(rr3->udev, pipe, irdata,
1027 sendbuf_len, &ret_len, 10 * HZ); 851 sendbuf_len, &ret_len, 10 * HZ);
1028 rr3_dbg(dev, "sent %d bytes, (ret %d)\n", ret_len, tmps); 852 rr3_dbg(dev, "sent %d bytes, (ret %d)\n", ret_len, ret);
1029 853
1030 /* now tell the hardware to transmit what we sent it */ 854 /* now tell the hardware to transmit what we sent it */
1031 pipe = usb_rcvctrlpipe(rr3->udev, 0); 855 pipe = usb_rcvctrlpipe(rr3->udev, 0);
1032 ret = usb_control_msg(rr3->udev, pipe, RR3_TX_SEND_SIGNAL, 856 ret = usb_control_msg(rr3->udev, pipe, RR3_TX_SEND_SIGNAL,
1033 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 857 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
1034 0, 0, buffer, 2, HZ * 10); 858 0, 0, irdata, 2, HZ * 10);
1035 859
1036 if (ret < 0) 860 if (ret < 0)
1037 dev_err(dev, "Error: control msg send failed, rc %d\n", ret); 861 dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
@@ -1040,8 +864,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
1040 864
1041out: 865out:
1042 kfree(sample_lens); 866 kfree(sample_lens);
1043 kfree(buffer); 867 kfree(irdata);
1044 kfree(sigdata);
1045 868
1046 rr3->transmitting = false; 869 rr3->transmitting = false;
1047 /* rr3 re-enables rc detector because it was enabled before */ 870 /* rr3 re-enables rc detector because it was enabled before */
@@ -1165,38 +988,18 @@ static int redrat3_dev_probe(struct usb_interface *intf,
1165 } 988 }
1166 989
1167 rr3->ep_in = ep_in; 990 rr3->ep_in = ep_in;
1168 rr3->bulk_in_buf = usb_alloc_coherent(udev, ep_in->wMaxPacketSize, 991 rr3->bulk_in_buf = usb_alloc_coherent(udev,
1169 GFP_ATOMIC, &rr3->dma_in); 992 le16_to_cpu(ep_in->wMaxPacketSize), GFP_ATOMIC, &rr3->dma_in);
1170 if (!rr3->bulk_in_buf) { 993 if (!rr3->bulk_in_buf) {
1171 dev_err(dev, "Read buffer allocation failure\n"); 994 dev_err(dev, "Read buffer allocation failure\n");
1172 goto error; 995 goto error;
1173 } 996 }
1174 997
1175 pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress); 998 pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress);
1176 usb_fill_bulk_urb(rr3->read_urb, udev, pipe, 999 usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf,
1177 rr3->bulk_in_buf, ep_in->wMaxPacketSize, 1000 le16_to_cpu(ep_in->wMaxPacketSize), redrat3_handle_async, rr3);
1178 (usb_complete_t)redrat3_handle_async, rr3);
1179
1180 /* set up bulk-out endpoint*/
1181 rr3->write_urb = usb_alloc_urb(0, GFP_KERNEL);
1182 if (!rr3->write_urb) {
1183 dev_err(dev, "Write urb allocation failure\n");
1184 goto error;
1185 }
1186 1001
1187 rr3->ep_out = ep_out; 1002 rr3->ep_out = ep_out;
1188 rr3->bulk_out_buf = usb_alloc_coherent(udev, ep_out->wMaxPacketSize,
1189 GFP_ATOMIC, &rr3->dma_out);
1190 if (!rr3->bulk_out_buf) {
1191 dev_err(dev, "Write buffer allocation failure\n");
1192 goto error;
1193 }
1194
1195 pipe = usb_sndbulkpipe(udev, ep_out->bEndpointAddress);
1196 usb_fill_bulk_urb(rr3->write_urb, udev, pipe,
1197 rr3->bulk_out_buf, ep_out->wMaxPacketSize,
1198 (usb_complete_t)redrat3_write_bulk_callback, rr3);
1199
1200 rr3->udev = udev; 1003 rr3->udev = udev;
1201 1004
1202 redrat3_reset(rr3); 1005 redrat3_reset(rr3);
diff --git a/drivers/media/rc/ttusbir.c b/drivers/media/rc/ttusbir.c
index cf0d47f57fb2..891762d167ed 100644
--- a/drivers/media/rc/ttusbir.c
+++ b/drivers/media/rc/ttusbir.c
@@ -347,6 +347,7 @@ static int ttusbir_probe(struct usb_interface *intf,
347 return 0; 347 return 0;
348out3: 348out3:
349 rc_unregister_device(rc); 349 rc_unregister_device(rc);
350 rc = NULL;
350out2: 351out2:
351 led_classdev_unregister(&tt->led); 352 led_classdev_unregister(&tt->led);
352out: 353out:
diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 535a18dccbd0..87af2d3ba601 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -1151,6 +1151,7 @@ exit_release_wbase:
1151 release_region(data->wbase, WAKEUP_IOMEM_LEN); 1151 release_region(data->wbase, WAKEUP_IOMEM_LEN);
1152exit_unregister_device: 1152exit_unregister_device:
1153 rc_unregister_device(data->dev); 1153 rc_unregister_device(data->dev);
1154 data->dev = NULL;
1154exit_free_rc: 1155exit_free_rc:
1155 rc_free_device(data->dev); 1156 rc_free_device(data->dev);
1156exit_unregister_led: 1157exit_unregister_led:
diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index e8fdf713fce8..f6768cad001a 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -241,4 +241,18 @@ config MEDIA_TUNER_TUA9001
241 default m if !MEDIA_SUBDRV_AUTOSELECT 241 default m if !MEDIA_SUBDRV_AUTOSELECT
242 help 242 help
243 Infineon TUA 9001 silicon tuner driver. 243 Infineon TUA 9001 silicon tuner driver.
244
245config MEDIA_TUNER_IT913X
246 tristate "ITE Tech IT913x silicon tuner"
247 depends on MEDIA_SUPPORT && I2C
248 default m if !MEDIA_SUBDRV_AUTOSELECT
249 help
250 ITE Tech IT913x silicon tuner driver.
251
252config MEDIA_TUNER_R820T
253 tristate "Rafael Micro R820T silicon tuner"
254 depends on MEDIA_SUPPORT && I2C
255 default m if !MEDIA_SUBDRV_AUTOSELECT
256 help
257 Rafael Micro R820T silicon tuner driver.
244endmenu 258endmenu
diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile
index 5e569b1083cf..308f108eadba 100644
--- a/drivers/media/tuners/Makefile
+++ b/drivers/media/tuners/Makefile
@@ -34,6 +34,8 @@ obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o
34obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o 34obj-$(CONFIG_MEDIA_TUNER_FC0011) += fc0011.o
35obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o 35obj-$(CONFIG_MEDIA_TUNER_FC0012) += fc0012.o
36obj-$(CONFIG_MEDIA_TUNER_FC0013) += fc0013.o 36obj-$(CONFIG_MEDIA_TUNER_FC0013) += fc0013.o
37obj-$(CONFIG_MEDIA_TUNER_IT913X) += tuner_it913x.o
38obj-$(CONFIG_MEDIA_TUNER_R820T) += r820t.o
37 39
38ccflags-y += -I$(srctree)/drivers/media/dvb-core 40ccflags-y += -I$(srctree)/drivers/media/dvb-core
39ccflags-y += -I$(srctree)/drivers/media/dvb-frontends 41ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
diff --git a/drivers/media/tuners/e4000.h b/drivers/media/tuners/e4000.h
index 71b1935eb3d2..3783a0bdf855 100644
--- a/drivers/media/tuners/e4000.h
+++ b/drivers/media/tuners/e4000.h
@@ -21,6 +21,7 @@
21#ifndef E4000_H 21#ifndef E4000_H
22#define E4000_H 22#define E4000_H
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
26struct e4000_config { 27struct e4000_config {
@@ -36,8 +37,7 @@ struct e4000_config {
36 u32 clock; 37 u32 clock;
37}; 38};
38 39
39#if defined(CONFIG_MEDIA_TUNER_E4000) || \ 40#if IS_ENABLED(CONFIG_MEDIA_TUNER_E4000)
40 (defined(CONFIG_MEDIA_TUNER_E4000_MODULE) && defined(MODULE))
41extern struct dvb_frontend *e4000_attach(struct dvb_frontend *fe, 41extern struct dvb_frontend *e4000_attach(struct dvb_frontend *fe,
42 struct i2c_adapter *i2c, const struct e4000_config *cfg); 42 struct i2c_adapter *i2c, const struct e4000_config *cfg);
43#else 43#else
diff --git a/drivers/media/tuners/fc0011.h b/drivers/media/tuners/fc0011.h
index 0ee581f122d2..43ec893a6877 100644
--- a/drivers/media/tuners/fc0011.h
+++ b/drivers/media/tuners/fc0011.h
@@ -1,6 +1,7 @@
1#ifndef LINUX_FC0011_H_ 1#ifndef LINUX_FC0011_H_
2#define LINUX_FC0011_H_ 2#define LINUX_FC0011_H_
3 3
4#include <linux/kconfig.h>
4#include "dvb_frontend.h" 5#include "dvb_frontend.h"
5 6
6 7
@@ -22,8 +23,7 @@ enum fc0011_fe_callback_commands {
22 FC0011_FE_CALLBACK_RESET, 23 FC0011_FE_CALLBACK_RESET,
23}; 24};
24 25
25#if defined(CONFIG_MEDIA_TUNER_FC0011) ||\ 26#if IS_ENABLED(CONFIG_MEDIA_TUNER_FC0011)
26 defined(CONFIG_MEDIA_TUNER_FC0011_MODULE)
27struct dvb_frontend *fc0011_attach(struct dvb_frontend *fe, 27struct dvb_frontend *fc0011_attach(struct dvb_frontend *fe,
28 struct i2c_adapter *i2c, 28 struct i2c_adapter *i2c,
29 const struct fc0011_config *config); 29 const struct fc0011_config *config);
diff --git a/drivers/media/tuners/fc0012.h b/drivers/media/tuners/fc0012.h
index 54508fcc3469..1d08057e3275 100644
--- a/drivers/media/tuners/fc0012.h
+++ b/drivers/media/tuners/fc0012.h
@@ -21,6 +21,7 @@
21#ifndef _FC0012_H_ 21#ifndef _FC0012_H_
22#define _FC0012_H_ 22#define _FC0012_H_
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25#include "fc001x-common.h" 26#include "fc001x-common.h"
26 27
@@ -48,8 +49,7 @@ struct fc0012_config {
48 bool clock_out; 49 bool clock_out;
49}; 50};
50 51
51#if defined(CONFIG_MEDIA_TUNER_FC0012) || \ 52#if IS_ENABLED(CONFIG_MEDIA_TUNER_FC0012)
52 (defined(CONFIG_MEDIA_TUNER_FC0012_MODULE) && defined(MODULE))
53extern struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe, 53extern struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
54 struct i2c_adapter *i2c, 54 struct i2c_adapter *i2c,
55 const struct fc0012_config *cfg); 55 const struct fc0012_config *cfg);
diff --git a/drivers/media/tuners/fc0013.h b/drivers/media/tuners/fc0013.h
index 594efd64aeec..d65d5b37f56e 100644
--- a/drivers/media/tuners/fc0013.h
+++ b/drivers/media/tuners/fc0013.h
@@ -22,11 +22,11 @@
22#ifndef _FC0013_H_ 22#ifndef _FC0013_H_
23#define _FC0013_H_ 23#define _FC0013_H_
24 24
25#include <linux/kconfig.h>
25#include "dvb_frontend.h" 26#include "dvb_frontend.h"
26#include "fc001x-common.h" 27#include "fc001x-common.h"
27 28
28#if defined(CONFIG_MEDIA_TUNER_FC0013) || \ 29#if IS_ENABLED(CONFIG_MEDIA_TUNER_FC0013)
29 (defined(CONFIG_MEDIA_TUNER_FC0013_MODULE) && defined(MODULE))
30extern struct dvb_frontend *fc0013_attach(struct dvb_frontend *fe, 30extern struct dvb_frontend *fc0013_attach(struct dvb_frontend *fe,
31 struct i2c_adapter *i2c, 31 struct i2c_adapter *i2c,
32 u8 i2c_address, int dual_master, 32 u8 i2c_address, int dual_master,
diff --git a/drivers/media/tuners/fc2580.h b/drivers/media/tuners/fc2580.h
index 222601e5d23b..9c43c1cc82d9 100644
--- a/drivers/media/tuners/fc2580.h
+++ b/drivers/media/tuners/fc2580.h
@@ -21,6 +21,7 @@
21#ifndef FC2580_H 21#ifndef FC2580_H
22#define FC2580_H 22#define FC2580_H
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
26struct fc2580_config { 27struct fc2580_config {
@@ -36,8 +37,7 @@ struct fc2580_config {
36 u32 clock; 37 u32 clock;
37}; 38};
38 39
39#if defined(CONFIG_MEDIA_TUNER_FC2580) || \ 40#if IS_ENABLED(CONFIG_MEDIA_TUNER_FC2580)
40 (defined(CONFIG_MEDIA_TUNER_FC2580_MODULE) && defined(MODULE))
41extern struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe, 41extern struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
42 struct i2c_adapter *i2c, const struct fc2580_config *cfg); 42 struct i2c_adapter *i2c, const struct fc2580_config *cfg);
43#else 43#else
diff --git a/drivers/media/tuners/max2165.h b/drivers/media/tuners/max2165.h
index c063c36a93d3..26e1dc64bb67 100644
--- a/drivers/media/tuners/max2165.h
+++ b/drivers/media/tuners/max2165.h
@@ -22,6 +22,8 @@
22#ifndef __MAX2165_H__ 22#ifndef __MAX2165_H__
23#define __MAX2165_H__ 23#define __MAX2165_H__
24 24
25#include <linux/kconfig.h>
26
25struct dvb_frontend; 27struct dvb_frontend;
26struct i2c_adapter; 28struct i2c_adapter;
27 29
@@ -30,8 +32,7 @@ struct max2165_config {
30 u8 osc_clk; /* in MHz, selectable values: 4,16,18,20,22,24,26,28 */ 32 u8 osc_clk; /* in MHz, selectable values: 4,16,18,20,22,24,26,28 */
31}; 33};
32 34
33#if defined(CONFIG_MEDIA_TUNER_MAX2165) || \ 35#if IS_ENABLED(CONFIG_MEDIA_TUNER_MAX2165)
34 (defined(CONFIG_MEDIA_TUNER_MAX2165_MODULE) && defined(MODULE))
35extern struct dvb_frontend *max2165_attach(struct dvb_frontend *fe, 36extern struct dvb_frontend *max2165_attach(struct dvb_frontend *fe,
36 struct i2c_adapter *i2c, 37 struct i2c_adapter *i2c,
37 struct max2165_config *cfg); 38 struct max2165_config *cfg);
diff --git a/drivers/media/tuners/mc44s803.h b/drivers/media/tuners/mc44s803.h
index 34f3892d3f6d..9aae50aca2b7 100644
--- a/drivers/media/tuners/mc44s803.h
+++ b/drivers/media/tuners/mc44s803.h
@@ -22,6 +22,8 @@
22#ifndef MC44S803_H 22#ifndef MC44S803_H
23#define MC44S803_H 23#define MC44S803_H
24 24
25#include <linux/kconfig.h>
26
25struct dvb_frontend; 27struct dvb_frontend;
26struct i2c_adapter; 28struct i2c_adapter;
27 29
@@ -30,8 +32,7 @@ struct mc44s803_config {
30 u8 dig_out; 32 u8 dig_out;
31}; 33};
32 34
33#if defined(CONFIG_MEDIA_TUNER_MC44S803) || \ 35#if IS_ENABLED(CONFIG_MEDIA_TUNER_MC44S803)
34 (defined(CONFIG_MEDIA_TUNER_MC44S803_MODULE) && defined(MODULE))
35extern struct dvb_frontend *mc44s803_attach(struct dvb_frontend *fe, 36extern struct dvb_frontend *mc44s803_attach(struct dvb_frontend *fe,
36 struct i2c_adapter *i2c, struct mc44s803_config *cfg); 37 struct i2c_adapter *i2c, struct mc44s803_config *cfg);
37#else 38#else
diff --git a/drivers/media/tuners/mxl5005s.h b/drivers/media/tuners/mxl5005s.h
index fc8a1ffc53b4..ae8db885ad87 100644
--- a/drivers/media/tuners/mxl5005s.h
+++ b/drivers/media/tuners/mxl5005s.h
@@ -23,6 +23,8 @@
23#ifndef __MXL5005S_H 23#ifndef __MXL5005S_H
24#define __MXL5005S_H 24#define __MXL5005S_H
25 25
26#include <linux/kconfig.h>
27
26#include <linux/i2c.h> 28#include <linux/i2c.h>
27#include "dvb_frontend.h" 29#include "dvb_frontend.h"
28 30
@@ -116,8 +118,7 @@ struct mxl5005s_config {
116 u8 AgcMasterByte; 118 u8 AgcMasterByte;
117}; 119};
118 120
119#if defined(CONFIG_MEDIA_TUNER_MXL5005S) || \ 121#if IS_ENABLED(CONFIG_MEDIA_TUNER_MXL5005S)
120 (defined(CONFIG_MEDIA_TUNER_MXL5005S_MODULE) && defined(MODULE))
121extern struct dvb_frontend *mxl5005s_attach(struct dvb_frontend *fe, 122extern struct dvb_frontend *mxl5005s_attach(struct dvb_frontend *fe,
122 struct i2c_adapter *i2c, 123 struct i2c_adapter *i2c,
123 struct mxl5005s_config *config); 124 struct mxl5005s_config *config);
diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
new file mode 100644
index 000000000000..4835021aa3b6
--- /dev/null
+++ b/drivers/media/tuners/r820t.c
@@ -0,0 +1,2355 @@
1/*
2 * Rafael Micro R820T driver
3 *
4 * Copyright (C) 2013 Mauro Carvalho Chehab <mchehab@redhat.com>
5 *
6 * This driver was written from scratch, based on an existing driver
7 * that it is part of rtl-sdr git tree, released under GPLv2:
8 * https://groups.google.com/forum/#!topic/ultra-cheap-sdr/Y3rBEOFtHug
9 * https://github.com/n1gp/gr-baz
10 *
11 * From what I understood from the threads, the original driver was converted
12 * to userspace from a Realtek tree. I couldn't find the original tree.
13 * However, the original driver look awkward on my eyes. So, I decided to
14 * write a new version from it from the scratch, while trying to reproduce
15 * everything found there.
16 *
17 * TODO:
18 * After locking, the original driver seems to have some routines to
19 * improve reception. This was not implemented here yet.
20 *
21 * RF Gain set/get is not implemented.
22 *
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 */
34
35#include <linux/videodev2.h>
36#include <linux/mutex.h>
37#include <linux/slab.h>
38#include <linux/bitrev.h>
39
40#include "tuner-i2c.h"
41#include "r820t.h"
42
43/*
44 * FIXME: I think that there are only 32 registers, but better safe than
45 * sorry. After finishing the driver, we may review it.
46 */
47#define REG_SHADOW_START 5
48#define NUM_REGS 27
49#define NUM_IMR 5
50#define IMR_TRIAL 9
51
52#define VER_NUM 49
53
54static int debug;
55module_param(debug, int, 0644);
56MODULE_PARM_DESC(debug, "enable verbose debug messages");
57
58static int no_imr_cal;
59module_param(no_imr_cal, int, 0444);
60MODULE_PARM_DESC(no_imr_cal, "Disable IMR calibration at module init");
61
62
63/*
64 * enums and structures
65 */
66
67enum xtal_cap_value {
68 XTAL_LOW_CAP_30P = 0,
69 XTAL_LOW_CAP_20P,
70 XTAL_LOW_CAP_10P,
71 XTAL_LOW_CAP_0P,
72 XTAL_HIGH_CAP_0P
73};
74
75struct r820t_sect_type {
76 u8 phase_y;
77 u8 gain_x;
78 u16 value;
79};
80
81struct r820t_priv {
82 struct list_head hybrid_tuner_instance_list;
83 const struct r820t_config *cfg;
84 struct tuner_i2c_props i2c_props;
85 struct mutex lock;
86
87 u8 regs[NUM_REGS];
88 u8 buf[NUM_REGS + 1];
89 enum xtal_cap_value xtal_cap_sel;
90 u16 pll; /* kHz */
91 u32 int_freq;
92 u8 fil_cal_code;
93 bool imr_done;
94 bool has_lock;
95 bool init_done;
96 struct r820t_sect_type imr_data[NUM_IMR];
97
98 /* Store current mode */
99 u32 delsys;
100 enum v4l2_tuner_type type;
101 v4l2_std_id std;
102 u32 bw; /* in MHz */
103};
104
105struct r820t_freq_range {
106 u32 freq;
107 u8 open_d;
108 u8 rf_mux_ploy;
109 u8 tf_c;
110 u8 xtal_cap20p;
111 u8 xtal_cap10p;
112 u8 xtal_cap0p;
113 u8 imr_mem; /* Not used, currently */
114};
115
116#define VCO_POWER_REF 0x02
117#define DIP_FREQ 32000000
118
119/*
120 * Static constants
121 */
122
123static LIST_HEAD(hybrid_tuner_instance_list);
124static DEFINE_MUTEX(r820t_list_mutex);
125
126/* Those initial values start from REG_SHADOW_START */
127static const u8 r820t_init_array[NUM_REGS] = {
128 0x83, 0x32, 0x75, /* 05 to 07 */
129 0xc0, 0x40, 0xd6, 0x6c, /* 08 to 0b */
130 0xf5, 0x63, 0x75, 0x68, /* 0c to 0f */
131 0x6c, 0x83, 0x80, 0x00, /* 10 to 13 */
132 0x0f, 0x00, 0xc0, 0x30, /* 14 to 17 */
133 0x48, 0xcc, 0x60, 0x00, /* 18 to 1b */
134 0x54, 0xae, 0x4a, 0xc0 /* 1c to 1f */
135};
136
137/* Tuner frequency ranges */
138static const struct r820t_freq_range freq_ranges[] = {
139 {
140 .freq = 0,
141 .open_d = 0x08, /* low */
142 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
143 .tf_c = 0xdf, /* R27[7:0] band2,band0 */
144 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
145 .xtal_cap10p = 0x01,
146 .xtal_cap0p = 0x00,
147 .imr_mem = 0,
148 }, {
149 .freq = 50, /* Start freq, in MHz */
150 .open_d = 0x08, /* low */
151 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
152 .tf_c = 0xbe, /* R27[7:0] band4,band1 */
153 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
154 .xtal_cap10p = 0x01,
155 .xtal_cap0p = 0x00,
156 .imr_mem = 0,
157 }, {
158 .freq = 55, /* Start freq, in MHz */
159 .open_d = 0x08, /* low */
160 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
161 .tf_c = 0x8b, /* R27[7:0] band7,band4 */
162 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
163 .xtal_cap10p = 0x01,
164 .xtal_cap0p = 0x00,
165 .imr_mem = 0,
166 }, {
167 .freq = 60, /* Start freq, in MHz */
168 .open_d = 0x08, /* low */
169 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
170 .tf_c = 0x7b, /* R27[7:0] band8,band4 */
171 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
172 .xtal_cap10p = 0x01,
173 .xtal_cap0p = 0x00,
174 .imr_mem = 0,
175 }, {
176 .freq = 65, /* Start freq, in MHz */
177 .open_d = 0x08, /* low */
178 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
179 .tf_c = 0x69, /* R27[7:0] band9,band6 */
180 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
181 .xtal_cap10p = 0x01,
182 .xtal_cap0p = 0x00,
183 .imr_mem = 0,
184 }, {
185 .freq = 70, /* Start freq, in MHz */
186 .open_d = 0x08, /* low */
187 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
188 .tf_c = 0x58, /* R27[7:0] band10,band7 */
189 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
190 .xtal_cap10p = 0x01,
191 .xtal_cap0p = 0x00,
192 .imr_mem = 0,
193 }, {
194 .freq = 75, /* Start freq, in MHz */
195 .open_d = 0x00, /* high */
196 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
197 .tf_c = 0x44, /* R27[7:0] band11,band11 */
198 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
199 .xtal_cap10p = 0x01,
200 .xtal_cap0p = 0x00,
201 .imr_mem = 0,
202 }, {
203 .freq = 80, /* Start freq, in MHz */
204 .open_d = 0x00, /* high */
205 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
206 .tf_c = 0x44, /* R27[7:0] band11,band11 */
207 .xtal_cap20p = 0x02, /* R16[1:0] 20pF (10) */
208 .xtal_cap10p = 0x01,
209 .xtal_cap0p = 0x00,
210 .imr_mem = 0,
211 }, {
212 .freq = 90, /* Start freq, in MHz */
213 .open_d = 0x00, /* high */
214 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
215 .tf_c = 0x34, /* R27[7:0] band12,band11 */
216 .xtal_cap20p = 0x01, /* R16[1:0] 10pF (01) */
217 .xtal_cap10p = 0x01,
218 .xtal_cap0p = 0x00,
219 .imr_mem = 0,
220 }, {
221 .freq = 100, /* Start freq, in MHz */
222 .open_d = 0x00, /* high */
223 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
224 .tf_c = 0x34, /* R27[7:0] band12,band11 */
225 .xtal_cap20p = 0x01, /* R16[1:0] 10pF (01) */
226 .xtal_cap10p = 0x01,
227 .xtal_cap0p = 0x00,
228 .imr_mem = 0,
229 }, {
230 .freq = 110, /* Start freq, in MHz */
231 .open_d = 0x00, /* high */
232 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
233 .tf_c = 0x24, /* R27[7:0] band13,band11 */
234 .xtal_cap20p = 0x01, /* R16[1:0] 10pF (01) */
235 .xtal_cap10p = 0x01,
236 .xtal_cap0p = 0x00,
237 .imr_mem = 1,
238 }, {
239 .freq = 120, /* Start freq, in MHz */
240 .open_d = 0x00, /* high */
241 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
242 .tf_c = 0x24, /* R27[7:0] band13,band11 */
243 .xtal_cap20p = 0x01, /* R16[1:0] 10pF (01) */
244 .xtal_cap10p = 0x01,
245 .xtal_cap0p = 0x00,
246 .imr_mem = 1,
247 }, {
248 .freq = 140, /* Start freq, in MHz */
249 .open_d = 0x00, /* high */
250 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
251 .tf_c = 0x14, /* R27[7:0] band14,band11 */
252 .xtal_cap20p = 0x01, /* R16[1:0] 10pF (01) */
253 .xtal_cap10p = 0x01,
254 .xtal_cap0p = 0x00,
255 .imr_mem = 1,
256 }, {
257 .freq = 180, /* Start freq, in MHz */
258 .open_d = 0x00, /* high */
259 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
260 .tf_c = 0x13, /* R27[7:0] band14,band12 */
261 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
262 .xtal_cap10p = 0x00,
263 .xtal_cap0p = 0x00,
264 .imr_mem = 1,
265 }, {
266 .freq = 220, /* Start freq, in MHz */
267 .open_d = 0x00, /* high */
268 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
269 .tf_c = 0x13, /* R27[7:0] band14,band12 */
270 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
271 .xtal_cap10p = 0x00,
272 .xtal_cap0p = 0x00,
273 .imr_mem = 2,
274 }, {
275 .freq = 250, /* Start freq, in MHz */
276 .open_d = 0x00, /* high */
277 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
278 .tf_c = 0x11, /* R27[7:0] highest,highest */
279 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
280 .xtal_cap10p = 0x00,
281 .xtal_cap0p = 0x00,
282 .imr_mem = 2,
283 }, {
284 .freq = 280, /* Start freq, in MHz */
285 .open_d = 0x00, /* high */
286 .rf_mux_ploy = 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
287 .tf_c = 0x00, /* R27[7:0] highest,highest */
288 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
289 .xtal_cap10p = 0x00,
290 .xtal_cap0p = 0x00,
291 .imr_mem = 2,
292 }, {
293 .freq = 310, /* Start freq, in MHz */
294 .open_d = 0x00, /* high */
295 .rf_mux_ploy = 0x41, /* R26[7:6]=1 (bypass) R26[1:0]=1 (middle) */
296 .tf_c = 0x00, /* R27[7:0] highest,highest */
297 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
298 .xtal_cap10p = 0x00,
299 .xtal_cap0p = 0x00,
300 .imr_mem = 2,
301 }, {
302 .freq = 450, /* Start freq, in MHz */
303 .open_d = 0x00, /* high */
304 .rf_mux_ploy = 0x41, /* R26[7:6]=1 (bypass) R26[1:0]=1 (middle) */
305 .tf_c = 0x00, /* R27[7:0] highest,highest */
306 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
307 .xtal_cap10p = 0x00,
308 .xtal_cap0p = 0x00,
309 .imr_mem = 3,
310 }, {
311 .freq = 588, /* Start freq, in MHz */
312 .open_d = 0x00, /* high */
313 .rf_mux_ploy = 0x40, /* R26[7:6]=1 (bypass) R26[1:0]=0 (highest) */
314 .tf_c = 0x00, /* R27[7:0] highest,highest */
315 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
316 .xtal_cap10p = 0x00,
317 .xtal_cap0p = 0x00,
318 .imr_mem = 3,
319 }, {
320 .freq = 650, /* Start freq, in MHz */
321 .open_d = 0x00, /* high */
322 .rf_mux_ploy = 0x40, /* R26[7:6]=1 (bypass) R26[1:0]=0 (highest) */
323 .tf_c = 0x00, /* R27[7:0] highest,highest */
324 .xtal_cap20p = 0x00, /* R16[1:0] 0pF (00) */
325 .xtal_cap10p = 0x00,
326 .xtal_cap0p = 0x00,
327 .imr_mem = 4,
328 }
329};
330
331static int r820t_xtal_capacitor[][2] = {
332 { 0x0b, XTAL_LOW_CAP_30P },
333 { 0x02, XTAL_LOW_CAP_20P },
334 { 0x01, XTAL_LOW_CAP_10P },
335 { 0x00, XTAL_LOW_CAP_0P },
336 { 0x10, XTAL_HIGH_CAP_0P },
337};
338
339/*
340 * measured with a Racal 6103E GSM test set at 928 MHz with -60 dBm
341 * input power, for raw results see:
342 * http://steve-m.de/projects/rtl-sdr/gain_measurement/r820t/
343 */
344
345static const int r820t_lna_gain_steps[] = {
346 0, 9, 13, 40, 38, 13, 31, 22, 26, 31, 26, 14, 19, 5, 35, 13
347};
348
349static const int r820t_mixer_gain_steps[] = {
350 0, 5, 10, 10, 19, 9, 10, 25, 17, 10, 8, 16, 13, 6, 3, -8
351};
352
353/*
354 * I2C read/write code and shadow registers logic
355 */
356static void shadow_store(struct r820t_priv *priv, u8 reg, const u8 *val,
357 int len)
358{
359 int r = reg - REG_SHADOW_START;
360
361 if (r < 0) {
362 len += r;
363 r = 0;
364 }
365 if (len <= 0)
366 return;
367 if (len > NUM_REGS)
368 len = NUM_REGS;
369
370 tuner_dbg("%s: prev reg=%02x len=%d: %*ph\n",
371 __func__, r + REG_SHADOW_START, len, len, val);
372
373 memcpy(&priv->regs[r], val, len);
374}
375
376static int r820t_write(struct r820t_priv *priv, u8 reg, const u8 *val,
377 int len)
378{
379 int rc, size, pos = 0;
380
381 /* Store the shadow registers */
382 shadow_store(priv, reg, val, len);
383
384 do {
385 if (len > priv->cfg->max_i2c_msg_len - 1)
386 size = priv->cfg->max_i2c_msg_len - 1;
387 else
388 size = len;
389
390 /* Fill I2C buffer */
391 priv->buf[0] = reg;
392 memcpy(&priv->buf[1], &val[pos], size);
393
394 rc = tuner_i2c_xfer_send(&priv->i2c_props, priv->buf, size + 1);
395 if (rc != size + 1) {
396 tuner_info("%s: i2c wr failed=%d reg=%02x len=%d: %*ph\n",
397 __func__, rc, reg, size, size, &priv->buf[1]);
398 if (rc < 0)
399 return rc;
400 return -EREMOTEIO;
401 }
402 tuner_dbg("%s: i2c wr reg=%02x len=%d: %*ph\n",
403 __func__, reg, size, size, &priv->buf[1]);
404
405 reg += size;
406 len -= size;
407 pos += size;
408 } while (len > 0);
409
410 return 0;
411}
412
413static int r820t_write_reg(struct r820t_priv *priv, u8 reg, u8 val)
414{
415 return r820t_write(priv, reg, &val, 1);
416}
417
418static int r820t_read_cache_reg(struct r820t_priv *priv, int reg)
419{
420 reg -= REG_SHADOW_START;
421
422 if (reg >= 0 && reg < NUM_REGS)
423 return priv->regs[reg];
424 else
425 return -EINVAL;
426}
427
428static int r820t_write_reg_mask(struct r820t_priv *priv, u8 reg, u8 val,
429 u8 bit_mask)
430{
431 int rc = r820t_read_cache_reg(priv, reg);
432
433 if (rc < 0)
434 return rc;
435
436 val = (rc & ~bit_mask) | (val & bit_mask);
437
438 return r820t_write(priv, reg, &val, 1);
439}
440
441static int r820t_read(struct r820t_priv *priv, u8 reg, u8 *val, int len)
442{
443 int rc, i;
444 u8 *p = &priv->buf[1];
445
446 priv->buf[0] = reg;
447
448 rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, priv->buf, 1, p, len);
449 if (rc != len) {
450 tuner_info("%s: i2c rd failed=%d reg=%02x len=%d: %*ph\n",
451 __func__, rc, reg, len, len, p);
452 if (rc < 0)
453 return rc;
454 return -EREMOTEIO;
455 }
456
457 /* Copy data to the output buffer */
458 for (i = 0; i < len; i++)
459 val[i] = bitrev8(p[i]);
460
461 tuner_dbg("%s: i2c rd reg=%02x len=%d: %*ph\n",
462 __func__, reg, len, len, val);
463
464 return 0;
465}
466
467/*
468 * r820t tuning logic
469 */
470
471static int r820t_set_mux(struct r820t_priv *priv, u32 freq)
472{
473 const struct r820t_freq_range *range;
474 int i, rc;
475 u8 val, reg08, reg09;
476
477 /* Get the proper frequency range */
478 freq = freq / 1000000;
479 for (i = 0; i < ARRAY_SIZE(freq_ranges) - 1; i++) {
480 if (freq < freq_ranges[i + 1].freq)
481 break;
482 }
483 range = &freq_ranges[i];
484
485 tuner_dbg("set r820t range#%d for frequency %d MHz\n", i, freq);
486
487 /* Open Drain */
488 rc = r820t_write_reg_mask(priv, 0x17, range->open_d, 0x08);
489 if (rc < 0)
490 return rc;
491
492 /* RF_MUX,Polymux */
493 rc = r820t_write_reg_mask(priv, 0x1a, range->rf_mux_ploy, 0xc3);
494 if (rc < 0)
495 return rc;
496
497 /* TF BAND */
498 rc = r820t_write_reg(priv, 0x1b, range->tf_c);
499 if (rc < 0)
500 return rc;
501
502 /* XTAL CAP & Drive */
503 switch (priv->xtal_cap_sel) {
504 case XTAL_LOW_CAP_30P:
505 case XTAL_LOW_CAP_20P:
506 val = range->xtal_cap20p | 0x08;
507 break;
508 case XTAL_LOW_CAP_10P:
509 val = range->xtal_cap10p | 0x08;
510 break;
511 case XTAL_HIGH_CAP_0P:
512 val = range->xtal_cap0p | 0x00;
513 break;
514 default:
515 case XTAL_LOW_CAP_0P:
516 val = range->xtal_cap0p | 0x08;
517 break;
518 }
519 rc = r820t_write_reg_mask(priv, 0x10, val, 0x0b);
520 if (rc < 0)
521 return rc;
522
523 if (priv->imr_done) {
524 reg08 = priv->imr_data[range->imr_mem].gain_x;
525 reg09 = priv->imr_data[range->imr_mem].phase_y;
526 } else {
527 reg08 = 0;
528 reg09 = 0;
529 }
530 rc = r820t_write_reg_mask(priv, 0x08, reg08, 0x3f);
531 if (rc < 0)
532 return rc;
533
534 rc = r820t_write_reg_mask(priv, 0x09, reg09, 0x3f);
535
536 return rc;
537}
538
539static int r820t_set_pll(struct r820t_priv *priv, enum v4l2_tuner_type type,
540 u32 freq)
541{
542 u32 vco_freq;
543 int rc, i;
544 unsigned sleep_time = 10000;
545 u32 vco_fra; /* VCO contribution by SDM (kHz) */
546 u32 vco_min = 1770000;
547 u32 vco_max = vco_min * 2;
548 u32 pll_ref;
549 u16 n_sdm = 2;
550 u16 sdm = 0;
551 u8 mix_div = 2;
552 u8 div_buf = 0;
553 u8 div_num = 0;
554 u8 refdiv2 = 0;
555 u8 ni, si, nint, vco_fine_tune, val;
556 u8 data[5];
557
558 /* Frequency in kHz */
559 freq = freq / 1000;
560 pll_ref = priv->cfg->xtal / 1000;
561
562#if 0
563 /* Doesn't exist on rtl-sdk, and on field tests, caused troubles */
564 if ((priv->cfg->rafael_chip == CHIP_R620D) ||
565 (priv->cfg->rafael_chip == CHIP_R828D) ||
566 (priv->cfg->rafael_chip == CHIP_R828)) {
567 /* ref set refdiv2, reffreq = Xtal/2 on ATV application */
568 if (type != V4L2_TUNER_DIGITAL_TV) {
569 pll_ref /= 2;
570 refdiv2 = 0x10;
571 sleep_time = 20000;
572 }
573 } else {
574 if (priv->cfg->xtal > 24000000) {
575 pll_ref /= 2;
576 refdiv2 = 0x10;
577 }
578 }
579#endif
580
581 rc = r820t_write_reg_mask(priv, 0x10, refdiv2, 0x10);
582 if (rc < 0)
583 return rc;
584
585 /* set pll autotune = 128kHz */
586 rc = r820t_write_reg_mask(priv, 0x1a, 0x00, 0x0c);
587 if (rc < 0)
588 return rc;
589
590 /* set VCO current = 100 */
591 rc = r820t_write_reg_mask(priv, 0x12, 0x80, 0xe0);
592 if (rc < 0)
593 return rc;
594
595 /* Calculate divider */
596 while (mix_div <= 64) {
597 if (((freq * mix_div) >= vco_min) &&
598 ((freq * mix_div) < vco_max)) {
599 div_buf = mix_div;
600 while (div_buf > 2) {
601 div_buf = div_buf >> 1;
602 div_num++;
603 }
604 break;
605 }
606 mix_div = mix_div << 1;
607 }
608
609 rc = r820t_read(priv, 0x00, data, sizeof(data));
610 if (rc < 0)
611 return rc;
612
613 vco_fine_tune = (data[4] & 0x30) >> 4;
614
615 if (vco_fine_tune > VCO_POWER_REF)
616 div_num = div_num - 1;
617 else if (vco_fine_tune < VCO_POWER_REF)
618 div_num = div_num + 1;
619
620 rc = r820t_write_reg_mask(priv, 0x10, div_num << 5, 0xe0);
621 if (rc < 0)
622 return rc;
623
624 vco_freq = freq * mix_div;
625 nint = vco_freq / (2 * pll_ref);
626 vco_fra = vco_freq - 2 * pll_ref * nint;
627
628 /* boundary spur prevention */
629 if (vco_fra < pll_ref / 64) {
630 vco_fra = 0;
631 } else if (vco_fra > pll_ref * 127 / 64) {
632 vco_fra = 0;
633 nint++;
634 } else if ((vco_fra > pll_ref * 127 / 128) && (vco_fra < pll_ref)) {
635 vco_fra = pll_ref * 127 / 128;
636 } else if ((vco_fra > pll_ref) && (vco_fra < pll_ref * 129 / 128)) {
637 vco_fra = pll_ref * 129 / 128;
638 }
639
640 if (nint > 63) {
641 tuner_info("No valid PLL values for %u kHz!\n", freq);
642 return -EINVAL;
643 }
644
645 ni = (nint - 13) / 4;
646 si = nint - 4 * ni - 13;
647
648 rc = r820t_write_reg(priv, 0x14, ni + (si << 6));
649 if (rc < 0)
650 return rc;
651
652 /* pw_sdm */
653 if (!vco_fra)
654 val = 0x08;
655 else
656 val = 0x00;
657
658 rc = r820t_write_reg_mask(priv, 0x12, val, 0x08);
659 if (rc < 0)
660 return rc;
661
662 /* sdm calculator */
663 while (vco_fra > 1) {
664 if (vco_fra > (2 * pll_ref / n_sdm)) {
665 sdm = sdm + 32768 / (n_sdm / 2);
666 vco_fra = vco_fra - 2 * pll_ref / n_sdm;
667 if (n_sdm >= 0x8000)
668 break;
669 }
670 n_sdm = n_sdm << 1;
671 }
672
673 tuner_dbg("freq %d kHz, pll ref %d%s, sdm=0x%04x\n",
674 freq, pll_ref, refdiv2 ? " / 2" : "", sdm);
675
676 rc = r820t_write_reg(priv, 0x16, sdm >> 8);
677 if (rc < 0)
678 return rc;
679 rc = r820t_write_reg(priv, 0x15, sdm & 0xff);
680 if (rc < 0)
681 return rc;
682
683 for (i = 0; i < 2; i++) {
684 usleep_range(sleep_time, sleep_time + 1000);
685
686 /* Check if PLL has locked */
687 rc = r820t_read(priv, 0x00, data, 3);
688 if (rc < 0)
689 return rc;
690 if (data[2] & 0x40)
691 break;
692
693 if (!i) {
694 /* Didn't lock. Increase VCO current */
695 rc = r820t_write_reg_mask(priv, 0x12, 0x60, 0xe0);
696 if (rc < 0)
697 return rc;
698 }
699 }
700
701 if (!(data[2] & 0x40)) {
702 priv->has_lock = false;
703 return 0;
704 }
705
706 priv->has_lock = true;
707 tuner_dbg("tuner has lock at frequency %d kHz\n", freq);
708
709 /* set pll autotune = 8kHz */
710 rc = r820t_write_reg_mask(priv, 0x1a, 0x08, 0x08);
711
712 return rc;
713}
714
715static int r820t_sysfreq_sel(struct r820t_priv *priv, u32 freq,
716 enum v4l2_tuner_type type,
717 v4l2_std_id std,
718 u32 delsys)
719{
720 int rc;
721 u8 mixer_top, lna_top, cp_cur, div_buf_cur, lna_vth_l, mixer_vth_l;
722 u8 air_cable1_in, cable2_in, pre_dect, lna_discharge, filter_cur;
723
724 tuner_dbg("adjusting tuner parameters for the standard\n");
725
726 switch (delsys) {
727 case SYS_DVBT:
728 if ((freq == 506000000) || (freq == 666000000) ||
729 (freq == 818000000)) {
730 mixer_top = 0x14; /* mixer top:14 , top-1, low-discharge */
731 lna_top = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
732 cp_cur = 0x28; /* 101, 0.2 */
733 div_buf_cur = 0x20; /* 10, 200u */
734 } else {
735 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */
736 lna_top = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
737 cp_cur = 0x38; /* 111, auto */
738 div_buf_cur = 0x30; /* 11, 150u */
739 }
740 lna_vth_l = 0x53; /* lna vth 0.84 , vtl 0.64 */
741 mixer_vth_l = 0x75; /* mixer vth 1.04, vtl 0.84 */
742 air_cable1_in = 0x00;
743 cable2_in = 0x00;
744 pre_dect = 0x40;
745 lna_discharge = 14;
746 filter_cur = 0x40; /* 10, low */
747 break;
748 case SYS_DVBT2:
749 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */
750 lna_top = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
751 lna_vth_l = 0x53; /* lna vth 0.84 , vtl 0.64 */
752 mixer_vth_l = 0x75; /* mixer vth 1.04, vtl 0.84 */
753 air_cable1_in = 0x00;
754 cable2_in = 0x00;
755 pre_dect = 0x40;
756 lna_discharge = 14;
757 cp_cur = 0x38; /* 111, auto */
758 div_buf_cur = 0x30; /* 11, 150u */
759 filter_cur = 0x40; /* 10, low */
760 break;
761 case SYS_ISDBT:
762 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */
763 lna_top = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
764 lna_vth_l = 0x75; /* lna vth 1.04 , vtl 0.84 */
765 mixer_vth_l = 0x75; /* mixer vth 1.04, vtl 0.84 */
766 air_cable1_in = 0x00;
767 cable2_in = 0x00;
768 pre_dect = 0x40;
769 lna_discharge = 14;
770 cp_cur = 0x38; /* 111, auto */
771 div_buf_cur = 0x30; /* 11, 150u */
772 filter_cur = 0x40; /* 10, low */
773 break;
774 default: /* DVB-T 8M */
775 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */
776 lna_top = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
777 lna_vth_l = 0x53; /* lna vth 0.84 , vtl 0.64 */
778 mixer_vth_l = 0x75; /* mixer vth 1.04, vtl 0.84 */
779 air_cable1_in = 0x00;
780 cable2_in = 0x00;
781 pre_dect = 0x40;
782 lna_discharge = 14;
783 cp_cur = 0x38; /* 111, auto */
784 div_buf_cur = 0x30; /* 11, 150u */
785 filter_cur = 0x40; /* 10, low */
786 break;
787 }
788
789 if (priv->cfg->use_diplexer &&
790 ((priv->cfg->rafael_chip == CHIP_R820T) ||
791 (priv->cfg->rafael_chip == CHIP_R828S) ||
792 (priv->cfg->rafael_chip == CHIP_R820C))) {
793 if (freq > DIP_FREQ)
794 air_cable1_in = 0x00;
795 else
796 air_cable1_in = 0x60;
797 cable2_in = 0x00;
798 }
799
800
801 if (priv->cfg->use_predetect) {
802 rc = r820t_write_reg_mask(priv, 0x06, pre_dect, 0x40);
803 if (rc < 0)
804 return rc;
805 }
806
807 rc = r820t_write_reg_mask(priv, 0x1d, lna_top, 0xc7);
808 if (rc < 0)
809 return rc;
810 rc = r820t_write_reg_mask(priv, 0x1c, mixer_top, 0xf8);
811 if (rc < 0)
812 return rc;
813 rc = r820t_write_reg(priv, 0x0d, lna_vth_l);
814 if (rc < 0)
815 return rc;
816 rc = r820t_write_reg(priv, 0x0e, mixer_vth_l);
817 if (rc < 0)
818 return rc;
819
820 /* Air-IN only for Astrometa */
821 rc = r820t_write_reg_mask(priv, 0x05, air_cable1_in, 0x60);
822 if (rc < 0)
823 return rc;
824 rc = r820t_write_reg_mask(priv, 0x06, cable2_in, 0x08);
825 if (rc < 0)
826 return rc;
827
828 rc = r820t_write_reg_mask(priv, 0x11, cp_cur, 0x38);
829 if (rc < 0)
830 return rc;
831 rc = r820t_write_reg_mask(priv, 0x17, div_buf_cur, 0x30);
832 if (rc < 0)
833 return rc;
834 rc = r820t_write_reg_mask(priv, 0x0a, filter_cur, 0x60);
835 if (rc < 0)
836 return rc;
837 /*
838 * Original driver initializes regs 0x05 and 0x06 with the
839 * same value again on this point. Probably, it is just an
840 * error there
841 */
842
843 /*
844 * Set LNA
845 */
846
847 tuner_dbg("adjusting LNA parameters\n");
848 if (type != V4L2_TUNER_ANALOG_TV) {
849 /* LNA TOP: lowest */
850 rc = r820t_write_reg_mask(priv, 0x1d, 0, 0x38);
851 if (rc < 0)
852 return rc;
853
854 /* 0: normal mode */
855 rc = r820t_write_reg_mask(priv, 0x1c, 0, 0x04);
856 if (rc < 0)
857 return rc;
858
859 /* 0: PRE_DECT off */
860 rc = r820t_write_reg_mask(priv, 0x06, 0, 0x40);
861 if (rc < 0)
862 return rc;
863
864 /* agc clk 250hz */
865 rc = r820t_write_reg_mask(priv, 0x1a, 0x30, 0x30);
866 if (rc < 0)
867 return rc;
868
869 msleep(250);
870
871 /* write LNA TOP = 3 */
872 rc = r820t_write_reg_mask(priv, 0x1d, 0x18, 0x38);
873 if (rc < 0)
874 return rc;
875
876 /*
877 * write discharge mode
878 * FIXME: IMHO, the mask here is wrong, but it matches
879 * what's there at the original driver
880 */
881 rc = r820t_write_reg_mask(priv, 0x1c, mixer_top, 0x04);
882 if (rc < 0)
883 return rc;
884
885 /* LNA discharge current */
886 rc = r820t_write_reg_mask(priv, 0x1e, lna_discharge, 0x1f);
887 if (rc < 0)
888 return rc;
889
890 /* agc clk 60hz */
891 rc = r820t_write_reg_mask(priv, 0x1a, 0x20, 0x30);
892 if (rc < 0)
893 return rc;
894 } else {
895 /* PRE_DECT off */
896 rc = r820t_write_reg_mask(priv, 0x06, 0, 0x40);
897 if (rc < 0)
898 return rc;
899
900 /* write LNA TOP */
901 rc = r820t_write_reg_mask(priv, 0x1d, lna_top, 0x38);
902 if (rc < 0)
903 return rc;
904
905 /*
906 * write discharge mode
907 * FIXME: IMHO, the mask here is wrong, but it matches
908 * what's there at the original driver
909 */
910 rc = r820t_write_reg_mask(priv, 0x1c, mixer_top, 0x04);
911 if (rc < 0)
912 return rc;
913
914 /* LNA discharge current */
915 rc = r820t_write_reg_mask(priv, 0x1e, lna_discharge, 0x1f);
916 if (rc < 0)
917 return rc;
918
919 /* agc clk 1Khz, external det1 cap 1u */
920 rc = r820t_write_reg_mask(priv, 0x1a, 0x00, 0x30);
921 if (rc < 0)
922 return rc;
923
924 rc = r820t_write_reg_mask(priv, 0x10, 0x00, 0x04);
925 if (rc < 0)
926 return rc;
927 }
928 return 0;
929}
930
931static int r820t_set_tv_standard(struct r820t_priv *priv,
932 unsigned bw,
933 enum v4l2_tuner_type type,
934 v4l2_std_id std, u32 delsys)
935
936{
937 int rc, i;
938 u32 if_khz, filt_cal_lo;
939 u8 data[5], val;
940 u8 filt_gain, img_r, filt_q, hp_cor, ext_enable, loop_through;
941 u8 lt_att, flt_ext_widest, polyfil_cur;
942 bool need_calibration;
943
944 tuner_dbg("selecting the delivery system\n");
945
946 if (delsys == SYS_ISDBT) {
947 if_khz = 4063;
948 filt_cal_lo = 59000;
949 filt_gain = 0x10; /* +3db, 6mhz on */
950 img_r = 0x00; /* image negative */
951 filt_q = 0x10; /* r10[4]:low q(1'b1) */
952 hp_cor = 0x6a; /* 1.7m disable, +2cap, 1.25mhz */
953 ext_enable = 0x40; /* r30[6], ext enable; r30[5]:0 ext at lna max */
954 loop_through = 0x00; /* r5[7], lt on */
955 lt_att = 0x00; /* r31[7], lt att enable */
956 flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
957 polyfil_cur = 0x60; /* r25[6:5]:min */
958 } else {
959 if (bw <= 6) {
960 if_khz = 3570;
961 filt_cal_lo = 56000; /* 52000->56000 */
962 filt_gain = 0x10; /* +3db, 6mhz on */
963 img_r = 0x00; /* image negative */
964 filt_q = 0x10; /* r10[4]:low q(1'b1) */
965 hp_cor = 0x6b; /* 1.7m disable, +2cap, 1.0mhz */
966 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
967 loop_through = 0x00; /* r5[7], lt on */
968 lt_att = 0x00; /* r31[7], lt att enable */
969 flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
970 polyfil_cur = 0x60; /* r25[6:5]:min */
971 } else if (bw == 7) {
972#if 0
973 /*
974 * There are two 7 MHz tables defined on the original
975 * driver, but just the second one seems to be visible
976 * by rtl2832. Keep this one here commented, as it
977 * might be needed in the future
978 */
979
980 if_khz = 4070;
981 filt_cal_lo = 60000;
982 filt_gain = 0x10; /* +3db, 6mhz on */
983 img_r = 0x00; /* image negative */
984 filt_q = 0x10; /* r10[4]:low q(1'b1) */
985 hp_cor = 0x2b; /* 1.7m disable, +1cap, 1.0mhz */
986 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
987 loop_through = 0x00; /* r5[7], lt on */
988 lt_att = 0x00; /* r31[7], lt att enable */
989 flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
990 polyfil_cur = 0x60; /* r25[6:5]:min */
991#endif
992 /* 7 MHz, second table */
993 if_khz = 4570;
994 filt_cal_lo = 63000;
995 filt_gain = 0x10; /* +3db, 6mhz on */
996 img_r = 0x00; /* image negative */
997 filt_q = 0x10; /* r10[4]:low q(1'b1) */
998 hp_cor = 0x2a; /* 1.7m disable, +1cap, 1.25mhz */
999 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
1000 loop_through = 0x00; /* r5[7], lt on */
1001 lt_att = 0x00; /* r31[7], lt att enable */
1002 flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
1003 polyfil_cur = 0x60; /* r25[6:5]:min */
1004 } else {
1005 if_khz = 4570;
1006 filt_cal_lo = 68500;
1007 filt_gain = 0x10; /* +3db, 6mhz on */
1008 img_r = 0x00; /* image negative */
1009 filt_q = 0x10; /* r10[4]:low q(1'b1) */
1010 hp_cor = 0x0b; /* 1.7m disable, +0cap, 1.0mhz */
1011 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
1012 loop_through = 0x00; /* r5[7], lt on */
1013 lt_att = 0x00; /* r31[7], lt att enable */
1014 flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
1015 polyfil_cur = 0x60; /* r25[6:5]:min */
1016 }
1017 }
1018
1019 /* Initialize the shadow registers */
1020 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array));
1021
1022 /* Init Flag & Xtal_check Result */
1023 if (priv->imr_done)
1024 val = 1 | priv->xtal_cap_sel << 1;
1025 else
1026 val = 0;
1027 rc = r820t_write_reg_mask(priv, 0x0c, val, 0x0f);
1028 if (rc < 0)
1029 return rc;
1030
1031 /* version */
1032 rc = r820t_write_reg_mask(priv, 0x13, VER_NUM, 0x3f);
1033 if (rc < 0)
1034 return rc;
1035
1036 /* for LT Gain test */
1037 if (type != V4L2_TUNER_ANALOG_TV) {
1038 rc = r820t_write_reg_mask(priv, 0x1d, 0x00, 0x38);
1039 if (rc < 0)
1040 return rc;
1041 usleep_range(1000, 2000);
1042 }
1043 priv->int_freq = if_khz * 1000;
1044
1045 /* Check if standard changed. If so, filter calibration is needed */
1046 if (type != priv->type)
1047 need_calibration = true;
1048 else if ((type == V4L2_TUNER_ANALOG_TV) && (std != priv->std))
1049 need_calibration = true;
1050 else if ((type == V4L2_TUNER_DIGITAL_TV) &&
1051 ((delsys != priv->delsys) || bw != priv->bw))
1052 need_calibration = true;
1053 else
1054 need_calibration = false;
1055
1056 if (need_calibration) {
1057 tuner_dbg("calibrating the tuner\n");
1058 for (i = 0; i < 2; i++) {
1059 /* Set filt_cap */
1060 rc = r820t_write_reg_mask(priv, 0x0b, hp_cor, 0x60);
1061 if (rc < 0)
1062 return rc;
1063
1064 /* set cali clk =on */
1065 rc = r820t_write_reg_mask(priv, 0x0f, 0x04, 0x04);
1066 if (rc < 0)
1067 return rc;
1068
1069 /* X'tal cap 0pF for PLL */
1070 rc = r820t_write_reg_mask(priv, 0x10, 0x00, 0x03);
1071 if (rc < 0)
1072 return rc;
1073
1074 rc = r820t_set_pll(priv, type, filt_cal_lo * 1000);
1075 if (rc < 0 || !priv->has_lock)
1076 return rc;
1077
1078 /* Start Trigger */
1079 rc = r820t_write_reg_mask(priv, 0x0b, 0x10, 0x10);
1080 if (rc < 0)
1081 return rc;
1082
1083 usleep_range(1000, 2000);
1084
1085 /* Stop Trigger */
1086 rc = r820t_write_reg_mask(priv, 0x0b, 0x00, 0x10);
1087 if (rc < 0)
1088 return rc;
1089
1090 /* set cali clk =off */
1091 rc = r820t_write_reg_mask(priv, 0x0f, 0x00, 0x04);
1092 if (rc < 0)
1093 return rc;
1094
1095 /* Check if calibration worked */
1096 rc = r820t_read(priv, 0x00, data, sizeof(data));
1097 if (rc < 0)
1098 return rc;
1099
1100 priv->fil_cal_code = data[4] & 0x0f;
1101 if (priv->fil_cal_code && priv->fil_cal_code != 0x0f)
1102 break;
1103 }
1104 /* narrowest */
1105 if (priv->fil_cal_code == 0x0f)
1106 priv->fil_cal_code = 0;
1107 }
1108
1109 rc = r820t_write_reg_mask(priv, 0x0a,
1110 filt_q | priv->fil_cal_code, 0x1f);
1111 if (rc < 0)
1112 return rc;
1113
1114 /* Set BW, Filter_gain, & HP corner */
1115 rc = r820t_write_reg_mask(priv, 0x0b, hp_cor, 0xef);
1116 if (rc < 0)
1117 return rc;
1118
1119
1120 /* Set Img_R */
1121 rc = r820t_write_reg_mask(priv, 0x07, img_r, 0x80);
1122 if (rc < 0)
1123 return rc;
1124
1125 /* Set filt_3dB, V6MHz */
1126 rc = r820t_write_reg_mask(priv, 0x06, filt_gain, 0x30);
1127 if (rc < 0)
1128 return rc;
1129
1130 /* channel filter extension */
1131 rc = r820t_write_reg_mask(priv, 0x1e, ext_enable, 0x60);
1132 if (rc < 0)
1133 return rc;
1134
1135 /* Loop through */
1136 rc = r820t_write_reg_mask(priv, 0x05, loop_through, 0x80);
1137 if (rc < 0)
1138 return rc;
1139
1140 /* Loop through attenuation */
1141 rc = r820t_write_reg_mask(priv, 0x1f, lt_att, 0x80);
1142 if (rc < 0)
1143 return rc;
1144
1145 /* filter extension widest */
1146 rc = r820t_write_reg_mask(priv, 0x0f, flt_ext_widest, 0x80);
1147 if (rc < 0)
1148 return rc;
1149
1150 /* RF poly filter current */
1151 rc = r820t_write_reg_mask(priv, 0x19, polyfil_cur, 0x60);
1152 if (rc < 0)
1153 return rc;
1154
1155 /* Store current standard. If it changes, re-calibrate the tuner */
1156 priv->delsys = delsys;
1157 priv->type = type;
1158 priv->std = std;
1159 priv->bw = bw;
1160
1161 return 0;
1162}
1163
1164static int r820t_read_gain(struct r820t_priv *priv)
1165{
1166 u8 data[4];
1167 int rc;
1168
1169 rc = r820t_read(priv, 0x00, data, sizeof(data));
1170 if (rc < 0)
1171 return rc;
1172
1173 return ((data[3] & 0x0f) << 1) + ((data[3] & 0xf0) >> 4);
1174}
1175
1176#if 0
1177/* FIXME: This routine requires more testing */
1178static int r820t_set_gain_mode(struct r820t_priv *priv,
1179 bool set_manual_gain,
1180 int gain)
1181{
1182 int rc;
1183
1184 if (set_manual_gain) {
1185 int i, total_gain = 0;
1186 uint8_t mix_index = 0, lna_index = 0;
1187 u8 data[4];
1188
1189 /* LNA auto off */
1190 rc = r820t_write_reg_mask(priv, 0x05, 0x10, 0x10);
1191 if (rc < 0)
1192 return rc;
1193
1194 /* Mixer auto off */
1195 rc = r820t_write_reg_mask(priv, 0x07, 0, 0x10);
1196 if (rc < 0)
1197 return rc;
1198
1199 rc = r820t_read(priv, 0x00, data, sizeof(data));
1200 if (rc < 0)
1201 return rc;
1202
1203 /* set fixed VGA gain for now (16.3 dB) */
1204 rc = r820t_write_reg_mask(priv, 0x0c, 0x08, 0x9f);
1205 if (rc < 0)
1206 return rc;
1207
1208 for (i = 0; i < 15; i++) {
1209 if (total_gain >= gain)
1210 break;
1211
1212 total_gain += r820t_lna_gain_steps[++lna_index];
1213
1214 if (total_gain >= gain)
1215 break;
1216
1217 total_gain += r820t_mixer_gain_steps[++mix_index];
1218 }
1219
1220 /* set LNA gain */
1221 rc = r820t_write_reg_mask(priv, 0x05, lna_index, 0x0f);
1222 if (rc < 0)
1223 return rc;
1224
1225 /* set Mixer gain */
1226 rc = r820t_write_reg_mask(priv, 0x07, mix_index, 0x0f);
1227 if (rc < 0)
1228 return rc;
1229 } else {
1230 /* LNA */
1231 rc = r820t_write_reg_mask(priv, 0x05, 0, 0x10);
1232 if (rc < 0)
1233 return rc;
1234
1235 /* Mixer */
1236 rc = r820t_write_reg_mask(priv, 0x07, 0x10, 0x10);
1237 if (rc < 0)
1238 return rc;
1239
1240 /* set fixed VGA gain for now (26.5 dB) */
1241 rc = r820t_write_reg_mask(priv, 0x0c, 0x0b, 0x9f);
1242 if (rc < 0)
1243 return rc;
1244 }
1245
1246 return 0;
1247}
1248#endif
1249
1250static int generic_set_freq(struct dvb_frontend *fe,
1251 u32 freq /* in HZ */,
1252 unsigned bw,
1253 enum v4l2_tuner_type type,
1254 v4l2_std_id std, u32 delsys)
1255{
1256 struct r820t_priv *priv = fe->tuner_priv;
1257 int rc = -EINVAL;
1258 u32 lo_freq;
1259
1260 tuner_dbg("should set frequency to %d kHz, bw %d MHz\n",
1261 freq / 1000, bw);
1262
1263 rc = r820t_set_tv_standard(priv, bw, type, std, delsys);
1264 if (rc < 0)
1265 goto err;
1266
1267 if ((type == V4L2_TUNER_ANALOG_TV) && (std == V4L2_STD_SECAM_LC))
1268 lo_freq = freq - priv->int_freq;
1269 else
1270 lo_freq = freq + priv->int_freq;
1271
1272 rc = r820t_set_mux(priv, lo_freq);
1273 if (rc < 0)
1274 goto err;
1275
1276 rc = r820t_set_pll(priv, type, lo_freq);
1277 if (rc < 0 || !priv->has_lock)
1278 goto err;
1279
1280 rc = r820t_sysfreq_sel(priv, freq, type, std, delsys);
1281 if (rc < 0)
1282 goto err;
1283
1284 tuner_dbg("%s: PLL locked on frequency %d Hz, gain=%d\n",
1285 __func__, freq, r820t_read_gain(priv));
1286
1287err:
1288
1289 if (rc < 0)
1290 tuner_dbg("%s: failed=%d\n", __func__, rc);
1291 return rc;
1292}
1293
1294/*
1295 * r820t standby logic
1296 */
1297
1298static int r820t_standby(struct r820t_priv *priv)
1299{
1300 int rc;
1301
1302 /* If device was not initialized yet, don't need to standby */
1303 if (!priv->init_done)
1304 return 0;
1305
1306 rc = r820t_write_reg(priv, 0x06, 0xb1);
1307 if (rc < 0)
1308 return rc;
1309 rc = r820t_write_reg(priv, 0x05, 0x03);
1310 if (rc < 0)
1311 return rc;
1312 rc = r820t_write_reg(priv, 0x07, 0x3a);
1313 if (rc < 0)
1314 return rc;
1315 rc = r820t_write_reg(priv, 0x08, 0x40);
1316 if (rc < 0)
1317 return rc;
1318 rc = r820t_write_reg(priv, 0x09, 0xc0);
1319 if (rc < 0)
1320 return rc;
1321 rc = r820t_write_reg(priv, 0x0a, 0x36);
1322 if (rc < 0)
1323 return rc;
1324 rc = r820t_write_reg(priv, 0x0c, 0x35);
1325 if (rc < 0)
1326 return rc;
1327 rc = r820t_write_reg(priv, 0x0f, 0x68);
1328 if (rc < 0)
1329 return rc;
1330 rc = r820t_write_reg(priv, 0x11, 0x03);
1331 if (rc < 0)
1332 return rc;
1333 rc = r820t_write_reg(priv, 0x17, 0xf4);
1334 if (rc < 0)
1335 return rc;
1336 rc = r820t_write_reg(priv, 0x19, 0x0c);
1337
1338 /* Force initial calibration */
1339 priv->type = -1;
1340
1341 return rc;
1342}
1343
1344/*
1345 * r820t device init logic
1346 */
1347
1348static int r820t_xtal_check(struct r820t_priv *priv)
1349{
1350 int rc, i;
1351 u8 data[3], val;
1352
1353 /* Initialize the shadow registers */
1354 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array));
1355
1356 /* cap 30pF & Drive Low */
1357 rc = r820t_write_reg_mask(priv, 0x10, 0x0b, 0x0b);
1358 if (rc < 0)
1359 return rc;
1360
1361 /* set pll autotune = 128kHz */
1362 rc = r820t_write_reg_mask(priv, 0x1a, 0x00, 0x0c);
1363 if (rc < 0)
1364 return rc;
1365
1366 /* set manual initial reg = 111111; */
1367 rc = r820t_write_reg_mask(priv, 0x13, 0x7f, 0x7f);
1368 if (rc < 0)
1369 return rc;
1370
1371 /* set auto */
1372 rc = r820t_write_reg_mask(priv, 0x13, 0x00, 0x40);
1373 if (rc < 0)
1374 return rc;
1375
1376 /* Try several xtal capacitor alternatives */
1377 for (i = 0; i < ARRAY_SIZE(r820t_xtal_capacitor); i++) {
1378 rc = r820t_write_reg_mask(priv, 0x10,
1379 r820t_xtal_capacitor[i][0], 0x1b);
1380 if (rc < 0)
1381 return rc;
1382
1383 usleep_range(5000, 6000);
1384
1385 rc = r820t_read(priv, 0x00, data, sizeof(data));
1386 if (rc < 0)
1387 return rc;
1388 if (!(data[2] & 0x40))
1389 continue;
1390
1391 val = data[2] & 0x3f;
1392
1393 if (priv->cfg->xtal == 16000000 && (val > 29 || val < 23))
1394 break;
1395
1396 if (val != 0x3f)
1397 break;
1398 }
1399
1400 if (i == ARRAY_SIZE(r820t_xtal_capacitor))
1401 return -EINVAL;
1402
1403 return r820t_xtal_capacitor[i][1];
1404}
1405
1406static int r820t_imr_prepare(struct r820t_priv *priv)
1407{
1408 int rc;
1409
1410 /* Initialize the shadow registers */
1411 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array));
1412
1413 /* lna off (air-in off) */
1414 rc = r820t_write_reg_mask(priv, 0x05, 0x20, 0x20);
1415 if (rc < 0)
1416 return rc;
1417
1418 /* mixer gain mode = manual */
1419 rc = r820t_write_reg_mask(priv, 0x07, 0, 0x10);
1420 if (rc < 0)
1421 return rc;
1422
1423 /* filter corner = lowest */
1424 rc = r820t_write_reg_mask(priv, 0x0a, 0x0f, 0x0f);
1425 if (rc < 0)
1426 return rc;
1427
1428 /* filter bw=+2cap, hp=5M */
1429 rc = r820t_write_reg_mask(priv, 0x0b, 0x60, 0x6f);
1430 if (rc < 0)
1431 return rc;
1432
1433 /* adc=on, vga code mode, gain = 26.5dB */
1434 rc = r820t_write_reg_mask(priv, 0x0c, 0x0b, 0x9f);
1435 if (rc < 0)
1436 return rc;
1437
1438 /* ring clk = on */
1439 rc = r820t_write_reg_mask(priv, 0x0f, 0, 0x08);
1440 if (rc < 0)
1441 return rc;
1442
1443 /* ring power = on */
1444 rc = r820t_write_reg_mask(priv, 0x18, 0x10, 0x10);
1445 if (rc < 0)
1446 return rc;
1447
1448 /* from ring = ring pll in */
1449 rc = r820t_write_reg_mask(priv, 0x1c, 0x02, 0x02);
1450 if (rc < 0)
1451 return rc;
1452
1453 /* sw_pdect = det3 */
1454 rc = r820t_write_reg_mask(priv, 0x1e, 0x80, 0x80);
1455 if (rc < 0)
1456 return rc;
1457
1458 /* Set filt_3dB */
1459 rc = r820t_write_reg_mask(priv, 0x06, 0x20, 0x20);
1460
1461 return rc;
1462}
1463
1464static int r820t_multi_read(struct r820t_priv *priv)
1465{
1466 int rc, i;
1467 u8 data[2], min = 0, max = 255, sum = 0;
1468
1469 usleep_range(5000, 6000);
1470
1471 for (i = 0; i < 6; i++) {
1472 rc = r820t_read(priv, 0x00, data, sizeof(data));
1473 if (rc < 0)
1474 return rc;
1475
1476 sum += data[1];
1477
1478 if (data[1] < min)
1479 min = data[1];
1480
1481 if (data[1] > max)
1482 max = data[1];
1483 }
1484 rc = sum - max - min;
1485
1486 return rc;
1487}
1488
1489static int r820t_imr_cross(struct r820t_priv *priv,
1490 struct r820t_sect_type iq_point[3],
1491 u8 *x_direct)
1492{
1493 struct r820t_sect_type cross[5]; /* (0,0)(0,Q-1)(0,I-1)(Q-1,0)(I-1,0) */
1494 struct r820t_sect_type tmp;
1495 int i, rc;
1496 u8 reg08, reg09;
1497
1498 reg08 = r820t_read_cache_reg(priv, 8) & 0xc0;
1499 reg09 = r820t_read_cache_reg(priv, 9) & 0xc0;
1500
1501 tmp.gain_x = 0;
1502 tmp.phase_y = 0;
1503 tmp.value = 255;
1504
1505 for (i = 0; i < 5; i++) {
1506 switch (i) {
1507 case 0:
1508 cross[i].gain_x = reg08;
1509 cross[i].phase_y = reg09;
1510 break;
1511 case 1:
1512 cross[i].gain_x = reg08; /* 0 */
1513 cross[i].phase_y = reg09 + 1; /* Q-1 */
1514 break;
1515 case 2:
1516 cross[i].gain_x = reg08; /* 0 */
1517 cross[i].phase_y = (reg09 | 0x20) + 1; /* I-1 */
1518 break;
1519 case 3:
1520 cross[i].gain_x = reg08 + 1; /* Q-1 */
1521 cross[i].phase_y = reg09;
1522 break;
1523 default:
1524 cross[i].gain_x = (reg08 | 0x20) + 1; /* I-1 */
1525 cross[i].phase_y = reg09;
1526 }
1527
1528 rc = r820t_write_reg(priv, 0x08, cross[i].gain_x);
1529 if (rc < 0)
1530 return rc;
1531
1532 rc = r820t_write_reg(priv, 0x09, cross[i].phase_y);
1533 if (rc < 0)
1534 return rc;
1535
1536 rc = r820t_multi_read(priv);
1537 if (rc < 0)
1538 return rc;
1539
1540 cross[i].value = rc;
1541
1542 if (cross[i].value < tmp.value)
1543 memcpy(&tmp, &cross[i], sizeof(tmp));
1544 }
1545
1546 if ((tmp.phase_y & 0x1f) == 1) { /* y-direction */
1547 *x_direct = 0;
1548
1549 iq_point[0] = cross[0];
1550 iq_point[1] = cross[1];
1551 iq_point[2] = cross[2];
1552 } else { /* (0,0) or x-direction */
1553 *x_direct = 1;
1554
1555 iq_point[0] = cross[0];
1556 iq_point[1] = cross[3];
1557 iq_point[2] = cross[4];
1558 }
1559 return 0;
1560}
1561
1562static void r820t_compre_cor(struct r820t_sect_type iq[3])
1563{
1564 int i;
1565
1566 for (i = 3; i > 0; i--) {
1567 if (iq[0].value > iq[i - 1].value)
1568 swap(iq[0], iq[i - 1]);
1569 }
1570}
1571
1572static int r820t_compre_step(struct r820t_priv *priv,
1573 struct r820t_sect_type iq[3], u8 reg)
1574{
1575 int rc;
1576 struct r820t_sect_type tmp;
1577
1578 /*
1579 * Purpose: if (Gain<9 or Phase<9), Gain+1 or Phase+1 and compare
1580 * with min value:
1581 * new < min => update to min and continue
1582 * new > min => Exit
1583 */
1584
1585 /* min value already saved in iq[0] */
1586 tmp.phase_y = iq[0].phase_y;
1587 tmp.gain_x = iq[0].gain_x;
1588
1589 while (((tmp.gain_x & 0x1f) < IMR_TRIAL) &&
1590 ((tmp.phase_y & 0x1f) < IMR_TRIAL)) {
1591 if (reg == 0x08)
1592 tmp.gain_x++;
1593 else
1594 tmp.phase_y++;
1595
1596 rc = r820t_write_reg(priv, 0x08, tmp.gain_x);
1597 if (rc < 0)
1598 return rc;
1599
1600 rc = r820t_write_reg(priv, 0x09, tmp.phase_y);
1601 if (rc < 0)
1602 return rc;
1603
1604 rc = r820t_multi_read(priv);
1605 if (rc < 0)
1606 return rc;
1607 tmp.value = rc;
1608
1609 if (tmp.value <= iq[0].value) {
1610 iq[0].gain_x = tmp.gain_x;
1611 iq[0].phase_y = tmp.phase_y;
1612 iq[0].value = tmp.value;
1613 } else {
1614 return 0;
1615 }
1616
1617 }
1618
1619 return 0;
1620}
1621
1622static int r820t_iq_tree(struct r820t_priv *priv,
1623 struct r820t_sect_type iq[3],
1624 u8 fix_val, u8 var_val, u8 fix_reg)
1625{
1626 int rc, i;
1627 u8 tmp, var_reg;
1628
1629 /*
1630 * record IMC results by input gain/phase location then adjust
1631 * gain or phase positive 1 step and negtive 1 step,
1632 * both record results
1633 */
1634
1635 if (fix_reg == 0x08)
1636 var_reg = 0x09;
1637 else
1638 var_reg = 0x08;
1639
1640 for (i = 0; i < 3; i++) {
1641 rc = r820t_write_reg(priv, fix_reg, fix_val);
1642 if (rc < 0)
1643 return rc;
1644
1645 rc = r820t_write_reg(priv, var_reg, var_val);
1646 if (rc < 0)
1647 return rc;
1648
1649 rc = r820t_multi_read(priv);
1650 if (rc < 0)
1651 return rc;
1652 iq[i].value = rc;
1653
1654 if (fix_reg == 0x08) {
1655 iq[i].gain_x = fix_val;
1656 iq[i].phase_y = var_val;
1657 } else {
1658 iq[i].phase_y = fix_val;
1659 iq[i].gain_x = var_val;
1660 }
1661
1662 if (i == 0) { /* try right-side point */
1663 var_val++;
1664 } else if (i == 1) { /* try left-side point */
1665 /* if absolute location is 1, change I/Q direction */
1666 if ((var_val & 0x1f) < 0x02) {
1667 tmp = 2 - (var_val & 0x1f);
1668
1669 /* b[5]:I/Q selection. 0:Q-path, 1:I-path */
1670 if (var_val & 0x20) {
1671 var_val &= 0xc0;
1672 var_val |= tmp;
1673 } else {
1674 var_val |= 0x20 | tmp;
1675 }
1676 } else {
1677 var_val -= 2;
1678 }
1679 }
1680 }
1681
1682 return 0;
1683}
1684
1685static int r820t_section(struct r820t_priv *priv,
1686 struct r820t_sect_type *iq_point)
1687{
1688 int rc;
1689 struct r820t_sect_type compare_iq[3], compare_bet[3];
1690
1691 /* Try X-1 column and save min result to compare_bet[0] */
1692 if (!(iq_point->gain_x & 0x1f))
1693 compare_iq[0].gain_x = ((iq_point->gain_x) & 0xdf) + 1; /* Q-path, Gain=1 */
1694 else
1695 compare_iq[0].gain_x = iq_point->gain_x - 1; /* left point */
1696 compare_iq[0].phase_y = iq_point->phase_y;
1697
1698 /* y-direction */
1699 rc = r820t_iq_tree(priv, compare_iq, compare_iq[0].gain_x,
1700 compare_iq[0].phase_y, 0x08);
1701 if (rc < 0)
1702 return rc;
1703
1704 r820t_compre_cor(compare_iq);
1705
1706 compare_bet[0] = compare_iq[0];
1707
1708 /* Try X column and save min result to compare_bet[1] */
1709 compare_iq[0].gain_x = iq_point->gain_x;
1710 compare_iq[0].phase_y = iq_point->phase_y;
1711
1712 rc = r820t_iq_tree(priv, compare_iq, compare_iq[0].gain_x,
1713 compare_iq[0].phase_y, 0x08);
1714 if (rc < 0)
1715 return rc;
1716
1717 r820t_compre_cor(compare_iq);
1718
1719 compare_bet[1] = compare_iq[0];
1720
1721 /* Try X+1 column and save min result to compare_bet[2] */
1722 if ((iq_point->gain_x & 0x1f) == 0x00)
1723 compare_iq[0].gain_x = ((iq_point->gain_x) | 0x20) + 1; /* I-path, Gain=1 */
1724 else
1725 compare_iq[0].gain_x = iq_point->gain_x + 1;
1726 compare_iq[0].phase_y = iq_point->phase_y;
1727
1728 rc = r820t_iq_tree(priv, compare_iq, compare_iq[0].gain_x,
1729 compare_iq[0].phase_y, 0x08);
1730 if (rc < 0)
1731 return rc;
1732
1733 r820t_compre_cor(compare_iq);
1734
1735 compare_bet[2] = compare_iq[0];
1736
1737 r820t_compre_cor(compare_bet);
1738
1739 *iq_point = compare_bet[0];
1740
1741 return 0;
1742}
1743
1744static int r820t_vga_adjust(struct r820t_priv *priv)
1745{
1746 int rc;
1747 u8 vga_count;
1748
1749 /* increase vga power to let image significant */
1750 for (vga_count = 12; vga_count < 16; vga_count++) {
1751 rc = r820t_write_reg_mask(priv, 0x0c, vga_count, 0x0f);
1752 if (rc < 0)
1753 return rc;
1754
1755 usleep_range(10000, 11000);
1756
1757 rc = r820t_multi_read(priv);
1758 if (rc < 0)
1759 return rc;
1760
1761 if (rc > 40 * 4)
1762 break;
1763 }
1764
1765 return 0;
1766}
1767
1768static int r820t_iq(struct r820t_priv *priv, struct r820t_sect_type *iq_pont)
1769{
1770 struct r820t_sect_type compare_iq[3];
1771 int rc;
1772 u8 x_direction = 0; /* 1:x, 0:y */
1773 u8 dir_reg, other_reg;
1774
1775 r820t_vga_adjust(priv);
1776
1777 rc = r820t_imr_cross(priv, compare_iq, &x_direction);
1778 if (rc < 0)
1779 return rc;
1780
1781 if (x_direction == 1) {
1782 dir_reg = 0x08;
1783 other_reg = 0x09;
1784 } else {
1785 dir_reg = 0x09;
1786 other_reg = 0x08;
1787 }
1788
1789 /* compare and find min of 3 points. determine i/q direction */
1790 r820t_compre_cor(compare_iq);
1791
1792 /* increase step to find min value of this direction */
1793 rc = r820t_compre_step(priv, compare_iq, dir_reg);
1794 if (rc < 0)
1795 return rc;
1796
1797 /* the other direction */
1798 rc = r820t_iq_tree(priv, compare_iq, compare_iq[0].gain_x,
1799 compare_iq[0].phase_y, dir_reg);
1800 if (rc < 0)
1801 return rc;
1802
1803 /* compare and find min of 3 points. determine i/q direction */
1804 r820t_compre_cor(compare_iq);
1805
1806 /* increase step to find min value on this direction */
1807 rc = r820t_compre_step(priv, compare_iq, other_reg);
1808 if (rc < 0)
1809 return rc;
1810
1811 /* check 3 points again */
1812 rc = r820t_iq_tree(priv, compare_iq, compare_iq[0].gain_x,
1813 compare_iq[0].phase_y, other_reg);
1814 if (rc < 0)
1815 return rc;
1816
1817 r820t_compre_cor(compare_iq);
1818
1819 /* section-9 check */
1820 rc = r820t_section(priv, compare_iq);
1821
1822 *iq_pont = compare_iq[0];
1823
1824 /* reset gain/phase control setting */
1825 rc = r820t_write_reg_mask(priv, 0x08, 0, 0x3f);
1826 if (rc < 0)
1827 return rc;
1828
1829 rc = r820t_write_reg_mask(priv, 0x09, 0, 0x3f);
1830
1831 return rc;
1832}
1833
1834static int r820t_f_imr(struct r820t_priv *priv, struct r820t_sect_type *iq_pont)
1835{
1836 int rc;
1837
1838 r820t_vga_adjust(priv);
1839
1840 /*
1841 * search surrounding points from previous point
1842 * try (x-1), (x), (x+1) columns, and find min IMR result point
1843 */
1844 rc = r820t_section(priv, iq_pont);
1845 if (rc < 0)
1846 return rc;
1847
1848 return 0;
1849}
1850
1851static int r820t_imr(struct r820t_priv *priv, unsigned imr_mem, bool im_flag)
1852{
1853 struct r820t_sect_type imr_point;
1854 int rc;
1855 u32 ring_vco, ring_freq, ring_ref;
1856 u8 n_ring, n;
1857 int reg18, reg19, reg1f;
1858
1859 if (priv->cfg->xtal > 24000000)
1860 ring_ref = priv->cfg->xtal / 2;
1861 else
1862 ring_ref = priv->cfg->xtal;
1863
1864 n_ring = 15;
1865 for (n = 0; n < 16; n++) {
1866 if ((16 + n) * 8 * ring_ref >= 3100000) {
1867 n_ring = n;
1868 break;
1869 }
1870 }
1871
1872 reg18 = r820t_read_cache_reg(priv, 0x18);
1873 reg19 = r820t_read_cache_reg(priv, 0x19);
1874 reg1f = r820t_read_cache_reg(priv, 0x1f);
1875
1876 reg18 &= 0xf0; /* set ring[3:0] */
1877 reg18 |= n_ring;
1878
1879 ring_vco = (16 + n_ring) * 8 * ring_ref;
1880
1881 reg18 &= 0xdf; /* clear ring_se23 */
1882 reg19 &= 0xfc; /* clear ring_seldiv */
1883 reg1f &= 0xfc; /* clear ring_att */
1884
1885 switch (imr_mem) {
1886 case 0:
1887 ring_freq = ring_vco / 48;
1888 reg18 |= 0x20; /* ring_se23 = 1 */
1889 reg19 |= 0x03; /* ring_seldiv = 3 */
1890 reg1f |= 0x02; /* ring_att 10 */
1891 break;
1892 case 1:
1893 ring_freq = ring_vco / 16;
1894 reg18 |= 0x00; /* ring_se23 = 0 */
1895 reg19 |= 0x02; /* ring_seldiv = 2 */
1896 reg1f |= 0x00; /* pw_ring 00 */
1897 break;
1898 case 2:
1899 ring_freq = ring_vco / 8;
1900 reg18 |= 0x00; /* ring_se23 = 0 */
1901 reg19 |= 0x01; /* ring_seldiv = 1 */
1902 reg1f |= 0x03; /* pw_ring 11 */
1903 break;
1904 case 3:
1905 ring_freq = ring_vco / 6;
1906 reg18 |= 0x20; /* ring_se23 = 1 */
1907 reg19 |= 0x00; /* ring_seldiv = 0 */
1908 reg1f |= 0x03; /* pw_ring 11 */
1909 break;
1910 case 4:
1911 ring_freq = ring_vco / 4;
1912 reg18 |= 0x00; /* ring_se23 = 0 */
1913 reg19 |= 0x00; /* ring_seldiv = 0 */
1914 reg1f |= 0x01; /* pw_ring 01 */
1915 break;
1916 default:
1917 ring_freq = ring_vco / 4;
1918 reg18 |= 0x00; /* ring_se23 = 0 */
1919 reg19 |= 0x00; /* ring_seldiv = 0 */
1920 reg1f |= 0x01; /* pw_ring 01 */
1921 break;
1922 }
1923
1924
1925 /* write pw_ring, n_ring, ringdiv2 registers */
1926
1927 /* n_ring, ring_se23 */
1928 rc = r820t_write_reg(priv, 0x18, reg18);
1929 if (rc < 0)
1930 return rc;
1931
1932 /* ring_sediv */
1933 rc = r820t_write_reg(priv, 0x19, reg19);
1934 if (rc < 0)
1935 return rc;
1936
1937 /* pw_ring */
1938 rc = r820t_write_reg(priv, 0x1f, reg1f);
1939 if (rc < 0)
1940 return rc;
1941
1942 /* mux input freq ~ rf_in freq */
1943 rc = r820t_set_mux(priv, (ring_freq - 5300) * 1000);
1944 if (rc < 0)
1945 return rc;
1946
1947 rc = r820t_set_pll(priv, V4L2_TUNER_DIGITAL_TV,
1948 (ring_freq - 5300) * 1000);
1949 if (!priv->has_lock)
1950 rc = -EINVAL;
1951 if (rc < 0)
1952 return rc;
1953
1954 if (im_flag) {
1955 rc = r820t_iq(priv, &imr_point);
1956 } else {
1957 imr_point.gain_x = priv->imr_data[3].gain_x;
1958 imr_point.phase_y = priv->imr_data[3].phase_y;
1959 imr_point.value = priv->imr_data[3].value;
1960
1961 rc = r820t_f_imr(priv, &imr_point);
1962 }
1963 if (rc < 0)
1964 return rc;
1965
1966 /* save IMR value */
1967 switch (imr_mem) {
1968 case 0:
1969 priv->imr_data[0].gain_x = imr_point.gain_x;
1970 priv->imr_data[0].phase_y = imr_point.phase_y;
1971 priv->imr_data[0].value = imr_point.value;
1972 break;
1973 case 1:
1974 priv->imr_data[1].gain_x = imr_point.gain_x;
1975 priv->imr_data[1].phase_y = imr_point.phase_y;
1976 priv->imr_data[1].value = imr_point.value;
1977 break;
1978 case 2:
1979 priv->imr_data[2].gain_x = imr_point.gain_x;
1980 priv->imr_data[2].phase_y = imr_point.phase_y;
1981 priv->imr_data[2].value = imr_point.value;
1982 break;
1983 case 3:
1984 priv->imr_data[3].gain_x = imr_point.gain_x;
1985 priv->imr_data[3].phase_y = imr_point.phase_y;
1986 priv->imr_data[3].value = imr_point.value;
1987 break;
1988 case 4:
1989 priv->imr_data[4].gain_x = imr_point.gain_x;
1990 priv->imr_data[4].phase_y = imr_point.phase_y;
1991 priv->imr_data[4].value = imr_point.value;
1992 break;
1993 default:
1994 priv->imr_data[4].gain_x = imr_point.gain_x;
1995 priv->imr_data[4].phase_y = imr_point.phase_y;
1996 priv->imr_data[4].value = imr_point.value;
1997 break;
1998 }
1999
2000 return 0;
2001}
2002
2003static int r820t_imr_callibrate(struct r820t_priv *priv)
2004{
2005 int rc, i;
2006 int xtal_cap = 0;
2007
2008 if (priv->init_done)
2009 return 0;
2010
2011 /* Detect Xtal capacitance */
2012 if ((priv->cfg->rafael_chip == CHIP_R820T) ||
2013 (priv->cfg->rafael_chip == CHIP_R828S) ||
2014 (priv->cfg->rafael_chip == CHIP_R820C)) {
2015 priv->xtal_cap_sel = XTAL_HIGH_CAP_0P;
2016 } else {
2017 /* Initialize registers */
2018 rc = r820t_write(priv, 0x05,
2019 r820t_init_array, sizeof(r820t_init_array));
2020 if (rc < 0)
2021 return rc;
2022 for (i = 0; i < 3; i++) {
2023 rc = r820t_xtal_check(priv);
2024 if (rc < 0)
2025 return rc;
2026 if (!i || rc > xtal_cap)
2027 xtal_cap = rc;
2028 }
2029 priv->xtal_cap_sel = xtal_cap;
2030 }
2031
2032 /*
2033 * Disables IMR callibration. That emulates the same behaviour
2034 * as what is done by rtl-sdr userspace library. Useful for testing
2035 */
2036 if (no_imr_cal) {
2037 priv->init_done = true;
2038
2039 return 0;
2040 }
2041
2042 /* Initialize registers */
2043 rc = r820t_write(priv, 0x05,
2044 r820t_init_array, sizeof(r820t_init_array));
2045 if (rc < 0)
2046 return rc;
2047
2048 rc = r820t_imr_prepare(priv);
2049 if (rc < 0)
2050 return rc;
2051
2052 rc = r820t_imr(priv, 3, true);
2053 if (rc < 0)
2054 return rc;
2055 rc = r820t_imr(priv, 1, false);
2056 if (rc < 0)
2057 return rc;
2058 rc = r820t_imr(priv, 0, false);
2059 if (rc < 0)
2060 return rc;
2061 rc = r820t_imr(priv, 2, false);
2062 if (rc < 0)
2063 return rc;
2064 rc = r820t_imr(priv, 4, false);
2065 if (rc < 0)
2066 return rc;
2067
2068 priv->init_done = true;
2069 priv->imr_done = true;
2070
2071 return 0;
2072}
2073
2074#if 0
2075/* Not used, for now */
2076static int r820t_gpio(struct r820t_priv *priv, bool enable)
2077{
2078 return r820t_write_reg_mask(priv, 0x0f, enable ? 1 : 0, 0x01);
2079}
2080#endif
2081
2082/*
2083 * r820t frontend operations and tuner attach code
2084 *
2085 * All driver locks and i2c control are only in this part of the code
2086 */
2087
2088static int r820t_init(struct dvb_frontend *fe)
2089{
2090 struct r820t_priv *priv = fe->tuner_priv;
2091 int rc;
2092
2093 tuner_dbg("%s:\n", __func__);
2094
2095 mutex_lock(&priv->lock);
2096 if (fe->ops.i2c_gate_ctrl)
2097 fe->ops.i2c_gate_ctrl(fe, 1);
2098
2099 rc = r820t_imr_callibrate(priv);
2100 if (rc < 0)
2101 goto err;
2102
2103 /* Initialize registers */
2104 rc = r820t_write(priv, 0x05,
2105 r820t_init_array, sizeof(r820t_init_array));
2106
2107err:
2108 if (fe->ops.i2c_gate_ctrl)
2109 fe->ops.i2c_gate_ctrl(fe, 0);
2110 mutex_unlock(&priv->lock);
2111
2112 if (rc < 0)
2113 tuner_dbg("%s: failed=%d\n", __func__, rc);
2114 return rc;
2115}
2116
2117static int r820t_sleep(struct dvb_frontend *fe)
2118{
2119 struct r820t_priv *priv = fe->tuner_priv;
2120 int rc;
2121
2122 tuner_dbg("%s:\n", __func__);
2123
2124 mutex_lock(&priv->lock);
2125 if (fe->ops.i2c_gate_ctrl)
2126 fe->ops.i2c_gate_ctrl(fe, 1);
2127
2128 rc = r820t_standby(priv);
2129
2130 if (fe->ops.i2c_gate_ctrl)
2131 fe->ops.i2c_gate_ctrl(fe, 0);
2132 mutex_unlock(&priv->lock);
2133
2134 tuner_dbg("%s: failed=%d\n", __func__, rc);
2135 return rc;
2136}
2137
2138static int r820t_set_analog_freq(struct dvb_frontend *fe,
2139 struct analog_parameters *p)
2140{
2141 struct r820t_priv *priv = fe->tuner_priv;
2142 unsigned bw;
2143 int rc;
2144
2145 tuner_dbg("%s called\n", __func__);
2146
2147 /* if std is not defined, choose one */
2148 if (!p->std)
2149 p->std = V4L2_STD_MN;
2150
2151 if ((p->std == V4L2_STD_PAL_M) || (p->std == V4L2_STD_NTSC))
2152 bw = 6;
2153 else
2154 bw = 8;
2155
2156 mutex_lock(&priv->lock);
2157 if (fe->ops.i2c_gate_ctrl)
2158 fe->ops.i2c_gate_ctrl(fe, 1);
2159
2160 rc = generic_set_freq(fe, 62500l * p->frequency, bw,
2161 V4L2_TUNER_ANALOG_TV, p->std, SYS_UNDEFINED);
2162
2163 if (fe->ops.i2c_gate_ctrl)
2164 fe->ops.i2c_gate_ctrl(fe, 0);
2165 mutex_unlock(&priv->lock);
2166
2167 return rc;
2168}
2169
2170static int r820t_set_params(struct dvb_frontend *fe)
2171{
2172 struct r820t_priv *priv = fe->tuner_priv;
2173 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2174 int rc;
2175 unsigned bw;
2176
2177 tuner_dbg("%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n",
2178 __func__, c->delivery_system, c->frequency, c->bandwidth_hz);
2179
2180 mutex_lock(&priv->lock);
2181 if (fe->ops.i2c_gate_ctrl)
2182 fe->ops.i2c_gate_ctrl(fe, 1);
2183
2184 bw = (c->bandwidth_hz + 500000) / 1000000;
2185 if (!bw)
2186 bw = 8;
2187
2188 rc = generic_set_freq(fe, c->frequency, bw,
2189 V4L2_TUNER_DIGITAL_TV, 0, c->delivery_system);
2190
2191 if (fe->ops.i2c_gate_ctrl)
2192 fe->ops.i2c_gate_ctrl(fe, 0);
2193 mutex_unlock(&priv->lock);
2194
2195 if (rc)
2196 tuner_dbg("%s: failed=%d\n", __func__, rc);
2197 return rc;
2198}
2199
2200static int r820t_signal(struct dvb_frontend *fe, u16 *strength)
2201{
2202 struct r820t_priv *priv = fe->tuner_priv;
2203 int rc = 0;
2204
2205 mutex_lock(&priv->lock);
2206 if (fe->ops.i2c_gate_ctrl)
2207 fe->ops.i2c_gate_ctrl(fe, 1);
2208
2209 if (priv->has_lock) {
2210 rc = r820t_read_gain(priv);
2211 if (rc < 0)
2212 goto err;
2213
2214 /* A higher gain at LNA means a lower signal strength */
2215 *strength = (45 - rc) << 4 | 0xff;
2216 if (*strength == 0xff)
2217 *strength = 0;
2218 } else {
2219 *strength = 0;
2220 }
2221
2222err:
2223 if (fe->ops.i2c_gate_ctrl)
2224 fe->ops.i2c_gate_ctrl(fe, 0);
2225 mutex_unlock(&priv->lock);
2226
2227 tuner_dbg("%s: %s, gain=%d strength=%d\n",
2228 __func__,
2229 priv->has_lock ? "PLL locked" : "no signal",
2230 rc, *strength);
2231
2232 return 0;
2233}
2234
2235static int r820t_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
2236{
2237 struct r820t_priv *priv = fe->tuner_priv;
2238
2239 tuner_dbg("%s:\n", __func__);
2240
2241 *frequency = priv->int_freq;
2242
2243 return 0;
2244}
2245
2246static int r820t_release(struct dvb_frontend *fe)
2247{
2248 struct r820t_priv *priv = fe->tuner_priv;
2249
2250 tuner_dbg("%s:\n", __func__);
2251
2252 mutex_lock(&r820t_list_mutex);
2253
2254 if (priv)
2255 hybrid_tuner_release_state(priv);
2256
2257 mutex_unlock(&r820t_list_mutex);
2258
2259 kfree(fe->tuner_priv);
2260 fe->tuner_priv = NULL;
2261
2262 return 0;
2263}
2264
2265static const struct dvb_tuner_ops r820t_tuner_ops = {
2266 .info = {
2267 .name = "Rafael Micro R820T",
2268 .frequency_min = 42000000,
2269 .frequency_max = 1002000000,
2270 },
2271 .init = r820t_init,
2272 .release = r820t_release,
2273 .sleep = r820t_sleep,
2274 .set_params = r820t_set_params,
2275 .set_analog_params = r820t_set_analog_freq,
2276 .get_if_frequency = r820t_get_if_frequency,
2277 .get_rf_strength = r820t_signal,
2278};
2279
2280struct dvb_frontend *r820t_attach(struct dvb_frontend *fe,
2281 struct i2c_adapter *i2c,
2282 const struct r820t_config *cfg)
2283{
2284 struct r820t_priv *priv;
2285 int rc = -ENODEV;
2286 u8 data[5];
2287 int instance;
2288
2289 mutex_lock(&r820t_list_mutex);
2290
2291 instance = hybrid_tuner_request_state(struct r820t_priv, priv,
2292 hybrid_tuner_instance_list,
2293 i2c, cfg->i2c_addr,
2294 "r820t");
2295 switch (instance) {
2296 case 0:
2297 /* memory allocation failure */
2298 goto err_no_gate;
2299 break;
2300 case 1:
2301 /* new tuner instance */
2302 priv->cfg = cfg;
2303
2304 mutex_init(&priv->lock);
2305
2306 fe->tuner_priv = priv;
2307 break;
2308 case 2:
2309 /* existing tuner instance */
2310 fe->tuner_priv = priv;
2311 break;
2312 }
2313
2314 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops, sizeof(r820t_tuner_ops));
2315
2316 if (fe->ops.i2c_gate_ctrl)
2317 fe->ops.i2c_gate_ctrl(fe, 1);
2318
2319 /* check if the tuner is there */
2320 rc = r820t_read(priv, 0x00, data, sizeof(data));
2321 if (rc < 0)
2322 goto err;
2323
2324 rc = r820t_sleep(fe);
2325 if (rc < 0)
2326 goto err;
2327
2328 tuner_info("Rafael Micro r820t successfully identified\n");
2329
2330 fe->tuner_priv = priv;
2331 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops,
2332 sizeof(struct dvb_tuner_ops));
2333
2334 if (fe->ops.i2c_gate_ctrl)
2335 fe->ops.i2c_gate_ctrl(fe, 0);
2336
2337 mutex_unlock(&r820t_list_mutex);
2338
2339 return fe;
2340err:
2341 if (fe->ops.i2c_gate_ctrl)
2342 fe->ops.i2c_gate_ctrl(fe, 0);
2343
2344err_no_gate:
2345 mutex_unlock(&r820t_list_mutex);
2346
2347 tuner_info("%s: failed=%d\n", __func__, rc);
2348 r820t_release(fe);
2349 return NULL;
2350}
2351EXPORT_SYMBOL_GPL(r820t_attach);
2352
2353MODULE_DESCRIPTION("Rafael Micro r820t silicon tuner driver");
2354MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
2355MODULE_LICENSE("GPL");
diff --git a/drivers/media/tuners/r820t.h b/drivers/media/tuners/r820t.h
new file mode 100644
index 000000000000..48af3548027d
--- /dev/null
+++ b/drivers/media/tuners/r820t.h
@@ -0,0 +1,59 @@
1/*
2 * Elonics R820T silicon tuner driver
3 *
4 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
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#ifndef R820T_H
22#define R820T_H
23
24#include <linux/kconfig.h>
25#include "dvb_frontend.h"
26
27enum r820t_chip {
28 CHIP_R820T,
29 CHIP_R620D,
30 CHIP_R828D,
31 CHIP_R828,
32 CHIP_R828S,
33 CHIP_R820C,
34};
35
36struct r820t_config {
37 u8 i2c_addr; /* 0x34 */
38 u32 xtal;
39 enum r820t_chip rafael_chip;
40 unsigned max_i2c_msg_len;
41 bool use_diplexer;
42 bool use_predetect;
43};
44
45#if IS_ENABLED(CONFIG_MEDIA_TUNER_R820T)
46struct dvb_frontend *r820t_attach(struct dvb_frontend *fe,
47 struct i2c_adapter *i2c,
48 const struct r820t_config *cfg);
49#else
50static inline struct dvb_frontend *r820t_attach(struct dvb_frontend *fe,
51 struct i2c_adapter *i2c,
52 const struct r820t_config *cfg)
53{
54 pr_warn("%s: driver disabled by Kconfig\n", __func__);
55 return NULL;
56}
57#endif
58
59#endif
diff --git a/drivers/media/tuners/tda18212.h b/drivers/media/tuners/tda18212.h
index 9bd5da4aabb7..7e0d503baf05 100644
--- a/drivers/media/tuners/tda18212.h
+++ b/drivers/media/tuners/tda18212.h
@@ -21,6 +21,7 @@
21#ifndef TDA18212_H 21#ifndef TDA18212_H
22#define TDA18212_H 22#define TDA18212_H
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
26struct tda18212_config { 27struct tda18212_config {
@@ -36,8 +37,7 @@ struct tda18212_config {
36 u16 if_dvbc; 37 u16 if_dvbc;
37}; 38};
38 39
39#if defined(CONFIG_MEDIA_TUNER_TDA18212) || \ 40#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA18212)
40 (defined(CONFIG_MEDIA_TUNER_TDA18212_MODULE) && defined(MODULE))
41extern struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe, 41extern struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe,
42 struct i2c_adapter *i2c, struct tda18212_config *cfg); 42 struct i2c_adapter *i2c, struct tda18212_config *cfg);
43#else 43#else
diff --git a/drivers/media/tuners/tda18218.h b/drivers/media/tuners/tda18218.h
index b4180d180029..366410e0cc9a 100644
--- a/drivers/media/tuners/tda18218.h
+++ b/drivers/media/tuners/tda18218.h
@@ -21,6 +21,7 @@
21#ifndef TDA18218_H 21#ifndef TDA18218_H
22#define TDA18218_H 22#define TDA18218_H
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
26struct tda18218_config { 27struct tda18218_config {
@@ -29,8 +30,7 @@ struct tda18218_config {
29 u8 loop_through:1; 30 u8 loop_through:1;
30}; 31};
31 32
32#if defined(CONFIG_MEDIA_TUNER_TDA18218) || \ 33#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA18218)
33 (defined(CONFIG_MEDIA_TUNER_TDA18218_MODULE) && defined(MODULE))
34extern struct dvb_frontend *tda18218_attach(struct dvb_frontend *fe, 34extern struct dvb_frontend *tda18218_attach(struct dvb_frontend *fe,
35 struct i2c_adapter *i2c, struct tda18218_config *cfg); 35 struct i2c_adapter *i2c, struct tda18218_config *cfg);
36#else 36#else
diff --git a/drivers/media/tuners/tda18271-fe.c b/drivers/media/tuners/tda18271-fe.c
index e7786862dab2..4995b890c164 100644
--- a/drivers/media/tuners/tda18271-fe.c
+++ b/drivers/media/tuners/tda18271-fe.c
@@ -21,6 +21,7 @@
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23#include "tda18271-priv.h" 23#include "tda18271-priv.h"
24#include "tda8290.h"
24 25
25int tda18271_debug; 26int tda18271_debug;
26module_param_named(debug, tda18271_debug, int, 0644); 27module_param_named(debug, tda18271_debug, int, 0644);
@@ -867,12 +868,12 @@ static int tda18271_agc(struct dvb_frontend *fe)
867 int ret = 0; 868 int ret = 0;
868 869
869 switch (priv->config) { 870 switch (priv->config) {
870 case 0: 871 case TDA8290_LNA_OFF:
871 /* no external agc configuration required */ 872 /* no external agc configuration required */
872 if (tda18271_debug & DBG_ADV) 873 if (tda18271_debug & DBG_ADV)
873 tda_dbg("no agc configuration provided\n"); 874 tda_dbg("no agc configuration provided\n");
874 break; 875 break;
875 case 3: 876 case TDA8290_LNA_ON_BRIDGE:
876 /* switch with GPIO of saa713x */ 877 /* switch with GPIO of saa713x */
877 tda_dbg("invoking callback\n"); 878 tda_dbg("invoking callback\n");
878 if (fe->callback) 879 if (fe->callback)
@@ -881,8 +882,8 @@ static int tda18271_agc(struct dvb_frontend *fe)
881 TDA18271_CALLBACK_CMD_AGC_ENABLE, 882 TDA18271_CALLBACK_CMD_AGC_ENABLE,
882 priv->mode); 883 priv->mode);
883 break; 884 break;
884 case 1: 885 case TDA8290_LNA_GP0_HIGH_ON:
885 case 2: 886 case TDA8290_LNA_GP0_HIGH_OFF:
886 default: 887 default:
887 /* n/a - currently not supported */ 888 /* n/a - currently not supported */
888 tda_err("unsupported configuration: %d\n", priv->config); 889 tda_err("unsupported configuration: %d\n", priv->config);
diff --git a/drivers/media/tuners/tda827x.c b/drivers/media/tuners/tda827x.c
index a0d176267470..73453a255cdc 100644
--- a/drivers/media/tuners/tda827x.c
+++ b/drivers/media/tuners/tda827x.c
@@ -479,10 +479,10 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
479 dprintk("setting LNA to low gain\n"); 479 dprintk("setting LNA to low gain\n");
480 } 480 }
481 switch (priv->cfg->config) { 481 switch (priv->cfg->config) {
482 case 0: /* no LNA */ 482 case TDA8290_LNA_OFF: /* no LNA */
483 break; 483 break;
484 case 1: /* switch is GPIO 0 of tda8290 */ 484 case TDA8290_LNA_GP0_HIGH_ON: /* switch is GPIO 0 of tda8290 */
485 case 2: 485 case TDA8290_LNA_GP0_HIGH_OFF:
486 if (params == NULL) { 486 if (params == NULL) {
487 gp_func = 0; 487 gp_func = 0;
488 arg = 0; 488 arg = 0;
@@ -499,11 +499,11 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
499 DVB_FRONTEND_COMPONENT_TUNER, 499 DVB_FRONTEND_COMPONENT_TUNER,
500 gp_func, arg); 500 gp_func, arg);
501 buf[1] = high ? 0 : 1; 501 buf[1] = high ? 0 : 1;
502 if (priv->cfg->config == 2) 502 if (priv->cfg->config == TDA8290_LNA_GP0_HIGH_OFF)
503 buf[1] = high ? 1 : 0; 503 buf[1] = high ? 1 : 0;
504 tuner_transfer(fe, &msg, 1); 504 tuner_transfer(fe, &msg, 1);
505 break; 505 break;
506 case 3: /* switch with GPIO of saa713x */ 506 case TDA8290_LNA_ON_BRIDGE: /* switch with GPIO of saa713x */
507 if (fe->callback) 507 if (fe->callback)
508 fe->callback(priv->i2c_adap->algo_data, 508 fe->callback(priv->i2c_adap->algo_data,
509 DVB_FRONTEND_COMPONENT_TUNER, 0, high); 509 DVB_FRONTEND_COMPONENT_TUNER, 0, high);
diff --git a/drivers/media/tuners/tda827x.h b/drivers/media/tuners/tda827x.h
index 9432b5b6121b..b64292152baf 100644
--- a/drivers/media/tuners/tda827x.h
+++ b/drivers/media/tuners/tda827x.h
@@ -26,6 +26,7 @@
26 26
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include "dvb_frontend.h" 28#include "dvb_frontend.h"
29#include "tda8290.h"
29 30
30struct tda827x_config 31struct tda827x_config
31{ 32{
@@ -34,7 +35,7 @@ struct tda827x_config
34 int (*sleep) (struct dvb_frontend *fe); 35 int (*sleep) (struct dvb_frontend *fe);
35 36
36 /* interface to tda829x driver */ 37 /* interface to tda829x driver */
37 unsigned int config; 38 enum tda8290_lna config;
38 int switch_addr; 39 int switch_addr;
39 40
40 void (*agcf)(struct dvb_frontend *fe); 41 void (*agcf)(struct dvb_frontend *fe);
diff --git a/drivers/media/tuners/tda8290.c b/drivers/media/tuners/tda8290.c
index 8c4852114eeb..ab4106c17b4c 100644
--- a/drivers/media/tuners/tda8290.c
+++ b/drivers/media/tuners/tda8290.c
@@ -54,6 +54,7 @@ struct tda8290_priv {
54#define TDA18271 16 54#define TDA18271 16
55 55
56 struct tda827x_config cfg; 56 struct tda827x_config cfg;
57 struct tda18271_std_map *tda18271_std_map;
57}; 58};
58 59
59/*---------------------------------------------------------------------*/ 60/*---------------------------------------------------------------------*/
@@ -233,7 +234,8 @@ static void tda8290_set_params(struct dvb_frontend *fe,
233 } 234 }
234 235
235 236
236 tda8290_i2c_bridge(fe, 1); 237 if (fe->ops.analog_ops.i2c_gate_ctrl)
238 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
237 239
238 if (fe->ops.tuner_ops.set_analog_params) 240 if (fe->ops.tuner_ops.set_analog_params)
239 fe->ops.tuner_ops.set_analog_params(fe, params); 241 fe->ops.tuner_ops.set_analog_params(fe, params);
@@ -302,7 +304,8 @@ static void tda8290_set_params(struct dvb_frontend *fe,
302 } 304 }
303 } 305 }
304 306
305 tda8290_i2c_bridge(fe, 0); 307 if (fe->ops.analog_ops.i2c_gate_ctrl)
308 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
306 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2); 309 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
307} 310}
308 311
@@ -388,7 +391,7 @@ static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
388 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2); 391 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
389} 392}
390 393
391static int tda8295_has_signal(struct dvb_frontend *fe) 394static int tda8295_has_signal(struct dvb_frontend *fe, u16 *signal)
392{ 395{
393 struct tda8290_priv *priv = fe->analog_demod_priv; 396 struct tda8290_priv *priv = fe->analog_demod_priv;
394 397
@@ -396,7 +399,8 @@ static int tda8295_has_signal(struct dvb_frontend *fe)
396 unsigned char ret; 399 unsigned char ret;
397 400
398 tuner_i2c_xfer_send_recv(&priv->i2c_props, &hvpll_stat, 1, &ret, 1); 401 tuner_i2c_xfer_send_recv(&priv->i2c_props, &hvpll_stat, 1, &ret, 1);
399 return (ret & 0x01) ? 65535 : 0; 402 *signal = (ret & 0x01) ? 65535 : 0;
403 return 0;
400} 404}
401 405
402/*---------------------------------------------------------------------*/ 406/*---------------------------------------------------------------------*/
@@ -405,7 +409,7 @@ static void tda8295_set_params(struct dvb_frontend *fe,
405 struct analog_parameters *params) 409 struct analog_parameters *params)
406{ 410{
407 struct tda8290_priv *priv = fe->analog_demod_priv; 411 struct tda8290_priv *priv = fe->analog_demod_priv;
408 412 u16 signal = 0;
409 unsigned char blanking_mode[] = { 0x1d, 0x00 }; 413 unsigned char blanking_mode[] = { 0x1d, 0x00 };
410 414
411 set_audio(fe, params); 415 set_audio(fe, params);
@@ -424,7 +428,8 @@ static void tda8295_set_params(struct dvb_frontend *fe,
424 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2); 428 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
425 msleep(20); 429 msleep(20);
426 430
427 tda8295_i2c_bridge(fe, 1); 431 if (fe->ops.analog_ops.i2c_gate_ctrl)
432 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
428 433
429 if (fe->ops.tuner_ops.set_analog_params) 434 if (fe->ops.tuner_ops.set_analog_params)
430 fe->ops.tuner_ops.set_analog_params(fe, params); 435 fe->ops.tuner_ops.set_analog_params(fe, params);
@@ -432,17 +437,19 @@ static void tda8295_set_params(struct dvb_frontend *fe,
432 if (priv->cfg.agcf) 437 if (priv->cfg.agcf)
433 priv->cfg.agcf(fe); 438 priv->cfg.agcf(fe);
434 439
435 if (tda8295_has_signal(fe)) 440 tda8295_has_signal(fe, &signal);
441 if (signal)
436 tuner_dbg("tda8295 is locked\n"); 442 tuner_dbg("tda8295 is locked\n");
437 else 443 else
438 tuner_dbg("tda8295 not locked, no signal?\n"); 444 tuner_dbg("tda8295 not locked, no signal?\n");
439 445
440 tda8295_i2c_bridge(fe, 0); 446 if (fe->ops.analog_ops.i2c_gate_ctrl)
447 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
441} 448}
442 449
443/*---------------------------------------------------------------------*/ 450/*---------------------------------------------------------------------*/
444 451
445static int tda8290_has_signal(struct dvb_frontend *fe) 452static int tda8290_has_signal(struct dvb_frontend *fe, u16 *signal)
446{ 453{
447 struct tda8290_priv *priv = fe->analog_demod_priv; 454 struct tda8290_priv *priv = fe->analog_demod_priv;
448 455
@@ -451,7 +458,8 @@ static int tda8290_has_signal(struct dvb_frontend *fe)
451 458
452 tuner_i2c_xfer_send_recv(&priv->i2c_props, 459 tuner_i2c_xfer_send_recv(&priv->i2c_props,
453 i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1); 460 i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1);
454 return (afc & 0x80)? 65535:0; 461 *signal = (afc & 0x80) ? 65535 : 0;
462 return 0;
455} 463}
456 464
457/*---------------------------------------------------------------------*/ 465/*---------------------------------------------------------------------*/
@@ -465,11 +473,13 @@ static void tda8290_standby(struct dvb_frontend *fe)
465 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; 473 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
466 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 474 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
467 475
468 tda8290_i2c_bridge(fe, 1); 476 if (fe->ops.analog_ops.i2c_gate_ctrl)
477 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
469 if (priv->ver & TDA8275A) 478 if (priv->ver & TDA8275A)
470 cb1[1] = 0x90; 479 cb1[1] = 0x90;
471 i2c_transfer(priv->i2c_props.adap, &msg, 1); 480 i2c_transfer(priv->i2c_props.adap, &msg, 1);
472 tda8290_i2c_bridge(fe, 0); 481 if (fe->ops.analog_ops.i2c_gate_ctrl)
482 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
473 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2); 483 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
474 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2); 484 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
475} 485}
@@ -489,7 +499,8 @@ static void tda8290_init_if(struct dvb_frontend *fe)
489 unsigned char set_GP00_CF[] = { 0x20, 0x01 }; 499 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
490 unsigned char set_GP01_CF[] = { 0x20, 0x0B }; 500 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
491 501
492 if ((priv->cfg.config == 1) || (priv->cfg.config == 2)) 502 if ((priv->cfg.config == TDA8290_LNA_GP0_HIGH_ON) ||
503 (priv->cfg.config == TDA8290_LNA_GP0_HIGH_OFF))
493 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); 504 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
494 else 505 else
495 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); 506 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
@@ -537,9 +548,11 @@ static void tda8290_init_tuner(struct dvb_frontend *fe)
537 if (priv->ver & TDA8275A) 548 if (priv->ver & TDA8275A)
538 msg.buf = tda8275a_init; 549 msg.buf = tda8275a_init;
539 550
540 tda8290_i2c_bridge(fe, 1); 551 if (fe->ops.analog_ops.i2c_gate_ctrl)
552 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
541 i2c_transfer(priv->i2c_props.adap, &msg, 1); 553 i2c_transfer(priv->i2c_props.adap, &msg, 1);
542 tda8290_i2c_bridge(fe, 0); 554 if (fe->ops.analog_ops.i2c_gate_ctrl)
555 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
543} 556}
544 557
545/*---------------------------------------------------------------------*/ 558/*---------------------------------------------------------------------*/
@@ -565,19 +578,13 @@ static struct tda18271_config tda829x_tda18271_config = {
565static int tda829x_find_tuner(struct dvb_frontend *fe) 578static int tda829x_find_tuner(struct dvb_frontend *fe)
566{ 579{
567 struct tda8290_priv *priv = fe->analog_demod_priv; 580 struct tda8290_priv *priv = fe->analog_demod_priv;
568 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
569 int i, ret, tuners_found; 581 int i, ret, tuners_found;
570 u32 tuner_addrs; 582 u32 tuner_addrs;
571 u8 data; 583 u8 data;
572 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 }; 584 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
573 585
574 if (!analog_ops->i2c_gate_ctrl) { 586 if (fe->ops.analog_ops.i2c_gate_ctrl)
575 printk(KERN_ERR "tda8290: no gate control were provided!\n"); 587 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
576
577 return -EINVAL;
578 }
579
580 analog_ops->i2c_gate_ctrl(fe, 1);
581 588
582 /* probe for tuner chip */ 589 /* probe for tuner chip */
583 tuners_found = 0; 590 tuners_found = 0;
@@ -595,7 +602,8 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
595 give a response now 602 give a response now
596 */ 603 */
597 604
598 analog_ops->i2c_gate_ctrl(fe, 0); 605 if (fe->ops.analog_ops.i2c_gate_ctrl)
606 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
599 607
600 if (tuners_found > 1) 608 if (tuners_found > 1)
601 for (i = 0; i < tuners_found; i++) { 609 for (i = 0; i < tuners_found; i++) {
@@ -618,18 +626,21 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
618 priv->tda827x_addr = tuner_addrs; 626 priv->tda827x_addr = tuner_addrs;
619 msg.addr = tuner_addrs; 627 msg.addr = tuner_addrs;
620 628
621 analog_ops->i2c_gate_ctrl(fe, 1); 629 if (fe->ops.analog_ops.i2c_gate_ctrl)
630 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
622 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); 631 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
623 632
624 if (ret != 1) { 633 if (ret != 1) {
625 tuner_warn("tuner access failed!\n"); 634 tuner_warn("tuner access failed!\n");
626 analog_ops->i2c_gate_ctrl(fe, 0); 635 if (fe->ops.analog_ops.i2c_gate_ctrl)
636 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
627 return -EREMOTEIO; 637 return -EREMOTEIO;
628 } 638 }
629 639
630 if ((data == 0x83) || (data == 0x84)) { 640 if ((data == 0x83) || (data == 0x84)) {
631 priv->ver |= TDA18271; 641 priv->ver |= TDA18271;
632 tda829x_tda18271_config.config = priv->cfg.config; 642 tda829x_tda18271_config.config = priv->cfg.config;
643 tda829x_tda18271_config.std_map = priv->tda18271_std_map;
633 dvb_attach(tda18271_attach, fe, priv->tda827x_addr, 644 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
634 priv->i2c_props.adap, &tda829x_tda18271_config); 645 priv->i2c_props.adap, &tda829x_tda18271_config);
635 } else { 646 } else {
@@ -648,7 +659,8 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
648 if (fe->ops.tuner_ops.sleep) 659 if (fe->ops.tuner_ops.sleep)
649 fe->ops.tuner_ops.sleep(fe); 660 fe->ops.tuner_ops.sleep(fe);
650 661
651 analog_ops->i2c_gate_ctrl(fe, 0); 662 if (fe->ops.analog_ops.i2c_gate_ctrl)
663 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
652 664
653 return 0; 665 return 0;
654} 666}
@@ -740,8 +752,10 @@ struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
740 priv->i2c_props.addr = i2c_addr; 752 priv->i2c_props.addr = i2c_addr;
741 priv->i2c_props.adap = i2c_adap; 753 priv->i2c_props.adap = i2c_adap;
742 priv->i2c_props.name = "tda829x"; 754 priv->i2c_props.name = "tda829x";
743 if (cfg) 755 if (cfg) {
744 priv->cfg.config = cfg->lna_cfg; 756 priv->cfg.config = cfg->lna_cfg;
757 priv->tda18271_std_map = cfg->tda18271_std_map;
758 }
745 759
746 if (tda8290_probe(&priv->i2c_props) == 0) { 760 if (tda8290_probe(&priv->i2c_props) == 0) {
747 priv->ver = TDA8290; 761 priv->ver = TDA8290;
@@ -755,6 +769,9 @@ struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
755 sizeof(struct analog_demod_ops)); 769 sizeof(struct analog_demod_ops));
756 } 770 }
757 771
772 if (cfg && cfg->no_i2c_gate)
773 fe->ops.analog_ops.i2c_gate_ctrl = NULL;
774
758 if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) { 775 if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) {
759 tda8295_power(fe, 1); 776 tda8295_power(fe, 1);
760 if (tda829x_find_tuner(fe) < 0) 777 if (tda829x_find_tuner(fe) < 0)
diff --git a/drivers/media/tuners/tda8290.h b/drivers/media/tuners/tda8290.h
index e12ecbaa35a4..cf96e585785e 100644
--- a/drivers/media/tuners/tda8290.h
+++ b/drivers/media/tuners/tda8290.h
@@ -19,13 +19,23 @@
19 19
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22#include "tda18271.h"
23
24enum tda8290_lna {
25 TDA8290_LNA_OFF = 0,
26 TDA8290_LNA_GP0_HIGH_ON = 1,
27 TDA8290_LNA_GP0_HIGH_OFF = 2,
28 TDA8290_LNA_ON_BRIDGE = 3,
29};
22 30
23struct tda829x_config { 31struct tda829x_config {
24 unsigned int lna_cfg; 32 enum tda8290_lna lna_cfg;
25 33
26 unsigned int probe_tuner:1; 34 unsigned int probe_tuner:1;
27#define TDA829X_PROBE_TUNER 0 35#define TDA829X_PROBE_TUNER 0
28#define TDA829X_DONT_PROBE 1 36#define TDA829X_DONT_PROBE 1
37 unsigned int no_i2c_gate:1;
38 struct tda18271_std_map *tda18271_std_map;
29}; 39};
30 40
31#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA8290) 41#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA8290)
diff --git a/drivers/media/tuners/tda9887.c b/drivers/media/tuners/tda9887.c
index cdb645d57438..300005c535ba 100644
--- a/drivers/media/tuners/tda9887.c
+++ b/drivers/media/tuners/tda9887.c
@@ -596,22 +596,22 @@ static void tda9887_tuner_status(struct dvb_frontend *fe)
596 priv->data[1], priv->data[2], priv->data[3]); 596 priv->data[1], priv->data[2], priv->data[3]);
597} 597}
598 598
599static int tda9887_get_afc(struct dvb_frontend *fe) 599static int tda9887_get_afc(struct dvb_frontend *fe, s32 *afc)
600{ 600{
601 struct tda9887_priv *priv = fe->analog_demod_priv; 601 struct tda9887_priv *priv = fe->analog_demod_priv;
602 static int AFC_BITS_2_kHz[] = { 602 static const int AFC_BITS_2_kHz[] = {
603 -12500, -37500, -62500, -97500, 603 -12500, -37500, -62500, -97500,
604 -112500, -137500, -162500, -187500, 604 -112500, -137500, -162500, -187500,
605 187500, 162500, 137500, 112500, 605 187500, 162500, 137500, 112500,
606 97500 , 62500, 37500 , 12500 606 97500 , 62500, 37500 , 12500
607 }; 607 };
608 int afc=0;
609 __u8 reg = 0; 608 __u8 reg = 0;
610 609
611 if (1 == tuner_i2c_xfer_recv(&priv->i2c_props,&reg,1)) 610 if (priv->mode != V4L2_TUNER_RADIO)
612 afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; 611 return 0;
613 612 if (1 == tuner_i2c_xfer_recv(&priv->i2c_props, &reg, 1))
614 return afc; 613 *afc = AFC_BITS_2_kHz[(reg >> 1) & 0x0f];
614 return 0;
615} 615}
616 616
617static void tda9887_standby(struct dvb_frontend *fe) 617static void tda9887_standby(struct dvb_frontend *fe)
diff --git a/drivers/media/tuners/tua9001.h b/drivers/media/tuners/tua9001.h
index cf5b815feff9..26358da1c100 100644
--- a/drivers/media/tuners/tua9001.h
+++ b/drivers/media/tuners/tua9001.h
@@ -21,6 +21,7 @@
21#ifndef TUA9001_H 21#ifndef TUA9001_H
22#define TUA9001_H 22#define TUA9001_H
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25 26
26struct tua9001_config { 27struct tua9001_config {
@@ -50,8 +51,7 @@ struct tua9001_config {
50#define TUA9001_CMD_RESETN 1 51#define TUA9001_CMD_RESETN 1
51#define TUA9001_CMD_RXEN 2 52#define TUA9001_CMD_RXEN 2
52 53
53#if defined(CONFIG_MEDIA_TUNER_TUA9001) || \ 54#if IS_ENABLED(CONFIG_MEDIA_TUNER_TUA9001)
54 (defined(CONFIG_MEDIA_TUNER_TUA9001_MODULE) && defined(MODULE))
55extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, 55extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
56 struct i2c_adapter *i2c, struct tua9001_config *cfg); 56 struct i2c_adapter *i2c, struct tua9001_config *cfg);
57#else 57#else
diff --git a/drivers/media/tuners/tuner-simple.c b/drivers/media/tuners/tuner-simple.c
index 39e7e583c8c0..ca274c2d8c70 100644
--- a/drivers/media/tuners/tuner-simple.c
+++ b/drivers/media/tuners/tuner-simple.c
@@ -115,6 +115,7 @@ struct tuner_simple_priv {
115 115
116 u32 frequency; 116 u32 frequency;
117 u32 bandwidth; 117 u32 bandwidth;
118 bool radio_mode;
118}; 119};
119 120
120/* ---------------------------------------------------------------------- */ 121/* ---------------------------------------------------------------------- */
@@ -189,7 +190,7 @@ static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
189 struct tuner_simple_priv *priv = fe->tuner_priv; 190 struct tuner_simple_priv *priv = fe->tuner_priv;
190 int signal; 191 int signal;
191 192
192 if (priv->i2c_props.adap == NULL) 193 if (priv->i2c_props.adap == NULL || !priv->radio_mode)
193 return -EINVAL; 194 return -EINVAL;
194 195
195 signal = tuner_signal(tuner_read_status(fe)); 196 signal = tuner_signal(tuner_read_status(fe));
@@ -776,11 +777,13 @@ static int simple_set_params(struct dvb_frontend *fe,
776 777
777 switch (params->mode) { 778 switch (params->mode) {
778 case V4L2_TUNER_RADIO: 779 case V4L2_TUNER_RADIO:
780 priv->radio_mode = true;
779 ret = simple_set_radio_freq(fe, params); 781 ret = simple_set_radio_freq(fe, params);
780 priv->frequency = params->frequency * 125 / 2; 782 priv->frequency = params->frequency * 125 / 2;
781 break; 783 break;
782 case V4L2_TUNER_ANALOG_TV: 784 case V4L2_TUNER_ANALOG_TV:
783 case V4L2_TUNER_DIGITAL_TV: 785 case V4L2_TUNER_DIGITAL_TV:
786 priv->radio_mode = false;
784 ret = simple_set_tv_freq(fe, params); 787 ret = simple_set_tv_freq(fe, params);
785 priv->frequency = params->frequency * 62500; 788 priv->frequency = params->frequency * 62500;
786 break; 789 break;
diff --git a/drivers/media/tuners/tuner-types.c b/drivers/media/tuners/tuner-types.c
index 2da4440c16ee..98bc15a388be 100644
--- a/drivers/media/tuners/tuner-types.c
+++ b/drivers/media/tuners/tuner-types.c
@@ -1381,6 +1381,58 @@ static struct tuner_params tuner_philips_fq1236_mk5_params[] = {
1381 }, 1381 },
1382}; 1382};
1383 1383
1384/* --------- Sony BTF-PG472Z PAL/SECAM ------- */
1385
1386static struct tuner_range tuner_sony_btf_pg472z_ranges[] = {
1387 { 16 * 144.25 /*MHz*/, 0xc6, 0x01, },
1388 { 16 * 427.25 /*MHz*/, 0xc6, 0x02, },
1389 { 16 * 999.99 , 0xc6, 0x04, },
1390};
1391
1392static struct tuner_params tuner_sony_btf_pg472z_params[] = {
1393 {
1394 .type = TUNER_PARAM_TYPE_PAL,
1395 .ranges = tuner_sony_btf_pg472z_ranges,
1396 .count = ARRAY_SIZE(tuner_sony_btf_pg472z_ranges),
1397 .has_tda9887 = 1,
1398 .port1_active = 1,
1399 .port2_invert_for_secam_lc = 1,
1400 },
1401};
1402
1403/* 90-99 */
1404/* --------- Sony BTF-PG467Z NTSC-M-JP ------- */
1405
1406static struct tuner_range tuner_sony_btf_pg467z_ranges[] = {
1407 { 16 * 220.25 /*MHz*/, 0xc6, 0x01, },
1408 { 16 * 467.25 /*MHz*/, 0xc6, 0x02, },
1409 { 16 * 999.99 , 0xc6, 0x04, },
1410};
1411
1412static struct tuner_params tuner_sony_btf_pg467z_params[] = {
1413 {
1414 .type = TUNER_PARAM_TYPE_NTSC,
1415 .ranges = tuner_sony_btf_pg467z_ranges,
1416 .count = ARRAY_SIZE(tuner_sony_btf_pg467z_ranges),
1417 },
1418};
1419
1420/* --------- Sony BTF-PG463Z NTSC-M ------- */
1421
1422static struct tuner_range tuner_sony_btf_pg463z_ranges[] = {
1423 { 16 * 130.25 /*MHz*/, 0xc6, 0x01, },
1424 { 16 * 364.25 /*MHz*/, 0xc6, 0x02, },
1425 { 16 * 999.99 , 0xc6, 0x04, },
1426};
1427
1428static struct tuner_params tuner_sony_btf_pg463z_params[] = {
1429 {
1430 .type = TUNER_PARAM_TYPE_NTSC,
1431 .ranges = tuner_sony_btf_pg463z_ranges,
1432 .count = ARRAY_SIZE(tuner_sony_btf_pg463z_ranges),
1433 },
1434};
1435
1384/* --------------------------------------------------------------------- */ 1436/* --------------------------------------------------------------------- */
1385 1437
1386struct tunertype tuners[] = { 1438struct tunertype tuners[] = {
@@ -1872,6 +1924,23 @@ struct tunertype tuners[] = {
1872 .name = "Xceive 5000C tuner", 1924 .name = "Xceive 5000C tuner",
1873 /* see xc5000.c for details */ 1925 /* see xc5000.c for details */
1874 }, 1926 },
1927 [TUNER_SONY_BTF_PG472Z] = {
1928 .name = "Sony BTF-PG472Z PAL/SECAM",
1929 .params = tuner_sony_btf_pg472z_params,
1930 .count = ARRAY_SIZE(tuner_sony_btf_pg472z_params),
1931 },
1932
1933 /* 90-99 */
1934 [TUNER_SONY_BTF_PK467Z] = {
1935 .name = "Sony BTF-PK467Z NTSC-M-JP",
1936 .params = tuner_sony_btf_pg467z_params,
1937 .count = ARRAY_SIZE(tuner_sony_btf_pg467z_params),
1938 },
1939 [TUNER_SONY_BTF_PB463Z] = {
1940 .name = "Sony BTF-PB463Z NTSC-M",
1941 .params = tuner_sony_btf_pg463z_params,
1942 .count = ARRAY_SIZE(tuner_sony_btf_pg463z_params),
1943 },
1875}; 1944};
1876EXPORT_SYMBOL(tuners); 1945EXPORT_SYMBOL(tuners);
1877 1946
diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index 09451737c77e..878d2c4d9e8e 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -1378,8 +1378,7 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
1378 * For the firmware name, keep a local copy of the string, 1378 * For the firmware name, keep a local copy of the string,
1379 * in order to avoid troubles during device release. 1379 * in order to avoid troubles during device release.
1380 */ 1380 */
1381 if (priv->ctrl.fname) 1381 kfree(priv->ctrl.fname);
1382 kfree(priv->ctrl.fname);
1383 memcpy(&priv->ctrl, p, sizeof(priv->ctrl)); 1382 memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
1384 if (p->fname) { 1383 if (p->fname) {
1385 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL); 1384 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
diff --git a/drivers/media/tuners/tuner_it913x.c b/drivers/media/tuners/tuner_it913x.c
new file mode 100644
index 000000000000..6f30d7e535b8
--- /dev/null
+++ b/drivers/media/tuners/tuner_it913x.c
@@ -0,0 +1,447 @@
1/*
2 * ITE Tech IT9137 silicon tuner driver
3 *
4 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
5 * IT9137 Copyright (C) ITE Tech Inc.
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 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
21 */
22
23#include "tuner_it913x_priv.h"
24
25struct it913x_state {
26 struct i2c_adapter *i2c_adap;
27 u8 i2c_addr;
28 u8 chip_ver;
29 u8 tuner_type;
30 u8 firmware_ver;
31 u16 tun_xtal;
32 u8 tun_fdiv;
33 u8 tun_clk_mode;
34 u32 tun_fn_min;
35};
36
37/* read multiple registers */
38static int it913x_rd_regs(struct it913x_state *state,
39 u32 reg, u8 *data, u8 count)
40{
41 int ret;
42 u8 b[3];
43 struct i2c_msg msg[2] = {
44 { .addr = state->i2c_addr, .flags = 0,
45 .buf = b, .len = sizeof(b) },
46 { .addr = state->i2c_addr, .flags = I2C_M_RD,
47 .buf = data, .len = count }
48 };
49 b[0] = (u8)(reg >> 16) & 0xff;
50 b[1] = (u8)(reg >> 8) & 0xff;
51 b[2] = (u8) reg & 0xff;
52 b[0] |= 0x80; /* All reads from demodulator */
53
54 ret = i2c_transfer(state->i2c_adap, msg, 2);
55
56 return ret;
57}
58
59/* read single register */
60static int it913x_rd_reg(struct it913x_state *state, u32 reg)
61{
62 int ret;
63 u8 b[1];
64 ret = it913x_rd_regs(state, reg, &b[0], sizeof(b));
65 return (ret < 0) ? -ENODEV : b[0];
66}
67
68/* write multiple registers */
69static int it913x_wr_regs(struct it913x_state *state,
70 u8 pro, u32 reg, u8 buf[], u8 count)
71{
72 u8 b[256];
73 struct i2c_msg msg[1] = {
74 { .addr = state->i2c_addr, .flags = 0,
75 .buf = b, .len = 3 + count }
76 };
77 int ret;
78 b[0] = (u8)(reg >> 16) & 0xff;
79 b[1] = (u8)(reg >> 8) & 0xff;
80 b[2] = (u8) reg & 0xff;
81 memcpy(&b[3], buf, count);
82
83 if (pro == PRO_DMOD)
84 b[0] |= 0x80;
85
86 ret = i2c_transfer(state->i2c_adap, msg, 1);
87
88 if (ret < 0)
89 return -EIO;
90
91 return 0;
92}
93
94/* write single register */
95static int it913x_wr_reg(struct it913x_state *state,
96 u8 pro, u32 reg, u32 data)
97{
98 int ret;
99 u8 b[4];
100 u8 s;
101
102 b[0] = data >> 24;
103 b[1] = (data >> 16) & 0xff;
104 b[2] = (data >> 8) & 0xff;
105 b[3] = data & 0xff;
106 /* expand write as needed */
107 if (data < 0x100)
108 s = 3;
109 else if (data < 0x1000)
110 s = 2;
111 else if (data < 0x100000)
112 s = 1;
113 else
114 s = 0;
115
116 ret = it913x_wr_regs(state, pro, reg, &b[s], sizeof(b) - s);
117
118 return ret;
119}
120
121static int it913x_script_loader(struct it913x_state *state,
122 struct it913xset *loadscript)
123{
124 int ret, i;
125 if (loadscript == NULL)
126 return -EINVAL;
127
128 for (i = 0; i < 1000; ++i) {
129 if (loadscript[i].pro == 0xff)
130 break;
131 ret = it913x_wr_regs(state, loadscript[i].pro,
132 loadscript[i].address,
133 loadscript[i].reg, loadscript[i].count);
134 if (ret < 0)
135 return -ENODEV;
136 }
137 return 0;
138}
139
140static int it913x_init(struct dvb_frontend *fe)
141{
142 struct it913x_state *state = fe->tuner_priv;
143 int ret, i, reg;
144 u8 val, nv_val;
145 u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
146 u8 b[2];
147
148 reg = it913x_rd_reg(state, 0xec86);
149 switch (reg) {
150 case 0:
151 state->tun_clk_mode = reg;
152 state->tun_xtal = 2000;
153 state->tun_fdiv = 3;
154 val = 16;
155 break;
156 case -ENODEV:
157 return -ENODEV;
158 case 1:
159 default:
160 state->tun_clk_mode = reg;
161 state->tun_xtal = 640;
162 state->tun_fdiv = 1;
163 val = 6;
164 break;
165 }
166
167 reg = it913x_rd_reg(state, 0xed03);
168
169 if (reg < 0)
170 return -ENODEV;
171 else if (reg < ARRAY_SIZE(nv))
172 nv_val = nv[reg];
173 else
174 nv_val = 2;
175
176 for (i = 0; i < 50; i++) {
177 ret = it913x_rd_regs(state, 0xed23, &b[0], sizeof(b));
178 reg = (b[1] << 8) + b[0];
179 if (reg > 0)
180 break;
181 if (ret < 0)
182 return -ENODEV;
183 udelay(2000);
184 }
185 state->tun_fn_min = state->tun_xtal * reg;
186 state->tun_fn_min /= (state->tun_fdiv * nv_val);
187 dev_dbg(&state->i2c_adap->dev, "%s: Tuner fn_min %d\n", __func__,
188 state->tun_fn_min);
189
190 if (state->chip_ver > 1)
191 msleep(50);
192 else {
193 for (i = 0; i < 50; i++) {
194 reg = it913x_rd_reg(state, 0xec82);
195 if (reg > 0)
196 break;
197 if (reg < 0)
198 return -ENODEV;
199 udelay(2000);
200 }
201 }
202
203 /* Power Up Tuner - common all versions */
204 ret = it913x_wr_reg(state, PRO_DMOD, 0xec40, 0x1);
205 ret |= it913x_wr_reg(state, PRO_DMOD, 0xfba8, 0x0);
206 ret |= it913x_wr_reg(state, PRO_DMOD, 0xec57, 0x0);
207 ret |= it913x_wr_reg(state, PRO_DMOD, 0xec58, 0x0);
208
209 return it913x_wr_reg(state, PRO_DMOD, 0xed81, val);
210}
211
212static int it9137_set_params(struct dvb_frontend *fe)
213{
214 struct it913x_state *state = fe->tuner_priv;
215 struct it913xset *set_tuner = set_it9137_template;
216 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
217 u32 bandwidth = p->bandwidth_hz;
218 u32 frequency_m = p->frequency;
219 int ret, reg;
220 u32 frequency = frequency_m / 1000;
221 u32 freq, temp_f, tmp;
222 u16 iqik_m_cal;
223 u16 n_div;
224 u8 n;
225 u8 l_band;
226 u8 lna_band;
227 u8 bw;
228
229 if (state->firmware_ver == 1)
230 set_tuner = set_it9135_template;
231 else
232 set_tuner = set_it9137_template;
233
234 dev_dbg(&state->i2c_adap->dev, "%s: Tuner Frequency %d Bandwidth %d\n",
235 __func__, frequency, bandwidth);
236
237 if (frequency >= 51000 && frequency <= 440000) {
238 l_band = 0;
239 lna_band = 0;
240 } else if (frequency > 440000 && frequency <= 484000) {
241 l_band = 1;
242 lna_band = 1;
243 } else if (frequency > 484000 && frequency <= 533000) {
244 l_band = 1;
245 lna_band = 2;
246 } else if (frequency > 533000 && frequency <= 587000) {
247 l_band = 1;
248 lna_band = 3;
249 } else if (frequency > 587000 && frequency <= 645000) {
250 l_band = 1;
251 lna_band = 4;
252 } else if (frequency > 645000 && frequency <= 710000) {
253 l_band = 1;
254 lna_band = 5;
255 } else if (frequency > 710000 && frequency <= 782000) {
256 l_band = 1;
257 lna_band = 6;
258 } else if (frequency > 782000 && frequency <= 860000) {
259 l_band = 1;
260 lna_band = 7;
261 } else if (frequency > 1450000 && frequency <= 1492000) {
262 l_band = 1;
263 lna_band = 0;
264 } else if (frequency > 1660000 && frequency <= 1685000) {
265 l_band = 1;
266 lna_band = 1;
267 } else
268 return -EINVAL;
269 set_tuner[0].reg[0] = lna_band;
270
271 switch (bandwidth) {
272 case 5000000:
273 bw = 0;
274 break;
275 case 6000000:
276 bw = 2;
277 break;
278 case 7000000:
279 bw = 4;
280 break;
281 default:
282 case 8000000:
283 bw = 6;
284 break;
285 }
286
287 set_tuner[1].reg[0] = bw;
288 set_tuner[2].reg[0] = 0xa0 | (l_band << 3);
289
290 if (frequency > 53000 && frequency <= 74000) {
291 n_div = 48;
292 n = 0;
293 } else if (frequency > 74000 && frequency <= 111000) {
294 n_div = 32;
295 n = 1;
296 } else if (frequency > 111000 && frequency <= 148000) {
297 n_div = 24;
298 n = 2;
299 } else if (frequency > 148000 && frequency <= 222000) {
300 n_div = 16;
301 n = 3;
302 } else if (frequency > 222000 && frequency <= 296000) {
303 n_div = 12;
304 n = 4;
305 } else if (frequency > 296000 && frequency <= 445000) {
306 n_div = 8;
307 n = 5;
308 } else if (frequency > 445000 && frequency <= state->tun_fn_min) {
309 n_div = 6;
310 n = 6;
311 } else if (frequency > state->tun_fn_min && frequency <= 950000) {
312 n_div = 4;
313 n = 7;
314 } else if (frequency > 1450000 && frequency <= 1680000) {
315 n_div = 2;
316 n = 0;
317 } else
318 return -EINVAL;
319
320 reg = it913x_rd_reg(state, 0xed81);
321 iqik_m_cal = (u16)reg * n_div;
322
323 if (reg < 0x20) {
324 if (state->tun_clk_mode == 0)
325 iqik_m_cal = (iqik_m_cal * 9) >> 5;
326 else
327 iqik_m_cal >>= 1;
328 } else {
329 iqik_m_cal = 0x40 - iqik_m_cal;
330 if (state->tun_clk_mode == 0)
331 iqik_m_cal = ~((iqik_m_cal * 9) >> 5);
332 else
333 iqik_m_cal = ~(iqik_m_cal >> 1);
334 }
335
336 temp_f = frequency * (u32)n_div * (u32)state->tun_fdiv;
337 freq = temp_f / state->tun_xtal;
338 tmp = freq * state->tun_xtal;
339
340 if ((temp_f - tmp) >= (state->tun_xtal >> 1))
341 freq++;
342
343 freq += (u32) n << 13;
344 /* Frequency OMEGA_IQIK_M_CAL_MID*/
345 temp_f = freq + (u32)iqik_m_cal;
346
347 set_tuner[3].reg[0] = temp_f & 0xff;
348 set_tuner[4].reg[0] = (temp_f >> 8) & 0xff;
349
350 dev_dbg(&state->i2c_adap->dev, "%s: High Frequency = %04x\n",
351 __func__, temp_f);
352
353 /* Lower frequency */
354 set_tuner[5].reg[0] = freq & 0xff;
355 set_tuner[6].reg[0] = (freq >> 8) & 0xff;
356
357 dev_dbg(&state->i2c_adap->dev, "%s: low Frequency = %04x\n",
358 __func__, freq);
359
360 ret = it913x_script_loader(state, set_tuner);
361
362 return (ret < 0) ? -ENODEV : 0;
363}
364
365/* Power sequence */
366/* Power Up Tuner on -> Frontend suspend off -> Tuner clk on */
367/* Power Down Frontend suspend on -> Tuner clk off -> Tuner off */
368
369static int it913x_sleep(struct dvb_frontend *fe)
370{
371 struct it913x_state *state = fe->tuner_priv;
372 return it913x_script_loader(state, it9137_tuner_off);
373}
374
375static int it913x_release(struct dvb_frontend *fe)
376{
377 kfree(fe->tuner_priv);
378 return 0;
379}
380
381static const struct dvb_tuner_ops it913x_tuner_ops = {
382 .info = {
383 .name = "ITE Tech IT913X",
384 .frequency_min = 174000000,
385 .frequency_max = 862000000,
386 },
387
388 .release = it913x_release,
389
390 .init = it913x_init,
391 .sleep = it913x_sleep,
392 .set_params = it9137_set_params,
393};
394
395struct dvb_frontend *it913x_attach(struct dvb_frontend *fe,
396 struct i2c_adapter *i2c_adap, u8 i2c_addr, u8 config)
397{
398 struct it913x_state *state = NULL;
399
400 /* allocate memory for the internal state */
401 state = kzalloc(sizeof(struct it913x_state), GFP_KERNEL);
402 if (state == NULL)
403 return NULL;
404
405 state->i2c_adap = i2c_adap;
406 state->i2c_addr = i2c_addr;
407
408 switch (config) {
409 case AF9033_TUNER_IT9135_38:
410 case AF9033_TUNER_IT9135_51:
411 case AF9033_TUNER_IT9135_52:
412 state->chip_ver = 0x01;
413 break;
414 case AF9033_TUNER_IT9135_60:
415 case AF9033_TUNER_IT9135_61:
416 case AF9033_TUNER_IT9135_62:
417 state->chip_ver = 0x02;
418 break;
419 default:
420 dev_dbg(&i2c_adap->dev,
421 "%s: invalid config=%02x\n", __func__, config);
422 goto error;
423 }
424
425 state->tuner_type = config;
426 state->firmware_ver = 1;
427
428 fe->tuner_priv = state;
429 memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops,
430 sizeof(struct dvb_tuner_ops));
431
432 dev_info(&i2c_adap->dev,
433 "%s: ITE Tech IT913X successfully attached\n",
434 KBUILD_MODNAME);
435 dev_dbg(&i2c_adap->dev, "%s: config=%02x chip_ver=%02x\n",
436 __func__, config, state->chip_ver);
437
438 return fe;
439error:
440 kfree(state);
441 return NULL;
442}
443EXPORT_SYMBOL(it913x_attach);
444
445MODULE_DESCRIPTION("ITE Tech IT913X silicon tuner driver");
446MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
447MODULE_LICENSE("GPL");
diff --git a/drivers/media/tuners/tuner_it913x.h b/drivers/media/tuners/tuner_it913x.h
new file mode 100644
index 000000000000..12dd36bd9e79
--- /dev/null
+++ b/drivers/media/tuners/tuner_it913x.h
@@ -0,0 +1,45 @@
1/*
2 * ITE Tech IT9137 silicon tuner driver
3 *
4 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
5 * IT9137 Copyright (C) ITE Tech Inc.
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 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
21 */
22
23#ifndef IT913X_H
24#define IT913X_H
25
26#include "dvb_frontend.h"
27
28#if defined(CONFIG_MEDIA_TUNER_IT913X) || \
29 (defined(CONFIG_MEDIA_TUNER_IT913X_MODULE) && defined(MODULE))
30extern struct dvb_frontend *it913x_attach(struct dvb_frontend *fe,
31 struct i2c_adapter *i2c_adap,
32 u8 i2c_addr,
33 u8 config);
34#else
35static inline struct dvb_frontend *it913x_attach(struct dvb_frontend *fe,
36 struct i2c_adapter *i2c_adap,
37 u8 i2c_addr,
38 u8 config)
39{
40 pr_warn("%s: driver disabled by Kconfig\n", __func__);
41 return NULL;
42}
43#endif
44
45#endif
diff --git a/drivers/media/tuners/tuner_it913x_priv.h b/drivers/media/tuners/tuner_it913x_priv.h
new file mode 100644
index 000000000000..ce652108aa5d
--- /dev/null
+++ b/drivers/media/tuners/tuner_it913x_priv.h
@@ -0,0 +1,78 @@
1/*
2 * ITE Tech IT9137 silicon tuner driver
3 *
4 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
5 * IT9137 Copyright (C) ITE Tech Inc.
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 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
21 */
22
23#ifndef IT913X_PRIV_H
24#define IT913X_PRIV_H
25
26#include "tuner_it913x.h"
27#include "af9033.h"
28
29#define PRO_LINK 0x0
30#define PRO_DMOD 0x1
31#define TRIGGER_OFSM 0x0000
32
33struct it913xset { u32 pro;
34 u32 address;
35 u8 reg[15];
36 u8 count;
37};
38
39/* Tuner setting scripts (still keeping it9137) */
40static struct it913xset it9137_tuner_off[] = {
41 {PRO_DMOD, 0xfba8, {0x01}, 0x01}, /* Tuner Clock Off */
42 {PRO_DMOD, 0xec40, {0x00}, 0x01}, /* Power Down Tuner */
43 {PRO_DMOD, 0xec02, {0x3f, 0x1f, 0x3f, 0x3f}, 0x04},
44 {PRO_DMOD, 0xec06, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00}, 0x0c},
46 {PRO_DMOD, 0xec12, {0x00, 0x00, 0x00, 0x00}, 0x04},
47 {PRO_DMOD, 0xec17, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 0x00}, 0x09},
49 {PRO_DMOD, 0xec22, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00}, 0x0a},
51 {PRO_DMOD, 0xec20, {0x00}, 0x01},
52 {PRO_DMOD, 0xec3f, {0x01}, 0x01},
53 {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
54};
55
56static struct it913xset set_it9135_template[] = {
57 {PRO_DMOD, 0xee06, {0x00}, 0x01},
58 {PRO_DMOD, 0xec56, {0x00}, 0x01},
59 {PRO_DMOD, 0xec4c, {0x00}, 0x01},
60 {PRO_DMOD, 0xec4d, {0x00}, 0x01},
61 {PRO_DMOD, 0xec4e, {0x00}, 0x01},
62 {PRO_DMOD, 0x011e, {0x00}, 0x01}, /* Older Devices */
63 {PRO_DMOD, 0x011f, {0x00}, 0x01},
64 {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
65};
66
67static struct it913xset set_it9137_template[] = {
68 {PRO_DMOD, 0xee06, {0x00}, 0x01},
69 {PRO_DMOD, 0xec56, {0x00}, 0x01},
70 {PRO_DMOD, 0xec4c, {0x00}, 0x01},
71 {PRO_DMOD, 0xec4d, {0x00}, 0x01},
72 {PRO_DMOD, 0xec4e, {0x00}, 0x01},
73 {PRO_DMOD, 0xec4f, {0x00}, 0x01},
74 {PRO_DMOD, 0xec50, {0x00}, 0x01},
75 {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */
76};
77
78#endif
diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index d6be1b613c52..5cd09a681b6a 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -422,13 +422,19 @@ static int xc_initialize(struct xc5000_priv *priv)
422} 422}
423 423
424static int xc_SetTVStandard(struct xc5000_priv *priv, 424static int xc_SetTVStandard(struct xc5000_priv *priv,
425 u16 VideoMode, u16 AudioMode) 425 u16 VideoMode, u16 AudioMode, u8 RadioMode)
426{ 426{
427 int ret; 427 int ret;
428 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, VideoMode, AudioMode); 428 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, VideoMode, AudioMode);
429 dprintk(1, "%s() Standard = %s\n", 429 if (RadioMode) {
430 __func__, 430 dprintk(1, "%s() Standard = %s\n",
431 XC5000_Standard[priv->video_standard].Name); 431 __func__,
432 XC5000_Standard[RadioMode].Name);
433 } else {
434 dprintk(1, "%s() Standard = %s\n",
435 __func__,
436 XC5000_Standard[priv->video_standard].Name);
437 }
432 438
433 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode); 439 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode);
434 if (ret == XC_RESULT_SUCCESS) 440 if (ret == XC_RESULT_SUCCESS)
@@ -824,7 +830,7 @@ static int xc5000_set_params(struct dvb_frontend *fe)
824 830
825 ret = xc_SetTVStandard(priv, 831 ret = xc_SetTVStandard(priv,
826 XC5000_Standard[priv->video_standard].VideoMode, 832 XC5000_Standard[priv->video_standard].VideoMode,
827 XC5000_Standard[priv->video_standard].AudioMode); 833 XC5000_Standard[priv->video_standard].AudioMode, 0);
828 if (ret != XC_RESULT_SUCCESS) { 834 if (ret != XC_RESULT_SUCCESS) {
829 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n"); 835 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
830 return -EREMOTEIO; 836 return -EREMOTEIO;
@@ -940,7 +946,7 @@ tune_channel:
940 946
941 ret = xc_SetTVStandard(priv, 947 ret = xc_SetTVStandard(priv,
942 XC5000_Standard[priv->video_standard].VideoMode, 948 XC5000_Standard[priv->video_standard].VideoMode,
943 XC5000_Standard[priv->video_standard].AudioMode); 949 XC5000_Standard[priv->video_standard].AudioMode, 0);
944 if (ret != XC_RESULT_SUCCESS) { 950 if (ret != XC_RESULT_SUCCESS) {
945 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n"); 951 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
946 return -EREMOTEIO; 952 return -EREMOTEIO;
@@ -1003,7 +1009,7 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe,
1003 priv->rf_mode = XC_RF_MODE_AIR; 1009 priv->rf_mode = XC_RF_MODE_AIR;
1004 1010
1005 ret = xc_SetTVStandard(priv, XC5000_Standard[radio_input].VideoMode, 1011 ret = xc_SetTVStandard(priv, XC5000_Standard[radio_input].VideoMode,
1006 XC5000_Standard[radio_input].AudioMode); 1012 XC5000_Standard[radio_input].AudioMode, radio_input);
1007 1013
1008 if (ret != XC_RESULT_SUCCESS) { 1014 if (ret != XC_RESULT_SUCCESS) {
1009 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n"); 1015 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
diff --git a/drivers/media/tuners/xc5000.h b/drivers/media/tuners/xc5000.h
index b1a547494625..7245cae19f0c 100644
--- a/drivers/media/tuners/xc5000.h
+++ b/drivers/media/tuners/xc5000.h
@@ -22,6 +22,7 @@
22#ifndef __XC5000_H__ 22#ifndef __XC5000_H__
23#define __XC5000_H__ 23#define __XC5000_H__
24 24
25#include <linux/kconfig.h>
25#include <linux/firmware.h> 26#include <linux/firmware.h>
26 27
27struct dvb_frontend; 28struct dvb_frontend;
@@ -56,8 +57,7 @@ struct xc5000_config {
56 * it's passed back to a bridge during tuner_callback(). 57 * it's passed back to a bridge during tuner_callback().
57 */ 58 */
58 59
59#if defined(CONFIG_MEDIA_TUNER_XC5000) || \ 60#if IS_ENABLED(CONFIG_MEDIA_TUNER_XC5000)
60 (defined(CONFIG_MEDIA_TUNER_XC5000_MODULE) && defined(MODULE))
61extern struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe, 61extern struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
62 struct i2c_adapter *i2c, 62 struct i2c_adapter *i2c,
63 const struct xc5000_config *cfg); 63 const struct xc5000_config *cfg);
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 1e6f40ef1c6b..bd9d19a73efd 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -125,6 +125,26 @@ static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
125 return status; 125 return status;
126} 126}
127 127
128static void au0828_usb_release(struct au0828_dev *dev)
129{
130 /* I2C */
131 au0828_i2c_unregister(dev);
132
133 kfree(dev);
134}
135
136#ifdef CONFIG_VIDEO_AU0828_V4L2
137static void au0828_usb_v4l2_release(struct v4l2_device *v4l2_dev)
138{
139 struct au0828_dev *dev =
140 container_of(v4l2_dev, struct au0828_dev, v4l2_dev);
141
142 v4l2_ctrl_handler_free(&dev->v4l2_ctrl_hdl);
143 v4l2_device_unregister(&dev->v4l2_dev);
144 au0828_usb_release(dev);
145}
146#endif
147
128static void au0828_usb_disconnect(struct usb_interface *interface) 148static void au0828_usb_disconnect(struct usb_interface *interface)
129{ 149{
130 struct au0828_dev *dev = usb_get_intfdata(interface); 150 struct au0828_dev *dev = usb_get_intfdata(interface);
@@ -134,26 +154,19 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
134 /* Digital TV */ 154 /* Digital TV */
135 au0828_dvb_unregister(dev); 155 au0828_dvb_unregister(dev);
136 156
137#ifdef CONFIG_VIDEO_AU0828_V4L2
138 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
139 au0828_analog_unregister(dev);
140#endif
141
142 /* I2C */
143 au0828_i2c_unregister(dev);
144
145#ifdef CONFIG_VIDEO_AU0828_V4L2
146 v4l2_device_unregister(&dev->v4l2_dev);
147#endif
148
149 usb_set_intfdata(interface, NULL); 157 usb_set_intfdata(interface, NULL);
150
151 mutex_lock(&dev->mutex); 158 mutex_lock(&dev->mutex);
152 dev->usbdev = NULL; 159 dev->usbdev = NULL;
153 mutex_unlock(&dev->mutex); 160 mutex_unlock(&dev->mutex);
154 161#ifdef CONFIG_VIDEO_AU0828_V4L2
155 kfree(dev); 162 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
156 163 au0828_analog_unregister(dev);
164 v4l2_device_disconnect(&dev->v4l2_dev);
165 v4l2_device_put(&dev->v4l2_dev);
166 return;
167 }
168#endif
169 au0828_usb_release(dev);
157} 170}
158 171
159static int au0828_usb_probe(struct usb_interface *interface, 172static int au0828_usb_probe(struct usb_interface *interface,
@@ -202,15 +215,27 @@ static int au0828_usb_probe(struct usb_interface *interface,
202 dev->boardnr = id->driver_info; 215 dev->boardnr = id->driver_info;
203 216
204#ifdef CONFIG_VIDEO_AU0828_V4L2 217#ifdef CONFIG_VIDEO_AU0828_V4L2
218 dev->v4l2_dev.release = au0828_usb_v4l2_release;
219
205 /* Create the v4l2_device */ 220 /* Create the v4l2_device */
206 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); 221 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
207 if (retval) { 222 if (retval) {
208 printk(KERN_ERR "%s() v4l2_device_register failed\n", 223 pr_err("%s() v4l2_device_register failed\n",
224 __func__);
225 mutex_unlock(&dev->lock);
226 kfree(dev);
227 return retval;
228 }
229 /* This control handler will inherit the controls from au8522 */
230 retval = v4l2_ctrl_handler_init(&dev->v4l2_ctrl_hdl, 4);
231 if (retval) {
232 pr_err("%s() v4l2_ctrl_handler_init failed\n",
209 __func__); 233 __func__);
210 mutex_unlock(&dev->lock); 234 mutex_unlock(&dev->lock);
211 kfree(dev); 235 kfree(dev);
212 return -EIO; 236 return retval;
213 } 237 }
238 dev->v4l2_dev.ctrl_handler = &dev->v4l2_ctrl_hdl;
214#endif 239#endif
215 240
216 /* Power Up the bridge */ 241 /* Power Up the bridge */
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 8b9e8268e911..75ac9947cdac 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -35,6 +35,7 @@
35#include <linux/suspend.h> 35#include <linux/suspend.h>
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-event.h>
38#include <media/v4l2-chip-ident.h> 39#include <media/v4l2-chip-ident.h>
39#include <media/tuner.h> 40#include <media/tuner.h>
40#include "au0828.h" 41#include "au0828.h"
@@ -58,6 +59,12 @@ do {\
58 } \ 59 } \
59 } while (0) 60 } while (0)
60 61
62static inline void i2c_gate_ctrl(struct au0828_dev *dev, int val)
63{
64 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl)
65 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, val);
66}
67
61static inline void print_err_status(struct au0828_dev *dev, 68static inline void print_err_status(struct au0828_dev *dev,
62 int packet, int status) 69 int packet, int status)
63{ 70{
@@ -988,20 +995,22 @@ static int au0828_v4l2_open(struct file *filp)
988 995
989 fh->type = type; 996 fh->type = type;
990 fh->dev = dev; 997 fh->dev = dev;
998 v4l2_fh_init(&fh->fh, vdev);
991 filp->private_data = fh; 999 filp->private_data = fh;
992 1000
993 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { 1001 if (mutex_lock_interruptible(&dev->lock)) {
1002 kfree(fh);
1003 return -ERESTARTSYS;
1004 }
1005 if (dev->users == 0) {
994 /* set au0828 interface0 to AS5 here again */ 1006 /* set au0828 interface0 to AS5 here again */
995 ret = usb_set_interface(dev->usbdev, 0, 5); 1007 ret = usb_set_interface(dev->usbdev, 0, 5);
996 if (ret < 0) { 1008 if (ret < 0) {
1009 mutex_unlock(&dev->lock);
997 printk(KERN_INFO "Au0828 can't set alternate to 5!\n"); 1010 printk(KERN_INFO "Au0828 can't set alternate to 5!\n");
1011 kfree(fh);
998 return -EBUSY; 1012 return -EBUSY;
999 } 1013 }
1000 dev->width = NTSC_STD_W;
1001 dev->height = NTSC_STD_H;
1002 dev->frame_size = dev->width * dev->height * 2;
1003 dev->field_size = dev->width * dev->height;
1004 dev->bytesperline = dev->width * 2;
1005 1014
1006 au0828_analog_stream_enable(dev); 1015 au0828_analog_stream_enable(dev);
1007 au0828_analog_stream_reset(dev); 1016 au0828_analog_stream_reset(dev);
@@ -1014,6 +1023,7 @@ static int au0828_v4l2_open(struct file *filp)
1014 } 1023 }
1015 1024
1016 dev->users++; 1025 dev->users++;
1026 mutex_unlock(&dev->lock);
1017 1027
1018 videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops, 1028 videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops,
1019 NULL, &dev->slock, 1029 NULL, &dev->slock,
@@ -1023,14 +1033,13 @@ static int au0828_v4l2_open(struct file *filp)
1023 &dev->lock); 1033 &dev->lock);
1024 1034
1025 /* VBI Setup */ 1035 /* VBI Setup */
1026 dev->vbi_width = 720;
1027 dev->vbi_height = 1;
1028 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &au0828_vbi_qops, 1036 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &au0828_vbi_qops,
1029 NULL, &dev->slock, 1037 NULL, &dev->slock,
1030 V4L2_BUF_TYPE_VBI_CAPTURE, 1038 V4L2_BUF_TYPE_VBI_CAPTURE,
1031 V4L2_FIELD_SEQ_TB, 1039 V4L2_FIELD_SEQ_TB,
1032 sizeof(struct au0828_buffer), fh, 1040 sizeof(struct au0828_buffer), fh,
1033 &dev->lock); 1041 &dev->lock);
1042 v4l2_fh_add(&fh->fh);
1034 return ret; 1043 return ret;
1035} 1044}
1036 1045
@@ -1040,6 +1049,9 @@ static int au0828_v4l2_close(struct file *filp)
1040 struct au0828_fh *fh = filp->private_data; 1049 struct au0828_fh *fh = filp->private_data;
1041 struct au0828_dev *dev = fh->dev; 1050 struct au0828_dev *dev = fh->dev;
1042 1051
1052 v4l2_fh_del(&fh->fh);
1053 v4l2_fh_exit(&fh->fh);
1054 mutex_lock(&dev->lock);
1043 if (res_check(fh, AU0828_RESOURCE_VIDEO)) { 1055 if (res_check(fh, AU0828_RESOURCE_VIDEO)) {
1044 /* Cancel timeout thread in case they didn't call streamoff */ 1056 /* Cancel timeout thread in case they didn't call streamoff */
1045 dev->vid_timeout_running = 0; 1057 dev->vid_timeout_running = 0;
@@ -1058,19 +1070,14 @@ static int au0828_v4l2_close(struct file *filp)
1058 res_free(fh, AU0828_RESOURCE_VBI); 1070 res_free(fh, AU0828_RESOURCE_VBI);
1059 } 1071 }
1060 1072
1061 if (dev->users == 1) { 1073 if (dev->users == 1 && video_is_registered(video_devdata(filp))) {
1062 if (dev->dev_state & DEV_DISCONNECTED) {
1063 au0828_analog_unregister(dev);
1064 kfree(dev);
1065 return 0;
1066 }
1067
1068 au0828_analog_stream_disable(dev); 1074 au0828_analog_stream_disable(dev);
1069 1075
1070 au0828_uninit_isoc(dev); 1076 au0828_uninit_isoc(dev);
1071 1077
1072 /* Save some power by putting tuner to sleep */ 1078 /* Save some power by putting tuner to sleep */
1073 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0); 1079 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
1080 dev->std_set_in_tuner_core = 0;
1074 1081
1075 /* When close the device, set the usb intf0 into alt0 to free 1082 /* When close the device, set the usb intf0 into alt0 to free
1076 USB bandwidth */ 1083 USB bandwidth */
@@ -1078,6 +1085,7 @@ static int au0828_v4l2_close(struct file *filp)
1078 if (ret < 0) 1085 if (ret < 0)
1079 printk(KERN_INFO "Au0828 can't set alternate to 0!\n"); 1086 printk(KERN_INFO "Au0828 can't set alternate to 0!\n");
1080 } 1087 }
1088 mutex_unlock(&dev->lock);
1081 1089
1082 videobuf_mmap_free(&fh->vb_vidq); 1090 videobuf_mmap_free(&fh->vb_vidq);
1083 videobuf_mmap_free(&fh->vb_vbiq); 1091 videobuf_mmap_free(&fh->vb_vbiq);
@@ -1087,6 +1095,26 @@ static int au0828_v4l2_close(struct file *filp)
1087 return 0; 1095 return 0;
1088} 1096}
1089 1097
1098/* Must be called with dev->lock held */
1099static void au0828_init_tuner(struct au0828_dev *dev)
1100{
1101 struct v4l2_frequency f = {
1102 .frequency = dev->ctrl_freq,
1103 .type = V4L2_TUNER_ANALOG_TV,
1104 };
1105
1106 if (dev->std_set_in_tuner_core)
1107 return;
1108 dev->std_set_in_tuner_core = 1;
1109 i2c_gate_ctrl(dev, 1);
1110 /* If we've never sent the standard in tuner core, do so now.
1111 We don't do this at device probe because we don't want to
1112 incur the cost of a firmware load */
1113 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->std);
1114 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
1115 i2c_gate_ctrl(dev, 0);
1116}
1117
1090static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf, 1118static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
1091 size_t count, loff_t *pos) 1119 size_t count, loff_t *pos)
1092{ 1120{
@@ -1098,6 +1126,11 @@ static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
1098 if (rc < 0) 1126 if (rc < 0)
1099 return rc; 1127 return rc;
1100 1128
1129 if (mutex_lock_interruptible(&dev->lock))
1130 return -ERESTARTSYS;
1131 au0828_init_tuner(dev);
1132 mutex_unlock(&dev->lock);
1133
1101 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1134 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1102 if (res_locked(dev, AU0828_RESOURCE_VIDEO)) 1135 if (res_locked(dev, AU0828_RESOURCE_VIDEO))
1103 return -EBUSY; 1136 return -EBUSY;
@@ -1128,23 +1161,32 @@ static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait)
1128{ 1161{
1129 struct au0828_fh *fh = filp->private_data; 1162 struct au0828_fh *fh = filp->private_data;
1130 struct au0828_dev *dev = fh->dev; 1163 struct au0828_dev *dev = fh->dev;
1131 int rc; 1164 unsigned long req_events = poll_requested_events(wait);
1165 unsigned int res;
1132 1166
1133 rc = check_dev(dev); 1167 if (check_dev(dev) < 0)
1134 if (rc < 0) 1168 return POLLERR;
1135 return rc; 1169
1170 res = v4l2_ctrl_poll(filp, wait);
1171 if (!(req_events & (POLLIN | POLLRDNORM)))
1172 return res;
1173
1174 if (mutex_lock_interruptible(&dev->lock))
1175 return -ERESTARTSYS;
1176 au0828_init_tuner(dev);
1177 mutex_unlock(&dev->lock);
1136 1178
1137 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1179 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1138 if (!res_get(fh, AU0828_RESOURCE_VIDEO)) 1180 if (!res_get(fh, AU0828_RESOURCE_VIDEO))
1139 return POLLERR; 1181 return POLLERR;
1140 return videobuf_poll_stream(filp, &fh->vb_vidq, wait); 1182 return res | videobuf_poll_stream(filp, &fh->vb_vidq, wait);
1141 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 1183 }
1184 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1142 if (!res_get(fh, AU0828_RESOURCE_VBI)) 1185 if (!res_get(fh, AU0828_RESOURCE_VBI))
1143 return POLLERR; 1186 return POLLERR;
1144 return videobuf_poll_stream(filp, &fh->vb_vbiq, wait); 1187 return res | videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
1145 } else {
1146 return POLLERR;
1147 } 1188 }
1189 return POLLERR;
1148} 1190}
1149 1191
1150static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) 1192static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
@@ -1172,9 +1214,6 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
1172 int width = format->fmt.pix.width; 1214 int width = format->fmt.pix.width;
1173 int height = format->fmt.pix.height; 1215 int height = format->fmt.pix.height;
1174 1216
1175 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1176 return -EINVAL;
1177
1178 /* If they are demanding a format other than the one we support, 1217 /* If they are demanding a format other than the one we support,
1179 bail out (tvtime asks for UYVY and then retries with YUYV) */ 1218 bail out (tvtime asks for UYVY and then retries with YUYV) */
1180 if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY) 1219 if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY)
@@ -1193,6 +1232,7 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
1193 format->fmt.pix.sizeimage = width * height * 2; 1232 format->fmt.pix.sizeimage = width * height * 2;
1194 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 1233 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1195 format->fmt.pix.field = V4L2_FIELD_INTERLACED; 1234 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
1235 format->fmt.pix.priv = 0;
1196 1236
1197 if (cmd == VIDIOC_TRY_FMT) 1237 if (cmd == VIDIOC_TRY_FMT)
1198 return 0; 1238 return 0;
@@ -1226,35 +1266,28 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
1226} 1266}
1227 1267
1228 1268
1229static int vidioc_queryctrl(struct file *file, void *priv,
1230 struct v4l2_queryctrl *qc)
1231{
1232 struct au0828_fh *fh = priv;
1233 struct au0828_dev *dev = fh->dev;
1234 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1235 if (qc->type)
1236 return 0;
1237 else
1238 return -EINVAL;
1239}
1240
1241static int vidioc_querycap(struct file *file, void *priv, 1269static int vidioc_querycap(struct file *file, void *priv,
1242 struct v4l2_capability *cap) 1270 struct v4l2_capability *cap)
1243{ 1271{
1244 struct au0828_fh *fh = priv; 1272 struct video_device *vdev = video_devdata(file);
1273 struct au0828_fh *fh = priv;
1245 struct au0828_dev *dev = fh->dev; 1274 struct au0828_dev *dev = fh->dev;
1246 1275
1247 strlcpy(cap->driver, "au0828", sizeof(cap->driver)); 1276 strlcpy(cap->driver, "au0828", sizeof(cap->driver));
1248 strlcpy(cap->card, dev->board.name, sizeof(cap->card)); 1277 strlcpy(cap->card, dev->board.name, sizeof(cap->card));
1249 strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info)); 1278 usb_make_path(dev->usbdev, cap->bus_info, sizeof(cap->bus_info));
1250 1279
1251 /*set the device capabilities */ 1280 /* set the device capabilities */
1252 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 1281 cap->device_caps = V4L2_CAP_AUDIO |
1253 V4L2_CAP_VBI_CAPTURE |
1254 V4L2_CAP_AUDIO |
1255 V4L2_CAP_READWRITE | 1282 V4L2_CAP_READWRITE |
1256 V4L2_CAP_STREAMING | 1283 V4L2_CAP_STREAMING |
1257 V4L2_CAP_TUNER; 1284 V4L2_CAP_TUNER;
1285 if (vdev->vfl_type == VFL_TYPE_GRABBER)
1286 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
1287 else
1288 cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
1289 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
1290 V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE;
1258 return 0; 1291 return 0;
1259} 1292}
1260 1293
@@ -1286,6 +1319,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1286 f->fmt.pix.sizeimage = dev->frame_size; 1319 f->fmt.pix.sizeimage = dev->frame_size;
1287 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */ 1320 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */
1288 f->fmt.pix.field = V4L2_FIELD_INTERLACED; 1321 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1322 f->fmt.pix.priv = 0;
1289 return 0; 1323 return 0;
1290} 1324}
1291 1325
@@ -1320,24 +1354,34 @@ out:
1320 return rc; 1354 return rc;
1321} 1355}
1322 1356
1323static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) 1357static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1324{ 1358{
1325 struct au0828_fh *fh = priv; 1359 struct au0828_fh *fh = priv;
1326 struct au0828_dev *dev = fh->dev; 1360 struct au0828_dev *dev = fh->dev;
1327 1361
1328 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl) 1362 dev->std = norm;
1329 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, 1); 1363
1364 au0828_init_tuner(dev);
1365
1366 i2c_gate_ctrl(dev, 1);
1330 1367
1331 /* FIXME: when we support something other than NTSC, we are going to 1368 /* FIXME: when we support something other than NTSC, we are going to
1332 have to make the au0828 bridge adjust the size of its capture 1369 have to make the au0828 bridge adjust the size of its capture
1333 buffer, which is currently hardcoded at 720x480 */ 1370 buffer, which is currently hardcoded at 720x480 */
1334 1371
1335 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, *norm); 1372 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, norm);
1336 dev->std_set_in_tuner_core = 1;
1337 1373
1338 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl) 1374 i2c_gate_ctrl(dev, 0);
1339 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, 0); 1375
1376 return 0;
1377}
1378
1379static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1380{
1381 struct au0828_fh *fh = priv;
1382 struct au0828_dev *dev = fh->dev;
1340 1383
1384 *norm = dev->std;
1341 return 0; 1385 return 0;
1342} 1386}
1343 1387
@@ -1368,10 +1412,13 @@ static int vidioc_enum_input(struct file *file, void *priv,
1368 input->index = tmp; 1412 input->index = tmp;
1369 strcpy(input->name, inames[AUVI_INPUT(tmp).type]); 1413 strcpy(input->name, inames[AUVI_INPUT(tmp).type]);
1370 if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) || 1414 if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) ||
1371 (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) 1415 (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) {
1372 input->type |= V4L2_INPUT_TYPE_TUNER; 1416 input->type |= V4L2_INPUT_TYPE_TUNER;
1373 else 1417 input->audioset = 1;
1418 } else {
1374 input->type |= V4L2_INPUT_TYPE_CAMERA; 1419 input->type |= V4L2_INPUT_TYPE_CAMERA;
1420 input->audioset = 2;
1421 }
1375 1422
1376 input->std = dev->vdev->tvnorms; 1423 input->std = dev->vdev->tvnorms;
1377 1424
@@ -1386,32 +1433,25 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1386 return 0; 1433 return 0;
1387} 1434}
1388 1435
1389static int vidioc_s_input(struct file *file, void *priv, unsigned int index) 1436static void au0828_s_input(struct au0828_dev *dev, int index)
1390{ 1437{
1391 struct au0828_fh *fh = priv;
1392 struct au0828_dev *dev = fh->dev;
1393 int i; 1438 int i;
1394 1439
1395 dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__,
1396 index);
1397 if (index >= AU0828_MAX_INPUT)
1398 return -EINVAL;
1399 if (AUVI_INPUT(index).type == 0)
1400 return -EINVAL;
1401 dev->ctrl_input = index;
1402
1403 switch (AUVI_INPUT(index).type) { 1440 switch (AUVI_INPUT(index).type) {
1404 case AU0828_VMUX_SVIDEO: 1441 case AU0828_VMUX_SVIDEO:
1405 dev->input_type = AU0828_VMUX_SVIDEO; 1442 dev->input_type = AU0828_VMUX_SVIDEO;
1443 dev->ctrl_ainput = 1;
1406 break; 1444 break;
1407 case AU0828_VMUX_COMPOSITE: 1445 case AU0828_VMUX_COMPOSITE:
1408 dev->input_type = AU0828_VMUX_COMPOSITE; 1446 dev->input_type = AU0828_VMUX_COMPOSITE;
1447 dev->ctrl_ainput = 1;
1409 break; 1448 break;
1410 case AU0828_VMUX_TELEVISION: 1449 case AU0828_VMUX_TELEVISION:
1411 dev->input_type = AU0828_VMUX_TELEVISION; 1450 dev->input_type = AU0828_VMUX_TELEVISION;
1451 dev->ctrl_ainput = 0;
1412 break; 1452 break;
1413 default: 1453 default:
1414 dprintk(1, "VIDIOC_S_INPUT unknown input type set [%d]\n", 1454 dprintk(1, "unknown input type set [%d]\n",
1415 AUVI_INPUT(index).type); 1455 AUVI_INPUT(index).type);
1416 break; 1456 break;
1417 } 1457 }
@@ -1442,55 +1482,60 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
1442 1482
1443 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, 1483 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
1444 AUVI_INPUT(index).amux, 0, 0); 1484 AUVI_INPUT(index).amux, 0, 0);
1445 return 0;
1446} 1485}
1447 1486
1448static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) 1487static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
1449{ 1488{
1450 struct au0828_fh *fh = priv; 1489 struct au0828_fh *fh = priv;
1451 struct au0828_dev *dev = fh->dev; 1490 struct au0828_dev *dev = fh->dev;
1452 unsigned int index = a->index;
1453 1491
1492 dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__,
1493 index);
1494 if (index >= AU0828_MAX_INPUT)
1495 return -EINVAL;
1496 if (AUVI_INPUT(index).type == 0)
1497 return -EINVAL;
1498 dev->ctrl_input = index;
1499 au0828_s_input(dev, index);
1500 return 0;
1501}
1502
1503static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)
1504{
1454 if (a->index > 1) 1505 if (a->index > 1)
1455 return -EINVAL; 1506 return -EINVAL;
1456 1507
1457 index = dev->ctrl_ainput; 1508 if (a->index == 0)
1458 if (index == 0)
1459 strcpy(a->name, "Television"); 1509 strcpy(a->name, "Television");
1460 else 1510 else
1461 strcpy(a->name, "Line in"); 1511 strcpy(a->name, "Line in");
1462 1512
1463 a->capability = V4L2_AUDCAP_STEREO; 1513 a->capability = V4L2_AUDCAP_STEREO;
1464 a->index = index;
1465 return 0; 1514 return 0;
1466} 1515}
1467 1516
1468static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a) 1517static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1469{ 1518{
1470 struct au0828_fh *fh = priv; 1519 struct au0828_fh *fh = priv;
1471 struct au0828_dev *dev = fh->dev; 1520 struct au0828_dev *dev = fh->dev;
1472 if (a->index != dev->ctrl_ainput)
1473 return -EINVAL;
1474 return 0;
1475}
1476 1521
1477static int vidioc_g_ctrl(struct file *file, void *priv, 1522 a->index = dev->ctrl_ainput;
1478 struct v4l2_control *ctrl) 1523 if (a->index == 0)
1479{ 1524 strcpy(a->name, "Television");
1480 struct au0828_fh *fh = priv; 1525 else
1481 struct au0828_dev *dev = fh->dev; 1526 strcpy(a->name, "Line in");
1482 1527
1483 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl); 1528 a->capability = V4L2_AUDCAP_STEREO;
1484 return 0; 1529 return 0;
1485
1486} 1530}
1487 1531
1488static int vidioc_s_ctrl(struct file *file, void *priv, 1532static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a)
1489 struct v4l2_control *ctrl)
1490{ 1533{
1491 struct au0828_fh *fh = priv; 1534 struct au0828_fh *fh = priv;
1492 struct au0828_dev *dev = fh->dev; 1535 struct au0828_dev *dev = fh->dev;
1493 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); 1536
1537 if (a->index != dev->ctrl_ainput)
1538 return -EINVAL;
1494 return 0; 1539 return 0;
1495} 1540}
1496 1541
@@ -1503,12 +1548,16 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1503 return -EINVAL; 1548 return -EINVAL;
1504 1549
1505 strcpy(t->name, "Auvitek tuner"); 1550 strcpy(t->name, "Auvitek tuner");
1551
1552 au0828_init_tuner(dev);
1553 i2c_gate_ctrl(dev, 1);
1506 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); 1554 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1555 i2c_gate_ctrl(dev, 0);
1507 return 0; 1556 return 0;
1508} 1557}
1509 1558
1510static int vidioc_s_tuner(struct file *file, void *priv, 1559static int vidioc_s_tuner(struct file *file, void *priv,
1511 struct v4l2_tuner *t) 1560 const struct v4l2_tuner *t)
1512{ 1561{
1513 struct au0828_fh *fh = priv; 1562 struct au0828_fh *fh = priv;
1514 struct au0828_dev *dev = fh->dev; 1563 struct au0828_dev *dev = fh->dev;
@@ -1516,15 +1565,10 @@ static int vidioc_s_tuner(struct file *file, void *priv,
1516 if (t->index != 0) 1565 if (t->index != 0)
1517 return -EINVAL; 1566 return -EINVAL;
1518 1567
1519 t->type = V4L2_TUNER_ANALOG_TV; 1568 au0828_init_tuner(dev);
1520 1569 i2c_gate_ctrl(dev, 1);
1521 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl)
1522 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, 1);
1523
1524 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); 1570 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1525 1571 i2c_gate_ctrl(dev, 0);
1526 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl)
1527 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, 0);
1528 1572
1529 dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal, 1573 dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal,
1530 t->afc); 1574 t->afc);
@@ -1539,40 +1583,31 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1539 struct au0828_fh *fh = priv; 1583 struct au0828_fh *fh = priv;
1540 struct au0828_dev *dev = fh->dev; 1584 struct au0828_dev *dev = fh->dev;
1541 1585
1542 freq->type = V4L2_TUNER_ANALOG_TV; 1586 if (freq->tuner != 0)
1587 return -EINVAL;
1543 freq->frequency = dev->ctrl_freq; 1588 freq->frequency = dev->ctrl_freq;
1544 return 0; 1589 return 0;
1545} 1590}
1546 1591
1547static int vidioc_s_frequency(struct file *file, void *priv, 1592static int vidioc_s_frequency(struct file *file, void *priv,
1548 struct v4l2_frequency *freq) 1593 const struct v4l2_frequency *freq)
1549{ 1594{
1550 struct au0828_fh *fh = priv; 1595 struct au0828_fh *fh = priv;
1551 struct au0828_dev *dev = fh->dev; 1596 struct au0828_dev *dev = fh->dev;
1597 struct v4l2_frequency new_freq = *freq;
1552 1598
1553 if (freq->tuner != 0) 1599 if (freq->tuner != 0)
1554 return -EINVAL; 1600 return -EINVAL;
1555 if (freq->type != V4L2_TUNER_ANALOG_TV)
1556 return -EINVAL;
1557
1558 dev->ctrl_freq = freq->frequency;
1559 1601
1560 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl) 1602 au0828_init_tuner(dev);
1561 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, 1); 1603 i2c_gate_ctrl(dev, 1);
1562
1563 if (dev->std_set_in_tuner_core == 0) {
1564 /* If we've never sent the standard in tuner core, do so now. We
1565 don't do this at device probe because we don't want to incur
1566 the cost of a firmware load */
1567 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std,
1568 dev->vdev->tvnorms);
1569 dev->std_set_in_tuner_core = 1;
1570 }
1571 1604
1572 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, freq); 1605 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, freq);
1606 /* Get the actual set (and possibly clamped) frequency */
1607 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, &new_freq);
1608 dev->ctrl_freq = new_freq.frequency;
1573 1609
1574 if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl) 1610 i2c_gate_ctrl(dev, 0);
1575 dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, 0);
1576 1611
1577 au0828_analog_stream_reset(dev); 1612 au0828_analog_stream_reset(dev);
1578 1613
@@ -1598,6 +1633,7 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1598 format->fmt.vbi.count[1] = dev->vbi_height; 1633 format->fmt.vbi.count[1] = dev->vbi_height;
1599 format->fmt.vbi.start[0] = 21; 1634 format->fmt.vbi.start[0] = 21;
1600 format->fmt.vbi.start[1] = 284; 1635 format->fmt.vbi.start[1] = 284;
1636 memset(format->fmt.vbi.reserved, 0, sizeof(format->fmt.vbi.reserved));
1601 1637
1602 return 0; 1638 return 0;
1603} 1639}
@@ -1664,6 +1700,7 @@ static int vidioc_streamon(struct file *file, void *priv,
1664 if (unlikely(!res_get(fh, get_ressource(fh)))) 1700 if (unlikely(!res_get(fh, get_ressource(fh))))
1665 return -EBUSY; 1701 return -EBUSY;
1666 1702
1703 au0828_init_tuner(dev);
1667 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1704 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1668 au0828_analog_stream_enable(dev); 1705 au0828_analog_stream_enable(dev);
1669 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1); 1706 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
@@ -1756,7 +1793,7 @@ static int vidioc_g_register(struct file *file, void *priv,
1756} 1793}
1757 1794
1758static int vidioc_s_register(struct file *file, void *priv, 1795static int vidioc_s_register(struct file *file, void *priv,
1759 struct v4l2_dbg_register *reg) 1796 const struct v4l2_dbg_register *reg)
1760{ 1797{
1761 struct au0828_fh *fh = priv; 1798 struct au0828_fh *fh = priv;
1762 struct au0828_dev *dev = fh->dev; 1799 struct au0828_dev *dev = fh->dev;
@@ -1773,6 +1810,15 @@ static int vidioc_s_register(struct file *file, void *priv,
1773} 1810}
1774#endif 1811#endif
1775 1812
1813static int vidioc_log_status(struct file *file, void *fh)
1814{
1815 struct video_device *vdev = video_devdata(file);
1816
1817 v4l2_ctrl_log_status(file, fh);
1818 v4l2_device_call_all(vdev->v4l2_dev, 0, core, log_status);
1819 return 0;
1820}
1821
1776static int vidioc_reqbufs(struct file *file, void *priv, 1822static int vidioc_reqbufs(struct file *file, void *priv,
1777 struct v4l2_requestbuffers *rb) 1823 struct v4l2_requestbuffers *rb)
1778{ 1824{
@@ -1872,7 +1918,9 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1872 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1918 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1873 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1919 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1874 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1920 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1921 .vidioc_try_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1875 .vidioc_s_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1922 .vidioc_s_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1923 .vidioc_enumaudio = vidioc_enumaudio,
1876 .vidioc_g_audio = vidioc_g_audio, 1924 .vidioc_g_audio = vidioc_g_audio,
1877 .vidioc_s_audio = vidioc_s_audio, 1925 .vidioc_s_audio = vidioc_s_audio,
1878 .vidioc_cropcap = vidioc_cropcap, 1926 .vidioc_cropcap = vidioc_cropcap,
@@ -1881,12 +1929,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1881 .vidioc_qbuf = vidioc_qbuf, 1929 .vidioc_qbuf = vidioc_qbuf,
1882 .vidioc_dqbuf = vidioc_dqbuf, 1930 .vidioc_dqbuf = vidioc_dqbuf,
1883 .vidioc_s_std = vidioc_s_std, 1931 .vidioc_s_std = vidioc_s_std,
1932 .vidioc_g_std = vidioc_g_std,
1884 .vidioc_enum_input = vidioc_enum_input, 1933 .vidioc_enum_input = vidioc_enum_input,
1885 .vidioc_g_input = vidioc_g_input, 1934 .vidioc_g_input = vidioc_g_input,
1886 .vidioc_s_input = vidioc_s_input, 1935 .vidioc_s_input = vidioc_s_input,
1887 .vidioc_queryctrl = vidioc_queryctrl,
1888 .vidioc_g_ctrl = vidioc_g_ctrl,
1889 .vidioc_s_ctrl = vidioc_s_ctrl,
1890 .vidioc_streamon = vidioc_streamon, 1936 .vidioc_streamon = vidioc_streamon,
1891 .vidioc_streamoff = vidioc_streamoff, 1937 .vidioc_streamoff = vidioc_streamoff,
1892 .vidioc_g_tuner = vidioc_g_tuner, 1938 .vidioc_g_tuner = vidioc_g_tuner,
@@ -1898,6 +1944,9 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1898 .vidioc_s_register = vidioc_s_register, 1944 .vidioc_s_register = vidioc_s_register,
1899#endif 1945#endif
1900 .vidioc_g_chip_ident = vidioc_g_chip_ident, 1946 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1947 .vidioc_log_status = vidioc_log_status,
1948 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1949 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1901}; 1950};
1902 1951
1903static const struct video_device au0828_video_template = { 1952static const struct video_device au0828_video_template = {
@@ -1905,7 +1954,6 @@ static const struct video_device au0828_video_template = {
1905 .release = video_device_release, 1954 .release = video_device_release,
1906 .ioctl_ops = &video_ioctl_ops, 1955 .ioctl_ops = &video_ioctl_ops,
1907 .tvnorms = V4L2_STD_NTSC_M, 1956 .tvnorms = V4L2_STD_NTSC_M,
1908 .current_norm = V4L2_STD_NTSC_M,
1909}; 1957};
1910 1958
1911/**************************************************************************/ 1959/**************************************************************************/
@@ -1972,7 +2020,12 @@ int au0828_analog_register(struct au0828_dev *dev,
1972 dev->field_size = dev->width * dev->height; 2020 dev->field_size = dev->width * dev->height;
1973 dev->frame_size = dev->field_size << 1; 2021 dev->frame_size = dev->field_size << 1;
1974 dev->bytesperline = dev->width << 1; 2022 dev->bytesperline = dev->width << 1;
2023 dev->vbi_width = 720;
2024 dev->vbi_height = 1;
1975 dev->ctrl_ainput = 0; 2025 dev->ctrl_ainput = 0;
2026 dev->ctrl_freq = 960;
2027 dev->std = V4L2_STD_NTSC_M;
2028 au0828_s_input(dev, 0);
1976 2029
1977 /* allocate and fill v4l2 video struct */ 2030 /* allocate and fill v4l2 video struct */
1978 dev->vdev = video_device_alloc(); 2031 dev->vdev = video_device_alloc();
@@ -1991,14 +2044,16 @@ int au0828_analog_register(struct au0828_dev *dev,
1991 2044
1992 /* Fill the video capture device struct */ 2045 /* Fill the video capture device struct */
1993 *dev->vdev = au0828_video_template; 2046 *dev->vdev = au0828_video_template;
1994 dev->vdev->parent = &dev->usbdev->dev; 2047 dev->vdev->v4l2_dev = &dev->v4l2_dev;
1995 dev->vdev->lock = &dev->lock; 2048 dev->vdev->lock = &dev->lock;
2049 set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev->flags);
1996 strcpy(dev->vdev->name, "au0828a video"); 2050 strcpy(dev->vdev->name, "au0828a video");
1997 2051
1998 /* Setup the VBI device */ 2052 /* Setup the VBI device */
1999 *dev->vbi_dev = au0828_video_template; 2053 *dev->vbi_dev = au0828_video_template;
2000 dev->vbi_dev->parent = &dev->usbdev->dev; 2054 dev->vbi_dev->v4l2_dev = &dev->v4l2_dev;
2001 dev->vbi_dev->lock = &dev->lock; 2055 dev->vbi_dev->lock = &dev->lock;
2056 set_bit(V4L2_FL_USE_FH_PRIO, &dev->vbi_dev->flags);
2002 strcpy(dev->vbi_dev->name, "au0828a vbi"); 2057 strcpy(dev->vbi_dev->name, "au0828a vbi");
2003 2058
2004 /* Register the v4l2 device */ 2059 /* Register the v4l2 device */
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index e579ff69ca4a..ef1f57f22be7 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -28,6 +28,8 @@
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/videobuf-vmalloc.h> 29#include <media/videobuf-vmalloc.h>
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-ctrls.h>
32#include <media/v4l2-fh.h>
31 33
32/* DVB */ 34/* DVB */
33#include "demux.h" 35#include "demux.h"
@@ -118,6 +120,9 @@ enum au0828_dev_state {
118}; 120};
119 121
120struct au0828_fh { 122struct au0828_fh {
123 /* must be the first field of this struct! */
124 struct v4l2_fh fh;
125
121 struct au0828_dev *dev; 126 struct au0828_dev *dev;
122 unsigned int resources; 127 unsigned int resources;
123 128
@@ -202,6 +207,7 @@ struct au0828_dev {
202#ifdef CONFIG_VIDEO_AU0828_V4L2 207#ifdef CONFIG_VIDEO_AU0828_V4L2
203 /* Analog */ 208 /* Analog */
204 struct v4l2_device v4l2_dev; 209 struct v4l2_device v4l2_dev;
210 struct v4l2_ctrl_handler v4l2_ctrl_hdl;
205#endif 211#endif
206 int users; 212 int users;
207 unsigned int resources; /* resources in use */ 213 unsigned int resources; /* resources in use */
@@ -216,6 +222,7 @@ struct au0828_dev {
216 int vbi_width; 222 int vbi_width;
217 int vbi_height; 223 int vbi_height;
218 u32 vbi_read; 224 u32 vbi_read;
225 v4l2_std_id std;
219 u32 field_size; 226 u32 field_size;
220 u32 frame_size; 227 u32 frame_size;
221 u32 bytesperline; 228 u32 bytesperline;
diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index 28688dbcb609..f548db8043d4 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -34,11 +34,12 @@
34#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
37#include <media/v4l2-event.h>
37#include <media/cx2341x.h> 38#include <media/cx2341x.h>
39#include <media/tuner.h>
38#include <linux/usb.h> 40#include <linux/usb.h>
39 41
40#include "cx231xx.h" 42#include "cx231xx.h"
41/*#include "cx23885-ioctl.h"*/
42 43
43#define CX231xx_FIRM_IMAGE_SIZE 376836 44#define CX231xx_FIRM_IMAGE_SIZE 376836
44#define CX231xx_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw" 45#define CX231xx_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
@@ -75,9 +76,11 @@
75static unsigned int mpegbufs = 8; 76static unsigned int mpegbufs = 8;
76module_param(mpegbufs, int, 0644); 77module_param(mpegbufs, int, 0644);
77MODULE_PARM_DESC(mpegbufs, "number of mpeg buffers, range 2-32"); 78MODULE_PARM_DESC(mpegbufs, "number of mpeg buffers, range 2-32");
79
78static unsigned int mpeglines = 128; 80static unsigned int mpeglines = 128;
79module_param(mpeglines, int, 0644); 81module_param(mpeglines, int, 0644);
80MODULE_PARM_DESC(mpeglines, "number of lines in an MPEG buffer, range 2-32"); 82MODULE_PARM_DESC(mpeglines, "number of lines in an MPEG buffer, range 2-32");
83
81static unsigned int mpeglinesize = 512; 84static unsigned int mpeglinesize = 512;
82module_param(mpeglinesize, int, 0644); 85module_param(mpeglinesize, int, 0644);
83MODULE_PARM_DESC(mpeglinesize, 86MODULE_PARM_DESC(mpeglinesize,
@@ -86,10 +89,10 @@ MODULE_PARM_DESC(mpeglinesize,
86static unsigned int v4l_debug = 1; 89static unsigned int v4l_debug = 1;
87module_param(v4l_debug, int, 0644); 90module_param(v4l_debug, int, 0644);
88MODULE_PARM_DESC(v4l_debug, "enable V4L debug messages"); 91MODULE_PARM_DESC(v4l_debug, "enable V4L debug messages");
89struct cx231xx_dmaqueue *dma_qq; 92
90#define dprintk(level, fmt, arg...)\ 93#define dprintk(level, fmt, arg...)\
91 do { if (v4l_debug >= level) \ 94 do { if (v4l_debug >= level) \
92 printk(KERN_INFO "%s: " fmt, \ 95 pr_info("%s: " fmt, \
93 (dev) ? dev->name : "cx231xx[?]", ## arg); \ 96 (dev) ? dev->name : "cx231xx[?]", ## arg); \
94 } while (0) 97 } while (0)
95 98
@@ -131,11 +134,13 @@ static struct cx231xx_tvnorm cx231xx_tvnorms[] = {
131}; 134};
132 135
133/* ------------------------------------------------------------------ */ 136/* ------------------------------------------------------------------ */
137
134enum cx231xx_capture_type { 138enum cx231xx_capture_type {
135 CX231xx_MPEG_CAPTURE, 139 CX231xx_MPEG_CAPTURE,
136 CX231xx_RAW_CAPTURE, 140 CX231xx_RAW_CAPTURE,
137 CX231xx_RAW_PASSTHRU_CAPTURE 141 CX231xx_RAW_PASSTHRU_CAPTURE
138}; 142};
143
139enum cx231xx_capture_bits { 144enum cx231xx_capture_bits {
140 CX231xx_RAW_BITS_NONE = 0x00, 145 CX231xx_RAW_BITS_NONE = 0x00,
141 CX231xx_RAW_BITS_YUV_CAPTURE = 0x01, 146 CX231xx_RAW_BITS_YUV_CAPTURE = 0x01,
@@ -144,33 +149,40 @@ enum cx231xx_capture_bits {
144 CX231xx_RAW_BITS_PASSTHRU_CAPTURE = 0x08, 149 CX231xx_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
145 CX231xx_RAW_BITS_TO_HOST_CAPTURE = 0x10 150 CX231xx_RAW_BITS_TO_HOST_CAPTURE = 0x10
146}; 151};
152
147enum cx231xx_capture_end { 153enum cx231xx_capture_end {
148 CX231xx_END_AT_GOP, /* stop at the end of gop, generate irq */ 154 CX231xx_END_AT_GOP, /* stop at the end of gop, generate irq */
149 CX231xx_END_NOW, /* stop immediately, no irq */ 155 CX231xx_END_NOW, /* stop immediately, no irq */
150}; 156};
157
151enum cx231xx_framerate { 158enum cx231xx_framerate {
152 CX231xx_FRAMERATE_NTSC_30, /* NTSC: 30fps */ 159 CX231xx_FRAMERATE_NTSC_30, /* NTSC: 30fps */
153 CX231xx_FRAMERATE_PAL_25 /* PAL: 25fps */ 160 CX231xx_FRAMERATE_PAL_25 /* PAL: 25fps */
154}; 161};
162
155enum cx231xx_stream_port { 163enum cx231xx_stream_port {
156 CX231xx_OUTPUT_PORT_MEMORY, 164 CX231xx_OUTPUT_PORT_MEMORY,
157 CX231xx_OUTPUT_PORT_STREAMING, 165 CX231xx_OUTPUT_PORT_STREAMING,
158 CX231xx_OUTPUT_PORT_SERIAL 166 CX231xx_OUTPUT_PORT_SERIAL
159}; 167};
168
160enum cx231xx_data_xfer_status { 169enum cx231xx_data_xfer_status {
161 CX231xx_MORE_BUFFERS_FOLLOW, 170 CX231xx_MORE_BUFFERS_FOLLOW,
162 CX231xx_LAST_BUFFER, 171 CX231xx_LAST_BUFFER,
163}; 172};
173
164enum cx231xx_picture_mask { 174enum cx231xx_picture_mask {
165 CX231xx_PICTURE_MASK_NONE, 175 CX231xx_PICTURE_MASK_NONE,
166 CX231xx_PICTURE_MASK_I_FRAMES, 176 CX231xx_PICTURE_MASK_I_FRAMES,
167 CX231xx_PICTURE_MASK_I_P_FRAMES = 0x3, 177 CX231xx_PICTURE_MASK_I_P_FRAMES = 0x3,
168 CX231xx_PICTURE_MASK_ALL_FRAMES = 0x7, 178 CX231xx_PICTURE_MASK_ALL_FRAMES = 0x7,
169}; 179};
180
170enum cx231xx_vbi_mode_bits { 181enum cx231xx_vbi_mode_bits {
171 CX231xx_VBI_BITS_SLICED, 182 CX231xx_VBI_BITS_SLICED,
172 CX231xx_VBI_BITS_RAW, 183 CX231xx_VBI_BITS_RAW,
173}; 184};
185
174enum cx231xx_vbi_insertion_bits { 186enum cx231xx_vbi_insertion_bits {
175 CX231xx_VBI_BITS_INSERT_IN_XTENSION_USR_DATA, 187 CX231xx_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
176 CX231xx_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1, 188 CX231xx_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
@@ -178,56 +190,69 @@ enum cx231xx_vbi_insertion_bits {
178 CX231xx_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1, 190 CX231xx_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
179 CX231xx_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1, 191 CX231xx_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
180}; 192};
193
181enum cx231xx_dma_unit { 194enum cx231xx_dma_unit {
182 CX231xx_DMA_BYTES, 195 CX231xx_DMA_BYTES,
183 CX231xx_DMA_FRAMES, 196 CX231xx_DMA_FRAMES,
184}; 197};
198
185enum cx231xx_dma_transfer_status_bits { 199enum cx231xx_dma_transfer_status_bits {
186 CX231xx_DMA_TRANSFER_BITS_DONE = 0x01, 200 CX231xx_DMA_TRANSFER_BITS_DONE = 0x01,
187 CX231xx_DMA_TRANSFER_BITS_ERROR = 0x04, 201 CX231xx_DMA_TRANSFER_BITS_ERROR = 0x04,
188 CX231xx_DMA_TRANSFER_BITS_LL_ERROR = 0x10, 202 CX231xx_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
189}; 203};
204
190enum cx231xx_pause { 205enum cx231xx_pause {
191 CX231xx_PAUSE_ENCODING, 206 CX231xx_PAUSE_ENCODING,
192 CX231xx_RESUME_ENCODING, 207 CX231xx_RESUME_ENCODING,
193}; 208};
209
194enum cx231xx_copyright { 210enum cx231xx_copyright {
195 CX231xx_COPYRIGHT_OFF, 211 CX231xx_COPYRIGHT_OFF,
196 CX231xx_COPYRIGHT_ON, 212 CX231xx_COPYRIGHT_ON,
197}; 213};
214
198enum cx231xx_notification_type { 215enum cx231xx_notification_type {
199 CX231xx_NOTIFICATION_REFRESH, 216 CX231xx_NOTIFICATION_REFRESH,
200}; 217};
218
201enum cx231xx_notification_status { 219enum cx231xx_notification_status {
202 CX231xx_NOTIFICATION_OFF, 220 CX231xx_NOTIFICATION_OFF,
203 CX231xx_NOTIFICATION_ON, 221 CX231xx_NOTIFICATION_ON,
204}; 222};
223
205enum cx231xx_notification_mailbox { 224enum cx231xx_notification_mailbox {
206 CX231xx_NOTIFICATION_NO_MAILBOX = -1, 225 CX231xx_NOTIFICATION_NO_MAILBOX = -1,
207}; 226};
227
208enum cx231xx_field1_lines { 228enum cx231xx_field1_lines {
209 CX231xx_FIELD1_SAA7114 = 0x00EF, /* 239 */ 229 CX231xx_FIELD1_SAA7114 = 0x00EF, /* 239 */
210 CX231xx_FIELD1_SAA7115 = 0x00F0, /* 240 */ 230 CX231xx_FIELD1_SAA7115 = 0x00F0, /* 240 */
211 CX231xx_FIELD1_MICRONAS = 0x0105, /* 261 */ 231 CX231xx_FIELD1_MICRONAS = 0x0105, /* 261 */
212}; 232};
233
213enum cx231xx_field2_lines { 234enum cx231xx_field2_lines {
214 CX231xx_FIELD2_SAA7114 = 0x00EF, /* 239 */ 235 CX231xx_FIELD2_SAA7114 = 0x00EF, /* 239 */
215 CX231xx_FIELD2_SAA7115 = 0x00F0, /* 240 */ 236 CX231xx_FIELD2_SAA7115 = 0x00F0, /* 240 */
216 CX231xx_FIELD2_MICRONAS = 0x0106, /* 262 */ 237 CX231xx_FIELD2_MICRONAS = 0x0106, /* 262 */
217}; 238};
239
218enum cx231xx_custom_data_type { 240enum cx231xx_custom_data_type {
219 CX231xx_CUSTOM_EXTENSION_USR_DATA, 241 CX231xx_CUSTOM_EXTENSION_USR_DATA,
220 CX231xx_CUSTOM_PRIVATE_PACKET, 242 CX231xx_CUSTOM_PRIVATE_PACKET,
221}; 243};
244
222enum cx231xx_mute { 245enum cx231xx_mute {
223 CX231xx_UNMUTE, 246 CX231xx_UNMUTE,
224 CX231xx_MUTE, 247 CX231xx_MUTE,
225}; 248};
249
226enum cx231xx_mute_video_mask { 250enum cx231xx_mute_video_mask {
227 CX231xx_MUTE_VIDEO_V_MASK = 0x0000FF00, 251 CX231xx_MUTE_VIDEO_V_MASK = 0x0000FF00,
228 CX231xx_MUTE_VIDEO_U_MASK = 0x00FF0000, 252 CX231xx_MUTE_VIDEO_U_MASK = 0x00FF0000,
229 CX231xx_MUTE_VIDEO_Y_MASK = 0xFF000000, 253 CX231xx_MUTE_VIDEO_Y_MASK = 0xFF000000,
230}; 254};
255
231enum cx231xx_mute_video_shift { 256enum cx231xx_mute_video_shift {
232 CX231xx_MUTE_VIDEO_V_SHIFT = 8, 257 CX231xx_MUTE_VIDEO_V_SHIFT = 8,
233 CX231xx_MUTE_VIDEO_U_SHIFT = 16, 258 CX231xx_MUTE_VIDEO_U_SHIFT = 16,
@@ -296,41 +321,43 @@ enum cx231xx_mute_video_shift {
296 321
297 322
298#define CX23417_GPIO_MASK 0xFC0003FF 323#define CX23417_GPIO_MASK 0xFC0003FF
299static int setITVCReg(struct cx231xx *dev, u32 gpio_direction, u32 value) 324
325static int set_itvc_reg(struct cx231xx *dev, u32 gpio_direction, u32 value)
300{ 326{
301 int status = 0; 327 int status = 0;
302 u32 _gpio_direction = 0; 328 u32 _gpio_direction = 0;
303 329
304 _gpio_direction = _gpio_direction & CX23417_GPIO_MASK; 330 _gpio_direction = _gpio_direction & CX23417_GPIO_MASK;
305 _gpio_direction = _gpio_direction|gpio_direction; 331 _gpio_direction = _gpio_direction | gpio_direction;
306 status = cx231xx_send_gpio_cmd(dev, _gpio_direction, 332 status = cx231xx_send_gpio_cmd(dev, _gpio_direction,
307 (u8 *)&value, 4, 0, 0); 333 (u8 *)&value, 4, 0, 0);
308 return status; 334 return status;
309} 335}
310static int getITVCReg(struct cx231xx *dev, u32 gpio_direction, u32 *pValue) 336
337static int get_itvc_reg(struct cx231xx *dev, u32 gpio_direction, u32 *val_ptr)
311{ 338{
312 int status = 0; 339 int status = 0;
313 u32 _gpio_direction = 0; 340 u32 _gpio_direction = 0;
314 341
315 _gpio_direction = _gpio_direction & CX23417_GPIO_MASK; 342 _gpio_direction = _gpio_direction & CX23417_GPIO_MASK;
316 _gpio_direction = _gpio_direction|gpio_direction; 343 _gpio_direction = _gpio_direction | gpio_direction;
317 344
318 status = cx231xx_send_gpio_cmd(dev, _gpio_direction, 345 status = cx231xx_send_gpio_cmd(dev, _gpio_direction,
319 (u8 *)pValue, 4, 0, 1); 346 (u8 *)val_ptr, 4, 0, 1);
320 return status; 347 return status;
321} 348}
322 349
323static int waitForMciComplete(struct cx231xx *dev) 350static int wait_for_mci_complete(struct cx231xx *dev)
324{ 351{
325 u32 gpio; 352 u32 gpio;
326 u32 gpio_driection = 0; 353 u32 gpio_direction = 0;
327 u8 count = 0; 354 u8 count = 0;
328 getITVCReg(dev, gpio_driection, &gpio); 355 get_itvc_reg(dev, gpio_direction, &gpio);
329 356
330 while (!(gpio&0x020000)) { 357 while (!(gpio&0x020000)) {
331 msleep(10); 358 msleep(10);
332 359
333 getITVCReg(dev, gpio_driection, &gpio); 360 get_itvc_reg(dev, gpio_direction, &gpio);
334 361
335 if (count++ > 100) { 362 if (count++ > 100) {
336 dprintk(3, "ERROR: Timeout - gpio=%x\n", gpio); 363 dprintk(3, "ERROR: Timeout - gpio=%x\n", gpio);
@@ -345,57 +372,57 @@ static int mc417_register_write(struct cx231xx *dev, u16 address, u32 value)
345 u32 temp; 372 u32 temp;
346 int status = 0; 373 int status = 0;
347 374
348 temp = 0x82|MCI_REGISTER_DATA_BYTE0|((value&0x000000FF)<<8); 375 temp = 0x82 | MCI_REGISTER_DATA_BYTE0 | ((value & 0x000000FF) << 8);
349 temp = temp<<10; 376 temp = temp << 10;
350 status = setITVCReg(dev, ITVC_WRITE_DIR, temp); 377 status = set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
351 if (status < 0) 378 if (status < 0)
352 return status; 379 return status;
353 temp = temp|((0x05)<<10); 380 temp = temp | (0x05 << 10);
354 setITVCReg(dev, ITVC_WRITE_DIR, temp); 381 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
355 382
356 /*write data byte 1;*/ 383 /*write data byte 1;*/
357 temp = 0x82|MCI_REGISTER_DATA_BYTE1|(value&0x0000FF00); 384 temp = 0x82 | MCI_REGISTER_DATA_BYTE1 | (value & 0x0000FF00);
358 temp = temp<<10; 385 temp = temp << 10;
359 setITVCReg(dev, ITVC_WRITE_DIR, temp); 386 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
360 temp = temp|((0x05)<<10); 387 temp = temp | (0x05 << 10);
361 setITVCReg(dev, ITVC_WRITE_DIR, temp); 388 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
362 389
363 /*write data byte 2;*/ 390 /*write data byte 2;*/
364 temp = 0x82|MCI_REGISTER_DATA_BYTE2|((value&0x00FF0000)>>8); 391 temp = 0x82 | MCI_REGISTER_DATA_BYTE2 | ((value & 0x00FF0000) >> 8);
365 temp = temp<<10; 392 temp = temp << 10;
366 setITVCReg(dev, ITVC_WRITE_DIR, temp); 393 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
367 temp = temp|((0x05)<<10); 394 temp = temp | (0x05 << 10);
368 setITVCReg(dev, ITVC_WRITE_DIR, temp); 395 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
369 396
370 /*write data byte 3;*/ 397 /*write data byte 3;*/
371 temp = 0x82|MCI_REGISTER_DATA_BYTE3|((value&0xFF000000)>>16); 398 temp = 0x82 | MCI_REGISTER_DATA_BYTE3 | ((value & 0xFF000000) >> 16);
372 temp = temp<<10; 399 temp = temp << 10;
373 setITVCReg(dev, ITVC_WRITE_DIR, temp); 400 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
374 temp = temp|((0x05)<<10); 401 temp = temp | (0x05 << 10);
375 setITVCReg(dev, ITVC_WRITE_DIR, temp); 402 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
376 403
377 /*write address byte 0;*/ 404 /*write address byte 0;*/
378 temp = 0x82|MCI_REGISTER_ADDRESS_BYTE0|((address&0x000000FF)<<8); 405 temp = 0x82 | MCI_REGISTER_ADDRESS_BYTE0 | ((address & 0x000000FF) << 8);
379 temp = temp<<10; 406 temp = temp << 10;
380 setITVCReg(dev, ITVC_WRITE_DIR, temp); 407 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
381 temp = temp|((0x05)<<10); 408 temp = temp | (0x05 << 10);
382 setITVCReg(dev, ITVC_WRITE_DIR, temp); 409 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
383 410
384 /*write address byte 1;*/ 411 /*write address byte 1;*/
385 temp = 0x82|MCI_REGISTER_ADDRESS_BYTE1|(address&0x0000FF00); 412 temp = 0x82 | MCI_REGISTER_ADDRESS_BYTE1 | (address & 0x0000FF00);
386 temp = temp<<10; 413 temp = temp << 10;
387 setITVCReg(dev, ITVC_WRITE_DIR, temp); 414 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
388 temp = temp|((0x05)<<10); 415 temp = temp | (0x05 << 10);
389 setITVCReg(dev, ITVC_WRITE_DIR, temp); 416 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
390 417
391 /*Write that the mode is write.*/ 418 /*Write that the mode is write.*/
392 temp = 0x82 | MCI_REGISTER_MODE | MCI_MODE_REGISTER_WRITE; 419 temp = 0x82 | MCI_REGISTER_MODE | MCI_MODE_REGISTER_WRITE;
393 temp = temp<<10; 420 temp = temp << 10;
394 setITVCReg(dev, ITVC_WRITE_DIR, temp); 421 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
395 temp = temp|((0x05)<<10); 422 temp = temp | (0x05 << 10);
396 setITVCReg(dev, ITVC_WRITE_DIR, temp); 423 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
397 424
398 return waitForMciComplete(dev); 425 return wait_for_mci_complete(dev);
399} 426}
400 427
401static int mc417_register_read(struct cx231xx *dev, u16 address, u32 *value) 428static int mc417_register_read(struct cx231xx *dev, u16 address, u32 *value)
@@ -407,70 +434,68 @@ static int mc417_register_read(struct cx231xx *dev, u16 address, u32 *value)
407 434
408 temp = 0x82 | MCI_REGISTER_ADDRESS_BYTE0 | ((address & 0x00FF) << 8); 435 temp = 0x82 | MCI_REGISTER_ADDRESS_BYTE0 | ((address & 0x00FF) << 8);
409 temp = temp << 10; 436 temp = temp << 10;
410 setITVCReg(dev, ITVC_WRITE_DIR, temp); 437 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
411 temp = temp | ((0x05) << 10); 438 temp = temp | ((0x05) << 10);
412 setITVCReg(dev, ITVC_WRITE_DIR, temp); 439 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
413 440
414 /*write address byte 1;*/ 441 /*write address byte 1;*/
415 temp = 0x82 | MCI_REGISTER_ADDRESS_BYTE1 | (address & 0xFF00); 442 temp = 0x82 | MCI_REGISTER_ADDRESS_BYTE1 | (address & 0xFF00);
416 temp = temp << 10; 443 temp = temp << 10;
417 setITVCReg(dev, ITVC_WRITE_DIR, temp); 444 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
418 temp = temp | ((0x05) << 10); 445 temp = temp | ((0x05) << 10);
419 setITVCReg(dev, ITVC_WRITE_DIR, temp); 446 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
420 447
421 /*write that the mode is read;*/ 448 /*write that the mode is read;*/
422 temp = 0x82 | MCI_REGISTER_MODE | MCI_MODE_REGISTER_READ; 449 temp = 0x82 | MCI_REGISTER_MODE | MCI_MODE_REGISTER_READ;
423 temp = temp << 10; 450 temp = temp << 10;
424 setITVCReg(dev, ITVC_WRITE_DIR, temp); 451 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
425 temp = temp | ((0x05) << 10); 452 temp = temp | ((0x05) << 10);
426 setITVCReg(dev, ITVC_WRITE_DIR, temp); 453 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
427 454
428 /*wait for the MIRDY line to be asserted , 455 /*wait for the MIRDY line to be asserted ,
429 signalling that the read is done;*/ 456 signalling that the read is done;*/
430 ret = waitForMciComplete(dev); 457 ret = wait_for_mci_complete(dev);
431 458
432 /*switch the DATA- GPIO to input mode;*/ 459 /*switch the DATA- GPIO to input mode;*/
433 460
434 /*Read data byte 0;*/ 461 /*Read data byte 0;*/
435 temp = (0x82 | MCI_REGISTER_DATA_BYTE0) << 10; 462 temp = (0x82 | MCI_REGISTER_DATA_BYTE0) << 10;
436 setITVCReg(dev, ITVC_READ_DIR, temp); 463 set_itvc_reg(dev, ITVC_READ_DIR, temp);
437 temp = ((0x81 | MCI_REGISTER_DATA_BYTE0) << 10); 464 temp = ((0x81 | MCI_REGISTER_DATA_BYTE0) << 10);
438 setITVCReg(dev, ITVC_READ_DIR, temp); 465 set_itvc_reg(dev, ITVC_READ_DIR, temp);
439 getITVCReg(dev, ITVC_READ_DIR, &temp); 466 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
440 return_value |= ((temp & 0x03FC0000) >> 18); 467 return_value |= ((temp & 0x03FC0000) >> 18);
441 setITVCReg(dev, ITVC_READ_DIR, (0x87 << 10)); 468 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
442 469
443 /* Read data byte 1;*/ 470 /* Read data byte 1;*/
444 temp = (0x82 | MCI_REGISTER_DATA_BYTE1) << 10; 471 temp = (0x82 | MCI_REGISTER_DATA_BYTE1) << 10;
445 setITVCReg(dev, ITVC_READ_DIR, temp); 472 set_itvc_reg(dev, ITVC_READ_DIR, temp);
446 temp = ((0x81 | MCI_REGISTER_DATA_BYTE1) << 10); 473 temp = ((0x81 | MCI_REGISTER_DATA_BYTE1) << 10);
447 setITVCReg(dev, ITVC_READ_DIR, temp); 474 set_itvc_reg(dev, ITVC_READ_DIR, temp);
448 getITVCReg(dev, ITVC_READ_DIR, &temp); 475 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
449 476
450 return_value |= ((temp & 0x03FC0000) >> 10); 477 return_value |= ((temp & 0x03FC0000) >> 10);
451 setITVCReg(dev, ITVC_READ_DIR, (0x87 << 10)); 478 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
452 479
453 /*Read data byte 2;*/ 480 /*Read data byte 2;*/
454 temp = (0x82 | MCI_REGISTER_DATA_BYTE2) << 10; 481 temp = (0x82 | MCI_REGISTER_DATA_BYTE2) << 10;
455 setITVCReg(dev, ITVC_READ_DIR, temp); 482 set_itvc_reg(dev, ITVC_READ_DIR, temp);
456 temp = ((0x81 | MCI_REGISTER_DATA_BYTE2) << 10); 483 temp = ((0x81 | MCI_REGISTER_DATA_BYTE2) << 10);
457 setITVCReg(dev, ITVC_READ_DIR, temp); 484 set_itvc_reg(dev, ITVC_READ_DIR, temp);
458 getITVCReg(dev, ITVC_READ_DIR, &temp); 485 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
459 return_value |= ((temp & 0x03FC0000) >> 2); 486 return_value |= ((temp & 0x03FC0000) >> 2);
460 setITVCReg(dev, ITVC_READ_DIR, (0x87 << 10)); 487 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
461 488
462 /*Read data byte 3;*/ 489 /*Read data byte 3;*/
463 temp = (0x82 | MCI_REGISTER_DATA_BYTE3) << 10; 490 temp = (0x82 | MCI_REGISTER_DATA_BYTE3) << 10;
464 setITVCReg(dev, ITVC_READ_DIR, temp); 491 set_itvc_reg(dev, ITVC_READ_DIR, temp);
465 temp = ((0x81 | MCI_REGISTER_DATA_BYTE3) << 10); 492 temp = ((0x81 | MCI_REGISTER_DATA_BYTE3) << 10);
466 setITVCReg(dev, ITVC_READ_DIR, temp); 493 set_itvc_reg(dev, ITVC_READ_DIR, temp);
467 getITVCReg(dev, ITVC_READ_DIR, &temp); 494 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
468 return_value |= ((temp & 0x03FC0000) << 6); 495 return_value |= ((temp & 0x03FC0000) << 6);
469 setITVCReg(dev, ITVC_READ_DIR, (0x87 << 10)); 496 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
470 497
471 *value = return_value; 498 *value = return_value;
472
473
474 return ret; 499 return ret;
475} 500}
476 501
@@ -481,59 +506,59 @@ static int mc417_memory_write(struct cx231xx *dev, u32 address, u32 value)
481 u32 temp; 506 u32 temp;
482 int ret = 0; 507 int ret = 0;
483 508
484 temp = 0x82 | MCI_MEMORY_DATA_BYTE0|((value & 0x000000FF) << 8); 509 temp = 0x82 | MCI_MEMORY_DATA_BYTE0 | ((value & 0x000000FF) << 8);
485 temp = temp << 10; 510 temp = temp << 10;
486 ret = setITVCReg(dev, ITVC_WRITE_DIR, temp); 511 ret = set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
487 if (ret < 0) 512 if (ret < 0)
488 return ret; 513 return ret;
489 temp = temp | ((0x05) << 10); 514 temp = temp | (0x05 << 10);
490 setITVCReg(dev, ITVC_WRITE_DIR, temp); 515 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
491 516
492 /*write data byte 1;*/ 517 /*write data byte 1;*/
493 temp = 0x82 | MCI_MEMORY_DATA_BYTE1 | (value & 0x0000FF00); 518 temp = 0x82 | MCI_MEMORY_DATA_BYTE1 | (value & 0x0000FF00);
494 temp = temp << 10; 519 temp = temp << 10;
495 setITVCReg(dev, ITVC_WRITE_DIR, temp); 520 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
496 temp = temp | ((0x05) << 10); 521 temp = temp | (0x05 << 10);
497 setITVCReg(dev, ITVC_WRITE_DIR, temp); 522 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
498 523
499 /*write data byte 2;*/ 524 /*write data byte 2;*/
500 temp = 0x82|MCI_MEMORY_DATA_BYTE2|((value&0x00FF0000)>>8); 525 temp = 0x82 | MCI_MEMORY_DATA_BYTE2 | ((value & 0x00FF0000) >> 8);
501 temp = temp<<10; 526 temp = temp << 10;
502 setITVCReg(dev, ITVC_WRITE_DIR, temp); 527 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
503 temp = temp|((0x05)<<10); 528 temp = temp | (0x05 << 10);
504 setITVCReg(dev, ITVC_WRITE_DIR, temp); 529 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
505 530
506 /*write data byte 3;*/ 531 /*write data byte 3;*/
507 temp = 0x82|MCI_MEMORY_DATA_BYTE3|((value&0xFF000000)>>16); 532 temp = 0x82 | MCI_MEMORY_DATA_BYTE3 | ((value & 0xFF000000) >> 16);
508 temp = temp<<10; 533 temp = temp << 10;
509 setITVCReg(dev, ITVC_WRITE_DIR, temp); 534 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
510 temp = temp|((0x05)<<10); 535 temp = temp | (0x05 << 10);
511 setITVCReg(dev, ITVC_WRITE_DIR, temp); 536 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
512 537
513 /* write address byte 2;*/ 538 /* write address byte 2;*/
514 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE2 | MCI_MODE_MEMORY_WRITE | 539 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE2 | MCI_MODE_MEMORY_WRITE |
515 ((address & 0x003F0000)>>8); 540 ((address & 0x003F0000) >> 8);
516 temp = temp<<10; 541 temp = temp << 10;
517 setITVCReg(dev, ITVC_WRITE_DIR, temp); 542 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
518 temp = temp|((0x05)<<10); 543 temp = temp | (0x05 << 10);
519 setITVCReg(dev, ITVC_WRITE_DIR, temp); 544 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
520 545
521 /* write address byte 1;*/ 546 /* write address byte 1;*/
522 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE1 | (address & 0xFF00); 547 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE1 | (address & 0xFF00);
523 temp = temp<<10; 548 temp = temp << 10;
524 setITVCReg(dev, ITVC_WRITE_DIR, temp); 549 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
525 temp = temp|((0x05)<<10); 550 temp = temp | (0x05 << 10);
526 setITVCReg(dev, ITVC_WRITE_DIR, temp); 551 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
527 552
528 /* write address byte 0;*/ 553 /* write address byte 0;*/
529 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE0|((address & 0x00FF)<<8); 554 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE0 | ((address & 0x00FF) << 8);
530 temp = temp<<10; 555 temp = temp << 10;
531 setITVCReg(dev, ITVC_WRITE_DIR, temp); 556 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
532 temp = temp|((0x05)<<10); 557 temp = temp | (0x05 << 10);
533 setITVCReg(dev, ITVC_WRITE_DIR, temp); 558 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
534 559
535 /*wait for MIRDY line;*/ 560 /*wait for MIRDY line;*/
536 waitForMciComplete(dev); 561 wait_for_mci_complete(dev);
537 562
538 return 0; 563 return 0;
539} 564}
@@ -545,68 +570,68 @@ static int mc417_memory_read(struct cx231xx *dev, u32 address, u32 *value)
545 int ret = 0; 570 int ret = 0;
546 571
547 /*write address byte 2;*/ 572 /*write address byte 2;*/
548 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE2 | MCI_MODE_MEMORY_READ | 573 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE2 | MCI_MODE_MEMORY_READ |
549 ((address & 0x003F0000)>>8); 574 ((address & 0x003F0000) >> 8);
550 temp = temp<<10; 575 temp = temp << 10;
551 ret = setITVCReg(dev, ITVC_WRITE_DIR, temp); 576 ret = set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
552 if (ret < 0) 577 if (ret < 0)
553 return ret; 578 return ret;
554 temp = temp|((0x05)<<10); 579 temp = temp | (0x05 << 10);
555 setITVCReg(dev, ITVC_WRITE_DIR, temp); 580 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
556 581
557 /*write address byte 1*/ 582 /*write address byte 1*/
558 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE1 | (address & 0xFF00); 583 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE1 | (address & 0xFF00);
559 temp = temp<<10; 584 temp = temp << 10;
560 setITVCReg(dev, ITVC_WRITE_DIR, temp); 585 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
561 temp = temp|((0x05)<<10); 586 temp = temp | (0x05 << 10);
562 setITVCReg(dev, ITVC_WRITE_DIR, temp); 587 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
563 588
564 /*write address byte 0*/ 589 /*write address byte 0*/
565 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE0 | ((address & 0x00FF)<<8); 590 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE0 | ((address & 0x00FF) << 8);
566 temp = temp<<10; 591 temp = temp << 10;
567 setITVCReg(dev, ITVC_WRITE_DIR, temp); 592 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
568 temp = temp|((0x05)<<10); 593 temp = temp | (0x05 << 10);
569 setITVCReg(dev, ITVC_WRITE_DIR, temp); 594 set_itvc_reg(dev, ITVC_WRITE_DIR, temp);
570 595
571 /*Wait for MIRDY line*/ 596 /*Wait for MIRDY line*/
572 ret = waitForMciComplete(dev); 597 ret = wait_for_mci_complete(dev);
573 598
574 599
575 /*Read data byte 3;*/ 600 /*Read data byte 3;*/
576 temp = (0x82|MCI_MEMORY_DATA_BYTE3)<<10; 601 temp = (0x82 | MCI_MEMORY_DATA_BYTE3) << 10;
577 setITVCReg(dev, ITVC_READ_DIR, temp); 602 set_itvc_reg(dev, ITVC_READ_DIR, temp);
578 temp = ((0x81|MCI_MEMORY_DATA_BYTE3)<<10); 603 temp = ((0x81 | MCI_MEMORY_DATA_BYTE3) << 10);
579 setITVCReg(dev, ITVC_READ_DIR, temp); 604 set_itvc_reg(dev, ITVC_READ_DIR, temp);
580 getITVCReg(dev, ITVC_READ_DIR, &temp); 605 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
581 return_value |= ((temp&0x03FC0000)<<6); 606 return_value |= ((temp & 0x03FC0000) << 6);
582 setITVCReg(dev, ITVC_READ_DIR, (0x87<<10)); 607 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
583 608
584 /*Read data byte 2;*/ 609 /*Read data byte 2;*/
585 temp = (0x82|MCI_MEMORY_DATA_BYTE2)<<10; 610 temp = (0x82 | MCI_MEMORY_DATA_BYTE2) << 10;
586 setITVCReg(dev, ITVC_READ_DIR, temp); 611 set_itvc_reg(dev, ITVC_READ_DIR, temp);
587 temp = ((0x81|MCI_MEMORY_DATA_BYTE2)<<10); 612 temp = ((0x81 | MCI_MEMORY_DATA_BYTE2) << 10);
588 setITVCReg(dev, ITVC_READ_DIR, temp); 613 set_itvc_reg(dev, ITVC_READ_DIR, temp);
589 getITVCReg(dev, ITVC_READ_DIR, &temp); 614 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
590 return_value |= ((temp&0x03FC0000)>>2); 615 return_value |= ((temp & 0x03FC0000) >> 2);
591 setITVCReg(dev, ITVC_READ_DIR, (0x87<<10)); 616 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
592 617
593 /* Read data byte 1;*/ 618 /* Read data byte 1;*/
594 temp = (0x82|MCI_MEMORY_DATA_BYTE1)<<10; 619 temp = (0x82 | MCI_MEMORY_DATA_BYTE1) << 10;
595 setITVCReg(dev, ITVC_READ_DIR, temp); 620 set_itvc_reg(dev, ITVC_READ_DIR, temp);
596 temp = ((0x81|MCI_MEMORY_DATA_BYTE1)<<10); 621 temp = ((0x81 | MCI_MEMORY_DATA_BYTE1) << 10);
597 setITVCReg(dev, ITVC_READ_DIR, temp); 622 set_itvc_reg(dev, ITVC_READ_DIR, temp);
598 getITVCReg(dev, ITVC_READ_DIR, &temp); 623 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
599 return_value |= ((temp&0x03FC0000)>>10); 624 return_value |= ((temp & 0x03FC0000) >> 10);
600 setITVCReg(dev, ITVC_READ_DIR, (0x87<<10)); 625 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
601 626
602 /*Read data byte 0;*/ 627 /*Read data byte 0;*/
603 temp = (0x82|MCI_MEMORY_DATA_BYTE0)<<10; 628 temp = (0x82 | MCI_MEMORY_DATA_BYTE0) << 10;
604 setITVCReg(dev, ITVC_READ_DIR, temp); 629 set_itvc_reg(dev, ITVC_READ_DIR, temp);
605 temp = ((0x81|MCI_MEMORY_DATA_BYTE0)<<10); 630 temp = ((0x81 | MCI_MEMORY_DATA_BYTE0) << 10);
606 setITVCReg(dev, ITVC_READ_DIR, temp); 631 set_itvc_reg(dev, ITVC_READ_DIR, temp);
607 getITVCReg(dev, ITVC_READ_DIR, &temp); 632 get_itvc_reg(dev, ITVC_READ_DIR, &temp);
608 return_value |= ((temp&0x03FC0000)>>18); 633 return_value |= ((temp & 0x03FC0000) >> 18);
609 setITVCReg(dev, ITVC_READ_DIR, (0x87<<10)); 634 set_itvc_reg(dev, ITVC_READ_DIR, (0x87 << 10));
610 635
611 *value = return_value; 636 *value = return_value;
612 return ret; 637 return ret;
@@ -619,94 +644,91 @@ static char *cmd_to_str(int cmd)
619{ 644{
620 switch (cmd) { 645 switch (cmd) {
621 case CX2341X_ENC_PING_FW: 646 case CX2341X_ENC_PING_FW:
622 return "PING_FW"; 647 return "PING_FW";
623 case CX2341X_ENC_START_CAPTURE: 648 case CX2341X_ENC_START_CAPTURE:
624 return "START_CAPTURE"; 649 return "START_CAPTURE";
625 case CX2341X_ENC_STOP_CAPTURE: 650 case CX2341X_ENC_STOP_CAPTURE:
626 return "STOP_CAPTURE"; 651 return "STOP_CAPTURE";
627 case CX2341X_ENC_SET_AUDIO_ID: 652 case CX2341X_ENC_SET_AUDIO_ID:
628 return "SET_AUDIO_ID"; 653 return "SET_AUDIO_ID";
629 case CX2341X_ENC_SET_VIDEO_ID: 654 case CX2341X_ENC_SET_VIDEO_ID:
630 return "SET_VIDEO_ID"; 655 return "SET_VIDEO_ID";
631 case CX2341X_ENC_SET_PCR_ID: 656 case CX2341X_ENC_SET_PCR_ID:
632 return "SET_PCR_PID"; 657 return "SET_PCR_PID";
633 case CX2341X_ENC_SET_FRAME_RATE: 658 case CX2341X_ENC_SET_FRAME_RATE:
634 return "SET_FRAME_RATE"; 659 return "SET_FRAME_RATE";
635 case CX2341X_ENC_SET_FRAME_SIZE: 660 case CX2341X_ENC_SET_FRAME_SIZE:
636 return "SET_FRAME_SIZE"; 661 return "SET_FRAME_SIZE";
637 case CX2341X_ENC_SET_BIT_RATE: 662 case CX2341X_ENC_SET_BIT_RATE:
638 return "SET_BIT_RATE"; 663 return "SET_BIT_RATE";
639 case CX2341X_ENC_SET_GOP_PROPERTIES: 664 case CX2341X_ENC_SET_GOP_PROPERTIES:
640 return "SET_GOP_PROPERTIES"; 665 return "SET_GOP_PROPERTIES";
641 case CX2341X_ENC_SET_ASPECT_RATIO: 666 case CX2341X_ENC_SET_ASPECT_RATIO:
642 return "SET_ASPECT_RATIO"; 667 return "SET_ASPECT_RATIO";
643 case CX2341X_ENC_SET_DNR_FILTER_MODE: 668 case CX2341X_ENC_SET_DNR_FILTER_MODE:
644 return "SET_DNR_FILTER_PROPS"; 669 return "SET_DNR_FILTER_PROPS";
645 case CX2341X_ENC_SET_DNR_FILTER_PROPS: 670 case CX2341X_ENC_SET_DNR_FILTER_PROPS:
646 return "SET_DNR_FILTER_PROPS"; 671 return "SET_DNR_FILTER_PROPS";
647 case CX2341X_ENC_SET_CORING_LEVELS: 672 case CX2341X_ENC_SET_CORING_LEVELS:
648 return "SET_CORING_LEVELS"; 673 return "SET_CORING_LEVELS";
649 case CX2341X_ENC_SET_SPATIAL_FILTER_TYPE: 674 case CX2341X_ENC_SET_SPATIAL_FILTER_TYPE:
650 return "SET_SPATIAL_FILTER_TYPE"; 675 return "SET_SPATIAL_FILTER_TYPE";
651 case CX2341X_ENC_SET_VBI_LINE: 676 case CX2341X_ENC_SET_VBI_LINE:
652 return "SET_VBI_LINE"; 677 return "SET_VBI_LINE";
653 case CX2341X_ENC_SET_STREAM_TYPE: 678 case CX2341X_ENC_SET_STREAM_TYPE:
654 return "SET_STREAM_TYPE"; 679 return "SET_STREAM_TYPE";
655 case CX2341X_ENC_SET_OUTPUT_PORT: 680 case CX2341X_ENC_SET_OUTPUT_PORT:
656 return "SET_OUTPUT_PORT"; 681 return "SET_OUTPUT_PORT";
657 case CX2341X_ENC_SET_AUDIO_PROPERTIES: 682 case CX2341X_ENC_SET_AUDIO_PROPERTIES:
658 return "SET_AUDIO_PROPERTIES"; 683 return "SET_AUDIO_PROPERTIES";
659 case CX2341X_ENC_HALT_FW: 684 case CX2341X_ENC_HALT_FW:
660 return "HALT_FW"; 685 return "HALT_FW";
661 case CX2341X_ENC_GET_VERSION: 686 case CX2341X_ENC_GET_VERSION:
662 return "GET_VERSION"; 687 return "GET_VERSION";
663 case CX2341X_ENC_SET_GOP_CLOSURE: 688 case CX2341X_ENC_SET_GOP_CLOSURE:
664 return "SET_GOP_CLOSURE"; 689 return "SET_GOP_CLOSURE";
665 case CX2341X_ENC_GET_SEQ_END: 690 case CX2341X_ENC_GET_SEQ_END:
666 return "GET_SEQ_END"; 691 return "GET_SEQ_END";
667 case CX2341X_ENC_SET_PGM_INDEX_INFO: 692 case CX2341X_ENC_SET_PGM_INDEX_INFO:
668 return "SET_PGM_INDEX_INFO"; 693 return "SET_PGM_INDEX_INFO";
669 case CX2341X_ENC_SET_VBI_CONFIG: 694 case CX2341X_ENC_SET_VBI_CONFIG:
670 return "SET_VBI_CONFIG"; 695 return "SET_VBI_CONFIG";
671 case CX2341X_ENC_SET_DMA_BLOCK_SIZE: 696 case CX2341X_ENC_SET_DMA_BLOCK_SIZE:
672 return "SET_DMA_BLOCK_SIZE"; 697 return "SET_DMA_BLOCK_SIZE";
673 case CX2341X_ENC_GET_PREV_DMA_INFO_MB_10: 698 case CX2341X_ENC_GET_PREV_DMA_INFO_MB_10:
674 return "GET_PREV_DMA_INFO_MB_10"; 699 return "GET_PREV_DMA_INFO_MB_10";
675 case CX2341X_ENC_GET_PREV_DMA_INFO_MB_9: 700 case CX2341X_ENC_GET_PREV_DMA_INFO_MB_9:
676 return "GET_PREV_DMA_INFO_MB_9"; 701 return "GET_PREV_DMA_INFO_MB_9";
677 case CX2341X_ENC_SCHED_DMA_TO_HOST: 702 case CX2341X_ENC_SCHED_DMA_TO_HOST:
678 return "SCHED_DMA_TO_HOST"; 703 return "SCHED_DMA_TO_HOST";
679 case CX2341X_ENC_INITIALIZE_INPUT: 704 case CX2341X_ENC_INITIALIZE_INPUT:
680 return "INITIALIZE_INPUT"; 705 return "INITIALIZE_INPUT";
681 case CX2341X_ENC_SET_FRAME_DROP_RATE: 706 case CX2341X_ENC_SET_FRAME_DROP_RATE:
682 return "SET_FRAME_DROP_RATE"; 707 return "SET_FRAME_DROP_RATE";
683 case CX2341X_ENC_PAUSE_ENCODER: 708 case CX2341X_ENC_PAUSE_ENCODER:
684 return "PAUSE_ENCODER"; 709 return "PAUSE_ENCODER";
685 case CX2341X_ENC_REFRESH_INPUT: 710 case CX2341X_ENC_REFRESH_INPUT:
686 return "REFRESH_INPUT"; 711 return "REFRESH_INPUT";
687 case CX2341X_ENC_SET_COPYRIGHT: 712 case CX2341X_ENC_SET_COPYRIGHT:
688 return "SET_COPYRIGHT"; 713 return "SET_COPYRIGHT";
689 case CX2341X_ENC_SET_EVENT_NOTIFICATION: 714 case CX2341X_ENC_SET_EVENT_NOTIFICATION:
690 return "SET_EVENT_NOTIFICATION"; 715 return "SET_EVENT_NOTIFICATION";
691 case CX2341X_ENC_SET_NUM_VSYNC_LINES: 716 case CX2341X_ENC_SET_NUM_VSYNC_LINES:
692 return "SET_NUM_VSYNC_LINES"; 717 return "SET_NUM_VSYNC_LINES";
693 case CX2341X_ENC_SET_PLACEHOLDER: 718 case CX2341X_ENC_SET_PLACEHOLDER:
694 return "SET_PLACEHOLDER"; 719 return "SET_PLACEHOLDER";
695 case CX2341X_ENC_MUTE_VIDEO: 720 case CX2341X_ENC_MUTE_VIDEO:
696 return "MUTE_VIDEO"; 721 return "MUTE_VIDEO";
697 case CX2341X_ENC_MUTE_AUDIO: 722 case CX2341X_ENC_MUTE_AUDIO:
698 return "MUTE_AUDIO"; 723 return "MUTE_AUDIO";
699 case CX2341X_ENC_MISC: 724 case CX2341X_ENC_MISC:
700 return "MISC"; 725 return "MISC";
701 default: 726 default:
702 return "UNKNOWN"; 727 return "UNKNOWN";
703 } 728 }
704} 729}
705 730
706static int cx231xx_mbox_func(void *priv, 731static int cx231xx_mbox_func(void *priv, u32 command, int in, int out,
707 u32 command,
708 int in,
709 int out,
710 u32 data[CX2341X_MBOX_MAX_DATA]) 732 u32 data[CX2341X_MBOX_MAX_DATA])
711{ 733{
712 struct cx231xx *dev = priv; 734 struct cx231xx *dev = priv;
@@ -721,11 +743,9 @@ static int cx231xx_mbox_func(void *priv,
721 without side effects */ 743 without side effects */
722 mc417_memory_read(dev, dev->cx23417_mailbox - 4, &value); 744 mc417_memory_read(dev, dev->cx23417_mailbox - 4, &value);
723 if (value != 0x12345678) { 745 if (value != 0x12345678) {
724 dprintk(3, 746 dprintk(3, "Firmware and/or mailbox pointer not initialized or corrupted, signature = 0x%x, cmd = %s\n",
725 "Firmware and/or mailbox pointer not initialized " 747 value, cmd_to_str(command));
726 "or corrupted, signature = 0x%x, cmd = %s\n", value, 748 return -EIO;
727 cmd_to_str(command));
728 return -1;
729 } 749 }
730 750
731 /* This read looks at 32 bits, but flag is only 8 bits. 751 /* This read looks at 32 bits, but flag is only 8 bits.
@@ -733,9 +753,9 @@ static int cx231xx_mbox_func(void *priv,
733 */ 753 */
734 mc417_memory_read(dev, dev->cx23417_mailbox, &flag); 754 mc417_memory_read(dev, dev->cx23417_mailbox, &flag);
735 if (flag) { 755 if (flag) {
736 dprintk(3, "ERROR: Mailbox appears to be in use " 756 dprintk(3, "ERROR: Mailbox appears to be in use (%x), cmd = %s\n",
737 "(%x), cmd = %s\n", flag, cmd_to_str(command)); 757 flag, cmd_to_str(command));
738 return -1; 758 return -EBUSY;
739 } 759 }
740 760
741 flag |= 1; /* tell 'em we're working on it */ 761 flag |= 1; /* tell 'em we're working on it */
@@ -764,7 +784,7 @@ static int cx231xx_mbox_func(void *priv,
764 break; 784 break;
765 if (time_after(jiffies, timeout)) { 785 if (time_after(jiffies, timeout)) {
766 dprintk(3, "ERROR: API Mailbox timeout\n"); 786 dprintk(3, "ERROR: API Mailbox timeout\n");
767 return -1; 787 return -EIO;
768 } 788 }
769 udelay(10); 789 udelay(10);
770 } 790 }
@@ -781,17 +801,14 @@ static int cx231xx_mbox_func(void *priv,
781 flag = 0; 801 flag = 0;
782 mc417_memory_write(dev, dev->cx23417_mailbox, flag); 802 mc417_memory_write(dev, dev->cx23417_mailbox, flag);
783 803
784 return retval; 804 return 0;
785} 805}
786 806
787/* We don't need to call the API often, so using just one 807/* We don't need to call the API often, so using just one
788 * mailbox will probably suffice 808 * mailbox will probably suffice
789 */ 809 */
790static int cx231xx_api_cmd(struct cx231xx *dev, 810static int cx231xx_api_cmd(struct cx231xx *dev, u32 command,
791 u32 command, 811 u32 inputcnt, u32 outputcnt, ...)
792 u32 inputcnt,
793 u32 outputcnt,
794 ...)
795{ 812{
796 u32 data[CX2341X_MBOX_MAX_DATA]; 813 u32 data[CX2341X_MBOX_MAX_DATA];
797 va_list vargs; 814 va_list vargs;
@@ -813,6 +830,7 @@ static int cx231xx_api_cmd(struct cx231xx *dev,
813 return err; 830 return err;
814} 831}
815 832
833
816static int cx231xx_find_mailbox(struct cx231xx *dev) 834static int cx231xx_find_mailbox(struct cx231xx *dev)
817{ 835{
818 u32 signature[4] = { 836 u32 signature[4] = {
@@ -834,81 +852,80 @@ static int cx231xx_find_mailbox(struct cx231xx *dev)
834 else 852 else
835 signaturecnt = 0; 853 signaturecnt = 0;
836 if (4 == signaturecnt) { 854 if (4 == signaturecnt) {
837 dprintk(1, "Mailbox signature found at 0x%x\n", i+1); 855 dprintk(1, "Mailbox signature found at 0x%x\n", i + 1);
838 return i+1; 856 return i + 1;
839 } 857 }
840 } 858 }
841 dprintk(3, "Mailbox signature values not found!\n"); 859 dprintk(3, "Mailbox signature values not found!\n");
842 return -1; 860 return -1;
843} 861}
844 862
845static void mciWriteMemoryToGPIO(struct cx231xx *dev, u32 address, u32 value, 863static void mci_write_memory_to_gpio(struct cx231xx *dev, u32 address, u32 value,
846 u32 *p_fw_image) 864 u32 *p_fw_image)
847{ 865{
848
849 u32 temp = 0; 866 u32 temp = 0;
850 int i = 0; 867 int i = 0;
851 868
852 temp = 0x82|MCI_MEMORY_DATA_BYTE0|((value&0x000000FF)<<8); 869 temp = 0x82 | MCI_MEMORY_DATA_BYTE0 | ((value & 0x000000FF) << 8);
853 temp = temp<<10; 870 temp = temp << 10;
854 *p_fw_image = temp; 871 *p_fw_image = temp;
855 p_fw_image++; 872 p_fw_image++;
856 temp = temp|((0x05)<<10); 873 temp = temp | (0x05 << 10);
857 *p_fw_image = temp; 874 *p_fw_image = temp;
858 p_fw_image++; 875 p_fw_image++;
859 876
860 /*write data byte 1;*/ 877 /*write data byte 1;*/
861 temp = 0x82|MCI_MEMORY_DATA_BYTE1|(value&0x0000FF00); 878 temp = 0x82 | MCI_MEMORY_DATA_BYTE1 | (value & 0x0000FF00);
862 temp = temp<<10; 879 temp = temp << 10;
863 *p_fw_image = temp; 880 *p_fw_image = temp;
864 p_fw_image++; 881 p_fw_image++;
865 temp = temp|((0x05)<<10); 882 temp = temp | (0x05 << 10);
866 *p_fw_image = temp; 883 *p_fw_image = temp;
867 p_fw_image++; 884 p_fw_image++;
868 885
869 /*write data byte 2;*/ 886 /*write data byte 2;*/
870 temp = 0x82|MCI_MEMORY_DATA_BYTE2|((value&0x00FF0000)>>8); 887 temp = 0x82 | MCI_MEMORY_DATA_BYTE2 | ((value & 0x00FF0000) >> 8);
871 temp = temp<<10; 888 temp = temp << 10;
872 *p_fw_image = temp; 889 *p_fw_image = temp;
873 p_fw_image++; 890 p_fw_image++;
874 temp = temp|((0x05)<<10); 891 temp = temp | (0x05 << 10);
875 *p_fw_image = temp; 892 *p_fw_image = temp;
876 p_fw_image++; 893 p_fw_image++;
877 894
878 /*write data byte 3;*/ 895 /*write data byte 3;*/
879 temp = 0x82|MCI_MEMORY_DATA_BYTE3|((value&0xFF000000)>>16); 896 temp = 0x82 | MCI_MEMORY_DATA_BYTE3 | ((value & 0xFF000000) >> 16);
880 temp = temp<<10; 897 temp = temp << 10;
881 *p_fw_image = temp; 898 *p_fw_image = temp;
882 p_fw_image++; 899 p_fw_image++;
883 temp = temp|((0x05)<<10); 900 temp = temp | (0x05 << 10);
884 *p_fw_image = temp; 901 *p_fw_image = temp;
885 p_fw_image++; 902 p_fw_image++;
886 903
887 /* write address byte 2;*/ 904 /* write address byte 2;*/
888 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE2 | MCI_MODE_MEMORY_WRITE | 905 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE2 | MCI_MODE_MEMORY_WRITE |
889 ((address & 0x003F0000)>>8); 906 ((address & 0x003F0000) >> 8);
890 temp = temp<<10; 907 temp = temp << 10;
891 *p_fw_image = temp; 908 *p_fw_image = temp;
892 p_fw_image++; 909 p_fw_image++;
893 temp = temp|((0x05)<<10); 910 temp = temp | (0x05 << 10);
894 *p_fw_image = temp; 911 *p_fw_image = temp;
895 p_fw_image++; 912 p_fw_image++;
896 913
897 /* write address byte 1;*/ 914 /* write address byte 1;*/
898 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE1 | (address & 0xFF00); 915 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE1 | (address & 0xFF00);
899 temp = temp<<10; 916 temp = temp << 10;
900 *p_fw_image = temp; 917 *p_fw_image = temp;
901 p_fw_image++; 918 p_fw_image++;
902 temp = temp|((0x05)<<10); 919 temp = temp | (0x05 << 10);
903 *p_fw_image = temp; 920 *p_fw_image = temp;
904 p_fw_image++; 921 p_fw_image++;
905 922
906 /* write address byte 0;*/ 923 /* write address byte 0;*/
907 temp = 0x82|MCI_MEMORY_ADDRESS_BYTE0|((address & 0x00FF)<<8); 924 temp = 0x82 | MCI_MEMORY_ADDRESS_BYTE0 | ((address & 0x00FF) << 8);
908 temp = temp<<10; 925 temp = temp << 10;
909 *p_fw_image = temp; 926 *p_fw_image = temp;
910 p_fw_image++; 927 p_fw_image++;
911 temp = temp|((0x05)<<10); 928 temp = temp | (0x05 << 10);
912 *p_fw_image = temp; 929 *p_fw_image = temp;
913 p_fw_image++; 930 p_fw_image++;
914 931
@@ -971,8 +988,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
971 IVTV_REG_APU, 0); 988 IVTV_REG_APU, 0);
972 989
973 if (retval != 0) { 990 if (retval != 0) {
974 printk(KERN_ERR "%s: Error with mc417_register_write\n", 991 pr_err("%s: Error with mc417_register_write\n", __func__);
975 __func__);
976 return -1; 992 return -1;
977 } 993 }
978 994
@@ -980,25 +996,21 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
980 &dev->udev->dev); 996 &dev->udev->dev);
981 997
982 if (retval != 0) { 998 if (retval != 0) {
983 printk(KERN_ERR 999 pr_err("ERROR: Hotplug firmware request failed (%s).\n",
984 "ERROR: Hotplug firmware request failed (%s).\n",
985 CX231xx_FIRM_IMAGE_NAME); 1000 CX231xx_FIRM_IMAGE_NAME);
986 printk(KERN_ERR "Please fix your hotplug setup, the board will " 1001 pr_err("Please fix your hotplug setup, the board will not work without firmware loaded!\n");
987 "not work without firmware loaded!\n");
988 return -1; 1002 return -1;
989 } 1003 }
990 1004
991 if (firmware->size != CX231xx_FIRM_IMAGE_SIZE) { 1005 if (firmware->size != CX231xx_FIRM_IMAGE_SIZE) {
992 printk(KERN_ERR "ERROR: Firmware size mismatch " 1006 pr_err("ERROR: Firmware size mismatch (have %zd, expected %d)\n",
993 "(have %zd, expected %d)\n",
994 firmware->size, CX231xx_FIRM_IMAGE_SIZE); 1007 firmware->size, CX231xx_FIRM_IMAGE_SIZE);
995 release_firmware(firmware); 1008 release_firmware(firmware);
996 return -1; 1009 return -1;
997 } 1010 }
998 1011
999 if (0 != memcmp(firmware->data, magic, 8)) { 1012 if (0 != memcmp(firmware->data, magic, 8)) {
1000 printk(KERN_ERR 1013 pr_err("ERROR: Firmware magic mismatch, wrong file?\n");
1001 "ERROR: Firmware magic mismatch, wrong file?\n");
1002 release_firmware(firmware); 1014 release_firmware(firmware);
1003 return -1; 1015 return -1;
1004 } 1016 }
@@ -1013,7 +1025,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
1013 transfer_size += 4) { 1025 transfer_size += 4) {
1014 fw_data = *p_fw_data; 1026 fw_data = *p_fw_data;
1015 1027
1016 mciWriteMemoryToGPIO(dev, address, fw_data, p_current_fw); 1028 mci_write_memory_to_gpio(dev, address, fw_data, p_current_fw);
1017 address = address + 1; 1029 address = address + 1;
1018 p_current_fw += 20; 1030 p_current_fw += 20;
1019 p_fw_data += 1; 1031 p_fw_data += 1;
@@ -1045,7 +1057,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
1045 retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS, 1057 retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS,
1046 IVTV_CMD_HW_BLOCKS_RST); 1058 IVTV_CMD_HW_BLOCKS_RST);
1047 if (retval < 0) { 1059 if (retval < 0) {
1048 printk(KERN_ERR "%s: Error with mc417_register_write\n", 1060 pr_err("%s: Error with mc417_register_write\n",
1049 __func__); 1061 __func__);
1050 return retval; 1062 return retval;
1051 } 1063 }
@@ -1057,7 +1069,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
1057 retval |= mc417_register_write(dev, IVTV_REG_VPU, value & 0xFFFFFFE8); 1069 retval |= mc417_register_write(dev, IVTV_REG_VPU, value & 0xFFFFFFE8);
1058 1070
1059 if (retval < 0) { 1071 if (retval < 0) {
1060 printk(KERN_ERR "%s: Error with mc417_register_write\n", 1072 pr_err("%s: Error with mc417_register_write\n",
1061 __func__); 1073 __func__);
1062 return retval; 1074 return retval;
1063 } 1075 }
@@ -1082,10 +1094,10 @@ static void cx231xx_codec_settings(struct cx231xx *dev)
1082 cx231xx_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, 1094 cx231xx_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
1083 dev->ts1.height, dev->ts1.width); 1095 dev->ts1.height, dev->ts1.width);
1084 1096
1085 dev->mpeg_params.width = dev->ts1.width; 1097 dev->mpeg_ctrl_handler.width = dev->ts1.width;
1086 dev->mpeg_params.height = dev->ts1.height; 1098 dev->mpeg_ctrl_handler.height = dev->ts1.height;
1087 1099
1088 cx2341x_update(dev, cx231xx_mbox_func, NULL, &dev->mpeg_params); 1100 cx2341x_handler_setup(&dev->mpeg_ctrl_handler);
1089 1101
1090 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 3, 1); 1102 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 3, 1);
1091 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 4, 1); 1103 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 4, 1);
@@ -1105,27 +1117,25 @@ static int cx231xx_initialize_codec(struct cx231xx *dev)
1105 dprintk(2, "%s() PING OK\n", __func__); 1117 dprintk(2, "%s() PING OK\n", __func__);
1106 retval = cx231xx_load_firmware(dev); 1118 retval = cx231xx_load_firmware(dev);
1107 if (retval < 0) { 1119 if (retval < 0) {
1108 printk(KERN_ERR "%s() f/w load failed\n", __func__); 1120 pr_err("%s() f/w load failed\n", __func__);
1109 return retval; 1121 return retval;
1110 } 1122 }
1111 retval = cx231xx_find_mailbox(dev); 1123 retval = cx231xx_find_mailbox(dev);
1112 if (retval < 0) { 1124 if (retval < 0) {
1113 printk(KERN_ERR "%s() mailbox < 0, error\n", 1125 pr_err("%s() mailbox < 0, error\n",
1114 __func__); 1126 __func__);
1115 return -1; 1127 return -1;
1116 } 1128 }
1117 dev->cx23417_mailbox = retval; 1129 dev->cx23417_mailbox = retval;
1118 retval = cx231xx_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); 1130 retval = cx231xx_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0);
1119 if (retval < 0) { 1131 if (retval < 0) {
1120 printk(KERN_ERR 1132 pr_err("ERROR: cx23417 firmware ping failed!\n");
1121 "ERROR: cx23417 firmware ping failed!\n");
1122 return -1; 1133 return -1;
1123 } 1134 }
1124 retval = cx231xx_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1, 1135 retval = cx231xx_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1,
1125 &version); 1136 &version);
1126 if (retval < 0) { 1137 if (retval < 0) {
1127 printk(KERN_ERR "ERROR: cx23417 firmware get encoder :" 1138 pr_err("ERROR: cx23417 firmware get encoder: version failed!\n");
1128 "version failed!\n");
1129 return -1; 1139 return -1;
1130 } 1140 }
1131 dprintk(1, "cx23417 firmware version is 0x%08x\n", version); 1141 dprintk(1, "cx23417 firmware version is 0x%08x\n", version);
@@ -1134,7 +1144,7 @@ static int cx231xx_initialize_codec(struct cx231xx *dev)
1134 1144
1135 for (i = 0; i < 1; i++) { 1145 for (i = 0; i < 1; i++) {
1136 retval = mc417_register_read(dev, 0x20f8, &val); 1146 retval = mc417_register_read(dev, 0x20f8, &val);
1137 dprintk(3, "***before enable656() VIM Capture Lines =%d ***\n", 1147 dprintk(3, "***before enable656() VIM Capture Lines = %d ***\n",
1138 val); 1148 val);
1139 if (retval < 0) 1149 if (retval < 0)
1140 return retval; 1150 return retval;
@@ -1202,7 +1212,7 @@ static int cx231xx_initialize_codec(struct cx231xx *dev)
1202 1212
1203 for (i = 0; i < 1; i++) { 1213 for (i = 0; i < 1; i++) {
1204 mc417_register_read(dev, 0x20f8, &val); 1214 mc417_register_read(dev, 0x20f8, &val);
1205 dprintk(3, "***VIM Capture Lines =%d ***\n", val); 1215 dprintk(3, "***VIM Capture Lines =%d ***\n", val);
1206 } 1216 }
1207 1217
1208 return 0; 1218 return 0;
@@ -1223,6 +1233,7 @@ static int bb_buf_setup(struct videobuf_queue *q,
1223 1233
1224 return 0; 1234 return 0;
1225} 1235}
1236
1226static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf) 1237static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
1227{ 1238{
1228 struct cx231xx_fh *fh = vq->priv_data; 1239 struct cx231xx_fh *fh = vq->priv_data;
@@ -1249,91 +1260,85 @@ static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
1249static void buffer_copy(struct cx231xx *dev, char *data, int len, struct urb *urb, 1260static void buffer_copy(struct cx231xx *dev, char *data, int len, struct urb *urb,
1250 struct cx231xx_dmaqueue *dma_q) 1261 struct cx231xx_dmaqueue *dma_q)
1251{ 1262{
1252 void *vbuf; 1263 void *vbuf;
1253 struct cx231xx_buffer *buf; 1264 struct cx231xx_buffer *buf;
1254 u32 tail_data = 0; 1265 u32 tail_data = 0;
1255 char *p_data; 1266 char *p_data;
1256
1257 if (dma_q->mpeg_buffer_done == 0) {
1258 if (list_empty(&dma_q->active))
1259 return;
1260
1261 buf = list_entry(dma_q->active.next,
1262 struct cx231xx_buffer, vb.queue);
1263 dev->video_mode.isoc_ctl.buf = buf;
1264 dma_q->mpeg_buffer_done = 1;
1265 }
1266 /* Fill buffer */
1267 buf = dev->video_mode.isoc_ctl.buf;
1268 vbuf = videobuf_to_vmalloc(&buf->vb);
1269
1270 if ((dma_q->mpeg_buffer_completed+len) <
1271 mpeglines*mpeglinesize) {
1272 if (dma_q->add_ps_package_head ==
1273 CX231XX_NEED_ADD_PS_PACKAGE_HEAD) {
1274 memcpy(vbuf+dma_q->mpeg_buffer_completed,
1275 dma_q->ps_head, 3);
1276 dma_q->mpeg_buffer_completed =
1277 dma_q->mpeg_buffer_completed + 3;
1278 dma_q->add_ps_package_head =
1279 CX231XX_NONEED_PS_PACKAGE_HEAD;
1280 }
1281 memcpy(vbuf+dma_q->mpeg_buffer_completed, data, len);
1282 dma_q->mpeg_buffer_completed =
1283 dma_q->mpeg_buffer_completed + len;
1284 } else {
1285 dma_q->mpeg_buffer_done = 0;
1286
1287 tail_data =
1288 mpeglines*mpeglinesize - dma_q->mpeg_buffer_completed;
1289 memcpy(vbuf+dma_q->mpeg_buffer_completed,
1290 data, tail_data);
1291
1292 buf->vb.state = VIDEOBUF_DONE;
1293 buf->vb.field_count++;
1294 v4l2_get_timestamp(&buf->vb.ts);
1295 list_del(&buf->vb.queue);
1296 wake_up(&buf->vb.done);
1297 dma_q->mpeg_buffer_completed = 0;
1298
1299 if (len - tail_data > 0) {
1300 p_data = data + tail_data;
1301 dma_q->left_data_count = len - tail_data;
1302 memcpy(dma_q->p_left_data,
1303 p_data, len - tail_data);
1304 }
1305
1306 }
1307
1308 return;
1309}
1310
1311static void buffer_filled(char *data, int len, struct urb *urb,
1312 struct cx231xx_dmaqueue *dma_q)
1313{
1314 void *vbuf;
1315 struct cx231xx_buffer *buf;
1316 1267
1268 if (dma_q->mpeg_buffer_done == 0) {
1317 if (list_empty(&dma_q->active)) 1269 if (list_empty(&dma_q->active))
1318 return; 1270 return;
1319 1271
1320
1321 buf = list_entry(dma_q->active.next, 1272 buf = list_entry(dma_q->active.next,
1322 struct cx231xx_buffer, vb.queue); 1273 struct cx231xx_buffer, vb.queue);
1274 dev->video_mode.isoc_ctl.buf = buf;
1275 dma_q->mpeg_buffer_done = 1;
1276 }
1277 /* Fill buffer */
1278 buf = dev->video_mode.isoc_ctl.buf;
1279 vbuf = videobuf_to_vmalloc(&buf->vb);
1280
1281 if ((dma_q->mpeg_buffer_completed+len) <
1282 mpeglines*mpeglinesize) {
1283 if (dma_q->add_ps_package_head ==
1284 CX231XX_NEED_ADD_PS_PACKAGE_HEAD) {
1285 memcpy(vbuf+dma_q->mpeg_buffer_completed,
1286 dma_q->ps_head, 3);
1287 dma_q->mpeg_buffer_completed =
1288 dma_q->mpeg_buffer_completed + 3;
1289 dma_q->add_ps_package_head =
1290 CX231XX_NONEED_PS_PACKAGE_HEAD;
1291 }
1292 memcpy(vbuf+dma_q->mpeg_buffer_completed, data, len);
1293 dma_q->mpeg_buffer_completed =
1294 dma_q->mpeg_buffer_completed + len;
1295 } else {
1296 dma_q->mpeg_buffer_done = 0;
1323 1297
1298 tail_data =
1299 mpeglines*mpeglinesize - dma_q->mpeg_buffer_completed;
1300 memcpy(vbuf+dma_q->mpeg_buffer_completed,
1301 data, tail_data);
1324 1302
1325 /* Fill buffer */
1326 vbuf = videobuf_to_vmalloc(&buf->vb);
1327 memcpy(vbuf, data, len);
1328 buf->vb.state = VIDEOBUF_DONE; 1303 buf->vb.state = VIDEOBUF_DONE;
1329 buf->vb.field_count++; 1304 buf->vb.field_count++;
1330 v4l2_get_timestamp(&buf->vb.ts); 1305 v4l2_get_timestamp(&buf->vb.ts);
1331 list_del(&buf->vb.queue); 1306 list_del(&buf->vb.queue);
1332 wake_up(&buf->vb.done); 1307 wake_up(&buf->vb.done);
1308 dma_q->mpeg_buffer_completed = 0;
1333 1309
1334 return; 1310 if (len - tail_data > 0) {
1311 p_data = data + tail_data;
1312 dma_q->left_data_count = len - tail_data;
1313 memcpy(dma_q->p_left_data,
1314 p_data, len - tail_data);
1315 }
1316 }
1335} 1317}
1336static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb) 1318
1319static void buffer_filled(char *data, int len, struct urb *urb,
1320 struct cx231xx_dmaqueue *dma_q)
1321{
1322 void *vbuf;
1323 struct cx231xx_buffer *buf;
1324
1325 if (list_empty(&dma_q->active))
1326 return;
1327
1328 buf = list_entry(dma_q->active.next,
1329 struct cx231xx_buffer, vb.queue);
1330
1331 /* Fill buffer */
1332 vbuf = videobuf_to_vmalloc(&buf->vb);
1333 memcpy(vbuf, data, len);
1334 buf->vb.state = VIDEOBUF_DONE;
1335 buf->vb.field_count++;
1336 v4l2_get_timestamp(&buf->vb.ts);
1337 list_del(&buf->vb.queue);
1338 wake_up(&buf->vb.done);
1339}
1340
1341static int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
1337{ 1342{
1338 struct cx231xx_dmaqueue *dma_q = urb->context; 1343 struct cx231xx_dmaqueue *dma_q = urb->context;
1339 unsigned char *p_buffer; 1344 unsigned char *p_buffer;
@@ -1358,11 +1363,9 @@ static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
1358 1363
1359 return 0; 1364 return 0;
1360} 1365}
1361static inline int cx231xx_bulk_copy(struct cx231xx *dev, struct urb *urb)
1362{
1363 1366
1364 /*char *outp;*/ 1367static int cx231xx_bulk_copy(struct cx231xx *dev, struct urb *urb)
1365 /*struct cx231xx_buffer *buf;*/ 1368{
1366 struct cx231xx_dmaqueue *dma_q = urb->context; 1369 struct cx231xx_dmaqueue *dma_q = urb->context;
1367 unsigned char *p_buffer, *buffer; 1370 unsigned char *p_buffer, *buffer;
1368 u32 buffer_size = 0; 1371 u32 buffer_size = 0;
@@ -1393,8 +1396,6 @@ static int bb_buf_prepare(struct videobuf_queue *q,
1393 int rc = 0, urb_init = 0; 1396 int rc = 0, urb_init = 0;
1394 int size = fh->dev->ts1.ts_packet_size * fh->dev->ts1.ts_packet_count; 1397 int size = fh->dev->ts1.ts_packet_size * fh->dev->ts1.ts_packet_count;
1395 1398
1396 dma_qq = &dev->video_mode.vidq;
1397
1398 if (0 != buf->vb.baddr && buf->vb.bsize < size) 1399 if (0 != buf->vb.baddr && buf->vb.bsize < size)
1399 return -EINVAL; 1400 return -EINVAL;
1400 buf->vb.width = fh->dev->ts1.ts_packet_size; 1401 buf->vb.width = fh->dev->ts1.ts_packet_size;
@@ -1482,36 +1483,6 @@ static struct videobuf_queue_ops cx231xx_qops = {
1482 1483
1483/* ------------------------------------------------------------------ */ 1484/* ------------------------------------------------------------------ */
1484 1485
1485static const u32 *ctrl_classes[] = {
1486 cx2341x_mpeg_ctrls,
1487 NULL
1488};
1489
1490static int cx231xx_queryctrl(struct cx231xx *dev,
1491 struct v4l2_queryctrl *qctrl)
1492{
1493 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1494 if (qctrl->id == 0)
1495 return -EINVAL;
1496
1497 /* MPEG V4L2 controls */
1498 if (cx2341x_ctrl_query(&dev->mpeg_params, qctrl))
1499 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
1500
1501 return 0;
1502}
1503
1504static int cx231xx_querymenu(struct cx231xx *dev,
1505 struct v4l2_querymenu *qmenu)
1506{
1507 struct v4l2_queryctrl qctrl;
1508
1509 qctrl.id = qmenu->id;
1510 cx231xx_queryctrl(dev, &qctrl);
1511 return v4l2_ctrl_query_menu(qmenu, &qctrl,
1512 cx2341x_ctrl_get_menu(&dev->mpeg_params, qmenu->id));
1513}
1514
1515static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm) 1486static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm)
1516{ 1487{
1517 struct cx231xx_fh *fh = file->private_data; 1488 struct cx231xx_fh *fh = file->private_data;
@@ -1520,14 +1491,15 @@ static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm)
1520 *norm = dev->encodernorm.id; 1491 *norm = dev->encodernorm.id;
1521 return 0; 1492 return 0;
1522} 1493}
1523static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 1494
1495static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
1524{ 1496{
1525 struct cx231xx_fh *fh = file->private_data; 1497 struct cx231xx_fh *fh = file->private_data;
1526 struct cx231xx *dev = fh->dev; 1498 struct cx231xx *dev = fh->dev;
1527 unsigned int i; 1499 unsigned int i;
1528 1500
1529 for (i = 0; i < ARRAY_SIZE(cx231xx_tvnorms); i++) 1501 for (i = 0; i < ARRAY_SIZE(cx231xx_tvnorms); i++)
1530 if (*id & cx231xx_tvnorms[i].id) 1502 if (id & cx231xx_tvnorms[i].id)
1531 break; 1503 break;
1532 if (i == ARRAY_SIZE(cx231xx_tvnorms)) 1504 if (i == ARRAY_SIZE(cx231xx_tvnorms))
1533 return -EINVAL; 1505 return -EINVAL;
@@ -1537,12 +1509,12 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
1537 dprintk(3, "encodernorm set to NTSC\n"); 1509 dprintk(3, "encodernorm set to NTSC\n");
1538 dev->norm = V4L2_STD_NTSC; 1510 dev->norm = V4L2_STD_NTSC;
1539 dev->ts1.height = 480; 1511 dev->ts1.height = 480;
1540 dev->mpeg_params.is_50hz = 0; 1512 cx2341x_handler_set_50hz(&dev->mpeg_ctrl_handler, false);
1541 } else { 1513 } else {
1542 dprintk(3, "encodernorm set to PAL\n"); 1514 dprintk(3, "encodernorm set to PAL\n");
1543 dev->norm = V4L2_STD_PAL_B; 1515 dev->norm = V4L2_STD_PAL_B;
1544 dev->ts1.height = 576; 1516 dev->ts1.height = 576;
1545 dev->mpeg_params.is_50hz = 1; 1517 cx2341x_handler_set_50hz(&dev->mpeg_ctrl_handler, true);
1546 } 1518 }
1547 call_all(dev, core, s_std, dev->norm); 1519 call_all(dev, core, s_std, dev->norm);
1548 /* do mode control overrides */ 1520 /* do mode control overrides */
@@ -1551,161 +1523,23 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
1551 dprintk(3, "exit vidioc_s_std() i=0x%x\n", i); 1523 dprintk(3, "exit vidioc_s_std() i=0x%x\n", i);
1552 return 0; 1524 return 0;
1553} 1525}
1554static int vidioc_g_audio(struct file *file, void *fh,
1555 struct v4l2_audio *a)
1556{
1557 struct v4l2_audio *vin = a;
1558
1559 int ret = -EINVAL;
1560 if (vin->index > 0)
1561 return ret;
1562 strncpy(vin->name, "VideoGrabber Audio", 14);
1563 vin->capability = V4L2_AUDCAP_STEREO;
1564return 0;
1565}
1566static int vidioc_enumaudio(struct file *file, void *fh,
1567 struct v4l2_audio *a)
1568{
1569 struct v4l2_audio *vin = a;
1570
1571 int ret = -EINVAL;
1572
1573 if (vin->index > 0)
1574 return ret;
1575 strncpy(vin->name, "VideoGrabber Audio", 14);
1576 vin->capability = V4L2_AUDCAP_STEREO;
1577
1578
1579return 0;
1580}
1581static const char *iname[] = {
1582 [CX231XX_VMUX_COMPOSITE1] = "Composite1",
1583 [CX231XX_VMUX_SVIDEO] = "S-Video",
1584 [CX231XX_VMUX_TELEVISION] = "Television",
1585 [CX231XX_VMUX_CABLE] = "Cable TV",
1586 [CX231XX_VMUX_DVB] = "DVB",
1587 [CX231XX_VMUX_DEBUG] = "for debug only",
1588};
1589static int vidioc_enum_input(struct file *file, void *priv,
1590 struct v4l2_input *i)
1591{
1592 struct cx231xx_fh *fh = file->private_data;
1593 struct cx231xx *dev = fh->dev;
1594 struct cx231xx_input *input;
1595 int n;
1596 dprintk(3, "enter vidioc_enum_input()i->index=%d\n", i->index);
1597
1598 if (i->index >= 4)
1599 return -EINVAL;
1600
1601
1602 input = &cx231xx_boards[dev->model].input[i->index];
1603
1604 if (input->type == 0)
1605 return -EINVAL;
1606
1607 /* FIXME
1608 * strcpy(i->name, input->name); */
1609
1610 n = i->index;
1611 strcpy(i->name, iname[INPUT(n)->type]);
1612
1613 if (input->type == CX231XX_VMUX_TELEVISION ||
1614 input->type == CX231XX_VMUX_CABLE)
1615 i->type = V4L2_INPUT_TYPE_TUNER;
1616 else
1617 i->type = V4L2_INPUT_TYPE_CAMERA;
1618
1619
1620 return 0;
1621}
1622
1623static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1624{
1625 *i = 0;
1626 return 0;
1627}
1628
1629static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1630{
1631 struct cx231xx_fh *fh = file->private_data;
1632 struct cx231xx *dev = fh->dev;
1633
1634 dprintk(3, "enter vidioc_s_input() i=%d\n", i);
1635
1636 mutex_lock(&dev->lock);
1637
1638 video_mux(dev, i);
1639
1640 mutex_unlock(&dev->lock);
1641
1642 if (i >= 4)
1643 return -EINVAL;
1644 dev->input = i;
1645 dprintk(3, "exit vidioc_s_input()\n");
1646 return 0;
1647}
1648
1649static int vidioc_g_tuner(struct file *file, void *priv,
1650 struct v4l2_tuner *t)
1651{
1652 return 0;
1653}
1654
1655static int vidioc_s_tuner(struct file *file, void *priv,
1656 struct v4l2_tuner *t)
1657{
1658 return 0;
1659}
1660
1661static int vidioc_g_frequency(struct file *file, void *priv,
1662 struct v4l2_frequency *f)
1663{
1664 return 0;
1665}
1666
1667static int vidioc_s_frequency(struct file *file, void *priv,
1668 struct v4l2_frequency *f)
1669{
1670
1671
1672 return 0;
1673}
1674 1526
1675static int vidioc_s_ctrl(struct file *file, void *priv, 1527static int vidioc_s_ctrl(struct file *file, void *priv,
1676 struct v4l2_control *ctl) 1528 struct v4l2_control *ctl)
1677{ 1529{
1678 struct cx231xx_fh *fh = file->private_data; 1530 struct cx231xx_fh *fh = file->private_data;
1679 struct cx231xx *dev = fh->dev; 1531 struct cx231xx *dev = fh->dev;
1532
1680 dprintk(3, "enter vidioc_s_ctrl()\n"); 1533 dprintk(3, "enter vidioc_s_ctrl()\n");
1681 /* Update the A/V core */ 1534 /* Update the A/V core */
1682 call_all(dev, core, s_ctrl, ctl); 1535 call_all(dev, core, s_ctrl, ctl);
1683 dprintk(3, "exit vidioc_s_ctrl()\n"); 1536 dprintk(3, "exit vidioc_s_ctrl()\n");
1684 return 0; 1537 return 0;
1685} 1538}
1686static struct v4l2_capability pvr_capability = {
1687 .driver = "cx231xx",
1688 .card = "VideoGrabber",
1689 .bus_info = "usb",
1690 .version = 1,
1691 .capabilities = (V4L2_CAP_VIDEO_CAPTURE |
1692 V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO |
1693 V4L2_CAP_STREAMING | V4L2_CAP_READWRITE),
1694};
1695static int vidioc_querycap(struct file *file, void *priv,
1696 struct v4l2_capability *cap)
1697{
1698
1699
1700
1701 memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability));
1702 return 0;
1703}
1704 1539
1705static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 1540static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1706 struct v4l2_fmtdesc *f) 1541 struct v4l2_fmtdesc *f)
1707{ 1542{
1708
1709 if (f->index != 0) 1543 if (f->index != 0)
1710 return -EINVAL; 1544 return -EINVAL;
1711 1545
@@ -1720,17 +1554,18 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1720{ 1554{
1721 struct cx231xx_fh *fh = file->private_data; 1555 struct cx231xx_fh *fh = file->private_data;
1722 struct cx231xx *dev = fh->dev; 1556 struct cx231xx *dev = fh->dev;
1557
1723 dprintk(3, "enter vidioc_g_fmt_vid_cap()\n"); 1558 dprintk(3, "enter vidioc_g_fmt_vid_cap()\n");
1724 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 1559 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1725 f->fmt.pix.bytesperline = 0; 1560 f->fmt.pix.bytesperline = 0;
1726 f->fmt.pix.sizeimage = 1561 f->fmt.pix.sizeimage = mpeglines * mpeglinesize;
1727 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count; 1562 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1728 f->fmt.pix.colorspace = 0; 1563 f->fmt.pix.width = dev->ts1.width;
1729 f->fmt.pix.width = dev->ts1.width; 1564 f->fmt.pix.height = dev->ts1.height;
1730 f->fmt.pix.height = dev->ts1.height; 1565 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1731 f->fmt.pix.field = fh->vidq.field; 1566 f->fmt.pix.priv = 0;
1732 dprintk(1, "VIDIOC_G_FMT: w: %d, h: %d, f: %d\n", 1567 dprintk(1, "VIDIOC_G_FMT: w: %d, h: %d\n",
1733 dev->ts1.width, dev->ts1.height, fh->vidq.field); 1568 dev->ts1.width, dev->ts1.height);
1734 dprintk(3, "exit vidioc_g_fmt_vid_cap()\n"); 1569 dprintk(3, "exit vidioc_g_fmt_vid_cap()\n");
1735 return 0; 1570 return 0;
1736} 1571}
@@ -1740,25 +1575,20 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1740{ 1575{
1741 struct cx231xx_fh *fh = file->private_data; 1576 struct cx231xx_fh *fh = file->private_data;
1742 struct cx231xx *dev = fh->dev; 1577 struct cx231xx *dev = fh->dev;
1578
1743 dprintk(3, "enter vidioc_try_fmt_vid_cap()\n"); 1579 dprintk(3, "enter vidioc_try_fmt_vid_cap()\n");
1744 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 1580 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1745 f->fmt.pix.bytesperline = 0; 1581 f->fmt.pix.bytesperline = 0;
1746 f->fmt.pix.sizeimage = 1582 f->fmt.pix.sizeimage = mpeglines * mpeglinesize;
1747 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count; 1583 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1748 f->fmt.pix.colorspace = 0; 1584 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1749 dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n", 1585 f->fmt.pix.priv = 0;
1750 dev->ts1.width, dev->ts1.height, fh->vidq.field); 1586 dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d\n",
1587 dev->ts1.width, dev->ts1.height);
1751 dprintk(3, "exit vidioc_try_fmt_vid_cap()\n"); 1588 dprintk(3, "exit vidioc_try_fmt_vid_cap()\n");
1752 return 0; 1589 return 0;
1753} 1590}
1754 1591
1755static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1756 struct v4l2_format *f)
1757{
1758
1759 return 0;
1760}
1761
1762static int vidioc_reqbufs(struct file *file, void *priv, 1592static int vidioc_reqbufs(struct file *file, void *priv,
1763 struct v4l2_requestbuffers *p) 1593 struct v4l2_requestbuffers *p)
1764{ 1594{
@@ -1795,22 +1625,22 @@ static int vidioc_streamon(struct file *file, void *priv,
1795 enum v4l2_buf_type i) 1625 enum v4l2_buf_type i)
1796{ 1626{
1797 struct cx231xx_fh *fh = file->private_data; 1627 struct cx231xx_fh *fh = file->private_data;
1798
1799 struct cx231xx *dev = fh->dev; 1628 struct cx231xx *dev = fh->dev;
1629
1800 dprintk(3, "enter vidioc_streamon()\n"); 1630 dprintk(3, "enter vidioc_streamon()\n");
1801 cx231xx_set_alt_setting(dev, INDEX_TS1, 0); 1631 cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
1802 cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); 1632 cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
1803 if (dev->USE_ISO) 1633 if (dev->USE_ISO)
1804 cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS, 1634 cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS,
1805 CX231XX_NUM_BUFS, 1635 CX231XX_NUM_BUFS,
1806 dev->video_mode.max_pkt_size, 1636 dev->video_mode.max_pkt_size,
1807 cx231xx_isoc_copy); 1637 cx231xx_isoc_copy);
1808 else { 1638 else {
1809 cx231xx_init_bulk(dev, 320, 1639 cx231xx_init_bulk(dev, 320,
1810 5, 1640 5,
1811 dev->ts1_mode.max_pkt_size, 1641 dev->ts1_mode.max_pkt_size,
1812 cx231xx_bulk_copy); 1642 cx231xx_bulk_copy);
1813 } 1643 }
1814 dprintk(3, "exit vidioc_streamon()\n"); 1644 dprintk(3, "exit vidioc_streamon()\n");
1815 return videobuf_streamon(&fh->vidq); 1645 return videobuf_streamon(&fh->vidq);
1816} 1646}
@@ -1822,117 +1652,25 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1822 return videobuf_streamoff(&fh->vidq); 1652 return videobuf_streamoff(&fh->vidq);
1823} 1653}
1824 1654
1825static int vidioc_g_ext_ctrls(struct file *file, void *priv,
1826 struct v4l2_ext_controls *f)
1827{
1828 struct cx231xx_fh *fh = priv;
1829 struct cx231xx *dev = fh->dev;
1830 dprintk(3, "enter vidioc_g_ext_ctrls()\n");
1831 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1832 return -EINVAL;
1833 dprintk(3, "exit vidioc_g_ext_ctrls()\n");
1834 return cx2341x_ext_ctrls(&dev->mpeg_params, 0, f, VIDIOC_G_EXT_CTRLS);
1835}
1836
1837static int vidioc_s_ext_ctrls(struct file *file, void *priv,
1838 struct v4l2_ext_controls *f)
1839{
1840 struct cx231xx_fh *fh = priv;
1841 struct cx231xx *dev = fh->dev;
1842 struct cx2341x_mpeg_params p;
1843 int err;
1844 dprintk(3, "enter vidioc_s_ext_ctrls()\n");
1845 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1846 return -EINVAL;
1847
1848 p = dev->mpeg_params;
1849 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_TRY_EXT_CTRLS);
1850 if (err == 0) {
1851 err = cx2341x_update(dev, cx231xx_mbox_func,
1852 &dev->mpeg_params, &p);
1853 dev->mpeg_params = p;
1854 }
1855
1856 return err;
1857
1858
1859return 0;
1860}
1861
1862static int vidioc_try_ext_ctrls(struct file *file, void *priv,
1863 struct v4l2_ext_controls *f)
1864{
1865 struct cx231xx_fh *fh = priv;
1866 struct cx231xx *dev = fh->dev;
1867 struct cx2341x_mpeg_params p;
1868 int err;
1869 dprintk(3, "enter vidioc_try_ext_ctrls()\n");
1870 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1871 return -EINVAL;
1872
1873 p = dev->mpeg_params;
1874 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_TRY_EXT_CTRLS);
1875 dprintk(3, "exit vidioc_try_ext_ctrls() err=%d\n", err);
1876 return err;
1877}
1878
1879static int vidioc_log_status(struct file *file, void *priv) 1655static int vidioc_log_status(struct file *file, void *priv)
1880{ 1656{
1881 struct cx231xx_fh *fh = priv; 1657 struct cx231xx_fh *fh = priv;
1882 struct cx231xx *dev = fh->dev; 1658 struct cx231xx *dev = fh->dev;
1883 char name[32 + 2];
1884 1659
1885 snprintf(name, sizeof(name), "%s/2", dev->name);
1886 dprintk(3,
1887 "%s/2: ============ START LOG STATUS ============\n",
1888 dev->name);
1889 call_all(dev, core, log_status); 1660 call_all(dev, core, log_status);
1890 cx2341x_log_status(&dev->mpeg_params, name); 1661 return v4l2_ctrl_log_status(file, priv);
1891 dprintk(3,
1892 "%s/2: ============= END LOG STATUS =============\n",
1893 dev->name);
1894 return 0;
1895}
1896
1897static int vidioc_querymenu(struct file *file, void *priv,
1898 struct v4l2_querymenu *a)
1899{
1900 struct cx231xx_fh *fh = priv;
1901 struct cx231xx *dev = fh->dev;
1902 dprintk(3, "enter vidioc_querymenu()\n");
1903 dprintk(3, "exit vidioc_querymenu()\n");
1904 return cx231xx_querymenu(dev, a);
1905}
1906
1907static int vidioc_queryctrl(struct file *file, void *priv,
1908 struct v4l2_queryctrl *c)
1909{
1910 struct cx231xx_fh *fh = priv;
1911 struct cx231xx *dev = fh->dev;
1912 dprintk(3, "enter vidioc_queryctrl()\n");
1913 dprintk(3, "exit vidioc_queryctrl()\n");
1914 return cx231xx_queryctrl(dev, c);
1915} 1662}
1916 1663
1917static int mpeg_open(struct file *file) 1664static int mpeg_open(struct file *file)
1918{ 1665{
1919 int minor = video_devdata(file)->minor; 1666 struct video_device *vdev = video_devdata(file);
1920 struct cx231xx *h, *dev = NULL; 1667 struct cx231xx *dev = video_drvdata(file);
1921 /*struct list_head *list;*/
1922 struct cx231xx_fh *fh; 1668 struct cx231xx_fh *fh;
1923 /*u32 value = 0;*/
1924 1669
1925 dprintk(2, "%s()\n", __func__); 1670 dprintk(2, "%s()\n", __func__);
1926 1671
1927 list_for_each_entry(h, &cx231xx_devlist, devlist) { 1672 if (mutex_lock_interruptible(&dev->lock))
1928 if (h->v4l_device->minor == minor) 1673 return -ERESTARTSYS;
1929 dev = h;
1930 }
1931
1932 if (dev == NULL)
1933 return -ENODEV;
1934
1935 mutex_lock(&dev->lock);
1936 1674
1937 /* allocate + initialize per filehandle data */ 1675 /* allocate + initialize per filehandle data */
1938 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 1676 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
@@ -1942,29 +1680,30 @@ static int mpeg_open(struct file *file)
1942 } 1680 }
1943 1681
1944 file->private_data = fh; 1682 file->private_data = fh;
1945 fh->dev = dev; 1683 v4l2_fh_init(&fh->fh, vdev);
1684 fh->dev = dev;
1946 1685
1947 1686
1948 videobuf_queue_vmalloc_init(&fh->vidq, &cx231xx_qops, 1687 videobuf_queue_vmalloc_init(&fh->vidq, &cx231xx_qops,
1949 NULL, &dev->video_mode.slock, 1688 NULL, &dev->video_mode.slock,
1950 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, 1689 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED,
1951 sizeof(struct cx231xx_buffer), fh, NULL); 1690 sizeof(struct cx231xx_buffer), fh, &dev->lock);
1952/* 1691/*
1953 videobuf_queue_sg_init(&fh->vidq, &cx231xx_qops, 1692 videobuf_queue_sg_init(&fh->vidq, &cx231xx_qops,
1954 &dev->udev->dev, &dev->ts1.slock, 1693 &dev->udev->dev, &dev->ts1.slock,
1955 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1694 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1956 V4L2_FIELD_INTERLACED, 1695 V4L2_FIELD_INTERLACED,
1957 sizeof(struct cx231xx_buffer), 1696 sizeof(struct cx231xx_buffer),
1958 fh, NULL); 1697 fh, &dev->lock);
1959*/ 1698*/
1960 1699
1961
1962 cx231xx_set_alt_setting(dev, INDEX_VANC, 1); 1700 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1963 cx231xx_set_gpio_value(dev, 2, 0); 1701 cx231xx_set_gpio_value(dev, 2, 0);
1964 1702
1965 cx231xx_initialize_codec(dev); 1703 cx231xx_initialize_codec(dev);
1966 1704
1967 mutex_unlock(&dev->lock); 1705 mutex_unlock(&dev->lock);
1706 v4l2_fh_add(&fh->fh);
1968 cx231xx_start_TS1(dev); 1707 cx231xx_start_TS1(dev);
1969 1708
1970 return 0; 1709 return 0;
@@ -1977,25 +1716,20 @@ static int mpeg_release(struct file *file)
1977 1716
1978 dprintk(3, "mpeg_release()! dev=0x%p\n", dev); 1717 dprintk(3, "mpeg_release()! dev=0x%p\n", dev);
1979 1718
1980 if (!dev) {
1981 dprintk(3, "abort!!!\n");
1982 return 0;
1983 }
1984
1985 mutex_lock(&dev->lock); 1719 mutex_lock(&dev->lock);
1986 1720
1987 cx231xx_stop_TS1(dev); 1721 cx231xx_stop_TS1(dev);
1988 1722
1989 /* do this before setting alternate! */ 1723 /* do this before setting alternate! */
1990 if (dev->USE_ISO) 1724 if (dev->USE_ISO)
1991 cx231xx_uninit_isoc(dev); 1725 cx231xx_uninit_isoc(dev);
1992 else 1726 else
1993 cx231xx_uninit_bulk(dev); 1727 cx231xx_uninit_bulk(dev);
1994 cx231xx_set_mode(dev, CX231XX_SUSPEND); 1728 cx231xx_set_mode(dev, CX231XX_SUSPEND);
1995 1729
1996 cx231xx_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, 1730 cx231xx_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1997 CX231xx_END_NOW, CX231xx_MPEG_CAPTURE, 1731 CX231xx_END_NOW, CX231xx_MPEG_CAPTURE,
1998 CX231xx_RAW_BITS_NONE); 1732 CX231xx_RAW_BITS_NONE);
1999 1733
2000 /* FIXME: Review this crap */ 1734 /* FIXME: Review this crap */
2001 /* Shut device down on last close */ 1735 /* Shut device down on last close */
@@ -2015,7 +1749,8 @@ static int mpeg_release(struct file *file)
2015 videobuf_read_stop(&fh->vidq); 1749 videobuf_read_stop(&fh->vidq);
2016 1750
2017 videobuf_mmap_free(&fh->vidq); 1751 videobuf_mmap_free(&fh->vidq);
2018 file->private_data = NULL; 1752 v4l2_fh_del(&fh->fh);
1753 v4l2_fh_exit(&fh->fh);
2019 kfree(fh); 1754 kfree(fh);
2020 mutex_unlock(&dev->lock); 1755 mutex_unlock(&dev->lock);
2021 return 0; 1756 return 0;
@@ -2027,7 +1762,6 @@ static ssize_t mpeg_read(struct file *file, char __user *data,
2027 struct cx231xx_fh *fh = file->private_data; 1762 struct cx231xx_fh *fh = file->private_data;
2028 struct cx231xx *dev = fh->dev; 1763 struct cx231xx *dev = fh->dev;
2029 1764
2030
2031 /* Deal w/ A/V decoder * and mpeg encoder sync issues. */ 1765 /* Deal w/ A/V decoder * and mpeg encoder sync issues. */
2032 /* Start mpeg encoder on first read. */ 1766 /* Start mpeg encoder on first read. */
2033 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) { 1767 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) {
@@ -2044,12 +1778,23 @@ static ssize_t mpeg_read(struct file *file, char __user *data,
2044static unsigned int mpeg_poll(struct file *file, 1778static unsigned int mpeg_poll(struct file *file,
2045 struct poll_table_struct *wait) 1779 struct poll_table_struct *wait)
2046{ 1780{
1781 unsigned long req_events = poll_requested_events(wait);
2047 struct cx231xx_fh *fh = file->private_data; 1782 struct cx231xx_fh *fh = file->private_data;
2048 /*struct cx231xx *dev = fh->dev;*/ 1783 struct cx231xx *dev = fh->dev;
1784 unsigned int res = 0;
1785
1786 if (v4l2_event_pending(&fh->fh))
1787 res |= POLLPRI;
1788 else
1789 poll_wait(file, &fh->fh.wait, wait);
2049 1790
2050 /*dprintk(2, "%s\n", __func__);*/ 1791 if (!(req_events & (POLLIN | POLLRDNORM)))
1792 return res;
2051 1793
2052 return videobuf_poll_stream(file, &fh->vidq, wait); 1794 mutex_lock(&dev->lock);
1795 res |= videobuf_poll_stream(file, &fh->vidq, wait);
1796 mutex_unlock(&dev->lock);
1797 return res;
2053} 1798}
2054 1799
2055static int mpeg_mmap(struct file *file, struct vm_area_struct *vma) 1800static int mpeg_mmap(struct file *file, struct vm_area_struct *vma)
@@ -2069,44 +1814,39 @@ static struct v4l2_file_operations mpeg_fops = {
2069 .read = mpeg_read, 1814 .read = mpeg_read,
2070 .poll = mpeg_poll, 1815 .poll = mpeg_poll,
2071 .mmap = mpeg_mmap, 1816 .mmap = mpeg_mmap,
2072 .ioctl = video_ioctl2, 1817 .unlocked_ioctl = video_ioctl2,
2073}; 1818};
2074 1819
2075static const struct v4l2_ioctl_ops mpeg_ioctl_ops = { 1820static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
2076 .vidioc_s_std = vidioc_s_std, 1821 .vidioc_s_std = vidioc_s_std,
2077 .vidioc_g_std = vidioc_g_std, 1822 .vidioc_g_std = vidioc_g_std,
2078 .vidioc_enum_input = vidioc_enum_input, 1823 .vidioc_g_tuner = cx231xx_g_tuner,
2079 .vidioc_enumaudio = vidioc_enumaudio, 1824 .vidioc_s_tuner = cx231xx_s_tuner,
2080 .vidioc_g_audio = vidioc_g_audio, 1825 .vidioc_g_frequency = cx231xx_g_frequency,
2081 .vidioc_g_input = vidioc_g_input, 1826 .vidioc_s_frequency = cx231xx_s_frequency,
2082 .vidioc_s_input = vidioc_s_input, 1827 .vidioc_enum_input = cx231xx_enum_input,
2083 .vidioc_g_tuner = vidioc_g_tuner, 1828 .vidioc_g_input = cx231xx_g_input,
2084 .vidioc_s_tuner = vidioc_s_tuner, 1829 .vidioc_s_input = cx231xx_s_input,
2085 .vidioc_g_frequency = vidioc_g_frequency,
2086 .vidioc_s_frequency = vidioc_s_frequency,
2087 .vidioc_s_ctrl = vidioc_s_ctrl, 1830 .vidioc_s_ctrl = vidioc_s_ctrl,
2088 .vidioc_querycap = vidioc_querycap, 1831 .vidioc_querycap = cx231xx_querycap,
2089 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1832 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2090 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1833 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2091 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1834 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2092 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1835 .vidioc_s_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2093 .vidioc_reqbufs = vidioc_reqbufs, 1836 .vidioc_reqbufs = vidioc_reqbufs,
2094 .vidioc_querybuf = vidioc_querybuf, 1837 .vidioc_querybuf = vidioc_querybuf,
2095 .vidioc_qbuf = vidioc_qbuf, 1838 .vidioc_qbuf = vidioc_qbuf,
2096 .vidioc_dqbuf = vidioc_dqbuf, 1839 .vidioc_dqbuf = vidioc_dqbuf,
2097 .vidioc_streamon = vidioc_streamon, 1840 .vidioc_streamon = vidioc_streamon,
2098 .vidioc_streamoff = vidioc_streamoff, 1841 .vidioc_streamoff = vidioc_streamoff,
2099 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
2100 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
2101 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
2102 .vidioc_log_status = vidioc_log_status, 1842 .vidioc_log_status = vidioc_log_status,
2103 .vidioc_querymenu = vidioc_querymenu, 1843 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
2104 .vidioc_queryctrl = vidioc_queryctrl,
2105/* .vidioc_g_chip_ident = cx231xx_g_chip_ident,*/
2106#ifdef CONFIG_VIDEO_ADV_DEBUG 1844#ifdef CONFIG_VIDEO_ADV_DEBUG
2107/* .vidioc_g_register = cx231xx_g_register,*/ 1845 .vidioc_g_register = cx231xx_g_register,
2108/* .vidioc_s_register = cx231xx_s_register,*/ 1846 .vidioc_s_register = cx231xx_s_register,
2109#endif 1847#endif
1848 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1849 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2110}; 1850};
2111 1851
2112static struct video_device cx231xx_mpeg_template = { 1852static struct video_device cx231xx_mpeg_template = {
@@ -2114,8 +1854,7 @@ static struct video_device cx231xx_mpeg_template = {
2114 .fops = &mpeg_fops, 1854 .fops = &mpeg_fops,
2115 .ioctl_ops = &mpeg_ioctl_ops, 1855 .ioctl_ops = &mpeg_ioctl_ops,
2116 .minor = -1, 1856 .minor = -1,
2117 .tvnorms = CX231xx_NORMS, 1857 .tvnorms = V4L2_STD_ALL,
2118 .current_norm = V4L2_STD_NTSC_M,
2119}; 1858};
2120 1859
2121void cx231xx_417_unregister(struct cx231xx *dev) 1860void cx231xx_417_unregister(struct cx231xx *dev)
@@ -2128,10 +1867,44 @@ void cx231xx_417_unregister(struct cx231xx *dev)
2128 video_unregister_device(dev->v4l_device); 1867 video_unregister_device(dev->v4l_device);
2129 else 1868 else
2130 video_device_release(dev->v4l_device); 1869 video_device_release(dev->v4l_device);
1870 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);
2131 dev->v4l_device = NULL; 1871 dev->v4l_device = NULL;
2132 } 1872 }
2133} 1873}
2134 1874
1875static int cx231xx_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
1876{
1877 struct cx231xx *dev = container_of(cxhdl, struct cx231xx, mpeg_ctrl_handler);
1878 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
1879 struct v4l2_mbus_framefmt fmt;
1880
1881 /* fix videodecoder resolution */
1882 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
1883 fmt.height = cxhdl->height;
1884 fmt.code = V4L2_MBUS_FMT_FIXED;
1885 v4l2_subdev_call(dev->sd_cx25840, video, s_mbus_fmt, &fmt);
1886 return 0;
1887}
1888
1889static int cx231xx_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
1890{
1891 static const u32 freqs[3] = { 44100, 48000, 32000 };
1892 struct cx231xx *dev = container_of(cxhdl, struct cx231xx, mpeg_ctrl_handler);
1893
1894 /* The audio clock of the digitizer must match the codec sample
1895 rate otherwise you get some very strange effects. */
1896 if (idx < ARRAY_SIZE(freqs))
1897 call_all(dev, audio, s_clock_freq, freqs[idx]);
1898 return 0;
1899}
1900
1901static struct cx2341x_handler_ops cx231xx_ops = {
1902 /* needed for the video clock freq */
1903 .s_audio_sampling_freq = cx231xx_s_audio_sampling_freq,
1904 /* needed for setting up the video resolution */
1905 .s_video_encoding = cx231xx_s_video_encoding,
1906};
1907
2135static struct video_device *cx231xx_video_dev_alloc( 1908static struct video_device *cx231xx_video_dev_alloc(
2136 struct cx231xx *dev, 1909 struct cx231xx *dev,
2137 struct usb_device *usbdev, 1910 struct usb_device *usbdev,
@@ -2145,12 +1918,21 @@ static struct video_device *cx231xx_video_dev_alloc(
2145 if (NULL == vfd) 1918 if (NULL == vfd)
2146 return NULL; 1919 return NULL;
2147 *vfd = *template; 1920 *vfd = *template;
2148 vfd->minor = -1;
2149 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, 1921 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name,
2150 type, cx231xx_boards[dev->model].name); 1922 type, cx231xx_boards[dev->model].name);
2151 1923
2152 vfd->v4l2_dev = &dev->v4l2_dev; 1924 vfd->v4l2_dev = &dev->v4l2_dev;
1925 vfd->lock = &dev->lock;
2153 vfd->release = video_device_release; 1926 vfd->release = video_device_release;
1927 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
1928 vfd->ctrl_handler = &dev->mpeg_ctrl_handler.hdl;
1929 video_set_drvdata(vfd, dev);
1930 if (dev->tuner_type == TUNER_ABSENT) {
1931 v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
1932 v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY);
1933 v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER);
1934 v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER);
1935 }
2154 1936
2155 return vfd; 1937 return vfd;
2156 1938
@@ -2173,10 +1955,27 @@ int cx231xx_417_register(struct cx231xx *dev)
2173 tsport->height = 576; 1955 tsport->height = 576;
2174 1956
2175 tsport->width = 720; 1957 tsport->width = 720;
2176 cx2341x_fill_defaults(&dev->mpeg_params); 1958 err = cx2341x_handler_init(&dev->mpeg_ctrl_handler, 50);
1959 if (err) {
1960 dprintk(3, "%s: can't init cx2341x controls\n", dev->name);
1961 return err;
1962 }
1963 dev->mpeg_ctrl_handler.func = cx231xx_mbox_func;
1964 dev->mpeg_ctrl_handler.priv = dev;
1965 dev->mpeg_ctrl_handler.ops = &cx231xx_ops;
1966 if (dev->sd_cx25840)
1967 v4l2_ctrl_add_handler(&dev->mpeg_ctrl_handler.hdl,
1968 dev->sd_cx25840->ctrl_handler, NULL);
1969 if (dev->mpeg_ctrl_handler.hdl.error) {
1970 err = dev->mpeg_ctrl_handler.hdl.error;
1971 dprintk(3, "%s: can't add cx25840 controls\n", dev->name);
1972 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);
1973 return err;
1974 }
2177 dev->norm = V4L2_STD_NTSC; 1975 dev->norm = V4L2_STD_NTSC;
2178 1976
2179 dev->mpeg_params.port = CX2341X_PORT_SERIAL; 1977 dev->mpeg_ctrl_handler.port = CX2341X_PORT_SERIAL;
1978 cx2341x_handler_set_50hz(&dev->mpeg_ctrl_handler, false);
2180 1979
2181 /* Allocate and initialize V4L video device */ 1980 /* Allocate and initialize V4L video device */
2182 dev->v4l_device = cx231xx_video_dev_alloc(dev, 1981 dev->v4l_device = cx231xx_video_dev_alloc(dev,
@@ -2185,6 +1984,7 @@ int cx231xx_417_register(struct cx231xx *dev)
2185 VFL_TYPE_GRABBER, -1); 1984 VFL_TYPE_GRABBER, -1);
2186 if (err < 0) { 1985 if (err < 0) {
2187 dprintk(3, "%s: can't register mpeg device\n", dev->name); 1986 dprintk(3, "%s: can't register mpeg device\n", dev->name);
1987 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);
2188 return err; 1988 return err;
2189 } 1989 }
2190 1990
diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c
index b4c99c7270cf..81a1d971d797 100644
--- a/drivers/media/usb/cx231xx/cx231xx-audio.c
+++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
@@ -449,9 +449,6 @@ static int snd_cx231xx_capture_open(struct snd_pcm_substream *substream)
449 return -ENODEV; 449 return -ENODEV;
450 } 450 }
451 451
452 /* Sets volume, mute, etc */
453 dev->mute = 0;
454
455 /* set alternate setting for audio interface */ 452 /* set alternate setting for audio interface */
456 /* 1 - 48000 samples per sec */ 453 /* 1 - 48000 samples per sec */
457 mutex_lock(&dev->lock); 454 mutex_lock(&dev->lock);
@@ -503,7 +500,6 @@ static int snd_cx231xx_pcm_close(struct snd_pcm_substream *substream)
503 return ret; 500 return ret;
504 } 501 }
505 502
506 dev->mute = 1;
507 dev->adev.users--; 503 dev->adev.users--;
508 mutex_unlock(&dev->lock); 504 mutex_unlock(&dev->lock);
509 505
@@ -708,8 +704,8 @@ static int cx231xx_audio_init(struct cx231xx *dev)
708 audio_index + 1]; 704 audio_index + 1];
709 705
710 adev->end_point_addr = 706 adev->end_point_addr =
711 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. 707 uif->altsetting[0].endpoint[isoc_pipe].desc.
712 bEndpointAddress); 708 bEndpointAddress;
713 709
714 adev->num_alt = uif->num_altsetting; 710 adev->num_alt = uif->num_altsetting;
715 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 711 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 722207913740..235ba657d52e 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -357,6 +357,7 @@ int cx231xx_afe_update_power_control(struct cx231xx *dev,
357 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID: 357 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
358 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL: 358 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
359 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC: 359 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC:
360 case CX231XX_BOARD_OTG102:
360 if (avmode == POLARIS_AVMODE_ANALOGT_TV) { 361 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
361 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS | 362 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
362 FLD_PWRDN_ENABLE_PLL)) { 363 FLD_PWRDN_ENABLE_PLL)) {
@@ -1720,6 +1721,7 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard)
1720 case CX231XX_BOARD_CNXT_RDU_250: 1721 case CX231XX_BOARD_CNXT_RDU_250:
1721 case CX231XX_BOARD_CNXT_VIDEO_GRABBER: 1722 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
1722 case CX231XX_BOARD_HAUPPAUGE_EXETER: 1723 case CX231XX_BOARD_HAUPPAUGE_EXETER:
1724 case CX231XX_BOARD_OTG102:
1723 func_mode = 0x03; 1725 func_mode = 0x03;
1724 break; 1726 break;
1725 case CX231XX_BOARD_CNXT_RDE_253S: 1727 case CX231XX_BOARD_CNXT_RDE_253S:
@@ -2133,7 +2135,7 @@ int cx231xx_tuner_post_channel_change(struct cx231xx *dev)
2133 2135
2134 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval); 2136 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
2135 2137
2136 return status; 2138 return status == sizeof(dwval) ? 0 : -EIO;
2137} 2139}
2138 2140
2139/****************************************************************************** 2141/******************************************************************************
@@ -2221,7 +2223,7 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode)
2221 if (status < 0) 2223 if (status < 0)
2222 return status; 2224 return status;
2223 2225
2224 tmp = *((u32 *) value); 2226 tmp = le32_to_cpu(*((u32 *) value));
2225 2227
2226 switch (mode) { 2228 switch (mode) {
2227 case POLARIS_AVMODE_ENXTERNAL_AV: 2229 case POLARIS_AVMODE_ENXTERNAL_AV:
@@ -2442,7 +2444,7 @@ int cx231xx_power_suspend(struct cx231xx *dev)
2442 if (status > 0) 2444 if (status > 0)
2443 return status; 2445 return status;
2444 2446
2445 tmp = *((u32 *) value); 2447 tmp = le32_to_cpu(*((u32 *) value));
2446 tmp &= (~PWR_MODE_MASK); 2448 tmp &= (~PWR_MODE_MASK);
2447 2449
2448 value[0] = (u8) tmp; 2450 value[0] = (u8) tmp;
@@ -2470,7 +2472,7 @@ int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask)
2470 if (status < 0) 2472 if (status < 0)
2471 return status; 2473 return status;
2472 2474
2473 tmp = *((u32 *) value); 2475 tmp = le32_to_cpu(*((u32 *) value));
2474 tmp |= ep_mask; 2476 tmp |= ep_mask;
2475 value[0] = (u8) tmp; 2477 value[0] = (u8) tmp;
2476 value[1] = (u8) (tmp >> 8); 2478 value[1] = (u8) (tmp >> 8);
@@ -2495,7 +2497,7 @@ int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask)
2495 if (status < 0) 2497 if (status < 0)
2496 return status; 2498 return status;
2497 2499
2498 tmp = *((u32 *) value); 2500 tmp = le32_to_cpu(*((u32 *) value));
2499 tmp &= (~ep_mask); 2501 tmp &= (~ep_mask);
2500 value[0] = (u8) tmp; 2502 value[0] = (u8) tmp;
2501 value[1] = (u8) (tmp >> 8); 2503 value[1] = (u8) (tmp >> 8);
@@ -2638,20 +2640,23 @@ EXPORT_SYMBOL_GPL(cx231xx_capture_start);
2638/***************************************************************************** 2640/*****************************************************************************
2639* G P I O B I T control functions * 2641* G P I O B I T control functions *
2640******************************************************************************/ 2642******************************************************************************/
2641int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val) 2643static int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u32 gpio_val)
2642{ 2644{
2643 int status = 0; 2645 int status = 0;
2644 2646
2645 status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 0); 2647 gpio_val = cpu_to_le32(gpio_val);
2648 status = cx231xx_send_gpio_cmd(dev, gpio_bit, (u8 *)&gpio_val, 4, 0, 0);
2646 2649
2647 return status; 2650 return status;
2648} 2651}
2649 2652
2650int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val) 2653static int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u32 *gpio_val)
2651{ 2654{
2655 u32 tmp;
2652 int status = 0; 2656 int status = 0;
2653 2657
2654 status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 1); 2658 status = cx231xx_send_gpio_cmd(dev, gpio_bit, (u8 *)&tmp, 4, 0, 1);
2659 *gpio_val = le32_to_cpu(tmp);
2655 2660
2656 return status; 2661 return status;
2657} 2662}
@@ -2683,7 +2688,7 @@ int cx231xx_set_gpio_direction(struct cx231xx *dev,
2683 else 2688 else
2684 value = dev->gpio_dir | (1 << pin_number); 2689 value = dev->gpio_dir | (1 << pin_number);
2685 2690
2686 status = cx231xx_set_gpio_bit(dev, value, (u8 *) &dev->gpio_val); 2691 status = cx231xx_set_gpio_bit(dev, value, dev->gpio_val);
2687 2692
2688 /* cache the value for future */ 2693 /* cache the value for future */
2689 dev->gpio_dir = value; 2694 dev->gpio_dir = value;
@@ -2717,7 +2722,7 @@ int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value)
2717 value = dev->gpio_dir | (1 << pin_number); 2722 value = dev->gpio_dir | (1 << pin_number);
2718 dev->gpio_dir = value; 2723 dev->gpio_dir = value;
2719 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2724 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2720 (u8 *) &dev->gpio_val); 2725 dev->gpio_val);
2721 value = 0; 2726 value = 0;
2722 } 2727 }
2723 2728
@@ -2730,7 +2735,7 @@ int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value)
2730 dev->gpio_val = value; 2735 dev->gpio_val = value;
2731 2736
2732 /* toggle bit0 of GP_IO */ 2737 /* toggle bit0 of GP_IO */
2733 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2738 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2734 2739
2735 return status; 2740 return status;
2736} 2741}
@@ -2748,7 +2753,7 @@ int cx231xx_gpio_i2c_start(struct cx231xx *dev)
2748 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2753 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2749 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio; 2754 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2750 2755
2751 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2756 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2752 if (status < 0) 2757 if (status < 0)
2753 return -EINVAL; 2758 return -EINVAL;
2754 2759
@@ -2756,7 +2761,7 @@ int cx231xx_gpio_i2c_start(struct cx231xx *dev)
2756 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2761 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2757 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); 2762 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2758 2763
2759 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2764 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2760 if (status < 0) 2765 if (status < 0)
2761 return -EINVAL; 2766 return -EINVAL;
2762 2767
@@ -2764,7 +2769,7 @@ int cx231xx_gpio_i2c_start(struct cx231xx *dev)
2764 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2769 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2765 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); 2770 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2766 2771
2767 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2772 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2768 if (status < 0) 2773 if (status < 0)
2769 return -EINVAL; 2774 return -EINVAL;
2770 2775
@@ -2782,7 +2787,7 @@ int cx231xx_gpio_i2c_end(struct cx231xx *dev)
2782 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2787 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2783 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); 2788 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2784 2789
2785 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2790 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2786 if (status < 0) 2791 if (status < 0)
2787 return -EINVAL; 2792 return -EINVAL;
2788 2793
@@ -2790,7 +2795,7 @@ int cx231xx_gpio_i2c_end(struct cx231xx *dev)
2790 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2795 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2791 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); 2796 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2792 2797
2793 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2798 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2794 if (status < 0) 2799 if (status < 0)
2795 return -EINVAL; 2800 return -EINVAL;
2796 2801
@@ -2800,7 +2805,7 @@ int cx231xx_gpio_i2c_end(struct cx231xx *dev)
2800 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); 2805 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2801 2806
2802 status = 2807 status =
2803 cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2808 cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2804 if (status < 0) 2809 if (status < 0)
2805 return -EINVAL; 2810 return -EINVAL;
2806 2811
@@ -2822,33 +2827,33 @@ int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data)
2822 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2827 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2823 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); 2828 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2824 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2829 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2825 (u8 *)&dev->gpio_val); 2830 dev->gpio_val);
2826 2831
2827 /* set SCL to output 1; set SDA to output 0 */ 2832 /* set SCL to output 1; set SDA to output 0 */
2828 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2833 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2829 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2834 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2830 (u8 *)&dev->gpio_val); 2835 dev->gpio_val);
2831 2836
2832 /* set SCL to output 0; set SDA to output 0 */ 2837 /* set SCL to output 0; set SDA to output 0 */
2833 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2838 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2834 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2839 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2835 (u8 *)&dev->gpio_val); 2840 dev->gpio_val);
2836 } else { 2841 } else {
2837 /* set SCL to output 0; set SDA to output 1 */ 2842 /* set SCL to output 0; set SDA to output 1 */
2838 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2843 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2839 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio; 2844 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2840 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2845 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2841 (u8 *)&dev->gpio_val); 2846 dev->gpio_val);
2842 2847
2843 /* set SCL to output 1; set SDA to output 1 */ 2848 /* set SCL to output 1; set SDA to output 1 */
2844 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2849 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2845 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2850 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2846 (u8 *)&dev->gpio_val); 2851 dev->gpio_val);
2847 2852
2848 /* set SCL to output 0; set SDA to output 1 */ 2853 /* set SCL to output 0; set SDA to output 1 */
2849 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2854 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2850 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2855 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2851 (u8 *)&dev->gpio_val); 2856 dev->gpio_val);
2852 } 2857 }
2853 } 2858 }
2854 return status; 2859 return status;
@@ -2867,17 +2872,17 @@ int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf)
2867 /* set SCL to output 0; set SDA to input */ 2872 /* set SCL to output 0; set SDA to input */
2868 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2873 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2869 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2874 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2870 (u8 *)&dev->gpio_val); 2875 dev->gpio_val);
2871 2876
2872 /* set SCL to output 1; set SDA to input */ 2877 /* set SCL to output 1; set SDA to input */
2873 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2878 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2874 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, 2879 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2875 (u8 *)&dev->gpio_val); 2880 dev->gpio_val);
2876 2881
2877 /* get SDA data bit */ 2882 /* get SDA data bit */
2878 gpio_logic_value = dev->gpio_val; 2883 gpio_logic_value = dev->gpio_val;
2879 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, 2884 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2880 (u8 *)&dev->gpio_val); 2885 &dev->gpio_val);
2881 if ((dev->gpio_val & (1 << dev->board.tuner_sda_gpio)) != 0) 2886 if ((dev->gpio_val & (1 << dev->board.tuner_sda_gpio)) != 0)
2882 value |= (1 << (8 - i - 1)); 2887 value |= (1 << (8 - i - 1));
2883 2888
@@ -2888,7 +2893,7 @@ int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf)
2888 !!!set SDA to input, never to modify SDA direction at 2893 !!!set SDA to input, never to modify SDA direction at
2889 the same times */ 2894 the same times */
2890 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2895 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2891 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2896 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2892 2897
2893 /* store the value */ 2898 /* store the value */
2894 *buf = value & 0xff; 2899 *buf = value & 0xff;
@@ -2909,12 +2914,12 @@ int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev)
2909 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio); 2914 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2910 2915
2911 gpio_logic_value = dev->gpio_val; 2916 gpio_logic_value = dev->gpio_val;
2912 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2917 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2913 2918
2914 do { 2919 do {
2915 msleep(2); 2920 msleep(2);
2916 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, 2921 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2917 (u8 *)&dev->gpio_val); 2922 &dev->gpio_val);
2918 nCnt--; 2923 nCnt--;
2919 } while (((dev->gpio_val & 2924 } while (((dev->gpio_val &
2920 (1 << dev->board.tuner_scl_gpio)) == 0) && 2925 (1 << dev->board.tuner_scl_gpio)) == 0) &&
@@ -2929,7 +2934,7 @@ int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev)
2929 * through clock stretch, slave has given a SCL signal, 2934 * through clock stretch, slave has given a SCL signal,
2930 * so the SDA data can be directly read. 2935 * so the SDA data can be directly read.
2931 */ 2936 */
2932 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2937 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, &dev->gpio_val);
2933 2938
2934 if ((dev->gpio_val & 1 << dev->board.tuner_sda_gpio) == 0) { 2939 if ((dev->gpio_val & 1 << dev->board.tuner_sda_gpio) == 0) {
2935 dev->gpio_val = gpio_logic_value; 2940 dev->gpio_val = gpio_logic_value;
@@ -2945,7 +2950,7 @@ int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev)
2945 dev->gpio_val = gpio_logic_value; 2950 dev->gpio_val = gpio_logic_value;
2946 dev->gpio_dir |= (1 << dev->board.tuner_scl_gpio); 2951 dev->gpio_dir |= (1 << dev->board.tuner_scl_gpio);
2947 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2952 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2948 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2953 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2949 2954
2950 return status; 2955 return status;
2951} 2956}
@@ -2956,24 +2961,24 @@ int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev)
2956 2961
2957 /* set SDA to ouput */ 2962 /* set SDA to ouput */
2958 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio; 2963 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2959 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2964 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2960 2965
2961 /* set SCL = 0 (output); set SDA = 0 (output) */ 2966 /* set SCL = 0 (output); set SDA = 0 (output) */
2962 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); 2967 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2963 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2968 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2964 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2969 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2965 2970
2966 /* set SCL = 1 (output); set SDA = 0 (output) */ 2971 /* set SCL = 1 (output); set SDA = 0 (output) */
2967 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 2972 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2968 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2973 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2969 2974
2970 /* set SCL = 0 (output); set SDA = 0 (output) */ 2975 /* set SCL = 0 (output); set SDA = 0 (output) */
2971 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2976 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2972 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2977 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2973 2978
2974 /* set SDA to input,and then the slave will read data from SDA. */ 2979 /* set SDA to input,and then the slave will read data from SDA. */
2975 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); 2980 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2976 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2981 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2977 2982
2978 return status; 2983 return status;
2979} 2984}
@@ -2985,15 +2990,15 @@ int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev)
2985 /* set scl to output ; set sda to input */ 2990 /* set scl to output ; set sda to input */
2986 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio; 2991 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2987 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); 2992 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2988 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2993 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2989 2994
2990 /* set scl to output 0; set sda to input */ 2995 /* set scl to output 0; set sda to input */
2991 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); 2996 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2992 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 2997 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2993 2998
2994 /* set scl to output 1; set sda to input */ 2999 /* set scl to output 1; set sda to input */
2995 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; 3000 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2996 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); 3001 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2997 3002
2998 return status; 3003 return status;
2999} 3004}
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 8d529565f163..13249e5a7891 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -263,7 +263,11 @@ struct cx231xx_board cx231xx_boards[] = {
263 .norm = V4L2_STD_PAL, 263 .norm = V4L2_STD_PAL,
264 .no_alt_vanc = 1, 264 .no_alt_vanc = 1,
265 .external_av = 1, 265 .external_av = 1,
266 .has_417 = 1, 266 .dont_use_port_3 = 1,
267 /* Actually, it has a 417, but it isn't working correctly.
268 * So set to 0 for now until someone can manage to get this
269 * to work reliably. */
270 .has_417 = 0,
267 271
268 .input = {{ 272 .input = {{
269 .type = CX231XX_VMUX_COMPOSITE1, 273 .type = CX231XX_VMUX_COMPOSITE1,
@@ -630,6 +634,39 @@ struct cx231xx_board cx231xx_boards[] = {
630 .gpio = NULL, 634 .gpio = NULL,
631 } }, 635 } },
632 }, 636 },
637 [CX231XX_BOARD_OTG102] = {
638 .name = "Geniatech OTG102",
639 .tuner_type = TUNER_ABSENT,
640 .decoder = CX231XX_AVDECODER,
641 .output_mode = OUT_MODE_VIP11,
642 .ctl_pin_status_mask = 0xFFFFFFC4,
643 .agc_analog_digital_select_gpio = 0x0c,
644 /* According with PV CxPlrCAP.inf file */
645 .gpio_pin_status_mask = 0x4001000,
646 .norm = V4L2_STD_NTSC,
647 .no_alt_vanc = 1,
648 .external_av = 1,
649 .dont_use_port_3 = 1,
650 /*.has_417 = 1, */
651 /* This board is believed to have a hardware encoding chip
652 * supporting mpeg1/2/4, but as the 417 is apparently not
653 * working for the reference board it is not here either. */
654
655 .input = {{
656 .type = CX231XX_VMUX_COMPOSITE1,
657 .vmux = CX231XX_VIN_2_1,
658 .amux = CX231XX_AMUX_LINE_IN,
659 .gpio = NULL,
660 }, {
661 .type = CX231XX_VMUX_SVIDEO,
662 .vmux = CX231XX_VIN_1_1 |
663 (CX231XX_VIN_1_2 << 8) |
664 CX25840_SVIDEO_ON,
665 .amux = CX231XX_AMUX_LINE_IN,
666 .gpio = NULL,
667 }
668 },
669 },
633}; 670};
634const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); 671const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
635 672
@@ -671,6 +708,8 @@ struct usb_device_id cx231xx_id_table[] = {
671 .driver_info = CX231XX_BOARD_ICONBIT_U100}, 708 .driver_info = CX231XX_BOARD_ICONBIT_U100},
672 {USB_DEVICE(0x0fd9, 0x0037), 709 {USB_DEVICE(0x0fd9, 0x0037),
673 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2}, 710 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
711 {USB_DEVICE(0x1f4d, 0x0102),
712 .driver_info = CX231XX_BOARD_OTG102},
674 {}, 713 {},
675}; 714};
676 715
@@ -846,8 +885,6 @@ void cx231xx_card_setup(struct cx231xx *dev)
846int cx231xx_config(struct cx231xx *dev) 885int cx231xx_config(struct cx231xx *dev)
847{ 886{
848 /* TBD need to add cx231xx specific code */ 887 /* TBD need to add cx231xx specific code */
849 dev->mute = 1; /* maybe not the right place... */
850 dev->volume = 0x1f;
851 888
852 return 0; 889 return 0;
853} 890}
@@ -1187,8 +1224,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1187 uif = udev->actconfig->interface[dev->current_pcb_config. 1224 uif = udev->actconfig->interface[dev->current_pcb_config.
1188 hs_config_info[0].interface_info.video_index + 1]; 1225 hs_config_info[0].interface_info.video_index + 1];
1189 1226
1190 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0]. 1227 dev->video_mode.end_point_addr = uif->altsetting[0].
1191 endpoint[isoc_pipe].desc.bEndpointAddress); 1228 endpoint[isoc_pipe].desc.bEndpointAddress;
1192 1229
1193 dev->video_mode.num_alt = uif->num_altsetting; 1230 dev->video_mode.num_alt = uif->num_altsetting;
1194 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1231 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
@@ -1221,8 +1258,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1221 vanc_index + 1]; 1258 vanc_index + 1];
1222 1259
1223 dev->vbi_mode.end_point_addr = 1260 dev->vbi_mode.end_point_addr =
1224 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. 1261 uif->altsetting[0].endpoint[isoc_pipe].desc.
1225 bEndpointAddress); 1262 bEndpointAddress;
1226 1263
1227 dev->vbi_mode.num_alt = uif->num_altsetting; 1264 dev->vbi_mode.num_alt = uif->num_altsetting;
1228 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1265 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
@@ -1256,8 +1293,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1256 hanc_index + 1]; 1293 hanc_index + 1];
1257 1294
1258 dev->sliced_cc_mode.end_point_addr = 1295 dev->sliced_cc_mode.end_point_addr =
1259 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. 1296 uif->altsetting[0].endpoint[isoc_pipe].desc.
1260 bEndpointAddress); 1297 bEndpointAddress;
1261 1298
1262 dev->sliced_cc_mode.num_alt = uif->num_altsetting; 1299 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1263 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1300 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
@@ -1292,8 +1329,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1292 ts1_index + 1]; 1329 ts1_index + 1];
1293 1330
1294 dev->ts1_mode.end_point_addr = 1331 dev->ts1_mode.end_point_addr =
1295 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. 1332 uif->altsetting[0].endpoint[isoc_pipe].
1296 desc.bEndpointAddress); 1333 desc.bEndpointAddress;
1297 1334
1298 dev->ts1_mode.num_alt = uif->num_altsetting; 1335 dev->ts1_mode.num_alt = uif->num_altsetting;
1299 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1336 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index 05358d486135..4ba3ce09b713 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -1488,7 +1488,7 @@ int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode)
1488 if (status < 0) 1488 if (status < 0)
1489 return status; 1489 return status;
1490 1490
1491 tmp = *((u32 *) value); 1491 tmp = le32_to_cpu(*((u32 *) value));
1492 tmp |= mode; 1492 tmp |= mode;
1493 1493
1494 value[0] = (u8) tmp; 1494 value[0] = (u8) tmp;
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 7c4e360ba9bc..14e26106fd72 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -89,8 +89,8 @@ static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = {
89}; 89};
90 90
91static struct tda18271_std_map mb86a20s_tda18271_config = { 91static struct tda18271_std_map mb86a20s_tda18271_config = {
92 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4, 92 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
93 .if_lvl = 7, .rfagc_top = 0x37, }, 93 .if_lvl = 0, .rfagc_top = 0x37, },
94}; 94};
95 95
96static struct tda18271_config cnxt_rde253s_tunerconfig = { 96static struct tda18271_config cnxt_rde253s_tunerconfig = {
diff --git a/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c b/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
index 7473c33e823e..d7308ab7a90f 100644
--- a/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
+++ b/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
@@ -672,7 +672,7 @@ u32 initialize_cx231xx(struct cx231xx *dev)
672 pcb config it is related to */ 672 pcb config it is related to */
673 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT, data, 4); 673 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT, data, 4);
674 674
675 config_info = *((u32 *) data); 675 config_info = le32_to_cpu(*((u32 *) data));
676 usb_speed = (u8) (config_info & 0x1); 676 usb_speed = (u8) (config_info & 0x1);
677 677
678 /* Verify this device belongs to Bus power or Self power device */ 678 /* Verify this device belongs to Bus power or Self power device */
diff --git a/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.h b/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.h
index f5e46e89f3ab..b3c6190e0c69 100644
--- a/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.h
+++ b/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.h
@@ -68,11 +68,6 @@ enum USB_SPEED{
68 HIGH_SPEED = 0x1 /* 1: high speed */ 68 HIGH_SPEED = 0x1 /* 1: high speed */
69}; 69};
70 70
71enum _true_false{
72 FALSE = 0,
73 TRUE = 1
74};
75
76#define TS_MASK 0x6 71#define TS_MASK 0x6
77enum TS_PORT{ 72enum TS_PORT{
78 NO_TS_PORT = 0x0, /* 2'b00: Neither port used. PCB not a Hybrid, 73 NO_TS_PORT = 0x0, /* 2'b00: Neither port used. PCB not a Hybrid,
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index 46e3892557c2..1340ff268817 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -70,10 +70,10 @@ static inline void print_err_status(struct cx231xx *dev, int packet, int status)
70 break; 70 break;
71 } 71 }
72 if (packet < 0) { 72 if (packet < 0) {
73 cx231xx_err(DRIVER_NAME "URB status %d [%s].\n", status, 73 cx231xx_err("URB status %d [%s].\n", status,
74 errmsg); 74 errmsg);
75 } else { 75 } else {
76 cx231xx_err(DRIVER_NAME "URB packet %d, status %d [%s].\n", 76 cx231xx_err("URB packet %d, status %d [%s].\n",
77 packet, status, errmsg); 77 packet, status, errmsg);
78 } 78 }
79} 79}
@@ -317,7 +317,7 @@ static void cx231xx_irq_vbi_callback(struct urb *urb)
317 case -ESHUTDOWN: 317 case -ESHUTDOWN:
318 return; 318 return;
319 default: /* error */ 319 default: /* error */
320 cx231xx_err(DRIVER_NAME "urb completition error %d.\n", 320 cx231xx_err("urb completition error %d.\n",
321 urb->status); 321 urb->status);
322 break; 322 break;
323 } 323 }
@@ -332,7 +332,7 @@ static void cx231xx_irq_vbi_callback(struct urb *urb)
332 332
333 urb->status = usb_submit_urb(urb, GFP_ATOMIC); 333 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
334 if (urb->status) { 334 if (urb->status) {
335 cx231xx_err(DRIVER_NAME "urb resubmit failed (error=%i)\n", 335 cx231xx_err("urb resubmit failed (error=%i)\n",
336 urb->status); 336 urb->status);
337 } 337 }
338} 338}
@@ -345,7 +345,7 @@ void cx231xx_uninit_vbi_isoc(struct cx231xx *dev)
345 struct urb *urb; 345 struct urb *urb;
346 int i; 346 int i;
347 347
348 cx231xx_info(DRIVER_NAME "cx231xx: called cx231xx_uninit_vbi_isoc\n"); 348 cx231xx_info("called cx231xx_uninit_vbi_isoc\n");
349 349
350 dev->vbi_mode.bulk_ctl.nfields = -1; 350 dev->vbi_mode.bulk_ctl.nfields = -1;
351 for (i = 0; i < dev->vbi_mode.bulk_ctl.num_bufs; i++) { 351 for (i = 0; i < dev->vbi_mode.bulk_ctl.num_bufs; i++) {
@@ -394,7 +394,7 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,
394 struct urb *urb; 394 struct urb *urb;
395 int rc; 395 int rc;
396 396
397 cx231xx_info(DRIVER_NAME "cx231xx: called cx231xx_prepare_isoc\n"); 397 cx231xx_info("called cx231xx_vbi_isoc\n");
398 398
399 /* De-allocates all pending stuff */ 399 /* De-allocates all pending stuff */
400 cx231xx_uninit_vbi_isoc(dev); 400 cx231xx_uninit_vbi_isoc(dev);
@@ -442,8 +442,7 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,
442 442
443 urb = usb_alloc_urb(0, GFP_KERNEL); 443 urb = usb_alloc_urb(0, GFP_KERNEL);
444 if (!urb) { 444 if (!urb) {
445 cx231xx_err(DRIVER_NAME 445 cx231xx_err("cannot alloc bulk_ctl.urb %i\n", i);
446 ": cannot alloc bulk_ctl.urb %i\n", i);
447 cx231xx_uninit_vbi_isoc(dev); 446 cx231xx_uninit_vbi_isoc(dev);
448 return -ENOMEM; 447 return -ENOMEM;
449 } 448 }
@@ -453,8 +452,7 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,
453 dev->vbi_mode.bulk_ctl.transfer_buffer[i] = 452 dev->vbi_mode.bulk_ctl.transfer_buffer[i] =
454 kzalloc(sb_size, GFP_KERNEL); 453 kzalloc(sb_size, GFP_KERNEL);
455 if (!dev->vbi_mode.bulk_ctl.transfer_buffer[i]) { 454 if (!dev->vbi_mode.bulk_ctl.transfer_buffer[i]) {
456 cx231xx_err(DRIVER_NAME 455 cx231xx_err("unable to allocate %i bytes for transfer"
457 ": unable to allocate %i bytes for transfer"
458 " buffer %i%s\n", sb_size, i, 456 " buffer %i%s\n", sb_size, i,
459 in_interrupt() ? " while in int" : ""); 457 in_interrupt() ? " while in int" : "");
460 cx231xx_uninit_vbi_isoc(dev); 458 cx231xx_uninit_vbi_isoc(dev);
@@ -473,8 +471,7 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,
473 for (i = 0; i < dev->vbi_mode.bulk_ctl.num_bufs; i++) { 471 for (i = 0; i < dev->vbi_mode.bulk_ctl.num_bufs; i++) {
474 rc = usb_submit_urb(dev->vbi_mode.bulk_ctl.urb[i], GFP_ATOMIC); 472 rc = usb_submit_urb(dev->vbi_mode.bulk_ctl.urb[i], GFP_ATOMIC);
475 if (rc) { 473 if (rc) {
476 cx231xx_err(DRIVER_NAME 474 cx231xx_err("submit of urb %i failed (error=%i)\n", i,
477 ": submit of urb %i failed (error=%i)\n", i,
478 rc); 475 rc);
479 cx231xx_uninit_vbi_isoc(dev); 476 cx231xx_uninit_vbi_isoc(dev);
480 return rc; 477 return rc;
@@ -526,7 +523,7 @@ static inline void vbi_buffer_filled(struct cx231xx *dev,
526 struct cx231xx_buffer *buf) 523 struct cx231xx_buffer *buf)
527{ 524{
528 /* Advice that buffer was filled */ 525 /* Advice that buffer was filled */
529 /* cx231xx_info(DRIVER_NAME "[%p/%d] wakeup\n", buf, buf->vb.i); */ 526 /* cx231xx_info("[%p/%d] wakeup\n", buf, buf->vb.i); */
530 527
531 buf->vb.state = VIDEOBUF_DONE; 528 buf->vb.state = VIDEOBUF_DONE;
532 buf->vb.field_count++; 529 buf->vb.field_count++;
@@ -618,7 +615,7 @@ static inline void get_next_vbi_buf(struct cx231xx_dmaqueue *dma_q,
618 char *outp; 615 char *outp;
619 616
620 if (list_empty(&dma_q->active)) { 617 if (list_empty(&dma_q->active)) {
621 cx231xx_err(DRIVER_NAME ": No active queue to serve\n"); 618 cx231xx_err("No active queue to serve\n");
622 dev->vbi_mode.bulk_ctl.buf = NULL; 619 dev->vbi_mode.bulk_ctl.buf = NULL;
623 *buf = NULL; 620 *buf = NULL;
624 return; 621 return;
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 06376d904c9f..cd221474e1b9 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -35,6 +35,7 @@
35 35
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-event.h>
38#include <media/v4l2-chip-ident.h> 39#include <media/v4l2-chip-ident.h>
39#include <media/msp3400.h> 40#include <media/msp3400.h>
40#include <media/tuner.h> 41#include <media/tuner.h>
@@ -100,125 +101,6 @@ static struct cx231xx_fmt format[] = {
100 }, 101 },
101}; 102};
102 103
103/* supported controls */
104/* Common to all boards */
105
106/* ------------------------------------------------------------------- */
107
108static const struct v4l2_queryctrl no_ctl = {
109 .name = "42",
110 .flags = V4L2_CTRL_FLAG_DISABLED,
111};
112
113static struct cx231xx_ctrl cx231xx_ctls[] = {
114 /* --- video --- */
115 {
116 .v = {
117 .id = V4L2_CID_BRIGHTNESS,
118 .name = "Brightness",
119 .minimum = 0x00,
120 .maximum = 0xff,
121 .step = 1,
122 .default_value = 0x7f,
123 .type = V4L2_CTRL_TYPE_INTEGER,
124 },
125 .off = 128,
126 .reg = LUMA_CTRL,
127 .mask = 0x00ff,
128 .shift = 0,
129 }, {
130 .v = {
131 .id = V4L2_CID_CONTRAST,
132 .name = "Contrast",
133 .minimum = 0,
134 .maximum = 0xff,
135 .step = 1,
136 .default_value = 0x3f,
137 .type = V4L2_CTRL_TYPE_INTEGER,
138 },
139 .off = 0,
140 .reg = LUMA_CTRL,
141 .mask = 0xff00,
142 .shift = 8,
143 }, {
144 .v = {
145 .id = V4L2_CID_HUE,
146 .name = "Hue",
147 .minimum = 0,
148 .maximum = 0xff,
149 .step = 1,
150 .default_value = 0x7f,
151 .type = V4L2_CTRL_TYPE_INTEGER,
152 },
153 .off = 128,
154 .reg = CHROMA_CTRL,
155 .mask = 0xff0000,
156 .shift = 16,
157 }, {
158 /* strictly, this only describes only U saturation.
159 * V saturation is handled specially through code.
160 */
161 .v = {
162 .id = V4L2_CID_SATURATION,
163 .name = "Saturation",
164 .minimum = 0,
165 .maximum = 0xff,
166 .step = 1,
167 .default_value = 0x7f,
168 .type = V4L2_CTRL_TYPE_INTEGER,
169 },
170 .off = 0,
171 .reg = CHROMA_CTRL,
172 .mask = 0x00ff,
173 .shift = 0,
174 }, {
175 /* --- audio --- */
176 .v = {
177 .id = V4L2_CID_AUDIO_MUTE,
178 .name = "Mute",
179 .minimum = 0,
180 .maximum = 1,
181 .default_value = 1,
182 .type = V4L2_CTRL_TYPE_BOOLEAN,
183 },
184 .reg = PATH1_CTL1,
185 .mask = (0x1f << 24),
186 .shift = 24,
187 }, {
188 .v = {
189 .id = V4L2_CID_AUDIO_VOLUME,
190 .name = "Volume",
191 .minimum = 0,
192 .maximum = 0x3f,
193 .step = 1,
194 .default_value = 0x3f,
195 .type = V4L2_CTRL_TYPE_INTEGER,
196 },
197 .reg = PATH1_VOL_CTL,
198 .mask = 0xff,
199 .shift = 0,
200 }
201};
202static const int CX231XX_CTLS = ARRAY_SIZE(cx231xx_ctls);
203
204static const u32 cx231xx_user_ctrls[] = {
205 V4L2_CID_USER_CLASS,
206 V4L2_CID_BRIGHTNESS,
207 V4L2_CID_CONTRAST,
208 V4L2_CID_SATURATION,
209 V4L2_CID_HUE,
210 V4L2_CID_AUDIO_VOLUME,
211#if 0
212 V4L2_CID_AUDIO_BALANCE,
213#endif
214 V4L2_CID_AUDIO_MUTE,
215 0
216};
217
218static const u32 *ctrl_classes[] = {
219 cx231xx_user_ctrls,
220 NULL
221};
222 104
223/* ------------------------------------------------------------------ 105/* ------------------------------------------------------------------
224 Video buffer and parser functions 106 Video buffer and parser functions
@@ -1005,6 +887,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1005 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 887 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1006 888
1007 f->fmt.pix.field = V4L2_FIELD_INTERLACED; 889 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
890 f->fmt.pix.priv = 0;
1008 891
1009 return 0; 892 return 0;
1010} 893}
@@ -1045,10 +928,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1045 f->fmt.pix.width = width; 928 f->fmt.pix.width = width;
1046 f->fmt.pix.height = height; 929 f->fmt.pix.height = height;
1047 f->fmt.pix.pixelformat = fmt->fourcc; 930 f->fmt.pix.pixelformat = fmt->fourcc;
1048 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; 931 f->fmt.pix.bytesperline = (width * fmt->depth + 7) >> 3;
1049 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; 932 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
1050 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 933 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1051 f->fmt.pix.field = V4L2_FIELD_INTERLACED; 934 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
935 f->fmt.pix.priv = 0;
1052 936
1053 return 0; 937 return 0;
1054} 938}
@@ -1103,39 +987,39 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1103 return 0; 987 return 0;
1104} 988}
1105 989
1106static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) 990static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1107{ 991{
1108 struct cx231xx_fh *fh = priv; 992 struct cx231xx_fh *fh = priv;
1109 struct cx231xx *dev = fh->dev; 993 struct cx231xx *dev = fh->dev;
1110 struct v4l2_mbus_framefmt mbus_fmt; 994 struct v4l2_mbus_framefmt mbus_fmt;
1111 struct v4l2_format f;
1112 int rc; 995 int rc;
1113 996
1114 rc = check_dev(dev); 997 rc = check_dev(dev);
1115 if (rc < 0) 998 if (rc < 0)
1116 return rc; 999 return rc;
1117 1000
1118 cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm); 1001 if (dev->norm == norm)
1002 return 0;
1119 1003
1120 dev->norm = *norm; 1004 if (videobuf_queue_is_busy(&fh->vb_vidq))
1005 return -EBUSY;
1006
1007 dev->norm = norm;
1121 1008
1122 /* Adjusts width/height, if needed */ 1009 /* Adjusts width/height, if needed */
1123 f.fmt.pix.width = dev->width; 1010 dev->width = 720;
1124 f.fmt.pix.height = dev->height; 1011 dev->height = (dev->norm & V4L2_STD_625_50) ? 576 : 480;
1125 vidioc_try_fmt_vid_cap(file, priv, &f);
1126 1012
1127 call_all(dev, core, s_std, dev->norm); 1013 call_all(dev, core, s_std, dev->norm);
1128 1014
1129 /* We need to reset basic properties in the decoder related to 1015 /* We need to reset basic properties in the decoder related to
1130 resolution (since a standard change effects things like the number 1016 resolution (since a standard change effects things like the number
1131 of lines in VACT, etc) */ 1017 of lines in VACT, etc) */
1132 v4l2_fill_mbus_format(&mbus_fmt, &f.fmt.pix, V4L2_MBUS_FMT_FIXED); 1018 memset(&mbus_fmt, 0, sizeof(mbus_fmt));
1019 mbus_fmt.code = V4L2_MBUS_FMT_FIXED;
1020 mbus_fmt.width = dev->width;
1021 mbus_fmt.height = dev->height;
1133 call_all(dev, video, s_mbus_fmt, &mbus_fmt); 1022 call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1134 v4l2_fill_pix_format(&f.fmt.pix, &mbus_fmt);
1135
1136 /* set new image size */
1137 dev->width = f.fmt.pix.width;
1138 dev->height = f.fmt.pix.height;
1139 1023
1140 /* do mode control overrides */ 1024 /* do mode control overrides */
1141 cx231xx_do_mode_ctrl_overrides(dev); 1025 cx231xx_do_mode_ctrl_overrides(dev);
@@ -1152,7 +1036,7 @@ static const char *iname[] = {
1152 [CX231XX_VMUX_DEBUG] = "for debug only", 1036 [CX231XX_VMUX_DEBUG] = "for debug only",
1153}; 1037};
1154 1038
1155static int vidioc_enum_input(struct file *file, void *priv, 1039int cx231xx_enum_input(struct file *file, void *priv,
1156 struct v4l2_input *i) 1040 struct v4l2_input *i)
1157{ 1041{
1158 struct cx231xx_fh *fh = priv; 1042 struct cx231xx_fh *fh = priv;
@@ -1192,7 +1076,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
1192 return 0; 1076 return 0;
1193} 1077}
1194 1078
1195static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 1079int cx231xx_g_input(struct file *file, void *priv, unsigned int *i)
1196{ 1080{
1197 struct cx231xx_fh *fh = priv; 1081 struct cx231xx_fh *fh = priv;
1198 struct cx231xx *dev = fh->dev; 1082 struct cx231xx *dev = fh->dev;
@@ -1202,7 +1086,7 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1202 return 0; 1086 return 0;
1203} 1087}
1204 1088
1205static int vidioc_s_input(struct file *file, void *priv, unsigned int i) 1089int cx231xx_s_input(struct file *file, void *priv, unsigned int i)
1206{ 1090{
1207 struct cx231xx_fh *fh = priv; 1091 struct cx231xx_fh *fh = priv;
1208 struct cx231xx *dev = fh->dev; 1092 struct cx231xx *dev = fh->dev;
@@ -1231,117 +1115,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1231 return 0; 1115 return 0;
1232} 1116}
1233 1117
1234static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) 1118int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1235{
1236 struct cx231xx_fh *fh = priv;
1237 struct cx231xx *dev = fh->dev;
1238
1239 switch (a->index) {
1240 case CX231XX_AMUX_VIDEO:
1241 strcpy(a->name, "Television");
1242 break;
1243 case CX231XX_AMUX_LINE_IN:
1244 strcpy(a->name, "Line In");
1245 break;
1246 default:
1247 return -EINVAL;
1248 }
1249
1250 a->index = dev->ctl_ainput;
1251 a->capability = V4L2_AUDCAP_STEREO;
1252
1253 return 0;
1254}
1255
1256static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a)
1257{
1258 struct cx231xx_fh *fh = priv;
1259 struct cx231xx *dev = fh->dev;
1260 int status = 0;
1261
1262 /* Doesn't allow manual routing */
1263 if (a->index != dev->ctl_ainput)
1264 return -EINVAL;
1265
1266 dev->ctl_ainput = INPUT(a->index)->amux;
1267 status = cx231xx_set_audio_input(dev, dev->ctl_ainput);
1268
1269 return status;
1270}
1271
1272static int vidioc_queryctrl(struct file *file, void *priv,
1273 struct v4l2_queryctrl *qc)
1274{
1275 struct cx231xx_fh *fh = priv;
1276 struct cx231xx *dev = fh->dev;
1277 int id = qc->id;
1278 int i;
1279 int rc;
1280
1281 rc = check_dev(dev);
1282 if (rc < 0)
1283 return rc;
1284
1285 qc->id = v4l2_ctrl_next(ctrl_classes, qc->id);
1286 if (unlikely(qc->id == 0))
1287 return -EINVAL;
1288
1289 memset(qc, 0, sizeof(*qc));
1290
1291 qc->id = id;
1292
1293 if (qc->id < V4L2_CID_BASE || qc->id >= V4L2_CID_LASTP1)
1294 return -EINVAL;
1295
1296 for (i = 0; i < CX231XX_CTLS; i++)
1297 if (cx231xx_ctls[i].v.id == qc->id)
1298 break;
1299
1300 if (i == CX231XX_CTLS) {
1301 *qc = no_ctl;
1302 return 0;
1303 }
1304 *qc = cx231xx_ctls[i].v;
1305
1306 call_all(dev, core, queryctrl, qc);
1307
1308 if (qc->type)
1309 return 0;
1310 else
1311 return -EINVAL;
1312}
1313
1314static int vidioc_g_ctrl(struct file *file, void *priv,
1315 struct v4l2_control *ctrl)
1316{
1317 struct cx231xx_fh *fh = priv;
1318 struct cx231xx *dev = fh->dev;
1319 int rc;
1320
1321 rc = check_dev(dev);
1322 if (rc < 0)
1323 return rc;
1324
1325 call_all(dev, core, g_ctrl, ctrl);
1326 return rc;
1327}
1328
1329static int vidioc_s_ctrl(struct file *file, void *priv,
1330 struct v4l2_control *ctrl)
1331{
1332 struct cx231xx_fh *fh = priv;
1333 struct cx231xx *dev = fh->dev;
1334 int rc;
1335
1336 rc = check_dev(dev);
1337 if (rc < 0)
1338 return rc;
1339
1340 call_all(dev, core, s_ctrl, ctrl);
1341 return rc;
1342}
1343
1344static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1345{ 1119{
1346 struct cx231xx_fh *fh = priv; 1120 struct cx231xx_fh *fh = priv;
1347 struct cx231xx *dev = fh->dev; 1121 struct cx231xx *dev = fh->dev;
@@ -1360,11 +1134,12 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1360 t->capability = V4L2_TUNER_CAP_NORM; 1134 t->capability = V4L2_TUNER_CAP_NORM;
1361 t->rangehigh = 0xffffffffUL; 1135 t->rangehigh = 0xffffffffUL;
1362 t->signal = 0xffff; /* LOCKED */ 1136 t->signal = 0xffff; /* LOCKED */
1137 call_all(dev, tuner, g_tuner, t);
1363 1138
1364 return 0; 1139 return 0;
1365} 1140}
1366 1141
1367static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) 1142int cx231xx_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t)
1368{ 1143{
1369 struct cx231xx_fh *fh = priv; 1144 struct cx231xx_fh *fh = priv;
1370 struct cx231xx *dev = fh->dev; 1145 struct cx231xx *dev = fh->dev;
@@ -1382,25 +1157,26 @@ static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1382 return 0; 1157 return 0;
1383} 1158}
1384 1159
1385static int vidioc_g_frequency(struct file *file, void *priv, 1160int cx231xx_g_frequency(struct file *file, void *priv,
1386 struct v4l2_frequency *f) 1161 struct v4l2_frequency *f)
1387{ 1162{
1388 struct cx231xx_fh *fh = priv; 1163 struct cx231xx_fh *fh = priv;
1389 struct cx231xx *dev = fh->dev; 1164 struct cx231xx *dev = fh->dev;
1390 1165
1391 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1166 if (f->tuner)
1392 f->frequency = dev->ctl_freq; 1167 return -EINVAL;
1393 1168
1394 call_all(dev, tuner, g_frequency, f); 1169 f->frequency = dev->ctl_freq;
1395 1170
1396 return 0; 1171 return 0;
1397} 1172}
1398 1173
1399static int vidioc_s_frequency(struct file *file, void *priv, 1174int cx231xx_s_frequency(struct file *file, void *priv,
1400 struct v4l2_frequency *f) 1175 const struct v4l2_frequency *f)
1401{ 1176{
1402 struct cx231xx_fh *fh = priv; 1177 struct cx231xx_fh *fh = priv;
1403 struct cx231xx *dev = fh->dev; 1178 struct cx231xx *dev = fh->dev;
1179 struct v4l2_frequency new_freq = *f;
1404 int rc; 1180 int rc;
1405 u32 if_frequency = 5400000; 1181 u32 if_frequency = 5400000;
1406 1182
@@ -1415,16 +1191,12 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1415 if (0 != f->tuner) 1191 if (0 != f->tuner)
1416 return -EINVAL; 1192 return -EINVAL;
1417 1193
1418 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1419 return -EINVAL;
1420 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1421 return -EINVAL;
1422
1423 /* set pre channel change settings in DIF first */ 1194 /* set pre channel change settings in DIF first */
1424 rc = cx231xx_tuner_pre_channel_change(dev); 1195 rc = cx231xx_tuner_pre_channel_change(dev);
1425 1196
1426 dev->ctl_freq = f->frequency;
1427 call_all(dev, tuner, s_frequency, f); 1197 call_all(dev, tuner, s_frequency, f);
1198 call_all(dev, tuner, g_frequency, &new_freq);
1199 dev->ctl_freq = new_freq.frequency;
1428 1200
1429 /* set post channel change settings in DIF first */ 1201 /* set post channel change settings in DIF first */
1430 rc = cx231xx_tuner_post_channel_change(dev); 1202 rc = cx231xx_tuner_post_channel_change(dev);
@@ -1456,6 +1228,19 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1456 return rc; 1228 return rc;
1457} 1229}
1458 1230
1231int cx231xx_g_chip_ident(struct file *file, void *fh,
1232 struct v4l2_dbg_chip_ident *chip)
1233{
1234 chip->ident = V4L2_IDENT_NONE;
1235 chip->revision = 0;
1236 if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
1237 if (v4l2_chip_match_host(&chip->match))
1238 chip->ident = V4L2_IDENT_CX23100;
1239 return 0;
1240 }
1241 return -EINVAL;
1242}
1243
1459#ifdef CONFIG_VIDEO_ADV_DEBUG 1244#ifdef CONFIG_VIDEO_ADV_DEBUG
1460 1245
1461/* 1246/*
@@ -1471,7 +1256,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1471 if type == i2caddr, then <chip> is the 7-bit I2C address 1256 if type == i2caddr, then <chip> is the 7-bit I2C address
1472*/ 1257*/
1473 1258
1474static int vidioc_g_register(struct file *file, void *priv, 1259int cx231xx_g_register(struct file *file, void *priv,
1475 struct v4l2_dbg_register *reg) 1260 struct v4l2_dbg_register *reg)
1476{ 1261{
1477 struct cx231xx_fh *fh = priv; 1262 struct cx231xx_fh *fh = priv;
@@ -1618,8 +1403,8 @@ static int vidioc_g_register(struct file *file, void *priv,
1618 return ret; 1403 return ret;
1619} 1404}
1620 1405
1621static int vidioc_s_register(struct file *file, void *priv, 1406int cx231xx_s_register(struct file *file, void *priv,
1622 struct v4l2_dbg_register *reg) 1407 const struct v4l2_dbg_register *reg)
1623{ 1408{
1624 struct cx231xx_fh *fh = priv; 1409 struct cx231xx_fh *fh = priv;
1625 struct cx231xx *dev = fh->dev; 1410 struct cx231xx *dev = fh->dev;
@@ -1837,9 +1622,6 @@ static int vidioc_streamoff(struct file *file, void *priv,
1837 if (rc < 0) 1622 if (rc < 0)
1838 return rc; 1623 return rc;
1839 1624
1840 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1841 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
1842 return -EINVAL;
1843 if (type != fh->type) 1625 if (type != fh->type)
1844 return -EINVAL; 1626 return -EINVAL;
1845 1627
@@ -1851,9 +1633,10 @@ static int vidioc_streamoff(struct file *file, void *priv,
1851 return 0; 1633 return 0;
1852} 1634}
1853 1635
1854static int vidioc_querycap(struct file *file, void *priv, 1636int cx231xx_querycap(struct file *file, void *priv,
1855 struct v4l2_capability *cap) 1637 struct v4l2_capability *cap)
1856{ 1638{
1639 struct video_device *vdev = video_devdata(file);
1857 struct cx231xx_fh *fh = priv; 1640 struct cx231xx_fh *fh = priv;
1858 struct cx231xx *dev = fh->dev; 1641 struct cx231xx *dev = fh->dev;
1859 1642
@@ -1861,17 +1644,22 @@ static int vidioc_querycap(struct file *file, void *priv,
1861 strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); 1644 strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
1862 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); 1645 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1863 1646
1864 cap->capabilities = V4L2_CAP_VBI_CAPTURE | 1647 if (vdev->vfl_type == VFL_TYPE_RADIO)
1865#if 0 1648 cap->device_caps = V4L2_CAP_RADIO;
1866 V4L2_CAP_SLICED_VBI_CAPTURE | 1649 else {
1867#endif 1650 cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1868 V4L2_CAP_VIDEO_CAPTURE | 1651 if (vdev->vfl_type == VFL_TYPE_VBI)
1869 V4L2_CAP_AUDIO | 1652 cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
1870 V4L2_CAP_READWRITE | 1653 else
1871 V4L2_CAP_STREAMING; 1654 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
1872 1655 }
1873 if (dev->tuner_type != TUNER_ABSENT) 1656 if (dev->tuner_type != TUNER_ABSENT)
1874 cap->capabilities |= V4L2_CAP_TUNER; 1657 cap->device_caps |= V4L2_CAP_TUNER;
1658 cap->capabilities = cap->device_caps | V4L2_CAP_READWRITE |
1659 V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE |
1660 V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
1661 if (dev->radio_dev)
1662 cap->capabilities |= V4L2_CAP_RADIO;
1875 1663
1876 return 0; 1664 return 0;
1877} 1665}
@@ -1888,47 +1676,6 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1888 return 0; 1676 return 0;
1889} 1677}
1890 1678
1891/* Sliced VBI ioctls */
1892static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1893 struct v4l2_format *f)
1894{
1895 struct cx231xx_fh *fh = priv;
1896 struct cx231xx *dev = fh->dev;
1897 int rc;
1898
1899 rc = check_dev(dev);
1900 if (rc < 0)
1901 return rc;
1902
1903 f->fmt.sliced.service_set = 0;
1904
1905 call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced);
1906
1907 if (f->fmt.sliced.service_set == 0)
1908 rc = -EINVAL;
1909
1910 return rc;
1911}
1912
1913static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1914 struct v4l2_format *f)
1915{
1916 struct cx231xx_fh *fh = priv;
1917 struct cx231xx *dev = fh->dev;
1918 int rc;
1919
1920 rc = check_dev(dev);
1921 if (rc < 0)
1922 return rc;
1923
1924 call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced);
1925
1926 if (f->fmt.sliced.service_set == 0)
1927 return -EINVAL;
1928
1929 return 0;
1930}
1931
1932/* RAW VBI ioctls */ 1679/* RAW VBI ioctls */
1933 1680
1934static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, 1681static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
@@ -1936,6 +1683,7 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1936{ 1683{
1937 struct cx231xx_fh *fh = priv; 1684 struct cx231xx_fh *fh = priv;
1938 struct cx231xx *dev = fh->dev; 1685 struct cx231xx *dev = fh->dev;
1686
1939 f->fmt.vbi.sampling_rate = 6750000 * 4; 1687 f->fmt.vbi.sampling_rate = 6750000 * 4;
1940 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; 1688 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
1941 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1689 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
@@ -1947,6 +1695,7 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1947 f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? 1695 f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
1948 PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; 1696 PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
1949 f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; 1697 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1698 memset(f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
1950 1699
1951 return 0; 1700 return 0;
1952 1701
@@ -1958,12 +1707,6 @@ static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv,
1958 struct cx231xx_fh *fh = priv; 1707 struct cx231xx_fh *fh = priv;
1959 struct cx231xx *dev = fh->dev; 1708 struct cx231xx *dev = fh->dev;
1960 1709
1961 if (dev->vbi_stream_on && !fh->stream_on) {
1962 cx231xx_errdev("%s device in use by another fh\n", __func__);
1963 return -EBUSY;
1964 }
1965
1966 f->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1967 f->fmt.vbi.sampling_rate = 6750000 * 4; 1710 f->fmt.vbi.sampling_rate = 6750000 * 4;
1968 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; 1711 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
1969 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1712 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
@@ -1976,11 +1719,25 @@ static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv,
1976 f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? 1719 f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
1977 PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; 1720 PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
1978 f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; 1721 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1722 memset(f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
1979 1723
1980 return 0; 1724 return 0;
1981 1725
1982} 1726}
1983 1727
1728static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1729 struct v4l2_format *f)
1730{
1731 struct cx231xx_fh *fh = priv;
1732 struct cx231xx *dev = fh->dev;
1733
1734 if (dev->vbi_stream_on && !fh->stream_on) {
1735 cx231xx_errdev("%s device in use by another fh\n", __func__);
1736 return -EBUSY;
1737 }
1738 return vidioc_try_fmt_vbi_cap(file, priv, f);
1739}
1740
1984static int vidioc_reqbufs(struct file *file, void *priv, 1741static int vidioc_reqbufs(struct file *file, void *priv,
1985 struct v4l2_requestbuffers *rb) 1742 struct v4l2_requestbuffers *rb)
1986{ 1743{
@@ -2038,58 +1795,24 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2038/* RADIO ESPECIFIC IOCTLS */ 1795/* RADIO ESPECIFIC IOCTLS */
2039/* ----------------------------------------------------------- */ 1796/* ----------------------------------------------------------- */
2040 1797
2041static int radio_querycap(struct file *file, void *priv,
2042 struct v4l2_capability *cap)
2043{
2044 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
2045
2046 strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
2047 strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
2048 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
2049
2050 cap->capabilities = V4L2_CAP_TUNER;
2051 return 0;
2052}
2053
2054static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) 1798static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
2055{ 1799{
2056 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; 1800 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
2057 1801
2058 if (unlikely(t->index > 0)) 1802 if (t->index)
2059 return -EINVAL; 1803 return -EINVAL;
2060 1804
2061 strcpy(t->name, "Radio"); 1805 strcpy(t->name, "Radio");
2062 t->type = V4L2_TUNER_RADIO;
2063
2064 call_all(dev, tuner, s_tuner, t);
2065
2066 return 0;
2067}
2068 1806
2069static int radio_enum_input(struct file *file, void *priv, struct v4l2_input *i) 1807 call_all(dev, tuner, g_tuner, t);
2070{
2071 if (i->index != 0)
2072 return -EINVAL;
2073 strcpy(i->name, "Radio");
2074 i->type = V4L2_INPUT_TYPE_TUNER;
2075 1808
2076 return 0; 1809 return 0;
2077} 1810}
2078 1811static int radio_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t)
2079static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2080{
2081 if (unlikely(a->index))
2082 return -EINVAL;
2083
2084 strcpy(a->name, "Radio");
2085 return 0;
2086}
2087
2088static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
2089{ 1812{
2090 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; 1813 struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
2091 1814
2092 if (0 != t->index) 1815 if (t->index)
2093 return -EINVAL; 1816 return -EINVAL;
2094 1817
2095 call_all(dev, tuner, s_tuner, t); 1818 call_all(dev, tuner, s_tuner, t);
@@ -2097,36 +1820,6 @@ static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
2097 return 0; 1820 return 0;
2098} 1821}
2099 1822
2100static int radio_s_audio(struct file *file, void *fh, const struct v4l2_audio *a)
2101{
2102 return 0;
2103}
2104
2105static int radio_s_input(struct file *file, void *fh, unsigned int i)
2106{
2107 return 0;
2108}
2109
2110static int radio_queryctrl(struct file *file, void *priv,
2111 struct v4l2_queryctrl *c)
2112{
2113 int i;
2114
2115 if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1)
2116 return -EINVAL;
2117 if (c->id == V4L2_CID_AUDIO_MUTE) {
2118 for (i = 0; i < CX231XX_CTLS; i++) {
2119 if (cx231xx_ctls[i].v.id == c->id)
2120 break;
2121 }
2122 if (i == CX231XX_CTLS)
2123 return -EINVAL;
2124 *c = cx231xx_ctls[i].v;
2125 } else
2126 *c = no_ctl;
2127 return 0;
2128}
2129
2130/* 1823/*
2131 * cx231xx_v4l2_open() 1824 * cx231xx_v4l2_open()
2132 * inits the device and starts isoc transfer 1825 * inits the device and starts isoc transfer
@@ -2174,14 +1867,11 @@ static int cx231xx_v4l2_open(struct file *filp)
2174 return -ERESTARTSYS; 1867 return -ERESTARTSYS;
2175 } 1868 }
2176 fh->dev = dev; 1869 fh->dev = dev;
2177 fh->radio = radio;
2178 fh->type = fh_type; 1870 fh->type = fh_type;
2179 filp->private_data = fh; 1871 filp->private_data = fh;
1872 v4l2_fh_init(&fh->fh, vdev);
2180 1873
2181 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { 1874 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
2182 dev->width = norm_maxw(dev);
2183 dev->height = norm_maxh(dev);
2184
2185 /* Power up in Analog TV mode */ 1875 /* Power up in Analog TV mode */
2186 if (dev->board.external_av) 1876 if (dev->board.external_av)
2187 cx231xx_set_power_mode(dev, 1877 cx231xx_set_power_mode(dev,
@@ -2204,7 +1894,7 @@ static int cx231xx_v4l2_open(struct file *filp)
2204 dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; 1894 dev->video_input = dev->video_input > 2 ? 2 : dev->video_input;
2205 1895
2206 } 1896 }
2207 if (fh->radio) { 1897 if (radio) {
2208 cx231xx_videodbg("video_open: setting radio device\n"); 1898 cx231xx_videodbg("video_open: setting radio device\n");
2209 1899
2210 /* cx231xx_start_radio(dev); */ 1900 /* cx231xx_start_radio(dev); */
@@ -2232,6 +1922,7 @@ static int cx231xx_v4l2_open(struct file *filp)
2232 fh, &dev->lock); 1922 fh, &dev->lock);
2233 } 1923 }
2234 mutex_unlock(&dev->lock); 1924 mutex_unlock(&dev->lock);
1925 v4l2_fh_add(&fh->fh);
2235 1926
2236 return errCode; 1927 return errCode;
2237} 1928}
@@ -2275,6 +1966,8 @@ void cx231xx_release_analog_resources(struct cx231xx *dev)
2275 video_device_release(dev->vdev); 1966 video_device_release(dev->vdev);
2276 dev->vdev = NULL; 1967 dev->vdev = NULL;
2277 } 1968 }
1969 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1970 v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
2278} 1971}
2279 1972
2280/* 1973/*
@@ -2324,12 +2017,15 @@ static int cx231xx_close(struct file *filp)
2324 else 2017 else
2325 cx231xx_set_alt_setting(dev, INDEX_HANC, 0); 2018 cx231xx_set_alt_setting(dev, INDEX_HANC, 0);
2326 2019
2020 v4l2_fh_del(&fh->fh);
2021 v4l2_fh_exit(&fh->fh);
2327 kfree(fh); 2022 kfree(fh);
2328 dev->users--; 2023 dev->users--;
2329 wake_up_interruptible_nr(&dev->open, 1); 2024 wake_up_interruptible_nr(&dev->open, 1);
2330 return 0; 2025 return 0;
2331 } 2026 }
2332 2027
2028 v4l2_fh_del(&fh->fh);
2333 dev->users--; 2029 dev->users--;
2334 if (!dev->users) { 2030 if (!dev->users) {
2335 videobuf_stop(&fh->vb_vidq); 2031 videobuf_stop(&fh->vb_vidq);
@@ -2356,6 +2052,7 @@ static int cx231xx_close(struct file *filp)
2356 /* set alternate 0 */ 2052 /* set alternate 0 */
2357 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); 2053 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0);
2358 } 2054 }
2055 v4l2_fh_exit(&fh->fh);
2359 kfree(fh); 2056 kfree(fh);
2360 wake_up_interruptible_nr(&dev->open, 1); 2057 wake_up_interruptible_nr(&dev->open, 1);
2361 return 0; 2058 return 0;
@@ -2412,29 +2109,37 @@ cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2412 */ 2109 */
2413static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait) 2110static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait)
2414{ 2111{
2112 unsigned long req_events = poll_requested_events(wait);
2415 struct cx231xx_fh *fh = filp->private_data; 2113 struct cx231xx_fh *fh = filp->private_data;
2416 struct cx231xx *dev = fh->dev; 2114 struct cx231xx *dev = fh->dev;
2115 unsigned res = 0;
2417 int rc; 2116 int rc;
2418 2117
2419 rc = check_dev(dev); 2118 rc = check_dev(dev);
2420 if (rc < 0) 2119 if (rc < 0)
2421 return rc; 2120 return POLLERR;
2422 2121
2423 rc = res_get(fh); 2122 rc = res_get(fh);
2424 2123
2425 if (unlikely(rc < 0)) 2124 if (unlikely(rc < 0))
2426 return POLLERR; 2125 return POLLERR;
2427 2126
2127 if (v4l2_event_pending(&fh->fh))
2128 res |= POLLPRI;
2129 else
2130 poll_wait(filp, &fh->fh.wait, wait);
2131
2132 if (!(req_events & (POLLIN | POLLRDNORM)))
2133 return res;
2134
2428 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) || 2135 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) ||
2429 (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) { 2136 (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) {
2430 unsigned int res;
2431
2432 mutex_lock(&dev->lock); 2137 mutex_lock(&dev->lock);
2433 res = videobuf_poll_stream(filp, &fh->vb_vidq, wait); 2138 res |= videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2434 mutex_unlock(&dev->lock); 2139 mutex_unlock(&dev->lock);
2435 return res; 2140 return res;
2436 } 2141 }
2437 return POLLERR; 2142 return res | POLLERR;
2438} 2143}
2439 2144
2440/* 2145/*
@@ -2479,41 +2184,37 @@ static const struct v4l2_file_operations cx231xx_v4l_fops = {
2479}; 2184};
2480 2185
2481static const struct v4l2_ioctl_ops video_ioctl_ops = { 2186static const struct v4l2_ioctl_ops video_ioctl_ops = {
2482 .vidioc_querycap = vidioc_querycap, 2187 .vidioc_querycap = cx231xx_querycap,
2483 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 2188 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2484 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 2189 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2485 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 2190 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2486 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 2191 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2487 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 2192 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
2488 .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, 2193 .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
2489 .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, 2194 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
2490 .vidioc_g_audio = vidioc_g_audio,
2491 .vidioc_s_audio = vidioc_s_audio,
2492 .vidioc_cropcap = vidioc_cropcap, 2195 .vidioc_cropcap = vidioc_cropcap,
2493 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
2494 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
2495 .vidioc_reqbufs = vidioc_reqbufs, 2196 .vidioc_reqbufs = vidioc_reqbufs,
2496 .vidioc_querybuf = vidioc_querybuf, 2197 .vidioc_querybuf = vidioc_querybuf,
2497 .vidioc_qbuf = vidioc_qbuf, 2198 .vidioc_qbuf = vidioc_qbuf,
2498 .vidioc_dqbuf = vidioc_dqbuf, 2199 .vidioc_dqbuf = vidioc_dqbuf,
2499 .vidioc_s_std = vidioc_s_std, 2200 .vidioc_s_std = vidioc_s_std,
2500 .vidioc_g_std = vidioc_g_std, 2201 .vidioc_g_std = vidioc_g_std,
2501 .vidioc_enum_input = vidioc_enum_input, 2202 .vidioc_enum_input = cx231xx_enum_input,
2502 .vidioc_g_input = vidioc_g_input, 2203 .vidioc_g_input = cx231xx_g_input,
2503 .vidioc_s_input = vidioc_s_input, 2204 .vidioc_s_input = cx231xx_s_input,
2504 .vidioc_queryctrl = vidioc_queryctrl,
2505 .vidioc_g_ctrl = vidioc_g_ctrl,
2506 .vidioc_s_ctrl = vidioc_s_ctrl,
2507 .vidioc_streamon = vidioc_streamon, 2205 .vidioc_streamon = vidioc_streamon,
2508 .vidioc_streamoff = vidioc_streamoff, 2206 .vidioc_streamoff = vidioc_streamoff,
2509 .vidioc_g_tuner = vidioc_g_tuner, 2207 .vidioc_g_tuner = cx231xx_g_tuner,
2510 .vidioc_s_tuner = vidioc_s_tuner, 2208 .vidioc_s_tuner = cx231xx_s_tuner,
2511 .vidioc_g_frequency = vidioc_g_frequency, 2209 .vidioc_g_frequency = cx231xx_g_frequency,
2512 .vidioc_s_frequency = vidioc_s_frequency, 2210 .vidioc_s_frequency = cx231xx_s_frequency,
2211 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
2513#ifdef CONFIG_VIDEO_ADV_DEBUG 2212#ifdef CONFIG_VIDEO_ADV_DEBUG
2514 .vidioc_g_register = vidioc_g_register, 2213 .vidioc_g_register = cx231xx_g_register,
2515 .vidioc_s_register = vidioc_s_register, 2214 .vidioc_s_register = cx231xx_s_register,
2516#endif 2215#endif
2216 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
2217 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2517}; 2218};
2518 2219
2519static struct video_device cx231xx_vbi_template; 2220static struct video_device cx231xx_vbi_template;
@@ -2523,33 +2224,29 @@ static const struct video_device cx231xx_video_template = {
2523 .release = video_device_release, 2224 .release = video_device_release,
2524 .ioctl_ops = &video_ioctl_ops, 2225 .ioctl_ops = &video_ioctl_ops,
2525 .tvnorms = V4L2_STD_ALL, 2226 .tvnorms = V4L2_STD_ALL,
2526 .current_norm = V4L2_STD_PAL,
2527}; 2227};
2528 2228
2529static const struct v4l2_file_operations radio_fops = { 2229static const struct v4l2_file_operations radio_fops = {
2530 .owner = THIS_MODULE, 2230 .owner = THIS_MODULE,
2531 .open = cx231xx_v4l2_open, 2231 .open = cx231xx_v4l2_open,
2532 .release = cx231xx_v4l2_close, 2232 .release = cx231xx_v4l2_close,
2533 .ioctl = video_ioctl2, 2233 .poll = v4l2_ctrl_poll,
2234 .unlocked_ioctl = video_ioctl2,
2534}; 2235};
2535 2236
2536static const struct v4l2_ioctl_ops radio_ioctl_ops = { 2237static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2537 .vidioc_querycap = radio_querycap, 2238 .vidioc_querycap = cx231xx_querycap,
2538 .vidioc_g_tuner = radio_g_tuner, 2239 .vidioc_g_tuner = radio_g_tuner,
2539 .vidioc_enum_input = radio_enum_input,
2540 .vidioc_g_audio = radio_g_audio,
2541 .vidioc_s_tuner = radio_s_tuner, 2240 .vidioc_s_tuner = radio_s_tuner,
2542 .vidioc_s_audio = radio_s_audio, 2241 .vidioc_g_frequency = cx231xx_g_frequency,
2543 .vidioc_s_input = radio_s_input, 2242 .vidioc_s_frequency = cx231xx_s_frequency,
2544 .vidioc_queryctrl = radio_queryctrl, 2243 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
2545 .vidioc_g_ctrl = vidioc_g_ctrl,
2546 .vidioc_s_ctrl = vidioc_s_ctrl,
2547 .vidioc_g_frequency = vidioc_g_frequency,
2548 .vidioc_s_frequency = vidioc_s_frequency,
2549#ifdef CONFIG_VIDEO_ADV_DEBUG 2244#ifdef CONFIG_VIDEO_ADV_DEBUG
2550 .vidioc_g_register = vidioc_g_register, 2245 .vidioc_g_register = cx231xx_g_register,
2551 .vidioc_s_register = vidioc_s_register, 2246 .vidioc_s_register = cx231xx_s_register,
2552#endif 2247#endif
2248 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
2249 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2553}; 2250};
2554 2251
2555static struct video_device cx231xx_radio_template = { 2252static struct video_device cx231xx_radio_template = {
@@ -2575,10 +2272,17 @@ static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
2575 vfd->release = video_device_release; 2272 vfd->release = video_device_release;
2576 vfd->debug = video_debug; 2273 vfd->debug = video_debug;
2577 vfd->lock = &dev->lock; 2274 vfd->lock = &dev->lock;
2275 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
2578 2276
2579 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); 2277 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
2580 2278
2581 video_set_drvdata(vfd, dev); 2279 video_set_drvdata(vfd, dev);
2280 if (dev->tuner_type == TUNER_ABSENT) {
2281 v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
2282 v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY);
2283 v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER);
2284 v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER);
2285 }
2582 return vfd; 2286 return vfd;
2583} 2287}
2584 2288
@@ -2590,7 +2294,7 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
2590 dev->name, CX231XX_VERSION); 2294 dev->name, CX231XX_VERSION);
2591 2295
2592 /* set default norm */ 2296 /* set default norm */
2593 /*dev->norm = cx231xx_video_template.current_norm; */ 2297 dev->norm = V4L2_STD_PAL;
2594 dev->width = norm_maxw(dev); 2298 dev->width = norm_maxw(dev);
2595 dev->height = norm_maxh(dev); 2299 dev->height = norm_maxh(dev);
2596 dev->interlaced = 0; 2300 dev->interlaced = 0;
@@ -2601,9 +2305,23 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
2601 /* Set the initial input */ 2305 /* Set the initial input */
2602 video_mux(dev, dev->video_input); 2306 video_mux(dev, dev->video_input);
2603 2307
2604 /* Audio defaults */ 2308 call_all(dev, core, s_std, dev->norm);
2605 dev->mute = 1; 2309
2606 dev->volume = 0x1f; 2310 v4l2_ctrl_handler_init(&dev->ctrl_handler, 10);
2311 v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 5);
2312
2313 if (dev->sd_cx25840) {
2314 v4l2_ctrl_add_handler(&dev->ctrl_handler,
2315 dev->sd_cx25840->ctrl_handler, NULL);
2316 v4l2_ctrl_add_handler(&dev->radio_ctrl_handler,
2317 dev->sd_cx25840->ctrl_handler,
2318 v4l2_ctrl_radio_filter);
2319 }
2320
2321 if (dev->ctrl_handler.error)
2322 return dev->ctrl_handler.error;
2323 if (dev->radio_ctrl_handler.error)
2324 return dev->radio_ctrl_handler.error;
2607 2325
2608 /* enable vbi capturing */ 2326 /* enable vbi capturing */
2609 /* write code here... */ 2327 /* write code here... */
@@ -2615,6 +2333,7 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
2615 return -ENODEV; 2333 return -ENODEV;
2616 } 2334 }
2617 2335
2336 dev->vdev->ctrl_handler = &dev->ctrl_handler;
2618 /* register v4l2 video video_device */ 2337 /* register v4l2 video video_device */
2619 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, 2338 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
2620 video_nr[dev->devno]); 2339 video_nr[dev->devno]);
@@ -2634,6 +2353,11 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
2634 /* Allocate and fill vbi video_device struct */ 2353 /* Allocate and fill vbi video_device struct */
2635 dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi"); 2354 dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi");
2636 2355
2356 if (!dev->vbi_dev) {
2357 cx231xx_errdev("cannot allocate video_device.\n");
2358 return -ENODEV;
2359 }
2360 dev->vbi_dev->ctrl_handler = &dev->ctrl_handler;
2637 /* register v4l2 vbi video_device */ 2361 /* register v4l2 vbi video_device */
2638 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, 2362 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2639 vbi_nr[dev->devno]); 2363 vbi_nr[dev->devno]);
@@ -2652,6 +2376,7 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
2652 cx231xx_errdev("cannot allocate video_device.\n"); 2376 cx231xx_errdev("cannot allocate video_device.\n");
2653 return -ENODEV; 2377 return -ENODEV;
2654 } 2378 }
2379 dev->radio_dev->ctrl_handler = &dev->radio_ctrl_handler;
2655 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, 2380 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
2656 radio_nr[dev->devno]); 2381 radio_nr[dev->devno]);
2657 if (ret < 0) { 2382 if (ret < 0) {
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 3e11462be0d0..5ad9fd61d3c8 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -33,6 +33,8 @@
33 33
34#include <media/videobuf-vmalloc.h> 34#include <media/videobuf-vmalloc.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-ctrls.h>
37#include <media/v4l2-fh.h>
36#include <media/rc-core.h> 38#include <media/rc-core.h>
37#include <media/ir-kbd-i2c.h> 39#include <media/ir-kbd-i2c.h>
38#include <media/videobuf-dvb.h> 40#include <media/videobuf-dvb.h>
@@ -69,6 +71,7 @@
69#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL 14 71#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL 14
70#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC 15 72#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC 15
71#define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2 16 73#define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2 16
74#define CX231XX_BOARD_OTG102 17
72 75
73/* Limits minimum and default number of buffers */ 76/* Limits minimum and default number of buffers */
74#define CX231XX_MIN_BUF 4 77#define CX231XX_MIN_BUF 4
@@ -428,27 +431,12 @@ struct cx231xx_audio {
428struct cx231xx; 431struct cx231xx;
429 432
430struct cx231xx_fh { 433struct cx231xx_fh {
434 struct v4l2_fh fh;
431 struct cx231xx *dev; 435 struct cx231xx *dev;
432 unsigned int stream_on:1; /* Locks streams */ 436 unsigned int stream_on:1; /* Locks streams */
433 int radio;
434
435 struct videobuf_queue vb_vidq;
436
437 enum v4l2_buf_type type; 437 enum v4l2_buf_type type;
438 438
439 439 struct videobuf_queue vb_vidq;
440
441/*following is copyed from cx23885.h*/
442 u32 resources;
443
444 /* video overlay */
445 struct v4l2_window win;
446 struct v4l2_clip *clips;
447 unsigned int nclips;
448
449 /* video capture */
450 struct cx23417_fmt *fmt;
451 unsigned int width, height;
452 440
453 /* vbi capture */ 441 /* vbi capture */
454 struct videobuf_queue vidq; 442 struct videobuf_queue vidq;
@@ -516,14 +504,6 @@ struct cx231xx_tvnorm {
516 u32 cxoformat; 504 u32 cxoformat;
517}; 505};
518 506
519struct cx231xx_ctrl {
520 struct v4l2_queryctrl v;
521 u32 off;
522 u32 reg;
523 u32 mask;
524 u32 shift;
525};
526
527enum TRANSFER_TYPE { 507enum TRANSFER_TYPE {
528 Raw_Video = 0, 508 Raw_Video = 0,
529 Audio, 509 Audio,
@@ -631,6 +611,9 @@ struct cx231xx {
631 struct v4l2_device v4l2_dev; 611 struct v4l2_device v4l2_dev;
632 struct v4l2_subdev *sd_cx25840; 612 struct v4l2_subdev *sd_cx25840;
633 struct v4l2_subdev *sd_tuner; 613 struct v4l2_subdev *sd_tuner;
614 struct v4l2_ctrl_handler ctrl_handler;
615 struct v4l2_ctrl_handler radio_ctrl_handler;
616 struct cx2341x_handler mpeg_ctrl_handler;
634 617
635 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */ 618 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
636 atomic_t stream_started; /* stream should be running if true */ 619 atomic_t stream_started; /* stream should be running if true */
@@ -653,8 +636,6 @@ struct cx231xx {
653 v4l2_std_id norm; /* selected tv norm */ 636 v4l2_std_id norm; /* selected tv norm */
654 int ctl_freq; /* selected frequency */ 637 int ctl_freq; /* selected frequency */
655 unsigned int ctl_ainput; /* selected audio input */ 638 unsigned int ctl_ainput; /* selected audio input */
656 int mute;
657 int volume;
658 639
659 /* frame properties */ 640 /* frame properties */
660 int width; /* current frame width */ 641 int width; /* current frame width */
@@ -736,7 +717,6 @@ struct cx231xx {
736 u8 USE_ISO; 717 u8 USE_ISO;
737 struct cx231xx_tvnorm encodernorm; 718 struct cx231xx_tvnorm encodernorm;
738 struct cx231xx_tsport ts1, ts2; 719 struct cx231xx_tsport ts1, ts2;
739 struct cx2341x_mpeg_params mpeg_params;
740 struct video_device *v4l_device; 720 struct video_device *v4l_device;
741 atomic_t v4l_reader_count; 721 atomic_t v4l_reader_count;
742 u32 freq; 722 u32 freq;
@@ -866,8 +846,6 @@ int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
866/* Gpio related functions */ 846/* Gpio related functions */
867int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val, 847int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
868 u8 len, u8 request, u8 direction); 848 u8 len, u8 request, u8 direction);
869int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
870int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
871int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value); 849int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
872int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number, 850int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
873 int pin_value); 851 int pin_value);
@@ -955,6 +933,23 @@ int cx231xx_register_extension(struct cx231xx_ops *dev);
955void cx231xx_unregister_extension(struct cx231xx_ops *dev); 933void cx231xx_unregister_extension(struct cx231xx_ops *dev);
956void cx231xx_init_extension(struct cx231xx *dev); 934void cx231xx_init_extension(struct cx231xx *dev);
957void cx231xx_close_extension(struct cx231xx *dev); 935void cx231xx_close_extension(struct cx231xx *dev);
936int cx231xx_querycap(struct file *file, void *priv,
937 struct v4l2_capability *cap);
938int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
939int cx231xx_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t);
940int cx231xx_g_frequency(struct file *file, void *priv,
941 struct v4l2_frequency *f);
942int cx231xx_s_frequency(struct file *file, void *priv,
943 const struct v4l2_frequency *f);
944int cx231xx_enum_input(struct file *file, void *priv,
945 struct v4l2_input *i);
946int cx231xx_g_input(struct file *file, void *priv, unsigned int *i);
947int cx231xx_s_input(struct file *file, void *priv, unsigned int i);
948int cx231xx_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip);
949int cx231xx_g_register(struct file *file, void *priv,
950 struct v4l2_dbg_register *reg);
951int cx231xx_s_register(struct file *file, void *priv,
952 const struct v4l2_dbg_register *reg);
958 953
959/* Provided by cx231xx-cards.c */ 954/* Provided by cx231xx-cards.c */
960extern void cx231xx_pre_card_setup(struct cx231xx *dev); 955extern void cx231xx_pre_card_setup(struct cx231xx *dev);
diff --git a/drivers/media/usb/dvb-usb-v2/Kconfig b/drivers/media/usb/dvb-usb-v2/Kconfig
index 692224d97d06..a3c8ecf22078 100644
--- a/drivers/media/usb/dvb-usb-v2/Kconfig
+++ b/drivers/media/usb/dvb-usb-v2/Kconfig
@@ -13,10 +13,6 @@ config DVB_USB_V2
13 13
14 Say Y if you own a USB DVB device. 14 Say Y if you own a USB DVB device.
15 15
16config DVB_USB_CYPRESS_FIRMWARE
17 tristate "Cypress firmware helper routines"
18 depends on DVB_USB_V2
19
20config DVB_USB_AF9015 16config DVB_USB_AF9015
21 tristate "Afatech AF9015 DVB-T USB2.0 support" 17 tristate "Afatech AF9015 DVB-T USB2.0 support"
22 depends on DVB_USB_V2 18 depends on DVB_USB_V2
@@ -41,6 +37,7 @@ config DVB_USB_AF9035
41 select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT 37 select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
42 select MEDIA_TUNER_TDA18218 if MEDIA_SUBDRV_AUTOSELECT 38 select MEDIA_TUNER_TDA18218 if MEDIA_SUBDRV_AUTOSELECT
43 select MEDIA_TUNER_FC2580 if MEDIA_SUBDRV_AUTOSELECT 39 select MEDIA_TUNER_FC2580 if MEDIA_SUBDRV_AUTOSELECT
40 select MEDIA_TUNER_IT913X if MEDIA_SUBDRV_AUTOSELECT
44 help 41 help
45 Say Y here to support the Afatech AF9035 based DVB USB receiver. 42 Say Y here to support the Afatech AF9035 based DVB USB receiver.
46 43
@@ -72,7 +69,7 @@ config DVB_USB_AU6610
72config DVB_USB_AZ6007 69config DVB_USB_AZ6007
73 tristate "AzureWave 6007 and clones DVB-T/C USB2.0 support" 70 tristate "AzureWave 6007 and clones DVB-T/C USB2.0 support"
74 depends on DVB_USB_V2 71 depends on DVB_USB_V2
75 select DVB_USB_CYPRESS_FIRMWARE 72 select CYPRESS_FIRMWARE
76 select DVB_DRXK if MEDIA_SUBDRV_AUTOSELECT 73 select DVB_DRXK if MEDIA_SUBDRV_AUTOSELECT
77 select MEDIA_TUNER_MT2063 if MEDIA_SUBDRV_AUTOSELECT 74 select MEDIA_TUNER_MT2063 if MEDIA_SUBDRV_AUTOSELECT
78 help 75 help
@@ -146,6 +143,7 @@ config DVB_USB_RTL28XXU
146 select MEDIA_TUNER_FC0013 if MEDIA_SUBDRV_AUTOSELECT 143 select MEDIA_TUNER_FC0013 if MEDIA_SUBDRV_AUTOSELECT
147 select MEDIA_TUNER_E4000 if MEDIA_SUBDRV_AUTOSELECT 144 select MEDIA_TUNER_E4000 if MEDIA_SUBDRV_AUTOSELECT
148 select MEDIA_TUNER_FC2580 if MEDIA_SUBDRV_AUTOSELECT 145 select MEDIA_TUNER_FC2580 if MEDIA_SUBDRV_AUTOSELECT
146 select MEDIA_TUNER_R820T if MEDIA_SUBDRV_AUTOSELECT
149 help 147 help
150 Say Y here to support the Realtek RTL28xxU DVB USB receiver. 148 Say Y here to support the Realtek RTL28xxU DVB USB receiver.
151 149
diff --git a/drivers/media/usb/dvb-usb-v2/Makefile b/drivers/media/usb/dvb-usb-v2/Makefile
index b76f58e6c64f..2c06714b9ef0 100644
--- a/drivers/media/usb/dvb-usb-v2/Makefile
+++ b/drivers/media/usb/dvb-usb-v2/Makefile
@@ -1,9 +1,6 @@
1dvb_usb_v2-objs := dvb_usb_core.o dvb_usb_urb.o usb_urb.o 1dvb_usb_v2-objs := dvb_usb_core.o dvb_usb_urb.o usb_urb.o
2obj-$(CONFIG_DVB_USB_V2) += dvb_usb_v2.o 2obj-$(CONFIG_DVB_USB_V2) += dvb_usb_v2.o
3 3
4dvb_usb_cypress_firmware-objs := cypress_firmware.o
5obj-$(CONFIG_DVB_USB_CYPRESS_FIRMWARE) += dvb_usb_cypress_firmware.o
6
7dvb-usb-af9015-objs := af9015.o 4dvb-usb-af9015-objs := af9015.o
8obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o 5obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o
9 6
@@ -46,4 +43,4 @@ obj-$(CONFIG_DVB_USB_RTL28XXU) += dvb-usb-rtl28xxu.o
46ccflags-y += -I$(srctree)/drivers/media/dvb-core 43ccflags-y += -I$(srctree)/drivers/media/dvb-core
47ccflags-y += -I$(srctree)/drivers/media/dvb-frontends 44ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
48ccflags-y += -I$(srctree)/drivers/media/tuners 45ccflags-y += -I$(srctree)/drivers/media/tuners
49 46ccflags-y += -I$(srctree)/drivers/media/common
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.c b/drivers/media/usb/dvb-usb-v2/af9015.c
index b86d0f27a398..d556042cf312 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.c
+++ b/drivers/media/usb/dvb-usb-v2/af9015.c
@@ -30,22 +30,22 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
30 30
31static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req) 31static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
32{ 32{
33#define BUF_LEN 63
34#define REQ_HDR_LEN 8 /* send header size */ 33#define REQ_HDR_LEN 8 /* send header size */
35#define ACK_HDR_LEN 2 /* rece header size */ 34#define ACK_HDR_LEN 2 /* rece header size */
36 struct af9015_state *state = d_to_priv(d); 35 struct af9015_state *state = d_to_priv(d);
37 int ret, wlen, rlen; 36 int ret, wlen, rlen;
38 u8 buf[BUF_LEN];
39 u8 write = 1; 37 u8 write = 1;
40 38
41 buf[0] = req->cmd; 39 mutex_lock(&d->usb_mutex);
42 buf[1] = state->seq++; 40
43 buf[2] = req->i2c_addr; 41 state->buf[0] = req->cmd;
44 buf[3] = req->addr >> 8; 42 state->buf[1] = state->seq++;
45 buf[4] = req->addr & 0xff; 43 state->buf[2] = req->i2c_addr;
46 buf[5] = req->mbox; 44 state->buf[3] = req->addr >> 8;
47 buf[6] = req->addr_len; 45 state->buf[4] = req->addr & 0xff;
48 buf[7] = req->data_len; 46 state->buf[5] = req->mbox;
47 state->buf[6] = req->addr_len;
48 state->buf[7] = req->data_len;
49 49
50 switch (req->cmd) { 50 switch (req->cmd) {
51 case GET_CONFIG: 51 case GET_CONFIG:
@@ -55,14 +55,14 @@ static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
55 break; 55 break;
56 case READ_I2C: 56 case READ_I2C:
57 write = 0; 57 write = 0;
58 buf[2] |= 0x01; /* set I2C direction */ 58 state->buf[2] |= 0x01; /* set I2C direction */
59 case WRITE_I2C: 59 case WRITE_I2C:
60 buf[0] = READ_WRITE_I2C; 60 state->buf[0] = READ_WRITE_I2C;
61 break; 61 break;
62 case WRITE_MEMORY: 62 case WRITE_MEMORY:
63 if (((req->addr & 0xff00) == 0xff00) || 63 if (((req->addr & 0xff00) == 0xff00) ||
64 ((req->addr & 0xff00) == 0xae00)) 64 ((req->addr & 0xff00) == 0xae00))
65 buf[0] = WRITE_VIRTUAL_MEMORY; 65 state->buf[0] = WRITE_VIRTUAL_MEMORY;
66 case WRITE_VIRTUAL_MEMORY: 66 case WRITE_VIRTUAL_MEMORY:
67 case COPY_FIRMWARE: 67 case COPY_FIRMWARE:
68 case DOWNLOAD_FIRMWARE: 68 case DOWNLOAD_FIRMWARE:
@@ -90,7 +90,7 @@ static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
90 rlen = ACK_HDR_LEN; 90 rlen = ACK_HDR_LEN;
91 if (write) { 91 if (write) {
92 wlen += req->data_len; 92 wlen += req->data_len;
93 memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len); 93 memcpy(&state->buf[REQ_HDR_LEN], req->data, req->data_len);
94 } else { 94 } else {
95 rlen += req->data_len; 95 rlen += req->data_len;
96 } 96 }
@@ -99,22 +99,25 @@ static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
99 if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB) 99 if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
100 rlen = 0; 100 rlen = 0;
101 101
102 ret = dvb_usbv2_generic_rw(d, buf, wlen, buf, rlen); 102 ret = dvb_usbv2_generic_rw_locked(d,
103 state->buf, wlen, state->buf, rlen);
103 if (ret) 104 if (ret)
104 goto error; 105 goto error;
105 106
106 /* check status */ 107 /* check status */
107 if (rlen && buf[1]) { 108 if (rlen && state->buf[1]) {
108 dev_err(&d->udev->dev, "%s: command failed=%d\n", 109 dev_err(&d->udev->dev, "%s: command failed=%d\n",
109 KBUILD_MODNAME, buf[1]); 110 KBUILD_MODNAME, state->buf[1]);
110 ret = -EIO; 111 ret = -EIO;
111 goto error; 112 goto error;
112 } 113 }
113 114
114 /* read request, copy returned data to return buf */ 115 /* read request, copy returned data to return buf */
115 if (!write) 116 if (!write)
116 memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len); 117 memcpy(req->data, &state->buf[ACK_HDR_LEN], req->data_len);
117error: 118error:
119 mutex_unlock(&d->usb_mutex);
120
118 return ret; 121 return ret;
119} 122}
120 123
@@ -1317,6 +1320,43 @@ static int af9015_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1317 #define af9015_get_rc_config NULL 1320 #define af9015_get_rc_config NULL
1318#endif 1321#endif
1319 1322
1323static int af9015_probe(struct usb_interface *intf,
1324 const struct usb_device_id *id)
1325{
1326 struct usb_device *udev = interface_to_usbdev(intf);
1327 char manufacturer[sizeof("ITE Technologies, Inc.")];
1328
1329 memset(manufacturer, 0, sizeof(manufacturer));
1330 usb_string(udev, udev->descriptor.iManufacturer,
1331 manufacturer, sizeof(manufacturer));
1332 /*
1333 * There is two devices having same ID but different chipset. One uses
1334 * AF9015 and the other IT9135 chipset. Only difference seen on lsusb
1335 * is iManufacturer string.
1336 *
1337 * idVendor 0x0ccd TerraTec Electronic GmbH
1338 * idProduct 0x0099
1339 * bcdDevice 2.00
1340 * iManufacturer 1 Afatech
1341 * iProduct 2 DVB-T 2
1342 *
1343 * idVendor 0x0ccd TerraTec Electronic GmbH
1344 * idProduct 0x0099
1345 * bcdDevice 2.00
1346 * iManufacturer 1 ITE Technologies, Inc.
1347 * iProduct 2 DVB-T TV Stick
1348 */
1349 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) &&
1350 (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) {
1351 if (!strcmp("ITE Technologies, Inc.", manufacturer)) {
1352 dev_dbg(&udev->dev, "%s: rejecting device\n", __func__);
1353 return -ENODEV;
1354 }
1355 }
1356
1357 return dvb_usbv2_probe(intf, id);
1358}
1359
1320/* interface 0 is used by DVB-T receiver and 1360/* interface 0 is used by DVB-T receiver and
1321 interface 1 is for remote controller (HID) */ 1361 interface 1 is for remote controller (HID) */
1322static struct dvb_usb_device_properties af9015_props = { 1362static struct dvb_usb_device_properties af9015_props = {
@@ -1425,6 +1465,7 @@ static const struct usb_device_id af9015_id_table[] = {
1425 &af9015_props, "AverMedia AVerTV Volar M (A815Mac)", NULL) }, 1465 &af9015_props, "AverMedia AVerTV Volar M (A815Mac)", NULL) },
1426 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC, 1466 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC,
1427 &af9015_props, "TerraTec Cinergy T Stick RC", RC_MAP_TERRATEC_SLIM_2) }, 1467 &af9015_props, "TerraTec Cinergy T Stick RC", RC_MAP_TERRATEC_SLIM_2) },
1468 /* XXX: that same ID [0ccd:0099] is used by af9035 driver too */
1428 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC, 1469 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
1429 &af9015_props, "TerraTec Cinergy T Stick Dual RC", RC_MAP_TERRATEC_SLIM) }, 1470 &af9015_props, "TerraTec Cinergy T Stick Dual RC", RC_MAP_TERRATEC_SLIM) },
1430 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T, 1471 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T,
@@ -1441,7 +1482,7 @@ MODULE_DEVICE_TABLE(usb, af9015_id_table);
1441static struct usb_driver af9015_usb_driver = { 1482static struct usb_driver af9015_usb_driver = {
1442 .name = KBUILD_MODNAME, 1483 .name = KBUILD_MODNAME,
1443 .id_table = af9015_id_table, 1484 .id_table = af9015_id_table,
1444 .probe = dvb_usbv2_probe, 1485 .probe = af9015_probe,
1445 .disconnect = dvb_usbv2_disconnect, 1486 .disconnect = dvb_usbv2_disconnect,
1446 .suspend = dvb_usbv2_suspend, 1487 .suspend = dvb_usbv2_suspend,
1447 .resume = dvb_usbv2_resume, 1488 .resume = dvb_usbv2_resume,
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.h b/drivers/media/usb/dvb-usb-v2/af9015.h
index 533637dedd23..3a6f3ad1eadb 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.h
+++ b/drivers/media/usb/dvb-usb-v2/af9015.h
@@ -115,7 +115,9 @@ enum af9015_ir_mode {
115 AF9015_IR_MODE_POLLING, /* just guess */ 115 AF9015_IR_MODE_POLLING, /* just guess */
116}; 116};
117 117
118#define BUF_LEN 63
118struct af9015_state { 119struct af9015_state {
120 u8 buf[BUF_LEN]; /* bulk USB control message */
119 u8 ir_mode; 121 u8 ir_mode;
120 u8 rc_repeat; 122 u8 rc_repeat;
121 u32 rc_keycode; 123 u32 rc_keycode;
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index f11cc42454f0..b638fc1cd574 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -41,79 +41,84 @@ static u16 af9035_checksum(const u8 *buf, size_t len)
41 41
42static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req) 42static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req)
43{ 43{
44#define BUF_LEN 64
45#define REQ_HDR_LEN 4 /* send header size */ 44#define REQ_HDR_LEN 4 /* send header size */
46#define ACK_HDR_LEN 3 /* rece header size */ 45#define ACK_HDR_LEN 3 /* rece header size */
47#define CHECKSUM_LEN 2 46#define CHECKSUM_LEN 2
48#define USB_TIMEOUT 2000 47#define USB_TIMEOUT 2000
49 struct state *state = d_to_priv(d); 48 struct state *state = d_to_priv(d);
50 int ret, wlen, rlen; 49 int ret, wlen, rlen;
51 u8 buf[BUF_LEN];
52 u16 checksum, tmp_checksum; 50 u16 checksum, tmp_checksum;
53 51
52 mutex_lock(&d->usb_mutex);
53
54 /* buffer overflow check */ 54 /* buffer overflow check */
55 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || 55 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
56 req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) { 56 req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) {
57 dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n", 57 dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n",
58 __func__, req->wlen, req->rlen); 58 __func__, req->wlen, req->rlen);
59 return -EINVAL; 59 ret = -EINVAL;
60 goto exit;
60 } 61 }
61 62
62 buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1; 63 state->buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1;
63 buf[1] = req->mbox; 64 state->buf[1] = req->mbox;
64 buf[2] = req->cmd; 65 state->buf[2] = req->cmd;
65 buf[3] = state->seq++; 66 state->buf[3] = state->seq++;
66 memcpy(&buf[REQ_HDR_LEN], req->wbuf, req->wlen); 67 memcpy(&state->buf[REQ_HDR_LEN], req->wbuf, req->wlen);
67 68
68 wlen = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN; 69 wlen = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN;
69 rlen = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN; 70 rlen = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN;
70 71
71 /* calc and add checksum */ 72 /* calc and add checksum */
72 checksum = af9035_checksum(buf, buf[0] - 1); 73 checksum = af9035_checksum(state->buf, state->buf[0] - 1);
73 buf[buf[0] - 1] = (checksum >> 8); 74 state->buf[state->buf[0] - 1] = (checksum >> 8);
74 buf[buf[0] - 0] = (checksum & 0xff); 75 state->buf[state->buf[0] - 0] = (checksum & 0xff);
75 76
76 /* no ack for these packets */ 77 /* no ack for these packets */
77 if (req->cmd == CMD_FW_DL) 78 if (req->cmd == CMD_FW_DL)
78 rlen = 0; 79 rlen = 0;
79 80
80 ret = dvb_usbv2_generic_rw(d, buf, wlen, buf, rlen); 81 ret = dvb_usbv2_generic_rw_locked(d,
82 state->buf, wlen, state->buf, rlen);
81 if (ret) 83 if (ret)
82 goto err; 84 goto exit;
83 85
84 /* no ack for those packets */ 86 /* no ack for those packets */
85 if (req->cmd == CMD_FW_DL) 87 if (req->cmd == CMD_FW_DL)
86 goto exit; 88 goto exit;
87 89
88 /* verify checksum */ 90 /* verify checksum */
89 checksum = af9035_checksum(buf, rlen - 2); 91 checksum = af9035_checksum(state->buf, rlen - 2);
90 tmp_checksum = (buf[rlen - 2] << 8) | buf[rlen - 1]; 92 tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1];
91 if (tmp_checksum != checksum) { 93 if (tmp_checksum != checksum) {
92 dev_err(&d->udev->dev, "%s: command=%02x checksum mismatch " \ 94 dev_err(&d->udev->dev, "%s: command=%02x checksum mismatch " \
93 "(%04x != %04x)\n", KBUILD_MODNAME, req->cmd, 95 "(%04x != %04x)\n", KBUILD_MODNAME, req->cmd,
94 tmp_checksum, checksum); 96 tmp_checksum, checksum);
95 ret = -EIO; 97 ret = -EIO;
96 goto err; 98 goto exit;
97 } 99 }
98 100
99 /* check status */ 101 /* check status */
100 if (buf[2]) { 102 if (state->buf[2]) {
103 /* fw returns status 1 when IR code was not received */
104 if (req->cmd == CMD_IR_GET || state->buf[2] == 1) {
105 ret = 1;
106 goto exit;
107 }
108
101 dev_dbg(&d->udev->dev, "%s: command=%02x failed fw error=%d\n", 109 dev_dbg(&d->udev->dev, "%s: command=%02x failed fw error=%d\n",
102 __func__, req->cmd, buf[2]); 110 __func__, req->cmd, state->buf[2]);
103 ret = -EIO; 111 ret = -EIO;
104 goto err; 112 goto exit;
105 } 113 }
106 114
107 /* read request, copy returned data to return buf */ 115 /* read request, copy returned data to return buf */
108 if (req->rlen) 116 if (req->rlen)
109 memcpy(req->rbuf, &buf[ACK_HDR_LEN], req->rlen); 117 memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen);
110
111exit: 118exit:
112 return 0; 119 mutex_unlock(&d->usb_mutex);
113 120 if (ret < 0)
114err: 121 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
115 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
116
117 return ret; 122 return ret;
118} 123}
119 124
@@ -292,12 +297,40 @@ static struct i2c_algorithm af9035_i2c_algo = {
292 297
293static int af9035_identify_state(struct dvb_usb_device *d, const char **name) 298static int af9035_identify_state(struct dvb_usb_device *d, const char **name)
294{ 299{
300 struct state *state = d_to_priv(d);
295 int ret; 301 int ret;
296 u8 wbuf[1] = { 1 }; 302 u8 wbuf[1] = { 1 };
297 u8 rbuf[4]; 303 u8 rbuf[4];
298 struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf, 304 struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf,
299 sizeof(rbuf), rbuf }; 305 sizeof(rbuf), rbuf };
300 306
307 ret = af9035_rd_regs(d, 0x1222, rbuf, 3);
308 if (ret < 0)
309 goto err;
310
311 state->chip_version = rbuf[0];
312 state->chip_type = rbuf[2] << 8 | rbuf[1] << 0;
313
314 ret = af9035_rd_reg(d, 0x384f, &state->prechip_version);
315 if (ret < 0)
316 goto err;
317
318 dev_info(&d->udev->dev,
319 "%s: prechip_version=%02x chip_version=%02x chip_type=%04x\n",
320 __func__, state->prechip_version, state->chip_version,
321 state->chip_type);
322
323 if (state->chip_type == 0x9135) {
324 if (state->chip_version == 0x02)
325 *name = AF9035_FIRMWARE_IT9135_V2;
326 else
327 *name = AF9035_FIRMWARE_IT9135_V1;
328 state->eeprom_addr = EEPROM_BASE_IT9135;
329 } else {
330 *name = AF9035_FIRMWARE_AF9035;
331 state->eeprom_addr = EEPROM_BASE_AF9035;
332 }
333
301 ret = af9035_ctrl_msg(d, &req); 334 ret = af9035_ctrl_msg(d, &req);
302 if (ret < 0) 335 if (ret < 0)
303 goto err; 336 goto err;
@@ -316,66 +349,19 @@ err:
316 return ret; 349 return ret;
317} 350}
318 351
319static int af9035_download_firmware(struct dvb_usb_device *d, 352static int af9035_download_firmware_old(struct dvb_usb_device *d,
320 const struct firmware *fw) 353 const struct firmware *fw)
321{ 354{
322 int ret, i, j, len; 355 int ret, i, j, len;
323 u8 wbuf[1]; 356 u8 wbuf[1];
324 u8 rbuf[4];
325 struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; 357 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
326 struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL }; 358 struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL };
327 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ; 359 u8 hdr_core;
328 u8 hdr_core, tmp;
329 u16 hdr_addr, hdr_data_len, hdr_checksum; 360 u16 hdr_addr, hdr_data_len, hdr_checksum;
330 #define MAX_DATA 58 361 #define MAX_DATA 58
331 #define HDR_SIZE 7 362 #define HDR_SIZE 7
332 363
333 /* 364 /*
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 /*
379 * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info! 365 * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info!
380 * 366 *
381 * byte 0: MCS 51 core 367 * byte 0: MCS 51 core
@@ -441,28 +427,6 @@ static int af9035_download_firmware(struct dvb_usb_device *d,
441 if (i) 427 if (i)
442 dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME); 428 dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME);
443 429
444 /* firmware loaded, request boot */
445 req.cmd = CMD_FW_BOOT;
446 ret = af9035_ctrl_msg(d, &req);
447 if (ret < 0)
448 goto err;
449
450 /* ensure firmware starts */
451 wbuf[0] = 1;
452 ret = af9035_ctrl_msg(d, &req_fw_ver);
453 if (ret < 0)
454 goto err;
455
456 if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) {
457 dev_err(&d->udev->dev, "%s: firmware did not run\n",
458 KBUILD_MODNAME);
459 ret = -ENODEV;
460 goto err;
461 }
462
463 dev_info(&d->udev->dev, "%s: firmware version=%d.%d.%d.%d",
464 KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
465
466 return 0; 430 return 0;
467 431
468err: 432err:
@@ -471,15 +435,11 @@ err:
471 return ret; 435 return ret;
472} 436}
473 437
474static int af9035_download_firmware_it9135(struct dvb_usb_device *d, 438static int af9035_download_firmware_new(struct dvb_usb_device *d,
475 const struct firmware *fw) 439 const struct firmware *fw)
476{ 440{
477 int ret, i, i_prev; 441 int ret, i, i_prev;
478 u8 wbuf[1];
479 u8 rbuf[4];
480 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
481 struct usb_req req_fw_dl = { CMD_FW_SCATTER_WR, 0, 0, NULL, 0, NULL }; 442 struct usb_req req_fw_dl = { CMD_FW_SCATTER_WR, 0, 0, NULL, 0, NULL };
482 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
483 #define HDR_SIZE 7 443 #define HDR_SIZE 7
484 444
485 /* 445 /*
@@ -494,7 +454,6 @@ static int af9035_download_firmware_it9135(struct dvb_usb_device *d,
494 * 5: addr LSB 454 * 5: addr LSB
495 * 6: count of data bytes ? 455 * 6: count of data bytes ?
496 */ 456 */
497
498 for (i = HDR_SIZE, i_prev = 0; i <= fw->size; i++) { 457 for (i = HDR_SIZE, i_prev = 0; i <= fw->size; i++) {
499 if (i == fw->size || 458 if (i == fw->size ||
500 (fw->data[i + 0] == 0x03 && 459 (fw->data[i + 0] == 0x03 &&
@@ -513,6 +472,86 @@ static int af9035_download_firmware_it9135(struct dvb_usb_device *d,
513 } 472 }
514 } 473 }
515 474
475 return 0;
476
477err:
478 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
479
480 return ret;
481}
482
483static int af9035_download_firmware(struct dvb_usb_device *d,
484 const struct firmware *fw)
485{
486 struct state *state = d_to_priv(d);
487 int ret;
488 u8 wbuf[1];
489 u8 rbuf[4];
490 u8 tmp;
491 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
492 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
493 dev_dbg(&d->udev->dev, "%s:\n", __func__);
494
495 /*
496 * In case of dual tuner configuration we need to do some extra
497 * initialization in order to download firmware to slave demod too,
498 * which is done by master demod.
499 * Master feeds also clock and controls power via GPIO.
500 */
501 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_DUAL_MODE, &tmp);
502 if (ret < 0)
503 goto err;
504
505 if (tmp) {
506 /* configure gpioh1, reset & power slave demod */
507 ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
508 if (ret < 0)
509 goto err;
510
511 ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01);
512 if (ret < 0)
513 goto err;
514
515 ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01);
516 if (ret < 0)
517 goto err;
518
519 usleep_range(10000, 50000);
520
521 ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01);
522 if (ret < 0)
523 goto err;
524
525 /* tell the slave I2C address */
526 ret = af9035_rd_reg(d,
527 state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR,
528 &tmp);
529 if (ret < 0)
530 goto err;
531
532 if (state->chip_type == 0x9135) {
533 ret = af9035_wr_reg(d, 0x004bfb, tmp);
534 if (ret < 0)
535 goto err;
536 } else {
537 ret = af9035_wr_reg(d, 0x00417f, tmp);
538 if (ret < 0)
539 goto err;
540
541 /* enable clock out */
542 ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01);
543 if (ret < 0)
544 goto err;
545 }
546 }
547
548 if (fw->data[0] == 0x01)
549 ret = af9035_download_firmware_old(d, fw);
550 else
551 ret = af9035_download_firmware_new(d, fw);
552 if (ret < 0)
553 goto err;
554
516 /* firmware loaded, request boot */ 555 /* firmware loaded, request boot */
517 req.cmd = CMD_FW_BOOT; 556 req.cmd = CMD_FW_BOOT;
518 ret = af9035_ctrl_msg(d, &req); 557 ret = af9035_ctrl_msg(d, &req);
@@ -546,15 +585,42 @@ err:
546static int af9035_read_config(struct dvb_usb_device *d) 585static int af9035_read_config(struct dvb_usb_device *d)
547{ 586{
548 struct state *state = d_to_priv(d); 587 struct state *state = d_to_priv(d);
549 int ret, i, eeprom_shift = 0; 588 int ret, i;
550 u8 tmp; 589 u8 tmp;
551 u16 tmp16; 590 u16 tmp16, addr;
552 591
553 /* demod I2C "address" */ 592 /* demod I2C "address" */
554 state->af9033_config[0].i2c_addr = 0x38; 593 state->af9033_config[0].i2c_addr = 0x38;
594 state->af9033_config[0].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
595 state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
596 state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
597 state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL;
598
599 /* eeprom memory mapped location */
600 if (state->chip_type == 0x9135) {
601 if (state->chip_version == 0x02) {
602 state->af9033_config[0].tuner = AF9033_TUNER_IT9135_60;
603 state->af9033_config[1].tuner = AF9033_TUNER_IT9135_60;
604 tmp16 = 0x00461d;
605 } else {
606 state->af9033_config[0].tuner = AF9033_TUNER_IT9135_38;
607 state->af9033_config[1].tuner = AF9033_TUNER_IT9135_38;
608 tmp16 = 0x00461b;
609 }
610
611 /* check if eeprom exists */
612 ret = af9035_rd_reg(d, tmp16, &tmp);
613 if (ret < 0)
614 goto err;
615
616 if (tmp == 0x00) {
617 dev_dbg(&d->udev->dev, "%s: no eeprom\n", __func__);
618 goto skip_eeprom;
619 }
620 }
555 621
556 /* check if there is dual tuners */ 622 /* check if there is dual tuners */
557 ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp); 623 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_DUAL_MODE, &tmp);
558 if (ret < 0) 624 if (ret < 0)
559 goto err; 625 goto err;
560 626
@@ -564,7 +630,9 @@ static int af9035_read_config(struct dvb_usb_device *d)
564 630
565 if (state->dual_mode) { 631 if (state->dual_mode) {
566 /* read 2nd demodulator I2C address */ 632 /* read 2nd demodulator I2C address */
567 ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp); 633 ret = af9035_rd_reg(d,
634 state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR,
635 &tmp);
568 if (ret < 0) 636 if (ret < 0)
569 goto err; 637 goto err;
570 638
@@ -573,17 +641,25 @@ static int af9035_read_config(struct dvb_usb_device *d)
573 __func__, tmp); 641 __func__, tmp);
574 } 642 }
575 643
644 addr = state->eeprom_addr;
645
576 for (i = 0; i < state->dual_mode + 1; i++) { 646 for (i = 0; i < state->dual_mode + 1; i++) {
577 /* tuner */ 647 /* tuner */
578 ret = af9035_rd_reg(d, EEPROM_1_TUNER_ID + eeprom_shift, &tmp); 648 ret = af9035_rd_reg(d, addr + EEPROM_1_TUNER_ID, &tmp);
579 if (ret < 0) 649 if (ret < 0)
580 goto err; 650 goto err;
581 651
582 state->af9033_config[i].tuner = tmp; 652 if (tmp == 0x00)
653 dev_dbg(&d->udev->dev,
654 "%s: [%d]tuner not set, using default\n",
655 __func__, i);
656 else
657 state->af9033_config[i].tuner = tmp;
658
583 dev_dbg(&d->udev->dev, "%s: [%d]tuner=%02x\n", 659 dev_dbg(&d->udev->dev, "%s: [%d]tuner=%02x\n",
584 __func__, i, tmp); 660 __func__, i, state->af9033_config[i].tuner);
585 661
586 switch (tmp) { 662 switch (state->af9033_config[i].tuner) {
587 case AF9033_TUNER_TUA9001: 663 case AF9033_TUNER_TUA9001:
588 case AF9033_TUNER_FC0011: 664 case AF9033_TUNER_FC0011:
589 case AF9033_TUNER_MXL5007T: 665 case AF9033_TUNER_MXL5007T:
@@ -592,32 +668,46 @@ static int af9035_read_config(struct dvb_usb_device *d)
592 case AF9033_TUNER_FC0012: 668 case AF9033_TUNER_FC0012:
593 state->af9033_config[i].spec_inv = 1; 669 state->af9033_config[i].spec_inv = 1;
594 break; 670 break;
671 case AF9033_TUNER_IT9135_38:
672 case AF9033_TUNER_IT9135_51:
673 case AF9033_TUNER_IT9135_52:
674 case AF9033_TUNER_IT9135_60:
675 case AF9033_TUNER_IT9135_61:
676 case AF9033_TUNER_IT9135_62:
677 break;
595 default: 678 default:
596 dev_warn(&d->udev->dev, "%s: tuner id=%02x not " \ 679 dev_warn(&d->udev->dev,
597 "supported, please report!", 680 "%s: tuner id=%02x not supported, please report!",
598 KBUILD_MODNAME, tmp); 681 KBUILD_MODNAME, tmp);
599 } 682 }
600 683
601 /* disable dual mode if driver does not support it */ 684 /* disable dual mode if driver does not support it */
602 if (i == 1) 685 if (i == 1)
603 switch (tmp) { 686 switch (state->af9033_config[i].tuner) {
604 case AF9033_TUNER_FC0012: 687 case AF9033_TUNER_FC0012:
688 case AF9033_TUNER_IT9135_38:
689 case AF9033_TUNER_IT9135_51:
690 case AF9033_TUNER_IT9135_52:
691 case AF9033_TUNER_IT9135_60:
692 case AF9033_TUNER_IT9135_61:
693 case AF9033_TUNER_IT9135_62:
694 case AF9033_TUNER_MXL5007T:
605 break; 695 break;
606 default: 696 default:
607 state->dual_mode = false; 697 state->dual_mode = false;
608 dev_info(&d->udev->dev, "%s: driver does not " \ 698 dev_info(&d->udev->dev,
609 "support 2nd tuner and will " \ 699 "%s: driver does not support 2nd tuner and will disable it",
610 "disable it", KBUILD_MODNAME); 700 KBUILD_MODNAME);
611 } 701 }
612 702
613 /* tuner IF frequency */ 703 /* tuner IF frequency */
614 ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_L + eeprom_shift, &tmp); 704 ret = af9035_rd_reg(d, addr + EEPROM_1_IF_L, &tmp);
615 if (ret < 0) 705 if (ret < 0)
616 goto err; 706 goto err;
617 707
618 tmp16 = tmp; 708 tmp16 = tmp;
619 709
620 ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_H + eeprom_shift, &tmp); 710 ret = af9035_rd_reg(d, addr + EEPROM_1_IF_H, &tmp);
621 if (ret < 0) 711 if (ret < 0)
622 goto err; 712 goto err;
623 713
@@ -625,9 +715,10 @@ static int af9035_read_config(struct dvb_usb_device *d)
625 715
626 dev_dbg(&d->udev->dev, "%s: [%d]IF=%d\n", __func__, i, tmp16); 716 dev_dbg(&d->udev->dev, "%s: [%d]IF=%d\n", __func__, i, tmp16);
627 717
628 eeprom_shift = 0x10; /* shift for the 2nd tuner params */ 718 addr += 0x10; /* shift for the 2nd tuner params */
629 } 719 }
630 720
721skip_eeprom:
631 /* get demod clock */ 722 /* get demod clock */
632 ret = af9035_rd_reg(d, 0x00d800, &tmp); 723 ret = af9035_rd_reg(d, 0x00d800, &tmp);
633 if (ret < 0) 724 if (ret < 0)
@@ -635,34 +726,12 @@ static int af9035_read_config(struct dvb_usb_device *d)
635 726
636 tmp = (tmp >> 0) & 0x0f; 727 tmp = (tmp >> 0) & 0x0f;
637 728
638 for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++) 729 for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++) {
639 state->af9033_config[i].clock = clock_lut[tmp]; 730 if (state->chip_type == 0x9135)
640 731 state->af9033_config[i].clock = clock_lut_it9135[tmp];
641 return 0; 732 else
642 733 state->af9033_config[i].clock = clock_lut_af9035[tmp];
643err: 734 }
644 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
645
646 return ret;
647}
648
649static int af9035_read_config_it9135(struct dvb_usb_device *d)
650{
651 struct state *state = d_to_priv(d);
652 int ret, i;
653 u8 tmp;
654
655 state->dual_mode = false;
656
657 /* get demod clock */
658 ret = af9035_rd_reg(d, 0x00d800, &tmp);
659 if (ret < 0)
660 goto err;
661
662 tmp = (tmp >> 0) & 0x0f;
663
664 for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++)
665 state->af9033_config[i].clock = clock_lut_it9135[tmp];
666 735
667 return 0; 736 return 0;
668 737
@@ -821,7 +890,12 @@ static int af9035_frontend_callback(void *adapter_priv, int component,
821static int af9035_get_adapter_count(struct dvb_usb_device *d) 890static int af9035_get_adapter_count(struct dvb_usb_device *d)
822{ 891{
823 struct state *state = d_to_priv(d); 892 struct state *state = d_to_priv(d);
824 return state->dual_mode + 1; 893
894 /* disable 2nd adapter as we don't have PID filters implemented */
895 if (d->udev->speed == USB_SPEED_FULL)
896 return 1;
897 else
898 return state->dual_mode + 1;
825} 899}
826 900
827static int af9035_frontend_attach(struct dvb_usb_adapter *adap) 901static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
@@ -829,6 +903,7 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
829 struct state *state = adap_to_priv(adap); 903 struct state *state = adap_to_priv(adap);
830 struct dvb_usb_device *d = adap_to_d(adap); 904 struct dvb_usb_device *d = adap_to_d(adap);
831 int ret; 905 int ret;
906 dev_dbg(&d->udev->dev, "%s:\n", __func__);
832 907
833 if (!state->af9033_config[adap->id].tuner) { 908 if (!state->af9033_config[adap->id].tuner) {
834 /* unsupported tuner */ 909 /* unsupported tuner */
@@ -836,20 +911,6 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
836 goto err; 911 goto err;
837 } 912 }
838 913
839 if (adap->id == 0) {
840 state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
841 state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL;
842
843 ret = af9035_wr_reg(d, 0x00417f,
844 state->af9033_config[1].i2c_addr);
845 if (ret < 0)
846 goto err;
847
848 ret = af9035_wr_reg(d, 0x00d81a, state->dual_mode);
849 if (ret < 0)
850 goto err;
851 }
852
853 /* attach demodulator */ 914 /* attach demodulator */
854 adap->fe[0] = dvb_attach(af9033_attach, &state->af9033_config[adap->id], 915 adap->fe[0] = dvb_attach(af9033_attach, &state->af9033_config[adap->id],
855 &d->i2c_adap); 916 &d->i2c_adap);
@@ -928,6 +989,8 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
928 struct dvb_frontend *fe; 989 struct dvb_frontend *fe;
929 struct i2c_msg msg[1]; 990 struct i2c_msg msg[1];
930 u8 tuner_addr; 991 u8 tuner_addr;
992 dev_dbg(&d->udev->dev, "%s:\n", __func__);
993
931 /* 994 /*
932 * XXX: Hack used in that function: we abuse unused I2C address bit [7] 995 * 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. 996 * to carry info about used I2C bus for dual tuner configuration.
@@ -1082,6 +1145,17 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
1082 fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap, 1145 fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap,
1083 &af9035_fc0012_config[adap->id]); 1146 &af9035_fc0012_config[adap->id]);
1084 break; 1147 break;
1148 case AF9033_TUNER_IT9135_38:
1149 case AF9033_TUNER_IT9135_51:
1150 case AF9033_TUNER_IT9135_52:
1151 case AF9033_TUNER_IT9135_60:
1152 case AF9033_TUNER_IT9135_61:
1153 case AF9033_TUNER_IT9135_62:
1154 /* attach tuner */
1155 fe = dvb_attach(it913x_attach, adap->fe[0], &d->i2c_adap,
1156 state->af9033_config[adap->id].i2c_addr,
1157 state->af9033_config[0].tuner);
1158 break;
1085 default: 1159 default:
1086 fe = NULL; 1160 fe = NULL;
1087 } 1161 }
@@ -1103,8 +1177,8 @@ static int af9035_init(struct dvb_usb_device *d)
1103{ 1177{
1104 struct state *state = d_to_priv(d); 1178 struct state *state = d_to_priv(d);
1105 int ret, i; 1179 int ret, i;
1106 u16 frame_size = 87 * 188 / 4; 1180 u16 frame_size = (d->udev->speed == USB_SPEED_FULL ? 5 : 87) * 188 / 4;
1107 u8 packet_size = 512 / 4; 1181 u8 packet_size = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4;
1108 struct reg_val_mask tab[] = { 1182 struct reg_val_mask tab[] = {
1109 { 0x80f99d, 0x01, 0x01 }, 1183 { 0x80f99d, 0x01, 0x01 },
1110 { 0x80f9a4, 0x01, 0x01 }, 1184 { 0x80f9a4, 0x01, 0x01 },
@@ -1149,40 +1223,49 @@ err:
1149#if IS_ENABLED(CONFIG_RC_CORE) 1223#if IS_ENABLED(CONFIG_RC_CORE)
1150static int af9035_rc_query(struct dvb_usb_device *d) 1224static int af9035_rc_query(struct dvb_usb_device *d)
1151{ 1225{
1152 unsigned int key;
1153 unsigned char b[4];
1154 int ret; 1226 int ret;
1155 struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, b }; 1227 u32 key;
1228 u8 buf[4];
1229 struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, buf };
1156 1230
1157 ret = af9035_ctrl_msg(d, &req); 1231 ret = af9035_ctrl_msg(d, &req);
1158 if (ret < 0) 1232 if (ret == 1)
1233 return 0;
1234 else if (ret < 0)
1159 goto err; 1235 goto err;
1160 1236
1161 if ((b[2] + b[3]) == 0xff) { 1237 if ((buf[2] + buf[3]) == 0xff) {
1162 if ((b[0] + b[1]) == 0xff) { 1238 if ((buf[0] + buf[1]) == 0xff) {
1163 /* NEC */ 1239 /* NEC standard 16bit */
1164 key = b[0] << 8 | b[2]; 1240 key = buf[0] << 8 | buf[2];
1165 } else { 1241 } else {
1166 /* ext. NEC */ 1242 /* NEC extended 24bit */
1167 key = b[0] << 16 | b[1] << 8 | b[2]; 1243 key = buf[0] << 16 | buf[1] << 8 | buf[2];
1168 } 1244 }
1169 } else { 1245 } else {
1170 key = b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3]; 1246 /* NEC full code 32bit */
1247 key = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
1171 } 1248 }
1172 1249
1250 dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 4, buf);
1251
1173 rc_keydown(d->rc_dev, key, 0); 1252 rc_keydown(d->rc_dev, key, 0);
1174 1253
1175err:
1176 /* ignore errors */
1177 return 0; 1254 return 0;
1255
1256err:
1257 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1258
1259 return ret;
1178} 1260}
1179 1261
1180static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) 1262static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1181{ 1263{
1264 struct state *state = d_to_priv(d);
1182 int ret; 1265 int ret;
1183 u8 tmp; 1266 u8 tmp;
1184 1267
1185 ret = af9035_rd_reg(d, EEPROM_IR_MODE, &tmp); 1268 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_MODE, &tmp);
1186 if (ret < 0) 1269 if (ret < 0)
1187 goto err; 1270 goto err;
1188 1271
@@ -1190,7 +1273,8 @@ static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1190 1273
1191 /* don't activate rc if in HID mode or if not available */ 1274 /* don't activate rc if in HID mode or if not available */
1192 if (tmp == 5) { 1275 if (tmp == 5) {
1193 ret = af9035_rd_reg(d, EEPROM_IR_TYPE, &tmp); 1276 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_TYPE,
1277 &tmp);
1194 if (ret < 0) 1278 if (ret < 0)
1195 goto err; 1279 goto err;
1196 1280
@@ -1225,6 +1309,109 @@ err:
1225 #define af9035_get_rc_config NULL 1309 #define af9035_get_rc_config NULL
1226#endif 1310#endif
1227 1311
1312static int af9035_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
1313 struct usb_data_stream_properties *stream)
1314{
1315 struct dvb_usb_device *d = fe_to_d(fe);
1316 dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, fe_to_adap(fe)->id);
1317
1318 if (d->udev->speed == USB_SPEED_FULL)
1319 stream->u.bulk.buffersize = 5 * 188;
1320
1321 return 0;
1322}
1323
1324/*
1325 * FIXME: PID filter is property of demodulator and should be moved to the
1326 * correct driver. Also we support only adapter #0 PID filter and will
1327 * disable adapter #1 if USB1.1 is used.
1328 */
1329static int af9035_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
1330{
1331 struct dvb_usb_device *d = adap_to_d(adap);
1332 int ret;
1333
1334 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
1335
1336 ret = af9035_wr_reg_mask(d, 0x80f993, onoff, 0x01);
1337 if (ret < 0)
1338 goto err;
1339
1340 return 0;
1341
1342err:
1343 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1344
1345 return ret;
1346}
1347
1348static int af9035_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
1349 int onoff)
1350{
1351 struct dvb_usb_device *d = adap_to_d(adap);
1352 int ret;
1353 u8 wbuf[2] = {(pid >> 0) & 0xff, (pid >> 8) & 0xff};
1354
1355 dev_dbg(&d->udev->dev, "%s: index=%d pid=%04x onoff=%d\n",
1356 __func__, index, pid, onoff);
1357
1358 ret = af9035_wr_regs(d, 0x80f996, wbuf, 2);
1359 if (ret < 0)
1360 goto err;
1361
1362 ret = af9035_wr_reg(d, 0x80f994, onoff);
1363 if (ret < 0)
1364 goto err;
1365
1366 ret = af9035_wr_reg(d, 0x80f995, index);
1367 if (ret < 0)
1368 goto err;
1369
1370 return 0;
1371
1372err:
1373 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1374
1375 return ret;
1376}
1377
1378static int af9035_probe(struct usb_interface *intf,
1379 const struct usb_device_id *id)
1380{
1381 struct usb_device *udev = interface_to_usbdev(intf);
1382 char manufacturer[sizeof("Afatech")];
1383
1384 memset(manufacturer, 0, sizeof(manufacturer));
1385 usb_string(udev, udev->descriptor.iManufacturer,
1386 manufacturer, sizeof(manufacturer));
1387 /*
1388 * There is two devices having same ID but different chipset. One uses
1389 * AF9015 and the other IT9135 chipset. Only difference seen on lsusb
1390 * is iManufacturer string.
1391 *
1392 * idVendor 0x0ccd TerraTec Electronic GmbH
1393 * idProduct 0x0099
1394 * bcdDevice 2.00
1395 * iManufacturer 1 Afatech
1396 * iProduct 2 DVB-T 2
1397 *
1398 * idVendor 0x0ccd TerraTec Electronic GmbH
1399 * idProduct 0x0099
1400 * bcdDevice 2.00
1401 * iManufacturer 1 ITE Technologies, Inc.
1402 * iProduct 2 DVB-T TV Stick
1403 */
1404 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) &&
1405 (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) {
1406 if (!strcmp("Afatech", manufacturer)) {
1407 dev_dbg(&udev->dev, "%s: rejecting device\n", __func__);
1408 return -ENODEV;
1409 }
1410 }
1411
1412 return dvb_usbv2_probe(intf, id);
1413}
1414
1228/* interface 0 is used by DVB-T receiver and 1415/* interface 0 is used by DVB-T receiver and
1229 interface 1 is for remote controller (HID) */ 1416 interface 1 is for remote controller (HID) */
1230static const struct dvb_usb_device_properties af9035_props = { 1417static const struct dvb_usb_device_properties af9035_props = {
@@ -1237,7 +1424,6 @@ static const struct dvb_usb_device_properties af9035_props = {
1237 .generic_bulk_ctrl_endpoint_response = 0x81, 1424 .generic_bulk_ctrl_endpoint_response = 0x81,
1238 1425
1239 .identify_state = af9035_identify_state, 1426 .identify_state = af9035_identify_state,
1240 .firmware = AF9035_FIRMWARE_AF9035,
1241 .download_firmware = af9035_download_firmware, 1427 .download_firmware = af9035_download_firmware,
1242 1428
1243 .i2c_algo = &af9035_i2c_algo, 1429 .i2c_algo = &af9035_i2c_algo,
@@ -1246,40 +1432,18 @@ static const struct dvb_usb_device_properties af9035_props = {
1246 .tuner_attach = af9035_tuner_attach, 1432 .tuner_attach = af9035_tuner_attach,
1247 .init = af9035_init, 1433 .init = af9035_init,
1248 .get_rc_config = af9035_get_rc_config, 1434 .get_rc_config = af9035_get_rc_config,
1435 .get_stream_config = af9035_get_stream_config,
1249 1436
1250 .get_adapter_count = af9035_get_adapter_count, 1437 .get_adapter_count = af9035_get_adapter_count,
1251 .adapter = { 1438 .adapter = {
1252 { 1439 {
1253 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188), 1440 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1254 }, { 1441 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1255 .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
1256 },
1257 },
1258};
1259
1260static const struct dvb_usb_device_properties it9135_props = {
1261 .driver_name = KBUILD_MODNAME,
1262 .owner = THIS_MODULE,
1263 .adapter_nr = adapter_nr,
1264 .size_of_priv = sizeof(struct state),
1265 1442
1266 .generic_bulk_ctrl_endpoint = 0x02, 1443 .pid_filter_count = 32,
1267 .generic_bulk_ctrl_endpoint_response = 0x81, 1444 .pid_filter_ctrl = af9035_pid_filter_ctrl,
1268 1445 .pid_filter = af9035_pid_filter,
1269 .identify_state = af9035_identify_state,
1270 .firmware = AF9035_FIRMWARE_IT9135,
1271 .download_firmware = af9035_download_firmware_it9135,
1272 1446
1273 .i2c_algo = &af9035_i2c_algo,
1274 .read_config = af9035_read_config_it9135,
1275 .frontend_attach = af9035_frontend_attach,
1276 .tuner_attach = af9035_tuner_attach,
1277 .init = af9035_init,
1278 .get_rc_config = af9035_get_rc_config,
1279
1280 .num_adapters = 1,
1281 .adapter = {
1282 {
1283 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188), 1447 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
1284 }, { 1448 }, {
1285 .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188), 1449 .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
@@ -1288,6 +1452,7 @@ static const struct dvb_usb_device_properties it9135_props = {
1288}; 1452};
1289 1453
1290static const struct usb_device_id af9035_id_table[] = { 1454static const struct usb_device_id af9035_id_table[] = {
1455 /* AF9035 devices */
1291 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_9035, 1456 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_9035,
1292 &af9035_props, "Afatech AF9035 reference design", NULL) }, 1457 &af9035_props, "Afatech AF9035 reference design", NULL) },
1293 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1000, 1458 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1000,
@@ -1312,6 +1477,18 @@ static const struct usb_device_id af9035_id_table[] = {
1312 &af9035_props, "AVerMedia Twinstar (A825)", NULL) }, 1477 &af9035_props, "AVerMedia Twinstar (A825)", NULL) },
1313 { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS, 1478 { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS,
1314 &af9035_props, "Asus U3100Mini Plus", NULL) }, 1479 &af9035_props, "Asus U3100Mini Plus", NULL) },
1480 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa,
1481 &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) },
1482 /* IT9135 devices */
1483#if 0
1484 { DVB_USB_DEVICE(0x048d, 0x9135,
1485 &af9035_props, "IT9135 reference design", NULL) },
1486 { DVB_USB_DEVICE(0x048d, 0x9006,
1487 &af9035_props, "IT9135 reference design", NULL) },
1488#endif
1489 /* XXX: that same ID [0ccd:0099] is used by af9015 driver too */
1490 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099,
1491 &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", NULL) },
1315 { } 1492 { }
1316}; 1493};
1317MODULE_DEVICE_TABLE(usb, af9035_id_table); 1494MODULE_DEVICE_TABLE(usb, af9035_id_table);
@@ -1319,7 +1496,7 @@ MODULE_DEVICE_TABLE(usb, af9035_id_table);
1319static struct usb_driver af9035_usb_driver = { 1496static struct usb_driver af9035_usb_driver = {
1320 .name = KBUILD_MODNAME, 1497 .name = KBUILD_MODNAME,
1321 .id_table = af9035_id_table, 1498 .id_table = af9035_id_table,
1322 .probe = dvb_usbv2_probe, 1499 .probe = af9035_probe,
1323 .disconnect = dvb_usbv2_disconnect, 1500 .disconnect = dvb_usbv2_disconnect,
1324 .suspend = dvb_usbv2_suspend, 1501 .suspend = dvb_usbv2_suspend,
1325 .resume = dvb_usbv2_resume, 1502 .resume = dvb_usbv2_resume,
@@ -1334,4 +1511,5 @@ MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1334MODULE_DESCRIPTION("Afatech AF9035 driver"); 1511MODULE_DESCRIPTION("Afatech AF9035 driver");
1335MODULE_LICENSE("GPL"); 1512MODULE_LICENSE("GPL");
1336MODULE_FIRMWARE(AF9035_FIRMWARE_AF9035); 1513MODULE_FIRMWARE(AF9035_FIRMWARE_AF9035);
1337MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135); 1514MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V1);
1515MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V2);
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.h b/drivers/media/usb/dvb-usb-v2/af9035.h
index 29f3eec22c2c..b5827ca3a01e 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.h
+++ b/drivers/media/usb/dvb-usb-v2/af9035.h
@@ -30,6 +30,7 @@
30#include "mxl5007t.h" 30#include "mxl5007t.h"
31#include "tda18218.h" 31#include "tda18218.h"
32#include "fc2580.h" 32#include "fc2580.h"
33#include "tuner_it913x.h"
33 34
34struct reg_val { 35struct reg_val {
35 u32 reg; 36 u32 reg;
@@ -52,12 +53,18 @@ struct usb_req {
52}; 53};
53 54
54struct state { 55struct state {
56#define BUF_LEN 64
57 u8 buf[BUF_LEN];
55 u8 seq; /* packet sequence number */ 58 u8 seq; /* packet sequence number */
56 bool dual_mode; 59 u8 prechip_version;
60 u8 chip_version;
61 u16 chip_type;
62 u8 dual_mode:1;
63 u16 eeprom_addr;
57 struct af9033_config af9033_config[2]; 64 struct af9033_config af9033_config[2];
58}; 65};
59 66
60u32 clock_lut[] = { 67static const u32 clock_lut_af9035[] = {
61 20480000, /* FPGA */ 68 20480000, /* FPGA */
62 16384000, /* 16.38 MHz */ 69 16384000, /* 16.38 MHz */
63 20480000, /* 20.48 MHz */ 70 20480000, /* 20.48 MHz */
@@ -72,7 +79,7 @@ u32 clock_lut[] = {
72 12000000, /* 12.00 MHz */ 79 12000000, /* 12.00 MHz */
73}; 80};
74 81
75u32 clock_lut_it9135[] = { 82static const u32 clock_lut_it9135[] = {
76 12000000, /* 12.00 MHz */ 83 12000000, /* 12.00 MHz */
77 20480000, /* 20.48 MHz */ 84 20480000, /* 20.48 MHz */
78 36000000, /* 36.00 MHz */ 85 36000000, /* 36.00 MHz */
@@ -86,19 +93,31 @@ u32 clock_lut_it9135[] = {
86}; 93};
87 94
88#define AF9035_FIRMWARE_AF9035 "dvb-usb-af9035-02.fw" 95#define AF9035_FIRMWARE_AF9035 "dvb-usb-af9035-02.fw"
89#define AF9035_FIRMWARE_IT9135 "dvb-usb-it9135-01.fw" 96#define AF9035_FIRMWARE_IT9135_V1 "dvb-usb-it9135-01.fw"
97#define AF9035_FIRMWARE_IT9135_V2 "dvb-usb-it9135-02.fw"
90 98
91/* EEPROM locations */ 99/*
92#define EEPROM_IR_MODE 0x430d 100 * eeprom is memory mapped as read only. Writing that memory mapped address
93#define EEPROM_DUAL_MODE 0x4326 101 * will not corrupt eeprom.
94#define EEPROM_2ND_DEMOD_ADDR 0x4327 102 *
95#define EEPROM_IR_TYPE 0x4329 103 * eeprom has value 0x00 single mode and 0x03 for dual mode as far as I have
96#define EEPROM_1_IFFREQ_L 0x432d 104 * seen to this day.
97#define EEPROM_1_IFFREQ_H 0x432e 105 */
98#define EEPROM_1_TUNER_ID 0x4331 106
99#define EEPROM_2_IFFREQ_L 0x433d 107#define EEPROM_BASE_AF9035 0x42fd
100#define EEPROM_2_IFFREQ_H 0x433e 108#define EEPROM_BASE_IT9135 0x499c
101#define EEPROM_2_TUNER_ID 0x4341 109#define EEPROM_SHIFT 0x10
110
111#define EEPROM_IR_MODE 0x10
112#define EEPROM_DUAL_MODE 0x29
113#define EEPROM_2ND_DEMOD_ADDR 0x2a
114#define EEPROM_IR_TYPE 0x2c
115#define EEPROM_1_IF_L 0x30
116#define EEPROM_1_IF_H 0x31
117#define EEPROM_1_TUNER_ID 0x34
118#define EEPROM_2_IF_L 0x40
119#define EEPROM_2_IF_H 0x41
120#define EEPROM_2_TUNER_ID 0x44
102 121
103/* USB commands */ 122/* USB commands */
104#define CMD_MEM_RD 0x00 123#define CMD_MEM_RD 0x00
diff --git a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-usb-v2/anysee.c
index a20d691d0b63..90cfa35ef6e6 100644
--- a/drivers/media/usb/dvb-usb-v2/anysee.c
+++ b/drivers/media/usb/dvb-usb-v2/anysee.c
@@ -45,25 +45,24 @@
45#include "cxd2820r.h" 45#include "cxd2820r.h"
46 46
47DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 47DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
48static DEFINE_MUTEX(anysee_usb_mutex);
49 48
50static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen, 49static int anysee_ctrl_msg(struct dvb_usb_device *d,
51 u8 *rbuf, u8 rlen) 50 u8 *sbuf, u8 slen, u8 *rbuf, u8 rlen)
52{ 51{
53 struct anysee_state *state = d_to_priv(d); 52 struct anysee_state *state = d_to_priv(d);
54 int act_len, ret, i; 53 int act_len, ret, i;
55 u8 buf[64];
56 54
57 memcpy(&buf[0], sbuf, slen); 55 mutex_lock(&d->usb_mutex);
58 buf[60] = state->seq++;
59 56
60 mutex_lock(&anysee_usb_mutex); 57 memcpy(&state->buf[0], sbuf, slen);
58 state->buf[60] = state->seq++;
61 59
62 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, buf); 60 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, state->buf);
63 61
64 /* We need receive one message more after dvb_usb_generic_rw due 62 /* We need receive one message more after dvb_usb_generic_rw due
65 to weird transaction flow, which is 1 x send + 2 x receive. */ 63 to weird transaction flow, which is 1 x send + 2 x receive. */
66 ret = dvb_usbv2_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf)); 64 ret = dvb_usbv2_generic_rw_locked(d, state->buf, sizeof(state->buf),
65 state->buf, sizeof(state->buf));
67 if (ret) 66 if (ret)
68 goto error_unlock; 67 goto error_unlock;
69 68
@@ -82,20 +81,19 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
82 for (i = 0; i < 3; i++) { 81 for (i = 0; i < 3; i++) {
83 /* receive 2nd answer */ 82 /* receive 2nd answer */
84 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, 83 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
85 d->props->generic_bulk_ctrl_endpoint), buf, sizeof(buf), 84 d->props->generic_bulk_ctrl_endpoint),
86 &act_len, 2000); 85 state->buf, sizeof(state->buf), &act_len, 2000);
87
88 if (ret) { 86 if (ret) {
89 dev_dbg(&d->udev->dev, "%s: recv bulk message " \ 87 dev_dbg(&d->udev->dev,
90 "failed=%d\n", __func__, ret); 88 "%s: recv bulk message failed=%d\n",
89 __func__, ret);
91 } else { 90 } else {
92 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__, 91 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
93 rlen, buf); 92 rlen, state->buf);
94
95 if (buf[63] != 0x4f)
96 dev_dbg(&d->udev->dev, "%s: cmd failed\n",
97 __func__);
98 93
94 if (state->buf[63] != 0x4f)
95 dev_dbg(&d->udev->dev,
96 "%s: cmd failed\n", __func__);
99 break; 97 break;
100 } 98 }
101 } 99 }
@@ -109,11 +107,10 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
109 107
110 /* read request, copy returned data to return buf */ 108 /* read request, copy returned data to return buf */
111 if (rbuf && rlen) 109 if (rbuf && rlen)
112 memcpy(rbuf, buf, rlen); 110 memcpy(rbuf, state->buf, rlen);
113 111
114error_unlock: 112error_unlock:
115 mutex_unlock(&anysee_usb_mutex); 113 mutex_unlock(&d->usb_mutex);
116
117 return ret; 114 return ret;
118} 115}
119 116
@@ -638,7 +635,7 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
638{ 635{
639 struct anysee_state *state = adap_to_priv(adap); 636 struct anysee_state *state = adap_to_priv(adap);
640 struct dvb_usb_device *d = adap_to_d(adap); 637 struct dvb_usb_device *d = adap_to_d(adap);
641 int ret; 638 int ret = 0;
642 u8 tmp; 639 u8 tmp;
643 struct i2c_msg msg[2] = { 640 struct i2c_msg msg[2] = {
644 { 641 {
@@ -884,9 +881,8 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
884 if (!adap->fe[0]) { 881 if (!adap->fe[0]) {
885 /* we have no frontend :-( */ 882 /* we have no frontend :-( */
886 ret = -ENODEV; 883 ret = -ENODEV;
887 dev_err(&d->udev->dev, "%s: Unsupported Anysee version. " \ 884 dev_err(&d->udev->dev,
888 "Please report the " \ 885 "%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n",
889 "<linux-media@vger.kernel.org>.\n",
890 KBUILD_MODNAME); 886 KBUILD_MODNAME);
891 } 887 }
892error: 888error:
diff --git a/drivers/media/usb/dvb-usb-v2/anysee.h b/drivers/media/usb/dvb-usb-v2/anysee.h
index c1a4273f14ff..8f426d9fc6e1 100644
--- a/drivers/media/usb/dvb-usb-v2/anysee.h
+++ b/drivers/media/usb/dvb-usb-v2/anysee.h
@@ -52,8 +52,9 @@ enum cmd {
52}; 52};
53 53
54struct anysee_state { 54struct anysee_state {
55 u8 hw; /* PCB ID */ 55 u8 buf[64];
56 u8 seq; 56 u8 seq;
57 u8 hw; /* PCB ID */
57 u8 fe_id:1; /* frondend ID */ 58 u8 fe_id:1; /* frondend ID */
58 u8 has_ci:1; 59 u8 has_ci:1;
59 u8 ci_attached:1; 60 u8 ci_attached:1;
diff --git a/drivers/media/usb/dvb-usb-v2/az6007.c b/drivers/media/usb/dvb-usb-v2/az6007.c
index 70ec80d8be71..44c64ef361bf 100644
--- a/drivers/media/usb/dvb-usb-v2/az6007.c
+++ b/drivers/media/usb/dvb-usb-v2/az6007.c
@@ -842,7 +842,7 @@ static int az6007_download_firmware(struct dvb_usb_device *d,
842{ 842{
843 pr_debug("Loading az6007 firmware\n"); 843 pr_debug("Loading az6007 firmware\n");
844 844
845 return usbv2_cypress_load_firmware(d->udev, fw, CYPRESS_FX2); 845 return cypress_load_firmware(d->udev, fw, CYPRESS_FX2);
846} 846}
847 847
848/* DVB USB Driver stuff */ 848/* DVB USB Driver stuff */
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index 3cac8bd0b116..658c6d47fdff 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -329,13 +329,16 @@ struct dvb_usb_adapter {
329 u8 feed_count; 329 u8 feed_count;
330 u8 max_feed_count; 330 u8 max_feed_count;
331 s8 active_fe; 331 s8 active_fe;
332#define ADAP_INIT 0
333#define ADAP_SLEEP 1
334#define ADAP_STREAMING 2
335 unsigned long state_bits;
332 336
333 /* dvb */ 337 /* dvb */
334 struct dvb_adapter dvb_adap; 338 struct dvb_adapter dvb_adap;
335 struct dmxdev dmxdev; 339 struct dmxdev dmxdev;
336 struct dvb_demux demux; 340 struct dvb_demux demux;
337 struct dvb_net dvb_net; 341 struct dvb_net dvb_net;
338 struct mutex sync_mutex;
339 342
340 struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP]; 343 struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP];
341 int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *); 344 int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
@@ -400,5 +403,9 @@ extern int dvb_usbv2_reset_resume(struct usb_interface *);
400/* the generic read/write method for device control */ 403/* the generic read/write method for device control */
401extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16); 404extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16);
402extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16); 405extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
406/* caller must hold lock when locked versions are called */
407extern int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *,
408 u8 *, u16, u8 *, u16);
409extern int dvb_usbv2_generic_write_locked(struct dvb_usb_device *, u8 *, u16);
403 410
404#endif 411#endif
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 086792055912..19f6737d9817 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -28,10 +28,11 @@ MODULE_PARM_DESC(disable_rc_polling,
28static int dvb_usb_force_pid_filter_usage; 28static int dvb_usb_force_pid_filter_usage;
29module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage, 29module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage,
30 int, 0444); 30 int, 0444);
31MODULE_PARM_DESC(force_pid_filter_usage, "force all DVB USB devices to use a " \ 31MODULE_PARM_DESC(force_pid_filter_usage,
32 "PID filter, if any (default: 0)"); 32 "force all DVB USB devices to use a PID filter, if any (default: 0)");
33 33
34static int dvb_usbv2_download_firmware(struct dvb_usb_device *d, const char *name) 34static int dvb_usbv2_download_firmware(struct dvb_usb_device *d,
35 const char *name)
35{ 36{
36 int ret; 37 int ret;
37 const struct firmware *fw; 38 const struct firmware *fw;
@@ -44,10 +45,9 @@ static int dvb_usbv2_download_firmware(struct dvb_usb_device *d, const char *nam
44 45
45 ret = request_firmware(&fw, name, &d->udev->dev); 46 ret = request_firmware(&fw, name, &d->udev->dev);
46 if (ret < 0) { 47 if (ret < 0) {
47 dev_err(&d->udev->dev, "%s: Did not find the firmware file "\ 48 dev_err(&d->udev->dev,
48 "'%s'. Please see linux/Documentation/dvb/ " \ 49 "%s: Did not find the firmware file '%s'. Please see linux/Documentation/dvb/ for more details on firmware-problems. Status %d\n",
49 "for more details on firmware-problems. " \ 50 KBUILD_MODNAME, name, ret);
50 "Status %d\n", KBUILD_MODNAME, name, ret);
51 goto err; 51 goto err;
52 } 52 }
53 53
@@ -181,9 +181,9 @@ static int dvb_usbv2_remote_init(struct dvb_usb_device *d)
181 /* initialize a work queue for handling polling */ 181 /* initialize a work queue for handling polling */
182 INIT_DELAYED_WORK(&d->rc_query_work, 182 INIT_DELAYED_WORK(&d->rc_query_work,
183 dvb_usb_read_remote_control); 183 dvb_usb_read_remote_control);
184 dev_info(&d->udev->dev, "%s: schedule remote query interval " \ 184 dev_info(&d->udev->dev,
185 "to %d msecs\n", KBUILD_MODNAME, 185 "%s: schedule remote query interval to %d msecs\n",
186 d->rc.interval); 186 KBUILD_MODNAME, d->rc.interval);
187 schedule_delayed_work(&d->rc_query_work, 187 schedule_delayed_work(&d->rc_query_work,
188 msecs_to_jiffies(d->rc.interval)); 188 msecs_to_jiffies(d->rc.interval));
189 d->rc_polling_active = true; 189 d->rc_polling_active = true;
@@ -253,128 +253,159 @@ static int dvb_usbv2_adapter_stream_exit(struct dvb_usb_adapter *adap)
253 return usb_urb_exitv2(&adap->stream); 253 return usb_urb_exitv2(&adap->stream);
254} 254}
255 255
256static inline int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, 256static int wait_schedule(void *ptr)
257 int count) 257{
258 schedule();
259
260 return 0;
261}
262
263static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
258{ 264{
259 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv; 265 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
260 struct dvb_usb_device *d = adap_to_d(adap); 266 struct dvb_usb_device *d = adap_to_d(adap);
261 int ret; 267 int ret = 0;
262 dev_dbg(&d->udev->dev, "%s: adap=%d active_fe=%d feed_type=%d " \ 268 struct usb_data_stream_properties stream_props;
263 "setting pid [%s]: %04x (%04d) at index %d '%s'\n", 269 dev_dbg(&d->udev->dev,
270 "%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: %04x (%04d) at index %d\n",
264 __func__, adap->id, adap->active_fe, dvbdmxfeed->type, 271 __func__, adap->id, adap->active_fe, dvbdmxfeed->type,
265 adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid, 272 adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid,
266 dvbdmxfeed->pid, dvbdmxfeed->index, 273 dvbdmxfeed->pid, dvbdmxfeed->index);
267 (count == 1) ? "on" : "off"); 274
275 /* wait init is done */
276 wait_on_bit(&adap->state_bits, ADAP_INIT, wait_schedule,
277 TASK_UNINTERRUPTIBLE);
268 278
269 if (adap->active_fe == -1) 279 if (adap->active_fe == -1)
270 return -EINVAL; 280 return -EINVAL;
271 281
272 adap->feed_count += count; 282 /* skip feed setup if we are already feeding */
273 283 if (adap->feed_count++ > 0)
274 /* stop feeding if it is last pid */ 284 goto skip_feed_start;
275 if (adap->feed_count == 0) {
276 dev_dbg(&d->udev->dev, "%s: stop feeding\n", __func__);
277
278 if (d->props->streaming_ctrl) {
279 ret = d->props->streaming_ctrl(
280 adap->fe[adap->active_fe], 0);
281 if (ret < 0) {
282 dev_err(&d->udev->dev, "%s: streaming_ctrl() " \
283 "failed=%d\n", KBUILD_MODNAME,
284 ret);
285 usb_urb_killv2(&adap->stream);
286 goto err_mutex_unlock;
287 }
288 }
289 usb_urb_killv2(&adap->stream);
290 mutex_unlock(&adap->sync_mutex);
291 }
292 285
293 /* activate the pid on the device pid filter */ 286 /* set 'streaming' status bit */
294 if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && 287 set_bit(ADAP_STREAMING, &adap->state_bits);
295 adap->pid_filtering && adap->props->pid_filter) { 288
296 ret = adap->props->pid_filter(adap, dvbdmxfeed->index, 289 /* resolve input and output streaming parameters */
297 dvbdmxfeed->pid, (count == 1) ? 1 : 0); 290 if (d->props->get_stream_config) {
298 if (ret < 0) 291 memcpy(&stream_props, &adap->props->stream,
299 dev_err(&d->udev->dev, "%s: pid_filter() failed=%d\n", 292 sizeof(struct usb_data_stream_properties));
293 ret = d->props->get_stream_config(adap->fe[adap->active_fe],
294 &adap->ts_type, &stream_props);
295 if (ret)
296 dev_err(&d->udev->dev,
297 "%s: get_stream_config() failed=%d\n",
300 KBUILD_MODNAME, ret); 298 KBUILD_MODNAME, ret);
299 } else {
300 stream_props = adap->props->stream;
301 } 301 }
302 302
303 /* start feeding if it is first pid */ 303 switch (adap->ts_type) {
304 if (adap->feed_count == 1 && count == 1) { 304 case DVB_USB_FE_TS_TYPE_204:
305 struct usb_data_stream_properties stream_props; 305 adap->stream.complete = dvb_usb_data_complete_204;
306 mutex_lock(&adap->sync_mutex); 306 break;
307 dev_dbg(&d->udev->dev, "%s: start feeding\n", __func__); 307 case DVB_USB_FE_TS_TYPE_RAW:
308 adap->stream.complete = dvb_usb_data_complete_raw;
309 break;
310 case DVB_USB_FE_TS_TYPE_188:
311 default:
312 adap->stream.complete = dvb_usb_data_complete;
313 break;
314 }
308 315
309 /* resolve input and output streaming paramters */ 316 /* submit USB streaming packets */
310 if (d->props->get_stream_config) { 317 usb_urb_submitv2(&adap->stream, &stream_props);
311 memcpy(&stream_props, &adap->props->stream,
312 sizeof(struct usb_data_stream_properties));
313 ret = d->props->get_stream_config(
314 adap->fe[adap->active_fe],
315 &adap->ts_type, &stream_props);
316 if (ret < 0)
317 goto err_mutex_unlock;
318 } else {
319 stream_props = adap->props->stream;
320 }
321 318
322 switch (adap->ts_type) { 319 /* enable HW PID filter */
323 case DVB_USB_FE_TS_TYPE_204: 320 if (adap->pid_filtering && adap->props->pid_filter_ctrl) {
324 adap->stream.complete = dvb_usb_data_complete_204; 321 ret = adap->props->pid_filter_ctrl(adap, 1);
325 break; 322 if (ret)
326 case DVB_USB_FE_TS_TYPE_RAW: 323 dev_err(&d->udev->dev,
327 adap->stream.complete = dvb_usb_data_complete_raw; 324 "%s: pid_filter_ctrl() failed=%d\n",
328 break; 325 KBUILD_MODNAME, ret);
329 case DVB_USB_FE_TS_TYPE_188: 326 }
330 default:
331 adap->stream.complete = dvb_usb_data_complete;
332 break;
333 }
334 327
335 usb_urb_submitv2(&adap->stream, &stream_props); 328 /* ask device to start streaming */
336 329 if (d->props->streaming_ctrl) {
337 if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && 330 ret = d->props->streaming_ctrl(adap->fe[adap->active_fe], 1);
338 adap->props->caps & 331 if (ret)
339 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && 332 dev_err(&d->udev->dev,
340 adap->props->pid_filter_ctrl) { 333 "%s: streaming_ctrl() failed=%d\n",
341 ret = adap->props->pid_filter_ctrl(adap, 334 KBUILD_MODNAME, ret);
342 adap->pid_filtering); 335 }
343 if (ret < 0) { 336skip_feed_start:
344 dev_err(&d->udev->dev, "%s: " \
345 "pid_filter_ctrl() failed=%d\n",
346 KBUILD_MODNAME, ret);
347 goto err_mutex_unlock;
348 }
349 }
350 337
351 if (d->props->streaming_ctrl) { 338 /* add PID to device HW PID filter */
352 ret = d->props->streaming_ctrl( 339 if (adap->pid_filtering && adap->props->pid_filter) {
353 adap->fe[adap->active_fe], 1); 340 ret = adap->props->pid_filter(adap, dvbdmxfeed->index,
354 if (ret < 0) { 341 dvbdmxfeed->pid, 1);
355 dev_err(&d->udev->dev, "%s: streaming_ctrl() " \ 342 if (ret)
356 "failed=%d\n", KBUILD_MODNAME, 343 dev_err(&d->udev->dev, "%s: pid_filter() failed=%d\n",
357 ret); 344 KBUILD_MODNAME, ret);
358 goto err_mutex_unlock;
359 }
360 }
361 } 345 }
362 346
363 return 0; 347 if (ret)
364err_mutex_unlock: 348 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
365 mutex_unlock(&adap->sync_mutex);
366 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
367 return ret; 349 return ret;
368} 350}
369 351
370static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
371{
372 return dvb_usb_ctrl_feed(dvbdmxfeed, 1);
373}
374
375static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) 352static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
376{ 353{
377 return dvb_usb_ctrl_feed(dvbdmxfeed, -1); 354 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
355 struct dvb_usb_device *d = adap_to_d(adap);
356 int ret = 0;
357 dev_dbg(&d->udev->dev,
358 "%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: %04x (%04d) at index %d\n",
359 __func__, adap->id, adap->active_fe, dvbdmxfeed->type,
360 adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid,
361 dvbdmxfeed->pid, dvbdmxfeed->index);
362
363 if (adap->active_fe == -1)
364 return -EINVAL;
365
366 /* remove PID from device HW PID filter */
367 if (adap->pid_filtering && adap->props->pid_filter) {
368 ret = adap->props->pid_filter(adap, dvbdmxfeed->index,
369 dvbdmxfeed->pid, 0);
370 if (ret)
371 dev_err(&d->udev->dev, "%s: pid_filter() failed=%d\n",
372 KBUILD_MODNAME, ret);
373 }
374
375 /* we cannot stop streaming until last PID is removed */
376 if (--adap->feed_count > 0)
377 goto skip_feed_stop;
378
379 /* ask device to stop streaming */
380 if (d->props->streaming_ctrl) {
381 ret = d->props->streaming_ctrl(adap->fe[adap->active_fe], 0);
382 if (ret)
383 dev_err(&d->udev->dev,
384 "%s: streaming_ctrl() failed=%d\n",
385 KBUILD_MODNAME, ret);
386 }
387
388 /* disable HW PID filter */
389 if (adap->pid_filtering && adap->props->pid_filter_ctrl) {
390 ret = adap->props->pid_filter_ctrl(adap, 0);
391 if (ret)
392 dev_err(&d->udev->dev,
393 "%s: pid_filter_ctrl() failed=%d\n",
394 KBUILD_MODNAME, ret);
395 }
396
397 /* kill USB streaming packets */
398 usb_urb_killv2(&adap->stream);
399
400 /* clear 'streaming' status bit */
401 clear_bit(ADAP_STREAMING, &adap->state_bits);
402 smp_mb__after_clear_bit();
403 wake_up_bit(&adap->state_bits, ADAP_STREAMING);
404skip_feed_stop:
405
406 if (ret)
407 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
408 return ret;
378} 409}
379 410
380static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap) 411static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap)
@@ -435,8 +466,6 @@ static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap)
435 goto err_dvb_net_init; 466 goto err_dvb_net_init;
436 } 467 }
437 468
438 mutex_init(&adap->sync_mutex);
439
440 return 0; 469 return 0;
441err_dvb_net_init: 470err_dvb_net_init:
442 dvb_dmxdev_release(&adap->dmxdev); 471 dvb_dmxdev_release(&adap->dmxdev);
@@ -500,7 +529,7 @@ static int dvb_usb_fe_init(struct dvb_frontend *fe)
500 529
501 if (!adap->suspend_resume_active) { 530 if (!adap->suspend_resume_active) {
502 adap->active_fe = fe->id; 531 adap->active_fe = fe->id;
503 mutex_lock(&adap->sync_mutex); 532 set_bit(ADAP_INIT, &adap->state_bits);
504 } 533 }
505 534
506 ret = dvb_usbv2_device_power_ctrl(d, 1); 535 ret = dvb_usbv2_device_power_ctrl(d, 1);
@@ -519,8 +548,11 @@ static int dvb_usb_fe_init(struct dvb_frontend *fe)
519 goto err; 548 goto err;
520 } 549 }
521err: 550err:
522 if (!adap->suspend_resume_active) 551 if (!adap->suspend_resume_active) {
523 mutex_unlock(&adap->sync_mutex); 552 clear_bit(ADAP_INIT, &adap->state_bits);
553 smp_mb__after_clear_bit();
554 wake_up_bit(&adap->state_bits, ADAP_INIT);
555 }
524 556
525 dev_dbg(&d->udev->dev, "%s: ret=%d\n", __func__, ret); 557 dev_dbg(&d->udev->dev, "%s: ret=%d\n", __func__, ret);
526 return ret; 558 return ret;
@@ -534,8 +566,11 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
534 dev_dbg(&d->udev->dev, "%s: adap=%d fe=%d\n", __func__, adap->id, 566 dev_dbg(&d->udev->dev, "%s: adap=%d fe=%d\n", __func__, adap->id,
535 fe->id); 567 fe->id);
536 568
537 if (!adap->suspend_resume_active) 569 if (!adap->suspend_resume_active) {
538 mutex_lock(&adap->sync_mutex); 570 set_bit(ADAP_SLEEP, &adap->state_bits);
571 wait_on_bit(&adap->state_bits, ADAP_STREAMING, wait_schedule,
572 TASK_UNINTERRUPTIBLE);
573 }
539 574
540 if (adap->fe_sleep[fe->id]) { 575 if (adap->fe_sleep[fe->id]) {
541 ret = adap->fe_sleep[fe->id](fe); 576 ret = adap->fe_sleep[fe->id](fe);
@@ -555,7 +590,9 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
555err: 590err:
556 if (!adap->suspend_resume_active) { 591 if (!adap->suspend_resume_active) {
557 adap->active_fe = -1; 592 adap->active_fe = -1;
558 mutex_unlock(&adap->sync_mutex); 593 clear_bit(ADAP_SLEEP, &adap->state_bits);
594 smp_mb__after_clear_bit();
595 wake_up_bit(&adap->state_bits, ADAP_SLEEP);
559 } 596 }
560 597
561 dev_dbg(&d->udev->dev, "%s: ret=%d\n", __func__, ret); 598 dev_dbg(&d->udev->dev, "%s: ret=%d\n", __func__, ret);
@@ -574,8 +611,9 @@ static int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter *adap)
574 if (d->props->frontend_attach) { 611 if (d->props->frontend_attach) {
575 ret = d->props->frontend_attach(adap); 612 ret = d->props->frontend_attach(adap);
576 if (ret < 0) { 613 if (ret < 0) {
577 dev_dbg(&d->udev->dev, "%s: frontend_attach() " \ 614 dev_dbg(&d->udev->dev,
578 "failed=%d\n", __func__, ret); 615 "%s: frontend_attach() failed=%d\n",
616 __func__, ret);
579 goto err_dvb_frontend_detach; 617 goto err_dvb_frontend_detach;
580 } 618 }
581 } else { 619 } else {
@@ -595,8 +633,9 @@ static int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter *adap)
595 633
596 ret = dvb_register_frontend(&adap->dvb_adap, adap->fe[i]); 634 ret = dvb_register_frontend(&adap->dvb_adap, adap->fe[i]);
597 if (ret < 0) { 635 if (ret < 0) {
598 dev_err(&d->udev->dev, "%s: frontend%d registration " \ 636 dev_err(&d->udev->dev,
599 "failed\n", KBUILD_MODNAME, i); 637 "%s: frontend%d registration failed\n",
638 KBUILD_MODNAME, i);
600 goto err_dvb_unregister_frontend; 639 goto err_dvb_unregister_frontend;
601 } 640 }
602 641
@@ -670,33 +709,33 @@ static int dvb_usbv2_adapter_init(struct dvb_usb_device *d)
670 /* speed - when running at FULL speed we need a HW PID filter */ 709 /* speed - when running at FULL speed we need a HW PID filter */
671 if (d->udev->speed == USB_SPEED_FULL && 710 if (d->udev->speed == USB_SPEED_FULL &&
672 !(adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) { 711 !(adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
673 dev_err(&d->udev->dev, "%s: this USB2.0 device " \ 712 dev_err(&d->udev->dev,
674 "cannot be run on a USB1.1 port (it " \ 713 "%s: this USB2.0 device cannot be run on a USB1.1 port (it lacks a hardware PID filter)\n",
675 "lacks a hardware PID filter)\n",
676 KBUILD_MODNAME); 714 KBUILD_MODNAME);
677 ret = -ENODEV; 715 ret = -ENODEV;
678 goto err; 716 goto err;
679 } else if ((d->udev->speed == USB_SPEED_FULL && 717 } else if ((d->udev->speed == USB_SPEED_FULL &&
680 adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) || 718 adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
681 (adap->props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) { 719 (adap->props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
682 dev_info(&d->udev->dev, "%s: will use the device's " \ 720 dev_info(&d->udev->dev,
683 "hardware PID filter " \ 721 "%s: will use the device's hardware PID filter (table count: %d)\n",
684 "(table count: %d)\n", KBUILD_MODNAME, 722 KBUILD_MODNAME,
685 adap->props->pid_filter_count); 723 adap->props->pid_filter_count);
686 adap->pid_filtering = 1; 724 adap->pid_filtering = 1;
687 adap->max_feed_count = adap->props->pid_filter_count; 725 adap->max_feed_count = adap->props->pid_filter_count;
688 } else { 726 } else {
689 dev_info(&d->udev->dev, "%s: will pass the complete " \ 727 dev_info(&d->udev->dev,
690 "MPEG2 transport stream to the " \ 728 "%s: will pass the complete MPEG2 transport stream to the software demuxer\n",
691 "software demuxer\n", KBUILD_MODNAME); 729 KBUILD_MODNAME);
692 adap->pid_filtering = 0; 730 adap->pid_filtering = 0;
693 adap->max_feed_count = 255; 731 adap->max_feed_count = 255;
694 } 732 }
695 733
696 if (!adap->pid_filtering && dvb_usb_force_pid_filter_usage && 734 if (!adap->pid_filtering && dvb_usb_force_pid_filter_usage &&
697 adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) { 735 adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) {
698 dev_info(&d->udev->dev, "%s: PID filter enabled by " \ 736 dev_info(&d->udev->dev,
699 "module option\n", KBUILD_MODNAME); 737 "%s: PID filter enabled by module option\n",
738 KBUILD_MODNAME);
700 adap->pid_filtering = 1; 739 adap->pid_filtering = 1;
701 adap->max_feed_count = adap->props->pid_filter_count; 740 adap->max_feed_count = adap->props->pid_filter_count;
702 } 741 }
@@ -825,8 +864,9 @@ static void dvb_usbv2_init_work(struct work_struct *work)
825 if (ret == 0) { 864 if (ret == 0) {
826 ; 865 ;
827 } else if (ret == COLD) { 866 } else if (ret == COLD) {
828 dev_info(&d->udev->dev, "%s: found a '%s' in cold " \ 867 dev_info(&d->udev->dev,
829 "state\n", KBUILD_MODNAME, d->name); 868 "%s: found a '%s' in cold state\n",
869 KBUILD_MODNAME, d->name);
830 870
831 if (!name) 871 if (!name)
832 name = d->props->firmware; 872 name = d->props->firmware;
@@ -868,8 +908,9 @@ static void dvb_usbv2_init_work(struct work_struct *work)
868 if (ret < 0) 908 if (ret < 0)
869 goto err_usb_driver_release_interface; 909 goto err_usb_driver_release_interface;
870 910
871 dev_info(&d->udev->dev, "%s: '%s' successfully initialized and " \ 911 dev_info(&d->udev->dev,
872 "connected\n", KBUILD_MODNAME, d->name); 912 "%s: '%s' successfully initialized and connected\n",
913 KBUILD_MODNAME, d->name);
873 914
874 return; 915 return;
875err_usb_driver_release_interface: 916err_usb_driver_release_interface:
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c
index 5716662b4834..33ff97e708e3 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c
@@ -21,8 +21,8 @@
21 21
22#include "dvb_usb_common.h" 22#include "dvb_usb_common.h"
23 23
24int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf, 24static int dvb_usb_v2_generic_io(struct dvb_usb_device *d,
25 u16 rlen) 25 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
26{ 26{
27 int ret, actual_length; 27 int ret, actual_length;
28 28
@@ -32,8 +32,6 @@ int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
32 return -EINVAL; 32 return -EINVAL;
33 } 33 }
34 34
35 mutex_lock(&d->usb_mutex);
36
37 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf); 35 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf);
38 36
39 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev, 37 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
@@ -56,20 +54,51 @@ int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
56 d->props->generic_bulk_ctrl_endpoint_response), 54 d->props->generic_bulk_ctrl_endpoint_response),
57 rbuf, rlen, &actual_length, 2000); 55 rbuf, rlen, &actual_length, 2000);
58 if (ret) 56 if (ret)
59 dev_err(&d->udev->dev, "%s: 2nd usb_bulk_msg() " \ 57 dev_err(&d->udev->dev,
60 "failed=%d\n", KBUILD_MODNAME, ret); 58 "%s: 2nd usb_bulk_msg() failed=%d\n",
59 KBUILD_MODNAME, ret);
61 60
62 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__, 61 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
63 actual_length, rbuf); 62 actual_length, rbuf);
64 } 63 }
65 64
65 return ret;
66}
67
68int dvb_usbv2_generic_rw(struct dvb_usb_device *d,
69 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
70{
71 int ret;
72
73 mutex_lock(&d->usb_mutex);
74 ret = dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
66 mutex_unlock(&d->usb_mutex); 75 mutex_unlock(&d->usb_mutex);
76
67 return ret; 77 return ret;
68} 78}
69EXPORT_SYMBOL(dvb_usbv2_generic_rw); 79EXPORT_SYMBOL(dvb_usbv2_generic_rw);
70 80
71int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len) 81int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
72{ 82{
73 return dvb_usbv2_generic_rw(d, buf, len, NULL, 0); 83 int ret;
84
85 mutex_lock(&d->usb_mutex);
86 ret = dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
87 mutex_unlock(&d->usb_mutex);
88
89 return ret;
74} 90}
75EXPORT_SYMBOL(dvb_usbv2_generic_write); 91EXPORT_SYMBOL(dvb_usbv2_generic_write);
92
93int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *d,
94 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
95{
96 return dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
97}
98EXPORT_SYMBOL(dvb_usbv2_generic_rw_locked);
99
100int dvb_usbv2_generic_write_locked(struct dvb_usb_device *d, u8 *buf, u16 len)
101{
102 return dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
103}
104EXPORT_SYMBOL(dvb_usbv2_generic_write_locked);
diff --git a/drivers/media/usb/dvb-usb-v2/it913x.c b/drivers/media/usb/dvb-usb-v2/it913x.c
index 833847995c65..e48cdeb9df41 100644
--- a/drivers/media/usb/dvb-usb-v2/it913x.c
+++ b/drivers/media/usb/dvb-usb-v2/it913x.c
@@ -218,6 +218,7 @@ static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
218 218
219 deb_info(1, "PID_C (%02x)", onoff); 219 deb_info(1, "PID_C (%02x)", onoff);
220 220
221 st->pid_filter_onoff = adap->pid_filtering;
221 ret = it913x_wr_reg(d, pro, PID_EN, st->pid_filter_onoff); 222 ret = it913x_wr_reg(d, pro, PID_EN, st->pid_filter_onoff);
222 223
223 mutex_unlock(&d->i2c_mutex); 224 mutex_unlock(&d->i2c_mutex);
diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c b/drivers/media/usb/dvb-usb-v2/lmedm04.c
index f30c58cecbba..b3fd0ffa3c3f 100644
--- a/drivers/media/usb/dvb-usb-v2/lmedm04.c
+++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c
@@ -1241,10 +1241,13 @@ static int lme2510_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
1241 struct usb_data_stream_properties *stream) 1241 struct usb_data_stream_properties *stream)
1242{ 1242{
1243 struct dvb_usb_adapter *adap = fe_to_adap(fe); 1243 struct dvb_usb_adapter *adap = fe_to_adap(fe);
1244 struct dvb_usb_device *d = adap_to_d(adap); 1244 struct dvb_usb_device *d;
1245 1245
1246 if (adap == NULL) 1246 if (adap == NULL)
1247 return 0; 1247 return 0;
1248
1249 d = adap_to_d(adap);
1250
1248 /* Turn PID filter on the fly by module option */ 1251 /* Turn PID filter on the fly by module option */
1249 if (pid_filter == 2) { 1252 if (pid_filter == 2) {
1250 adap->pid_filtering = 1; 1253 adap->pid_filtering = 1;
@@ -1299,8 +1302,7 @@ static void lme2510_exit(struct dvb_usb_device *d)
1299 1302
1300 if (d != NULL) { 1303 if (d != NULL) {
1301 usb_buffer = lme2510_exit_int(d); 1304 usb_buffer = lme2510_exit_int(d);
1302 if (usb_buffer != NULL) 1305 kfree(usb_buffer);
1303 kfree(usb_buffer);
1304 } 1306 }
1305} 1307}
1306 1308
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
index 432706ae5274..3f3f8bfd190b 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
@@ -21,6 +21,7 @@
21#ifndef __MXL111SF_DEMOD_H__ 21#ifndef __MXL111SF_DEMOD_H__
22#define __MXL111SF_DEMOD_H__ 22#define __MXL111SF_DEMOD_H__
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25#include "mxl111sf.h" 26#include "mxl111sf.h"
26 27
@@ -31,8 +32,7 @@ struct mxl111sf_demod_config {
31 struct mxl111sf_reg_ctrl_info *ctrl_reg_info); 32 struct mxl111sf_reg_ctrl_info *ctrl_reg_info);
32}; 33};
33 34
34#if defined(CONFIG_DVB_USB_MXL111SF) || \ 35#if IS_ENABLED(CONFIG_DVB_USB_MXL111SF)
35 (defined(CONFIG_DVB_USB_MXL111SF_MODULE) && defined(MODULE))
36extern 36extern
37struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state, 37struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
38 struct mxl111sf_demod_config *cfg); 38 struct mxl111sf_demod_config *cfg);
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
index ff333960b184..90f583e5d6a6 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
@@ -21,8 +21,8 @@
21#ifndef __MXL111SF_TUNER_H__ 21#ifndef __MXL111SF_TUNER_H__
22#define __MXL111SF_TUNER_H__ 22#define __MXL111SF_TUNER_H__
23 23
24#include <linux/kconfig.h>
24#include "dvb_frontend.h" 25#include "dvb_frontend.h"
25
26#include "mxl111sf.h" 26#include "mxl111sf.h"
27 27
28enum mxl_if_freq { 28enum mxl_if_freq {
@@ -60,8 +60,7 @@ struct mxl111sf_tuner_config {
60 60
61/* ------------------------------------------------------------------------ */ 61/* ------------------------------------------------------------------------ */
62 62
63#if defined(CONFIG_DVB_USB_MXL111SF) || \ 63#if IS_ENABLED(CONFIG_DVB_USB_MXL111SF)
64 (defined(CONFIG_DVB_USB_MXL111SF_MODULE) && defined(MODULE))
65extern 64extern
66struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe, 65struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
67 struct mxl111sf_state *mxl_state, 66 struct mxl111sf_state *mxl_state,
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index d98387a3c95e..22015fe1a0f3 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -33,6 +33,7 @@
33#include "e4000.h" 33#include "e4000.h"
34#include "fc2580.h" 34#include "fc2580.h"
35#include "tua9001.h" 35#include "tua9001.h"
36#include "r820t.h"
36 37
37DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 38DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
38 39
@@ -375,6 +376,7 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
375 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf}; 376 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
376 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf}; 377 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
377 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf}; 378 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
379 struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 5, buf};
378 380
379 dev_dbg(&d->udev->dev, "%s:\n", __func__); 381 dev_dbg(&d->udev->dev, "%s:\n", __func__);
380 382
@@ -479,6 +481,14 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
479 goto found; 481 goto found;
480 } 482 }
481 483
484 /* check R820T by reading tuner stats at I2C addr 0x1a */
485 ret = rtl28xxu_ctrl_msg(d, &req_r820t);
486 if (ret == 0) {
487 priv->tuner = TUNER_RTL2832_R820T;
488 priv->tuner_name = "R820T";
489 goto found;
490 }
491
482found: 492found:
483 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name); 493 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
484 494
@@ -589,6 +599,12 @@ static struct rtl2832_config rtl28xxu_rtl2832_e4000_config = {
589 .tuner = TUNER_RTL2832_E4000, 599 .tuner = TUNER_RTL2832_E4000,
590}; 600};
591 601
602static struct rtl2832_config rtl28xxu_rtl2832_r820t_config = {
603 .i2c_addr = 0x10,
604 .xtal = 28800000,
605 .tuner = TUNER_RTL2832_R820T,
606};
607
592static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d, 608static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
593 int cmd, int arg) 609 int cmd, int arg)
594{ 610{
@@ -728,6 +744,9 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
728 case TUNER_RTL2832_E4000: 744 case TUNER_RTL2832_E4000:
729 rtl2832_config = &rtl28xxu_rtl2832_e4000_config; 745 rtl2832_config = &rtl28xxu_rtl2832_e4000_config;
730 break; 746 break;
747 case TUNER_RTL2832_R820T:
748 rtl2832_config = &rtl28xxu_rtl2832_r820t_config;
749 break;
731 default: 750 default:
732 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n", 751 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
733 KBUILD_MODNAME, priv->tuner_name); 752 KBUILD_MODNAME, priv->tuner_name);
@@ -840,6 +859,13 @@ static const struct fc0012_config rtl2832u_fc0012_config = {
840 .xtal_freq = FC_XTAL_28_8_MHZ, 859 .xtal_freq = FC_XTAL_28_8_MHZ,
841}; 860};
842 861
862static const struct r820t_config rtl2832u_r820t_config = {
863 .i2c_addr = 0x1a,
864 .xtal = 28800000,
865 .max_i2c_msg_len = 2,
866 .rafael_chip = CHIP_R820T,
867};
868
843static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) 869static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
844{ 870{
845 int ret; 871 int ret;
@@ -889,6 +915,14 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
889 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap, 915 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap,
890 &rtl2832u_tua9001_config); 916 &rtl2832u_tua9001_config);
891 break; 917 break;
918 case TUNER_RTL2832_R820T:
919 fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap,
920 &rtl2832u_r820t_config);
921
922 /* Use tuner to get the signal strength */
923 adap->fe[0]->ops.read_signal_strength =
924 adap->fe[0]->ops.tuner_ops.get_rf_strength;
925 break;
892 default: 926 default:
893 fe = NULL; 927 fe = NULL;
894 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, 928 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
@@ -1372,6 +1406,8 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1372 &rtl2832u_props, "Digivox Micro Hd", NULL) }, 1406 &rtl2832u_props, "Digivox Micro Hd", NULL) },
1373 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620, 1407 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
1374 &rtl2832u_props, "Compro VideoMate U620F", NULL) }, 1408 &rtl2832u_props, "Compro VideoMate U620F", NULL) },
1409 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
1410 &rtl2832u_props, "MaxMedia HU394-T", NULL) },
1375 { } 1411 { }
1376}; 1412};
1377MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); 1413MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
index 2f3af2d3b6ce..533a33127289 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
@@ -82,6 +82,7 @@ enum rtl28xxu_tuner {
82 TUNER_RTL2832_E4000, 82 TUNER_RTL2832_E4000,
83 TUNER_RTL2832_TDA18272, 83 TUNER_RTL2832_TDA18272,
84 TUNER_RTL2832_FC0013, 84 TUNER_RTL2832_FC0013,
85 TUNER_RTL2832_R820T,
85}; 86};
86 87
87struct rtl28xxu_req { 88struct rtl28xxu_req {
diff --git a/drivers/media/usb/dvb-usb-v2/usb_urb.c b/drivers/media/usb/dvb-usb-v2/usb_urb.c
index 7346f85f3f2f..ca8f3c2b1082 100644
--- a/drivers/media/usb/dvb-usb-v2/usb_urb.c
+++ b/drivers/media/usb/dvb-usb-v2/usb_urb.c
@@ -22,8 +22,8 @@ static void usb_urb_complete(struct urb *urb)
22 int i; 22 int i;
23 u8 *b; 23 u8 *b;
24 24
25 dev_dbg_ratelimited(&stream->udev->dev, "%s: %s urb completed " \ 25 dev_dbg_ratelimited(&stream->udev->dev,
26 "status=%d length=%d/%d pack_num=%d errors=%d\n", 26 "%s: %s urb completed status=%d length=%d/%d pack_num=%d errors=%d\n",
27 __func__, ptype == PIPE_ISOCHRONOUS ? "isoc" : "bulk", 27 __func__, ptype == PIPE_ISOCHRONOUS ? "isoc" : "bulk",
28 urb->status, urb->actual_length, 28 urb->status, urb->actual_length,
29 urb->transfer_buffer_length, 29 urb->transfer_buffer_length,
@@ -49,8 +49,8 @@ static void usb_urb_complete(struct urb *urb)
49 case PIPE_ISOCHRONOUS: 49 case PIPE_ISOCHRONOUS:
50 for (i = 0; i < urb->number_of_packets; i++) { 50 for (i = 0; i < urb->number_of_packets; i++) {
51 if (urb->iso_frame_desc[i].status != 0) 51 if (urb->iso_frame_desc[i].status != 0)
52 dev_dbg(&stream->udev->dev, "%s: iso frame " \ 52 dev_dbg(&stream->udev->dev,
53 "descriptor has an error=%d\n", 53 "%s: iso frame descriptor has an error=%d\n",
54 __func__, 54 __func__,
55 urb->iso_frame_desc[i].status); 55 urb->iso_frame_desc[i].status);
56 else if (urb->iso_frame_desc[i].actual_length > 0) 56 else if (urb->iso_frame_desc[i].actual_length > 0)
@@ -67,8 +67,9 @@ static void usb_urb_complete(struct urb *urb)
67 stream->complete(stream, b, urb->actual_length); 67 stream->complete(stream, b, urb->actual_length);
68 break; 68 break;
69 default: 69 default:
70 dev_err(&stream->udev->dev, "%s: unknown endpoint type in " \ 70 dev_err(&stream->udev->dev,
71 "completition handler\n", KBUILD_MODNAME); 71 "%s: unknown endpoint type in completition handler\n",
72 KBUILD_MODNAME);
72 return; 73 return;
73 } 74 }
74 usb_submit_urb(urb, GFP_ATOMIC); 75 usb_submit_urb(urb, GFP_ATOMIC);
@@ -101,8 +102,8 @@ int usb_urb_submitv2(struct usb_data_stream *stream,
101 dev_dbg(&stream->udev->dev, "%s: submit urb=%d\n", __func__, i); 102 dev_dbg(&stream->udev->dev, "%s: submit urb=%d\n", __func__, i);
102 ret = usb_submit_urb(stream->urb_list[i], GFP_ATOMIC); 103 ret = usb_submit_urb(stream->urb_list[i], GFP_ATOMIC);
103 if (ret) { 104 if (ret) {
104 dev_err(&stream->udev->dev, "%s: could not submit " \ 105 dev_err(&stream->udev->dev,
105 "urb no. %d - get them all back\n", 106 "%s: could not submit urb no. %d - get them all back\n",
106 KBUILD_MODNAME, i); 107 KBUILD_MODNAME, i);
107 usb_urb_killv2(stream); 108 usb_urb_killv2(stream);
108 return ret; 109 return ret;
@@ -229,8 +230,9 @@ static int usb_alloc_stream_buffers(struct usb_data_stream *stream, int num,
229 stream->buf_num = 0; 230 stream->buf_num = 0;
230 stream->buf_size = size; 231 stream->buf_size = size;
231 232
232 dev_dbg(&stream->udev->dev, "%s: all in all I will use %lu bytes for " \ 233 dev_dbg(&stream->udev->dev,
233 "streaming\n", __func__, num * size); 234 "%s: all in all I will use %lu bytes for streaming\n",
235 __func__, num * size);
234 236
235 for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) { 237 for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) {
236 stream->buf_list[stream->buf_num] = usb_alloc_coherent( 238 stream->buf_list[stream->buf_num] = usb_alloc_coherent(
@@ -274,8 +276,8 @@ int usb_urb_reconfig(struct usb_data_stream *stream,
274 } 276 }
275 277
276 if (stream->buf_num < props->count || stream->buf_size < buf_size) { 278 if (stream->buf_num < props->count || stream->buf_size < buf_size) {
277 dev_err(&stream->udev->dev, "%s: cannot reconfigure as " \ 279 dev_err(&stream->udev->dev,
278 "allocated buffers are too small\n", 280 "%s: cannot reconfigure as allocated buffers are too small\n",
279 KBUILD_MODNAME); 281 KBUILD_MODNAME);
280 return -EINVAL; 282 return -EINVAL;
281 } 283 }
@@ -321,8 +323,9 @@ int usb_urb_initv2(struct usb_data_stream *stream,
321 memcpy(&stream->props, props, sizeof(*props)); 323 memcpy(&stream->props, props, sizeof(*props));
322 324
323 if (!stream->complete) { 325 if (!stream->complete) {
324 dev_err(&stream->udev->dev, "%s: there is no data callback - " \ 326 dev_err(&stream->udev->dev,
325 "this doesn't make sense\n", KBUILD_MODNAME); 327 "%s: there is no data callback - this doesn't make sense\n",
328 KBUILD_MODNAME);
326 return -EINVAL; 329 return -EINVAL;
327 } 330 }
328 331
@@ -343,8 +346,9 @@ int usb_urb_initv2(struct usb_data_stream *stream,
343 346
344 return usb_urb_alloc_isoc_urbs(stream); 347 return usb_urb_alloc_isoc_urbs(stream);
345 default: 348 default:
346 dev_err(&stream->udev->dev, "%s: unknown urb-type for data " \ 349 dev_err(&stream->udev->dev,
347 "transfer\n", KBUILD_MODNAME); 350 "%s: unknown urb-type for data transfer\n",
351 KBUILD_MODNAME);
348 return -EINVAL; 352 return -EINVAL;
349 } 353 }
350} 354}
diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index 1efc028a76c9..c890fe46acd3 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -300,8 +300,7 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
300static void cinergyt2_fe_release(struct dvb_frontend *fe) 300static void cinergyt2_fe_release(struct dvb_frontend *fe)
301{ 301{
302 struct cinergyt2_fe_state *state = fe->demodulator_priv; 302 struct cinergyt2_fe_state *state = fe->demodulator_priv;
303 if (state != NULL) 303 kfree(state);
304 kfree(state);
305} 304}
306 305
307static struct dvb_frontend_ops cinergyt2_fe_ops; 306static struct dvb_frontend_ops cinergyt2_fe_ops;
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 11798426fa88..f08136052f9c 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -1431,13 +1431,22 @@ static int dib8090_get_adc_power(struct dvb_frontend *fe)
1431 return dib8000_get_adc_power(fe, 1); 1431 return dib8000_get_adc_power(fe, 1);
1432} 1432}
1433 1433
1434static void dib8090_agc_control(struct dvb_frontend *fe, u8 restart)
1435{
1436 deb_info("AGC control callback: %i\n", restart);
1437 dib0090_dcc_freq(fe, restart);
1438
1439 if (restart == 0) /* before AGC startup */
1440 dib0090_set_dc_servo(fe, 1);
1441}
1442
1434static struct dib8000_config dib809x_dib8000_config[2] = { 1443static struct dib8000_config dib809x_dib8000_config[2] = {
1435 { 1444 {
1436 .output_mpeg2_in_188_bytes = 1, 1445 .output_mpeg2_in_188_bytes = 1,
1437 1446
1438 .agc_config_count = 2, 1447 .agc_config_count = 2,
1439 .agc = dib8090_agc_config, 1448 .agc = dib8090_agc_config,
1440 .agc_control = dib0090_dcc_freq, 1449 .agc_control = dib8090_agc_control,
1441 .pll = &dib8090_pll_config_12mhz, 1450 .pll = &dib8090_pll_config_12mhz,
1442 .tuner_is_baseband = 1, 1451 .tuner_is_baseband = 1,
1443 1452
@@ -1456,7 +1465,7 @@ static struct dib8000_config dib809x_dib8000_config[2] = {
1456 1465
1457 .agc_config_count = 2, 1466 .agc_config_count = 2,
1458 .agc = dib8090_agc_config, 1467 .agc = dib8090_agc_config,
1459 .agc_control = dib0090_dcc_freq, 1468 .agc_control = dib8090_agc_control,
1460 .pll = &dib8090_pll_config_12mhz, 1469 .pll = &dib8090_pll_config_12mhz,
1461 .tuner_is_baseband = 1, 1470 .tuner_is_baseband = 1,
1462 1471
@@ -1504,28 +1513,89 @@ static struct dib0090_config dib809x_dib0090_config = {
1504 .fref_clock_ratio = 6, 1513 .fref_clock_ratio = 6,
1505}; 1514};
1506 1515
1516static u8 dib8090_compute_pll_parameters(struct dvb_frontend *fe)
1517{
1518 u8 optimal_pll_ratio = 20;
1519 u32 freq_adc, ratio, rest, max = 0;
1520 u8 pll_ratio;
1521
1522 for (pll_ratio = 17; pll_ratio <= 20; pll_ratio++) {
1523 freq_adc = 12 * pll_ratio * (1 << 8) / 16;
1524 ratio = ((fe->dtv_property_cache.frequency / 1000) * (1 << 8) / 1000) / freq_adc;
1525 rest = ((fe->dtv_property_cache.frequency / 1000) * (1 << 8) / 1000) - ratio * freq_adc;
1526
1527 if (rest > freq_adc / 2)
1528 rest = freq_adc - rest;
1529 deb_info("PLL ratio=%i rest=%i\n", pll_ratio, rest);
1530 if ((rest > max) && (rest > 717)) {
1531 optimal_pll_ratio = pll_ratio;
1532 max = rest;
1533 }
1534 }
1535 deb_info("optimal PLL ratio=%i\n", optimal_pll_ratio);
1536
1537 return optimal_pll_ratio;
1538}
1539
1507static int dib8096_set_param_override(struct dvb_frontend *fe) 1540static int dib8096_set_param_override(struct dvb_frontend *fe)
1508{ 1541{
1509 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1510 struct dvb_usb_adapter *adap = fe->dvb->priv; 1542 struct dvb_usb_adapter *adap = fe->dvb->priv;
1511 struct dib0700_adapter_state *state = adap->priv; 1543 struct dib0700_adapter_state *state = adap->priv;
1512 u8 band = BAND_OF_FREQUENCY(p->frequency/1000); 1544 u8 pll_ratio, band = BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000);
1513 u16 target; 1545 u16 target, ltgain, rf_gain_limit;
1546 u32 timf;
1514 int ret = 0; 1547 int ret = 0;
1515 enum frontend_tune_state tune_state = CT_SHUTDOWN; 1548 enum frontend_tune_state tune_state = CT_SHUTDOWN;
1516 u16 ltgain, rf_gain_limit; 1549
1550 switch (band) {
1551 default:
1552 deb_info("Warning : Rf frequency (%iHz) is not in the supported range, using VHF switch ", fe->dtv_property_cache.frequency);
1553 case BAND_VHF:
1554 dib8000_set_gpio(fe, 3, 0, 1);
1555 break;
1556 case BAND_UHF:
1557 dib8000_set_gpio(fe, 3, 0, 0);
1558 break;
1559 }
1517 1560
1518 ret = state->set_param_save(fe); 1561 ret = state->set_param_save(fe);
1519 if (ret < 0) 1562 if (ret < 0)
1520 return ret; 1563 return ret;
1521 1564
1522 target = (dib0090_get_wbd_target(fe) * 8 * 18 / 33 + 1) / 2; 1565 if (fe->dtv_property_cache.bandwidth_hz != 6000000) {
1523 dib8000_set_wbd_ref(fe, target); 1566 deb_info("only 6MHz bandwidth is supported\n");
1567 return -EINVAL;
1568 }
1569
1570 /** Update PLL if needed ratio **/
1571 dib8000_update_pll(fe, &dib8090_pll_config_12mhz, fe->dtv_property_cache.bandwidth_hz / 1000, 0);
1572
1573 /** Get optimize PLL ratio to remove spurious **/
1574 pll_ratio = dib8090_compute_pll_parameters(fe);
1575 if (pll_ratio == 17)
1576 timf = 21387946;
1577 else if (pll_ratio == 18)
1578 timf = 20199727;
1579 else if (pll_ratio == 19)
1580 timf = 19136583;
1581 else
1582 timf = 18179756;
1583
1584 /** Update ratio **/
1585 dib8000_update_pll(fe, &dib8090_pll_config_12mhz, fe->dtv_property_cache.bandwidth_hz / 1000, pll_ratio);
1524 1586
1587 dib8000_ctrl_timf(fe, DEMOD_TIMF_SET, timf);
1588
1589 if (band != BAND_CBAND) {
1590 /* dib0090_get_wbd_target is returning any possible temperature compensated wbd-target */
1591 target = (dib0090_get_wbd_target(fe) * 8 * 18 / 33 + 1) / 2;
1592 dib8000_set_wbd_ref(fe, target);
1593 }
1525 1594
1526 if (band == BAND_CBAND) { 1595 if (band == BAND_CBAND) {
1527 deb_info("tuning in CBAND - soft-AGC startup\n"); 1596 deb_info("tuning in CBAND - soft-AGC startup\n");
1528 dib0090_set_tune_state(fe, CT_AGC_START); 1597 dib0090_set_tune_state(fe, CT_AGC_START);
1598
1529 do { 1599 do {
1530 ret = dib0090_gain_control(fe); 1600 ret = dib0090_gain_control(fe);
1531 msleep(ret); 1601 msleep(ret);
@@ -1534,14 +1604,17 @@ static int dib8096_set_param_override(struct dvb_frontend *fe)
1534 dib8000_set_gpio(fe, 6, 0, 1); 1604 dib8000_set_gpio(fe, 6, 0, 1);
1535 else if (tune_state == CT_AGC_STEP_1) { 1605 else if (tune_state == CT_AGC_STEP_1) {
1536 dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain); 1606 dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain);
1537 if (rf_gain_limit == 0) 1607 if (rf_gain_limit < 2000) /* activate the external attenuator in case of very high input power */
1538 dib8000_set_gpio(fe, 6, 0, 0); 1608 dib8000_set_gpio(fe, 6, 0, 0);
1539 } 1609 }
1540 } while (tune_state < CT_AGC_STOP); 1610 } while (tune_state < CT_AGC_STOP);
1611
1612 deb_info("switching to PWM AGC\n");
1541 dib0090_pwm_gain_reset(fe); 1613 dib0090_pwm_gain_reset(fe);
1542 dib8000_pwm_agc_reset(fe); 1614 dib8000_pwm_agc_reset(fe);
1543 dib8000_set_tune_state(fe, CT_DEMOD_START); 1615 dib8000_set_tune_state(fe, CT_DEMOD_START);
1544 } else { 1616 } else {
1617 /* for everything else than CBAND we are using standard AGC */
1545 deb_info("not tuning in CBAND - standard AGC startup\n"); 1618 deb_info("not tuning in CBAND - standard AGC startup\n");
1546 dib0090_pwm_gain_reset(fe); 1619 dib0090_pwm_gain_reset(fe);
1547 } 1620 }
@@ -1814,21 +1887,92 @@ struct dibx090p_adc {
1814 u32 pll_prediv; /* New loopdiv */ 1887 u32 pll_prediv; /* New loopdiv */
1815}; 1888};
1816 1889
1817struct dibx090p_adc dib8090p_adc_tab[] = { 1890struct dibx090p_best_adc {
1818 { 50000, 17043521, 16, 3}, /* 64 MHz */ 1891 u32 timf;
1819 {878000, 20199729, 9, 1}, /* 60 MHz */ 1892 u32 pll_loopdiv;
1820 {0xffffffff, 0, 0, 0}, /* 60 MHz */ 1893 u32 pll_prediv;
1821}; 1894};
1822 1895
1896static int dib8096p_get_best_sampling(struct dvb_frontend *fe, struct dibx090p_best_adc *adc)
1897{
1898 u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
1899 u16 xtal = 12000;
1900 u16 fcp_min = 1900; /* PLL, Minimum Frequency of phase comparator (KHz) */
1901 u16 fcp_max = 20000; /* PLL, Maximum Frequency of phase comparator (KHz) */
1902 u32 fmem_max = 140000; /* 140MHz max SDRAM freq */
1903 u32 fdem_min = 66000;
1904 u32 fcp = 0, fs = 0, fdem = 0, fmem = 0;
1905 u32 harmonic_id = 0;
1906
1907 adc->timf = 0;
1908 adc->pll_loopdiv = loopdiv;
1909 adc->pll_prediv = prediv;
1910
1911 deb_info("bandwidth = %d", fe->dtv_property_cache.bandwidth_hz);
1912
1913 /* Find Min and Max prediv */
1914 while ((xtal / max_prediv) >= fcp_min)
1915 max_prediv++;
1916
1917 max_prediv--;
1918 min_prediv = max_prediv;
1919 while ((xtal / min_prediv) <= fcp_max) {
1920 min_prediv--;
1921 if (min_prediv == 1)
1922 break;
1923 }
1924 deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);
1925
1926 min_prediv = 1;
1927
1928 for (prediv = min_prediv; prediv < max_prediv; prediv++) {
1929 fcp = xtal / prediv;
1930 if (fcp > fcp_min && fcp < fcp_max) {
1931 for (loopdiv = 1; loopdiv < 64; loopdiv++) {
1932 fmem = ((xtal/prediv) * loopdiv);
1933 fdem = fmem / 2;
1934 fs = fdem / 4;
1935
1936 /* test min/max system restrictions */
1937 if ((fdem >= fdem_min) && (fmem <= fmem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz / 1000)) {
1938 spur = 0;
1939 /* test fs harmonics positions */
1940 for (harmonic_id = (fe->dtv_property_cache.frequency / (1000 * fs)); harmonic_id <= ((fe->dtv_property_cache.frequency / (1000 * fs)) + 1); harmonic_id++) {
1941 if (((fs * harmonic_id) >= (fe->dtv_property_cache.frequency / 1000 - (fe->dtv_property_cache.bandwidth_hz / 2000))) && ((fs * harmonic_id) <= (fe->dtv_property_cache.frequency / 1000 + (fe->dtv_property_cache.bandwidth_hz / 2000)))) {
1942 spur = 1;
1943 break;
1944 }
1945 }
1946
1947 if (!spur) {
1948 adc->pll_loopdiv = loopdiv;
1949 adc->pll_prediv = prediv;
1950 adc->timf = (4260880253U / fdem) * (1 << 8);
1951 adc->timf += ((4260880253U % fdem) << 8) / fdem;
1952
1953 deb_info("RF %6d; BW %6d; Xtal %6d; Fmem %6d; Fdem %6d; Fs %6d; Prediv %2d; Loopdiv %2d; Timf %8d;", fe->dtv_property_cache.frequency, fe->dtv_property_cache.bandwidth_hz, xtal, fmem, fdem, fs, prediv, loopdiv, adc->timf);
1954 break;
1955 }
1956 }
1957 }
1958 }
1959 if (!spur)
1960 break;
1961 }
1962
1963 if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
1964 return -EINVAL;
1965 return 0;
1966}
1967
1823static int dib8096p_agc_startup(struct dvb_frontend *fe) 1968static int dib8096p_agc_startup(struct dvb_frontend *fe)
1824{ 1969{
1825 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1826 struct dvb_usb_adapter *adap = fe->dvb->priv; 1970 struct dvb_usb_adapter *adap = fe->dvb->priv;
1827 struct dib0700_adapter_state *state = adap->priv; 1971 struct dib0700_adapter_state *state = adap->priv;
1828 struct dibx000_bandwidth_config pll; 1972 struct dibx000_bandwidth_config pll;
1973 struct dibx090p_best_adc adc;
1829 u16 target; 1974 u16 target;
1830 int better_sampling_freq = 0, ret; 1975 int ret;
1831 struct dibx090p_adc *adc_table = &dib8090p_adc_tab[0];
1832 1976
1833 ret = state->set_param_save(fe); 1977 ret = state->set_param_save(fe);
1834 if (ret < 0) 1978 if (ret < 0)
@@ -1841,23 +1985,27 @@ static int dib8096p_agc_startup(struct dvb_frontend *fe)
1841 target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2; 1985 target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2;
1842 dib8000_set_wbd_ref(fe, target); 1986 dib8000_set_wbd_ref(fe, target);
1843 1987
1988 if (dib8096p_get_best_sampling(fe, &adc) == 0) {
1989 pll.pll_ratio = adc.pll_loopdiv;
1990 pll.pll_prediv = adc.pll_prediv;
1844 1991
1845 while (p->frequency / 1000 > adc_table->freq) { 1992 dib0700_set_i2c_speed(adap->dev, 200);
1846 better_sampling_freq = 1; 1993 dib8000_update_pll(fe, &pll, fe->dtv_property_cache.bandwidth_hz / 1000, 0);
1847 adc_table++; 1994 dib8000_ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
1848 } 1995 dib0700_set_i2c_speed(adap->dev, 1000);
1849
1850 if ((adc_table->freq != 0xffffffff) && better_sampling_freq) {
1851 pll.pll_ratio = adc_table->pll_loopdiv;
1852 pll.pll_prediv = adc_table->pll_prediv;
1853 dib8000_update_pll(fe, &pll);
1854 dib8000_ctrl_timf(fe, DEMOD_TIMF_SET, adc_table->timf);
1855 } 1996 }
1856 return 0; 1997 return 0;
1857} 1998}
1858 1999
1859static int tfe8096p_frontend_attach(struct dvb_usb_adapter *adap) 2000static int tfe8096p_frontend_attach(struct dvb_usb_adapter *adap)
1860{ 2001{
2002 struct dib0700_state *st = adap->dev->priv;
2003 u32 fw_version;
2004
2005 dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
2006 if (fw_version >= 0x10200)
2007 st->fw_use_new_i2c_api = 1;
2008
1861 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 2009 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1862 msleep(20); 2010 msleep(20);
1863 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1); 2011 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
@@ -2242,13 +2390,7 @@ static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)
2242} 2390}
2243 2391
2244/* NIM7090 */ 2392/* NIM7090 */
2245struct dib7090p_best_adc { 2393static int dib7090p_get_best_sampling(struct dvb_frontend *fe , struct dibx090p_best_adc *adc)
2246 u32 timf;
2247 u32 pll_loopdiv;
2248 u32 pll_prediv;
2249};
2250
2251static int dib7090p_get_best_sampling(struct dvb_frontend *fe , struct dib7090p_best_adc *adc)
2252{ 2394{
2253 u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1; 2395 u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
2254 2396
@@ -2327,7 +2469,7 @@ static int dib7090_agc_startup(struct dvb_frontend *fe)
2327 struct dib0700_adapter_state *state = adap->priv; 2469 struct dib0700_adapter_state *state = adap->priv;
2328 struct dibx000_bandwidth_config pll; 2470 struct dibx000_bandwidth_config pll;
2329 u16 target; 2471 u16 target;
2330 struct dib7090p_best_adc adc; 2472 struct dibx090p_best_adc adc;
2331 int ret; 2473 int ret;
2332 2474
2333 ret = state->set_param_save(fe); 2475 ret = state->set_param_save(fe);
@@ -2357,36 +2499,16 @@ static int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
2357 return 0; 2499 return 0;
2358} 2500}
2359 2501
2360static int dib7090e_update_lna(struct dvb_frontend *fe, u16 agc_global) 2502static int tfe7790p_update_lna(struct dvb_frontend *fe, u16 agc_global)
2361{ 2503{
2362 u16 agc1 = 0, agc2, wbd = 0, wbd_target, wbd_offset, threshold_agc1; 2504 deb_info("update LNA: agc global=%i", agc_global);
2363 s16 wbd_delta;
2364 2505
2365 if ((fe->dtv_property_cache.frequency) < 400000000) 2506 if (agc_global < 25000) {
2366 threshold_agc1 = 25000; 2507 dib7000p_set_gpio(fe, 8, 0, 0);
2367 else 2508 dib7000p_set_agc1_min(fe, 0);
2368 threshold_agc1 = 30000;
2369
2370 wbd_target = (dib0090_get_wbd_target(fe)*8+1)/2;
2371 wbd_offset = dib0090_get_wbd_offset(fe);
2372 dib7000p_get_agc_values(fe, NULL, &agc1, &agc2, &wbd);
2373 wbd_delta = (s16)wbd - (((s16)wbd_offset+10)*4) ;
2374
2375 deb_info("update lna, agc_global=%d agc1=%d agc2=%d",
2376 agc_global, agc1, agc2);
2377 deb_info("update lna, wbd=%d wbd target=%d wbd offset=%d wbd delta=%d",
2378 wbd, wbd_target, wbd_offset, wbd_delta);
2379
2380 if ((agc1 < threshold_agc1) && (wbd_delta > 0)) {
2381 dib0090_set_switch(fe, 1, 1, 1);
2382 dib0090_set_vga(fe, 0);
2383 dib0090_update_rframp_7090(fe, 0);
2384 dib0090_update_tuning_table_7090(fe, 0);
2385 } else { 2509 } else {
2386 dib0090_set_vga(fe, 1); 2510 dib7000p_set_gpio(fe, 8, 0, 1);
2387 dib0090_update_rframp_7090(fe, 1); 2511 dib7000p_set_agc1_min(fe, 32768);
2388 dib0090_update_tuning_table_7090(fe, 1);
2389 dib0090_set_switch(fe, 0, 0, 0);
2390 } 2512 }
2391 2513
2392 return 0; 2514 return 0;
@@ -2400,15 +2522,6 @@ static struct dib0090_wbd_slope dib7090_wbd_table[] = {
2400 { 0xFFFF, 0, 0, 0, 0, 0}, 2522 { 0xFFFF, 0, 0, 0, 0, 0},
2401}; 2523};
2402 2524
2403static struct dib0090_wbd_slope dib7090e_wbd_table[] = {
2404 { 380, 81, 850, 64, 540, 4},
2405 { 700, 51, 866, 21, 320, 4},
2406 { 860, 48, 666, 18, 330, 6},
2407 {1700, 0, 250, 0, 100, 6},
2408 {2600, 0, 250, 0, 100, 6},
2409 { 0xFFFF, 0, 0, 0, 0, 0},
2410};
2411
2412static struct dibx000_agc_config dib7090_agc_config[2] = { 2525static struct dibx000_agc_config dib7090_agc_config[2] = {
2413 { 2526 {
2414 .band_caps = BAND_UHF, 2527 .band_caps = BAND_UHF,
@@ -2428,7 +2541,7 @@ static struct dibx000_agc_config dib7090_agc_config[2] = {
2428 .wbd_alpha = 5, 2541 .wbd_alpha = 5,
2429 2542
2430 .agc1_max = 65535, 2543 .agc1_max = 65535,
2431 .agc1_min = 0, 2544 .agc1_min = 32768,
2432 2545
2433 .agc2_max = 65535, 2546 .agc2_max = 65535,
2434 .agc2_min = 0, 2547 .agc2_min = 0,
@@ -2505,7 +2618,7 @@ static struct dib7000p_config nim7090_dib7000p_config = {
2505 .output_mpeg2_in_188_bytes = 1, 2618 .output_mpeg2_in_188_bytes = 1,
2506 .hostbus_diversity = 1, 2619 .hostbus_diversity = 1,
2507 .tuner_is_baseband = 1, 2620 .tuner_is_baseband = 1,
2508 .update_lna = NULL, 2621 .update_lna = tfe7790p_update_lna, /* GPIO used is the same as TFE7790 */
2509 2622
2510 .agc_config_count = 2, 2623 .agc_config_count = 2,
2511 .agc = dib7090_agc_config, 2624 .agc = dib7090_agc_config,
@@ -2529,12 +2642,26 @@ static struct dib7000p_config nim7090_dib7000p_config = {
2529 .enMpegOutput = 1, 2642 .enMpegOutput = 1,
2530}; 2643};
2531 2644
2645static int tfe7090p_pvr_update_lna(struct dvb_frontend *fe, u16 agc_global)
2646{
2647 deb_info("TFE7090P-PVR update LNA: agc global=%i", agc_global);
2648 if (agc_global < 25000) {
2649 dib7000p_set_gpio(fe, 5, 0, 0);
2650 dib7000p_set_agc1_min(fe, 0);
2651 } else {
2652 dib7000p_set_gpio(fe, 5, 0, 1);
2653 dib7000p_set_agc1_min(fe, 32768);
2654 }
2655
2656 return 0;
2657}
2658
2532static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = { 2659static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2533 { 2660 {
2534 .output_mpeg2_in_188_bytes = 1, 2661 .output_mpeg2_in_188_bytes = 1,
2535 .hostbus_diversity = 1, 2662 .hostbus_diversity = 1,
2536 .tuner_is_baseband = 1, 2663 .tuner_is_baseband = 1,
2537 .update_lna = NULL, 2664 .update_lna = tfe7090p_pvr_update_lna,
2538 2665
2539 .agc_config_count = 2, 2666 .agc_config_count = 2,
2540 .agc = dib7090_agc_config, 2667 .agc = dib7090_agc_config,
@@ -2561,7 +2688,7 @@ static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2561 .output_mpeg2_in_188_bytes = 1, 2688 .output_mpeg2_in_188_bytes = 1,
2562 .hostbus_diversity = 1, 2689 .hostbus_diversity = 1,
2563 .tuner_is_baseband = 1, 2690 .tuner_is_baseband = 1,
2564 .update_lna = NULL, 2691 .update_lna = tfe7090p_pvr_update_lna,
2565 2692
2566 .agc_config_count = 2, 2693 .agc_config_count = 2,
2567 .agc = dib7090_agc_config, 2694 .agc = dib7090_agc_config,
@@ -2587,34 +2714,6 @@ static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2587 } 2714 }
2588}; 2715};
2589 2716
2590static struct dib7000p_config tfe7090e_dib7000p_config = {
2591 .output_mpeg2_in_188_bytes = 1,
2592 .hostbus_diversity = 1,
2593 .tuner_is_baseband = 1,
2594 .update_lna = dib7090e_update_lna,
2595
2596 .agc_config_count = 2,
2597 .agc = dib7090_agc_config,
2598
2599 .bw = &dib7090_clock_config_12_mhz,
2600
2601 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2602 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
2603 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
2604
2605 .pwm_freq_div = 0,
2606
2607 .agc_control = dib7090_agc_restart,
2608
2609 .spur_protect = 0,
2610 .disable_sample_and_hold = 0,
2611 .enable_current_mirror = 0,
2612 .diversity_delay = 0,
2613
2614 .output_mode = OUTMODE_MPEG2_FIFO,
2615 .enMpegOutput = 1,
2616};
2617
2618static const struct dib0090_config nim7090_dib0090_config = { 2717static const struct dib0090_config nim7090_dib0090_config = {
2619 .io.clock_khz = 12000, 2718 .io.clock_khz = 12000,
2620 .io.pll_bypass = 0, 2719 .io.pll_bypass = 0,
@@ -2649,47 +2748,11 @@ static const struct dib0090_config nim7090_dib0090_config = {
2649 .in_soc = 1, 2748 .in_soc = 1,
2650}; 2749};
2651 2750
2652static const struct dib0090_config tfe7090e_dib0090_config = { 2751static struct dib7000p_config tfe7790p_dib7000p_config = {
2653 .io.clock_khz = 12000,
2654 .io.pll_bypass = 0,
2655 .io.pll_range = 0,
2656 .io.pll_prediv = 3,
2657 .io.pll_loopdiv = 6,
2658 .io.adc_clock_ratio = 0,
2659 .io.pll_int_loop_filt = 0,
2660 .reset = dib7090_tuner_sleep,
2661 .sleep = dib7090_tuner_sleep,
2662
2663 .freq_offset_khz_uhf = 0,
2664 .freq_offset_khz_vhf = 0,
2665
2666 .get_adc_power = dib7090_get_adc_power,
2667
2668 .clkouttobamse = 1,
2669 .analog_output = 0,
2670
2671 .wbd_vhf_offset = 0,
2672 .wbd_cband_offset = 0,
2673 .use_pwm_agc = 1,
2674 .clkoutdrive = 0,
2675
2676 .fref_clock_ratio = 0,
2677
2678 .wbd = dib7090e_wbd_table,
2679
2680 .ls_cfg_pad_drv = 0,
2681 .data_tx_drv = 0,
2682 .low_if = NULL,
2683 .in_soc = 1,
2684 .force_cband_input = 1,
2685 .is_dib7090e = 1,
2686};
2687
2688static struct dib7000p_config tfe7790e_dib7000p_config = {
2689 .output_mpeg2_in_188_bytes = 1, 2752 .output_mpeg2_in_188_bytes = 1,
2690 .hostbus_diversity = 1, 2753 .hostbus_diversity = 1,
2691 .tuner_is_baseband = 1, 2754 .tuner_is_baseband = 1,
2692 .update_lna = dib7090e_update_lna, 2755 .update_lna = tfe7790p_update_lna,
2693 2756
2694 .agc_config_count = 2, 2757 .agc_config_count = 2,
2695 .agc = dib7090_agc_config, 2758 .agc = dib7090_agc_config,
@@ -2713,7 +2776,7 @@ static struct dib7000p_config tfe7790e_dib7000p_config = {
2713 .enMpegOutput = 1, 2776 .enMpegOutput = 1,
2714}; 2777};
2715 2778
2716static const struct dib0090_config tfe7790e_dib0090_config = { 2779static const struct dib0090_config tfe7790p_dib0090_config = {
2717 .io.clock_khz = 12000, 2780 .io.clock_khz = 12000,
2718 .io.pll_bypass = 0, 2781 .io.pll_bypass = 0,
2719 .io.pll_range = 0, 2782 .io.pll_range = 0,
@@ -2739,14 +2802,14 @@ static const struct dib0090_config tfe7790e_dib0090_config = {
2739 2802
2740 .fref_clock_ratio = 0, 2803 .fref_clock_ratio = 0,
2741 2804
2742 .wbd = dib7090e_wbd_table, 2805 .wbd = dib7090_wbd_table,
2743 2806
2744 .ls_cfg_pad_drv = 0, 2807 .ls_cfg_pad_drv = 0,
2745 .data_tx_drv = 0, 2808 .data_tx_drv = 0,
2746 .low_if = NULL, 2809 .low_if = NULL,
2747 .in_soc = 1, 2810 .in_soc = 1,
2748 .force_cband_input = 1, 2811 .force_cband_input = 0,
2749 .is_dib7090e = 1, 2812 .is_dib7090e = 0,
2750 .force_crystal_mode = 1, 2813 .force_crystal_mode = 1,
2751}; 2814};
2752 2815
@@ -2942,37 +3005,11 @@ static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
2942 return 0; 3005 return 0;
2943} 3006}
2944 3007
2945static int tfe7090e_frontend_attach(struct dvb_usb_adapter *adap) 3008static int tfe7790p_frontend_attach(struct dvb_usb_adapter *adap)
2946{
2947 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2948 msleep(20);
2949 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2950 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2951 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2952 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2953
2954 msleep(20);
2955 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2956 msleep(20);
2957 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2958
2959 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap,
2960 1, 0x10, &tfe7090e_dib7000p_config) != 0) {
2961 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n",
2962 __func__);
2963 return -ENODEV;
2964 }
2965 adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,
2966 0x80, &tfe7090e_dib7000p_config);
2967
2968 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2969}
2970
2971static int tfe7790e_frontend_attach(struct dvb_usb_adapter *adap)
2972{ 3009{
2973 struct dib0700_state *st = adap->dev->priv; 3010 struct dib0700_state *st = adap->dev->priv;
2974 3011
2975 /* The TFE7790E requires the dib0700 to not be in master mode */ 3012 /* The TFE7790P requires the dib0700 to not be in master mode */
2976 st->disable_streaming_master_mode = 1; 3013 st->disable_streaming_master_mode = 1;
2977 3014
2978 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 3015 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
@@ -2988,42 +3025,25 @@ static int tfe7790e_frontend_attach(struct dvb_usb_adapter *adap)
2988 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 3025 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2989 3026
2990 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 3027 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap,
2991 1, 0x10, &tfe7790e_dib7000p_config) != 0) { 3028 1, 0x10, &tfe7790p_dib7000p_config) != 0) {
2992 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 3029 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n",
2993 __func__); 3030 __func__);
2994 return -ENODEV; 3031 return -ENODEV;
2995 } 3032 }
2996 adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 3033 adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,
2997 0x80, &tfe7790e_dib7000p_config); 3034 0x80, &tfe7790p_dib7000p_config);
2998 3035
2999 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 3036 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3000} 3037}
3001 3038
3002static int tfe7790e_tuner_attach(struct dvb_usb_adapter *adap) 3039static int tfe7790p_tuner_attach(struct dvb_usb_adapter *adap)
3003{
3004 struct dib0700_adapter_state *st = adap->priv;
3005 struct i2c_adapter *tun_i2c =
3006 dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
3007
3008 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
3009 &tfe7790e_dib0090_config) == NULL)
3010 return -ENODEV;
3011
3012 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3013
3014 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3015 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3016 return 0;
3017}
3018
3019static int tfe7090e_tuner_attach(struct dvb_usb_adapter *adap)
3020{ 3040{
3021 struct dib0700_adapter_state *st = adap->priv; 3041 struct dib0700_adapter_state *st = adap->priv;
3022 struct i2c_adapter *tun_i2c = 3042 struct i2c_adapter *tun_i2c =
3023 dib7090_get_i2c_tuner(adap->fe_adap[0].fe); 3043 dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
3024 3044
3025 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, 3045 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
3026 &tfe7090e_dib0090_config) == NULL) 3046 &tfe7790p_dib0090_config) == NULL)
3027 return -ENODEV; 3047 return -ENODEV;
3028 3048
3029 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 3049 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
@@ -3566,10 +3586,9 @@ struct usb_device_id dib0700_usb_id_table[] = {
3566/* 75 */{ USB_DEVICE(USB_VID_MEDION, USB_PID_CREATIX_CTX1921) }, 3586/* 75 */{ USB_DEVICE(USB_VID_MEDION, USB_PID_CREATIX_CTX1921) },
3567 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV340E) }, 3587 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV340E) },
3568 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV340E_SE) }, 3588 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV340E_SE) },
3569 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_TFE7090E) }, 3589 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_TFE7790P) },
3570 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_TFE7790E) }, 3590 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_TFE8096P) },
3571/* 80 */{ USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_TFE8096P) }, 3591/* 80 */{ USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_DTT_2) },
3572 { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_DTT_2) },
3573 { 0 } /* Terminating entry */ 3592 { 0 } /* Terminating entry */
3574}; 3593};
3575MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 3594MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -3880,7 +3899,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3880 { NULL }, 3899 { NULL },
3881 }, 3900 },
3882 { "Elgato EyeTV DTT rev. 2", 3901 { "Elgato EyeTV DTT rev. 2",
3883 { &dib0700_usb_id_table[81], NULL }, 3902 { &dib0700_usb_id_table[80], NULL },
3884 { NULL }, 3903 { NULL },
3885 }, 3904 },
3886 }, 3905 },
@@ -4697,48 +4716,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4697 .pid_filter_count = 32, 4716 .pid_filter_count = 32,
4698 .pid_filter = stk70x0p_pid_filter, 4717 .pid_filter = stk70x0p_pid_filter,
4699 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl, 4718 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4700 .frontend_attach = tfe7090e_frontend_attach, 4719 .frontend_attach = tfe7790p_frontend_attach,
4701 .tuner_attach = tfe7090e_tuner_attach, 4720 .tuner_attach = tfe7790p_tuner_attach,
4702
4703 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4704 } },
4705
4706 .size_of_priv =
4707 sizeof(struct dib0700_adapter_state),
4708 },
4709 },
4710
4711 .num_device_descs = 1,
4712 .devices = {
4713 { "DiBcom TFE7090E reference design",
4714 { &dib0700_usb_id_table[78], NULL },
4715 { NULL },
4716 },
4717 },
4718
4719 .rc.core = {
4720 .rc_interval = DEFAULT_RC_INTERVAL,
4721 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
4722 .module_name = "dib0700",
4723 .rc_query = dib0700_rc_query_old_firmware,
4724 .allowed_protos = RC_BIT_RC5 |
4725 RC_BIT_RC6_MCE |
4726 RC_BIT_NEC,
4727 .change_protocol = dib0700_change_protocol,
4728 },
4729 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4730 .num_adapters = 1,
4731 .adapter = {
4732 {
4733 .num_frontends = 1,
4734 .fe = {{
4735 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4736 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4737 .pid_filter_count = 32,
4738 .pid_filter = stk70x0p_pid_filter,
4739 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4740 .frontend_attach = tfe7790e_frontend_attach,
4741 .tuner_attach = tfe7790e_tuner_attach,
4742 4721
4743 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4722 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4744 } }, 4723 } },
@@ -4750,8 +4729,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4750 4729
4751 .num_device_descs = 1, 4730 .num_device_descs = 1,
4752 .devices = { 4731 .devices = {
4753 { "DiBcom TFE7790E reference design", 4732 { "DiBcom TFE7790P reference design",
4754 { &dib0700_usb_id_table[79], NULL }, 4733 { &dib0700_usb_id_table[78], NULL },
4755 { NULL }, 4734 { NULL },
4756 }, 4735 },
4757 }, 4736 },
@@ -4792,7 +4771,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4792 .num_device_descs = 1, 4771 .num_device_descs = 1,
4793 .devices = { 4772 .devices = {
4794 { "DiBcom TFE8096P reference design", 4773 { "DiBcom TFE8096P reference design",
4795 { &dib0700_usb_id_table[80], NULL }, 4774 { &dib0700_usb_id_table[79], NULL },
4796 { NULL }, 4775 { NULL },
4797 }, 4776 },
4798 }, 4777 },
diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c b/drivers/media/usb/dvb-usb/dibusb-common.c
index af0d4321845b..c2dded92f1d3 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -8,6 +8,8 @@
8 * 8 *
9 * see Documentation/dvb/README.dvb-usb for more information 9 * see Documentation/dvb/README.dvb-usb for more information
10 */ 10 */
11
12#include <linux/kconfig.h>
11#include "dibusb.h" 13#include "dibusb.h"
12 14
13static int debug; 15static int debug;
@@ -232,8 +234,7 @@ static struct dibx000_agc_config dib3000p_panasonic_agc_config = {
232 .agc2_slope2 = 0x1e, 234 .agc2_slope2 = 0x1e,
233}; 235};
234 236
235#if defined(CONFIG_DVB_DIB3000MC) || \ 237#if IS_ENABLED(CONFIG_DVB_DIB3000MC)
236 (defined(CONFIG_DVB_DIB3000MC_MODULE) && defined(MODULE))
237 238
238static struct dib3000mc_config mod3000p_dib3000p_config = { 239static struct dib3000mc_config mod3000p_dib3000p_config = {
239 &dib3000p_panasonic_agc_config, 240 &dib3000p_panasonic_agc_config,
diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index 9578a6761f1b..6e237b6dd0a8 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -29,7 +29,6 @@
29#include "stb6100.h" 29#include "stb6100.h"
30#include "stb6100_proc.h" 30#include "stb6100_proc.h"
31#include "m88rs2000.h" 31#include "m88rs2000.h"
32#include "ts2020.h"
33 32
34#ifndef USB_PID_DW2102 33#ifndef USB_PID_DW2102
35#define USB_PID_DW2102 0x2102 34#define USB_PID_DW2102 0x2102
@@ -79,6 +78,10 @@
79#define USB_PID_TEVII_S632 0xd632 78#define USB_PID_TEVII_S632 0xd632
80#endif 79#endif
81 80
81#ifndef USB_PID_GOTVIEW_SAT_HD
82#define USB_PID_GOTVIEW_SAT_HD 0x5456
83#endif
84
82#define DW210X_READ_MSG 0 85#define DW210X_READ_MSG 0
83#define DW210X_WRITE_MSG 1 86#define DW210X_WRITE_MSG 1
84 87
@@ -1548,6 +1551,8 @@ enum dw2102_table_entry {
1548 X3M_SPC1400HD, 1551 X3M_SPC1400HD,
1549 TEVII_S421, 1552 TEVII_S421,
1550 TEVII_S632, 1553 TEVII_S632,
1554 TERRATEC_CINERGY_S2_R2,
1555 GOTVIEW_SAT_HD,
1551}; 1556};
1552 1557
1553static struct usb_device_id dw2102_table[] = { 1558static struct usb_device_id dw2102_table[] = {
@@ -1568,6 +1573,8 @@ static struct usb_device_id dw2102_table[] = {
1568 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)}, 1573 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1569 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)}, 1574 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1570 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)}, 1575 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1576 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00b0)},
1577 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1571 { } 1578 { }
1572}; 1579};
1573 1580
@@ -1968,7 +1975,7 @@ static struct dvb_usb_device_properties su3000_properties = {
1968 }}, 1975 }},
1969 } 1976 }
1970 }, 1977 },
1971 .num_device_descs = 3, 1978 .num_device_descs = 5,
1972 .devices = { 1979 .devices = {
1973 { "SU3000HD DVB-S USB2.0", 1980 { "SU3000HD DVB-S USB2.0",
1974 { &dw2102_table[GENIATECH_SU3000], NULL }, 1981 { &dw2102_table[GENIATECH_SU3000], NULL },
@@ -1982,6 +1989,14 @@ static struct dvb_usb_device_properties su3000_properties = {
1982 { &dw2102_table[X3M_SPC1400HD], NULL }, 1989 { &dw2102_table[X3M_SPC1400HD], NULL },
1983 { NULL }, 1990 { NULL },
1984 }, 1991 },
1992 { "Terratec Cinergy S2 USB HD Rev.2",
1993 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
1994 { NULL },
1995 },
1996 { "GOTVIEW Satellite HD",
1997 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
1998 { NULL },
1999 },
1985 } 2000 }
1986}; 2001};
1987 2002
diff --git a/drivers/media/usb/dvb-usb/m920x.c b/drivers/media/usb/dvb-usb/m920x.c
index 92afeb20650f..c2b635d6a17a 100644
--- a/drivers/media/usb/dvb-usb/m920x.c
+++ b/drivers/media/usb/dvb-usb/m920x.c
@@ -68,20 +68,20 @@ static inline int m920x_write_seq(struct usb_device *udev, u8 request,
68 struct m920x_inits *seq) 68 struct m920x_inits *seq)
69{ 69{
70 int ret; 70 int ret;
71 while (seq->address) { 71 do {
72 ret = m920x_write(udev, request, seq->data, seq->address); 72 ret = m920x_write(udev, request, seq->data, seq->address);
73 if (ret != 0) 73 if (ret != 0)
74 return ret; 74 return ret;
75 75
76 seq++; 76 seq++;
77 } 77 } while (seq->address);
78 78
79 return ret; 79 return 0;
80} 80}
81 81
82static 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)
83{ 83{
84 int ret = 0, i, epi, flags = 0; 84 int ret, i, epi, flags = 0;
85 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 }; 85 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
86 86
87 /* Remote controller init. */ 87 /* Remote controller init. */
@@ -124,7 +124,7 @@ static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
124 } 124 }
125 } 125 }
126 126
127 return ret; 127 return 0;
128} 128}
129 129
130static int m920x_init_ep(struct usb_interface *intf) 130static int m920x_init_ep(struct usb_interface *intf)
diff --git a/drivers/media/usb/em28xx/Kconfig b/drivers/media/usb/em28xx/Kconfig
index c754a80a8d8b..ca5ee6aceb62 100644
--- a/drivers/media/usb/em28xx/Kconfig
+++ b/drivers/media/usb/em28xx/Kconfig
@@ -46,6 +46,7 @@ config VIDEO_EM28XX_DVB
46 select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT 46 select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT
47 select DVB_MT352 if MEDIA_SUBDRV_AUTOSELECT 47 select DVB_MT352 if MEDIA_SUBDRV_AUTOSELECT
48 select DVB_S5H1409 if MEDIA_SUBDRV_AUTOSELECT 48 select DVB_S5H1409 if MEDIA_SUBDRV_AUTOSELECT
49 select DVB_MB86A20S if MEDIA_SUBDRV_AUTOSELECT
49 select MEDIA_TUNER_QT1010 if MEDIA_SUBDRV_AUTOSELECT 50 select MEDIA_TUNER_QT1010 if MEDIA_SUBDRV_AUTOSELECT
50 select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT 51 select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT
51 ---help--- 52 ---help---
diff --git a/drivers/media/usb/em28xx/Makefile b/drivers/media/usb/em28xx/Makefile
index 634fb920dd39..ad6d48557940 100644
--- a/drivers/media/usb/em28xx/Makefile
+++ b/drivers/media/usb/em28xx/Makefile
@@ -1,5 +1,5 @@
1em28xx-y += em28xx-video.o em28xx-i2c.o em28xx-cards.o 1em28xx-y += em28xx-video.o em28xx-i2c.o em28xx-cards.o
2em28xx-y += em28xx-core.o em28xx-vbi.o 2em28xx-y += em28xx-core.o em28xx-vbi.o em28xx-camera.o
3 3
4em28xx-alsa-objs := em28xx-audio.o 4em28xx-alsa-objs := em28xx-audio.o
5em28xx-rc-objs := em28xx-input.o 5em28xx-rc-objs := em28xx-input.o
diff --git a/drivers/media/usb/em28xx/em28xx-camera.c b/drivers/media/usb/em28xx/em28xx-camera.c
new file mode 100644
index 000000000000..73cc50afa5e1
--- /dev/null
+++ b/drivers/media/usb/em28xx/em28xx-camera.c
@@ -0,0 +1,434 @@
1/*
2 em28xx-camera.c - driver for Empia EM25xx/27xx/28xx USB video capture devices
3
4 Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@infradead.org>
5 Copyright (C) 2013 Frank Schäfer <fschaefer.oss@googlemail.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 <linux/i2c.h>
23#include <media/soc_camera.h>
24#include <media/mt9v011.h>
25#include <media/v4l2-common.h>
26
27#include "em28xx.h"
28
29
30/* Possible i2c addresses of Micron sensors */
31static unsigned short micron_sensor_addrs[] = {
32 0xb8 >> 1, /* MT9V111, MT9V403 */
33 0xba >> 1, /* MT9M001/011/111/112, MT9V011/012/112, MT9D011 */
34 0x90 >> 1, /* MT9V012/112, MT9D011 (alternative address) */
35 I2C_CLIENT_END
36};
37
38/* Possible i2c addresses of Omnivision sensors */
39static unsigned short omnivision_sensor_addrs[] = {
40 0x42 >> 1, /* OV7725, OV7670/60/48 */
41 0x60 >> 1, /* OV2640, OV9650/53/55 */
42 I2C_CLIENT_END
43};
44
45
46static struct soc_camera_link camlink = {
47 .bus_id = 0,
48 .flags = 0,
49 .module_name = "em28xx",
50};
51
52
53/* FIXME: Should be replaced by a proper mt9m111 driver */
54static int em28xx_initialize_mt9m111(struct em28xx *dev)
55{
56 int i;
57 unsigned char regs[][3] = {
58 { 0x0d, 0x00, 0x01, }, /* reset and use defaults */
59 { 0x0d, 0x00, 0x00, },
60 { 0x0a, 0x00, 0x21, },
61 { 0x21, 0x04, 0x00, }, /* full readout speed, no row/col skipping */
62 };
63
64 for (i = 0; i < ARRAY_SIZE(regs); i++)
65 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
66 &regs[i][0], 3);
67
68 return 0;
69}
70
71
72/* FIXME: Should be replaced by a proper mt9m001 driver */
73static int em28xx_initialize_mt9m001(struct em28xx *dev)
74{
75 int i;
76 unsigned char regs[][3] = {
77 { 0x0d, 0x00, 0x01, },
78 { 0x0d, 0x00, 0x00, },
79 { 0x04, 0x05, 0x00, }, /* hres = 1280 */
80 { 0x03, 0x04, 0x00, }, /* vres = 1024 */
81 { 0x20, 0x11, 0x00, },
82 { 0x06, 0x00, 0x10, },
83 { 0x2b, 0x00, 0x24, },
84 { 0x2e, 0x00, 0x24, },
85 { 0x35, 0x00, 0x24, },
86 { 0x2d, 0x00, 0x20, },
87 { 0x2c, 0x00, 0x20, },
88 { 0x09, 0x0a, 0xd4, },
89 { 0x35, 0x00, 0x57, },
90 };
91
92 for (i = 0; i < ARRAY_SIZE(regs); i++)
93 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
94 &regs[i][0], 3);
95
96 return 0;
97}
98
99
100/*
101 * Probes Micron sensors with 8 bit address and 16 bit register width
102 */
103static int em28xx_probe_sensor_micron(struct em28xx *dev)
104{
105 int ret, i;
106 char *name;
107 u8 reg;
108 __be16 id_be;
109 u16 id;
110
111 struct i2c_client client = dev->i2c_client[dev->def_i2c_bus];
112
113 dev->em28xx_sensor = EM28XX_NOSENSOR;
114 for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) {
115 client.addr = micron_sensor_addrs[i];
116 /* NOTE: i2c_smbus_read_word_data() doesn't work with BE data */
117 /* Read chip ID from register 0x00 */
118 reg = 0x00;
119 ret = i2c_master_send(&client, &reg, 1);
120 if (ret < 0) {
121 if (ret != -ENODEV)
122 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
123 client.addr << 1, ret);
124 continue;
125 }
126 ret = i2c_master_recv(&client, (u8 *)&id_be, 2);
127 if (ret < 0) {
128 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
129 client.addr << 1, ret);
130 continue;
131 }
132 id = be16_to_cpu(id_be);
133 /* Read chip ID from register 0xff */
134 reg = 0xff;
135 ret = i2c_master_send(&client, &reg, 1);
136 if (ret < 0) {
137 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
138 client.addr << 1, ret);
139 continue;
140 }
141 ret = i2c_master_recv(&client, (u8 *)&id_be, 2);
142 if (ret < 0) {
143 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
144 client.addr << 1, ret);
145 continue;
146 }
147 /* Validate chip ID to be sure we have a Micron device */
148 if (id != be16_to_cpu(id_be))
149 continue;
150 /* Check chip ID */
151 id = be16_to_cpu(id_be);
152 switch (id) {
153 case 0x1222:
154 name = "MT9V012"; /* MI370 */ /* 640x480 */
155 break;
156 case 0x1229:
157 name = "MT9V112"; /* 640x480 */
158 break;
159 case 0x1433:
160 name = "MT9M011"; /* 1280x1024 */
161 break;
162 case 0x143a: /* found in the ECS G200 */
163 name = "MT9M111"; /* MI1310 */ /* 1280x1024 */
164 dev->em28xx_sensor = EM28XX_MT9M111;
165 break;
166 case 0x148c:
167 name = "MT9M112"; /* MI1320 */ /* 1280x1024 */
168 break;
169 case 0x1511:
170 name = "MT9D011"; /* MI2010 */ /* 1600x1200 */
171 break;
172 case 0x8232:
173 case 0x8243: /* rev B */
174 name = "MT9V011"; /* MI360 */ /* 640x480 */
175 dev->em28xx_sensor = EM28XX_MT9V011;
176 break;
177 case 0x8431:
178 name = "MT9M001"; /* 1280x1024 */
179 dev->em28xx_sensor = EM28XX_MT9M001;
180 break;
181 default:
182 em28xx_info("unknown Micron sensor detected: 0x%04x\n",
183 id);
184 return 0;
185 }
186
187 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
188 em28xx_info("unsupported sensor detected: %s\n", name);
189 else
190 em28xx_info("sensor %s detected\n", name);
191
192 dev->i2c_client[dev->def_i2c_bus].addr = client.addr;
193 return 0;
194 }
195
196 return -ENODEV;
197}
198
199/*
200 * Probes Omnivision sensors with 8 bit address and register width
201 */
202static int em28xx_probe_sensor_omnivision(struct em28xx *dev)
203{
204 int ret, i;
205 char *name;
206 u8 reg;
207 u16 id;
208 struct i2c_client client = dev->i2c_client[dev->def_i2c_bus];
209
210 dev->em28xx_sensor = EM28XX_NOSENSOR;
211 /* NOTE: these devices have the register auto incrementation disabled
212 * by default, so we have to use single byte reads ! */
213 for (i = 0; omnivision_sensor_addrs[i] != I2C_CLIENT_END; i++) {
214 client.addr = omnivision_sensor_addrs[i];
215 /* Read manufacturer ID from registers 0x1c-0x1d (BE) */
216 reg = 0x1c;
217 ret = i2c_smbus_read_byte_data(&client, reg);
218 if (ret < 0) {
219 if (ret != -ENODEV)
220 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
221 client.addr << 1, ret);
222 continue;
223 }
224 id = ret << 8;
225 reg = 0x1d;
226 ret = i2c_smbus_read_byte_data(&client, reg);
227 if (ret < 0) {
228 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
229 client.addr << 1, ret);
230 continue;
231 }
232 id += ret;
233 /* Check manufacturer ID */
234 if (id != 0x7fa2)
235 continue;
236 /* Read product ID from registers 0x0a-0x0b (BE) */
237 reg = 0x0a;
238 ret = i2c_smbus_read_byte_data(&client, reg);
239 if (ret < 0) {
240 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
241 client.addr << 1, ret);
242 continue;
243 }
244 id = ret << 8;
245 reg = 0x0b;
246 ret = i2c_smbus_read_byte_data(&client, reg);
247 if (ret < 0) {
248 em28xx_errdev("couldn't read from i2c device 0x%02x: error %i\n",
249 client.addr << 1, ret);
250 continue;
251 }
252 id += ret;
253 /* Check product ID */
254 switch (id) {
255 case 0x2642:
256 name = "OV2640";
257 dev->em28xx_sensor = EM28XX_OV2640;
258 break;
259 case 0x7648:
260 name = "OV7648";
261 break;
262 case 0x7660:
263 name = "OV7660";
264 break;
265 case 0x7673:
266 name = "OV7670";
267 break;
268 case 0x7720:
269 name = "OV7720";
270 break;
271 case 0x7721:
272 name = "OV7725";
273 break;
274 case 0x9648: /* Rev 2 */
275 case 0x9649: /* Rev 3 */
276 name = "OV9640";
277 break;
278 case 0x9650:
279 case 0x9652: /* OV9653 */
280 name = "OV9650";
281 break;
282 case 0x9656: /* Rev 4 */
283 case 0x9657: /* Rev 5 */
284 name = "OV9655";
285 break;
286 default:
287 em28xx_info("unknown OmniVision sensor detected: 0x%04x\n",
288 id);
289 return 0;
290 }
291
292 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
293 em28xx_info("unsupported sensor detected: %s\n", name);
294 else
295 em28xx_info("sensor %s detected\n", name);
296
297 dev->i2c_client[dev->def_i2c_bus].addr = client.addr;
298 return 0;
299 }
300
301 return -ENODEV;
302}
303
304int em28xx_detect_sensor(struct em28xx *dev)
305{
306 int ret;
307
308 ret = em28xx_probe_sensor_micron(dev);
309
310 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0)
311 ret = em28xx_probe_sensor_omnivision(dev);
312
313 /*
314 * NOTE: the Windows driver also probes i2c addresses
315 * 0x22 (Samsung ?) and 0x66 (Kodak ?)
316 */
317
318 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) {
319 em28xx_info("No sensor detected\n");
320 return -ENODEV;
321 }
322
323 return 0;
324}
325
326int em28xx_init_camera(struct em28xx *dev)
327{
328 switch (dev->em28xx_sensor) {
329 case EM28XX_MT9V011:
330 {
331 struct mt9v011_platform_data pdata;
332 struct i2c_board_info mt9v011_info = {
333 .type = "mt9v011",
334 .addr = dev->i2c_client[dev->def_i2c_bus].addr,
335 .platform_data = &pdata,
336 };
337
338 dev->sensor_xres = 640;
339 dev->sensor_yres = 480;
340
341 /*
342 * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
343 * the Silvercrest cam I have here for testing - for higher
344 * resolutions, a high clock cause horizontal artifacts, so we
345 * need to use a lower xclk frequency.
346 * Yet, it would be possible to adjust xclk depending on the
347 * desired resolution, since this affects directly the
348 * frame rate.
349 */
350 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
351 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
352 dev->sensor_xtal = 4300000;
353 pdata.xtal = dev->sensor_xtal;
354 if (NULL ==
355 v4l2_i2c_new_subdev_board(&dev->v4l2_dev,
356 &dev->i2c_adap[dev->def_i2c_bus],
357 &mt9v011_info, NULL))
358 return -ENODEV;
359 /* probably means GRGB 16 bit bayer */
360 dev->vinmode = 0x0d;
361 dev->vinctl = 0x00;
362
363 break;
364 }
365 case EM28XX_MT9M001:
366 dev->sensor_xres = 1280;
367 dev->sensor_yres = 1024;
368
369 em28xx_initialize_mt9m001(dev);
370
371 /* probably means BGGR 16 bit bayer */
372 dev->vinmode = 0x0c;
373 dev->vinctl = 0x00;
374
375 break;
376 case EM28XX_MT9M111:
377 dev->sensor_xres = 640;
378 dev->sensor_yres = 512;
379
380 dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
381 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
382 em28xx_initialize_mt9m111(dev);
383
384 dev->vinmode = 0x0a;
385 dev->vinctl = 0x00;
386
387 break;
388 case EM28XX_OV2640:
389 {
390 struct v4l2_subdev *subdev;
391 struct i2c_board_info ov2640_info = {
392 .type = "ov2640",
393 .flags = I2C_CLIENT_SCCB,
394 .addr = dev->i2c_client[dev->def_i2c_bus].addr,
395 .platform_data = &camlink,
396 };
397 struct v4l2_mbus_framefmt fmt;
398
399 /*
400 * FIXME: sensor supports resolutions up to 1600x1200, but
401 * resolution setting/switching needs to be modified to
402 * - switch sensor output resolution (including further
403 * configuration changes)
404 * - adjust bridge xclk
405 * - disable 16 bit (12 bit) output formats on high resolutions
406 */
407 dev->sensor_xres = 640;
408 dev->sensor_yres = 480;
409
410 subdev =
411 v4l2_i2c_new_subdev_board(&dev->v4l2_dev,
412 &dev->i2c_adap[dev->def_i2c_bus],
413 &ov2640_info, NULL);
414
415 fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;
416 fmt.width = 640;
417 fmt.height = 480;
418 v4l2_subdev_call(subdev, video, s_mbus_fmt, &fmt);
419
420 /* NOTE: for UXGA=1600x1200 switch to 12MHz */
421 dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ;
422 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
423 dev->vinmode = 0x08;
424 dev->vinctl = 0x00;
425
426 break;
427 }
428 case EM28XX_NOSENSOR:
429 default:
430 return -EINVAL;
431 }
432
433 return 0;
434}
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 54a03b20de6e..83bfbe4c980f 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -34,7 +34,6 @@
34#include <media/saa7115.h> 34#include <media/saa7115.h>
35#include <media/tvp5150.h> 35#include <media/tvp5150.h>
36#include <media/tvaudio.h> 36#include <media/tvaudio.h>
37#include <media/mt9v011.h>
38#include <media/i2c-addr.h> 37#include <media/i2c-addr.h>
39#include <media/tveeprom.h> 38#include <media/tveeprom.h>
40#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
@@ -345,6 +344,18 @@ static struct em28xx_reg_seq pctv_460e[] = {
345 { -1, -1, -1, -1}, 344 { -1, -1, -1, -1},
346}; 345};
347 346
347static struct em28xx_reg_seq c3tech_digital_duo_digital[] = {
348 {EM2874_R80_GPIO, 0xff, 0xff, 10},
349 {EM2874_R80_GPIO, 0xfd, 0xff, 10}, /* xc5000 reset */
350 {EM2874_R80_GPIO, 0xf9, 0xff, 35},
351 {EM2874_R80_GPIO, 0xfd, 0xff, 10},
352 {EM2874_R80_GPIO, 0xff, 0xff, 10},
353 {EM2874_R80_GPIO, 0xfe, 0xff, 10},
354 {EM2874_R80_GPIO, 0xbe, 0xff, 10},
355 {EM2874_R80_GPIO, 0xfe, 0xff, 20},
356 { -1, -1, -1, -1},
357};
358
348#if 0 359#if 0
349static struct em28xx_reg_seq hauppauge_930c_gpio[] = { 360static struct em28xx_reg_seq hauppauge_930c_gpio[] = {
350 {EM2874_R80_GPIO, 0x6f, 0xff, 10}, 361 {EM2874_R80_GPIO, 0x6f, 0xff, 10},
@@ -958,8 +969,8 @@ struct em28xx_board em28xx_boards[] = {
958#else 969#else
959 .tuner_type = TUNER_ABSENT, 970 .tuner_type = TUNER_ABSENT,
960#endif 971#endif
961 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 972 .def_i2c_bus = 1,
962 EM28XX_I2C_CLK_WAIT_ENABLE | 973 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
963 EM28XX_I2C_FREQ_400_KHZ, 974 EM28XX_I2C_FREQ_400_KHZ,
964 }, 975 },
965 [EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C] = { 976 [EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C] = {
@@ -974,17 +985,27 @@ struct em28xx_board em28xx_boards[] = {
974 .tuner_type = TUNER_ABSENT, 985 .tuner_type = TUNER_ABSENT,
975#endif 986#endif
976 .ir_codes = RC_MAP_HAUPPAUGE, 987 .ir_codes = RC_MAP_HAUPPAUGE,
977 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 988 .def_i2c_bus = 1,
978 EM28XX_I2C_CLK_WAIT_ENABLE | 989 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
979 EM28XX_I2C_FREQ_400_KHZ, 990 EM28XX_I2C_FREQ_400_KHZ,
980 }, 991 },
992 [EM2884_BOARD_C3TECH_DIGITAL_DUO] = {
993 .name = "C3 Tech Digital Duo HDTV/SDTV USB",
994 .has_dvb = 1,
995 /* FIXME: Add analog support - need a saa7136 driver */
996 .tuner_type = TUNER_ABSENT, /* Digital-only TDA18271HD */
997 .ir_codes = RC_MAP_EMPTY,
998 .def_i2c_bus = 1,
999 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE,
1000 .dvb_gpio = c3tech_digital_duo_digital,
1001 },
981 [EM2884_BOARD_CINERGY_HTC_STICK] = { 1002 [EM2884_BOARD_CINERGY_HTC_STICK] = {
982 .name = "Terratec Cinergy HTC Stick", 1003 .name = "Terratec Cinergy HTC Stick",
983 .has_dvb = 1, 1004 .has_dvb = 1,
984 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS, 1005 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
985 .tuner_type = TUNER_ABSENT, 1006 .tuner_type = TUNER_ABSENT,
986 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 1007 .def_i2c_bus = 1,
987 EM28XX_I2C_CLK_WAIT_ENABLE | 1008 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
988 EM28XX_I2C_FREQ_400_KHZ, 1009 EM28XX_I2C_FREQ_400_KHZ,
989 }, 1010 },
990 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = { 1011 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
@@ -1404,8 +1425,8 @@ struct em28xx_board em28xx_boards[] = {
1404 }, 1425 },
1405 1426
1406 [EM2874_BOARD_LEADERSHIP_ISDBT] = { 1427 [EM2874_BOARD_LEADERSHIP_ISDBT] = {
1407 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 1428 .def_i2c_bus = 1,
1408 EM28XX_I2C_CLK_WAIT_ENABLE | 1429 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1409 EM28XX_I2C_FREQ_100_KHZ, 1430 EM28XX_I2C_FREQ_100_KHZ,
1410 .xclk = EM28XX_XCLK_FREQUENCY_10MHZ, 1431 .xclk = EM28XX_XCLK_FREQUENCY_10MHZ,
1411 .name = "EM2874 Leadership ISDBT", 1432 .name = "EM2874 Leadership ISDBT",
@@ -1917,8 +1938,8 @@ struct em28xx_board em28xx_boards[] = {
1917 * Empia EM28174, Sony CXD2820R and NXP TDA18271HD/C2 */ 1938 * Empia EM28174, Sony CXD2820R and NXP TDA18271HD/C2 */
1918 [EM28174_BOARD_PCTV_290E] = { 1939 [EM28174_BOARD_PCTV_290E] = {
1919 .name = "PCTV nanoStick T2 290e", 1940 .name = "PCTV nanoStick T2 290e",
1920 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 1941 .def_i2c_bus = 1,
1921 EM28XX_I2C_CLK_WAIT_ENABLE | EM28XX_I2C_FREQ_100_KHZ, 1942 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | EM28XX_I2C_FREQ_100_KHZ,
1922 .tuner_type = TUNER_ABSENT, 1943 .tuner_type = TUNER_ABSENT,
1923 .tuner_gpio = pctv_290e, 1944 .tuner_gpio = pctv_290e,
1924 .has_dvb = 1, 1945 .has_dvb = 1,
@@ -1927,8 +1948,8 @@ struct em28xx_board em28xx_boards[] = {
1927 /* 2013:024f PCTV DVB-S2 Stick 460e 1948 /* 2013:024f PCTV DVB-S2 Stick 460e
1928 * Empia EM28174, NXP TDA10071, Conexant CX24118A and Allegro A8293 */ 1949 * Empia EM28174, NXP TDA10071, Conexant CX24118A and Allegro A8293 */
1929 [EM28174_BOARD_PCTV_460E] = { 1950 [EM28174_BOARD_PCTV_460E] = {
1930 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 1951 .def_i2c_bus = 1,
1931 EM28XX_I2C_CLK_WAIT_ENABLE | EM28XX_I2C_FREQ_400_KHZ, 1952 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | EM28XX_I2C_FREQ_400_KHZ,
1932 .name = "PCTV DVB-S2 Stick (460e)", 1953 .name = "PCTV DVB-S2 Stick (460e)",
1933 .tuner_type = TUNER_ABSENT, 1954 .tuner_type = TUNER_ABSENT,
1934 .tuner_gpio = pctv_460e, 1955 .tuner_gpio = pctv_460e,
@@ -1958,8 +1979,9 @@ struct em28xx_board em28xx_boards[] = {
1958 .tuner_type = TUNER_ABSENT, 1979 .tuner_type = TUNER_ABSENT,
1959 .tuner_gpio = maxmedia_ub425_tc, 1980 .tuner_gpio = maxmedia_ub425_tc,
1960 .has_dvb = 1, 1981 .has_dvb = 1,
1961 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 1982 .ir_codes = RC_MAP_REDDO,
1962 EM28XX_I2C_CLK_WAIT_ENABLE | 1983 .def_i2c_bus = 1,
1984 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1963 EM28XX_I2C_FREQ_400_KHZ, 1985 EM28XX_I2C_FREQ_400_KHZ,
1964 }, 1986 },
1965 /* 2304:0242 PCTV QuatroStick (510e) 1987 /* 2304:0242 PCTV QuatroStick (510e)
@@ -1970,8 +1992,8 @@ struct em28xx_board em28xx_boards[] = {
1970 .tuner_gpio = pctv_510e, 1992 .tuner_gpio = pctv_510e,
1971 .has_dvb = 1, 1993 .has_dvb = 1,
1972 .ir_codes = RC_MAP_PINNACLE_PCTV_HD, 1994 .ir_codes = RC_MAP_PINNACLE_PCTV_HD,
1973 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 1995 .def_i2c_bus = 1,
1974 EM28XX_I2C_CLK_WAIT_ENABLE | 1996 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1975 EM28XX_I2C_FREQ_400_KHZ, 1997 EM28XX_I2C_FREQ_400_KHZ,
1976 }, 1998 },
1977 /* 2013:0251 PCTV QuatroStick nano (520e) 1999 /* 2013:0251 PCTV QuatroStick nano (520e)
@@ -1982,8 +2004,8 @@ struct em28xx_board em28xx_boards[] = {
1982 .tuner_gpio = pctv_520e, 2004 .tuner_gpio = pctv_520e,
1983 .has_dvb = 1, 2005 .has_dvb = 1,
1984 .ir_codes = RC_MAP_PINNACLE_PCTV_HD, 2006 .ir_codes = RC_MAP_PINNACLE_PCTV_HD,
1985 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 2007 .def_i2c_bus = 1,
1986 EM28XX_I2C_CLK_WAIT_ENABLE | 2008 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1987 EM28XX_I2C_FREQ_400_KHZ, 2009 EM28XX_I2C_FREQ_400_KHZ,
1988 }, 2010 },
1989 [EM2884_BOARD_TERRATEC_HTC_USB_XS] = { 2011 [EM2884_BOARD_TERRATEC_HTC_USB_XS] = {
@@ -1991,8 +2013,8 @@ struct em28xx_board em28xx_boards[] = {
1991 .has_dvb = 1, 2013 .has_dvb = 1,
1992 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS, 2014 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
1993 .tuner_type = TUNER_ABSENT, 2015 .tuner_type = TUNER_ABSENT,
1994 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT | 2016 .def_i2c_bus = 1,
1995 EM28XX_I2C_CLK_WAIT_ENABLE | 2017 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1996 EM28XX_I2C_FREQ_400_KHZ, 2018 EM28XX_I2C_FREQ_400_KHZ,
1997 }, 2019 },
1998}; 2020};
@@ -2144,6 +2166,8 @@ struct usb_device_id em28xx_id_table[] = {
2144 .driver_info = EM28174_BOARD_PCTV_460E }, 2166 .driver_info = EM28174_BOARD_PCTV_460E },
2145 { USB_DEVICE(0x2040, 0x1605), 2167 { USB_DEVICE(0x2040, 0x1605),
2146 .driver_info = EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C }, 2168 .driver_info = EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C },
2169 { USB_DEVICE(0x1b80, 0xe755),
2170 .driver_info = EM2884_BOARD_C3TECH_DIGITAL_DUO },
2147 { USB_DEVICE(0xeb1a, 0x5006), 2171 { USB_DEVICE(0xeb1a, 0x5006),
2148 .driver_info = EM2860_BOARD_HT_VIDBOX_NW03 }, 2172 .driver_info = EM2860_BOARD_HT_VIDBOX_NW03 },
2149 { USB_DEVICE(0x1b80, 0xe309), /* Sveon STV40 */ 2173 { USB_DEVICE(0x1b80, 0xe309), /* Sveon STV40 */
@@ -2183,6 +2207,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
2183 {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF}, 2207 {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF},
2184 {0x6b800080, EM2874_BOARD_LEADERSHIP_ISDBT, TUNER_ABSENT}, 2208 {0x6b800080, EM2874_BOARD_LEADERSHIP_ISDBT, TUNER_ABSENT},
2185}; 2209};
2210/* NOTE: introduce a separate hash table for devices with 16 bit eeproms */
2186 2211
2187/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */ 2212/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */
2188static unsigned short saa711x_addrs[] = { 2213static unsigned short saa711x_addrs[] = {
@@ -2204,8 +2229,9 @@ static unsigned short msp3400_addrs[] = {
2204 2229
2205int em28xx_tuner_callback(void *ptr, int component, int command, int arg) 2230int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
2206{ 2231{
2232 struct em28xx_i2c_bus *i2c_bus = ptr;
2233 struct em28xx *dev = i2c_bus->dev;
2207 int rc = 0; 2234 int rc = 0;
2208 struct em28xx *dev = ptr;
2209 2235
2210 if (dev->tuner_type != TUNER_XC2028 && dev->tuner_type != TUNER_XC5000) 2236 if (dev->tuner_type != TUNER_XC2028 && dev->tuner_type != TUNER_XC5000)
2211 return 0; 2237 return 0;
@@ -2233,145 +2259,9 @@ static inline void em28xx_set_model(struct em28xx *dev)
2233 if (!dev->board.i2c_speed) 2259 if (!dev->board.i2c_speed)
2234 dev->board.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | 2260 dev->board.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
2235 EM28XX_I2C_FREQ_100_KHZ; 2261 EM28XX_I2C_FREQ_100_KHZ;
2236}
2237
2238
2239/* FIXME: Should be replaced by a proper mt9m111 driver */
2240static int em28xx_initialize_mt9m111(struct em28xx *dev)
2241{
2242 int i;
2243 unsigned char regs[][3] = {
2244 { 0x0d, 0x00, 0x01, }, /* reset and use defaults */
2245 { 0x0d, 0x00, 0x00, },
2246 { 0x0a, 0x00, 0x21, },
2247 { 0x21, 0x04, 0x00, }, /* full readout speed, no row/col skipping */
2248 };
2249
2250 for (i = 0; i < ARRAY_SIZE(regs); i++)
2251 i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
2252
2253 return 0;
2254}
2255
2256
2257/* FIXME: Should be replaced by a proper mt9m001 driver */
2258static int em28xx_initialize_mt9m001(struct em28xx *dev)
2259{
2260 int i;
2261 unsigned char regs[][3] = {
2262 { 0x0d, 0x00, 0x01, },
2263 { 0x0d, 0x00, 0x00, },
2264 { 0x04, 0x05, 0x00, }, /* hres = 1280 */
2265 { 0x03, 0x04, 0x00, }, /* vres = 1024 */
2266 { 0x20, 0x11, 0x00, },
2267 { 0x06, 0x00, 0x10, },
2268 { 0x2b, 0x00, 0x24, },
2269 { 0x2e, 0x00, 0x24, },
2270 { 0x35, 0x00, 0x24, },
2271 { 0x2d, 0x00, 0x20, },
2272 { 0x2c, 0x00, 0x20, },
2273 { 0x09, 0x0a, 0xd4, },
2274 { 0x35, 0x00, 0x57, },
2275 };
2276
2277 for (i = 0; i < ARRAY_SIZE(regs); i++)
2278 i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
2279
2280 return 0;
2281}
2282
2283/* HINT method: webcam I2C chips
2284 *
2285 * This method works for webcams with Micron sensors
2286 */
2287static int em28xx_hint_sensor(struct em28xx *dev)
2288{
2289 int rc;
2290 char *sensor_name;
2291 unsigned char cmd;
2292 __be16 version_be;
2293 u16 version;
2294
2295 /* Micron sensor detection */
2296 dev->i2c_client.addr = 0xba >> 1;
2297 cmd = 0;
2298 i2c_master_send(&dev->i2c_client, &cmd, 1);
2299 rc = i2c_master_recv(&dev->i2c_client, (char *)&version_be, 2);
2300 if (rc != 2)
2301 return -EINVAL;
2302
2303 version = be16_to_cpu(version_be);
2304 switch (version) {
2305 case 0x8232: /* mt9v011 640x480 1.3 Mpix sensor */
2306 case 0x8243: /* mt9v011 rev B 640x480 1.3 Mpix sensor */
2307 dev->model = EM2820_BOARD_SILVERCREST_WEBCAM;
2308 em28xx_set_model(dev);
2309
2310 sensor_name = "mt9v011";
2311 dev->em28xx_sensor = EM28XX_MT9V011;
2312 dev->sensor_xres = 640;
2313 dev->sensor_yres = 480;
2314 /*
2315 * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
2316 * the Silvercrest cam I have here for testing - for higher
2317 * resolutions, a high clock cause horizontal artifacts, so we
2318 * need to use a lower xclk frequency.
2319 * Yet, it would be possible to adjust xclk depending on the
2320 * desired resolution, since this affects directly the
2321 * frame rate.
2322 */
2323 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
2324 dev->sensor_xtal = 4300000;
2325
2326 /* probably means GRGB 16 bit bayer */
2327 dev->vinmode = 0x0d;
2328 dev->vinctl = 0x00;
2329
2330 break;
2331
2332 case 0x143a: /* MT9M111 as found in the ECS G200 */
2333 dev->model = EM2750_BOARD_UNKNOWN;
2334 em28xx_set_model(dev);
2335
2336 sensor_name = "mt9m111";
2337 dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
2338 dev->em28xx_sensor = EM28XX_MT9M111;
2339 em28xx_initialize_mt9m111(dev);
2340 dev->sensor_xres = 640;
2341 dev->sensor_yres = 512;
2342
2343 dev->vinmode = 0x0a;
2344 dev->vinctl = 0x00;
2345
2346 break;
2347
2348 case 0x8431:
2349 dev->model = EM2750_BOARD_UNKNOWN;
2350 em28xx_set_model(dev);
2351
2352 sensor_name = "mt9m001";
2353 dev->em28xx_sensor = EM28XX_MT9M001;
2354 em28xx_initialize_mt9m001(dev);
2355 dev->sensor_xres = 1280;
2356 dev->sensor_yres = 1024;
2357
2358 /* probably means BGGR 16 bit bayer */
2359 dev->vinmode = 0x0c;
2360 dev->vinctl = 0x00;
2361
2362 break;
2363 default:
2364 printk("Unknown Micron Sensor 0x%04x\n", version);
2365 return -EINVAL;
2366 }
2367
2368 /* Setup webcam defaults */
2369 em28xx_pre_card_setup(dev);
2370 2262
2371 em28xx_errdev("Sensor is %s, using model %s entry.\n", 2263 /* Should be initialized early, for I2C to work */
2372 sensor_name, em28xx_boards[dev->model].name); 2264 dev->def_i2c_bus = dev->board.def_i2c_bus;
2373
2374 return 0;
2375} 2265}
2376 2266
2377/* Since em28xx_pre_card_setup() requires a proper dev->model, 2267/* Since em28xx_pre_card_setup() requires a proper dev->model,
@@ -2599,6 +2489,18 @@ static int em28xx_hint_board(struct em28xx *dev)
2599{ 2489{
2600 int i; 2490 int i;
2601 2491
2492 if (dev->board.is_webcam) {
2493 if (dev->em28xx_sensor == EM28XX_MT9V011) {
2494 dev->model = EM2820_BOARD_SILVERCREST_WEBCAM;
2495 } else if (dev->em28xx_sensor == EM28XX_MT9M001 ||
2496 dev->em28xx_sensor == EM28XX_MT9M111) {
2497 dev->model = EM2750_BOARD_UNKNOWN;
2498 }
2499 /* FIXME: IMPROVE ! */
2500
2501 return 0;
2502 }
2503
2602 /* HINT method: EEPROM 2504 /* HINT method: EEPROM
2603 * 2505 *
2604 * This method works only for boards with eeprom. 2506 * This method works only for boards with eeprom.
@@ -2638,7 +2540,7 @@ static int em28xx_hint_board(struct em28xx *dev)
2638 2540
2639 /* user did not request i2c scanning => do it now */ 2541 /* user did not request i2c scanning => do it now */
2640 if (!dev->i2c_hash) 2542 if (!dev->i2c_hash)
2641 em28xx_do_i2c_scan(dev); 2543 em28xx_do_i2c_scan(dev, dev->def_i2c_bus);
2642 2544
2643 for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) { 2545 for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
2644 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) { 2546 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
@@ -2684,16 +2586,16 @@ static void em28xx_card_setup(struct em28xx *dev)
2684 * If sensor is not found, then it isn't a webcam. 2586 * If sensor is not found, then it isn't a webcam.
2685 */ 2587 */
2686 if (dev->board.is_webcam) { 2588 if (dev->board.is_webcam) {
2687 if (em28xx_hint_sensor(dev) < 0) 2589 if (em28xx_detect_sensor(dev) < 0)
2688 dev->board.is_webcam = 0; 2590 dev->board.is_webcam = 0;
2689 else 2591 else
2690 dev->progressive = 1; 2592 dev->progressive = 1;
2691 } 2593 }
2692 2594
2693 if (!dev->board.is_webcam) { 2595 switch (dev->model) {
2694 switch (dev->model) { 2596 case EM2750_BOARD_UNKNOWN:
2695 case EM2820_BOARD_UNKNOWN: 2597 case EM2820_BOARD_UNKNOWN:
2696 case EM2800_BOARD_UNKNOWN: 2598 case EM2800_BOARD_UNKNOWN:
2697 /* 2599 /*
2698 * The K-WORLD DVB-T 310U is detected as an MSI Digivox AD. 2600 * The K-WORLD DVB-T 310U is detected as an MSI Digivox AD.
2699 * 2601 *
@@ -2714,9 +2616,8 @@ static void em28xx_card_setup(struct em28xx *dev)
2714 em28xx_pre_card_setup(dev); 2616 em28xx_pre_card_setup(dev);
2715 } 2617 }
2716 break; 2618 break;
2717 default: 2619 default:
2718 em28xx_set_model(dev); 2620 em28xx_set_model(dev);
2719 }
2720 } 2621 }
2721 2622
2722 em28xx_info("Identified as %s (card=%d)\n", 2623 em28xx_info("Identified as %s (card=%d)\n",
@@ -2736,15 +2637,19 @@ static void em28xx_card_setup(struct em28xx *dev)
2736 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: 2637 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
2737 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: 2638 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
2738 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: 2639 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
2640 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
2739 { 2641 {
2740 struct tveeprom tv; 2642 struct tveeprom tv;
2643
2644 if (dev->eedata == NULL)
2645 break;
2741#if defined(CONFIG_MODULES) && defined(MODULE) 2646#if defined(CONFIG_MODULES) && defined(MODULE)
2742 request_module("tveeprom"); 2647 request_module("tveeprom");
2743#endif 2648#endif
2744 /* Call first TVeeprom */ 2649 /* Call first TVeeprom */
2745 2650
2746 dev->i2c_client.addr = 0xa0 >> 1; 2651 dev->i2c_client[dev->def_i2c_bus].addr = 0xa0 >> 1;
2747 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata); 2652 tveeprom_hauppauge_analog(&dev->i2c_client[dev->def_i2c_bus], &tv, dev->eedata);
2748 2653
2749 dev->tuner_type = tv.tuner_type; 2654 dev->tuner_type = tv.tuner_type;
2750 2655
@@ -2791,7 +2696,7 @@ static void em28xx_card_setup(struct em28xx *dev)
2791 em28xx_set_mode(dev, EM28XX_ANALOG_MODE); 2696 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2792 break; 2697 break;
2793 2698
2794/* 2699 /*
2795 * The Dikom DK300 is detected as an Kworld VS-DVB-T 323UR. 2700 * The Dikom DK300 is detected as an Kworld VS-DVB-T 323UR.
2796 * 2701 *
2797 * This occurs because they share identical USB vendor and 2702 * This occurs because they share identical USB vendor and
@@ -2826,51 +2731,41 @@ static void em28xx_card_setup(struct em28xx *dev)
2826 "addresses)\n\n"); 2731 "addresses)\n\n");
2827 } 2732 }
2828 2733
2734 /* Free eeprom data memory */
2735 kfree(dev->eedata);
2736 dev->eedata = NULL;
2737
2829 /* Allow override tuner type by a module parameter */ 2738 /* Allow override tuner type by a module parameter */
2830 if (tuner >= 0) 2739 if (tuner >= 0)
2831 dev->tuner_type = tuner; 2740 dev->tuner_type = tuner;
2832 2741
2833 /* request some modules */ 2742 /* request some modules */
2834 if (dev->board.has_msp34xx) 2743 if (dev->board.has_msp34xx)
2835 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2744 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
2836 "msp3400", 0, msp3400_addrs); 2745 "msp3400", 0, msp3400_addrs);
2837 2746
2838 if (dev->board.decoder == EM28XX_SAA711X) 2747 if (dev->board.decoder == EM28XX_SAA711X)
2839 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2748 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
2840 "saa7115_auto", 0, saa711x_addrs); 2749 "saa7115_auto", 0, saa711x_addrs);
2841 2750
2842 if (dev->board.decoder == EM28XX_TVP5150) 2751 if (dev->board.decoder == EM28XX_TVP5150)
2843 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2752 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
2844 "tvp5150", 0, tvp5150_addrs); 2753 "tvp5150", 0, tvp5150_addrs);
2845 2754
2846 if (dev->em28xx_sensor == EM28XX_MT9V011) {
2847 struct mt9v011_platform_data pdata;
2848 struct i2c_board_info mt9v011_info = {
2849 .type = "mt9v011",
2850 .addr = 0xba >> 1,
2851 .platform_data = &pdata,
2852 };
2853
2854 pdata.xtal = dev->sensor_xtal;
2855 v4l2_i2c_new_subdev_board(&dev->v4l2_dev, &dev->i2c_adap,
2856 &mt9v011_info, NULL);
2857 }
2858
2859
2860 if (dev->board.adecoder == EM28XX_TVAUDIO) 2755 if (dev->board.adecoder == EM28XX_TVAUDIO)
2861 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2756 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
2862 "tvaudio", dev->board.tvaudio_addr, NULL); 2757 "tvaudio", dev->board.tvaudio_addr, NULL);
2863 2758
2864 if (dev->board.tuner_type != TUNER_ABSENT) { 2759 if (dev->board.tuner_type != TUNER_ABSENT) {
2865 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT); 2760 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
2866 2761
2867 if (dev->board.radio.type) 2762 if (dev->board.radio.type)
2868 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2763 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
2869 "tuner", dev->board.radio_addr, NULL); 2764 "tuner", dev->board.radio_addr, NULL);
2870 2765
2871 if (has_demod) 2766 if (has_demod)
2872 v4l2_i2c_new_subdev(&dev->v4l2_dev, 2767 v4l2_i2c_new_subdev(&dev->v4l2_dev,
2873 &dev->i2c_adap, "tuner", 2768 &dev->i2c_adap[dev->def_i2c_bus], "tuner",
2874 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 2769 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
2875 if (dev->tuner_addr == 0) { 2770 if (dev->tuner_addr == 0) {
2876 enum v4l2_i2c_tuner_type type = 2771 enum v4l2_i2c_tuner_type type =
@@ -2878,18 +2773,20 @@ static void em28xx_card_setup(struct em28xx *dev)
2878 struct v4l2_subdev *sd; 2773 struct v4l2_subdev *sd;
2879 2774
2880 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 2775 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
2881 &dev->i2c_adap, "tuner", 2776 &dev->i2c_adap[dev->def_i2c_bus], "tuner",
2882 0, v4l2_i2c_tuner_addrs(type)); 2777 0, v4l2_i2c_tuner_addrs(type));
2883 2778
2884 if (sd) 2779 if (sd)
2885 dev->tuner_addr = v4l2_i2c_subdev_addr(sd); 2780 dev->tuner_addr = v4l2_i2c_subdev_addr(sd);
2886 } else { 2781 } else {
2887 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2782 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
2888 "tuner", dev->tuner_addr, NULL); 2783 "tuner", dev->tuner_addr, NULL);
2889 } 2784 }
2890 } 2785 }
2891 2786
2892 em28xx_tuner_setup(dev); 2787 em28xx_tuner_setup(dev);
2788
2789 em28xx_init_camera(dev);
2893} 2790}
2894 2791
2895 2792
@@ -2914,7 +2811,8 @@ static void request_module_async(struct work_struct *work)
2914 2811
2915 if (dev->board.has_dvb) 2812 if (dev->board.has_dvb)
2916 request_module("em28xx-dvb"); 2813 request_module("em28xx-dvb");
2917 if ((dev->board.ir_codes || dev->board.has_ir_i2c) && !disable_ir) 2814 if (dev->board.has_snapshot_button ||
2815 ((dev->board.ir_codes || dev->board.has_ir_i2c) && !disable_ir))
2918 request_module("em28xx-rc"); 2816 request_module("em28xx-rc");
2919#endif /* CONFIG_MODULES */ 2817#endif /* CONFIG_MODULES */
2920} 2818}
@@ -2941,7 +2839,9 @@ void em28xx_release_resources(struct em28xx *dev)
2941 2839
2942 em28xx_release_analog_resources(dev); 2840 em28xx_release_analog_resources(dev);
2943 2841
2944 em28xx_i2c_unregister(dev); 2842 if (dev->def_i2c_bus)
2843 em28xx_i2c_unregister(dev, 1);
2844 em28xx_i2c_unregister(dev, 0);
2945 2845
2946 v4l2_ctrl_handler_free(&dev->ctrl_handler); 2846 v4l2_ctrl_handler_free(&dev->ctrl_handler);
2947 2847
@@ -3002,8 +2902,23 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3002 case CHIP_ID_EM2750: 2902 case CHIP_ID_EM2750:
3003 chip_name = "em2750"; 2903 chip_name = "em2750";
3004 break; 2904 break;
2905 case CHIP_ID_EM2765:
2906 chip_name = "em2765";
2907 dev->wait_after_write = 0;
2908 dev->is_em25xx = 1;
2909 dev->eeprom_addrwidth_16bit = 1;
2910 break;
3005 case CHIP_ID_EM2820: 2911 case CHIP_ID_EM2820:
3006 chip_name = "em2710/2820"; 2912 chip_name = "em2710/2820";
2913 if (le16_to_cpu(dev->udev->descriptor.idVendor)
2914 == 0xeb1a) {
2915 __le16 idProd = dev->udev->descriptor.idProduct;
2916 if (le16_to_cpu(idProd) == 0x2710)
2917 chip_name = "em2710";
2918 else if (le16_to_cpu(idProd) == 0x2820)
2919 chip_name = "em2820";
2920 }
2921 /* NOTE: the em2820 is used in webcams, too ! */
3007 break; 2922 break;
3008 case CHIP_ID_EM2840: 2923 case CHIP_ID_EM2840:
3009 chip_name = "em2840"; 2924 chip_name = "em2840";
@@ -3019,11 +2934,13 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3019 chip_name = "em2874"; 2934 chip_name = "em2874";
3020 dev->reg_gpio_num = EM2874_R80_GPIO; 2935 dev->reg_gpio_num = EM2874_R80_GPIO;
3021 dev->wait_after_write = 0; 2936 dev->wait_after_write = 0;
2937 dev->eeprom_addrwidth_16bit = 1;
3022 break; 2938 break;
3023 case CHIP_ID_EM28174: 2939 case CHIP_ID_EM28174:
3024 chip_name = "em28174"; 2940 chip_name = "em28174";
3025 dev->reg_gpio_num = EM2874_R80_GPIO; 2941 dev->reg_gpio_num = EM2874_R80_GPIO;
3026 dev->wait_after_write = 0; 2942 dev->wait_after_write = 0;
2943 dev->eeprom_addrwidth_16bit = 1;
3027 break; 2944 break;
3028 case CHIP_ID_EM2883: 2945 case CHIP_ID_EM2883:
3029 chip_name = "em2882/3"; 2946 chip_name = "em2882/3";
@@ -3033,6 +2950,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3033 chip_name = "em2884"; 2950 chip_name = "em2884";
3034 dev->reg_gpio_num = EM2874_R80_GPIO; 2951 dev->reg_gpio_num = EM2874_R80_GPIO;
3035 dev->wait_after_write = 0; 2952 dev->wait_after_write = 0;
2953 dev->eeprom_addrwidth_16bit = 1;
3036 break; 2954 break;
3037 default: 2955 default:
3038 printk(KERN_INFO DRIVER_NAME 2956 printk(KERN_INFO DRIVER_NAME
@@ -3066,14 +2984,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3066 2984
3067 em28xx_pre_card_setup(dev); 2985 em28xx_pre_card_setup(dev);
3068 2986
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
3077 if (!dev->board.is_em2800) { 2987 if (!dev->board.is_em2800) {
3078 /* Resets I2C speed */ 2988 /* Resets I2C speed */
3079 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed); 2989 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
@@ -3091,17 +3001,37 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3091 return retval; 3001 return retval;
3092 } 3002 }
3093 3003
3094 v4l2_ctrl_handler_init(hdl, 4); 3004 v4l2_ctrl_handler_init(hdl, 8);
3095 dev->v4l2_dev.ctrl_handler = hdl; 3005 dev->v4l2_dev.ctrl_handler = hdl;
3096 3006
3097 /* register i2c bus */ 3007 rt_mutex_init(&dev->i2c_bus_lock);
3098 retval = em28xx_i2c_register(dev); 3008
3009 /* register i2c bus 0 */
3010 if (dev->board.is_em2800)
3011 retval = em28xx_i2c_register(dev, 0, EM28XX_I2C_ALGO_EM2800);
3012 else
3013 retval = em28xx_i2c_register(dev, 0, EM28XX_I2C_ALGO_EM28XX);
3099 if (retval < 0) { 3014 if (retval < 0) {
3100 em28xx_errdev("%s: em28xx_i2c_register - error [%d]!\n", 3015 em28xx_errdev("%s: em28xx_i2c_register bus 0 - error [%d]!\n",
3101 __func__, retval); 3016 __func__, retval);
3102 goto unregister_dev; 3017 goto unregister_dev;
3103 } 3018 }
3104 3019
3020 /* register i2c bus 1 */
3021 if (dev->def_i2c_bus) {
3022 if (dev->is_em25xx)
3023 retval = em28xx_i2c_register(dev, 1,
3024 EM28XX_I2C_ALGO_EM25XX_BUS_B);
3025 else
3026 retval = em28xx_i2c_register(dev, 1,
3027 EM28XX_I2C_ALGO_EM28XX);
3028 if (retval < 0) {
3029 em28xx_errdev("%s: em28xx_i2c_register bus 1 - error [%d]!\n",
3030 __func__, retval);
3031 goto unregister_dev;
3032 }
3033 }
3034
3105 /* 3035 /*
3106 * Default format, used for tvp5150 or saa711x output formats 3036 * Default format, used for tvp5150 or saa711x output formats
3107 */ 3037 */
@@ -3160,11 +3090,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3160 msleep(3); 3090 msleep(3);
3161 } 3091 }
3162 3092
3163 v4l2_ctrl_handler_setup(&dev->ctrl_handler);
3164 retval = dev->ctrl_handler.error;
3165 if (retval)
3166 goto fail;
3167
3168 retval = em28xx_register_analog_devices(dev); 3093 retval = em28xx_register_analog_devices(dev);
3169 if (retval < 0) { 3094 if (retval < 0) {
3170 goto fail; 3095 goto fail;
@@ -3176,7 +3101,9 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3176 return 0; 3101 return 0;
3177 3102
3178fail: 3103fail:
3179 em28xx_i2c_unregister(dev); 3104 if (dev->def_i2c_bus)
3105 em28xx_i2c_unregister(dev, 1);
3106 em28xx_i2c_unregister(dev, 0);
3180 v4l2_ctrl_handler_free(&dev->ctrl_handler); 3107 v4l2_ctrl_handler_free(&dev->ctrl_handler);
3181 3108
3182unregister_dev: 3109unregister_dev:
@@ -3292,14 +3219,15 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3292 dev->analog_ep_bulk = 3219 dev->analog_ep_bulk =
3293 e->bEndpointAddress; 3220 e->bEndpointAddress;
3294 } else { 3221 } else {
3295 has_dvb = true;
3296 if (usb_endpoint_xfer_isoc(e)) { 3222 if (usb_endpoint_xfer_isoc(e)) {
3297 dev->dvb_ep_isoc = e->bEndpointAddress;
3298 if (size > dev->dvb_max_pkt_size_isoc) { 3223 if (size > dev->dvb_max_pkt_size_isoc) {
3224 has_dvb = true; /* see NOTE (~) */
3225 dev->dvb_ep_isoc = e->bEndpointAddress;
3299 dev->dvb_max_pkt_size_isoc = size; 3226 dev->dvb_max_pkt_size_isoc = size;
3300 dev->dvb_alt_isoc = i; 3227 dev->dvb_alt_isoc = i;
3301 } 3228 }
3302 } else { 3229 } else {
3230 has_dvb = true;
3303 dev->dvb_ep_bulk = e->bEndpointAddress; 3231 dev->dvb_ep_bulk = e->bEndpointAddress;
3304 } 3232 }
3305 } 3233 }
@@ -3326,6 +3254,12 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3326 * so far. But there might be devices for which this 3254 * so far. But there might be devices for which this
3327 * logic is not sufficient... 3255 * logic is not sufficient...
3328 */ 3256 */
3257 /*
3258 * NOTE (~): some manufacturers (e.g. Terratec) disable
3259 * endpoints by setting wMaxPacketSize to 0 bytes for
3260 * all alt settings. So far, we've seen this for
3261 * DVB isoc endpoints only.
3262 */
3329 } 3263 }
3330 } 3264 }
3331 3265
diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c
index aaedd11791f2..a802128ce9c5 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -607,12 +607,12 @@ EXPORT_SYMBOL_GPL(em28xx_audio_setup);
607 607
608int em28xx_colorlevels_set_default(struct em28xx *dev) 608int em28xx_colorlevels_set_default(struct em28xx *dev)
609{ 609{
610 em28xx_write_reg(dev, EM28XX_R20_YGAIN, 0x10); /* contrast */ 610 em28xx_write_reg(dev, EM28XX_R20_YGAIN, CONTRAST_DEFAULT);
611 em28xx_write_reg(dev, EM28XX_R21_YOFFSET, 0x00); /* brightness */ 611 em28xx_write_reg(dev, EM28XX_R21_YOFFSET, BRIGHTNESS_DEFAULT);
612 em28xx_write_reg(dev, EM28XX_R22_UVGAIN, 0x10); /* saturation */ 612 em28xx_write_reg(dev, EM28XX_R22_UVGAIN, SATURATION_DEFAULT);
613 em28xx_write_reg(dev, EM28XX_R23_UOFFSET, 0x00); 613 em28xx_write_reg(dev, EM28XX_R23_UOFFSET, BLUE_BALANCE_DEFAULT);
614 em28xx_write_reg(dev, EM28XX_R24_VOFFSET, 0x00); 614 em28xx_write_reg(dev, EM28XX_R24_VOFFSET, RED_BALANCE_DEFAULT);
615 em28xx_write_reg(dev, EM28XX_R25_SHARPNESS, 0x00); 615 em28xx_write_reg(dev, EM28XX_R25_SHARPNESS, SHARPNESS_DEFAULT);
616 616
617 em28xx_write_reg(dev, EM28XX_R14_GAMMA, 0x20); 617 em28xx_write_reg(dev, EM28XX_R14_GAMMA, 0x20);
618 em28xx_write_reg(dev, EM28XX_R15_RGAIN, 0x20); 618 em28xx_write_reg(dev, EM28XX_R15_RGAIN, 0x20);
@@ -681,6 +681,11 @@ int em28xx_vbi_supported(struct em28xx *dev)
681 if (disable_vbi == 1) 681 if (disable_vbi == 1)
682 return 0; 682 return 0;
683 683
684 if (dev->board.is_webcam)
685 return 0;
686
687 /* FIXME: check subdevices for VBI support */
688
684 if (dev->chip_id == CHIP_ID_EM2860 || 689 if (dev->chip_id == CHIP_ID_EM2860 ||
685 dev->chip_id == CHIP_ID_EM2883) 690 dev->chip_id == CHIP_ID_EM2883)
686 return 1; 691 return 1;
@@ -692,12 +697,23 @@ int em28xx_vbi_supported(struct em28xx *dev)
692int em28xx_set_outfmt(struct em28xx *dev) 697int em28xx_set_outfmt(struct em28xx *dev)
693{ 698{
694 int ret; 699 int ret;
695 u8 vinctrl; 700 u8 fmt, vinctrl;
696 701
697 ret = em28xx_write_reg_bits(dev, EM28XX_R27_OUTFMT, 702 fmt = dev->format->reg;
698 dev->format->reg | 0x20, 0xff); 703 if (!dev->is_em25xx)
704 fmt |= 0x20;
705 /*
706 * NOTE: it's not clear if this is really needed !
707 * The datasheets say bit 5 is a reserved bit and devices seem to work
708 * fine without it. But the Windows driver sets it for em2710/50+em28xx
709 * devices and we've always been setting it, too.
710 *
711 * em2765 (em25xx, em276x/7x/8x) devices do NOT work with this bit set,
712 * it's likely used for an additional (compressed ?) format there.
713 */
714 ret = em28xx_write_reg(dev, EM28XX_R27_OUTFMT, fmt);
699 if (ret < 0) 715 if (ret < 0)
700 return ret; 716 return ret;
701 717
702 ret = em28xx_write_reg(dev, EM28XX_R10_VINMODE, dev->vinmode); 718 ret = em28xx_write_reg(dev, EM28XX_R10_VINMODE, dev->vinmode);
703 if (ret < 0) 719 if (ret < 0)
@@ -751,6 +767,13 @@ static void em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart,
751 em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1); 767 em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1);
752 em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1); 768 em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1);
753 em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1); 769 em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1);
770
771 /* FIXME: function/meaning of these registers ? */
772 /* FIXME: align width+height to multiples of 4 ?! */
773 if (dev->is_em25xx) {
774 em28xx_write_reg(dev, 0x34, width >> 4);
775 em28xx_write_reg(dev, 0x35, height >> 4);
776 }
754} 777}
755 778
756static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v) 779static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index a81ec2e8cc9b..b22f8fed8127 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -50,6 +50,7 @@
50#include "tda10071.h" 50#include "tda10071.h"
51#include "a8293.h" 51#include "a8293.h"
52#include "qt1010.h" 52#include "qt1010.h"
53#include "mb86a20s.h"
53 54
54MODULE_DESCRIPTION("driver for em28xx based DVB cards"); 55MODULE_DESCRIPTION("driver for em28xx based DVB cards");
55MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 56MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
@@ -177,7 +178,8 @@ static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
177static int em28xx_start_streaming(struct em28xx_dvb *dvb) 178static int em28xx_start_streaming(struct em28xx_dvb *dvb)
178{ 179{
179 int rc; 180 int rc;
180 struct em28xx *dev = dvb->adapter.priv; 181 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
182 struct em28xx *dev = i2c_bus->dev;
181 int dvb_max_packet_size, packet_multiplier, dvb_alt; 183 int dvb_max_packet_size, packet_multiplier, dvb_alt;
182 184
183 if (dev->dvb_xfer_bulk) { 185 if (dev->dvb_xfer_bulk) {
@@ -216,12 +218,11 @@ static int em28xx_start_streaming(struct em28xx_dvb *dvb)
216 218
217static int em28xx_stop_streaming(struct em28xx_dvb *dvb) 219static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
218{ 220{
219 struct em28xx *dev = dvb->adapter.priv; 221 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
222 struct em28xx *dev = i2c_bus->dev;
220 223
221 em28xx_stop_urbs(dev); 224 em28xx_stop_urbs(dev);
222 225
223 em28xx_set_mode(dev, EM28XX_SUSPEND);
224
225 return 0; 226 return 0;
226} 227}
227 228
@@ -269,7 +270,8 @@ static int em28xx_stop_feed(struct dvb_demux_feed *feed)
269/* ------------------------------------------------------------------ */ 270/* ------------------------------------------------------------------ */
270static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) 271static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
271{ 272{
272 struct em28xx *dev = fe->dvb->priv; 273 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
274 struct em28xx *dev = i2c_bus->dev;
273 275
274 if (acquire) 276 if (acquire)
275 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 277 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
@@ -465,10 +467,10 @@ static void hauppauge_hvr930c_init(struct em28xx *dev)
465 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 467 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
466 msleep(10); 468 msleep(10);
467 469
468 dev->i2c_client.addr = 0x82 >> 1; 470 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
469 471
470 for (i = 0; i < ARRAY_SIZE(regs); i++) 472 for (i = 0; i < ARRAY_SIZE(regs); i++)
471 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); 473 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
472 em28xx_gpio_set(dev, hauppauge_hvr930c_end); 474 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
473 475
474 msleep(100); 476 msleep(100);
@@ -522,10 +524,10 @@ static void terratec_h5_init(struct em28xx *dev)
522 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); 524 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
523 msleep(10); 525 msleep(10);
524 526
525 dev->i2c_client.addr = 0x82 >> 1; 527 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
526 528
527 for (i = 0; i < ARRAY_SIZE(regs); i++) 529 for (i = 0; i < ARRAY_SIZE(regs); i++)
528 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); 530 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
529 em28xx_gpio_set(dev, terratec_h5_end); 531 em28xx_gpio_set(dev, terratec_h5_end);
530}; 532};
531 533
@@ -575,10 +577,10 @@ static void terratec_htc_stick_init(struct em28xx *dev)
575 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 577 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
576 msleep(10); 578 msleep(10);
577 579
578 dev->i2c_client.addr = 0x82 >> 1; 580 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
579 581
580 for (i = 0; i < ARRAY_SIZE(regs); i++) 582 for (i = 0; i < ARRAY_SIZE(regs); i++)
581 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); 583 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
582 584
583 em28xx_gpio_set(dev, terratec_htc_stick_end); 585 em28xx_gpio_set(dev, terratec_htc_stick_end);
584}; 586};
@@ -633,10 +635,10 @@ static void terratec_htc_usb_xs_init(struct em28xx *dev)
633 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 635 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
634 msleep(10); 636 msleep(10);
635 637
636 dev->i2c_client.addr = 0x82 >> 1; 638 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
637 639
638 for (i = 0; i < ARRAY_SIZE(regs); i++) 640 for (i = 0; i < ARRAY_SIZE(regs); i++)
639 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); 641 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
640 642
641 em28xx_gpio_set(dev, terratec_htc_usb_xs_end); 643 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
642}; 644};
@@ -662,10 +664,10 @@ static void pctv_520e_init(struct em28xx *dev)
662 {{ 0x01, 0x00, 0x73, 0xaf }, 4}, 664 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
663 }; 665 };
664 666
665 dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */ 667 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
666 668
667 for (i = 0; i < ARRAY_SIZE(regs); i++) 669 for (i = 0; i < ARRAY_SIZE(regs); i++)
668 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); 670 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
669}; 671};
670 672
671static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe) 673static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
@@ -768,9 +770,25 @@ static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
768}; 770};
769static struct qt1010_config em28xx_qt1010_config = { 771static struct qt1010_config em28xx_qt1010_config = {
770 .i2c_address = 0x62 772 .i2c_address = 0x62
773};
771 774
775static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
776 .demod_address = 0x10,
777 .is_serial = true,
778};
779
780static struct tda18271_std_map mb86a20s_tda18271_config = {
781 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
782 .if_lvl = 1, .rfagc_top = 0x37, },
772}; 783};
773 784
785static struct tda18271_config c3tech_duo_tda18271_config = {
786 .std_map = &mb86a20s_tda18271_config,
787 .gate = TDA18271_GATE_DIGITAL,
788 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
789};
790
791
774/* ------------------------------------------------------------------ */ 792/* ------------------------------------------------------------------ */
775 793
776static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev) 794static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
@@ -779,7 +797,7 @@ static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
779 struct xc2028_config cfg; 797 struct xc2028_config cfg;
780 798
781 memset(&cfg, 0, sizeof(cfg)); 799 memset(&cfg, 0, sizeof(cfg));
782 cfg.i2c_adap = &dev->i2c_adap; 800 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
783 cfg.i2c_addr = addr; 801 cfg.i2c_addr = addr;
784 802
785 if (!dev->dvb->fe[0]) { 803 if (!dev->dvb->fe[0]) {
@@ -824,7 +842,7 @@ static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
824 if (dvb->fe[1]) 842 if (dvb->fe[1])
825 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; 843 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
826 844
827 dvb->adapter.priv = dev; 845 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
828 846
829 /* register frontend */ 847 /* register frontend */
830 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]); 848 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
@@ -962,7 +980,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
962 switch (dev->model) { 980 switch (dev->model) {
963 case EM2874_BOARD_LEADERSHIP_ISDBT: 981 case EM2874_BOARD_LEADERSHIP_ISDBT:
964 dvb->fe[0] = dvb_attach(s921_attach, 982 dvb->fe[0] = dvb_attach(s921_attach,
965 &sharp_isdbt, &dev->i2c_adap); 983 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
966 984
967 if (!dvb->fe[0]) { 985 if (!dvb->fe[0]) {
968 result = -EINVAL; 986 result = -EINVAL;
@@ -976,7 +994,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
976 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: 994 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
977 dvb->fe[0] = dvb_attach(lgdt330x_attach, 995 dvb->fe[0] = dvb_attach(lgdt330x_attach,
978 &em2880_lgdt3303_dev, 996 &em2880_lgdt3303_dev,
979 &dev->i2c_adap); 997 &dev->i2c_adap[dev->def_i2c_bus]);
980 if (em28xx_attach_xc3028(0x61, dev) < 0) { 998 if (em28xx_attach_xc3028(0x61, dev) < 0) {
981 result = -EINVAL; 999 result = -EINVAL;
982 goto out_free; 1000 goto out_free;
@@ -985,7 +1003,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
985 case EM2880_BOARD_KWORLD_DVB_310U: 1003 case EM2880_BOARD_KWORLD_DVB_310U:
986 dvb->fe[0] = dvb_attach(zl10353_attach, 1004 dvb->fe[0] = dvb_attach(zl10353_attach,
987 &em28xx_zl10353_with_xc3028, 1005 &em28xx_zl10353_with_xc3028,
988 &dev->i2c_adap); 1006 &dev->i2c_adap[dev->def_i2c_bus]);
989 if (em28xx_attach_xc3028(0x61, dev) < 0) { 1007 if (em28xx_attach_xc3028(0x61, dev) < 0) {
990 result = -EINVAL; 1008 result = -EINVAL;
991 goto out_free; 1009 goto out_free;
@@ -996,7 +1014,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
996 case EM2880_BOARD_EMPIRE_DUAL_TV: 1014 case EM2880_BOARD_EMPIRE_DUAL_TV:
997 dvb->fe[0] = dvb_attach(zl10353_attach, 1015 dvb->fe[0] = dvb_attach(zl10353_attach,
998 &em28xx_zl10353_xc3028_no_i2c_gate, 1016 &em28xx_zl10353_xc3028_no_i2c_gate,
999 &dev->i2c_adap); 1017 &dev->i2c_adap[dev->def_i2c_bus]);
1000 if (em28xx_attach_xc3028(0x61, dev) < 0) { 1018 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1001 result = -EINVAL; 1019 result = -EINVAL;
1002 goto out_free; 1020 goto out_free;
@@ -1009,13 +1027,13 @@ static int em28xx_dvb_init(struct em28xx *dev)
1009 case EM2882_BOARD_KWORLD_VS_DVBT: 1027 case EM2882_BOARD_KWORLD_VS_DVBT:
1010 dvb->fe[0] = dvb_attach(zl10353_attach, 1028 dvb->fe[0] = dvb_attach(zl10353_attach,
1011 &em28xx_zl10353_xc3028_no_i2c_gate, 1029 &em28xx_zl10353_xc3028_no_i2c_gate,
1012 &dev->i2c_adap); 1030 &dev->i2c_adap[dev->def_i2c_bus]);
1013 if (dvb->fe[0] == NULL) { 1031 if (dvb->fe[0] == NULL) {
1014 /* This board could have either a zl10353 or a mt352. 1032 /* This board could have either a zl10353 or a mt352.
1015 If the chip id isn't for zl10353, try mt352 */ 1033 If the chip id isn't for zl10353, try mt352 */
1016 dvb->fe[0] = dvb_attach(mt352_attach, 1034 dvb->fe[0] = dvb_attach(mt352_attach,
1017 &terratec_xs_mt352_cfg, 1035 &terratec_xs_mt352_cfg,
1018 &dev->i2c_adap); 1036 &dev->i2c_adap[dev->def_i2c_bus]);
1019 } 1037 }
1020 1038
1021 if (em28xx_attach_xc3028(0x61, dev) < 0) { 1039 if (em28xx_attach_xc3028(0x61, dev) < 0) {
@@ -1026,16 +1044,16 @@ static int em28xx_dvb_init(struct em28xx *dev)
1026 case EM2870_BOARD_KWORLD_355U: 1044 case EM2870_BOARD_KWORLD_355U:
1027 dvb->fe[0] = dvb_attach(zl10353_attach, 1045 dvb->fe[0] = dvb_attach(zl10353_attach,
1028 &em28xx_zl10353_no_i2c_gate_dev, 1046 &em28xx_zl10353_no_i2c_gate_dev,
1029 &dev->i2c_adap); 1047 &dev->i2c_adap[dev->def_i2c_bus]);
1030 if (dvb->fe[0] != NULL) 1048 if (dvb->fe[0] != NULL)
1031 dvb_attach(qt1010_attach, dvb->fe[0], 1049 dvb_attach(qt1010_attach, dvb->fe[0],
1032 &dev->i2c_adap, &em28xx_qt1010_config); 1050 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
1033 break; 1051 break;
1034 case EM2883_BOARD_KWORLD_HYBRID_330U: 1052 case EM2883_BOARD_KWORLD_HYBRID_330U:
1035 case EM2882_BOARD_EVGA_INDTUBE: 1053 case EM2882_BOARD_EVGA_INDTUBE:
1036 dvb->fe[0] = dvb_attach(s5h1409_attach, 1054 dvb->fe[0] = dvb_attach(s5h1409_attach,
1037 &em28xx_s5h1409_with_xc3028, 1055 &em28xx_s5h1409_with_xc3028,
1038 &dev->i2c_adap); 1056 &dev->i2c_adap[dev->def_i2c_bus]);
1039 if (em28xx_attach_xc3028(0x61, dev) < 0) { 1057 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1040 result = -EINVAL; 1058 result = -EINVAL;
1041 goto out_free; 1059 goto out_free;
@@ -1044,10 +1062,10 @@ static int em28xx_dvb_init(struct em28xx *dev)
1044 case EM2882_BOARD_KWORLD_ATSC_315U: 1062 case EM2882_BOARD_KWORLD_ATSC_315U:
1045 dvb->fe[0] = dvb_attach(lgdt330x_attach, 1063 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1046 &em2880_lgdt3303_dev, 1064 &em2880_lgdt3303_dev,
1047 &dev->i2c_adap); 1065 &dev->i2c_adap[dev->def_i2c_bus]);
1048 if (dvb->fe[0] != NULL) { 1066 if (dvb->fe[0] != NULL) {
1049 if (!dvb_attach(simple_tuner_attach, dvb->fe[0], 1067 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1050 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) { 1068 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
1051 result = -EINVAL; 1069 result = -EINVAL;
1052 goto out_free; 1070 goto out_free;
1053 } 1071 }
@@ -1056,7 +1074,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1056 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: 1074 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1057 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E: 1075 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1058 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL, 1076 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1059 &dev->i2c_adap, &dev->udev->dev); 1077 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
1060 if (em28xx_attach_xc3028(0x61, dev) < 0) { 1078 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1061 result = -EINVAL; 1079 result = -EINVAL;
1062 goto out_free; 1080 goto out_free;
@@ -1066,10 +1084,10 @@ static int em28xx_dvb_init(struct em28xx *dev)
1066 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */ 1084 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1067 dvb->fe[0] = dvb_attach(tda10023_attach, 1085 dvb->fe[0] = dvb_attach(tda10023_attach,
1068 &em28xx_tda10023_config, 1086 &em28xx_tda10023_config,
1069 &dev->i2c_adap, 0x48); 1087 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
1070 if (dvb->fe[0]) { 1088 if (dvb->fe[0]) {
1071 if (!dvb_attach(simple_tuner_attach, dvb->fe[0], 1089 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1072 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) { 1090 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
1073 result = -EINVAL; 1091 result = -EINVAL;
1074 goto out_free; 1092 goto out_free;
1075 } 1093 }
@@ -1078,10 +1096,10 @@ static int em28xx_dvb_init(struct em28xx *dev)
1078 case EM2870_BOARD_KWORLD_A340: 1096 case EM2870_BOARD_KWORLD_A340:
1079 dvb->fe[0] = dvb_attach(lgdt3305_attach, 1097 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1080 &em2870_lgdt3304_dev, 1098 &em2870_lgdt3304_dev,
1081 &dev->i2c_adap); 1099 &dev->i2c_adap[dev->def_i2c_bus]);
1082 if (dvb->fe[0] != NULL) 1100 if (dvb->fe[0] != NULL)
1083 dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1101 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1084 &dev->i2c_adap, &kworld_a340_config); 1102 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
1085 break; 1103 break;
1086 case EM28174_BOARD_PCTV_290E: 1104 case EM28174_BOARD_PCTV_290E:
1087 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */ 1105 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
@@ -1089,14 +1107,14 @@ static int em28xx_dvb_init(struct em28xx *dev)
1089 CXD2820R_GPIO_L; 1107 CXD2820R_GPIO_L;
1090 dvb->fe[0] = dvb_attach(cxd2820r_attach, 1108 dvb->fe[0] = dvb_attach(cxd2820r_attach,
1091 &em28xx_cxd2820r_config, 1109 &em28xx_cxd2820r_config,
1092 &dev->i2c_adap, 1110 &dev->i2c_adap[dev->def_i2c_bus],
1093 &dvb->lna_gpio); 1111 &dvb->lna_gpio);
1094 if (dvb->fe[0]) { 1112 if (dvb->fe[0]) {
1095 /* FE 0 attach tuner */ 1113 /* FE 0 attach tuner */
1096 if (!dvb_attach(tda18271_attach, 1114 if (!dvb_attach(tda18271_attach,
1097 dvb->fe[0], 1115 dvb->fe[0],
1098 0x60, 1116 0x60,
1099 &dev->i2c_adap, 1117 &dev->i2c_adap[dev->def_i2c_bus],
1100 &em28xx_cxd2820r_tda18271_config)) { 1118 &em28xx_cxd2820r_tda18271_config)) {
1101 1119
1102 dvb_frontend_detach(dvb->fe[0]); 1120 dvb_frontend_detach(dvb->fe[0]);
@@ -1126,7 +1144,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1126 hauppauge_hvr930c_init(dev); 1144 hauppauge_hvr930c_init(dev);
1127 1145
1128 dvb->fe[0] = dvb_attach(drxk_attach, 1146 dvb->fe[0] = dvb_attach(drxk_attach,
1129 &hauppauge_930c_drxk, &dev->i2c_adap); 1147 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1130 if (!dvb->fe[0]) { 1148 if (!dvb->fe[0]) {
1131 result = -EINVAL; 1149 result = -EINVAL;
1132 goto out_free; 1150 goto out_free;
@@ -1144,7 +1162,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1144 1162
1145 if (dvb->fe[0]->ops.i2c_gate_ctrl) 1163 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1146 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); 1164 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1147 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap, 1165 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1148 &cfg)) { 1166 &cfg)) {
1149 result = -EINVAL; 1167 result = -EINVAL;
1150 goto out_free; 1168 goto out_free;
@@ -1157,7 +1175,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1157 case EM2884_BOARD_TERRATEC_H5: 1175 case EM2884_BOARD_TERRATEC_H5:
1158 terratec_h5_init(dev); 1176 terratec_h5_init(dev);
1159 1177
1160 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap); 1178 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1161 if (!dvb->fe[0]) { 1179 if (!dvb->fe[0]) {
1162 result = -EINVAL; 1180 result = -EINVAL;
1163 goto out_free; 1181 goto out_free;
@@ -1171,7 +1189,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1171 /* Attach tda18271 to DVB-C frontend */ 1189 /* Attach tda18271 to DVB-C frontend */
1172 if (dvb->fe[0]->ops.i2c_gate_ctrl) 1190 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1173 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); 1191 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1174 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) { 1192 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1175 result = -EINVAL; 1193 result = -EINVAL;
1176 goto out_free; 1194 goto out_free;
1177 } 1195 }
@@ -1179,20 +1197,29 @@ static int em28xx_dvb_init(struct em28xx *dev)
1179 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); 1197 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1180 1198
1181 break; 1199 break;
1200 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1201 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1202 &c3tech_duo_mb86a20s_config,
1203 &dev->i2c_adap[dev->def_i2c_bus]);
1204 if (dvb->fe[0] != NULL)
1205 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1206 &dev->i2c_adap[dev->def_i2c_bus],
1207 &c3tech_duo_tda18271_config);
1208 break;
1182 case EM28174_BOARD_PCTV_460E: 1209 case EM28174_BOARD_PCTV_460E:
1183 /* attach demod */ 1210 /* attach demod */
1184 dvb->fe[0] = dvb_attach(tda10071_attach, 1211 dvb->fe[0] = dvb_attach(tda10071_attach,
1185 &em28xx_tda10071_config, &dev->i2c_adap); 1212 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
1186 1213
1187 /* attach SEC */ 1214 /* attach SEC */
1188 if (dvb->fe[0]) 1215 if (dvb->fe[0])
1189 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap, 1216 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1190 &em28xx_a8293_config); 1217 &em28xx_a8293_config);
1191 break; 1218 break;
1192 case EM2874_BOARD_MAXMEDIA_UB425_TC: 1219 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1193 /* attach demodulator */ 1220 /* attach demodulator */
1194 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk, 1221 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1195 &dev->i2c_adap); 1222 &dev->i2c_adap[dev->def_i2c_bus]);
1196 1223
1197 if (dvb->fe[0]) { 1224 if (dvb->fe[0]) {
1198 /* disable I2C-gate */ 1225 /* disable I2C-gate */
@@ -1200,7 +1227,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1200 1227
1201 /* attach tuner */ 1228 /* attach tuner */
1202 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], 1229 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1203 &dev->i2c_adap, 0x60)) { 1230 &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1204 dvb_frontend_detach(dvb->fe[0]); 1231 dvb_frontend_detach(dvb->fe[0]);
1205 result = -EINVAL; 1232 result = -EINVAL;
1206 goto out_free; 1233 goto out_free;
@@ -1218,12 +1245,12 @@ static int em28xx_dvb_init(struct em28xx *dev)
1218 1245
1219 /* attach demodulator */ 1246 /* attach demodulator */
1220 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk, 1247 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1221 &dev->i2c_adap); 1248 &dev->i2c_adap[dev->def_i2c_bus]);
1222 1249
1223 if (dvb->fe[0]) { 1250 if (dvb->fe[0]) {
1224 /* attach tuner */ 1251 /* attach tuner */
1225 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1252 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1226 &dev->i2c_adap, 1253 &dev->i2c_adap[dev->def_i2c_bus],
1227 &em28xx_cxd2820r_tda18271_config)) { 1254 &em28xx_cxd2820r_tda18271_config)) {
1228 dvb_frontend_detach(dvb->fe[0]); 1255 dvb_frontend_detach(dvb->fe[0]);
1229 result = -EINVAL; 1256 result = -EINVAL;
@@ -1236,7 +1263,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1236 1263
1237 /* attach demodulator */ 1264 /* attach demodulator */
1238 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk, 1265 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1239 &dev->i2c_adap); 1266 &dev->i2c_adap[dev->def_i2c_bus]);
1240 if (!dvb->fe[0]) { 1267 if (!dvb->fe[0]) {
1241 result = -EINVAL; 1268 result = -EINVAL;
1242 goto out_free; 1269 goto out_free;
@@ -1244,7 +1271,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1244 1271
1245 /* Attach the demodulator. */ 1272 /* Attach the demodulator. */
1246 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1273 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1247 &dev->i2c_adap, 1274 &dev->i2c_adap[dev->def_i2c_bus],
1248 &em28xx_cxd2820r_tda18271_config)) { 1275 &em28xx_cxd2820r_tda18271_config)) {
1249 result = -EINVAL; 1276 result = -EINVAL;
1250 goto out_free; 1277 goto out_free;
@@ -1255,7 +1282,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1255 1282
1256 /* attach demodulator */ 1283 /* attach demodulator */
1257 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk, 1284 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1258 &dev->i2c_adap); 1285 &dev->i2c_adap[dev->def_i2c_bus]);
1259 if (!dvb->fe[0]) { 1286 if (!dvb->fe[0]) {
1260 result = -EINVAL; 1287 result = -EINVAL;
1261 goto out_free; 1288 goto out_free;
@@ -1263,7 +1290,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1263 1290
1264 /* Attach the demodulator. */ 1291 /* Attach the demodulator. */
1265 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1292 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1266 &dev->i2c_adap, 1293 &dev->i2c_adap[dev->def_i2c_bus],
1267 &em28xx_cxd2820r_tda18271_config)) { 1294 &em28xx_cxd2820r_tda18271_config)) {
1268 result = -EINVAL; 1295 result = -EINVAL;
1269 goto out_free; 1296 goto out_free;
diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c
index 8532c1d4fd46..4851cc2e4a4d 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.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) 2013 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
@@ -41,14 +42,6 @@ static unsigned int i2c_debug;
41module_param(i2c_debug, int, 0644); 42module_param(i2c_debug, int, 0644);
42MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 43MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
43 44
44#define dprintk2(lvl, fmt, args...) \
45do { \
46 if (i2c_debug >= lvl) { \
47 printk(KERN_DEBUG "%s at %s: " fmt, \
48 dev->name, __func__ , ##args); \
49 } \
50} while (0)
51
52/* 45/*
53 * em2800_i2c_send_bytes() 46 * em2800_i2c_send_bytes()
54 * send up to 4 bytes to the em2800 i2c device 47 * send up to 4 bytes to the em2800 i2c device
@@ -76,8 +69,8 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
76 /* trigger write */ 69 /* trigger write */
77 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len); 70 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len);
78 if (ret != 2 + len) { 71 if (ret != 2 + len) {
79 em28xx_warn("failed to trigger write to i2c address 0x%x " 72 em28xx_warn("failed to trigger write to i2c address 0x%x (error=%i)\n",
80 "(error=%i)\n", addr, ret); 73 addr, ret);
81 return (ret < 0) ? ret : -EIO; 74 return (ret < 0) ? ret : -EIO;
82 } 75 }
83 /* wait for completion */ 76 /* wait for completion */
@@ -89,8 +82,8 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
89 } else if (ret == 0x94 + len - 1) { 82 } else if (ret == 0x94 + len - 1) {
90 return -ENODEV; 83 return -ENODEV;
91 } else if (ret < 0) { 84 } else if (ret < 0) {
92 em28xx_warn("failed to get i2c transfer status from " 85 em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n",
93 "bridge register (error=%i)\n", ret); 86 ret);
94 return ret; 87 return ret;
95 } 88 }
96 msleep(5); 89 msleep(5);
@@ -118,8 +111,8 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
118 buf2[0] = addr; 111 buf2[0] = addr;
119 ret = dev->em28xx_write_regs(dev, 0x04, buf2, 2); 112 ret = dev->em28xx_write_regs(dev, 0x04, buf2, 2);
120 if (ret != 2) { 113 if (ret != 2) {
121 em28xx_warn("failed to trigger read from i2c address 0x%x " 114 em28xx_warn("failed to trigger read from i2c address 0x%x (error=%i)\n",
122 "(error=%i)\n", addr, ret); 115 addr, ret);
123 return (ret < 0) ? ret : -EIO; 116 return (ret < 0) ? ret : -EIO;
124 } 117 }
125 118
@@ -132,8 +125,8 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
132 } else if (ret == 0x94 + len - 1) { 125 } else if (ret == 0x94 + len - 1) {
133 return -ENODEV; 126 return -ENODEV;
134 } else if (ret < 0) { 127 } else if (ret < 0) {
135 em28xx_warn("failed to get i2c transfer status from " 128 em28xx_warn("failed to get i2c transfer status from bridge register (error=%i)\n",
136 "bridge register (error=%i)\n", ret); 129 ret);
137 return ret; 130 return ret;
138 } 131 }
139 msleep(5); 132 msleep(5);
@@ -144,9 +137,8 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
144 /* get the received message */ 137 /* get the received message */
145 ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len); 138 ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len);
146 if (ret != len) { 139 if (ret != len) {
147 em28xx_warn("reading from i2c device at 0x%x failed: " 140 em28xx_warn("reading from i2c device at 0x%x failed: couldn't get the received message from the bridge (error=%i)\n",
148 "couldn't get the received message from the bridge " 141 addr, ret);
149 "(error=%i)\n", addr, ret);
150 return (ret < 0) ? ret : -EIO; 142 return (ret < 0) ? ret : -EIO;
151 } 143 }
152 for (i = 0; i < len; i++) 144 for (i = 0; i < len; i++)
@@ -180,19 +172,20 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
180 172
181 if (len < 1 || len > 64) 173 if (len < 1 || len > 64)
182 return -EOPNOTSUPP; 174 return -EOPNOTSUPP;
183 /* NOTE: limited by the USB ctrl message constraints 175 /*
184 * Zero length reads always succeed, even if no device is connected */ 176 * NOTE: limited by the USB ctrl message constraints
177 * Zero length reads always succeed, even if no device is connected
178 */
185 179
186 /* Write to i2c device */ 180 /* Write to i2c device */
187 ret = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len); 181 ret = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
188 if (ret != len) { 182 if (ret != len) {
189 if (ret < 0) { 183 if (ret < 0) {
190 em28xx_warn("writing to i2c device at 0x%x failed " 184 em28xx_warn("writing to i2c device at 0x%x failed (error=%i)\n",
191 "(error=%i)\n", addr, ret); 185 addr, ret);
192 return ret; 186 return ret;
193 } else { 187 } else {
194 em28xx_warn("%i bytes write to i2c device at 0x%x " 188 em28xx_warn("%i bytes write to i2c device at 0x%x requested, but %i bytes written\n",
195 "requested, but %i bytes written\n",
196 len, addr, ret); 189 len, addr, ret);
197 return -EIO; 190 return -EIO;
198 } 191 }
@@ -207,14 +200,16 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
207 } else if (ret == 0x10) { 200 } else if (ret == 0x10) {
208 return -ENODEV; 201 return -ENODEV;
209 } else if (ret < 0) { 202 } else if (ret < 0) {
210 em28xx_warn("failed to read i2c transfer status from " 203 em28xx_warn("failed to read i2c transfer status from bridge (error=%i)\n",
211 "bridge (error=%i)\n", ret); 204 ret);
212 return ret; 205 return ret;
213 } 206 }
214 msleep(5); 207 msleep(5);
215 /* NOTE: do we really have to wait for success ? 208 /*
216 Never seen anything else than 0x00 or 0x10 209 * NOTE: do we really have to wait for success ?
217 (even with high payload) ... */ 210 * Never seen anything else than 0x00 or 0x10
211 * (even with high payload) ...
212 */
218 } 213 }
219 em28xx_warn("write to i2c device at 0x%x timed out\n", addr); 214 em28xx_warn("write to i2c device at 0x%x timed out\n", addr);
220 return -EIO; 215 return -EIO;
@@ -230,29 +225,32 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len)
230 225
231 if (len < 1 || len > 64) 226 if (len < 1 || len > 64)
232 return -EOPNOTSUPP; 227 return -EOPNOTSUPP;
233 /* NOTE: limited by the USB ctrl message constraints 228 /*
234 * Zero length reads always succeed, even if no device is connected */ 229 * NOTE: limited by the USB ctrl message constraints
230 * Zero length reads always succeed, even if no device is connected
231 */
235 232
236 /* Read data from i2c device */ 233 /* Read data from i2c device */
237 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); 234 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len);
238 if (ret != len) { 235 if (ret < 0) {
239 if (ret < 0) { 236 em28xx_warn("reading from i2c device at 0x%x failed (error=%i)\n",
240 em28xx_warn("reading from i2c device at 0x%x failed " 237 addr, ret);
241 "(error=%i)\n", addr, ret); 238 return 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 } 239 }
240 /*
241 * NOTE: some devices with two i2c busses have the bad habit to return 0
242 * bytes if we are on bus B AND there was no write attempt to the
243 * specified slave address before AND no device is present at the
244 * requested slave address.
245 * Anyway, the next check will fail with -ENODEV in this case, so avoid
246 * spamming the system log on device probing and do nothing here.
247 */
250 248
251 /* Check success of the i2c operation */ 249 /* Check success of the i2c operation */
252 ret = dev->em28xx_read_reg(dev, 0x05); 250 ret = dev->em28xx_read_reg(dev, 0x05);
253 if (ret < 0) { 251 if (ret < 0) {
254 em28xx_warn("failed to read i2c transfer status from " 252 em28xx_warn("failed to read i2c transfer status from bridge (error=%i)\n",
255 "bridge (error=%i)\n", ret); 253 ret);
256 return ret; 254 return ret;
257 } 255 }
258 if (ret > 0) { 256 if (ret > 0) {
@@ -282,77 +280,254 @@ static int em28xx_i2c_check_for_device(struct em28xx *dev, u16 addr)
282} 280}
283 281
284/* 282/*
283 * em25xx_bus_B_send_bytes
284 * write bytes to the i2c device
285 */
286static int em25xx_bus_B_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
287 u16 len)
288{
289 int ret;
290
291 if (len < 1 || len > 64)
292 return -EOPNOTSUPP;
293 /*
294 * NOTE: limited by the USB ctrl message constraints
295 * Zero length reads always succeed, even if no device is connected
296 */
297
298 /* Set register and write value */
299 ret = dev->em28xx_write_regs_req(dev, 0x06, addr, buf, len);
300 if (ret != len) {
301 if (ret < 0) {
302 em28xx_warn("writing to i2c device at 0x%x failed (error=%i)\n",
303 addr, ret);
304 return ret;
305 } else {
306 em28xx_warn("%i bytes write to i2c device at 0x%x requested, but %i bytes written\n",
307 len, addr, ret);
308 return -EIO;
309 }
310 }
311 /* Check success */
312 ret = dev->em28xx_read_reg_req(dev, 0x08, 0x0000);
313 /*
314 * NOTE: the only error we've seen so far is
315 * 0x01 when the slave device is not present
316 */
317 if (!ret)
318 return len;
319 else if (ret > 0)
320 return -ENODEV;
321
322 return ret;
323 /*
324 * NOTE: With chip types (other chip IDs) which actually don't support
325 * this operation, it seems to succeed ALWAYS ! (even if there is no
326 * slave device or even no second i2c bus provided)
327 */
328}
329
330/*
331 * em25xx_bus_B_recv_bytes
332 * read bytes from the i2c device
333 */
334static int em25xx_bus_B_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf,
335 u16 len)
336{
337 int ret;
338
339 if (len < 1 || len > 64)
340 return -EOPNOTSUPP;
341 /*
342 * NOTE: limited by the USB ctrl message constraints
343 * Zero length reads always succeed, even if no device is connected
344 */
345
346 /* Read value */
347 ret = dev->em28xx_read_reg_req_len(dev, 0x06, addr, buf, len);
348 if (ret < 0) {
349 em28xx_warn("reading from i2c device at 0x%x failed (error=%i)\n",
350 addr, ret);
351 return ret;
352 }
353 /*
354 * NOTE: some devices with two i2c busses have the bad habit to return 0
355 * bytes if we are on bus B AND there was no write attempt to the
356 * specified slave address before AND no device is present at the
357 * requested slave address.
358 * Anyway, the next check will fail with -ENODEV in this case, so avoid
359 * spamming the system log on device probing and do nothing here.
360 */
361
362 /* Check success */
363 ret = dev->em28xx_read_reg_req(dev, 0x08, 0x0000);
364 /*
365 * NOTE: the only error we've seen so far is
366 * 0x01 when the slave device is not present
367 */
368 if (!ret)
369 return len;
370 else if (ret > 0)
371 return -ENODEV;
372
373 return ret;
374 /*
375 * NOTE: With chip types (other chip IDs) which actually don't support
376 * this operation, it seems to succeed ALWAYS ! (even if there is no
377 * slave device or even no second i2c bus provided)
378 */
379}
380
381/*
382 * em25xx_bus_B_check_for_device()
383 * check if there is a i2c device at the supplied address
384 */
385static int em25xx_bus_B_check_for_device(struct em28xx *dev, u16 addr)
386{
387 u8 buf;
388 int ret;
389
390 ret = em25xx_bus_B_recv_bytes(dev, addr, &buf, 1);
391 if (ret < 0)
392 return ret;
393
394 return 0;
395 /*
396 * NOTE: With chips which do not support this operation,
397 * it seems to succeed ALWAYS ! (even if no device connected)
398 */
399}
400
401static inline int i2c_check_for_device(struct em28xx_i2c_bus *i2c_bus, u16 addr)
402{
403 struct em28xx *dev = i2c_bus->dev;
404 int rc = -EOPNOTSUPP;
405
406 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX)
407 rc = em28xx_i2c_check_for_device(dev, addr);
408 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800)
409 rc = em2800_i2c_check_for_device(dev, addr);
410 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
411 rc = em25xx_bus_B_check_for_device(dev, addr);
412 if (rc == -ENODEV) {
413 if (i2c_debug)
414 printk(" no device\n");
415 }
416 return rc;
417}
418
419static inline int i2c_recv_bytes(struct em28xx_i2c_bus *i2c_bus,
420 struct i2c_msg msg)
421{
422 struct em28xx *dev = i2c_bus->dev;
423 u16 addr = msg.addr << 1;
424 int byte, rc = -EOPNOTSUPP;
425
426 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX)
427 rc = em28xx_i2c_recv_bytes(dev, addr, msg.buf, msg.len);
428 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800)
429 rc = em2800_i2c_recv_bytes(dev, addr, msg.buf, msg.len);
430 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
431 rc = em25xx_bus_B_recv_bytes(dev, addr, msg.buf, msg.len);
432 if (i2c_debug) {
433 for (byte = 0; byte < msg.len; byte++)
434 printk(" %02x", msg.buf[byte]);
435 }
436 return rc;
437}
438
439static inline int i2c_send_bytes(struct em28xx_i2c_bus *i2c_bus,
440 struct i2c_msg msg, int stop)
441{
442 struct em28xx *dev = i2c_bus->dev;
443 u16 addr = msg.addr << 1;
444 int byte, rc = -EOPNOTSUPP;
445
446 if (i2c_debug) {
447 for (byte = 0; byte < msg.len; byte++)
448 printk(" %02x", msg.buf[byte]);
449 }
450 if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX)
451 rc = em28xx_i2c_send_bytes(dev, addr, msg.buf, msg.len, stop);
452 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800)
453 rc = em2800_i2c_send_bytes(dev, addr, msg.buf, msg.len);
454 else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
455 rc = em25xx_bus_B_send_bytes(dev, addr, msg.buf, msg.len);
456 return rc;
457}
458
459/*
285 * em28xx_i2c_xfer() 460 * em28xx_i2c_xfer()
286 * the main i2c transfer function 461 * the main i2c transfer function
287 */ 462 */
288static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap, 463static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
289 struct i2c_msg msgs[], int num) 464 struct i2c_msg msgs[], int num)
290{ 465{
291 struct em28xx *dev = i2c_adap->algo_data; 466 struct em28xx_i2c_bus *i2c_bus = i2c_adap->algo_data;
292 int addr, rc, i, byte; 467 struct em28xx *dev = i2c_bus->dev;
468 unsigned bus = i2c_bus->bus;
469 int addr, rc, i;
470 u8 reg;
471
472 rc = rt_mutex_trylock(&dev->i2c_bus_lock);
473 if (rc < 0)
474 return rc;
475
476 /* Switch I2C bus if needed */
477 if (bus != dev->cur_i2c_bus &&
478 i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) {
479 if (bus == 1)
480 reg = EM2874_I2C_SECONDARY_BUS_SELECT;
481 else
482 reg = 0;
483 em28xx_write_reg_bits(dev, EM28XX_R06_I2C_CLK, reg,
484 EM2874_I2C_SECONDARY_BUS_SELECT);
485 dev->cur_i2c_bus = bus;
486 }
293 487
294 if (num <= 0) 488 if (num <= 0) {
489 rt_mutex_unlock(&dev->i2c_bus_lock);
295 return 0; 490 return 0;
491 }
296 for (i = 0; i < num; i++) { 492 for (i = 0; i < num; i++) {
297 addr = msgs[i].addr << 1; 493 addr = msgs[i].addr << 1;
298 dprintk2(2, "%s %s addr=%x len=%d:", 494 if (i2c_debug)
299 (msgs[i].flags & I2C_M_RD) ? "read" : "write", 495 printk(KERN_DEBUG "%s at %s: %s %s addr=%02x len=%d:",
300 i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); 496 dev->name, __func__ ,
497 (msgs[i].flags & I2C_M_RD) ? "read" : "write",
498 i == num - 1 ? "stop" : "nonstop",
499 addr, msgs[i].len);
301 if (!msgs[i].len) { /* no len: check only for device presence */ 500 if (!msgs[i].len) { /* no len: check only for device presence */
302 if (dev->board.is_em2800) 501 rc = i2c_check_for_device(i2c_bus, addr);
303 rc = em2800_i2c_check_for_device(dev, addr);
304 else
305 rc = em28xx_i2c_check_for_device(dev, addr);
306 if (rc == -ENODEV) { 502 if (rc == -ENODEV) {
307 if (i2c_debug >= 2) 503 rt_mutex_unlock(&dev->i2c_bus_lock);
308 printk(" no device\n");
309 return rc; 504 return rc;
310 } 505 }
311 } else if (msgs[i].flags & I2C_M_RD) { 506 } else if (msgs[i].flags & I2C_M_RD) {
312 /* read bytes */ 507 /* read bytes */
313 if (dev->board.is_em2800) 508 rc = i2c_recv_bytes(i2c_bus, msgs[i]);
314 rc = em2800_i2c_recv_bytes(dev, addr,
315 msgs[i].buf,
316 msgs[i].len);
317 else
318 rc = em28xx_i2c_recv_bytes(dev, addr,
319 msgs[i].buf,
320 msgs[i].len);
321 if (i2c_debug >= 2) {
322 for (byte = 0; byte < msgs[i].len; byte++)
323 printk(" %02x", msgs[i].buf[byte]);
324 }
325 } else { 509 } else {
326 /* write bytes */ 510 /* write bytes */
327 if (i2c_debug >= 2) { 511 rc = i2c_send_bytes(i2c_bus, msgs[i], i == num - 1);
328 for (byte = 0; byte < msgs[i].len; byte++)
329 printk(" %02x", msgs[i].buf[byte]);
330 }
331 if (dev->board.is_em2800)
332 rc = em2800_i2c_send_bytes(dev, addr,
333 msgs[i].buf,
334 msgs[i].len);
335 else
336 rc = em28xx_i2c_send_bytes(dev, addr,
337 msgs[i].buf,
338 msgs[i].len,
339 i == num - 1);
340 } 512 }
341 if (rc < 0) { 513 if (rc < 0) {
342 if (i2c_debug >= 2) 514 if (i2c_debug)
343 printk(" ERROR: %i\n", rc); 515 printk(" ERROR: %i\n", rc);
516 rt_mutex_unlock(&dev->i2c_bus_lock);
344 return rc; 517 return rc;
345 } 518 }
346 if (i2c_debug >= 2) 519 if (i2c_debug)
347 printk("\n"); 520 printk("\n");
348 } 521 }
349 522
523 rt_mutex_unlock(&dev->i2c_bus_lock);
350 return num; 524 return num;
351} 525}
352 526
353/* based on linux/sunrpc/svcauth.h and linux/hash.h 527/*
528 * based on linux/sunrpc/svcauth.h and linux/hash.h
354 * The original hash function returns a different value, if arch is x86_64 529 * The original hash function returns a different value, if arch is x86_64
355 * or i386. 530 * or i386.
356 */ 531 */
357static inline unsigned long em28xx_hash_mem(char *buf, int length, int bits) 532static inline unsigned long em28xx_hash_mem(char *buf, int length, int bits)
358{ 533{
@@ -375,127 +550,230 @@ static inline unsigned long em28xx_hash_mem(char *buf, int length, int bits)
375 return (hash >> (32 - bits)) & 0xffffffffUL; 550 return (hash >> (32 - bits)) & 0xffffffffUL;
376} 551}
377 552
378static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) 553/*
554 * Helper function to read data blocks from i2c clients with 8 or 16 bit
555 * address width, 8 bit register width and auto incrementation been activated
556 */
557static int em28xx_i2c_read_block(struct em28xx *dev, unsigned bus, u16 addr,
558 bool addr_w16, u16 len, u8 *data)
379{ 559{
380 unsigned char buf, *p = eedata; 560 int remain = len, rsize, rsize_max, ret;
381 struct em28xx_eeprom *em_eeprom = (void *)eedata; 561 u8 buf[2];
382 int i, err, size = len, block, block_max; 562
383 563 /* Sanity check */
384 if (dev->chip_id == CHIP_ID_EM2874 || 564 if (addr + remain > (addr_w16 * 0xff00 + 0xff + 1))
385 dev->chip_id == CHIP_ID_EM28174 || 565 return -EINVAL;
386 dev->chip_id == CHIP_ID_EM2884) { 566 /* Select address */
387 /* Empia switched to a 16-bit addressable eeprom in newer 567 buf[0] = addr >> 8;
388 devices. While we could certainly write a routine to read 568 buf[1] = addr & 0xff;
389 the eeprom, there is nothing of use in there that cannot be 569 ret = i2c_master_send(&dev->i2c_client[bus], buf + !addr_w16, 1 + addr_w16);
390 accessed through registers, and there is the risk that we 570 if (ret < 0)
391 could corrupt the eeprom (since a 16-bit read call is 571 return ret;
392 interpreted as a write call by 8-bit eeproms). 572 /* Read data */
393 */ 573 if (dev->board.is_em2800)
394 return 0; 574 rsize_max = 4;
575 else
576 rsize_max = 64;
577 while (remain > 0) {
578 if (remain > rsize_max)
579 rsize = rsize_max;
580 else
581 rsize = remain;
582
583 ret = i2c_master_recv(&dev->i2c_client[bus], data, rsize);
584 if (ret < 0)
585 return ret;
586
587 remain -= rsize;
588 data += rsize;
395 } 589 }
396 590
397 dev->i2c_client.addr = 0xa0 >> 1; 591 return len;
592}
593
594static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned bus,
595 u8 **eedata, u16 *eedata_len)
596{
597 const u16 len = 256;
598 /*
599 * FIXME common length/size for bytes to read, to display, hash
600 * calculation and returned device dataset. Simplifies the code a lot,
601 * but we might have to deal with multiple sizes in the future !
602 */
603 int i, err;
604 struct em28xx_eeprom *dev_config;
605 u8 buf, *data;
606
607 *eedata = NULL;
608 *eedata_len = 0;
609
610 /* EEPROM is always on i2c bus 0 on all known devices. */
611
612 dev->i2c_client[bus].addr = 0xa0 >> 1;
398 613
399 /* Check if board has eeprom */ 614 /* Check if board has eeprom */
400 err = i2c_master_recv(&dev->i2c_client, &buf, 0); 615 err = i2c_master_recv(&dev->i2c_client[bus], &buf, 0);
401 if (err < 0) { 616 if (err < 0) {
402 em28xx_errdev("board has no eeprom\n"); 617 em28xx_info("board has no eeprom\n");
403 memset(eedata, 0, len);
404 return -ENODEV; 618 return -ENODEV;
405 } 619 }
406 620
407 buf = 0; 621 data = kzalloc(len, GFP_KERNEL);
408 622 if (data == NULL)
409 err = i2c_master_send(&dev->i2c_client, &buf, 1); 623 return -ENOMEM;
410 if (err != 1) { 624
411 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", 625 /* Read EEPROM content */
412 dev->name, err); 626 err = em28xx_i2c_read_block(dev, bus, 0x0000,
413 return err; 627 dev->eeprom_addrwidth_16bit,
628 len, data);
629 if (err != len) {
630 em28xx_errdev("failed to read eeprom (err=%d)\n", err);
631 goto error;
414 } 632 }
415 633
416 if (dev->board.is_em2800) 634 /* Display eeprom content */
417 block_max = 4;
418 else
419 block_max = 64;
420
421 while (size > 0) {
422 if (size > block_max)
423 block = block_max;
424 else
425 block = size;
426
427 if (block !=
428 (err = i2c_master_recv(&dev->i2c_client, p, block))) {
429 printk(KERN_WARNING
430 "%s: i2c eeprom read error (err=%d)\n",
431 dev->name, err);
432 return err;
433 }
434 size -= block;
435 p += block;
436 }
437 for (i = 0; i < len; i++) { 635 for (i = 0; i < len; i++) {
438 if (0 == (i % 16)) 636 if (0 == (i % 16)) {
439 printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i); 637 if (dev->eeprom_addrwidth_16bit)
440 printk(" %02x", eedata[i]); 638 em28xx_info("i2c eeprom %04x:", i);
639 else
640 em28xx_info("i2c eeprom %02x:", i);
641 }
642 printk(" %02x", data[i]);
441 if (15 == (i % 16)) 643 if (15 == (i % 16))
442 printk("\n"); 644 printk("\n");
443 } 645 }
646 if (dev->eeprom_addrwidth_16bit)
647 em28xx_info("i2c eeprom %04x: ... (skipped)\n", i);
648
649 if (dev->eeprom_addrwidth_16bit &&
650 data[0] == 0x26 && data[3] == 0x00) {
651 /* new eeprom format; size 4-64kb */
652 u16 mc_start;
653 u16 hwconf_offset;
654
655 dev->hash = em28xx_hash_mem(data, len, 32);
656 mc_start = (data[1] << 8) + 4; /* usually 0x0004 */
657
658 em28xx_info("EEPROM ID = %02x %02x %02x %02x, EEPROM hash = 0x%08lx\n",
659 data[0], data[1], data[2], data[3], dev->hash);
660 em28xx_info("EEPROM info:\n");
661 em28xx_info("\tmicrocode start address = 0x%04x, boot configuration = 0x%02x\n",
662 mc_start, data[2]);
663 /*
664 * boot configuration (address 0x0002):
665 * [0] microcode download speed: 1 = 400 kHz; 0 = 100 kHz
666 * [1] always selects 12 kb RAM
667 * [2] USB device speed: 1 = force Full Speed; 0 = auto detect
668 * [4] 1 = force fast mode and no suspend for device testing
669 * [5:7] USB PHY tuning registers; determined by device
670 * characterization
671 */
672
673 /*
674 * Read hardware config dataset offset from address
675 * (microcode start + 46)
676 */
677 err = em28xx_i2c_read_block(dev, bus, mc_start + 46, 1, 2,
678 data);
679 if (err != 2) {
680 em28xx_errdev("failed to read hardware configuration data from eeprom (err=%d)\n",
681 err);
682 goto error;
683 }
444 684
445 if (em_eeprom->id == 0x9567eb1a) 685 /* Calculate hardware config dataset start address */
446 dev->hash = em28xx_hash_mem(eedata, len, 32); 686 hwconf_offset = mc_start + data[0] + (data[1] << 8);
687
688 /* Read hardware config dataset */
689 /*
690 * NOTE: the microcode copy can be multiple pages long, but
691 * we assume the hardware config dataset is the same as in
692 * the old eeprom and not longer than 256 bytes.
693 * tveeprom is currently also limited to 256 bytes.
694 */
695 err = em28xx_i2c_read_block(dev, bus, hwconf_offset, 1, len,
696 data);
697 if (err != len) {
698 em28xx_errdev("failed to read hardware configuration data from eeprom (err=%d)\n",
699 err);
700 goto error;
701 }
447 702
448 printk(KERN_INFO "%s: EEPROM ID= 0x%08x, EEPROM hash = 0x%08lx\n", 703 /* Verify hardware config dataset */
449 dev->name, em_eeprom->id, dev->hash); 704 /* NOTE: not all devices provide this type of dataset */
705 if (data[0] != 0x1a || data[1] != 0xeb ||
706 data[2] != 0x67 || data[3] != 0x95) {
707 em28xx_info("\tno hardware configuration dataset found in eeprom\n");
708 kfree(data);
709 return 0;
710 }
450 711
451 printk(KERN_INFO "%s: EEPROM info:\n", dev->name); 712 /* TODO: decrypt eeprom data for camera bridges (em25xx, em276x+) */
713
714 } else if (!dev->eeprom_addrwidth_16bit &&
715 data[0] == 0x1a && data[1] == 0xeb &&
716 data[2] == 0x67 && data[3] == 0x95) {
717 dev->hash = em28xx_hash_mem(data, len, 32);
718 em28xx_info("EEPROM ID = %02x %02x %02x %02x, EEPROM hash = 0x%08lx\n",
719 data[0], data[1], data[2], data[3], dev->hash);
720 em28xx_info("EEPROM info:\n");
721 } else {
722 em28xx_info("unknown eeprom format or eeprom corrupted !\n");
723 err = -ENODEV;
724 goto error;
725 }
452 726
453 switch (em_eeprom->chip_conf >> 4 & 0x3) { 727 *eedata = data;
728 *eedata_len = len;
729 dev_config = (void *)eedata;
730
731 switch (le16_to_cpu(dev_config->chip_conf) >> 4 & 0x3) {
454 case 0: 732 case 0:
455 printk(KERN_INFO "%s:\tNo audio on board.\n", dev->name); 733 em28xx_info("\tNo audio on board.\n");
456 break; 734 break;
457 case 1: 735 case 1:
458 printk(KERN_INFO "%s:\tAC97 audio (5 sample rates)\n", 736 em28xx_info("\tAC97 audio (5 sample rates)\n");
459 dev->name);
460 break; 737 break;
461 case 2: 738 case 2:
462 printk(KERN_INFO "%s:\tI2S audio, sample rate=32k\n", 739 em28xx_info("\tI2S audio, sample rate=32k\n");
463 dev->name);
464 break; 740 break;
465 case 3: 741 case 3:
466 printk(KERN_INFO "%s:\tI2S audio, 3 sample rates\n", 742 em28xx_info("\tI2S audio, 3 sample rates\n");
467 dev->name);
468 break; 743 break;
469 } 744 }
470 745
471 if (em_eeprom->chip_conf & 1 << 3) 746 if (le16_to_cpu(dev_config->chip_conf) & 1 << 3)
472 printk(KERN_INFO "%s:\tUSB Remote wakeup capable\n", dev->name); 747 em28xx_info("\tUSB Remote wakeup capable\n");
473 748
474 if (em_eeprom->chip_conf & 1 << 2) 749 if (le16_to_cpu(dev_config->chip_conf) & 1 << 2)
475 printk(KERN_INFO "%s:\tUSB Self power capable\n", dev->name); 750 em28xx_info("\tUSB Self power capable\n");
476 751
477 switch (em_eeprom->chip_conf & 0x3) { 752 switch (le16_to_cpu(dev_config->chip_conf) & 0x3) {
478 case 0: 753 case 0:
479 printk(KERN_INFO "%s:\t500mA max power\n", dev->name); 754 em28xx_info("\t500mA max power\n");
480 break; 755 break;
481 case 1: 756 case 1:
482 printk(KERN_INFO "%s:\t400mA max power\n", dev->name); 757 em28xx_info("\t400mA max power\n");
483 break; 758 break;
484 case 2: 759 case 2:
485 printk(KERN_INFO "%s:\t300mA max power\n", dev->name); 760 em28xx_info("\t300mA max power\n");
486 break; 761 break;
487 case 3: 762 case 3:
488 printk(KERN_INFO "%s:\t200mA max power\n", dev->name); 763 em28xx_info("\t200mA max power\n");
489 break; 764 break;
490 } 765 }
491 printk(KERN_INFO "%s:\tTable at 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n", 766 em28xx_info("\tTable at offset 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n",
492 dev->name, 767 dev_config->string_idx_table,
493 em_eeprom->string_idx_table, 768 le16_to_cpu(dev_config->string1),
494 em_eeprom->string1, 769 le16_to_cpu(dev_config->string2),
495 em_eeprom->string2, 770 le16_to_cpu(dev_config->string3));
496 em_eeprom->string3);
497 771
498 return 0; 772 return 0;
773
774error:
775 kfree(data);
776 return err;
499} 777}
500 778
501/* ----------------------------------------------------------- */ 779/* ----------------------------------------------------------- */
@@ -503,13 +781,20 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
503/* 781/*
504 * functionality() 782 * functionality()
505 */ 783 */
506static u32 functionality(struct i2c_adapter *adap) 784static u32 functionality(struct i2c_adapter *i2c_adap)
507{ 785{
508 struct em28xx *dev = adap->algo_data; 786 struct em28xx_i2c_bus *i2c_bus = i2c_adap->algo_data;
509 u32 func_flags = I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 787
510 if (dev->board.is_em2800) 788 if ((i2c_bus->algo_type == EM28XX_I2C_ALGO_EM28XX) ||
511 func_flags &= ~I2C_FUNC_SMBUS_WRITE_BLOCK_DATA; 789 (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)) {
512 return func_flags; 790 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
791 } else if (i2c_bus->algo_type == EM28XX_I2C_ALGO_EM2800) {
792 return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL) &
793 ~I2C_FUNC_SMBUS_WRITE_BLOCK_DATA;
794 }
795
796 WARN(1, "Unknown i2c bus algorithm.\n");
797 return 0;
513} 798}
514 799
515static struct i2c_algorithm em28xx_algo = { 800static struct i2c_algorithm em28xx_algo = {
@@ -556,7 +841,7 @@ static char *i2c_devs[128] = {
556 * do_i2c_scan() 841 * do_i2c_scan()
557 * check i2c address range for devices 842 * check i2c address range for devices
558 */ 843 */
559void em28xx_do_i2c_scan(struct em28xx *dev) 844void em28xx_do_i2c_scan(struct em28xx *dev, unsigned bus)
560{ 845{
561 u8 i2c_devicelist[128]; 846 u8 i2c_devicelist[128];
562 unsigned char buf; 847 unsigned char buf;
@@ -565,55 +850,68 @@ void em28xx_do_i2c_scan(struct em28xx *dev)
565 memset(i2c_devicelist, 0, ARRAY_SIZE(i2c_devicelist)); 850 memset(i2c_devicelist, 0, ARRAY_SIZE(i2c_devicelist));
566 851
567 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) { 852 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
568 dev->i2c_client.addr = i; 853 dev->i2c_client[bus].addr = i;
569 rc = i2c_master_recv(&dev->i2c_client, &buf, 0); 854 rc = i2c_master_recv(&dev->i2c_client[bus], &buf, 0);
570 if (rc < 0) 855 if (rc < 0)
571 continue; 856 continue;
572 i2c_devicelist[i] = i; 857 i2c_devicelist[i] = i;
573 printk(KERN_INFO "%s: found i2c device @ 0x%x [%s]\n", 858 em28xx_info("found i2c device @ 0x%x on bus %d [%s]\n",
574 dev->name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); 859 i << 1, bus, i2c_devs[i] ? i2c_devs[i] : "???");
575 } 860 }
576 861
577 dev->i2c_hash = em28xx_hash_mem(i2c_devicelist, 862 if (bus == dev->def_i2c_bus)
578 ARRAY_SIZE(i2c_devicelist), 32); 863 dev->i2c_hash = em28xx_hash_mem(i2c_devicelist,
864 ARRAY_SIZE(i2c_devicelist), 32);
579} 865}
580 866
581/* 867/*
582 * em28xx_i2c_register() 868 * em28xx_i2c_register()
583 * register i2c bus 869 * register i2c bus
584 */ 870 */
585int em28xx_i2c_register(struct em28xx *dev) 871int em28xx_i2c_register(struct em28xx *dev, unsigned bus,
872 enum em28xx_i2c_algo_type algo_type)
586{ 873{
587 int retval; 874 int retval;
588 875
589 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg); 876 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
590 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req); 877 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
591 dev->i2c_adap = em28xx_adap_template;
592 dev->i2c_adap.dev.parent = &dev->udev->dev;
593 strcpy(dev->i2c_adap.name, dev->name);
594 dev->i2c_adap.algo_data = dev;
595 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
596 878
597 retval = i2c_add_adapter(&dev->i2c_adap); 879 if (bus >= NUM_I2C_BUSES)
880 return -ENODEV;
881
882 dev->i2c_adap[bus] = em28xx_adap_template;
883 dev->i2c_adap[bus].dev.parent = &dev->udev->dev;
884 strcpy(dev->i2c_adap[bus].name, dev->name);
885
886 dev->i2c_bus[bus].bus = bus;
887 dev->i2c_bus[bus].algo_type = algo_type;
888 dev->i2c_bus[bus].dev = dev;
889 dev->i2c_adap[bus].algo_data = &dev->i2c_bus[bus];
890 i2c_set_adapdata(&dev->i2c_adap[bus], &dev->v4l2_dev);
891
892 retval = i2c_add_adapter(&dev->i2c_adap[bus]);
598 if (retval < 0) { 893 if (retval < 0) {
599 em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n", 894 em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
600 __func__, retval); 895 __func__, retval);
601 return retval; 896 return retval;
602 } 897 }
603 898
604 dev->i2c_client = em28xx_client_template; 899 dev->i2c_client[bus] = em28xx_client_template;
605 dev->i2c_client.adapter = &dev->i2c_adap; 900 dev->i2c_client[bus].adapter = &dev->i2c_adap[bus];
606 901
607 retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); 902 /* Up to now, all eeproms are at bus 0 */
608 if ((retval < 0) && (retval != -ENODEV)) { 903 if (!bus) {
609 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n", 904 retval = em28xx_i2c_eeprom(dev, bus, &dev->eedata, &dev->eedata_len);
610 __func__, retval); 905 if ((retval < 0) && (retval != -ENODEV)) {
906 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
907 __func__, retval);
611 908
612 return retval; 909 return retval;
910 }
613 } 911 }
614 912
615 if (i2c_scan) 913 if (i2c_scan)
616 em28xx_do_i2c_scan(dev); 914 em28xx_do_i2c_scan(dev, bus);
617 915
618 return 0; 916 return 0;
619} 917}
@@ -622,8 +920,11 @@ int em28xx_i2c_register(struct em28xx *dev)
622 * em28xx_i2c_unregister() 920 * em28xx_i2c_unregister()
623 * unregister i2c_bus 921 * unregister i2c_bus
624 */ 922 */
625int em28xx_i2c_unregister(struct em28xx *dev) 923int em28xx_i2c_unregister(struct em28xx *dev, unsigned bus)
626{ 924{
627 i2c_del_adapter(&dev->i2c_adap); 925 if (bus >= NUM_I2C_BUSES)
926 return -ENODEV;
927
928 i2c_del_adapter(&dev->i2c_adap[bus]);
628 return 0; 929 return 0;
629} 930}
diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c
index 1bef990b3f18..466b19d0d767 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -280,11 +280,12 @@ static int em2874_polling_getkey(struct em28xx_IR *ir,
280 280
281static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir) 281static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
282{ 282{
283 struct em28xx *dev = ir->dev;
283 static u32 ir_key; 284 static u32 ir_key;
284 int rc; 285 int rc;
285 struct i2c_client client; 286 struct i2c_client client;
286 287
287 client.adapter = &ir->dev->i2c_adap; 288 client.adapter = &ir->dev->i2c_adap[dev->def_i2c_bus];
288 client.addr = ir->i2c_dev_addr; 289 client.addr = ir->i2c_dev_addr;
289 290
290 rc = ir->get_key_i2c(&client, &ir_key); 291 rc = ir->get_key_i2c(&client, &ir_key);
@@ -461,7 +462,7 @@ static int em28xx_probe_i2c_ir(struct em28xx *dev)
461 }; 462 };
462 463
463 while (addr_list[i] != I2C_CLIENT_END) { 464 while (addr_list[i] != I2C_CLIENT_END) {
464 if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1) 465 if (i2c_probe_func_quick_read(&dev->i2c_adap[dev->def_i2c_bus], addr_list[i]) == 1)
465 return addr_list[i]; 466 return addr_list[i];
466 i++; 467 i++;
467 } 468 }
diff --git a/drivers/media/usb/em28xx/em28xx-reg.h b/drivers/media/usb/em28xx/em28xx-reg.h
index 885089e22bcd..622871db04aa 100644
--- a/drivers/media/usb/em28xx/em28xx-reg.h
+++ b/drivers/media/usb/em28xx/em28xx-reg.h
@@ -48,7 +48,7 @@
48#define EM28XX_CHIPCFG2_TS_PACKETSIZE_752 0x03 48#define EM28XX_CHIPCFG2_TS_PACKETSIZE_752 0x03
49 49
50 50
51 /* GPIO/GPO registers */ 51/* GPIO/GPO registers */
52#define EM2880_R04_GPO 0x04 /* em2880-em2883 only */ 52#define EM2880_R04_GPO 0x04 /* em2880-em2883 only */
53#define EM28XX_R08_GPIO 0x08 /* em2820 or upper */ 53#define EM28XX_R08_GPIO 0x08 /* em2820 or upper */
54 54
@@ -120,12 +120,23 @@
120#define EM28XX_R1E_CWIDTH 0x1e 120#define EM28XX_R1E_CWIDTH 0x1e
121#define EM28XX_R1F_CHEIGHT 0x1f 121#define EM28XX_R1F_CHEIGHT 0x1f
122 122
123#define EM28XX_R20_YGAIN 0x20 123#define EM28XX_R20_YGAIN 0x20 /* contrast [0:4] */
124#define EM28XX_R21_YOFFSET 0x21 124#define CONTRAST_DEFAULT 0x10
125#define EM28XX_R22_UVGAIN 0x22 125
126#define EM28XX_R23_UOFFSET 0x23 126#define EM28XX_R21_YOFFSET 0x21 /* brightness */ /* signed */
127#define EM28XX_R24_VOFFSET 0x24 127#define BRIGHTNESS_DEFAULT 0x00
128#define EM28XX_R25_SHARPNESS 0x25 128
129#define EM28XX_R22_UVGAIN 0x22 /* saturation [0:4] */
130#define SATURATION_DEFAULT 0x10
131
132#define EM28XX_R23_UOFFSET 0x23 /* blue balance */ /* signed */
133#define BLUE_BALANCE_DEFAULT 0x00
134
135#define EM28XX_R24_VOFFSET 0x24 /* red balance */ /* signed */
136#define RED_BALANCE_DEFAULT 0x00
137
138#define EM28XX_R25_SHARPNESS 0x25 /* sharpness [0:4] */
139#define SHARPNESS_DEFAULT 0x00
129 140
130#define EM28XX_R26_COMPR 0x26 141#define EM28XX_R26_COMPR 0x26
131#define EM28XX_R27_OUTFMT 0x27 142#define EM28XX_R27_OUTFMT 0x27
@@ -152,8 +163,17 @@
152#define EM28XX_R31_HSCALEHIGH 0x31 163#define EM28XX_R31_HSCALEHIGH 0x31
153#define EM28XX_R32_VSCALELOW 0x32 164#define EM28XX_R32_VSCALELOW 0x32
154#define EM28XX_R33_VSCALEHIGH 0x33 165#define EM28XX_R33_VSCALEHIGH 0x33
166#define EM28XX_HVSCALE_MAX 0x3fff /* => 20% */
167
155#define EM28XX_R34_VBI_START_H 0x34 168#define EM28XX_R34_VBI_START_H 0x34
156#define EM28XX_R35_VBI_START_V 0x35 169#define EM28XX_R35_VBI_START_V 0x35
170/*
171 * NOTE: the EM276x (and EM25xx, EM277x/8x ?) (camera bridges) use these
172 * registers for a different unknown purpose.
173 * => register 0x34 is set to capture width / 16
174 * => register 0x35 is set to capture height / 16
175 */
176
157#define EM28XX_R36_VBI_WIDTH 0x36 177#define EM28XX_R36_VBI_WIDTH 0x36
158#define EM28XX_R37_VBI_HEIGHT 0x37 178#define EM28XX_R37_VBI_HEIGHT 0x37
159 179
@@ -206,6 +226,7 @@ enum em28xx_chip_id {
206 CHIP_ID_EM2860 = 34, 226 CHIP_ID_EM2860 = 34,
207 CHIP_ID_EM2870 = 35, 227 CHIP_ID_EM2870 = 35,
208 CHIP_ID_EM2883 = 36, 228 CHIP_ID_EM2883 = 36,
229 CHIP_ID_EM2765 = 54,
209 CHIP_ID_EM2874 = 65, 230 CHIP_ID_EM2874 = 65,
210 CHIP_ID_EM2884 = 68, 231 CHIP_ID_EM2884 = 68,
211 CHIP_ID_EM28174 = 113, 232 CHIP_ID_EM28174 = 113,
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 32bd7de5dec1..32d60e5546bc 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -52,7 +52,7 @@
52 52
53#define DRIVER_DESC "Empia em28xx based USB video device driver" 53#define DRIVER_DESC "Empia em28xx based USB video device driver"
54 54
55#define EM28XX_VERSION "0.1.3" 55#define EM28XX_VERSION "0.2.0"
56 56
57#define em28xx_videodbg(fmt, arg...) do {\ 57#define em28xx_videodbg(fmt, arg...) do {\
58 if (video_debug) \ 58 if (video_debug) \
@@ -76,6 +76,16 @@ MODULE_DESCRIPTION(DRIVER_DESC);
76MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
77MODULE_VERSION(EM28XX_VERSION); 77MODULE_VERSION(EM28XX_VERSION);
78 78
79
80#define EM25XX_FRMDATAHDR_BYTE1 0x02
81#define EM25XX_FRMDATAHDR_BYTE2_STILL_IMAGE 0x20
82#define EM25XX_FRMDATAHDR_BYTE2_FRAME_END 0x02
83#define EM25XX_FRMDATAHDR_BYTE2_FRAME_ID 0x01
84#define EM25XX_FRMDATAHDR_BYTE2_MASK (EM25XX_FRMDATAHDR_BYTE2_STILL_IMAGE | \
85 EM25XX_FRMDATAHDR_BYTE2_FRAME_END | \
86 EM25XX_FRMDATAHDR_BYTE2_FRAME_ID)
87
88
79static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U }; 89static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
80static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U }; 90static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
81static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U }; 91static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
@@ -408,6 +418,62 @@ static inline void process_frame_data_em28xx(struct em28xx *dev,
408 em28xx_copy_video(dev, buf, data_pkt, data_len); 418 em28xx_copy_video(dev, buf, data_pkt, data_len);
409} 419}
410 420
421/*
422 * Process data packet according to the em25xx/em276x/7x/8x frame data format
423 */
424static inline void process_frame_data_em25xx(struct em28xx *dev,
425 unsigned char *data_pkt,
426 unsigned int data_len)
427{
428 struct em28xx_buffer *buf = dev->usb_ctl.vid_buf;
429 struct em28xx_dmaqueue *dmaq = &dev->vidq;
430 bool frame_end = 0;
431
432 /* Check for header */
433 /* NOTE: at least with bulk transfers, only the first packet
434 * has a header and has always set the FRAME_END bit */
435 if (data_len >= 2) { /* em25xx header is only 2 bytes long */
436 if ((data_pkt[0] == EM25XX_FRMDATAHDR_BYTE1) &&
437 ((data_pkt[1] & ~EM25XX_FRMDATAHDR_BYTE2_MASK) == 0x00)) {
438 dev->top_field = !(data_pkt[1] &
439 EM25XX_FRMDATAHDR_BYTE2_FRAME_ID);
440 frame_end = data_pkt[1] &
441 EM25XX_FRMDATAHDR_BYTE2_FRAME_END;
442 data_pkt += 2;
443 data_len -= 2;
444 }
445
446 /* Finish field and prepare next (BULK only) */
447 if (dev->analog_xfer_bulk && frame_end) {
448 buf = finish_field_prepare_next(dev, buf, dmaq);
449 dev->usb_ctl.vid_buf = buf;
450 }
451 /* NOTE: in ISOC mode when a new frame starts and buf==NULL,
452 * we COULD already prepare a buffer here to avoid skipping the
453 * first frame.
454 */
455 }
456
457 /* Copy data */
458 if (buf != NULL && data_len > 0)
459 em28xx_copy_video(dev, buf, data_pkt, data_len);
460
461 /* Finish frame (ISOC only) => avoids lag of 1 frame */
462 if (!dev->analog_xfer_bulk && frame_end) {
463 buf = finish_field_prepare_next(dev, buf, dmaq);
464 dev->usb_ctl.vid_buf = buf;
465 }
466
467 /* NOTE: Tested with USB bulk transfers only !
468 * The wording in the datasheet suggests that isoc might work different.
469 * The current code assumes that with isoc transfers each packet has a
470 * header like with the other em28xx devices.
471 */
472 /* NOTE: Support for interlaced mode is pure theory. It has not been
473 * tested and it is unknown if these devices actually support it. */
474 /* NOTE: No VBI support yet (these chips likely do not support VBI). */
475}
476
411/* Processes and copies the URB data content (video and VBI data) */ 477/* Processes and copies the URB data content (video and VBI data) */
412static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) 478static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb)
413{ 479{
@@ -460,7 +526,13 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb)
460 continue; 526 continue;
461 } 527 }
462 528
463 process_frame_data_em28xx(dev, usb_data_pkt, usb_data_len); 529 if (dev->is_em25xx)
530 process_frame_data_em25xx(dev,
531 usb_data_pkt, usb_data_len);
532 else
533 process_frame_data_em28xx(dev,
534 usb_data_pkt, usb_data_len);
535
464 } 536 }
465 return 1; 537 return 1;
466} 538}
@@ -700,6 +772,7 @@ int em28xx_vb2_setup(struct em28xx *dev)
700 q = &dev->vb_vidq; 772 q = &dev->vb_vidq;
701 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 773 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
702 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 774 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
775 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
703 q->drv_priv = dev; 776 q->drv_priv = dev;
704 q->buf_struct_size = sizeof(struct em28xx_buffer); 777 q->buf_struct_size = sizeof(struct em28xx_buffer);
705 q->ops = &em28xx_video_qops; 778 q->ops = &em28xx_video_qops;
@@ -713,6 +786,7 @@ int em28xx_vb2_setup(struct em28xx *dev)
713 q = &dev->vb_vbiq; 786 q = &dev->vb_vbiq;
714 q->type = V4L2_BUF_TYPE_VBI_CAPTURE; 787 q->type = V4L2_BUF_TYPE_VBI_CAPTURE;
715 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR; 788 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR;
789 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
716 q->drv_priv = dev; 790 q->drv_priv = dev;
717 q->buf_struct_size = sizeof(struct em28xx_buffer); 791 q->buf_struct_size = sizeof(struct em28xx_buffer);
718 q->ops = &em28xx_vbi_qops; 792 q->ops = &em28xx_vbi_qops;
@@ -782,33 +856,45 @@ void em28xx_ctrl_notify(struct v4l2_ctrl *ctrl, void *priv)
782static int em28xx_s_ctrl(struct v4l2_ctrl *ctrl) 856static int em28xx_s_ctrl(struct v4l2_ctrl *ctrl)
783{ 857{
784 struct em28xx *dev = container_of(ctrl->handler, struct em28xx, ctrl_handler); 858 struct em28xx *dev = container_of(ctrl->handler, struct em28xx, ctrl_handler);
859 int ret = -EINVAL;
785 860
786 switch (ctrl->id) { 861 switch (ctrl->id) {
787 case V4L2_CID_AUDIO_MUTE: 862 case V4L2_CID_AUDIO_MUTE:
788 dev->mute = ctrl->val; 863 dev->mute = ctrl->val;
864 ret = em28xx_audio_analog_set(dev);
789 break; 865 break;
790 case V4L2_CID_AUDIO_VOLUME: 866 case V4L2_CID_AUDIO_VOLUME:
791 dev->volume = ctrl->val; 867 dev->volume = ctrl->val;
868 ret = em28xx_audio_analog_set(dev);
869 break;
870 case V4L2_CID_CONTRAST:
871 ret = em28xx_write_reg(dev, EM28XX_R20_YGAIN, ctrl->val);
872 break;
873 case V4L2_CID_BRIGHTNESS:
874 ret = em28xx_write_reg(dev, EM28XX_R21_YOFFSET, ctrl->val);
875 break;
876 case V4L2_CID_SATURATION:
877 ret = em28xx_write_reg(dev, EM28XX_R22_UVGAIN, ctrl->val);
878 break;
879 case V4L2_CID_BLUE_BALANCE:
880 ret = em28xx_write_reg(dev, EM28XX_R23_UOFFSET, ctrl->val);
881 break;
882 case V4L2_CID_RED_BALANCE:
883 ret = em28xx_write_reg(dev, EM28XX_R24_VOFFSET, ctrl->val);
884 break;
885 case V4L2_CID_SHARPNESS:
886 ret = em28xx_write_reg(dev, EM28XX_R25_SHARPNESS, ctrl->val);
792 break; 887 break;
793 } 888 }
794 889
795 return em28xx_audio_analog_set(dev); 890 return (ret < 0) ? ret : 0;
796} 891}
797 892
798const struct v4l2_ctrl_ops em28xx_ctrl_ops = { 893const struct v4l2_ctrl_ops em28xx_ctrl_ops = {
799 .s_ctrl = em28xx_s_ctrl, 894 .s_ctrl = em28xx_s_ctrl,
800}; 895};
801 896
802static int check_dev(struct em28xx *dev) 897static void size_to_scale(struct em28xx *dev,
803{
804 if (dev->disconnected) {
805 em28xx_errdev("v4l2 ioctl: device not present\n");
806 return -ENODEV;
807 }
808 return 0;
809}
810
811static void get_scale(struct em28xx *dev,
812 unsigned int width, unsigned int height, 898 unsigned int width, unsigned int height,
813 unsigned int *hscale, unsigned int *vscale) 899 unsigned int *hscale, unsigned int *vscale)
814{ 900{
@@ -816,12 +902,23 @@ static void get_scale(struct em28xx *dev,
816 unsigned int maxh = norm_maxh(dev); 902 unsigned int maxh = norm_maxh(dev);
817 903
818 *hscale = (((unsigned long)maxw) << 12) / width - 4096L; 904 *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
819 if (*hscale >= 0x4000) 905 if (*hscale > EM28XX_HVSCALE_MAX)
820 *hscale = 0x3fff; 906 *hscale = EM28XX_HVSCALE_MAX;
821 907
822 *vscale = (((unsigned long)maxh) << 12) / height - 4096L; 908 *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
823 if (*vscale >= 0x4000) 909 if (*vscale > EM28XX_HVSCALE_MAX)
824 *vscale = 0x3fff; 910 *vscale = EM28XX_HVSCALE_MAX;
911}
912
913static void scale_to_size(struct em28xx *dev,
914 unsigned int hscale, unsigned int vscale,
915 unsigned int *width, unsigned int *height)
916{
917 unsigned int maxw = norm_maxw(dev);
918 unsigned int maxh = norm_maxh(dev);
919
920 *width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
921 *height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
825} 922}
826 923
827/* ------------------------------------------------------------------ 924/* ------------------------------------------------------------------
@@ -898,10 +995,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
898 1, 0); 995 1, 0);
899 } 996 }
900 997
901 get_scale(dev, width, height, &hscale, &vscale); 998 size_to_scale(dev, width, height, &hscale, &vscale);
902 999 scale_to_size(dev, hscale, vscale, &width, &height);
903 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
904 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
905 1000
906 f->fmt.pix.width = width; 1001 f->fmt.pix.width = width;
907 f->fmt.pix.height = height; 1002 f->fmt.pix.height = height;
@@ -932,7 +1027,7 @@ static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
932 dev->height = height; 1027 dev->height = height;
933 1028
934 /* set new image size */ 1029 /* set new image size */
935 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); 1030 size_to_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
936 1031
937 em28xx_resolution_set(dev); 1032 em28xx_resolution_set(dev);
938 1033
@@ -957,13 +1052,6 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
957{ 1052{
958 struct em28xx_fh *fh = priv; 1053 struct em28xx_fh *fh = priv;
959 struct em28xx *dev = fh->dev; 1054 struct em28xx *dev = fh->dev;
960 int rc;
961
962 if (dev->board.is_webcam)
963 return -ENOTTY;
964 rc = check_dev(dev);
965 if (rc < 0)
966 return rc;
967 1055
968 *norm = dev->norm; 1056 *norm = dev->norm;
969 1057
@@ -974,48 +1062,35 @@ static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm)
974{ 1062{
975 struct em28xx_fh *fh = priv; 1063 struct em28xx_fh *fh = priv;
976 struct em28xx *dev = fh->dev; 1064 struct em28xx *dev = fh->dev;
977 int rc;
978
979 if (dev->board.is_webcam)
980 return -ENOTTY;
981 rc = check_dev(dev);
982 if (rc < 0)
983 return rc;
984 1065
985 v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm); 1066 v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm);
986 1067
987 return 0; 1068 return 0;
988} 1069}
989 1070
990static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) 1071static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
991{ 1072{
992 struct em28xx_fh *fh = priv; 1073 struct em28xx_fh *fh = priv;
993 struct em28xx *dev = fh->dev; 1074 struct em28xx *dev = fh->dev;
994 struct v4l2_format f; 1075 struct v4l2_format f;
995 int rc;
996 1076
997 if (dev->board.is_webcam) 1077 if (norm == dev->norm)
998 return -ENOTTY;
999 if (*norm == dev->norm)
1000 return 0; 1078 return 0;
1001 rc = check_dev(dev);
1002 if (rc < 0)
1003 return rc;
1004 1079
1005 if (dev->streaming_users > 0) 1080 if (dev->streaming_users > 0)
1006 return -EBUSY; 1081 return -EBUSY;
1007 1082
1008 dev->norm = *norm; 1083 dev->norm = norm;
1009 1084
1010 /* Adjusts width/height, if needed */ 1085 /* Adjusts width/height, if needed */
1011 f.fmt.pix.width = 720; 1086 f.fmt.pix.width = 720;
1012 f.fmt.pix.height = (*norm & V4L2_STD_525_60) ? 480 : 576; 1087 f.fmt.pix.height = (norm & V4L2_STD_525_60) ? 480 : 576;
1013 vidioc_try_fmt_vid_cap(file, priv, &f); 1088 vidioc_try_fmt_vid_cap(file, priv, &f);
1014 1089
1015 /* set new image size */ 1090 /* set new image size */
1016 dev->width = f.fmt.pix.width; 1091 dev->width = f.fmt.pix.width;
1017 dev->height = f.fmt.pix.height; 1092 dev->height = f.fmt.pix.height;
1018 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); 1093 size_to_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1019 1094
1020 em28xx_resolution_set(dev); 1095 em28xx_resolution_set(dev);
1021 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm); 1096 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
@@ -1030,9 +1105,6 @@ static int vidioc_g_parm(struct file *file, void *priv,
1030 struct em28xx *dev = fh->dev; 1105 struct em28xx *dev = fh->dev;
1031 int rc = 0; 1106 int rc = 0;
1032 1107
1033 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1034 return -EINVAL;
1035
1036 p->parm.capture.readbuffers = EM28XX_MIN_BUF; 1108 p->parm.capture.readbuffers = EM28XX_MIN_BUF;
1037 if (dev->board.is_webcam) 1109 if (dev->board.is_webcam)
1038 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0, 1110 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0,
@@ -1050,12 +1122,6 @@ static int vidioc_s_parm(struct file *file, void *priv,
1050 struct em28xx_fh *fh = priv; 1122 struct em28xx_fh *fh = priv;
1051 struct em28xx *dev = fh->dev; 1123 struct em28xx *dev = fh->dev;
1052 1124
1053 if (!dev->board.is_webcam)
1054 return -ENOTTY;
1055
1056 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1057 return -EINVAL;
1058
1059 p->parm.capture.readbuffers = EM28XX_MIN_BUF; 1125 p->parm.capture.readbuffers = EM28XX_MIN_BUF;
1060 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p); 1126 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p);
1061} 1127}
@@ -1116,11 +1182,6 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1116{ 1182{
1117 struct em28xx_fh *fh = priv; 1183 struct em28xx_fh *fh = priv;
1118 struct em28xx *dev = fh->dev; 1184 struct em28xx *dev = fh->dev;
1119 int rc;
1120
1121 rc = check_dev(dev);
1122 if (rc < 0)
1123 return rc;
1124 1185
1125 if (i >= MAX_EM28XX_INPUT) 1186 if (i >= MAX_EM28XX_INPUT)
1126 return -EINVAL; 1187 return -EINVAL;
@@ -1136,9 +1197,6 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1136 struct em28xx_fh *fh = priv; 1197 struct em28xx_fh *fh = priv;
1137 struct em28xx *dev = fh->dev; 1198 struct em28xx *dev = fh->dev;
1138 1199
1139 if (!dev->audio_mode.has_audio)
1140 return -EINVAL;
1141
1142 switch (a->index) { 1200 switch (a->index) {
1143 case EM28XX_AMUX_VIDEO: 1201 case EM28XX_AMUX_VIDEO:
1144 strcpy(a->name, "Television"); 1202 strcpy(a->name, "Television");
@@ -1179,10 +1237,6 @@ static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio
1179 struct em28xx_fh *fh = priv; 1237 struct em28xx_fh *fh = priv;
1180 struct em28xx *dev = fh->dev; 1238 struct em28xx *dev = fh->dev;
1181 1239
1182
1183 if (!dev->audio_mode.has_audio)
1184 return -EINVAL;
1185
1186 if (a->index >= MAX_EM28XX_INPUT) 1240 if (a->index >= MAX_EM28XX_INPUT)
1187 return -EINVAL; 1241 return -EINVAL;
1188 if (0 == INPUT(a->index)->type) 1242 if (0 == INPUT(a->index)->type)
@@ -1202,11 +1256,6 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1202{ 1256{
1203 struct em28xx_fh *fh = priv; 1257 struct em28xx_fh *fh = priv;
1204 struct em28xx *dev = fh->dev; 1258 struct em28xx *dev = fh->dev;
1205 int rc;
1206
1207 rc = check_dev(dev);
1208 if (rc < 0)
1209 return rc;
1210 1259
1211 if (0 != t->index) 1260 if (0 != t->index)
1212 return -EINVAL; 1261 return -EINVAL;
@@ -1218,15 +1267,10 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1218} 1267}
1219 1268
1220static int vidioc_s_tuner(struct file *file, void *priv, 1269static int vidioc_s_tuner(struct file *file, void *priv,
1221 struct v4l2_tuner *t) 1270 const struct v4l2_tuner *t)
1222{ 1271{
1223 struct em28xx_fh *fh = priv; 1272 struct em28xx_fh *fh = priv;
1224 struct em28xx *dev = fh->dev; 1273 struct em28xx *dev = fh->dev;
1225 int rc;
1226
1227 rc = check_dev(dev);
1228 if (rc < 0)
1229 return rc;
1230 1274
1231 if (0 != t->index) 1275 if (0 != t->index)
1232 return -EINVAL; 1276 return -EINVAL;
@@ -1249,39 +1293,22 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1249} 1293}
1250 1294
1251static int vidioc_s_frequency(struct file *file, void *priv, 1295static int vidioc_s_frequency(struct file *file, void *priv,
1252 struct v4l2_frequency *f) 1296 const struct v4l2_frequency *f)
1253{ 1297{
1298 struct v4l2_frequency new_freq = *f;
1254 struct em28xx_fh *fh = priv; 1299 struct em28xx_fh *fh = priv;
1255 struct em28xx *dev = fh->dev; 1300 struct em28xx *dev = fh->dev;
1256 int rc;
1257
1258 rc = check_dev(dev);
1259 if (rc < 0)
1260 return rc;
1261 1301
1262 if (0 != f->tuner) 1302 if (0 != f->tuner)
1263 return -EINVAL; 1303 return -EINVAL;
1264 1304
1265 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f); 1305 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); 1306 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, &new_freq);
1267 dev->ctl_freq = f->frequency; 1307 dev->ctl_freq = new_freq.frequency;
1268 1308
1269 return 0; 1309 return 0;
1270} 1310}
1271 1311
1272#ifdef CONFIG_VIDEO_ADV_DEBUG
1273static int em28xx_reg_len(int reg)
1274{
1275 switch (reg) {
1276 case EM28XX_R40_AC97LSB:
1277 case EM28XX_R30_HSCALELOW:
1278 case EM28XX_R32_VSCALELOW:
1279 return 2;
1280 default:
1281 return 1;
1282 }
1283}
1284
1285static int vidioc_g_chip_ident(struct file *file, void *priv, 1312static int vidioc_g_chip_ident(struct file *file, void *priv,
1286 struct v4l2_dbg_chip_ident *chip) 1313 struct v4l2_dbg_chip_ident *chip)
1287{ 1314{
@@ -1290,9 +1317,9 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
1290 1317
1291 chip->ident = V4L2_IDENT_NONE; 1318 chip->ident = V4L2_IDENT_NONE;
1292 chip->revision = 0; 1319 chip->revision = 0;
1293 if (chip->match.type == V4L2_CHIP_MATCH_HOST) { 1320 if (chip->match.type == V4L2_CHIP_MATCH_BRIDGE) {
1294 if (v4l2_chip_match_host(&chip->match)) 1321 if (chip->match.addr > 1)
1295 chip->ident = V4L2_IDENT_NONE; 1322 return -EINVAL;
1296 return 0; 1323 return 0;
1297 } 1324 }
1298 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER && 1325 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
@@ -1304,6 +1331,33 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
1304 return 0; 1331 return 0;
1305} 1332}
1306 1333
1334#ifdef CONFIG_VIDEO_ADV_DEBUG
1335static int vidioc_g_chip_info(struct file *file, void *priv,
1336 struct v4l2_dbg_chip_info *chip)
1337{
1338 struct em28xx_fh *fh = priv;
1339 struct em28xx *dev = fh->dev;
1340
1341 if (chip->match.addr > 1)
1342 return -EINVAL;
1343 if (chip->match.addr == 1)
1344 strlcpy(chip->name, "ac97", sizeof(chip->name));
1345 else
1346 strlcpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name));
1347 return 0;
1348}
1349
1350static int em28xx_reg_len(int reg)
1351{
1352 switch (reg) {
1353 case EM28XX_R40_AC97LSB:
1354 case EM28XX_R30_HSCALELOW:
1355 case EM28XX_R32_VSCALELOW:
1356 return 2;
1357 default:
1358 return 1;
1359 }
1360}
1307 1361
1308static int vidioc_g_register(struct file *file, void *priv, 1362static int vidioc_g_register(struct file *file, void *priv,
1309 struct v4l2_dbg_register *reg) 1363 struct v4l2_dbg_register *reg)
@@ -1313,6 +1367,12 @@ static int vidioc_g_register(struct file *file, void *priv,
1313 int ret; 1367 int ret;
1314 1368
1315 switch (reg->match.type) { 1369 switch (reg->match.type) {
1370 case V4L2_CHIP_MATCH_BRIDGE:
1371 if (reg->match.addr > 1)
1372 return -EINVAL;
1373 if (!reg->match.addr)
1374 break;
1375 /* fall-through */
1316 case V4L2_CHIP_MATCH_AC97: 1376 case V4L2_CHIP_MATCH_AC97:
1317 ret = em28xx_read_ac97(dev, reg->reg); 1377 ret = em28xx_read_ac97(dev, reg->reg);
1318 if (ret < 0) 1378 if (ret < 0)
@@ -1329,8 +1389,7 @@ static int vidioc_g_register(struct file *file, void *priv,
1329 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg); 1389 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1330 return 0; 1390 return 0;
1331 default: 1391 default:
1332 if (!v4l2_chip_match_host(&reg->match)) 1392 return -EINVAL;
1333 return -EINVAL;
1334 } 1393 }
1335 1394
1336 /* Match host */ 1395 /* Match host */
@@ -1356,13 +1415,19 @@ static int vidioc_g_register(struct file *file, void *priv,
1356} 1415}
1357 1416
1358static int vidioc_s_register(struct file *file, void *priv, 1417static int vidioc_s_register(struct file *file, void *priv,
1359 struct v4l2_dbg_register *reg) 1418 const struct v4l2_dbg_register *reg)
1360{ 1419{
1361 struct em28xx_fh *fh = priv; 1420 struct em28xx_fh *fh = priv;
1362 struct em28xx *dev = fh->dev; 1421 struct em28xx *dev = fh->dev;
1363 __le16 buf; 1422 __le16 buf;
1364 1423
1365 switch (reg->match.type) { 1424 switch (reg->match.type) {
1425 case V4L2_CHIP_MATCH_BRIDGE:
1426 if (reg->match.addr > 1)
1427 return -EINVAL;
1428 if (!reg->match.addr)
1429 break;
1430 /* fall-through */
1366 case V4L2_CHIP_MATCH_AC97: 1431 case V4L2_CHIP_MATCH_AC97:
1367 return em28xx_write_ac97(dev, reg->reg, reg->val); 1432 return em28xx_write_ac97(dev, reg->reg, reg->val);
1368 case V4L2_CHIP_MATCH_I2C_DRIVER: 1433 case V4L2_CHIP_MATCH_I2C_DRIVER:
@@ -1373,8 +1438,7 @@ static int vidioc_s_register(struct file *file, void *priv,
1373 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg); 1438 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1374 return 0; 1439 return 0;
1375 default: 1440 default:
1376 if (!v4l2_chip_match_host(&reg->match)) 1441 return -EINVAL;
1377 return -EINVAL;
1378 } 1442 }
1379 1443
1380 /* Match host */ 1444 /* Match host */
@@ -1386,26 +1450,6 @@ static int vidioc_s_register(struct file *file, void *priv,
1386#endif 1450#endif
1387 1451
1388 1452
1389static int vidioc_cropcap(struct file *file, void *priv,
1390 struct v4l2_cropcap *cc)
1391{
1392 struct em28xx_fh *fh = priv;
1393 struct em28xx *dev = fh->dev;
1394
1395 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1396 return -EINVAL;
1397
1398 cc->bounds.left = 0;
1399 cc->bounds.top = 0;
1400 cc->bounds.width = dev->width;
1401 cc->bounds.height = dev->height;
1402 cc->defrect = cc->bounds;
1403 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1404 cc->pixelaspect.denominator = 59;
1405
1406 return 0;
1407}
1408
1409static int vidioc_querycap(struct file *file, void *priv, 1453static int vidioc_querycap(struct file *file, void *priv,
1410 struct v4l2_capability *cap) 1454 struct v4l2_capability *cap)
1411{ 1455{
@@ -1482,8 +1526,12 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
1482 1526
1483 /* Report a continuous range */ 1527 /* Report a continuous range */
1484 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; 1528 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
1485 fsize->stepwise.min_width = 48; 1529 scale_to_size(dev, EM28XX_HVSCALE_MAX, EM28XX_HVSCALE_MAX,
1486 fsize->stepwise.min_height = 32; 1530 &fsize->stepwise.min_width, &fsize->stepwise.min_height);
1531 if (fsize->stepwise.min_width < 48)
1532 fsize->stepwise.min_width = 48;
1533 if (fsize->stepwise.min_height < 38)
1534 fsize->stepwise.min_height = 38;
1487 fsize->stepwise.max_width = maxw; 1535 fsize->stepwise.max_width = maxw;
1488 fsize->stepwise.max_height = maxh; 1536 fsize->stepwise.max_height = maxh;
1489 fsize->stepwise.step_width = 1; 1537 fsize->stepwise.step_width = 1;
@@ -1522,35 +1570,6 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1522 return 0; 1570 return 0;
1523} 1571}
1524 1572
1525static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1526 struct v4l2_format *format)
1527{
1528 struct em28xx_fh *fh = priv;
1529 struct em28xx *dev = fh->dev;
1530
1531 format->fmt.vbi.samples_per_line = dev->vbi_width;
1532 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1533 format->fmt.vbi.offset = 0;
1534 format->fmt.vbi.flags = 0;
1535 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1536 format->fmt.vbi.count[0] = dev->vbi_height;
1537 format->fmt.vbi.count[1] = dev->vbi_height;
1538 memset(format->fmt.vbi.reserved, 0, sizeof(format->fmt.vbi.reserved));
1539
1540 /* Varies by video standard (NTSC, PAL, etc.) */
1541 if (dev->norm & V4L2_STD_525_60) {
1542 /* NTSC */
1543 format->fmt.vbi.start[0] = 10;
1544 format->fmt.vbi.start[1] = 273;
1545 } else if (dev->norm & V4L2_STD_625_50) {
1546 /* PAL */
1547 format->fmt.vbi.start[0] = 6;
1548 format->fmt.vbi.start[1] = 318;
1549 }
1550
1551 return 0;
1552}
1553
1554/* ----------------------------------------------------------- */ 1573/* ----------------------------------------------------------- */
1555/* RADIO ESPECIFIC IOCTLS */ 1574/* RADIO ESPECIFIC IOCTLS */
1556/* ----------------------------------------------------------- */ 1575/* ----------------------------------------------------------- */
@@ -1564,7 +1583,6 @@ static int radio_g_tuner(struct file *file, void *priv,
1564 return -EINVAL; 1583 return -EINVAL;
1565 1584
1566 strcpy(t->name, "Radio"); 1585 strcpy(t->name, "Radio");
1567 t->type = V4L2_TUNER_RADIO;
1568 1586
1569 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); 1587 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1570 1588
@@ -1572,7 +1590,7 @@ static int radio_g_tuner(struct file *file, void *priv,
1572} 1590}
1573 1591
1574static int radio_s_tuner(struct file *file, void *priv, 1592static int radio_s_tuner(struct file *file, void *priv,
1575 struct v4l2_tuner *t) 1593 const struct v4l2_tuner *t)
1576{ 1594{
1577 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev; 1595 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1578 1596
@@ -1749,11 +1767,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1749 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1767 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1750 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1768 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1751 .vidioc_try_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1769 .vidioc_try_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1752 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, 1770 .vidioc_s_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1753 .vidioc_enum_framesizes = vidioc_enum_framesizes, 1771 .vidioc_enum_framesizes = vidioc_enum_framesizes,
1754 .vidioc_g_audio = vidioc_g_audio, 1772 .vidioc_g_audio = vidioc_g_audio,
1755 .vidioc_s_audio = vidioc_s_audio, 1773 .vidioc_s_audio = vidioc_s_audio,
1756 .vidioc_cropcap = vidioc_cropcap,
1757 1774
1758 .vidioc_reqbufs = vb2_ioctl_reqbufs, 1775 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1759 .vidioc_create_bufs = vb2_ioctl_create_bufs, 1776 .vidioc_create_bufs = vb2_ioctl_create_bufs,
@@ -1778,10 +1795,11 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1778 .vidioc_s_frequency = vidioc_s_frequency, 1795 .vidioc_s_frequency = vidioc_s_frequency,
1779 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1796 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1780 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1797 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1798 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1781#ifdef CONFIG_VIDEO_ADV_DEBUG 1799#ifdef CONFIG_VIDEO_ADV_DEBUG
1800 .vidioc_g_chip_info = vidioc_g_chip_info,
1782 .vidioc_g_register = vidioc_g_register, 1801 .vidioc_g_register = vidioc_g_register,
1783 .vidioc_s_register = vidioc_s_register, 1802 .vidioc_s_register = vidioc_s_register,
1784 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1785#endif 1803#endif
1786}; 1804};
1787 1805
@@ -1808,7 +1826,9 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1808 .vidioc_s_frequency = vidioc_s_frequency, 1826 .vidioc_s_frequency = vidioc_s_frequency,
1809 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1827 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1810 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1828 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1829 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1811#ifdef CONFIG_VIDEO_ADV_DEBUG 1830#ifdef CONFIG_VIDEO_ADV_DEBUG
1831 .vidioc_g_chip_info = vidioc_g_chip_info,
1812 .vidioc_g_register = vidioc_g_register, 1832 .vidioc_g_register = vidioc_g_register,
1813 .vidioc_s_register = vidioc_s_register, 1833 .vidioc_s_register = vidioc_s_register,
1814#endif 1834#endif
@@ -1887,9 +1907,42 @@ int em28xx_register_analog_devices(struct em28xx *dev)
1887 (EM28XX_XCLK_AUDIO_UNMUTE | val)); 1907 (EM28XX_XCLK_AUDIO_UNMUTE | val));
1888 1908
1889 em28xx_set_outfmt(dev); 1909 em28xx_set_outfmt(dev);
1890 em28xx_colorlevels_set_default(dev);
1891 em28xx_compression_disable(dev); 1910 em28xx_compression_disable(dev);
1892 1911
1912 /* Add image controls */
1913 /* NOTE: at this point, the subdevices are already registered, so bridge
1914 * controls are only added/enabled when no subdevice provides them */
1915 if (NULL == v4l2_ctrl_find(&dev->ctrl_handler, V4L2_CID_CONTRAST))
1916 v4l2_ctrl_new_std(&dev->ctrl_handler, &em28xx_ctrl_ops,
1917 V4L2_CID_CONTRAST,
1918 0, 0x1f, 1, CONTRAST_DEFAULT);
1919 if (NULL == v4l2_ctrl_find(&dev->ctrl_handler, V4L2_CID_BRIGHTNESS))
1920 v4l2_ctrl_new_std(&dev->ctrl_handler, &em28xx_ctrl_ops,
1921 V4L2_CID_BRIGHTNESS,
1922 -0x80, 0x7f, 1, BRIGHTNESS_DEFAULT);
1923 if (NULL == v4l2_ctrl_find(&dev->ctrl_handler, V4L2_CID_SATURATION))
1924 v4l2_ctrl_new_std(&dev->ctrl_handler, &em28xx_ctrl_ops,
1925 V4L2_CID_SATURATION,
1926 0, 0x1f, 1, SATURATION_DEFAULT);
1927 if (NULL == v4l2_ctrl_find(&dev->ctrl_handler, V4L2_CID_BLUE_BALANCE))
1928 v4l2_ctrl_new_std(&dev->ctrl_handler, &em28xx_ctrl_ops,
1929 V4L2_CID_BLUE_BALANCE,
1930 -0x30, 0x30, 1, BLUE_BALANCE_DEFAULT);
1931 if (NULL == v4l2_ctrl_find(&dev->ctrl_handler, V4L2_CID_RED_BALANCE))
1932 v4l2_ctrl_new_std(&dev->ctrl_handler, &em28xx_ctrl_ops,
1933 V4L2_CID_RED_BALANCE,
1934 -0x30, 0x30, 1, RED_BALANCE_DEFAULT);
1935 if (NULL == v4l2_ctrl_find(&dev->ctrl_handler, V4L2_CID_SHARPNESS))
1936 v4l2_ctrl_new_std(&dev->ctrl_handler, &em28xx_ctrl_ops,
1937 V4L2_CID_SHARPNESS,
1938 0, 0x0f, 1, SHARPNESS_DEFAULT);
1939
1940 /* Reset image controls */
1941 em28xx_colorlevels_set_default(dev);
1942 v4l2_ctrl_handler_setup(&dev->ctrl_handler);
1943 if (dev->ctrl_handler.error)
1944 return dev->ctrl_handler.error;
1945
1893 /* allocate and fill video video_device struct */ 1946 /* allocate and fill video video_device struct */
1894 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video"); 1947 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
1895 if (!dev->vdev) { 1948 if (!dev->vdev) {
@@ -1899,6 +1952,25 @@ int em28xx_register_analog_devices(struct em28xx *dev)
1899 dev->vdev->queue = &dev->vb_vidq; 1952 dev->vdev->queue = &dev->vb_vidq;
1900 dev->vdev->queue->lock = &dev->vb_queue_lock; 1953 dev->vdev->queue->lock = &dev->vb_queue_lock;
1901 1954
1955 /* disable inapplicable ioctls */
1956 if (dev->board.is_webcam) {
1957 v4l2_disable_ioctl(dev->vdev, VIDIOC_QUERYSTD);
1958 v4l2_disable_ioctl(dev->vdev, VIDIOC_G_STD);
1959 v4l2_disable_ioctl(dev->vdev, VIDIOC_S_STD);
1960 } else {
1961 v4l2_disable_ioctl(dev->vdev, VIDIOC_S_PARM);
1962 }
1963 if (dev->tuner_type == TUNER_ABSENT) {
1964 v4l2_disable_ioctl(dev->vdev, VIDIOC_G_TUNER);
1965 v4l2_disable_ioctl(dev->vdev, VIDIOC_S_TUNER);
1966 v4l2_disable_ioctl(dev->vdev, VIDIOC_G_FREQUENCY);
1967 v4l2_disable_ioctl(dev->vdev, VIDIOC_S_FREQUENCY);
1968 }
1969 if (!dev->audio_mode.has_audio) {
1970 v4l2_disable_ioctl(dev->vdev, VIDIOC_G_AUDIO);
1971 v4l2_disable_ioctl(dev->vdev, VIDIOC_S_AUDIO);
1972 }
1973
1902 /* register v4l2 video video_device */ 1974 /* register v4l2 video video_device */
1903 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, 1975 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
1904 video_nr[dev->devno]); 1976 video_nr[dev->devno]);
@@ -1916,6 +1988,19 @@ int em28xx_register_analog_devices(struct em28xx *dev)
1916 dev->vbi_dev->queue = &dev->vb_vbiq; 1988 dev->vbi_dev->queue = &dev->vb_vbiq;
1917 dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock; 1989 dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock;
1918 1990
1991 /* disable inapplicable ioctls */
1992 v4l2_disable_ioctl(dev->vdev, VIDIOC_S_PARM);
1993 if (dev->tuner_type == TUNER_ABSENT) {
1994 v4l2_disable_ioctl(dev->vbi_dev, VIDIOC_G_TUNER);
1995 v4l2_disable_ioctl(dev->vbi_dev, VIDIOC_S_TUNER);
1996 v4l2_disable_ioctl(dev->vbi_dev, VIDIOC_G_FREQUENCY);
1997 v4l2_disable_ioctl(dev->vbi_dev, VIDIOC_S_FREQUENCY);
1998 }
1999 if (!dev->audio_mode.has_audio) {
2000 v4l2_disable_ioctl(dev->vbi_dev, VIDIOC_G_AUDIO);
2001 v4l2_disable_ioctl(dev->vbi_dev, VIDIOC_S_AUDIO);
2002 }
2003
1919 /* register v4l2 vbi video_device */ 2004 /* register v4l2 vbi video_device */
1920 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, 2005 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
1921 vbi_nr[dev->devno]); 2006 vbi_nr[dev->devno]);
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index 5f0b2c59e846..a9323b63d8e5 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -42,28 +42,28 @@
42#include "em28xx-reg.h" 42#include "em28xx-reg.h"
43 43
44/* Boards supported by driver */ 44/* Boards supported by driver */
45#define EM2800_BOARD_UNKNOWN 0 45#define EM2800_BOARD_UNKNOWN 0
46#define EM2820_BOARD_UNKNOWN 1 46#define EM2820_BOARD_UNKNOWN 1
47#define EM2820_BOARD_TERRATEC_CINERGY_250 2 47#define EM2820_BOARD_TERRATEC_CINERGY_250 2
48#define EM2820_BOARD_PINNACLE_USB_2 3 48#define EM2820_BOARD_PINNACLE_USB_2 3
49#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4 49#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
50#define EM2820_BOARD_MSI_VOX_USB_2 5 50#define EM2820_BOARD_MSI_VOX_USB_2 5
51#define EM2800_BOARD_TERRATEC_CINERGY_200 6 51#define EM2800_BOARD_TERRATEC_CINERGY_200 6
52#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7 52#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
53#define EM2800_BOARD_KWORLD_USB2800 8 53#define EM2800_BOARD_KWORLD_USB2800 8
54#define EM2820_BOARD_PINNACLE_DVC_90 9 54#define EM2820_BOARD_PINNACLE_DVC_90 9
55#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10 55#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
56#define EM2880_BOARD_TERRATEC_HYBRID_XS 11 56#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
57#define EM2820_BOARD_KWORLD_PVRTV2800RF 12 57#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
58#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13 58#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
59#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14 59#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
60#define EM2800_BOARD_VGEAR_POCKETTV 15 60#define EM2800_BOARD_VGEAR_POCKETTV 15
61#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16 61#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16
62#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17 62#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17
63#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18 63#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18
64#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19 64#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19
65#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20 65#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20
66#define EM2800_BOARD_GRABBEEX_USB2800 21 66#define EM2800_BOARD_GRABBEEX_USB2800 21
67#define EM2750_BOARD_UNKNOWN 22 67#define EM2750_BOARD_UNKNOWN 22
68#define EM2750_BOARD_DLCW_130 23 68#define EM2750_BOARD_DLCW_130 23
69#define EM2820_BOARD_DLINK_USB_TV 24 69#define EM2820_BOARD_DLINK_USB_TV 24
@@ -99,36 +99,37 @@
99#define EM2882_BOARD_KWORLD_VS_DVBT 54 99#define EM2882_BOARD_KWORLD_VS_DVBT 54
100#define EM2882_BOARD_TERRATEC_HYBRID_XS 55 100#define EM2882_BOARD_TERRATEC_HYBRID_XS 55
101#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56 101#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56
102#define EM2883_BOARD_KWORLD_HYBRID_330U 57 102#define EM2883_BOARD_KWORLD_HYBRID_330U 57
103#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58 103#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
104#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60 104#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60
105#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61 105#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61
106#define EM2820_BOARD_GADMEI_TVR200 62 106#define EM2820_BOARD_GADMEI_TVR200 62
107#define EM2860_BOARD_KAIOMY_TVNPC_U2 63 107#define EM2860_BOARD_KAIOMY_TVNPC_U2 63
108#define EM2860_BOARD_EASYCAP 64 108#define EM2860_BOARD_EASYCAP 64
109#define EM2820_BOARD_IODATA_GVMVP_SZ 65 109#define EM2820_BOARD_IODATA_GVMVP_SZ 65
110#define EM2880_BOARD_EMPIRE_DUAL_TV 66 110#define EM2880_BOARD_EMPIRE_DUAL_TV 66
111#define EM2860_BOARD_TERRATEC_GRABBY 67 111#define EM2860_BOARD_TERRATEC_GRABBY 67
112#define EM2860_BOARD_TERRATEC_AV350 68 112#define EM2860_BOARD_TERRATEC_AV350 68
113#define EM2882_BOARD_KWORLD_ATSC_315U 69 113#define EM2882_BOARD_KWORLD_ATSC_315U 69
114#define EM2882_BOARD_EVGA_INDTUBE 70 114#define EM2882_BOARD_EVGA_INDTUBE 70
115#define EM2820_BOARD_SILVERCREST_WEBCAM 71 115#define EM2820_BOARD_SILVERCREST_WEBCAM 71
116#define EM2861_BOARD_GADMEI_UTV330PLUS 72 116#define EM2861_BOARD_GADMEI_UTV330PLUS 72
117#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73 117#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
118#define EM2800_BOARD_VC211A 74 118#define EM2800_BOARD_VC211A 74
119#define EM2882_BOARD_DIKOM_DK300 75 119#define EM2882_BOARD_DIKOM_DK300 75
120#define EM2870_BOARD_KWORLD_A340 76 120#define EM2870_BOARD_KWORLD_A340 76
121#define EM2874_BOARD_LEADERSHIP_ISDBT 77 121#define EM2874_BOARD_LEADERSHIP_ISDBT 77
122#define EM28174_BOARD_PCTV_290E 78 122#define EM28174_BOARD_PCTV_290E 78
123#define EM2884_BOARD_TERRATEC_H5 79 123#define EM2884_BOARD_TERRATEC_H5 79
124#define EM28174_BOARD_PCTV_460E 80 124#define EM28174_BOARD_PCTV_460E 80
125#define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C 81 125#define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C 81
126#define EM2884_BOARD_CINERGY_HTC_STICK 82 126#define EM2884_BOARD_CINERGY_HTC_STICK 82
127#define EM2860_BOARD_HT_VIDBOX_NW03 83 127#define EM2860_BOARD_HT_VIDBOX_NW03 83
128#define EM2874_BOARD_MAXMEDIA_UB425_TC 84 128#define EM2874_BOARD_MAXMEDIA_UB425_TC 84
129#define EM2884_BOARD_PCTV_510E 85 129#define EM2884_BOARD_PCTV_510E 85
130#define EM2884_BOARD_PCTV_520E 86 130#define EM2884_BOARD_PCTV_520E 86
131#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87 131#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
132#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88
132 133
133/* Limits minimum and default number of buffers */ 134/* Limits minimum and default number of buffers */
134#define EM28XX_MIN_BUF 4 135#define EM28XX_MIN_BUF 4
@@ -157,6 +158,9 @@
157#define EM28XX_NUM_BUFS 5 158#define EM28XX_NUM_BUFS 5
158#define EM28XX_DVB_NUM_BUFS 5 159#define EM28XX_DVB_NUM_BUFS 5
159 160
161/* max number of I2C buses on em28xx devices */
162#define NUM_I2C_BUSES 2
163
160/* isoc transfers: number of packets for each buffer 164/* isoc transfers: number of packets for each buffer
161 windows requests only 64 packets .. so we better do the same 165 windows requests only 64 packets .. so we better do the same
162 this is what I found out for all alternate numbers there! 166 this is what I found out for all alternate numbers there!
@@ -172,27 +176,6 @@
172 176
173#define EM28XX_INTERLACED_DEFAULT 1 177#define EM28XX_INTERLACED_DEFAULT 1
174 178
175/*
176#define (use usbview if you want to get the other alternate number infos)
177#define
178#define alternate number 2
179#define Endpoint Address: 82
180 Direction: in
181 Attribute: 1
182 Type: Isoc
183 Max Packet Size: 1448
184 Interval: 125us
185
186 alternate number 7
187
188 Endpoint Address: 82
189 Direction: in
190 Attribute: 1
191 Type: Isoc
192 Max Packet Size: 3072
193 Interval: 125us
194*/
195
196/* time in msecs to wait for i2c writes to finish */ 179/* time in msecs to wait for i2c writes to finish */
197#define EM2800_I2C_XFER_TIMEOUT 20 180#define EM2800_I2C_XFER_TIMEOUT 20
198 181
@@ -381,6 +364,7 @@ enum em28xx_sensor {
381 EM28XX_MT9V011, 364 EM28XX_MT9V011,
382 EM28XX_MT9M001, 365 EM28XX_MT9M001,
383 EM28XX_MT9M111, 366 EM28XX_MT9M111,
367 EM28XX_OV2640,
384}; 368};
385 369
386enum em28xx_adecoder { 370enum em28xx_adecoder {
@@ -393,6 +377,7 @@ struct em28xx_board {
393 int vchannels; 377 int vchannels;
394 int tuner_type; 378 int tuner_type;
395 int tuner_addr; 379 int tuner_addr;
380 unsigned def_i2c_bus; /* Default I2C bus */
396 381
397 /* i2c flags */ 382 /* i2c flags */
398 unsigned int tda9887_conf; 383 unsigned int tda9887_conf;
@@ -426,15 +411,15 @@ struct em28xx_board {
426}; 411};
427 412
428struct em28xx_eeprom { 413struct em28xx_eeprom {
429 u32 id; /* 0x9567eb1a */ 414 u8 id[4]; /* 1a eb 67 95 */
430 u16 vendor_ID; 415 __le16 vendor_ID;
431 u16 product_ID; 416 __le16 product_ID;
432 417
433 u16 chip_conf; 418 __le16 chip_conf;
434 419
435 u16 board_conf; 420 __le16 board_conf;
436 421
437 u16 string1, string2, string3; 422 __le16 string1, string2, string3;
438 423
439 u8 string_idx_table; 424 u8 string_idx_table;
440}; 425};
@@ -477,6 +462,20 @@ struct em28xx_fh {
477 enum v4l2_buf_type type; 462 enum v4l2_buf_type type;
478}; 463};
479 464
465enum em28xx_i2c_algo_type {
466 EM28XX_I2C_ALGO_EM28XX = 0,
467 EM28XX_I2C_ALGO_EM2800,
468 EM28XX_I2C_ALGO_EM25XX_BUS_B,
469};
470
471struct em28xx_i2c_bus {
472 struct em28xx *dev;
473
474 unsigned bus;
475 enum em28xx_i2c_algo_type algo_type;
476};
477
478
480/* main device struct */ 479/* main device struct */
481struct em28xx { 480struct em28xx {
482 /* generic device properties */ 481 /* generic device properties */
@@ -484,6 +483,7 @@ struct em28xx {
484 int model; /* index in the device_data struct */ 483 int model; /* index in the device_data struct */
485 int devno; /* marks the number of this device */ 484 int devno; /* marks the number of this device */
486 enum em28xx_chip_id chip_id; 485 enum em28xx_chip_id chip_id;
486 unsigned int is_em25xx:1; /* em25xx/em276x/7x/8x family bridge */
487 487
488 unsigned char disconnected:1; /* device has been diconnected */ 488 unsigned char disconnected:1; /* device has been diconnected */
489 489
@@ -491,8 +491,6 @@ struct em28xx {
491 491
492 struct v4l2_device v4l2_dev; 492 struct v4l2_device v4l2_dev;
493 struct v4l2_ctrl_handler ctrl_handler; 493 struct v4l2_ctrl_handler ctrl_handler;
494 /* provides ac97 mute and volume overrides */
495 struct v4l2_ctrl_handler ac97_ctrl_handler;
496 struct em28xx_board board; 494 struct em28xx_board board;
497 495
498 /* Webcam specific fields */ 496 /* Webcam specific fields */
@@ -511,8 +509,8 @@ struct em28xx {
511 unsigned int is_audio_only:1; 509 unsigned int is_audio_only:1;
512 510
513 /* Controls audio streaming */ 511 /* Controls audio streaming */
514 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */ 512 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
515 atomic_t stream_started; /* stream should be running if true */ 513 atomic_t stream_started; /* stream should be running if true */
516 514
517 struct em28xx_fmt *format; 515 struct em28xx_fmt *format;
518 516
@@ -530,9 +528,17 @@ struct em28xx {
530 int tuner_type; /* type of the tuner */ 528 int tuner_type; /* type of the tuner */
531 int tuner_addr; /* tuner address */ 529 int tuner_addr; /* tuner address */
532 int tda9887_conf; 530 int tda9887_conf;
531
533 /* i2c i/o */ 532 /* i2c i/o */
534 struct i2c_adapter i2c_adap; 533 struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
535 struct i2c_client i2c_client; 534 struct i2c_client i2c_client[NUM_I2C_BUSES];
535 struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
536
537 unsigned char eeprom_addrwidth_16bit:1;
538 unsigned def_i2c_bus; /* Default I2C bus */
539 unsigned cur_i2c_bus; /* Current I2C bus */
540 struct rt_mutex i2c_bus_lock;
541
536 /* video for linux */ 542 /* video for linux */
537 int users; /* user count for exclusive use */ 543 int users; /* user count for exclusive use */
538 int streaming_users; /* Number of actively streaming users */ 544 int streaming_users; /* Number of actively streaming users */
@@ -584,7 +590,9 @@ struct em28xx {
584 /* resources in use */ 590 /* resources in use */
585 unsigned int resources; 591 unsigned int resources;
586 592
587 unsigned char eedata[256]; 593 /* eeprom content */
594 u8 *eedata;
595 u16 eedata_len;
588 596
589 /* Isoc control struct */ 597 /* Isoc control struct */
590 struct em28xx_dmaqueue vidq; 598 struct em28xx_dmaqueue vidq;
@@ -600,7 +608,7 @@ struct em28xx {
600 u8 analog_ep_isoc; /* address of isoc endpoint for analog */ 608 u8 analog_ep_isoc; /* address of isoc endpoint for analog */
601 u8 analog_ep_bulk; /* address of bulk endpoint for analog */ 609 u8 analog_ep_bulk; /* address of bulk endpoint for analog */
602 u8 dvb_ep_isoc; /* address of isoc endpoint for DVB */ 610 u8 dvb_ep_isoc; /* address of isoc endpoint for DVB */
603 u8 dvb_ep_bulk; /* address of bulk endpoint for DVC */ 611 u8 dvb_ep_bulk; /* address of bulk endpoint for DVB */
604 int alt; /* alternate setting */ 612 int alt; /* alternate setting */
605 int max_pkt_size; /* max packet size of the selected ep at alt */ 613 int max_pkt_size; /* max packet size of the selected ep at alt */
606 int packet_multiplier; /* multiplier for wMaxPacketSize, used for 614 int packet_multiplier; /* multiplier for wMaxPacketSize, used for
@@ -651,16 +659,12 @@ struct em28xx_ops {
651}; 659};
652 660
653/* Provided by em28xx-i2c.c */ 661/* Provided by em28xx-i2c.c */
654void em28xx_do_i2c_scan(struct em28xx *dev); 662void em28xx_do_i2c_scan(struct em28xx *dev, unsigned bus);
655int em28xx_i2c_register(struct em28xx *dev); 663int em28xx_i2c_register(struct em28xx *dev, unsigned bus,
656int em28xx_i2c_unregister(struct em28xx *dev); 664 enum em28xx_i2c_algo_type algo_type);
665int em28xx_i2c_unregister(struct em28xx *dev, unsigned bus);
657 666
658/* Provided by em28xx-core.c */ 667/* Provided by em28xx-core.c */
659
660u32 em28xx_request_buffers(struct em28xx *dev, u32 count);
661void em28xx_queue_unusedframes(struct em28xx *dev);
662void em28xx_release_buffers(struct em28xx *dev);
663
664int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg, 668int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
665 char *buf, int len); 669 char *buf, int len);
666int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg); 670int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
@@ -693,7 +697,6 @@ int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
693 (struct em28xx *dev, struct urb *urb)); 697 (struct em28xx *dev, struct urb *urb));
694void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode); 698void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
695void em28xx_stop_urbs(struct em28xx *dev); 699void em28xx_stop_urbs(struct em28xx *dev);
696int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev);
697int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode); 700int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
698int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio); 701int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio);
699void em28xx_wake_i2c(struct em28xx *dev); 702void em28xx_wake_i2c(struct em28xx *dev);
@@ -712,16 +715,18 @@ int em28xx_stop_vbi_streaming(struct vb2_queue *vq);
712extern const struct v4l2_ctrl_ops em28xx_ctrl_ops; 715extern const struct v4l2_ctrl_ops em28xx_ctrl_ops;
713 716
714/* Provided by em28xx-cards.c */ 717/* Provided by em28xx-cards.c */
715extern int em2800_variant_detect(struct usb_device *udev, int model);
716extern struct em28xx_board em28xx_boards[]; 718extern struct em28xx_board em28xx_boards[];
717extern struct usb_device_id em28xx_id_table[]; 719extern struct usb_device_id em28xx_id_table[];
718extern const unsigned int em28xx_bcount;
719int em28xx_tuner_callback(void *ptr, int component, int command, int arg); 720int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
720void em28xx_release_resources(struct em28xx *dev); 721void em28xx_release_resources(struct em28xx *dev);
721 722
722/* Provided by em28xx-vbi.c */ 723/* Provided by em28xx-vbi.c */
723extern struct vb2_ops em28xx_vbi_qops; 724extern struct vb2_ops em28xx_vbi_qops;
724 725
726/* Provided by em28xx-camera.c */
727int em28xx_detect_sensor(struct em28xx *dev);
728int em28xx_init_camera(struct em28xx *dev);
729
725/* printk macros */ 730/* printk macros */
726 731
727#define em28xx_err(fmt, arg...) do {\ 732#define em28xx_err(fmt, arg...) do {\
@@ -744,72 +749,6 @@ static inline int em28xx_compression_disable(struct em28xx *dev)
744 return em28xx_write_reg(dev, EM28XX_R26_COMPR, 0x00); 749 return em28xx_write_reg(dev, EM28XX_R26_COMPR, 0x00);
745} 750}
746 751
747static inline int em28xx_contrast_get(struct em28xx *dev)
748{
749 return em28xx_read_reg(dev, EM28XX_R20_YGAIN) & 0x1f;
750}
751
752static inline int em28xx_brightness_get(struct em28xx *dev)
753{
754 return em28xx_read_reg(dev, EM28XX_R21_YOFFSET);
755}
756
757static inline int em28xx_saturation_get(struct em28xx *dev)
758{
759 return em28xx_read_reg(dev, EM28XX_R22_UVGAIN) & 0x1f;
760}
761
762static inline int em28xx_u_balance_get(struct em28xx *dev)
763{
764 return em28xx_read_reg(dev, EM28XX_R23_UOFFSET);
765}
766
767static inline int em28xx_v_balance_get(struct em28xx *dev)
768{
769 return em28xx_read_reg(dev, EM28XX_R24_VOFFSET);
770}
771
772static inline int em28xx_gamma_get(struct em28xx *dev)
773{
774 return em28xx_read_reg(dev, EM28XX_R14_GAMMA) & 0x3f;
775}
776
777static inline int em28xx_contrast_set(struct em28xx *dev, s32 val)
778{
779 u8 tmp = (u8) val;
780 return em28xx_write_regs(dev, EM28XX_R20_YGAIN, &tmp, 1);
781}
782
783static inline int em28xx_brightness_set(struct em28xx *dev, s32 val)
784{
785 u8 tmp = (u8) val;
786 return em28xx_write_regs(dev, EM28XX_R21_YOFFSET, &tmp, 1);
787}
788
789static inline int em28xx_saturation_set(struct em28xx *dev, s32 val)
790{
791 u8 tmp = (u8) val;
792 return em28xx_write_regs(dev, EM28XX_R22_UVGAIN, &tmp, 1);
793}
794
795static inline int em28xx_u_balance_set(struct em28xx *dev, s32 val)
796{
797 u8 tmp = (u8) val;
798 return em28xx_write_regs(dev, EM28XX_R23_UOFFSET, &tmp, 1);
799}
800
801static inline int em28xx_v_balance_set(struct em28xx *dev, s32 val)
802{
803 u8 tmp = (u8) val;
804 return em28xx_write_regs(dev, EM28XX_R24_VOFFSET, &tmp, 1);
805}
806
807static inline int em28xx_gamma_set(struct em28xx *dev, s32 val)
808{
809 u8 tmp = (u8) val;
810 return em28xx_write_regs(dev, EM28XX_R14_GAMMA, &tmp, 1);
811}
812
813/*FIXME: maxw should be dependent of alt mode */ 752/*FIXME: maxw should be dependent of alt mode */
814static inline unsigned int norm_maxw(struct em28xx *dev) 753static inline unsigned int norm_maxw(struct em28xx *dev)
815{ 754{
diff --git a/drivers/media/usb/gspca/autogain_functions.h b/drivers/media/usb/gspca/autogain_functions.h
deleted file mode 100644
index d625eafe63eb..000000000000
--- a/drivers/media/usb/gspca/autogain_functions.h
+++ /dev/null
@@ -1,183 +0,0 @@
1/*
2 * Functions for auto gain.
3 *
4 * Copyright (C) 2010-2011 Hans de Goede <hdegoede@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifdef WANT_REGULAR_AUTOGAIN
22/* auto gain and exposure algorithm based on the knee algorithm described here:
23 http://ytse.tricolour.net/docs/LowLightOptimization.html
24
25 Returns 0 if no changes were made, 1 if the gain and or exposure settings
26 where changed. */
27static inline int auto_gain_n_exposure(
28 struct gspca_dev *gspca_dev,
29 int avg_lum,
30 int desired_avg_lum,
31 int deadzone,
32 int gain_knee,
33 int exposure_knee)
34{
35 struct sd *sd = (struct sd *) gspca_dev;
36 int i, steps, gain, orig_gain, exposure, orig_exposure;
37 int retval = 0;
38
39 orig_gain = gain = sd->ctrls[GAIN].val;
40 orig_exposure = exposure = sd->ctrls[EXPOSURE].val;
41
42 /* If we are of a multiple of deadzone, do multiple steps to reach the
43 desired lumination fast (with the risc of a slight overshoot) */
44 steps = abs(desired_avg_lum - avg_lum) / deadzone;
45
46 PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d",
47 avg_lum, desired_avg_lum, steps);
48
49 for (i = 0; i < steps; i++) {
50 if (avg_lum > desired_avg_lum) {
51 if (gain > gain_knee)
52 gain--;
53 else if (exposure > exposure_knee)
54 exposure--;
55 else if (gain > sd->ctrls[GAIN].def)
56 gain--;
57 else if (exposure > sd->ctrls[EXPOSURE].min)
58 exposure--;
59 else if (gain > sd->ctrls[GAIN].min)
60 gain--;
61 else
62 break;
63 } else {
64 if (gain < sd->ctrls[GAIN].def)
65 gain++;
66 else if (exposure < exposure_knee)
67 exposure++;
68 else if (gain < gain_knee)
69 gain++;
70 else if (exposure < sd->ctrls[EXPOSURE].max)
71 exposure++;
72 else if (gain < sd->ctrls[GAIN].max)
73 gain++;
74 else
75 break;
76 }
77 }
78
79 if (gain != orig_gain) {
80 sd->ctrls[GAIN].val = gain;
81 setgain(gspca_dev);
82 retval = 1;
83 }
84 if (exposure != orig_exposure) {
85 sd->ctrls[EXPOSURE].val = exposure;
86 setexposure(gspca_dev);
87 retval = 1;
88 }
89
90 if (retval)
91 PDEBUG(D_FRAM, "autogain: changed gain: %d, expo: %d",
92 gain, exposure);
93 return retval;
94}
95#endif
96
97#ifdef WANT_COARSE_EXPO_AUTOGAIN
98/* Autogain + exposure algorithm for cameras with a coarse exposure control
99 (usually this means we can only control the clockdiv to change exposure)
100 As changing the clockdiv so that the fps drops from 30 to 15 fps for
101 example, will lead to a huge exposure change (it effectively doubles),
102 this algorithm normally tries to only adjust the gain (between 40 and
103 80 %) and if that does not help, only then changes exposure. This leads
104 to a much more stable image then using the knee algorithm which at
105 certain points of the knee graph will only try to adjust exposure,
106 which leads to oscilating as one exposure step is huge.
107
108 Note this assumes that the sd struct for the cam in question has
109 exp_too_low_cnt and exp_too_high_cnt int members for use by this function.
110
111 Returns 0 if no changes were made, 1 if the gain and or exposure settings
112 where changed. */
113static inline int coarse_grained_expo_autogain(
114 struct gspca_dev *gspca_dev,
115 int avg_lum,
116 int desired_avg_lum,
117 int deadzone)
118{
119 struct sd *sd = (struct sd *) gspca_dev;
120 int steps, gain, orig_gain, exposure, orig_exposure;
121 int gain_low, gain_high;
122 int retval = 0;
123
124 orig_gain = gain = sd->ctrls[GAIN].val;
125 orig_exposure = exposure = sd->ctrls[EXPOSURE].val;
126
127 gain_low = (sd->ctrls[GAIN].max - sd->ctrls[GAIN].min) / 5 * 2;
128 gain_low += sd->ctrls[GAIN].min;
129 gain_high = (sd->ctrls[GAIN].max - sd->ctrls[GAIN].min) / 5 * 4;
130 gain_high += sd->ctrls[GAIN].min;
131
132 /* If we are of a multiple of deadzone, do multiple steps to reach the
133 desired lumination fast (with the risc of a slight overshoot) */
134 steps = (desired_avg_lum - avg_lum) / deadzone;
135
136 PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d",
137 avg_lum, desired_avg_lum, steps);
138
139 if ((gain + steps) > gain_high &&
140 exposure < sd->ctrls[EXPOSURE].max) {
141 gain = gain_high;
142 sd->exp_too_low_cnt++;
143 sd->exp_too_high_cnt = 0;
144 } else if ((gain + steps) < gain_low &&
145 exposure > sd->ctrls[EXPOSURE].min) {
146 gain = gain_low;
147 sd->exp_too_high_cnt++;
148 sd->exp_too_low_cnt = 0;
149 } else {
150 gain += steps;
151 if (gain > sd->ctrls[GAIN].max)
152 gain = sd->ctrls[GAIN].max;
153 else if (gain < sd->ctrls[GAIN].min)
154 gain = sd->ctrls[GAIN].min;
155 sd->exp_too_high_cnt = 0;
156 sd->exp_too_low_cnt = 0;
157 }
158
159 if (sd->exp_too_high_cnt > 3) {
160 exposure--;
161 sd->exp_too_high_cnt = 0;
162 } else if (sd->exp_too_low_cnt > 3) {
163 exposure++;
164 sd->exp_too_low_cnt = 0;
165 }
166
167 if (gain != orig_gain) {
168 sd->ctrls[GAIN].val = gain;
169 setgain(gspca_dev);
170 retval = 1;
171 }
172 if (exposure != orig_exposure) {
173 sd->ctrls[EXPOSURE].val = exposure;
174 setexposure(gspca_dev);
175 retval = 1;
176 }
177
178 if (retval)
179 PDEBUG(D_FRAM, "autogain: changed gain: %d, expo: %d",
180 gain, exposure);
181 return retval;
182}
183#endif
diff --git a/drivers/media/usb/gspca/benq.c b/drivers/media/usb/gspca/benq.c
index 352f32190e68..05f406deae13 100644
--- a/drivers/media/usb/gspca/benq.c
+++ b/drivers/media/usb/gspca/benq.c
@@ -186,7 +186,7 @@ static void sd_isoc_irq(struct urb *urb)
186 /* check the packet status and length */ 186 /* check the packet status and length */
187 if (urb0->iso_frame_desc[i].actual_length != SD_PKT_SZ 187 if (urb0->iso_frame_desc[i].actual_length != SD_PKT_SZ
188 || urb->iso_frame_desc[i].actual_length != SD_PKT_SZ) { 188 || urb->iso_frame_desc[i].actual_length != SD_PKT_SZ) {
189 PDEBUG(D_ERR, "ISOC bad lengths %d / %d", 189 PERR("ISOC bad lengths %d / %d",
190 urb0->iso_frame_desc[i].actual_length, 190 urb0->iso_frame_desc[i].actual_length,
191 urb->iso_frame_desc[i].actual_length); 191 urb->iso_frame_desc[i].actual_length);
192 gspca_dev->last_packet_type = DISCARD_PACKET; 192 gspca_dev->last_packet_type = DISCARD_PACKET;
diff --git a/drivers/media/usb/gspca/conex.c b/drivers/media/usb/gspca/conex.c
index c9052f20435e..38714df31ac4 100644
--- a/drivers/media/usb/gspca/conex.c
+++ b/drivers/media/usb/gspca/conex.c
@@ -73,12 +73,11 @@ static void reg_r(struct gspca_dev *gspca_dev,
73{ 73{
74 struct usb_device *dev = gspca_dev->dev; 74 struct usb_device *dev = gspca_dev->dev;
75 75
76#ifdef GSPCA_DEBUG
77 if (len > USB_BUF_SZ) { 76 if (len > USB_BUF_SZ) {
78 pr_err("reg_r: buffer overflow\n"); 77 PERR("reg_r: buffer overflow\n");
79 return; 78 return;
80 } 79 }
81#endif 80
82 usb_control_msg(dev, 81 usb_control_msg(dev,
83 usb_rcvctrlpipe(dev, 0), 82 usb_rcvctrlpipe(dev, 0),
84 0, 83 0,
@@ -113,13 +112,12 @@ static void reg_w(struct gspca_dev *gspca_dev,
113{ 112{
114 struct usb_device *dev = gspca_dev->dev; 113 struct usb_device *dev = gspca_dev->dev;
115 114
116#ifdef GSPCA_DEBUG
117 if (len > USB_BUF_SZ) { 115 if (len > USB_BUF_SZ) {
118 pr_err("reg_w: buffer overflow\n"); 116 PERR("reg_w: buffer overflow\n");
119 return; 117 return;
120 } 118 }
121 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer); 119 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
122#endif 120
123 memcpy(gspca_dev->usb_buf, buffer, len); 121 memcpy(gspca_dev->usb_buf, buffer, len);
124 usb_control_msg(dev, 122 usb_control_msg(dev,
125 usb_sndctrlpipe(dev, 0), 123 usb_sndctrlpipe(dev, 0),
@@ -689,7 +687,7 @@ static void cx11646_jpeg(struct gspca_dev*gspca_dev)
689 reg_w_val(gspca_dev, 0x0053, 0x00); 687 reg_w_val(gspca_dev, 0x0053, 0x00);
690 } while (--retry); 688 } while (--retry);
691 if (retry == 0) 689 if (retry == 0)
692 PDEBUG(D_ERR, "Damned Errors sending jpeg Table"); 690 PERR("Damned Errors sending jpeg Table");
693 /* send the qtable now */ 691 /* send the qtable now */
694 reg_r(gspca_dev, 0x0001, 1); /* -> 0x18 */ 692 reg_r(gspca_dev, 0x0001, 1); /* -> 0x18 */
695 length = 8; 693 length = 8;
diff --git a/drivers/media/usb/gspca/cpia1.c b/drivers/media/usb/gspca/cpia1.c
index 1dcdd9f95f1c..064b53043b15 100644
--- a/drivers/media/usb/gspca/cpia1.c
+++ b/drivers/media/usb/gspca/cpia1.c
@@ -421,8 +421,7 @@ static int cpia_usb_transferCmd(struct gspca_dev *gspca_dev, u8 *command)
421 pipe = usb_sndctrlpipe(gspca_dev->dev, 0); 421 pipe = usb_sndctrlpipe(gspca_dev->dev, 0);
422 requesttype = USB_TYPE_VENDOR | USB_RECIP_DEVICE; 422 requesttype = USB_TYPE_VENDOR | USB_RECIP_DEVICE;
423 } else { 423 } else {
424 PDEBUG(D_ERR, "Unexpected first byte of command: %x", 424 PERR("Unexpected first byte of command: %x", command[0]);
425 command[0]);
426 return -EINVAL; 425 return -EINVAL;
427 } 426 }
428 427
@@ -701,7 +700,7 @@ static void reset_camera_params(struct gspca_dev *gspca_dev)
701 params->qx3.cradled = 0; 700 params->qx3.cradled = 0;
702} 701}
703 702
704static void printstatus(struct cam_params *params) 703static void printstatus(struct gspca_dev *gspca_dev, struct cam_params *params)
705{ 704{
706 PDEBUG(D_PROBE, "status: %02x %02x %02x %02x %02x %02x %02x %02x", 705 PDEBUG(D_PROBE, "status: %02x %02x %02x %02x %02x %02x %02x %02x",
707 params->status.systemState, params->status.grabState, 706 params->status.systemState, params->status.grabState,
@@ -725,10 +724,9 @@ static int goto_low_power(struct gspca_dev *gspca_dev)
725 724
726 if (sd->params.status.systemState != LO_POWER_STATE) { 725 if (sd->params.status.systemState != LO_POWER_STATE) {
727 if (sd->params.status.systemState != WARM_BOOT_STATE) { 726 if (sd->params.status.systemState != WARM_BOOT_STATE) {
728 PDEBUG(D_ERR, 727 PERR("unexpected state after lo power cmd: %02x",
729 "unexpected state after lo power cmd: %02x", 728 sd->params.status.systemState);
730 sd->params.status.systemState); 729 printstatus(gspca_dev, &sd->params);
731 printstatus(&sd->params);
732 } 730 }
733 return -EIO; 731 return -EIO;
734 } 732 }
@@ -756,9 +754,9 @@ static int goto_high_power(struct gspca_dev *gspca_dev)
756 return ret; 754 return ret;
757 755
758 if (sd->params.status.systemState != HI_POWER_STATE) { 756 if (sd->params.status.systemState != HI_POWER_STATE) {
759 PDEBUG(D_ERR, "unexpected state after hi power cmd: %02x", 757 PERR("unexpected state after hi power cmd: %02x",
760 sd->params.status.systemState); 758 sd->params.status.systemState);
761 printstatus(&sd->params); 759 printstatus(gspca_dev, &sd->params);
762 return -EIO; 760 return -EIO;
763 } 761 }
764 762
@@ -1449,8 +1447,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
1449 sd->params.version.firmwareVersion = 0; 1447 sd->params.version.firmwareVersion = 0;
1450 get_version_information(gspca_dev); 1448 get_version_information(gspca_dev);
1451 if (sd->params.version.firmwareVersion != 1) { 1449 if (sd->params.version.firmwareVersion != 1) {
1452 PDEBUG(D_ERR, "only firmware version 1 is supported (got: %d)", 1450 PERR("only firmware version 1 is supported (got: %d)",
1453 sd->params.version.firmwareVersion); 1451 sd->params.version.firmwareVersion);
1454 return -ENODEV; 1452 return -ENODEV;
1455 } 1453 }
1456 1454
@@ -1475,9 +1473,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
1475 /* Start the camera in low power mode */ 1473 /* Start the camera in low power mode */
1476 if (goto_low_power(gspca_dev)) { 1474 if (goto_low_power(gspca_dev)) {
1477 if (sd->params.status.systemState != WARM_BOOT_STATE) { 1475 if (sd->params.status.systemState != WARM_BOOT_STATE) {
1478 PDEBUG(D_ERR, "unexpected systemstate: %02x", 1476 PERR("unexpected systemstate: %02x",
1479 sd->params.status.systemState); 1477 sd->params.status.systemState);
1480 printstatus(&sd->params); 1478 printstatus(gspca_dev, &sd->params);
1481 return -ENODEV; 1479 return -ENODEV;
1482 } 1480 }
1483 1481
@@ -1523,9 +1521,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
1523 return ret; 1521 return ret;
1524 1522
1525 if (sd->params.status.fatalError) { 1523 if (sd->params.status.fatalError) {
1526 PDEBUG(D_ERR, "fatal_error: %04x, vp_status: %04x", 1524 PERR("fatal_error: %04x, vp_status: %04x",
1527 sd->params.status.fatalError, 1525 sd->params.status.fatalError, sd->params.status.vpStatus);
1528 sd->params.status.vpStatus);
1529 return -EIO; 1526 return -EIO;
1530 } 1527 }
1531 1528
diff --git a/drivers/media/usb/gspca/etoms.c b/drivers/media/usb/gspca/etoms.c
index 38f68e11c3a2..26c9ee1f1045 100644
--- a/drivers/media/usb/gspca/etoms.c
+++ b/drivers/media/usb/gspca/etoms.c
@@ -163,12 +163,11 @@ static void reg_r(struct gspca_dev *gspca_dev,
163{ 163{
164 struct usb_device *dev = gspca_dev->dev; 164 struct usb_device *dev = gspca_dev->dev;
165 165
166#ifdef GSPCA_DEBUG
167 if (len > USB_BUF_SZ) { 166 if (len > USB_BUF_SZ) {
168 pr_err("reg_r: buffer overflow\n"); 167 PERR("reg_r: buffer overflow\n");
169 return; 168 return;
170 } 169 }
171#endif 170
172 usb_control_msg(dev, 171 usb_control_msg(dev,
173 usb_rcvctrlpipe(dev, 0), 172 usb_rcvctrlpipe(dev, 0),
174 0, 173 0,
@@ -201,13 +200,12 @@ static void reg_w(struct gspca_dev *gspca_dev,
201{ 200{
202 struct usb_device *dev = gspca_dev->dev; 201 struct usb_device *dev = gspca_dev->dev;
203 202
204#ifdef GSPCA_DEBUG
205 if (len > USB_BUF_SZ) { 203 if (len > USB_BUF_SZ) {
206 pr_err("reg_w: buffer overflow\n"); 204 pr_err("reg_w: buffer overflow\n");
207 return; 205 return;
208 } 206 }
209 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer); 207 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
210#endif 208
211 memcpy(gspca_dev->usb_buf, buffer, len); 209 memcpy(gspca_dev->usb_buf, buffer, len);
212 usb_control_msg(dev, 210 usb_control_msg(dev,
213 usb_sndctrlpipe(dev, 0), 211 usb_sndctrlpipe(dev, 0),
@@ -274,7 +272,7 @@ static int et_video(struct gspca_dev *gspca_dev,
274 : 0); /* stopvideo */ 272 : 0); /* stopvideo */
275 ret = Et_WaitStatus(gspca_dev); 273 ret = Et_WaitStatus(gspca_dev);
276 if (ret != 0) 274 if (ret != 0)
277 PDEBUG(D_ERR, "timeout video on/off"); 275 PERR("timeout video on/off");
278 return ret; 276 return ret;
279} 277}
280 278
@@ -768,9 +766,7 @@ static const struct sd_desc sd_desc = {
768/* -- module initialisation -- */ 766/* -- module initialisation -- */
769static const struct usb_device_id device_table[] = { 767static const struct usb_device_id device_table[] = {
770 {USB_DEVICE(0x102c, 0x6151), .driver_info = SENSOR_PAS106}, 768 {USB_DEVICE(0x102c, 0x6151), .driver_info = SENSOR_PAS106},
771#if !defined CONFIG_USB_ET61X251 && !defined CONFIG_USB_ET61X251_MODULE
772 {USB_DEVICE(0x102c, 0x6251), .driver_info = SENSOR_TAS5130CXX}, 769 {USB_DEVICE(0x102c, 0x6251), .driver_info = SENSOR_TAS5130CXX},
773#endif
774 {} 770 {}
775}; 771};
776 772
diff --git a/drivers/media/usb/gspca/gl860/gl860.c b/drivers/media/usb/gspca/gl860/gl860.c
index ced3b71f14e5..cb1e64ca59c9 100644
--- a/drivers/media/usb/gspca/gl860/gl860.c
+++ b/drivers/media/usb/gspca/gl860/gl860.c
@@ -58,115 +58,135 @@ MODULE_PARM_DESC(sensor,
58 58
59/*============================ webcam controls =============================*/ 59/*============================ webcam controls =============================*/
60 60
61/* Functions to get and set a control value */ 61static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
62#define SD_SETGET(thename) \ 62{
63static int sd_set_##thename(struct gspca_dev *gspca_dev, s32 val)\ 63 struct gspca_dev *gspca_dev =
64{\ 64 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
65 struct sd *sd = (struct sd *) gspca_dev;\ 65 struct sd *sd = (struct sd *) gspca_dev;
66\
67 sd->vcur.thename = val;\
68 if (gspca_dev->streaming)\
69 sd->waitSet = 1;\
70 return 0;\
71} \
72static int sd_get_##thename(struct gspca_dev *gspca_dev, s32 *val)\
73{\
74 struct sd *sd = (struct sd *) gspca_dev;\
75\
76 *val = sd->vcur.thename;\
77 return 0;\
78}
79 66
80SD_SETGET(mirror) 67 switch (ctrl->id) {
81SD_SETGET(flip) 68 case V4L2_CID_BRIGHTNESS:
82SD_SETGET(AC50Hz) 69 sd->vcur.brightness = ctrl->val;
83SD_SETGET(backlight) 70 break;
84SD_SETGET(brightness) 71 case V4L2_CID_CONTRAST:
85SD_SETGET(gamma) 72 sd->vcur.contrast = ctrl->val;
86SD_SETGET(hue) 73 break;
87SD_SETGET(saturation) 74 case V4L2_CID_SATURATION:
88SD_SETGET(sharpness) 75 sd->vcur.saturation = ctrl->val;
89SD_SETGET(whitebal) 76 break;
90SD_SETGET(contrast) 77 case V4L2_CID_HUE:
91 78 sd->vcur.hue = ctrl->val;
92#define GL860_NCTRLS 11 79 break;
93 80 case V4L2_CID_GAMMA:
94/* control table */ 81 sd->vcur.gamma = ctrl->val;
95static struct ctrl sd_ctrls_mi1320[GL860_NCTRLS]; 82 break;
96static struct ctrl sd_ctrls_mi2020[GL860_NCTRLS]; 83 case V4L2_CID_HFLIP:
97static struct ctrl sd_ctrls_ov2640[GL860_NCTRLS]; 84 sd->vcur.mirror = ctrl->val;
98static struct ctrl sd_ctrls_ov9655[GL860_NCTRLS]; 85 break;
99 86 case V4L2_CID_VFLIP:
100#define SET_MY_CTRL(theid, \ 87 sd->vcur.flip = ctrl->val;
101 thetype, thelabel, thename) \ 88 break;
102 if (sd->vmax.thename != 0) {\ 89 case V4L2_CID_POWER_LINE_FREQUENCY:
103 sd_ctrls[nCtrls].qctrl.id = theid;\ 90 sd->vcur.AC50Hz = ctrl->val;
104 sd_ctrls[nCtrls].qctrl.type = thetype;\ 91 break;
105 strcpy(sd_ctrls[nCtrls].qctrl.name, thelabel);\ 92 case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
106 sd_ctrls[nCtrls].qctrl.minimum = 0;\ 93 sd->vcur.whitebal = ctrl->val;
107 sd_ctrls[nCtrls].qctrl.maximum = sd->vmax.thename;\ 94 break;
108 sd_ctrls[nCtrls].qctrl.default_value = sd->vcur.thename;\ 95 case V4L2_CID_SHARPNESS:
109 sd_ctrls[nCtrls].qctrl.step = \ 96 sd->vcur.sharpness = ctrl->val;
110 (sd->vmax.thename < 16) ? 1 : sd->vmax.thename/16;\ 97 break;
111 sd_ctrls[nCtrls].set = sd_set_##thename;\ 98 case V4L2_CID_BACKLIGHT_COMPENSATION:
112 sd_ctrls[nCtrls].get = sd_get_##thename;\ 99 sd->vcur.backlight = ctrl->val;
113 nCtrls++;\ 100 break;
101 default:
102 return -EINVAL;
114 } 103 }
115 104
116static int gl860_build_control_table(struct gspca_dev *gspca_dev) 105 if (gspca_dev->streaming)
106 sd->waitSet = 1;
107
108 return 0;
109}
110
111static const struct v4l2_ctrl_ops sd_ctrl_ops = {
112 .s_ctrl = sd_s_ctrl,
113};
114
115static int sd_init_controls(struct gspca_dev *gspca_dev)
117{ 116{
118 struct sd *sd = (struct sd *) gspca_dev; 117 struct sd *sd = (struct sd *) gspca_dev;
119 struct ctrl *sd_ctrls; 118 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
120 int nCtrls = 0; 119
121 120 gspca_dev->vdev.ctrl_handler = hdl;
122 if (_MI1320_) 121 v4l2_ctrl_handler_init(hdl, 11);
123 sd_ctrls = sd_ctrls_mi1320; 122
124 else if (_MI2020_) 123 if (sd->vmax.brightness)
125 sd_ctrls = sd_ctrls_mi2020; 124 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_BRIGHTNESS,
126 else if (_OV2640_) 125 0, sd->vmax.brightness, 1,
127 sd_ctrls = sd_ctrls_ov2640; 126 sd->vcur.brightness);
128 else if (_OV9655_) 127
129 sd_ctrls = sd_ctrls_ov9655; 128 if (sd->vmax.contrast)
130 else 129 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_CONTRAST,
131 return 0; 130 0, sd->vmax.contrast, 1,
132 131 sd->vcur.contrast);
133 memset(sd_ctrls, 0, GL860_NCTRLS * sizeof(struct ctrl)); 132
134 133 if (sd->vmax.saturation)
135 SET_MY_CTRL(V4L2_CID_BRIGHTNESS, 134 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_SATURATION,
136 V4L2_CTRL_TYPE_INTEGER, "Brightness", brightness) 135 0, sd->vmax.saturation, 1,
137 SET_MY_CTRL(V4L2_CID_SHARPNESS, 136 sd->vcur.saturation);
138 V4L2_CTRL_TYPE_INTEGER, "Sharpness", sharpness) 137
139 SET_MY_CTRL(V4L2_CID_CONTRAST, 138 if (sd->vmax.hue)
140 V4L2_CTRL_TYPE_INTEGER, "Contrast", contrast) 139 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_HUE,
141 SET_MY_CTRL(V4L2_CID_GAMMA, 140 0, sd->vmax.hue, 1, sd->vcur.hue);
142 V4L2_CTRL_TYPE_INTEGER, "Gamma", gamma) 141
143 SET_MY_CTRL(V4L2_CID_HUE, 142 if (sd->vmax.gamma)
144 V4L2_CTRL_TYPE_INTEGER, "Palette", hue) 143 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_GAMMA,
145 SET_MY_CTRL(V4L2_CID_SATURATION, 144 0, sd->vmax.gamma, 1, sd->vcur.gamma);
146 V4L2_CTRL_TYPE_INTEGER, "Saturation", saturation) 145
147 SET_MY_CTRL(V4L2_CID_WHITE_BALANCE_TEMPERATURE, 146 if (sd->vmax.mirror)
148 V4L2_CTRL_TYPE_INTEGER, "White Bal.", whitebal) 147 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_HFLIP,
149 SET_MY_CTRL(V4L2_CID_BACKLIGHT_COMPENSATION, 148 0, sd->vmax.mirror, 1, sd->vcur.mirror);
150 V4L2_CTRL_TYPE_INTEGER, "Backlight" , backlight) 149
151 150 if (sd->vmax.flip)
152 SET_MY_CTRL(V4L2_CID_HFLIP, 151 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_VFLIP,
153 V4L2_CTRL_TYPE_BOOLEAN, "Mirror", mirror) 152 0, sd->vmax.flip, 1, sd->vcur.flip);
154 SET_MY_CTRL(V4L2_CID_VFLIP, 153
155 V4L2_CTRL_TYPE_BOOLEAN, "Flip", flip) 154 if (sd->vmax.AC50Hz)
156 SET_MY_CTRL(V4L2_CID_POWER_LINE_FREQUENCY, 155 v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
157 V4L2_CTRL_TYPE_BOOLEAN, "AC power 50Hz", AC50Hz) 156 V4L2_CID_POWER_LINE_FREQUENCY,
158 157 sd->vmax.AC50Hz, 0, sd->vcur.AC50Hz);
159 return nCtrls; 158
159 if (sd->vmax.whitebal)
160 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
161 V4L2_CID_WHITE_BALANCE_TEMPERATURE,
162 0, sd->vmax.whitebal, 1, sd->vcur.whitebal);
163
164 if (sd->vmax.sharpness)
165 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_SHARPNESS,
166 0, sd->vmax.sharpness, 1,
167 sd->vcur.sharpness);
168
169 if (sd->vmax.backlight)
170 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
171 V4L2_CID_BACKLIGHT_COMPENSATION,
172 0, sd->vmax.backlight, 1,
173 sd->vcur.backlight);
174
175 if (hdl->error) {
176 pr_err("Could not initialize controls\n");
177 return hdl->error;
178 }
179
180 return 0;
160} 181}
161 182
162/*==================== sud-driver structure initialisation =================*/ 183/*==================== sud-driver structure initialisation =================*/
163 184
164static const struct sd_desc sd_desc_mi1320 = { 185static const struct sd_desc sd_desc_mi1320 = {
165 .name = MODULE_NAME, 186 .name = MODULE_NAME,
166 .ctrls = sd_ctrls_mi1320,
167 .nctrls = GL860_NCTRLS,
168 .config = sd_config, 187 .config = sd_config,
169 .init = sd_init, 188 .init = sd_init,
189 .init_controls = sd_init_controls,
170 .isoc_init = sd_isoc_init, 190 .isoc_init = sd_isoc_init,
171 .start = sd_start, 191 .start = sd_start,
172 .stop0 = sd_stop0, 192 .stop0 = sd_stop0,
@@ -176,10 +196,9 @@ static const struct sd_desc sd_desc_mi1320 = {
176 196
177static const struct sd_desc sd_desc_mi2020 = { 197static const struct sd_desc sd_desc_mi2020 = {
178 .name = MODULE_NAME, 198 .name = MODULE_NAME,
179 .ctrls = sd_ctrls_mi2020,
180 .nctrls = GL860_NCTRLS,
181 .config = sd_config, 199 .config = sd_config,
182 .init = sd_init, 200 .init = sd_init,
201 .init_controls = sd_init_controls,
183 .isoc_init = sd_isoc_init, 202 .isoc_init = sd_isoc_init,
184 .start = sd_start, 203 .start = sd_start,
185 .stop0 = sd_stop0, 204 .stop0 = sd_stop0,
@@ -189,10 +208,9 @@ static const struct sd_desc sd_desc_mi2020 = {
189 208
190static const struct sd_desc sd_desc_ov2640 = { 209static const struct sd_desc sd_desc_ov2640 = {
191 .name = MODULE_NAME, 210 .name = MODULE_NAME,
192 .ctrls = sd_ctrls_ov2640,
193 .nctrls = GL860_NCTRLS,
194 .config = sd_config, 211 .config = sd_config,
195 .init = sd_init, 212 .init = sd_init,
213 .init_controls = sd_init_controls,
196 .isoc_init = sd_isoc_init, 214 .isoc_init = sd_isoc_init,
197 .start = sd_start, 215 .start = sd_start,
198 .stop0 = sd_stop0, 216 .stop0 = sd_stop0,
@@ -202,10 +220,9 @@ static const struct sd_desc sd_desc_ov2640 = {
202 220
203static const struct sd_desc sd_desc_ov9655 = { 221static const struct sd_desc sd_desc_ov9655 = {
204 .name = MODULE_NAME, 222 .name = MODULE_NAME,
205 .ctrls = sd_ctrls_ov9655,
206 .nctrls = GL860_NCTRLS,
207 .config = sd_config, 223 .config = sd_config,
208 .init = sd_init, 224 .init = sd_init,
225 .init_controls = sd_init_controls,
209 .isoc_init = sd_isoc_init, 226 .isoc_init = sd_isoc_init,
210 .start = sd_start, 227 .start = sd_start,
211 .stop0 = sd_stop0, 228 .stop0 = sd_stop0,
@@ -371,7 +388,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
371 dev_init_settings(gspca_dev); 388 dev_init_settings(gspca_dev);
372 if (AC50Hz != 0xff) 389 if (AC50Hz != 0xff)
373 ((struct sd *) gspca_dev)->vcur.AC50Hz = AC50Hz; 390 ((struct sd *) gspca_dev)->vcur.AC50Hz = AC50Hz;
374 gl860_build_control_table(gspca_dev);
375 391
376 return 0; 392 return 0;
377} 393}
@@ -566,7 +582,7 @@ int gl860_RTx(struct gspca_dev *gspca_dev,
566 pr_err("ctrl transfer failed %4d [p%02x r%d v%04x i%04x len%d]\n", 582 pr_err("ctrl transfer failed %4d [p%02x r%d v%04x i%04x len%d]\n",
567 r, pref, req, val, index, len); 583 r, pref, req, val, index, len);
568 else if (len > 1 && r < len) 584 else if (len > 1 && r < len)
569 PDEBUG(D_ERR, "short ctrl transfer %d/%d", r, len); 585 PERR("short ctrl transfer %d/%d", r, len);
570 586
571 msleep(1); 587 msleep(1);
572 588
diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 3564bdbb2ea3..5995ec4de6bc 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -60,14 +60,14 @@ MODULE_DESCRIPTION("GSPCA USB Camera Driver");
60MODULE_LICENSE("GPL"); 60MODULE_LICENSE("GPL");
61MODULE_VERSION(GSPCA_VERSION); 61MODULE_VERSION(GSPCA_VERSION);
62 62
63#ifdef GSPCA_DEBUG 63int gspca_debug;
64int gspca_debug = D_ERR | D_PROBE;
65EXPORT_SYMBOL(gspca_debug); 64EXPORT_SYMBOL(gspca_debug);
66 65
67static void PDEBUG_MODE(char *txt, __u32 pixfmt, int w, int h) 66static void PDEBUG_MODE(struct gspca_dev *gspca_dev, int debug, char *txt,
67 __u32 pixfmt, int w, int h)
68{ 68{
69 if ((pixfmt >> 24) >= '0' && (pixfmt >> 24) <= 'z') { 69 if ((pixfmt >> 24) >= '0' && (pixfmt >> 24) <= 'z') {
70 PDEBUG(D_CONF|D_STREAM, "%s %c%c%c%c %dx%d", 70 PDEBUG(debug, "%s %c%c%c%c %dx%d",
71 txt, 71 txt,
72 pixfmt & 0xff, 72 pixfmt & 0xff,
73 (pixfmt >> 8) & 0xff, 73 (pixfmt >> 8) & 0xff,
@@ -75,15 +75,12 @@ static void PDEBUG_MODE(char *txt, __u32 pixfmt, int w, int h)
75 pixfmt >> 24, 75 pixfmt >> 24,
76 w, h); 76 w, h);
77 } else { 77 } else {
78 PDEBUG(D_CONF|D_STREAM, "%s 0x%08x %dx%d", 78 PDEBUG(debug, "%s 0x%08x %dx%d",
79 txt, 79 txt,
80 pixfmt, 80 pixfmt,
81 w, h); 81 w, h);
82 } 82 }
83} 83}
84#else
85#define PDEBUG_MODE(txt, pixfmt, w, h)
86#endif
87 84
88/* specific memory types - !! should be different from V4L2_MEMORY_xxx */ 85/* specific memory types - !! should be different from V4L2_MEMORY_xxx */
89#define GSPCA_MEMORY_NO 0 /* V4L2_MEMORY_xxx starts from 1 */ 86#define GSPCA_MEMORY_NO 0 /* V4L2_MEMORY_xxx starts from 1 */
@@ -129,7 +126,7 @@ static void int_irq(struct urb *urb)
129 case 0: 126 case 0:
130 if (gspca_dev->sd_desc->int_pkt_scan(gspca_dev, 127 if (gspca_dev->sd_desc->int_pkt_scan(gspca_dev,
131 urb->transfer_buffer, urb->actual_length) < 0) { 128 urb->transfer_buffer, urb->actual_length) < 0) {
132 PDEBUG(D_ERR, "Unknown packet received"); 129 PERR("Unknown packet received");
133 } 130 }
134 break; 131 break;
135 132
@@ -143,7 +140,7 @@ static void int_irq(struct urb *urb)
143 break; 140 break;
144 141
145 default: 142 default:
146 PDEBUG(D_ERR, "URB error %i, resubmitting", urb->status); 143 PERR("URB error %i, resubmitting", urb->status);
147 urb->status = 0; 144 urb->status = 0;
148 ret = 0; 145 ret = 0;
149 } 146 }
@@ -229,7 +226,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
229 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 226 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
230 ret = usb_submit_urb(urb, GFP_KERNEL); 227 ret = usb_submit_urb(urb, GFP_KERNEL);
231 if (ret < 0) { 228 if (ret < 0) {
232 PDEBUG(D_ERR, "submit int URB failed with error %i", ret); 229 PERR("submit int URB failed with error %i", ret);
233 goto error_submit; 230 goto error_submit;
234 } 231 }
235 gspca_dev->int_urb = urb; 232 gspca_dev->int_urb = urb;
@@ -315,7 +312,7 @@ static void fill_frame(struct gspca_dev *gspca_dev,
315 if (gspca_dev->frozen) 312 if (gspca_dev->frozen)
316 return; 313 return;
317#endif 314#endif
318 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); 315 PERR("urb status: %d", urb->status);
319 urb->status = 0; 316 urb->status = 0;
320 goto resubmit; 317 goto resubmit;
321 } 318 }
@@ -388,7 +385,7 @@ static void bulk_irq(struct urb *urb)
388 if (gspca_dev->frozen) 385 if (gspca_dev->frozen)
389 return; 386 return;
390#endif 387#endif
391 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); 388 PERR("urb status: %d", urb->status);
392 urb->status = 0; 389 urb->status = 0;
393 goto resubmit; 390 goto resubmit;
394 } 391 }
@@ -460,7 +457,7 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
460 /* append the packet to the frame buffer */ 457 /* append the packet to the frame buffer */
461 if (len > 0) { 458 if (len > 0) {
462 if (gspca_dev->image_len + len > gspca_dev->frsz) { 459 if (gspca_dev->image_len + len > gspca_dev->frsz) {
463 PDEBUG(D_ERR|D_PACK, "frame overflow %d > %d", 460 PERR("frame overflow %d > %d",
464 gspca_dev->image_len + len, 461 gspca_dev->image_len + len,
465 gspca_dev->frsz); 462 gspca_dev->frsz);
466 packet_type = DISCARD_PACKET; 463 packet_type = DISCARD_PACKET;
@@ -570,11 +567,10 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
570 567
571 gspca_dev->urb[i] = NULL; 568 gspca_dev->urb[i] = NULL;
572 usb_kill_urb(urb); 569 usb_kill_urb(urb);
573 if (urb->transfer_buffer != NULL) 570 usb_free_coherent(gspca_dev->dev,
574 usb_free_coherent(gspca_dev->dev, 571 urb->transfer_buffer_length,
575 urb->transfer_buffer_length, 572 urb->transfer_buffer,
576 urb->transfer_buffer, 573 urb->transfer_dma);
577 urb->transfer_dma);
578 usb_free_urb(urb); 574 usb_free_urb(urb);
579 } 575 }
580} 576}
@@ -960,9 +956,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
960 /* the bandwidth is not wide enough 956 /* the bandwidth is not wide enough
961 * negotiate or try a lower alternate setting */ 957 * negotiate or try a lower alternate setting */
962retry: 958retry:
963 PDEBUG(D_ERR|D_STREAM, 959 PERR("alt %d - bandwidth not wide enough, trying again", alt);
964 "alt %d - bandwidth not wide enough - trying again",
965 alt);
966 msleep(20); /* wait for kill complete */ 960 msleep(20); /* wait for kill complete */
967 if (gspca_dev->sd_desc->isoc_nego) { 961 if (gspca_dev->sd_desc->isoc_nego) {
968 ret = gspca_dev->sd_desc->isoc_nego(gspca_dev); 962 ret = gspca_dev->sd_desc->isoc_nego(gspca_dev);
@@ -984,7 +978,6 @@ out:
984 978
985static void gspca_set_default_mode(struct gspca_dev *gspca_dev) 979static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
986{ 980{
987 struct gspca_ctrl *ctrl;
988 int i; 981 int i;
989 982
990 i = gspca_dev->cam.nmodes - 1; /* take the highest mode */ 983 i = gspca_dev->cam.nmodes - 1; /* take the highest mode */
@@ -993,17 +986,8 @@ static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
993 gspca_dev->height = gspca_dev->cam.cam_mode[i].height; 986 gspca_dev->height = gspca_dev->cam.cam_mode[i].height;
994 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat; 987 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat;
995 988
996 /* set the current control values to their default values
997 * which may have changed in sd_init() */
998 /* does nothing if ctrl_handler == NULL */ 989 /* does nothing if ctrl_handler == NULL */
999 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler); 990 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler);
1000 ctrl = gspca_dev->cam.ctrls;
1001 if (ctrl != NULL) {
1002 for (i = 0;
1003 i < gspca_dev->sd_desc->nctrls;
1004 i++, ctrl++)
1005 ctrl->val = ctrl->def;
1006 }
1007} 991}
1008 992
1009static int wxh_to_mode(struct gspca_dev *gspca_dev, 993static int wxh_to_mode(struct gspca_dev *gspca_dev,
@@ -1055,7 +1039,7 @@ static int vidioc_g_register(struct file *file, void *priv,
1055} 1039}
1056 1040
1057static int vidioc_s_register(struct file *file, void *priv, 1041static int vidioc_s_register(struct file *file, void *priv,
1058 struct v4l2_dbg_register *reg) 1042 const struct v4l2_dbg_register *reg)
1059{ 1043{
1060 struct gspca_dev *gspca_dev = video_drvdata(file); 1044 struct gspca_dev *gspca_dev = video_drvdata(file);
1061 1045
@@ -1137,10 +1121,9 @@ static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
1137 w = fmt->fmt.pix.width; 1121 w = fmt->fmt.pix.width;
1138 h = fmt->fmt.pix.height; 1122 h = fmt->fmt.pix.height;
1139 1123
1140#ifdef GSPCA_DEBUG 1124 PDEBUG_MODE(gspca_dev, D_CONF, "try fmt cap",
1141 if (gspca_debug & D_CONF) 1125 fmt->fmt.pix.pixelformat, w, h);
1142 PDEBUG_MODE("try fmt cap", fmt->fmt.pix.pixelformat, w, h); 1126
1143#endif
1144 /* search the closest mode for width and height */ 1127 /* search the closest mode for width and height */
1145 mode = wxh_to_mode(gspca_dev, w, h); 1128 mode = wxh_to_mode(gspca_dev, w, h);
1146 1129
@@ -1153,8 +1136,6 @@ static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
1153 fmt->fmt.pix.pixelformat); 1136 fmt->fmt.pix.pixelformat);
1154 if (mode2 >= 0) 1137 if (mode2 >= 0)
1155 mode = mode2; 1138 mode = mode2;
1156/* else
1157 ; * no chance, return this mode */
1158 } 1139 }
1159 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode]; 1140 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode];
1160 /* some drivers use priv internally, zero it before giving it to 1141 /* some drivers use priv internally, zero it before giving it to
@@ -1290,15 +1271,6 @@ static int dev_open(struct file *file)
1290 if (!try_module_get(gspca_dev->module)) 1271 if (!try_module_get(gspca_dev->module))
1291 return -ENODEV; 1272 return -ENODEV;
1292 1273
1293#ifdef GSPCA_DEBUG
1294 /* activate the v4l2 debug */
1295 if (gspca_debug & D_V4L2)
1296 gspca_dev->vdev.debug |= V4L2_DEBUG_IOCTL
1297 | V4L2_DEBUG_IOCTL_ARG;
1298 else
1299 gspca_dev->vdev.debug &= ~(V4L2_DEBUG_IOCTL
1300 | V4L2_DEBUG_IOCTL_ARG);
1301#endif
1302 return v4l2_fh_open(file); 1274 return v4l2_fh_open(file);
1303} 1275}
1304 1276
@@ -1357,134 +1329,6 @@ static int vidioc_querycap(struct file *file, void *priv,
1357 return 0; 1329 return 0;
1358} 1330}
1359 1331
1360static int get_ctrl(struct gspca_dev *gspca_dev,
1361 int id)
1362{
1363 const struct ctrl *ctrls;
1364 int i;
1365
1366 for (i = 0, ctrls = gspca_dev->sd_desc->ctrls;
1367 i < gspca_dev->sd_desc->nctrls;
1368 i++, ctrls++) {
1369 if (gspca_dev->ctrl_dis & (1 << i))
1370 continue;
1371 if (id == ctrls->qctrl.id)
1372 return i;
1373 }
1374 return -1;
1375}
1376
1377static int vidioc_queryctrl(struct file *file, void *priv,
1378 struct v4l2_queryctrl *q_ctrl)
1379{
1380 struct gspca_dev *gspca_dev = video_drvdata(file);
1381 const struct ctrl *ctrls;
1382 struct gspca_ctrl *gspca_ctrl;
1383 int i, idx;
1384 u32 id;
1385
1386 id = q_ctrl->id;
1387 if (id & V4L2_CTRL_FLAG_NEXT_CTRL) {
1388 id &= V4L2_CTRL_ID_MASK;
1389 id++;
1390 idx = -1;
1391 for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) {
1392 if (gspca_dev->ctrl_dis & (1 << i))
1393 continue;
1394 if (gspca_dev->sd_desc->ctrls[i].qctrl.id < id)
1395 continue;
1396 if (idx >= 0
1397 && gspca_dev->sd_desc->ctrls[i].qctrl.id
1398 > gspca_dev->sd_desc->ctrls[idx].qctrl.id)
1399 continue;
1400 idx = i;
1401 }
1402 } else {
1403 idx = get_ctrl(gspca_dev, id);
1404 }
1405 if (idx < 0)
1406 return -EINVAL;
1407 ctrls = &gspca_dev->sd_desc->ctrls[idx];
1408 memcpy(q_ctrl, &ctrls->qctrl, sizeof *q_ctrl);
1409 if (gspca_dev->cam.ctrls != NULL) {
1410 gspca_ctrl = &gspca_dev->cam.ctrls[idx];
1411 q_ctrl->default_value = gspca_ctrl->def;
1412 q_ctrl->minimum = gspca_ctrl->min;
1413 q_ctrl->maximum = gspca_ctrl->max;
1414 }
1415 if (gspca_dev->ctrl_inac & (1 << idx))
1416 q_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
1417 return 0;
1418}
1419
1420static int vidioc_s_ctrl(struct file *file, void *priv,
1421 struct v4l2_control *ctrl)
1422{
1423 struct gspca_dev *gspca_dev = video_drvdata(file);
1424 const struct ctrl *ctrls;
1425 struct gspca_ctrl *gspca_ctrl;
1426 int idx;
1427
1428 idx = get_ctrl(gspca_dev, ctrl->id);
1429 if (idx < 0)
1430 return -EINVAL;
1431 if (gspca_dev->ctrl_inac & (1 << idx))
1432 return -EINVAL;
1433 ctrls = &gspca_dev->sd_desc->ctrls[idx];
1434 if (gspca_dev->cam.ctrls != NULL) {
1435 gspca_ctrl = &gspca_dev->cam.ctrls[idx];
1436 if (ctrl->value < gspca_ctrl->min
1437 || ctrl->value > gspca_ctrl->max)
1438 return -ERANGE;
1439 } else {
1440 gspca_ctrl = NULL;
1441 if (ctrl->value < ctrls->qctrl.minimum
1442 || ctrl->value > ctrls->qctrl.maximum)
1443 return -ERANGE;
1444 }
1445 PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value);
1446 gspca_dev->usb_err = 0;
1447 if (ctrls->set != NULL)
1448 return ctrls->set(gspca_dev, ctrl->value);
1449 if (gspca_ctrl != NULL) {
1450 gspca_ctrl->val = ctrl->value;
1451 if (ctrls->set_control != NULL
1452 && gspca_dev->streaming)
1453 ctrls->set_control(gspca_dev);
1454 }
1455 return gspca_dev->usb_err;
1456}
1457
1458static int vidioc_g_ctrl(struct file *file, void *priv,
1459 struct v4l2_control *ctrl)
1460{
1461 struct gspca_dev *gspca_dev = video_drvdata(file);
1462 const struct ctrl *ctrls;
1463 int idx;
1464
1465 idx = get_ctrl(gspca_dev, ctrl->id);
1466 if (idx < 0)
1467 return -EINVAL;
1468 ctrls = &gspca_dev->sd_desc->ctrls[idx];
1469
1470 gspca_dev->usb_err = 0;
1471 if (ctrls->get != NULL)
1472 return ctrls->get(gspca_dev, &ctrl->value);
1473 if (gspca_dev->cam.ctrls != NULL)
1474 ctrl->value = gspca_dev->cam.ctrls[idx].val;
1475 return 0;
1476}
1477
1478static int vidioc_querymenu(struct file *file, void *priv,
1479 struct v4l2_querymenu *qmenu)
1480{
1481 struct gspca_dev *gspca_dev = video_drvdata(file);
1482
1483 if (!gspca_dev->sd_desc->querymenu)
1484 return -ENOTTY;
1485 return gspca_dev->sd_desc->querymenu(gspca_dev, qmenu);
1486}
1487
1488static int vidioc_enum_input(struct file *file, void *priv, 1332static int vidioc_enum_input(struct file *file, void *priv,
1489 struct v4l2_input *input) 1333 struct v4l2_input *input)
1490{ 1334{
@@ -1621,14 +1465,8 @@ static int vidioc_streamon(struct file *file, void *priv,
1621 if (ret < 0) 1465 if (ret < 0)
1622 goto out; 1466 goto out;
1623 } 1467 }
1624#ifdef GSPCA_DEBUG 1468 PDEBUG_MODE(gspca_dev, D_STREAM, "stream on OK", gspca_dev->pixfmt,
1625 if (gspca_debug & D_STREAM) { 1469 gspca_dev->width, gspca_dev->height);
1626 PDEBUG_MODE("stream on OK",
1627 gspca_dev->pixfmt,
1628 gspca_dev->width,
1629 gspca_dev->height);
1630 }
1631#endif
1632 ret = 0; 1470 ret = 0;
1633out: 1471out:
1634 mutex_unlock(&gspca_dev->queue_lock); 1472 mutex_unlock(&gspca_dev->queue_lock);
@@ -1879,8 +1717,7 @@ static int vidioc_dqbuf(struct file *file, void *priv,
1879 if (copy_to_user((__u8 __user *) frame->v4l2_buf.m.userptr, 1717 if (copy_to_user((__u8 __user *) frame->v4l2_buf.m.userptr,
1880 frame->data, 1718 frame->data,
1881 frame->v4l2_buf.bytesused)) { 1719 frame->v4l2_buf.bytesused)) {
1882 PDEBUG(D_ERR|D_STREAM, 1720 PERR("dqbuf cp to user failed");
1883 "dqbuf cp to user failed");
1884 ret = -EFAULT; 1721 ret = -EFAULT;
1885 } 1722 }
1886 } 1723 }
@@ -2092,8 +1929,7 @@ static ssize_t dev_read(struct file *file, char __user *data,
2092 count = frame->v4l2_buf.bytesused; 1929 count = frame->v4l2_buf.bytesused;
2093 ret = copy_to_user(data, frame->data, count); 1930 ret = copy_to_user(data, frame->data, count);
2094 if (ret != 0) { 1931 if (ret != 0) {
2095 PDEBUG(D_ERR|D_STREAM, 1932 PERR("read cp to user lack %d / %zd", ret, count);
2096 "read cp to user lack %d / %zd", ret, count);
2097 ret = -EFAULT; 1933 ret = -EFAULT;
2098 goto out; 1934 goto out;
2099 } 1935 }
@@ -2125,10 +1961,6 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
2125 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1961 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
2126 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1962 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2127 .vidioc_streamon = vidioc_streamon, 1963 .vidioc_streamon = vidioc_streamon,
2128 .vidioc_queryctrl = vidioc_queryctrl,
2129 .vidioc_g_ctrl = vidioc_g_ctrl,
2130 .vidioc_s_ctrl = vidioc_s_ctrl,
2131 .vidioc_querymenu = vidioc_querymenu,
2132 .vidioc_enum_input = vidioc_enum_input, 1964 .vidioc_enum_input = vidioc_enum_input,
2133 .vidioc_g_input = vidioc_g_input, 1965 .vidioc_g_input = vidioc_g_input,
2134 .vidioc_s_input = vidioc_s_input, 1966 .vidioc_s_input = vidioc_s_input,
@@ -2157,22 +1989,6 @@ static const struct video_device gspca_template = {
2157 .release = video_device_release_empty, /* We use v4l2_dev.release */ 1989 .release = video_device_release_empty, /* We use v4l2_dev.release */
2158}; 1990};
2159 1991
2160/* initialize the controls */
2161static void ctrls_init(struct gspca_dev *gspca_dev)
2162{
2163 struct gspca_ctrl *ctrl;
2164 int i;
2165
2166 for (i = 0, ctrl = gspca_dev->cam.ctrls;
2167 i < gspca_dev->sd_desc->nctrls;
2168 i++, ctrl++) {
2169 ctrl->def = gspca_dev->sd_desc->ctrls[i].qctrl.default_value;
2170 ctrl->val = ctrl->def;
2171 ctrl->min = gspca_dev->sd_desc->ctrls[i].qctrl.minimum;
2172 ctrl->max = gspca_dev->sd_desc->ctrls[i].qctrl.maximum;
2173 }
2174}
2175
2176/* 1992/*
2177 * probe and create a new gspca device 1993 * probe and create a new gspca device
2178 * 1994 *
@@ -2249,8 +2065,6 @@ int gspca_dev_probe2(struct usb_interface *intf,
2249 ret = sd_desc->config(gspca_dev, id); 2065 ret = sd_desc->config(gspca_dev, id);
2250 if (ret < 0) 2066 if (ret < 0)
2251 goto out; 2067 goto out;
2252 if (gspca_dev->cam.ctrls != NULL)
2253 ctrls_init(gspca_dev);
2254 ret = sd_desc->init(gspca_dev); 2068 ret = sd_desc->init(gspca_dev);
2255 if (ret < 0) 2069 if (ret < 0)
2256 goto out; 2070 goto out;
@@ -2450,10 +2264,6 @@ static void __exit gspca_exit(void)
2450module_init(gspca_init); 2264module_init(gspca_init);
2451module_exit(gspca_exit); 2265module_exit(gspca_exit);
2452 2266
2453#ifdef GSPCA_DEBUG
2454module_param_named(debug, gspca_debug, int, 0644); 2267module_param_named(debug, gspca_debug, int, 0644);
2455MODULE_PARM_DESC(debug, 2268MODULE_PARM_DESC(debug,
2456 "Debug (bit) 0x01:error 0x02:probe 0x04:config" 2269 "1:probe 2:config 3:stream 4:frame 5:packet 6:usbi 7:usbo");
2457 " 0x08:stream 0x10:frame 0x20:packet"
2458 " 0x0100: v4l2");
2459#endif
diff --git a/drivers/media/usb/gspca/gspca.h b/drivers/media/usb/gspca/gspca.h
index 5559932bf2f5..ef8efeb80070 100644
--- a/drivers/media/usb/gspca/gspca.h
+++ b/drivers/media/usb/gspca/gspca.h
@@ -10,30 +10,26 @@
10#include <media/v4l2-device.h> 10#include <media/v4l2-device.h>
11#include <linux/mutex.h> 11#include <linux/mutex.h>
12 12
13/* compilation option */
14/*#define GSPCA_DEBUG 1*/
15 13
16#ifdef GSPCA_DEBUG 14
17/* GSPCA our debug messages */ 15/* GSPCA debug codes */
16
17#define D_PROBE 1
18#define D_CONF 2
19#define D_STREAM 3
20#define D_FRAM 4
21#define D_PACK 5
22#define D_USBI 6
23#define D_USBO 7
24
18extern int gspca_debug; 25extern int gspca_debug;
19#define PDEBUG(level, fmt, ...) \
20do { \
21 if (gspca_debug & (level)) \
22 pr_info(fmt, ##__VA_ARGS__); \
23} while (0)
24 26
25#define D_ERR 0x01 27
26#define D_PROBE 0x02 28#define PDEBUG(level, fmt, ...) \
27#define D_CONF 0x04 29 v4l2_dbg(level, gspca_debug, &gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
28#define D_STREAM 0x08 30
29#define D_FRAM 0x10 31#define PERR(fmt, ...) \
30#define D_PACK 0x20 32 v4l2_err(&gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__)
31#define D_USBI 0x00
32#define D_USBO 0x00
33#define D_V4L2 0x0100
34#else
35#define PDEBUG(level, fmt, ...) do {} while(0)
36#endif
37 33
38#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */ 34#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
39/* image transfers */ 35/* image transfers */
@@ -46,20 +42,11 @@ struct framerates {
46 int nrates; 42 int nrates;
47}; 43};
48 44
49/* control definition */
50struct gspca_ctrl {
51 s16 val; /* current value */
52 s16 def; /* default value */
53 s16 min, max; /* minimum and maximum values */
54};
55
56/* device information - set at probe time */ 45/* device information - set at probe time */
57struct cam { 46struct cam {
58 const struct v4l2_pix_format *cam_mode; /* size nmodes */ 47 const struct v4l2_pix_format *cam_mode; /* size nmodes */
59 const struct framerates *mode_framerates; /* must have size nmodes, 48 const struct framerates *mode_framerates; /* must have size nmodes,
60 * just like cam_mode */ 49 * just like cam_mode */
61 struct gspca_ctrl *ctrls; /* control table - size nctrls */
62 /* may be NULL */
63 u32 bulk_size; /* buffer size when image transfer by bulk */ 50 u32 bulk_size; /* buffer size when image transfer by bulk */
64 u32 input_flags; /* value for ENUM_INPUT status flags */ 51 u32 input_flags; /* value for ENUM_INPUT status flags */
65 u8 nmodes; /* size of cam_mode */ 52 u8 nmodes; /* size of cam_mode */
@@ -87,14 +74,14 @@ typedef int (*cam_get_jpg_op) (struct gspca_dev *,
87 struct v4l2_jpegcompression *); 74 struct v4l2_jpegcompression *);
88typedef int (*cam_set_jpg_op) (struct gspca_dev *, 75typedef int (*cam_set_jpg_op) (struct gspca_dev *,
89 const struct v4l2_jpegcompression *); 76 const struct v4l2_jpegcompression *);
90typedef int (*cam_reg_op) (struct gspca_dev *, 77typedef int (*cam_get_reg_op) (struct gspca_dev *,
91 struct v4l2_dbg_register *); 78 struct v4l2_dbg_register *);
79typedef int (*cam_set_reg_op) (struct gspca_dev *,
80 const struct v4l2_dbg_register *);
92typedef int (*cam_ident_op) (struct gspca_dev *, 81typedef int (*cam_ident_op) (struct gspca_dev *,
93 struct v4l2_dbg_chip_ident *); 82 struct v4l2_dbg_chip_ident *);
94typedef void (*cam_streamparm_op) (struct gspca_dev *, 83typedef void (*cam_streamparm_op) (struct gspca_dev *,
95 struct v4l2_streamparm *); 84 struct v4l2_streamparm *);
96typedef int (*cam_qmnu_op) (struct gspca_dev *,
97 struct v4l2_querymenu *);
98typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, 85typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
99 u8 *data, 86 u8 *data,
100 int len); 87 int len);
@@ -102,20 +89,10 @@ typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
102 u8 *data, 89 u8 *data,
103 int len); 90 int len);
104 91
105struct ctrl {
106 struct v4l2_queryctrl qctrl;
107 int (*set)(struct gspca_dev *, __s32);
108 int (*get)(struct gspca_dev *, __s32 *);
109 cam_v_op set_control;
110};
111
112/* subdriver description */ 92/* subdriver description */
113struct sd_desc { 93struct sd_desc {
114/* information */ 94/* information */
115 const char *name; /* sub-driver name */ 95 const char *name; /* sub-driver name */
116/* controls */
117 const struct ctrl *ctrls; /* static control definition */
118 int nctrls;
119/* mandatory operations */ 96/* mandatory operations */
120 cam_cf_op config; /* called on probe */ 97 cam_cf_op config; /* called on probe */
121 cam_op init; /* called on probe and resume */ 98 cam_op init; /* called on probe and resume */
@@ -130,12 +107,11 @@ struct sd_desc {
130 cam_v_op dq_callback; /* called when a frame has been dequeued */ 107 cam_v_op dq_callback; /* called when a frame has been dequeued */
131 cam_get_jpg_op get_jcomp; 108 cam_get_jpg_op get_jcomp;
132 cam_set_jpg_op set_jcomp; 109 cam_set_jpg_op set_jcomp;
133 cam_qmnu_op querymenu;
134 cam_streamparm_op get_streamparm; 110 cam_streamparm_op get_streamparm;
135 cam_streamparm_op set_streamparm; 111 cam_streamparm_op set_streamparm;
136#ifdef CONFIG_VIDEO_ADV_DEBUG 112#ifdef CONFIG_VIDEO_ADV_DEBUG
137 cam_reg_op set_register; 113 cam_set_reg_op set_register;
138 cam_reg_op get_register; 114 cam_get_reg_op get_register;
139#endif 115#endif
140 cam_ident_op get_chip_ident; 116 cam_ident_op get_chip_ident;
141#if IS_ENABLED(CONFIG_INPUT) 117#if IS_ENABLED(CONFIG_INPUT)
@@ -174,8 +150,6 @@ struct gspca_dev {
174 150
175 struct cam cam; /* device information */ 151 struct cam cam; /* device information */
176 const struct sd_desc *sd_desc; /* subdriver description */ 152 const struct sd_desc *sd_desc; /* subdriver description */
177 unsigned ctrl_dis; /* disabled controls (bit map) */
178 unsigned ctrl_inac; /* inactive controls (bit map) */
179 struct v4l2_ctrl_handler ctrl_handler; 153 struct v4l2_ctrl_handler ctrl_handler;
180 154
181 /* autogain and exposure or gain control cluster, these are global as 155 /* autogain and exposure or gain control cluster, these are global as
diff --git a/drivers/media/usb/gspca/jeilinj.c b/drivers/media/usb/gspca/jeilinj.c
index 1ba29fe7fada..8da3dde38385 100644
--- a/drivers/media/usb/gspca/jeilinj.c
+++ b/drivers/media/usb/gspca/jeilinj.c
@@ -266,7 +266,7 @@ static int jlj_start(struct gspca_dev *gspca_dev)
266 msleep(2); 266 msleep(2);
267 setfreq(gspca_dev, v4l2_ctrl_g_ctrl(sd->freq)); 267 setfreq(gspca_dev, v4l2_ctrl_g_ctrl(sd->freq));
268 if (gspca_dev->usb_err < 0) 268 if (gspca_dev->usb_err < 0)
269 PDEBUG(D_ERR, "Start streaming command failed"); 269 PERR("Start streaming command failed");
270 return gspca_dev->usb_err; 270 return gspca_dev->usb_err;
271} 271}
272 272
diff --git a/drivers/media/usb/gspca/konica.c b/drivers/media/usb/gspca/konica.c
index 61e25dbf2447..39c96bb4c985 100644
--- a/drivers/media/usb/gspca/konica.c
+++ b/drivers/media/usb/gspca/konica.c
@@ -277,7 +277,7 @@ static void sd_isoc_irq(struct urb *urb)
277 if (gspca_dev->frozen) 277 if (gspca_dev->frozen)
278 return; 278 return;
279#endif 279#endif
280 PDEBUG(D_ERR, "urb status: %d", urb->status); 280 PERR("urb status: %d", urb->status);
281 st = usb_submit_urb(urb, GFP_ATOMIC); 281 st = usb_submit_urb(urb, GFP_ATOMIC);
282 if (st < 0) 282 if (st < 0)
283 pr_err("resubmit urb error %d\n", st); 283 pr_err("resubmit urb error %d\n", st);
@@ -295,33 +295,30 @@ static void sd_isoc_irq(struct urb *urb)
295 sd->last_data_urb = NULL; 295 sd->last_data_urb = NULL;
296 296
297 if (!data_urb || data_urb->start_frame != status_urb->start_frame) { 297 if (!data_urb || data_urb->start_frame != status_urb->start_frame) {
298 PDEBUG(D_ERR|D_PACK, "lost sync on frames"); 298 PERR("lost sync on frames");
299 goto resubmit; 299 goto resubmit;
300 } 300 }
301 301
302 if (data_urb->number_of_packets != status_urb->number_of_packets) { 302 if (data_urb->number_of_packets != status_urb->number_of_packets) {
303 PDEBUG(D_ERR|D_PACK, 303 PERR("no packets does not match, data: %d, status: %d",
304 "no packets does not match, data: %d, status: %d", 304 data_urb->number_of_packets,
305 data_urb->number_of_packets, 305 status_urb->number_of_packets);
306 status_urb->number_of_packets);
307 goto resubmit; 306 goto resubmit;
308 } 307 }
309 308
310 for (i = 0; i < status_urb->number_of_packets; i++) { 309 for (i = 0; i < status_urb->number_of_packets; i++) {
311 if (data_urb->iso_frame_desc[i].status || 310 if (data_urb->iso_frame_desc[i].status ||
312 status_urb->iso_frame_desc[i].status) { 311 status_urb->iso_frame_desc[i].status) {
313 PDEBUG(D_ERR|D_PACK, 312 PERR("pkt %d data-status %d, status-status %d", i,
314 "pkt %d data-status %d, status-status %d", i, 313 data_urb->iso_frame_desc[i].status,
315 data_urb->iso_frame_desc[i].status, 314 status_urb->iso_frame_desc[i].status);
316 status_urb->iso_frame_desc[i].status);
317 gspca_dev->last_packet_type = DISCARD_PACKET; 315 gspca_dev->last_packet_type = DISCARD_PACKET;
318 continue; 316 continue;
319 } 317 }
320 318
321 if (status_urb->iso_frame_desc[i].actual_length != 1) { 319 if (status_urb->iso_frame_desc[i].actual_length != 1) {
322 PDEBUG(D_ERR|D_PACK, 320 PERR("bad status packet length %d",
323 "bad status packet length %d", 321 status_urb->iso_frame_desc[i].actual_length);
324 status_urb->iso_frame_desc[i].actual_length);
325 gspca_dev->last_packet_type = DISCARD_PACKET; 322 gspca_dev->last_packet_type = DISCARD_PACKET;
326 continue; 323 continue;
327 } 324 }
@@ -366,12 +363,11 @@ resubmit:
366 if (data_urb) { 363 if (data_urb) {
367 st = usb_submit_urb(data_urb, GFP_ATOMIC); 364 st = usb_submit_urb(data_urb, GFP_ATOMIC);
368 if (st < 0) 365 if (st < 0)
369 PDEBUG(D_ERR|D_PACK, 366 PERR("usb_submit_urb(data_urb) ret %d", st);
370 "usb_submit_urb(data_urb) ret %d", st);
371 } 367 }
372 st = usb_submit_urb(status_urb, GFP_ATOMIC); 368 st = usb_submit_urb(status_urb, GFP_ATOMIC);
373 if (st < 0) 369 if (st < 0)
374 pr_err("usb_submit_urb(status_urb) ret %d\n", st); 370 PERR("usb_submit_urb(status_urb) ret %d\n", st);
375} 371}
376 372
377static int sd_s_ctrl(struct v4l2_ctrl *ctrl) 373static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
diff --git a/drivers/media/usb/gspca/m5602/m5602_bridge.h b/drivers/media/usb/gspca/m5602/m5602_bridge.h
index 51af3ee3ab85..19eb1a64f9d6 100644
--- a/drivers/media/usb/gspca/m5602/m5602_bridge.h
+++ b/drivers/media/usb/gspca/m5602/m5602_bridge.h
@@ -136,16 +136,33 @@ struct sd {
136 /* A pointer to the currently connected sensor */ 136 /* A pointer to the currently connected sensor */
137 const struct m5602_sensor *sensor; 137 const struct m5602_sensor *sensor;
138 138
139 struct sd_desc *desc;
140
141 /* Sensor private data */
142 void *sensor_priv;
143
144 /* The current frame's id, used to detect frame boundaries */ 139 /* The current frame's id, used to detect frame boundaries */
145 u8 frame_id; 140 u8 frame_id;
146 141
147 /* The current frame count */ 142 /* The current frame count */
148 u32 frame_count; 143 u32 frame_count;
144
145 /* Camera rotation polling thread for "flipable" cams */
146 struct task_struct *rotation_thread;
147
148 struct { /* auto-white-bal + green/red/blue balance control cluster */
149 struct v4l2_ctrl *auto_white_bal;
150 struct v4l2_ctrl *red_bal;
151 struct v4l2_ctrl *blue_bal;
152 struct v4l2_ctrl *green_bal;
153 };
154 struct { /* autoexpo / expo cluster */
155 struct v4l2_ctrl *autoexpo;
156 struct v4l2_ctrl *expo;
157 };
158 struct { /* autogain / gain cluster */
159 struct v4l2_ctrl *autogain;
160 struct v4l2_ctrl *gain;
161 };
162 struct { /* hflip/vflip cluster */
163 struct v4l2_ctrl *hflip;
164 struct v4l2_ctrl *vflip;
165 };
149}; 166};
150 167
151int m5602_read_bridge( 168int m5602_read_bridge(
diff --git a/drivers/media/usb/gspca/m5602/m5602_core.c b/drivers/media/usb/gspca/m5602/m5602_core.c
index ed22638978ce..d926e62cb80b 100644
--- a/drivers/media/usb/gspca/m5602/m5602_core.c
+++ b/drivers/media/usb/gspca/m5602/m5602_core.c
@@ -41,6 +41,7 @@ MODULE_DEVICE_TABLE(usb, m5602_table);
41int m5602_read_bridge(struct sd *sd, const u8 address, u8 *i2c_data) 41int m5602_read_bridge(struct sd *sd, const u8 address, u8 *i2c_data)
42{ 42{
43 int err; 43 int err;
44 struct gspca_dev *gspca_dev = (struct gspca_dev *) sd;
44 struct usb_device *udev = sd->gspca_dev.dev; 45 struct usb_device *udev = sd->gspca_dev.dev;
45 __u8 *buf = sd->gspca_dev.usb_buf; 46 __u8 *buf = sd->gspca_dev.usb_buf;
46 47
@@ -62,6 +63,7 @@ int m5602_read_bridge(struct sd *sd, const u8 address, u8 *i2c_data)
62int m5602_write_bridge(struct sd *sd, const u8 address, const u8 i2c_data) 63int m5602_write_bridge(struct sd *sd, const u8 address, const u8 i2c_data)
63{ 64{
64 int err; 65 int err;
66 struct gspca_dev *gspca_dev = (struct gspca_dev *) sd;
65 struct usb_device *udev = sd->gspca_dev.dev; 67 struct usb_device *udev = sd->gspca_dev.dev;
66 __u8 *buf = sd->gspca_dev.usb_buf; 68 __u8 *buf = sd->gspca_dev.usb_buf;
67 69
@@ -98,6 +100,7 @@ int m5602_read_sensor(struct sd *sd, const u8 address,
98 u8 *i2c_data, const u8 len) 100 u8 *i2c_data, const u8 len)
99{ 101{
100 int err, i; 102 int err, i;
103 struct gspca_dev *gspca_dev = (struct gspca_dev *) sd;
101 104
102 if (!len || len > sd->sensor->i2c_regW) 105 if (!len || len > sd->sensor->i2c_regW)
103 return -EINVAL; 106 return -EINVAL;
@@ -147,6 +150,7 @@ int m5602_write_sensor(struct sd *sd, const u8 address,
147{ 150{
148 int err, i; 151 int err, i;
149 u8 *p; 152 u8 *p;
153 struct gspca_dev *gspca_dev = (struct gspca_dev *) sd;
150 struct usb_device *udev = sd->gspca_dev.dev; 154 struct usb_device *udev = sd->gspca_dev.dev;
151 __u8 *buf = sd->gspca_dev.usb_buf; 155 __u8 *buf = sd->gspca_dev.usb_buf;
152 156
@@ -252,6 +256,16 @@ static int m5602_init(struct gspca_dev *gspca_dev)
252 return err; 256 return err;
253} 257}
254 258
259static int m5602_init_controls(struct gspca_dev *gspca_dev)
260{
261 struct sd *sd = (struct sd *) gspca_dev;
262
263 if (!sd->sensor->init_controls)
264 return 0;
265
266 return sd->sensor->init_controls(sd);
267}
268
255static int m5602_start_transfer(struct gspca_dev *gspca_dev) 269static int m5602_start_transfer(struct gspca_dev *gspca_dev)
256{ 270{
257 struct sd *sd = (struct sd *) gspca_dev; 271 struct sd *sd = (struct sd *) gspca_dev;
@@ -336,11 +350,12 @@ static void m5602_stop_transfer(struct gspca_dev *gspca_dev)
336 sd->sensor->stop(sd); 350 sd->sensor->stop(sd);
337} 351}
338 352
339/* sub-driver description, the ctrl and nctrl is filled at probe time */ 353/* sub-driver description */
340static struct sd_desc sd_desc = { 354static const struct sd_desc sd_desc = {
341 .name = MODULE_NAME, 355 .name = MODULE_NAME,
342 .config = m5602_configure, 356 .config = m5602_configure,
343 .init = m5602_init, 357 .init = m5602_init,
358 .init_controls = m5602_init_controls,
344 .start = m5602_start_transfer, 359 .start = m5602_start_transfer,
345 .stopN = m5602_stop_transfer, 360 .stopN = m5602_stop_transfer,
346 .pkt_scan = m5602_urb_complete 361 .pkt_scan = m5602_urb_complete
@@ -355,7 +370,6 @@ static int m5602_configure(struct gspca_dev *gspca_dev,
355 int err; 370 int err;
356 371
357 cam = &gspca_dev->cam; 372 cam = &gspca_dev->cam;
358 sd->desc = &sd_desc;
359 373
360 if (dump_bridge) 374 if (dump_bridge)
361 m5602_dump_bridge(sd); 375 m5602_dump_bridge(sd);
@@ -368,7 +382,7 @@ static int m5602_configure(struct gspca_dev *gspca_dev,
368 return 0; 382 return 0;
369 383
370fail: 384fail:
371 PDEBUG(D_ERR, "ALi m5602 webcam failed"); 385 PERR("ALi m5602 webcam failed");
372 cam->cam_mode = NULL; 386 cam->cam_mode = NULL;
373 cam->nmodes = 0; 387 cam->nmodes = 0;
374 388
diff --git a/drivers/media/usb/gspca/m5602/m5602_mt9m111.c b/drivers/media/usb/gspca/m5602/m5602_mt9m111.c
index 6268aa24ec5d..cfa4663f8934 100644
--- a/drivers/media/usb/gspca/m5602/m5602_mt9m111.c
+++ b/drivers/media/usb/gspca/m5602/m5602_mt9m111.c
@@ -20,22 +20,8 @@
20 20
21#include "m5602_mt9m111.h" 21#include "m5602_mt9m111.h"
22 22
23static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val); 23static int mt9m111_s_ctrl(struct v4l2_ctrl *ctrl);
24static int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); 24static void mt9m111_dump_registers(struct sd *sd);
25static int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
26static int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
27static int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
28static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val);
29static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev,
30 __s32 val);
31static int mt9m111_get_auto_white_balance(struct gspca_dev *gspca_dev,
32 __s32 *val);
33static int mt9m111_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val);
34static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val);
35static int mt9m111_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
36static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
37static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
38static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
39 25
40static struct v4l2_pix_format mt9m111_modes[] = { 26static struct v4l2_pix_format mt9m111_modes[] = {
41 { 27 {
@@ -50,118 +36,27 @@ static struct v4l2_pix_format mt9m111_modes[] = {
50 } 36 }
51}; 37};
52 38
53static const struct ctrl mt9m111_ctrls[] = { 39static const struct v4l2_ctrl_ops mt9m111_ctrl_ops = {
54#define VFLIP_IDX 0 40 .s_ctrl = mt9m111_s_ctrl,
55 {
56 {
57 .id = V4L2_CID_VFLIP,
58 .type = V4L2_CTRL_TYPE_BOOLEAN,
59 .name = "vertical flip",
60 .minimum = 0,
61 .maximum = 1,
62 .step = 1,
63 .default_value = 0
64 },
65 .set = mt9m111_set_vflip,
66 .get = mt9m111_get_vflip
67 },
68#define HFLIP_IDX 1
69 {
70 {
71 .id = V4L2_CID_HFLIP,
72 .type = V4L2_CTRL_TYPE_BOOLEAN,
73 .name = "horizontal flip",
74 .minimum = 0,
75 .maximum = 1,
76 .step = 1,
77 .default_value = 0
78 },
79 .set = mt9m111_set_hflip,
80 .get = mt9m111_get_hflip
81 },
82#define GAIN_IDX 2
83 {
84 {
85 .id = V4L2_CID_GAIN,
86 .type = V4L2_CTRL_TYPE_INTEGER,
87 .name = "gain",
88 .minimum = 0,
89 .maximum = (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2,
90 .step = 1,
91 .default_value = MT9M111_DEFAULT_GAIN,
92 .flags = V4L2_CTRL_FLAG_SLIDER
93 },
94 .set = mt9m111_set_gain,
95 .get = mt9m111_get_gain
96 },
97#define AUTO_WHITE_BALANCE_IDX 3
98 {
99 {
100 .id = V4L2_CID_AUTO_WHITE_BALANCE,
101 .type = V4L2_CTRL_TYPE_BOOLEAN,
102 .name = "auto white balance",
103 .minimum = 0,
104 .maximum = 1,
105 .step = 1,
106 .default_value = 0,
107 },
108 .set = mt9m111_set_auto_white_balance,
109 .get = mt9m111_get_auto_white_balance
110 },
111#define GREEN_BALANCE_IDX 4
112 {
113 {
114 .id = M5602_V4L2_CID_GREEN_BALANCE,
115 .type = V4L2_CTRL_TYPE_INTEGER,
116 .name = "green balance",
117 .minimum = 0x00,
118 .maximum = 0x7ff,
119 .step = 0x1,
120 .default_value = MT9M111_GREEN_GAIN_DEFAULT,
121 .flags = V4L2_CTRL_FLAG_SLIDER
122 },
123 .set = mt9m111_set_green_balance,
124 .get = mt9m111_get_green_balance
125 },
126#define BLUE_BALANCE_IDX 5
127 {
128 {
129 .id = V4L2_CID_BLUE_BALANCE,
130 .type = V4L2_CTRL_TYPE_INTEGER,
131 .name = "blue balance",
132 .minimum = 0x00,
133 .maximum = 0x7ff,
134 .step = 0x1,
135 .default_value = MT9M111_BLUE_GAIN_DEFAULT,
136 .flags = V4L2_CTRL_FLAG_SLIDER
137 },
138 .set = mt9m111_set_blue_balance,
139 .get = mt9m111_get_blue_balance
140 },
141#define RED_BALANCE_IDX 5
142 {
143 {
144 .id = V4L2_CID_RED_BALANCE,
145 .type = V4L2_CTRL_TYPE_INTEGER,
146 .name = "red balance",
147 .minimum = 0x00,
148 .maximum = 0x7ff,
149 .step = 0x1,
150 .default_value = MT9M111_RED_GAIN_DEFAULT,
151 .flags = V4L2_CTRL_FLAG_SLIDER
152 },
153 .set = mt9m111_set_red_balance,
154 .get = mt9m111_get_red_balance
155 },
156}; 41};
157 42
158static void mt9m111_dump_registers(struct sd *sd); 43static const struct v4l2_ctrl_config mt9m111_greenbal_cfg = {
44 .ops = &mt9m111_ctrl_ops,
45 .id = M5602_V4L2_CID_GREEN_BALANCE,
46 .name = "Green Balance",
47 .type = V4L2_CTRL_TYPE_INTEGER,
48 .min = 0,
49 .max = 0x7ff,
50 .step = 1,
51 .def = MT9M111_GREEN_GAIN_DEFAULT,
52 .flags = V4L2_CTRL_FLAG_SLIDER,
53};
159 54
160int mt9m111_probe(struct sd *sd) 55int mt9m111_probe(struct sd *sd)
161{ 56{
162 u8 data[2] = {0x00, 0x00}; 57 u8 data[2] = {0x00, 0x00};
163 int i; 58 int i;
164 s32 *sensor_settings; 59 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
165 60
166 if (force_sensor) { 61 if (force_sensor) {
167 if (force_sensor == MT9M111_SENSOR) { 62 if (force_sensor == MT9M111_SENSOR) {
@@ -200,19 +95,8 @@ int mt9m111_probe(struct sd *sd)
200 return -ENODEV; 95 return -ENODEV;
201 96
202sensor_found: 97sensor_found:
203 sensor_settings = kmalloc(ARRAY_SIZE(mt9m111_ctrls) * sizeof(s32),
204 GFP_KERNEL);
205 if (!sensor_settings)
206 return -ENOMEM;
207
208 sd->gspca_dev.cam.cam_mode = mt9m111_modes; 98 sd->gspca_dev.cam.cam_mode = mt9m111_modes;
209 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(mt9m111_modes); 99 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(mt9m111_modes);
210 sd->desc->ctrls = mt9m111_ctrls;
211 sd->desc->nctrls = ARRAY_SIZE(mt9m111_ctrls);
212
213 for (i = 0; i < ARRAY_SIZE(mt9m111_ctrls); i++)
214 sensor_settings[i] = mt9m111_ctrls[i].qctrl.default_value;
215 sd->sensor_priv = sensor_settings;
216 100
217 return 0; 101 return 0;
218} 102}
@@ -220,7 +104,6 @@ sensor_found:
220int mt9m111_init(struct sd *sd) 104int mt9m111_init(struct sd *sd)
221{ 105{
222 int i, err = 0; 106 int i, err = 0;
223 s32 *sensor_settings = sd->sensor_priv;
224 107
225 /* Init the sensor */ 108 /* Init the sensor */
226 for (i = 0; i < ARRAY_SIZE(init_mt9m111) && !err; i++) { 109 for (i = 0; i < ARRAY_SIZE(init_mt9m111) && !err; i++) {
@@ -241,30 +124,45 @@ int mt9m111_init(struct sd *sd)
241 if (dump_sensor) 124 if (dump_sensor)
242 mt9m111_dump_registers(sd); 125 mt9m111_dump_registers(sd);
243 126
244 err = mt9m111_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]); 127 return 0;
245 if (err < 0) 128}
246 return err;
247
248 err = mt9m111_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]);
249 if (err < 0)
250 return err;
251
252 err = mt9m111_set_green_balance(&sd->gspca_dev,
253 sensor_settings[GREEN_BALANCE_IDX]);
254 if (err < 0)
255 return err;
256 129
257 err = mt9m111_set_blue_balance(&sd->gspca_dev, 130int mt9m111_init_controls(struct sd *sd)
258 sensor_settings[BLUE_BALANCE_IDX]); 131{
259 if (err < 0) 132 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
260 return err; 133
134 sd->gspca_dev.vdev.ctrl_handler = hdl;
135 v4l2_ctrl_handler_init(hdl, 7);
136
137 sd->auto_white_bal = v4l2_ctrl_new_std(hdl, &mt9m111_ctrl_ops,
138 V4L2_CID_AUTO_WHITE_BALANCE,
139 0, 1, 1, 0);
140 sd->green_bal = v4l2_ctrl_new_custom(hdl, &mt9m111_greenbal_cfg, NULL);
141 sd->red_bal = v4l2_ctrl_new_std(hdl, &mt9m111_ctrl_ops,
142 V4L2_CID_RED_BALANCE, 0, 0x7ff, 1,
143 MT9M111_RED_GAIN_DEFAULT);
144 sd->blue_bal = v4l2_ctrl_new_std(hdl, &mt9m111_ctrl_ops,
145 V4L2_CID_BLUE_BALANCE, 0, 0x7ff, 1,
146 MT9M111_BLUE_GAIN_DEFAULT);
147
148 v4l2_ctrl_new_std(hdl, &mt9m111_ctrl_ops, V4L2_CID_GAIN, 0,
149 (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2, 1,
150 MT9M111_DEFAULT_GAIN);
151
152 sd->hflip = v4l2_ctrl_new_std(hdl, &mt9m111_ctrl_ops, V4L2_CID_HFLIP,
153 0, 1, 1, 0);
154 sd->vflip = v4l2_ctrl_new_std(hdl, &mt9m111_ctrl_ops, V4L2_CID_VFLIP,
155 0, 1, 1, 0);
156
157 if (hdl->error) {
158 pr_err("Could not initialize controls\n");
159 return hdl->error;
160 }
261 161
262 err = mt9m111_set_red_balance(&sd->gspca_dev, 162 v4l2_ctrl_auto_cluster(4, &sd->auto_white_bal, 0, false);
263 sensor_settings[RED_BALANCE_IDX]); 163 v4l2_ctrl_cluster(2, &sd->hflip);
264 if (err < 0)
265 return err;
266 164
267 return mt9m111_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); 165 return 0;
268} 166}
269 167
270int mt9m111_start(struct sd *sd) 168int mt9m111_start(struct sd *sd)
@@ -272,7 +170,7 @@ int mt9m111_start(struct sd *sd)
272 int i, err = 0; 170 int i, err = 0;
273 u8 data[2]; 171 u8 data[2];
274 struct cam *cam = &sd->gspca_dev.cam; 172 struct cam *cam = &sd->gspca_dev.cam;
275 s32 *sensor_settings = sd->sensor_priv; 173 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
276 174
277 int width = cam->cam_mode[sd->gspca_dev.curr_mode].width - 1; 175 int width = cam->cam_mode[sd->gspca_dev.curr_mode].width - 1;
278 int height = cam->cam_mode[sd->gspca_dev.curr_mode].height; 176 int height = cam->cam_mode[sd->gspca_dev.curr_mode].height;
@@ -333,26 +231,11 @@ int mt9m111_start(struct sd *sd)
333 231
334 switch (width) { 232 switch (width) {
335 case 640: 233 case 640:
336 PDEBUG(D_V4L2, "Configuring camera for VGA mode"); 234 PDEBUG(D_CONF, "Configuring camera for VGA mode");
337 data[0] = MT9M111_RMB_OVER_SIZED;
338 data[1] = MT9M111_RMB_ROW_SKIP_2X |
339 MT9M111_RMB_COLUMN_SKIP_2X |
340 (sensor_settings[VFLIP_IDX] << 0) |
341 (sensor_settings[HFLIP_IDX] << 1);
342
343 err = m5602_write_sensor(sd,
344 MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
345 break; 235 break;
346 236
347 case 320: 237 case 320:
348 PDEBUG(D_V4L2, "Configuring camera for QVGA mode"); 238 PDEBUG(D_CONF, "Configuring camera for QVGA mode");
349 data[0] = MT9M111_RMB_OVER_SIZED;
350 data[1] = MT9M111_RMB_ROW_SKIP_4X |
351 MT9M111_RMB_COLUMN_SKIP_4X |
352 (sensor_settings[VFLIP_IDX] << 0) |
353 (sensor_settings[HFLIP_IDX] << 1);
354 err = m5602_write_sensor(sd,
355 MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
356 break; 239 break;
357 } 240 }
358 return err; 241 return err;
@@ -361,105 +244,46 @@ int mt9m111_start(struct sd *sd)
361void mt9m111_disconnect(struct sd *sd) 244void mt9m111_disconnect(struct sd *sd)
362{ 245{
363 sd->sensor = NULL; 246 sd->sensor = NULL;
364 kfree(sd->sensor_priv);
365}
366
367static int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
368{
369 struct sd *sd = (struct sd *) gspca_dev;
370 s32 *sensor_settings = sd->sensor_priv;
371
372 *val = sensor_settings[VFLIP_IDX];
373 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
374
375 return 0;
376}
377
378static int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
379{
380 int err;
381 u8 data[2] = {0x00, 0x00};
382 struct sd *sd = (struct sd *) gspca_dev;
383 s32 *sensor_settings = sd->sensor_priv;
384
385 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
386
387 sensor_settings[VFLIP_IDX] = val;
388
389 /* The mt9m111 is flipped by default */
390 val = !val;
391
392 /* Set the correct page map */
393 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
394 if (err < 0)
395 return err;
396
397 err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
398 if (err < 0)
399 return err;
400
401 data[1] = (data[1] & 0xfe) | val;
402 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
403 data, 2);
404 return err;
405}
406
407static int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
408{
409 struct sd *sd = (struct sd *) gspca_dev;
410 s32 *sensor_settings = sd->sensor_priv;
411
412 *val = sensor_settings[HFLIP_IDX];
413 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
414
415 return 0;
416} 247}
417 248
418static int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val) 249static int mt9m111_set_hvflip(struct gspca_dev *gspca_dev)
419{ 250{
420 int err; 251 int err;
421 u8 data[2] = {0x00, 0x00}; 252 u8 data[2] = {0x00, 0x00};
422 struct sd *sd = (struct sd *) gspca_dev; 253 struct sd *sd = (struct sd *) gspca_dev;
423 s32 *sensor_settings = sd->sensor_priv; 254 int hflip;
255 int vflip;
424 256
425 PDEBUG(D_V4L2, "Set horizontal flip to %d", val); 257 PDEBUG(D_CONF, "Set hvflip to %d %d", sd->hflip->val, sd->vflip->val);
426
427 sensor_settings[HFLIP_IDX] = val;
428 258
429 /* The mt9m111 is flipped by default */ 259 /* The mt9m111 is flipped by default */
430 val = !val; 260 hflip = !sd->hflip->val;
261 vflip = !sd->vflip->val;
431 262
432 /* Set the correct page map */ 263 /* Set the correct page map */
433 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); 264 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
434 if (err < 0) 265 if (err < 0)
435 return err; 266 return err;
436 267
437 err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); 268 data[0] = MT9M111_RMB_OVER_SIZED;
438 if (err < 0) 269 if (gspca_dev->width == 640) {
439 return err; 270 data[1] = MT9M111_RMB_ROW_SKIP_2X |
440 271 MT9M111_RMB_COLUMN_SKIP_2X |
441 data[1] = (data[1] & 0xfd) | ((val << 1) & 0x02); 272 (hflip << 1) | vflip;
273 } else {
274 data[1] = MT9M111_RMB_ROW_SKIP_4X |
275 MT9M111_RMB_COLUMN_SKIP_4X |
276 (hflip << 1) | vflip;
277 }
442 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, 278 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
443 data, 2); 279 data, 2);
444 return err; 280 return err;
445} 281}
446 282
447static int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
448{
449 struct sd *sd = (struct sd *) gspca_dev;
450 s32 *sensor_settings = sd->sensor_priv;
451
452 *val = sensor_settings[GAIN_IDX];
453 PDEBUG(D_V4L2, "Read gain %d", *val);
454
455 return 0;
456}
457
458static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev, 283static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev,
459 __s32 val) 284 __s32 val)
460{ 285{
461 struct sd *sd = (struct sd *) gspca_dev; 286 struct sd *sd = (struct sd *) gspca_dev;
462 s32 *sensor_settings = sd->sensor_priv;
463 int err; 287 int err;
464 u8 data[2]; 288 u8 data[2];
465 289
@@ -467,33 +291,19 @@ static int mt9m111_set_auto_white_balance(struct gspca_dev *gspca_dev,
467 if (err < 0) 291 if (err < 0)
468 return err; 292 return err;
469 293
470 sensor_settings[AUTO_WHITE_BALANCE_IDX] = val & 0x01;
471 data[1] = ((data[1] & 0xfd) | ((val & 0x01) << 1)); 294 data[1] = ((data[1] & 0xfd) | ((val & 0x01) << 1));
472 295
473 err = m5602_write_sensor(sd, MT9M111_CP_OPERATING_MODE_CTL, data, 2); 296 err = m5602_write_sensor(sd, MT9M111_CP_OPERATING_MODE_CTL, data, 2);
474 297
475 PDEBUG(D_V4L2, "Set auto white balance %d", val); 298 PDEBUG(D_CONF, "Set auto white balance %d", val);
476 return err; 299 return err;
477} 300}
478 301
479static int mt9m111_get_auto_white_balance(struct gspca_dev *gspca_dev,
480 __s32 *val) {
481 struct sd *sd = (struct sd *) gspca_dev;
482 s32 *sensor_settings = sd->sensor_priv;
483
484 *val = sensor_settings[AUTO_WHITE_BALANCE_IDX];
485 PDEBUG(D_V4L2, "Read auto white balance %d", *val);
486 return 0;
487}
488
489static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val) 302static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
490{ 303{
491 int err, tmp; 304 int err, tmp;
492 u8 data[2] = {0x00, 0x00}; 305 u8 data[2] = {0x00, 0x00};
493 struct sd *sd = (struct sd *) gspca_dev; 306 struct sd *sd = (struct sd *) gspca_dev;
494 s32 *sensor_settings = sd->sensor_priv;
495
496 sensor_settings[GAIN_IDX] = val;
497 307
498 /* Set the correct page map */ 308 /* Set the correct page map */
499 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); 309 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
@@ -518,7 +328,7 @@ static int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
518 328
519 data[1] = (tmp & 0xff); 329 data[1] = (tmp & 0xff);
520 data[0] = (tmp & 0xff00) >> 8; 330 data[0] = (tmp & 0xff00) >> 8;
521 PDEBUG(D_V4L2, "tmp=%d, data[1]=%d, data[0]=%d", tmp, 331 PDEBUG(D_CONF, "tmp=%d, data[1]=%d, data[0]=%d", tmp,
522 data[1], data[0]); 332 data[1], data[0]);
523 333
524 err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN, 334 err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN,
@@ -532,13 +342,11 @@ static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val)
532 int err; 342 int err;
533 u8 data[2]; 343 u8 data[2];
534 struct sd *sd = (struct sd *) gspca_dev; 344 struct sd *sd = (struct sd *) gspca_dev;
535 s32 *sensor_settings = sd->sensor_priv;
536 345
537 sensor_settings[GREEN_BALANCE_IDX] = val;
538 data[1] = (val & 0xff); 346 data[1] = (val & 0xff);
539 data[0] = (val & 0xff00) >> 8; 347 data[0] = (val & 0xff00) >> 8;
540 348
541 PDEBUG(D_V4L2, "Set green balance %d", val); 349 PDEBUG(D_CONF, "Set green balance %d", val);
542 err = m5602_write_sensor(sd, MT9M111_SC_GREEN_1_GAIN, 350 err = m5602_write_sensor(sd, MT9M111_SC_GREEN_1_GAIN,
543 data, 2); 351 data, 2);
544 if (err < 0) 352 if (err < 0)
@@ -548,66 +356,68 @@ static int mt9m111_set_green_balance(struct gspca_dev *gspca_dev, __s32 val)
548 data, 2); 356 data, 2);
549} 357}
550 358
551static int mt9m111_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val)
552{
553 struct sd *sd = (struct sd *) gspca_dev;
554 s32 *sensor_settings = sd->sensor_priv;
555
556 *val = sensor_settings[GREEN_BALANCE_IDX];
557 PDEBUG(D_V4L2, "Read green balance %d", *val);
558 return 0;
559}
560
561static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) 359static int mt9m111_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
562{ 360{
563 u8 data[2]; 361 u8 data[2];
564 struct sd *sd = (struct sd *) gspca_dev; 362 struct sd *sd = (struct sd *) gspca_dev;
565 s32 *sensor_settings = sd->sensor_priv;
566 363
567 sensor_settings[BLUE_BALANCE_IDX] = val;
568 data[1] = (val & 0xff); 364 data[1] = (val & 0xff);
569 data[0] = (val & 0xff00) >> 8; 365 data[0] = (val & 0xff00) >> 8;
570 366
571 PDEBUG(D_V4L2, "Set blue balance %d", val); 367 PDEBUG(D_CONF, "Set blue balance %d", val);
572 368
573 return m5602_write_sensor(sd, MT9M111_SC_BLUE_GAIN, 369 return m5602_write_sensor(sd, MT9M111_SC_BLUE_GAIN,
574 data, 2); 370 data, 2);
575} 371}
576 372
577static int mt9m111_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
578{
579 struct sd *sd = (struct sd *) gspca_dev;
580 s32 *sensor_settings = sd->sensor_priv;
581
582 *val = sensor_settings[BLUE_BALANCE_IDX];
583 PDEBUG(D_V4L2, "Read blue balance %d", *val);
584 return 0;
585}
586
587static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) 373static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
588{ 374{
589 u8 data[2]; 375 u8 data[2];
590 struct sd *sd = (struct sd *) gspca_dev; 376 struct sd *sd = (struct sd *) gspca_dev;
591 s32 *sensor_settings = sd->sensor_priv;
592 377
593 sensor_settings[RED_BALANCE_IDX] = val;
594 data[1] = (val & 0xff); 378 data[1] = (val & 0xff);
595 data[0] = (val & 0xff00) >> 8; 379 data[0] = (val & 0xff00) >> 8;
596 380
597 PDEBUG(D_V4L2, "Set red balance %d", val); 381 PDEBUG(D_CONF, "Set red balance %d", val);
598 382
599 return m5602_write_sensor(sd, MT9M111_SC_RED_GAIN, 383 return m5602_write_sensor(sd, MT9M111_SC_RED_GAIN,
600 data, 2); 384 data, 2);
601} 385}
602 386
603static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val) 387static int mt9m111_s_ctrl(struct v4l2_ctrl *ctrl)
604{ 388{
389 struct gspca_dev *gspca_dev =
390 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
605 struct sd *sd = (struct sd *) gspca_dev; 391 struct sd *sd = (struct sd *) gspca_dev;
606 s32 *sensor_settings = sd->sensor_priv; 392 int err;
607 393
608 *val = sensor_settings[RED_BALANCE_IDX]; 394 if (!gspca_dev->streaming)
609 PDEBUG(D_V4L2, "Read red balance %d", *val); 395 return 0;
610 return 0; 396
397 switch (ctrl->id) {
398 case V4L2_CID_AUTO_WHITE_BALANCE:
399 err = mt9m111_set_auto_white_balance(gspca_dev, ctrl->val);
400 if (err || ctrl->val)
401 return err;
402 err = mt9m111_set_green_balance(gspca_dev, sd->green_bal->val);
403 if (err)
404 return err;
405 err = mt9m111_set_red_balance(gspca_dev, sd->red_bal->val);
406 if (err)
407 return err;
408 err = mt9m111_set_blue_balance(gspca_dev, sd->blue_bal->val);
409 break;
410 case V4L2_CID_GAIN:
411 err = mt9m111_set_gain(gspca_dev, ctrl->val);
412 break;
413 case V4L2_CID_HFLIP:
414 err = mt9m111_set_hvflip(gspca_dev);
415 break;
416 default:
417 return -EINVAL;
418 }
419
420 return err;
611} 421}
612 422
613static void mt9m111_dump_registers(struct sd *sd) 423static void mt9m111_dump_registers(struct sd *sd)
diff --git a/drivers/media/usb/gspca/m5602/m5602_mt9m111.h b/drivers/media/usb/gspca/m5602/m5602_mt9m111.h
index 8c672b5c8c6a..07448d35e3cd 100644
--- a/drivers/media/usb/gspca/m5602/m5602_mt9m111.h
+++ b/drivers/media/usb/gspca/m5602/m5602_mt9m111.h
@@ -110,6 +110,7 @@ extern bool dump_sensor;
110 110
111int mt9m111_probe(struct sd *sd); 111int mt9m111_probe(struct sd *sd);
112int mt9m111_init(struct sd *sd); 112int mt9m111_init(struct sd *sd);
113int mt9m111_init_controls(struct sd *sd);
113int mt9m111_start(struct sd *sd); 114int mt9m111_start(struct sd *sd);
114void mt9m111_disconnect(struct sd *sd); 115void mt9m111_disconnect(struct sd *sd);
115 116
@@ -121,6 +122,7 @@ static const struct m5602_sensor mt9m111 = {
121 122
122 .probe = mt9m111_probe, 123 .probe = mt9m111_probe,
123 .init = mt9m111_init, 124 .init = mt9m111_init,
125 .init_controls = mt9m111_init_controls,
124 .disconnect = mt9m111_disconnect, 126 .disconnect = mt9m111_disconnect,
125 .start = mt9m111_start, 127 .start = mt9m111_start,
126}; 128};
diff --git a/drivers/media/usb/gspca/m5602/m5602_ov7660.c b/drivers/media/usb/gspca/m5602/m5602_ov7660.c
index 9a14835c128f..64b3b03a9141 100644
--- a/drivers/media/usb/gspca/m5602/m5602_ov7660.c
+++ b/drivers/media/usb/gspca/m5602/m5602_ov7660.c
@@ -20,111 +20,8 @@
20 20
21#include "m5602_ov7660.h" 21#include "m5602_ov7660.h"
22 22
23static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val); 23static int ov7660_s_ctrl(struct v4l2_ctrl *ctrl);
24static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val); 24static void ov7660_dump_registers(struct sd *sd);
25static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev,
26 __s32 *val);
27static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev,
28 __s32 val);
29static int ov7660_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val);
30static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val);
31static int ov7660_get_auto_exposure(struct gspca_dev *gspca_dev, __s32 *val);
32static int ov7660_set_auto_exposure(struct gspca_dev *gspca_dev, __s32 val);
33static int ov7660_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
34static int ov7660_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
35static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
36static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
37
38static const struct ctrl ov7660_ctrls[] = {
39#define GAIN_IDX 1
40 {
41 {
42 .id = V4L2_CID_GAIN,
43 .type = V4L2_CTRL_TYPE_INTEGER,
44 .name = "gain",
45 .minimum = 0x00,
46 .maximum = 0xff,
47 .step = 0x1,
48 .default_value = OV7660_DEFAULT_GAIN,
49 .flags = V4L2_CTRL_FLAG_SLIDER
50 },
51 .set = ov7660_set_gain,
52 .get = ov7660_get_gain
53 },
54#define BLUE_BALANCE_IDX 2
55#define RED_BALANCE_IDX 3
56#define AUTO_WHITE_BALANCE_IDX 4
57 {
58 {
59 .id = V4L2_CID_AUTO_WHITE_BALANCE,
60 .type = V4L2_CTRL_TYPE_BOOLEAN,
61 .name = "auto white balance",
62 .minimum = 0,
63 .maximum = 1,
64 .step = 1,
65 .default_value = 1
66 },
67 .set = ov7660_set_auto_white_balance,
68 .get = ov7660_get_auto_white_balance
69 },
70#define AUTO_GAIN_CTRL_IDX 5
71 {
72 {
73 .id = V4L2_CID_AUTOGAIN,
74 .type = V4L2_CTRL_TYPE_BOOLEAN,
75 .name = "auto gain control",
76 .minimum = 0,
77 .maximum = 1,
78 .step = 1,
79 .default_value = 1
80 },
81 .set = ov7660_set_auto_gain,
82 .get = ov7660_get_auto_gain
83 },
84#define AUTO_EXPOSURE_IDX 6
85 {
86 {
87 .id = V4L2_CID_EXPOSURE_AUTO,
88 .type = V4L2_CTRL_TYPE_BOOLEAN,
89 .name = "auto exposure",
90 .minimum = 0,
91 .maximum = 1,
92 .step = 1,
93 .default_value = 1
94 },
95 .set = ov7660_set_auto_exposure,
96 .get = ov7660_get_auto_exposure
97 },
98#define HFLIP_IDX 7
99 {
100 {
101 .id = V4L2_CID_HFLIP,
102 .type = V4L2_CTRL_TYPE_BOOLEAN,
103 .name = "horizontal flip",
104 .minimum = 0,
105 .maximum = 1,
106 .step = 1,
107 .default_value = 0
108 },
109 .set = ov7660_set_hflip,
110 .get = ov7660_get_hflip
111 },
112#define VFLIP_IDX 8
113 {
114 {
115 .id = V4L2_CID_VFLIP,
116 .type = V4L2_CTRL_TYPE_BOOLEAN,
117 .name = "vertical flip",
118 .minimum = 0,
119 .maximum = 1,
120 .step = 1,
121 .default_value = 0
122 },
123 .set = ov7660_set_vflip,
124 .get = ov7660_get_vflip
125 },
126
127};
128 25
129static struct v4l2_pix_format ov7660_modes[] = { 26static struct v4l2_pix_format ov7660_modes[] = {
130 { 27 {
@@ -140,15 +37,15 @@ static struct v4l2_pix_format ov7660_modes[] = {
140 } 37 }
141}; 38};
142 39
143static void ov7660_dump_registers(struct sd *sd); 40static const struct v4l2_ctrl_ops ov7660_ctrl_ops = {
41 .s_ctrl = ov7660_s_ctrl,
42};
144 43
145int ov7660_probe(struct sd *sd) 44int ov7660_probe(struct sd *sd)
146{ 45{
147 int err = 0, i; 46 int err = 0, i;
148 u8 prod_id = 0, ver_id = 0; 47 u8 prod_id = 0, ver_id = 0;
149 48
150 s32 *sensor_settings;
151
152 if (force_sensor) { 49 if (force_sensor) {
153 if (force_sensor == OV7660_SENSOR) { 50 if (force_sensor == OV7660_SENSOR) {
154 pr_info("Forcing an %s sensor\n", ov7660.name); 51 pr_info("Forcing an %s sensor\n", ov7660.name);
@@ -191,27 +88,15 @@ int ov7660_probe(struct sd *sd)
191 return -ENODEV; 88 return -ENODEV;
192 89
193sensor_found: 90sensor_found:
194 sensor_settings = kmalloc(
195 ARRAY_SIZE(ov7660_ctrls) * sizeof(s32), GFP_KERNEL);
196 if (!sensor_settings)
197 return -ENOMEM;
198
199 sd->gspca_dev.cam.cam_mode = ov7660_modes; 91 sd->gspca_dev.cam.cam_mode = ov7660_modes;
200 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov7660_modes); 92 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov7660_modes);
201 sd->desc->ctrls = ov7660_ctrls;
202 sd->desc->nctrls = ARRAY_SIZE(ov7660_ctrls);
203
204 for (i = 0; i < ARRAY_SIZE(ov7660_ctrls); i++)
205 sensor_settings[i] = ov7660_ctrls[i].qctrl.default_value;
206 sd->sensor_priv = sensor_settings;
207 93
208 return 0; 94 return 0;
209} 95}
210 96
211int ov7660_init(struct sd *sd) 97int ov7660_init(struct sd *sd)
212{ 98{
213 int i, err = 0; 99 int i, err;
214 s32 *sensor_settings = sd->sensor_priv;
215 100
216 /* Init the sensor */ 101 /* Init the sensor */
217 for (i = 0; i < ARRAY_SIZE(init_ov7660); i++) { 102 for (i = 0; i < ARRAY_SIZE(init_ov7660); i++) {
@@ -226,38 +111,47 @@ int ov7660_init(struct sd *sd)
226 err = m5602_write_sensor(sd, 111 err = m5602_write_sensor(sd,
227 init_ov7660[i][1], data, 1); 112 init_ov7660[i][1], data, 1);
228 } 113 }
114 if (err < 0)
115 return err;
229 } 116 }
230 117
231 if (dump_sensor) 118 if (dump_sensor)
232 ov7660_dump_registers(sd); 119 ov7660_dump_registers(sd);
233 120
234 err = ov7660_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); 121 return 0;
235 if (err < 0) 122}
236 return err;
237 123
238 err = ov7660_set_auto_white_balance(&sd->gspca_dev, 124int ov7660_init_controls(struct sd *sd)
239 sensor_settings[AUTO_WHITE_BALANCE_IDX]); 125{
240 if (err < 0) 126 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
241 return err;
242 127
243 err = ov7660_set_auto_gain(&sd->gspca_dev, 128 sd->gspca_dev.vdev.ctrl_handler = hdl;
244 sensor_settings[AUTO_GAIN_CTRL_IDX]); 129 v4l2_ctrl_handler_init(hdl, 6);
245 if (err < 0)
246 return err;
247 130
248 err = ov7660_set_auto_exposure(&sd->gspca_dev, 131 v4l2_ctrl_new_std(hdl, &ov7660_ctrl_ops, V4L2_CID_AUTO_WHITE_BALANCE,
249 sensor_settings[AUTO_EXPOSURE_IDX]); 132 0, 1, 1, 1);
250 if (err < 0) 133 v4l2_ctrl_new_std_menu(hdl, &ov7660_ctrl_ops,
251 return err; 134 V4L2_CID_EXPOSURE_AUTO, 1, 0, V4L2_EXPOSURE_AUTO);
252 err = ov7660_set_hflip(&sd->gspca_dev,
253 sensor_settings[HFLIP_IDX]);
254 if (err < 0)
255 return err;
256 135
257 err = ov7660_set_vflip(&sd->gspca_dev, 136 sd->autogain = v4l2_ctrl_new_std(hdl, &ov7660_ctrl_ops,
258 sensor_settings[VFLIP_IDX]); 137 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
138 sd->gain = v4l2_ctrl_new_std(hdl, &ov7660_ctrl_ops, V4L2_CID_GAIN, 0,
139 255, 1, OV7660_DEFAULT_GAIN);
259 140
260 return err; 141 sd->hflip = v4l2_ctrl_new_std(hdl, &ov7660_ctrl_ops, V4L2_CID_HFLIP,
142 0, 1, 1, 0);
143 sd->vflip = v4l2_ctrl_new_std(hdl, &ov7660_ctrl_ops, V4L2_CID_VFLIP,
144 0, 1, 1, 0);
145
146 if (hdl->error) {
147 pr_err("Could not initialize controls\n");
148 return hdl->error;
149 }
150
151 v4l2_ctrl_auto_cluster(2, &sd->autogain, 0, false);
152 v4l2_ctrl_cluster(2, &sd->hflip);
153
154 return 0;
261} 155}
262 156
263int ov7660_start(struct sd *sd) 157int ov7660_start(struct sd *sd)
@@ -275,56 +169,29 @@ void ov7660_disconnect(struct sd *sd)
275 ov7660_stop(sd); 169 ov7660_stop(sd);
276 170
277 sd->sensor = NULL; 171 sd->sensor = NULL;
278 kfree(sd->sensor_priv);
279}
280
281static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
282{
283 struct sd *sd = (struct sd *) gspca_dev;
284 s32 *sensor_settings = sd->sensor_priv;
285
286 *val = sensor_settings[GAIN_IDX];
287 PDEBUG(D_V4L2, "Read gain %d", *val);
288 return 0;
289} 172}
290 173
291static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val) 174static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val)
292{ 175{
293 int err; 176 int err;
294 u8 i2c_data; 177 u8 i2c_data = val;
295 struct sd *sd = (struct sd *) gspca_dev; 178 struct sd *sd = (struct sd *) gspca_dev;
296 s32 *sensor_settings = sd->sensor_priv;
297 179
298 PDEBUG(D_V4L2, "Setting gain to %d", val); 180 PDEBUG(D_CONF, "Setting gain to %d", val);
299
300 sensor_settings[GAIN_IDX] = val;
301 181
302 err = m5602_write_sensor(sd, OV7660_GAIN, &i2c_data, 1); 182 err = m5602_write_sensor(sd, OV7660_GAIN, &i2c_data, 1);
303 return err; 183 return err;
304} 184}
305 185
306
307static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev,
308 __s32 *val)
309{
310 struct sd *sd = (struct sd *) gspca_dev;
311 s32 *sensor_settings = sd->sensor_priv;
312
313 *val = sensor_settings[AUTO_WHITE_BALANCE_IDX];
314 return 0;
315}
316
317static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev, 186static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev,
318 __s32 val) 187 __s32 val)
319{ 188{
320 int err; 189 int err;
321 u8 i2c_data; 190 u8 i2c_data;
322 struct sd *sd = (struct sd *) gspca_dev; 191 struct sd *sd = (struct sd *) gspca_dev;
323 s32 *sensor_settings = sd->sensor_priv;
324 192
325 PDEBUG(D_V4L2, "Set auto white balance to %d", val); 193 PDEBUG(D_CONF, "Set auto white balance to %d", val);
326 194
327 sensor_settings[AUTO_WHITE_BALANCE_IDX] = val;
328 err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); 195 err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1);
329 if (err < 0) 196 if (err < 0)
330 return err; 197 return err;
@@ -335,26 +202,14 @@ static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev,
335 return err; 202 return err;
336} 203}
337 204
338static int ov7660_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
339{
340 struct sd *sd = (struct sd *) gspca_dev;
341 s32 *sensor_settings = sd->sensor_priv;
342
343 *val = sensor_settings[AUTO_GAIN_CTRL_IDX];
344 PDEBUG(D_V4L2, "Read auto gain control %d", *val);
345 return 0;
346}
347
348static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val) 205static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
349{ 206{
350 int err; 207 int err;
351 u8 i2c_data; 208 u8 i2c_data;
352 struct sd *sd = (struct sd *) gspca_dev; 209 struct sd *sd = (struct sd *) gspca_dev;
353 s32 *sensor_settings = sd->sensor_priv;
354 210
355 PDEBUG(D_V4L2, "Set auto gain control to %d", val); 211 PDEBUG(D_CONF, "Set auto gain control to %d", val);
356 212
357 sensor_settings[AUTO_GAIN_CTRL_IDX] = val;
358 err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); 213 err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1);
359 if (err < 0) 214 if (err < 0)
360 return err; 215 return err;
@@ -364,94 +219,69 @@ static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
364 return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1); 219 return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1);
365} 220}
366 221
367static int ov7660_get_auto_exposure(struct gspca_dev *gspca_dev, __s32 *val)
368{
369 struct sd *sd = (struct sd *) gspca_dev;
370 s32 *sensor_settings = sd->sensor_priv;
371
372 *val = sensor_settings[AUTO_EXPOSURE_IDX];
373 PDEBUG(D_V4L2, "Read auto exposure control %d", *val);
374 return 0;
375}
376
377static int ov7660_set_auto_exposure(struct gspca_dev *gspca_dev, 222static int ov7660_set_auto_exposure(struct gspca_dev *gspca_dev,
378 __s32 val) 223 __s32 val)
379{ 224{
380 int err; 225 int err;
381 u8 i2c_data; 226 u8 i2c_data;
382 struct sd *sd = (struct sd *) gspca_dev; 227 struct sd *sd = (struct sd *) gspca_dev;
383 s32 *sensor_settings = sd->sensor_priv;
384 228
385 PDEBUG(D_V4L2, "Set auto exposure control to %d", val); 229 PDEBUG(D_CONF, "Set auto exposure control to %d", val);
386 230
387 sensor_settings[AUTO_EXPOSURE_IDX] = val;
388 err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); 231 err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1);
389 if (err < 0) 232 if (err < 0)
390 return err; 233 return err;
391 234
235 val = (val == V4L2_EXPOSURE_AUTO);
392 i2c_data = ((i2c_data & 0xfe) | ((val & 0x01) << 0)); 236 i2c_data = ((i2c_data & 0xfe) | ((val & 0x01) << 0));
393 237
394 return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1); 238 return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1);
395} 239}
396 240
397static int ov7660_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) 241static int ov7660_set_hvflip(struct gspca_dev *gspca_dev)
398{
399 struct sd *sd = (struct sd *) gspca_dev;
400 s32 *sensor_settings = sd->sensor_priv;
401
402 *val = sensor_settings[HFLIP_IDX];
403 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
404 return 0;
405}
406
407static int ov7660_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
408{ 242{
409 int err; 243 int err;
410 u8 i2c_data; 244 u8 i2c_data;
411 struct sd *sd = (struct sd *) gspca_dev; 245 struct sd *sd = (struct sd *) gspca_dev;
412 s32 *sensor_settings = sd->sensor_priv;
413 246
414 PDEBUG(D_V4L2, "Set horizontal flip to %d", val); 247 PDEBUG(D_CONF, "Set hvflip to %d, %d", sd->hflip->val, sd->vflip->val);
415 248
416 sensor_settings[HFLIP_IDX] = val; 249 i2c_data = (sd->hflip->val << 5) | (sd->vflip->val << 4);
417
418 i2c_data = ((val & 0x01) << 5) |
419 (sensor_settings[VFLIP_IDX] << 4);
420 250
421 err = m5602_write_sensor(sd, OV7660_MVFP, &i2c_data, 1); 251 err = m5602_write_sensor(sd, OV7660_MVFP, &i2c_data, 1);
422 252
423 return err; 253 return err;
424} 254}
425 255
426static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) 256static int ov7660_s_ctrl(struct v4l2_ctrl *ctrl)
427{ 257{
258 struct gspca_dev *gspca_dev =
259 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
428 struct sd *sd = (struct sd *) gspca_dev; 260 struct sd *sd = (struct sd *) gspca_dev;
429 s32 *sensor_settings = sd->sensor_priv;
430
431 *val = sensor_settings[VFLIP_IDX];
432 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
433
434 return 0;
435}
436
437static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
438{
439 int err; 261 int err;
440 u8 i2c_data;
441 struct sd *sd = (struct sd *) gspca_dev;
442 s32 *sensor_settings = sd->sensor_priv;
443
444 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
445 sensor_settings[VFLIP_IDX] = val;
446 262
447 i2c_data = ((val & 0x01) << 4) | (sensor_settings[VFLIP_IDX] << 5); 263 if (!gspca_dev->streaming)
448 err = m5602_write_sensor(sd, OV7660_MVFP, &i2c_data, 1); 264 return 0;
449 if (err < 0) 265
450 return err; 266 switch (ctrl->id) {
451 267 case V4L2_CID_AUTO_WHITE_BALANCE:
452 /* When vflip is toggled we need to readjust the bridge hsync/vsync */ 268 err = ov7660_set_auto_white_balance(gspca_dev, ctrl->val);
453 if (gspca_dev->streaming) 269 break;
454 err = ov7660_start(sd); 270 case V4L2_CID_EXPOSURE_AUTO:
271 err = ov7660_set_auto_exposure(gspca_dev, ctrl->val);
272 break;
273 case V4L2_CID_AUTOGAIN:
274 err = ov7660_set_auto_gain(gspca_dev, ctrl->val);
275 if (err || ctrl->val)
276 return err;
277 err = ov7660_set_gain(gspca_dev, sd->gain->val);
278 break;
279 case V4L2_CID_HFLIP:
280 err = ov7660_set_hvflip(gspca_dev);
281 break;
282 default:
283 return -EINVAL;
284 }
455 285
456 return err; 286 return err;
457} 287}
diff --git a/drivers/media/usb/gspca/m5602/m5602_ov7660.h b/drivers/media/usb/gspca/m5602/m5602_ov7660.h
index 2b6a13b508f7..6fece1ce1232 100644
--- a/drivers/media/usb/gspca/m5602/m5602_ov7660.h
+++ b/drivers/media/usb/gspca/m5602/m5602_ov7660.h
@@ -90,6 +90,8 @@ extern bool dump_sensor;
90 90
91int ov7660_probe(struct sd *sd); 91int ov7660_probe(struct sd *sd);
92int ov7660_init(struct sd *sd); 92int ov7660_init(struct sd *sd);
93int ov7660_init(struct sd *sd);
94int ov7660_init_controls(struct sd *sd);
93int ov7660_start(struct sd *sd); 95int ov7660_start(struct sd *sd);
94int ov7660_stop(struct sd *sd); 96int ov7660_stop(struct sd *sd);
95void ov7660_disconnect(struct sd *sd); 97void ov7660_disconnect(struct sd *sd);
@@ -100,6 +102,7 @@ static const struct m5602_sensor ov7660 = {
100 .i2c_regW = 1, 102 .i2c_regW = 1,
101 .probe = ov7660_probe, 103 .probe = ov7660_probe,
102 .init = ov7660_init, 104 .init = ov7660_init,
105 .init_controls = ov7660_init_controls,
103 .start = ov7660_start, 106 .start = ov7660_start,
104 .stop = ov7660_stop, 107 .stop = ov7660_stop,
105 .disconnect = ov7660_disconnect, 108 .disconnect = ov7660_disconnect,
diff --git a/drivers/media/usb/gspca/m5602/m5602_ov9650.c b/drivers/media/usb/gspca/m5602/m5602_ov9650.c
index 2114a8b90ec9..59bc62bfae26 100644
--- a/drivers/media/usb/gspca/m5602/m5602_ov9650.c
+++ b/drivers/media/usb/gspca/m5602/m5602_ov9650.c
@@ -20,26 +20,8 @@
20 20
21#include "m5602_ov9650.h" 21#include "m5602_ov9650.h"
22 22
23static int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val); 23static int ov9650_s_ctrl(struct v4l2_ctrl *ctrl);
24static int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val); 24static void ov9650_dump_registers(struct sd *sd);
25static int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
26static int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val);
27static int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
28static int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
29static int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
30static int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
31static int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
32static int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
33static int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
34static int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
35static int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev,
36 __s32 *val);
37static int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev,
38 __s32 val);
39static int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val);
40static int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val);
41static int ov9650_get_auto_exposure(struct gspca_dev *gspca_dev, __s32 *val);
42static int ov9650_set_auto_exposure(struct gspca_dev *gspca_dev, __s32 val);
43 25
44/* Vertically and horizontally flips the image if matched, needed for machines 26/* Vertically and horizontally flips the image if matched, needed for machines
45 where the sensor is mounted upside down */ 27 where the sensor is mounted upside down */
@@ -113,140 +95,6 @@ static
113 {} 95 {}
114}; 96};
115 97
116static const struct ctrl ov9650_ctrls[] = {
117#define EXPOSURE_IDX 0
118 {
119 {
120 .id = V4L2_CID_EXPOSURE,
121 .type = V4L2_CTRL_TYPE_INTEGER,
122 .name = "exposure",
123 .minimum = 0x00,
124 .maximum = 0x1ff,
125 .step = 0x4,
126 .default_value = EXPOSURE_DEFAULT,
127 .flags = V4L2_CTRL_FLAG_SLIDER
128 },
129 .set = ov9650_set_exposure,
130 .get = ov9650_get_exposure
131 },
132#define GAIN_IDX 1
133 {
134 {
135 .id = V4L2_CID_GAIN,
136 .type = V4L2_CTRL_TYPE_INTEGER,
137 .name = "gain",
138 .minimum = 0x00,
139 .maximum = 0x3ff,
140 .step = 0x1,
141 .default_value = GAIN_DEFAULT,
142 .flags = V4L2_CTRL_FLAG_SLIDER
143 },
144 .set = ov9650_set_gain,
145 .get = ov9650_get_gain
146 },
147#define RED_BALANCE_IDX 2
148 {
149 {
150 .id = V4L2_CID_RED_BALANCE,
151 .type = V4L2_CTRL_TYPE_INTEGER,
152 .name = "red balance",
153 .minimum = 0x00,
154 .maximum = 0xff,
155 .step = 0x1,
156 .default_value = RED_GAIN_DEFAULT,
157 .flags = V4L2_CTRL_FLAG_SLIDER
158 },
159 .set = ov9650_set_red_balance,
160 .get = ov9650_get_red_balance
161 },
162#define BLUE_BALANCE_IDX 3
163 {
164 {
165 .id = V4L2_CID_BLUE_BALANCE,
166 .type = V4L2_CTRL_TYPE_INTEGER,
167 .name = "blue balance",
168 .minimum = 0x00,
169 .maximum = 0xff,
170 .step = 0x1,
171 .default_value = BLUE_GAIN_DEFAULT,
172 .flags = V4L2_CTRL_FLAG_SLIDER
173 },
174 .set = ov9650_set_blue_balance,
175 .get = ov9650_get_blue_balance
176 },
177#define HFLIP_IDX 4
178 {
179 {
180 .id = V4L2_CID_HFLIP,
181 .type = V4L2_CTRL_TYPE_BOOLEAN,
182 .name = "horizontal flip",
183 .minimum = 0,
184 .maximum = 1,
185 .step = 1,
186 .default_value = 0
187 },
188 .set = ov9650_set_hflip,
189 .get = ov9650_get_hflip
190 },
191#define VFLIP_IDX 5
192 {
193 {
194 .id = V4L2_CID_VFLIP,
195 .type = V4L2_CTRL_TYPE_BOOLEAN,
196 .name = "vertical flip",
197 .minimum = 0,
198 .maximum = 1,
199 .step = 1,
200 .default_value = 0
201 },
202 .set = ov9650_set_vflip,
203 .get = ov9650_get_vflip
204 },
205#define AUTO_WHITE_BALANCE_IDX 6
206 {
207 {
208 .id = V4L2_CID_AUTO_WHITE_BALANCE,
209 .type = V4L2_CTRL_TYPE_BOOLEAN,
210 .name = "auto white balance",
211 .minimum = 0,
212 .maximum = 1,
213 .step = 1,
214 .default_value = 1
215 },
216 .set = ov9650_set_auto_white_balance,
217 .get = ov9650_get_auto_white_balance
218 },
219#define AUTO_GAIN_CTRL_IDX 7
220 {
221 {
222 .id = V4L2_CID_AUTOGAIN,
223 .type = V4L2_CTRL_TYPE_BOOLEAN,
224 .name = "auto gain control",
225 .minimum = 0,
226 .maximum = 1,
227 .step = 1,
228 .default_value = 1
229 },
230 .set = ov9650_set_auto_gain,
231 .get = ov9650_get_auto_gain
232 },
233#define AUTO_EXPOSURE_IDX 8
234 {
235 {
236 .id = V4L2_CID_EXPOSURE_AUTO,
237 .type = V4L2_CTRL_TYPE_BOOLEAN,
238 .name = "auto exposure",
239 .minimum = 0,
240 .maximum = 1,
241 .step = 1,
242 .default_value = 1
243 },
244 .set = ov9650_set_auto_exposure,
245 .get = ov9650_get_auto_exposure
246 }
247
248};
249
250static struct v4l2_pix_format ov9650_modes[] = { 98static struct v4l2_pix_format ov9650_modes[] = {
251 { 99 {
252 176, 100 176,
@@ -291,13 +139,15 @@ static struct v4l2_pix_format ov9650_modes[] = {
291 } 139 }
292}; 140};
293 141
294static void ov9650_dump_registers(struct sd *sd); 142static const struct v4l2_ctrl_ops ov9650_ctrl_ops = {
143 .s_ctrl = ov9650_s_ctrl,
144};
295 145
296int ov9650_probe(struct sd *sd) 146int ov9650_probe(struct sd *sd)
297{ 147{
298 int err = 0; 148 int err = 0;
299 u8 prod_id = 0, ver_id = 0, i; 149 u8 prod_id = 0, ver_id = 0, i;
300 s32 *sensor_settings; 150 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
301 151
302 if (force_sensor) { 152 if (force_sensor) {
303 if (force_sensor == OV9650_SENSOR) { 153 if (force_sensor == OV9650_SENSOR) {
@@ -338,19 +188,9 @@ int ov9650_probe(struct sd *sd)
338 return -ENODEV; 188 return -ENODEV;
339 189
340sensor_found: 190sensor_found:
341 sensor_settings = kmalloc(
342 ARRAY_SIZE(ov9650_ctrls) * sizeof(s32), GFP_KERNEL);
343 if (!sensor_settings)
344 return -ENOMEM;
345
346 sd->gspca_dev.cam.cam_mode = ov9650_modes; 191 sd->gspca_dev.cam.cam_mode = ov9650_modes;
347 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov9650_modes); 192 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov9650_modes);
348 sd->desc->ctrls = ov9650_ctrls;
349 sd->desc->nctrls = ARRAY_SIZE(ov9650_ctrls);
350 193
351 for (i = 0; i < ARRAY_SIZE(ov9650_ctrls); i++)
352 sensor_settings[i] = ov9650_ctrls[i].qctrl.default_value;
353 sd->sensor_priv = sensor_settings;
354 return 0; 194 return 0;
355} 195}
356 196
@@ -358,7 +198,6 @@ int ov9650_init(struct sd *sd)
358{ 198{
359 int i, err = 0; 199 int i, err = 0;
360 u8 data; 200 u8 data;
361 s32 *sensor_settings = sd->sensor_priv;
362 201
363 if (dump_sensor) 202 if (dump_sensor)
364 ov9650_dump_registers(sd); 203 ov9650_dump_registers(sd);
@@ -372,46 +211,52 @@ int ov9650_init(struct sd *sd)
372 err = m5602_write_bridge(sd, init_ov9650[i][1], data); 211 err = m5602_write_bridge(sd, init_ov9650[i][1], data);
373 } 212 }
374 213
375 err = ov9650_set_exposure(&sd->gspca_dev, 214 return 0;
376 sensor_settings[EXPOSURE_IDX]); 215}
377 if (err < 0)
378 return err;
379
380 err = ov9650_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]);
381 if (err < 0)
382 return err;
383
384 err = ov9650_set_red_balance(&sd->gspca_dev,
385 sensor_settings[RED_BALANCE_IDX]);
386 if (err < 0)
387 return err;
388
389 err = ov9650_set_blue_balance(&sd->gspca_dev,
390 sensor_settings[BLUE_BALANCE_IDX]);
391 if (err < 0)
392 return err;
393
394 err = ov9650_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]);
395 if (err < 0)
396 return err;
397
398 err = ov9650_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]);
399 if (err < 0)
400 return err;
401 216
402 err = ov9650_set_auto_exposure(&sd->gspca_dev, 217int ov9650_init_controls(struct sd *sd)
403 sensor_settings[AUTO_EXPOSURE_IDX]); 218{
404 if (err < 0) 219 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
405 return err; 220
221 sd->gspca_dev.vdev.ctrl_handler = hdl;
222 v4l2_ctrl_handler_init(hdl, 9);
223
224 sd->auto_white_bal = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops,
225 V4L2_CID_AUTO_WHITE_BALANCE,
226 0, 1, 1, 1);
227 sd->red_bal = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops,
228 V4L2_CID_RED_BALANCE, 0, 255, 1,
229 RED_GAIN_DEFAULT);
230 sd->blue_bal = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops,
231 V4L2_CID_BLUE_BALANCE, 0, 255, 1,
232 BLUE_GAIN_DEFAULT);
233
234 sd->autoexpo = v4l2_ctrl_new_std_menu(hdl, &ov9650_ctrl_ops,
235 V4L2_CID_EXPOSURE_AUTO, 1, 0, V4L2_EXPOSURE_AUTO);
236 sd->expo = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops, V4L2_CID_EXPOSURE,
237 0, 0x1ff, 4, EXPOSURE_DEFAULT);
238
239 sd->autogain = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops,
240 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
241 sd->gain = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops, V4L2_CID_GAIN, 0,
242 0x3ff, 1, GAIN_DEFAULT);
243
244 sd->hflip = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops, V4L2_CID_HFLIP,
245 0, 1, 1, 0);
246 sd->vflip = v4l2_ctrl_new_std(hdl, &ov9650_ctrl_ops, V4L2_CID_VFLIP,
247 0, 1, 1, 0);
248
249 if (hdl->error) {
250 pr_err("Could not initialize controls\n");
251 return hdl->error;
252 }
406 253
407 err = ov9650_set_auto_white_balance(&sd->gspca_dev, 254 v4l2_ctrl_auto_cluster(3, &sd->auto_white_bal, 0, false);
408 sensor_settings[AUTO_WHITE_BALANCE_IDX]); 255 v4l2_ctrl_auto_cluster(2, &sd->autoexpo, 0, false);
409 if (err < 0) 256 v4l2_ctrl_auto_cluster(2, &sd->autogain, 0, false);
410 return err; 257 v4l2_ctrl_cluster(2, &sd->hflip);
411 258
412 err = ov9650_set_auto_gain(&sd->gspca_dev, 259 return 0;
413 sensor_settings[AUTO_GAIN_CTRL_IDX]);
414 return err;
415} 260}
416 261
417int ov9650_start(struct sd *sd) 262int ov9650_start(struct sd *sd)
@@ -419,17 +264,17 @@ int ov9650_start(struct sd *sd)
419 u8 data; 264 u8 data;
420 int i, err = 0; 265 int i, err = 0;
421 struct cam *cam = &sd->gspca_dev.cam; 266 struct cam *cam = &sd->gspca_dev.cam;
422 s32 *sensor_settings = sd->sensor_priv;
423 267
424 int width = cam->cam_mode[sd->gspca_dev.curr_mode].width; 268 int width = cam->cam_mode[sd->gspca_dev.curr_mode].width;
425 int height = cam->cam_mode[sd->gspca_dev.curr_mode].height; 269 int height = cam->cam_mode[sd->gspca_dev.curr_mode].height;
426 int ver_offs = cam->cam_mode[sd->gspca_dev.curr_mode].priv; 270 int ver_offs = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
427 int hor_offs = OV9650_LEFT_OFFSET; 271 int hor_offs = OV9650_LEFT_OFFSET;
272 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
428 273
429 if ((!dmi_check_system(ov9650_flip_dmi_table) && 274 if ((!dmi_check_system(ov9650_flip_dmi_table) &&
430 sensor_settings[VFLIP_IDX]) || 275 sd->vflip->val) ||
431 (dmi_check_system(ov9650_flip_dmi_table) && 276 (dmi_check_system(ov9650_flip_dmi_table) &&
432 !sensor_settings[VFLIP_IDX])) 277 !sd->vflip->val))
433 ver_offs--; 278 ver_offs--;
434 279
435 if (width <= 320) 280 if (width <= 320)
@@ -508,7 +353,7 @@ int ov9650_start(struct sd *sd)
508 353
509 switch (width) { 354 switch (width) {
510 case 640: 355 case 640:
511 PDEBUG(D_V4L2, "Configuring camera for VGA mode"); 356 PDEBUG(D_CONF, "Configuring camera for VGA mode");
512 357
513 data = OV9650_VGA_SELECT | OV9650_RGB_SELECT | 358 data = OV9650_VGA_SELECT | OV9650_RGB_SELECT |
514 OV9650_RAW_RGB_SELECT; 359 OV9650_RAW_RGB_SELECT;
@@ -516,7 +361,7 @@ int ov9650_start(struct sd *sd)
516 break; 361 break;
517 362
518 case 352: 363 case 352:
519 PDEBUG(D_V4L2, "Configuring camera for CIF mode"); 364 PDEBUG(D_CONF, "Configuring camera for CIF mode");
520 365
521 data = OV9650_CIF_SELECT | OV9650_RGB_SELECT | 366 data = OV9650_CIF_SELECT | OV9650_RGB_SELECT |
522 OV9650_RAW_RGB_SELECT; 367 OV9650_RAW_RGB_SELECT;
@@ -524,7 +369,7 @@ int ov9650_start(struct sd *sd)
524 break; 369 break;
525 370
526 case 320: 371 case 320:
527 PDEBUG(D_V4L2, "Configuring camera for QVGA mode"); 372 PDEBUG(D_CONF, "Configuring camera for QVGA mode");
528 373
529 data = OV9650_QVGA_SELECT | OV9650_RGB_SELECT | 374 data = OV9650_QVGA_SELECT | OV9650_RGB_SELECT |
530 OV9650_RAW_RGB_SELECT; 375 OV9650_RAW_RGB_SELECT;
@@ -532,7 +377,7 @@ int ov9650_start(struct sd *sd)
532 break; 377 break;
533 378
534 case 176: 379 case 176:
535 PDEBUG(D_V4L2, "Configuring camera for QCIF mode"); 380 PDEBUG(D_CONF, "Configuring camera for QCIF mode");
536 381
537 data = OV9650_QCIF_SELECT | OV9650_RGB_SELECT | 382 data = OV9650_QCIF_SELECT | OV9650_RGB_SELECT |
538 OV9650_RAW_RGB_SELECT; 383 OV9650_RAW_RGB_SELECT;
@@ -553,29 +398,16 @@ void ov9650_disconnect(struct sd *sd)
553 ov9650_stop(sd); 398 ov9650_stop(sd);
554 399
555 sd->sensor = NULL; 400 sd->sensor = NULL;
556 kfree(sd->sensor_priv);
557}
558
559static int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
560{
561 struct sd *sd = (struct sd *) gspca_dev;
562 s32 *sensor_settings = sd->sensor_priv;
563
564 *val = sensor_settings[EXPOSURE_IDX];
565 PDEBUG(D_V4L2, "Read exposure %d", *val);
566 return 0;
567} 401}
568 402
569static int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val) 403static int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
570{ 404{
571 struct sd *sd = (struct sd *) gspca_dev; 405 struct sd *sd = (struct sd *) gspca_dev;
572 s32 *sensor_settings = sd->sensor_priv;
573 u8 i2c_data; 406 u8 i2c_data;
574 int err; 407 int err;
575 408
576 PDEBUG(D_V4L2, "Set exposure to %d", val); 409 PDEBUG(D_CONF, "Set exposure to %d", val);
577 410
578 sensor_settings[EXPOSURE_IDX] = val;
579 /* The 6 MSBs */ 411 /* The 6 MSBs */
580 i2c_data = (val >> 10) & 0x3f; 412 i2c_data = (val >> 10) & 0x3f;
581 err = m5602_write_sensor(sd, OV9650_AECHM, 413 err = m5602_write_sensor(sd, OV9650_AECHM,
@@ -596,26 +428,13 @@ static int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
596 return err; 428 return err;
597} 429}
598 430
599static int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
600{
601 struct sd *sd = (struct sd *) gspca_dev;
602 s32 *sensor_settings = sd->sensor_priv;
603
604 *val = sensor_settings[GAIN_IDX];
605 PDEBUG(D_V4L2, "Read gain %d", *val);
606 return 0;
607}
608
609static int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val) 431static int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
610{ 432{
611 int err; 433 int err;
612 u8 i2c_data; 434 u8 i2c_data;
613 struct sd *sd = (struct sd *) gspca_dev; 435 struct sd *sd = (struct sd *) gspca_dev;
614 s32 *sensor_settings = sd->sensor_priv;
615 436
616 PDEBUG(D_V4L2, "Setting gain to %d", val); 437 PDEBUG(D_CONF, "Setting gain to %d", val);
617
618 sensor_settings[GAIN_IDX] = val;
619 438
620 /* The 2 MSB */ 439 /* The 2 MSB */
621 /* Read the OV9650_VREF register first to avoid 440 /* Read the OV9650_VREF register first to avoid
@@ -637,117 +456,46 @@ static int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
637 return err; 456 return err;
638} 457}
639 458
640static int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
641{
642 struct sd *sd = (struct sd *) gspca_dev;
643 s32 *sensor_settings = sd->sensor_priv;
644
645 *val = sensor_settings[RED_BALANCE_IDX];
646 PDEBUG(D_V4L2, "Read red gain %d", *val);
647 return 0;
648}
649
650static int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) 459static int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
651{ 460{
652 int err; 461 int err;
653 u8 i2c_data; 462 u8 i2c_data;
654 struct sd *sd = (struct sd *) gspca_dev; 463 struct sd *sd = (struct sd *) gspca_dev;
655 s32 *sensor_settings = sd->sensor_priv;
656 464
657 PDEBUG(D_V4L2, "Set red gain to %d", val); 465 PDEBUG(D_CONF, "Set red gain to %d", val);
658
659 sensor_settings[RED_BALANCE_IDX] = val;
660 466
661 i2c_data = val & 0xff; 467 i2c_data = val & 0xff;
662 err = m5602_write_sensor(sd, OV9650_RED, &i2c_data, 1); 468 err = m5602_write_sensor(sd, OV9650_RED, &i2c_data, 1);
663 return err; 469 return err;
664} 470}
665 471
666static int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
667{
668 struct sd *sd = (struct sd *) gspca_dev;
669 s32 *sensor_settings = sd->sensor_priv;
670
671 *val = sensor_settings[BLUE_BALANCE_IDX];
672 PDEBUG(D_V4L2, "Read blue gain %d", *val);
673
674 return 0;
675}
676
677static int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) 472static int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
678{ 473{
679 int err; 474 int err;
680 u8 i2c_data; 475 u8 i2c_data;
681 struct sd *sd = (struct sd *) gspca_dev; 476 struct sd *sd = (struct sd *) gspca_dev;
682 s32 *sensor_settings = sd->sensor_priv;
683
684 PDEBUG(D_V4L2, "Set blue gain to %d", val);
685 477
686 sensor_settings[BLUE_BALANCE_IDX] = val; 478 PDEBUG(D_CONF, "Set blue gain to %d", val);
687 479
688 i2c_data = val & 0xff; 480 i2c_data = val & 0xff;
689 err = m5602_write_sensor(sd, OV9650_BLUE, &i2c_data, 1); 481 err = m5602_write_sensor(sd, OV9650_BLUE, &i2c_data, 1);
690 return err; 482 return err;
691} 483}
692 484
693static int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) 485static int ov9650_set_hvflip(struct gspca_dev *gspca_dev)
694{
695 struct sd *sd = (struct sd *) gspca_dev;
696 s32 *sensor_settings = sd->sensor_priv;
697
698 *val = sensor_settings[HFLIP_IDX];
699 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
700 return 0;
701}
702
703static int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
704{ 486{
705 int err; 487 int err;
706 u8 i2c_data; 488 u8 i2c_data;
707 struct sd *sd = (struct sd *) gspca_dev; 489 struct sd *sd = (struct sd *) gspca_dev;
708 s32 *sensor_settings = sd->sensor_priv; 490 int hflip = sd->hflip->val;
491 int vflip = sd->vflip->val;
709 492
710 PDEBUG(D_V4L2, "Set horizontal flip to %d", val); 493 PDEBUG(D_CONF, "Set hvflip to %d %d", hflip, vflip);
711
712 sensor_settings[HFLIP_IDX] = val;
713
714 if (!dmi_check_system(ov9650_flip_dmi_table))
715 i2c_data = ((val & 0x01) << 5) |
716 (sensor_settings[VFLIP_IDX] << 4);
717 else
718 i2c_data = ((val & 0x01) << 5) |
719 (!sensor_settings[VFLIP_IDX] << 4);
720
721 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
722
723 return err;
724}
725
726static int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
727{
728 struct sd *sd = (struct sd *) gspca_dev;
729 s32 *sensor_settings = sd->sensor_priv;
730
731 *val = sensor_settings[VFLIP_IDX];
732 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
733
734 return 0;
735}
736
737static int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
738{
739 int err;
740 u8 i2c_data;
741 struct sd *sd = (struct sd *) gspca_dev;
742 s32 *sensor_settings = sd->sensor_priv;
743
744 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
745 sensor_settings[VFLIP_IDX] = val;
746 494
747 if (dmi_check_system(ov9650_flip_dmi_table)) 495 if (dmi_check_system(ov9650_flip_dmi_table))
748 val = !val; 496 vflip = !vflip;
749 497
750 i2c_data = ((val & 0x01) << 4) | (sensor_settings[VFLIP_IDX] << 5); 498 i2c_data = (hflip << 5) | (vflip << 4);
751 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); 499 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
752 if (err < 0) 500 if (err < 0)
753 return err; 501 return err;
@@ -759,57 +507,34 @@ static int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
759 return err; 507 return err;
760} 508}
761 509
762static int ov9650_get_auto_exposure(struct gspca_dev *gspca_dev, __s32 *val)
763{
764 struct sd *sd = (struct sd *) gspca_dev;
765 s32 *sensor_settings = sd->sensor_priv;
766
767 *val = sensor_settings[AUTO_EXPOSURE_IDX];
768 PDEBUG(D_V4L2, "Read auto exposure control %d", *val);
769 return 0;
770}
771
772static int ov9650_set_auto_exposure(struct gspca_dev *gspca_dev, 510static int ov9650_set_auto_exposure(struct gspca_dev *gspca_dev,
773 __s32 val) 511 __s32 val)
774{ 512{
775 int err; 513 int err;
776 u8 i2c_data; 514 u8 i2c_data;
777 struct sd *sd = (struct sd *) gspca_dev; 515 struct sd *sd = (struct sd *) gspca_dev;
778 s32 *sensor_settings = sd->sensor_priv;
779 516
780 PDEBUG(D_V4L2, "Set auto exposure control to %d", val); 517 PDEBUG(D_CONF, "Set auto exposure control to %d", val);
781 518
782 sensor_settings[AUTO_EXPOSURE_IDX] = val;
783 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 519 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
784 if (err < 0) 520 if (err < 0)
785 return err; 521 return err;
786 522
523 val = (val == V4L2_EXPOSURE_AUTO);
787 i2c_data = ((i2c_data & 0xfe) | ((val & 0x01) << 0)); 524 i2c_data = ((i2c_data & 0xfe) | ((val & 0x01) << 0));
788 525
789 return m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1); 526 return m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
790} 527}
791 528
792static int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev,
793 __s32 *val)
794{
795 struct sd *sd = (struct sd *) gspca_dev;
796 s32 *sensor_settings = sd->sensor_priv;
797
798 *val = sensor_settings[AUTO_WHITE_BALANCE_IDX];
799 return 0;
800}
801
802static int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, 529static int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev,
803 __s32 val) 530 __s32 val)
804{ 531{
805 int err; 532 int err;
806 u8 i2c_data; 533 u8 i2c_data;
807 struct sd *sd = (struct sd *) gspca_dev; 534 struct sd *sd = (struct sd *) gspca_dev;
808 s32 *sensor_settings = sd->sensor_priv;
809 535
810 PDEBUG(D_V4L2, "Set auto white balance to %d", val); 536 PDEBUG(D_CONF, "Set auto white balance to %d", val);
811 537
812 sensor_settings[AUTO_WHITE_BALANCE_IDX] = val;
813 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 538 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
814 if (err < 0) 539 if (err < 0)
815 return err; 540 return err;
@@ -820,26 +545,14 @@ static int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev,
820 return err; 545 return err;
821} 546}
822 547
823static int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
824{
825 struct sd *sd = (struct sd *) gspca_dev;
826 s32 *sensor_settings = sd->sensor_priv;
827
828 *val = sensor_settings[AUTO_GAIN_CTRL_IDX];
829 PDEBUG(D_V4L2, "Read auto gain control %d", *val);
830 return 0;
831}
832
833static int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val) 548static int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
834{ 549{
835 int err; 550 int err;
836 u8 i2c_data; 551 u8 i2c_data;
837 struct sd *sd = (struct sd *) gspca_dev; 552 struct sd *sd = (struct sd *) gspca_dev;
838 s32 *sensor_settings = sd->sensor_priv;
839 553
840 PDEBUG(D_V4L2, "Set auto gain control to %d", val); 554 PDEBUG(D_CONF, "Set auto gain control to %d", val);
841 555
842 sensor_settings[AUTO_GAIN_CTRL_IDX] = val;
843 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 556 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
844 if (err < 0) 557 if (err < 0)
845 return err; 558 return err;
@@ -849,6 +562,48 @@ static int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
849 return m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1); 562 return m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
850} 563}
851 564
565static int ov9650_s_ctrl(struct v4l2_ctrl *ctrl)
566{
567 struct gspca_dev *gspca_dev =
568 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
569 struct sd *sd = (struct sd *) gspca_dev;
570 int err;
571
572 if (!gspca_dev->streaming)
573 return 0;
574
575 switch (ctrl->id) {
576 case V4L2_CID_AUTO_WHITE_BALANCE:
577 err = ov9650_set_auto_white_balance(gspca_dev, ctrl->val);
578 if (err || ctrl->val)
579 return err;
580 err = ov9650_set_red_balance(gspca_dev, sd->red_bal->val);
581 if (err)
582 return err;
583 err = ov9650_set_blue_balance(gspca_dev, sd->blue_bal->val);
584 break;
585 case V4L2_CID_EXPOSURE_AUTO:
586 err = ov9650_set_auto_exposure(gspca_dev, ctrl->val);
587 if (err || ctrl->val == V4L2_EXPOSURE_AUTO)
588 return err;
589 err = ov9650_set_exposure(gspca_dev, sd->expo->val);
590 break;
591 case V4L2_CID_AUTOGAIN:
592 err = ov9650_set_auto_gain(gspca_dev, ctrl->val);
593 if (err || ctrl->val)
594 return err;
595 err = ov9650_set_gain(gspca_dev, sd->gain->val);
596 break;
597 case V4L2_CID_HFLIP:
598 err = ov9650_set_hvflip(gspca_dev);
599 break;
600 default:
601 return -EINVAL;
602 }
603
604 return err;
605}
606
852static void ov9650_dump_registers(struct sd *sd) 607static void ov9650_dump_registers(struct sd *sd)
853{ 608{
854 int address; 609 int address;
diff --git a/drivers/media/usb/gspca/m5602/m5602_ov9650.h b/drivers/media/usb/gspca/m5602/m5602_ov9650.h
index f7aa5bf68983..f9f5870da60f 100644
--- a/drivers/media/usb/gspca/m5602/m5602_ov9650.h
+++ b/drivers/media/usb/gspca/m5602/m5602_ov9650.h
@@ -139,6 +139,7 @@ extern bool dump_sensor;
139 139
140int ov9650_probe(struct sd *sd); 140int ov9650_probe(struct sd *sd);
141int ov9650_init(struct sd *sd); 141int ov9650_init(struct sd *sd);
142int ov9650_init_controls(struct sd *sd);
142int ov9650_start(struct sd *sd); 143int ov9650_start(struct sd *sd);
143int ov9650_stop(struct sd *sd); 144int ov9650_stop(struct sd *sd);
144void ov9650_disconnect(struct sd *sd); 145void ov9650_disconnect(struct sd *sd);
@@ -149,6 +150,7 @@ static const struct m5602_sensor ov9650 = {
149 .i2c_regW = 1, 150 .i2c_regW = 1,
150 .probe = ov9650_probe, 151 .probe = ov9650_probe,
151 .init = ov9650_init, 152 .init = ov9650_init,
153 .init_controls = ov9650_init_controls,
152 .start = ov9650_start, 154 .start = ov9650_start,
153 .stop = ov9650_stop, 155 .stop = ov9650_stop,
154 .disconnect = ov9650_disconnect, 156 .disconnect = ov9650_disconnect,
diff --git a/drivers/media/usb/gspca/m5602/m5602_po1030.c b/drivers/media/usb/gspca/m5602/m5602_po1030.c
index b8771698cbcb..4bf5c43424b7 100644
--- a/drivers/media/usb/gspca/m5602/m5602_po1030.c
+++ b/drivers/media/usb/gspca/m5602/m5602_po1030.c
@@ -20,28 +20,8 @@
20 20
21#include "m5602_po1030.h" 21#include "m5602_po1030.h"
22 22
23static int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val); 23static int po1030_s_ctrl(struct v4l2_ctrl *ctrl);
24static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val); 24static void po1030_dump_registers(struct sd *sd);
25static int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
26static int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val);
27static int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
28static int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
29static int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
30static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
31static int po1030_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val);
32static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val);
33static int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
34static int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
35static int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
36static int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
37static int po1030_set_auto_white_balance(struct gspca_dev *gspca_dev,
38 __s32 val);
39static int po1030_get_auto_white_balance(struct gspca_dev *gspca_dev,
40 __s32 *val);
41static int po1030_set_auto_exposure(struct gspca_dev *gspca_dev,
42 __s32 val);
43static int po1030_get_auto_exposure(struct gspca_dev *gspca_dev,
44 __s32 *val);
45 25
46static struct v4l2_pix_format po1030_modes[] = { 26static struct v4l2_pix_format po1030_modes[] = {
47 { 27 {
@@ -56,146 +36,26 @@ static struct v4l2_pix_format po1030_modes[] = {
56 } 36 }
57}; 37};
58 38
59static const struct ctrl po1030_ctrls[] = { 39static const struct v4l2_ctrl_ops po1030_ctrl_ops = {
60#define GAIN_IDX 0 40 .s_ctrl = po1030_s_ctrl,
61 {
62 {
63 .id = V4L2_CID_GAIN,
64 .type = V4L2_CTRL_TYPE_INTEGER,
65 .name = "gain",
66 .minimum = 0x00,
67 .maximum = 0x4f,
68 .step = 0x1,
69 .default_value = PO1030_GLOBAL_GAIN_DEFAULT,
70 .flags = V4L2_CTRL_FLAG_SLIDER
71 },
72 .set = po1030_set_gain,
73 .get = po1030_get_gain
74 },
75#define EXPOSURE_IDX 1
76 {
77 {
78 .id = V4L2_CID_EXPOSURE,
79 .type = V4L2_CTRL_TYPE_INTEGER,
80 .name = "exposure",
81 .minimum = 0x00,
82 .maximum = 0x02ff,
83 .step = 0x1,
84 .default_value = PO1030_EXPOSURE_DEFAULT,
85 .flags = V4L2_CTRL_FLAG_SLIDER
86 },
87 .set = po1030_set_exposure,
88 .get = po1030_get_exposure
89 },
90#define RED_BALANCE_IDX 2
91 {
92 {
93 .id = V4L2_CID_RED_BALANCE,
94 .type = V4L2_CTRL_TYPE_INTEGER,
95 .name = "red balance",
96 .minimum = 0x00,
97 .maximum = 0xff,
98 .step = 0x1,
99 .default_value = PO1030_RED_GAIN_DEFAULT,
100 .flags = V4L2_CTRL_FLAG_SLIDER
101 },
102 .set = po1030_set_red_balance,
103 .get = po1030_get_red_balance
104 },
105#define BLUE_BALANCE_IDX 3
106 {
107 {
108 .id = V4L2_CID_BLUE_BALANCE,
109 .type = V4L2_CTRL_TYPE_INTEGER,
110 .name = "blue balance",
111 .minimum = 0x00,
112 .maximum = 0xff,
113 .step = 0x1,
114 .default_value = PO1030_BLUE_GAIN_DEFAULT,
115 .flags = V4L2_CTRL_FLAG_SLIDER
116 },
117 .set = po1030_set_blue_balance,
118 .get = po1030_get_blue_balance
119 },
120#define HFLIP_IDX 4
121 {
122 {
123 .id = V4L2_CID_HFLIP,
124 .type = V4L2_CTRL_TYPE_BOOLEAN,
125 .name = "horizontal flip",
126 .minimum = 0,
127 .maximum = 1,
128 .step = 1,
129 .default_value = 0,
130 },
131 .set = po1030_set_hflip,
132 .get = po1030_get_hflip
133 },
134#define VFLIP_IDX 5
135 {
136 {
137 .id = V4L2_CID_VFLIP,
138 .type = V4L2_CTRL_TYPE_BOOLEAN,
139 .name = "vertical flip",
140 .minimum = 0,
141 .maximum = 1,
142 .step = 1,
143 .default_value = 0,
144 },
145 .set = po1030_set_vflip,
146 .get = po1030_get_vflip
147 },
148#define AUTO_WHITE_BALANCE_IDX 6
149 {
150 {
151 .id = V4L2_CID_AUTO_WHITE_BALANCE,
152 .type = V4L2_CTRL_TYPE_BOOLEAN,
153 .name = "auto white balance",
154 .minimum = 0,
155 .maximum = 1,
156 .step = 1,
157 .default_value = 0,
158 },
159 .set = po1030_set_auto_white_balance,
160 .get = po1030_get_auto_white_balance
161 },
162#define AUTO_EXPOSURE_IDX 7
163 {
164 {
165 .id = V4L2_CID_EXPOSURE_AUTO,
166 .type = V4L2_CTRL_TYPE_BOOLEAN,
167 .name = "auto exposure",
168 .minimum = 0,
169 .maximum = 1,
170 .step = 1,
171 .default_value = 0,
172 },
173 .set = po1030_set_auto_exposure,
174 .get = po1030_get_auto_exposure
175 },
176#define GREEN_BALANCE_IDX 8
177 {
178 {
179 .id = M5602_V4L2_CID_GREEN_BALANCE,
180 .type = V4L2_CTRL_TYPE_INTEGER,
181 .name = "green balance",
182 .minimum = 0x00,
183 .maximum = 0xff,
184 .step = 0x1,
185 .default_value = PO1030_GREEN_GAIN_DEFAULT,
186 .flags = V4L2_CTRL_FLAG_SLIDER
187 },
188 .set = po1030_set_green_balance,
189 .get = po1030_get_green_balance
190 },
191}; 41};
192 42
193static void po1030_dump_registers(struct sd *sd); 43static const struct v4l2_ctrl_config po1030_greenbal_cfg = {
44 .ops = &po1030_ctrl_ops,
45 .id = M5602_V4L2_CID_GREEN_BALANCE,
46 .name = "Green Balance",
47 .type = V4L2_CTRL_TYPE_INTEGER,
48 .min = 0,
49 .max = 255,
50 .step = 1,
51 .def = PO1030_GREEN_GAIN_DEFAULT,
52 .flags = V4L2_CTRL_FLAG_SLIDER,
53};
194 54
195int po1030_probe(struct sd *sd) 55int po1030_probe(struct sd *sd)
196{ 56{
197 u8 dev_id_h = 0, i; 57 u8 dev_id_h = 0, i;
198 s32 *sensor_settings; 58 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
199 59
200 if (force_sensor) { 60 if (force_sensor) {
201 if (force_sensor == PO1030_SENSOR) { 61 if (force_sensor == PO1030_SENSOR) {
@@ -229,26 +89,14 @@ int po1030_probe(struct sd *sd)
229 return -ENODEV; 89 return -ENODEV;
230 90
231sensor_found: 91sensor_found:
232 sensor_settings = kmalloc(
233 ARRAY_SIZE(po1030_ctrls) * sizeof(s32), GFP_KERNEL);
234 if (!sensor_settings)
235 return -ENOMEM;
236
237 sd->gspca_dev.cam.cam_mode = po1030_modes; 92 sd->gspca_dev.cam.cam_mode = po1030_modes;
238 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(po1030_modes); 93 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(po1030_modes);
239 sd->desc->ctrls = po1030_ctrls;
240 sd->desc->nctrls = ARRAY_SIZE(po1030_ctrls);
241
242 for (i = 0; i < ARRAY_SIZE(po1030_ctrls); i++)
243 sensor_settings[i] = po1030_ctrls[i].qctrl.default_value;
244 sd->sensor_priv = sensor_settings;
245 94
246 return 0; 95 return 0;
247} 96}
248 97
249int po1030_init(struct sd *sd) 98int po1030_init(struct sd *sd)
250{ 99{
251 s32 *sensor_settings = sd->sensor_priv;
252 int i, err = 0; 100 int i, err = 0;
253 101
254 /* Init the sensor */ 102 /* Init the sensor */
@@ -279,46 +127,50 @@ int po1030_init(struct sd *sd)
279 if (dump_sensor) 127 if (dump_sensor)
280 po1030_dump_registers(sd); 128 po1030_dump_registers(sd);
281 129
282 err = po1030_set_exposure(&sd->gspca_dev, 130 return 0;
283 sensor_settings[EXPOSURE_IDX]); 131}
284 if (err < 0)
285 return err;
286
287 err = po1030_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]);
288 if (err < 0)
289 return err;
290
291 err = po1030_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]);
292 if (err < 0)
293 return err;
294
295 err = po1030_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]);
296 if (err < 0)
297 return err;
298
299 err = po1030_set_red_balance(&sd->gspca_dev,
300 sensor_settings[RED_BALANCE_IDX]);
301 if (err < 0)
302 return err;
303
304 err = po1030_set_blue_balance(&sd->gspca_dev,
305 sensor_settings[BLUE_BALANCE_IDX]);
306 if (err < 0)
307 return err;
308 132
309 err = po1030_set_green_balance(&sd->gspca_dev, 133int po1030_init_controls(struct sd *sd)
310 sensor_settings[GREEN_BALANCE_IDX]); 134{
311 if (err < 0) 135 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
312 return err; 136
137 sd->gspca_dev.vdev.ctrl_handler = hdl;
138 v4l2_ctrl_handler_init(hdl, 9);
139
140 sd->auto_white_bal = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops,
141 V4L2_CID_AUTO_WHITE_BALANCE,
142 0, 1, 1, 0);
143 sd->green_bal = v4l2_ctrl_new_custom(hdl, &po1030_greenbal_cfg, NULL);
144 sd->red_bal = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops,
145 V4L2_CID_RED_BALANCE, 0, 255, 1,
146 PO1030_RED_GAIN_DEFAULT);
147 sd->blue_bal = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops,
148 V4L2_CID_BLUE_BALANCE, 0, 255, 1,
149 PO1030_BLUE_GAIN_DEFAULT);
150
151 sd->autoexpo = v4l2_ctrl_new_std_menu(hdl, &po1030_ctrl_ops,
152 V4L2_CID_EXPOSURE_AUTO, 1, 0, V4L2_EXPOSURE_MANUAL);
153 sd->expo = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops, V4L2_CID_EXPOSURE,
154 0, 0x2ff, 1, PO1030_EXPOSURE_DEFAULT);
155
156 sd->gain = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops, V4L2_CID_GAIN, 0,
157 0x4f, 1, PO1030_GLOBAL_GAIN_DEFAULT);
158
159 sd->hflip = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops, V4L2_CID_HFLIP,
160 0, 1, 1, 0);
161 sd->vflip = v4l2_ctrl_new_std(hdl, &po1030_ctrl_ops, V4L2_CID_VFLIP,
162 0, 1, 1, 0);
163
164 if (hdl->error) {
165 pr_err("Could not initialize controls\n");
166 return hdl->error;
167 }
313 168
314 err = po1030_set_auto_white_balance(&sd->gspca_dev, 169 v4l2_ctrl_auto_cluster(4, &sd->auto_white_bal, 0, false);
315 sensor_settings[AUTO_WHITE_BALANCE_IDX]); 170 v4l2_ctrl_auto_cluster(2, &sd->autoexpo, 0, false);
316 if (err < 0) 171 v4l2_ctrl_cluster(2, &sd->hflip);
317 return err;
318 172
319 err = po1030_set_auto_exposure(&sd->gspca_dev, 173 return 0;
320 sensor_settings[AUTO_EXPOSURE_IDX]);
321 return err;
322} 174}
323 175
324int po1030_start(struct sd *sd) 176int po1030_start(struct sd *sd)
@@ -448,28 +300,16 @@ int po1030_start(struct sd *sd)
448 return err; 300 return err;
449} 301}
450 302
451static int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
452{
453 struct sd *sd = (struct sd *) gspca_dev;
454 s32 *sensor_settings = sd->sensor_priv;
455
456 *val = sensor_settings[EXPOSURE_IDX];
457 PDEBUG(D_V4L2, "Exposure read as %d", *val);
458 return 0;
459}
460
461static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val) 303static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
462{ 304{
463 struct sd *sd = (struct sd *) gspca_dev; 305 struct sd *sd = (struct sd *) gspca_dev;
464 s32 *sensor_settings = sd->sensor_priv;
465 u8 i2c_data; 306 u8 i2c_data;
466 int err; 307 int err;
467 308
468 sensor_settings[EXPOSURE_IDX] = val; 309 PDEBUG(D_CONF, "Set exposure to %d", val & 0xffff);
469 PDEBUG(D_V4L2, "Set exposure to %d", val & 0xffff);
470 310
471 i2c_data = ((val & 0xff00) >> 8); 311 i2c_data = ((val & 0xff00) >> 8);
472 PDEBUG(D_V4L2, "Set exposure to high byte to 0x%x", 312 PDEBUG(D_CONF, "Set exposure to high byte to 0x%x",
473 i2c_data); 313 i2c_data);
474 314
475 err = m5602_write_sensor(sd, PO1030_INTEGLINES_H, 315 err = m5602_write_sensor(sd, PO1030_INTEGLINES_H,
@@ -478,7 +318,7 @@ static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
478 return err; 318 return err;
479 319
480 i2c_data = (val & 0xff); 320 i2c_data = (val & 0xff);
481 PDEBUG(D_V4L2, "Set exposure to low byte to 0x%x", 321 PDEBUG(D_CONF, "Set exposure to low byte to 0x%x",
482 i2c_data); 322 i2c_data);
483 err = m5602_write_sensor(sd, PO1030_INTEGLINES_M, 323 err = m5602_write_sensor(sd, PO1030_INTEGLINES_M,
484 &i2c_data, 1); 324 &i2c_data, 1);
@@ -486,91 +326,32 @@ static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
486 return err; 326 return err;
487} 327}
488 328
489static int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
490{
491 struct sd *sd = (struct sd *) gspca_dev;
492 s32 *sensor_settings = sd->sensor_priv;
493
494 *val = sensor_settings[GAIN_IDX];
495 PDEBUG(D_V4L2, "Read global gain %d", *val);
496 return 0;
497}
498
499static int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val) 329static int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val)
500{ 330{
501 struct sd *sd = (struct sd *) gspca_dev; 331 struct sd *sd = (struct sd *) gspca_dev;
502 s32 *sensor_settings = sd->sensor_priv;
503 u8 i2c_data; 332 u8 i2c_data;
504 int err; 333 int err;
505 334
506 sensor_settings[GAIN_IDX] = val;
507
508 i2c_data = val & 0xff; 335 i2c_data = val & 0xff;
509 PDEBUG(D_V4L2, "Set global gain to %d", i2c_data); 336 PDEBUG(D_CONF, "Set global gain to %d", i2c_data);
510 err = m5602_write_sensor(sd, PO1030_GLOBALGAIN, 337 err = m5602_write_sensor(sd, PO1030_GLOBALGAIN,
511 &i2c_data, 1); 338 &i2c_data, 1);
512 return err; 339 return err;
513} 340}
514 341
515static int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) 342static int po1030_set_hvflip(struct gspca_dev *gspca_dev)
516{
517 struct sd *sd = (struct sd *) gspca_dev;
518 s32 *sensor_settings = sd->sensor_priv;
519
520 *val = sensor_settings[HFLIP_IDX];
521 PDEBUG(D_V4L2, "Read hflip %d", *val);
522
523 return 0;
524}
525
526static int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
527{
528 struct sd *sd = (struct sd *) gspca_dev;
529 s32 *sensor_settings = sd->sensor_priv;
530 u8 i2c_data;
531 int err;
532
533 sensor_settings[HFLIP_IDX] = val;
534
535 PDEBUG(D_V4L2, "Set hflip %d", val);
536 err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1);
537 if (err < 0)
538 return err;
539
540 i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7);
541
542 err = m5602_write_sensor(sd, PO1030_CONTROL2,
543 &i2c_data, 1);
544
545 return err;
546}
547
548static int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
549{ 343{
550 struct sd *sd = (struct sd *) gspca_dev; 344 struct sd *sd = (struct sd *) gspca_dev;
551 s32 *sensor_settings = sd->sensor_priv;
552
553 *val = sensor_settings[VFLIP_IDX];
554 PDEBUG(D_V4L2, "Read vflip %d", *val);
555
556 return 0;
557}
558
559static int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
560{
561 struct sd *sd = (struct sd *) gspca_dev;
562 s32 *sensor_settings = sd->sensor_priv;
563 u8 i2c_data; 345 u8 i2c_data;
564 int err; 346 int err;
565 347
566 sensor_settings[VFLIP_IDX] = val; 348 PDEBUG(D_CONF, "Set hvflip %d %d", sd->hflip->val, sd->vflip->val);
567
568 PDEBUG(D_V4L2, "Set vflip %d", val);
569 err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1); 349 err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1);
570 if (err < 0) 350 if (err < 0)
571 return err; 351 return err;
572 352
573 i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6); 353 i2c_data = (0x3f & i2c_data) | (sd->hflip->val << 7) |
354 (sd->vflip->val << 6);
574 355
575 err = m5602_write_sensor(sd, PO1030_CONTROL2, 356 err = m5602_write_sensor(sd, PO1030_CONTROL2,
576 &i2c_data, 1); 357 &i2c_data, 1);
@@ -578,81 +359,41 @@ static int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
578 return err; 359 return err;
579} 360}
580 361
581static int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
582{
583 struct sd *sd = (struct sd *) gspca_dev;
584 s32 *sensor_settings = sd->sensor_priv;
585
586 *val = sensor_settings[RED_BALANCE_IDX];
587 PDEBUG(D_V4L2, "Read red gain %d", *val);
588 return 0;
589}
590
591static int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) 362static int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
592{ 363{
593 struct sd *sd = (struct sd *) gspca_dev; 364 struct sd *sd = (struct sd *) gspca_dev;
594 s32 *sensor_settings = sd->sensor_priv;
595 u8 i2c_data; 365 u8 i2c_data;
596 int err; 366 int err;
597 367
598 sensor_settings[RED_BALANCE_IDX] = val;
599
600 i2c_data = val & 0xff; 368 i2c_data = val & 0xff;
601 PDEBUG(D_V4L2, "Set red gain to %d", i2c_data); 369 PDEBUG(D_CONF, "Set red gain to %d", i2c_data);
602 err = m5602_write_sensor(sd, PO1030_RED_GAIN, 370 err = m5602_write_sensor(sd, PO1030_RED_GAIN,
603 &i2c_data, 1); 371 &i2c_data, 1);
604 return err; 372 return err;
605} 373}
606 374
607static int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
608{
609 struct sd *sd = (struct sd *) gspca_dev;
610 s32 *sensor_settings = sd->sensor_priv;
611
612 *val = sensor_settings[BLUE_BALANCE_IDX];
613 PDEBUG(D_V4L2, "Read blue gain %d", *val);
614
615 return 0;
616}
617
618static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) 375static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
619{ 376{
620 struct sd *sd = (struct sd *) gspca_dev; 377 struct sd *sd = (struct sd *) gspca_dev;
621 s32 *sensor_settings = sd->sensor_priv;
622 u8 i2c_data; 378 u8 i2c_data;
623 int err; 379 int err;
624 380
625 sensor_settings[BLUE_BALANCE_IDX] = val;
626
627 i2c_data = val & 0xff; 381 i2c_data = val & 0xff;
628 PDEBUG(D_V4L2, "Set blue gain to %d", i2c_data); 382 PDEBUG(D_CONF, "Set blue gain to %d", i2c_data);
629 err = m5602_write_sensor(sd, PO1030_BLUE_GAIN, 383 err = m5602_write_sensor(sd, PO1030_BLUE_GAIN,
630 &i2c_data, 1); 384 &i2c_data, 1);
631 385
632 return err; 386 return err;
633} 387}
634 388
635static int po1030_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val)
636{
637 struct sd *sd = (struct sd *) gspca_dev;
638 s32 *sensor_settings = sd->sensor_priv;
639
640 *val = sensor_settings[GREEN_BALANCE_IDX];
641 PDEBUG(D_V4L2, "Read green gain %d", *val);
642
643 return 0;
644}
645
646static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val) 389static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val)
647{ 390{
648 struct sd *sd = (struct sd *) gspca_dev; 391 struct sd *sd = (struct sd *) gspca_dev;
649 s32 *sensor_settings = sd->sensor_priv;
650 u8 i2c_data; 392 u8 i2c_data;
651 int err; 393 int err;
652 394
653 sensor_settings[GREEN_BALANCE_IDX] = val;
654 i2c_data = val & 0xff; 395 i2c_data = val & 0xff;
655 PDEBUG(D_V4L2, "Set green gain to %d", i2c_data); 396 PDEBUG(D_CONF, "Set green gain to %d", i2c_data);
656 397
657 err = m5602_write_sensor(sd, PO1030_GREEN_1_GAIN, 398 err = m5602_write_sensor(sd, PO1030_GREEN_1_GAIN,
658 &i2c_data, 1); 399 &i2c_data, 1);
@@ -663,63 +404,36 @@ static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val)
663 &i2c_data, 1); 404 &i2c_data, 1);
664} 405}
665 406
666static int po1030_get_auto_white_balance(struct gspca_dev *gspca_dev,
667 __s32 *val)
668{
669 struct sd *sd = (struct sd *) gspca_dev;
670 s32 *sensor_settings = sd->sensor_priv;
671
672 *val = sensor_settings[AUTO_WHITE_BALANCE_IDX];
673 PDEBUG(D_V4L2, "Auto white balancing is %d", *val);
674
675 return 0;
676}
677
678static int po1030_set_auto_white_balance(struct gspca_dev *gspca_dev, 407static int po1030_set_auto_white_balance(struct gspca_dev *gspca_dev,
679 __s32 val) 408 __s32 val)
680{ 409{
681 struct sd *sd = (struct sd *) gspca_dev; 410 struct sd *sd = (struct sd *) gspca_dev;
682 s32 *sensor_settings = sd->sensor_priv;
683 u8 i2c_data; 411 u8 i2c_data;
684 int err; 412 int err;
685 413
686 sensor_settings[AUTO_WHITE_BALANCE_IDX] = val;
687
688 err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); 414 err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1);
689 if (err < 0) 415 if (err < 0)
690 return err; 416 return err;
691 417
692 PDEBUG(D_V4L2, "Set auto white balance to %d", val); 418 PDEBUG(D_CONF, "Set auto white balance to %d", val);
693 i2c_data = (i2c_data & 0xfe) | (val & 0x01); 419 i2c_data = (i2c_data & 0xfe) | (val & 0x01);
694 err = m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); 420 err = m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1);
695 return err; 421 return err;
696} 422}
697 423
698static int po1030_get_auto_exposure(struct gspca_dev *gspca_dev,
699 __s32 *val)
700{
701 struct sd *sd = (struct sd *) gspca_dev;
702 s32 *sensor_settings = sd->sensor_priv;
703
704 *val = sensor_settings[AUTO_EXPOSURE_IDX];
705 PDEBUG(D_V4L2, "Auto exposure is %d", *val);
706 return 0;
707}
708
709static int po1030_set_auto_exposure(struct gspca_dev *gspca_dev, 424static int po1030_set_auto_exposure(struct gspca_dev *gspca_dev,
710 __s32 val) 425 __s32 val)
711{ 426{
712 struct sd *sd = (struct sd *) gspca_dev; 427 struct sd *sd = (struct sd *) gspca_dev;
713 s32 *sensor_settings = sd->sensor_priv;
714 u8 i2c_data; 428 u8 i2c_data;
715 int err; 429 int err;
716 430
717 sensor_settings[AUTO_EXPOSURE_IDX] = val;
718 err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); 431 err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1);
719 if (err < 0) 432 if (err < 0)
720 return err; 433 return err;
721 434
722 PDEBUG(D_V4L2, "Set auto exposure to %d", val); 435 PDEBUG(D_CONF, "Set auto exposure to %d", val);
436 val = (val == V4L2_EXPOSURE_AUTO);
723 i2c_data = (i2c_data & 0xfd) | ((val & 0x01) << 1); 437 i2c_data = (i2c_data & 0xfd) | ((val & 0x01) << 1);
724 return m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); 438 return m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1);
725} 439}
@@ -727,7 +441,48 @@ static int po1030_set_auto_exposure(struct gspca_dev *gspca_dev,
727void po1030_disconnect(struct sd *sd) 441void po1030_disconnect(struct sd *sd)
728{ 442{
729 sd->sensor = NULL; 443 sd->sensor = NULL;
730 kfree(sd->sensor_priv); 444}
445
446static int po1030_s_ctrl(struct v4l2_ctrl *ctrl)
447{
448 struct gspca_dev *gspca_dev =
449 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
450 struct sd *sd = (struct sd *) gspca_dev;
451 int err;
452
453 if (!gspca_dev->streaming)
454 return 0;
455
456 switch (ctrl->id) {
457 case V4L2_CID_AUTO_WHITE_BALANCE:
458 err = po1030_set_auto_white_balance(gspca_dev, ctrl->val);
459 if (err || ctrl->val)
460 return err;
461 err = po1030_set_green_balance(gspca_dev, sd->green_bal->val);
462 if (err)
463 return err;
464 err = po1030_set_red_balance(gspca_dev, sd->red_bal->val);
465 if (err)
466 return err;
467 err = po1030_set_blue_balance(gspca_dev, sd->blue_bal->val);
468 break;
469 case V4L2_CID_EXPOSURE_AUTO:
470 err = po1030_set_auto_exposure(gspca_dev, ctrl->val);
471 if (err || ctrl->val == V4L2_EXPOSURE_AUTO)
472 return err;
473 err = po1030_set_exposure(gspca_dev, sd->expo->val);
474 break;
475 case V4L2_CID_GAIN:
476 err = po1030_set_gain(gspca_dev, ctrl->val);
477 break;
478 case V4L2_CID_HFLIP:
479 err = po1030_set_hvflip(gspca_dev);
480 break;
481 default:
482 return -EINVAL;
483 }
484
485 return err;
731} 486}
732 487
733static void po1030_dump_registers(struct sd *sd) 488static void po1030_dump_registers(struct sd *sd)
diff --git a/drivers/media/usb/gspca/m5602/m5602_po1030.h b/drivers/media/usb/gspca/m5602/m5602_po1030.h
index 81a2bcb88fe3..a6ab76149bd0 100644
--- a/drivers/media/usb/gspca/m5602/m5602_po1030.h
+++ b/drivers/media/usb/gspca/m5602/m5602_po1030.h
@@ -151,6 +151,7 @@ extern bool dump_sensor;
151 151
152int po1030_probe(struct sd *sd); 152int po1030_probe(struct sd *sd);
153int po1030_init(struct sd *sd); 153int po1030_init(struct sd *sd);
154int po1030_init_controls(struct sd *sd);
154int po1030_start(struct sd *sd); 155int po1030_start(struct sd *sd);
155void po1030_disconnect(struct sd *sd); 156void po1030_disconnect(struct sd *sd);
156 157
@@ -162,6 +163,7 @@ static const struct m5602_sensor po1030 = {
162 163
163 .probe = po1030_probe, 164 .probe = po1030_probe,
164 .init = po1030_init, 165 .init = po1030_init,
166 .init_controls = po1030_init_controls,
165 .start = po1030_start, 167 .start = po1030_start,
166 .disconnect = po1030_disconnect, 168 .disconnect = po1030_disconnect,
167}; 169};
diff --git a/drivers/media/usb/gspca/m5602/m5602_s5k4aa.c b/drivers/media/usb/gspca/m5602/m5602_s5k4aa.c
index c8e1572eb502..7d12599458e2 100644
--- a/drivers/media/usb/gspca/m5602/m5602_s5k4aa.c
+++ b/drivers/media/usb/gspca/m5602/m5602_s5k4aa.c
@@ -20,18 +20,12 @@
20 20
21#include "m5602_s5k4aa.h" 21#include "m5602_s5k4aa.h"
22 22
23static int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val); 23static int s5k4aa_s_ctrl(struct v4l2_ctrl *ctrl);
24static int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val); 24static void s5k4aa_dump_registers(struct sd *sd);
25static int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); 25
26static int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val); 26static const struct v4l2_ctrl_ops s5k4aa_ctrl_ops = {
27static int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val); 27 .s_ctrl = s5k4aa_s_ctrl,
28static int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val); 28};
29static int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
30static int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val);
31static int s5k4aa_get_noise(struct gspca_dev *gspca_dev, __s32 *val);
32static int s5k4aa_set_noise(struct gspca_dev *gspca_dev, __s32 val);
33static int s5k4aa_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
34static int s5k4aa_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
35 29
36static 30static
37 const 31 const
@@ -147,104 +141,12 @@ static struct v4l2_pix_format s5k4aa_modes[] = {
147 } 141 }
148}; 142};
149 143
150static const struct ctrl s5k4aa_ctrls[] = {
151#define VFLIP_IDX 0
152 {
153 {
154 .id = V4L2_CID_VFLIP,
155 .type = V4L2_CTRL_TYPE_BOOLEAN,
156 .name = "vertical flip",
157 .minimum = 0,
158 .maximum = 1,
159 .step = 1,
160 .default_value = 0
161 },
162 .set = s5k4aa_set_vflip,
163 .get = s5k4aa_get_vflip
164 },
165#define HFLIP_IDX 1
166 {
167 {
168 .id = V4L2_CID_HFLIP,
169 .type = V4L2_CTRL_TYPE_BOOLEAN,
170 .name = "horizontal flip",
171 .minimum = 0,
172 .maximum = 1,
173 .step = 1,
174 .default_value = 0
175 },
176 .set = s5k4aa_set_hflip,
177 .get = s5k4aa_get_hflip
178 },
179#define GAIN_IDX 2
180 {
181 {
182 .id = V4L2_CID_GAIN,
183 .type = V4L2_CTRL_TYPE_INTEGER,
184 .name = "Gain",
185 .minimum = 0,
186 .maximum = 127,
187 .step = 1,
188 .default_value = S5K4AA_DEFAULT_GAIN,
189 .flags = V4L2_CTRL_FLAG_SLIDER
190 },
191 .set = s5k4aa_set_gain,
192 .get = s5k4aa_get_gain
193 },
194#define EXPOSURE_IDX 3
195 {
196 {
197 .id = V4L2_CID_EXPOSURE,
198 .type = V4L2_CTRL_TYPE_INTEGER,
199 .name = "Exposure",
200 .minimum = 13,
201 .maximum = 0xfff,
202 .step = 1,
203 .default_value = 0x100,
204 .flags = V4L2_CTRL_FLAG_SLIDER
205 },
206 .set = s5k4aa_set_exposure,
207 .get = s5k4aa_get_exposure
208 },
209#define NOISE_SUPP_IDX 4
210 {
211 {
212 .id = V4L2_CID_PRIVATE_BASE,
213 .type = V4L2_CTRL_TYPE_BOOLEAN,
214 .name = "Noise suppression (smoothing)",
215 .minimum = 0,
216 .maximum = 1,
217 .step = 1,
218 .default_value = 1,
219 },
220 .set = s5k4aa_set_noise,
221 .get = s5k4aa_get_noise
222 },
223#define BRIGHTNESS_IDX 5
224 {
225 {
226 .id = V4L2_CID_BRIGHTNESS,
227 .type = V4L2_CTRL_TYPE_INTEGER,
228 .name = "Brightness",
229 .minimum = 0,
230 .maximum = 0x1f,
231 .step = 1,
232 .default_value = S5K4AA_DEFAULT_BRIGHTNESS,
233 },
234 .set = s5k4aa_set_brightness,
235 .get = s5k4aa_get_brightness
236 },
237
238};
239
240static void s5k4aa_dump_registers(struct sd *sd);
241
242int s5k4aa_probe(struct sd *sd) 144int s5k4aa_probe(struct sd *sd)
243{ 145{
244 u8 prod_id[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 146 u8 prod_id[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
245 const u8 expected_prod_id[6] = {0x00, 0x10, 0x00, 0x4b, 0x33, 0x75}; 147 const u8 expected_prod_id[6] = {0x00, 0x10, 0x00, 0x4b, 0x33, 0x75};
148 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
246 int i, err = 0; 149 int i, err = 0;
247 s32 *sensor_settings;
248 150
249 if (force_sensor) { 151 if (force_sensor) {
250 if (force_sensor == S5K4AA_SENSOR) { 152 if (force_sensor == S5K4AA_SENSOR) {
@@ -303,19 +205,8 @@ int s5k4aa_probe(struct sd *sd)
303 pr_info("Detected a s5k4aa sensor\n"); 205 pr_info("Detected a s5k4aa sensor\n");
304 206
305sensor_found: 207sensor_found:
306 sensor_settings = kmalloc(
307 ARRAY_SIZE(s5k4aa_ctrls) * sizeof(s32), GFP_KERNEL);
308 if (!sensor_settings)
309 return -ENOMEM;
310
311 sd->gspca_dev.cam.cam_mode = s5k4aa_modes; 208 sd->gspca_dev.cam.cam_mode = s5k4aa_modes;
312 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k4aa_modes); 209 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k4aa_modes);
313 sd->desc->ctrls = s5k4aa_ctrls;
314 sd->desc->nctrls = ARRAY_SIZE(s5k4aa_ctrls);
315
316 for (i = 0; i < ARRAY_SIZE(s5k4aa_ctrls); i++)
317 sensor_settings[i] = s5k4aa_ctrls[i].qctrl.default_value;
318 sd->sensor_priv = sensor_settings;
319 210
320 return 0; 211 return 0;
321} 212}
@@ -325,11 +216,11 @@ int s5k4aa_start(struct sd *sd)
325 int i, err = 0; 216 int i, err = 0;
326 u8 data[2]; 217 u8 data[2];
327 struct cam *cam = &sd->gspca_dev.cam; 218 struct cam *cam = &sd->gspca_dev.cam;
328 s32 *sensor_settings = sd->sensor_priv; 219 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
329 220
330 switch (cam->cam_mode[sd->gspca_dev.curr_mode].width) { 221 switch (cam->cam_mode[sd->gspca_dev.curr_mode].width) {
331 case 1280: 222 case 1280:
332 PDEBUG(D_V4L2, "Configuring camera for SXGA mode"); 223 PDEBUG(D_CONF, "Configuring camera for SXGA mode");
333 224
334 for (i = 0; i < ARRAY_SIZE(SXGA_s5k4aa); i++) { 225 for (i = 0; i < ARRAY_SIZE(SXGA_s5k4aa); i++) {
335 switch (SXGA_s5k4aa[i][0]) { 226 switch (SXGA_s5k4aa[i][0]) {
@@ -359,13 +250,10 @@ int s5k4aa_start(struct sd *sd)
359 return -EINVAL; 250 return -EINVAL;
360 } 251 }
361 } 252 }
362 err = s5k4aa_set_noise(&sd->gspca_dev, 0);
363 if (err < 0)
364 return err;
365 break; 253 break;
366 254
367 case 640: 255 case 640:
368 PDEBUG(D_V4L2, "Configuring camera for VGA mode"); 256 PDEBUG(D_CONF, "Configuring camera for VGA mode");
369 257
370 for (i = 0; i < ARRAY_SIZE(VGA_s5k4aa); i++) { 258 for (i = 0; i < ARRAY_SIZE(VGA_s5k4aa); i++) {
371 switch (VGA_s5k4aa[i][0]) { 259 switch (VGA_s5k4aa[i][0]) {
@@ -395,37 +283,12 @@ int s5k4aa_start(struct sd *sd)
395 return -EINVAL; 283 return -EINVAL;
396 } 284 }
397 } 285 }
398 err = s5k4aa_set_noise(&sd->gspca_dev, 1);
399 if (err < 0)
400 return err;
401 break; 286 break;
402 } 287 }
403 if (err < 0) 288 if (err < 0)
404 return err; 289 return err;
405 290
406 err = s5k4aa_set_exposure(&sd->gspca_dev, 291 return 0;
407 sensor_settings[EXPOSURE_IDX]);
408 if (err < 0)
409 return err;
410
411 err = s5k4aa_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]);
412 if (err < 0)
413 return err;
414
415 err = s5k4aa_set_brightness(&sd->gspca_dev,
416 sensor_settings[BRIGHTNESS_IDX]);
417 if (err < 0)
418 return err;
419
420 err = s5k4aa_set_noise(&sd->gspca_dev, sensor_settings[NOISE_SUPP_IDX]);
421 if (err < 0)
422 return err;
423
424 err = s5k4aa_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]);
425 if (err < 0)
426 return err;
427
428 return s5k4aa_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]);
429} 292}
430 293
431int s5k4aa_init(struct sd *sd) 294int s5k4aa_init(struct sd *sd)
@@ -466,13 +329,36 @@ int s5k4aa_init(struct sd *sd)
466 return err; 329 return err;
467} 330}
468 331
469static int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) 332int s5k4aa_init_controls(struct sd *sd)
470{ 333{
471 struct sd *sd = (struct sd *) gspca_dev; 334 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
472 s32 *sensor_settings = sd->sensor_priv; 335
336 sd->gspca_dev.vdev.ctrl_handler = hdl;
337 v4l2_ctrl_handler_init(hdl, 6);
473 338
474 *val = sensor_settings[EXPOSURE_IDX]; 339 v4l2_ctrl_new_std(hdl, &s5k4aa_ctrl_ops, V4L2_CID_BRIGHTNESS,
475 PDEBUG(D_V4L2, "Read exposure %d", *val); 340 0, 0x1f, 1, S5K4AA_DEFAULT_BRIGHTNESS);
341
342 v4l2_ctrl_new_std(hdl, &s5k4aa_ctrl_ops, V4L2_CID_EXPOSURE,
343 13, 0xfff, 1, 0x100);
344
345 v4l2_ctrl_new_std(hdl, &s5k4aa_ctrl_ops, V4L2_CID_GAIN,
346 0, 127, 1, S5K4AA_DEFAULT_GAIN);
347
348 v4l2_ctrl_new_std(hdl, &s5k4aa_ctrl_ops, V4L2_CID_SHARPNESS,
349 0, 1, 1, 1);
350
351 sd->hflip = v4l2_ctrl_new_std(hdl, &s5k4aa_ctrl_ops, V4L2_CID_HFLIP,
352 0, 1, 1, 0);
353 sd->vflip = v4l2_ctrl_new_std(hdl, &s5k4aa_ctrl_ops, V4L2_CID_VFLIP,
354 0, 1, 1, 0);
355
356 if (hdl->error) {
357 pr_err("Could not initialize controls\n");
358 return hdl->error;
359 }
360
361 v4l2_ctrl_cluster(2, &sd->hflip);
476 362
477 return 0; 363 return 0;
478} 364}
@@ -480,12 +366,10 @@ static int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
480static int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val) 366static int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
481{ 367{
482 struct sd *sd = (struct sd *) gspca_dev; 368 struct sd *sd = (struct sd *) gspca_dev;
483 s32 *sensor_settings = sd->sensor_priv;
484 u8 data = S5K4AA_PAGE_MAP_2; 369 u8 data = S5K4AA_PAGE_MAP_2;
485 int err; 370 int err;
486 371
487 sensor_settings[EXPOSURE_IDX] = val; 372 PDEBUG(D_CONF, "Set exposure to %d", val);
488 PDEBUG(D_V4L2, "Set exposure to %d", val);
489 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 373 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
490 if (err < 0) 374 if (err < 0)
491 return err; 375 return err;
@@ -499,27 +383,15 @@ static int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
499 return err; 383 return err;
500} 384}
501 385
502static int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) 386static int s5k4aa_set_hvflip(struct gspca_dev *gspca_dev)
503{ 387{
504 struct sd *sd = (struct sd *) gspca_dev; 388 struct sd *sd = (struct sd *) gspca_dev;
505 s32 *sensor_settings = sd->sensor_priv;
506
507 *val = sensor_settings[VFLIP_IDX];
508 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
509
510 return 0;
511}
512
513static int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
514{
515 struct sd *sd = (struct sd *) gspca_dev;
516 s32 *sensor_settings = sd->sensor_priv;
517 u8 data = S5K4AA_PAGE_MAP_2; 389 u8 data = S5K4AA_PAGE_MAP_2;
518 int err; 390 int err;
391 int hflip = sd->hflip->val;
392 int vflip = sd->vflip->val;
519 393
520 sensor_settings[VFLIP_IDX] = val; 394 PDEBUG(D_CONF, "Set hvflip %d %d", hflip, vflip);
521
522 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
523 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 395 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
524 if (err < 0) 396 if (err < 0)
525 return err; 397 return err;
@@ -528,93 +400,48 @@ static int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
528 if (err < 0) 400 if (err < 0)
529 return err; 401 return err;
530 402
531 if (dmi_check_system(s5k4aa_vflip_dmi_table)) 403 if (dmi_check_system(s5k4aa_vflip_dmi_table)) {
532 val = !val; 404 hflip = !hflip;
405 vflip = !vflip;
406 }
533 407
534 data = ((data & ~S5K4AA_RM_V_FLIP) | ((val & 0x01) << 7)); 408 data = (data & 0x7f) | (vflip << 7) | (hflip << 6);
535 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); 409 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
536 if (err < 0) 410 if (err < 0)
537 return err; 411 return err;
538 412
539 err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); 413 err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
540 if (err < 0) 414 if (err < 0)
541 return err; 415 return err;
542 if (val) 416 if (hflip)
543 data &= 0xfe; 417 data &= 0xfe;
544 else 418 else
545 data |= 0x01; 419 data |= 0x01;
546 err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); 420 err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
547 return err;
548}
549
550static int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
551{
552 struct sd *sd = (struct sd *) gspca_dev;
553 s32 *sensor_settings = sd->sensor_priv;
554
555 *val = sensor_settings[HFLIP_IDX];
556 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
557
558 return 0;
559}
560
561static int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
562{
563 struct sd *sd = (struct sd *) gspca_dev;
564 s32 *sensor_settings = sd->sensor_priv;
565 u8 data = S5K4AA_PAGE_MAP_2;
566 int err;
567
568 sensor_settings[HFLIP_IDX] = val;
569
570 PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
571 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
572 if (err < 0)
573 return err;
574
575 err = m5602_read_sensor(sd, S5K4AA_READ_MODE, &data, 1);
576 if (err < 0)
577 return err;
578
579 if (dmi_check_system(s5k4aa_vflip_dmi_table))
580 val = !val;
581
582 data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6));
583 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
584 if (err < 0) 421 if (err < 0)
585 return err; 422 return err;
586 423
587 err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); 424 err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
588 if (err < 0) 425 if (err < 0)
589 return err; 426 return err;
590 if (val) 427 if (vflip)
591 data &= 0xfe; 428 data &= 0xfe;
592 else 429 else
593 data |= 0x01; 430 data |= 0x01;
594 err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); 431 err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
595 return err; 432 if (err < 0)
596} 433 return err;
597
598static int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
599{
600 struct sd *sd = (struct sd *) gspca_dev;
601 s32 *sensor_settings = sd->sensor_priv;
602 434
603 *val = sensor_settings[GAIN_IDX];
604 PDEBUG(D_V4L2, "Read gain %d", *val);
605 return 0; 435 return 0;
606} 436}
607 437
608static int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val) 438static int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val)
609{ 439{
610 struct sd *sd = (struct sd *) gspca_dev; 440 struct sd *sd = (struct sd *) gspca_dev;
611 s32 *sensor_settings = sd->sensor_priv;
612 u8 data = S5K4AA_PAGE_MAP_2; 441 u8 data = S5K4AA_PAGE_MAP_2;
613 int err; 442 int err;
614 443
615 sensor_settings[GAIN_IDX] = val; 444 PDEBUG(D_CONF, "Set gain to %d", val);
616
617 PDEBUG(D_V4L2, "Set gain to %d", val);
618 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 445 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
619 if (err < 0) 446 if (err < 0)
620 return err; 447 return err;
@@ -625,26 +452,13 @@ static int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val)
625 return err; 452 return err;
626} 453}
627 454
628static int s5k4aa_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
629{
630 struct sd *sd = (struct sd *) gspca_dev;
631 s32 *sensor_settings = sd->sensor_priv;
632
633 *val = sensor_settings[BRIGHTNESS_IDX];
634 PDEBUG(D_V4L2, "Read brightness %d", *val);
635 return 0;
636}
637
638static int s5k4aa_set_brightness(struct gspca_dev *gspca_dev, __s32 val) 455static int s5k4aa_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
639{ 456{
640 struct sd *sd = (struct sd *) gspca_dev; 457 struct sd *sd = (struct sd *) gspca_dev;
641 s32 *sensor_settings = sd->sensor_priv;
642 u8 data = S5K4AA_PAGE_MAP_2; 458 u8 data = S5K4AA_PAGE_MAP_2;
643 int err; 459 int err;
644 460
645 sensor_settings[BRIGHTNESS_IDX] = val; 461 PDEBUG(D_CONF, "Set brightness to %d", val);
646
647 PDEBUG(D_V4L2, "Set brightness to %d", val);
648 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 462 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
649 if (err < 0) 463 if (err < 0)
650 return err; 464 return err;
@@ -653,26 +467,13 @@ static int s5k4aa_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
653 return m5602_write_sensor(sd, S5K4AA_BRIGHTNESS, &data, 1); 467 return m5602_write_sensor(sd, S5K4AA_BRIGHTNESS, &data, 1);
654} 468}
655 469
656static int s5k4aa_get_noise(struct gspca_dev *gspca_dev, __s32 *val)
657{
658 struct sd *sd = (struct sd *) gspca_dev;
659 s32 *sensor_settings = sd->sensor_priv;
660
661 *val = sensor_settings[NOISE_SUPP_IDX];
662 PDEBUG(D_V4L2, "Read noise %d", *val);
663 return 0;
664}
665
666static int s5k4aa_set_noise(struct gspca_dev *gspca_dev, __s32 val) 470static int s5k4aa_set_noise(struct gspca_dev *gspca_dev, __s32 val)
667{ 471{
668 struct sd *sd = (struct sd *) gspca_dev; 472 struct sd *sd = (struct sd *) gspca_dev;
669 s32 *sensor_settings = sd->sensor_priv;
670 u8 data = S5K4AA_PAGE_MAP_2; 473 u8 data = S5K4AA_PAGE_MAP_2;
671 int err; 474 int err;
672 475
673 sensor_settings[NOISE_SUPP_IDX] = val; 476 PDEBUG(D_CONF, "Set noise to %d", val);
674
675 PDEBUG(D_V4L2, "Set noise to %d", val);
676 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 477 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
677 if (err < 0) 478 if (err < 0)
678 return err; 479 return err;
@@ -681,10 +482,41 @@ static int s5k4aa_set_noise(struct gspca_dev *gspca_dev, __s32 val)
681 return m5602_write_sensor(sd, S5K4AA_NOISE_SUPP, &data, 1); 482 return m5602_write_sensor(sd, S5K4AA_NOISE_SUPP, &data, 1);
682} 483}
683 484
485static int s5k4aa_s_ctrl(struct v4l2_ctrl *ctrl)
486{
487 struct gspca_dev *gspca_dev =
488 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
489 int err;
490
491 if (!gspca_dev->streaming)
492 return 0;
493
494 switch (ctrl->id) {
495 case V4L2_CID_BRIGHTNESS:
496 err = s5k4aa_set_brightness(gspca_dev, ctrl->val);
497 break;
498 case V4L2_CID_EXPOSURE:
499 err = s5k4aa_set_exposure(gspca_dev, ctrl->val);
500 break;
501 case V4L2_CID_GAIN:
502 err = s5k4aa_set_gain(gspca_dev, ctrl->val);
503 break;
504 case V4L2_CID_SHARPNESS:
505 err = s5k4aa_set_noise(gspca_dev, ctrl->val);
506 break;
507 case V4L2_CID_HFLIP:
508 err = s5k4aa_set_hvflip(gspca_dev);
509 break;
510 default:
511 return -EINVAL;
512 }
513
514 return err;
515}
516
684void s5k4aa_disconnect(struct sd *sd) 517void s5k4aa_disconnect(struct sd *sd)
685{ 518{
686 sd->sensor = NULL; 519 sd->sensor = NULL;
687 kfree(sd->sensor_priv);
688} 520}
689 521
690static void s5k4aa_dump_registers(struct sd *sd) 522static void s5k4aa_dump_registers(struct sd *sd)
diff --git a/drivers/media/usb/gspca/m5602/m5602_s5k4aa.h b/drivers/media/usb/gspca/m5602/m5602_s5k4aa.h
index 8e0035e731c7..9953e9766954 100644
--- a/drivers/media/usb/gspca/m5602/m5602_s5k4aa.h
+++ b/drivers/media/usb/gspca/m5602/m5602_s5k4aa.h
@@ -69,6 +69,7 @@ extern bool dump_sensor;
69 69
70int s5k4aa_probe(struct sd *sd); 70int s5k4aa_probe(struct sd *sd);
71int s5k4aa_init(struct sd *sd); 71int s5k4aa_init(struct sd *sd);
72int s5k4aa_init_controls(struct sd *sd);
72int s5k4aa_start(struct sd *sd); 73int s5k4aa_start(struct sd *sd);
73void s5k4aa_disconnect(struct sd *sd); 74void s5k4aa_disconnect(struct sd *sd);
74 75
@@ -79,6 +80,7 @@ static const struct m5602_sensor s5k4aa = {
79 80
80 .probe = s5k4aa_probe, 81 .probe = s5k4aa_probe,
81 .init = s5k4aa_init, 82 .init = s5k4aa_init,
83 .init_controls = s5k4aa_init_controls,
82 .start = s5k4aa_start, 84 .start = s5k4aa_start,
83 .disconnect = s5k4aa_disconnect, 85 .disconnect = s5k4aa_disconnect,
84}; 86};
diff --git a/drivers/media/usb/gspca/m5602/m5602_s5k83a.c b/drivers/media/usb/gspca/m5602/m5602_s5k83a.c
index 1de743a02b02..7cbc3a00bda8 100644
--- a/drivers/media/usb/gspca/m5602/m5602_s5k83a.c
+++ b/drivers/media/usb/gspca/m5602/m5602_s5k83a.c
@@ -21,16 +21,11 @@
21#include <linux/kthread.h> 21#include <linux/kthread.h>
22#include "m5602_s5k83a.h" 22#include "m5602_s5k83a.h"
23 23
24static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val); 24static int s5k83a_s_ctrl(struct v4l2_ctrl *ctrl);
25static int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val); 25
26static int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val); 26static const struct v4l2_ctrl_ops s5k83a_ctrl_ops = {
27static int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val); 27 .s_ctrl = s5k83a_s_ctrl,
28static int s5k83a_set_exposure(struct gspca_dev *gspca_dev, __s32 val); 28};
29static int s5k83a_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
30static int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
31static int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
32static int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
33static int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
34 29
35static struct v4l2_pix_format s5k83a_modes[] = { 30static struct v4l2_pix_format s5k83a_modes[] = {
36 { 31 {
@@ -46,83 +41,6 @@ static struct v4l2_pix_format s5k83a_modes[] = {
46 } 41 }
47}; 42};
48 43
49static const struct ctrl s5k83a_ctrls[] = {
50#define GAIN_IDX 0
51 {
52 {
53 .id = V4L2_CID_GAIN,
54 .type = V4L2_CTRL_TYPE_INTEGER,
55 .name = "gain",
56 .minimum = 0x00,
57 .maximum = 0xff,
58 .step = 0x01,
59 .default_value = S5K83A_DEFAULT_GAIN,
60 .flags = V4L2_CTRL_FLAG_SLIDER
61 },
62 .set = s5k83a_set_gain,
63 .get = s5k83a_get_gain
64
65 },
66#define BRIGHTNESS_IDX 1
67 {
68 {
69 .id = V4L2_CID_BRIGHTNESS,
70 .type = V4L2_CTRL_TYPE_INTEGER,
71 .name = "brightness",
72 .minimum = 0x00,
73 .maximum = 0xff,
74 .step = 0x01,
75 .default_value = S5K83A_DEFAULT_BRIGHTNESS,
76 .flags = V4L2_CTRL_FLAG_SLIDER
77 },
78 .set = s5k83a_set_brightness,
79 .get = s5k83a_get_brightness,
80 },
81#define EXPOSURE_IDX 2
82 {
83 {
84 .id = V4L2_CID_EXPOSURE,
85 .type = V4L2_CTRL_TYPE_INTEGER,
86 .name = "exposure",
87 .minimum = 0x00,
88 .maximum = S5K83A_MAXIMUM_EXPOSURE,
89 .step = 0x01,
90 .default_value = S5K83A_DEFAULT_EXPOSURE,
91 .flags = V4L2_CTRL_FLAG_SLIDER
92 },
93 .set = s5k83a_set_exposure,
94 .get = s5k83a_get_exposure
95 },
96#define HFLIP_IDX 3
97 {
98 {
99 .id = V4L2_CID_HFLIP,
100 .type = V4L2_CTRL_TYPE_BOOLEAN,
101 .name = "horizontal flip",
102 .minimum = 0,
103 .maximum = 1,
104 .step = 1,
105 .default_value = 0
106 },
107 .set = s5k83a_set_hflip,
108 .get = s5k83a_get_hflip
109 },
110#define VFLIP_IDX 4
111 {
112 {
113 .id = V4L2_CID_VFLIP,
114 .type = V4L2_CTRL_TYPE_BOOLEAN,
115 .name = "vertical flip",
116 .minimum = 0,
117 .maximum = 1,
118 .step = 1,
119 .default_value = 0
120 },
121 .set = s5k83a_set_vflip,
122 .get = s5k83a_get_vflip
123 }
124};
125
126static void s5k83a_dump_registers(struct sd *sd); 44static void s5k83a_dump_registers(struct sd *sd);
127static int s5k83a_get_rotation(struct sd *sd, u8 *reg_data); 45static int s5k83a_get_rotation(struct sd *sd, u8 *reg_data);
128static int s5k83a_set_led_indication(struct sd *sd, u8 val); 46static int s5k83a_set_led_indication(struct sd *sd, u8 val);
@@ -131,9 +49,9 @@ static int s5k83a_set_flip_real(struct gspca_dev *gspca_dev,
131 49
132int s5k83a_probe(struct sd *sd) 50int s5k83a_probe(struct sd *sd)
133{ 51{
134 struct s5k83a_priv *sens_priv;
135 u8 prod_id = 0, ver_id = 0; 52 u8 prod_id = 0, ver_id = 0;
136 int i, err = 0; 53 int i, err = 0;
54 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
137 55
138 if (force_sensor) { 56 if (force_sensor) {
139 if (force_sensor == S5K83A_SENSOR) { 57 if (force_sensor == S5K83A_SENSOR) {
@@ -173,38 +91,18 @@ int s5k83a_probe(struct sd *sd)
173 pr_info("Detected a s5k83a sensor\n"); 91 pr_info("Detected a s5k83a sensor\n");
174 92
175sensor_found: 93sensor_found:
176 sens_priv = kmalloc(
177 sizeof(struct s5k83a_priv), GFP_KERNEL);
178 if (!sens_priv)
179 return -ENOMEM;
180
181 sens_priv->settings =
182 kmalloc(sizeof(s32)*ARRAY_SIZE(s5k83a_ctrls), GFP_KERNEL);
183 if (!sens_priv->settings) {
184 kfree(sens_priv);
185 return -ENOMEM;
186 }
187
188 sd->gspca_dev.cam.cam_mode = s5k83a_modes; 94 sd->gspca_dev.cam.cam_mode = s5k83a_modes;
189 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k83a_modes); 95 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k83a_modes);
190 sd->desc->ctrls = s5k83a_ctrls;
191 sd->desc->nctrls = ARRAY_SIZE(s5k83a_ctrls);
192 96
193 /* null the pointer! thread is't running now */ 97 /* null the pointer! thread is't running now */
194 sens_priv->rotation_thread = NULL; 98 sd->rotation_thread = NULL;
195
196 for (i = 0; i < ARRAY_SIZE(s5k83a_ctrls); i++)
197 sens_priv->settings[i] = s5k83a_ctrls[i].qctrl.default_value;
198 99
199 sd->sensor_priv = sens_priv;
200 return 0; 100 return 0;
201} 101}
202 102
203int s5k83a_init(struct sd *sd) 103int s5k83a_init(struct sd *sd)
204{ 104{
205 int i, err = 0; 105 int i, err = 0;
206 s32 *sensor_settings =
207 ((struct s5k83a_priv *) sd->sensor_priv)->settings;
208 106
209 for (i = 0; i < ARRAY_SIZE(init_s5k83a) && !err; i++) { 107 for (i = 0; i < ARRAY_SIZE(init_s5k83a) && !err; i++) {
210 u8 data[2] = {0x00, 0x00}; 108 u8 data[2] = {0x00, 0x00};
@@ -237,33 +135,44 @@ int s5k83a_init(struct sd *sd)
237 if (dump_sensor) 135 if (dump_sensor)
238 s5k83a_dump_registers(sd); 136 s5k83a_dump_registers(sd);
239 137
240 err = s5k83a_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); 138 return err;
241 if (err < 0) 139}
242 return err;
243 140
244 err = s5k83a_set_brightness(&sd->gspca_dev, 141int s5k83a_init_controls(struct sd *sd)
245 sensor_settings[BRIGHTNESS_IDX]); 142{
246 if (err < 0) 143 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
247 return err;
248 144
249 err = s5k83a_set_exposure(&sd->gspca_dev, 145 sd->gspca_dev.vdev.ctrl_handler = hdl;
250 sensor_settings[EXPOSURE_IDX]); 146 v4l2_ctrl_handler_init(hdl, 6);
251 if (err < 0)
252 return err;
253 147
254 err = s5k83a_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]); 148 v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_BRIGHTNESS,
255 if (err < 0) 149 0, 255, 1, S5K83A_DEFAULT_BRIGHTNESS);
256 return err;
257 150
258 err = s5k83a_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]); 151 v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_EXPOSURE,
152 0, S5K83A_MAXIMUM_EXPOSURE, 1,
153 S5K83A_DEFAULT_EXPOSURE);
259 154
260 return err; 155 v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_GAIN,
156 0, 255, 1, S5K83A_DEFAULT_GAIN);
157
158 sd->hflip = v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_HFLIP,
159 0, 1, 1, 0);
160 sd->vflip = v4l2_ctrl_new_std(hdl, &s5k83a_ctrl_ops, V4L2_CID_VFLIP,
161 0, 1, 1, 0);
162
163 if (hdl->error) {
164 pr_err("Could not initialize controls\n");
165 return hdl->error;
166 }
167
168 v4l2_ctrl_cluster(2, &sd->hflip);
169
170 return 0;
261} 171}
262 172
263static int rotation_thread_function(void *data) 173static int rotation_thread_function(void *data)
264{ 174{
265 struct sd *sd = (struct sd *) data; 175 struct sd *sd = (struct sd *) data;
266 struct s5k83a_priv *sens_priv = sd->sensor_priv;
267 u8 reg, previous_rotation = 0; 176 u8 reg, previous_rotation = 0;
268 __s32 vflip, hflip; 177 __s32 vflip, hflip;
269 178
@@ -277,8 +186,8 @@ static int rotation_thread_function(void *data)
277 previous_rotation = reg; 186 previous_rotation = reg;
278 pr_info("Camera was flipped\n"); 187 pr_info("Camera was flipped\n");
279 188
280 s5k83a_get_vflip((struct gspca_dev *) sd, &vflip); 189 hflip = sd->hflip->val;
281 s5k83a_get_hflip((struct gspca_dev *) sd, &hflip); 190 vflip = sd->vflip->val;
282 191
283 if (reg) { 192 if (reg) {
284 vflip = !vflip; 193 vflip = !vflip;
@@ -294,26 +203,25 @@ static int rotation_thread_function(void *data)
294 203
295 /* return to "front" flip */ 204 /* return to "front" flip */
296 if (previous_rotation) { 205 if (previous_rotation) {
297 s5k83a_get_vflip((struct gspca_dev *) sd, &vflip); 206 hflip = sd->hflip->val;
298 s5k83a_get_hflip((struct gspca_dev *) sd, &hflip); 207 vflip = sd->vflip->val;
299 s5k83a_set_flip_real((struct gspca_dev *) sd, vflip, hflip); 208 s5k83a_set_flip_real((struct gspca_dev *) sd, vflip, hflip);
300 } 209 }
301 210
302 sens_priv->rotation_thread = NULL; 211 sd->rotation_thread = NULL;
303 return 0; 212 return 0;
304} 213}
305 214
306int s5k83a_start(struct sd *sd) 215int s5k83a_start(struct sd *sd)
307{ 216{
308 int i, err = 0; 217 int i, err = 0;
309 struct s5k83a_priv *sens_priv = sd->sensor_priv;
310 218
311 /* Create another thread, polling the GPIO ports of the camera to check 219 /* Create another thread, polling the GPIO ports of the camera to check
312 if it got rotated. This is how the windows driver does it so we have 220 if it got rotated. This is how the windows driver does it so we have
313 to assume that there is no better way of accomplishing this */ 221 to assume that there is no better way of accomplishing this */
314 sens_priv->rotation_thread = kthread_create(rotation_thread_function, 222 sd->rotation_thread = kthread_create(rotation_thread_function,
315 sd, "rotation thread"); 223 sd, "rotation thread");
316 wake_up_process(sens_priv->rotation_thread); 224 wake_up_process(sd->rotation_thread);
317 225
318 /* Preinit the sensor */ 226 /* Preinit the sensor */
319 for (i = 0; i < ARRAY_SIZE(start_s5k83a) && !err; i++) { 227 for (i = 0; i < ARRAY_SIZE(start_s5k83a) && !err; i++) {
@@ -333,32 +241,17 @@ int s5k83a_start(struct sd *sd)
333 241
334int s5k83a_stop(struct sd *sd) 242int s5k83a_stop(struct sd *sd)
335{ 243{
336 struct s5k83a_priv *sens_priv = sd->sensor_priv; 244 if (sd->rotation_thread)
337 245 kthread_stop(sd->rotation_thread);
338 if (sens_priv->rotation_thread)
339 kthread_stop(sens_priv->rotation_thread);
340 246
341 return s5k83a_set_led_indication(sd, 0); 247 return s5k83a_set_led_indication(sd, 0);
342} 248}
343 249
344void s5k83a_disconnect(struct sd *sd) 250void s5k83a_disconnect(struct sd *sd)
345{ 251{
346 struct s5k83a_priv *sens_priv = sd->sensor_priv;
347
348 s5k83a_stop(sd); 252 s5k83a_stop(sd);
349 253
350 sd->sensor = NULL; 254 sd->sensor = NULL;
351 kfree(sens_priv->settings);
352 kfree(sens_priv);
353}
354
355static int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
356{
357 struct sd *sd = (struct sd *) gspca_dev;
358 struct s5k83a_priv *sens_priv = sd->sensor_priv;
359
360 *val = sens_priv->settings[GAIN_IDX];
361 return 0;
362} 255}
363 256
364static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val) 257static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val)
@@ -366,9 +259,6 @@ static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val)
366 int err; 259 int err;
367 u8 data[2]; 260 u8 data[2];
368 struct sd *sd = (struct sd *) gspca_dev; 261 struct sd *sd = (struct sd *) gspca_dev;
369 struct s5k83a_priv *sens_priv = sd->sensor_priv;
370
371 sens_priv->settings[GAIN_IDX] = val;
372 262
373 data[0] = 0x00; 263 data[0] = 0x00;
374 data[1] = 0x20; 264 data[1] = 0x20;
@@ -391,60 +281,29 @@ static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val)
391 return err; 281 return err;
392} 282}
393 283
394static int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
395{
396 struct sd *sd = (struct sd *) gspca_dev;
397 struct s5k83a_priv *sens_priv = sd->sensor_priv;
398
399 *val = sens_priv->settings[BRIGHTNESS_IDX];
400 return 0;
401}
402
403static int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) 284static int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
404{ 285{
405 int err; 286 int err;
406 u8 data[1]; 287 u8 data[1];
407 struct sd *sd = (struct sd *) gspca_dev; 288 struct sd *sd = (struct sd *) gspca_dev;
408 struct s5k83a_priv *sens_priv = sd->sensor_priv;
409 289
410 sens_priv->settings[BRIGHTNESS_IDX] = val;
411 data[0] = val; 290 data[0] = val;
412 err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 1); 291 err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 1);
413 return err; 292 return err;
414} 293}
415 294
416static int s5k83a_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
417{
418 struct sd *sd = (struct sd *) gspca_dev;
419 struct s5k83a_priv *sens_priv = sd->sensor_priv;
420
421 *val = sens_priv->settings[EXPOSURE_IDX];
422 return 0;
423}
424
425static int s5k83a_set_exposure(struct gspca_dev *gspca_dev, __s32 val) 295static int s5k83a_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
426{ 296{
427 int err; 297 int err;
428 u8 data[2]; 298 u8 data[2];
429 struct sd *sd = (struct sd *) gspca_dev; 299 struct sd *sd = (struct sd *) gspca_dev;
430 struct s5k83a_priv *sens_priv = sd->sensor_priv;
431 300
432 sens_priv->settings[EXPOSURE_IDX] = val;
433 data[0] = 0; 301 data[0] = 0;
434 data[1] = val; 302 data[1] = val;
435 err = m5602_write_sensor(sd, S5K83A_EXPOSURE, data, 2); 303 err = m5602_write_sensor(sd, S5K83A_EXPOSURE, data, 2);
436 return err; 304 return err;
437} 305}
438 306
439static int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
440{
441 struct sd *sd = (struct sd *) gspca_dev;
442 struct s5k83a_priv *sens_priv = sd->sensor_priv;
443
444 *val = sens_priv->settings[VFLIP_IDX];
445 return 0;
446}
447
448static int s5k83a_set_flip_real(struct gspca_dev *gspca_dev, 307static int s5k83a_set_flip_real(struct gspca_dev *gspca_dev,
449 __s32 vflip, __s32 hflip) 308 __s32 vflip, __s32 hflip)
450{ 309{
@@ -476,60 +335,52 @@ static int s5k83a_set_flip_real(struct gspca_dev *gspca_dev,
476 return err; 335 return err;
477} 336}
478 337
479static int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val) 338static int s5k83a_set_hvflip(struct gspca_dev *gspca_dev)
480{ 339{
481 int err; 340 int err;
482 u8 reg; 341 u8 reg;
483 __s32 hflip;
484 struct sd *sd = (struct sd *) gspca_dev; 342 struct sd *sd = (struct sd *) gspca_dev;
485 struct s5k83a_priv *sens_priv = sd->sensor_priv; 343 int hflip = sd->hflip->val;
486 344 int vflip = sd->vflip->val;
487 sens_priv->settings[VFLIP_IDX] = val;
488
489 s5k83a_get_hflip(gspca_dev, &hflip);
490 345
491 err = s5k83a_get_rotation(sd, &reg); 346 err = s5k83a_get_rotation(sd, &reg);
492 if (err < 0) 347 if (err < 0)
493 return err; 348 return err;
494 if (reg) { 349 if (reg) {
495 val = !val;
496 hflip = !hflip; 350 hflip = !hflip;
351 vflip = !vflip;
497 } 352 }
498 353
499 err = s5k83a_set_flip_real(gspca_dev, val, hflip); 354 err = s5k83a_set_flip_real(gspca_dev, vflip, hflip);
500 return err; 355 return err;
501} 356}
502 357
503static int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) 358static int s5k83a_s_ctrl(struct v4l2_ctrl *ctrl)
504{
505 struct sd *sd = (struct sd *) gspca_dev;
506 struct s5k83a_priv *sens_priv = sd->sensor_priv;
507
508 *val = sens_priv->settings[HFLIP_IDX];
509 return 0;
510}
511
512static int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
513{ 359{
360 struct gspca_dev *gspca_dev =
361 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
514 int err; 362 int err;
515 u8 reg;
516 __s32 vflip;
517 struct sd *sd = (struct sd *) gspca_dev;
518 struct s5k83a_priv *sens_priv = sd->sensor_priv;
519
520 sens_priv->settings[HFLIP_IDX] = val;
521 363
522 s5k83a_get_vflip(gspca_dev, &vflip); 364 if (!gspca_dev->streaming)
523 365 return 0;
524 err = s5k83a_get_rotation(sd, &reg); 366
525 if (err < 0) 367 switch (ctrl->id) {
526 return err; 368 case V4L2_CID_BRIGHTNESS:
527 if (reg) { 369 err = s5k83a_set_brightness(gspca_dev, ctrl->val);
528 val = !val; 370 break;
529 vflip = !vflip; 371 case V4L2_CID_EXPOSURE:
372 err = s5k83a_set_exposure(gspca_dev, ctrl->val);
373 break;
374 case V4L2_CID_GAIN:
375 err = s5k83a_set_gain(gspca_dev, ctrl->val);
376 break;
377 case V4L2_CID_HFLIP:
378 err = s5k83a_set_hvflip(gspca_dev);
379 break;
380 default:
381 return -EINVAL;
530 } 382 }
531 383
532 err = s5k83a_set_flip_real(gspca_dev, vflip, val);
533 return err; 384 return err;
534} 385}
535 386
diff --git a/drivers/media/usb/gspca/m5602/m5602_s5k83a.h b/drivers/media/usb/gspca/m5602/m5602_s5k83a.h
index 79952247b534..d61b918228df 100644
--- a/drivers/media/usb/gspca/m5602/m5602_s5k83a.h
+++ b/drivers/media/usb/gspca/m5602/m5602_s5k83a.h
@@ -45,6 +45,7 @@ extern bool dump_sensor;
45 45
46int s5k83a_probe(struct sd *sd); 46int s5k83a_probe(struct sd *sd);
47int s5k83a_init(struct sd *sd); 47int s5k83a_init(struct sd *sd);
48int s5k83a_init_controls(struct sd *sd);
48int s5k83a_start(struct sd *sd); 49int s5k83a_start(struct sd *sd);
49int s5k83a_stop(struct sd *sd); 50int s5k83a_stop(struct sd *sd);
50void s5k83a_disconnect(struct sd *sd); 51void s5k83a_disconnect(struct sd *sd);
@@ -53,6 +54,7 @@ static const struct m5602_sensor s5k83a = {
53 .name = "S5K83A", 54 .name = "S5K83A",
54 .probe = s5k83a_probe, 55 .probe = s5k83a_probe,
55 .init = s5k83a_init, 56 .init = s5k83a_init,
57 .init_controls = s5k83a_init_controls,
56 .start = s5k83a_start, 58 .start = s5k83a_start,
57 .stop = s5k83a_stop, 59 .stop = s5k83a_stop,
58 .disconnect = s5k83a_disconnect, 60 .disconnect = s5k83a_disconnect,
@@ -60,13 +62,6 @@ static const struct m5602_sensor s5k83a = {
60 .i2c_regW = 2, 62 .i2c_regW = 2,
61}; 63};
62 64
63struct s5k83a_priv {
64 /* We use another thread periodically
65 probing the orientation of the camera */
66 struct task_struct *rotation_thread;
67 s32 *settings;
68};
69
70static const unsigned char preinit_s5k83a[][4] = { 65static const unsigned char preinit_s5k83a[][4] = {
71 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00}, 66 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
72 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00}, 67 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
diff --git a/drivers/media/usb/gspca/m5602/m5602_sensor.h b/drivers/media/usb/gspca/m5602/m5602_sensor.h
index edff4f1f586f..48341b4d607b 100644
--- a/drivers/media/usb/gspca/m5602/m5602_sensor.h
+++ b/drivers/media/usb/gspca/m5602/m5602_sensor.h
@@ -57,6 +57,9 @@ struct m5602_sensor {
57 /* Performs a initialization sequence */ 57 /* Performs a initialization sequence */
58 int (*init)(struct sd *sd); 58 int (*init)(struct sd *sd);
59 59
60 /* Controls initialization, maybe NULL */
61 int (*init_controls)(struct sd *sd);
62
60 /* Executed when the camera starts to send data */ 63 /* Executed when the camera starts to send data */
61 int (*start)(struct sd *sd); 64 int (*start)(struct sd *sd);
62 65
diff --git a/drivers/media/usb/gspca/mr97310a.c b/drivers/media/usb/gspca/mr97310a.c
index 8f4714df5990..68bb2f359666 100644
--- a/drivers/media/usb/gspca/mr97310a.c
+++ b/drivers/media/usb/gspca/mr97310a.c
@@ -289,7 +289,7 @@ static int zero_the_pointer(struct gspca_dev *gspca_dev)
289 return err_code; 289 return err_code;
290 } 290 }
291 if (status != 0x0a) 291 if (status != 0x0a)
292 PDEBUG(D_ERR, "status is %02x", status); 292 PERR("status is %02x", status);
293 293
294 tries = 0; 294 tries = 0;
295 while (tries < 4) { 295 while (tries < 4) {
@@ -330,7 +330,7 @@ static void stream_stop(struct gspca_dev *gspca_dev)
330 gspca_dev->usb_buf[0] = 0x01; 330 gspca_dev->usb_buf[0] = 0x01;
331 gspca_dev->usb_buf[1] = 0x00; 331 gspca_dev->usb_buf[1] = 0x00;
332 if (mr_write(gspca_dev, 2) < 0) 332 if (mr_write(gspca_dev, 2) < 0)
333 PDEBUG(D_ERR, "Stream Stop failed"); 333 PERR("Stream Stop failed");
334} 334}
335 335
336static void lcd_stop(struct gspca_dev *gspca_dev) 336static void lcd_stop(struct gspca_dev *gspca_dev)
@@ -338,7 +338,7 @@ static void lcd_stop(struct gspca_dev *gspca_dev)
338 gspca_dev->usb_buf[0] = 0x19; 338 gspca_dev->usb_buf[0] = 0x19;
339 gspca_dev->usb_buf[1] = 0x54; 339 gspca_dev->usb_buf[1] = 0x54;
340 if (mr_write(gspca_dev, 2) < 0) 340 if (mr_write(gspca_dev, 2) < 0)
341 PDEBUG(D_ERR, "LCD Stop failed"); 341 PERR("LCD Stop failed");
342} 342}
343 343
344static int isoc_enable(struct gspca_dev *gspca_dev) 344static int isoc_enable(struct gspca_dev *gspca_dev)
@@ -1026,7 +1026,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1026 struct sd *sd = (struct sd *) gspca_dev; 1026 struct sd *sd = (struct sd *) gspca_dev;
1027 unsigned char *sof; 1027 unsigned char *sof;
1028 1028
1029 sof = pac_find_sof(&sd->sof_read, data, len); 1029 sof = pac_find_sof(gspca_dev, &sd->sof_read, data, len);
1030 if (sof) { 1030 if (sof) {
1031 int n; 1031 int n;
1032 1032
diff --git a/drivers/media/usb/gspca/ov519.c b/drivers/media/usb/gspca/ov519.c
index 9ad19a7ef81b..a3958ee86816 100644
--- a/drivers/media/usb/gspca/ov519.c
+++ b/drivers/media/usb/gspca/ov519.c
@@ -2034,6 +2034,7 @@ static unsigned char ov7670_abs_to_sm(unsigned char v)
2034/* Write a OV519 register */ 2034/* Write a OV519 register */
2035static void reg_w(struct sd *sd, u16 index, u16 value) 2035static void reg_w(struct sd *sd, u16 index, u16 value)
2036{ 2036{
2037 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2037 int ret, req = 0; 2038 int ret, req = 0;
2038 2039
2039 if (sd->gspca_dev.usb_err < 0) 2040 if (sd->gspca_dev.usb_err < 0)
@@ -2071,7 +2072,7 @@ static void reg_w(struct sd *sd, u16 index, u16 value)
2071 sd->gspca_dev.usb_buf, 1, 500); 2072 sd->gspca_dev.usb_buf, 1, 500);
2072leave: 2073leave:
2073 if (ret < 0) { 2074 if (ret < 0) {
2074 pr_err("reg_w %02x failed %d\n", index, ret); 2075 PERR("reg_w %02x failed %d\n", index, ret);
2075 sd->gspca_dev.usb_err = ret; 2076 sd->gspca_dev.usb_err = ret;
2076 return; 2077 return;
2077 } 2078 }
@@ -2081,6 +2082,7 @@ leave:
2081/* returns: negative is error, pos or zero is data */ 2082/* returns: negative is error, pos or zero is data */
2082static int reg_r(struct sd *sd, u16 index) 2083static int reg_r(struct sd *sd, u16 index)
2083{ 2084{
2085 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2084 int ret; 2086 int ret;
2085 int req; 2087 int req;
2086 2088
@@ -2110,7 +2112,7 @@ static int reg_r(struct sd *sd, u16 index)
2110 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x", 2112 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
2111 req, index, ret); 2113 req, index, ret);
2112 } else { 2114 } else {
2113 pr_err("reg_r %02x failed %d\n", index, ret); 2115 PERR("reg_r %02x failed %d\n", index, ret);
2114 sd->gspca_dev.usb_err = ret; 2116 sd->gspca_dev.usb_err = ret;
2115 } 2117 }
2116 2118
@@ -2121,6 +2123,7 @@ static int reg_r(struct sd *sd, u16 index)
2121static int reg_r8(struct sd *sd, 2123static int reg_r8(struct sd *sd,
2122 u16 index) 2124 u16 index)
2123{ 2125{
2126 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2124 int ret; 2127 int ret;
2125 2128
2126 if (sd->gspca_dev.usb_err < 0) 2129 if (sd->gspca_dev.usb_err < 0)
@@ -2135,7 +2138,7 @@ static int reg_r8(struct sd *sd,
2135 if (ret >= 0) { 2138 if (ret >= 0) {
2136 ret = sd->gspca_dev.usb_buf[0]; 2139 ret = sd->gspca_dev.usb_buf[0];
2137 } else { 2140 } else {
2138 pr_err("reg_r8 %02x failed %d\n", index, ret); 2141 PERR("reg_r8 %02x failed %d\n", index, ret);
2139 sd->gspca_dev.usb_err = ret; 2142 sd->gspca_dev.usb_err = ret;
2140 } 2143 }
2141 2144
@@ -2174,6 +2177,7 @@ static void reg_w_mask(struct sd *sd,
2174 */ 2177 */
2175static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n) 2178static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
2176{ 2179{
2180 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2177 int ret; 2181 int ret;
2178 2182
2179 if (sd->gspca_dev.usb_err < 0) 2183 if (sd->gspca_dev.usb_err < 0)
@@ -2188,13 +2192,14 @@ static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
2188 0, index, 2192 0, index,
2189 sd->gspca_dev.usb_buf, n, 500); 2193 sd->gspca_dev.usb_buf, n, 500);
2190 if (ret < 0) { 2194 if (ret < 0) {
2191 pr_err("reg_w32 %02x failed %d\n", index, ret); 2195 PERR("reg_w32 %02x failed %d\n", index, ret);
2192 sd->gspca_dev.usb_err = ret; 2196 sd->gspca_dev.usb_err = ret;
2193 } 2197 }
2194} 2198}
2195 2199
2196static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value) 2200static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
2197{ 2201{
2202 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2198 int rc, retries; 2203 int rc, retries;
2199 2204
2200 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value); 2205 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value);
@@ -2228,6 +2233,7 @@ static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
2228 2233
2229static int ov511_i2c_r(struct sd *sd, u8 reg) 2234static int ov511_i2c_r(struct sd *sd, u8 reg)
2230{ 2235{
2236 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2231 int rc, value, retries; 2237 int rc, value, retries;
2232 2238
2233 /* Two byte write cycle */ 2239 /* Two byte write cycle */
@@ -2300,6 +2306,8 @@ static void ov518_i2c_w(struct sd *sd,
2300 u8 reg, 2306 u8 reg,
2301 u8 value) 2307 u8 value)
2302{ 2308{
2309 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2310
2303 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value); 2311 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value);
2304 2312
2305 /* Select camera register */ 2313 /* Select camera register */
@@ -2325,6 +2333,7 @@ static void ov518_i2c_w(struct sd *sd,
2325 */ 2333 */
2326static int ov518_i2c_r(struct sd *sd, u8 reg) 2334static int ov518_i2c_r(struct sd *sd, u8 reg)
2327{ 2335{
2336 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2328 int value; 2337 int value;
2329 2338
2330 /* Select camera register */ 2339 /* Select camera register */
@@ -2345,6 +2354,7 @@ static int ov518_i2c_r(struct sd *sd, u8 reg)
2345 2354
2346static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value) 2355static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
2347{ 2356{
2357 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2348 int ret; 2358 int ret;
2349 2359
2350 if (sd->gspca_dev.usb_err < 0) 2360 if (sd->gspca_dev.usb_err < 0)
@@ -2357,7 +2367,7 @@ static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
2357 (u16) value, (u16) reg, NULL, 0, 500); 2367 (u16) value, (u16) reg, NULL, 0, 500);
2358 2368
2359 if (ret < 0) { 2369 if (ret < 0) {
2360 pr_err("ovfx2_i2c_w %02x failed %d\n", reg, ret); 2370 PERR("ovfx2_i2c_w %02x failed %d\n", reg, ret);
2361 sd->gspca_dev.usb_err = ret; 2371 sd->gspca_dev.usb_err = ret;
2362 } 2372 }
2363 2373
@@ -2366,6 +2376,7 @@ static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
2366 2376
2367static int ovfx2_i2c_r(struct sd *sd, u8 reg) 2377static int ovfx2_i2c_r(struct sd *sd, u8 reg)
2368{ 2378{
2379 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2369 int ret; 2380 int ret;
2370 2381
2371 if (sd->gspca_dev.usb_err < 0) 2382 if (sd->gspca_dev.usb_err < 0)
@@ -2381,7 +2392,7 @@ static int ovfx2_i2c_r(struct sd *sd, u8 reg)
2381 ret = sd->gspca_dev.usb_buf[0]; 2392 ret = sd->gspca_dev.usb_buf[0];
2382 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret); 2393 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
2383 } else { 2394 } else {
2384 pr_err("ovfx2_i2c_r %02x failed %d\n", reg, ret); 2395 PERR("ovfx2_i2c_r %02x failed %d\n", reg, ret);
2385 sd->gspca_dev.usb_err = ret; 2396 sd->gspca_dev.usb_err = ret;
2386 } 2397 }
2387 2398
@@ -2478,6 +2489,8 @@ static void i2c_w_mask(struct sd *sd,
2478 * registers while the camera is streaming */ 2489 * registers while the camera is streaming */
2479static inline void ov51x_stop(struct sd *sd) 2490static inline void ov51x_stop(struct sd *sd)
2480{ 2491{
2492 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2493
2481 PDEBUG(D_STREAM, "stopping"); 2494 PDEBUG(D_STREAM, "stopping");
2482 sd->stopped = 1; 2495 sd->stopped = 1;
2483 switch (sd->bridge) { 2496 switch (sd->bridge) {
@@ -2507,6 +2520,8 @@ static inline void ov51x_stop(struct sd *sd)
2507 * actually stopped (for performance). */ 2520 * actually stopped (for performance). */
2508static inline void ov51x_restart(struct sd *sd) 2521static inline void ov51x_restart(struct sd *sd)
2509{ 2522{
2523 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2524
2510 PDEBUG(D_STREAM, "restarting"); 2525 PDEBUG(D_STREAM, "restarting");
2511 if (!sd->stopped) 2526 if (!sd->stopped)
2512 return; 2527 return;
@@ -2545,6 +2560,7 @@ static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
2545static int init_ov_sensor(struct sd *sd, u8 slave) 2560static int init_ov_sensor(struct sd *sd, u8 slave)
2546{ 2561{
2547 int i; 2562 int i;
2563 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2548 2564
2549 ov51x_set_slave_ids(sd, slave); 2565 ov51x_set_slave_ids(sd, slave);
2550 2566
@@ -2624,10 +2640,11 @@ static void write_i2c_regvals(struct sd *sd,
2624/* This initializes the OV2x10 / OV3610 / OV3620 / OV9600 */ 2640/* This initializes the OV2x10 / OV3610 / OV3620 / OV9600 */
2625static void ov_hires_configure(struct sd *sd) 2641static void ov_hires_configure(struct sd *sd)
2626{ 2642{
2643 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2627 int high, low; 2644 int high, low;
2628 2645
2629 if (sd->bridge != BRIDGE_OVFX2) { 2646 if (sd->bridge != BRIDGE_OVFX2) {
2630 pr_err("error hires sensors only supported with ovfx2\n"); 2647 PERR("error hires sensors only supported with ovfx2\n");
2631 return; 2648 return;
2632 } 2649 }
2633 2650
@@ -2662,7 +2679,7 @@ static void ov_hires_configure(struct sd *sd)
2662 } 2679 }
2663 break; 2680 break;
2664 } 2681 }
2665 pr_err("Error unknown sensor type: %02x%02x\n", high, low); 2682 PERR("Error unknown sensor type: %02x%02x\n", high, low);
2666} 2683}
2667 2684
2668/* This initializes the OV8110, OV8610 sensor. The OV8110 uses 2685/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
@@ -2670,6 +2687,7 @@ static void ov_hires_configure(struct sd *sd)
2670 */ 2687 */
2671static void ov8xx0_configure(struct sd *sd) 2688static void ov8xx0_configure(struct sd *sd)
2672{ 2689{
2690 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2673 int rc; 2691 int rc;
2674 2692
2675 PDEBUG(D_PROBE, "starting ov8xx0 configuration"); 2693 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
@@ -2677,13 +2695,13 @@ static void ov8xx0_configure(struct sd *sd)
2677 /* Detect sensor (sub)type */ 2695 /* Detect sensor (sub)type */
2678 rc = i2c_r(sd, OV7610_REG_COM_I); 2696 rc = i2c_r(sd, OV7610_REG_COM_I);
2679 if (rc < 0) { 2697 if (rc < 0) {
2680 PDEBUG(D_ERR, "Error detecting sensor type"); 2698 PERR("Error detecting sensor type");
2681 return; 2699 return;
2682 } 2700 }
2683 if ((rc & 3) == 1) 2701 if ((rc & 3) == 1)
2684 sd->sensor = SEN_OV8610; 2702 sd->sensor = SEN_OV8610;
2685 else 2703 else
2686 pr_err("Unknown image sensor version: %d\n", rc & 3); 2704 PERR("Unknown image sensor version: %d\n", rc & 3);
2687} 2705}
2688 2706
2689/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses 2707/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
@@ -2691,6 +2709,7 @@ static void ov8xx0_configure(struct sd *sd)
2691 */ 2709 */
2692static void ov7xx0_configure(struct sd *sd) 2710static void ov7xx0_configure(struct sd *sd)
2693{ 2711{
2712 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2694 int rc, high, low; 2713 int rc, high, low;
2695 2714
2696 PDEBUG(D_PROBE, "starting OV7xx0 configuration"); 2715 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
@@ -2701,7 +2720,7 @@ static void ov7xx0_configure(struct sd *sd)
2701 /* add OV7670 here 2720 /* add OV7670 here
2702 * it appears to be wrongly detected as a 7610 by default */ 2721 * it appears to be wrongly detected as a 7610 by default */
2703 if (rc < 0) { 2722 if (rc < 0) {
2704 pr_err("Error detecting sensor type\n"); 2723 PERR("Error detecting sensor type\n");
2705 return; 2724 return;
2706 } 2725 }
2707 if ((rc & 3) == 3) { 2726 if ((rc & 3) == 3) {
@@ -2729,19 +2748,19 @@ static void ov7xx0_configure(struct sd *sd)
2729 /* try to read product id registers */ 2748 /* try to read product id registers */
2730 high = i2c_r(sd, 0x0a); 2749 high = i2c_r(sd, 0x0a);
2731 if (high < 0) { 2750 if (high < 0) {
2732 pr_err("Error detecting camera chip PID\n"); 2751 PERR("Error detecting camera chip PID\n");
2733 return; 2752 return;
2734 } 2753 }
2735 low = i2c_r(sd, 0x0b); 2754 low = i2c_r(sd, 0x0b);
2736 if (low < 0) { 2755 if (low < 0) {
2737 pr_err("Error detecting camera chip VER\n"); 2756 PERR("Error detecting camera chip VER\n");
2738 return; 2757 return;
2739 } 2758 }
2740 if (high == 0x76) { 2759 if (high == 0x76) {
2741 switch (low) { 2760 switch (low) {
2742 case 0x30: 2761 case 0x30:
2743 pr_err("Sensor is an OV7630/OV7635\n"); 2762 PERR("Sensor is an OV7630/OV7635\n");
2744 pr_err("7630 is not supported by this driver\n"); 2763 PERR("7630 is not supported by this driver\n");
2745 return; 2764 return;
2746 case 0x40: 2765 case 0x40:
2747 PDEBUG(D_PROBE, "Sensor is an OV7645"); 2766 PDEBUG(D_PROBE, "Sensor is an OV7645");
@@ -2760,7 +2779,7 @@ static void ov7xx0_configure(struct sd *sd)
2760 sd->sensor = SEN_OV7660; 2779 sd->sensor = SEN_OV7660;
2761 break; 2780 break;
2762 default: 2781 default:
2763 pr_err("Unknown sensor: 0x76%02x\n", low); 2782 PERR("Unknown sensor: 0x76%02x\n", low);
2764 return; 2783 return;
2765 } 2784 }
2766 } else { 2785 } else {
@@ -2768,20 +2787,22 @@ static void ov7xx0_configure(struct sd *sd)
2768 sd->sensor = SEN_OV7620; 2787 sd->sensor = SEN_OV7620;
2769 } 2788 }
2770 } else { 2789 } else {
2771 pr_err("Unknown image sensor version: %d\n", rc & 3); 2790 PERR("Unknown image sensor version: %d\n", rc & 3);
2772 } 2791 }
2773} 2792}
2774 2793
2775/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */ 2794/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
2776static void ov6xx0_configure(struct sd *sd) 2795static void ov6xx0_configure(struct sd *sd)
2777{ 2796{
2797 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2778 int rc; 2798 int rc;
2799
2779 PDEBUG(D_PROBE, "starting OV6xx0 configuration"); 2800 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
2780 2801
2781 /* Detect sensor (sub)type */ 2802 /* Detect sensor (sub)type */
2782 rc = i2c_r(sd, OV7610_REG_COM_I); 2803 rc = i2c_r(sd, OV7610_REG_COM_I);
2783 if (rc < 0) { 2804 if (rc < 0) {
2784 pr_err("Error detecting sensor type\n"); 2805 PERR("Error detecting sensor type\n");
2785 return; 2806 return;
2786 } 2807 }
2787 2808
@@ -2810,7 +2831,7 @@ static void ov6xx0_configure(struct sd *sd)
2810 pr_warn("WARNING: Sensor is an OV66307. Your camera may have been misdetected in previous driver versions.\n"); 2831 pr_warn("WARNING: Sensor is an OV66307. Your camera may have been misdetected in previous driver versions.\n");
2811 break; 2832 break;
2812 default: 2833 default:
2813 pr_err("FATAL: Unknown sensor version: 0x%02x\n", rc); 2834 PERR("FATAL: Unknown sensor version: 0x%02x\n", rc);
2814 return; 2835 return;
2815 } 2836 }
2816 2837
@@ -2907,6 +2928,7 @@ static void ov51x_upload_quan_tables(struct sd *sd)
2907 7, 7, 7, 7, 7, 7, 8, 8 2928 7, 7, 7, 7, 7, 7, 8, 8
2908 }; 2929 };
2909 2930
2931 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
2910 const unsigned char *pYTable, *pUVTable; 2932 const unsigned char *pYTable, *pUVTable;
2911 unsigned char val0, val1; 2933 unsigned char val0, val1;
2912 int i, size, reg = R51x_COMP_LUT_BEGIN; 2934 int i, size, reg = R51x_COMP_LUT_BEGIN;
@@ -3300,7 +3322,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
3300 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) { 3322 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
3301 ov_hires_configure(sd); 3323 ov_hires_configure(sd);
3302 } else { 3324 } else {
3303 pr_err("Can't determine sensor slave IDs\n"); 3325 PERR("Can't determine sensor slave IDs\n");
3304 goto error; 3326 goto error;
3305 } 3327 }
3306 3328
@@ -3433,7 +3455,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
3433 } 3455 }
3434 return gspca_dev->usb_err; 3456 return gspca_dev->usb_err;
3435error: 3457error:
3436 PDEBUG(D_ERR, "OV519 Config failed"); 3458 PERR("OV519 Config failed");
3437 return -EINVAL; 3459 return -EINVAL;
3438} 3460}
3439 3461
@@ -3459,6 +3481,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
3459 */ 3481 */
3460static void ov511_mode_init_regs(struct sd *sd) 3482static void ov511_mode_init_regs(struct sd *sd)
3461{ 3483{
3484 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
3462 int hsegs, vsegs, packet_size, fps, needed; 3485 int hsegs, vsegs, packet_size, fps, needed;
3463 int interlaced = 0; 3486 int interlaced = 0;
3464 struct usb_host_interface *alt; 3487 struct usb_host_interface *alt;
@@ -3467,7 +3490,7 @@ static void ov511_mode_init_regs(struct sd *sd)
3467 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); 3490 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3468 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 3491 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3469 if (!alt) { 3492 if (!alt) {
3470 pr_err("Couldn't get altsetting\n"); 3493 PERR("Couldn't get altsetting\n");
3471 sd->gspca_dev.usb_err = -EIO; 3494 sd->gspca_dev.usb_err = -EIO;
3472 return; 3495 return;
3473 } 3496 }
@@ -3583,6 +3606,7 @@ static void ov511_mode_init_regs(struct sd *sd)
3583 */ 3606 */
3584static void ov518_mode_init_regs(struct sd *sd) 3607static void ov518_mode_init_regs(struct sd *sd)
3585{ 3608{
3609 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
3586 int hsegs, vsegs, packet_size; 3610 int hsegs, vsegs, packet_size;
3587 struct usb_host_interface *alt; 3611 struct usb_host_interface *alt;
3588 struct usb_interface *intf; 3612 struct usb_interface *intf;
@@ -3590,7 +3614,7 @@ static void ov518_mode_init_regs(struct sd *sd)
3590 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); 3614 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3591 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 3615 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3592 if (!alt) { 3616 if (!alt) {
3593 pr_err("Couldn't get altsetting\n"); 3617 PERR("Couldn't get altsetting\n");
3594 sd->gspca_dev.usb_err = -EIO; 3618 sd->gspca_dev.usb_err = -EIO;
3595 return; 3619 return;
3596 } 3620 }
@@ -3750,6 +3774,8 @@ static void ov519_mode_init_regs(struct sd *sd)
3750 /* windows reads 0x55 at this point, why? */ 3774 /* windows reads 0x55 at this point, why? */
3751 }; 3775 };
3752 3776
3777 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
3778
3753 /******** Set the mode ********/ 3779 /******** Set the mode ********/
3754 switch (sd->sensor) { 3780 switch (sd->sensor) {
3755 default: 3781 default:
@@ -3865,11 +3891,10 @@ static void ov519_mode_init_regs(struct sd *sd)
3865 3891
3866static void mode_init_ov_sensor_regs(struct sd *sd) 3892static void mode_init_ov_sensor_regs(struct sd *sd)
3867{ 3893{
3868 struct gspca_dev *gspca_dev; 3894 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
3869 int qvga, xstart, xend, ystart, yend; 3895 int qvga, xstart, xend, ystart, yend;
3870 u8 v; 3896 u8 v;
3871 3897
3872 gspca_dev = &sd->gspca_dev;
3873 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1; 3898 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3874 3899
3875 /******** Mode (VGA/QVGA) and sensor specific regs ********/ 3900 /******** Mode (VGA/QVGA) and sensor specific regs ********/
@@ -4304,7 +4329,7 @@ static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
4304 /* Frame end */ 4329 /* Frame end */
4305 if ((in[9] + 1) * 8 != gspca_dev->width || 4330 if ((in[9] + 1) * 8 != gspca_dev->width ||
4306 (in[10] + 1) * 8 != gspca_dev->height) { 4331 (in[10] + 1) * 8 != gspca_dev->height) {
4307 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d," 4332 PERR("Invalid frame size, got: %dx%d,"
4308 " requested: %dx%d\n", 4333 " requested: %dx%d\n",
4309 (in[9] + 1) * 8, (in[10] + 1) * 8, 4334 (in[9] + 1) * 8, (in[10] + 1) * 8,
4310 gspca_dev->width, gspca_dev->height); 4335 gspca_dev->width, gspca_dev->height);
@@ -4355,7 +4380,7 @@ static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
4355 except that they may contain part of the footer), are 4380 except that they may contain part of the footer), are
4356 numbered 0 */ 4381 numbered 0 */
4357 else if (sd->packet_nr == 0 || data[len]) { 4382 else if (sd->packet_nr == 0 || data[len]) {
4358 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)", 4383 PERR("Invalid packet nr: %d (expect: %d)",
4359 (int)data[len], (int)sd->packet_nr); 4384 (int)data[len], (int)sd->packet_nr);
4360 gspca_dev->last_packet_type = DISCARD_PACKET; 4385 gspca_dev->last_packet_type = DISCARD_PACKET;
4361 return; 4386 return;
@@ -4898,7 +4923,7 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
4898 QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF); 4923 QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF);
4899 4924
4900 if (hdl->error) { 4925 if (hdl->error) {
4901 pr_err("Could not initialize controls\n"); 4926 PERR("Could not initialize controls\n");
4902 return hdl->error; 4927 return hdl->error;
4903 } 4928 }
4904 if (gspca_dev->autogain) 4929 if (gspca_dev->autogain)
diff --git a/drivers/media/usb/gspca/ov534.c b/drivers/media/usb/gspca/ov534.c
index bb09d7884b89..2e28c81a03ab 100644
--- a/drivers/media/usb/gspca/ov534.c
+++ b/drivers/media/usb/gspca/ov534.c
@@ -690,7 +690,7 @@ static int sccb_check_status(struct gspca_dev *gspca_dev)
690 case 0x03: 690 case 0x03:
691 break; 691 break;
692 default: 692 default:
693 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", 693 PERR("sccb status 0x%02x, attempt %d/5",
694 data, i + 1); 694 data, i + 1);
695 } 695 }
696 } 696 }
diff --git a/drivers/media/usb/gspca/pac207.c b/drivers/media/usb/gspca/pac207.c
index 3b75097dd34e..83519be94e58 100644
--- a/drivers/media/usb/gspca/pac207.c
+++ b/drivers/media/usb/gspca/pac207.c
@@ -373,7 +373,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
373 struct sd *sd = (struct sd *) gspca_dev; 373 struct sd *sd = (struct sd *) gspca_dev;
374 unsigned char *sof; 374 unsigned char *sof;
375 375
376 sof = pac_find_sof(&sd->sof_read, data, len); 376 sof = pac_find_sof(gspca_dev, &sd->sof_read, data, len);
377 if (sof) { 377 if (sof) {
378 int n; 378 int n;
379 379
diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index add6f725ba50..6008c8d546a3 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -344,13 +344,10 @@ static void reg_w_var(struct gspca_dev *gspca_dev,
344 reg_w_page(gspca_dev, page3, page3_len); 344 reg_w_page(gspca_dev, page3, page3_len);
345 break; 345 break;
346 default: 346 default:
347#ifdef GSPCA_DEBUG
348 if (len > USB_BUF_SZ) { 347 if (len > USB_BUF_SZ) {
349 PDEBUG(D_ERR|D_STREAM, 348 PERR("Incorrect variable sequence");
350 "Incorrect variable sequence");
351 return; 349 return;
352 } 350 }
353#endif
354 while (len > 0) { 351 while (len > 0) {
355 if (len < 8) { 352 if (len < 8) {
356 reg_w_buf(gspca_dev, 353 reg_w_buf(gspca_dev,
@@ -795,7 +792,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
795 u8 *image; 792 u8 *image;
796 u8 *sof; 793 u8 *sof;
797 794
798 sof = pac_find_sof(&sd->sof_read, data, len); 795 sof = pac_find_sof(gspca_dev, &sd->sof_read, data, len);
799 if (sof) { 796 if (sof) {
800 int n, lum_offset, footer_length; 797 int n, lum_offset, footer_length;
801 798
@@ -843,7 +840,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
843 840
844#ifdef CONFIG_VIDEO_ADV_DEBUG 841#ifdef CONFIG_VIDEO_ADV_DEBUG
845static int sd_dbg_s_register(struct gspca_dev *gspca_dev, 842static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
846 struct v4l2_dbg_register *reg) 843 const struct v4l2_dbg_register *reg)
847{ 844{
848 u8 index; 845 u8 index;
849 u8 value; 846 u8 value;
diff --git a/drivers/media/usb/gspca/pac7311.c b/drivers/media/usb/gspca/pac7311.c
index a12dfbf6e051..1a5bdc853a80 100644
--- a/drivers/media/usb/gspca/pac7311.c
+++ b/drivers/media/usb/gspca/pac7311.c
@@ -262,8 +262,7 @@ static void reg_w_var(struct gspca_dev *gspca_dev,
262 break; 262 break;
263 default: 263 default:
264 if (len > USB_BUF_SZ) { 264 if (len > USB_BUF_SZ) {
265 PDEBUG(D_ERR|D_STREAM, 265 PERR("Incorrect variable sequence");
266 "Incorrect variable sequence");
267 return; 266 return;
268 } 267 }
269 while (len > 0) { 268 while (len > 0) {
@@ -575,7 +574,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
575 u8 *image; 574 u8 *image;
576 unsigned char *sof; 575 unsigned char *sof;
577 576
578 sof = pac_find_sof(&sd->sof_read, data, len); 577 sof = pac_find_sof(gspca_dev, &sd->sof_read, data, len);
579 if (sof) { 578 if (sof) {
580 int n, lum_offset, footer_length; 579 int n, lum_offset, footer_length;
581 580
diff --git a/drivers/media/usb/gspca/pac_common.h b/drivers/media/usb/gspca/pac_common.h
index 8462a7c1a338..fbc5e226c3e4 100644
--- a/drivers/media/usb/gspca/pac_common.h
+++ b/drivers/media/usb/gspca/pac_common.h
@@ -71,7 +71,7 @@ static const unsigned char pac_sof_marker[5] =
71 +----------+ 71 +----------+
72*/ 72*/
73 73
74static unsigned char *pac_find_sof(u8 *sof_read, 74static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev, u8 *sof_read,
75 unsigned char *m, int len) 75 unsigned char *m, int len)
76{ 76{
77 int i; 77 int i;
diff --git a/drivers/media/usb/gspca/sn9c2028.c b/drivers/media/usb/gspca/sn9c2028.c
index 03fa3fd940b4..39b6b2e02963 100644
--- a/drivers/media/usb/gspca/sn9c2028.c
+++ b/drivers/media/usb/gspca/sn9c2028.c
@@ -650,13 +650,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
650 650
651 result = sn9c2028_read1(gspca_dev); 651 result = sn9c2028_read1(gspca_dev);
652 if (result < 0) 652 if (result < 0)
653 PDEBUG(D_ERR, "Camera Stop read failed"); 653 PERR("Camera Stop read failed");
654 654
655 memset(data, 0, 6); 655 memset(data, 0, 6);
656 data[0] = 0x14; 656 data[0] = 0x14;
657 result = sn9c2028_command(gspca_dev, data); 657 result = sn9c2028_command(gspca_dev, data);
658 if (result < 0) 658 if (result < 0)
659 PDEBUG(D_ERR, "Camera Stop command failed"); 659 PERR("Camera Stop command failed");
660} 660}
661 661
662/* Include sn9c2028 sof detection functions */ 662/* Include sn9c2028 sof detection functions */
diff --git a/drivers/media/usb/gspca/sn9c20x.c b/drivers/media/usb/gspca/sn9c20x.c
index 4ec544f4a845..ead9a1f58513 100644
--- a/drivers/media/usb/gspca/sn9c20x.c
+++ b/drivers/media/usb/gspca/sn9c20x.c
@@ -1598,7 +1598,7 @@ static int sd_dbg_g_register(struct gspca_dev *gspca_dev,
1598} 1598}
1599 1599
1600static int sd_dbg_s_register(struct gspca_dev *gspca_dev, 1600static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
1601 struct v4l2_dbg_register *reg) 1601 const struct v4l2_dbg_register *reg)
1602{ 1602{
1603 struct sd *sd = (struct sd *) gspca_dev; 1603 struct sd *sd = (struct sd *) gspca_dev;
1604 1604
diff --git a/drivers/media/usb/gspca/sonixb.c b/drivers/media/usb/gspca/sonixb.c
index 104ae25275b4..3fe207e038c7 100644
--- a/drivers/media/usb/gspca/sonixb.c
+++ b/drivers/media/usb/gspca/sonixb.c
@@ -1379,27 +1379,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1379 } 1379 }
1380} 1380}
1381 1381
1382static int sd_querymenu(struct gspca_dev *gspca_dev,
1383 struct v4l2_querymenu *menu)
1384{
1385 switch (menu->id) {
1386 case V4L2_CID_POWER_LINE_FREQUENCY:
1387 switch (menu->index) {
1388 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1389 strcpy((char *) menu->name, "NoFliker");
1390 return 0;
1391 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1392 strcpy((char *) menu->name, "50 Hz");
1393 return 0;
1394 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1395 strcpy((char *) menu->name, "60 Hz");
1396 return 0;
1397 }
1398 break;
1399 }
1400 return -EINVAL;
1401}
1402
1403#if IS_ENABLED(CONFIG_INPUT) 1382#if IS_ENABLED(CONFIG_INPUT)
1404static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 1383static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1405 u8 *data, /* interrupt packet data */ 1384 u8 *data, /* interrupt packet data */
@@ -1428,7 +1407,6 @@ static const struct sd_desc sd_desc = {
1428 .start = sd_start, 1407 .start = sd_start,
1429 .stopN = sd_stopN, 1408 .stopN = sd_stopN,
1430 .pkt_scan = sd_pkt_scan, 1409 .pkt_scan = sd_pkt_scan,
1431 .querymenu = sd_querymenu,
1432 .dq_callback = do_autogain, 1410 .dq_callback = do_autogain,
1433#if IS_ENABLED(CONFIG_INPUT) 1411#if IS_ENABLED(CONFIG_INPUT)
1434 .int_pkt_scan = sd_int_pkt_scan, 1412 .int_pkt_scan = sd_int_pkt_scan,
diff --git a/drivers/media/usb/gspca/sonixj.c b/drivers/media/usb/gspca/sonixj.c
index 671d0c6dece3..3b5ccb1c4cdf 100644
--- a/drivers/media/usb/gspca/sonixj.c
+++ b/drivers/media/usb/gspca/sonixj.c
@@ -31,32 +31,26 @@ MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
31MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
32MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
33 33
34/* controls */
35enum e_ctrl {
36 BRIGHTNESS,
37 CONTRAST,
38 COLORS,
39 BLUE,
40 RED,
41 GAMMA,
42 EXPOSURE,
43 AUTOGAIN,
44 GAIN,
45 HFLIP,
46 VFLIP,
47 SHARPNESS,
48 ILLUM,
49 FREQ,
50 NCTRLS /* number of controls */
51};
52
53/* specific webcam descriptor */ 34/* specific webcam descriptor */
54struct sd { 35struct sd {
55 struct gspca_dev gspca_dev; /* !! must be the first item */ 36 struct gspca_dev gspca_dev; /* !! must be the first item */
56 37
57 struct gspca_ctrl ctrls[NCTRLS];
58
59 atomic_t avg_lum; 38 atomic_t avg_lum;
39 struct v4l2_ctrl *brightness;
40 struct v4l2_ctrl *contrast;
41 struct v4l2_ctrl *saturation;
42 struct { /* red/blue balance control cluster */
43 struct v4l2_ctrl *red_bal;
44 struct v4l2_ctrl *blue_bal;
45 };
46 struct { /* hflip/vflip control cluster */
47 struct v4l2_ctrl *vflip;
48 struct v4l2_ctrl *hflip;
49 };
50 struct v4l2_ctrl *gamma;
51 struct v4l2_ctrl *illum;
52 struct v4l2_ctrl *sharpness;
53 struct v4l2_ctrl *freq;
60 u32 exposure; 54 u32 exposure;
61 55
62 struct work_struct work; 56 struct work_struct work;
@@ -127,283 +121,6 @@ static void qual_upd(struct work_struct *work);
127#define SEN_CLK_EN 0x20 /* enable sensor clock */ 121#define SEN_CLK_EN 0x20 /* enable sensor clock */
128#define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */ 122#define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */
129 123
130/* V4L2 controls supported by the driver */
131static void setbrightness(struct gspca_dev *gspca_dev);
132static void setcontrast(struct gspca_dev *gspca_dev);
133static void setcolors(struct gspca_dev *gspca_dev);
134static void setredblue(struct gspca_dev *gspca_dev);
135static void setgamma(struct gspca_dev *gspca_dev);
136static void setexposure(struct gspca_dev *gspca_dev);
137static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
138static void setgain(struct gspca_dev *gspca_dev);
139static void sethvflip(struct gspca_dev *gspca_dev);
140static void setsharpness(struct gspca_dev *gspca_dev);
141static void setillum(struct gspca_dev *gspca_dev);
142static void setfreq(struct gspca_dev *gspca_dev);
143
144static const struct ctrl sd_ctrls[NCTRLS] = {
145[BRIGHTNESS] = {
146 {
147 .id = V4L2_CID_BRIGHTNESS,
148 .type = V4L2_CTRL_TYPE_INTEGER,
149 .name = "Brightness",
150 .minimum = 0,
151 .maximum = 0xff,
152 .step = 1,
153 .default_value = 0x80,
154 },
155 .set_control = setbrightness
156 },
157[CONTRAST] = {
158 {
159 .id = V4L2_CID_CONTRAST,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "Contrast",
162 .minimum = 0,
163#define CONTRAST_MAX 127
164 .maximum = CONTRAST_MAX,
165 .step = 1,
166 .default_value = 20,
167 },
168 .set_control = setcontrast
169 },
170[COLORS] = {
171 {
172 .id = V4L2_CID_SATURATION,
173 .type = V4L2_CTRL_TYPE_INTEGER,
174 .name = "Saturation",
175 .minimum = 0,
176 .maximum = 40,
177 .step = 1,
178#define COLORS_DEF 25
179 .default_value = COLORS_DEF,
180 },
181 .set_control = setcolors
182 },
183[BLUE] = {
184 {
185 .id = V4L2_CID_BLUE_BALANCE,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 .name = "Blue Balance",
188 .minimum = 24,
189 .maximum = 40,
190 .step = 1,
191 .default_value = 32,
192 },
193 .set_control = setredblue
194 },
195[RED] = {
196 {
197 .id = V4L2_CID_RED_BALANCE,
198 .type = V4L2_CTRL_TYPE_INTEGER,
199 .name = "Red Balance",
200 .minimum = 24,
201 .maximum = 40,
202 .step = 1,
203 .default_value = 32,
204 },
205 .set_control = setredblue
206 },
207[GAMMA] = {
208 {
209 .id = V4L2_CID_GAMMA,
210 .type = V4L2_CTRL_TYPE_INTEGER,
211 .name = "Gamma",
212 .minimum = 0,
213 .maximum = 40,
214 .step = 1,
215#define GAMMA_DEF 20
216 .default_value = GAMMA_DEF,
217 },
218 .set_control = setgamma
219 },
220[EXPOSURE] = {
221 {
222 .id = V4L2_CID_EXPOSURE,
223 .type = V4L2_CTRL_TYPE_INTEGER,
224 .name = "Exposure",
225 .minimum = 500,
226 .maximum = 1500,
227 .step = 1,
228 .default_value = 1024
229 },
230 .set_control = setexposure
231 },
232[AUTOGAIN] = {
233 {
234 .id = V4L2_CID_AUTOGAIN,
235 .type = V4L2_CTRL_TYPE_BOOLEAN,
236 .name = "Auto Gain",
237 .minimum = 0,
238 .maximum = 1,
239 .step = 1,
240 .default_value = 1
241 },
242 .set = sd_setautogain,
243 },
244[GAIN] = {
245 {
246 .id = V4L2_CID_GAIN,
247 .type = V4L2_CTRL_TYPE_INTEGER,
248 .name = "Gain",
249 .minimum = 4,
250 .maximum = 49,
251 .step = 1,
252 .default_value = 15
253 },
254 .set_control = setgain
255 },
256[HFLIP] = {
257 {
258 .id = V4L2_CID_HFLIP,
259 .type = V4L2_CTRL_TYPE_BOOLEAN,
260 .name = "Mirror",
261 .minimum = 0,
262 .maximum = 1,
263 .step = 1,
264 .default_value = 0,
265 },
266 .set_control = sethvflip
267 },
268[VFLIP] = {
269 {
270 .id = V4L2_CID_VFLIP,
271 .type = V4L2_CTRL_TYPE_BOOLEAN,
272 .name = "Vflip",
273 .minimum = 0,
274 .maximum = 1,
275 .step = 1,
276 .default_value = 0,
277 },
278 .set_control = sethvflip
279 },
280[SHARPNESS] = {
281 {
282 .id = V4L2_CID_SHARPNESS,
283 .type = V4L2_CTRL_TYPE_INTEGER,
284 .name = "Sharpness",
285 .minimum = 0,
286 .maximum = 255,
287 .step = 1,
288 .default_value = 90,
289 },
290 .set_control = setsharpness
291 },
292[ILLUM] = {
293 {
294 .id = V4L2_CID_ILLUMINATORS_1,
295 .type = V4L2_CTRL_TYPE_BOOLEAN,
296 .name = "Illuminator / infrared",
297 .minimum = 0,
298 .maximum = 1,
299 .step = 1,
300 .default_value = 0,
301 },
302 .set_control = setillum
303 },
304/* ov7630/ov7648/ov7660 only */
305[FREQ] = {
306 {
307 .id = V4L2_CID_POWER_LINE_FREQUENCY,
308 .type = V4L2_CTRL_TYPE_MENU,
309 .name = "Light frequency filter",
310 .minimum = 0,
311 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
312 .step = 1,
313 .default_value = 1,
314 },
315 .set_control = setfreq
316 },
317};
318
319/* table of the disabled controls */
320static const __u32 ctrl_dis[] = {
321[SENSOR_ADCM1700] = (1 << EXPOSURE) |
322 (1 << AUTOGAIN) |
323 (1 << GAIN) |
324 (1 << HFLIP) |
325 (1 << VFLIP) |
326 (1 << FREQ),
327
328[SENSOR_GC0307] = (1 << EXPOSURE) |
329 (1 << GAIN) |
330 (1 << HFLIP) |
331 (1 << VFLIP) |
332 (1 << FREQ),
333
334[SENSOR_HV7131R] = (1 << EXPOSURE) |
335 (1 << GAIN) |
336 (1 << HFLIP) |
337 (1 << FREQ),
338
339[SENSOR_MI0360] = (1 << EXPOSURE) |
340 (1 << GAIN) |
341 (1 << HFLIP) |
342 (1 << VFLIP) |
343 (1 << FREQ),
344
345[SENSOR_MI0360B] = (1 << EXPOSURE) |
346 (1 << GAIN) |
347 (1 << HFLIP) |
348 (1 << VFLIP) |
349 (1 << FREQ),
350
351[SENSOR_MO4000] = (1 << EXPOSURE) |
352 (1 << GAIN) |
353 (1 << HFLIP) |
354 (1 << VFLIP) |
355 (1 << FREQ),
356
357[SENSOR_MT9V111] = (1 << EXPOSURE) |
358 (1 << GAIN) |
359 (1 << HFLIP) |
360 (1 << VFLIP) |
361 (1 << FREQ),
362
363[SENSOR_OM6802] = (1 << EXPOSURE) |
364 (1 << GAIN) |
365 (1 << HFLIP) |
366 (1 << VFLIP) |
367 (1 << FREQ),
368
369[SENSOR_OV7630] = (1 << EXPOSURE) |
370 (1 << GAIN) |
371 (1 << HFLIP),
372
373[SENSOR_OV7648] = (1 << EXPOSURE) |
374 (1 << GAIN) |
375 (1 << HFLIP),
376
377[SENSOR_OV7660] = (1 << EXPOSURE) |
378 (1 << AUTOGAIN) |
379 (1 << GAIN) |
380 (1 << HFLIP) |
381 (1 << VFLIP),
382
383[SENSOR_PO1030] = (1 << EXPOSURE) |
384 (1 << AUTOGAIN) |
385 (1 << GAIN) |
386 (1 << HFLIP) |
387 (1 << VFLIP) |
388 (1 << FREQ),
389
390[SENSOR_PO2030N] = (1 << FREQ),
391
392[SENSOR_SOI768] = (1 << EXPOSURE) |
393 (1 << AUTOGAIN) |
394 (1 << GAIN) |
395 (1 << HFLIP) |
396 (1 << VFLIP) |
397 (1 << FREQ),
398
399[SENSOR_SP80708] = (1 << EXPOSURE) |
400 (1 << AUTOGAIN) |
401 (1 << GAIN) |
402 (1 << HFLIP) |
403 (1 << VFLIP) |
404 (1 << FREQ),
405};
406
407static const struct v4l2_pix_format cif_mode[] = { 124static const struct v4l2_pix_format cif_mode[] = {
408 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 125 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
409 .bytesperline = 352, 126 .bytesperline = 352,
@@ -1442,12 +1159,11 @@ static void reg_r(struct gspca_dev *gspca_dev,
1442 1159
1443 if (gspca_dev->usb_err < 0) 1160 if (gspca_dev->usb_err < 0)
1444 return; 1161 return;
1445#ifdef GSPCA_DEBUG
1446 if (len > USB_BUF_SZ) { 1162 if (len > USB_BUF_SZ) {
1447 pr_err("reg_r: buffer overflow\n"); 1163 PERR("reg_r: buffer overflow\n");
1448 return; 1164 return;
1449 } 1165 }
1450#endif 1166
1451 ret = usb_control_msg(gspca_dev->dev, 1167 ret = usb_control_msg(gspca_dev->dev,
1452 usb_rcvctrlpipe(gspca_dev->dev, 0), 1168 usb_rcvctrlpipe(gspca_dev->dev, 0),
1453 0, 1169 0,
@@ -1496,12 +1212,12 @@ static void reg_w(struct gspca_dev *gspca_dev,
1496 return; 1212 return;
1497 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..", 1213 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
1498 value, buffer[0], buffer[1]); 1214 value, buffer[0], buffer[1]);
1499#ifdef GSPCA_DEBUG 1215
1500 if (len > USB_BUF_SZ) { 1216 if (len > USB_BUF_SZ) {
1501 pr_err("reg_w: buffer overflow\n"); 1217 PERR("reg_w: buffer overflow\n");
1502 return; 1218 return;
1503 } 1219 }
1504#endif 1220
1505 memcpy(gspca_dev->usb_buf, buffer, len); 1221 memcpy(gspca_dev->usb_buf, buffer, len);
1506 ret = usb_control_msg(gspca_dev->dev, 1222 ret = usb_control_msg(gspca_dev->dev,
1507 usb_sndctrlpipe(gspca_dev->dev, 0), 1223 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -1822,7 +1538,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1822 cam->nmodes = ARRAY_SIZE(vga_mode); 1538 cam->nmodes = ARRAY_SIZE(vga_mode);
1823 } 1539 }
1824 cam->npkt = 24; /* 24 packets per ISOC message */ 1540 cam->npkt = 24; /* 24 packets per ISOC message */
1825 cam->ctrls = sd->ctrls;
1826 1541
1827 sd->ag_cnt = -1; 1542 sd->ag_cnt = -1;
1828 sd->quality = QUALITY_DEF; 1543 sd->quality = QUALITY_DEF;
@@ -1888,9 +1603,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
1888 break; 1603 break;
1889 } 1604 }
1890 1605
1891 if (sd->sensor == SENSOR_OM6802)
1892 sd->ctrls[SHARPNESS].def = 0x10;
1893
1894 /* Note we do not disable the sensor clock here (power saving mode), 1606 /* Note we do not disable the sensor clock here (power saving mode),
1895 as that also disables the button on the cam. */ 1607 as that also disables the button on the cam. */
1896 reg_w1(gspca_dev, 0xf1, 0x00); 1608 reg_w1(gspca_dev, 0xf1, 0x00);
@@ -1899,13 +1611,92 @@ static int sd_init(struct gspca_dev *gspca_dev)
1899 sn9c1xx = sn_tb[sd->sensor]; 1611 sn9c1xx = sn_tb[sd->sensor];
1900 sd->i2c_addr = sn9c1xx[9]; 1612 sd->i2c_addr = sn9c1xx[9];
1901 1613
1902 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
1903 if (!(sd->flags & F_ILLUM))
1904 gspca_dev->ctrl_dis |= (1 << ILLUM);
1905
1906 return gspca_dev->usb_err; 1614 return gspca_dev->usb_err;
1907} 1615}
1908 1616
1617static int sd_s_ctrl(struct v4l2_ctrl *ctrl);
1618
1619static const struct v4l2_ctrl_ops sd_ctrl_ops = {
1620 .s_ctrl = sd_s_ctrl,
1621};
1622
1623/* this function is called at probe time */
1624static int sd_init_controls(struct gspca_dev *gspca_dev)
1625{
1626 struct sd *sd = (struct sd *) gspca_dev;
1627 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
1628
1629 gspca_dev->vdev.ctrl_handler = hdl;
1630 v4l2_ctrl_handler_init(hdl, 14);
1631
1632 sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1633 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1634#define CONTRAST_MAX 127
1635 sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1636 V4L2_CID_CONTRAST, 0, CONTRAST_MAX, 1, 20);
1637#define COLORS_DEF 25
1638 sd->saturation = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1639 V4L2_CID_SATURATION, 0, 40, 1, COLORS_DEF);
1640 sd->red_bal = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1641 V4L2_CID_RED_BALANCE, 24, 40, 1, 32);
1642 sd->blue_bal = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1643 V4L2_CID_BLUE_BALANCE, 24, 40, 1, 32);
1644#define GAMMA_DEF 20
1645 sd->gamma = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1646 V4L2_CID_GAMMA, 0, 40, 1, GAMMA_DEF);
1647
1648 if (sd->sensor == SENSOR_OM6802)
1649 sd->sharpness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1650 V4L2_CID_SHARPNESS, 0, 255, 1, 16);
1651 else
1652 sd->sharpness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1653 V4L2_CID_SHARPNESS, 0, 255, 1, 90);
1654
1655 if (sd->flags & F_ILLUM)
1656 sd->illum = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1657 V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0);
1658
1659 if (sd->sensor == SENSOR_PO2030N) {
1660 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1661 V4L2_CID_EXPOSURE, 500, 1500, 1, 1024);
1662 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1663 V4L2_CID_GAIN, 4, 49, 1, 15);
1664 sd->hflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1665 V4L2_CID_HFLIP, 0, 1, 1, 0);
1666 }
1667
1668 if (sd->sensor != SENSOR_ADCM1700 && sd->sensor != SENSOR_OV7660 &&
1669 sd->sensor != SENSOR_PO1030 && sd->sensor != SENSOR_SOI768 &&
1670 sd->sensor != SENSOR_SP80708)
1671 gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1672 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1673
1674 if (sd->sensor == SENSOR_HV7131R || sd->sensor == SENSOR_OV7630 ||
1675 sd->sensor == SENSOR_OV7648 || sd->sensor == SENSOR_PO2030N)
1676 sd->vflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1677 V4L2_CID_VFLIP, 0, 1, 1, 0);
1678
1679 if (sd->sensor == SENSOR_OV7630 || sd->sensor == SENSOR_OV7648 ||
1680 sd->sensor == SENSOR_OV7660)
1681 sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
1682 V4L2_CID_POWER_LINE_FREQUENCY,
1683 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
1684 V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
1685
1686 if (hdl->error) {
1687 pr_err("Could not initialize controls\n");
1688 return hdl->error;
1689 }
1690
1691 v4l2_ctrl_cluster(2, &sd->red_bal);
1692 if (sd->sensor == SENSOR_PO2030N) {
1693 v4l2_ctrl_cluster(2, &sd->vflip);
1694 v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
1695 }
1696
1697 return 0;
1698}
1699
1909static u32 expo_adjust(struct gspca_dev *gspca_dev, 1700static u32 expo_adjust(struct gspca_dev *gspca_dev,
1910 u32 expo) 1701 u32 expo)
1911{ 1702{
@@ -2014,10 +1805,9 @@ static void setbrightness(struct gspca_dev *gspca_dev)
2014{ 1805{
2015 struct sd *sd = (struct sd *) gspca_dev; 1806 struct sd *sd = (struct sd *) gspca_dev;
2016 unsigned int expo; 1807 unsigned int expo;
2017 int brightness; 1808 int brightness = sd->brightness->val;
2018 u8 k2; 1809 u8 k2;
2019 1810
2020 brightness = sd->ctrls[BRIGHTNESS].val;
2021 k2 = (brightness - 0x80) >> 2; 1811 k2 = (brightness - 0x80) >> 2;
2022 switch (sd->sensor) { 1812 switch (sd->sensor) {
2023 case SENSOR_ADCM1700: 1813 case SENSOR_ADCM1700:
@@ -2064,7 +1854,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
2064 u8 k2; 1854 u8 k2;
2065 u8 contrast[6]; 1855 u8 contrast[6];
2066 1856
2067 k2 = sd->ctrls[CONTRAST].val * 37 / (CONTRAST_MAX + 1) 1857 k2 = sd->contrast->val * 37 / (CONTRAST_MAX + 1)
2068 + 37; /* 37..73 */ 1858 + 37; /* 37..73 */
2069 contrast[0] = (k2 + 1) / 2; /* red */ 1859 contrast[0] = (k2 + 1) / 2; /* red */
2070 contrast[1] = 0; 1860 contrast[1] = 0;
@@ -2090,7 +1880,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
2090 60, -51, -9 /* VR VG VB */ 1880 60, -51, -9 /* VR VG VB */
2091 }; 1881 };
2092 1882
2093 colors = sd->ctrls[COLORS].val; 1883 colors = sd->saturation->val;
2094 if (sd->sensor == SENSOR_MI0360B) 1884 if (sd->sensor == SENSOR_MI0360B)
2095 uv = uv_mi0360b; 1885 uv = uv_mi0360b;
2096 else 1886 else
@@ -2112,14 +1902,14 @@ static void setredblue(struct gspca_dev *gspca_dev)
2112 {0xc1, 0x6e, 0x16, 0x00, 0x40, 0x00, 0x00, 0x10}; 1902 {0xc1, 0x6e, 0x16, 0x00, 0x40, 0x00, 0x00, 0x10};
2113 1903
2114 /* 0x40 = normal value = gain x 1 */ 1904 /* 0x40 = normal value = gain x 1 */
2115 rg1b[3] = sd->ctrls[RED].val * 2; 1905 rg1b[3] = sd->red_bal->val * 2;
2116 rg1b[5] = sd->ctrls[BLUE].val * 2; 1906 rg1b[5] = sd->blue_bal->val * 2;
2117 i2c_w8(gspca_dev, rg1b); 1907 i2c_w8(gspca_dev, rg1b);
2118 return; 1908 return;
2119 } 1909 }
2120 reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val); 1910 reg_w1(gspca_dev, 0x05, sd->red_bal->val);
2121/* reg_w1(gspca_dev, 0x07, 32); */ 1911/* reg_w1(gspca_dev, 0x07, 32); */
2122 reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val); 1912 reg_w1(gspca_dev, 0x06, sd->blue_bal->val);
2123} 1913}
2124 1914
2125static void setgamma(struct gspca_dev *gspca_dev) 1915static void setgamma(struct gspca_dev *gspca_dev)
@@ -2153,7 +1943,7 @@ static void setgamma(struct gspca_dev *gspca_dev)
2153 break; 1943 break;
2154 } 1944 }
2155 1945
2156 val = sd->ctrls[GAMMA].val; 1946 val = sd->gamma->val;
2157 for (i = 0; i < sizeof gamma; i++) 1947 for (i = 0; i < sizeof gamma; i++)
2158 gamma[i] = gamma_base[i] 1948 gamma[i] = gamma_base[i]
2159 + delta[i] * (val - GAMMA_DEF) / 32; 1949 + delta[i] * (val - GAMMA_DEF) / 32;
@@ -2168,11 +1958,11 @@ static void setexposure(struct gspca_dev *gspca_dev)
2168 u8 rexpo[] = /* 1a: expo H, 1b: expo M */ 1958 u8 rexpo[] = /* 1a: expo H, 1b: expo M */
2169 {0xa1, 0x6e, 0x1a, 0x00, 0x40, 0x00, 0x00, 0x10}; 1959 {0xa1, 0x6e, 0x1a, 0x00, 0x40, 0x00, 0x00, 0x10};
2170 1960
2171 rexpo[3] = sd->ctrls[EXPOSURE].val >> 8; 1961 rexpo[3] = gspca_dev->exposure->val >> 8;
2172 i2c_w8(gspca_dev, rexpo); 1962 i2c_w8(gspca_dev, rexpo);
2173 msleep(6); 1963 msleep(6);
2174 rexpo[2] = 0x1b; 1964 rexpo[2] = 0x1b;
2175 rexpo[3] = sd->ctrls[EXPOSURE].val; 1965 rexpo[3] = gspca_dev->exposure->val;
2176 i2c_w8(gspca_dev, rexpo); 1966 i2c_w8(gspca_dev, rexpo);
2177 } 1967 }
2178} 1968}
@@ -2181,8 +1971,6 @@ static void setautogain(struct gspca_dev *gspca_dev)
2181{ 1971{
2182 struct sd *sd = (struct sd *) gspca_dev; 1972 struct sd *sd = (struct sd *) gspca_dev;
2183 1973
2184 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
2185 return;
2186 switch (sd->sensor) { 1974 switch (sd->sensor) {
2187 case SENSOR_OV7630: 1975 case SENSOR_OV7630:
2188 case SENSOR_OV7648: { 1976 case SENSOR_OV7648: {
@@ -2192,13 +1980,13 @@ static void setautogain(struct gspca_dev *gspca_dev)
2192 comb = 0xc0; 1980 comb = 0xc0;
2193 else 1981 else
2194 comb = 0xa0; 1982 comb = 0xa0;
2195 if (sd->ctrls[AUTOGAIN].val) 1983 if (gspca_dev->autogain->val)
2196 comb |= 0x03; 1984 comb |= 0x03;
2197 i2c_w1(&sd->gspca_dev, 0x13, comb); 1985 i2c_w1(&sd->gspca_dev, 0x13, comb);
2198 return; 1986 return;
2199 } 1987 }
2200 } 1988 }
2201 if (sd->ctrls[AUTOGAIN].val) 1989 if (gspca_dev->autogain->val)
2202 sd->ag_cnt = AG_CNT_START; 1990 sd->ag_cnt = AG_CNT_START;
2203 else 1991 else
2204 sd->ag_cnt = -1; 1992 sd->ag_cnt = -1;
@@ -2212,7 +2000,7 @@ static void setgain(struct gspca_dev *gspca_dev)
2212 u8 rgain[] = /* 15: gain */ 2000 u8 rgain[] = /* 15: gain */
2213 {0xa1, 0x6e, 0x15, 0x00, 0x40, 0x00, 0x00, 0x15}; 2001 {0xa1, 0x6e, 0x15, 0x00, 0x40, 0x00, 0x00, 0x15};
2214 2002
2215 rgain[3] = sd->ctrls[GAIN].val; 2003 rgain[3] = gspca_dev->gain->val;
2216 i2c_w8(gspca_dev, rgain); 2004 i2c_w8(gspca_dev, rgain);
2217 } 2005 }
2218} 2006}
@@ -2225,19 +2013,19 @@ static void sethvflip(struct gspca_dev *gspca_dev)
2225 switch (sd->sensor) { 2013 switch (sd->sensor) {
2226 case SENSOR_HV7131R: 2014 case SENSOR_HV7131R:
2227 comn = 0x18; /* clkdiv = 1, ablcen = 1 */ 2015 comn = 0x18; /* clkdiv = 1, ablcen = 1 */
2228 if (sd->ctrls[VFLIP].val) 2016 if (sd->vflip->val)
2229 comn |= 0x01; 2017 comn |= 0x01;
2230 i2c_w1(gspca_dev, 0x01, comn); /* sctra */ 2018 i2c_w1(gspca_dev, 0x01, comn); /* sctra */
2231 break; 2019 break;
2232 case SENSOR_OV7630: 2020 case SENSOR_OV7630:
2233 comn = 0x02; 2021 comn = 0x02;
2234 if (!sd->ctrls[VFLIP].val) 2022 if (!sd->vflip->val)
2235 comn |= 0x80; 2023 comn |= 0x80;
2236 i2c_w1(gspca_dev, 0x75, comn); 2024 i2c_w1(gspca_dev, 0x75, comn);
2237 break; 2025 break;
2238 case SENSOR_OV7648: 2026 case SENSOR_OV7648:
2239 comn = 0x06; 2027 comn = 0x06;
2240 if (sd->ctrls[VFLIP].val) 2028 if (sd->vflip->val)
2241 comn |= 0x80; 2029 comn |= 0x80;
2242 i2c_w1(gspca_dev, 0x75, comn); 2030 i2c_w1(gspca_dev, 0x75, comn);
2243 break; 2031 break;
@@ -2251,9 +2039,9 @@ static void sethvflip(struct gspca_dev *gspca_dev)
2251 * bit3-0: X 2039 * bit3-0: X
2252 */ 2040 */
2253 comn = 0x0a; 2041 comn = 0x0a;
2254 if (sd->ctrls[HFLIP].val) 2042 if (sd->hflip->val)
2255 comn |= 0x80; 2043 comn |= 0x80;
2256 if (sd->ctrls[VFLIP].val) 2044 if (sd->vflip->val)
2257 comn |= 0x40; 2045 comn |= 0x40;
2258 i2c_w1(&sd->gspca_dev, 0x1e, comn); 2046 i2c_w1(&sd->gspca_dev, 0x1e, comn);
2259 break; 2047 break;
@@ -2264,23 +2052,21 @@ static void setsharpness(struct gspca_dev *gspca_dev)
2264{ 2052{
2265 struct sd *sd = (struct sd *) gspca_dev; 2053 struct sd *sd = (struct sd *) gspca_dev;
2266 2054
2267 reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val); 2055 reg_w1(gspca_dev, 0x99, sd->sharpness->val);
2268} 2056}
2269 2057
2270static void setillum(struct gspca_dev *gspca_dev) 2058static void setillum(struct gspca_dev *gspca_dev)
2271{ 2059{
2272 struct sd *sd = (struct sd *) gspca_dev; 2060 struct sd *sd = (struct sd *) gspca_dev;
2273 2061
2274 if (gspca_dev->ctrl_dis & (1 << ILLUM))
2275 return;
2276 switch (sd->sensor) { 2062 switch (sd->sensor) {
2277 case SENSOR_ADCM1700: 2063 case SENSOR_ADCM1700:
2278 reg_w1(gspca_dev, 0x02, /* gpio */ 2064 reg_w1(gspca_dev, 0x02, /* gpio */
2279 sd->ctrls[ILLUM].val ? 0x64 : 0x60); 2065 sd->illum->val ? 0x64 : 0x60);
2280 break; 2066 break;
2281 case SENSOR_MT9V111: 2067 case SENSOR_MT9V111:
2282 reg_w1(gspca_dev, 0x02, 2068 reg_w1(gspca_dev, 0x02,
2283 sd->ctrls[ILLUM].val ? 0x77 : 0x74); 2069 sd->illum->val ? 0x77 : 0x74);
2284/* should have been: */ 2070/* should have been: */
2285/* 0x55 : 0x54); * 370i */ 2071/* 0x55 : 0x54); * 370i */
2286/* 0x66 : 0x64); * Clip */ 2072/* 0x66 : 0x64); * Clip */
@@ -2292,13 +2078,11 @@ static void setfreq(struct gspca_dev *gspca_dev)
2292{ 2078{
2293 struct sd *sd = (struct sd *) gspca_dev; 2079 struct sd *sd = (struct sd *) gspca_dev;
2294 2080
2295 if (gspca_dev->ctrl_dis & (1 << FREQ))
2296 return;
2297 if (sd->sensor == SENSOR_OV7660) { 2081 if (sd->sensor == SENSOR_OV7660) {
2298 u8 com8; 2082 u8 com8;
2299 2083
2300 com8 = 0xdf; /* auto gain/wb/expo */ 2084 com8 = 0xdf; /* auto gain/wb/expo */
2301 switch (sd->ctrls[FREQ].val) { 2085 switch (sd->freq->val) {
2302 case 0: /* Banding filter disabled */ 2086 case 0: /* Banding filter disabled */
2303 i2c_w1(gspca_dev, 0x13, com8 | 0x20); 2087 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
2304 break; 2088 break;
@@ -2326,7 +2110,7 @@ static void setfreq(struct gspca_dev *gspca_dev)
2326 break; 2110 break;
2327 } 2111 }
2328 2112
2329 switch (sd->ctrls[FREQ].val) { 2113 switch (sd->freq->val) {
2330 case 0: /* Banding filter disabled */ 2114 case 0: /* Banding filter disabled */
2331 break; 2115 break;
2332 case 1: /* 50 hz (filter on and framerate adj) */ 2116 case 1: /* 50 hz (filter on and framerate adj) */
@@ -2698,17 +2482,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
2698 sd->reg01 = reg01; 2482 sd->reg01 = reg01;
2699 sd->reg17 = reg17; 2483 sd->reg17 = reg17;
2700 2484
2701 sethvflip(gspca_dev);
2702 setbrightness(gspca_dev);
2703 setcontrast(gspca_dev);
2704 setcolors(gspca_dev);
2705 setautogain(gspca_dev);
2706 if (!(gspca_dev->ctrl_inac & ((1 << EXPOSURE) | (1 << GAIN)))) {
2707 setexposure(gspca_dev);
2708 setgain(gspca_dev);
2709 }
2710 setfreq(gspca_dev);
2711
2712 sd->pktsz = sd->npkt = 0; 2485 sd->pktsz = sd->npkt = 0;
2713 sd->nchg = sd->short_mark = 0; 2486 sd->nchg = sd->short_mark = 0;
2714 sd->work_thread = create_singlethread_workqueue(MODULE_NAME); 2487 sd->work_thread = create_singlethread_workqueue(MODULE_NAME);
@@ -2803,9 +2576,6 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2803 } 2576 }
2804} 2577}
2805 2578
2806#define WANT_REGULAR_AUTOGAIN
2807#include "autogain_functions.h"
2808
2809static void do_autogain(struct gspca_dev *gspca_dev) 2579static void do_autogain(struct gspca_dev *gspca_dev)
2810{ 2580{
2811 struct sd *sd = (struct sd *) gspca_dev; 2581 struct sd *sd = (struct sd *) gspca_dev;
@@ -2825,7 +2595,7 @@ static void do_autogain(struct gspca_dev *gspca_dev)
2825 PDEBUG(D_FRAM, "mean lum %d", delta); 2595 PDEBUG(D_FRAM, "mean lum %d", delta);
2826 2596
2827 if (sd->sensor == SENSOR_PO2030N) { 2597 if (sd->sensor == SENSOR_PO2030N) {
2828 auto_gain_n_exposure(gspca_dev, delta, luma_mean, luma_delta, 2598 gspca_expo_autogain(gspca_dev, delta, luma_mean, luma_delta,
2829 15, 1024); 2599 15, 1024);
2830 return; 2600 return;
2831 } 2601 }
@@ -3042,39 +2812,53 @@ marker_found:
3042 } 2812 }
3043} 2813}
3044 2814
3045static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) 2815static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
3046{ 2816{
3047 struct sd *sd = (struct sd *) gspca_dev; 2817 struct gspca_dev *gspca_dev =
2818 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
3048 2819
3049 sd->ctrls[AUTOGAIN].val = val; 2820 gspca_dev->usb_err = 0;
3050 if (val)
3051 gspca_dev->ctrl_inac |= (1 << EXPOSURE) | (1 << GAIN);
3052 else
3053 gspca_dev->ctrl_inac &= ~(1 << EXPOSURE) & ~(1 << GAIN);
3054 if (gspca_dev->streaming)
3055 setautogain(gspca_dev);
3056 return gspca_dev->usb_err;
3057}
3058 2821
3059static int sd_querymenu(struct gspca_dev *gspca_dev, 2822 if (!gspca_dev->streaming)
3060 struct v4l2_querymenu *menu) 2823 return 0;
3061{ 2824
3062 switch (menu->id) { 2825 switch (ctrl->id) {
2826 case V4L2_CID_BRIGHTNESS:
2827 setbrightness(gspca_dev);
2828 break;
2829 case V4L2_CID_CONTRAST:
2830 setcontrast(gspca_dev);
2831 break;
2832 case V4L2_CID_SATURATION:
2833 setcolors(gspca_dev);
2834 break;
2835 case V4L2_CID_RED_BALANCE:
2836 setredblue(gspca_dev);
2837 break;
2838 case V4L2_CID_GAMMA:
2839 setgamma(gspca_dev);
2840 break;
2841 case V4L2_CID_AUTOGAIN:
2842 setautogain(gspca_dev);
2843 setexposure(gspca_dev);
2844 setgain(gspca_dev);
2845 break;
2846 case V4L2_CID_VFLIP:
2847 sethvflip(gspca_dev);
2848 break;
2849 case V4L2_CID_SHARPNESS:
2850 setsharpness(gspca_dev);
2851 break;
2852 case V4L2_CID_ILLUMINATORS_1:
2853 setillum(gspca_dev);
2854 break;
3063 case V4L2_CID_POWER_LINE_FREQUENCY: 2855 case V4L2_CID_POWER_LINE_FREQUENCY:
3064 switch (menu->index) { 2856 setfreq(gspca_dev);
3065 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
3066 strcpy((char *) menu->name, "NoFliker");
3067 return 0;
3068 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
3069 strcpy((char *) menu->name, "50 Hz");
3070 return 0;
3071 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
3072 strcpy((char *) menu->name, "60 Hz");
3073 return 0;
3074 }
3075 break; 2857 break;
2858 default:
2859 return -EINVAL;
3076 } 2860 }
3077 return -EINVAL; 2861 return gspca_dev->usb_err;
3078} 2862}
3079 2863
3080#if IS_ENABLED(CONFIG_INPUT) 2864#if IS_ENABLED(CONFIG_INPUT)
@@ -3099,16 +2883,14 @@ static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
3099/* sub-driver description */ 2883/* sub-driver description */
3100static const struct sd_desc sd_desc = { 2884static const struct sd_desc sd_desc = {
3101 .name = MODULE_NAME, 2885 .name = MODULE_NAME,
3102 .ctrls = sd_ctrls,
3103 .nctrls = NCTRLS,
3104 .config = sd_config, 2886 .config = sd_config,
3105 .init = sd_init, 2887 .init = sd_init,
2888 .init_controls = sd_init_controls,
3106 .start = sd_start, 2889 .start = sd_start,
3107 .stopN = sd_stopN, 2890 .stopN = sd_stopN,
3108 .stop0 = sd_stop0, 2891 .stop0 = sd_stop0,
3109 .pkt_scan = sd_pkt_scan, 2892 .pkt_scan = sd_pkt_scan,
3110 .dq_callback = do_autogain, 2893 .dq_callback = do_autogain,
3111 .querymenu = sd_querymenu,
3112#if IS_ENABLED(CONFIG_INPUT) 2894#if IS_ENABLED(CONFIG_INPUT)
3113 .int_pkt_scan = sd_int_pkt_scan, 2895 .int_pkt_scan = sd_int_pkt_scan,
3114#endif 2896#endif
diff --git a/drivers/media/usb/gspca/spca1528.c b/drivers/media/usb/gspca/spca1528.c
index 14d635277d71..688592b289ea 100644
--- a/drivers/media/usb/gspca/spca1528.c
+++ b/drivers/media/usb/gspca/spca1528.c
@@ -146,7 +146,7 @@ static void wait_status_0(struct gspca_dev *gspca_dev)
146 w += 15; 146 w += 15;
147 msleep(w); 147 msleep(w);
148 } while (--i > 0); 148 } while (--i > 0);
149 PDEBUG(D_ERR, "wait_status_0 timeout"); 149 PERR("wait_status_0 timeout");
150 gspca_dev->usb_err = -ETIME; 150 gspca_dev->usb_err = -ETIME;
151} 151}
152 152
@@ -164,7 +164,7 @@ static void wait_status_1(struct gspca_dev *gspca_dev)
164 return; 164 return;
165 } 165 }
166 } while (--i > 0); 166 } while (--i > 0);
167 PDEBUG(D_ERR, "wait_status_1 timeout"); 167 PERR("wait_status_1 timeout");
168 gspca_dev->usb_err = -ETIME; 168 gspca_dev->usb_err = -ETIME;
169} 169}
170 170
diff --git a/drivers/media/usb/gspca/spca500.c b/drivers/media/usb/gspca/spca500.c
index 25cb68d0556d..9f8bf51fd64b 100644
--- a/drivers/media/usb/gspca/spca500.c
+++ b/drivers/media/usb/gspca/spca500.c
@@ -489,7 +489,7 @@ static int spca500_full_reset(struct gspca_dev *gspca_dev)
489 return err; 489 return err;
490 err = reg_r_wait(gspca_dev, 0x06, 0, 0); 490 err = reg_r_wait(gspca_dev, 0x06, 0, 0);
491 if (err < 0) { 491 if (err < 0) {
492 PDEBUG(D_ERR, "reg_r_wait() failed"); 492 PERR("reg_r_wait() failed");
493 return err; 493 return err;
494 } 494 }
495 /* all ok */ 495 /* all ok */
@@ -505,7 +505,7 @@ static int spca500_full_reset(struct gspca_dev *gspca_dev)
505static int spca500_synch310(struct gspca_dev *gspca_dev) 505static int spca500_synch310(struct gspca_dev *gspca_dev)
506{ 506{
507 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) { 507 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
508 PDEBUG(D_ERR, "Set packet size: set interface error"); 508 PERR("Set packet size: set interface error");
509 goto error; 509 goto error;
510 } 510 }
511 spca500_ping310(gspca_dev); 511 spca500_ping310(gspca_dev);
@@ -519,7 +519,7 @@ static int spca500_synch310(struct gspca_dev *gspca_dev)
519 if (usb_set_interface(gspca_dev->dev, 519 if (usb_set_interface(gspca_dev->dev,
520 gspca_dev->iface, 520 gspca_dev->iface,
521 gspca_dev->alt) < 0) { 521 gspca_dev->alt) < 0) {
522 PDEBUG(D_ERR, "Set packet size: set interface error"); 522 PERR("Set packet size: set interface error");
523 goto error; 523 goto error;
524 } 524 }
525 return 0; 525 return 0;
@@ -544,7 +544,7 @@ static void spca500_reinit(struct gspca_dev *gspca_dev)
544 err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, 544 err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
545 qtable_pocketdv); 545 qtable_pocketdv);
546 if (err < 0) 546 if (err < 0)
547 PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init"); 547 PERR("spca50x_setup_qtable failed on init");
548 548
549 /* set qtable index */ 549 /* set qtable index */
550 reg_w(gspca_dev, 0x00, 0x8880, 2); 550 reg_w(gspca_dev, 0x00, 0x8880, 2);
@@ -639,7 +639,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
639 0x00, 0x8800, 0x8840, 639 0x00, 0x8800, 0x8840,
640 qtable_creative_pccam); 640 qtable_creative_pccam);
641 if (err < 0) 641 if (err < 0)
642 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 642 PERR("spca50x_setup_qtable failed");
643 /* Init SDRAM - needed for SDRAM access */ 643 /* Init SDRAM - needed for SDRAM access */
644 reg_w(gspca_dev, 0x00, 0x870a, 0x04); 644 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
645 645
@@ -647,7 +647,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
647 reg_w(gspca_dev, 0x00, 0x8000, 0x0004); 647 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
648 msleep(500); 648 msleep(500);
649 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) 649 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
650 PDEBUG(D_ERR, "reg_r_wait() failed"); 650 PERR("reg_r_wait() failed");
651 651
652 reg_r(gspca_dev, 0x816b, 1); 652 reg_r(gspca_dev, 0x816b, 1);
653 Data = gspca_dev->usb_buf[0]; 653 Data = gspca_dev->usb_buf[0];
@@ -660,13 +660,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
660 /* enable drop packet */ 660 /* enable drop packet */
661 err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001); 661 err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
662 if (err < 0) 662 if (err < 0)
663 PDEBUG(D_ERR, "failed to enable drop packet"); 663 PERR("failed to enable drop packet");
664 reg_w(gspca_dev, 0x00, 0x8880, 3); 664 reg_w(gspca_dev, 0x00, 0x8880, 3);
665 err = spca50x_setup_qtable(gspca_dev, 665 err = spca50x_setup_qtable(gspca_dev,
666 0x00, 0x8800, 0x8840, 666 0x00, 0x8800, 0x8840,
667 qtable_creative_pccam); 667 qtable_creative_pccam);
668 if (err < 0) 668 if (err < 0)
669 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 669 PERR("spca50x_setup_qtable failed");
670 670
671 /* Init SDRAM - needed for SDRAM access */ 671 /* Init SDRAM - needed for SDRAM access */
672 reg_w(gspca_dev, 0x00, 0x870a, 0x04); 672 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
@@ -675,7 +675,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
675 reg_w(gspca_dev, 0x00, 0x8000, 0x0004); 675 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
676 676
677 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) 677 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
678 PDEBUG(D_ERR, "reg_r_wait() failed"); 678 PERR("reg_r_wait() failed");
679 679
680 reg_r(gspca_dev, 0x816b, 1); 680 reg_r(gspca_dev, 0x816b, 1);
681 Data = gspca_dev->usb_buf[0]; 681 Data = gspca_dev->usb_buf[0];
@@ -689,18 +689,18 @@ static int sd_start(struct gspca_dev *gspca_dev)
689 /* do a full reset */ 689 /* do a full reset */
690 err = spca500_full_reset(gspca_dev); 690 err = spca500_full_reset(gspca_dev);
691 if (err < 0) 691 if (err < 0)
692 PDEBUG(D_ERR, "spca500_full_reset failed"); 692 PERR("spca500_full_reset failed");
693 693
694 /* enable drop packet */ 694 /* enable drop packet */
695 err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001); 695 err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
696 if (err < 0) 696 if (err < 0)
697 PDEBUG(D_ERR, "failed to enable drop packet"); 697 PERR("failed to enable drop packet");
698 reg_w(gspca_dev, 0x00, 0x8880, 3); 698 reg_w(gspca_dev, 0x00, 0x8880, 3);
699 err = spca50x_setup_qtable(gspca_dev, 699 err = spca50x_setup_qtable(gspca_dev,
700 0x00, 0x8800, 0x8840, 700 0x00, 0x8800, 0x8840,
701 qtable_creative_pccam); 701 qtable_creative_pccam);
702 if (err < 0) 702 if (err < 0)
703 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 703 PERR("spca50x_setup_qtable failed");
704 704
705 spca500_setmode(gspca_dev, xmult, ymult); 705 spca500_setmode(gspca_dev, xmult, ymult);
706 reg_w(gspca_dev, 0x20, 0x0001, 0x0004); 706 reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
@@ -709,7 +709,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
709 reg_w(gspca_dev, 0x00, 0x8000, 0x0004); 709 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
710 710
711 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) 711 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
712 PDEBUG(D_ERR, "reg_r_wait() failed"); 712 PERR("reg_r_wait() failed");
713 713
714 reg_r(gspca_dev, 0x816b, 1); 714 reg_r(gspca_dev, 0x816b, 1);
715 Data = gspca_dev->usb_buf[0]; 715 Data = gspca_dev->usb_buf[0];
@@ -722,7 +722,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
722 /* do a full reset */ 722 /* do a full reset */
723 err = spca500_full_reset(gspca_dev); 723 err = spca500_full_reset(gspca_dev);
724 if (err < 0) 724 if (err < 0)
725 PDEBUG(D_ERR, "spca500_full_reset failed"); 725 PERR("spca500_full_reset failed");
726 /* enable drop packet */ 726 /* enable drop packet */
727 reg_w(gspca_dev, 0x00, 0x850a, 0x0001); 727 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
728 reg_w(gspca_dev, 0x00, 0x8880, 0); 728 reg_w(gspca_dev, 0x00, 0x8880, 0);
@@ -730,7 +730,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
730 0x00, 0x8800, 0x8840, 730 0x00, 0x8800, 0x8840,
731 qtable_kodak_ez200); 731 qtable_kodak_ez200);
732 if (err < 0) 732 if (err < 0)
733 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 733 PERR("spca50x_setup_qtable failed");
734 spca500_setmode(gspca_dev, xmult, ymult); 734 spca500_setmode(gspca_dev, xmult, ymult);
735 735
736 reg_w(gspca_dev, 0x20, 0x0001, 0x0004); 736 reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
@@ -739,7 +739,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
739 reg_w(gspca_dev, 0x00, 0x8000, 0x0004); 739 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
740 740
741 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) 741 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
742 PDEBUG(D_ERR, "reg_r_wait() failed"); 742 PERR("reg_r_wait() failed");
743 743
744 reg_r(gspca_dev, 0x816b, 1); 744 reg_r(gspca_dev, 0x816b, 1);
745 Data = gspca_dev->usb_buf[0]; 745 Data = gspca_dev->usb_buf[0];
@@ -765,7 +765,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
765 err = spca50x_setup_qtable(gspca_dev, 765 err = spca50x_setup_qtable(gspca_dev,
766 0x00, 0x8800, 0x8840, qtable_pocketdv); 766 0x00, 0x8800, 0x8840, qtable_pocketdv);
767 if (err < 0) 767 if (err < 0)
768 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 768 PERR("spca50x_setup_qtable failed");
769 reg_w(gspca_dev, 0x00, 0x8880, 2); 769 reg_w(gspca_dev, 0x00, 0x8880, 2);
770 770
771 /* familycam Quicksmart pocketDV stuff */ 771 /* familycam Quicksmart pocketDV stuff */
@@ -795,7 +795,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
795 0x00, 0x8800, 795 0x00, 0x8800,
796 0x8840, qtable_creative_pccam); 796 0x8840, qtable_creative_pccam);
797 if (err < 0) 797 if (err < 0)
798 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 798 PERR("spca50x_setup_qtable failed");
799 reg_w(gspca_dev, 0x00, 0x8880, 3); 799 reg_w(gspca_dev, 0x00, 0x8880, 3);
800 reg_w(gspca_dev, 0x00, 0x800a, 0x00); 800 reg_w(gspca_dev, 0x00, 0x800a, 0x00);
801 /* Init SDRAM - needed for SDRAM access */ 801 /* Init SDRAM - needed for SDRAM access */
diff --git a/drivers/media/usb/gspca/spca501.c b/drivers/media/usb/gspca/spca501.c
index 3b7f777785b4..d92fd17d6701 100644
--- a/drivers/media/usb/gspca/spca501.c
+++ b/drivers/media/usb/gspca/spca501.c
@@ -1756,10 +1756,11 @@ static const __u16 spca501c_mysterious_init_data[][3] = {
1756 {} 1756 {}
1757}; 1757};
1758 1758
1759static int reg_write(struct usb_device *dev, 1759static int reg_write(struct gspca_dev *gspca_dev,
1760 __u16 req, __u16 index, __u16 value) 1760 __u16 req, __u16 index, __u16 value)
1761{ 1761{
1762 int ret; 1762 int ret;
1763 struct usb_device *dev = gspca_dev->dev;
1763 1764
1764 ret = usb_control_msg(dev, 1765 ret = usb_control_msg(dev,
1765 usb_sndctrlpipe(dev, 0), 1766 usb_sndctrlpipe(dev, 0),
@@ -1774,17 +1775,15 @@ static int reg_write(struct usb_device *dev,
1774} 1775}
1775 1776
1776 1777
1777static int write_vector(struct gspca_dev *gspca_dev, 1778static int write_vector(struct gspca_dev *gspca_dev, const __u16 data[][3])
1778 const __u16 data[][3])
1779{ 1779{
1780 struct usb_device *dev = gspca_dev->dev;
1781 int ret, i = 0; 1780 int ret, i = 0;
1782 1781
1783 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { 1782 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
1784 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); 1783 ret = reg_write(gspca_dev, data[i][0], data[i][2],
1784 data[i][1]);
1785 if (ret < 0) { 1785 if (ret < 0) {
1786 PDEBUG(D_ERR, 1786 PERR("Reg write failed for 0x%02x,0x%02x,0x%02x",
1787 "Reg write failed for 0x%02x,0x%02x,0x%02x",
1788 data[i][0], data[i][1], data[i][2]); 1787 data[i][0], data[i][1], data[i][2]);
1789 return ret; 1788 return ret;
1790 } 1789 }
@@ -1795,30 +1794,28 @@ static int write_vector(struct gspca_dev *gspca_dev,
1795 1794
1796static void setbrightness(struct gspca_dev *gspca_dev, s32 val) 1795static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
1797{ 1796{
1798 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x12, val); 1797 reg_write(gspca_dev, SPCA501_REG_CCDSP, 0x12, val);
1799} 1798}
1800 1799
1801static void setcontrast(struct gspca_dev *gspca_dev, s32 val) 1800static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
1802{ 1801{
1803 reg_write(gspca_dev->dev, 0x00, 0x00, 1802 reg_write(gspca_dev, 0x00, 0x00, (val >> 8) & 0xff);
1804 (val >> 8) & 0xff); 1803 reg_write(gspca_dev, 0x00, 0x01, val & 0xff);
1805 reg_write(gspca_dev->dev, 0x00, 0x01,
1806 val & 0xff);
1807} 1804}
1808 1805
1809static void setcolors(struct gspca_dev *gspca_dev, s32 val) 1806static void setcolors(struct gspca_dev *gspca_dev, s32 val)
1810{ 1807{
1811 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x0c, val); 1808 reg_write(gspca_dev, SPCA501_REG_CCDSP, 0x0c, val);
1812} 1809}
1813 1810
1814static void setblue_balance(struct gspca_dev *gspca_dev, s32 val) 1811static void setblue_balance(struct gspca_dev *gspca_dev, s32 val)
1815{ 1812{
1816 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x11, val); 1813 reg_write(gspca_dev, SPCA501_REG_CCDSP, 0x11, val);
1817} 1814}
1818 1815
1819static void setred_balance(struct gspca_dev *gspca_dev, s32 val) 1816static void setred_balance(struct gspca_dev *gspca_dev, s32 val)
1820{ 1817{
1821 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x13, val); 1818 reg_write(gspca_dev, SPCA501_REG_CCDSP, 0x13, val);
1822} 1819}
1823 1820
1824/* this function is called at probe time */ 1821/* this function is called at probe time */
@@ -1868,7 +1865,6 @@ error:
1868static int sd_start(struct gspca_dev *gspca_dev) 1865static int sd_start(struct gspca_dev *gspca_dev)
1869{ 1866{
1870 struct sd *sd = (struct sd *) gspca_dev; 1867 struct sd *sd = (struct sd *) gspca_dev;
1871 struct usb_device *dev = gspca_dev->dev;
1872 int mode; 1868 int mode;
1873 1869
1874 switch (sd->subtype) { 1870 switch (sd->subtype) {
@@ -1895,20 +1891,20 @@ static int sd_start(struct gspca_dev *gspca_dev)
1895 1891
1896 /* Enable ISO packet machine CTRL reg=2, 1892 /* Enable ISO packet machine CTRL reg=2,
1897 * index=1 bitmask=0x2 (bit ordinal 1) */ 1893 * index=1 bitmask=0x2 (bit ordinal 1) */
1898 reg_write(dev, SPCA50X_REG_USB, 0x6, 0x94); 1894 reg_write(gspca_dev, SPCA50X_REG_USB, 0x6, 0x94);
1899 switch (mode) { 1895 switch (mode) {
1900 case 0: /* 640x480 */ 1896 case 0: /* 640x480 */
1901 reg_write(dev, SPCA50X_REG_USB, 0x07, 0x004a); 1897 reg_write(gspca_dev, SPCA50X_REG_USB, 0x07, 0x004a);
1902 break; 1898 break;
1903 case 1: /* 320x240 */ 1899 case 1: /* 320x240 */
1904 reg_write(dev, SPCA50X_REG_USB, 0x07, 0x104a); 1900 reg_write(gspca_dev, SPCA50X_REG_USB, 0x07, 0x104a);
1905 break; 1901 break;
1906 default: 1902 default:
1907/* case 2: * 160x120 */ 1903/* case 2: * 160x120 */
1908 reg_write(dev, SPCA50X_REG_USB, 0x07, 0x204a); 1904 reg_write(gspca_dev, SPCA50X_REG_USB, 0x07, 0x204a);
1909 break; 1905 break;
1910 } 1906 }
1911 reg_write(dev, SPCA501_REG_CTLRL, 0x01, 0x02); 1907 reg_write(gspca_dev, SPCA501_REG_CTLRL, 0x01, 0x02);
1912 1908
1913 return 0; 1909 return 0;
1914} 1910}
@@ -1917,7 +1913,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1917{ 1913{
1918 /* Disable ISO packet 1914 /* Disable ISO packet
1919 * machine CTRL reg=2, index=1 bitmask=0x0 (bit ordinal 1) */ 1915 * machine CTRL reg=2, index=1 bitmask=0x0 (bit ordinal 1) */
1920 reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x01, 0x00); 1916 reg_write(gspca_dev, SPCA501_REG_CTLRL, 0x01, 0x00);
1921} 1917}
1922 1918
1923/* called on streamoff with alt 0 and on disconnect */ 1919/* called on streamoff with alt 0 and on disconnect */
@@ -1925,7 +1921,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
1925{ 1921{
1926 if (!gspca_dev->present) 1922 if (!gspca_dev->present)
1927 return; 1923 return;
1928 reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x05, 0x00); 1924 reg_write(gspca_dev, SPCA501_REG_CTLRL, 0x05, 0x00);
1929} 1925}
1930 1926
1931static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1927static void sd_pkt_scan(struct gspca_dev *gspca_dev,
diff --git a/drivers/media/usb/gspca/spca505.c b/drivers/media/usb/gspca/spca505.c
index bc7d67c3cb04..232b330d2dd3 100644
--- a/drivers/media/usb/gspca/spca505.c
+++ b/drivers/media/usb/gspca/spca505.c
@@ -544,10 +544,11 @@ static const u8 spca505b_open_data_ccd[][3] = {
544 {} 544 {}
545}; 545};
546 546
547static int reg_write(struct usb_device *dev, 547static int reg_write(struct gspca_dev *gspca_dev,
548 u16 req, u16 index, u16 value) 548 u16 req, u16 index, u16 value)
549{ 549{
550 int ret; 550 int ret;
551 struct usb_device *dev = gspca_dev->dev;
551 552
552 ret = usb_control_msg(dev, 553 ret = usb_control_msg(dev,
553 usb_sndctrlpipe(dev, 0), 554 usb_sndctrlpipe(dev, 0),
@@ -584,11 +585,11 @@ static int reg_read(struct gspca_dev *gspca_dev,
584static int write_vector(struct gspca_dev *gspca_dev, 585static int write_vector(struct gspca_dev *gspca_dev,
585 const u8 data[][3]) 586 const u8 data[][3])
586{ 587{
587 struct usb_device *dev = gspca_dev->dev;
588 int ret, i = 0; 588 int ret, i = 0;
589 589
590 while (data[i][0] != 0) { 590 while (data[i][0] != 0) {
591 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); 591 ret = reg_write(gspca_dev, data[i][0], data[i][2],
592 data[i][1]);
592 if (ret < 0) 593 if (ret < 0)
593 return ret; 594 return ret;
594 i++; 595 i++;
@@ -629,14 +630,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
629 630
630static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness) 631static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
631{ 632{
632 reg_write(gspca_dev->dev, 0x05, 0x00, (255 - brightness) >> 6); 633 reg_write(gspca_dev, 0x05, 0x00, (255 - brightness) >> 6);
633 reg_write(gspca_dev->dev, 0x05, 0x01, (255 - brightness) << 2); 634 reg_write(gspca_dev, 0x05, 0x01, (255 - brightness) << 2);
634} 635}
635 636
636static int sd_start(struct gspca_dev *gspca_dev) 637static int sd_start(struct gspca_dev *gspca_dev)
637{ 638{
638 struct sd *sd = (struct sd *) gspca_dev; 639 struct sd *sd = (struct sd *) gspca_dev;
639 struct usb_device *dev = gspca_dev->dev;
640 int ret, mode; 640 int ret, mode;
641 static u8 mode_tb[][3] = { 641 static u8 mode_tb[][3] = {
642 /* r00 r06 r07 */ 642 /* r00 r06 r07 */
@@ -654,9 +654,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
654 ret = reg_read(gspca_dev, 0x06, 0x16); 654 ret = reg_read(gspca_dev, 0x06, 0x16);
655 655
656 if (ret < 0) { 656 if (ret < 0) {
657 PDEBUG(D_ERR|D_CONF, 657 PERR("register read failed err: %d", ret);
658 "register read failed err: %d",
659 ret);
660 return ret; 658 return ret;
661 } 659 }
662 if (ret != 0x0101) { 660 if (ret != 0x0101) {
@@ -664,22 +662,22 @@ static int sd_start(struct gspca_dev *gspca_dev)
664 ret); 662 ret);
665 } 663 }
666 664
667 ret = reg_write(gspca_dev->dev, 0x06, 0x16, 0x0a); 665 ret = reg_write(gspca_dev, 0x06, 0x16, 0x0a);
668 if (ret < 0) 666 if (ret < 0)
669 return ret; 667 return ret;
670 reg_write(gspca_dev->dev, 0x05, 0xc2, 0x12); 668 reg_write(gspca_dev, 0x05, 0xc2, 0x12);
671 669
672 /* necessary because without it we can see stream 670 /* necessary because without it we can see stream
673 * only once after loading module */ 671 * only once after loading module */
674 /* stopping usb registers Tomasz change */ 672 /* stopping usb registers Tomasz change */
675 reg_write(dev, 0x02, 0x00, 0x00); 673 reg_write(gspca_dev, 0x02, 0x00, 0x00);
676 674
677 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 675 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
678 reg_write(dev, SPCA50X_REG_COMPRESS, 0x00, mode_tb[mode][0]); 676 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x00, mode_tb[mode][0]);
679 reg_write(dev, SPCA50X_REG_COMPRESS, 0x06, mode_tb[mode][1]); 677 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x06, mode_tb[mode][1]);
680 reg_write(dev, SPCA50X_REG_COMPRESS, 0x07, mode_tb[mode][2]); 678 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x07, mode_tb[mode][2]);
681 679
682 return reg_write(dev, SPCA50X_REG_USB, 680 return reg_write(gspca_dev, SPCA50X_REG_USB,
683 SPCA50X_USB_CTRL, 681 SPCA50X_USB_CTRL,
684 SPCA50X_CUSB_ENABLE); 682 SPCA50X_CUSB_ENABLE);
685} 683}
@@ -687,7 +685,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
687static void sd_stopN(struct gspca_dev *gspca_dev) 685static void sd_stopN(struct gspca_dev *gspca_dev)
688{ 686{
689 /* Disable ISO packet machine */ 687 /* Disable ISO packet machine */
690 reg_write(gspca_dev->dev, 0x02, 0x00, 0x00); 688 reg_write(gspca_dev, 0x02, 0x00, 0x00);
691} 689}
692 690
693/* called on streamoff with alt 0 and on disconnect */ 691/* called on streamoff with alt 0 and on disconnect */
@@ -697,11 +695,11 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
697 return; 695 return;
698 696
699 /* This maybe reset or power control */ 697 /* This maybe reset or power control */
700 reg_write(gspca_dev->dev, 0x03, 0x03, 0x20); 698 reg_write(gspca_dev, 0x03, 0x03, 0x20);
701 reg_write(gspca_dev->dev, 0x03, 0x01, 0x00); 699 reg_write(gspca_dev, 0x03, 0x01, 0x00);
702 reg_write(gspca_dev->dev, 0x03, 0x00, 0x01); 700 reg_write(gspca_dev, 0x03, 0x00, 0x01);
703 reg_write(gspca_dev->dev, 0x05, 0x10, 0x01); 701 reg_write(gspca_dev, 0x05, 0x10, 0x01);
704 reg_write(gspca_dev->dev, 0x05, 0x11, 0x0f); 702 reg_write(gspca_dev, 0x05, 0x11, 0x0f);
705} 703}
706 704
707static void sd_pkt_scan(struct gspca_dev *gspca_dev, 705static void sd_pkt_scan(struct gspca_dev *gspca_dev,
diff --git a/drivers/media/usb/gspca/spca508.c b/drivers/media/usb/gspca/spca508.c
index 1286b4170b88..75f2beb2ea5a 100644
--- a/drivers/media/usb/gspca/spca508.c
+++ b/drivers/media/usb/gspca/spca508.c
@@ -1241,10 +1241,10 @@ static const u16 spca508_vista_init_data[][2] = {
1241 {} 1241 {}
1242}; 1242};
1243 1243
1244static int reg_write(struct usb_device *dev, 1244static int reg_write(struct gspca_dev *gspca_dev, u16 index, u16 value)
1245 u16 index, u16 value)
1246{ 1245{
1247 int ret; 1246 int ret;
1247 struct usb_device *dev = gspca_dev->dev;
1248 1248
1249 ret = usb_control_msg(dev, 1249 ret = usb_control_msg(dev,
1250 usb_sndctrlpipe(dev, 0), 1250 usb_sndctrlpipe(dev, 0),
@@ -1286,22 +1286,21 @@ static int reg_read(struct gspca_dev *gspca_dev,
1286static int ssi_w(struct gspca_dev *gspca_dev, 1286static int ssi_w(struct gspca_dev *gspca_dev,
1287 u16 reg, u16 val) 1287 u16 reg, u16 val)
1288{ 1288{
1289 struct usb_device *dev = gspca_dev->dev;
1290 int ret, retry; 1289 int ret, retry;
1291 1290
1292 ret = reg_write(dev, 0x8802, reg >> 8); 1291 ret = reg_write(gspca_dev, 0x8802, reg >> 8);
1293 if (ret < 0) 1292 if (ret < 0)
1294 goto out; 1293 goto out;
1295 ret = reg_write(dev, 0x8801, reg & 0x00ff); 1294 ret = reg_write(gspca_dev, 0x8801, reg & 0x00ff);
1296 if (ret < 0) 1295 if (ret < 0)
1297 goto out; 1296 goto out;
1298 if ((reg & 0xff00) == 0x1000) { /* if 2 bytes */ 1297 if ((reg & 0xff00) == 0x1000) { /* if 2 bytes */
1299 ret = reg_write(dev, 0x8805, val & 0x00ff); 1298 ret = reg_write(gspca_dev, 0x8805, val & 0x00ff);
1300 if (ret < 0) 1299 if (ret < 0)
1301 goto out; 1300 goto out;
1302 val >>= 8; 1301 val >>= 8;
1303 } 1302 }
1304 ret = reg_write(dev, 0x8800, val); 1303 ret = reg_write(gspca_dev, 0x8800, val);
1305 if (ret < 0) 1304 if (ret < 0)
1306 goto out; 1305 goto out;
1307 1306
@@ -1314,8 +1313,7 @@ static int ssi_w(struct gspca_dev *gspca_dev,
1314 if (gspca_dev->usb_buf[0] == 0) 1313 if (gspca_dev->usb_buf[0] == 0)
1315 break; 1314 break;
1316 if (--retry <= 0) { 1315 if (--retry <= 0) {
1317 PDEBUG(D_ERR, "ssi_w busy %02x", 1316 PERR("ssi_w busy %02x", gspca_dev->usb_buf[0]);
1318 gspca_dev->usb_buf[0]);
1319 ret = -1; 1317 ret = -1;
1320 break; 1318 break;
1321 } 1319 }
@@ -1329,7 +1327,6 @@ out:
1329static int write_vector(struct gspca_dev *gspca_dev, 1327static int write_vector(struct gspca_dev *gspca_dev,
1330 const u16 (*data)[2]) 1328 const u16 (*data)[2])
1331{ 1329{
1332 struct usb_device *dev = gspca_dev->dev;
1333 int ret = 0; 1330 int ret = 0;
1334 1331
1335 while ((*data)[1] != 0) { 1332 while ((*data)[1] != 0) {
@@ -1337,7 +1334,8 @@ static int write_vector(struct gspca_dev *gspca_dev,
1337 if ((*data)[1] == 0xdd00) /* delay */ 1334 if ((*data)[1] == 0xdd00) /* delay */
1338 msleep((*data)[0]); 1335 msleep((*data)[0]);
1339 else 1336 else
1340 ret = reg_write(dev, (*data)[1], (*data)[0]); 1337 ret = reg_write(gspca_dev, (*data)[1],
1338 (*data)[0]);
1341 } else { 1339 } else {
1342 ret = ssi_w(gspca_dev, (*data)[1], (*data)[0]); 1340 ret = ssi_w(gspca_dev, (*data)[1], (*data)[0]);
1343 } 1341 }
@@ -1363,8 +1361,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1363 spca508cs110_init_data, /* MicroInnovationIC200 4 */ 1361 spca508cs110_init_data, /* MicroInnovationIC200 4 */
1364 spca508_init_data, /* ViewQuestVQ110 5 */ 1362 spca508_init_data, /* ViewQuestVQ110 5 */
1365 }; 1363 };
1366
1367#ifdef GSPCA_DEBUG
1368 int data1, data2; 1364 int data1, data2;
1369 1365
1370 /* Read from global register the USB product and vendor IDs, just to 1366 /* Read from global register the USB product and vendor IDs, just to
@@ -1381,7 +1377,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1381 1377
1382 data1 = reg_read(gspca_dev, 0x8621); 1378 data1 = reg_read(gspca_dev, 0x8621);
1383 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1); 1379 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1);
1384#endif
1385 1380
1386 cam = &gspca_dev->cam; 1381 cam = &gspca_dev->cam;
1387 cam->cam_mode = sif_mode; 1382 cam->cam_mode = sif_mode;
@@ -1404,26 +1399,26 @@ static int sd_start(struct gspca_dev *gspca_dev)
1404 int mode; 1399 int mode;
1405 1400
1406 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 1401 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1407 reg_write(gspca_dev->dev, 0x8500, mode); 1402 reg_write(gspca_dev, 0x8500, mode);
1408 switch (mode) { 1403 switch (mode) {
1409 case 0: 1404 case 0:
1410 case 1: 1405 case 1:
1411 reg_write(gspca_dev->dev, 0x8700, 0x28); /* clock */ 1406 reg_write(gspca_dev, 0x8700, 0x28); /* clock */
1412 break; 1407 break;
1413 default: 1408 default:
1414/* case 2: */ 1409/* case 2: */
1415/* case 3: */ 1410/* case 3: */
1416 reg_write(gspca_dev->dev, 0x8700, 0x23); /* clock */ 1411 reg_write(gspca_dev, 0x8700, 0x23); /* clock */
1417 break; 1412 break;
1418 } 1413 }
1419 reg_write(gspca_dev->dev, 0x8112, 0x10 | 0x20); 1414 reg_write(gspca_dev, 0x8112, 0x10 | 0x20);
1420 return 0; 1415 return 0;
1421} 1416}
1422 1417
1423static void sd_stopN(struct gspca_dev *gspca_dev) 1418static void sd_stopN(struct gspca_dev *gspca_dev)
1424{ 1419{
1425 /* Video ISO disable, Video Drop Packet enable: */ 1420 /* Video ISO disable, Video Drop Packet enable: */
1426 reg_write(gspca_dev->dev, 0x8112, 0x20); 1421 reg_write(gspca_dev, 0x8112, 0x20);
1427} 1422}
1428 1423
1429static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1424static void sd_pkt_scan(struct gspca_dev *gspca_dev,
@@ -1450,10 +1445,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1450static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness) 1445static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
1451{ 1446{
1452 /* MX seem contrast */ 1447 /* MX seem contrast */
1453 reg_write(gspca_dev->dev, 0x8651, brightness); 1448 reg_write(gspca_dev, 0x8651, brightness);
1454 reg_write(gspca_dev->dev, 0x8652, brightness); 1449 reg_write(gspca_dev, 0x8652, brightness);
1455 reg_write(gspca_dev->dev, 0x8653, brightness); 1450 reg_write(gspca_dev, 0x8653, brightness);
1456 reg_write(gspca_dev->dev, 0x8654, brightness); 1451 reg_write(gspca_dev, 0x8654, brightness);
1457} 1452}
1458 1453
1459static int sd_s_ctrl(struct v4l2_ctrl *ctrl) 1454static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
diff --git a/drivers/media/usb/gspca/spca561.c b/drivers/media/usb/gspca/spca561.c
index d1db3d8f6522..403d71cd65d9 100644
--- a/drivers/media/usb/gspca/spca561.c
+++ b/drivers/media/usb/gspca/spca561.c
@@ -285,9 +285,10 @@ static const __u16 spca561_161rev12A_data2[][2] = {
285 {} 285 {}
286}; 286};
287 287
288static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value) 288static void reg_w_val(struct gspca_dev *gspca_dev, __u16 index, __u8 value)
289{ 289{
290 int ret; 290 int ret;
291 struct usb_device *dev = gspca_dev->dev;
291 292
292 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 293 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
293 0, /* request */ 294 0, /* request */
@@ -301,12 +302,11 @@ static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
301static void write_vector(struct gspca_dev *gspca_dev, 302static void write_vector(struct gspca_dev *gspca_dev,
302 const __u16 data[][2]) 303 const __u16 data[][2])
303{ 304{
304 struct usb_device *dev = gspca_dev->dev;
305 int i; 305 int i;
306 306
307 i = 0; 307 i = 0;
308 while (data[i][1] != 0) { 308 while (data[i][1] != 0) {
309 reg_w_val(dev, data[i][1], data[i][0]); 309 reg_w_val(gspca_dev, data[i][1], data[i][0]);
310 i++; 310 i++;
311 } 311 }
312} 312}
@@ -339,9 +339,9 @@ static void i2c_write(struct gspca_dev *gspca_dev, __u16 value, __u16 reg)
339{ 339{
340 int retry = 60; 340 int retry = 60;
341 341
342 reg_w_val(gspca_dev->dev, 0x8801, reg); 342 reg_w_val(gspca_dev, 0x8801, reg);
343 reg_w_val(gspca_dev->dev, 0x8805, value); 343 reg_w_val(gspca_dev, 0x8805, value);
344 reg_w_val(gspca_dev->dev, 0x8800, value >> 8); 344 reg_w_val(gspca_dev, 0x8800, value >> 8);
345 do { 345 do {
346 reg_r(gspca_dev, 0x8803, 1); 346 reg_r(gspca_dev, 0x8803, 1);
347 if (!gspca_dev->usb_buf[0]) 347 if (!gspca_dev->usb_buf[0])
@@ -355,9 +355,9 @@ static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
355 int retry = 60; 355 int retry = 60;
356 __u8 value; 356 __u8 value;
357 357
358 reg_w_val(gspca_dev->dev, 0x8804, 0x92); 358 reg_w_val(gspca_dev, 0x8804, 0x92);
359 reg_w_val(gspca_dev->dev, 0x8801, reg); 359 reg_w_val(gspca_dev, 0x8801, reg);
360 reg_w_val(gspca_dev->dev, 0x8802, mode | 0x01); 360 reg_w_val(gspca_dev, 0x8802, mode | 0x01);
361 do { 361 do {
362 reg_r(gspca_dev, 0x8803, 1); 362 reg_r(gspca_dev, 0x8803, 1);
363 if (!gspca_dev->usb_buf[0]) { 363 if (!gspca_dev->usb_buf[0]) {
@@ -459,14 +459,13 @@ static int sd_init_72a(struct gspca_dev *gspca_dev)
459 write_sensor_72a(gspca_dev, rev72a_init_sensor1); 459 write_sensor_72a(gspca_dev, rev72a_init_sensor1);
460 write_vector(gspca_dev, rev72a_init_data2); 460 write_vector(gspca_dev, rev72a_init_data2);
461 write_sensor_72a(gspca_dev, rev72a_init_sensor2); 461 write_sensor_72a(gspca_dev, rev72a_init_sensor2);
462 reg_w_val(gspca_dev->dev, 0x8112, 0x30); 462 reg_w_val(gspca_dev, 0x8112, 0x30);
463 return 0; 463 return 0;
464} 464}
465 465
466static void setbrightness(struct gspca_dev *gspca_dev, s32 val) 466static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
467{ 467{
468 struct sd *sd = (struct sd *) gspca_dev; 468 struct sd *sd = (struct sd *) gspca_dev;
469 struct usb_device *dev = gspca_dev->dev;
470 __u16 reg; 469 __u16 reg;
471 470
472 if (sd->chip_revision == Rev012A) 471 if (sd->chip_revision == Rev012A)
@@ -474,16 +473,15 @@ static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
474 else 473 else
475 reg = 0x8611; 474 reg = 0x8611;
476 475
477 reg_w_val(dev, reg + 0, val); /* R */ 476 reg_w_val(gspca_dev, reg + 0, val); /* R */
478 reg_w_val(dev, reg + 1, val); /* Gr */ 477 reg_w_val(gspca_dev, reg + 1, val); /* Gr */
479 reg_w_val(dev, reg + 2, val); /* B */ 478 reg_w_val(gspca_dev, reg + 2, val); /* B */
480 reg_w_val(dev, reg + 3, val); /* Gb */ 479 reg_w_val(gspca_dev, reg + 3, val); /* Gb */
481} 480}
482 481
483static void setwhite(struct gspca_dev *gspca_dev, s32 white, s32 contrast) 482static void setwhite(struct gspca_dev *gspca_dev, s32 white, s32 contrast)
484{ 483{
485 struct sd *sd = (struct sd *) gspca_dev; 484 struct sd *sd = (struct sd *) gspca_dev;
486 struct usb_device *dev = gspca_dev->dev;
487 __u8 blue, red; 485 __u8 blue, red;
488 __u16 reg; 486 __u16 reg;
489 487
@@ -496,11 +494,11 @@ static void setwhite(struct gspca_dev *gspca_dev, s32 white, s32 contrast)
496 reg = 0x8651; 494 reg = 0x8651;
497 red += contrast - 0x20; 495 red += contrast - 0x20;
498 blue += contrast - 0x20; 496 blue += contrast - 0x20;
499 reg_w_val(dev, 0x8652, contrast + 0x20); /* Gr */ 497 reg_w_val(gspca_dev, 0x8652, contrast + 0x20); /* Gr */
500 reg_w_val(dev, 0x8654, contrast + 0x20); /* Gb */ 498 reg_w_val(gspca_dev, 0x8654, contrast + 0x20); /* Gb */
501 } 499 }
502 reg_w_val(dev, reg, red); 500 reg_w_val(gspca_dev, reg, red);
503 reg_w_val(dev, reg + 2, blue); 501 reg_w_val(gspca_dev, reg + 2, blue);
504} 502}
505 503
506/* rev 12a only */ 504/* rev 12a only */
@@ -570,7 +568,6 @@ static void setautogain(struct gspca_dev *gspca_dev, s32 val)
570 568
571static int sd_start_12a(struct gspca_dev *gspca_dev) 569static int sd_start_12a(struct gspca_dev *gspca_dev)
572{ 570{
573 struct usb_device *dev = gspca_dev->dev;
574 int mode; 571 int mode;
575 static const __u8 Reg8391[8] = 572 static const __u8 Reg8391[8] =
576 {0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00}; 573 {0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00};
@@ -578,34 +575,33 @@ static int sd_start_12a(struct gspca_dev *gspca_dev)
578 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 575 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
579 if (mode <= 1) { 576 if (mode <= 1) {
580 /* Use compression on 320x240 and above */ 577 /* Use compression on 320x240 and above */
581 reg_w_val(dev, 0x8500, 0x10 | mode); 578 reg_w_val(gspca_dev, 0x8500, 0x10 | mode);
582 } else { 579 } else {
583 /* I couldn't get the compression to work below 320x240 580 /* I couldn't get the compression to work below 320x240
584 * Fortunately at these resolutions the bandwidth 581 * Fortunately at these resolutions the bandwidth
585 * is sufficient to push raw frames at ~20fps */ 582 * is sufficient to push raw frames at ~20fps */
586 reg_w_val(dev, 0x8500, mode); 583 reg_w_val(gspca_dev, 0x8500, mode);
587 } /* -- qq@kuku.eu.org */ 584 } /* -- qq@kuku.eu.org */
588 585
589 gspca_dev->usb_buf[0] = 0xaa; 586 gspca_dev->usb_buf[0] = 0xaa;
590 gspca_dev->usb_buf[1] = 0x00; 587 gspca_dev->usb_buf[1] = 0x00;
591 reg_w_buf(gspca_dev, 0x8307, 2); 588 reg_w_buf(gspca_dev, 0x8307, 2);
592 /* clock - lower 0x8X values lead to fps > 30 */ 589 /* clock - lower 0x8X values lead to fps > 30 */
593 reg_w_val(gspca_dev->dev, 0x8700, 0x8a); 590 reg_w_val(gspca_dev, 0x8700, 0x8a);
594 /* 0x8f 0x85 0x27 clock */ 591 /* 0x8f 0x85 0x27 clock */
595 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20); 592 reg_w_val(gspca_dev, 0x8112, 0x1e | 0x20);
596 reg_w_val(gspca_dev->dev, 0x850b, 0x03); 593 reg_w_val(gspca_dev, 0x850b, 0x03);
597 memcpy(gspca_dev->usb_buf, Reg8391, 8); 594 memcpy(gspca_dev->usb_buf, Reg8391, 8);
598 reg_w_buf(gspca_dev, 0x8391, 8); 595 reg_w_buf(gspca_dev, 0x8391, 8);
599 reg_w_buf(gspca_dev, 0x8390, 8); 596 reg_w_buf(gspca_dev, 0x8390, 8);
600 597
601 /* Led ON (bit 3 -> 0 */ 598 /* Led ON (bit 3 -> 0 */
602 reg_w_val(gspca_dev->dev, 0x8114, 0x00); 599 reg_w_val(gspca_dev, 0x8114, 0x00);
603 return 0; 600 return 0;
604} 601}
605static int sd_start_72a(struct gspca_dev *gspca_dev) 602static int sd_start_72a(struct gspca_dev *gspca_dev)
606{ 603{
607 struct sd *sd = (struct sd *) gspca_dev; 604 struct sd *sd = (struct sd *) gspca_dev;
608 struct usb_device *dev = gspca_dev->dev;
609 int Clck; 605 int Clck;
610 int mode; 606 int mode;
611 607
@@ -630,15 +626,15 @@ static int sd_start_72a(struct gspca_dev *gspca_dev)
630 Clck = 0x21; 626 Clck = 0x21;
631 break; 627 break;
632 } 628 }
633 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */ 629 reg_w_val(gspca_dev, 0x8700, Clck); /* 0x27 clock */
634 reg_w_val(dev, 0x8702, 0x81); 630 reg_w_val(gspca_dev, 0x8702, 0x81);
635 reg_w_val(dev, 0x8500, mode); /* mode */ 631 reg_w_val(gspca_dev, 0x8500, mode); /* mode */
636 write_sensor_72a(gspca_dev, rev72a_init_sensor2); 632 write_sensor_72a(gspca_dev, rev72a_init_sensor2);
637 setwhite(gspca_dev, v4l2_ctrl_g_ctrl(sd->hue), 633 setwhite(gspca_dev, v4l2_ctrl_g_ctrl(sd->hue),
638 v4l2_ctrl_g_ctrl(sd->contrast)); 634 v4l2_ctrl_g_ctrl(sd->contrast));
639/* setbrightness(gspca_dev); * fixme: bad values */ 635/* setbrightness(gspca_dev); * fixme: bad values */
640 setautogain(gspca_dev, v4l2_ctrl_g_ctrl(sd->autogain)); 636 setautogain(gspca_dev, v4l2_ctrl_g_ctrl(sd->autogain));
641 reg_w_val(dev, 0x8112, 0x10 | 0x20); 637 reg_w_val(gspca_dev, 0x8112, 0x10 | 0x20);
642 return 0; 638 return 0;
643} 639}
644 640
@@ -647,12 +643,12 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
647 struct sd *sd = (struct sd *) gspca_dev; 643 struct sd *sd = (struct sd *) gspca_dev;
648 644
649 if (sd->chip_revision == Rev012A) { 645 if (sd->chip_revision == Rev012A) {
650 reg_w_val(gspca_dev->dev, 0x8112, 0x0e); 646 reg_w_val(gspca_dev, 0x8112, 0x0e);
651 /* Led Off (bit 3 -> 1 */ 647 /* Led Off (bit 3 -> 1 */
652 reg_w_val(gspca_dev->dev, 0x8114, 0x08); 648 reg_w_val(gspca_dev, 0x8114, 0x08);
653 } else { 649 } else {
654 reg_w_val(gspca_dev->dev, 0x8112, 0x20); 650 reg_w_val(gspca_dev, 0x8112, 0x20);
655/* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */ 651/* reg_w_val(gspca_dev, 0x8102, 0x00); ?? */
656 } 652 }
657} 653}
658 654
@@ -736,7 +732,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
736 732
737 /* This should never happen */ 733 /* This should never happen */
738 if (len < 2) { 734 if (len < 2) {
739 PDEBUG(D_ERR, "Short SOF packet, ignoring"); 735 PERR("Short SOF packet, ignoring");
740 gspca_dev->last_packet_type = DISCARD_PACKET; 736 gspca_dev->last_packet_type = DISCARD_PACKET;
741 return; 737 return;
742 } 738 }
diff --git a/drivers/media/usb/gspca/sq905.c b/drivers/media/usb/gspca/sq905.c
index 1d99f10a3e19..a7ae0ec9fa91 100644
--- a/drivers/media/usb/gspca/sq905.c
+++ b/drivers/media/usb/gspca/sq905.c
@@ -387,7 +387,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
387 } 387 }
388 388
389 if (ret < 0) { 389 if (ret < 0) {
390 PDEBUG(D_ERR, "Start streaming command failed"); 390 PERR("Start streaming command failed");
391 return ret; 391 return ret;
392 } 392 }
393 /* Start the workqueue function to do the streaming */ 393 /* Start the workqueue function to do the streaming */
diff --git a/drivers/media/usb/gspca/sq905c.c b/drivers/media/usb/gspca/sq905c.c
index 410cdcbb55d4..acb19fb9a3df 100644
--- a/drivers/media/usb/gspca/sq905c.c
+++ b/drivers/media/usb/gspca/sq905c.c
@@ -215,13 +215,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
215 215
216 ret = sq905c_command(gspca_dev, SQ905C_GET_ID, 0); 216 ret = sq905c_command(gspca_dev, SQ905C_GET_ID, 0);
217 if (ret < 0) { 217 if (ret < 0) {
218 PDEBUG(D_ERR, "Get version command failed"); 218 PERR("Get version command failed");
219 return ret; 219 return ret;
220 } 220 }
221 221
222 ret = sq905c_read(gspca_dev, 0xf5, 0, 20); 222 ret = sq905c_read(gspca_dev, 0xf5, 0, 20);
223 if (ret < 0) { 223 if (ret < 0) {
224 PDEBUG(D_ERR, "Reading version command failed"); 224 PERR("Reading version command failed");
225 return ret; 225 return ret;
226 } 226 }
227 /* Note we leave out the usb id and the manufacturing date */ 227 /* Note we leave out the usb id and the manufacturing date */
@@ -286,7 +286,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
286 } 286 }
287 287
288 if (ret < 0) { 288 if (ret < 0) {
289 PDEBUG(D_ERR, "Start streaming command failed"); 289 PERR("Start streaming command failed");
290 return ret; 290 return ret;
291 } 291 }
292 /* Start the workqueue function to do the streaming */ 292 /* Start the workqueue function to do the streaming */
diff --git a/drivers/media/usb/gspca/sq930x.c b/drivers/media/usb/gspca/sq930x.c
index 7e8748b31e85..b10d0821111c 100644
--- a/drivers/media/usb/gspca/sq930x.c
+++ b/drivers/media/usb/gspca/sq930x.c
@@ -541,13 +541,11 @@ static void ucbus_write(struct gspca_dev *gspca_dev,
541 if (gspca_dev->usb_err < 0) 541 if (gspca_dev->usb_err < 0)
542 return; 542 return;
543 543
544#ifdef GSPCA_DEBUG
545 if ((batchsize - 1) * 3 > USB_BUF_SZ) { 544 if ((batchsize - 1) * 3 > USB_BUF_SZ) {
546 pr_err("Bug: usb_buf overflow\n"); 545 PERR("Bug: usb_buf overflow\n");
547 gspca_dev->usb_err = -ENOMEM; 546 gspca_dev->usb_err = -ENOMEM;
548 return; 547 return;
549 } 548 }
550#endif
551 549
552 for (;;) { 550 for (;;) {
553 len = ncmds; 551 len = ncmds;
diff --git a/drivers/media/usb/gspca/stv0680.c b/drivers/media/usb/gspca/stv0680.c
index 67605272aaa8..9c0827631b9c 100644
--- a/drivers/media/usb/gspca/stv0680.c
+++ b/drivers/media/usb/gspca/stv0680.c
@@ -86,7 +86,7 @@ static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val,
86static int stv0680_handle_error(struct gspca_dev *gspca_dev, int ret) 86static int stv0680_handle_error(struct gspca_dev *gspca_dev, int ret)
87{ 87{
88 stv_sndctrl(gspca_dev, 0, 0x80, 0, 0x02); /* Get Last Error */ 88 stv_sndctrl(gspca_dev, 0, 0x80, 0, 0x02); /* Get Last Error */
89 PDEBUG(D_ERR, "last error: %i, command = 0x%x", 89 PERR("last error: %i, command = 0x%x",
90 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]); 90 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
91 return ret; 91 return ret;
92} 92}
@@ -98,7 +98,7 @@ static int stv0680_get_video_mode(struct gspca_dev *gspca_dev)
98 gspca_dev->usb_buf[0] = 0x0f; 98 gspca_dev->usb_buf[0] = 0x0f;
99 99
100 if (stv_sndctrl(gspca_dev, 0, 0x87, 0, 0x08) != 0x08) { 100 if (stv_sndctrl(gspca_dev, 0, 0x87, 0, 0x08) != 0x08) {
101 PDEBUG(D_ERR, "Get_Camera_Mode failed"); 101 PERR("Get_Camera_Mode failed");
102 return stv0680_handle_error(gspca_dev, -EIO); 102 return stv0680_handle_error(gspca_dev, -EIO);
103 } 103 }
104 104
@@ -116,13 +116,13 @@ static int stv0680_set_video_mode(struct gspca_dev *gspca_dev, u8 mode)
116 gspca_dev->usb_buf[0] = mode; 116 gspca_dev->usb_buf[0] = mode;
117 117
118 if (stv_sndctrl(gspca_dev, 3, 0x07, 0x0100, 0x08) != 0x08) { 118 if (stv_sndctrl(gspca_dev, 3, 0x07, 0x0100, 0x08) != 0x08) {
119 PDEBUG(D_ERR, "Set_Camera_Mode failed"); 119 PERR("Set_Camera_Mode failed");
120 return stv0680_handle_error(gspca_dev, -EIO); 120 return stv0680_handle_error(gspca_dev, -EIO);
121 } 121 }
122 122
123 /* Verify we got what we've asked for */ 123 /* Verify we got what we've asked for */
124 if (stv0680_get_video_mode(gspca_dev) != mode) { 124 if (stv0680_get_video_mode(gspca_dev) != mode) {
125 PDEBUG(D_ERR, "Error setting camera video mode!"); 125 PERR("Error setting camera video mode!");
126 return -EIO; 126 return -EIO;
127 } 127 }
128 128
@@ -146,7 +146,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
146 /* ping camera to be sure STV0680 is present */ 146 /* ping camera to be sure STV0680 is present */
147 if (stv_sndctrl(gspca_dev, 0, 0x88, 0x5678, 0x02) != 0x02 || 147 if (stv_sndctrl(gspca_dev, 0, 0x88, 0x5678, 0x02) != 0x02 ||
148 gspca_dev->usb_buf[0] != 0x56 || gspca_dev->usb_buf[1] != 0x78) { 148 gspca_dev->usb_buf[0] != 0x56 || gspca_dev->usb_buf[1] != 0x78) {
149 PDEBUG(D_ERR, "STV(e): camera ping failed!!"); 149 PERR("STV(e): camera ping failed!!");
150 return stv0680_handle_error(gspca_dev, -ENODEV); 150 return stv0680_handle_error(gspca_dev, -ENODEV);
151 } 151 }
152 152
@@ -156,7 +156,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
156 156
157 if (stv_sndctrl(gspca_dev, 2, 0x06, 0x0200, 0x22) != 0x22 || 157 if (stv_sndctrl(gspca_dev, 2, 0x06, 0x0200, 0x22) != 0x22 ||
158 gspca_dev->usb_buf[7] != 0xa0 || gspca_dev->usb_buf[8] != 0x23) { 158 gspca_dev->usb_buf[7] != 0xa0 || gspca_dev->usb_buf[8] != 0x23) {
159 PDEBUG(D_ERR, "Could not get descriptor 0200."); 159 PERR("Could not get descriptor 0200.");
160 return stv0680_handle_error(gspca_dev, -ENODEV); 160 return stv0680_handle_error(gspca_dev, -ENODEV);
161 } 161 }
162 if (stv_sndctrl(gspca_dev, 0, 0x8a, 0, 0x02) != 0x02) 162 if (stv_sndctrl(gspca_dev, 0, 0x8a, 0, 0x02) != 0x02)
@@ -167,7 +167,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
167 return stv0680_handle_error(gspca_dev, -ENODEV); 167 return stv0680_handle_error(gspca_dev, -ENODEV);
168 168
169 if (!(gspca_dev->usb_buf[7] & 0x09)) { 169 if (!(gspca_dev->usb_buf[7] & 0x09)) {
170 PDEBUG(D_ERR, "Camera supports neither CIF nor QVGA mode"); 170 PERR("Camera supports neither CIF nor QVGA mode");
171 return -ENODEV; 171 return -ENODEV;
172 } 172 }
173 if (gspca_dev->usb_buf[7] & 0x01) 173 if (gspca_dev->usb_buf[7] & 0x01)
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx.c b/drivers/media/usb/gspca/stv06xx/stv06xx.c
index 657160b4a1f7..55ee7a61c67f 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c
@@ -42,8 +42,10 @@ static bool dump_sensor;
42int stv06xx_write_bridge(struct sd *sd, u16 address, u16 i2c_data) 42int stv06xx_write_bridge(struct sd *sd, u16 address, u16 i2c_data)
43{ 43{
44 int err; 44 int err;
45 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
45 struct usb_device *udev = sd->gspca_dev.dev; 46 struct usb_device *udev = sd->gspca_dev.dev;
46 __u8 *buf = sd->gspca_dev.usb_buf; 47 __u8 *buf = sd->gspca_dev.usb_buf;
48
47 u8 len = (i2c_data > 0xff) ? 2 : 1; 49 u8 len = (i2c_data > 0xff) ? 2 : 1;
48 50
49 buf[0] = i2c_data & 0xff; 51 buf[0] = i2c_data & 0xff;
@@ -62,6 +64,7 @@ int stv06xx_write_bridge(struct sd *sd, u16 address, u16 i2c_data)
62int stv06xx_read_bridge(struct sd *sd, u16 address, u8 *i2c_data) 64int stv06xx_read_bridge(struct sd *sd, u16 address, u8 *i2c_data)
63{ 65{
64 int err; 66 int err;
67 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
65 struct usb_device *udev = sd->gspca_dev.dev; 68 struct usb_device *udev = sd->gspca_dev.dev;
66 __u8 *buf = sd->gspca_dev.usb_buf; 69 __u8 *buf = sd->gspca_dev.usb_buf;
67 70
@@ -110,6 +113,7 @@ static int stv06xx_write_sensor_finish(struct sd *sd)
110int stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len) 113int stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len)
111{ 114{
112 int err, i, j; 115 int err, i, j;
116 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
113 struct usb_device *udev = sd->gspca_dev.dev; 117 struct usb_device *udev = sd->gspca_dev.dev;
114 __u8 *buf = sd->gspca_dev.usb_buf; 118 __u8 *buf = sd->gspca_dev.usb_buf;
115 119
@@ -139,6 +143,7 @@ int stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len)
139int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len) 143int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len)
140{ 144{
141 int err, i, j; 145 int err, i, j;
146 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
142 struct usb_device *udev = sd->gspca_dev.dev; 147 struct usb_device *udev = sd->gspca_dev.dev;
143 __u8 *buf = sd->gspca_dev.usb_buf; 148 __u8 *buf = sd->gspca_dev.usb_buf;
144 149
@@ -170,6 +175,7 @@ int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len)
170int stv06xx_read_sensor(struct sd *sd, const u8 address, u16 *value) 175int stv06xx_read_sensor(struct sd *sd, const u8 address, u16 *value)
171{ 176{
172 int err; 177 int err;
178 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
173 struct usb_device *udev = sd->gspca_dev.dev; 179 struct usb_device *udev = sd->gspca_dev.dev;
174 __u8 *buf = sd->gspca_dev.usb_buf; 180 __u8 *buf = sd->gspca_dev.usb_buf;
175 181
@@ -283,7 +289,7 @@ static int stv06xx_start(struct gspca_dev *gspca_dev)
283 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); 289 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
284 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 290 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
285 if (!alt) { 291 if (!alt) {
286 PDEBUG(D_ERR, "Couldn't get altsetting"); 292 PERR("Couldn't get altsetting");
287 return -EIO; 293 return -EIO;
288 } 294 }
289 295
@@ -341,7 +347,7 @@ static int stv06xx_isoc_nego(struct gspca_dev *gspca_dev)
341 347
342 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); 348 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
343 if (ret < 0) 349 if (ret < 0)
344 PDEBUG(D_ERR|D_STREAM, "set alt 1 err %d", ret); 350 PERR("set alt 1 err %d", ret);
345 351
346 return ret; 352 return ret;
347} 353}
@@ -406,7 +412,7 @@ static void stv06xx_pkt_scan(struct gspca_dev *gspca_dev,
406 len -= 4; 412 len -= 4;
407 413
408 if (len < chunk_len) { 414 if (len < chunk_len) {
409 PDEBUG(D_ERR, "URB packet length is smaller" 415 PERR("URB packet length is smaller"
410 " than the specified chunk length"); 416 " than the specified chunk length");
411 gspca_dev->last_packet_type = DISCARD_PACKET; 417 gspca_dev->last_packet_type = DISCARD_PACKET;
412 return; 418 return;
@@ -449,7 +455,7 @@ frame_data:
449 sd->to_skip = gspca_dev->width * 4; 455 sd->to_skip = gspca_dev->width * 4;
450 456
451 if (chunk_len) 457 if (chunk_len)
452 PDEBUG(D_ERR, "Chunk length is " 458 PERR("Chunk length is "
453 "non-zero on a SOF"); 459 "non-zero on a SOF");
454 break; 460 break;
455 461
@@ -463,7 +469,7 @@ frame_data:
463 NULL, 0); 469 NULL, 0);
464 470
465 if (chunk_len) 471 if (chunk_len)
466 PDEBUG(D_ERR, "Chunk length is " 472 PERR("Chunk length is "
467 "non-zero on a EOF"); 473 "non-zero on a EOF");
468 break; 474 break;
469 475
@@ -596,7 +602,6 @@ MODULE_DEVICE_TABLE(usb, device_table);
596static int sd_probe(struct usb_interface *intf, 602static int sd_probe(struct usb_interface *intf,
597 const struct usb_device_id *id) 603 const struct usb_device_id *id)
598{ 604{
599 PDEBUG(D_PROBE, "Probing for a stv06xx device");
600 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), 605 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
601 THIS_MODULE); 606 THIS_MODULE);
602} 607}
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx_hdcs.c b/drivers/media/usb/gspca/stv06xx/stv06xx_hdcs.c
index 06fa54c5efb2..2220b70d47e6 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx_hdcs.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx_hdcs.c
@@ -255,7 +255,7 @@ static int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
255 if (err < 0) 255 if (err < 0)
256 return err; 256 return err;
257 } 257 }
258 PDEBUG(D_V4L2, "Writing exposure %d, rowexp %d, srowexp %d", 258 PDEBUG(D_CONF, "Writing exposure %d, rowexp %d, srowexp %d",
259 val, rowexp, srowexp); 259 val, rowexp, srowexp);
260 return err; 260 return err;
261} 261}
@@ -280,7 +280,7 @@ static int hdcs_set_gains(struct sd *sd, u8 g)
280 280
281static int hdcs_set_gain(struct gspca_dev *gspca_dev, __s32 val) 281static int hdcs_set_gain(struct gspca_dev *gspca_dev, __s32 val)
282{ 282{
283 PDEBUG(D_V4L2, "Writing gain %d", val); 283 PDEBUG(D_CONF, "Writing gain %d", val);
284 return hdcs_set_gains((struct sd *) gspca_dev, 284 return hdcs_set_gains((struct sd *) gspca_dev,
285 val & 0xff); 285 val & 0xff);
286} 286}
@@ -467,6 +467,8 @@ static int hdcs_probe_1020(struct sd *sd)
467 467
468static int hdcs_start(struct sd *sd) 468static int hdcs_start(struct sd *sd)
469{ 469{
470 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
471
470 PDEBUG(D_STREAM, "Starting stream"); 472 PDEBUG(D_STREAM, "Starting stream");
471 473
472 return hdcs_set_state(sd, HDCS_STATE_RUN); 474 return hdcs_set_state(sd, HDCS_STATE_RUN);
@@ -474,6 +476,8 @@ static int hdcs_start(struct sd *sd)
474 476
475static int hdcs_stop(struct sd *sd) 477static int hdcs_stop(struct sd *sd)
476{ 478{
479 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
480
477 PDEBUG(D_STREAM, "Halting stream"); 481 PDEBUG(D_STREAM, "Halting stream");
478 482
479 return hdcs_set_state(sd, HDCS_STATE_SLEEP); 483 return hdcs_set_state(sd, HDCS_STATE_SLEEP);
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c b/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
index cdfc3d05ab6b..8206b7743300 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
@@ -190,6 +190,7 @@ static int pb0100_start(struct sd *sd)
190 int err, packet_size, max_packet_size; 190 int err, packet_size, max_packet_size;
191 struct usb_host_interface *alt; 191 struct usb_host_interface *alt;
192 struct usb_interface *intf; 192 struct usb_interface *intf;
193 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
193 struct cam *cam = &sd->gspca_dev.cam; 194 struct cam *cam = &sd->gspca_dev.cam;
194 u32 mode = cam->cam_mode[sd->gspca_dev.curr_mode].priv; 195 u32 mode = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
195 196
@@ -239,6 +240,7 @@ static int pb0100_start(struct sd *sd)
239 240
240static int pb0100_stop(struct sd *sd) 241static int pb0100_stop(struct sd *sd)
241{ 242{
243 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
242 int err; 244 int err;
243 245
244 err = stv06xx_write_sensor(sd, PB_ABORTFRAME, 1); 246 err = stv06xx_write_sensor(sd, PB_ABORTFRAME, 1);
@@ -334,7 +336,7 @@ static int pb0100_set_gain(struct gspca_dev *gspca_dev, __s32 val)
334 err = stv06xx_write_sensor(sd, PB_G1GAIN, val); 336 err = stv06xx_write_sensor(sd, PB_G1GAIN, val);
335 if (!err) 337 if (!err)
336 err = stv06xx_write_sensor(sd, PB_G2GAIN, val); 338 err = stv06xx_write_sensor(sd, PB_G2GAIN, val);
337 PDEBUG(D_V4L2, "Set green gain to %d, status: %d", val, err); 339 PDEBUG(D_CONF, "Set green gain to %d, status: %d", val, err);
338 340
339 if (!err) 341 if (!err)
340 err = pb0100_set_red_balance(gspca_dev, ctrls->red->val); 342 err = pb0100_set_red_balance(gspca_dev, ctrls->red->val);
@@ -357,7 +359,7 @@ static int pb0100_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
357 val = 255; 359 val = 255;
358 360
359 err = stv06xx_write_sensor(sd, PB_RGAIN, val); 361 err = stv06xx_write_sensor(sd, PB_RGAIN, val);
360 PDEBUG(D_V4L2, "Set red gain to %d, status: %d", val, err); 362 PDEBUG(D_CONF, "Set red gain to %d, status: %d", val, err);
361 363
362 return err; 364 return err;
363} 365}
@@ -375,7 +377,7 @@ static int pb0100_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
375 val = 255; 377 val = 255;
376 378
377 err = stv06xx_write_sensor(sd, PB_BGAIN, val); 379 err = stv06xx_write_sensor(sd, PB_BGAIN, val);
378 PDEBUG(D_V4L2, "Set blue gain to %d, status: %d", val, err); 380 PDEBUG(D_CONF, "Set blue gain to %d, status: %d", val, err);
379 381
380 return err; 382 return err;
381} 383}
@@ -386,7 +388,7 @@ static int pb0100_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
386 int err; 388 int err;
387 389
388 err = stv06xx_write_sensor(sd, PB_RINTTIME, val); 390 err = stv06xx_write_sensor(sd, PB_RINTTIME, val);
389 PDEBUG(D_V4L2, "Set exposure to %d, status: %d", val, err); 391 PDEBUG(D_CONF, "Set exposure to %d, status: %d", val, err);
390 392
391 return err; 393 return err;
392} 394}
@@ -406,7 +408,7 @@ static int pb0100_set_autogain(struct gspca_dev *gspca_dev, __s32 val)
406 val = 0; 408 val = 0;
407 409
408 err = stv06xx_write_sensor(sd, PB_EXPGAIN, val); 410 err = stv06xx_write_sensor(sd, PB_EXPGAIN, val);
409 PDEBUG(D_V4L2, "Set autogain to %d (natural: %d), status: %d", 411 PDEBUG(D_CONF, "Set autogain to %d (natural: %d), status: %d",
410 val, ctrls->natural->val, err); 412 val, ctrls->natural->val, err);
411 413
412 return err; 414 return err;
@@ -428,7 +430,7 @@ static int pb0100_set_autogain_target(struct gspca_dev *gspca_dev, __s32 val)
428 if (!err) 430 if (!err)
429 err = stv06xx_write_sensor(sd, PB_R22, darkpixels); 431 err = stv06xx_write_sensor(sd, PB_R22, darkpixels);
430 432
431 PDEBUG(D_V4L2, "Set autogain target to %d, status: %d", val, err); 433 PDEBUG(D_CONF, "Set autogain target to %d, status: %d", val, err);
432 434
433 return err; 435 return err;
434} 436}
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx_st6422.c b/drivers/media/usb/gspca/stv06xx/stv06xx_st6422.c
index 8a57990dfe0f..515a9e121653 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx_st6422.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx_st6422.c
@@ -279,6 +279,8 @@ static int st6422_start(struct sd *sd)
279 279
280static int st6422_stop(struct sd *sd) 280static int st6422_stop(struct sd *sd)
281{ 281{
282 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
283
282 PDEBUG(D_STREAM, "Halting stream"); 284 PDEBUG(D_STREAM, "Halting stream");
283 285
284 return 0; 286 return 0;
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c b/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c
index e95fa8997d22..bf3e5c317a26 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c
@@ -131,6 +131,7 @@ static int vv6410_init(struct sd *sd)
131static int vv6410_start(struct sd *sd) 131static int vv6410_start(struct sd *sd)
132{ 132{
133 int err; 133 int err;
134 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
134 struct cam *cam = &sd->gspca_dev.cam; 135 struct cam *cam = &sd->gspca_dev.cam;
135 u32 priv = cam->cam_mode[sd->gspca_dev.curr_mode].priv; 136 u32 priv = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
136 137
@@ -163,6 +164,7 @@ static int vv6410_start(struct sd *sd)
163 164
164static int vv6410_stop(struct sd *sd) 165static int vv6410_stop(struct sd *sd)
165{ 166{
167 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
166 int err; 168 int err;
167 169
168 /* Turn off LED */ 170 /* Turn off LED */
@@ -208,7 +210,7 @@ static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
208 else 210 else
209 i2c_data &= ~VV6410_HFLIP; 211 i2c_data &= ~VV6410_HFLIP;
210 212
211 PDEBUG(D_V4L2, "Set horizontal flip to %d", val); 213 PDEBUG(D_CONF, "Set horizontal flip to %d", val);
212 err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data); 214 err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data);
213 215
214 return (err < 0) ? err : 0; 216 return (err < 0) ? err : 0;
@@ -229,7 +231,7 @@ static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
229 else 231 else
230 i2c_data &= ~VV6410_VFLIP; 232 i2c_data &= ~VV6410_VFLIP;
231 233
232 PDEBUG(D_V4L2, "Set vertical flip to %d", val); 234 PDEBUG(D_CONF, "Set vertical flip to %d", val);
233 err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data); 235 err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data);
234 236
235 return (err < 0) ? err : 0; 237 return (err < 0) ? err : 0;
@@ -240,7 +242,7 @@ static int vv6410_set_analog_gain(struct gspca_dev *gspca_dev, __s32 val)
240 int err; 242 int err;
241 struct sd *sd = (struct sd *) gspca_dev; 243 struct sd *sd = (struct sd *) gspca_dev;
242 244
243 PDEBUG(D_V4L2, "Set analog gain to %d", val); 245 PDEBUG(D_CONF, "Set analog gain to %d", val);
244 err = stv06xx_write_sensor(sd, VV6410_ANALOGGAIN, 0xf0 | (val & 0xf)); 246 err = stv06xx_write_sensor(sd, VV6410_ANALOGGAIN, 0xf0 | (val & 0xf));
245 247
246 return (err < 0) ? err : 0; 248 return (err < 0) ? err : 0;
@@ -257,7 +259,7 @@ static int vv6410_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
257 fine = val % VV6410_CIF_LINELENGTH; 259 fine = val % VV6410_CIF_LINELENGTH;
258 coarse = min(512, val / VV6410_CIF_LINELENGTH); 260 coarse = min(512, val / VV6410_CIF_LINELENGTH);
259 261
260 PDEBUG(D_V4L2, "Set coarse exposure to %d, fine expsure to %d", 262 PDEBUG(D_CONF, "Set coarse exposure to %d, fine expsure to %d",
261 coarse, fine); 263 coarse, fine);
262 264
263 err = stv06xx_write_sensor(sd, VV6410_FINEH, fine >> 8); 265 err = stv06xx_write_sensor(sd, VV6410_FINEH, fine >> 8);
diff --git a/drivers/media/usb/gspca/sunplus.c b/drivers/media/usb/gspca/sunplus.c
index 9ccfcb1c6479..af8767a9bd4c 100644
--- a/drivers/media/usb/gspca/sunplus.c
+++ b/drivers/media/usb/gspca/sunplus.c
@@ -251,12 +251,10 @@ static void reg_r(struct gspca_dev *gspca_dev,
251{ 251{
252 int ret; 252 int ret;
253 253
254#ifdef GSPCA_DEBUG
255 if (len > USB_BUF_SZ) { 254 if (len > USB_BUF_SZ) {
256 pr_err("reg_r: buffer overflow\n"); 255 PERR("reg_r: buffer overflow\n");
257 return; 256 return;
258 } 257 }
259#endif
260 if (gspca_dev->usb_err < 0) 258 if (gspca_dev->usb_err < 0)
261 return; 259 return;
262 ret = usb_control_msg(gspca_dev->dev, 260 ret = usb_control_msg(gspca_dev->dev,
@@ -357,12 +355,14 @@ static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
357 PDEBUG(D_FRAM, "after wait 0x%04x", gspca_dev->usb_buf[0]); 355 PDEBUG(D_FRAM, "after wait 0x%04x", gspca_dev->usb_buf[0]);
358} 356}
359 357
360#ifdef GSPCA_DEBUG
361static void spca504_read_info(struct gspca_dev *gspca_dev) 358static void spca504_read_info(struct gspca_dev *gspca_dev)
362{ 359{
363 int i; 360 int i;
364 u8 info[6]; 361 u8 info[6];
365 362
363 if (gspca_debug < D_STREAM)
364 return;
365
366 for (i = 0; i < 6; i++) { 366 for (i = 0; i < 6; i++) {
367 reg_r(gspca_dev, 0, i, 1); 367 reg_r(gspca_dev, 0, i, 1);
368 info[i] = gspca_dev->usb_buf[0]; 368 info[i] = gspca_dev->usb_buf[0];
@@ -373,7 +373,6 @@ static void spca504_read_info(struct gspca_dev *gspca_dev)
373 info[0], info[1], info[2], 373 info[0], info[1], info[2],
374 info[3], info[4], info[5]); 374 info[3], info[4], info[5]);
375} 375}
376#endif
377 376
378static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, 377static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
379 u8 req, 378 u8 req,
@@ -432,11 +431,13 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
432 } 431 }
433} 432}
434 433
435#ifdef GSPCA_DEBUG
436static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) 434static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
437{ 435{
438 u8 *data; 436 u8 *data;
439 437
438 if (gspca_debug < D_STREAM)
439 return;
440
440 data = gspca_dev->usb_buf; 441 data = gspca_dev->usb_buf;
441 reg_r(gspca_dev, 0x20, 0, 5); 442 reg_r(gspca_dev, 0x20, 0, 5);
442 PDEBUG(D_STREAM, "FirmWare: %d %d %d %d %d", 443 PDEBUG(D_STREAM, "FirmWare: %d %d %d %d %d",
@@ -444,7 +445,6 @@ static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
444 reg_r(gspca_dev, 0x23, 0, 64); 445 reg_r(gspca_dev, 0x23, 0, 64);
445 reg_r(gspca_dev, 0x23, 1, 64); 446 reg_r(gspca_dev, 0x23, 1, 64);
446} 447}
447#endif
448 448
449static void spca504B_SetSizeType(struct gspca_dev *gspca_dev) 449static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
450{ 450{
@@ -457,9 +457,8 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
457 reg_w_riv(gspca_dev, 0x31, 0, 0); 457 reg_w_riv(gspca_dev, 0x31, 0, 0);
458 spca504B_WaitCmdStatus(gspca_dev); 458 spca504B_WaitCmdStatus(gspca_dev);
459 spca504B_PollingDataReady(gspca_dev); 459 spca504B_PollingDataReady(gspca_dev);
460#ifdef GSPCA_DEBUG
461 spca50x_GetFirmware(gspca_dev); 460 spca50x_GetFirmware(gspca_dev);
462#endif 461
463 reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */ 462 reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
464 reg_r(gspca_dev, 0x24, 8, 1); 463 reg_r(gspca_dev, 0x24, 8, 1);
465 464
@@ -645,14 +644,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
645 /* fall thru */ 644 /* fall thru */
646 case BRIDGE_SPCA533: 645 case BRIDGE_SPCA533:
647 spca504B_PollingDataReady(gspca_dev); 646 spca504B_PollingDataReady(gspca_dev);
648#ifdef GSPCA_DEBUG
649 spca50x_GetFirmware(gspca_dev); 647 spca50x_GetFirmware(gspca_dev);
650#endif
651 break; 648 break;
652 case BRIDGE_SPCA536: 649 case BRIDGE_SPCA536:
653#ifdef GSPCA_DEBUG
654 spca50x_GetFirmware(gspca_dev); 650 spca50x_GetFirmware(gspca_dev);
655#endif
656 reg_r(gspca_dev, 0x00, 0x5002, 1); 651 reg_r(gspca_dev, 0x00, 0x5002, 1);
657 reg_w_1(gspca_dev, 0x24, 0, 0, 0); 652 reg_w_1(gspca_dev, 0x24, 0, 0, 0);
658 reg_r(gspca_dev, 0x24, 0, 1); 653 reg_r(gspca_dev, 0x24, 0, 1);
@@ -678,9 +673,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
678/* case BRIDGE_SPCA504: */ 673/* case BRIDGE_SPCA504: */
679 PDEBUG(D_STREAM, "Opening SPCA504"); 674 PDEBUG(D_STREAM, "Opening SPCA504");
680 if (sd->subtype == AiptekMiniPenCam13) { 675 if (sd->subtype == AiptekMiniPenCam13) {
681#ifdef GSPCA_DEBUG
682 spca504_read_info(gspca_dev); 676 spca504_read_info(gspca_dev);
683#endif
684 677
685 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ 678 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
686 spca504A_acknowledged_command(gspca_dev, 0x24, 679 spca504A_acknowledged_command(gspca_dev, 0x24,
@@ -752,9 +745,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
752 break; 745 break;
753 case BRIDGE_SPCA504: 746 case BRIDGE_SPCA504:
754 if (sd->subtype == AiptekMiniPenCam13) { 747 if (sd->subtype == AiptekMiniPenCam13) {
755#ifdef GSPCA_DEBUG
756 spca504_read_info(gspca_dev); 748 spca504_read_info(gspca_dev);
757#endif
758 749
759 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ 750 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
760 spca504A_acknowledged_command(gspca_dev, 0x24, 751 spca504A_acknowledged_command(gspca_dev, 0x24,
@@ -766,9 +757,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
766 0, 0, 0x9d, 1); 757 0, 0, 0x9d, 1);
767 } else { 758 } else {
768 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 759 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
769#ifdef GSPCA_DEBUG
770 spca504_read_info(gspca_dev); 760 spca504_read_info(gspca_dev);
771#endif
772 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 761 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
773 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 762 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
774 } 763 }
diff --git a/drivers/media/usb/gspca/vc032x.c b/drivers/media/usb/gspca/vc032x.c
index e50079503d96..c00ac57de510 100644
--- a/drivers/media/usb/gspca/vc032x.c
+++ b/drivers/media/usb/gspca/vc032x.c
@@ -2927,7 +2927,6 @@ static void reg_r(struct gspca_dev *gspca_dev,
2927 u16 len) 2927 u16 len)
2928{ 2928{
2929 reg_r_i(gspca_dev, req, index, len); 2929 reg_r_i(gspca_dev, req, index, len);
2930#ifdef GSPCA_DEBUG
2931 if (gspca_dev->usb_err < 0) 2930 if (gspca_dev->usb_err < 0)
2932 return; 2931 return;
2933 if (len == 1) 2932 if (len == 1)
@@ -2936,7 +2935,6 @@ static void reg_r(struct gspca_dev *gspca_dev,
2936 else 2935 else
2937 PDEBUG(D_USBI, "GET %02x 0001 %04x %*ph", 2936 PDEBUG(D_USBI, "GET %02x 0001 %04x %*ph",
2938 req, index, 3, gspca_dev->usb_buf); 2937 req, index, 3, gspca_dev->usb_buf);
2939#endif
2940} 2938}
2941 2939
2942static void reg_w_i(struct gspca_dev *gspca_dev, 2940static void reg_w_i(struct gspca_dev *gspca_dev,
@@ -2964,11 +2962,9 @@ static void reg_w(struct gspca_dev *gspca_dev,
2964 u16 value, 2962 u16 value,
2965 u16 index) 2963 u16 index)
2966{ 2964{
2967#ifdef GSPCA_DEBUG
2968 if (gspca_dev->usb_err < 0) 2965 if (gspca_dev->usb_err < 0)
2969 return; 2966 return;
2970 PDEBUG(D_USBO, "SET %02x %04x %04x", req, value, index); 2967 PDEBUG(D_USBO, "SET %02x %04x %04x", req, value, index);
2971#endif
2972 reg_w_i(gspca_dev, req, value, index); 2968 reg_w_i(gspca_dev, req, value, index);
2973} 2969}
2974 2970
@@ -3044,8 +3040,7 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
3044 if (value == 0 && ptsensor_info->IdAdd == 0x82) 3040 if (value == 0 && ptsensor_info->IdAdd == 0x82)
3045 value = read_sensor_register(gspca_dev, 0x83); 3041 value = read_sensor_register(gspca_dev, 0x83);
3046 if (value != 0) { 3042 if (value != 0) {
3047 PDEBUG(D_ERR|D_PROBE, "Sensor ID %04x (%d)", 3043 PDEBUG(D_PROBE, "Sensor ID %04x (%d)", value, i);
3048 value, i);
3049 if (value == ptsensor_info->VpId) 3044 if (value == ptsensor_info->VpId)
3050 return ptsensor_info->sensorId; 3045 return ptsensor_info->sensorId;
3051 3046
@@ -3069,14 +3064,12 @@ static void i2c_write(struct gspca_dev *gspca_dev,
3069{ 3064{
3070 int retry; 3065 int retry;
3071 3066
3072#ifdef GSPCA_DEBUG
3073 if (gspca_dev->usb_err < 0) 3067 if (gspca_dev->usb_err < 0)
3074 return; 3068 return;
3075 if (size == 1) 3069 if (size == 1)
3076 PDEBUG(D_USBO, "i2c_w %02x %02x", reg, *val); 3070 PDEBUG(D_USBO, "i2c_w %02x %02x", reg, *val);
3077 else 3071 else
3078 PDEBUG(D_USBO, "i2c_w %02x %02x%02x", reg, *val, val[1]); 3072 PDEBUG(D_USBO, "i2c_w %02x %02x%02x", reg, *val, val[1]);
3079#endif
3080 reg_r_i(gspca_dev, 0xa1, 0xb33f, 1); 3073 reg_r_i(gspca_dev, 0xa1, 0xb33f, 1);
3081/*fixme:should check if (!(gspca_dev->usb_buf[0] & 0x02)) error*/ 3074/*fixme:should check if (!(gspca_dev->usb_buf[0] & 0x02)) error*/
3082 reg_w_i(gspca_dev, 0xa0, size, 0xb334); 3075 reg_w_i(gspca_dev, 0xa0, size, 0xb334);
diff --git a/drivers/media/usb/gspca/w996Xcf.c b/drivers/media/usb/gspca/w996Xcf.c
index 9e3a909e0a00..2165da0c7ce1 100644
--- a/drivers/media/usb/gspca/w996Xcf.c
+++ b/drivers/media/usb/gspca/w996Xcf.c
@@ -232,6 +232,7 @@ static void w9968cf_smbus_write_nack(struct sd *sd)
232 232
233static void w9968cf_smbus_read_ack(struct sd *sd) 233static void w9968cf_smbus_read_ack(struct sd *sd)
234{ 234{
235 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
235 int sda; 236 int sda;
236 237
237 /* Ensure SDA is high before raising clock to avoid a spurious stop */ 238 /* Ensure SDA is high before raising clock to avoid a spurious stop */
@@ -248,6 +249,7 @@ static void w9968cf_smbus_read_ack(struct sd *sd)
248/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */ 249/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */
249static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value) 250static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
250{ 251{
252 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
251 u16* data = (u16 *)sd->gspca_dev.usb_buf; 253 u16* data = (u16 *)sd->gspca_dev.usb_buf;
252 254
253 data[0] = 0x082f | ((sd->sensor_addr & 0x80) ? 0x1500 : 0x0); 255 data[0] = 0x082f | ((sd->sensor_addr & 0x80) ? 0x1500 : 0x0);
@@ -297,6 +299,7 @@ static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
297/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */ 299/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */
298static int w9968cf_i2c_r(struct sd *sd, u8 reg) 300static int w9968cf_i2c_r(struct sd *sd, u8 reg)
299{ 301{
302 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
300 int ret = 0; 303 int ret = 0;
301 u8 value; 304 u8 value;
302 305
@@ -326,7 +329,7 @@ static int w9968cf_i2c_r(struct sd *sd, u8 reg)
326 ret = value; 329 ret = value;
327 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value); 330 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
328 } else 331 } else
329 PDEBUG(D_ERR, "i2c read [0x%02x] failed", reg); 332 PERR("i2c read [0x%02x] failed", reg);
330 333
331 return ret; 334 return ret;
332} 335}
diff --git a/drivers/media/usb/gspca/zc3xx.c b/drivers/media/usb/gspca/zc3xx.c
index a8dc421f9f1f..cbfc2f921427 100644
--- a/drivers/media/usb/gspca/zc3xx.c
+++ b/drivers/media/usb/gspca/zc3xx.c
@@ -6259,12 +6259,11 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6259 retword |= i2c_read(gspca_dev, 0x01); /* ID 1 */ 6259 retword |= i2c_read(gspca_dev, 0x01); /* ID 1 */
6260 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", retword); 6260 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", retword);
6261 if (retword == 0x2030) { 6261 if (retword == 0x2030) {
6262#ifdef GSPCA_DEBUG
6263 u8 retbyte; 6262 u8 retbyte;
6264 6263
6265 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */ 6264 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */
6266 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte); 6265 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte);
6267#endif 6266
6268 send_unknown(gspca_dev, SENSOR_PO2030); 6267 send_unknown(gspca_dev, SENSOR_PO2030);
6269 return retword; 6268 return retword;
6270 } 6269 }
diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index 5c6193536399..8247c19d6260 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -174,6 +174,7 @@ static int device_authorization(struct hdpvr_device *dev)
174 case HDPVR_FIRMWARE_VERSION_AC3: 174 case HDPVR_FIRMWARE_VERSION_AC3:
175 case HDPVR_FIRMWARE_VERSION_0X12: 175 case HDPVR_FIRMWARE_VERSION_0X12:
176 case HDPVR_FIRMWARE_VERSION_0X15: 176 case HDPVR_FIRMWARE_VERSION_0X15:
177 case HDPVR_FIRMWARE_VERSION_0X1E:
177 dev->flags |= HDPVR_FLAG_AC3_CAP; 178 dev->flags |= HDPVR_FLAG_AC3_CAP;
178 break; 179 break;
179 default: 180 default:
@@ -196,6 +197,7 @@ static int device_authorization(struct hdpvr_device *dev)
196 hex_dump_to_buffer(response, 8, 16, 1, print_buf, 5*buf_size+1, 0); 197 hex_dump_to_buffer(response, 8, 16, 1, print_buf, 5*buf_size+1, 0);
197 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, " response: %s\n", 198 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, " response: %s\n",
198 print_buf); 199 print_buf);
200 kfree(print_buf);
199#endif 201#endif
200 202
201 msleep(100); 203 msleep(100);
@@ -385,12 +387,6 @@ static int hdpvr_probe(struct usb_interface *interface,
385 } 387 }
386 mutex_unlock(&dev->io_mutex); 388 mutex_unlock(&dev->io_mutex);
387 389
388 if (hdpvr_register_videodev(dev, &interface->dev,
389 video_nr[atomic_inc_return(&dev_nr)])) {
390 v4l2_err(&dev->v4l2_dev, "registering videodev failed\n");
391 goto error;
392 }
393
394#if IS_ENABLED(CONFIG_I2C) 390#if IS_ENABLED(CONFIG_I2C)
395 retval = hdpvr_register_i2c_adapter(dev); 391 retval = hdpvr_register_i2c_adapter(dev);
396 if (retval < 0) { 392 if (retval < 0) {
@@ -413,6 +409,13 @@ static int hdpvr_probe(struct usb_interface *interface,
413 } 409 }
414#endif 410#endif
415 411
412 retval = hdpvr_register_videodev(dev, &interface->dev,
413 video_nr[atomic_inc_return(&dev_nr)]);
414 if (retval < 0) {
415 v4l2_err(&dev->v4l2_dev, "registering videodev failed\n");
416 goto error;
417 }
418
416 /* let the user know what node this device is now attached to */ 419 /* let the user know what node this device is now attached to */
417 v4l2_info(&dev->v4l2_dev, "device now attached to %s\n", 420 v4l2_info(&dev->v4l2_dev, "device now attached to %s\n",
418 video_device_node_name(dev->video_dev)); 421 video_device_node_name(dev->video_dev));
diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c
index da6b77912222..774ba0e820be 100644
--- a/drivers/media/usb/hdpvr/hdpvr-video.c
+++ b/drivers/media/usb/hdpvr/hdpvr-video.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/kconfig.h>
13#include <linux/errno.h> 14#include <linux/errno.h>
14#include <linux/init.h> 15#include <linux/init.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
@@ -20,9 +21,11 @@
20#include <linux/workqueue.h> 21#include <linux/workqueue.h>
21 22
22#include <linux/videodev2.h> 23#include <linux/videodev2.h>
24#include <linux/v4l2-dv-timings.h>
23#include <media/v4l2-dev.h> 25#include <media/v4l2-dev.h>
24#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
25#include <media/v4l2-ioctl.h> 27#include <media/v4l2-ioctl.h>
28#include <media/v4l2-event.h>
26#include "hdpvr.h" 29#include "hdpvr.h"
27 30
28#define BULK_URB_TIMEOUT 90 /* 0.09 seconds */ 31#define BULK_URB_TIMEOUT 90 /* 0.09 seconds */
@@ -34,8 +37,23 @@
34 list_size(&dev->free_buff_list), \ 37 list_size(&dev->free_buff_list), \
35 list_size(&dev->rec_buff_list)); } 38 list_size(&dev->rec_buff_list)); }
36 39
40static const struct v4l2_dv_timings hdpvr_dv_timings[] = {
41 V4L2_DV_BT_CEA_720X480I59_94,
42 V4L2_DV_BT_CEA_720X576I50,
43 V4L2_DV_BT_CEA_720X480P59_94,
44 V4L2_DV_BT_CEA_720X576P50,
45 V4L2_DV_BT_CEA_1280X720P50,
46 V4L2_DV_BT_CEA_1280X720P60,
47 V4L2_DV_BT_CEA_1920X1080I50,
48 V4L2_DV_BT_CEA_1920X1080I60,
49};
50
51/* Use 480i59 as the default timings */
52#define HDPVR_DEF_DV_TIMINGS_IDX (0)
53
37struct hdpvr_fh { 54struct hdpvr_fh {
38 struct hdpvr_device *dev; 55 struct v4l2_fh fh;
56 bool legacy_mode;
39}; 57};
40 58
41static uint list_size(struct list_head *list) 59static uint list_size(struct list_head *list)
@@ -359,53 +377,29 @@ static int hdpvr_stop_streaming(struct hdpvr_device *dev)
359 377
360static int hdpvr_open(struct file *file) 378static int hdpvr_open(struct file *file)
361{ 379{
362 struct hdpvr_device *dev; 380 struct hdpvr_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL);
363 struct hdpvr_fh *fh;
364 int retval = -ENOMEM;
365
366 dev = (struct hdpvr_device *)video_get_drvdata(video_devdata(file));
367 if (!dev) {
368 pr_err("open failing with with ENODEV\n");
369 retval = -ENODEV;
370 goto err;
371 }
372
373 fh = kzalloc(sizeof(struct hdpvr_fh), GFP_KERNEL);
374 if (!fh) {
375 v4l2_err(&dev->v4l2_dev, "Out of memory\n");
376 goto err;
377 }
378 /* lock the device to allow correctly handling errors
379 * in resumption */
380 mutex_lock(&dev->io_mutex);
381 dev->open_count++;
382 mutex_unlock(&dev->io_mutex);
383 381
384 fh->dev = dev; 382 if (fh == NULL)
385 383 return -ENOMEM;
386 /* save our object in the file's private structure */ 384 fh->legacy_mode = true;
385 v4l2_fh_init(&fh->fh, video_devdata(file));
386 v4l2_fh_add(&fh->fh);
387 file->private_data = fh; 387 file->private_data = fh;
388 388 return 0;
389 retval = 0;
390err:
391 return retval;
392} 389}
393 390
394static int hdpvr_release(struct file *file) 391static int hdpvr_release(struct file *file)
395{ 392{
396 struct hdpvr_fh *fh = file->private_data; 393 struct hdpvr_device *dev = video_drvdata(file);
397 struct hdpvr_device *dev = fh->dev;
398
399 if (!dev)
400 return -ENODEV;
401 394
402 mutex_lock(&dev->io_mutex); 395 mutex_lock(&dev->io_mutex);
403 if (!(--dev->open_count) && dev->status == STATUS_STREAMING) 396 if (file->private_data == dev->owner) {
404 hdpvr_stop_streaming(dev); 397 hdpvr_stop_streaming(dev);
405 398 dev->owner = NULL;
399 }
406 mutex_unlock(&dev->io_mutex); 400 mutex_unlock(&dev->io_mutex);
407 401
408 return 0; 402 return v4l2_fh_release(file);
409} 403}
410 404
411/* 405/*
@@ -415,8 +409,7 @@ static int hdpvr_release(struct file *file)
415static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count, 409static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
416 loff_t *pos) 410 loff_t *pos)
417{ 411{
418 struct hdpvr_fh *fh = file->private_data; 412 struct hdpvr_device *dev = video_drvdata(file);
419 struct hdpvr_device *dev = fh->dev;
420 struct hdpvr_buffer *buf = NULL; 413 struct hdpvr_buffer *buf = NULL;
421 struct urb *urb; 414 struct urb *urb;
422 unsigned int ret = 0; 415 unsigned int ret = 0;
@@ -425,9 +418,6 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
425 if (*pos) 418 if (*pos)
426 return -ESPIPE; 419 return -ESPIPE;
427 420
428 if (!dev)
429 return -ENODEV;
430
431 mutex_lock(&dev->io_mutex); 421 mutex_lock(&dev->io_mutex);
432 if (dev->status == STATUS_IDLE) { 422 if (dev->status == STATUS_IDLE) {
433 if (hdpvr_start_streaming(dev)) { 423 if (hdpvr_start_streaming(dev)) {
@@ -439,6 +429,7 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
439 mutex_unlock(&dev->io_mutex); 429 mutex_unlock(&dev->io_mutex);
440 goto err; 430 goto err;
441 } 431 }
432 dev->owner = file->private_data;
442 print_buffer_status(); 433 print_buffer_status();
443 } 434 }
444 mutex_unlock(&dev->io_mutex); 435 mutex_unlock(&dev->io_mutex);
@@ -516,23 +507,23 @@ err:
516 507
517static unsigned int hdpvr_poll(struct file *filp, poll_table *wait) 508static unsigned int hdpvr_poll(struct file *filp, poll_table *wait)
518{ 509{
510 unsigned long req_events = poll_requested_events(wait);
519 struct hdpvr_buffer *buf = NULL; 511 struct hdpvr_buffer *buf = NULL;
520 struct hdpvr_fh *fh = filp->private_data; 512 struct hdpvr_device *dev = video_drvdata(filp);
521 struct hdpvr_device *dev = fh->dev; 513 unsigned int mask = v4l2_ctrl_poll(filp, wait);
522 unsigned int mask = 0;
523 514
524 mutex_lock(&dev->io_mutex); 515 if (!(req_events & (POLLIN | POLLRDNORM)))
516 return mask;
525 517
526 if (!video_is_registered(dev->video_dev)) { 518 mutex_lock(&dev->io_mutex);
527 mutex_unlock(&dev->io_mutex);
528 return -EIO;
529 }
530 519
531 if (dev->status == STATUS_IDLE) { 520 if (dev->status == STATUS_IDLE) {
532 if (hdpvr_start_streaming(dev)) { 521 if (hdpvr_start_streaming(dev)) {
533 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, 522 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
534 "start_streaming failed\n"); 523 "start_streaming failed\n");
535 dev->status = STATUS_IDLE; 524 dev->status = STATUS_IDLE;
525 } else {
526 dev->owner = filp->private_data;
536 } 527 }
537 528
538 print_buffer_status(); 529 print_buffer_status();
@@ -574,36 +565,188 @@ static int vidioc_querycap(struct file *file, void *priv,
574 strcpy(cap->driver, "hdpvr"); 565 strcpy(cap->driver, "hdpvr");
575 strcpy(cap->card, "Hauppauge HD PVR"); 566 strcpy(cap->card, "Hauppauge HD PVR");
576 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); 567 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
577 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 568 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_AUDIO |
578 V4L2_CAP_AUDIO | 569 V4L2_CAP_READWRITE;
579 V4L2_CAP_READWRITE; 570 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
580 return 0; 571 return 0;
581} 572}
582 573
583static int vidioc_s_std(struct file *file, void *private_data, 574static int vidioc_s_std(struct file *file, void *_fh,
584 v4l2_std_id *std) 575 v4l2_std_id std)
585{ 576{
586 struct hdpvr_fh *fh = file->private_data; 577 struct hdpvr_device *dev = video_drvdata(file);
587 struct hdpvr_device *dev = fh->dev; 578 struct hdpvr_fh *fh = _fh;
588 u8 std_type = 1; 579 u8 std_type = 1;
589 580
590 if (*std & (V4L2_STD_NTSC | V4L2_STD_PAL_60)) 581 if (!fh->legacy_mode && dev->options.video_input == HDPVR_COMPONENT)
582 return -ENODATA;
583 if (dev->status != STATUS_IDLE)
584 return -EBUSY;
585 if (std & V4L2_STD_525_60)
591 std_type = 0; 586 std_type = 0;
587 dev->cur_std = std;
588 dev->width = 720;
589 dev->height = std_type ? 576 : 480;
592 590
593 return hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, std_type); 591 return hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, std_type);
594} 592}
595 593
594static int vidioc_g_std(struct file *file, void *_fh,
595 v4l2_std_id *std)
596{
597 struct hdpvr_device *dev = video_drvdata(file);
598 struct hdpvr_fh *fh = _fh;
599
600 if (!fh->legacy_mode && dev->options.video_input == HDPVR_COMPONENT)
601 return -ENODATA;
602 *std = dev->cur_std;
603 return 0;
604}
605
606static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a)
607{
608 struct hdpvr_device *dev = video_drvdata(file);
609 struct hdpvr_video_info *vid_info;
610 struct hdpvr_fh *fh = _fh;
611
612 *a = V4L2_STD_ALL;
613 if (dev->options.video_input == HDPVR_COMPONENT)
614 return fh->legacy_mode ? 0 : -ENODATA;
615 vid_info = get_video_info(dev);
616 if (vid_info == NULL)
617 return 0;
618 if (vid_info->width == 720 &&
619 (vid_info->height == 480 || vid_info->height == 576)) {
620 *a = (vid_info->height == 480) ?
621 V4L2_STD_525_60 : V4L2_STD_625_50;
622 }
623 kfree(vid_info);
624 return 0;
625}
626
627static int vidioc_s_dv_timings(struct file *file, void *_fh,
628 struct v4l2_dv_timings *timings)
629{
630 struct hdpvr_device *dev = video_drvdata(file);
631 struct hdpvr_fh *fh = _fh;
632 int i;
633
634 fh->legacy_mode = false;
635 if (dev->options.video_input)
636 return -ENODATA;
637 if (dev->status != STATUS_IDLE)
638 return -EBUSY;
639 for (i = 0; i < ARRAY_SIZE(hdpvr_dv_timings); i++)
640 if (v4l_match_dv_timings(timings, hdpvr_dv_timings + i, 0))
641 break;
642 if (i == ARRAY_SIZE(hdpvr_dv_timings))
643 return -EINVAL;
644 dev->cur_dv_timings = hdpvr_dv_timings[i];
645 dev->width = hdpvr_dv_timings[i].bt.width;
646 dev->height = hdpvr_dv_timings[i].bt.height;
647 return 0;
648}
649
650static int vidioc_g_dv_timings(struct file *file, void *_fh,
651 struct v4l2_dv_timings *timings)
652{
653 struct hdpvr_device *dev = video_drvdata(file);
654 struct hdpvr_fh *fh = _fh;
655
656 fh->legacy_mode = false;
657 if (dev->options.video_input)
658 return -ENODATA;
659 *timings = dev->cur_dv_timings;
660 return 0;
661}
662
663static int vidioc_query_dv_timings(struct file *file, void *_fh,
664 struct v4l2_dv_timings *timings)
665{
666 struct hdpvr_device *dev = video_drvdata(file);
667 struct hdpvr_fh *fh = _fh;
668 struct hdpvr_video_info *vid_info;
669 bool interlaced;
670 int ret = 0;
671 int i;
672
673 fh->legacy_mode = false;
674 if (dev->options.video_input)
675 return -ENODATA;
676 vid_info = get_video_info(dev);
677 if (vid_info == NULL)
678 return -ENOLCK;
679 interlaced = vid_info->fps <= 30;
680 for (i = 0; i < ARRAY_SIZE(hdpvr_dv_timings); i++) {
681 const struct v4l2_bt_timings *bt = &hdpvr_dv_timings[i].bt;
682 unsigned hsize;
683 unsigned vsize;
684 unsigned fps;
685
686 hsize = bt->hfrontporch + bt->hsync + bt->hbackporch + bt->width;
687 vsize = bt->vfrontporch + bt->vsync + bt->vbackporch +
688 bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch +
689 bt->height;
690 fps = (unsigned)bt->pixelclock / (hsize * vsize);
691 if (bt->width != vid_info->width ||
692 bt->height != vid_info->height ||
693 bt->interlaced != interlaced ||
694 (fps != vid_info->fps && fps + 1 != vid_info->fps))
695 continue;
696 *timings = hdpvr_dv_timings[i];
697 break;
698 }
699 if (i == ARRAY_SIZE(hdpvr_dv_timings))
700 ret = -ERANGE;
701 kfree(vid_info);
702 return ret;
703}
704
705static int vidioc_enum_dv_timings(struct file *file, void *_fh,
706 struct v4l2_enum_dv_timings *timings)
707{
708 struct hdpvr_device *dev = video_drvdata(file);
709 struct hdpvr_fh *fh = _fh;
710
711 fh->legacy_mode = false;
712 memset(timings->reserved, 0, sizeof(timings->reserved));
713 if (dev->options.video_input)
714 return -ENODATA;
715 if (timings->index >= ARRAY_SIZE(hdpvr_dv_timings))
716 return -EINVAL;
717 timings->timings = hdpvr_dv_timings[timings->index];
718 return 0;
719}
720
721static int vidioc_dv_timings_cap(struct file *file, void *_fh,
722 struct v4l2_dv_timings_cap *cap)
723{
724 struct hdpvr_device *dev = video_drvdata(file);
725 struct hdpvr_fh *fh = _fh;
726
727 fh->legacy_mode = false;
728 if (dev->options.video_input)
729 return -ENODATA;
730 cap->type = V4L2_DV_BT_656_1120;
731 cap->bt.min_width = 720;
732 cap->bt.max_width = 1920;
733 cap->bt.min_height = 480;
734 cap->bt.max_height = 1080;
735 cap->bt.min_pixelclock = 27000000;
736 cap->bt.max_pixelclock = 74250000;
737 cap->bt.standards = V4L2_DV_BT_STD_CEA861;
738 cap->bt.capabilities = V4L2_DV_BT_CAP_INTERLACED | V4L2_DV_BT_CAP_PROGRESSIVE;
739 return 0;
740}
741
596static const char *iname[] = { 742static const char *iname[] = {
597 [HDPVR_COMPONENT] = "Component", 743 [HDPVR_COMPONENT] = "Component",
598 [HDPVR_SVIDEO] = "S-Video", 744 [HDPVR_SVIDEO] = "S-Video",
599 [HDPVR_COMPOSITE] = "Composite", 745 [HDPVR_COMPOSITE] = "Composite",
600}; 746};
601 747
602static int vidioc_enum_input(struct file *file, void *priv, 748static int vidioc_enum_input(struct file *file, void *_fh, struct v4l2_input *i)
603 struct v4l2_input *i)
604{ 749{
605 struct hdpvr_fh *fh = file->private_data;
606 struct hdpvr_device *dev = fh->dev;
607 unsigned int n; 750 unsigned int n;
608 751
609 n = i->index; 752 n = i->index;
@@ -617,27 +760,42 @@ static int vidioc_enum_input(struct file *file, void *priv,
617 760
618 i->audioset = 1<<HDPVR_RCA_FRONT | 1<<HDPVR_RCA_BACK | 1<<HDPVR_SPDIF; 761 i->audioset = 1<<HDPVR_RCA_FRONT | 1<<HDPVR_RCA_BACK | 1<<HDPVR_SPDIF;
619 762
620 i->std = dev->video_dev->tvnorms; 763 i->capabilities = n ? V4L2_IN_CAP_STD : V4L2_IN_CAP_DV_TIMINGS;
764 i->std = n ? V4L2_STD_ALL : 0;
621 765
622 return 0; 766 return 0;
623} 767}
624 768
625static int vidioc_s_input(struct file *file, void *private_data, 769static int vidioc_s_input(struct file *file, void *_fh,
626 unsigned int index) 770 unsigned int index)
627{ 771{
628 struct hdpvr_fh *fh = file->private_data; 772 struct hdpvr_device *dev = video_drvdata(file);
629 struct hdpvr_device *dev = fh->dev;
630 int retval; 773 int retval;
631 774
632 if (index >= HDPVR_VIDEO_INPUTS) 775 if (index >= HDPVR_VIDEO_INPUTS)
633 return -EINVAL; 776 return -EINVAL;
634 777
635 if (dev->status != STATUS_IDLE) 778 if (dev->status != STATUS_IDLE)
636 return -EAGAIN; 779 return -EBUSY;
637 780
638 retval = hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, index+1); 781 retval = hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, index+1);
639 if (!retval) 782 if (!retval) {
640 dev->options.video_input = index; 783 dev->options.video_input = index;
784 /*
785 * Unfortunately gstreamer calls ENUMSTD and bails out if it
786 * won't find any formats, even though component input is
787 * selected. This means that we have to leave tvnorms at
788 * V4L2_STD_ALL. We cannot use the 'legacy' trick since
789 * tvnorms is set at the device node level and not at the
790 * filehandle level.
791 *
792 * Comment this out for now, but if the legacy mode can be
793 * removed in the future, then this code should be enabled
794 * again.
795 dev->video_dev->tvnorms =
796 (index != HDPVR_COMPONENT) ? V4L2_STD_ALL : 0;
797 */
798 }
641 799
642 return retval; 800 return retval;
643} 801}
@@ -645,8 +803,7 @@ static int vidioc_s_input(struct file *file, void *private_data,
645static int vidioc_g_input(struct file *file, void *private_data, 803static int vidioc_g_input(struct file *file, void *private_data,
646 unsigned int *index) 804 unsigned int *index)
647{ 805{
648 struct hdpvr_fh *fh = file->private_data; 806 struct hdpvr_device *dev = video_drvdata(file);
649 struct hdpvr_device *dev = fh->dev;
650 807
651 *index = dev->options.video_input; 808 *index = dev->options.video_input;
652 return 0; 809 return 0;
@@ -679,15 +836,14 @@ static int vidioc_enumaudio(struct file *file, void *priv,
679static int vidioc_s_audio(struct file *file, void *private_data, 836static int vidioc_s_audio(struct file *file, void *private_data,
680 const struct v4l2_audio *audio) 837 const struct v4l2_audio *audio)
681{ 838{
682 struct hdpvr_fh *fh = file->private_data; 839 struct hdpvr_device *dev = video_drvdata(file);
683 struct hdpvr_device *dev = fh->dev;
684 int retval; 840 int retval;
685 841
686 if (audio->index >= HDPVR_AUDIO_INPUTS) 842 if (audio->index >= HDPVR_AUDIO_INPUTS)
687 return -EINVAL; 843 return -EINVAL;
688 844
689 if (dev->status != STATUS_IDLE) 845 if (dev->status != STATUS_IDLE)
690 return -EAGAIN; 846 return -EBUSY;
691 847
692 retval = hdpvr_set_audio(dev, audio->index+1, dev->options.audio_codec); 848 retval = hdpvr_set_audio(dev, audio->index+1, dev->options.audio_codec);
693 if (!retval) 849 if (!retval)
@@ -699,8 +855,7 @@ static int vidioc_s_audio(struct file *file, void *private_data,
699static int vidioc_g_audio(struct file *file, void *private_data, 855static int vidioc_g_audio(struct file *file, void *private_data,
700 struct v4l2_audio *audio) 856 struct v4l2_audio *audio)
701{ 857{
702 struct hdpvr_fh *fh = file->private_data; 858 struct hdpvr_device *dev = video_drvdata(file);
703 struct hdpvr_device *dev = fh->dev;
704 859
705 audio->index = dev->options.audio_input; 860 audio->index = dev->options.audio_input;
706 audio->capability = V4L2_AUDCAP_STEREO; 861 audio->capability = V4L2_AUDCAP_STEREO;
@@ -709,335 +864,69 @@ static int vidioc_g_audio(struct file *file, void *private_data,
709 return 0; 864 return 0;
710} 865}
711 866
712static const s32 supported_v4l2_ctrls[] = { 867static int hdpvr_try_ctrl(struct v4l2_ctrl *ctrl)
713 V4L2_CID_BRIGHTNESS,
714 V4L2_CID_CONTRAST,
715 V4L2_CID_SATURATION,
716 V4L2_CID_HUE,
717 V4L2_CID_SHARPNESS,
718 V4L2_CID_MPEG_AUDIO_ENCODING,
719 V4L2_CID_MPEG_VIDEO_ENCODING,
720 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
721 V4L2_CID_MPEG_VIDEO_BITRATE,
722 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
723};
724
725static int fill_queryctrl(struct hdpvr_options *opt, struct v4l2_queryctrl *qc,
726 int ac3, int fw_ver)
727{
728 int err;
729
730 if (fw_ver > 0x15) {
731 switch (qc->id) {
732 case V4L2_CID_BRIGHTNESS:
733 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
734 case V4L2_CID_CONTRAST:
735 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x40);
736 case V4L2_CID_SATURATION:
737 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x40);
738 case V4L2_CID_HUE:
739 return v4l2_ctrl_query_fill(qc, 0x0, 0x1e, 1, 0xf);
740 case V4L2_CID_SHARPNESS:
741 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
742 }
743 } else {
744 switch (qc->id) {
745 case V4L2_CID_BRIGHTNESS:
746 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x86);
747 case V4L2_CID_CONTRAST:
748 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
749 case V4L2_CID_SATURATION:
750 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
751 case V4L2_CID_HUE:
752 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
753 case V4L2_CID_SHARPNESS:
754 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
755 }
756 }
757
758 switch (qc->id) {
759 case V4L2_CID_MPEG_AUDIO_ENCODING:
760 return v4l2_ctrl_query_fill(
761 qc, V4L2_MPEG_AUDIO_ENCODING_AAC,
762 ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3
763 : V4L2_MPEG_AUDIO_ENCODING_AAC,
764 1, V4L2_MPEG_AUDIO_ENCODING_AAC);
765 case V4L2_CID_MPEG_VIDEO_ENCODING:
766 return v4l2_ctrl_query_fill(
767 qc, V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC,
768 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
769 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
770
771/* case V4L2_CID_MPEG_VIDEO_? maybe keyframe interval: */
772/* return v4l2_ctrl_query_fill(qc, 0, 128, 128, 0); */
773 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
774 return v4l2_ctrl_query_fill(
775 qc, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
776 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
777 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
778
779 case V4L2_CID_MPEG_VIDEO_BITRATE:
780 return v4l2_ctrl_query_fill(qc, 1000000, 13500000, 100000,
781 6500000);
782 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
783 err = v4l2_ctrl_query_fill(qc, 1100000, 20200000, 100000,
784 9000000);
785 if (!err && opt->bitrate_mode == HDPVR_CONSTANT)
786 qc->flags |= V4L2_CTRL_FLAG_INACTIVE;
787 return err;
788 default:
789 return -EINVAL;
790 }
791}
792
793static int vidioc_queryctrl(struct file *file, void *private_data,
794 struct v4l2_queryctrl *qc)
795{
796 struct hdpvr_fh *fh = file->private_data;
797 struct hdpvr_device *dev = fh->dev;
798 int i, next;
799 u32 id = qc->id;
800
801 memset(qc, 0, sizeof(*qc));
802
803 next = !!(id & V4L2_CTRL_FLAG_NEXT_CTRL);
804 qc->id = id & ~V4L2_CTRL_FLAG_NEXT_CTRL;
805
806 for (i = 0; i < ARRAY_SIZE(supported_v4l2_ctrls); i++) {
807 if (next) {
808 if (qc->id < supported_v4l2_ctrls[i])
809 qc->id = supported_v4l2_ctrls[i];
810 else
811 continue;
812 }
813
814 if (qc->id == supported_v4l2_ctrls[i])
815 return fill_queryctrl(&dev->options, qc,
816 dev->flags & HDPVR_FLAG_AC3_CAP,
817 dev->fw_ver);
818
819 if (qc->id < supported_v4l2_ctrls[i])
820 break;
821 }
822
823 return -EINVAL;
824}
825
826static int vidioc_g_ctrl(struct file *file, void *private_data,
827 struct v4l2_control *ctrl)
828{ 868{
829 struct hdpvr_fh *fh = file->private_data; 869 struct hdpvr_device *dev =
830 struct hdpvr_device *dev = fh->dev; 870 container_of(ctrl->handler, struct hdpvr_device, hdl);
831 871
832 switch (ctrl->id) { 872 switch (ctrl->id) {
833 case V4L2_CID_BRIGHTNESS: 873 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
834 ctrl->value = dev->options.brightness; 874 if (ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
835 break; 875 dev->video_bitrate->val >= dev->video_bitrate_peak->val)
836 case V4L2_CID_CONTRAST: 876 dev->video_bitrate_peak->val =
837 ctrl->value = dev->options.contrast; 877 dev->video_bitrate->val + 100000;
838 break;
839 case V4L2_CID_SATURATION:
840 ctrl->value = dev->options.saturation;
841 break;
842 case V4L2_CID_HUE:
843 ctrl->value = dev->options.hue;
844 break;
845 case V4L2_CID_SHARPNESS:
846 ctrl->value = dev->options.sharpness;
847 break; 878 break;
848 default:
849 return -EINVAL;
850 } 879 }
851 return 0; 880 return 0;
852} 881}
853 882
854static int vidioc_s_ctrl(struct file *file, void *private_data, 883static int hdpvr_s_ctrl(struct v4l2_ctrl *ctrl)
855 struct v4l2_control *ctrl)
856{ 884{
857 struct hdpvr_fh *fh = file->private_data; 885 struct hdpvr_device *dev =
858 struct hdpvr_device *dev = fh->dev; 886 container_of(ctrl->handler, struct hdpvr_device, hdl);
859 int retval; 887 struct hdpvr_options *opt = &dev->options;
888 int ret = -EINVAL;
860 889
861 switch (ctrl->id) { 890 switch (ctrl->id) {
862 case V4L2_CID_BRIGHTNESS: 891 case V4L2_CID_BRIGHTNESS:
863 retval = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->value); 892 ret = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->val);
864 if (!retval) 893 if (ret)
865 dev->options.brightness = ctrl->value; 894 break;
866 break; 895 dev->options.brightness = ctrl->val;
896 return 0;
867 case V4L2_CID_CONTRAST: 897 case V4L2_CID_CONTRAST:
868 retval = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->value); 898 ret = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->val);
869 if (!retval) 899 if (ret)
870 dev->options.contrast = ctrl->value; 900 break;
871 break; 901 dev->options.contrast = ctrl->val;
902 return 0;
872 case V4L2_CID_SATURATION: 903 case V4L2_CID_SATURATION:
873 retval = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->value); 904 ret = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->val);
874 if (!retval) 905 if (ret)
875 dev->options.saturation = ctrl->value; 906 break;
876 break; 907 dev->options.saturation = ctrl->val;
908 return 0;
877 case V4L2_CID_HUE: 909 case V4L2_CID_HUE:
878 retval = hdpvr_config_call(dev, CTRL_HUE, ctrl->value); 910 ret = hdpvr_config_call(dev, CTRL_HUE, ctrl->val);
879 if (!retval) 911 if (ret)
880 dev->options.hue = ctrl->value; 912 break;
881 break; 913 dev->options.hue = ctrl->val;
914 return 0;
882 case V4L2_CID_SHARPNESS: 915 case V4L2_CID_SHARPNESS:
883 retval = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->value); 916 ret = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->val);
884 if (!retval) 917 if (ret)
885 dev->options.sharpness = ctrl->value; 918 break;
886 break; 919 dev->options.sharpness = ctrl->val;
887 default: 920 return 0;
888 return -EINVAL;
889 }
890
891 return retval;
892}
893
894
895static int hdpvr_get_ctrl(struct hdpvr_options *opt,
896 struct v4l2_ext_control *ctrl)
897{
898 switch (ctrl->id) {
899 case V4L2_CID_MPEG_AUDIO_ENCODING:
900 ctrl->value = opt->audio_codec;
901 break;
902 case V4L2_CID_MPEG_VIDEO_ENCODING:
903 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC;
904 break;
905/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
906/* ctrl->value = (opt->gop_mode & 0x2) ? 0 : 128; */
907/* break; */
908 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
909 ctrl->value = opt->bitrate_mode == HDPVR_CONSTANT
910 ? V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
911 : V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
912 break;
913 case V4L2_CID_MPEG_VIDEO_BITRATE:
914 ctrl->value = opt->bitrate * 100000;
915 break;
916 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
917 ctrl->value = opt->peak_bitrate * 100000;
918 break;
919 case V4L2_CID_MPEG_STREAM_TYPE:
920 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
921 break;
922 default:
923 return -EINVAL;
924 }
925 return 0;
926}
927
928static int vidioc_g_ext_ctrls(struct file *file, void *priv,
929 struct v4l2_ext_controls *ctrls)
930{
931 struct hdpvr_fh *fh = file->private_data;
932 struct hdpvr_device *dev = fh->dev;
933 int i, err = 0;
934
935 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
936 for (i = 0; i < ctrls->count; i++) {
937 struct v4l2_ext_control *ctrl = ctrls->controls + i;
938
939 err = hdpvr_get_ctrl(&dev->options, ctrl);
940 if (err) {
941 ctrls->error_idx = i;
942 break;
943 }
944 }
945 return err;
946
947 }
948
949 return -EINVAL;
950}
951
952
953static int hdpvr_try_ctrl(struct v4l2_ext_control *ctrl, int ac3)
954{
955 int ret = -EINVAL;
956
957 switch (ctrl->id) {
958 case V4L2_CID_MPEG_AUDIO_ENCODING:
959 if (ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AAC ||
960 (ac3 && ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AC3))
961 ret = 0;
962 break;
963 case V4L2_CID_MPEG_VIDEO_ENCODING:
964 if (ctrl->value == V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC)
965 ret = 0;
966 break;
967/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
968/* if (ctrl->value == 0 || ctrl->value == 128) */
969/* ret = 0; */
970/* break; */
971 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
972 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR ||
973 ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR)
974 ret = 0;
975 break;
976 case V4L2_CID_MPEG_VIDEO_BITRATE:
977 {
978 uint bitrate = ctrl->value / 100000;
979 if (bitrate >= 10 && bitrate <= 135)
980 ret = 0;
981 break;
982 }
983 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
984 {
985 uint peak_bitrate = ctrl->value / 100000;
986 if (peak_bitrate >= 10 && peak_bitrate <= 202)
987 ret = 0;
988 break;
989 }
990 case V4L2_CID_MPEG_STREAM_TYPE:
991 if (ctrl->value == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
992 ret = 0;
993 break;
994 default:
995 return -EINVAL;
996 }
997 return ret;
998}
999
1000static int vidioc_try_ext_ctrls(struct file *file, void *priv,
1001 struct v4l2_ext_controls *ctrls)
1002{
1003 struct hdpvr_fh *fh = file->private_data;
1004 struct hdpvr_device *dev = fh->dev;
1005 int i, err = 0;
1006
1007 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1008 for (i = 0; i < ctrls->count; i++) {
1009 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1010
1011 err = hdpvr_try_ctrl(ctrl,
1012 dev->flags & HDPVR_FLAG_AC3_CAP);
1013 if (err) {
1014 ctrls->error_idx = i;
1015 break;
1016 }
1017 }
1018 return err;
1019 }
1020
1021 return -EINVAL;
1022}
1023
1024
1025static int hdpvr_set_ctrl(struct hdpvr_device *dev,
1026 struct v4l2_ext_control *ctrl)
1027{
1028 struct hdpvr_options *opt = &dev->options;
1029 int ret = 0;
1030
1031 switch (ctrl->id) {
1032 case V4L2_CID_MPEG_AUDIO_ENCODING: 921 case V4L2_CID_MPEG_AUDIO_ENCODING:
1033 if (dev->flags & HDPVR_FLAG_AC3_CAP) { 922 if (dev->flags & HDPVR_FLAG_AC3_CAP) {
1034 opt->audio_codec = ctrl->value; 923 opt->audio_codec = ctrl->val;
1035 ret = hdpvr_set_audio(dev, opt->audio_input, 924 return hdpvr_set_audio(dev, opt->audio_input,
1036 opt->audio_codec); 925 opt->audio_codec);
1037 } 926 }
1038 break; 927 return 0;
1039 case V4L2_CID_MPEG_VIDEO_ENCODING: 928 case V4L2_CID_MPEG_VIDEO_ENCODING:
1040 break; 929 return 0;
1041/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */ 930/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
1042/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */ 931/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */
1043/* opt->gop_mode |= 0x2; */ 932/* opt->gop_mode |= 0x2; */
@@ -1050,86 +939,41 @@ static int hdpvr_set_ctrl(struct hdpvr_device *dev,
1050/* opt->gop_mode); */ 939/* opt->gop_mode); */
1051/* } */ 940/* } */
1052/* break; */ 941/* break; */
1053 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 942 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: {
1054 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR && 943 uint peak_bitrate = dev->video_bitrate_peak->val / 100000;
1055 opt->bitrate_mode != HDPVR_CONSTANT) { 944 uint bitrate = dev->video_bitrate->val / 100000;
1056 opt->bitrate_mode = HDPVR_CONSTANT; 945
1057 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, 946 if (ctrl->is_new) {
1058 opt->bitrate_mode); 947 if (ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
1059 } 948 opt->bitrate_mode = HDPVR_CONSTANT;
1060 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR && 949 else
1061 opt->bitrate_mode == HDPVR_CONSTANT) { 950 opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE;
1062 opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE;
1063 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, 951 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
1064 opt->bitrate_mode); 952 opt->bitrate_mode);
953 v4l2_ctrl_activate(dev->video_bitrate_peak,
954 ctrl->val != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
1065 } 955 }
1066 break;
1067 case V4L2_CID_MPEG_VIDEO_BITRATE: {
1068 uint bitrate = ctrl->value / 100000;
1069
1070 opt->bitrate = bitrate;
1071 if (bitrate >= opt->peak_bitrate)
1072 opt->peak_bitrate = bitrate+1;
1073
1074 hdpvr_set_bitrate(dev);
1075 break;
1076 }
1077 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: {
1078 uint peak_bitrate = ctrl->value / 100000;
1079
1080 if (opt->bitrate_mode == HDPVR_CONSTANT)
1081 break;
1082 956
1083 if (opt->bitrate < peak_bitrate) { 957 if (dev->video_bitrate_peak->is_new ||
958 dev->video_bitrate->is_new) {
959 opt->bitrate = bitrate;
1084 opt->peak_bitrate = peak_bitrate; 960 opt->peak_bitrate = peak_bitrate;
1085 hdpvr_set_bitrate(dev); 961 hdpvr_set_bitrate(dev);
1086 } else 962 }
1087 ret = -EINVAL; 963 return 0;
1088 break;
1089 } 964 }
1090 case V4L2_CID_MPEG_STREAM_TYPE: 965 case V4L2_CID_MPEG_STREAM_TYPE:
1091 break; 966 return 0;
1092 default: 967 default:
1093 return -EINVAL; 968 break;
1094 } 969 }
1095 return ret; 970 return ret;
1096} 971}
1097 972
1098static int vidioc_s_ext_ctrls(struct file *file, void *priv,
1099 struct v4l2_ext_controls *ctrls)
1100{
1101 struct hdpvr_fh *fh = file->private_data;
1102 struct hdpvr_device *dev = fh->dev;
1103 int i, err = 0;
1104
1105 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1106 for (i = 0; i < ctrls->count; i++) {
1107 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1108
1109 err = hdpvr_try_ctrl(ctrl,
1110 dev->flags & HDPVR_FLAG_AC3_CAP);
1111 if (err) {
1112 ctrls->error_idx = i;
1113 break;
1114 }
1115 err = hdpvr_set_ctrl(dev, ctrl);
1116 if (err) {
1117 ctrls->error_idx = i;
1118 break;
1119 }
1120 }
1121 return err;
1122
1123 }
1124
1125 return -EINVAL;
1126}
1127
1128static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data, 973static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data,
1129 struct v4l2_fmtdesc *f) 974 struct v4l2_fmtdesc *f)
1130{ 975{
1131 976 if (f->index != 0)
1132 if (f->index != 0 || f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1133 return -EINVAL; 977 return -EINVAL;
1134 978
1135 f->flags = V4L2_FMT_FLAG_COMPRESSED; 979 f->flags = V4L2_FMT_FLAG_COMPRESSED;
@@ -1139,56 +983,92 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data,
1139 return 0; 983 return 0;
1140} 984}
1141 985
1142static int vidioc_g_fmt_vid_cap(struct file *file, void *private_data, 986static int vidioc_g_fmt_vid_cap(struct file *file, void *_fh,
1143 struct v4l2_format *f) 987 struct v4l2_format *f)
1144{ 988{
1145 struct hdpvr_fh *fh = file->private_data; 989 struct hdpvr_device *dev = video_drvdata(file);
1146 struct hdpvr_device *dev = fh->dev; 990 struct hdpvr_fh *fh = _fh;
1147 struct hdpvr_video_info *vid_info; 991
1148 992 /*
1149 if (!dev) 993 * The original driver would always returns the current detected
1150 return -ENODEV; 994 * resolution as the format (and EFAULT if it couldn't be detected).
1151 995 * With the introduction of VIDIOC_QUERY_DV_TIMINGS there is now a
1152 vid_info = get_video_info(dev); 996 * better way of doing this, but to stay compatible with existing
1153 if (!vid_info) 997 * applications we assume legacy mode every time an application opens
1154 return -EFAULT; 998 * the device. Only if one of the new DV_TIMINGS ioctls is called
1155 999 * will the filehandle go into 'normal' mode where g_fmt returns the
1156 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1000 * last set format.
1001 */
1002 if (fh->legacy_mode) {
1003 struct hdpvr_video_info *vid_info;
1004
1005 vid_info = get_video_info(dev);
1006 if (!vid_info)
1007 return -EFAULT;
1008 f->fmt.pix.width = vid_info->width;
1009 f->fmt.pix.height = vid_info->height;
1010 kfree(vid_info);
1011 } else {
1012 f->fmt.pix.width = dev->width;
1013 f->fmt.pix.height = dev->height;
1014 }
1157 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 1015 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1158 f->fmt.pix.width = vid_info->width;
1159 f->fmt.pix.height = vid_info->height;
1160 f->fmt.pix.sizeimage = dev->bulk_in_size; 1016 f->fmt.pix.sizeimage = dev->bulk_in_size;
1161 f->fmt.pix.colorspace = 0;
1162 f->fmt.pix.bytesperline = 0; 1017 f->fmt.pix.bytesperline = 0;
1163 f->fmt.pix.field = V4L2_FIELD_ANY; 1018 f->fmt.pix.priv = 0;
1164 1019 if (f->fmt.pix.width == 720) {
1165 kfree(vid_info); 1020 /* SDTV formats */
1021 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1022 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1023 } else {
1024 /* HDTV formats */
1025 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE240M;
1026 f->fmt.pix.field = V4L2_FIELD_NONE;
1027 }
1166 return 0; 1028 return 0;
1167} 1029}
1168 1030
1169static int vidioc_encoder_cmd(struct file *filp, void *priv, 1031static int vidioc_encoder_cmd(struct file *filp, void *priv,
1170 struct v4l2_encoder_cmd *a) 1032 struct v4l2_encoder_cmd *a)
1171{ 1033{
1172 struct hdpvr_fh *fh = filp->private_data; 1034 struct hdpvr_device *dev = video_drvdata(filp);
1173 struct hdpvr_device *dev = fh->dev; 1035 int res = 0;
1174 int res;
1175 1036
1176 mutex_lock(&dev->io_mutex); 1037 mutex_lock(&dev->io_mutex);
1038 a->flags = 0;
1177 1039
1178 memset(&a->raw, 0, sizeof(a->raw));
1179 switch (a->cmd) { 1040 switch (a->cmd) {
1180 case V4L2_ENC_CMD_START: 1041 case V4L2_ENC_CMD_START:
1181 a->flags = 0; 1042 if (dev->owner && filp->private_data != dev->owner) {
1043 res = -EBUSY;
1044 break;
1045 }
1046 if (dev->status == STATUS_STREAMING)
1047 break;
1182 res = hdpvr_start_streaming(dev); 1048 res = hdpvr_start_streaming(dev);
1049 if (!res)
1050 dev->owner = filp->private_data;
1051 else
1052 dev->status = STATUS_IDLE;
1183 break; 1053 break;
1184 case V4L2_ENC_CMD_STOP: 1054 case V4L2_ENC_CMD_STOP:
1055 if (dev->owner && filp->private_data != dev->owner) {
1056 res = -EBUSY;
1057 break;
1058 }
1059 if (dev->status == STATUS_IDLE)
1060 break;
1185 res = hdpvr_stop_streaming(dev); 1061 res = hdpvr_stop_streaming(dev);
1062 if (!res)
1063 dev->owner = NULL;
1186 break; 1064 break;
1187 default: 1065 default:
1188 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, 1066 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
1189 "Unsupported encoder cmd %d\n", a->cmd); 1067 "Unsupported encoder cmd %d\n", a->cmd);
1190 res = -EINVAL; 1068 res = -EINVAL;
1069 break;
1191 } 1070 }
1071
1192 mutex_unlock(&dev->io_mutex); 1072 mutex_unlock(&dev->io_mutex);
1193 return res; 1073 return res;
1194} 1074}
@@ -1196,6 +1076,7 @@ static int vidioc_encoder_cmd(struct file *filp, void *priv,
1196static int vidioc_try_encoder_cmd(struct file *filp, void *priv, 1076static int vidioc_try_encoder_cmd(struct file *filp, void *priv,
1197 struct v4l2_encoder_cmd *a) 1077 struct v4l2_encoder_cmd *a)
1198{ 1078{
1079 a->flags = 0;
1199 switch (a->cmd) { 1080 switch (a->cmd) {
1200 case V4L2_ENC_CMD_START: 1081 case V4L2_ENC_CMD_START:
1201 case V4L2_ENC_CMD_STOP: 1082 case V4L2_ENC_CMD_STOP:
@@ -1208,22 +1089,28 @@ static int vidioc_try_encoder_cmd(struct file *filp, void *priv,
1208static const struct v4l2_ioctl_ops hdpvr_ioctl_ops = { 1089static const struct v4l2_ioctl_ops hdpvr_ioctl_ops = {
1209 .vidioc_querycap = vidioc_querycap, 1090 .vidioc_querycap = vidioc_querycap,
1210 .vidioc_s_std = vidioc_s_std, 1091 .vidioc_s_std = vidioc_s_std,
1092 .vidioc_g_std = vidioc_g_std,
1093 .vidioc_querystd = vidioc_querystd,
1094 .vidioc_s_dv_timings = vidioc_s_dv_timings,
1095 .vidioc_g_dv_timings = vidioc_g_dv_timings,
1096 .vidioc_query_dv_timings= vidioc_query_dv_timings,
1097 .vidioc_enum_dv_timings = vidioc_enum_dv_timings,
1098 .vidioc_dv_timings_cap = vidioc_dv_timings_cap,
1211 .vidioc_enum_input = vidioc_enum_input, 1099 .vidioc_enum_input = vidioc_enum_input,
1212 .vidioc_g_input = vidioc_g_input, 1100 .vidioc_g_input = vidioc_g_input,
1213 .vidioc_s_input = vidioc_s_input, 1101 .vidioc_s_input = vidioc_s_input,
1214 .vidioc_enumaudio = vidioc_enumaudio, 1102 .vidioc_enumaudio = vidioc_enumaudio,
1215 .vidioc_g_audio = vidioc_g_audio, 1103 .vidioc_g_audio = vidioc_g_audio,
1216 .vidioc_s_audio = vidioc_s_audio, 1104 .vidioc_s_audio = vidioc_s_audio,
1217 .vidioc_queryctrl = vidioc_queryctrl, 1105 .vidioc_enum_fmt_vid_cap= vidioc_enum_fmt_vid_cap,
1218 .vidioc_g_ctrl = vidioc_g_ctrl, 1106 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1219 .vidioc_s_ctrl = vidioc_s_ctrl, 1107 .vidioc_s_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1220 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls, 1108 .vidioc_try_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1221 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1222 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1223 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1224 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1225 .vidioc_encoder_cmd = vidioc_encoder_cmd, 1109 .vidioc_encoder_cmd = vidioc_encoder_cmd,
1226 .vidioc_try_encoder_cmd = vidioc_try_encoder_cmd, 1110 .vidioc_try_encoder_cmd = vidioc_try_encoder_cmd,
1111 .vidioc_log_status = v4l2_ctrl_log_status,
1112 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1113 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1227}; 1114};
1228 1115
1229static void hdpvr_device_release(struct video_device *vdev) 1116static void hdpvr_device_release(struct video_device *vdev)
@@ -1236,9 +1123,10 @@ static void hdpvr_device_release(struct video_device *vdev)
1236 mutex_unlock(&dev->io_mutex); 1123 mutex_unlock(&dev->io_mutex);
1237 1124
1238 v4l2_device_unregister(&dev->v4l2_dev); 1125 v4l2_device_unregister(&dev->v4l2_dev);
1126 v4l2_ctrl_handler_free(&dev->hdl);
1239 1127
1240 /* deregister I2C adapter */ 1128 /* deregister I2C adapter */
1241#if defined(CONFIG_I2C) || (CONFIG_I2C_MODULE) 1129#if IS_ENABLED(CONFIG_I2C)
1242 mutex_lock(&dev->i2c_mutex); 1130 mutex_lock(&dev->i2c_mutex);
1243 i2c_del_adapter(&dev->i2c_adapter); 1131 i2c_del_adapter(&dev->i2c_adapter);
1244 mutex_unlock(&dev->i2c_mutex); 1132 mutex_unlock(&dev->i2c_mutex);
@@ -1249,41 +1137,112 @@ static void hdpvr_device_release(struct video_device *vdev)
1249} 1137}
1250 1138
1251static const struct video_device hdpvr_video_template = { 1139static const struct video_device hdpvr_video_template = {
1252/* .type = VFL_TYPE_GRABBER, */
1253/* .type2 = VID_TYPE_CAPTURE | VID_TYPE_MPEG_ENCODER, */
1254 .fops = &hdpvr_fops, 1140 .fops = &hdpvr_fops,
1255 .release = hdpvr_device_release, 1141 .release = hdpvr_device_release,
1256 .ioctl_ops = &hdpvr_ioctl_ops, 1142 .ioctl_ops = &hdpvr_ioctl_ops,
1257 .tvnorms = 1143 .tvnorms = V4L2_STD_ALL,
1258 V4L2_STD_NTSC | V4L2_STD_SECAM | V4L2_STD_PAL_B | 1144};
1259 V4L2_STD_PAL_G | V4L2_STD_PAL_H | V4L2_STD_PAL_I | 1145
1260 V4L2_STD_PAL_D | V4L2_STD_PAL_M | V4L2_STD_PAL_N | 1146static const struct v4l2_ctrl_ops hdpvr_ctrl_ops = {
1261 V4L2_STD_PAL_60, 1147 .try_ctrl = hdpvr_try_ctrl,
1262 .current_norm = V4L2_STD_NTSC | V4L2_STD_PAL_M | 1148 .s_ctrl = hdpvr_s_ctrl,
1263 V4L2_STD_PAL_60,
1264}; 1149};
1265 1150
1266int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent, 1151int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
1267 int devnum) 1152 int devnum)
1268{ 1153{
1154 struct v4l2_ctrl_handler *hdl = &dev->hdl;
1155 bool ac3 = dev->flags & HDPVR_FLAG_AC3_CAP;
1156 int res;
1157
1158 dev->cur_std = V4L2_STD_525_60;
1159 dev->width = 720;
1160 dev->height = 480;
1161 dev->cur_dv_timings = hdpvr_dv_timings[HDPVR_DEF_DV_TIMINGS_IDX];
1162 v4l2_ctrl_handler_init(hdl, 11);
1163 if (dev->fw_ver > 0x15) {
1164 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1165 V4L2_CID_BRIGHTNESS, 0x0, 0xff, 1, 0x80);
1166 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1167 V4L2_CID_CONTRAST, 0x0, 0xff, 1, 0x40);
1168 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1169 V4L2_CID_SATURATION, 0x0, 0xff, 1, 0x40);
1170 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1171 V4L2_CID_HUE, 0x0, 0x1e, 1, 0xf);
1172 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1173 V4L2_CID_SHARPNESS, 0x0, 0xff, 1, 0x80);
1174 } else {
1175 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1176 V4L2_CID_BRIGHTNESS, 0x0, 0xff, 1, 0x86);
1177 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1178 V4L2_CID_CONTRAST, 0x0, 0xff, 1, 0x80);
1179 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1180 V4L2_CID_SATURATION, 0x0, 0xff, 1, 0x80);
1181 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1182 V4L2_CID_HUE, 0x0, 0xff, 1, 0x80);
1183 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1184 V4L2_CID_SHARPNESS, 0x0, 0xff, 1, 0x80);
1185 }
1186
1187 v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
1188 V4L2_CID_MPEG_STREAM_TYPE,
1189 V4L2_MPEG_STREAM_TYPE_MPEG2_TS,
1190 0x1, V4L2_MPEG_STREAM_TYPE_MPEG2_TS);
1191 v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
1192 V4L2_CID_MPEG_AUDIO_ENCODING,
1193 ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 : V4L2_MPEG_AUDIO_ENCODING_AAC,
1194 0x7, V4L2_MPEG_AUDIO_ENCODING_AAC);
1195 v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
1196 V4L2_CID_MPEG_VIDEO_ENCODING,
1197 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 0x3,
1198 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
1199
1200 dev->video_mode = v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
1201 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
1202 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 0,
1203 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
1204
1205 dev->video_bitrate = v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1206 V4L2_CID_MPEG_VIDEO_BITRATE,
1207 1000000, 13500000, 100000, 6500000);
1208 dev->video_bitrate_peak = v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1209 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
1210 1100000, 20200000, 100000, 9000000);
1211 dev->v4l2_dev.ctrl_handler = hdl;
1212 if (hdl->error) {
1213 res = hdl->error;
1214 v4l2_err(&dev->v4l2_dev, "Could not register controls\n");
1215 goto error;
1216 }
1217 v4l2_ctrl_cluster(3, &dev->video_mode);
1218 res = v4l2_ctrl_handler_setup(hdl);
1219 if (res < 0) {
1220 v4l2_err(&dev->v4l2_dev, "Could not setup controls\n");
1221 goto error;
1222 }
1223
1269 /* setup and register video device */ 1224 /* setup and register video device */
1270 dev->video_dev = video_device_alloc(); 1225 dev->video_dev = video_device_alloc();
1271 if (!dev->video_dev) { 1226 if (!dev->video_dev) {
1272 v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n"); 1227 v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n");
1228 res = -ENOMEM;
1273 goto error; 1229 goto error;
1274 } 1230 }
1275 1231
1276 *(dev->video_dev) = hdpvr_video_template; 1232 *dev->video_dev = hdpvr_video_template;
1277 strcpy(dev->video_dev->name, "Hauppauge HD PVR"); 1233 strcpy(dev->video_dev->name, "Hauppauge HD PVR");
1278 dev->video_dev->parent = parent; 1234 dev->video_dev->v4l2_dev = &dev->v4l2_dev;
1279 video_set_drvdata(dev->video_dev, dev); 1235 video_set_drvdata(dev->video_dev, dev);
1236 set_bit(V4L2_FL_USE_FH_PRIO, &dev->video_dev->flags);
1280 1237
1281 if (video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum)) { 1238 res = video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum);
1239 if (res < 0) {
1282 v4l2_err(&dev->v4l2_dev, "video_device registration failed\n"); 1240 v4l2_err(&dev->v4l2_dev, "video_device registration failed\n");
1283 goto error; 1241 goto error;
1284 } 1242 }
1285 1243
1286 return 0; 1244 return 0;
1287error: 1245error:
1288 return -ENOMEM; 1246 v4l2_ctrl_handler_free(hdl);
1247 return res;
1289} 1248}
diff --git a/drivers/media/usb/hdpvr/hdpvr.h b/drivers/media/usb/hdpvr/hdpvr.h
index fea3c6926997..1478f3d57630 100644
--- a/drivers/media/usb/hdpvr/hdpvr.h
+++ b/drivers/media/usb/hdpvr/hdpvr.h
@@ -16,6 +16,7 @@
16#include <linux/videodev2.h> 16#include <linux/videodev2.h>
17 17
18#include <media/v4l2-device.h> 18#include <media/v4l2-device.h>
19#include <media/v4l2-ctrls.h>
19#include <media/ir-kbd-i2c.h> 20#include <media/ir-kbd-i2c.h>
20 21
21#define HDPVR_MAX 8 22#define HDPVR_MAX 8
@@ -37,6 +38,7 @@
37#define HDPVR_FIRMWARE_VERSION_AC3 0x0d 38#define HDPVR_FIRMWARE_VERSION_AC3 0x0d
38#define HDPVR_FIRMWARE_VERSION_0X12 0x12 39#define HDPVR_FIRMWARE_VERSION_0X12 0x12
39#define HDPVR_FIRMWARE_VERSION_0X15 0x15 40#define HDPVR_FIRMWARE_VERSION_0X15 0x15
41#define HDPVR_FIRMWARE_VERSION_0X1E 0x1e
40 42
41/* #define HDPVR_DEBUG */ 43/* #define HDPVR_DEBUG */
42 44
@@ -65,10 +67,19 @@ struct hdpvr_options {
65struct hdpvr_device { 67struct hdpvr_device {
66 /* the v4l device for this device */ 68 /* the v4l device for this device */
67 struct video_device *video_dev; 69 struct video_device *video_dev;
70 /* the control handler for this device */
71 struct v4l2_ctrl_handler hdl;
68 /* the usb device for this device */ 72 /* the usb device for this device */
69 struct usb_device *udev; 73 struct usb_device *udev;
70 /* v4l2-device unused */ 74 /* v4l2-device unused */
71 struct v4l2_device v4l2_dev; 75 struct v4l2_device v4l2_dev;
76 struct { /* video mode/bitrate control cluster */
77 struct v4l2_ctrl *video_mode;
78 struct v4l2_ctrl *video_bitrate;
79 struct v4l2_ctrl *video_bitrate_peak;
80 };
81 /* v4l2 format */
82 uint width, height;
72 83
73 /* the max packet size of the bulk endpoint */ 84 /* the max packet size of the bulk endpoint */
74 size_t bulk_in_size; 85 size_t bulk_in_size;
@@ -77,11 +88,11 @@ struct hdpvr_device {
77 88
78 /* holds the current device status */ 89 /* holds the current device status */
79 __u8 status; 90 __u8 status;
80 /* count the number of openers */
81 uint open_count;
82 91
83 /* holds the cureent set options */ 92 /* holds the current set options */
84 struct hdpvr_options options; 93 struct hdpvr_options options;
94 v4l2_std_id cur_std;
95 struct v4l2_dv_timings cur_dv_timings;
85 96
86 uint flags; 97 uint flags;
87 98
@@ -99,6 +110,8 @@ struct hdpvr_device {
99 struct workqueue_struct *workqueue; 110 struct workqueue_struct *workqueue;
100 /**/ 111 /**/
101 struct work_struct worker; 112 struct work_struct worker;
113 /* current stream owner */
114 struct v4l2_fh *owner;
102 115
103 /* I2C adapter */ 116 /* I2C adapter */
104 struct i2c_adapter i2c_adapter; 117 struct i2c_adapter i2c_adapter;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index 299751a8b06b..e11267f35d87 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -5165,7 +5165,7 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
5165 5165
5166 5166
5167int pvr2_hdw_register_access(struct pvr2_hdw *hdw, 5167int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
5168 struct v4l2_dbg_match *match, u64 reg_id, 5168 const struct v4l2_dbg_match *match, u64 reg_id,
5169 int setFl, u64 *val_ptr) 5169 int setFl, u64 *val_ptr)
5170{ 5170{
5171#ifdef CONFIG_VIDEO_ADV_DEBUG 5171#ifdef CONFIG_VIDEO_ADV_DEBUG
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
index 8060fc666eeb..91bae930cd79 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
@@ -240,7 +240,7 @@ void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
240 setFl - true to set the register, false to read it 240 setFl - true to set the register, false to read it
241 val_ptr - storage location for source / result. */ 241 val_ptr - storage location for source / result. */
242int pvr2_hdw_register_access(struct pvr2_hdw *, 242int pvr2_hdw_register_access(struct pvr2_hdw *,
243 struct v4l2_dbg_match *match, u64 reg_id, 243 const struct v4l2_dbg_match *match, u64 reg_id,
244 int setFl, u64 *val_ptr); 244 int setFl, u64 *val_ptr);
245 245
246/* The following entry points are all lower level things you normally don't 246/* The following entry points are all lower level things you normally don't
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index 34c3b6e80e86..a8a65fa57930 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -196,13 +196,13 @@ static int pvr2_g_std(struct file *file, void *priv, v4l2_std_id *std)
196 return ret; 196 return ret;
197} 197}
198 198
199static int pvr2_s_std(struct file *file, void *priv, v4l2_std_id *std) 199static int pvr2_s_std(struct file *file, void *priv, v4l2_std_id std)
200{ 200{
201 struct pvr2_v4l2_fh *fh = file->private_data; 201 struct pvr2_v4l2_fh *fh = file->private_data;
202 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; 202 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
203 203
204 return pvr2_ctrl_set_value( 204 return pvr2_ctrl_set_value(
205 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_STDCUR), *std); 205 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_STDCUR), std);
206} 206}
207 207
208static int pvr2_querystd(struct file *file, void *priv, v4l2_std_id *std) 208static int pvr2_querystd(struct file *file, void *priv, v4l2_std_id *std)
@@ -352,7 +352,7 @@ static int pvr2_g_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
352 return pvr2_hdw_get_tuner_status(hdw, vt); 352 return pvr2_hdw_get_tuner_status(hdw, vt);
353} 353}
354 354
355static int pvr2_s_tuner(struct file *file, void *priv, struct v4l2_tuner *vt) 355static int pvr2_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *vt)
356{ 356{
357 struct pvr2_v4l2_fh *fh = file->private_data; 357 struct pvr2_v4l2_fh *fh = file->private_data;
358 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; 358 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
@@ -365,7 +365,7 @@ static int pvr2_s_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
365 vt->audmode); 365 vt->audmode);
366} 366}
367 367
368static int pvr2_s_frequency(struct file *file, void *priv, struct v4l2_frequency *vf) 368static int pvr2_s_frequency(struct file *file, void *priv, const struct v4l2_frequency *vf)
369{ 369{
370 struct pvr2_v4l2_fh *fh = file->private_data; 370 struct pvr2_v4l2_fh *fh = file->private_data;
371 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; 371 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
@@ -815,7 +815,7 @@ static int pvr2_g_register(struct file *file, void *priv, struct v4l2_dbg_regist
815 return ret; 815 return ret;
816} 816}
817 817
818static int pvr2_s_register(struct file *file, void *priv, struct v4l2_dbg_register *req) 818static int pvr2_s_register(struct file *file, void *priv, const struct v4l2_dbg_register *req)
819{ 819{
820 struct pvr2_v4l2_fh *fh = file->private_data; 820 struct pvr2_v4l2_fh *fh = file->private_data;
821 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; 821 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 5ec15cb1ed26..77bbf7889659 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -1001,6 +1001,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1001 pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf); 1001 pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf);
1002 pdev->vb_queue.ops = &pwc_vb_queue_ops; 1002 pdev->vb_queue.ops = &pwc_vb_queue_ops;
1003 pdev->vb_queue.mem_ops = &vb2_vmalloc_memops; 1003 pdev->vb_queue.mem_ops = &vb2_vmalloc_memops;
1004 pdev->vb_queue.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1004 rc = vb2_queue_init(&pdev->vb_queue); 1005 rc = vb2_queue_init(&pdev->vb_queue);
1005 if (rc < 0) { 1006 if (rc < 0) {
1006 PWC_ERROR("Oops, could not initialize vb2 queue.\n"); 1007 PWC_ERROR("Oops, could not initialize vb2 queue.\n");
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 498c57ea5d32..ab97e7d0b4f2 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -43,12 +43,14 @@
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/videodev2.h> 44#include <linux/videodev2.h>
45#include <linux/mm.h> 45#include <linux/mm.h>
46#include <linux/vmalloc.h>
47#include <linux/usb.h>
46#include <media/videobuf-vmalloc.h> 48#include <media/videobuf-vmalloc.h>
47#include <media/v4l2-common.h> 49#include <media/v4l2-common.h>
48#include <media/v4l2-device.h> 50#include <media/v4l2-device.h>
49#include <media/v4l2-ioctl.h> 51#include <media/v4l2-ioctl.h>
50#include <linux/vmalloc.h> 52#include <media/v4l2-ctrls.h>
51#include <linux/usb.h> 53#include <media/v4l2-event.h>
52 54
53#define S2255_VERSION "1.22.1" 55#define S2255_VERSION "1.22.1"
54#define FIRMWARE_FILE_NAME "f2255usb.bin" 56#define FIRMWARE_FILE_NAME "f2255usb.bin"
@@ -217,12 +219,15 @@ struct s2255_dev;
217 219
218struct s2255_channel { 220struct s2255_channel {
219 struct video_device vdev; 221 struct video_device vdev;
222 struct v4l2_ctrl_handler hdl;
223 struct v4l2_ctrl *jpegqual_ctrl;
220 int resources; 224 int resources;
221 struct s2255_dmaqueue vidq; 225 struct s2255_dmaqueue vidq;
222 struct s2255_bufferi buffer; 226 struct s2255_bufferi buffer;
223 struct s2255_mode mode; 227 struct s2255_mode mode;
228 v4l2_std_id std;
224 /* jpeg compression */ 229 /* jpeg compression */
225 struct v4l2_jpegcompression jc; 230 unsigned jpegqual;
226 /* capture parameters (for high quality mode full size) */ 231 /* capture parameters (for high quality mode full size) */
227 struct v4l2_captureparm cap_parm; 232 struct v4l2_captureparm cap_parm;
228 int cur_frame; 233 int cur_frame;
@@ -292,6 +297,8 @@ struct s2255_buffer {
292}; 297};
293 298
294struct s2255_fh { 299struct s2255_fh {
300 /* this must be the first field in this struct */
301 struct v4l2_fh fh;
295 struct s2255_dev *dev; 302 struct s2255_dev *dev;
296 struct videobuf_queue vb_vidq; 303 struct videobuf_queue vb_vidq;
297 enum v4l2_buf_type type; 304 enum v4l2_buf_type type;
@@ -306,7 +313,7 @@ struct s2255_fh {
306/* Need DSP version 5+ for video status feature */ 313/* Need DSP version 5+ for video status feature */
307#define S2255_MIN_DSP_STATUS 5 314#define S2255_MIN_DSP_STATUS 5
308#define S2255_MIN_DSP_COLORFILTER 8 315#define S2255_MIN_DSP_COLORFILTER 8
309#define S2255_NORMS (V4L2_STD_PAL | V4L2_STD_NTSC) 316#define S2255_NORMS (V4L2_STD_ALL)
310 317
311/* private V4L2 controls */ 318/* private V4L2 controls */
312 319
@@ -336,7 +343,7 @@ struct s2255_fh {
336 */ 343 */
337#define S2255_V4L2_YC_ON 1 344#define S2255_V4L2_YC_ON 1
338#define S2255_V4L2_YC_OFF 0 345#define S2255_V4L2_YC_OFF 0
339#define V4L2_CID_PRIVATE_COLORFILTER (V4L2_CID_PRIVATE_BASE + 0) 346#define V4L2_CID_S2255_COLORFILTER (V4L2_CID_USER_S2255_BASE + 0)
340 347
341/* frame prefix size (sent once every frame) */ 348/* frame prefix size (sent once every frame) */
342#define PREFIX_SIZE 512 349#define PREFIX_SIZE 512
@@ -409,11 +416,6 @@ MODULE_DEVICE_TABLE(usb, s2255_table);
409/* JPEG formats must be defined last to support jpeg_enable parameter */ 416/* JPEG formats must be defined last to support jpeg_enable parameter */
410static const struct s2255_fmt formats[] = { 417static const struct s2255_fmt formats[] = {
411 { 418 {
412 .name = "4:2:2, planar, YUV422P",
413 .fourcc = V4L2_PIX_FMT_YUV422P,
414 .depth = 16
415
416 }, {
417 .name = "4:2:2, packed, YUYV", 419 .name = "4:2:2, packed, YUYV",
418 .fourcc = V4L2_PIX_FMT_YUYV, 420 .fourcc = V4L2_PIX_FMT_YUYV,
419 .depth = 16 421 .depth = 16
@@ -423,6 +425,11 @@ static const struct s2255_fmt formats[] = {
423 .fourcc = V4L2_PIX_FMT_UYVY, 425 .fourcc = V4L2_PIX_FMT_UYVY,
424 .depth = 16 426 .depth = 16
425 }, { 427 }, {
428 .name = "4:2:2, planar, YUV422P",
429 .fourcc = V4L2_PIX_FMT_YUV422P,
430 .depth = 16
431
432 }, {
426 .name = "8bpp GREY", 433 .name = "8bpp GREY",
427 .fourcc = V4L2_PIX_FMT_GREY, 434 .fourcc = V4L2_PIX_FMT_GREY,
428 .depth = 8 435 .depth = 8
@@ -437,27 +444,27 @@ static const struct s2255_fmt formats[] = {
437 } 444 }
438}; 445};
439 446
440static int norm_maxw(struct video_device *vdev) 447static int norm_maxw(struct s2255_channel *channel)
441{ 448{
442 return (vdev->current_norm & V4L2_STD_NTSC) ? 449 return (channel->std & V4L2_STD_525_60) ?
443 LINE_SZ_4CIFS_NTSC : LINE_SZ_4CIFS_PAL; 450 LINE_SZ_4CIFS_NTSC : LINE_SZ_4CIFS_PAL;
444} 451}
445 452
446static int norm_maxh(struct video_device *vdev) 453static int norm_maxh(struct s2255_channel *channel)
447{ 454{
448 return (vdev->current_norm & V4L2_STD_NTSC) ? 455 return (channel->std & V4L2_STD_525_60) ?
449 (NUM_LINES_1CIFS_NTSC * 2) : (NUM_LINES_1CIFS_PAL * 2); 456 (NUM_LINES_1CIFS_NTSC * 2) : (NUM_LINES_1CIFS_PAL * 2);
450} 457}
451 458
452static int norm_minw(struct video_device *vdev) 459static int norm_minw(struct s2255_channel *channel)
453{ 460{
454 return (vdev->current_norm & V4L2_STD_NTSC) ? 461 return (channel->std & V4L2_STD_525_60) ?
455 LINE_SZ_1CIFS_NTSC : LINE_SZ_1CIFS_PAL; 462 LINE_SZ_1CIFS_NTSC : LINE_SZ_1CIFS_PAL;
456} 463}
457 464
458static int norm_minh(struct video_device *vdev) 465static int norm_minh(struct s2255_channel *channel)
459{ 466{
460 return (vdev->current_norm & V4L2_STD_NTSC) ? 467 return (channel->std & V4L2_STD_525_60) ?
461 (NUM_LINES_1CIFS_NTSC) : (NUM_LINES_1CIFS_PAL); 468 (NUM_LINES_1CIFS_NTSC) : (NUM_LINES_1CIFS_PAL);
462} 469}
463 470
@@ -515,7 +522,7 @@ static void s2255_timer(unsigned long user_data)
515 522
516 523
517/* this loads the firmware asynchronously. 524/* this loads the firmware asynchronously.
518 Originally this was done synchroously in probe. 525 Originally this was done synchronously in probe.
519 But it is better to load it asynchronously here than block 526 But it is better to load it asynchronously here than block
520 inside the probe function. Blocking inside probe affects boot time. 527 inside the probe function. Blocking inside probe affects boot time.
521 FW loading is triggered by the timer in the probe function 528 FW loading is triggered by the timer in the probe function
@@ -719,10 +726,10 @@ static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
719 if (channel->fmt == NULL) 726 if (channel->fmt == NULL)
720 return -EINVAL; 727 return -EINVAL;
721 728
722 if ((w < norm_minw(&channel->vdev)) || 729 if ((w < norm_minw(channel)) ||
723 (w > norm_maxw(&channel->vdev)) || 730 (w > norm_maxw(channel)) ||
724 (h < norm_minh(&channel->vdev)) || 731 (h < norm_minh(channel)) ||
725 (h > norm_maxh(&channel->vdev))) { 732 (h > norm_maxh(channel))) {
726 dprintk(4, "invalid buffer prepare\n"); 733 dprintk(4, "invalid buffer prepare\n");
727 return -EINVAL; 734 return -EINVAL;
728 } 735 }
@@ -810,37 +817,17 @@ static void res_free(struct s2255_fh *fh)
810 dprintk(1, "res: put\n"); 817 dprintk(1, "res: put\n");
811} 818}
812 819
813static int vidioc_querymenu(struct file *file, void *priv,
814 struct v4l2_querymenu *qmenu)
815{
816 static const char *colorfilter[] = {
817 "Off",
818 "On",
819 NULL
820 };
821 if (qmenu->id == V4L2_CID_PRIVATE_COLORFILTER) {
822 int i;
823 const char **menu_items = colorfilter;
824 for (i = 0; i < qmenu->index && menu_items[i]; i++)
825 ; /* do nothing (from v4l2-common.c) */
826 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
827 return -EINVAL;
828 strlcpy(qmenu->name, menu_items[qmenu->index],
829 sizeof(qmenu->name));
830 return 0;
831 }
832 return v4l2_ctrl_query_menu(qmenu, NULL, NULL);
833}
834
835static int vidioc_querycap(struct file *file, void *priv, 820static int vidioc_querycap(struct file *file, void *priv,
836 struct v4l2_capability *cap) 821 struct v4l2_capability *cap)
837{ 822{
838 struct s2255_fh *fh = file->private_data; 823 struct s2255_fh *fh = file->private_data;
839 struct s2255_dev *dev = fh->dev; 824 struct s2255_dev *dev = fh->dev;
825
840 strlcpy(cap->driver, "s2255", sizeof(cap->driver)); 826 strlcpy(cap->driver, "s2255", sizeof(cap->driver));
841 strlcpy(cap->card, "s2255", sizeof(cap->card)); 827 strlcpy(cap->card, "s2255", sizeof(cap->card));
842 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); 828 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
843 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 829 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
830 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
844 return 0; 831 return 0;
845} 832}
846 833
@@ -865,13 +852,20 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
865{ 852{
866 struct s2255_fh *fh = priv; 853 struct s2255_fh *fh = priv;
867 struct s2255_channel *channel = fh->channel; 854 struct s2255_channel *channel = fh->channel;
855 int is_ntsc = channel->std & V4L2_STD_525_60;
868 856
869 f->fmt.pix.width = channel->width; 857 f->fmt.pix.width = channel->width;
870 f->fmt.pix.height = channel->height; 858 f->fmt.pix.height = channel->height;
871 f->fmt.pix.field = fh->vb_vidq.field; 859 if (f->fmt.pix.height >=
860 (is_ntsc ? NUM_LINES_1CIFS_NTSC : NUM_LINES_1CIFS_PAL) * 2)
861 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
862 else
863 f->fmt.pix.field = V4L2_FIELD_TOP;
872 f->fmt.pix.pixelformat = channel->fmt->fourcc; 864 f->fmt.pix.pixelformat = channel->fmt->fourcc;
873 f->fmt.pix.bytesperline = f->fmt.pix.width * (channel->fmt->depth >> 3); 865 f->fmt.pix.bytesperline = f->fmt.pix.width * (channel->fmt->depth >> 3);
874 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 866 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
867 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
868 f->fmt.pix.priv = 0;
875 return 0; 869 return 0;
876} 870}
877 871
@@ -880,12 +874,9 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
880{ 874{
881 const struct s2255_fmt *fmt; 875 const struct s2255_fmt *fmt;
882 enum v4l2_field field; 876 enum v4l2_field field;
883 int b_any_field = 0;
884 struct s2255_fh *fh = priv; 877 struct s2255_fh *fh = priv;
885 struct s2255_channel *channel = fh->channel; 878 struct s2255_channel *channel = fh->channel;
886 int is_ntsc; 879 int is_ntsc = channel->std & V4L2_STD_525_60;
887 is_ntsc =
888 (channel->vdev.current_norm & V4L2_STD_NTSC) ? 1 : 0;
889 880
890 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 881 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
891 882
@@ -893,8 +884,6 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
893 return -EINVAL; 884 return -EINVAL;
894 885
895 field = f->fmt.pix.field; 886 field = f->fmt.pix.field;
896 if (field == V4L2_FIELD_ANY)
897 b_any_field = 1;
898 887
899 dprintk(50, "%s NTSC: %d suggested width: %d, height: %d\n", 888 dprintk(50, "%s NTSC: %d suggested width: %d, height: %d\n",
900 __func__, is_ntsc, f->fmt.pix.width, f->fmt.pix.height); 889 __func__, is_ntsc, f->fmt.pix.width, f->fmt.pix.height);
@@ -902,24 +891,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
902 /* NTSC */ 891 /* NTSC */
903 if (f->fmt.pix.height >= NUM_LINES_1CIFS_NTSC * 2) { 892 if (f->fmt.pix.height >= NUM_LINES_1CIFS_NTSC * 2) {
904 f->fmt.pix.height = NUM_LINES_1CIFS_NTSC * 2; 893 f->fmt.pix.height = NUM_LINES_1CIFS_NTSC * 2;
905 if (b_any_field) { 894 field = V4L2_FIELD_INTERLACED;
906 field = V4L2_FIELD_SEQ_TB;
907 } else if (!((field == V4L2_FIELD_INTERLACED) ||
908 (field == V4L2_FIELD_SEQ_TB) ||
909 (field == V4L2_FIELD_INTERLACED_TB))) {
910 dprintk(1, "unsupported field setting\n");
911 return -EINVAL;
912 }
913 } else { 895 } else {
914 f->fmt.pix.height = NUM_LINES_1CIFS_NTSC; 896 f->fmt.pix.height = NUM_LINES_1CIFS_NTSC;
915 if (b_any_field) { 897 field = V4L2_FIELD_TOP;
916 field = V4L2_FIELD_TOP;
917 } else if (!((field == V4L2_FIELD_TOP) ||
918 (field == V4L2_FIELD_BOTTOM))) {
919 dprintk(1, "unsupported field setting\n");
920 return -EINVAL;
921 }
922
923 } 898 }
924 if (f->fmt.pix.width >= LINE_SZ_4CIFS_NTSC) 899 if (f->fmt.pix.width >= LINE_SZ_4CIFS_NTSC)
925 f->fmt.pix.width = LINE_SZ_4CIFS_NTSC; 900 f->fmt.pix.width = LINE_SZ_4CIFS_NTSC;
@@ -933,41 +908,25 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
933 /* PAL */ 908 /* PAL */
934 if (f->fmt.pix.height >= NUM_LINES_1CIFS_PAL * 2) { 909 if (f->fmt.pix.height >= NUM_LINES_1CIFS_PAL * 2) {
935 f->fmt.pix.height = NUM_LINES_1CIFS_PAL * 2; 910 f->fmt.pix.height = NUM_LINES_1CIFS_PAL * 2;
936 if (b_any_field) { 911 field = V4L2_FIELD_INTERLACED;
937 field = V4L2_FIELD_SEQ_TB;
938 } else if (!((field == V4L2_FIELD_INTERLACED) ||
939 (field == V4L2_FIELD_SEQ_TB) ||
940 (field == V4L2_FIELD_INTERLACED_TB))) {
941 dprintk(1, "unsupported field setting\n");
942 return -EINVAL;
943 }
944 } else { 912 } else {
945 f->fmt.pix.height = NUM_LINES_1CIFS_PAL; 913 f->fmt.pix.height = NUM_LINES_1CIFS_PAL;
946 if (b_any_field) { 914 field = V4L2_FIELD_TOP;
947 field = V4L2_FIELD_TOP;
948 } else if (!((field == V4L2_FIELD_TOP) ||
949 (field == V4L2_FIELD_BOTTOM))) {
950 dprintk(1, "unsupported field setting\n");
951 return -EINVAL;
952 }
953 } 915 }
954 if (f->fmt.pix.width >= LINE_SZ_4CIFS_PAL) { 916 if (f->fmt.pix.width >= LINE_SZ_4CIFS_PAL)
955 f->fmt.pix.width = LINE_SZ_4CIFS_PAL; 917 f->fmt.pix.width = LINE_SZ_4CIFS_PAL;
956 field = V4L2_FIELD_SEQ_TB; 918 else if (f->fmt.pix.width >= LINE_SZ_2CIFS_PAL)
957 } else if (f->fmt.pix.width >= LINE_SZ_2CIFS_PAL) {
958 f->fmt.pix.width = LINE_SZ_2CIFS_PAL; 919 f->fmt.pix.width = LINE_SZ_2CIFS_PAL;
959 field = V4L2_FIELD_TOP; 920 else if (f->fmt.pix.width >= LINE_SZ_1CIFS_PAL)
960 } else if (f->fmt.pix.width >= LINE_SZ_1CIFS_PAL) {
961 f->fmt.pix.width = LINE_SZ_1CIFS_PAL; 921 f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
962 field = V4L2_FIELD_TOP; 922 else
963 } else {
964 f->fmt.pix.width = LINE_SZ_1CIFS_PAL; 923 f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
965 field = V4L2_FIELD_TOP;
966 }
967 } 924 }
968 f->fmt.pix.field = field; 925 f->fmt.pix.field = field;
969 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; 926 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
970 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 927 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
928 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
929 f->fmt.pix.priv = 0;
971 dprintk(50, "%s: set width %d height %d field %d\n", __func__, 930 dprintk(50, "%s: set width %d height %d field %d\n", __func__,
972 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field); 931 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field);
973 return 0; 932 return 0;
@@ -1012,8 +971,8 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1012 channel->height = f->fmt.pix.height; 971 channel->height = f->fmt.pix.height;
1013 fh->vb_vidq.field = f->fmt.pix.field; 972 fh->vb_vidq.field = f->fmt.pix.field;
1014 fh->type = f->type; 973 fh->type = f->type;
1015 if (channel->width > norm_minw(&channel->vdev)) { 974 if (channel->width > norm_minw(channel)) {
1016 if (channel->height > norm_minh(&channel->vdev)) { 975 if (channel->height > norm_minh(channel)) {
1017 if (channel->cap_parm.capturemode & 976 if (channel->cap_parm.capturemode &
1018 V4L2_MODE_HIGHQUALITY) 977 V4L2_MODE_HIGHQUALITY)
1019 mode.scale = SCALE_4CIFSI; 978 mode.scale = SCALE_4CIFSI;
@@ -1035,7 +994,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1035 case V4L2_PIX_FMT_MJPEG: 994 case V4L2_PIX_FMT_MJPEG:
1036 mode.color &= ~MASK_COLOR; 995 mode.color &= ~MASK_COLOR;
1037 mode.color |= COLOR_JPG; 996 mode.color |= COLOR_JPG;
1038 mode.color |= (channel->jc.quality << 8); 997 mode.color |= (channel->jpegqual << 8);
1039 break; 998 break;
1040 case V4L2_PIX_FMT_YUV422P: 999 case V4L2_PIX_FMT_YUV422P:
1041 mode.color &= ~MASK_COLOR; 1000 mode.color &= ~MASK_COLOR;
@@ -1198,6 +1157,8 @@ static int s2255_set_mode(struct s2255_channel *channel,
1198 __le32 *buffer; 1157 __le32 *buffer;
1199 unsigned long chn_rev; 1158 unsigned long chn_rev;
1200 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); 1159 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1160 int i;
1161
1201 chn_rev = G_chnmap[channel->idx]; 1162 chn_rev = G_chnmap[channel->idx];
1202 dprintk(3, "%s channel: %d\n", __func__, channel->idx); 1163 dprintk(3, "%s channel: %d\n", __func__, channel->idx);
1203 /* if JPEG, set the quality */ 1164 /* if JPEG, set the quality */
@@ -1205,7 +1166,7 @@ static int s2255_set_mode(struct s2255_channel *channel,
1205 mode->color &= ~MASK_COLOR; 1166 mode->color &= ~MASK_COLOR;
1206 mode->color |= COLOR_JPG; 1167 mode->color |= COLOR_JPG;
1207 mode->color &= ~MASK_JPG_QUALITY; 1168 mode->color &= ~MASK_JPG_QUALITY;
1208 mode->color |= (channel->jc.quality << 8); 1169 mode->color |= (channel->jpegqual << 8);
1209 } 1170 }
1210 /* save the mode */ 1171 /* save the mode */
1211 channel->mode = *mode; 1172 channel->mode = *mode;
@@ -1220,7 +1181,8 @@ static int s2255_set_mode(struct s2255_channel *channel,
1220 buffer[0] = IN_DATA_TOKEN; 1181 buffer[0] = IN_DATA_TOKEN;
1221 buffer[1] = (__le32) cpu_to_le32(chn_rev); 1182 buffer[1] = (__le32) cpu_to_le32(chn_rev);
1222 buffer[2] = CMD_SET_MODE; 1183 buffer[2] = CMD_SET_MODE;
1223 memcpy(&buffer[3], &channel->mode, sizeof(struct s2255_mode)); 1184 for (i = 0; i < sizeof(struct s2255_mode) / sizeof(u32); i++)
1185 buffer[3 + i] = cpu_to_le32(((u32 *)&channel->mode)[i]);
1224 channel->setmode_ready = 0; 1186 channel->setmode_ready = 0;
1225 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); 1187 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
1226 if (debug) 1188 if (debug)
@@ -1332,12 +1294,14 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1332 return 0; 1294 return 0;
1333} 1295}
1334 1296
1335static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) 1297static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id i)
1336{ 1298{
1337 struct s2255_fh *fh = priv; 1299 struct s2255_fh *fh = priv;
1338 struct s2255_mode mode; 1300 struct s2255_mode mode;
1339 struct videobuf_queue *q = &fh->vb_vidq; 1301 struct videobuf_queue *q = &fh->vb_vidq;
1302 struct s2255_channel *channel = fh->channel;
1340 int ret = 0; 1303 int ret = 0;
1304
1341 mutex_lock(&q->vb_lock); 1305 mutex_lock(&q->vb_lock);
1342 if (videobuf_queue_is_busy(q)) { 1306 if (videobuf_queue_is_busy(q)) {
1343 dprintk(1, "queue busy\n"); 1307 dprintk(1, "queue busy\n");
@@ -1350,24 +1314,30 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
1350 goto out_s_std; 1314 goto out_s_std;
1351 } 1315 }
1352 mode = fh->channel->mode; 1316 mode = fh->channel->mode;
1353 if (*i & V4L2_STD_NTSC) { 1317 if (i & V4L2_STD_525_60) {
1354 dprintk(4, "%s NTSC\n", __func__); 1318 dprintk(4, "%s 60 Hz\n", __func__);
1355 /* if changing format, reset frame decimation/intervals */ 1319 /* if changing format, reset frame decimation/intervals */
1356 if (mode.format != FORMAT_NTSC) { 1320 if (mode.format != FORMAT_NTSC) {
1357 mode.restart = 1; 1321 mode.restart = 1;
1358 mode.format = FORMAT_NTSC; 1322 mode.format = FORMAT_NTSC;
1359 mode.fdec = FDEC_1; 1323 mode.fdec = FDEC_1;
1324 channel->width = LINE_SZ_4CIFS_NTSC;
1325 channel->height = NUM_LINES_4CIFS_NTSC * 2;
1360 } 1326 }
1361 } else if (*i & V4L2_STD_PAL) { 1327 } else if (i & V4L2_STD_625_50) {
1362 dprintk(4, "%s PAL\n", __func__); 1328 dprintk(4, "%s 50 Hz\n", __func__);
1363 if (mode.format != FORMAT_PAL) { 1329 if (mode.format != FORMAT_PAL) {
1364 mode.restart = 1; 1330 mode.restart = 1;
1365 mode.format = FORMAT_PAL; 1331 mode.format = FORMAT_PAL;
1366 mode.fdec = FDEC_1; 1332 mode.fdec = FDEC_1;
1333 channel->width = LINE_SZ_4CIFS_PAL;
1334 channel->height = NUM_LINES_4CIFS_PAL * 2;
1367 } 1335 }
1368 } else { 1336 } else {
1369 ret = -EINVAL; 1337 ret = -EINVAL;
1338 goto out_s_std;
1370 } 1339 }
1340 fh->channel->std = i;
1371 if (mode.restart) 1341 if (mode.restart)
1372 s2255_set_mode(fh->channel, &mode); 1342 s2255_set_mode(fh->channel, &mode);
1373out_s_std: 1343out_s_std:
@@ -1375,6 +1345,14 @@ out_s_std:
1375 return ret; 1345 return ret;
1376} 1346}
1377 1347
1348static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *i)
1349{
1350 struct s2255_fh *fh = priv;
1351
1352 *i = fh->channel->std;
1353 return 0;
1354}
1355
1378/* Sensoray 2255 is a multiple channel capture device. 1356/* Sensoray 2255 is a multiple channel capture device.
1379 It does not have a "crossbar" of inputs. 1357 It does not have a "crossbar" of inputs.
1380 We use one V4L device per channel. The user must 1358 We use one V4L device per channel. The user must
@@ -1427,110 +1405,36 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1427 return 0; 1405 return 0;
1428} 1406}
1429 1407
1430/* --- controls ---------------------------------------------- */ 1408static int s2255_s_ctrl(struct v4l2_ctrl *ctrl)
1431static int vidioc_queryctrl(struct file *file, void *priv,
1432 struct v4l2_queryctrl *qc)
1433{
1434 struct s2255_fh *fh = priv;
1435 struct s2255_channel *channel = fh->channel;
1436 struct s2255_dev *dev = fh->dev;
1437 switch (qc->id) {
1438 case V4L2_CID_BRIGHTNESS:
1439 v4l2_ctrl_query_fill(qc, -127, 127, 1, DEF_BRIGHT);
1440 break;
1441 case V4L2_CID_CONTRAST:
1442 v4l2_ctrl_query_fill(qc, 0, 255, 1, DEF_CONTRAST);
1443 break;
1444 case V4L2_CID_SATURATION:
1445 v4l2_ctrl_query_fill(qc, 0, 255, 1, DEF_SATURATION);
1446 break;
1447 case V4L2_CID_HUE:
1448 v4l2_ctrl_query_fill(qc, 0, 255, 1, DEF_HUE);
1449 break;
1450 case V4L2_CID_PRIVATE_COLORFILTER:
1451 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
1452 return -EINVAL;
1453 if ((dev->pid == 0x2257) && (channel->idx > 1))
1454 return -EINVAL;
1455 strlcpy(qc->name, "Color Filter", sizeof(qc->name));
1456 qc->type = V4L2_CTRL_TYPE_MENU;
1457 qc->minimum = 0;
1458 qc->maximum = 1;
1459 qc->step = 1;
1460 qc->default_value = 1;
1461 qc->flags = 0;
1462 break;
1463 default:
1464 return -EINVAL;
1465 }
1466 dprintk(4, "%s, id %d\n", __func__, qc->id);
1467 return 0;
1468}
1469
1470static int vidioc_g_ctrl(struct file *file, void *priv,
1471 struct v4l2_control *ctrl)
1472{
1473 struct s2255_fh *fh = priv;
1474 struct s2255_dev *dev = fh->dev;
1475 struct s2255_channel *channel = fh->channel;
1476 switch (ctrl->id) {
1477 case V4L2_CID_BRIGHTNESS:
1478 ctrl->value = channel->mode.bright;
1479 break;
1480 case V4L2_CID_CONTRAST:
1481 ctrl->value = channel->mode.contrast;
1482 break;
1483 case V4L2_CID_SATURATION:
1484 ctrl->value = channel->mode.saturation;
1485 break;
1486 case V4L2_CID_HUE:
1487 ctrl->value = channel->mode.hue;
1488 break;
1489 case V4L2_CID_PRIVATE_COLORFILTER:
1490 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
1491 return -EINVAL;
1492 if ((dev->pid == 0x2257) && (channel->idx > 1))
1493 return -EINVAL;
1494 ctrl->value = !((channel->mode.color & MASK_INPUT_TYPE) >> 16);
1495 break;
1496 default:
1497 return -EINVAL;
1498 }
1499 dprintk(4, "%s, id %d val %d\n", __func__, ctrl->id, ctrl->value);
1500 return 0;
1501}
1502
1503static int vidioc_s_ctrl(struct file *file, void *priv,
1504 struct v4l2_control *ctrl)
1505{ 1409{
1506 struct s2255_fh *fh = priv; 1410 struct s2255_channel *channel =
1507 struct s2255_channel *channel = fh->channel; 1411 container_of(ctrl->handler, struct s2255_channel, hdl);
1508 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1509 struct s2255_mode mode; 1412 struct s2255_mode mode;
1413
1510 mode = channel->mode; 1414 mode = channel->mode;
1511 dprintk(4, "%s\n", __func__); 1415 dprintk(4, "%s\n", __func__);
1416
1512 /* update the mode to the corresponding value */ 1417 /* update the mode to the corresponding value */
1513 switch (ctrl->id) { 1418 switch (ctrl->id) {
1514 case V4L2_CID_BRIGHTNESS: 1419 case V4L2_CID_BRIGHTNESS:
1515 mode.bright = ctrl->value; 1420 mode.bright = ctrl->val;
1516 break; 1421 break;
1517 case V4L2_CID_CONTRAST: 1422 case V4L2_CID_CONTRAST:
1518 mode.contrast = ctrl->value; 1423 mode.contrast = ctrl->val;
1519 break; 1424 break;
1520 case V4L2_CID_HUE: 1425 case V4L2_CID_HUE:
1521 mode.hue = ctrl->value; 1426 mode.hue = ctrl->val;
1522 break; 1427 break;
1523 case V4L2_CID_SATURATION: 1428 case V4L2_CID_SATURATION:
1524 mode.saturation = ctrl->value; 1429 mode.saturation = ctrl->val;
1525 break; 1430 break;
1526 case V4L2_CID_PRIVATE_COLORFILTER: 1431 case V4L2_CID_S2255_COLORFILTER:
1527 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
1528 return -EINVAL;
1529 if ((dev->pid == 0x2257) && (channel->idx > 1))
1530 return -EINVAL;
1531 mode.color &= ~MASK_INPUT_TYPE; 1432 mode.color &= ~MASK_INPUT_TYPE;
1532 mode.color |= ((ctrl->value ? 0 : 1) << 16); 1433 mode.color |= !ctrl->val << 16;
1533 break; 1434 break;
1435 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
1436 channel->jpegqual = ctrl->val;
1437 return 0;
1534 default: 1438 default:
1535 return -EINVAL; 1439 return -EINVAL;
1536 } 1440 }
@@ -1539,7 +1443,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1539 some V4L programs restart stream unnecessarily 1443 some V4L programs restart stream unnecessarily
1540 after a s_crtl. 1444 after a s_crtl.
1541 */ 1445 */
1542 s2255_set_mode(fh->channel, &mode); 1446 s2255_set_mode(channel, &mode);
1543 return 0; 1447 return 0;
1544} 1448}
1545 1449
@@ -1548,7 +1452,9 @@ static int vidioc_g_jpegcomp(struct file *file, void *priv,
1548{ 1452{
1549 struct s2255_fh *fh = priv; 1453 struct s2255_fh *fh = priv;
1550 struct s2255_channel *channel = fh->channel; 1454 struct s2255_channel *channel = fh->channel;
1551 *jc = channel->jc; 1455
1456 memset(jc, 0, sizeof(*jc));
1457 jc->quality = channel->jpegqual;
1552 dprintk(2, "%s: quality %d\n", __func__, jc->quality); 1458 dprintk(2, "%s: quality %d\n", __func__, jc->quality);
1553 return 0; 1459 return 0;
1554} 1460}
@@ -1560,7 +1466,7 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1560 struct s2255_channel *channel = fh->channel; 1466 struct s2255_channel *channel = fh->channel;
1561 if (jc->quality < 0 || jc->quality > 100) 1467 if (jc->quality < 0 || jc->quality > 100)
1562 return -EINVAL; 1468 return -EINVAL;
1563 channel->jc.quality = jc->quality; 1469 v4l2_ctrl_s_ctrl(channel->jpegqual_ctrl, jc->quality);
1564 dprintk(2, "%s: quality %d\n", __func__, jc->quality); 1470 dprintk(2, "%s: quality %d\n", __func__, jc->quality);
1565 return 0; 1471 return 0;
1566} 1472}
@@ -1573,7 +1479,6 @@ static int vidioc_g_parm(struct file *file, void *priv,
1573 struct s2255_channel *channel = fh->channel; 1479 struct s2255_channel *channel = fh->channel;
1574 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1480 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1575 return -EINVAL; 1481 return -EINVAL;
1576 memset(sp, 0, sizeof(struct v4l2_streamparm));
1577 sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; 1482 sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1578 sp->parm.capture.capturemode = channel->cap_parm.capturemode; 1483 sp->parm.capture.capturemode = channel->cap_parm.capturemode;
1579 def_num = (channel->mode.format == FORMAT_NTSC) ? 1001 : 1000; 1484 def_num = (channel->mode.format == FORMAT_NTSC) ? 1001 : 1000;
@@ -1643,36 +1548,64 @@ static int vidioc_s_parm(struct file *file, void *priv,
1643 return 0; 1548 return 0;
1644} 1549}
1645 1550
1551#define NUM_SIZE_ENUMS 3
1552static const struct v4l2_frmsize_discrete ntsc_sizes[] = {
1553 { 640, 480 },
1554 { 640, 240 },
1555 { 320, 240 },
1556};
1557static const struct v4l2_frmsize_discrete pal_sizes[] = {
1558 { 704, 576 },
1559 { 704, 288 },
1560 { 352, 288 },
1561};
1562
1563static int vidioc_enum_framesizes(struct file *file, void *priv,
1564 struct v4l2_frmsizeenum *fe)
1565{
1566 struct s2255_fh *fh = priv;
1567 struct s2255_channel *channel = fh->channel;
1568 int is_ntsc = channel->std & V4L2_STD_525_60;
1569 const struct s2255_fmt *fmt;
1570
1571 if (fe->index >= NUM_SIZE_ENUMS)
1572 return -EINVAL;
1573
1574 fmt = format_by_fourcc(fe->pixel_format);
1575 if (fmt == NULL)
1576 return -EINVAL;
1577 fe->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1578 fe->discrete = is_ntsc ? ntsc_sizes[fe->index] : pal_sizes[fe->index];
1579 return 0;
1580}
1581
1646static int vidioc_enum_frameintervals(struct file *file, void *priv, 1582static int vidioc_enum_frameintervals(struct file *file, void *priv,
1647 struct v4l2_frmivalenum *fe) 1583 struct v4l2_frmivalenum *fe)
1648{ 1584{
1649 int is_ntsc = 0; 1585 struct s2255_fh *fh = priv;
1586 struct s2255_channel *channel = fh->channel;
1587 const struct s2255_fmt *fmt;
1588 const struct v4l2_frmsize_discrete *sizes;
1589 int is_ntsc = channel->std & V4L2_STD_525_60;
1650#define NUM_FRAME_ENUMS 4 1590#define NUM_FRAME_ENUMS 4
1651 int frm_dec[NUM_FRAME_ENUMS] = {1, 2, 3, 5}; 1591 int frm_dec[NUM_FRAME_ENUMS] = {1, 2, 3, 5};
1592 int i;
1593
1652 if (fe->index >= NUM_FRAME_ENUMS) 1594 if (fe->index >= NUM_FRAME_ENUMS)
1653 return -EINVAL; 1595 return -EINVAL;
1654 switch (fe->width) { 1596
1655 case 640: 1597 fmt = format_by_fourcc(fe->pixel_format);
1656 if (fe->height != 240 && fe->height != 480) 1598 if (fmt == NULL)
1657 return -EINVAL;
1658 is_ntsc = 1;
1659 break;
1660 case 320:
1661 if (fe->height != 240)
1662 return -EINVAL;
1663 is_ntsc = 1;
1664 break;
1665 case 704:
1666 if (fe->height != 288 && fe->height != 576)
1667 return -EINVAL;
1668 break;
1669 case 352:
1670 if (fe->height != 288)
1671 return -EINVAL;
1672 break;
1673 default:
1674 return -EINVAL; 1599 return -EINVAL;
1675 } 1600
1601 sizes = is_ntsc ? ntsc_sizes : pal_sizes;
1602 for (i = 0; i < NUM_SIZE_ENUMS; i++, sizes++)
1603 if (fe->width == sizes->width &&
1604 fe->height == sizes->height)
1605 break;
1606 if (i == NUM_SIZE_ENUMS)
1607 return -EINVAL;
1608
1676 fe->type = V4L2_FRMIVAL_TYPE_DISCRETE; 1609 fe->type = V4L2_FRMIVAL_TYPE_DISCRETE;
1677 fe->discrete.denominator = is_ntsc ? 30000 : 25000; 1610 fe->discrete.denominator = is_ntsc ? 30000 : 25000;
1678 fe->discrete.numerator = (is_ntsc ? 1001 : 1000) * frm_dec[fe->index]; 1611 fe->discrete.numerator = (is_ntsc ? 1001 : 1000) * frm_dec[fe->index];
@@ -1757,7 +1690,9 @@ static int __s2255_open(struct file *file)
1757 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 1690 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1758 if (NULL == fh) 1691 if (NULL == fh)
1759 return -ENOMEM; 1692 return -ENOMEM;
1760 file->private_data = fh; 1693 v4l2_fh_init(&fh->fh, vdev);
1694 v4l2_fh_add(&fh->fh);
1695 file->private_data = &fh->fh;
1761 fh->dev = dev; 1696 fh->dev = dev;
1762 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1697 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1763 fh->channel = channel; 1698 fh->channel = channel;
@@ -1800,12 +1735,13 @@ static unsigned int s2255_poll(struct file *file,
1800{ 1735{
1801 struct s2255_fh *fh = file->private_data; 1736 struct s2255_fh *fh = file->private_data;
1802 struct s2255_dev *dev = fh->dev; 1737 struct s2255_dev *dev = fh->dev;
1803 int rc; 1738 int rc = v4l2_ctrl_poll(file, wait);
1739
1804 dprintk(100, "%s\n", __func__); 1740 dprintk(100, "%s\n", __func__);
1805 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1741 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1806 return POLLERR; 1742 return POLLERR;
1807 mutex_lock(&dev->lock); 1743 mutex_lock(&dev->lock);
1808 rc = videobuf_poll_stream(file, &fh->vb_vidq, wait); 1744 rc |= videobuf_poll_stream(file, &fh->vb_vidq, wait);
1809 mutex_unlock(&dev->lock); 1745 mutex_unlock(&dev->lock);
1810 return rc; 1746 return rc;
1811} 1747}
@@ -1852,6 +1788,8 @@ static int s2255_release(struct file *file)
1852 videobuf_mmap_free(&fh->vb_vidq); 1788 videobuf_mmap_free(&fh->vb_vidq);
1853 mutex_unlock(&dev->lock); 1789 mutex_unlock(&dev->lock);
1854 dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev)); 1790 dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev));
1791 v4l2_fh_del(&fh->fh);
1792 v4l2_fh_exit(&fh->fh);
1855 kfree(fh); 1793 kfree(fh);
1856 return 0; 1794 return 0;
1857} 1795}
@@ -1886,7 +1824,6 @@ static const struct v4l2_file_operations s2255_fops_v4l = {
1886}; 1824};
1887 1825
1888static const struct v4l2_ioctl_ops s2255_ioctl_ops = { 1826static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
1889 .vidioc_querymenu = vidioc_querymenu,
1890 .vidioc_querycap = vidioc_querycap, 1827 .vidioc_querycap = vidioc_querycap,
1891 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1828 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1892 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1829 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1897,26 +1834,33 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
1897 .vidioc_qbuf = vidioc_qbuf, 1834 .vidioc_qbuf = vidioc_qbuf,
1898 .vidioc_dqbuf = vidioc_dqbuf, 1835 .vidioc_dqbuf = vidioc_dqbuf,
1899 .vidioc_s_std = vidioc_s_std, 1836 .vidioc_s_std = vidioc_s_std,
1837 .vidioc_g_std = vidioc_g_std,
1900 .vidioc_enum_input = vidioc_enum_input, 1838 .vidioc_enum_input = vidioc_enum_input,
1901 .vidioc_g_input = vidioc_g_input, 1839 .vidioc_g_input = vidioc_g_input,
1902 .vidioc_s_input = vidioc_s_input, 1840 .vidioc_s_input = vidioc_s_input,
1903 .vidioc_queryctrl = vidioc_queryctrl,
1904 .vidioc_g_ctrl = vidioc_g_ctrl,
1905 .vidioc_s_ctrl = vidioc_s_ctrl,
1906 .vidioc_streamon = vidioc_streamon, 1841 .vidioc_streamon = vidioc_streamon,
1907 .vidioc_streamoff = vidioc_streamoff, 1842 .vidioc_streamoff = vidioc_streamoff,
1908 .vidioc_s_jpegcomp = vidioc_s_jpegcomp, 1843 .vidioc_s_jpegcomp = vidioc_s_jpegcomp,
1909 .vidioc_g_jpegcomp = vidioc_g_jpegcomp, 1844 .vidioc_g_jpegcomp = vidioc_g_jpegcomp,
1910 .vidioc_s_parm = vidioc_s_parm, 1845 .vidioc_s_parm = vidioc_s_parm,
1911 .vidioc_g_parm = vidioc_g_parm, 1846 .vidioc_g_parm = vidioc_g_parm,
1847 .vidioc_enum_framesizes = vidioc_enum_framesizes,
1912 .vidioc_enum_frameintervals = vidioc_enum_frameintervals, 1848 .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
1849 .vidioc_log_status = v4l2_ctrl_log_status,
1850 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1851 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1913}; 1852};
1914 1853
1915static void s2255_video_device_release(struct video_device *vdev) 1854static void s2255_video_device_release(struct video_device *vdev)
1916{ 1855{
1917 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev); 1856 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev);
1918 dprintk(4, "%s, chnls: %d \n", __func__, 1857 struct s2255_channel *channel =
1858 container_of(vdev, struct s2255_channel, vdev);
1859
1860 v4l2_ctrl_handler_free(&channel->hdl);
1861 dprintk(4, "%s, chnls: %d\n", __func__,
1919 atomic_read(&dev->num_channels)); 1862 atomic_read(&dev->num_channels));
1863
1920 if (atomic_dec_and_test(&dev->num_channels)) 1864 if (atomic_dec_and_test(&dev->num_channels))
1921 s2255_destroy(dev); 1865 s2255_destroy(dev);
1922 return; 1866 return;
@@ -1928,7 +1872,20 @@ static struct video_device template = {
1928 .ioctl_ops = &s2255_ioctl_ops, 1872 .ioctl_ops = &s2255_ioctl_ops,
1929 .release = s2255_video_device_release, 1873 .release = s2255_video_device_release,
1930 .tvnorms = S2255_NORMS, 1874 .tvnorms = S2255_NORMS,
1931 .current_norm = V4L2_STD_NTSC_M, 1875};
1876
1877static const struct v4l2_ctrl_ops s2255_ctrl_ops = {
1878 .s_ctrl = s2255_s_ctrl,
1879};
1880
1881static const struct v4l2_ctrl_config color_filter_ctrl = {
1882 .ops = &s2255_ctrl_ops,
1883 .name = "Color Filter",
1884 .id = V4L2_CID_S2255_COLORFILTER,
1885 .type = V4L2_CTRL_TYPE_BOOLEAN,
1886 .max = 1,
1887 .step = 1,
1888 .def = 1,
1932}; 1889};
1933 1890
1934static int s2255_probe_v4l(struct s2255_dev *dev) 1891static int s2255_probe_v4l(struct s2255_dev *dev)
@@ -1945,11 +1902,36 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
1945 for (i = 0; i < MAX_CHANNELS; i++) { 1902 for (i = 0; i < MAX_CHANNELS; i++) {
1946 channel = &dev->channel[i]; 1903 channel = &dev->channel[i];
1947 INIT_LIST_HEAD(&channel->vidq.active); 1904 INIT_LIST_HEAD(&channel->vidq.active);
1905
1906 v4l2_ctrl_handler_init(&channel->hdl, 6);
1907 v4l2_ctrl_new_std(&channel->hdl, &s2255_ctrl_ops,
1908 V4L2_CID_BRIGHTNESS, -127, 127, 1, DEF_BRIGHT);
1909 v4l2_ctrl_new_std(&channel->hdl, &s2255_ctrl_ops,
1910 V4L2_CID_CONTRAST, 0, 255, 1, DEF_CONTRAST);
1911 v4l2_ctrl_new_std(&channel->hdl, &s2255_ctrl_ops,
1912 V4L2_CID_SATURATION, 0, 255, 1, DEF_SATURATION);
1913 v4l2_ctrl_new_std(&channel->hdl, &s2255_ctrl_ops,
1914 V4L2_CID_HUE, 0, 255, 1, DEF_HUE);
1915 channel->jpegqual_ctrl = v4l2_ctrl_new_std(&channel->hdl,
1916 &s2255_ctrl_ops,
1917 V4L2_CID_JPEG_COMPRESSION_QUALITY,
1918 0, 100, 1, S2255_DEF_JPEG_QUAL);
1919 if (dev->dsp_fw_ver >= S2255_MIN_DSP_COLORFILTER &&
1920 (dev->pid != 0x2257 || channel->idx <= 1))
1921 v4l2_ctrl_new_custom(&channel->hdl, &color_filter_ctrl, NULL);
1922 if (channel->hdl.error) {
1923 ret = channel->hdl.error;
1924 v4l2_ctrl_handler_free(&channel->hdl);
1925 dev_err(&dev->udev->dev, "couldn't register control\n");
1926 break;
1927 }
1948 channel->vidq.dev = dev; 1928 channel->vidq.dev = dev;
1949 /* register 4 video devices */ 1929 /* register 4 video devices */
1950 channel->vdev = template; 1930 channel->vdev = template;
1931 channel->vdev.ctrl_handler = &channel->hdl;
1951 channel->vdev.lock = &dev->lock; 1932 channel->vdev.lock = &dev->lock;
1952 channel->vdev.v4l2_dev = &dev->v4l2_dev; 1933 channel->vdev.v4l2_dev = &dev->v4l2_dev;
1934 set_bit(V4L2_FL_USE_FH_PRIO, &channel->vdev.flags);
1953 video_set_drvdata(&channel->vdev, channel); 1935 video_set_drvdata(&channel->vdev, channel);
1954 if (video_nr == -1) 1936 if (video_nr == -1)
1955 ret = video_register_device(&channel->vdev, 1937 ret = video_register_device(&channel->vdev,
@@ -2300,9 +2282,10 @@ static int s2255_board_init(struct s2255_dev *dev)
2300 channel->mode = mode_def; 2282 channel->mode = mode_def;
2301 if (dev->pid == 0x2257 && j > 1) 2283 if (dev->pid == 0x2257 && j > 1)
2302 channel->mode.color |= (1 << 16); 2284 channel->mode.color |= (1 << 16);
2303 channel->jc.quality = S2255_DEF_JPEG_QUAL; 2285 channel->jpegqual = S2255_DEF_JPEG_QUAL;
2304 channel->width = LINE_SZ_4CIFS_NTSC; 2286 channel->width = LINE_SZ_4CIFS_NTSC;
2305 channel->height = NUM_LINES_4CIFS_NTSC * 2; 2287 channel->height = NUM_LINES_4CIFS_NTSC * 2;
2288 channel->std = V4L2_STD_NTSC_M;
2306 channel->fmt = &formats[0]; 2289 channel->fmt = &formats[0];
2307 channel->mode.restart = 1; 2290 channel->mode.restart = 1;
2308 channel->req_image_size = get_transfer_size(&mode_def); 2291 channel->req_image_size = get_transfer_size(&mode_def);
@@ -2531,7 +2514,7 @@ static int s2255_probe(struct usb_interface *interface,
2531 return -ENOMEM; 2514 return -ENOMEM;
2532 } 2515 }
2533 atomic_set(&dev->num_channels, 0); 2516 atomic_set(&dev->num_channels, 0);
2534 dev->pid = id->idProduct; 2517 dev->pid = le16_to_cpu(id->idProduct);
2535 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL); 2518 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
2536 if (!dev->fw_data) 2519 if (!dev->fw_data)
2537 goto errorFWDATA1; 2520 goto errorFWDATA1;
@@ -2601,7 +2584,7 @@ static int s2255_probe(struct usb_interface *interface,
2601 /* make sure firmware is the latest */ 2584 /* make sure firmware is the latest */
2602 __le32 *pRel; 2585 __le32 *pRel;
2603 pRel = (__le32 *) &dev->fw_data->fw->data[fw_size - 4]; 2586 pRel = (__le32 *) &dev->fw_data->fw->data[fw_size - 4];
2604 printk(KERN_INFO "s2255 dsp fw version %x\n", *pRel); 2587 printk(KERN_INFO "s2255 dsp fw version %x\n", le32_to_cpu(*pRel));
2605 dev->dsp_fw_ver = le32_to_cpu(*pRel); 2588 dev->dsp_fw_ver = le32_to_cpu(*pRel);
2606 if (dev->dsp_fw_ver < S2255_CUR_DSP_FWVER) 2589 if (dev->dsp_fw_ver < S2255_CUR_DSP_FWVER)
2607 printk(KERN_INFO "s2255: f2255usb.bin out of date.\n"); 2590 printk(KERN_INFO "s2255: f2255usb.bin out of date.\n");
diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
index de2c10289eec..03761c6f472f 100644
--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -35,16 +35,23 @@ module_param_named(debug, sms_dbg, int, 0644);
35MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); 35MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
36 36
37#define USB1_BUFFER_SIZE 0x1000 37#define USB1_BUFFER_SIZE 0x1000
38#define USB2_BUFFER_SIZE 0x4000 38#define USB2_BUFFER_SIZE 0x2000
39 39
40#define MAX_BUFFERS 50 40#define MAX_BUFFERS 50
41#define MAX_URBS 10 41#define MAX_URBS 10
42 42
43struct smsusb_device_t; 43struct smsusb_device_t;
44 44
45enum smsusb_state {
46 SMSUSB_DISCONNECTED,
47 SMSUSB_SUSPENDED,
48 SMSUSB_ACTIVE
49};
50
45struct smsusb_urb_t { 51struct smsusb_urb_t {
52 struct list_head entry;
46 struct smscore_buffer_t *cb; 53 struct smscore_buffer_t *cb;
47 struct smsusb_device_t *dev; 54 struct smsusb_device_t *dev;
48 55
49 struct urb urb; 56 struct urb urb;
50}; 57};
@@ -57,11 +64,23 @@ struct smsusb_device_t {
57 64
58 int response_alignment; 65 int response_alignment;
59 int buffer_size; 66 int buffer_size;
67
68 unsigned char in_ep;
69 unsigned char out_ep;
70 enum smsusb_state state;
60}; 71};
61 72
62static int smsusb_submit_urb(struct smsusb_device_t *dev, 73static int smsusb_submit_urb(struct smsusb_device_t *dev,
63 struct smsusb_urb_t *surb); 74 struct smsusb_urb_t *surb);
64 75
76/**
77 * Completing URB's callback handler - top half (interrupt context)
78 * adds completing sms urb to the global surbs list and activtes the worker
79 * thread the surb
80 * IMPORTANT - blocking functions must not be called from here !!!
81
82 * @param urb pointer to a completing urb object
83 */
65static void smsusb_onresponse(struct urb *urb) 84static void smsusb_onresponse(struct urb *urb)
66{ 85{
67 struct smsusb_urb_t *surb = (struct smsusb_urb_t *) urb->context; 86 struct smsusb_urb_t *surb = (struct smsusb_urb_t *) urb->context;
@@ -74,26 +93,26 @@ static void smsusb_onresponse(struct urb *urb)
74 } 93 }
75 94
76 if ((urb->actual_length > 0) && (urb->status == 0)) { 95 if ((urb->actual_length > 0) && (urb->status == 0)) {
77 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)surb->cb->p; 96 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *)surb->cb->p;
78 97
79 smsendian_handle_message_header(phdr); 98 smsendian_handle_message_header(phdr);
80 if (urb->actual_length >= phdr->msgLength) { 99 if (urb->actual_length >= phdr->msg_length) {
81 surb->cb->size = phdr->msgLength; 100 surb->cb->size = phdr->msg_length;
82 101
83 if (dev->response_alignment && 102 if (dev->response_alignment &&
84 (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) { 103 (phdr->msg_flags & MSG_HDR_FLAG_SPLIT_MSG)) {
85 104
86 surb->cb->offset = 105 surb->cb->offset =
87 dev->response_alignment + 106 dev->response_alignment +
88 ((phdr->msgFlags >> 8) & 3); 107 ((phdr->msg_flags >> 8) & 3);
89 108
90 /* sanity check */ 109 /* sanity check */
91 if (((int) phdr->msgLength + 110 if (((int) phdr->msg_length +
92 surb->cb->offset) > urb->actual_length) { 111 surb->cb->offset) > urb->actual_length) {
93 sms_err("invalid response " 112 sms_err("invalid response "
94 "msglen %d offset %d " 113 "msglen %d offset %d "
95 "size %d", 114 "size %d",
96 phdr->msgLength, 115 phdr->msg_length,
97 surb->cb->offset, 116 surb->cb->offset,
98 urb->actual_length); 117 urb->actual_length);
99 goto exit_and_resubmit; 118 goto exit_and_resubmit;
@@ -102,16 +121,22 @@ static void smsusb_onresponse(struct urb *urb)
102 /* move buffer pointer and 121 /* move buffer pointer and
103 * copy header to its new location */ 122 * copy header to its new location */
104 memcpy((char *) phdr + surb->cb->offset, 123 memcpy((char *) phdr + surb->cb->offset,
105 phdr, sizeof(struct SmsMsgHdr_ST)); 124 phdr, sizeof(struct sms_msg_hdr));
106 } else 125 } else
107 surb->cb->offset = 0; 126 surb->cb->offset = 0;
108 127
128 sms_debug("received %s(%d) size: %d",
129 smscore_translate_msg(phdr->msg_type),
130 phdr->msg_type, phdr->msg_length);
131
132 smsendian_handle_rx_message((struct sms_msg_data *) phdr);
133
109 smscore_onresponse(dev->coredev, surb->cb); 134 smscore_onresponse(dev->coredev, surb->cb);
110 surb->cb = NULL; 135 surb->cb = NULL;
111 } else { 136 } else {
112 sms_err("invalid response " 137 sms_err("invalid response "
113 "msglen %d actual %d", 138 "msglen %d actual %d",
114 phdr->msgLength, urb->actual_length); 139 phdr->msg_length, urb->actual_length);
115 } 140 }
116 } else 141 } else
117 sms_err("error, urb status %d, %d bytes", 142 sms_err("error, urb status %d, %d bytes",
@@ -136,7 +161,7 @@ static int smsusb_submit_urb(struct smsusb_device_t *dev,
136 usb_fill_bulk_urb( 161 usb_fill_bulk_urb(
137 &surb->urb, 162 &surb->urb,
138 dev->udev, 163 dev->udev,
139 usb_rcvbulkpipe(dev->udev, 0x81), 164 usb_rcvbulkpipe(dev->udev, dev->in_ep),
140 surb->cb->p, 165 surb->cb->p,
141 dev->buffer_size, 166 dev->buffer_size,
142 smsusb_onresponse, 167 smsusb_onresponse,
@@ -181,9 +206,18 @@ static int smsusb_start_streaming(struct smsusb_device_t *dev)
181static int smsusb_sendrequest(void *context, void *buffer, size_t size) 206static int smsusb_sendrequest(void *context, void *buffer, size_t size)
182{ 207{
183 struct smsusb_device_t *dev = (struct smsusb_device_t *) context; 208 struct smsusb_device_t *dev = (struct smsusb_device_t *) context;
209 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;
184 int dummy; 210 int dummy;
185 211
186 smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer); 212 if (dev->state != SMSUSB_ACTIVE)
213 return -ENOENT;
214
215 sms_debug("sending %s(%d) size: %d",
216 smscore_translate_msg(phdr->msg_type), phdr->msg_type,
217 phdr->msg_length);
218
219 smsendian_handle_tx_message((struct sms_msg_data *) phdr);
220 smsendian_handle_message_header((struct sms_msg_hdr *)buffer);
187 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2), 221 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
188 buffer, size, &dummy, 1000); 222 buffer, size, &dummy, 1000);
189} 223}
@@ -276,15 +310,15 @@ static void smsusb1_detectmode(void *context, int *mode)
276 310
277static int smsusb1_setmode(void *context, int mode) 311static int smsusb1_setmode(void *context, int mode)
278{ 312{
279 struct SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK, 313 struct sms_msg_hdr msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK,
280 sizeof(struct SmsMsgHdr_ST), 0 }; 314 sizeof(struct sms_msg_hdr), 0 };
281 315
282 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) { 316 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
283 sms_err("invalid firmware id specified %d", mode); 317 sms_err("invalid firmware id specified %d", mode);
284 return -EINVAL; 318 return -EINVAL;
285 } 319 }
286 320
287 return smsusb_sendrequest(context, &Msg, sizeof(Msg)); 321 return smsusb_sendrequest(context, &msg, sizeof(msg));
288} 322}
289 323
290static void smsusb_term_device(struct usb_interface *intf) 324static void smsusb_term_device(struct usb_interface *intf)
@@ -292,13 +326,15 @@ static void smsusb_term_device(struct usb_interface *intf)
292 struct smsusb_device_t *dev = usb_get_intfdata(intf); 326 struct smsusb_device_t *dev = usb_get_intfdata(intf);
293 327
294 if (dev) { 328 if (dev) {
329 dev->state = SMSUSB_DISCONNECTED;
330
295 smsusb_stop_streaming(dev); 331 smsusb_stop_streaming(dev);
296 332
297 /* unregister from smscore */ 333 /* unregister from smscore */
298 if (dev->coredev) 334 if (dev->coredev)
299 smscore_unregister_device(dev->coredev); 335 smscore_unregister_device(dev->coredev);
300 336
301 sms_info("device %p destroyed", dev); 337 sms_info("device 0x%p destroyed", dev);
302 kfree(dev); 338 kfree(dev);
303 } 339 }
304 340
@@ -321,6 +357,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
321 memset(&params, 0, sizeof(params)); 357 memset(&params, 0, sizeof(params));
322 usb_set_intfdata(intf, dev); 358 usb_set_intfdata(intf, dev);
323 dev->udev = interface_to_usbdev(intf); 359 dev->udev = interface_to_usbdev(intf);
360 dev->state = SMSUSB_DISCONNECTED;
324 361
325 params.device_type = sms_get_board(board_id)->type; 362 params.device_type = sms_get_board(board_id)->type;
326 363
@@ -331,21 +368,29 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
331 params.setmode_handler = smsusb1_setmode; 368 params.setmode_handler = smsusb1_setmode;
332 params.detectmode_handler = smsusb1_detectmode; 369 params.detectmode_handler = smsusb1_detectmode;
333 break; 370 break;
334 default: 371 case SMS_UNKNOWN_TYPE:
335 sms_err("Unspecified sms device type!"); 372 sms_err("Unspecified sms device type!");
336 /* fall-thru */ 373 /* fall-thru */
337 case SMS_NOVA_A0: 374 default:
338 case SMS_NOVA_B0:
339 case SMS_VEGA:
340 dev->buffer_size = USB2_BUFFER_SIZE; 375 dev->buffer_size = USB2_BUFFER_SIZE;
341 dev->response_alignment = 376 dev->response_alignment =
342 le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) - 377 le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
343 sizeof(struct SmsMsgHdr_ST); 378 sizeof(struct sms_msg_hdr);
344 379
345 params.flags |= SMS_DEVICE_FAMILY2; 380 params.flags |= SMS_DEVICE_FAMILY2;
346 break; 381 break;
347 } 382 }
348 383
384 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
385 if (intf->cur_altsetting->endpoint[i].desc. bEndpointAddress & USB_DIR_IN)
386 dev->in_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
387 else
388 dev->out_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
389 }
390
391 sms_info("in_ep = %02x, out_ep = %02x",
392 dev->in_ep, dev->out_ep);
393
349 params.device = &dev->udev->dev; 394 params.device = &dev->udev->dev;
350 params.buffer_size = dev->buffer_size; 395 params.buffer_size = dev->buffer_size;
351 params.num_buffers = MAX_BUFFERS; 396 params.num_buffers = MAX_BUFFERS;
@@ -363,6 +408,8 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
363 408
364 smscore_set_board_id(dev->coredev, board_id); 409 smscore_set_board_id(dev->coredev, board_id);
365 410
411 dev->coredev->is_usb_device = true;
412
366 /* initialize urbs */ 413 /* initialize urbs */
367 for (i = 0; i < MAX_URBS; i++) { 414 for (i = 0; i < MAX_URBS; i++) {
368 dev->surbs[i].dev = dev; 415 dev->surbs[i].dev = dev;
@@ -377,6 +424,8 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
377 return rc; 424 return rc;
378 } 425 }
379 426
427 dev->state = SMSUSB_ACTIVE;
428
380 rc = smscore_start_device(dev->coredev); 429 rc = smscore_start_device(dev->coredev);
381 if (rc < 0) { 430 if (rc < 0) {
382 sms_err("smscore_start_device(...) failed"); 431 sms_err("smscore_start_device(...) failed");
@@ -384,7 +433,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
384 return rc; 433 return rc;
385 } 434 }
386 435
387 sms_info("device %p created", dev); 436 sms_info("device 0x%p created", dev);
388 437
389 return rc; 438 return rc;
390} 439}
@@ -396,12 +445,21 @@ static int smsusb_probe(struct usb_interface *intf,
396 char devpath[32]; 445 char devpath[32];
397 int i, rc; 446 int i, rc;
398 447
399 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81)); 448 sms_info("interface number %d",
400 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02)); 449 intf->cur_altsetting->desc.bInterfaceNumber);
401 450
402 if (intf->num_altsetting > 0) { 451 if (sms_get_board(id->driver_info)->intf_num !=
403 rc = usb_set_interface( 452 intf->cur_altsetting->desc.bInterfaceNumber) {
404 udev, intf->cur_altsetting->desc.bInterfaceNumber, 0); 453 sms_err("interface number is %d expecting %d",
454 sms_get_board(id->driver_info)->intf_num,
455 intf->cur_altsetting->desc.bInterfaceNumber);
456 return -ENODEV;
457 }
458
459 if (intf->num_altsetting > 1) {
460 rc = usb_set_interface(udev,
461 intf->cur_altsetting->desc.bInterfaceNumber,
462 0);
405 if (rc < 0) { 463 if (rc < 0) {
406 sms_err("usb_set_interface failed, rc %d", rc); 464 sms_err("usb_set_interface failed, rc %d", rc);
407 return rc; 465 return rc;
@@ -410,19 +468,27 @@ static int smsusb_probe(struct usb_interface *intf,
410 468
411 sms_info("smsusb_probe %d", 469 sms_info("smsusb_probe %d",
412 intf->cur_altsetting->desc.bInterfaceNumber); 470 intf->cur_altsetting->desc.bInterfaceNumber);
413 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) 471 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
414 sms_info("endpoint %d %02x %02x %d", i, 472 sms_info("endpoint %d %02x %02x %d", i,
415 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress, 473 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
416 intf->cur_altsetting->endpoint[i].desc.bmAttributes, 474 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
417 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize); 475 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
418 476 if (intf->cur_altsetting->endpoint[i].desc.bEndpointAddress &
477 USB_DIR_IN)
478 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev,
479 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress));
480 else
481 rc = usb_clear_halt(udev, usb_sndbulkpipe(udev,
482 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress));
483 }
419 if ((udev->actconfig->desc.bNumInterfaces == 2) && 484 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
420 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) { 485 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
421 sms_err("rom interface 0 is not used"); 486 sms_err("rom interface 0 is not used");
422 return -ENODEV; 487 return -ENODEV;
423 } 488 }
424 489
425 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { 490 if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) {
491 sms_info("stellar device was found.");
426 snprintf(devpath, sizeof(devpath), "usb\\%d-%s", 492 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
427 udev->bus->busnum, udev->devpath); 493 udev->bus->busnum, udev->devpath);
428 sms_info("stellar device was found."); 494 sms_info("stellar device was found.");
@@ -445,7 +511,9 @@ static void smsusb_disconnect(struct usb_interface *intf)
445static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg) 511static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
446{ 512{
447 struct smsusb_device_t *dev = usb_get_intfdata(intf); 513 struct smsusb_device_t *dev = usb_get_intfdata(intf);
448 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event); 514 printk(KERN_INFO "%s Entering status %d.\n", __func__, msg.event);
515 dev->state = SMSUSB_SUSPENDED;
516 /*smscore_set_power_mode(dev, SMS_POWER_MODE_SUSPENDED);*/
449 smsusb_stop_streaming(dev); 517 smsusb_stop_streaming(dev);
450 return 0; 518 return 0;
451} 519}
@@ -456,9 +524,9 @@ static int smsusb_resume(struct usb_interface *intf)
456 struct smsusb_device_t *dev = usb_get_intfdata(intf); 524 struct smsusb_device_t *dev = usb_get_intfdata(intf);
457 struct usb_device *udev = interface_to_usbdev(intf); 525 struct usb_device *udev = interface_to_usbdev(intf);
458 526
459 printk(KERN_INFO "%s: Entering.\n", __func__); 527 printk(KERN_INFO "%s Entering.\n", __func__);
460 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81)); 528 usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->in_ep));
461 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02)); 529 usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->out_ep));
462 530
463 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) 531 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++)
464 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i, 532 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i,
@@ -546,6 +614,26 @@ static const struct usb_device_id smsusb_id_table[] = {
546 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, 614 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
547 { USB_DEVICE(0x2040, 0xf5a0), 615 { USB_DEVICE(0x2040, 0xf5a0),
548 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, 616 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
617 { USB_DEVICE(0x187f, 0x0202),
618 .driver_info = SMS1XXX_BOARD_SIANO_NICE },
619 { USB_DEVICE(0x187f, 0x0301),
620 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
621 { USB_DEVICE(0x187f, 0x0302),
622 .driver_info = SMS1XXX_BOARD_SIANO_VENICE },
623 { USB_DEVICE(0x187f, 0x0310),
624 .driver_info = SMS1XXX_BOARD_SIANO_MING },
625 { USB_DEVICE(0x187f, 0x0500),
626 .driver_info = SMS1XXX_BOARD_SIANO_PELE },
627 { USB_DEVICE(0x187f, 0x0600),
628 .driver_info = SMS1XXX_BOARD_SIANO_RIO },
629 { USB_DEVICE(0x187f, 0x0700),
630 .driver_info = SMS1XXX_BOARD_SIANO_DENVER_2160 },
631 { USB_DEVICE(0x187f, 0x0800),
632 .driver_info = SMS1XXX_BOARD_SIANO_DENVER_1530 },
633 { USB_DEVICE(0x19D2, 0x0086),
634 .driver_info = SMS1XXX_BOARD_ZTE_DVB_DATA_CARD },
635 { USB_DEVICE(0x19D2, 0x0078),
636 .driver_info = SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD },
549 { } /* Terminating entry */ 637 { } /* Terminating entry */
550 }; 638 };
551 639
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index 6694f9e2ca57..a59153d2f8bf 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -375,7 +375,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
375 return 0; 375 return 0;
376} 376}
377 377
378static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) 378static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
379{ 379{
380 struct stk1160 *dev = video_drvdata(file); 380 struct stk1160 *dev = video_drvdata(file);
381 struct vb2_queue *q = &dev->vb_vidq; 381 struct vb2_queue *q = &dev->vb_vidq;
@@ -388,7 +388,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
388 return -ENODEV; 388 return -ENODEV;
389 389
390 /* We need to set this now, before we call stk1160_set_std */ 390 /* We need to set this now, before we call stk1160_set_std */
391 dev->norm = *norm; 391 dev->norm = norm;
392 392
393 /* This is taken from saa7115 video decoder */ 393 /* This is taken from saa7115 video decoder */
394 if (dev->norm & V4L2_STD_525_60) { 394 if (dev->norm & V4L2_STD_525_60) {
@@ -458,7 +458,7 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
458 struct v4l2_dbg_chip_ident *chip) 458 struct v4l2_dbg_chip_ident *chip)
459{ 459{
460 switch (chip->match.type) { 460 switch (chip->match.type) {
461 case V4L2_CHIP_MATCH_HOST: 461 case V4L2_CHIP_MATCH_BRIDGE:
462 chip->ident = V4L2_IDENT_NONE; 462 chip->ident = V4L2_IDENT_NONE;
463 chip->revision = 0; 463 chip->revision = 0;
464 return 0; 464 return 0;
@@ -476,9 +476,6 @@ static int vidioc_g_register(struct file *file, void *priv,
476 u8 val; 476 u8 val;
477 477
478 switch (reg->match.type) { 478 switch (reg->match.type) {
479 case V4L2_CHIP_MATCH_AC97:
480 /* TODO: Support me please :-( */
481 return -EINVAL;
482 case V4L2_CHIP_MATCH_I2C_DRIVER: 479 case V4L2_CHIP_MATCH_I2C_DRIVER:
483 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg); 480 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
484 return 0; 481 return 0;
@@ -500,13 +497,11 @@ static int vidioc_g_register(struct file *file, void *priv,
500} 497}
501 498
502static int vidioc_s_register(struct file *file, void *priv, 499static int vidioc_s_register(struct file *file, void *priv,
503 struct v4l2_dbg_register *reg) 500 const struct v4l2_dbg_register *reg)
504{ 501{
505 struct stk1160 *dev = video_drvdata(file); 502 struct stk1160 *dev = video_drvdata(file);
506 503
507 switch (reg->match.type) { 504 switch (reg->match.type) {
508 case V4L2_CHIP_MATCH_AC97:
509 return -EINVAL;
510 case V4L2_CHIP_MATCH_I2C_DRIVER: 505 case V4L2_CHIP_MATCH_I2C_DRIVER:
511 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg); 506 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
512 return 0; 507 return 0;
@@ -687,6 +682,7 @@ int stk1160_vb2_setup(struct stk1160 *dev)
687 q->buf_struct_size = sizeof(struct stk1160_buffer); 682 q->buf_struct_size = sizeof(struct stk1160_buffer);
688 q->ops = &stk1160_video_qops; 683 q->ops = &stk1160_video_qops;
689 q->mem_ops = &vb2_vmalloc_memops; 684 q->mem_ops = &vb2_vmalloc_memops;
685 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
690 686
691 rc = vb2_queue_init(q); 687 rc = vb2_queue_init(q);
692 if (rc < 0) 688 if (rc < 0)
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index 4cbab085e348..c43c8d32be40 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -35,6 +35,7 @@
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-event.h>
38 39
39#include "stk-webcam.h" 40#include "stk-webcam.h"
40 41
@@ -63,7 +64,39 @@ static struct usb_device_id stkwebcam_table[] = {
63}; 64};
64MODULE_DEVICE_TABLE(usb, stkwebcam_table); 65MODULE_DEVICE_TABLE(usb, stkwebcam_table);
65 66
66/* The stk webcam laptop module is mounted upside down in some laptops :( */ 67/*
68 * The stk webcam laptop module is mounted upside down in some laptops :(
69 *
70 * Some background information (thanks to Hans de Goede for providing this):
71 *
72 * 1) Once upon a time the stkwebcam driver was written
73 *
74 * 2) The webcam in question was used mostly in Asus laptop models, including
75 * the laptop of the original author of the driver, and in these models, in
76 * typical Asus fashion (see the long long list for uvc cams inside v4l-utils),
77 * they mounted the webcam-module the wrong way up. So the hflip and vflip
78 * module options were given a default value of 1 (the correct value for
79 * upside down mounted models)
80 *
81 * 3) Years later I got a bug report from a user with a laptop with stkwebcam,
82 * where the module was actually mounted the right way up, and thus showed
83 * upside down under Linux. So now I was facing the choice of 2 options:
84 *
85 * a) Add a not-upside-down list to stkwebcam, which overrules the default.
86 *
87 * b) Do it like all the other drivers do, and make the default right for
88 * cams mounted the proper way and add an upside-down model list, with
89 * models where we need to flip-by-default.
90 *
91 * Despite knowing that going b) would cause a period of pain where we were
92 * building the table I opted to go for option b), since a) is just too ugly,
93 * and worse different from how every other driver does it leading to
94 * confusion in the long run. This change was made in kernel 3.6.
95 *
96 * So for any user report about upside-down images since kernel 3.6 ask them
97 * to provide the output of 'sudo dmidecode' so the laptop can be added in
98 * the table below.
99 */
67static const struct dmi_system_id stk_upside_down_dmi_table[] = { 100static const struct dmi_system_id stk_upside_down_dmi_table[] = {
68 { 101 {
69 .ident = "ASUS G1", 102 .ident = "ASUS G1",
@@ -71,6 +104,12 @@ static const struct dmi_system_id stk_upside_down_dmi_table[] = {
71 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), 104 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
72 DMI_MATCH(DMI_PRODUCT_NAME, "G1") 105 DMI_MATCH(DMI_PRODUCT_NAME, "G1")
73 } 106 }
107 }, {
108 .ident = "ASUS F3JC",
109 .matches = {
110 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
111 DMI_MATCH(DMI_PRODUCT_NAME, "F3JC")
112 }
74 }, 113 },
75 {} 114 {}
76}; 115};
@@ -565,31 +604,31 @@ static void stk_free_buffers(struct stk_camera *dev)
565 604
566static int v4l_stk_open(struct file *fp) 605static int v4l_stk_open(struct file *fp)
567{ 606{
568 static int first_init = 1; /* webcam LED management */ 607 struct stk_camera *dev = video_drvdata(fp);
569 struct stk_camera *dev; 608 int err;
570 struct video_device *vdev;
571
572 vdev = video_devdata(fp);
573 dev = vdev_to_camera(vdev);
574 609
575 if (dev == NULL || !is_present(dev)) 610 if (dev == NULL || !is_present(dev))
576 return -ENXIO; 611 return -ENXIO;
577 612
578 if (!first_init) 613 if (mutex_lock_interruptible(&dev->lock))
614 return -ERESTARTSYS;
615 if (!dev->first_init)
579 stk_camera_write_reg(dev, 0x0, 0x24); 616 stk_camera_write_reg(dev, 0x0, 0x24);
580 else 617 else
581 first_init = 0; 618 dev->first_init = 0;
582
583 fp->private_data = dev;
584 usb_autopm_get_interface(dev->interface);
585 619
586 return 0; 620 err = v4l2_fh_open(fp);
621 if (!err)
622 usb_autopm_get_interface(dev->interface);
623 mutex_unlock(&dev->lock);
624 return err;
587} 625}
588 626
589static int v4l_stk_release(struct file *fp) 627static int v4l_stk_release(struct file *fp)
590{ 628{
591 struct stk_camera *dev = fp->private_data; 629 struct stk_camera *dev = video_drvdata(fp);
592 630
631 mutex_lock(&dev->lock);
593 if (dev->owner == fp) { 632 if (dev->owner == fp) {
594 stk_stop_stream(dev); 633 stk_stop_stream(dev);
595 stk_free_buffers(dev); 634 stk_free_buffers(dev);
@@ -600,22 +639,22 @@ static int v4l_stk_release(struct file *fp)
600 639
601 if (is_present(dev)) 640 if (is_present(dev))
602 usb_autopm_put_interface(dev->interface); 641 usb_autopm_put_interface(dev->interface);
603 642 mutex_unlock(&dev->lock);
604 return 0; 643 return v4l2_fh_release(fp);
605} 644}
606 645
607static ssize_t v4l_stk_read(struct file *fp, char __user *buf, 646static ssize_t stk_read(struct file *fp, char __user *buf,
608 size_t count, loff_t *f_pos) 647 size_t count, loff_t *f_pos)
609{ 648{
610 int i; 649 int i;
611 int ret; 650 int ret;
612 unsigned long flags; 651 unsigned long flags;
613 struct stk_sio_buffer *sbuf; 652 struct stk_sio_buffer *sbuf;
614 struct stk_camera *dev = fp->private_data; 653 struct stk_camera *dev = video_drvdata(fp);
615 654
616 if (!is_present(dev)) 655 if (!is_present(dev))
617 return -EIO; 656 return -EIO;
618 if (dev->owner && dev->owner != fp) 657 if (dev->owner && (!dev->reading || dev->owner != fp))
619 return -EBUSY; 658 return -EBUSY;
620 dev->owner = fp; 659 dev->owner = fp;
621 if (!is_streaming(dev)) { 660 if (!is_streaming(dev)) {
@@ -623,6 +662,7 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
623 || stk_allocate_buffers(dev, 3) 662 || stk_allocate_buffers(dev, 3)
624 || stk_start_stream(dev)) 663 || stk_start_stream(dev))
625 return -ENOMEM; 664 return -ENOMEM;
665 dev->reading = 1;
626 spin_lock_irqsave(&dev->spinlock, flags); 666 spin_lock_irqsave(&dev->spinlock, flags);
627 for (i = 0; i < dev->n_sbufs; i++) { 667 for (i = 0; i < dev->n_sbufs; i++) {
628 list_add_tail(&dev->sio_bufs[i].list, &dev->sio_avail); 668 list_add_tail(&dev->sio_bufs[i].list, &dev->sio_avail);
@@ -665,9 +705,23 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
665 return count; 705 return count;
666} 706}
667 707
708static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
709 size_t count, loff_t *f_pos)
710{
711 struct stk_camera *dev = video_drvdata(fp);
712 int ret;
713
714 if (mutex_lock_interruptible(&dev->lock))
715 return -ERESTARTSYS;
716 ret = stk_read(fp, buf, count, f_pos);
717 mutex_unlock(&dev->lock);
718 return ret;
719}
720
668static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait) 721static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
669{ 722{
670 struct stk_camera *dev = fp->private_data; 723 struct stk_camera *dev = video_drvdata(fp);
724 unsigned res = v4l2_ctrl_poll(fp, wait);
671 725
672 poll_wait(fp, &dev->wait_frame, wait); 726 poll_wait(fp, &dev->wait_frame, wait);
673 727
@@ -675,9 +729,9 @@ static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
675 return POLLERR; 729 return POLLERR;
676 730
677 if (!list_empty(&dev->sio_full)) 731 if (!list_empty(&dev->sio_full))
678 return POLLIN | POLLRDNORM; 732 return res | POLLIN | POLLRDNORM;
679 733
680 return 0; 734 return res;
681} 735}
682 736
683 737
@@ -703,7 +757,7 @@ static int v4l_stk_mmap(struct file *fp, struct vm_area_struct *vma)
703 unsigned int i; 757 unsigned int i;
704 int ret; 758 int ret;
705 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 759 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
706 struct stk_camera *dev = fp->private_data; 760 struct stk_camera *dev = video_drvdata(fp);
707 struct stk_sio_buffer *sbuf = NULL; 761 struct stk_sio_buffer *sbuf = NULL;
708 762
709 if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED)) 763 if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
@@ -733,12 +787,15 @@ static int v4l_stk_mmap(struct file *fp, struct vm_area_struct *vma)
733static int stk_vidioc_querycap(struct file *filp, 787static int stk_vidioc_querycap(struct file *filp,
734 void *priv, struct v4l2_capability *cap) 788 void *priv, struct v4l2_capability *cap)
735{ 789{
790 struct stk_camera *dev = video_drvdata(filp);
791
736 strcpy(cap->driver, "stk"); 792 strcpy(cap->driver, "stk");
737 strcpy(cap->card, "stk"); 793 strcpy(cap->card, "stk");
738 cap->version = DRIVER_VERSION_NUM; 794 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
739 795
740 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE 796 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
741 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 797 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
798 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
742 return 0; 799 return 0;
743} 800}
744 801
@@ -762,111 +819,28 @@ static int stk_vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
762 819
763static int stk_vidioc_s_input(struct file *filp, void *priv, unsigned int i) 820static int stk_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
764{ 821{
765 if (i != 0) 822 return i ? -EINVAL : 0;
766 return -EINVAL;
767 else
768 return 0;
769}
770
771/* from vivi.c */
772static int stk_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a)
773{
774 return 0;
775}
776
777/* List of all V4Lv2 controls supported by the driver */
778static struct v4l2_queryctrl stk_controls[] = {
779 {
780 .id = V4L2_CID_BRIGHTNESS,
781 .type = V4L2_CTRL_TYPE_INTEGER,
782 .name = "Brightness",
783 .minimum = 0,
784 .maximum = 0xffff,
785 .step = 0x0100,
786 .default_value = 0x6000,
787 },
788 {
789 .id = V4L2_CID_HFLIP,
790 .type = V4L2_CTRL_TYPE_BOOLEAN,
791 .name = "Horizontal Flip",
792 .minimum = 0,
793 .maximum = 1,
794 .step = 1,
795 .default_value = 1,
796 },
797 {
798 .id = V4L2_CID_VFLIP,
799 .type = V4L2_CTRL_TYPE_BOOLEAN,
800 .name = "Vertical Flip",
801 .minimum = 0,
802 .maximum = 1,
803 .step = 1,
804 .default_value = 1,
805 },
806};
807
808static int stk_vidioc_queryctrl(struct file *filp,
809 void *priv, struct v4l2_queryctrl *c)
810{
811 int i;
812 int nbr;
813 nbr = ARRAY_SIZE(stk_controls);
814
815 for (i = 0; i < nbr; i++) {
816 if (stk_controls[i].id == c->id) {
817 memcpy(c, &stk_controls[i],
818 sizeof(struct v4l2_queryctrl));
819 return 0;
820 }
821 }
822 return -EINVAL;
823} 823}
824 824
825static int stk_vidioc_g_ctrl(struct file *filp, 825static int stk_s_ctrl(struct v4l2_ctrl *ctrl)
826 void *priv, struct v4l2_control *c)
827{ 826{
828 struct stk_camera *dev = priv; 827 struct stk_camera *dev =
829 switch (c->id) { 828 container_of(ctrl->handler, struct stk_camera, hdl);
830 case V4L2_CID_BRIGHTNESS:
831 c->value = dev->vsettings.brightness;
832 break;
833 case V4L2_CID_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;
838 break;
839 case V4L2_CID_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;
844 break;
845 default:
846 return -EINVAL;
847 }
848 return 0;
849}
850 829
851static int stk_vidioc_s_ctrl(struct file *filp, 830 switch (ctrl->id) {
852 void *priv, struct v4l2_control *c)
853{
854 struct stk_camera *dev = priv;
855 switch (c->id) {
856 case V4L2_CID_BRIGHTNESS: 831 case V4L2_CID_BRIGHTNESS:
857 dev->vsettings.brightness = c->value; 832 return stk_sensor_set_brightness(dev, ctrl->val);
858 return stk_sensor_set_brightness(dev, c->value >> 8);
859 case V4L2_CID_HFLIP: 833 case V4L2_CID_HFLIP:
860 if (dmi_check_system(stk_upside_down_dmi_table)) 834 if (dmi_check_system(stk_upside_down_dmi_table))
861 dev->vsettings.hflip = !c->value; 835 dev->vsettings.hflip = !ctrl->val;
862 else 836 else
863 dev->vsettings.hflip = c->value; 837 dev->vsettings.hflip = ctrl->val;
864 return 0; 838 return 0;
865 case V4L2_CID_VFLIP: 839 case V4L2_CID_VFLIP:
866 if (dmi_check_system(stk_upside_down_dmi_table)) 840 if (dmi_check_system(stk_upside_down_dmi_table))
867 dev->vsettings.vflip = !c->value; 841 dev->vsettings.vflip = !ctrl->val;
868 else 842 else
869 dev->vsettings.vflip = c->value; 843 dev->vsettings.vflip = ctrl->val;
870 return 0; 844 return 0;
871 default: 845 default:
872 return -EINVAL; 846 return -EINVAL;
@@ -921,7 +895,7 @@ static int stk_vidioc_g_fmt_vid_cap(struct file *filp,
921 void *priv, struct v4l2_format *f) 895 void *priv, struct v4l2_format *f)
922{ 896{
923 struct v4l2_pix_format *pix_format = &f->fmt.pix; 897 struct v4l2_pix_format *pix_format = &f->fmt.pix;
924 struct stk_camera *dev = priv; 898 struct stk_camera *dev = video_drvdata(filp);
925 int i; 899 int i;
926 900
927 for (i = 0; i < ARRAY_SIZE(stk_sizes) && 901 for (i = 0; i < ARRAY_SIZE(stk_sizes) &&
@@ -942,11 +916,12 @@ static int stk_vidioc_g_fmt_vid_cap(struct file *filp,
942 pix_format->bytesperline = 2 * pix_format->width; 916 pix_format->bytesperline = 2 * pix_format->width;
943 pix_format->sizeimage = pix_format->bytesperline 917 pix_format->sizeimage = pix_format->bytesperline
944 * pix_format->height; 918 * pix_format->height;
919 pix_format->priv = 0;
945 return 0; 920 return 0;
946} 921}
947 922
948static int stk_vidioc_try_fmt_vid_cap(struct file *filp, 923static int stk_try_fmt_vid_cap(struct file *filp,
949 void *priv, struct v4l2_format *fmtd) 924 struct v4l2_format *fmtd, int *idx)
950{ 925{
951 int i; 926 int i;
952 switch (fmtd->fmt.pix.pixelformat) { 927 switch (fmtd->fmt.pix.pixelformat) {
@@ -968,11 +943,13 @@ static int stk_vidioc_try_fmt_vid_cap(struct file *filp,
968 < abs(fmtd->fmt.pix.width - stk_sizes[i].w))) { 943 < abs(fmtd->fmt.pix.width - stk_sizes[i].w))) {
969 fmtd->fmt.pix.height = stk_sizes[i-1].h; 944 fmtd->fmt.pix.height = stk_sizes[i-1].h;
970 fmtd->fmt.pix.width = stk_sizes[i-1].w; 945 fmtd->fmt.pix.width = stk_sizes[i-1].w;
971 fmtd->fmt.pix.priv = i - 1; 946 if (idx)
947 *idx = i - 1;
972 } else { 948 } else {
973 fmtd->fmt.pix.height = stk_sizes[i].h; 949 fmtd->fmt.pix.height = stk_sizes[i].h;
974 fmtd->fmt.pix.width = stk_sizes[i].w; 950 fmtd->fmt.pix.width = stk_sizes[i].w;
975 fmtd->fmt.pix.priv = i; 951 if (idx)
952 *idx = i;
976 } 953 }
977 954
978 fmtd->fmt.pix.field = V4L2_FIELD_NONE; 955 fmtd->fmt.pix.field = V4L2_FIELD_NONE;
@@ -983,9 +960,16 @@ static int stk_vidioc_try_fmt_vid_cap(struct file *filp,
983 fmtd->fmt.pix.bytesperline = 2 * fmtd->fmt.pix.width; 960 fmtd->fmt.pix.bytesperline = 2 * fmtd->fmt.pix.width;
984 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.bytesperline 961 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.bytesperline
985 * fmtd->fmt.pix.height; 962 * fmtd->fmt.pix.height;
963 fmtd->fmt.pix.priv = 0;
986 return 0; 964 return 0;
987} 965}
988 966
967static int stk_vidioc_try_fmt_vid_cap(struct file *filp,
968 void *priv, struct v4l2_format *fmtd)
969{
970 return stk_try_fmt_vid_cap(filp, fmtd, NULL);
971}
972
989static int stk_setup_format(struct stk_camera *dev) 973static int stk_setup_format(struct stk_camera *dev)
990{ 974{
991 int i = 0; 975 int i = 0;
@@ -1026,7 +1010,8 @@ static int stk_vidioc_s_fmt_vid_cap(struct file *filp,
1026 void *priv, struct v4l2_format *fmtd) 1010 void *priv, struct v4l2_format *fmtd)
1027{ 1011{
1028 int ret; 1012 int ret;
1029 struct stk_camera *dev = priv; 1013 int idx;
1014 struct stk_camera *dev = video_drvdata(filp);
1030 1015
1031 if (dev == NULL) 1016 if (dev == NULL)
1032 return -ENODEV; 1017 return -ENODEV;
@@ -1034,17 +1019,16 @@ static int stk_vidioc_s_fmt_vid_cap(struct file *filp,
1034 return -ENODEV; 1019 return -ENODEV;
1035 if (is_streaming(dev)) 1020 if (is_streaming(dev))
1036 return -EBUSY; 1021 return -EBUSY;
1037 if (dev->owner && dev->owner != filp) 1022 if (dev->owner)
1038 return -EBUSY; 1023 return -EBUSY;
1039 ret = stk_vidioc_try_fmt_vid_cap(filp, priv, fmtd); 1024 ret = stk_try_fmt_vid_cap(filp, fmtd, &idx);
1040 if (ret) 1025 if (ret)
1041 return ret; 1026 return ret;
1042 dev->owner = filp;
1043 1027
1044 dev->vsettings.palette = fmtd->fmt.pix.pixelformat; 1028 dev->vsettings.palette = fmtd->fmt.pix.pixelformat;
1045 stk_free_buffers(dev); 1029 stk_free_buffers(dev);
1046 dev->frame_size = fmtd->fmt.pix.sizeimage; 1030 dev->frame_size = fmtd->fmt.pix.sizeimage;
1047 dev->vsettings.mode = stk_sizes[fmtd->fmt.pix.priv].m; 1031 dev->vsettings.mode = stk_sizes[idx].m;
1048 1032
1049 stk_initialise(dev); 1033 stk_initialise(dev);
1050 return stk_setup_format(dev); 1034 return stk_setup_format(dev);
@@ -1053,7 +1037,7 @@ static int stk_vidioc_s_fmt_vid_cap(struct file *filp,
1053static int stk_vidioc_reqbufs(struct file *filp, 1037static int stk_vidioc_reqbufs(struct file *filp,
1054 void *priv, struct v4l2_requestbuffers *rb) 1038 void *priv, struct v4l2_requestbuffers *rb)
1055{ 1039{
1056 struct stk_camera *dev = priv; 1040 struct stk_camera *dev = video_drvdata(filp);
1057 1041
1058 if (dev == NULL) 1042 if (dev == NULL)
1059 return -ENODEV; 1043 return -ENODEV;
@@ -1062,6 +1046,13 @@ static int stk_vidioc_reqbufs(struct file *filp,
1062 if (is_streaming(dev) 1046 if (is_streaming(dev)
1063 || (dev->owner && dev->owner != filp)) 1047 || (dev->owner && dev->owner != filp))
1064 return -EBUSY; 1048 return -EBUSY;
1049 stk_free_buffers(dev);
1050 if (rb->count == 0) {
1051 stk_camera_write_reg(dev, 0x0, 0x49); /* turn off the LED */
1052 unset_initialised(dev);
1053 dev->owner = NULL;
1054 return 0;
1055 }
1065 dev->owner = filp; 1056 dev->owner = filp;
1066 1057
1067 /*FIXME If they ask for zero, we must stop streaming and free */ 1058 /*FIXME If they ask for zero, we must stop streaming and free */
@@ -1079,7 +1070,7 @@ static int stk_vidioc_reqbufs(struct file *filp,
1079static int stk_vidioc_querybuf(struct file *filp, 1070static int stk_vidioc_querybuf(struct file *filp,
1080 void *priv, struct v4l2_buffer *buf) 1071 void *priv, struct v4l2_buffer *buf)
1081{ 1072{
1082 struct stk_camera *dev = priv; 1073 struct stk_camera *dev = video_drvdata(filp);
1083 struct stk_sio_buffer *sbuf; 1074 struct stk_sio_buffer *sbuf;
1084 1075
1085 if (buf->index >= dev->n_sbufs) 1076 if (buf->index >= dev->n_sbufs)
@@ -1092,7 +1083,7 @@ static int stk_vidioc_querybuf(struct file *filp,
1092static int stk_vidioc_qbuf(struct file *filp, 1083static int stk_vidioc_qbuf(struct file *filp,
1093 void *priv, struct v4l2_buffer *buf) 1084 void *priv, struct v4l2_buffer *buf)
1094{ 1085{
1095 struct stk_camera *dev = priv; 1086 struct stk_camera *dev = video_drvdata(filp);
1096 struct stk_sio_buffer *sbuf; 1087 struct stk_sio_buffer *sbuf;
1097 unsigned long flags; 1088 unsigned long flags;
1098 1089
@@ -1116,7 +1107,7 @@ static int stk_vidioc_qbuf(struct file *filp,
1116static int stk_vidioc_dqbuf(struct file *filp, 1107static int stk_vidioc_dqbuf(struct file *filp,
1117 void *priv, struct v4l2_buffer *buf) 1108 void *priv, struct v4l2_buffer *buf)
1118{ 1109{
1119 struct stk_camera *dev = priv; 1110 struct stk_camera *dev = video_drvdata(filp);
1120 struct stk_sio_buffer *sbuf; 1111 struct stk_sio_buffer *sbuf;
1121 unsigned long flags; 1112 unsigned long flags;
1122 int ret; 1113 int ret;
@@ -1149,7 +1140,7 @@ static int stk_vidioc_dqbuf(struct file *filp,
1149static int stk_vidioc_streamon(struct file *filp, 1140static int stk_vidioc_streamon(struct file *filp,
1150 void *priv, enum v4l2_buf_type type) 1141 void *priv, enum v4l2_buf_type type)
1151{ 1142{
1152 struct stk_camera *dev = priv; 1143 struct stk_camera *dev = video_drvdata(filp);
1153 if (is_streaming(dev)) 1144 if (is_streaming(dev))
1154 return 0; 1145 return 0;
1155 if (dev->sio_bufs == NULL) 1146 if (dev->sio_bufs == NULL)
@@ -1161,7 +1152,7 @@ static int stk_vidioc_streamon(struct file *filp,
1161static int stk_vidioc_streamoff(struct file *filp, 1152static int stk_vidioc_streamoff(struct file *filp,
1162 void *priv, enum v4l2_buf_type type) 1153 void *priv, enum v4l2_buf_type type)
1163{ 1154{
1164 struct stk_camera *dev = priv; 1155 struct stk_camera *dev = video_drvdata(filp);
1165 unsigned long flags; 1156 unsigned long flags;
1166 int i; 1157 int i;
1167 stk_stop_stream(dev); 1158 stk_stop_stream(dev);
@@ -1206,6 +1197,10 @@ static int stk_vidioc_enum_framesizes(struct file *filp,
1206 } 1197 }
1207} 1198}
1208 1199
1200static const struct v4l2_ctrl_ops stk_ctrl_ops = {
1201 .s_ctrl = stk_s_ctrl,
1202};
1203
1209static struct v4l2_file_operations v4l_stk_fops = { 1204static struct v4l2_file_operations v4l_stk_fops = {
1210 .owner = THIS_MODULE, 1205 .owner = THIS_MODULE,
1211 .open = v4l_stk_open, 1206 .open = v4l_stk_open,
@@ -1213,7 +1208,7 @@ static struct v4l2_file_operations v4l_stk_fops = {
1213 .read = v4l_stk_read, 1208 .read = v4l_stk_read,
1214 .poll = v4l_stk_poll, 1209 .poll = v4l_stk_poll,
1215 .mmap = v4l_stk_mmap, 1210 .mmap = v4l_stk_mmap,
1216 .ioctl = video_ioctl2, 1211 .unlocked_ioctl = video_ioctl2,
1217}; 1212};
1218 1213
1219static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = { 1214static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
@@ -1225,18 +1220,17 @@ static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
1225 .vidioc_enum_input = stk_vidioc_enum_input, 1220 .vidioc_enum_input = stk_vidioc_enum_input,
1226 .vidioc_s_input = stk_vidioc_s_input, 1221 .vidioc_s_input = stk_vidioc_s_input,
1227 .vidioc_g_input = stk_vidioc_g_input, 1222 .vidioc_g_input = stk_vidioc_g_input,
1228 .vidioc_s_std = stk_vidioc_s_std,
1229 .vidioc_reqbufs = stk_vidioc_reqbufs, 1223 .vidioc_reqbufs = stk_vidioc_reqbufs,
1230 .vidioc_querybuf = stk_vidioc_querybuf, 1224 .vidioc_querybuf = stk_vidioc_querybuf,
1231 .vidioc_qbuf = stk_vidioc_qbuf, 1225 .vidioc_qbuf = stk_vidioc_qbuf,
1232 .vidioc_dqbuf = stk_vidioc_dqbuf, 1226 .vidioc_dqbuf = stk_vidioc_dqbuf,
1233 .vidioc_streamon = stk_vidioc_streamon, 1227 .vidioc_streamon = stk_vidioc_streamon,
1234 .vidioc_streamoff = stk_vidioc_streamoff, 1228 .vidioc_streamoff = stk_vidioc_streamoff,
1235 .vidioc_queryctrl = stk_vidioc_queryctrl,
1236 .vidioc_g_ctrl = stk_vidioc_g_ctrl,
1237 .vidioc_s_ctrl = stk_vidioc_s_ctrl,
1238 .vidioc_g_parm = stk_vidioc_g_parm, 1229 .vidioc_g_parm = stk_vidioc_g_parm,
1239 .vidioc_enum_framesizes = stk_vidioc_enum_framesizes, 1230 .vidioc_enum_framesizes = stk_vidioc_enum_framesizes,
1231 .vidioc_log_status = v4l2_ctrl_log_status,
1232 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1233 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1240}; 1234};
1241 1235
1242static void stk_v4l_dev_release(struct video_device *vd) 1236static void stk_v4l_dev_release(struct video_device *vd)
@@ -1251,8 +1245,6 @@ static void stk_v4l_dev_release(struct video_device *vd)
1251 1245
1252static struct video_device stk_v4l_data = { 1246static struct video_device stk_v4l_data = {
1253 .name = "stkwebcam", 1247 .name = "stkwebcam",
1254 .tvnorms = V4L2_STD_UNKNOWN,
1255 .current_norm = V4L2_STD_UNKNOWN,
1256 .fops = &v4l_stk_fops, 1248 .fops = &v4l_stk_fops,
1257 .ioctl_ops = &v4l_stk_ioctl_ops, 1249 .ioctl_ops = &v4l_stk_ioctl_ops,
1258 .release = stk_v4l_dev_release, 1250 .release = stk_v4l_dev_release,
@@ -1264,8 +1256,11 @@ static int stk_register_video_device(struct stk_camera *dev)
1264 int err; 1256 int err;
1265 1257
1266 dev->vdev = stk_v4l_data; 1258 dev->vdev = stk_v4l_data;
1259 dev->vdev.lock = &dev->lock;
1267 dev->vdev.debug = debug; 1260 dev->vdev.debug = debug;
1268 dev->vdev.parent = &dev->interface->dev; 1261 dev->vdev.v4l2_dev = &dev->v4l2_dev;
1262 set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
1263 video_set_drvdata(&dev->vdev, dev);
1269 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1); 1264 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
1270 if (err) 1265 if (err)
1271 STK_ERROR("v4l registration failed\n"); 1266 STK_ERROR("v4l registration failed\n");
@@ -1281,8 +1276,9 @@ static int stk_register_video_device(struct stk_camera *dev)
1281static int stk_camera_probe(struct usb_interface *interface, 1276static int stk_camera_probe(struct usb_interface *interface,
1282 const struct usb_device_id *id) 1277 const struct usb_device_id *id)
1283{ 1278{
1284 int i; 1279 struct v4l2_ctrl_handler *hdl;
1285 int err = 0; 1280 int err = 0;
1281 int i;
1286 1282
1287 struct stk_camera *dev = NULL; 1283 struct stk_camera *dev = NULL;
1288 struct usb_device *udev = interface_to_usbdev(interface); 1284 struct usb_device *udev = interface_to_usbdev(interface);
@@ -1294,9 +1290,31 @@ static int stk_camera_probe(struct usb_interface *interface,
1294 STK_ERROR("Out of memory !\n"); 1290 STK_ERROR("Out of memory !\n");
1295 return -ENOMEM; 1291 return -ENOMEM;
1296 } 1292 }
1293 err = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
1294 if (err < 0) {
1295 dev_err(&udev->dev, "couldn't register v4l2_device\n");
1296 kfree(dev);
1297 return err;
1298 }
1299 hdl = &dev->hdl;
1300 v4l2_ctrl_handler_init(hdl, 3);
1301 v4l2_ctrl_new_std(hdl, &stk_ctrl_ops,
1302 V4L2_CID_BRIGHTNESS, 0, 0xff, 0x1, 0x60);
1303 v4l2_ctrl_new_std(hdl, &stk_ctrl_ops,
1304 V4L2_CID_HFLIP, 0, 1, 1, 1);
1305 v4l2_ctrl_new_std(hdl, &stk_ctrl_ops,
1306 V4L2_CID_VFLIP, 0, 1, 1, 1);
1307 if (hdl->error) {
1308 err = hdl->error;
1309 dev_err(&udev->dev, "couldn't register control\n");
1310 goto error;
1311 }
1312 dev->v4l2_dev.ctrl_handler = hdl;
1297 1313
1298 spin_lock_init(&dev->spinlock); 1314 spin_lock_init(&dev->spinlock);
1315 mutex_init(&dev->lock);
1299 init_waitqueue_head(&dev->wait_frame); 1316 init_waitqueue_head(&dev->wait_frame);
1317 dev->first_init = 1; /* webcam LED management */
1300 1318
1301 dev->udev = udev; 1319 dev->udev = udev;
1302 dev->interface = interface; 1320 dev->interface = interface;
@@ -1337,7 +1355,6 @@ static int stk_camera_probe(struct usb_interface *interface,
1337 err = -ENODEV; 1355 err = -ENODEV;
1338 goto error; 1356 goto error;
1339 } 1357 }
1340 dev->vsettings.brightness = 0x7fff;
1341 dev->vsettings.palette = V4L2_PIX_FMT_RGB565; 1358 dev->vsettings.palette = V4L2_PIX_FMT_RGB565;
1342 dev->vsettings.mode = MODE_VGA; 1359 dev->vsettings.mode = MODE_VGA;
1343 dev->frame_size = 640 * 480 * 2; 1360 dev->frame_size = 640 * 480 * 2;
@@ -1354,6 +1371,8 @@ static int stk_camera_probe(struct usb_interface *interface,
1354 return 0; 1371 return 0;
1355 1372
1356error: 1373error:
1374 v4l2_ctrl_handler_free(hdl);
1375 v4l2_device_unregister(&dev->v4l2_dev);
1357 kfree(dev); 1376 kfree(dev);
1358 return err; 1377 return err;
1359} 1378}
@@ -1371,6 +1390,8 @@ static void stk_camera_disconnect(struct usb_interface *interface)
1371 video_device_node_name(&dev->vdev)); 1390 video_device_node_name(&dev->vdev));
1372 1391
1373 video_unregister_device(&dev->vdev); 1392 video_unregister_device(&dev->vdev);
1393 v4l2_ctrl_handler_free(&dev->hdl);
1394 v4l2_device_unregister(&dev->v4l2_dev);
1374} 1395}
1375 1396
1376#ifdef CONFIG_PM 1397#ifdef CONFIG_PM
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.h b/drivers/media/usb/stkwebcam/stk-webcam.h
index 9f6736637571..9bbfa3d9bfdd 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.h
+++ b/drivers/media/usb/stkwebcam/stk-webcam.h
@@ -23,6 +23,8 @@
23#define STKWEBCAM_H 23#define STKWEBCAM_H
24 24
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <media/v4l2-device.h>
27#include <media/v4l2-ctrls.h>
26#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
27 29
28#define DRIVER_VERSION "v0.0.1" 30#define DRIVER_VERSION "v0.0.1"
@@ -59,7 +61,6 @@ enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};
59 61
60struct stk_video { 62struct stk_video {
61 enum stk_mode mode; 63 enum stk_mode mode;
62 int brightness;
63 __u32 palette; 64 __u32 palette;
64 int hflip; 65 int hflip;
65 int vflip; 66 int vflip;
@@ -91,11 +92,15 @@ struct regval {
91}; 92};
92 93
93struct stk_camera { 94struct stk_camera {
95 struct v4l2_device v4l2_dev;
96 struct v4l2_ctrl_handler hdl;
94 struct video_device vdev; 97 struct video_device vdev;
95 struct usb_device *udev; 98 struct usb_device *udev;
96 struct usb_interface *interface; 99 struct usb_interface *interface;
97 int webcam_model; 100 int webcam_model;
98 struct file *owner; 101 struct file *owner;
102 struct mutex lock;
103 int first_init;
99 104
100 u8 isoc_ep; 105 u8 isoc_ep;
101 106
@@ -113,6 +118,7 @@ struct stk_camera {
113 118
114 int frame_size; 119 int frame_size;
115 /* Streaming buffers */ 120 /* Streaming buffers */
121 int reading;
116 unsigned int n_sbufs; 122 unsigned int n_sbufs;
117 struct stk_sio_buffer *sio_bufs; 123 struct stk_sio_buffer *sio_bufs;
118 struct list_head sio_avail; 124 struct list_head sio_avail;
diff --git a/drivers/media/usb/tlg2300/pd-common.h b/drivers/media/usb/tlg2300/pd-common.h
index 5dd73b7857d1..9e23ad32d2fe 100644
--- a/drivers/media/usb/tlg2300/pd-common.h
+++ b/drivers/media/usb/tlg2300/pd-common.h
@@ -10,6 +10,7 @@
10#include <linux/poll.h> 10#include <linux/poll.h>
11#include <media/videobuf-vmalloc.h> 11#include <media/videobuf-vmalloc.h>
12#include <media/v4l2-device.h> 12#include <media/v4l2-device.h>
13#include <media/v4l2-ctrls.h>
13 14
14#include "dvb_frontend.h" 15#include "dvb_frontend.h"
15#include "dvbdev.h" 16#include "dvbdev.h"
@@ -25,7 +26,6 @@
25#define POSEIDON_STATE_ANALOG (0x0001) 26#define POSEIDON_STATE_ANALOG (0x0001)
26#define POSEIDON_STATE_FM (0x0002) 27#define POSEIDON_STATE_FM (0x0002)
27#define POSEIDON_STATE_DVBT (0x0004) 28#define POSEIDON_STATE_DVBT (0x0004)
28#define POSEIDON_STATE_VBI (0x0008)
29#define POSEIDON_STATE_DISCONNECT (0x0080) 29#define POSEIDON_STATE_DISCONNECT (0x0080)
30 30
31#define PM_SUSPEND_DELAY 3 31#define PM_SUSPEND_DELAY 3
@@ -35,11 +35,11 @@
35#define V4L_PAL_VBI_FRAMESIZE (V4L_PAL_VBI_LINES * 1440 * 2) 35#define V4L_PAL_VBI_FRAMESIZE (V4L_PAL_VBI_LINES * 1440 * 2)
36#define V4L_NTSC_VBI_FRAMESIZE (V4L_NTSC_VBI_LINES * 1440 * 2) 36#define V4L_NTSC_VBI_FRAMESIZE (V4L_NTSC_VBI_LINES * 1440 * 2)
37 37
38#define TUNER_FREQ_MIN (45000000) 38#define TUNER_FREQ_MIN (45000000U)
39#define TUNER_FREQ_MAX (862000000) 39#define TUNER_FREQ_MAX (862000000U)
40 40
41struct vbi_data { 41struct vbi_data {
42 struct video_device *v_dev; 42 struct video_device v_dev;
43 struct video_data *video; 43 struct video_data *video;
44 struct front_face *front; 44 struct front_face *front;
45 45
@@ -62,7 +62,8 @@ struct running_context {
62 62
63struct video_data { 63struct video_data {
64 /* v4l2 video device */ 64 /* v4l2 video device */
65 struct video_device *v_dev; 65 struct video_device v_dev;
66 struct v4l2_ctrl_handler ctrl_handler;
66 67
67 /* the working context */ 68 /* the working context */
68 struct running_context context; 69 struct running_context context;
@@ -115,10 +116,10 @@ struct poseidon_audio {
115 116
116struct radio_data { 117struct radio_data {
117 __u32 fm_freq; 118 __u32 fm_freq;
118 int users;
119 unsigned int is_radio_streaming; 119 unsigned int is_radio_streaming;
120 int pre_emphasis; 120 int pre_emphasis;
121 struct video_device *fm_dev; 121 struct video_device fm_dev;
122 struct v4l2_ctrl_handler ctrl_handler;
122}; 123};
123 124
124#define DVB_SBUF_NUM 4 125#define DVB_SBUF_NUM 4
@@ -233,7 +234,6 @@ void dvb_stop_streaming(struct pd_dvb_adapter *);
233/* FM */ 234/* FM */
234int poseidon_fm_init(struct poseidon *); 235int poseidon_fm_init(struct poseidon *);
235int poseidon_fm_exit(struct poseidon *); 236int poseidon_fm_exit(struct poseidon *);
236struct video_device *vdev_init(struct poseidon *, struct video_device *);
237 237
238/* vendor command ops */ 238/* vendor command ops */
239int send_set_req(struct poseidon*, u8, s32, s32*); 239int send_set_req(struct poseidon*, u8, s32, s32*);
@@ -249,7 +249,6 @@ void free_all_urb_generic(struct urb **urb_array, int num);
249 249
250/* misc */ 250/* misc */
251void poseidon_delete(struct kref *kref); 251void poseidon_delete(struct kref *kref);
252void destroy_video_device(struct video_device **v_dev);
253extern int debug_mode; 252extern int debug_mode;
254void set_debug_mode(struct video_device *vfd, int debug_mode); 253void set_debug_mode(struct video_device *vfd, int debug_mode);
255 254
@@ -269,13 +268,4 @@ void set_debug_mode(struct video_device *vfd, int debug_mode);
269 log();\ 268 log();\
270 } while (0) 269 } while (0)
271 270
272#define logs(f) do { \
273 if ((debug_mode & 0x4) && \
274 (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
275 log("type : VBI");\
276 \
277 if ((debug_mode & 0x8) && \
278 (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
279 log("type : VIDEO");\
280 } while (0)
281#endif 271#endif
diff --git a/drivers/media/usb/tlg2300/pd-main.c b/drivers/media/usb/tlg2300/pd-main.c
index 7b1f6ebd0e2c..e07e4c699cc2 100644
--- a/drivers/media/usb/tlg2300/pd-main.c
+++ b/drivers/media/usb/tlg2300/pd-main.c
@@ -55,7 +55,6 @@ MODULE_PARM_DESC(debug_mode, "0 = disable, 1 = enable, 2 = verbose");
55 55
56#define TLG2300_FIRMWARE "tlg2300_firmware.bin" 56#define TLG2300_FIRMWARE "tlg2300_firmware.bin"
57static const char *firmware_name = TLG2300_FIRMWARE; 57static const char *firmware_name = TLG2300_FIRMWARE;
58static struct usb_driver poseidon_driver;
59static LIST_HEAD(pd_device_list); 58static LIST_HEAD(pd_device_list);
60 59
61/* 60/*
@@ -268,7 +267,8 @@ static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev)
268static inline int get_autopm_ref(struct poseidon *pd) 267static inline int get_autopm_ref(struct poseidon *pd)
269{ 268{
270 return pd->video_data.users + pd->vbi_data.users + pd->audio.users 269 return pd->video_data.users + pd->vbi_data.users + pd->audio.users
271 + atomic_read(&pd->dvb_data.users) + pd->radio_data.users; 270 + atomic_read(&pd->dvb_data.users) +
271 !list_empty(&pd->radio_data.fm_dev.fh_list);
272} 272}
273 273
274/* fixup something for poseidon */ 274/* fixup something for poseidon */
@@ -316,7 +316,7 @@ static int poseidon_suspend(struct usb_interface *intf, pm_message_t msg)
316 if (get_pm_count(pd) <= 0 && !in_hibernation(pd)) { 316 if (get_pm_count(pd) <= 0 && !in_hibernation(pd)) {
317 pd->msg.event = PM_EVENT_AUTO_SUSPEND; 317 pd->msg.event = PM_EVENT_AUTO_SUSPEND;
318 pd->pm_resume = NULL; /* a good guard */ 318 pd->pm_resume = NULL; /* a good guard */
319 printk(KERN_DEBUG "\n\t+ TLG2300 auto suspend +\n\n"); 319 printk(KERN_DEBUG "TLG2300 auto suspend\n");
320 } 320 }
321 return 0; 321 return 0;
322 } 322 }
@@ -331,7 +331,7 @@ static int poseidon_resume(struct usb_interface *intf)
331 331
332 if (!pd) 332 if (!pd)
333 return 0; 333 return 0;
334 printk(KERN_DEBUG "\n\t ++ TLG2300 resume ++\n\n"); 334 printk(KERN_DEBUG "TLG2300 resume\n");
335 335
336 if (!is_working(pd)) { 336 if (!is_working(pd)) {
337 if (PM_EVENT_AUTO_SUSPEND == pd->msg.event) 337 if (PM_EVENT_AUTO_SUSPEND == pd->msg.event)
@@ -431,15 +431,11 @@ static int poseidon_probe(struct usb_interface *interface,
431 usb_set_intfdata(interface, pd); 431 usb_set_intfdata(interface, pd);
432 432
433 if (new_one) { 433 if (new_one) {
434 struct device *dev = &interface->dev;
435
436 logpm(pd); 434 logpm(pd);
437 mutex_init(&pd->lock); 435 mutex_init(&pd->lock);
438 436
439 /* register v4l2 device */ 437 /* register v4l2 device */
440 snprintf(pd->v4l2_dev.name, sizeof(pd->v4l2_dev.name), "%s %s", 438 ret = v4l2_device_register(&interface->dev, &pd->v4l2_dev);
441 dev->driver->name, dev_name(dev));
442 ret = v4l2_device_register(NULL, &pd->v4l2_dev);
443 439
444 /* register devices in directory /dev */ 440 /* register devices in directory /dev */
445 ret = pd_video_init(pd); 441 ret = pd_video_init(pd);
@@ -530,7 +526,7 @@ module_init(poseidon_init);
530module_exit(poseidon_exit); 526module_exit(poseidon_exit);
531 527
532MODULE_AUTHOR("Telegent Systems"); 528MODULE_AUTHOR("Telegent Systems");
533MODULE_DESCRIPTION("For tlg2300-based USB device "); 529MODULE_DESCRIPTION("For tlg2300-based USB device");
534MODULE_LICENSE("GPL"); 530MODULE_LICENSE("GPL");
535MODULE_VERSION("0.0.2"); 531MODULE_VERSION("0.0.2");
536MODULE_FIRMWARE(TLG2300_FIRMWARE); 532MODULE_FIRMWARE(TLG2300_FIRMWARE);
diff --git a/drivers/media/usb/tlg2300/pd-radio.c b/drivers/media/usb/tlg2300/pd-radio.c
index 25eeb166aa0b..ea6070ba835e 100644
--- a/drivers/media/usb/tlg2300/pd-radio.c
+++ b/drivers/media/usb/tlg2300/pd-radio.c
@@ -9,6 +9,8 @@
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <linux/mutex.h> 10#include <linux/mutex.h>
11#include <media/v4l2-ioctl.h> 11#include <media/v4l2-ioctl.h>
12#include <media/v4l2-event.h>
13#include <media/v4l2-fh.h>
12#include <linux/sched.h> 14#include <linux/sched.h>
13 15
14#include "pd-common.h" 16#include "pd-common.h"
@@ -18,8 +20,8 @@ static int set_frequency(struct poseidon *p, __u32 frequency);
18static int poseidon_fm_close(struct file *filp); 20static int poseidon_fm_close(struct file *filp);
19static int poseidon_fm_open(struct file *filp); 21static int poseidon_fm_open(struct file *filp);
20 22
21#define TUNER_FREQ_MIN_FM 76000000 23#define TUNER_FREQ_MIN_FM 76000000U
22#define TUNER_FREQ_MAX_FM 108000000 24#define TUNER_FREQ_MAX_FM 108000000U
23 25
24#define MAX_PREEMPHASIS (V4L2_PREEMPHASIS_75_uS + 1) 26#define MAX_PREEMPHASIS (V4L2_PREEMPHASIS_75_uS + 1)
25static int preemphasis[MAX_PREEMPHASIS] = { 27static int preemphasis[MAX_PREEMPHASIS] = {
@@ -77,13 +79,9 @@ static int pm_fm_resume(struct poseidon *p)
77 79
78static int poseidon_fm_open(struct file *filp) 80static int poseidon_fm_open(struct file *filp)
79{ 81{
80 struct video_device *vfd = video_devdata(filp); 82 struct poseidon *p = video_drvdata(filp);
81 struct poseidon *p = video_get_drvdata(vfd);
82 int ret = 0; 83 int ret = 0;
83 84
84 if (!p)
85 return -1;
86
87 mutex_lock(&p->lock); 85 mutex_lock(&p->lock);
88 if (p->state & POSEIDON_STATE_DISCONNECT) { 86 if (p->state & POSEIDON_STATE_DISCONNECT) {
89 ret = -ENODEV; 87 ret = -ENODEV;
@@ -94,9 +92,14 @@ static int poseidon_fm_open(struct file *filp)
94 ret = -EBUSY; 92 ret = -EBUSY;
95 goto out; 93 goto out;
96 } 94 }
95 ret = v4l2_fh_open(filp);
96 if (ret)
97 goto out;
97 98
98 usb_autopm_get_interface(p->interface); 99 usb_autopm_get_interface(p->interface);
99 if (0 == p->state) { 100 if (0 == p->state) {
101 struct video_device *vfd = &p->radio_data.fm_dev;
102
100 /* default pre-emphasis */ 103 /* default pre-emphasis */
101 if (p->radio_data.pre_emphasis == 0) 104 if (p->radio_data.pre_emphasis == 0)
102 p->radio_data.pre_emphasis = TLG_TUNE_ASTD_FM_EUR; 105 p->radio_data.pre_emphasis = TLG_TUNE_ASTD_FM_EUR;
@@ -109,9 +112,7 @@ static int poseidon_fm_open(struct file *filp)
109 } 112 }
110 p->state |= POSEIDON_STATE_FM; 113 p->state |= POSEIDON_STATE_FM;
111 } 114 }
112 p->radio_data.users++;
113 kref_get(&p->kref); 115 kref_get(&p->kref);
114 filp->private_data = p;
115out: 116out:
116 mutex_unlock(&p->lock); 117 mutex_unlock(&p->lock);
117 return ret; 118 return ret;
@@ -119,13 +120,12 @@ out:
119 120
120static int poseidon_fm_close(struct file *filp) 121static int poseidon_fm_close(struct file *filp)
121{ 122{
122 struct poseidon *p = filp->private_data; 123 struct poseidon *p = video_drvdata(filp);
123 struct radio_data *fm = &p->radio_data; 124 struct radio_data *fm = &p->radio_data;
124 uint32_t status; 125 uint32_t status;
125 126
126 mutex_lock(&p->lock); 127 mutex_lock(&p->lock);
127 fm->users--; 128 if (v4l2_fh_is_singular_file(filp))
128 if (0 == fm->users)
129 p->state &= ~POSEIDON_STATE_FM; 129 p->state &= ~POSEIDON_STATE_FM;
130 130
131 if (fm->is_radio_streaming && filp == p->file_for_stream) { 131 if (fm->is_radio_streaming && filp == p->file_for_stream) {
@@ -136,19 +136,23 @@ static int poseidon_fm_close(struct file *filp)
136 mutex_unlock(&p->lock); 136 mutex_unlock(&p->lock);
137 137
138 kref_put(&p->kref, poseidon_delete); 138 kref_put(&p->kref, poseidon_delete);
139 filp->private_data = NULL; 139 return v4l2_fh_release(filp);
140 return 0;
141} 140}
142 141
143static int vidioc_querycap(struct file *file, void *priv, 142static int vidioc_querycap(struct file *file, void *priv,
144 struct v4l2_capability *v) 143 struct v4l2_capability *v)
145{ 144{
146 struct poseidon *p = file->private_data; 145 struct poseidon *p = video_drvdata(file);
147 146
148 strlcpy(v->driver, "tele-radio", sizeof(v->driver)); 147 strlcpy(v->driver, "tele-radio", sizeof(v->driver));
149 strlcpy(v->card, "Telegent Poseidon", sizeof(v->card)); 148 strlcpy(v->card, "Telegent Poseidon", sizeof(v->card));
150 usb_make_path(p->udev, v->bus_info, sizeof(v->bus_info)); 149 usb_make_path(p->udev, v->bus_info, sizeof(v->bus_info));
151 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 150 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
151 /* Report all capabilities of the USB device */
152 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS |
153 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
154 V4L2_CAP_AUDIO | V4L2_CAP_STREAMING |
155 V4L2_CAP_READWRITE;
152 return 0; 156 return 0;
153} 157}
154 158
@@ -156,27 +160,29 @@ static const struct v4l2_file_operations poseidon_fm_fops = {
156 .owner = THIS_MODULE, 160 .owner = THIS_MODULE,
157 .open = poseidon_fm_open, 161 .open = poseidon_fm_open,
158 .release = poseidon_fm_close, 162 .release = poseidon_fm_close,
159 .ioctl = video_ioctl2, 163 .poll = v4l2_ctrl_poll,
164 .unlocked_ioctl = video_ioctl2,
160}; 165};
161 166
162static int tlg_fm_vidioc_g_tuner(struct file *file, void *priv, 167static int tlg_fm_vidioc_g_tuner(struct file *file, void *priv,
163 struct v4l2_tuner *vt) 168 struct v4l2_tuner *vt)
164{ 169{
170 struct poseidon *p = video_drvdata(file);
165 struct tuner_fm_sig_stat_s fm_stat = {}; 171 struct tuner_fm_sig_stat_s fm_stat = {};
166 int ret, status, count = 5; 172 int ret, status, count = 5;
167 struct poseidon *p = file->private_data;
168 173
169 if (vt->index != 0) 174 if (vt->index != 0)
170 return -EINVAL; 175 return -EINVAL;
171 176
172 vt->type = V4L2_TUNER_RADIO; 177 vt->type = V4L2_TUNER_RADIO;
173 vt->capability = V4L2_TUNER_CAP_STEREO; 178 vt->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW;
174 vt->rangelow = TUNER_FREQ_MIN_FM / 62500; 179 vt->rangelow = TUNER_FREQ_MIN_FM * 2 / 125;
175 vt->rangehigh = TUNER_FREQ_MAX_FM / 62500; 180 vt->rangehigh = TUNER_FREQ_MAX_FM * 2 / 125;
176 vt->rxsubchans = V4L2_TUNER_SUB_STEREO; 181 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
177 vt->audmode = V4L2_TUNER_MODE_STEREO; 182 vt->audmode = V4L2_TUNER_MODE_STEREO;
178 vt->signal = 0; 183 vt->signal = 0;
179 vt->afc = 0; 184 vt->afc = 0;
185 strlcpy(vt->name, "Radio", sizeof(vt->name));
180 186
181 mutex_lock(&p->lock); 187 mutex_lock(&p->lock);
182 ret = send_get_req(p, TUNER_STATUS, TLG_MODE_FM_RADIO, 188 ret = send_get_req(p, TUNER_STATUS, TLG_MODE_FM_RADIO,
@@ -205,8 +211,10 @@ static int tlg_fm_vidioc_g_tuner(struct file *file, void *priv,
205static int fm_get_freq(struct file *file, void *priv, 211static int fm_get_freq(struct file *file, void *priv,
206 struct v4l2_frequency *argp) 212 struct v4l2_frequency *argp)
207{ 213{
208 struct poseidon *p = file->private_data; 214 struct poseidon *p = video_drvdata(file);
209 215
216 if (argp->tuner)
217 return -EINVAL;
210 argp->frequency = p->radio_data.fm_freq; 218 argp->frequency = p->radio_data.fm_freq;
211 return 0; 219 return 0;
212} 220}
@@ -221,11 +229,8 @@ static int set_frequency(struct poseidon *p, __u32 frequency)
221 ret = send_set_req(p, TUNER_AUD_ANA_STD, 229 ret = send_set_req(p, TUNER_AUD_ANA_STD,
222 p->radio_data.pre_emphasis, &status); 230 p->radio_data.pre_emphasis, &status);
223 231
224 freq = (frequency * 125) * 500 / 1000;/* kHZ */ 232 freq = (frequency * 125) / 2; /* Hz */
225 if (freq < TUNER_FREQ_MIN_FM/1000 || freq > TUNER_FREQ_MAX_FM/1000) { 233 freq = clamp(freq, TUNER_FREQ_MIN_FM, TUNER_FREQ_MAX_FM);
226 ret = -EINVAL;
227 goto error;
228 }
229 234
230 ret = send_set_req(p, TUNE_FREQ_SELECT, freq, &status); 235 ret = send_set_req(p, TUNE_FREQ_SELECT, freq, &status);
231 if (ret < 0) 236 if (ret < 0)
@@ -240,18 +245,20 @@ static int set_frequency(struct poseidon *p, __u32 frequency)
240 TLG_TUNE_PLAY_SVC_START, &status); 245 TLG_TUNE_PLAY_SVC_START, &status);
241 p->radio_data.is_radio_streaming = 1; 246 p->radio_data.is_radio_streaming = 1;
242 } 247 }
243 p->radio_data.fm_freq = frequency; 248 p->radio_data.fm_freq = freq * 2 / 125;
244error: 249error:
245 mutex_unlock(&p->lock); 250 mutex_unlock(&p->lock);
246 return ret; 251 return ret;
247} 252}
248 253
249static int fm_set_freq(struct file *file, void *priv, 254static int fm_set_freq(struct file *file, void *priv,
250 struct v4l2_frequency *argp) 255 const struct v4l2_frequency *argp)
251{ 256{
252 struct poseidon *p = file->private_data; 257 struct poseidon *p = video_drvdata(file);
253 258
254 p->file_for_stream = file; 259 if (argp->tuner)
260 return -EINVAL;
261 p->file_for_stream = file;
255#ifdef CONFIG_PM 262#ifdef CONFIG_PM
256 p->pm_suspend = pm_fm_suspend; 263 p->pm_suspend = pm_fm_suspend;
257 p->pm_resume = pm_fm_resume; 264 p->pm_resume = pm_fm_resume;
@@ -259,163 +266,75 @@ static int fm_set_freq(struct file *file, void *priv,
259 return set_frequency(p, argp->frequency); 266 return set_frequency(p, argp->frequency);
260} 267}
261 268
262static int tlg_fm_vidioc_g_ctrl(struct file *file, void *priv, 269static int tlg_fm_s_ctrl(struct v4l2_ctrl *ctrl)
263 struct v4l2_control *arg)
264{
265 return 0;
266}
267
268static int tlg_fm_vidioc_g_exts_ctrl(struct file *file, void *fh,
269 struct v4l2_ext_controls *ctrls)
270{
271 struct poseidon *p = file->private_data;
272 int i;
273
274 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_FM_TX)
275 return -EINVAL;
276
277 for (i = 0; i < ctrls->count; i++) {
278 struct v4l2_ext_control *ctrl = ctrls->controls + i;
279
280 if (ctrl->id != V4L2_CID_TUNE_PREEMPHASIS)
281 continue;
282
283 if (i < MAX_PREEMPHASIS)
284 ctrl->value = p->radio_data.pre_emphasis;
285 }
286 return 0;
287}
288
289static int tlg_fm_vidioc_s_exts_ctrl(struct file *file, void *fh,
290 struct v4l2_ext_controls *ctrls)
291{
292 int i;
293
294 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_FM_TX)
295 return -EINVAL;
296
297 for (i = 0; i < ctrls->count; i++) {
298 struct v4l2_ext_control *ctrl = ctrls->controls + i;
299
300 if (ctrl->id != V4L2_CID_TUNE_PREEMPHASIS)
301 continue;
302
303 if (ctrl->value >= 0 && ctrl->value < MAX_PREEMPHASIS) {
304 struct poseidon *p = file->private_data;
305 int pre_emphasis = preemphasis[ctrl->value];
306 u32 status;
307
308 send_set_req(p, TUNER_AUD_ANA_STD,
309 pre_emphasis, &status);
310 p->radio_data.pre_emphasis = pre_emphasis;
311 }
312 }
313 return 0;
314}
315
316static int tlg_fm_vidioc_s_ctrl(struct file *file, void *priv,
317 struct v4l2_control *ctrl)
318{ 270{
319 return 0; 271 struct poseidon *p = container_of(ctrl->handler, struct poseidon,
320} 272 radio_data.ctrl_handler);
321 273 int pre_emphasis;
322static int tlg_fm_vidioc_queryctrl(struct file *file, void *priv, 274 u32 status;
323 struct v4l2_queryctrl *ctrl)
324{
325 if (!(ctrl->id & V4L2_CTRL_FLAG_NEXT_CTRL))
326 return -EINVAL;
327 275
328 ctrl->id &= ~V4L2_CTRL_FLAG_NEXT_CTRL; 276 switch (ctrl->id) {
329 if (ctrl->id != V4L2_CID_TUNE_PREEMPHASIS) { 277 case V4L2_CID_TUNE_PREEMPHASIS:
330 /* return the next supported control */ 278 pre_emphasis = preemphasis[ctrl->val];
331 ctrl->id = V4L2_CID_TUNE_PREEMPHASIS; 279 send_set_req(p, TUNER_AUD_ANA_STD, pre_emphasis, &status);
332 v4l2_ctrl_query_fill(ctrl, V4L2_PREEMPHASIS_DISABLED, 280 p->radio_data.pre_emphasis = pre_emphasis;
333 V4L2_PREEMPHASIS_75_uS, 1,
334 V4L2_PREEMPHASIS_50_uS);
335 ctrl->flags = V4L2_CTRL_FLAG_UPDATE;
336 return 0; 281 return 0;
337 } 282 }
338 return -EINVAL; 283 return -EINVAL;
339} 284}
340 285
341static int tlg_fm_vidioc_querymenu(struct file *file, void *fh, 286static int vidioc_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *vt)
342 struct v4l2_querymenu *qmenu)
343{
344 return v4l2_ctrl_query_menu(qmenu, NULL, NULL);
345}
346
347static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
348{ 287{
349 return vt->index > 0 ? -EINVAL : 0; 288 return vt->index > 0 ? -EINVAL : 0;
350} 289}
351static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *va)
352{
353 return (va->index != 0) ? -EINVAL : 0;
354}
355
356static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
357{
358 a->index = 0;
359 a->mode = 0;
360 a->capability = V4L2_AUDCAP_STEREO;
361 strcpy(a->name, "Radio");
362 return 0;
363}
364
365static int vidioc_s_input(struct file *filp, void *priv, u32 i)
366{
367 return (i != 0) ? -EINVAL : 0;
368}
369 290
370static int vidioc_g_input(struct file *filp, void *priv, u32 *i) 291static const struct v4l2_ctrl_ops tlg_fm_ctrl_ops = {
371{ 292 .s_ctrl = tlg_fm_s_ctrl,
372 return (*i != 0) ? -EINVAL : 0; 293};
373}
374 294
375static const struct v4l2_ioctl_ops poseidon_fm_ioctl_ops = { 295static const struct v4l2_ioctl_ops poseidon_fm_ioctl_ops = {
376 .vidioc_querycap = vidioc_querycap, 296 .vidioc_querycap = vidioc_querycap,
377 .vidioc_g_audio = vidioc_g_audio,
378 .vidioc_s_audio = vidioc_s_audio,
379 .vidioc_g_input = vidioc_g_input,
380 .vidioc_s_input = vidioc_s_input,
381 .vidioc_queryctrl = tlg_fm_vidioc_queryctrl,
382 .vidioc_querymenu = tlg_fm_vidioc_querymenu,
383 .vidioc_g_ctrl = tlg_fm_vidioc_g_ctrl,
384 .vidioc_s_ctrl = tlg_fm_vidioc_s_ctrl,
385 .vidioc_s_ext_ctrls = tlg_fm_vidioc_s_exts_ctrl,
386 .vidioc_g_ext_ctrls = tlg_fm_vidioc_g_exts_ctrl,
387 .vidioc_s_tuner = vidioc_s_tuner, 297 .vidioc_s_tuner = vidioc_s_tuner,
388 .vidioc_g_tuner = tlg_fm_vidioc_g_tuner, 298 .vidioc_g_tuner = tlg_fm_vidioc_g_tuner,
389 .vidioc_g_frequency = fm_get_freq, 299 .vidioc_g_frequency = fm_get_freq,
390 .vidioc_s_frequency = fm_set_freq, 300 .vidioc_s_frequency = fm_set_freq,
301 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
302 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
391}; 303};
392 304
393static struct video_device poseidon_fm_template = { 305static struct video_device poseidon_fm_template = {
394 .name = "Telegent-Radio", 306 .name = "Telegent-Radio",
395 .fops = &poseidon_fm_fops, 307 .fops = &poseidon_fm_fops,
396 .minor = -1, 308 .minor = -1,
397 .release = video_device_release, 309 .release = video_device_release_empty,
398 .ioctl_ops = &poseidon_fm_ioctl_ops, 310 .ioctl_ops = &poseidon_fm_ioctl_ops,
399}; 311};
400 312
401int poseidon_fm_init(struct poseidon *p) 313int poseidon_fm_init(struct poseidon *p)
402{ 314{
403 struct video_device *fm_dev; 315 struct video_device *vfd = &p->radio_data.fm_dev;
404 316 struct v4l2_ctrl_handler *hdl = &p->radio_data.ctrl_handler;
405 fm_dev = vdev_init(p, &poseidon_fm_template); 317
406 if (fm_dev == NULL) 318 *vfd = poseidon_fm_template;
407 return -1; 319
408 320 set_frequency(p, TUNER_FREQ_MIN_FM);
409 if (video_register_device(fm_dev, VFL_TYPE_RADIO, -1) < 0) { 321 v4l2_ctrl_handler_init(hdl, 1);
410 video_device_release(fm_dev); 322 v4l2_ctrl_new_std_menu(hdl, &tlg_fm_ctrl_ops, V4L2_CID_TUNE_PREEMPHASIS,
411 return -1; 323 V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
324 if (hdl->error) {
325 v4l2_ctrl_handler_free(hdl);
326 return hdl->error;
412 } 327 }
413 p->radio_data.fm_dev = fm_dev; 328 vfd->v4l2_dev = &p->v4l2_dev;
414 return 0; 329 vfd->ctrl_handler = hdl;
330 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
331 video_set_drvdata(vfd, p);
332 return video_register_device(vfd, VFL_TYPE_RADIO, -1);
415} 333}
416 334
417int poseidon_fm_exit(struct poseidon *p) 335int poseidon_fm_exit(struct poseidon *p)
418{ 336{
419 destroy_video_device(&p->radio_data.fm_dev); 337 video_unregister_device(&p->radio_data.fm_dev);
338 v4l2_ctrl_handler_free(&p->radio_data.ctrl_handler);
420 return 0; 339 return 0;
421} 340}
diff --git a/drivers/media/usb/tlg2300/pd-video.c b/drivers/media/usb/tlg2300/pd-video.c
index 21723378bb8f..8df668d06552 100644
--- a/drivers/media/usb/tlg2300/pd-video.c
+++ b/drivers/media/usb/tlg2300/pd-video.c
@@ -8,6 +8,7 @@
8 8
9#include <media/v4l2-ioctl.h> 9#include <media/v4l2-ioctl.h>
10#include <media/v4l2-dev.h> 10#include <media/v4l2-dev.h>
11#include <media/v4l2-ctrls.h>
11 12
12#include "pd-common.h" 13#include "pd-common.h"
13#include "vendorcmds.h" 14#include "vendorcmds.h"
@@ -82,31 +83,6 @@ static const struct pd_input pd_inputs[] = {
82}; 83};
83static const unsigned int POSEIDON_INPUTS = ARRAY_SIZE(pd_inputs); 84static const unsigned int POSEIDON_INPUTS = ARRAY_SIZE(pd_inputs);
84 85
85struct poseidon_control {
86 struct v4l2_queryctrl v4l2_ctrl;
87 enum cmd_custom_param_id vc_id;
88};
89
90static struct poseidon_control controls[] = {
91 {
92 { V4L2_CID_BRIGHTNESS, V4L2_CTRL_TYPE_INTEGER,
93 "brightness", 0, 10000, 1, 100, 0, },
94 CUST_PARM_ID_BRIGHTNESS_CTRL
95 }, {
96 { V4L2_CID_CONTRAST, V4L2_CTRL_TYPE_INTEGER,
97 "contrast", 0, 10000, 1, 100, 0, },
98 CUST_PARM_ID_CONTRAST_CTRL,
99 }, {
100 { V4L2_CID_HUE, V4L2_CTRL_TYPE_INTEGER,
101 "hue", 0, 10000, 1, 100, 0, },
102 CUST_PARM_ID_HUE_CTRL,
103 }, {
104 { V4L2_CID_SATURATION, V4L2_CTRL_TYPE_INTEGER,
105 "saturation", 0, 10000, 1, 100, 0, },
106 CUST_PARM_ID_SATURATION_CTRL,
107 },
108};
109
110struct video_std_to_audio_std { 86struct video_std_to_audio_std {
111 v4l2_std_id video_std; 87 v4l2_std_id video_std;
112 int audio_std; 88 int audio_std;
@@ -142,17 +118,20 @@ static int get_audio_std(v4l2_std_id v4l2_std)
142static int vidioc_querycap(struct file *file, void *fh, 118static int vidioc_querycap(struct file *file, void *fh,
143 struct v4l2_capability *cap) 119 struct v4l2_capability *cap)
144{ 120{
145 struct front_face *front = fh; 121 struct video_device *vdev = video_devdata(file);
146 struct poseidon *p = front->pd; 122 struct poseidon *p = video_get_drvdata(vdev);
147
148 logs(front);
149 123
150 strcpy(cap->driver, "tele-video"); 124 strcpy(cap->driver, "tele-video");
151 strcpy(cap->card, "Telegent Poseidon"); 125 strcpy(cap->card, "Telegent Poseidon");
152 usb_make_path(p->udev, cap->bus_info, sizeof(cap->bus_info)); 126 usb_make_path(p->udev, cap->bus_info, sizeof(cap->bus_info));
153 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | 127 cap->device_caps = V4L2_CAP_TUNER | V4L2_CAP_AUDIO |
154 V4L2_CAP_AUDIO | V4L2_CAP_STREAMING | 128 V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
155 V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE; 129 if (vdev->vfl_type == VFL_TYPE_VBI)
130 cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
131 else
132 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
133 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
134 V4L2_CAP_RADIO | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE;
156 return 0; 135 return 0;
157} 136}
158 137
@@ -223,7 +202,6 @@ static void submit_frame(struct front_face *front)
223 */ 202 */
224static void end_field(struct video_data *video) 203static void end_field(struct video_data *video)
225{ 204{
226 /* logs(video->front); */
227 if (1 == video->field_count) 205 if (1 == video->field_count)
228 submit_frame(video->front); 206 submit_frame(video->front);
229 else 207 else
@@ -718,17 +696,10 @@ static int vidioc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
718 struct front_face *front = fh; 696 struct front_face *front = fh;
719 struct poseidon *pd = front->pd; 697 struct poseidon *pd = front->pd;
720 698
721 logs(front);
722 f->fmt.pix = pd->video_data.context.pix; 699 f->fmt.pix = pd->video_data.context.pix;
723 return 0; 700 return 0;
724} 701}
725 702
726static int vidioc_try_fmt(struct file *file, void *fh,
727 struct v4l2_format *f)
728{
729 return 0;
730}
731
732/* 703/*
733 * VLC calls VIDIOC_S_STD before VIDIOC_S_FMT, while 704 * VLC calls VIDIOC_S_STD before VIDIOC_S_FMT, while
734 * Mplayer calls them in the reverse order. 705 * Mplayer calls them in the reverse order.
@@ -787,7 +758,6 @@ static int vidioc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
787 struct front_face *front = fh; 758 struct front_face *front = fh;
788 struct poseidon *pd = front->pd; 759 struct poseidon *pd = front->pd;
789 760
790 logs(front);
791 /* stop VBI here */ 761 /* stop VBI here */
792 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type) 762 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
793 return -EINVAL; 763 return -EINVAL;
@@ -828,11 +798,10 @@ static int vidioc_g_fmt_vbi(struct file *file, void *fh,
828 vbi_fmt->count[1] = V4L_PAL_VBI_LINES; 798 vbi_fmt->count[1] = V4L_PAL_VBI_LINES;
829 } 799 }
830 vbi_fmt->flags = V4L2_VBI_UNSYNC; 800 vbi_fmt->flags = V4L2_VBI_UNSYNC;
831 logs(front);
832 return 0; 801 return 0;
833} 802}
834 803
835static int set_std(struct poseidon *pd, v4l2_std_id *norm) 804static int set_std(struct poseidon *pd, v4l2_std_id norm)
836{ 805{
837 struct video_data *video = &pd->video_data; 806 struct video_data *video = &pd->video_data;
838 struct vbi_data *vbi = &pd->vbi_data; 807 struct vbi_data *vbi = &pd->vbi_data;
@@ -842,7 +811,7 @@ static int set_std(struct poseidon *pd, v4l2_std_id *norm)
842 int height; 811 int height;
843 812
844 for (i = 0; i < POSEIDON_TVNORMS; i++) { 813 for (i = 0; i < POSEIDON_TVNORMS; i++) {
845 if (*norm & poseidon_tvnorms[i].v4l2_id) { 814 if (norm & poseidon_tvnorms[i].v4l2_id) {
846 param = poseidon_tvnorms[i].tlg_tvnorm; 815 param = poseidon_tvnorms[i].tlg_tvnorm;
847 log("name : %s", poseidon_tvnorms[i].name); 816 log("name : %s", poseidon_tvnorms[i].name);
848 goto found; 817 goto found;
@@ -877,17 +846,23 @@ out:
877 return ret; 846 return ret;
878} 847}
879 848
880static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *norm) 849static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id norm)
881{ 850{
882 struct front_face *front = fh; 851 struct front_face *front = fh;
883 logs(front); 852
884 return set_std(front->pd, norm); 853 return set_std(front->pd, norm);
885} 854}
886 855
887static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *in) 856static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
888{ 857{
889 struct front_face *front = fh; 858 struct front_face *front = fh;
890 859
860 *norm = front->pd->video_data.context.tvnormid;
861 return 0;
862}
863
864static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *in)
865{
891 if (in->index >= POSEIDON_INPUTS) 866 if (in->index >= POSEIDON_INPUTS)
892 return -EINVAL; 867 return -EINVAL;
893 strcpy(in->name, pd_inputs[in->index].name); 868 strcpy(in->name, pd_inputs[in->index].name);
@@ -897,11 +872,10 @@ static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *in)
897 * the audio input index mixed with this video input, 872 * the audio input index mixed with this video input,
898 * Poseidon only have one audio/video, set to "0" 873 * Poseidon only have one audio/video, set to "0"
899 */ 874 */
900 in->audioset = 0; 875 in->audioset = 1;
901 in->tuner = 0; 876 in->tuner = 0;
902 in->std = V4L2_STD_ALL; 877 in->std = V4L2_STD_ALL;
903 in->status = 0; 878 in->status = 0;
904 logs(front);
905 return 0; 879 return 0;
906} 880}
907 881
@@ -911,7 +885,6 @@ static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
911 struct poseidon *pd = front->pd; 885 struct poseidon *pd = front->pd;
912 struct running_context *context = &pd->video_data.context; 886 struct running_context *context = &pd->video_data.context;
913 887
914 logs(front);
915 *i = context->sig_index; 888 *i = context->sig_index;
916 return 0; 889 return 0;
917} 890}
@@ -934,68 +907,28 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
934 return 0; 907 return 0;
935} 908}
936 909
937static struct poseidon_control *check_control_id(__u32 id) 910static int tlg_s_ctrl(struct v4l2_ctrl *c)
938{
939 struct poseidon_control *control = &controls[0];
940 int array_size = ARRAY_SIZE(controls);
941
942 for (; control < &controls[array_size]; control++)
943 if (control->v4l2_ctrl.id == id)
944 return control;
945 return NULL;
946}
947
948static int vidioc_queryctrl(struct file *file, void *fh,
949 struct v4l2_queryctrl *a)
950{
951 struct poseidon_control *control = NULL;
952
953 control = check_control_id(a->id);
954 if (!control)
955 return -EINVAL;
956
957 *a = control->v4l2_ctrl;
958 return 0;
959}
960
961static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *ctrl)
962{
963 struct front_face *front = fh;
964 struct poseidon *pd = front->pd;
965 struct poseidon_control *control = NULL;
966 struct tuner_custom_parameter_s tuner_param;
967 s32 ret = 0, cmd_status;
968
969 control = check_control_id(ctrl->id);
970 if (!control)
971 return -EINVAL;
972
973 mutex_lock(&pd->lock);
974 ret = send_get_req(pd, TUNER_CUSTOM_PARAMETER, control->vc_id,
975 &tuner_param, &cmd_status, sizeof(tuner_param));
976 mutex_unlock(&pd->lock);
977
978 if (ret || cmd_status)
979 return -1;
980
981 ctrl->value = tuner_param.param_value;
982 return 0;
983}
984
985static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a)
986{ 911{
912 struct poseidon *pd = container_of(c->handler, struct poseidon,
913 video_data.ctrl_handler);
987 struct tuner_custom_parameter_s param = {0}; 914 struct tuner_custom_parameter_s param = {0};
988 struct poseidon_control *control = NULL;
989 struct front_face *front = fh;
990 struct poseidon *pd = front->pd;
991 s32 ret = 0, cmd_status, params; 915 s32 ret = 0, cmd_status, params;
992 916
993 control = check_control_id(a->id); 917 switch (c->id) {
994 if (!control) 918 case V4L2_CID_BRIGHTNESS:
995 return -EINVAL; 919 param.param_id = CUST_PARM_ID_BRIGHTNESS_CTRL;
996 920 break;
997 param.param_value = a->value; 921 case V4L2_CID_CONTRAST:
998 param.param_id = control->vc_id; 922 param.param_id = CUST_PARM_ID_CONTRAST_CTRL;
923 break;
924 case V4L2_CID_HUE:
925 param.param_id = CUST_PARM_ID_HUE_CTRL;
926 break;
927 case V4L2_CID_SATURATION:
928 param.param_id = CUST_PARM_ID_SATURATION_CTRL;
929 break;
930 }
931 param.param_value = c->val;
999 params = *(s32 *)&param; /* temp code */ 932 params = *(s32 *)&param; /* temp code */
1000 933
1001 mutex_lock(&pd->lock); 934 mutex_lock(&pd->lock);
@@ -1079,7 +1012,6 @@ static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *tuner)
1079 tuner->rxsubchans = pd_audio_modes[index].v4l2_audio_sub; 1012 tuner->rxsubchans = pd_audio_modes[index].v4l2_audio_sub;
1080 tuner->audmode = pd_audio_modes[index].v4l2_audio_mode; 1013 tuner->audmode = pd_audio_modes[index].v4l2_audio_mode;
1081 tuner->afc = 0; 1014 tuner->afc = 0;
1082 logs(front);
1083 return 0; 1015 return 0;
1084} 1016}
1085 1017
@@ -1099,7 +1031,7 @@ static int pd_vidioc_s_tuner(struct poseidon *pd, int index)
1099 return ret; 1031 return ret;
1100} 1032}
1101 1033
1102static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *a) 1034static int vidioc_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *a)
1103{ 1035{
1104 struct front_face *front = fh; 1036 struct front_face *front = fh;
1105 struct poseidon *pd = front->pd; 1037 struct poseidon *pd = front->pd;
@@ -1107,7 +1039,6 @@ static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *a)
1107 1039
1108 if (0 != a->index) 1040 if (0 != a->index)
1109 return -EINVAL; 1041 return -EINVAL;
1110 logs(front);
1111 for (index = 0; index < POSEIDON_AUDIOMODS; index++) 1042 for (index = 0; index < POSEIDON_AUDIOMODS; index++)
1112 if (a->audmode == pd_audio_modes[index].v4l2_audio_mode) 1043 if (a->audmode == pd_audio_modes[index].v4l2_audio_mode)
1113 return pd_vidioc_s_tuner(pd, index); 1044 return pd_vidioc_s_tuner(pd, index);
@@ -1128,51 +1059,51 @@ static int vidioc_g_frequency(struct file *file, void *fh,
1128 return 0; 1059 return 0;
1129} 1060}
1130 1061
1131static int set_frequency(struct poseidon *pd, __u32 frequency) 1062static int set_frequency(struct poseidon *pd, u32 *frequency)
1132{ 1063{
1133 s32 ret = 0, param, cmd_status; 1064 s32 ret = 0, param, cmd_status;
1134 struct running_context *context = &pd->video_data.context; 1065 struct running_context *context = &pd->video_data.context;
1135 1066
1136 param = frequency * 62500 / 1000; 1067 *frequency = clamp(*frequency,
1137 if (param < TUNER_FREQ_MIN/1000 || param > TUNER_FREQ_MAX / 1000) 1068 TUNER_FREQ_MIN / 62500, TUNER_FREQ_MAX / 62500);
1138 return -EINVAL; 1069 param = (*frequency) * 62500 / 1000;
1139 1070
1140 mutex_lock(&pd->lock); 1071 mutex_lock(&pd->lock);
1141 ret = send_set_req(pd, TUNE_FREQ_SELECT, param, &cmd_status); 1072 ret = send_set_req(pd, TUNE_FREQ_SELECT, param, &cmd_status);
1142 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status); 1073 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
1143 1074
1144 msleep(250); /* wait for a while until the hardware is ready. */ 1075 msleep(250); /* wait for a while until the hardware is ready. */
1145 context->freq = frequency; 1076 context->freq = *frequency;
1146 mutex_unlock(&pd->lock); 1077 mutex_unlock(&pd->lock);
1147 return ret; 1078 return ret;
1148} 1079}
1149 1080
1150static int vidioc_s_frequency(struct file *file, void *fh, 1081static int vidioc_s_frequency(struct file *file, void *fh,
1151 struct v4l2_frequency *freq) 1082 const struct v4l2_frequency *freq)
1152{ 1083{
1153 struct front_face *front = fh; 1084 struct front_face *front = fh;
1154 struct poseidon *pd = front->pd; 1085 struct poseidon *pd = front->pd;
1086 u32 frequency = freq->frequency;
1155 1087
1156 logs(front); 1088 if (freq->tuner)
1089 return -EINVAL;
1157#ifdef CONFIG_PM 1090#ifdef CONFIG_PM
1158 pd->pm_suspend = pm_video_suspend; 1091 pd->pm_suspend = pm_video_suspend;
1159 pd->pm_resume = pm_video_resume; 1092 pd->pm_resume = pm_video_resume;
1160#endif 1093#endif
1161 return set_frequency(pd, freq->frequency); 1094 return set_frequency(pd, &frequency);
1162} 1095}
1163 1096
1164static int vidioc_reqbufs(struct file *file, void *fh, 1097static int vidioc_reqbufs(struct file *file, void *fh,
1165 struct v4l2_requestbuffers *b) 1098 struct v4l2_requestbuffers *b)
1166{ 1099{
1167 struct front_face *front = file->private_data; 1100 struct front_face *front = file->private_data;
1168 logs(front);
1169 return videobuf_reqbufs(&front->q, b); 1101 return videobuf_reqbufs(&front->q, b);
1170} 1102}
1171 1103
1172static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *b) 1104static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
1173{ 1105{
1174 struct front_face *front = file->private_data; 1106 struct front_face *front = file->private_data;
1175 logs(front);
1176 return videobuf_querybuf(&front->q, b); 1107 return videobuf_querybuf(&front->q, b);
1177} 1108}
1178 1109
@@ -1261,7 +1192,6 @@ static int vidioc_streamon(struct file *file, void *fh,
1261{ 1192{
1262 struct front_face *front = fh; 1193 struct front_face *front = fh;
1263 1194
1264 logs(front);
1265 if (unlikely(type != front->type)) 1195 if (unlikely(type != front->type))
1266 return -EINVAL; 1196 return -EINVAL;
1267 return videobuf_streamon(&front->q); 1197 return videobuf_streamon(&front->q);
@@ -1272,7 +1202,6 @@ static int vidioc_streamoff(struct file *file, void *fh,
1272{ 1202{
1273 struct front_face *front = file->private_data; 1203 struct front_face *front = file->private_data;
1274 1204
1275 logs(front);
1276 if (unlikely(type != front->type)) 1205 if (unlikely(type != front->type))
1277 return -EINVAL; 1206 return -EINVAL;
1278 return videobuf_streamoff(&front->q); 1207 return videobuf_streamoff(&front->q);
@@ -1341,11 +1270,11 @@ static int restore_v4l2_context(struct poseidon *pd,
1341 1270
1342 pd_video_checkmode(pd); 1271 pd_video_checkmode(pd);
1343 1272
1344 set_std(pd, &context->tvnormid); 1273 set_std(pd, context->tvnormid);
1345 vidioc_s_input(NULL, front, context->sig_index); 1274 vidioc_s_input(NULL, front, context->sig_index);
1346 pd_vidioc_s_tuner(pd, context->audio_idx); 1275 pd_vidioc_s_tuner(pd, context->audio_idx);
1347 pd_vidioc_s_fmt(pd, &context->pix); 1276 pd_vidioc_s_fmt(pd, &context->pix);
1348 set_frequency(pd, context->freq); 1277 set_frequency(pd, &context->freq);
1349 return 0; 1278 return 0;
1350} 1279}
1351 1280
@@ -1406,12 +1335,14 @@ static int pd_video_open(struct file *file)
1406 mutex_lock(&pd->lock); 1335 mutex_lock(&pd->lock);
1407 usb_autopm_get_interface(pd->interface); 1336 usb_autopm_get_interface(pd->interface);
1408 1337
1409 if (vfd->vfl_type == VFL_TYPE_GRABBER 1338 if (pd->state && !(pd->state & POSEIDON_STATE_ANALOG)) {
1410 && !(pd->state & POSEIDON_STATE_ANALOG)) { 1339 ret = -EBUSY;
1411 front = kzalloc(sizeof(struct front_face), GFP_KERNEL); 1340 goto out;
1412 if (!front) 1341 }
1413 goto out; 1342 front = kzalloc(sizeof(struct front_face), GFP_KERNEL);
1414 1343 if (!front)
1344 goto out;
1345 if (vfd->vfl_type == VFL_TYPE_GRABBER) {
1415 pd->cur_transfer_mode = usb_transfer_mode;/* bulk or iso */ 1346 pd->cur_transfer_mode = usb_transfer_mode;/* bulk or iso */
1416 init_video_context(&pd->video_data.context); 1347 init_video_context(&pd->video_data.context);
1417 1348
@@ -1422,7 +1353,6 @@ static int pd_video_open(struct file *file)
1422 goto out; 1353 goto out;
1423 } 1354 }
1424 1355
1425 pd->state |= POSEIDON_STATE_ANALOG;
1426 front->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1356 front->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1427 pd->video_data.users++; 1357 pd->video_data.users++;
1428 set_debug_mode(vfd, debug_mode); 1358 set_debug_mode(vfd, debug_mode);
@@ -1433,13 +1363,7 @@ static int pd_video_open(struct file *file)
1433 V4L2_FIELD_INTERLACED,/* video is interlacd */ 1363 V4L2_FIELD_INTERLACED,/* video is interlacd */
1434 sizeof(struct videobuf_buffer),/*it's enough*/ 1364 sizeof(struct videobuf_buffer),/*it's enough*/
1435 front, NULL); 1365 front, NULL);
1436 } else if (vfd->vfl_type == VFL_TYPE_VBI 1366 } else {
1437 && !(pd->state & POSEIDON_STATE_VBI)) {
1438 front = kzalloc(sizeof(struct front_face), GFP_KERNEL);
1439 if (!front)
1440 goto out;
1441
1442 pd->state |= POSEIDON_STATE_VBI;
1443 front->type = V4L2_BUF_TYPE_VBI_CAPTURE; 1367 front->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1444 pd->vbi_data.front = front; 1368 pd->vbi_data.front = front;
1445 pd->vbi_data.users++; 1369 pd->vbi_data.users++;
@@ -1450,19 +1374,15 @@ static int pd_video_open(struct file *file)
1450 V4L2_FIELD_NONE, /* vbi is NONE mode */ 1374 V4L2_FIELD_NONE, /* vbi is NONE mode */
1451 sizeof(struct videobuf_buffer), 1375 sizeof(struct videobuf_buffer),
1452 front, NULL); 1376 front, NULL);
1453 } else {
1454 /* maybe add FM support here */
1455 log("other ");
1456 ret = -EINVAL;
1457 goto out;
1458 } 1377 }
1459 1378
1460 front->pd = pd; 1379 pd->state |= POSEIDON_STATE_ANALOG;
1461 front->curr_frame = NULL; 1380 front->pd = pd;
1381 front->curr_frame = NULL;
1462 INIT_LIST_HEAD(&front->active); 1382 INIT_LIST_HEAD(&front->active);
1463 spin_lock_init(&front->queue_lock); 1383 spin_lock_init(&front->queue_lock);
1464 1384
1465 file->private_data = front; 1385 file->private_data = front;
1466 kref_get(&pd->kref); 1386 kref_get(&pd->kref);
1467 1387
1468 mutex_unlock(&pd->lock); 1388 mutex_unlock(&pd->lock);
@@ -1479,12 +1399,9 @@ static int pd_video_release(struct file *file)
1479 struct poseidon *pd = front->pd; 1399 struct poseidon *pd = front->pd;
1480 s32 cmd_status = 0; 1400 s32 cmd_status = 0;
1481 1401
1482 logs(front);
1483 mutex_lock(&pd->lock); 1402 mutex_lock(&pd->lock);
1484 1403
1485 if (front->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1404 if (front->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1486 pd->state &= ~POSEIDON_STATE_ANALOG;
1487
1488 /* stop the device, and free the URBs */ 1405 /* stop the device, and free the URBs */
1489 usb_transfer_stop(&pd->video_data); 1406 usb_transfer_stop(&pd->video_data);
1490 free_all_urb(&pd->video_data); 1407 free_all_urb(&pd->video_data);
@@ -1496,10 +1413,11 @@ static int pd_video_release(struct file *file)
1496 pd->file_for_stream = NULL; 1413 pd->file_for_stream = NULL;
1497 pd->video_data.users--; 1414 pd->video_data.users--;
1498 } else if (front->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 1415 } else if (front->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1499 pd->state &= ~POSEIDON_STATE_VBI;
1500 pd->vbi_data.front = NULL; 1416 pd->vbi_data.front = NULL;
1501 pd->vbi_data.users--; 1417 pd->vbi_data.users--;
1502 } 1418 }
1419 if (!pd->vbi_data.users && !pd->video_data.users)
1420 pd->state &= ~POSEIDON_STATE_ANALOG;
1503 videobuf_stop(&front->q); 1421 videobuf_stop(&front->q);
1504 videobuf_mmap_free(&front->q); 1422 videobuf_mmap_free(&front->q);
1505 1423
@@ -1551,7 +1469,6 @@ static const struct v4l2_ioctl_ops pd_video_ioctl_ops = {
1551 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt, 1469 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt,
1552 .vidioc_s_fmt_vid_cap = vidioc_s_fmt, 1470 .vidioc_s_fmt_vid_cap = vidioc_s_fmt,
1553 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi, /* VBI */ 1471 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi, /* VBI */
1554 .vidioc_try_fmt_vid_cap = vidioc_try_fmt,
1555 1472
1556 /* Input */ 1473 /* Input */
1557 .vidioc_g_input = vidioc_g_input, 1474 .vidioc_g_input = vidioc_g_input,
@@ -1566,6 +1483,7 @@ static const struct v4l2_ioctl_ops pd_video_ioctl_ops = {
1566 /* Tuner ioctls */ 1483 /* Tuner ioctls */
1567 .vidioc_g_tuner = vidioc_g_tuner, 1484 .vidioc_g_tuner = vidioc_g_tuner,
1568 .vidioc_s_tuner = vidioc_s_tuner, 1485 .vidioc_s_tuner = vidioc_s_tuner,
1486 .vidioc_g_std = vidioc_g_std,
1569 .vidioc_s_std = vidioc_s_std, 1487 .vidioc_s_std = vidioc_s_std,
1570 .vidioc_g_frequency = vidioc_g_frequency, 1488 .vidioc_g_frequency = vidioc_g_frequency,
1571 .vidioc_s_frequency = vidioc_s_frequency, 1489 .vidioc_s_frequency = vidioc_s_frequency,
@@ -1579,59 +1497,29 @@ static const struct v4l2_ioctl_ops pd_video_ioctl_ops = {
1579 /* Stream on/off */ 1497 /* Stream on/off */
1580 .vidioc_streamon = vidioc_streamon, 1498 .vidioc_streamon = vidioc_streamon,
1581 .vidioc_streamoff = vidioc_streamoff, 1499 .vidioc_streamoff = vidioc_streamoff,
1582
1583 /* Control handling */
1584 .vidioc_queryctrl = vidioc_queryctrl,
1585 .vidioc_g_ctrl = vidioc_g_ctrl,
1586 .vidioc_s_ctrl = vidioc_s_ctrl,
1587}; 1500};
1588 1501
1589static struct video_device pd_video_template = { 1502static struct video_device pd_video_template = {
1590 .name = "Telegent-Video", 1503 .name = "Telegent-Video",
1591 .fops = &pd_video_fops, 1504 .fops = &pd_video_fops,
1592 .minor = -1, 1505 .minor = -1,
1593 .release = video_device_release, 1506 .release = video_device_release_empty,
1594 .tvnorms = V4L2_STD_ALL, 1507 .tvnorms = V4L2_STD_ALL,
1595 .ioctl_ops = &pd_video_ioctl_ops, 1508 .ioctl_ops = &pd_video_ioctl_ops,
1596}; 1509};
1597 1510
1598struct video_device *vdev_init(struct poseidon *pd, struct video_device *tmp) 1511static const struct v4l2_ctrl_ops tlg_ctrl_ops = {
1599{ 1512 .s_ctrl = tlg_s_ctrl,
1600 struct video_device *vfd; 1513};
1601
1602 vfd = video_device_alloc();
1603 if (vfd == NULL)
1604 return NULL;
1605 *vfd = *tmp;
1606 vfd->minor = -1;
1607 vfd->v4l2_dev = &pd->v4l2_dev;
1608 /*vfd->parent = &(pd->udev->dev); */
1609 vfd->release = video_device_release;
1610 video_set_drvdata(vfd, pd);
1611 return vfd;
1612}
1613
1614void destroy_video_device(struct video_device **v_dev)
1615{
1616 struct video_device *dev = *v_dev;
1617
1618 if (dev == NULL)
1619 return;
1620
1621 if (video_is_registered(dev))
1622 video_unregister_device(dev);
1623 else
1624 video_device_release(dev);
1625 *v_dev = NULL;
1626}
1627 1514
1628void pd_video_exit(struct poseidon *pd) 1515void pd_video_exit(struct poseidon *pd)
1629{ 1516{
1630 struct video_data *video = &pd->video_data; 1517 struct video_data *video = &pd->video_data;
1631 struct vbi_data *vbi = &pd->vbi_data; 1518 struct vbi_data *vbi = &pd->vbi_data;
1632 1519
1633 destroy_video_device(&video->v_dev); 1520 video_unregister_device(&video->v_dev);
1634 destroy_video_device(&vbi->v_dev); 1521 video_unregister_device(&vbi->v_dev);
1522 v4l2_ctrl_handler_free(&video->ctrl_handler);
1635 log(); 1523 log();
1636} 1524}
1637 1525
@@ -1639,23 +1527,39 @@ int pd_video_init(struct poseidon *pd)
1639{ 1527{
1640 struct video_data *video = &pd->video_data; 1528 struct video_data *video = &pd->video_data;
1641 struct vbi_data *vbi = &pd->vbi_data; 1529 struct vbi_data *vbi = &pd->vbi_data;
1530 struct v4l2_ctrl_handler *hdl = &video->ctrl_handler;
1531 u32 freq = TUNER_FREQ_MIN / 62500;
1642 int ret = -ENOMEM; 1532 int ret = -ENOMEM;
1643 1533
1644 video->v_dev = vdev_init(pd, &pd_video_template); 1534 v4l2_ctrl_handler_init(hdl, 4);
1645 if (video->v_dev == NULL) 1535 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_BRIGHTNESS,
1646 goto out; 1536 0, 10000, 1, 100);
1537 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_CONTRAST,
1538 0, 10000, 1, 100);
1539 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_HUE,
1540 0, 10000, 1, 100);
1541 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_SATURATION,
1542 0, 10000, 1, 100);
1543 if (hdl->error) {
1544 v4l2_ctrl_handler_free(hdl);
1545 return hdl->error;
1546 }
1547 set_frequency(pd, &freq);
1548 video->v_dev = pd_video_template;
1549 video->v_dev.v4l2_dev = &pd->v4l2_dev;
1550 video->v_dev.ctrl_handler = hdl;
1551 video_set_drvdata(&video->v_dev, pd);
1647 1552
1648 ret = video_register_device(video->v_dev, VFL_TYPE_GRABBER, -1); 1553 ret = video_register_device(&video->v_dev, VFL_TYPE_GRABBER, -1);
1649 if (ret != 0) 1554 if (ret != 0)
1650 goto out; 1555 goto out;
1651 1556
1652 /* VBI uses the same template as video */ 1557 /* VBI uses the same template as video */
1653 vbi->v_dev = vdev_init(pd, &pd_video_template); 1558 vbi->v_dev = pd_video_template;
1654 if (vbi->v_dev == NULL) { 1559 vbi->v_dev.v4l2_dev = &pd->v4l2_dev;
1655 ret = -ENOMEM; 1560 vbi->v_dev.ctrl_handler = hdl;
1656 goto out; 1561 video_set_drvdata(&vbi->v_dev, pd);
1657 } 1562 ret = video_register_device(&vbi->v_dev, VFL_TYPE_VBI, -1);
1658 ret = video_register_device(vbi->v_dev, VFL_TYPE_VBI, -1);
1659 if (ret != 0) 1563 if (ret != 0)
1660 goto out; 1564 goto out;
1661 log("register VIDEO/VBI devices"); 1565 log("register VIDEO/VBI devices");
@@ -1665,4 +1569,3 @@ out:
1665 pd_video_exit(pd); 1569 pd_video_exit(pd);
1666 return ret; 1570 return ret;
1667} 1571}
1668
diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c
index 1a6857929c15..a78de1d1bc9e 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -1056,13 +1056,13 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1056 return 0; 1056 return 0;
1057} 1057}
1058 1058
1059static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) 1059static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1060{ 1060{
1061 int rc = 0; 1061 int rc = 0;
1062 struct tm6000_fh *fh = priv; 1062 struct tm6000_fh *fh = priv;
1063 struct tm6000_core *dev = fh->dev; 1063 struct tm6000_core *dev = fh->dev;
1064 1064
1065 dev->norm = *norm; 1065 dev->norm = norm;
1066 rc = tm6000_init_analog_mode(dev); 1066 rc = tm6000_init_analog_mode(dev);
1067 1067
1068 fh->width = dev->width; 1068 fh->width = dev->width;
@@ -1134,7 +1134,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1134 1134
1135 dev->input = i; 1135 dev->input = i;
1136 1136
1137 rc = vidioc_s_std(file, priv, &dev->vfd->current_norm); 1137 rc = vidioc_s_std(file, priv, dev->vfd->current_norm);
1138 1138
1139 return rc; 1139 return rc;
1140} 1140}
@@ -1215,7 +1215,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1215} 1215}
1216 1216
1217static int vidioc_s_tuner(struct file *file, void *priv, 1217static int vidioc_s_tuner(struct file *file, void *priv,
1218 struct v4l2_tuner *t) 1218 const struct v4l2_tuner *t)
1219{ 1219{
1220 struct tm6000_fh *fh = priv; 1220 struct tm6000_fh *fh = priv;
1221 struct tm6000_core *dev = fh->dev; 1221 struct tm6000_core *dev = fh->dev;
@@ -1255,7 +1255,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1255} 1255}
1256 1256
1257static int vidioc_s_frequency(struct file *file, void *priv, 1257static int vidioc_s_frequency(struct file *file, void *priv,
1258 struct v4l2_frequency *f) 1258 const struct v4l2_frequency *f)
1259{ 1259{
1260 struct tm6000_fh *fh = priv; 1260 struct tm6000_fh *fh = priv;
1261 struct tm6000_core *dev = fh->dev; 1261 struct tm6000_core *dev = fh->dev;
@@ -1293,18 +1293,14 @@ static int radio_g_tuner(struct file *file, void *priv,
1293} 1293}
1294 1294
1295static int radio_s_tuner(struct file *file, void *priv, 1295static int radio_s_tuner(struct file *file, void *priv,
1296 struct v4l2_tuner *t) 1296 const struct v4l2_tuner *t)
1297{ 1297{
1298 struct tm6000_fh *fh = file->private_data; 1298 struct tm6000_fh *fh = file->private_data;
1299 struct tm6000_core *dev = fh->dev; 1299 struct tm6000_core *dev = fh->dev;
1300 1300
1301 if (0 != t->index) 1301 if (0 != t->index)
1302 return -EINVAL; 1302 return -EINVAL;
1303 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1304 t->audmode = V4L2_TUNER_MODE_STEREO;
1305
1306 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); 1303 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1307
1308 return 0; 1304 return 0;
1309} 1305}
1310 1306
diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
index e40718552850..21b9049c7b3f 100644
--- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
@@ -930,11 +930,11 @@ static int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
930 930
931 if (dvbdmxfeed->type == DMX_TYPE_TS) { 931 if (dvbdmxfeed->type == DMX_TYPE_TS) {
932 switch (dvbdmxfeed->pes_type) { 932 switch (dvbdmxfeed->pes_type) {
933 case DMX_TS_PES_VIDEO: 933 case DMX_PES_VIDEO:
934 case DMX_TS_PES_AUDIO: 934 case DMX_PES_AUDIO:
935 case DMX_TS_PES_TELETEXT: 935 case DMX_PES_TELETEXT:
936 case DMX_TS_PES_PCR: 936 case DMX_PES_PCR:
937 case DMX_TS_PES_OTHER: 937 case DMX_PES_OTHER:
938 break; 938 break;
939 default: 939 default:
940 return -EINVAL; 940 return -EINVAL;
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 504c81230339..e52c3b97f304 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -951,34 +951,34 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
951 951
952 switch (dvbdmxfeed->pes_type) { 952 switch (dvbdmxfeed->pes_type) {
953 953
954 case DMX_TS_PES_VIDEO: 954 case DMX_PES_VIDEO:
955 dprintk(" pes_type: DMX_TS_PES_VIDEO\n"); 955 dprintk(" pes_type: DMX_PES_VIDEO\n");
956 dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid; 956 dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
957 dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid; 957 dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid;
958 dec->video_filter = dvbdmxfeed->filter; 958 dec->video_filter = dvbdmxfeed->filter;
959 ttusb_dec_set_pids(dec); 959 ttusb_dec_set_pids(dec);
960 break; 960 break;
961 961
962 case DMX_TS_PES_AUDIO: 962 case DMX_PES_AUDIO:
963 dprintk(" pes_type: DMX_TS_PES_AUDIO\n"); 963 dprintk(" pes_type: DMX_PES_AUDIO\n");
964 dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid; 964 dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid;
965 dec->audio_filter = dvbdmxfeed->filter; 965 dec->audio_filter = dvbdmxfeed->filter;
966 ttusb_dec_set_pids(dec); 966 ttusb_dec_set_pids(dec);
967 break; 967 break;
968 968
969 case DMX_TS_PES_TELETEXT: 969 case DMX_PES_TELETEXT:
970 dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid; 970 dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid;
971 dprintk(" pes_type: DMX_TS_PES_TELETEXT(not supported)\n"); 971 dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
972 return -ENOSYS; 972 return -ENOSYS;
973 973
974 case DMX_TS_PES_PCR: 974 case DMX_PES_PCR:
975 dprintk(" pes_type: DMX_TS_PES_PCR\n"); 975 dprintk(" pes_type: DMX_PES_PCR\n");
976 dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid; 976 dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
977 ttusb_dec_set_pids(dec); 977 ttusb_dec_set_pids(dec);
978 break; 978 break;
979 979
980 case DMX_TS_PES_OTHER: 980 case DMX_PES_OTHER:
981 dprintk(" pes_type: DMX_TS_PES_OTHER(not supported)\n"); 981 dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
982 return -ENOSYS; 982 return -ENOSYS;
983 983
984 default: 984 default:
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
index cd1fe78a5532..d34c2afe2c24 100644
--- a/drivers/media/usb/usbvision/usbvision-video.c
+++ b/drivers/media/usb/usbvision/usbvision-video.c
@@ -483,7 +483,7 @@ static int vidioc_g_register(struct file *file, void *priv,
483} 483}
484 484
485static int vidioc_s_register(struct file *file, void *priv, 485static int vidioc_s_register(struct file *file, void *priv,
486 struct v4l2_dbg_register *reg) 486 const struct v4l2_dbg_register *reg)
487{ 487{
488 struct usb_usbvision *usbvision = video_drvdata(file); 488 struct usb_usbvision *usbvision = video_drvdata(file);
489 int err_code; 489 int err_code;
@@ -595,11 +595,11 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
595 return 0; 595 return 0;
596} 596}
597 597
598static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 598static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
599{ 599{
600 struct usb_usbvision *usbvision = video_drvdata(file); 600 struct usb_usbvision *usbvision = video_drvdata(file);
601 601
602 usbvision->tvnorm_id = *id; 602 usbvision->tvnorm_id = id;
603 603
604 call_all(usbvision, core, s_std, usbvision->tvnorm_id); 604 call_all(usbvision, core, s_std, usbvision->tvnorm_id);
605 /* propagate the change to the decoder */ 605 /* propagate the change to the decoder */
@@ -628,7 +628,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
628} 628}
629 629
630static int vidioc_s_tuner(struct file *file, void *priv, 630static int vidioc_s_tuner(struct file *file, void *priv,
631 struct v4l2_tuner *vt) 631 const struct v4l2_tuner *vt)
632{ 632{
633 struct usb_usbvision *usbvision = video_drvdata(file); 633 struct usb_usbvision *usbvision = video_drvdata(file);
634 634
@@ -657,7 +657,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
657} 657}
658 658
659static int vidioc_s_frequency(struct file *file, void *priv, 659static int vidioc_s_frequency(struct file *file, void *priv,
660 struct v4l2_frequency *freq) 660 const struct v4l2_frequency *freq)
661{ 661{
662 struct usb_usbvision *usbvision = video_drvdata(file); 662 struct usb_usbvision *usbvision = video_drvdata(file);
663 663
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 61e28dec991d..a2f4501c23ca 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1487,7 +1487,7 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
1487 step = mapping->get(mapping, UVC_GET_RES, 1487 step = mapping->get(mapping, UVC_GET_RES,
1488 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); 1488 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
1489 if (!(step & value)) 1489 if (!(step & value))
1490 return -ERANGE; 1490 return -EINVAL;
1491 } 1491 }
1492 1492
1493 break; 1493 break;
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 6c233a54ce40..cd962be860ca 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -149,6 +149,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
149 queue->queue.buf_struct_size = sizeof(struct uvc_buffer); 149 queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
150 queue->queue.ops = &uvc_queue_qops; 150 queue->queue.ops = &uvc_queue_qops;
151 queue->queue.mem_ops = &vb2_vmalloc_memops; 151 queue->queue.mem_ops = &vb2_vmalloc_memops;
152 queue->queue.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
152 ret = vb2_queue_init(&queue->queue); 153 ret = vb2_queue_init(&queue->queue);
153 if (ret) 154 if (ret)
154 return ret; 155 return ret;
diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig
index 976d029e9925..8c05565a240e 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -67,6 +67,7 @@ config VIDEOBUF2_MEMOPS
67 67
68config VIDEOBUF2_DMA_CONTIG 68config VIDEOBUF2_DMA_CONTIG
69 tristate 69 tristate
70 depends on HAS_DMA
70 select VIDEOBUF2_CORE 71 select VIDEOBUF2_CORE
71 select VIDEOBUF2_MEMOPS 72 select VIDEOBUF2_MEMOPS
72 select DMA_SHARED_BUFFER 73 select DMA_SHARED_BUFFER
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 768aaf62d5dc..aa50c46314b7 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -9,6 +9,9 @@ videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
9ifeq ($(CONFIG_COMPAT),y) 9ifeq ($(CONFIG_COMPAT),y)
10 videodev-objs += v4l2-compat-ioctl32.o 10 videodev-objs += v4l2-compat-ioctl32.o
11endif 11endif
12ifeq ($(CONFIG_OF),y)
13 videodev-objs += v4l2-of.o
14endif
12 15
13obj-$(CONFIG_VIDEO_V4L2) += videodev.o 16obj-$(CONFIG_VIDEO_V4L2) += videodev.o
14obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o 17obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o
diff --git a/drivers/media/v4l2-core/tuner-core.c b/drivers/media/v4l2-core/tuner-core.c
index b5a8aac2e126..ddc9379eb276 100644
--- a/drivers/media/v4l2-core/tuner-core.c
+++ b/drivers/media/v4l2-core/tuner-core.c
@@ -132,7 +132,7 @@ struct tuner {
132 bool standby; /* Standby mode */ 132 bool standby; /* Standby mode */
133 133
134 unsigned int type; /* chip type id */ 134 unsigned int type; /* chip type id */
135 unsigned int config; 135 void *config;
136 const char *name; 136 const char *name;
137}; 137};
138 138
@@ -218,26 +218,6 @@ static void fe_standby(struct dvb_frontend *fe)
218 fe_tuner_ops->sleep(fe); 218 fe_tuner_ops->sleep(fe);
219} 219}
220 220
221static int fe_has_signal(struct dvb_frontend *fe)
222{
223 u16 strength = 0;
224
225 if (fe->ops.tuner_ops.get_rf_strength)
226 fe->ops.tuner_ops.get_rf_strength(fe, &strength);
227
228 return strength;
229}
230
231static int fe_get_afc(struct dvb_frontend *fe)
232{
233 s32 afc = 0;
234
235 if (fe->ops.tuner_ops.get_afc)
236 fe->ops.tuner_ops.get_afc(fe, &afc);
237
238 return 0;
239}
240
241static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg) 221static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg)
242{ 222{
243 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops; 223 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
@@ -253,11 +233,9 @@ static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg)
253 233
254static void tuner_status(struct dvb_frontend *fe); 234static void tuner_status(struct dvb_frontend *fe);
255 235
256static struct analog_demod_ops tuner_analog_ops = { 236static const struct analog_demod_ops tuner_analog_ops = {
257 .set_params = fe_set_params, 237 .set_params = fe_set_params,
258 .standby = fe_standby, 238 .standby = fe_standby,
259 .has_signal = fe_has_signal,
260 .get_afc = fe_get_afc,
261 .set_config = fe_set_config, 239 .set_config = fe_set_config,
262 .tuner_status = tuner_status 240 .tuner_status = tuner_status
263}; 241};
@@ -272,9 +250,8 @@ static struct analog_demod_ops tuner_analog_ops = {
272 * @c: i2c_client descriptoy 250 * @c: i2c_client descriptoy
273 * @type: type of the tuner (e. g. tuner number) 251 * @type: type of the tuner (e. g. tuner number)
274 * @new_mode_mask: Indicates if tuner supports TV and/or Radio 252 * @new_mode_mask: Indicates if tuner supports TV and/or Radio
275 * @new_config: an optional parameter ranging from 0-255 used by 253 * @new_config: an optional parameter used by a few tuners to adjust
276 a few tuners to adjust an internal parameter, 254 internal parameters, like LNA mode
277 like LNA mode
278 * @tuner_callback: an optional function to be called when switching 255 * @tuner_callback: an optional function to be called when switching
279 * to analog mode 256 * to analog mode
280 * 257 *
@@ -282,7 +259,7 @@ static struct analog_demod_ops tuner_analog_ops = {
282 * by tun_setup structure. It contains several per-tuner initialization "magic" 259 * by tun_setup structure. It contains several per-tuner initialization "magic"
283 */ 260 */
284static void set_type(struct i2c_client *c, unsigned int type, 261static void set_type(struct i2c_client *c, unsigned int type,
285 unsigned int new_mode_mask, unsigned int new_config, 262 unsigned int new_mode_mask, void *new_config,
286 int (*tuner_callback) (void *dev, int component, int cmd, int arg)) 263 int (*tuner_callback) (void *dev, int component, int cmd, int arg))
287{ 264{
288 struct tuner *t = to_tuner(i2c_get_clientdata(c)); 265 struct tuner *t = to_tuner(i2c_get_clientdata(c));
@@ -297,8 +274,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
297 } 274 }
298 275
299 t->type = type; 276 t->type = type;
300 /* prevent invalid config values */ 277 t->config = new_config;
301 t->config = new_config < 256 ? new_config : 0;
302 if (tuner_callback != NULL) { 278 if (tuner_callback != NULL) {
303 tuner_dbg("defining GPIO callback\n"); 279 tuner_dbg("defining GPIO callback\n");
304 t->fe.callback = tuner_callback; 280 t->fe.callback = tuner_callback;
@@ -316,11 +292,8 @@ static void set_type(struct i2c_client *c, unsigned int type,
316 break; 292 break;
317 case TUNER_PHILIPS_TDA8290: 293 case TUNER_PHILIPS_TDA8290:
318 { 294 {
319 struct tda829x_config cfg = {
320 .lna_cfg = t->config,
321 };
322 if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter, 295 if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter,
323 t->i2c->addr, &cfg)) 296 t->i2c->addr, t->config))
324 goto attach_failed; 297 goto attach_failed;
325 break; 298 break;
326 } 299 }
@@ -409,7 +382,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
409 case TUNER_NXP_TDA18271: 382 case TUNER_NXP_TDA18271:
410 { 383 {
411 struct tda18271_config cfg = { 384 struct tda18271_config cfg = {
412 .config = t->config,
413 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT, 385 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
414 }; 386 };
415 387
@@ -453,6 +425,11 @@ static void set_type(struct i2c_client *c, unsigned int type,
453 memcpy(analog_ops, &tuner_analog_ops, 425 memcpy(analog_ops, &tuner_analog_ops,
454 sizeof(struct analog_demod_ops)); 426 sizeof(struct analog_demod_ops));
455 427
428 if (fe_tuner_ops->get_rf_strength)
429 analog_ops->has_signal = fe_tuner_ops->get_rf_strength;
430 if (fe_tuner_ops->get_afc)
431 analog_ops->get_afc = fe_tuner_ops->get_afc;
432
456 } else { 433 } else {
457 t->name = analog_ops->info.name; 434 t->name = analog_ops->info.name;
458 } 435 }
@@ -506,7 +483,7 @@ static int tuner_s_type_addr(struct v4l2_subdev *sd,
506 struct tuner *t = to_tuner(sd); 483 struct tuner *t = to_tuner(sd);
507 struct i2c_client *c = v4l2_get_subdevdata(sd); 484 struct i2c_client *c = v4l2_get_subdevdata(sd);
508 485
509 tuner_dbg("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n", 486 tuner_dbg("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=%p\n",
510 tun_setup->type, 487 tun_setup->type,
511 tun_setup->addr, 488 tun_setup->addr,
512 tun_setup->mode_mask, 489 tun_setup->mode_mask,
@@ -1073,9 +1050,12 @@ static void tuner_status(struct dvb_frontend *fe)
1073 if (tuner_status & TUNER_STATUS_STEREO) 1050 if (tuner_status & TUNER_STATUS_STEREO)
1074 tuner_info("Stereo: yes\n"); 1051 tuner_info("Stereo: yes\n");
1075 } 1052 }
1076 if (analog_ops->has_signal) 1053 if (analog_ops->has_signal) {
1077 tuner_info("Signal strength: %d\n", 1054 u16 signal;
1078 analog_ops->has_signal(fe)); 1055
1056 if (!analog_ops->has_signal(fe, &signal))
1057 tuner_info("Signal strength: %hu\n", signal);
1058 }
1079} 1059}
1080 1060
1081/* 1061/*
@@ -1134,7 +1114,7 @@ static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1134 return 0; 1114 return 0;
1135} 1115}
1136 1116
1137static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) 1117static int tuner_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
1138{ 1118{
1139 struct tuner *t = to_tuner(sd); 1119 struct tuner *t = to_tuner(sd);
1140 1120
@@ -1193,9 +1173,13 @@ static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1193 if (check_mode(t, vt->type) == -EINVAL) 1173 if (check_mode(t, vt->type) == -EINVAL)
1194 return 0; 1174 return 0;
1195 if (vt->type == t->mode && analog_ops->get_afc) 1175 if (vt->type == t->mode && analog_ops->get_afc)
1196 vt->afc = analog_ops->get_afc(&t->fe); 1176 analog_ops->get_afc(&t->fe, &vt->afc);
1197 if (analog_ops->has_signal) 1177 if (vt->type == t->mode && analog_ops->has_signal) {
1198 vt->signal = analog_ops->has_signal(&t->fe); 1178 u16 signal = (u16)vt->signal;
1179
1180 if (!analog_ops->has_signal(&t->fe, &signal))
1181 vt->signal = signal;
1182 }
1199 if (vt->type != V4L2_TUNER_RADIO) { 1183 if (vt->type != V4L2_TUNER_RADIO) {
1200 vt->capability |= V4L2_TUNER_CAP_NORM; 1184 vt->capability |= V4L2_TUNER_CAP_NORM;
1201 vt->rangelow = tv_range[0] * 16; 1185 vt->rangelow = tv_range[0] * 16;
@@ -1233,7 +1217,7 @@ static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1233 * Note: vt->type should be initialized before calling it. 1217 * Note: vt->type should be initialized before calling it.
1234 * This is done by either video_ioctl2 or by the bridge driver. 1218 * This is done by either video_ioctl2 or by the bridge driver.
1235 */ 1219 */
1236static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) 1220static int tuner_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
1237{ 1221{
1238 struct tuner *t = to_tuner(sd); 1222 struct tuner *t = to_tuner(sd);
1239 1223
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index aa044f491666..3fed63f4e026 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -230,7 +230,7 @@ EXPORT_SYMBOL(v4l2_ctrl_next);
230int v4l2_chip_match_host(const struct v4l2_dbg_match *match) 230int v4l2_chip_match_host(const struct v4l2_dbg_match *match)
231{ 231{
232 switch (match->type) { 232 switch (match->type) {
233 case V4L2_CHIP_MATCH_HOST: 233 case V4L2_CHIP_MATCH_BRIDGE:
234 return match->addr == 0; 234 return match->addr == 0;
235 default: 235 default:
236 return 0; 236 return 0;
@@ -251,12 +251,11 @@ int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match
251 if (c->driver == NULL || c->driver->driver.name == NULL) 251 if (c->driver == NULL || c->driver->driver.name == NULL)
252 return 0; 252 return 0;
253 len = strlen(c->driver->driver.name); 253 len = strlen(c->driver->driver.name);
254 /* legacy drivers have a ' suffix, don't try to match that */
255 if (len && c->driver->driver.name[len - 1] == '\'')
256 len--;
257 return len && !strncmp(c->driver->driver.name, match->name, len); 254 return len && !strncmp(c->driver->driver.name, match->name, len);
258 case V4L2_CHIP_MATCH_I2C_ADDR: 255 case V4L2_CHIP_MATCH_I2C_ADDR:
259 return c->addr == match->addr; 256 return c->addr == match->addr;
257 case V4L2_CHIP_MATCH_SUBDEV:
258 return 1;
260 default: 259 default:
261 return 0; 260 return 0;
262 } 261 }
@@ -551,53 +550,6 @@ void v4l_bound_align_image(u32 *w, unsigned int wmin, unsigned int wmax,
551EXPORT_SYMBOL_GPL(v4l_bound_align_image); 550EXPORT_SYMBOL_GPL(v4l_bound_align_image);
552 551
553/** 552/**
554 * v4l_fill_dv_preset_info - fill description of a digital video preset
555 * @preset - preset value
556 * @info - pointer to struct v4l2_dv_enum_preset
557 *
558 * drivers can use this helper function to fill description of dv preset
559 * in info.
560 */
561int v4l_fill_dv_preset_info(u32 preset, struct v4l2_dv_enum_preset *info)
562{
563 static const struct v4l2_dv_preset_info {
564 u16 width;
565 u16 height;
566 const char *name;
567 } dv_presets[] = {
568 { 0, 0, "Invalid" }, /* V4L2_DV_INVALID */
569 { 720, 480, "480p@59.94" }, /* V4L2_DV_480P59_94 */
570 { 720, 576, "576p@50" }, /* V4L2_DV_576P50 */
571 { 1280, 720, "720p@24" }, /* V4L2_DV_720P24 */
572 { 1280, 720, "720p@25" }, /* V4L2_DV_720P25 */
573 { 1280, 720, "720p@30" }, /* V4L2_DV_720P30 */
574 { 1280, 720, "720p@50" }, /* V4L2_DV_720P50 */
575 { 1280, 720, "720p@59.94" }, /* V4L2_DV_720P59_94 */
576 { 1280, 720, "720p@60" }, /* V4L2_DV_720P60 */
577 { 1920, 1080, "1080i@29.97" }, /* V4L2_DV_1080I29_97 */
578 { 1920, 1080, "1080i@30" }, /* V4L2_DV_1080I30 */
579 { 1920, 1080, "1080i@25" }, /* V4L2_DV_1080I25 */
580 { 1920, 1080, "1080i@50" }, /* V4L2_DV_1080I50 */
581 { 1920, 1080, "1080i@60" }, /* V4L2_DV_1080I60 */
582 { 1920, 1080, "1080p@24" }, /* V4L2_DV_1080P24 */
583 { 1920, 1080, "1080p@25" }, /* V4L2_DV_1080P25 */
584 { 1920, 1080, "1080p@30" }, /* V4L2_DV_1080P30 */
585 { 1920, 1080, "1080p@50" }, /* V4L2_DV_1080P50 */
586 { 1920, 1080, "1080p@60" }, /* V4L2_DV_1080P60 */
587 };
588
589 if (info == NULL || preset >= ARRAY_SIZE(dv_presets))
590 return -EINVAL;
591
592 info->preset = preset;
593 info->width = dv_presets[preset].width;
594 info->height = dv_presets[preset].height;
595 strlcpy(info->name, dv_presets[preset].name, sizeof(info->name));
596 return 0;
597}
598EXPORT_SYMBOL_GPL(v4l_fill_dv_preset_info);
599
600/**
601 * v4l_match_dv_timings - check if two timings match 553 * v4l_match_dv_timings - check if two timings match
602 * @t1 - compare this v4l2_dv_timings struct... 554 * @t1 - compare this v4l2_dv_timings struct...
603 * @t2 - with this struct. 555 * @t2 - with this struct.
diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 7157af301b14..f1295519f285 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -1076,10 +1076,6 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
1076 case VIDIOC_DBG_G_REGISTER: 1076 case VIDIOC_DBG_G_REGISTER:
1077 case VIDIOC_DBG_G_CHIP_IDENT: 1077 case VIDIOC_DBG_G_CHIP_IDENT:
1078 case VIDIOC_S_HW_FREQ_SEEK: 1078 case VIDIOC_S_HW_FREQ_SEEK:
1079 case VIDIOC_ENUM_DV_PRESETS:
1080 case VIDIOC_S_DV_PRESET:
1081 case VIDIOC_G_DV_PRESET:
1082 case VIDIOC_QUERY_DV_PRESET:
1083 case VIDIOC_S_DV_TIMINGS: 1079 case VIDIOC_S_DV_TIMINGS:
1084 case VIDIOC_G_DV_TIMINGS: 1080 case VIDIOC_G_DV_TIMINGS:
1085 case VIDIOC_DQEVENT: 1081 case VIDIOC_DQEVENT:
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index 6b28b5800500..ebb8e48619a2 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -234,6 +234,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
234 "Average", 234 "Average",
235 "Center Weighted", 235 "Center Weighted",
236 "Spot", 236 "Spot",
237 "Matrix",
237 NULL 238 NULL
238 }; 239 };
239 static const char * const camera_auto_focus_range[] = { 240 static const char * const camera_auto_focus_range[] = {
@@ -297,8 +298,8 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
297 "Text", 298 "Text",
298 NULL 299 NULL
299 }; 300 };
300 static const char * const tune_preemphasis[] = { 301 static const char * const tune_emphasis[] = {
301 "No Preemphasis", 302 "None",
302 "50 Microseconds", 303 "50 Microseconds",
303 "75 Microseconds", 304 "75 Microseconds",
304 NULL, 305 NULL,
@@ -508,7 +509,9 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
508 case V4L2_CID_SCENE_MODE: 509 case V4L2_CID_SCENE_MODE:
509 return scene_mode; 510 return scene_mode;
510 case V4L2_CID_TUNE_PREEMPHASIS: 511 case V4L2_CID_TUNE_PREEMPHASIS:
511 return tune_preemphasis; 512 return tune_emphasis;
513 case V4L2_CID_TUNE_DEEMPHASIS:
514 return tune_emphasis;
512 case V4L2_CID_FLASH_LED_MODE: 515 case V4L2_CID_FLASH_LED_MODE:
513 return flash_led_mode; 516 return flash_led_mode;
514 case V4L2_CID_FLASH_STROBE_SOURCE: 517 case V4L2_CID_FLASH_STROBE_SOURCE:
@@ -695,6 +698,7 @@ const char *v4l2_ctrl_get_name(u32 id)
695 case V4L2_CID_MPEG_VIDEO_DEC_PTS: return "Video Decoder PTS"; 698 case V4L2_CID_MPEG_VIDEO_DEC_PTS: return "Video Decoder PTS";
696 case V4L2_CID_MPEG_VIDEO_DEC_FRAME: return "Video Decoder Frame Count"; 699 case V4L2_CID_MPEG_VIDEO_DEC_FRAME: return "Video Decoder Frame Count";
697 case V4L2_CID_MPEG_VIDEO_VBV_DELAY: return "Initial Delay for VBV Control"; 700 case V4L2_CID_MPEG_VIDEO_VBV_DELAY: return "Initial Delay for VBV Control";
701 case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER: return "Repeat Sequence Header";
698 702
699 /* CAMERA controls */ 703 /* CAMERA controls */
700 /* Keep the order of the 'case's the same as in videodev2.h! */ 704 /* Keep the order of the 'case's the same as in videodev2.h! */
@@ -799,6 +803,9 @@ const char *v4l2_ctrl_get_name(u32 id)
799 case V4L2_CID_DV_RX_POWER_PRESENT: return "Power Present"; 803 case V4L2_CID_DV_RX_POWER_PRESENT: return "Power Present";
800 case V4L2_CID_DV_RX_RGB_RANGE: return "Rx RGB Quantization Range"; 804 case V4L2_CID_DV_RX_RGB_RANGE: return "Rx RGB Quantization Range";
801 805
806 case V4L2_CID_FM_RX_CLASS: return "FM Radio Receiver Controls";
807 case V4L2_CID_TUNE_DEEMPHASIS: return "De-Emphasis";
808 case V4L2_CID_RDS_RECEPTION: return "RDS Reception";
802 default: 809 default:
803 return NULL; 810 return NULL;
804 } 811 }
@@ -844,8 +851,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
844 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: 851 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:
845 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE: 852 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:
846 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL: 853 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:
854 case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER:
847 case V4L2_CID_WIDE_DYNAMIC_RANGE: 855 case V4L2_CID_WIDE_DYNAMIC_RANGE:
848 case V4L2_CID_IMAGE_STABILIZATION: 856 case V4L2_CID_IMAGE_STABILIZATION:
857 case V4L2_CID_RDS_RECEPTION:
849 *type = V4L2_CTRL_TYPE_BOOLEAN; 858 *type = V4L2_CTRL_TYPE_BOOLEAN;
850 *min = 0; 859 *min = 0;
851 *max = *step = 1; 860 *max = *step = 1;
@@ -904,6 +913,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
904 case V4L2_CID_DV_TX_RGB_RANGE: 913 case V4L2_CID_DV_TX_RGB_RANGE:
905 case V4L2_CID_DV_RX_RGB_RANGE: 914 case V4L2_CID_DV_RX_RGB_RANGE:
906 case V4L2_CID_TEST_PATTERN: 915 case V4L2_CID_TEST_PATTERN:
916 case V4L2_CID_TUNE_DEEMPHASIS:
907 *type = V4L2_CTRL_TYPE_MENU; 917 *type = V4L2_CTRL_TYPE_MENU;
908 break; 918 break;
909 case V4L2_CID_LINK_FREQ: 919 case V4L2_CID_LINK_FREQ:
@@ -926,6 +936,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
926 case V4L2_CID_IMAGE_SOURCE_CLASS: 936 case V4L2_CID_IMAGE_SOURCE_CLASS:
927 case V4L2_CID_IMAGE_PROC_CLASS: 937 case V4L2_CID_IMAGE_PROC_CLASS:
928 case V4L2_CID_DV_CLASS: 938 case V4L2_CID_DV_CLASS:
939 case V4L2_CID_FM_RX_CLASS:
929 *type = V4L2_CTRL_TYPE_CTRL_CLASS; 940 *type = V4L2_CTRL_TYPE_CTRL_CLASS;
930 /* You can neither read not write these */ 941 /* You can neither read not write these */
931 *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY; 942 *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -1362,11 +1373,13 @@ static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err)
1362} 1373}
1363 1374
1364/* Initialize the handler */ 1375/* Initialize the handler */
1365int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl, 1376int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
1366 unsigned nr_of_controls_hint) 1377 unsigned nr_of_controls_hint,
1378 struct lock_class_key *key, const char *name)
1367{ 1379{
1368 hdl->lock = &hdl->_lock; 1380 hdl->lock = &hdl->_lock;
1369 mutex_init(hdl->lock); 1381 mutex_init(hdl->lock);
1382 lockdep_set_class_and_name(hdl->lock, key, name);
1370 INIT_LIST_HEAD(&hdl->ctrls); 1383 INIT_LIST_HEAD(&hdl->ctrls);
1371 INIT_LIST_HEAD(&hdl->ctrl_refs); 1384 INIT_LIST_HEAD(&hdl->ctrl_refs);
1372 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; 1385 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8;
@@ -1375,7 +1388,7 @@ int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl,
1375 hdl->error = hdl->buckets ? 0 : -ENOMEM; 1388 hdl->error = hdl->buckets ? 0 : -ENOMEM;
1376 return hdl->error; 1389 return hdl->error;
1377} 1390}
1378EXPORT_SYMBOL(v4l2_ctrl_handler_init); 1391EXPORT_SYMBOL(v4l2_ctrl_handler_init_class);
1379 1392
1380/* Free all controls and control refs */ 1393/* Free all controls and control refs */
1381void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) 1394void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index de1e9ab7db99..5923c5dfacd5 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -592,8 +592,9 @@ static void determine_valid_ioctls(struct video_device *vdev)
592 SET_VALID_IOCTL(ops, VIDIOC_S_FREQUENCY, vidioc_s_frequency); 592 SET_VALID_IOCTL(ops, VIDIOC_S_FREQUENCY, vidioc_s_frequency);
593 SET_VALID_IOCTL(ops, VIDIOC_LOG_STATUS, vidioc_log_status); 593 SET_VALID_IOCTL(ops, VIDIOC_LOG_STATUS, vidioc_log_status);
594#ifdef CONFIG_VIDEO_ADV_DEBUG 594#ifdef CONFIG_VIDEO_ADV_DEBUG
595 SET_VALID_IOCTL(ops, VIDIOC_DBG_G_REGISTER, vidioc_g_register); 595 set_bit(_IOC_NR(VIDIOC_DBG_G_CHIP_INFO), valid_ioctls);
596 SET_VALID_IOCTL(ops, VIDIOC_DBG_S_REGISTER, vidioc_s_register); 596 set_bit(_IOC_NR(VIDIOC_DBG_G_REGISTER), valid_ioctls);
597 set_bit(_IOC_NR(VIDIOC_DBG_S_REGISTER), valid_ioctls);
597#endif 598#endif
598 SET_VALID_IOCTL(ops, VIDIOC_DBG_G_CHIP_IDENT, vidioc_g_chip_ident); 599 SET_VALID_IOCTL(ops, VIDIOC_DBG_G_CHIP_IDENT, vidioc_g_chip_ident);
599 /* yes, really vidioc_subscribe_event */ 600 /* yes, really vidioc_subscribe_event */
@@ -685,7 +686,6 @@ static void determine_valid_ioctls(struct video_device *vdev)
685 SET_VALID_IOCTL(ops, VIDIOC_ENUMAUDIO, vidioc_enumaudio); 686 SET_VALID_IOCTL(ops, VIDIOC_ENUMAUDIO, vidioc_enumaudio);
686 SET_VALID_IOCTL(ops, VIDIOC_G_AUDIO, vidioc_g_audio); 687 SET_VALID_IOCTL(ops, VIDIOC_G_AUDIO, vidioc_g_audio);
687 SET_VALID_IOCTL(ops, VIDIOC_S_AUDIO, vidioc_s_audio); 688 SET_VALID_IOCTL(ops, VIDIOC_S_AUDIO, vidioc_s_audio);
688 SET_VALID_IOCTL(ops, VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset);
689 SET_VALID_IOCTL(ops, VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings); 689 SET_VALID_IOCTL(ops, VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings);
690 } 690 }
691 if (is_tx) { 691 if (is_tx) {
@@ -708,9 +708,6 @@ static void determine_valid_ioctls(struct video_device *vdev)
708 (ops->vidioc_g_std || vdev->current_norm))) 708 (ops->vidioc_g_std || vdev->current_norm)))
709 set_bit(_IOC_NR(VIDIOC_G_PARM), valid_ioctls); 709 set_bit(_IOC_NR(VIDIOC_G_PARM), valid_ioctls);
710 SET_VALID_IOCTL(ops, VIDIOC_S_PARM, vidioc_s_parm); 710 SET_VALID_IOCTL(ops, VIDIOC_S_PARM, vidioc_s_parm);
711 SET_VALID_IOCTL(ops, VIDIOC_ENUM_DV_PRESETS, vidioc_enum_dv_presets);
712 SET_VALID_IOCTL(ops, VIDIOC_S_DV_PRESET, vidioc_s_dv_preset);
713 SET_VALID_IOCTL(ops, VIDIOC_G_DV_PRESET, vidioc_g_dv_preset);
714 SET_VALID_IOCTL(ops, VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings); 711 SET_VALID_IOCTL(ops, VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings);
715 SET_VALID_IOCTL(ops, VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings); 712 SET_VALID_IOCTL(ops, VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings);
716 SET_VALID_IOCTL(ops, VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings); 713 SET_VALID_IOCTL(ops, VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings);
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index aa6e7c788db2..f81bda1a48ec 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -35,6 +35,8 @@
35 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \ 35 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
36 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field)) 36 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
37 37
38#define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls)
39
38struct std_descr { 40struct std_descr {
39 v4l2_std_id std; 41 v4l2_std_id std;
40 const char *descr; 42 const char *descr;
@@ -167,9 +169,11 @@ static void v4l_print_querycap(const void *arg, bool write_only)
167{ 169{
168 const struct v4l2_capability *p = arg; 170 const struct v4l2_capability *p = arg;
169 171
170 pr_cont("driver=%s, card=%s, bus=%s, version=0x%08x, " 172 pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, "
171 "capabilities=0x%08x, device_caps=0x%08x\n", 173 "capabilities=0x%08x, device_caps=0x%08x\n",
172 p->driver, p->card, p->bus_info, 174 (int)sizeof(p->driver), p->driver,
175 (int)sizeof(p->card), p->card,
176 (int)sizeof(p->bus_info), p->bus_info,
173 p->version, p->capabilities, p->device_caps); 177 p->version, p->capabilities, p->device_caps);
174} 178}
175 179
@@ -177,20 +181,21 @@ static void v4l_print_enuminput(const void *arg, bool write_only)
177{ 181{
178 const struct v4l2_input *p = arg; 182 const struct v4l2_input *p = arg;
179 183
180 pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, tuner=%u, " 184 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, "
181 "std=0x%08Lx, status=0x%x, capabilities=0x%x\n", 185 "std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
182 p->index, p->name, p->type, p->audioset, p->tuner, 186 p->index, (int)sizeof(p->name), p->name, p->type, p->audioset,
183 (unsigned long long)p->std, p->status, p->capabilities); 187 p->tuner, (unsigned long long)p->std, p->status,
188 p->capabilities);
184} 189}
185 190
186static void v4l_print_enumoutput(const void *arg, bool write_only) 191static void v4l_print_enumoutput(const void *arg, bool write_only)
187{ 192{
188 const struct v4l2_output *p = arg; 193 const struct v4l2_output *p = arg;
189 194
190 pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, " 195 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, "
191 "modulator=%u, std=0x%08Lx, capabilities=0x%x\n", 196 "modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
192 p->index, p->name, p->type, p->audioset, p->modulator, 197 p->index, (int)sizeof(p->name), p->name, p->type, p->audioset,
193 (unsigned long long)p->std, p->capabilities); 198 p->modulator, (unsigned long long)p->std, p->capabilities);
194} 199}
195 200
196static void v4l_print_audio(const void *arg, bool write_only) 201static void v4l_print_audio(const void *arg, bool write_only)
@@ -200,8 +205,9 @@ static void v4l_print_audio(const void *arg, bool write_only)
200 if (write_only) 205 if (write_only)
201 pr_cont("index=%u, mode=0x%x\n", p->index, p->mode); 206 pr_cont("index=%u, mode=0x%x\n", p->index, p->mode);
202 else 207 else
203 pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n", 208 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
204 p->index, p->name, p->capability, p->mode); 209 p->index, (int)sizeof(p->name), p->name,
210 p->capability, p->mode);
205} 211}
206 212
207static void v4l_print_audioout(const void *arg, bool write_only) 213static void v4l_print_audioout(const void *arg, bool write_only)
@@ -211,21 +217,22 @@ static void v4l_print_audioout(const void *arg, bool write_only)
211 if (write_only) 217 if (write_only)
212 pr_cont("index=%u\n", p->index); 218 pr_cont("index=%u\n", p->index);
213 else 219 else
214 pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n", 220 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
215 p->index, p->name, p->capability, p->mode); 221 p->index, (int)sizeof(p->name), p->name,
222 p->capability, p->mode);
216} 223}
217 224
218static void v4l_print_fmtdesc(const void *arg, bool write_only) 225static void v4l_print_fmtdesc(const void *arg, bool write_only)
219{ 226{
220 const struct v4l2_fmtdesc *p = arg; 227 const struct v4l2_fmtdesc *p = arg;
221 228
222 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%s'\n", 229 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
223 p->index, prt_names(p->type, v4l2_type_names), 230 p->index, prt_names(p->type, v4l2_type_names),
224 p->flags, (p->pixelformat & 0xff), 231 p->flags, (p->pixelformat & 0xff),
225 (p->pixelformat >> 8) & 0xff, 232 (p->pixelformat >> 8) & 0xff,
226 (p->pixelformat >> 16) & 0xff, 233 (p->pixelformat >> 16) & 0xff,
227 (p->pixelformat >> 24) & 0xff, 234 (p->pixelformat >> 24) & 0xff,
228 p->description); 235 (int)sizeof(p->description), p->description);
229} 236}
230 237
231static void v4l_print_format(const void *arg, bool write_only) 238static void v4l_print_format(const void *arg, bool write_only)
@@ -348,9 +355,9 @@ static void v4l_print_modulator(const void *arg, bool write_only)
348 if (write_only) 355 if (write_only)
349 pr_cont("index=%u, txsubchans=0x%x", p->index, p->txsubchans); 356 pr_cont("index=%u, txsubchans=0x%x", p->index, p->txsubchans);
350 else 357 else
351 pr_cont("index=%u, name=%s, capability=0x%x, " 358 pr_cont("index=%u, name=%.*s, capability=0x%x, "
352 "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n", 359 "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
353 p->index, p->name, p->capability, 360 p->index, (int)sizeof(p->name), p->name, p->capability,
354 p->rangelow, p->rangehigh, p->txsubchans); 361 p->rangelow, p->rangehigh, p->txsubchans);
355} 362}
356 363
@@ -361,10 +368,10 @@ static void v4l_print_tuner(const void *arg, bool write_only)
361 if (write_only) 368 if (write_only)
362 pr_cont("index=%u, audmode=%u\n", p->index, p->audmode); 369 pr_cont("index=%u, audmode=%u\n", p->index, p->audmode);
363 else 370 else
364 pr_cont("index=%u, name=%s, type=%u, capability=0x%x, " 371 pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, "
365 "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, " 372 "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, "
366 "rxsubchans=0x%x, audmode=%u\n", 373 "rxsubchans=0x%x, audmode=%u\n",
367 p->index, p->name, p->type, 374 p->index, (int)sizeof(p->name), p->name, p->type,
368 p->capability, p->rangelow, 375 p->capability, p->rangelow,
369 p->rangehigh, p->signal, p->afc, 376 p->rangehigh, p->signal, p->afc,
370 p->rxsubchans, p->audmode); 377 p->rxsubchans, p->audmode);
@@ -382,9 +389,9 @@ static void v4l_print_standard(const void *arg, bool write_only)
382{ 389{
383 const struct v4l2_standard *p = arg; 390 const struct v4l2_standard *p = arg;
384 391
385 pr_cont("index=%u, id=0x%Lx, name=%s, fps=%u/%u, " 392 pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, "
386 "framelines=%u\n", p->index, 393 "framelines=%u\n", p->index,
387 (unsigned long long)p->id, p->name, 394 (unsigned long long)p->id, (int)sizeof(p->name), p->name,
388 p->frameperiod.numerator, 395 p->frameperiod.numerator,
389 p->frameperiod.denominator, 396 p->frameperiod.denominator,
390 p->framelines); 397 p->framelines);
@@ -504,9 +511,9 @@ static void v4l_print_queryctrl(const void *arg, bool write_only)
504{ 511{
505 const struct v4l2_queryctrl *p = arg; 512 const struct v4l2_queryctrl *p = arg;
506 513
507 pr_cont("id=0x%x, type=%d, name=%s, min/max=%d/%d, " 514 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, "
508 "step=%d, default=%d, flags=0x%08x\n", 515 "step=%d, default=%d, flags=0x%08x\n",
509 p->id, p->type, p->name, 516 p->id, p->type, (int)sizeof(p->name), p->name,
510 p->minimum, p->maximum, 517 p->minimum, p->maximum,
511 p->step, p->default_value, p->flags); 518 p->step, p->default_value, p->flags);
512} 519}
@@ -623,39 +630,39 @@ static void v4l_print_dbg_chip_ident(const void *arg, bool write_only)
623 630
624 pr_cont("type=%u, ", p->match.type); 631 pr_cont("type=%u, ", p->match.type);
625 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) 632 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
626 pr_cont("name=%s, ", p->match.name); 633 pr_cont("name=%.*s, ",
634 (int)sizeof(p->match.name), p->match.name);
627 else 635 else
628 pr_cont("addr=%u, ", p->match.addr); 636 pr_cont("addr=%u, ", p->match.addr);
629 pr_cont("chip_ident=%u, revision=0x%x\n", 637 pr_cont("chip_ident=%u, revision=0x%x\n",
630 p->ident, p->revision); 638 p->ident, p->revision);
631} 639}
632 640
633static void v4l_print_dbg_register(const void *arg, bool write_only) 641static void v4l_print_dbg_chip_info(const void *arg, bool write_only)
634{ 642{
635 const struct v4l2_dbg_register *p = arg; 643 const struct v4l2_dbg_chip_info *p = arg;
636 644
637 pr_cont("type=%u, ", p->match.type); 645 pr_cont("type=%u, ", p->match.type);
638 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) 646 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
639 pr_cont("name=%s, ", p->match.name); 647 pr_cont("name=%.*s, ",
648 (int)sizeof(p->match.name), p->match.name);
640 else 649 else
641 pr_cont("addr=%u, ", p->match.addr); 650 pr_cont("addr=%u, ", p->match.addr);
642 pr_cont("reg=0x%llx, val=0x%llx\n", 651 pr_cont("name=%.*s\n", (int)sizeof(p->name), p->name);
643 p->reg, p->val);
644} 652}
645 653
646static void v4l_print_dv_enum_presets(const void *arg, bool write_only) 654static void v4l_print_dbg_register(const void *arg, bool write_only)
647{
648 const struct v4l2_dv_enum_preset *p = arg;
649
650 pr_cont("index=%u, preset=%u, name=%s, width=%u, height=%u\n",
651 p->index, p->preset, p->name, p->width, p->height);
652}
653
654static void v4l_print_dv_preset(const void *arg, bool write_only)
655{ 655{
656 const struct v4l2_dv_preset *p = arg; 656 const struct v4l2_dbg_register *p = arg;
657 657
658 pr_cont("preset=%u\n", p->preset); 658 pr_cont("type=%u, ", p->match.type);
659 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
660 pr_cont("name=%.*s, ",
661 (int)sizeof(p->match.name), p->match.name);
662 else
663 pr_cont("addr=%u, ", p->match.addr);
664 pr_cont("reg=0x%llx, val=0x%llx\n",
665 p->reg, p->val);
659} 666}
660 667
661static void v4l_print_dv_timings(const void *arg, bool write_only) 668static void v4l_print_dv_timings(const void *arg, bool write_only)
@@ -997,20 +1004,17 @@ static int v4l_s_priority(const struct v4l2_ioctl_ops *ops,
997static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, 1004static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
998 struct file *file, void *fh, void *arg) 1005 struct file *file, void *fh, void *arg)
999{ 1006{
1007 struct video_device *vfd = video_devdata(file);
1000 struct v4l2_input *p = arg; 1008 struct v4l2_input *p = arg;
1001 1009
1002 /* 1010 /*
1003 * We set the flags for CAP_PRESETS, CAP_DV_TIMINGS & 1011 * We set the flags for CAP_DV_TIMINGS &
1004 * CAP_STD here based on ioctl handler provided by the 1012 * CAP_STD here based on ioctl handler provided by the
1005 * driver. If the driver doesn't support these 1013 * driver. If the driver doesn't support these
1006 * for a specific input, it must override these flags. 1014 * for a specific input, it must override these flags.
1007 */ 1015 */
1008 if (ops->vidioc_s_std) 1016 if (is_valid_ioctl(vfd, VIDIOC_S_STD))
1009 p->capabilities |= V4L2_IN_CAP_STD; 1017 p->capabilities |= V4L2_IN_CAP_STD;
1010 if (ops->vidioc_s_dv_preset)
1011 p->capabilities |= V4L2_IN_CAP_PRESETS;
1012 if (ops->vidioc_s_dv_timings)
1013 p->capabilities |= V4L2_IN_CAP_DV_TIMINGS;
1014 1018
1015 return ops->vidioc_enum_input(file, fh, p); 1019 return ops->vidioc_enum_input(file, fh, p);
1016} 1020}
@@ -1018,20 +1022,17 @@ static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
1018static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, 1022static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
1019 struct file *file, void *fh, void *arg) 1023 struct file *file, void *fh, void *arg)
1020{ 1024{
1025 struct video_device *vfd = video_devdata(file);
1021 struct v4l2_output *p = arg; 1026 struct v4l2_output *p = arg;
1022 1027
1023 /* 1028 /*
1024 * We set the flags for CAP_PRESETS, CAP_DV_TIMINGS & 1029 * We set the flags for CAP_DV_TIMINGS &
1025 * CAP_STD here based on ioctl handler provided by the 1030 * CAP_STD here based on ioctl handler provided by the
1026 * driver. If the driver doesn't support these 1031 * driver. If the driver doesn't support these
1027 * for a specific output, it must override these flags. 1032 * for a specific output, it must override these flags.
1028 */ 1033 */
1029 if (ops->vidioc_s_std) 1034 if (is_valid_ioctl(vfd, VIDIOC_S_STD))
1030 p->capabilities |= V4L2_OUT_CAP_STD; 1035 p->capabilities |= V4L2_OUT_CAP_STD;
1031 if (ops->vidioc_s_dv_preset)
1032 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1033 if (ops->vidioc_s_dv_timings)
1034 p->capabilities |= V4L2_OUT_CAP_DV_TIMINGS;
1035 1036
1036 return ops->vidioc_enum_output(file, fh, p); 1037 return ops->vidioc_enum_output(file, fh, p);
1037} 1038}
@@ -1316,7 +1317,7 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
1316 struct file *file, void *fh, void *arg) 1317 struct file *file, void *fh, void *arg)
1317{ 1318{
1318 struct video_device *vfd = video_devdata(file); 1319 struct video_device *vfd = video_devdata(file);
1319 struct v4l2_frequency *p = arg; 1320 const struct v4l2_frequency *p = arg;
1320 enum v4l2_tuner_type type; 1321 enum v4l2_tuner_type type;
1321 1322
1322 type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 1323 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
@@ -1383,15 +1384,15 @@ static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
1383 struct file *file, void *fh, void *arg) 1384 struct file *file, void *fh, void *arg)
1384{ 1385{
1385 struct video_device *vfd = video_devdata(file); 1386 struct video_device *vfd = video_devdata(file);
1386 v4l2_std_id *id = arg, norm; 1387 v4l2_std_id id = *(v4l2_std_id *)arg, norm;
1387 int ret; 1388 int ret;
1388 1389
1389 norm = (*id) & vfd->tvnorms; 1390 norm = id & vfd->tvnorms;
1390 if (vfd->tvnorms && !norm) /* Check if std is supported */ 1391 if (vfd->tvnorms && !norm) /* Check if std is supported */
1391 return -EINVAL; 1392 return -EINVAL;
1392 1393
1393 /* Calls the specific handler */ 1394 /* Calls the specific handler */
1394 ret = ops->vidioc_s_std(file, fh, &norm); 1395 ret = ops->vidioc_s_std(file, fh, norm);
1395 1396
1396 /* Updates standard information */ 1397 /* Updates standard information */
1397 if (ret >= 0) 1398 if (ret >= 0)
@@ -1513,7 +1514,7 @@ static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
1513 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 1514 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1514 return -EINVAL; 1515 return -EINVAL;
1515 p->parm.capture.readbuffers = 2; 1516 p->parm.capture.readbuffers = 2;
1516 if (ops->vidioc_g_std) 1517 if (is_valid_ioctl(vfd, VIDIOC_G_STD) && ops->vidioc_g_std)
1517 ret = ops->vidioc_g_std(file, fh, &std); 1518 ret = ops->vidioc_g_std(file, fh, &std);
1518 if (ret == 0) 1519 if (ret == 0)
1519 v4l2_video_std_frame_period(std, 1520 v4l2_video_std_frame_period(std,
@@ -1792,10 +1793,23 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
1792{ 1793{
1793#ifdef CONFIG_VIDEO_ADV_DEBUG 1794#ifdef CONFIG_VIDEO_ADV_DEBUG
1794 struct v4l2_dbg_register *p = arg; 1795 struct v4l2_dbg_register *p = arg;
1796 struct video_device *vfd = video_devdata(file);
1797 struct v4l2_subdev *sd;
1798 int idx = 0;
1795 1799
1796 if (!capable(CAP_SYS_ADMIN)) 1800 if (!capable(CAP_SYS_ADMIN))
1797 return -EPERM; 1801 return -EPERM;
1798 return ops->vidioc_g_register(file, fh, p); 1802 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) {
1803 if (vfd->v4l2_dev == NULL)
1804 return -EINVAL;
1805 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev)
1806 if (p->match.addr == idx++)
1807 return v4l2_subdev_call(sd, core, g_register, p);
1808 return -EINVAL;
1809 }
1810 if (ops->vidioc_g_register)
1811 return ops->vidioc_g_register(file, fh, p);
1812 return -EINVAL;
1799#else 1813#else
1800 return -ENOTTY; 1814 return -ENOTTY;
1801#endif 1815#endif
@@ -1805,11 +1819,24 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
1805 struct file *file, void *fh, void *arg) 1819 struct file *file, void *fh, void *arg)
1806{ 1820{
1807#ifdef CONFIG_VIDEO_ADV_DEBUG 1821#ifdef CONFIG_VIDEO_ADV_DEBUG
1808 struct v4l2_dbg_register *p = arg; 1822 const struct v4l2_dbg_register *p = arg;
1823 struct video_device *vfd = video_devdata(file);
1824 struct v4l2_subdev *sd;
1825 int idx = 0;
1809 1826
1810 if (!capable(CAP_SYS_ADMIN)) 1827 if (!capable(CAP_SYS_ADMIN))
1811 return -EPERM; 1828 return -EPERM;
1812 return ops->vidioc_s_register(file, fh, p); 1829 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) {
1830 if (vfd->v4l2_dev == NULL)
1831 return -EINVAL;
1832 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev)
1833 if (p->match.addr == idx++)
1834 return v4l2_subdev_call(sd, core, s_register, p);
1835 return -EINVAL;
1836 }
1837 if (ops->vidioc_s_register)
1838 return ops->vidioc_s_register(file, fh, p);
1839 return -EINVAL;
1813#else 1840#else
1814 return -ENOTTY; 1841 return -ENOTTY;
1815#endif 1842#endif
@@ -1822,9 +1849,59 @@ static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops,
1822 1849
1823 p->ident = V4L2_IDENT_NONE; 1850 p->ident = V4L2_IDENT_NONE;
1824 p->revision = 0; 1851 p->revision = 0;
1852 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV)
1853 return -EINVAL;
1825 return ops->vidioc_g_chip_ident(file, fh, p); 1854 return ops->vidioc_g_chip_ident(file, fh, p);
1826} 1855}
1827 1856
1857static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
1858 struct file *file, void *fh, void *arg)
1859{
1860#ifdef CONFIG_VIDEO_ADV_DEBUG
1861 struct video_device *vfd = video_devdata(file);
1862 struct v4l2_dbg_chip_info *p = arg;
1863 struct v4l2_subdev *sd;
1864 int idx = 0;
1865
1866 switch (p->match.type) {
1867 case V4L2_CHIP_MATCH_BRIDGE:
1868 if (ops->vidioc_s_register)
1869 p->flags |= V4L2_CHIP_FL_WRITABLE;
1870 if (ops->vidioc_g_register)
1871 p->flags |= V4L2_CHIP_FL_READABLE;
1872 if (vfd->v4l2_dev)
1873 strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1874 else if (vfd->parent)
1875 strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name));
1876 else
1877 strlcpy(p->name, "bridge", sizeof(p->name));
1878 if (ops->vidioc_g_chip_info)
1879 return ops->vidioc_g_chip_info(file, fh, arg);
1880 if (p->match.addr)
1881 return -EINVAL;
1882 return 0;
1883
1884 case V4L2_CHIP_MATCH_SUBDEV:
1885 if (vfd->v4l2_dev == NULL)
1886 break;
1887 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) {
1888 if (p->match.addr != idx++)
1889 continue;
1890 if (sd->ops->core && sd->ops->core->s_register)
1891 p->flags |= V4L2_CHIP_FL_WRITABLE;
1892 if (sd->ops->core && sd->ops->core->g_register)
1893 p->flags |= V4L2_CHIP_FL_READABLE;
1894 strlcpy(p->name, sd->name, sizeof(p->name));
1895 return 0;
1896 }
1897 break;
1898 }
1899 return -EINVAL;
1900#else
1901 return -ENOTTY;
1902#endif
1903}
1904
1828static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, 1905static int v4l_dqevent(const struct v4l2_ioctl_ops *ops,
1829 struct file *file, void *fh, void *arg) 1906 struct file *file, void *fh, void *arg)
1830{ 1907{
@@ -1873,7 +1950,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
1873 return -EINVAL; 1950 return -EINVAL;
1874 if (ops->vidioc_enum_freq_bands) 1951 if (ops->vidioc_enum_freq_bands)
1875 return ops->vidioc_enum_freq_bands(file, fh, p); 1952 return ops->vidioc_enum_freq_bands(file, fh, p);
1876 if (ops->vidioc_g_tuner) { 1953 if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) {
1877 struct v4l2_tuner t = { 1954 struct v4l2_tuner t = {
1878 .index = p->tuner, 1955 .index = p->tuner,
1879 .type = type, 1956 .type = type,
@@ -1891,7 +1968,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
1891 V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB; 1968 V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB;
1892 return 0; 1969 return 0;
1893 } 1970 }
1894 if (ops->vidioc_g_modulator) { 1971 if (is_valid_ioctl(vfd, VIDIOC_G_MODULATOR)) {
1895 struct v4l2_modulator m = { 1972 struct v4l2_modulator m = {
1896 .index = p->tuner, 1973 .index = p->tuner,
1897 }; 1974 };
@@ -2028,10 +2105,6 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
2028 IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0), 2105 IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
2029 IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0), 2106 IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
2030 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO), 2107 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
2031 IOCTL_INFO_STD(VIDIOC_ENUM_DV_PRESETS, vidioc_enum_dv_presets, v4l_print_dv_enum_presets, 0),
2032 IOCTL_INFO_STD(VIDIOC_S_DV_PRESET, vidioc_s_dv_preset, v4l_print_dv_preset, INFO_FL_PRIO),
2033 IOCTL_INFO_STD(VIDIOC_G_DV_PRESET, vidioc_g_dv_preset, v4l_print_dv_preset, 0),
2034 IOCTL_INFO_STD(VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset, v4l_print_dv_preset, 0),
2035 IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO), 2108 IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
2036 IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0), 2109 IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
2037 IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0), 2110 IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
@@ -2043,6 +2116,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
2043 IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0), 2116 IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
2044 IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, type)), 2117 IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, type)),
2045 IOCTL_INFO_FNC(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0), 2118 IOCTL_INFO_FNC(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0),
2119 IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)),
2046}; 2120};
2047#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) 2121#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
2048 2122
@@ -2147,11 +2221,6 @@ static long __video_do_ioctl(struct file *file,
2147 } 2221 }
2148 2222
2149 write_only = _IOC_DIR(cmd) == _IOC_WRITE; 2223 write_only = _IOC_DIR(cmd) == _IOC_WRITE;
2150 if (write_only && debug > V4L2_DEBUG_IOCTL) {
2151 v4l_printk_ioctl(video_device_node_name(vfd), cmd);
2152 pr_cont(": ");
2153 info->debug(arg, write_only);
2154 }
2155 if (info->flags & INFO_FL_STD) { 2224 if (info->flags & INFO_FL_STD) {
2156 typedef int (*vidioc_op)(struct file *file, void *fh, void *p); 2225 typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
2157 const void *p = vfd->ioctl_ops; 2226 const void *p = vfd->ioctl_ops;
@@ -2170,16 +2239,10 @@ static long __video_do_ioctl(struct file *file,
2170 2239
2171done: 2240done:
2172 if (debug) { 2241 if (debug) {
2173 if (write_only && debug > V4L2_DEBUG_IOCTL) {
2174 if (ret < 0)
2175 printk(KERN_DEBUG "%s: error %ld\n",
2176 video_device_node_name(vfd), ret);
2177 return ret;
2178 }
2179 v4l_printk_ioctl(video_device_node_name(vfd), cmd); 2242 v4l_printk_ioctl(video_device_node_name(vfd), cmd);
2180 if (ret < 0) 2243 if (ret < 0)
2181 pr_cont(": error %ld\n", ret); 2244 pr_cont(": error %ld", ret);
2182 else if (debug == V4L2_DEBUG_IOCTL) 2245 if (debug == V4L2_DEBUG_IOCTL)
2183 pr_cont("\n"); 2246 pr_cont("\n");
2184 else if (_IOC_DIR(cmd) == _IOC_NONE) 2247 else if (_IOC_DIR(cmd) == _IOC_NONE)
2185 info->debug(arg, write_only); 2248 info->debug(arg, write_only);
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index da99cf727162..66f599fcb829 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -230,12 +230,15 @@ static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
230 dprintk("No input buffers available\n"); 230 dprintk("No input buffers available\n");
231 return; 231 return;
232 } 232 }
233 spin_lock_irqsave(&m2m_ctx->cap_q_ctx.rdy_spinlock, flags);
233 if (list_empty(&m2m_ctx->cap_q_ctx.rdy_queue)) { 234 if (list_empty(&m2m_ctx->cap_q_ctx.rdy_queue)) {
235 spin_unlock_irqrestore(&m2m_ctx->cap_q_ctx.rdy_spinlock, flags);
234 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags); 236 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags);
235 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job); 237 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
236 dprintk("No output buffers available\n"); 238 dprintk("No output buffers available\n");
237 return; 239 return;
238 } 240 }
241 spin_unlock_irqrestore(&m2m_ctx->cap_q_ctx.rdy_spinlock, flags);
239 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags); 242 spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags);
240 243
241 if (m2m_dev->m2m_ops->job_ready 244 if (m2m_dev->m2m_ops->job_ready
@@ -405,10 +408,35 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_streamon);
405int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, 408int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
406 enum v4l2_buf_type type) 409 enum v4l2_buf_type type)
407{ 410{
408 struct vb2_queue *vq; 411 struct v4l2_m2m_dev *m2m_dev;
412 struct v4l2_m2m_queue_ctx *q_ctx;
413 unsigned long flags_job, flags;
414 int ret;
409 415
410 vq = v4l2_m2m_get_vq(m2m_ctx, type); 416 q_ctx = get_queue_ctx(m2m_ctx, type);
411 return vb2_streamoff(vq, type); 417 ret = vb2_streamoff(&q_ctx->q, type);
418 if (ret)
419 return ret;
420
421 m2m_dev = m2m_ctx->m2m_dev;
422 spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
423 /* We should not be scheduled anymore, since we're dropping a queue. */
424 INIT_LIST_HEAD(&m2m_ctx->queue);
425 m2m_ctx->job_flags = 0;
426
427 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
428 /* Drop queue, since streamoff returns device to the same state as after
429 * calling reqbufs. */
430 INIT_LIST_HEAD(&q_ctx->rdy_queue);
431 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
432
433 if (m2m_dev->curr_ctx == m2m_ctx) {
434 m2m_dev->curr_ctx = NULL;
435 wake_up(&m2m_ctx->finished);
436 }
437 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
438
439 return 0;
412} 440}
413EXPORT_SYMBOL_GPL(v4l2_m2m_streamoff); 441EXPORT_SYMBOL_GPL(v4l2_m2m_streamoff);
414 442
diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
new file mode 100644
index 000000000000..aa59639d013c
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -0,0 +1,266 @@
1/*
2 * V4L2 OF binding parsing library
3 *
4 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 *
7 * Copyright (C) 2012 Renesas Electronics Corp.
8 * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 */
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/string.h>
18#include <linux/types.h>
19
20#include <media/v4l2-of.h>
21
22static void v4l2_of_parse_csi_bus(const struct device_node *node,
23 struct v4l2_of_endpoint *endpoint)
24{
25 struct v4l2_of_bus_mipi_csi2 *bus = &endpoint->bus.mipi_csi2;
26 u32 data_lanes[ARRAY_SIZE(bus->data_lanes)];
27 struct property *prop;
28 bool have_clk_lane = false;
29 unsigned int flags = 0;
30 u32 v;
31
32 prop = of_find_property(node, "data-lanes", NULL);
33 if (prop) {
34 const __be32 *lane = NULL;
35 int i;
36
37 for (i = 0; i < ARRAY_SIZE(data_lanes); i++) {
38 lane = of_prop_next_u32(prop, lane, &data_lanes[i]);
39 if (!lane)
40 break;
41 }
42 bus->num_data_lanes = i;
43 while (i--)
44 bus->data_lanes[i] = data_lanes[i];
45 }
46
47 if (!of_property_read_u32(node, "clock-lanes", &v)) {
48 bus->clock_lane = v;
49 have_clk_lane = true;
50 }
51
52 if (of_get_property(node, "clock-noncontinuous", &v))
53 flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
54 else if (have_clk_lane || bus->num_data_lanes > 0)
55 flags |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
56
57 bus->flags = flags;
58 endpoint->bus_type = V4L2_MBUS_CSI2;
59}
60
61static void v4l2_of_parse_parallel_bus(const struct device_node *node,
62 struct v4l2_of_endpoint *endpoint)
63{
64 struct v4l2_of_bus_parallel *bus = &endpoint->bus.parallel;
65 unsigned int flags = 0;
66 u32 v;
67
68 if (!of_property_read_u32(node, "hsync-active", &v))
69 flags |= v ? V4L2_MBUS_HSYNC_ACTIVE_HIGH :
70 V4L2_MBUS_HSYNC_ACTIVE_LOW;
71
72 if (!of_property_read_u32(node, "vsync-active", &v))
73 flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
74 V4L2_MBUS_VSYNC_ACTIVE_LOW;
75
76 if (!of_property_read_u32(node, "pclk-sample", &v))
77 flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
78 V4L2_MBUS_PCLK_SAMPLE_FALLING;
79
80 if (!of_property_read_u32(node, "field-even-active", &v))
81 flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
82 V4L2_MBUS_FIELD_EVEN_LOW;
83 if (flags)
84 endpoint->bus_type = V4L2_MBUS_PARALLEL;
85 else
86 endpoint->bus_type = V4L2_MBUS_BT656;
87
88 if (!of_property_read_u32(node, "data-active", &v))
89 flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
90 V4L2_MBUS_DATA_ACTIVE_LOW;
91
92 if (of_get_property(node, "slave-mode", &v))
93 flags |= V4L2_MBUS_SLAVE;
94 else
95 flags |= V4L2_MBUS_MASTER;
96
97 if (!of_property_read_u32(node, "bus-width", &v))
98 bus->bus_width = v;
99
100 if (!of_property_read_u32(node, "data-shift", &v))
101 bus->data_shift = v;
102
103 bus->flags = flags;
104
105}
106
107/**
108 * v4l2_of_parse_endpoint() - parse all endpoint node properties
109 * @node: pointer to endpoint device_node
110 * @endpoint: pointer to the V4L2 OF endpoint data structure
111 *
112 * All properties are optional. If none are found, we don't set any flags.
113 * This means the port has a static configuration and no properties have
114 * to be specified explicitly.
115 * If any properties that identify the bus as parallel are found and
116 * slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if we recognise
117 * the bus as serial CSI-2 and clock-noncontinuous isn't set, we set the
118 * V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag.
119 * The caller should hold a reference to @node.
120 */
121void v4l2_of_parse_endpoint(const struct device_node *node,
122 struct v4l2_of_endpoint *endpoint)
123{
124 struct device_node *port_node = of_get_parent(node);
125
126 memset(endpoint, 0, offsetof(struct v4l2_of_endpoint, head));
127
128 endpoint->local_node = node;
129 /*
130 * It doesn't matter whether the two calls below succeed.
131 * If they don't then the default value 0 is used.
132 */
133 of_property_read_u32(port_node, "reg", &endpoint->port);
134 of_property_read_u32(node, "reg", &endpoint->id);
135
136 v4l2_of_parse_csi_bus(node, endpoint);
137 /*
138 * Parse the parallel video bus properties only if none
139 * of the MIPI CSI-2 specific properties were found.
140 */
141 if (endpoint->bus.mipi_csi2.flags == 0)
142 v4l2_of_parse_parallel_bus(node, endpoint);
143
144 of_node_put(port_node);
145}
146EXPORT_SYMBOL(v4l2_of_parse_endpoint);
147
148/**
149 * v4l2_of_get_next_endpoint() - get next endpoint node
150 * @parent: pointer to the parent device node
151 * @prev: previous endpoint node, or NULL to get first
152 *
153 * Return: An 'endpoint' node pointer with refcount incremented. Refcount
154 * of the passed @prev node is not decremented, the caller have to use
155 * of_node_put() on it when done.
156 */
157struct device_node *v4l2_of_get_next_endpoint(const struct device_node *parent,
158 struct device_node *prev)
159{
160 struct device_node *endpoint;
161 struct device_node *port = NULL;
162
163 if (!parent)
164 return NULL;
165
166 if (!prev) {
167 struct device_node *node;
168 /*
169 * It's the first call, we have to find a port subnode
170 * within this node or within an optional 'ports' node.
171 */
172 node = of_get_child_by_name(parent, "ports");
173 if (node)
174 parent = node;
175
176 for_each_child_of_node(parent, node) {
177 if (!of_node_cmp(node->name, "port")) {
178 port = node;
179 break;
180 }
181 }
182 if (port) {
183 /* Found a port, get an endpoint. */
184 endpoint = of_get_next_child(port, NULL);
185 of_node_put(port);
186 } else {
187 endpoint = NULL;
188 }
189
190 if (!endpoint)
191 pr_err("%s(): no endpoint nodes specified for %s\n",
192 __func__, parent->full_name);
193 } else {
194 port = of_get_parent(prev);
195 if (!port)
196 /* Hm, has someone given us the root node ?... */
197 return NULL;
198
199 /* Avoid dropping prev node refcount to 0. */
200 of_node_get(prev);
201 endpoint = of_get_next_child(port, prev);
202 if (endpoint) {
203 of_node_put(port);
204 return endpoint;
205 }
206
207 /* No more endpoints under this port, try the next one. */
208 do {
209 port = of_get_next_child(parent, port);
210 if (!port)
211 return NULL;
212 } while (of_node_cmp(port->name, "port"));
213
214 /* Pick up the first endpoint in this port. */
215 endpoint = of_get_next_child(port, NULL);
216 of_node_put(port);
217 }
218
219 return endpoint;
220}
221EXPORT_SYMBOL(v4l2_of_get_next_endpoint);
222
223/**
224 * v4l2_of_get_remote_port_parent() - get remote port's parent node
225 * @node: pointer to a local endpoint device_node
226 *
227 * Return: Remote device node associated with remote endpoint node linked
228 * to @node. Use of_node_put() on it when done.
229 */
230struct device_node *v4l2_of_get_remote_port_parent(
231 const struct device_node *node)
232{
233 struct device_node *np;
234 unsigned int depth;
235
236 /* Get remote endpoint node. */
237 np = of_parse_phandle(node, "remote-endpoint", 0);
238
239 /* Walk 3 levels up only if there is 'ports' node. */
240 for (depth = 3; depth && np; depth--) {
241 np = of_get_next_parent(np);
242 if (depth == 2 && of_node_cmp(np->name, "ports"))
243 break;
244 }
245 return np;
246}
247EXPORT_SYMBOL(v4l2_of_get_remote_port_parent);
248
249/**
250 * v4l2_of_get_remote_port() - get remote port node
251 * @node: pointer to a local endpoint device_node
252 *
253 * Return: Remote port node associated with remote endpoint node linked
254 * to @node. Use of_node_put() on it when done.
255 */
256struct device_node *v4l2_of_get_remote_port(const struct device_node *node)
257{
258 struct device_node *np;
259
260 /* Get remote endpoint node. */
261 np = of_parse_phandle(node, "remote-endpoint", 0);
262 if (!np)
263 return NULL;
264 return of_get_parent(np);
265}
266EXPORT_SYMBOL(v4l2_of_get_remote_port);
diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c
index 3a43ba0959bf..67f572c3fba2 100644
--- a/drivers/media/v4l2-core/videobuf-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf-dma-contig.c
@@ -27,7 +27,6 @@ struct videobuf_dma_contig_memory {
27 u32 magic; 27 u32 magic;
28 void *vaddr; 28 void *vaddr;
29 dma_addr_t dma_handle; 29 dma_addr_t dma_handle;
30 bool cached;
31 unsigned long size; 30 unsigned long size;
32}; 31};
33 32
@@ -43,26 +42,8 @@ static int __videobuf_dc_alloc(struct device *dev,
43 unsigned long size, gfp_t flags) 42 unsigned long size, gfp_t flags)
44{ 43{
45 mem->size = size; 44 mem->size = size;
46 if (mem->cached) { 45 mem->vaddr = dma_alloc_coherent(dev, mem->size,
47 mem->vaddr = alloc_pages_exact(mem->size, flags | GFP_DMA); 46 &mem->dma_handle, flags);
48 if (mem->vaddr) {
49 int err;
50
51 mem->dma_handle = dma_map_single(dev, mem->vaddr,
52 mem->size,
53 DMA_FROM_DEVICE);
54 err = dma_mapping_error(dev, mem->dma_handle);
55 if (err) {
56 dev_err(dev, "dma_map_single failed\n");
57
58 free_pages_exact(mem->vaddr, mem->size);
59 mem->vaddr = NULL;
60 return err;
61 }
62 }
63 } else
64 mem->vaddr = dma_alloc_coherent(dev, mem->size,
65 &mem->dma_handle, flags);
66 47
67 if (!mem->vaddr) { 48 if (!mem->vaddr) {
68 dev_err(dev, "memory alloc size %ld failed\n", mem->size); 49 dev_err(dev, "memory alloc size %ld failed\n", mem->size);
@@ -77,14 +58,7 @@ static int __videobuf_dc_alloc(struct device *dev,
77static void __videobuf_dc_free(struct device *dev, 58static void __videobuf_dc_free(struct device *dev,
78 struct videobuf_dma_contig_memory *mem) 59 struct videobuf_dma_contig_memory *mem)
79{ 60{
80 if (mem->cached) { 61 dma_free_coherent(dev, mem->size, mem->vaddr, mem->dma_handle);
81 if (!mem->vaddr)
82 return;
83 dma_unmap_single(dev, mem->dma_handle, mem->size,
84 DMA_FROM_DEVICE);
85 free_pages_exact(mem->vaddr, mem->size);
86 } else
87 dma_free_coherent(dev, mem->size, mem->vaddr, mem->dma_handle);
88 62
89 mem->vaddr = NULL; 63 mem->vaddr = NULL;
90} 64}
@@ -234,7 +208,7 @@ out_up:
234 return ret; 208 return ret;
235} 209}
236 210
237static struct videobuf_buffer *__videobuf_alloc_vb(size_t size, bool cached) 211static struct videobuf_buffer *__videobuf_alloc(size_t size)
238{ 212{
239 struct videobuf_dma_contig_memory *mem; 213 struct videobuf_dma_contig_memory *mem;
240 struct videobuf_buffer *vb; 214 struct videobuf_buffer *vb;
@@ -244,22 +218,11 @@ static struct videobuf_buffer *__videobuf_alloc_vb(size_t size, bool cached)
244 vb->priv = ((char *)vb) + size; 218 vb->priv = ((char *)vb) + size;
245 mem = vb->priv; 219 mem = vb->priv;
246 mem->magic = MAGIC_DC_MEM; 220 mem->magic = MAGIC_DC_MEM;
247 mem->cached = cached;
248 } 221 }
249 222
250 return vb; 223 return vb;
251} 224}
252 225
253static struct videobuf_buffer *__videobuf_alloc_uncached(size_t size)
254{
255 return __videobuf_alloc_vb(size, false);
256}
257
258static struct videobuf_buffer *__videobuf_alloc_cached(size_t size)
259{
260 return __videobuf_alloc_vb(size, true);
261}
262
263static void *__videobuf_to_vaddr(struct videobuf_buffer *buf) 226static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
264{ 227{
265 struct videobuf_dma_contig_memory *mem = buf->priv; 228 struct videobuf_dma_contig_memory *mem = buf->priv;
@@ -310,19 +273,6 @@ static int __videobuf_iolock(struct videobuf_queue *q,
310 return 0; 273 return 0;
311} 274}
312 275
313static int __videobuf_sync(struct videobuf_queue *q,
314 struct videobuf_buffer *buf)
315{
316 struct videobuf_dma_contig_memory *mem = buf->priv;
317 BUG_ON(!mem);
318 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
319
320 dma_sync_single_for_cpu(q->dev, mem->dma_handle, mem->size,
321 DMA_FROM_DEVICE);
322
323 return 0;
324}
325
326static int __videobuf_mmap_mapper(struct videobuf_queue *q, 276static int __videobuf_mmap_mapper(struct videobuf_queue *q,
327 struct videobuf_buffer *buf, 277 struct videobuf_buffer *buf,
328 struct vm_area_struct *vma) 278 struct vm_area_struct *vma)
@@ -331,8 +281,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
331 struct videobuf_mapping *map; 281 struct videobuf_mapping *map;
332 int retval; 282 int retval;
333 unsigned long size; 283 unsigned long size;
334 unsigned long pos, start = vma->vm_start;
335 struct page *page;
336 284
337 dev_dbg(q->dev, "%s\n", __func__); 285 dev_dbg(q->dev, "%s\n", __func__);
338 286
@@ -359,43 +307,16 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
359 size = vma->vm_end - vma->vm_start; 307 size = vma->vm_end - vma->vm_start;
360 size = (size < mem->size) ? size : mem->size; 308 size = (size < mem->size) ? size : mem->size;
361 309
362 if (!mem->cached) { 310 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
363 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 311 retval = remap_pfn_range(vma, vma->vm_start,
364 retval = remap_pfn_range(vma, vma->vm_start, 312 mem->dma_handle >> PAGE_SHIFT,
365 mem->dma_handle >> PAGE_SHIFT,
366 size, vma->vm_page_prot); 313 size, vma->vm_page_prot);
367 if (retval) { 314 if (retval) {
368 dev_err(q->dev, "mmap: remap failed with error %d. ", 315 dev_err(q->dev, "mmap: remap failed with error %d. ",
369 retval); 316 retval);
370 dma_free_coherent(q->dev, mem->size, 317 dma_free_coherent(q->dev, mem->size,
371 mem->vaddr, mem->dma_handle); 318 mem->vaddr, mem->dma_handle);
372 goto error; 319 goto error;
373 }
374 } else {
375 pos = (unsigned long)mem->vaddr;
376
377 while (size > 0) {
378 page = virt_to_page((void *)pos);
379 if (NULL == page) {
380 dev_err(q->dev, "mmap: virt_to_page failed\n");
381 __videobuf_dc_free(q->dev, mem);
382 goto error;
383 }
384 retval = vm_insert_page(vma, start, page);
385 if (retval) {
386 dev_err(q->dev, "mmap: insert failed with error %d\n",
387 retval);
388 __videobuf_dc_free(q->dev, mem);
389 goto error;
390 }
391 start += PAGE_SIZE;
392 pos += PAGE_SIZE;
393
394 if (size > PAGE_SIZE)
395 size -= PAGE_SIZE;
396 else
397 size = 0;
398 }
399 } 320 }
400 321
401 vma->vm_ops = &videobuf_vm_ops; 322 vma->vm_ops = &videobuf_vm_ops;
@@ -417,17 +338,8 @@ error:
417 338
418static struct videobuf_qtype_ops qops = { 339static struct videobuf_qtype_ops qops = {
419 .magic = MAGIC_QTYPE_OPS, 340 .magic = MAGIC_QTYPE_OPS,
420 .alloc_vb = __videobuf_alloc_uncached, 341 .alloc_vb = __videobuf_alloc,
421 .iolock = __videobuf_iolock,
422 .mmap_mapper = __videobuf_mmap_mapper,
423 .vaddr = __videobuf_to_vaddr,
424};
425
426static struct videobuf_qtype_ops qops_cached = {
427 .magic = MAGIC_QTYPE_OPS,
428 .alloc_vb = __videobuf_alloc_cached,
429 .iolock = __videobuf_iolock, 342 .iolock = __videobuf_iolock,
430 .sync = __videobuf_sync,
431 .mmap_mapper = __videobuf_mmap_mapper, 343 .mmap_mapper = __videobuf_mmap_mapper,
432 .vaddr = __videobuf_to_vaddr, 344 .vaddr = __videobuf_to_vaddr,
433}; 345};
@@ -447,20 +359,6 @@ void videobuf_queue_dma_contig_init(struct videobuf_queue *q,
447} 359}
448EXPORT_SYMBOL_GPL(videobuf_queue_dma_contig_init); 360EXPORT_SYMBOL_GPL(videobuf_queue_dma_contig_init);
449 361
450void videobuf_queue_dma_contig_init_cached(struct videobuf_queue *q,
451 const struct videobuf_queue_ops *ops,
452 struct device *dev,
453 spinlock_t *irqlock,
454 enum v4l2_buf_type type,
455 enum v4l2_field field,
456 unsigned int msize,
457 void *priv, struct mutex *ext_lock)
458{
459 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
460 priv, &qops_cached, ext_lock);
461}
462EXPORT_SYMBOL_GPL(videobuf_queue_dma_contig_init_cached);
463
464dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf) 362dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf)
465{ 363{
466 struct videobuf_dma_contig_memory *mem = buf->priv; 364 struct videobuf_dma_contig_memory *mem = buf->priv;
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index db1235dcb328..7d833eefaf4e 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -54,10 +54,15 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
54 void *mem_priv; 54 void *mem_priv;
55 int plane; 55 int plane;
56 56
57 /* Allocate memory for all planes in this buffer */ 57 /*
58 * Allocate memory for all planes in this buffer
59 * NOTE: mmapped areas should be page aligned
60 */
58 for (plane = 0; plane < vb->num_planes; ++plane) { 61 for (plane = 0; plane < vb->num_planes; ++plane) {
62 unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
63
59 mem_priv = call_memop(q, alloc, q->alloc_ctx[plane], 64 mem_priv = call_memop(q, alloc, q->alloc_ctx[plane],
60 q->plane_sizes[plane]); 65 size, q->gfp_flags);
61 if (IS_ERR_OR_NULL(mem_priv)) 66 if (IS_ERR_OR_NULL(mem_priv))
62 goto free; 67 goto free;
63 68
@@ -403,7 +408,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
403 * Clear any buffer state related flags. 408 * Clear any buffer state related flags.
404 */ 409 */
405 b->flags &= ~V4L2_BUFFER_MASK_FLAGS; 410 b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
406 b->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 411 b->flags |= q->timestamp_type;
407 412
408 switch (vb->state) { 413 switch (vb->state) {
409 case VB2_BUF_STATE_QUEUED: 414 case VB2_BUF_STATE_QUEUED:
@@ -855,7 +860,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
855 return; 860 return;
856 861
857 dprintk(4, "Done processing on buffer %d, state: %d\n", 862 dprintk(4, "Done processing on buffer %d, state: %d\n",
858 vb->v4l2_buf.index, vb->state); 863 vb->v4l2_buf.index, state);
859 864
860 /* sync buffers */ 865 /* sync buffers */
861 for (plane = 0; plane < vb->num_planes; ++plane) 866 for (plane = 0; plane < vb->num_planes; ++plane)
@@ -1852,6 +1857,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
1852 struct vb2_buffer *vb; 1857 struct vb2_buffer *vb;
1853 unsigned int buffer, plane; 1858 unsigned int buffer, plane;
1854 int ret; 1859 int ret;
1860 unsigned long length;
1855 1861
1856 if (q->memory != V4L2_MEMORY_MMAP) { 1862 if (q->memory != V4L2_MEMORY_MMAP) {
1857 dprintk(1, "Queue is not currently set up for mmap\n"); 1863 dprintk(1, "Queue is not currently set up for mmap\n");
@@ -1886,6 +1892,18 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
1886 1892
1887 vb = q->bufs[buffer]; 1893 vb = q->bufs[buffer];
1888 1894
1895 /*
1896 * MMAP requires page_aligned buffers.
1897 * The buffer length was page_aligned at __vb2_buf_mem_alloc(),
1898 * so, we need to do the same here.
1899 */
1900 length = PAGE_ALIGN(vb->v4l2_planes[plane].length);
1901 if (length < (vma->vm_end - vma->vm_start)) {
1902 dprintk(1,
1903 "MMAP invalid, as it would overflow buffer length\n");
1904 return -EINVAL;
1905 }
1906
1889 ret = call_memop(q, mmap, vb->planes[plane].mem_priv, vma); 1907 ret = call_memop(q, mmap, vb->planes[plane].mem_priv, vma);
1890 if (ret) 1908 if (ret)
1891 return ret; 1909 return ret;
@@ -2039,9 +2057,13 @@ int vb2_queue_init(struct vb2_queue *q)
2039 WARN_ON(!q->type) || 2057 WARN_ON(!q->type) ||
2040 WARN_ON(!q->io_modes) || 2058 WARN_ON(!q->io_modes) ||
2041 WARN_ON(!q->ops->queue_setup) || 2059 WARN_ON(!q->ops->queue_setup) ||
2042 WARN_ON(!q->ops->buf_queue)) 2060 WARN_ON(!q->ops->buf_queue) ||
2061 WARN_ON(q->timestamp_type & ~V4L2_BUF_FLAG_TIMESTAMP_MASK))
2043 return -EINVAL; 2062 return -EINVAL;
2044 2063
2064 /* Warn that the driver should choose an appropriate timestamp type */
2065 WARN_ON(q->timestamp_type == V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
2066
2045 INIT_LIST_HEAD(&q->queued_list); 2067 INIT_LIST_HEAD(&q->queued_list);
2046 INIT_LIST_HEAD(&q->done_list); 2068 INIT_LIST_HEAD(&q->done_list);
2047 spin_lock_init(&q->done_lock); 2069 spin_lock_init(&q->done_lock);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 10beaee7f0ae..fd56f2563201 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -152,7 +152,7 @@ static void vb2_dc_put(void *buf_priv)
152 kfree(buf); 152 kfree(buf);
153} 153}
154 154
155static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) 155static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags)
156{ 156{
157 struct vb2_dc_conf *conf = alloc_ctx; 157 struct vb2_dc_conf *conf = alloc_ctx;
158 struct device *dev = conf->dev; 158 struct device *dev = conf->dev;
@@ -162,10 +162,8 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size)
162 if (!buf) 162 if (!buf)
163 return ERR_PTR(-ENOMEM); 163 return ERR_PTR(-ENOMEM);
164 164
165 /* align image size to PAGE_SIZE */ 165 buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr,
166 size = PAGE_ALIGN(size); 166 GFP_KERNEL | gfp_flags);
167
168 buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, GFP_KERNEL);
169 if (!buf->vaddr) { 167 if (!buf->vaddr) {
170 dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); 168 dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size);
171 kfree(buf); 169 kfree(buf);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 25c3b360e1ad..16ae3dcc7e29 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -21,6 +21,15 @@
21#include <media/videobuf2-memops.h> 21#include <media/videobuf2-memops.h>
22#include <media/videobuf2-dma-sg.h> 22#include <media/videobuf2-dma-sg.h>
23 23
24static int debug;
25module_param(debug, int, 0644);
26
27#define dprintk(level, fmt, arg...) \
28 do { \
29 if (debug >= level) \
30 printk(KERN_DEBUG "vb2-dma-sg: " fmt, ## arg); \
31 } while (0)
32
24struct vb2_dma_sg_buf { 33struct vb2_dma_sg_buf {
25 void *vaddr; 34 void *vaddr;
26 struct page **pages; 35 struct page **pages;
@@ -33,7 +42,7 @@ struct vb2_dma_sg_buf {
33 42
34static void vb2_dma_sg_put(void *buf_priv); 43static void vb2_dma_sg_put(void *buf_priv);
35 44
36static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size) 45static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags)
37{ 46{
38 struct vb2_dma_sg_buf *buf; 47 struct vb2_dma_sg_buf *buf;
39 int i; 48 int i;
@@ -46,7 +55,8 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size)
46 buf->write = 0; 55 buf->write = 0;
47 buf->offset = 0; 56 buf->offset = 0;
48 buf->sg_desc.size = size; 57 buf->sg_desc.size = size;
49 buf->sg_desc.num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 58 /* size is already page aligned */
59 buf->sg_desc.num_pages = size >> PAGE_SHIFT;
50 60
51 buf->sg_desc.sglist = vzalloc(buf->sg_desc.num_pages * 61 buf->sg_desc.sglist = vzalloc(buf->sg_desc.num_pages *
52 sizeof(*buf->sg_desc.sglist)); 62 sizeof(*buf->sg_desc.sglist));
@@ -60,7 +70,8 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size)
60 goto fail_pages_array_alloc; 70 goto fail_pages_array_alloc;
61 71
62 for (i = 0; i < buf->sg_desc.num_pages; ++i) { 72 for (i = 0; i < buf->sg_desc.num_pages; ++i) {
63 buf->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN); 73 buf->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO |
74 __GFP_NOWARN | gfp_flags);
64 if (NULL == buf->pages[i]) 75 if (NULL == buf->pages[i])
65 goto fail_pages_alloc; 76 goto fail_pages_alloc;
66 sg_set_page(&buf->sg_desc.sglist[i], 77 sg_set_page(&buf->sg_desc.sglist[i],
@@ -73,7 +84,7 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size)
73 84
74 atomic_inc(&buf->refcount); 85 atomic_inc(&buf->refcount);
75 86
76 printk(KERN_DEBUG "%s: Allocated buffer of %d pages\n", 87 dprintk(1, "%s: Allocated buffer of %d pages\n",
77 __func__, buf->sg_desc.num_pages); 88 __func__, buf->sg_desc.num_pages);
78 return buf; 89 return buf;
79 90
@@ -96,7 +107,7 @@ static void vb2_dma_sg_put(void *buf_priv)
96 int i = buf->sg_desc.num_pages; 107 int i = buf->sg_desc.num_pages;
97 108
98 if (atomic_dec_and_test(&buf->refcount)) { 109 if (atomic_dec_and_test(&buf->refcount)) {
99 printk(KERN_DEBUG "%s: Freeing buffer of %d pages\n", __func__, 110 dprintk(1, "%s: Freeing buffer of %d pages\n", __func__,
100 buf->sg_desc.num_pages); 111 buf->sg_desc.num_pages);
101 if (buf->vaddr) 112 if (buf->vaddr)
102 vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages); 113 vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages);
@@ -162,7 +173,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
162 return buf; 173 return buf;
163 174
164userptr_fail_get_user_pages: 175userptr_fail_get_user_pages:
165 printk(KERN_DEBUG "get_user_pages requested/got: %d/%d]\n", 176 dprintk(1, "get_user_pages requested/got: %d/%d]\n",
166 num_pages_from_user, buf->sg_desc.num_pages); 177 num_pages_from_user, buf->sg_desc.num_pages);
167 while (--num_pages_from_user >= 0) 178 while (--num_pages_from_user >= 0)
168 put_page(buf->pages[num_pages_from_user]); 179 put_page(buf->pages[num_pages_from_user]);
@@ -185,7 +196,7 @@ static void vb2_dma_sg_put_userptr(void *buf_priv)
185 struct vb2_dma_sg_buf *buf = buf_priv; 196 struct vb2_dma_sg_buf *buf = buf_priv;
186 int i = buf->sg_desc.num_pages; 197 int i = buf->sg_desc.num_pages;
187 198
188 printk(KERN_DEBUG "%s: Releasing userspace buffer of %d pages\n", 199 dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
189 __func__, buf->sg_desc.num_pages); 200 __func__, buf->sg_desc.num_pages);
190 if (buf->vaddr) 201 if (buf->vaddr)
191 vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages); 202 vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages);
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index a47fd4f589a1..313d9771b2bc 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -35,11 +35,11 @@ struct vb2_vmalloc_buf {
35 35
36static void vb2_vmalloc_put(void *buf_priv); 36static void vb2_vmalloc_put(void *buf_priv);
37 37
38static void *vb2_vmalloc_alloc(void *alloc_ctx, unsigned long size) 38static void *vb2_vmalloc_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags)
39{ 39{
40 struct vb2_vmalloc_buf *buf; 40 struct vb2_vmalloc_buf *buf;
41 41
42 buf = kzalloc(sizeof(*buf), GFP_KERNEL); 42 buf = kzalloc(sizeof(*buf), GFP_KERNEL | gfp_flags);
43 if (!buf) 43 if (!buf)
44 return NULL; 44 return NULL;
45 45
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 321d3ef05006..1733081eb873 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -382,6 +382,7 @@ struct device_node *of_get_next_parent(struct device_node *node)
382 raw_spin_unlock_irqrestore(&devtree_lock, flags); 382 raw_spin_unlock_irqrestore(&devtree_lock, flags);
383 return parent; 383 return parent;
384} 384}
385EXPORT_SYMBOL(of_get_next_parent);
385 386
386/** 387/**
387 * of_get_next_child - Iterate a node childs 388 * of_get_next_child - Iterate a node childs
diff --git a/drivers/staging/media/as102/Makefile b/drivers/staging/media/as102/Makefile
index d8dfb757f1e2..8916d8a909bc 100644
--- a/drivers/staging/media/as102/Makefile
+++ b/drivers/staging/media/as102/Makefile
@@ -3,4 +3,4 @@ dvb-as102-objs := as102_drv.o as102_fw.o as10x_cmd.o as10x_cmd_stream.o \
3 3
4obj-$(CONFIG_DVB_AS102) += dvb-as102.o 4obj-$(CONFIG_DVB_AS102) += dvb-as102.o
5 5
6EXTRA_CFLAGS += -Idrivers/media/dvb-core 6ccflags-y += -Idrivers/media/dvb-core
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
index 92853539cc0a..05673ed45ce4 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -1859,5 +1859,5 @@ void vpfe_ipipe_cleanup(struct vpfe_ipipe_device *ipipe,
1859 iounmap(ipipe->isp5_base_addr); 1859 iounmap(ipipe->isp5_base_addr);
1860 res = platform_get_resource(pdev, IORESOURCE_MEM, 4); 1860 res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
1861 if (res) 1861 if (res)
1862 release_mem_region(res->start, res->end - res->start + 1); 1862 release_mem_region(res->start, resource_size(res));
1863} 1863}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index c8cae51d3d00..b2f4ef84f3db 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -1065,7 +1065,6 @@ vpfe_ipipeif_cleanup(struct vpfe_ipipeif_device *ipipeif,
1065 iounmap(ipipeif->ipipeif_base_addr); 1065 iounmap(ipipeif->ipipeif_base_addr);
1066 res = platform_get_resource(pdev, IORESOURCE_MEM, 3); 1066 res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
1067 if (res) 1067 if (res)
1068 release_mem_region(res->start, 1068 release_mem_region(res->start, resource_size(res));
1069 res->end - res->start + 1);
1070 1069
1071} 1070}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index 6d4a93c556e4..5829360f74c9 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1953,7 +1953,7 @@ static void isif_remove(struct vpfe_isif_device *isif,
1953 res = platform_get_resource(pdev, IORESOURCE_MEM, i); 1953 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
1954 if (res) 1954 if (res)
1955 release_mem_region(res->start, 1955 release_mem_region(res->start,
1956 res->end - res->start + 1); 1956 resource_size(res));
1957 i++; 1957 i++;
1958 } 1958 }
1959} 1959}
@@ -2003,7 +2003,7 @@ int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
2003 status = -ENOENT; 2003 status = -ENOENT;
2004 goto fail_nobase_res; 2004 goto fail_nobase_res;
2005 } 2005 }
2006 res_len = res->end - res->start + 1; 2006 res_len = resource_size(res);
2007 res = request_mem_region(res->start, res_len, res->name); 2007 res = request_mem_region(res->start, res_len, res->name);
2008 if (!res) { 2008 if (!res) {
2009 status = -EBUSY; 2009 status = -EBUSY;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 9cb0262b9b33..126f84c4cb64 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1995,5 +1995,5 @@ vpfe_resizer_cleanup(struct vpfe_resizer_device *vpfe_rsz,
1995 res = platform_get_resource(pdev, IORESOURCE_MEM, 5); 1995 res = platform_get_resource(pdev, IORESOURCE_MEM, 5);
1996 if (res) 1996 if (res)
1997 release_mem_region(res->start, 1997 release_mem_region(res->start,
1998 res->end - res->start + 1); 1998 resource_size(res));
1999} 1999}
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 7b351717bcbb..b88e1ddce229 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -243,7 +243,7 @@ static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
243 243
244 vpfe_dev->clks[i] = 244 vpfe_dev->clks[i] =
245 clk_get(vpfe_dev->pdev, vpfe_cfg->clocks[i]); 245 clk_get(vpfe_dev->pdev, vpfe_cfg->clocks[i]);
246 if (vpfe_dev->clks[i] == NULL) { 246 if (IS_ERR(vpfe_dev->clks[i])) {
247 v4l2_err(vpfe_dev->pdev->driver, 247 v4l2_err(vpfe_dev->pdev->driver,
248 "Failed to get clock %s\n", 248 "Failed to get clock %s\n",
249 vpfe_cfg->clocks[i]); 249 vpfe_cfg->clocks[i]);
@@ -264,7 +264,7 @@ static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
264 return 0; 264 return 0;
265out: 265out:
266 for (i = 0; i < vpfe_cfg->num_clocks; i++) 266 for (i = 0; i < vpfe_cfg->num_clocks; i++)
267 if (vpfe_dev->clks[i]) { 267 if (!IS_ERR(vpfe_dev->clks[i])) {
268 clk_disable_unprepare(vpfe_dev->clks[i]); 268 clk_disable_unprepare(vpfe_dev->clks[i]);
269 clk_put(vpfe_dev->clks[i]); 269 clk_put(vpfe_dev->clks[i]);
270 } 270 }
@@ -719,22 +719,4 @@ static struct platform_driver vpfe_driver = {
719 .remove = vpfe_remove, 719 .remove = vpfe_remove,
720}; 720};
721 721
722/** 722module_platform_driver(vpfe_driver);
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_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index c91d356c13df..ba913f1d955b 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -924,7 +924,7 @@ static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
924 * 924 *
925 * Return 0 on success, error code otherwise 925 * Return 0 on success, error code otherwise
926 */ 926 */
927static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id *std_id) 927static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id std_id)
928{ 928{
929 struct vpfe_video_device *video = video_drvdata(file); 929 struct vpfe_video_device *video = video_drvdata(file);
930 struct vpfe_device *vpfe_dev = video->vpfe_dev; 930 struct vpfe_device *vpfe_dev = video->vpfe_dev;
@@ -945,13 +945,13 @@ static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
945 goto unlock_out; 945 goto unlock_out;
946 } 946 }
947 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id, 947 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
948 core, s_std, *std_id); 948 core, s_std, std_id);
949 if (ret < 0) { 949 if (ret < 0) {
950 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to set standard\n"); 950 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to set standard\n");
951 video->stdid = V4L2_STD_UNKNOWN; 951 video->stdid = V4L2_STD_UNKNOWN;
952 goto unlock_out; 952 goto unlock_out;
953 } 953 }
954 video->stdid = *std_id; 954 video->stdid = std_id;
955unlock_out: 955unlock_out:
956 mutex_unlock(&video->lock); 956 mutex_unlock(&video->lock);
957 return ret; 957 return ret;
@@ -1016,12 +1016,12 @@ vpfe_query_dv_timings(struct file *file, void *fh,
1016} 1016}
1017 1017
1018/* 1018/*
1019 * vpfe_s_dv_timings() - set dv_preset on external subdev 1019 * vpfe_s_dv_timings() - set dv_timings on external subdev
1020 * @file: file pointer 1020 * @file: file pointer
1021 * @priv: void pointer 1021 * @priv: void pointer
1022 * @timings: pointer to v4l2_dv_timings structure 1022 * @timings: pointer to v4l2_dv_timings structure
1023 * 1023 *
1024 * set dv_timings pointed by preset on external subdev through 1024 * set dv_timings pointed by timings on external subdev through
1025 * v4l2_device_call_until_err, this configures amplifier also 1025 * v4l2_device_call_until_err, this configures amplifier also
1026 * 1026 *
1027 * Return 0 on success, error code otherwise 1027 * Return 0 on success, error code otherwise
@@ -1042,12 +1042,12 @@ vpfe_s_dv_timings(struct file *file, void *fh,
1042} 1042}
1043 1043
1044/* 1044/*
1045 * vpfe_g_dv_timings() - get dv_preset which is set on external subdev 1045 * vpfe_g_dv_timings() - get dv_timings which is set on external subdev
1046 * @file: file pointer 1046 * @file: file pointer
1047 * @priv: void pointer 1047 * @priv: void pointer
1048 * @timings: pointer to v4l2_dv_timings structure 1048 * @timings: pointer to v4l2_dv_timings structure
1049 * 1049 *
1050 * get dv_preset which is set on external subdev through 1050 * get dv_timings which is set on external subdev through
1051 * v4l2_subdev_call 1051 * v4l2_subdev_call
1052 * 1052 *
1053 * Return 0 on success, error code otherwise 1053 * Return 0 on success, error code otherwise
@@ -1423,7 +1423,7 @@ static int vpfe_dqbuf(struct file *file, void *priv,
1423} 1423}
1424 1424
1425/* 1425/*
1426 * vpfe_streamon() - get dv_preset which is set on external subdev 1426 * vpfe_streamon() - start streaming
1427 * @file: file pointer 1427 * @file: file pointer
1428 * @priv: void pointer 1428 * @priv: void pointer
1429 * @buf_type: enum v4l2_buf_type 1429 * @buf_type: enum v4l2_buf_type
@@ -1472,7 +1472,7 @@ static int vpfe_streamon(struct file *file, void *priv,
1472} 1472}
1473 1473
1474/* 1474/*
1475 * vpfe_streamoff() - get dv_preset which is set on external subdev 1475 * vpfe_streamoff() - stop streaming
1476 * @file: file pointer 1476 * @file: file pointer
1477 * @priv: void pointer 1477 * @priv: void pointer
1478 * @buf_type: enum v4l2_buf_type 1478 * @buf_type: enum v4l2_buf_type
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c
index e33b7f55d84e..c32e0acde4f4 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c
@@ -26,6 +26,7 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <media/v4l2-dev.h> 27#include <media/v4l2-dev.h>
28#include <media/v4l2-ioctl.h> 28#include <media/v4l2-ioctl.h>
29#include <media/v4l2-common.h>
29#include <media/videobuf2-dma-contig.h> 30#include <media/videobuf2-dma-contig.h>
30 31
31#include "dt3155v4l.h" 32#include "dt3155v4l.h"
@@ -341,7 +342,7 @@ dt3155_irq_handler_even(int irq, void *dev_id)
341 342
342 spin_lock(&ipd->lock); 343 spin_lock(&ipd->lock);
343 if (ipd->curr_buf) { 344 if (ipd->curr_buf) {
344 do_gettimeofday(&ipd->curr_buf->v4l2_buf.timestamp); 345 v4l2_get_timestamp(&ipd->curr_buf->v4l2_buf.timestamp);
345 ipd->curr_buf->v4l2_buf.sequence = (ipd->field_count) >> 1; 346 ipd->curr_buf->v4l2_buf.sequence = (ipd->field_count) >> 1;
346 vb2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE); 347 vb2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE);
347 } 348 }
@@ -390,6 +391,7 @@ dt3155_open(struct file *filp)
390 goto err_alloc_queue; 391 goto err_alloc_queue;
391 } 392 }
392 pd->q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 393 pd->q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
394 pd->q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
393 pd->q->io_modes = VB2_READ | VB2_MMAP; 395 pd->q->io_modes = VB2_READ | VB2_MMAP;
394 pd->q->ops = &q_ops; 396 pd->q->ops = &q_ops;
395 pd->q->mem_ops = &vb2_dma_contig_memops; 397 pd->q->mem_ops = &vb2_dma_contig_memops;
@@ -398,7 +400,7 @@ dt3155_open(struct file *filp)
398 pd->field_count = 0; 400 pd->field_count = 0;
399 ret = vb2_queue_init(pd->q); 401 ret = vb2_queue_init(pd->q);
400 if (ret < 0) 402 if (ret < 0)
401 return ret; 403 goto err_request_irq;
402 INIT_LIST_HEAD(&pd->dmaq); 404 INIT_LIST_HEAD(&pd->dmaq);
403 spin_lock_init(&pd->lock); 405 spin_lock_init(&pd->lock);
404 /* disable all irqs, clear all irq flags */ 406 /* disable all irqs, clear all irq flags */
@@ -410,6 +412,7 @@ dt3155_open(struct file *filp)
410 goto err_request_irq; 412 goto err_request_irq;
411 } 413 }
412 pd->users++; 414 pd->users++;
415 mutex_unlock(&pd->mux);
413 return 0; /* success */ 416 return 0; /* success */
414err_request_irq: 417err_request_irq:
415 kfree(pd->q); 418 kfree(pd->q);
@@ -612,9 +615,9 @@ dt3155_ioc_g_std(struct file *filp, void *p, v4l2_std_id *norm)
612} 615}
613 616
614static int 617static int
615dt3155_ioc_s_std(struct file *filp, void *p, v4l2_std_id *norm) 618dt3155_ioc_s_std(struct file *filp, void *p, v4l2_std_id norm)
616{ 619{
617 if (*norm & DT3155_CURRENT_NORM) 620 if (norm & DT3155_CURRENT_NORM)
618 return 0; 621 return 0;
619 return -EINVAL; 622 return -EINVAL;
620} 623}
diff --git a/drivers/staging/media/go7007/Kconfig b/drivers/staging/media/go7007/Kconfig
index 7dfb2815b9ec..04bd0fba7b1f 100644
--- a/drivers/staging/media/go7007/Kconfig
+++ b/drivers/staging/media/go7007/Kconfig
@@ -1,20 +1,25 @@
1config VIDEO_GO7007 1config VIDEO_GO7007
2 tristate "WIS GO7007 MPEG encoder support" 2 tristate "WIS GO7007 MPEG encoder support"
3 depends on VIDEO_DEV && PCI && I2C 3 depends on VIDEO_DEV && I2C
4 depends on SND 4 depends on SND && USB
5 select VIDEOBUF_DMA_SG 5 select VIDEOBUF2_VMALLOC
6 depends on RC_CORE
7 select VIDEO_TUNER 6 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 7 select CYPRESS_FIRMWARE
9 select SND_PCM 8 select SND_PCM
10 select CRC32 9 select VIDEO_SONY_BTF_MPX if MEDIA_SUBDRV_AUTOSELECT
10 select VIDEO_SAA711X if MEDIA_SUBDRV_AUTOSELECT
11 select VIDEO_TW2804 if MEDIA_SUBDRV_AUTOSELECT
12 select VIDEO_TW9903 if MEDIA_SUBDRV_AUTOSELECT
13 select VIDEO_TW9906 if MEDIA_SUBDRV_AUTOSELECT
14 select VIDEO_OV7640 if MEDIA_SUBDRV_AUTOSELECT
15 select VIDEO_UDA1342 if MEDIA_SUBDRV_AUTOSELECT
11 default N 16 default N
12 ---help--- 17 ---help---
13 This is a video4linux driver for the WIS GO7007 MPEG 18 This is a video4linux driver for the WIS GO7007 MPEG
14 encoder chip. 19 encoder chip.
15 20
16 To compile this driver as a module, choose M here: the 21 To compile this driver as a module, choose M here: the
17 module will be called go7007 22 module will be called go7007.
18 23
19config VIDEO_GO7007_USB 24config VIDEO_GO7007_USB
20 tristate "WIS GO7007 USB support" 25 tristate "WIS GO7007 USB support"
@@ -25,85 +30,25 @@ config VIDEO_GO7007_USB
25 encoder chip over USB. 30 encoder chip over USB.
26 31
27 To compile this driver as a module, choose M here: the 32 To compile this driver as a module, choose M here: the
28 module will be called go7007-usb 33 module will be called go7007-usb.
29 34
30config VIDEO_GO7007_USB_S2250_BOARD 35config VIDEO_GO7007_LOADER
31 tristate "Sensoray 2250/2251 support" 36 tristate "WIS GO7007 Loader support"
32 depends on VIDEO_GO7007_USB && DVB_USB
33 default N
34 ---help---
35 This is a video4linux driver for the Sensoray 2250/2251 device.
36
37 To compile this driver as a module, choose M here: the
38 module will be called s2250
39
40config VIDEO_GO7007_OV7640
41 tristate "OV7640 subdev support"
42 depends on VIDEO_GO7007
43 default N
44 ---help---
45 This is a video4linux driver for the OV7640 sub-device.
46
47 To compile this driver as a module, choose M here: the
48 module will be called wis-ov7640
49
50config VIDEO_GO7007_SAA7113
51 tristate "SAA7113 subdev support"
52 depends on VIDEO_GO7007
53 default N
54 ---help---
55 This is a video4linux driver for the SAA7113 sub-device.
56
57 To compile this driver as a module, choose M here: the
58 module will be called wis-saa7113
59
60config VIDEO_GO7007_SAA7115
61 tristate "SAA7115 subdev support"
62 depends on VIDEO_GO7007
63 default N
64 ---help---
65 This is a video4linux driver for the SAA7115 sub-device.
66
67 To compile this driver as a module, choose M here: the
68 module will be called wis-saa7115
69
70config VIDEO_GO7007_TW9903
71 tristate "TW9903 subdev support"
72 depends on VIDEO_GO7007
73 default N
74 ---help---
75 This is a video4linux driver for the TW9903 sub-device.
76
77 To compile this driver as a module, choose M here: the
78 module will be called wis-tw9903
79
80config VIDEO_GO7007_UDA1342
81 tristate "UDA1342 subdev support"
82 depends on VIDEO_GO7007
83 default N
84 ---help---
85 This is a video4linux driver for the UDA1342 sub-device.
86
87 To compile this driver as a module, choose M here: the
88 module will be called wis-uda1342
89
90config VIDEO_GO7007_SONY_TUNER
91 tristate "Sony tuner subdev support"
92 depends on VIDEO_GO7007 37 depends on VIDEO_GO7007
93 default N 38 default y
94 ---help--- 39 ---help---
95 This is a video4linux driver for the Sony Tuner sub-device. 40 This is a go7007 firmware loader driver for the WIS GO7007
41 MPEG encoder chip over USB.
96 42
97 To compile this driver as a module, choose M here: the 43 To compile this driver as a module, choose M here: the
98 module will be called wis-sony-tuner 44 module will be called go7007-loader.
99 45
100config VIDEO_GO7007_TW2804 46config VIDEO_GO7007_USB_S2250_BOARD
101 tristate "TW2804 subdev support" 47 tristate "Sensoray 2250/2251 support"
102 depends on VIDEO_GO7007 48 depends on VIDEO_GO7007_USB && USB
103 default N 49 default N
104 ---help--- 50 ---help---
105 This is a video4linux driver for the TW2804 sub-device. 51 This is a video4linux driver for the Sensoray 2250/2251 device.
106 52
107 To compile this driver as a module, choose M here: the 53 To compile this driver as a module, choose M here: the
108 module will be called wis-tw2804 54 module will be called s2250.
109
diff --git a/drivers/staging/media/go7007/Makefile b/drivers/staging/media/go7007/Makefile
index 3fdbef5306a0..9c6ad4a263ec 100644
--- a/drivers/staging/media/go7007/Makefile
+++ b/drivers/staging/media/go7007/Makefile
@@ -1,18 +1,7 @@
1#obj-m += go7007.o go7007-usb.o snd-go7007.o wis-saa7115.o wis-tw9903.o \
2 wis-uda1342.o wis-sony-tuner.o wis-saa7113.o wis-ov7640.o \
3 wis-tw2804.o
4
5
6obj-$(CONFIG_VIDEO_GO7007) += go7007.o 1obj-$(CONFIG_VIDEO_GO7007) += go7007.o
7obj-$(CONFIG_VIDEO_GO7007_USB) += go7007-usb.o 2obj-$(CONFIG_VIDEO_GO7007_USB) += go7007-usb.o
8obj-$(CONFIG_VIDEO_GO7007_USB_S2250_BOARD) += s2250.o s2250-loader.o 3obj-$(CONFIG_VIDEO_GO7007_LOADER) += go7007-loader.o
9obj-$(CONFIG_VIDEO_GO7007_SAA7113) += wis-saa7113.o 4obj-$(CONFIG_VIDEO_GO7007_USB_S2250_BOARD) += s2250.o
10obj-$(CONFIG_VIDEO_GO7007_OV7640) += wis-ov7640.o
11obj-$(CONFIG_VIDEO_GO7007_SAA7115) += wis-saa7115.o
12obj-$(CONFIG_VIDEO_GO7007_TW9903) += wis-tw9903.o
13obj-$(CONFIG_VIDEO_GO7007_UDA1342) += wis-uda1342.o
14obj-$(CONFIG_VIDEO_GO7007_SONY_TUNER) += wis-sony-tuner.o
15obj-$(CONFIG_VIDEO_GO7007_TW2804) += wis-tw2804.o
16 5
17go7007-y := go7007-v4l2.o go7007-driver.o go7007-i2c.o go7007-fw.o \ 6go7007-y := go7007-v4l2.o go7007-driver.o go7007-i2c.o go7007-fw.o \
18 snd-go7007.o 7 snd-go7007.o
@@ -21,10 +10,6 @@ s2250-y := s2250-board.o
21 10
22# Uncomment when the saa7134 patches get into upstream 11# Uncomment when the saa7134 patches get into upstream
23#obj-$(CONFIG_VIDEO_SAA7134) += saa7134-go7007.o 12#obj-$(CONFIG_VIDEO_SAA7134) += saa7134-go7007.o
24#ccflags-$(CONFIG_VIDEO_SAA7134:m=y) += -Idrivers/media/video/saa7134 -DSAA7134_MPEG_GO7007=3 13#ccflags-$(CONFIG_VIDEO_SAA7134:m=y) += -Idrivers/media/pci/saa7134
25
26# S2250 needs cypress ezusb loader from dvb-usb
27ccflags-$(CONFIG_VIDEO_GO7007_USB_S2250_BOARD:m=y) += -Idrivers/media/usb/dvb-usb
28 14
29ccflags-y += -Idrivers/media/dvb-frontends 15ccflags-$(CONFIG_VIDEO_GO7007_LOADER:m=y) += -Idrivers/media/common
30ccflags-y += -Idrivers/media/dvb-core
diff --git a/drivers/staging/media/go7007/README b/drivers/staging/media/go7007/README
index aeba1324a9c5..3af0d9062811 100644
--- a/drivers/staging/media/go7007/README
+++ b/drivers/staging/media/go7007/README
@@ -1,11 +1,137 @@
1Todo: 1Todo:
2 - checkpatch.pl cleanups 2 - create an API for motion detection
3 - sparse cleanups 3 - let s2250-board use i2c subdevs as well instead of hardcoding
4 - lots of little modules, should be merged together 4 support for the i2c devices.
5 and added to the build. 5 - when the driver is moved out of staging, support for saa7134-go7007
6 - testing? 6 should be added to the saa7134 driver. The patch for that is
7 - handle churn in v4l layer. 7 included below.
8 8
9Please send patches to Greg Kroah-Hartman <greg@linuxfoundation.org> and Cc: Ross 9Patch for saa7134:
10Cohen <rcohen@snurgle.org> as well.
11 10
11diff --git a/drivers/media/pci/saa7134/saa7134-cards.c b/drivers/media/pci/saa7134/saa7134-cards.c
12index dc68cf1..9a53794 100644
13--- a/drivers/media/pci/saa7134/saa7134-cards.c
14+++ b/drivers/media/pci/saa7134/saa7134-cards.c
15@@ -5790,6 +5790,29 @@ struct saa7134_board saa7134_boards[] = {
16 .gpio = 0x6010000,
17 } },
18 },
19+ [SAA7134_BOARD_WIS_VOYAGER] = {
20+ .name = "WIS Voyager or compatible",
21+ .audio_clock = 0x00200000,
22+ .tuner_type = TUNER_PHILIPS_TDA8290,
23+ .radio_type = UNSET,
24+ .tuner_addr = ADDR_UNSET,
25+ .radio_addr = ADDR_UNSET,
26+ .mpeg = SAA7134_MPEG_GO7007,
27+ .inputs = { {
28+ .name = name_comp1,
29+ .vmux = 0,
30+ .amux = LINE2,
31+ }, {
32+ .name = name_tv,
33+ .vmux = 3,
34+ .amux = TV,
35+ .tv = 1,
36+ }, {
37+ .name = name_svideo,
38+ .vmux = 6,
39+ .amux = LINE1,
40+ } },
41+ },
42
43 };
44
45@@ -7037,6 +7060,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
46 .subdevice = 0x0911,
47 .driver_data = SAA7134_BOARD_SENSORAY811_911,
48 }, {
49+ .vendor = PCI_VENDOR_ID_PHILIPS,
50+ .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
51+ .subvendor = 0x1905, /* WIS */
52+ .subdevice = 0x7007,
53+ .driver_data = SAA7134_BOARD_WIS_VOYAGER,
54+ }, {
55 /* --- boards without eeprom + subsystem ID --- */
56 .vendor = PCI_VENDOR_ID_PHILIPS,
57 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
58diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
59index 8fd24e7..0a849ea 100644
60--- a/drivers/media/pci/saa7134/saa7134-core.c
61+++ b/drivers/media/pci/saa7134/saa7134-core.c
62@@ -156,6 +156,8 @@ static void request_module_async(struct work_struct *work){
63 request_module("saa7134-empress");
64 if (card_is_dvb(dev))
65 request_module("saa7134-dvb");
66+ if (card_is_go7007(dev))
67+ request_module("saa7134-go7007");
68 if (alsa) {
69 if (dev->pci->device != PCI_DEVICE_ID_PHILIPS_SAA7130)
70 request_module("saa7134-alsa");
71@@ -557,8 +559,12 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
72 saa7134_irq_vbi_done(dev,status);
73
74 if ((report & SAA7134_IRQ_REPORT_DONE_RA2) &&
75- card_has_mpeg(dev))
76- saa7134_irq_ts_done(dev,status);
77+ card_has_mpeg(dev)) {
78+ if (dev->mops->irq_ts_done != NULL)
79+ dev->mops->irq_ts_done(dev, status);
80+ else
81+ saa7134_irq_ts_done(dev, status);
82+ }
83
84 if (report & SAA7134_IRQ_REPORT_GPIO16) {
85 switch (dev->has_remote) {
86diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
87index 62169dd..5fad39a 100644
88--- a/drivers/media/pci/saa7134/saa7134.h
89+++ b/drivers/media/pci/saa7134/saa7134.h
90@@ -334,6 +334,7 @@ struct saa7134_card_ir {
91 #define SAA7134_BOARD_KWORLD_PC150U 189
92 #define SAA7134_BOARD_ASUSTeK_PS3_100 190
93 #define SAA7134_BOARD_HAWELL_HW_9004V1 191
94+#define SAA7134_BOARD_WIS_VOYAGER 192
95
96 #define SAA7134_MAXBOARDS 32
97 #define SAA7134_INPUT_MAX 8
98@@ -364,6 +365,7 @@ enum saa7134_mpeg_type {
99 SAA7134_MPEG_UNUSED,
100 SAA7134_MPEG_EMPRESS,
101 SAA7134_MPEG_DVB,
102+ SAA7134_MPEG_GO7007,
103 };
104
105 enum saa7134_mpeg_ts_type {
106@@ -403,6 +405,7 @@ struct saa7134_board {
107 #define card_has_radio(dev) (NULL != saa7134_boards[dev->board].radio.name)
108 #define card_is_empress(dev) (SAA7134_MPEG_EMPRESS == saa7134_boards[dev->board].mpeg)
109 #define card_is_dvb(dev) (SAA7134_MPEG_DVB == saa7134_boards[dev->board].mpeg)
110+#define card_is_go7007(dev) (SAA7134_MPEG_GO7007 == saa7134_boards[dev->board].mpeg)
111 #define card_has_mpeg(dev) (SAA7134_MPEG_UNUSED != saa7134_boards[dev->board].mpeg)
112 #define card(dev) (saa7134_boards[dev->board])
113 #define card_in(dev,n) (saa7134_boards[dev->board].inputs[n])
114@@ -535,6 +538,8 @@ struct saa7134_mpeg_ops {
115 int (*init)(struct saa7134_dev *dev);
116 int (*fini)(struct saa7134_dev *dev);
117 void (*signal_change)(struct saa7134_dev *dev);
118+ void (*irq_ts_done)(struct saa7134_dev *dev,
119+ unsigned long status);
120 };
121
122 /* global device status */
123diff --git a/drivers/staging/media/go7007/Makefile b/drivers/staging/media/go7007/Makefile
124index 9c6ad4a..1b23689 100644
125--- a/drivers/staging/media/go7007/Makefile
126+++ b/drivers/staging/media/go7007/Makefile
127@@ -8,8 +8,7 @@ go7007-y := go7007-v4l2.o go7007-driver.o go7007-i2c.o go7007-fw.o \
128
129 s2250-y := s2250-board.o
130
131-# Uncomment when the saa7134 patches get into upstream
132-#obj-$(CONFIG_VIDEO_SAA7134) += saa7134-go7007.o
133-#ccflags-$(CONFIG_VIDEO_SAA7134:m=y) += -Idrivers/media/pci/saa7134
134+obj-$(CONFIG_VIDEO_SAA7134) += saa7134-go7007.o
135+ccflags-$(CONFIG_VIDEO_SAA7134:m=y) += -Idrivers/media/pci/saa7134
136
137 ccflags-$(CONFIG_VIDEO_GO7007_LOADER:m=y) += -Idrivers/media/common
diff --git a/drivers/staging/media/go7007/go7007-driver.c b/drivers/staging/media/go7007/go7007-driver.c
index 66950916df23..a5ca99d7c0b2 100644
--- a/drivers/staging/media/go7007/go7007-driver.c
+++ b/drivers/staging/media/go7007/go7007-driver.c
@@ -35,7 +35,6 @@
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36 36
37#include "go7007-priv.h" 37#include "go7007-priv.h"
38#include "wis-i2c.h"
39 38
40/* 39/*
41 * Wait for an interrupt to be delivered from the GO7007SB and return 40 * Wait for an interrupt to be delivered from the GO7007SB and return
@@ -91,43 +90,43 @@ EXPORT_SYMBOL(go7007_read_addr);
91static int go7007_load_encoder(struct go7007 *go) 90static int go7007_load_encoder(struct go7007 *go)
92{ 91{
93 const struct firmware *fw_entry; 92 const struct firmware *fw_entry;
94 char fw_name[] = "go7007fw.bin"; 93 char fw_name[] = "go7007/go7007fw.bin";
95 void *bounce; 94 void *bounce;
96 int fw_len, rv = 0; 95 int fw_len, rv = 0;
97 u16 intr_val, intr_data; 96 u16 intr_val, intr_data;
98 97
99 if (request_firmware(&fw_entry, fw_name, go->dev)) { 98 if (go->boot_fw == NULL) {
100 v4l2_err(go, "unable to load firmware from file " 99 if (request_firmware(&fw_entry, fw_name, go->dev)) {
101 "\"%s\"\n", fw_name); 100 v4l2_err(go, "unable to load firmware from file \"%s\"\n", fw_name);
102 return -1; 101 return -1;
103 } 102 }
104 if (fw_entry->size < 16 || memcmp(fw_entry->data, "WISGO7007FW", 11)) { 103 if (fw_entry->size < 16 || memcmp(fw_entry->data, "WISGO7007FW", 11)) {
105 v4l2_err(go, "file \"%s\" does not appear to be " 104 v4l2_err(go, "file \"%s\" does not appear to be go7007 firmware\n", fw_name);
106 "go7007 firmware\n", fw_name); 105 release_firmware(fw_entry);
107 release_firmware(fw_entry); 106 return -1;
108 return -1; 107 }
109 } 108 fw_len = fw_entry->size - 16;
110 fw_len = fw_entry->size - 16; 109 bounce = kmemdup(fw_entry->data + 16, fw_len, GFP_KERNEL);
111 bounce = kmemdup(fw_entry->data + 16, fw_len, GFP_KERNEL); 110 if (bounce == NULL) {
112 if (bounce == NULL) { 111 v4l2_err(go, "unable to allocate %d bytes for firmware transfer\n", fw_len);
113 v4l2_err(go, "unable to allocate %d bytes for " 112 release_firmware(fw_entry);
114 "firmware transfer\n", fw_len); 113 return -1;
114 }
115 release_firmware(fw_entry); 115 release_firmware(fw_entry);
116 return -1; 116 go->boot_fw_len = fw_len;
117 go->boot_fw = bounce;
117 } 118 }
118 release_firmware(fw_entry);
119 if (go7007_interface_reset(go) < 0 || 119 if (go7007_interface_reset(go) < 0 ||
120 go7007_send_firmware(go, bounce, fw_len) < 0 || 120 go7007_send_firmware(go, go->boot_fw, go->boot_fw_len) < 0 ||
121 go7007_read_interrupt(go, &intr_val, &intr_data) < 0 || 121 go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
122 (intr_val & ~0x1) != 0x5a5a) { 122 (intr_val & ~0x1) != 0x5a5a) {
123 v4l2_err(go, "error transferring firmware\n"); 123 v4l2_err(go, "error transferring firmware\n");
124 rv = -1; 124 rv = -1;
125 } 125 }
126 kfree(bounce);
127 return rv; 126 return rv;
128} 127}
129 128
130MODULE_FIRMWARE("go7007fw.bin"); 129MODULE_FIRMWARE("go7007/go7007fw.bin");
131 130
132/* 131/*
133 * Boot the encoder and register the I2C adapter if requested. Do the 132 * Boot the encoder and register the I2C adapter if requested. Do the
@@ -167,15 +166,24 @@ static int go7007_init_encoder(struct go7007 *go)
167 go7007_write_addr(go, 0x1000, 0x0811); 166 go7007_write_addr(go, 0x1000, 0x0811);
168 go7007_write_addr(go, 0x1000, 0x0c11); 167 go7007_write_addr(go, 0x1000, 0x0c11);
169 } 168 }
170 if (go->board_id == GO7007_BOARDID_MATRIX_REV) { 169 switch (go->board_id) {
170 case GO7007_BOARDID_MATRIX_REV:
171 /* Set GPIO pin 0 to be an output (audio clock control) */ 171 /* Set GPIO pin 0 to be an output (audio clock control) */
172 go7007_write_addr(go, 0x3c82, 0x0001); 172 go7007_write_addr(go, 0x3c82, 0x0001);
173 go7007_write_addr(go, 0x3c80, 0x00fe); 173 go7007_write_addr(go, 0x3c80, 0x00fe);
174 } 174 break;
175 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) { 175 case GO7007_BOARDID_ADLINK_MPG24:
176 /* set GPIO5 to be an output, currently low */ 176 /* set GPIO5 to be an output, currently low */
177 go7007_write_addr(go, 0x3c82, 0x0000); 177 go7007_write_addr(go, 0x3c82, 0x0000);
178 go7007_write_addr(go, 0x3c80, 0x00df); 178 go7007_write_addr(go, 0x3c80, 0x00df);
179 break;
180 case GO7007_BOARDID_ADS_USBAV_709:
181 /* GPIO pin 0: audio clock control */
182 /* pin 2: TW9906 reset */
183 /* pin 3: capture LED */
184 go7007_write_addr(go, 0x3c82, 0x000d);
185 go7007_write_addr(go, 0x3c80, 0x00f2);
186 break;
179 } 187 }
180 return 0; 188 return 0;
181} 189}
@@ -196,18 +204,54 @@ int go7007_reset_encoder(struct go7007 *go)
196/* 204/*
197 * Attempt to instantiate an I2C client by ID, probably loading a module. 205 * Attempt to instantiate an I2C client by ID, probably loading a module.
198 */ 206 */
199static int init_i2c_module(struct i2c_adapter *adapter, const char *type, 207static int init_i2c_module(struct i2c_adapter *adapter, const struct go_i2c *const i2c)
200 int addr)
201{ 208{
202 struct go7007 *go = i2c_get_adapdata(adapter); 209 struct go7007 *go = i2c_get_adapdata(adapter);
203 struct v4l2_device *v4l2_dev = &go->v4l2_dev; 210 struct v4l2_device *v4l2_dev = &go->v4l2_dev;
204 211 struct v4l2_subdev *sd;
205 if (v4l2_i2c_new_subdev(v4l2_dev, adapter, type, addr, NULL)) 212 struct i2c_board_info info;
213
214 memset(&info, 0, sizeof(info));
215 strlcpy(info.type, i2c->type, sizeof(info.type));
216 info.addr = i2c->addr;
217 info.flags = i2c->flags;
218
219 sd = v4l2_i2c_new_subdev_board(v4l2_dev, adapter, &info, NULL);
220 if (sd) {
221 if (i2c->is_video)
222 go->sd_video = sd;
223 if (i2c->is_audio)
224 go->sd_audio = sd;
206 return 0; 225 return 0;
226 }
207 227
208 dev_info(&adapter->dev, 228 printk(KERN_INFO "go7007: probing for module i2c:%s failed\n", i2c->type);
209 "go7007: probing for module i2c:%s failed\n", type); 229 return -EINVAL;
210 return -1; 230}
231
232/*
233 * Detach and unregister the encoder. The go7007 struct won't be freed
234 * until v4l2 finishes releasing its resources and all associated fds are
235 * closed by applications.
236 */
237static void go7007_remove(struct v4l2_device *v4l2_dev)
238{
239 struct go7007 *go = container_of(v4l2_dev, struct go7007, v4l2_dev);
240
241 v4l2_device_unregister(v4l2_dev);
242 if (go->hpi_ops->release)
243 go->hpi_ops->release(go);
244 if (go->i2c_adapter_online) {
245 if (i2c_del_adapter(&go->i2c_adapter) == 0)
246 go->i2c_adapter_online = 0;
247 else
248 v4l2_err(&go->v4l2_dev,
249 "error removing I2C adapter!\n");
250 }
251
252 kfree(go->boot_fw);
253 go7007_v4l2_remove(go);
254 kfree(go);
211} 255}
212 256
213/* 257/*
@@ -218,38 +262,63 @@ static int init_i2c_module(struct i2c_adapter *adapter, const char *type,
218 * 262 *
219 * Must NOT be called with the hw_lock held. 263 * Must NOT be called with the hw_lock held.
220 */ 264 */
221int go7007_register_encoder(struct go7007 *go) 265int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs)
222{ 266{
223 int i, ret; 267 int i, ret;
224 268
225 dev_info(go->dev, "go7007: registering new %s\n", go->name); 269 dev_info(go->dev, "go7007: registering new %s\n", go->name);
226 270
271 go->v4l2_dev.release = go7007_remove;
272 ret = v4l2_device_register(go->dev, &go->v4l2_dev);
273 if (ret < 0)
274 return ret;
275
227 mutex_lock(&go->hw_lock); 276 mutex_lock(&go->hw_lock);
228 ret = go7007_init_encoder(go); 277 ret = go7007_init_encoder(go);
229 mutex_unlock(&go->hw_lock); 278 mutex_unlock(&go->hw_lock);
230 if (ret < 0) 279 if (ret < 0)
231 return -1; 280 return ret;
232 281
233 /* v4l2 init must happen before i2c subdevs */ 282 ret = go7007_v4l2_ctrl_init(go);
234 ret = go7007_v4l2_init(go);
235 if (ret < 0) 283 if (ret < 0)
236 return ret; 284 return ret;
237 285
238 if (!go->i2c_adapter_online && 286 if (!go->i2c_adapter_online &&
239 go->board_info->flags & GO7007_BOARD_USE_ONBOARD_I2C) { 287 go->board_info->flags & GO7007_BOARD_USE_ONBOARD_I2C) {
240 if (go7007_i2c_init(go) < 0) 288 ret = go7007_i2c_init(go);
241 return -1; 289 if (ret < 0)
290 return ret;
242 go->i2c_adapter_online = 1; 291 go->i2c_adapter_online = 1;
243 } 292 }
244 if (go->i2c_adapter_online) { 293 if (go->i2c_adapter_online) {
245 for (i = 0; i < go->board_info->num_i2c_devs; ++i) 294 if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) {
246 init_i2c_module(&go->i2c_adapter, 295 /* Reset the TW9906 */
247 go->board_info->i2c_devs[i].type, 296 go7007_write_addr(go, 0x3c82, 0x0009);
248 go->board_info->i2c_devs[i].addr); 297 msleep(50);
298 go7007_write_addr(go, 0x3c82, 0x000d);
299 }
300 for (i = 0; i < num_i2c_devs; ++i)
301 init_i2c_module(&go->i2c_adapter, &go->board_info->i2c_devs[i]);
302
303 if (go->tuner_type >= 0) {
304 struct tuner_setup setup = {
305 .addr = ADDR_UNSET,
306 .type = go->tuner_type,
307 .mode_mask = T_ANALOG_TV,
308 };
309
310 v4l2_device_call_all(&go->v4l2_dev, 0, tuner,
311 s_type_addr, &setup);
312 }
249 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) 313 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
250 i2c_clients_command(&go->i2c_adapter, 314 v4l2_subdev_call(go->sd_video, video, s_routing,
251 DECODER_SET_CHANNEL, &go->channel_number); 315 0, 0, go->channel_number + 1);
252 } 316 }
317
318 ret = go7007_v4l2_init(go);
319 if (ret < 0)
320 return ret;
321
253 if (go->board_info->flags & GO7007_BOARD_HAS_AUDIO) { 322 if (go->board_info->flags & GO7007_BOARD_HAS_AUDIO) {
254 go->audio_enabled = 1; 323 go->audio_enabled = 1;
255 go7007_snd_init(go); 324 go7007_snd_init(go);
@@ -309,48 +378,54 @@ start_error:
309/* 378/*
310 * Store a byte in the current video buffer, if there is one. 379 * Store a byte in the current video buffer, if there is one.
311 */ 380 */
312static inline void store_byte(struct go7007_buffer *gobuf, u8 byte) 381static inline void store_byte(struct go7007_buffer *vb, u8 byte)
313{ 382{
314 if (gobuf != NULL && gobuf->bytesused < GO7007_BUF_SIZE) { 383 if (vb && vb->vb.v4l2_planes[0].bytesused < GO7007_BUF_SIZE) {
315 unsigned int pgidx = gobuf->offset >> PAGE_SHIFT; 384 u8 *ptr = vb2_plane_vaddr(&vb->vb, 0);
316 unsigned int pgoff = gobuf->offset & ~PAGE_MASK;
317 385
318 *((u8 *)page_address(gobuf->pages[pgidx]) + pgoff) = byte; 386 ptr[vb->vb.v4l2_planes[0].bytesused++] = byte;
319 ++gobuf->offset;
320 ++gobuf->bytesused;
321 } 387 }
322} 388}
323 389
324/* 390/*
325 * Deliver the last video buffer and get a new one to start writing to. 391 * Deliver the last video buffer and get a new one to start writing to.
326 */ 392 */
327static void frame_boundary(struct go7007 *go) 393static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buffer *vb)
328{ 394{
329 struct go7007_buffer *gobuf; 395 struct go7007_buffer *vb_tmp = NULL;
396 u32 *bytesused = &vb->vb.v4l2_planes[0].bytesused;
330 int i; 397 int i;
331 398
332 if (go->active_buf) { 399 if (vb) {
333 if (go->active_buf->modet_active) { 400 if (vb->modet_active) {
334 if (go->active_buf->bytesused + 216 < GO7007_BUF_SIZE) { 401 if (*bytesused + 216 < GO7007_BUF_SIZE) {
335 for (i = 0; i < 216; ++i) 402 for (i = 0; i < 216; ++i)
336 store_byte(go->active_buf, 403 store_byte(vb, go->active_map[i]);
337 go->active_map[i]); 404 *bytesused -= 216;
338 go->active_buf->bytesused -= 216;
339 } else 405 } else
340 go->active_buf->modet_active = 0; 406 vb->modet_active = 0;
341 } 407 }
342 go->active_buf->state = BUF_STATE_DONE; 408 vb->vb.v4l2_buf.sequence = go->next_seq++;
343 wake_up_interruptible(&go->frame_waitq); 409 v4l2_get_timestamp(&vb->vb.v4l2_buf.timestamp);
344 go->active_buf = NULL; 410 vb_tmp = vb;
411 spin_lock(&go->spinlock);
412 list_del(&vb->list);
413 if (list_empty(&go->vidq_active))
414 vb = NULL;
415 else
416 vb = list_first_entry(&go->vidq_active, struct go7007_buffer, list);
417 go->active_buf = vb;
418 spin_unlock(&go->spinlock);
419 vb2_buffer_done(&vb_tmp->vb, VB2_BUF_STATE_DONE);
420 return vb;
345 } 421 }
346 list_for_each_entry(gobuf, &go->stream, stream) 422 spin_lock(&go->spinlock);
347 if (gobuf->state == BUF_STATE_QUEUED) { 423 if (!list_empty(&go->vidq_active))
348 gobuf->seq = go->next_seq; 424 vb = go->active_buf =
349 do_gettimeofday(&gobuf->timestamp); 425 list_first_entry(&go->vidq_active, struct go7007_buffer, list);
350 go->active_buf = gobuf; 426 spin_unlock(&go->spinlock);
351 break; 427 go->next_seq++;
352 } 428 return vb;
353 ++go->next_seq;
354} 429}
355 430
356static void write_bitmap_word(struct go7007 *go) 431static void write_bitmap_word(struct go7007 *go)
@@ -374,30 +449,30 @@ static void write_bitmap_word(struct go7007 *go)
374 */ 449 */
375void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length) 450void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
376{ 451{
377 int i, seq_start_code = -1, frame_start_code = -1; 452 struct go7007_buffer *vb = go->active_buf;
378 453 int i, seq_start_code = -1, gop_start_code = -1, frame_start_code = -1;
379 spin_lock(&go->spinlock);
380 454
381 switch (go->format) { 455 switch (go->format) {
382 case GO7007_FORMAT_MPEG4: 456 case V4L2_PIX_FMT_MPEG4:
383 seq_start_code = 0xB0; 457 seq_start_code = 0xB0;
458 gop_start_code = 0xB3;
384 frame_start_code = 0xB6; 459 frame_start_code = 0xB6;
385 break; 460 break;
386 case GO7007_FORMAT_MPEG1: 461 case V4L2_PIX_FMT_MPEG1:
387 case GO7007_FORMAT_MPEG2: 462 case V4L2_PIX_FMT_MPEG2:
388 seq_start_code = 0xB3; 463 seq_start_code = 0xB3;
464 gop_start_code = 0xB8;
389 frame_start_code = 0x00; 465 frame_start_code = 0x00;
390 break; 466 break;
391 } 467 }
392 468
393 for (i = 0; i < length; ++i) { 469 for (i = 0; i < length; ++i) {
394 if (go->active_buf != NULL && 470 if (vb && vb->vb.v4l2_planes[0].bytesused >= GO7007_BUF_SIZE - 3) {
395 go->active_buf->bytesused >= GO7007_BUF_SIZE - 3) {
396 v4l2_info(&go->v4l2_dev, "dropping oversized frame\n"); 471 v4l2_info(&go->v4l2_dev, "dropping oversized frame\n");
397 go->active_buf->offset -= go->active_buf->bytesused; 472 vb->vb.v4l2_planes[0].bytesused = 0;
398 go->active_buf->bytesused = 0; 473 vb->frame_offset = 0;
399 go->active_buf->modet_active = 0; 474 vb->modet_active = 0;
400 go->active_buf = NULL; 475 vb = go->active_buf = NULL;
401 } 476 }
402 477
403 switch (go->state) { 478 switch (go->state) {
@@ -410,7 +485,7 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
410 go->state = STATE_FF; 485 go->state = STATE_FF;
411 break; 486 break;
412 default: 487 default:
413 store_byte(go->active_buf, buf[i]); 488 store_byte(vb, buf[i]);
414 break; 489 break;
415 } 490 }
416 break; 491 break;
@@ -420,12 +495,12 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
420 go->state = STATE_00_00; 495 go->state = STATE_00_00;
421 break; 496 break;
422 case 0xFF: 497 case 0xFF:
423 store_byte(go->active_buf, 0x00); 498 store_byte(vb, 0x00);
424 go->state = STATE_FF; 499 go->state = STATE_FF;
425 break; 500 break;
426 default: 501 default:
427 store_byte(go->active_buf, 0x00); 502 store_byte(vb, 0x00);
428 store_byte(go->active_buf, buf[i]); 503 store_byte(vb, buf[i]);
429 go->state = STATE_DATA; 504 go->state = STATE_DATA;
430 break; 505 break;
431 } 506 }
@@ -433,21 +508,21 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
433 case STATE_00_00: 508 case STATE_00_00:
434 switch (buf[i]) { 509 switch (buf[i]) {
435 case 0x00: 510 case 0x00:
436 store_byte(go->active_buf, 0x00); 511 store_byte(vb, 0x00);
437 /* go->state remains STATE_00_00 */ 512 /* go->state remains STATE_00_00 */
438 break; 513 break;
439 case 0x01: 514 case 0x01:
440 go->state = STATE_00_00_01; 515 go->state = STATE_00_00_01;
441 break; 516 break;
442 case 0xFF: 517 case 0xFF:
443 store_byte(go->active_buf, 0x00); 518 store_byte(vb, 0x00);
444 store_byte(go->active_buf, 0x00); 519 store_byte(vb, 0x00);
445 go->state = STATE_FF; 520 go->state = STATE_FF;
446 break; 521 break;
447 default: 522 default:
448 store_byte(go->active_buf, 0x00); 523 store_byte(vb, 0x00);
449 store_byte(go->active_buf, 0x00); 524 store_byte(vb, 0x00);
450 store_byte(go->active_buf, buf[i]); 525 store_byte(vb, buf[i]);
451 go->state = STATE_DATA; 526 go->state = STATE_DATA;
452 break; 527 break;
453 } 528 }
@@ -455,31 +530,26 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
455 case STATE_00_00_01: 530 case STATE_00_00_01:
456 if (buf[i] == 0xF8 && go->modet_enable == 0) { 531 if (buf[i] == 0xF8 && go->modet_enable == 0) {
457 /* MODET start code, but MODET not enabled */ 532 /* MODET start code, but MODET not enabled */
458 store_byte(go->active_buf, 0x00); 533 store_byte(vb, 0x00);
459 store_byte(go->active_buf, 0x00); 534 store_byte(vb, 0x00);
460 store_byte(go->active_buf, 0x01); 535 store_byte(vb, 0x01);
461 store_byte(go->active_buf, 0xF8); 536 store_byte(vb, 0xF8);
462 go->state = STATE_DATA; 537 go->state = STATE_DATA;
463 break; 538 break;
464 } 539 }
465 /* If this is the start of a new MPEG frame, 540 /* If this is the start of a new MPEG frame,
466 * get a new buffer */ 541 * get a new buffer */
467 if ((go->format == GO7007_FORMAT_MPEG1 || 542 if ((go->format == V4L2_PIX_FMT_MPEG1 ||
468 go->format == GO7007_FORMAT_MPEG2 || 543 go->format == V4L2_PIX_FMT_MPEG2 ||
469 go->format == GO7007_FORMAT_MPEG4) && 544 go->format == V4L2_PIX_FMT_MPEG4) &&
470 (buf[i] == seq_start_code || 545 (buf[i] == seq_start_code ||
471 buf[i] == 0xB8 || /* GOP code */ 546 buf[i] == gop_start_code ||
472 buf[i] == frame_start_code)) { 547 buf[i] == frame_start_code)) {
473 if (go->active_buf == NULL || go->seen_frame) 548 if (vb == NULL || go->seen_frame)
474 frame_boundary(go); 549 vb = frame_boundary(go, vb);
475 if (buf[i] == frame_start_code) { 550 go->seen_frame = buf[i] == frame_start_code;
476 if (go->active_buf != NULL) 551 if (vb && go->seen_frame)
477 go->active_buf->frame_offset = 552 vb->frame_offset = vb->vb.v4l2_planes[0].bytesused;
478 go->active_buf->offset;
479 go->seen_frame = 1;
480 } else {
481 go->seen_frame = 0;
482 }
483 } 553 }
484 /* Handle any special chunk types, or just write the 554 /* Handle any special chunk types, or just write the
485 * start code to the (potentially new) buffer */ 555 * start code to the (potentially new) buffer */
@@ -498,16 +568,16 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
498 go->state = STATE_MODET_MAP; 568 go->state = STATE_MODET_MAP;
499 break; 569 break;
500 case 0xFF: /* Potential JPEG start code */ 570 case 0xFF: /* Potential JPEG start code */
501 store_byte(go->active_buf, 0x00); 571 store_byte(vb, 0x00);
502 store_byte(go->active_buf, 0x00); 572 store_byte(vb, 0x00);
503 store_byte(go->active_buf, 0x01); 573 store_byte(vb, 0x01);
504 go->state = STATE_FF; 574 go->state = STATE_FF;
505 break; 575 break;
506 default: 576 default:
507 store_byte(go->active_buf, 0x00); 577 store_byte(vb, 0x00);
508 store_byte(go->active_buf, 0x00); 578 store_byte(vb, 0x00);
509 store_byte(go->active_buf, 0x01); 579 store_byte(vb, 0x01);
510 store_byte(go->active_buf, buf[i]); 580 store_byte(vb, buf[i]);
511 go->state = STATE_DATA; 581 go->state = STATE_DATA;
512 break; 582 break;
513 } 583 }
@@ -515,20 +585,20 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
515 case STATE_FF: 585 case STATE_FF:
516 switch (buf[i]) { 586 switch (buf[i]) {
517 case 0x00: 587 case 0x00:
518 store_byte(go->active_buf, 0xFF); 588 store_byte(vb, 0xFF);
519 go->state = STATE_00; 589 go->state = STATE_00;
520 break; 590 break;
521 case 0xFF: 591 case 0xFF:
522 store_byte(go->active_buf, 0xFF); 592 store_byte(vb, 0xFF);
523 /* go->state remains STATE_FF */ 593 /* go->state remains STATE_FF */
524 break; 594 break;
525 case 0xD8: 595 case 0xD8:
526 if (go->format == GO7007_FORMAT_MJPEG) 596 if (go->format == V4L2_PIX_FMT_MJPEG)
527 frame_boundary(go); 597 vb = frame_boundary(go, vb);
528 /* fall through */ 598 /* fall through */
529 default: 599 default:
530 store_byte(go->active_buf, 0xFF); 600 store_byte(vb, 0xFF);
531 store_byte(go->active_buf, buf[i]); 601 store_byte(vb, buf[i]);
532 go->state = STATE_DATA; 602 go->state = STATE_DATA;
533 break; 603 break;
534 } 604 }
@@ -551,8 +621,8 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
551 write_bitmap_word(go); 621 write_bitmap_word(go);
552 } else 622 } else
553 go->modet_word = buf[i] << 8; 623 go->modet_word = buf[i] << 8;
554 } else if (go->parse_length == 207 && go->active_buf) { 624 } else if (go->parse_length == 207 && vb) {
555 go->active_buf->modet_active = buf[i]; 625 vb->modet_active = buf[i];
556 } 626 }
557 if (++go->parse_length == 208) 627 if (++go->parse_length == 208)
558 go->state = STATE_DATA; 628 go->state = STATE_DATA;
@@ -563,15 +633,14 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
563 break; 633 break;
564 } 634 }
565 } 635 }
566
567 spin_unlock(&go->spinlock);
568} 636}
569EXPORT_SYMBOL(go7007_parse_video_stream); 637EXPORT_SYMBOL(go7007_parse_video_stream);
570 638
571/* 639/*
572 * Allocate a new go7007 struct. Used by the hardware-specific probe. 640 * Allocate a new go7007 struct. Used by the hardware-specific probe.
573 */ 641 */
574struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev) 642struct go7007 *go7007_alloc(const struct go7007_board_info *board,
643 struct device *dev)
575{ 644{
576 struct go7007 *go; 645 struct go7007 *go;
577 int i; 646 int i;
@@ -588,33 +657,17 @@ struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev)
588 mutex_init(&go->hw_lock); 657 mutex_init(&go->hw_lock);
589 init_waitqueue_head(&go->frame_waitq); 658 init_waitqueue_head(&go->frame_waitq);
590 spin_lock_init(&go->spinlock); 659 spin_lock_init(&go->spinlock);
591 go->video_dev = NULL;
592 go->ref_count = 0;
593 go->status = STATUS_INIT; 660 go->status = STATUS_INIT;
594 memset(&go->i2c_adapter, 0, sizeof(go->i2c_adapter)); 661 memset(&go->i2c_adapter, 0, sizeof(go->i2c_adapter));
595 go->i2c_adapter_online = 0; 662 go->i2c_adapter_online = 0;
596 go->interrupt_available = 0; 663 go->interrupt_available = 0;
597 init_waitqueue_head(&go->interrupt_waitq); 664 init_waitqueue_head(&go->interrupt_waitq);
598 go->in_use = 0;
599 go->input = 0; 665 go->input = 0;
600 if (board->sensor_flags & GO7007_SENSOR_TV) { 666 go7007_update_board(go);
601 go->standard = GO7007_STD_NTSC;
602 go->width = 720;
603 go->height = 480;
604 go->sensor_framerate = 30000;
605 } else {
606 go->standard = GO7007_STD_OTHER;
607 go->width = board->sensor_width;
608 go->height = board->sensor_height;
609 go->sensor_framerate = board->sensor_framerate;
610 }
611 go->encoder_v_offset = board->sensor_v_offset;
612 go->encoder_h_offset = board->sensor_h_offset;
613 go->encoder_h_halve = 0; 667 go->encoder_h_halve = 0;
614 go->encoder_v_halve = 0; 668 go->encoder_v_halve = 0;
615 go->encoder_subsample = 0; 669 go->encoder_subsample = 0;
616 go->streaming = 0; 670 go->format = V4L2_PIX_FMT_MJPEG;
617 go->format = GO7007_FORMAT_MJPEG;
618 go->bitrate = 1500000; 671 go->bitrate = 1500000;
619 go->fps_scale = 1; 672 go->fps_scale = 1;
620 go->pali = 0; 673 go->pali = 0;
@@ -633,31 +686,30 @@ struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev)
633 go->modet_map[i] = 0; 686 go->modet_map[i] = 0;
634 go->audio_deliver = NULL; 687 go->audio_deliver = NULL;
635 go->audio_enabled = 0; 688 go->audio_enabled = 0;
636 INIT_LIST_HEAD(&go->stream);
637 689
638 return go; 690 return go;
639} 691}
640EXPORT_SYMBOL(go7007_alloc); 692EXPORT_SYMBOL(go7007_alloc);
641 693
642/* 694void go7007_update_board(struct go7007 *go)
643 * Detach and unregister the encoder. The go7007 struct won't be freed
644 * until v4l2 finishes releasing its resources and all associated fds are
645 * closed by applications.
646 */
647void go7007_remove(struct go7007 *go)
648{ 695{
649 if (go->i2c_adapter_online) { 696 const struct go7007_board_info *board = go->board_info;
650 if (i2c_del_adapter(&go->i2c_adapter) == 0)
651 go->i2c_adapter_online = 0;
652 else
653 v4l2_err(&go->v4l2_dev,
654 "error removing I2C adapter!\n");
655 }
656 697
657 if (go->audio_enabled) 698 if (board->sensor_flags & GO7007_SENSOR_TV) {
658 go7007_snd_remove(go); 699 go->standard = GO7007_STD_NTSC;
659 go7007_v4l2_remove(go); 700 go->std = V4L2_STD_NTSC_M;
701 go->width = 720;
702 go->height = 480;
703 go->sensor_framerate = 30000;
704 } else {
705 go->standard = GO7007_STD_OTHER;
706 go->width = board->sensor_width;
707 go->height = board->sensor_height;
708 go->sensor_framerate = board->sensor_framerate;
709 }
710 go->encoder_v_offset = board->sensor_v_offset;
711 go->encoder_h_offset = board->sensor_h_offset;
660} 712}
661EXPORT_SYMBOL(go7007_remove); 713EXPORT_SYMBOL(go7007_update_board);
662 714
663MODULE_LICENSE("GPL v2"); 715MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/go7007/go7007-fw.c b/drivers/staging/media/go7007/go7007-fw.c
index a5ede1c109d0..c2d0e58afc34 100644
--- a/drivers/staging/media/go7007/go7007-fw.c
+++ b/drivers/staging/media/go7007/go7007-fw.c
@@ -36,6 +36,8 @@
36 36
37#include "go7007-priv.h" 37#include "go7007-priv.h"
38 38
39#define GO7007_FW_NAME "go7007/go7007tv.bin"
40
39/* Constants used in the source firmware image to describe code segments */ 41/* Constants used in the source firmware image to describe code segments */
40 42
41#define FLAG_MODE_MJPEG (1) 43#define FLAG_MODE_MJPEG (1)
@@ -455,9 +457,9 @@ static int mpeg1_frame_header(struct go7007 *go, unsigned char *buf,
455 457
456 CODE_ADD(c, frame == PFRAME ? 0x2 : 0x3, 13); 458 CODE_ADD(c, frame == PFRAME ? 0x2 : 0x3, 13);
457 CODE_ADD(c, 0xffff, 16); 459 CODE_ADD(c, 0xffff, 16);
458 CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 0x7 : 0x4, 4); 460 CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 0x7 : 0x4, 4);
459 if (frame != PFRAME) 461 if (frame != PFRAME)
460 CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 0x7 : 0x4, 4); 462 CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 0x7 : 0x4, 4);
461 else 463 else
462 CODE_ADD(c, 0, 4); /* Is this supposed to be here?? */ 464 CODE_ADD(c, 0, 4); /* Is this supposed to be here?? */
463 CODE_ADD(c, 0, 3); /* What is this?? */ 465 CODE_ADD(c, 0, 3); /* What is this?? */
@@ -466,7 +468,7 @@ static int mpeg1_frame_header(struct go7007 *go, unsigned char *buf,
466 if (j != 8) 468 if (j != 8)
467 CODE_ADD(c, 0, j); 469 CODE_ADD(c, 0, j);
468 470
469 if (go->format == GO7007_FORMAT_MPEG2) { 471 if (go->format == V4L2_PIX_FMT_MPEG2) {
470 CODE_ADD(c, 0x1, 24); 472 CODE_ADD(c, 0x1, 24);
471 CODE_ADD(c, 0xb5, 8); 473 CODE_ADD(c, 0xb5, 8);
472 CODE_ADD(c, 0x844, 12); 474 CODE_ADD(c, 0x844, 12);
@@ -537,7 +539,7 @@ static int mpeg1_sequence_header(struct go7007 *go, unsigned char *buf, int ext)
537 int i, aspect_ratio, picture_rate; 539 int i, aspect_ratio, picture_rate;
538 CODE_GEN(c, buf + 6); 540 CODE_GEN(c, buf + 6);
539 541
540 if (go->format == GO7007_FORMAT_MPEG1) { 542 if (go->format == V4L2_PIX_FMT_MPEG1) {
541 switch (go->aspect_ratio) { 543 switch (go->aspect_ratio) {
542 case GO7007_RATIO_4_3: 544 case GO7007_RATIO_4_3:
543 aspect_ratio = go->standard == GO7007_STD_NTSC ? 3 : 2; 545 aspect_ratio = go->standard == GO7007_STD_NTSC ? 3 : 2;
@@ -587,9 +589,9 @@ static int mpeg1_sequence_header(struct go7007 *go, unsigned char *buf, int ext)
587 CODE_ADD(c, go->height, 12); 589 CODE_ADD(c, go->height, 12);
588 CODE_ADD(c, aspect_ratio, 4); 590 CODE_ADD(c, aspect_ratio, 4);
589 CODE_ADD(c, picture_rate, 4); 591 CODE_ADD(c, picture_rate, 4);
590 CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 20000 : 0x3ffff, 18); 592 CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 20000 : 0x3ffff, 18);
591 CODE_ADD(c, 1, 1); 593 CODE_ADD(c, 1, 1);
592 CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 112 : 20, 10); 594 CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 112 : 20, 10);
593 CODE_ADD(c, 0, 3); 595 CODE_ADD(c, 0, 3);
594 596
595 /* Byte-align with zeros */ 597 /* Byte-align with zeros */
@@ -597,7 +599,7 @@ static int mpeg1_sequence_header(struct go7007 *go, unsigned char *buf, int ext)
597 if (i != 8) 599 if (i != 8)
598 CODE_ADD(c, 0, i); 600 CODE_ADD(c, 0, i);
599 601
600 if (go->format == GO7007_FORMAT_MPEG2) { 602 if (go->format == V4L2_PIX_FMT_MPEG2) {
601 CODE_ADD(c, 0x1, 24); 603 CODE_ADD(c, 0x1, 24);
602 CODE_ADD(c, 0xb5, 8); 604 CODE_ADD(c, 0xb5, 8);
603 CODE_ADD(c, 0x148, 12); 605 CODE_ADD(c, 0x148, 12);
@@ -930,10 +932,10 @@ static int brctrl_to_package(struct go7007 *go,
930 __le16 *code, int space, int *framelen) 932 __le16 *code, int space, int *framelen)
931{ 933{
932 int converge_speed = 0; 934 int converge_speed = 0;
933 int lambda = (go->format == GO7007_FORMAT_MJPEG || go->dvd_mode) ? 935 int lambda = (go->format == V4L2_PIX_FMT_MJPEG || go->dvd_mode) ?
934 100 : 0; 936 100 : 0;
935 int peak_rate = 6 * go->bitrate / 5; 937 int peak_rate = 6 * go->bitrate / 5;
936 int vbv_buffer = go->format == GO7007_FORMAT_MJPEG ? 938 int vbv_buffer = go->format == V4L2_PIX_FMT_MJPEG ?
937 go->bitrate : 939 go->bitrate :
938 (go->dvd_mode ? 900000 : peak_rate); 940 (go->dvd_mode ? 900000 : peak_rate);
939 int fps = go->sensor_framerate / go->fps_scale; 941 int fps = go->sensor_framerate / go->fps_scale;
@@ -1096,10 +1098,10 @@ static int config_package(struct go7007 *go, __le16 *code, int space)
1096 0xc003, 0x28b4, 1098 0xc003, 0x28b4,
1097 0xc004, 0x3c5a, 1099 0xc004, 0x3c5a,
1098 0xdc05, 0x2a77, 1100 0xdc05, 0x2a77,
1099 0xc6c3, go->format == GO7007_FORMAT_MPEG4 ? 0 : 1101 0xc6c3, go->format == V4L2_PIX_FMT_MPEG4 ? 0 :
1100 (go->format == GO7007_FORMAT_H263 ? 0 : 1), 1102 (go->format == V4L2_PIX_FMT_H263 ? 0 : 1),
1101 0xc680, go->format == GO7007_FORMAT_MPEG4 ? 0xf1 : 1103 0xc680, go->format == V4L2_PIX_FMT_MPEG4 ? 0xf1 :
1102 (go->format == GO7007_FORMAT_H263 ? 0x61 : 1104 (go->format == V4L2_PIX_FMT_H263 ? 0x61 :
1103 0xd3), 1105 0xd3),
1104 0xc780, 0x0140, 1106 0xc780, 0x0140,
1105 0xe009, 0x0001, 1107 0xe009, 0x0001,
@@ -1123,15 +1125,15 @@ static int config_package(struct go7007 *go, __le16 *code, int space)
1123 (!go->interlace_coding) ? 1125 (!go->interlace_coding) ?
1124 0x0008 : 0x0009, 1126 0x0008 : 0x0009,
1125 0xc404, go->interlace_coding ? 0x44 : 1127 0xc404, go->interlace_coding ? 0x44 :
1126 (go->format == GO7007_FORMAT_MPEG4 ? 0x11 : 1128 (go->format == V4L2_PIX_FMT_MPEG4 ? 0x11 :
1127 (go->format == GO7007_FORMAT_MPEG1 ? 0x02 : 1129 (go->format == V4L2_PIX_FMT_MPEG1 ? 0x02 :
1128 (go->format == GO7007_FORMAT_MPEG2 ? 0x04 : 1130 (go->format == V4L2_PIX_FMT_MPEG2 ? 0x04 :
1129 (go->format == GO7007_FORMAT_H263 ? 0x08 : 1131 (go->format == V4L2_PIX_FMT_H263 ? 0x08 :
1130 0x20)))), 1132 0x20)))),
1131 0xbf0a, (go->format == GO7007_FORMAT_MPEG4 ? 8 : 1133 0xbf0a, (go->format == V4L2_PIX_FMT_MPEG4 ? 8 :
1132 (go->format == GO7007_FORMAT_MPEG1 ? 1 : 1134 (go->format == V4L2_PIX_FMT_MPEG1 ? 1 :
1133 (go->format == GO7007_FORMAT_MPEG2 ? 2 : 1135 (go->format == V4L2_PIX_FMT_MPEG2 ? 2 :
1134 (go->format == GO7007_FORMAT_H263 ? 4 : 16)))) | 1136 (go->format == V4L2_PIX_FMT_H263 ? 4 : 16)))) |
1135 ((go->repeat_seqhead ? 1 : 0) << 6) | 1137 ((go->repeat_seqhead ? 1 : 0) << 6) |
1136 ((go->dvd_mode ? 1 : 0) << 9) | 1138 ((go->dvd_mode ? 1 : 0) << 9) |
1137 ((go->gop_header_enable ? 1 : 0) << 10), 1139 ((go->gop_header_enable ? 1 : 0) << 10),
@@ -1348,19 +1350,19 @@ static int final_package(struct go7007 *go, __le16 *code, int space)
1348 0x41, 1350 0x41,
1349 go->ipb ? 0xd4c : 0x36b, 1351 go->ipb ? 0xd4c : 0x36b,
1350 (rows << 8) | (go->width >> 4), 1352 (rows << 8) | (go->width >> 4),
1351 go->format == GO7007_FORMAT_MPEG4 ? 0x0404 : 0, 1353 go->format == V4L2_PIX_FMT_MPEG4 ? 0x0404 : 0,
1352 (1 << 15) | ((go->interlace_coding ? 1 : 0) << 13) | 1354 (1 << 15) | ((go->interlace_coding ? 1 : 0) << 13) |
1353 ((go->closed_gop ? 1 : 0) << 12) | 1355 ((go->closed_gop ? 1 : 0) << 12) |
1354 ((go->format == GO7007_FORMAT_MPEG4 ? 1 : 0) << 11) | 1356 ((go->format == V4L2_PIX_FMT_MPEG4 ? 1 : 0) << 11) |
1355 /* (1 << 9) | */ 1357 /* (1 << 9) | */
1356 ((go->ipb ? 3 : 0) << 7) | 1358 ((go->ipb ? 3 : 0) << 7) |
1357 ((go->modet_enable ? 1 : 0) << 2) | 1359 ((go->modet_enable ? 1 : 0) << 2) |
1358 ((go->dvd_mode ? 1 : 0) << 1) | 1, 1360 ((go->dvd_mode ? 1 : 0) << 1) | 1,
1359 (go->format == GO7007_FORMAT_MPEG1 ? 0x89a0 : 1361 (go->format == V4L2_PIX_FMT_MPEG1 ? 0x89a0 :
1360 (go->format == GO7007_FORMAT_MPEG2 ? 0x89a0 : 1362 (go->format == V4L2_PIX_FMT_MPEG2 ? 0x89a0 :
1361 (go->format == GO7007_FORMAT_MJPEG ? 0x89a0 : 1363 (go->format == V4L2_PIX_FMT_MJPEG ? 0x89a0 :
1362 (go->format == GO7007_FORMAT_MPEG4 ? 0x8920 : 1364 (go->format == V4L2_PIX_FMT_MPEG4 ? 0x8920 :
1363 (go->format == GO7007_FORMAT_H263 ? 0x8920 : 0))))), 1365 (go->format == V4L2_PIX_FMT_H263 ? 0x8920 : 0))))),
1364 go->ipb ? 0x1f15 : 0x1f0b, 1366 go->ipb ? 0x1f15 : 0x1f0b,
1365 go->ipb ? 0x0015 : 0x000b, 1367 go->ipb ? 0x0015 : 0x000b,
1366 go->ipb ? 0xa800 : 0x5800, 1368 go->ipb ? 0xa800 : 0x5800,
@@ -1503,13 +1505,13 @@ static int do_special(struct go7007 *go, u16 type, __le16 *code, int space,
1503 switch (type) { 1505 switch (type) {
1504 case SPECIAL_FRM_HEAD: 1506 case SPECIAL_FRM_HEAD:
1505 switch (go->format) { 1507 switch (go->format) {
1506 case GO7007_FORMAT_MJPEG: 1508 case V4L2_PIX_FMT_MJPEG:
1507 return gen_mjpeghdr_to_package(go, code, space); 1509 return gen_mjpeghdr_to_package(go, code, space);
1508 case GO7007_FORMAT_MPEG1: 1510 case V4L2_PIX_FMT_MPEG1:
1509 case GO7007_FORMAT_MPEG2: 1511 case V4L2_PIX_FMT_MPEG2:
1510 return gen_mpeg1hdr_to_package(go, code, space, 1512 return gen_mpeg1hdr_to_package(go, code, space,
1511 framelen); 1513 framelen);
1512 case GO7007_FORMAT_MPEG4: 1514 case V4L2_PIX_FMT_MPEG4:
1513 return gen_mpeg4hdr_to_package(go, code, space, 1515 return gen_mpeg4hdr_to_package(go, code, space,
1514 framelen); 1516 framelen);
1515 } 1517 }
@@ -1519,11 +1521,11 @@ static int do_special(struct go7007 *go, u16 type, __le16 *code, int space,
1519 return config_package(go, code, space); 1521 return config_package(go, code, space);
1520 case SPECIAL_SEQHEAD: 1522 case SPECIAL_SEQHEAD:
1521 switch (go->format) { 1523 switch (go->format) {
1522 case GO7007_FORMAT_MPEG1: 1524 case V4L2_PIX_FMT_MPEG1:
1523 case GO7007_FORMAT_MPEG2: 1525 case V4L2_PIX_FMT_MPEG2:
1524 return seqhead_to_package(go, code, space, 1526 return seqhead_to_package(go, code, space,
1525 mpeg1_sequence_header); 1527 mpeg1_sequence_header);
1526 case GO7007_FORMAT_MPEG4: 1528 case V4L2_PIX_FMT_MPEG4:
1527 return seqhead_to_package(go, code, space, 1529 return seqhead_to_package(go, code, space,
1528 mpeg4_sequence_header); 1530 mpeg4_sequence_header);
1529 default: 1531 default:
@@ -1553,25 +1555,25 @@ int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen)
1553 int ret; 1555 int ret;
1554 1556
1555 switch (go->format) { 1557 switch (go->format) {
1556 case GO7007_FORMAT_MJPEG: 1558 case V4L2_PIX_FMT_MJPEG:
1557 mode_flag = FLAG_MODE_MJPEG; 1559 mode_flag = FLAG_MODE_MJPEG;
1558 break; 1560 break;
1559 case GO7007_FORMAT_MPEG1: 1561 case V4L2_PIX_FMT_MPEG1:
1560 mode_flag = FLAG_MODE_MPEG1; 1562 mode_flag = FLAG_MODE_MPEG1;
1561 break; 1563 break;
1562 case GO7007_FORMAT_MPEG2: 1564 case V4L2_PIX_FMT_MPEG2:
1563 mode_flag = FLAG_MODE_MPEG2; 1565 mode_flag = FLAG_MODE_MPEG2;
1564 break; 1566 break;
1565 case GO7007_FORMAT_MPEG4: 1567 case V4L2_PIX_FMT_MPEG4:
1566 mode_flag = FLAG_MODE_MPEG4; 1568 mode_flag = FLAG_MODE_MPEG4;
1567 break; 1569 break;
1568 default: 1570 default:
1569 return -1; 1571 return -1;
1570 } 1572 }
1571 if (request_firmware(&fw_entry, go->board_info->firmware, go->dev)) { 1573 if (request_firmware(&fw_entry, GO7007_FW_NAME, go->dev)) {
1572 dev_err(go->dev, 1574 dev_err(go->dev,
1573 "unable to load firmware from file \"%s\"\n", 1575 "unable to load firmware from file \"%s\"\n",
1574 go->board_info->firmware); 1576 GO7007_FW_NAME);
1575 return -1; 1577 return -1;
1576 } 1578 }
1577 code = kzalloc(codespace * 2, GFP_KERNEL); 1579 code = kzalloc(codespace * 2, GFP_KERNEL);
@@ -1586,7 +1588,7 @@ int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen)
1586 if (chunk_len + 2 > srclen) { 1588 if (chunk_len + 2 > srclen) {
1587 dev_err(go->dev, 1589 dev_err(go->dev,
1588 "firmware file \"%s\" appears to be corrupted\n", 1590 "firmware file \"%s\" appears to be corrupted\n",
1589 go->board_info->firmware); 1591 GO7007_FW_NAME);
1590 goto fw_failed; 1592 goto fw_failed;
1591 } 1593 }
1592 if (chunk_flags & mode_flag) { 1594 if (chunk_flags & mode_flag) {
@@ -1622,3 +1624,5 @@ fw_failed:
1622 release_firmware(fw_entry); 1624 release_firmware(fw_entry);
1623 return -1; 1625 return -1;
1624} 1626}
1627
1628MODULE_FIRMWARE(GO7007_FW_NAME);
diff --git a/drivers/staging/media/go7007/go7007-i2c.c b/drivers/staging/media/go7007/go7007-i2c.c
index 39456a36b2c6..74f25e03c326 100644
--- a/drivers/staging/media/go7007/go7007-i2c.c
+++ b/drivers/staging/media/go7007/go7007-i2c.c
@@ -28,7 +28,6 @@
28#include <linux/uaccess.h> 28#include <linux/uaccess.h>
29 29
30#include "go7007-priv.h" 30#include "go7007-priv.h"
31#include "wis-i2c.h"
32 31
33/********************* Driver for on-board I2C adapter *********************/ 32/********************* Driver for on-board I2C adapter *********************/
34 33
@@ -52,11 +51,11 @@ static DEFINE_MUTEX(adlink_mpg24_i2c_lock);
52static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read, 51static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
53 u16 command, int flags, u8 *data) 52 u16 command, int flags, u8 *data)
54{ 53{
55 int i, ret = -1; 54 int i, ret = -EIO;
56 u16 val; 55 u16 val;
57 56
58 if (go->status == STATUS_SHUTDOWN) 57 if (go->status == STATUS_SHUTDOWN)
59 return -1; 58 return -ENODEV;
60 59
61#ifdef GO7007_I2C_DEBUG 60#ifdef GO7007_I2C_DEBUG
62 if (read) 61 if (read)
@@ -146,7 +145,7 @@ static int go7007_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
146 struct go7007 *go = i2c_get_adapdata(adapter); 145 struct go7007 *go = i2c_get_adapdata(adapter);
147 146
148 if (size != I2C_SMBUS_BYTE_DATA) 147 if (size != I2C_SMBUS_BYTE_DATA)
149 return -1; 148 return -EIO;
150 return go7007_i2c_xfer(go, addr, read_write == I2C_SMBUS_READ, command, 149 return go7007_i2c_xfer(go, addr, read_write == I2C_SMBUS_READ, command,
151 flags & I2C_CLIENT_SCCB ? 0x10 : 0x00, &data->byte); 150 flags & I2C_CLIENT_SCCB ? 0x10 : 0x00, &data->byte);
152} 151}
@@ -170,26 +169,26 @@ static int go7007_i2c_master_xfer(struct i2c_adapter *adapter,
170 (msgs[i].flags & I2C_M_RD) || 169 (msgs[i].flags & I2C_M_RD) ||
171 !(msgs[i + 1].flags & I2C_M_RD) || 170 !(msgs[i + 1].flags & I2C_M_RD) ||
172 msgs[i + 1].len != 1) 171 msgs[i + 1].len != 1)
173 return -1; 172 return -EIO;
174 if (go7007_i2c_xfer(go, msgs[i].addr, 1, 173 if (go7007_i2c_xfer(go, msgs[i].addr, 1,
175 (msgs[i].buf[0] << 8) | msgs[i].buf[1], 174 (msgs[i].buf[0] << 8) | msgs[i].buf[1],
176 0x01, &msgs[i + 1].buf[0]) < 0) 175 0x01, &msgs[i + 1].buf[0]) < 0)
177 return -1; 176 return -EIO;
178 ++i; 177 ++i;
179 } else if (msgs[i].len == 3) { 178 } else if (msgs[i].len == 3) {
180 if (msgs[i].flags & I2C_M_RD) 179 if (msgs[i].flags & I2C_M_RD)
181 return -1; 180 return -EIO;
182 if (msgs[i].len != 3) 181 if (msgs[i].len != 3)
183 return -1; 182 return -EIO;
184 if (go7007_i2c_xfer(go, msgs[i].addr, 0, 183 if (go7007_i2c_xfer(go, msgs[i].addr, 0,
185 (msgs[i].buf[0] << 8) | msgs[i].buf[1], 184 (msgs[i].buf[0] << 8) | msgs[i].buf[1],
186 0x01, &msgs[i].buf[2]) < 0) 185 0x01, &msgs[i].buf[2]) < 0)
187 return -1; 186 return -EIO;
188 } else 187 } else
189 return -1; 188 return -EIO;
190 } 189 }
191 190
192 return 0; 191 return num;
193} 192}
194 193
195static u32 go7007_functionality(struct i2c_adapter *adapter) 194static u32 go7007_functionality(struct i2c_adapter *adapter)
diff --git a/drivers/staging/media/go7007/go7007-loader.c b/drivers/staging/media/go7007/go7007-loader.c
new file mode 100644
index 000000000000..f846ad5819dc
--- /dev/null
+++ b/drivers/staging/media/go7007/go7007-loader.c
@@ -0,0 +1,144 @@
1/*
2 * Copyright (C) 2008 Sensoray Company Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/usb.h>
22#include <linux/firmware.h>
23#include <cypress_firmware.h>
24
25struct fw_config {
26 u16 vendor;
27 u16 product;
28 const char * const fw_name1;
29 const char * const fw_name2;
30};
31
32struct fw_config fw_configs[] = {
33 { 0x1943, 0xa250, "go7007/s2250-1.fw", "go7007/s2250-2.fw" },
34 { 0x093b, 0xa002, "go7007/px-m402u.fw", NULL },
35 { 0x093b, 0xa004, "go7007/px-tv402u.fw", NULL },
36 { 0x0eb1, 0x6666, "go7007/lr192.fw", NULL },
37 { 0x0eb1, 0x6668, "go7007/wis-startrek.fw", NULL },
38 { 0, 0, NULL, NULL }
39};
40MODULE_FIRMWARE("go7007/s2250-1.fw");
41MODULE_FIRMWARE("go7007/s2250-2.fw");
42MODULE_FIRMWARE("go7007/px-m402u.fw");
43MODULE_FIRMWARE("go7007/px-tv402u.fw");
44MODULE_FIRMWARE("go7007/lr192.fw");
45MODULE_FIRMWARE("go7007/wis-startrek.fw");
46
47static int go7007_loader_probe(struct usb_interface *interface,
48 const struct usb_device_id *id)
49{
50 struct usb_device *usbdev;
51 const struct firmware *fw;
52 u16 vendor, product;
53 const char *fw1, *fw2;
54 int ret;
55 int i;
56
57 usbdev = usb_get_dev(interface_to_usbdev(interface));
58 if (!usbdev)
59 goto failed2;
60
61 if (usbdev->descriptor.bNumConfigurations != 1) {
62 dev_err(&interface->dev, "can't handle multiple config\n");
63 return -ENODEV;
64 }
65
66 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
67 product = le16_to_cpu(usbdev->descriptor.idProduct);
68
69 for (i = 0; fw_configs[i].fw_name1; i++)
70 if (fw_configs[i].vendor == vendor &&
71 fw_configs[i].product == product)
72 break;
73
74 /* Should never happen */
75 if (fw_configs[i].fw_name1 == NULL)
76 goto failed2;
77
78 fw1 = fw_configs[i].fw_name1;
79 fw2 = fw_configs[i].fw_name2;
80
81 dev_info(&interface->dev, "loading firmware %s\n", fw1);
82
83 if (request_firmware(&fw, fw1, &usbdev->dev)) {
84 dev_err(&interface->dev,
85 "unable to load firmware from file \"%s\"\n", fw1);
86 goto failed2;
87 }
88 ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
89 release_firmware(fw);
90 if (0 != ret) {
91 dev_err(&interface->dev, "loader download failed\n");
92 goto failed2;
93 }
94
95 if (fw2 == NULL)
96 return 0;
97
98 if (request_firmware(&fw, fw2, &usbdev->dev)) {
99 dev_err(&interface->dev,
100 "unable to load firmware from file \"%s\"\n", fw2);
101 goto failed2;
102 }
103 ret = cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
104 release_firmware(fw);
105 if (0 != ret) {
106 dev_err(&interface->dev, "firmware download failed\n");
107 goto failed2;
108 }
109 return 0;
110
111failed2:
112 dev_err(&interface->dev, "probe failed\n");
113 return -ENODEV;
114}
115
116static void go7007_loader_disconnect(struct usb_interface *interface)
117{
118 dev_info(&interface->dev, "disconnect\n");
119 usb_set_intfdata(interface, NULL);
120}
121
122static const struct usb_device_id go7007_loader_ids[] = {
123 { USB_DEVICE(0x1943, 0xa250) },
124 { USB_DEVICE(0x093b, 0xa002) },
125 { USB_DEVICE(0x093b, 0xa004) },
126 { USB_DEVICE(0x0eb1, 0x6666) },
127 { USB_DEVICE(0x0eb1, 0x6668) },
128 {} /* Terminating entry */
129};
130
131MODULE_DEVICE_TABLE(usb, go7007_loader_ids);
132
133static struct usb_driver go7007_loader_driver = {
134 .name = "go7007-loader",
135 .probe = go7007_loader_probe,
136 .disconnect = go7007_loader_disconnect,
137 .id_table = go7007_loader_ids,
138};
139
140module_usb_driver(go7007_loader_driver);
141
142MODULE_AUTHOR("");
143MODULE_DESCRIPTION("firmware loader for go7007-usb");
144MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/go7007/go7007-priv.h b/drivers/staging/media/go7007/go7007-priv.h
index b58c394c6555..6e16af720504 100644
--- a/drivers/staging/media/go7007/go7007-priv.h
+++ b/drivers/staging/media/go7007/go7007-priv.h
@@ -22,6 +22,9 @@
22 */ 22 */
23 23
24#include <media/v4l2-device.h> 24#include <media/v4l2-device.h>
25#include <media/v4l2-ctrls.h>
26#include <media/v4l2-fh.h>
27#include <media/videobuf2-core.h>
25 28
26struct go7007; 29struct go7007;
27 30
@@ -34,15 +37,13 @@ struct go7007;
34#define GO7007_BOARDID_XMEN_II 5 37#define GO7007_BOARDID_XMEN_II 5
35#define GO7007_BOARDID_XMEN_III 6 38#define GO7007_BOARDID_XMEN_III 6
36#define GO7007_BOARDID_MATRIX_REV 7 39#define GO7007_BOARDID_MATRIX_REV 7
37#define GO7007_BOARDID_PX_M402U 16 40#define GO7007_BOARDID_PX_M402U 8
38#define GO7007_BOARDID_PX_TV402U_ANY 17 /* need to check tuner model */ 41#define GO7007_BOARDID_PX_TV402U 9
39#define GO7007_BOARDID_PX_TV402U_NA 18 /* detected NTSC tuner */ 42#define GO7007_BOARDID_LIFEVIEW_LR192 10 /* TV Walker Ultra */
40#define GO7007_BOARDID_PX_TV402U_EU 19 /* detected PAL tuner */ 43#define GO7007_BOARDID_ENDURA 11
41#define GO7007_BOARDID_PX_TV402U_JP 20 /* detected NTSC-J tuner */ 44#define GO7007_BOARDID_ADLINK_MPG24 12
42#define GO7007_BOARDID_LIFEVIEW_LR192 21 /* TV Walker Ultra */ 45#define GO7007_BOARDID_SENSORAY_2250 13 /* Sensoray 2250/2251 */
43#define GO7007_BOARDID_ENDURA 22 46#define GO7007_BOARDID_ADS_USBAV_709 14
44#define GO7007_BOARDID_ADLINK_MPG24 23
45#define GO7007_BOARDID_SENSORAY_2250 24 /* Sensoray 2250/2251 */
46 47
47/* Various characteristics of each board */ 48/* Various characteristics of each board */
48#define GO7007_BOARD_HAS_AUDIO (1<<0) 49#define GO7007_BOARD_HAS_AUDIO (1<<0)
@@ -61,6 +62,7 @@ struct go7007;
61#define GO7007_SENSOR_TV (1<<7) 62#define GO7007_SENSOR_TV (1<<7)
62#define GO7007_SENSOR_VBI (1<<8) 63#define GO7007_SENSOR_VBI (1<<8)
63#define GO7007_SENSOR_SCALING (1<<9) 64#define GO7007_SENSOR_SCALING (1<<9)
65#define GO7007_SENSOR_SAA7115 (1<<10)
64 66
65/* Characteristics of audio sensor devices */ 67/* Characteristics of audio sensor devices */
66#define GO7007_AUDIO_I2S_MODE_1 (1) 68#define GO7007_AUDIO_I2S_MODE_1 (1)
@@ -74,7 +76,6 @@ struct go7007;
74#define GO7007_AUDIO_OKI_MODE (1<<17) 76#define GO7007_AUDIO_OKI_MODE (1<<17)
75 77
76struct go7007_board_info { 78struct go7007_board_info {
77 char *firmware;
78 unsigned int flags; 79 unsigned int flags;
79 int hpi_buffer_cap; 80 int hpi_buffer_cap;
80 unsigned int sensor_flags; 81 unsigned int sensor_flags;
@@ -88,17 +89,25 @@ struct go7007_board_info {
88 int audio_bclk_div; 89 int audio_bclk_div;
89 int audio_main_div; 90 int audio_main_div;
90 int num_i2c_devs; 91 int num_i2c_devs;
91 struct { 92 struct go_i2c {
92 const char *type; 93 const char *type;
93 int id; 94 unsigned int is_video:1;
95 unsigned int is_audio:1;
94 int addr; 96 int addr;
95 } i2c_devs[4]; 97 u32 flags;
98 } i2c_devs[5];
96 int num_inputs; 99 int num_inputs;
97 struct { 100 struct {
98 int video_input; 101 int video_input;
99 int audio_input; 102 int audio_index;
100 char *name; 103 char *name;
101 } inputs[4]; 104 } inputs[4];
105 int video_config;
106 int num_aud_inputs;
107 struct {
108 int audio_input;
109 char *name;
110 } aud_inputs[3];
102}; 111};
103 112
104struct go7007_hpi_ops { 113struct go7007_hpi_ops {
@@ -109,6 +118,7 @@ struct go7007_hpi_ops {
109 int (*stream_stop)(struct go7007 *go); 118 int (*stream_stop)(struct go7007 *go);
110 int (*send_firmware)(struct go7007 *go, u8 *data, int len); 119 int (*send_firmware)(struct go7007 *go, u8 *data, int len);
111 int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg); 120 int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg);
121 void (*release)(struct go7007 *go);
112}; 122};
113 123
114/* The video buffer size must be a multiple of PAGE_SIZE */ 124/* The video buffer size must be a multiple of PAGE_SIZE */
@@ -116,35 +126,12 @@ struct go7007_hpi_ops {
116#define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT) 126#define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
117 127
118struct go7007_buffer { 128struct go7007_buffer {
119 struct go7007 *go; /* Reverse reference for VMA ops */ 129 struct vb2_buffer vb;
120 int index; /* Reverse reference for DQBUF */ 130 struct list_head list;
121 enum { BUF_STATE_IDLE, BUF_STATE_QUEUED, BUF_STATE_DONE } state;
122 u32 seq;
123 struct timeval timestamp;
124 struct list_head stream;
125 struct page *pages[GO7007_BUF_PAGES + 1]; /* extra for straddling */
126 unsigned long user_addr;
127 unsigned int page_count;
128 unsigned int offset;
129 unsigned int bytesused;
130 unsigned int frame_offset; 131 unsigned int frame_offset;
131 u32 modet_active; 132 u32 modet_active;
132 int mapped;
133}; 133};
134 134
135struct go7007_file {
136 struct go7007 *go;
137 struct mutex lock;
138 int buf_count;
139 struct go7007_buffer *bufs;
140};
141
142#define GO7007_FORMAT_MJPEG 0
143#define GO7007_FORMAT_MPEG4 1
144#define GO7007_FORMAT_MPEG1 2
145#define GO7007_FORMAT_MPEG2 3
146#define GO7007_FORMAT_H263 4
147
148#define GO7007_RATIO_1_1 0 135#define GO7007_RATIO_1_1 0
149#define GO7007_RATIO_4_3 1 136#define GO7007_RATIO_4_3 1
150#define GO7007_RATIO_16_9 2 137#define GO7007_RATIO_16_9 2
@@ -163,24 +150,38 @@ enum go7007_parser_state {
163 150
164struct go7007 { 151struct go7007 {
165 struct device *dev; 152 struct device *dev;
166 struct go7007_board_info *board_info; 153 u8 bus_info[32];
154 const struct go7007_board_info *board_info;
167 unsigned int board_id; 155 unsigned int board_id;
168 int tuner_type; 156 int tuner_type;
169 int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */ 157 int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */
170 char name[64]; 158 char name[64];
171 struct video_device *video_dev; 159 struct video_device vdev;
160 void *boot_fw;
161 unsigned boot_fw_len;
172 struct v4l2_device v4l2_dev; 162 struct v4l2_device v4l2_dev;
173 int ref_count; 163 struct v4l2_ctrl_handler hdl;
164 struct v4l2_ctrl *mpeg_video_encoding;
165 struct v4l2_ctrl *mpeg_video_gop_size;
166 struct v4l2_ctrl *mpeg_video_gop_closure;
167 struct v4l2_ctrl *mpeg_video_bitrate;
168 struct v4l2_ctrl *mpeg_video_aspect_ratio;
169 struct v4l2_ctrl *mpeg_video_b_frames;
170 struct v4l2_ctrl *mpeg_video_rep_seqheader;
174 enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status; 171 enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
175 spinlock_t spinlock; 172 spinlock_t spinlock;
176 struct mutex hw_lock; 173 struct mutex hw_lock;
177 int streaming; 174 struct mutex serialize_lock;
178 int in_use;
179 int audio_enabled; 175 int audio_enabled;
176 struct v4l2_subdev *sd_video;
177 struct v4l2_subdev *sd_audio;
178 u8 usb_buf[16];
180 179
181 /* Video input */ 180 /* Video input */
182 int input; 181 int input;
182 int aud_input;
183 enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard; 183 enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
184 v4l2_std_id std;
184 int sensor_framerate; 185 int sensor_framerate;
185 int width; 186 int width;
186 int height; 187 int height;
@@ -191,7 +192,7 @@ struct go7007 {
191 unsigned int encoder_subsample:1; 192 unsigned int encoder_subsample:1;
192 193
193 /* Encoder config */ 194 /* Encoder config */
194 int format; 195 u32 format;
195 int bitrate; 196 int bitrate;
196 int fps_scale; 197 int fps_scale;
197 int pali; 198 int pali;
@@ -217,14 +218,16 @@ struct go7007 {
217 unsigned char active_map[216]; 218 unsigned char active_map[216];
218 219
219 /* Video streaming */ 220 /* Video streaming */
220 struct go7007_buffer *active_buf; 221 struct mutex queue_lock;
222 struct vb2_queue vidq;
221 enum go7007_parser_state state; 223 enum go7007_parser_state state;
222 int parse_length; 224 int parse_length;
223 u16 modet_word; 225 u16 modet_word;
224 int seen_frame; 226 int seen_frame;
225 u32 next_seq; 227 u32 next_seq;
226 struct list_head stream; 228 struct list_head vidq_active;
227 wait_queue_head_t frame_waitq; 229 wait_queue_head_t frame_waitq;
230 struct go7007_buffer *active_buf;
228 231
229 /* Audio streaming */ 232 /* Audio streaming */
230 void (*audio_deliver)(struct go7007 *go, u8 *buf, int length); 233 void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
@@ -267,12 +270,12 @@ int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
267int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data); 270int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
268int go7007_boot_encoder(struct go7007 *go, int init_i2c); 271int go7007_boot_encoder(struct go7007 *go, int init_i2c);
269int go7007_reset_encoder(struct go7007 *go); 272int go7007_reset_encoder(struct go7007 *go);
270int go7007_register_encoder(struct go7007 *go); 273int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs);
271int go7007_start_encoder(struct go7007 *go); 274int go7007_start_encoder(struct go7007 *go);
272void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length); 275void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
273struct go7007 *go7007_alloc(struct go7007_board_info *board, 276struct go7007 *go7007_alloc(const struct go7007_board_info *board,
274 struct device *dev); 277 struct device *dev);
275void go7007_remove(struct go7007 *go); 278void go7007_update_board(struct go7007 *go);
276 279
277/* go7007-fw.c */ 280/* go7007-fw.c */
278int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen); 281int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
@@ -283,6 +286,7 @@ int go7007_i2c_remove(struct go7007 *go);
283 286
284/* go7007-v4l2.c */ 287/* go7007-v4l2.c */
285int go7007_v4l2_init(struct go7007 *go); 288int go7007_v4l2_init(struct go7007 *go);
289int go7007_v4l2_ctrl_init(struct go7007 *go);
286void go7007_v4l2_remove(struct go7007 *go); 290void go7007_v4l2_remove(struct go7007 *go);
287 291
288/* snd-go7007.c */ 292/* snd-go7007.c */
diff --git a/drivers/staging/media/go7007/go7007-usb.c b/drivers/staging/media/go7007/go7007-usb.c
index 9dbf5ecd05a2..50066e01a6ed 100644
--- a/drivers/staging/media/go7007/go7007-usb.c
+++ b/drivers/staging/media/go7007/go7007-usb.c
@@ -26,10 +26,11 @@
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <asm/byteorder.h> 28#include <asm/byteorder.h>
29#include <media/tvaudio.h> 29#include <media/saa7115.h>
30#include <media/tuner.h>
31#include <media/uda1342.h>
30 32
31#include "go7007-priv.h" 33#include "go7007-priv.h"
32#include "wis-i2c.h"
33 34
34static unsigned int assume_endura; 35static unsigned int assume_endura;
35module_param(assume_endura, int, 0644); 36module_param(assume_endura, int, 0644);
@@ -62,7 +63,7 @@ struct go7007_usb_board {
62}; 63};
63 64
64struct go7007_usb { 65struct go7007_usb {
65 struct go7007_usb_board *board; 66 const struct go7007_usb_board *board;
66 struct mutex i2c_lock; 67 struct mutex i2c_lock;
67 struct usb_device *usbdev; 68 struct usb_device *usbdev;
68 struct urb *video_urbs[8]; 69 struct urb *video_urbs[8];
@@ -72,10 +73,9 @@ struct go7007_usb {
72 73
73/*********************** Product specification data ***********************/ 74/*********************** Product specification data ***********************/
74 75
75static struct go7007_usb_board board_matrix_ii = { 76static const struct go7007_usb_board board_matrix_ii = {
76 .flags = GO7007_USB_EZUSB, 77 .flags = GO7007_USB_EZUSB,
77 .main_info = { 78 .main_info = {
78 .firmware = "go7007tv.bin",
79 .flags = GO7007_BOARD_HAS_AUDIO | 79 .flags = GO7007_BOARD_HAS_AUDIO |
80 GO7007_BOARD_USE_ONBOARD_I2C, 80 GO7007_BOARD_USE_ONBOARD_I2C,
81 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 81 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
@@ -87,14 +87,15 @@ static struct go7007_usb_board board_matrix_ii = {
87 .sensor_flags = GO7007_SENSOR_656 | 87 .sensor_flags = GO7007_SENSOR_656 |
88 GO7007_SENSOR_VALID_ENABLE | 88 GO7007_SENSOR_VALID_ENABLE |
89 GO7007_SENSOR_TV | 89 GO7007_SENSOR_TV |
90 GO7007_SENSOR_SAA7115 |
90 GO7007_SENSOR_VBI | 91 GO7007_SENSOR_VBI |
91 GO7007_SENSOR_SCALING, 92 GO7007_SENSOR_SCALING,
92 .num_i2c_devs = 1, 93 .num_i2c_devs = 1,
93 .i2c_devs = { 94 .i2c_devs = {
94 { 95 {
95 .type = "wis_saa7115", 96 .type = "saa7115",
96 .id = I2C_DRIVERID_WIS_SAA7115,
97 .addr = 0x20, 97 .addr = 0x20,
98 .is_video = 1,
98 }, 99 },
99 }, 100 },
100 .num_inputs = 2, 101 .num_inputs = 2,
@@ -108,13 +109,13 @@ static struct go7007_usb_board board_matrix_ii = {
108 .name = "S-Video", 109 .name = "S-Video",
109 }, 110 },
110 }, 111 },
112 .video_config = SAA7115_IDQ_IS_DEFAULT,
111 }, 113 },
112}; 114};
113 115
114static struct go7007_usb_board board_matrix_reload = { 116static const struct go7007_usb_board board_matrix_reload = {
115 .flags = GO7007_USB_EZUSB, 117 .flags = GO7007_USB_EZUSB,
116 .main_info = { 118 .main_info = {
117 .firmware = "go7007tv.bin",
118 .flags = GO7007_BOARD_HAS_AUDIO | 119 .flags = GO7007_BOARD_HAS_AUDIO |
119 GO7007_BOARD_USE_ONBOARD_I2C, 120 GO7007_BOARD_USE_ONBOARD_I2C,
120 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 121 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
@@ -129,9 +130,9 @@ static struct go7007_usb_board board_matrix_reload = {
129 .num_i2c_devs = 1, 130 .num_i2c_devs = 1,
130 .i2c_devs = { 131 .i2c_devs = {
131 { 132 {
132 .type = "wis_saa7113", 133 .type = "saa7113",
133 .id = I2C_DRIVERID_WIS_SAA7113,
134 .addr = 0x25, 134 .addr = 0x25,
135 .is_video = 1,
135 }, 136 },
136 }, 137 },
137 .num_inputs = 2, 138 .num_inputs = 2,
@@ -145,18 +146,19 @@ static struct go7007_usb_board board_matrix_reload = {
145 .name = "S-Video", 146 .name = "S-Video",
146 }, 147 },
147 }, 148 },
149 .video_config = SAA7115_IDQ_IS_DEFAULT,
148 }, 150 },
149}; 151};
150 152
151static struct go7007_usb_board board_star_trek = { 153static const struct go7007_usb_board board_star_trek = {
152 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C, 154 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
153 .main_info = { 155 .main_info = {
154 .firmware = "go7007tv.bin",
155 .flags = GO7007_BOARD_HAS_AUDIO, /* | 156 .flags = GO7007_BOARD_HAS_AUDIO, /* |
156 GO7007_BOARD_HAS_TUNER, */ 157 GO7007_BOARD_HAS_TUNER, */
157 .sensor_flags = GO7007_SENSOR_656 | 158 .sensor_flags = GO7007_SENSOR_656 |
158 GO7007_SENSOR_VALID_ENABLE | 159 GO7007_SENSOR_VALID_ENABLE |
159 GO7007_SENSOR_TV | 160 GO7007_SENSOR_TV |
161 GO7007_SENSOR_SAA7115 |
160 GO7007_SENSOR_VBI | 162 GO7007_SENSOR_VBI |
161 GO7007_SENSOR_SCALING, 163 GO7007_SENSOR_SCALING,
162 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 164 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
@@ -167,42 +169,43 @@ static struct go7007_usb_board board_star_trek = {
167 .num_i2c_devs = 1, 169 .num_i2c_devs = 1,
168 .i2c_devs = { 170 .i2c_devs = {
169 { 171 {
170 .type = "wis_saa7115", 172 .type = "saa7115",
171 .id = I2C_DRIVERID_WIS_SAA7115,
172 .addr = 0x20, 173 .addr = 0x20,
174 .is_video = 1,
173 }, 175 },
174 }, 176 },
175 .num_inputs = 2, 177 .num_inputs = 2,
176 .inputs = { 178 .inputs = {
179 /* {
180 * .video_input = 3,
181 * .audio_index = AUDIO_TUNER,
182 * .name = "Tuner",
183 * },
184 */
177 { 185 {
178 .video_input = 1, 186 .video_input = 1,
179 /* .audio_input = AUDIO_EXTERN, */ 187 /* .audio_index = AUDIO_EXTERN, */
180 .name = "Composite", 188 .name = "Composite",
181 }, 189 },
182 { 190 {
183 .video_input = 8, 191 .video_input = 8,
184 /* .audio_input = AUDIO_EXTERN, */ 192 /* .audio_index = AUDIO_EXTERN, */
185 .name = "S-Video", 193 .name = "S-Video",
186 }, 194 },
187 /* {
188 * .video_input = 3,
189 * .audio_input = AUDIO_TUNER,
190 * .name = "Tuner",
191 * },
192 */
193 }, 195 },
196 .video_config = SAA7115_IDQ_IS_DEFAULT,
194 }, 197 },
195}; 198};
196 199
197static struct go7007_usb_board board_px_tv402u = { 200static const struct go7007_usb_board board_px_tv402u = {
198 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C, 201 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
199 .main_info = { 202 .main_info = {
200 .firmware = "go7007tv.bin",
201 .flags = GO7007_BOARD_HAS_AUDIO | 203 .flags = GO7007_BOARD_HAS_AUDIO |
202 GO7007_BOARD_HAS_TUNER, 204 GO7007_BOARD_HAS_TUNER,
203 .sensor_flags = GO7007_SENSOR_656 | 205 .sensor_flags = GO7007_SENSOR_656 |
204 GO7007_SENSOR_VALID_ENABLE | 206 GO7007_SENSOR_VALID_ENABLE |
205 GO7007_SENSOR_TV | 207 GO7007_SENSOR_TV |
208 GO7007_SENSOR_SAA7115 |
206 GO7007_SENSOR_VBI | 209 GO7007_SENSOR_VBI |
207 GO7007_SENSOR_SCALING, 210 GO7007_SENSOR_SCALING,
208 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 211 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
@@ -210,49 +213,67 @@ static struct go7007_usb_board board_px_tv402u = {
210 .audio_bclk_div = 8, 213 .audio_bclk_div = 8,
211 .audio_main_div = 2, 214 .audio_main_div = 2,
212 .hpi_buffer_cap = 7, 215 .hpi_buffer_cap = 7,
213 .num_i2c_devs = 3, 216 .num_i2c_devs = 5,
214 .i2c_devs = { 217 .i2c_devs = {
215 { 218 {
216 .type = "wis_saa7115", 219 .type = "saa7115",
217 .id = I2C_DRIVERID_WIS_SAA7115,
218 .addr = 0x20, 220 .addr = 0x20,
221 .is_video = 1,
219 }, 222 },
220 { 223 {
221 .type = "wis_uda1342", 224 .type = "uda1342",
222 .id = I2C_DRIVERID_WIS_UDA1342,
223 .addr = 0x1a, 225 .addr = 0x1a,
226 .is_audio = 1,
224 }, 227 },
225 { 228 {
226 .type = "wis_sony_tuner", 229 .type = "tuner",
227 .id = I2C_DRIVERID_WIS_SONY_TUNER,
228 .addr = 0x60, 230 .addr = 0x60,
229 }, 231 },
232 {
233 .type = "tuner",
234 .addr = 0x43,
235 },
236 {
237 .type = "sony-btf-mpx",
238 .addr = 0x44,
239 },
230 }, 240 },
231 .num_inputs = 3, 241 .num_inputs = 3,
232 .inputs = { 242 .inputs = {
233 { 243 {
244 .video_input = 3,
245 .audio_index = 0,
246 .name = "Tuner",
247 },
248 {
234 .video_input = 1, 249 .video_input = 1,
235 .audio_input = TVAUDIO_INPUT_EXTERN, 250 .audio_index = 1,
236 .name = "Composite", 251 .name = "Composite",
237 }, 252 },
238 { 253 {
239 .video_input = 8, 254 .video_input = 8,
240 .audio_input = TVAUDIO_INPUT_EXTERN, 255 .audio_index = 1,
241 .name = "S-Video", 256 .name = "S-Video",
242 }, 257 },
258 },
259 .video_config = SAA7115_IDQ_IS_DEFAULT,
260 .num_aud_inputs = 2,
261 .aud_inputs = {
243 { 262 {
244 .video_input = 3, 263 .audio_input = UDA1342_IN2,
245 .audio_input = TVAUDIO_INPUT_TUNER,
246 .name = "Tuner", 264 .name = "Tuner",
247 }, 265 },
266 {
267 .audio_input = UDA1342_IN1,
268 .name = "Line In",
269 },
248 }, 270 },
249 }, 271 },
250}; 272};
251 273
252static struct go7007_usb_board board_xmen = { 274static const struct go7007_usb_board board_xmen = {
253 .flags = 0, 275 .flags = 0,
254 .main_info = { 276 .main_info = {
255 .firmware = "go7007tv.bin",
256 .flags = GO7007_BOARD_USE_ONBOARD_I2C, 277 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
257 .hpi_buffer_cap = 0, 278 .hpi_buffer_cap = 0,
258 .sensor_flags = GO7007_SENSOR_VREF_POLAR, 279 .sensor_flags = GO7007_SENSOR_VREF_POLAR,
@@ -271,8 +292,7 @@ static struct go7007_usb_board board_xmen = {
271 .num_i2c_devs = 1, 292 .num_i2c_devs = 1,
272 .i2c_devs = { 293 .i2c_devs = {
273 { 294 {
274 .type = "wis_ov7640", 295 .type = "ov7640",
275 .id = I2C_DRIVERID_WIS_OV7640,
276 .addr = 0x21, 296 .addr = 0x21,
277 }, 297 },
278 }, 298 },
@@ -285,10 +305,9 @@ static struct go7007_usb_board board_xmen = {
285 }, 305 },
286}; 306};
287 307
288static struct go7007_usb_board board_matrix_revolution = { 308static const struct go7007_usb_board board_matrix_revolution = {
289 .flags = GO7007_USB_EZUSB, 309 .flags = GO7007_USB_EZUSB,
290 .main_info = { 310 .main_info = {
291 .firmware = "go7007tv.bin",
292 .flags = GO7007_BOARD_HAS_AUDIO | 311 .flags = GO7007_BOARD_HAS_AUDIO |
293 GO7007_BOARD_USE_ONBOARD_I2C, 312 GO7007_BOARD_USE_ONBOARD_I2C,
294 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 313 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
@@ -304,8 +323,8 @@ static struct go7007_usb_board board_matrix_revolution = {
304 .num_i2c_devs = 1, 323 .num_i2c_devs = 1,
305 .i2c_devs = { 324 .i2c_devs = {
306 { 325 {
307 .type = "wis_tw9903", 326 .type = "tw9903",
308 .id = I2C_DRIVERID_WIS_TW9903, 327 .is_video = 1,
309 .addr = 0x44, 328 .addr = 0x44,
310 }, 329 },
311 }, 330 },
@@ -323,10 +342,9 @@ static struct go7007_usb_board board_matrix_revolution = {
323 }, 342 },
324}; 343};
325 344
326static struct go7007_usb_board board_lifeview_lr192 = { 345static const struct go7007_usb_board board_lifeview_lr192 = {
327 .flags = GO7007_USB_EZUSB, 346 .flags = GO7007_USB_EZUSB,
328 .main_info = { 347 .main_info = {
329 .firmware = "go7007tv.bin",
330 .flags = GO7007_BOARD_HAS_AUDIO | 348 .flags = GO7007_BOARD_HAS_AUDIO |
331 GO7007_BOARD_USE_ONBOARD_I2C, 349 GO7007_BOARD_USE_ONBOARD_I2C,
332 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 350 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
@@ -351,10 +369,9 @@ static struct go7007_usb_board board_lifeview_lr192 = {
351 }, 369 },
352}; 370};
353 371
354static struct go7007_usb_board board_endura = { 372static const struct go7007_usb_board board_endura = {
355 .flags = 0, 373 .flags = 0,
356 .main_info = { 374 .main_info = {
357 .firmware = "go7007tv.bin",
358 .flags = 0, 375 .flags = 0,
359 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 376 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
360 GO7007_AUDIO_I2S_MASTER | 377 GO7007_AUDIO_I2S_MASTER |
@@ -376,10 +393,9 @@ static struct go7007_usb_board board_endura = {
376 }, 393 },
377}; 394};
378 395
379static struct go7007_usb_board board_adlink_mpg24 = { 396static const struct go7007_usb_board board_adlink_mpg24 = {
380 .flags = 0, 397 .flags = 0,
381 .main_info = { 398 .main_info = {
382 .firmware = "go7007tv.bin",
383 .flags = GO7007_BOARD_USE_ONBOARD_I2C, 399 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
384 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 400 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
385 GO7007_AUDIO_I2S_MASTER | 401 GO7007_AUDIO_I2S_MASTER |
@@ -394,9 +410,10 @@ static struct go7007_usb_board board_adlink_mpg24 = {
394 .num_i2c_devs = 1, 410 .num_i2c_devs = 1,
395 .i2c_devs = { 411 .i2c_devs = {
396 { 412 {
397 .type = "wis_tw2804", 413 .type = "tw2804",
398 .id = I2C_DRIVERID_WIS_TW2804,
399 .addr = 0x00, /* yes, really */ 414 .addr = 0x00, /* yes, really */
415 .flags = I2C_CLIENT_TEN,
416 .is_video = 1,
400 }, 417 },
401 }, 418 },
402 .num_inputs = 1, 419 .num_inputs = 1,
@@ -408,10 +425,9 @@ static struct go7007_usb_board board_adlink_mpg24 = {
408 }, 425 },
409}; 426};
410 427
411static struct go7007_usb_board board_sensoray_2250 = { 428static const struct go7007_usb_board board_sensoray_2250 = {
412 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C, 429 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
413 .main_info = { 430 .main_info = {
414 .firmware = "go7007tv.bin",
415 .audio_flags = GO7007_AUDIO_I2S_MODE_1 | 431 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
416 GO7007_AUDIO_I2S_MASTER | 432 GO7007_AUDIO_I2S_MASTER |
417 GO7007_AUDIO_WORD_16, 433 GO7007_AUDIO_WORD_16,
@@ -426,8 +442,9 @@ static struct go7007_usb_board board_sensoray_2250 = {
426 .i2c_devs = { 442 .i2c_devs = {
427 { 443 {
428 .type = "s2250", 444 .type = "s2250",
429 .id = I2C_DRIVERID_S2250,
430 .addr = 0x43, 445 .addr = 0x43,
446 .is_video = 1,
447 .is_audio = 1,
431 }, 448 },
432 }, 449 },
433 .num_inputs = 2, 450 .num_inputs = 2,
@@ -441,10 +458,60 @@ static struct go7007_usb_board board_sensoray_2250 = {
441 .name = "S-Video", 458 .name = "S-Video",
442 }, 459 },
443 }, 460 },
461 .num_aud_inputs = 3,
462 .aud_inputs = {
463 {
464 .audio_input = 0,
465 .name = "Line In",
466 },
467 {
468 .audio_input = 1,
469 .name = "Mic",
470 },
471 {
472 .audio_input = 2,
473 .name = "Mic Boost",
474 },
475 },
444 }, 476 },
445}; 477};
446 478
447MODULE_FIRMWARE("go7007tv.bin"); 479static const struct go7007_usb_board board_ads_usbav_709 = {
480 .flags = GO7007_USB_EZUSB,
481 .main_info = {
482 .flags = GO7007_BOARD_HAS_AUDIO |
483 GO7007_BOARD_USE_ONBOARD_I2C,
484 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
485 GO7007_AUDIO_I2S_MASTER |
486 GO7007_AUDIO_WORD_16,
487 .audio_rate = 48000,
488 .audio_bclk_div = 8,
489 .audio_main_div = 2,
490 .hpi_buffer_cap = 7,
491 .sensor_flags = GO7007_SENSOR_656 |
492 GO7007_SENSOR_TV |
493 GO7007_SENSOR_VBI,
494 .num_i2c_devs = 1,
495 .i2c_devs = {
496 {
497 .type = "tw9906",
498 .is_video = 1,
499 .addr = 0x44,
500 },
501 },
502 .num_inputs = 2,
503 .inputs = {
504 {
505 .video_input = 0,
506 .name = "Composite",
507 },
508 {
509 .video_input = 10,
510 .name = "S-Video",
511 },
512 },
513 },
514};
448 515
449static const struct usb_device_id go7007_usb_id_table[] = { 516static const struct usb_device_id go7007_usb_id_table[] = {
450 { 517 {
@@ -529,7 +596,7 @@ static const struct usb_device_id go7007_usb_id_table[] = {
529 .idProduct = 0xa104, /* Product ID of TV402U */ 596 .idProduct = 0xa104, /* Product ID of TV402U */
530 .bcdDevice_lo = 0x1, 597 .bcdDevice_lo = 0x1,
531 .bcdDevice_hi = 0x1, 598 .bcdDevice_hi = 0x1,
532 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U_ANY, 599 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U,
533 }, 600 },
534 { 601 {
535 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, 602 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
@@ -547,6 +614,14 @@ static const struct usb_device_id go7007_usb_id_table[] = {
547 .bcdDevice_hi = 0x1, 614 .bcdDevice_hi = 0x1,
548 .driver_info = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250, 615 .driver_info = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250,
549 }, 616 },
617 {
618 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
619 .idVendor = 0x06e1, /* Vendor ID of ADS Technologies */
620 .idProduct = 0x0709, /* Product ID of DVD Xpress DX2 */
621 .bcdDevice_lo = 0x204,
622 .bcdDevice_hi = 0x204,
623 .driver_info = (kernel_ulong_t)GO7007_BOARDID_ADS_USBAV_709,
624 },
550 { } /* Terminating entry */ 625 { } /* Terminating entry */
551}; 626};
552 627
@@ -578,6 +653,8 @@ static int go7007_usb_interface_reset(struct go7007 *go)
578 struct go7007_usb *usb = go->hpi_context; 653 struct go7007_usb *usb = go->hpi_context;
579 u16 intr_val, intr_data; 654 u16 intr_val, intr_data;
580 655
656 if (go->status == STATUS_SHUTDOWN)
657 return -1;
581 /* Reset encoder */ 658 /* Reset encoder */
582 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0) 659 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
583 return -1; 660 return -1;
@@ -613,7 +690,7 @@ static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
613{ 690{
614 struct go7007_usb *usb = go->hpi_context; 691 struct go7007_usb *usb = go->hpi_context;
615 int i, r; 692 int i, r;
616 u16 status_reg; 693 u16 status_reg = 0;
617 int timeout = 500; 694 int timeout = 500;
618 695
619#ifdef GO7007_USB_DEBUG 696#ifdef GO7007_USB_DEBUG
@@ -625,15 +702,17 @@ static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
625 r = usb_control_msg(usb->usbdev, 702 r = usb_control_msg(usb->usbdev,
626 usb_rcvctrlpipe(usb->usbdev, 0), 0x14, 703 usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
627 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 704 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
628 0, HPI_STATUS_ADDR, &status_reg, 705 0, HPI_STATUS_ADDR, go->usb_buf,
629 sizeof(status_reg), timeout); 706 sizeof(status_reg), timeout);
630 if (r < 0) 707 if (r < 0)
631 goto write_int_error; 708 break;
632 __le16_to_cpus(&status_reg); 709 status_reg = le16_to_cpu(*((u16 *)go->usb_buf));
633 if (!(status_reg & 0x0010)) 710 if (!(status_reg & 0x0010))
634 break; 711 break;
635 msleep(10); 712 msleep(10);
636 } 713 }
714 if (r < 0)
715 goto write_int_error;
637 if (i == 100) { 716 if (i == 100) {
638 printk(KERN_ERR 717 printk(KERN_ERR
639 "go7007-usb: device is hung, status reg = 0x%04x\n", 718 "go7007-usb: device is hung, status reg = 0x%04x\n",
@@ -661,7 +740,6 @@ static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
661 int addr, int data) 740 int addr, int data)
662{ 741{
663 struct go7007_usb *usb = go->hpi_context; 742 struct go7007_usb *usb = go->hpi_context;
664 u8 *tbuf;
665 int r; 743 int r;
666 int timeout = 500; 744 int timeout = 500;
667 745
@@ -670,17 +748,14 @@ static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
670 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data); 748 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
671#endif 749#endif
672 750
673 tbuf = kzalloc(8, GFP_KERNEL); 751 go->usb_buf[0] = data & 0xff;
674 if (tbuf == NULL) 752 go->usb_buf[1] = data >> 8;
675 return -ENOMEM; 753 go->usb_buf[2] = addr & 0xff;
676 tbuf[0] = data & 0xff; 754 go->usb_buf[3] = addr >> 8;
677 tbuf[1] = data >> 8; 755 go->usb_buf[4] = go->usb_buf[5] = go->usb_buf[6] = go->usb_buf[7] = 0;
678 tbuf[2] = addr & 0xff;
679 tbuf[3] = addr >> 8;
680 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00, 756 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
681 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa, 757 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
682 0xf0f0, tbuf, 8, timeout); 758 0xf0f0, go->usb_buf, 8, timeout);
683 kfree(tbuf);
684 if (r < 0) { 759 if (r < 0) {
685 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r); 760 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
686 return r; 761 return r;
@@ -738,7 +813,7 @@ static void go7007_usb_read_video_pipe_complete(struct urb *urb)
738 struct go7007 *go = (struct go7007 *)urb->context; 813 struct go7007 *go = (struct go7007 *)urb->context;
739 int r, status = urb->status; 814 int r, status = urb->status;
740 815
741 if (!go->streaming) { 816 if (!vb2_is_streaming(&go->vidq)) {
742 wake_up_interruptible(&go->frame_waitq); 817 wake_up_interruptible(&go->frame_waitq);
743 return; 818 return;
744 } 819 }
@@ -762,7 +837,7 @@ static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
762 struct go7007 *go = (struct go7007 *)urb->context; 837 struct go7007 *go = (struct go7007 *)urb->context;
763 int r, status = urb->status; 838 int r, status = urb->status;
764 839
765 if (!go->streaming) 840 if (!vb2_is_streaming(&go->vidq))
766 return; 841 return;
767 if (status) { 842 if (status) {
768 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n", 843 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n",
@@ -849,6 +924,37 @@ static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
849 &transferred, timeout); 924 &transferred, timeout);
850} 925}
851 926
927static void go7007_usb_release(struct go7007 *go)
928{
929 struct go7007_usb *usb = go->hpi_context;
930 struct urb *vurb, *aurb;
931 int i;
932
933 if (usb->intr_urb) {
934 usb_kill_urb(usb->intr_urb);
935 kfree(usb->intr_urb->transfer_buffer);
936 usb_free_urb(usb->intr_urb);
937 }
938
939 /* Free USB-related structs */
940 for (i = 0; i < 8; ++i) {
941 vurb = usb->video_urbs[i];
942 if (vurb) {
943 usb_kill_urb(vurb);
944 kfree(vurb->transfer_buffer);
945 usb_free_urb(vurb);
946 }
947 aurb = usb->audio_urbs[i];
948 if (aurb) {
949 usb_kill_urb(aurb);
950 kfree(aurb->transfer_buffer);
951 usb_free_urb(aurb);
952 }
953 }
954
955 kfree(go->hpi_context);
956}
957
852static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = { 958static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
853 .interface_reset = go7007_usb_interface_reset, 959 .interface_reset = go7007_usb_interface_reset,
854 .write_interrupt = go7007_usb_ezusb_write_interrupt, 960 .write_interrupt = go7007_usb_ezusb_write_interrupt,
@@ -856,6 +962,7 @@ static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
856 .stream_start = go7007_usb_stream_start, 962 .stream_start = go7007_usb_stream_start,
857 .stream_stop = go7007_usb_stream_stop, 963 .stream_stop = go7007_usb_stream_stop,
858 .send_firmware = go7007_usb_send_firmware, 964 .send_firmware = go7007_usb_send_firmware,
965 .release = go7007_usb_release,
859}; 966};
860 967
861static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = { 968static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
@@ -865,6 +972,7 @@ static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
865 .stream_start = go7007_usb_stream_start, 972 .stream_start = go7007_usb_stream_start,
866 .stream_stop = go7007_usb_stream_stop, 973 .stream_stop = go7007_usb_stream_stop,
867 .send_firmware = go7007_usb_send_firmware, 974 .send_firmware = go7007_usb_send_firmware,
975 .release = go7007_usb_release,
868}; 976};
869 977
870/********************* Driver for EZ-USB I2C adapter *********************/ 978/********************* Driver for EZ-USB I2C adapter *********************/
@@ -874,12 +982,12 @@ static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
874{ 982{
875 struct go7007 *go = i2c_get_adapdata(adapter); 983 struct go7007 *go = i2c_get_adapdata(adapter);
876 struct go7007_usb *usb = go->hpi_context; 984 struct go7007_usb *usb = go->hpi_context;
877 u8 buf[16]; 985 u8 *buf = go->usb_buf;
878 int buf_len, i; 986 int buf_len, i;
879 int ret = -1; 987 int ret = -EIO;
880 988
881 if (go->status == STATUS_SHUTDOWN) 989 if (go->status == STATUS_SHUTDOWN)
882 return -1; 990 return -ENODEV;
883 991
884 mutex_lock(&usb->i2c_lock); 992 mutex_lock(&usb->i2c_lock);
885 993
@@ -929,14 +1037,14 @@ static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
929 buf, buf_len, 0) < 0) 1037 buf, buf_len, 0) < 0)
930 goto i2c_done; 1038 goto i2c_done;
931 if (msgs[i].flags & I2C_M_RD) { 1039 if (msgs[i].flags & I2C_M_RD) {
932 memset(buf, 0, sizeof(buf)); 1040 memset(buf, 0, msgs[i].len + 1);
933 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf, 1041 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
934 msgs[i].len + 1, 1) < 0) 1042 msgs[i].len + 1, 1) < 0)
935 goto i2c_done; 1043 goto i2c_done;
936 memcpy(msgs[i].buf, buf + 1, msgs[i].len); 1044 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
937 } 1045 }
938 } 1046 }
939 ret = 0; 1047 ret = num;
940 1048
941i2c_done: 1049i2c_done:
942 mutex_unlock(&usb->i2c_lock); 1050 mutex_unlock(&usb->i2c_lock);
@@ -968,8 +1076,9 @@ static int go7007_usb_probe(struct usb_interface *intf,
968{ 1076{
969 struct go7007 *go; 1077 struct go7007 *go;
970 struct go7007_usb *usb; 1078 struct go7007_usb *usb;
971 struct go7007_usb_board *board; 1079 const struct go7007_usb_board *board;
972 struct usb_device *usbdev = interface_to_usbdev(intf); 1080 struct usb_device *usbdev = interface_to_usbdev(intf);
1081 unsigned num_i2c_devs;
973 char *name; 1082 char *name;
974 int video_pipe, i, v_urb_len; 1083 int video_pipe, i, v_urb_len;
975 1084
@@ -1008,7 +1117,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
1008 name = "Plextor PX-M402U"; 1117 name = "Plextor PX-M402U";
1009 board = &board_matrix_ii; 1118 board = &board_matrix_ii;
1010 break; 1119 break;
1011 case GO7007_BOARDID_PX_TV402U_ANY: 1120 case GO7007_BOARDID_PX_TV402U:
1012 name = "Plextor PX-TV402U (unknown tuner)"; 1121 name = "Plextor PX-TV402U (unknown tuner)";
1013 board = &board_px_tv402u; 1122 board = &board_px_tv402u;
1014 break; 1123 break;
@@ -1024,29 +1133,29 @@ static int go7007_usb_probe(struct usb_interface *intf,
1024 name = "Sensoray 2250/2251"; 1133 name = "Sensoray 2250/2251";
1025 board = &board_sensoray_2250; 1134 board = &board_sensoray_2250;
1026 break; 1135 break;
1136 case GO7007_BOARDID_ADS_USBAV_709:
1137 name = "ADS Tech DVD Xpress DX2";
1138 board = &board_ads_usbav_709;
1139 break;
1027 default: 1140 default:
1028 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n", 1141 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n",
1029 (unsigned int)id->driver_info); 1142 (unsigned int)id->driver_info);
1030 return 0; 1143 return 0;
1031 } 1144 }
1032 1145
1033 usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL); 1146 go = go7007_alloc(&board->main_info, &intf->dev);
1034 if (usb == NULL) 1147 if (go == NULL)
1035 return -ENOMEM; 1148 return -ENOMEM;
1036 1149
1037 /* Allocate the URB and buffer for receiving incoming interrupts */ 1150 usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
1038 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL); 1151 if (usb == NULL) {
1039 if (usb->intr_urb == NULL) 1152 kfree(go);
1040 goto allocfail; 1153 return -ENOMEM;
1041 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL); 1154 }
1042 if (usb->intr_urb->transfer_buffer == NULL)
1043 goto allocfail;
1044 1155
1045 go = go7007_alloc(&board->main_info, &intf->dev);
1046 if (go == NULL)
1047 goto allocfail;
1048 usb->board = board; 1156 usb->board = board;
1049 usb->usbdev = usbdev; 1157 usb->usbdev = usbdev;
1158 usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
1050 go->board_id = id->driver_info; 1159 go->board_id = id->driver_info;
1051 strncpy(go->name, name, sizeof(go->name)); 1160 strncpy(go->name, name, sizeof(go->name));
1052 if (board->flags & GO7007_USB_EZUSB) 1161 if (board->flags & GO7007_USB_EZUSB)
@@ -1054,6 +1163,15 @@ static int go7007_usb_probe(struct usb_interface *intf,
1054 else 1163 else
1055 go->hpi_ops = &go7007_usb_onboard_hpi_ops; 1164 go->hpi_ops = &go7007_usb_onboard_hpi_ops;
1056 go->hpi_context = usb; 1165 go->hpi_context = usb;
1166
1167 /* Allocate the URB and buffer for receiving incoming interrupts */
1168 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
1169 if (usb->intr_urb == NULL)
1170 goto allocfail;
1171 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
1172 if (usb->intr_urb->transfer_buffer == NULL)
1173 goto allocfail;
1174
1057 if (go->board_id == GO7007_BOARDID_SENSORAY_2250) 1175 if (go->board_id == GO7007_BOARDID_SENSORAY_2250)
1058 usb_fill_bulk_urb(usb->intr_urb, usb->usbdev, 1176 usb_fill_bulk_urb(usb->intr_urb, usb->usbdev,
1059 usb_rcvbulkpipe(usb->usbdev, 4), 1177 usb_rcvbulkpipe(usb->usbdev, 4),
@@ -1069,7 +1187,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
1069 /* Boot the GO7007 */ 1187 /* Boot the GO7007 */
1070 if (go7007_boot_encoder(go, go->board_info->flags & 1188 if (go7007_boot_encoder(go, go->board_info->flags &
1071 GO7007_BOARD_USE_ONBOARD_I2C) < 0) 1189 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1072 goto initfail; 1190 goto allocfail;
1073 1191
1074 /* Register the EZ-USB I2C adapter, if we're using it */ 1192 /* Register the EZ-USB I2C adapter, if we're using it */
1075 if (board->flags & GO7007_USB_EZUSB_I2C) { 1193 if (board->flags & GO7007_USB_EZUSB_I2C) {
@@ -1081,7 +1199,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
1081 if (i2c_add_adapter(&go->i2c_adapter) < 0) { 1199 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1082 printk(KERN_ERR 1200 printk(KERN_ERR
1083 "go7007-usb: error: i2c_add_adapter failed\n"); 1201 "go7007-usb: error: i2c_add_adapter failed\n");
1084 goto initfail; 1202 goto allocfail;
1085 } 1203 }
1086 go->i2c_adapter_online = 1; 1204 go->i2c_adapter_online = 1;
1087 } 1205 }
@@ -1121,34 +1239,36 @@ static int go7007_usb_probe(struct usb_interface *intf,
1121 "Adlink PCI-MPG24, channel #%d", 1239 "Adlink PCI-MPG24, channel #%d",
1122 channel); 1240 channel);
1123 } 1241 }
1242 go7007_update_board(go);
1124 } 1243 }
1125 } 1244 }
1126 1245
1127 /* Probe the tuner model on the TV402U */ 1246 num_i2c_devs = go->board_info->num_i2c_devs;
1128 if (go->board_id == GO7007_BOARDID_PX_TV402U_ANY) {
1129 u8 data[3];
1130 1247
1248 /* Probe the tuner model on the TV402U */
1249 if (go->board_id == GO7007_BOARDID_PX_TV402U) {
1131 /* Board strapping indicates tuner model */ 1250 /* Board strapping indicates tuner model */
1132 if (go7007_usb_vendor_request(go, 0x41, 0, 0, data, 3, 1) < 0) { 1251 if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3, 1) < 0) {
1133 printk(KERN_ERR "go7007-usb: GPIO read failed!\n"); 1252 printk(KERN_ERR "go7007-usb: GPIO read failed!\n");
1134 goto initfail; 1253 goto allocfail;
1135 } 1254 }
1136 switch (data[0] >> 6) { 1255 switch (go->usb_buf[0] >> 6) {
1137 case 1: 1256 case 1:
1138 go->board_id = GO7007_BOARDID_PX_TV402U_EU;
1139 go->tuner_type = TUNER_SONY_BTF_PG472Z; 1257 go->tuner_type = TUNER_SONY_BTF_PG472Z;
1258 go->std = V4L2_STD_PAL;
1140 strncpy(go->name, "Plextor PX-TV402U-EU", 1259 strncpy(go->name, "Plextor PX-TV402U-EU",
1141 sizeof(go->name)); 1260 sizeof(go->name));
1142 break; 1261 break;
1143 case 2: 1262 case 2:
1144 go->board_id = GO7007_BOARDID_PX_TV402U_JP;
1145 go->tuner_type = TUNER_SONY_BTF_PK467Z; 1263 go->tuner_type = TUNER_SONY_BTF_PK467Z;
1264 go->std = V4L2_STD_NTSC_M_JP;
1265 num_i2c_devs -= 2;
1146 strncpy(go->name, "Plextor PX-TV402U-JP", 1266 strncpy(go->name, "Plextor PX-TV402U-JP",
1147 sizeof(go->name)); 1267 sizeof(go->name));
1148 break; 1268 break;
1149 case 3: 1269 case 3:
1150 go->board_id = GO7007_BOARDID_PX_TV402U_NA;
1151 go->tuner_type = TUNER_SONY_BTF_PB463Z; 1270 go->tuner_type = TUNER_SONY_BTF_PB463Z;
1271 num_i2c_devs -= 2;
1152 strncpy(go->name, "Plextor PX-TV402U-NA", 1272 strncpy(go->name, "Plextor PX-TV402U-NA",
1153 sizeof(go->name)); 1273 sizeof(go->name));
1154 break; 1274 break;
@@ -1162,7 +1282,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
1162 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0, 1282 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1163 NULL, 0, 0) < 0) { 1283 NULL, 0, 0) < 0) {
1164 printk(KERN_ERR "go7007-usb: GPIO write failed!\n"); 1284 printk(KERN_ERR "go7007-usb: GPIO write failed!\n");
1165 goto initfail; 1285 goto allocfail;
1166 } 1286 }
1167 } 1287 }
1168 1288
@@ -1176,11 +1296,6 @@ static int go7007_usb_probe(struct usb_interface *intf,
1176 "port will result in stream corruption, even " 1296 "port will result in stream corruption, even "
1177 "at low bitrates!\n"); 1297 "at low bitrates!\n");
1178 1298
1179 /* Do any final GO7007 initialization, then register the
1180 * V4L2 and ALSA interfaces */
1181 if (go7007_register_encoder(go) < 0)
1182 goto initfail;
1183
1184 /* Allocate the URBs and buffers for receiving the video stream */ 1299 /* Allocate the URBs and buffers for receiving the video stream */
1185 if (board->flags & GO7007_USB_EZUSB) { 1300 if (board->flags & GO7007_USB_EZUSB) {
1186 v_urb_len = 1024; 1301 v_urb_len = 1024;
@@ -1192,80 +1307,65 @@ static int go7007_usb_probe(struct usb_interface *intf,
1192 for (i = 0; i < 8; ++i) { 1307 for (i = 0; i < 8; ++i) {
1193 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL); 1308 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1194 if (usb->video_urbs[i] == NULL) 1309 if (usb->video_urbs[i] == NULL)
1195 goto initfail; 1310 goto allocfail;
1196 usb->video_urbs[i]->transfer_buffer = 1311 usb->video_urbs[i]->transfer_buffer =
1197 kmalloc(v_urb_len, GFP_KERNEL); 1312 kmalloc(v_urb_len, GFP_KERNEL);
1198 if (usb->video_urbs[i]->transfer_buffer == NULL) 1313 if (usb->video_urbs[i]->transfer_buffer == NULL)
1199 goto initfail; 1314 goto allocfail;
1200 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe, 1315 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1201 usb->video_urbs[i]->transfer_buffer, v_urb_len, 1316 usb->video_urbs[i]->transfer_buffer, v_urb_len,
1202 go7007_usb_read_video_pipe_complete, go); 1317 go7007_usb_read_video_pipe_complete, go);
1203 } 1318 }
1204 1319
1205 /* Allocate the URBs and buffers for receiving the audio stream */ 1320 /* Allocate the URBs and buffers for receiving the audio stream */
1206 if ((board->flags & GO7007_USB_EZUSB) && go->audio_enabled) 1321 if ((board->flags & GO7007_USB_EZUSB) &&
1322 (board->flags & GO7007_BOARD_HAS_AUDIO)) {
1207 for (i = 0; i < 8; ++i) { 1323 for (i = 0; i < 8; ++i) {
1208 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL); 1324 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1209 if (usb->audio_urbs[i] == NULL) 1325 if (usb->audio_urbs[i] == NULL)
1210 goto initfail; 1326 goto allocfail;
1211 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096, 1327 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1212 GFP_KERNEL); 1328 GFP_KERNEL);
1213 if (usb->audio_urbs[i]->transfer_buffer == NULL) 1329 if (usb->audio_urbs[i]->transfer_buffer == NULL)
1214 goto initfail; 1330 goto allocfail;
1215 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev, 1331 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1216 usb_rcvbulkpipe(usb->usbdev, 8), 1332 usb_rcvbulkpipe(usb->usbdev, 8),
1217 usb->audio_urbs[i]->transfer_buffer, 4096, 1333 usb->audio_urbs[i]->transfer_buffer, 4096,
1218 go7007_usb_read_audio_pipe_complete, go); 1334 go7007_usb_read_audio_pipe_complete, go);
1219 } 1335 }
1336 }
1220 1337
1338 /* Do any final GO7007 initialization, then register the
1339 * V4L2 and ALSA interfaces */
1340 if (go7007_register_encoder(go, num_i2c_devs) < 0)
1341 goto allocfail;
1221 1342
1222 go->status = STATUS_ONLINE; 1343 go->status = STATUS_ONLINE;
1223 return 0; 1344 return 0;
1224 1345
1225initfail:
1226 go->status = STATUS_SHUTDOWN;
1227 return 0;
1228
1229allocfail: 1346allocfail:
1230 if (usb->intr_urb) { 1347 go7007_usb_release(go);
1231 kfree(usb->intr_urb->transfer_buffer); 1348 kfree(go);
1232 usb_free_urb(usb->intr_urb);
1233 }
1234 kfree(usb);
1235 return -ENOMEM; 1349 return -ENOMEM;
1236} 1350}
1237 1351
1238static void go7007_usb_disconnect(struct usb_interface *intf) 1352static void go7007_usb_disconnect(struct usb_interface *intf)
1239{ 1353{
1240 struct go7007 *go = to_go7007(usb_get_intfdata(intf)); 1354 struct go7007 *go = to_go7007(usb_get_intfdata(intf));
1241 struct go7007_usb *usb = go->hpi_context;
1242 struct urb *vurb, *aurb;
1243 int i;
1244 1355
1245 usb_kill_urb(usb->intr_urb); 1356 mutex_lock(&go->queue_lock);
1357 mutex_lock(&go->serialize_lock);
1246 1358
1247 /* Free USB-related structs */ 1359 if (go->audio_enabled)
1248 for (i = 0; i < 8; ++i) { 1360 go7007_snd_remove(go);
1249 vurb = usb->video_urbs[i];
1250 if (vurb) {
1251 usb_kill_urb(vurb);
1252 kfree(vurb->transfer_buffer);
1253 usb_free_urb(vurb);
1254 }
1255 aurb = usb->audio_urbs[i];
1256 if (aurb) {
1257 usb_kill_urb(aurb);
1258 kfree(aurb->transfer_buffer);
1259 usb_free_urb(aurb);
1260 }
1261 }
1262 kfree(usb->intr_urb->transfer_buffer);
1263 usb_free_urb(usb->intr_urb);
1264
1265 kfree(go->hpi_context);
1266 1361
1267 go7007_remove(go);
1268 go->status = STATUS_SHUTDOWN; 1362 go->status = STATUS_SHUTDOWN;
1363 v4l2_device_disconnect(&go->v4l2_dev);
1364 video_unregister_device(&go->vdev);
1365 mutex_unlock(&go->serialize_lock);
1366 mutex_unlock(&go->queue_lock);
1367
1368 v4l2_device_put(&go->v4l2_dev);
1269} 1369}
1270 1370
1271static struct usb_driver go7007_usb_driver = { 1371static 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 cb9fe33050c7..50eb69a8ef07 100644
--- a/drivers/staging/media/go7007/go7007-v4l2.c
+++ b/drivers/staging/media/go7007/go7007-v4l2.c
@@ -17,7 +17,6 @@
17 17
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/version.h>
21#include <linux/delay.h> 20#include <linux/delay.h>
22#include <linux/sched.h> 21#include <linux/sched.h>
23#include <linux/spinlock.h> 22#include <linux/spinlock.h>
@@ -27,115 +26,45 @@
27#include <linux/time.h> 26#include <linux/time.h>
28#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
29#include <linux/pagemap.h> 28#include <linux/pagemap.h>
29#include <linux/i2c.h>
30#include <linux/mutex.h>
31#include <linux/uaccess.h>
30#include <linux/videodev2.h> 32#include <linux/videodev2.h>
31#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
32#include <media/v4l2-ioctl.h> 34#include <media/v4l2-ioctl.h>
33#include <media/v4l2-subdev.h> 35#include <media/v4l2-subdev.h>
34#include <linux/i2c.h> 36#include <media/v4l2-event.h>
35#include <linux/mutex.h> 37#include <media/videobuf2-vmalloc.h>
36#include <linux/uaccess.h> 38#include <media/saa7115.h>
37 39
38#include "go7007.h" 40#include "go7007.h"
39#include "go7007-priv.h" 41#include "go7007-priv.h"
40#include "wis-i2c.h"
41
42/* Temporary defines until accepted in v4l-dvb */
43#ifndef V4L2_MPEG_STREAM_TYPE_MPEG_ELEM
44#define V4L2_MPEG_STREAM_TYPE_MPEG_ELEM 6 /* MPEG elementary stream */
45#endif
46#ifndef V4L2_MPEG_VIDEO_ENCODING_MPEG_4
47#define V4L2_MPEG_VIDEO_ENCODING_MPEG_4 3
48#endif
49 42
50#define call_all(dev, o, f, args...) \ 43#define call_all(dev, o, f, args...) \
51 v4l2_device_call_until_err(dev, 0, o, f, ##args) 44 v4l2_device_call_until_err(dev, 0, o, f, ##args)
52 45
53static void deactivate_buffer(struct go7007_buffer *gobuf) 46static bool valid_pixelformat(u32 pixelformat)
54{
55 int i;
56
57 if (gobuf->state != BUF_STATE_IDLE) {
58 list_del(&gobuf->stream);
59 gobuf->state = BUF_STATE_IDLE;
60 }
61 if (gobuf->page_count > 0) {
62 for (i = 0; i < gobuf->page_count; ++i)
63 page_cache_release(gobuf->pages[i]);
64 gobuf->page_count = 0;
65 }
66}
67
68static void abort_queued(struct go7007 *go)
69{
70 struct go7007_buffer *gobuf, *next;
71
72 list_for_each_entry_safe(gobuf, next, &go->stream, stream) {
73 deactivate_buffer(gobuf);
74 }
75}
76
77static int go7007_streamoff(struct go7007 *go)
78{
79 unsigned long flags;
80
81 mutex_lock(&go->hw_lock);
82 if (go->streaming) {
83 go->streaming = 0;
84 go7007_stream_stop(go);
85 spin_lock_irqsave(&go->spinlock, flags);
86 abort_queued(go);
87 spin_unlock_irqrestore(&go->spinlock, flags);
88 go7007_reset_encoder(go);
89 }
90 mutex_unlock(&go->hw_lock);
91 return 0;
92}
93
94static int go7007_open(struct file *file)
95{
96 struct go7007 *go = video_get_drvdata(video_devdata(file));
97 struct go7007_file *gofh;
98
99 if (go->status != STATUS_ONLINE)
100 return -EBUSY;
101 gofh = kzalloc(sizeof(struct go7007_file), GFP_KERNEL);
102 if (gofh == NULL)
103 return -ENOMEM;
104 ++go->ref_count;
105 gofh->go = go;
106 mutex_init(&gofh->lock);
107 gofh->buf_count = 0;
108 file->private_data = gofh;
109 return 0;
110}
111
112static int go7007_release(struct file *file)
113{ 47{
114 struct go7007_file *gofh = file->private_data; 48 switch (pixelformat) {
115 struct go7007 *go = gofh->go; 49 case V4L2_PIX_FMT_MJPEG:
116 50 case V4L2_PIX_FMT_MPEG1:
117 if (gofh->buf_count > 0) { 51 case V4L2_PIX_FMT_MPEG2:
118 go7007_streamoff(go); 52 case V4L2_PIX_FMT_MPEG4:
119 go->in_use = 0; 53 return true;
120 kfree(gofh->bufs); 54 default:
121 gofh->buf_count = 0; 55 return false;
122 } 56 }
123 kfree(gofh);
124 if (--go->ref_count == 0)
125 kfree(go);
126 file->private_data = NULL;
127 return 0;
128} 57}
129 58
130static u32 get_frame_type_flag(struct go7007_buffer *gobuf, int format) 59static u32 get_frame_type_flag(struct go7007_buffer *vb, int format)
131{ 60{
132 u8 *f = page_address(gobuf->pages[0]); 61 u8 *ptr = vb2_plane_vaddr(&vb->vb, 0);
133 62
134 switch (format) { 63 switch (format) {
135 case GO7007_FORMAT_MJPEG: 64 case V4L2_PIX_FMT_MJPEG:
136 return V4L2_BUF_FLAG_KEYFRAME; 65 return V4L2_BUF_FLAG_KEYFRAME;
137 case GO7007_FORMAT_MPEG4: 66 case V4L2_PIX_FMT_MPEG4:
138 switch ((f[gobuf->frame_offset + 4] >> 6) & 0x3) { 67 switch ((ptr[vb->frame_offset + 4] >> 6) & 0x3) {
139 case 0: 68 case 0:
140 return V4L2_BUF_FLAG_KEYFRAME; 69 return V4L2_BUF_FLAG_KEYFRAME;
141 case 1: 70 case 1:
@@ -145,9 +74,9 @@ static u32 get_frame_type_flag(struct go7007_buffer *gobuf, int format)
145 default: 74 default:
146 return 0; 75 return 0;
147 } 76 }
148 case GO7007_FORMAT_MPEG1: 77 case V4L2_PIX_FMT_MPEG1:
149 case GO7007_FORMAT_MPEG2: 78 case V4L2_PIX_FMT_MPEG2:
150 switch ((f[gobuf->frame_offset + 5] >> 3) & 0x7) { 79 switch ((ptr[vb->frame_offset + 5] >> 3) & 0x7) {
151 case 1: 80 case 1:
152 return V4L2_BUF_FLAG_KEYFRAME; 81 return V4L2_BUF_FLAG_KEYFRAME;
153 case 2: 82 case 2:
@@ -162,30 +91,111 @@ static u32 get_frame_type_flag(struct go7007_buffer *gobuf, int format)
162 return 0; 91 return 0;
163} 92}
164 93
165static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try) 94static void get_resolution(struct go7007 *go, int *width, int *height)
166{ 95{
167 int sensor_height = 0, sensor_width = 0;
168 int width, height, i;
169
170 if (fmt != NULL && fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG &&
171 fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MPEG &&
172 fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MPEG4)
173 return -EINVAL;
174
175 switch (go->standard) { 96 switch (go->standard) {
176 case GO7007_STD_NTSC: 97 case GO7007_STD_NTSC:
177 sensor_width = 720; 98 *width = 720;
178 sensor_height = 480; 99 *height = 480;
179 break; 100 break;
180 case GO7007_STD_PAL: 101 case GO7007_STD_PAL:
181 sensor_width = 720; 102 *width = 720;
182 sensor_height = 576; 103 *height = 576;
183 break; 104 break;
184 case GO7007_STD_OTHER: 105 case GO7007_STD_OTHER:
185 sensor_width = go->board_info->sensor_width; 106 default:
186 sensor_height = go->board_info->sensor_height; 107 *width = go->board_info->sensor_width;
108 *height = go->board_info->sensor_height;
109 break;
110 }
111}
112
113static void set_formatting(struct go7007 *go)
114{
115 if (go->format == V4L2_PIX_FMT_MJPEG) {
116 go->pali = 0;
117 go->aspect_ratio = GO7007_RATIO_1_1;
118 go->gop_size = 0;
119 go->ipb = 0;
120 go->closed_gop = 0;
121 go->repeat_seqhead = 0;
122 go->seq_header_enable = 0;
123 go->gop_header_enable = 0;
124 go->dvd_mode = 0;
125 return;
126 }
127
128 switch (go->format) {
129 case V4L2_PIX_FMT_MPEG1:
130 go->pali = 0;
131 break;
132 default:
133 case V4L2_PIX_FMT_MPEG2:
134 go->pali = 0x48;
135 break;
136 case V4L2_PIX_FMT_MPEG4:
137 /* For future reference: this is the list of MPEG4
138 * profiles that are available, although they are
139 * untested:
140 *
141 * Profile pali
142 * -------------- ----
143 * PROFILE_S_L0 0x08
144 * PROFILE_S_L1 0x01
145 * PROFILE_S_L2 0x02
146 * PROFILE_S_L3 0x03
147 * PROFILE_ARTS_L1 0x91
148 * PROFILE_ARTS_L2 0x92
149 * PROFILE_ARTS_L3 0x93
150 * PROFILE_ARTS_L4 0x94
151 * PROFILE_AS_L0 0xf0
152 * PROFILE_AS_L1 0xf1
153 * PROFILE_AS_L2 0xf2
154 * PROFILE_AS_L3 0xf3
155 * PROFILE_AS_L4 0xf4
156 * PROFILE_AS_L5 0xf5
157 */
158 go->pali = 0xf5;
159 break;
160 }
161 go->gop_size = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_size);
162 go->closed_gop = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_closure);
163 go->ipb = v4l2_ctrl_g_ctrl(go->mpeg_video_b_frames) != 0;
164 go->bitrate = v4l2_ctrl_g_ctrl(go->mpeg_video_bitrate);
165 go->repeat_seqhead = v4l2_ctrl_g_ctrl(go->mpeg_video_rep_seqheader);
166 go->gop_header_enable = 1;
167 go->dvd_mode = 0;
168 if (go->format == V4L2_PIX_FMT_MPEG2)
169 go->dvd_mode =
170 go->bitrate == 9800000 &&
171 go->gop_size == 15 &&
172 go->ipb == 0 &&
173 go->repeat_seqhead == 1 &&
174 go->closed_gop;
175
176 switch (v4l2_ctrl_g_ctrl(go->mpeg_video_aspect_ratio)) {
177 default:
178 case V4L2_MPEG_VIDEO_ASPECT_1x1:
179 go->aspect_ratio = GO7007_RATIO_1_1;
180 break;
181 case V4L2_MPEG_VIDEO_ASPECT_4x3:
182 go->aspect_ratio = GO7007_RATIO_4_3;
183 break;
184 case V4L2_MPEG_VIDEO_ASPECT_16x9:
185 go->aspect_ratio = GO7007_RATIO_16_9;
187 break; 186 break;
188 } 187 }
188}
189
190static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
191{
192 int sensor_height = 0, sensor_width = 0;
193 int width, height, i;
194
195 if (fmt != NULL && !valid_pixelformat(fmt->fmt.pix.pixelformat))
196 return -EINVAL;
197
198 get_resolution(go, &sensor_width, &sensor_height);
189 199
190 if (fmt == NULL) { 200 if (fmt == NULL) {
191 width = sensor_width; 201 width = sensor_width;
@@ -205,13 +215,12 @@ static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
205 else 215 else
206 height = fmt->fmt.pix.height & ~0x0f; 216 height = fmt->fmt.pix.height & ~0x0f;
207 } else { 217 } else {
208 int requested_size = fmt->fmt.pix.width * fmt->fmt.pix.height; 218 width = fmt->fmt.pix.width;
209 int sensor_size = sensor_width * sensor_height;
210 219
211 if (64 * requested_size < 9 * sensor_size) { 220 if (width <= sensor_width / 4) {
212 width = sensor_width / 4; 221 width = sensor_width / 4;
213 height = sensor_height / 4; 222 height = sensor_height / 4;
214 } else if (64 * requested_size < 36 * sensor_size) { 223 } else if (width <= sensor_width / 2) {
215 width = sensor_width / 2; 224 width = sensor_width / 2;
216 height = sensor_height / 2; 225 height = sensor_height / 2;
217 } else { 226 } else {
@@ -233,12 +242,14 @@ static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
233 fmt->fmt.pix.field = V4L2_FIELD_NONE; 242 fmt->fmt.pix.field = V4L2_FIELD_NONE;
234 fmt->fmt.pix.bytesperline = 0; 243 fmt->fmt.pix.bytesperline = 0;
235 fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE; 244 fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE;
236 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* ?? */ 245 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
237 } 246 }
238 247
239 if (try) 248 if (try)
240 return 0; 249 return 0;
241 250
251 if (fmt)
252 go->format = fmt->fmt.pix.pixelformat;
242 go->width = width; 253 go->width = width;
243 go->height = height; 254 go->height = height;
244 go->encoder_h_offset = go->board_info->sensor_h_offset; 255 go->encoder_h_offset = go->board_info->sensor_h_offset;
@@ -252,18 +263,11 @@ static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
252 struct v4l2_mbus_framefmt mbus_fmt; 263 struct v4l2_mbus_framefmt mbus_fmt;
253 264
254 mbus_fmt.code = V4L2_MBUS_FMT_FIXED; 265 mbus_fmt.code = V4L2_MBUS_FMT_FIXED;
255 if (fmt != NULL) 266 mbus_fmt.width = fmt ? fmt->fmt.pix.width : width;
256 mbus_fmt.width = fmt->fmt.pix.width; 267 mbus_fmt.height = height;
257 else 268 go->encoder_h_halve = 0;
258 mbus_fmt.width = width; 269 go->encoder_v_halve = 0;
259 270 go->encoder_subsample = 0;
260 if (height > sensor_height / 2) {
261 mbus_fmt.height = height / 2;
262 go->encoder_v_halve = 0;
263 } else {
264 mbus_fmt.height = height;
265 go->encoder_v_halve = 1;
266 }
267 call_all(&go->v4l2_dev, video, s_mbus_fmt, &mbus_fmt); 271 call_all(&go->v4l2_dev, video, s_mbus_fmt, &mbus_fmt);
268 } else { 272 } else {
269 if (width <= sensor_width / 4) { 273 if (width <= sensor_width / 4) {
@@ -280,55 +284,6 @@ static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
280 go->encoder_subsample = 0; 284 go->encoder_subsample = 0;
281 } 285 }
282 } 286 }
283
284 if (fmt == NULL)
285 return 0;
286
287 switch (fmt->fmt.pix.pixelformat) {
288 case V4L2_PIX_FMT_MPEG:
289 if (go->format == GO7007_FORMAT_MPEG1 ||
290 go->format == GO7007_FORMAT_MPEG2 ||
291 go->format == GO7007_FORMAT_MPEG4)
292 break;
293 go->format = GO7007_FORMAT_MPEG1;
294 go->pali = 0;
295 go->aspect_ratio = GO7007_RATIO_1_1;
296 go->gop_size = go->sensor_framerate / 1000;
297 go->ipb = 0;
298 go->closed_gop = 1;
299 go->repeat_seqhead = 1;
300 go->seq_header_enable = 1;
301 go->gop_header_enable = 1;
302 go->dvd_mode = 0;
303 break;
304 /* Backwards compatibility only! */
305 case V4L2_PIX_FMT_MPEG4:
306 if (go->format == GO7007_FORMAT_MPEG4)
307 break;
308 go->format = GO7007_FORMAT_MPEG4;
309 go->pali = 0xf5;
310 go->aspect_ratio = GO7007_RATIO_1_1;
311 go->gop_size = go->sensor_framerate / 1000;
312 go->ipb = 0;
313 go->closed_gop = 1;
314 go->repeat_seqhead = 1;
315 go->seq_header_enable = 1;
316 go->gop_header_enable = 1;
317 go->dvd_mode = 0;
318 break;
319 case V4L2_PIX_FMT_MJPEG:
320 go->format = GO7007_FORMAT_MJPEG;
321 go->pali = 0;
322 go->aspect_ratio = GO7007_RATIO_1_1;
323 go->gop_size = 0;
324 go->ipb = 0;
325 go->closed_gop = 0;
326 go->repeat_seqhead = 0;
327 go->seq_header_enable = 0;
328 go->gop_header_enable = 0;
329 go->dvd_mode = 0;
330 break;
331 }
332 return 0; 287 return 0;
333} 288}
334 289
@@ -390,230 +345,23 @@ static int clip_to_modet_map(struct go7007 *go, int region,
390} 345}
391#endif 346#endif
392 347
393static int mpeg_query_ctrl(struct v4l2_queryctrl *ctrl)
394{
395 static const u32 mpeg_ctrls[] = {
396 V4L2_CID_MPEG_CLASS,
397 V4L2_CID_MPEG_STREAM_TYPE,
398 V4L2_CID_MPEG_VIDEO_ENCODING,
399 V4L2_CID_MPEG_VIDEO_ASPECT,
400 V4L2_CID_MPEG_VIDEO_GOP_SIZE,
401 V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
402 V4L2_CID_MPEG_VIDEO_BITRATE,
403 0
404 };
405 static const u32 *ctrl_classes[] = {
406 mpeg_ctrls,
407 NULL
408 };
409
410 ctrl->id = v4l2_ctrl_next(ctrl_classes, ctrl->id);
411
412 switch (ctrl->id) {
413 case V4L2_CID_MPEG_CLASS:
414 return v4l2_ctrl_query_fill(ctrl, 0, 0, 0, 0);
415 case V4L2_CID_MPEG_STREAM_TYPE:
416 return v4l2_ctrl_query_fill(ctrl,
417 V4L2_MPEG_STREAM_TYPE_MPEG2_DVD,
418 V4L2_MPEG_STREAM_TYPE_MPEG_ELEM, 1,
419 V4L2_MPEG_STREAM_TYPE_MPEG_ELEM);
420 case V4L2_CID_MPEG_VIDEO_ENCODING:
421 return v4l2_ctrl_query_fill(ctrl,
422 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
423 V4L2_MPEG_VIDEO_ENCODING_MPEG_4, 1,
424 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
425 case V4L2_CID_MPEG_VIDEO_ASPECT:
426 return v4l2_ctrl_query_fill(ctrl,
427 V4L2_MPEG_VIDEO_ASPECT_1x1,
428 V4L2_MPEG_VIDEO_ASPECT_16x9, 1,
429 V4L2_MPEG_VIDEO_ASPECT_1x1);
430 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
431 return v4l2_ctrl_query_fill(ctrl, 0, 34, 1, 15);
432 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
433 return v4l2_ctrl_query_fill(ctrl, 0, 1, 1, 0);
434 case V4L2_CID_MPEG_VIDEO_BITRATE:
435 return v4l2_ctrl_query_fill(ctrl,
436 64000,
437 10000000, 1,
438 1500000);
439 default:
440 return -EINVAL;
441 }
442 return 0;
443}
444
445static int mpeg_s_ctrl(struct v4l2_control *ctrl, struct go7007 *go)
446{
447 /* pretty sure we can't change any of these while streaming */
448 if (go->streaming)
449 return -EBUSY;
450
451 switch (ctrl->id) {
452 case V4L2_CID_MPEG_STREAM_TYPE:
453 switch (ctrl->value) {
454 case V4L2_MPEG_STREAM_TYPE_MPEG2_DVD:
455 go->format = GO7007_FORMAT_MPEG2;
456 go->bitrate = 9800000;
457 go->gop_size = 15;
458 go->pali = 0x48;
459 go->closed_gop = 1;
460 go->repeat_seqhead = 0;
461 go->seq_header_enable = 1;
462 go->gop_header_enable = 1;
463 go->dvd_mode = 1;
464 break;
465 case V4L2_MPEG_STREAM_TYPE_MPEG_ELEM:
466 /* todo: */
467 break;
468 default:
469 return -EINVAL;
470 }
471 break;
472 case V4L2_CID_MPEG_VIDEO_ENCODING:
473 switch (ctrl->value) {
474 case V4L2_MPEG_VIDEO_ENCODING_MPEG_1:
475 go->format = GO7007_FORMAT_MPEG1;
476 go->pali = 0;
477 break;
478 case V4L2_MPEG_VIDEO_ENCODING_MPEG_2:
479 go->format = GO7007_FORMAT_MPEG2;
480 /*if (mpeg->pali >> 24 == 2)
481 go->pali = mpeg->pali & 0xff;
482 else*/
483 go->pali = 0x48;
484 break;
485 case V4L2_MPEG_VIDEO_ENCODING_MPEG_4:
486 go->format = GO7007_FORMAT_MPEG4;
487 /*if (mpeg->pali >> 24 == 4)
488 go->pali = mpeg->pali & 0xff;
489 else*/
490 go->pali = 0xf5;
491 break;
492 default:
493 return -EINVAL;
494 }
495 go->gop_header_enable =
496 /*mpeg->flags & GO7007_MPEG_OMIT_GOP_HEADER
497 ? 0 :*/ 1;
498 /*if (mpeg->flags & GO7007_MPEG_REPEAT_SEQHEADER)
499 go->repeat_seqhead = 1;
500 else*/
501 go->repeat_seqhead = 0;
502 go->dvd_mode = 0;
503 break;
504 case V4L2_CID_MPEG_VIDEO_ASPECT:
505 if (go->format == GO7007_FORMAT_MJPEG)
506 return -EINVAL;
507 switch (ctrl->value) {
508 case V4L2_MPEG_VIDEO_ASPECT_1x1:
509 go->aspect_ratio = GO7007_RATIO_1_1;
510 break;
511 case V4L2_MPEG_VIDEO_ASPECT_4x3:
512 go->aspect_ratio = GO7007_RATIO_4_3;
513 break;
514 case V4L2_MPEG_VIDEO_ASPECT_16x9:
515 go->aspect_ratio = GO7007_RATIO_16_9;
516 break;
517 case V4L2_MPEG_VIDEO_ASPECT_221x100:
518 default:
519 return -EINVAL;
520 }
521 break;
522 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
523 if (ctrl->value < 0 || ctrl->value > 34)
524 return -EINVAL;
525 go->gop_size = ctrl->value;
526 break;
527 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
528 if (ctrl->value != 0 && ctrl->value != 1)
529 return -EINVAL;
530 go->closed_gop = ctrl->value;
531 break;
532 case V4L2_CID_MPEG_VIDEO_BITRATE:
533 /* Upper bound is kind of arbitrary here */
534 if (ctrl->value < 64000 || ctrl->value > 10000000)
535 return -EINVAL;
536 go->bitrate = ctrl->value;
537 break;
538 default:
539 return -EINVAL;
540 }
541 return 0;
542}
543
544static int mpeg_g_ctrl(struct v4l2_control *ctrl, struct go7007 *go)
545{
546 switch (ctrl->id) {
547 case V4L2_CID_MPEG_STREAM_TYPE:
548 if (go->dvd_mode)
549 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_DVD;
550 else
551 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG_ELEM;
552 break;
553 case V4L2_CID_MPEG_VIDEO_ENCODING:
554 switch (go->format) {
555 case GO7007_FORMAT_MPEG1:
556 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
557 break;
558 case GO7007_FORMAT_MPEG2:
559 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
560 break;
561 case GO7007_FORMAT_MPEG4:
562 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4;
563 break;
564 default:
565 return -EINVAL;
566 }
567 break;
568 case V4L2_CID_MPEG_VIDEO_ASPECT:
569 switch (go->aspect_ratio) {
570 case GO7007_RATIO_1_1:
571 ctrl->value = V4L2_MPEG_VIDEO_ASPECT_1x1;
572 break;
573 case GO7007_RATIO_4_3:
574 ctrl->value = V4L2_MPEG_VIDEO_ASPECT_4x3;
575 break;
576 case GO7007_RATIO_16_9:
577 ctrl->value = V4L2_MPEG_VIDEO_ASPECT_16x9;
578 break;
579 default:
580 return -EINVAL;
581 }
582 break;
583 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
584 ctrl->value = go->gop_size;
585 break;
586 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
587 ctrl->value = go->closed_gop;
588 break;
589 case V4L2_CID_MPEG_VIDEO_BITRATE:
590 ctrl->value = go->bitrate;
591 break;
592 default:
593 return -EINVAL;
594 }
595 return 0;
596}
597
598static int vidioc_querycap(struct file *file, void *priv, 348static int vidioc_querycap(struct file *file, void *priv,
599 struct v4l2_capability *cap) 349 struct v4l2_capability *cap)
600{ 350{
601 struct go7007 *go = ((struct go7007_file *) priv)->go; 351 struct go7007 *go = video_drvdata(file);
602 352
603 strlcpy(cap->driver, "go7007", sizeof(cap->driver)); 353 strlcpy(cap->driver, "go7007", sizeof(cap->driver));
604 strlcpy(cap->card, go->name, sizeof(cap->card)); 354 strlcpy(cap->card, go->name, sizeof(cap->card));
605#if 0 355 strlcpy(cap->bus_info, go->bus_info, sizeof(cap->bus_info));
606 strlcpy(cap->bus_info, dev_name(&dev->udev->dev), sizeof(cap->bus_info));
607#endif
608
609 cap->version = KERNEL_VERSION(0, 9, 8);
610 356
611 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 357 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
612 V4L2_CAP_STREAMING; /* | V4L2_CAP_AUDIO; */ 358 V4L2_CAP_STREAMING;
613 359
360 if (go->board_info->num_aud_inputs)
361 cap->device_caps |= V4L2_CAP_AUDIO;
614 if (go->board_info->flags & GO7007_BOARD_HAS_TUNER) 362 if (go->board_info->flags & GO7007_BOARD_HAS_TUNER)
615 cap->capabilities |= V4L2_CAP_TUNER; 363 cap->device_caps |= V4L2_CAP_TUNER;
616 364 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
617 return 0; 365 return 0;
618} 366}
619 367
@@ -625,11 +373,19 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
625 switch (fmt->index) { 373 switch (fmt->index) {
626 case 0: 374 case 0:
627 fmt->pixelformat = V4L2_PIX_FMT_MJPEG; 375 fmt->pixelformat = V4L2_PIX_FMT_MJPEG;
628 desc = "Motion-JPEG"; 376 desc = "Motion JPEG";
629 break; 377 break;
630 case 1: 378 case 1:
631 fmt->pixelformat = V4L2_PIX_FMT_MPEG; 379 fmt->pixelformat = V4L2_PIX_FMT_MPEG1;
632 desc = "MPEG1/MPEG2/MPEG4"; 380 desc = "MPEG-1 ES";
381 break;
382 case 2:
383 fmt->pixelformat = V4L2_PIX_FMT_MPEG2;
384 desc = "MPEG-2 ES";
385 break;
386 case 3:
387 fmt->pixelformat = V4L2_PIX_FMT_MPEG4;
388 desc = "MPEG-4 ES";
633 break; 389 break;
634 default: 390 default:
635 return -EINVAL; 391 return -EINVAL;
@@ -645,13 +401,12 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
645static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 401static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
646 struct v4l2_format *fmt) 402 struct v4l2_format *fmt)
647{ 403{
648 struct go7007 *go = ((struct go7007_file *) priv)->go; 404 struct go7007 *go = video_drvdata(file);
649 405
650 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 406 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
651 fmt->fmt.pix.width = go->width; 407 fmt->fmt.pix.width = go->width;
652 fmt->fmt.pix.height = go->height; 408 fmt->fmt.pix.height = go->height;
653 fmt->fmt.pix.pixelformat = (go->format == GO7007_FORMAT_MJPEG) ? 409 fmt->fmt.pix.pixelformat = go->format;
654 V4L2_PIX_FMT_MJPEG : V4L2_PIX_FMT_MPEG;
655 fmt->fmt.pix.field = V4L2_FIELD_NONE; 410 fmt->fmt.pix.field = V4L2_FIELD_NONE;
656 fmt->fmt.pix.bytesperline = 0; 411 fmt->fmt.pix.bytesperline = 0;
657 fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE; 412 fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE;
@@ -663,7 +418,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
663static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 418static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
664 struct v4l2_format *fmt) 419 struct v4l2_format *fmt)
665{ 420{
666 struct go7007 *go = ((struct go7007_file *) priv)->go; 421 struct go7007 *go = video_drvdata(file);
667 422
668 return set_capture_size(go, fmt, 1); 423 return set_capture_size(go, fmt, 1);
669} 424}
@@ -671,348 +426,137 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
671static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 426static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
672 struct v4l2_format *fmt) 427 struct v4l2_format *fmt)
673{ 428{
674 struct go7007 *go = ((struct go7007_file *) priv)->go; 429 struct go7007 *go = video_drvdata(file);
675 430
676 if (go->streaming) 431 if (vb2_is_busy(&go->vidq))
677 return -EBUSY; 432 return -EBUSY;
678 433
679 return set_capture_size(go, fmt, 0); 434 return set_capture_size(go, fmt, 0);
680} 435}
681 436
682static int vidioc_reqbufs(struct file *file, void *priv, 437static int go7007_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
683 struct v4l2_requestbuffers *req) 438 unsigned int *num_buffers, unsigned int *num_planes,
439 unsigned int sizes[], void *alloc_ctxs[])
684{ 440{
685 struct go7007_file *gofh = priv; 441 sizes[0] = GO7007_BUF_SIZE;
686 struct go7007 *go = gofh->go; 442 *num_planes = 1;
687 int retval = -EBUSY;
688 unsigned int count, i;
689
690 if (go->streaming)
691 return retval;
692
693 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
694 req->memory != V4L2_MEMORY_MMAP)
695 return -EINVAL;
696
697 mutex_lock(&gofh->lock);
698 for (i = 0; i < gofh->buf_count; ++i)
699 if (gofh->bufs[i].mapped > 0)
700 goto unlock_and_return;
701
702 mutex_lock(&go->hw_lock);
703 if (go->in_use > 0 && gofh->buf_count == 0) {
704 mutex_unlock(&go->hw_lock);
705 goto unlock_and_return;
706 }
707 443
708 if (gofh->buf_count > 0) 444 if (*num_buffers < 2)
709 kfree(gofh->bufs); 445 *num_buffers = 2;
710
711 retval = -ENOMEM;
712 count = req->count;
713 if (count > 0) {
714 if (count < 2)
715 count = 2;
716 if (count > 32)
717 count = 32;
718
719 gofh->bufs = kcalloc(count, sizeof(struct go7007_buffer),
720 GFP_KERNEL);
721
722 if (!gofh->bufs) {
723 mutex_unlock(&go->hw_lock);
724 goto unlock_and_return;
725 }
726
727 for (i = 0; i < count; ++i) {
728 gofh->bufs[i].go = go;
729 gofh->bufs[i].index = i;
730 gofh->bufs[i].state = BUF_STATE_IDLE;
731 gofh->bufs[i].mapped = 0;
732 }
733
734 go->in_use = 1;
735 } else {
736 go->in_use = 0;
737 }
738
739 gofh->buf_count = count;
740 mutex_unlock(&go->hw_lock);
741 mutex_unlock(&gofh->lock);
742
743 memset(req, 0, sizeof(*req));
744
745 req->count = count;
746 req->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
747 req->memory = V4L2_MEMORY_MMAP;
748
749 return 0;
750
751unlock_and_return:
752 mutex_unlock(&gofh->lock);
753 return retval;
754}
755
756static int vidioc_querybuf(struct file *file, void *priv,
757 struct v4l2_buffer *buf)
758{
759 struct go7007_file *gofh = priv;
760 int retval = -EINVAL;
761 unsigned int index;
762
763 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
764 return retval;
765
766 index = buf->index;
767
768 mutex_lock(&gofh->lock);
769 if (index >= gofh->buf_count)
770 goto unlock_and_return;
771
772 memset(buf, 0, sizeof(*buf));
773 buf->index = index;
774 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
775
776 switch (gofh->bufs[index].state) {
777 case BUF_STATE_QUEUED:
778 buf->flags = V4L2_BUF_FLAG_QUEUED;
779 break;
780 case BUF_STATE_DONE:
781 buf->flags = V4L2_BUF_FLAG_DONE;
782 break;
783 default:
784 buf->flags = 0;
785 }
786
787 if (gofh->bufs[index].mapped)
788 buf->flags |= V4L2_BUF_FLAG_MAPPED;
789 buf->memory = V4L2_MEMORY_MMAP;
790 buf->m.offset = index * GO7007_BUF_SIZE;
791 buf->length = GO7007_BUF_SIZE;
792 mutex_unlock(&gofh->lock);
793 446
794 return 0; 447 return 0;
795
796unlock_and_return:
797 mutex_unlock(&gofh->lock);
798 return retval;
799} 448}
800 449
801static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 450static void go7007_buf_queue(struct vb2_buffer *vb)
802{ 451{
803 struct go7007_file *gofh = priv; 452 struct vb2_queue *vq = vb->vb2_queue;
804 struct go7007 *go = gofh->go; 453 struct go7007 *go = vb2_get_drv_priv(vq);
805 struct go7007_buffer *gobuf; 454 struct go7007_buffer *go7007_vb =
455 container_of(vb, struct go7007_buffer, vb);
806 unsigned long flags; 456 unsigned long flags;
807 int retval = -EINVAL;
808 int ret;
809 457
810 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
811 buf->memory != V4L2_MEMORY_MMAP)
812 return retval;
813
814 mutex_lock(&gofh->lock);
815 if (buf->index >= gofh->buf_count)
816 goto unlock_and_return;
817
818 gobuf = &gofh->bufs[buf->index];
819 if (!gobuf->mapped)
820 goto unlock_and_return;
821
822 retval = -EBUSY;
823 if (gobuf->state != BUF_STATE_IDLE)
824 goto unlock_and_return;
825
826 /* offset will be 0 until we really support USERPTR streaming */
827 gobuf->offset = gobuf->user_addr & ~PAGE_MASK;
828 gobuf->bytesused = 0;
829 gobuf->frame_offset = 0;
830 gobuf->modet_active = 0;
831 if (gobuf->offset > 0)
832 gobuf->page_count = GO7007_BUF_PAGES + 1;
833 else
834 gobuf->page_count = GO7007_BUF_PAGES;
835
836 retval = -ENOMEM;
837 down_read(&current->mm->mmap_sem);
838 ret = get_user_pages(current, current->mm,
839 gobuf->user_addr & PAGE_MASK, gobuf->page_count,
840 1, 1, gobuf->pages, NULL);
841 up_read(&current->mm->mmap_sem);
842
843 if (ret != gobuf->page_count) {
844 int i;
845 for (i = 0; i < ret; ++i)
846 page_cache_release(gobuf->pages[i]);
847 gobuf->page_count = 0;
848 goto unlock_and_return;
849 }
850
851 gobuf->state = BUF_STATE_QUEUED;
852 spin_lock_irqsave(&go->spinlock, flags); 458 spin_lock_irqsave(&go->spinlock, flags);
853 list_add_tail(&gobuf->stream, &go->stream); 459 list_add_tail(&go7007_vb->list, &go->vidq_active);
854 spin_unlock_irqrestore(&go->spinlock, flags); 460 spin_unlock_irqrestore(&go->spinlock, flags);
855 mutex_unlock(&gofh->lock); 461}
856 462
857 return 0; 463static int go7007_buf_prepare(struct vb2_buffer *vb)
464{
465 struct go7007_buffer *go7007_vb =
466 container_of(vb, struct go7007_buffer, vb);
858 467
859unlock_and_return: 468 go7007_vb->modet_active = 0;
860 mutex_unlock(&gofh->lock); 469 go7007_vb->frame_offset = 0;
861 return retval; 470 vb->v4l2_planes[0].bytesused = 0;
471 return 0;
862} 472}
863 473
864 474static int go7007_buf_finish(struct vb2_buffer *vb)
865static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
866{ 475{
867 struct go7007_file *gofh = priv; 476 struct vb2_queue *vq = vb->vb2_queue;
868 struct go7007 *go = gofh->go; 477 struct go7007 *go = vb2_get_drv_priv(vq);
869 struct go7007_buffer *gobuf; 478 struct go7007_buffer *go7007_vb =
870 int retval = -EINVAL; 479 container_of(vb, struct go7007_buffer, vb);
871 unsigned long flags; 480 u32 frame_type_flag = get_frame_type_flag(go7007_vb, go->format);
872 u32 frame_type_flag; 481 struct v4l2_buffer *buf = &vb->v4l2_buf;
873 DEFINE_WAIT(wait); 482
874 483 buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_BFRAME |
875 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 484 V4L2_BUF_FLAG_PFRAME);
876 return retval; 485 buf->flags |= frame_type_flag;
877 if (buf->memory != V4L2_MEMORY_MMAP)
878 return retval;
879
880 mutex_lock(&gofh->lock);
881 if (list_empty(&go->stream))
882 goto unlock_and_return;
883 gobuf = list_entry(go->stream.next,
884 struct go7007_buffer, stream);
885
886 retval = -EAGAIN;
887 if (gobuf->state != BUF_STATE_DONE &&
888 !(file->f_flags & O_NONBLOCK)) {
889 for (;;) {
890 prepare_to_wait(&go->frame_waitq, &wait,
891 TASK_INTERRUPTIBLE);
892 if (gobuf->state == BUF_STATE_DONE)
893 break;
894 if (signal_pending(current)) {
895 retval = -ERESTARTSYS;
896 break;
897 }
898 schedule();
899 }
900 finish_wait(&go->frame_waitq, &wait);
901 }
902 if (gobuf->state != BUF_STATE_DONE)
903 goto unlock_and_return;
904
905 spin_lock_irqsave(&go->spinlock, flags);
906 deactivate_buffer(gobuf);
907 spin_unlock_irqrestore(&go->spinlock, flags);
908 frame_type_flag = get_frame_type_flag(gobuf, go->format);
909 gobuf->state = BUF_STATE_IDLE;
910
911 memset(buf, 0, sizeof(*buf));
912 buf->index = gobuf->index;
913 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
914 buf->bytesused = gobuf->bytesused;
915 buf->flags = V4L2_BUF_FLAG_MAPPED | frame_type_flag;
916 buf->field = V4L2_FIELD_NONE; 486 buf->field = V4L2_FIELD_NONE;
917 buf->timestamp = gobuf->timestamp;
918 buf->sequence = gobuf->seq;
919 buf->memory = V4L2_MEMORY_MMAP;
920 buf->m.offset = gobuf->index * GO7007_BUF_SIZE;
921 buf->length = GO7007_BUF_SIZE;
922 buf->reserved = gobuf->modet_active;
923
924 mutex_unlock(&gofh->lock);
925 return 0; 487 return 0;
926
927unlock_and_return:
928 mutex_unlock(&gofh->lock);
929 return retval;
930} 488}
931 489
932static int vidioc_streamon(struct file *file, void *priv, 490static int go7007_start_streaming(struct vb2_queue *q, unsigned int count)
933 enum v4l2_buf_type type)
934{ 491{
935 struct go7007_file *gofh = priv; 492 struct go7007 *go = vb2_get_drv_priv(q);
936 struct go7007 *go = gofh->go; 493 int ret;
937 int retval = 0;
938
939 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
940 return -EINVAL;
941 494
942 mutex_lock(&gofh->lock); 495 set_formatting(go);
943 mutex_lock(&go->hw_lock); 496 mutex_lock(&go->hw_lock);
944 497 go->next_seq = 0;
945 if (!go->streaming) { 498 go->active_buf = NULL;
946 go->streaming = 1; 499 q->streaming = 1;
947 go->next_seq = 0; 500 if (go7007_start_encoder(go) < 0)
948 go->active_buf = NULL; 501 ret = -EIO;
949 if (go7007_start_encoder(go) < 0) 502 else
950 retval = -EIO; 503 ret = 0;
951 else
952 retval = 0;
953 }
954 mutex_unlock(&go->hw_lock); 504 mutex_unlock(&go->hw_lock);
955 mutex_unlock(&gofh->lock); 505 if (ret) {
506 q->streaming = 0;
507 return ret;
508 }
956 call_all(&go->v4l2_dev, video, s_stream, 1); 509 call_all(&go->v4l2_dev, video, s_stream, 1);
957 510 v4l2_ctrl_grab(go->mpeg_video_gop_size, true);
958 return retval; 511 v4l2_ctrl_grab(go->mpeg_video_gop_closure, true);
512 v4l2_ctrl_grab(go->mpeg_video_bitrate, true);
513 v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, true);
514 /* Turn on Capture LED */
515 if (go->board_id == GO7007_BOARDID_ADS_USBAV_709)
516 go7007_write_addr(go, 0x3c82, 0x0005);
517 return ret;
959} 518}
960 519
961static int vidioc_streamoff(struct file *file, void *priv, 520static int go7007_stop_streaming(struct vb2_queue *q)
962 enum v4l2_buf_type type)
963{ 521{
964 struct go7007_file *gofh = priv; 522 struct go7007 *go = vb2_get_drv_priv(q);
965 struct go7007 *go = gofh->go; 523 unsigned long flags;
966 524
967 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 525 q->streaming = 0;
968 return -EINVAL; 526 go7007_stream_stop(go);
969 mutex_lock(&gofh->lock); 527 mutex_lock(&go->hw_lock);
970 go7007_streamoff(go); 528 go7007_reset_encoder(go);
971 mutex_unlock(&gofh->lock); 529 mutex_unlock(&go->hw_lock);
972 call_all(&go->v4l2_dev, video, s_stream, 0); 530 call_all(&go->v4l2_dev, video, s_stream, 0);
973 531
532 spin_lock_irqsave(&go->spinlock, flags);
533 INIT_LIST_HEAD(&go->vidq_active);
534 spin_unlock_irqrestore(&go->spinlock, flags);
535 v4l2_ctrl_grab(go->mpeg_video_gop_size, false);
536 v4l2_ctrl_grab(go->mpeg_video_gop_closure, false);
537 v4l2_ctrl_grab(go->mpeg_video_bitrate, false);
538 v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, false);
539 /* Turn on Capture LED */
540 if (go->board_id == GO7007_BOARDID_ADS_USBAV_709)
541 go7007_write_addr(go, 0x3c82, 0x000d);
974 return 0; 542 return 0;
975} 543}
976 544
977static int vidioc_queryctrl(struct file *file, void *priv, 545static struct vb2_ops go7007_video_qops = {
978 struct v4l2_queryctrl *query) 546 .queue_setup = go7007_queue_setup,
979{ 547 .buf_queue = go7007_buf_queue,
980 struct go7007 *go = ((struct go7007_file *) priv)->go; 548 .buf_prepare = go7007_buf_prepare,
981 int id = query->id; 549 .buf_finish = go7007_buf_finish,
982 550 .start_streaming = go7007_start_streaming,
983 if (0 == call_all(&go->v4l2_dev, core, queryctrl, query)) 551 .stop_streaming = go7007_stop_streaming,
984 return 0; 552 .wait_prepare = vb2_ops_wait_prepare,
985 553 .wait_finish = vb2_ops_wait_finish,
986 query->id = id; 554};
987 return mpeg_query_ctrl(query);
988}
989
990static int vidioc_g_ctrl(struct file *file, void *priv,
991 struct v4l2_control *ctrl)
992{
993 struct go7007 *go = ((struct go7007_file *) priv)->go;
994
995 if (0 == call_all(&go->v4l2_dev, core, g_ctrl, ctrl))
996 return 0;
997
998 return mpeg_g_ctrl(ctrl, go);
999}
1000
1001static int vidioc_s_ctrl(struct file *file, void *priv,
1002 struct v4l2_control *ctrl)
1003{
1004 struct go7007 *go = ((struct go7007_file *) priv)->go;
1005
1006 if (0 == call_all(&go->v4l2_dev, core, s_ctrl, ctrl))
1007 return 0;
1008
1009 return mpeg_s_ctrl(ctrl, go);
1010}
1011 555
1012static int vidioc_g_parm(struct file *filp, void *priv, 556static int vidioc_g_parm(struct file *filp, void *priv,
1013 struct v4l2_streamparm *parm) 557 struct v4l2_streamparm *parm)
1014{ 558{
1015 struct go7007 *go = ((struct go7007_file *) priv)->go; 559 struct go7007 *go = video_drvdata(filp);
1016 struct v4l2_fract timeperframe = { 560 struct v4l2_fract timeperframe = {
1017 .numerator = 1001 * go->fps_scale, 561 .numerator = 1001 * go->fps_scale,
1018 .denominator = go->sensor_framerate, 562 .denominator = go->sensor_framerate,
@@ -1021,7 +565,8 @@ static int vidioc_g_parm(struct file *filp, void *priv,
1021 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 565 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1022 return -EINVAL; 566 return -EINVAL;
1023 567
1024 parm->parm.capture.capability |= V4L2_CAP_TIMEPERFRAME; 568 parm->parm.capture.readbuffers = 2;
569 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1025 parm->parm.capture.timeperframe = timeperframe; 570 parm->parm.capture.timeperframe = timeperframe;
1026 571
1027 return 0; 572 return 0;
@@ -1030,13 +575,11 @@ static int vidioc_g_parm(struct file *filp, void *priv,
1030static int vidioc_s_parm(struct file *filp, void *priv, 575static int vidioc_s_parm(struct file *filp, void *priv,
1031 struct v4l2_streamparm *parm) 576 struct v4l2_streamparm *parm)
1032{ 577{
1033 struct go7007 *go = ((struct go7007_file *) priv)->go; 578 struct go7007 *go = video_drvdata(filp);
1034 unsigned int n, d; 579 unsigned int n, d;
1035 580
1036 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 581 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1037 return -EINVAL; 582 return -EINVAL;
1038 if (parm->parm.capture.capturemode != 0)
1039 return -EINVAL;
1040 583
1041 n = go->sensor_framerate * 584 n = go->sensor_framerate *
1042 parm->parm.capture.timeperframe.numerator; 585 parm->parm.capture.timeperframe.numerator;
@@ -1046,7 +589,7 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1046 else 589 else
1047 go->fps_scale = 1; 590 go->fps_scale = 1;
1048 591
1049 return 0; 592 return vidioc_g_parm(filp, priv, parm);
1050} 593}
1051 594
1052/* VIDIOC_ENUMSTD on go7007 were used for enumerating the supported fps and 595/* VIDIOC_ENUMSTD on go7007 were used for enumerating the supported fps and
@@ -1062,121 +605,96 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1062static int vidioc_enum_framesizes(struct file *filp, void *priv, 605static int vidioc_enum_framesizes(struct file *filp, void *priv,
1063 struct v4l2_frmsizeenum *fsize) 606 struct v4l2_frmsizeenum *fsize)
1064{ 607{
1065 struct go7007 *go = ((struct go7007_file *) priv)->go; 608 struct go7007 *go = video_drvdata(filp);
609 int width, height;
1066 610
1067 /* Return -EINVAL, if it is a TV board */ 611 if (fsize->index > 2)
1068 if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) ||
1069 (go->board_info->sensor_flags & GO7007_SENSOR_TV))
1070 return -EINVAL; 612 return -EINVAL;
1071 613
1072 if (fsize->index > 0) 614 if (!valid_pixelformat(fsize->pixel_format))
1073 return -EINVAL; 615 return -EINVAL;
1074 616
617 get_resolution(go, &width, &height);
1075 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; 618 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1076 fsize->discrete.width = go->board_info->sensor_width; 619 fsize->discrete.width = (width >> fsize->index) & ~0xf;
1077 fsize->discrete.height = go->board_info->sensor_height; 620 fsize->discrete.height = (height >> fsize->index) & ~0xf;
1078
1079 return 0; 621 return 0;
1080} 622}
1081 623
1082static int vidioc_enum_frameintervals(struct file *filp, void *priv, 624static int vidioc_enum_frameintervals(struct file *filp, void *priv,
1083 struct v4l2_frmivalenum *fival) 625 struct v4l2_frmivalenum *fival)
1084{ 626{
1085 struct go7007 *go = ((struct go7007_file *) priv)->go; 627 struct go7007 *go = video_drvdata(filp);
628 int width, height;
629 int i;
1086 630
1087 /* Return -EINVAL, if it is a TV board */ 631 if (fival->index > 4)
1088 if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) ||
1089 (go->board_info->sensor_flags & GO7007_SENSOR_TV))
1090 return -EINVAL; 632 return -EINVAL;
1091 633
1092 if (fival->index > 0) 634 if (!valid_pixelformat(fival->pixel_format))
1093 return -EINVAL; 635 return -EINVAL;
1094 636
637 if (!(go->board_info->sensor_flags & GO7007_SENSOR_SCALING)) {
638 get_resolution(go, &width, &height);
639 for (i = 0; i <= 2; i++)
640 if (fival->width == ((width >> i) & ~0xf) &&
641 fival->height == ((height >> i) & ~0xf))
642 break;
643 if (i > 2)
644 return -EINVAL;
645 }
1095 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; 646 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
1096 fival->discrete.numerator = 1001; 647 fival->discrete.numerator = 1001 * (fival->index + 1);
1097 fival->discrete.denominator = go->board_info->sensor_framerate; 648 fival->discrete.denominator = go->sensor_framerate;
1098
1099 return 0; 649 return 0;
1100} 650}
1101 651
1102static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std) 652static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
1103{ 653{
1104 struct go7007 *go = ((struct go7007_file *) priv)->go; 654 struct go7007 *go = video_drvdata(file);
1105 655
1106 switch (go->standard) { 656 *std = go->std;
1107 case GO7007_STD_NTSC: 657 return 0;
1108 *std = V4L2_STD_NTSC; 658}
1109 break; 659
1110 case GO7007_STD_PAL: 660static int go7007_s_std(struct go7007 *go)
1111 *std = V4L2_STD_PAL; 661{
1112 break; 662 if (go->std & V4L2_STD_625_50) {
1113 default: 663 go->standard = GO7007_STD_PAL;
1114 return -EINVAL; 664 go->sensor_framerate = 25025;
665 } else {
666 go->standard = GO7007_STD_NTSC;
667 go->sensor_framerate = 30000;
1115 } 668 }
1116 669
670 call_all(&go->v4l2_dev, core, s_std, go->std);
671 set_capture_size(go, NULL, 0);
1117 return 0; 672 return 0;
1118} 673}
1119 674
1120static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std) 675static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std)
1121{ 676{
1122 struct go7007 *go = ((struct go7007_file *) priv)->go; 677 struct go7007 *go = video_drvdata(file);
1123 678
1124 if (go->streaming) 679 if (vb2_is_busy(&go->vidq))
1125 return -EBUSY; 680 return -EBUSY;
1126 681
1127 if (!(go->board_info->sensor_flags & GO7007_SENSOR_TV) && *std != 0) 682 go->std = std;
1128 return -EINVAL;
1129
1130 if (*std == 0)
1131 return -EINVAL;
1132
1133 if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) &&
1134 go->input == go->board_info->num_inputs - 1) {
1135 if (!go->i2c_adapter_online)
1136 return -EIO;
1137 if (call_all(&go->v4l2_dev, core, s_std, *std) < 0)
1138 return -EINVAL;
1139 }
1140
1141 if (*std & V4L2_STD_NTSC) {
1142 go->standard = GO7007_STD_NTSC;
1143 go->sensor_framerate = 30000;
1144 } else if (*std & V4L2_STD_PAL) {
1145 go->standard = GO7007_STD_PAL;
1146 go->sensor_framerate = 25025;
1147 } else if (*std & V4L2_STD_SECAM) {
1148 go->standard = GO7007_STD_PAL;
1149 go->sensor_framerate = 25025;
1150 } else
1151 return -EINVAL;
1152
1153 call_all(&go->v4l2_dev, core, s_std, *std);
1154 set_capture_size(go, NULL, 0);
1155 683
1156 return 0; 684 return go7007_s_std(go);
1157} 685}
1158 686
1159static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) 687static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
1160{ 688{
1161 struct go7007 *go = ((struct go7007_file *) priv)->go; 689 struct go7007 *go = video_drvdata(file);
1162
1163 if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) &&
1164 go->input == go->board_info->num_inputs - 1) {
1165 if (!go->i2c_adapter_online)
1166 return -EIO;
1167 return call_all(&go->v4l2_dev, video, querystd, std);
1168 } else if (go->board_info->sensor_flags & GO7007_SENSOR_TV)
1169 *std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
1170 else
1171 *std = 0;
1172 690
1173 return 0; 691 return call_all(&go->v4l2_dev, video, querystd, std);
1174} 692}
1175 693
1176static int vidioc_enum_input(struct file *file, void *priv, 694static int vidioc_enum_input(struct file *file, void *priv,
1177 struct v4l2_input *inp) 695 struct v4l2_input *inp)
1178{ 696{
1179 struct go7007 *go = ((struct go7007_file *) priv)->go; 697 struct go7007 *go = video_drvdata(file);
1180 698
1181 if (inp->index >= go->board_info->num_inputs) 699 if (inp->index >= go->board_info->num_inputs)
1182 return -EINVAL; 700 return -EINVAL;
@@ -1184,18 +702,20 @@ static int vidioc_enum_input(struct file *file, void *priv,
1184 strncpy(inp->name, go->board_info->inputs[inp->index].name, 702 strncpy(inp->name, go->board_info->inputs[inp->index].name,
1185 sizeof(inp->name)); 703 sizeof(inp->name));
1186 704
1187 /* If this board has a tuner, it will be the last input */ 705 /* If this board has a tuner, it will be the first input */
1188 if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) && 706 if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) &&
1189 inp->index == go->board_info->num_inputs - 1) 707 inp->index == 0)
1190 inp->type = V4L2_INPUT_TYPE_TUNER; 708 inp->type = V4L2_INPUT_TYPE_TUNER;
1191 else 709 else
1192 inp->type = V4L2_INPUT_TYPE_CAMERA; 710 inp->type = V4L2_INPUT_TYPE_CAMERA;
1193 711
1194 inp->audioset = 0; 712 if (go->board_info->num_aud_inputs)
713 inp->audioset = (1 << go->board_info->num_aud_inputs) - 1;
714 else
715 inp->audioset = 0;
1195 inp->tuner = 0; 716 inp->tuner = 0;
1196 if (go->board_info->sensor_flags & GO7007_SENSOR_TV) 717 if (go->board_info->sensor_flags & GO7007_SENSOR_TV)
1197 inp->std = V4L2_STD_NTSC | V4L2_STD_PAL | 718 inp->std = video_devdata(file)->tvnorms;
1198 V4L2_STD_SECAM;
1199 else 719 else
1200 inp->std = 0; 720 inp->std = 0;
1201 721
@@ -1205,203 +725,128 @@ static int vidioc_enum_input(struct file *file, void *priv,
1205 725
1206static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) 726static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
1207{ 727{
1208 struct go7007 *go = ((struct go7007_file *) priv)->go; 728 struct go7007 *go = video_drvdata(file);
1209 729
1210 *input = go->input; 730 *input = go->input;
1211 731
1212 return 0; 732 return 0;
1213} 733}
1214 734
1215static int vidioc_s_input(struct file *file, void *priv, unsigned int input) 735static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
1216{ 736{
1217 struct go7007 *go = ((struct go7007_file *) priv)->go; 737 struct go7007 *go = video_drvdata(file);
1218 738
1219 if (input >= go->board_info->num_inputs) 739 if (a->index >= go->board_info->num_aud_inputs)
1220 return -EINVAL; 740 return -EINVAL;
1221 if (go->streaming) 741 strlcpy(a->name, go->board_info->aud_inputs[a->index].name, sizeof(a->name));
1222 return -EBUSY; 742 a->capability = V4L2_AUDCAP_STEREO;
743 return 0;
744}
1223 745
1224 go->input = input; 746static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
747{
748 struct go7007 *go = video_drvdata(file);
1225 749
1226 return call_all(&go->v4l2_dev, video, s_routing, input, 0, 0); 750 a->index = go->aud_input;
751 strlcpy(a->name, go->board_info->aud_inputs[go->aud_input].name, sizeof(a->name));
752 a->capability = V4L2_AUDCAP_STEREO;
753 return 0;
1227} 754}
1228 755
1229static int vidioc_g_tuner(struct file *file, void *priv, 756static int vidioc_s_audio(struct file *file, void *fh, const struct v4l2_audio *a)
1230 struct v4l2_tuner *t)
1231{ 757{
1232 struct go7007 *go = ((struct go7007_file *) priv)->go; 758 struct go7007 *go = video_drvdata(file);
1233 759
1234 if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) 760 if (a->index >= go->board_info->num_aud_inputs)
1235 return -EINVAL;
1236 if (t->index != 0)
1237 return -EINVAL; 761 return -EINVAL;
1238 if (!go->i2c_adapter_online) 762 go->aud_input = a->index;
1239 return -EIO; 763 v4l2_subdev_call(go->sd_audio, audio, s_routing,
1240 764 go->board_info->aud_inputs[go->aud_input].audio_input, 0, 0);
1241 return call_all(&go->v4l2_dev, tuner, g_tuner, t); 765 return 0;
1242} 766}
1243 767
1244static int vidioc_s_tuner(struct file *file, void *priv, 768static void go7007_s_input(struct go7007 *go)
1245 struct v4l2_tuner *t)
1246{ 769{
1247 struct go7007 *go = ((struct go7007_file *) priv)->go; 770 unsigned int input = go->input;
1248 771
1249 if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) 772 v4l2_subdev_call(go->sd_video, video, s_routing,
1250 return -EINVAL; 773 go->board_info->inputs[input].video_input, 0,
1251 if (t->index != 0) 774 go->board_info->video_config);
1252 return -EINVAL; 775 if (go->board_info->num_aud_inputs) {
1253 if (!go->i2c_adapter_online) 776 int aud_input = go->board_info->inputs[input].audio_index;
1254 return -EIO;
1255
1256 switch (go->board_id) {
1257 case GO7007_BOARDID_PX_TV402U_NA:
1258 case GO7007_BOARDID_PX_TV402U_JP:
1259 /* No selectable options currently */
1260 if (t->audmode != V4L2_TUNER_MODE_STEREO)
1261 return -EINVAL;
1262 break;
1263 }
1264 777
1265 return call_all(&go->v4l2_dev, tuner, s_tuner, t); 778 v4l2_subdev_call(go->sd_audio, audio, s_routing,
779 go->board_info->aud_inputs[aud_input].audio_input, 0, 0);
780 go->aud_input = aud_input;
781 }
1266} 782}
1267 783
1268static int vidioc_g_frequency(struct file *file, void *priv, 784static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
1269 struct v4l2_frequency *f)
1270{ 785{
1271 struct go7007 *go = ((struct go7007_file *) priv)->go; 786 struct go7007 *go = video_drvdata(file);
1272 787
1273 if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) 788 if (input >= go->board_info->num_inputs)
1274 return -EINVAL; 789 return -EINVAL;
1275 if (!go->i2c_adapter_online) 790 if (vb2_is_busy(&go->vidq))
1276 return -EIO; 791 return -EBUSY;
1277 792
1278 f->type = V4L2_TUNER_ANALOG_TV; 793 go->input = input;
794 go7007_s_input(go);
1279 795
1280 return call_all(&go->v4l2_dev, tuner, g_frequency, f); 796 return 0;
1281} 797}
1282 798
1283static int vidioc_s_frequency(struct file *file, void *priv, 799static int vidioc_g_tuner(struct file *file, void *priv,
1284 struct v4l2_frequency *f) 800 struct v4l2_tuner *t)
1285{ 801{
1286 struct go7007 *go = ((struct go7007_file *) priv)->go; 802 struct go7007 *go = video_drvdata(file);
1287 803
1288 if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) 804 if (t->index != 0)
1289 return -EINVAL; 805 return -EINVAL;
1290 if (!go->i2c_adapter_online)
1291 return -EIO;
1292 806
1293 return call_all(&go->v4l2_dev, tuner, s_frequency, f); 807 strlcpy(t->name, "Tuner", sizeof(t->name));
808 return call_all(&go->v4l2_dev, tuner, g_tuner, t);
1294} 809}
1295 810
1296static int vidioc_cropcap(struct file *file, void *priv, 811static int vidioc_s_tuner(struct file *file, void *priv,
1297 struct v4l2_cropcap *cropcap) 812 const struct v4l2_tuner *t)
1298{ 813{
1299 struct go7007 *go = ((struct go7007_file *) priv)->go; 814 struct go7007 *go = video_drvdata(file);
1300 815
1301 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 816 if (t->index != 0)
1302 return -EINVAL; 817 return -EINVAL;
1303 818
1304 /* These specify the raw input of the sensor */ 819 return call_all(&go->v4l2_dev, tuner, s_tuner, t);
1305 switch (go->standard) {
1306 case GO7007_STD_NTSC:
1307 cropcap->bounds.top = 0;
1308 cropcap->bounds.left = 0;
1309 cropcap->bounds.width = 720;
1310 cropcap->bounds.height = 480;
1311 cropcap->defrect.top = 0;
1312 cropcap->defrect.left = 0;
1313 cropcap->defrect.width = 720;
1314 cropcap->defrect.height = 480;
1315 break;
1316 case GO7007_STD_PAL:
1317 cropcap->bounds.top = 0;
1318 cropcap->bounds.left = 0;
1319 cropcap->bounds.width = 720;
1320 cropcap->bounds.height = 576;
1321 cropcap->defrect.top = 0;
1322 cropcap->defrect.left = 0;
1323 cropcap->defrect.width = 720;
1324 cropcap->defrect.height = 576;
1325 break;
1326 case GO7007_STD_OTHER:
1327 cropcap->bounds.top = 0;
1328 cropcap->bounds.left = 0;
1329 cropcap->bounds.width = go->board_info->sensor_width;
1330 cropcap->bounds.height = go->board_info->sensor_height;
1331 cropcap->defrect.top = 0;
1332 cropcap->defrect.left = 0;
1333 cropcap->defrect.width = go->board_info->sensor_width;
1334 cropcap->defrect.height = go->board_info->sensor_height;
1335 break;
1336 }
1337
1338 return 0;
1339} 820}
1340 821
1341static int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop) 822static int vidioc_g_frequency(struct file *file, void *priv,
823 struct v4l2_frequency *f)
1342{ 824{
1343 struct go7007 *go = ((struct go7007_file *) priv)->go; 825 struct go7007 *go = video_drvdata(file);
1344 826
1345 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 827 if (f->tuner)
1346 return -EINVAL; 828 return -EINVAL;
1347 829
1348 crop->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 830 return call_all(&go->v4l2_dev, tuner, g_frequency, f);
1349
1350 /* These specify the raw input of the sensor */
1351 switch (go->standard) {
1352 case GO7007_STD_NTSC:
1353 crop->c.top = 0;
1354 crop->c.left = 0;
1355 crop->c.width = 720;
1356 crop->c.height = 480;
1357 break;
1358 case GO7007_STD_PAL:
1359 crop->c.top = 0;
1360 crop->c.left = 0;
1361 crop->c.width = 720;
1362 crop->c.height = 576;
1363 break;
1364 case GO7007_STD_OTHER:
1365 crop->c.top = 0;
1366 crop->c.left = 0;
1367 crop->c.width = go->board_info->sensor_width;
1368 crop->c.height = go->board_info->sensor_height;
1369 break;
1370 }
1371
1372 return 0;
1373} 831}
1374 832
1375/* FIXME: vidioc_s_crop is not really implemented!!! 833static int vidioc_s_frequency(struct file *file, void *priv,
1376 */ 834 const struct v4l2_frequency *f)
1377static int vidioc_s_crop(struct file *file, void *priv, const struct v4l2_crop *crop)
1378{ 835{
1379 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 836 struct go7007 *go = video_drvdata(file);
1380 return -EINVAL;
1381
1382 return 0;
1383}
1384 837
1385static int vidioc_g_jpegcomp(struct file *file, void *priv, 838 if (f->tuner)
1386 struct v4l2_jpegcompression *params) 839 return -EINVAL;
1387{
1388 memset(params, 0, sizeof(*params));
1389 params->quality = 50; /* ?? */
1390 params->jpeg_markers = V4L2_JPEG_MARKER_DHT |
1391 V4L2_JPEG_MARKER_DQT;
1392 840
1393 return 0; 841 return call_all(&go->v4l2_dev, tuner, s_frequency, f);
1394} 842}
1395 843
1396static int vidioc_s_jpegcomp(struct file *file, void *priv, 844static int vidioc_log_status(struct file *file, void *priv)
1397 const struct v4l2_jpegcompression *params)
1398{ 845{
1399 if (params->quality != 50 || 846 struct go7007 *go = video_drvdata(file);
1400 params->jpeg_markers != (V4L2_JPEG_MARKER_DHT |
1401 V4L2_JPEG_MARKER_DQT))
1402 return -EINVAL;
1403 847
1404 return 0; 848 v4l2_ctrl_log_status(file, priv);
849 return call_all(&go->v4l2_dev, core, log_status);
1405} 850}
1406 851
1407/* FIXME: 852/* FIXME:
@@ -1412,180 +857,6 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1412 */ 857 */
1413 858
1414#if 0 859#if 0
1415 /* Temporary ioctls for controlling compression characteristics */
1416 case GO7007IOC_S_BITRATE:
1417 {
1418 int *bitrate = arg;
1419
1420 if (go->streaming)
1421 return -EINVAL;
1422 /* Upper bound is kind of arbitrary here */
1423 if (*bitrate < 64000 || *bitrate > 10000000)
1424 return -EINVAL;
1425 go->bitrate = *bitrate;
1426 return 0;
1427 }
1428 case GO7007IOC_G_BITRATE:
1429 {
1430 int *bitrate = arg;
1431
1432 *bitrate = go->bitrate;
1433 return 0;
1434 }
1435 case GO7007IOC_S_COMP_PARAMS:
1436 {
1437 struct go7007_comp_params *comp = arg;
1438
1439 if (go->format == GO7007_FORMAT_MJPEG)
1440 return -EINVAL;
1441 if (comp->gop_size > 0)
1442 go->gop_size = comp->gop_size;
1443 else
1444 go->gop_size = go->sensor_framerate / 1000;
1445 if (go->gop_size != 15)
1446 go->dvd_mode = 0;
1447 /*go->ipb = comp->max_b_frames > 0;*/ /* completely untested */
1448 if (go->board_info->sensor_flags & GO7007_SENSOR_TV) {
1449 switch (comp->aspect_ratio) {
1450 case GO7007_ASPECT_RATIO_4_3_NTSC:
1451 case GO7007_ASPECT_RATIO_4_3_PAL:
1452 go->aspect_ratio = GO7007_RATIO_4_3;
1453 break;
1454 case GO7007_ASPECT_RATIO_16_9_NTSC:
1455 case GO7007_ASPECT_RATIO_16_9_PAL:
1456 go->aspect_ratio = GO7007_RATIO_16_9;
1457 break;
1458 default:
1459 go->aspect_ratio = GO7007_RATIO_1_1;
1460 break;
1461 }
1462 }
1463 if (comp->flags & GO7007_COMP_OMIT_SEQ_HEADER) {
1464 go->dvd_mode = 0;
1465 go->seq_header_enable = 0;
1466 } else {
1467 go->seq_header_enable = 1;
1468 }
1469 /* fall-through */
1470 }
1471 case GO7007IOC_G_COMP_PARAMS:
1472 {
1473 struct go7007_comp_params *comp = arg;
1474
1475 if (go->format == GO7007_FORMAT_MJPEG)
1476 return -EINVAL;
1477 memset(comp, 0, sizeof(*comp));
1478 comp->gop_size = go->gop_size;
1479 comp->max_b_frames = go->ipb ? 2 : 0;
1480 switch (go->aspect_ratio) {
1481 case GO7007_RATIO_4_3:
1482 if (go->standard == GO7007_STD_NTSC)
1483 comp->aspect_ratio =
1484 GO7007_ASPECT_RATIO_4_3_NTSC;
1485 else
1486 comp->aspect_ratio =
1487 GO7007_ASPECT_RATIO_4_3_PAL;
1488 break;
1489 case GO7007_RATIO_16_9:
1490 if (go->standard == GO7007_STD_NTSC)
1491 comp->aspect_ratio =
1492 GO7007_ASPECT_RATIO_16_9_NTSC;
1493 else
1494 comp->aspect_ratio =
1495 GO7007_ASPECT_RATIO_16_9_PAL;
1496 break;
1497 default:
1498 comp->aspect_ratio = GO7007_ASPECT_RATIO_1_1;
1499 break;
1500 }
1501 if (go->closed_gop)
1502 comp->flags |= GO7007_COMP_CLOSED_GOP;
1503 if (!go->seq_header_enable)
1504 comp->flags |= GO7007_COMP_OMIT_SEQ_HEADER;
1505 return 0;
1506 }
1507 case GO7007IOC_S_MPEG_PARAMS:
1508 {
1509 struct go7007_mpeg_params *mpeg = arg;
1510
1511 if (go->format != GO7007_FORMAT_MPEG1 &&
1512 go->format != GO7007_FORMAT_MPEG2 &&
1513 go->format != GO7007_FORMAT_MPEG4)
1514 return -EINVAL;
1515
1516 if (mpeg->flags & GO7007_MPEG_FORCE_DVD_MODE) {
1517 go->format = GO7007_FORMAT_MPEG2;
1518 go->bitrate = 9800000;
1519 go->gop_size = 15;
1520 go->pali = 0x48;
1521 go->closed_gop = 1;
1522 go->repeat_seqhead = 0;
1523 go->seq_header_enable = 1;
1524 go->gop_header_enable = 1;
1525 go->dvd_mode = 1;
1526 } else {
1527 switch (mpeg->mpeg_video_standard) {
1528 case GO7007_MPEG_VIDEO_MPEG1:
1529 go->format = GO7007_FORMAT_MPEG1;
1530 go->pali = 0;
1531 break;
1532 case GO7007_MPEG_VIDEO_MPEG2:
1533 go->format = GO7007_FORMAT_MPEG2;
1534 if (mpeg->pali >> 24 == 2)
1535 go->pali = mpeg->pali & 0xff;
1536 else
1537 go->pali = 0x48;
1538 break;
1539 case GO7007_MPEG_VIDEO_MPEG4:
1540 go->format = GO7007_FORMAT_MPEG4;
1541 if (mpeg->pali >> 24 == 4)
1542 go->pali = mpeg->pali & 0xff;
1543 else
1544 go->pali = 0xf5;
1545 break;
1546 default:
1547 return -EINVAL;
1548 }
1549 go->gop_header_enable =
1550 mpeg->flags & GO7007_MPEG_OMIT_GOP_HEADER
1551 ? 0 : 1;
1552 if (mpeg->flags & GO7007_MPEG_REPEAT_SEQHEADER)
1553 go->repeat_seqhead = 1;
1554 else
1555 go->repeat_seqhead = 0;
1556 go->dvd_mode = 0;
1557 }
1558 /* fall-through */
1559 }
1560 case GO7007IOC_G_MPEG_PARAMS:
1561 {
1562 struct go7007_mpeg_params *mpeg = arg;
1563
1564 memset(mpeg, 0, sizeof(*mpeg));
1565 switch (go->format) {
1566 case GO7007_FORMAT_MPEG1:
1567 mpeg->mpeg_video_standard = GO7007_MPEG_VIDEO_MPEG1;
1568 mpeg->pali = 0;
1569 break;
1570 case GO7007_FORMAT_MPEG2:
1571 mpeg->mpeg_video_standard = GO7007_MPEG_VIDEO_MPEG2;
1572 mpeg->pali = GO7007_MPEG_PROFILE(2, go->pali);
1573 break;
1574 case GO7007_FORMAT_MPEG4:
1575 mpeg->mpeg_video_standard = GO7007_MPEG_VIDEO_MPEG4;
1576 mpeg->pali = GO7007_MPEG_PROFILE(4, go->pali);
1577 break;
1578 default:
1579 return -EINVAL;
1580 }
1581 if (!go->gop_header_enable)
1582 mpeg->flags |= GO7007_MPEG_OMIT_GOP_HEADER;
1583 if (go->repeat_seqhead)
1584 mpeg->flags |= GO7007_MPEG_REPEAT_SEQHEADER;
1585 if (go->dvd_mode)
1586 mpeg->flags |= GO7007_MPEG_FORCE_DVD_MODE;
1587 return 0;
1588 }
1589 case GO7007IOC_S_MD_PARAMS: 860 case GO7007IOC_S_MD_PARAMS:
1590 { 861 {
1591 struct go7007_md_params *mdp = arg; 862 struct go7007_md_params *mdp = arg;
@@ -1604,25 +875,6 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1604 go->modet[mdp->region].enable = 0; 875 go->modet[mdp->region].enable = 0;
1605 /* fall-through */ 876 /* fall-through */
1606 } 877 }
1607 case GO7007IOC_G_MD_PARAMS:
1608 {
1609 struct go7007_md_params *mdp = arg;
1610 int region = mdp->region;
1611
1612 if (mdp->region > 3)
1613 return -EINVAL;
1614 memset(mdp, 0, sizeof(struct go7007_md_params));
1615 mdp->region = region;
1616 if (!go->modet[region].enable)
1617 return 0;
1618 mdp->pixel_threshold =
1619 (go->modet[region].pixel_threshold << 1) + 1;
1620 mdp->motion_threshold =
1621 (go->modet[region].motion_threshold << 1) + 1;
1622 mdp->trigger =
1623 (go->modet[region].mb_threshold << 1) + 1;
1624 return 0;
1625 }
1626 case GO7007IOC_S_MD_REGION: 878 case GO7007IOC_S_MD_REGION:
1627 { 879 {
1628 struct go7007_md_region *region = arg; 880 struct go7007_md_region *region = arg;
@@ -1633,116 +885,14 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1633 } 885 }
1634#endif 886#endif
1635 887
1636static ssize_t go7007_read(struct file *file, char __user *data,
1637 size_t count, loff_t *ppos)
1638{
1639 return -EINVAL;
1640}
1641
1642static void go7007_vm_open(struct vm_area_struct *vma)
1643{
1644 struct go7007_buffer *gobuf = vma->vm_private_data;
1645
1646 ++gobuf->mapped;
1647}
1648
1649static void go7007_vm_close(struct vm_area_struct *vma)
1650{
1651 struct go7007_buffer *gobuf = vma->vm_private_data;
1652 unsigned long flags;
1653
1654 if (--gobuf->mapped == 0) {
1655 spin_lock_irqsave(&gobuf->go->spinlock, flags);
1656 deactivate_buffer(gobuf);
1657 spin_unlock_irqrestore(&gobuf->go->spinlock, flags);
1658 }
1659}
1660
1661/* Copied from videobuf-dma-sg.c */
1662static int go7007_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1663{
1664 struct page *page;
1665
1666 page = alloc_page(GFP_USER | __GFP_DMA32);
1667 if (!page)
1668 return VM_FAULT_OOM;
1669 clear_user_highpage(page, (unsigned long)vmf->virtual_address);
1670 vmf->page = page;
1671 return 0;
1672}
1673
1674static struct vm_operations_struct go7007_vm_ops = {
1675 .open = go7007_vm_open,
1676 .close = go7007_vm_close,
1677 .fault = go7007_vm_fault,
1678};
1679
1680static int go7007_mmap(struct file *file, struct vm_area_struct *vma)
1681{
1682 struct go7007_file *gofh = file->private_data;
1683 unsigned int index;
1684
1685 if (gofh->go->status != STATUS_ONLINE)
1686 return -EIO;
1687 if (!(vma->vm_flags & VM_SHARED))
1688 return -EINVAL; /* only support VM_SHARED mapping */
1689 if (vma->vm_end - vma->vm_start != GO7007_BUF_SIZE)
1690 return -EINVAL; /* must map exactly one full buffer */
1691 mutex_lock(&gofh->lock);
1692 index = vma->vm_pgoff / GO7007_BUF_PAGES;
1693 if (index >= gofh->buf_count) {
1694 mutex_unlock(&gofh->lock);
1695 return -EINVAL; /* trying to map beyond requested buffers */
1696 }
1697 if (index * GO7007_BUF_PAGES != vma->vm_pgoff) {
1698 mutex_unlock(&gofh->lock);
1699 return -EINVAL; /* offset is not aligned on buffer boundary */
1700 }
1701 if (gofh->bufs[index].mapped > 0) {
1702 mutex_unlock(&gofh->lock);
1703 return -EBUSY;
1704 }
1705 gofh->bufs[index].mapped = 1;
1706 gofh->bufs[index].user_addr = vma->vm_start;
1707 vma->vm_ops = &go7007_vm_ops;
1708 vma->vm_flags |= VM_DONTEXPAND;
1709 vma->vm_flags &= ~VM_IO;
1710 vma->vm_private_data = &gofh->bufs[index];
1711 mutex_unlock(&gofh->lock);
1712 return 0;
1713}
1714
1715static unsigned int go7007_poll(struct file *file, poll_table *wait)
1716{
1717 struct go7007_file *gofh = file->private_data;
1718 struct go7007_buffer *gobuf;
1719
1720 if (list_empty(&gofh->go->stream))
1721 return POLLERR;
1722 gobuf = list_entry(gofh->go->stream.next, struct go7007_buffer, stream);
1723 poll_wait(file, &gofh->go->frame_waitq, wait);
1724 if (gobuf->state == BUF_STATE_DONE)
1725 return POLLIN | POLLRDNORM;
1726 return 0;
1727}
1728
1729static void go7007_vfl_release(struct video_device *vfd)
1730{
1731 struct go7007 *go = video_get_drvdata(vfd);
1732
1733 video_device_release(vfd);
1734 if (--go->ref_count == 0)
1735 kfree(go);
1736}
1737
1738static struct v4l2_file_operations go7007_fops = { 888static struct v4l2_file_operations go7007_fops = {
1739 .owner = THIS_MODULE, 889 .owner = THIS_MODULE,
1740 .open = go7007_open, 890 .open = v4l2_fh_open,
1741 .release = go7007_release, 891 .release = vb2_fop_release,
1742 .ioctl = video_ioctl2, 892 .unlocked_ioctl = video_ioctl2,
1743 .read = go7007_read, 893 .read = vb2_fop_read,
1744 .mmap = go7007_mmap, 894 .mmap = vb2_fop_mmap,
1745 .poll = go7007_poll, 895 .poll = vb2_fop_poll,
1746}; 896};
1747 897
1748static const struct v4l2_ioctl_ops video_ioctl_ops = { 898static const struct v4l2_ioctl_ops video_ioctl_ops = {
@@ -1751,21 +901,21 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1751 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 901 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1752 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 902 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1753 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 903 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1754 .vidioc_reqbufs = vidioc_reqbufs, 904 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1755 .vidioc_querybuf = vidioc_querybuf, 905 .vidioc_querybuf = vb2_ioctl_querybuf,
1756 .vidioc_qbuf = vidioc_qbuf, 906 .vidioc_qbuf = vb2_ioctl_qbuf,
1757 .vidioc_dqbuf = vidioc_dqbuf, 907 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1758 .vidioc_g_std = vidioc_g_std, 908 .vidioc_g_std = vidioc_g_std,
1759 .vidioc_s_std = vidioc_s_std, 909 .vidioc_s_std = vidioc_s_std,
1760 .vidioc_querystd = vidioc_querystd, 910 .vidioc_querystd = vidioc_querystd,
1761 .vidioc_enum_input = vidioc_enum_input, 911 .vidioc_enum_input = vidioc_enum_input,
1762 .vidioc_g_input = vidioc_g_input, 912 .vidioc_g_input = vidioc_g_input,
1763 .vidioc_s_input = vidioc_s_input, 913 .vidioc_s_input = vidioc_s_input,
1764 .vidioc_queryctrl = vidioc_queryctrl, 914 .vidioc_enumaudio = vidioc_enumaudio,
1765 .vidioc_g_ctrl = vidioc_g_ctrl, 915 .vidioc_g_audio = vidioc_g_audio,
1766 .vidioc_s_ctrl = vidioc_s_ctrl, 916 .vidioc_s_audio = vidioc_s_audio,
1767 .vidioc_streamon = vidioc_streamon, 917 .vidioc_streamon = vb2_ioctl_streamon,
1768 .vidioc_streamoff = vidioc_streamoff, 918 .vidioc_streamoff = vb2_ioctl_streamoff,
1769 .vidioc_g_tuner = vidioc_g_tuner, 919 .vidioc_g_tuner = vidioc_g_tuner,
1770 .vidioc_s_tuner = vidioc_s_tuner, 920 .vidioc_s_tuner = vidioc_s_tuner,
1771 .vidioc_g_frequency = vidioc_g_frequency, 921 .vidioc_g_frequency = vidioc_g_frequency,
@@ -1774,66 +924,129 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1774 .vidioc_s_parm = vidioc_s_parm, 924 .vidioc_s_parm = vidioc_s_parm,
1775 .vidioc_enum_framesizes = vidioc_enum_framesizes, 925 .vidioc_enum_framesizes = vidioc_enum_framesizes,
1776 .vidioc_enum_frameintervals = vidioc_enum_frameintervals, 926 .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
1777 .vidioc_cropcap = vidioc_cropcap, 927 .vidioc_log_status = vidioc_log_status,
1778 .vidioc_g_crop = vidioc_g_crop, 928 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1779 .vidioc_s_crop = vidioc_s_crop, 929 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1780 .vidioc_g_jpegcomp = vidioc_g_jpegcomp,
1781 .vidioc_s_jpegcomp = vidioc_s_jpegcomp,
1782}; 930};
1783 931
1784static struct video_device go7007_template = { 932static struct video_device go7007_template = {
1785 .name = "go7007", 933 .name = "go7007",
1786 .fops = &go7007_fops, 934 .fops = &go7007_fops,
1787 .release = go7007_vfl_release, 935 .release = video_device_release_empty,
1788 .ioctl_ops = &video_ioctl_ops, 936 .ioctl_ops = &video_ioctl_ops,
1789 .tvnorms = V4L2_STD_ALL, 937 .tvnorms = V4L2_STD_ALL,
1790 .current_norm = V4L2_STD_NTSC,
1791}; 938};
1792 939
940int go7007_v4l2_ctrl_init(struct go7007 *go)
941{
942 struct v4l2_ctrl_handler *hdl = &go->hdl;
943 struct v4l2_ctrl *ctrl;
944
945 v4l2_ctrl_handler_init(hdl, 13);
946 go->mpeg_video_gop_size = v4l2_ctrl_new_std(hdl, NULL,
947 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, 34, 1, 15);
948 go->mpeg_video_gop_closure = v4l2_ctrl_new_std(hdl, NULL,
949 V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 0, 1, 1, 1);
950 go->mpeg_video_bitrate = v4l2_ctrl_new_std(hdl, NULL,
951 V4L2_CID_MPEG_VIDEO_BITRATE,
952 64000, 10000000, 1, 9800000);
953 go->mpeg_video_b_frames = v4l2_ctrl_new_std(hdl, NULL,
954 V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 2, 2, 0);
955 go->mpeg_video_rep_seqheader = v4l2_ctrl_new_std(hdl, NULL,
956 V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, 0, 1, 1, 1);
957
958 go->mpeg_video_aspect_ratio = v4l2_ctrl_new_std_menu(hdl, NULL,
959 V4L2_CID_MPEG_VIDEO_ASPECT,
960 V4L2_MPEG_VIDEO_ASPECT_16x9, 0,
961 V4L2_MPEG_VIDEO_ASPECT_1x1);
962 ctrl = v4l2_ctrl_new_std(hdl, NULL,
963 V4L2_CID_JPEG_ACTIVE_MARKER, 0,
964 V4L2_JPEG_ACTIVE_MARKER_DQT | V4L2_JPEG_ACTIVE_MARKER_DHT, 0,
965 V4L2_JPEG_ACTIVE_MARKER_DQT | V4L2_JPEG_ACTIVE_MARKER_DHT);
966 if (ctrl)
967 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
968 if (hdl->error) {
969 int rv = hdl->error;
970
971 v4l2_err(&go->v4l2_dev, "Could not register controls\n");
972 return rv;
973 }
974 go->v4l2_dev.ctrl_handler = hdl;
975 return 0;
976}
977
1793int go7007_v4l2_init(struct go7007 *go) 978int go7007_v4l2_init(struct go7007 *go)
1794{ 979{
980 struct video_device *vdev = &go->vdev;
1795 int rv; 981 int rv;
1796 982
1797 go->video_dev = video_device_alloc(); 983 mutex_init(&go->serialize_lock);
1798 if (go->video_dev == NULL) 984 mutex_init(&go->queue_lock);
1799 return -ENOMEM; 985
1800 *go->video_dev = go7007_template; 986 INIT_LIST_HEAD(&go->vidq_active);
1801 go->video_dev->parent = go->dev; 987 go->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1802 rv = video_register_device(go->video_dev, VFL_TYPE_GRABBER, -1); 988 go->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1803 if (rv < 0) { 989 go->vidq.ops = &go7007_video_qops;
1804 video_device_release(go->video_dev); 990 go->vidq.mem_ops = &vb2_vmalloc_memops;
1805 go->video_dev = NULL; 991 go->vidq.drv_priv = go;
992 go->vidq.buf_struct_size = sizeof(struct go7007_buffer);
993 go->vidq.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
994 go->vidq.lock = &go->queue_lock;
995 rv = vb2_queue_init(&go->vidq);
996 if (rv)
1806 return rv; 997 return rv;
998 *vdev = go7007_template;
999 vdev->lock = &go->serialize_lock;
1000 vdev->queue = &go->vidq;
1001 set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1002 video_set_drvdata(vdev, go);
1003 vdev->v4l2_dev = &go->v4l2_dev;
1004 if (!v4l2_device_has_op(&go->v4l2_dev, video, querystd))
1005 v4l2_disable_ioctl(vdev, VIDIOC_QUERYSTD);
1006 if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) {
1007 v4l2_disable_ioctl(vdev, VIDIOC_S_FREQUENCY);
1008 v4l2_disable_ioctl(vdev, VIDIOC_G_FREQUENCY);
1009 v4l2_disable_ioctl(vdev, VIDIOC_S_TUNER);
1010 v4l2_disable_ioctl(vdev, VIDIOC_G_TUNER);
1011 } else {
1012 struct v4l2_frequency f = {
1013 .type = V4L2_TUNER_ANALOG_TV,
1014 .frequency = 980,
1015 };
1016
1017 call_all(&go->v4l2_dev, tuner, s_frequency, &f);
1807 } 1018 }
1808 rv = v4l2_device_register(go->dev, &go->v4l2_dev); 1019 if (!(go->board_info->sensor_flags & GO7007_SENSOR_TV)) {
1809 if (rv < 0) { 1020 v4l2_disable_ioctl(vdev, VIDIOC_G_STD);
1810 video_device_release(go->video_dev); 1021 v4l2_disable_ioctl(vdev, VIDIOC_S_STD);
1811 go->video_dev = NULL; 1022 vdev->tvnorms = 0;
1812 return rv; 1023 }
1024 if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING)
1025 v4l2_disable_ioctl(vdev, VIDIOC_ENUM_FRAMESIZES);
1026 if (go->board_info->num_aud_inputs == 0) {
1027 v4l2_disable_ioctl(vdev, VIDIOC_G_AUDIO);
1028 v4l2_disable_ioctl(vdev, VIDIOC_S_AUDIO);
1029 v4l2_disable_ioctl(vdev, VIDIOC_ENUMAUDIO);
1813 } 1030 }
1814 video_set_drvdata(go->video_dev, go); 1031 /* Setup correct crystal frequency on this board */
1815 ++go->ref_count; 1032 if (go->board_info->sensor_flags & GO7007_SENSOR_SAA7115)
1033 v4l2_subdev_call(go->sd_video, video, s_crystal_freq,
1034 SAA7115_FREQ_24_576_MHZ,
1035 SAA7115_FREQ_FL_APLL | SAA7115_FREQ_FL_UCGC |
1036 SAA7115_FREQ_FL_DOUBLE_ASCLK);
1037 go7007_s_input(go);
1038 if (go->board_info->sensor_flags & GO7007_SENSOR_TV)
1039 go7007_s_std(go);
1040 rv = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1041 if (rv < 0)
1042 return rv;
1816 dev_info(go->dev, "registered device %s [v4l2]\n", 1043 dev_info(go->dev, "registered device %s [v4l2]\n",
1817 video_device_node_name(go->video_dev)); 1044 video_device_node_name(vdev));
1818 1045
1819 return 0; 1046 return 0;
1820} 1047}
1821 1048
1822void go7007_v4l2_remove(struct go7007 *go) 1049void go7007_v4l2_remove(struct go7007 *go)
1823{ 1050{
1824 unsigned long flags; 1051 v4l2_ctrl_handler_free(&go->hdl);
1825
1826 mutex_lock(&go->hw_lock);
1827 if (go->streaming) {
1828 go->streaming = 0;
1829 go7007_stream_stop(go);
1830 spin_lock_irqsave(&go->spinlock, flags);
1831 abort_queued(go);
1832 spin_unlock_irqrestore(&go->spinlock, flags);
1833 }
1834 mutex_unlock(&go->hw_lock);
1835 if (go->video_dev)
1836 video_unregister_device(go->video_dev);
1837 if (go->status != STATUS_SHUTDOWN)
1838 v4l2_device_unregister(&go->v4l2_dev);
1839} 1052}
diff --git a/drivers/staging/media/go7007/go7007.h b/drivers/staging/media/go7007/go7007.h
index 7399c915a934..54b989738982 100644
--- a/drivers/staging/media/go7007/go7007.h
+++ b/drivers/staging/media/go7007/go7007.h
@@ -17,72 +17,6 @@
17 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 */ 18 */
19 19
20/* DEPRECATED -- use V4L2_PIX_FMT_MPEG and then call GO7007IOC_S_MPEG_PARAMS
21 * to select between MPEG1, MPEG2, and MPEG4 */
22#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG4 */
23
24/* These will be replaced with a better interface
25 * soon, so don't get too attached to them */
26#define GO7007IOC_S_BITRATE _IOW('V', BASE_VIDIOC_PRIVATE + 0, int)
27#define GO7007IOC_G_BITRATE _IOR('V', BASE_VIDIOC_PRIVATE + 1, int)
28
29enum go7007_aspect_ratio {
30 GO7007_ASPECT_RATIO_1_1 = 0,
31 GO7007_ASPECT_RATIO_4_3_NTSC = 1,
32 GO7007_ASPECT_RATIO_4_3_PAL = 2,
33 GO7007_ASPECT_RATIO_16_9_NTSC = 3,
34 GO7007_ASPECT_RATIO_16_9_PAL = 4,
35};
36
37/* Used to set generic compression parameters */
38struct go7007_comp_params {
39 __u32 gop_size;
40 __u32 max_b_frames;
41 enum go7007_aspect_ratio aspect_ratio;
42 __u32 flags;
43 __u32 reserved[8];
44};
45
46#define GO7007_COMP_CLOSED_GOP 0x00000001
47#define GO7007_COMP_OMIT_SEQ_HEADER 0x00000002
48
49enum go7007_mpeg_video_standard {
50 GO7007_MPEG_VIDEO_MPEG1 = 0,
51 GO7007_MPEG_VIDEO_MPEG2 = 1,
52 GO7007_MPEG_VIDEO_MPEG4 = 2,
53};
54
55/* Used to set parameters for V4L2_PIX_FMT_MPEG format */
56struct go7007_mpeg_params {
57 enum go7007_mpeg_video_standard mpeg_video_standard;
58 __u32 flags;
59 __u32 pali;
60 __u32 reserved[8];
61};
62
63#define GO7007_MPEG_FORCE_DVD_MODE 0x00000001
64#define GO7007_MPEG_OMIT_GOP_HEADER 0x00000002
65#define GO7007_MPEG_REPEAT_SEQHEADER 0x00000004
66
67#define GO7007_MPEG_PROFILE(format, pali) (((format)<<24)|(pali))
68
69#define GO7007_MPEG2_PROFILE_MAIN_MAIN GO7007_MPEG_PROFILE(2, 0x48)
70
71#define GO7007_MPEG4_PROFILE_S_L0 GO7007_MPEG_PROFILE(4, 0x08)
72#define GO7007_MPEG4_PROFILE_S_L1 GO7007_MPEG_PROFILE(4, 0x01)
73#define GO7007_MPEG4_PROFILE_S_L2 GO7007_MPEG_PROFILE(4, 0x02)
74#define GO7007_MPEG4_PROFILE_S_L3 GO7007_MPEG_PROFILE(4, 0x03)
75#define GO7007_MPEG4_PROFILE_ARTS_L1 GO7007_MPEG_PROFILE(4, 0x91)
76#define GO7007_MPEG4_PROFILE_ARTS_L2 GO7007_MPEG_PROFILE(4, 0x92)
77#define GO7007_MPEG4_PROFILE_ARTS_L3 GO7007_MPEG_PROFILE(4, 0x93)
78#define GO7007_MPEG4_PROFILE_ARTS_L4 GO7007_MPEG_PROFILE(4, 0x94)
79#define GO7007_MPEG4_PROFILE_AS_L0 GO7007_MPEG_PROFILE(4, 0xf0)
80#define GO7007_MPEG4_PROFILE_AS_L1 GO7007_MPEG_PROFILE(4, 0xf1)
81#define GO7007_MPEG4_PROFILE_AS_L2 GO7007_MPEG_PROFILE(4, 0xf2)
82#define GO7007_MPEG4_PROFILE_AS_L3 GO7007_MPEG_PROFILE(4, 0xf3)
83#define GO7007_MPEG4_PROFILE_AS_L4 GO7007_MPEG_PROFILE(4, 0xf4)
84#define GO7007_MPEG4_PROFILE_AS_L5 GO7007_MPEG_PROFILE(4, 0xf5)
85
86struct go7007_md_params { 20struct go7007_md_params {
87 __u16 region; 21 __u16 region;
88 __u16 trigger; 22 __u16 trigger;
@@ -98,14 +32,6 @@ struct go7007_md_region {
98 __u32 reserved[8]; 32 __u32 reserved[8];
99}; 33};
100 34
101#define GO7007IOC_S_MPEG_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 2, \
102 struct go7007_mpeg_params)
103#define GO7007IOC_G_MPEG_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 3, \
104 struct go7007_mpeg_params)
105#define GO7007IOC_S_COMP_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 4, \
106 struct go7007_comp_params)
107#define GO7007IOC_G_COMP_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 5, \
108 struct go7007_comp_params)
109#define GO7007IOC_S_MD_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 6, \ 35#define GO7007IOC_S_MD_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 6, \
110 struct go7007_md_params) 36 struct go7007_md_params)
111#define GO7007IOC_G_MD_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 7, \ 37#define GO7007IOC_G_MD_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 7, \
diff --git a/drivers/staging/media/go7007/s2250-board.c b/drivers/staging/media/go7007/s2250-board.c
index 37400bfa6ccb..beaa98b9c85a 100644
--- a/drivers/staging/media/go7007/s2250-board.c
+++ b/drivers/staging/media/go7007/s2250-board.c
@@ -29,6 +29,13 @@
29MODULE_DESCRIPTION("Sensoray 2250/2251 i2c v4l2 subdev driver"); 29MODULE_DESCRIPTION("Sensoray 2250/2251 i2c v4l2 subdev driver");
30MODULE_LICENSE("GPL v2"); 30MODULE_LICENSE("GPL v2");
31 31
32/*
33 * Note: this board has two i2c devices: a vpx3226f and a tlv320aic23b.
34 * Due to the unusual way these are accessed on this device we do not
35 * reuse the i2c drivers, but instead they are implemented in this
36 * driver. It would be nice to improve on this, though.
37 */
38
32#define TLV320_ADDRESS 0x34 39#define TLV320_ADDRESS 0x34
33#define VPX322_ADDR_ANALOGCONTROL1 0x02 40#define VPX322_ADDR_ANALOGCONTROL1 0x02
34#define VPX322_ADDR_BRIGHTNESS0 0x0127 41#define VPX322_ADDR_BRIGHTNESS0 0x0127
@@ -116,6 +123,7 @@ static u16 vid_regs_fp_pal[] = {
116 123
117struct s2250 { 124struct s2250 {
118 struct v4l2_subdev sd; 125 struct v4l2_subdev sd;
126 struct v4l2_ctrl_handler hdl;
119 v4l2_std_id std; 127 v4l2_std_id std;
120 int input; 128 int input;
121 int brightness; 129 int brightness;
@@ -353,127 +361,48 @@ static int s2250_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
353 u16 vidsource; 361 u16 vidsource;
354 362
355 vidsource = (state->input == 1) ? 0x040 : 0x020; 363 vidsource = (state->input == 1) ? 0x040 : 0x020;
356 switch (norm) { 364 if (norm & V4L2_STD_625_50) {
357 case V4L2_STD_NTSC:
358 write_regs_fp(client, vid_regs_fp);
359 write_reg_fp(client, 0x20, vidsource | 1);
360 break;
361 case V4L2_STD_PAL:
362 write_regs_fp(client, vid_regs_fp); 365 write_regs_fp(client, vid_regs_fp);
363 write_regs_fp(client, vid_regs_fp_pal); 366 write_regs_fp(client, vid_regs_fp_pal);
364 write_reg_fp(client, 0x20, vidsource); 367 write_reg_fp(client, 0x20, vidsource);
365 break; 368 } else {
366 default: 369 write_regs_fp(client, vid_regs_fp);
367 return -EINVAL; 370 write_reg_fp(client, 0x20, vidsource | 1);
368 } 371 }
369 state->std = norm; 372 state->std = norm;
370 return 0; 373 return 0;
371} 374}
372 375
373static int s2250_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *query) 376static int s2250_s_ctrl(struct v4l2_ctrl *ctrl)
374{ 377{
375 switch (query->id) { 378 struct s2250 *state = container_of(ctrl->handler, struct s2250, hdl);
376 case V4L2_CID_BRIGHTNESS: 379 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
377 return v4l2_ctrl_query_fill(query, 0, 100, 1, 50);
378 case V4L2_CID_CONTRAST:
379 return v4l2_ctrl_query_fill(query, 0, 100, 1, 50);
380 case V4L2_CID_SATURATION:
381 return v4l2_ctrl_query_fill(query, 0, 100, 1, 50);
382 case V4L2_CID_HUE:
383 return v4l2_ctrl_query_fill(query, -50, 50, 1, 0);
384 default:
385 return -EINVAL;
386 }
387 return 0;
388}
389
390static int s2250_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
391{
392 struct s2250 *state = to_state(sd);
393 struct i2c_client *client = v4l2_get_subdevdata(sd);
394 int value1;
395 u16 oldvalue; 380 u16 oldvalue;
396 381
397 switch (ctrl->id) { 382 switch (ctrl->id) {
398 case V4L2_CID_BRIGHTNESS: 383 case V4L2_CID_BRIGHTNESS:
399 if (ctrl->value > 100)
400 state->brightness = 100;
401 else if (ctrl->value < 0)
402 state->brightness = 0;
403 else
404 state->brightness = ctrl->value;
405 value1 = (state->brightness - 50) * 255 / 100;
406 read_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, &oldvalue); 384 read_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, &oldvalue);
407 write_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, 385 write_reg_fp(client, VPX322_ADDR_BRIGHTNESS0,
408 value1 | (oldvalue & ~0xff)); 386 ctrl->val | (oldvalue & ~0xff));
409 read_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, &oldvalue); 387 read_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, &oldvalue);
410 write_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, 388 write_reg_fp(client, VPX322_ADDR_BRIGHTNESS1,
411 value1 | (oldvalue & ~0xff)); 389 ctrl->val | (oldvalue & ~0xff));
412 write_reg_fp(client, 0x140, 0x60); 390 write_reg_fp(client, 0x140, 0x60);
413 break; 391 break;
414 case V4L2_CID_CONTRAST: 392 case V4L2_CID_CONTRAST:
415 if (ctrl->value > 100)
416 state->contrast = 100;
417 else if (ctrl->value < 0)
418 state->contrast = 0;
419 else
420 state->contrast = ctrl->value;
421 value1 = state->contrast * 0x40 / 100;
422 if (value1 > 0x3f)
423 value1 = 0x3f; /* max */
424 read_reg_fp(client, VPX322_ADDR_CONTRAST0, &oldvalue); 393 read_reg_fp(client, VPX322_ADDR_CONTRAST0, &oldvalue);
425 write_reg_fp(client, VPX322_ADDR_CONTRAST0, 394 write_reg_fp(client, VPX322_ADDR_CONTRAST0,
426 value1 | (oldvalue & ~0x3f)); 395 ctrl->val | (oldvalue & ~0x3f));
427 read_reg_fp(client, VPX322_ADDR_CONTRAST1, &oldvalue); 396 read_reg_fp(client, VPX322_ADDR_CONTRAST1, &oldvalue);
428 write_reg_fp(client, VPX322_ADDR_CONTRAST1, 397 write_reg_fp(client, VPX322_ADDR_CONTRAST1,
429 value1 | (oldvalue & ~0x3f)); 398 ctrl->val | (oldvalue & ~0x3f));
430 write_reg_fp(client, 0x140, 0x60); 399 write_reg_fp(client, 0x140, 0x60);
431 break; 400 break;
432 case V4L2_CID_SATURATION: 401 case V4L2_CID_SATURATION:
433 if (ctrl->value > 100) 402 write_reg_fp(client, VPX322_ADDR_SAT, ctrl->val);
434 state->saturation = 100;
435 else if (ctrl->value < 0)
436 state->saturation = 0;
437 else
438 state->saturation = ctrl->value;
439 value1 = state->saturation * 4140 / 100;
440 if (value1 > 4094)
441 value1 = 4094;
442 write_reg_fp(client, VPX322_ADDR_SAT, value1);
443 break;
444 case V4L2_CID_HUE:
445 if (ctrl->value > 50)
446 state->hue = 50;
447 else if (ctrl->value < -50)
448 state->hue = -50;
449 else
450 state->hue = ctrl->value;
451 /* clamp the hue range */
452 value1 = state->hue * 280 / 50;
453 write_reg_fp(client, VPX322_ADDR_HUE, value1);
454 break;
455 default:
456 return -EINVAL;
457 }
458 return 0;
459}
460
461static int s2250_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
462{
463 struct s2250 *state = to_state(sd);
464
465 switch (ctrl->id) {
466 case V4L2_CID_BRIGHTNESS:
467 ctrl->value = state->brightness;
468 break;
469 case V4L2_CID_CONTRAST:
470 ctrl->value = state->contrast;
471 break;
472 case V4L2_CID_SATURATION:
473 ctrl->value = state->saturation;
474 break; 403 break;
475 case V4L2_CID_HUE: 404 case V4L2_CID_HUE:
476 ctrl->value = state->hue; 405 write_reg_fp(client, VPX322_ADDR_HUE, ctrl->val);
477 break; 406 break;
478 default: 407 default:
479 return -EINVAL; 408 return -EINVAL;
@@ -531,24 +460,21 @@ static int s2250_log_status(struct v4l2_subdev *sd)
531 v4l2_info(sd, "Input: %s\n", state->input == 0 ? "Composite" : 460 v4l2_info(sd, "Input: %s\n", state->input == 0 ? "Composite" :
532 state->input == 1 ? "S-video" : 461 state->input == 1 ? "S-video" :
533 "error"); 462 "error");
534 v4l2_info(sd, "Brightness: %d\n", state->brightness);
535 v4l2_info(sd, "Contrast: %d\n", state->contrast);
536 v4l2_info(sd, "Saturation: %d\n", state->saturation);
537 v4l2_info(sd, "Hue: %d\n", state->hue);
538 v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" : 463 v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" :
539 state->audio_input == 1 ? "Mic" : 464 state->audio_input == 1 ? "Mic" :
540 state->audio_input == 2 ? "Mic Boost" : 465 state->audio_input == 2 ? "Mic Boost" :
541 "error"); 466 "error");
542 return 0; 467 return v4l2_ctrl_subdev_log_status(sd);
543} 468}
544 469
545/* --------------------------------------------------------------------------*/ 470/* --------------------------------------------------------------------------*/
546 471
472static const struct v4l2_ctrl_ops s2250_ctrl_ops = {
473 .s_ctrl = s2250_s_ctrl,
474};
475
547static const struct v4l2_subdev_core_ops s2250_core_ops = { 476static const struct v4l2_subdev_core_ops s2250_core_ops = {
548 .log_status = s2250_log_status, 477 .log_status = s2250_log_status,
549 .g_ctrl = s2250_g_ctrl,
550 .s_ctrl = s2250_s_ctrl,
551 .queryctrl = s2250_queryctrl,
552 .s_std = s2250_s_std, 478 .s_std = s2250_s_std,
553}; 479};
554 480
@@ -584,7 +510,7 @@ static int s2250_probe(struct i2c_client *client,
584 if (audio == NULL) 510 if (audio == NULL)
585 return -ENOMEM; 511 return -ENOMEM;
586 512
587 state = kmalloc(sizeof(struct s2250), GFP_KERNEL); 513 state = kzalloc(sizeof(struct s2250), GFP_KERNEL);
588 if (state == NULL) { 514 if (state == NULL) {
589 i2c_unregister_device(audio); 515 i2c_unregister_device(audio);
590 return -ENOMEM; 516 return -ENOMEM;
@@ -596,6 +522,24 @@ static int s2250_probe(struct i2c_client *client,
596 v4l2_info(sd, "initializing %s at address 0x%x on %s\n", 522 v4l2_info(sd, "initializing %s at address 0x%x on %s\n",
597 "Sensoray 2250/2251", client->addr, client->adapter->name); 523 "Sensoray 2250/2251", client->addr, client->adapter->name);
598 524
525 v4l2_ctrl_handler_init(&state->hdl, 4);
526 v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
527 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
528 v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
529 V4L2_CID_CONTRAST, 0, 0x3f, 1, 0x32);
530 v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
531 V4L2_CID_SATURATION, 0, 4094, 1, 2070);
532 v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
533 V4L2_CID_HUE, -512, 511, 1, 0);
534 sd->ctrl_handler = &state->hdl;
535 if (state->hdl.error) {
536 int err = state->hdl.error;
537
538 v4l2_ctrl_handler_free(&state->hdl);
539 kfree(state);
540 return err;
541 }
542
599 state->std = V4L2_STD_NTSC; 543 state->std = V4L2_STD_NTSC;
600 state->brightness = 50; 544 state->brightness = 50;
601 state->contrast = 50; 545 state->contrast = 50;
@@ -606,22 +550,16 @@ static int s2250_probe(struct i2c_client *client,
606 /* initialize the audio */ 550 /* initialize the audio */
607 if (write_regs(audio, aud_regs) < 0) { 551 if (write_regs(audio, aud_regs) < 0) {
608 dev_err(&client->dev, "error initializing audio\n"); 552 dev_err(&client->dev, "error initializing audio\n");
609 i2c_unregister_device(audio); 553 goto fail;
610 kfree(state);
611 return 0;
612 } 554 }
613 555
614 if (write_regs(client, vid_regs) < 0) { 556 if (write_regs(client, vid_regs) < 0) {
615 dev_err(&client->dev, "error initializing decoder\n"); 557 dev_err(&client->dev, "error initializing decoder\n");
616 i2c_unregister_device(audio); 558 goto fail;
617 kfree(state);
618 return 0;
619 } 559 }
620 if (write_regs_fp(client, vid_regs_fp) < 0) { 560 if (write_regs_fp(client, vid_regs_fp) < 0) {
621 dev_err(&client->dev, "error initializing decoder\n"); 561 dev_err(&client->dev, "error initializing decoder\n");
622 i2c_unregister_device(audio); 562 goto fail;
623 kfree(state);
624 return 0;
625 } 563 }
626 /* set default channel */ 564 /* set default channel */
627 /* composite */ 565 /* composite */
@@ -657,14 +595,21 @@ static int s2250_probe(struct i2c_client *client,
657 595
658 v4l2_info(sd, "initialized successfully\n"); 596 v4l2_info(sd, "initialized successfully\n");
659 return 0; 597 return 0;
598
599fail:
600 i2c_unregister_device(audio);
601 v4l2_ctrl_handler_free(&state->hdl);
602 kfree(state);
603 return -EIO;
660} 604}
661 605
662static int s2250_remove(struct i2c_client *client) 606static int s2250_remove(struct i2c_client *client)
663{ 607{
664 struct v4l2_subdev *sd = i2c_get_clientdata(client); 608 struct s2250 *state = to_state(i2c_get_clientdata(client));
665 609
666 v4l2_device_unregister_subdev(sd); 610 v4l2_device_unregister_subdev(&state->sd);
667 kfree(to_state(sd)); 611 v4l2_ctrl_handler_free(&state->hdl);
612 kfree(state);
668 return 0; 613 return 0;
669} 614}
670 615
diff --git a/drivers/staging/media/go7007/s2250-loader.c b/drivers/staging/media/go7007/s2250-loader.c
deleted file mode 100644
index 72e5175fe7e3..000000000000
--- a/drivers/staging/media/go7007/s2250-loader.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/*
2 * Copyright (C) 2008 Sensoray Company Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/usb.h>
22#include <dvb-usb.h>
23
24#define S2250_LOADER_FIRMWARE "s2250_loader.fw"
25#define S2250_FIRMWARE "s2250.fw"
26
27typedef struct device_extension_s {
28 struct kref kref;
29 int minor;
30 struct usb_device *usbdev;
31} device_extension_t, *pdevice_extension_t;
32
33#define USB_s2250loader_MAJOR 240
34#define USB_s2250loader_MINOR_BASE 0
35#define MAX_DEVICES 256
36
37static pdevice_extension_t s2250_dev_table[MAX_DEVICES];
38static DEFINE_MUTEX(s2250_dev_table_mutex);
39
40#define to_s2250loader_dev_common(d) container_of(d, device_extension_t, kref)
41static void s2250loader_delete(struct kref *kref)
42{
43 pdevice_extension_t s = to_s2250loader_dev_common(kref);
44 s2250_dev_table[s->minor] = NULL;
45 kfree(s);
46}
47
48static int s2250loader_probe(struct usb_interface *interface,
49 const struct usb_device_id *id)
50{
51 struct usb_device *usbdev;
52 int minor, ret;
53 pdevice_extension_t s = NULL;
54 const struct firmware *fw;
55
56 usbdev = usb_get_dev(interface_to_usbdev(interface));
57 if (!usbdev) {
58 dev_err(&interface->dev, "Enter s2250loader_probe failed\n");
59 return -1;
60 }
61 dev_info(&interface->dev, "Enter s2250loader_probe 2.6 kernel\n");
62 dev_info(&interface->dev, "vendor id 0x%x, device id 0x%x devnum:%d\n",
63 usbdev->descriptor.idVendor, usbdev->descriptor.idProduct,
64 usbdev->devnum);
65
66 if (usbdev->descriptor.bNumConfigurations != 1) {
67 dev_err(&interface->dev, "can't handle multiple config\n");
68 return -1;
69 }
70 mutex_lock(&s2250_dev_table_mutex);
71
72 for (minor = 0; minor < MAX_DEVICES; minor++) {
73 if (s2250_dev_table[minor] == NULL)
74 break;
75 }
76
77 if (minor < 0 || minor >= MAX_DEVICES) {
78 dev_err(&interface->dev, "Invalid minor: %d\n", minor);
79 goto failed;
80 }
81
82 /* Allocate dev data structure */
83 s = kmalloc(sizeof(device_extension_t), GFP_KERNEL);
84 if (s == NULL)
85 goto failed;
86
87 s2250_dev_table[minor] = s;
88
89 dev_info(&interface->dev,
90 "s2250loader_probe: Device %d on Bus %d Minor %d\n",
91 usbdev->devnum, usbdev->bus->busnum, minor);
92
93 memset(s, 0, sizeof(device_extension_t));
94 s->usbdev = usbdev;
95 dev_info(&interface->dev, "loading 2250 loader\n");
96
97 kref_init(&(s->kref));
98
99 mutex_unlock(&s2250_dev_table_mutex);
100
101 if (request_firmware(&fw, S2250_LOADER_FIRMWARE, &usbdev->dev)) {
102 dev_err(&interface->dev,
103 "s2250: unable to load firmware from file \"%s\"\n",
104 S2250_LOADER_FIRMWARE);
105 goto failed2;
106 }
107 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
108 release_firmware(fw);
109 if (0 != ret) {
110 dev_err(&interface->dev, "loader download failed\n");
111 goto failed2;
112 }
113
114 if (request_firmware(&fw, S2250_FIRMWARE, &usbdev->dev)) {
115 dev_err(&interface->dev,
116 "s2250: unable to load firmware from file \"%s\"\n",
117 S2250_FIRMWARE);
118 goto failed2;
119 }
120 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
121 release_firmware(fw);
122 if (0 != ret) {
123 dev_err(&interface->dev, "firmware_s2250 download failed\n");
124 goto failed2;
125 }
126
127 usb_set_intfdata(interface, s);
128 return 0;
129
130failed:
131 mutex_unlock(&s2250_dev_table_mutex);
132failed2:
133 if (s)
134 kref_put(&(s->kref), s2250loader_delete);
135
136 dev_err(&interface->dev, "probe failed\n");
137 return -1;
138}
139
140static void s2250loader_disconnect(struct usb_interface *interface)
141{
142 pdevice_extension_t s;
143 dev_info(&interface->dev, "s2250: disconnect\n");
144 s = usb_get_intfdata(interface);
145 usb_set_intfdata(interface, NULL);
146 kref_put(&(s->kref), s2250loader_delete);
147}
148
149static const struct usb_device_id s2250loader_ids[] = {
150 {USB_DEVICE(0x1943, 0xa250)},
151 {} /* Terminating entry */
152};
153
154MODULE_DEVICE_TABLE(usb, s2250loader_ids);
155
156static struct usb_driver s2250loader_driver = {
157 .name = "s2250-loader",
158 .probe = s2250loader_probe,
159 .disconnect = s2250loader_disconnect,
160 .id_table = s2250loader_ids,
161};
162
163module_usb_driver(s2250loader_driver);
164
165MODULE_AUTHOR("");
166MODULE_DESCRIPTION("firmware loader for Sensoray 2250/2251");
167MODULE_LICENSE("GPL v2");
168MODULE_FIRMWARE(S2250_LOADER_FIRMWARE);
169MODULE_FIRMWARE(S2250_FIRMWARE);
diff --git a/drivers/staging/media/go7007/s2250-loader.h b/drivers/staging/media/go7007/s2250-loader.h
deleted file mode 100644
index b7c301af16cc..000000000000
--- a/drivers/staging/media/go7007/s2250-loader.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#ifndef _S2250_LOADER_H_
19#define _S2250_LOADER_H_
20
21extern int s2250loader_init(void);
22extern void s2250loader_cleanup(void);
23
24#endif
diff --git a/drivers/staging/media/go7007/saa7134-go7007.c b/drivers/staging/media/go7007/saa7134-go7007.c
index cf7c34a99459..d80b235d72ee 100644
--- a/drivers/staging/media/go7007/saa7134-go7007.c
+++ b/drivers/staging/media/go7007/saa7134-go7007.c
@@ -28,12 +28,15 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <asm/byteorder.h> 29#include <asm/byteorder.h>
30#include <media/v4l2-common.h> 30#include <media/v4l2-common.h>
31#include <media/v4l2-device.h>
32#include <media/v4l2-subdev.h>
31 33
32#include "saa7134-reg.h"
33#include "saa7134.h" 34#include "saa7134.h"
35#include "saa7134-reg.h"
36#include "go7007.h"
34#include "go7007-priv.h" 37#include "go7007-priv.h"
35 38
36#define GO7007_HPI_DEBUG 39/*#define GO7007_HPI_DEBUG*/
37 40
38enum hpi_address { 41enum hpi_address {
39 HPI_ADDR_VIDEO_BUFFER = 0xe4, 42 HPI_ADDR_VIDEO_BUFFER = 0xe4,
@@ -57,6 +60,7 @@ enum gpio_command {
57}; 60};
58 61
59struct saa7134_go7007 { 62struct saa7134_go7007 {
63 struct v4l2_subdev sd;
60 struct saa7134_dev *dev; 64 struct saa7134_dev *dev;
61 u8 *top; 65 u8 *top;
62 u8 *bottom; 66 u8 *bottom;
@@ -64,8 +68,12 @@ struct saa7134_go7007 {
64 dma_addr_t bottom_dma; 68 dma_addr_t bottom_dma;
65}; 69};
66 70
67static struct go7007_board_info board_voyager = { 71static inline struct saa7134_go7007 *to_state(struct v4l2_subdev *sd)
68 .firmware = "go7007tv.bin", 72{
73 return container_of(sd, struct saa7134_go7007, sd);
74}
75
76static const struct go7007_board_info board_voyager = {
69 .flags = 0, 77 .flags = 0,
70 .sensor_flags = GO7007_SENSOR_656 | 78 .sensor_flags = GO7007_SENSOR_656 |
71 GO7007_SENSOR_VALID_ENABLE | 79 GO7007_SENSOR_VALID_ENABLE |
@@ -84,7 +92,6 @@ static struct go7007_board_info board_voyager = {
84 }, 92 },
85 }, 93 },
86}; 94};
87MODULE_FIRMWARE("go7007tv.bin");
88 95
89/********************* Driver for GPIO HPI interface *********************/ 96/********************* Driver for GPIO HPI interface *********************/
90 97
@@ -236,7 +243,7 @@ static void saa7134_go7007_irq_ts_done(struct saa7134_dev *dev,
236 struct go7007 *go = video_get_drvdata(dev->empress_dev); 243 struct go7007 *go = video_get_drvdata(dev->empress_dev);
237 struct saa7134_go7007 *saa = go->hpi_context; 244 struct saa7134_go7007 *saa = go->hpi_context;
238 245
239 if (!go->streaming) 246 if (!vb2_is_streaming(&go->vidq))
240 return; 247 return;
241 if (0 != (status & 0x000f0000)) 248 if (0 != (status & 0x000f0000))
242 printk(KERN_DEBUG "saa7134-go7007: irq: lost %ld\n", 249 printk(KERN_DEBUG "saa7134-go7007: irq: lost %ld\n",
@@ -261,12 +268,12 @@ static int saa7134_go7007_stream_start(struct go7007 *go)
261 268
262 saa->top_dma = dma_map_page(&dev->pci->dev, virt_to_page(saa->top), 269 saa->top_dma = dma_map_page(&dev->pci->dev, virt_to_page(saa->top),
263 0, PAGE_SIZE, DMA_FROM_DEVICE); 270 0, PAGE_SIZE, DMA_FROM_DEVICE);
264 if (!saa->top_dma) 271 if (dma_mapping_error(&dev->pci->dev, saa->top_dma))
265 return -ENOMEM; 272 return -ENOMEM;
266 saa->bottom_dma = dma_map_page(&dev->pci->dev, 273 saa->bottom_dma = dma_map_page(&dev->pci->dev,
267 virt_to_page(saa->bottom), 274 virt_to_page(saa->bottom),
268 0, PAGE_SIZE, DMA_FROM_DEVICE); 275 0, PAGE_SIZE, DMA_FROM_DEVICE);
269 if (!saa->bottom_dma) { 276 if (dma_mapping_error(&dev->pci->dev, saa->bottom_dma)) {
270 dma_unmap_page(&dev->pci->dev, saa->top_dma, PAGE_SIZE, 277 dma_unmap_page(&dev->pci->dev, saa->top_dma, PAGE_SIZE,
271 DMA_FROM_DEVICE); 278 DMA_FROM_DEVICE);
272 return -ENOMEM; 279 return -ENOMEM;
@@ -380,47 +387,6 @@ static int saa7134_go7007_send_firmware(struct go7007 *go, u8 *data, int len)
380 return 0; 387 return 0;
381} 388}
382 389
383static int saa7134_go7007_send_command(struct go7007 *go, unsigned int cmd,
384 void *arg)
385{
386 struct saa7134_go7007 *saa = go->hpi_context;
387 struct saa7134_dev *dev = saa->dev;
388
389 switch (cmd) {
390 case VIDIOC_S_STD:
391 {
392 v4l2_std_id *std = arg;
393 return saa7134_s_std_internal(dev, NULL, std);
394 }
395 case VIDIOC_G_STD:
396 {
397 v4l2_std_id *std = arg;
398 *std = dev->tvnorm->id;
399 return 0;
400 }
401 case VIDIOC_QUERYCTRL:
402 {
403 struct v4l2_queryctrl *ctrl = arg;
404 if (V4L2_CTRL_ID2CLASS(ctrl->id) == V4L2_CTRL_CLASS_USER)
405 return saa7134_queryctrl(NULL, NULL, ctrl);
406 }
407 case VIDIOC_G_CTRL:
408 {
409 struct v4l2_control *ctrl = arg;
410 if (V4L2_CTRL_ID2CLASS(ctrl->id) == V4L2_CTRL_CLASS_USER)
411 return saa7134_g_ctrl_internal(dev, NULL, ctrl);
412 }
413 case VIDIOC_S_CTRL:
414 {
415 struct v4l2_control *ctrl = arg;
416 if (V4L2_CTRL_ID2CLASS(ctrl->id) == V4L2_CTRL_CLASS_USER)
417 return saa7134_s_ctrl_internal(dev, NULL, ctrl);
418 }
419 }
420 return -EINVAL;
421
422}
423
424static struct go7007_hpi_ops saa7134_go7007_hpi_ops = { 390static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
425 .interface_reset = saa7134_go7007_interface_reset, 391 .interface_reset = saa7134_go7007_interface_reset,
426 .write_interrupt = saa7134_go7007_write_interrupt, 392 .write_interrupt = saa7134_go7007_write_interrupt,
@@ -428,21 +394,88 @@ static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
428 .stream_start = saa7134_go7007_stream_start, 394 .stream_start = saa7134_go7007_stream_start,
429 .stream_stop = saa7134_go7007_stream_stop, 395 .stream_stop = saa7134_go7007_stream_stop,
430 .send_firmware = saa7134_go7007_send_firmware, 396 .send_firmware = saa7134_go7007_send_firmware,
431 .send_command = saa7134_go7007_send_command, 397};
398MODULE_FIRMWARE("go7007/go7007tv.bin");
399
400/* --------------------------------------------------------------------------*/
401
402static int saa7134_go7007_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
403{
404 struct saa7134_go7007 *saa = to_state(sd);
405 struct saa7134_dev *dev = saa->dev;
406
407 return saa7134_s_std_internal(dev, NULL, norm);
408}
409
410static int saa7134_go7007_queryctrl(struct v4l2_subdev *sd,
411 struct v4l2_queryctrl *query)
412{
413 return saa7134_queryctrl(NULL, NULL, query);
414}
415static int saa7134_go7007_s_ctrl(struct v4l2_subdev *sd,
416 struct v4l2_control *ctrl)
417{
418 struct saa7134_go7007 *saa = to_state(sd);
419 struct saa7134_dev *dev = saa->dev;
420 return saa7134_s_ctrl_internal(dev, NULL, ctrl);
421}
422
423static int saa7134_go7007_g_ctrl(struct v4l2_subdev *sd,
424 struct v4l2_control *ctrl)
425{
426 struct saa7134_go7007 *saa = to_state(sd);
427 struct saa7134_dev *dev = saa->dev;
428 return saa7134_g_ctrl_internal(dev, NULL, ctrl);
429}
430
431/* --------------------------------------------------------------------------*/
432
433static const struct v4l2_subdev_core_ops saa7134_go7007_core_ops = {
434 .g_ctrl = saa7134_go7007_g_ctrl,
435 .s_ctrl = saa7134_go7007_s_ctrl,
436 .queryctrl = saa7134_go7007_queryctrl,
437 .s_std = saa7134_go7007_s_std,
438};
439
440static const struct v4l2_subdev_ops saa7134_go7007_sd_ops = {
441 .core = &saa7134_go7007_core_ops,
432}; 442};
433 443
444/* --------------------------------------------------------------------------*/
445
446
434/********************* Add/remove functions *********************/ 447/********************* Add/remove functions *********************/
435 448
436static int saa7134_go7007_init(struct saa7134_dev *dev) 449static int saa7134_go7007_init(struct saa7134_dev *dev)
437{ 450{
438 struct go7007 *go; 451 struct go7007 *go;
439 struct saa7134_go7007 *saa; 452 struct saa7134_go7007 *saa;
453 struct v4l2_subdev *sd;
440 454
441 printk(KERN_DEBUG "saa7134-go7007: probing new SAA713X board\n"); 455 printk(KERN_DEBUG "saa7134-go7007: probing new SAA713X board\n");
442 456
457 go = go7007_alloc(&board_voyager, &dev->pci->dev);
458 if (go == NULL)
459 return -ENOMEM;
460
443 saa = kzalloc(sizeof(struct saa7134_go7007), GFP_KERNEL); 461 saa = kzalloc(sizeof(struct saa7134_go7007), GFP_KERNEL);
444 if (saa == NULL) 462 if (saa == NULL) {
463 kfree(go);
445 return -ENOMEM; 464 return -ENOMEM;
465 }
466
467 go->board_id = GO7007_BOARDID_PCI_VOYAGER;
468 snprintf(go->bus_info, sizeof(go->bus_info), "PCI:%s", pci_name(dev->pci));
469 strlcpy(go->name, saa7134_boards[dev->board].name, sizeof(go->name));
470 go->hpi_ops = &saa7134_go7007_hpi_ops;
471 go->hpi_context = saa;
472 saa->dev = dev;
473
474 /* Init the subdevice interface */
475 sd = &saa->sd;
476 v4l2_subdev_init(sd, &saa7134_go7007_sd_ops);
477 v4l2_set_subdevdata(sd, saa);
478 strncpy(sd->name, "saa7134-go7007", sizeof(sd->name));
446 479
447 /* Allocate a couple pages for receiving the compressed stream */ 480 /* Allocate a couple pages for receiving the compressed stream */
448 saa->top = (u8 *)get_zeroed_page(GFP_KERNEL); 481 saa->top = (u8 *)get_zeroed_page(GFP_KERNEL);
@@ -452,32 +485,23 @@ static int saa7134_go7007_init(struct saa7134_dev *dev)
452 if (!saa->bottom) 485 if (!saa->bottom)
453 goto allocfail; 486 goto allocfail;
454 487
455 go = go7007_alloc(&board_voyager, &dev->pci->dev);
456 if (go == NULL)
457 goto allocfail;
458 go->board_id = GO7007_BOARDID_PCI_VOYAGER;
459 strncpy(go->name, saa7134_boards[dev->board].name, sizeof(go->name));
460 go->hpi_ops = &saa7134_go7007_hpi_ops;
461 go->hpi_context = saa;
462 saa->dev = dev;
463
464 /* Boot the GO7007 */ 488 /* Boot the GO7007 */
465 if (go7007_boot_encoder(go, go->board_info->flags & 489 if (go7007_boot_encoder(go, go->board_info->flags &
466 GO7007_BOARD_USE_ONBOARD_I2C) < 0) 490 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
467 goto initfail; 491 goto allocfail;
468 492
469 /* Do any final GO7007 initialization, then register the 493 /* Do any final GO7007 initialization, then register the
470 * V4L2 and ALSA interfaces */ 494 * V4L2 and ALSA interfaces */
471 if (go7007_register_encoder(go) < 0) 495 if (go7007_register_encoder(go, go->board_info->num_i2c_devs) < 0)
472 goto initfail; 496 goto allocfail;
473 dev->empress_dev = go->video_dev;
474 video_set_drvdata(dev->empress_dev, go);
475 497
476 go->status = STATUS_ONLINE; 498 /* Register the subdevice interface with the go7007 device */
477 return 0; 499 if (v4l2_device_register_subdev(&go->v4l2_dev, sd) < 0)
500 printk(KERN_INFO "saa7134-go7007: register subdev failed\n");
478 501
479initfail: 502 dev->empress_dev = &go->vdev;
480 go->status = STATUS_SHUTDOWN; 503
504 go->status = STATUS_ONLINE;
481 return 0; 505 return 0;
482 506
483allocfail: 507allocfail:
@@ -486,6 +510,7 @@ allocfail:
486 if (saa->bottom) 510 if (saa->bottom)
487 free_page((unsigned long)saa->bottom); 511 free_page((unsigned long)saa->bottom);
488 kfree(saa); 512 kfree(saa);
513 kfree(go);
489 return -ENOMEM; 514 return -ENOMEM;
490} 515}
491 516
@@ -498,12 +523,18 @@ static int saa7134_go7007_fini(struct saa7134_dev *dev)
498 return 0; 523 return 0;
499 524
500 go = video_get_drvdata(dev->empress_dev); 525 go = video_get_drvdata(dev->empress_dev);
526 if (go->audio_enabled)
527 go7007_snd_remove(go);
528
501 saa = go->hpi_context; 529 saa = go->hpi_context;
502 go->status = STATUS_SHUTDOWN; 530 go->status = STATUS_SHUTDOWN;
503 free_page((unsigned long)saa->top); 531 free_page((unsigned long)saa->top);
504 free_page((unsigned long)saa->bottom); 532 free_page((unsigned long)saa->bottom);
533 v4l2_device_unregister_subdev(&saa->sd);
505 kfree(saa); 534 kfree(saa);
506 go7007_remove(go); 535 video_unregister_device(&go->vdev);
536
537 v4l2_device_put(&go->v4l2_dev);
507 dev->empress_dev = NULL; 538 dev->empress_dev = NULL;
508 539
509 return 0; 540 return 0;
diff --git a/drivers/staging/media/go7007/snd-go7007.c b/drivers/staging/media/go7007/snd-go7007.c
index 5af29ff68bfd..4be0fa40a39a 100644
--- a/drivers/staging/media/go7007/snd-go7007.c
+++ b/drivers/staging/media/go7007/snd-go7007.c
@@ -221,8 +221,6 @@ static int go7007_snd_free(struct snd_device *device)
221 221
222 kfree(go->snd_context); 222 kfree(go->snd_context);
223 go->snd_context = NULL; 223 go->snd_context = NULL;
224 if (--go->ref_count == 0)
225 kfree(go);
226 return 0; 224 return 0;
227} 225}
228 226
@@ -267,9 +265,9 @@ int go7007_snd_init(struct go7007 *go)
267 kfree(gosnd); 265 kfree(gosnd);
268 return ret; 266 return ret;
269 } 267 }
270 strncpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver)); 268 strlcpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver));
271 strncpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->driver)); 269 strlcpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->driver));
272 strncpy(gosnd->card->longname, gosnd->card->shortname, 270 strlcpy(gosnd->card->longname, gosnd->card->shortname,
273 sizeof(gosnd->card->longname)); 271 sizeof(gosnd->card->longname));
274 272
275 gosnd->pcm->private_data = go; 273 gosnd->pcm->private_data = go;
@@ -285,8 +283,8 @@ int go7007_snd_init(struct go7007 *go)
285 283
286 gosnd->substream = NULL; 284 gosnd->substream = NULL;
287 go->snd_context = gosnd; 285 go->snd_context = gosnd;
286 v4l2_device_get(&go->v4l2_dev);
288 ++dev; 287 ++dev;
289 ++go->ref_count;
290 288
291 return 0; 289 return 0;
292} 290}
@@ -298,6 +296,7 @@ int go7007_snd_remove(struct go7007 *go)
298 296
299 snd_card_disconnect(gosnd->card); 297 snd_card_disconnect(gosnd->card);
300 snd_card_free_when_closed(gosnd->card); 298 snd_card_free_when_closed(gosnd->card);
299 v4l2_device_put(&go->v4l2_dev);
301 return 0; 300 return 0;
302} 301}
303EXPORT_SYMBOL(go7007_snd_remove); 302EXPORT_SYMBOL(go7007_snd_remove);
diff --git a/drivers/staging/media/go7007/wis-i2c.h b/drivers/staging/media/go7007/wis-i2c.h
deleted file mode 100644
index 6d09c06c8560..000000000000
--- a/drivers/staging/media/go7007/wis-i2c.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18/* Temporary I2C IDs -- these need to be replaced with real registered IDs */
19#define I2C_DRIVERID_WIS_SAA7115 0xf0f0
20#define I2C_DRIVERID_WIS_UDA1342 0xf0f1
21#define I2C_DRIVERID_WIS_SONY_TUNER 0xf0f2
22#define I2C_DRIVERID_WIS_TW9903 0xf0f3
23#define I2C_DRIVERID_WIS_SAA7113 0xf0f4
24#define I2C_DRIVERID_WIS_OV7640 0xf0f5
25#define I2C_DRIVERID_WIS_TW2804 0xf0f6
26#define I2C_DRIVERID_S2250 0xf0f7
27
28/* Definitions for new video decoder commands */
29
30struct video_decoder_resolution {
31 unsigned int width;
32 unsigned int height;
33};
34
35#define DECODER_SET_RESOLUTION _IOW('d', 200, struct video_decoder_resolution)
36#define DECODER_SET_CHANNEL _IOW('d', 201, int)
37
38/* Sony tuner types */
39
40#define TUNER_SONY_BTF_PG472Z 200
41#define TUNER_SONY_BTF_PK467Z 201
42#define TUNER_SONY_BTF_PB463Z 202
diff --git a/drivers/staging/media/go7007/wis-saa7113.c b/drivers/staging/media/go7007/wis-saa7113.c
deleted file mode 100644
index 891cde713a47..000000000000
--- a/drivers/staging/media/go7007/wis-saa7113.c
+++ /dev/null
@@ -1,324 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24
25#include "wis-i2c.h"
26
27struct wis_saa7113 {
28 int norm;
29 int brightness;
30 int contrast;
31 int saturation;
32 int hue;
33};
34
35static u8 initial_registers[] = {
36 0x01, 0x08,
37 0x02, 0xc0,
38 0x03, 0x33,
39 0x04, 0x00,
40 0x05, 0x00,
41 0x06, 0xe9,
42 0x07, 0x0d,
43 0x08, 0xd8,
44 0x09, 0x40,
45 0x0a, 0x80,
46 0x0b, 0x47,
47 0x0c, 0x40,
48 0x0d, 0x00,
49 0x0e, 0x01,
50 0x0f, 0x2a,
51 0x10, 0x40,
52 0x11, 0x0c,
53 0x12, 0xfe,
54 0x13, 0x00,
55 0x14, 0x00,
56 0x15, 0x04,
57 0x16, 0x00,
58 0x17, 0x00,
59 0x18, 0x00,
60 0x19, 0x00,
61 0x1a, 0x00,
62 0x1b, 0x00,
63 0x1c, 0x00,
64 0x1d, 0x00,
65 0x1e, 0x00,
66 0x1f, 0xc8,
67 0x40, 0x00,
68 0x41, 0xff,
69 0x42, 0xff,
70 0x43, 0xff,
71 0x44, 0xff,
72 0x45, 0xff,
73 0x46, 0xff,
74 0x47, 0xff,
75 0x48, 0xff,
76 0x49, 0xff,
77 0x4a, 0xff,
78 0x4b, 0xff,
79 0x4c, 0xff,
80 0x4d, 0xff,
81 0x4e, 0xff,
82 0x4f, 0xff,
83 0x50, 0xff,
84 0x51, 0xff,
85 0x52, 0xff,
86 0x53, 0xff,
87 0x54, 0xff,
88 0x55, 0xff,
89 0x56, 0xff,
90 0x57, 0xff,
91 0x58, 0x00,
92 0x59, 0x54,
93 0x5a, 0x07,
94 0x5b, 0x83,
95 0x5c, 0x00,
96 0x5d, 0x00,
97 0x5e, 0x00,
98 0x5f, 0x00,
99 0x60, 0x00,
100 0x61, 0x00,
101 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
102};
103
104static int write_reg(struct i2c_client *client, u8 reg, u8 value)
105{
106 return i2c_smbus_write_byte_data(client, reg, value);
107}
108
109static int write_regs(struct i2c_client *client, u8 *regs)
110{
111 int i;
112
113 for (i = 0; regs[i] != 0x00; i += 2)
114 if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
115 return -1;
116 return 0;
117}
118
119static int wis_saa7113_command(struct i2c_client *client,
120 unsigned int cmd, void *arg)
121{
122 struct wis_saa7113 *dec = i2c_get_clientdata(client);
123
124 switch (cmd) {
125 case VIDIOC_S_INPUT:
126 {
127 int *input = arg;
128
129 i2c_smbus_write_byte_data(client, 0x02, 0xC0 | *input);
130 i2c_smbus_write_byte_data(client, 0x09,
131 *input < 6 ? 0x40 : 0x80);
132 break;
133 }
134 case VIDIOC_S_STD:
135 {
136 v4l2_std_id *input = arg;
137 dec->norm = *input;
138 if (dec->norm & V4L2_STD_NTSC) {
139 write_reg(client, 0x0e, 0x01);
140 write_reg(client, 0x10, 0x40);
141 } else if (dec->norm & V4L2_STD_PAL) {
142 write_reg(client, 0x0e, 0x01);
143 write_reg(client, 0x10, 0x48);
144 } else if (dec->norm & V4L2_STD_SECAM) {
145 write_reg(client, 0x0e, 0x50);
146 write_reg(client, 0x10, 0x48);
147 }
148 break;
149 }
150 case VIDIOC_QUERYCTRL:
151 {
152 struct v4l2_queryctrl *ctrl = arg;
153
154 switch (ctrl->id) {
155 case V4L2_CID_BRIGHTNESS:
156 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
157 strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
158 ctrl->minimum = 0;
159 ctrl->maximum = 255;
160 ctrl->step = 1;
161 ctrl->default_value = 128;
162 ctrl->flags = 0;
163 break;
164 case V4L2_CID_CONTRAST:
165 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
166 strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
167 ctrl->minimum = 0;
168 ctrl->maximum = 127;
169 ctrl->step = 1;
170 ctrl->default_value = 71;
171 ctrl->flags = 0;
172 break;
173 case V4L2_CID_SATURATION:
174 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
175 strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
176 ctrl->minimum = 0;
177 ctrl->maximum = 127;
178 ctrl->step = 1;
179 ctrl->default_value = 64;
180 ctrl->flags = 0;
181 break;
182 case V4L2_CID_HUE:
183 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
184 strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
185 ctrl->minimum = -128;
186 ctrl->maximum = 127;
187 ctrl->step = 1;
188 ctrl->default_value = 0;
189 ctrl->flags = 0;
190 break;
191 }
192 break;
193 }
194 case VIDIOC_S_CTRL:
195 {
196 struct v4l2_control *ctrl = arg;
197
198 switch (ctrl->id) {
199 case V4L2_CID_BRIGHTNESS:
200 if (ctrl->value > 255)
201 dec->brightness = 255;
202 else if (ctrl->value < 0)
203 dec->brightness = 0;
204 else
205 dec->brightness = ctrl->value;
206 write_reg(client, 0x0a, dec->brightness);
207 break;
208 case V4L2_CID_CONTRAST:
209 if (ctrl->value > 127)
210 dec->contrast = 127;
211 else if (ctrl->value < 0)
212 dec->contrast = 0;
213 else
214 dec->contrast = ctrl->value;
215 write_reg(client, 0x0b, dec->contrast);
216 break;
217 case V4L2_CID_SATURATION:
218 if (ctrl->value > 127)
219 dec->saturation = 127;
220 else if (ctrl->value < 0)
221 dec->saturation = 0;
222 else
223 dec->saturation = ctrl->value;
224 write_reg(client, 0x0c, dec->saturation);
225 break;
226 case V4L2_CID_HUE:
227 if (ctrl->value > 127)
228 dec->hue = 127;
229 else if (ctrl->value < -128)
230 dec->hue = -128;
231 else
232 dec->hue = ctrl->value;
233 write_reg(client, 0x0d, dec->hue);
234 break;
235 }
236 break;
237 }
238 case VIDIOC_G_CTRL:
239 {
240 struct v4l2_control *ctrl = arg;
241
242 switch (ctrl->id) {
243 case V4L2_CID_BRIGHTNESS:
244 ctrl->value = dec->brightness;
245 break;
246 case V4L2_CID_CONTRAST:
247 ctrl->value = dec->contrast;
248 break;
249 case V4L2_CID_SATURATION:
250 ctrl->value = dec->saturation;
251 break;
252 case V4L2_CID_HUE:
253 ctrl->value = dec->hue;
254 break;
255 }
256 break;
257 }
258 default:
259 break;
260 }
261 return 0;
262}
263
264static int wis_saa7113_probe(struct i2c_client *client,
265 const struct i2c_device_id *id)
266{
267 struct i2c_adapter *adapter = client->adapter;
268 struct wis_saa7113 *dec;
269
270 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
271 return -ENODEV;
272
273 dec = kmalloc(sizeof(struct wis_saa7113), GFP_KERNEL);
274 if (dec == NULL)
275 return -ENOMEM;
276
277 dec->norm = V4L2_STD_NTSC;
278 dec->brightness = 128;
279 dec->contrast = 71;
280 dec->saturation = 64;
281 dec->hue = 0;
282 i2c_set_clientdata(client, dec);
283
284 dev_dbg(&client->dev,
285 "wis-saa7113: initializing SAA7113 at address %d on %s\n",
286 client->addr, adapter->name);
287
288 if (write_regs(client, initial_registers) < 0) {
289 dev_err(&client->dev,
290 "wis-saa7113: error initializing SAA7113\n");
291 kfree(dec);
292 return -ENODEV;
293 }
294
295 return 0;
296}
297
298static int wis_saa7113_remove(struct i2c_client *client)
299{
300 struct wis_saa7113 *dec = i2c_get_clientdata(client);
301
302 kfree(dec);
303 return 0;
304}
305
306static const struct i2c_device_id wis_saa7113_id[] = {
307 { "wis_saa7113", 0 },
308 { }
309};
310MODULE_DEVICE_TABLE(i2c, wis_saa7113_id);
311
312static struct i2c_driver wis_saa7113_driver = {
313 .driver = {
314 .name = "WIS SAA7113 I2C driver",
315 },
316 .probe = wis_saa7113_probe,
317 .remove = wis_saa7113_remove,
318 .command = wis_saa7113_command,
319 .id_table = wis_saa7113_id,
320};
321
322module_i2c_driver(wis_saa7113_driver);
323
324MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/go7007/wis-saa7115.c b/drivers/staging/media/go7007/wis-saa7115.c
deleted file mode 100644
index fa86acd3fdf0..000000000000
--- a/drivers/staging/media/go7007/wis-saa7115.c
+++ /dev/null
@@ -1,457 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24
25#include "wis-i2c.h"
26
27struct wis_saa7115 {
28 int norm;
29 int brightness;
30 int contrast;
31 int saturation;
32 int hue;
33};
34
35static u8 initial_registers[] = {
36 0x01, 0x08,
37 0x02, 0xc0,
38 0x03, 0x20,
39 0x04, 0x80,
40 0x05, 0x80,
41 0x06, 0xeb,
42 0x07, 0xe0,
43 0x08, 0xf0, /* always toggle FID */
44 0x09, 0x40,
45 0x0a, 0x80,
46 0x0b, 0x40,
47 0x0c, 0x40,
48 0x0d, 0x00,
49 0x0e, 0x03,
50 0x0f, 0x2a,
51 0x10, 0x0e,
52 0x11, 0x00,
53 0x12, 0x8d,
54 0x13, 0x00,
55 0x14, 0x00,
56 0x15, 0x11,
57 0x16, 0x01,
58 0x17, 0xda,
59 0x18, 0x40,
60 0x19, 0x80,
61 0x1a, 0x00,
62 0x1b, 0x42,
63 0x1c, 0xa9,
64 0x30, 0x66,
65 0x31, 0x90,
66 0x32, 0x01,
67 0x34, 0x00,
68 0x35, 0x00,
69 0x36, 0x20,
70 0x38, 0x03,
71 0x39, 0x20,
72 0x3a, 0x88,
73 0x40, 0x00,
74 0x41, 0xff,
75 0x42, 0xff,
76 0x43, 0xff,
77 0x44, 0xff,
78 0x45, 0xff,
79 0x46, 0xff,
80 0x47, 0xff,
81 0x48, 0xff,
82 0x49, 0xff,
83 0x4a, 0xff,
84 0x4b, 0xff,
85 0x4c, 0xff,
86 0x4d, 0xff,
87 0x4e, 0xff,
88 0x4f, 0xff,
89 0x50, 0xff,
90 0x51, 0xff,
91 0x52, 0xff,
92 0x53, 0xff,
93 0x54, 0xf4 /*0xff*/,
94 0x55, 0xff,
95 0x56, 0xff,
96 0x57, 0xff,
97 0x58, 0x40,
98 0x59, 0x47,
99 0x5a, 0x06 /*0x03*/,
100 0x5b, 0x83,
101 0x5d, 0x06,
102 0x5e, 0x00,
103 0x80, 0x30, /* window defined scaler operation, task A and B enabled */
104 0x81, 0x03, /* use scaler datapath generated V */
105 0x83, 0x00,
106 0x84, 0x00,
107 0x85, 0x00,
108 0x86, 0x45,
109 0x87, 0x31,
110 0x88, 0xc0,
111 0x90, 0x02, /* task A process top field */
112 0x91, 0x08,
113 0x92, 0x09,
114 0x93, 0x80,
115 0x94, 0x06,
116 0x95, 0x00,
117 0x96, 0xc0,
118 0x97, 0x02,
119 0x98, 0x12,
120 0x99, 0x00,
121 0x9a, 0xf2,
122 0x9b, 0x00,
123 0x9c, 0xd0,
124 0x9d, 0x02,
125 0x9e, 0xf2,
126 0x9f, 0x00,
127 0xa0, 0x01,
128 0xa1, 0x01,
129 0xa2, 0x01,
130 0xa4, 0x80,
131 0xa5, 0x40,
132 0xa6, 0x40,
133 0xa8, 0x00,
134 0xa9, 0x04,
135 0xaa, 0x00,
136 0xac, 0x00,
137 0xad, 0x02,
138 0xae, 0x00,
139 0xb0, 0x00,
140 0xb1, 0x04,
141 0xb2, 0x00,
142 0xb3, 0x04,
143 0xb4, 0x00,
144 0xb8, 0x00,
145 0xbc, 0x00,
146 0xc0, 0x03, /* task B process bottom field */
147 0xc1, 0x08,
148 0xc2, 0x09,
149 0xc3, 0x80,
150 0xc4, 0x06,
151 0xc5, 0x00,
152 0xc6, 0xc0,
153 0xc7, 0x02,
154 0xc8, 0x12,
155 0xc9, 0x00,
156 0xca, 0xf2,
157 0xcb, 0x00,
158 0xcc, 0xd0,
159 0xcd, 0x02,
160 0xce, 0xf2,
161 0xcf, 0x00,
162 0xd0, 0x01,
163 0xd1, 0x01,
164 0xd2, 0x01,
165 0xd4, 0x80,
166 0xd5, 0x40,
167 0xd6, 0x40,
168 0xd8, 0x00,
169 0xd9, 0x04,
170 0xda, 0x00,
171 0xdc, 0x00,
172 0xdd, 0x02,
173 0xde, 0x00,
174 0xe0, 0x00,
175 0xe1, 0x04,
176 0xe2, 0x00,
177 0xe3, 0x04,
178 0xe4, 0x00,
179 0xe8, 0x00,
180 0x88, 0xf0, /* End of original static list */
181 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
182};
183
184static int write_reg(struct i2c_client *client, u8 reg, u8 value)
185{
186 return i2c_smbus_write_byte_data(client, reg, value);
187}
188
189static int write_regs(struct i2c_client *client, u8 *regs)
190{
191 int i;
192
193 for (i = 0; regs[i] != 0x00; i += 2)
194 if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
195 return -1;
196 return 0;
197}
198
199static int wis_saa7115_command(struct i2c_client *client,
200 unsigned int cmd, void *arg)
201{
202 struct wis_saa7115 *dec = i2c_get_clientdata(client);
203
204 switch (cmd) {
205 case VIDIOC_S_INPUT:
206 {
207 int *input = arg;
208
209 i2c_smbus_write_byte_data(client, 0x02, 0xC0 | *input);
210 i2c_smbus_write_byte_data(client, 0x09,
211 *input < 6 ? 0x40 : 0xC0);
212 break;
213 }
214 case DECODER_SET_RESOLUTION:
215 {
216 struct video_decoder_resolution *res = arg;
217 /* Course-grained scaler */
218 int h_integer_scaler = res->width < 704 ? 704 / res->width : 1;
219 /* Fine-grained scaler to take care of remainder */
220 int h_scaling_increment = (704 / h_integer_scaler) *
221 1024 / res->width;
222 /* Fine-grained scaler only */
223 int v_scaling_increment = (dec->norm & V4L2_STD_NTSC ?
224 240 : 288) * 1024 / res->height;
225 u8 regs[] = {
226 0x88, 0xc0,
227 0x9c, res->width & 0xff,
228 0x9d, res->width >> 8,
229 0x9e, res->height & 0xff,
230 0x9f, res->height >> 8,
231 0xa0, h_integer_scaler,
232 0xa1, 1,
233 0xa2, 1,
234 0xa8, h_scaling_increment & 0xff,
235 0xa9, h_scaling_increment >> 8,
236 0xac, (h_scaling_increment / 2) & 0xff,
237 0xad, (h_scaling_increment / 2) >> 8,
238 0xb0, v_scaling_increment & 0xff,
239 0xb1, v_scaling_increment >> 8,
240 0xb2, v_scaling_increment & 0xff,
241 0xb3, v_scaling_increment >> 8,
242 0xcc, res->width & 0xff,
243 0xcd, res->width >> 8,
244 0xce, res->height & 0xff,
245 0xcf, res->height >> 8,
246 0xd0, h_integer_scaler,
247 0xd1, 1,
248 0xd2, 1,
249 0xd8, h_scaling_increment & 0xff,
250 0xd9, h_scaling_increment >> 8,
251 0xdc, (h_scaling_increment / 2) & 0xff,
252 0xdd, (h_scaling_increment / 2) >> 8,
253 0xe0, v_scaling_increment & 0xff,
254 0xe1, v_scaling_increment >> 8,
255 0xe2, v_scaling_increment & 0xff,
256 0xe3, v_scaling_increment >> 8,
257 0x88, 0xf0,
258 0, 0,
259 };
260 write_regs(client, regs);
261 break;
262 }
263 case VIDIOC_S_STD:
264 {
265 v4l2_std_id *input = arg;
266 u8 regs[] = {
267 0x88, 0xc0,
268 0x98, *input & V4L2_STD_NTSC ? 0x12 : 0x16,
269 0x9a, *input & V4L2_STD_NTSC ? 0xf2 : 0x20,
270 0x9b, *input & V4L2_STD_NTSC ? 0x00 : 0x01,
271 0xc8, *input & V4L2_STD_NTSC ? 0x12 : 0x16,
272 0xca, *input & V4L2_STD_NTSC ? 0xf2 : 0x20,
273 0xcb, *input & V4L2_STD_NTSC ? 0x00 : 0x01,
274 0x88, 0xf0,
275 0x30, *input & V4L2_STD_NTSC ? 0x66 : 0x00,
276 0x31, *input & V4L2_STD_NTSC ? 0x90 : 0xe0,
277 0, 0,
278 };
279 write_regs(client, regs);
280 dec->norm = *input;
281 break;
282 }
283 case VIDIOC_QUERYCTRL:
284 {
285 struct v4l2_queryctrl *ctrl = arg;
286
287 switch (ctrl->id) {
288 case V4L2_CID_BRIGHTNESS:
289 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
290 strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
291 ctrl->minimum = 0;
292 ctrl->maximum = 255;
293 ctrl->step = 1;
294 ctrl->default_value = 128;
295 ctrl->flags = 0;
296 break;
297 case V4L2_CID_CONTRAST:
298 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
299 strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
300 ctrl->minimum = 0;
301 ctrl->maximum = 127;
302 ctrl->step = 1;
303 ctrl->default_value = 64;
304 ctrl->flags = 0;
305 break;
306 case V4L2_CID_SATURATION:
307 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
308 strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
309 ctrl->minimum = 0;
310 ctrl->maximum = 127;
311 ctrl->step = 1;
312 ctrl->default_value = 64;
313 ctrl->flags = 0;
314 break;
315 case V4L2_CID_HUE:
316 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
317 strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
318 ctrl->minimum = -128;
319 ctrl->maximum = 127;
320 ctrl->step = 1;
321 ctrl->default_value = 0;
322 ctrl->flags = 0;
323 break;
324 }
325 break;
326 }
327 case VIDIOC_S_CTRL:
328 {
329 struct v4l2_control *ctrl = arg;
330
331 switch (ctrl->id) {
332 case V4L2_CID_BRIGHTNESS:
333 if (ctrl->value > 255)
334 dec->brightness = 255;
335 else if (ctrl->value < 0)
336 dec->brightness = 0;
337 else
338 dec->brightness = ctrl->value;
339 write_reg(client, 0x0a, dec->brightness);
340 break;
341 case V4L2_CID_CONTRAST:
342 if (ctrl->value > 127)
343 dec->contrast = 127;
344 else if (ctrl->value < 0)
345 dec->contrast = 0;
346 else
347 dec->contrast = ctrl->value;
348 write_reg(client, 0x0b, dec->contrast);
349 break;
350 case V4L2_CID_SATURATION:
351 if (ctrl->value > 127)
352 dec->saturation = 127;
353 else if (ctrl->value < 0)
354 dec->saturation = 0;
355 else
356 dec->saturation = ctrl->value;
357 write_reg(client, 0x0c, dec->saturation);
358 break;
359 case V4L2_CID_HUE:
360 if (ctrl->value > 127)
361 dec->hue = 127;
362 else if (ctrl->value < -128)
363 dec->hue = -128;
364 else
365 dec->hue = ctrl->value;
366 write_reg(client, 0x0d, dec->hue);
367 break;
368 }
369 break;
370 }
371 case VIDIOC_G_CTRL:
372 {
373 struct v4l2_control *ctrl = arg;
374
375 switch (ctrl->id) {
376 case V4L2_CID_BRIGHTNESS:
377 ctrl->value = dec->brightness;
378 break;
379 case V4L2_CID_CONTRAST:
380 ctrl->value = dec->contrast;
381 break;
382 case V4L2_CID_SATURATION:
383 ctrl->value = dec->saturation;
384 break;
385 case V4L2_CID_HUE:
386 ctrl->value = dec->hue;
387 break;
388 }
389 break;
390 }
391 default:
392 break;
393 }
394 return 0;
395}
396
397static int wis_saa7115_probe(struct i2c_client *client,
398 const struct i2c_device_id *id)
399{
400 struct i2c_adapter *adapter = client->adapter;
401 struct wis_saa7115 *dec;
402
403 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
404 return -ENODEV;
405
406 dec = kmalloc(sizeof(struct wis_saa7115), GFP_KERNEL);
407 if (dec == NULL)
408 return -ENOMEM;
409
410 dec->norm = V4L2_STD_NTSC;
411 dec->brightness = 128;
412 dec->contrast = 64;
413 dec->saturation = 64;
414 dec->hue = 0;
415 i2c_set_clientdata(client, dec);
416
417 dev_dbg(&client->dev,
418 "wis-saa7115: initializing SAA7115 at address %d on %s\n",
419 client->addr, adapter->name);
420
421 if (write_regs(client, initial_registers) < 0) {
422 dev_err(&client->dev,
423 "wis-saa7115: error initializing SAA7115\n");
424 kfree(dec);
425 return -ENODEV;
426 }
427
428 return 0;
429}
430
431static int wis_saa7115_remove(struct i2c_client *client)
432{
433 struct wis_saa7115 *dec = i2c_get_clientdata(client);
434
435 kfree(dec);
436 return 0;
437}
438
439static const struct i2c_device_id wis_saa7115_id[] = {
440 { "wis_saa7115", 0 },
441 { }
442};
443MODULE_DEVICE_TABLE(i2c, wis_saa7115_id);
444
445static struct i2c_driver wis_saa7115_driver = {
446 .driver = {
447 .name = "WIS SAA7115 I2C driver",
448 },
449 .probe = wis_saa7115_probe,
450 .remove = wis_saa7115_remove,
451 .command = wis_saa7115_command,
452 .id_table = wis_saa7115_id,
453};
454
455module_i2c_driver(wis_saa7115_driver);
456
457MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/go7007/wis-sony-tuner.c b/drivers/staging/media/go7007/wis-sony-tuner.c
deleted file mode 100644
index 5d7ff8c81d6d..000000000000
--- a/drivers/staging/media/go7007/wis-sony-tuner.c
+++ /dev/null
@@ -1,707 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/slab.h>
23#include <media/tuner.h>
24#include <media/v4l2-common.h>
25#include <media/v4l2-ioctl.h>
26
27#include "wis-i2c.h"
28
29/* #define MPX_DEBUG */
30
31/* AS(IF/MPX) pin: LOW HIGH/OPEN
32 * IF/MPX address: 0x42/0x40 0x43/0x44
33 */
34#define IF_I2C_ADDR 0x43
35#define MPX_I2C_ADDR 0x44
36
37static v4l2_std_id force_band;
38static char force_band_str[] = "-";
39module_param_string(force_band, force_band_str, sizeof(force_band_str), 0644);
40static int force_mpx_mode = -1;
41module_param(force_mpx_mode, int, 0644);
42
43/* Store tuner info in the same format as tuner.c, so maybe we can put the
44 * Sony tuner support in there. */
45struct sony_tunertype {
46 char *name;
47 unsigned char Vendor; /* unused here */
48 unsigned char Type; /* unused here */
49
50 unsigned short thresh1; /* band switch VHF_LO <=> VHF_HI */
51 unsigned short thresh2; /* band switch VHF_HI <=> UHF */
52 unsigned char VHF_L;
53 unsigned char VHF_H;
54 unsigned char UHF;
55 unsigned char config;
56 unsigned short IFPCoff;
57};
58
59/* This array is indexed by (tuner_type - 200) */
60static struct sony_tunertype sony_tuners[] = {
61 { "Sony PAL+SECAM (BTF-PG472Z)", 0, 0,
62 16*144.25, 16*427.25, 0x01, 0x02, 0x04, 0xc6, 623},
63 { "Sony NTSC_JP (BTF-PK467Z)", 0, 0,
64 16*220.25, 16*467.25, 0x01, 0x02, 0x04, 0xc6, 940},
65 { "Sony NTSC (BTF-PB463Z)", 0, 0,
66 16*130.25, 16*364.25, 0x01, 0x02, 0x04, 0xc6, 732},
67};
68
69struct wis_sony_tuner {
70 int type;
71 v4l2_std_id std;
72 unsigned int freq;
73 int mpxmode;
74 u32 audmode;
75};
76
77/* Basically the same as default_set_tv_freq() in tuner.c */
78static int set_freq(struct i2c_client *client, int freq)
79{
80 struct wis_sony_tuner *t = i2c_get_clientdata(client);
81 char *band_name;
82 int n;
83 int band_select;
84 struct sony_tunertype *tun;
85 u8 buffer[4];
86
87 tun = &sony_tuners[t->type - 200];
88 if (freq < tun->thresh1) {
89 band_name = "VHF_L";
90 band_select = tun->VHF_L;
91 } else if (freq < tun->thresh2) {
92 band_name = "VHF_H";
93 band_select = tun->VHF_H;
94 } else {
95 band_name = "UHF";
96 band_select = tun->UHF;
97 }
98 dev_dbg(&client->dev, "tuning to frequency %d.%04d (%s)\n",
99 freq / 16, (freq % 16) * 625, band_name);
100 n = freq + tun->IFPCoff;
101
102 buffer[0] = n >> 8;
103 buffer[1] = n & 0xff;
104 buffer[2] = tun->config;
105 buffer[3] = band_select;
106 i2c_master_send(client, buffer, 4);
107
108 return 0;
109}
110
111static int mpx_write(struct i2c_client *client, int dev, int addr, int val)
112{
113 u8 buffer[5];
114 struct i2c_msg msg;
115
116 buffer[0] = dev;
117 buffer[1] = addr >> 8;
118 buffer[2] = addr & 0xff;
119 buffer[3] = val >> 8;
120 buffer[4] = val & 0xff;
121 msg.addr = MPX_I2C_ADDR;
122 msg.flags = 0;
123 msg.len = 5;
124 msg.buf = buffer;
125 i2c_transfer(client->adapter, &msg, 1);
126 return 0;
127}
128
129/*
130 * MPX register values for the BTF-PG472Z:
131 *
132 * FM_ NICAM_ SCART_
133 * MODUS SOURCE ACB PRESCAL PRESCAL PRESCAL SYSTEM VOLUME
134 * 10/0030 12/0008 12/0013 12/000E 12/0010 12/0000 10/0020 12/0000
135 * ---------------------------------------------------------------
136 * Auto 1003 0020 0100 2603 5000 XXXX 0001 7500
137 *
138 * B/G
139 * Mono 1003 0020 0100 2603 5000 XXXX 0003 7500
140 * A2 1003 0020 0100 2601 5000 XXXX 0003 7500
141 * NICAM 1003 0120 0100 2603 5000 XXXX 0008 7500
142 *
143 * I
144 * Mono 1003 0020 0100 2603 7900 XXXX 000A 7500
145 * NICAM 1003 0120 0100 2603 7900 XXXX 000A 7500
146 *
147 * D/K
148 * Mono 1003 0020 0100 2603 5000 XXXX 0004 7500
149 * A2-1 1003 0020 0100 2601 5000 XXXX 0004 7500
150 * A2-2 1003 0020 0100 2601 5000 XXXX 0005 7500
151 * A2-3 1003 0020 0100 2601 5000 XXXX 0007 7500
152 * NICAM 1003 0120 0100 2603 5000 XXXX 000B 7500
153 *
154 * L/L'
155 * Mono 0003 0200 0100 7C03 5000 2200 0009 7500
156 * NICAM 0003 0120 0100 7C03 5000 XXXX 0009 7500
157 *
158 * M
159 * Mono 1003 0200 0100 2B03 5000 2B00 0002 7500
160 *
161 * For Asia, replace the 0x26XX in FM_PRESCALE with 0x14XX.
162 *
163 * Bilingual selection in A2/NICAM:
164 *
165 * High byte of SOURCE Left chan Right chan
166 * 0x01 MAIN SUB
167 * 0x03 MAIN MAIN
168 * 0x04 SUB SUB
169 *
170 * Force mono in NICAM by setting the high byte of SOURCE to 0x02 (L/L') or
171 * 0x00 (all other bands). Force mono in A2 with FMONO_A2:
172 *
173 * FMONO_A2
174 * 10/0022
175 * --------
176 * Forced mono ON 07F0
177 * Forced mono OFF 0190
178 */
179
180static struct {
181 enum { AUD_MONO, AUD_A2, AUD_NICAM, AUD_NICAM_L } audio_mode;
182 u16 modus;
183 u16 source;
184 u16 acb;
185 u16 fm_prescale;
186 u16 nicam_prescale;
187 u16 scart_prescale;
188 u16 system;
189 u16 volume;
190} mpx_audio_modes[] = {
191 /* Auto */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
192 0x5000, 0x0000, 0x0001, 0x7500 },
193 /* B/G Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
194 0x5000, 0x0000, 0x0003, 0x7500 },
195 /* B/G A2 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
196 0x5000, 0x0000, 0x0003, 0x7500 },
197 /* B/G NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
198 0x5000, 0x0000, 0x0008, 0x7500 },
199 /* I Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
200 0x7900, 0x0000, 0x000A, 0x7500 },
201 /* I NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
202 0x7900, 0x0000, 0x000A, 0x7500 },
203 /* D/K Mono */ { AUD_MONO, 0x1003, 0x0020, 0x0100, 0x2603,
204 0x5000, 0x0000, 0x0004, 0x7500 },
205 /* D/K A2-1 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
206 0x5000, 0x0000, 0x0004, 0x7500 },
207 /* D/K A2-2 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
208 0x5000, 0x0000, 0x0005, 0x7500 },
209 /* D/K A2-3 */ { AUD_A2, 0x1003, 0x0020, 0x0100, 0x2601,
210 0x5000, 0x0000, 0x0007, 0x7500 },
211 /* D/K NICAM */ { AUD_NICAM, 0x1003, 0x0120, 0x0100, 0x2603,
212 0x5000, 0x0000, 0x000B, 0x7500 },
213 /* L/L' Mono */ { AUD_MONO, 0x0003, 0x0200, 0x0100, 0x7C03,
214 0x5000, 0x2200, 0x0009, 0x7500 },
215 /* L/L' NICAM */{ AUD_NICAM_L, 0x0003, 0x0120, 0x0100, 0x7C03,
216 0x5000, 0x0000, 0x0009, 0x7500 },
217};
218
219#define MPX_NUM_MODES ARRAY_SIZE(mpx_audio_modes)
220
221static int mpx_setup(struct i2c_client *client)
222{
223 struct wis_sony_tuner *t = i2c_get_clientdata(client);
224 u16 source = 0;
225 u8 buffer[3];
226 struct i2c_msg msg;
227
228 /* reset MPX */
229 buffer[0] = 0x00;
230 buffer[1] = 0x80;
231 buffer[2] = 0x00;
232 msg.addr = MPX_I2C_ADDR;
233 msg.flags = 0;
234 msg.len = 3;
235 msg.buf = buffer;
236 i2c_transfer(client->adapter, &msg, 1);
237 buffer[1] = 0x00;
238 i2c_transfer(client->adapter, &msg, 1);
239
240 if (mpx_audio_modes[t->mpxmode].audio_mode != AUD_MONO) {
241 switch (t->audmode) {
242 case V4L2_TUNER_MODE_MONO:
243 switch (mpx_audio_modes[t->mpxmode].audio_mode) {
244 case AUD_A2:
245 source = mpx_audio_modes[t->mpxmode].source;
246 break;
247 case AUD_NICAM:
248 source = 0x0000;
249 break;
250 case AUD_NICAM_L:
251 source = 0x0200;
252 break;
253 default:
254 break;
255 }
256 break;
257 case V4L2_TUNER_MODE_STEREO:
258 source = mpx_audio_modes[t->mpxmode].source;
259 break;
260 case V4L2_TUNER_MODE_LANG1:
261 source = 0x0300;
262 break;
263 case V4L2_TUNER_MODE_LANG2:
264 source = 0x0400;
265 break;
266 }
267 source |= mpx_audio_modes[t->mpxmode].source & 0x00ff;
268 } else
269 source = mpx_audio_modes[t->mpxmode].source;
270
271 mpx_write(client, 0x10, 0x0030, mpx_audio_modes[t->mpxmode].modus);
272 mpx_write(client, 0x12, 0x0008, source);
273 mpx_write(client, 0x12, 0x0013, mpx_audio_modes[t->mpxmode].acb);
274 mpx_write(client, 0x12, 0x000e,
275 mpx_audio_modes[t->mpxmode].fm_prescale);
276 mpx_write(client, 0x12, 0x0010,
277 mpx_audio_modes[t->mpxmode].nicam_prescale);
278 mpx_write(client, 0x12, 0x000d,
279 mpx_audio_modes[t->mpxmode].scart_prescale);
280 mpx_write(client, 0x10, 0x0020, mpx_audio_modes[t->mpxmode].system);
281 mpx_write(client, 0x12, 0x0000, mpx_audio_modes[t->mpxmode].volume);
282 if (mpx_audio_modes[t->mpxmode].audio_mode == AUD_A2)
283 mpx_write(client, 0x10, 0x0022,
284 t->audmode == V4L2_TUNER_MODE_MONO ? 0x07f0 : 0x0190);
285
286#ifdef MPX_DEBUG
287 {
288 u8 buf1[3], buf2[2];
289 struct i2c_msg msgs[2];
290
291 dev_dbg(&client->dev,
292 "MPX registers: %04x %04x %04x %04x %04x %04x %04x %04x\n",
293 mpx_audio_modes[t->mpxmode].modus,
294 source,
295 mpx_audio_modes[t->mpxmode].acb,
296 mpx_audio_modes[t->mpxmode].fm_prescale,
297 mpx_audio_modes[t->mpxmode].nicam_prescale,
298 mpx_audio_modes[t->mpxmode].scart_prescale,
299 mpx_audio_modes[t->mpxmode].system,
300 mpx_audio_modes[t->mpxmode].volume);
301 buf1[0] = 0x11;
302 buf1[1] = 0x00;
303 buf1[2] = 0x7e;
304 msgs[0].addr = MPX_I2C_ADDR;
305 msgs[0].flags = 0;
306 msgs[0].len = 3;
307 msgs[0].buf = buf1;
308 msgs[1].addr = MPX_I2C_ADDR;
309 msgs[1].flags = I2C_M_RD;
310 msgs[1].len = 2;
311 msgs[1].buf = buf2;
312 i2c_transfer(client->adapter, msgs, 2);
313 dev_dbg(&client->dev, "MPX system: %02x%02x\n",
314 buf2[0], buf2[1]);
315 buf1[0] = 0x11;
316 buf1[1] = 0x02;
317 buf1[2] = 0x00;
318 i2c_transfer(client->adapter, msgs, 2);
319 dev_dbg(&client->dev, "MPX status: %02x%02x\n",
320 buf2[0], buf2[1]);
321 }
322#endif
323 return 0;
324}
325
326/*
327 * IF configuration values for the BTF-PG472Z:
328 *
329 * B/G: 0x94 0x70 0x49
330 * I: 0x14 0x70 0x4a
331 * D/K: 0x14 0x70 0x4b
332 * L: 0x04 0x70 0x4b
333 * L': 0x44 0x70 0x53
334 * M: 0x50 0x30 0x4c
335 */
336
337static int set_if(struct i2c_client *client)
338{
339 struct wis_sony_tuner *t = i2c_get_clientdata(client);
340 u8 buffer[4];
341 struct i2c_msg msg;
342 int default_mpx_mode = 0;
343
344 /* configure IF */
345 buffer[0] = 0;
346 if (t->std & V4L2_STD_PAL_BG) {
347 buffer[1] = 0x94;
348 buffer[2] = 0x70;
349 buffer[3] = 0x49;
350 default_mpx_mode = 1;
351 } else if (t->std & V4L2_STD_PAL_I) {
352 buffer[1] = 0x14;
353 buffer[2] = 0x70;
354 buffer[3] = 0x4a;
355 default_mpx_mode = 4;
356 } else if (t->std & V4L2_STD_PAL_DK) {
357 buffer[1] = 0x14;
358 buffer[2] = 0x70;
359 buffer[3] = 0x4b;
360 default_mpx_mode = 6;
361 } else if (t->std & V4L2_STD_SECAM_L) {
362 buffer[1] = 0x04;
363 buffer[2] = 0x70;
364 buffer[3] = 0x4b;
365 default_mpx_mode = 11;
366 }
367 msg.addr = IF_I2C_ADDR;
368 msg.flags = 0;
369 msg.len = 4;
370 msg.buf = buffer;
371 i2c_transfer(client->adapter, &msg, 1);
372
373 /* Select MPX mode if not forced by the user */
374 if (force_mpx_mode >= 0 && force_mpx_mode < MPX_NUM_MODES)
375 t->mpxmode = force_mpx_mode;
376 else
377 t->mpxmode = default_mpx_mode;
378 dev_dbg(&client->dev, "setting MPX to mode %d\n", t->mpxmode);
379 mpx_setup(client);
380
381 return 0;
382}
383
384static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
385{
386 struct wis_sony_tuner *t = i2c_get_clientdata(client);
387
388 switch (cmd) {
389#if 0
390#ifdef TUNER_SET_TYPE_ADDR
391 case TUNER_SET_TYPE_ADDR:
392 {
393 struct tuner_setup *tun_setup = arg;
394 int *type = &tun_setup->type;
395#else
396 case TUNER_SET_TYPE:
397 {
398 int *type = arg;
399#endif
400
401 if (t->type >= 0) {
402 if (t->type != *type)
403 dev_err(&client->dev,
404 "type already set to %d, ignoring request for %d\n",
405 t->type, *type);
406 break;
407 }
408 t->type = *type;
409 switch (t->type) {
410 case TUNER_SONY_BTF_PG472Z:
411 switch (force_band_str[0]) {
412 case 'b':
413 case 'B':
414 case 'g':
415 case 'G':
416 dev_info(&client->dev,
417 "forcing tuner to PAL-B/G bands\n");
418 force_band = V4L2_STD_PAL_BG;
419 break;
420 case 'i':
421 case 'I':
422 dev_info(&client->dev,
423 "forcing tuner to PAL-I band\n");
424 force_band = V4L2_STD_PAL_I;
425 break;
426 case 'd':
427 case 'D':
428 case 'k':
429 case 'K':
430 dev_info(&client->dev,
431 "forcing tuner to PAL-D/K bands\n");
432 force_band = V4L2_STD_PAL_I;
433 break;
434 case 'l':
435 case 'L':
436 dev_info(&client->dev,
437 "forcing tuner to SECAM-L band\n");
438 force_band = V4L2_STD_SECAM_L;
439 break;
440 default:
441 force_band = 0;
442 break;
443 }
444 if (force_band)
445 t->std = force_band;
446 else
447 t->std = V4L2_STD_PAL_BG;
448 set_if(client);
449 break;
450 case TUNER_SONY_BTF_PK467Z:
451 t->std = V4L2_STD_NTSC_M_JP;
452 break;
453 case TUNER_SONY_BTF_PB463Z:
454 t->std = V4L2_STD_NTSC_M;
455 break;
456 default:
457 dev_err(&client->dev,
458 "tuner type %d is not supported by this module\n",
459 *type);
460 break;
461 }
462 if (type >= 0)
463 dev_info(&clinet->dev,
464 "type set to %d (%s)\n",
465 t->type, sony_tuners[t->type - 200].name);
466 break;
467 }
468#endif
469 case VIDIOC_G_FREQUENCY:
470 {
471 struct v4l2_frequency *f = arg;
472
473 f->frequency = t->freq;
474 break;
475 }
476 case VIDIOC_S_FREQUENCY:
477 {
478 struct v4l2_frequency *f = arg;
479
480 t->freq = f->frequency;
481 set_freq(client, t->freq);
482 break;
483 }
484 case VIDIOC_ENUMSTD:
485 {
486 struct v4l2_standard *std = arg;
487
488 switch (t->type) {
489 case TUNER_SONY_BTF_PG472Z:
490 switch (std->index) {
491 case 0:
492 v4l2_video_std_construct(std,
493 V4L2_STD_PAL_BG, "PAL-B/G");
494 break;
495 case 1:
496 v4l2_video_std_construct(std,
497 V4L2_STD_PAL_I, "PAL-I");
498 break;
499 case 2:
500 v4l2_video_std_construct(std,
501 V4L2_STD_PAL_DK, "PAL-D/K");
502 break;
503 case 3:
504 v4l2_video_std_construct(std,
505 V4L2_STD_SECAM_L, "SECAM-L");
506 break;
507 default:
508 std->id = 0; /* hack to indicate EINVAL */
509 break;
510 }
511 break;
512 case TUNER_SONY_BTF_PK467Z:
513 if (std->index != 0) {
514 std->id = 0; /* hack to indicate EINVAL */
515 break;
516 }
517 v4l2_video_std_construct(std,
518 V4L2_STD_NTSC_M_JP, "NTSC-J");
519 break;
520 case TUNER_SONY_BTF_PB463Z:
521 if (std->index != 0) {
522 std->id = 0; /* hack to indicate EINVAL */
523 break;
524 }
525 v4l2_video_std_construct(std, V4L2_STD_NTSC_M, "NTSC");
526 break;
527 }
528 break;
529 }
530 case VIDIOC_G_STD:
531 {
532 v4l2_std_id *std = arg;
533
534 *std = t->std;
535 break;
536 }
537 case VIDIOC_S_STD:
538 {
539 v4l2_std_id *std = arg;
540 v4l2_std_id old = t->std;
541
542 switch (t->type) {
543 case TUNER_SONY_BTF_PG472Z:
544 if (force_band && (*std & force_band) != *std &&
545 *std != V4L2_STD_PAL &&
546 *std != V4L2_STD_SECAM) {
547 dev_dbg(&client->dev,
548 "ignoring requested TV standard in favor of force_band value\n");
549 t->std = force_band;
550 } else if (*std & V4L2_STD_PAL_BG) { /* default */
551 t->std = V4L2_STD_PAL_BG;
552 } else if (*std & V4L2_STD_PAL_I) {
553 t->std = V4L2_STD_PAL_I;
554 } else if (*std & V4L2_STD_PAL_DK) {
555 t->std = V4L2_STD_PAL_DK;
556 } else if (*std & V4L2_STD_SECAM_L) {
557 t->std = V4L2_STD_SECAM_L;
558 } else {
559 dev_err(&client->dev,
560 "TV standard not supported\n");
561 *std = 0; /* hack to indicate EINVAL */
562 break;
563 }
564 if (old != t->std)
565 set_if(client);
566 break;
567 case TUNER_SONY_BTF_PK467Z:
568 if (!(*std & V4L2_STD_NTSC_M_JP)) {
569 dev_err(&client->dev,
570 "TV standard not supported\n");
571 *std = 0; /* hack to indicate EINVAL */
572 }
573 break;
574 case TUNER_SONY_BTF_PB463Z:
575 if (!(*std & V4L2_STD_NTSC_M)) {
576 dev_err(&client->dev,
577 "TV standard not supported\n");
578 *std = 0; /* hack to indicate EINVAL */
579 }
580 break;
581 }
582 break;
583 }
584 case VIDIOC_QUERYSTD:
585 {
586 v4l2_std_id *std = arg;
587
588 switch (t->type) {
589 case TUNER_SONY_BTF_PG472Z:
590 if (force_band)
591 *std = force_band;
592 else
593 *std = V4L2_STD_PAL_BG | V4L2_STD_PAL_I |
594 V4L2_STD_PAL_DK | V4L2_STD_SECAM_L;
595 break;
596 case TUNER_SONY_BTF_PK467Z:
597 *std = V4L2_STD_NTSC_M_JP;
598 break;
599 case TUNER_SONY_BTF_PB463Z:
600 *std = V4L2_STD_NTSC_M;
601 break;
602 }
603 break;
604 }
605 case VIDIOC_G_TUNER:
606 {
607 struct v4l2_tuner *tun = arg;
608
609 memset(tun, 0, sizeof(*tun));
610 strcpy(tun->name, "Television");
611 tun->type = V4L2_TUNER_ANALOG_TV;
612 tun->rangelow = 0UL; /* does anything use these? */
613 tun->rangehigh = 0xffffffffUL;
614 switch (t->type) {
615 case TUNER_SONY_BTF_PG472Z:
616 tun->capability = V4L2_TUNER_CAP_NORM |
617 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
618 V4L2_TUNER_CAP_LANG2;
619 tun->rxsubchans = V4L2_TUNER_SUB_MONO |
620 V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_LANG1 |
621 V4L2_TUNER_SUB_LANG2;
622 break;
623 case TUNER_SONY_BTF_PK467Z:
624 case TUNER_SONY_BTF_PB463Z:
625 tun->capability = V4L2_TUNER_CAP_STEREO;
626 tun->rxsubchans = V4L2_TUNER_SUB_MONO |
627 V4L2_TUNER_SUB_STEREO;
628 break;
629 }
630 tun->audmode = t->audmode;
631 return 0;
632 }
633 case VIDIOC_S_TUNER:
634 {
635 struct v4l2_tuner *tun = arg;
636
637 switch (t->type) {
638 case TUNER_SONY_BTF_PG472Z:
639 if (tun->audmode != t->audmode) {
640 t->audmode = tun->audmode;
641 mpx_setup(client);
642 }
643 break;
644 case TUNER_SONY_BTF_PK467Z:
645 case TUNER_SONY_BTF_PB463Z:
646 break;
647 }
648 return 0;
649 }
650 default:
651 break;
652 }
653 return 0;
654}
655
656static int wis_sony_tuner_probe(struct i2c_client *client,
657 const struct i2c_device_id *id)
658{
659 struct i2c_adapter *adapter = client->adapter;
660 struct wis_sony_tuner *t;
661
662 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
663 return -ENODEV;
664
665 t = kmalloc(sizeof(struct wis_sony_tuner), GFP_KERNEL);
666 if (t == NULL)
667 return -ENOMEM;
668
669 t->type = -1;
670 t->freq = 0;
671 t->mpxmode = 0;
672 t->audmode = V4L2_TUNER_MODE_STEREO;
673 i2c_set_clientdata(client, t);
674
675 dev_dbg(&client->dev, "initializing tuner at address %d on %s\n",
676 client->addr, adapter->name);
677
678 return 0;
679}
680
681static int wis_sony_tuner_remove(struct i2c_client *client)
682{
683 struct wis_sony_tuner *t = i2c_get_clientdata(client);
684
685 kfree(t);
686 return 0;
687}
688
689static const struct i2c_device_id wis_sony_tuner_id[] = {
690 { "wis_sony_tuner", 0 },
691 { }
692};
693MODULE_DEVICE_TABLE(i2c, wis_sony_tuner_id);
694
695static struct i2c_driver wis_sony_tuner_driver = {
696 .driver = {
697 .name = "WIS Sony TV Tuner I2C driver",
698 },
699 .probe = wis_sony_tuner_probe,
700 .remove = wis_sony_tuner_remove,
701 .command = tuner_command,
702 .id_table = wis_sony_tuner_id,
703};
704
705module_i2c_driver(wis_sony_tuner_driver);
706
707MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/go7007/wis-tw2804.c b/drivers/staging/media/go7007/wis-tw2804.c
deleted file mode 100644
index 290fd8c7bfef..000000000000
--- a/drivers/staging/media/go7007/wis-tw2804.c
+++ /dev/null
@@ -1,348 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24
25#include "wis-i2c.h"
26
27struct wis_tw2804 {
28 int channel;
29 int norm;
30 int brightness;
31 int contrast;
32 int saturation;
33 int hue;
34};
35
36static u8 global_registers[] = {
37 0x39, 0x00,
38 0x3a, 0xff,
39 0x3b, 0x84,
40 0x3c, 0x80,
41 0x3d, 0x80,
42 0x3e, 0x82,
43 0x3f, 0x82,
44 0xff, 0xff, /* Terminator (reg 0xff does not exist) */
45};
46
47static u8 channel_registers[] = {
48 0x01, 0xc4,
49 0x02, 0xa5,
50 0x03, 0x20,
51 0x04, 0xd0,
52 0x05, 0x20,
53 0x06, 0xd0,
54 0x07, 0x88,
55 0x08, 0x20,
56 0x09, 0x07,
57 0x0a, 0xf0,
58 0x0b, 0x07,
59 0x0c, 0xf0,
60 0x0d, 0x40,
61 0x0e, 0xd2,
62 0x0f, 0x80,
63 0x10, 0x80,
64 0x11, 0x80,
65 0x12, 0x80,
66 0x13, 0x1f,
67 0x14, 0x00,
68 0x15, 0x00,
69 0x16, 0x00,
70 0x17, 0x00,
71 0x18, 0xff,
72 0x19, 0xff,
73 0x1a, 0xff,
74 0x1b, 0xff,
75 0x1c, 0xff,
76 0x1d, 0xff,
77 0x1e, 0xff,
78 0x1f, 0xff,
79 0x20, 0x07,
80 0x21, 0x07,
81 0x22, 0x00,
82 0x23, 0x91,
83 0x24, 0x51,
84 0x25, 0x03,
85 0x26, 0x00,
86 0x27, 0x00,
87 0x28, 0x00,
88 0x29, 0x00,
89 0x2a, 0x00,
90 0x2b, 0x00,
91 0x2c, 0x00,
92 0x2d, 0x00,
93 0x2e, 0x00,
94 0x2f, 0x00,
95 0x30, 0x00,
96 0x31, 0x00,
97 0x32, 0x00,
98 0x33, 0x00,
99 0x34, 0x00,
100 0x35, 0x00,
101 0x36, 0x00,
102 0x37, 0x00,
103 0xff, 0xff, /* Terminator (reg 0xff does not exist) */
104};
105
106static int write_reg(struct i2c_client *client, u8 reg, u8 value, int channel)
107{
108 return i2c_smbus_write_byte_data(client, reg | (channel << 6), value);
109}
110
111static int write_regs(struct i2c_client *client, u8 *regs, int channel)
112{
113 int i;
114
115 for (i = 0; regs[i] != 0xff; i += 2)
116 if (i2c_smbus_write_byte_data(client,
117 regs[i] | (channel << 6), regs[i + 1]) < 0)
118 return -1;
119 return 0;
120}
121
122static int wis_tw2804_command(struct i2c_client *client,
123 unsigned int cmd, void *arg)
124{
125 struct wis_tw2804 *dec = i2c_get_clientdata(client);
126
127 if (cmd == DECODER_SET_CHANNEL) {
128 int *input = arg;
129
130 if (*input < 0 || *input > 3) {
131 dev_err(&client->dev,
132 "channel %d is not between 0 and 3!\n", *input);
133 return 0;
134 }
135 dec->channel = *input;
136 dev_dbg(&client->dev, "initializing TW2804 channel %d\n",
137 dec->channel);
138 if (dec->channel == 0 &&
139 write_regs(client, global_registers, 0) < 0) {
140 dev_err(&client->dev,
141 "error initializing TW2804 global registers\n");
142 return 0;
143 }
144 if (write_regs(client, channel_registers, dec->channel) < 0) {
145 dev_err(&client->dev,
146 "error initializing TW2804 channel %d\n",
147 dec->channel);
148 return 0;
149 }
150 return 0;
151 }
152
153 if (dec->channel < 0) {
154 dev_dbg(&client->dev,
155 "ignoring command %08x until channel number is set\n",
156 cmd);
157 return 0;
158 }
159
160 switch (cmd) {
161 case VIDIOC_S_STD:
162 {
163 v4l2_std_id *input = arg;
164 u8 regs[] = {
165 0x01, *input & V4L2_STD_NTSC ? 0xc4 : 0x84,
166 0x09, *input & V4L2_STD_NTSC ? 0x07 : 0x04,
167 0x0a, *input & V4L2_STD_NTSC ? 0xf0 : 0x20,
168 0x0b, *input & V4L2_STD_NTSC ? 0x07 : 0x04,
169 0x0c, *input & V4L2_STD_NTSC ? 0xf0 : 0x20,
170 0x0d, *input & V4L2_STD_NTSC ? 0x40 : 0x4a,
171 0x16, *input & V4L2_STD_NTSC ? 0x00 : 0x40,
172 0x17, *input & V4L2_STD_NTSC ? 0x00 : 0x40,
173 0x20, *input & V4L2_STD_NTSC ? 0x07 : 0x0f,
174 0x21, *input & V4L2_STD_NTSC ? 0x07 : 0x0f,
175 0xff, 0xff,
176 };
177 write_regs(client, regs, dec->channel);
178 dec->norm = *input;
179 break;
180 }
181 case VIDIOC_QUERYCTRL:
182 {
183 struct v4l2_queryctrl *ctrl = arg;
184
185 switch (ctrl->id) {
186 case V4L2_CID_BRIGHTNESS:
187 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
188 strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
189 ctrl->minimum = 0;
190 ctrl->maximum = 255;
191 ctrl->step = 1;
192 ctrl->default_value = 128;
193 ctrl->flags = 0;
194 break;
195 case V4L2_CID_CONTRAST:
196 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
197 strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
198 ctrl->minimum = 0;
199 ctrl->maximum = 255;
200 ctrl->step = 1;
201 ctrl->default_value = 128;
202 ctrl->flags = 0;
203 break;
204 case V4L2_CID_SATURATION:
205 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
206 strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
207 ctrl->minimum = 0;
208 ctrl->maximum = 255;
209 ctrl->step = 1;
210 ctrl->default_value = 128;
211 ctrl->flags = 0;
212 break;
213 case V4L2_CID_HUE:
214 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
215 strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
216 ctrl->minimum = 0;
217 ctrl->maximum = 255;
218 ctrl->step = 1;
219 ctrl->default_value = 128;
220 ctrl->flags = 0;
221 break;
222 }
223 break;
224 }
225 case VIDIOC_S_CTRL:
226 {
227 struct v4l2_control *ctrl = arg;
228
229 switch (ctrl->id) {
230 case V4L2_CID_BRIGHTNESS:
231 if (ctrl->value > 255)
232 dec->brightness = 255;
233 else if (ctrl->value < 0)
234 dec->brightness = 0;
235 else
236 dec->brightness = ctrl->value;
237 write_reg(client, 0x12, dec->brightness, dec->channel);
238 break;
239 case V4L2_CID_CONTRAST:
240 if (ctrl->value > 255)
241 dec->contrast = 255;
242 else if (ctrl->value < 0)
243 dec->contrast = 0;
244 else
245 dec->contrast = ctrl->value;
246 write_reg(client, 0x11, dec->contrast, dec->channel);
247 break;
248 case V4L2_CID_SATURATION:
249 if (ctrl->value > 255)
250 dec->saturation = 255;
251 else if (ctrl->value < 0)
252 dec->saturation = 0;
253 else
254 dec->saturation = ctrl->value;
255 write_reg(client, 0x10, dec->saturation, dec->channel);
256 break;
257 case V4L2_CID_HUE:
258 if (ctrl->value > 255)
259 dec->hue = 255;
260 else if (ctrl->value < 0)
261 dec->hue = 0;
262 else
263 dec->hue = ctrl->value;
264 write_reg(client, 0x0f, dec->hue, dec->channel);
265 break;
266 }
267 break;
268 }
269 case VIDIOC_G_CTRL:
270 {
271 struct v4l2_control *ctrl = arg;
272
273 switch (ctrl->id) {
274 case V4L2_CID_BRIGHTNESS:
275 ctrl->value = dec->brightness;
276 break;
277 case V4L2_CID_CONTRAST:
278 ctrl->value = dec->contrast;
279 break;
280 case V4L2_CID_SATURATION:
281 ctrl->value = dec->saturation;
282 break;
283 case V4L2_CID_HUE:
284 ctrl->value = dec->hue;
285 break;
286 }
287 break;
288 }
289 default:
290 break;
291 }
292 return 0;
293}
294
295static int wis_tw2804_probe(struct i2c_client *client,
296 const struct i2c_device_id *id)
297{
298 struct i2c_adapter *adapter = client->adapter;
299 struct wis_tw2804 *dec;
300
301 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
302 return -ENODEV;
303
304 dec = kmalloc(sizeof(struct wis_tw2804), GFP_KERNEL);
305 if (dec == NULL)
306 return -ENOMEM;
307
308 dec->channel = -1;
309 dec->norm = V4L2_STD_NTSC;
310 dec->brightness = 128;
311 dec->contrast = 128;
312 dec->saturation = 128;
313 dec->hue = 128;
314 i2c_set_clientdata(client, dec);
315
316 dev_dbg(&client->dev, "creating TW2804 at address %d on %s\n",
317 client->addr, adapter->name);
318
319 return 0;
320}
321
322static int wis_tw2804_remove(struct i2c_client *client)
323{
324 struct wis_tw2804 *dec = i2c_get_clientdata(client);
325
326 kfree(dec);
327 return 0;
328}
329
330static const struct i2c_device_id wis_tw2804_id[] = {
331 { "wis_tw2804", 0 },
332 { }
333};
334MODULE_DEVICE_TABLE(i2c, wis_tw2804_id);
335
336static struct i2c_driver wis_tw2804_driver = {
337 .driver = {
338 .name = "WIS TW2804 I2C driver",
339 },
340 .probe = wis_tw2804_probe,
341 .remove = wis_tw2804_remove,
342 .command = wis_tw2804_command,
343 .id_table = wis_tw2804_id,
344};
345
346module_i2c_driver(wis_tw2804_driver);
347
348MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/go7007/wis-tw9903.c b/drivers/staging/media/go7007/wis-tw9903.c
deleted file mode 100644
index 684ca37f0382..000000000000
--- a/drivers/staging/media/go7007/wis-tw9903.c
+++ /dev/null
@@ -1,328 +0,0 @@
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
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 Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22#include <linux/ioctl.h>
23#include <linux/slab.h>
24
25#include "wis-i2c.h"
26
27struct wis_tw9903 {
28 int norm;
29 int brightness;
30 int contrast;
31 int hue;
32};
33
34static u8 initial_registers[] = {
35 0x02, 0x44, /* input 1, composite */
36 0x03, 0x92, /* correct digital format */
37 0x04, 0x00,
38 0x05, 0x80, /* or 0x00 for PAL */
39 0x06, 0x40, /* second internal current reference */
40 0x07, 0x02, /* window */
41 0x08, 0x14, /* window */
42 0x09, 0xf0, /* window */
43 0x0a, 0x81, /* window */
44 0x0b, 0xd0, /* window */
45 0x0c, 0x8c,
46 0x0d, 0x00, /* scaling */
47 0x0e, 0x11, /* scaling */
48 0x0f, 0x00, /* scaling */
49 0x10, 0x00, /* brightness */
50 0x11, 0x60, /* contrast */
51 0x12, 0x01, /* sharpness */
52 0x13, 0x7f, /* U gain */
53 0x14, 0x5a, /* V gain */
54 0x15, 0x00, /* hue */
55 0x16, 0xc3, /* sharpness */
56 0x18, 0x00,
57 0x19, 0x58, /* vbi */
58 0x1a, 0x80,
59 0x1c, 0x0f, /* video norm */
60 0x1d, 0x7f, /* video norm */
61 0x20, 0xa0, /* clamping gain (working 0x50) */
62 0x21, 0x22,
63 0x22, 0xf0,
64 0x23, 0xfe,
65 0x24, 0x3c,
66 0x25, 0x38,
67 0x26, 0x44,
68 0x27, 0x20,
69 0x28, 0x00,
70 0x29, 0x15,
71 0x2a, 0xa0,
72 0x2b, 0x44,
73 0x2c, 0x37,
74 0x2d, 0x00,
75 0x2e, 0xa5, /* burst PLL control (working: a9) */
76 0x2f, 0xe0, /* 0xea is blue test frame -- 0xe0 for normal */
77 0x31, 0x00,
78 0x33, 0x22,
79 0x34, 0x11,
80 0x35, 0x35,
81 0x3b, 0x05,
82 0x06, 0xc0, /* reset device */
83 0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
84};
85
86static int write_reg(struct i2c_client *client, u8 reg, u8 value)
87{
88 return i2c_smbus_write_byte_data(client, reg, value);
89}
90
91static int write_regs(struct i2c_client *client, u8 *regs)
92{
93 int i;
94
95 for (i = 0; regs[i] != 0x00; i += 2)
96 if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
97 return -1;
98 return 0;
99}
100
101static int wis_tw9903_command(struct i2c_client *client,
102 unsigned int cmd, void *arg)
103{
104 struct wis_tw9903 *dec = i2c_get_clientdata(client);
105
106 switch (cmd) {
107 case VIDIOC_S_INPUT:
108 {
109 int *input = arg;
110
111 i2c_smbus_write_byte_data(client, 0x02, 0x40 | (*input << 1));
112 break;
113 }
114#if 0
115 /* The scaler on this thing seems to be horribly broken */
116 case DECODER_SET_RESOLUTION:
117 {
118 struct video_decoder_resolution *res = arg;
119 /*int hscale = 256 * 720 / res->width;*/
120 int hscale = 256 * 720 / (res->width - (res->width > 704 ? 0 : 8));
121 int vscale = 256 * (dec->norm & V4L2_STD_NTSC ? 240 : 288)
122 / res->height;
123 u8 regs[] = {
124 0x0d, vscale & 0xff,
125 0x0f, hscale & 0xff,
126 0x0e, ((vscale & 0xf00) >> 4) | ((hscale & 0xf00) >> 8),
127 0x06, 0xc0, /* reset device */
128 0, 0,
129 };
130 dev_dbg(&client->dev, "vscale is %04x, hscale is %04x\n",
131 vscale, hscale);
132 /*write_regs(client, regs);*/
133 break;
134 }
135#endif
136 case VIDIOC_S_STD:
137 {
138 v4l2_std_id *input = arg;
139 u8 regs[] = {
140 0x05, *input & V4L2_STD_NTSC ? 0x80 : 0x00,
141 0x07, *input & V4L2_STD_NTSC ? 0x02 : 0x12,
142 0x08, *input & V4L2_STD_NTSC ? 0x14 : 0x18,
143 0x09, *input & V4L2_STD_NTSC ? 0xf0 : 0x20,
144 0, 0,
145 };
146 write_regs(client, regs);
147 dec->norm = *input;
148 break;
149 }
150 case VIDIOC_QUERYCTRL:
151 {
152 struct v4l2_queryctrl *ctrl = arg;
153
154 switch (ctrl->id) {
155 case V4L2_CID_BRIGHTNESS:
156 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
157 strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
158 ctrl->minimum = -128;
159 ctrl->maximum = 127;
160 ctrl->step = 1;
161 ctrl->default_value = 0x00;
162 ctrl->flags = 0;
163 break;
164 case V4L2_CID_CONTRAST:
165 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
166 strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
167 ctrl->minimum = 0;
168 ctrl->maximum = 255;
169 ctrl->step = 1;
170 ctrl->default_value = 0x60;
171 ctrl->flags = 0;
172 break;
173#if 0
174 /* I don't understand how the Chroma Gain registers work... */
175 case V4L2_CID_SATURATION:
176 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
177 strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
178 ctrl->minimum = 0;
179 ctrl->maximum = 127;
180 ctrl->step = 1;
181 ctrl->default_value = 64;
182 ctrl->flags = 0;
183 break;
184#endif
185 case V4L2_CID_HUE:
186 ctrl->type = V4L2_CTRL_TYPE_INTEGER;
187 strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
188 ctrl->minimum = -128;
189 ctrl->maximum = 127;
190 ctrl->step = 1;
191 ctrl->default_value = 0;
192 ctrl->flags = 0;
193 break;
194 }
195 break;
196 }
197 case VIDIOC_S_CTRL:
198 {
199 struct v4l2_control *ctrl = arg;
200
201 switch (ctrl->id) {
202 case V4L2_CID_BRIGHTNESS:
203 if (ctrl->value > 127)
204 dec->brightness = 127;
205 else if (ctrl->value < -128)
206 dec->brightness = -128;
207 else
208 dec->brightness = ctrl->value;
209 write_reg(client, 0x10, dec->brightness);
210 break;
211 case V4L2_CID_CONTRAST:
212 if (ctrl->value > 255)
213 dec->contrast = 255;
214 else if (ctrl->value < 0)
215 dec->contrast = 0;
216 else
217 dec->contrast = ctrl->value;
218 write_reg(client, 0x11, dec->contrast);
219 break;
220#if 0
221 case V4L2_CID_SATURATION:
222 if (ctrl->value > 127)
223 dec->saturation = 127;
224 else if (ctrl->value < 0)
225 dec->saturation = 0;
226 else
227 dec->saturation = ctrl->value;
228 /*write_reg(client, 0x0c, dec->saturation);*/
229 break;
230#endif
231 case V4L2_CID_HUE:
232 if (ctrl->value > 127)
233 dec->hue = 127;
234 else if (ctrl->value < -128)
235 dec->hue = -128;
236 else
237 dec->hue = ctrl->value;
238 write_reg(client, 0x15, dec->hue);
239 break;
240 }
241 break;
242 }
243 case VIDIOC_G_CTRL:
244 {
245 struct v4l2_control *ctrl = arg;
246
247 switch (ctrl->id) {
248 case V4L2_CID_BRIGHTNESS:
249 ctrl->value = dec->brightness;
250 break;
251 case V4L2_CID_CONTRAST:
252 ctrl->value = dec->contrast;
253 break;
254#if 0
255 case V4L2_CID_SATURATION:
256 ctrl->value = dec->saturation;
257 break;
258#endif
259 case V4L2_CID_HUE:
260 ctrl->value = dec->hue;
261 break;
262 }
263 break;
264 }
265 default:
266 break;
267 }
268 return 0;
269}
270
271static int wis_tw9903_probe(struct i2c_client *client,
272 const struct i2c_device_id *id)
273{
274 struct i2c_adapter *adapter = client->adapter;
275 struct wis_tw9903 *dec;
276
277 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
278 return -ENODEV;
279
280 dec = kmalloc(sizeof(struct wis_tw9903), GFP_KERNEL);
281 if (dec == NULL)
282 return -ENOMEM;
283
284 dec->norm = V4L2_STD_NTSC;
285 dec->brightness = 0;
286 dec->contrast = 0x60;
287 dec->hue = 0;
288 i2c_set_clientdata(client, dec);
289
290 dev_dbg(&client->dev, "initializing TW9903 at address %d on %s\n",
291 client->addr, adapter->name);
292
293 if (write_regs(client, initial_registers) < 0) {
294 dev_err(&client->dev, "error initializing TW9903\n");
295 kfree(dec);
296 return -ENODEV;
297 }
298
299 return 0;
300}
301
302static int wis_tw9903_remove(struct i2c_client *client)
303{
304 struct wis_tw9903 *dec = i2c_get_clientdata(client);
305
306 kfree(dec);
307 return 0;
308}
309
310static const struct i2c_device_id wis_tw9903_id[] = {
311 { "wis_tw9903", 0 },
312 { }
313};
314MODULE_DEVICE_TABLE(i2c, wis_tw9903_id);
315
316static struct i2c_driver wis_tw9903_driver = {
317 .driver = {
318 .name = "WIS TW9903 I2C driver",
319 },
320 .probe = wis_tw9903_probe,
321 .remove = wis_tw9903_remove,
322 .command = wis_tw9903_command,
323 .id_table = wis_tw9903_id,
324};
325
326module_i2c_driver(wis_tw9903_driver);
327
328MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
index 63a554c36f75..f781c532b3c4 100644
--- a/drivers/staging/media/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
@@ -787,12 +787,6 @@ static int init_hardware(void)
787 spin_lock_irqsave(&hardware_lock, flags); 787 spin_lock_irqsave(&hardware_lock, flags);
788 /* reset UART */ 788 /* reset UART */
789#ifdef LIRC_ON_SA1100 789#ifdef LIRC_ON_SA1100
790#ifdef CONFIG_SA1100_BITSY
791 if (machine_is_bitsy()) {
792 pr_info("Power on IR module\n");
793 set_bitsy_egpio(EGPIO_BITSY_IR_ON);
794 }
795#endif
796#ifdef CONFIG_SA1100_COLLIE 790#ifdef CONFIG_SA1100_COLLIE
797 sa1100_irda_set_power_collie(3); /* power on */ 791 sa1100_irda_set_power_collie(3); /* power on */
798#endif 792#endif
@@ -942,10 +936,6 @@ static void drop_hardware(void)
942 Ser2UTCR3 = sr.utcr3; 936 Ser2UTCR3 = sr.utcr3;
943 937
944 Ser2HSCR0 = sr.hscr0; 938 Ser2HSCR0 = sr.hscr0;
945#ifdef CONFIG_SA1100_BITSY
946 if (machine_is_bitsy())
947 clr_bitsy_egpio(EGPIO_BITSY_IR_ON);
948#endif
949#ifdef CONFIG_SA1100_COLLIE 939#ifdef CONFIG_SA1100_COLLIE
950 sa1100_irda_set_power_collie(0); /* power off */ 940 sa1100_irda_set_power_collie(0); /* power off */
951#endif 941#endif
diff --git a/drivers/staging/media/solo6x10/Kconfig b/drivers/staging/media/solo6x10/Kconfig
index 63352de5eabf..ec32776ff547 100644
--- a/drivers/staging/media/solo6x10/Kconfig
+++ b/drivers/staging/media/solo6x10/Kconfig
@@ -1,7 +1,8 @@
1config SOLO6X10 1config SOLO6X10
2 tristate "Softlogic 6x10 MPEG codec cards" 2 tristate "Softlogic 6x10 MPEG codec cards"
3 depends on PCI && VIDEO_DEV && SND && I2C 3 depends on PCI && VIDEO_DEV && SND && I2C
4 select VIDEOBUF_DMA_SG 4 select VIDEOBUF2_DMA_SG
5 select VIDEOBUF2_DMA_CONTIG
5 select SND_PCM 6 select SND_PCM
6 ---help--- 7 ---help---
7 This driver supports the Softlogic based MPEG-4 and h.264 codec 8 This driver supports the Softlogic based MPEG-4 and h.264 codec
diff --git a/drivers/staging/media/solo6x10/Makefile b/drivers/staging/media/solo6x10/Makefile
index 337e38c3a0f0..7aae118947b2 100644
--- a/drivers/staging/media/solo6x10/Makefile
+++ b/drivers/staging/media/solo6x10/Makefile
@@ -1,3 +1,5 @@
1solo6x10-y := core.o i2c.o p2m.o v4l2.o tw28.o gpio.o disp.o enc.o v4l2-enc.o g723.o 1solo6x10-y := solo6x10-core.o solo6x10-i2c.o solo6x10-p2m.o solo6x10-v4l2.o \
2 solo6x10-tw28.o solo6x10-gpio.o solo6x10-disp.o solo6x10-enc.o \
3 solo6x10-v4l2-enc.o solo6x10-g723.o solo6x10-eeprom.o
2 4
3obj-$(CONFIG_SOLO6X10) += solo6x10.o 5obj-$(CONFIG_SOLO6X10) += solo6x10.o
diff --git a/drivers/staging/media/solo6x10/TODO b/drivers/staging/media/solo6x10/TODO
index 539f739fe9e6..7b8db75b1acb 100644
--- a/drivers/staging/media/solo6x10/TODO
+++ b/drivers/staging/media/solo6x10/TODO
@@ -1,24 +1,15 @@
1TODO (staging => main): 1- batch up desc requests for more efficient use of p2m?
2 2- encoder on/off controls
3 * Motion detection flags need to be moved to v4l2 3- mpeg cid bitrate mode (vbr/cbr)
4 * Some private CIDs need to be moved to v4l2 4- mpeg cid bitrate/bitrate-peak
5 5- mpeg encode of user data
6TODO (general): 6- mpeg decode of user data
7 7- implement CID controls for mozaic areas
8 * encoder on/off controls 8
9 * mpeg cid bitrate mode (vbr/cbr) 9- sound
10 * mpeg cid bitrate/bitrate-peak 10 - implement playback via external sound jack
11 * mpeg encode of user data 11 - implement loopback of external sound jack with incoming audio?
12 * mpeg decode of user data 12 - implement pause/resume (make use of in bc-server)
13 * switch between 4 frames/irq to 1 when using mjpeg (and then back 13
14 when not) 14Please send patches to the linux media list <linux-media@vger.kernel.org> and
15 * implement a CID control for motion areas/thresholds 15Cc Ismael Luceno <ismael.luceno@corp.bluecherry.net>.
16 * implement CID controls for mozaic areas
17 * allow for higher level of interval (for < 1 fps)
18 * sound:
19 - implement playback via external sound jack
20 - implement loopback of external sound jack with incoming audio?
21 - implement pause/resume
22
23Plase send patches to Mauro Carvalho Chehab <mchehab@redhat.com> and Cc Ben Collins
24<bcollins@bluecherry.net>
diff --git a/drivers/staging/media/solo6x10/core.c b/drivers/staging/media/solo6x10/core.c
deleted file mode 100644
index fd83d6d028bf..000000000000
--- a/drivers/staging/media/solo6x10/core.c
+++ /dev/null
@@ -1,321 +0,0 @@
1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/interrupt.h>
24#include <linux/slab.h>
25#include <linux/videodev2.h>
26#include "solo6x10.h"
27#include "tw28.h"
28
29MODULE_DESCRIPTION("Softlogic 6x10 MP4/H.264 Encoder/Decoder V4L2/ALSA Driver");
30MODULE_AUTHOR("Ben Collins <bcollins@bluecherry.net>");
31MODULE_VERSION(SOLO6X10_VERSION);
32MODULE_LICENSE("GPL");
33
34void solo_irq_on(struct solo_dev *solo_dev, u32 mask)
35{
36 solo_dev->irq_mask |= mask;
37 solo_reg_write(solo_dev, SOLO_IRQ_ENABLE, solo_dev->irq_mask);
38}
39
40void solo_irq_off(struct solo_dev *solo_dev, u32 mask)
41{
42 solo_dev->irq_mask &= ~mask;
43 solo_reg_write(solo_dev, SOLO_IRQ_ENABLE, solo_dev->irq_mask);
44}
45
46/* XXX We should check the return value of the sub-device ISR's */
47static irqreturn_t solo_isr(int irq, void *data)
48{
49 struct solo_dev *solo_dev = data;
50 u32 status;
51 int i;
52
53 status = solo_reg_read(solo_dev, SOLO_IRQ_STAT);
54 if (!status)
55 return IRQ_NONE;
56
57 if (status & ~solo_dev->irq_mask) {
58 solo_reg_write(solo_dev, SOLO_IRQ_STAT,
59 status & ~solo_dev->irq_mask);
60 status &= solo_dev->irq_mask;
61 }
62
63 if (status & SOLO_IRQ_PCI_ERR) {
64 u32 err = solo_reg_read(solo_dev, SOLO_PCI_ERR);
65 solo_p2m_error_isr(solo_dev, err);
66 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_PCI_ERR);
67 }
68
69 for (i = 0; i < SOLO_NR_P2M; i++)
70 if (status & SOLO_IRQ_P2M(i))
71 solo_p2m_isr(solo_dev, i);
72
73 if (status & SOLO_IRQ_IIC)
74 solo_i2c_isr(solo_dev);
75
76 if (status & SOLO_IRQ_VIDEO_IN)
77 solo_video_in_isr(solo_dev);
78
79 /* Call this first so enc gets detected flag set */
80 if (status & SOLO_IRQ_MOTION)
81 solo_motion_isr(solo_dev);
82
83 if (status & SOLO_IRQ_ENCODER)
84 solo_enc_v4l2_isr(solo_dev);
85
86 if (status & SOLO_IRQ_G723)
87 solo_g723_isr(solo_dev);
88
89 return IRQ_HANDLED;
90}
91
92static void free_solo_dev(struct solo_dev *solo_dev)
93{
94 struct pci_dev *pdev;
95
96 if (!solo_dev)
97 return;
98
99 pdev = solo_dev->pdev;
100
101 /* If we never initialized the PCI device, then nothing else
102 * below here needs cleanup */
103 if (!pdev) {
104 kfree(solo_dev);
105 return;
106 }
107
108 /* Bring down the sub-devices first */
109 solo_g723_exit(solo_dev);
110 solo_enc_v4l2_exit(solo_dev);
111 solo_enc_exit(solo_dev);
112 solo_v4l2_exit(solo_dev);
113 solo_disp_exit(solo_dev);
114 solo_gpio_exit(solo_dev);
115 solo_p2m_exit(solo_dev);
116 solo_i2c_exit(solo_dev);
117
118 /* Now cleanup the PCI device */
119 if (solo_dev->reg_base) {
120 solo_irq_off(solo_dev, ~0);
121 pci_iounmap(pdev, solo_dev->reg_base);
122 free_irq(pdev->irq, solo_dev);
123 }
124
125 pci_release_regions(pdev);
126 pci_disable_device(pdev);
127 pci_set_drvdata(pdev, NULL);
128
129 kfree(solo_dev);
130}
131
132static int solo_pci_probe(struct pci_dev *pdev,
133 const struct pci_device_id *id)
134{
135 struct solo_dev *solo_dev;
136 int ret;
137 int sdram;
138 u8 chip_id;
139 u32 reg;
140
141 solo_dev = kzalloc(sizeof(*solo_dev), GFP_KERNEL);
142 if (solo_dev == NULL)
143 return -ENOMEM;
144
145 solo_dev->pdev = pdev;
146 spin_lock_init(&solo_dev->reg_io_lock);
147 pci_set_drvdata(pdev, solo_dev);
148
149 ret = pci_enable_device(pdev);
150 if (ret)
151 goto fail_probe;
152
153 pci_set_master(pdev);
154
155 ret = pci_request_regions(pdev, SOLO6X10_NAME);
156 if (ret)
157 goto fail_probe;
158
159 solo_dev->reg_base = pci_ioremap_bar(pdev, 0);
160 if (solo_dev->reg_base == NULL) {
161 ret = -ENOMEM;
162 goto fail_probe;
163 }
164
165 chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) &
166 SOLO_CHIP_ID_MASK;
167 switch (chip_id) {
168 case 7:
169 solo_dev->nr_chans = 16;
170 solo_dev->nr_ext = 5;
171 break;
172 case 6:
173 solo_dev->nr_chans = 8;
174 solo_dev->nr_ext = 2;
175 break;
176 default:
177 dev_warn(&pdev->dev, "Invalid chip_id 0x%02x, "
178 "defaulting to 4 channels\n",
179 chip_id);
180 case 5:
181 solo_dev->nr_chans = 4;
182 solo_dev->nr_ext = 1;
183 }
184
185 solo_dev->flags = id->driver_data;
186
187 /* Disable all interrupts to start */
188 solo_irq_off(solo_dev, ~0);
189
190 reg = SOLO_SYS_CFG_SDRAM64BIT;
191 /* Initial global settings */
192 if (!(solo_dev->flags & FLAGS_6110))
193 reg |= SOLO6010_SYS_CFG_INPUTDIV(25) |
194 SOLO6010_SYS_CFG_FEEDBACKDIV((SOLO_CLOCK_MHZ * 2) - 2) |
195 SOLO6010_SYS_CFG_OUTDIV(3);
196 solo_reg_write(solo_dev, SOLO_SYS_CFG, reg);
197
198 if (solo_dev->flags & FLAGS_6110) {
199 u32 sys_clock_MHz = SOLO_CLOCK_MHZ;
200 u32 pll_DIVQ;
201 u32 pll_DIVF;
202
203 if (sys_clock_MHz < 125) {
204 pll_DIVQ = 3;
205 pll_DIVF = (sys_clock_MHz * 4) / 3;
206 } else {
207 pll_DIVQ = 2;
208 pll_DIVF = (sys_clock_MHz * 2) / 3;
209 }
210
211 solo_reg_write(solo_dev, SOLO6110_PLL_CONFIG,
212 SOLO6110_PLL_RANGE_5_10MHZ |
213 SOLO6110_PLL_DIVR(9) |
214 SOLO6110_PLL_DIVQ_EXP(pll_DIVQ) |
215 SOLO6110_PLL_DIVF(pll_DIVF) | SOLO6110_PLL_FSEN);
216 mdelay(1); /* PLL Locking time (1ms) */
217
218 solo_reg_write(solo_dev, SOLO_DMA_CTRL1, 3 << 8); /* ? */
219 } else
220 solo_reg_write(solo_dev, SOLO_DMA_CTRL1, 1 << 8); /* ? */
221
222 solo_reg_write(solo_dev, SOLO_TIMER_CLOCK_NUM, SOLO_CLOCK_MHZ - 1);
223
224 /* PLL locking time of 1ms */
225 mdelay(1);
226
227 ret = request_irq(pdev->irq, solo_isr, IRQF_SHARED, SOLO6X10_NAME,
228 solo_dev);
229 if (ret)
230 goto fail_probe;
231
232 /* Handle this from the start */
233 solo_irq_on(solo_dev, SOLO_IRQ_PCI_ERR);
234
235 ret = solo_i2c_init(solo_dev);
236 if (ret)
237 goto fail_probe;
238
239 /* Setup the DMA engine */
240 sdram = (solo_dev->nr_chans >= 8) ? 2 : 1;
241 solo_reg_write(solo_dev, SOLO_DMA_CTRL,
242 SOLO_DMA_CTRL_REFRESH_CYCLE(1) |
243 SOLO_DMA_CTRL_SDRAM_SIZE(sdram) |
244 SOLO_DMA_CTRL_SDRAM_CLK_INVERT |
245 SOLO_DMA_CTRL_READ_CLK_SELECT |
246 SOLO_DMA_CTRL_LATENCY(1));
247
248 ret = solo_p2m_init(solo_dev);
249 if (ret)
250 goto fail_probe;
251
252 ret = solo_disp_init(solo_dev);
253 if (ret)
254 goto fail_probe;
255
256 ret = solo_gpio_init(solo_dev);
257 if (ret)
258 goto fail_probe;
259
260 ret = solo_tw28_init(solo_dev);
261 if (ret)
262 goto fail_probe;
263
264 ret = solo_v4l2_init(solo_dev);
265 if (ret)
266 goto fail_probe;
267
268 ret = solo_enc_init(solo_dev);
269 if (ret)
270 goto fail_probe;
271
272 ret = solo_enc_v4l2_init(solo_dev);
273 if (ret)
274 goto fail_probe;
275
276 ret = solo_g723_init(solo_dev);
277 if (ret)
278 goto fail_probe;
279
280 return 0;
281
282fail_probe:
283 free_solo_dev(solo_dev);
284 return ret;
285}
286
287static void solo_pci_remove(struct pci_dev *pdev)
288{
289 struct solo_dev *solo_dev = pci_get_drvdata(pdev);
290
291 free_solo_dev(solo_dev);
292}
293
294static struct pci_device_id solo_id_table[] = {
295 /* 6010 based cards */
296 {PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6010)},
297 {PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6110),
298 .driver_data = FLAGS_6110},
299 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_4)},
300 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_9)},
301 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_16)},
302 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_4)},
303 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_9)},
304 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_16)},
305 /* 6110 based cards */
306 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_4)},
307 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_8)},
308 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_16)},
309 {0,}
310};
311
312MODULE_DEVICE_TABLE(pci, solo_id_table);
313
314static struct pci_driver solo_pci_driver = {
315 .name = SOLO6X10_NAME,
316 .id_table = solo_id_table,
317 .probe = solo_pci_probe,
318 .remove = solo_pci_remove,
319};
320
321module_pci_driver(solo_pci_driver);
diff --git a/drivers/staging/media/solo6x10/offsets.h b/drivers/staging/media/solo6x10/offsets.h
deleted file mode 100644
index 3d7e569f1cf8..000000000000
--- a/drivers/staging/media/solo6x10/offsets.h
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifndef __SOLO6X10_OFFSETS_H
21#define __SOLO6X10_OFFSETS_H
22
23/* Offsets and sizes of the external address */
24#define SOLO_DISP_EXT_ADDR 0x00000000
25#define SOLO_DISP_EXT_SIZE 0x00480000
26
27#define SOLO_DEC2LIVE_EXT_ADDR (SOLO_DISP_EXT_ADDR + SOLO_DISP_EXT_SIZE)
28#define SOLO_DEC2LIVE_EXT_SIZE 0x00240000
29
30#define SOLO_OSG_EXT_ADDR (SOLO_DEC2LIVE_EXT_ADDR + SOLO_DEC2LIVE_EXT_SIZE)
31#define SOLO_OSG_EXT_SIZE 0x00120000
32
33#define SOLO_EOSD_EXT_ADDR (SOLO_OSG_EXT_ADDR + SOLO_OSG_EXT_SIZE)
34#define SOLO_EOSD_EXT_SIZE 0x00010000
35
36#define SOLO_MOTION_EXT_ADDR(__solo) (SOLO_EOSD_EXT_ADDR + \
37 (SOLO_EOSD_EXT_SIZE * __solo->nr_chans))
38#define SOLO_MOTION_EXT_SIZE 0x00080000
39
40#define SOLO_G723_EXT_ADDR(__solo) \
41 (SOLO_MOTION_EXT_ADDR(__solo) + SOLO_MOTION_EXT_SIZE)
42#define SOLO_G723_EXT_SIZE 0x00010000
43
44#define SOLO_CAP_EXT_ADDR(__solo) \
45 (SOLO_G723_EXT_ADDR(__solo) + SOLO_G723_EXT_SIZE)
46#define SOLO_CAP_EXT_MAX_PAGE (18 + 15)
47#define SOLO_CAP_EXT_SIZE (SOLO_CAP_EXT_MAX_PAGE * 65536)
48
49/* This +1 is very important -- Why?! -- BenC */
50#define SOLO_EREF_EXT_ADDR(__solo) \
51 (SOLO_CAP_EXT_ADDR(__solo) + \
52 (SOLO_CAP_EXT_SIZE * (__solo->nr_chans + 1)))
53#define SOLO_EREF_EXT_SIZE 0x00140000
54
55#define SOLO_MP4E_EXT_ADDR(__solo) \
56 (SOLO_EREF_EXT_ADDR(__solo) + \
57 (SOLO_EREF_EXT_SIZE * __solo->nr_chans))
58#define SOLO_MP4E_EXT_SIZE(__solo) (0x00080000 * __solo->nr_chans)
59
60#define SOLO_DREF_EXT_ADDR(__solo) \
61 (SOLO_MP4E_EXT_ADDR(__solo) + SOLO_MP4E_EXT_SIZE(__solo))
62#define SOLO_DREF_EXT_SIZE 0x00140000
63
64#define SOLO_MP4D_EXT_ADDR(__solo) \
65 (SOLO_DREF_EXT_ADDR(__solo) + \
66 (SOLO_DREF_EXT_SIZE * __solo->nr_chans))
67#define SOLO_MP4D_EXT_SIZE 0x00080000
68
69#define SOLO_JPEG_EXT_ADDR(__solo) \
70 (SOLO_MP4D_EXT_ADDR(__solo) + \
71 (SOLO_MP4D_EXT_SIZE * __solo->nr_chans))
72#define SOLO_JPEG_EXT_SIZE(__solo) (0x00080000 * __solo->nr_chans)
73
74#endif /* __SOLO6X10_OFFSETS_H */
diff --git a/drivers/staging/media/solo6x10/osd-font.h b/drivers/staging/media/solo6x10/osd-font.h
deleted file mode 100644
index 591e0e82e0e8..000000000000
--- a/drivers/staging/media/solo6x10/osd-font.h
+++ /dev/null
@@ -1,154 +0,0 @@
1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifndef __SOLO6X10_OSD_FONT_H
21#define __SOLO6X10_OSD_FONT_H
22
23static const unsigned int solo_osd_font[] = {
24 0x00000000, 0x0000c0c8, 0xccfefe0c, 0x08000000,
25 0x00000000, 0x10103838, 0x7c7cfefe, 0x00000000, /* 0 */
26 0x00000000, 0xfefe7c7c, 0x38381010, 0x10000000,
27 0x00000000, 0x7c82fefe, 0xfefefe7c, 0x00000000,
28 0x00000000, 0x00001038, 0x10000000, 0x00000000,
29 0x00000000, 0x0010387c, 0xfe7c3810, 0x00000000,
30 0x00000000, 0x00384444, 0x44380000, 0x00000000,
31 0x00000000, 0x38448282, 0x82443800, 0x00000000,
32 0x00000000, 0x007c7c7c, 0x7c7c0000, 0x00000000,
33 0x00000000, 0x6c6c6c6c, 0x6c6c6c6c, 0x00000000,
34 0x00000000, 0x061e7efe, 0xfe7e1e06, 0x00000000,
35 0x00000000, 0xc0f0fcfe, 0xfefcf0c0, 0x00000000,
36 0x00000000, 0xc6cedefe, 0xfedecec6, 0x00000000,
37 0x00000000, 0xc6e6f6fe, 0xfef6e6c6, 0x00000000,
38 0x00000000, 0x12367efe, 0xfe7e3612, 0x00000000,
39 0x00000000, 0x90d8fcfe, 0xfefcd890, 0x00000000,
40 0x00000038, 0x7cc692ba, 0x92c67c38, 0x00000000,
41 0x00000038, 0x7cc6aa92, 0xaac67c38, 0x00000000,
42 0x00000038, 0x7830107c, 0xbaa8680c, 0x00000000,
43 0x00000038, 0x3c18127c, 0xb8382c60, 0x00000000,
44 0x00000044, 0xaa6c8254, 0x38eec67c, 0x00000000,
45 0x00000082, 0x44288244, 0x38c6827c, 0x00000000,
46 0x00000038, 0x444444fe, 0xfeeec6fe, 0x00000000,
47 0x00000018, 0x78187818, 0x3c7e7e3c, 0x00000000,
48 0x00000000, 0x3854929a, 0x82443800, 0x00000000,
49 0x00000000, 0x00c0c8cc, 0xfefe0c08, 0x00000000,
50 0x0000e0a0, 0xe040e00e, 0x8a0ea40e, 0x00000000,
51 0x0000e0a0, 0xe040e00e, 0x0a8e440e, 0x00000000,
52 0x0000007c, 0x82829292, 0x929282fe, 0x00000000,
53 0x000000f8, 0xfc046494, 0x946404fc, 0x00000000,
54 0x0000003f, 0x7f404c52, 0x524c407f, 0x00000000,
55 0x0000007c, 0x82ba82ba, 0x82ba82fe, 0x00000000,
56 0x00000000, 0x00000000, 0x00000000, 0x00000000,
57 0x00000000, 0x183c3c3c, 0x18180018, 0x18000000, /* 32 ! */
58 0x00000066, 0x66240000, 0x00000000, 0x00000000,
59 0x00000000, 0x6c6cfe6c, 0x6c6cfe6c, 0x6c000000, /* 34 " # */
60 0x00001010, 0x7cd6d616, 0x7cd0d6d6, 0x7c101000,
61 0x00000000, 0x0086c660, 0x30180cc6, 0xc2000000, /* 36 $ % */
62 0x00000000, 0x386c6c38, 0xdc766666, 0xdc000000,
63 0x0000000c, 0x0c0c0600, 0x00000000, 0x00000000, /* 38 & ' */
64 0x00000000, 0x30180c0c, 0x0c0c0c18, 0x30000000,
65 0x00000000, 0x0c183030, 0x30303018, 0x0c000000, /* 40 ( ) */
66 0x00000000, 0x0000663c, 0xff3c6600, 0x00000000,
67 0x00000000, 0x00001818, 0x7e181800, 0x00000000, /* 42 * + */
68 0x00000000, 0x00000000, 0x00000e0e, 0x0c060000,
69 0x00000000, 0x00000000, 0x7e000000, 0x00000000, /* 44 , - */
70 0x00000000, 0x00000000, 0x00000006, 0x06000000,
71 0x00000000, 0x80c06030, 0x180c0602, 0x00000000, /* 46 . / */
72 0x0000007c, 0xc6e6f6de, 0xcec6c67c, 0x00000000,
73 0x00000030, 0x383c3030, 0x303030fc, 0x00000000, /* 48 0 1 */
74 0x0000007c, 0xc6c06030, 0x180cc6fe, 0x00000000,
75 0x0000007c, 0xc6c0c07c, 0xc0c0c67c, 0x00000000, /* 50 2 3 */
76 0x00000060, 0x70786c66, 0xfe6060f0, 0x00000000,
77 0x000000fe, 0x0606067e, 0xc0c0c67c, 0x00000000, /* 52 4 5 */
78 0x00000038, 0x0c06067e, 0xc6c6c67c, 0x00000000,
79 0x000000fe, 0xc6c06030, 0x18181818, 0x00000000, /* 54 6 7 */
80 0x0000007c, 0xc6c6c67c, 0xc6c6c67c, 0x00000000,
81 0x0000007c, 0xc6c6c6fc, 0xc0c06038, 0x00000000, /* 56 8 9 */
82 0x00000000, 0x18180000, 0x00181800, 0x00000000,
83 0x00000000, 0x18180000, 0x0018180c, 0x00000000, /* 58 : ; */
84 0x00000060, 0x30180c06, 0x0c183060, 0x00000000,
85 0x00000000, 0x007e0000, 0x007e0000, 0x00000000,
86 0x00000006, 0x0c183060, 0x30180c06, 0x00000000,
87 0x0000007c, 0xc6c66030, 0x30003030, 0x00000000,
88 0x0000007c, 0xc6f6d6d6, 0x7606067c, 0x00000000,
89 0x00000010, 0x386cc6c6, 0xfec6c6c6, 0x00000000, /* 64 @ A */
90 0x0000007e, 0xc6c6c67e, 0xc6c6c67e, 0x00000000,
91 0x00000078, 0xcc060606, 0x0606cc78, 0x00000000, /* 66 */
92 0x0000003e, 0x66c6c6c6, 0xc6c6663e, 0x00000000,
93 0x000000fe, 0x0606063e, 0x060606fe, 0x00000000, /* 68 */
94 0x000000fe, 0x0606063e, 0x06060606, 0x00000000,
95 0x00000078, 0xcc060606, 0xf6c6ccb8, 0x00000000, /* 70 */
96 0x000000c6, 0xc6c6c6fe, 0xc6c6c6c6, 0x00000000,
97 0x0000003c, 0x18181818, 0x1818183c, 0x00000000, /* 72 */
98 0x00000060, 0x60606060, 0x6066663c, 0x00000000,
99 0x000000c6, 0xc666361e, 0x3666c6c6, 0x00000000, /* 74 */
100 0x00000006, 0x06060606, 0x060606fe, 0x00000000,
101 0x000000c6, 0xeefed6c6, 0xc6c6c6c6, 0x00000000, /* 76 */
102 0x000000c6, 0xcedefef6, 0xe6c6c6c6, 0x00000000,
103 0x00000038, 0x6cc6c6c6, 0xc6c66c38, 0x00000000, /* 78 */
104 0x0000007e, 0xc6c6c67e, 0x06060606, 0x00000000,
105 0x00000038, 0x6cc6c6c6, 0xc6d67c38, 0x60000000, /* 80 */
106 0x0000007e, 0xc6c6c67e, 0x66c6c6c6, 0x00000000,
107 0x0000007c, 0xc6c60c38, 0x60c6c67c, 0x00000000, /* 82 */
108 0x0000007e, 0x18181818, 0x18181818, 0x00000000,
109 0x000000c6, 0xc6c6c6c6, 0xc6c6c67c, 0x00000000, /* 84 */
110 0x000000c6, 0xc6c6c6c6, 0xc66c3810, 0x00000000,
111 0x000000c6, 0xc6c6c6c6, 0xd6d6fe6c, 0x00000000, /* 86 */
112 0x000000c6, 0xc6c66c38, 0x6cc6c6c6, 0x00000000,
113 0x00000066, 0x66666666, 0x3c181818, 0x00000000, /* 88 */
114 0x000000fe, 0xc0603018, 0x0c0606fe, 0x00000000,
115 0x0000003c, 0x0c0c0c0c, 0x0c0c0c3c, 0x00000000, /* 90 */
116 0x00000002, 0x060c1830, 0x60c08000, 0x00000000,
117 0x0000003c, 0x30303030, 0x3030303c, 0x00000000, /* 92 */
118 0x00001038, 0x6cc60000, 0x00000000, 0x00000000,
119 0x00000000, 0x00000000, 0x00000000, 0x00fe0000,
120 0x00001818, 0x30000000, 0x00000000, 0x00000000,
121 0x00000000, 0x00003c60, 0x7c66667c, 0x00000000,
122 0x0000000c, 0x0c0c7ccc, 0xcccccc7c, 0x00000000,
123 0x00000000, 0x00007cc6, 0x0606c67c, 0x00000000,
124 0x00000060, 0x60607c66, 0x6666667c, 0x00000000,
125 0x00000000, 0x00007cc6, 0xfe06c67c, 0x00000000,
126 0x00000078, 0x0c0c0c3e, 0x0c0c0c0c, 0x00000000,
127 0x00000000, 0x00007c66, 0x6666667c, 0x60603e00,
128 0x0000000c, 0x0c0c7ccc, 0xcccccccc, 0x00000000,
129 0x00000030, 0x30003830, 0x30303078, 0x00000000,
130 0x00000030, 0x30003c30, 0x30303030, 0x30301f00,
131 0x0000000c, 0x0c0ccc6c, 0x3c6ccccc, 0x00000000,
132 0x00000030, 0x30303030, 0x30303030, 0x00000000,
133 0x00000000, 0x000066fe, 0xd6d6d6d6, 0x00000000,
134 0x00000000, 0x000078cc, 0xcccccccc, 0x00000000,
135 0x00000000, 0x00007cc6, 0xc6c6c67c, 0x00000000,
136 0x00000000, 0x00007ccc, 0xcccccc7c, 0x0c0c0c00,
137 0x00000000, 0x00007c66, 0x6666667c, 0x60606000,
138 0x00000000, 0x000076dc, 0x0c0c0c0c, 0x00000000,
139 0x00000000, 0x00007cc6, 0x1c70c67c, 0x00000000,
140 0x00000000, 0x1818fe18, 0x18181870, 0x00000000,
141 0x00000000, 0x00006666, 0x6666663c, 0x00000000,
142 0x00000000, 0x0000c6c6, 0xc66c3810, 0x00000000,
143 0x00000000, 0x0000c6d6, 0xd6d6fe6c, 0x00000000,
144 0x00000000, 0x0000c66c, 0x38386cc6, 0x00000000,
145 0x00000000, 0x00006666, 0x6666667c, 0x60603e00,
146 0x00000000, 0x0000fe60, 0x30180cfe, 0x00000000,
147 0x00000070, 0x1818180e, 0x18181870, 0x00000000,
148 0x00000018, 0x18181800, 0x18181818, 0x00000000,
149 0x0000000e, 0x18181870, 0x1818180e, 0x00000000,
150 0x000000dc, 0x76000000, 0x00000000, 0x00000000,
151 0x00000000, 0x0010386c, 0xc6c6fe00, 0x00000000
152};
153
154#endif /* __SOLO6X10_OSD_FONT_H */
diff --git a/drivers/staging/media/solo6x10/p2m.c b/drivers/staging/media/solo6x10/p2m.c
deleted file mode 100644
index 58ab61b1f1d9..000000000000
--- a/drivers/staging/media/solo6x10/p2m.c
+++ /dev/null
@@ -1,306 +0,0 @@
1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <linux/kernel.h>
21#include <linux/slab.h>
22#include <linux/scatterlist.h>
23#include "solo6x10.h"
24
25/* #define SOLO_TEST_P2M */
26
27int solo_p2m_dma(struct solo_dev *solo_dev, u8 id, int wr,
28 void *sys_addr, u32 ext_addr, u32 size)
29{
30 dma_addr_t dma_addr;
31 int ret;
32
33 WARN_ON(!size);
34 BUG_ON(id >= SOLO_NR_P2M);
35
36 if (!size)
37 return -EINVAL;
38
39 dma_addr = pci_map_single(solo_dev->pdev, sys_addr, size,
40 wr ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
41
42 ret = solo_p2m_dma_t(solo_dev, id, wr, dma_addr, ext_addr, size);
43
44 pci_unmap_single(solo_dev->pdev, dma_addr, size,
45 wr ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
46
47 return ret;
48}
49
50int solo_p2m_dma_t(struct solo_dev *solo_dev, u8 id, int wr,
51 dma_addr_t dma_addr, u32 ext_addr, u32 size)
52{
53 struct p2m_desc *desc = kzalloc(sizeof(*desc) * 2, GFP_DMA);
54 int ret;
55
56 if (desc == NULL)
57 return -ENOMEM;
58
59 solo_p2m_push_desc(&desc[1], wr, dma_addr, ext_addr, size, 0, 0);
60 ret = solo_p2m_dma_desc(solo_dev, id, desc, 2);
61 kfree(desc);
62
63 return ret;
64}
65
66void solo_p2m_push_desc(struct p2m_desc *desc, int wr, dma_addr_t dma_addr,
67 u32 ext_addr, u32 size, int repeat, u32 ext_size)
68{
69 desc->ta = cpu_to_le32(dma_addr);
70 desc->fa = cpu_to_le32(ext_addr);
71
72 desc->ext = cpu_to_le32(SOLO_P2M_COPY_SIZE(size >> 2));
73 desc->ctrl = cpu_to_le32(SOLO_P2M_BURST_SIZE(SOLO_P2M_BURST_256) |
74 (wr ? SOLO_P2M_WRITE : 0) | SOLO_P2M_TRANS_ON);
75
76 /* Ext size only matters when we're repeating */
77 if (repeat) {
78 desc->ext |= cpu_to_le32(SOLO_P2M_EXT_INC(ext_size >> 2));
79 desc->ctrl |= cpu_to_le32(SOLO_P2M_PCI_INC(size >> 2) |
80 SOLO_P2M_REPEAT(repeat));
81 }
82}
83
84int solo_p2m_dma_desc(struct solo_dev *solo_dev, u8 id,
85 struct p2m_desc *desc, int desc_count)
86{
87 struct solo_p2m_dev *p2m_dev;
88 unsigned int timeout;
89 int ret = 0;
90 u32 config = 0;
91 dma_addr_t desc_dma = 0;
92
93 BUG_ON(id >= SOLO_NR_P2M);
94 BUG_ON(!desc_count || desc_count > SOLO_NR_P2M_DESC);
95
96 p2m_dev = &solo_dev->p2m_dev[id];
97
98 mutex_lock(&p2m_dev->mutex);
99
100 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), 0);
101
102 INIT_COMPLETION(p2m_dev->completion);
103 p2m_dev->error = 0;
104
105 /* Enable the descriptors */
106 config = solo_reg_read(solo_dev, SOLO_P2M_CONFIG(id));
107 desc_dma = pci_map_single(solo_dev->pdev, desc,
108 desc_count * sizeof(*desc),
109 PCI_DMA_TODEVICE);
110 solo_reg_write(solo_dev, SOLO_P2M_DES_ADR(id), desc_dma);
111 solo_reg_write(solo_dev, SOLO_P2M_DESC_ID(id), desc_count - 1);
112 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(id), config |
113 SOLO_P2M_DESC_MODE);
114
115 /* Should have all descriptors completed from one interrupt */
116 timeout = wait_for_completion_timeout(&p2m_dev->completion, HZ);
117
118 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), 0);
119
120 /* Reset back to non-descriptor mode */
121 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(id), config);
122 solo_reg_write(solo_dev, SOLO_P2M_DESC_ID(id), 0);
123 solo_reg_write(solo_dev, SOLO_P2M_DES_ADR(id), 0);
124 pci_unmap_single(solo_dev->pdev, desc_dma,
125 desc_count * sizeof(*desc),
126 PCI_DMA_TODEVICE);
127
128 if (p2m_dev->error)
129 ret = -EIO;
130 else if (timeout == 0)
131 ret = -EAGAIN;
132
133 mutex_unlock(&p2m_dev->mutex);
134
135 WARN_ON_ONCE(ret);
136
137 return ret;
138}
139
140int solo_p2m_dma_sg(struct solo_dev *solo_dev, u8 id,
141 struct p2m_desc *pdesc, int wr,
142 struct scatterlist *sg, u32 sg_off,
143 u32 ext_addr, u32 size)
144{
145 int i;
146 int idx;
147
148 BUG_ON(id >= SOLO_NR_P2M);
149
150 if (WARN_ON_ONCE(!size))
151 return -EINVAL;
152
153 memset(pdesc, 0, sizeof(*pdesc));
154
155 /* Should rewrite this to handle > SOLO_NR_P2M_DESC transactions */
156 for (i = 0, idx = 1; idx < SOLO_NR_P2M_DESC && sg && size > 0;
157 i++, sg = sg_next(sg)) {
158 struct p2m_desc *desc = &pdesc[idx];
159 u32 sg_len = sg_dma_len(sg);
160 u32 len;
161
162 if (sg_off >= sg_len) {
163 sg_off -= sg_len;
164 continue;
165 }
166
167 sg_len -= sg_off;
168 len = min(sg_len, size);
169
170 solo_p2m_push_desc(desc, wr, sg_dma_address(sg) + sg_off,
171 ext_addr, len, 0, 0);
172
173 size -= len;
174 ext_addr += len;
175 idx++;
176
177 sg_off = 0;
178 }
179
180 WARN_ON_ONCE(size || i >= SOLO_NR_P2M_DESC);
181
182 return solo_p2m_dma_desc(solo_dev, id, pdesc, idx);
183}
184
185#ifdef SOLO_TEST_P2M
186
187#define P2M_TEST_CHAR 0xbe
188
189static unsigned long long p2m_test(struct solo_dev *solo_dev, u8 id,
190 u32 base, int size)
191{
192 u8 *wr_buf;
193 u8 *rd_buf;
194 int i;
195 unsigned long long err_cnt = 0;
196
197 wr_buf = kmalloc(size, GFP_KERNEL);
198 if (!wr_buf) {
199 printk(SOLO6X10_NAME ": Failed to malloc for p2m_test\n");
200 return size;
201 }
202
203 rd_buf = kmalloc(size, GFP_KERNEL);
204 if (!rd_buf) {
205 printk(SOLO6X10_NAME ": Failed to malloc for p2m_test\n");
206 kfree(wr_buf);
207 return size;
208 }
209
210 memset(wr_buf, P2M_TEST_CHAR, size);
211 memset(rd_buf, P2M_TEST_CHAR + 1, size);
212
213 solo_p2m_dma(solo_dev, id, 1, wr_buf, base, size);
214 solo_p2m_dma(solo_dev, id, 0, rd_buf, base, size);
215
216 for (i = 0; i < size; i++)
217 if (wr_buf[i] != rd_buf[i])
218 err_cnt++;
219
220 kfree(wr_buf);
221 kfree(rd_buf);
222
223 return err_cnt;
224}
225
226#define TEST_CHUNK_SIZE (8 * 1024)
227
228static void run_p2m_test(struct solo_dev *solo_dev)
229{
230 unsigned long long errs = 0;
231 u32 size = SOLO_JPEG_EXT_ADDR(solo_dev) + SOLO_JPEG_EXT_SIZE(solo_dev);
232 int i, d;
233
234 dev_warn(&solo_dev->pdev->dev, "Testing %u bytes of external ram\n",
235 size);
236
237 for (i = 0; i < size; i += TEST_CHUNK_SIZE)
238 for (d = 0; d < 4; d++)
239 errs += p2m_test(solo_dev, d, i, TEST_CHUNK_SIZE);
240
241 dev_warn(&solo_dev->pdev->dev, "Found %llu errors during p2m test\n",
242 errs);
243
244 return;
245}
246#else
247#define run_p2m_test(__solo) do {} while (0)
248#endif
249
250void solo_p2m_isr(struct solo_dev *solo_dev, int id)
251{
252 struct solo_p2m_dev *p2m_dev = &solo_dev->p2m_dev[id];
253
254 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_P2M(id));
255
256 complete(&p2m_dev->completion);
257}
258
259void solo_p2m_error_isr(struct solo_dev *solo_dev, u32 status)
260{
261 struct solo_p2m_dev *p2m_dev;
262 int i;
263
264 if (!(status & SOLO_PCI_ERR_P2M))
265 return;
266
267 for (i = 0; i < SOLO_NR_P2M; i++) {
268 p2m_dev = &solo_dev->p2m_dev[i];
269 p2m_dev->error = 1;
270 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(i), 0);
271 complete(&p2m_dev->completion);
272 }
273}
274
275void solo_p2m_exit(struct solo_dev *solo_dev)
276{
277 int i;
278
279 for (i = 0; i < SOLO_NR_P2M; i++)
280 solo_irq_off(solo_dev, SOLO_IRQ_P2M(i));
281}
282
283int solo_p2m_init(struct solo_dev *solo_dev)
284{
285 struct solo_p2m_dev *p2m_dev;
286 int i;
287
288 for (i = 0; i < SOLO_NR_P2M; i++) {
289 p2m_dev = &solo_dev->p2m_dev[i];
290
291 mutex_init(&p2m_dev->mutex);
292 init_completion(&p2m_dev->completion);
293
294 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(i), 0);
295 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(i),
296 SOLO_P2M_CSC_16BIT_565 |
297 SOLO_P2M_DMA_INTERVAL(3) |
298 SOLO_P2M_DESC_INTR_OPT |
299 SOLO_P2M_PCI_MASTER_MODE);
300 solo_irq_on(solo_dev, SOLO_IRQ_P2M(i));
301 }
302
303 run_p2m_test(solo_dev);
304
305 return 0;
306}
diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
new file mode 100644
index 000000000000..36750205d23f
--- /dev/null
+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
@@ -0,0 +1,709 @@
1/*
2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28#include <linux/interrupt.h>
29#include <linux/videodev2.h>
30#include <linux/delay.h>
31#include <linux/sysfs.h>
32#include <linux/ktime.h>
33#include <linux/slab.h>
34
35#include "solo6x10.h"
36#include "solo6x10-tw28.h"
37
38MODULE_DESCRIPTION("Softlogic 6x10 MPEG4/H.264/G.723 CODEC V4L2/ALSA Driver");
39MODULE_AUTHOR("Bluecherry <maintainers@bluecherrydvr.com>");
40MODULE_VERSION(SOLO6X10_VERSION);
41MODULE_LICENSE("GPL");
42
43unsigned video_nr = -1;
44module_param(video_nr, uint, 0644);
45MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect (default)");
46
47static int full_eeprom; /* default is only top 64B */
48module_param(full_eeprom, uint, 0644);
49MODULE_PARM_DESC(full_eeprom, "Allow access to full 128B EEPROM (dangerous)");
50
51
52static void solo_set_time(struct solo_dev *solo_dev)
53{
54 struct timespec ts;
55
56 ktime_get_ts(&ts);
57
58 solo_reg_write(solo_dev, SOLO_TIMER_SEC, ts.tv_sec);
59 solo_reg_write(solo_dev, SOLO_TIMER_USEC, ts.tv_nsec / NSEC_PER_USEC);
60}
61
62static void solo_timer_sync(struct solo_dev *solo_dev)
63{
64 u32 sec, usec;
65 struct timespec ts;
66 long diff;
67
68 if (solo_dev->type != SOLO_DEV_6110)
69 return;
70
71 if (++solo_dev->time_sync < 60)
72 return;
73
74 solo_dev->time_sync = 0;
75
76 sec = solo_reg_read(solo_dev, SOLO_TIMER_SEC);
77 usec = solo_reg_read(solo_dev, SOLO_TIMER_USEC);
78
79 ktime_get_ts(&ts);
80
81 diff = (long)ts.tv_sec - (long)sec;
82 diff = (diff * 1000000)
83 + ((long)(ts.tv_nsec / NSEC_PER_USEC) - (long)usec);
84
85 if (diff > 1000 || diff < -1000) {
86 solo_set_time(solo_dev);
87 } else if (diff) {
88 long usec_lsb = solo_dev->usec_lsb;
89
90 usec_lsb -= diff / 4;
91 if (usec_lsb < 0)
92 usec_lsb = 0;
93 else if (usec_lsb > 255)
94 usec_lsb = 255;
95
96 solo_dev->usec_lsb = usec_lsb;
97 solo_reg_write(solo_dev, SOLO_TIMER_USEC_LSB,
98 solo_dev->usec_lsb);
99 }
100}
101
102static irqreturn_t solo_isr(int irq, void *data)
103{
104 struct solo_dev *solo_dev = data;
105 u32 status;
106 int i;
107
108 status = solo_reg_read(solo_dev, SOLO_IRQ_STAT);
109 if (!status)
110 return IRQ_NONE;
111
112 if (status & ~solo_dev->irq_mask) {
113 solo_reg_write(solo_dev, SOLO_IRQ_STAT,
114 status & ~solo_dev->irq_mask);
115 status &= solo_dev->irq_mask;
116 }
117
118 if (status & SOLO_IRQ_PCI_ERR)
119 solo_p2m_error_isr(solo_dev);
120
121 for (i = 0; i < SOLO_NR_P2M; i++)
122 if (status & SOLO_IRQ_P2M(i))
123 solo_p2m_isr(solo_dev, i);
124
125 if (status & SOLO_IRQ_IIC)
126 solo_i2c_isr(solo_dev);
127
128 if (status & SOLO_IRQ_VIDEO_IN) {
129 solo_video_in_isr(solo_dev);
130 solo_timer_sync(solo_dev);
131 }
132
133 if (status & SOLO_IRQ_ENCODER)
134 solo_enc_v4l2_isr(solo_dev);
135
136 if (status & SOLO_IRQ_G723)
137 solo_g723_isr(solo_dev);
138
139 /* Clear all interrupts handled */
140 solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);
141
142 return IRQ_HANDLED;
143}
144
145static void free_solo_dev(struct solo_dev *solo_dev)
146{
147 struct pci_dev *pdev;
148
149 if (!solo_dev)
150 return;
151
152 if (solo_dev->dev.parent)
153 device_unregister(&solo_dev->dev);
154
155 pdev = solo_dev->pdev;
156
157 /* If we never initialized the PCI device, then nothing else
158 * below here needs cleanup */
159 if (!pdev) {
160 kfree(solo_dev);
161 return;
162 }
163
164 if (solo_dev->reg_base) {
165 /* Bring down the sub-devices first */
166 solo_g723_exit(solo_dev);
167 solo_enc_v4l2_exit(solo_dev);
168 solo_enc_exit(solo_dev);
169 solo_v4l2_exit(solo_dev);
170 solo_disp_exit(solo_dev);
171 solo_gpio_exit(solo_dev);
172 solo_p2m_exit(solo_dev);
173 solo_i2c_exit(solo_dev);
174
175 /* Now cleanup the PCI device */
176 solo_irq_off(solo_dev, ~0);
177 pci_iounmap(pdev, solo_dev->reg_base);
178 if (pdev->irq)
179 free_irq(pdev->irq, solo_dev);
180 }
181
182 pci_release_regions(pdev);
183 pci_disable_device(pdev);
184 v4l2_device_unregister(&solo_dev->v4l2_dev);
185 pci_set_drvdata(pdev, NULL);
186
187 kfree(solo_dev);
188}
189
190static ssize_t eeprom_store(struct device *dev, struct device_attribute *attr,
191 const char *buf, size_t count)
192{
193 struct solo_dev *solo_dev =
194 container_of(dev, struct solo_dev, dev);
195 unsigned short *p = (unsigned short *)buf;
196 int i;
197
198 if (count & 0x1)
199 dev_warn(dev, "EEPROM Write not aligned (truncating)\n");
200
201 if (!full_eeprom && count > 64) {
202 dev_warn(dev, "EEPROM Write truncated to 64 bytes\n");
203 count = 64;
204 } else if (full_eeprom && count > 128) {
205 dev_warn(dev, "EEPROM Write truncated to 128 bytes\n");
206 count = 128;
207 }
208
209 solo_eeprom_ewen(solo_dev, 1);
210
211 for (i = full_eeprom ? 0 : 32; i < min((int)(full_eeprom ? 64 : 32),
212 (int)(count / 2)); i++)
213 solo_eeprom_write(solo_dev, i, cpu_to_be16(p[i]));
214
215 solo_eeprom_ewen(solo_dev, 0);
216
217 return count;
218}
219
220static ssize_t eeprom_show(struct device *dev, struct device_attribute *attr,
221 char *buf)
222{
223 struct solo_dev *solo_dev =
224 container_of(dev, struct solo_dev, dev);
225 unsigned short *p = (unsigned short *)buf;
226 int count = (full_eeprom ? 128 : 64);
227 int i;
228
229 for (i = (full_eeprom ? 0 : 32); i < (count / 2); i++)
230 p[i] = be16_to_cpu(solo_eeprom_read(solo_dev, i));
231
232 return count;
233}
234
235static ssize_t p2m_timeouts_show(struct device *dev,
236 struct device_attribute *attr,
237 char *buf)
238{
239 struct solo_dev *solo_dev =
240 container_of(dev, struct solo_dev, dev);
241
242 return sprintf(buf, "%d\n", solo_dev->p2m_timeouts);
243}
244
245static ssize_t sdram_size_show(struct device *dev,
246 struct device_attribute *attr,
247 char *buf)
248{
249 struct solo_dev *solo_dev =
250 container_of(dev, struct solo_dev, dev);
251
252 return sprintf(buf, "%dMegs\n", solo_dev->sdram_size >> 20);
253}
254
255static ssize_t tw28xx_show(struct device *dev,
256 struct device_attribute *attr,
257 char *buf)
258{
259 struct solo_dev *solo_dev =
260 container_of(dev, struct solo_dev, dev);
261
262 return sprintf(buf, "tw2815[%d] tw2864[%d] tw2865[%d]\n",
263 hweight32(solo_dev->tw2815),
264 hweight32(solo_dev->tw2864),
265 hweight32(solo_dev->tw2865));
266}
267
268static ssize_t input_map_show(struct device *dev,
269 struct device_attribute *attr,
270 char *buf)
271{
272 struct solo_dev *solo_dev =
273 container_of(dev, struct solo_dev, dev);
274 unsigned int val;
275 char *out = buf;
276
277 val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_0);
278 out += sprintf(out, "Channel 0 => Input %d\n", val & 0x1f);
279 out += sprintf(out, "Channel 1 => Input %d\n", (val >> 5) & 0x1f);
280 out += sprintf(out, "Channel 2 => Input %d\n", (val >> 10) & 0x1f);
281 out += sprintf(out, "Channel 3 => Input %d\n", (val >> 15) & 0x1f);
282 out += sprintf(out, "Channel 4 => Input %d\n", (val >> 20) & 0x1f);
283 out += sprintf(out, "Channel 5 => Input %d\n", (val >> 25) & 0x1f);
284
285 val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_1);
286 out += sprintf(out, "Channel 6 => Input %d\n", val & 0x1f);
287 out += sprintf(out, "Channel 7 => Input %d\n", (val >> 5) & 0x1f);
288 out += sprintf(out, "Channel 8 => Input %d\n", (val >> 10) & 0x1f);
289 out += sprintf(out, "Channel 9 => Input %d\n", (val >> 15) & 0x1f);
290 out += sprintf(out, "Channel 10 => Input %d\n", (val >> 20) & 0x1f);
291 out += sprintf(out, "Channel 11 => Input %d\n", (val >> 25) & 0x1f);
292
293 val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_2);
294 out += sprintf(out, "Channel 12 => Input %d\n", val & 0x1f);
295 out += sprintf(out, "Channel 13 => Input %d\n", (val >> 5) & 0x1f);
296 out += sprintf(out, "Channel 14 => Input %d\n", (val >> 10) & 0x1f);
297 out += sprintf(out, "Channel 15 => Input %d\n", (val >> 15) & 0x1f);
298 out += sprintf(out, "Spot Output => Input %d\n", (val >> 20) & 0x1f);
299
300 return out - buf;
301}
302
303static ssize_t p2m_timeout_store(struct device *dev,
304 struct device_attribute *attr,
305 const char *buf, size_t count)
306{
307 struct solo_dev *solo_dev =
308 container_of(dev, struct solo_dev, dev);
309 unsigned long ms;
310
311 int ret = kstrtoul(buf, 10, &ms);
312 if (ret < 0 || ms > 200)
313 return -EINVAL;
314 solo_dev->p2m_jiffies = msecs_to_jiffies(ms);
315
316 return count;
317}
318
319static ssize_t p2m_timeout_show(struct device *dev,
320 struct device_attribute *attr,
321 char *buf)
322{
323 struct solo_dev *solo_dev =
324 container_of(dev, struct solo_dev, dev);
325
326 return sprintf(buf, "%ums\n", jiffies_to_msecs(solo_dev->p2m_jiffies));
327}
328
329static ssize_t intervals_show(struct device *dev,
330 struct device_attribute *attr,
331 char *buf)
332{
333 struct solo_dev *solo_dev =
334 container_of(dev, struct solo_dev, dev);
335 char *out = buf;
336 int fps = solo_dev->fps;
337 int i;
338
339 for (i = 0; i < solo_dev->nr_chans; i++) {
340 out += sprintf(out, "Channel %d: %d/%d (0x%08x)\n",
341 i, solo_dev->v4l2_enc[i]->interval, fps,
342 solo_reg_read(solo_dev, SOLO_CAP_CH_INTV(i)));
343 }
344
345 return out - buf;
346}
347
348static ssize_t sdram_offsets_show(struct device *dev,
349 struct device_attribute *attr,
350 char *buf)
351{
352 struct solo_dev *solo_dev =
353 container_of(dev, struct solo_dev, dev);
354 char *out = buf;
355
356 out += sprintf(out, "DISP: 0x%08x @ 0x%08x\n",
357 SOLO_DISP_EXT_ADDR,
358 SOLO_DISP_EXT_SIZE);
359
360 out += sprintf(out, "EOSD: 0x%08x @ 0x%08x (0x%08x * %d)\n",
361 SOLO_EOSD_EXT_ADDR,
362 SOLO_EOSD_EXT_AREA(solo_dev),
363 SOLO_EOSD_EXT_SIZE(solo_dev),
364 SOLO_EOSD_EXT_AREA(solo_dev) /
365 SOLO_EOSD_EXT_SIZE(solo_dev));
366
367 out += sprintf(out, "MOTI: 0x%08x @ 0x%08x\n",
368 SOLO_MOTION_EXT_ADDR(solo_dev),
369 SOLO_MOTION_EXT_SIZE);
370
371 out += sprintf(out, "G723: 0x%08x @ 0x%08x\n",
372 SOLO_G723_EXT_ADDR(solo_dev),
373 SOLO_G723_EXT_SIZE);
374
375 out += sprintf(out, "CAPT: 0x%08x @ 0x%08x (0x%08x * %d)\n",
376 SOLO_CAP_EXT_ADDR(solo_dev),
377 SOLO_CAP_EXT_SIZE(solo_dev),
378 SOLO_CAP_PAGE_SIZE,
379 SOLO_CAP_EXT_SIZE(solo_dev) / SOLO_CAP_PAGE_SIZE);
380
381 out += sprintf(out, "EREF: 0x%08x @ 0x%08x (0x%08x * %d)\n",
382 SOLO_EREF_EXT_ADDR(solo_dev),
383 SOLO_EREF_EXT_AREA(solo_dev),
384 SOLO_EREF_EXT_SIZE,
385 SOLO_EREF_EXT_AREA(solo_dev) / SOLO_EREF_EXT_SIZE);
386
387 out += sprintf(out, "MPEG: 0x%08x @ 0x%08x\n",
388 SOLO_MP4E_EXT_ADDR(solo_dev),
389 SOLO_MP4E_EXT_SIZE(solo_dev));
390
391 out += sprintf(out, "JPEG: 0x%08x @ 0x%08x\n",
392 SOLO_JPEG_EXT_ADDR(solo_dev),
393 SOLO_JPEG_EXT_SIZE(solo_dev));
394
395 return out - buf;
396}
397
398static ssize_t sdram_show(struct file *file, struct kobject *kobj,
399 struct bin_attribute *a, char *buf,
400 loff_t off, size_t count)
401{
402 struct device *dev = container_of(kobj, struct device, kobj);
403 struct solo_dev *solo_dev =
404 container_of(dev, struct solo_dev, dev);
405 const int size = solo_dev->sdram_size;
406
407 if (off >= size)
408 return 0;
409
410 if (off + count > size)
411 count = size - off;
412
413 if (solo_p2m_dma(solo_dev, 0, buf, off, count, 0, 0))
414 return -EIO;
415
416 return count;
417}
418
419static const struct device_attribute solo_dev_attrs[] = {
420 __ATTR(eeprom, 0640, eeprom_show, eeprom_store),
421 __ATTR(p2m_timeout, 0644, p2m_timeout_show, p2m_timeout_store),
422 __ATTR_RO(p2m_timeouts),
423 __ATTR_RO(sdram_size),
424 __ATTR_RO(tw28xx),
425 __ATTR_RO(input_map),
426 __ATTR_RO(intervals),
427 __ATTR_RO(sdram_offsets),
428};
429
430static void solo_device_release(struct device *dev)
431{
432 /* Do nothing */
433}
434
435static int solo_sysfs_init(struct solo_dev *solo_dev)
436{
437 struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
438 struct device *dev = &solo_dev->dev;
439 const char *driver;
440 int i;
441
442 if (solo_dev->type == SOLO_DEV_6110)
443 driver = "solo6110";
444 else
445 driver = "solo6010";
446
447 dev->release = solo_device_release;
448 dev->parent = &solo_dev->pdev->dev;
449 set_dev_node(dev, dev_to_node(&solo_dev->pdev->dev));
450 dev_set_name(dev, "%s-%d-%d", driver, solo_dev->vfd->num,
451 solo_dev->nr_chans);
452
453 if (device_register(dev)) {
454 dev->parent = NULL;
455 return -ENOMEM;
456 }
457
458 for (i = 0; i < ARRAY_SIZE(solo_dev_attrs); i++) {
459 if (device_create_file(dev, &solo_dev_attrs[i])) {
460 device_unregister(dev);
461 return -ENOMEM;
462 }
463 }
464
465 sysfs_attr_init(&sdram_attr->attr);
466 sdram_attr->attr.name = "sdram";
467 sdram_attr->attr.mode = 0440;
468 sdram_attr->read = sdram_show;
469 sdram_attr->size = solo_dev->sdram_size;
470
471 if (device_create_bin_file(dev, sdram_attr)) {
472 device_unregister(dev);
473 return -ENOMEM;
474 }
475
476 return 0;
477}
478
479static int solo_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
480{
481 struct solo_dev *solo_dev;
482 int ret;
483 u8 chip_id;
484
485 solo_dev = kzalloc(sizeof(*solo_dev), GFP_KERNEL);
486 if (solo_dev == NULL)
487 return -ENOMEM;
488
489 if (id->driver_data == SOLO_DEV_6010)
490 dev_info(&pdev->dev, "Probing Softlogic 6010\n");
491 else
492 dev_info(&pdev->dev, "Probing Softlogic 6110\n");
493
494 solo_dev->type = id->driver_data;
495 solo_dev->pdev = pdev;
496 spin_lock_init(&solo_dev->reg_io_lock);
497 ret = v4l2_device_register(&pdev->dev, &solo_dev->v4l2_dev);
498 if (ret)
499 goto fail_probe;
500
501 /* Only for during init */
502 solo_dev->p2m_jiffies = msecs_to_jiffies(100);
503
504 ret = pci_enable_device(pdev);
505 if (ret)
506 goto fail_probe;
507
508 pci_set_master(pdev);
509
510 /* RETRY/TRDY Timeout disabled */
511 pci_write_config_byte(pdev, 0x40, 0x00);
512 pci_write_config_byte(pdev, 0x41, 0x00);
513
514 ret = pci_request_regions(pdev, SOLO6X10_NAME);
515 if (ret)
516 goto fail_probe;
517
518 solo_dev->reg_base = pci_ioremap_bar(pdev, 0);
519 if (solo_dev->reg_base == NULL) {
520 ret = -ENOMEM;
521 goto fail_probe;
522 }
523
524 chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) &
525 SOLO_CHIP_ID_MASK;
526 switch (chip_id) {
527 case 7:
528 solo_dev->nr_chans = 16;
529 solo_dev->nr_ext = 5;
530 break;
531 case 6:
532 solo_dev->nr_chans = 8;
533 solo_dev->nr_ext = 2;
534 break;
535 default:
536 dev_warn(&pdev->dev, "Invalid chip_id 0x%02x, assuming 4 ch\n",
537 chip_id);
538 case 5:
539 solo_dev->nr_chans = 4;
540 solo_dev->nr_ext = 1;
541 }
542
543 /* Disable all interrupts to start */
544 solo_irq_off(solo_dev, ~0);
545
546 /* Initial global settings */
547 if (solo_dev->type == SOLO_DEV_6010) {
548 solo_dev->clock_mhz = 108;
549 solo_dev->sys_config = SOLO_SYS_CFG_SDRAM64BIT
550 | SOLO_SYS_CFG_INPUTDIV(25)
551 | SOLO_SYS_CFG_FEEDBACKDIV(solo_dev->clock_mhz * 2 - 2)
552 | SOLO_SYS_CFG_OUTDIV(3);
553 solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
554 } else {
555 u32 divq, divf;
556
557 solo_dev->clock_mhz = 135;
558
559 if (solo_dev->clock_mhz < 125) {
560 divq = 3;
561 divf = (solo_dev->clock_mhz * 4) / 3 - 1;
562 } else {
563 divq = 2;
564 divf = (solo_dev->clock_mhz * 2) / 3 - 1;
565 }
566
567 solo_reg_write(solo_dev, SOLO_PLL_CONFIG,
568 (1 << 20) | /* PLL_RANGE */
569 (8 << 15) | /* PLL_DIVR */
570 (divq << 12) |
571 (divf << 4) |
572 (1 << 1) /* PLL_FSEN */);
573
574 solo_dev->sys_config = SOLO_SYS_CFG_SDRAM64BIT;
575 }
576
577 solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
578 solo_reg_write(solo_dev, SOLO_TIMER_CLOCK_NUM,
579 solo_dev->clock_mhz - 1);
580
581 /* PLL locking time of 1ms */
582 mdelay(1);
583
584 ret = request_irq(pdev->irq, solo_isr, IRQF_SHARED, SOLO6X10_NAME,
585 solo_dev);
586 if (ret)
587 goto fail_probe;
588
589 /* Handle this from the start */
590 solo_irq_on(solo_dev, SOLO_IRQ_PCI_ERR);
591
592 ret = solo_i2c_init(solo_dev);
593 if (ret)
594 goto fail_probe;
595
596 /* Setup the DMA engine */
597 solo_reg_write(solo_dev, SOLO_DMA_CTRL,
598 SOLO_DMA_CTRL_REFRESH_CYCLE(1) |
599 SOLO_DMA_CTRL_SDRAM_SIZE(2) |
600 SOLO_DMA_CTRL_SDRAM_CLK_INVERT |
601 SOLO_DMA_CTRL_READ_CLK_SELECT |
602 SOLO_DMA_CTRL_LATENCY(1));
603
604 /* Undocumented crap */
605 solo_reg_write(solo_dev, SOLO_DMA_CTRL1,
606 solo_dev->type == SOLO_DEV_6010 ? 0x100 : 0x300);
607
608 if (solo_dev->type != SOLO_DEV_6010) {
609 solo_dev->usec_lsb = 0x3f;
610 solo_set_time(solo_dev);
611 }
612
613 /* Disable watchdog */
614 solo_reg_write(solo_dev, SOLO_WATCHDOG, 0);
615
616 /* Initialize sub components */
617
618 ret = solo_p2m_init(solo_dev);
619 if (ret)
620 goto fail_probe;
621
622 ret = solo_disp_init(solo_dev);
623 if (ret)
624 goto fail_probe;
625
626 ret = solo_gpio_init(solo_dev);
627 if (ret)
628 goto fail_probe;
629
630 ret = solo_tw28_init(solo_dev);
631 if (ret)
632 goto fail_probe;
633
634 ret = solo_v4l2_init(solo_dev, video_nr);
635 if (ret)
636 goto fail_probe;
637
638 ret = solo_enc_init(solo_dev);
639 if (ret)
640 goto fail_probe;
641
642 ret = solo_enc_v4l2_init(solo_dev, video_nr);
643 if (ret)
644 goto fail_probe;
645
646 ret = solo_g723_init(solo_dev);
647 if (ret)
648 goto fail_probe;
649
650 ret = solo_sysfs_init(solo_dev);
651 if (ret)
652 goto fail_probe;
653
654 /* Now that init is over, set this lower */
655 solo_dev->p2m_jiffies = msecs_to_jiffies(20);
656
657 return 0;
658
659fail_probe:
660 free_solo_dev(solo_dev);
661 return ret;
662}
663
664static void solo_pci_remove(struct pci_dev *pdev)
665{
666 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
667 struct solo_dev *solo_dev = container_of(v4l2_dev, struct solo_dev, v4l2_dev);
668
669 free_solo_dev(solo_dev);
670}
671
672static DEFINE_PCI_DEVICE_TABLE(solo_id_table) = {
673 /* 6010 based cards */
674 { PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6010),
675 .driver_data = SOLO_DEV_6010 },
676 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_4),
677 .driver_data = SOLO_DEV_6010 },
678 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_9),
679 .driver_data = SOLO_DEV_6010 },
680 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_16),
681 .driver_data = SOLO_DEV_6010 },
682 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_4),
683 .driver_data = SOLO_DEV_6010 },
684 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_9),
685 .driver_data = SOLO_DEV_6010 },
686 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_16),
687 .driver_data = SOLO_DEV_6010 },
688 /* 6110 based cards */
689 { PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6110),
690 .driver_data = SOLO_DEV_6110 },
691 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_4),
692 .driver_data = SOLO_DEV_6110 },
693 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_8),
694 .driver_data = SOLO_DEV_6110 },
695 { PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_16),
696 .driver_data = SOLO_DEV_6110 },
697 {0,}
698};
699
700MODULE_DEVICE_TABLE(pci, solo_id_table);
701
702static struct pci_driver solo_pci_driver = {
703 .name = SOLO6X10_NAME,
704 .id_table = solo_id_table,
705 .probe = solo_pci_probe,
706 .remove = solo_pci_remove,
707};
708
709module_pci_driver(solo_pci_driver);
diff --git a/drivers/staging/media/solo6x10/disp.c b/drivers/staging/media/solo6x10/solo6x10-disp.c
index 884c0eb757c4..32d9953bc36e 100644
--- a/drivers/staging/media/solo6x10/disp.c
+++ b/drivers/staging/media/solo6x10/solo6x10-disp.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -21,6 +26,7 @@
21#include <linux/module.h> 26#include <linux/module.h>
22#include <linux/videodev2.h> 27#include <linux/videodev2.h>
23#include <media/v4l2-ioctl.h> 28#include <media/v4l2-ioctl.h>
29
24#include "solo6x10.h" 30#include "solo6x10.h"
25 31
26#define SOLO_VCLK_DELAY 3 32#define SOLO_VCLK_DELAY 3
@@ -30,12 +36,8 @@
30#define SOLO_MOT_THRESH_H 64 36#define SOLO_MOT_THRESH_H 64
31#define SOLO_MOT_THRESH_SIZE 8192 37#define SOLO_MOT_THRESH_SIZE 8192
32#define SOLO_MOT_THRESH_REAL (SOLO_MOT_THRESH_W * SOLO_MOT_THRESH_H) 38#define SOLO_MOT_THRESH_REAL (SOLO_MOT_THRESH_W * SOLO_MOT_THRESH_H)
33#define SOLO_MOT_FLAG_SIZE 512 39#define SOLO_MOT_FLAG_SIZE 1024
34#define SOLO_MOT_FLAG_AREA (SOLO_MOT_FLAG_SIZE * 32) 40#define SOLO_MOT_FLAG_AREA (SOLO_MOT_FLAG_SIZE * 16)
35
36static unsigned video_type;
37module_param(video_type, uint, 0644);
38MODULE_PARM_DESC(video_type, "video_type (0 = NTSC/Default, 1 = PAL)");
39 41
40static void solo_vin_config(struct solo_dev *solo_dev) 42static void solo_vin_config(struct solo_dev *solo_dev)
41{ 43{
@@ -73,7 +75,12 @@ static void solo_vin_config(struct solo_dev *solo_dev)
73 solo_reg_write(solo_dev, SOLO_VI_CH_FORMAT, 75 solo_reg_write(solo_dev, SOLO_VI_CH_FORMAT,
74 SOLO_VI_FD_SEL_MASK(0) | SOLO_VI_PROG_MASK(0)); 76 SOLO_VI_FD_SEL_MASK(0) | SOLO_VI_PROG_MASK(0));
75 77
76 solo_reg_write(solo_dev, SOLO_VI_FMT_CFG, 0); 78 /* On 6110, initialize mozaic darkness stength */
79 if (solo_dev->type == SOLO_DEV_6010)
80 solo_reg_write(solo_dev, SOLO_VI_FMT_CFG, 0);
81 else
82 solo_reg_write(solo_dev, SOLO_VI_FMT_CFG, 16 << 22);
83
77 solo_reg_write(solo_dev, SOLO_VI_PAGE_SW, 2); 84 solo_reg_write(solo_dev, SOLO_VI_PAGE_SW, 2);
78 85
79 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) { 86 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
@@ -97,21 +104,30 @@ static void solo_vin_config(struct solo_dev *solo_dev)
97 SOLO_VI_PB_HSTOP(16 + 720)); 104 SOLO_VI_PB_HSTOP(16 + 720));
98} 105}
99 106
100static void solo_disp_config(struct solo_dev *solo_dev) 107static void solo_vout_config_cursor(struct solo_dev *dev)
108{
109 int i;
110
111 /* Load (blank) cursor bitmap mask (2bpp) */
112 for (i = 0; i < 20; i++)
113 solo_reg_write(dev, SOLO_VO_CURSOR_MASK(i), 0);
114
115 solo_reg_write(dev, SOLO_VO_CURSOR_POS, 0);
116
117 solo_reg_write(dev, SOLO_VO_CURSOR_CLR,
118 (0x80 << 24) | (0x80 << 16) | (0x10 << 8) | 0x80);
119 solo_reg_write(dev, SOLO_VO_CURSOR_CLR2, (0xe0 << 8) | 0x80);
120}
121
122static void solo_vout_config(struct solo_dev *solo_dev)
101{ 123{
102 solo_dev->vout_hstart = 6; 124 solo_dev->vout_hstart = 6;
103 solo_dev->vout_vstart = 8; 125 solo_dev->vout_vstart = 8;
104 126
105 solo_reg_write(solo_dev, SOLO_VO_BORDER_LINE_COLOR,
106 (0xa0 << 24) | (0x88 << 16) | (0xa0 << 8) | 0x88);
107 solo_reg_write(solo_dev, SOLO_VO_BORDER_FILL_COLOR,
108 (0x10 << 24) | (0x8f << 16) | (0x10 << 8) | 0x8f);
109 solo_reg_write(solo_dev, SOLO_VO_BKG_COLOR,
110 (16 << 24) | (128 << 16) | (16 << 8) | 128);
111
112 solo_reg_write(solo_dev, SOLO_VO_FMT_ENC, 127 solo_reg_write(solo_dev, SOLO_VO_FMT_ENC,
113 solo_dev->video_type | 128 solo_dev->video_type |
114 SOLO_VO_USER_COLOR_SET_NAV | 129 SOLO_VO_USER_COLOR_SET_NAV |
130 SOLO_VO_USER_COLOR_SET_NAH |
115 SOLO_VO_NA_COLOR_Y(0) | 131 SOLO_VO_NA_COLOR_Y(0) |
116 SOLO_VO_NA_COLOR_CB(0) | 132 SOLO_VO_NA_COLOR_CB(0) |
117 SOLO_VO_NA_COLOR_CR(0)); 133 SOLO_VO_NA_COLOR_CR(0));
@@ -130,19 +146,31 @@ static void solo_disp_config(struct solo_dev *solo_dev)
130 SOLO_VO_H_LEN(solo_dev->video_hsize) | 146 SOLO_VO_H_LEN(solo_dev->video_hsize) |
131 SOLO_VO_V_LEN(solo_dev->video_vsize)); 147 SOLO_VO_V_LEN(solo_dev->video_vsize));
132 148
133 solo_reg_write(solo_dev, SOLO_VI_WIN_SW, 5); 149 /* Border & background colors */
150 solo_reg_write(solo_dev, SOLO_VO_BORDER_LINE_COLOR,
151 (0xa0 << 24) | (0x88 << 16) | (0xa0 << 8) | 0x88);
152 solo_reg_write(solo_dev, SOLO_VO_BORDER_FILL_COLOR,
153 (0x10 << 24) | (0x8f << 16) | (0x10 << 8) | 0x8f);
154 solo_reg_write(solo_dev, SOLO_VO_BKG_COLOR,
155 (16 << 24) | (128 << 16) | (16 << 8) | 128);
156
157 solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, SOLO_VO_DISP_ERASE_ON);
158
159 solo_reg_write(solo_dev, SOLO_VI_WIN_SW, 0);
160
161 solo_reg_write(solo_dev, SOLO_VO_ZOOM_CTRL, 0);
162 solo_reg_write(solo_dev, SOLO_VO_FREEZE_CTRL, 0);
134 163
135 solo_reg_write(solo_dev, SOLO_VO_DISP_CTRL, SOLO_VO_DISP_ON | 164 solo_reg_write(solo_dev, SOLO_VO_DISP_CTRL, SOLO_VO_DISP_ON |
136 SOLO_VO_DISP_ERASE_COUNT(8) | 165 SOLO_VO_DISP_ERASE_COUNT(8) |
137 SOLO_VO_DISP_BASE(SOLO_DISP_EXT_ADDR)); 166 SOLO_VO_DISP_BASE(SOLO_DISP_EXT_ADDR));
138 167
139 solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, SOLO_VO_DISP_ERASE_ON);
140 168
141 /* Enable channels we support */ 169 solo_vout_config_cursor(solo_dev);
142 solo_reg_write(solo_dev, SOLO_VI_CH_ENA, (1 << solo_dev->nr_chans) - 1);
143 170
144 /* Disable the watchdog */ 171 /* Enable channels we support */
145 solo_reg_write(solo_dev, SOLO_WATCHDOG, 0); 172 solo_reg_write(solo_dev, SOLO_VI_CH_ENA,
173 (1 << solo_dev->nr_chans) - 1);
146} 174}
147 175
148static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off, 176static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off,
@@ -153,29 +181,48 @@ static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off,
153 int ret = 0; 181 int ret = 0;
154 182
155 for (i = 0; i < sizeof(buf) >> 1; i++) 183 for (i = 0; i < sizeof(buf) >> 1; i++)
156 buf[i] = val; 184 buf[i] = cpu_to_le16(val);
157 185
158 for (i = 0; i < reg_size; i += sizeof(buf)) 186 for (i = 0; i < reg_size; i += sizeof(buf))
159 ret |= solo_p2m_dma(solo_dev, SOLO_P2M_DMA_ID_VIN, 1, buf, 187 ret |= solo_p2m_dma(solo_dev, 1, buf,
160 SOLO_MOTION_EXT_ADDR(solo_dev) + off + i, 188 SOLO_MOTION_EXT_ADDR(solo_dev) + off + i,
161 sizeof(buf)); 189 sizeof(buf), 0, 0);
162 190
163 return ret; 191 return ret;
164} 192}
165 193
166void solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val) 194int solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val)
167{ 195{
168 if (ch > solo_dev->nr_chans) 196 if (ch > solo_dev->nr_chans)
169 return; 197 return -EINVAL;
170 198
171 solo_dma_vin_region(solo_dev, SOLO_MOT_FLAG_AREA + 199 return solo_dma_vin_region(solo_dev, SOLO_MOT_FLAG_AREA +
172 (ch * SOLO_MOT_THRESH_SIZE * 2), 200 (ch * SOLO_MOT_THRESH_SIZE * 2),
173 val, SOLO_MOT_THRESH_REAL); 201 val, SOLO_MOT_THRESH_SIZE);
202}
203
204int solo_set_motion_block(struct solo_dev *solo_dev, u8 ch,
205 const struct solo_motion_thresholds *thresholds)
206{
207 u32 off = SOLO_MOT_FLAG_AREA + ch * SOLO_MOT_THRESH_SIZE * 2;
208 u16 buf[64];
209 int x, y;
210 int ret = 0;
211
212 memset(buf, 0, sizeof(buf));
213 for (y = 0; y < SOLO_MOTION_SZ; y++) {
214 for (x = 0; x < SOLO_MOTION_SZ; x++)
215 buf[x] = cpu_to_le16(thresholds->thresholds[y][x]);
216 ret |= solo_p2m_dma(solo_dev, 1, buf,
217 SOLO_MOTION_EXT_ADDR(solo_dev) + off + y * sizeof(buf),
218 sizeof(buf), 0, 0);
219 }
220 return ret;
174} 221}
175 222
176/* First 8k is motion flag (512 bytes * 16). Following that is an 8k+8k 223/* First 8k is motion flag (512 bytes * 16). Following that is an 8k+8k
177 * threshold and working table for each channel. Atleast that's what the 224 * threshold and working table for each channel. Atleast that's what the
178 * spec says. However, this code (take from rdk) has some mystery 8k 225 * spec says. However, this code (taken from rdk) has some mystery 8k
179 * block right after the flag area, before the first thresh table. */ 226 * block right after the flag area, before the first thresh table. */
180static void solo_motion_config(struct solo_dev *solo_dev) 227static void solo_motion_config(struct solo_dev *solo_dev)
181{ 228{
@@ -188,9 +235,9 @@ static void solo_motion_config(struct solo_dev *solo_dev)
188 235
189 /* Clear working cache table */ 236 /* Clear working cache table */
190 solo_dma_vin_region(solo_dev, SOLO_MOT_FLAG_AREA + 237 solo_dma_vin_region(solo_dev, SOLO_MOT_FLAG_AREA +
191 SOLO_MOT_THRESH_SIZE + 238 (i * SOLO_MOT_THRESH_SIZE * 2) +
192 (i * SOLO_MOT_THRESH_SIZE * 2), 239 SOLO_MOT_THRESH_SIZE, 0x0000,
193 0x0000, SOLO_MOT_THRESH_REAL); 240 SOLO_MOT_THRESH_SIZE);
194 241
195 /* Set default threshold table */ 242 /* Set default threshold table */
196 solo_set_motion_threshold(solo_dev, i, SOLO_DEF_MOT_THRESH); 243 solo_set_motion_threshold(solo_dev, i, SOLO_DEF_MOT_THRESH);
@@ -202,8 +249,8 @@ static void solo_motion_config(struct solo_dev *solo_dev)
202 solo_reg_write(solo_dev, SOLO_VI_MOT_CTRL, 249 solo_reg_write(solo_dev, SOLO_VI_MOT_CTRL,
203 SOLO_VI_MOTION_FRAME_COUNT(3) | 250 SOLO_VI_MOTION_FRAME_COUNT(3) |
204 SOLO_VI_MOTION_SAMPLE_LENGTH(solo_dev->video_hsize / 16) 251 SOLO_VI_MOTION_SAMPLE_LENGTH(solo_dev->video_hsize / 16)
205 | /* SOLO_VI_MOTION_INTR_START_STOP | */ 252 /* | SOLO_VI_MOTION_INTR_START_STOP */
206 SOLO_VI_MOTION_SAMPLE_COUNT(10)); 253 | SOLO_VI_MOTION_SAMPLE_COUNT(10));
207 254
208 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0); 255 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0);
209 solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR, 0); 256 solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR, 0);
@@ -214,19 +261,17 @@ int solo_disp_init(struct solo_dev *solo_dev)
214 int i; 261 int i;
215 262
216 solo_dev->video_hsize = 704; 263 solo_dev->video_hsize = 704;
217 if (video_type == 0) { 264 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
218 solo_dev->video_type = SOLO_VO_FMT_TYPE_NTSC;
219 solo_dev->video_vsize = 240; 265 solo_dev->video_vsize = 240;
220 solo_dev->fps = 30; 266 solo_dev->fps = 30;
221 } else { 267 } else {
222 solo_dev->video_type = SOLO_VO_FMT_TYPE_PAL;
223 solo_dev->video_vsize = 288; 268 solo_dev->video_vsize = 288;
224 solo_dev->fps = 25; 269 solo_dev->fps = 25;
225 } 270 }
226 271
227 solo_vin_config(solo_dev); 272 solo_vin_config(solo_dev);
228 solo_motion_config(solo_dev); 273 solo_motion_config(solo_dev);
229 solo_disp_config(solo_dev); 274 solo_vout_config(solo_dev);
230 275
231 for (i = 0; i < solo_dev->nr_chans; i++) 276 for (i = 0; i < solo_dev->nr_chans; i++)
232 solo_reg_write(solo_dev, SOLO_VI_WIN_ON(i), 1); 277 solo_reg_write(solo_dev, SOLO_VI_WIN_ON(i), 1);
@@ -238,8 +283,6 @@ void solo_disp_exit(struct solo_dev *solo_dev)
238{ 283{
239 int i; 284 int i;
240 285
241 solo_irq_off(solo_dev, SOLO_IRQ_MOTION);
242
243 solo_reg_write(solo_dev, SOLO_VO_DISP_CTRL, 0); 286 solo_reg_write(solo_dev, SOLO_VO_DISP_CTRL, 0);
244 solo_reg_write(solo_dev, SOLO_VO_ZOOM_CTRL, 0); 287 solo_reg_write(solo_dev, SOLO_VO_ZOOM_CTRL, 0);
245 solo_reg_write(solo_dev, SOLO_VO_FREEZE_CTRL, 0); 288 solo_reg_write(solo_dev, SOLO_VO_FREEZE_CTRL, 0);
diff --git a/drivers/staging/media/solo6x10/solo6x10-eeprom.c b/drivers/staging/media/solo6x10/solo6x10-eeprom.c
new file mode 100644
index 000000000000..9d1c9bb53d6b
--- /dev/null
+++ b/drivers/staging/media/solo6x10/solo6x10-eeprom.c
@@ -0,0 +1,154 @@
1/*
2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25#include <linux/kernel.h>
26#include <linux/delay.h>
27
28#include "solo6x10.h"
29
30/* Control */
31#define EE_SHIFT_CLK 0x04
32#define EE_CS 0x08
33#define EE_DATA_WRITE 0x02
34#define EE_DATA_READ 0x01
35#define EE_ENB (0x80 | EE_CS)
36
37#define eeprom_delay() udelay(100)
38#if 0
39#define eeprom_delay() solo_reg_read(solo_dev, SOLO_EEPROM_CTRL)
40#define eeprom_delay() ({ \
41 int i, ret; \
42 udelay(100); \
43 for (i = ret = 0; i < 1000 && !ret; i++) \
44 ret = solo_eeprom_reg_read(solo_dev); \
45})
46#endif
47#define ADDR_LEN 6
48
49/* Commands */
50#define EE_EWEN_CMD 4
51#define EE_EWDS_CMD 4
52#define EE_WRITE_CMD 5
53#define EE_READ_CMD 6
54#define EE_ERASE_CMD 7
55
56static unsigned int solo_eeprom_reg_read(struct solo_dev *solo_dev)
57{
58 return solo_reg_read(solo_dev, SOLO_EEPROM_CTRL) & EE_DATA_READ;
59}
60
61static void solo_eeprom_reg_write(struct solo_dev *solo_dev, u32 data)
62{
63 solo_reg_write(solo_dev, SOLO_EEPROM_CTRL, data);
64 eeprom_delay();
65}
66
67static void solo_eeprom_cmd(struct solo_dev *solo_dev, int cmd)
68{
69 int i;
70
71 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ACCESS_EN);
72 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE);
73
74 for (i = 4 + ADDR_LEN; i >= 0; i--) {
75 int dataval = (cmd & (1 << i)) ? EE_DATA_WRITE : 0;
76
77 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE | dataval);
78 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE |
79 EE_SHIFT_CLK | dataval);
80 }
81
82 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE);
83}
84
85unsigned int solo_eeprom_ewen(struct solo_dev *solo_dev, int w_en)
86{
87 int ewen_cmd = (w_en ? 0x3f : 0) | (EE_EWEN_CMD << ADDR_LEN);
88 unsigned int retval = 0;
89 int i;
90
91 solo_eeprom_cmd(solo_dev, ewen_cmd);
92
93 for (i = 0; i < 16; i++) {
94 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE |
95 EE_SHIFT_CLK);
96 retval = (retval << 1) | solo_eeprom_reg_read(solo_dev);
97 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE);
98 retval = (retval << 1) | solo_eeprom_reg_read(solo_dev);
99 }
100
101 solo_eeprom_reg_write(solo_dev, ~EE_CS);
102 retval = (retval << 1) | solo_eeprom_reg_read(solo_dev);
103
104 return retval;
105}
106
107unsigned short solo_eeprom_read(struct solo_dev *solo_dev, int loc)
108{
109 int read_cmd = loc | (EE_READ_CMD << ADDR_LEN);
110 unsigned short retval = 0;
111 int i;
112
113 solo_eeprom_cmd(solo_dev, read_cmd);
114
115 for (i = 0; i < 16; i++) {
116 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE |
117 EE_SHIFT_CLK);
118 retval = (retval << 1) | solo_eeprom_reg_read(solo_dev);
119 solo_eeprom_reg_write(solo_dev, SOLO_EEPROM_ENABLE);
120 }
121
122 solo_eeprom_reg_write(solo_dev, ~EE_CS);
123
124 return retval;
125}
126
127int solo_eeprom_write(struct solo_dev *solo_dev, int loc,
128 unsigned short data)
129{
130 int write_cmd = loc | (EE_WRITE_CMD << ADDR_LEN);
131 unsigned int retval;
132 int i;
133
134 solo_eeprom_cmd(solo_dev, write_cmd);
135
136 for (i = 15; i >= 0; i--) {
137 unsigned int dataval = (data >> i) & 1;
138
139 solo_eeprom_reg_write(solo_dev, EE_ENB);
140 solo_eeprom_reg_write(solo_dev,
141 EE_ENB | (dataval << 1) | EE_SHIFT_CLK);
142 }
143
144 solo_eeprom_reg_write(solo_dev, EE_ENB);
145 solo_eeprom_reg_write(solo_dev, ~EE_CS);
146 solo_eeprom_reg_write(solo_dev, EE_ENB);
147
148 for (i = retval = 0; i < 10000 && !retval; i++)
149 retval = solo_eeprom_reg_read(solo_dev);
150
151 solo_eeprom_reg_write(solo_dev, ~EE_CS);
152
153 return !retval;
154}
diff --git a/drivers/staging/media/solo6x10/enc.c b/drivers/staging/media/solo6x10/solo6x10-enc.c
index de502599bb19..94d5735abf85 100644
--- a/drivers/staging/media/solo6x10/enc.c
+++ b/drivers/staging/media/solo6x10/solo6x10-enc.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -18,30 +23,41 @@
18 */ 23 */
19 24
20#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/font.h>
27#include <linux/bitrev.h>
21#include <linux/slab.h> 28#include <linux/slab.h>
22#include "solo6x10.h"
23#include "osd-font.h"
24 29
25#define CAPTURE_MAX_BANDWIDTH 32 /* D1 4channel (D1 == 4) */ 30#include "solo6x10.h"
26#define OSG_BUFFER_SIZE 1024
27 31
28#define VI_PROG_HSIZE (1280 - 16) 32#define VI_PROG_HSIZE (1280 - 16)
29#define VI_PROG_VSIZE (1024 - 16) 33#define VI_PROG_VSIZE (1024 - 16)
30 34
35#define IRQ_LEVEL 2
36
31static void solo_capture_config(struct solo_dev *solo_dev) 37static void solo_capture_config(struct solo_dev *solo_dev)
32{ 38{
33 int i, j;
34 unsigned long height; 39 unsigned long height;
35 unsigned long width; 40 unsigned long width;
36 unsigned char *buf; 41 void *buf;
42 int i;
37 43
38 solo_reg_write(solo_dev, SOLO_CAP_BASE, 44 solo_reg_write(solo_dev, SOLO_CAP_BASE,
39 SOLO_CAP_MAX_PAGE(SOLO_CAP_EXT_MAX_PAGE * 45 SOLO_CAP_MAX_PAGE((SOLO_CAP_EXT_SIZE(solo_dev)
40 solo_dev->nr_chans) | 46 - SOLO_CAP_PAGE_SIZE) >> 16)
41 SOLO_CAP_BASE_ADDR(SOLO_CAP_EXT_ADDR(solo_dev) >> 16)); 47 | SOLO_CAP_BASE_ADDR(SOLO_CAP_EXT_ADDR(solo_dev) >> 16));
42 solo_reg_write(solo_dev, SOLO_CAP_BTW, 48
43 (1 << 17) | SOLO_CAP_PROG_BANDWIDTH(2) | 49 /* XXX: Undocumented bits at b17 and b24 */
44 SOLO_CAP_MAX_BANDWIDTH(CAPTURE_MAX_BANDWIDTH)); 50 if (solo_dev->type == SOLO_DEV_6110) {
51 /* NOTE: Ref driver has (62 << 24) here as well, but it causes
52 * wacked out frame timing on 4-port 6110. */
53 solo_reg_write(solo_dev, SOLO_CAP_BTW,
54 (1 << 17) | SOLO_CAP_PROG_BANDWIDTH(2) |
55 SOLO_CAP_MAX_BANDWIDTH(36));
56 } else {
57 solo_reg_write(solo_dev, SOLO_CAP_BTW,
58 (1 << 17) | SOLO_CAP_PROG_BANDWIDTH(2) |
59 SOLO_CAP_MAX_BANDWIDTH(32));
60 }
45 61
46 /* Set scale 1, 9 dimension */ 62 /* Set scale 1, 9 dimension */
47 width = solo_dev->video_hsize; 63 width = solo_dev->video_hsize;
@@ -96,115 +112,212 @@ static void solo_capture_config(struct solo_dev *solo_dev)
96 solo_reg_write(solo_dev, SOLO_VE_OSD_BASE, SOLO_EOSD_EXT_ADDR >> 16); 112 solo_reg_write(solo_dev, SOLO_VE_OSD_BASE, SOLO_EOSD_EXT_ADDR >> 16);
97 solo_reg_write(solo_dev, SOLO_VE_OSD_CLR, 113 solo_reg_write(solo_dev, SOLO_VE_OSD_CLR,
98 0xF0 << 16 | 0x80 << 8 | 0x80); 114 0xF0 << 16 | 0x80 << 8 | 0x80);
99 solo_reg_write(solo_dev, SOLO_VE_OSD_OPT, 0); 115
116 if (solo_dev->type == SOLO_DEV_6010)
117 solo_reg_write(solo_dev, SOLO_VE_OSD_OPT,
118 SOLO_VE_OSD_H_SHADOW | SOLO_VE_OSD_V_SHADOW);
119 else
120 solo_reg_write(solo_dev, SOLO_VE_OSD_OPT, SOLO_VE_OSD_V_DOUBLE
121 | SOLO_VE_OSD_H_SHADOW | SOLO_VE_OSD_V_SHADOW);
100 122
101 /* Clear OSG buffer */ 123 /* Clear OSG buffer */
102 buf = kzalloc(OSG_BUFFER_SIZE, GFP_KERNEL); 124 buf = kzalloc(SOLO_EOSD_EXT_SIZE(solo_dev), GFP_KERNEL);
103 if (!buf) 125 if (!buf)
104 return; 126 return;
105 127
106 for (i = 0; i < solo_dev->nr_chans; i++) { 128 for (i = 0; i < solo_dev->nr_chans; i++) {
107 for (j = 0; j < SOLO_EOSD_EXT_SIZE; j += OSG_BUFFER_SIZE) { 129 solo_p2m_dma(solo_dev, 1, buf,
108 solo_p2m_dma(solo_dev, SOLO_P2M_DMA_ID_MP4E, 1, buf, 130 SOLO_EOSD_EXT_ADDR +
109 SOLO_EOSD_EXT_ADDR + 131 (SOLO_EOSD_EXT_SIZE(solo_dev) * i),
110 (i * SOLO_EOSD_EXT_SIZE) + j, 132 SOLO_EOSD_EXT_SIZE(solo_dev), 0, 0);
111 OSG_BUFFER_SIZE);
112 }
113 } 133 }
114 kfree(buf); 134 kfree(buf);
115} 135}
116 136
137/* Should be called with enable_lock held */
117int solo_osd_print(struct solo_enc_dev *solo_enc) 138int solo_osd_print(struct solo_enc_dev *solo_enc)
118{ 139{
119 struct solo_dev *solo_dev = solo_enc->solo_dev; 140 struct solo_dev *solo_dev = solo_enc->solo_dev;
120 char *str = solo_enc->osd_text; 141 unsigned char *str = solo_enc->osd_text;
121 u8 *buf; 142 u8 *buf = solo_enc->osd_buf;
122 u32 reg = solo_reg_read(solo_dev, SOLO_VE_OSD_CH); 143 u32 reg = solo_reg_read(solo_dev, SOLO_VE_OSD_CH);
123 int len = strlen(str); 144 const struct font_desc *vga = find_font("VGA8x16");
145 const unsigned char *vga_data;
146 int len;
124 int i, j; 147 int i, j;
125 int x = 1, y = 1; 148
149 if (WARN_ON_ONCE(!vga))
150 return -ENODEV;
151
152 len = strlen(str);
126 153
127 if (len == 0) { 154 if (len == 0) {
155 /* Disable OSD on this channel */
128 reg &= ~(1 << solo_enc->ch); 156 reg &= ~(1 << solo_enc->ch);
129 solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg); 157 solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg);
130 return 0; 158 return 0;
131 } 159 }
132 160
133 buf = kzalloc(SOLO_EOSD_EXT_SIZE, GFP_KERNEL); 161 memset(buf, 0, SOLO_EOSD_EXT_SIZE_MAX);
134 if (!buf) 162 vga_data = (const unsigned char *)vga->data;
135 return -ENOMEM;
136 163
137 for (i = 0; i < len; i++) { 164 for (i = 0; i < len; i++) {
165 unsigned char c = str[i];
166
138 for (j = 0; j < 16; j++) { 167 for (j = 0; j < 16; j++) {
139 buf[(j*2) + (i%2) + ((x + (i/2)) * 32) + (y * 2048)] = 168 buf[(j * 2) + (i % 2) + (i / 2 * 32)] =
140 (solo_osd_font[(str[i] * 4) + (j / 4)] 169 bitrev8(vga_data[(c * 16) + j]);
141 >> ((3 - (j % 4)) * 8)) & 0xff;
142 } 170 }
143 } 171 }
144 172
145 solo_p2m_dma(solo_dev, 0, 1, buf, SOLO_EOSD_EXT_ADDR + 173 solo_p2m_dma(solo_dev, 1, buf,
146 (solo_enc->ch * SOLO_EOSD_EXT_SIZE), SOLO_EOSD_EXT_SIZE); 174 SOLO_EOSD_EXT_ADDR +
175 (solo_enc->ch * SOLO_EOSD_EXT_SIZE(solo_dev)),
176 SOLO_EOSD_EXT_SIZE(solo_dev), 0, 0);
177
178 /* Enable OSD on this channel */
147 reg |= (1 << solo_enc->ch); 179 reg |= (1 << solo_enc->ch);
148 solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg); 180 solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg);
149 181
150 kfree(buf);
151
152 return 0; 182 return 0;
153} 183}
154 184
185/**
186 * Set channel Quality Profile (0-3).
187 */
188void solo_s_jpeg_qp(struct solo_dev *solo_dev, unsigned int ch,
189 unsigned int qp)
190{
191 unsigned long flags;
192 unsigned int idx, reg;
193
194 if ((ch > 31) || (qp > 3))
195 return;
196
197 if (solo_dev->type == SOLO_DEV_6010)
198 return;
199
200 if (ch < 16) {
201 idx = 0;
202 reg = SOLO_VE_JPEG_QP_CH_L;
203 } else {
204 ch -= 16;
205 idx = 1;
206 reg = SOLO_VE_JPEG_QP_CH_H;
207 }
208 ch *= 2;
209
210 spin_lock_irqsave(&solo_dev->jpeg_qp_lock, flags);
211
212 solo_dev->jpeg_qp[idx] &= ~(3 << ch);
213 solo_dev->jpeg_qp[idx] |= (qp & 3) << ch;
214
215 solo_reg_write(solo_dev, reg, solo_dev->jpeg_qp[idx]);
216
217 spin_unlock_irqrestore(&solo_dev->jpeg_qp_lock, flags);
218}
219
220int solo_g_jpeg_qp(struct solo_dev *solo_dev, unsigned int ch)
221{
222 int idx;
223
224 if (solo_dev->type == SOLO_DEV_6010)
225 return 2;
226
227 if (WARN_ON_ONCE(ch > 31))
228 return 2;
229
230 if (ch < 16) {
231 idx = 0;
232 } else {
233 ch -= 16;
234 idx = 1;
235 }
236 ch *= 2;
237
238 return (solo_dev->jpeg_qp[idx] >> ch) & 3;
239}
240
241#define SOLO_QP_INIT 0xaaaaaaaa
242
155static void solo_jpeg_config(struct solo_dev *solo_dev) 243static void solo_jpeg_config(struct solo_dev *solo_dev)
156{ 244{
157 u32 reg; 245 if (solo_dev->type == SOLO_DEV_6010) {
158 if (solo_dev->flags & FLAGS_6110) 246 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_TBL,
159 reg = (4 << 24) | (3 << 16) | (2 << 8) | (1 << 0); 247 (2 << 24) | (2 << 16) | (2 << 8) | 2);
160 else 248 } else {
161 reg = (2 << 24) | (2 << 16) | (2 << 8) | (2 << 0); 249 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_TBL,
162 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_TBL, reg); 250 (4 << 24) | (3 << 16) | (2 << 8) | 1);
163 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_L, 0); 251 }
164 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_H, 0); 252
253 spin_lock_init(&solo_dev->jpeg_qp_lock);
254
255 /* Initialize Quality Profile for all channels */
256 solo_dev->jpeg_qp[0] = solo_dev->jpeg_qp[1] = SOLO_QP_INIT;
257 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_L, SOLO_QP_INIT);
258 solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_H, SOLO_QP_INIT);
259
165 solo_reg_write(solo_dev, SOLO_VE_JPEG_CFG, 260 solo_reg_write(solo_dev, SOLO_VE_JPEG_CFG,
166 (SOLO_JPEG_EXT_SIZE(solo_dev) & 0xffff0000) | 261 (SOLO_JPEG_EXT_SIZE(solo_dev) & 0xffff0000) |
167 ((SOLO_JPEG_EXT_ADDR(solo_dev) >> 16) & 0x0000ffff)); 262 ((SOLO_JPEG_EXT_ADDR(solo_dev) >> 16) & 0x0000ffff));
168 solo_reg_write(solo_dev, SOLO_VE_JPEG_CTRL, 0xffffffff); 263 solo_reg_write(solo_dev, SOLO_VE_JPEG_CTRL, 0xffffffff);
169 /* que limit, samp limit, pos limit */ 264 if (solo_dev->type == SOLO_DEV_6110) {
170 solo_reg_write(solo_dev, 0x0688, (0 << 16) | (30 << 8) | 60); 265 solo_reg_write(solo_dev, SOLO_VE_JPEG_CFG1,
266 (0 << 16) | (30 << 8) | 60);
267 }
171} 268}
172 269
173static void solo_mp4e_config(struct solo_dev *solo_dev) 270static void solo_mp4e_config(struct solo_dev *solo_dev)
174{ 271{
175 int i; 272 int i;
176 u32 reg; 273 u32 cfg;
177 274
178 /* We can only use VE_INTR_CTRL(0) if we want to support mjpeg */
179 solo_reg_write(solo_dev, SOLO_VE_CFG0, 275 solo_reg_write(solo_dev, SOLO_VE_CFG0,
180 SOLO_VE_INTR_CTRL(0) | 276 SOLO_VE_INTR_CTRL(IRQ_LEVEL) |
181 SOLO_VE_BLOCK_SIZE(SOLO_MP4E_EXT_SIZE(solo_dev) >> 16) | 277 SOLO_VE_BLOCK_SIZE(SOLO_MP4E_EXT_SIZE(solo_dev) >> 16) |
182 SOLO_VE_BLOCK_BASE(SOLO_MP4E_EXT_ADDR(solo_dev) >> 16)); 278 SOLO_VE_BLOCK_BASE(SOLO_MP4E_EXT_ADDR(solo_dev) >> 16));
183 279
184 solo_reg_write(solo_dev, SOLO_VE_CFG1, 280
185 SOLO_VE_INSERT_INDEX | SOLO_VE_MOTION_MODE(0)); 281 cfg = SOLO_VE_BYTE_ALIGN(2) | SOLO_VE_INSERT_INDEX
282 | SOLO_VE_MOTION_MODE(0);
283 if (solo_dev->type != SOLO_DEV_6010) {
284 cfg |= SOLO_VE_MPEG_SIZE_H(
285 (SOLO_MP4E_EXT_SIZE(solo_dev) >> 24) & 0x0f);
286 cfg |= SOLO_VE_JPEG_SIZE_H(
287 (SOLO_JPEG_EXT_SIZE(solo_dev) >> 24) & 0x0f);
288 }
289 solo_reg_write(solo_dev, SOLO_VE_CFG1, cfg);
186 290
187 solo_reg_write(solo_dev, SOLO_VE_WMRK_POLY, 0); 291 solo_reg_write(solo_dev, SOLO_VE_WMRK_POLY, 0);
188 solo_reg_write(solo_dev, SOLO_VE_VMRK_INIT_KEY, 0); 292 solo_reg_write(solo_dev, SOLO_VE_VMRK_INIT_KEY, 0);
189 solo_reg_write(solo_dev, SOLO_VE_WMRK_STRL, 0); 293 solo_reg_write(solo_dev, SOLO_VE_WMRK_STRL, 0);
294 if (solo_dev->type == SOLO_DEV_6110)
295 solo_reg_write(solo_dev, SOLO_VE_WMRK_ENABLE, 0);
190 solo_reg_write(solo_dev, SOLO_VE_ENCRYP_POLY, 0); 296 solo_reg_write(solo_dev, SOLO_VE_ENCRYP_POLY, 0);
191 solo_reg_write(solo_dev, SOLO_VE_ENCRYP_INIT, 0); 297 solo_reg_write(solo_dev, SOLO_VE_ENCRYP_INIT, 0);
192 298
193 reg = SOLO_VE_LITTLE_ENDIAN | SOLO_COMP_ATTR_FCODE(1) | 299 solo_reg_write(solo_dev, SOLO_VE_ATTR,
194 SOLO_COMP_TIME_INC(0) | SOLO_COMP_TIME_WIDTH(15); 300 SOLO_VE_LITTLE_ENDIAN |
195 if (solo_dev->flags & FLAGS_6110) 301 SOLO_COMP_ATTR_FCODE(1) |
196 reg |= SOLO_DCT_INTERVAL(10); 302 SOLO_COMP_TIME_INC(0) |
197 else 303 SOLO_COMP_TIME_WIDTH(15) |
198 reg |= SOLO_DCT_INTERVAL(36 / 4); 304 SOLO_DCT_INTERVAL(solo_dev->type == SOLO_DEV_6010 ? 9 : 10));
199 solo_reg_write(solo_dev, SOLO_VE_ATTR, reg);
200 305
201 for (i = 0; i < solo_dev->nr_chans; i++) 306 for (i = 0; i < solo_dev->nr_chans; i++) {
202 solo_reg_write(solo_dev, SOLO_VE_CH_REF_BASE(i), 307 solo_reg_write(solo_dev, SOLO_VE_CH_REF_BASE(i),
203 (SOLO_EREF_EXT_ADDR(solo_dev) + 308 (SOLO_EREF_EXT_ADDR(solo_dev) +
204 (i * SOLO_EREF_EXT_SIZE)) >> 16); 309 (i * SOLO_EREF_EXT_SIZE)) >> 16);
310 solo_reg_write(solo_dev, SOLO_VE_CH_REF_BASE_E(i),
311 (SOLO_EREF_EXT_ADDR(solo_dev) +
312 ((i + 16) * SOLO_EREF_EXT_SIZE)) >> 16);
313 }
205 314
206 if (solo_dev->flags & FLAGS_6110) 315 if (solo_dev->type == SOLO_DEV_6110) {
207 solo_reg_write(solo_dev, 0x0634, 0x00040008); /* ? */ 316 solo_reg_write(solo_dev, SOLO_VE_COMPT_MOT, 0x00040008);
317 } else {
318 for (i = 0; i < solo_dev->nr_chans; i++)
319 solo_reg_write(solo_dev, SOLO_VE_CH_MOT(i), 0x100);
320 }
208} 321}
209 322
210int solo_enc_init(struct solo_dev *solo_dev) 323int solo_enc_init(struct solo_dev *solo_dev)
@@ -220,8 +333,6 @@ int solo_enc_init(struct solo_dev *solo_dev)
220 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0); 333 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0);
221 } 334 }
222 335
223 solo_irq_on(solo_dev, SOLO_IRQ_ENCODER);
224
225 return 0; 336 return 0;
226} 337}
227 338
@@ -229,8 +340,6 @@ void solo_enc_exit(struct solo_dev *solo_dev)
229{ 340{
230 int i; 341 int i;
231 342
232 solo_irq_off(solo_dev, SOLO_IRQ_ENCODER);
233
234 for (i = 0; i < solo_dev->nr_chans; i++) { 343 for (i = 0; i < solo_dev->nr_chans; i++) {
235 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(i), 0); 344 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(i), 0);
236 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0); 345 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0);
diff --git a/drivers/staging/media/solo6x10/g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
index 2cd0de28a633..1db18c7972a0 100644
--- a/drivers/staging/media/solo6x10/g723.c
+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -21,17 +26,18 @@
21#include <linux/mempool.h> 26#include <linux/mempool.h>
22#include <linux/poll.h> 27#include <linux/poll.h>
23#include <linux/kthread.h> 28#include <linux/kthread.h>
24#include <linux/slab.h>
25#include <linux/freezer.h> 29#include <linux/freezer.h>
26#include <linux/export.h> 30#include <linux/module.h>
31#include <linux/slab.h>
32
27#include <sound/core.h> 33#include <sound/core.h>
28#include <sound/initval.h> 34#include <sound/initval.h>
29#include <sound/pcm.h> 35#include <sound/pcm.h>
30#include <sound/control.h> 36#include <sound/control.h>
37
31#include "solo6x10.h" 38#include "solo6x10.h"
32#include "tw28.h" 39#include "solo6x10-tw28.h"
33 40
34#define G723_INTR_ORDER 0
35#define G723_FDMA_PAGES 32 41#define G723_FDMA_PAGES 32
36#define G723_PERIOD_BYTES 48 42#define G723_PERIOD_BYTES 48
37#define G723_PERIOD_BLOCK 1024 43#define G723_PERIOD_BLOCK 1024
@@ -46,36 +52,40 @@
46/* The solo writes to 1k byte pages, 32 pages, in the dma. Each 1k page 52/* The solo writes to 1k byte pages, 32 pages, in the dma. Each 1k page
47 * is broken down to 20 * 48 byte regions (one for each channel possible) 53 * is broken down to 20 * 48 byte regions (one for each channel possible)
48 * with the rest of the page being dummy data. */ 54 * with the rest of the page being dummy data. */
49#define MAX_BUFFER (G723_PERIOD_BYTES * PERIODS_MAX) 55#define G723_MAX_BUFFER (G723_PERIOD_BYTES * PERIODS_MAX)
50#define IRQ_PAGES 4 /* 0 - 4 */ 56#define G723_INTR_ORDER 4 /* 0 - 4 */
51#define PERIODS_MIN (1 << IRQ_PAGES) 57#define PERIODS_MIN (1 << G723_INTR_ORDER)
52#define PERIODS_MAX G723_FDMA_PAGES 58#define PERIODS_MAX G723_FDMA_PAGES
53 59
54struct solo_snd_pcm { 60struct solo_snd_pcm {
55 int on; 61 int on;
56 spinlock_t lock; 62 spinlock_t lock;
57 struct solo_dev *solo_dev; 63 struct solo_dev *solo_dev;
58 unsigned char g723_buf[G723_PERIOD_BYTES]; 64 unsigned char *g723_buf;
65 dma_addr_t g723_dma;
59}; 66};
60 67
61static void solo_g723_config(struct solo_dev *solo_dev) 68static void solo_g723_config(struct solo_dev *solo_dev)
62{ 69{
63 int clk_div; 70 int clk_div;
64 71
65 clk_div = SOLO_CLOCK_MHZ / (SAMPLERATE * (BITRATE * 2) * 2); 72 clk_div = (solo_dev->clock_mhz * 1000000)
73 / (SAMPLERATE * (BITRATE * 2) * 2);
66 74
67 solo_reg_write(solo_dev, SOLO_AUDIO_SAMPLE, 75 solo_reg_write(solo_dev, SOLO_AUDIO_SAMPLE,
68 SOLO_AUDIO_BITRATE(BITRATE) | 76 SOLO_AUDIO_BITRATE(BITRATE)
69 SOLO_AUDIO_CLK_DIV(clk_div)); 77 | SOLO_AUDIO_CLK_DIV(clk_div));
70 78
71 solo_reg_write(solo_dev, SOLO_AUDIO_FDMA_INTR, 79 solo_reg_write(solo_dev, SOLO_AUDIO_FDMA_INTR,
72 SOLO_AUDIO_FDMA_INTERVAL(IRQ_PAGES) | 80 SOLO_AUDIO_FDMA_INTERVAL(1)
73 SOLO_AUDIO_INTR_ORDER(G723_INTR_ORDER) | 81 | SOLO_AUDIO_INTR_ORDER(G723_INTR_ORDER)
74 SOLO_AUDIO_FDMA_BASE(SOLO_G723_EXT_ADDR(solo_dev) >> 16)); 82 | SOLO_AUDIO_FDMA_BASE(SOLO_G723_EXT_ADDR(solo_dev) >> 16));
75 83
76 solo_reg_write(solo_dev, SOLO_AUDIO_CONTROL, 84 solo_reg_write(solo_dev, SOLO_AUDIO_CONTROL,
77 SOLO_AUDIO_ENABLE | SOLO_AUDIO_I2S_MODE | 85 SOLO_AUDIO_ENABLE
78 SOLO_AUDIO_I2S_MULTI(3) | SOLO_AUDIO_MODE(OUTMODE_MASK)); 86 | SOLO_AUDIO_I2S_MODE
87 | SOLO_AUDIO_I2S_MULTI(3)
88 | SOLO_AUDIO_MODE(OUTMODE_MASK));
79} 89}
80 90
81void solo_g723_isr(struct solo_dev *solo_dev) 91void solo_g723_isr(struct solo_dev *solo_dev)
@@ -85,8 +95,6 @@ void solo_g723_isr(struct solo_dev *solo_dev)
85 struct snd_pcm_substream *ss; 95 struct snd_pcm_substream *ss;
86 struct solo_snd_pcm *solo_pcm; 96 struct solo_snd_pcm *solo_pcm;
87 97
88 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_G723);
89
90 for (ss = pstr->substream; ss != NULL; ss = ss->next) { 98 for (ss = pstr->substream; ss != NULL; ss = ss->next) {
91 if (snd_pcm_substream_chip(ss) == NULL) 99 if (snd_pcm_substream_chip(ss) == NULL)
92 continue; 100 continue;
@@ -115,18 +123,18 @@ static int snd_solo_hw_free(struct snd_pcm_substream *ss)
115 return snd_pcm_lib_free_pages(ss); 123 return snd_pcm_lib_free_pages(ss);
116} 124}
117 125
118static struct snd_pcm_hardware snd_solo_pcm_hw = { 126static const struct snd_pcm_hardware snd_solo_pcm_hw = {
119 .info = (SNDRV_PCM_INFO_MMAP | 127 .info = (SNDRV_PCM_INFO_MMAP |
120 SNDRV_PCM_INFO_INTERLEAVED | 128 SNDRV_PCM_INFO_INTERLEAVED |
121 SNDRV_PCM_INFO_BLOCK_TRANSFER | 129 SNDRV_PCM_INFO_BLOCK_TRANSFER |
122 SNDRV_PCM_INFO_MMAP_VALID), 130 SNDRV_PCM_INFO_MMAP_VALID),
123 .formats = SNDRV_PCM_FMTBIT_U8, 131 .formats = SNDRV_PCM_FMTBIT_U8,
124 .rates = SNDRV_PCM_RATE_8000, 132 .rates = SNDRV_PCM_RATE_8000,
125 .rate_min = 8000, 133 .rate_min = SAMPLERATE,
126 .rate_max = 8000, 134 .rate_max = SAMPLERATE,
127 .channels_min = 1, 135 .channels_min = 1,
128 .channels_max = 1, 136 .channels_max = 1,
129 .buffer_bytes_max = MAX_BUFFER, 137 .buffer_bytes_max = G723_MAX_BUFFER,
130 .period_bytes_min = G723_PERIOD_BYTES, 138 .period_bytes_min = G723_PERIOD_BYTES,
131 .period_bytes_max = G723_PERIOD_BYTES, 139 .period_bytes_max = G723_PERIOD_BYTES,
132 .periods_min = PERIODS_MIN, 140 .periods_min = PERIODS_MIN,
@@ -140,7 +148,13 @@ static int snd_solo_pcm_open(struct snd_pcm_substream *ss)
140 148
141 solo_pcm = kzalloc(sizeof(*solo_pcm), GFP_KERNEL); 149 solo_pcm = kzalloc(sizeof(*solo_pcm), GFP_KERNEL);
142 if (solo_pcm == NULL) 150 if (solo_pcm == NULL)
143 return -ENOMEM; 151 goto oom;
152
153 solo_pcm->g723_buf = pci_alloc_consistent(solo_dev->pdev,
154 G723_PERIOD_BYTES,
155 &solo_pcm->g723_dma);
156 if (solo_pcm->g723_buf == NULL)
157 goto oom;
144 158
145 spin_lock_init(&solo_pcm->lock); 159 spin_lock_init(&solo_pcm->lock);
146 solo_pcm->solo_dev = solo_dev; 160 solo_pcm->solo_dev = solo_dev;
@@ -149,6 +163,10 @@ static int snd_solo_pcm_open(struct snd_pcm_substream *ss)
149 snd_pcm_substream_chip(ss) = solo_pcm; 163 snd_pcm_substream_chip(ss) = solo_pcm;
150 164
151 return 0; 165 return 0;
166
167oom:
168 kfree(solo_pcm);
169 return -ENOMEM;
152} 170}
153 171
154static int snd_solo_pcm_close(struct snd_pcm_substream *ss) 172static int snd_solo_pcm_close(struct snd_pcm_substream *ss)
@@ -156,6 +174,8 @@ static int snd_solo_pcm_close(struct snd_pcm_substream *ss)
156 struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss); 174 struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
157 175
158 snd_pcm_substream_chip(ss) = solo_pcm->solo_dev; 176 snd_pcm_substream_chip(ss) = solo_pcm->solo_dev;
177 pci_free_consistent(solo_pcm->solo_dev->pdev, G723_PERIOD_BYTES,
178 solo_pcm->g723_buf, solo_pcm->g723_dma);
159 kfree(solo_pcm); 179 kfree(solo_pcm);
160 180
161 return 0; 181 return 0;
@@ -220,12 +240,11 @@ static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel,
220 for (i = 0; i < (count / G723_FRAMES_PER_PAGE); i++) { 240 for (i = 0; i < (count / G723_FRAMES_PER_PAGE); i++) {
221 int page = (pos / G723_FRAMES_PER_PAGE) + i; 241 int page = (pos / G723_FRAMES_PER_PAGE) + i;
222 242
223 err = solo_p2m_dma(solo_dev, SOLO_P2M_DMA_ID_G723E, 0, 243 err = solo_p2m_dma_t(solo_dev, 0, solo_pcm->g723_dma,
224 solo_pcm->g723_buf, 244 SOLO_G723_EXT_ADDR(solo_dev) +
225 SOLO_G723_EXT_ADDR(solo_dev) + 245 (page * G723_PERIOD_BLOCK) +
226 (page * G723_PERIOD_BLOCK) + 246 (ss->number * G723_PERIOD_BYTES),
227 (ss->number * G723_PERIOD_BYTES), 247 G723_PERIOD_BYTES, 0, 0);
228 G723_PERIOD_BYTES);
229 if (err) 248 if (err)
230 return err; 249 return err;
231 250
@@ -325,7 +344,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
325 ret = snd_pcm_lib_preallocate_pages_for_all(pcm, 344 ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
326 SNDRV_DMA_TYPE_CONTINUOUS, 345 SNDRV_DMA_TYPE_CONTINUOUS,
327 snd_dma_continuous_data(GFP_KERNEL), 346 snd_dma_continuous_data(GFP_KERNEL),
328 MAX_BUFFER, MAX_BUFFER); 347 G723_MAX_BUFFER, G723_MAX_BUFFER);
329 if (ret < 0) 348 if (ret < 0)
330 return ret; 349 return ret;
331 350
@@ -368,6 +387,7 @@ int solo_g723_init(struct solo_dev *solo_dev)
368 strcpy(card->mixername, "SOLO-6x10"); 387 strcpy(card->mixername, "SOLO-6x10");
369 kctl = snd_solo_capture_volume; 388 kctl = snd_solo_capture_volume;
370 kctl.count = solo_dev->nr_chans; 389 kctl.count = solo_dev->nr_chans;
390
371 ret = snd_ctl_add(card, snd_ctl_new1(&kctl, solo_dev)); 391 ret = snd_ctl_add(card, snd_ctl_new1(&kctl, solo_dev));
372 if (ret < 0) 392 if (ret < 0)
373 return ret; 393 return ret;
@@ -393,8 +413,12 @@ snd_error:
393 413
394void solo_g723_exit(struct solo_dev *solo_dev) 414void solo_g723_exit(struct solo_dev *solo_dev)
395{ 415{
416 if (!solo_dev->snd_card)
417 return;
418
396 solo_reg_write(solo_dev, SOLO_AUDIO_CONTROL, 0); 419 solo_reg_write(solo_dev, SOLO_AUDIO_CONTROL, 0);
397 solo_irq_off(solo_dev, SOLO_IRQ_G723); 420 solo_irq_off(solo_dev, SOLO_IRQ_G723);
398 421
399 snd_card_free(solo_dev->snd_card); 422 snd_card_free(solo_dev->snd_card);
423 solo_dev->snd_card = NULL;
400} 424}
diff --git a/drivers/staging/media/solo6x10/gpio.c b/drivers/staging/media/solo6x10/solo6x10-gpio.c
index 0925e6f33a99..73276dc92875 100644
--- a/drivers/staging/media/solo6x10/gpio.c
+++ b/drivers/staging/media/solo6x10/solo6x10-gpio.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -19,7 +24,9 @@
19 24
20#include <linux/kernel.h> 25#include <linux/kernel.h>
21#include <linux/fs.h> 26#include <linux/fs.h>
22#include <asm/uaccess.h> 27#include <linux/delay.h>
28#include <linux/uaccess.h>
29
23#include "solo6x10.h" 30#include "solo6x10.h"
24 31
25static void solo_gpio_mode(struct solo_dev *solo_dev, 32static void solo_gpio_mode(struct solo_dev *solo_dev,
diff --git a/drivers/staging/media/solo6x10/i2c.c b/drivers/staging/media/solo6x10/solo6x10-i2c.c
index 398070a3d293..01aa417c9258 100644
--- a/drivers/staging/media/solo6x10/i2c.c
+++ b/drivers/staging/media/solo6x10/solo6x10-i2c.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -26,6 +31,7 @@
26 * thread context, ACK the interrupt, and move on. -- BenC */ 31 * thread context, ACK the interrupt, and move on. -- BenC */
27 32
28#include <linux/kernel.h> 33#include <linux/kernel.h>
34
29#include "solo6x10.h" 35#include "solo6x10.h"
30 36
31u8 solo_i2c_readbyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off) 37u8 solo_i2c_readbyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off)
@@ -173,10 +179,9 @@ int solo_i2c_isr(struct solo_dev *solo_dev)
173 u32 status = solo_reg_read(solo_dev, SOLO_IIC_CTRL); 179 u32 status = solo_reg_read(solo_dev, SOLO_IIC_CTRL);
174 int ret = -EINVAL; 180 int ret = -EINVAL;
175 181
176 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_IIC);
177 182
178 if (status & (SOLO_IIC_STATE_TRNS | SOLO_IIC_STATE_SIG_ERR) || 183 if (CHK_FLAGS(status, SOLO_IIC_STATE_TRNS | SOLO_IIC_STATE_SIG_ERR)
179 solo_dev->i2c_id < 0) { 184 || solo_dev->i2c_id < 0) {
180 solo_i2c_stop(solo_dev); 185 solo_i2c_stop(solo_dev);
181 return -ENXIO; 186 return -ENXIO;
182 } 187 }
@@ -239,7 +244,8 @@ static int solo_i2c_master_xfer(struct i2c_adapter *adap,
239 timeout = HZ / 2; 244 timeout = HZ / 2;
240 245
241 for (;;) { 246 for (;;) {
242 prepare_to_wait(&solo_dev->i2c_wait, &wait, TASK_INTERRUPTIBLE); 247 prepare_to_wait(&solo_dev->i2c_wait, &wait,
248 TASK_INTERRUPTIBLE);
243 249
244 if (solo_dev->i2c_state == IIC_STATE_STOP) 250 if (solo_dev->i2c_state == IIC_STATE_STOP)
245 break; 251 break;
@@ -267,7 +273,7 @@ static u32 solo_i2c_functionality(struct i2c_adapter *adap)
267 return I2C_FUNC_I2C; 273 return I2C_FUNC_I2C;
268} 274}
269 275
270static struct i2c_algorithm solo_i2c_algo = { 276static const struct i2c_algorithm solo_i2c_algo = {
271 .master_xfer = solo_i2c_master_xfer, 277 .master_xfer = solo_i2c_master_xfer,
272 .functionality = solo_i2c_functionality, 278 .functionality = solo_i2c_functionality,
273}; 279};
@@ -288,7 +294,8 @@ int solo_i2c_init(struct solo_dev *solo_dev)
288 for (i = 0; i < SOLO_I2C_ADAPTERS; i++) { 294 for (i = 0; i < SOLO_I2C_ADAPTERS; i++) {
289 struct i2c_adapter *adap = &solo_dev->i2c_adap[i]; 295 struct i2c_adapter *adap = &solo_dev->i2c_adap[i];
290 296
291 snprintf(adap->name, I2C_NAME_SIZE, "%s I2C %d", SOLO6X10_NAME, i); 297 snprintf(adap->name, I2C_NAME_SIZE, "%s I2C %d",
298 SOLO6X10_NAME, i);
292 adap->algo = &solo_i2c_algo; 299 adap->algo = &solo_i2c_algo;
293 adap->algo_data = solo_dev; 300 adap->algo_data = solo_dev;
294 adap->retries = 1; 301 adap->retries = 1;
@@ -311,9 +318,6 @@ int solo_i2c_init(struct solo_dev *solo_dev)
311 return ret; 318 return ret;
312 } 319 }
313 320
314 dev_info(&solo_dev->pdev->dev, "Enabled %d i2c adapters\n",
315 SOLO_I2C_ADAPTERS);
316
317 return 0; 321 return 0;
318} 322}
319 323
diff --git a/drivers/staging/media/solo6x10/solo6x10-jpeg.h b/drivers/staging/media/solo6x10/solo6x10-jpeg.h
index 50defec318cc..c5218ceeabca 100644
--- a/drivers/staging/media/solo6x10/solo6x10-jpeg.h
+++ b/drivers/staging/media/solo6x10/solo6x10-jpeg.h
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -20,7 +25,7 @@
20#ifndef __SOLO6X10_JPEG_H 25#ifndef __SOLO6X10_JPEG_H
21#define __SOLO6X10_JPEG_H 26#define __SOLO6X10_JPEG_H
22 27
23static unsigned char jpeg_header[] = { 28static const unsigned char jpeg_header[] = {
24 0xff, 0xd8, 0xff, 0xfe, 0x00, 0x0d, 0x42, 0x6c, 29 0xff, 0xd8, 0xff, 0xfe, 0x00, 0x0d, 0x42, 0x6c,
25 0x75, 0x65, 0x63, 0x68, 0x65, 0x72, 0x72, 0x79, 30 0x75, 0x65, 0x63, 0x68, 0x65, 0x72, 0x72, 0x79,
26 0x20, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x20, 0x16, 31 0x20, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x20, 0x16,
@@ -102,4 +107,87 @@ static unsigned char jpeg_header[] = {
102/* This is the byte marker for the start of SOF0: 0xffc0 marker */ 107/* This is the byte marker for the start of SOF0: 0xffc0 marker */
103#define SOF0_START 575 108#define SOF0_START 575
104 109
110/* This is the byte marker for the start of the DQT */
111#define DQT_START 17
112#define DQT_LEN 138
113const unsigned char jpeg_dqt[4][DQT_LEN] = {
114 {
115 0xff, 0xdb, 0x00, 0x43, 0x00,
116 0x08, 0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07,
117 0x07, 0x07, 0x09, 0x09, 0x08, 0x0a, 0x0c, 0x14,
118 0x0d, 0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12, 0x13,
119 0x0f, 0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a,
120 0x1c, 0x1c, 0x20, 0x24, 0x2e, 0x27, 0x20, 0x22,
121 0x2c, 0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29, 0x2c,
122 0x30, 0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39,
123 0x3d, 0x38, 0x32, 0x3c, 0x2e, 0x33, 0x34, 0x32,
124 0xff, 0xdb, 0x00, 0x43, 0x01,
125 0x09, 0x09, 0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0d,
126 0x0d, 0x18, 0x32, 0x21, 0x1c, 0x21, 0x32, 0x32,
127 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
128 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
129 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
130 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
131 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
132 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32
133 }, {
134 0xff, 0xdb, 0x00, 0x43, 0x00,
135 0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
136 0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
137 0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
138 0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
139 0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
140 0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
141 0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
142 0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
143 0xff, 0xdb, 0x00, 0x43, 0x01,
144 0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
145 0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
146 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
147 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
148 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
149 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
150 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
151 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63
152 }, {
153 0xff, 0xdb, 0x00, 0x43, 0x00,
154 0x20, 0x16, 0x18, 0x1c, 0x18, 0x14, 0x20, 0x1c,
155 0x1a, 0x1c, 0x24, 0x22, 0x20, 0x26, 0x30, 0x50,
156 0x34, 0x30, 0x2c, 0x2c, 0x30, 0x62, 0x46, 0x4a,
157 0x3a, 0x50, 0x74, 0x66, 0x7a, 0x78, 0x72, 0x66,
158 0x70, 0x6e, 0x80, 0x90, 0xb8, 0x9c, 0x80, 0x88,
159 0xae, 0x8a, 0x6e, 0x70, 0xa0, 0xda, 0xa2, 0xae,
160 0xbe, 0xc4, 0xce, 0xd0, 0xce, 0x7c, 0x9a, 0xe2,
161 0xf2, 0xe0, 0xc8, 0xf0, 0xb8, 0xca, 0xce, 0xc6,
162 0xff, 0xdb, 0x00, 0x43, 0x01,
163 0x22, 0x24, 0x24, 0x30, 0x2a, 0x30, 0x5e, 0x34,
164 0x34, 0x5e, 0xc6, 0x84, 0x70, 0x84, 0xc6, 0xc6,
165 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
166 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
167 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
168 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
169 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
170 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6
171 }, {
172 0xff, 0xdb, 0x00, 0x43, 0x00,
173 0x30, 0x21, 0x24, 0x2a, 0x24, 0x1e, 0x30, 0x2a,
174 0x27, 0x2a, 0x36, 0x33, 0x30, 0x39, 0x48, 0x78,
175 0x4e, 0x48, 0x42, 0x42, 0x48, 0x93, 0x69, 0x6f,
176 0x57, 0x78, 0xae, 0x99, 0xb7, 0xb4, 0xab, 0x99,
177 0xa8, 0xa5, 0xc0, 0xd8, 0xff, 0xea, 0xc0, 0xcc,
178 0xff, 0xcf, 0xa5, 0xa8, 0xf0, 0xff, 0xf3, 0xff,
179 0xff, 0xff, 0xff, 0xff, 0xff, 0xba, 0xe7, 0xff,
180 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
181 0xff, 0xdb, 0x00, 0x43, 0x01,
182 0x33, 0x36, 0x36, 0x48, 0x3f, 0x48, 0x8d, 0x4e,
183 0x4e, 0x8d, 0xff, 0xc6, 0xa8, 0xc6, 0xff, 0xff,
184 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
185 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
186 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
187 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
188 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
189 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
190 }
191};
192
105#endif /* __SOLO6X10_JPEG_H */ 193#endif /* __SOLO6X10_JPEG_H */
diff --git a/drivers/staging/media/solo6x10/solo6x10-offsets.h b/drivers/staging/media/solo6x10/solo6x10-offsets.h
new file mode 100644
index 000000000000..f005dca501f1
--- /dev/null
+++ b/drivers/staging/media/solo6x10/solo6x10-offsets.h
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25#ifndef __SOLO6X10_OFFSETS_H
26#define __SOLO6X10_OFFSETS_H
27
28#define SOLO_DISP_EXT_ADDR 0x00000000
29#define SOLO_DISP_EXT_SIZE 0x00480000
30
31#define SOLO_EOSD_EXT_ADDR \
32 (SOLO_DISP_EXT_ADDR + SOLO_DISP_EXT_SIZE)
33#define SOLO_EOSD_EXT_SIZE(__solo) \
34 (__solo->type == SOLO_DEV_6010 ? 0x10000 : 0x20000)
35#define SOLO_EOSD_EXT_SIZE_MAX 0x20000
36#define SOLO_EOSD_EXT_AREA(__solo) \
37 (SOLO_EOSD_EXT_SIZE(__solo) * 32)
38
39#define SOLO_MOTION_EXT_ADDR(__solo) \
40 (SOLO_EOSD_EXT_ADDR + SOLO_EOSD_EXT_AREA(__solo))
41#define SOLO_MOTION_EXT_SIZE 0x00080000
42
43#define SOLO_G723_EXT_ADDR(__solo) \
44 (SOLO_MOTION_EXT_ADDR(__solo) + SOLO_MOTION_EXT_SIZE)
45#define SOLO_G723_EXT_SIZE 0x00010000
46
47#define SOLO_CAP_EXT_ADDR(__solo) \
48 (SOLO_G723_EXT_ADDR(__solo) + SOLO_G723_EXT_SIZE)
49
50/* 18 is the maximum number of pages required for PAL@D1, the largest frame
51 * possible */
52#define SOLO_CAP_PAGE_SIZE (18 << 16)
53
54/* Always allow the encoder enough for 16 channels, even if we have less. The
55 * exception is if we have card with only 32Megs of memory. */
56#define SOLO_CAP_EXT_SIZE(__solo) \
57 ((((__solo->sdram_size <= (32 << 20)) ? 4 : 16) + 1) \
58 * SOLO_CAP_PAGE_SIZE)
59
60#define SOLO_EREF_EXT_ADDR(__solo) \
61 (SOLO_CAP_EXT_ADDR(__solo) + SOLO_CAP_EXT_SIZE(__solo))
62#define SOLO_EREF_EXT_SIZE 0x00140000
63#define SOLO_EREF_EXT_AREA(__solo) \
64 (SOLO_EREF_EXT_SIZE * __solo->nr_chans * 2)
65
66#define __SOLO_JPEG_MIN_SIZE(__solo) (__solo->nr_chans * 0x00080000)
67
68#define SOLO_MP4E_EXT_ADDR(__solo) \
69 (SOLO_EREF_EXT_ADDR(__solo) + SOLO_EREF_EXT_AREA(__solo))
70#define SOLO_MP4E_EXT_SIZE(__solo) \
71 max((__solo->nr_chans * 0x00080000), \
72 min(((__solo->sdram_size - SOLO_MP4E_EXT_ADDR(__solo)) - \
73 __SOLO_JPEG_MIN_SIZE(__solo)), 0x00ff0000))
74
75#define __SOLO_JPEG_MIN_SIZE(__solo) (__solo->nr_chans * 0x00080000)
76#define SOLO_JPEG_EXT_ADDR(__solo) \
77 (SOLO_MP4E_EXT_ADDR(__solo) + SOLO_MP4E_EXT_SIZE(__solo))
78#define SOLO_JPEG_EXT_SIZE(__solo) \
79 max(__SOLO_JPEG_MIN_SIZE(__solo), \
80 min((__solo->sdram_size - SOLO_JPEG_EXT_ADDR(__solo)), 0x00ff0000))
81
82#define SOLO_SDRAM_END(__solo) \
83 (SOLO_JPEG_EXT_ADDR(__solo) + SOLO_JPEG_EXT_SIZE(__solo))
84
85#endif /* __SOLO6X10_OFFSETS_H */
diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
new file mode 100644
index 000000000000..333594189b81
--- /dev/null
+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
@@ -0,0 +1,333 @@
1/*
2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28
29#include "solo6x10.h"
30
31static int multi_p2m;
32module_param(multi_p2m, uint, 0644);
33MODULE_PARM_DESC(multi_p2m,
34 "Use multiple P2M DMA channels (default: no, 6010-only)");
35
36static int desc_mode;
37module_param(desc_mode, uint, 0644);
38MODULE_PARM_DESC(desc_mode,
39 "Allow use of descriptor mode DMA (default: no, 6010-only)");
40
41int solo_p2m_dma(struct solo_dev *solo_dev, int wr,
42 void *sys_addr, u32 ext_addr, u32 size,
43 int repeat, u32 ext_size)
44{
45 dma_addr_t dma_addr;
46 int ret;
47
48 if (WARN_ON_ONCE((unsigned long)sys_addr & 0x03))
49 return -EINVAL;
50 if (WARN_ON_ONCE(!size))
51 return -EINVAL;
52
53 dma_addr = pci_map_single(solo_dev->pdev, sys_addr, size,
54 wr ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
55 if (pci_dma_mapping_error(solo_dev->pdev, dma_addr))
56 return -ENOMEM;
57
58 ret = solo_p2m_dma_t(solo_dev, wr, dma_addr, ext_addr, size,
59 repeat, ext_size);
60
61 pci_unmap_single(solo_dev->pdev, dma_addr, size,
62 wr ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
63
64 return ret;
65}
66
67/* Mutex must be held for p2m_id before calling this!! */
68int solo_p2m_dma_desc(struct solo_dev *solo_dev,
69 struct solo_p2m_desc *desc, dma_addr_t desc_dma,
70 int desc_cnt)
71{
72 struct solo_p2m_dev *p2m_dev;
73 unsigned int timeout;
74 unsigned int config = 0;
75 int ret = 0;
76 int p2m_id = 0;
77
78 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
79 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
80 p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
81 if (p2m_id < 0)
82 p2m_id = -p2m_id;
83 }
84
85 p2m_dev = &solo_dev->p2m_dev[p2m_id];
86
87 if (mutex_lock_interruptible(&p2m_dev->mutex))
88 return -EINTR;
89
90 INIT_COMPLETION(p2m_dev->completion);
91 p2m_dev->error = 0;
92
93 if (desc_cnt > 1 && solo_dev->type != SOLO_DEV_6110 && desc_mode) {
94 /* For 6010 with more than one desc, we can do a one-shot */
95 p2m_dev->desc_count = p2m_dev->desc_idx = 0;
96 config = solo_reg_read(solo_dev, SOLO_P2M_CONFIG(p2m_id));
97
98 solo_reg_write(solo_dev, SOLO_P2M_DES_ADR(p2m_id), desc_dma);
99 solo_reg_write(solo_dev, SOLO_P2M_DESC_ID(p2m_id), desc_cnt);
100 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(p2m_id), config |
101 SOLO_P2M_DESC_MODE);
102 } else {
103 /* For single descriptors and 6110, we need to run each desc */
104 p2m_dev->desc_count = desc_cnt;
105 p2m_dev->desc_idx = 1;
106 p2m_dev->descs = desc;
107
108 solo_reg_write(solo_dev, SOLO_P2M_TAR_ADR(p2m_id),
109 desc[1].dma_addr);
110 solo_reg_write(solo_dev, SOLO_P2M_EXT_ADR(p2m_id),
111 desc[1].ext_addr);
112 solo_reg_write(solo_dev, SOLO_P2M_EXT_CFG(p2m_id),
113 desc[1].cfg);
114 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(p2m_id),
115 desc[1].ctrl);
116 }
117
118 timeout = wait_for_completion_timeout(&p2m_dev->completion,
119 solo_dev->p2m_jiffies);
120
121 if (WARN_ON_ONCE(p2m_dev->error))
122 ret = -EIO;
123 else if (timeout == 0) {
124 solo_dev->p2m_timeouts++;
125 ret = -EAGAIN;
126 }
127
128 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(p2m_id), 0);
129
130 /* Don't write here for the no_desc_mode case, because config is 0.
131 * We can't test no_desc_mode again, it might race. */
132 if (desc_cnt > 1 && solo_dev->type != SOLO_DEV_6110 && config)
133 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(p2m_id), config);
134
135 mutex_unlock(&p2m_dev->mutex);
136
137 return ret;
138}
139
140void solo_p2m_fill_desc(struct solo_p2m_desc *desc, int wr,
141 dma_addr_t dma_addr, u32 ext_addr, u32 size,
142 int repeat, u32 ext_size)
143{
144 WARN_ON_ONCE(dma_addr & 0x03);
145 WARN_ON_ONCE(!size);
146
147 desc->cfg = SOLO_P2M_COPY_SIZE(size >> 2);
148 desc->ctrl = SOLO_P2M_BURST_SIZE(SOLO_P2M_BURST_256) |
149 (wr ? SOLO_P2M_WRITE : 0) | SOLO_P2M_TRANS_ON;
150
151 if (repeat) {
152 desc->cfg |= SOLO_P2M_EXT_INC(ext_size >> 2);
153 desc->ctrl |= SOLO_P2M_PCI_INC(size >> 2) |
154 SOLO_P2M_REPEAT(repeat);
155 }
156
157 desc->dma_addr = dma_addr;
158 desc->ext_addr = ext_addr;
159}
160
161int solo_p2m_dma_t(struct solo_dev *solo_dev, int wr,
162 dma_addr_t dma_addr, u32 ext_addr, u32 size,
163 int repeat, u32 ext_size)
164{
165 struct solo_p2m_desc desc[2];
166
167 solo_p2m_fill_desc(&desc[1], wr, dma_addr, ext_addr, size, repeat,
168 ext_size);
169
170 /* No need for desc_dma since we know it is a single-shot */
171 return solo_p2m_dma_desc(solo_dev, desc, 0, 1);
172}
173
174void solo_p2m_isr(struct solo_dev *solo_dev, int id)
175{
176 struct solo_p2m_dev *p2m_dev = &solo_dev->p2m_dev[id];
177 struct solo_p2m_desc *desc;
178
179 if (p2m_dev->desc_count <= p2m_dev->desc_idx) {
180 complete(&p2m_dev->completion);
181 return;
182 }
183
184 /* Setup next descriptor */
185 p2m_dev->desc_idx++;
186 desc = &p2m_dev->descs[p2m_dev->desc_idx];
187
188 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), 0);
189 solo_reg_write(solo_dev, SOLO_P2M_TAR_ADR(id), desc->dma_addr);
190 solo_reg_write(solo_dev, SOLO_P2M_EXT_ADR(id), desc->ext_addr);
191 solo_reg_write(solo_dev, SOLO_P2M_EXT_CFG(id), desc->cfg);
192 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), desc->ctrl);
193}
194
195void solo_p2m_error_isr(struct solo_dev *solo_dev)
196{
197 unsigned int err = solo_reg_read(solo_dev, SOLO_PCI_ERR);
198 struct solo_p2m_dev *p2m_dev;
199 int i;
200
201 if (!(err & (SOLO_PCI_ERR_P2M | SOLO_PCI_ERR_P2M_DESC)))
202 return;
203
204 for (i = 0; i < SOLO_NR_P2M; i++) {
205 p2m_dev = &solo_dev->p2m_dev[i];
206 p2m_dev->error = 1;
207 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(i), 0);
208 complete(&p2m_dev->completion);
209 }
210}
211
212void solo_p2m_exit(struct solo_dev *solo_dev)
213{
214 int i;
215
216 for (i = 0; i < SOLO_NR_P2M; i++)
217 solo_irq_off(solo_dev, SOLO_IRQ_P2M(i));
218}
219
220static int solo_p2m_test(struct solo_dev *solo_dev, int base, int size)
221{
222 u32 *wr_buf;
223 u32 *rd_buf;
224 int i;
225 int ret = -EIO;
226 int order = get_order(size);
227
228 wr_buf = (u32 *)__get_free_pages(GFP_KERNEL, order);
229 if (wr_buf == NULL)
230 return -1;
231
232 rd_buf = (u32 *)__get_free_pages(GFP_KERNEL, order);
233 if (rd_buf == NULL) {
234 free_pages((unsigned long)wr_buf, order);
235 return -1;
236 }
237
238 for (i = 0; i < (size >> 3); i++)
239 *(wr_buf + i) = (i << 16) | (i + 1);
240
241 for (i = (size >> 3); i < (size >> 2); i++)
242 *(wr_buf + i) = ~((i << 16) | (i + 1));
243
244 memset(rd_buf, 0x55, size);
245
246 if (solo_p2m_dma(solo_dev, 1, wr_buf, base, size, 0, 0))
247 goto test_fail;
248
249 if (solo_p2m_dma(solo_dev, 0, rd_buf, base, size, 0, 0))
250 goto test_fail;
251
252 for (i = 0; i < (size >> 2); i++) {
253 if (*(wr_buf + i) != *(rd_buf + i))
254 goto test_fail;
255 }
256
257 ret = 0;
258
259test_fail:
260 free_pages((unsigned long)wr_buf, order);
261 free_pages((unsigned long)rd_buf, order);
262
263 return ret;
264}
265
266int solo_p2m_init(struct solo_dev *solo_dev)
267{
268 struct solo_p2m_dev *p2m_dev;
269 int i;
270
271 for (i = 0; i < SOLO_NR_P2M; i++) {
272 p2m_dev = &solo_dev->p2m_dev[i];
273
274 mutex_init(&p2m_dev->mutex);
275 init_completion(&p2m_dev->completion);
276
277 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(i), 0);
278 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(i),
279 SOLO_P2M_CSC_16BIT_565 |
280 SOLO_P2M_DESC_INTR_OPT |
281 SOLO_P2M_DMA_INTERVAL(0) |
282 SOLO_P2M_PCI_MASTER_MODE);
283 solo_irq_on(solo_dev, SOLO_IRQ_P2M(i));
284 }
285
286 /* Find correct SDRAM size */
287 for (solo_dev->sdram_size = 0, i = 2; i >= 0; i--) {
288 solo_reg_write(solo_dev, SOLO_DMA_CTRL,
289 SOLO_DMA_CTRL_REFRESH_CYCLE(1) |
290 SOLO_DMA_CTRL_SDRAM_SIZE(i) |
291 SOLO_DMA_CTRL_SDRAM_CLK_INVERT |
292 SOLO_DMA_CTRL_READ_CLK_SELECT |
293 SOLO_DMA_CTRL_LATENCY(1));
294
295 solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config |
296 SOLO_SYS_CFG_RESET);
297 solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
298
299 switch (i) {
300 case 2:
301 if (solo_p2m_test(solo_dev, 0x07ff0000, 0x00010000) ||
302 solo_p2m_test(solo_dev, 0x05ff0000, 0x00010000))
303 continue;
304 break;
305
306 case 1:
307 if (solo_p2m_test(solo_dev, 0x03ff0000, 0x00010000))
308 continue;
309 break;
310
311 default:
312 if (solo_p2m_test(solo_dev, 0x01ff0000, 0x00010000))
313 continue;
314 }
315
316 solo_dev->sdram_size = (32 << 20) << i;
317 break;
318 }
319
320 if (!solo_dev->sdram_size) {
321 dev_err(&solo_dev->pdev->dev, "Error detecting SDRAM size\n");
322 return -EIO;
323 }
324
325 if (SOLO_SDRAM_END(solo_dev) > solo_dev->sdram_size) {
326 dev_err(&solo_dev->pdev->dev,
327 "SDRAM is not large enough (%u < %u)\n",
328 solo_dev->sdram_size, SOLO_SDRAM_END(solo_dev));
329 return -EIO;
330 }
331
332 return 0;
333}
diff --git a/drivers/staging/media/solo6x10/registers.h b/drivers/staging/media/solo6x10/solo6x10-regs.h
index aca544472c93..428f6c951180 100644
--- a/drivers/staging/media/solo6x10/registers.h
+++ b/drivers/staging/media/solo6x10/solo6x10-regs.h
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -20,20 +25,20 @@
20#ifndef __SOLO6X10_REGISTERS_H 25#ifndef __SOLO6X10_REGISTERS_H
21#define __SOLO6X10_REGISTERS_H 26#define __SOLO6X10_REGISTERS_H
22 27
23#include "offsets.h" 28#include "solo6x10-offsets.h"
24 29
25/* Global 6X10 system configuration */ 30/* Global 6010 system configuration */
26#define SOLO_SYS_CFG 0x0000 31#define SOLO_SYS_CFG 0x0000
27#define SOLO6010_SYS_CFG_FOUT_EN 0x00000001 /* 6010 only */ 32#define SOLO_SYS_CFG_FOUT_EN 0x00000001
28#define SOLO6010_SYS_CFG_PLL_BYPASS 0x00000002 /* 6010 only */ 33#define SOLO_SYS_CFG_PLL_BYPASS 0x00000002
29#define SOLO6010_SYS_CFG_PLL_PWDN 0x00000004 /* 6010 only */ 34#define SOLO_SYS_CFG_PLL_PWDN 0x00000004
30#define SOLO6010_SYS_CFG_OUTDIV(__n) (((__n) & 0x003) << 3) /* 6010 only */ 35#define SOLO_SYS_CFG_OUTDIV(__n) (((__n) & 0x003) << 3)
31#define SOLO6010_SYS_CFG_FEEDBACKDIV(__n) (((__n) & 0x1ff) << 5) /* 6010 only */ 36#define SOLO_SYS_CFG_FEEDBACKDIV(__n) (((__n) & 0x1ff) << 5)
32#define SOLO6010_SYS_CFG_INPUTDIV(__n) (((__n) & 0x01f) << 14) /* 6010 only */ 37#define SOLO_SYS_CFG_INPUTDIV(__n) (((__n) & 0x01f) << 14)
33#define SOLO_SYS_CFG_CLOCK_DIV 0x00080000 38#define SOLO_SYS_CFG_CLOCK_DIV 0x00080000
34#define SOLO_SYS_CFG_NCLK_DELAY(__n) (((__n) & 0x003) << 24) 39#define SOLO_SYS_CFG_NCLK_DELAY(__n) (((__n) & 0x003) << 24)
35#define SOLO_SYS_CFG_PCLK_DELAY(__n) (((__n) & 0x00f) << 26) 40#define SOLO_SYS_CFG_PCLK_DELAY(__n) (((__n) & 0x00f) << 26)
36#define SOLO_SYS_CFG_SDRAM64BIT 0x40000000 /* 6110: must be set */ 41#define SOLO_SYS_CFG_SDRAM64BIT 0x40000000
37#define SOLO_SYS_CFG_RESET 0x80000000 42#define SOLO_SYS_CFG_RESET 0x80000000
38 43
39#define SOLO_DMA_CTRL 0x0004 44#define SOLO_DMA_CTRL 0x0004
@@ -45,7 +50,9 @@
45#define SOLO_DMA_CTRL_READ_DATA_SELECT (1<<3) 50#define SOLO_DMA_CTRL_READ_DATA_SELECT (1<<3)
46#define SOLO_DMA_CTRL_READ_CLK_SELECT (1<<2) 51#define SOLO_DMA_CTRL_READ_CLK_SELECT (1<<2)
47#define SOLO_DMA_CTRL_LATENCY(n) ((n)<<0) 52#define SOLO_DMA_CTRL_LATENCY(n) ((n)<<0)
48#define SOLO_DMA_CTRL1 0x0008 53
54/* Some things we set in this are undocumented. Why Softlogic?!?! */
55#define SOLO_DMA_CTRL1 0x0008
49 56
50#define SOLO_SYS_VCLK 0x000C 57#define SOLO_SYS_VCLK 0x000C
51#define SOLO_VCLK_INVERT (1<<22) 58#define SOLO_VCLK_INVERT (1<<22)
@@ -61,7 +68,7 @@
61#define SOLO_VCLK_VIN0001_DELAY(n) ((n)<<0) 68#define SOLO_VCLK_VIN0001_DELAY(n) ((n)<<0)
62 69
63#define SOLO_IRQ_STAT 0x0010 70#define SOLO_IRQ_STAT 0x0010
64#define SOLO_IRQ_ENABLE 0x0014 71#define SOLO_IRQ_MASK 0x0014
65#define SOLO_IRQ_P2M(n) (1<<((n)+17)) 72#define SOLO_IRQ_P2M(n) (1<<((n)+17))
66#define SOLO_IRQ_GPIO (1<<16) 73#define SOLO_IRQ_GPIO (1<<16)
67#define SOLO_IRQ_VIDEO_LOSS (1<<15) 74#define SOLO_IRQ_VIDEO_LOSS (1<<15)
@@ -82,22 +89,7 @@
82#define SOLO_CHIP_OPTION 0x001C 89#define SOLO_CHIP_OPTION 0x001C
83#define SOLO_CHIP_ID_MASK 0x00000007 90#define SOLO_CHIP_ID_MASK 0x00000007
84 91
85#define SOLO6110_PLL_CONFIG 0x0020 92#define SOLO_PLL_CONFIG 0x0020 /* 6110 Only */
86#define SOLO6110_PLL_RANGE_BYPASS (0 << 20)
87#define SOLO6110_PLL_RANGE_5_10MHZ (1 << 20)
88#define SOLO6110_PLL_RANGE_8_16MHZ (2 << 20)
89#define SOLO6110_PLL_RANGE_13_26MHZ (3 << 20)
90#define SOLO6110_PLL_RANGE_21_42MHZ (4 << 20)
91#define SOLO6110_PLL_RANGE_34_68MHZ (5 << 20)
92#define SOLO6110_PLL_RANGE_54_108MHZ (6 << 20)
93#define SOLO6110_PLL_RANGE_88_200MHZ (7 << 20)
94#define SOLO6110_PLL_DIVR(x) (((x) - 1) << 15)
95#define SOLO6110_PLL_DIVQ_EXP(x) ((x) << 12)
96#define SOLO6110_PLL_DIVF(x) (((x) - 1) << 4)
97#define SOLO6110_PLL_RESET (1 << 3)
98#define SOLO6110_PLL_BYPASS (1 << 2)
99#define SOLO6110_PLL_FSEN (1 << 1)
100#define SOLO6110_PLL_FB (1 << 0)
101 93
102#define SOLO_EEPROM_CTRL 0x0060 94#define SOLO_EEPROM_CTRL 0x0060
103#define SOLO_EEPROM_ACCESS_EN (1<<7) 95#define SOLO_EEPROM_ACCESS_EN (1<<7)
@@ -105,7 +97,7 @@
105#define SOLO_EEPROM_CLK (1<<2) 97#define SOLO_EEPROM_CLK (1<<2)
106#define SOLO_EEPROM_DO (1<<1) 98#define SOLO_EEPROM_DO (1<<1)
107#define SOLO_EEPROM_DI (1<<0) 99#define SOLO_EEPROM_DI (1<<0)
108#define SOLO_EEPROM_ENABLE (EEPROM_ACCESS_EN | EEPROM_CS) 100#define SOLO_EEPROM_ENABLE (SOLO_EEPROM_ACCESS_EN | SOLO_EEPROM_CS)
109 101
110#define SOLO_PCI_ERR 0x0070 102#define SOLO_PCI_ERR 0x0070
111#define SOLO_PCI_ERR_FATAL 0x00000001 103#define SOLO_PCI_ERR_FATAL 0x00000001
@@ -274,8 +266,8 @@
274#define SOLO_VO_FI_CHANGE (1<<20) 266#define SOLO_VO_FI_CHANGE (1<<20)
275#define SOLO_VO_USER_COLOR_SET_VSYNC (1<<19) 267#define SOLO_VO_USER_COLOR_SET_VSYNC (1<<19)
276#define SOLO_VO_USER_COLOR_SET_HSYNC (1<<18) 268#define SOLO_VO_USER_COLOR_SET_HSYNC (1<<18)
277#define SOLO_VO_USER_COLOR_SET_NAV (1<<17) 269#define SOLO_VO_USER_COLOR_SET_NAH (1<<17)
278#define SOLO_VO_USER_COLOR_SET_NAH (1<<16) 270#define SOLO_VO_USER_COLOR_SET_NAV (1<<16)
279#define SOLO_VO_NA_COLOR_Y(Y) ((Y)<<8) 271#define SOLO_VO_NA_COLOR_Y(Y) ((Y)<<8)
280#define SOLO_VO_NA_COLOR_CB(CB) (((CB)/16)<<4) 272#define SOLO_VO_NA_COLOR_CB(CB) (((CB)/16)<<4)
281#define SOLO_VO_NA_COLOR_CR(CR) (((CR)/16)<<0) 273#define SOLO_VO_NA_COLOR_CR(CR) (((CR)/16)<<0)
@@ -401,12 +393,13 @@
401#define SOLO_VE_BLOCK_BASE(n) ((n)<<0) 393#define SOLO_VE_BLOCK_BASE(n) ((n)<<0)
402 394
403#define SOLO_VE_CFG1 0x0614 395#define SOLO_VE_CFG1 0x0614
404#define SOLO6110_VE_MPEG_SIZE_H(n) ((n)<<28) /* 6110 only */ 396#define SOLO_VE_BYTE_ALIGN(n) ((n)<<24)
405#define SOLO6010_VE_BYTE_ALIGN(n) ((n)<<24) /* 6010 only */
406#define SOLO6110_VE_JPEG_SIZE_H(n) ((n)<<20) /* 6110 only */
407#define SOLO_VE_INSERT_INDEX (1<<18) 397#define SOLO_VE_INSERT_INDEX (1<<18)
408#define SOLO_VE_MOTION_MODE(n) ((n)<<16) 398#define SOLO_VE_MOTION_MODE(n) ((n)<<16)
409#define SOLO_VE_MOTION_BASE(n) ((n)<<0) 399#define SOLO_VE_MOTION_BASE(n) ((n)<<0)
400#define SOLO_VE_MPEG_SIZE_H(n) ((n)<<28) /* 6110 Only */
401#define SOLO_VE_JPEG_SIZE_H(n) ((n)<<20) /* 6110 Only */
402#define SOLO_VE_INSERT_INDEX_JPEG (1<<19) /* 6110 Only */
410 403
411#define SOLO_VE_WMRK_POLY 0x061C 404#define SOLO_VE_WMRK_POLY 0x061C
412#define SOLO_VE_VMRK_INIT_KEY 0x0620 405#define SOLO_VE_VMRK_INIT_KEY 0x0620
@@ -420,6 +413,7 @@
420#define SOLO_COMP_TIME_INC(n) ((n)<<25) 413#define SOLO_COMP_TIME_INC(n) ((n)<<25)
421#define SOLO_COMP_TIME_WIDTH(n) ((n)<<21) 414#define SOLO_COMP_TIME_WIDTH(n) ((n)<<21)
422#define SOLO_DCT_INTERVAL(n) ((n)<<16) 415#define SOLO_DCT_INTERVAL(n) ((n)<<16)
416#define SOLO_VE_COMPT_MOT 0x0634 /* 6110 Only */
423 417
424#define SOLO_VE_STATE(n) (0x0640+((n)*4)) 418#define SOLO_VE_STATE(n) (0x0640+((n)*4))
425 419
@@ -428,14 +422,21 @@
428#define SOLO_VE_JPEG_QP_CH_H 0x0678 422#define SOLO_VE_JPEG_QP_CH_H 0x0678
429#define SOLO_VE_JPEG_CFG 0x067C 423#define SOLO_VE_JPEG_CFG 0x067C
430#define SOLO_VE_JPEG_CTRL 0x0680 424#define SOLO_VE_JPEG_CTRL 0x0680
431 425#define SOLO_VE_CODE_ENCRYPT 0x0684 /* 6110 Only */
426#define SOLO_VE_JPEG_CFG1 0x0688 /* 6110 Only */
427#define SOLO_VE_WMRK_ENABLE 0x068C /* 6110 Only */
432#define SOLO_VE_OSD_CH 0x0690 428#define SOLO_VE_OSD_CH 0x0690
433#define SOLO_VE_OSD_BASE 0x0694 429#define SOLO_VE_OSD_BASE 0x0694
434#define SOLO_VE_OSD_CLR 0x0698 430#define SOLO_VE_OSD_CLR 0x0698
435#define SOLO_VE_OSD_OPT 0x069C 431#define SOLO_VE_OSD_OPT 0x069C
432#define SOLO_VE_OSD_V_DOUBLE (1<<16) /* 6110 Only */
433#define SOLO_VE_OSD_H_SHADOW (1<<15)
434#define SOLO_VE_OSD_V_SHADOW (1<<14)
435#define SOLO_VE_OSD_H_OFFSET(n) ((n & 0x7f)<<7)
436#define SOLO_VE_OSD_V_OFFSET(n) (n & 0x7f)
436 437
437#define SOLO_VE_CH_INTL(ch) (0x0700+((ch)*4)) 438#define SOLO_VE_CH_INTL(ch) (0x0700+((ch)*4))
438#define SOLO6010_VE_CH_MOT(ch) (0x0740+((ch)*4)) /* 6010 only */ 439#define SOLO_VE_CH_MOT(ch) (0x0740+((ch)*4))
439#define SOLO_VE_CH_QP(ch) (0x0780+((ch)*4)) 440#define SOLO_VE_CH_QP(ch) (0x0780+((ch)*4))
440#define SOLO_VE_CH_QP_E(ch) (0x07C0+((ch)*4)) 441#define SOLO_VE_CH_QP_E(ch) (0x07C0+((ch)*4))
441#define SOLO_VE_CH_GOP(ch) (0x0800+((ch)*4)) 442#define SOLO_VE_CH_GOP(ch) (0x0800+((ch)*4))
@@ -447,7 +448,7 @@
447#define SOLO_VE_JPEG_QUE(n) (0x0A04+((n)*8)) 448#define SOLO_VE_JPEG_QUE(n) (0x0A04+((n)*8))
448 449
449#define SOLO_VD_CFG0 0x0900 450#define SOLO_VD_CFG0 0x0900
450#define SOLO6010_VD_CFG_NO_WRITE_NO_WINDOW (1<<24) /* 6010 only */ 451#define SOLO_VD_CFG_NO_WRITE_NO_WINDOW (1<<24)
451#define SOLO_VD_CFG_BUSY_WIAT_CODE (1<<23) 452#define SOLO_VD_CFG_BUSY_WIAT_CODE (1<<23)
452#define SOLO_VD_CFG_BUSY_WIAT_REF (1<<22) 453#define SOLO_VD_CFG_BUSY_WIAT_REF (1<<22)
453#define SOLO_VD_CFG_BUSY_WIAT_RES (1<<21) 454#define SOLO_VD_CFG_BUSY_WIAT_RES (1<<21)
@@ -599,9 +600,9 @@
599#define SOLO_UART_RX_DATA_POP (1<<8) 600#define SOLO_UART_RX_DATA_POP (1<<8)
600 601
601#define SOLO_TIMER_CLOCK_NUM 0x0be0 602#define SOLO_TIMER_CLOCK_NUM 0x0be0
602#define SOLO_TIMER_WATCHDOG 0x0be4
603#define SOLO_TIMER_USEC 0x0be8 603#define SOLO_TIMER_USEC 0x0be8
604#define SOLO_TIMER_SEC 0x0bec 604#define SOLO_TIMER_SEC 0x0bec
605#define SOLO_TIMER_USEC_LSB 0x0d20 /* 6110 Only */
605 606
606#define SOLO_AUDIO_CONTROL 0x0D00 607#define SOLO_AUDIO_CONTROL 0x0D00
607#define SOLO_AUDIO_ENABLE (1<<31) 608#define SOLO_AUDIO_ENABLE (1<<31)
@@ -629,9 +630,10 @@
629#define SOLO_AUDIO_EVOL(ch, value) ((value)<<((ch)%10)) 630#define SOLO_AUDIO_EVOL(ch, value) ((value)<<((ch)%10))
630#define SOLO_AUDIO_STA 0x0D14 631#define SOLO_AUDIO_STA 0x0D14
631 632
632 633/*
633#define SOLO_WATCHDOG 0x0BE4 634 * Watchdog configuration
634#define WATCHDOG_STAT(status) (status<<8) 635 */
635#define WATCHDOG_TIME(sec) (sec&0xff) 636#define SOLO_WATCHDOG 0x0be4
637#define SOLO_WATCHDOG_SET(status, sec) (status << 8 | (sec & 0xff))
636 638
637#endif /* __SOLO6X10_REGISTERS_H */ 639#endif /* __SOLO6X10_REGISTERS_H */
diff --git a/drivers/staging/media/solo6x10/tw28.c b/drivers/staging/media/solo6x10/solo6x10-tw28.c
index db56b42c56c6..ad00e2b60323 100644
--- a/drivers/staging/media/solo6x10/tw28.c
+++ b/drivers/staging/media/solo6x10/solo6x10-tw28.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -18,12 +23,12 @@
18 */ 23 */
19 24
20#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/delay.h>
27
21#include "solo6x10.h" 28#include "solo6x10.h"
22#include "tw28.h" 29#include "solo6x10-tw28.h"
23 30
24/* XXX: Some of these values are masked into an 8-bit regs, and shifted 31#define DEFAULT_HDELAY_NTSC (32 - 8)
25 * around for other 8-bit regs. What are the magic bits in these values? */
26#define DEFAULT_HDELAY_NTSC (32 - 4)
27#define DEFAULT_HACTIVE_NTSC (720 + 16) 32#define DEFAULT_HACTIVE_NTSC (720 + 16)
28#define DEFAULT_VDELAY_NTSC (7 - 2) 33#define DEFAULT_VDELAY_NTSC (7 - 2)
29#define DEFAULT_VACTIVE_NTSC (240 + 4) 34#define DEFAULT_VACTIVE_NTSC (240 + 4)
@@ -33,15 +38,16 @@
33#define DEFAULT_VDELAY_PAL (6) 38#define DEFAULT_VDELAY_PAL (6)
34#define DEFAULT_VACTIVE_PAL (312-DEFAULT_VDELAY_PAL) 39#define DEFAULT_VACTIVE_PAL (312-DEFAULT_VDELAY_PAL)
35 40
36static u8 tbl_tw2864_template[] = { 41
37 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x00 */ 42static const u8 tbl_tw2864_ntsc_template[] = {
38 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 43 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x00 */
39 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x10 */ 44 0x12, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x00, 0x7f,
40 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 45 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x10 */
41 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x20 */ 46 0x12, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x00, 0x7f,
42 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 47 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x20 */
43 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x30 */ 48 0x12, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x00, 0x7f,
44 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 49 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x30 */
50 0x12, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x00, 0x7f,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */ 51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */ 53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
@@ -61,14 +67,49 @@ static u8 tbl_tw2864_template[] = {
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */ 67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
62 0x00, 0x00, 0x55, 0x00, 0xb1, 0xe4, 0x40, 0x00, 68 0x00, 0x00, 0x55, 0x00, 0xb1, 0xe4, 0x40, 0x00,
63 0x77, 0x77, 0x01, 0x13, 0x57, 0x9b, 0xdf, 0x20, /* 0xd0 */ 69 0x77, 0x77, 0x01, 0x13, 0x57, 0x9b, 0xdf, 0x20, /* 0xd0 */
64 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81, 70 0x64, 0xa8, 0xec, 0xc1, 0x0f, 0x11, 0x11, 0x81,
65 0x10, 0xe0, 0xbb, 0xbb, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */ 71 0x00, 0xe0, 0xbb, 0xbb, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
66 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00, 72 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
67 0x83, 0xb5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, /* 0xf0 */ 73 0x83, 0xb5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, /* 0xf0 */
68 0x64, 0x11, 0x40, 0xaf, 0xff, 0x00, 0x00, 0x00, 74 0x64, 0x11, 0x40, 0xaf, 0xff, 0x00, 0x00, 0x00,
69}; 75};
70 76
71static u8 tbl_tw2865_ntsc_template[] = { 77static const u8 tbl_tw2864_pal_template[] = {
78 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x00 */
79 0x18, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x01, 0x7f,
80 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x10 */
81 0x18, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x01, 0x7f,
82 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x20 */
83 0x18, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x01, 0x7f,
84 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x30 */
85 0x18, 0xf5, 0x0c, 0xd0, 0x00, 0x00, 0x01, 0x7f,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 */
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA3, 0x00,
94 0x00, 0x02, 0x00, 0xcc, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
95 0x22, 0x01, 0xd8, 0xbc, 0xb8, 0x44, 0x38, 0x00,
96 0x00, 0x78, 0x72, 0x3e, 0x14, 0xa5, 0xe4, 0x05, /* 0x90 */
97 0x00, 0x28, 0x44, 0x44, 0xa0, 0x90, 0x5a, 0x01,
98 0x0a, 0x0a, 0x0a, 0x0a, 0x1a, 0x1a, 0x1a, 0x1a, /* 0xa0 */
99 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x44,
100 0x44, 0x0a, 0x00, 0xff, 0xef, 0xef, 0xef, 0xef, /* 0xb0 */
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
103 0x00, 0x00, 0x55, 0x00, 0xb1, 0xe4, 0x40, 0x00,
104 0x77, 0x77, 0x01, 0x13, 0x57, 0x9b, 0xdf, 0x20, /* 0xd0 */
105 0x64, 0xa8, 0xec, 0xc1, 0x0f, 0x11, 0x11, 0x81,
106 0x00, 0xe0, 0xbb, 0xbb, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
107 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
108 0x83, 0xb5, 0x09, 0x00, 0xa0, 0x00, 0x01, 0x20, /* 0xf0 */
109 0x64, 0x11, 0x40, 0xaf, 0xff, 0x00, 0x00, 0x00,
110};
111
112static const u8 tbl_tw2865_ntsc_template[] = {
72 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x00 */ 113 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x00 */
73 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 114 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
74 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x10 */ 115 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x10 */
@@ -103,7 +144,7 @@ static u8 tbl_tw2865_ntsc_template[] = {
103 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0, 144 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0,
104}; 145};
105 146
106static u8 tbl_tw2865_pal_template[] = { 147static const u8 tbl_tw2865_pal_template[] = {
107 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x00 */ 148 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x00 */
108 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f, 149 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
109 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x10 */ 150 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x10 */
@@ -180,8 +221,8 @@ static void tw_write_and_verify(struct solo_dev *solo_dev, u8 addr, u8 off,
180 msleep_interruptible(1); 221 msleep_interruptible(1);
181 } 222 }
182 223
183/* printk("solo6x10/tw28: Error writing register: %02x->%02x [%02x]\n", 224/* printk("solo6x10/tw28: Error writing register: %02x->%02x [%02x]\n", */
184 addr, off, val); */ 225/* addr, off, val); */
185} 226}
186 227
187static int tw2865_setup(struct solo_dev *solo_dev, u8 dev_addr) 228static int tw2865_setup(struct solo_dev *solo_dev, u8 dev_addr)
@@ -216,16 +257,17 @@ static int tw2865_setup(struct solo_dev *solo_dev, u8 dev_addr)
216 257
217 for (i = 0; i < 0xff; i++) { 258 for (i = 0; i < 0xff; i++) {
218 /* Skip read only registers */ 259 /* Skip read only registers */
219 if (i >= 0xb8 && i <= 0xc1) 260 switch (i) {
220 continue; 261 case 0xb8 ... 0xc1:
221 if ((i & ~0x30) == 0x00 || 262 case 0xc4 ... 0xc7:
222 (i & ~0x30) == 0x0c || 263 case 0xfd:
223 (i & ~0x30) == 0x0d)
224 continue;
225 if (i >= 0xc4 && i <= 0xc7)
226 continue; 264 continue;
227 if (i == 0xfd) 265 }
266 switch (i & ~0x30) {
267 case 0x00:
268 case 0x0c ... 0x0d:
228 continue; 269 continue;
270 }
229 271
230 tw_write_and_verify(solo_dev, dev_addr, i, 272 tw_write_and_verify(solo_dev, dev_addr, i,
231 tbl_tw2865_common[i]); 273 tbl_tw2865_common[i]);
@@ -236,11 +278,15 @@ static int tw2865_setup(struct solo_dev *solo_dev, u8 dev_addr)
236 278
237static int tw2864_setup(struct solo_dev *solo_dev, u8 dev_addr) 279static int tw2864_setup(struct solo_dev *solo_dev, u8 dev_addr)
238{ 280{
239 u8 tbl_tw2864_common[sizeof(tbl_tw2864_template)]; 281 u8 tbl_tw2864_common[256];
240 int i; 282 int i;
241 283
242 memcpy(tbl_tw2864_common, tbl_tw2864_template, 284 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_PAL)
243 sizeof(tbl_tw2864_common)); 285 memcpy(tbl_tw2864_common, tbl_tw2864_pal_template,
286 sizeof(tbl_tw2864_common));
287 else
288 memcpy(tbl_tw2864_common, tbl_tw2864_ntsc_template,
289 sizeof(tbl_tw2864_common));
244 290
245 if (solo_dev->tw2865 == 0) { 291 if (solo_dev->tw2865 == 0) {
246 /* IRQ Mode */ 292 /* IRQ Mode */
@@ -285,33 +331,19 @@ static int tw2864_setup(struct solo_dev *solo_dev, u8 dev_addr)
285 } 331 }
286 } 332 }
287 333
288 /* NTSC or PAL */
289 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_PAL) {
290 for (i = 0; i < 4; i++) {
291 tbl_tw2864_common[0x07 | (i << 4)] |= 0x10;
292 tbl_tw2864_common[0x08 | (i << 4)] |= 0x06;
293 tbl_tw2864_common[0x0a | (i << 4)] |= 0x08;
294 tbl_tw2864_common[0x0b | (i << 4)] |= 0x13;
295 tbl_tw2864_common[0x0e | (i << 4)] |= 0x01;
296 }
297 tbl_tw2864_common[0x9d] = 0x90;
298 tbl_tw2864_common[0xf3] = 0x00;
299 tbl_tw2864_common[0xf4] = 0xa0;
300 }
301
302 for (i = 0; i < 0xff; i++) { 334 for (i = 0; i < 0xff; i++) {
303 /* Skip read only registers */ 335 /* Skip read only registers */
304 if (i >= 0xb8 && i <= 0xc1) 336 switch (i) {
337 case 0xb8 ... 0xc1:
338 case 0xfd:
305 continue; 339 continue;
306 if ((i & ~0x30) == 0x00 || 340 }
307 (i & ~0x30) == 0x0c || 341 switch (i & ~0x30) {
308 (i & ~0x30) == 0x0d) 342 case 0x00:
309 continue; 343 case 0x0c:
310 if (i == 0x74 || i == 0x77 || i == 0x78 || 344 case 0x0d:
311 i == 0x79 || i == 0x7a)
312 continue;
313 if (i == 0xfd)
314 continue; 345 continue;
346 }
315 347
316 tw_write_and_verify(solo_dev, dev_addr, i, 348 tw_write_and_verify(solo_dev, dev_addr, i,
317 tbl_tw2864_common[i]); 349 tbl_tw2864_common[i]);
@@ -544,8 +576,10 @@ int solo_tw28_init(struct solo_dev *solo_dev)
544 int i; 576 int i;
545 u8 value; 577 u8 value;
546 578
547 /* Detect techwell chip type */ 579 solo_dev->tw28_cnt = 0;
548 for (i = 0; i < TW_NUM_CHIP; i++) { 580
581 /* Detect techwell chip type(s) */
582 for (i = 0; i < solo_dev->nr_chans / 4; i++) {
549 value = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW, 583 value = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
550 TW_CHIP_OFFSET_ADDR(i), 0xFF); 584 TW_CHIP_OFFSET_ADDR(i), 0xFF);
551 585
@@ -560,7 +594,8 @@ int solo_tw28_init(struct solo_dev *solo_dev)
560 break; 594 break;
561 default: 595 default:
562 value = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW, 596 value = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
563 TW_CHIP_OFFSET_ADDR(i), 0x59); 597 TW_CHIP_OFFSET_ADDR(i),
598 0x59);
564 if ((value >> 3) == 0x04) { 599 if ((value >> 3) == 0x04) {
565 solo_dev->tw2815 |= 1 << i; 600 solo_dev->tw2815 |= 1 << i;
566 solo_dev->tw28_cnt++; 601 solo_dev->tw28_cnt++;
@@ -568,8 +603,11 @@ int solo_tw28_init(struct solo_dev *solo_dev)
568 } 603 }
569 } 604 }
570 605
571 if (!solo_dev->tw28_cnt) 606 if (solo_dev->tw28_cnt != (solo_dev->nr_chans >> 2)) {
607 dev_err(&solo_dev->pdev->dev,
608 "Could not initialize any techwell chips\n");
572 return -EINVAL; 609 return -EINVAL;
610 }
573 611
574 saa7128_setup(solo_dev); 612 saa7128_setup(solo_dev);
575 613
@@ -582,17 +620,6 @@ int solo_tw28_init(struct solo_dev *solo_dev)
582 tw2815_setup(solo_dev, TW_CHIP_OFFSET_ADDR(i)); 620 tw2815_setup(solo_dev, TW_CHIP_OFFSET_ADDR(i));
583 } 621 }
584 622
585 dev_info(&solo_dev->pdev->dev, "Initialized %d tw28xx chip%s:",
586 solo_dev->tw28_cnt, solo_dev->tw28_cnt == 1 ? "" : "s");
587
588 if (solo_dev->tw2865)
589 printk(" tw2865[%d]", hweight32(solo_dev->tw2865));
590 if (solo_dev->tw2864)
591 printk(" tw2864[%d]", hweight32(solo_dev->tw2864));
592 if (solo_dev->tw2815)
593 printk(" tw2815[%d]", hweight32(solo_dev->tw2815));
594 printk("\n");
595
596 return 0; 623 return 0;
597} 624}
598 625
@@ -610,7 +637,7 @@ int tw28_get_video_status(struct solo_dev *solo_dev, u8 ch)
610 chip_num = ch / 4; 637 chip_num = ch / 4;
611 ch %= 4; 638 ch %= 4;
612 639
613 val = tw_readbyte(solo_dev, chip_num, TW286X_AV_STAT_ADDR, 640 val = tw_readbyte(solo_dev, chip_num, TW286x_AV_STAT_ADDR,
614 TW_AV_STAT_ADDR) & 0x0f; 641 TW_AV_STAT_ADDR) & 0x0f;
615 642
616 return val & (1 << ch) ? 1 : 0; 643 return val & (1 << ch) ? 1 : 0;
@@ -626,7 +653,7 @@ u16 tw28_get_audio_status(struct solo_dev *solo_dev)
626 int i; 653 int i;
627 654
628 for (i = 0; i < solo_dev->tw28_cnt; i++) { 655 for (i = 0; i < solo_dev->tw28_cnt; i++) {
629 val = (tw_readbyte(solo_dev, i, TW286X_AV_STAT_ADDR, 656 val = (tw_readbyte(solo_dev, i, TW286x_AV_STAT_ADDR,
630 TW_AV_STAT_ADDR) & 0xf0) >> 4; 657 TW_AV_STAT_ADDR) & 0xf0) >> 4;
631 status |= val << (i * 4); 658 status |= val << (i * 4);
632 } 659 }
@@ -635,7 +662,13 @@ u16 tw28_get_audio_status(struct solo_dev *solo_dev)
635} 662}
636#endif 663#endif
637 664
638int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val) 665bool tw28_has_sharpness(struct solo_dev *solo_dev, u8 ch)
666{
667 return is_tw286x(solo_dev, ch / 4);
668}
669
670int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch,
671 s32 val)
639{ 672{
640 char sval; 673 char sval;
641 u8 chip_num; 674 u8 chip_num;
@@ -650,8 +683,6 @@ int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val)
650 switch (ctrl) { 683 switch (ctrl) {
651 case V4L2_CID_SHARPNESS: 684 case V4L2_CID_SHARPNESS:
652 /* Only 286x has sharpness */ 685 /* Only 286x has sharpness */
653 if (val > 0x0f || val < 0)
654 return -ERANGE;
655 if (is_tw286x(solo_dev, chip_num)) { 686 if (is_tw286x(solo_dev, chip_num)) {
656 u8 v = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW, 687 u8 v = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
657 TW_CHIP_OFFSET_ADDR(chip_num), 688 TW_CHIP_OFFSET_ADDR(chip_num),
@@ -661,8 +692,9 @@ int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val)
661 solo_i2c_writebyte(solo_dev, SOLO_I2C_TW, 692 solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
662 TW_CHIP_OFFSET_ADDR(chip_num), 693 TW_CHIP_OFFSET_ADDR(chip_num),
663 TW286x_SHARPNESS(chip_num), v); 694 TW286x_SHARPNESS(chip_num), v);
664 } else if (val != 0) 695 } else {
665 return -ERANGE; 696 return -EINVAL;
697 }
666 break; 698 break;
667 699
668 case V4L2_CID_HUE: 700 case V4L2_CID_HUE:
@@ -676,6 +708,7 @@ int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val)
676 break; 708 break;
677 709
678 case V4L2_CID_SATURATION: 710 case V4L2_CID_SATURATION:
711 /* 286x chips have a U and V component for saturation */
679 if (is_tw286x(solo_dev, chip_num)) { 712 if (is_tw286x(solo_dev, chip_num)) {
680 solo_i2c_writebyte(solo_dev, SOLO_I2C_TW, 713 solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
681 TW_CHIP_OFFSET_ADDR(chip_num), 714 TW_CHIP_OFFSET_ADDR(chip_num),
diff --git a/drivers/staging/media/solo6x10/tw28.h b/drivers/staging/media/solo6x10/solo6x10-tw28.h
index a44a03afbd30..1a02c87d4cf0 100644
--- a/drivers/staging/media/solo6x10/tw28.h
+++ b/drivers/staging/media/solo6x10/solo6x10-tw28.h
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -36,7 +41,7 @@
36#define TW_AUDIO_INPUT_GAIN_ADDR(n) (0x60 + ((n > 1) ? 1 : 0)) 41#define TW_AUDIO_INPUT_GAIN_ADDR(n) (0x60 + ((n > 1) ? 1 : 0))
37 42
38/* tw286x */ 43/* tw286x */
39#define TW286X_AV_STAT_ADDR 0xfd 44#define TW286x_AV_STAT_ADDR 0xfd
40#define TW286x_HUE_ADDR(n) (0x06 | ((n) << 4)) 45#define TW286x_HUE_ADDR(n) (0x06 | ((n) << 4))
41#define TW286x_SATURATIONU_ADDR(n) (0x04 | ((n) << 4)) 46#define TW286x_SATURATIONU_ADDR(n) (0x04 | ((n) << 4))
42#define TW286x_SATURATIONV_ADDR(n) (0x05 | ((n) << 4)) 47#define TW286x_SATURATIONV_ADDR(n) (0x05 | ((n) << 4))
@@ -50,6 +55,7 @@ int solo_tw28_init(struct solo_dev *solo_dev);
50 55
51int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val); 56int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val);
52int tw28_get_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 *val); 57int tw28_get_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 *val);
58bool tw28_has_sharpness(struct solo_dev *solo_dev, u8 ch);
53 59
54u8 tw28_get_audio_gain(struct solo_dev *solo_dev, u8 ch); 60u8 tw28_get_audio_gain(struct solo_dev *solo_dev, u8 ch);
55void tw28_set_audio_gain(struct solo_dev *solo_dev, u8 ch, u8 val); 61void tw28_set_audio_gain(struct solo_dev *solo_dev, u8 ch, u8 val);
diff --git a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
new file mode 100644
index 000000000000..98e2902afd74
--- /dev/null
+++ b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
@@ -0,0 +1,1385 @@
1/*
2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/freezer.h>
29
30#include <media/v4l2-ioctl.h>
31#include <media/v4l2-common.h>
32#include <media/v4l2-event.h>
33#include <media/videobuf2-dma-sg.h>
34
35#include "solo6x10.h"
36#include "solo6x10-tw28.h"
37#include "solo6x10-jpeg.h"
38
39#define MIN_VID_BUFFERS 2
40#define FRAME_BUF_SIZE (196 * 1024)
41#define MP4_QS 16
42#define DMA_ALIGN 4096
43
44/* 6010 M4V */
45static unsigned char vop_6010_ntsc_d1[] = {
46 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
47 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40,
48 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
49 0x1f, 0x4c, 0x58, 0x10, 0xf0, 0x71, 0x18, 0x3f,
50};
51
52static unsigned char vop_6010_ntsc_cif[] = {
53 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
54 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40,
55 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
56 0x1f, 0x4c, 0x2c, 0x10, 0x78, 0x51, 0x18, 0x3f,
57};
58
59static unsigned char vop_6010_pal_d1[] = {
60 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
61 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40,
62 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
63 0x1f, 0x4c, 0x58, 0x11, 0x20, 0x71, 0x18, 0x3f,
64};
65
66static unsigned char vop_6010_pal_cif[] = {
67 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
68 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40,
69 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
70 0x1f, 0x4c, 0x2c, 0x10, 0x90, 0x51, 0x18, 0x3f,
71};
72
73/* 6110 h.264 */
74static unsigned char vop_6110_ntsc_d1[] = {
75 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
76 0x9a, 0x74, 0x05, 0x81, 0xec, 0x80, 0x00, 0x00,
77 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00,
78};
79
80static unsigned char vop_6110_ntsc_cif[] = {
81 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
82 0x9a, 0x74, 0x0b, 0x0f, 0xc8, 0x00, 0x00, 0x00,
83 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
84};
85
86static unsigned char vop_6110_pal_d1[] = {
87 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
88 0x9a, 0x74, 0x05, 0x80, 0x93, 0x20, 0x00, 0x00,
89 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00,
90};
91
92static unsigned char vop_6110_pal_cif[] = {
93 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
94 0x9a, 0x74, 0x0b, 0x04, 0xb2, 0x00, 0x00, 0x00,
95 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
96};
97
98struct vop_header {
99 /* VE_STATUS0 */
100 u32 mpeg_size:20, sad_motion_flag:1, video_motion_flag:1, vop_type:2,
101 channel:5, source_fl:1, interlace:1, progressive:1;
102
103 /* VE_STATUS1 */
104 u32 vsize:8, hsize:8, last_queue:4, nop0:8, scale:4;
105
106 /* VE_STATUS2 */
107 u32 mpeg_off;
108
109 /* VE_STATUS3 */
110 u32 jpeg_off;
111
112 /* VE_STATUS4 */
113 u32 jpeg_size:20, interval:10, nop1:2;
114
115 /* VE_STATUS5/6 */
116 u32 sec, usec;
117
118 /* VE_STATUS7/8/9 */
119 u32 nop2[3];
120
121 /* VE_STATUS10 */
122 u32 mpeg_size_alt:20, nop3:12;
123
124 u32 end_nops[5];
125} __packed;
126
127struct solo_enc_buf {
128 enum solo_enc_types type;
129 struct vop_header *vh;
130 int motion;
131};
132
133static int solo_is_motion_on(struct solo_enc_dev *solo_enc)
134{
135 struct solo_dev *solo_dev = solo_enc->solo_dev;
136
137 return (solo_dev->motion_mask >> solo_enc->ch) & 1;
138}
139
140static int solo_motion_detected(struct solo_enc_dev *solo_enc)
141{
142 struct solo_dev *solo_dev = solo_enc->solo_dev;
143 unsigned long flags;
144 u32 ch_mask = 1 << solo_enc->ch;
145 int ret = 0;
146
147 spin_lock_irqsave(&solo_enc->motion_lock, flags);
148 if (solo_reg_read(solo_dev, SOLO_VI_MOT_STATUS) & ch_mask) {
149 solo_reg_write(solo_dev, SOLO_VI_MOT_CLEAR, ch_mask);
150 ret = 1;
151 }
152 spin_unlock_irqrestore(&solo_enc->motion_lock, flags);
153
154 return ret;
155}
156
157static void solo_motion_toggle(struct solo_enc_dev *solo_enc, int on)
158{
159 struct solo_dev *solo_dev = solo_enc->solo_dev;
160 u32 mask = 1 << solo_enc->ch;
161 unsigned long flags;
162
163 spin_lock_irqsave(&solo_enc->motion_lock, flags);
164
165 if (on)
166 solo_dev->motion_mask |= mask;
167 else
168 solo_dev->motion_mask &= ~mask;
169
170 solo_reg_write(solo_dev, SOLO_VI_MOT_CLEAR, mask);
171
172 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR,
173 SOLO_VI_MOTION_EN(solo_dev->motion_mask) |
174 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16));
175
176 spin_unlock_irqrestore(&solo_enc->motion_lock, flags);
177}
178
179void solo_update_mode(struct solo_enc_dev *solo_enc)
180{
181 struct solo_dev *solo_dev = solo_enc->solo_dev;
182 int vop_len;
183 unsigned char *vop;
184
185 solo_enc->interlaced = (solo_enc->mode & 0x08) ? 1 : 0;
186 solo_enc->bw_weight = max(solo_dev->fps / solo_enc->interval, 1);
187
188 if (solo_enc->mode == SOLO_ENC_MODE_CIF) {
189 solo_enc->width = solo_dev->video_hsize >> 1;
190 solo_enc->height = solo_dev->video_vsize;
191 if (solo_dev->type == SOLO_DEV_6110) {
192 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
193 vop = vop_6110_ntsc_cif;
194 vop_len = sizeof(vop_6110_ntsc_cif);
195 } else {
196 vop = vop_6110_pal_cif;
197 vop_len = sizeof(vop_6110_pal_cif);
198 }
199 } else {
200 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
201 vop = vop_6010_ntsc_cif;
202 vop_len = sizeof(vop_6010_ntsc_cif);
203 } else {
204 vop = vop_6010_pal_cif;
205 vop_len = sizeof(vop_6010_pal_cif);
206 }
207 }
208 } else {
209 solo_enc->width = solo_dev->video_hsize;
210 solo_enc->height = solo_dev->video_vsize << 1;
211 solo_enc->bw_weight <<= 2;
212 if (solo_dev->type == SOLO_DEV_6110) {
213 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
214 vop = vop_6110_ntsc_d1;
215 vop_len = sizeof(vop_6110_ntsc_d1);
216 } else {
217 vop = vop_6110_pal_d1;
218 vop_len = sizeof(vop_6110_pal_d1);
219 }
220 } else {
221 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
222 vop = vop_6010_ntsc_d1;
223 vop_len = sizeof(vop_6010_ntsc_d1);
224 } else {
225 vop = vop_6010_pal_d1;
226 vop_len = sizeof(vop_6010_pal_d1);
227 }
228 }
229 }
230
231 memcpy(solo_enc->vop, vop, vop_len);
232
233 /* Some fixups for 6010/M4V */
234 if (solo_dev->type == SOLO_DEV_6010) {
235 u16 fps = solo_dev->fps * 1000;
236 u16 interval = solo_enc->interval * 1000;
237
238 vop = solo_enc->vop;
239
240 /* Frame rate and interval */
241 vop[22] = fps >> 4;
242 vop[23] = ((fps << 4) & 0xf0) | 0x0c
243 | ((interval >> 13) & 0x3);
244 vop[24] = (interval >> 5) & 0xff;
245 vop[25] = ((interval << 3) & 0xf8) | 0x04;
246 }
247
248 solo_enc->vop_len = vop_len;
249
250 /* Now handle the jpeg header */
251 vop = solo_enc->jpeg_header;
252 vop[SOF0_START + 5] = 0xff & (solo_enc->height >> 8);
253 vop[SOF0_START + 6] = 0xff & solo_enc->height;
254 vop[SOF0_START + 7] = 0xff & (solo_enc->width >> 8);
255 vop[SOF0_START + 8] = 0xff & solo_enc->width;
256
257 memcpy(vop + DQT_START,
258 jpeg_dqt[solo_g_jpeg_qp(solo_dev, solo_enc->ch)], DQT_LEN);
259}
260
261static int solo_enc_on(struct solo_enc_dev *solo_enc)
262{
263 u8 ch = solo_enc->ch;
264 struct solo_dev *solo_dev = solo_enc->solo_dev;
265 u8 interval;
266
267 solo_update_mode(solo_enc);
268
269 /* Make sure to do a bandwidth check */
270 if (solo_enc->bw_weight > solo_dev->enc_bw_remain)
271 return -EBUSY;
272 solo_enc->sequence = 0;
273 solo_dev->enc_bw_remain -= solo_enc->bw_weight;
274
275 if (solo_enc->type == SOLO_ENC_TYPE_EXT)
276 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(ch), 1);
277
278 /* Disable all encoding for this channel */
279 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), 0);
280
281 /* Common for both std and ext encoding */
282 solo_reg_write(solo_dev, SOLO_VE_CH_INTL(ch),
283 solo_enc->interlaced ? 1 : 0);
284
285 if (solo_enc->interlaced)
286 interval = solo_enc->interval - 1;
287 else
288 interval = solo_enc->interval;
289
290 /* Standard encoding only */
291 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(ch), solo_enc->gop);
292 solo_reg_write(solo_dev, SOLO_VE_CH_QP(ch), solo_enc->qp);
293 solo_reg_write(solo_dev, SOLO_CAP_CH_INTV(ch), interval);
294
295 /* Extended encoding only */
296 solo_reg_write(solo_dev, SOLO_VE_CH_GOP_E(ch), solo_enc->gop);
297 solo_reg_write(solo_dev, SOLO_VE_CH_QP_E(ch), solo_enc->qp);
298 solo_reg_write(solo_dev, SOLO_CAP_CH_INTV_E(ch), interval);
299
300 /* Enables the standard encoder */
301 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), solo_enc->mode);
302
303 return 0;
304}
305
306static void solo_enc_off(struct solo_enc_dev *solo_enc)
307{
308 struct solo_dev *solo_dev = solo_enc->solo_dev;
309
310 solo_dev->enc_bw_remain += solo_enc->bw_weight;
311
312 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(solo_enc->ch), 0);
313 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(solo_enc->ch), 0);
314}
315
316static int enc_get_mpeg_dma(struct solo_dev *solo_dev, dma_addr_t dma,
317 unsigned int off, unsigned int size)
318{
319 int ret;
320
321 if (off > SOLO_MP4E_EXT_SIZE(solo_dev))
322 return -EINVAL;
323
324 /* Single shot */
325 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) {
326 return solo_p2m_dma_t(solo_dev, 0, dma,
327 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size,
328 0, 0);
329 }
330
331 /* Buffer wrap */
332 ret = solo_p2m_dma_t(solo_dev, 0, dma,
333 SOLO_MP4E_EXT_ADDR(solo_dev) + off,
334 SOLO_MP4E_EXT_SIZE(solo_dev) - off, 0, 0);
335
336 if (!ret) {
337 ret = solo_p2m_dma_t(solo_dev, 0,
338 dma + SOLO_MP4E_EXT_SIZE(solo_dev) - off,
339 SOLO_MP4E_EXT_ADDR(solo_dev),
340 size + off - SOLO_MP4E_EXT_SIZE(solo_dev), 0, 0);
341 }
342
343 return ret;
344}
345
346/* Build a descriptor queue out of an SG list and send it to the P2M for
347 * processing. */
348static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
349 struct vb2_dma_sg_desc *vbuf, int off, int size,
350 unsigned int base, unsigned int base_size)
351{
352 struct solo_dev *solo_dev = solo_enc->solo_dev;
353 struct scatterlist *sg;
354 int i;
355 int ret;
356
357 if (WARN_ON_ONCE(size > FRAME_BUF_SIZE))
358 return -EINVAL;
359
360 solo_enc->desc_count = 1;
361
362 for_each_sg(vbuf->sglist, sg, vbuf->num_pages, i) {
363 struct solo_p2m_desc *desc;
364 dma_addr_t dma;
365 int len;
366 int left = base_size - off;
367
368 desc = &solo_enc->desc_items[solo_enc->desc_count++];
369 dma = sg_dma_address(sg);
370 len = sg_dma_len(sg);
371
372 /* We assume this is smaller than the scatter size */
373 BUG_ON(skip >= len);
374 if (skip) {
375 len -= skip;
376 dma += skip;
377 size -= skip;
378 skip = 0;
379 }
380
381 len = min(len, size);
382
383 if (len <= left) {
384 /* Single descriptor */
385 solo_p2m_fill_desc(desc, 0, dma, base + off,
386 len, 0, 0);
387 } else {
388 /* Buffer wrap */
389 /* XXX: Do these as separate DMA requests, to avoid
390 timeout errors triggered by awkwardly sized
391 descriptors. See
392 <https://github.com/bluecherrydvr/solo6x10/issues/8>
393 */
394 ret = solo_p2m_dma_t(solo_dev, 0, dma, base + off,
395 left, 0, 0);
396 if (ret)
397 return ret;
398
399 ret = solo_p2m_dma_t(solo_dev, 0, dma + left, base,
400 len - left, 0, 0);
401 if (ret)
402 return ret;
403
404 solo_enc->desc_count--;
405 }
406
407 size -= len;
408 if (size <= 0)
409 break;
410
411 off += len;
412 if (off >= base_size)
413 off -= base_size;
414
415 /* Because we may use two descriptors per loop */
416 if (solo_enc->desc_count >= (solo_enc->desc_nelts - 1)) {
417 ret = solo_p2m_dma_desc(solo_dev, solo_enc->desc_items,
418 solo_enc->desc_dma,
419 solo_enc->desc_count - 1);
420 if (ret)
421 return ret;
422 solo_enc->desc_count = 1;
423 }
424 }
425
426 if (solo_enc->desc_count <= 1)
427 return 0;
428
429 return solo_p2m_dma_desc(solo_dev, solo_enc->desc_items, solo_enc->desc_dma,
430 solo_enc->desc_count - 1);
431}
432
433static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
434 struct vb2_buffer *vb, struct vop_header *vh)
435{
436 struct solo_dev *solo_dev = solo_enc->solo_dev;
437 struct vb2_dma_sg_desc *vbuf = vb2_dma_sg_plane_desc(vb, 0);
438 int frame_size;
439 int ret;
440
441 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
442
443 if (vb2_plane_size(vb, 0) < vh->jpeg_size + solo_enc->jpeg_len)
444 return -EIO;
445
446 sg_copy_from_buffer(vbuf->sglist, vbuf->num_pages,
447 solo_enc->jpeg_header,
448 solo_enc->jpeg_len);
449
450 frame_size = (vh->jpeg_size + solo_enc->jpeg_len + (DMA_ALIGN - 1))
451 & ~(DMA_ALIGN - 1);
452 vb2_set_plane_payload(vb, 0, vh->jpeg_size + solo_enc->jpeg_len);
453
454 dma_map_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
455 DMA_FROM_DEVICE);
456 ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf, vh->jpeg_off,
457 frame_size, SOLO_JPEG_EXT_ADDR(solo_dev),
458 SOLO_JPEG_EXT_SIZE(solo_dev));
459 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
460 DMA_FROM_DEVICE);
461 return ret;
462}
463
464static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
465 struct vb2_buffer *vb, struct vop_header *vh)
466{
467 struct solo_dev *solo_dev = solo_enc->solo_dev;
468 struct vb2_dma_sg_desc *vbuf = vb2_dma_sg_plane_desc(vb, 0);
469 int frame_off, frame_size;
470 int skip = 0;
471 int ret;
472
473 if (vb2_plane_size(vb, 0) < vh->mpeg_size)
474 return -EIO;
475
476 /* If this is a key frame, add extra header */
477 if (!vh->vop_type) {
478 sg_copy_from_buffer(vbuf->sglist, vbuf->num_pages,
479 solo_enc->vop,
480 solo_enc->vop_len);
481
482 skip = solo_enc->vop_len;
483
484 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
485 vb2_set_plane_payload(vb, 0, vh->mpeg_size + solo_enc->vop_len);
486 } else {
487 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
488 vb2_set_plane_payload(vb, 0, vh->mpeg_size);
489 }
490
491 /* Now get the actual mpeg payload */
492 frame_off = (vh->mpeg_off + sizeof(*vh))
493 % SOLO_MP4E_EXT_SIZE(solo_dev);
494 frame_size = (vh->mpeg_size + skip + (DMA_ALIGN - 1))
495 & ~(DMA_ALIGN - 1);
496
497 dma_map_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
498 DMA_FROM_DEVICE);
499 ret = solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size,
500 SOLO_MP4E_EXT_ADDR(solo_dev),
501 SOLO_MP4E_EXT_SIZE(solo_dev));
502 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
503 DMA_FROM_DEVICE);
504 return ret;
505}
506
507static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
508 struct vb2_buffer *vb, struct solo_enc_buf *enc_buf)
509{
510 struct vop_header *vh = enc_buf->vh;
511 int ret;
512
513 /* Check for motion flags */
514 vb->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_MOTION_ON |
515 V4L2_BUF_FLAG_MOTION_DETECTED);
516 if (solo_is_motion_on(solo_enc)) {
517 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_MOTION_ON;
518 if (enc_buf->motion)
519 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_MOTION_DETECTED;
520 }
521
522 switch (solo_enc->fmt) {
523 case V4L2_PIX_FMT_MPEG4:
524 case V4L2_PIX_FMT_H264:
525 ret = solo_fill_mpeg(solo_enc, vb, vh);
526 break;
527 default: /* V4L2_PIX_FMT_MJPEG */
528 ret = solo_fill_jpeg(solo_enc, vb, vh);
529 break;
530 }
531
532 if (!ret) {
533 vb->v4l2_buf.sequence = solo_enc->sequence++;
534 vb->v4l2_buf.timestamp.tv_sec = vh->sec;
535 vb->v4l2_buf.timestamp.tv_usec = vh->usec;
536 }
537
538 vb2_buffer_done(vb, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
539
540 return ret;
541}
542
543static void solo_enc_handle_one(struct solo_enc_dev *solo_enc,
544 struct solo_enc_buf *enc_buf)
545{
546 struct solo_vb2_buf *vb;
547 unsigned long flags;
548
549 mutex_lock(&solo_enc->lock);
550 if (solo_enc->type != enc_buf->type)
551 goto unlock;
552
553 spin_lock_irqsave(&solo_enc->av_lock, flags);
554 if (list_empty(&solo_enc->vidq_active)) {
555 spin_unlock_irqrestore(&solo_enc->av_lock, flags);
556 goto unlock;
557 }
558 vb = list_first_entry(&solo_enc->vidq_active, struct solo_vb2_buf, list);
559 list_del(&vb->list);
560 spin_unlock_irqrestore(&solo_enc->av_lock, flags);
561
562 solo_enc_fillbuf(solo_enc, &vb->vb, enc_buf);
563unlock:
564 mutex_unlock(&solo_enc->lock);
565}
566
567void solo_enc_v4l2_isr(struct solo_dev *solo_dev)
568{
569 wake_up_interruptible_all(&solo_dev->ring_thread_wait);
570}
571
572static void solo_handle_ring(struct solo_dev *solo_dev)
573{
574 for (;;) {
575 struct solo_enc_dev *solo_enc;
576 struct solo_enc_buf enc_buf;
577 u32 mpeg_current, off;
578 u8 ch;
579 u8 cur_q;
580
581 /* Check if the hardware has any new ones in the queue */
582 cur_q = solo_reg_read(solo_dev, SOLO_VE_STATE(11)) & 0xff;
583 if (cur_q == solo_dev->enc_idx)
584 break;
585
586 mpeg_current = solo_reg_read(solo_dev,
587 SOLO_VE_MPEG4_QUE(solo_dev->enc_idx));
588 solo_dev->enc_idx = (solo_dev->enc_idx + 1) % MP4_QS;
589
590 ch = (mpeg_current >> 24) & 0x1f;
591 off = mpeg_current & 0x00ffffff;
592
593 if (ch >= SOLO_MAX_CHANNELS) {
594 ch -= SOLO_MAX_CHANNELS;
595 enc_buf.type = SOLO_ENC_TYPE_EXT;
596 } else
597 enc_buf.type = SOLO_ENC_TYPE_STD;
598
599 solo_enc = solo_dev->v4l2_enc[ch];
600 if (solo_enc == NULL) {
601 dev_err(&solo_dev->pdev->dev,
602 "Got spurious packet for channel %d\n", ch);
603 continue;
604 }
605
606 /* FAIL... */
607 if (enc_get_mpeg_dma(solo_dev, solo_dev->vh_dma, off,
608 sizeof(struct vop_header)))
609 continue;
610
611 enc_buf.vh = (struct vop_header *)solo_dev->vh_buf;
612 enc_buf.vh->mpeg_off -= SOLO_MP4E_EXT_ADDR(solo_dev);
613 enc_buf.vh->jpeg_off -= SOLO_JPEG_EXT_ADDR(solo_dev);
614
615 /* Sanity check */
616 if (enc_buf.vh->mpeg_off != off)
617 continue;
618
619 if (solo_motion_detected(solo_enc))
620 enc_buf.motion = 1;
621 else
622 enc_buf.motion = 0;
623
624 solo_enc_handle_one(solo_enc, &enc_buf);
625 }
626}
627
628static int solo_ring_thread(void *data)
629{
630 struct solo_dev *solo_dev = data;
631 DECLARE_WAITQUEUE(wait, current);
632
633 set_freezable();
634 add_wait_queue(&solo_dev->ring_thread_wait, &wait);
635
636 for (;;) {
637 long timeout = schedule_timeout_interruptible(HZ);
638 if (timeout == -ERESTARTSYS || kthread_should_stop())
639 break;
640 solo_irq_off(solo_dev, SOLO_IRQ_ENCODER);
641 solo_handle_ring(solo_dev);
642 solo_irq_on(solo_dev, SOLO_IRQ_ENCODER);
643 try_to_freeze();
644 }
645
646 remove_wait_queue(&solo_dev->ring_thread_wait, &wait);
647
648 return 0;
649}
650
651static int solo_enc_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
652 unsigned int *num_buffers, unsigned int *num_planes,
653 unsigned int sizes[], void *alloc_ctxs[])
654{
655 sizes[0] = FRAME_BUF_SIZE;
656 *num_planes = 1;
657
658 if (*num_buffers < MIN_VID_BUFFERS)
659 *num_buffers = MIN_VID_BUFFERS;
660
661 return 0;
662}
663
664static void solo_enc_buf_queue(struct vb2_buffer *vb)
665{
666 struct vb2_queue *vq = vb->vb2_queue;
667 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vq);
668 struct solo_vb2_buf *solo_vb =
669 container_of(vb, struct solo_vb2_buf, vb);
670
671 spin_lock(&solo_enc->av_lock);
672 list_add_tail(&solo_vb->list, &solo_enc->vidq_active);
673 spin_unlock(&solo_enc->av_lock);
674}
675
676static int solo_ring_start(struct solo_dev *solo_dev)
677{
678 solo_dev->ring_thread = kthread_run(solo_ring_thread, solo_dev,
679 SOLO6X10_NAME "_ring");
680 if (IS_ERR(solo_dev->ring_thread)) {
681 int err = PTR_ERR(solo_dev->ring_thread);
682 solo_dev->ring_thread = NULL;
683 return err;
684 }
685
686 solo_irq_on(solo_dev, SOLO_IRQ_ENCODER);
687
688 return 0;
689}
690
691static void solo_ring_stop(struct solo_dev *solo_dev)
692{
693 if (solo_dev->ring_thread) {
694 kthread_stop(solo_dev->ring_thread);
695 solo_dev->ring_thread = NULL;
696 }
697
698 solo_irq_off(solo_dev, SOLO_IRQ_ENCODER);
699}
700
701static int solo_enc_start_streaming(struct vb2_queue *q, unsigned int count)
702{
703 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q);
704 int ret;
705
706 ret = solo_enc_on(solo_enc);
707 if (ret)
708 return ret;
709 return solo_ring_start(solo_enc->solo_dev);
710}
711
712static int solo_enc_stop_streaming(struct vb2_queue *q)
713{
714 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q);
715
716 solo_enc_off(solo_enc);
717 INIT_LIST_HEAD(&solo_enc->vidq_active);
718 solo_ring_stop(solo_enc->solo_dev);
719 return 0;
720}
721
722static struct vb2_ops solo_enc_video_qops = {
723 .queue_setup = solo_enc_queue_setup,
724 .buf_queue = solo_enc_buf_queue,
725 .start_streaming = solo_enc_start_streaming,
726 .stop_streaming = solo_enc_stop_streaming,
727 .wait_prepare = vb2_ops_wait_prepare,
728 .wait_finish = vb2_ops_wait_finish,
729};
730
731static int solo_enc_querycap(struct file *file, void *priv,
732 struct v4l2_capability *cap)
733{
734 struct solo_enc_dev *solo_enc = video_drvdata(file);
735 struct solo_dev *solo_dev = solo_enc->solo_dev;
736
737 strcpy(cap->driver, SOLO6X10_NAME);
738 snprintf(cap->card, sizeof(cap->card), "Softlogic 6x10 Enc %d",
739 solo_enc->ch);
740 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
741 pci_name(solo_dev->pdev));
742 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
743 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
744 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
745 return 0;
746}
747
748static int solo_enc_enum_input(struct file *file, void *priv,
749 struct v4l2_input *input)
750{
751 struct solo_enc_dev *solo_enc = video_drvdata(file);
752 struct solo_dev *solo_dev = solo_enc->solo_dev;
753
754 if (input->index)
755 return -EINVAL;
756
757 snprintf(input->name, sizeof(input->name), "Encoder %d",
758 solo_enc->ch + 1);
759 input->type = V4L2_INPUT_TYPE_CAMERA;
760 input->std = solo_enc->vfd->tvnorms;
761
762 if (!tw28_get_video_status(solo_dev, solo_enc->ch))
763 input->status = V4L2_IN_ST_NO_SIGNAL;
764
765 return 0;
766}
767
768static int solo_enc_set_input(struct file *file, void *priv,
769 unsigned int index)
770{
771 if (index)
772 return -EINVAL;
773
774 return 0;
775}
776
777static int solo_enc_get_input(struct file *file, void *priv,
778 unsigned int *index)
779{
780 *index = 0;
781
782 return 0;
783}
784
785static int solo_enc_enum_fmt_cap(struct file *file, void *priv,
786 struct v4l2_fmtdesc *f)
787{
788 struct solo_enc_dev *solo_enc = video_drvdata(file);
789 int dev_type = solo_enc->solo_dev->type;
790
791 switch (f->index) {
792 case 0:
793 switch (dev_type) {
794 case SOLO_DEV_6010:
795 f->pixelformat = V4L2_PIX_FMT_MPEG4;
796 strcpy(f->description, "MPEG-4 part 2");
797 break;
798 case SOLO_DEV_6110:
799 f->pixelformat = V4L2_PIX_FMT_H264;
800 strcpy(f->description, "H.264");
801 break;
802 }
803 break;
804 case 1:
805 f->pixelformat = V4L2_PIX_FMT_MJPEG;
806 strcpy(f->description, "MJPEG");
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 f->flags = V4L2_FMT_FLAG_COMPRESSED;
813
814 return 0;
815}
816
817static inline int solo_valid_pixfmt(u32 pixfmt, int dev_type)
818{
819 return (pixfmt == V4L2_PIX_FMT_H264 && dev_type == SOLO_DEV_6110)
820 || (pixfmt == V4L2_PIX_FMT_MPEG4 && dev_type == SOLO_DEV_6010)
821 || pixfmt == V4L2_PIX_FMT_MJPEG ? 0 : -EINVAL;
822}
823
824static int solo_enc_try_fmt_cap(struct file *file, void *priv,
825 struct v4l2_format *f)
826{
827 struct solo_enc_dev *solo_enc = video_drvdata(file);
828 struct solo_dev *solo_dev = solo_enc->solo_dev;
829 struct v4l2_pix_format *pix = &f->fmt.pix;
830
831 if (solo_valid_pixfmt(pix->pixelformat, solo_dev->type))
832 return -EINVAL;
833
834 if (pix->width < solo_dev->video_hsize ||
835 pix->height < solo_dev->video_vsize << 1) {
836 /* Default to CIF 1/2 size */
837 pix->width = solo_dev->video_hsize >> 1;
838 pix->height = solo_dev->video_vsize;
839 } else {
840 /* Full frame */
841 pix->width = solo_dev->video_hsize;
842 pix->height = solo_dev->video_vsize << 1;
843 }
844
845 switch (pix->field) {
846 case V4L2_FIELD_NONE:
847 case V4L2_FIELD_INTERLACED:
848 break;
849 case V4L2_FIELD_ANY:
850 default:
851 pix->field = V4L2_FIELD_INTERLACED;
852 break;
853 }
854
855 /* Just set these */
856 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
857 pix->sizeimage = FRAME_BUF_SIZE;
858 pix->bytesperline = 0;
859 pix->priv = 0;
860
861 return 0;
862}
863
864static int solo_enc_set_fmt_cap(struct file *file, void *priv,
865 struct v4l2_format *f)
866{
867 struct solo_enc_dev *solo_enc = video_drvdata(file);
868 struct solo_dev *solo_dev = solo_enc->solo_dev;
869 struct v4l2_pix_format *pix = &f->fmt.pix;
870 int ret;
871
872 if (vb2_is_busy(&solo_enc->vidq))
873 return -EBUSY;
874
875 ret = solo_enc_try_fmt_cap(file, priv, f);
876 if (ret)
877 return ret;
878
879 if (pix->width == solo_dev->video_hsize)
880 solo_enc->mode = SOLO_ENC_MODE_D1;
881 else
882 solo_enc->mode = SOLO_ENC_MODE_CIF;
883
884 /* This does not change the encoder at all */
885 solo_enc->fmt = pix->pixelformat;
886
887 /*
888 * More information is needed about these 'extended' types. As far
889 * as I can tell these are basically additional video streams with
890 * different MPEG encoding attributes that can run in parallel with
891 * the main stream. If so, then this should be implemented as a
892 * second video node. Abusing priv like this is certainly not the
893 * right approach.
894 if (pix->priv)
895 solo_enc->type = SOLO_ENC_TYPE_EXT;
896 */
897 solo_update_mode(solo_enc);
898 return 0;
899}
900
901static int solo_enc_get_fmt_cap(struct file *file, void *priv,
902 struct v4l2_format *f)
903{
904 struct solo_enc_dev *solo_enc = video_drvdata(file);
905 struct v4l2_pix_format *pix = &f->fmt.pix;
906
907 pix->width = solo_enc->width;
908 pix->height = solo_enc->height;
909 pix->pixelformat = solo_enc->fmt;
910 pix->field = solo_enc->interlaced ? V4L2_FIELD_INTERLACED :
911 V4L2_FIELD_NONE;
912 pix->sizeimage = FRAME_BUF_SIZE;
913 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
914 pix->priv = 0;
915
916 return 0;
917}
918
919static int solo_enc_g_std(struct file *file, void *priv, v4l2_std_id *i)
920{
921 struct solo_enc_dev *solo_enc = video_drvdata(file);
922 struct solo_dev *solo_dev = solo_enc->solo_dev;
923
924 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
925 *i = V4L2_STD_NTSC_M;
926 else
927 *i = V4L2_STD_PAL;
928 return 0;
929}
930
931static int solo_enc_s_std(struct file *file, void *priv, v4l2_std_id std)
932{
933 struct solo_enc_dev *solo_enc = video_drvdata(file);
934
935 return solo_set_video_type(solo_enc->solo_dev, std & V4L2_STD_PAL);
936}
937
938static int solo_enum_framesizes(struct file *file, void *priv,
939 struct v4l2_frmsizeenum *fsize)
940{
941 struct solo_enc_dev *solo_enc = video_drvdata(file);
942 struct solo_dev *solo_dev = solo_enc->solo_dev;
943
944 if (solo_valid_pixfmt(fsize->pixel_format, solo_dev->type))
945 return -EINVAL;
946
947 switch (fsize->index) {
948 case 0:
949 fsize->discrete.width = solo_dev->video_hsize >> 1;
950 fsize->discrete.height = solo_dev->video_vsize;
951 break;
952 case 1:
953 fsize->discrete.width = solo_dev->video_hsize;
954 fsize->discrete.height = solo_dev->video_vsize << 1;
955 break;
956 default:
957 return -EINVAL;
958 }
959
960 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
961
962 return 0;
963}
964
965static int solo_enum_frameintervals(struct file *file, void *priv,
966 struct v4l2_frmivalenum *fintv)
967{
968 struct solo_enc_dev *solo_enc = video_drvdata(file);
969 struct solo_dev *solo_dev = solo_enc->solo_dev;
970
971 if (solo_valid_pixfmt(fintv->pixel_format, solo_dev->type))
972 return -EINVAL;
973 if (fintv->index)
974 return -EINVAL;
975 if ((fintv->width != solo_dev->video_hsize >> 1 ||
976 fintv->height != solo_dev->video_vsize) &&
977 (fintv->width != solo_dev->video_hsize ||
978 fintv->height != solo_dev->video_vsize << 1))
979 return -EINVAL;
980
981 fintv->type = V4L2_FRMIVAL_TYPE_STEPWISE;
982
983 fintv->stepwise.min.numerator = 1;
984 fintv->stepwise.min.denominator = solo_dev->fps;
985
986 fintv->stepwise.max.numerator = 15;
987 fintv->stepwise.max.denominator = solo_dev->fps;
988
989 fintv->stepwise.step.numerator = 1;
990 fintv->stepwise.step.denominator = solo_dev->fps;
991
992 return 0;
993}
994
995static int solo_g_parm(struct file *file, void *priv,
996 struct v4l2_streamparm *sp)
997{
998 struct solo_enc_dev *solo_enc = video_drvdata(file);
999 struct solo_dev *solo_dev = solo_enc->solo_dev;
1000 struct v4l2_captureparm *cp = &sp->parm.capture;
1001
1002 cp->capability = V4L2_CAP_TIMEPERFRAME;
1003 cp->timeperframe.numerator = solo_enc->interval;
1004 cp->timeperframe.denominator = solo_dev->fps;
1005 cp->capturemode = 0;
1006 /* XXX: Shouldn't we be able to get/set this from videobuf? */
1007 cp->readbuffers = 2;
1008
1009 return 0;
1010}
1011
1012static int solo_s_parm(struct file *file, void *priv,
1013 struct v4l2_streamparm *sp)
1014{
1015 struct solo_enc_dev *solo_enc = video_drvdata(file);
1016 struct solo_dev *solo_dev = solo_enc->solo_dev;
1017 struct v4l2_captureparm *cp = &sp->parm.capture;
1018
1019 if (vb2_is_streaming(&solo_enc->vidq))
1020 return -EBUSY;
1021
1022 if ((cp->timeperframe.numerator == 0) ||
1023 (cp->timeperframe.denominator == 0)) {
1024 /* reset framerate */
1025 cp->timeperframe.numerator = 1;
1026 cp->timeperframe.denominator = solo_dev->fps;
1027 }
1028
1029 if (cp->timeperframe.denominator != solo_dev->fps)
1030 cp->timeperframe.denominator = solo_dev->fps;
1031
1032 if (cp->timeperframe.numerator > 15)
1033 cp->timeperframe.numerator = 15;
1034
1035 solo_enc->interval = cp->timeperframe.numerator;
1036
1037 cp->capability = V4L2_CAP_TIMEPERFRAME;
1038 cp->readbuffers = 2;
1039
1040 solo_update_mode(solo_enc);
1041 return 0;
1042}
1043
1044static long solo_enc_default(struct file *file, void *fh,
1045 bool valid_prio, unsigned int cmd, void *arg)
1046{
1047 struct solo_enc_dev *solo_enc = video_drvdata(file);
1048 struct solo_dev *solo_dev = solo_enc->solo_dev;
1049 struct solo_motion_thresholds *thresholds = arg;
1050
1051 switch (cmd) {
1052 case SOLO_IOC_G_MOTION_THRESHOLDS:
1053 *thresholds = solo_enc->motion_thresholds;
1054 return 0;
1055
1056 case SOLO_IOC_S_MOTION_THRESHOLDS:
1057 if (!valid_prio)
1058 return -EBUSY;
1059 solo_enc->motion_thresholds = *thresholds;
1060 if (solo_enc->motion_enabled && !solo_enc->motion_global)
1061 return solo_set_motion_block(solo_dev, solo_enc->ch,
1062 &solo_enc->motion_thresholds);
1063 return 0;
1064 default:
1065 return -ENOTTY;
1066 }
1067}
1068
1069static int solo_s_ctrl(struct v4l2_ctrl *ctrl)
1070{
1071 struct solo_enc_dev *solo_enc =
1072 container_of(ctrl->handler, struct solo_enc_dev, hdl);
1073 struct solo_dev *solo_dev = solo_enc->solo_dev;
1074 int err;
1075
1076 switch (ctrl->id) {
1077 case V4L2_CID_BRIGHTNESS:
1078 case V4L2_CID_CONTRAST:
1079 case V4L2_CID_SATURATION:
1080 case V4L2_CID_HUE:
1081 case V4L2_CID_SHARPNESS:
1082 return tw28_set_ctrl_val(solo_dev, ctrl->id, solo_enc->ch,
1083 ctrl->val);
1084 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1085 solo_enc->gop = ctrl->val;
1086 return 0;
1087 case V4L2_CID_MOTION_THRESHOLD:
1088 solo_enc->motion_thresh = ctrl->val;
1089 if (!solo_enc->motion_global || !solo_enc->motion_enabled)
1090 return 0;
1091 return solo_set_motion_threshold(solo_dev, solo_enc->ch, ctrl->val);
1092 case V4L2_CID_MOTION_MODE:
1093 solo_enc->motion_global = ctrl->val == 1;
1094 solo_enc->motion_enabled = ctrl->val > 0;
1095 if (ctrl->val) {
1096 if (solo_enc->motion_global)
1097 solo_set_motion_threshold(solo_dev, solo_enc->ch,
1098 solo_enc->motion_thresh);
1099 else
1100 solo_set_motion_block(solo_dev, solo_enc->ch,
1101 &solo_enc->motion_thresholds);
1102 }
1103 solo_motion_toggle(solo_enc, ctrl->val);
1104 return 0;
1105 case V4L2_CID_OSD_TEXT:
1106 strcpy(solo_enc->osd_text, ctrl->string);
1107 err = solo_osd_print(solo_enc);
1108 return err;
1109 default:
1110 return -EINVAL;
1111 }
1112
1113 return 0;
1114}
1115
1116static const struct v4l2_file_operations solo_enc_fops = {
1117 .owner = THIS_MODULE,
1118 .open = v4l2_fh_open,
1119 .release = vb2_fop_release,
1120 .read = vb2_fop_read,
1121 .poll = vb2_fop_poll,
1122 .mmap = vb2_fop_mmap,
1123 .unlocked_ioctl = video_ioctl2,
1124};
1125
1126static const struct v4l2_ioctl_ops solo_enc_ioctl_ops = {
1127 .vidioc_querycap = solo_enc_querycap,
1128 .vidioc_s_std = solo_enc_s_std,
1129 .vidioc_g_std = solo_enc_g_std,
1130 /* Input callbacks */
1131 .vidioc_enum_input = solo_enc_enum_input,
1132 .vidioc_s_input = solo_enc_set_input,
1133 .vidioc_g_input = solo_enc_get_input,
1134 /* Video capture format callbacks */
1135 .vidioc_enum_fmt_vid_cap = solo_enc_enum_fmt_cap,
1136 .vidioc_try_fmt_vid_cap = solo_enc_try_fmt_cap,
1137 .vidioc_s_fmt_vid_cap = solo_enc_set_fmt_cap,
1138 .vidioc_g_fmt_vid_cap = solo_enc_get_fmt_cap,
1139 /* Streaming I/O */
1140 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1141 .vidioc_querybuf = vb2_ioctl_querybuf,
1142 .vidioc_qbuf = vb2_ioctl_qbuf,
1143 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1144 .vidioc_streamon = vb2_ioctl_streamon,
1145 .vidioc_streamoff = vb2_ioctl_streamoff,
1146 /* Frame size and interval */
1147 .vidioc_enum_framesizes = solo_enum_framesizes,
1148 .vidioc_enum_frameintervals = solo_enum_frameintervals,
1149 /* Video capture parameters */
1150 .vidioc_s_parm = solo_s_parm,
1151 .vidioc_g_parm = solo_g_parm,
1152 /* Logging and events */
1153 .vidioc_log_status = v4l2_ctrl_log_status,
1154 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1155 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1156 .vidioc_default = solo_enc_default,
1157};
1158
1159static const struct video_device solo_enc_template = {
1160 .name = SOLO6X10_NAME,
1161 .fops = &solo_enc_fops,
1162 .ioctl_ops = &solo_enc_ioctl_ops,
1163 .minor = -1,
1164 .release = video_device_release,
1165 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL,
1166};
1167
1168static const struct v4l2_ctrl_ops solo_ctrl_ops = {
1169 .s_ctrl = solo_s_ctrl,
1170};
1171
1172static const struct v4l2_ctrl_config solo_motion_threshold_ctrl = {
1173 .ops = &solo_ctrl_ops,
1174 .id = V4L2_CID_MOTION_THRESHOLD,
1175 .name = "Motion Detection Threshold",
1176 .type = V4L2_CTRL_TYPE_INTEGER,
1177 .max = 0xffff,
1178 .def = SOLO_DEF_MOT_THRESH,
1179 .step = 1,
1180 .flags = V4L2_CTRL_FLAG_SLIDER,
1181};
1182
1183static const char * const solo_motion_mode_menu[] = {
1184 "Disabled",
1185 "Global Threshold",
1186 "Regional Threshold",
1187 NULL
1188};
1189
1190static const struct v4l2_ctrl_config solo_motion_enable_ctrl = {
1191 .ops = &solo_ctrl_ops,
1192 .id = V4L2_CID_MOTION_MODE,
1193 .name = "Motion Detection Mode",
1194 .type = V4L2_CTRL_TYPE_MENU,
1195 .qmenu = solo_motion_mode_menu,
1196 .max = 2,
1197};
1198
1199static const struct v4l2_ctrl_config solo_osd_text_ctrl = {
1200 .ops = &solo_ctrl_ops,
1201 .id = V4L2_CID_OSD_TEXT,
1202 .name = "OSD Text",
1203 .type = V4L2_CTRL_TYPE_STRING,
1204 .max = OSD_TEXT_MAX,
1205 .step = 1,
1206};
1207
1208static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev,
1209 u8 ch, unsigned nr)
1210{
1211 struct solo_enc_dev *solo_enc;
1212 struct v4l2_ctrl_handler *hdl;
1213 int ret;
1214 int x, y;
1215
1216 solo_enc = kzalloc(sizeof(*solo_enc), GFP_KERNEL);
1217 if (!solo_enc)
1218 return ERR_PTR(-ENOMEM);
1219
1220 hdl = &solo_enc->hdl;
1221 v4l2_ctrl_handler_init(hdl, 10);
1222 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1223 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1224 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1225 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1226 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1227 V4L2_CID_SATURATION, 0, 255, 1, 128);
1228 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1229 V4L2_CID_HUE, 0, 255, 1, 128);
1230 if (tw28_has_sharpness(solo_dev, ch))
1231 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1232 V4L2_CID_SHARPNESS, 0, 15, 1, 0);
1233 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1234 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 255, 1, solo_dev->fps);
1235 v4l2_ctrl_new_custom(hdl, &solo_motion_threshold_ctrl, NULL);
1236 v4l2_ctrl_new_custom(hdl, &solo_motion_enable_ctrl, NULL);
1237 v4l2_ctrl_new_custom(hdl, &solo_osd_text_ctrl, NULL);
1238 if (hdl->error) {
1239 ret = hdl->error;
1240 goto hdl_free;
1241 }
1242
1243 solo_enc->solo_dev = solo_dev;
1244 solo_enc->ch = ch;
1245 mutex_init(&solo_enc->lock);
1246 spin_lock_init(&solo_enc->av_lock);
1247 INIT_LIST_HEAD(&solo_enc->vidq_active);
1248 solo_enc->fmt = (solo_dev->type == SOLO_DEV_6010) ?
1249 V4L2_PIX_FMT_MPEG4 : V4L2_PIX_FMT_H264;
1250 solo_enc->type = SOLO_ENC_TYPE_STD;
1251
1252 solo_enc->qp = SOLO_DEFAULT_QP;
1253 solo_enc->gop = solo_dev->fps;
1254 solo_enc->interval = 1;
1255 solo_enc->mode = SOLO_ENC_MODE_CIF;
1256 solo_enc->motion_global = true;
1257 solo_enc->motion_thresh = SOLO_DEF_MOT_THRESH;
1258 for (y = 0; y < SOLO_MOTION_SZ; y++)
1259 for (x = 0; x < SOLO_MOTION_SZ; x++)
1260 solo_enc->motion_thresholds.thresholds[y][x] =
1261 SOLO_DEF_MOT_THRESH;
1262
1263 solo_enc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1264 solo_enc->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1265 solo_enc->vidq.ops = &solo_enc_video_qops;
1266 solo_enc->vidq.mem_ops = &vb2_dma_sg_memops;
1267 solo_enc->vidq.drv_priv = solo_enc;
1268 solo_enc->vidq.gfp_flags = __GFP_DMA32;
1269 solo_enc->vidq.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1270 solo_enc->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
1271 solo_enc->vidq.lock = &solo_enc->lock;
1272 ret = vb2_queue_init(&solo_enc->vidq);
1273 if (ret)
1274 goto hdl_free;
1275 solo_update_mode(solo_enc);
1276
1277 spin_lock_init(&solo_enc->motion_lock);
1278
1279 /* Initialize this per encoder */
1280 solo_enc->jpeg_len = sizeof(jpeg_header);
1281 memcpy(solo_enc->jpeg_header, jpeg_header, solo_enc->jpeg_len);
1282
1283 solo_enc->desc_nelts = 32;
1284 solo_enc->desc_items = pci_alloc_consistent(solo_dev->pdev,
1285 sizeof(struct solo_p2m_desc) *
1286 solo_enc->desc_nelts, &solo_enc->desc_dma);
1287 ret = -ENOMEM;
1288 if (solo_enc->desc_items == NULL)
1289 goto hdl_free;
1290
1291 solo_enc->vfd = video_device_alloc();
1292 if (!solo_enc->vfd)
1293 goto pci_free;
1294
1295 *solo_enc->vfd = solo_enc_template;
1296 solo_enc->vfd->v4l2_dev = &solo_dev->v4l2_dev;
1297 solo_enc->vfd->ctrl_handler = hdl;
1298 solo_enc->vfd->queue = &solo_enc->vidq;
1299 solo_enc->vfd->lock = &solo_enc->lock;
1300 set_bit(V4L2_FL_USE_FH_PRIO, &solo_enc->vfd->flags);
1301 video_set_drvdata(solo_enc->vfd, solo_enc);
1302 ret = video_register_device(solo_enc->vfd, VFL_TYPE_GRABBER, nr);
1303 if (ret < 0)
1304 goto vdev_release;
1305
1306 snprintf(solo_enc->vfd->name, sizeof(solo_enc->vfd->name),
1307 "%s-enc (%i/%i)", SOLO6X10_NAME, solo_dev->vfd->num,
1308 solo_enc->vfd->num);
1309
1310 return solo_enc;
1311
1312vdev_release:
1313 video_device_release(solo_enc->vfd);
1314pci_free:
1315 pci_free_consistent(solo_enc->solo_dev->pdev,
1316 sizeof(struct solo_p2m_desc) * solo_enc->desc_nelts,
1317 solo_enc->desc_items, solo_enc->desc_dma);
1318hdl_free:
1319 v4l2_ctrl_handler_free(hdl);
1320 kfree(solo_enc);
1321 return ERR_PTR(ret);
1322}
1323
1324static void solo_enc_free(struct solo_enc_dev *solo_enc)
1325{
1326 if (solo_enc == NULL)
1327 return;
1328
1329 video_unregister_device(solo_enc->vfd);
1330 v4l2_ctrl_handler_free(&solo_enc->hdl);
1331 kfree(solo_enc);
1332}
1333
1334int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
1335{
1336 int i;
1337
1338 init_waitqueue_head(&solo_dev->ring_thread_wait);
1339
1340 solo_dev->vh_size = sizeof(struct vop_header);
1341 solo_dev->vh_buf = pci_alloc_consistent(solo_dev->pdev,
1342 solo_dev->vh_size,
1343 &solo_dev->vh_dma);
1344 if (solo_dev->vh_buf == NULL)
1345 return -ENOMEM;
1346
1347 for (i = 0; i < solo_dev->nr_chans; i++) {
1348 solo_dev->v4l2_enc[i] = solo_enc_alloc(solo_dev, i, nr);
1349 if (IS_ERR(solo_dev->v4l2_enc[i]))
1350 break;
1351 }
1352
1353 if (i != solo_dev->nr_chans) {
1354 int ret = PTR_ERR(solo_dev->v4l2_enc[i]);
1355 while (i--)
1356 solo_enc_free(solo_dev->v4l2_enc[i]);
1357 pci_free_consistent(solo_dev->pdev, solo_dev->vh_size,
1358 solo_dev->vh_buf, solo_dev->vh_dma);
1359 solo_dev->vh_buf = NULL;
1360 return ret;
1361 }
1362
1363 if (solo_dev->type == SOLO_DEV_6010)
1364 solo_dev->enc_bw_remain = solo_dev->fps * 4 * 4;
1365 else
1366 solo_dev->enc_bw_remain = solo_dev->fps * 4 * 5;
1367
1368 dev_info(&solo_dev->pdev->dev, "Encoders as /dev/video%d-%d\n",
1369 solo_dev->v4l2_enc[0]->vfd->num,
1370 solo_dev->v4l2_enc[solo_dev->nr_chans - 1]->vfd->num);
1371
1372 return 0;
1373}
1374
1375void solo_enc_v4l2_exit(struct solo_dev *solo_dev)
1376{
1377 int i;
1378
1379 for (i = 0; i < solo_dev->nr_chans; i++)
1380 solo_enc_free(solo_dev->v4l2_enc[i]);
1381
1382 if (solo_dev->vh_buf)
1383 pci_free_consistent(solo_dev->pdev, solo_dev->vh_size,
1384 solo_dev->vh_buf, solo_dev->vh_dma);
1385}
diff --git a/drivers/staging/media/solo6x10/solo6x10-v4l2.c b/drivers/staging/media/solo6x10/solo6x10-v4l2.c
new file mode 100644
index 000000000000..7b26de3488da
--- /dev/null
+++ b/drivers/staging/media/solo6x10/solo6x10-v4l2.c
@@ -0,0 +1,734 @@
1/*
2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/freezer.h>
29
30#include <media/v4l2-ioctl.h>
31#include <media/v4l2-common.h>
32#include <media/v4l2-event.h>
33#include <media/videobuf2-dma-contig.h>
34
35#include "solo6x10.h"
36#include "solo6x10-tw28.h"
37
38/* Image size is two fields, SOLO_HW_BPL is one horizontal line in hardware */
39#define SOLO_HW_BPL 2048
40#define solo_vlines(__solo) (__solo->video_vsize * 2)
41#define solo_image_size(__solo) (solo_bytesperline(__solo) * \
42 solo_vlines(__solo))
43#define solo_bytesperline(__solo) (__solo->video_hsize * 2)
44
45#define MIN_VID_BUFFERS 2
46
47static inline void erase_on(struct solo_dev *solo_dev)
48{
49 solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, SOLO_VO_DISP_ERASE_ON);
50 solo_dev->erasing = 1;
51 solo_dev->frame_blank = 0;
52}
53
54static inline int erase_off(struct solo_dev *solo_dev)
55{
56 if (!solo_dev->erasing)
57 return 0;
58
59 /* First time around, assert erase off */
60 if (!solo_dev->frame_blank)
61 solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, 0);
62 /* Keep the erasing flag on for 8 frames minimum */
63 if (solo_dev->frame_blank++ >= 8)
64 solo_dev->erasing = 0;
65
66 return 1;
67}
68
69void solo_video_in_isr(struct solo_dev *solo_dev)
70{
71 wake_up_interruptible_all(&solo_dev->disp_thread_wait);
72}
73
74static void solo_win_setup(struct solo_dev *solo_dev, u8 ch,
75 int sx, int sy, int ex, int ey, int scale)
76{
77 if (ch >= solo_dev->nr_chans)
78 return;
79
80 /* Here, we just keep window/channel the same */
81 solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL0(ch),
82 SOLO_VI_WIN_CHANNEL(ch) |
83 SOLO_VI_WIN_SX(sx) |
84 SOLO_VI_WIN_EX(ex) |
85 SOLO_VI_WIN_SCALE(scale));
86
87 solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL1(ch),
88 SOLO_VI_WIN_SY(sy) |
89 SOLO_VI_WIN_EY(ey));
90}
91
92static int solo_v4l2_ch_ext_4up(struct solo_dev *solo_dev, u8 idx, int on)
93{
94 u8 ch = idx * 4;
95
96 if (ch >= solo_dev->nr_chans)
97 return -EINVAL;
98
99 if (!on) {
100 u8 i;
101 for (i = ch; i < ch + 4; i++)
102 solo_win_setup(solo_dev, i, solo_dev->video_hsize,
103 solo_vlines(solo_dev),
104 solo_dev->video_hsize,
105 solo_vlines(solo_dev), 0);
106 return 0;
107 }
108
109 /* Row 1 */
110 solo_win_setup(solo_dev, ch, 0, 0, solo_dev->video_hsize / 2,
111 solo_vlines(solo_dev) / 2, 3);
112 solo_win_setup(solo_dev, ch + 1, solo_dev->video_hsize / 2, 0,
113 solo_dev->video_hsize, solo_vlines(solo_dev) / 2, 3);
114 /* Row 2 */
115 solo_win_setup(solo_dev, ch + 2, 0, solo_vlines(solo_dev) / 2,
116 solo_dev->video_hsize / 2, solo_vlines(solo_dev), 3);
117 solo_win_setup(solo_dev, ch + 3, solo_dev->video_hsize / 2,
118 solo_vlines(solo_dev) / 2, solo_dev->video_hsize,
119 solo_vlines(solo_dev), 3);
120
121 return 0;
122}
123
124static int solo_v4l2_ch_ext_16up(struct solo_dev *solo_dev, int on)
125{
126 int sy, ysize, hsize, i;
127
128 if (!on) {
129 for (i = 0; i < 16; i++)
130 solo_win_setup(solo_dev, i, solo_dev->video_hsize,
131 solo_vlines(solo_dev),
132 solo_dev->video_hsize,
133 solo_vlines(solo_dev), 0);
134 return 0;
135 }
136
137 ysize = solo_vlines(solo_dev) / 4;
138 hsize = solo_dev->video_hsize / 4;
139
140 for (sy = 0, i = 0; i < 4; i++, sy += ysize) {
141 solo_win_setup(solo_dev, i * 4, 0, sy, hsize,
142 sy + ysize, 5);
143 solo_win_setup(solo_dev, (i * 4) + 1, hsize, sy,
144 hsize * 2, sy + ysize, 5);
145 solo_win_setup(solo_dev, (i * 4) + 2, hsize * 2, sy,
146 hsize * 3, sy + ysize, 5);
147 solo_win_setup(solo_dev, (i * 4) + 3, hsize * 3, sy,
148 solo_dev->video_hsize, sy + ysize, 5);
149 }
150
151 return 0;
152}
153
154static int solo_v4l2_ch(struct solo_dev *solo_dev, u8 ch, int on)
155{
156 u8 ext_ch;
157
158 if (ch < solo_dev->nr_chans) {
159 solo_win_setup(solo_dev, ch, on ? 0 : solo_dev->video_hsize,
160 on ? 0 : solo_vlines(solo_dev),
161 solo_dev->video_hsize, solo_vlines(solo_dev),
162 on ? 1 : 0);
163 return 0;
164 }
165
166 if (ch >= solo_dev->nr_chans + solo_dev->nr_ext)
167 return -EINVAL;
168
169 ext_ch = ch - solo_dev->nr_chans;
170
171 /* 4up's first */
172 if (ext_ch < 4)
173 return solo_v4l2_ch_ext_4up(solo_dev, ext_ch, on);
174
175 /* Remaining case is 16up for 16-port */
176 return solo_v4l2_ch_ext_16up(solo_dev, on);
177}
178
179static int solo_v4l2_set_ch(struct solo_dev *solo_dev, u8 ch)
180{
181 if (ch >= solo_dev->nr_chans + solo_dev->nr_ext)
182 return -EINVAL;
183
184 erase_on(solo_dev);
185
186 solo_v4l2_ch(solo_dev, solo_dev->cur_disp_ch, 0);
187 solo_v4l2_ch(solo_dev, ch, 1);
188
189 solo_dev->cur_disp_ch = ch;
190
191 return 0;
192}
193
194static void solo_fillbuf(struct solo_dev *solo_dev,
195 struct vb2_buffer *vb)
196{
197 dma_addr_t vbuf;
198 unsigned int fdma_addr;
199 int error = -1;
200 int i;
201
202 vbuf = vb2_dma_contig_plane_dma_addr(vb, 0);
203 if (!vbuf)
204 goto finish_buf;
205
206 if (erase_off(solo_dev)) {
207 void *p = vb2_plane_vaddr(vb, 0);
208 int image_size = solo_image_size(solo_dev);
209 for (i = 0; i < image_size; i += 2) {
210 ((u8 *)p)[i] = 0x80;
211 ((u8 *)p)[i + 1] = 0x00;
212 }
213 error = 0;
214 } else {
215 fdma_addr = SOLO_DISP_EXT_ADDR + (solo_dev->old_write *
216 (SOLO_HW_BPL * solo_vlines(solo_dev)));
217
218 error = solo_p2m_dma_t(solo_dev, 0, vbuf, fdma_addr,
219 solo_bytesperline(solo_dev),
220 solo_vlines(solo_dev), SOLO_HW_BPL);
221 }
222
223finish_buf:
224 if (!error) {
225 vb2_set_plane_payload(vb, 0,
226 solo_vlines(solo_dev) * solo_bytesperline(solo_dev));
227 vb->v4l2_buf.sequence = solo_dev->sequence++;
228 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
229 }
230
231 vb2_buffer_done(vb, error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
232}
233
234static void solo_thread_try(struct solo_dev *solo_dev)
235{
236 struct solo_vb2_buf *vb;
237
238 /* Only "break" from this loop if slock is held, otherwise
239 * just return. */
240 for (;;) {
241 unsigned int cur_write;
242
243 cur_write = SOLO_VI_STATUS0_PAGE(
244 solo_reg_read(solo_dev, SOLO_VI_STATUS0));
245 if (cur_write == solo_dev->old_write)
246 return;
247
248 spin_lock(&solo_dev->slock);
249
250 if (list_empty(&solo_dev->vidq_active))
251 break;
252
253 vb = list_first_entry(&solo_dev->vidq_active, struct solo_vb2_buf,
254 list);
255
256 solo_dev->old_write = cur_write;
257 list_del(&vb->list);
258
259 spin_unlock(&solo_dev->slock);
260
261 solo_fillbuf(solo_dev, &vb->vb);
262 }
263
264 assert_spin_locked(&solo_dev->slock);
265 spin_unlock(&solo_dev->slock);
266}
267
268static int solo_thread(void *data)
269{
270 struct solo_dev *solo_dev = data;
271 DECLARE_WAITQUEUE(wait, current);
272
273 set_freezable();
274 add_wait_queue(&solo_dev->disp_thread_wait, &wait);
275
276 for (;;) {
277 long timeout = schedule_timeout_interruptible(HZ);
278 if (timeout == -ERESTARTSYS || kthread_should_stop())
279 break;
280 solo_thread_try(solo_dev);
281 try_to_freeze();
282 }
283
284 remove_wait_queue(&solo_dev->disp_thread_wait, &wait);
285
286 return 0;
287}
288
289static int solo_start_thread(struct solo_dev *solo_dev)
290{
291 int ret = 0;
292
293 solo_dev->kthread = kthread_run(solo_thread, solo_dev, SOLO6X10_NAME "_disp");
294
295 if (IS_ERR(solo_dev->kthread)) {
296 ret = PTR_ERR(solo_dev->kthread);
297 solo_dev->kthread = NULL;
298 return ret;
299 }
300 solo_irq_on(solo_dev, SOLO_IRQ_VIDEO_IN);
301
302 return ret;
303}
304
305static void solo_stop_thread(struct solo_dev *solo_dev)
306{
307 if (!solo_dev->kthread)
308 return;
309
310 solo_irq_off(solo_dev, SOLO_IRQ_VIDEO_IN);
311 kthread_stop(solo_dev->kthread);
312 solo_dev->kthread = NULL;
313}
314
315static int solo_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
316 unsigned int *num_buffers, unsigned int *num_planes,
317 unsigned int sizes[], void *alloc_ctxs[])
318{
319 struct solo_dev *solo_dev = vb2_get_drv_priv(q);
320
321 sizes[0] = solo_image_size(solo_dev);
322 alloc_ctxs[0] = solo_dev->alloc_ctx;
323 *num_planes = 1;
324
325 if (*num_buffers < MIN_VID_BUFFERS)
326 *num_buffers = MIN_VID_BUFFERS;
327
328 return 0;
329}
330
331static int solo_start_streaming(struct vb2_queue *q, unsigned int count)
332{
333 struct solo_dev *solo_dev = vb2_get_drv_priv(q);
334
335 solo_dev->sequence = 0;
336 return solo_start_thread(solo_dev);
337}
338
339static int solo_stop_streaming(struct vb2_queue *q)
340{
341 struct solo_dev *solo_dev = vb2_get_drv_priv(q);
342
343 solo_stop_thread(solo_dev);
344 INIT_LIST_HEAD(&solo_dev->vidq_active);
345 return 0;
346}
347
348static void solo_buf_queue(struct vb2_buffer *vb)
349{
350 struct vb2_queue *vq = vb->vb2_queue;
351 struct solo_dev *solo_dev = vb2_get_drv_priv(vq);
352 struct solo_vb2_buf *solo_vb =
353 container_of(vb, struct solo_vb2_buf, vb);
354
355 spin_lock(&solo_dev->slock);
356 list_add_tail(&solo_vb->list, &solo_dev->vidq_active);
357 spin_unlock(&solo_dev->slock);
358 wake_up_interruptible(&solo_dev->disp_thread_wait);
359}
360
361static const struct vb2_ops solo_video_qops = {
362 .queue_setup = solo_queue_setup,
363 .buf_queue = solo_buf_queue,
364 .start_streaming = solo_start_streaming,
365 .stop_streaming = solo_stop_streaming,
366 .wait_prepare = vb2_ops_wait_prepare,
367 .wait_finish = vb2_ops_wait_finish,
368};
369
370static int solo_querycap(struct file *file, void *priv,
371 struct v4l2_capability *cap)
372{
373 struct solo_dev *solo_dev = video_drvdata(file);
374
375 strcpy(cap->driver, SOLO6X10_NAME);
376 strcpy(cap->card, "Softlogic 6x10");
377 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
378 pci_name(solo_dev->pdev));
379 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
380 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
381 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
382 return 0;
383}
384
385static int solo_enum_ext_input(struct solo_dev *solo_dev,
386 struct v4l2_input *input)
387{
388 static const char * const dispnames_1[] = { "4UP" };
389 static const char * const dispnames_2[] = { "4UP-1", "4UP-2" };
390 static const char * const dispnames_5[] = {
391 "4UP-1", "4UP-2", "4UP-3", "4UP-4", "16UP"
392 };
393 const char * const *dispnames;
394
395 if (input->index >= (solo_dev->nr_chans + solo_dev->nr_ext))
396 return -EINVAL;
397
398 if (solo_dev->nr_ext == 5)
399 dispnames = dispnames_5;
400 else if (solo_dev->nr_ext == 2)
401 dispnames = dispnames_2;
402 else
403 dispnames = dispnames_1;
404
405 snprintf(input->name, sizeof(input->name), "Multi %s",
406 dispnames[input->index - solo_dev->nr_chans]);
407
408 return 0;
409}
410
411static int solo_enum_input(struct file *file, void *priv,
412 struct v4l2_input *input)
413{
414 struct solo_dev *solo_dev = video_drvdata(file);
415
416 if (input->index >= solo_dev->nr_chans) {
417 int ret = solo_enum_ext_input(solo_dev, input);
418 if (ret < 0)
419 return ret;
420 } else {
421 snprintf(input->name, sizeof(input->name), "Camera %d",
422 input->index + 1);
423
424 /* We can only check this for normal inputs */
425 if (!tw28_get_video_status(solo_dev, input->index))
426 input->status = V4L2_IN_ST_NO_SIGNAL;
427 }
428
429 input->type = V4L2_INPUT_TYPE_CAMERA;
430 input->std = solo_dev->vfd->tvnorms;
431 return 0;
432}
433
434static int solo_set_input(struct file *file, void *priv, unsigned int index)
435{
436 struct solo_dev *solo_dev = video_drvdata(file);
437 int ret = solo_v4l2_set_ch(solo_dev, index);
438
439 if (!ret) {
440 while (erase_off(solo_dev))
441 /* Do nothing */;
442 }
443
444 return ret;
445}
446
447static int solo_get_input(struct file *file, void *priv, unsigned int *index)
448{
449 struct solo_dev *solo_dev = video_drvdata(file);
450
451 *index = solo_dev->cur_disp_ch;
452
453 return 0;
454}
455
456static int solo_enum_fmt_cap(struct file *file, void *priv,
457 struct v4l2_fmtdesc *f)
458{
459 if (f->index)
460 return -EINVAL;
461
462 f->pixelformat = V4L2_PIX_FMT_UYVY;
463 strlcpy(f->description, "UYUV 4:2:2 Packed", sizeof(f->description));
464
465 return 0;
466}
467
468static int solo_try_fmt_cap(struct file *file, void *priv,
469 struct v4l2_format *f)
470{
471 struct solo_dev *solo_dev = video_drvdata(file);
472 struct v4l2_pix_format *pix = &f->fmt.pix;
473 int image_size = solo_image_size(solo_dev);
474
475 if (pix->pixelformat != V4L2_PIX_FMT_UYVY)
476 return -EINVAL;
477
478 pix->width = solo_dev->video_hsize;
479 pix->height = solo_vlines(solo_dev);
480 pix->sizeimage = image_size;
481 pix->field = V4L2_FIELD_INTERLACED;
482 pix->pixelformat = V4L2_PIX_FMT_UYVY;
483 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
484 pix->priv = 0;
485 return 0;
486}
487
488static int solo_set_fmt_cap(struct file *file, void *priv,
489 struct v4l2_format *f)
490{
491 struct solo_dev *solo_dev = video_drvdata(file);
492
493 if (vb2_is_busy(&solo_dev->vidq))
494 return -EBUSY;
495
496 /* For right now, if it doesn't match our running config,
497 * then fail */
498 return solo_try_fmt_cap(file, priv, f);
499}
500
501static int solo_get_fmt_cap(struct file *file, void *priv,
502 struct v4l2_format *f)
503{
504 struct solo_dev *solo_dev = video_drvdata(file);
505 struct v4l2_pix_format *pix = &f->fmt.pix;
506
507 pix->width = solo_dev->video_hsize;
508 pix->height = solo_vlines(solo_dev);
509 pix->pixelformat = V4L2_PIX_FMT_UYVY;
510 pix->field = V4L2_FIELD_INTERLACED;
511 pix->sizeimage = solo_image_size(solo_dev);
512 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
513 pix->bytesperline = solo_bytesperline(solo_dev);
514 pix->priv = 0;
515
516 return 0;
517}
518
519static int solo_g_std(struct file *file, void *priv, v4l2_std_id *i)
520{
521 struct solo_dev *solo_dev = video_drvdata(file);
522
523 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
524 *i = V4L2_STD_NTSC_M;
525 else
526 *i = V4L2_STD_PAL;
527 return 0;
528}
529
530int solo_set_video_type(struct solo_dev *solo_dev, bool type)
531{
532 int i;
533
534 /* Make sure all video nodes are idle */
535 if (vb2_is_busy(&solo_dev->vidq))
536 return -EBUSY;
537 for (i = 0; i < solo_dev->nr_chans; i++)
538 if (vb2_is_busy(&solo_dev->v4l2_enc[i]->vidq))
539 return -EBUSY;
540 solo_dev->video_type = type;
541 /* Reconfigure for the new standard */
542 solo_disp_init(solo_dev);
543 solo_enc_init(solo_dev);
544 solo_tw28_init(solo_dev);
545 for (i = 0; i < solo_dev->nr_chans; i++)
546 solo_update_mode(solo_dev->v4l2_enc[i]);
547 return solo_v4l2_set_ch(solo_dev, solo_dev->cur_disp_ch);
548}
549
550static int solo_s_std(struct file *file, void *priv, v4l2_std_id std)
551{
552 struct solo_dev *solo_dev = video_drvdata(file);
553
554 return solo_set_video_type(solo_dev, std & V4L2_STD_PAL);
555}
556
557static int solo_s_ctrl(struct v4l2_ctrl *ctrl)
558{
559 struct solo_dev *solo_dev =
560 container_of(ctrl->handler, struct solo_dev, disp_hdl);
561
562 switch (ctrl->id) {
563 case V4L2_CID_MOTION_TRACE:
564 if (ctrl->val) {
565 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER,
566 SOLO_VI_MOTION_Y_ADD |
567 SOLO_VI_MOTION_Y_VALUE(0x20) |
568 SOLO_VI_MOTION_CB_VALUE(0x10) |
569 SOLO_VI_MOTION_CR_VALUE(0x10));
570 solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR,
571 SOLO_VI_MOTION_CR_ADD |
572 SOLO_VI_MOTION_Y_VALUE(0x10) |
573 SOLO_VI_MOTION_CB_VALUE(0x80) |
574 SOLO_VI_MOTION_CR_VALUE(0x10));
575 } else {
576 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0);
577 solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR, 0);
578 }
579 return 0;
580 default:
581 break;
582 }
583 return -EINVAL;
584}
585
586static const struct v4l2_file_operations solo_v4l2_fops = {
587 .owner = THIS_MODULE,
588 .open = v4l2_fh_open,
589 .release = vb2_fop_release,
590 .read = vb2_fop_read,
591 .poll = vb2_fop_poll,
592 .mmap = vb2_fop_mmap,
593 .unlocked_ioctl = video_ioctl2,
594};
595
596static const struct v4l2_ioctl_ops solo_v4l2_ioctl_ops = {
597 .vidioc_querycap = solo_querycap,
598 .vidioc_s_std = solo_s_std,
599 .vidioc_g_std = solo_g_std,
600 /* Input callbacks */
601 .vidioc_enum_input = solo_enum_input,
602 .vidioc_s_input = solo_set_input,
603 .vidioc_g_input = solo_get_input,
604 /* Video capture format callbacks */
605 .vidioc_enum_fmt_vid_cap = solo_enum_fmt_cap,
606 .vidioc_try_fmt_vid_cap = solo_try_fmt_cap,
607 .vidioc_s_fmt_vid_cap = solo_set_fmt_cap,
608 .vidioc_g_fmt_vid_cap = solo_get_fmt_cap,
609 /* Streaming I/O */
610 .vidioc_reqbufs = vb2_ioctl_reqbufs,
611 .vidioc_querybuf = vb2_ioctl_querybuf,
612 .vidioc_qbuf = vb2_ioctl_qbuf,
613 .vidioc_dqbuf = vb2_ioctl_dqbuf,
614 .vidioc_streamon = vb2_ioctl_streamon,
615 .vidioc_streamoff = vb2_ioctl_streamoff,
616 /* Logging and events */
617 .vidioc_log_status = v4l2_ctrl_log_status,
618 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
619 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
620};
621
622static struct video_device solo_v4l2_template = {
623 .name = SOLO6X10_NAME,
624 .fops = &solo_v4l2_fops,
625 .ioctl_ops = &solo_v4l2_ioctl_ops,
626 .minor = -1,
627 .release = video_device_release,
628 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL,
629};
630
631static const struct v4l2_ctrl_ops solo_ctrl_ops = {
632 .s_ctrl = solo_s_ctrl,
633};
634
635static const struct v4l2_ctrl_config solo_motion_trace_ctrl = {
636 .ops = &solo_ctrl_ops,
637 .id = V4L2_CID_MOTION_TRACE,
638 .name = "Motion Detection Trace",
639 .type = V4L2_CTRL_TYPE_BOOLEAN,
640 .max = 1,
641 .step = 1,
642};
643
644int solo_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
645{
646 int ret;
647 int i;
648
649 init_waitqueue_head(&solo_dev->disp_thread_wait);
650 spin_lock_init(&solo_dev->slock);
651 mutex_init(&solo_dev->lock);
652 INIT_LIST_HEAD(&solo_dev->vidq_active);
653
654 solo_dev->vfd = video_device_alloc();
655 if (!solo_dev->vfd)
656 return -ENOMEM;
657
658 *solo_dev->vfd = solo_v4l2_template;
659 solo_dev->vfd->v4l2_dev = &solo_dev->v4l2_dev;
660 solo_dev->vfd->queue = &solo_dev->vidq;
661 solo_dev->vfd->lock = &solo_dev->lock;
662 v4l2_ctrl_handler_init(&solo_dev->disp_hdl, 1);
663 v4l2_ctrl_new_custom(&solo_dev->disp_hdl, &solo_motion_trace_ctrl, NULL);
664 if (solo_dev->disp_hdl.error) {
665 ret = solo_dev->disp_hdl.error;
666 goto fail;
667 }
668 solo_dev->vfd->ctrl_handler = &solo_dev->disp_hdl;
669 set_bit(V4L2_FL_USE_FH_PRIO, &solo_dev->vfd->flags);
670
671 video_set_drvdata(solo_dev->vfd, solo_dev);
672
673 solo_dev->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
674 solo_dev->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
675 solo_dev->vidq.ops = &solo_video_qops;
676 solo_dev->vidq.mem_ops = &vb2_dma_contig_memops;
677 solo_dev->vidq.drv_priv = solo_dev;
678 solo_dev->vidq.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
679 solo_dev->vidq.gfp_flags = __GFP_DMA32;
680 solo_dev->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
681 solo_dev->vidq.lock = &solo_dev->lock;
682 ret = vb2_queue_init(&solo_dev->vidq);
683 if (ret < 0)
684 goto fail;
685
686 solo_dev->alloc_ctx = vb2_dma_contig_init_ctx(&solo_dev->pdev->dev);
687 if (IS_ERR(solo_dev->alloc_ctx)) {
688 dev_err(&solo_dev->pdev->dev, "Can't allocate buffer context");
689 return PTR_ERR(solo_dev->alloc_ctx);
690 }
691
692 /* Cycle all the channels and clear */
693 for (i = 0; i < solo_dev->nr_chans; i++) {
694 solo_v4l2_set_ch(solo_dev, i);
695 while (erase_off(solo_dev))
696 /* Do nothing */;
697 }
698
699 /* Set the default display channel */
700 solo_v4l2_set_ch(solo_dev, 0);
701 while (erase_off(solo_dev))
702 /* Do nothing */;
703
704 ret = video_register_device(solo_dev->vfd, VFL_TYPE_GRABBER, nr);
705 if (ret < 0)
706 goto fail;
707
708 snprintf(solo_dev->vfd->name, sizeof(solo_dev->vfd->name), "%s (%i)",
709 SOLO6X10_NAME, solo_dev->vfd->num);
710
711 dev_info(&solo_dev->pdev->dev, "Display as /dev/video%d with "
712 "%d inputs (%d extended)\n", solo_dev->vfd->num,
713 solo_dev->nr_chans, solo_dev->nr_ext);
714
715 return 0;
716
717fail:
718 video_device_release(solo_dev->vfd);
719 vb2_dma_contig_cleanup_ctx(solo_dev->alloc_ctx);
720 v4l2_ctrl_handler_free(&solo_dev->disp_hdl);
721 solo_dev->vfd = NULL;
722 return ret;
723}
724
725void solo_v4l2_exit(struct solo_dev *solo_dev)
726{
727 if (solo_dev->vfd == NULL)
728 return;
729
730 video_unregister_device(solo_dev->vfd);
731 vb2_dma_contig_cleanup_ctx(solo_dev->alloc_ctx);
732 v4l2_ctrl_handler_free(&solo_dev->disp_hdl);
733 solo_dev->vfd = NULL;
734}
diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
index abee7213202f..6f91d2e34b2a 100644
--- a/drivers/staging/media/solo6x10/solo6x10.h
+++ b/drivers/staging/media/solo6x10/solo6x10.h
@@ -1,6 +1,11 @@
1/* 1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com 2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net> 3 *
4 * Original author:
5 * Ben Collins <bcollins@ubuntu.com>
6 *
7 * Additional work by:
8 * John Brooks <john.brooks@bluecherry.net>
4 * 9 *
5 * 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
6 * 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
@@ -20,21 +25,23 @@
20#ifndef __SOLO6X10_H 25#ifndef __SOLO6X10_H
21#define __SOLO6X10_H 26#define __SOLO6X10_H
22 27
23#include <linux/version.h>
24#include <linux/pci.h> 28#include <linux/pci.h>
25#include <linux/i2c.h> 29#include <linux/i2c.h>
26#include <linux/semaphore.h>
27#include <linux/mutex.h> 30#include <linux/mutex.h>
28#include <linux/list.h> 31#include <linux/list.h>
29#include <linux/wait.h> 32#include <linux/wait.h>
30#include <linux/delay.h> 33#include <linux/stringify.h>
31#include <linux/slab.h> 34#include <linux/io.h>
32#include <asm/io.h>
33#include <linux/atomic.h> 35#include <linux/atomic.h>
36#include <linux/slab.h>
34#include <linux/videodev2.h> 37#include <linux/videodev2.h>
38
35#include <media/v4l2-dev.h> 39#include <media/v4l2-dev.h>
36#include <media/videobuf-core.h> 40#include <media/v4l2-device.h>
37#include "registers.h" 41#include <media/v4l2-ctrls.h>
42#include <media/videobuf2-core.h>
43
44#include "solo6x10-regs.h"
38 45
39#ifndef PCI_VENDOR_ID_SOFTLOGIC 46#ifndef PCI_VENDOR_ID_SOFTLOGIC
40#define PCI_VENDOR_ID_SOFTLOGIC 0x9413 47#define PCI_VENDOR_ID_SOFTLOGIC 0x9413
@@ -58,19 +65,15 @@
58#define PCI_DEVICE_ID_BC_6110_16 0x5310 65#define PCI_DEVICE_ID_BC_6110_16 0x5310
59#endif /* Bluecherry */ 66#endif /* Bluecherry */
60 67
68/* Used in pci_device_id, and solo_dev->type */
69#define SOLO_DEV_6010 0
70#define SOLO_DEV_6110 1
71
61#define SOLO6X10_NAME "solo6x10" 72#define SOLO6X10_NAME "solo6x10"
62 73
63#define SOLO_MAX_CHANNELS 16 74#define SOLO_MAX_CHANNELS 16
64 75
65/* Make sure these two match */ 76#define SOLO6X10_VERSION "3.0.0"
66#define SOLO6X10_VERSION "2.1.0"
67#define SOLO6X10_VER_MAJOR 2
68#define SOLO6X10_VER_MINOR 0
69#define SOLO6X10_VER_SUB 0
70#define SOLO6X10_VER_NUM \
71 KERNEL_VERSION(SOLO6X10_VER_MAJOR, SOLO6X10_VER_MINOR, SOLO6X10_VER_SUB)
72
73#define FLAGS_6110 1
74 77
75/* 78/*
76 * The SOLO6x10 actually has 8 i2c channels, but we only use 2. 79 * The SOLO6x10 actually has 8 i2c channels, but we only use 2.
@@ -84,16 +87,7 @@
84/* DMA Engine setup */ 87/* DMA Engine setup */
85#define SOLO_NR_P2M 4 88#define SOLO_NR_P2M 4
86#define SOLO_NR_P2M_DESC 256 89#define SOLO_NR_P2M_DESC 256
87/* MPEG and JPEG share the same interrupt and locks so they must be together 90#define SOLO_P2M_DESC_SIZE (SOLO_NR_P2M_DESC * 16)
88 * in the same dma channel. */
89#define SOLO_P2M_DMA_ID_MP4E 0
90#define SOLO_P2M_DMA_ID_JPEG 0
91#define SOLO_P2M_DMA_ID_MP4D 1
92#define SOLO_P2M_DMA_ID_G723D 1
93#define SOLO_P2M_DMA_ID_DISP 2
94#define SOLO_P2M_DMA_ID_OSG 2
95#define SOLO_P2M_DMA_ID_G723E 3
96#define SOLO_P2M_DMA_ID_VIN 3
97 91
98/* Encoder standard modes */ 92/* Encoder standard modes */
99#define SOLO_ENC_MODE_CIF 2 93#define SOLO_ENC_MODE_CIF 2
@@ -103,23 +97,37 @@
103#define SOLO_DEFAULT_GOP 30 97#define SOLO_DEFAULT_GOP 30
104#define SOLO_DEFAULT_QP 3 98#define SOLO_DEFAULT_QP 3
105 99
106/* There is 8MB memory available for solo to buffer MPEG4 frames.
107 * This gives us 512 * 16kbyte queues. */
108#define SOLO_NR_RING_BUFS 512
109
110#define SOLO_CLOCK_MHZ 108
111
112#ifndef V4L2_BUF_FLAG_MOTION_ON 100#ifndef V4L2_BUF_FLAG_MOTION_ON
113#define V4L2_BUF_FLAG_MOTION_ON 0x0400 101#define V4L2_BUF_FLAG_MOTION_ON 0x10000
114#define V4L2_BUF_FLAG_MOTION_DETECTED 0x0800 102#define V4L2_BUF_FLAG_MOTION_DETECTED 0x20000
115#endif
116#ifndef V4L2_CID_MOTION_ENABLE
117#define PRIVATE_CIDS
118#define V4L2_CID_MOTION_ENABLE (V4L2_CID_PRIVATE_BASE+0)
119#define V4L2_CID_MOTION_THRESHOLD (V4L2_CID_PRIVATE_BASE+1)
120#define V4L2_CID_MOTION_TRACE (V4L2_CID_PRIVATE_BASE+2)
121#endif 103#endif
122 104
105#define SOLO_CID_CUSTOM_BASE (V4L2_CID_USER_BASE | 0xf000)
106#define V4L2_CID_MOTION_MODE (SOLO_CID_CUSTOM_BASE+0)
107#define V4L2_CID_MOTION_THRESHOLD (SOLO_CID_CUSTOM_BASE+1)
108#define V4L2_CID_MOTION_TRACE (SOLO_CID_CUSTOM_BASE+2)
109#define V4L2_CID_OSD_TEXT (SOLO_CID_CUSTOM_BASE+3)
110
111/*
112 * Motion thresholds are in a table of 64x64 samples, with
113 * each sample representing 16x16 pixels of the source. In
114 * effect, 44x30 samples are used for NTSC, and 44x36 for PAL.
115 * The 5th sample on the 10th row is (10*64)+5 = 645.
116 *
117 * Using a 64x64 array will result in a problem on some architectures like
118 * the powerpc where the size of the argument is limited to 13 bits.
119 * Since both PAL and NTSC do not use the full table anyway I've chosen
120 * to limit the array to 45x45 (45*16 = 720, which is the maximum PAL/NTSC
121 * width).
122 */
123#define SOLO_MOTION_SZ (45)
124struct solo_motion_thresholds {
125 __u16 thresholds[SOLO_MOTION_SZ][SOLO_MOTION_SZ];
126};
127
128#define SOLO_IOC_G_MOTION_THRESHOLDS _IOR('V', BASE_VIDIOC_PRIVATE+0, struct solo_motion_thresholds)
129#define SOLO_IOC_S_MOTION_THRESHOLDS _IOW('V', BASE_VIDIOC_PRIVATE+1, struct solo_motion_thresholds)
130
123enum SOLO_I2C_STATE { 131enum SOLO_I2C_STATE {
124 IIC_STATE_IDLE, 132 IIC_STATE_IDLE,
125 IIC_STATE_START, 133 IIC_STATE_START,
@@ -128,20 +136,29 @@ enum SOLO_I2C_STATE {
128 IIC_STATE_STOP 136 IIC_STATE_STOP
129}; 137};
130 138
131struct p2m_desc { 139/* Defined in Table 4-16, Page 68-69 of the 6010 Datasheet */
132 u32 ctrl; 140struct solo_p2m_desc {
133 u32 ext; 141 u32 ctrl;
134 u32 ta; 142 u32 cfg;
135 u32 fa; 143 u32 dma_addr;
144 u32 ext_addr;
136}; 145};
137 146
138struct solo_p2m_dev { 147struct solo_p2m_dev {
139 struct mutex mutex; 148 struct mutex mutex;
140 struct completion completion; 149 struct completion completion;
150 int desc_count;
151 int desc_idx;
152 struct solo_p2m_desc *descs;
141 int error; 153 int error;
142}; 154};
143 155
144#define OSD_TEXT_MAX 30 156#define OSD_TEXT_MAX 44
157
158struct solo_vb2_buf {
159 struct vb2_buffer vb;
160 struct list_head list;
161};
145 162
146enum solo_enc_types { 163enum solo_enc_types {
147 SOLO_ENC_TYPE_STD, 164 SOLO_ENC_TYPE_STD,
@@ -149,46 +166,61 @@ enum solo_enc_types {
149}; 166};
150 167
151struct solo_enc_dev { 168struct solo_enc_dev {
152 struct solo_dev *solo_dev; 169 struct solo_dev *solo_dev;
153 /* V4L2 Items */ 170 /* V4L2 Items */
171 struct v4l2_ctrl_handler hdl;
154 struct video_device *vfd; 172 struct video_device *vfd;
155 /* General accounting */ 173 /* General accounting */
156 wait_queue_head_t thread_wait; 174 struct mutex lock;
157 spinlock_t lock; 175 spinlock_t motion_lock;
158 atomic_t readers;
159 u8 ch; 176 u8 ch;
160 u8 mode, gop, qp, interlaced, interval; 177 u8 mode, gop, qp, interlaced, interval;
161 u8 reset_gop;
162 u8 bw_weight; 178 u8 bw_weight;
163 u8 motion_detected;
164 u16 motion_thresh; 179 u16 motion_thresh;
180 struct solo_motion_thresholds motion_thresholds;
181 bool motion_global;
182 bool motion_enabled;
165 u16 width; 183 u16 width;
166 u16 height; 184 u16 height;
185
186 /* OSD buffers */
167 char osd_text[OSD_TEXT_MAX + 1]; 187 char osd_text[OSD_TEXT_MAX + 1];
168}; 188 u8 osd_buf[SOLO_EOSD_EXT_SIZE_MAX]
189 __aligned(4);
169 190
170struct solo_enc_buf { 191 /* VOP stuff */
171 u8 vop; 192 unsigned char vop[64];
172 u8 ch; 193 int vop_len;
194 unsigned char jpeg_header[1024];
195 int jpeg_len;
196
197 u32 fmt;
173 enum solo_enc_types type; 198 enum solo_enc_types type;
174 u32 off; 199 u32 sequence;
175 u32 size; 200 struct vb2_queue vidq;
176 u32 jpeg_off; 201 struct list_head vidq_active;
177 u32 jpeg_size; 202 int desc_count;
178 struct timeval ts; 203 int desc_nelts;
204 struct solo_p2m_desc *desc_items;
205 dma_addr_t desc_dma;
206 spinlock_t av_lock;
179}; 207};
180 208
181/* The SOLO6x10 PCI Device */ 209/* The SOLO6x10 PCI Device */
182struct solo_dev { 210struct solo_dev {
183 /* General stuff */ 211 /* General stuff */
184 struct pci_dev *pdev; 212 struct pci_dev *pdev;
213 int type;
214 unsigned int time_sync;
215 unsigned int usec_lsb;
216 unsigned int clock_mhz;
185 u8 __iomem *reg_base; 217 u8 __iomem *reg_base;
186 int nr_chans; 218 int nr_chans;
187 int nr_ext; 219 int nr_ext;
188 u32 flags;
189 u32 irq_mask; 220 u32 irq_mask;
190 u32 motion_mask; 221 u32 motion_mask;
191 spinlock_t reg_io_lock; 222 spinlock_t reg_io_lock;
223 struct v4l2_device v4l2_dev;
192 224
193 /* tw28xx accounting */ 225 /* tw28xx accounting */
194 u8 tw2865, tw2864, tw2815; 226 u8 tw2865, tw2864, tw2815;
@@ -206,6 +238,9 @@ struct solo_dev {
206 238
207 /* P2M DMA Engine */ 239 /* P2M DMA Engine */
208 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M]; 240 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
241 atomic_t p2m_count;
242 int p2m_jiffies;
243 unsigned int p2m_timeouts;
209 244
210 /* V4L2 Display items */ 245 /* V4L2 Display items */
211 struct video_device *vfd; 246 struct video_device *vfd;
@@ -213,15 +248,13 @@ struct solo_dev {
213 unsigned int frame_blank; 248 unsigned int frame_blank;
214 u8 cur_disp_ch; 249 u8 cur_disp_ch;
215 wait_queue_head_t disp_thread_wait; 250 wait_queue_head_t disp_thread_wait;
251 struct v4l2_ctrl_handler disp_hdl;
216 252
217 /* V4L2 Encoder items */ 253 /* V4L2 Encoder items */
218 struct solo_enc_dev *v4l2_enc[SOLO_MAX_CHANNELS]; 254 struct solo_enc_dev *v4l2_enc[SOLO_MAX_CHANNELS];
219 u16 enc_bw_remain; 255 u16 enc_bw_remain;
220 /* IDX into hw mp4 encoder */ 256 /* IDX into hw mp4 encoder */
221 u8 enc_idx; 257 u8 enc_idx;
222 /* Our software ring of enc buf references */
223 u16 enc_wr_idx;
224 struct solo_enc_buf enc_buf[SOLO_NR_RING_BUFS];
225 258
226 /* Current video settings */ 259 /* Current video settings */
227 u32 video_type; 260 u32 video_type;
@@ -230,11 +263,40 @@ struct solo_dev {
230 u16 vin_hstart, vin_vstart; 263 u16 vin_hstart, vin_vstart;
231 u8 fps; 264 u8 fps;
232 265
266 /* JPEG Qp setting */
267 spinlock_t jpeg_qp_lock;
268 u32 jpeg_qp[2];
269
233 /* Audio components */ 270 /* Audio components */
234 struct snd_card *snd_card; 271 struct snd_card *snd_card;
235 struct snd_pcm *snd_pcm; 272 struct snd_pcm *snd_pcm;
236 atomic_t snd_users; 273 atomic_t snd_users;
237 int g723_hw_idx; 274 int g723_hw_idx;
275
276 /* sysfs stuffs */
277 struct device dev;
278 int sdram_size;
279 struct bin_attribute sdram_attr;
280 unsigned int sys_config;
281
282 /* Ring thread */
283 struct task_struct *ring_thread;
284 wait_queue_head_t ring_thread_wait;
285
286 /* VOP_HEADER handling */
287 void *vh_buf;
288 dma_addr_t vh_dma;
289 int vh_size;
290
291 /* Buffer handling */
292 struct vb2_queue vidq;
293 struct vb2_alloc_ctx *alloc_ctx;
294 u32 sequence;
295 struct task_struct *kthread;
296 struct mutex lock;
297 spinlock_t slock;
298 int old_write;
299 struct list_head vidq_active;
238}; 300};
239 301
240static inline u32 solo_reg_read(struct solo_dev *solo_dev, int reg) 302static inline u32 solo_reg_read(struct solo_dev *solo_dev, int reg)
@@ -255,7 +317,8 @@ static inline u32 solo_reg_read(struct solo_dev *solo_dev, int reg)
255 return ret; 317 return ret;
256} 318}
257 319
258static inline void solo_reg_write(struct solo_dev *solo_dev, int reg, u32 data) 320static inline void solo_reg_write(struct solo_dev *solo_dev, int reg,
321 u32 data)
259{ 322{
260 unsigned long flags; 323 unsigned long flags;
261 u16 val; 324 u16 val;
@@ -270,10 +333,19 @@ static inline void solo_reg_write(struct solo_dev *solo_dev, int reg, u32 data)
270 spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags); 333 spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags);
271} 334}
272 335
273void solo_irq_on(struct solo_dev *solo_dev, u32 mask); 336static inline void solo_irq_on(struct solo_dev *dev, u32 mask)
274void solo_irq_off(struct solo_dev *solo_dev, u32 mask); 337{
338 dev->irq_mask |= mask;
339 solo_reg_write(dev, SOLO_IRQ_MASK, dev->irq_mask);
340}
341
342static inline void solo_irq_off(struct solo_dev *dev, u32 mask)
343{
344 dev->irq_mask &= ~mask;
345 solo_reg_write(dev, SOLO_IRQ_MASK, dev->irq_mask);
346}
275 347
276/* Init/exit routeines for subsystems */ 348/* Init/exit routines for subsystems */
277int solo_disp_init(struct solo_dev *solo_dev); 349int solo_disp_init(struct solo_dev *solo_dev);
278void solo_disp_exit(struct solo_dev *solo_dev); 350void solo_disp_exit(struct solo_dev *solo_dev);
279 351
@@ -286,13 +358,13 @@ void solo_i2c_exit(struct solo_dev *solo_dev);
286int solo_p2m_init(struct solo_dev *solo_dev); 358int solo_p2m_init(struct solo_dev *solo_dev);
287void solo_p2m_exit(struct solo_dev *solo_dev); 359void solo_p2m_exit(struct solo_dev *solo_dev);
288 360
289int solo_v4l2_init(struct solo_dev *solo_dev); 361int solo_v4l2_init(struct solo_dev *solo_dev, unsigned nr);
290void solo_v4l2_exit(struct solo_dev *solo_dev); 362void solo_v4l2_exit(struct solo_dev *solo_dev);
291 363
292int solo_enc_init(struct solo_dev *solo_dev); 364int solo_enc_init(struct solo_dev *solo_dev);
293void solo_enc_exit(struct solo_dev *solo_dev); 365void solo_enc_exit(struct solo_dev *solo_dev);
294 366
295int solo_enc_v4l2_init(struct solo_dev *solo_dev); 367int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr);
296void solo_enc_v4l2_exit(struct solo_dev *solo_dev); 368void solo_enc_v4l2_exit(struct solo_dev *solo_dev);
297 369
298int solo_g723_init(struct solo_dev *solo_dev); 370int solo_g723_init(struct solo_dev *solo_dev);
@@ -301,7 +373,7 @@ void solo_g723_exit(struct solo_dev *solo_dev);
301/* ISR's */ 373/* ISR's */
302int solo_i2c_isr(struct solo_dev *solo_dev); 374int solo_i2c_isr(struct solo_dev *solo_dev);
303void solo_p2m_isr(struct solo_dev *solo_dev, int id); 375void solo_p2m_isr(struct solo_dev *solo_dev, int id);
304void solo_p2m_error_isr(struct solo_dev *solo_dev, u32 status); 376void solo_p2m_error_isr(struct solo_dev *solo_dev);
305void solo_enc_v4l2_isr(struct solo_dev *solo_dev); 377void solo_enc_v4l2_isr(struct solo_dev *solo_dev);
306void solo_g723_isr(struct solo_dev *solo_dev); 378void solo_g723_isr(struct solo_dev *solo_dev);
307void solo_motion_isr(struct solo_dev *solo_dev); 379void solo_motion_isr(struct solo_dev *solo_dev);
@@ -313,24 +385,43 @@ void solo_i2c_writebyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off,
313 u8 data); 385 u8 data);
314 386
315/* P2M DMA */ 387/* P2M DMA */
316int solo_p2m_dma_t(struct solo_dev *solo_dev, u8 id, int wr, 388int solo_p2m_dma_t(struct solo_dev *solo_dev, int wr,
317 dma_addr_t dma_addr, u32 ext_addr, u32 size); 389 dma_addr_t dma_addr, u32 ext_addr, u32 size,
318int solo_p2m_dma(struct solo_dev *solo_dev, u8 id, int wr, 390 int repeat, u32 ext_size);
319 void *sys_addr, u32 ext_addr, u32 size); 391int solo_p2m_dma(struct solo_dev *solo_dev, int wr,
320int solo_p2m_dma_sg(struct solo_dev *solo_dev, u8 id, 392 void *sys_addr, u32 ext_addr, u32 size,
321 struct p2m_desc *pdesc, int wr, 393 int repeat, u32 ext_size);
322 struct scatterlist *sglist, u32 sg_off, 394void solo_p2m_fill_desc(struct solo_p2m_desc *desc, int wr,
323 u32 ext_addr, u32 size); 395 dma_addr_t dma_addr, u32 ext_addr, u32 size,
324void solo_p2m_push_desc(struct p2m_desc *desc, int wr, dma_addr_t dma_addr, 396 int repeat, u32 ext_size);
325 u32 ext_addr, u32 size, int repeat, u32 ext_size); 397int solo_p2m_dma_desc(struct solo_dev *solo_dev,
326int solo_p2m_dma_desc(struct solo_dev *solo_dev, u8 id, 398 struct solo_p2m_desc *desc, dma_addr_t desc_dma,
327 struct p2m_desc *desc, int desc_count); 399 int desc_cnt);
400
401/* Global s_std ioctl */
402int solo_set_video_type(struct solo_dev *solo_dev, bool type);
403void solo_update_mode(struct solo_enc_dev *solo_enc);
328 404
329/* Set the threshold for motion detection */ 405/* Set the threshold for motion detection */
330void solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val); 406int solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val);
407int solo_set_motion_block(struct solo_dev *solo_dev, u8 ch,
408 const struct solo_motion_thresholds *thresholds);
331#define SOLO_DEF_MOT_THRESH 0x0300 409#define SOLO_DEF_MOT_THRESH 0x0300
332 410
333/* Write text on OSD */ 411/* Write text on OSD */
334int solo_osd_print(struct solo_enc_dev *solo_enc); 412int solo_osd_print(struct solo_enc_dev *solo_enc);
335 413
414/* EEPROM commands */
415unsigned int solo_eeprom_ewen(struct solo_dev *solo_dev, int w_en);
416unsigned short solo_eeprom_read(struct solo_dev *solo_dev, int loc);
417int solo_eeprom_write(struct solo_dev *solo_dev, int loc,
418 unsigned short data);
419
420/* JPEG Qp functions */
421void solo_s_jpeg_qp(struct solo_dev *solo_dev, unsigned int ch,
422 unsigned int qp);
423int solo_g_jpeg_qp(struct solo_dev *solo_dev, unsigned int ch);
424
425#define CHK_FLAGS(v, flags) (((v) & (flags)) == (flags))
426
336#endif /* __SOLO6X10_H */ 427#endif /* __SOLO6X10_H */
diff --git a/drivers/staging/media/solo6x10/v4l2-enc.c b/drivers/staging/media/solo6x10/v4l2-enc.c
deleted file mode 100644
index 4977e869d5b7..000000000000
--- a/drivers/staging/media/solo6x10/v4l2-enc.c
+++ /dev/null
@@ -1,1829 +0,0 @@
1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/kthread.h>
23#include <linux/freezer.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-common.h>
26#include <media/videobuf-dma-sg.h>
27#include "solo6x10.h"
28#include "tw28.h"
29#include "solo6x10-jpeg.h"
30
31#define MIN_VID_BUFFERS 4
32#define FRAME_BUF_SIZE (128 * 1024)
33#define MP4_QS 16
34
35static int solo_enc_thread(void *data);
36
37extern unsigned video_nr;
38
39struct solo_enc_fh {
40 struct solo_enc_dev *enc;
41 u32 fmt;
42 u16 rd_idx;
43 u8 enc_on;
44 enum solo_enc_types type;
45 struct videobuf_queue vidq;
46 struct list_head vidq_active;
47 struct task_struct *kthread;
48 struct p2m_desc desc[SOLO_NR_P2M_DESC];
49};
50
51static const u32 solo_user_ctrls[] = {
52 V4L2_CID_BRIGHTNESS,
53 V4L2_CID_CONTRAST,
54 V4L2_CID_SATURATION,
55 V4L2_CID_HUE,
56 V4L2_CID_SHARPNESS,
57 0
58};
59
60static const u32 solo_mpeg_ctrls[] = {
61 V4L2_CID_MPEG_VIDEO_ENCODING,
62 V4L2_CID_MPEG_VIDEO_GOP_SIZE,
63 0
64};
65
66static const u32 solo_private_ctrls[] = {
67 V4L2_CID_MOTION_ENABLE,
68 V4L2_CID_MOTION_THRESHOLD,
69 0
70};
71
72static const u32 solo_fmtx_ctrls[] = {
73 V4L2_CID_RDS_TX_RADIO_TEXT,
74 0
75};
76
77static const u32 *solo_ctrl_classes[] = {
78 solo_user_ctrls,
79 solo_mpeg_ctrls,
80 solo_fmtx_ctrls,
81 solo_private_ctrls,
82 NULL
83};
84
85static int solo_is_motion_on(struct solo_enc_dev *solo_enc)
86{
87 struct solo_dev *solo_dev = solo_enc->solo_dev;
88 u8 ch = solo_enc->ch;
89
90 if (solo_dev->motion_mask & (1 << ch))
91 return 1;
92 return 0;
93}
94
95static void solo_motion_toggle(struct solo_enc_dev *solo_enc, int on)
96{
97 struct solo_dev *solo_dev = solo_enc->solo_dev;
98 u8 ch = solo_enc->ch;
99
100 spin_lock(&solo_enc->lock);
101
102 if (on)
103 solo_dev->motion_mask |= (1 << ch);
104 else
105 solo_dev->motion_mask &= ~(1 << ch);
106
107 /* Do this regardless of if we are turning on or off */
108 solo_reg_write(solo_enc->solo_dev, SOLO_VI_MOT_CLEAR,
109 1 << solo_enc->ch);
110 solo_enc->motion_detected = 0;
111
112 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR,
113 SOLO_VI_MOTION_EN(solo_dev->motion_mask) |
114 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16));
115
116 if (solo_dev->motion_mask)
117 solo_irq_on(solo_dev, SOLO_IRQ_MOTION);
118 else
119 solo_irq_off(solo_dev, SOLO_IRQ_MOTION);
120
121 spin_unlock(&solo_enc->lock);
122}
123
124/* Should be called with solo_enc->lock held */
125static void solo_update_mode(struct solo_enc_dev *solo_enc)
126{
127 struct solo_dev *solo_dev = solo_enc->solo_dev;
128
129 assert_spin_locked(&solo_enc->lock);
130
131 solo_enc->interlaced = (solo_enc->mode & 0x08) ? 1 : 0;
132 solo_enc->bw_weight = max(solo_dev->fps / solo_enc->interval, 1);
133
134 switch (solo_enc->mode) {
135 case SOLO_ENC_MODE_CIF:
136 solo_enc->width = solo_dev->video_hsize >> 1;
137 solo_enc->height = solo_dev->video_vsize;
138 break;
139 case SOLO_ENC_MODE_D1:
140 solo_enc->width = solo_dev->video_hsize;
141 solo_enc->height = solo_dev->video_vsize << 1;
142 solo_enc->bw_weight <<= 2;
143 break;
144 default:
145 WARN(1, "mode is unknown\n");
146 }
147}
148
149/* Should be called with solo_enc->lock held */
150static int solo_enc_on(struct solo_enc_fh *fh)
151{
152 struct solo_enc_dev *solo_enc = fh->enc;
153 u8 ch = solo_enc->ch;
154 struct solo_dev *solo_dev = solo_enc->solo_dev;
155 u8 interval;
156
157 assert_spin_locked(&solo_enc->lock);
158
159 if (fh->enc_on)
160 return 0;
161
162 solo_update_mode(solo_enc);
163
164 /* Make sure to bw check on first reader */
165 if (!atomic_read(&solo_enc->readers)) {
166 if (solo_enc->bw_weight > solo_dev->enc_bw_remain)
167 return -EBUSY;
168 else
169 solo_dev->enc_bw_remain -= solo_enc->bw_weight;
170 }
171
172 fh->enc_on = 1;
173 fh->rd_idx = solo_enc->solo_dev->enc_wr_idx;
174
175 if (fh->type == SOLO_ENC_TYPE_EXT)
176 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(ch), 1);
177
178 if (atomic_inc_return(&solo_enc->readers) > 1)
179 return 0;
180
181 /* Disable all encoding for this channel */
182 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), 0);
183
184 /* Common for both std and ext encoding */
185 solo_reg_write(solo_dev, SOLO_VE_CH_INTL(ch),
186 solo_enc->interlaced ? 1 : 0);
187
188 if (solo_enc->interlaced)
189 interval = solo_enc->interval - 1;
190 else
191 interval = solo_enc->interval;
192
193 /* Standard encoding only */
194 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(ch), solo_enc->gop);
195 solo_reg_write(solo_dev, SOLO_VE_CH_QP(ch), solo_enc->qp);
196 solo_reg_write(solo_dev, SOLO_CAP_CH_INTV(ch), interval);
197
198 /* Extended encoding only */
199 solo_reg_write(solo_dev, SOLO_VE_CH_GOP_E(ch), solo_enc->gop);
200 solo_reg_write(solo_dev, SOLO_VE_CH_QP_E(ch), solo_enc->qp);
201 solo_reg_write(solo_dev, SOLO_CAP_CH_INTV_E(ch), interval);
202
203 /* Enables the standard encoder */
204 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), solo_enc->mode);
205
206 /* Settle down Beavis... */
207 mdelay(10);
208
209 return 0;
210}
211
212static void solo_enc_off(struct solo_enc_fh *fh)
213{
214 struct solo_enc_dev *solo_enc = fh->enc;
215 struct solo_dev *solo_dev = solo_enc->solo_dev;
216
217 if (!fh->enc_on)
218 return;
219
220 if (fh->kthread) {
221 kthread_stop(fh->kthread);
222 fh->kthread = NULL;
223 }
224
225 solo_dev->enc_bw_remain += solo_enc->bw_weight;
226 fh->enc_on = 0;
227
228 if (atomic_dec_return(&solo_enc->readers) > 0)
229 return;
230
231 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(solo_enc->ch), 0);
232 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(solo_enc->ch), 0);
233}
234
235static int solo_start_fh_thread(struct solo_enc_fh *fh)
236{
237 struct solo_enc_dev *solo_enc = fh->enc;
238
239 fh->kthread = kthread_run(solo_enc_thread, fh, SOLO6X10_NAME "_enc");
240
241 /* Oops, we had a problem */
242 if (IS_ERR(fh->kthread)) {
243 spin_lock(&solo_enc->lock);
244 solo_enc_off(fh);
245 spin_unlock(&solo_enc->lock);
246
247 return PTR_ERR(fh->kthread);
248 }
249
250 return 0;
251}
252
253static void enc_reset_gop(struct solo_dev *solo_dev, u8 ch)
254{
255 BUG_ON(ch >= solo_dev->nr_chans);
256 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(ch), 1);
257 solo_dev->v4l2_enc[ch]->reset_gop = 1;
258}
259
260static int enc_gop_reset(struct solo_dev *solo_dev, u8 ch, u8 vop)
261{
262 BUG_ON(ch >= solo_dev->nr_chans);
263 if (!solo_dev->v4l2_enc[ch]->reset_gop)
264 return 0;
265 if (vop)
266 return 1;
267 solo_dev->v4l2_enc[ch]->reset_gop = 0;
268 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(ch),
269 solo_dev->v4l2_enc[ch]->gop);
270 return 0;
271}
272
273static void enc_write_sg(struct scatterlist *sglist, void *buf, int size)
274{
275 struct scatterlist *sg;
276 u8 *src = buf;
277
278 for (sg = sglist; sg && size > 0; sg = sg_next(sg)) {
279 u8 *p = sg_virt(sg);
280 size_t len = sg_dma_len(sg);
281 int i;
282
283 for (i = 0; i < len && size; i++)
284 p[i] = *(src++);
285 }
286}
287
288static int enc_get_mpeg_dma_sg(struct solo_dev *solo_dev,
289 struct p2m_desc *desc,
290 struct scatterlist *sglist, int skip,
291 unsigned int off, unsigned int size)
292{
293 int ret;
294
295 if (off > SOLO_MP4E_EXT_SIZE(solo_dev))
296 return -EINVAL;
297
298 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) {
299 return solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_MP4E,
300 desc, 0, sglist, skip,
301 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size);
302 }
303
304 /* Buffer wrap */
305 ret = solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_MP4E, desc, 0,
306 sglist, skip, SOLO_MP4E_EXT_ADDR(solo_dev) + off,
307 SOLO_MP4E_EXT_SIZE(solo_dev) - off);
308
309 ret |= solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_MP4E, desc, 0,
310 sglist, skip + SOLO_MP4E_EXT_SIZE(solo_dev) - off,
311 SOLO_MP4E_EXT_ADDR(solo_dev),
312 size + off - SOLO_MP4E_EXT_SIZE(solo_dev));
313
314 return ret;
315}
316
317static int enc_get_mpeg_dma_t(struct solo_dev *solo_dev,
318 dma_addr_t buf, unsigned int off,
319 unsigned int size)
320{
321 int ret;
322
323 if (off > SOLO_MP4E_EXT_SIZE(solo_dev))
324 return -EINVAL;
325
326 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) {
327 return solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, buf,
328 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size);
329 }
330
331 /* Buffer wrap */
332 ret = solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, buf,
333 SOLO_MP4E_EXT_ADDR(solo_dev) + off,
334 SOLO_MP4E_EXT_SIZE(solo_dev) - off);
335
336 ret |= solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0,
337 buf + SOLO_MP4E_EXT_SIZE(solo_dev) - off,
338 SOLO_MP4E_EXT_ADDR(solo_dev),
339 size + off - SOLO_MP4E_EXT_SIZE(solo_dev));
340
341 return ret;
342}
343
344static int enc_get_mpeg_dma(struct solo_dev *solo_dev, void *buf,
345 unsigned int off, unsigned int size)
346{
347 int ret;
348
349 dma_addr_t dma_addr = pci_map_single(solo_dev->pdev, buf, size,
350 PCI_DMA_FROMDEVICE);
351 ret = enc_get_mpeg_dma_t(solo_dev, dma_addr, off, size);
352 pci_unmap_single(solo_dev->pdev, dma_addr, size, PCI_DMA_FROMDEVICE);
353
354 return ret;
355}
356
357static int enc_get_jpeg_dma_sg(struct solo_dev *solo_dev,
358 struct p2m_desc *desc,
359 struct scatterlist *sglist, int skip,
360 unsigned int off, unsigned int size)
361{
362 int ret;
363
364 if (off > SOLO_JPEG_EXT_SIZE(solo_dev))
365 return -EINVAL;
366
367 if (off + size <= SOLO_JPEG_EXT_SIZE(solo_dev)) {
368 return solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_JPEG,
369 desc, 0, sglist, skip,
370 SOLO_JPEG_EXT_ADDR(solo_dev) + off, size);
371 }
372
373 /* Buffer wrap */
374 ret = solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_JPEG, desc, 0,
375 sglist, skip, SOLO_JPEG_EXT_ADDR(solo_dev) + off,
376 SOLO_JPEG_EXT_SIZE(solo_dev) - off);
377
378 ret |= solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_JPEG, desc, 0,
379 sglist, skip + SOLO_JPEG_EXT_SIZE(solo_dev) - off,
380 SOLO_JPEG_EXT_ADDR(solo_dev),
381 size + off - SOLO_JPEG_EXT_SIZE(solo_dev));
382
383 return ret;
384}
385
386/* Returns true of __chk is within the first __range bytes of __off */
387#define OFF_IN_RANGE(__off, __range, __chk) \
388 ((__off <= __chk) && ((__off + __range) >= __chk))
389
390static void solo_jpeg_header(struct solo_enc_dev *solo_enc,
391 struct videobuf_dmabuf *vbuf)
392{
393 struct scatterlist *sg;
394 void *src = jpeg_header;
395 size_t copied = 0;
396 size_t to_copy = sizeof(jpeg_header);
397
398 for (sg = vbuf->sglist; sg && copied < to_copy; sg = sg_next(sg)) {
399 size_t this_copy = min(sg_dma_len(sg),
400 (unsigned int)(to_copy - copied));
401 u8 *p = sg_virt(sg);
402
403 memcpy(p, src + copied, this_copy);
404
405 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 5))
406 p[(SOF0_START + 5) - copied] =
407 0xff & (solo_enc->height >> 8);
408 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 6))
409 p[(SOF0_START + 6) - copied] = 0xff & solo_enc->height;
410 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 7))
411 p[(SOF0_START + 7) - copied] =
412 0xff & (solo_enc->width >> 8);
413 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 8))
414 p[(SOF0_START + 8) - copied] = 0xff & solo_enc->width;
415
416 copied += this_copy;
417 }
418}
419
420static int solo_fill_jpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf,
421 struct videobuf_buffer *vb,
422 struct videobuf_dmabuf *vbuf)
423{
424 struct solo_dev *solo_dev = fh->enc->solo_dev;
425 int size = enc_buf->jpeg_size;
426
427 /* Copy the header first (direct write) */
428 solo_jpeg_header(fh->enc, vbuf);
429
430 vb->size = size + sizeof(jpeg_header);
431
432 /* Grab the jpeg frame */
433 return enc_get_jpeg_dma_sg(solo_dev, fh->desc, vbuf->sglist,
434 sizeof(jpeg_header),
435 enc_buf->jpeg_off, size);
436}
437
438static inline int vop_interlaced(__le32 *vh)
439{
440 return (__le32_to_cpu(vh[0]) >> 30) & 1;
441}
442
443static inline u32 vop_size(__le32 *vh)
444{
445 return __le32_to_cpu(vh[0]) & 0xFFFFF;
446}
447
448static inline u8 vop_hsize(__le32 *vh)
449{
450 return (__le32_to_cpu(vh[1]) >> 8) & 0xFF;
451}
452
453static inline u8 vop_vsize(__le32 *vh)
454{
455 return __le32_to_cpu(vh[1]) & 0xFF;
456}
457
458/* must be called with *bits % 8 = 0 */
459static void write_bytes(u8 **out, unsigned *bits, const u8 *src, unsigned count)
460{
461 memcpy(*out, src, count);
462 *out += count;
463 *bits += count * 8;
464}
465
466static void write_bits(u8 **out, unsigned *bits, u32 value, unsigned count)
467{
468
469 value <<= 32 - count; // shift to the right
470
471 while (count--) {
472 **out <<= 1;
473 **out |= !!(value & (1 << 31)); /* MSB */
474 value <<= 1;
475 if (++(*bits) % 8 == 0)
476 (*out)++;
477 }
478}
479
480static void write_ue(u8 **out, unsigned *bits, unsigned value) /* H.264 only */
481{
482 uint32_t max = 0, cnt = 0;
483
484 while (value > max) {
485 max = (max + 2) * 2 - 2;
486 cnt++;
487 }
488 write_bits(out, bits, 1, cnt + 1);
489 write_bits(out, bits, ~(max - value), cnt);
490}
491
492static void write_se(u8 **out, unsigned *bits, int value) /* H.264 only */
493{
494 if (value <= 0)
495 write_ue(out, bits, -value * 2);
496 else
497 write_ue(out, bits, value * 2 - 1);
498}
499
500static void write_mpeg4_end(u8 **out, unsigned *bits)
501{
502 write_bits(out, bits, 0, 1);
503 /* align on 32-bit boundary */
504 if (*bits % 32)
505 write_bits(out, bits, 0xFFFFFFFF, 32 - *bits % 32);
506}
507
508static void write_h264_end(u8 **out, unsigned *bits, int align)
509{
510 write_bits(out, bits, 1, 1);
511 while ((*bits) % 8)
512 write_bits(out, bits, 0, 1);
513 if (align)
514 while ((*bits) % 32)
515 write_bits(out, bits, 0, 1);
516}
517
518static void mpeg4_write_vol(u8 **out, struct solo_dev *solo_dev,
519 __le32 *vh, unsigned fps, unsigned interval)
520{
521 static const u8 hdr[] = {
522 0, 0, 1, 0x00 /* video_object_start_code */,
523 0, 0, 1, 0x20 /* video_object_layer_start_code */
524 };
525 unsigned bits = 0;
526 unsigned width = vop_hsize(vh) << 4;
527 unsigned height = vop_vsize(vh) << 4;
528 unsigned interlaced = vop_interlaced(vh);
529
530 write_bytes(out, &bits, hdr, sizeof(hdr));
531 write_bits(out, &bits, 0, 1); /* random_accessible_vol */
532 write_bits(out, &bits, 0x04, 8); /* video_object_type_indication: main */
533 write_bits(out, &bits, 1, 1); /* is_object_layer_identifier */
534 write_bits(out, &bits, 2, 4); /* video_object_layer_verid: table V2-39 */
535 write_bits(out, &bits, 0, 3); /* video_object_layer_priority */
536 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
537 write_bits(out, &bits, 3, 4); /* aspect_ratio_info, assuming 4:3 */
538 else
539 write_bits(out, &bits, 2, 4);
540 write_bits(out, &bits, 1, 1); /* vol_control_parameters */
541 write_bits(out, &bits, 1, 2); /* chroma_format: 4:2:0 */
542 write_bits(out, &bits, 1, 1); /* low_delay */
543 write_bits(out, &bits, 0, 1); /* vbv_parameters */
544 write_bits(out, &bits, 0, 2); /* video_object_layer_shape: rectangular */
545 write_bits(out, &bits, 1, 1); /* marker_bit */
546 write_bits(out, &bits, fps, 16); /* vop_time_increment_resolution */
547 write_bits(out, &bits, 1, 1); /* marker_bit */
548 write_bits(out, &bits, 1, 1); /* fixed_vop_rate */
549 write_bits(out, &bits, interval, 15); /* fixed_vop_time_increment */
550 write_bits(out, &bits, 1, 1); /* marker_bit */
551 write_bits(out, &bits, width, 13); /* video_object_layer_width */
552 write_bits(out, &bits, 1, 1); /* marker_bit */
553 write_bits(out, &bits, height, 13); /* video_object_layer_height */
554 write_bits(out, &bits, 1, 1); /* marker_bit */
555 write_bits(out, &bits, interlaced, 1); /* interlaced */
556 write_bits(out, &bits, 1, 1); /* obmc_disable */
557 write_bits(out, &bits, 0, 2); /* sprite_enable */
558 write_bits(out, &bits, 0, 1); /* not_8_bit */
559 write_bits(out, &bits, 1, 0); /* quant_type */
560 write_bits(out, &bits, 0, 1); /* load_intra_quant_mat */
561 write_bits(out, &bits, 0, 1); /* load_nonintra_quant_mat */
562 write_bits(out, &bits, 0, 1); /* quarter_sample */
563 write_bits(out, &bits, 1, 1); /* complexity_estimation_disable */
564 write_bits(out, &bits, 1, 1); /* resync_marker_disable */
565 write_bits(out, &bits, 0, 1); /* data_partitioned */
566 write_bits(out, &bits, 0, 1); /* newpred_enable */
567 write_bits(out, &bits, 0, 1); /* reduced_resolution_vop_enable */
568 write_bits(out, &bits, 0, 1); /* scalability */
569 write_mpeg4_end(out, &bits);
570}
571
572static void h264_write_vol(u8 **out, struct solo_dev *solo_dev, __le32 *vh)
573{
574 static const u8 sps[] = {
575 0, 0, 0, 1 /* start code */, 0x67, 66 /* profile_idc */,
576 0 /* constraints */, 30 /* level_idc */
577 };
578 static const u8 pps[] = {
579 0, 0, 0, 1 /* start code */, 0x68
580 };
581
582 unsigned bits = 0;
583 unsigned mbs_w = vop_hsize(vh);
584 unsigned mbs_h = vop_vsize(vh);
585
586 write_bytes(out, &bits, sps, sizeof(sps));
587 write_ue(out, &bits, 0); /* seq_parameter_set_id */
588 write_ue(out, &bits, 5); /* log2_max_frame_num_minus4 */
589 write_ue(out, &bits, 0); /* pic_order_cnt_type */
590 write_ue(out, &bits, 6); /* log2_max_pic_order_cnt_lsb_minus4 */
591 write_ue(out, &bits, 1); /* max_num_ref_frames */
592 write_bits(out, &bits, 0, 1); /* gaps_in_frame_num_value_allowed_flag */
593 write_ue(out, &bits, mbs_w - 1); /* pic_width_in_mbs_minus1 */
594 write_ue(out, &bits, mbs_h - 1); /* pic_height_in_map_units_minus1 */
595 write_bits(out, &bits, 1, 1); /* frame_mbs_only_flag */
596 write_bits(out, &bits, 1, 1); /* direct_8x8_frame_field_flag */
597 write_bits(out, &bits, 0, 1); /* frame_cropping_flag */
598 write_bits(out, &bits, 0, 1); /* vui_parameters_present_flag */
599 write_h264_end(out, &bits, 0);
600
601 write_bytes(out, &bits, pps, sizeof(pps));
602 write_ue(out, &bits, 0); /* pic_parameter_set_id */
603 write_ue(out, &bits, 0); /* seq_parameter_set_id */
604 write_bits(out, &bits, 0, 1); /* entropy_coding_mode_flag */
605 write_bits(out, &bits, 0, 1); /* bottom_field_pic_order_in_frame_present_flag */
606 write_ue(out, &bits, 0); /* num_slice_groups_minus1 */
607 write_ue(out, &bits, 0); /* num_ref_idx_l0_default_active_minus1 */
608 write_ue(out, &bits, 0); /* num_ref_idx_l1_default_active_minus1 */
609 write_bits(out, &bits, 0, 1); /* weighted_pred_flag */
610 write_bits(out, &bits, 0, 2); /* weighted_bipred_idc */
611 write_se(out, &bits, 0); /* pic_init_qp_minus26 */
612 write_se(out, &bits, 0); /* pic_init_qs_minus26 */
613 write_se(out, &bits, 2); /* chroma_qp_index_offset */
614 write_bits(out, &bits, 0, 1); /* deblocking_filter_control_present_flag */
615 write_bits(out, &bits, 1, 1); /* constrained_intra_pred_flag */
616 write_bits(out, &bits, 0, 1); /* redundant_pic_cnt_present_flag */
617 write_h264_end(out, &bits, 1);
618}
619
620static int solo_fill_mpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf,
621 struct videobuf_buffer *vb,
622 struct videobuf_dmabuf *vbuf)
623{
624 struct solo_enc_dev *solo_enc = fh->enc;
625 struct solo_dev *solo_dev = solo_enc->solo_dev;
626
627#define VH_WORDS 16
628#define MAX_VOL_HEADER_LENGTH 64
629
630 __le32 vh[VH_WORDS];
631 int ret;
632 int frame_size, frame_off;
633 int skip = 0;
634
635 if (WARN_ON_ONCE(enc_buf->size <= sizeof(vh)))
636 return -EINVAL;
637
638 /* First get the hardware vop header (not real mpeg) */
639 ret = enc_get_mpeg_dma(solo_dev, vh, enc_buf->off, sizeof(vh));
640 if (WARN_ON_ONCE(ret))
641 return ret;
642
643 if (WARN_ON_ONCE(vop_size(vh) > enc_buf->size))
644 return -EINVAL;
645
646 vb->width = vop_hsize(vh) << 4;
647 vb->height = vop_vsize(vh) << 4;
648 vb->size = vop_size(vh);
649
650 /* If this is a key frame, add extra m4v header */
651 if (!enc_buf->vop) {
652 u8 header[MAX_VOL_HEADER_LENGTH], *out = header;
653
654 if (solo_dev->flags & FLAGS_6110)
655 h264_write_vol(&out, solo_dev, vh);
656 else
657 mpeg4_write_vol(&out, solo_dev, vh,
658 solo_dev->fps * 1000,
659 solo_enc->interval * 1000);
660 skip = out - header;
661 enc_write_sg(vbuf->sglist, header, skip);
662 /* Adjust the dma buffer past this header */
663 vb->size += skip;
664 }
665
666 /* Now get the actual mpeg payload */
667 frame_off = (enc_buf->off + sizeof(vh)) % SOLO_MP4E_EXT_SIZE(solo_dev);
668 frame_size = enc_buf->size - sizeof(vh);
669
670 ret = enc_get_mpeg_dma_sg(solo_dev, fh->desc, vbuf->sglist,
671 skip, frame_off, frame_size);
672 WARN_ON_ONCE(ret);
673
674 return ret;
675}
676
677static void solo_enc_fillbuf(struct solo_enc_fh *fh,
678 struct videobuf_buffer *vb)
679{
680 struct solo_enc_dev *solo_enc = fh->enc;
681 struct solo_dev *solo_dev = solo_enc->solo_dev;
682 struct solo_enc_buf *enc_buf = NULL;
683 struct videobuf_dmabuf *vbuf;
684 int ret;
685 int error = 1;
686 u16 idx = fh->rd_idx;
687
688 while (idx != solo_dev->enc_wr_idx) {
689 struct solo_enc_buf *ebuf = &solo_dev->enc_buf[idx];
690
691 idx = (idx + 1) % SOLO_NR_RING_BUFS;
692
693 if (ebuf->ch != solo_enc->ch)
694 continue;
695
696 if (fh->fmt == V4L2_PIX_FMT_MPEG) {
697 if (fh->type == ebuf->type) {
698 enc_buf = ebuf;
699 break;
700 }
701 } else {
702 /* For mjpeg, keep reading to the newest frame */
703 enc_buf = ebuf;
704 }
705 }
706
707 fh->rd_idx = idx;
708
709 if (WARN_ON_ONCE(!enc_buf))
710 goto buf_err;
711
712 if ((fh->fmt == V4L2_PIX_FMT_MPEG &&
713 vb->bsize < enc_buf->size) ||
714 (fh->fmt == V4L2_PIX_FMT_MJPEG &&
715 vb->bsize < (enc_buf->jpeg_size + sizeof(jpeg_header)))) {
716 WARN_ON_ONCE(1);
717 goto buf_err;
718 }
719
720 vbuf = videobuf_to_dma(vb);
721 if (WARN_ON_ONCE(!vbuf))
722 goto buf_err;
723
724 if (fh->fmt == V4L2_PIX_FMT_MPEG)
725 ret = solo_fill_mpeg(fh, enc_buf, vb, vbuf);
726 else
727 ret = solo_fill_jpeg(fh, enc_buf, vb, vbuf);
728
729 if (!ret)
730 error = 0;
731
732buf_err:
733 if (error) {
734 vb->state = VIDEOBUF_ERROR;
735 } else {
736 vb->field_count++;
737 vb->ts = enc_buf->ts;
738 vb->state = VIDEOBUF_DONE;
739 }
740
741 wake_up(&vb->done);
742
743 return;
744}
745
746static void solo_enc_thread_try(struct solo_enc_fh *fh)
747{
748 struct solo_enc_dev *solo_enc = fh->enc;
749 struct solo_dev *solo_dev = solo_enc->solo_dev;
750 struct videobuf_buffer *vb;
751
752 for (;;) {
753 spin_lock(&solo_enc->lock);
754
755 if (fh->rd_idx == solo_dev->enc_wr_idx)
756 break;
757
758 if (list_empty(&fh->vidq_active))
759 break;
760
761 vb = list_first_entry(&fh->vidq_active,
762 struct videobuf_buffer, queue);
763
764 if (!waitqueue_active(&vb->done))
765 break;
766
767 list_del(&vb->queue);
768
769 spin_unlock(&solo_enc->lock);
770
771 solo_enc_fillbuf(fh, vb);
772 }
773
774 assert_spin_locked(&solo_enc->lock);
775 spin_unlock(&solo_enc->lock);
776}
777
778static int solo_enc_thread(void *data)
779{
780 struct solo_enc_fh *fh = data;
781 struct solo_enc_dev *solo_enc = fh->enc;
782 DECLARE_WAITQUEUE(wait, current);
783
784 set_freezable();
785 add_wait_queue(&solo_enc->thread_wait, &wait);
786
787 for (;;) {
788 long timeout = schedule_timeout_interruptible(HZ);
789 if (timeout == -ERESTARTSYS || kthread_should_stop())
790 break;
791 solo_enc_thread_try(fh);
792 try_to_freeze();
793 }
794
795 remove_wait_queue(&solo_enc->thread_wait, &wait);
796
797 return 0;
798}
799
800void solo_motion_isr(struct solo_dev *solo_dev)
801{
802 u32 status;
803 int i;
804
805 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_MOTION);
806
807 status = solo_reg_read(solo_dev, SOLO_VI_MOT_STATUS);
808
809 for (i = 0; i < solo_dev->nr_chans; i++) {
810 struct solo_enc_dev *solo_enc = solo_dev->v4l2_enc[i];
811
812 BUG_ON(solo_enc == NULL);
813
814 if (solo_enc->motion_detected)
815 continue;
816 if (!(status & (1 << i)))
817 continue;
818
819 solo_enc->motion_detected = 1;
820 }
821}
822
823void solo_enc_v4l2_isr(struct solo_dev *solo_dev)
824{
825 struct solo_enc_buf *enc_buf;
826 u32 mpeg_current, mpeg_next, mpeg_size;
827 u32 jpeg_current, jpeg_next, jpeg_size;
828 u32 reg_mpeg_size;
829 u8 cur_q, vop_type;
830 u8 ch;
831 enum solo_enc_types enc_type;
832
833 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_ENCODER);
834
835 cur_q = ((solo_reg_read(solo_dev, SOLO_VE_STATE(11)) & 0xF) + 1) % MP4_QS;
836
837 reg_mpeg_size = ((solo_reg_read(solo_dev, SOLO_VE_STATE(0)) & 0xFFFFF) + 64 + 8) & ~7;
838
839 while (solo_dev->enc_idx != cur_q) {
840 mpeg_current = solo_reg_read(solo_dev,
841 SOLO_VE_MPEG4_QUE(solo_dev->enc_idx));
842 jpeg_current = solo_reg_read(solo_dev,
843 SOLO_VE_JPEG_QUE(solo_dev->enc_idx));
844 solo_dev->enc_idx = (solo_dev->enc_idx + 1) % MP4_QS;
845 mpeg_next = solo_reg_read(solo_dev,
846 SOLO_VE_MPEG4_QUE(solo_dev->enc_idx));
847 jpeg_next = solo_reg_read(solo_dev,
848 SOLO_VE_JPEG_QUE(solo_dev->enc_idx));
849
850 ch = (mpeg_current >> 24) & 0x1f;
851 if (ch >= SOLO_MAX_CHANNELS) {
852 ch -= SOLO_MAX_CHANNELS;
853 enc_type = SOLO_ENC_TYPE_EXT;
854 } else
855 enc_type = SOLO_ENC_TYPE_STD;
856
857 vop_type = (mpeg_current >> 29) & 3;
858
859 mpeg_current &= 0x00ffffff;
860 mpeg_next &= 0x00ffffff;
861 jpeg_current &= 0x00ffffff;
862 jpeg_next &= 0x00ffffff;
863
864 mpeg_size = (SOLO_MP4E_EXT_SIZE(solo_dev) +
865 mpeg_next - mpeg_current) %
866 SOLO_MP4E_EXT_SIZE(solo_dev);
867
868 jpeg_size = (SOLO_JPEG_EXT_SIZE(solo_dev) +
869 jpeg_next - jpeg_current) %
870 SOLO_JPEG_EXT_SIZE(solo_dev);
871
872 /* XXX I think this means we had a ring overflow? */
873 if (mpeg_current > mpeg_next && mpeg_size != reg_mpeg_size) {
874 enc_reset_gop(solo_dev, ch);
875 continue;
876 }
877
878 /* When resetting the GOP, skip frames until I-frame */
879 if (enc_gop_reset(solo_dev, ch, vop_type))
880 continue;
881
882 enc_buf = &solo_dev->enc_buf[solo_dev->enc_wr_idx];
883
884 enc_buf->vop = vop_type;
885 enc_buf->ch = ch;
886 enc_buf->off = mpeg_current;
887 enc_buf->size = mpeg_size;
888 enc_buf->jpeg_off = jpeg_current;
889 enc_buf->jpeg_size = jpeg_size;
890 enc_buf->type = enc_type;
891
892 do_gettimeofday(&enc_buf->ts);
893
894 solo_dev->enc_wr_idx = (solo_dev->enc_wr_idx + 1) %
895 SOLO_NR_RING_BUFS;
896
897 wake_up_interruptible(&solo_dev->v4l2_enc[ch]->thread_wait);
898 }
899
900 return;
901}
902
903static int solo_enc_buf_setup(struct videobuf_queue *vq, unsigned int *count,
904 unsigned int *size)
905{
906 *size = FRAME_BUF_SIZE;
907
908 if (*count < MIN_VID_BUFFERS)
909 *count = MIN_VID_BUFFERS;
910
911 return 0;
912}
913
914static int solo_enc_buf_prepare(struct videobuf_queue *vq,
915 struct videobuf_buffer *vb,
916 enum v4l2_field field)
917{
918 struct solo_enc_fh *fh = vq->priv_data;
919 struct solo_enc_dev *solo_enc = fh->enc;
920
921 vb->size = FRAME_BUF_SIZE;
922 if (vb->baddr != 0 && vb->bsize < vb->size)
923 return -EINVAL;
924
925 /* These properties only change when queue is idle */
926 vb->width = solo_enc->width;
927 vb->height = solo_enc->height;
928 vb->field = field;
929
930 if (vb->state == VIDEOBUF_NEEDS_INIT) {
931 int rc = videobuf_iolock(vq, vb, NULL);
932 if (rc < 0) {
933 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
934 videobuf_dma_unmap(vq->dev, dma);
935 videobuf_dma_free(dma);
936 vb->state = VIDEOBUF_NEEDS_INIT;
937 return rc;
938 }
939 }
940 vb->state = VIDEOBUF_PREPARED;
941
942 return 0;
943}
944
945static void solo_enc_buf_queue(struct videobuf_queue *vq,
946 struct videobuf_buffer *vb)
947{
948 struct solo_enc_fh *fh = vq->priv_data;
949
950 vb->state = VIDEOBUF_QUEUED;
951 list_add_tail(&vb->queue, &fh->vidq_active);
952 wake_up_interruptible(&fh->enc->thread_wait);
953}
954
955static void solo_enc_buf_release(struct videobuf_queue *vq,
956 struct videobuf_buffer *vb)
957{
958 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
959
960 videobuf_dma_unmap(vq->dev, dma);
961 videobuf_dma_free(dma);
962 vb->state = VIDEOBUF_NEEDS_INIT;
963}
964
965static struct videobuf_queue_ops solo_enc_video_qops = {
966 .buf_setup = solo_enc_buf_setup,
967 .buf_prepare = solo_enc_buf_prepare,
968 .buf_queue = solo_enc_buf_queue,
969 .buf_release = solo_enc_buf_release,
970};
971
972static unsigned int solo_enc_poll(struct file *file,
973 struct poll_table_struct *wait)
974{
975 struct solo_enc_fh *fh = file->private_data;
976
977 return videobuf_poll_stream(file, &fh->vidq, wait);
978}
979
980static int solo_enc_mmap(struct file *file, struct vm_area_struct *vma)
981{
982 struct solo_enc_fh *fh = file->private_data;
983
984 return videobuf_mmap_mapper(&fh->vidq, vma);
985}
986
987static int solo_enc_open(struct file *file)
988{
989 struct solo_enc_dev *solo_enc = video_drvdata(file);
990 struct solo_enc_fh *fh;
991
992 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
993 if (fh == NULL)
994 return -ENOMEM;
995
996 fh->enc = solo_enc;
997 file->private_data = fh;
998 INIT_LIST_HEAD(&fh->vidq_active);
999 fh->fmt = V4L2_PIX_FMT_MPEG;
1000 fh->type = SOLO_ENC_TYPE_STD;
1001
1002 videobuf_queue_sg_init(&fh->vidq, &solo_enc_video_qops,
1003 &solo_enc->solo_dev->pdev->dev,
1004 &solo_enc->lock,
1005 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1006 V4L2_FIELD_INTERLACED,
1007 sizeof(struct videobuf_buffer), fh, NULL);
1008
1009 return 0;
1010}
1011
1012static ssize_t solo_enc_read(struct file *file, char __user *data,
1013 size_t count, loff_t *ppos)
1014{
1015 struct solo_enc_fh *fh = file->private_data;
1016 struct solo_enc_dev *solo_enc = fh->enc;
1017
1018 /* Make sure the encoder is on */
1019 if (!fh->enc_on) {
1020 int ret;
1021
1022 spin_lock(&solo_enc->lock);
1023 ret = solo_enc_on(fh);
1024 spin_unlock(&solo_enc->lock);
1025 if (ret)
1026 return ret;
1027
1028 ret = solo_start_fh_thread(fh);
1029 if (ret)
1030 return ret;
1031 }
1032
1033 return videobuf_read_stream(&fh->vidq, data, count, ppos, 0,
1034 file->f_flags & O_NONBLOCK);
1035}
1036
1037static int solo_enc_release(struct file *file)
1038{
1039 struct solo_enc_fh *fh = file->private_data;
1040 struct solo_enc_dev *solo_enc = fh->enc;
1041
1042 videobuf_stop(&fh->vidq);
1043 videobuf_mmap_free(&fh->vidq);
1044
1045 spin_lock(&solo_enc->lock);
1046 solo_enc_off(fh);
1047 spin_unlock(&solo_enc->lock);
1048
1049 kfree(fh);
1050
1051 return 0;
1052}
1053
1054static int solo_enc_querycap(struct file *file, void *priv,
1055 struct v4l2_capability *cap)
1056{
1057 struct solo_enc_fh *fh = priv;
1058 struct solo_enc_dev *solo_enc = fh->enc;
1059 struct solo_dev *solo_dev = solo_enc->solo_dev;
1060
1061 strcpy(cap->driver, SOLO6X10_NAME);
1062 snprintf(cap->card, sizeof(cap->card), "Softlogic 6x10 Enc %d",
1063 solo_enc->ch);
1064 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI %s",
1065 pci_name(solo_dev->pdev));
1066 cap->version = SOLO6X10_VER_NUM;
1067 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
1068 V4L2_CAP_READWRITE |
1069 V4L2_CAP_STREAMING;
1070 return 0;
1071}
1072
1073static int solo_enc_enum_input(struct file *file, void *priv,
1074 struct v4l2_input *input)
1075{
1076 struct solo_enc_fh *fh = priv;
1077 struct solo_enc_dev *solo_enc = fh->enc;
1078 struct solo_dev *solo_dev = solo_enc->solo_dev;
1079
1080 if (input->index)
1081 return -EINVAL;
1082
1083 snprintf(input->name, sizeof(input->name), "Encoder %d",
1084 solo_enc->ch + 1);
1085 input->type = V4L2_INPUT_TYPE_CAMERA;
1086
1087 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
1088 input->std = V4L2_STD_NTSC_M;
1089 else
1090 input->std = V4L2_STD_PAL_B;
1091
1092 if (!tw28_get_video_status(solo_dev, solo_enc->ch))
1093 input->status = V4L2_IN_ST_NO_SIGNAL;
1094
1095 return 0;
1096}
1097
1098static int solo_enc_set_input(struct file *file, void *priv, unsigned int index)
1099{
1100 if (index)
1101 return -EINVAL;
1102
1103 return 0;
1104}
1105
1106static int solo_enc_get_input(struct file *file, void *priv,
1107 unsigned int *index)
1108{
1109 *index = 0;
1110
1111 return 0;
1112}
1113
1114static int solo_enc_enum_fmt_cap(struct file *file, void *priv,
1115 struct v4l2_fmtdesc *f)
1116{
1117 switch (f->index) {
1118 case 0:
1119 f->pixelformat = V4L2_PIX_FMT_MPEG;
1120 strcpy(f->description, "MPEG-4 AVC");
1121 break;
1122 case 1:
1123 f->pixelformat = V4L2_PIX_FMT_MJPEG;
1124 strcpy(f->description, "MJPEG");
1125 break;
1126 default:
1127 return -EINVAL;
1128 }
1129
1130 f->flags = V4L2_FMT_FLAG_COMPRESSED;
1131
1132 return 0;
1133}
1134
1135static int solo_enc_try_fmt_cap(struct file *file, void *priv,
1136 struct v4l2_format *f)
1137{
1138 struct solo_enc_fh *fh = priv;
1139 struct solo_enc_dev *solo_enc = fh->enc;
1140 struct solo_dev *solo_dev = solo_enc->solo_dev;
1141 struct v4l2_pix_format *pix = &f->fmt.pix;
1142
1143 if (pix->pixelformat != V4L2_PIX_FMT_MPEG &&
1144 pix->pixelformat != V4L2_PIX_FMT_MJPEG)
1145 return -EINVAL;
1146
1147 /* We cannot change width/height in mid read */
1148 if (atomic_read(&solo_enc->readers) > 0) {
1149 if (pix->width != solo_enc->width ||
1150 pix->height != solo_enc->height)
1151 return -EBUSY;
1152 }
1153
1154 if (pix->width < solo_dev->video_hsize ||
1155 pix->height < solo_dev->video_vsize << 1) {
1156 /* Default to CIF 1/2 size */
1157 pix->width = solo_dev->video_hsize >> 1;
1158 pix->height = solo_dev->video_vsize;
1159 } else {
1160 /* Full frame */
1161 pix->width = solo_dev->video_hsize;
1162 pix->height = solo_dev->video_vsize << 1;
1163 }
1164
1165 if (pix->field == V4L2_FIELD_ANY)
1166 pix->field = V4L2_FIELD_INTERLACED;
1167 else if (pix->field != V4L2_FIELD_INTERLACED)
1168 pix->field = V4L2_FIELD_INTERLACED;
1169
1170 /* Just set these */
1171 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1172 pix->sizeimage = FRAME_BUF_SIZE;
1173
1174 return 0;
1175}
1176
1177static int solo_enc_set_fmt_cap(struct file *file, void *priv,
1178 struct v4l2_format *f)
1179{
1180 struct solo_enc_fh *fh = priv;
1181 struct solo_enc_dev *solo_enc = fh->enc;
1182 struct solo_dev *solo_dev = solo_enc->solo_dev;
1183 struct v4l2_pix_format *pix = &f->fmt.pix;
1184 int ret;
1185
1186 spin_lock(&solo_enc->lock);
1187
1188 ret = solo_enc_try_fmt_cap(file, priv, f);
1189 if (ret) {
1190 spin_unlock(&solo_enc->lock);
1191 return ret;
1192 }
1193
1194 if (pix->width == solo_dev->video_hsize)
1195 solo_enc->mode = SOLO_ENC_MODE_D1;
1196 else
1197 solo_enc->mode = SOLO_ENC_MODE_CIF;
1198
1199 /* This does not change the encoder at all */
1200 fh->fmt = pix->pixelformat;
1201
1202 if (pix->priv)
1203 fh->type = SOLO_ENC_TYPE_EXT;
1204 ret = solo_enc_on(fh);
1205
1206 spin_unlock(&solo_enc->lock);
1207
1208 if (ret)
1209 return ret;
1210
1211 return solo_start_fh_thread(fh);
1212}
1213
1214static int solo_enc_get_fmt_cap(struct file *file, void *priv,
1215 struct v4l2_format *f)
1216{
1217 struct solo_enc_fh *fh = priv;
1218 struct solo_enc_dev *solo_enc = fh->enc;
1219 struct v4l2_pix_format *pix = &f->fmt.pix;
1220
1221 pix->width = solo_enc->width;
1222 pix->height = solo_enc->height;
1223 pix->pixelformat = fh->fmt;
1224 pix->field = solo_enc->interlaced ? V4L2_FIELD_INTERLACED :
1225 V4L2_FIELD_NONE;
1226 pix->sizeimage = FRAME_BUF_SIZE;
1227 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1228
1229 return 0;
1230}
1231
1232static int solo_enc_reqbufs(struct file *file, void *priv,
1233 struct v4l2_requestbuffers *req)
1234{
1235 struct solo_enc_fh *fh = priv;
1236
1237 return videobuf_reqbufs(&fh->vidq, req);
1238}
1239
1240static int solo_enc_querybuf(struct file *file, void *priv,
1241 struct v4l2_buffer *buf)
1242{
1243 struct solo_enc_fh *fh = priv;
1244
1245 return videobuf_querybuf(&fh->vidq, buf);
1246}
1247
1248static int solo_enc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1249{
1250 struct solo_enc_fh *fh = priv;
1251
1252 return videobuf_qbuf(&fh->vidq, buf);
1253}
1254
1255static int solo_enc_dqbuf(struct file *file, void *priv,
1256 struct v4l2_buffer *buf)
1257{
1258 struct solo_enc_fh *fh = priv;
1259 struct solo_enc_dev *solo_enc = fh->enc;
1260 int ret;
1261
1262 /* Make sure the encoder is on */
1263 if (!fh->enc_on) {
1264 spin_lock(&solo_enc->lock);
1265 ret = solo_enc_on(fh);
1266 spin_unlock(&solo_enc->lock);
1267 if (ret)
1268 return ret;
1269
1270 ret = solo_start_fh_thread(fh);
1271 if (ret)
1272 return ret;
1273 }
1274
1275 ret = videobuf_dqbuf(&fh->vidq, buf, file->f_flags & O_NONBLOCK);
1276 if (ret)
1277 return ret;
1278
1279 /* Signal motion detection */
1280 if (solo_is_motion_on(solo_enc)) {
1281 buf->flags |= V4L2_BUF_FLAG_MOTION_ON;
1282 if (solo_enc->motion_detected) {
1283 buf->flags |= V4L2_BUF_FLAG_MOTION_DETECTED;
1284 solo_reg_write(solo_enc->solo_dev, SOLO_VI_MOT_CLEAR,
1285 1 << solo_enc->ch);
1286 solo_enc->motion_detected = 0;
1287 }
1288 }
1289
1290 /* Check for key frame on mpeg data */
1291 if (fh->fmt == V4L2_PIX_FMT_MPEG) {
1292 struct videobuf_dmabuf *vbuf =
1293 videobuf_to_dma(fh->vidq.bufs[buf->index]);
1294
1295 if (vbuf) {
1296 u8 *p = sg_virt(vbuf->sglist);
1297 if (p[3] == 0x00)
1298 buf->flags |= V4L2_BUF_FLAG_KEYFRAME;
1299 else
1300 buf->flags |= V4L2_BUF_FLAG_PFRAME;
1301 }
1302 }
1303
1304 return 0;
1305}
1306
1307static int solo_enc_streamon(struct file *file, void *priv,
1308 enum v4l2_buf_type i)
1309{
1310 struct solo_enc_fh *fh = priv;
1311
1312 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1313 return -EINVAL;
1314
1315 return videobuf_streamon(&fh->vidq);
1316}
1317
1318static int solo_enc_streamoff(struct file *file, void *priv,
1319 enum v4l2_buf_type i)
1320{
1321 struct solo_enc_fh *fh = priv;
1322
1323 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1324 return -EINVAL;
1325
1326 return videobuf_streamoff(&fh->vidq);
1327}
1328
1329static int solo_enc_s_std(struct file *file, void *priv, v4l2_std_id *i)
1330{
1331 return 0;
1332}
1333
1334static int solo_enum_framesizes(struct file *file, void *priv,
1335 struct v4l2_frmsizeenum *fsize)
1336{
1337 struct solo_enc_fh *fh = priv;
1338 struct solo_dev *solo_dev = fh->enc->solo_dev;
1339
1340 if (fsize->pixel_format != V4L2_PIX_FMT_MPEG)
1341 return -EINVAL;
1342
1343 switch (fsize->index) {
1344 case 0:
1345 fsize->discrete.width = solo_dev->video_hsize >> 1;
1346 fsize->discrete.height = solo_dev->video_vsize;
1347 break;
1348 case 1:
1349 fsize->discrete.width = solo_dev->video_hsize;
1350 fsize->discrete.height = solo_dev->video_vsize << 1;
1351 break;
1352 default:
1353 return -EINVAL;
1354 }
1355
1356 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1357
1358 return 0;
1359}
1360
1361static int solo_enum_frameintervals(struct file *file, void *priv,
1362 struct v4l2_frmivalenum *fintv)
1363{
1364 struct solo_enc_fh *fh = priv;
1365 struct solo_dev *solo_dev = fh->enc->solo_dev;
1366
1367 if (fintv->pixel_format != V4L2_PIX_FMT_MPEG || fintv->index)
1368 return -EINVAL;
1369
1370 fintv->type = V4L2_FRMIVAL_TYPE_STEPWISE;
1371
1372 fintv->stepwise.min.numerator = solo_dev->fps;
1373 fintv->stepwise.min.denominator = 1;
1374
1375 fintv->stepwise.max.numerator = solo_dev->fps;
1376 fintv->stepwise.max.denominator = 15;
1377
1378 fintv->stepwise.step.numerator = 1;
1379 fintv->stepwise.step.denominator = 1;
1380
1381 return 0;
1382}
1383
1384static int solo_g_parm(struct file *file, void *priv,
1385 struct v4l2_streamparm *sp)
1386{
1387 struct solo_enc_fh *fh = priv;
1388 struct solo_enc_dev *solo_enc = fh->enc;
1389 struct solo_dev *solo_dev = solo_enc->solo_dev;
1390 struct v4l2_captureparm *cp = &sp->parm.capture;
1391
1392 cp->capability = V4L2_CAP_TIMEPERFRAME;
1393 cp->timeperframe.numerator = solo_enc->interval;
1394 cp->timeperframe.denominator = solo_dev->fps;
1395 cp->capturemode = 0;
1396 /* XXX: Shouldn't we be able to get/set this from videobuf? */
1397 cp->readbuffers = 2;
1398
1399 return 0;
1400}
1401
1402static int solo_s_parm(struct file *file, void *priv,
1403 struct v4l2_streamparm *sp)
1404{
1405 struct solo_enc_fh *fh = priv;
1406 struct solo_enc_dev *solo_enc = fh->enc;
1407 struct solo_dev *solo_dev = solo_enc->solo_dev;
1408 struct v4l2_captureparm *cp = &sp->parm.capture;
1409
1410 spin_lock(&solo_enc->lock);
1411
1412 if (atomic_read(&solo_enc->readers) > 0) {
1413 spin_unlock(&solo_enc->lock);
1414 return -EBUSY;
1415 }
1416
1417 if ((cp->timeperframe.numerator == 0) ||
1418 (cp->timeperframe.denominator == 0)) {
1419 /* reset framerate */
1420 cp->timeperframe.numerator = 1;
1421 cp->timeperframe.denominator = solo_dev->fps;
1422 }
1423
1424 if (cp->timeperframe.denominator != solo_dev->fps)
1425 cp->timeperframe.denominator = solo_dev->fps;
1426
1427 if (cp->timeperframe.numerator > 15)
1428 cp->timeperframe.numerator = 15;
1429
1430 solo_enc->interval = cp->timeperframe.numerator;
1431
1432 cp->capability = V4L2_CAP_TIMEPERFRAME;
1433
1434 solo_enc->gop = max(solo_dev->fps / solo_enc->interval, 1);
1435 solo_update_mode(solo_enc);
1436
1437 spin_unlock(&solo_enc->lock);
1438
1439 return 0;
1440}
1441
1442static int solo_queryctrl(struct file *file, void *priv,
1443 struct v4l2_queryctrl *qc)
1444{
1445 struct solo_enc_fh *fh = priv;
1446 struct solo_enc_dev *solo_enc = fh->enc;
1447 struct solo_dev *solo_dev = solo_enc->solo_dev;
1448
1449 qc->id = v4l2_ctrl_next(solo_ctrl_classes, qc->id);
1450 if (!qc->id)
1451 return -EINVAL;
1452
1453 switch (qc->id) {
1454 case V4L2_CID_BRIGHTNESS:
1455 case V4L2_CID_CONTRAST:
1456 case V4L2_CID_SATURATION:
1457 case V4L2_CID_HUE:
1458 return v4l2_ctrl_query_fill(qc, 0x00, 0xff, 1, 0x80);
1459 case V4L2_CID_SHARPNESS:
1460 return v4l2_ctrl_query_fill(qc, 0x00, 0x0f, 1, 0x00);
1461 case V4L2_CID_MPEG_VIDEO_ENCODING:
1462 return v4l2_ctrl_query_fill(
1463 qc, V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
1464 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
1465 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
1466 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1467 return v4l2_ctrl_query_fill(qc, 1, 255, 1, solo_dev->fps);
1468#ifdef PRIVATE_CIDS
1469 case V4L2_CID_MOTION_THRESHOLD:
1470 qc->flags |= V4L2_CTRL_FLAG_SLIDER;
1471 qc->type = V4L2_CTRL_TYPE_INTEGER;
1472 qc->minimum = 0;
1473 qc->maximum = 0xffff;
1474 qc->step = 1;
1475 qc->default_value = SOLO_DEF_MOT_THRESH;
1476 strlcpy(qc->name, "Motion Detection Threshold",
1477 sizeof(qc->name));
1478 return 0;
1479 case V4L2_CID_MOTION_ENABLE:
1480 qc->type = V4L2_CTRL_TYPE_BOOLEAN;
1481 qc->minimum = 0;
1482 qc->maximum = qc->step = 1;
1483 qc->default_value = 0;
1484 strlcpy(qc->name, "Motion Detection Enable", sizeof(qc->name));
1485 return 0;
1486#else
1487 case V4L2_CID_MOTION_THRESHOLD:
1488 return v4l2_ctrl_query_fill(qc, 0, 0xffff, 1,
1489 SOLO_DEF_MOT_THRESH);
1490 case V4L2_CID_MOTION_ENABLE:
1491 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1492#endif
1493 case V4L2_CID_RDS_TX_RADIO_TEXT:
1494 qc->type = V4L2_CTRL_TYPE_STRING;
1495 qc->minimum = 0;
1496 qc->maximum = OSD_TEXT_MAX;
1497 qc->step = 1;
1498 qc->default_value = 0;
1499 strlcpy(qc->name, "OSD Text", sizeof(qc->name));
1500 return 0;
1501 }
1502
1503 return -EINVAL;
1504}
1505
1506static int solo_querymenu(struct file *file, void *priv,
1507 struct v4l2_querymenu *qmenu)
1508{
1509 struct v4l2_queryctrl qctrl;
1510 int err;
1511
1512 qctrl.id = qmenu->id;
1513 err = solo_queryctrl(file, priv, &qctrl);
1514 if (err)
1515 return err;
1516
1517 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
1518}
1519
1520static int solo_g_ctrl(struct file *file, void *priv,
1521 struct v4l2_control *ctrl)
1522{
1523 struct solo_enc_fh *fh = priv;
1524 struct solo_enc_dev *solo_enc = fh->enc;
1525 struct solo_dev *solo_dev = solo_enc->solo_dev;
1526
1527 switch (ctrl->id) {
1528 case V4L2_CID_BRIGHTNESS:
1529 case V4L2_CID_CONTRAST:
1530 case V4L2_CID_SATURATION:
1531 case V4L2_CID_HUE:
1532 case V4L2_CID_SHARPNESS:
1533 return tw28_get_ctrl_val(solo_dev, ctrl->id, solo_enc->ch,
1534 &ctrl->value);
1535 case V4L2_CID_MPEG_VIDEO_ENCODING:
1536 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC;
1537 break;
1538 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1539 ctrl->value = solo_enc->gop;
1540 break;
1541 case V4L2_CID_MOTION_THRESHOLD:
1542 ctrl->value = solo_enc->motion_thresh;
1543 break;
1544 case V4L2_CID_MOTION_ENABLE:
1545 ctrl->value = solo_is_motion_on(solo_enc);
1546 break;
1547 default:
1548 return -EINVAL;
1549 }
1550
1551 return 0;
1552}
1553
1554static int solo_s_ctrl(struct file *file, void *priv,
1555 struct v4l2_control *ctrl)
1556{
1557 struct solo_enc_fh *fh = priv;
1558 struct solo_enc_dev *solo_enc = fh->enc;
1559 struct solo_dev *solo_dev = solo_enc->solo_dev;
1560
1561 switch (ctrl->id) {
1562 case V4L2_CID_BRIGHTNESS:
1563 case V4L2_CID_CONTRAST:
1564 case V4L2_CID_SATURATION:
1565 case V4L2_CID_HUE:
1566 case V4L2_CID_SHARPNESS:
1567 return tw28_set_ctrl_val(solo_dev, ctrl->id, solo_enc->ch,
1568 ctrl->value);
1569 case V4L2_CID_MPEG_VIDEO_ENCODING:
1570 if (ctrl->value != V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC)
1571 return -ERANGE;
1572 break;
1573 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1574 if (ctrl->value < 1 || ctrl->value > 255)
1575 return -ERANGE;
1576 solo_enc->gop = ctrl->value;
1577 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(solo_enc->ch),
1578 solo_enc->gop);
1579 solo_reg_write(solo_dev, SOLO_VE_CH_GOP_E(solo_enc->ch),
1580 solo_enc->gop);
1581 break;
1582 case V4L2_CID_MOTION_THRESHOLD:
1583 /* TODO accept value on lower 16-bits and use high
1584 * 16-bits to assign the value to a specific block */
1585 if (ctrl->value < 0 || ctrl->value > 0xffff)
1586 return -ERANGE;
1587 solo_enc->motion_thresh = ctrl->value;
1588 solo_set_motion_threshold(solo_dev, solo_enc->ch, ctrl->value);
1589 break;
1590 case V4L2_CID_MOTION_ENABLE:
1591 solo_motion_toggle(solo_enc, ctrl->value);
1592 break;
1593 default:
1594 return -EINVAL;
1595 }
1596
1597 return 0;
1598}
1599
1600static int solo_s_ext_ctrls(struct file *file, void *priv,
1601 struct v4l2_ext_controls *ctrls)
1602{
1603 struct solo_enc_fh *fh = priv;
1604 struct solo_enc_dev *solo_enc = fh->enc;
1605 int i;
1606
1607 for (i = 0; i < ctrls->count; i++) {
1608 struct v4l2_ext_control *ctrl = (ctrls->controls + i);
1609 int err;
1610
1611 switch (ctrl->id) {
1612 case V4L2_CID_RDS_TX_RADIO_TEXT:
1613 if (ctrl->size - 1 > OSD_TEXT_MAX)
1614 err = -ERANGE;
1615 else {
1616 err = copy_from_user(solo_enc->osd_text,
1617 ctrl->string,
1618 OSD_TEXT_MAX);
1619 solo_enc->osd_text[OSD_TEXT_MAX] = '\0';
1620 if (!err)
1621 err = solo_osd_print(solo_enc);
1622 else
1623 err = -EFAULT;
1624 }
1625 break;
1626 default:
1627 err = -EINVAL;
1628 }
1629
1630 if (err < 0) {
1631 ctrls->error_idx = i;
1632 return err;
1633 }
1634 }
1635
1636 return 0;
1637}
1638
1639static int solo_g_ext_ctrls(struct file *file, void *priv,
1640 struct v4l2_ext_controls *ctrls)
1641{
1642 struct solo_enc_fh *fh = priv;
1643 struct solo_enc_dev *solo_enc = fh->enc;
1644 int i;
1645
1646 for (i = 0; i < ctrls->count; i++) {
1647 struct v4l2_ext_control *ctrl = (ctrls->controls + i);
1648 int err;
1649
1650 switch (ctrl->id) {
1651 case V4L2_CID_RDS_TX_RADIO_TEXT:
1652 if (ctrl->size < OSD_TEXT_MAX) {
1653 ctrl->size = OSD_TEXT_MAX;
1654 err = -ENOSPC;
1655 } else {
1656 err = copy_to_user(ctrl->string,
1657 solo_enc->osd_text,
1658 OSD_TEXT_MAX);
1659 if (err)
1660 err = -EFAULT;
1661 }
1662 break;
1663 default:
1664 err = -EINVAL;
1665 }
1666
1667 if (err < 0) {
1668 ctrls->error_idx = i;
1669 return err;
1670 }
1671 }
1672
1673 return 0;
1674}
1675
1676static const struct v4l2_file_operations solo_enc_fops = {
1677 .owner = THIS_MODULE,
1678 .open = solo_enc_open,
1679 .release = solo_enc_release,
1680 .read = solo_enc_read,
1681 .poll = solo_enc_poll,
1682 .mmap = solo_enc_mmap,
1683 .ioctl = video_ioctl2,
1684};
1685
1686static const struct v4l2_ioctl_ops solo_enc_ioctl_ops = {
1687 .vidioc_querycap = solo_enc_querycap,
1688 .vidioc_s_std = solo_enc_s_std,
1689 /* Input callbacks */
1690 .vidioc_enum_input = solo_enc_enum_input,
1691 .vidioc_s_input = solo_enc_set_input,
1692 .vidioc_g_input = solo_enc_get_input,
1693 /* Video capture format callbacks */
1694 .vidioc_enum_fmt_vid_cap = solo_enc_enum_fmt_cap,
1695 .vidioc_try_fmt_vid_cap = solo_enc_try_fmt_cap,
1696 .vidioc_s_fmt_vid_cap = solo_enc_set_fmt_cap,
1697 .vidioc_g_fmt_vid_cap = solo_enc_get_fmt_cap,
1698 /* Streaming I/O */
1699 .vidioc_reqbufs = solo_enc_reqbufs,
1700 .vidioc_querybuf = solo_enc_querybuf,
1701 .vidioc_qbuf = solo_enc_qbuf,
1702 .vidioc_dqbuf = solo_enc_dqbuf,
1703 .vidioc_streamon = solo_enc_streamon,
1704 .vidioc_streamoff = solo_enc_streamoff,
1705 /* Frame size and interval */
1706 .vidioc_enum_framesizes = solo_enum_framesizes,
1707 .vidioc_enum_frameintervals = solo_enum_frameintervals,
1708 /* Video capture parameters */
1709 .vidioc_s_parm = solo_s_parm,
1710 .vidioc_g_parm = solo_g_parm,
1711 /* Controls */
1712 .vidioc_queryctrl = solo_queryctrl,
1713 .vidioc_querymenu = solo_querymenu,
1714 .vidioc_g_ctrl = solo_g_ctrl,
1715 .vidioc_s_ctrl = solo_s_ctrl,
1716 .vidioc_g_ext_ctrls = solo_g_ext_ctrls,
1717 .vidioc_s_ext_ctrls = solo_s_ext_ctrls,
1718};
1719
1720static struct video_device solo_enc_template = {
1721 .name = SOLO6X10_NAME,
1722 .fops = &solo_enc_fops,
1723 .ioctl_ops = &solo_enc_ioctl_ops,
1724 .minor = -1,
1725 .release = video_device_release,
1726
1727 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_B,
1728 .current_norm = V4L2_STD_NTSC_M,
1729};
1730
1731static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev, u8 ch)
1732{
1733 struct solo_enc_dev *solo_enc;
1734 int ret;
1735
1736 solo_enc = kzalloc(sizeof(*solo_enc), GFP_KERNEL);
1737 if (!solo_enc)
1738 return ERR_PTR(-ENOMEM);
1739
1740 solo_enc->vfd = video_device_alloc();
1741 if (!solo_enc->vfd) {
1742 kfree(solo_enc);
1743 return ERR_PTR(-ENOMEM);
1744 }
1745
1746 solo_enc->solo_dev = solo_dev;
1747 solo_enc->ch = ch;
1748
1749 *solo_enc->vfd = solo_enc_template;
1750 solo_enc->vfd->parent = &solo_dev->pdev->dev;
1751 ret = video_register_device(solo_enc->vfd, VFL_TYPE_GRABBER,
1752 video_nr);
1753 if (ret < 0) {
1754 video_device_release(solo_enc->vfd);
1755 kfree(solo_enc);
1756 return ERR_PTR(ret);
1757 }
1758
1759 video_set_drvdata(solo_enc->vfd, solo_enc);
1760
1761 snprintf(solo_enc->vfd->name, sizeof(solo_enc->vfd->name),
1762 "%s-enc (%i/%i)", SOLO6X10_NAME, solo_dev->vfd->num,
1763 solo_enc->vfd->num);
1764
1765 if (video_nr != -1)
1766 video_nr++;
1767
1768 spin_lock_init(&solo_enc->lock);
1769 init_waitqueue_head(&solo_enc->thread_wait);
1770 atomic_set(&solo_enc->readers, 0);
1771
1772 solo_enc->qp = SOLO_DEFAULT_QP;
1773 solo_enc->gop = solo_dev->fps;
1774 solo_enc->interval = 1;
1775 solo_enc->mode = SOLO_ENC_MODE_CIF;
1776 solo_enc->motion_thresh = SOLO_DEF_MOT_THRESH;
1777
1778 spin_lock(&solo_enc->lock);
1779 solo_update_mode(solo_enc);
1780 spin_unlock(&solo_enc->lock);
1781
1782 return solo_enc;
1783}
1784
1785static void solo_enc_free(struct solo_enc_dev *solo_enc)
1786{
1787 if (solo_enc == NULL)
1788 return;
1789
1790 video_unregister_device(solo_enc->vfd);
1791 kfree(solo_enc);
1792}
1793
1794int solo_enc_v4l2_init(struct solo_dev *solo_dev)
1795{
1796 int i;
1797
1798 for (i = 0; i < solo_dev->nr_chans; i++) {
1799 solo_dev->v4l2_enc[i] = solo_enc_alloc(solo_dev, i);
1800 if (IS_ERR(solo_dev->v4l2_enc[i]))
1801 break;
1802 }
1803
1804 if (i != solo_dev->nr_chans) {
1805 int ret = PTR_ERR(solo_dev->v4l2_enc[i]);
1806 while (i--)
1807 solo_enc_free(solo_dev->v4l2_enc[i]);
1808 return ret;
1809 }
1810
1811 /* D1@MAX-FPS * 4 */
1812 solo_dev->enc_bw_remain = solo_dev->fps * 4 * 4;
1813
1814 dev_info(&solo_dev->pdev->dev, "Encoders as /dev/video%d-%d\n",
1815 solo_dev->v4l2_enc[0]->vfd->num,
1816 solo_dev->v4l2_enc[solo_dev->nr_chans - 1]->vfd->num);
1817
1818 return 0;
1819}
1820
1821void solo_enc_v4l2_exit(struct solo_dev *solo_dev)
1822{
1823 int i;
1824
1825 solo_irq_off(solo_dev, SOLO_IRQ_MOTION);
1826
1827 for (i = 0; i < solo_dev->nr_chans; i++)
1828 solo_enc_free(solo_dev->v4l2_enc[i]);
1829}
diff --git a/drivers/staging/media/solo6x10/v4l2.c b/drivers/staging/media/solo6x10/v4l2.c
deleted file mode 100644
index ca774cc57539..000000000000
--- a/drivers/staging/media/solo6x10/v4l2.c
+++ /dev/null
@@ -1,961 +0,0 @@
1/*
2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/kthread.h>
23#include <linux/freezer.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-common.h>
26#include <media/videobuf-dma-sg.h>
27#include "solo6x10.h"
28#include "tw28.h"
29
30#define SOLO_HW_BPL 2048
31#define SOLO_DISP_PIX_FIELD V4L2_FIELD_INTERLACED
32
33/* Image size is two fields, SOLO_HW_BPL is one horizontal line */
34#define solo_vlines(__solo) (__solo->video_vsize * 2)
35#define solo_image_size(__solo) (solo_bytesperline(__solo) * \
36 solo_vlines(__solo))
37#define solo_bytesperline(__solo) (__solo->video_hsize * 2)
38
39#define MIN_VID_BUFFERS 4
40
41/* Simple file handle */
42struct solo_filehandle {
43 struct solo_dev *solo_dev;
44 struct videobuf_queue vidq;
45 struct task_struct *kthread;
46 spinlock_t slock;
47 int old_write;
48 struct list_head vidq_active;
49 struct p2m_desc desc[SOLO_NR_P2M_DESC];
50 int desc_idx;
51};
52
53unsigned video_nr = -1;
54module_param(video_nr, uint, 0644);
55MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect (default)");
56
57static void erase_on(struct solo_dev *solo_dev)
58{
59 solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, SOLO_VO_DISP_ERASE_ON);
60 solo_dev->erasing = 1;
61 solo_dev->frame_blank = 0;
62}
63
64static int erase_off(struct solo_dev *solo_dev)
65{
66 if (!solo_dev->erasing)
67 return 0;
68
69 /* First time around, assert erase off */
70 if (!solo_dev->frame_blank)
71 solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, 0);
72 /* Keep the erasing flag on for 8 frames minimum */
73 if (solo_dev->frame_blank++ >= 8)
74 solo_dev->erasing = 0;
75
76 return 1;
77}
78
79void solo_video_in_isr(struct solo_dev *solo_dev)
80{
81 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_VIDEO_IN);
82 wake_up_interruptible(&solo_dev->disp_thread_wait);
83}
84
85static void solo_win_setup(struct solo_dev *solo_dev, u8 ch,
86 int sx, int sy, int ex, int ey, int scale)
87{
88 if (ch >= solo_dev->nr_chans)
89 return;
90
91 /* Here, we just keep window/channel the same */
92 solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL0(ch),
93 SOLO_VI_WIN_CHANNEL(ch) |
94 SOLO_VI_WIN_SX(sx) |
95 SOLO_VI_WIN_EX(ex) |
96 SOLO_VI_WIN_SCALE(scale));
97
98 solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL1(ch),
99 SOLO_VI_WIN_SY(sy) |
100 SOLO_VI_WIN_EY(ey));
101}
102
103static int solo_v4l2_ch_ext_4up(struct solo_dev *solo_dev, u8 idx, int on)
104{
105 u8 ch = idx * 4;
106
107 if (ch >= solo_dev->nr_chans)
108 return -EINVAL;
109
110 if (!on) {
111 u8 i;
112 for (i = ch; i < ch + 4; i++)
113 solo_win_setup(solo_dev, i, solo_dev->video_hsize,
114 solo_vlines(solo_dev),
115 solo_dev->video_hsize,
116 solo_vlines(solo_dev), 0);
117 return 0;
118 }
119
120 /* Row 1 */
121 solo_win_setup(solo_dev, ch, 0, 0, solo_dev->video_hsize / 2,
122 solo_vlines(solo_dev) / 2, 3);
123 solo_win_setup(solo_dev, ch + 1, solo_dev->video_hsize / 2, 0,
124 solo_dev->video_hsize, solo_vlines(solo_dev) / 2, 3);
125 /* Row 2 */
126 solo_win_setup(solo_dev, ch + 2, 0, solo_vlines(solo_dev) / 2,
127 solo_dev->video_hsize / 2, solo_vlines(solo_dev), 3);
128 solo_win_setup(solo_dev, ch + 3, solo_dev->video_hsize / 2,
129 solo_vlines(solo_dev) / 2, solo_dev->video_hsize,
130 solo_vlines(solo_dev), 3);
131
132 return 0;
133}
134
135static int solo_v4l2_ch_ext_16up(struct solo_dev *solo_dev, int on)
136{
137 int sy, ysize, hsize, i;
138
139 if (!on) {
140 for (i = 0; i < 16; i++)
141 solo_win_setup(solo_dev, i, solo_dev->video_hsize,
142 solo_vlines(solo_dev),
143 solo_dev->video_hsize,
144 solo_vlines(solo_dev), 0);
145 return 0;
146 }
147
148 ysize = solo_vlines(solo_dev) / 4;
149 hsize = solo_dev->video_hsize / 4;
150
151 for (sy = 0, i = 0; i < 4; i++, sy += ysize) {
152 solo_win_setup(solo_dev, i * 4, 0, sy, hsize,
153 sy + ysize, 5);
154 solo_win_setup(solo_dev, (i * 4) + 1, hsize, sy,
155 hsize * 2, sy + ysize, 5);
156 solo_win_setup(solo_dev, (i * 4) + 2, hsize * 2, sy,
157 hsize * 3, sy + ysize, 5);
158 solo_win_setup(solo_dev, (i * 4) + 3, hsize * 3, sy,
159 solo_dev->video_hsize, sy + ysize, 5);
160 }
161
162 return 0;
163}
164
165static int solo_v4l2_ch(struct solo_dev *solo_dev, u8 ch, int on)
166{
167 u8 ext_ch;
168
169 if (ch < solo_dev->nr_chans) {
170 solo_win_setup(solo_dev, ch, on ? 0 : solo_dev->video_hsize,
171 on ? 0 : solo_vlines(solo_dev),
172 solo_dev->video_hsize, solo_vlines(solo_dev),
173 on ? 1 : 0);
174 return 0;
175 }
176
177 if (ch >= solo_dev->nr_chans + solo_dev->nr_ext)
178 return -EINVAL;
179
180 ext_ch = ch - solo_dev->nr_chans;
181
182 /* 4up's first */
183 if (ext_ch < 4)
184 return solo_v4l2_ch_ext_4up(solo_dev, ext_ch, on);
185
186 /* Remaining case is 16up for 16-port */
187 return solo_v4l2_ch_ext_16up(solo_dev, on);
188}
189
190static int solo_v4l2_set_ch(struct solo_dev *solo_dev, u8 ch)
191{
192 if (ch >= solo_dev->nr_chans + solo_dev->nr_ext)
193 return -EINVAL;
194
195 erase_on(solo_dev);
196
197 solo_v4l2_ch(solo_dev, solo_dev->cur_disp_ch, 0);
198 solo_v4l2_ch(solo_dev, ch, 1);
199
200 solo_dev->cur_disp_ch = ch;
201
202 return 0;
203}
204
205static void disp_reset_desc(struct solo_filehandle *fh)
206{
207 /* We use desc mode, which ignores desc 0 */
208 memset(fh->desc, 0, sizeof(*fh->desc));
209 fh->desc_idx = 1;
210}
211
212static int disp_flush_descs(struct solo_filehandle *fh)
213{
214 int ret;
215
216 if (!fh->desc_idx)
217 return 0;
218
219 ret = solo_p2m_dma_desc(fh->solo_dev, SOLO_P2M_DMA_ID_DISP,
220 fh->desc, fh->desc_idx);
221 disp_reset_desc(fh);
222
223 return ret;
224}
225
226static int disp_push_desc(struct solo_filehandle *fh, dma_addr_t dma_addr,
227 u32 ext_addr, int size, int repeat, int ext_size)
228{
229 if (fh->desc_idx >= SOLO_NR_P2M_DESC) {
230 int ret = disp_flush_descs(fh);
231 if (ret)
232 return ret;
233 }
234
235 solo_p2m_push_desc(&fh->desc[fh->desc_idx], 0, dma_addr, ext_addr,
236 size, repeat, ext_size);
237 fh->desc_idx++;
238
239 return 0;
240}
241
242static void solo_fillbuf(struct solo_filehandle *fh,
243 struct videobuf_buffer *vb)
244{
245 struct solo_dev *solo_dev = fh->solo_dev;
246 struct videobuf_dmabuf *vbuf;
247 unsigned int fdma_addr;
248 int error = 1;
249 int i;
250 struct scatterlist *sg;
251 dma_addr_t sg_dma;
252 int sg_size_left;
253
254 vbuf = videobuf_to_dma(vb);
255 if (!vbuf)
256 goto finish_buf;
257
258 if (erase_off(solo_dev)) {
259 int i;
260
261 /* Just blit to the entire sg list, ignoring size */
262 for_each_sg(vbuf->sglist, sg, vbuf->sglen, i) {
263 void *p = sg_virt(sg);
264 size_t len = sg_dma_len(sg);
265
266 for (i = 0; i < len; i += 2) {
267 ((u8 *)p)[i] = 0x80;
268 ((u8 *)p)[i + 1] = 0x00;
269 }
270 }
271
272 error = 0;
273 goto finish_buf;
274 }
275
276 disp_reset_desc(fh);
277 sg = vbuf->sglist;
278 sg_dma = sg_dma_address(sg);
279 sg_size_left = sg_dma_len(sg);
280
281 fdma_addr = SOLO_DISP_EXT_ADDR + (fh->old_write *
282 (SOLO_HW_BPL * solo_vlines(solo_dev)));
283
284 for (i = 0; i < solo_vlines(solo_dev); i++) {
285 int line_len = solo_bytesperline(solo_dev);
286 int lines;
287
288 if (!sg_size_left) {
289 sg = sg_next(sg);
290 if (sg == NULL)
291 goto finish_buf;
292 sg_dma = sg_dma_address(sg);
293 sg_size_left = sg_dma_len(sg);
294 }
295
296 /* No room for an entire line, so chunk it up */
297 if (sg_size_left < line_len) {
298 int this_addr = fdma_addr;
299
300 while (line_len > 0) {
301 int this_write;
302
303 if (!sg_size_left) {
304 sg = sg_next(sg);
305 if (sg == NULL)
306 goto finish_buf;
307 sg_dma = sg_dma_address(sg);
308 sg_size_left = sg_dma_len(sg);
309 }
310
311 this_write = min(sg_size_left, line_len);
312
313 if (disp_push_desc(fh, sg_dma, this_addr,
314 this_write, 0, 0))
315 goto finish_buf;
316
317 line_len -= this_write;
318 sg_size_left -= this_write;
319 sg_dma += this_write;
320 this_addr += this_write;
321 }
322
323 fdma_addr += SOLO_HW_BPL;
324 continue;
325 }
326
327 /* Shove as many lines into a repeating descriptor as possible */
328 lines = min(sg_size_left / line_len,
329 solo_vlines(solo_dev) - i);
330
331 if (disp_push_desc(fh, sg_dma, fdma_addr, line_len,
332 lines - 1, SOLO_HW_BPL))
333 goto finish_buf;
334
335 i += lines - 1;
336 fdma_addr += SOLO_HW_BPL * lines;
337 sg_dma += lines * line_len;
338 sg_size_left -= lines * line_len;
339 }
340
341 error = disp_flush_descs(fh);
342
343finish_buf:
344 if (error) {
345 vb->state = VIDEOBUF_ERROR;
346 } else {
347 vb->size = solo_vlines(solo_dev) * solo_bytesperline(solo_dev);
348 vb->state = VIDEOBUF_DONE;
349 vb->field_count++;
350 do_gettimeofday(&vb->ts);
351 }
352
353 wake_up(&vb->done);
354
355 return;
356}
357
358static void solo_thread_try(struct solo_filehandle *fh)
359{
360 struct videobuf_buffer *vb;
361 unsigned int cur_write;
362
363 for (;;) {
364 spin_lock(&fh->slock);
365
366 if (list_empty(&fh->vidq_active))
367 break;
368
369 vb = list_first_entry(&fh->vidq_active, struct videobuf_buffer,
370 queue);
371
372 if (!waitqueue_active(&vb->done))
373 break;
374
375 cur_write = SOLO_VI_STATUS0_PAGE(solo_reg_read(fh->solo_dev,
376 SOLO_VI_STATUS0));
377 if (cur_write == fh->old_write)
378 break;
379
380 fh->old_write = cur_write;
381 list_del(&vb->queue);
382
383 spin_unlock(&fh->slock);
384
385 solo_fillbuf(fh, vb);
386 }
387
388 assert_spin_locked(&fh->slock);
389 spin_unlock(&fh->slock);
390}
391
392static int solo_thread(void *data)
393{
394 struct solo_filehandle *fh = data;
395 struct solo_dev *solo_dev = fh->solo_dev;
396 DECLARE_WAITQUEUE(wait, current);
397
398 set_freezable();
399 add_wait_queue(&solo_dev->disp_thread_wait, &wait);
400
401 for (;;) {
402 long timeout = schedule_timeout_interruptible(HZ);
403 if (timeout == -ERESTARTSYS || kthread_should_stop())
404 break;
405 solo_thread_try(fh);
406 try_to_freeze();
407 }
408
409 remove_wait_queue(&solo_dev->disp_thread_wait, &wait);
410
411 return 0;
412}
413
414static int solo_start_thread(struct solo_filehandle *fh)
415{
416 fh->kthread = kthread_run(solo_thread, fh, SOLO6X10_NAME "_disp");
417
418 return PTR_RET(fh->kthread);
419}
420
421static void solo_stop_thread(struct solo_filehandle *fh)
422{
423 if (fh->kthread) {
424 kthread_stop(fh->kthread);
425 fh->kthread = NULL;
426 }
427}
428
429static int solo_buf_setup(struct videobuf_queue *vq, unsigned int *count,
430 unsigned int *size)
431{
432 struct solo_filehandle *fh = vq->priv_data;
433 struct solo_dev *solo_dev = fh->solo_dev;
434
435 *size = solo_image_size(solo_dev);
436
437 if (*count < MIN_VID_BUFFERS)
438 *count = MIN_VID_BUFFERS;
439
440 return 0;
441}
442
443static int solo_buf_prepare(struct videobuf_queue *vq,
444 struct videobuf_buffer *vb, enum v4l2_field field)
445{
446 struct solo_filehandle *fh = vq->priv_data;
447 struct solo_dev *solo_dev = fh->solo_dev;
448
449 vb->size = solo_image_size(solo_dev);
450 if (vb->baddr != 0 && vb->bsize < vb->size)
451 return -EINVAL;
452
453 /* XXX: These properties only change when queue is idle */
454 vb->width = solo_dev->video_hsize;
455 vb->height = solo_vlines(solo_dev);
456 vb->bytesperline = solo_bytesperline(solo_dev);
457 vb->field = field;
458
459 if (vb->state == VIDEOBUF_NEEDS_INIT) {
460 int rc = videobuf_iolock(vq, vb, NULL);
461 if (rc < 0) {
462 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
463 videobuf_dma_unmap(vq->dev, dma);
464 videobuf_dma_free(dma);
465 vb->state = VIDEOBUF_NEEDS_INIT;
466 return rc;
467 }
468 }
469 vb->state = VIDEOBUF_PREPARED;
470
471 return 0;
472}
473
474static void solo_buf_queue(struct videobuf_queue *vq,
475 struct videobuf_buffer *vb)
476{
477 struct solo_filehandle *fh = vq->priv_data;
478 struct solo_dev *solo_dev = fh->solo_dev;
479
480 vb->state = VIDEOBUF_QUEUED;
481 list_add_tail(&vb->queue, &fh->vidq_active);
482 wake_up_interruptible(&solo_dev->disp_thread_wait);
483}
484
485static void solo_buf_release(struct videobuf_queue *vq,
486 struct videobuf_buffer *vb)
487{
488 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
489
490 videobuf_dma_unmap(vq->dev, dma);
491 videobuf_dma_free(dma);
492 vb->state = VIDEOBUF_NEEDS_INIT;
493}
494
495static struct videobuf_queue_ops solo_video_qops = {
496 .buf_setup = solo_buf_setup,
497 .buf_prepare = solo_buf_prepare,
498 .buf_queue = solo_buf_queue,
499 .buf_release = solo_buf_release,
500};
501
502static unsigned int solo_v4l2_poll(struct file *file,
503 struct poll_table_struct *wait)
504{
505 struct solo_filehandle *fh = file->private_data;
506
507 return videobuf_poll_stream(file, &fh->vidq, wait);
508}
509
510static int solo_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
511{
512 struct solo_filehandle *fh = file->private_data;
513
514 return videobuf_mmap_mapper(&fh->vidq, vma);
515}
516
517static int solo_v4l2_open(struct file *file)
518{
519 struct solo_dev *solo_dev = video_drvdata(file);
520 struct solo_filehandle *fh;
521 int ret;
522
523 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
524 if (fh == NULL)
525 return -ENOMEM;
526
527 spin_lock_init(&fh->slock);
528 INIT_LIST_HEAD(&fh->vidq_active);
529 fh->solo_dev = solo_dev;
530 file->private_data = fh;
531
532 ret = solo_start_thread(fh);
533 if (ret) {
534 kfree(fh);
535 return ret;
536 }
537
538 videobuf_queue_sg_init(&fh->vidq, &solo_video_qops,
539 &solo_dev->pdev->dev, &fh->slock,
540 V4L2_BUF_TYPE_VIDEO_CAPTURE,
541 SOLO_DISP_PIX_FIELD,
542 sizeof(struct videobuf_buffer), fh, NULL);
543
544 return 0;
545}
546
547static ssize_t solo_v4l2_read(struct file *file, char __user *data,
548 size_t count, loff_t *ppos)
549{
550 struct solo_filehandle *fh = file->private_data;
551
552 return videobuf_read_stream(&fh->vidq, data, count, ppos, 0,
553 file->f_flags & O_NONBLOCK);
554}
555
556static int solo_v4l2_release(struct file *file)
557{
558 struct solo_filehandle *fh = file->private_data;
559
560 videobuf_stop(&fh->vidq);
561 videobuf_mmap_free(&fh->vidq);
562 solo_stop_thread(fh);
563 kfree(fh);
564
565 return 0;
566}
567
568static int solo_querycap(struct file *file, void *priv,
569 struct v4l2_capability *cap)
570{
571 struct solo_filehandle *fh = priv;
572 struct solo_dev *solo_dev = fh->solo_dev;
573
574 strcpy(cap->driver, SOLO6X10_NAME);
575 strcpy(cap->card, "Softlogic 6x10");
576 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI %s",
577 pci_name(solo_dev->pdev));
578 cap->version = SOLO6X10_VER_NUM;
579 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
580 V4L2_CAP_READWRITE |
581 V4L2_CAP_STREAMING;
582 return 0;
583}
584
585static int solo_enum_ext_input(struct solo_dev *solo_dev,
586 struct v4l2_input *input)
587{
588 static const char *dispnames_1[] = { "4UP" };
589 static const char *dispnames_2[] = { "4UP-1", "4UP-2" };
590 static const char *dispnames_5[] = {
591 "4UP-1", "4UP-2", "4UP-3", "4UP-4", "16UP"
592 };
593 const char **dispnames;
594
595 if (input->index >= (solo_dev->nr_chans + solo_dev->nr_ext))
596 return -EINVAL;
597
598 if (solo_dev->nr_ext == 5)
599 dispnames = dispnames_5;
600 else if (solo_dev->nr_ext == 2)
601 dispnames = dispnames_2;
602 else
603 dispnames = dispnames_1;
604
605 snprintf(input->name, sizeof(input->name), "Multi %s",
606 dispnames[input->index - solo_dev->nr_chans]);
607
608 return 0;
609}
610
611static int solo_enum_input(struct file *file, void *priv,
612 struct v4l2_input *input)
613{
614 struct solo_filehandle *fh = priv;
615 struct solo_dev *solo_dev = fh->solo_dev;
616
617 if (input->index >= solo_dev->nr_chans) {
618 int ret = solo_enum_ext_input(solo_dev, input);
619 if (ret < 0)
620 return ret;
621 } else {
622 snprintf(input->name, sizeof(input->name), "Camera %d",
623 input->index + 1);
624
625 /* We can only check this for normal inputs */
626 if (!tw28_get_video_status(solo_dev, input->index))
627 input->status = V4L2_IN_ST_NO_SIGNAL;
628 }
629
630 input->type = V4L2_INPUT_TYPE_CAMERA;
631
632 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
633 input->std = V4L2_STD_NTSC_M;
634 else
635 input->std = V4L2_STD_PAL_B;
636
637 return 0;
638}
639
640static int solo_set_input(struct file *file, void *priv, unsigned int index)
641{
642 struct solo_filehandle *fh = priv;
643
644 return solo_v4l2_set_ch(fh->solo_dev, index);
645}
646
647static int solo_get_input(struct file *file, void *priv, unsigned int *index)
648{
649 struct solo_filehandle *fh = priv;
650
651 *index = fh->solo_dev->cur_disp_ch;
652
653 return 0;
654}
655
656static int solo_enum_fmt_cap(struct file *file, void *priv,
657 struct v4l2_fmtdesc *f)
658{
659 if (f->index)
660 return -EINVAL;
661
662 f->pixelformat = V4L2_PIX_FMT_UYVY;
663 strlcpy(f->description, "UYUV 4:2:2 Packed", sizeof(f->description));
664
665 return 0;
666}
667
668static int solo_try_fmt_cap(struct file *file, void *priv,
669 struct v4l2_format *f)
670{
671 struct solo_filehandle *fh = priv;
672 struct solo_dev *solo_dev = fh->solo_dev;
673 struct v4l2_pix_format *pix = &f->fmt.pix;
674 int image_size = solo_image_size(solo_dev);
675
676 /* Check supported sizes */
677 if (pix->width != solo_dev->video_hsize)
678 pix->width = solo_dev->video_hsize;
679 if (pix->height != solo_vlines(solo_dev))
680 pix->height = solo_vlines(solo_dev);
681 if (pix->sizeimage != image_size)
682 pix->sizeimage = image_size;
683
684 /* Check formats */
685 if (pix->field == V4L2_FIELD_ANY)
686 pix->field = SOLO_DISP_PIX_FIELD;
687
688 if (pix->pixelformat != V4L2_PIX_FMT_UYVY ||
689 pix->field != SOLO_DISP_PIX_FIELD ||
690 pix->colorspace != V4L2_COLORSPACE_SMPTE170M)
691 return -EINVAL;
692
693 return 0;
694}
695
696static int solo_set_fmt_cap(struct file *file, void *priv,
697 struct v4l2_format *f)
698{
699 struct solo_filehandle *fh = priv;
700
701 if (videobuf_queue_is_busy(&fh->vidq))
702 return -EBUSY;
703
704 /* For right now, if it doesn't match our running config,
705 * then fail */
706 return solo_try_fmt_cap(file, priv, f);
707}
708
709static int solo_get_fmt_cap(struct file *file, void *priv,
710 struct v4l2_format *f)
711{
712 struct solo_filehandle *fh = priv;
713 struct solo_dev *solo_dev = fh->solo_dev;
714 struct v4l2_pix_format *pix = &f->fmt.pix;
715
716 pix->width = solo_dev->video_hsize;
717 pix->height = solo_vlines(solo_dev);
718 pix->pixelformat = V4L2_PIX_FMT_UYVY;
719 pix->field = SOLO_DISP_PIX_FIELD;
720 pix->sizeimage = solo_image_size(solo_dev);
721 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
722 pix->bytesperline = solo_bytesperline(solo_dev);
723
724 return 0;
725}
726
727static int solo_reqbufs(struct file *file, void *priv,
728 struct v4l2_requestbuffers *req)
729{
730 struct solo_filehandle *fh = priv;
731
732 return videobuf_reqbufs(&fh->vidq, req);
733}
734
735static int solo_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf)
736{
737 struct solo_filehandle *fh = priv;
738
739 return videobuf_querybuf(&fh->vidq, buf);
740}
741
742static int solo_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
743{
744 struct solo_filehandle *fh = priv;
745
746 return videobuf_qbuf(&fh->vidq, buf);
747}
748
749static int solo_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
750{
751 struct solo_filehandle *fh = priv;
752
753 return videobuf_dqbuf(&fh->vidq, buf, file->f_flags & O_NONBLOCK);
754}
755
756static int solo_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
757{
758 struct solo_filehandle *fh = priv;
759
760 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
761 return -EINVAL;
762
763 return videobuf_streamon(&fh->vidq);
764}
765
766static int solo_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
767{
768 struct solo_filehandle *fh = priv;
769
770 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
771 return -EINVAL;
772
773 return videobuf_streamoff(&fh->vidq);
774}
775
776static int solo_s_std(struct file *file, void *priv, v4l2_std_id *i)
777{
778 return 0;
779}
780
781static const u32 solo_motion_ctrls[] = {
782 V4L2_CID_MOTION_TRACE,
783 0
784};
785
786static const u32 *solo_ctrl_classes[] = {
787 solo_motion_ctrls,
788 NULL
789};
790
791static int solo_disp_queryctrl(struct file *file, void *priv,
792 struct v4l2_queryctrl *qc)
793{
794 qc->id = v4l2_ctrl_next(solo_ctrl_classes, qc->id);
795 if (!qc->id)
796 return -EINVAL;
797
798 switch (qc->id) {
799#ifdef PRIVATE_CIDS
800 case V4L2_CID_MOTION_TRACE:
801 qc->type = V4L2_CTRL_TYPE_BOOLEAN;
802 qc->minimum = 0;
803 qc->maximum = qc->step = 1;
804 qc->default_value = 0;
805 strlcpy(qc->name, "Motion Detection Trace", sizeof(qc->name));
806 return 0;
807#else
808 case V4L2_CID_MOTION_TRACE:
809 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
810#endif
811 }
812 return -EINVAL;
813}
814
815static int solo_disp_g_ctrl(struct file *file, void *priv,
816 struct v4l2_control *ctrl)
817{
818 struct solo_filehandle *fh = priv;
819 struct solo_dev *solo_dev = fh->solo_dev;
820
821 switch (ctrl->id) {
822 case V4L2_CID_MOTION_TRACE:
823 ctrl->value = solo_reg_read(solo_dev, SOLO_VI_MOTION_BAR)
824 ? 1 : 0;
825 return 0;
826 }
827 return -EINVAL;
828}
829
830static int solo_disp_s_ctrl(struct file *file, void *priv,
831 struct v4l2_control *ctrl)
832{
833 struct solo_filehandle *fh = priv;
834 struct solo_dev *solo_dev = fh->solo_dev;
835
836 switch (ctrl->id) {
837 case V4L2_CID_MOTION_TRACE:
838 if (ctrl->value) {
839 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER,
840 SOLO_VI_MOTION_Y_ADD |
841 SOLO_VI_MOTION_Y_VALUE(0x20) |
842 SOLO_VI_MOTION_CB_VALUE(0x10) |
843 SOLO_VI_MOTION_CR_VALUE(0x10));
844 solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR,
845 SOLO_VI_MOTION_CR_ADD |
846 SOLO_VI_MOTION_Y_VALUE(0x10) |
847 SOLO_VI_MOTION_CB_VALUE(0x80) |
848 SOLO_VI_MOTION_CR_VALUE(0x10));
849 } else {
850 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0);
851 solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR, 0);
852 }
853 return 0;
854 }
855 return -EINVAL;
856}
857
858static const struct v4l2_file_operations solo_v4l2_fops = {
859 .owner = THIS_MODULE,
860 .open = solo_v4l2_open,
861 .release = solo_v4l2_release,
862 .read = solo_v4l2_read,
863 .poll = solo_v4l2_poll,
864 .mmap = solo_v4l2_mmap,
865 .ioctl = video_ioctl2,
866};
867
868static const struct v4l2_ioctl_ops solo_v4l2_ioctl_ops = {
869 .vidioc_querycap = solo_querycap,
870 .vidioc_s_std = solo_s_std,
871 /* Input callbacks */
872 .vidioc_enum_input = solo_enum_input,
873 .vidioc_s_input = solo_set_input,
874 .vidioc_g_input = solo_get_input,
875 /* Video capture format callbacks */
876 .vidioc_enum_fmt_vid_cap = solo_enum_fmt_cap,
877 .vidioc_try_fmt_vid_cap = solo_try_fmt_cap,
878 .vidioc_s_fmt_vid_cap = solo_set_fmt_cap,
879 .vidioc_g_fmt_vid_cap = solo_get_fmt_cap,
880 /* Streaming I/O */
881 .vidioc_reqbufs = solo_reqbufs,
882 .vidioc_querybuf = solo_querybuf,
883 .vidioc_qbuf = solo_qbuf,
884 .vidioc_dqbuf = solo_dqbuf,
885 .vidioc_streamon = solo_streamon,
886 .vidioc_streamoff = solo_streamoff,
887 /* Controls */
888 .vidioc_queryctrl = solo_disp_queryctrl,
889 .vidioc_g_ctrl = solo_disp_g_ctrl,
890 .vidioc_s_ctrl = solo_disp_s_ctrl,
891};
892
893static struct video_device solo_v4l2_template = {
894 .name = SOLO6X10_NAME,
895 .fops = &solo_v4l2_fops,
896 .ioctl_ops = &solo_v4l2_ioctl_ops,
897 .minor = -1,
898 .release = video_device_release,
899
900 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_B,
901 .current_norm = V4L2_STD_NTSC_M,
902};
903
904int solo_v4l2_init(struct solo_dev *solo_dev)
905{
906 int ret;
907 int i;
908
909 init_waitqueue_head(&solo_dev->disp_thread_wait);
910
911 solo_dev->vfd = video_device_alloc();
912 if (!solo_dev->vfd)
913 return -ENOMEM;
914
915 *solo_dev->vfd = solo_v4l2_template;
916 solo_dev->vfd->parent = &solo_dev->pdev->dev;
917
918 ret = video_register_device(solo_dev->vfd, VFL_TYPE_GRABBER, video_nr);
919 if (ret < 0) {
920 video_device_release(solo_dev->vfd);
921 solo_dev->vfd = NULL;
922 return ret;
923 }
924
925 video_set_drvdata(solo_dev->vfd, solo_dev);
926
927 snprintf(solo_dev->vfd->name, sizeof(solo_dev->vfd->name), "%s (%i)",
928 SOLO6X10_NAME, solo_dev->vfd->num);
929
930 if (video_nr != -1)
931 video_nr++;
932
933 dev_info(&solo_dev->pdev->dev, "Display as /dev/video%d with "
934 "%d inputs (%d extended)\n", solo_dev->vfd->num,
935 solo_dev->nr_chans, solo_dev->nr_ext);
936
937 /* Cycle all the channels and clear */
938 for (i = 0; i < solo_dev->nr_chans; i++) {
939 solo_v4l2_set_ch(solo_dev, i);
940 while (erase_off(solo_dev))
941 ;/* Do nothing */
942 }
943
944 /* Set the default display channel */
945 solo_v4l2_set_ch(solo_dev, 0);
946 while (erase_off(solo_dev))
947 ;/* Do nothing */
948
949 solo_irq_on(solo_dev, SOLO_IRQ_VIDEO_IN);
950
951 return 0;
952}
953
954void solo_v4l2_exit(struct solo_dev *solo_dev)
955{
956 solo_irq_off(solo_dev, SOLO_IRQ_VIDEO_IN);
957 if (solo_dev->vfd) {
958 video_unregister_device(solo_dev->vfd);
959 solo_dev->vfd = NULL;
960 }
961}