aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/media/.gitignore1
-rw-r--r--Documentation/DocBook/media/Makefile88
-rw-r--r--Documentation/DocBook/media/dvb/audio.xml6
-rw-r--r--Documentation/DocBook/media/dvb/ca.xml4
-rw-r--r--Documentation/DocBook/media/dvb/demux.xml61
-rw-r--r--Documentation/DocBook/media/dvb/dvbapi.xml34
-rw-r--r--Documentation/DocBook/media/dvb/dvbproperty.xml1117
-rw-r--r--Documentation/DocBook/media/dvb/examples.xml6
-rw-r--r--Documentation/DocBook/media/dvb/fe-diseqc-recv-slave-reply.xml78
-rw-r--r--Documentation/DocBook/media/dvb/fe-diseqc-reset-overload.xml51
-rw-r--r--Documentation/DocBook/media/dvb/fe-diseqc-send-burst.xml89
-rw-r--r--Documentation/DocBook/media/dvb/fe-diseqc-send-master-cmd.xml72
-rw-r--r--Documentation/DocBook/media/dvb/fe-enable-high-lnb-voltage.xml61
-rw-r--r--Documentation/DocBook/media/dvb/fe-get-info.xml266
-rw-r--r--Documentation/DocBook/media/dvb/fe-get-property.xml81
-rw-r--r--Documentation/DocBook/media/dvb/fe-read-status.xml107
-rw-r--r--Documentation/DocBook/media/dvb/fe-set-frontend-tune-mode.xml64
-rw-r--r--Documentation/DocBook/media/dvb/fe-set-tone.xml91
-rw-r--r--Documentation/DocBook/media/dvb/fe-set-voltage.xml69
-rw-r--r--Documentation/DocBook/media/dvb/frontend.xml1747
-rw-r--r--Documentation/DocBook/media/dvb/frontend_legacy_api.xml654
-rw-r--r--Documentation/DocBook/media/dvb/intro.xml30
-rw-r--r--Documentation/DocBook/media/dvb/kdapi.xml4
-rw-r--r--Documentation/DocBook/media/dvb/net.xml374
-rw-r--r--Documentation/DocBook/media/dvb/video.xml10
-rw-r--r--Documentation/DocBook/media/typical_media_device.svg28
-rw-r--r--Documentation/DocBook/media/v4l/controls.xml4
-rw-r--r--Documentation/DocBook/media/v4l/io.xml26
-rw-r--r--Documentation/DocBook/media/v4l/media-func-open.xml2
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt-y16-be.xml81
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt.xml134
-rw-r--r--Documentation/DocBook/media/v4l/remote_controllers.xml2
-rw-r--r--Documentation/DocBook/media/v4l/subdev-formats.xml12
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-create-bufs.xml3
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-decoder-cmd.xml12
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-dqevent.xml5
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-encoder-cmd.xml10
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-enum-frameintervals.xml3
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-enum-framesizes.xml3
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-expbuf.xml3
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-g-dv-timings.xml4
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-g-edid.xml11
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-g-selection.xml2
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-qbuf.xml10
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-query-dv-timings.xml3
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-querybuf.xml3
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-reqbufs.xml4
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml3
-rw-r--r--Documentation/DocBook/media_api.tmpl53
-rw-r--r--Documentation/devicetree/bindings/media/i2c/adp1653.txt37
-rw-r--r--Documentation/devicetree/bindings/media/st,stih4xx.txt32
-rw-r--r--Documentation/video4linux/CARDLIST.cx238859
-rw-r--r--Documentation/video4linux/CARDLIST.em28xx2
-rw-r--r--Documentation/video4linux/CARDLIST.saa71341
-rw-r--r--Documentation/video4linux/CARDLIST.saa71643
-rw-r--r--Documentation/video4linux/v4l2-framework.txt4
-rw-r--r--Documentation/video4linux/v4l2-pci-skeleton.c2
-rw-r--r--Documentation/video4linux/vivid.txt32
-rw-r--r--MAINTAINERS42
-rw-r--r--drivers/input/touchscreen/Kconfig3
-rw-r--r--drivers/input/touchscreen/sur40.c46
-rw-r--r--drivers/media/Kconfig2
-rw-r--r--drivers/media/common/b2c2/Kconfig1
-rw-r--r--drivers/media/common/b2c2/flexcop-common.h1
-rw-r--r--drivers/media/common/b2c2/flexcop-fe-tuner.c63
-rw-r--r--drivers/media/common/b2c2/flexcop-hw-filter.c16
-rw-r--r--drivers/media/common/b2c2/flexcop-misc.c1
-rw-r--r--drivers/media/common/b2c2/flexcop-reg.h1
-rw-r--r--drivers/media/common/siano/smscoreapi.h3
-rw-r--r--drivers/media/common/siano/smsdvb-main.c6
-rw-r--r--drivers/media/common/siano/smsdvb.h2
-rw-r--r--drivers/media/common/siano/smsir.c2
-rw-r--r--drivers/media/dvb-core/dvb_frontend.c78
-rw-r--r--drivers/media/dvb-core/dvb_frontend.h45
-rw-r--r--drivers/media/dvb-frontends/Kconfig13
-rw-r--r--drivers/media/dvb-frontends/Makefile1
-rw-r--r--drivers/media/dvb-frontends/a8293.c89
-rw-r--r--drivers/media/dvb-frontends/a8293.h15
-rw-r--r--drivers/media/dvb-frontends/af9013.c8
-rw-r--r--drivers/media/dvb-frontends/af9033.c4
-rw-r--r--drivers/media/dvb-frontends/as102_fe.c4
-rw-r--r--drivers/media/dvb-frontends/atbm8830.c3
-rw-r--r--drivers/media/dvb-frontends/au8522_dig.c4
-rw-r--r--drivers/media/dvb-frontends/au8522_priv.h2
-rw-r--r--drivers/media/dvb-frontends/bcm3510.c6
-rw-r--r--drivers/media/dvb-frontends/cx22700.c9
-rw-r--r--drivers/media/dvb-frontends/cx22702.c2
-rw-r--r--drivers/media/dvb-frontends/cx24110.c19
-rw-r--r--drivers/media/dvb-frontends/cx24116.c46
-rw-r--r--drivers/media/dvb-frontends/cx24117.c42
-rw-r--r--drivers/media/dvb-frontends/cx24120.c1595
-rw-r--r--drivers/media/dvb-frontends/cx24120.h58
-rw-r--r--drivers/media/dvb-frontends/cx24123.c18
-rw-r--r--drivers/media/dvb-frontends/cx24123.h2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_c.c2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_core.c5
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_priv.h8
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_t.c2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_t2.c2
-rw-r--r--drivers/media/dvb-frontends/dib0070.c575
-rw-r--r--drivers/media/dvb-frontends/dib0090.c4
-rw-r--r--drivers/media/dvb-frontends/dib3000mb.c7
-rw-r--r--drivers/media/dvb-frontends/dib3000mc.c20
-rw-r--r--drivers/media/dvb-frontends/dib7000m.c2
-rw-r--r--drivers/media/dvb-frontends/dib7000p.c6
-rw-r--r--drivers/media/dvb-frontends/dib8000.c10
-rw-r--r--drivers/media/dvb-frontends/dib8000.h2
-rw-r--r--drivers/media/dvb-frontends/dib9000.c4
-rw-r--r--drivers/media/dvb-frontends/drx39xyj/drxj.c42
-rw-r--r--drivers/media/dvb-frontends/drxd_hard.c2
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.c11
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.h2
-rw-r--r--drivers/media/dvb-frontends/ds3000.c13
-rw-r--r--drivers/media/dvb-frontends/dvb_dummy_fe.c9
-rw-r--r--drivers/media/dvb-frontends/ec100.c2
-rw-r--r--drivers/media/dvb-frontends/hd29l2.c2
-rw-r--r--drivers/media/dvb-frontends/hd29l2_priv.h2
-rw-r--r--drivers/media/dvb-frontends/isl6405.c3
-rw-r--r--drivers/media/dvb-frontends/isl6421.c6
-rw-r--r--drivers/media/dvb-frontends/l64781.c2
-rw-r--r--drivers/media/dvb-frontends/lg2160.c2
-rw-r--r--drivers/media/dvb-frontends/lgdt3305.c4
-rw-r--r--drivers/media/dvb-frontends/lgdt3306a.c11
-rw-r--r--drivers/media/dvb-frontends/lgdt330x.c8
-rw-r--r--drivers/media/dvb-frontends/lgs8gl5.c2
-rw-r--r--drivers/media/dvb-frontends/lgs8gxx.c3
-rw-r--r--drivers/media/dvb-frontends/lnbp21.c4
-rw-r--r--drivers/media/dvb-frontends/lnbp22.c3
-rw-r--r--drivers/media/dvb-frontends/m88ds3103.c1275
-rw-r--r--drivers/media/dvb-frontends/m88ds3103.h67
-rw-r--r--drivers/media/dvb-frontends/m88ds3103_priv.h20
-rw-r--r--drivers/media/dvb-frontends/m88rs2000.c19
-rw-r--r--drivers/media/dvb-frontends/mb86a16.c7
-rw-r--r--drivers/media/dvb-frontends/mb86a16.h3
-rw-r--r--drivers/media/dvb-frontends/mb86a20s.c6
-rw-r--r--drivers/media/dvb-frontends/mb86a20s.h2
-rw-r--r--drivers/media/dvb-frontends/mt312.c17
-rw-r--r--drivers/media/dvb-frontends/mt352.c2
-rw-r--r--drivers/media/dvb-frontends/nxt200x.c2
-rw-r--r--drivers/media/dvb-frontends/nxt6000.c12
-rw-r--r--drivers/media/dvb-frontends/or51132.c6
-rw-r--r--drivers/media/dvb-frontends/or51211.c2
-rw-r--r--drivers/media/dvb-frontends/rtl2830.c2
-rw-r--r--drivers/media/dvb-frontends/rtl2830_priv.h2
-rw-r--r--drivers/media/dvb-frontends/rtl2832.c10
-rw-r--r--drivers/media/dvb-frontends/rtl2832.h2
-rw-r--r--drivers/media/dvb-frontends/rtl2832_priv.h51
-rw-r--r--drivers/media/dvb-frontends/rtl2832_sdr.c120
-rw-r--r--drivers/media/dvb-frontends/rtl2832_sdr.h1
-rw-r--r--drivers/media/dvb-frontends/s5h1409.c6
-rw-r--r--drivers/media/dvb-frontends/s5h1411.c6
-rw-r--r--drivers/media/dvb-frontends/s5h1420.c43
-rw-r--r--drivers/media/dvb-frontends/s5h1432.c4
-rw-r--r--drivers/media/dvb-frontends/s921.c6
-rw-r--r--drivers/media/dvb-frontends/s921.h2
-rw-r--r--drivers/media/dvb-frontends/si2165.c2
-rw-r--r--drivers/media/dvb-frontends/si2168.c144
-rw-r--r--drivers/media/dvb-frontends/si2168.h3
-rw-r--r--drivers/media/dvb-frontends/si2168_priv.h6
-rw-r--r--drivers/media/dvb-frontends/si21xx.c10
-rw-r--r--drivers/media/dvb-frontends/sp8870.c3
-rw-r--r--drivers/media/dvb-frontends/sp887x.c2
-rw-r--r--drivers/media/dvb-frontends/stb0899_drv.c8
-rw-r--r--drivers/media/dvb-frontends/stv0288.c39
-rw-r--r--drivers/media/dvb-frontends/stv0297.c19
-rw-r--r--drivers/media/dvb-frontends/stv0299.c34
-rw-r--r--drivers/media/dvb-frontends/stv0367.c12
-rw-r--r--drivers/media/dvb-frontends/stv0367_priv.h2
-rw-r--r--drivers/media/dvb-frontends/stv0900_core.c6
-rw-r--r--drivers/media/dvb-frontends/stv0900_sw.c6
-rw-r--r--drivers/media/dvb-frontends/stv090x.c5
-rw-r--r--drivers/media/dvb-frontends/stv6110.c2
-rw-r--r--drivers/media/dvb-frontends/tc90522.c17
-rw-r--r--drivers/media/dvb-frontends/tda10021.c9
-rw-r--r--drivers/media/dvb-frontends/tda10023.c5
-rw-r--r--drivers/media/dvb-frontends/tda10048.c2
-rw-r--r--drivers/media/dvb-frontends/tda1004x.c5
-rw-r--r--drivers/media/dvb-frontends/tda10071.c117
-rw-r--r--drivers/media/dvb-frontends/tda10071.h29
-rw-r--r--drivers/media/dvb-frontends/tda10071_priv.h11
-rw-r--r--drivers/media/dvb-frontends/tda10086.c13
-rw-r--r--drivers/media/dvb-frontends/tda8083.c38
-rw-r--r--drivers/media/dvb-frontends/ts2020.c591
-rw-r--r--drivers/media/dvb-frontends/ts2020.h17
-rw-r--r--drivers/media/dvb-frontends/ves1820.c6
-rw-r--r--drivers/media/dvb-frontends/ves1x93.c15
-rw-r--r--drivers/media/dvb-frontends/zl10353.c12
-rw-r--r--drivers/media/firewire/firedtv-fe.c8
-rw-r--r--drivers/media/firewire/firedtv.h4
-rw-r--r--drivers/media/i2c/Kconfig4
-rw-r--r--drivers/media/i2c/adp1653.c100
-rw-r--r--drivers/media/i2c/adv7170.c42
-rw-r--r--drivers/media/i2c/adv7175.c42
-rw-r--r--drivers/media/i2c/adv7183.c61
-rw-r--r--drivers/media/i2c/adv7511.c160
-rw-r--r--drivers/media/i2c/adv7604.c192
-rw-r--r--drivers/media/i2c/adv7842.c309
-rw-r--r--drivers/media/i2c/ak881x.c39
-rw-r--r--drivers/media/i2c/cx25840/cx25840-core.c17
-rw-r--r--drivers/media/i2c/ml86v7667.c29
-rw-r--r--drivers/media/i2c/mt9v011.c53
-rw-r--r--drivers/media/i2c/ov2659.c38
-rw-r--r--drivers/media/i2c/ov7670.c65
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-core.c2
-rw-r--r--drivers/media/i2c/s5k5baf.c4
-rw-r--r--drivers/media/i2c/s5k6aa.c2
-rw-r--r--drivers/media/i2c/saa6752hs.c42
-rw-r--r--drivers/media/i2c/saa7115.c16
-rw-r--r--drivers/media/i2c/saa717x.c20
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c38
-rw-r--r--drivers/media/i2c/soc_camera/imx074.c66
-rw-r--r--drivers/media/i2c/soc_camera/mt9m001.c43
-rw-r--r--drivers/media/i2c/soc_camera/mt9m111.c57
-rw-r--r--drivers/media/i2c/soc_camera/mt9t031.c74
-rw-r--r--drivers/media/i2c/soc_camera/mt9t112.c41
-rw-r--r--drivers/media/i2c/soc_camera/mt9v022.c43
-rw-r--r--drivers/media/i2c/soc_camera/ov2640.c62
-rw-r--r--drivers/media/i2c/soc_camera/ov5642.c60
-rw-r--r--drivers/media/i2c/soc_camera/ov6650.c43
-rw-r--r--drivers/media/i2c/soc_camera/ov772x.c41
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.c32
-rw-r--r--drivers/media/i2c/soc_camera/ov9740.c35
-rw-r--r--drivers/media/i2c/soc_camera/rj54n1cb0c.c66
-rw-r--r--drivers/media/i2c/soc_camera/tw9910.c41
-rw-r--r--drivers/media/i2c/sr030pc30.c62
-rw-r--r--drivers/media/i2c/tvaudio.c2
-rw-r--r--drivers/media/i2c/tvp514x.c55
-rw-r--r--drivers/media/i2c/tvp5150.c30
-rw-r--r--drivers/media/i2c/tvp7002.c48
-rw-r--r--drivers/media/i2c/vs6624.c55
-rw-r--r--drivers/media/pci/Kconfig2
-rw-r--r--drivers/media/pci/Makefile2
-rw-r--r--drivers/media/pci/bt8xx/bttv-audio-hook.c443
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c5
-rw-r--r--drivers/media/pci/bt8xx/dst.c25
-rw-r--r--drivers/media/pci/bt8xx/dst_ca.c138
-rw-r--r--drivers/media/pci/bt8xx/dst_common.h12
-rw-r--r--drivers/media/pci/cobalt/Kconfig18
-rw-r--r--drivers/media/pci/cobalt/Makefile5
-rw-r--r--drivers/media/pci/cobalt/cobalt-alsa-main.c162
-rw-r--r--drivers/media/pci/cobalt/cobalt-alsa-pcm.c603
-rw-r--r--drivers/media/pci/cobalt/cobalt-alsa-pcm.h22
-rw-r--r--drivers/media/pci/cobalt/cobalt-alsa.h41
-rw-r--r--drivers/media/pci/cobalt/cobalt-cpld.c341
-rw-r--r--drivers/media/pci/cobalt/cobalt-cpld.h29
-rw-r--r--drivers/media/pci/cobalt/cobalt-driver.c832
-rw-r--r--drivers/media/pci/cobalt/cobalt-driver.h380
-rw-r--r--drivers/media/pci/cobalt/cobalt-flash.c128
-rw-r--r--drivers/media/pci/cobalt/cobalt-flash.h29
-rw-r--r--drivers/media/pci/cobalt/cobalt-i2c.c396
-rw-r--r--drivers/media/pci/cobalt/cobalt-i2c.h25
-rw-r--r--drivers/media/pci/cobalt/cobalt-irq.c258
-rw-r--r--drivers/media/pci/cobalt/cobalt-irq.h25
-rw-r--r--drivers/media/pci/cobalt/cobalt-omnitek.c341
-rw-r--r--drivers/media/pci/cobalt/cobalt-omnitek.h62
-rw-r--r--drivers/media/pci/cobalt/cobalt-v4l2.c1272
-rw-r--r--drivers/media/pci/cobalt/cobalt-v4l2.h22
-rw-r--r--drivers/media/pci/cobalt/m00233_video_measure_memmap_package.h115
-rw-r--r--drivers/media/pci/cobalt/m00235_fdma_packer_memmap_package.h44
-rw-r--r--drivers/media/pci/cobalt/m00389_cvi_memmap_package.h59
-rw-r--r--drivers/media/pci/cobalt/m00460_evcnt_memmap_package.h44
-rw-r--r--drivers/media/pci/cobalt/m00473_freewheel_memmap_package.h57
-rw-r--r--drivers/media/pci/cobalt/m00479_clk_loss_detector_memmap_package.h53
-rw-r--r--drivers/media/pci/cobalt/m00514_syncgen_flow_evcnt_memmap_package.h88
-rw-r--r--drivers/media/pci/cx18/cx18-av-core.c16
-rw-r--r--drivers/media/pci/cx18/cx18-controls.c13
-rw-r--r--drivers/media/pci/cx18/cx18-driver.c4
-rw-r--r--drivers/media/pci/cx18/cx18-ioctl.c12
-rw-r--r--drivers/media/pci/cx18/cx18-streams.c1
-rw-r--r--drivers/media/pci/cx23885/altera-ci.c2
-rw-r--r--drivers/media/pci/cx23885/cx23885-dvb.c150
-rw-r--r--drivers/media/pci/cx23885/cx23885-f300.c2
-rw-r--r--drivers/media/pci/cx23885/cx23885-f300.h2
-rw-r--r--drivers/media/pci/cx23885/cx23885-video.c12
-rw-r--r--drivers/media/pci/cx23885/cx23885.h3
-rw-r--r--drivers/media/pci/cx88/cx88-core.c2
-rw-r--r--drivers/media/pci/cx88/cx88-dvb.c12
-rw-r--r--drivers/media/pci/cx88/cx88-mpeg.c6
-rw-r--r--drivers/media/pci/cx88/cx88-vbi.c6
-rw-r--r--drivers/media/pci/cx88/cx88-video.c9
-rw-r--r--drivers/media/pci/cx88/cx88.h6
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-core.c3
-rw-r--r--drivers/media/pci/dm1105/dm1105.c3
-rw-r--r--drivers/media/pci/dt3155/Kconfig13
-rw-r--r--drivers/media/pci/dt3155/Makefile1
-rw-r--r--drivers/media/pci/dt3155/dt3155.c632
-rw-r--r--drivers/media/pci/dt3155/dt3155.h (renamed from drivers/staging/media/dt3155v4l/dt3155v4l.h)64
-rw-r--r--drivers/media/pci/ivtv/ivtv-controls.c12
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c4
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.h3
-rw-r--r--drivers/media/pci/ivtv/ivtv-ioctl.c15
-rw-r--r--drivers/media/pci/mantis/hopper_cards.c14
-rw-r--r--drivers/media/pci/mantis/mantis_cards.c94
-rw-r--r--drivers/media/pci/mantis/mantis_common.h33
-rw-r--r--drivers/media/pci/mantis/mantis_dma.c5
-rw-r--r--drivers/media/pci/mantis/mantis_i2c.c12
-rw-r--r--drivers/media/pci/mantis/mantis_input.c110
-rw-r--r--drivers/media/pci/mantis/mantis_input.h24
-rw-r--r--drivers/media/pci/mantis/mantis_pcmcia.c4
-rw-r--r--drivers/media/pci/mantis/mantis_uart.c61
-rw-r--r--drivers/media/pci/mantis/mantis_vp1034.c2
-rw-r--r--drivers/media/pci/mantis/mantis_vp1034.h3
-rw-r--r--drivers/media/pci/ngene/ngene-core.c10
-rw-r--r--drivers/media/pci/ngene/ngene.h2
-rw-r--r--drivers/media/pci/pt1/pt1.c6
-rw-r--r--drivers/media/pci/pt1/va1j5jf8007s.c4
-rw-r--r--drivers/media/pci/pt1/va1j5jf8007t.c4
-rw-r--r--drivers/media/pci/pt3/pt3.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-alsa.c55
-rw-r--r--drivers/media/pci/saa7134/saa7134-cards.c150
-rw-r--r--drivers/media/pci/saa7134/saa7134-core.c161
-rw-r--r--drivers/media/pci/saa7134/saa7134-dvb.c122
-rw-r--r--drivers/media/pci/saa7134/saa7134-empress.c55
-rw-r--r--drivers/media/pci/saa7134/saa7134-go7007.c11
-rw-r--r--drivers/media/pci/saa7134/saa7134-i2c.c87
-rw-r--r--drivers/media/pci/saa7134/saa7134-input.c59
-rw-r--r--drivers/media/pci/saa7134/saa7134-ts.c24
-rw-r--r--drivers/media/pci/saa7134/saa7134-tvaudio.c168
-rw-r--r--drivers/media/pci/saa7134/saa7134-vbi.c14
-rw-r--r--drivers/media/pci/saa7134/saa7134-video.c43
-rw-r--r--drivers/media/pci/saa7134/saa7134.h6
-rw-r--r--drivers/media/pci/saa7164/saa7164-api.c11
-rw-r--r--drivers/media/pci/saa7164/saa7164-buffer.c2
-rw-r--r--drivers/media/pci/saa7164/saa7164-bus.c2
-rw-r--r--drivers/media/pci/saa7164/saa7164-cards.c188
-rw-r--r--drivers/media/pci/saa7164/saa7164-cmd.c2
-rw-r--r--drivers/media/pci/saa7164/saa7164-core.c82
-rw-r--r--drivers/media/pci/saa7164/saa7164-dvb.c241
-rw-r--r--drivers/media/pci/saa7164/saa7164-encoder.c13
-rw-r--r--drivers/media/pci/saa7164/saa7164-fw.c2
-rw-r--r--drivers/media/pci/saa7164/saa7164-i2c.c9
-rw-r--r--drivers/media/pci/saa7164/saa7164-reg.h2
-rw-r--r--drivers/media/pci/saa7164/saa7164-types.h2
-rw-r--r--drivers/media/pci/saa7164/saa7164-vbi.c13
-rw-r--r--drivers/media/pci/saa7164/saa7164.h8
-rw-r--r--drivers/media/pci/smipcie/smipcie.c1
-rw-r--r--drivers/media/pci/sta2x11/sta2x11_vip.c3
-rw-r--r--drivers/media/pci/ttpci/av7110.c18
-rw-r--r--drivers/media/pci/ttpci/av7110.h27
-rw-r--r--drivers/media/pci/ttpci/budget-core.c3
-rw-r--r--drivers/media/pci/ttpci/budget-patch.c15
-rw-r--r--drivers/media/pci/ttpci/budget.c12
-rw-r--r--drivers/media/pci/ttpci/budget.h2
-rw-r--r--drivers/media/pci/zoran/zoran_device.c13
-rw-r--r--drivers/media/platform/Kconfig10
-rw-r--r--drivers/media/platform/Makefile2
-rw-r--r--drivers/media/platform/am437x/am437x-vpfe.c35
-rw-r--r--drivers/media/platform/blackfin/bfin_capture.c40
-rw-r--r--drivers/media/platform/coda/coda-bit.c4
-rw-r--r--drivers/media/platform/coda/coda-common.c27
-rw-r--r--drivers/media/platform/coda/coda.h3
-rw-r--r--drivers/media/platform/coda/trace.h2
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c9
-rw-r--r--drivers/media/platform/davinci/vpfe_capture.c19
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.c2
-rw-r--r--drivers/media/platform/exynos4-is/Kconfig1
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.c2
-rw-r--r--drivers/media/platform/fsl-viu.c2
-rw-r--r--drivers/media/platform/m2m-deinterlace.c1
-rw-r--r--drivers/media/platform/marvell-ccic/cafe-driver.c13
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c480
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.h3
-rw-r--r--drivers/media/platform/marvell-ccic/mmp-driver.c1
-rw-r--r--drivers/media/platform/omap/omap_vout.c10
-rw-r--r--drivers/media/platform/omap3isp/isppreview.c4
-rw-r--r--drivers/media/platform/s3c-camif/camif-capture.c13
-rw-r--r--drivers/media/platform/s3c-camif/camif-core.c2
-rw-r--r--drivers/media/platform/s5p-g2d/g2d.c2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c5
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c6
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c4
-rw-r--r--drivers/media/platform/s5p-tv/hdmi_drv.c14
-rw-r--r--drivers/media/platform/s5p-tv/mixer_drv.c15
-rw-r--r--drivers/media/platform/s5p-tv/sdo_drv.c14
-rw-r--r--drivers/media/platform/sh_vou.c75
-rw-r--r--drivers/media/platform/soc_camera/atmel-isi.c74
-rw-r--r--drivers/media/platform/soc_camera/mx2_camera.c113
-rw-r--r--drivers/media/platform/soc_camera/mx3_camera.c105
-rw-r--r--drivers/media/platform/soc_camera/omap1_camera.c106
-rw-r--r--drivers/media/platform/soc_camera/pxa_camera.c99
-rw-r--r--drivers/media/platform/soc_camera/rcar_vin.c113
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c115
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_csi2.c35
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c30
-rw-r--r--drivers/media/platform/soc_camera/soc_camera_platform.c24
-rw-r--r--drivers/media/platform/soc_camera/soc_scale_crop.c37
-rw-r--r--drivers/media/platform/sti/bdisp/Makefile3
-rw-r--r--drivers/media/platform/sti/bdisp/bdisp-debug.c679
-rw-r--r--drivers/media/platform/sti/bdisp/bdisp-filter.h346
-rw-r--r--drivers/media/platform/sti/bdisp/bdisp-hw.c823
-rw-r--r--drivers/media/platform/sti/bdisp/bdisp-reg.h235
-rw-r--r--drivers/media/platform/sti/bdisp/bdisp-v4l2.c1416
-rw-r--r--drivers/media/platform/sti/bdisp/bdisp.h216
-rw-r--r--drivers/media/platform/via-camera.c19
-rw-r--r--drivers/media/platform/vim2m.c12
-rw-r--r--drivers/media/platform/vivid/vivid-core.c20
-rw-r--r--drivers/media/platform/vivid/vivid-core.h6
-rw-r--r--drivers/media/platform/vivid/vivid-ctrls.c139
-rw-r--r--drivers/media/platform/vivid/vivid-radio-rx.c2
-rw-r--r--drivers/media/platform/vivid/vivid-sdr-cap.c96
-rw-r--r--drivers/media/platform/vivid/vivid-sdr-cap.h2
-rw-r--r--drivers/media/platform/vivid/vivid-tpg-colors.c478
-rw-r--r--drivers/media/platform/vivid/vivid-tpg-colors.h4
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.c313
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.h20
-rw-r--r--drivers/media/platform/vivid/vivid-vid-cap.c31
-rw-r--r--drivers/media/platform/vivid/vivid-vid-common.c68
-rw-r--r--drivers/media/platform/vivid/vivid-vid-out.c7
-rw-r--r--drivers/media/platform/xilinx/Kconfig2
-rw-r--r--drivers/media/platform/xilinx/xilinx-dma.c4
-rw-r--r--drivers/media/radio/radio-si476x.c4
-rw-r--r--drivers/media/radio/radio-timb.c4
-rw-r--r--drivers/media/radio/si470x/radio-si470x-i2c.c9
-rw-r--r--drivers/media/radio/si470x/radio-si470x-usb.c6
-rw-r--r--drivers/media/radio/si470x/radio-si470x.h8
-rw-r--r--drivers/media/radio/si4713/si4713.c4
-rw-r--r--drivers/media/radio/wl128x/Kconfig4
-rw-r--r--drivers/media/radio/wl128x/fmdrv.h2
-rw-r--r--drivers/media/rc/fintek-cir.c1
-rw-r--r--drivers/media/rc/gpio-ir-recv.c4
-rw-r--r--drivers/media/rc/ir-hix5hd2.c8
-rw-r--r--drivers/media/rc/ir-rc5-decoder.c116
-rw-r--r--drivers/media/rc/ir-rc6-decoder.c122
-rw-r--r--drivers/media/rc/ir-sony-decoder.c28
-rw-r--r--drivers/media/rc/keymaps/Makefile4
-rw-r--r--drivers/media/rc/keymaps/rc-technisat-ts35.c76
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-cinergy-c-pci.c88
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-cinergy-s2-hd.c86
-rw-r--r--drivers/media/rc/keymaps/rc-twinhan-dtv-cab-ci.c98
-rw-r--r--drivers/media/rc/nuvoton-cir.c127
-rw-r--r--drivers/media/rc/nuvoton-cir.h1
-rw-r--r--drivers/media/rc/rc-core-priv.h36
-rw-r--r--drivers/media/rc/rc-ir-raw.c139
-rw-r--r--drivers/media/rc/rc-loopback.c36
-rw-r--r--drivers/media/rc/rc-main.c9
-rw-r--r--drivers/media/rc/redrat3.c7
-rw-r--r--drivers/media/rc/st_rc.c12
-rw-r--r--drivers/media/rc/streamzap.c6
-rw-r--r--drivers/media/tuners/Kconfig5
-rw-r--r--drivers/media/tuners/e4000.c592
-rw-r--r--drivers/media/tuners/e4000.h1
-rw-r--r--drivers/media/tuners/e4000_priv.h11
-rw-r--r--drivers/media/tuners/fc0013.c2
-rw-r--r--drivers/media/tuners/fc2580.c781
-rw-r--r--drivers/media/tuners/fc2580.h40
-rw-r--r--drivers/media/tuners/fc2580_priv.h36
-rw-r--r--drivers/media/tuners/msi001.c267
-rw-r--r--drivers/media/tuners/qt1010.c8
-rw-r--r--drivers/media/tuners/r820t.c4
-rw-r--r--drivers/media/tuners/si2157.c44
-rw-r--r--drivers/media/tuners/si2157.h6
-rw-r--r--drivers/media/tuners/si2157_priv.h2
-rw-r--r--drivers/media/tuners/tua9001.c331
-rw-r--r--drivers/media/tuners/tua9001.h35
-rw-r--r--drivers/media/tuners/tua9001_priv.h19
-rw-r--r--drivers/media/tuners/tuner-i2c.h10
-rw-r--r--drivers/media/tuners/tuner-xc2028.c2
-rw-r--r--drivers/media/usb/as102/as102_drv.c1
-rw-r--r--drivers/media/usb/au0828/au0828-cards.c2
-rw-r--r--drivers/media/usb/au0828/au0828-core.c2
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-417.c21
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-avcore.c44
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c56
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-core.c30
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-dvb.c2
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-vbi.c3
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-video.c26
-rw-r--r--drivers/media/usb/cx231xx/cx231xx.h1
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c58
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvbsky.c18
-rw-r--r--drivers/media/usb/dvb-usb-v2/lmedm04.c112
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c14
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.c193
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.h5
-rw-r--r--drivers/media/usb/dvb-usb/af9005-fe.c7
-rw-r--r--drivers/media/usb/dvb-usb/az6027.c3
-rw-r--r--drivers/media/usb/dvb-usb/cinergyT2-fe.c2
-rw-r--r--drivers/media/usb/dvb-usb/cxusb.c1
-rw-r--r--drivers/media/usb/dvb-usb/dib0700.h2
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_core.c70
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_devices.c145
-rw-r--r--drivers/media/usb/dvb-usb/dtt200u-fe.c7
-rw-r--r--drivers/media/usb/dvb-usb/dw2102.c55
-rw-r--r--drivers/media/usb/dvb-usb/friio-fe.c3
-rw-r--r--drivers/media/usb/dvb-usb/gp8psk-fe.c13
-rw-r--r--drivers/media/usb/dvb-usb/opera1.c3
-rw-r--r--drivers/media/usb/dvb-usb/technisat-usb2.c2
-rw-r--r--drivers/media/usb/dvb-usb/vp702x-fe.c17
-rw-r--r--drivers/media/usb/dvb-usb/vp702x.c7
-rw-r--r--drivers/media/usb/dvb-usb/vp7045-fe.c3
-rw-r--r--drivers/media/usb/em28xx/em28xx-camera.c12
-rw-r--r--drivers/media/usb/em28xx/em28xx-dvb.c216
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c1
-rw-r--r--drivers/media/usb/go7007/go7007-driver.c3
-rw-r--r--drivers/media/usb/go7007/go7007-usb.c4
-rw-r--r--drivers/media/usb/go7007/go7007-v4l2.c12
-rw-r--r--drivers/media/usb/go7007/s2250-board.c18
-rw-r--r--drivers/media/usb/gspca/benq.c4
-rw-r--r--drivers/media/usb/gspca/sn9c2028.c241
-rw-r--r--drivers/media/usb/gspca/sn9c2028.h18
-rw-r--r--drivers/media/usb/gspca/sonixj.c2
-rw-r--r--drivers/media/usb/gspca/stk014.c2
-rw-r--r--drivers/media/usb/gspca/xirlink_cit.c12
-rw-r--r--drivers/media/usb/gspca/zc3xx.c16
-rw-r--r--drivers/media/usb/msi2500/msi2500.c655
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-context.c3
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.c35
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-io.c30
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-ioread.c24
-rw-r--r--drivers/media/usb/stk1160/stk1160-v4l.c3
-rw-r--r--drivers/media/usb/tm6000/tm6000-video.c5
-rw-r--r--drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c9
-rw-r--r--drivers/media/usb/ttusb-dec/ttusb_dec.c4
-rw-r--r--drivers/media/usb/ttusb-dec/ttusbdecfe.c10
-rw-r--r--drivers/media/usb/usbtv/usbtv-video.c12
-rw-r--r--drivers/media/usb/usbvision/usbvision-core.c4
-rw-r--r--drivers/media/usb/usbvision/usbvision-video.c17
-rw-r--r--drivers/media/usb/uvc/uvc_driver.c2
-rw-r--r--drivers/media/usb/uvc/uvc_queue.c12
-rw-r--r--drivers/media/usb/uvc/uvc_v4l2.c16
-rw-r--r--drivers/media/usb/uvc/uvc_video.c8
-rw-r--r--drivers/media/usb/uvc/uvcvideo.h7
-rw-r--r--drivers/media/usb/zr364xx/zr364xx.c3
-rw-r--r--drivers/media/v4l2-core/Kconfig2
-rw-r--r--drivers/media/v4l2-core/v4l2-dv-timings.c117
-rw-r--r--drivers/media/v4l2-core/v4l2-ioctl.c214
-rw-r--r--drivers/media/v4l2-core/v4l2-mem2mem.c38
-rw-r--r--drivers/media/v4l2-core/v4l2-of.c100
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c63
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-contig.c6
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-sg.c22
-rw-r--r--drivers/media/v4l2-core/videobuf2-vmalloc.c6
-rw-r--r--drivers/staging/media/Kconfig2
-rw-r--r--drivers/staging/media/Makefile1
-rw-r--r--drivers/staging/media/bcm2048/radio-bcm2048.c3
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c1
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h2
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_video.c18
-rw-r--r--drivers/staging/media/dt3155v4l/Kconfig29
-rw-r--r--drivers/staging/media/dt3155v4l/Makefile1
-rw-r--r--drivers/staging/media/dt3155v4l/dt3155v4l.c981
-rw-r--r--drivers/staging/media/lirc/lirc_imon.c97
-rw-r--r--drivers/staging/media/lirc/lirc_sir.c75
-rw-r--r--drivers/staging/media/mn88472/mn88472.c6
-rw-r--r--drivers/staging/media/mn88472/mn88472_priv.h2
-rw-r--r--drivers/staging/media/mn88473/mn88473.c2
-rw-r--r--drivers/staging/media/mn88473/mn88473_priv.h2
-rw-r--r--drivers/staging/media/omap4iss/iss.c2
-rw-r--r--drivers/staging/media/omap4iss/iss_csi2.c18
-rw-r--r--drivers/staging/media/omap4iss/iss_ipipe.c30
-rw-r--r--drivers/staging/media/omap4iss/iss_ipipeif.c10
-rw-r--r--drivers/staging/media/omap4iss/iss_resizer.c8
-rw-r--r--include/media/adp1653.h8
-rw-r--r--include/media/adv7511.h7
-rw-r--r--include/media/adv7604.h1
-rw-r--r--include/media/adv7842.h142
-rw-r--r--include/media/rc-core.h9
-rw-r--r--include/media/rc-map.h4
-rw-r--r--include/media/v4l2-dv-timings.h6
-rw-r--r--include/media/v4l2-mediabus.h2
-rw-r--r--include/media/v4l2-mem2mem.h4
-rw-r--r--include/media/v4l2-of.h20
-rw-r--r--include/media/v4l2-subdev.h18
-rw-r--r--include/media/videobuf2-core.h13
-rw-r--r--include/trace/events/v4l2.h3
-rw-r--r--include/uapi/linux/dvb/dmx.h10
-rw-r--r--include/uapi/linux/dvb/frontend.h223
-rw-r--r--include/uapi/linux/v4l2-mediabus.h4
-rw-r--r--include/uapi/linux/videodev2.h83
571 files changed, 27333 insertions, 10259 deletions
diff --git a/Documentation/DocBook/media/.gitignore b/Documentation/DocBook/media/.gitignore
new file mode 100644
index 000000000000..e461c585fde8
--- /dev/null
+++ b/Documentation/DocBook/media/.gitignore
@@ -0,0 +1 @@
!*.svg
diff --git a/Documentation/DocBook/media/Makefile b/Documentation/DocBook/media/Makefile
index 8bf7c6191296..23996f88cd58 100644
--- a/Documentation/DocBook/media/Makefile
+++ b/Documentation/DocBook/media/Makefile
@@ -65,29 +65,31 @@ IOCTLS = \
65 $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/uapi/linux/dvb/video.h) \ 65 $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/uapi/linux/dvb/video.h) \
66 $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/uapi/linux/media.h) \ 66 $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/uapi/linux/media.h) \
67 $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/uapi/linux/v4l2-subdev.h) \ 67 $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/uapi/linux/v4l2-subdev.h) \
68 VIDIOC_SUBDEV_G_FRAME_INTERVAL \ 68
69 VIDIOC_SUBDEV_S_FRAME_INTERVAL \ 69DEFINES = \
70 VIDIOC_SUBDEV_ENUM_MBUS_CODE \ 70 $(shell perl -ne 'print "$$1 " if /\#define\s+(DTV_[^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/frontend.h) \
71 VIDIOC_SUBDEV_ENUM_FRAME_SIZE \
72 VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL \
73 VIDIOC_SUBDEV_G_SELECTION \
74 VIDIOC_SUBDEV_S_SELECTION \
75 71
76TYPES = \ 72TYPES = \
77 $(shell perl -ne 'print "$$1 " if /^typedef\s+[^\s]+\s+([^\s]+)\;/' $(srctree)/include/uapi/linux/videodev2.h) \ 73 $(shell perl -ne 'print "$$1 " if /^typedef\s+.*\s+(\S+)\;/' $(srctree)/include/uapi/linux/videodev2.h) \
78 $(shell perl -ne 'print "$$1 " if /^}\s+([a-z0-9_]+_t)/' $(srctree)/include/uapi/linux/dvb/frontend.h) 74 $(shell perl -ne 'print "$$1 " if /^typedef\s+.*\s+(\S+)\;/' $(srctree)/include/uapi/linux/dvb/frontend.h)
79 75
80ENUMS = \ 76ENUMS = \
81 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/videodev2.h) \ 77 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' \
82 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/audio.h) \ 78 $(srctree)/include/uapi/linux/videodev2.h \
83 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/ca.h) \ 79 $(srctree)/include/uapi/linux/dvb/audio.h \
84 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/dmx.h) \ 80 $(srctree)/include/uapi/linux/dvb/ca.h \
85 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/frontend.h) \ 81 $(srctree)/include/uapi/linux/dvb/dmx.h \
86 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/net.h) \ 82 $(srctree)/include/uapi/linux/dvb/frontend.h \
87 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/dvb/video.h) \ 83 $(srctree)/include/uapi/linux/dvb/net.h \
88 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/media.h) \ 84 $(srctree)/include/uapi/linux/dvb/video.h \
89 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/v4l2-mediabus.h) \ 85 $(srctree)/include/uapi/linux/media.h \
90 $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/v4l2-subdev.h) 86 $(srctree)/include/uapi/linux/v4l2-mediabus.h \
87 $(srctree)/include/uapi/linux/v4l2-subdev.h)
88
89ENUM_DEFS = \
90 $(shell perl -e 'open IN,"cat @ARGV| cpp -fpreprocessed |"; while (<IN>) { if ($$enum) {print "$$1\n" if (/\s*([A-Z]\S+)\b/); } $$enum = 0 if ($$enum && /^\}/); $$enum = 1 if(/^\s*enum\s/); }; close IN;' \
91 $(srctree)/include/uapi/linux/dvb/dmx.h \
92 $(srctree)/include/uapi/linux/dvb/frontend.h)
91 93
92STRUCTS = \ 94STRUCTS = \
93 $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/videodev2.h) \ 95 $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/videodev2.h) \
@@ -95,7 +97,7 @@ STRUCTS = \
95 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/ca.h) \ 97 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/ca.h) \
96 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/dmx.h) \ 98 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/dmx.h) \
97 $(shell perl -ne 'print "$$1 " if (!/dtv\_cmds\_h/ && /^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/frontend.h) \ 99 $(shell perl -ne 'print "$$1 " if (!/dtv\_cmds\_h/ && /^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/frontend.h) \
98 $(shell perl -ne 'print "$$1 " if (/^struct\s+([A-Z][^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/net.h) \ 100 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/ && !/_old/)' $(srctree)/include/uapi/linux/dvb/net.h) \
99 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/video.h) \ 101 $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/uapi/linux/dvb/video.h) \
100 $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/media.h) \ 102 $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/media.h) \
101 $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/v4l2-subdev.h) \ 103 $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/uapi/linux/v4l2-subdev.h) \
@@ -179,7 +181,6 @@ DOCUMENTED = \
179 -e "s/v4l2\-mpeg\-vbi\-ITV0/v4l2-mpeg-vbi-itv0-1/g" 181 -e "s/v4l2\-mpeg\-vbi\-ITV0/v4l2-mpeg-vbi-itv0-1/g"
180 182
181DVB_DOCUMENTED = \ 183DVB_DOCUMENTED = \
182 -e "s/\(linkend\=\"\)FE_SET_PROPERTY/\1FE_GET_PROPERTY/g" \
183 -e "s,\(struct\s\+\)\([a-z0-9_]\+\)\(\s\+{\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \ 184 -e "s,\(struct\s\+\)\([a-z0-9_]\+\)\(\s\+{\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
184 -e "s,\(}\s\+\)\([a-z0-9_]\+_t\+\),\1\<link linkend=\"\2\">\2\<\/link\>,g" \ 185 -e "s,\(}\s\+\)\([a-z0-9_]\+_t\+\),\1\<link linkend=\"\2\">\2\<\/link\>,g" \
185 -e "s,\(define\s\+\)\(DTV_[A-Z0-9_]\+\)\(\s\+[0-9]\+\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \ 186 -e "s,\(define\s\+\)\(DTV_[A-Z0-9_]\+\)\(\s\+[0-9]\+\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
@@ -188,14 +189,17 @@ DVB_DOCUMENTED = \
188 -e "s,\(audio-mixer\|audio-karaoke\|audio-status\|ca-slot-info\|ca-descr-info\|ca-caps\|ca-msg\|ca-descr\|ca-pid\|dmx-filter\|dmx-caps\|video-system\|video-highlight\|video-spu\|video-spu-palette\|video-navi-pack\)-t,\1,g" \ 189 -e "s,\(audio-mixer\|audio-karaoke\|audio-status\|ca-slot-info\|ca-descr-info\|ca-caps\|ca-msg\|ca-descr\|ca-pid\|dmx-filter\|dmx-caps\|video-system\|video-highlight\|video-spu\|video-spu-palette\|video-navi-pack\)-t,\1,g" \
189 -e "s,DTV-ISDBT-LAYER[A-C],DTV-ISDBT-LAYER,g" \ 190 -e "s,DTV-ISDBT-LAYER[A-C],DTV-ISDBT-LAYER,g" \
190 -e "s,\(define\s\+\)\([A-Z0-9_]\+\)\(\s\+_IO\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \ 191 -e "s,\(define\s\+\)\([A-Z0-9_]\+\)\(\s\+_IO\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
192 -e "s,\(define\s\+\)\(DTV_[A-Z0-9_]\+\)\(\s\+\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
191 -e "s,<link\s\+linkend=\".*\">\(__.*_OLD\)<\/link>,\1,g" \ 193 -e "s,<link\s\+linkend=\".*\">\(__.*_OLD\)<\/link>,\1,g" \
194 -e "s/\(linkend\=\"\)FE_SET_PROPERTY/\1FE_GET_PROPERTY/g" \
195 -e "s,<link\s\+linkend=\".*\">\(DTV_ISDBS_TS_ID_LEGACY\|DTV_MAX_COMMAND\|DTV_IOCTL_MAX_MSGS\)<\/link>,\1,g" \
192 196
193# 197#
194# Media targets and dependencies 198# Media targets and dependencies
195# 199#
196 200
197install_media_images = \ 201install_media_images = \
198 $(Q)-cp $(OBJIMGFILES) $(MEDIA_SRC_DIR)/v4l/*.svg $(MEDIA_OBJ_DIR)/media_api 202 $(Q)-cp $(OBJIMGFILES) $(MEDIA_SRC_DIR)/*.svg $(MEDIA_SRC_DIR)/v4l/*.svg $(MEDIA_OBJ_DIR)/media_api
199 203
200$(MEDIA_OBJ_DIR)/%: $(MEDIA_SRC_DIR)/%.b64 204$(MEDIA_OBJ_DIR)/%: $(MEDIA_SRC_DIR)/%.b64
201 $(Q)base64 -d $< >$@ 205 $(Q)base64 -d $< >$@
@@ -243,9 +247,14 @@ $(MEDIA_OBJ_DIR)/dmx.h.xml: $(srctree)/include/uapi/linux/dvb/dmx.h $(MEDIA_OBJ_
243 @( \ 247 @( \
244 echo "<programlisting>") > $@ 248 echo "<programlisting>") > $@
245 @( \ 249 @( \
250 for ident in $(ENUM_DEFS) ; do \
251 entity=`echo $$ident | tr _ -` ; \
252 r="$$r s/([^\w\-])$$ident([^\w\-])/\1\&$$entity\;\2/g;";\
253 done; \
246 expand --tabs=8 < $< | \ 254 expand --tabs=8 < $< | \
247 sed $(ESCAPE) $(DVB_DOCUMENTED) | \ 255 sed $(ESCAPE) $(DVB_DOCUMENTED) | \
248 sed 's/i\.e\./&ie;/') >> $@ 256 sed 's/i\.e\./&ie;/' | \
257 perl -ne "$$r print $$_;") >> $@
249 @( \ 258 @( \
250 echo "</programlisting>") >> $@ 259 echo "</programlisting>") >> $@
251 260
@@ -254,9 +263,14 @@ $(MEDIA_OBJ_DIR)/frontend.h.xml: $(srctree)/include/uapi/linux/dvb/frontend.h $(
254 @( \ 263 @( \
255 echo "<programlisting>") > $@ 264 echo "<programlisting>") > $@
256 @( \ 265 @( \
266 for ident in $(ENUM_DEFS) ; do \
267 entity=`echo $$ident | tr _ -` ; \
268 r="$$r s/([^\w\-])$$ident([^\w\-])/\1\&$$entity\;\2/g;";\
269 done; \
257 expand --tabs=8 < $< | \ 270 expand --tabs=8 < $< | \
258 sed $(ESCAPE) $(DVB_DOCUMENTED) | \ 271 sed $(ESCAPE) $(DVB_DOCUMENTED) | \
259 sed 's/i\.e\./&ie;/') >> $@ 272 sed 's/i\.e\./&ie;/' | \
273 perl -ne "$$r print $$_;") >> $@
260 @( \ 274 @( \
261 echo "</programlisting>") >> $@ 275 echo "</programlisting>") >> $@
262 276
@@ -298,11 +312,22 @@ $(MEDIA_OBJ_DIR)/media-entities.tmpl: $(MEDIA_OBJ_DIR)/v4l2.xml
298 @( \ 312 @( \
299 echo -e "\n<!-- Ioctls -->") >>$@ 313 echo -e "\n<!-- Ioctls -->") >>$@
300 @( \ 314 @( \
301 for ident in $(IOCTLS) ; do \ 315 for ident in `echo $(IOCTLS) | sed -e "s,VIDIOC_RESERVED,,"`; do\
302 entity=`echo $$ident | tr _ -` ; \ 316 entity=`echo $$ident | tr _ -` ; \
303 id=`grep "<refname>$$ident" $(MEDIA_OBJ_DIR)/vidioc-*.xml $(MEDIA_OBJ_DIR)/media-ioc-*.xml | sed -r s,"^.*/(.*).xml.*","\1",` ; \ 317 id=`grep -e "<refname>$$ident" -e "<section id=\"$$ident\"" $$(find $(MEDIA_SRC_DIR) -name *.xml -type f)| sed -r s,"^.*/(.*).xml.*","\1",` ; \
304 echo "<!ENTITY $$entity \"<link" \ 318 if [ "$$id" != "" ]; then echo "<!ENTITY $$entity \"<link" \
305 "linkend='$$id'><constant>$$ident</constant></link>\">" \ 319 "linkend='$$id'><constant>$$ident</constant></link>\">" \
320 >>$@ ; else \
321 echo "Warning: undocumented ioctl: $$ident. Please document it at the media DocBook!" >&2; \
322 fi; \
323 done)
324 @( \
325 echo -e "\n<!-- Defines -->") >>$@
326 @( \
327 for ident in $(DEFINES) ; do \
328 entity=`echo $$ident | tr _ -` ; \
329 echo "<!ENTITY $$entity \"<link" \
330 "linkend='$$entity'><constant>$$ident</constant></link>\">" \
306 >>$@ ; \ 331 >>$@ ; \
307 done) 332 done)
308 @( \ 333 @( \
@@ -322,6 +347,15 @@ $(MEDIA_OBJ_DIR)/media-entities.tmpl: $(MEDIA_OBJ_DIR)/v4l2.xml
322 "linkend='$$entity'>$$ident</link>\">" >>$@ ; \ 347 "linkend='$$entity'>$$ident</link>\">" >>$@ ; \
323 done) 348 done)
324 @( \ 349 @( \
350 echo -e "\n<!-- Enum definitions -->") >>$@
351 @( \
352 for ident in $(ENUM_DEFS) ; do \
353 entity=`echo $$ident | tr _ -` ; \
354 echo "<!ENTITY $$entity \"<link" \
355 "linkend='$$entity'><constant>$$ident</constant></link>\">" \
356 >>$@ ; \
357 done)
358 @( \
325 echo -e "\n<!-- Structures -->") >>$@ 359 echo -e "\n<!-- Structures -->") >>$@
326 @( \ 360 @( \
327 for ident in $(STRUCTS) ; do \ 361 for ident in $(STRUCTS) ; do \
diff --git a/Documentation/DocBook/media/dvb/audio.xml b/Documentation/DocBook/media/dvb/audio.xml
index a7ea56c71a27..ea56743ddbe7 100644
--- a/Documentation/DocBook/media/dvb/audio.xml
+++ b/Documentation/DocBook/media/dvb/audio.xml
@@ -1,7 +1,7 @@
1<title>DVB Audio Device</title> 1<title>DVB Audio Device</title>
2<para>The DVB audio device controls the MPEG2 audio decoder of the DVB hardware. It 2<para>The DVB audio device controls the MPEG2 audio decoder of the DVB hardware. It
3can be accessed through <emphasis role="tt">/dev/dvb/adapter0/audio0</emphasis>. Data types and and 3can be accessed through <constant>/dev/dvb/adapter?/audio?</constant>. Data types and and
4ioctl definitions can be accessed by including <emphasis role="tt">linux/dvb/audio.h</emphasis> in your 4ioctl definitions can be accessed by including <constant>linux/dvb/audio.h</constant> in your
5application. 5application.
6</para> 6</para>
7<para>Please note that some DVB cards don&#8217;t have their own MPEG decoder, which results in 7<para>Please note that some DVB cards don&#8217;t have their own MPEG decoder, which results in
@@ -32,7 +32,7 @@ typedef enum {
32</programlisting> 32</programlisting>
33<para>AUDIO_SOURCE_DEMUX selects the demultiplexer (fed either by the frontend or the 33<para>AUDIO_SOURCE_DEMUX selects the demultiplexer (fed either by the frontend or the
34DVR device) as the source of the video stream. If AUDIO_SOURCE_MEMORY 34DVR device) as the source of the video stream. If AUDIO_SOURCE_MEMORY
35is selected the stream comes from the application through the <emphasis role="tt">write()</emphasis> system 35is selected the stream comes from the application through the <constant>write()</constant> system
36call. 36call.
37</para> 37</para>
38 38
diff --git a/Documentation/DocBook/media/dvb/ca.xml b/Documentation/DocBook/media/dvb/ca.xml
index 85eaf4fe2931..d0b07e763908 100644
--- a/Documentation/DocBook/media/dvb/ca.xml
+++ b/Documentation/DocBook/media/dvb/ca.xml
@@ -1,7 +1,7 @@
1<title>DVB CA Device</title> 1<title>DVB CA Device</title>
2<para>The DVB CA device controls the conditional access hardware. It can be accessed through 2<para>The DVB CA device controls the conditional access hardware. It can be accessed through
3<emphasis role="tt">/dev/dvb/adapter0/ca0</emphasis>. Data types and and ioctl definitions can be accessed by 3<constant>/dev/dvb/adapter?/ca?</constant>. Data types and and ioctl definitions can be accessed by
4including <emphasis role="tt">linux/dvb/ca.h</emphasis> in your application. 4including <constant>linux/dvb/ca.h</constant> in your application.
5</para> 5</para>
6 6
7<section id="ca_data_types"> 7<section id="ca_data_types">
diff --git a/Documentation/DocBook/media/dvb/demux.xml b/Documentation/DocBook/media/dvb/demux.xml
index c8683d66f059..34f2fb1cd601 100644
--- a/Documentation/DocBook/media/dvb/demux.xml
+++ b/Documentation/DocBook/media/dvb/demux.xml
@@ -1,33 +1,50 @@
1<title>DVB Demux Device</title> 1<title>DVB Demux Device</title>
2 2
3<para>The DVB demux device controls the filters of the DVB hardware/software. It can be 3<para>The DVB demux device controls the filters of the DVB hardware/software. It can be
4accessed through <emphasis role="tt">/dev/adapter0/demux0</emphasis>. Data types and and ioctl definitions can be 4accessed through <constant>/dev/adapter?/demux?</constant>. Data types and and ioctl definitions can be
5accessed by including <emphasis role="tt">linux/dvb/dmx.h</emphasis> in your application. 5accessed by including <constant>linux/dvb/dmx.h</constant> in your application.
6</para> 6</para>
7<section id="dmx_types"> 7<section id="dmx_types">
8<title>Demux Data Types</title> 8<title>Demux Data Types</title>
9 9
10<section id="dmx-output-t"> 10<section id="dmx-output-t">
11<title>dmx_output_t</title> 11<title>Output for the demux</title>
12<programlisting> 12
13typedef enum 13<table pgwide="1" frame="none" id="dmx-output">
14{ 14 <title>enum dmx_output</title>
15 DMX_OUT_DECODER, /&#x22C6; Streaming directly to decoder. &#x22C6;/ 15 <tgroup cols="2">
16 DMX_OUT_TAP, /&#x22C6; Output going to a memory buffer &#x22C6;/ 16 &cs-def;
17 /&#x22C6; (to be retrieved via the read command).&#x22C6;/ 17 <thead>
18 DMX_OUT_TS_TAP, /&#x22C6; Output multiplexed into a new TS &#x22C6;/ 18 <row>
19 /&#x22C6; (to be retrieved by reading from the &#x22C6;/ 19 <entry>ID</entry>
20 /&#x22C6; logical DVR device). &#x22C6;/ 20 <entry>Description</entry>
21 DMX_OUT_TSDEMUX_TAP /&#x22C6; Like TS_TAP but retrieved from the DMX device &#x22C6;/ 21 </row>
22} dmx_output_t; 22 </thead>
23</programlisting> 23 <tbody valign="top">
24<para><emphasis role="tt">DMX_OUT_TAP</emphasis> delivers the stream output to the demux device on which the ioctl is 24 <row>
25called. 25 <entry align="char" id="DMX-OUT-DECODER">DMX_OUT_DECODER</entry>
26</para> 26 <entry>Streaming directly to decoder.</entry>
27<para><emphasis role="tt">DMX_OUT_TS_TAP</emphasis> routes output to the logical DVR device <emphasis role="tt">/dev/dvb/adapter0/dvr0</emphasis>, 27 </row><row>
28which delivers a TS multiplexed from all filters for which <emphasis role="tt">DMX_OUT_TS_TAP</emphasis> was 28 <entry align="char" id="DMX-OUT-TAP">DMX_OUT_TAP</entry>
29specified. 29 <entry>Output going to a memory buffer (to be retrieved via the
30</para> 30 read command). Delivers the stream output to the demux
31 device on which the ioctl is called.</entry>
32 </row><row>
33 <entry align="char" id="DMX-OUT-TS-TAP">DMX_OUT_TS_TAP</entry>
34 <entry>Output multiplexed into a new TS (to be retrieved by
35 reading from the logical DVR device). Routes output to the
36 logical DVR device <constant>/dev/dvb/adapter?/dvr?</constant>,
37 which delivers a TS multiplexed from all filters for which
38 <constant>DMX_OUT_TS_TAP</constant> was specified.</entry>
39 </row><row>
40 <entry align="char" id="DMX-OUT-TSDEMUX-TAP">DMX_OUT_TSDEMUX_TAP</entry>
41 <entry>Like &DMX-OUT-TS-TAP; but retrieved from the DMX
42 device.</entry>
43 </row>
44 </tbody>
45 </tgroup>
46</table>
47
31</section> 48</section>
32 49
33<section id="dmx-input-t"> 50<section id="dmx-input-t">
diff --git a/Documentation/DocBook/media/dvb/dvbapi.xml b/Documentation/DocBook/media/dvb/dvbapi.xml
index 4c15396c67e5..858fd7d17104 100644
--- a/Documentation/DocBook/media/dvb/dvbapi.xml
+++ b/Documentation/DocBook/media/dvb/dvbapi.xml
@@ -28,13 +28,23 @@
28 <holder>Convergence GmbH</holder> 28 <holder>Convergence GmbH</holder>
29</copyright> 29</copyright>
30<copyright> 30<copyright>
31 <year>2009-2014</year> 31 <year>2009-2015</year>
32 <holder>Mauro Carvalho Chehab</holder> 32 <holder>Mauro Carvalho Chehab</holder>
33</copyright> 33</copyright>
34 34
35<revhistory> 35<revhistory>
36<!-- Put document revisions here, newest first. --> 36<!-- Put document revisions here, newest first. -->
37<revision> 37<revision>
38 <revnumber>2.1.0</revnumber>
39 <date>2015-05-29</date>
40 <authorinitials>mcc</authorinitials>
41 <revremark>
42 DocBook improvements and cleanups, in order to document the
43 system calls on a more standard way and provide more description
44 about the current DVB API.
45 </revremark>
46</revision>
47<revision>
38 <revnumber>2.0.4</revnumber> 48 <revnumber>2.0.4</revnumber>
39 <date>2011-05-06</date> 49 <date>2011-05-06</date>
40 <authorinitials>mcc</authorinitials> 50 <authorinitials>mcc</authorinitials>
@@ -95,18 +105,26 @@ Added ISDB-T test originally written by Patrick Boettcher
95 <chapter id="dvb_demux"> 105 <chapter id="dvb_demux">
96 &sub-demux; 106 &sub-demux;
97 </chapter> 107 </chapter>
98 <chapter id="dvb_video">
99 &sub-video;
100 </chapter>
101 <chapter id="dvb_audio">
102 &sub-audio;
103 </chapter>
104 <chapter id="dvb_ca"> 108 <chapter id="dvb_ca">
105 &sub-ca; 109 &sub-ca;
106 </chapter> 110 </chapter>
107 <chapter id="dvb_net"> 111 <chapter id="net">
108 &sub-net; 112 &sub-net;
109 </chapter> 113 </chapter>
114 <chapter id="legacy_dvb_apis">
115 <title>DVB Deprecated APIs</title>
116 <para>The APIs described here are kept only for historical reasons. There's
117 just one driver for a very legacy hardware that uses this API. No
118 modern drivers should use it. Instead, audio and video should be using
119 the V4L2 and ALSA APIs, and the pipelines should be set using the
120 Media Controller API</para>
121 <section id="dvb_video">
122 &sub-video;
123 </section>
124 <section id="dvb_audio">
125 &sub-audio;
126 </section>
127 </chapter>
110 <chapter id="dvb_kdapi"> 128 <chapter id="dvb_kdapi">
111 &sub-kdapi; 129 &sub-kdapi;
112 </chapter> 130 </chapter>
diff --git a/Documentation/DocBook/media/dvb/dvbproperty.xml b/Documentation/DocBook/media/dvb/dvbproperty.xml
index 3018564ddfd9..08227d4e9150 100644
--- a/Documentation/DocBook/media/dvb/dvbproperty.xml
+++ b/Documentation/DocBook/media/dvb/dvbproperty.xml
@@ -1,14 +1,88 @@
1<section id="FE_GET_SET_PROPERTY"> 1<section id="frontend-properties">
2<title><constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant></title> 2<title>DVB Frontend properties</title>
3<para>This section describes the DVB version 5 extension of the DVB-API, also 3<para>Tuning into a Digital TV physical channel and starting decoding it
4called "S2API", as this API were added to provide support for DVB-S2. It was 4 requires changing a set of parameters, in order to control the
5designed to be able to replace the old frontend API. Yet, the DISEQC and 5 tuner, the demodulator, the Linear Low-noise Amplifier (LNA) and to set the
6the capability ioctls weren't implemented yet via the new way.</para> 6 antenna subsystem via Satellite Equipment Control (SEC), on satellite
7<para>The typical usage for the <constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant> 7 systems. The actual parameters are specific to each particular digital
8API is to replace the ioctl's were the <link linkend="dvb-frontend-parameters"> 8 TV standards, and may change as the digital TV specs evolves.</para>
9struct <constant>dvb_frontend_parameters</constant></link> were used.</para> 9<para>In the past, the strategy used was to have a union with the parameters
10 needed to tune for DVB-S, DVB-C, DVB-T and ATSC delivery systems grouped
11 there. The problem is that, as the second generation standards appeared,
12 those structs were not big enough to contain the additional parameters.
13 Also, the union didn't have any space left to be expanded without breaking
14 userspace. So, the decision was to deprecate the legacy union/struct based
15 approach, in favor of a properties set approach.</para>
16
17<para>NOTE: on Linux DVB API version 3, setting a frontend were done via
18 <link linkend="dvb-frontend-parameters">struct <constant>dvb_frontend_parameters</constant></link>.
19 This got replaced on version 5 (also called "S2API", as this API were
20 added originally_enabled to provide support for DVB-S2), because the old
21 API has a very limited support to new standards and new hardware. This
22 section describes the new and recommended way to set the frontend, with
23 suppports all digital TV delivery systems.</para>
24
25<para>Example: with the properties based approach, in order to set the tuner
26 to a DVB-C channel at 651 kHz, modulated with 256-QAM, FEC 3/4 and symbol
27 rate of 5.217 Mbauds, those properties should be sent to
28 <link linkend="FE_GET_PROPERTY"><constant>FE_SET_PROPERTY</constant></link> ioctl:</para>
29 <itemizedlist>
30 <listitem><para>&DTV-DELIVERY-SYSTEM; = SYS_DVBC_ANNEX_A</para></listitem>
31 <listitem><para>&DTV-FREQUENCY; = 651000000</para></listitem>
32 <listitem><para>&DTV-MODULATION; = QAM_256</para></listitem>
33 <listitem><para>&DTV-INVERSION; = INVERSION_AUTO</para></listitem>
34 <listitem><para>&DTV-SYMBOL-RATE; = 5217000</para></listitem>
35 <listitem><para>&DTV-INNER-FEC; = FEC_3_4</para></listitem>
36 <listitem><para>&DTV-TUNE;</para></listitem>
37 </itemizedlist>
38
39<para>The code that would do the above is:</para>
40<programlisting>
41#include &lt;stdio.h&gt;
42#include &lt;fcntl.h&gt;
43#include &lt;sys/ioctl.h&gt;
44#include &lt;linux/dvb/frontend.h&gt;
45
46static struct dtv_property props[] = {
47 { .cmd = DTV_DELIVERY_SYSTEM, .u.data = SYS_DVBC_ANNEX_A },
48 { .cmd = DTV_FREQUENCY, .u.data = 651000000 },
49 { .cmd = DTV_MODULATION, .u.data = QAM_256 },
50 { .cmd = DTV_INVERSION, .u.data = INVERSION_AUTO },
51 { .cmd = DTV_SYMBOL_RATE, .u.data = 5217000 },
52 { .cmd = DTV_INNER_FEC, .u.data = FEC_3_4 },
53 { .cmd = DTV_TUNE }
54};
55
56static struct dtv_properties dtv_prop = {
57 .num = 6, .props = props
58};
59
60int main(void)
61{
62 int fd = open("/dev/dvb/adapter0/frontend0", O_RDWR);
63
64 if (!fd) {
65 perror ("open");
66 return -1;
67 }
68 if (ioctl(fd, FE_SET_PROPERTY, &amp;dtv_prop) == -1) {
69 perror("ioctl");
70 return -1;
71 }
72 printf("Frontend set\n");
73 return 0;
74}
75</programlisting>
76
77<para>NOTE: While it is possible to directly call the Kernel code like the
78 above example, it is strongly recommended to use
79 <ulink url="http://linuxtv.org/docs/libdvbv5/index.html">libdvbv5</ulink>,
80 as it provides abstraction to work with the supported digital TV standards
81 and provides methods for usual operations like program scanning and to
82 read/write channel descriptor files.</para>
83
10<section id="dtv-stats"> 84<section id="dtv-stats">
11<title>DTV stats type</title> 85<title>struct <structname>dtv_stats</structname></title>
12<programlisting> 86<programlisting>
13struct dtv_stats { 87struct dtv_stats {
14 __u8 scale; /* enum fecap_scale_params type */ 88 __u8 scale; /* enum fecap_scale_params type */
@@ -20,19 +94,19 @@ struct dtv_stats {
20</programlisting> 94</programlisting>
21</section> 95</section>
22<section id="dtv-fe-stats"> 96<section id="dtv-fe-stats">
23<title>DTV stats type</title> 97<title>struct <structname>dtv_fe_stats</structname></title>
24<programlisting> 98<programlisting>
25#define MAX_DTV_STATS 4 99#define MAX_DTV_STATS 4
26 100
27struct dtv_fe_stats { 101struct dtv_fe_stats {
28 __u8 len; 102 __u8 len;
29 struct dtv_stats stat[MAX_DTV_STATS]; 103 &dtv-stats; stat[MAX_DTV_STATS];
30} __packed; 104} __packed;
31</programlisting> 105</programlisting>
32</section> 106</section>
33 107
34<section id="dtv-property"> 108<section id="dtv-property">
35<title>DTV property type</title> 109<title>struct <structname>dtv_property</structname></title>
36<programlisting> 110<programlisting>
37/* Reserved fields should be set to 0 */ 111/* Reserved fields should be set to 0 */
38 112
@@ -41,7 +115,7 @@ struct dtv_property {
41 __u32 reserved[3]; 115 __u32 reserved[3];
42 union { 116 union {
43 __u32 data; 117 __u32 data;
44 struct dtv_fe_stats st; 118 &dtv-fe-stats; st;
45 struct { 119 struct {
46 __u8 data[32]; 120 __u8 data[32];
47 __u32 len; 121 __u32 len;
@@ -57,115 +131,19 @@ struct dtv_property {
57</programlisting> 131</programlisting>
58</section> 132</section>
59<section id="dtv-properties"> 133<section id="dtv-properties">
60<title>DTV properties type</title> 134<title>struct <structname>dtv_properties</structname></title>
61<programlisting> 135<programlisting>
62struct dtv_properties { 136struct dtv_properties {
63 __u32 num; 137 __u32 num;
64 struct dtv_property *props; 138 &dtv-property; *props;
65}; 139};
66</programlisting> 140</programlisting>
67</section> 141</section>
68 142
69<section id="FE_GET_PROPERTY">
70<title>FE_GET_PROPERTY</title>
71<para>DESCRIPTION
72</para>
73<informaltable><tgroup cols="1"><tbody><row><entry
74 align="char">
75<para>This ioctl call returns one or more frontend properties. This call only
76 requires read-only access to the device.</para>
77</entry>
78 </row></tbody></tgroup></informaltable>
79<para>SYNOPSIS
80</para>
81<informaltable><tgroup cols="1"><tbody><row><entry
82 align="char">
83<para>int ioctl(int fd, int request = <link linkend="FE_GET_PROPERTY">FE_GET_PROPERTY</link>,
84 dtv_properties &#x22C6;props);</para>
85</entry>
86 </row></tbody></tgroup></informaltable>
87<para>PARAMETERS
88</para>
89<informaltable><tgroup cols="2"><tbody><row><entry align="char">
90<para>int fd</para>
91</entry><entry
92 align="char">
93<para>File descriptor returned by a previous call to open().</para>
94</entry>
95 </row><row><entry
96 align="char">
97<para>int num</para>
98</entry><entry
99 align="char">
100<para>Equals <link linkend="FE_GET_PROPERTY">FE_GET_PROPERTY</link> for this command.</para>
101</entry>
102 </row><row><entry
103 align="char">
104<para>struct dtv_property *props</para>
105</entry><entry
106 align="char">
107<para>Points to the location where the front-end property commands are stored.</para>
108</entry>
109 </row></tbody></tgroup></informaltable>
110&return-value-dvb;
111<informaltable><tgroup cols="2"><tbody><row>
112 <entry align="char"><para>EOPNOTSUPP</para></entry>
113 <entry align="char"><para>Property type not supported.</para></entry>
114 </row></tbody></tgroup></informaltable>
115</section>
116
117<section id="FE_SET_PROPERTY">
118<title>FE_SET_PROPERTY</title>
119<para>DESCRIPTION
120</para>
121<informaltable><tgroup cols="1"><tbody><row><entry
122 align="char">
123<para>This ioctl call sets one or more frontend properties. This call
124 requires read/write access to the device.</para>
125</entry>
126 </row></tbody></tgroup></informaltable>
127<para>SYNOPSIS
128</para>
129<informaltable><tgroup cols="1"><tbody><row><entry
130 align="char">
131<para>int ioctl(int fd, int request = <link linkend="FE_SET_PROPERTY">FE_SET_PROPERTY</link>,
132 dtv_properties &#x22C6;props);</para>
133</entry>
134 </row></tbody></tgroup></informaltable>
135<para>PARAMETERS
136</para>
137<informaltable><tgroup cols="2"><tbody><row><entry align="char">
138<para>int fd</para>
139</entry><entry
140 align="char">
141<para>File descriptor returned by a previous call to open().</para>
142</entry>
143 </row><row><entry
144 align="char">
145<para>int num</para>
146</entry><entry
147 align="char">
148<para>Equals <link linkend="FE_SET_PROPERTY">FE_SET_PROPERTY</link> for this command.</para>
149</entry>
150 </row><row><entry
151 align="char">
152<para>struct dtv_property *props</para>
153</entry><entry
154 align="char">
155<para>Points to the location where the front-end property commands are stored.</para>
156</entry>
157 </row></tbody></tgroup></informaltable>
158&return-value-dvb;
159<informaltable><tgroup cols="2"><tbody><row>
160 <entry align="char"><para>EOPNOTSUPP</para></entry>
161 <entry align="char"><para>Property type not supported.</para></entry>
162 </row></tbody></tgroup></informaltable>
163</section>
164
165<section> 143<section>
166 <title>Property types</title> 144 <title>Property types</title>
167<para> 145<para>
168On <link linkend="FE_GET_PROPERTY">FE_GET_PROPERTY</link>/<link linkend="FE_SET_PROPERTY">FE_SET_PROPERTY</link>, 146On <link linkend="FE_GET_PROPERTY">FE_GET_PROPERTY and FE_SET_PROPERTY</link>,
169the actual action is determined by the dtv_property cmd/data pairs. With one single ioctl, is possible to 147the actual action is determined by the dtv_property cmd/data pairs. With one single ioctl, is possible to
170get/set up to 64 properties. The actual meaning of each property is described on the next sections. 148get/set up to 64 properties. The actual meaning of each property is described on the next sections.
171</para> 149</para>
@@ -193,7 +171,7 @@ get/set up to 64 properties. The actual meaning of each property is described on
193 <para>Central frequency of the channel.</para> 171 <para>Central frequency of the channel.</para>
194 172
195 <para>Notes:</para> 173 <para>Notes:</para>
196 <para>1)For satellital delivery systems, it is measured in kHz. 174 <para>1)For satellite delivery systems, it is measured in kHz.
197 For the other ones, it is measured in Hz.</para> 175 For the other ones, it is measured in Hz.</para>
198 <para>2)For ISDB-T, the channels are usually transmitted with an offset of 143kHz. 176 <para>2)For ISDB-T, the channels are usually transmitted with an offset of 143kHz.
199 E.g. a valid frequency could be 474143 kHz. The stepping is bound to the bandwidth of 177 E.g. a valid frequency could be 474143 kHz. The stepping is bound to the bandwidth of
@@ -205,25 +183,78 @@ get/set up to 64 properties. The actual meaning of each property is described on
205 </section> 183 </section>
206 <section id="DTV-MODULATION"> 184 <section id="DTV-MODULATION">
207 <title><constant>DTV_MODULATION</constant></title> 185 <title><constant>DTV_MODULATION</constant></title>
208<para>Specifies the frontend modulation type for cable and satellite types. The modulation can be one of the types bellow:</para> 186<para>Specifies the frontend modulation type for delivery systems that supports
209<programlisting> 187 more than one modulation type. The modulation can be one of the types
210 typedef enum fe_modulation { 188 defined by &fe-modulation;.</para>
211 QPSK, 189
212 QAM_16, 190
213 QAM_32, 191<section id="fe-modulation-t">
214 QAM_64, 192<title>Modulation property</title>
215 QAM_128, 193
216 QAM_256, 194<para>Most of the digital TV standards currently offers more than one possible
217 QAM_AUTO, 195 modulation (sometimes called as "constellation" on some standards). This
218 VSB_8, 196 enum contains the values used by the Kernel. Please note that not all
219 VSB_16, 197 modulations are supported by a given standard.</para>
220 PSK_8, 198
221 APSK_16, 199<table pgwide="1" frame="none" id="fe-modulation">
222 APSK_32, 200 <title>enum fe_modulation</title>
223 DQPSK, 201 <tgroup cols="2">
224 QAM_4_NR, 202 &cs-def;
225 } fe_modulation_t; 203 <thead>
226</programlisting> 204 <row>
205 <entry>ID</entry>
206 <entry>Description</entry>
207 </row>
208 </thead>
209 <tbody valign="top">
210 <row>
211 <entry id="QPSK"><constant>QPSK</constant></entry>
212 <entry>QPSK modulation</entry>
213 </row><row>
214 <entry id="QAM-16"><constant>QAM_16</constant></entry>
215 <entry>16-QAM modulation</entry>
216 </row><row>
217 <entry id="QAM-32"><constant>QAM_32</constant></entry>
218 <entry>32-QAM modulation</entry>
219 </row><row>
220 <entry id="QAM-64"><constant>QAM_64</constant></entry>
221 <entry>64-QAM modulation</entry>
222 </row><row>
223 <entry id="QAM-128"><constant>QAM_128</constant></entry>
224 <entry>128-QAM modulation</entry>
225 </row><row>
226 <entry id="QAM-256"><constant>QAM_256</constant></entry>
227 <entry>256-QAM modulation</entry>
228 </row><row>
229 <entry id="QAM-AUTO"><constant>QAM_AUTO</constant></entry>
230 <entry>Autodetect QAM modulation</entry>
231 </row><row>
232 <entry id="VSB-8"><constant>VSB_8</constant></entry>
233 <entry>8-VSB modulation</entry>
234 </row><row>
235 <entry id="VSB-16"><constant>VSB_16</constant></entry>
236 <entry>16-VSB modulation</entry>
237 </row><row>
238 <entry id="PSK-8"><constant>PSK_8</constant></entry>
239 <entry>8-PSK modulation</entry>
240 </row><row>
241 <entry id="APSK-16"><constant>APSK_16</constant></entry>
242 <entry>16-APSK modulation</entry>
243 </row><row>
244 <entry id="APSK-32"><constant>APSK_32</constant></entry>
245 <entry>32-APSK modulation</entry>
246 </row><row>
247 <entry id="DQPSK"><constant>DQPSK</constant></entry>
248 <entry>DQPSK modulation</entry>
249 </row><row>
250 <entry id="QAM-4-NR"><constant>QAM_4_NR</constant></entry>
251 <entry>4-QAM-NR modulation</entry>
252 </row>
253 </tbody>
254 </tgroup>
255</table>
256</section>
257
227 </section> 258 </section>
228 <section id="DTV-BANDWIDTH-HZ"> 259 <section id="DTV-BANDWIDTH-HZ">
229 <title><constant>DTV_BANDWIDTH_HZ</constant></title> 260 <title><constant>DTV_BANDWIDTH_HZ</constant></title>
@@ -253,19 +284,45 @@ get/set up to 64 properties. The actual meaning of each property is described on
253 </section> 284 </section>
254 <section id="DTV-INVERSION"> 285 <section id="DTV-INVERSION">
255 <title><constant>DTV_INVERSION</constant></title> 286 <title><constant>DTV_INVERSION</constant></title>
256 <para>The Inversion field can take one of these values: 287
257 </para> 288 <para>Specifies if the frontend should do spectral inversion or not.</para>
258 <programlisting> 289
259 typedef enum fe_spectral_inversion { 290<section id="fe-spectral-inversion-t">
260 INVERSION_OFF, 291<title>enum fe_modulation: Frontend spectral inversion</title>
261 INVERSION_ON, 292
262 INVERSION_AUTO 293<para>This parameter indicates if spectral inversion should be presumed or not.
263 } fe_spectral_inversion_t; 294 In the automatic setting (<constant>INVERSION_AUTO</constant>) the hardware
264 </programlisting> 295 will try to figure out the correct setting by itself. If the hardware
265 <para>It indicates if spectral inversion should be presumed or not. In the automatic setting 296 doesn't support, the DVB core will try to lock at the carrier first with
266 (<constant>INVERSION_AUTO</constant>) the hardware will try to figure out the correct setting by 297 inversion off. If it fails, it will try to enable inversion.
267 itself. 298</para>
268 </para> 299
300<table pgwide="1" frame="none" id="fe-spectral-inversion">
301 <title>enum fe_modulation</title>
302 <tgroup cols="2">
303 &cs-def;
304 <thead>
305 <row>
306 <entry>ID</entry>
307 <entry>Description</entry>
308 </row>
309 </thead>
310 <tbody valign="top">
311 <row>
312 <entry id="INVERSION-OFF"><constant>INVERSION_OFF</constant></entry>
313 <entry>Don't do spectral band inversion.</entry>
314 </row><row>
315 <entry id="INVERSION-ON"><constant>INVERSION_ON</constant></entry>
316 <entry>Do spectral band inversion.</entry>
317 </row><row>
318 <entry id="INVERSION-AUTO"><constant>INVERSION_AUTO</constant></entry>
319 <entry>Autodetect spectral band inversion.</entry>
320 </row>
321 </tbody>
322 </tgroup>
323</table>
324</section>
325
269 </section> 326 </section>
270 <section id="DTV-DISEQC-MASTER"> 327 <section id="DTV-DISEQC-MASTER">
271 <title><constant>DTV_DISEQC_MASTER</constant></title> 328 <title><constant>DTV_DISEQC_MASTER</constant></title>
@@ -279,25 +336,64 @@ get/set up to 64 properties. The actual meaning of each property is described on
279 <title><constant>DTV_INNER_FEC</constant></title> 336 <title><constant>DTV_INNER_FEC</constant></title>
280 <para>Used cable/satellite transmissions. The acceptable values are: 337 <para>Used cable/satellite transmissions. The acceptable values are:
281 </para> 338 </para>
282 <programlisting> 339<section id="fe-code-rate-t">
283typedef enum fe_code_rate { 340<title>enum fe_code_rate: type of the Forward Error Correction.</title>
284 FEC_NONE = 0, 341
285 FEC_1_2, 342<table pgwide="1" frame="none" id="fe-code-rate">
286 FEC_2_3, 343 <title>enum fe_code_rate</title>
287 FEC_3_4, 344 <tgroup cols="2">
288 FEC_4_5, 345 &cs-def;
289 FEC_5_6, 346 <thead>
290 FEC_6_7, 347 <row>
291 FEC_7_8, 348 <entry>ID</entry>
292 FEC_8_9, 349 <entry>Description</entry>
293 FEC_AUTO, 350 </row>
294 FEC_3_5, 351 </thead>
295 FEC_9_10, 352 <tbody valign="top">
296 FEC_2_5, 353 <row>
297} fe_code_rate_t; 354 <entry id="FEC-NONE"><constant>FEC_NONE</constant></entry>
298 </programlisting> 355 <entry>No Forward Error Correction Code</entry>
299 <para>which correspond to error correction rates of 1/2, 2/3, etc., 356 </row><row>
300 no error correction or auto detection.</para> 357 <entry id="FEC-AUTO"><constant>FEC_AUTO</constant></entry>
358 <entry>Autodetect Error Correction Code</entry>
359 </row><row>
360 <entry id="FEC-1-2"><constant>FEC_1_2</constant></entry>
361 <entry>Forward Error Correction Code 1/2</entry>
362 </row><row>
363 <entry id="FEC-2-3"><constant>FEC_2_3</constant></entry>
364 <entry>Forward Error Correction Code 2/3</entry>
365 </row><row>
366 <entry id="FEC-3-4"><constant>FEC_3_4</constant></entry>
367 <entry>Forward Error Correction Code 3/4</entry>
368 </row><row>
369 <entry id="FEC-4-5"><constant>FEC_4_5</constant></entry>
370 <entry>Forward Error Correction Code 4/5</entry>
371 </row><row>
372 <entry id="FEC-5-6"><constant>FEC_5_6</constant></entry>
373 <entry>Forward Error Correction Code 5/6</entry>
374 </row><row>
375 <entry id="FEC-6-7"><constant>FEC_6_7</constant></entry>
376 <entry>Forward Error Correction Code 6/7</entry>
377 </row><row>
378 <entry id="FEC-7-8"><constant>FEC_7_8</constant></entry>
379 <entry>Forward Error Correction Code 7/8</entry>
380 </row><row>
381 <entry id="FEC-8-9"><constant>FEC_8_9</constant></entry>
382 <entry>Forward Error Correction Code 8/9</entry>
383 </row><row>
384 <entry id="FEC-9-10"><constant>FEC_9_10</constant></entry>
385 <entry>Forward Error Correction Code 9/10</entry>
386 </row><row>
387 <entry id="FEC-2-5"><constant>FEC_2_5</constant></entry>
388 <entry>Forward Error Correction Code 2/5</entry>
389 </row><row>
390 <entry id="FEC-3-5"><constant>FEC_3_5</constant></entry>
391 <entry>Forward Error Correction Code 3/5</entry>
392 </row>
393 </tbody>
394 </tgroup>
395</table>
396</section>
301 </section> 397 </section>
302 <section id="DTV-VOLTAGE"> 398 <section id="DTV-VOLTAGE">
303 <title><constant>DTV_VOLTAGE</constant></title> 399 <title><constant>DTV_VOLTAGE</constant></title>
@@ -305,12 +401,31 @@ typedef enum fe_code_rate {
305 the polarzation (horizontal/vertical). When using DiSEqC epuipment this 401 the polarzation (horizontal/vertical). When using DiSEqC epuipment this
306 voltage has to be switched consistently to the DiSEqC commands as 402 voltage has to be switched consistently to the DiSEqC commands as
307 described in the DiSEqC spec.</para> 403 described in the DiSEqC spec.</para>
308 <programlisting> 404
309 typedef enum fe_sec_voltage { 405<table pgwide="1" frame="none" id="fe-sec-voltage">
310 SEC_VOLTAGE_13, 406 <title id="fe-sec-voltage-t">enum fe_sec_voltage</title>
311 SEC_VOLTAGE_18 407 <tgroup cols="2">
312 } fe_sec_voltage_t; 408 &cs-def;
313 </programlisting> 409 <thead>
410 <row>
411 <entry>ID</entry>
412 <entry>Description</entry>
413 </row>
414 </thead>
415 <tbody valign="top">
416 <row>
417 <entry align="char" id="SEC-VOLTAGE-13"><constant>SEC_VOLTAGE_13</constant></entry>
418 <entry align="char">Set DC voltage level to 13V</entry>
419 </row><row>
420 <entry align="char" id="SEC-VOLTAGE-18"><constant>SEC_VOLTAGE_18</constant></entry>
421 <entry align="char">Set DC voltage level to 18V</entry>
422 </row><row>
423 <entry align="char" id="SEC-VOLTAGE-OFF"><constant>SEC_VOLTAGE_OFF</constant></entry>
424 <entry align="char">Don't send any voltage to the antenna</entry>
425 </row>
426 </tbody>
427 </tgroup>
428</table>
314 </section> 429 </section>
315 <section id="DTV-TONE"> 430 <section id="DTV-TONE">
316 <title><constant>DTV_TONE</constant></title> 431 <title><constant>DTV_TONE</constant></title>
@@ -321,13 +436,30 @@ typedef enum fe_code_rate {
321 <para>Sets DVB-S2 pilot</para> 436 <para>Sets DVB-S2 pilot</para>
322 <section id="fe-pilot-t"> 437 <section id="fe-pilot-t">
323 <title>fe_pilot type</title> 438 <title>fe_pilot type</title>
324 <programlisting> 439<table pgwide="1" frame="none" id="fe-pilot">
325typedef enum fe_pilot { 440 <title>enum fe_pilot</title>
326 PILOT_ON, 441 <tgroup cols="2">
327 PILOT_OFF, 442 &cs-def;
328 PILOT_AUTO, 443 <thead>
329} fe_pilot_t; 444 <row>
330 </programlisting> 445 <entry>ID</entry>
446 <entry>Description</entry>
447 </row>
448 </thead>
449 <tbody valign="top">
450 <row>
451 <entry align="char" id="PILOT-ON"><constant>PILOT_ON</constant></entry>
452 <entry align="char">Pilot tones enabled</entry>
453 </row><row>
454 <entry align="char" id="PILOT-OFF"><constant>PILOT_OFF</constant></entry>
455 <entry align="char">Pilot tones disabled</entry>
456 </row><row>
457 <entry align="char" id="PILOT-AUTO"><constant>PILOT_AUTO</constant></entry>
458 <entry align="char">Autodetect pilot tones</entry>
459 </row>
460 </tbody>
461 </tgroup>
462</table>
331 </section> 463 </section>
332 </section> 464 </section>
333 <section id="DTV-ROLLOFF"> 465 <section id="DTV-ROLLOFF">
@@ -336,14 +468,33 @@ typedef enum fe_pilot {
336 468
337 <section id="fe-rolloff-t"> 469 <section id="fe-rolloff-t">
338 <title>fe_rolloff type</title> 470 <title>fe_rolloff type</title>
339 <programlisting> 471<table pgwide="1" frame="none" id="fe-rolloff">
340typedef enum fe_rolloff { 472 <title>enum fe_rolloff</title>
341 ROLLOFF_35, /* Implied value in DVB-S, default for DVB-S2 */ 473 <tgroup cols="2">
342 ROLLOFF_20, 474 &cs-def;
343 ROLLOFF_25, 475 <thead>
344 ROLLOFF_AUTO, 476 <row>
345} fe_rolloff_t; 477 <entry>ID</entry>
346 </programlisting> 478 <entry>Description</entry>
479 </row>
480 </thead>
481 <tbody valign="top">
482 <row>
483 <entry align="char" id="ROLLOFF-35"><constant>ROLLOFF_35</constant></entry>
484 <entry align="char">Roloff factor: &alpha;=35%</entry>
485 </row><row>
486 <entry align="char" id="ROLLOFF-20"><constant>ROLLOFF_20</constant></entry>
487 <entry align="char">Roloff factor: &alpha;=20%</entry>
488 </row><row>
489 <entry align="char" id="ROLLOFF-25"><constant>ROLLOFF_25</constant></entry>
490 <entry align="char">Roloff factor: &alpha;=25%</entry>
491 </row><row>
492 <entry align="char" id="ROLLOFF-AUTO"><constant>ROLLOFF_AUTO</constant></entry>
493 <entry align="char">Auto-detect the roloff factor.</entry>
494 </row>
495 </tbody>
496 </tgroup>
497</table>
347 </section> 498 </section>
348 </section> 499 </section>
349 <section id="DTV-DISEQC-SLAVE-REPLY"> 500 <section id="DTV-DISEQC-SLAVE-REPLY">
@@ -364,31 +515,82 @@ typedef enum fe_rolloff {
364 <section id="fe-delivery-system-t"> 515 <section id="fe-delivery-system-t">
365 <title>fe_delivery_system type</title> 516 <title>fe_delivery_system type</title>
366 <para>Possible values: </para> 517 <para>Possible values: </para>
367<programlisting>
368 518
369typedef enum fe_delivery_system { 519<table pgwide="1" frame="none" id="fe-delivery-system">
370 SYS_UNDEFINED, 520 <title>enum fe_delivery_system</title>
371 SYS_DVBC_ANNEX_A, 521 <tgroup cols="2">
372 SYS_DVBC_ANNEX_B, 522 &cs-def;
373 SYS_DVBT, 523 <thead>
374 SYS_DSS, 524 <row>
375 SYS_DVBS, 525 <entry>ID</entry>
376 SYS_DVBS2, 526 <entry>Description</entry>
377 SYS_DVBH, 527 </row>
378 SYS_ISDBT, 528 </thead>
379 SYS_ISDBS, 529 <tbody valign="top">
380 SYS_ISDBC, 530 <row>
381 SYS_ATSC, 531 <entry id="SYS-UNDEFINED"><constant>SYS_UNDEFINED</constant></entry>
382 SYS_ATSCMH, 532 <entry>Undefined standard. Generally, indicates an error</entry>
383 SYS_DTMB, 533 </row><row>
384 SYS_CMMB, 534 <entry id="SYS-DVBC-ANNEX-A"><constant>SYS_DVBC_ANNEX_A</constant></entry>
385 SYS_DAB, 535 <entry>Cable TV: DVB-C following ITU-T J.83 Annex A spec</entry>
386 SYS_DVBT2, 536 </row><row>
387 SYS_TURBO, 537 <entry id="SYS-DVBC-ANNEX-B"><constant>SYS_DVBC_ANNEX_B</constant></entry>
388 SYS_DVBC_ANNEX_C, 538 <entry>Cable TV: DVB-C following ITU-T J.83 Annex B spec (ClearQAM)</entry>
389} fe_delivery_system_t; 539 </row><row>
390</programlisting> 540 <entry id="SYS-DVBC-ANNEX-C"><constant>SYS_DVBC_ANNEX_C</constant></entry>
391 </section> 541 <entry>Cable TV: DVB-C following ITU-T J.83 Annex C spec</entry>
542 </row><row>
543 <entry id="SYS-ISDBC"><constant>SYS_ISDBC</constant></entry>
544 <entry>Cable TV: ISDB-C (no drivers yet)</entry>
545 </row><row>
546 <entry id="SYS-DVBT"><constant>SYS_DVBT</constant></entry>
547 <entry>Terrestral TV: DVB-T</entry>
548 </row><row>
549 <entry id="SYS-DVBT2"><constant>SYS_DVBT2</constant></entry>
550 <entry>Terrestral TV: DVB-T2</entry>
551 </row><row>
552 <entry id="SYS-ISDBT"><constant>SYS_ISDBT</constant></entry>
553 <entry>Terrestral TV: ISDB-T</entry>
554 </row><row>
555 <entry id="SYS-ATSC"><constant>SYS_ATSC</constant></entry>
556 <entry>Terrestral TV: ATSC</entry>
557 </row><row>
558 <entry id="SYS-ATSCMH"><constant>SYS_ATSCMH</constant></entry>
559 <entry>Terrestral TV (mobile): ATSC-M/H</entry>
560 </row><row>
561 <entry id="SYS-DTMB"><constant>SYS_DTMB</constant></entry>
562 <entry>Terrestrial TV: DTMB</entry>
563 </row><row>
564 <entry id="SYS-DVBS"><constant>SYS_DVBS</constant></entry>
565 <entry>Satellite TV: DVB-S</entry>
566 </row><row>
567 <entry id="SYS-DVBS2"><constant>SYS_DVBS2</constant></entry>
568 <entry>Satellite TV: DVB-S2</entry>
569 </row><row>
570 <entry id="SYS-TURBO"><constant>SYS_TURBO</constant></entry>
571 <entry>Satellite TV: DVB-S Turbo</entry>
572 </row><row>
573 <entry id="SYS-ISDBS"><constant>SYS_ISDBS</constant></entry>
574 <entry>Satellite TV: ISDB-S</entry>
575 </row><row>
576 <entry id="SYS-DAB"><constant>SYS_DAB</constant></entry>
577 <entry>Digital audio: DAB (not fully supported)</entry>
578 </row><row>
579 <entry id="SYS-DSS"><constant>SYS_DSS</constant></entry>
580 <entry>Satellite TV:"DSS (not fully supported)</entry>
581 </row><row>
582 <entry id="SYS-CMMB"><constant>SYS_CMMB</constant></entry>
583 <entry>Terrestral TV (mobile):CMMB (not fully supported)</entry>
584 </row><row>
585 <entry id="SYS-DVBH"><constant>SYS_DVBH</constant></entry>
586 <entry>Terrestral TV (mobile): DVB-H (standard deprecated)</entry>
587 </row>
588 </tbody>
589 </tgroup>
590</table>
591
592
593</section>
392 </section> 594 </section>
393 <section id="DTV-ISDBT-PARTIAL-RECEPTION"> 595 <section id="DTV-ISDBT-PARTIAL-RECEPTION">
394 <title><constant>DTV_ISDBT_PARTIAL_RECEPTION</constant></title> 596 <title><constant>DTV_ISDBT_PARTIAL_RECEPTION</constant></title>
@@ -630,114 +832,177 @@ typedef enum fe_delivery_system {
630 </section> 832 </section>
631 <section id="DTV-ATSCMH-RS-FRAME-MODE"> 833 <section id="DTV-ATSCMH-RS-FRAME-MODE">
632 <title><constant>DTV_ATSCMH_RS_FRAME_MODE</constant></title> 834 <title><constant>DTV_ATSCMH_RS_FRAME_MODE</constant></title>
633 <para>RS frame mode.</para> 835 <para>Reed Solomon (RS) frame mode.</para>
634 <para>Possible values are:</para> 836 <para>Possible values are:</para>
635 <para id="atscmh-rs-frame-mode"> 837<table pgwide="1" frame="none" id="atscmh-rs-frame-mode">
636<programlisting> 838 <title>enum atscmh_rs_frame_mode</title>
637typedef enum atscmh_rs_frame_mode { 839 <tgroup cols="2">
638 ATSCMH_RSFRAME_PRI_ONLY = 0, 840 &cs-def;
639 ATSCMH_RSFRAME_PRI_SEC = 1, 841 <thead>
640} atscmh_rs_frame_mode_t; 842 <row>
641</programlisting> 843 <entry>ID</entry>
642 </para> 844 <entry>Description</entry>
845 </row>
846 </thead>
847 <tbody valign="top">
848 <row>
849 <entry id="ATSCMH-RSFRAME-PRI-ONLY"><constant>ATSCMH_RSFRAME_PRI_ONLY</constant></entry>
850 <entry>Single Frame: There is only a primary RS Frame for all
851 Group Regions.</entry>
852 </row><row>
853 <entry id="ATSCMH-RSFRAME-PRI-SEC"><constant>ATSCMH_RSFRAME_PRI_SEC</constant></entry>
854 <entry>Dual Frame: There are two separate RS Frames: Primary RS
855 Frame for Group Region A and B and Secondary RS Frame for Group
856 Region C and D.</entry>
857 </row>
858 </tbody>
859 </tgroup>
860</table>
643 </section> 861 </section>
644 <section id="DTV-ATSCMH-RS-FRAME-ENSEMBLE"> 862 <section id="DTV-ATSCMH-RS-FRAME-ENSEMBLE">
645 <title><constant>DTV_ATSCMH_RS_FRAME_ENSEMBLE</constant></title> 863 <title><constant>DTV_ATSCMH_RS_FRAME_ENSEMBLE</constant></title>
646 <para>RS frame ensemble.</para> 864 <para>Reed Solomon(RS) frame ensemble.</para>
647 <para>Possible values are:</para> 865 <para>Possible values are:</para>
648 <para id="atscmh-rs-frame-ensemble"> 866<table pgwide="1" frame="none" id="atscmh-rs-frame-ensemble">
649<programlisting> 867 <title>enum atscmh_rs_frame_ensemble</title>
650typedef enum atscmh_rs_frame_ensemble { 868 <tgroup cols="2">
651 ATSCMH_RSFRAME_ENS_PRI = 0, 869 &cs-def;
652 ATSCMH_RSFRAME_ENS_SEC = 1, 870 <thead>
653} atscmh_rs_frame_ensemble_t; 871 <row>
654</programlisting> 872 <entry>ID</entry>
655 </para> 873 <entry>Description</entry>
874 </row>
875 </thead>
876 <tbody valign="top">
877 <row>
878 <entry id="ATSCMH-RSFRAME-ENS-PRI"><constant>ATSCMH_RSFRAME_ENS_PRI</constant></entry>
879 <entry>Primary Ensemble.</entry>
880 </row><row>
881 <entry id="ATSCMH-RSFRAME-ENS-SEC"><constant>AATSCMH_RSFRAME_PRI_SEC</constant></entry>
882 <entry>Secondary Ensemble.</entry>
883 </row><row>
884 <entry id="ATSCMH-RSFRAME-RES"><constant>AATSCMH_RSFRAME_RES</constant></entry>
885 <entry>Reserved. Shouldn't be used.</entry>
886 </row>
887 </tbody>
888 </tgroup>
889</table>
656 </section> 890 </section>
657 <section id="DTV-ATSCMH-RS-CODE-MODE-PRI"> 891 <section id="DTV-ATSCMH-RS-CODE-MODE-PRI">
658 <title><constant>DTV_ATSCMH_RS_CODE_MODE_PRI</constant></title> 892 <title><constant>DTV_ATSCMH_RS_CODE_MODE_PRI</constant></title>
659 <para>RS code mode (primary).</para> 893 <para>Reed Solomon (RS) code mode (primary).</para>
660 <para>Possible values are:</para> 894 <para>Possible values are:</para>
661 <para id="atscmh-rs-code-mode"> 895<table pgwide="1" frame="none" id="atscmh-rs-code-mode">
662<programlisting> 896 <title>enum atscmh_rs_code_mode</title>
663typedef enum atscmh_rs_code_mode { 897 <tgroup cols="2">
664 ATSCMH_RSCODE_211_187 = 0, 898 &cs-def;
665 ATSCMH_RSCODE_223_187 = 1, 899 <thead>
666 ATSCMH_RSCODE_235_187 = 2, 900 <row>
667} atscmh_rs_code_mode_t; 901 <entry>ID</entry>
668</programlisting> 902 <entry>Description</entry>
669 </para> 903 </row>
904 </thead>
905 <tbody valign="top">
906 <row>
907 <entry id="ATSCMH-RSCODE-211-187"><constant>ATSCMH_RSCODE_211_187</constant></entry>
908 <entry>Reed Solomon code (211,187).</entry>
909 </row><row>
910 <entry id="ATSCMH-RSCODE-223-187"><constant>ATSCMH_RSCODE_223_187</constant></entry>
911 <entry>Reed Solomon code (223,187).</entry>
912 </row><row>
913 <entry id="ATSCMH-RSCODE-235-187"><constant>ATSCMH_RSCODE_235_187</constant></entry>
914 <entry>Reed Solomon code (235,187).</entry>
915 </row><row>
916 <entry id="ATSCMH-RSCODE-RES"><constant>ATSCMH_RSCODE_RES</constant></entry>
917 <entry>Reserved. Shouldn't be used.</entry>
918 </row>
919 </tbody>
920 </tgroup>
921</table>
670 </section> 922 </section>
671 <section id="DTV-ATSCMH-RS-CODE-MODE-SEC"> 923 <section id="DTV-ATSCMH-RS-CODE-MODE-SEC">
672 <title><constant>DTV_ATSCMH_RS_CODE_MODE_SEC</constant></title> 924 <title><constant>DTV_ATSCMH_RS_CODE_MODE_SEC</constant></title>
673 <para>RS code mode (secondary).</para> 925 <para>Reed Solomon (RS) code mode (secondary).</para>
674 <para>Possible values are:</para> 926 <para>Possible values are the same as documented on
675<programlisting> 927 &atscmh-rs-code-mode;:</para>
676typedef enum atscmh_rs_code_mode {
677 ATSCMH_RSCODE_211_187 = 0,
678 ATSCMH_RSCODE_223_187 = 1,
679 ATSCMH_RSCODE_235_187 = 2,
680} atscmh_rs_code_mode_t;
681</programlisting>
682 </section> 928 </section>
683 <section id="DTV-ATSCMH-SCCC-BLOCK-MODE"> 929 <section id="DTV-ATSCMH-SCCC-BLOCK-MODE">
684 <title><constant>DTV_ATSCMH_SCCC_BLOCK_MODE</constant></title> 930 <title><constant>DTV_ATSCMH_SCCC_BLOCK_MODE</constant></title>
685 <para>Series Concatenated Convolutional Code Block Mode.</para> 931 <para>Series Concatenated Convolutional Code Block Mode.</para>
686 <para>Possible values are:</para> 932 <para>Possible values are:</para>
687 <para id="atscmh-sccc-block-mode"> 933<table pgwide="1" frame="none" id="atscmh-sccc-block-mode">
688<programlisting> 934 <title>enum atscmh_scc_block_mode</title>
689typedef enum atscmh_sccc_block_mode { 935 <tgroup cols="2">
690 ATSCMH_SCCC_BLK_SEP = 0, 936 &cs-def;
691 ATSCMH_SCCC_BLK_COMB = 1, 937 <thead>
692} atscmh_sccc_block_mode_t; 938 <row>
693</programlisting> 939 <entry>ID</entry>
694 </para> 940 <entry>Description</entry>
941 </row>
942 </thead>
943 <tbody valign="top">
944 <row>
945 <entry id="ATSCMH-SCCC-BLK-SEP"><constant>ATSCMH_SCCC_BLK_SEP</constant></entry>
946 <entry>Separate SCCC: the SCCC outer code mode shall be set independently
947 for each Group Region (A, B, C, D)</entry>
948 </row><row>
949 <entry id="ATSCMH-SCCC-BLK-COMB"><constant>ATSCMH_SCCC_BLK_COMB</constant></entry>
950 <entry>Combined SCCC: all four Regions shall have the same SCCC outer
951 code mode.</entry>
952 </row><row>
953 <entry id="ATSCMH-SCCC-BLK-RES"><constant>ATSCMH_SCCC_BLK_RES</constant></entry>
954 <entry>Reserved. Shouldn't be used.</entry>
955 </row>
956 </tbody>
957 </tgroup>
958</table>
695 </section> 959 </section>
696 <section id="DTV-ATSCMH-SCCC-CODE-MODE-A"> 960 <section id="DTV-ATSCMH-SCCC-CODE-MODE-A">
697 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_A</constant></title> 961 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_A</constant></title>
698 <para>Series Concatenated Convolutional Code Rate.</para> 962 <para>Series Concatenated Convolutional Code Rate.</para>
699 <para>Possible values are:</para> 963 <para>Possible values are:</para>
700 <para id="atscmh-sccc-code-mode"> 964<table pgwide="1" frame="none" id="atscmh-sccc-code-mode">
701<programlisting> 965 <title>enum atscmh_sccc_code_mode</title>
702typedef enum atscmh_sccc_code_mode { 966 <tgroup cols="2">
703 ATSCMH_SCCC_CODE_HLF = 0, 967 &cs-def;
704 ATSCMH_SCCC_CODE_QTR = 1, 968 <thead>
705} atscmh_sccc_code_mode_t; 969 <row>
706</programlisting> 970 <entry>ID</entry>
707 </para> 971 <entry>Description</entry>
972 </row>
973 </thead>
974 <tbody valign="top">
975 <row>
976 <entry id="ATSCMH-SCCC-CODE-HLF"><constant>ATSCMH_SCCC_CODE_HLF</constant></entry>
977 <entry>The outer code rate of a SCCC Block is 1/2 rate.</entry>
978 </row><row>
979 <entry id="ATSCMH-SCCC-CODE-QTR"><constant>ATSCMH_SCCC_CODE_QTR</constant></entry>
980 <entry>The outer code rate of a SCCC Block is 1/4 rate.</entry>
981 </row><row>
982 <entry id="ATSCMH-SCCC-CODE-RES"><constant>ATSCMH_SCCC_CODE_RES</constant></entry>
983 <entry>to be documented.</entry>
984 </row>
985 </tbody>
986 </tgroup>
987</table>
708 </section> 988 </section>
709 <section id="DTV-ATSCMH-SCCC-CODE-MODE-B"> 989 <section id="DTV-ATSCMH-SCCC-CODE-MODE-B">
710 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_B</constant></title> 990 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_B</constant></title>
711 <para>Series Concatenated Convolutional Code Rate.</para> 991 <para>Series Concatenated Convolutional Code Rate.</para>
712 <para>Possible values are:</para> 992 <para>Possible values are the same as documented on
713<programlisting> 993 &atscmh-sccc-code-mode;.</para>
714typedef enum atscmh_sccc_code_mode {
715 ATSCMH_SCCC_CODE_HLF = 0,
716 ATSCMH_SCCC_CODE_QTR = 1,
717} atscmh_sccc_code_mode_t;
718</programlisting>
719 </section> 994 </section>
720 <section id="DTV-ATSCMH-SCCC-CODE-MODE-C"> 995 <section id="DTV-ATSCMH-SCCC-CODE-MODE-C">
721 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_C</constant></title> 996 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_C</constant></title>
722 <para>Series Concatenated Convolutional Code Rate.</para> 997 <para>Series Concatenated Convolutional Code Rate.</para>
723 <para>Possible values are:</para> 998 <para>Possible values are the same as documented on
724<programlisting> 999 &atscmh-sccc-code-mode;.</para>
725typedef enum atscmh_sccc_code_mode {
726 ATSCMH_SCCC_CODE_HLF = 0,
727 ATSCMH_SCCC_CODE_QTR = 1,
728} atscmh_sccc_code_mode_t;
729</programlisting>
730 </section> 1000 </section>
731 <section id="DTV-ATSCMH-SCCC-CODE-MODE-D"> 1001 <section id="DTV-ATSCMH-SCCC-CODE-MODE-D">
732 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_D</constant></title> 1002 <title><constant>DTV_ATSCMH_SCCC_CODE_MODE_D</constant></title>
733 <para>Series Concatenated Convolutional Code Rate.</para> 1003 <para>Series Concatenated Convolutional Code Rate.</para>
734 <para>Possible values are:</para> 1004 <para>Possible values are the same as documented on
735<programlisting> 1005 &atscmh-sccc-code-mode;.</para>
736typedef enum atscmh_sccc_code_mode {
737 ATSCMH_SCCC_CODE_HLF = 0,
738 ATSCMH_SCCC_CODE_QTR = 1,
739} atscmh_sccc_code_mode_t;
740</programlisting>
741 </section> 1006 </section>
742 </section> 1007 </section>
743 <section id="DTV-API-VERSION"> 1008 <section id="DTV-API-VERSION">
@@ -746,65 +1011,74 @@ typedef enum atscmh_sccc_code_mode {
746 </section> 1011 </section>
747 <section id="DTV-CODE-RATE-HP"> 1012 <section id="DTV-CODE-RATE-HP">
748 <title><constant>DTV_CODE_RATE_HP</constant></title> 1013 <title><constant>DTV_CODE_RATE_HP</constant></title>
749 <para>Used on terrestrial transmissions. The acceptable values are: 1014 <para>Used on terrestrial transmissions. The acceptable values are
1015 the ones described at &fe-transmit-mode-t;.
750 </para> 1016 </para>
751 <programlisting>
752typedef enum fe_code_rate {
753 FEC_NONE = 0,
754 FEC_1_2,
755 FEC_2_3,
756 FEC_3_4,
757 FEC_4_5,
758 FEC_5_6,
759 FEC_6_7,
760 FEC_7_8,
761 FEC_8_9,
762 FEC_AUTO,
763 FEC_3_5,
764 FEC_9_10,
765} fe_code_rate_t;
766 </programlisting>
767 </section> 1017 </section>
768 <section id="DTV-CODE-RATE-LP"> 1018 <section id="DTV-CODE-RATE-LP">
769 <title><constant>DTV_CODE_RATE_LP</constant></title> 1019 <title><constant>DTV_CODE_RATE_LP</constant></title>
770 <para>Used on terrestrial transmissions. The acceptable values are: 1020 <para>Used on terrestrial transmissions. The acceptable values are
1021 the ones described at &fe-transmit-mode-t;.
771 </para> 1022 </para>
772 <programlisting> 1023
773typedef enum fe_code_rate {
774 FEC_NONE = 0,
775 FEC_1_2,
776 FEC_2_3,
777 FEC_3_4,
778 FEC_4_5,
779 FEC_5_6,
780 FEC_6_7,
781 FEC_7_8,
782 FEC_8_9,
783 FEC_AUTO,
784 FEC_3_5,
785 FEC_9_10,
786} fe_code_rate_t;
787 </programlisting>
788 </section> 1024 </section>
1025
789 <section id="DTV-GUARD-INTERVAL"> 1026 <section id="DTV-GUARD-INTERVAL">
790 <title><constant>DTV_GUARD_INTERVAL</constant></title> 1027 <title><constant>DTV_GUARD_INTERVAL</constant></title>
791 1028
792 <para>Possible values are:</para> 1029 <para>Possible values are:</para>
793<programlisting> 1030
794typedef enum fe_guard_interval { 1031<section id="fe-guard-interval-t">
795 GUARD_INTERVAL_1_32, 1032<title>Modulation guard interval</title>
796 GUARD_INTERVAL_1_16, 1033
797 GUARD_INTERVAL_1_8, 1034<table pgwide="1" frame="none" id="fe-guard-interval">
798 GUARD_INTERVAL_1_4, 1035 <title>enum fe_guard_interval</title>
799 GUARD_INTERVAL_AUTO, 1036 <tgroup cols="2">
800 GUARD_INTERVAL_1_128, 1037 &cs-def;
801 GUARD_INTERVAL_19_128, 1038 <thead>
802 GUARD_INTERVAL_19_256, 1039 <row>
803 GUARD_INTERVAL_PN420, 1040 <entry>ID</entry>
804 GUARD_INTERVAL_PN595, 1041 <entry>Description</entry>
805 GUARD_INTERVAL_PN945, 1042 </row>
806} fe_guard_interval_t; 1043 </thead>
807</programlisting> 1044 <tbody valign="top">
1045 <row>
1046 <entry id="GUARD-INTERVAL-AUTO"><constant>GUARD_INTERVAL_AUTO</constant></entry>
1047 <entry>Autodetect the guard interval</entry>
1048 </row><row>
1049 <entry id="GUARD-INTERVAL-1-128"><constant>GUARD_INTERVAL_1_128</constant></entry>
1050 <entry>Guard interval 1/128</entry>
1051 </row><row>
1052 <entry id="GUARD-INTERVAL-1-32"><constant>GUARD_INTERVAL_1_32</constant></entry>
1053 <entry>Guard interval 1/32</entry>
1054 </row><row>
1055 <entry id="GUARD-INTERVAL-1-16"><constant>GUARD_INTERVAL_1_16</constant></entry>
1056 <entry>Guard interval 1/16</entry>
1057 </row><row>
1058 <entry id="GUARD-INTERVAL-1-8"><constant>GUARD_INTERVAL_1_8</constant></entry>
1059 <entry>Guard interval 1/8</entry>
1060 </row><row>
1061 <entry id="GUARD-INTERVAL-1-4"><constant>GUARD_INTERVAL_1_4</constant></entry>
1062 <entry>Guard interval 1/4</entry>
1063 </row><row>
1064 <entry id="GUARD-INTERVAL-19-128"><constant>GUARD_INTERVAL_19_128</constant></entry>
1065 <entry>Guard interval 19/128</entry>
1066 </row><row>
1067 <entry id="GUARD-INTERVAL-19-256"><constant>GUARD_INTERVAL_19_256</constant></entry>
1068 <entry>Guard interval 19/256</entry>
1069 </row><row>
1070 <entry id="GUARD-INTERVAL-PN420"><constant>GUARD_INTERVAL_PN420</constant></entry>
1071 <entry>PN length 420 (1/4)</entry>
1072 </row><row>
1073 <entry id="GUARD-INTERVAL-PN595"><constant>GUARD_INTERVAL_PN595</constant></entry>
1074 <entry>PN length 595 (1/6)</entry>
1075 </row><row>
1076 <entry id="GUARD-INTERVAL-PN945"><constant>GUARD_INTERVAL_PN945</constant></entry>
1077 <entry>PN length 945 (1/9)</entry>
1078 </row>
1079 </tbody>
1080 </tgroup>
1081</table>
808 1082
809 <para>Notes:</para> 1083 <para>Notes:</para>
810 <para>1) If <constant>DTV_GUARD_INTERVAL</constant> is set the <constant>GUARD_INTERVAL_AUTO</constant> the hardware will 1084 <para>1) If <constant>DTV_GUARD_INTERVAL</constant> is set the <constant>GUARD_INTERVAL_AUTO</constant> the hardware will
@@ -812,26 +1086,64 @@ typedef enum fe_guard_interval {
812 in the missing parameters.</para> 1086 in the missing parameters.</para>
813 <para>2) Intervals 1/128, 19/128 and 19/256 are used only for DVB-T2 at present</para> 1087 <para>2) Intervals 1/128, 19/128 and 19/256 are used only for DVB-T2 at present</para>
814 <para>3) DTMB specifies PN420, PN595 and PN945.</para> 1088 <para>3) DTMB specifies PN420, PN595 and PN945.</para>
1089</section>
815 </section> 1090 </section>
816 <section id="DTV-TRANSMISSION-MODE"> 1091 <section id="DTV-TRANSMISSION-MODE">
817 <title><constant>DTV_TRANSMISSION_MODE</constant></title> 1092 <title><constant>DTV_TRANSMISSION_MODE</constant></title>
818 1093
819 <para>Specifies the number of carriers used by the standard</para> 1094 <para>Specifies the number of carriers used by the standard.
1095 This is used only on OFTM-based standards, e. g.
1096 DVB-T/T2, ISDB-T, DTMB</para>
1097
1098<section id="fe-transmit-mode-t">
1099<title>enum fe_transmit_mode: Number of carriers per channel</title>
1100
1101<table pgwide="1" frame="none" id="fe-transmit-mode">
1102 <title>enum fe_transmit_mode</title>
1103 <tgroup cols="2">
1104 &cs-def;
1105 <thead>
1106 <row>
1107 <entry>ID</entry>
1108 <entry>Description</entry>
1109 </row>
1110 </thead>
1111 <tbody valign="top">
1112 <row>
1113 <entry id="TRANSMISSION-MODE-AUTO"><constant>TRANSMISSION_MODE_AUTO</constant></entry>
1114 <entry>Autodetect transmission mode. The hardware will try to find
1115 the correct FFT-size (if capable) to fill in the missing
1116 parameters.</entry>
1117 </row><row>
1118 <entry id="TRANSMISSION-MODE-1K"><constant>TRANSMISSION_MODE_1K</constant></entry>
1119 <entry>Transmission mode 1K</entry>
1120 </row><row>
1121 <entry id="TRANSMISSION-MODE-2K"><constant>TRANSMISSION_MODE_2K</constant></entry>
1122 <entry>Transmission mode 2K</entry>
1123 </row><row>
1124 <entry id="TRANSMISSION-MODE-8K"><constant>TRANSMISSION_MODE_8K</constant></entry>
1125 <entry>Transmission mode 8K</entry>
1126 </row><row>
1127 <entry id="TRANSMISSION-MODE-4K"><constant>TRANSMISSION_MODE_4K</constant></entry>
1128 <entry>Transmission mode 4K</entry>
1129 </row><row>
1130 <entry id="TRANSMISSION-MODE-16K"><constant>TRANSMISSION_MODE_16K</constant></entry>
1131 <entry>Transmission mode 16K</entry>
1132 </row><row>
1133 <entry id="TRANSMISSION-MODE-32K"><constant>TRANSMISSION_MODE_32K</constant></entry>
1134 <entry>Transmission mode 32K</entry>
1135 </row><row>
1136 <entry id="TRANSMISSION-MODE-C1"><constant>TRANSMISSION_MODE_C1</constant></entry>
1137 <entry>Single Carrier (C=1) transmission mode (DTMB)</entry>
1138 </row><row>
1139 <entry id="TRANSMISSION-MODE-C3780"><constant>TRANSMISSION_MODE_C3780</constant></entry>
1140 <entry>Multi Carrier (C=3780) transmission mode (DTMB)</entry>
1141 </row>
1142 </tbody>
1143 </tgroup>
1144</table>
1145
820 1146
821 <para>Possible values are:</para>
822<programlisting>
823typedef enum fe_transmit_mode {
824 TRANSMISSION_MODE_2K,
825 TRANSMISSION_MODE_8K,
826 TRANSMISSION_MODE_AUTO,
827 TRANSMISSION_MODE_4K,
828 TRANSMISSION_MODE_1K,
829 TRANSMISSION_MODE_16K,
830 TRANSMISSION_MODE_32K,
831 TRANSMISSION_MODE_C1,
832 TRANSMISSION_MODE_C3780,
833} fe_transmit_mode_t;
834</programlisting>
835 <para>Notes:</para> 1147 <para>Notes:</para>
836 <para>1) ISDB-T supports three carrier/symbol-size: 8K, 4K, 2K. It is called 1148 <para>1) ISDB-T supports three carrier/symbol-size: 8K, 4K, 2K. It is called
837 'mode' in the standard: Mode 1 is 2K, mode 2 is 4K, mode 3 is 8K</para> 1149 'mode' in the standard: Mode 1 is 2K, mode 2 is 4K, mode 3 is 8K</para>
@@ -842,19 +1154,48 @@ typedef enum fe_transmit_mode {
842 <para>3) DVB-T specifies 2K and 8K as valid sizes.</para> 1154 <para>3) DVB-T specifies 2K and 8K as valid sizes.</para>
843 <para>4) DVB-T2 specifies 1K, 2K, 4K, 8K, 16K and 32K.</para> 1155 <para>4) DVB-T2 specifies 1K, 2K, 4K, 8K, 16K and 32K.</para>
844 <para>5) DTMB specifies C1 and C3780.</para> 1156 <para>5) DTMB specifies C1 and C3780.</para>
1157</section>
845 </section> 1158 </section>
846 <section id="DTV-HIERARCHY"> 1159 <section id="DTV-HIERARCHY">
847 <title><constant>DTV_HIERARCHY</constant></title> 1160 <title><constant>DTV_HIERARCHY</constant></title>
848 <para>Frontend hierarchy</para> 1161 <para>Frontend hierarchy</para>
849 <programlisting> 1162
850typedef enum fe_hierarchy { 1163
851 HIERARCHY_NONE, 1164<section id="fe-hierarchy-t">
852 HIERARCHY_1, 1165<title>Frontend hierarchy</title>
853 HIERARCHY_2, 1166
854 HIERARCHY_4, 1167<table pgwide="1" frame="none" id="fe-hierarchy">
855 HIERARCHY_AUTO 1168 <title>enum fe_hierarchy</title>
856 } fe_hierarchy_t; 1169 <tgroup cols="2">
857 </programlisting> 1170 &cs-def;
1171 <thead>
1172 <row>
1173 <entry>ID</entry>
1174 <entry>Description</entry>
1175 </row>
1176 </thead>
1177 <tbody valign="top">
1178 <row>
1179 <entry id="HIERARCHY-NONE"><constant>HIERARCHY_NONE</constant></entry>
1180 <entry>No hierarchy</entry>
1181 </row><row>
1182 <entry id="HIERARCHY-AUTO"><constant>HIERARCHY_AUTO</constant></entry>
1183 <entry>Autodetect hierarchy (if supported)</entry>
1184 </row><row>
1185 <entry id="HIERARCHY-1"><constant>HIERARCHY_1</constant></entry>
1186 <entry>Hierarchy 1</entry>
1187 </row><row>
1188 <entry id="HIERARCHY-2"><constant>HIERARCHY_2</constant></entry>
1189 <entry>Hierarchy 2</entry>
1190 </row><row>
1191 <entry id="HIERARCHY-4"><constant>HIERARCHY_4</constant></entry>
1192 <entry>Hierarchy 4</entry>
1193 </row>
1194 </tbody>
1195 </tgroup>
1196</table>
1197</section>
1198
858 </section> 1199 </section>
859 <section id="DTV-STREAM-ID"> 1200 <section id="DTV-STREAM-ID">
860 <title><constant>DTV_STREAM_ID</constant></title> 1201 <title><constant>DTV_STREAM_ID</constant></title>
@@ -891,15 +1232,37 @@ typedef enum fe_hierarchy {
891 </section> 1232 </section>
892 <section id="DTV-INTERLEAVING"> 1233 <section id="DTV-INTERLEAVING">
893 <title><constant>DTV_INTERLEAVING</constant></title> 1234 <title><constant>DTV_INTERLEAVING</constant></title>
894 <para id="fe-interleaving">Interleaving mode</para> 1235
895 <programlisting> 1236<para>Time interleaving to be used. Currently, used only on DTMB.</para>
896enum fe_interleaving { 1237
897 INTERLEAVING_NONE, 1238<table pgwide="1" frame="none" id="fe-interleaving">
898 INTERLEAVING_AUTO, 1239 <title>enum fe_interleaving</title>
899 INTERLEAVING_240, 1240 <tgroup cols="2">
900 INTERLEAVING_720, 1241 &cs-def;
901}; 1242 <thead>
902 </programlisting> 1243 <row>
1244 <entry>ID</entry>
1245 <entry>Description</entry>
1246 </row>
1247 </thead>
1248 <tbody valign="top">
1249 <row>
1250 <entry id="INTERLEAVING-NONE"><constant>INTERLEAVING_NONE</constant></entry>
1251 <entry>No interleaving.</entry>
1252 </row><row>
1253 <entry id="INTERLEAVING-AUTO"><constant>INTERLEAVING_AUTO</constant></entry>
1254 <entry>Auto-detect interleaving.</entry>
1255 </row><row>
1256 <entry id="INTERLEAVING-240"><constant>INTERLEAVING_240</constant></entry>
1257 <entry>Interleaving of 240 symbols.</entry>
1258 </row><row>
1259 <entry id="INTERLEAVING-720"><constant>INTERLEAVING_720</constant></entry>
1260 <entry>Interleaving of 720 symbols.</entry>
1261 </row>
1262 </tbody>
1263 </tgroup>
1264</table>
1265
903 </section> 1266 </section>
904 <section id="DTV-LNA"> 1267 <section id="DTV-LNA">
905 <title><constant>DTV_LNA</constant></title> 1268 <title><constant>DTV_LNA</constant></title>
@@ -921,7 +1284,7 @@ enum fe_interleaving {
921 <para>For most delivery systems, <constant>dtv_property.stat.len</constant> 1284 <para>For most delivery systems, <constant>dtv_property.stat.len</constant>
922 will be 1 if the stats is supported, and the properties will 1285 will be 1 if the stats is supported, and the properties will
923 return a single value for each parameter.</para> 1286 return a single value for each parameter.</para>
924 <para>It should be noticed, however, that new OFDM delivery systems 1287 <para>It should be noted, however, that new OFDM delivery systems
925 like ISDB can use different modulation types for each group of 1288 like ISDB can use different modulation types for each group of
926 carriers. On such standards, up to 3 groups of statistics can be 1289 carriers. On such standards, up to 3 groups of statistics can be
927 provided, and <constant>dtv_property.stat.len</constant> is updated 1290 provided, and <constant>dtv_property.stat.len</constant> is updated
@@ -940,10 +1303,10 @@ enum fe_interleaving {
940 and <constant>uvalue</constant> is for unsigned values (counters, relative scale)</para></listitem> 1303 and <constant>uvalue</constant> is for unsigned values (counters, relative scale)</para></listitem>
941 <listitem><para><constant>scale</constant> - Scale for the value. It can be:</para> 1304 <listitem><para><constant>scale</constant> - Scale for the value. It can be:</para>
942 <itemizedlist mark='bullet' id="fecap-scale-params"> 1305 <itemizedlist mark='bullet' id="fecap-scale-params">
943 <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - The parameter is supported by the frontend, but it was not possible to collect it (could be a transitory or permanent condition)</para></listitem> 1306 <listitem id="FE-SCALE-NOT-AVAILABLE"><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - The parameter is supported by the frontend, but it was not possible to collect it (could be a transitory or permanent condition)</para></listitem>
944 <listitem><para><constant>FE_SCALE_DECIBEL</constant> - parameter is a signed value, measured in 1/1000 dB</para></listitem> 1307 <listitem id="FE-SCALE-DECIBEL"><para><constant>FE_SCALE_DECIBEL</constant> - parameter is a signed value, measured in 1/1000 dB</para></listitem>
945 <listitem><para><constant>FE_SCALE_RELATIVE</constant> - parameter is a unsigned value, where 0 means 0% and 65535 means 100%.</para></listitem> 1308 <listitem id="FE-SCALE-RELATIVE"><para><constant>FE_SCALE_RELATIVE</constant> - parameter is a unsigned value, where 0 means 0% and 65535 means 100%.</para></listitem>
946 <listitem><para><constant>FE_SCALE_COUNTER</constant> - parameter is a unsigned value that counts the occurrence of an event, like bit error, block error, or lapsed time.</para></listitem> 1309 <listitem id="FE-SCALE-COUNTER"><para><constant>FE_SCALE_COUNTER</constant> - parameter is a unsigned value that counts the occurrence of an event, like bit error, block error, or lapsed time.</para></listitem>
947 </itemizedlist> 1310 </itemizedlist>
948 </listitem> 1311 </listitem>
949 </itemizedlist> 1312 </itemizedlist>
@@ -953,7 +1316,7 @@ enum fe_interleaving {
953 <para>Possible scales for this metric are:</para> 1316 <para>Possible scales for this metric are:</para>
954 <itemizedlist mark='bullet'> 1317 <itemizedlist mark='bullet'>
955 <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</para></listitem> 1318 <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</para></listitem>
956 <listitem><para><constant>FE_SCALE_DECIBEL</constant> - signal strength is in 0.0001 dBm units, power measured in miliwatts. This value is generally negative.</para></listitem> 1319 <listitem><para><constant>FE_SCALE_DECIBEL</constant> - signal strength is in 0.001 dBm units, power measured in miliwatts. This value is generally negative.</para></listitem>
957 <listitem><para><constant>FE_SCALE_RELATIVE</constant> - The frontend provides a 0% to 100% measurement for power (actually, 0 to 65535).</para></listitem> 1320 <listitem><para><constant>FE_SCALE_RELATIVE</constant> - The frontend provides a 0% to 100% measurement for power (actually, 0 to 65535).</para></listitem>
958 </itemizedlist> 1321 </itemizedlist>
959 </section> 1322 </section>
@@ -963,7 +1326,7 @@ enum fe_interleaving {
963 <para>Possible scales for this metric are:</para> 1326 <para>Possible scales for this metric are:</para>
964 <itemizedlist mark='bullet'> 1327 <itemizedlist mark='bullet'>
965 <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</para></listitem> 1328 <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</para></listitem>
966 <listitem><para><constant>FE_SCALE_DECIBEL</constant> - Signal/Noise ratio is in 0.0001 dB units.</para></listitem> 1329 <listitem><para><constant>FE_SCALE_DECIBEL</constant> - Signal/Noise ratio is in 0.001 dB units.</para></listitem>
967 <listitem><para><constant>FE_SCALE_RELATIVE</constant> - The frontend provides a 0% to 100% measurement for Signal/Noise (actually, 0 to 65535).</para></listitem> 1330 <listitem><para><constant>FE_SCALE_RELATIVE</constant> - The frontend provides a 0% to 100% measurement for Signal/Noise (actually, 0 to 65535).</para></listitem>
968 </itemizedlist> 1331 </itemizedlist>
969 </section> 1332 </section>
@@ -985,7 +1348,7 @@ enum fe_interleaving {
985 <title><constant>DTV_STAT_PRE_TOTAL_BIT_COUNT</constant></title> 1348 <title><constant>DTV_STAT_PRE_TOTAL_BIT_COUNT</constant></title>
986 <para>Measures the amount of bits received before the inner code block, during the same period as 1349 <para>Measures the amount of bits received before the inner code block, during the same period as
987 <link linkend="DTV-STAT-PRE-ERROR-BIT-COUNT"><constant>DTV_STAT_PRE_ERROR_BIT_COUNT</constant></link> measurement was taken.</para> 1350 <link linkend="DTV-STAT-PRE-ERROR-BIT-COUNT"><constant>DTV_STAT_PRE_ERROR_BIT_COUNT</constant></link> measurement was taken.</para>
988 <para>It should be noticed that this measurement can be smaller than the total amount of bits on the transport stream, 1351 <para>It should be noted that this measurement can be smaller than the total amount of bits on the transport stream,
989 as the frontend may need to manually restart the measurement, losing some data between each measurement interval.</para> 1352 as the frontend may need to manually restart the measurement, losing some data between each measurement interval.</para>
990 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements. 1353 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
991 The frontend may reset it when a channel/transponder is tuned.</para> 1354 The frontend may reset it when a channel/transponder is tuned.</para>
@@ -1014,7 +1377,7 @@ enum fe_interleaving {
1014 <title><constant>DTV_STAT_POST_TOTAL_BIT_COUNT</constant></title> 1377 <title><constant>DTV_STAT_POST_TOTAL_BIT_COUNT</constant></title>
1015 <para>Measures the amount of bits received after the inner coding, during the same period as 1378 <para>Measures the amount of bits received after the inner coding, during the same period as
1016 <link linkend="DTV-STAT-POST-ERROR-BIT-COUNT"><constant>DTV_STAT_POST_ERROR_BIT_COUNT</constant></link> measurement was taken.</para> 1379 <link linkend="DTV-STAT-POST-ERROR-BIT-COUNT"><constant>DTV_STAT_POST_ERROR_BIT_COUNT</constant></link> measurement was taken.</para>
1017 <para>It should be noticed that this measurement can be smaller than the total amount of bits on the transport stream, 1380 <para>It should be noted that this measurement can be smaller than the total amount of bits on the transport stream,
1018 as the frontend may need to manually restart the measurement, losing some data between each measurement interval.</para> 1381 as the frontend may need to manually restart the measurement, losing some data between each measurement interval.</para>
1019 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements. 1382 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
1020 The frontend may reset it when a channel/transponder is tuned.</para> 1383 The frontend may reset it when a channel/transponder is tuned.</para>
@@ -1255,8 +1618,8 @@ enum fe_interleaving {
1255 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> 1618 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
1256 </section> 1619 </section>
1257 </section> 1620 </section>
1258 <section id="frontend-property-satellital-systems"> 1621 <section id="frontend-property-satellite-systems">
1259 <title>Properties used on satellital delivery systems</title> 1622 <title>Properties used on satellite delivery systems</title>
1260 <section id="dvbs-params"> 1623 <section id="dvbs-params">
1261 <title>DVB-S delivery system</title> 1624 <title>DVB-S delivery system</title>
1262 <para>The following parameters are valid for DVB-S:</para> 1625 <para>The following parameters are valid for DVB-S:</para>
diff --git a/Documentation/DocBook/media/dvb/examples.xml b/Documentation/DocBook/media/dvb/examples.xml
index f037e568eb6e..c9f68c7183cc 100644
--- a/Documentation/DocBook/media/dvb/examples.xml
+++ b/Documentation/DocBook/media/dvb/examples.xml
@@ -1,8 +1,10 @@
1<title>Examples</title> 1<title>Examples</title>
2<para>In this section we would like to present some examples for using the DVB API. 2<para>In this section we would like to present some examples for using the DVB API.
3</para> 3</para>
4<para>Maintainer note: This section is out of date. Please refer to the sample programs packaged 4<para>NOTE: This section is out of date, and the code below won't even
5with the driver distribution from <ulink url="http://linuxtv.org/hg/dvb-apps" />. 5 compile. Please refer to the
6 <ulink url="http://linuxtv.org/docs/libdvbv5/index.html">libdvbv5</ulink>
7 for updated/recommended examples.
6</para> 8</para>
7 9
8<section id="tuning"> 10<section id="tuning">
diff --git a/Documentation/DocBook/media/dvb/fe-diseqc-recv-slave-reply.xml b/Documentation/DocBook/media/dvb/fe-diseqc-recv-slave-reply.xml
new file mode 100644
index 000000000000..4595dbfff208
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-diseqc-recv-slave-reply.xml
@@ -0,0 +1,78 @@
1<refentry id="FE_DISEQC_RECV_SLAVE_REPLY">
2 <refmeta>
3 <refentrytitle>ioctl FE_DISEQC_RECV_SLAVE_REPLY</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_DISEQC_RECV_SLAVE_REPLY</refname>
9 <refpurpose>Receives reply from a DiSEqC 2.0 command</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>struct dvb_diseqc_slave_reply *<parameter>argp</parameter></paramdef>
19 </funcprototype>
20 </funcsynopsis>
21 </refsynopsisdiv>
22
23 <refsect1>
24 <title>Arguments</title>
25 <variablelist>
26 <varlistentry>
27 <term><parameter>fd</parameter></term>
28 <listitem>
29 <para>&fe_fd;</para>
30 </listitem>
31 </varlistentry>
32 <varlistentry>
33 <term><parameter>request</parameter></term>
34 <listitem>
35 <para>FE_DISEQC_RECV_SLAVE_REPLY</para>
36 </listitem>
37 </varlistentry>
38 <varlistentry>
39 <term><parameter>argp</parameter></term>
40 <listitem>
41 <para>pointer to &dvb-diseqc-slave-reply;</para>
42 </listitem>
43 </varlistentry>
44 </variablelist>
45 </refsect1>
46
47 <refsect1>
48 <title>Description</title>
49
50 <para>Receives reply from a DiSEqC 2.0 command.</para>
51&return-value-dvb;
52
53<table pgwide="1" frame="none" id="dvb-diseqc-slave-reply">
54 <title>struct <structname>dvb_diseqc_slave_reply</structname></title>
55 <tgroup cols="3">
56 &cs-str;
57 <tbody valign="top">
58 <row>
59 <entry>uint8_t</entry>
60 <entry>msg[4]</entry>
61 <entry>DiSEqC message (framing, data[3])</entry>
62 </row><row>
63 <entry>uint8_t</entry>
64 <entry>msg_len</entry>
65 <entry>Length of the DiSEqC message. Valid values are 0 to 4,
66 where 0 means no msg</entry>
67 </row><row>
68 <entry>int</entry>
69 <entry>timeout</entry>
70 <entry>Return from ioctl after timeout ms with errorcode when no
71 message was received</entry>
72 </row>
73 </tbody>
74 </tgroup>
75</table>
76
77</refsect1>
78</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-diseqc-reset-overload.xml b/Documentation/DocBook/media/dvb/fe-diseqc-reset-overload.xml
new file mode 100644
index 000000000000..c104df77ecd0
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-diseqc-reset-overload.xml
@@ -0,0 +1,51 @@
1<refentry id="FE_DISEQC_RESET_OVERLOAD">
2 <refmeta>
3 <refentrytitle>ioctl FE_DISEQC_RESET_OVERLOAD</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_DISEQC_RESET_OVERLOAD</refname>
9 <refpurpose>Restores the power to the antenna subsystem, if it was powered
10 off due to power overload.</refpurpose>
11 </refnamediv>
12
13 <refsynopsisdiv>
14 <funcsynopsis>
15 <funcprototype>
16 <funcdef>int <function>ioctl</function></funcdef>
17 <paramdef>int <parameter>fd</parameter></paramdef>
18 <paramdef>int <parameter>request</parameter></paramdef>
19 <paramdef>NULL</paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 </refsynopsisdiv>
23
24 <refsect1>
25 <title>Arguments</title>
26 <variablelist>
27 <varlistentry>
28 <term><parameter>fd</parameter></term>
29 <listitem>
30 <para>&fe_fd;</para>
31 </listitem>
32 </varlistentry>
33 <varlistentry>
34 <term><parameter>request</parameter></term>
35 <listitem>
36 <para>FE_DISEQC_RESET_OVERLOAD</para>
37 </listitem>
38 </varlistentry>
39 </variablelist>
40 </refsect1>
41
42 <refsect1>
43 <title>Description</title>
44
45 <para>If the bus has been automatically powered off due to power overload, this ioctl
46 call restores the power to the bus. The call requires read/write access to the
47 device. This call has no effect if the device is manually powered off. Not all
48 DVB adapters support this ioctl.</para>
49&return-value-dvb;
50</refsect1>
51</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-diseqc-send-burst.xml b/Documentation/DocBook/media/dvb/fe-diseqc-send-burst.xml
new file mode 100644
index 000000000000..9f6a68f32de3
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-diseqc-send-burst.xml
@@ -0,0 +1,89 @@
1<refentry id="FE_DISEQC_SEND_BURST">
2 <refmeta>
3 <refentrytitle>ioctl FE_DISEQC_SEND_BURST</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_DISEQC_SEND_BURST</refname>
9 <refpurpose>Sends a 22KHz tone burst for 2x1 mini DiSEqC satellite selection.</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>enum fe_sec_mini_cmd *<parameter>tone</parameter></paramdef>
19 </funcprototype>
20 </funcsynopsis>
21 </refsynopsisdiv>
22
23 <refsect1>
24 <title>Arguments</title>
25 <variablelist>
26 <varlistentry>
27 <term><parameter>fd</parameter></term>
28 <listitem>
29 <para>&fe_fd;</para>
30 </listitem>
31 </varlistentry>
32 <varlistentry>
33 <term><parameter>request</parameter></term>
34 <listitem>
35 <para>FE_DISEQC_SEND_BURST</para>
36 </listitem>
37 </varlistentry>
38 <varlistentry>
39 <term><parameter>tone</parameter></term>
40 <listitem>
41 <para>pointer to &fe-sec-mini-cmd;</para>
42 </listitem>
43 </varlistentry>
44 </variablelist>
45 </refsect1>
46
47 <refsect1>
48 <title>Description</title>
49
50<para>This ioctl is used to set the generation of a 22kHz tone burst for mini
51 DiSEqC satellite
52 selection for 2x1 switches.
53 This call requires read/write permissions.</para>
54<para>It provides support for what's specified at
55 <ulink url="http://www.eutelsat.com/files/contributed/satellites/pdf/Diseqc/associated%20docs/simple_tone_burst_detec.pdf">Digital Satellite Equipment Control
56 (DiSEqC) - Simple "ToneBurst" Detection Circuit specification.</ulink>
57 </para>
58&return-value-dvb;
59</refsect1>
60
61<refsect1 id="fe-sec-mini-cmd-t">
62<title>enum fe_sec_mini_cmd</title>
63
64<table pgwide="1" frame="none" id="fe-sec-mini-cmd">
65 <title>enum fe_sec_mini_cmd</title>
66 <tgroup cols="2">
67 &cs-def;
68 <thead>
69 <row>
70 <entry>ID</entry>
71 <entry>Description</entry>
72 </row>
73 </thead>
74 <tbody valign="top">
75 <row>
76 <entry align="char" id="SEC-MINI-A"><constant>SEC_MINI_A</constant></entry>
77 <entry align="char">Sends a mini-DiSEqC 22kHz '0' Tone Burst to
78 select satellite-A</entry>
79 </row><row>
80 <entry align="char" id="SEC-MINI-B"><constant>SEC_MINI_B</constant></entry>
81 <entry align="char">Sends a mini-DiSEqC 22kHz '1' Data Burst to
82 select satellite-B</entry>
83 </row>
84 </tbody>
85 </tgroup>
86</table>
87</refsect1>
88
89</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-diseqc-send-master-cmd.xml b/Documentation/DocBook/media/dvb/fe-diseqc-send-master-cmd.xml
new file mode 100644
index 000000000000..38cf313e121b
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-diseqc-send-master-cmd.xml
@@ -0,0 +1,72 @@
1<refentry id="FE_DISEQC_SEND_MASTER_CMD">
2 <refmeta>
3 <refentrytitle>ioctl FE_DISEQC_SEND_MASTER_CMD</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_DISEQC_SEND_MASTER_CMD</refname>
9 <refpurpose>Sends a DiSEqC command</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>struct dvb_diseqc_master_cmd *<parameter>argp</parameter></paramdef>
19 </funcprototype>
20 </funcsynopsis>
21 </refsynopsisdiv>
22
23 <refsect1>
24 <title>Arguments</title>
25 <variablelist>
26 <varlistentry>
27 <term><parameter>fd</parameter></term>
28 <listitem>
29 <para>&fe_fd;</para>
30 </listitem>
31 </varlistentry>
32 <varlistentry>
33 <term><parameter>request</parameter></term>
34 <listitem>
35 <para>FE_DISEQC_SEND_MASTER_CMD</para>
36 </listitem>
37 </varlistentry>
38 <varlistentry>
39 <term><parameter>argp</parameter></term>
40 <listitem>
41 <para>pointer to &dvb-diseqc-master-cmd;</para>
42 </listitem>
43 </varlistentry>
44 </variablelist>
45 </refsect1>
46
47 <refsect1>
48 <title>Description</title>
49
50 <para>Sends a DiSEqC command to the antenna subsystem.</para>
51&return-value-dvb;
52
53<table pgwide="1" frame="none" id="dvb-diseqc-master-cmd">
54 <title>struct <structname>dvb_diseqc_master_cmd</structname></title>
55 <tgroup cols="3">
56 &cs-str;
57 <tbody valign="top">
58 <row>
59 <entry>uint8_t</entry>
60 <entry>msg[6]</entry>
61 <entry>DiSEqC message (framing, address, command, data[3])</entry>
62 </row><row>
63 <entry>uint8_t</entry>
64 <entry>msg_len</entry>
65 <entry>Length of the DiSEqC message. Valid values are 3 to 6</entry>
66 </row>
67 </tbody>
68 </tgroup>
69</table>
70
71</refsect1>
72</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-enable-high-lnb-voltage.xml b/Documentation/DocBook/media/dvb/fe-enable-high-lnb-voltage.xml
new file mode 100644
index 000000000000..c11890b184ad
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-enable-high-lnb-voltage.xml
@@ -0,0 +1,61 @@
1<refentry id="FE_ENABLE_HIGH_LNB_VOLTAGE">
2 <refmeta>
3 <refentrytitle>ioctl FE_ENABLE_HIGH_LNB_VOLTAGE</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_ENABLE_HIGH_LNB_VOLTAGE</refname>
9 <refpurpose>Select output DC level between normal LNBf voltages or higher
10 LNBf voltages.</refpurpose>
11 </refnamediv>
12
13 <refsynopsisdiv>
14 <funcsynopsis>
15 <funcprototype>
16 <funcdef>int <function>ioctl</function></funcdef>
17 <paramdef>int <parameter>fd</parameter></paramdef>
18 <paramdef>int <parameter>request</parameter></paramdef>
19 <paramdef>unsigned int <parameter>high</parameter></paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 </refsynopsisdiv>
23
24 <refsect1>
25 <title>Arguments</title>
26 <variablelist>
27 <varlistentry>
28 <term><parameter>fd</parameter></term>
29 <listitem>
30 <para>&fe_fd;</para>
31 </listitem>
32 </varlistentry>
33 <varlistentry>
34 <term><parameter>request</parameter></term>
35 <listitem>
36 <para>FE_ENABLE_HIGH_LNB_VOLTAGE</para>
37 </listitem>
38 </varlistentry>
39 <varlistentry>
40 <term><parameter>high</parameter></term>
41 <listitem>
42 <para>Valid flags:</para>
43 <itemizedlist>
44 <listitem><para>0 - normal 13V and 18V.</para></listitem>
45 <listitem><para>&gt;0 - enables slightly higher voltages instead of
46 13/18V, in order to compensate for long antenna cables.</para></listitem>
47 </itemizedlist>
48 </listitem>
49 </varlistentry>
50 </variablelist>
51 </refsect1>
52
53 <refsect1>
54 <title>Description</title>
55
56 <para>Select output DC level between normal LNBf voltages or higher
57 LNBf voltages between 0 (normal) or a value grater than 0 for higher
58 voltages.</para>
59&return-value-dvb;
60</refsect1>
61</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-get-info.xml b/Documentation/DocBook/media/dvb/fe-get-info.xml
new file mode 100644
index 000000000000..ed0eeb29dd65
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-get-info.xml
@@ -0,0 +1,266 @@
1<refentry id="FE_GET_INFO">
2 <refmeta>
3 <refentrytitle>ioctl FE_GET_INFO</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_GET_INFO</refname>
9 <refpurpose>Query DVB frontend capabilities and returns information about
10 the front-end. This call only requires read-only access to the device</refpurpose>
11 </refnamediv>
12
13 <refsynopsisdiv>
14 <funcsynopsis>
15 <funcprototype>
16 <funcdef>int <function>ioctl</function></funcdef>
17 <paramdef>int <parameter>fd</parameter></paramdef>
18 <paramdef>int <parameter>request</parameter></paramdef>
19 <paramdef>struct dvb_frontend_info *<parameter>argp</parameter></paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 </refsynopsisdiv>
23
24 <refsect1>
25 <title>Arguments</title>
26 <variablelist>
27 <varlistentry>
28 <term><parameter>fd</parameter></term>
29 <listitem>
30 <para>&fe_fd;</para>
31 </listitem>
32 </varlistentry>
33 <varlistentry>
34 <term><parameter>request</parameter></term>
35 <listitem>
36 <para>FE_GET_INFO</para>
37 </listitem>
38 </varlistentry>
39 <varlistentry>
40 <term><parameter>argp</parameter></term>
41 <listitem>
42 <para>pointer to struct &dvb-frontend-info;</para>
43 </listitem>
44 </varlistentry>
45 </variablelist>
46 </refsect1>
47
48 <refsect1>
49 <title>Description</title>
50
51 <para>All DVB frontend devices support the
52<constant>FE_GET_INFO</constant> ioctl. It is used to identify
53kernel devices compatible with this specification and to obtain
54information about driver and hardware capabilities. The ioctl takes a
55pointer to dvb_frontend_info which is filled by the driver. When the
56driver is not compatible with this specification the ioctl returns an error.
57</para>
58&return-value-dvb;
59
60 <table pgwide="1" frame="none" id="dvb-frontend-info">
61 <title>struct <structname>dvb_frontend_info</structname></title>
62 <tgroup cols="3">
63 &cs-str;
64 <tbody valign="top">
65 <row>
66 <entry>char</entry>
67 <entry>name[128]</entry>
68 <entry>Name of the frontend</entry>
69 </row><row>
70 <entry>fe_type_t</entry>
71 <entry>type</entry>
72 <entry><emphasis role="bold">DEPRECATED</emphasis>. DVBv3 type. Should not be used on modern programs, as a
73 frontend may have more than one type. So, the DVBv5 API should
74 be used instead to enumerate and select the frontend type.</entry>
75 </row><row>
76 <entry>uint32_t</entry>
77 <entry>frequency_min</entry>
78 <entry>Minimal frequency supported by the frontend</entry>
79 </row><row>
80 <entry>uint32_t</entry>
81 <entry>frequency_max</entry>
82 <entry>Maximal frequency supported by the frontend</entry>
83 </row><row>
84 <entry>uint32_t</entry>
85 <entry>frequency_stepsize</entry>
86 <entry>Frequency step - all frequencies are multiple of this value</entry>
87 </row><row>
88 <entry>uint32_t</entry>
89 <entry>frequency_tolerance</entry>
90 <entry>Tolerance of the frequency</entry>
91 </row><row>
92 <entry>uint32_t</entry>
93 <entry>symbol_rate_min</entry>
94 <entry>Minimal symbol rate (for Cable/Satellite systems), in bauds</entry>
95 </row><row>
96 <entry>uint32_t</entry>
97 <entry>symbol_rate_max</entry>
98 <entry>Maximal symbol rate (for Cable/Satellite systems), in bauds</entry>
99 </row><row>
100 <entry>uint32_t</entry>
101 <entry>symbol_rate_tolerance</entry>
102 <entry>Maximal symbol rate tolerance, in ppm</entry>
103 </row><row>
104 <entry>uint32_t</entry>
105 <entry>notifier_delay</entry>
106 <entry><emphasis role="bold">DEPRECATED</emphasis>. Not used by any driver.</entry>
107 </row><row>
108 <entry>&fe-caps;</entry>
109 <entry>caps</entry>
110 <entry>Capabilities supported by the frontend</entry>
111 </row>
112 </tbody>
113 </tgroup>
114 </table>
115
116 <para>NOTE: The frequencies are specified in Hz for Terrestrial and Cable
117 systems. They're specified in kHz for Satellite systems</para>
118 </refsect1>
119
120<refsect1 id="fe-caps-t">
121<title>frontend capabilities</title>
122
123<para>Capabilities describe what a frontend can do. Some capabilities are
124 supported only on some specific frontend types.</para>
125
126<table pgwide="1" frame="none" id="fe-caps">
127 <title>enum fe_caps</title>
128 <tgroup cols="2">
129 &cs-def;
130 <thead>
131 <row>
132 <entry>ID</entry>
133 <entry>Description</entry>
134 </row>
135 </thead>
136 <tbody valign="top">
137 <row>
138 <entry id="FE-IS-STUPID"><constant>FE_IS_STUPID</constant></entry>
139 <entry>There's something wrong at the frontend, and it can't
140 report its capabilities</entry>
141 </row>
142 <row>
143 <entry id="FE-CAN-INVERSION-AUTO"><constant>FE_CAN_INVERSION_AUTO</constant></entry>
144 <entry>The frontend is capable of auto-detecting inversion</entry>
145 </row>
146 <row>
147 <entry id="FE-CAN-FEC-1-2"><constant>FE_CAN_FEC_1_2</constant></entry>
148 <entry>The frontend supports FEC 1/2</entry>
149 </row>
150 <row>
151 <entry id="FE-CAN-FEC-2-3"><constant>FE_CAN_FEC_2_3</constant></entry>
152 <entry>The frontend supports FEC 2/3</entry>
153 </row>
154 <row>
155 <entry id="FE-CAN-FEC-3-4"><constant>FE_CAN_FEC_3_4</constant></entry>
156 <entry>The frontend supports FEC 3/4</entry>
157 </row>
158 <row>
159 <entry id="FE-CAN-FEC-4-5"><constant>FE_CAN_FEC_4_5</constant></entry>
160 <entry>The frontend supports FEC 4/5</entry>
161 </row>
162 <row>
163 <entry id="FE-CAN-FEC-5-6"><constant>FE_CAN_FEC_5_6</constant></entry>
164 <entry>The frontend supports FEC 5/6</entry>
165 </row>
166 <row>
167 <entry id="FE-CAN-FEC-6-7"><constant>FE_CAN_FEC_6_7</constant></entry>
168 <entry>The frontend supports FEC 6/7</entry>
169 </row>
170 <row>
171 <entry id="FE-CAN-FEC-7-8"><constant>FE_CAN_FEC_7_8</constant></entry>
172 <entry>The frontend supports FEC 7/8</entry>
173 </row>
174 <row>
175 <entry id="FE-CAN-FEC-8-9"><constant>FE_CAN_FEC_8_9</constant></entry>
176 <entry>The frontend supports FEC 8/9</entry>
177 </row>
178 <row>
179 <entry id="FE-CAN-FEC-AUTO"><constant>FE_CAN_FEC_AUTO</constant></entry>
180 <entry>The frontend can autodetect FEC.</entry>
181 </row>
182 <row>
183 <entry id="FE-CAN-QPSK"><constant>FE_CAN_QPSK</constant></entry>
184 <entry>The frontend supports QPSK modulation</entry>
185 </row>
186 <row>
187 <entry id="FE-CAN-QAM-16"><constant>FE_CAN_QAM_16</constant></entry>
188 <entry>The frontend supports 16-QAM modulation</entry>
189 </row>
190 <row>
191 <entry id="FE-CAN-QAM-32"><constant>FE_CAN_QAM_32</constant></entry>
192 <entry>The frontend supports 32-QAM modulation</entry>
193 </row>
194 <row>
195 <entry id="FE-CAN-QAM-64"><constant>FE_CAN_QAM_64</constant></entry>
196 <entry>The frontend supports 64-QAM modulation</entry>
197 </row>
198 <row>
199 <entry id="FE-CAN-QAM-128"><constant>FE_CAN_QAM_128</constant></entry>
200 <entry>The frontend supports 128-QAM modulation</entry>
201 </row>
202 <row>
203 <entry id="FE-CAN-QAM-256"><constant>FE_CAN_QAM_256</constant></entry>
204 <entry>The frontend supports 256-QAM modulation</entry>
205 </row>
206 <row>
207 <entry id="FE-CAN-QAM-AUTO"><constant>FE_CAN_QAM_AUTO</constant></entry>
208 <entry>The frontend can autodetect modulation</entry>
209 </row>
210 <row>
211 <entry id="FE-CAN-TRANSMISSION-MODE-AUTO"><constant>FE_CAN_TRANSMISSION_MODE_AUTO</constant></entry>
212 <entry>The frontend can autodetect the transmission mode</entry>
213 </row>
214 <row>
215 <entry id="FE-CAN-BANDWIDTH-AUTO"><constant>FE_CAN_BANDWIDTH_AUTO</constant></entry>
216 <entry>The frontend can autodetect the bandwidth</entry>
217 </row>
218 <row>
219 <entry id="FE-CAN-GUARD-INTERVAL-AUTO"><constant>FE_CAN_GUARD_INTERVAL_AUTO</constant></entry>
220 <entry>The frontend can autodetect the guard interval</entry>
221 </row>
222 <row>
223 <entry id="FE-CAN-HIERARCHY-AUTO"><constant>FE_CAN_HIERARCHY_AUTO</constant></entry>
224 <entry>The frontend can autodetect hierarch</entry>
225 </row>
226 <row>
227 <entry id="FE-CAN-8VSB"><constant>FE_CAN_8VSB</constant></entry>
228 <entry>The frontend supports 8-VSB modulation</entry>
229 </row>
230 <row>
231 <entry id="FE-CAN-16VSB"><constant>FE_CAN_16VSB</constant></entry>
232 <entry>The frontend supports 16-VSB modulation</entry>
233 </row>
234 <row>
235 <entry id="FE-HAS-EXTENDED-CAPS"><constant>FE_HAS_EXTENDED_CAPS</constant></entry>
236 <entry>Currently, unused</entry>
237 </row>
238 <row>
239 <entry id="FE-CAN-MULTISTREAM"><constant>FE_CAN_MULTISTREAM</constant></entry>
240 <entry>The frontend supports multistream filtering</entry>
241 </row>
242 <row>
243 <entry id="FE-CAN-TURBO-FEC"><constant>FE_CAN_TURBO_FEC</constant></entry>
244 <entry>The frontend supports turbo FEC modulation</entry>
245 </row>
246 <row>
247 <entry id="FE-CAN-2G-MODULATION"><constant>FE_CAN_2G_MODULATION</constant></entry>
248 <entry>The frontend supports "2nd generation modulation" (DVB-S2/T2)></entry>
249 </row>
250 <row>
251 <entry id="FE-NEEDS-BENDING"><constant>FE_NEEDS_BENDING</constant></entry>
252 <entry>Not supported anymore, don't use it</entry>
253 </row>
254 <row>
255 <entry id="FE-CAN-RECOVER"><constant>FE_CAN_RECOVER</constant></entry>
256 <entry>The frontend can recover from a cable unplug automatically</entry>
257 </row>
258 <row>
259 <entry id="FE-CAN-MUTE-TS"><constant>FE_CAN_MUTE_TS</constant></entry>
260 <entry>The frontend can stop spurious TS data output</entry>
261 </row>
262 </tbody>
263 </tgroup>
264</table>
265</refsect1>
266</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-get-property.xml b/Documentation/DocBook/media/dvb/fe-get-property.xml
new file mode 100644
index 000000000000..53a170ed3bd1
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-get-property.xml
@@ -0,0 +1,81 @@
1<refentry id="FE_GET_PROPERTY">
2 <refmeta>
3 <refentrytitle>ioctl FE_SET_PROPERTY, FE_GET_PROPERTY</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_SET_PROPERTY</refname>
9 <refname>FE_GET_PROPERTY</refname>
10 <refpurpose>FE_SET_PROPERTY sets one or more frontend properties.
11 FE_GET_PROPERTY returns one or more frontend properties.</refpurpose>
12 </refnamediv>
13
14 <refsynopsisdiv>
15 <funcsynopsis>
16 <funcprototype>
17 <funcdef>int <function>ioctl</function></funcdef>
18 <paramdef>int <parameter>fd</parameter></paramdef>
19 <paramdef>int <parameter>request</parameter></paramdef>
20 <paramdef>struct dtv_properties *<parameter>argp</parameter></paramdef>
21 </funcprototype>
22 </funcsynopsis>
23 </refsynopsisdiv>
24
25 <refsect1>
26 <title>Arguments</title>
27 <variablelist>
28 <varlistentry>
29 <term><parameter>fd</parameter></term>
30 <listitem>
31 <para>&fe_fd;</para>
32 </listitem>
33 </varlistentry>
34 <varlistentry>
35 <term><parameter>request</parameter></term>
36 <listitem>
37 <para>FE_SET_PROPERTY, FE_GET_PROPERTY</para>
38 </listitem>
39 </varlistentry>
40 <varlistentry>
41 <term><parameter>argp</parameter></term>
42 <listitem>
43 <para>pointer to &dtv-properties;</para>
44 </listitem>
45 </varlistentry>
46 </variablelist>
47 </refsect1>
48
49 <refsect1>
50 <title>Description</title>
51
52 <para>All DVB frontend devices support the
53<constant>FE_SET_PROPERTY</constant> and <constant>FE_GET_PROPERTY</constant>
54ioctls. The supported properties and statistics depends on the delivery system
55and on the device:</para>
56<itemizedlist>
57<listitem>
58 <para><constant>FE_SET_PROPERTY:</constant></para>
59<itemizedlist>
60<listitem><para>This ioctl is used to set one or more
61 frontend properties.</para></listitem>
62<listitem><para>This is the basic command to request the frontend to tune into some
63 frequency and to start decoding the digital TV signal.</para></listitem>
64<listitem><para>This call requires read/write access to the device.</para></listitem>
65<listitem><para>At return, the values are updated to reflect the
66 actual parameters used.</para></listitem>
67</itemizedlist>
68</listitem>
69<listitem>
70 <para><constant>FE_GET_PROPERTY:</constant></para>
71<itemizedlist>
72<listitem><para>This ioctl is used to get properties and
73statistics from the frontend.</para></listitem>
74<listitem><para>No properties are changed, and statistics aren't reset.</para></listitem>
75<listitem><para>This call only requires read-only access to the device.</para></listitem>
76</itemizedlist>
77</listitem>
78</itemizedlist>
79&return-value-dvb;
80</refsect1>
81</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-read-status.xml b/Documentation/DocBook/media/dvb/fe-read-status.xml
new file mode 100644
index 000000000000..bc0dc2a55f19
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-read-status.xml
@@ -0,0 +1,107 @@
1<refentry id="FE_READ_STATUS">
2 <refmeta>
3 <refentrytitle>ioctl FE_READ_STATUS</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_READ_STATUS</refname>
9 <refpurpose>Returns status information about the front-end. This call only
10 requires read-only access to the device</refpurpose>
11 </refnamediv>
12
13 <refsynopsisdiv>
14 <funcsynopsis>
15 <funcprototype>
16 <funcdef>int <function>ioctl</function></funcdef>
17 <paramdef>int <parameter>fd</parameter></paramdef>
18 <paramdef>int <parameter>request</parameter></paramdef>
19 <paramdef>unsigned int *<parameter>status</parameter></paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 </refsynopsisdiv>
23
24 <refsect1>
25 <title>Arguments</title>
26 <variablelist>
27 <varlistentry>
28 <term><parameter>fd</parameter></term>
29 <listitem>
30 <para>&fe_fd;</para>
31 </listitem>
32 </varlistentry>
33 <varlistentry>
34 <term><parameter>request</parameter></term>
35 <listitem>
36 <para>FE_READ_STATUS</para>
37 </listitem>
38 </varlistentry>
39 <varlistentry>
40 <term><parameter>status</parameter></term>
41 <listitem>
42 <para>pointer to a bitmask integer filled with the values defined by
43 &fe-status;.</para>
44 </listitem>
45 </varlistentry>
46 </variablelist>
47 </refsect1>
48
49 <refsect1>
50 <title>Description</title>
51
52 <para>All DVB frontend devices support the
53<constant>FE_READ_STATUS</constant> ioctl. It is used to check about the
54locking status of the frontend after being tuned. The ioctl takes a
55pointer to an integer where the status will be written.
56</para>
57<para>NOTE: the size of status is actually sizeof(enum fe_status), with varies
58 according with the architecture. This needs to be fixed in the future.</para>
59&return-value-dvb;
60</refsect1>
61
62<refsect1 id="fe-status-t">
63<title>int fe_status</title>
64
65<para>The fe_status parameter is used to indicate the current state
66 and/or state changes of the frontend hardware. It is produced using
67 the &fe-status; values on a bitmask</para>
68
69<table pgwide="1" frame="none" id="fe-status">
70 <title>enum fe_status</title>
71 <tgroup cols="2">
72 &cs-def;
73 <thead>
74 <row>
75 <entry>ID</entry>
76 <entry>Description</entry>
77 </row>
78 </thead>
79 <tbody valign="top">
80 <row>
81 <entry align="char" id="FE-HAS-SIGNAL"><constant>FE_HAS_SIGNAL</constant></entry>
82 <entry align="char">The frontend has found something above the noise level</entry>
83 </row><row>
84 <entry align="char" id="FE-HAS-CARRIER"><constant>FE_HAS_CARRIER</constant></entry>
85 <entry align="char">The frontend has found a DVB signal</entry>
86 </row><row>
87 <entry align="char" id="FE-HAS-VITERBI"><constant>FE_HAS_VITERBI</constant></entry>
88 <entry align="char">The frontend FEC inner coding (Viterbi, LDPC or other inner code) is stable</entry>
89 </row><row>
90 <entry align="char" id="FE-HAS-SYNC"><constant>FE_HAS_SYNC</constant></entry>
91 <entry align="char">Synchronization bytes was found</entry>
92 </row><row>
93 <entry align="char" id="FE-HAS-LOCK"><constant>FE_HAS_LOCK</constant></entry>
94 <entry align="char">The DVB were locked and everything is working</entry>
95 </row><row>
96 <entry align="char" id="FE-TIMEDOUT"><constant>FE_TIMEDOUT</constant></entry>
97 <entry align="char">no lock within the last about 2 seconds</entry>
98 </row><row>
99 <entry align="char" id="FE-REINIT"><constant>FE_REINIT</constant></entry>
100 <entry align="char">The frontend was reinitialized, application is
101 recommended to reset DiSEqC, tone and parameters</entry>
102 </row>
103 </tbody>
104 </tgroup>
105</table>
106</refsect1>
107</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-set-frontend-tune-mode.xml b/Documentation/DocBook/media/dvb/fe-set-frontend-tune-mode.xml
new file mode 100644
index 000000000000..99fa8a015c7a
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-set-frontend-tune-mode.xml
@@ -0,0 +1,64 @@
1<refentry id="FE_SET_FRONTEND_TUNE_MODE">
2 <refmeta>
3 <refentrytitle>ioctl FE_SET_FRONTEND_TUNE_MODE</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_SET_FRONTEND_TUNE_MODE</refname>
9 <refpurpose>Allow setting tuner mode flags to the frontend.</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>unsigned int <parameter>flags</parameter></paramdef>
19 </funcprototype>
20 </funcsynopsis>
21 </refsynopsisdiv>
22
23 <refsect1>
24 <title>Arguments</title>
25 <variablelist>
26 <varlistentry>
27 <term><parameter>fd</parameter></term>
28 <listitem>
29 <para>&fe_fd;</para>
30 </listitem>
31 </varlistentry>
32 <varlistentry>
33 <term><parameter>request</parameter></term>
34 <listitem>
35 <para>FE_SET_FRONTEND_TUNE_MODE</para>
36 </listitem>
37 </varlistentry>
38 <varlistentry>
39 <term><parameter>flags</parameter></term>
40 <listitem>
41 <para>Valid flags:</para>
42 <itemizedlist>
43 <listitem><para>0 - normal tune mode</para></listitem>
44 <listitem><para>FE_TUNE_MODE_ONESHOT - When set, this flag will
45 disable any zigzagging or other "normal" tuning behaviour.
46 Additionally, there will be no automatic monitoring of the
47 lock status, and hence no frontend events will be
48 generated. If a frontend device is closed, this flag will
49 be automatically turned off when the device is reopened
50 read-write.</para></listitem>
51 </itemizedlist>
52 </listitem>
53 </varlistentry>
54 </variablelist>
55 </refsect1>
56
57 <refsect1>
58 <title>Description</title>
59
60 <para>Allow setting tuner mode flags to the frontend, between 0 (normal)
61 or FE_TUNE_MODE_ONESHOT mode</para>
62&return-value-dvb;
63</refsect1>
64</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-set-tone.xml b/Documentation/DocBook/media/dvb/fe-set-tone.xml
new file mode 100644
index 000000000000..62d44e4ccc39
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-set-tone.xml
@@ -0,0 +1,91 @@
1<refentry id="FE_SET_TONE">
2 <refmeta>
3 <refentrytitle>ioctl FE_SET_TONE</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_SET_TONE</refname>
9 <refpurpose>Sets/resets the generation of the continuous 22kHz tone.</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>enum fe_sec_tone_mode *<parameter>tone</parameter></paramdef>
19 </funcprototype>
20 </funcsynopsis>
21 </refsynopsisdiv>
22
23 <refsect1>
24 <title>Arguments</title>
25 <variablelist>
26 <varlistentry>
27 <term><parameter>fd</parameter></term>
28 <listitem>
29 <para>&fe_fd;</para>
30 </listitem>
31 </varlistentry>
32 <varlistentry>
33 <term><parameter>request</parameter></term>
34 <listitem>
35 <para>FE_SET_TONE</para>
36 </listitem>
37 </varlistentry>
38 <varlistentry>
39 <term><parameter>tone</parameter></term>
40 <listitem>
41 <para>pointer to &fe-sec-tone-mode;</para>
42 </listitem>
43 </varlistentry>
44 </variablelist>
45 </refsect1>
46
47 <refsect1>
48 <title>Description</title>
49
50<para>This ioctl is used to set the generation of the continuous 22kHz tone.
51 This call requires read/write permissions.</para>
52<para>Usually, satellite antenna subsystems require that the digital TV
53 device to send a 22kHz tone in order to select between high/low band on
54 some dual-band LNBf. It is also used to send signals to DiSEqC equipment,
55 but this is done using the DiSEqC ioctls.</para>
56<para>NOTE: if more than one device is connected to the same antenna,
57 setting a tone may interfere on other devices, as they may lose
58 the capability of selecting the band. So, it is recommended that
59 applications would change to SEC_TONE_OFF when the device is not used.</para>
60
61&return-value-dvb;
62</refsect1>
63
64<refsect1 id="fe-sec-tone-mode-t">
65<title>enum fe_sec_tone_mode</title>
66
67<table pgwide="1" frame="none" id="fe-sec-tone-mode">
68 <title>enum fe_sec_tone_mode</title>
69 <tgroup cols="2">
70 &cs-def;
71 <thead>
72 <row>
73 <entry>ID</entry>
74 <entry>Description</entry>
75 </row>
76 </thead>
77 <tbody valign="top">
78 <row>
79 <entry align="char" id="SEC-TONE-ON"><constant>SEC_TONE_ON</constant></entry>
80 <entry align="char">Sends a 22kHz tone burst to the antenna</entry>
81 </row><row>
82 <entry align="char" id="SEC-TONE-OFF"><constant>SEC_TONE_OFF</constant></entry>
83 <entry align="char">Don't send a 22kHz tone to the antenna
84 (except if the FE_DISEQC_* ioctls are called)</entry>
85 </row>
86 </tbody>
87 </tgroup>
88</table>
89</refsect1>
90
91</refentry>
diff --git a/Documentation/DocBook/media/dvb/fe-set-voltage.xml b/Documentation/DocBook/media/dvb/fe-set-voltage.xml
new file mode 100644
index 000000000000..c89a6f79b5af
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/fe-set-voltage.xml
@@ -0,0 +1,69 @@
1<refentry id="FE_SET_VOLTAGE">
2 <refmeta>
3 <refentrytitle>ioctl FE_SET_VOLTAGE</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>FE_SET_VOLTAGE</refname>
9 <refpurpose>Allow setting the DC level sent to the antenna subsystem.</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>enum fe_sec_voltage *<parameter>voltage</parameter></paramdef>
19 </funcprototype>
20 </funcsynopsis>
21 </refsynopsisdiv>
22
23 <refsect1>
24 <title>Arguments</title>
25 <variablelist>
26 <varlistentry>
27 <term><parameter>fd</parameter></term>
28 <listitem>
29 <para>&fe_fd;</para>
30 </listitem>
31 </varlistentry>
32 <varlistentry>
33 <term><parameter>request</parameter></term>
34 <listitem>
35 <para>FE_SET_VOLTAGE</para>
36 </listitem>
37 </varlistentry>
38 <varlistentry>
39 <term><parameter>voltage</parameter></term>
40 <listitem>
41 <para>pointer to &fe-sec-voltage;</para>
42 <para>Valid values are described at &fe-sec-voltage;.</para>
43 </listitem>
44 </varlistentry>
45 </variablelist>
46 </refsect1>
47
48 <refsect1>
49 <title>Description</title>
50
51<para>This ioctl allows to set the DC voltage level sent through the antenna
52 cable to 13V, 18V or off.</para>
53<para>Usually, a satellite antenna subsystems require that the digital TV
54 device to send a DC voltage to feed power to the LNBf. Depending on the
55 LNBf type, the polarization or the intermediate frequency (IF) of the LNBf
56 can controlled by the voltage level. Other devices (for example, the ones
57 that implement DISEqC and multipoint LNBf's don't need to control the
58 voltage level, provided that either 13V or 18V is sent to power up the
59 LNBf.</para>
60<para>NOTE: if more than one device is connected to the same antenna,
61 setting a voltage level may interfere on other devices, as they may lose
62 the capability of setting polarization or IF. So, on those
63 cases, setting the voltage to SEC_VOLTAGE_OFF while the device is not is
64 used is recommended.</para>
65
66&return-value-dvb;
67</refsect1>
68
69</refentry>
diff --git a/Documentation/DocBook/media/dvb/frontend.xml b/Documentation/DocBook/media/dvb/frontend.xml
index 8a6a6ff27af5..01210b33c130 100644
--- a/Documentation/DocBook/media/dvb/frontend.xml
+++ b/Documentation/DocBook/media/dvb/frontend.xml
@@ -1,485 +1,112 @@
1<title>DVB Frontend API</title> 1<title>DVB Frontend API</title>
2 2
3<para>The DVB frontend device controls the tuner and DVB demodulator 3<para>The DVB frontend API was designed to support three types of delivery systems:</para>
4hardware. It can be accessed through <emphasis 4<itemizedlist>
5role="tt">/dev/dvb/adapter0/frontend0</emphasis>. Data types and and 5 <listitem><para>Terrestrial systems: DVB-T, DVB-T2, ATSC, ATSC M/H, ISDB-T, DVB-H, DTMB, CMMB</para></listitem>
6ioctl definitions can be accessed by including <emphasis 6 <listitem><para>Cable systems: DVB-C Annex A/C, ClearQAM (DVB-C Annex B), ISDB-C</para></listitem>
7role="tt">linux/dvb/frontend.h</emphasis> in your application.</para> 7 <listitem><para>Satellite systems: DVB-S, DVB-S2, DVB Turbo, ISDB-S, DSS</para></listitem>
8 8</itemizedlist>
9<para>DVB frontends come in three varieties: DVB-S (satellite), DVB-C 9<para>The DVB frontend controls several sub-devices including:</para>
10(cable) and DVB-T (terrestrial). Transmission via the internet (DVB-IP) 10<itemizedlist>
11is not yet handled by this API but a future extension is possible. For 11 <listitem><para>Tuner</para></listitem>
12DVB-S the frontend device also supports satellite equipment control 12 <listitem><para>Digital TV demodulator</para></listitem>
13(SEC) via DiSEqC and V-SEC protocols. The DiSEqC (digital SEC) 13 <listitem><para>Low noise amplifier (LNA)</para></listitem>
14specification is available from 14 <listitem><para>Satellite Equipment Control (SEC) hardware (only for Satellite).</para></listitem>
15</itemizedlist>
16<para>The frontend can be accessed through
17 <constant>/dev/dvb/adapter?/frontend?</constant>. Data types and
18 ioctl definitions can be accessed by including
19 <constant>linux/dvb/frontend.h</constant> in your application.
20</para>
21
22<para>NOTE: Transmission via the internet (DVB-IP)
23 is not yet handled by this API but a future extension is possible.</para>
24<para>On Satellite systems, the API support for the Satellite Equipment Control
25 (SEC) allows to power control and to send/receive signals to control the
26 antenna subsystem, selecting the polarization and choosing the Intermediate
27 Frequency IF) of the Low Noise Block Converter Feed Horn (LNBf). It
28 supports the DiSEqC and V-SEC protocols. The DiSEqC (digital SEC)
29specification is available at
15<ulink url="http://www.eutelsat.com/satellites/4_5_5.html">Eutelsat</ulink>.</para> 30<ulink url="http://www.eutelsat.com/satellites/4_5_5.html">Eutelsat</ulink>.</para>
16 31
17<para>Note that the DVB API may also be used for MPEG decoder-only PCI 32<section id="query-dvb-frontend-info">
18cards, in which case there exists no frontend device.</para> 33<title>Querying frontend information</title>
19
20<section id="frontend_types">
21<title>Frontend Data Types</title>
22
23<section id="fe-type-t">
24<title>Frontend type</title>
25
26<para>For historical reasons, frontend types are named by the type of modulation used in
27transmission. The fontend types are given by fe_type_t type, defined as:</para>
28
29<table pgwide="1" frame="none" id="fe-type">
30<title>Frontend types</title>
31<tgroup cols="3">
32 &cs-def;
33 <thead>
34 <row>
35 <entry>fe_type</entry>
36 <entry>Description</entry>
37 <entry><link linkend="DTV-DELIVERY-SYSTEM">DTV_DELIVERY_SYSTEM</link> equivalent type</entry>
38 </row>
39 </thead>
40 <tbody valign="top">
41 <row>
42 <entry id="FE_QPSK"><constant>FE_QPSK</constant></entry>
43 <entry>For DVB-S standard</entry>
44 <entry><constant>SYS_DVBS</constant></entry>
45 </row>
46 <row>
47 <entry id="FE_QAM"><constant>FE_QAM</constant></entry>
48 <entry>For DVB-C annex A standard</entry>
49 <entry><constant>SYS_DVBC_ANNEX_A</constant></entry>
50 </row>
51 <row>
52 <entry id="FE_OFDM"><constant>FE_OFDM</constant></entry>
53 <entry>For DVB-T standard</entry>
54 <entry><constant>SYS_DVBT</constant></entry>
55 </row>
56 <row>
57 <entry id="FE_ATSC"><constant>FE_ATSC</constant></entry>
58 <entry>For ATSC standard (terrestrial) or for DVB-C Annex B (cable) used in US.</entry>
59 <entry><constant>SYS_ATSC</constant> (terrestrial) or <constant>SYS_DVBC_ANNEX_B</constant> (cable)</entry>
60 </row>
61</tbody></tgroup></table>
62
63<para>Newer formats like DVB-S2, ISDB-T, ISDB-S and DVB-T2 are not described at the above, as they're
64supported via the new <link linkend="FE_GET_SET_PROPERTY">FE_GET_PROPERTY/FE_GET_SET_PROPERTY</link> ioctl's, using the <link linkend="DTV-DELIVERY-SYSTEM">DTV_DELIVERY_SYSTEM</link> parameter.
65</para>
66
67<para>The usage of this field is deprecated, as it doesn't report all supported standards, and
68will provide an incomplete information for frontends that support multiple delivery systems.
69Please use <link linkend="DTV-ENUM-DELSYS">DTV_ENUM_DELSYS</link> instead.</para>
70</section>
71
72<section id="fe-caps-t">
73<title>frontend capabilities</title>
74
75<para>Capabilities describe what a frontend can do. Some capabilities can only be supported for
76a specific frontend type.</para>
77<programlisting>
78 typedef enum fe_caps {
79 FE_IS_STUPID = 0,
80 FE_CAN_INVERSION_AUTO = 0x1,
81 FE_CAN_FEC_1_2 = 0x2,
82 FE_CAN_FEC_2_3 = 0x4,
83 FE_CAN_FEC_3_4 = 0x8,
84 FE_CAN_FEC_4_5 = 0x10,
85 FE_CAN_FEC_5_6 = 0x20,
86 FE_CAN_FEC_6_7 = 0x40,
87 FE_CAN_FEC_7_8 = 0x80,
88 FE_CAN_FEC_8_9 = 0x100,
89 FE_CAN_FEC_AUTO = 0x200,
90 FE_CAN_QPSK = 0x400,
91 FE_CAN_QAM_16 = 0x800,
92 FE_CAN_QAM_32 = 0x1000,
93 FE_CAN_QAM_64 = 0x2000,
94 FE_CAN_QAM_128 = 0x4000,
95 FE_CAN_QAM_256 = 0x8000,
96 FE_CAN_QAM_AUTO = 0x10000,
97 FE_CAN_TRANSMISSION_MODE_AUTO = 0x20000,
98 FE_CAN_BANDWIDTH_AUTO = 0x40000,
99 FE_CAN_GUARD_INTERVAL_AUTO = 0x80000,
100 FE_CAN_HIERARCHY_AUTO = 0x100000,
101 FE_CAN_8VSB = 0x200000,
102 FE_CAN_16VSB = 0x400000,
103 FE_HAS_EXTENDED_CAPS = 0x800000,
104 FE_CAN_MULTISTREAM = 0x4000000,
105 FE_CAN_TURBO_FEC = 0x8000000,
106 FE_CAN_2G_MODULATION = 0x10000000,
107 FE_NEEDS_BENDING = 0x20000000,
108 FE_CAN_RECOVER = 0x40000000,
109 FE_CAN_MUTE_TS = 0x80000000
110 } fe_caps_t;
111</programlisting>
112</section>
113
114<section id="dvb-frontend-info">
115<title>frontend information</title>
116
117<para>Information about the frontend ca be queried with
118 <link linkend="FE_GET_INFO">FE_GET_INFO</link>.</para>
119
120<programlisting>
121 struct dvb_frontend_info {
122 char name[128];
123 fe_type_t type;
124 uint32_t frequency_min;
125 uint32_t frequency_max;
126 uint32_t frequency_stepsize;
127 uint32_t frequency_tolerance;
128 uint32_t symbol_rate_min;
129 uint32_t symbol_rate_max;
130 uint32_t symbol_rate_tolerance; /&#x22C6; ppm &#x22C6;/
131 uint32_t notifier_delay; /&#x22C6; ms &#x22C6;/
132 fe_caps_t caps;
133 };
134</programlisting>
135</section>
136
137<section id="dvb-diseqc-master-cmd">
138<title>diseqc master command</title>
139
140<para>A message sent from the frontend to DiSEqC capable equipment.</para>
141<programlisting>
142 struct dvb_diseqc_master_cmd {
143 uint8_t msg [6]; /&#x22C6; { framing, address, command, data[3] } &#x22C6;/
144 uint8_t msg_len; /&#x22C6; valid values are 3...6 &#x22C6;/
145 };
146</programlisting>
147</section>
148<section role="subsection" id="dvb-diseqc-slave-reply">
149<title>diseqc slave reply</title>
150
151<para>A reply to the frontend from DiSEqC 2.0 capable equipment.</para>
152<programlisting>
153 struct dvb_diseqc_slave_reply {
154 uint8_t msg [4]; /&#x22C6; { framing, data [3] } &#x22C6;/
155 uint8_t msg_len; /&#x22C6; valid values are 0...4, 0 means no msg &#x22C6;/
156 int timeout; /&#x22C6; return from ioctl after timeout ms with &#x22C6;/
157 }; /&#x22C6; errorcode when no message was received &#x22C6;/
158</programlisting>
159</section>
160
161<section id="fe-sec-voltage-t">
162<title>diseqc slave reply</title>
163<para>The voltage is usually used with non-DiSEqC capable LNBs to switch the polarzation
164(horizontal/vertical). When using DiSEqC epuipment this voltage has to be switched
165consistently to the DiSEqC commands as described in the DiSEqC spec.</para>
166<programlisting>
167 typedef enum fe_sec_voltage {
168 SEC_VOLTAGE_13,
169 SEC_VOLTAGE_18
170 } fe_sec_voltage_t;
171</programlisting>
172</section>
173
174<section id="fe-sec-tone-mode-t">
175<title>SEC continuous tone</title>
176 34
177<para>The continuous 22KHz tone is usually used with non-DiSEqC capable LNBs to switch the 35<para>Usually, the first thing to do when the frontend is opened is to
178high/low band of a dual-band LNB. When using DiSEqC epuipment this voltage has to 36 check the frontend capabilities. This is done using <link linkend="FE_GET_INFO">FE_GET_INFO</link>. This ioctl will enumerate
179be switched consistently to the DiSEqC commands as described in the DiSEqC 37 the DVB API version and other characteristics about the frontend, and
180spec.</para> 38 can be opened either in read only or read/write mode.</para>
181<programlisting>
182 typedef enum fe_sec_tone_mode {
183 SEC_TONE_ON,
184 SEC_TONE_OFF
185 } fe_sec_tone_mode_t;
186</programlisting>
187</section> 39</section>
188 40
189<section id="fe-sec-mini-cmd-t"> 41<section id="dvb-fe-read-status">
190<title>SEC tone burst</title> 42<title>Querying frontend status and statistics</title>
191
192<para>The 22KHz tone burst is usually used with non-DiSEqC capable switches to select
193between two connected LNBs/satellites. When using DiSEqC epuipment this voltage has to
194be switched consistently to the DiSEqC commands as described in the DiSEqC
195spec.</para>
196<programlisting>
197 typedef enum fe_sec_mini_cmd {
198 SEC_MINI_A,
199 SEC_MINI_B
200 } fe_sec_mini_cmd_t;
201</programlisting>
202
203<para></para>
204</section>
205
206<section id="fe-status-t">
207<title>frontend status</title>
208<para>Several functions of the frontend device use the fe_status data type defined
209by</para>
210<programlisting>
211typedef enum fe_status {
212 FE_HAS_SIGNAL = 0x01,
213 FE_HAS_CARRIER = 0x02,
214 FE_HAS_VITERBI = 0x04,
215 FE_HAS_SYNC = 0x08,
216 FE_HAS_LOCK = 0x10,
217 FE_TIMEDOUT = 0x20,
218 FE_REINIT = 0x40,
219} fe_status_t;
220</programlisting>
221<para>to indicate the current state and/or state changes of the frontend hardware:
222</para>
223
224<informaltable><tgroup cols="2"><tbody>
225<row>
226<entry align="char">FE_HAS_SIGNAL</entry>
227<entry align="char">The frontend has found something above the noise level</entry>
228</row><row>
229<entry align="char">FE_HAS_CARRIER</entry>
230<entry align="char">The frontend has found a DVB signal</entry>
231</row><row>
232<entry align="char">FE_HAS_VITERBI</entry>
233<entry align="char">The frontend FEC inner coding (Viterbi, LDPC or other inner code) is stable</entry>
234</row><row>
235<entry align="char">FE_HAS_SYNC</entry>
236<entry align="char">Synchronization bytes was found</entry>
237</row><row>
238<entry align="char">FE_HAS_LOCK</entry>
239<entry align="char">The DVB were locked and everything is working</entry>
240</row><row>
241<entry align="char">FE_TIMEDOUT</entry>
242<entry align="char">no lock within the last about 2 seconds</entry>
243</row><row>
244<entry align="char">FE_REINIT</entry>
245<entry align="char">The frontend was reinitialized, application is
246recommended to reset DiSEqC, tone and parameters</entry>
247</row>
248</tbody></tgroup></informaltable>
249 43
44<para>Once <link linkend="FE_GET_PROPERTY"><constant>FE_SET_PROPERTY</constant></link>
45 is called, the frontend will run a kernel thread that will periodically
46 check for the tuner lock status and provide statistics about the quality
47 of the signal.</para>
48<para>The information about the frontend tuner locking status can be queried
49 using <link linkend="FE_READ_STATUS">FE_READ_STATUS</link>.</para>
50<para>Signal statistics are provided via <link linkend="FE_GET_PROPERTY"><constant>FE_GET_PROPERTY</constant></link>.
51 Please note that several statistics require the demodulator to be fully
52 locked (e. g. with FE_HAS_LOCK bit set). See
53 <link linkend="frontend-stat-properties">Frontend statistics indicators</link>
54 for more details.</para>
250</section> 55</section>
251 56
252<section id="dvb-frontend-parameters"> 57&sub-dvbproperty;
253<title>frontend parameters</title>
254<para>The kind of parameters passed to the frontend device for tuning depend on
255the kind of hardware you are using.</para>
256<para>The struct <constant>dvb_frontend_parameters</constant> uses an
257union with specific per-system parameters. However, as newer delivery systems
258required more data, the structure size weren't enough to fit, and just
259extending its size would break the existing applications. So, those parameters
260were replaced by the usage of <link linkend="FE_GET_SET_PROPERTY">
261<constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant></link> ioctl's. The
262new API is flexible enough to add new parameters to existing delivery systems,
263and to add newer delivery systems.</para>
264<para>So, newer applications should use <link linkend="FE_GET_SET_PROPERTY">
265<constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant></link> instead, in
266order to be able to support the newer System Delivery like DVB-S2, DVB-T2,
267DVB-C2, ISDB, etc.</para>
268<para>All kinds of parameters are combined as an union in the FrontendParameters structure:
269<programlisting>
270struct dvb_frontend_parameters {
271 uint32_t frequency; /&#x22C6; (absolute) frequency in Hz for QAM/OFDM &#x22C6;/
272 /&#x22C6; intermediate frequency in kHz for QPSK &#x22C6;/
273 fe_spectral_inversion_t inversion;
274 union {
275 struct dvb_qpsk_parameters qpsk;
276 struct dvb_qam_parameters qam;
277 struct dvb_ofdm_parameters ofdm;
278 struct dvb_vsb_parameters vsb;
279 } u;
280};
281</programlisting></para>
282<para>In the case of QPSK frontends the <constant>frequency</constant> field specifies the intermediate
283frequency, i.e. the offset which is effectively added to the local oscillator frequency (LOF) of
284the LNB. The intermediate frequency has to be specified in units of kHz. For QAM and
285OFDM frontends the <constant>frequency</constant> specifies the absolute frequency and is given in Hz.
286</para>
287
288<section id="dvb-qpsk-parameters">
289<title>QPSK parameters</title>
290<para>For satellite QPSK frontends you have to use the <constant>dvb_qpsk_parameters</constant> structure:</para>
291<programlisting>
292 struct dvb_qpsk_parameters {
293 uint32_t symbol_rate; /&#x22C6; symbol rate in Symbols per second &#x22C6;/
294 fe_code_rate_t fec_inner; /&#x22C6; forward error correction (see above) &#x22C6;/
295 };
296</programlisting>
297</section>
298<section id="dvb-qam-parameters">
299<title>QAM parameters</title>
300<para>for cable QAM frontend you use the <constant>dvb_qam_parameters</constant> structure:</para>
301<programlisting>
302 struct dvb_qam_parameters {
303 uint32_t symbol_rate; /&#x22C6; symbol rate in Symbols per second &#x22C6;/
304 fe_code_rate_t fec_inner; /&#x22C6; forward error correction (see above) &#x22C6;/
305 fe_modulation_t modulation; /&#x22C6; modulation type (see above) &#x22C6;/
306 };
307</programlisting>
308</section>
309<section id="dvb-vsb-parameters">
310<title>VSB parameters</title>
311<para>ATSC frontends are supported by the <constant>dvb_vsb_parameters</constant> structure:</para>
312<programlisting>
313struct dvb_vsb_parameters {
314 fe_modulation_t modulation; /&#x22C6; modulation type (see above) &#x22C6;/
315};
316</programlisting>
317</section>
318<section id="dvb-ofdm-parameters">
319<title>OFDM parameters</title>
320<para>DVB-T frontends are supported by the <constant>dvb_ofdm_parameters</constant> structure:</para>
321<programlisting>
322 struct dvb_ofdm_parameters {
323 fe_bandwidth_t bandwidth;
324 fe_code_rate_t code_rate_HP; /&#x22C6; high priority stream code rate &#x22C6;/
325 fe_code_rate_t code_rate_LP; /&#x22C6; low priority stream code rate &#x22C6;/
326 fe_modulation_t constellation; /&#x22C6; modulation type (see above) &#x22C6;/
327 fe_transmit_mode_t transmission_mode;
328 fe_guard_interval_t guard_interval;
329 fe_hierarchy_t hierarchy_information;
330 };
331</programlisting>
332</section>
333<section id="fe-spectral-inversion-t">
334<title>frontend spectral inversion</title>
335<para>The Inversion field can take one of these values:
336</para>
337<programlisting>
338typedef enum fe_spectral_inversion {
339 INVERSION_OFF,
340 INVERSION_ON,
341 INVERSION_AUTO
342} fe_spectral_inversion_t;
343</programlisting>
344<para>It indicates if spectral inversion should be presumed or not. In the automatic setting
345(<constant>INVERSION_AUTO</constant>) the hardware will try to figure out the correct setting by
346itself.
347</para>
348</section>
349<section id="fe-code-rate-t">
350<title>frontend code rate</title>
351<para>The possible values for the <constant>fec_inner</constant> field used on
352<link linkend="dvb-qpsk-parameters"><constant>struct dvb_qpsk_parameters</constant></link> and
353<link linkend="dvb-qam-parameters"><constant>struct dvb_qam_parameters</constant></link> are:
354</para>
355<programlisting>
356typedef enum fe_code_rate {
357 FEC_NONE = 0,
358 FEC_1_2,
359 FEC_2_3,
360 FEC_3_4,
361 FEC_4_5,
362 FEC_5_6,
363 FEC_6_7,
364 FEC_7_8,
365 FEC_8_9,
366 FEC_AUTO,
367 FEC_3_5,
368 FEC_9_10,
369} fe_code_rate_t;
370</programlisting>
371<para>which correspond to error correction rates of 1/2, 2/3, etc., no error correction or auto
372detection.
373</para>
374</section>
375<section id="fe-modulation-t">
376<title>frontend modulation type for QAM, OFDM and VSB</title>
377<para>For cable and terrestrial frontends, e. g. for
378<link linkend="dvb-qam-parameters"><constant>struct dvb_qpsk_parameters</constant></link>,
379<link linkend="dvb-ofdm-parameters"><constant>struct dvb_qam_parameters</constant></link> and
380<link linkend="dvb-vsb-parameters"><constant>struct dvb_qam_parameters</constant></link>,
381it needs to specify the quadrature modulation mode which can be one of the following:
382</para>
383<programlisting>
384 typedef enum fe_modulation {
385 QPSK,
386 QAM_16,
387 QAM_32,
388 QAM_64,
389 QAM_128,
390 QAM_256,
391 QAM_AUTO,
392 VSB_8,
393 VSB_16,
394 PSK_8,
395 APSK_16,
396 APSK_32,
397 DQPSK,
398 } fe_modulation_t;
399</programlisting>
400</section>
401<section>
402<title>More OFDM parameters</title>
403<section id="fe-transmit-mode-t">
404<title>Number of carriers per channel</title>
405<programlisting>
406typedef enum fe_transmit_mode {
407 TRANSMISSION_MODE_2K,
408 TRANSMISSION_MODE_8K,
409 TRANSMISSION_MODE_AUTO,
410 TRANSMISSION_MODE_4K,
411 TRANSMISSION_MODE_1K,
412 TRANSMISSION_MODE_16K,
413 TRANSMISSION_MODE_32K,
414 } fe_transmit_mode_t;
415</programlisting>
416</section>
417<section id="fe-bandwidth-t">
418<title>frontend bandwidth</title>
419<programlisting>
420typedef enum fe_bandwidth {
421 BANDWIDTH_8_MHZ,
422 BANDWIDTH_7_MHZ,
423 BANDWIDTH_6_MHZ,
424 BANDWIDTH_AUTO,
425 BANDWIDTH_5_MHZ,
426 BANDWIDTH_10_MHZ,
427 BANDWIDTH_1_712_MHZ,
428} fe_bandwidth_t;
429</programlisting>
430</section>
431<section id="fe-guard-interval-t">
432<title>frontend guard inverval</title>
433<programlisting>
434typedef enum fe_guard_interval {
435 GUARD_INTERVAL_1_32,
436 GUARD_INTERVAL_1_16,
437 GUARD_INTERVAL_1_8,
438 GUARD_INTERVAL_1_4,
439 GUARD_INTERVAL_AUTO,
440 GUARD_INTERVAL_1_128,
441 GUARD_INTERVAL_19_128,
442 GUARD_INTERVAL_19_256,
443} fe_guard_interval_t;
444</programlisting>
445</section>
446<section id="fe-hierarchy-t">
447<title>frontend hierarchy</title>
448<programlisting>
449typedef enum fe_hierarchy {
450 HIERARCHY_NONE,
451 HIERARCHY_1,
452 HIERARCHY_2,
453 HIERARCHY_4,
454 HIERARCHY_AUTO
455 } fe_hierarchy_t;
456</programlisting>
457</section>
458</section>
459
460</section>
461
462<section id="dvb-frontend-event">
463<title>frontend events</title>
464 <programlisting>
465 struct dvb_frontend_event {
466 fe_status_t status;
467 struct dvb_frontend_parameters parameters;
468 };
469</programlisting>
470 </section>
471</section>
472
473 58
474<section id="frontend_fcalls"> 59<section id="frontend_fcalls">
475<title>Frontend Function Calls</title> 60<title>Frontend Function Calls</title>
476 61
477<section id="frontend_f_open"> 62<refentry id="frontend_f_open">
478<title>open()</title> 63 <refmeta>
479<para>DESCRIPTION</para> 64 <refentrytitle>DVB frontend open()</refentrytitle>
480<informaltable><tgroup cols="1"><tbody><row> 65 &manvol;
481<entry align="char"> 66 </refmeta>
482<para>This system call opens a named frontend device (/dev/dvb/adapter0/frontend0) 67
68 <refnamediv>
69 <refname>fe-open</refname>
70 <refpurpose>Open a frontend device</refpurpose>
71 </refnamediv>
72
73 <refsynopsisdiv>
74 <funcsynopsis>
75 <funcsynopsisinfo>#include &lt;fcntl.h&gt;</funcsynopsisinfo>
76 <funcprototype>
77 <funcdef>int <function>open</function></funcdef>
78 <paramdef>const char *<parameter>device_name</parameter></paramdef>
79 <paramdef>int <parameter>flags</parameter></paramdef>
80 </funcprototype>
81 </funcsynopsis>
82 </refsynopsisdiv>
83
84 <refsect1>
85 <title>Arguments</title>
86
87 <variablelist>
88 <varlistentry>
89 <term><parameter>device_name</parameter></term>
90 <listitem>
91 <para>Device to be opened.</para>
92 </listitem>
93 </varlistentry>
94 <varlistentry>
95 <term><parameter>flags</parameter></term>
96 <listitem>
97 <para>Open flags. Access can either be
98 <constant>O_RDWR</constant> or <constant>O_RDONLY</constant>.</para>
99 <para>Multiple opens are allowed with <constant>O_RDONLY</constant>. In this mode, only query and read ioctls are allowed.</para>
100 <para>Only one open is allowed in <constant>O_RDWR</constant>. In this mode, all ioctls are allowed.</para>
101 <para>When the <constant>O_NONBLOCK</constant> flag is given, the system calls may return &EAGAIN; when no data is available or when the device driver is temporarily busy.</para>
102 <para>Other flags have no effect.</para>
103 </listitem>
104 </varlistentry>
105 </variablelist>
106 </refsect1>
107 <refsect1>
108 <title>Description</title>
109 <para>This system call opens a named frontend device (<constant>/dev/dvb/adapter?/frontend?</constant>)
483 for subsequent use. Usually the first thing to do after a successful open is to 110 for subsequent use. Usually the first thing to do after a successful open is to
484 find out the frontend type with <link linkend="FE_GET_INFO">FE_GET_INFO</link>.</para> 111 find out the frontend type with <link linkend="FE_GET_INFO">FE_GET_INFO</link>.</para>
485<para>The device can be opened in read-only mode, which only allows monitoring of 112<para>The device can be opened in read-only mode, which only allows monitoring of
@@ -497,1052 +124,146 @@ typedef enum fe_hierarchy {
497 for use in the specified mode. This implies that the corresponding hardware is 124 for use in the specified mode. This implies that the corresponding hardware is
498 powered up, and that other front-ends may have been powered down to make 125 powered up, and that other front-ends may have been powered down to make
499 that possible.</para> 126 that possible.</para>
500</entry> 127 </refsect1>
501 </row></tbody></tgroup></informaltable> 128
502 129 <refsect1>
503<para>SYNOPSIS</para> 130 <title>Return Value</title>
504<informaltable><tgroup cols="1"><tbody><row><entry 131
505 align="char"> 132 <para>On success <function>open</function> returns the new file
506<para>int open(const char &#x22C6;deviceName, int flags);</para> 133descriptor. On error -1 is returned, and the <varname>errno</varname>
507</entry> 134variable is set appropriately. Possible error codes are:</para>
508 </row></tbody></tgroup></informaltable> 135
509<para>PARAMETERS 136 <variablelist>
510</para> 137 <varlistentry>
511<informaltable><tgroup cols="2"><tbody><row><entry 138 <term><errorcode>EACCES</errorcode></term>
512 align="char"> 139 <listitem>
513<para>const char 140 <para>The caller has no permission to access the
514 *deviceName</para> 141device.</para>
515</entry><entry 142 </listitem>
516 align="char"> 143 </varlistentry>
517<para>Name of specific video device.</para> 144 <varlistentry>
518</entry> 145 <term><errorcode>EBUSY</errorcode></term>
519 </row><row><entry 146 <listitem>
520 align="char"> 147 <para>The the device driver is already in use.</para>
521<para>int flags</para> 148 </listitem>
522</entry><entry 149 </varlistentry>
523 align="char"> 150 <varlistentry>
524<para>A bit-wise OR of the following flags:</para> 151 <term><errorcode>ENXIO</errorcode></term>
525</entry> 152 <listitem>
526 </row><row><entry 153 <para>No device corresponding to this device special file
527 align="char"> 154exists.</para>
528</entry><entry 155 </listitem>
529 align="char"> 156 </varlistentry>
530<para>O_RDONLY read-only access</para> 157 <varlistentry>
531</entry> 158 <term><errorcode>ENOMEM</errorcode></term>
532 </row><row><entry 159 <listitem>
533 align="char"> 160 <para>Not enough kernel memory was available to complete the
534</entry><entry 161request.</para>
535 align="char"> 162 </listitem>
536<para>O_RDWR read/write access</para> 163 </varlistentry>
537</entry> 164 <varlistentry>
538 </row><row><entry 165 <term><errorcode>EMFILE</errorcode></term>
539 align="char"> 166 <listitem>
540</entry><entry 167 <para>The process already has the maximum number of
541 align="char"> 168files open.</para>
542<para>O_NONBLOCK open in non-blocking mode</para> 169 </listitem>
543</entry> 170 </varlistentry>
544 </row><row><entry 171 <varlistentry>
545 align="char"> 172 <term><errorcode>ENFILE</errorcode></term>
546</entry><entry 173 <listitem>
547 align="char"> 174 <para>The limit on the total number of files open on the
548<para>(blocking mode is the default)</para> 175system has been reached.</para>
549</entry> 176 </listitem>
550 </row></tbody></tgroup></informaltable> 177 </varlistentry>
551<para>RETURN VALUE</para> 178 <varlistentry>
552<informaltable><tgroup cols="2"><tbody><row><entry 179 <term><errorcode>ENODEV</errorcode></term>
553 align="char"> 180 <listitem>
554<para>ENODEV</para> 181 <para>The device got removed.</para>
555</entry><entry 182 </listitem>
556 align="char"> 183 </varlistentry>
557<para>Device driver not loaded/available.</para> 184 </variablelist>
558</entry> 185 </refsect1>
559 </row><row><entry 186</refentry>
560 align="char"> 187
561<para>EINTERNAL</para> 188<refentry id="frontend_f_close">
562</entry><entry 189 <refmeta>
563 align="char"> 190 <refentrytitle>DVB frontend close()</refentrytitle>
564<para>Internal error.</para> 191 &manvol;
565</entry> 192 </refmeta>
566 </row><row><entry 193
567 align="char"> 194 <refnamediv>
568<para>EBUSY</para> 195 <refname>fe-close</refname>
569</entry><entry 196 <refpurpose>Close a frontend device</refpurpose>
570 align="char"> 197 </refnamediv>
571<para>Device or resource busy.</para> 198
572</entry> 199 <refsynopsisdiv>
573 </row><row><entry 200 <funcsynopsis>
574 align="char"> 201 <funcsynopsisinfo>#include &lt;unistd.h&gt;</funcsynopsisinfo>
575<para>EINVAL</para> 202 <funcprototype>
576</entry><entry 203 <funcdef>int <function>close</function></funcdef>
577 align="char"> 204 <paramdef>int <parameter>fd</parameter></paramdef>
578<para>Invalid argument.</para> 205 </funcprototype>
579</entry> 206 </funcsynopsis>
580 </row></tbody></tgroup></informaltable> 207 </refsynopsisdiv>
581</section> 208
582 209 <refsect1>
583<section id="frontend_f_close"> 210 <title>Arguments</title>
584<title>close()</title> 211
585<para>DESCRIPTION 212 <variablelist>
586</para> 213 <varlistentry>
587<informaltable><tgroup cols="1"><tbody><row><entry 214 <term><parameter>fd</parameter></term>
588 align="char"> 215 <listitem>
216 <para>&fd;</para>
217 </listitem>
218 </varlistentry>
219 </variablelist>
220 </refsect1>
221
222 <refsect1>
223 <title>Description</title>
589<para>This system call closes a previously opened front-end device. After closing 224<para>This system call closes a previously opened front-end device. After closing
590 a front-end device, its corresponding hardware might be powered down 225 a front-end device, its corresponding hardware might be powered down
591 automatically.</para> 226 automatically.</para>
592</entry> 227</refsect1>
593 </row></tbody></tgroup></informaltable> 228 <refsect1>
594<para>SYNOPSIS 229 <title>Return Value</title>
595</para> 230
596<informaltable><tgroup cols="1"><tbody><row><entry 231 <para>The function returns <returnvalue>0</returnvalue> on
597 align="char"> 232success, <returnvalue>-1</returnvalue> on failure and the
598<para>int close(int fd);</para> 233<varname>errno</varname> is set appropriately. Possible error
599</entry> 234codes:</para>
600 </row></tbody></tgroup></informaltable> 235
601<para>PARAMETERS 236 <variablelist>
602</para> 237 <varlistentry>
603<informaltable><tgroup cols="2"><tbody><row><entry 238 <term><errorcode>EBADF</errorcode></term>
604 align="char"> 239 <listitem>
605<para>int fd</para> 240 <para><parameter>fd</parameter> is not a valid open file
606</entry><entry 241descriptor.</para>
607 align="char"> 242 </listitem>
608<para>File descriptor returned by a previous call to open().</para> 243 </varlistentry>
609</entry> 244 </variablelist>
610 </row></tbody></tgroup></informaltable> 245 </refsect1>
611<para>RETURN VALUE</para> 246</refentry>
612<informaltable><tgroup cols="2"><tbody><row><entry 247
613 align="char"> 248&sub-fe-get-info;
614<para>EBADF</para> 249&sub-fe-read-status;
615</entry><entry 250&sub-fe-get-property;
616 align="char"> 251&sub-fe-diseqc-reset-overload;
617<para>fd is not a valid open file descriptor.</para> 252&sub-fe-diseqc-send-master-cmd;
618</entry> 253&sub-fe-diseqc-recv-slave-reply;
619 </row></tbody></tgroup></informaltable> 254&sub-fe-diseqc-send-burst;
620</section> 255&sub-fe-set-tone;
621 256&sub-fe-set-voltage;
622<section id="FE_READ_STATUS"> 257&sub-fe-enable-high-lnb-voltage;
623<title>FE_READ_STATUS</title> 258&sub-fe-set-frontend-tune-mode;
624<para>DESCRIPTION 259
625</para> 260</section>
626<informaltable><tgroup cols="1"><tbody><row><entry 261
627 align="char"> 262<section id="frontend_legacy_dvbv3_api">
628<para>This ioctl call returns status information about the front-end. This call only 263<title>DVB Frontend legacy API (a. k. a. DVBv3)</title>
629 requires read-only access to the device.</para> 264<para>The usage of this API is deprecated, as it doesn't support all digital
630</entry> 265 TV standards, doesn't provide good statistics measurements and provides
631 </row></tbody></tgroup></informaltable> 266 incomplete information. This is kept only to support legacy applications.</para>
632<para>SYNOPSIS 267
633</para> 268&sub-frontend_legacy_api;
634<informaltable><tgroup cols="1"><tbody><row><entry
635 align="char">
636<para>int ioctl(int fd, int request = <link linkend="FE_READ_STATUS">FE_READ_STATUS</link>,
637 fe_status_t &#x22C6;status);</para>
638</entry>
639 </row></tbody></tgroup></informaltable>
640<para>PARAMETERS
641</para>
642
643<informaltable><tgroup cols="2"><tbody><row><entry
644 align="char">
645<para>int fd</para>
646</entry><entry
647 align="char">
648<para>File descriptor returned by a previous call to open().</para>
649</entry>
650 </row><row><entry
651 align="char">
652<para>int request</para>
653</entry><entry
654 align="char">
655<para>Equals <link linkend="FE_READ_STATUS">FE_READ_STATUS</link> for this command.</para>
656</entry>
657 </row><row><entry
658 align="char">
659<para>struct fe_status_t
660 *status</para>
661</entry><entry
662 align="char">
663<para>Points to the location where the front-end status word is
664 to be stored.</para>
665</entry>
666 </row></tbody></tgroup></informaltable>
667<para>RETURN VALUE</para>
668<informaltable><tgroup cols="2"><tbody><row><entry
669 align="char">
670<para>EBADF</para>
671</entry><entry
672 align="char">
673<para>fd is not a valid open file descriptor.</para>
674</entry>
675 </row><row><entry
676 align="char">
677<para>EFAULT</para>
678</entry><entry
679 align="char">
680<para>status points to invalid address.</para>
681</entry>
682 </row></tbody></tgroup></informaltable>
683</section>
684
685<section id="FE_READ_BER">
686<title>FE_READ_BER</title>
687<para>DESCRIPTION
688</para>
689<informaltable><tgroup cols="1"><tbody><row><entry
690 align="char">
691<para>This ioctl call returns the bit error rate for the signal currently
692 received/demodulated by the front-end. For this command, read-only access to
693 the device is sufficient.</para>
694</entry>
695 </row></tbody></tgroup></informaltable>
696<para>SYNOPSIS
697</para>
698<informaltable><tgroup cols="1"><tbody><row><entry
699 align="char">
700<para>int ioctl(int fd, int request = <link linkend="FE_READ_BER">FE_READ_BER</link>,
701 uint32_t &#x22C6;ber);</para>
702</entry>
703 </row></tbody></tgroup></informaltable>
704<para>PARAMETERS
705</para>
706<informaltable><tgroup cols="2"><tbody><row><entry
707 align="char">
708<para>int fd</para>
709</entry><entry
710 align="char">
711<para>File descriptor returned by a previous call to open().</para>
712</entry>
713 </row><row><entry
714 align="char">
715<para>int request</para>
716</entry><entry
717 align="char">
718<para>Equals <link linkend="FE_READ_BER">FE_READ_BER</link> for this command.</para>
719</entry>
720 </row><row><entry
721 align="char">
722<para>uint32_t *ber</para>
723</entry><entry
724 align="char">
725<para>The bit error rate is stored into *ber.</para>
726</entry>
727 </row></tbody></tgroup></informaltable>
728
729&return-value-dvb;
730</section>
731
732<section id="FE_READ_SNR">
733<title>FE_READ_SNR</title>
734
735<para>DESCRIPTION
736</para>
737<informaltable><tgroup cols="1"><tbody><row><entry
738 align="char">
739<para>This ioctl call returns the signal-to-noise ratio for the signal currently received
740 by the front-end. For this command, read-only access to the device is sufficient.</para>
741</entry>
742 </row></tbody></tgroup></informaltable>
743<para>SYNOPSIS
744</para>
745<informaltable><tgroup cols="1"><tbody><row><entry
746 align="char">
747<para>int ioctl(int fd, int request = <link linkend="FE_READ_SNR">FE_READ_SNR</link>, uint16_t
748 &#x22C6;snr);</para>
749</entry>
750 </row></tbody></tgroup></informaltable>
751<para>PARAMETERS
752</para>
753<informaltable><tgroup cols="2"><tbody><row><entry
754 align="char">
755<para>int fd</para>
756</entry><entry
757 align="char">
758<para>File descriptor returned by a previous call to open().</para>
759</entry>
760 </row><row><entry
761 align="char">
762<para>int request</para>
763</entry><entry
764 align="char">
765<para>Equals <link linkend="FE_READ_SNR">FE_READ_SNR</link> for this command.</para>
766</entry>
767 </row><row><entry
768 align="char">
769<para>uint16_t *snr</para>
770</entry><entry
771 align="char">
772<para>The signal-to-noise ratio is stored into *snr.</para>
773</entry>
774 </row></tbody></tgroup></informaltable>
775
776&return-value-dvb;
777</section>
778
779<section id="FE_READ_SIGNAL_STRENGTH">
780<title>FE_READ_SIGNAL_STRENGTH</title>
781<para>DESCRIPTION
782</para>
783<informaltable><tgroup cols="1"><tbody><row><entry
784 align="char">
785<para>This ioctl call returns the signal strength value for the signal currently received
786 by the front-end. For this command, read-only access to the device is sufficient.</para>
787</entry>
788 </row></tbody></tgroup></informaltable>
789<para>SYNOPSIS
790</para>
791<informaltable><tgroup cols="1"><tbody><row><entry
792 align="char">
793<para>int ioctl( int fd, int request =
794 <link linkend="FE_READ_SIGNAL_STRENGTH">FE_READ_SIGNAL_STRENGTH</link>, uint16_t &#x22C6;strength);</para>
795</entry>
796 </row></tbody></tgroup></informaltable>
797
798<para>PARAMETERS
799</para>
800<informaltable><tgroup cols="2"><tbody><row><entry
801 align="char">
802<para>int fd</para>
803</entry><entry
804 align="char">
805<para>File descriptor returned by a previous call to open().</para>
806</entry>
807 </row><row><entry
808 align="char">
809<para>int request</para>
810</entry><entry
811 align="char">
812<para>Equals <link linkend="FE_READ_SIGNAL_STRENGTH">FE_READ_SIGNAL_STRENGTH</link> for this
813 command.</para>
814</entry>
815 </row><row><entry
816 align="char">
817<para>uint16_t *strength</para>
818</entry><entry
819 align="char">
820<para>The signal strength value is stored into *strength.</para>
821</entry>
822 </row></tbody></tgroup></informaltable>
823
824&return-value-dvb;
825</section>
826
827<section id="FE_READ_UNCORRECTED_BLOCKS">
828<title>FE_READ_UNCORRECTED_BLOCKS</title>
829<para>DESCRIPTION
830</para>
831<informaltable><tgroup cols="1"><tbody><row><entry
832 align="char">
833<para>This ioctl call returns the number of uncorrected blocks detected by the device
834 driver during its lifetime. For meaningful measurements, the increment in block
835 count during a specific time interval should be calculated. For this command,
836 read-only access to the device is sufficient.</para>
837</entry>
838 </row><row><entry
839 align="char">
840<para>Note that the counter will wrap to zero after its maximum count has been
841 reached.</para>
842</entry>
843 </row></tbody></tgroup></informaltable>
844<para>SYNOPSIS
845</para>
846<informaltable><tgroup cols="1"><tbody><row><entry
847 align="char">
848<para>int ioctl( int fd, int request =
849 <link linkend="FE_READ_UNCORRECTED_BLOCKS">FE_READ_UNCORRECTED_BLOCKS</link>, uint32_t &#x22C6;ublocks);</para>
850</entry>
851 </row></tbody></tgroup></informaltable>
852<para>PARAMETERS
853</para>
854<informaltable><tgroup cols="2"><tbody><row><entry
855 align="char">
856<para>int fd</para>
857</entry><entry
858 align="char">
859<para>File descriptor returned by a previous call to open().</para>
860</entry>
861 </row><row><entry
862 align="char">
863<para>int request</para>
864</entry><entry
865 align="char">
866<para>Equals <link linkend="FE_READ_UNCORRECTED_BLOCKS">FE_READ_UNCORRECTED_BLOCKS</link> for this
867 command.</para>
868</entry>
869 </row><row><entry
870 align="char">
871<para>uint32_t *ublocks</para>
872</entry><entry
873 align="char">
874<para>The total number of uncorrected blocks seen by the driver
875 so far.</para>
876</entry>
877 </row></tbody></tgroup></informaltable>
878
879&return-value-dvb;
880</section>
881
882<section id="FE_SET_FRONTEND">
883<title>FE_SET_FRONTEND</title>
884<para>DESCRIPTION
885</para>
886<informaltable><tgroup cols="1"><tbody><row><entry
887 align="char">
888<para>This ioctl call starts a tuning operation using specified parameters. The result
889 of this call will be successful if the parameters were valid and the tuning could
890 be initiated. The result of the tuning operation in itself, however, will arrive
891 asynchronously as an event (see documentation for <link linkend="FE_GET_EVENT">FE_GET_EVENT</link> and
892 FrontendEvent.) If a new <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link> operation is initiated before
893 the previous one was completed, the previous operation will be aborted in favor
894 of the new one. This command requires read/write access to the device.</para>
895</entry>
896 </row></tbody></tgroup></informaltable>
897
898<para>SYNOPSIS
899</para>
900<informaltable><tgroup cols="1"><tbody><row><entry
901 align="char">
902<para>int ioctl(int fd, int request = <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link>,
903 struct dvb_frontend_parameters &#x22C6;p);</para>
904</entry>
905 </row></tbody></tgroup></informaltable>
906<para>PARAMETERS
907</para>
908<informaltable><tgroup cols="2"><tbody><row><entry
909 align="char">
910<para>int fd</para>
911</entry><entry
912 align="char">
913<para>File descriptor returned by a previous call to open().</para>
914</entry>
915 </row><row><entry
916 align="char">
917<para>int request</para>
918</entry><entry
919 align="char">
920<para>Equals <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link> for this command.</para>
921</entry>
922 </row><row><entry
923 align="char">
924<para>struct
925 dvb_frontend_parameters
926 *p</para>
927</entry><entry
928 align="char">
929<para>Points to parameters for tuning operation.</para>
930</entry>
931 </row></tbody></tgroup></informaltable>
932
933&return-value-dvb;
934<informaltable><tgroup cols="2"><tbody><row><entry
935 align="char">
936<para>EINVAL</para>
937</entry><entry
938 align="char">
939<para>Maximum supported symbol rate reached.</para>
940</entry>
941</row></tbody></tgroup></informaltable>
942</section>
943
944<section id="FE_GET_FRONTEND">
945<title>FE_GET_FRONTEND</title>
946<para>DESCRIPTION
947</para>
948<informaltable><tgroup cols="1"><tbody><row><entry
949 align="char">
950<para>This ioctl call queries the currently effective frontend parameters. For this
951 command, read-only access to the device is sufficient.</para>
952</entry>
953 </row></tbody></tgroup></informaltable>
954
955<para>SYNOPSIS
956</para>
957<informaltable><tgroup cols="1"><tbody><row><entry
958 align="char">
959<para>int ioctl(int fd, int request = <link linkend="FE_GET_FRONTEND">FE_GET_FRONTEND</link>,
960 struct dvb_frontend_parameters &#x22C6;p);</para>
961</entry>
962 </row></tbody></tgroup></informaltable>
963
964<para>PARAMETERS
965</para>
966<informaltable><tgroup cols="2"><tbody><row><entry
967 align="char">
968<para>int fd</para>
969</entry><entry
970 align="char">
971<para>File descriptor returned by a previous call to open().</para>
972</entry>
973 </row><row><entry
974 align="char">
975<para>int request</para>
976</entry><entry
977 align="char">
978<para>Equals <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link> for this command.</para>
979</entry>
980 </row><row><entry
981 align="char">
982<para>struct
983 dvb_frontend_parameters
984 *p</para>
985</entry><entry
986 align="char">
987<para>Points to parameters for tuning operation.</para>
988</entry>
989 </row></tbody></tgroup></informaltable>
990
991&return-value-dvb;
992<informaltable><tgroup cols="2"><tbody><row><entry
993 align="char">
994<para>EINVAL</para>
995</entry><entry
996 align="char">
997<para>Maximum supported symbol rate reached.</para>
998</entry>
999 </row></tbody></tgroup></informaltable>
1000
1001</section>
1002
1003<section id="FE_GET_EVENT">
1004<title>FE_GET_EVENT</title>
1005<para>DESCRIPTION
1006</para>
1007<informaltable><tgroup cols="1"><tbody><row><entry
1008 align="char">
1009<para>This ioctl call returns a frontend event if available. If an event is not
1010 available, the behavior depends on whether the device is in blocking or
1011 non-blocking mode. In the latter case, the call fails immediately with errno
1012 set to EWOULDBLOCK. In the former case, the call blocks until an event
1013 becomes available.</para>
1014</entry>
1015 </row><row><entry
1016 align="char">
1017<para>The standard Linux poll() and/or select() system calls can be used with the
1018 device file descriptor to watch for new events. For select(), the file descriptor
1019 should be included in the exceptfds argument, and for poll(), POLLPRI should
1020 be specified as the wake-up condition. Since the event queue allocated is
1021 rather small (room for 8 events), the queue must be serviced regularly to avoid
1022 overflow. If an overflow happens, the oldest event is discarded from the queue,
1023 and an error (EOVERFLOW) occurs the next time the queue is read. After
1024 reporting the error condition in this fashion, subsequent
1025 <link linkend="FE_GET_EVENT">FE_GET_EVENT</link>
1026 calls will return events from the queue as usual.</para>
1027</entry>
1028 </row><row><entry
1029 align="char">
1030<para>For the sake of implementation simplicity, this command requires read/write
1031 access to the device.</para>
1032</entry>
1033 </row></tbody></tgroup></informaltable>
1034
1035<para>SYNOPSIS
1036</para>
1037<informaltable><tgroup cols="1"><tbody><row><entry
1038 align="char">
1039<para>int ioctl(int fd, int request = QPSK_GET_EVENT,
1040 struct dvb_frontend_event &#x22C6;ev);</para>
1041</entry>
1042 </row></tbody></tgroup></informaltable>
1043
1044<para>PARAMETERS
1045</para>
1046<informaltable><tgroup cols="2"><tbody><row><entry
1047 align="char">
1048<para>int fd</para>
1049</entry><entry
1050 align="char">
1051<para>File descriptor returned by a previous call to open().</para>
1052</entry>
1053 </row><row><entry
1054 align="char">
1055<para>int request</para>
1056</entry><entry
1057 align="char">
1058<para>Equals <link linkend="FE_GET_EVENT">FE_GET_EVENT</link> for this command.</para>
1059</entry>
1060 </row><row><entry
1061 align="char">
1062<para>struct
1063 dvb_frontend_event
1064 *ev</para>
1065</entry><entry
1066 align="char">
1067<para>Points to the location where the event,</para>
1068</entry>
1069 </row><row><entry
1070 align="char">
1071</entry><entry
1072 align="char">
1073<para>if any, is to be stored.</para>
1074</entry>
1075 </row></tbody></tgroup></informaltable>
1076
1077&return-value-dvb;
1078<informaltable><tgroup cols="2"><tbody><row><entry
1079 align="char">
1080<para>EWOULDBLOCK</para>
1081</entry><entry
1082 align="char">
1083<para>There is no event pending, and the device is in
1084 non-blocking mode.</para>
1085</entry>
1086 </row><row><entry
1087 align="char">
1088<para>EOVERFLOW</para>
1089</entry><entry
1090 align="char">
1091<para>Overflow in event queue - one or more events were lost.</para>
1092</entry>
1093</row></tbody></tgroup></informaltable>
1094</section>
1095
1096<section id="FE_GET_INFO">
1097<title>FE_GET_INFO</title>
1098<para>DESCRIPTION
1099</para>
1100<informaltable><tgroup cols="1"><tbody><row><entry
1101 align="char">
1102<para>This ioctl call returns information about the front-end. This call only requires
1103 read-only access to the device.</para>
1104</entry>
1105 </row></tbody></tgroup></informaltable>
1106<para>SYNOPSIS
1107</para>
1108
1109<informaltable><tgroup cols="1"><tbody><row><entry
1110 align="char">
1111<para> int ioctl(int fd, int request = <link linkend="FE_GET_INFO">FE_GET_INFO</link>, struct
1112 dvb_frontend_info &#x22C6;info);</para>
1113</entry>
1114 </row></tbody></tgroup></informaltable>
1115<para>PARAMETERS
1116</para>
1117
1118<informaltable><tgroup cols="2"><tbody><row><entry
1119 align="char">
1120<para>int fd</para>
1121</entry><entry
1122 align="char">
1123<para>File descriptor returned by a previous call to open().</para>
1124</entry>
1125 </row><row><entry
1126 align="char">
1127<para>int request</para>
1128</entry><entry
1129 align="char">
1130<para>Equals <link linkend="FE_GET_INFO">FE_GET_INFO</link> for this command.</para>
1131</entry>
1132 </row><row><entry
1133 align="char">
1134<para>struct
1135 dvb_frontend_info
1136 *info</para>
1137</entry><entry
1138 align="char">
1139<para>Points to the location where the front-end information is
1140 to be stored.</para>
1141</entry>
1142 </row></tbody></tgroup></informaltable>
1143&return-value-dvb;
1144</section>
1145
1146<section id="FE_DISEQC_RESET_OVERLOAD">
1147<title>FE_DISEQC_RESET_OVERLOAD</title>
1148<para>DESCRIPTION
1149</para>
1150<informaltable><tgroup cols="1"><tbody><row><entry
1151 align="char">
1152<para>If the bus has been automatically powered off due to power overload, this ioctl
1153 call restores the power to the bus. The call requires read/write access to the
1154 device. This call has no effect if the device is manually powered off. Not all
1155 DVB adapters support this ioctl.</para>
1156</entry>
1157 </row></tbody></tgroup></informaltable>
1158
1159<para>SYNOPSIS
1160</para>
1161<informaltable><tgroup cols="1"><tbody><row><entry
1162 align="char">
1163<para>int ioctl(int fd, int request =
1164 <link linkend="FE_DISEQC_RESET_OVERLOAD">FE_DISEQC_RESET_OVERLOAD</link>);</para>
1165</entry>
1166 </row></tbody></tgroup></informaltable>
1167<para>PARAMETERS
1168</para>
1169<informaltable><tgroup cols="2"><tbody><row><entry
1170 align="char">
1171<para>int fd</para>
1172</entry><entry
1173 align="char">
1174<para>File descriptor returned by a previous call to open().</para>
1175</entry>
1176 </row><row><entry
1177 align="char">
1178<para>int request</para>
1179</entry><entry
1180 align="char">
1181<para>Equals <link linkend="FE_DISEQC_RESET_OVERLOAD">FE_DISEQC_RESET_OVERLOAD</link> for this
1182 command.</para>
1183</entry>
1184 </row></tbody></tgroup></informaltable>
1185
1186&return-value-dvb;
1187</section>
1188
1189<section id="FE_DISEQC_SEND_MASTER_CMD">
1190<title>FE_DISEQC_SEND_MASTER_CMD</title>
1191<para>DESCRIPTION
1192</para>
1193<informaltable><tgroup cols="1"><tbody><row><entry
1194 align="char">
1195<para>This ioctl call is used to send a a DiSEqC command.</para>
1196</entry>
1197 </row></tbody></tgroup></informaltable>
1198<para>SYNOPSIS
1199</para>
1200<informaltable><tgroup cols="1"><tbody><row><entry
1201 align="char">
1202<para>int ioctl(int fd, int request =
1203 <link linkend="FE_DISEQC_SEND_MASTER_CMD">FE_DISEQC_SEND_MASTER_CMD</link>, struct
1204 dvb_diseqc_master_cmd &#x22C6;cmd);</para>
1205</entry>
1206 </row></tbody></tgroup></informaltable>
1207
1208<para>PARAMETERS
1209</para>
1210<informaltable><tgroup cols="2"><tbody><row><entry
1211 align="char">
1212<para>int fd</para>
1213</entry><entry
1214 align="char">
1215<para>File descriptor returned by a previous call to open().</para>
1216</entry>
1217 </row><row><entry
1218 align="char">
1219<para>int request</para>
1220</entry><entry
1221 align="char">
1222<para>Equals <link linkend="FE_DISEQC_SEND_MASTER_CMD">FE_DISEQC_SEND_MASTER_CMD</link> for this
1223 command.</para>
1224</entry>
1225 </row><row><entry
1226 align="char">
1227<para>struct
1228 dvb_diseqc_master_cmd
1229 *cmd</para>
1230</entry><entry
1231 align="char">
1232<para>Pointer to the command to be transmitted.</para>
1233</entry>
1234 </row></tbody></tgroup></informaltable>
1235
1236&return-value-dvb;
1237</section> 269</section>
1238
1239<section id="FE_DISEQC_RECV_SLAVE_REPLY">
1240<title>FE_DISEQC_RECV_SLAVE_REPLY</title>
1241<para>DESCRIPTION
1242</para>
1243<informaltable><tgroup cols="1"><tbody><row><entry
1244 align="char">
1245<para>This ioctl call is used to receive reply to a DiSEqC 2.0 command.</para>
1246</entry>
1247 </row></tbody></tgroup></informaltable>
1248
1249<para>SYNOPSIS
1250</para>
1251<informaltable><tgroup cols="1"><tbody><row><entry
1252 align="char">
1253<para>int ioctl(int fd, int request =
1254 <link linkend="FE_DISEQC_RECV_SLAVE_REPLY">FE_DISEQC_RECV_SLAVE_REPLY</link>, struct
1255 dvb_diseqc_slave_reply &#x22C6;reply);</para>
1256</entry>
1257 </row></tbody></tgroup></informaltable>
1258
1259<para>PARAMETERS
1260</para>
1261<informaltable><tgroup cols="2"><tbody><row><entry
1262 align="char">
1263<para>int fd</para>
1264</entry><entry
1265 align="char">
1266<para>File descriptor returned by a previous call to open().</para>
1267</entry>
1268 </row><row><entry
1269 align="char">
1270<para>int request</para>
1271</entry><entry
1272 align="char">
1273<para>Equals <link linkend="FE_DISEQC_RECV_SLAVE_REPLY">FE_DISEQC_RECV_SLAVE_REPLY</link> for this
1274 command.</para>
1275</entry>
1276 </row><row><entry
1277 align="char">
1278<para>struct
1279 dvb_diseqc_slave_reply
1280 *reply</para>
1281</entry><entry
1282 align="char">
1283<para>Pointer to the command to be received.</para>
1284</entry>
1285 </row></tbody></tgroup></informaltable>
1286&return-value-dvb;
1287</section>
1288
1289<section id="FE_DISEQC_SEND_BURST">
1290<title>FE_DISEQC_SEND_BURST</title>
1291<para>DESCRIPTION
1292</para>
1293<informaltable><tgroup cols="1"><tbody><row><entry
1294 align="char">
1295<para>This ioctl call is used to send a 22KHz tone burst.</para>
1296</entry>
1297 </row></tbody></tgroup></informaltable>
1298
1299<para>SYNOPSIS
1300</para>
1301<informaltable><tgroup cols="1"><tbody><row><entry
1302 align="char">
1303<para>int ioctl(int fd, int request =
1304 <link linkend="FE_DISEQC_SEND_BURST">FE_DISEQC_SEND_BURST</link>, fe_sec_mini_cmd_t burst);</para>
1305</entry>
1306 </row></tbody></tgroup></informaltable>
1307
1308<para>PARAMETERS
1309</para>
1310<informaltable><tgroup cols="2"><tbody><row><entry
1311 align="char">
1312<para>int fd</para>
1313</entry><entry
1314 align="char">
1315<para>File descriptor returned by a previous call to open().</para>
1316</entry>
1317 </row><row><entry
1318 align="char">
1319<para>int request</para>
1320</entry><entry
1321 align="char">
1322<para>Equals <link linkend="FE_DISEQC_SEND_BURST">FE_DISEQC_SEND_BURST</link> for this command.</para>
1323</entry>
1324 </row><row><entry
1325 align="char">
1326<para>fe_sec_mini_cmd_t
1327 burst</para>
1328</entry><entry
1329 align="char">
1330<para>burst A or B.</para>
1331</entry>
1332 </row></tbody></tgroup></informaltable>
1333
1334&return-value-dvb;
1335</section>
1336
1337<section id="FE_SET_TONE">
1338<title>FE_SET_TONE</title>
1339<para>DESCRIPTION
1340</para>
1341<informaltable><tgroup cols="1"><tbody><row><entry
1342 align="char">
1343<para>This call is used to set the generation of the continuous 22kHz tone. This call
1344 requires read/write permissions.</para>
1345</entry>
1346 </row></tbody></tgroup></informaltable>
1347<para>SYNOPSIS
1348</para>
1349<informaltable><tgroup cols="1"><tbody><row><entry
1350 align="char">
1351<para>int ioctl(int fd, int request = <link linkend="FE_SET_TONE">FE_SET_TONE</link>,
1352 fe_sec_tone_mode_t tone);</para>
1353</entry>
1354 </row></tbody></tgroup></informaltable>
1355<para>PARAMETERS
1356</para>
1357<informaltable><tgroup cols="2"><tbody><row><entry
1358 align="char">
1359<para>int fd</para>
1360</entry><entry
1361 align="char">
1362<para>File descriptor returned by a previous call to open().</para>
1363</entry>
1364 </row><row><entry
1365 align="char">
1366<para>int request</para>
1367</entry><entry
1368 align="char">
1369<para>Equals <link linkend="FE_SET_TONE">FE_SET_TONE</link> for this command.</para>
1370</entry>
1371 </row><row><entry
1372 align="char">
1373<para>fe_sec_tone_mode_t
1374 tone</para>
1375</entry><entry
1376 align="char">
1377<para>The requested tone generation mode (on/off).</para>
1378</entry>
1379 </row></tbody></tgroup></informaltable>
1380&return-value-dvb;
1381</section>
1382
1383<section id="FE_SET_VOLTAGE">
1384<title>FE_SET_VOLTAGE</title>
1385<para>DESCRIPTION
1386</para>
1387<informaltable><tgroup cols="1"><tbody><row><entry
1388 align="char">
1389<para>This call is used to set the bus voltage. This call requires read/write
1390 permissions.</para>
1391</entry>
1392 </row></tbody></tgroup></informaltable>
1393<para>SYNOPSIS
1394</para>
1395<informaltable><tgroup cols="1"><tbody><row><entry
1396 align="char">
1397<para>int ioctl(int fd, int request = <link linkend="FE_SET_VOLTAGE">FE_SET_VOLTAGE</link>,
1398 fe_sec_voltage_t voltage);</para>
1399</entry>
1400 </row></tbody></tgroup></informaltable>
1401
1402<para>PARAMETERS
1403</para>
1404<informaltable><tgroup cols="2"><tbody><row><entry
1405 align="char">
1406<para>int fd</para>
1407</entry><entry
1408 align="char">
1409<para>File descriptor returned by a previous call to open().</para>
1410</entry>
1411 </row><row><entry
1412 align="char">
1413<para>int request</para>
1414</entry><entry
1415 align="char">
1416<para>Equals <link linkend="FE_SET_VOLTAGE">FE_SET_VOLTAGE</link> for this command.</para>
1417</entry>
1418 </row><row><entry
1419 align="char">
1420<para>fe_sec_voltage_t
1421 voltage</para>
1422</entry><entry
1423 align="char">
1424<para>The requested bus voltage.</para>
1425</entry>
1426 </row></tbody></tgroup></informaltable>
1427
1428&return-value-dvb;
1429</section>
1430
1431<section id="FE_ENABLE_HIGH_LNB_VOLTAGE">
1432<title>FE_ENABLE_HIGH_LNB_VOLTAGE</title>
1433<para>DESCRIPTION
1434</para>
1435<informaltable><tgroup cols="1"><tbody><row><entry
1436 align="char">
1437<para>If high != 0 enables slightly higher voltages instead of 13/18V (to compensate
1438 for long cables). This call requires read/write permissions. Not all DVB
1439 adapters support this ioctl.</para>
1440</entry>
1441 </row></tbody></tgroup></informaltable>
1442
1443<para>SYNOPSIS
1444</para>
1445<informaltable><tgroup cols="1"><tbody><row><entry
1446 align="char">
1447<para>int ioctl(int fd, int request =
1448 <link linkend="FE_ENABLE_HIGH_LNB_VOLTAGE">FE_ENABLE_HIGH_LNB_VOLTAGE</link>, int high);</para>
1449</entry>
1450 </row></tbody></tgroup></informaltable>
1451
1452<para>PARAMETERS
1453</para>
1454<informaltable><tgroup cols="2"><tbody><row><entry
1455 align="char">
1456<para>int fd</para>
1457</entry><entry
1458 align="char">
1459<para>File descriptor returned by a previous call to open().</para>
1460</entry>
1461 </row><row><entry
1462 align="char">
1463<para>int request</para>
1464</entry><entry
1465 align="char">
1466<para>Equals <link linkend="FE_SET_VOLTAGE">FE_SET_VOLTAGE</link> for this command.</para>
1467</entry>
1468 </row><row><entry
1469 align="char">
1470<para>int high</para>
1471</entry><entry
1472 align="char">
1473<para>The requested bus voltage.</para>
1474</entry>
1475 </row></tbody></tgroup></informaltable>
1476
1477&return-value-dvb;
1478</section>
1479
1480<section id="FE_SET_FRONTEND_TUNE_MODE">
1481<title>FE_SET_FRONTEND_TUNE_MODE</title>
1482<para>DESCRIPTION</para>
1483<informaltable><tgroup cols="1"><tbody><row>
1484<entry align="char">
1485<para>Allow setting tuner mode flags to the frontend.</para>
1486</entry>
1487</row></tbody></tgroup></informaltable>
1488
1489<para>SYNOPSIS</para>
1490<informaltable><tgroup cols="1"><tbody><row>
1491<entry align="char">
1492<para>int ioctl(int fd, int request =
1493<link linkend="FE_SET_FRONTEND_TUNE_MODE">FE_SET_FRONTEND_TUNE_MODE</link>, unsigned int flags);</para>
1494</entry>
1495</row></tbody></tgroup></informaltable>
1496
1497<para>PARAMETERS</para>
1498<informaltable><tgroup cols="2"><tbody><row>
1499<entry align="char">
1500 <para>unsigned int flags</para>
1501</entry>
1502<entry align="char">
1503<para>
1504FE_TUNE_MODE_ONESHOT When set, this flag will disable any zigzagging or other "normal" tuning behaviour. Additionally, there will be no automatic monitoring of the lock status, and hence no frontend events will be generated. If a frontend device is closed, this flag will be automatically turned off when the device is reopened read-write.
1505</para>
1506</entry>
1507 </row></tbody></tgroup></informaltable>
1508
1509&return-value-dvb;
1510</section>
1511
1512<section id="FE_DISHNETWORK_SEND_LEGACY_CMD">
1513 <title>FE_DISHNETWORK_SEND_LEGACY_CMD</title>
1514<para>DESCRIPTION</para>
1515<informaltable><tgroup cols="1"><tbody><row>
1516<entry align="char">
1517<para>WARNING: This is a very obscure legacy command, used only at stv0299 driver. Should not be used on newer drivers.</para>
1518<para>It provides a non-standard method for selecting Diseqc voltage on the frontend, for Dish Network legacy switches.</para>
1519<para>As support for this ioctl were added in 2004, this means that such dishes were already legacy in 2004.</para>
1520</entry>
1521</row></tbody></tgroup></informaltable>
1522
1523<para>SYNOPSIS</para>
1524<informaltable><tgroup cols="1"><tbody><row>
1525<entry align="char">
1526<para>int ioctl(int fd, int request =
1527 <link linkend="FE_DISHNETWORK_SEND_LEGACY_CMD">FE_DISHNETWORK_SEND_LEGACY_CMD</link>, unsigned long cmd);</para>
1528</entry>
1529</row></tbody></tgroup></informaltable>
1530
1531<para>PARAMETERS</para>
1532<informaltable><tgroup cols="2"><tbody><row>
1533<entry align="char">
1534 <para>unsigned long cmd</para>
1535</entry>
1536<entry align="char">
1537<para>
1538sends the specified raw cmd to the dish via DISEqC.
1539</para>
1540</entry>
1541 </row></tbody></tgroup></informaltable>
1542
1543&return-value-dvb;
1544</section>
1545
1546</section>
1547
1548&sub-dvbproperty;
diff --git a/Documentation/DocBook/media/dvb/frontend_legacy_api.xml b/Documentation/DocBook/media/dvb/frontend_legacy_api.xml
new file mode 100644
index 000000000000..8fadf3a4ba44
--- /dev/null
+++ b/Documentation/DocBook/media/dvb/frontend_legacy_api.xml
@@ -0,0 +1,654 @@
1<section id="frontend_legacy_types">
2<title>Frontend Legacy Data Types</title>
3
4<section id="fe-type-t">
5<title>Frontend type</title>
6
7<para>For historical reasons, frontend types are named by the type of modulation
8 used in transmission. The fontend types are given by fe_type_t type, defined as:</para>
9
10<table pgwide="1" frame="none" id="fe-type">
11<title>Frontend types</title>
12<tgroup cols="3">
13 &cs-def;
14 <thead>
15 <row>
16 <entry>fe_type</entry>
17 <entry>Description</entry>
18 <entry><link linkend="DTV-DELIVERY-SYSTEM">DTV_DELIVERY_SYSTEM</link> equivalent type</entry>
19 </row>
20 </thead>
21 <tbody valign="top">
22 <row>
23 <entry id="FE-QPSK"><constant>FE_QPSK</constant></entry>
24 <entry>For DVB-S standard</entry>
25 <entry><constant>SYS_DVBS</constant></entry>
26 </row>
27 <row>
28 <entry id="FE-QAM"><constant>FE_QAM</constant></entry>
29 <entry>For DVB-C annex A standard</entry>
30 <entry><constant>SYS_DVBC_ANNEX_A</constant></entry>
31 </row>
32 <row>
33 <entry id="FE-OFDM"><constant>FE_OFDM</constant></entry>
34 <entry>For DVB-T standard</entry>
35 <entry><constant>SYS_DVBT</constant></entry>
36 </row>
37 <row>
38 <entry id="FE-ATSC"><constant>FE_ATSC</constant></entry>
39 <entry>For ATSC standard (terrestrial) or for DVB-C Annex B (cable) used in US.</entry>
40 <entry><constant>SYS_ATSC</constant> (terrestrial) or <constant>SYS_DVBC_ANNEX_B</constant> (cable)</entry>
41 </row>
42</tbody></tgroup></table>
43
44<para>Newer formats like DVB-S2, ISDB-T, ISDB-S and DVB-T2 are not described at the above, as they're
45supported via the new <link linkend="FE_GET_PROPERTY">FE_GET_PROPERTY/FE_GET_SET_PROPERTY</link> ioctl's, using the <link linkend="DTV-DELIVERY-SYSTEM">DTV_DELIVERY_SYSTEM</link> parameter.
46</para>
47
48<para>In the old days, &dvb-frontend-info; used to contain
49 <constant>fe_type_t</constant> field to indicate the delivery systems,
50 filled with either FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC. While this is
51 still filled to keep backward compatibility, the usage of this
52 field is deprecated, as it can report just one delivery system, but some
53 devices support multiple delivery systems. Please use
54 <link linkend="DTV-ENUM-DELSYS">DTV_ENUM_DELSYS</link> instead.
55</para>
56<para>On devices that support multiple delivery systems,
57 &dvb-frontend-info;::<constant>fe_type_t</constant> is filled with the
58 currently standard, as selected by the last call to
59 <link linkend="FE_GET_PROPERTY">FE_SET_PROPERTY</link>
60 using the &DTV-DELIVERY-SYSTEM; property.</para>
61</section>
62
63<section id="fe-bandwidth-t">
64<title>Frontend bandwidth</title>
65
66<table pgwide="1" frame="none" id="fe-bandwidth">
67 <title>enum fe_bandwidth</title>
68 <tgroup cols="2">
69 &cs-def;
70 <thead>
71 <row>
72 <entry>ID</entry>
73 <entry>Description</entry>
74 </row>
75 </thead>
76 <tbody valign="top">
77 <row>
78 <entry id="BANDWIDTH-AUTO"><constant>BANDWIDTH_AUTO</constant></entry>
79 <entry>Autodetect bandwidth (if supported)</entry>
80 </row><row>
81 <entry id="BANDWIDTH-1-712-MHZ"><constant>BANDWIDTH_1_712_MHZ</constant></entry>
82 <entry>1.712 MHz</entry>
83 </row><row>
84 <entry id="BANDWIDTH-5-MHZ"><constant>BANDWIDTH_5_MHZ</constant></entry>
85 <entry>5 MHz</entry>
86 </row><row>
87 <entry id="BANDWIDTH-6-MHZ"><constant>BANDWIDTH_6_MHZ</constant></entry>
88 <entry>6 MHz</entry>
89 </row><row>
90 <entry id="BANDWIDTH-7-MHZ"><constant>BANDWIDTH_7_MHZ</constant></entry>
91 <entry>7 MHz</entry>
92 </row><row>
93 <entry id="BANDWIDTH-8-MHZ"><constant>BANDWIDTH_8_MHZ</constant></entry>
94 <entry>8 MHz</entry>
95 </row><row>
96 <entry id="BANDWIDTH-10-MHZ"><constant>BANDWIDTH_10_MHZ</constant></entry>
97 <entry>10 MHz</entry>
98 </row>
99 </tbody>
100 </tgroup>
101</table>
102
103</section>
104
105<section id="dvb-frontend-parameters">
106<title>frontend parameters</title>
107<para>The kind of parameters passed to the frontend device for tuning depend on
108the kind of hardware you are using.</para>
109<para>The struct <constant>dvb_frontend_parameters</constant> uses an
110union with specific per-system parameters. However, as newer delivery systems
111required more data, the structure size weren't enough to fit, and just
112extending its size would break the existing applications. So, those parameters
113were replaced by the usage of <link linkend="FE_GET_PROPERTY">
114<constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant></link> ioctl's. The
115new API is flexible enough to add new parameters to existing delivery systems,
116and to add newer delivery systems.</para>
117<para>So, newer applications should use <link linkend="FE_GET_PROPERTY">
118<constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant></link> instead, in
119order to be able to support the newer System Delivery like DVB-S2, DVB-T2,
120DVB-C2, ISDB, etc.</para>
121<para>All kinds of parameters are combined as an union in the FrontendParameters structure:
122<programlisting>
123struct dvb_frontend_parameters {
124 uint32_t frequency; /&#x22C6; (absolute) frequency in Hz for QAM/OFDM &#x22C6;/
125 /&#x22C6; intermediate frequency in kHz for QPSK &#x22C6;/
126 &fe-spectral-inversion-t; inversion;
127 union {
128 struct dvb_qpsk_parameters qpsk;
129 struct dvb_qam_parameters qam;
130 struct dvb_ofdm_parameters ofdm;
131 struct dvb_vsb_parameters vsb;
132 } u;
133};
134</programlisting></para>
135<para>In the case of QPSK frontends the <constant>frequency</constant> field specifies the intermediate
136frequency, i.e. the offset which is effectively added to the local oscillator frequency (LOF) of
137the LNB. The intermediate frequency has to be specified in units of kHz. For QAM and
138OFDM frontends the <constant>frequency</constant> specifies the absolute frequency and is given in Hz.
139</para>
140
141<section id="dvb-qpsk-parameters">
142<title>QPSK parameters</title>
143<para>For satellite QPSK frontends you have to use the <constant>dvb_qpsk_parameters</constant> structure:</para>
144<programlisting>
145 struct dvb_qpsk_parameters {
146 uint32_t symbol_rate; /&#x22C6; symbol rate in Symbols per second &#x22C6;/
147 &fe-code-rate-t; fec_inner; /&#x22C6; forward error correction (see above) &#x22C6;/
148 };
149</programlisting>
150</section>
151
152<section id="dvb-qam-parameters">
153<title>QAM parameters</title>
154<para>for cable QAM frontend you use the <constant>dvb_qam_parameters</constant> structure:</para>
155<programlisting>
156 struct dvb_qam_parameters {
157 uint32_t symbol_rate; /&#x22C6; symbol rate in Symbols per second &#x22C6;/
158 &fe-code-rate-t; fec_inner; /&#x22C6; forward error correction (see above) &#x22C6;/
159 &fe-modulation-t; modulation; /&#x22C6; modulation type (see above) &#x22C6;/
160 };
161</programlisting>
162</section>
163
164<section id="dvb-vsb-parameters">
165<title>VSB parameters</title>
166<para>ATSC frontends are supported by the <constant>dvb_vsb_parameters</constant> structure:</para>
167<programlisting>
168struct dvb_vsb_parameters {
169 &fe-modulation-t; modulation; /&#x22C6; modulation type (see above) &#x22C6;/
170};
171</programlisting>
172</section>
173
174<section id="dvb-ofdm-parameters">
175<title>OFDM parameters</title>
176<para>DVB-T frontends are supported by the <constant>dvb_ofdm_parameters</constant> structure:</para>
177<programlisting>
178 struct dvb_ofdm_parameters {
179 &fe-bandwidth-t; bandwidth;
180 &fe-code-rate-t; code_rate_HP; /&#x22C6; high priority stream code rate &#x22C6;/
181 &fe-code-rate-t; code_rate_LP; /&#x22C6; low priority stream code rate &#x22C6;/
182 &fe-modulation-t; constellation; /&#x22C6; modulation type (see above) &#x22C6;/
183 &fe-transmit-mode-t; transmission_mode;
184 &fe-guard-interval-t; guard_interval;
185 &fe-hierarchy-t; hierarchy_information;
186 };
187</programlisting>
188</section>
189</section>
190
191<section id="dvb-frontend-event">
192<title>frontend events</title>
193 <programlisting>
194 struct dvb_frontend_event {
195 fe_status_t status;
196 struct dvb_frontend_parameters parameters;
197 };
198</programlisting>
199 </section>
200</section>
201
202<section id="frontend_legacy_fcalls">
203<title>Frontend Legacy Function Calls</title>
204
205<para>Those functions are defined at DVB version 3. The support is kept in
206 the kernel due to compatibility issues only. Their usage is strongly
207 not recommended</para>
208
209<section id="FE_READ_BER">
210<title>FE_READ_BER</title>
211<para>DESCRIPTION
212</para>
213<informaltable><tgroup cols="1"><tbody><row><entry
214 align="char">
215<para>This ioctl call returns the bit error rate for the signal currently
216 received/demodulated by the front-end. For this command, read-only access to
217 the device is sufficient.</para>
218</entry>
219 </row></tbody></tgroup></informaltable>
220<para>SYNOPSIS
221</para>
222<informaltable><tgroup cols="1"><tbody><row><entry
223 align="char">
224<para>int ioctl(int fd, int request = <link linkend="FE_READ_BER">FE_READ_BER</link>,
225 uint32_t &#x22C6;ber);</para>
226</entry>
227 </row></tbody></tgroup></informaltable>
228<para>PARAMETERS
229</para>
230<informaltable><tgroup cols="2"><tbody><row><entry
231 align="char">
232<para>int fd</para>
233</entry><entry
234 align="char">
235<para>File descriptor returned by a previous call to open().</para>
236</entry>
237 </row><row><entry
238 align="char">
239<para>int request</para>
240</entry><entry
241 align="char">
242<para>Equals <link linkend="FE_READ_BER">FE_READ_BER</link> for this command.</para>
243</entry>
244 </row><row><entry
245 align="char">
246<para>uint32_t *ber</para>
247</entry><entry
248 align="char">
249<para>The bit error rate is stored into *ber.</para>
250</entry>
251 </row></tbody></tgroup></informaltable>
252
253&return-value-dvb;
254</section>
255
256<section id="FE_READ_SNR">
257<title>FE_READ_SNR</title>
258
259<para>DESCRIPTION
260</para>
261<informaltable><tgroup cols="1"><tbody><row><entry
262 align="char">
263<para>This ioctl call returns the signal-to-noise ratio for the signal currently received
264 by the front-end. For this command, read-only access to the device is sufficient.</para>
265</entry>
266 </row></tbody></tgroup></informaltable>
267<para>SYNOPSIS
268</para>
269<informaltable><tgroup cols="1"><tbody><row><entry
270 align="char">
271<para>int ioctl(int fd, int request = <link linkend="FE_READ_SNR">FE_READ_SNR</link>, uint16_t
272 &#x22C6;snr);</para>
273</entry>
274 </row></tbody></tgroup></informaltable>
275<para>PARAMETERS
276</para>
277<informaltable><tgroup cols="2"><tbody><row><entry
278 align="char">
279<para>int fd</para>
280</entry><entry
281 align="char">
282<para>File descriptor returned by a previous call to open().</para>
283</entry>
284 </row><row><entry
285 align="char">
286<para>int request</para>
287</entry><entry
288 align="char">
289<para>Equals <link linkend="FE_READ_SNR">FE_READ_SNR</link> for this command.</para>
290</entry>
291 </row><row><entry
292 align="char">
293<para>uint16_t *snr</para>
294</entry><entry
295 align="char">
296<para>The signal-to-noise ratio is stored into *snr.</para>
297</entry>
298 </row></tbody></tgroup></informaltable>
299
300&return-value-dvb;
301</section>
302
303<section id="FE_READ_SIGNAL_STRENGTH">
304<title>FE_READ_SIGNAL_STRENGTH</title>
305<para>DESCRIPTION
306</para>
307<informaltable><tgroup cols="1"><tbody><row><entry
308 align="char">
309<para>This ioctl call returns the signal strength value for the signal currently received
310 by the front-end. For this command, read-only access to the device is sufficient.</para>
311</entry>
312 </row></tbody></tgroup></informaltable>
313<para>SYNOPSIS
314</para>
315<informaltable><tgroup cols="1"><tbody><row><entry
316 align="char">
317<para>int ioctl( int fd, int request =
318 <link linkend="FE_READ_SIGNAL_STRENGTH">FE_READ_SIGNAL_STRENGTH</link>, uint16_t &#x22C6;strength);</para>
319</entry>
320 </row></tbody></tgroup></informaltable>
321
322<para>PARAMETERS
323</para>
324<informaltable><tgroup cols="2"><tbody><row><entry
325 align="char">
326<para>int fd</para>
327</entry><entry
328 align="char">
329<para>File descriptor returned by a previous call to open().</para>
330</entry>
331 </row><row><entry
332 align="char">
333<para>int request</para>
334</entry><entry
335 align="char">
336<para>Equals <link linkend="FE_READ_SIGNAL_STRENGTH">FE_READ_SIGNAL_STRENGTH</link> for this
337 command.</para>
338</entry>
339 </row><row><entry
340 align="char">
341<para>uint16_t *strength</para>
342</entry><entry
343 align="char">
344<para>The signal strength value is stored into *strength.</para>
345</entry>
346 </row></tbody></tgroup></informaltable>
347
348&return-value-dvb;
349</section>
350
351<section id="FE_READ_UNCORRECTED_BLOCKS">
352<title>FE_READ_UNCORRECTED_BLOCKS</title>
353<para>DESCRIPTION
354</para>
355<informaltable><tgroup cols="1"><tbody><row><entry
356 align="char">
357<para>This ioctl call returns the number of uncorrected blocks detected by the device
358 driver during its lifetime. For meaningful measurements, the increment in block
359 count during a specific time interval should be calculated. For this command,
360 read-only access to the device is sufficient.</para>
361</entry>
362 </row><row><entry
363 align="char">
364<para>Note that the counter will wrap to zero after its maximum count has been
365 reached.</para>
366</entry>
367 </row></tbody></tgroup></informaltable>
368<para>SYNOPSIS
369</para>
370<informaltable><tgroup cols="1"><tbody><row><entry
371 align="char">
372<para>int ioctl( int fd, int request =
373 <link linkend="FE_READ_UNCORRECTED_BLOCKS">FE_READ_UNCORRECTED_BLOCKS</link>, uint32_t &#x22C6;ublocks);</para>
374</entry>
375 </row></tbody></tgroup></informaltable>
376<para>PARAMETERS
377</para>
378<informaltable><tgroup cols="2"><tbody><row><entry
379 align="char">
380<para>int fd</para>
381</entry><entry
382 align="char">
383<para>File descriptor returned by a previous call to open().</para>
384</entry>
385 </row><row><entry
386 align="char">
387<para>int request</para>
388</entry><entry
389 align="char">
390<para>Equals <link linkend="FE_READ_UNCORRECTED_BLOCKS">FE_READ_UNCORRECTED_BLOCKS</link> for this
391 command.</para>
392</entry>
393 </row><row><entry
394 align="char">
395<para>uint32_t *ublocks</para>
396</entry><entry
397 align="char">
398<para>The total number of uncorrected blocks seen by the driver
399 so far.</para>
400</entry>
401 </row></tbody></tgroup></informaltable>
402
403&return-value-dvb;
404</section>
405
406<section id="FE_SET_FRONTEND">
407<title>FE_SET_FRONTEND</title>
408<para>DESCRIPTION
409</para>
410<informaltable><tgroup cols="1"><tbody><row><entry
411 align="char">
412<para>This ioctl call starts a tuning operation using specified parameters. The result
413 of this call will be successful if the parameters were valid and the tuning could
414 be initiated. The result of the tuning operation in itself, however, will arrive
415 asynchronously as an event (see documentation for <link linkend="FE_GET_EVENT">FE_GET_EVENT</link> and
416 FrontendEvent.) If a new <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link> operation is initiated before
417 the previous one was completed, the previous operation will be aborted in favor
418 of the new one. This command requires read/write access to the device.</para>
419</entry>
420 </row></tbody></tgroup></informaltable>
421
422<para>SYNOPSIS
423</para>
424<informaltable><tgroup cols="1"><tbody><row><entry
425 align="char">
426<para>int ioctl(int fd, int request = <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link>,
427 struct dvb_frontend_parameters &#x22C6;p);</para>
428</entry>
429 </row></tbody></tgroup></informaltable>
430<para>PARAMETERS
431</para>
432<informaltable><tgroup cols="2"><tbody><row><entry
433 align="char">
434<para>int fd</para>
435</entry><entry
436 align="char">
437<para>File descriptor returned by a previous call to open().</para>
438</entry>
439 </row><row><entry
440 align="char">
441<para>int request</para>
442</entry><entry
443 align="char">
444<para>Equals <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link> for this command.</para>
445</entry>
446 </row><row><entry
447 align="char">
448<para>struct
449 dvb_frontend_parameters
450 *p</para>
451</entry><entry
452 align="char">
453<para>Points to parameters for tuning operation.</para>
454</entry>
455 </row></tbody></tgroup></informaltable>
456
457&return-value-dvb;
458<informaltable><tgroup cols="2"><tbody><row><entry
459 align="char">
460<para>EINVAL</para>
461</entry><entry
462 align="char">
463<para>Maximum supported symbol rate reached.</para>
464</entry>
465</row></tbody></tgroup></informaltable>
466</section>
467
468<section id="FE_GET_FRONTEND">
469<title>FE_GET_FRONTEND</title>
470<para>DESCRIPTION
471</para>
472<informaltable><tgroup cols="1"><tbody><row><entry
473 align="char">
474<para>This ioctl call queries the currently effective frontend parameters. For this
475 command, read-only access to the device is sufficient.</para>
476</entry>
477 </row></tbody></tgroup></informaltable>
478
479<para>SYNOPSIS
480</para>
481<informaltable><tgroup cols="1"><tbody><row><entry
482 align="char">
483<para>int ioctl(int fd, int request = <link linkend="FE_GET_FRONTEND">FE_GET_FRONTEND</link>,
484 struct dvb_frontend_parameters &#x22C6;p);</para>
485</entry>
486 </row></tbody></tgroup></informaltable>
487
488<para>PARAMETERS
489</para>
490<informaltable><tgroup cols="2"><tbody><row><entry
491 align="char">
492<para>int fd</para>
493</entry><entry
494 align="char">
495<para>File descriptor returned by a previous call to open().</para>
496</entry>
497 </row><row><entry
498 align="char">
499<para>int request</para>
500</entry><entry
501 align="char">
502<para>Equals <link linkend="FE_SET_FRONTEND">FE_SET_FRONTEND</link> for this command.</para>
503</entry>
504 </row><row><entry
505 align="char">
506<para>struct
507 dvb_frontend_parameters
508 *p</para>
509</entry><entry
510 align="char">
511<para>Points to parameters for tuning operation.</para>
512</entry>
513 </row></tbody></tgroup></informaltable>
514
515&return-value-dvb;
516<informaltable><tgroup cols="2"><tbody><row><entry
517 align="char">
518<para>EINVAL</para>
519</entry><entry
520 align="char">
521<para>Maximum supported symbol rate reached.</para>
522</entry>
523 </row></tbody></tgroup></informaltable>
524
525</section>
526
527<section id="FE_GET_EVENT">
528<title>FE_GET_EVENT</title>
529<para>DESCRIPTION
530</para>
531<informaltable><tgroup cols="1"><tbody><row><entry
532 align="char">
533<para>This ioctl call returns a frontend event if available. If an event is not
534 available, the behavior depends on whether the device is in blocking or
535 non-blocking mode. In the latter case, the call fails immediately with errno
536 set to EWOULDBLOCK. In the former case, the call blocks until an event
537 becomes available.</para>
538</entry>
539 </row><row><entry
540 align="char">
541<para>The standard Linux poll() and/or select() system calls can be used with the
542 device file descriptor to watch for new events. For select(), the file descriptor
543 should be included in the exceptfds argument, and for poll(), POLLPRI should
544 be specified as the wake-up condition. Since the event queue allocated is
545 rather small (room for 8 events), the queue must be serviced regularly to avoid
546 overflow. If an overflow happens, the oldest event is discarded from the queue,
547 and an error (EOVERFLOW) occurs the next time the queue is read. After
548 reporting the error condition in this fashion, subsequent
549 <link linkend="FE_GET_EVENT">FE_GET_EVENT</link>
550 calls will return events from the queue as usual.</para>
551</entry>
552 </row><row><entry
553 align="char">
554<para>For the sake of implementation simplicity, this command requires read/write
555 access to the device.</para>
556</entry>
557 </row></tbody></tgroup></informaltable>
558
559<para>SYNOPSIS
560</para>
561<informaltable><tgroup cols="1"><tbody><row><entry
562 align="char">
563<para>int ioctl(int fd, int request = QPSK_GET_EVENT,
564 struct dvb_frontend_event &#x22C6;ev);</para>
565</entry>
566 </row></tbody></tgroup></informaltable>
567
568<para>PARAMETERS
569</para>
570<informaltable><tgroup cols="2"><tbody><row><entry
571 align="char">
572<para>int fd</para>
573</entry><entry
574 align="char">
575<para>File descriptor returned by a previous call to open().</para>
576</entry>
577 </row><row><entry
578 align="char">
579<para>int request</para>
580</entry><entry
581 align="char">
582<para>Equals <link linkend="FE_GET_EVENT">FE_GET_EVENT</link> for this command.</para>
583</entry>
584 </row><row><entry
585 align="char">
586<para>struct
587 dvb_frontend_event
588 *ev</para>
589</entry><entry
590 align="char">
591<para>Points to the location where the event,</para>
592</entry>
593 </row><row><entry
594 align="char">
595</entry><entry
596 align="char">
597<para>if any, is to be stored.</para>
598</entry>
599 </row></tbody></tgroup></informaltable>
600
601&return-value-dvb;
602<informaltable><tgroup cols="2"><tbody><row><entry
603 align="char">
604<para>EWOULDBLOCK</para>
605</entry><entry
606 align="char">
607<para>There is no event pending, and the device is in
608 non-blocking mode.</para>
609</entry>
610 </row><row><entry
611 align="char">
612<para>EOVERFLOW</para>
613</entry><entry
614 align="char">
615<para>Overflow in event queue - one or more events were lost.</para>
616</entry>
617</row></tbody></tgroup></informaltable>
618</section>
619
620<section id="FE_DISHNETWORK_SEND_LEGACY_CMD">
621 <title>FE_DISHNETWORK_SEND_LEGACY_CMD</title>
622<para>DESCRIPTION</para>
623<informaltable><tgroup cols="1"><tbody><row>
624<entry align="char">
625<para>WARNING: This is a very obscure legacy command, used only at stv0299 driver. Should not be used on newer drivers.</para>
626<para>It provides a non-standard method for selecting Diseqc voltage on the frontend, for Dish Network legacy switches.</para>
627<para>As support for this ioctl were added in 2004, this means that such dishes were already legacy in 2004.</para>
628</entry>
629</row></tbody></tgroup></informaltable>
630
631<para>SYNOPSIS</para>
632<informaltable><tgroup cols="1"><tbody><row>
633<entry align="char">
634<para>int ioctl(int fd, int request =
635 <link linkend="FE_DISHNETWORK_SEND_LEGACY_CMD">FE_DISHNETWORK_SEND_LEGACY_CMD</link>, unsigned long cmd);</para>
636</entry>
637</row></tbody></tgroup></informaltable>
638
639<para>PARAMETERS</para>
640<informaltable><tgroup cols="2"><tbody><row>
641<entry align="char">
642 <para>unsigned long cmd</para>
643</entry>
644<entry align="char">
645<para>
646sends the specified raw cmd to the dish via DISEqC.
647</para>
648</entry>
649 </row></tbody></tgroup></informaltable>
650
651&return-value-dvb;
652</section>
653
654</section>
diff --git a/Documentation/DocBook/media/dvb/intro.xml b/Documentation/DocBook/media/dvb/intro.xml
index 2048b53d19b9..bcc72c216402 100644
--- a/Documentation/DocBook/media/dvb/intro.xml
+++ b/Documentation/DocBook/media/dvb/intro.xml
@@ -129,41 +129,41 @@ hardware. It can depend on the individual security requirements of the
129platform, if and how many of the CA functions are made available to the 129platform, if and how many of the CA functions are made available to the
130application through this device.</para> 130application through this device.</para>
131 131
132<para>All devices can be found in the <emphasis role="tt">/dev</emphasis> 132<para>All devices can be found in the <constant>/dev</constant>
133tree under <emphasis role="tt">/dev/dvb</emphasis>. The individual devices 133tree under <constant>/dev/dvb</constant>. The individual devices
134are called:</para> 134are called:</para>
135 135
136<itemizedlist> 136<itemizedlist>
137<listitem> 137<listitem>
138 138
139<para><emphasis role="tt">/dev/dvb/adapterN/audioM</emphasis>,</para> 139<para><constant>/dev/dvb/adapterN/audioM</constant>,</para>
140</listitem> 140</listitem>
141<listitem> 141<listitem>
142<para><emphasis role="tt">/dev/dvb/adapterN/videoM</emphasis>,</para> 142<para><constant>/dev/dvb/adapterN/videoM</constant>,</para>
143</listitem> 143</listitem>
144<listitem> 144<listitem>
145<para><emphasis role="tt">/dev/dvb/adapterN/frontendM</emphasis>,</para> 145<para><constant>/dev/dvb/adapterN/frontendM</constant>,</para>
146</listitem> 146</listitem>
147 <listitem> 147 <listitem>
148 148
149<para><emphasis role="tt">/dev/dvb/adapterN/netM</emphasis>,</para> 149<para><constant>/dev/dvb/adapterN/netM</constant>,</para>
150</listitem> 150</listitem>
151 <listitem> 151 <listitem>
152 152
153<para><emphasis role="tt">/dev/dvb/adapterN/demuxM</emphasis>,</para> 153<para><constant>/dev/dvb/adapterN/demuxM</constant>,</para>
154</listitem> 154</listitem>
155 <listitem> 155 <listitem>
156 156
157<para><emphasis role="tt">/dev/dvb/adapterN/dvrM</emphasis>,</para> 157<para><constant>/dev/dvb/adapterN/dvrM</constant>,</para>
158</listitem> 158</listitem>
159 <listitem> 159 <listitem>
160 160
161<para><emphasis role="tt">/dev/dvb/adapterN/caM</emphasis>,</para></listitem></itemizedlist> 161<para><constant>/dev/dvb/adapterN/caM</constant>,</para></listitem></itemizedlist>
162 162
163<para>where N enumerates the DVB PCI cards in a system starting 163<para>where N enumerates the DVB PCI cards in a system starting
164from&#x00A0;0, and M enumerates the devices of each type within each 164from&#x00A0;0, and M enumerates the devices of each type within each
165adapter, starting from&#x00A0;0, too. We will omit the &#8220;<emphasis 165adapter, starting from&#x00A0;0, too. We will omit the &#8220;
166role="tt">/dev/dvb/adapterN/</emphasis>&#8221; in the further dicussion 166<constant>/dev/dvb/adapterN/</constant>&#8221; in the further dicussion
167of these devices. The naming scheme for the devices is the same wheter 167of these devices. The naming scheme for the devices is the same wheter
168devfs is used or not.</para> 168devfs is used or not.</para>
169 169
@@ -202,10 +202,10 @@ a partial path like:</para>
202</programlisting> 202</programlisting>
203 203
204<para>To enable applications to support different API version, an 204<para>To enable applications to support different API version, an
205additional include file <emphasis 205additional include file
206role="tt">linux/dvb/version.h</emphasis> exists, which defines the 206<constant>linux/dvb/version.h</constant> exists, which defines the
207constant <emphasis role="tt">DVB_API_VERSION</emphasis>. This document 207constant <constant>DVB_API_VERSION</constant>. This document
208describes <emphasis role="tt">DVB_API_VERSION 5.8</emphasis>. 208describes <constant>DVB_API_VERSION 5.10</constant>.
209</para> 209</para>
210 210
211</section> 211</section>
diff --git a/Documentation/DocBook/media/dvb/kdapi.xml b/Documentation/DocBook/media/dvb/kdapi.xml
index 6c11ec52cbee..68bcd33a82c3 100644
--- a/Documentation/DocBook/media/dvb/kdapi.xml
+++ b/Documentation/DocBook/media/dvb/kdapi.xml
@@ -1,8 +1,8 @@
1<title>Kernel Demux API</title> 1<title>Kernel Demux API</title>
2<para>The kernel demux API defines a driver-internal interface for registering low-level, 2<para>The kernel demux API defines a driver-internal interface for registering low-level,
3hardware specific driver to a hardware independent demux layer. It is only of interest for 3hardware specific driver to a hardware independent demux layer. It is only of interest for
4DVB device driver writers. The header file for this API is named <emphasis role="tt">demux.h</emphasis> and located in 4DVB device driver writers. The header file for this API is named <constant>demux.h</constant> and located in
5<emphasis role="tt">drivers/media/dvb-core</emphasis>. 5<constant>">drivers/media/dvb-core</constant>.
6</para> 6</para>
7<para>Maintainer note: This section must be reviewed. It is probably out of date. 7<para>Maintainer note: This section must be reviewed. It is probably out of date.
8</para> 8</para>
diff --git a/Documentation/DocBook/media/dvb/net.xml b/Documentation/DocBook/media/dvb/net.xml
index a193e86941b5..d2e44b7e07df 100644
--- a/Documentation/DocBook/media/dvb/net.xml
+++ b/Documentation/DocBook/media/dvb/net.xml
@@ -1,156 +1,238 @@
1<title>DVB Network API</title> 1<title>DVB Network API</title>
2<para>The DVB net device enables feeding of MPE (multi protocol encapsulation) packets 2<para>The DVB net device controls the mapping of data packages that are
3received via DVB into the Linux network protocol stack, e.g. for internet via satellite 3 part of a transport stream to be mapped into a virtual network interface,
4applications. It can be accessed through <emphasis role="tt">/dev/dvb/adapter0/net0</emphasis>. Data types and 4 visible through the standard Linux network protocol stack.</para>
5and ioctl definitions can be accessed by including <emphasis role="tt">linux/dvb/net.h</emphasis> in your 5<para>Currently, two encapsulations are supported:</para>
6application. 6<itemizedlist>
7</para> 7 <listitem><para><ulink url="http://en.wikipedia.org/wiki/Multiprotocol_Encapsulation">
8<section id="dvb_net_types"> 8 Multi Protocol Encapsulation (MPE)</ulink></para></listitem>
9<title>DVB Net Data Types</title> 9 <listitem><para><ulink url="http://en.wikipedia.org/wiki/Unidirectional_Lightweight_Encapsulation">
10 10 Ultra Lightweight Encapsulation (ULE)</ulink></para></listitem>
11<section id="dvb-net-if"> 11</itemizedlist>
12<title>struct dvb_net_if</title> 12
13<programlisting> 13<para>In order to create the Linux virtual network interfaces, an application
14struct dvb_net_if { 14 needs to tell to the Kernel what are the PIDs and the encapsulation types
15 __u16 pid; 15 that are present on the transport stream. This is done through
16 __u16 if_num; 16 <constant>/dev/dvb/adapter?/net?</constant> device node.
17 __u8 feedtype; 17 The data will be available via virtual <constant>dvb?_?</constant>
18#define DVB_NET_FEEDTYPE_MPE 0 /&#x22C6; multi protocol encapsulation &#x22C6;/ 18 network interfaces, and will be controled/routed via the standard
19#define DVB_NET_FEEDTYPE_ULE 1 /&#x22C6; ultra lightweight encapsulation &#x22C6;/ 19 ip tools (like ip, route, netstat, ifconfig, etc).</para>
20}; 20<para> Data types and and ioctl definitions are defined via
21</programlisting> 21 <constant>linux/dvb/net.h</constant> header.</para>
22</section>
23 22
24</section>
25<section id="net_fcalls"> 23<section id="net_fcalls">
26<title>DVB net Function Calls</title> 24<title>DVB net Function Calls</title>
27<para>To be written&#x2026; 25
28</para> 26
29 27<refentry id="NET_ADD_IF">
30<section id="NET_ADD_IF" 28 <refmeta>
31role="subsection"><title>NET_ADD_IF</title> 29 <refentrytitle>ioctl NET_ADD_IF</refentrytitle>
32<para>DESCRIPTION 30 &manvol;
33</para> 31 </refmeta>
34<informaltable><tgroup cols="1"><tbody><row><entry 32
35 align="char"> 33 <refnamediv>
36<para>This ioctl is undocumented. Documentation is welcome.</para> 34 <refname>NET_ADD_IF</refname>
37</entry> 35 <refpurpose>Creates a new network interface for a given Packet ID.</refpurpose>
38 </row></tbody></tgroup></informaltable> 36 </refnamediv>
39<para>SYNOPSIS 37
40</para> 38 <refsynopsisdiv>
41<informaltable><tgroup cols="1"><tbody><row><entry 39 <funcsynopsis>
42 align="char"> 40 <funcprototype>
43<para>int ioctl(fd, int request = NET_ADD_IF, 41 <funcdef>int <function>ioctl</function></funcdef>
44 struct dvb_net_if *if);</para> 42 <paramdef>int <parameter>fd</parameter></paramdef>
45</entry> 43 <paramdef>int <parameter>request</parameter></paramdef>
46 </row></tbody></tgroup></informaltable> 44 <paramdef>struct dvb_net_if *<parameter>net_if</parameter></paramdef>
47<para>PARAMETERS 45 </funcprototype>
48</para> 46 </funcsynopsis>
49<informaltable><tgroup cols="2"><tbody><row><entry 47 </refsynopsisdiv>
50 align="char"> 48
51<para>int fd</para> 49 <refsect1>
52</entry><entry 50 <title>Arguments</title>
53 align="char"> 51 <variablelist>
54<para>File descriptor returned by a previous call to open().</para> 52 <varlistentry>
55</entry> 53 <term><parameter>fd</parameter></term>
56 </row><row><entry 54 <listitem>
57 align="char"> 55 <para>&fe_fd;</para>
58<para>int request</para> 56 </listitem>
59</entry><entry 57 </varlistentry>
60 align="char"> 58 <varlistentry>
61<para>Equals NET_ADD_IF for this command.</para> 59 <term><parameter>request</parameter></term>
62</entry> 60 <listitem>
63 </row><row><entry 61 <para>FE_SET_TONE</para>
64 align="char"> 62 </listitem>
65<para>struct dvb_net_if *if 63 </varlistentry>
66</para> 64 <varlistentry>
67</entry><entry 65 <term><parameter>net_if</parameter></term>
68 align="char"> 66 <listitem>
69<para>Undocumented.</para> 67 <para>pointer to &dvb-net-if;</para>
70</entry> 68 </listitem>
71 </row></tbody></tgroup></informaltable> 69 </varlistentry>
70 </variablelist>
71 </refsect1>
72
73 <refsect1>
74 <title>Description</title>
75
76<para>The NET_ADD_IF ioctl system call selects the Packet ID (PID) that
77 contains a TCP/IP traffic, the type of encapsulation to be used (MPE or ULE)
78 and the interface number for the new interface to be created. When the
79 system call successfully returns, a new virtual network interface is created.</para>
80<para>The &dvb-net-if;::ifnum field will be filled with the number of the
81 created interface.</para>
82
72&return-value-dvb; 83&return-value-dvb;
73</section> 84</refsect1>
85
86<refsect1 id="dvb-net-if-t">
87<title>struct <structname>dvb_net_if</structname> description</title>
88
89<table pgwide="1" frame="none" id="dvb-net-if">
90 <title>struct <structname>dvb_net_if</structname></title>
91 <tgroup cols="2">
92 &cs-def;
93 <thead>
94 <row>
95 <entry>ID</entry>
96 <entry>Description</entry>
97 </row>
98 </thead>
99 <tbody valign="top">
100 <row>
101 <entry align="char">pid</entry>
102 <entry align="char">Packet ID (PID) of the MPEG-TS that contains
103 data</entry>
104 </row><row>
105 <entry align="char">ifnum</entry>
106 <entry align="char">number of the DVB interface.</entry>
107 </row><row>
108 <entry align="char">feedtype</entry>
109 <entry align="char">Encapsulation type of the feed. It can be:
110 <constant>DVB_NET_FEEDTYPE_MPE</constant> for MPE encoding
111 or
112 <constant>DVB_NET_FEEDTYPE_ULE</constant> for ULE encoding.
113 </entry>
114 </row>
115 </tbody>
116 </tgroup>
117</table>
118</refsect1>
119</refentry>
120
121<refentry id="NET_REMOVE_IF">
122 <refmeta>
123 <refentrytitle>ioctl NET_REMOVE_IF</refentrytitle>
124 &manvol;
125 </refmeta>
126
127 <refnamediv>
128 <refname>NET_REMOVE_IF</refname>
129 <refpurpose>Removes a network interface.</refpurpose>
130 </refnamediv>
131
132 <refsynopsisdiv>
133 <funcsynopsis>
134 <funcprototype>
135 <funcdef>int <function>ioctl</function></funcdef>
136 <paramdef>int <parameter>fd</parameter></paramdef>
137 <paramdef>int <parameter>request</parameter></paramdef>
138 <paramdef>int <parameter>ifnum</parameter></paramdef>
139 </funcprototype>
140 </funcsynopsis>
141 </refsynopsisdiv>
142
143 <refsect1>
144 <title>Arguments</title>
145 <variablelist>
146 <varlistentry>
147 <term><parameter>fd</parameter></term>
148 <listitem>
149 <para>&fe_fd;</para>
150 </listitem>
151 </varlistentry>
152 <varlistentry>
153 <term><parameter>request</parameter></term>
154 <listitem>
155 <para>FE_SET_TONE</para>
156 </listitem>
157 </varlistentry>
158 <varlistentry>
159 <term><parameter>net_if</parameter></term>
160 <listitem>
161 <para>number of the interface to be removed</para>
162 </listitem>
163 </varlistentry>
164 </variablelist>
165 </refsect1>
166
167 <refsect1>
168 <title>Description</title>
169
170<para>The NET_REMOVE_IF ioctl deletes an interface previously created
171 via &NET-ADD-IF;.</para>
74 172
75<section id="NET_REMOVE_IF"
76role="subsection"><title>NET_REMOVE_IF</title>
77<para>DESCRIPTION
78</para>
79<informaltable><tgroup cols="1"><tbody><row><entry
80 align="char">
81<para>This ioctl is undocumented. Documentation is welcome.</para>
82</entry>
83 </row></tbody></tgroup></informaltable>
84<para>SYNOPSIS
85</para>
86<informaltable><tgroup cols="1"><tbody><row><entry
87 align="char">
88<para>int ioctl(fd, int request = NET_REMOVE_IF);
89</para>
90</entry>
91 </row></tbody></tgroup></informaltable>
92<para>PARAMETERS
93</para>
94<informaltable><tgroup cols="2"><tbody><row><entry
95 align="char">
96<para>int fd</para>
97</entry><entry
98 align="char">
99<para>File descriptor returned by a previous call to open().</para>
100</entry>
101 </row><row><entry
102 align="char">
103<para>int request</para>
104</entry><entry
105 align="char">
106<para>Equals NET_REMOVE_IF for this command.</para>
107</entry>
108 </row></tbody></tgroup></informaltable>
109&return-value-dvb; 173&return-value-dvb;
110</section> 174</refsect1>
175</refentry>
176
177
178<refentry id="NET_GET_IF">
179 <refmeta>
180 <refentrytitle>ioctl NET_GET_IF</refentrytitle>
181 &manvol;
182 </refmeta>
183
184 <refnamediv>
185 <refname>NET_GET_IF</refname>
186 <refpurpose>Read the configuration data of an interface created via
187 &NET-ADD-IF;.</refpurpose>
188 </refnamediv>
189
190 <refsynopsisdiv>
191 <funcsynopsis>
192 <funcprototype>
193 <funcdef>int <function>ioctl</function></funcdef>
194 <paramdef>int <parameter>fd</parameter></paramdef>
195 <paramdef>int <parameter>request</parameter></paramdef>
196 <paramdef>struct dvb_net_if *<parameter>net_if</parameter></paramdef>
197 </funcprototype>
198 </funcsynopsis>
199 </refsynopsisdiv>
200
201 <refsect1>
202 <title>Arguments</title>
203 <variablelist>
204 <varlistentry>
205 <term><parameter>fd</parameter></term>
206 <listitem>
207 <para>&fe_fd;</para>
208 </listitem>
209 </varlistentry>
210 <varlistentry>
211 <term><parameter>request</parameter></term>
212 <listitem>
213 <para>FE_SET_TONE</para>
214 </listitem>
215 </varlistentry>
216 <varlistentry>
217 <term><parameter>net_if</parameter></term>
218 <listitem>
219 <para>pointer to &dvb-net-if;</para>
220 </listitem>
221 </varlistentry>
222 </variablelist>
223 </refsect1>
224
225 <refsect1>
226 <title>Description</title>
227
228<para>The NET_GET_IF ioctl uses the interface number given by the
229 &dvb-net-if;::ifnum field and fills the content of &dvb-net-if; with
230 the packet ID and encapsulation type used on such interface. If the
231 interface was not created yet with &NET-ADD-IF;, it will return -1 and
232 fill the <constant>errno</constant> with <constant>EINVAL</constant>
233 error code.</para>
111 234
112<section id="NET_GET_IF"
113role="subsection"><title>NET_GET_IF</title>
114<para>DESCRIPTION
115</para>
116<informaltable><tgroup cols="1"><tbody><row><entry
117 align="char">
118<para>This ioctl is undocumented. Documentation is welcome.</para>
119</entry>
120 </row></tbody></tgroup></informaltable>
121<para>SYNOPSIS
122</para>
123<informaltable><tgroup cols="1"><tbody><row><entry
124 align="char">
125<para>int ioctl(fd, int request = NET_GET_IF,
126 struct dvb_net_if *if);</para>
127</entry>
128 </row></tbody></tgroup></informaltable>
129<para>PARAMETERS
130</para>
131<informaltable><tgroup cols="2"><tbody><row><entry
132 align="char">
133<para>int fd</para>
134</entry><entry
135 align="char">
136<para>File descriptor returned by a previous call to open().</para>
137</entry>
138 </row><row><entry
139 align="char">
140<para>int request</para>
141</entry><entry
142 align="char">
143<para>Equals NET_GET_IF for this command.</para>
144</entry>
145 </row><row><entry
146 align="char">
147<para>struct dvb_net_if *if
148</para>
149</entry><entry
150 align="char">
151<para>Undocumented.</para>
152</entry>
153 </row></tbody></tgroup></informaltable>
154&return-value-dvb; 235&return-value-dvb;
155</section> 236</refsect1>
237</refentry>
156</section> 238</section>
diff --git a/Documentation/DocBook/media/dvb/video.xml b/Documentation/DocBook/media/dvb/video.xml
index 3ea1ca7e785e..71547fcd7ba0 100644
--- a/Documentation/DocBook/media/dvb/video.xml
+++ b/Documentation/DocBook/media/dvb/video.xml
@@ -1,12 +1,12 @@
1<title>DVB Video Device</title> 1<title>DVB Video Device</title>
2<para>The DVB video device controls the MPEG2 video decoder of the DVB hardware. It 2<para>The DVB video device controls the MPEG2 video decoder of the DVB hardware. It
3can be accessed through <emphasis role="tt">/dev/dvb/adapter0/video0</emphasis>. Data types and and 3can be accessed through <emphasis role="bold">/dev/dvb/adapter0/video0</emphasis>. Data types and and
4ioctl definitions can be accessed by including <emphasis role="tt">linux/dvb/video.h</emphasis> in your 4ioctl definitions can be accessed by including <emphasis role="bold">linux/dvb/video.h</emphasis> in your
5application. 5application.
6</para> 6</para>
7<para>Note that the DVB video device only controls decoding of the MPEG video stream, not 7<para>Note that the DVB video device only controls decoding of the MPEG video stream, not
8its presentation on the TV or computer screen. On PCs this is typically handled by an 8its presentation on the TV or computer screen. On PCs this is typically handled by an
9associated video4linux device, e.g. <emphasis role="tt">/dev/video</emphasis>, which allows scaling and defining output 9associated video4linux device, e.g. <emphasis role="bold">/dev/video</emphasis>, which allows scaling and defining output
10windows. 10windows.
11</para> 11</para>
12<para>Some DVB cards don&#8217;t have their own MPEG decoder, which results in the omission of 12<para>Some DVB cards don&#8217;t have their own MPEG decoder, which results in the omission of
@@ -24,7 +24,7 @@ have been created to replace that functionality.</para>
24 24
25<section id="video-format-t"> 25<section id="video-format-t">
26<title>video_format_t</title> 26<title>video_format_t</title>
27<para>The <emphasis role="tt">video_format_t</emphasis> data type defined by 27<para>The <constant>video_format_t</constant> data type defined by
28</para> 28</para>
29<programlisting> 29<programlisting>
30typedef enum { 30typedef enum {
@@ -74,7 +74,7 @@ typedef enum {
74</programlisting> 74</programlisting>
75<para>VIDEO_SOURCE_DEMUX selects the demultiplexer (fed either by the frontend or the 75<para>VIDEO_SOURCE_DEMUX selects the demultiplexer (fed either by the frontend or the
76DVR device) as the source of the video stream. If VIDEO_SOURCE_MEMORY 76DVR device) as the source of the video stream. If VIDEO_SOURCE_MEMORY
77is selected the stream comes from the application through the <emphasis role="tt">write()</emphasis> system 77is selected the stream comes from the application through the <emphasis role="bold">write()</emphasis> system
78call. 78call.
79</para> 79</para>
80</section> 80</section>
diff --git a/Documentation/DocBook/media/typical_media_device.svg b/Documentation/DocBook/media/typical_media_device.svg
new file mode 100644
index 000000000000..f0c82f72c4b6
--- /dev/null
+++ b/Documentation/DocBook/media/typical_media_device.svg
@@ -0,0 +1,28 @@
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<svg stroke-linejoin="round" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" clip-path="url(#a)" xml:space="preserve" fill-rule="evenodd" height="178.78mm" viewBox="0 0 24285.662 17877.829" width="251.99mm" version="1.2" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" preserveAspectRatio="xMidYMid" stroke-width="28.222"><defs><clipPath id="a" clipPathUnits="userSpaceOnUse"><rect y="0" x="0" width="28000" height="21000"/></clipPath></defs><g transform="matrix(1.004 0 0 1 -2185.6 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#fcf" d="m12231 4800c-516 0-1031 515-1031 1031v4124c0 516 515 1032 1031 1032h8538c516 0 1032-516 1032-1032v-4124c0-516-516-1031-1032-1031h-8538z"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#ffc" d="m3595 15607c-293 0-585 292-585 585v2340c0 293 292 586 585 586h3275c293 0 586-293 586-586v-2340c0-293-293-585-586-585h-3275z"/></g><g transform="translate(-2197.3 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#e6e6e6" d="m2663 2186c-461 0-922 461-922 922v11169c0 461 461 923 922 923h3692c461 0 922-462 922-923v-11169c0-461-461-922-922-922h-3692z"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#ff8080" d="m4461 8602h-2260v-1086h4520v1086h-2260z"/><path fill="none" d="m4461 8602h-2260v-1086h4520v1086h-2260z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="8275" x="2579" class="TextPosition"><tspan fill="#000000">Audio decoder</tspan></tspan></tspan></text>
3</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#ff8080" d="m4461 11772h-2260v-1270h4520v1270h-2260z"/><path fill="none" d="m4461 11772h-2260v-1270h4520v1270h-2260z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="11353" x="2617" class="TextPosition"><tspan fill="#000000">Video decoder</tspan></tspan></tspan></text>
4</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#ff8080" d="m4453 10217h-2269v-1224h4537v1224h-2268z"/><path fill="none" d="m4453 10217h-2269v-1224h4537v1224h-2268z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="9821" x="2571" class="TextPosition"><tspan fill="#000000">Audio encoder</tspan></tspan></tspan></text>
5</g><g transform="translate(-2140.9 -2468.2)" class="com.sun.star.drawing.RectangleShape"><path fill="#cfc" d="m15711 12832h-3810v-1281h7620v1281h-3810z"/><path fill="none" d="m15711 12832h-3810v-1281h7620v1281h-3810z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="12407" x="12377" class="TextPosition"><tspan fill="#000000">Button Key/IR input logic</tspan></tspan></tspan></text>
6</g><g transform="translate(-2140.9 -2411.8)" class="com.sun.star.drawing.RectangleShape"><path fill="#cfe7f5" d="m14169 14572h-2268v-1412h4536v1412h-2268z"/><path fill="none" d="m14169 14572h-2268v-1412h4536v1412h-2268z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="14082" x="12882" class="TextPosition"><tspan fill="#000000">EEPROM</tspan></tspan></tspan></text>
7</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#fc9" d="m5140 17662h-1563v-1715h3126v1715h-1563z"/><path fill="none" d="m5140 17662h-1563v-1715h3126v1715h-1563z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="17020" x="4276" class="TextPosition"><tspan fill="#000000">Sensor</tspan></tspan></tspan></text>
8</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m6719 8030 385-353v176h1167v-176l386 353-386 354v-177h-1167v177l-385-354z"/><path fill="none" d="m6719 8030 385-353v176h1167v-176l386 353-386 354v-177h-1167v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m6719 9612 385-353v176h1167v-176l386 353-386 354v-177h-1167v177l-385-354z"/><path fill="none" d="m6719 9612 385-353v176h1167v-176l386 353-386 354v-177h-1167v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m6721 11100 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z"/><path fill="none" d="m6721 11100 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2411.8)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9962 13854 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z"/><path fill="none" d="m9962 13854 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2468.2)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9962 12163 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z"/><path fill="none" d="m9962 12163 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9962 17158 670-353v176h2028v-176l671 353-671 354v-177h-2028v177l-670-354z"/><path fill="none" d="m9962 17158 670-353v176h2028v-176l671 353-671 354v-177h-2028v177l-670-354z" stroke="#3465af"/></g><g transform="matrix(0 .83339 -1.0005 0 30268 -5276.3)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m23229 12779 1009-978 1009 978h-505v2959h505l-1009 979-1009-979h504v-2959h-504z"/><path fill="none" d="m23229 12779 1009-978 1009 978h-505v2959h505l-1009 979-1009-979h504v-2959h-504z" stroke="#3465af"/></g><g transform="translate(-9973.6 -666.6)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="706px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="15832" x="24341" class="TextPosition" transform="matrix(0,-1,1,0,8509,40173)"><tspan fill="#000000">System Bus</tspan></tspan></tspan></text>
9</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#cff" d="m13151 9262h-1250v-875h2499v875h-1249z"/><path fill="none" d="m13151 9262h-1250v-875h2499v875h-1249z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="9040" x="12215" class="TextPosition"><tspan fill="#000000">Demux</tspan></tspan></tspan></text>
10</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9996 8765 373-357v178h1130v-178l374 357-374 358v-179h-1130v179l-373-358z"/><path fill="none" d="m9996 8765 373-357v178h1130v-178l374 357-374 358v-179h-1130v179l-373-358z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9996 7378 373-358v179h1130v-179l374 358-374 358v-179h-1130v179l-373-358z"/><path fill="none" d="m9996 7378 373-358v179h1130v-179l374 358-374 358v-179h-1130v179l-373-358z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#cff" d="m16322 7992h-4421v-1270h8841v1270h-4420z"/><path fill="none" d="m16322 7992h-4421v-1270h8841v1270h-4420z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="7573" x="12786" class="TextPosition"><tspan fill="#000000">Conditional Access Module</tspan></tspan></tspan></text>
11</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#ff8080" d="m4445 13287h-2269v-1224h4537v1224h-2268z"/><path fill="none" d="m4445 13287h-2269v-1224h4537v1224h-2268z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="12891" x="2601" class="TextPosition"><tspan fill="#000000">Video encoder</tspan></tspan></tspan></text>
12</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m6721 12634 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z"/><path fill="none" d="m6721 12634 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m20791 7545 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z"/><path fill="none" d="m20791 7545 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2028 -2186)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="14478" x="1990" class="TextPosition"><tspan fill="#000000">Radio / Analog TV</tspan></tspan></tspan></text>
13</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="700" class="TextParagraph"><tspan y="10724" x="14956" class="TextPosition"><tspan fill="#000000">Digital TV</tspan></tspan></tspan></text>
14</g><g transform="translate(-8970.5 -1395.8)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="494px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="19167" x="14724" class="TextPosition"><tspan fill="#000000">PS.: picture is not complete: other blocks may be present</tspan></tspan></tspan></text>
15</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="18561" x="4199" class="TextPosition"><tspan fill="#000000">Webcam</tspan></tspan></tspan></text>
16</g><g transform="translate(-2140.9 -2468.2)" class="com.sun.star.drawing.RectangleShape"><path fill="#f90" d="m14552 16372h-2650v-1412h5299v1412h-2649z"/><path fill="none" d="m14552 16372h-2650v-1412h5299v1412h-2649z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="15882" x="12265" class="TextPosition"><tspan fill="#000000">Processing blocks</tspan></tspan></tspan></text>
17</g><g transform="translate(-2140.9 -2468.2)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9962 15654 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z"/><path fill="none" d="m9962 15654 385-353v176h1166v-176l386 353-386 354v-177h-1166v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m6702 16954 397-353v176h1201v-176l398 353-398 354v-177h-1201v177l-397-354z"/><path fill="none" d="m6702 16954 397-353v176h1201v-176l398 353-398 354v-177h-1201v177l-397-354z" stroke="#3465af"/></g><g transform="translate(-2479.5 -2186)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="8792" x="22850" class="TextPosition"><tspan fill="#000000">Smartcard</tspan></tspan></tspan></text>
18</g><g transform="matrix(1.0048 0 0 1 -2207.4 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#fcf" d="m2766 2600c-333 0-666 333-666 666v2668c0 333 333 666 666 666h18368c333 0 667-333 667-666v-2668c0-333-334-666-667-666h-18368z"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#ff8080" d="m5121 5155h-1614v-1816h3227v1816h-1613z"/><path fill="none" d="m5121 5155h-1614v-1816h3227v1816h-1613z" stroke="#3465af"/><text font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextShape"><tspan class="TextParagraph"><tspan y="4111" x="4374" class="TextPosition"><tspan fill="#000000">Tuner</tspan></tspan></tspan><tspan class="TextParagraph"><tspan y="4814" x="4151" class="TextPosition"><tspan fill="#000000">FM/TV</tspan></tspan></tspan></text>
19</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#ff8080" d="m2902 3702c0 111 40 202 88 202h530c48 0 89-91 89-202 0-110-41-202-89-202h-530c-48 0-88 92-88 202z"/><path fill="none" d="m2902 3702c0 111 40 202 88 202h530c48 0 89-91 89-202 0-110-41-202-89-202h-530c-48 0-88 92-88 202z" stroke="#3465af"/><path fill="#ffb3b3" d="m2902 3702c0 111 40 202 88 202s88-91 88-202c0-110-40-202-88-202s-88 92-88 202z"/><path fill="none" d="m2902 3702c0 111 40 202 88 202s88-91 88-202c0-110-40-202-88-202s-88 92-88 202z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#ff8080" d="m2903 4267c0 110 40 202 88 202h530c48 0 89-92 89-202s-41-203-89-203h-530c-48 0-88 93-88 203z"/><path fill="none" d="m2903 4267c0 110 40 202 88 202h530c48 0 89-92 89-202s-41-203-89-203h-530c-48 0-88 93-88 203z" stroke="#3465af"/><path fill="#ffb3b3" d="m2903 4267c0 110 40 202 88 202s88-92 88-202-40-203-88-203-88 93-88 203z"/><path fill="none" d="m2903 4267c0 110 40 202 88 202s88-92 88-202-40-203-88-203-88 93-88 203z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m6719 4196 385-353v176h1167v-176l386 353-386 354v-177h-1167v177l-385-354z"/><path fill="none" d="m6719 4196 385-353v176h1167v-176l386 353-386 354v-177h-1167v177l-385-354z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9979 4150 402-368v184h1217v-184l403 368-403 369v-185h-1217v185l-402-369z"/><path fill="none" d="m9979 4150 402-368v184h1217v-184l403 368-403 369v-185h-1217v185l-402-369z" stroke="#3465af"/></g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.RectangleShape"><path fill="#cff" d="m16500 6189h-4500v-1389h9e3v1389h-4500z"/><path fill="none" d="m16500 6189h-4500v-1389h9e3v1389h-4500z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="5710" x="12051" class="TextPosition"><tspan fill="#000000">Satellite Equipment Control (SEC)</tspan></tspan></tspan></text>
20</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#cff" d="m13400 4600h-1400v-1e3h2800v1e3h-1400z"/><path fill="none" d="m13400 4600h-1400v-1e3h2800v1e3h-1400z" stroke="#3465af"/><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="4316" x="12465" class="TextPosition"><tspan fill="#000000">Demod</tspan></tspan></tspan></text>
21</g><g transform="translate(-2140.9 -2186)" class="com.sun.star.drawing.CustomShape"><path fill="#729fcf" d="m9979 5451 402-368v184h1217v-184l403 368-403 369v-185h-1217v185l-402-369z"/><path fill="none" d="m9979 5451 402-368v184h1217v-184l403 368-403 369v-185h-1217v185l-402-369z" stroke="#3465af"/></g><path fill="#ff9" d="m7855.1 9099v7302h-1270v-14605h1270v7303z"/><path fill="none" d="m7855.1 9099v7302h-1270v-14605h1270v7303z" stroke="#3465af"/><text y="-6640.4663" x="-20770.572" transform="rotate(-90)" class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="7409.5396" x="-11193.634" class="TextPosition" transform="matrix(0,-1,1,0,-4473,23627)"><tspan fill="#000000">I2C Bus (control bus)</tspan></tspan></tspan></text>
22<g transform="translate(-2197.3 -2186)" class="com.sun.star.drawing.TextShape"><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="3278" x="9391" class="TextPosition"><tspan fill="#000000">Digital TV Frontend</tspan></tspan></tspan></text>
23</g><g transform="matrix(1.015 0 0 .99994 -2233.3 -2185.7)" class="com.sun.star.drawing.CustomShape"><g stroke="#3465af" fill="none"><path d="m3e3 2800c-18 0-35 1-53 3"/><path d="m2915 2808c-17 3-35 7-52 12"/><path d="m2832 2830c-16 6-33 12-49 20"/><path d="m2754 2864c-15 8-31 17-46 27"/><path d="m2681 2909c-14 10-28 21-42 32"/><path d="m2614 2962c-13 12-26 24-38 37"/><path d="m2554 3023c-11 13-22 27-33 41"/><path d="m2502 3091c-10 14-19 29-28 45"/><path d="m2459 3164c-8 16-15 32-22 49"/><path d="m2426 3243c-5 17-10 34-14 51"/><path d="m2406 3326c-3 18-5 35-6 53"/><path d="m2400 3411v53"/><path d="m2400 3497v53"/><path d="m2400 3582v53"/><path d="m2400 3668v53"/><path d="m2400 3753v53"/><path d="m2400 3839v53"/><path d="m2400 3924v53"/><path d="m2400 4009v54"/><path d="m2400 4095v53"/><path d="m2400 4180v53"/><path d="m2400 4266v53"/><path d="m2400 4351v53"/><path d="m2400 4437v53"/><path d="m2400 4522v53"/><path d="m2400 4607v54"/><path d="m2400 4693v53"/><path d="m2400 4778v53"/><path d="m2400 4864v53"/><path d="m2400 4949v53"/><path d="m2400 5035v53"/><path d="m2400 5120v53"/><path d="m2400 5205v54"/><path d="m2400 5291v53"/><path d="m2400 5376v53"/><path d="m2400 5462v53"/><path d="m2400 5547v53"/><path d="m2400 5633v53"/><path d="m2400 5718v53"/><path d="m2400 5803c0 18 1 36 3 53"/><path d="m2408 5888c4 18 8 35 13 52"/><path d="m2431 5971c6 16 13 33 20 49"/><path d="m2466 6049c8 15 17 31 27 46"/><path d="m2511 6122c10 14 21 28 32 42"/><path d="m2564 6188c12 13 25 26 38 38"/><path d="m2626 6248c13 11 27 23 41 33"/><path d="m2694 6300c14 10 29 19 45 27"/><path d="m2768 6343c15 7 32 15 48 21"/><path d="m2847 6375c17 5 34 10 51 14"/><path d="m2930 6395c17 2 35 4 53 5"/><path d="m3015 6400h53"/><path d="m3100 6400h53"/><path d="m3186 6400h53"/><path d="m3271 6400h53"/><path d="m3357 6400h53"/><path d="m3442 6400h53"/><path d="m3527 6400h54"/><path d="m3613 6400h53"/><path d="m3698 6400h53"/><path d="m3784 6400h53"/><path d="m3869 6400h53"/><path d="m3955 6400h53"/><path d="m4040 6400h53"/><path d="m4125 6400h54"/><path d="m4211 6400h53"/><path d="m4296 6400h53"/><path d="m4382 6400h53"/><path d="m4467 6400h53"/><path d="m4553 6400h53"/><path d="m4638 6400h53"/><path d="m4723 6400h54"/><path d="m4809 6400h53"/><path d="m4894 6400h53"/><path d="m4980 6400h53"/><path d="m5065 6400h53"/><path d="m5151 6400h53"/><path d="m5236 6400h53"/><path d="m5322 6400h53"/><path d="m5407 6400h53"/><path d="m5492 6400h53"/><path d="m5578 6400h53"/><path d="m5663 6400h53"/><path d="m5749 6400h53"/><path d="m5834 6400h53"/><path d="m5920 6400h53"/><path d="m6005 6400h53"/><path d="m6090 6400h53"/><path d="m6176 6400h53"/><path d="m6261 6400h53"/><path d="m6347 6400h53"/><path d="m6432 6400h53"/><path d="m6518 6400h53"/><path d="m6603 6400h53"/><path d="m6688 6400h54"/><path d="m6774 6400h53"/><path d="m6859 6400h53"/><path d="m6945 6400h53"/><path d="m7030 6400h53"/><path d="m7116 6400h53"/><path d="m7201 6400h53"/><path d="m7286 6400h54"/><path d="m7372 6400h53"/><path d="m7457 6400h53"/><path d="m7543 6400h53"/><path d="m7628 6400h53"/><path d="m7714 6400h53"/><path d="m7799 6400h53"/><path d="m7884 6400h54"/><path d="m7970 6400h53"/><path d="m8055 6400h53"/><path d="m8141 6400h53"/><path d="m8226 6400h53"/><path d="m8312 6400h53"/><path d="m8397 6400h53"/><path d="m8482 6400h54"/><path d="m8568 6400h53"/><path d="m8653 6400h53"/><path d="m8739 6400h53"/><path d="m8824 6400h53"/><path d="m8910 6400h53"/><path d="m8995 6400h53"/><path d="m9081 6400h53"/><path d="m9166 6400h53"/><path d="m9251 6400h53"/><path d="m9337 6400h53"/><path d="m9422 6400h53"/><path d="m9508 6400h53"/><path d="m9593 6400h53"/><path d="m9679 6400h53"/><path d="m9764 6400h53"/><path d="m9849 6400h53"/><path d="m9935 6400h53"/><path d="m10020 6400h53"/><path d="m10106 6400h53"/><path d="m10191 6400h53"/><path d="m10277 6400h53"/><path d="m10362 6400h53"/><path d="m10447 6400h53"/><path d="m10533 6400h53"/><path d="m10618 6400h53"/><path d="m10704 6400h53"/><path d="m10789 6400h53"/><path d="m10875 6400h53"/><path d="m10960 6400h53"/><path d="m11045 6400h54"/><path d="m11131 6400h53"/><path d="m11216 6400h53"/><path d="m11302 6400h53"/><path d="m11387 6400h53"/><path d="m11473 6400h53"/><path d="m11558 6400h53"/><path d="m11643 6400h54"/><path d="m11729 6400h53"/><path d="m11814 6400h53"/><path d="m11900 6400h53"/><path d="m11985 6400h53"/><path d="m12071 6400h53"/><path d="m12156 6400h53"/><path d="m12241 6400h54"/><path d="m12327 6400h53"/><path d="m12412 6400h53"/><path d="m12498 6400h53"/><path d="m12583 6400h53"/><path d="m12669 6400h53"/><path d="m12754 6400h53"/><path d="m12839 6400h54"/><path d="m12925 6400h53"/><path d="m13010 6400h53"/><path d="m13096 6400h53"/><path d="m13181 6400h53"/><path d="m13267 6400h53"/><path d="m13352 6400h53"/><path d="m13438 6400h53"/><path d="m13523 6400h53"/><path d="m13608 6400h53"/><path d="m13694 6400h53"/><path d="m13779 6400h53"/><path d="m13865 6400h53"/><path d="m13950 6400h53"/><path d="m14036 6400h53"/><path d="m14121 6400h53"/><path d="m14206 6400h53"/><path d="m14292 6400h53"/><path d="m14377 6400h53"/><path d="m14463 6400h53"/><path d="m14548 6400h53"/><path d="m14634 6400h53"/><path d="m14719 6400h53"/><path d="m14804 6400h54"/><path d="m14890 6400h53"/><path d="m14975 6400h53"/><path d="m15061 6400h53"/><path d="m15146 6400h53"/><path d="m15232 6400h53"/><path d="m15317 6400h53"/><path d="m15402 6400h54"/><path d="m15488 6400h53"/><path d="m15573 6400h53"/><path d="m15659 6400h53"/><path d="m15744 6400h53"/><path d="m15830 6400h53"/><path d="m15915 6400h53"/><path d="m16000 6400h54"/><path d="m16086 6400h53"/><path d="m16171 6400h53"/><path d="m16257 6400h53"/><path d="m16342 6400h53"/><path d="m16428 6400h53"/><path d="m16513 6400h53"/><path d="m16598 6400h54"/><path d="m16684 6400h53"/><path d="m16769 6400h53"/><path d="m16855 6400h53"/><path d="m16940 6400h53"/><path d="m17026 6400h53"/><path d="m17111 6400h53"/><path d="m17196 6400h54"/><path d="m17282 6400h53"/><path d="m17367 6400h53"/><path d="m17453 6400h53"/><path d="m17538 6400h53"/><path d="m17624 6400h53"/><path d="m17709 6400h53"/><path d="m17795 6400h53"/><path d="m17880 6400h53"/><path d="m17965 6400h53"/><path d="m18051 6400h53"/><path d="m18136 6400h53"/><path d="m18222 6400h53"/><path d="m18307 6400h53"/><path d="m18393 6400h53"/><path d="m18478 6400h53"/><path d="m18563 6400h53"/><path d="m18649 6400h53"/><path d="m18734 6400h53"/><path d="m18820 6400h53"/><path d="m18905 6400h53"/><path d="m18991 6400h53"/><path d="m19076 6400h53"/><path d="m19161 6400h54"/><path d="m19247 6400h53"/><path d="m19332 6400h53"/><path d="m19418 6400h53"/><path d="m19503 6400h53"/><path d="m19589 6400h53"/><path d="m19674 6400h53"/><path d="m19759 6400h54"/><path d="m19845 6400h53"/><path d="m19930 6400h53"/><path d="m20016 6400h53"/><path d="m20101 6400h53"/><path d="m20187 6400h53"/><path d="m20272 6400h53"/><path d="m20357 6400h54"/><path d="m20443 6400h53"/><path d="m20528 6400h53"/><path d="m20614 6400c17-1 35-2 53-5"/><path d="m20699 6390c17-4 34-9 51-14"/><path d="m20781 6365c16-6 32-13 48-21"/><path d="m20858 6329c15-8 31-17 45-27"/><path d="m20930 6283c14-10 28-21 42-32"/><path d="m20996 6229c13-12 25-25 37-38"/><path d="m21055 6167c11-14 22-28 33-42"/><path d="m21106 6098c10-15 19-30 27-45"/><path d="m21148 6024c7-16 14-33 20-49"/><path d="m21179 5944c5-17 9-34 13-51"/><path d="m21197 5861c2-18 4-35 4-53"/><path d="m21201 5776v-54"/><path d="m21201 5690v-53"/><path d="m21201 5605v-53"/><path d="m21201 5519v-53"/><path d="m21201 5434v-53"/><path d="m21201 5348v-53"/><path d="m21201 5263v-53"/><path d="m21201 5178v-54"/><path d="m21201 5092v-53"/><path d="m21201 5007v-53"/><path d="m21201 4921v-53"/><path d="m21201 4836v-53"/><path d="m21201 4750v-53"/><path d="m21201 4665v-53"/><path d="m21201 4579v-53"/><path d="m21201 4494v-53"/><path d="m21201 4409v-53"/><path d="m21201 4323v-53"/><path d="m21201 4238v-53"/><path d="m21201 4152v-53"/><path d="m21201 4067v-53"/><path d="m21201 3981v-53"/><path d="m21201 3896v-53"/><path d="m21201 3811v-53"/><path d="m21201 3725v-53"/><path d="m21201 3640v-53"/><path d="m21201 3554v-53"/><path d="m21201 3469v-53"/><path d="m21201 3383c-1-17-3-35-5-52"/><path d="m21190 3299c-4-17-8-35-14-51"/><path d="m21165 3217c-6-16-13-33-21-49"/><path d="m21129 3140c-9-16-18-31-28-46"/><path d="m21082 3068c-10-14-21-28-33-42"/><path d="m21027 3002c-12-13-24-25-37-37"/><path d="m20965 2944c-14-12-28-22-42-33"/><path d="m20896 2893c-15-9-30-18-46-27"/><path d="m20821 2852c-16-8-32-14-49-20"/><path d="m20741 2821c-17-5-34-9-51-12"/><path d="m20658 2804c-18-3-35-4-53-4"/><path d="m20573 2800h-53"/><path d="m20487 2800h-53"/><path d="m20402 2800h-53"/><path d="m20316 2800h-53"/><path d="m20231 2800h-53"/><path d="m20146 2800h-54"/><path d="m20060 2800h-53"/><path d="m19975 2800h-53"/><path d="m19889 2800h-53"/><path d="m19804 2800h-53"/><path d="m19718 2800h-53"/><path d="m19633 2800h-53"/><path d="m19548 2800h-54"/><path d="m19462 2800h-53"/><path d="m19377 2800h-53"/><path d="m19291 2800h-53"/><path d="m19206 2800h-53"/><path d="m19120 2800h-53"/><path d="m19035 2800h-53"/><path d="m18950 2800h-54"/><path d="m18864 2800h-53"/><path d="m18779 2800h-53"/><path d="m18693 2800h-53"/><path d="m18608 2800h-53"/><path d="m18522 2800h-53"/><path d="m18437 2800h-53"/><path d="m18352 2800h-54"/><path d="m18266 2800h-53"/><path d="m18181 2800h-53"/><path d="m18095 2800h-53"/><path d="m18010 2800h-53"/><path d="m17924 2800h-53"/><path d="m17839 2800h-53"/><path d="m17753 2800h-53"/><path d="m17668 2800h-53"/><path d="m17583 2800h-53"/><path d="m17497 2800h-53"/><path d="m17412 2800h-53"/><path d="m17326 2800h-53"/><path d="m17241 2800h-53"/><path d="m17155 2800h-53"/><path d="m17070 2800h-53"/><path d="m16985 2800h-53"/><path d="m16899 2800h-53"/><path d="m16814 2800h-53"/><path d="m16728 2800h-53"/><path d="m16643 2800h-53"/><path d="m16557 2800h-53"/><path d="m16472 2800h-53"/><path d="m16387 2800h-54"/><path d="m16301 2800h-53"/><path d="m16216 2800h-53"/><path d="m16130 2800h-53"/><path d="m16045 2800h-53"/><path d="m15959 2800h-53"/><path d="m15874 2800h-53"/><path d="m15789 2800h-54"/><path d="m15703 2800h-53"/><path d="m15618 2800h-53"/><path d="m15532 2800h-53"/><path d="m15447 2800h-53"/><path d="m15361 2800h-53"/><path d="m15276 2800h-53"/><path d="m15191 2800h-54"/><path d="m15105 2800h-53"/><path d="m15020 2800h-53"/><path d="m14934 2800h-53"/><path d="m14849 2800h-53"/><path d="m14763 2800h-53"/><path d="m14678 2800h-53"/><path d="m14593 2800h-54"/><path d="m14507 2800h-53"/><path d="m14422 2800h-53"/><path d="m14336 2800h-53"/><path d="m14251 2800h-53"/><path d="m14165 2800h-53"/><path d="m14080 2800h-53"/><path d="m13994 2800h-53"/><path d="m13909 2800h-53"/><path d="m13824 2800h-53"/><path d="m13738 2800h-53"/><path d="m13653 2800h-53"/><path d="m13567 2800h-53"/><path d="m13482 2800h-53"/><path d="m13396 2800h-53"/><path d="m13311 2800h-53"/><path d="m13226 2800h-53"/><path d="m13140 2800h-53"/><path d="m13055 2800h-53"/><path d="m12969 2800h-53"/><path d="m12884 2800h-53"/><path d="m12798 2800h-53"/><path d="m12713 2800h-53"/><path d="m12628 2800h-53"/><path d="m12542 2800h-53"/><path d="m12457 2800h-53"/><path d="m12371 2800h-53"/><path d="m12286 2800h-53"/><path d="m12200 2800h-53"/><path d="m12115 2800h-53"/><path d="m12030 2800h-54"/><path d="m11944 2800h-53"/><path d="m11859 2800h-53"/><path d="m11773 2800h-53"/><path d="m11688 2800h-53"/><path d="m11602 2800h-53"/><path d="m11517 2800h-53"/><path d="m11432 2800h-54"/><path d="m11346 2800h-53"/><path d="m11261 2800h-53"/><path d="m11175 2800h-53"/><path d="m11090 2800h-53"/><path d="m11004 2800h-53"/><path d="m10919 2800h-53"/><path d="m10834 2800h-54"/><path d="m10748 2800h-53"/><path d="m10663 2800h-53"/><path d="m10577 2800h-53"/><path d="m10492 2800h-53"/><path d="m10406 2800h-53"/><path d="m10321 2800h-53"/><path d="m10236 2800h-54"/><path d="m10150 2800h-53"/><path d="m10065 2800h-53"/><path d="m9979 2800h-53"/><path d="m9894 2800h-53"/><path d="m9808 2800h-53"/><path d="m9723 2800h-53"/><path d="m9637 2800h-53"/><path d="m9552 2800h-53"/><path d="m9467 2800h-53"/><path d="m9381 2800h-53"/><path d="m9296 2800h-53"/><path d="m9210 2800h-53"/><path d="m9125 2800h-53"/><path d="m9039 2800h-53"/><path d="m8954 2800h-53"/><path d="m8869 2800h-53"/><path d="m8783 2800h-53"/><path d="m8698 2800h-53"/><path d="m8612 2800h-53"/><path d="m8527 2800h-53"/><path d="m8441 2800h-53"/><path d="m8356 2800h-53"/><path d="m8271 2800h-54"/><path d="m8185 2800h-53"/><path d="m8100 2800h-53"/><path d="m8014 2800h-53"/><path d="m7929 2800h-53"/><path d="m7843 2800h-53"/><path d="m7758 2800h-53"/><path d="m7673 2800h-54"/><path d="m7587 2800h-53"/><path d="m7502 2800h-53"/><path d="m7416 2800h-53"/><path d="m7331 2800h-53"/><path d="m7245 2800h-53"/><path d="m7160 2800h-53"/><path d="m7075 2800h-54"/><path d="m6989 2800h-53"/><path d="m6904 2800h-53"/><path d="m6818 2800h-53"/><path d="m6733 2800h-53"/><path d="m6647 2800h-53"/><path d="m6562 2800h-53"/><path d="m6477 2800h-54"/><path d="m6391 2800h-53"/><path d="m6306 2800h-53"/><path d="m6220 2800h-53"/><path d="m6135 2800h-53"/><path d="m6049 2800h-53"/><path d="m5964 2800h-53"/><path d="m5879 2800h-54"/><path d="m5793 2800h-53"/><path d="m5708 2800h-53"/><path d="m5622 2800h-53"/><path d="m5537 2800h-53"/><path d="m5451 2800h-53"/><path d="m5366 2800h-53"/><path d="m5280 2800h-53"/><path d="m5195 2800h-53"/><path d="m5110 2800h-53"/><path d="m5024 2800h-53"/><path d="m4939 2800h-53"/><path d="m4853 2800h-53"/><path d="m4768 2800h-53"/><path d="m4682 2800h-53"/><path d="m4597 2800h-53"/><path d="m4512 2800h-53"/><path d="m4426 2800h-53"/><path d="m4341 2800h-53"/><path d="m4255 2800h-53"/><path d="m4170 2800h-53"/><path d="m4084 2800h-53"/><path d="m3999 2800h-53"/><path d="m3914 2800h-54"/><path d="m3828 2800h-53"/><path d="m3743 2800h-53"/><path d="m3657 2800h-53"/><path d="m3572 2800h-53"/><path d="m3486 2800h-53"/><path d="m3401 2800h-53"/><path d="m3316 2800h-54"/><path d="m3230 2800h-53"/><path d="m3145 2800h-53"/><path d="m3059 2800h-53"/></g></g><g transform="translate(-2197.3 -2186)"><rect height="1100.7" width="1213.6" y="6917.1" x="23255" fill="#f3e777"/><path fill="#ca4677" d="m22802 7700.4v-405.46l150.7-169.16c82.886-93.039 170.53-186.62 194.77-207.96l44.069-38.798 783.23-0.086 783.23-0.086v613.5 613.5h-978-978v-405.46zm1027.7 136.98v-78.372l-169.91 4.925-169.91 4.9249-5.09 45.854c-8.249 74.303 46.711 101.04 207.69 101.04h137.21v-78.372zm235.86-262.94 4.495-341.31 207.2-8.6408 207.2-8.6408 5.144-46.443c9.596-86.615-41.863-102.05-322.02-96.607l-246.71 4.7956-4.438 419.08-4.439 419.08h74.537 74.538l4.494-341.31zm391.3 313.72c26.41-19.286 36.255-41.399 32.697-73.447l-5.09-45.854h-174.05-174.05l-5.38 48.984c-9.97 90.771 0.993 97.91 150.36 97.91 99.305 0 148.27-7.6982 175.52-27.594zm-627.16-274.84v-77.768h-174.05-174.05v66.246c0 36.436 4.973 71.431 11.051 77.768 6.078 6.3366 84.401 11.521 174.05 11.521h163v-77.768zm659.89-4.9154 5.125-74.042-179.18 4.9155-179.18 4.9155-5.38 48.984c-10.473 95.348-2.259 99.57 183.28 94.197l170.2-4.9284 5.125-74.042zm-659.89-237.63v-78.372l-169.91 4.925-169.91 4.925-5.097 73.447-5.097 73.447h175 175v-78.372zm659.86 4.925-5.097-73.447h-174.05-174.05l-5.38 48.984c-10.289 93.673-2.146 97.91 188.15 97.91h175.52l-5.097-73.447zm-659.86-228.98v-77.768h-137.21c-97.358 0-147.91 7.8138-174.05 26.902-34.952 25.523-49.645 92.242-25.79 117.11 6.078 6.3366 84.401 11.521 174.05 11.521h163v-77.768z"/></g><g transform="matrix(.84874 0 0 .76147 2408.1 3615.3)"><rect height="3076.2" width="2734.3" y="13264" x="19249" fill="#6076b3"/><g stroke-linejoin="round" fill-rule="evenodd" stroke-width="28.222" fill="#e0ee2c"><rect y="13369" width="356.65" x="18937" height="180.95"/><rect y="13708" width="356.65" x="18937" height="180.95"/><rect y="14048" width="356.65" x="18937" height="180.95"/><rect y="14387" width="356.65" x="18937" height="180.95"/><rect y="14726" width="356.65" x="18937" height="180.95"/><rect y="15066" width="356.65" x="18937" height="180.95"/><rect y="15405" width="356.65" x="18937" height="180.95"/><rect y="15744" width="356.65" x="18937" height="180.95"/><rect y="16083" width="356.65" x="18937" height="180.95"/><rect y="13324" width="356.65" x="21939" height="180.95"/><rect y="13663" width="356.65" x="21939" height="180.95"/><rect y="14002" width="356.65" x="21939" height="180.95"/><rect y="14342" width="356.65" x="21939" height="180.95"/><rect y="14681" width="356.65" x="21939" height="180.95"/><rect y="15020" width="356.65" x="21939" height="180.95"/><rect y="15360" width="356.65" x="21939" height="180.95"/><rect y="15699" width="356.65" x="21939" height="180.95"/><rect y="16038" width="356.65" x="21939" height="180.95"/></g><g stroke-linejoin="round" fill-rule="evenodd" transform="matrix(.98702 0 0 .90336 -2675 7020.8)" class="com.sun.star.drawing.TextShape" stroke-width="28.222"><text class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"/></text>
24<text style="word-spacing:0px;letter-spacing:0px" xml:space="preserve" font-size="1128.9px" y="9042.0264" x="22439.668" font-family="Sans" line-height="125%" fill="#000000"><tspan y="9042.0264" x="22439.668">CPU</tspan></text>
25</g></g><g stroke-linejoin="round" fill-rule="evenodd" transform="translate(-11752 543.6)" class="com.sun.star.drawing.TextShape" stroke-width="28.222"><text class="TextShape"><tspan font-size="706px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="15832" x="24341" class="TextPosition" transform="matrix(0,-1,1,0,8509,40173)"><tspan fill="#000000">PCI, USB, SPI, I2C, ...</tspan></tspan></tspan></text>
26</g><g stroke-linejoin="round" fill-rule="evenodd" transform="translate(-655.31 963.83)" class="com.sun.star.drawing.RectangleShape" stroke-width="28.222"><g transform="matrix(.49166 0 0 1.0059 6045.6 -82.24)"><path fill="#cfe7f5" d="m14169 14572h-2268v-1412h4536v1412h-2268z"/><path fill="none" d="m14169 14572h-2268v-1412h4536v1412h-2268z" stroke="#3465af"/></g><text y="-395.11282" x="-790.22229" class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="13686.9" x="12091.779" class="TextPosition"><tspan fill="#000000">Bridge</tspan></tspan></tspan></text>
27<text y="338.66486" x="-846.66675" class="TextShape"><tspan font-size="635px" font-family="&apos;Times New Roman&apos;, serif" font-weight="400" class="TextParagraph"><tspan y="14420.677" x="12035.335" class="TextPosition"><tspan fill="#000000"> DMA</tspan></tspan></tspan></text>
28</g></svg>
diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml
index 4e9462f1ab4c..6e1667b5f3eb 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4863,7 +4863,7 @@ interface and may change in the future.</para>
4863 </note> 4863 </note>
4864 4864
4865 <para> 4865 <para>
4866 The Image Source control class is intended for low-level control of 4866 The Image Process control class is intended for low-level control of
4867 image processing functions. Unlike 4867 image processing functions. Unlike
4868 <constant>V4L2_CID_IMAGE_SOURCE_CLASS</constant>, the controls in 4868 <constant>V4L2_CID_IMAGE_SOURCE_CLASS</constant>, the controls in
4869 this class affect processing the image, and do not control capturing 4869 this class affect processing the image, and do not control capturing
@@ -4871,7 +4871,7 @@ interface and may change in the future.</para>
4871 </para> 4871 </para>
4872 4872
4873 <table pgwide="1" frame="none" id="image-process-control-id"> 4873 <table pgwide="1" frame="none" id="image-process-control-id">
4874 <title>Image Source Control IDs</title> 4874 <title>Image Process Control IDs</title>
4875 4875
4876 <tgroup cols="4"> 4876 <tgroup cols="4">
4877 <colspec colname="c1" colwidth="1*" /> 4877 <colspec colname="c1" colwidth="1*" />
diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
index 1c17f802b471..7bbc2a48911e 100644
--- a/Documentation/DocBook/media/v4l/io.xml
+++ b/Documentation/DocBook/media/v4l/io.xml
@@ -841,15 +841,15 @@ is the file descriptor associated with a DMABUF buffer.</entry>
841 <entry>__u32</entry> 841 <entry>__u32</entry>
842 <entry><structfield>reserved2</structfield></entry> 842 <entry><structfield>reserved2</structfield></entry>
843 <entry></entry> 843 <entry></entry>
844 <entry>A place holder for future extensions. Applications 844 <entry>A place holder for future extensions. Drivers and applications
845should set this to 0.</entry> 845must set this to 0.</entry>
846 </row> 846 </row>
847 <row> 847 <row>
848 <entry>__u32</entry> 848 <entry>__u32</entry>
849 <entry><structfield>reserved</structfield></entry> 849 <entry><structfield>reserved</structfield></entry>
850 <entry></entry> 850 <entry></entry>
851 <entry>A place holder for future extensions. Applications 851 <entry>A place holder for future extensions. Drivers and applications
852should set this to 0.</entry> 852must set this to 0.</entry>
853 </row> 853 </row>
854 </tbody> 854 </tbody>
855 </tgroup> 855 </tgroup>
@@ -930,8 +930,8 @@ should set this to 0.</entry>
930 <entry>__u32</entry> 930 <entry>__u32</entry>
931 <entry><structfield>reserved[11]</structfield></entry> 931 <entry><structfield>reserved[11]</structfield></entry>
932 <entry></entry> 932 <entry></entry>
933 <entry>Reserved for future use. Should be zeroed by an 933 <entry>Reserved for future use. Should be zeroed by drivers and
934 application.</entry> 934 applications.</entry>
935 </row> 935 </row>
936 </tbody> 936 </tbody>
937 </tgroup> 937 </tgroup>
@@ -1129,6 +1129,18 @@ in this buffer has not been created by the CPU but by some DMA-capable unit,
1129in which case caches have not been used.</entry> 1129in which case caches have not been used.</entry>
1130 </row> 1130 </row>
1131 <row> 1131 <row>
1132 <entry><constant>V4L2_BUF_FLAG_LAST</constant></entry>
1133 <entry>0x00100000</entry>
1134 <entry>Last buffer produced by the hardware. mem2mem codec drivers
1135set this flag on the capture queue for the last buffer when the
1136<link linkend="vidioc-querybuf">VIDIOC_QUERYBUF</link> or
1137<link linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl is called. Due to hardware
1138limitations, the last buffer may be empty. In this case the driver will set the
1139<structfield>bytesused</structfield> field to 0, regardless of the format. Any
1140Any subsequent call to the <link linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl
1141will not block anymore, but return an &EPIPE;.</entry>
1142 </row>
1143 <row>
1132 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry> 1144 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
1133 <entry>0x0000e000</entry> 1145 <entry>0x0000e000</entry>
1134 <entry>Mask for timestamp types below. To test the 1146 <entry>Mask for timestamp types below. To test the
@@ -1155,7 +1167,7 @@ in which case caches have not been used.</entry>
1155 <entry>The buffer timestamp has been taken from the 1167 <entry>The buffer timestamp has been taken from the
1156 <constant>CLOCK_MONOTONIC</constant> clock. To access the 1168 <constant>CLOCK_MONOTONIC</constant> clock. To access the
1157 same clock outside V4L2, use 1169 same clock outside V4L2, use
1158 <function>clock_gettime(2)</function> .</entry> 1170 <function>clock_gettime(2)</function>.</entry>
1159 </row> 1171 </row>
1160 <row> 1172 <row>
1161 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_COPY</constant></entry> 1173 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_COPY</constant></entry>
diff --git a/Documentation/DocBook/media/v4l/media-func-open.xml b/Documentation/DocBook/media/v4l/media-func-open.xml
index f7df034dc9ed..122374a3e894 100644
--- a/Documentation/DocBook/media/v4l/media-func-open.xml
+++ b/Documentation/DocBook/media/v4l/media-func-open.xml
@@ -44,7 +44,7 @@
44 <para>To open a media device applications call <function>open()</function> 44 <para>To open a media device applications call <function>open()</function>
45 with the desired device name. The function has no side effects; the device 45 with the desired device name. The function has no side effects; the device
46 configuration remain unchanged.</para> 46 configuration remain unchanged.</para>
47 <para>When the device is opened in read-only mode, attemps to modify its 47 <para>When the device is opened in read-only mode, attempts to modify its
48 configuration will result in an error, and <varname>errno</varname> will be 48 configuration will result in an error, and <varname>errno</varname> will be
49 set to <errorcode>EBADF</errorcode>.</para> 49 set to <errorcode>EBADF</errorcode>.</para>
50 </refsect1> 50 </refsect1>
diff --git a/Documentation/DocBook/media/v4l/pixfmt-y16-be.xml b/Documentation/DocBook/media/v4l/pixfmt-y16-be.xml
new file mode 100644
index 000000000000..cea53e1eaa43
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-y16-be.xml
@@ -0,0 +1,81 @@
1<refentry id="V4L2-PIX-FMT-Y16-BE">
2 <refmeta>
3 <refentrytitle>V4L2_PIX_FMT_Y16_BE ('Y16 ' | (1 &lt;&lt; 31))</refentrytitle>
4 &manvol;
5 </refmeta>
6 <refnamediv>
7 <refname><constant>V4L2_PIX_FMT_Y16_BE</constant></refname>
8 <refpurpose>Grey-scale image</refpurpose>
9 </refnamediv>
10 <refsect1>
11 <title>Description</title>
12
13 <para>This is a grey-scale image with a depth of 16 bits per
14pixel. The most significant byte is stored at lower memory addresses
15(big-endian). Note the actual sampling precision may be lower than
1616 bits, for example 10 bits per pixel with values in range 0 to
171023.</para>
18
19 <example>
20 <title><constant>V4L2_PIX_FMT_Y16_BE</constant> 4 &times; 4
21pixel image</title>
22
23 <formalpara>
24 <title>Byte Order.</title>
25 <para>Each cell is one byte.
26 <informaltable frame="none">
27 <tgroup cols="9" align="center">
28 <colspec align="left" colwidth="2*" />
29 <tbody valign="top">
30 <row>
31 <entry>start&nbsp;+&nbsp;0:</entry>
32 <entry>Y'<subscript>00high</subscript></entry>
33 <entry>Y'<subscript>00low</subscript></entry>
34 <entry>Y'<subscript>01high</subscript></entry>
35 <entry>Y'<subscript>01low</subscript></entry>
36 <entry>Y'<subscript>02high</subscript></entry>
37 <entry>Y'<subscript>02low</subscript></entry>
38 <entry>Y'<subscript>03high</subscript></entry>
39 <entry>Y'<subscript>03low</subscript></entry>
40 </row>
41 <row>
42 <entry>start&nbsp;+&nbsp;8:</entry>
43 <entry>Y'<subscript>10high</subscript></entry>
44 <entry>Y'<subscript>10low</subscript></entry>
45 <entry>Y'<subscript>11high</subscript></entry>
46 <entry>Y'<subscript>11low</subscript></entry>
47 <entry>Y'<subscript>12high</subscript></entry>
48 <entry>Y'<subscript>12low</subscript></entry>
49 <entry>Y'<subscript>13high</subscript></entry>
50 <entry>Y'<subscript>13low</subscript></entry>
51 </row>
52 <row>
53 <entry>start&nbsp;+&nbsp;16:</entry>
54 <entry>Y'<subscript>20high</subscript></entry>
55 <entry>Y'<subscript>20low</subscript></entry>
56 <entry>Y'<subscript>21high</subscript></entry>
57 <entry>Y'<subscript>21low</subscript></entry>
58 <entry>Y'<subscript>22high</subscript></entry>
59 <entry>Y'<subscript>22low</subscript></entry>
60 <entry>Y'<subscript>23high</subscript></entry>
61 <entry>Y'<subscript>23low</subscript></entry>
62 </row>
63 <row>
64 <entry>start&nbsp;+&nbsp;24:</entry>
65 <entry>Y'<subscript>30high</subscript></entry>
66 <entry>Y'<subscript>30low</subscript></entry>
67 <entry>Y'<subscript>31high</subscript></entry>
68 <entry>Y'<subscript>31low</subscript></entry>
69 <entry>Y'<subscript>32high</subscript></entry>
70 <entry>Y'<subscript>32low</subscript></entry>
71 <entry>Y'<subscript>33high</subscript></entry>
72 <entry>Y'<subscript>33low</subscript></entry>
73 </row>
74 </tbody>
75 </tgroup>
76 </informaltable>
77 </para>
78 </formalpara>
79 </example>
80 </refsect1>
81</refentry>
diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml b/Documentation/DocBook/media/v4l/pixfmt.xml
index fcde4e20205e..965ea916784a 100644
--- a/Documentation/DocBook/media/v4l/pixfmt.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt.xml
@@ -157,6 +157,14 @@ see <xref linkend="colorspaces" />.</entry>
157capture streams and by the application for output streams, 157capture streams and by the application for output streams,
158see <xref linkend="colorspaces" />.</entry> 158see <xref linkend="colorspaces" />.</entry>
159 </row> 159 </row>
160 <row>
161 <entry>&v4l2-xfer-func;</entry>
162 <entry><structfield>xfer_func</structfield></entry>
163 <entry>This information supplements the
164<structfield>colorspace</structfield> and must be set by the driver for
165capture streams and by the application for output streams,
166see <xref linkend="colorspaces" />.</entry>
167 </row>
160 </tbody> 168 </tbody>
161 </tgroup> 169 </tgroup>
162 </table> 170 </table>
@@ -190,8 +198,8 @@ see <xref linkend="colorspaces" />.</entry>
190 <row> 198 <row>
191 <entry>__u16</entry> 199 <entry>__u16</entry>
192 <entry><structfield>reserved[6]</structfield></entry> 200 <entry><structfield>reserved[6]</structfield></entry>
193 <entry>Reserved for future extensions. Should be zeroed by the 201 <entry>Reserved for future extensions. Should be zeroed by drivers and
194 application.</entry> 202 applications.</entry>
195 </row> 203 </row>
196 </tbody> 204 </tbody>
197 </tgroup> 205 </tgroup>
@@ -264,11 +272,19 @@ see <xref linkend="colorspaces" />.</entry>
264capture streams and by the application for output streams, 272capture streams and by the application for output streams,
265see <xref linkend="colorspaces" />.</entry> 273see <xref linkend="colorspaces" />.</entry>
266 </row> 274 </row>
275 <row>
276 <entry>&v4l2-xfer-func;</entry>
277 <entry><structfield>xfer_func</structfield></entry>
278 <entry>This information supplements the
279<structfield>colorspace</structfield> and must be set by the driver for
280capture streams and by the application for output streams,
281see <xref linkend="colorspaces" />.</entry>
282 </row>
267 <row> 283 <row>
268 <entry>__u8</entry> 284 <entry>__u8</entry>
269 <entry><structfield>reserved[8]</structfield></entry> 285 <entry><structfield>reserved[7]</structfield></entry>
270 <entry>Reserved for future extensions. Should be zeroed by the 286 <entry>Reserved for future extensions. Should be zeroed by drivers
271 application.</entry> 287 and applications.</entry>
272 </row> 288 </row>
273 </tbody> 289 </tbody>
274 </tgroup> 290 </tgroup>
@@ -476,15 +492,16 @@ is also very useful.</para>
476 492
477 <section> 493 <section>
478 <title>Defining Colorspaces in V4L2</title> 494 <title>Defining Colorspaces in V4L2</title>
479 <para>In V4L2 colorspaces are defined by three values. The first is the colorspace 495 <para>In V4L2 colorspaces are defined by four values. The first is the colorspace
480identifier (&v4l2-colorspace;) which defines the chromaticities, the transfer 496identifier (&v4l2-colorspace;) which defines the chromaticities, the default transfer
481function, the default Y'CbCr encoding and the default quantization method. The second 497function, the default Y'CbCr encoding and the default quantization method. The second
482is the Y'CbCr encoding identifier (&v4l2-ycbcr-encoding;) to specify non-standard 498is the transfer function identifier (&v4l2-xfer-func;) to specify non-standard
483Y'CbCr encodings and the third is the quantization identifier (&v4l2-quantization;) 499transfer functions. The third is the Y'CbCr encoding identifier (&v4l2-ycbcr-encoding;)
484to specify non-standard quantization methods. Most of the time only the colorspace 500to specify non-standard Y'CbCr encodings and the fourth is the quantization identifier
485field of &v4l2-pix-format; or &v4l2-pix-format-mplane; needs to be filled in. Note 501(&v4l2-quantization;) to specify non-standard quantization methods. Most of the time
486that the default R'G'B' quantization is full range for all colorspaces except for 502only the colorspace field of &v4l2-pix-format; or &v4l2-pix-format-mplane; needs to
487BT.2020 which uses limited range R'G'B' quantization.</para> 503be filled in. Note that the default R'G'B' quantization is full range for all
504colorspaces except for BT.2020 which uses limited range R'G'B' quantization.</para>
488 505
489 <table pgwide="1" frame="none" id="v4l2-colorspace"> 506 <table pgwide="1" frame="none" id="v4l2-colorspace">
490 <title>V4L2 Colorspaces</title> 507 <title>V4L2 Colorspaces</title>
@@ -498,6 +515,11 @@ BT.2020 which uses limited range R'G'B' quantization.</para>
498 </thead> 515 </thead>
499 <tbody valign="top"> 516 <tbody valign="top">
500 <row> 517 <row>
518 <entry><constant>V4L2_COLORSPACE_DEFAULT</constant></entry>
519 <entry>The default colorspace. This can be used by applications to let the
520 driver fill in the colorspace.</entry>
521 </row>
522 <row>
501 <entry><constant>V4L2_COLORSPACE_SMPTE170M</constant></entry> 523 <entry><constant>V4L2_COLORSPACE_SMPTE170M</constant></entry>
502 <entry>See <xref linkend="col-smpte-170m" />.</entry> 524 <entry>See <xref linkend="col-smpte-170m" />.</entry>
503 </row> 525 </row>
@@ -533,6 +555,52 @@ BT.2020 which uses limited range R'G'B' quantization.</para>
533 <entry><constant>V4L2_COLORSPACE_JPEG</constant></entry> 555 <entry><constant>V4L2_COLORSPACE_JPEG</constant></entry>
534 <entry>See <xref linkend="col-jpeg" />.</entry> 556 <entry>See <xref linkend="col-jpeg" />.</entry>
535 </row> 557 </row>
558 <row>
559 <entry><constant>V4L2_COLORSPACE_RAW</constant></entry>
560 <entry>The raw colorspace. This is used for raw image capture where
561 the image is minimally processed and is using the internal colorspace
562 of the device. The software that processes an image using this
563 'colorspace' will have to know the internals of the capture device.</entry>
564 </row>
565 </tbody>
566 </tgroup>
567 </table>
568
569 <table pgwide="1" frame="none" id="v4l2-xfer-func">
570 <title>V4L2 Transfer Function</title>
571 <tgroup cols="2" align="left">
572 &cs-def;
573 <thead>
574 <row>
575 <entry>Identifier</entry>
576 <entry>Details</entry>
577 </row>
578 </thead>
579 <tbody valign="top">
580 <row>
581 <entry><constant>V4L2_XFER_FUNC_DEFAULT</constant></entry>
582 <entry>Use the default transfer function as defined by the colorspace.</entry>
583 </row>
584 <row>
585 <entry><constant>V4L2_XFER_FUNC_709</constant></entry>
586 <entry>Use the Rec. 709 transfer function.</entry>
587 </row>
588 <row>
589 <entry><constant>V4L2_XFER_FUNC_SRGB</constant></entry>
590 <entry>Use the sRGB transfer function.</entry>
591 </row>
592 <row>
593 <entry><constant>V4L2_XFER_FUNC_ADOBERGB</constant></entry>
594 <entry>Use the AdobeRGB transfer function.</entry>
595 </row>
596 <row>
597 <entry><constant>V4L2_XFER_FUNC_SMPTE240M</constant></entry>
598 <entry>Use the SMPTE 240M transfer function.</entry>
599 </row>
600 <row>
601 <entry><constant>V4L2_XFER_FUNC_NONE</constant></entry>
602 <entry>Do not use a transfer function (i.e. use linear RGB values).</entry>
603 </row>
536 </tbody> 604 </tbody>
537 </tgroup> 605 </tgroup>
538 </table> 606 </table>
@@ -624,7 +692,8 @@ is mapped to [16&hellip;235]. Cb and Cr are mapped from [-0.5&hellip;0.5] to [16
624 <section id="col-smpte-170m"> 692 <section id="col-smpte-170m">
625 <title>Colorspace SMPTE 170M (<constant>V4L2_COLORSPACE_SMPTE170M</constant>)</title> 693 <title>Colorspace SMPTE 170M (<constant>V4L2_COLORSPACE_SMPTE170M</constant>)</title>
626 <para>The <xref linkend="smpte170m" /> standard defines the colorspace used by NTSC and PAL and by SDTV 694 <para>The <xref linkend="smpte170m" /> standard defines the colorspace used by NTSC and PAL and by SDTV
627in general. The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_601</constant>. 695in general. The default transfer function is <constant>V4L2_XFER_FUNC_709</constant>.
696The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_601</constant>.
628The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and 697The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and
629the white reference are:</para> 698the white reference are:</para>
630 <table frame="none"> 699 <table frame="none">
@@ -706,7 +775,8 @@ rarely seen.</para>
706 775
707 <section id="col-rec709"> 776 <section id="col-rec709">
708 <title>Colorspace Rec. 709 (<constant>V4L2_COLORSPACE_REC709</constant>)</title> 777 <title>Colorspace Rec. 709 (<constant>V4L2_COLORSPACE_REC709</constant>)</title>
709 <para>The <xref linkend="itu709" /> standard defines the colorspace used by HDTV in general. The default 778 <para>The <xref linkend="itu709" /> standard defines the colorspace used by HDTV in general.
779The default transfer function is <constant>V4L2_XFER_FUNC_709</constant>. The default
710Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_709</constant>. The default Y'CbCr quantization is 780Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_709</constant>. The default Y'CbCr quantization is
711limited range. The chromaticities of the primary colors and the white reference are:</para> 781limited range. The chromaticities of the primary colors and the white reference are:</para>
712 <table frame="none"> 782 <table frame="none">
@@ -817,9 +887,11 @@ The xvYCC encodings always use full range quantization.</para>
817 887
818 <section id="col-srgb"> 888 <section id="col-srgb">
819 <title>Colorspace sRGB (<constant>V4L2_COLORSPACE_SRGB</constant>)</title> 889 <title>Colorspace sRGB (<constant>V4L2_COLORSPACE_SRGB</constant>)</title>
820 <para>The <xref linkend="srgb" /> standard defines the colorspace used by most webcams and computer graphics. The 890 <para>The <xref linkend="srgb" /> standard defines the colorspace used by most webcams
821default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_SYCC</constant>. The default Y'CbCr quantization 891and computer graphics. The default transfer function is <constant>V4L2_XFER_FUNC_SRGB</constant>.
822is full range. The chromaticities of the primary colors and the white reference are:</para> 892The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_SYCC</constant>. The default Y'CbCr
893quantization is full range. The chromaticities of the primary colors and the white
894reference are:</para>
823 <table frame="none"> 895 <table frame="none">
824 <title>sRGB Chromaticities</title> 896 <title>sRGB Chromaticities</title>
825 <tgroup cols="3" align="left"> 897 <tgroup cols="3" align="left">
@@ -896,6 +968,7 @@ values before quantization, but this encoding does not do that.</para>
896 <title>Colorspace Adobe RGB (<constant>V4L2_COLORSPACE_ADOBERGB</constant>)</title> 968 <title>Colorspace Adobe RGB (<constant>V4L2_COLORSPACE_ADOBERGB</constant>)</title>
897 <para>The <xref linkend="adobergb" /> standard defines the colorspace used by computer graphics 969 <para>The <xref linkend="adobergb" /> standard defines the colorspace used by computer graphics
898that use the AdobeRGB colorspace. This is also known as the <xref linkend="oprgb" /> standard. 970that use the AdobeRGB colorspace. This is also known as the <xref linkend="oprgb" /> standard.
971The default transfer function is <constant>V4L2_XFER_FUNC_ADOBERGB</constant>.
899The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_601</constant>. The default Y'CbCr 972The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_601</constant>. The default Y'CbCr
900quantization is limited range. The chromaticities of the primary colors and the white reference 973quantization is limited range. The chromaticities of the primary colors and the white reference
901are:</para> 974are:</para>
@@ -967,7 +1040,8 @@ SMPTE 170M/BT.601. The Y'CbCr quantization is limited range.</para>
967 <section id="col-bt2020"> 1040 <section id="col-bt2020">
968 <title>Colorspace BT.2020 (<constant>V4L2_COLORSPACE_BT2020</constant>)</title> 1041 <title>Colorspace BT.2020 (<constant>V4L2_COLORSPACE_BT2020</constant>)</title>
969 <para>The <xref linkend="itu2020" /> standard defines the colorspace used by Ultra-high definition 1042 <para>The <xref linkend="itu2020" /> standard defines the colorspace used by Ultra-high definition
970television (UHDTV). The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_BT2020</constant>. 1043television (UHDTV). The default transfer function is <constant>V4L2_XFER_FUNC_709</constant>.
1044The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_BT2020</constant>.
971The default R'G'B' quantization is limited range (!), and so is the default Y'CbCr quantization. 1045The default R'G'B' quantization is limited range (!), and so is the default Y'CbCr quantization.
972The chromaticities of the primary colors and the white reference are:</para> 1046The chromaticities of the primary colors and the white reference are:</para>
973 <table frame="none"> 1047 <table frame="none">
@@ -1082,8 +1156,10 @@ clamped to the range [-0.5&hellip;0.5]. The Yc'CbcCrc quantization is limited ra
1082 1156
1083 <section id="col-smpte-240m"> 1157 <section id="col-smpte-240m">
1084 <title>Colorspace SMPTE 240M (<constant>V4L2_COLORSPACE_SMPTE240M</constant>)</title> 1158 <title>Colorspace SMPTE 240M (<constant>V4L2_COLORSPACE_SMPTE240M</constant>)</title>
1085 <para>The <xref linkend="smpte240m" /> standard was an interim standard used during the early days of HDTV (1988-1998). 1159 <para>The <xref linkend="smpte240m" /> standard was an interim standard used during
1086It has been superseded by Rec. 709. The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_SMPTE240M</constant>. 1160the early days of HDTV (1988-1998). It has been superseded by Rec. 709.
1161The default transfer function is <constant>V4L2_XFER_FUNC_SMPTE240M</constant>.
1162The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_SMPTE240M</constant>.
1087The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the 1163The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the
1088white reference are:</para> 1164white reference are:</para>
1089 <table frame="none"> 1165 <table frame="none">
@@ -1156,8 +1232,10 @@ clamped to the range [-0.5&hellip;0.5]. The Y'CbCr quantization is limited range
1156 <section id="col-sysm"> 1232 <section id="col-sysm">
1157 <title>Colorspace NTSC 1953 (<constant>V4L2_COLORSPACE_470_SYSTEM_M</constant>)</title> 1233 <title>Colorspace NTSC 1953 (<constant>V4L2_COLORSPACE_470_SYSTEM_M</constant>)</title>
1158 <para>This standard defines the colorspace used by NTSC in 1953. In practice this 1234 <para>This standard defines the colorspace used by NTSC in 1953. In practice this
1159colorspace is obsolete and SMPTE 170M should be used instead. The default Y'CbCr encoding 1235colorspace is obsolete and SMPTE 170M should be used instead.
1160is <constant>V4L2_YCBCR_ENC_601</constant>. The default Y'CbCr quantization is limited range. 1236The default transfer function is <constant>V4L2_XFER_FUNC_709</constant>.
1237The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_601</constant>.
1238The default Y'CbCr quantization is limited range.
1161The chromaticities of the primary colors and the white reference are:</para> 1239The chromaticities of the primary colors and the white reference are:</para>
1162 <table frame="none"> 1240 <table frame="none">
1163 <title>NTSC 1953 Chromaticities</title> 1241 <title>NTSC 1953 Chromaticities</title>
@@ -1234,8 +1312,10 @@ This transform is identical to one defined in SMPTE 170M/BT.601.</para>
1234 <section id="col-sysbg"> 1312 <section id="col-sysbg">
1235 <title>Colorspace EBU Tech. 3213 (<constant>V4L2_COLORSPACE_470_SYSTEM_BG</constant>)</title> 1313 <title>Colorspace EBU Tech. 3213 (<constant>V4L2_COLORSPACE_470_SYSTEM_BG</constant>)</title>
1236 <para>The <xref linkend="tech3213" /> standard defines the colorspace used by PAL/SECAM in 1975. In practice this 1314 <para>The <xref linkend="tech3213" /> standard defines the colorspace used by PAL/SECAM in 1975. In practice this
1237colorspace is obsolete and SMPTE 170M should be used instead. The default Y'CbCr encoding 1315colorspace is obsolete and SMPTE 170M should be used instead.
1238is <constant>V4L2_YCBCR_ENC_601</constant>. The default Y'CbCr quantization is limited range. 1316The default transfer function is <constant>V4L2_XFER_FUNC_709</constant>.
1317The default Y'CbCr encoding is <constant>V4L2_YCBCR_ENC_601</constant>.
1318The default Y'CbCr quantization is limited range.
1239The chromaticities of the primary colors and the white reference are:</para> 1319The chromaticities of the primary colors and the white reference are:</para>
1240 <table frame="none"> 1320 <table frame="none">
1241 <title>EBU Tech. 3213 Chromaticities</title> 1321 <title>EBU Tech. 3213 Chromaticities</title>
@@ -1308,7 +1388,8 @@ This transform is identical to one defined in SMPTE 170M/BT.601.</para>
1308 <section id="col-jpeg"> 1388 <section id="col-jpeg">
1309 <title>Colorspace JPEG (<constant>V4L2_COLORSPACE_JPEG</constant>)</title> 1389 <title>Colorspace JPEG (<constant>V4L2_COLORSPACE_JPEG</constant>)</title>
1310 <para>This colorspace defines the colorspace used by most (Motion-)JPEG formats. The chromaticities 1390 <para>This colorspace defines the colorspace used by most (Motion-)JPEG formats. The chromaticities
1311of the primary colors and the white reference are identical to sRGB. The Y'CbCr encoding is 1391of the primary colors and the white reference are identical to sRGB. The transfer
1392function use is <constant>V4L2_XFER_FUNC_SRGB</constant>. The Y'CbCr encoding is
1312<constant>V4L2_YCBCR_ENC_601</constant> with full range quantization where 1393<constant>V4L2_YCBCR_ENC_601</constant> with full range quantization where
1313Y' is scaled to [0&hellip;255] and Cb/Cr are scaled to [-128&hellip;128] and 1394Y' is scaled to [0&hellip;255] and Cb/Cr are scaled to [-128&hellip;128] and
1314then clipped to [-128&hellip;127].</para> 1395then clipped to [-128&hellip;127].</para>
@@ -1429,6 +1510,7 @@ information.</para>
1429 &sub-y12; 1510 &sub-y12;
1430 &sub-y10b; 1511 &sub-y10b;
1431 &sub-y16; 1512 &sub-y16;
1513 &sub-y16-be;
1432 &sub-uv8; 1514 &sub-uv8;
1433 &sub-yuyv; 1515 &sub-yuyv;
1434 &sub-uyvy; 1516 &sub-uyvy;
diff --git a/Documentation/DocBook/media/v4l/remote_controllers.xml b/Documentation/DocBook/media/v4l/remote_controllers.xml
index 5124a6c4daa8..b86844e80257 100644
--- a/Documentation/DocBook/media/v4l/remote_controllers.xml
+++ b/Documentation/DocBook/media/v4l/remote_controllers.xml
@@ -284,7 +284,7 @@ different IR's. Due to that, V4L2 API now specifies a standard for mapping Media
284</tgroup> 284</tgroup>
285</table> 285</table>
286 286
287<para>It should be noticed that, sometimes, there some fundamental missing keys at some cheaper IR's. Due to that, it is recommended to:</para> 287<para>It should be noted that, sometimes, there some fundamental missing keys at some cheaper IR's. Due to that, it is recommended to:</para>
288 288
289<table pgwide="1" frame="none" id="rc_keymap_notes"> 289<table pgwide="1" frame="none" id="rc_keymap_notes">
290<title>Notes</title> 290<title>Notes</title>
diff --git a/Documentation/DocBook/media/v4l/subdev-formats.xml b/Documentation/DocBook/media/v4l/subdev-formats.xml
index 2588ad781242..4e73345e3eab 100644
--- a/Documentation/DocBook/media/v4l/subdev-formats.xml
+++ b/Documentation/DocBook/media/v4l/subdev-formats.xml
@@ -50,8 +50,16 @@ capture streams and by the application for output streams,
50see <xref linkend="colorspaces" />.</entry> 50see <xref linkend="colorspaces" />.</entry>
51 </row> 51 </row>
52 <row> 52 <row>
53 <entry>__u32</entry> 53 <entry>&v4l2-xfer-func;</entry>
54 <entry><structfield>reserved</structfield>[6]</entry> 54 <entry><structfield>xfer_func</structfield></entry>
55 <entry>This information supplements the
56<structfield>colorspace</structfield> and must be set by the driver for
57capture streams and by the application for output streams,
58see <xref linkend="colorspaces" />.</entry>
59 </row>
60 <row>
61 <entry>__u16</entry>
62 <entry><structfield>reserved</structfield>[11]</entry>
55 <entry>Reserved for future extensions. Applications and drivers must 63 <entry>Reserved for future extensions. Applications and drivers must
56 set the array to zero.</entry> 64 set the array to zero.</entry>
57 </row> 65 </row>
diff --git a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
index 9b700a5f4df7..8ffe74f84af1 100644
--- a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
@@ -134,7 +134,8 @@ information.</para>
134 <row> 134 <row>
135 <entry>__u32</entry> 135 <entry>__u32</entry>
136 <entry><structfield>reserved</structfield>[8]</entry> 136 <entry><structfield>reserved</structfield>[8]</entry>
137 <entry>A place holder for future extensions.</entry> 137 <entry>A place holder for future extensions. Drivers and applications
138must set the array to zero.</entry>
138 </row> 139 </row>
139 </tbody> 140 </tbody>
140 </tgroup> 141 </tgroup>
diff --git a/Documentation/DocBook/media/v4l/vidioc-decoder-cmd.xml b/Documentation/DocBook/media/v4l/vidioc-decoder-cmd.xml
index 9215627b04c7..73eb5cfe698a 100644
--- a/Documentation/DocBook/media/v4l/vidioc-decoder-cmd.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-decoder-cmd.xml
@@ -197,7 +197,17 @@ be muted when playing back at a non-standard speed.
197this command does nothing. This command has two flags: 197this command does nothing. This command has two flags:
198if <constant>V4L2_DEC_CMD_STOP_TO_BLACK</constant> is set, then the decoder will 198if <constant>V4L2_DEC_CMD_STOP_TO_BLACK</constant> is set, then the decoder will
199set the picture to black after it stopped decoding. Otherwise the last image will 199set the picture to black after it stopped decoding. Otherwise the last image will
200repeat. If <constant>V4L2_DEC_CMD_STOP_IMMEDIATELY</constant> is set, then the decoder 200repeat. mem2mem decoders will stop producing new frames altogether. They will send
201a <constant>V4L2_EVENT_EOS</constant> event when the last frame has been decoded
202and all frames are ready to be dequeued and will set the
203<constant>V4L2_BUF_FLAG_LAST</constant> buffer flag on the last buffer of the
204capture queue to indicate there will be no new buffers produced to dequeue. This
205buffer may be empty, indicated by the driver setting the
206<structfield>bytesused</structfield> field to 0. Once the
207<constant>V4L2_BUF_FLAG_LAST</constant> flag was set, the
208<link linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl will not block anymore,
209but return an &EPIPE;.
210If <constant>V4L2_DEC_CMD_STOP_IMMEDIATELY</constant> is set, then the decoder
201stops immediately (ignoring the <structfield>pts</structfield> value), otherwise it 211stops immediately (ignoring the <structfield>pts</structfield> value), otherwise it
202will keep decoding until timestamp >= pts or until the last of the pending data from 212will keep decoding until timestamp >= pts or until the last of the pending data from
203its internal buffers was decoded. 213its internal buffers was decoded.
diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index 50ccd33948c1..c9c3c7713832 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -133,7 +133,10 @@
133 <entry>struct timespec</entry> 133 <entry>struct timespec</entry>
134 <entry><structfield>timestamp</structfield></entry> 134 <entry><structfield>timestamp</structfield></entry>
135 <entry></entry> 135 <entry></entry>
136 <entry>Event timestamp.</entry> 136 <entry>Event timestamp. The timestamp has been taken from the
137 <constant>CLOCK_MONOTONIC</constant> clock. To access the
138 same clock outside V4L2, use <function>clock_gettime(2)</function>.
139 </entry>
137 </row> 140 </row>
138 <row> 141 <row>
139 <entry>u32</entry> 142 <entry>u32</entry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-encoder-cmd.xml b/Documentation/DocBook/media/v4l/vidioc-encoder-cmd.xml
index 0619ca5d2d36..fc1d4625a78c 100644
--- a/Documentation/DocBook/media/v4l/vidioc-encoder-cmd.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-encoder-cmd.xml
@@ -129,7 +129,15 @@ this command.</entry>
129encoding will continue until the end of the current <wordasword>Group 129encoding will continue until the end of the current <wordasword>Group
130Of Pictures</wordasword>, otherwise encoding will stop immediately. 130Of Pictures</wordasword>, otherwise encoding will stop immediately.
131When the encoder is already stopped, this command does 131When the encoder is already stopped, this command does
132nothing.</entry> 132nothing. mem2mem encoders will send a <constant>V4L2_EVENT_EOS</constant> event
133when the last frame has been decoded and all frames are ready to be dequeued and
134will set the <constant>V4L2_BUF_FLAG_LAST</constant> buffer flag on the last
135buffer of the capture queue to indicate there will be no new buffers produced to
136dequeue. This buffer may be empty, indicated by the driver setting the
137<structfield>bytesused</structfield> field to 0. Once the
138<constant>V4L2_BUF_FLAG_LAST</constant> flag was set, the
139<link linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl will not block anymore,
140but return an &EPIPE;.</entry>
133 </row> 141 </row>
134 <row> 142 <row>
135 <entry><constant>V4L2_ENC_CMD_PAUSE</constant></entry> 143 <entry><constant>V4L2_ENC_CMD_PAUSE</constant></entry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-enum-frameintervals.xml b/Documentation/DocBook/media/v4l/vidioc-enum-frameintervals.xml
index 5fd72c4c33e3..7c839ab0afbb 100644
--- a/Documentation/DocBook/media/v4l/vidioc-enum-frameintervals.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-enum-frameintervals.xml
@@ -217,7 +217,8 @@ enumerated.</entry>
217 <entry>__u32</entry> 217 <entry>__u32</entry>
218 <entry><structfield>reserved[2]</structfield></entry> 218 <entry><structfield>reserved[2]</structfield></entry>
219 <entry></entry> 219 <entry></entry>
220 <entry>Reserved space for future use.</entry> 220 <entry>Reserved space for future use. Must be zeroed by drivers and
221 applications.</entry>
221 </row> 222 </row>
222 </tbody> 223 </tbody>
223 </tgroup> 224 </tgroup>
diff --git a/Documentation/DocBook/media/v4l/vidioc-enum-framesizes.xml b/Documentation/DocBook/media/v4l/vidioc-enum-framesizes.xml
index a78454b5abcd..9ed68ac8f474 100644
--- a/Documentation/DocBook/media/v4l/vidioc-enum-framesizes.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-enum-framesizes.xml
@@ -223,7 +223,8 @@ application should zero out all members except for the
223 <entry>__u32</entry> 223 <entry>__u32</entry>
224 <entry><structfield>reserved[2]</structfield></entry> 224 <entry><structfield>reserved[2]</structfield></entry>
225 <entry></entry> 225 <entry></entry>
226 <entry>Reserved space for future use.</entry> 226 <entry>Reserved space for future use. Must be zeroed by drivers and
227 applications.</entry>
227 </row> 228 </row>
228 </tbody> 229 </tbody>
229 </tgroup> 230 </tgroup>
diff --git a/Documentation/DocBook/media/v4l/vidioc-expbuf.xml b/Documentation/DocBook/media/v4l/vidioc-expbuf.xml
index 4165e7bfa4ff..a78c9207422f 100644
--- a/Documentation/DocBook/media/v4l/vidioc-expbuf.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-expbuf.xml
@@ -184,7 +184,8 @@ of open() for more details.</entry>
184 <row> 184 <row>
185 <entry>__u32</entry> 185 <entry>__u32</entry>
186 <entry><structfield>reserved[11]</structfield></entry> 186 <entry><structfield>reserved[11]</structfield></entry>
187 <entry>Reserved field for future use. Must be set to zero.</entry> 187 <entry>Reserved field for future use. Drivers and applications must
188set the array to zero.</entry>
188 </row> 189 </row>
189 </tbody> 190 </tbody>
190 </tgroup> 191 </tgroup>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-dv-timings.xml b/Documentation/DocBook/media/v4l/vidioc-g-dv-timings.xml
index 764b635ed4cf..06952d7cc770 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-dv-timings.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-dv-timings.xml
@@ -7,6 +7,8 @@
7 <refnamediv> 7 <refnamediv>
8 <refname>VIDIOC_G_DV_TIMINGS</refname> 8 <refname>VIDIOC_G_DV_TIMINGS</refname>
9 <refname>VIDIOC_S_DV_TIMINGS</refname> 9 <refname>VIDIOC_S_DV_TIMINGS</refname>
10 <refname>VIDIOC_SUBDEV_G_DV_TIMINGS</refname>
11 <refname>VIDIOC_SUBDEV_S_DV_TIMINGS</refname>
10 <refpurpose>Get or set DV timings for input or output</refpurpose> 12 <refpurpose>Get or set DV timings for input or output</refpurpose>
11 </refnamediv> 13 </refnamediv>
12 14
@@ -34,7 +36,7 @@
34 <varlistentry> 36 <varlistentry>
35 <term><parameter>request</parameter></term> 37 <term><parameter>request</parameter></term>
36 <listitem> 38 <listitem>
37 <para>VIDIOC_G_DV_TIMINGS, VIDIOC_S_DV_TIMINGS</para> 39 <para>VIDIOC_G_DV_TIMINGS, VIDIOC_S_DV_TIMINGS, VIDIOC_SUBDEV_G_DV_TIMINGS, VIDIOC_SUBDEV_S_DV_TIMINGS</para>
38 </listitem> 40 </listitem>
39 </varlistentry> 41 </varlistentry>
40 <varlistentry> 42 <varlistentry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-edid.xml b/Documentation/DocBook/media/v4l/vidioc-g-edid.xml
index 6df40db4c8ba..2702536bbc7c 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-edid.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-edid.xml
@@ -7,6 +7,8 @@
7 <refnamediv> 7 <refnamediv>
8 <refname>VIDIOC_G_EDID</refname> 8 <refname>VIDIOC_G_EDID</refname>
9 <refname>VIDIOC_S_EDID</refname> 9 <refname>VIDIOC_S_EDID</refname>
10 <refname>VIDIOC_SUBDEV_G_EDID</refname>
11 <refname>VIDIOC_SUBDEV_S_EDID</refname>
10 <refpurpose>Get or set the EDID of a video receiver/transmitter</refpurpose> 12 <refpurpose>Get or set the EDID of a video receiver/transmitter</refpurpose>
11 </refnamediv> 13 </refnamediv>
12 14
@@ -42,7 +44,7 @@
42 <varlistentry> 44 <varlistentry>
43 <term><parameter>request</parameter></term> 45 <term><parameter>request</parameter></term>
44 <listitem> 46 <listitem>
45 <para>VIDIOC_G_EDID, VIDIOC_S_EDID</para> 47 <para>VIDIOC_G_EDID, VIDIOC_S_EDID, VIDIOC_SUBDEV_G_EDID, VIDIOC_SUBDEV_S_EDID</para>
46 </listitem> 48 </listitem>
47 </varlistentry> 49 </varlistentry>
48 <varlistentry> 50 <varlistentry>
@@ -82,6 +84,13 @@
82 <para>If blocks have to be retrieved from the sink, then this call will block until they 84 <para>If blocks have to be retrieved from the sink, then this call will block until they
83 have been read.</para> 85 have been read.</para>
84 86
87 <para>If <structfield>start_block</structfield> and <structfield>blocks</structfield> are
88 both set to 0 when <constant>VIDIOC_G_EDID</constant> is called, then the driver will
89 set <structfield>blocks</structfield> to the total number of available EDID blocks
90 and it will return 0 without copying any data. This is an easy way to discover how many
91 EDID blocks there are. Note that if there are no EDID blocks available at all, then
92 the driver will set <structfield>blocks</structfield> to 0 and it returns 0.</para>
93
85 <para>To set the EDID blocks of a receiver the application has to fill in the <structfield>pad</structfield>, 94 <para>To set the EDID blocks of a receiver the application has to fill in the <structfield>pad</structfield>,
86 <structfield>blocks</structfield> and <structfield>edid</structfield> fields and set 95 <structfield>blocks</structfield> and <structfield>edid</structfield> fields and set
87 <structfield>start_block</structfield> to 0. It is not possible to set part of an EDID, 96 <structfield>start_block</structfield> to 0. It is not possible to set part of an EDID,
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-selection.xml b/Documentation/DocBook/media/v4l/vidioc-g-selection.xml
index 0bb5c060db27..7865351688da 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-selection.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-selection.xml
@@ -199,7 +199,7 @@ exist no rectangle</emphasis> that satisfies the constraints.</para>
199 <row> 199 <row>
200 <entry>__u32</entry> 200 <entry>__u32</entry>
201 <entry><structfield>reserved[9]</structfield></entry> 201 <entry><structfield>reserved[9]</structfield></entry>
202 <entry>Reserved fields for future use.</entry> 202 <entry>Reserved fields for future use. Drivers and applications must zero this array.</entry>
203 </row> 203 </row>
204 </tbody> 204 </tbody>
205 </tgroup> 205 </tgroup>
diff --git a/Documentation/DocBook/media/v4l/vidioc-qbuf.xml b/Documentation/DocBook/media/v4l/vidioc-qbuf.xml
index 3504a7f2f382..8b98a0e421fc 100644
--- a/Documentation/DocBook/media/v4l/vidioc-qbuf.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-qbuf.xml
@@ -187,6 +187,16 @@ continue streaming.
187 </para> 187 </para>
188 </listitem> 188 </listitem>
189 </varlistentry> 189 </varlistentry>
190 <varlistentry>
191 <term><errorcode>EPIPE</errorcode></term>
192 <listitem>
193 <para><constant>VIDIOC_DQBUF</constant> returns this on an empty
194capture queue for mem2mem codecs if a buffer with the
195<constant>V4L2_BUF_FLAG_LAST</constant> was already dequeued and no new buffers
196are expected to become available.
197 </para>
198 </listitem>
199 </varlistentry>
190 </variablelist> 200 </variablelist>
191 </refsect1> 201 </refsect1>
192</refentry> 202</refentry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-query-dv-timings.xml b/Documentation/DocBook/media/v4l/vidioc-query-dv-timings.xml
index e185f149e0a1..e9c70a8f3476 100644
--- a/Documentation/DocBook/media/v4l/vidioc-query-dv-timings.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-query-dv-timings.xml
@@ -6,6 +6,7 @@
6 6
7 <refnamediv> 7 <refnamediv>
8 <refname>VIDIOC_QUERY_DV_TIMINGS</refname> 8 <refname>VIDIOC_QUERY_DV_TIMINGS</refname>
9 <refname>VIDIOC_SUBDEV_QUERY_DV_TIMINGS</refname>
9 <refpurpose>Sense the DV preset received by the current 10 <refpurpose>Sense the DV preset received by the current
10input</refpurpose> 11input</refpurpose>
11 </refnamediv> 12 </refnamediv>
@@ -34,7 +35,7 @@ input</refpurpose>
34 <varlistentry> 35 <varlistentry>
35 <term><parameter>request</parameter></term> 36 <term><parameter>request</parameter></term>
36 <listitem> 37 <listitem>
37 <para>VIDIOC_QUERY_DV_TIMINGS</para> 38 <para>VIDIOC_QUERY_DV_TIMINGS, VIDIOC_SUBDEV_QUERY_DV_TIMINGS</para>
38 </listitem> 39 </listitem>
39 </varlistentry> 40 </varlistentry>
40 <varlistentry> 41 <varlistentry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-querybuf.xml b/Documentation/DocBook/media/v4l/vidioc-querybuf.xml
index a597155c052d..50bfcb5e8508 100644
--- a/Documentation/DocBook/media/v4l/vidioc-querybuf.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-querybuf.xml
@@ -60,7 +60,8 @@ buffer at any time after buffers have been allocated with the
60 field. Valid index numbers range from zero 60 field. Valid index numbers range from zero
61to the number of buffers allocated with &VIDIOC-REQBUFS; 61to the number of buffers allocated with &VIDIOC-REQBUFS;
62 (&v4l2-requestbuffers; <structfield>count</structfield>) minus one. 62 (&v4l2-requestbuffers; <structfield>count</structfield>) minus one.
63The <structfield>reserved</structfield> field should to set to 0. 63The <structfield>reserved</structfield> and <structfield>reserved2 </structfield>
64fields must be set to 0.
64When using the <link linkend="planar-apis">multi-planar API</link>, the 65When using the <link linkend="planar-apis">multi-planar API</link>, the
65<structfield>m.planes</structfield> field must contain a userspace pointer to an 66<structfield>m.planes</structfield> field must contain a userspace pointer to an
66array of &v4l2-plane; and the <structfield>length</structfield> field has 67array of &v4l2-plane; and the <structfield>length</structfield> field has
diff --git a/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml b/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
index 78a06a9a5ece..0f193fda0470 100644
--- a/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
@@ -112,8 +112,8 @@ as the &v4l2-format; <structfield>type</structfield> field. See <xref
112 <row> 112 <row>
113 <entry>__u32</entry> 113 <entry>__u32</entry>
114 <entry><structfield>reserved</structfield>[2]</entry> 114 <entry><structfield>reserved</structfield>[2]</entry>
115 <entry>A place holder for future extensions. This array should 115 <entry>A place holder for future extensions. Drivers and applications
116be zeroed by applications.</entry> 116must set the array to zero.</entry>
117 </row> 117 </row>
118 </tbody> 118 </tbody>
119 </tgroup> 119 </tgroup>
diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index d0332f610929..5fd0ee78f880 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -5,7 +5,8 @@
5 </refmeta> 5 </refmeta>
6 6
7 <refnamediv> 7 <refnamediv>
8 <refname>VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT</refname> 8 <refname>VIDIOC_SUBSCRIBE_EVENT</refname>
9 <refname>VIDIOC_UNSUBSCRIBE_EVENT</refname>
9 <refpurpose>Subscribe or unsubscribe event</refpurpose> 10 <refpurpose>Subscribe or unsubscribe event</refpurpose>
10 </refnamediv> 11 </refnamediv>
11 12
diff --git a/Documentation/DocBook/media_api.tmpl b/Documentation/DocBook/media_api.tmpl
index 03f9a1f8d413..f3f5fe5b64c9 100644
--- a/Documentation/DocBook/media_api.tmpl
+++ b/Documentation/DocBook/media_api.tmpl
@@ -1,12 +1,13 @@
1<?xml version="1.0"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [ 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4<!ENTITY % media-entities SYSTEM "./media-entities.tmpl"> %media-entities; 4<!ENTITY % media-entities SYSTEM "./media-entities.tmpl"> %media-entities;
5<!ENTITY media-indices SYSTEM "./media-indices.tmpl"> 5<!ENTITY media-indices SYSTEM "./media-indices.tmpl">
6 6
7<!ENTITY eg "e.&nbsp;g."> 7<!ENTITY eg "e.&nbsp;g.">
8<!ENTITY ie "i.&nbsp;e."> 8<!ENTITY ie "i.&nbsp;e.">
9<!ENTITY fd "File descriptor returned by <link linkend='func-open'><function>open()</function></link>."> 9<!ENTITY fd "File descriptor returned by <link linkend='func-open'><function>open()</function></link>.">
10<!ENTITY fe_fd "File descriptor returned by <link linkend='frontend_f_open'><function>open()</function></link>.">
10<!ENTITY i2c "I<superscript>2</superscript>C"> 11<!ENTITY i2c "I<superscript>2</superscript>C">
11<!ENTITY return-value "<title>Return Value</title><para>On success <returnvalue>0</returnvalue> is returned, on error <returnvalue>-1</returnvalue> and the <varname>errno</varname> variable is set appropriately. The generic error codes are described at the <link linkend='gen-errors'>Generic Error Codes</link> chapter.</para>"> 12<!ENTITY return-value "<title>Return Value</title><para>On success <returnvalue>0</returnvalue> is returned, on error <returnvalue>-1</returnvalue> and the <varname>errno</varname> variable is set appropriately. The generic error codes are described at the <link linkend='gen-errors'>Generic Error Codes</link> chapter.</para>">
12<!ENTITY return-value-dvb "<para>RETURN VALUE</para><para>On success <returnvalue>0</returnvalue> is returned, on error <returnvalue>-1</returnvalue> and the <varname>errno</varname> variable is set appropriately. The generic error codes are described at the <link linkend='gen-errors'>Generic Error Codes</link> chapter.</para>"> 13<!ENTITY return-value-dvb "<para>RETURN VALUE</para><para>On success <returnvalue>0</returnvalue> is returned, on error <returnvalue>-1</returnvalue> and the <varname>errno</varname> variable is set appropriately. The generic error codes are described at the <link linkend='gen-errors'>Generic Error Codes</link> chapter.</para>">
@@ -32,7 +33,7 @@
32<!ENTITY dash-ent-24 "<entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry>"> 33<!ENTITY dash-ent-24 "<entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry>">
33]> 34]>
34 35
35<book id="media_api"> 36<book id="media_api" lang="en">
36<bookinfo> 37<bookinfo>
37 <title>LINUX MEDIA INFRASTRUCTURE API</title> 38 <title>LINUX MEDIA INFRASTRUCTURE API</title>
38 39
@@ -60,28 +61,56 @@
60 analog and digital TV receiver cards, AM/FM receiver cards, 61 analog and digital TV receiver cards, AM/FM receiver cards,
61 streaming capture and output devices, codec devices and remote 62 streaming capture and output devices, codec devices and remote
62 controllers.</para> 63 controllers.</para>
63 <para>It is divided into four parts.</para> 64 <para>A typical media device hardware is shown at
65 <xref linkend="typical_media_device" />.</para>
66 <figure id="typical_media_device">
67 <title>Typical Media Device</title>
68 <mediaobject>
69 <imageobject>
70 <imagedata fileref="typical_media_device.svg" format="SVG" />
71 </imageobject>
72 <textobject>
73 <phrase>Typical Media Device Block Diagram</phrase>
74 </textobject>
75 </mediaobject>
76 </figure>
77 <para>The media infrastructure API was designed to control such
78 devices. It is divided into four parts.</para>
64 <para>The first part covers radio, video capture and output, 79 <para>The first part covers radio, video capture and output,
65 cameras, analog TV devices and codecs.</para> 80 cameras, analog TV devices and codecs.</para>
66 <para>The second part covers the 81 <para>The second part covers the
67 API used for digital TV and Internet reception via one of the 82 API used for digital TV and Internet reception via one of the
68 several digital tv standards. While it is called as DVB API, 83 several digital tv standards. While it is called as DVB API,
69 in fact it covers several different video standards including 84 in fact it covers several different video standards including
70 DVB-T, DVB-S, DVB-C and ATSC. The API is currently being updated 85 DVB-T/T2, DVB-S/S2, DVB-C, ATSC, ISDB-T, ISDB-S,etc. The complete
71 to document support also for DVB-S2, ISDB-T and ISDB-S.</para> 86 list of supported standards can be found at
87 <xref linkend="fe-delivery-system-t" />.</para>
72 <para>The third part covers the Remote Controller API.</para> 88 <para>The third part covers the Remote Controller API.</para>
73 <para>The fourth part covers the Media Controller API.</para> 89 <para>The fourth part covers the Media Controller API.</para>
90 <para>It should also be noted that a media device may also have audio
91 components, like mixers, PCM capture, PCM playback, etc, which
92 are controlled via ALSA API.</para>
74 <para>For additional information and for the latest development code, 93 <para>For additional information and for the latest development code,
75 see: <ulink url="http://linuxtv.org">http://linuxtv.org</ulink>.</para> 94 see: <ulink url="http://linuxtv.org">http://linuxtv.org</ulink>.</para>
76 <para>For discussing improvements, reporting troubles, sending new drivers, etc, please mail to: <ulink url="http://vger.kernel.org/vger-lists.html#linux-media">Linux Media Mailing List (LMML).</ulink>.</para> 95 <para>For discussing improvements, reporting troubles, sending new drivers, etc, please mail to: <ulink url="http://vger.kernel.org/vger-lists.html#linux-media">Linux Media Mailing List (LMML).</ulink>.</para>
77</preface> 96</preface>
78 97
79<part id="v4l2spec">&sub-v4l2;</part> 98<part id="v4l2spec">
80<part id="dvbapi">&sub-dvbapi;</part> 99&sub-v4l2;
81<part id="remotes">&sub-remote_controllers;</part> 100</part>
82<part id="media_common">&sub-media-controller;</part> 101<part id="dvbapi">
102&sub-dvbapi;
103</part>
104<part id="remotes">
105&sub-remote_controllers;
106</part>
107<part id="media_common">
108&sub-media-controller;
109</part>
83 110
84<chapter id="gen_errors">&sub-gen-errors;</chapter> 111<chapter id="gen_errors">
112&sub-gen-errors;
113</chapter>
85 114
86&sub-fdl-appendix; 115&sub-fdl-appendix;
87 116
diff --git a/Documentation/devicetree/bindings/media/i2c/adp1653.txt b/Documentation/devicetree/bindings/media/i2c/adp1653.txt
new file mode 100644
index 000000000000..5ce66f2104e3
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/adp1653.txt
@@ -0,0 +1,37 @@
1* Analog Devices ADP1653 flash LED driver
2
3Required Properties:
4
5 - compatible: Must contain "adi,adp1653"
6
7 - reg: I2C slave address
8
9 - enable-gpios: Specifier of the GPIO connected to EN pin
10
11There are two LED outputs available - flash and indicator. One LED is
12represented by one child node, nodes need to be named "flash" and "indicator".
13
14Required properties of the LED child node:
15- max-microamp : see Documentation/devicetree/bindings/leds/common.txt
16
17Required properties of the flash LED child node:
18
19- flash-max-microamp : see Documentation/devicetree/bindings/leds/common.txt
20- flash-timeout-us : see Documentation/devicetree/bindings/leds/common.txt
21
22Example:
23
24 adp1653: led-controller@30 {
25 compatible = "adi,adp1653";
26 reg = <0x30>;
27 enable-gpios = <&gpio3 24 GPIO_ACTIVE_HIGH>; /* 88 */
28
29 flash {
30 flash-timeout-us = <500000>;
31 flash-max-microamp = <320000>;
32 max-microamp = <50000>;
33 };
34 indicator {
35 max-microamp = <17500>;
36 };
37 };
diff --git a/Documentation/devicetree/bindings/media/st,stih4xx.txt b/Documentation/devicetree/bindings/media/st,stih4xx.txt
new file mode 100644
index 000000000000..df655cd3a4f8
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st,stih4xx.txt
@@ -0,0 +1,32 @@
1STMicroelectronics stih4xx platforms
2
3bdisp: 2D blitter for STMicroelectronics SoC.
4
5Required properties:
6- compatible: should be "st,stih407-bdisp".
7- reg: BDISP physical address location and length.
8- interrupts: BDISP interrupt number.
9- clocks: from common clock binding: handle hardware IP needed clocks, the
10 number of clocks may depend on the SoC type.
11 See ../clocks/clock-bindings.txt for details.
12- clock-names: names of the clocks listed in clocks property in the same order.
13
14Example:
15
16 bdisp0:bdisp@9f10000 {
17 compatible = "st,stih407-bdisp";
18 reg = <0x9f10000 0x1000>;
19 interrupts = <GIC_SPI 38 IRQ_TYPE_NONE>;
20 clock-names = "bdisp";
21 clocks = <&clk_s_c0_flexgen CLK_IC_BDISP_0>;
22 };
23
24Aliases:
25Each BDISP should have a numbered alias in the aliases node, in the form of
26bdispN, N = 0 or 1.
27
28Example:
29
30 aliases {
31 bdisp0 = &bdisp0;
32 };
diff --git a/Documentation/video4linux/CARDLIST.cx23885 b/Documentation/video4linux/CARDLIST.cx23885
index 4c84ec853265..44a4cfbfdc40 100644
--- a/Documentation/video4linux/CARDLIST.cx23885
+++ b/Documentation/video4linux/CARDLIST.cx23885
@@ -36,7 +36,7 @@
36 35 -> TeVii S471 [d471:9022] 36 35 -> TeVii S471 [d471:9022]
37 36 -> Hauppauge WinTV-HVR1255 [0070:2259] 37 36 -> Hauppauge WinTV-HVR1255 [0070:2259]
38 37 -> Prof Revolution DVB-S2 8000 [8000:3034] 38 37 -> Prof Revolution DVB-S2 8000 [8000:3034]
39 38 -> Hauppauge WinTV-HVR4400 [0070:c108,0070:c138,0070:c12a,0070:c1f8] 39 38 -> Hauppauge WinTV-HVR4400/HVR5500 [0070:c108,0070:c138,0070:c1f8]
40 39 -> AVerTV Hybrid Express Slim HC81R [1461:d939] 40 39 -> AVerTV Hybrid Express Slim HC81R [1461:d939]
41 40 -> TurboSight TBS 6981 [6981:8888] 41 40 -> TurboSight TBS 6981 [6981:8888]
42 41 -> TurboSight TBS 6980 [6980:8888] 42 41 -> TurboSight TBS 6980 [6980:8888]
@@ -45,3 +45,10 @@
45 44 -> DViCO FusionHDTV DVB-T Dual Express2 [18ac:db98] 45 44 -> DViCO FusionHDTV DVB-T Dual Express2 [18ac:db98]
46 45 -> DVBSky T9580 [4254:9580] 46 45 -> DVBSky T9580 [4254:9580]
47 46 -> DVBSky T980C [4254:980c] 47 46 -> DVBSky T980C [4254:980c]
48 47 -> DVBSky S950C [4254:950c]
49 48 -> Technotrend TT-budget CT2-4500 CI [13c2:3013]
50 49 -> DVBSky S950 [4254:0950]
51 50 -> DVBSky S952 [4254:0952]
52 51 -> DVBSky T982 [4254:0982]
53 52 -> Hauppauge WinTV-HVR5525 [0070:f038]
54 53 -> Hauppauge WinTV Starburst [0070:c12a]
diff --git a/Documentation/video4linux/CARDLIST.em28xx b/Documentation/video4linux/CARDLIST.em28xx
index 3700edb81db2..9e57ce43c4f4 100644
--- a/Documentation/video4linux/CARDLIST.em28xx
+++ b/Documentation/video4linux/CARDLIST.em28xx
@@ -94,3 +94,5 @@
94 93 -> KWorld USB ATSC TV Stick UB435-Q V3 (em2874) [1b80:e34c] 94 93 -> KWorld USB ATSC TV Stick UB435-Q V3 (em2874) [1b80:e34c]
95 94 -> PCTV tripleStick (292e) (em28178) 95 94 -> PCTV tripleStick (292e) (em28178)
96 95 -> Leadtek VC100 (em2861) [0413:6f07] 96 95 -> Leadtek VC100 (em2861) [0413:6f07]
97 96 -> Terratec Cinergy T2 Stick HD (em28178)
98 97 -> Elgato EyeTV Hybrid 2008 INT (em2884) [0fd9:0018]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index a93d86455233..f4b395bdc090 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -192,3 +192,4 @@
192191 -> Hawell HW-9004V1 192191 -> Hawell HW-9004V1
193192 -> AverMedia AverTV Satellite Hybrid+FM A706 [1461:2055] 193192 -> AverMedia AverTV Satellite Hybrid+FM A706 [1461:2055]
194193 -> WIS Voyager or compatible [1905:7007] 194193 -> WIS Voyager or compatible [1905:7007]
195194 -> AverMedia AverTV/505 [1461:a10a]
diff --git a/Documentation/video4linux/CARDLIST.saa7164 b/Documentation/video4linux/CARDLIST.saa7164
index 2205e8d55537..6eb057220474 100644
--- a/Documentation/video4linux/CARDLIST.saa7164
+++ b/Documentation/video4linux/CARDLIST.saa7164
@@ -9,3 +9,6 @@
9 8 -> Hauppauge WinTV-HVR2250 [0070:88A1] 9 8 -> Hauppauge WinTV-HVR2250 [0070:88A1]
10 9 -> Hauppauge WinTV-HVR2200 [0070:8940] 10 9 -> Hauppauge WinTV-HVR2200 [0070:8940]
11 10 -> Hauppauge WinTV-HVR2200 [0070:8953] 11 10 -> Hauppauge WinTV-HVR2200 [0070:8953]
12 11 -> Hauppauge WinTV-HVR2255(proto)
13 12 -> Hauppauge WinTV-HVR2255 [0070:f111]
14 13 -> Hauppauge WinTV-HVR2205 [0070:f123,0070:f120]
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index 59e619f9bbf5..75d5c18d689a 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -1129,6 +1129,10 @@ available event type is 'class base + 1'.
1129An example on how the V4L2 events may be used can be found in the OMAP 1129An example on how the V4L2 events may be used can be found in the OMAP
11303 ISP driver (drivers/media/platform/omap3isp). 11303 ISP driver (drivers/media/platform/omap3isp).
1131 1131
1132A subdev can directly send an event to the v4l2_device notify function with
1133V4L2_DEVICE_NOTIFY_EVENT. This allows the bridge to map the subdev that sends
1134the event to the video node(s) associated with the subdev that need to be
1135informed about such an event.
1132 1136
1133V4L2 clocks 1137V4L2 clocks
1134----------- 1138-----------
diff --git a/Documentation/video4linux/v4l2-pci-skeleton.c b/Documentation/video4linux/v4l2-pci-skeleton.c
index 7bd1b975bfd2..9c80c090e92d 100644
--- a/Documentation/video4linux/v4l2-pci-skeleton.c
+++ b/Documentation/video4linux/v4l2-pci-skeleton.c
@@ -406,9 +406,7 @@ static int skeleton_enum_fmt_vid_cap(struct file *file, void *priv,
406 if (f->index != 0) 406 if (f->index != 0)
407 return -EINVAL; 407 return -EINVAL;
408 408
409 strlcpy(f->description, "4:2:2, packed, YUYV", sizeof(f->description));
410 f->pixelformat = V4L2_PIX_FMT_YUYV; 409 f->pixelformat = V4L2_PIX_FMT_YUYV;
411 f->flags = 0;
412 return 0; 410 return 0;
413} 411}
414 412
diff --git a/Documentation/video4linux/vivid.txt b/Documentation/video4linux/vivid.txt
index cd4b5a1ac529..e35d376b7f64 100644
--- a/Documentation/video4linux/vivid.txt
+++ b/Documentation/video4linux/vivid.txt
@@ -631,26 +631,33 @@ Timestamp Source: selects when the timestamp for each buffer is taken.
631 631
632Colorspace: selects which colorspace should be used when generating the image. 632Colorspace: selects which colorspace should be used when generating the image.
633 This only applies if the CSC Colorbar test pattern is selected, 633 This only applies if the CSC Colorbar test pattern is selected,
634 otherwise the test pattern will go through unconverted (except for 634 otherwise the test pattern will go through unconverted.
635 the so-called 'Transfer Function' corrections and the R'G'B' to Y'CbCr 635 This behavior is also what you want, since a 75% Colorbar
636 conversion). This behavior is also what you want, since a 75% Colorbar
637 should really have 75% signal intensity and should not be affected 636 should really have 75% signal intensity and should not be affected
638 by colorspace conversions. 637 by colorspace conversions.
639 638
640 Changing the colorspace will result in the V4L2_EVENT_SOURCE_CHANGE 639 Changing the colorspace will result in the V4L2_EVENT_SOURCE_CHANGE
641 to be sent since it emulates a detected colorspace change. 640 to be sent since it emulates a detected colorspace change.
642 641
642Transfer Function: selects which colorspace transfer function should be used when
643 generating an image. This only applies if the CSC Colorbar test pattern is
644 selected, otherwise the test pattern will go through unconverted.
645 This behavior is also what you want, since a 75% Colorbar
646 should really have 75% signal intensity and should not be affected
647 by colorspace conversions.
648
649 Changing the transfer function will result in the V4L2_EVENT_SOURCE_CHANGE
650 to be sent since it emulates a detected colorspace change.
651
643Y'CbCr Encoding: selects which Y'CbCr encoding should be used when generating 652Y'CbCr Encoding: selects which Y'CbCr encoding should be used when generating
644 a Y'CbCr image. This only applies if the CSC Colorbar test pattern is 653 a Y'CbCr image. This only applies if the format is set to a Y'CbCr format
645 selected, and if the format is set to a Y'CbCr format as opposed to an 654 as opposed to an RGB format.
646 RGB format.
647 655
648 Changing the Y'CbCr encoding will result in the V4L2_EVENT_SOURCE_CHANGE 656 Changing the Y'CbCr encoding will result in the V4L2_EVENT_SOURCE_CHANGE
649 to be sent since it emulates a detected colorspace change. 657 to be sent since it emulates a detected colorspace change.
650 658
651Quantization: selects which quantization should be used for the RGB or Y'CbCr 659Quantization: selects which quantization should be used for the RGB or Y'CbCr
652 encoding when generating the test pattern. This only applies if the CSC 660 encoding when generating the test pattern.
653 Colorbar test pattern is selected.
654 661
655 Changing the quantization will result in the V4L2_EVENT_SOURCE_CHANGE 662 Changing the quantization will result in the V4L2_EVENT_SOURCE_CHANGE
656 to be sent since it emulates a detected colorspace change. 663 to be sent since it emulates a detected colorspace change.
@@ -888,7 +895,7 @@ Section 10.1: Video and Sliced VBI looping
888 895
889The way to enable video/VBI looping is currently fairly crude. A 'Loop Video' 896The way to enable video/VBI looping is currently fairly crude. A 'Loop Video'
890control is available in the "Vivid" control class of the video 897control is available in the "Vivid" control class of the video
891output and VBI output devices. When checked the video looping will be enabled. 898capture and VBI capture devices. When checked the video looping will be enabled.
892Once enabled any video S-Video or HDMI input will show a static test pattern 899Once enabled any video S-Video or HDMI input will show a static test pattern
893until the video output has started. At that time the video output will be 900until the video output has started. At that time the video output will be
894looped to the video input provided that: 901looped to the video input provided that:
@@ -985,8 +992,9 @@ to change crop and compose rectangles on the fly.
985Section 12: Formats 992Section 12: Formats
986------------------- 993-------------------
987 994
988The driver supports all the regular packed YUYV formats, 16, 24 and 32 RGB 995The driver supports all the regular packed and planar 4:4:4, 4:2:2 and 4:2:0
989packed formats and two multiplanar formats (one luma and one chroma plane). 996YUYV formats, 8, 16, 24 and 32 RGB packed formats and various multiplanar
997formats.
990 998
991The alpha component can be set through the 'Alpha Component' User control 999The alpha component can be set through the 'Alpha Component' User control
992for those formats that support it. If the 'Apply Alpha To Red Only' control 1000for those formats that support it. If the 'Apply Alpha To Red Only' control
@@ -1119,11 +1127,9 @@ Just as a reminder and in no particular order:
1119- Use per-queue locks and/or per-device locks to improve throughput 1127- Use per-queue locks and/or per-device locks to improve throughput
1120- Add support to loop from a specific output to a specific input across 1128- Add support to loop from a specific output to a specific input across
1121 vivid instances 1129 vivid instances
1122- Add support for VIDIOC_EXPBUF once support for that has been added to vb2
1123- The SDR radio should use the same 'frequencies' for stations as the normal 1130- The SDR radio should use the same 'frequencies' for stations as the normal
1124 radio receiver, and give back noise if the frequency doesn't match up with 1131 radio receiver, and give back noise if the frequency doesn't match up with
1125 a station frequency 1132 a station frequency
1126- Improve the sine generation of the SDR radio.
1127- Make a thread for the RDS generation, that would help in particular for the 1133- Make a thread for the RDS generation, that would help in particular for the
1128 "Controls" RDS Rx I/O Mode as the read-only RDS controls could be updated 1134 "Controls" RDS Rx I/O Mode as the read-only RDS controls could be updated
1129 in real-time. 1135 in real-time.
diff --git a/MAINTAINERS b/MAINTAINERS
index dec4c7fa6ff3..d73b6561905a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1991,6 +1991,14 @@ W: http://bcache.evilpiepirate.org
1991S: Maintained: 1991S: Maintained:
1992F: drivers/md/bcache/ 1992F: drivers/md/bcache/
1993 1993
1994BDISP ST MEDIA DRIVER
1995M: Fabien Dessenne <fabien.dessenne@st.com>
1996L: linux-media@vger.kernel.org
1997T: git git://linuxtv.org/media_tree.git
1998W: http://linuxtv.org
1999S: Supported
2000F: drivers/media/platform/sti/bdisp
2001
1994BEFS FILE SYSTEM 2002BEFS FILE SYSTEM
1995S: Orphan 2003S: Orphan
1996F: Documentation/filesystems/befs.txt 2004F: Documentation/filesystems/befs.txt
@@ -2659,6 +2667,14 @@ L: platform-driver-x86@vger.kernel.org
2659S: Supported 2667S: Supported
2660F: drivers/platform/x86/classmate-laptop.c 2668F: drivers/platform/x86/classmate-laptop.c
2661 2669
2670COBALT MEDIA DRIVER
2671M: Hans Verkuil <hans.verkuil@cisco.com>
2672L: linux-media@vger.kernel.org
2673T: git git://linuxtv.org/media_tree.git
2674W: http://linuxtv.org
2675S: Supported
2676F: drivers/media/pci/cobalt/
2677
2662COCCINELLE/Semantic Patches (SmPL) 2678COCCINELLE/Semantic Patches (SmPL)
2663M: Julia Lawall <Julia.Lawall@lip6.fr> 2679M: Julia Lawall <Julia.Lawall@lip6.fr>
2664M: Gilles Muller <Gilles.Muller@lip6.fr> 2680M: Gilles Muller <Gilles.Muller@lip6.fr>
@@ -2930,6 +2946,15 @@ S: Maintained
2930F: drivers/media/common/cx2341x* 2946F: drivers/media/common/cx2341x*
2931F: include/media/cx2341x* 2947F: include/media/cx2341x*
2932 2948
2949CX24120 MEDIA DRIVER
2950M: Jemma Denson <jdenson@gmail.com>
2951M: Patrick Boettcher <patrick.boettcher@posteo.de>
2952L: linux-media@vger.kernel.org
2953W: http://linuxtv.org/
2954Q: http://patchwork.linuxtv.org/project/linux-media/list/
2955S: Maintained
2956F: drivers/media/dvb-frontends/cx24120*
2957
2933CX88 VIDEO4LINUX DRIVER 2958CX88 VIDEO4LINUX DRIVER
2934M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 2959M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2935L: linux-media@vger.kernel.org 2960L: linux-media@vger.kernel.org
@@ -3498,6 +3523,14 @@ L: netdev@vger.kernel.org
3498S: Maintained 3523S: Maintained
3499F: drivers/net/wan/dscc4.c 3524F: drivers/net/wan/dscc4.c
3500 3525
3526DT3155 MEDIA DRIVER
3527M: Hans Verkuil <hverkuil@xs4all.nl>
3528L: linux-media@vger.kernel.org
3529T: git git://linuxtv.org/media_tree.git
3530W: http://linuxtv.org
3531S: Odd Fixes
3532F: drivers/media/pci/dt3155/
3533
3501DVB_USB_AF9015 MEDIA DRIVER 3534DVB_USB_AF9015 MEDIA DRIVER
3502M: Antti Palosaari <crope@iki.fi> 3535M: Antti Palosaari <crope@iki.fi>
3503L: linux-media@vger.kernel.org 3536L: linux-media@vger.kernel.org
@@ -6434,6 +6467,15 @@ W: http://linuxtv.org
6434S: Maintained 6467S: Maintained
6435F: drivers/media/radio/radio-maxiradio* 6468F: drivers/media/radio/radio-maxiradio*
6436 6469
6470MEDIA DRIVERS FOR RENESAS - VSP1
6471M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6472L: linux-media@vger.kernel.org
6473L: linux-sh@vger.kernel.org
6474T: git git://linuxtv.org/media_tree.git
6475S: Supported
6476F: Documentation/devicetree/bindings/media/renesas,vsp1.txt
6477F: drivers/media/platform/vsp1/
6478
6437MEDIA INPUT INFRASTRUCTURE (V4L/DVB) 6479MEDIA INPUT INFRASTRUCTURE (V4L/DVB)
6438M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 6480M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
6439P: LinuxTV.org Project 6481P: LinuxTV.org Project
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 7afa6a2b776c..d20fe1dff403 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -980,8 +980,7 @@ config TOUCHSCREEN_SUN4I
980 980
981config TOUCHSCREEN_SUR40 981config TOUCHSCREEN_SUR40
982 tristate "Samsung SUR40 (Surface 2.0/PixelSense) touchscreen" 982 tristate "Samsung SUR40 (Surface 2.0/PixelSense) touchscreen"
983 depends on USB 983 depends on USB && MEDIA_USB_SUPPORT && HAS_DMA
984 depends on MEDIA_USB_SUPPORT
985 select INPUT_POLLDEV 984 select INPUT_POLLDEV
986 select VIDEOBUF2_DMA_SG 985 select VIDEOBUF2_DMA_SG
987 help 986 help
diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
index a24eba5ea843..8be7b9b79f20 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -125,7 +125,7 @@ struct sur40_image_header {
125#define VIDEO_PACKET_SIZE 16384 125#define VIDEO_PACKET_SIZE 16384
126 126
127/* polling interval (ms) */ 127/* polling interval (ms) */
128#define POLL_INTERVAL 10 128#define POLL_INTERVAL 4
129 129
130/* maximum number of contacts FIXME: this is a guess? */ 130/* maximum number of contacts FIXME: this is a guess? */
131#define MAX_CONTACTS 64 131#define MAX_CONTACTS 64
@@ -342,7 +342,7 @@ static void sur40_poll(struct input_polled_dev *polldev)
342 * instead of at the end. 342 * instead of at the end.
343 */ 343 */
344 if (packet_id != header->packet_id) 344 if (packet_id != header->packet_id)
345 dev_warn(sur40->dev, "packet ID mismatch\n"); 345 dev_dbg(sur40->dev, "packet ID mismatch\n");
346 346
347 packet_blobs = result / sizeof(struct sur40_blob); 347 packet_blobs = result / sizeof(struct sur40_blob);
348 dev_dbg(sur40->dev, "received %d blobs\n", packet_blobs); 348 dev_dbg(sur40->dev, "received %d blobs\n", packet_blobs);
@@ -389,6 +389,8 @@ static void sur40_process_video(struct sur40_state *sur40)
389 list_del(&new_buf->list); 389 list_del(&new_buf->list);
390 spin_unlock(&sur40->qlock); 390 spin_unlock(&sur40->qlock);
391 391
392 dev_dbg(sur40->dev, "buffer acquired\n");
393
392 /* retrieve data via bulk read */ 394 /* retrieve data via bulk read */
393 result = usb_bulk_msg(sur40->usbdev, 395 result = usb_bulk_msg(sur40->usbdev,
394 usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 396 usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT),
@@ -416,6 +418,8 @@ static void sur40_process_video(struct sur40_state *sur40)
416 goto err_poll; 418 goto err_poll;
417 } 419 }
418 420
421 dev_dbg(sur40->dev, "header acquired\n");
422
419 sgt = vb2_dma_sg_plane_desc(&new_buf->vb, 0); 423 sgt = vb2_dma_sg_plane_desc(&new_buf->vb, 0);
420 424
421 result = usb_sg_init(&sgr, sur40->usbdev, 425 result = usb_sg_init(&sgr, sur40->usbdev,
@@ -432,11 +436,18 @@ static void sur40_process_video(struct sur40_state *sur40)
432 goto err_poll; 436 goto err_poll;
433 } 437 }
434 438
439 dev_dbg(sur40->dev, "image acquired\n");
440
441 /* return error if streaming was stopped in the meantime */
442 if (sur40->sequence == -1)
443 goto err_poll;
444
435 /* mark as finished */ 445 /* mark as finished */
436 v4l2_get_timestamp(&new_buf->vb.v4l2_buf.timestamp); 446 v4l2_get_timestamp(&new_buf->vb.v4l2_buf.timestamp);
437 new_buf->vb.v4l2_buf.sequence = sur40->sequence++; 447 new_buf->vb.v4l2_buf.sequence = sur40->sequence++;
438 new_buf->vb.v4l2_buf.field = V4L2_FIELD_NONE; 448 new_buf->vb.v4l2_buf.field = V4L2_FIELD_NONE;
439 vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_DONE); 449 vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_DONE);
450 dev_dbg(sur40->dev, "buffer marked done\n");
440 return; 451 return;
441 452
442err_poll: 453err_poll:
@@ -716,6 +727,7 @@ static int sur40_start_streaming(struct vb2_queue *vq, unsigned int count)
716static void sur40_stop_streaming(struct vb2_queue *vq) 727static void sur40_stop_streaming(struct vb2_queue *vq)
717{ 728{
718 struct sur40_state *sur40 = vb2_get_drv_priv(vq); 729 struct sur40_state *sur40 = vb2_get_drv_priv(vq);
730 sur40->sequence = -1;
719 731
720 /* Release all active buffers */ 732 /* Release all active buffers */
721 return_all_buffers(sur40, VB2_BUF_STATE_ERROR); 733 return_all_buffers(sur40, VB2_BUF_STATE_ERROR);
@@ -778,6 +790,33 @@ static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
778 return 0; 790 return 0;
779} 791}
780 792
793static int sur40_vidioc_enum_framesizes(struct file *file, void *priv,
794 struct v4l2_frmsizeenum *f)
795{
796 if ((f->index != 0) || (f->pixel_format != V4L2_PIX_FMT_GREY))
797 return -EINVAL;
798
799 f->type = V4L2_FRMSIZE_TYPE_DISCRETE;
800 f->discrete.width = sur40_video_format.width;
801 f->discrete.height = sur40_video_format.height;
802 return 0;
803}
804
805static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv,
806 struct v4l2_frmivalenum *f)
807{
808 if ((f->index > 1) || (f->pixel_format != V4L2_PIX_FMT_GREY)
809 || (f->width != sur40_video_format.width)
810 || (f->height != sur40_video_format.height))
811 return -EINVAL;
812
813 f->type = V4L2_FRMIVAL_TYPE_DISCRETE;
814 f->discrete.denominator = 60/(f->index+1);
815 f->discrete.numerator = 1;
816 return 0;
817}
818
819
781static const struct usb_device_id sur40_table[] = { 820static const struct usb_device_id sur40_table[] = {
782 { USB_DEVICE(ID_MICROSOFT, ID_SUR40) }, /* Samsung SUR40 */ 821 { USB_DEVICE(ID_MICROSOFT, ID_SUR40) }, /* Samsung SUR40 */
783 { } /* terminating null entry */ 822 { } /* terminating null entry */
@@ -829,6 +868,9 @@ static const struct v4l2_ioctl_ops sur40_video_ioctl_ops = {
829 .vidioc_s_fmt_vid_cap = sur40_vidioc_fmt, 868 .vidioc_s_fmt_vid_cap = sur40_vidioc_fmt,
830 .vidioc_g_fmt_vid_cap = sur40_vidioc_fmt, 869 .vidioc_g_fmt_vid_cap = sur40_vidioc_fmt,
831 870
871 .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes,
872 .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals,
873
832 .vidioc_enum_input = sur40_vidioc_enum_input, 874 .vidioc_enum_input = sur40_vidioc_enum_input,
833 .vidioc_g_input = sur40_vidioc_g_input, 875 .vidioc_g_input = sur40_vidioc_g_input,
834 .vidioc_s_input = sur40_vidioc_s_input, 876 .vidioc_s_input = sur40_vidioc_s_input,
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 157099243d61..3ef3d6c6bbf8 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -95,7 +95,7 @@ config MEDIA_CONTROLLER
95 This API is mostly used by camera interfaces in embedded platforms. 95 This API is mostly used by camera interfaces in embedded platforms.
96 96
97config MEDIA_CONTROLLER_DVB 97config MEDIA_CONTROLLER_DVB
98 bool "Enable Media controller for DVB" 98 bool "Enable Media controller for DVB (EXPERIMENTAL)"
99 depends on MEDIA_CONTROLLER 99 depends on MEDIA_CONTROLLER
100 depends on BROKEN 100 depends on BROKEN
101 ---help--- 101 ---help---
diff --git a/drivers/media/common/b2c2/Kconfig b/drivers/media/common/b2c2/Kconfig
index a8c6cdfaa2f5..e5936380b1e5 100644
--- a/drivers/media/common/b2c2/Kconfig
+++ b/drivers/media/common/b2c2/Kconfig
@@ -14,6 +14,7 @@ config DVB_B2C2_FLEXCOP
14 select DVB_S5H1420 if MEDIA_SUBDRV_AUTOSELECT 14 select DVB_S5H1420 if MEDIA_SUBDRV_AUTOSELECT
15 select DVB_TUNER_ITD1000 if MEDIA_SUBDRV_AUTOSELECT 15 select DVB_TUNER_ITD1000 if MEDIA_SUBDRV_AUTOSELECT
16 select DVB_ISL6421 if MEDIA_SUBDRV_AUTOSELECT 16 select DVB_ISL6421 if MEDIA_SUBDRV_AUTOSELECT
17 select DVB_CX24120 if MEDIA_SUBDRV_AUTOSELECT
17 select DVB_CX24123 if MEDIA_SUBDRV_AUTOSELECT 18 select DVB_CX24123 if MEDIA_SUBDRV_AUTOSELECT
18 select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT 19 select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT
19 select DVB_TUNER_CX24113 if MEDIA_SUBDRV_AUTOSELECT 20 select DVB_TUNER_CX24113 if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/common/b2c2/flexcop-common.h b/drivers/media/common/b2c2/flexcop-common.h
index 437912e49824..2b2460e9e6b4 100644
--- a/drivers/media/common/b2c2/flexcop-common.h
+++ b/drivers/media/common/b2c2/flexcop-common.h
@@ -91,6 +91,7 @@ struct flexcop_device {
91 int feedcount; 91 int feedcount;
92 int pid_filtering; 92 int pid_filtering;
93 int fullts_streaming_state; 93 int fullts_streaming_state;
94 int skip_6_hw_pid_filter;
94 95
95 /* bus specific callbacks */ 96 /* bus specific callbacks */
96 flexcop_ibi_value(*read_ibi_reg) (struct flexcop_device *, 97 flexcop_ibi_value(*read_ibi_reg) (struct flexcop_device *,
diff --git a/drivers/media/common/b2c2/flexcop-fe-tuner.c b/drivers/media/common/b2c2/flexcop-fe-tuner.c
index 7e14e90d2922..9c59f4306883 100644
--- a/drivers/media/common/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/common/b2c2/flexcop-fe-tuner.c
@@ -12,6 +12,7 @@
12#include "cx24113.h" 12#include "cx24113.h"
13#include "cx24123.h" 13#include "cx24123.h"
14#include "isl6421.h" 14#include "isl6421.h"
15#include "cx24120.h"
15#include "mt352.h" 16#include "mt352.h"
16#include "bcm3510.h" 17#include "bcm3510.h"
17#include "nxt200x.h" 18#include "nxt200x.h"
@@ -26,9 +27,20 @@
26#define FE_SUPPORTED(fe) (defined(CONFIG_DVB_##fe) || \ 27#define FE_SUPPORTED(fe) (defined(CONFIG_DVB_##fe) || \
27 (defined(CONFIG_DVB_##fe##_MODULE) && defined(MODULE))) 28 (defined(CONFIG_DVB_##fe##_MODULE) && defined(MODULE)))
28 29
30#if FE_SUPPORTED(BCM3510) || (FE_SUPPORTED(CX24120) && FE_SUPPORTED(ISL6421))
31static int flexcop_fe_request_firmware(struct dvb_frontend *fe,
32 const struct firmware **fw, char *name)
33{
34 struct flexcop_device *fc = fe->dvb->priv;
35
36 return request_firmware(fw, name, fc->dev);
37}
38#endif
39
29/* lnb control */ 40/* lnb control */
30#if FE_SUPPORTED(MT312) || FE_SUPPORTED(STV0299) 41#if FE_SUPPORTED(MT312) || FE_SUPPORTED(STV0299)
31static int flexcop_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 42static int flexcop_set_voltage(struct dvb_frontend *fe,
43 enum fe_sec_voltage voltage)
32{ 44{
33 struct flexcop_device *fc = fe->dvb->priv; 45 struct flexcop_device *fc = fe->dvb->priv;
34 flexcop_ibi_value v; 46 flexcop_ibi_value v;
@@ -67,7 +79,7 @@ static int flexcop_sleep(struct dvb_frontend* fe)
67 79
68/* SkyStar2 DVB-S rev 2.3 */ 80/* SkyStar2 DVB-S rev 2.3 */
69#if FE_SUPPORTED(MT312) && FE_SUPPORTED(PLL) 81#if FE_SUPPORTED(MT312) && FE_SUPPORTED(PLL)
70static int flexcop_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 82static int flexcop_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
71{ 83{
72/* u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc }; */ 84/* u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc }; */
73 struct flexcop_device *fc = fe->dvb->priv; 85 struct flexcop_device *fc = fe->dvb->priv;
@@ -146,7 +158,7 @@ static int flexcop_diseqc_send_master_cmd(struct dvb_frontend *fe,
146} 158}
147 159
148static int flexcop_diseqc_send_burst(struct dvb_frontend *fe, 160static int flexcop_diseqc_send_burst(struct dvb_frontend *fe,
149 fe_sec_mini_cmd_t minicmd) 161 enum fe_sec_mini_cmd minicmd)
150{ 162{
151 return flexcop_send_diseqc_msg(fe, 0, NULL, minicmd); 163 return flexcop_send_diseqc_msg(fe, 0, NULL, minicmd);
152} 164}
@@ -445,13 +457,6 @@ static int airstar_dvbt_attach(struct flexcop_device *fc,
445 457
446/* AirStar ATSC 1st generation */ 458/* AirStar ATSC 1st generation */
447#if FE_SUPPORTED(BCM3510) 459#if FE_SUPPORTED(BCM3510)
448static int flexcop_fe_request_firmware(struct dvb_frontend *fe,
449 const struct firmware **fw, char* name)
450{
451 struct flexcop_device *fc = fe->dvb->priv;
452 return request_firmware(fw, name, fc->dev);
453}
454
455static struct bcm3510_config air2pc_atsc_first_gen_config = { 460static struct bcm3510_config air2pc_atsc_first_gen_config = {
456 .demod_address = 0x0f, 461 .demod_address = 0x0f,
457 .request_firmware = flexcop_fe_request_firmware, 462 .request_firmware = flexcop_fe_request_firmware,
@@ -619,6 +624,43 @@ fail:
619#define cablestar2_attach NULL 624#define cablestar2_attach NULL
620#endif 625#endif
621 626
627/* SkyStar S2 PCI DVB-S/S2 card based on Conexant cx24120/cx24118 */
628#if FE_SUPPORTED(CX24120) && FE_SUPPORTED(ISL6421)
629static const struct cx24120_config skystar2_rev3_3_cx24120_config = {
630 .i2c_addr = 0x55,
631 .xtal_khz = 10111,
632 .initial_mpeg_config = { 0xa1, 0x76, 0x07 },
633 .request_firmware = flexcop_fe_request_firmware,
634 .i2c_wr_max = 4,
635};
636
637static int skystarS2_rev33_attach(struct flexcop_device *fc,
638 struct i2c_adapter *i2c)
639{
640 fc->fe = dvb_attach(cx24120_attach,
641 &skystar2_rev3_3_cx24120_config, i2c);
642 if (!fc->fe)
643 return 0;
644
645 fc->dev_type = FC_SKYS2_REV33;
646 fc->fc_i2c_adap[2].no_base_addr = 1;
647 if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
648 0x08, 0, 0, false)) {
649 err("ISL6421 could NOT be attached!");
650 fc->fc_i2c_adap[2].no_base_addr = 0;
651 return 0;
652 }
653 info("ISL6421 successfully attached.");
654
655 if (fc->has_32_hw_pid_filter)
656 fc->skip_6_hw_pid_filter = 1;
657
658 return 1;
659}
660#else
661#define skystarS2_rev33_attach NULL
662#endif
663
622static struct { 664static struct {
623 flexcop_device_type_t type; 665 flexcop_device_type_t type;
624 int (*attach)(struct flexcop_device *, struct i2c_adapter *); 666 int (*attach)(struct flexcop_device *, struct i2c_adapter *);
@@ -632,6 +674,7 @@ static struct {
632 { FC_AIR_ATSC1, airstar_atsc1_attach }, 674 { FC_AIR_ATSC1, airstar_atsc1_attach },
633 { FC_CABLE, cablestar2_attach }, 675 { FC_CABLE, cablestar2_attach },
634 { FC_SKY_REV23, skystar2_rev23_attach }, 676 { FC_SKY_REV23, skystar2_rev23_attach },
677 { FC_SKYS2_REV33, skystarS2_rev33_attach },
635}; 678};
636 679
637/* try to figure out the frontend */ 680/* try to figure out the frontend */
diff --git a/drivers/media/common/b2c2/flexcop-hw-filter.c b/drivers/media/common/b2c2/flexcop-hw-filter.c
index 77e45475f4c7..8220257903ef 100644
--- a/drivers/media/common/b2c2/flexcop-hw-filter.c
+++ b/drivers/media/common/b2c2/flexcop-hw-filter.c
@@ -117,6 +117,10 @@ static void flexcop_pid_control(struct flexcop_device *fc,
117 deb_ts("setting pid: %5d %04x at index %d '%s'\n", 117 deb_ts("setting pid: %5d %04x at index %d '%s'\n",
118 pid, pid, index, onoff ? "on" : "off"); 118 pid, pid, index, onoff ? "on" : "off");
119 119
120 /* First 6 can be buggy - skip over them if option set */
121 if (fc->skip_6_hw_pid_filter)
122 index += 6;
123
120 /* We could use bit magic here to reduce source code size. 124 /* We could use bit magic here to reduce source code size.
121 * I decided against it, but to use the real register names */ 125 * I decided against it, but to use the real register names */
122 switch (index) { 126 switch (index) {
@@ -170,7 +174,10 @@ static int flexcop_toggle_fullts_streaming(struct flexcop_device *fc, int onoff)
170int flexcop_pid_feed_control(struct flexcop_device *fc, 174int flexcop_pid_feed_control(struct flexcop_device *fc,
171 struct dvb_demux_feed *dvbdmxfeed, int onoff) 175 struct dvb_demux_feed *dvbdmxfeed, int onoff)
172{ 176{
173 int max_pid_filter = 6 + fc->has_32_hw_pid_filter*32; 177 int max_pid_filter = 6;
178
179 max_pid_filter -= 6 * fc->skip_6_hw_pid_filter;
180 max_pid_filter += 32 * fc->has_32_hw_pid_filter;
174 181
175 fc->feedcount += onoff ? 1 : -1; /* the number of PIDs/Feed currently requested */ 182 fc->feedcount += onoff ? 1 : -1; /* the number of PIDs/Feed currently requested */
176 if (dvbdmxfeed->index >= max_pid_filter) 183 if (dvbdmxfeed->index >= max_pid_filter)
@@ -217,7 +224,12 @@ void flexcop_hw_filter_init(struct flexcop_device *fc)
217{ 224{
218 int i; 225 int i;
219 flexcop_ibi_value v; 226 flexcop_ibi_value v;
220 for (i = 0; i < 6 + 32*fc->has_32_hw_pid_filter; i++) 227 int max_pid_filter = 6;
228
229 max_pid_filter -= 6 * fc->skip_6_hw_pid_filter;
230 max_pid_filter += 32 * fc->has_32_hw_pid_filter;
231
232 for (i = 0; i < max_pid_filter; i++)
221 flexcop_pid_control(fc, i, 0x1fff, 0); 233 flexcop_pid_control(fc, i, 0x1fff, 0);
222 234
223 flexcop_pid_group_filter(fc, 0, 0x1fe0); 235 flexcop_pid_group_filter(fc, 0, 0x1fe0);
diff --git a/drivers/media/common/b2c2/flexcop-misc.c b/drivers/media/common/b2c2/flexcop-misc.c
index f06f3a9070f5..b8eff235367d 100644
--- a/drivers/media/common/b2c2/flexcop-misc.c
+++ b/drivers/media/common/b2c2/flexcop-misc.c
@@ -56,6 +56,7 @@ static const char *flexcop_device_names[] = {
56 [FC_SKY_REV26] = "Sky2PC/SkyStar 2 DVB-S rev 2.6", 56 [FC_SKY_REV26] = "Sky2PC/SkyStar 2 DVB-S rev 2.6",
57 [FC_SKY_REV27] = "Sky2PC/SkyStar 2 DVB-S rev 2.7a/u", 57 [FC_SKY_REV27] = "Sky2PC/SkyStar 2 DVB-S rev 2.7a/u",
58 [FC_SKY_REV28] = "Sky2PC/SkyStar 2 DVB-S rev 2.8", 58 [FC_SKY_REV28] = "Sky2PC/SkyStar 2 DVB-S rev 2.8",
59 [FC_SKYS2_REV33] = "Sky2PC/SkyStar S2 DVB-S/S2 rev 3.3",
59}; 60};
60 61
61static const char *flexcop_bus_names[] = { 62static const char *flexcop_bus_names[] = {
diff --git a/drivers/media/common/b2c2/flexcop-reg.h b/drivers/media/common/b2c2/flexcop-reg.h
index dc4528dcbb98..835c54d60e74 100644
--- a/drivers/media/common/b2c2/flexcop-reg.h
+++ b/drivers/media/common/b2c2/flexcop-reg.h
@@ -24,6 +24,7 @@ typedef enum {
24 FC_SKY_REV26, 24 FC_SKY_REV26,
25 FC_SKY_REV27, 25 FC_SKY_REV27,
26 FC_SKY_REV28, 26 FC_SKY_REV28,
27 FC_SKYS2_REV33,
27} flexcop_device_type_t; 28} flexcop_device_type_t;
28 29
29typedef enum { 30typedef enum {
diff --git a/drivers/media/common/siano/smscoreapi.h b/drivers/media/common/siano/smscoreapi.h
index eb8bd689b936..4cc39e4a8318 100644
--- a/drivers/media/common/siano/smscoreapi.h
+++ b/drivers/media/common/siano/smscoreapi.h
@@ -1010,6 +1010,7 @@ struct sms_rx_stats_ex {
1010 s32 mrc_in_band_pwr; /* In band power in dBM */ 1010 s32 mrc_in_band_pwr; /* In band power in dBM */
1011}; 1011};
1012 1012
1013#define SRVM_MAX_PID_FILTERS 8
1013 1014
1014/* statistics information returned as response for 1015/* statistics information returned as response for
1015 * SmsHostApiGetstatisticsEx_Req for DVB applications, SMS1100 and up */ 1016 * SmsHostApiGetstatisticsEx_Req for DVB applications, SMS1100 and up */
@@ -1021,7 +1022,6 @@ struct sms_stats_dvb {
1021 struct sms_tx_stats transmission_data; 1022 struct sms_tx_stats transmission_data;
1022 1023
1023 /* Burst parameters, valid only for DVB-H */ 1024 /* Burst parameters, valid only for DVB-H */
1024#define SRVM_MAX_PID_FILTERS 8
1025 struct sms_pid_data pid_data[SRVM_MAX_PID_FILTERS]; 1025 struct sms_pid_data pid_data[SRVM_MAX_PID_FILTERS];
1026}; 1026};
1027 1027
@@ -1035,7 +1035,6 @@ struct sms_stats_dvb_ex {
1035 struct sms_tx_stats transmission_data; 1035 struct sms_tx_stats transmission_data;
1036 1036
1037 /* Burst parameters, valid only for DVB-H */ 1037 /* Burst parameters, valid only for DVB-H */
1038#define SRVM_MAX_PID_FILTERS 8
1039 struct sms_pid_data pid_data[SRVM_MAX_PID_FILTERS]; 1038 struct sms_pid_data pid_data[SRVM_MAX_PID_FILTERS];
1040}; 1039};
1041 1040
diff --git a/drivers/media/common/siano/smsdvb-main.c b/drivers/media/common/siano/smsdvb-main.c
index 367b8e77feb8..f4305ae800f4 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -753,7 +753,7 @@ static inline int led_feedback(struct smsdvb_client_t *client)
753 SMS_LED_HI : SMS_LED_LO); 753 SMS_LED_HI : SMS_LED_LO);
754} 754}
755 755
756static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat) 756static int smsdvb_read_status(struct dvb_frontend *fe, enum fe_status *stat)
757{ 757{
758 int rc; 758 int rc;
759 struct smsdvb_client_t *client; 759 struct smsdvb_client_t *client;
@@ -900,7 +900,7 @@ static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
900 /* Disable LNA, if any. An error is returned if no LNA is present */ 900 /* Disable LNA, if any. An error is returned if no LNA is present */
901 ret = sms_board_lna_control(client->coredev, 0); 901 ret = sms_board_lna_control(client->coredev, 0);
902 if (ret == 0) { 902 if (ret == 0) {
903 fe_status_t status; 903 enum fe_status status;
904 904
905 /* tune with LNA off at first */ 905 /* tune with LNA off at first */
906 ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), 906 ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
@@ -971,7 +971,7 @@ static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
971 /* Disable LNA, if any. An error is returned if no LNA is present */ 971 /* Disable LNA, if any. An error is returned if no LNA is present */
972 ret = sms_board_lna_control(client->coredev, 0); 972 ret = sms_board_lna_control(client->coredev, 0);
973 if (ret == 0) { 973 if (ret == 0) {
974 fe_status_t status; 974 enum fe_status status;
975 975
976 /* tune with LNA off at first */ 976 /* tune with LNA off at first */
977 ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), 977 ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
diff --git a/drivers/media/common/siano/smsdvb.h b/drivers/media/common/siano/smsdvb.h
index ae36d0ae0fb1..b15754d95ec0 100644
--- a/drivers/media/common/siano/smsdvb.h
+++ b/drivers/media/common/siano/smsdvb.h
@@ -40,7 +40,7 @@ struct smsdvb_client_t {
40 struct dmxdev dmxdev; 40 struct dmxdev dmxdev;
41 struct dvb_frontend frontend; 41 struct dvb_frontend frontend;
42 42
43 fe_status_t fe_status; 43 enum fe_status fe_status;
44 44
45 struct completion tune_done; 45 struct completion tune_done;
46 struct completion stats_done; 46 struct completion stats_done;
diff --git a/drivers/media/common/siano/smsir.c b/drivers/media/common/siano/smsir.c
index 1d60d200d9ab..41f2a3939979 100644
--- a/drivers/media/common/siano/smsir.c
+++ b/drivers/media/common/siano/smsir.c
@@ -78,7 +78,7 @@ int sms_ir_init(struct smscore_device_t *coredev)
78 dev->dev.parent = coredev->device; 78 dev->dev.parent = coredev->device;
79 79
80#if 0 80#if 0
81 /* TODO: properly initialize the parameters bellow */ 81 /* TODO: properly initialize the parameters below */
82 dev->input_id.bustype = BUS_USB; 82 dev->input_id.bustype = BUS_USB;
83 dev->input_id.version = 1; 83 dev->input_id.version = 1;
84 dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 84 dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 882ca417f328..842b9c8f80c6 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -40,6 +40,7 @@
40#include <linux/freezer.h> 40#include <linux/freezer.h>
41#include <linux/jiffies.h> 41#include <linux/jiffies.h>
42#include <linux/kthread.h> 42#include <linux/kthread.h>
43#include <linux/ktime.h>
43#include <asm/processor.h> 44#include <asm/processor.h>
44 45
45#include "dvb_frontend.h" 46#include "dvb_frontend.h"
@@ -110,7 +111,7 @@ struct dvb_frontend_private {
110 struct task_struct *thread; 111 struct task_struct *thread;
111 unsigned long release_jiffies; 112 unsigned long release_jiffies;
112 unsigned int wakeup; 113 unsigned int wakeup;
113 fe_status_t status; 114 enum fe_status status;
114 unsigned long tune_mode_flags; 115 unsigned long tune_mode_flags;
115 unsigned int delay; 116 unsigned int delay;
116 unsigned int reinitialise; 117 unsigned int reinitialise;
@@ -198,7 +199,8 @@ static enum dvbv3_emulation_type dvbv3_type(u32 delivery_system)
198 } 199 }
199} 200}
200 201
201static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status) 202static void dvb_frontend_add_event(struct dvb_frontend *fe,
203 enum fe_status status)
202{ 204{
203 struct dvb_frontend_private *fepriv = fe->frontend_priv; 205 struct dvb_frontend_private *fepriv = fe->frontend_priv;
204 struct dvb_fe_events *events = &fepriv->events; 206 struct dvb_fe_events *events = &fepriv->events;
@@ -429,7 +431,7 @@ static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wra
429 431
430static void dvb_frontend_swzigzag(struct dvb_frontend *fe) 432static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
431{ 433{
432 fe_status_t s = 0; 434 enum fe_status s = 0;
433 int retval = 0; 435 int retval = 0;
434 struct dvb_frontend_private *fepriv = fe->frontend_priv; 436 struct dvb_frontend_private *fepriv = fe->frontend_priv;
435 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp; 437 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
@@ -690,7 +692,7 @@ static int dvb_frontend_thread(void *data)
690{ 692{
691 struct dvb_frontend *fe = data; 693 struct dvb_frontend *fe = data;
692 struct dvb_frontend_private *fepriv = fe->frontend_priv; 694 struct dvb_frontend_private *fepriv = fe->frontend_priv;
693 fe_status_t s; 695 enum fe_status s;
694 enum dvbfe_algo algo; 696 enum dvbfe_algo algo;
695#ifdef CONFIG_MEDIA_CONTROLLER_DVB 697#ifdef CONFIG_MEDIA_CONTROLLER_DVB
696 int ret; 698 int ret;
@@ -889,42 +891,21 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
889 fepriv->thread); 891 fepriv->thread);
890} 892}
891 893
892s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
893{
894 return ((curtime.tv_usec < lasttime.tv_usec) ?
895 1000000 - lasttime.tv_usec + curtime.tv_usec :
896 curtime.tv_usec - lasttime.tv_usec);
897}
898EXPORT_SYMBOL(timeval_usec_diff);
899
900static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
901{
902 curtime->tv_usec += add_usec;
903 if (curtime->tv_usec >= 1000000) {
904 curtime->tv_usec -= 1000000;
905 curtime->tv_sec++;
906 }
907}
908
909/* 894/*
910 * Sleep until gettimeofday() > waketime + add_usec 895 * Sleep until gettimeofday() > waketime + add_usec
911 * This needs to be as precise as possible, but as the delay is 896 * This needs to be as precise as possible, but as the delay is
912 * usually between 2ms and 32ms, it is done using a scheduled msleep 897 * usually between 2ms and 32ms, it is done using a scheduled msleep
913 * followed by usleep (normally a busy-wait loop) for the remainder 898 * followed by usleep (normally a busy-wait loop) for the remainder
914 */ 899 */
915void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec) 900void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
916{ 901{
917 struct timeval lasttime;
918 s32 delta, newdelta; 902 s32 delta, newdelta;
919 903
920 timeval_usec_add(waketime, add_usec); 904 ktime_add_us(*waketime, add_usec);
921 905 delta = ktime_us_delta(ktime_get_real(), *waketime);
922 do_gettimeofday(&lasttime);
923 delta = timeval_usec_diff(lasttime, *waketime);
924 if (delta > 2500) { 906 if (delta > 2500) {
925 msleep((delta - 1500) / 1000); 907 msleep((delta - 1500) / 1000);
926 do_gettimeofday(&lasttime); 908 newdelta = ktime_us_delta(ktime_get_real(), *waketime);
927 newdelta = timeval_usec_diff(lasttime, *waketime);
928 delta = (newdelta > delta) ? 0 : newdelta; 909 delta = (newdelta > delta) ? 0 : newdelta;
929 } 910 }
930 if (delta > 0) 911 if (delta > 0)
@@ -2216,7 +2197,7 @@ static int dtv_set_frontend(struct dvb_frontend *fe)
2216 break; 2197 break;
2217 } 2198 }
2218 if (rolloff) 2199 if (rolloff)
2219 c->bandwidth_hz = (c->symbol_rate * rolloff) / 100; 2200 c->bandwidth_hz = mult_frac(c->symbol_rate, rolloff, 100);
2220 2201
2221 /* force auto frequency inversion if requested */ 2202 /* force auto frequency inversion if requested */
2222 if (dvb_force_auto_inversion) 2203 if (dvb_force_auto_inversion)
@@ -2341,7 +2322,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2341 } 2322 }
2342 2323
2343 case FE_READ_STATUS: { 2324 case FE_READ_STATUS: {
2344 fe_status_t* status = parg; 2325 enum fe_status *status = parg;
2345 2326
2346 /* if retune was requested but hasn't occurred yet, prevent 2327 /* if retune was requested but hasn't occurred yet, prevent
2347 * that user get signal state from previous tuning */ 2328 * that user get signal state from previous tuning */
@@ -2403,7 +2384,13 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2403 2384
2404 case FE_DISEQC_SEND_MASTER_CMD: 2385 case FE_DISEQC_SEND_MASTER_CMD:
2405 if (fe->ops.diseqc_send_master_cmd) { 2386 if (fe->ops.diseqc_send_master_cmd) {
2406 err = fe->ops.diseqc_send_master_cmd(fe, (struct dvb_diseqc_master_cmd*) parg); 2387 struct dvb_diseqc_master_cmd *cmd = parg;
2388
2389 if (cmd->msg_len > sizeof(cmd->msg)) {
2390 err = -EINVAL;
2391 break;
2392 }
2393 err = fe->ops.diseqc_send_master_cmd(fe, cmd);
2407 fepriv->state = FESTATE_DISEQC; 2394 fepriv->state = FESTATE_DISEQC;
2408 fepriv->status = 0; 2395 fepriv->status = 0;
2409 } 2396 }
@@ -2411,7 +2398,8 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2411 2398
2412 case FE_DISEQC_SEND_BURST: 2399 case FE_DISEQC_SEND_BURST:
2413 if (fe->ops.diseqc_send_burst) { 2400 if (fe->ops.diseqc_send_burst) {
2414 err = fe->ops.diseqc_send_burst(fe, (fe_sec_mini_cmd_t) parg); 2401 err = fe->ops.diseqc_send_burst(fe,
2402 (enum fe_sec_mini_cmd)parg);
2415 fepriv->state = FESTATE_DISEQC; 2403 fepriv->state = FESTATE_DISEQC;
2416 fepriv->status = 0; 2404 fepriv->status = 0;
2417 } 2405 }
@@ -2419,8 +2407,9 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2419 2407
2420 case FE_SET_TONE: 2408 case FE_SET_TONE:
2421 if (fe->ops.set_tone) { 2409 if (fe->ops.set_tone) {
2422 err = fe->ops.set_tone(fe, (fe_sec_tone_mode_t) parg); 2410 err = fe->ops.set_tone(fe,
2423 fepriv->tone = (fe_sec_tone_mode_t) parg; 2411 (enum fe_sec_tone_mode)parg);
2412 fepriv->tone = (enum fe_sec_tone_mode)parg;
2424 fepriv->state = FESTATE_DISEQC; 2413 fepriv->state = FESTATE_DISEQC;
2425 fepriv->status = 0; 2414 fepriv->status = 0;
2426 } 2415 }
@@ -2428,8 +2417,9 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2428 2417
2429 case FE_SET_VOLTAGE: 2418 case FE_SET_VOLTAGE:
2430 if (fe->ops.set_voltage) { 2419 if (fe->ops.set_voltage) {
2431 err = fe->ops.set_voltage(fe, (fe_sec_voltage_t) parg); 2420 err = fe->ops.set_voltage(fe,
2432 fepriv->voltage = (fe_sec_voltage_t) parg; 2421 (enum fe_sec_voltage)parg);
2422 fepriv->voltage = (enum fe_sec_voltage)parg;
2433 fepriv->state = FESTATE_DISEQC; 2423 fepriv->state = FESTATE_DISEQC;
2434 fepriv->status = 0; 2424 fepriv->status = 0;
2435 } 2425 }
@@ -2437,7 +2427,8 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2437 2427
2438 case FE_DISHNETWORK_SEND_LEGACY_CMD: 2428 case FE_DISHNETWORK_SEND_LEGACY_CMD:
2439 if (fe->ops.dishnetwork_send_legacy_command) { 2429 if (fe->ops.dishnetwork_send_legacy_command) {
2440 err = fe->ops.dishnetwork_send_legacy_command(fe, (unsigned long) parg); 2430 err = fe->ops.dishnetwork_send_legacy_command(fe,
2431 (unsigned long)parg);
2441 fepriv->state = FESTATE_DISEQC; 2432 fepriv->state = FESTATE_DISEQC;
2442 fepriv->status = 0; 2433 fepriv->status = 0;
2443 } else if (fe->ops.set_voltage) { 2434 } else if (fe->ops.set_voltage) {
@@ -2458,13 +2449,13 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2458 * include the initialization or start bit 2449 * include the initialization or start bit
2459 */ 2450 */
2460 unsigned long swcmd = ((unsigned long) parg) << 1; 2451 unsigned long swcmd = ((unsigned long) parg) << 1;
2461 struct timeval nexttime; 2452 ktime_t nexttime;
2462 struct timeval tv[10]; 2453 ktime_t tv[10];
2463 int i; 2454 int i;
2464 u8 last = 1; 2455 u8 last = 1;
2465 if (dvb_frontend_debug) 2456 if (dvb_frontend_debug)
2466 printk("%s switch command: 0x%04lx\n", __func__, swcmd); 2457 printk("%s switch command: 0x%04lx\n", __func__, swcmd);
2467 do_gettimeofday(&nexttime); 2458 nexttime = ktime_get_real();
2468 if (dvb_frontend_debug) 2459 if (dvb_frontend_debug)
2469 tv[0] = nexttime; 2460 tv[0] = nexttime;
2470 /* before sending a command, initialize by sending 2461 /* before sending a command, initialize by sending
@@ -2475,7 +2466,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2475 2466
2476 for (i = 0; i < 9; i++) { 2467 for (i = 0; i < 9; i++) {
2477 if (dvb_frontend_debug) 2468 if (dvb_frontend_debug)
2478 do_gettimeofday(&tv[i + 1]); 2469 tv[i+1] = ktime_get_real();
2479 if ((swcmd & 0x01) != last) { 2470 if ((swcmd & 0x01) != last) {
2480 /* set voltage to (last ? 13V : 18V) */ 2471 /* set voltage to (last ? 13V : 18V) */
2481 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18); 2472 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
@@ -2489,7 +2480,8 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2489 printk("%s(%d): switch delay (should be 32k followed by all 8k\n", 2480 printk("%s(%d): switch delay (should be 32k followed by all 8k\n",
2490 __func__, fe->dvb->num); 2481 __func__, fe->dvb->num);
2491 for (i = 1; i < 10; i++) 2482 for (i = 1; i < 10; i++)
2492 printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); 2483 printk("%d: %d\n", i,
2484 (int) ktime_us_delta(tv[i], tv[i-1]));
2493 } 2485 }
2494 err = 0; 2486 err = 0;
2495 fepriv->state = FESTATE_DISEQC; 2487 fepriv->state = FESTATE_DISEQC;
diff --git a/drivers/media/dvb-core/dvb_frontend.h b/drivers/media/dvb-core/dvb_frontend.h
index 816269e5f706..4816947294fe 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -279,7 +279,7 @@ struct dvb_frontend_ops {
279 bool re_tune, 279 bool re_tune,
280 unsigned int mode_flags, 280 unsigned int mode_flags,
281 unsigned int *delay, 281 unsigned int *delay,
282 fe_status_t *status); 282 enum fe_status *status);
283 /* get frontend tuning algorithm from the module */ 283 /* get frontend tuning algorithm from the module */
284 enum dvbfe_algo (*get_frontend_algo)(struct dvb_frontend *fe); 284 enum dvbfe_algo (*get_frontend_algo)(struct dvb_frontend *fe);
285 285
@@ -289,7 +289,7 @@ struct dvb_frontend_ops {
289 289
290 int (*get_frontend)(struct dvb_frontend *fe); 290 int (*get_frontend)(struct dvb_frontend *fe);
291 291
292 int (*read_status)(struct dvb_frontend* fe, fe_status_t* status); 292 int (*read_status)(struct dvb_frontend *fe, enum fe_status *status);
293 int (*read_ber)(struct dvb_frontend* fe, u32* ber); 293 int (*read_ber)(struct dvb_frontend* fe, u32* ber);
294 int (*read_signal_strength)(struct dvb_frontend* fe, u16* strength); 294 int (*read_signal_strength)(struct dvb_frontend* fe, u16* strength);
295 int (*read_snr)(struct dvb_frontend* fe, u16* snr); 295 int (*read_snr)(struct dvb_frontend* fe, u16* snr);
@@ -298,9 +298,11 @@ struct dvb_frontend_ops {
298 int (*diseqc_reset_overload)(struct dvb_frontend* fe); 298 int (*diseqc_reset_overload)(struct dvb_frontend* fe);
299 int (*diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd); 299 int (*diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd);
300 int (*diseqc_recv_slave_reply)(struct dvb_frontend* fe, struct dvb_diseqc_slave_reply* reply); 300 int (*diseqc_recv_slave_reply)(struct dvb_frontend* fe, struct dvb_diseqc_slave_reply* reply);
301 int (*diseqc_send_burst)(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd); 301 int (*diseqc_send_burst)(struct dvb_frontend *fe,
302 int (*set_tone)(struct dvb_frontend* fe, fe_sec_tone_mode_t tone); 302 enum fe_sec_mini_cmd minicmd);
303 int (*set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage); 303 int (*set_tone)(struct dvb_frontend *fe, enum fe_sec_tone_mode tone);
304 int (*set_voltage)(struct dvb_frontend *fe,
305 enum fe_sec_voltage voltage);
304 int (*enable_high_lnb_voltage)(struct dvb_frontend* fe, long arg); 306 int (*enable_high_lnb_voltage)(struct dvb_frontend* fe, long arg);
305 int (*dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd); 307 int (*dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd);
306 int (*i2c_gate_ctrl)(struct dvb_frontend* fe, int enable); 308 int (*i2c_gate_ctrl)(struct dvb_frontend* fe, int enable);
@@ -338,24 +340,24 @@ struct dtv_frontend_properties {
338 u32 state; 340 u32 state;
339 341
340 u32 frequency; 342 u32 frequency;
341 fe_modulation_t modulation; 343 enum fe_modulation modulation;
342 344
343 fe_sec_voltage_t voltage; 345 enum fe_sec_voltage voltage;
344 fe_sec_tone_mode_t sectone; 346 enum fe_sec_tone_mode sectone;
345 fe_spectral_inversion_t inversion; 347 enum fe_spectral_inversion inversion;
346 fe_code_rate_t fec_inner; 348 enum fe_code_rate fec_inner;
347 fe_transmit_mode_t transmission_mode; 349 enum fe_transmit_mode transmission_mode;
348 u32 bandwidth_hz; /* 0 = AUTO */ 350 u32 bandwidth_hz; /* 0 = AUTO */
349 fe_guard_interval_t guard_interval; 351 enum fe_guard_interval guard_interval;
350 fe_hierarchy_t hierarchy; 352 enum fe_hierarchy hierarchy;
351 u32 symbol_rate; 353 u32 symbol_rate;
352 fe_code_rate_t code_rate_HP; 354 enum fe_code_rate code_rate_HP;
353 fe_code_rate_t code_rate_LP; 355 enum fe_code_rate code_rate_LP;
354 356
355 fe_pilot_t pilot; 357 enum fe_pilot pilot;
356 fe_rolloff_t rolloff; 358 enum fe_rolloff rolloff;
357 359
358 fe_delivery_system_t delivery_system; 360 enum fe_delivery_system delivery_system;
359 361
360 enum fe_interleaving interleaving; 362 enum fe_interleaving interleaving;
361 363
@@ -368,8 +370,8 @@ struct dtv_frontend_properties {
368 u8 isdbt_layer_enabled; 370 u8 isdbt_layer_enabled;
369 struct { 371 struct {
370 u8 segment_count; 372 u8 segment_count;
371 fe_code_rate_t fec; 373 enum fe_code_rate fec;
372 fe_modulation_t modulation; 374 enum fe_modulation modulation;
373 u8 interleaving; 375 u8 interleaving;
374 } layer[3]; 376 } layer[3];
375 377
@@ -439,7 +441,6 @@ extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
439extern int dvb_frontend_suspend(struct dvb_frontend *fe); 441extern int dvb_frontend_suspend(struct dvb_frontend *fe);
440extern int dvb_frontend_resume(struct dvb_frontend *fe); 442extern int dvb_frontend_resume(struct dvb_frontend *fe);
441 443
442extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec); 444extern void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec);
443extern s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime);
444 445
445#endif 446#endif
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 97c151d5b2e1..0d35f5850ff1 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -36,8 +36,9 @@ config DVB_STV6110x
36 A Silicon tuner that supports DVB-S and DVB-S2 modes 36 A Silicon tuner that supports DVB-S and DVB-S2 modes
37 37
38config DVB_M88DS3103 38config DVB_M88DS3103
39 tristate "Montage M88DS3103" 39 tristate "Montage Technology M88DS3103"
40 depends on DVB_CORE && I2C && I2C_MUX 40 depends on DVB_CORE && I2C && I2C_MUX
41 select REGMAP_I2C
41 default m if !MEDIA_SUBDRV_AUTOSELECT 42 default m if !MEDIA_SUBDRV_AUTOSELECT
42 help 43 help
43 Say Y when you want to support this frontend. 44 Say Y when you want to support this frontend.
@@ -223,6 +224,13 @@ config DVB_CX24117
223 help 224 help
224 A Dual DVB-S/S2 tuner module. Say Y when you want to support this frontend. 225 A Dual DVB-S/S2 tuner module. Say Y when you want to support this frontend.
225 226
227config DVB_CX24120
228 tristate "Conexant CX24120 based"
229 depends on DVB_CORE && I2C
230 default m if !MEDIA_SUBDRV_AUTOSELECT
231 help
232 A DVB-S/S2 tuner module. Say Y when you want to support this frontend.
233
226config DVB_SI21XX 234config DVB_SI21XX
227 tristate "Silicon Labs SI21XX based" 235 tristate "Silicon Labs SI21XX based"
228 depends on DVB_CORE && I2C 236 depends on DVB_CORE && I2C
@@ -232,7 +240,8 @@ config DVB_SI21XX
232 240
233config DVB_TS2020 241config DVB_TS2020
234 tristate "Montage Tehnology TS2020 based tuners" 242 tristate "Montage Tehnology TS2020 based tuners"
235 depends on DVB_CORE && I2C 243 depends on DVB_CORE
244 select REGMAP_I2C
236 default m if !MEDIA_SUBDRV_AUTOSELECT 245 default m if !MEDIA_SUBDRV_AUTOSELECT
237 help 246 help
238 A DVB-S/S2 silicon tuner. Say Y when you want to support this tuner. 247 A DVB-S/S2 silicon tuner. Say Y when you want to support this tuner.
diff --git a/drivers/media/dvb-frontends/Makefile b/drivers/media/dvb-frontends/Makefile
index 23d399bec804..ebab1b83e1fc 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -83,6 +83,7 @@ obj-$(CONFIG_DVB_DUMMY_FE) += dvb_dummy_fe.o
83obj-$(CONFIG_DVB_AF9013) += af9013.o 83obj-$(CONFIG_DVB_AF9013) += af9013.o
84obj-$(CONFIG_DVB_CX24116) += cx24116.o 84obj-$(CONFIG_DVB_CX24116) += cx24116.o
85obj-$(CONFIG_DVB_CX24117) += cx24117.o 85obj-$(CONFIG_DVB_CX24117) += cx24117.o
86obj-$(CONFIG_DVB_CX24120) += cx24120.o
86obj-$(CONFIG_DVB_SI21XX) += si21xx.o 87obj-$(CONFIG_DVB_SI21XX) += si21xx.o
87obj-$(CONFIG_DVB_SI2168) += si2168.o 88obj-$(CONFIG_DVB_SI2168) += si2168.o
88obj-$(CONFIG_DVB_STV0288) += stv0288.o 89obj-$(CONFIG_DVB_STV0288) += stv0288.o
diff --git a/drivers/media/dvb-frontends/a8293.c b/drivers/media/dvb-frontends/a8293.c
index 780da58132f1..97ecbe01034c 100644
--- a/drivers/media/dvb-frontends/a8293.c
+++ b/drivers/media/dvb-frontends/a8293.c
@@ -22,8 +22,9 @@
22#include "a8293.h" 22#include "a8293.h"
23 23
24struct a8293_priv { 24struct a8293_priv {
25 u8 i2c_addr;
25 struct i2c_adapter *i2c; 26 struct i2c_adapter *i2c;
26 const struct a8293_config *cfg; 27 struct i2c_client *client;
27 u8 reg[2]; 28 u8 reg[2];
28}; 29};
29 30
@@ -32,7 +33,7 @@ static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd)
32 int ret; 33 int ret;
33 struct i2c_msg msg[1] = { 34 struct i2c_msg msg[1] = {
34 { 35 {
35 .addr = priv->cfg->i2c_addr, 36 .addr = priv->i2c_addr,
36 .len = len, 37 .len = len,
37 .buf = val, 38 .buf = val,
38 } 39 }
@@ -66,7 +67,7 @@ static int a8293_rd(struct a8293_priv *priv, u8 *val, int len)
66} 67}
67 68
68static int a8293_set_voltage(struct dvb_frontend *fe, 69static int a8293_set_voltage(struct dvb_frontend *fe,
69 fe_sec_voltage_t fe_sec_voltage) 70 enum fe_sec_voltage fe_sec_voltage)
70{ 71{
71 struct a8293_priv *priv = fe->sec_priv; 72 struct a8293_priv *priv = fe->sec_priv;
72 int ret; 73 int ret;
@@ -128,7 +129,7 @@ struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
128 129
129 /* setup the priv */ 130 /* setup the priv */
130 priv->i2c = i2c; 131 priv->i2c = i2c;
131 priv->cfg = cfg; 132 priv->i2c_addr = cfg->i2c_addr;
132 fe->sec_priv = priv; 133 fe->sec_priv = priv;
133 134
134 /* check if the SEC is there */ 135 /* check if the SEC is there */
@@ -164,6 +165,86 @@ err:
164} 165}
165EXPORT_SYMBOL(a8293_attach); 166EXPORT_SYMBOL(a8293_attach);
166 167
168static int a8293_probe(struct i2c_client *client,
169 const struct i2c_device_id *id)
170{
171 struct a8293_priv *dev;
172 struct a8293_platform_data *pdata = client->dev.platform_data;
173 struct dvb_frontend *fe = pdata->dvb_frontend;
174 int ret;
175 u8 buf[2];
176
177 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
178 if (!dev) {
179 ret = -ENOMEM;
180 goto err;
181 }
182
183 dev->client = client;
184 dev->i2c = client->adapter;
185 dev->i2c_addr = client->addr;
186
187 /* check if the SEC is there */
188 ret = a8293_rd(dev, buf, 2);
189 if (ret)
190 goto err_kfree;
191
192 /* ENB=0 */
193 dev->reg[0] = 0x10;
194 ret = a8293_wr(dev, &dev->reg[0], 1);
195 if (ret)
196 goto err_kfree;
197
198 /* TMODE=0, TGATE=1 */
199 dev->reg[1] = 0x82;
200 ret = a8293_wr(dev, &dev->reg[1], 1);
201 if (ret)
202 goto err_kfree;
203
204 /* override frontend ops */
205 fe->ops.set_voltage = a8293_set_voltage;
206
207 fe->sec_priv = dev;
208 i2c_set_clientdata(client, dev);
209
210 dev_info(&client->dev, "Allegro A8293 SEC successfully attached\n");
211 return 0;
212err_kfree:
213 kfree(dev);
214err:
215 dev_dbg(&client->dev, "failed=%d\n", ret);
216 return ret;
217}
218
219static int a8293_remove(struct i2c_client *client)
220{
221 struct a8293_dev *dev = i2c_get_clientdata(client);
222
223 dev_dbg(&client->dev, "\n");
224
225 kfree(dev);
226 return 0;
227}
228
229static const struct i2c_device_id a8293_id_table[] = {
230 {"a8293", 0},
231 {}
232};
233MODULE_DEVICE_TABLE(i2c, a8293_id_table);
234
235static struct i2c_driver a8293_driver = {
236 .driver = {
237 .owner = THIS_MODULE,
238 .name = "a8293",
239 .suppress_bind_attrs = true,
240 },
241 .probe = a8293_probe,
242 .remove = a8293_remove,
243 .id_table = a8293_id_table,
244};
245
246module_i2c_driver(a8293_driver);
247
167MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 248MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
168MODULE_DESCRIPTION("Allegro A8293 SEC driver"); 249MODULE_DESCRIPTION("Allegro A8293 SEC driver");
169MODULE_LICENSE("GPL"); 250MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/a8293.h b/drivers/media/dvb-frontends/a8293.h
index 5f0411939ffc..aff36538f582 100644
--- a/drivers/media/dvb-frontends/a8293.h
+++ b/drivers/media/dvb-frontends/a8293.h
@@ -21,8 +21,23 @@
21#ifndef A8293_H 21#ifndef A8293_H
22#define A8293_H 22#define A8293_H
23 23
24#include "dvb_frontend.h"
24#include <linux/kconfig.h> 25#include <linux/kconfig.h>
25 26
27/*
28 * I2C address
29 * 0x08, 0x09, 0x0a, 0x0b
30 */
31
32/**
33 * struct a8293_platform_data - Platform data for the a8293 driver
34 * @dvb_frontend: DVB frontend.
35 */
36struct a8293_platform_data {
37 struct dvb_frontend *dvb_frontend;
38};
39
40
26struct a8293_config { 41struct a8293_config {
27 u8 i2c_addr; 42 u8 i2c_addr;
28}; 43};
diff --git a/drivers/media/dvb-frontends/af9013.c b/drivers/media/dvb-frontends/af9013.c
index 8001690d7576..e23197da84af 100644
--- a/drivers/media/dvb-frontends/af9013.c
+++ b/drivers/media/dvb-frontends/af9013.c
@@ -39,7 +39,7 @@ struct af9013_state {
39 u32 ucblocks; 39 u32 ucblocks;
40 u16 snr; 40 u16 snr;
41 u32 bandwidth_hz; 41 u32 bandwidth_hz;
42 fe_status_t fe_status; 42 enum fe_status fe_status;
43 unsigned long set_frontend_jiffies; 43 unsigned long set_frontend_jiffies;
44 unsigned long read_status_jiffies; 44 unsigned long read_status_jiffies;
45 bool first_tune; 45 bool first_tune;
@@ -605,6 +605,10 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
605 } 605 }
606 } 606 }
607 607
608 /* Return an error if can't find bandwidth or the right clock */
609 if (i == ARRAY_SIZE(coeff_lut))
610 return -EINVAL;
611
608 ret = af9013_wr_regs(state, 0xae00, coeff_lut[i].val, 612 ret = af9013_wr_regs(state, 0xae00, coeff_lut[i].val,
609 sizeof(coeff_lut[i].val)); 613 sizeof(coeff_lut[i].val));
610 } 614 }
@@ -979,7 +983,7 @@ err:
979 return ret; 983 return ret;
980} 984}
981 985
982static int af9013_read_status(struct dvb_frontend *fe, fe_status_t *status) 986static int af9013_read_status(struct dvb_frontend *fe, enum fe_status *status)
983{ 987{
984 struct af9013_state *state = fe->demodulator_priv; 988 struct af9013_state *state = fe->demodulator_priv;
985 int ret; 989 int ret;
diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
index 82ce47bdf5dc..59018afaa95f 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -35,7 +35,7 @@ struct af9033_dev {
35 bool ts_mode_parallel; 35 bool ts_mode_parallel;
36 bool ts_mode_serial; 36 bool ts_mode_serial;
37 37
38 fe_status_t fe_status; 38 enum fe_status fe_status;
39 u64 post_bit_error_prev; /* for old read_ber we return (curr - prev) */ 39 u64 post_bit_error_prev; /* for old read_ber we return (curr - prev) */
40 u64 post_bit_error; 40 u64 post_bit_error;
41 u64 post_bit_count; 41 u64 post_bit_count;
@@ -818,7 +818,7 @@ err:
818 return ret; 818 return ret;
819} 819}
820 820
821static int af9033_read_status(struct dvb_frontend *fe, fe_status_t *status) 821static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status)
822{ 822{
823 struct af9033_dev *dev = fe->demodulator_priv; 823 struct af9033_dev *dev = fe->demodulator_priv;
824 int ret; 824 int ret;
diff --git a/drivers/media/dvb-frontends/as102_fe.c b/drivers/media/dvb-frontends/as102_fe.c
index 493665899565..544c5f65d19a 100644
--- a/drivers/media/dvb-frontends/as102_fe.c
+++ b/drivers/media/dvb-frontends/as102_fe.c
@@ -32,7 +32,7 @@ struct as102_state {
32 uint32_t ber; 32 uint32_t ber;
33}; 33};
34 34
35static uint8_t as102_fe_get_code_rate(fe_code_rate_t arg) 35static uint8_t as102_fe_get_code_rate(enum fe_code_rate arg)
36{ 36{
37 uint8_t c; 37 uint8_t c;
38 38
@@ -306,7 +306,7 @@ static int as102_fe_get_tune_settings(struct dvb_frontend *fe,
306 return 0; 306 return 0;
307} 307}
308 308
309static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status) 309static int as102_fe_read_status(struct dvb_frontend *fe, enum fe_status *status)
310{ 310{
311 int ret = 0; 311 int ret = 0;
312 struct as102_state *state = fe->demodulator_priv; 312 struct as102_state *state = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/atbm8830.c b/drivers/media/dvb-frontends/atbm8830.c
index 4e11dc4b1335..8fe552e293ed 100644
--- a/drivers/media/dvb-frontends/atbm8830.c
+++ b/drivers/media/dvb-frontends/atbm8830.c
@@ -335,7 +335,8 @@ static int atbm8830_get_tune_settings(struct dvb_frontend *fe,
335 return 0; 335 return 0;
336} 336}
337 337
338static int atbm8830_read_status(struct dvb_frontend *fe, fe_status_t *fe_status) 338static int atbm8830_read_status(struct dvb_frontend *fe,
339 enum fe_status *fe_status)
339{ 340{
340 struct atbm_state *priv = fe->demodulator_priv; 341 struct atbm_state *priv = fe->demodulator_priv;
341 u8 locked = 0; 342 u8 locked = 0;
diff --git a/drivers/media/dvb-frontends/au8522_dig.c b/drivers/media/dvb-frontends/au8522_dig.c
index 5d06c99b0e97..b744a3f8d467 100644
--- a/drivers/media/dvb-frontends/au8522_dig.c
+++ b/drivers/media/dvb-frontends/au8522_dig.c
@@ -552,7 +552,7 @@ static struct {
552}; 552};
553 553
554static int au8522_enable_modulation(struct dvb_frontend *fe, 554static int au8522_enable_modulation(struct dvb_frontend *fe,
555 fe_modulation_t m) 555 enum fe_modulation m)
556{ 556{
557 struct au8522_state *state = fe->demodulator_priv; 557 struct au8522_state *state = fe->demodulator_priv;
558 int i; 558 int i;
@@ -644,7 +644,7 @@ static int au8522_set_frontend(struct dvb_frontend *fe)
644 return 0; 644 return 0;
645} 645}
646 646
647static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status) 647static int au8522_read_status(struct dvb_frontend *fe, enum fe_status *status)
648{ 648{
649 struct au8522_state *state = fe->demodulator_priv; 649 struct au8522_state *state = fe->demodulator_priv;
650 u8 reg; 650 u8 reg;
diff --git a/drivers/media/dvb-frontends/au8522_priv.h b/drivers/media/dvb-frontends/au8522_priv.h
index b8aca1c84786..951b3847e6f6 100644
--- a/drivers/media/dvb-frontends/au8522_priv.h
+++ b/drivers/media/dvb-frontends/au8522_priv.h
@@ -55,7 +55,7 @@ struct au8522_state {
55 struct dvb_frontend frontend; 55 struct dvb_frontend frontend;
56 56
57 u32 current_frequency; 57 u32 current_frequency;
58 fe_modulation_t current_modulation; 58 enum fe_modulation current_modulation;
59 59
60 u32 fe_status; 60 u32 fe_status;
61 unsigned int led_state; 61 unsigned int led_state;
diff --git a/drivers/media/dvb-frontends/bcm3510.c b/drivers/media/dvb-frontends/bcm3510.c
index 638c7aa0fb7e..d30275f27644 100644
--- a/drivers/media/dvb-frontends/bcm3510.c
+++ b/drivers/media/dvb-frontends/bcm3510.c
@@ -289,7 +289,7 @@ static int bcm3510_refresh_state(struct bcm3510_state *st)
289 return 0; 289 return 0;
290} 290}
291 291
292static int bcm3510_read_status(struct dvb_frontend *fe, fe_status_t *status) 292static int bcm3510_read_status(struct dvb_frontend *fe, enum fe_status *status)
293{ 293{
294 struct bcm3510_state* st = fe->demodulator_priv; 294 struct bcm3510_state* st = fe->demodulator_priv;
295 bcm3510_refresh_state(st); 295 bcm3510_refresh_state(st);
@@ -685,7 +685,7 @@ static int bcm3510_reset(struct bcm3510_state *st)
685 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0) 685 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0)
686 return ret; 686 return ret;
687 687
688 t = jiffies + 3*HZ; 688 t = jiffies + 3*HZ;
689 while (time_before(jiffies, t)) { 689 while (time_before(jiffies, t)) {
690 msleep(10); 690 msleep(10);
691 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0) 691 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
@@ -708,7 +708,7 @@ static int bcm3510_clear_reset(struct bcm3510_state *st)
708 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0) 708 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0)
709 return ret; 709 return ret;
710 710
711 t = jiffies + 3*HZ; 711 t = jiffies + 3*HZ;
712 while (time_before(jiffies, t)) { 712 while (time_before(jiffies, t)) {
713 msleep(10); 713 msleep(10);
714 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0) 714 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
diff --git a/drivers/media/dvb-frontends/cx22700.c b/drivers/media/dvb-frontends/cx22700.c
index 86563260d0f2..fd033cca6e11 100644
--- a/drivers/media/dvb-frontends/cx22700.c
+++ b/drivers/media/dvb-frontends/cx22700.c
@@ -191,9 +191,10 @@ static int cx22700_set_tps(struct cx22700_state *state,
191static int cx22700_get_tps(struct cx22700_state *state, 191static int cx22700_get_tps(struct cx22700_state *state,
192 struct dtv_frontend_properties *p) 192 struct dtv_frontend_properties *p)
193{ 193{
194 static const fe_modulation_t qam_tab [3] = { QPSK, QAM_16, QAM_64 }; 194 static const enum fe_modulation qam_tab[3] = { QPSK, QAM_16, QAM_64 };
195 static const fe_code_rate_t fec_tab [5] = { FEC_1_2, FEC_2_3, FEC_3_4, 195 static const enum fe_code_rate fec_tab[5] = {
196 FEC_5_6, FEC_7_8 }; 196 FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8
197 };
197 u8 val; 198 u8 val;
198 199
199 dprintk ("%s\n", __func__); 200 dprintk ("%s\n", __func__);
@@ -253,7 +254,7 @@ static int cx22700_init (struct dvb_frontend* fe)
253 return 0; 254 return 0;
254} 255}
255 256
256static int cx22700_read_status(struct dvb_frontend* fe, fe_status_t* status) 257static int cx22700_read_status(struct dvb_frontend *fe, enum fe_status *status)
257{ 258{
258 struct cx22700_state* state = fe->demodulator_priv; 259 struct cx22700_state* state = fe->demodulator_priv;
259 260
diff --git a/drivers/media/dvb-frontends/cx22702.c b/drivers/media/dvb-frontends/cx22702.c
index edc8eafc5c09..d2d06dcd7683 100644
--- a/drivers/media/dvb-frontends/cx22702.c
+++ b/drivers/media/dvb-frontends/cx22702.c
@@ -452,7 +452,7 @@ static int cx22702_init(struct dvb_frontend *fe)
452 return 0; 452 return 0;
453} 453}
454 454
455static int cx22702_read_status(struct dvb_frontend *fe, fe_status_t *status) 455static int cx22702_read_status(struct dvb_frontend *fe, enum fe_status *status)
456{ 456{
457 struct cx22702_state *state = fe->demodulator_priv; 457 struct cx22702_state *state = fe->demodulator_priv;
458 u8 reg0A; 458 u8 reg0A;
diff --git a/drivers/media/dvb-frontends/cx24110.c b/drivers/media/dvb-frontends/cx24110.c
index 7b510f2ae20f..cb36475e322b 100644
--- a/drivers/media/dvb-frontends/cx24110.c
+++ b/drivers/media/dvb-frontends/cx24110.c
@@ -143,7 +143,8 @@ static int cx24110_readreg (struct cx24110_state* state, u8 reg)
143 return b1[0]; 143 return b1[0];
144} 144}
145 145
146static int cx24110_set_inversion (struct cx24110_state* state, fe_spectral_inversion_t inversion) 146static int cx24110_set_inversion(struct cx24110_state *state,
147 enum fe_spectral_inversion inversion)
147{ 148{
148/* fixme (low): error handling */ 149/* fixme (low): error handling */
149 150
@@ -177,7 +178,7 @@ static int cx24110_set_inversion (struct cx24110_state* state, fe_spectral_inver
177 return 0; 178 return 0;
178} 179}
179 180
180static int cx24110_set_fec(struct cx24110_state* state, fe_code_rate_t fec) 181static int cx24110_set_fec(struct cx24110_state *state, enum fe_code_rate fec)
181{ 182{
182 static const int rate[FEC_AUTO] = {-1, 1, 2, 3, 5, 7, -1}; 183 static const int rate[FEC_AUTO] = {-1, 1, 2, 3, 5, 7, -1};
183 static const int g1[FEC_AUTO] = {-1, 0x01, 0x02, 0x05, 0x15, 0x45, -1}; 184 static const int g1[FEC_AUTO] = {-1, 0x01, 0x02, 0x05, 0x15, 0x45, -1};
@@ -220,7 +221,7 @@ static int cx24110_set_fec(struct cx24110_state* state, fe_code_rate_t fec)
220 return 0; 221 return 0;
221} 222}
222 223
223static fe_code_rate_t cx24110_get_fec (struct cx24110_state* state) 224static enum fe_code_rate cx24110_get_fec(struct cx24110_state *state)
224{ 225{
225 int i; 226 int i;
226 227
@@ -365,7 +366,8 @@ static int cx24110_initfe(struct dvb_frontend* fe)
365 return 0; 366 return 0;
366} 367}
367 368
368static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 369static int cx24110_set_voltage(struct dvb_frontend *fe,
370 enum fe_sec_voltage voltage)
369{ 371{
370 struct cx24110_state *state = fe->demodulator_priv; 372 struct cx24110_state *state = fe->demodulator_priv;
371 373
@@ -379,7 +381,8 @@ static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
379 } 381 }
380} 382}
381 383
382static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 384static int cx24110_diseqc_send_burst(struct dvb_frontend *fe,
385 enum fe_sec_mini_cmd burst)
383{ 386{
384 int rv, bit; 387 int rv, bit;
385 struct cx24110_state *state = fe->demodulator_priv; 388 struct cx24110_state *state = fe->demodulator_priv;
@@ -434,7 +437,8 @@ static int cx24110_send_diseqc_msg(struct dvb_frontend* fe,
434 return 0; 437 return 0;
435} 438}
436 439
437static int cx24110_read_status(struct dvb_frontend* fe, fe_status_t* status) 440static int cx24110_read_status(struct dvb_frontend *fe,
441 enum fe_status *status)
438{ 442{
439 struct cx24110_state *state = fe->demodulator_priv; 443 struct cx24110_state *state = fe->demodulator_priv;
440 444
@@ -574,7 +578,8 @@ static int cx24110_get_frontend(struct dvb_frontend *fe)
574 return 0; 578 return 0;
575} 579}
576 580
577static int cx24110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 581static int cx24110_set_tone(struct dvb_frontend *fe,
582 enum fe_sec_tone_mode tone)
578{ 583{
579 struct cx24110_state *state = fe->demodulator_priv; 584 struct cx24110_state *state = fe->demodulator_priv;
580 585
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 2916d7c74a1d..8814f36d53fb 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -160,13 +160,13 @@ enum cmds {
160struct cx24116_tuning { 160struct cx24116_tuning {
161 u32 frequency; 161 u32 frequency;
162 u32 symbol_rate; 162 u32 symbol_rate;
163 fe_spectral_inversion_t inversion; 163 enum fe_spectral_inversion inversion;
164 fe_code_rate_t fec; 164 enum fe_code_rate fec;
165 165
166 fe_delivery_system_t delsys; 166 enum fe_delivery_system delsys;
167 fe_modulation_t modulation; 167 enum fe_modulation modulation;
168 fe_pilot_t pilot; 168 enum fe_pilot pilot;
169 fe_rolloff_t rolloff; 169 enum fe_rolloff rolloff;
170 170
171 /* Demod values */ 171 /* Demod values */
172 u8 fec_val; 172 u8 fec_val;
@@ -285,7 +285,7 @@ static int cx24116_readreg(struct cx24116_state *state, u8 reg)
285} 285}
286 286
287static int cx24116_set_inversion(struct cx24116_state *state, 287static int cx24116_set_inversion(struct cx24116_state *state,
288 fe_spectral_inversion_t inversion) 288 enum fe_spectral_inversion inversion)
289{ 289{
290 dprintk("%s(%d)\n", __func__, inversion); 290 dprintk("%s(%d)\n", __func__, inversion);
291 291
@@ -373,9 +373,9 @@ static int cx24116_set_inversion(struct cx24116_state *state,
373 * a scheme are support. Especially, no auto detect when in S2 mode. 373 * a scheme are support. Especially, no auto detect when in S2 mode.
374 */ 374 */
375static struct cx24116_modfec { 375static struct cx24116_modfec {
376 fe_delivery_system_t delivery_system; 376 enum fe_delivery_system delivery_system;
377 fe_modulation_t modulation; 377 enum fe_modulation modulation;
378 fe_code_rate_t fec; 378 enum fe_code_rate fec;
379 u8 mask; /* In DVBS mode this is used to autodetect */ 379 u8 mask; /* In DVBS mode this is used to autodetect */
380 u8 val; /* Passed to the firmware to indicate mode selection */ 380 u8 val; /* Passed to the firmware to indicate mode selection */
381} CX24116_MODFEC_MODES[] = { 381} CX24116_MODFEC_MODES[] = {
@@ -415,7 +415,7 @@ static struct cx24116_modfec {
415}; 415};
416 416
417static int cx24116_lookup_fecmod(struct cx24116_state *state, 417static int cx24116_lookup_fecmod(struct cx24116_state *state,
418 fe_delivery_system_t d, fe_modulation_t m, fe_code_rate_t f) 418 enum fe_delivery_system d, enum fe_modulation m, enum fe_code_rate f)
419{ 419{
420 int i, ret = -EOPNOTSUPP; 420 int i, ret = -EOPNOTSUPP;
421 421
@@ -434,7 +434,9 @@ static int cx24116_lookup_fecmod(struct cx24116_state *state,
434} 434}
435 435
436static int cx24116_set_fec(struct cx24116_state *state, 436static int cx24116_set_fec(struct cx24116_state *state,
437 fe_delivery_system_t delsys, fe_modulation_t mod, fe_code_rate_t fec) 437 enum fe_delivery_system delsys,
438 enum fe_modulation mod,
439 enum fe_code_rate fec)
438{ 440{
439 int ret = 0; 441 int ret = 0;
440 442
@@ -683,7 +685,7 @@ static int cx24116_load_firmware(struct dvb_frontend *fe,
683 return 0; 685 return 0;
684} 686}
685 687
686static int cx24116_read_status(struct dvb_frontend *fe, fe_status_t *status) 688static int cx24116_read_status(struct dvb_frontend *fe, enum fe_status *status)
687{ 689{
688 struct cx24116_state *state = fe->demodulator_priv; 690 struct cx24116_state *state = fe->demodulator_priv;
689 691
@@ -844,7 +846,7 @@ static int cx24116_wait_for_lnb(struct dvb_frontend *fe)
844} 846}
845 847
846static int cx24116_set_voltage(struct dvb_frontend *fe, 848static int cx24116_set_voltage(struct dvb_frontend *fe,
847 fe_sec_voltage_t voltage) 849 enum fe_sec_voltage voltage)
848{ 850{
849 struct cx24116_cmd cmd; 851 struct cx24116_cmd cmd;
850 int ret; 852 int ret;
@@ -872,7 +874,7 @@ static int cx24116_set_voltage(struct dvb_frontend *fe,
872} 874}
873 875
874static int cx24116_set_tone(struct dvb_frontend *fe, 876static int cx24116_set_tone(struct dvb_frontend *fe,
875 fe_sec_tone_mode_t tone) 877 enum fe_sec_tone_mode tone)
876{ 878{
877 struct cx24116_cmd cmd; 879 struct cx24116_cmd cmd;
878 int ret; 880 int ret;
@@ -963,6 +965,10 @@ static int cx24116_send_diseqc_msg(struct dvb_frontend *fe,
963 struct cx24116_state *state = fe->demodulator_priv; 965 struct cx24116_state *state = fe->demodulator_priv;
964 int i, ret; 966 int i, ret;
965 967
968 /* Validate length */
969 if (d->msg_len > sizeof(d->msg))
970 return -EINVAL;
971
966 /* Dump DiSEqC message */ 972 /* Dump DiSEqC message */
967 if (debug) { 973 if (debug) {
968 printk(KERN_INFO "cx24116: %s(", __func__); 974 printk(KERN_INFO "cx24116: %s(", __func__);
@@ -974,10 +980,6 @@ static int cx24116_send_diseqc_msg(struct dvb_frontend *fe,
974 printk(") toneburst=%d\n", toneburst); 980 printk(") toneburst=%d\n", toneburst);
975 } 981 }
976 982
977 /* Validate length */
978 if (d->msg_len > (CX24116_ARGLEN - CX24116_DISEQC_MSGOFS))
979 return -EINVAL;
980
981 /* DiSEqC message */ 983 /* DiSEqC message */
982 for (i = 0; i < d->msg_len; i++) 984 for (i = 0; i < d->msg_len; i++)
983 state->dsec_cmd.args[CX24116_DISEQC_MSGOFS + i] = d->msg[i]; 985 state->dsec_cmd.args[CX24116_DISEQC_MSGOFS + i] = d->msg[i];
@@ -1055,7 +1057,7 @@ static int cx24116_send_diseqc_msg(struct dvb_frontend *fe,
1055 1057
1056/* Send DiSEqC burst */ 1058/* Send DiSEqC burst */
1057static int cx24116_diseqc_send_burst(struct dvb_frontend *fe, 1059static int cx24116_diseqc_send_burst(struct dvb_frontend *fe,
1058 fe_sec_mini_cmd_t burst) 1060 enum fe_sec_mini_cmd burst)
1059{ 1061{
1060 struct cx24116_state *state = fe->demodulator_priv; 1062 struct cx24116_state *state = fe->demodulator_priv;
1061 int ret; 1063 int ret;
@@ -1220,7 +1222,7 @@ static int cx24116_set_frontend(struct dvb_frontend *fe)
1220 struct cx24116_state *state = fe->demodulator_priv; 1222 struct cx24116_state *state = fe->demodulator_priv;
1221 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1223 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1222 struct cx24116_cmd cmd; 1224 struct cx24116_cmd cmd;
1223 fe_status_t tunerstat; 1225 enum fe_status tunerstat;
1224 int i, status, ret, retune = 1; 1226 int i, status, ret, retune = 1;
1225 1227
1226 dprintk("%s()\n", __func__); 1228 dprintk("%s()\n", __func__);
@@ -1441,7 +1443,7 @@ tuned: /* Set/Reset B/W */
1441} 1443}
1442 1444
1443static int cx24116_tune(struct dvb_frontend *fe, bool re_tune, 1445static int cx24116_tune(struct dvb_frontend *fe, bool re_tune,
1444 unsigned int mode_flags, unsigned int *delay, fe_status_t *status) 1446 unsigned int mode_flags, unsigned int *delay, enum fe_status *status)
1445{ 1447{
1446 /* 1448 /*
1447 * It is safe to discard "params" here, as the DVB core will sync 1449 * It is safe to discard "params" here, as the DVB core will sync
diff --git a/drivers/media/dvb-frontends/cx24117.c b/drivers/media/dvb-frontends/cx24117.c
index acb965ce0358..5f77bc80a896 100644
--- a/drivers/media/dvb-frontends/cx24117.c
+++ b/drivers/media/dvb-frontends/cx24117.c
@@ -171,13 +171,13 @@ static DEFINE_MUTEX(cx24117_list_mutex);
171struct cx24117_tuning { 171struct cx24117_tuning {
172 u32 frequency; 172 u32 frequency;
173 u32 symbol_rate; 173 u32 symbol_rate;
174 fe_spectral_inversion_t inversion; 174 enum fe_spectral_inversion inversion;
175 fe_code_rate_t fec; 175 enum fe_code_rate fec;
176 176
177 fe_delivery_system_t delsys; 177 enum fe_delivery_system delsys;
178 fe_modulation_t modulation; 178 enum fe_modulation modulation;
179 fe_pilot_t pilot; 179 enum fe_pilot pilot;
180 fe_rolloff_t rolloff; 180 enum fe_rolloff rolloff;
181 181
182 /* Demod values */ 182 /* Demod values */
183 u8 fec_val; 183 u8 fec_val;
@@ -220,9 +220,9 @@ struct cx24117_state {
220/* modfec (modulation and FEC) lookup table */ 220/* modfec (modulation and FEC) lookup table */
221/* Check cx24116.c for a detailed description of each field */ 221/* Check cx24116.c for a detailed description of each field */
222static struct cx24117_modfec { 222static struct cx24117_modfec {
223 fe_delivery_system_t delivery_system; 223 enum fe_delivery_system delivery_system;
224 fe_modulation_t modulation; 224 enum fe_modulation modulation;
225 fe_code_rate_t fec; 225 enum fe_code_rate fec;
226 u8 mask; /* In DVBS mode this is used to autodetect */ 226 u8 mask; /* In DVBS mode this is used to autodetect */
227 u8 val; /* Passed to the firmware to indicate mode selection */ 227 u8 val; /* Passed to the firmware to indicate mode selection */
228} cx24117_modfec_modes[] = { 228} cx24117_modfec_modes[] = {
@@ -362,7 +362,7 @@ static int cx24117_readregN(struct cx24117_state *state,
362} 362}
363 363
364static int cx24117_set_inversion(struct cx24117_state *state, 364static int cx24117_set_inversion(struct cx24117_state *state,
365 fe_spectral_inversion_t inversion) 365 enum fe_spectral_inversion inversion)
366{ 366{
367 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n", 367 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
368 __func__, inversion, state->demod); 368 __func__, inversion, state->demod);
@@ -387,7 +387,7 @@ static int cx24117_set_inversion(struct cx24117_state *state,
387} 387}
388 388
389static int cx24117_lookup_fecmod(struct cx24117_state *state, 389static int cx24117_lookup_fecmod(struct cx24117_state *state,
390 fe_delivery_system_t d, fe_modulation_t m, fe_code_rate_t f) 390 enum fe_delivery_system d, enum fe_modulation m, enum fe_code_rate f)
391{ 391{
392 int i, ret = -EINVAL; 392 int i, ret = -EINVAL;
393 393
@@ -408,7 +408,9 @@ static int cx24117_lookup_fecmod(struct cx24117_state *state,
408} 408}
409 409
410static int cx24117_set_fec(struct cx24117_state *state, 410static int cx24117_set_fec(struct cx24117_state *state,
411 fe_delivery_system_t delsys, fe_modulation_t mod, fe_code_rate_t fec) 411 enum fe_delivery_system delsys,
412 enum fe_modulation mod,
413 enum fe_code_rate fec)
412{ 414{
413 int ret; 415 int ret;
414 416
@@ -737,7 +739,7 @@ error:
737 return ret; 739 return ret;
738} 740}
739 741
740static int cx24117_read_status(struct dvb_frontend *fe, fe_status_t *status) 742static int cx24117_read_status(struct dvb_frontend *fe, enum fe_status *status)
741{ 743{
742 struct cx24117_state *state = fe->demodulator_priv; 744 struct cx24117_state *state = fe->demodulator_priv;
743 int lock; 745 int lock;
@@ -843,7 +845,7 @@ static int cx24117_read_snr(struct dvb_frontend *fe, u16 *snr)
843static int cx24117_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 845static int cx24117_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
844{ 846{
845 struct cx24117_state *state = fe->demodulator_priv; 847 struct cx24117_state *state = fe->demodulator_priv;
846 fe_delivery_system_t delsys = fe->dtv_property_cache.delivery_system; 848 enum fe_delivery_system delsys = fe->dtv_property_cache.delivery_system;
847 int ret; 849 int ret;
848 u8 buf[2]; 850 u8 buf[2];
849 u8 reg = (state->demod == 0) ? 851 u8 reg = (state->demod == 0) ?
@@ -904,7 +906,7 @@ static int cx24117_wait_for_lnb(struct dvb_frontend *fe)
904} 906}
905 907
906static int cx24117_set_voltage(struct dvb_frontend *fe, 908static int cx24117_set_voltage(struct dvb_frontend *fe,
907 fe_sec_voltage_t voltage) 909 enum fe_sec_voltage voltage)
908{ 910{
909 struct cx24117_state *state = fe->demodulator_priv; 911 struct cx24117_state *state = fe->demodulator_priv;
910 struct cx24117_cmd cmd; 912 struct cx24117_cmd cmd;
@@ -956,7 +958,7 @@ static int cx24117_set_voltage(struct dvb_frontend *fe,
956} 958}
957 959
958static int cx24117_set_tone(struct dvb_frontend *fe, 960static int cx24117_set_tone(struct dvb_frontend *fe,
959 fe_sec_tone_mode_t tone) 961 enum fe_sec_tone_mode tone)
960{ 962{
961 struct cx24117_state *state = fe->demodulator_priv; 963 struct cx24117_state *state = fe->demodulator_priv;
962 struct cx24117_cmd cmd; 964 struct cx24117_cmd cmd;
@@ -1043,7 +1045,7 @@ static int cx24117_send_diseqc_msg(struct dvb_frontend *fe,
1043 dev_dbg(&state->priv->i2c->dev, ")\n"); 1045 dev_dbg(&state->priv->i2c->dev, ")\n");
1044 1046
1045 /* Validate length */ 1047 /* Validate length */
1046 if (d->msg_len > 15) 1048 if (d->msg_len > sizeof(d->msg))
1047 return -EINVAL; 1049 return -EINVAL;
1048 1050
1049 /* DiSEqC message */ 1051 /* DiSEqC message */
@@ -1112,7 +1114,7 @@ static int cx24117_send_diseqc_msg(struct dvb_frontend *fe,
1112 1114
1113/* Send DiSEqC burst */ 1115/* Send DiSEqC burst */
1114static int cx24117_diseqc_send_burst(struct dvb_frontend *fe, 1116static int cx24117_diseqc_send_burst(struct dvb_frontend *fe,
1115 fe_sec_mini_cmd_t burst) 1117 enum fe_sec_mini_cmd burst)
1116{ 1118{
1117 struct cx24117_state *state = fe->demodulator_priv; 1119 struct cx24117_state *state = fe->demodulator_priv;
1118 1120
@@ -1306,7 +1308,7 @@ static int cx24117_set_frontend(struct dvb_frontend *fe)
1306 struct cx24117_state *state = fe->demodulator_priv; 1308 struct cx24117_state *state = fe->demodulator_priv;
1307 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1309 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1308 struct cx24117_cmd cmd; 1310 struct cx24117_cmd cmd;
1309 fe_status_t tunerstat; 1311 enum fe_status tunerstat;
1310 int i, status, ret, retune = 1; 1312 int i, status, ret, retune = 1;
1311 u8 reg_clkdiv, reg_ratediv; 1313 u8 reg_clkdiv, reg_ratediv;
1312 1314
@@ -1537,7 +1539,7 @@ static int cx24117_set_frontend(struct dvb_frontend *fe)
1537} 1539}
1538 1540
1539static int cx24117_tune(struct dvb_frontend *fe, bool re_tune, 1541static int cx24117_tune(struct dvb_frontend *fe, bool re_tune,
1540 unsigned int mode_flags, unsigned int *delay, fe_status_t *status) 1542 unsigned int mode_flags, unsigned int *delay, enum fe_status *status)
1541{ 1543{
1542 struct cx24117_state *state = fe->demodulator_priv; 1544 struct cx24117_state *state = fe->demodulator_priv;
1543 1545
diff --git a/drivers/media/dvb-frontends/cx24120.c b/drivers/media/dvb-frontends/cx24120.c
new file mode 100644
index 000000000000..3b0ef52bb834
--- /dev/null
+++ b/drivers/media/dvb-frontends/cx24120.c
@@ -0,0 +1,1595 @@
1/*
2 Conexant cx24120/cx24118 - DVBS/S2 Satellite demod/tuner driver
3
4 Copyright (C) 2008 Patrick Boettcher <pb@linuxtv.org>
5 Copyright (C) 2009 Sergey Tyurin <forum.free-x.de>
6 Updated 2012 by Jannis Achstetter <jannis_achstetter@web.de>
7 Copyright (C) 2015 Jemma Denson <jdenson@gmail.com>
8 April 2015
9 Refactored & simplified driver
10 Updated to work with delivery system supplied by DVBv5
11 Add frequency, fec & pilot to get_frontend
12
13 Cards supported: Technisat Skystar S2
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24*/
25
26#include <linux/slab.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/moduleparam.h>
30#include <linux/init.h>
31#include <linux/firmware.h>
32#include "dvb_frontend.h"
33#include "cx24120.h"
34
35#define CX24120_SEARCH_RANGE_KHZ 5000
36#define CX24120_FIRMWARE "dvb-fe-cx24120-1.20.58.2.fw"
37
38/* cx24120 i2c registers */
39#define CX24120_REG_CMD_START 0x00 /* write cmd_id */
40#define CX24120_REG_CMD_ARGS 0x01 /* write command arguments */
41#define CX24120_REG_CMD_END 0x1f /* write 0x01 for end */
42
43#define CX24120_REG_MAILBOX 0x33
44#define CX24120_REG_FREQ3 0x34 /* frequency */
45#define CX24120_REG_FREQ2 0x35
46#define CX24120_REG_FREQ1 0x36
47
48#define CX24120_REG_FECMODE 0x39 /* FEC status */
49#define CX24120_REG_STATUS 0x3a /* Tuner status */
50#define CX24120_REG_SIGSTR_H 0x3a /* Signal strength high */
51#define CX24120_REG_SIGSTR_L 0x3b /* Signal strength low byte */
52#define CX24120_REG_QUALITY_H 0x40 /* SNR high byte */
53#define CX24120_REG_QUALITY_L 0x41 /* SNR low byte */
54
55#define CX24120_REG_BER_HH 0x47 /* BER high byte of high word */
56#define CX24120_REG_BER_HL 0x48 /* BER low byte of high word */
57#define CX24120_REG_BER_LH 0x49 /* BER high byte of low word */
58#define CX24120_REG_BER_LL 0x4a /* BER low byte of low word */
59
60#define CX24120_REG_UCB_H 0x50 /* UCB high byte */
61#define CX24120_REG_UCB_L 0x51 /* UCB low byte */
62
63#define CX24120_REG_CLKDIV 0xe6
64#define CX24120_REG_RATEDIV 0xf0
65
66#define CX24120_REG_REVISION 0xff /* Chip revision (ro) */
67
68/* Command messages */
69enum command_message_id {
70 CMD_VCO_SET = 0x10, /* cmd.len = 12; */
71 CMD_TUNEREQUEST = 0x11, /* cmd.len = 15; */
72
73 CMD_MPEG_ONOFF = 0x13, /* cmd.len = 4; */
74 CMD_MPEG_INIT = 0x14, /* cmd.len = 7; */
75 CMD_BANDWIDTH = 0x15, /* cmd.len = 12; */
76 CMD_CLOCK_READ = 0x16, /* read clock */
77 CMD_CLOCK_SET = 0x17, /* cmd.len = 10; */
78
79 CMD_DISEQC_MSG1 = 0x20, /* cmd.len = 11; */
80 CMD_DISEQC_MSG2 = 0x21, /* cmd.len = d->msg_len + 6; */
81 CMD_SETVOLTAGE = 0x22, /* cmd.len = 2; */
82 CMD_SETTONE = 0x23, /* cmd.len = 4; */
83 CMD_DISEQC_BURST = 0x24, /* cmd.len not used !!! */
84
85 CMD_READ_SNR = 0x1a, /* Read signal strength */
86 CMD_START_TUNER = 0x1b, /* ??? */
87
88 CMD_FWVERSION = 0x35,
89
90 CMD_BER_CTRL = 0x3c, /* cmd.len = 0x03; */
91};
92
93#define CX24120_MAX_CMD_LEN 30
94
95/* pilot mask */
96#define CX24120_PILOT_OFF 0x00
97#define CX24120_PILOT_ON 0x40
98#define CX24120_PILOT_AUTO 0x80
99
100/* signal status */
101#define CX24120_HAS_SIGNAL 0x01
102#define CX24120_HAS_CARRIER 0x02
103#define CX24120_HAS_VITERBI 0x04
104#define CX24120_HAS_LOCK 0x08
105#define CX24120_HAS_UNK1 0x10
106#define CX24120_HAS_UNK2 0x20
107#define CX24120_STATUS_MASK 0x0f
108#define CX24120_SIGNAL_MASK 0xc0
109
110/* ber window */
111#define CX24120_BER_WINDOW 16
112#define CX24120_BER_WSIZE ((1 << CX24120_BER_WINDOW) * 208 * 8)
113
114#define info(args...) pr_info("cx24120: " args)
115#define err(args...) pr_err("cx24120: ### ERROR: " args)
116
117/* The Demod/Tuner can't easily provide these, we cache them */
118struct cx24120_tuning {
119 u32 frequency;
120 u32 symbol_rate;
121 enum fe_spectral_inversion inversion;
122 enum fe_code_rate fec;
123
124 enum fe_delivery_system delsys;
125 enum fe_modulation modulation;
126 enum fe_pilot pilot;
127
128 /* Demod values */
129 u8 fec_val;
130 u8 fec_mask;
131 u8 clkdiv;
132 u8 ratediv;
133 u8 inversion_val;
134 u8 pilot_val;
135};
136
137/* Private state */
138struct cx24120_state {
139 struct i2c_adapter *i2c;
140 const struct cx24120_config *config;
141 struct dvb_frontend frontend;
142
143 u8 cold_init;
144 u8 mpeg_enabled;
145 u8 need_clock_set;
146
147 /* current and next tuning parameters */
148 struct cx24120_tuning dcur;
149 struct cx24120_tuning dnxt;
150
151 enum fe_status fe_status;
152
153 /* dvbv5 stats calculations */
154 u32 bitrate;
155 u32 berw_usecs;
156 u32 ber_prev;
157 u32 ucb_offset;
158 unsigned long ber_jiffies_stats;
159 unsigned long per_jiffies_stats;
160};
161
162/* Command message to firmware */
163struct cx24120_cmd {
164 u8 id;
165 u8 len;
166 u8 arg[CX24120_MAX_CMD_LEN];
167};
168
169/* Read single register */
170static int cx24120_readreg(struct cx24120_state *state, u8 reg)
171{
172 int ret;
173 u8 buf = 0;
174 struct i2c_msg msg[] = {
175 {
176 .addr = state->config->i2c_addr,
177 .flags = 0,
178 .len = 1,
179 .buf = &reg
180 }, {
181 .addr = state->config->i2c_addr,
182 .flags = I2C_M_RD,
183 .len = 1,
184 .buf = &buf
185 }
186 };
187
188 ret = i2c_transfer(state->i2c, msg, 2);
189 if (ret != 2) {
190 err("Read error: reg=0x%02x, ret=%i)\n", reg, ret);
191 return ret;
192 }
193
194 dev_dbg(&state->i2c->dev, "reg=0x%02x; data=0x%02x\n", reg, buf);
195
196 return buf;
197}
198
199/* Write single register */
200static int cx24120_writereg(struct cx24120_state *state, u8 reg, u8 data)
201{
202 u8 buf[] = { reg, data };
203 struct i2c_msg msg = {
204 .addr = state->config->i2c_addr,
205 .flags = 0,
206 .buf = buf,
207 .len = 2
208 };
209 int ret;
210
211 ret = i2c_transfer(state->i2c, &msg, 1);
212 if (ret != 1) {
213 err("Write error: i2c_write error(err == %i, 0x%02x: 0x%02x)\n",
214 ret, reg, data);
215 return ret;
216 }
217
218 dev_dbg(&state->i2c->dev, "reg=0x%02x; data=0x%02x\n", reg, data);
219
220 return 0;
221}
222
223/* Write multiple registers in chunks of i2c_wr_max-sized buffers */
224static int cx24120_writeregs(struct cx24120_state *state,
225 u8 reg, const u8 *values, u16 len, u8 incr)
226{
227 int ret;
228 u16 max = state->config->i2c_wr_max > 0 ?
229 state->config->i2c_wr_max :
230 len;
231
232 struct i2c_msg msg = {
233 .addr = state->config->i2c_addr,
234 .flags = 0,
235 };
236
237 msg.buf = kmalloc(max + 1, GFP_KERNEL);
238 if (!msg.buf)
239 return -ENOMEM;
240
241 while (len) {
242 msg.buf[0] = reg;
243 msg.len = len > max ? max : len;
244 memcpy(&msg.buf[1], values, msg.len);
245
246 len -= msg.len; /* data length revers counter */
247 values += msg.len; /* incr data pointer */
248
249 if (incr)
250 reg += msg.len;
251 msg.len++; /* don't forget the addr byte */
252
253 ret = i2c_transfer(state->i2c, &msg, 1);
254 if (ret != 1) {
255 err("i2c_write error(err == %i, 0x%02x)\n", ret, reg);
256 goto out;
257 }
258
259 dev_dbg(&state->i2c->dev, "reg=0x%02x; data=%*ph\n",
260 reg, msg.len - 1, msg.buf + 1);
261 }
262
263 ret = 0;
264
265out:
266 kfree(msg.buf);
267 return ret;
268}
269
270static struct dvb_frontend_ops cx24120_ops;
271
272struct dvb_frontend *cx24120_attach(const struct cx24120_config *config,
273 struct i2c_adapter *i2c)
274{
275 struct cx24120_state *state;
276 int demod_rev;
277
278 info("Conexant cx24120/cx24118 - DVBS/S2 Satellite demod/tuner\n");
279 state = kzalloc(sizeof(*state), GFP_KERNEL);
280 if (!state) {
281 err("Unable to allocate memory for cx24120_state\n");
282 goto error;
283 }
284
285 /* setup the state */
286 state->config = config;
287 state->i2c = i2c;
288
289 /* check if the demod is present and has proper type */
290 demod_rev = cx24120_readreg(state, CX24120_REG_REVISION);
291 switch (demod_rev) {
292 case 0x07:
293 info("Demod cx24120 rev. 0x07 detected.\n");
294 break;
295 case 0x05:
296 info("Demod cx24120 rev. 0x05 detected.\n");
297 break;
298 default:
299 err("Unsupported demod revision: 0x%x detected.\n", demod_rev);
300 goto error;
301 }
302
303 /* create dvb_frontend */
304 state->cold_init = 0;
305 memcpy(&state->frontend.ops, &cx24120_ops,
306 sizeof(struct dvb_frontend_ops));
307 state->frontend.demodulator_priv = state;
308
309 info("Conexant cx24120/cx24118 attached.\n");
310 return &state->frontend;
311
312error:
313 kfree(state);
314 return NULL;
315}
316EXPORT_SYMBOL(cx24120_attach);
317
318static int cx24120_test_rom(struct cx24120_state *state)
319{
320 int err, ret;
321
322 err = cx24120_readreg(state, 0xfd);
323 if (err & 4) {
324 ret = cx24120_readreg(state, 0xdf) & 0xfe;
325 err = cx24120_writereg(state, 0xdf, ret);
326 }
327 return err;
328}
329
330static int cx24120_read_snr(struct dvb_frontend *fe, u16 *snr)
331{
332 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
333
334 if (c->cnr.stat[0].scale != FE_SCALE_DECIBEL)
335 *snr = 0;
336 else
337 *snr = div_s64(c->cnr.stat[0].svalue, 100);
338
339 return 0;
340}
341
342static int cx24120_read_ber(struct dvb_frontend *fe, u32 *ber)
343{
344 struct cx24120_state *state = fe->demodulator_priv;
345 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
346
347 if (c->post_bit_error.stat[0].scale != FE_SCALE_COUNTER) {
348 *ber = 0;
349 return 0;
350 }
351
352 *ber = c->post_bit_error.stat[0].uvalue - state->ber_prev;
353 state->ber_prev = c->post_bit_error.stat[0].uvalue;
354
355 return 0;
356}
357
358static int cx24120_msg_mpeg_output_global_config(struct cx24120_state *state,
359 u8 flag);
360
361/* Check if we're running a command that needs to disable mpeg out */
362static void cx24120_check_cmd(struct cx24120_state *state, u8 id)
363{
364 switch (id) {
365 case CMD_TUNEREQUEST:
366 case CMD_CLOCK_READ:
367 case CMD_DISEQC_MSG1:
368 case CMD_DISEQC_MSG2:
369 case CMD_SETVOLTAGE:
370 case CMD_SETTONE:
371 case CMD_DISEQC_BURST:
372 cx24120_msg_mpeg_output_global_config(state, 0);
373 /* Old driver would do a msleep(100) here */
374 default:
375 return;
376 }
377}
378
379/* Send a message to the firmware */
380static int cx24120_message_send(struct cx24120_state *state,
381 struct cx24120_cmd *cmd)
382{
383 int ficus;
384
385 if (state->mpeg_enabled) {
386 /* Disable mpeg out on certain commands */
387 cx24120_check_cmd(state, cmd->id);
388 }
389
390 cx24120_writereg(state, CX24120_REG_CMD_START, cmd->id);
391 cx24120_writeregs(state, CX24120_REG_CMD_ARGS, &cmd->arg[0],
392 cmd->len, 1);
393 cx24120_writereg(state, CX24120_REG_CMD_END, 0x01);
394
395 ficus = 1000;
396 while (cx24120_readreg(state, CX24120_REG_CMD_END)) {
397 msleep(20);
398 ficus -= 20;
399 if (ficus == 0) {
400 err("Error sending message to firmware\n");
401 return -EREMOTEIO;
402 }
403 }
404 dev_dbg(&state->i2c->dev, "sent message 0x%02x\n", cmd->id);
405
406 return 0;
407}
408
409/* Send a message and fill arg[] with the results */
410static int cx24120_message_sendrcv(struct cx24120_state *state,
411 struct cx24120_cmd *cmd, u8 numreg)
412{
413 int ret, i;
414
415 if (numreg > CX24120_MAX_CMD_LEN) {
416 err("Too many registers to read. cmd->reg = %d", numreg);
417 return -EREMOTEIO;
418 }
419
420 ret = cx24120_message_send(state, cmd);
421 if (ret != 0)
422 return ret;
423
424 if (!numreg)
425 return 0;
426
427 /* Read numreg registers starting from register cmd->len */
428 for (i = 0; i < numreg; i++)
429 cmd->arg[i] = cx24120_readreg(state, (cmd->len + i + 1));
430
431 return 0;
432}
433
434static int cx24120_read_signal_strength(struct dvb_frontend *fe,
435 u16 *signal_strength)
436{
437 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
438
439 if (c->strength.stat[0].scale != FE_SCALE_RELATIVE)
440 *signal_strength = 0;
441 else
442 *signal_strength = c->strength.stat[0].uvalue;
443
444 return 0;
445}
446
447static int cx24120_msg_mpeg_output_global_config(struct cx24120_state *state,
448 u8 enable)
449{
450 struct cx24120_cmd cmd;
451 int ret;
452
453 cmd.id = CMD_MPEG_ONOFF;
454 cmd.len = 4;
455 cmd.arg[0] = 0x01;
456 cmd.arg[1] = 0x00;
457 cmd.arg[2] = enable ? 0 : (u8)(-1);
458 cmd.arg[3] = 0x01;
459
460 ret = cx24120_message_send(state, &cmd);
461 if (ret != 0) {
462 dev_dbg(&state->i2c->dev, "failed to %s MPEG output\n",
463 enable ? "enable" : "disable");
464 return ret;
465 }
466
467 state->mpeg_enabled = enable;
468 dev_dbg(&state->i2c->dev, "MPEG output %s\n",
469 enable ? "enabled" : "disabled");
470
471 return 0;
472}
473
474static int cx24120_msg_mpeg_output_config(struct cx24120_state *state, u8 seq)
475{
476 struct cx24120_cmd cmd;
477 struct cx24120_initial_mpeg_config i =
478 state->config->initial_mpeg_config;
479
480 cmd.id = CMD_MPEG_INIT;
481 cmd.len = 7;
482 cmd.arg[0] = seq; /* sequental number - can be 0,1,2 */
483 cmd.arg[1] = ((i.x1 & 0x01) << 1) | ((i.x1 >> 1) & 0x01);
484 cmd.arg[2] = 0x05;
485 cmd.arg[3] = 0x02;
486 cmd.arg[4] = ((i.x2 >> 1) & 0x01);
487 cmd.arg[5] = (i.x2 & 0xf0) | (i.x3 & 0x0f);
488 cmd.arg[6] = 0x10;
489
490 return cx24120_message_send(state, &cmd);
491}
492
493static int cx24120_diseqc_send_burst(struct dvb_frontend *fe,
494 enum fe_sec_mini_cmd burst)
495{
496 struct cx24120_state *state = fe->demodulator_priv;
497 struct cx24120_cmd cmd;
498
499 dev_dbg(&state->i2c->dev, "\n");
500
501 /*
502 * Yes, cmd.len is set to zero. The old driver
503 * didn't specify any len, but also had a
504 * memset 0 before every use of the cmd struct
505 * which would have set it to zero.
506 * This quite probably needs looking into.
507 */
508 cmd.id = CMD_DISEQC_BURST;
509 cmd.len = 0;
510 cmd.arg[0] = 0x00;
511 cmd.arg[1] = (burst == SEC_MINI_B) ? 0x01 : 0x00;
512
513 return cx24120_message_send(state, &cmd);
514}
515
516static int cx24120_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
517{
518 struct cx24120_state *state = fe->demodulator_priv;
519 struct cx24120_cmd cmd;
520
521 dev_dbg(&state->i2c->dev, "(%d)\n", tone);
522
523 if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) {
524 err("Invalid tone=%d\n", tone);
525 return -EINVAL;
526 }
527
528 cmd.id = CMD_SETTONE;
529 cmd.len = 4;
530 cmd.arg[0] = 0x00;
531 cmd.arg[1] = 0x00;
532 cmd.arg[2] = 0x00;
533 cmd.arg[3] = (tone == SEC_TONE_ON) ? 0x01 : 0x00;
534
535 return cx24120_message_send(state, &cmd);
536}
537
538static int cx24120_set_voltage(struct dvb_frontend *fe,
539 enum fe_sec_voltage voltage)
540{
541 struct cx24120_state *state = fe->demodulator_priv;
542 struct cx24120_cmd cmd;
543
544 dev_dbg(&state->i2c->dev, "(%d)\n", voltage);
545
546 cmd.id = CMD_SETVOLTAGE;
547 cmd.len = 2;
548 cmd.arg[0] = 0x00;
549 cmd.arg[1] = (voltage == SEC_VOLTAGE_18) ? 0x01 : 0x00;
550
551 return cx24120_message_send(state, &cmd);
552}
553
554static int cx24120_send_diseqc_msg(struct dvb_frontend *fe,
555 struct dvb_diseqc_master_cmd *d)
556{
557 struct cx24120_state *state = fe->demodulator_priv;
558 struct cx24120_cmd cmd;
559 int back_count;
560
561 dev_dbg(&state->i2c->dev, "\n");
562
563 cmd.id = CMD_DISEQC_MSG1;
564 cmd.len = 11;
565 cmd.arg[0] = 0x00;
566 cmd.arg[1] = 0x00;
567 cmd.arg[2] = 0x03;
568 cmd.arg[3] = 0x16;
569 cmd.arg[4] = 0x28;
570 cmd.arg[5] = 0x01;
571 cmd.arg[6] = 0x01;
572 cmd.arg[7] = 0x14;
573 cmd.arg[8] = 0x19;
574 cmd.arg[9] = 0x14;
575 cmd.arg[10] = 0x1e;
576
577 if (cx24120_message_send(state, &cmd)) {
578 err("send 1st message(0x%x) failed\n", cmd.id);
579 return -EREMOTEIO;
580 }
581
582 cmd.id = CMD_DISEQC_MSG2;
583 cmd.len = d->msg_len + 6;
584 cmd.arg[0] = 0x00;
585 cmd.arg[1] = 0x01;
586 cmd.arg[2] = 0x02;
587 cmd.arg[3] = 0x00;
588 cmd.arg[4] = 0x00;
589 cmd.arg[5] = d->msg_len;
590
591 memcpy(&cmd.arg[6], &d->msg, d->msg_len);
592
593 if (cx24120_message_send(state, &cmd)) {
594 err("send 2nd message(0x%x) failed\n", cmd.id);
595 return -EREMOTEIO;
596 }
597
598 back_count = 500;
599 do {
600 if (!(cx24120_readreg(state, 0x93) & 0x01)) {
601 dev_dbg(&state->i2c->dev, "diseqc sequence sent\n");
602 return 0;
603 }
604 msleep(20);
605 back_count -= 20;
606 } while (back_count);
607
608 err("Too long waiting for diseqc.\n");
609 return -ETIMEDOUT;
610}
611
612static void cx24120_get_stats(struct cx24120_state *state)
613{
614 struct dvb_frontend *fe = &state->frontend;
615 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
616 struct cx24120_cmd cmd;
617 int ret, cnr, msecs;
618 u16 sig, ucb;
619 u32 ber;
620
621 dev_dbg(&state->i2c->dev, "\n");
622
623 /* signal strength */
624 if (state->fe_status & FE_HAS_SIGNAL) {
625 cmd.id = CMD_READ_SNR;
626 cmd.len = 1;
627 cmd.arg[0] = 0x00;
628
629 ret = cx24120_message_send(state, &cmd);
630 if (ret != 0) {
631 err("error reading signal strength\n");
632 return;
633 }
634
635 /* raw */
636 sig = cx24120_readreg(state, CX24120_REG_SIGSTR_H) >> 6;
637 sig = sig << 8;
638 sig |= cx24120_readreg(state, CX24120_REG_SIGSTR_L);
639 dev_dbg(&state->i2c->dev,
640 "signal strength from firmware = 0x%x\n", sig);
641
642 /* cooked */
643 sig = -100 * sig + 94324;
644
645 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
646 c->strength.stat[0].uvalue = sig;
647 } else {
648 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
649 }
650
651 /* CNR */
652 if (state->fe_status & FE_HAS_VITERBI) {
653 cnr = cx24120_readreg(state, CX24120_REG_QUALITY_H) << 8;
654 cnr |= cx24120_readreg(state, CX24120_REG_QUALITY_L);
655 dev_dbg(&state->i2c->dev, "read SNR index = %d\n", cnr);
656
657 /* guessed - seems about right */
658 cnr = cnr * 100;
659
660 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
661 c->cnr.stat[0].svalue = cnr;
662 } else {
663 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
664 }
665
666 /* BER & UCB require lock */
667 if (!(state->fe_status & FE_HAS_LOCK)) {
668 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
669 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
670 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
671 c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
672 return;
673 }
674
675 /* BER */
676 if (time_after(jiffies, state->ber_jiffies_stats)) {
677 msecs = (state->berw_usecs + 500) / 1000;
678 state->ber_jiffies_stats = jiffies + msecs_to_jiffies(msecs);
679
680 ber = cx24120_readreg(state, CX24120_REG_BER_HH) << 24;
681 ber |= cx24120_readreg(state, CX24120_REG_BER_HL) << 16;
682 ber |= cx24120_readreg(state, CX24120_REG_BER_LH) << 8;
683 ber |= cx24120_readreg(state, CX24120_REG_BER_LL);
684 dev_dbg(&state->i2c->dev, "read BER index = %d\n", ber);
685
686 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
687 c->post_bit_error.stat[0].uvalue += ber;
688
689 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
690 c->post_bit_count.stat[0].uvalue += CX24120_BER_WSIZE;
691 }
692
693 /* UCB */
694 if (time_after(jiffies, state->per_jiffies_stats)) {
695 state->per_jiffies_stats = jiffies + msecs_to_jiffies(1000);
696
697 ucb = cx24120_readreg(state, CX24120_REG_UCB_H) << 8;
698 ucb |= cx24120_readreg(state, CX24120_REG_UCB_L);
699 dev_dbg(&state->i2c->dev, "ucblocks = %d\n", ucb);
700
701 /* handle reset */
702 if (ucb < state->ucb_offset)
703 state->ucb_offset = c->block_error.stat[0].uvalue;
704
705 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
706 c->block_error.stat[0].uvalue = ucb + state->ucb_offset;
707
708 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
709 c->block_count.stat[0].uvalue += state->bitrate / 8 / 208;
710 }
711}
712
713static void cx24120_set_clock_ratios(struct dvb_frontend *fe);
714
715/* Read current tuning status */
716static int cx24120_read_status(struct dvb_frontend *fe, enum fe_status *status)
717{
718 struct cx24120_state *state = fe->demodulator_priv;
719 int lock;
720
721 lock = cx24120_readreg(state, CX24120_REG_STATUS);
722
723 dev_dbg(&state->i2c->dev, "status = 0x%02x\n", lock);
724
725 *status = 0;
726
727 if (lock & CX24120_HAS_SIGNAL)
728 *status = FE_HAS_SIGNAL;
729 if (lock & CX24120_HAS_CARRIER)
730 *status |= FE_HAS_CARRIER;
731 if (lock & CX24120_HAS_VITERBI)
732 *status |= FE_HAS_VITERBI | FE_HAS_SYNC;
733 if (lock & CX24120_HAS_LOCK)
734 *status |= FE_HAS_LOCK;
735
736 /*
737 * TODO: is FE_HAS_SYNC in the right place?
738 * Other cx241xx drivers have this slightly
739 * different
740 */
741
742 state->fe_status = *status;
743 cx24120_get_stats(state);
744
745 /* Set the clock once tuned in */
746 if (state->need_clock_set && *status & FE_HAS_LOCK) {
747 /* Set clock ratios */
748 cx24120_set_clock_ratios(fe);
749
750 /* Old driver would do a msleep(200) here */
751
752 /* Renable mpeg output */
753 if (!state->mpeg_enabled)
754 cx24120_msg_mpeg_output_global_config(state, 1);
755
756 state->need_clock_set = 0;
757 }
758
759 return 0;
760}
761
762/*
763 * FEC & modulation lookup table
764 * Used for decoding the REG_FECMODE register
765 * once tuned in.
766 */
767struct cx24120_modfec {
768 enum fe_delivery_system delsys;
769 enum fe_modulation mod;
770 enum fe_code_rate fec;
771 u8 val;
772};
773
774static const struct cx24120_modfec modfec_lookup_table[] = {
775 /*delsys mod fec val */
776 { SYS_DVBS, QPSK, FEC_1_2, 0x01 },
777 { SYS_DVBS, QPSK, FEC_2_3, 0x02 },
778 { SYS_DVBS, QPSK, FEC_3_4, 0x03 },
779 { SYS_DVBS, QPSK, FEC_4_5, 0x04 },
780 { SYS_DVBS, QPSK, FEC_5_6, 0x05 },
781 { SYS_DVBS, QPSK, FEC_6_7, 0x06 },
782 { SYS_DVBS, QPSK, FEC_7_8, 0x07 },
783
784 { SYS_DVBS2, QPSK, FEC_1_2, 0x04 },
785 { SYS_DVBS2, QPSK, FEC_3_5, 0x05 },
786 { SYS_DVBS2, QPSK, FEC_2_3, 0x06 },
787 { SYS_DVBS2, QPSK, FEC_3_4, 0x07 },
788 { SYS_DVBS2, QPSK, FEC_4_5, 0x08 },
789 { SYS_DVBS2, QPSK, FEC_5_6, 0x09 },
790 { SYS_DVBS2, QPSK, FEC_8_9, 0x0a },
791 { SYS_DVBS2, QPSK, FEC_9_10, 0x0b },
792
793 { SYS_DVBS2, PSK_8, FEC_3_5, 0x0c },
794 { SYS_DVBS2, PSK_8, FEC_2_3, 0x0d },
795 { SYS_DVBS2, PSK_8, FEC_3_4, 0x0e },
796 { SYS_DVBS2, PSK_8, FEC_5_6, 0x0f },
797 { SYS_DVBS2, PSK_8, FEC_8_9, 0x10 },
798 { SYS_DVBS2, PSK_8, FEC_9_10, 0x11 },
799};
800
801/* Retrieve current fec, modulation & pilot values */
802static int cx24120_get_fec(struct dvb_frontend *fe)
803{
804 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
805 struct cx24120_state *state = fe->demodulator_priv;
806 int idx;
807 int ret;
808 int fec;
809
810 ret = cx24120_readreg(state, CX24120_REG_FECMODE);
811 fec = ret & 0x3f; /* Lower 6 bits */
812
813 dev_dbg(&state->i2c->dev, "raw fec = %d\n", fec);
814
815 for (idx = 0; idx < ARRAY_SIZE(modfec_lookup_table); idx++) {
816 if (modfec_lookup_table[idx].delsys != state->dcur.delsys)
817 continue;
818 if (modfec_lookup_table[idx].val != fec)
819 continue;
820
821 break; /* found */
822 }
823
824 if (idx >= ARRAY_SIZE(modfec_lookup_table)) {
825 dev_dbg(&state->i2c->dev, "couldn't find fec!\n");
826 return -EINVAL;
827 }
828
829 /* save values back to cache */
830 c->modulation = modfec_lookup_table[idx].mod;
831 c->fec_inner = modfec_lookup_table[idx].fec;
832 c->pilot = (ret & 0x80) ? PILOT_ON : PILOT_OFF;
833
834 dev_dbg(&state->i2c->dev, "mod(%d), fec(%d), pilot(%d)\n",
835 c->modulation, c->fec_inner, c->pilot);
836
837 return 0;
838}
839
840/* Calculate ber window time */
841static void cx24120_calculate_ber_window(struct cx24120_state *state, u32 rate)
842{
843 struct dvb_frontend *fe = &state->frontend;
844 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
845 u64 tmp;
846
847 /*
848 * Calculate bitrate from rate in the clock ratios table.
849 * This isn't *exactly* right but close enough.
850 */
851 tmp = (u64)c->symbol_rate * rate;
852 do_div(tmp, 256);
853 state->bitrate = tmp;
854
855 /* usecs per ber window */
856 tmp = 1000000ULL * CX24120_BER_WSIZE;
857 do_div(tmp, state->bitrate);
858 state->berw_usecs = tmp;
859
860 dev_dbg(&state->i2c->dev, "bitrate: %u, berw_usecs: %u\n",
861 state->bitrate, state->berw_usecs);
862}
863
864/*
865 * Clock ratios lookup table
866 *
867 * Values obtained from much larger table in old driver
868 * which had numerous entries which would never match.
869 *
870 * There's probably some way of calculating these but I
871 * can't determine the pattern
872 */
873struct cx24120_clock_ratios_table {
874 enum fe_delivery_system delsys;
875 enum fe_pilot pilot;
876 enum fe_modulation mod;
877 enum fe_code_rate fec;
878 u32 m_rat;
879 u32 n_rat;
880 u32 rate;
881};
882
883static const struct cx24120_clock_ratios_table clock_ratios_table[] = {
884 /*delsys pilot mod fec m_rat n_rat rate */
885 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_1_2, 273088, 254505, 274 },
886 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_3_5, 17272, 13395, 330 },
887 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_2_3, 24344, 16967, 367 },
888 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_3_4, 410788, 254505, 413 },
889 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_4_5, 438328, 254505, 440 },
890 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_5_6, 30464, 16967, 459 },
891 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_8_9, 487832, 254505, 490 },
892 { SYS_DVBS2, PILOT_OFF, QPSK, FEC_9_10, 493952, 254505, 496 },
893 { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_3_5, 328168, 169905, 494 },
894 { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_2_3, 24344, 11327, 550 },
895 { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_3_4, 410788, 169905, 618 },
896 { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_5_6, 30464, 11327, 688 },
897 { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_8_9, 487832, 169905, 735 },
898 { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_9_10, 493952, 169905, 744 },
899 { SYS_DVBS2, PILOT_ON, QPSK, FEC_1_2, 273088, 260709, 268 },
900 { SYS_DVBS2, PILOT_ON, QPSK, FEC_3_5, 328168, 260709, 322 },
901 { SYS_DVBS2, PILOT_ON, QPSK, FEC_2_3, 121720, 86903, 358 },
902 { SYS_DVBS2, PILOT_ON, QPSK, FEC_3_4, 410788, 260709, 403 },
903 { SYS_DVBS2, PILOT_ON, QPSK, FEC_4_5, 438328, 260709, 430 },
904 { SYS_DVBS2, PILOT_ON, QPSK, FEC_5_6, 152320, 86903, 448 },
905 { SYS_DVBS2, PILOT_ON, QPSK, FEC_8_9, 487832, 260709, 479 },
906 { SYS_DVBS2, PILOT_ON, QPSK, FEC_9_10, 493952, 260709, 485 },
907 { SYS_DVBS2, PILOT_ON, PSK_8, FEC_3_5, 328168, 173853, 483 },
908 { SYS_DVBS2, PILOT_ON, PSK_8, FEC_2_3, 121720, 57951, 537 },
909 { SYS_DVBS2, PILOT_ON, PSK_8, FEC_3_4, 410788, 173853, 604 },
910 { SYS_DVBS2, PILOT_ON, PSK_8, FEC_5_6, 152320, 57951, 672 },
911 { SYS_DVBS2, PILOT_ON, PSK_8, FEC_8_9, 487832, 173853, 718 },
912 { SYS_DVBS2, PILOT_ON, PSK_8, FEC_9_10, 493952, 173853, 727 },
913 { SYS_DVBS, PILOT_OFF, QPSK, FEC_1_2, 152592, 152592, 256 },
914 { SYS_DVBS, PILOT_OFF, QPSK, FEC_2_3, 305184, 228888, 341 },
915 { SYS_DVBS, PILOT_OFF, QPSK, FEC_3_4, 457776, 305184, 384 },
916 { SYS_DVBS, PILOT_OFF, QPSK, FEC_5_6, 762960, 457776, 427 },
917 { SYS_DVBS, PILOT_OFF, QPSK, FEC_7_8, 1068144, 610368, 448 },
918};
919
920/* Set clock ratio from lookup table */
921static void cx24120_set_clock_ratios(struct dvb_frontend *fe)
922{
923 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
924 struct cx24120_state *state = fe->demodulator_priv;
925 struct cx24120_cmd cmd;
926 int ret, idx;
927
928 /* Find fec, modulation, pilot */
929 ret = cx24120_get_fec(fe);
930 if (ret != 0)
931 return;
932
933 /* Find the clock ratios in the lookup table */
934 for (idx = 0; idx < ARRAY_SIZE(clock_ratios_table); idx++) {
935 if (clock_ratios_table[idx].delsys != state->dcur.delsys)
936 continue;
937 if (clock_ratios_table[idx].mod != c->modulation)
938 continue;
939 if (clock_ratios_table[idx].fec != c->fec_inner)
940 continue;
941 if (clock_ratios_table[idx].pilot != c->pilot)
942 continue;
943
944 break; /* found */
945 }
946
947 if (idx >= ARRAY_SIZE(clock_ratios_table)) {
948 info("Clock ratio not found - data reception in danger\n");
949 return;
950 }
951
952 /* Read current values? */
953 cmd.id = CMD_CLOCK_READ;
954 cmd.len = 1;
955 cmd.arg[0] = 0x00;
956 ret = cx24120_message_sendrcv(state, &cmd, 6);
957 if (ret != 0)
958 return;
959 /* in cmd[0]-[5] - result */
960
961 dev_dbg(&state->i2c->dev, "m=%d, n=%d; idx: %d m=%d, n=%d, rate=%d\n",
962 cmd.arg[2] | (cmd.arg[1] << 8) | (cmd.arg[0] << 16),
963 cmd.arg[5] | (cmd.arg[4] << 8) | (cmd.arg[3] << 16),
964 idx,
965 clock_ratios_table[idx].m_rat,
966 clock_ratios_table[idx].n_rat,
967 clock_ratios_table[idx].rate);
968
969 /* Set the clock */
970 cmd.id = CMD_CLOCK_SET;
971 cmd.len = 10;
972 cmd.arg[0] = 0;
973 cmd.arg[1] = 0x10;
974 cmd.arg[2] = (clock_ratios_table[idx].m_rat >> 16) & 0xff;
975 cmd.arg[3] = (clock_ratios_table[idx].m_rat >> 8) & 0xff;
976 cmd.arg[4] = (clock_ratios_table[idx].m_rat >> 0) & 0xff;
977 cmd.arg[5] = (clock_ratios_table[idx].n_rat >> 16) & 0xff;
978 cmd.arg[6] = (clock_ratios_table[idx].n_rat >> 8) & 0xff;
979 cmd.arg[7] = (clock_ratios_table[idx].n_rat >> 0) & 0xff;
980 cmd.arg[8] = (clock_ratios_table[idx].rate >> 8) & 0xff;
981 cmd.arg[9] = (clock_ratios_table[idx].rate >> 0) & 0xff;
982
983 cx24120_message_send(state, &cmd);
984
985 /* Calculate ber window rates for stat work */
986 cx24120_calculate_ber_window(state, clock_ratios_table[idx].rate);
987}
988
989/* Set inversion value */
990static int cx24120_set_inversion(struct cx24120_state *state,
991 enum fe_spectral_inversion inversion)
992{
993 dev_dbg(&state->i2c->dev, "(%d)\n", inversion);
994
995 switch (inversion) {
996 case INVERSION_OFF:
997 state->dnxt.inversion_val = 0x00;
998 break;
999 case INVERSION_ON:
1000 state->dnxt.inversion_val = 0x04;
1001 break;
1002 case INVERSION_AUTO:
1003 state->dnxt.inversion_val = 0x0c;
1004 break;
1005 default:
1006 return -EINVAL;
1007 }
1008
1009 state->dnxt.inversion = inversion;
1010
1011 return 0;
1012}
1013
1014/* FEC lookup table for tuning */
1015struct cx24120_modfec_table {
1016 enum fe_delivery_system delsys;
1017 enum fe_modulation mod;
1018 enum fe_code_rate fec;
1019 u8 val;
1020};
1021
1022static const struct cx24120_modfec_table modfec_table[] = {
1023 /*delsys mod fec val */
1024 { SYS_DVBS, QPSK, FEC_1_2, 0x2e },
1025 { SYS_DVBS, QPSK, FEC_2_3, 0x2f },
1026 { SYS_DVBS, QPSK, FEC_3_4, 0x30 },
1027 { SYS_DVBS, QPSK, FEC_5_6, 0x31 },
1028 { SYS_DVBS, QPSK, FEC_6_7, 0x32 },
1029 { SYS_DVBS, QPSK, FEC_7_8, 0x33 },
1030
1031 { SYS_DVBS2, QPSK, FEC_1_2, 0x04 },
1032 { SYS_DVBS2, QPSK, FEC_3_5, 0x05 },
1033 { SYS_DVBS2, QPSK, FEC_2_3, 0x06 },
1034 { SYS_DVBS2, QPSK, FEC_3_4, 0x07 },
1035 { SYS_DVBS2, QPSK, FEC_4_5, 0x08 },
1036 { SYS_DVBS2, QPSK, FEC_5_6, 0x09 },
1037 { SYS_DVBS2, QPSK, FEC_8_9, 0x0a },
1038 { SYS_DVBS2, QPSK, FEC_9_10, 0x0b },
1039
1040 { SYS_DVBS2, PSK_8, FEC_3_5, 0x0c },
1041 { SYS_DVBS2, PSK_8, FEC_2_3, 0x0d },
1042 { SYS_DVBS2, PSK_8, FEC_3_4, 0x0e },
1043 { SYS_DVBS2, PSK_8, FEC_5_6, 0x0f },
1044 { SYS_DVBS2, PSK_8, FEC_8_9, 0x10 },
1045 { SYS_DVBS2, PSK_8, FEC_9_10, 0x11 },
1046};
1047
1048/* Set fec_val & fec_mask values from delsys, modulation & fec */
1049static int cx24120_set_fec(struct cx24120_state *state, enum fe_modulation mod,
1050 enum fe_code_rate fec)
1051{
1052 int idx;
1053
1054 dev_dbg(&state->i2c->dev, "(0x%02x,0x%02x)\n", mod, fec);
1055
1056 state->dnxt.fec = fec;
1057
1058 /* Lookup fec_val from modfec table */
1059 for (idx = 0; idx < ARRAY_SIZE(modfec_table); idx++) {
1060 if (modfec_table[idx].delsys != state->dnxt.delsys)
1061 continue;
1062 if (modfec_table[idx].mod != mod)
1063 continue;
1064 if (modfec_table[idx].fec != fec)
1065 continue;
1066
1067 /* found */
1068 state->dnxt.fec_mask = 0x00;
1069 state->dnxt.fec_val = modfec_table[idx].val;
1070 return 0;
1071 }
1072
1073 if (state->dnxt.delsys == SYS_DVBS2) {
1074 /* DVBS2 auto is 0x00/0x00 */
1075 state->dnxt.fec_mask = 0x00;
1076 state->dnxt.fec_val = 0x00;
1077 } else {
1078 /* Set DVB-S to auto */
1079 state->dnxt.fec_val = 0x2e;
1080 state->dnxt.fec_mask = 0xac;
1081 }
1082
1083 return 0;
1084}
1085
1086/* Set pilot */
1087static int cx24120_set_pilot(struct cx24120_state *state, enum fe_pilot pilot)
1088{
1089 dev_dbg(&state->i2c->dev, "(%d)\n", pilot);
1090
1091 /* Pilot only valid in DVBS2 */
1092 if (state->dnxt.delsys != SYS_DVBS2) {
1093 state->dnxt.pilot_val = CX24120_PILOT_OFF;
1094 return 0;
1095 }
1096
1097 switch (pilot) {
1098 case PILOT_OFF:
1099 state->dnxt.pilot_val = CX24120_PILOT_OFF;
1100 break;
1101 case PILOT_ON:
1102 state->dnxt.pilot_val = CX24120_PILOT_ON;
1103 break;
1104 case PILOT_AUTO:
1105 default:
1106 state->dnxt.pilot_val = CX24120_PILOT_AUTO;
1107 }
1108
1109 return 0;
1110}
1111
1112/* Set symbol rate */
1113static int cx24120_set_symbolrate(struct cx24120_state *state, u32 rate)
1114{
1115 dev_dbg(&state->i2c->dev, "(%d)\n", rate);
1116
1117 state->dnxt.symbol_rate = rate;
1118
1119 /* Check symbol rate */
1120 if (rate > 31000000) {
1121 state->dnxt.clkdiv = (-(rate < 31000001) & 3) + 2;
1122 state->dnxt.ratediv = (-(rate < 31000001) & 6) + 4;
1123 } else {
1124 state->dnxt.clkdiv = 3;
1125 state->dnxt.ratediv = 6;
1126 }
1127
1128 return 0;
1129}
1130
1131/* Overwrite the current tuning params, we are about to tune */
1132static void cx24120_clone_params(struct dvb_frontend *fe)
1133{
1134 struct cx24120_state *state = fe->demodulator_priv;
1135
1136 state->dcur = state->dnxt;
1137}
1138
1139static int cx24120_set_frontend(struct dvb_frontend *fe)
1140{
1141 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1142 struct cx24120_state *state = fe->demodulator_priv;
1143 struct cx24120_cmd cmd;
1144 int ret;
1145
1146 switch (c->delivery_system) {
1147 case SYS_DVBS2:
1148 dev_dbg(&state->i2c->dev, "DVB-S2\n");
1149 break;
1150 case SYS_DVBS:
1151 dev_dbg(&state->i2c->dev, "DVB-S\n");
1152 break;
1153 default:
1154 dev_dbg(&state->i2c->dev,
1155 "delivery system(%d) not supported\n",
1156 c->delivery_system);
1157 ret = -EINVAL;
1158 break;
1159 }
1160
1161 state->dnxt.delsys = c->delivery_system;
1162 state->dnxt.modulation = c->modulation;
1163 state->dnxt.frequency = c->frequency;
1164 state->dnxt.pilot = c->pilot;
1165
1166 ret = cx24120_set_inversion(state, c->inversion);
1167 if (ret != 0)
1168 return ret;
1169
1170 ret = cx24120_set_fec(state, c->modulation, c->fec_inner);
1171 if (ret != 0)
1172 return ret;
1173
1174 ret = cx24120_set_pilot(state, c->pilot);
1175 if (ret != 0)
1176 return ret;
1177
1178 ret = cx24120_set_symbolrate(state, c->symbol_rate);
1179 if (ret != 0)
1180 return ret;
1181
1182 /* discard the 'current' tuning parameters and prepare to tune */
1183 cx24120_clone_params(fe);
1184
1185 dev_dbg(&state->i2c->dev,
1186 "delsys = %d\n", state->dcur.delsys);
1187 dev_dbg(&state->i2c->dev,
1188 "modulation = %d\n", state->dcur.modulation);
1189 dev_dbg(&state->i2c->dev,
1190 "frequency = %d\n", state->dcur.frequency);
1191 dev_dbg(&state->i2c->dev,
1192 "pilot = %d (val = 0x%02x)\n",
1193 state->dcur.pilot, state->dcur.pilot_val);
1194 dev_dbg(&state->i2c->dev,
1195 "symbol_rate = %d (clkdiv/ratediv = 0x%02x/0x%02x)\n",
1196 state->dcur.symbol_rate,
1197 state->dcur.clkdiv, state->dcur.ratediv);
1198 dev_dbg(&state->i2c->dev,
1199 "FEC = %d (mask/val = 0x%02x/0x%02x)\n",
1200 state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
1201 dev_dbg(&state->i2c->dev,
1202 "Inversion = %d (val = 0x%02x)\n",
1203 state->dcur.inversion, state->dcur.inversion_val);
1204
1205 /* Flag that clock needs to be set after tune */
1206 state->need_clock_set = 1;
1207
1208 /* Tune in */
1209 cmd.id = CMD_TUNEREQUEST;
1210 cmd.len = 15;
1211 cmd.arg[0] = 0;
1212 cmd.arg[1] = (state->dcur.frequency & 0xff0000) >> 16;
1213 cmd.arg[2] = (state->dcur.frequency & 0x00ff00) >> 8;
1214 cmd.arg[3] = (state->dcur.frequency & 0x0000ff);
1215 cmd.arg[4] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;
1216 cmd.arg[5] = ((state->dcur.symbol_rate / 1000) & 0x00ff);
1217 cmd.arg[6] = state->dcur.inversion;
1218 cmd.arg[7] = state->dcur.fec_val | state->dcur.pilot_val;
1219 cmd.arg[8] = CX24120_SEARCH_RANGE_KHZ >> 8;
1220 cmd.arg[9] = CX24120_SEARCH_RANGE_KHZ & 0xff;
1221 cmd.arg[10] = 0; /* maybe rolloff? */
1222 cmd.arg[11] = state->dcur.fec_mask;
1223 cmd.arg[12] = state->dcur.ratediv;
1224 cmd.arg[13] = state->dcur.clkdiv;
1225 cmd.arg[14] = 0;
1226
1227 /* Send tune command */
1228 ret = cx24120_message_send(state, &cmd);
1229 if (ret != 0)
1230 return ret;
1231
1232 /* Write symbol rate values */
1233 ret = cx24120_writereg(state, CX24120_REG_CLKDIV, state->dcur.clkdiv);
1234 ret = cx24120_readreg(state, CX24120_REG_RATEDIV);
1235 ret &= 0xfffffff0;
1236 ret |= state->dcur.ratediv;
1237 ret = cx24120_writereg(state, CX24120_REG_RATEDIV, ret);
1238
1239 return 0;
1240}
1241
1242/* Set vco from config */
1243static int cx24120_set_vco(struct cx24120_state *state)
1244{
1245 struct cx24120_cmd cmd;
1246 u32 nxtal_khz, vco;
1247 u64 inv_vco;
1248 u32 xtal_khz = state->config->xtal_khz;
1249
1250 nxtal_khz = xtal_khz * 4;
1251 vco = nxtal_khz * 10;
1252 inv_vco = DIV_ROUND_CLOSEST_ULL(0x400000000ULL, vco);
1253
1254 dev_dbg(&state->i2c->dev, "xtal=%d, vco=%d, inv_vco=%lld\n",
1255 xtal_khz, vco, inv_vco);
1256
1257 cmd.id = CMD_VCO_SET;
1258 cmd.len = 12;
1259 cmd.arg[0] = (vco >> 16) & 0xff;
1260 cmd.arg[1] = (vco >> 8) & 0xff;
1261 cmd.arg[2] = vco & 0xff;
1262 cmd.arg[3] = (inv_vco >> 8) & 0xff;
1263 cmd.arg[4] = (inv_vco) & 0xff;
1264 cmd.arg[5] = 0x03;
1265 cmd.arg[6] = (nxtal_khz >> 8) & 0xff;
1266 cmd.arg[7] = nxtal_khz & 0xff;
1267 cmd.arg[8] = 0x06;
1268 cmd.arg[9] = 0x03;
1269 cmd.arg[10] = (xtal_khz >> 16) & 0xff;
1270 cmd.arg[11] = xtal_khz & 0xff;
1271
1272 return cx24120_message_send(state, &cmd);
1273}
1274
1275static int cx24120_init(struct dvb_frontend *fe)
1276{
1277 const struct firmware *fw;
1278 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1279 struct cx24120_state *state = fe->demodulator_priv;
1280 struct cx24120_cmd cmd;
1281 u8 reg;
1282 int ret, i;
1283 unsigned char vers[4];
1284
1285 if (state->cold_init)
1286 return 0;
1287
1288 /* ???? */
1289 cx24120_writereg(state, 0xea, 0x00);
1290 cx24120_test_rom(state);
1291 reg = cx24120_readreg(state, 0xfb) & 0xfe;
1292 cx24120_writereg(state, 0xfb, reg);
1293 reg = cx24120_readreg(state, 0xfc) & 0xfe;
1294 cx24120_writereg(state, 0xfc, reg);
1295 cx24120_writereg(state, 0xc3, 0x04);
1296 cx24120_writereg(state, 0xc4, 0x04);
1297 cx24120_writereg(state, 0xce, 0x00);
1298 cx24120_writereg(state, 0xcf, 0x00);
1299 reg = cx24120_readreg(state, 0xea) & 0xfe;
1300 cx24120_writereg(state, 0xea, reg);
1301 cx24120_writereg(state, 0xeb, 0x0c);
1302 cx24120_writereg(state, 0xec, 0x06);
1303 cx24120_writereg(state, 0xed, 0x05);
1304 cx24120_writereg(state, 0xee, 0x03);
1305 cx24120_writereg(state, 0xef, 0x05);
1306 cx24120_writereg(state, 0xf3, 0x03);
1307 cx24120_writereg(state, 0xf4, 0x44);
1308
1309 for (i = 0; i < 3; i++) {
1310 cx24120_writereg(state, 0xf0 + i, 0x04);
1311 cx24120_writereg(state, 0xe6 + i, 0x02);
1312 }
1313
1314 cx24120_writereg(state, 0xea, (reg | 0x01));
1315 for (i = 0; i < 6; i += 2) {
1316 cx24120_writereg(state, 0xc5 + i, 0x00);
1317 cx24120_writereg(state, 0xc6 + i, 0x00);
1318 }
1319
1320 cx24120_writereg(state, 0xe4, 0x03);
1321 cx24120_writereg(state, 0xeb, 0x0a);
1322
1323 dev_dbg(&state->i2c->dev, "requesting firmware (%s) to download...\n",
1324 CX24120_FIRMWARE);
1325
1326 ret = state->config->request_firmware(fe, &fw, CX24120_FIRMWARE);
1327 if (ret) {
1328 err("Could not load firmware (%s): %d\n", CX24120_FIRMWARE,
1329 ret);
1330 return ret;
1331 }
1332
1333 dev_dbg(&state->i2c->dev,
1334 "Firmware found, size %d bytes (%02x %02x .. %02x %02x)\n",
1335 (int)fw->size, /* firmware_size in bytes */
1336 fw->data[0], /* fw 1st byte */
1337 fw->data[1], /* fw 2d byte */
1338 fw->data[fw->size - 2], /* fw before last byte */
1339 fw->data[fw->size - 1]); /* fw last byte */
1340
1341 cx24120_test_rom(state);
1342 reg = cx24120_readreg(state, 0xfb) & 0xfe;
1343 cx24120_writereg(state, 0xfb, reg);
1344 cx24120_writereg(state, 0xe0, 0x76);
1345 cx24120_writereg(state, 0xf7, 0x81);
1346 cx24120_writereg(state, 0xf8, 0x00);
1347 cx24120_writereg(state, 0xf9, 0x00);
1348 cx24120_writeregs(state, 0xfa, fw->data, (fw->size - 1), 0x00);
1349 cx24120_writereg(state, 0xf7, 0xc0);
1350 cx24120_writereg(state, 0xe0, 0x00);
1351 reg = (fw->size - 2) & 0x00ff;
1352 cx24120_writereg(state, 0xf8, reg);
1353 reg = ((fw->size - 2) >> 8) & 0x00ff;
1354 cx24120_writereg(state, 0xf9, reg);
1355 cx24120_writereg(state, 0xf7, 0x00);
1356 cx24120_writereg(state, 0xdc, 0x00);
1357 cx24120_writereg(state, 0xdc, 0x07);
1358 msleep(500);
1359
1360 /* Check final byte matches final byte of firmware */
1361 reg = cx24120_readreg(state, 0xe1);
1362 if (reg == fw->data[fw->size - 1]) {
1363 dev_dbg(&state->i2c->dev, "Firmware uploaded successfully\n");
1364 ret = 0;
1365 } else {
1366 err("Firmware upload failed. Last byte returned=0x%x\n", ret);
1367 ret = -EREMOTEIO;
1368 }
1369 cx24120_writereg(state, 0xdc, 0x00);
1370 release_firmware(fw);
1371 if (ret != 0)
1372 return ret;
1373
1374 /* Start tuner */
1375 cmd.id = CMD_START_TUNER;
1376 cmd.len = 3;
1377 cmd.arg[0] = 0x00;
1378 cmd.arg[1] = 0x00;
1379 cmd.arg[2] = 0x00;
1380
1381 if (cx24120_message_send(state, &cmd) != 0) {
1382 err("Error tuner start! :(\n");
1383 return -EREMOTEIO;
1384 }
1385
1386 /* Set VCO */
1387 ret = cx24120_set_vco(state);
1388 if (ret != 0) {
1389 err("Error set VCO! :(\n");
1390 return ret;
1391 }
1392
1393 /* set bandwidth */
1394 cmd.id = CMD_BANDWIDTH;
1395 cmd.len = 12;
1396 cmd.arg[0] = 0x00;
1397 cmd.arg[1] = 0x00;
1398 cmd.arg[2] = 0x00;
1399 cmd.arg[3] = 0x00;
1400 cmd.arg[4] = 0x05;
1401 cmd.arg[5] = 0x02;
1402 cmd.arg[6] = 0x02;
1403 cmd.arg[7] = 0x00;
1404 cmd.arg[8] = 0x05;
1405 cmd.arg[9] = 0x02;
1406 cmd.arg[10] = 0x02;
1407 cmd.arg[11] = 0x00;
1408
1409 if (cx24120_message_send(state, &cmd)) {
1410 err("Error set bandwidth!\n");
1411 return -EREMOTEIO;
1412 }
1413
1414 reg = cx24120_readreg(state, 0xba);
1415 if (reg > 3) {
1416 dev_dbg(&state->i2c->dev, "Reset-readreg 0xba: %x\n", ret);
1417 err("Error initialising tuner!\n");
1418 return -EREMOTEIO;
1419 }
1420
1421 dev_dbg(&state->i2c->dev, "Tuner initialised correctly.\n");
1422
1423 /* Initialise mpeg outputs */
1424 cx24120_writereg(state, 0xeb, 0x0a);
1425 if (cx24120_msg_mpeg_output_global_config(state, 0) ||
1426 cx24120_msg_mpeg_output_config(state, 0) ||
1427 cx24120_msg_mpeg_output_config(state, 1) ||
1428 cx24120_msg_mpeg_output_config(state, 2)) {
1429 err("Error initialising mpeg output. :(\n");
1430 return -EREMOTEIO;
1431 }
1432
1433 /* Set size of BER window */
1434 cmd.id = CMD_BER_CTRL;
1435 cmd.len = 3;
1436 cmd.arg[0] = 0x00;
1437 cmd.arg[1] = CX24120_BER_WINDOW;
1438 cmd.arg[2] = CX24120_BER_WINDOW;
1439 if (cx24120_message_send(state, &cmd)) {
1440 err("Error setting ber window\n");
1441 return -EREMOTEIO;
1442 }
1443
1444 /* Firmware CMD 35: Get firmware version */
1445 cmd.id = CMD_FWVERSION;
1446 cmd.len = 1;
1447 for (i = 0; i < 4; i++) {
1448 cmd.arg[0] = i;
1449 ret = cx24120_message_send(state, &cmd);
1450 if (ret != 0)
1451 return ret;
1452 vers[i] = cx24120_readreg(state, CX24120_REG_MAILBOX);
1453 }
1454 info("FW version %i.%i.%i.%i\n", vers[0], vers[1], vers[2], vers[3]);
1455
1456 /* init stats here in order signal app which stats are supported */
1457 c->strength.len = 1;
1458 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1459 c->cnr.len = 1;
1460 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1461 c->post_bit_error.len = 1;
1462 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1463 c->post_bit_count.len = 1;
1464 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1465 c->block_error.len = 1;
1466 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1467 c->block_count.len = 1;
1468 c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1469
1470 state->cold_init = 1;
1471
1472 return 0;
1473}
1474
1475static int cx24120_tune(struct dvb_frontend *fe, bool re_tune,
1476 unsigned int mode_flags, unsigned int *delay,
1477 enum fe_status *status)
1478{
1479 struct cx24120_state *state = fe->demodulator_priv;
1480 int ret;
1481
1482 dev_dbg(&state->i2c->dev, "(%d)\n", re_tune);
1483
1484 /* TODO: Do we need to set delay? */
1485
1486 if (re_tune) {
1487 ret = cx24120_set_frontend(fe);
1488 if (ret)
1489 return ret;
1490 }
1491
1492 return cx24120_read_status(fe, status);
1493}
1494
1495static int cx24120_get_algo(struct dvb_frontend *fe)
1496{
1497 return DVBFE_ALGO_HW;
1498}
1499
1500static int cx24120_sleep(struct dvb_frontend *fe)
1501{
1502 return 0;
1503}
1504
1505static int cx24120_get_frontend(struct dvb_frontend *fe)
1506{
1507 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1508 struct cx24120_state *state = fe->demodulator_priv;
1509 u8 freq1, freq2, freq3;
1510
1511 dev_dbg(&state->i2c->dev, "\n");
1512
1513 /* don't return empty data if we're not tuned in */
1514 if ((state->fe_status & FE_HAS_LOCK) == 0)
1515 return 0;
1516
1517 /* Get frequency */
1518 freq1 = cx24120_readreg(state, CX24120_REG_FREQ1);
1519 freq2 = cx24120_readreg(state, CX24120_REG_FREQ2);
1520 freq3 = cx24120_readreg(state, CX24120_REG_FREQ3);
1521 c->frequency = (freq3 << 16) | (freq2 << 8) | freq1;
1522 dev_dbg(&state->i2c->dev, "frequency = %d\n", c->frequency);
1523
1524 /* Get modulation, fec, pilot */
1525 cx24120_get_fec(fe);
1526
1527 return 0;
1528}
1529
1530static void cx24120_release(struct dvb_frontend *fe)
1531{
1532 struct cx24120_state *state = fe->demodulator_priv;
1533
1534 dev_dbg(&state->i2c->dev, "Clear state structure\n");
1535 kfree(state);
1536}
1537
1538static int cx24120_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1539{
1540 struct cx24120_state *state = fe->demodulator_priv;
1541 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1542
1543 if (c->block_error.stat[0].scale != FE_SCALE_COUNTER) {
1544 *ucblocks = 0;
1545 return 0;
1546 }
1547
1548 *ucblocks = c->block_error.stat[0].uvalue - state->ucb_offset;
1549
1550 return 0;
1551}
1552
1553static struct dvb_frontend_ops cx24120_ops = {
1554 .delsys = { SYS_DVBS, SYS_DVBS2 },
1555 .info = {
1556 .name = "Conexant CX24120/CX24118",
1557 .frequency_min = 950000,
1558 .frequency_max = 2150000,
1559 .frequency_stepsize = 1011, /* kHz for QPSK frontends */
1560 .frequency_tolerance = 5000,
1561 .symbol_rate_min = 1000000,
1562 .symbol_rate_max = 45000000,
1563 .caps = FE_CAN_INVERSION_AUTO |
1564 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1565 FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
1566 FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1567 FE_CAN_2G_MODULATION |
1568 FE_CAN_QPSK | FE_CAN_RECOVER
1569 },
1570 .release = cx24120_release,
1571
1572 .init = cx24120_init,
1573 .sleep = cx24120_sleep,
1574
1575 .tune = cx24120_tune,
1576 .get_frontend_algo = cx24120_get_algo,
1577 .set_frontend = cx24120_set_frontend,
1578
1579 .get_frontend = cx24120_get_frontend,
1580 .read_status = cx24120_read_status,
1581 .read_ber = cx24120_read_ber,
1582 .read_signal_strength = cx24120_read_signal_strength,
1583 .read_snr = cx24120_read_snr,
1584 .read_ucblocks = cx24120_read_ucblocks,
1585
1586 .diseqc_send_master_cmd = cx24120_send_diseqc_msg,
1587
1588 .diseqc_send_burst = cx24120_diseqc_send_burst,
1589 .set_tone = cx24120_set_tone,
1590 .set_voltage = cx24120_set_voltage,
1591};
1592
1593MODULE_DESCRIPTION("DVB Frontend module for Conexant CX24120/CX24118 hardware");
1594MODULE_AUTHOR("Jemma Denson");
1595MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/cx24120.h b/drivers/media/dvb-frontends/cx24120.h
new file mode 100644
index 000000000000..f0970423e16f
--- /dev/null
+++ b/drivers/media/dvb-frontends/cx24120.h
@@ -0,0 +1,58 @@
1/*
2 * Conexant CX24120/CX24118 - DVB-S/S2 demod/tuner driver
3 *
4 * Copyright (C) 2008 Patrick Boettcher <pb@linuxtv.org>
5 * Copyright (C) 2009 Sergey Tyurin <forum.free-x.de>
6 * Updated 2012 by Jannis Achstetter <jannis_achstetter@web.de>
7 * Copyright (C) 2015 Jemma Denson <jdenson@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; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#ifndef CX24120_H
21#define CX24120_H
22
23#include <linux/kconfig.h>
24#include <linux/dvb/frontend.h>
25#include <linux/firmware.h>
26
27struct cx24120_initial_mpeg_config {
28 u8 x1;
29 u8 x2;
30 u8 x3;
31};
32
33struct cx24120_config {
34 u8 i2c_addr;
35 u32 xtal_khz;
36 struct cx24120_initial_mpeg_config initial_mpeg_config;
37
38 int (*request_firmware)(struct dvb_frontend *fe,
39 const struct firmware **fw, char *name);
40
41 /* max bytes I2C provider can write at once */
42 u16 i2c_wr_max;
43};
44
45#if IS_REACHABLE(CONFIG_DVB_CX24120)
46struct dvb_frontend *cx24120_attach(const struct cx24120_config *config,
47 struct i2c_adapter *i2c);
48#else
49static inline
50struct dvb_frontend *cx24120_attach(const struct cx24120_config *config,
51 struct i2c_adapter *i2c)
52{
53 pr_warn("%s: driver disabled by Kconfig\n", __func__);
54 return NULL;
55}
56#endif
57
58#endif /* CX24120_H */
diff --git a/drivers/media/dvb-frontends/cx24123.c b/drivers/media/dvb-frontends/cx24123.c
index 7975c6608e20..e18cf9e1185e 100644
--- a/drivers/media/dvb-frontends/cx24123.c
+++ b/drivers/media/dvb-frontends/cx24123.c
@@ -290,7 +290,7 @@ static int cx24123_i2c_readreg(struct cx24123_state *state, u8 i2c_addr, u8 reg)
290 cx24123_i2c_writereg(state, state->config->demod_address, reg, val) 290 cx24123_i2c_writereg(state, state->config->demod_address, reg, val)
291 291
292static int cx24123_set_inversion(struct cx24123_state *state, 292static int cx24123_set_inversion(struct cx24123_state *state,
293 fe_spectral_inversion_t inversion) 293 enum fe_spectral_inversion inversion)
294{ 294{
295 u8 nom_reg = cx24123_readreg(state, 0x0e); 295 u8 nom_reg = cx24123_readreg(state, 0x0e);
296 u8 auto_reg = cx24123_readreg(state, 0x10); 296 u8 auto_reg = cx24123_readreg(state, 0x10);
@@ -318,7 +318,7 @@ static int cx24123_set_inversion(struct cx24123_state *state,
318} 318}
319 319
320static int cx24123_get_inversion(struct cx24123_state *state, 320static int cx24123_get_inversion(struct cx24123_state *state,
321 fe_spectral_inversion_t *inversion) 321 enum fe_spectral_inversion *inversion)
322{ 322{
323 u8 val; 323 u8 val;
324 324
@@ -335,7 +335,7 @@ static int cx24123_get_inversion(struct cx24123_state *state,
335 return 0; 335 return 0;
336} 336}
337 337
338static int cx24123_set_fec(struct cx24123_state *state, fe_code_rate_t fec) 338static int cx24123_set_fec(struct cx24123_state *state, enum fe_code_rate fec)
339{ 339{
340 u8 nom_reg = cx24123_readreg(state, 0x0e) & ~0x07; 340 u8 nom_reg = cx24123_readreg(state, 0x0e) & ~0x07;
341 341
@@ -397,7 +397,7 @@ static int cx24123_set_fec(struct cx24123_state *state, fe_code_rate_t fec)
397 return 0; 397 return 0;
398} 398}
399 399
400static int cx24123_get_fec(struct cx24123_state *state, fe_code_rate_t *fec) 400static int cx24123_get_fec(struct cx24123_state *state, enum fe_code_rate *fec)
401{ 401{
402 int ret; 402 int ret;
403 403
@@ -720,7 +720,7 @@ static int cx24123_initfe(struct dvb_frontend *fe)
720} 720}
721 721
722static int cx24123_set_voltage(struct dvb_frontend *fe, 722static int cx24123_set_voltage(struct dvb_frontend *fe,
723 fe_sec_voltage_t voltage) 723 enum fe_sec_voltage voltage)
724{ 724{
725 struct cx24123_state *state = fe->demodulator_priv; 725 struct cx24123_state *state = fe->demodulator_priv;
726 u8 val; 726 u8 val;
@@ -795,7 +795,7 @@ static int cx24123_send_diseqc_msg(struct dvb_frontend *fe,
795} 795}
796 796
797static int cx24123_diseqc_send_burst(struct dvb_frontend *fe, 797static int cx24123_diseqc_send_burst(struct dvb_frontend *fe,
798 fe_sec_mini_cmd_t burst) 798 enum fe_sec_mini_cmd burst)
799{ 799{
800 struct cx24123_state *state = fe->demodulator_priv; 800 struct cx24123_state *state = fe->demodulator_priv;
801 int val, tone; 801 int val, tone;
@@ -831,7 +831,7 @@ static int cx24123_diseqc_send_burst(struct dvb_frontend *fe,
831 return 0; 831 return 0;
832} 832}
833 833
834static int cx24123_read_status(struct dvb_frontend *fe, fe_status_t *status) 834static int cx24123_read_status(struct dvb_frontend *fe, enum fe_status *status)
835{ 835{
836 struct cx24123_state *state = fe->demodulator_priv; 836 struct cx24123_state *state = fe->demodulator_priv;
837 int sync = cx24123_readreg(state, 0x14); 837 int sync = cx24123_readreg(state, 0x14);
@@ -966,7 +966,7 @@ static int cx24123_get_frontend(struct dvb_frontend *fe)
966 return 0; 966 return 0;
967} 967}
968 968
969static int cx24123_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 969static int cx24123_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
970{ 970{
971 struct cx24123_state *state = fe->demodulator_priv; 971 struct cx24123_state *state = fe->demodulator_priv;
972 u8 val; 972 u8 val;
@@ -995,7 +995,7 @@ static int cx24123_tune(struct dvb_frontend *fe,
995 bool re_tune, 995 bool re_tune,
996 unsigned int mode_flags, 996 unsigned int mode_flags,
997 unsigned int *delay, 997 unsigned int *delay,
998 fe_status_t *status) 998 enum fe_status *status)
999{ 999{
1000 int retval = 0; 1000 int retval = 0;
1001 1001
diff --git a/drivers/media/dvb-frontends/cx24123.h b/drivers/media/dvb-frontends/cx24123.h
index 758aee5a072f..975f3c926fe8 100644
--- a/drivers/media/dvb-frontends/cx24123.h
+++ b/drivers/media/dvb-frontends/cx24123.h
@@ -50,7 +50,7 @@ static inline struct dvb_frontend *cx24123_attach(
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;
52} 52}
53static struct i2c_adapter * 53static inline struct i2c_adapter *
54 cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe) 54 cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe)
55{ 55{
56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c b/drivers/media/dvb-frontends/cxd2820r_c.c
index 72b0e2db3aab..42fad6aa3958 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -259,7 +259,7 @@ int cxd2820r_read_ucblocks_c(struct dvb_frontend *fe, u32 *ucblocks)
259 return 0; 259 return 0;
260} 260}
261 261
262int cxd2820r_read_status_c(struct dvb_frontend *fe, fe_status_t *status) 262int cxd2820r_read_status_c(struct dvb_frontend *fe, enum fe_status *status)
263{ 263{
264 struct cxd2820r_priv *priv = fe->demodulator_priv; 264 struct cxd2820r_priv *priv = fe->demodulator_priv;
265 int ret; 265 int ret;
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
index 490e090048ef..def6d21d1445 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -287,7 +287,8 @@ static int cxd2820r_set_frontend(struct dvb_frontend *fe)
287err: 287err:
288 return ret; 288 return ret;
289} 289}
290static int cxd2820r_read_status(struct dvb_frontend *fe, fe_status_t *status) 290
291static int cxd2820r_read_status(struct dvb_frontend *fe, enum fe_status *status)
291{ 292{
292 struct cxd2820r_priv *priv = fe->demodulator_priv; 293 struct cxd2820r_priv *priv = fe->demodulator_priv;
293 int ret; 294 int ret;
@@ -501,7 +502,7 @@ static enum dvbfe_search cxd2820r_search(struct dvb_frontend *fe)
501 struct cxd2820r_priv *priv = fe->demodulator_priv; 502 struct cxd2820r_priv *priv = fe->demodulator_priv;
502 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 503 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
503 int ret, i; 504 int ret, i;
504 fe_status_t status = 0; 505 enum fe_status status = 0;
505 506
506 dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, 507 dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__,
507 fe->dtv_property_cache.delivery_system); 508 fe->dtv_property_cache.delivery_system);
diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h b/drivers/media/dvb-frontends/cxd2820r_priv.h
index 4b428959b16e..a0d53f01a8bf 100644
--- a/drivers/media/dvb-frontends/cxd2820r_priv.h
+++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
@@ -48,7 +48,7 @@ struct cxd2820r_priv {
48 struct gpio_chip gpio_chip; 48 struct gpio_chip gpio_chip;
49#endif 49#endif
50 50
51 fe_delivery_system_t delivery_system; 51 enum fe_delivery_system delivery_system;
52 bool last_tune_failed; /* for switch between T and T2 tune */ 52 bool last_tune_failed; /* for switch between T and T2 tune */
53}; 53};
54 54
@@ -80,7 +80,7 @@ int cxd2820r_get_frontend_c(struct dvb_frontend *fe);
80 80
81int cxd2820r_set_frontend_c(struct dvb_frontend *fe); 81int cxd2820r_set_frontend_c(struct dvb_frontend *fe);
82 82
83int cxd2820r_read_status_c(struct dvb_frontend *fe, fe_status_t *status); 83int cxd2820r_read_status_c(struct dvb_frontend *fe, enum fe_status *status);
84 84
85int cxd2820r_read_ber_c(struct dvb_frontend *fe, u32 *ber); 85int cxd2820r_read_ber_c(struct dvb_frontend *fe, u32 *ber);
86 86
@@ -103,7 +103,7 @@ int cxd2820r_get_frontend_t(struct dvb_frontend *fe);
103 103
104int cxd2820r_set_frontend_t(struct dvb_frontend *fe); 104int cxd2820r_set_frontend_t(struct dvb_frontend *fe);
105 105
106int cxd2820r_read_status_t(struct dvb_frontend *fe, fe_status_t *status); 106int cxd2820r_read_status_t(struct dvb_frontend *fe, enum fe_status *status);
107 107
108int cxd2820r_read_ber_t(struct dvb_frontend *fe, u32 *ber); 108int cxd2820r_read_ber_t(struct dvb_frontend *fe, u32 *ber);
109 109
@@ -126,7 +126,7 @@ int cxd2820r_get_frontend_t2(struct dvb_frontend *fe);
126 126
127int cxd2820r_set_frontend_t2(struct dvb_frontend *fe); 127int cxd2820r_set_frontend_t2(struct dvb_frontend *fe);
128 128
129int cxd2820r_read_status_t2(struct dvb_frontend *fe, fe_status_t *status); 129int cxd2820r_read_status_t2(struct dvb_frontend *fe, enum fe_status *status);
130 130
131int cxd2820r_read_ber_t2(struct dvb_frontend *fe, u32 *ber); 131int cxd2820r_read_ber_t2(struct dvb_frontend *fe, u32 *ber);
132 132
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c b/drivers/media/dvb-frontends/cxd2820r_t.c
index 008cb2ac8480..21abf1b4ed4d 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
@@ -349,7 +349,7 @@ int cxd2820r_read_ucblocks_t(struct dvb_frontend *fe, u32 *ucblocks)
349 return 0; 349 return 0;
350} 350}
351 351
352int cxd2820r_read_status_t(struct dvb_frontend *fe, fe_status_t *status) 352int cxd2820r_read_status_t(struct dvb_frontend *fe, enum fe_status *status)
353{ 353{
354 struct cxd2820r_priv *priv = fe->demodulator_priv; 354 struct cxd2820r_priv *priv = fe->demodulator_priv;
355 int ret; 355 int ret;
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c b/drivers/media/dvb-frontends/cxd2820r_t2.c
index 35fe364c7182..4e028b41c0d5 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ -284,7 +284,7 @@ error:
284 return ret; 284 return ret;
285} 285}
286 286
287int cxd2820r_read_status_t2(struct dvb_frontend *fe, fe_status_t *status) 287int cxd2820r_read_status_t2(struct dvb_frontend *fe, enum fe_status *status)
288{ 288{
289 struct cxd2820r_priv *priv = fe->demodulator_priv; 289 struct cxd2820r_priv *priv = fe->demodulator_priv;
290 int ret; 290 int ret;
diff --git a/drivers/media/dvb-frontends/dib0070.c b/drivers/media/dvb-frontends/dib0070.c
index 3b024bfe980a..0b8fb5dd1889 100644
--- a/drivers/media/dvb-frontends/dib0070.c
+++ b/drivers/media/dvb-frontends/dib0070.c
@@ -58,10 +58,10 @@ struct dib0070_state {
58 u16 wbd_ff_offset; 58 u16 wbd_ff_offset;
59 u8 revision; 59 u8 revision;
60 60
61 enum frontend_tune_state tune_state; 61 enum frontend_tune_state tune_state;
62 u32 current_rf; 62 u32 current_rf;
63 63
64 /* for the captrim binary search */ 64 /* for the captrim binary search */
65 s8 step; 65 s8 step;
66 u16 adc_diff; 66 u16 adc_diff;
67 67
@@ -72,7 +72,7 @@ struct dib0070_state {
72 const struct dib0070_tuning *current_tune_table_index; 72 const struct dib0070_tuning *current_tune_table_index;
73 const struct dib0070_lna_match *lna_match; 73 const struct dib0070_lna_match *lna_match;
74 74
75 u8 wbd_gain_current; 75 u8 wbd_gain_current;
76 u16 wbd_offset_3_3[2]; 76 u16 wbd_offset_3_3[2];
77 77
78 /* for the I2C transfer */ 78 /* for the I2C transfer */
@@ -151,31 +151,31 @@ static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val)
151} while (0) 151} while (0)
152 152
153static int dib0070_set_bandwidth(struct dvb_frontend *fe) 153static int dib0070_set_bandwidth(struct dvb_frontend *fe)
154{ 154 {
155 struct dib0070_state *state = fe->tuner_priv; 155 struct dib0070_state *state = fe->tuner_priv;
156 u16 tmp = dib0070_read_reg(state, 0x02) & 0x3fff; 156 u16 tmp = dib0070_read_reg(state, 0x02) & 0x3fff;
157 157
158 if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 7000) 158 if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 7000)
159 tmp |= (0 << 14); 159 tmp |= (0 << 14);
160 else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 6000) 160 else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 6000)
161 tmp |= (1 << 14); 161 tmp |= (1 << 14);
162 else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 5000) 162 else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 5000)
163 tmp |= (2 << 14); 163 tmp |= (2 << 14);
164 else 164 else
165 tmp |= (3 << 14); 165 tmp |= (3 << 14);
166 166
167 dib0070_write_reg(state, 0x02, tmp); 167 dib0070_write_reg(state, 0x02, tmp);
168 168
169 /* sharpen the BB filter in ISDB-T to have higher immunity to adjacent channels */ 169 /* sharpen the BB filter in ISDB-T to have higher immunity to adjacent channels */
170 if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) { 170 if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) {
171 u16 value = dib0070_read_reg(state, 0x17); 171 u16 value = dib0070_read_reg(state, 0x17);
172 172
173 dib0070_write_reg(state, 0x17, value & 0xfffc); 173 dib0070_write_reg(state, 0x17, value & 0xfffc);
174 tmp = dib0070_read_reg(state, 0x01) & 0x01ff; 174 tmp = dib0070_read_reg(state, 0x01) & 0x01ff;
175 dib0070_write_reg(state, 0x01, tmp | (60 << 9)); 175 dib0070_write_reg(state, 0x01, tmp | (60 << 9));
176 176
177 dib0070_write_reg(state, 0x17, value); 177 dib0070_write_reg(state, 0x17, value);
178 } 178 }
179 return 0; 179 return 0;
180} 180}
181 181
@@ -186,7 +186,6 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state
186 int ret = 0; 186 int ret = 0;
187 187
188 if (*tune_state == CT_TUNER_STEP_0) { 188 if (*tune_state == CT_TUNER_STEP_0) {
189
190 dib0070_write_reg(state, 0x0f, 0xed10); 189 dib0070_write_reg(state, 0x0f, 0xed10);
191 dib0070_write_reg(state, 0x17, 0x0034); 190 dib0070_write_reg(state, 0x17, 0x0034);
192 191
@@ -195,7 +194,7 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state
195 state->adc_diff = 3000; 194 state->adc_diff = 3000;
196 ret = 20; 195 ret = 20;
197 196
198 *tune_state = CT_TUNER_STEP_1; 197 *tune_state = CT_TUNER_STEP_1;
199 } else if (*tune_state == CT_TUNER_STEP_1) { 198 } else if (*tune_state == CT_TUNER_STEP_1) {
200 state->step /= 2; 199 state->step /= 2;
201 dib0070_write_reg(state, 0x14, state->lo4 | state->captrim); 200 dib0070_write_reg(state, 0x14, state->lo4 | state->captrim);
@@ -220,9 +219,6 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state
220 dprintk("CAPTRIM=%hd is closer to target (%hd/%hd)", state->captrim, adc, state->adc_diff); 219 dprintk("CAPTRIM=%hd is closer to target (%hd/%hd)", state->captrim, adc, state->adc_diff);
221 state->adc_diff = adc; 220 state->adc_diff = adc;
222 state->fcaptrim = state->captrim; 221 state->fcaptrim = state->captrim;
223
224
225
226 } 222 }
227 state->captrim += (step_sign * state->step); 223 state->captrim += (step_sign * state->step);
228 224
@@ -243,7 +239,8 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state
243static int dib0070_set_ctrl_lo5(struct dvb_frontend *fe, u8 vco_bias_trim, u8 hf_div_trim, u8 cp_current, u8 third_order_filt) 239static int dib0070_set_ctrl_lo5(struct dvb_frontend *fe, u8 vco_bias_trim, u8 hf_div_trim, u8 cp_current, u8 third_order_filt)
244{ 240{
245 struct dib0070_state *state = fe->tuner_priv; 241 struct dib0070_state *state = fe->tuner_priv;
246 u16 lo5 = (third_order_filt << 14) | (0 << 13) | (1 << 12) | (3 << 9) | (cp_current << 6) | (hf_div_trim << 3) | (vco_bias_trim << 0); 242 u16 lo5 = (third_order_filt << 14) | (0 << 13) | (1 << 12) | (3 << 9) | (cp_current << 6) | (hf_div_trim << 3) | (vco_bias_trim << 0);
243
247 dprintk("CTRL_LO5: 0x%x", lo5); 244 dprintk("CTRL_LO5: 0x%x", lo5);
248 return dib0070_write_reg(state, 0x15, lo5); 245 return dib0070_write_reg(state, 0x15, lo5);
249} 246}
@@ -257,281 +254,282 @@ void dib0070_ctrl_agc_filter(struct dvb_frontend *fe, u8 open)
257 dib0070_write_reg(state, 0x1a, 0x0000); 254 dib0070_write_reg(state, 0x1a, 0x0000);
258 } else { 255 } else {
259 dib0070_write_reg(state, 0x1b, 0x4112); 256 dib0070_write_reg(state, 0x1b, 0x4112);
260 if (state->cfg->vga_filter != 0) { 257 if (state->cfg->vga_filter != 0) {
261 dib0070_write_reg(state, 0x1a, state->cfg->vga_filter); 258 dib0070_write_reg(state, 0x1a, state->cfg->vga_filter);
262 dprintk("vga filter register is set to %x", state->cfg->vga_filter); 259 dprintk("vga filter register is set to %x", state->cfg->vga_filter);
263 } else 260 } else
264 dib0070_write_reg(state, 0x1a, 0x0009); 261 dib0070_write_reg(state, 0x1a, 0x0009);
265 } 262 }
266} 263}
267 264
268EXPORT_SYMBOL(dib0070_ctrl_agc_filter); 265EXPORT_SYMBOL(dib0070_ctrl_agc_filter);
269struct dib0070_tuning { 266struct dib0070_tuning {
270 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ 267 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */
271 u8 switch_trim; 268 u8 switch_trim;
272 u8 vco_band; 269 u8 vco_band;
273 u8 hfdiv; 270 u8 hfdiv;
274 u8 vco_multi; 271 u8 vco_multi;
275 u8 presc; 272 u8 presc;
276 u8 wbdmux; 273 u8 wbdmux;
277 u16 tuner_enable; 274 u16 tuner_enable;
278}; 275};
279 276
280struct dib0070_lna_match { 277struct dib0070_lna_match {
281 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ 278 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */
282 u8 lna_band; 279 u8 lna_band;
283}; 280};
284 281
285static const struct dib0070_tuning dib0070s_tuning_table[] = { 282static const struct dib0070_tuning dib0070s_tuning_table[] = {
286 { 570000, 2, 1, 3, 6, 6, 2, 0x4000 | 0x0800 }, /* UHF */ 283 { 570000, 2, 1, 3, 6, 6, 2, 0x4000 | 0x0800 }, /* UHF */
287 { 700000, 2, 0, 2, 4, 2, 2, 0x4000 | 0x0800 }, 284 { 700000, 2, 0, 2, 4, 2, 2, 0x4000 | 0x0800 },
288 { 863999, 2, 1, 2, 4, 2, 2, 0x4000 | 0x0800 }, 285 { 863999, 2, 1, 2, 4, 2, 2, 0x4000 | 0x0800 },
289 { 1500000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND */ 286 { 1500000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND */
290 { 1600000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, 287 { 1600000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 },
291 { 2000000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, 288 { 2000000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 },
292 { 0xffffffff, 0, 0, 8, 1, 2, 1, 0x8000 | 0x1000 }, /* SBAND */ 289 { 0xffffffff, 0, 0, 8, 1, 2, 1, 0x8000 | 0x1000 }, /* SBAND */
293}; 290};
294 291
295static const struct dib0070_tuning dib0070_tuning_table[] = { 292static const struct dib0070_tuning dib0070_tuning_table[] = {
296 { 115000, 1, 0, 7, 24, 2, 1, 0x8000 | 0x1000 }, /* FM below 92MHz cannot be tuned */ 293 { 115000, 1, 0, 7, 24, 2, 1, 0x8000 | 0x1000 }, /* FM below 92MHz cannot be tuned */
297 { 179500, 1, 0, 3, 16, 2, 1, 0x8000 | 0x1000 }, /* VHF */ 294 { 179500, 1, 0, 3, 16, 2, 1, 0x8000 | 0x1000 }, /* VHF */
298 { 189999, 1, 1, 3, 16, 2, 1, 0x8000 | 0x1000 }, 295 { 189999, 1, 1, 3, 16, 2, 1, 0x8000 | 0x1000 },
299 { 250000, 1, 0, 6, 12, 2, 1, 0x8000 | 0x1000 }, 296 { 250000, 1, 0, 6, 12, 2, 1, 0x8000 | 0x1000 },
300 { 569999, 2, 1, 5, 6, 2, 2, 0x4000 | 0x0800 }, /* UHF */ 297 { 569999, 2, 1, 5, 6, 2, 2, 0x4000 | 0x0800 }, /* UHF */
301 { 699999, 2, 0, 1, 4, 2, 2, 0x4000 | 0x0800 }, 298 { 699999, 2, 0, 1, 4, 2, 2, 0x4000 | 0x0800 },
302 { 863999, 2, 1, 1, 4, 2, 2, 0x4000 | 0x0800 }, 299 { 863999, 2, 1, 1, 4, 2, 2, 0x4000 | 0x0800 },
303 { 0xffffffff, 0, 1, 0, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND or everything higher than UHF */ 300 { 0xffffffff, 0, 1, 0, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND or everything higher than UHF */
304}; 301};
305 302
306static const struct dib0070_lna_match dib0070_lna_flip_chip[] = { 303static const struct dib0070_lna_match dib0070_lna_flip_chip[] = {
307 { 180000, 0 }, /* VHF */ 304 { 180000, 0 }, /* VHF */
308 { 188000, 1 }, 305 { 188000, 1 },
309 { 196400, 2 }, 306 { 196400, 2 },
310 { 250000, 3 }, 307 { 250000, 3 },
311 { 550000, 0 }, /* UHF */ 308 { 550000, 0 }, /* UHF */
312 { 590000, 1 }, 309 { 590000, 1 },
313 { 666000, 3 }, 310 { 666000, 3 },
314 { 864000, 5 }, 311 { 864000, 5 },
315 { 1500000, 0 }, /* LBAND or everything higher than UHF */ 312 { 1500000, 0 }, /* LBAND or everything higher than UHF */
316 { 1600000, 1 }, 313 { 1600000, 1 },
317 { 2000000, 3 }, 314 { 2000000, 3 },
318 { 0xffffffff, 7 }, 315 { 0xffffffff, 7 },
319}; 316};
320 317
321static const struct dib0070_lna_match dib0070_lna[] = { 318static const struct dib0070_lna_match dib0070_lna[] = {
322 { 180000, 0 }, /* VHF */ 319 { 180000, 0 }, /* VHF */
323 { 188000, 1 }, 320 { 188000, 1 },
324 { 196400, 2 }, 321 { 196400, 2 },
325 { 250000, 3 }, 322 { 250000, 3 },
326 { 550000, 2 }, /* UHF */ 323 { 550000, 2 }, /* UHF */
327 { 650000, 3 }, 324 { 650000, 3 },
328 { 750000, 5 }, 325 { 750000, 5 },
329 { 850000, 6 }, 326 { 850000, 6 },
330 { 864000, 7 }, 327 { 864000, 7 },
331 { 1500000, 0 }, /* LBAND or everything higher than UHF */ 328 { 1500000, 0 }, /* LBAND or everything higher than UHF */
332 { 1600000, 1 }, 329 { 1600000, 1 },
333 { 2000000, 3 }, 330 { 2000000, 3 },
334 { 0xffffffff, 7 }, 331 { 0xffffffff, 7 },
335}; 332};
336 333
337#define LPF 100 334#define LPF 100
338static int dib0070_tune_digital(struct dvb_frontend *fe) 335static int dib0070_tune_digital(struct dvb_frontend *fe)
339{ 336{
340 struct dib0070_state *state = fe->tuner_priv; 337 struct dib0070_state *state = fe->tuner_priv;
341 338
342 const struct dib0070_tuning *tune; 339 const struct dib0070_tuning *tune;
343 const struct dib0070_lna_match *lna_match; 340 const struct dib0070_lna_match *lna_match;
344 341
345 enum frontend_tune_state *tune_state = &state->tune_state; 342 enum frontend_tune_state *tune_state = &state->tune_state;
346 int ret = 10; /* 1ms is the default delay most of the time */ 343 int ret = 10; /* 1ms is the default delay most of the time */
347 344
348 u8 band = (u8)BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency/1000); 345 u8 band = (u8)BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency/1000);
349 u32 freq = fe->dtv_property_cache.frequency/1000 + (band == BAND_VHF ? state->cfg->freq_offset_khz_vhf : state->cfg->freq_offset_khz_uhf); 346 u32 freq = fe->dtv_property_cache.frequency/1000 + (band == BAND_VHF ? state->cfg->freq_offset_khz_vhf : state->cfg->freq_offset_khz_uhf);
350 347
351#ifdef CONFIG_SYS_ISDBT 348#ifdef CONFIG_SYS_ISDBT
352 if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1) 349 if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1)
353 if (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) 350 if (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2)
354 && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1))) 351 && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
355 || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) 352 || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
356 && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == (state->fe->dtv_property_cache.isdbt_sb_segment_count / 2))) 353 && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == (state->fe->dtv_property_cache.isdbt_sb_segment_count / 2)))
357 || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) 354 || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
358 && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))) 355 && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1))))
359 freq += 850; 356 freq += 850;
360#endif 357#endif
361 if (state->current_rf != freq) {
362
363 switch (state->revision) {
364 case DIB0070S_P1A:
365 tune = dib0070s_tuning_table;
366 lna_match = dib0070_lna;
367 break;
368 default:
369 tune = dib0070_tuning_table;
370 if (state->cfg->flip_chip)
371 lna_match = dib0070_lna_flip_chip;
372 else
373 lna_match = dib0070_lna;
374 break;
375 }
376 while (freq > tune->max_freq) /* find the right one */
377 tune++;
378 while (freq > lna_match->max_freq) /* find the right one */
379 lna_match++;
380
381 state->current_tune_table_index = tune;
382 state->lna_match = lna_match;
383 }
384
385 if (*tune_state == CT_TUNER_START) {
386 dprintk("Tuning for Band: %hd (%d kHz)", band, freq);
387 if (state->current_rf != freq) { 358 if (state->current_rf != freq) {
388 u8 REFDIV;
389 u32 FBDiv, Rest, FREF, VCOF_kHz;
390 u8 Den;
391
392 state->current_rf = freq;
393 state->lo4 = (state->current_tune_table_index->vco_band << 11) | (state->current_tune_table_index->hfdiv << 7);
394
395
396 dib0070_write_reg(state, 0x17, 0x30);
397
398
399 VCOF_kHz = state->current_tune_table_index->vco_multi * freq * 2;
400
401 switch (band) {
402 case BAND_VHF:
403 REFDIV = (u8) ((state->cfg->clock_khz + 9999) / 10000);
404 break;
405 case BAND_FM:
406 REFDIV = (u8) ((state->cfg->clock_khz) / 1000);
407 break;
408 default:
409 REFDIV = (u8) (state->cfg->clock_khz / 10000);
410 break;
411 }
412 FREF = state->cfg->clock_khz / REFDIV;
413
414
415 359
416 switch (state->revision) { 360 switch (state->revision) {
417 case DIB0070S_P1A: 361 case DIB0070S_P1A:
418 FBDiv = (VCOF_kHz / state->current_tune_table_index->presc / FREF); 362 tune = dib0070s_tuning_table;
419 Rest = (VCOF_kHz / state->current_tune_table_index->presc) - FBDiv * FREF; 363 lna_match = dib0070_lna;
420 break; 364 break;
421
422 case DIB0070_P1G:
423 case DIB0070_P1F:
424 default: 365 default:
425 FBDiv = (freq / (FREF / 2)); 366 tune = dib0070_tuning_table;
426 Rest = 2 * freq - FBDiv * FREF; 367 if (state->cfg->flip_chip)
427 break; 368 lna_match = dib0070_lna_flip_chip;
428 } 369 else
429 370 lna_match = dib0070_lna;
430 if (Rest < LPF) 371 break;
431 Rest = 0;
432 else if (Rest < 2 * LPF)
433 Rest = 2 * LPF;
434 else if (Rest > (FREF - LPF)) {
435 Rest = 0;
436 FBDiv += 1;
437 } else if (Rest > (FREF - 2 * LPF))
438 Rest = FREF - 2 * LPF;
439 Rest = (Rest * 6528) / (FREF / 10);
440
441 Den = 1;
442 if (Rest > 0) {
443 state->lo4 |= (1 << 14) | (1 << 12);
444 Den = 255;
445 } 372 }
373 while (freq > tune->max_freq) /* find the right one */
374 tune++;
375 while (freq > lna_match->max_freq) /* find the right one */
376 lna_match++;
446 377
378 state->current_tune_table_index = tune;
379 state->lna_match = lna_match;
380 }
447 381
448 dib0070_write_reg(state, 0x11, (u16)FBDiv); 382 if (*tune_state == CT_TUNER_START) {
449 dib0070_write_reg(state, 0x12, (Den << 8) | REFDIV); 383 dprintk("Tuning for Band: %hd (%d kHz)", band, freq);
450 dib0070_write_reg(state, 0x13, (u16) Rest); 384 if (state->current_rf != freq) {
451 385 u8 REFDIV;
452 if (state->revision == DIB0070S_P1A) { 386 u32 FBDiv, Rest, FREF, VCOF_kHz;
453 387 u8 Den;
454 if (band == BAND_SBAND) { 388
455 dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0); 389 state->current_rf = freq;
456 dib0070_write_reg(state, 0x1d, 0xFFFF); 390 state->lo4 = (state->current_tune_table_index->vco_band << 11) | (state->current_tune_table_index->hfdiv << 7);
457 } else 391
458 dib0070_set_ctrl_lo5(fe, 5, 4, 3, 1); 392
393 dib0070_write_reg(state, 0x17, 0x30);
394
395
396 VCOF_kHz = state->current_tune_table_index->vco_multi * freq * 2;
397
398 switch (band) {
399 case BAND_VHF:
400 REFDIV = (u8) ((state->cfg->clock_khz + 9999) / 10000);
401 break;
402 case BAND_FM:
403 REFDIV = (u8) ((state->cfg->clock_khz) / 1000);
404 break;
405 default:
406 REFDIV = (u8) (state->cfg->clock_khz / 10000);
407 break;
408 }
409 FREF = state->cfg->clock_khz / REFDIV;
410
411
412
413 switch (state->revision) {
414 case DIB0070S_P1A:
415 FBDiv = (VCOF_kHz / state->current_tune_table_index->presc / FREF);
416 Rest = (VCOF_kHz / state->current_tune_table_index->presc) - FBDiv * FREF;
417 break;
418
419 case DIB0070_P1G:
420 case DIB0070_P1F:
421 default:
422 FBDiv = (freq / (FREF / 2));
423 Rest = 2 * freq - FBDiv * FREF;
424 break;
425 }
426
427 if (Rest < LPF)
428 Rest = 0;
429 else if (Rest < 2 * LPF)
430 Rest = 2 * LPF;
431 else if (Rest > (FREF - LPF)) {
432 Rest = 0;
433 FBDiv += 1;
434 } else if (Rest > (FREF - 2 * LPF))
435 Rest = FREF - 2 * LPF;
436 Rest = (Rest * 6528) / (FREF / 10);
437
438 Den = 1;
439 if (Rest > 0) {
440 state->lo4 |= (1 << 14) | (1 << 12);
441 Den = 255;
442 }
443
444
445 dib0070_write_reg(state, 0x11, (u16)FBDiv);
446 dib0070_write_reg(state, 0x12, (Den << 8) | REFDIV);
447 dib0070_write_reg(state, 0x13, (u16) Rest);
448
449 if (state->revision == DIB0070S_P1A) {
450
451 if (band == BAND_SBAND) {
452 dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0);
453 dib0070_write_reg(state, 0x1d, 0xFFFF);
454 } else
455 dib0070_set_ctrl_lo5(fe, 5, 4, 3, 1);
456 }
457
458 dib0070_write_reg(state, 0x20,
459 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001 | state->current_tune_table_index->tuner_enable);
460
461 dprintk("REFDIV: %hd, FREF: %d", REFDIV, FREF);
462 dprintk("FBDIV: %d, Rest: %d", FBDiv, Rest);
463 dprintk("Num: %hd, Den: %hd, SD: %hd", (u16) Rest, Den, (state->lo4 >> 12) & 0x1);
464 dprintk("HFDIV code: %hd", state->current_tune_table_index->hfdiv);
465 dprintk("VCO = %hd", state->current_tune_table_index->vco_band);
466 dprintk("VCOF: ((%hd*%d) << 1))", state->current_tune_table_index->vco_multi, freq);
467
468 *tune_state = CT_TUNER_STEP_0;
469 } else { /* we are already tuned to this frequency - the configuration is correct */
470 ret = 50; /* wakeup time */
471 *tune_state = CT_TUNER_STEP_5;
459 } 472 }
473 } else if ((*tune_state > CT_TUNER_START) && (*tune_state < CT_TUNER_STEP_4)) {
460 474
461 dib0070_write_reg(state, 0x20, 475 ret = dib0070_captrim(state, tune_state);
462 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001 | state->current_tune_table_index->tuner_enable);
463
464 dprintk("REFDIV: %hd, FREF: %d", REFDIV, FREF);
465 dprintk("FBDIV: %d, Rest: %d", FBDiv, Rest);
466 dprintk("Num: %hd, Den: %hd, SD: %hd", (u16) Rest, Den, (state->lo4 >> 12) & 0x1);
467 dprintk("HFDIV code: %hd", state->current_tune_table_index->hfdiv);
468 dprintk("VCO = %hd", state->current_tune_table_index->vco_band);
469 dprintk("VCOF: ((%hd*%d) << 1))", state->current_tune_table_index->vco_multi, freq);
470
471 *tune_state = CT_TUNER_STEP_0;
472 } else { /* we are already tuned to this frequency - the configuration is correct */
473 ret = 50; /* wakeup time */
474 *tune_state = CT_TUNER_STEP_5;
475 }
476 } else if ((*tune_state > CT_TUNER_START) && (*tune_state < CT_TUNER_STEP_4)) {
477
478 ret = dib0070_captrim(state, tune_state);
479 476
480 } else if (*tune_state == CT_TUNER_STEP_4) { 477 } else if (*tune_state == CT_TUNER_STEP_4) {
481 const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; 478 const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain;
482 if (tmp != NULL) { 479 if (tmp != NULL) {
483 while (freq/1000 > tmp->freq) /* find the right one */ 480 while (freq/1000 > tmp->freq) /* find the right one */
484 tmp++; 481 tmp++;
485 dib0070_write_reg(state, 0x0f,
486 (0 << 15) | (1 << 14) | (3 << 12)
487 | (tmp->wbd_gain_val << 9) | (0 << 8) | (1 << 7)
488 | (state->current_tune_table_index->wbdmux << 0));
489 state->wbd_gain_current = tmp->wbd_gain_val;
490 } else {
491 dib0070_write_reg(state, 0x0f, 482 dib0070_write_reg(state, 0x0f,
492 (0 << 15) | (1 << 14) | (3 << 12) | (6 << 9) | (0 << 8) | (1 << 7) | (state->current_tune_table_index-> 483 (0 << 15) | (1 << 14) | (3 << 12)
493 wbdmux << 0)); 484 | (tmp->wbd_gain_val << 9) | (0 << 8) | (1 << 7)
494 state->wbd_gain_current = 6; 485 | (state->current_tune_table_index->wbdmux << 0));
495 } 486 state->wbd_gain_current = tmp->wbd_gain_val;
487 } else {
488 dib0070_write_reg(state, 0x0f,
489 (0 << 15) | (1 << 14) | (3 << 12)
490 | (6 << 9) | (0 << 8) | (1 << 7)
491 | (state->current_tune_table_index->wbdmux << 0));
492 state->wbd_gain_current = 6;
493 }
496 494
497 dib0070_write_reg(state, 0x06, 0x3fff); 495 dib0070_write_reg(state, 0x06, 0x3fff);
498 dib0070_write_reg(state, 0x07, 496 dib0070_write_reg(state, 0x07,
499 (state->current_tune_table_index->switch_trim << 11) | (7 << 8) | (state->lna_match->lna_band << 3) | (3 << 0)); 497 (state->current_tune_table_index->switch_trim << 11) | (7 << 8) | (state->lna_match->lna_band << 3) | (3 << 0));
500 dib0070_write_reg(state, 0x08, (state->lna_match->lna_band << 10) | (3 << 7) | (127)); 498 dib0070_write_reg(state, 0x08, (state->lna_match->lna_band << 10) | (3 << 7) | (127));
501 dib0070_write_reg(state, 0x0d, 0x0d80); 499 dib0070_write_reg(state, 0x0d, 0x0d80);
502 500
503 501
504 dib0070_write_reg(state, 0x18, 0x07ff); 502 dib0070_write_reg(state, 0x18, 0x07ff);
505 dib0070_write_reg(state, 0x17, 0x0033); 503 dib0070_write_reg(state, 0x17, 0x0033);
506 504
507 505
508 *tune_state = CT_TUNER_STEP_5; 506 *tune_state = CT_TUNER_STEP_5;
509 } else if (*tune_state == CT_TUNER_STEP_5) { 507 } else if (*tune_state == CT_TUNER_STEP_5) {
510 dib0070_set_bandwidth(fe); 508 dib0070_set_bandwidth(fe);
511 *tune_state = CT_TUNER_STOP; 509 *tune_state = CT_TUNER_STOP;
512 } else { 510 } else {
513 ret = FE_CALLBACK_TIME_NEVER; /* tuner finished, time to call again infinite */ 511 ret = FE_CALLBACK_TIME_NEVER; /* tuner finished, time to call again infinite */
514 } 512 }
515 return ret; 513 return ret;
516} 514}
517 515
518 516
519static int dib0070_tune(struct dvb_frontend *fe) 517static int dib0070_tune(struct dvb_frontend *fe)
520{ 518{
521 struct dib0070_state *state = fe->tuner_priv; 519 struct dib0070_state *state = fe->tuner_priv;
522 uint32_t ret; 520 uint32_t ret;
523 521
524 state->tune_state = CT_TUNER_START; 522 state->tune_state = CT_TUNER_START;
525 523
526 do { 524 do {
527 ret = dib0070_tune_digital(fe); 525 ret = dib0070_tune_digital(fe);
528 if (ret != FE_CALLBACK_TIME_NEVER) 526 if (ret != FE_CALLBACK_TIME_NEVER)
529 msleep(ret/10); 527 msleep(ret/10);
530 else 528 else
531 break; 529 break;
532 } while (state->tune_state != CT_TUNER_STOP); 530 } while (state->tune_state != CT_TUNER_STOP);
533 531
534 return 0; 532 return 0;
535} 533}
536 534
537static int dib0070_wakeup(struct dvb_frontend *fe) 535static int dib0070_wakeup(struct dvb_frontend *fe)
@@ -610,48 +608,48 @@ static const u16 dib0070_p1f_defaults[] =
610 608
611static u16 dib0070_read_wbd_offset(struct dib0070_state *state, u8 gain) 609static u16 dib0070_read_wbd_offset(struct dib0070_state *state, u8 gain)
612{ 610{
613 u16 tuner_en = dib0070_read_reg(state, 0x20); 611 u16 tuner_en = dib0070_read_reg(state, 0x20);
614 u16 offset; 612 u16 offset;
615 613
616 dib0070_write_reg(state, 0x18, 0x07ff); 614 dib0070_write_reg(state, 0x18, 0x07ff);
617 dib0070_write_reg(state, 0x20, 0x0800 | 0x4000 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001); 615 dib0070_write_reg(state, 0x20, 0x0800 | 0x4000 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001);
618 dib0070_write_reg(state, 0x0f, (1 << 14) | (2 << 12) | (gain << 9) | (1 << 8) | (1 << 7) | (0 << 0)); 616 dib0070_write_reg(state, 0x0f, (1 << 14) | (2 << 12) | (gain << 9) | (1 << 8) | (1 << 7) | (0 << 0));
619 msleep(9); 617 msleep(9);
620 offset = dib0070_read_reg(state, 0x19); 618 offset = dib0070_read_reg(state, 0x19);
621 dib0070_write_reg(state, 0x20, tuner_en); 619 dib0070_write_reg(state, 0x20, tuner_en);
622 return offset; 620 return offset;
623} 621}
624 622
625static void dib0070_wbd_offset_calibration(struct dib0070_state *state) 623static void dib0070_wbd_offset_calibration(struct dib0070_state *state)
626{ 624{
627 u8 gain; 625 u8 gain;
628 for (gain = 6; gain < 8; gain++) { 626 for (gain = 6; gain < 8; gain++) {
629 state->wbd_offset_3_3[gain - 6] = ((dib0070_read_wbd_offset(state, gain) * 8 * 18 / 33 + 1) / 2); 627 state->wbd_offset_3_3[gain - 6] = ((dib0070_read_wbd_offset(state, gain) * 8 * 18 / 33 + 1) / 2);
630 dprintk("Gain: %d, WBDOffset (3.3V) = %hd", gain, state->wbd_offset_3_3[gain-6]); 628 dprintk("Gain: %d, WBDOffset (3.3V) = %hd", gain, state->wbd_offset_3_3[gain-6]);
631 } 629 }
632} 630}
633 631
634u16 dib0070_wbd_offset(struct dvb_frontend *fe) 632u16 dib0070_wbd_offset(struct dvb_frontend *fe)
635{ 633{
636 struct dib0070_state *state = fe->tuner_priv; 634 struct dib0070_state *state = fe->tuner_priv;
637 const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; 635 const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain;
638 u32 freq = fe->dtv_property_cache.frequency/1000; 636 u32 freq = fe->dtv_property_cache.frequency/1000;
639 637
640 if (tmp != NULL) { 638 if (tmp != NULL) {
641 while (freq/1000 > tmp->freq) /* find the right one */ 639 while (freq/1000 > tmp->freq) /* find the right one */
642 tmp++; 640 tmp++;
643 state->wbd_gain_current = tmp->wbd_gain_val; 641 state->wbd_gain_current = tmp->wbd_gain_val;
644 } else 642 } else
645 state->wbd_gain_current = 6; 643 state->wbd_gain_current = 6;
646 644
647 return state->wbd_offset_3_3[state->wbd_gain_current - 6]; 645 return state->wbd_offset_3_3[state->wbd_gain_current - 6];
648} 646}
649EXPORT_SYMBOL(dib0070_wbd_offset); 647EXPORT_SYMBOL(dib0070_wbd_offset);
650 648
651#define pgm_read_word(w) (*w) 649#define pgm_read_word(w) (*w)
652static int dib0070_reset(struct dvb_frontend *fe) 650static int dib0070_reset(struct dvb_frontend *fe)
653{ 651{
654 struct dib0070_state *state = fe->tuner_priv; 652 struct dib0070_state *state = fe->tuner_priv;
655 u16 l, r, *n; 653 u16 l, r, *n;
656 654
657 HARD_RESET(state); 655 HARD_RESET(state);
@@ -664,7 +662,7 @@ static int dib0070_reset(struct dvb_frontend *fe)
664#else 662#else
665#warning forcing SBAND 663#warning forcing SBAND
666#endif 664#endif
667 state->revision = DIB0070S_P1A; 665 state->revision = DIB0070S_P1A;
668 666
669 /* P1F or not */ 667 /* P1F or not */
670 dprintk("Revision: %x", state->revision); 668 dprintk("Revision: %x", state->revision);
@@ -703,24 +701,25 @@ static int dib0070_reset(struct dvb_frontend *fe)
703 dib0070_write_reg(state, 0x02, r | (1 << 5)); 701 dib0070_write_reg(state, 0x02, r | (1 << 5));
704 } 702 }
705 703
706 if (state->revision == DIB0070S_P1A) 704 if (state->revision == DIB0070S_P1A)
707 dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0); 705 dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0);
708 else 706 else
709 dib0070_set_ctrl_lo5(fe, 5, 4, state->cfg->charge_pump, state->cfg->enable_third_order_filter); 707 dib0070_set_ctrl_lo5(fe, 5, 4, state->cfg->charge_pump,
708 state->cfg->enable_third_order_filter);
710 709
711 dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8); 710 dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8);
712 711
713 dib0070_wbd_offset_calibration(state); 712 dib0070_wbd_offset_calibration(state);
714 713
715 return 0; 714 return 0;
716} 715}
717 716
718static int dib0070_get_frequency(struct dvb_frontend *fe, u32 *frequency) 717static int dib0070_get_frequency(struct dvb_frontend *fe, u32 *frequency)
719{ 718{
720 struct dib0070_state *state = fe->tuner_priv; 719 struct dib0070_state *state = fe->tuner_priv;
721 720
722 *frequency = 1000 * state->current_rf; 721 *frequency = 1000 * state->current_rf;
723 return 0; 722 return 0;
724} 723}
725 724
726static int dib0070_release(struct dvb_frontend *fe) 725static int dib0070_release(struct dvb_frontend *fe)
diff --git a/drivers/media/dvb-frontends/dib0090.c b/drivers/media/dvb-frontends/dib0090.c
index 68e2af2650d3..47cb72243b9d 100644
--- a/drivers/media/dvb-frontends/dib0090.c
+++ b/drivers/media/dvb-frontends/dib0090.c
@@ -1696,12 +1696,10 @@ static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum front
1696 1696
1697 if (state->identity.p1g) 1697 if (state->identity.p1g)
1698 state->dc = dc_p1g_table; 1698 state->dc = dc_p1g_table;
1699 *tune_state = CT_TUNER_STEP_0;
1700 1699
1701 /* fall through */ 1700 /* fall through */
1702
1703 case CT_TUNER_STEP_0: 1701 case CT_TUNER_STEP_0:
1704 dprintk("Sart/continue DC calibration for %s path", (state->dc->i == 1) ? "I" : "Q"); 1702 dprintk("Start/continue DC calibration for %s path", (state->dc->i == 1) ? "I" : "Q");
1705 dib0090_write_reg(state, 0x01, state->dc->bb1); 1703 dib0090_write_reg(state, 0x01, state->dc->bb1);
1706 dib0090_write_reg(state, 0x07, state->bb7 | (state->dc->i << 7)); 1704 dib0090_write_reg(state, 0x07, state->bb7 | (state->dc->i << 7));
1707 1705
diff --git a/drivers/media/dvb-frontends/dib3000mb.c b/drivers/media/dvb-frontends/dib3000mb.c
index af91e0c92339..7a61172d0d45 100644
--- a/drivers/media/dvb-frontends/dib3000mb.c
+++ b/drivers/media/dvb-frontends/dib3000mb.c
@@ -118,7 +118,7 @@ static int dib3000mb_set_frontend(struct dvb_frontend *fe, int tuner)
118{ 118{
119 struct dib3000_state* state = fe->demodulator_priv; 119 struct dib3000_state* state = fe->demodulator_priv;
120 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 120 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
121 fe_code_rate_t fe_cr = FEC_NONE; 121 enum fe_code_rate fe_cr = FEC_NONE;
122 int search_state, seq; 122 int search_state, seq;
123 123
124 if (tuner && fe->ops.tuner_ops.set_params) { 124 if (tuner && fe->ops.tuner_ops.set_params) {
@@ -454,7 +454,7 @@ static int dib3000mb_get_frontend(struct dvb_frontend* fe)
454{ 454{
455 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 455 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
456 struct dib3000_state* state = fe->demodulator_priv; 456 struct dib3000_state* state = fe->demodulator_priv;
457 fe_code_rate_t *cr; 457 enum fe_code_rate *cr;
458 u16 tps_val; 458 u16 tps_val;
459 int inv_test1,inv_test2; 459 int inv_test1,inv_test2;
460 u32 dds_val, threshold = 0x800000; 460 u32 dds_val, threshold = 0x800000;
@@ -611,7 +611,8 @@ static int dib3000mb_get_frontend(struct dvb_frontend* fe)
611 return 0; 611 return 0;
612} 612}
613 613
614static int dib3000mb_read_status(struct dvb_frontend* fe, fe_status_t *stat) 614static int dib3000mb_read_status(struct dvb_frontend *fe,
615 enum fe_status *stat)
615{ 616{
616 struct dib3000_state* state = fe->demodulator_priv; 617 struct dib3000_state* state = fe->demodulator_priv;
617 618
diff --git a/drivers/media/dvb-frontends/dib3000mc.c b/drivers/media/dvb-frontends/dib3000mc.c
index ffad181a9692..583d6b7fabed 100644
--- a/drivers/media/dvb-frontends/dib3000mc.c
+++ b/drivers/media/dvb-frontends/dib3000mc.c
@@ -131,7 +131,7 @@ static int dib3000mc_set_timing(struct dib3000mc_state *state, s16 nfft, u32 bw,
131static int dib3000mc_setup_pwm_state(struct dib3000mc_state *state) 131static int dib3000mc_setup_pwm_state(struct dib3000mc_state *state)
132{ 132{
133 u16 reg_51, reg_52 = state->cfg->agc->setup & 0xfefb; 133 u16 reg_51, reg_52 = state->cfg->agc->setup & 0xfefb;
134 if (state->cfg->pwm3_inversion) { 134 if (state->cfg->pwm3_inversion) {
135 reg_51 = (2 << 14) | (0 << 10) | (7 << 6) | (2 << 2) | (2 << 0); 135 reg_51 = (2 << 14) | (0 << 10) | (7 << 6) | (2 << 2) | (2 << 0);
136 reg_52 |= (1 << 2); 136 reg_52 |= (1 << 2);
137 } else { 137 } else {
@@ -141,12 +141,12 @@ static int dib3000mc_setup_pwm_state(struct dib3000mc_state *state)
141 dib3000mc_write_word(state, 51, reg_51); 141 dib3000mc_write_word(state, 51, reg_51);
142 dib3000mc_write_word(state, 52, reg_52); 142 dib3000mc_write_word(state, 52, reg_52);
143 143
144 if (state->cfg->use_pwm3) 144 if (state->cfg->use_pwm3)
145 dib3000mc_write_word(state, 245, (1 << 3) | (1 << 0)); 145 dib3000mc_write_word(state, 245, (1 << 3) | (1 << 0));
146 else 146 else
147 dib3000mc_write_word(state, 245, 0); 147 dib3000mc_write_word(state, 245, 0);
148 148
149 dib3000mc_write_word(state, 1040, 0x3); 149 dib3000mc_write_word(state, 1040, 0x3);
150 return 0; 150 return 0;
151} 151}
152 152
@@ -417,7 +417,7 @@ static int dib3000mc_sleep(struct dvb_frontend *demod)
417 dib3000mc_write_word(state, 1032, 0xFFFF); 417 dib3000mc_write_word(state, 1032, 0xFFFF);
418 dib3000mc_write_word(state, 1033, 0xFFF0); 418 dib3000mc_write_word(state, 1033, 0xFFF0);
419 419
420 return 0; 420 return 0;
421} 421}
422 422
423static void dib3000mc_set_adp_cfg(struct dib3000mc_state *state, s16 qam) 423static void dib3000mc_set_adp_cfg(struct dib3000mc_state *state, s16 qam)
@@ -447,10 +447,14 @@ static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state,
447 dib3000mc_set_bandwidth(state, bw); 447 dib3000mc_set_bandwidth(state, bw);
448 dib3000mc_set_timing(state, ch->transmission_mode, bw, 0); 448 dib3000mc_set_timing(state, ch->transmission_mode, bw, 0);
449 449
450// if (boost) 450#if 1
451// dib3000mc_write_word(state, 100, (11 << 6) + 6); 451 dib3000mc_write_word(state, 100, (16 << 6) + 9);
452// else 452#else
453 if (boost)
454 dib3000mc_write_word(state, 100, (11 << 6) + 6);
455 else
453 dib3000mc_write_word(state, 100, (16 << 6) + 9); 456 dib3000mc_write_word(state, 100, (16 << 6) + 9);
457#endif
454 458
455 dib3000mc_write_word(state, 1027, 0x0800); 459 dib3000mc_write_word(state, 1027, 0x0800);
456 dib3000mc_write_word(state, 1027, 0x0000); 460 dib3000mc_write_word(state, 1027, 0x0000);
@@ -732,7 +736,7 @@ static int dib3000mc_set_frontend(struct dvb_frontend *fe)
732 return ret; 736 return ret;
733} 737}
734 738
735static int dib3000mc_read_status(struct dvb_frontend *fe, fe_status_t *stat) 739static int dib3000mc_read_status(struct dvb_frontend *fe, enum fe_status *stat)
736{ 740{
737 struct dib3000mc_state *state = fe->demodulator_priv; 741 struct dib3000mc_state *state = fe->demodulator_priv;
738 u16 lock = dib3000mc_read_word(state, 509); 742 u16 lock = dib3000mc_read_word(state, 509);
diff --git a/drivers/media/dvb-frontends/dib7000m.c b/drivers/media/dvb-frontends/dib7000m.c
index dcb9a15ef0c2..35eb71fe3c2b 100644
--- a/drivers/media/dvb-frontends/dib7000m.c
+++ b/drivers/media/dvb-frontends/dib7000m.c
@@ -1256,7 +1256,7 @@ static int dib7000m_set_frontend(struct dvb_frontend *fe)
1256 return ret; 1256 return ret;
1257} 1257}
1258 1258
1259static int dib7000m_read_status(struct dvb_frontend *fe, fe_status_t *stat) 1259static int dib7000m_read_status(struct dvb_frontend *fe, enum fe_status *stat)
1260{ 1260{
1261 struct dib7000m_state *state = fe->demodulator_priv; 1261 struct dib7000m_state *state = fe->demodulator_priv;
1262 u16 lock = dib7000m_read_word(state, 535); 1262 u16 lock = dib7000m_read_word(state, 535);
diff --git a/drivers/media/dvb-frontends/dib7000p.c b/drivers/media/dvb-frontends/dib7000p.c
index c505d696f92d..33be5d6b9e10 100644
--- a/drivers/media/dvb-frontends/dib7000p.c
+++ b/drivers/media/dvb-frontends/dib7000p.c
@@ -1558,9 +1558,9 @@ static int dib7000p_set_frontend(struct dvb_frontend *fe)
1558 return ret; 1558 return ret;
1559} 1559}
1560 1560
1561static int dib7000p_get_stats(struct dvb_frontend *fe, fe_status_t stat); 1561static int dib7000p_get_stats(struct dvb_frontend *fe, enum fe_status stat);
1562 1562
1563static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t * stat) 1563static int dib7000p_read_status(struct dvb_frontend *fe, enum fe_status *stat)
1564{ 1564{
1565 struct dib7000p_state *state = fe->demodulator_priv; 1565 struct dib7000p_state *state = fe->demodulator_priv;
1566 u16 lock = dib7000p_read_word(state, 509); 1566 u16 lock = dib7000p_read_word(state, 509);
@@ -1877,7 +1877,7 @@ static u32 dib7000p_get_time_us(struct dvb_frontend *demod)
1877 return time_us; 1877 return time_us;
1878} 1878}
1879 1879
1880static int dib7000p_get_stats(struct dvb_frontend *demod, fe_status_t stat) 1880static int dib7000p_get_stats(struct dvb_frontend *demod, enum fe_status stat)
1881{ 1881{
1882 struct dib7000p_state *state = demod->demodulator_priv; 1882 struct dib7000p_state *state = demod->demodulator_priv;
1883 struct dtv_frontend_properties *c = &demod->dtv_property_cache; 1883 struct dtv_frontend_properties *c = &demod->dtv_property_cache;
diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c
index 8c6663b6399d..94c26270fff0 100644
--- a/drivers/media/dvb-frontends/dib8000.c
+++ b/drivers/media/dvb-frontends/dib8000.c
@@ -3380,13 +3380,13 @@ static int dib8000_sleep(struct dvb_frontend *fe)
3380 return dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(state, DIBX000_ADC_OFF); 3380 return dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(state, DIBX000_ADC_OFF);
3381} 3381}
3382 3382
3383static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat); 3383static int dib8000_read_status(struct dvb_frontend *fe, enum fe_status *stat);
3384 3384
3385static int dib8000_get_frontend(struct dvb_frontend *fe) 3385static int dib8000_get_frontend(struct dvb_frontend *fe)
3386{ 3386{
3387 struct dib8000_state *state = fe->demodulator_priv; 3387 struct dib8000_state *state = fe->demodulator_priv;
3388 u16 i, val = 0; 3388 u16 i, val = 0;
3389 fe_status_t stat = 0; 3389 enum fe_status stat = 0;
3390 u8 index_frontend, sub_index_frontend; 3390 u8 index_frontend, sub_index_frontend;
3391 3391
3392 fe->dtv_property_cache.bandwidth_hz = 6000000; 3392 fe->dtv_property_cache.bandwidth_hz = 6000000;
@@ -3733,9 +3733,9 @@ static int dib8000_set_frontend(struct dvb_frontend *fe)
3733 return 0; 3733 return 0;
3734} 3734}
3735 3735
3736static int dib8000_get_stats(struct dvb_frontend *fe, fe_status_t stat); 3736static int dib8000_get_stats(struct dvb_frontend *fe, enum fe_status stat);
3737 3737
3738static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat) 3738static int dib8000_read_status(struct dvb_frontend *fe, enum fe_status *stat)
3739{ 3739{
3740 struct dib8000_state *state = fe->demodulator_priv; 3740 struct dib8000_state *state = fe->demodulator_priv;
3741 u16 lock_slave = 0, lock; 3741 u16 lock_slave = 0, lock;
@@ -4089,7 +4089,7 @@ static u32 dib8000_get_time_us(struct dvb_frontend *fe, int layer)
4089 return time_us; 4089 return time_us;
4090} 4090}
4091 4091
4092static int dib8000_get_stats(struct dvb_frontend *fe, fe_status_t stat) 4092static int dib8000_get_stats(struct dvb_frontend *fe, enum fe_status stat)
4093{ 4093{
4094 struct dib8000_state *state = fe->demodulator_priv; 4094 struct dib8000_state *state = fe->demodulator_priv;
4095 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache; 4095 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
index 780c37bdcb72..2b8b4b1656a2 100644
--- a/drivers/media/dvb-frontends/dib8000.h
+++ b/drivers/media/dvb-frontends/dib8000.h
@@ -66,7 +66,7 @@ struct dib8000_ops {
66#if IS_REACHABLE(CONFIG_DVB_DIB8000) 66#if IS_REACHABLE(CONFIG_DVB_DIB8000)
67void *dib8000_attach(struct dib8000_ops *ops); 67void *dib8000_attach(struct dib8000_ops *ops);
68#else 68#else
69static inline int dib8000_attach(struct dib8000_ops *ops) 69static inline void *dib8000_attach(struct dib8000_ops *ops)
70{ 70{
71 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 71 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
72 return NULL; 72 return NULL;
diff --git a/drivers/media/dvb-frontends/dib9000.c b/drivers/media/dvb-frontends/dib9000.c
index f75dec443783..8f92aca0b073 100644
--- a/drivers/media/dvb-frontends/dib9000.c
+++ b/drivers/media/dvb-frontends/dib9000.c
@@ -1893,7 +1893,7 @@ static int dib9000_get_frontend(struct dvb_frontend *fe)
1893{ 1893{
1894 struct dib9000_state *state = fe->demodulator_priv; 1894 struct dib9000_state *state = fe->demodulator_priv;
1895 u8 index_frontend, sub_index_frontend; 1895 u8 index_frontend, sub_index_frontend;
1896 fe_status_t stat; 1896 enum fe_status stat;
1897 int ret = 0; 1897 int ret = 0;
1898 1898
1899 if (state->get_frontend_internal == 0) { 1899 if (state->get_frontend_internal == 0) {
@@ -2161,7 +2161,7 @@ static u16 dib9000_read_lock(struct dvb_frontend *fe)
2161 return dib9000_read_word(state, 535); 2161 return dib9000_read_word(state, 535);
2162} 2162}
2163 2163
2164static int dib9000_read_status(struct dvb_frontend *fe, fe_status_t * stat) 2164static int dib9000_read_status(struct dvb_frontend *fe, enum fe_status *stat)
2165{ 2165{
2166 struct dib9000_state *state = fe->demodulator_priv; 2166 struct dib9000_state *state = fe->demodulator_priv;
2167 u8 index_frontend; 2167 u8 index_frontend;
diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c
index 2bfa7a435974..b28b5787b39a 100644
--- a/drivers/media/dvb-frontends/drx39xyj/drxj.c
+++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c
@@ -210,7 +210,7 @@ DEFINES
210 210
211/** 211/**
212* \def DRXJ_DEF_I2C_ADDR 212* \def DRXJ_DEF_I2C_ADDR
213* \brief Default I2C addres of a demodulator instance. 213* \brief Default I2C address of a demodulator instance.
214*/ 214*/
215#define DRXJ_DEF_I2C_ADDR (0x52) 215#define DRXJ_DEF_I2C_ADDR (0x52)
216 216
@@ -336,7 +336,7 @@ DEFINES
336 * MICROCODE RELATED DEFINES 336 * MICROCODE RELATED DEFINES
337 */ 337 */
338 338
339/* Magic word for checking correct Endianess of microcode data */ 339/* Magic word for checking correct Endianness of microcode data */
340#define DRX_UCODE_MAGIC_WORD ((((u16)'H')<<8)+((u16)'L')) 340#define DRX_UCODE_MAGIC_WORD ((((u16)'H')<<8)+((u16)'L'))
341 341
342/* CRC flag in ucode header, flags field. */ 342/* CRC flag in ucode header, flags field. */
@@ -847,9 +847,9 @@ static struct drx_common_attr drxj_default_comm_attr_g = {
847 static clockrate is selected */ 847 static clockrate is selected */
848 DRX_MPEG_STR_WIDTH_1 /* MPEG Start width in clock cycles */ 848 DRX_MPEG_STR_WIDTH_1 /* MPEG Start width in clock cycles */
849 }, 849 },
850 /* Initilisations below can be ommited, they require no user input and 850 /* Initilisations below can be omitted, they require no user input and
851 are initialy 0, NULL or false. The compiler will initialize them to these 851 are initialy 0, NULL or false. The compiler will initialize them to these
852 values when ommited. */ 852 values when omitted. */
853 false, /* is_opened */ 853 false, /* is_opened */
854 854
855 /* SCAN */ 855 /* SCAN */
@@ -1175,7 +1175,7 @@ static u32 log1_times100(u32 x)
1175 Now x has binary point between bit[scale] and bit[scale-1] 1175 Now x has binary point between bit[scale] and bit[scale-1]
1176 and 1.0 <= x < 2.0 */ 1176 and 1.0 <= x < 2.0 */
1177 1177
1178 /* correction for divison: log(x) = log(x/y)+log(y) */ 1178 /* correction for division: log(x) = log(x/y)+log(y) */
1179 y = k * ((((u32) 1) << scale) * 200); 1179 y = k * ((((u32) 1) << scale) * 200);
1180 1180
1181 /* remove integer part */ 1181 /* remove integer part */
@@ -1653,7 +1653,7 @@ static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr,
1653 sequense will be visible: (1) write address {i2c addr, 1653 sequense will be visible: (1) write address {i2c addr,
1654 4 bytes chip address} (2) write data {i2c addr, 4 bytes data } 1654 4 bytes chip address} (2) write data {i2c addr, 4 bytes data }
1655 (3) write address (4) write data etc... 1655 (3) write address (4) write data etc...
1656 Addres must be rewriten because HI is reset after data transport and 1656 Address must be rewriten because HI is reset after data transport and
1657 expects an address. 1657 expects an address.
1658 */ 1658 */
1659 todo = (block_size < datasize ? block_size : datasize); 1659 todo = (block_size < datasize ? block_size : datasize);
@@ -2971,7 +2971,7 @@ ctrl_set_cfg_mpeg_output(struct drx_demod_instance *demod, struct drx_cfg_mpeg_o
2971 } /* ext_attr->standard */ 2971 } /* ext_attr->standard */
2972 } 2972 }
2973 2973
2974 if (cfg_data->enable_parallel == true) { /* MPEG data output is paralel -> clear ipr_mode[0] */ 2974 if (cfg_data->enable_parallel == true) { /* MPEG data output is parallel -> clear ipr_mode[0] */
2975 fec_oc_reg_ipr_mode &= (~(FEC_OC_IPR_MODE_SERIAL__M)); 2975 fec_oc_reg_ipr_mode &= (~(FEC_OC_IPR_MODE_SERIAL__M));
2976 } else { /* MPEG data output is serial -> set ipr_mode[0] */ 2976 } else { /* MPEG data output is serial -> set ipr_mode[0] */
2977 fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_SERIAL__M; 2977 fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_SERIAL__M;
@@ -3157,7 +3157,7 @@ ctrl_set_cfg_mpeg_output(struct drx_demod_instance *demod, struct drx_cfg_mpeg_o
3157 pr_err("error %d\n", rc); 3157 pr_err("error %d\n", rc);
3158 goto rw_error; 3158 goto rw_error;
3159 } 3159 }
3160 if (cfg_data->enable_parallel == true) { /* MPEG data output is paralel -> set MD1 to MD7 to output mode */ 3160 if (cfg_data->enable_parallel == true) { /* MPEG data output is parallel -> set MD1 to MD7 to output mode */
3161 sio_pdr_md_cfg = 3161 sio_pdr_md_cfg =
3162 MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH << 3162 MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH <<
3163 SIO_PDR_MD0_CFG_DRIVE__B | 0x03 << 3163 SIO_PDR_MD0_CFG_DRIVE__B | 0x03 <<
@@ -4320,7 +4320,7 @@ static int adc_synchronization(struct drx_demod_instance *demod)
4320 } 4320 }
4321 4321
4322 if (count == 1) { 4322 if (count == 1) {
4323 /* Try sampling on a diffrent edge */ 4323 /* Try sampling on a different edge */
4324 u16 clk_neg = 0; 4324 u16 clk_neg = 0;
4325 4325
4326 rc = drxj_dap_read_reg16(dev_addr, IQM_AF_CLKNEG__A, &clk_neg, 0); 4326 rc = drxj_dap_read_reg16(dev_addr, IQM_AF_CLKNEG__A, &clk_neg, 0);
@@ -6461,7 +6461,7 @@ set_qam_measurement(struct drx_demod_instance *demod,
6461 enum drx_modulation constellation, u32 symbol_rate) 6461 enum drx_modulation constellation, u32 symbol_rate)
6462{ 6462{
6463 struct i2c_device_addr *dev_addr = NULL; /* device address for I2C writes */ 6463 struct i2c_device_addr *dev_addr = NULL; /* device address for I2C writes */
6464 struct drxj_data *ext_attr = NULL; /* Global data container for DRXJ specif data */ 6464 struct drxj_data *ext_attr = NULL; /* Global data container for DRXJ specific data */
6465 int rc; 6465 int rc;
6466 u32 fec_bits_desired = 0; /* BER accounting period */ 6466 u32 fec_bits_desired = 0; /* BER accounting period */
6467 u16 fec_rs_plen = 0; /* defines RS BER measurement period */ 6467 u16 fec_rs_plen = 0; /* defines RS BER measurement period */
@@ -8864,7 +8864,7 @@ qam64auto(struct drx_demod_instance *demod,
8864 u32 timeout_ofs = 0; 8864 u32 timeout_ofs = 0;
8865 u16 data = 0; 8865 u16 data = 0;
8866 8866
8867 /* external attributes for storing aquired channel constellation */ 8867 /* external attributes for storing acquired channel constellation */
8868 *lock_status = DRX_NOT_LOCKED; 8868 *lock_status = DRX_NOT_LOCKED;
8869 start_time = jiffies_to_msecs(jiffies); 8869 start_time = jiffies_to_msecs(jiffies);
8870 lck_state = NO_LOCK; 8870 lck_state = NO_LOCK;
@@ -9011,7 +9011,7 @@ qam256auto(struct drx_demod_instance *demod,
9011 u32 d_locked_time = 0; 9011 u32 d_locked_time = 0;
9012 u32 timeout_ofs = DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME; 9012 u32 timeout_ofs = DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME;
9013 9013
9014 /* external attributes for storing aquired channel constellation */ 9014 /* external attributes for storing acquired channel constellation */
9015 *lock_status = DRX_NOT_LOCKED; 9015 *lock_status = DRX_NOT_LOCKED;
9016 start_time = jiffies_to_msecs(jiffies); 9016 start_time = jiffies_to_msecs(jiffies);
9017 lck_state = NO_LOCK; 9017 lck_state = NO_LOCK;
@@ -9087,7 +9087,7 @@ set_qam_channel(struct drx_demod_instance *demod,
9087 enum drx_lock_status lock_status = DRX_NOT_LOCKED; 9087 enum drx_lock_status lock_status = DRX_NOT_LOCKED;
9088 bool auto_flag = false; 9088 bool auto_flag = false;
9089 9089
9090 /* external attributes for storing aquired channel constellation */ 9090 /* external attributes for storing acquired channel constellation */
9091 ext_attr = (struct drxj_data *) demod->my_ext_attr; 9091 ext_attr = (struct drxj_data *) demod->my_ext_attr;
9092 9092
9093 /* set QAM channel constellation */ 9093 /* set QAM channel constellation */
@@ -9431,7 +9431,7 @@ rw_error:
9431 9431
9432/** 9432/**
9433* \fn int ctrl_get_qam_sig_quality() 9433* \fn int ctrl_get_qam_sig_quality()
9434* \brief Retreive QAM signal quality from device. 9434* \brief Retrieve QAM signal quality from device.
9435* \param devmod Pointer to demodulator instance. 9435* \param devmod Pointer to demodulator instance.
9436* \param sig_quality Pointer to signal quality data. 9436* \param sig_quality Pointer to signal quality data.
9437* \return int. 9437* \return int.
@@ -9541,7 +9541,7 @@ ctrl_get_qam_sig_quality(struct drx_demod_instance *demod)
9541 /* ----------------------------------------- */ 9541 /* ----------------------------------------- */
9542 /* Pre Viterbi Symbol Error Rate Calculation */ 9542 /* Pre Viterbi Symbol Error Rate Calculation */
9543 /* ----------------------------------------- */ 9543 /* ----------------------------------------- */
9544 /* pre viterbi SER is good if it is bellow 0.025 */ 9544 /* pre viterbi SER is good if it is below 0.025 */
9545 9545
9546 /* get the register value */ 9546 /* get the register value */
9547 /* no of quadrature symbol errors */ 9547 /* no of quadrature symbol errors */
@@ -10647,7 +10647,7 @@ rw_error:
10647 10647
10648/** 10648/**
10649* \fn int ctrl_sig_quality() 10649* \fn int ctrl_sig_quality()
10650* \brief Retreive signal quality form device. 10650* \brief Retrieve signal quality form device.
10651* \param devmod Pointer to demodulator instance. 10651* \param devmod Pointer to demodulator instance.
10652* \param sig_quality Pointer to signal quality data. 10652* \param sig_quality Pointer to signal quality data.
10653* \return int. 10653* \return int.
@@ -10763,7 +10763,7 @@ rw_error:
10763 10763
10764/** 10764/**
10765* \fn int ctrl_lock_status() 10765* \fn int ctrl_lock_status()
10766* \brief Retreive lock status . 10766* \brief Retrieve lock status .
10767* \param dev_addr Pointer to demodulator device address. 10767* \param dev_addr Pointer to demodulator device address.
10768* \param lock_stat Pointer to lock status structure. 10768* \param lock_stat Pointer to lock status structure.
10769* \return int. 10769* \return int.
@@ -10815,7 +10815,7 @@ ctrl_lock_status(struct drx_demod_instance *demod, enum drx_lock_status *lock_st
10815 return -EIO; 10815 return -EIO;
10816 } 10816 }
10817 10817
10818 /* define the SCU command paramters and execute the command */ 10818 /* define the SCU command parameters and execute the command */
10819 cmd_scu.parameter_len = 0; 10819 cmd_scu.parameter_len = 0;
10820 cmd_scu.result_len = 2; 10820 cmd_scu.result_len = 2;
10821 cmd_scu.parameter = NULL; 10821 cmd_scu.parameter = NULL;
@@ -11489,7 +11489,7 @@ static int drxj_open(struct drx_demod_instance *demod)
11489 } 11489 }
11490 11490
11491 /* Stamp driver version number in SCU data RAM in BCD code 11491 /* Stamp driver version number in SCU data RAM in BCD code
11492 Done to enable field application engineers to retreive drxdriver version 11492 Done to enable field application engineers to retrieve drxdriver version
11493 via I2C from SCU RAM 11493 via I2C from SCU RAM
11494 */ 11494 */
11495 driver_version = (VERSION_MAJOR / 100) % 10; 11495 driver_version = (VERSION_MAJOR / 100) % 10;
@@ -11892,7 +11892,7 @@ release:
11892 return rc; 11892 return rc;
11893} 11893}
11894 11894
11895/* caller is expeced to check if lna is supported before enabling */ 11895/* caller is expected to check if lna is supported before enabling */
11896static int drxj_set_lna_state(struct drx_demod_instance *demod, bool state) 11896static int drxj_set_lna_state(struct drx_demod_instance *demod, bool state)
11897{ 11897{
11898 struct drxuio_cfg uio_cfg; 11898 struct drxuio_cfg uio_cfg;
@@ -11946,7 +11946,7 @@ static int drx39xxj_set_powerstate(struct dvb_frontend *fe, int enable)
11946 return 0; 11946 return 0;
11947} 11947}
11948 11948
11949static int drx39xxj_read_status(struct dvb_frontend *fe, fe_status_t *status) 11949static int drx39xxj_read_status(struct dvb_frontend *fe, enum fe_status *status)
11950{ 11950{
11951 struct drx39xxj_state *state = fe->demodulator_priv; 11951 struct drx39xxj_state *state = fe->demodulator_priv;
11952 struct drx_demod_instance *demod = state->demod; 11952 struct drx_demod_instance *demod = state->demod;
diff --git a/drivers/media/dvb-frontends/drxd_hard.c b/drivers/media/dvb-frontends/drxd_hard.c
index 687e893d29fe..34b9441840da 100644
--- a/drivers/media/dvb-frontends/drxd_hard.c
+++ b/drivers/media/dvb-frontends/drxd_hard.c
@@ -2805,7 +2805,7 @@ static int drxd_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
2805 return 0; 2805 return 0;
2806} 2806}
2807 2807
2808static int drxd_read_status(struct dvb_frontend *fe, fe_status_t * status) 2808static int drxd_read_status(struct dvb_frontend *fe, enum fe_status *status)
2809{ 2809{
2810 struct drxd_state *state = fe->demodulator_priv; 2810 struct drxd_state *state = fe->demodulator_priv;
2811 u32 lock; 2811 u32 lock;
diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c
index d46cf5f7cd2e..b975da099929 100644
--- a/drivers/media/dvb-frontends/drxk_hard.c
+++ b/drivers/media/dvb-frontends/drxk_hard.c
@@ -544,7 +544,7 @@ error:
544static int init_state(struct drxk_state *state) 544static int init_state(struct drxk_state *state)
545{ 545{
546 /* 546 /*
547 * FIXME: most (all?) of the values bellow should be moved into 547 * FIXME: most (all?) of the values below should be moved into
548 * struct drxk_config, as they are probably board-specific 548 * struct drxk_config, as they are probably board-specific
549 */ 549 */
550 u32 ul_vsb_if_agc_mode = DRXK_AGC_CTRL_AUTO; 550 u32 ul_vsb_if_agc_mode = DRXK_AGC_CTRL_AUTO;
@@ -3262,6 +3262,7 @@ static int dvbt_sc_command(struct drxk_state *state,
3262 } 3262 }
3263 3263
3264 /* Write needed parameters and the command */ 3264 /* Write needed parameters and the command */
3265 status = 0;
3265 switch (cmd) { 3266 switch (cmd) {
3266 /* All commands using 5 parameters */ 3267 /* All commands using 5 parameters */
3267 /* All commands using 4 parameters */ 3268 /* All commands using 4 parameters */
@@ -3270,16 +3271,16 @@ static int dvbt_sc_command(struct drxk_state *state,
3270 case OFDM_SC_RA_RAM_CMD_PROC_START: 3271 case OFDM_SC_RA_RAM_CMD_PROC_START:
3271 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: 3272 case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM:
3272 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: 3273 case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM:
3273 status = write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1); 3274 status |= write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1);
3274 /* All commands using 1 parameters */ 3275 /* All commands using 1 parameters */
3275 case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: 3276 case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING:
3276 case OFDM_SC_RA_RAM_CMD_USER_IO: 3277 case OFDM_SC_RA_RAM_CMD_USER_IO:
3277 status = write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0); 3278 status |= write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0);
3278 /* All commands using 0 parameters */ 3279 /* All commands using 0 parameters */
3279 case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: 3280 case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM:
3280 case OFDM_SC_RA_RAM_CMD_NULL: 3281 case OFDM_SC_RA_RAM_CMD_NULL:
3281 /* Write command */ 3282 /* Write command */
3282 status = write16(state, OFDM_SC_RA_RAM_CMD__A, cmd); 3283 status |= write16(state, OFDM_SC_RA_RAM_CMD__A, cmd);
3283 break; 3284 break;
3284 default: 3285 default:
3285 /* Unknown command */ 3286 /* Unknown command */
@@ -6639,7 +6640,7 @@ error:
6639} 6640}
6640 6641
6641 6642
6642static int drxk_read_status(struct dvb_frontend *fe, fe_status_t *status) 6643static int drxk_read_status(struct dvb_frontend *fe, enum fe_status *status)
6643{ 6644{
6644 struct drxk_state *state = fe->demodulator_priv; 6645 struct drxk_state *state = fe->demodulator_priv;
6645 int rc; 6646 int rc;
diff --git a/drivers/media/dvb-frontends/drxk_hard.h b/drivers/media/dvb-frontends/drxk_hard.h
index bae9c71dc3e9..9ed88e014942 100644
--- a/drivers/media/dvb-frontends/drxk_hard.h
+++ b/drivers/media/dvb-frontends/drxk_hard.h
@@ -350,7 +350,7 @@ struct drxk_state {
350 bool antenna_dvbt; 350 bool antenna_dvbt;
351 u16 antenna_gpio; 351 u16 antenna_gpio;
352 352
353 fe_status_t fe_status; 353 enum fe_status fe_status;
354 354
355 /* Firmware */ 355 /* Firmware */
356 const char *microcode_name; 356 const char *microcode_name;
diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index 9d0d0347758f..e8fc0329ea64 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -404,7 +404,8 @@ static int ds3000_load_firmware(struct dvb_frontend *fe,
404 return ret; 404 return ret;
405} 405}
406 406
407static int ds3000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 407static int ds3000_set_voltage(struct dvb_frontend *fe,
408 enum fe_sec_voltage voltage)
408{ 409{
409 struct ds3000_state *state = fe->demodulator_priv; 410 struct ds3000_state *state = fe->demodulator_priv;
410 u8 data; 411 u8 data;
@@ -431,7 +432,7 @@ static int ds3000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
431 return 0; 432 return 0;
432} 433}
433 434
434static int ds3000_read_status(struct dvb_frontend *fe, fe_status_t* status) 435static int ds3000_read_status(struct dvb_frontend *fe, enum fe_status *status)
435{ 436{
436 struct ds3000_state *state = fe->demodulator_priv; 437 struct ds3000_state *state = fe->demodulator_priv;
437 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 438 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
@@ -666,7 +667,7 @@ static int ds3000_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
666 return 0; 667 return 0;
667} 668}
668 669
669static int ds3000_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 670static int ds3000_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
670{ 671{
671 struct ds3000_state *state = fe->demodulator_priv; 672 struct ds3000_state *state = fe->demodulator_priv;
672 u8 data; 673 u8 data;
@@ -766,7 +767,7 @@ static int ds3000_send_diseqc_msg(struct dvb_frontend *fe,
766 767
767/* Send DiSEqC burst */ 768/* Send DiSEqC burst */
768static int ds3000_diseqc_send_burst(struct dvb_frontend *fe, 769static int ds3000_diseqc_send_burst(struct dvb_frontend *fe,
769 fe_sec_mini_cmd_t burst) 770 enum fe_sec_mini_cmd burst)
770{ 771{
771 struct ds3000_state *state = fe->demodulator_priv; 772 struct ds3000_state *state = fe->demodulator_priv;
772 int i; 773 int i;
@@ -905,7 +906,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe)
905 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 906 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
906 907
907 int i; 908 int i;
908 fe_status_t status; 909 enum fe_status status;
909 s32 offset_khz; 910 s32 offset_khz;
910 u32 frequency; 911 u32 frequency;
911 u16 value; 912 u16 value;
@@ -1045,7 +1046,7 @@ static int ds3000_tune(struct dvb_frontend *fe,
1045 bool re_tune, 1046 bool re_tune,
1046 unsigned int mode_flags, 1047 unsigned int mode_flags,
1047 unsigned int *delay, 1048 unsigned int *delay,
1048 fe_status_t *status) 1049 enum fe_status *status)
1049{ 1050{
1050 if (re_tune) { 1051 if (re_tune) {
1051 int ret = ds3000_set_frontend(fe); 1052 int ret = ds3000_set_frontend(fe);
diff --git a/drivers/media/dvb-frontends/dvb_dummy_fe.c b/drivers/media/dvb-frontends/dvb_dummy_fe.c
index d5acc304786b..14e996d45fac 100644
--- a/drivers/media/dvb-frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb-frontends/dvb_dummy_fe.c
@@ -33,7 +33,8 @@ struct dvb_dummy_fe_state {
33}; 33};
34 34
35 35
36static int dvb_dummy_fe_read_status(struct dvb_frontend* fe, fe_status_t* status) 36static int dvb_dummy_fe_read_status(struct dvb_frontend *fe,
37 enum fe_status *status)
37{ 38{
38 *status = FE_HAS_SIGNAL 39 *status = FE_HAS_SIGNAL
39 | FE_HAS_CARRIER 40 | FE_HAS_CARRIER
@@ -97,12 +98,14 @@ static int dvb_dummy_fe_init(struct dvb_frontend* fe)
97 return 0; 98 return 0;
98} 99}
99 100
100static int dvb_dummy_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 101static int dvb_dummy_fe_set_tone(struct dvb_frontend *fe,
102 enum fe_sec_tone_mode tone)
101{ 103{
102 return 0; 104 return 0;
103} 105}
104 106
105static int dvb_dummy_fe_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 107static int dvb_dummy_fe_set_voltage(struct dvb_frontend *fe,
108 enum fe_sec_voltage voltage)
106{ 109{
107 return 0; 110 return 0;
108} 111}
diff --git a/drivers/media/dvb-frontends/ec100.c b/drivers/media/dvb-frontends/ec100.c
index 9d424809d06b..c9012e677cd1 100644
--- a/drivers/media/dvb-frontends/ec100.c
+++ b/drivers/media/dvb-frontends/ec100.c
@@ -174,7 +174,7 @@ static int ec100_get_tune_settings(struct dvb_frontend *fe,
174 return 0; 174 return 0;
175} 175}
176 176
177static int ec100_read_status(struct dvb_frontend *fe, fe_status_t *status) 177static int ec100_read_status(struct dvb_frontend *fe, enum fe_status *status)
178{ 178{
179 struct ec100_state *state = fe->demodulator_priv; 179 struct ec100_state *state = fe->demodulator_priv;
180 int ret; 180 int ret;
diff --git a/drivers/media/dvb-frontends/hd29l2.c b/drivers/media/dvb-frontends/hd29l2.c
index 67c8e6df42e8..40e359f2d17d 100644
--- a/drivers/media/dvb-frontends/hd29l2.c
+++ b/drivers/media/dvb-frontends/hd29l2.c
@@ -211,7 +211,7 @@ err:
211 return ret; 211 return ret;
212} 212}
213 213
214static int hd29l2_read_status(struct dvb_frontend *fe, fe_status_t *status) 214static int hd29l2_read_status(struct dvb_frontend *fe, enum fe_status *status)
215{ 215{
216 int ret; 216 int ret;
217 struct hd29l2_priv *priv = fe->demodulator_priv; 217 struct hd29l2_priv *priv = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/hd29l2_priv.h b/drivers/media/dvb-frontends/hd29l2_priv.h
index 4d571a2282d4..6dc225c4bc91 100644
--- a/drivers/media/dvb-frontends/hd29l2_priv.h
+++ b/drivers/media/dvb-frontends/hd29l2_priv.h
@@ -67,7 +67,7 @@ struct hd29l2_priv {
67 struct hd29l2_config cfg; 67 struct hd29l2_config cfg;
68 u8 tuner_i2c_addr_programmed:1; 68 u8 tuner_i2c_addr_programmed:1;
69 69
70 fe_status_t fe_status; 70 enum fe_status fe_status;
71}; 71};
72 72
73static const struct reg_mod_vals reg_mod_vals_tab[] = { 73static const struct reg_mod_vals reg_mod_vals_tab[] = {
diff --git a/drivers/media/dvb-frontends/isl6405.c b/drivers/media/dvb-frontends/isl6405.c
index 0c642a5bf823..b46450a10b80 100644
--- a/drivers/media/dvb-frontends/isl6405.c
+++ b/drivers/media/dvb-frontends/isl6405.c
@@ -43,7 +43,8 @@ struct isl6405 {
43 u8 i2c_addr; 43 u8 i2c_addr;
44}; 44};
45 45
46static int isl6405_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 46static int isl6405_set_voltage(struct dvb_frontend *fe,
47 enum fe_sec_voltage voltage)
47{ 48{
48 struct isl6405 *isl6405 = (struct isl6405 *) fe->sec_priv; 49 struct isl6405 *isl6405 = (struct isl6405 *) fe->sec_priv;
49 struct i2c_msg msg = { .addr = isl6405->i2c_addr, .flags = 0, 50 struct i2c_msg msg = { .addr = isl6405->i2c_addr, .flags = 0,
diff --git a/drivers/media/dvb-frontends/isl6421.c b/drivers/media/dvb-frontends/isl6421.c
index c77002fcc8e2..3a4d4606a426 100644
--- a/drivers/media/dvb-frontends/isl6421.c
+++ b/drivers/media/dvb-frontends/isl6421.c
@@ -43,7 +43,8 @@ struct isl6421 {
43 u8 i2c_addr; 43 u8 i2c_addr;
44}; 44};
45 45
46static int isl6421_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 46static int isl6421_set_voltage(struct dvb_frontend *fe,
47 enum fe_sec_voltage voltage)
47{ 48{
48 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv; 49 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
49 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0, 50 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
@@ -89,7 +90,8 @@ static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
89 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO; 90 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
90} 91}
91 92
92static int isl6421_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 93static int isl6421_set_tone(struct dvb_frontend *fe,
94 enum fe_sec_tone_mode tone)
93{ 95{
94 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv; 96 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
95 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0, 97 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
diff --git a/drivers/media/dvb-frontends/l64781.c b/drivers/media/dvb-frontends/l64781.c
index ddf866c46f8b..0977871232a2 100644
--- a/drivers/media/dvb-frontends/l64781.c
+++ b/drivers/media/dvb-frontends/l64781.c
@@ -359,7 +359,7 @@ static int get_frontend(struct dvb_frontend *fe)
359 return 0; 359 return 0;
360} 360}
361 361
362static int l64781_read_status(struct dvb_frontend* fe, fe_status_t* status) 362static int l64781_read_status(struct dvb_frontend *fe, enum fe_status *status)
363{ 363{
364 struct l64781_state* state = fe->demodulator_priv; 364 struct l64781_state* state = fe->demodulator_priv;
365 int sync = l64781_readreg (state, 0x32); 365 int sync = l64781_readreg (state, 0x32);
diff --git a/drivers/media/dvb-frontends/lg2160.c b/drivers/media/dvb-frontends/lg2160.c
index 99efeba3c31a..7880f71ccd8a 100644
--- a/drivers/media/dvb-frontends/lg2160.c
+++ b/drivers/media/dvb-frontends/lg2160.c
@@ -1203,7 +1203,7 @@ static int lg216x_read_lock_status(struct lg216x_state *state,
1203#endif 1203#endif
1204} 1204}
1205 1205
1206static int lg216x_read_status(struct dvb_frontend *fe, fe_status_t *status) 1206static int lg216x_read_status(struct dvb_frontend *fe, enum fe_status *status)
1207{ 1207{
1208 struct lg216x_state *state = fe->demodulator_priv; 1208 struct lg216x_state *state = fe->demodulator_priv;
1209 int ret, acq_lock, sync_lock; 1209 int ret, acq_lock, sync_lock;
diff --git a/drivers/media/dvb-frontends/lgdt3305.c b/drivers/media/dvb-frontends/lgdt3305.c
index d08570af1c10..47121866163d 100644
--- a/drivers/media/dvb-frontends/lgdt3305.c
+++ b/drivers/media/dvb-frontends/lgdt3305.c
@@ -60,7 +60,7 @@ struct lgdt3305_state {
60 60
61 struct dvb_frontend frontend; 61 struct dvb_frontend frontend;
62 62
63 fe_modulation_t current_modulation; 63 enum fe_modulation current_modulation;
64 u32 current_frequency; 64 u32 current_frequency;
65 u32 snr; 65 u32 snr;
66}; 66};
@@ -912,7 +912,7 @@ fail:
912 return ret; 912 return ret;
913} 913}
914 914
915static int lgdt3305_read_status(struct dvb_frontend *fe, fe_status_t *status) 915static int lgdt3305_read_status(struct dvb_frontend *fe, enum fe_status *status)
916{ 916{
917 struct lgdt3305_state *state = fe->demodulator_priv; 917 struct lgdt3305_state *state = fe->demodulator_priv;
918 u8 val; 918 u8 val;
diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c
index d9a2b0e768e0..721fbc07e9ee 100644
--- a/drivers/media/dvb-frontends/lgdt3306a.c
+++ b/drivers/media/dvb-frontends/lgdt3306a.c
@@ -62,7 +62,7 @@ struct lgdt3306a_state {
62 62
63 struct dvb_frontend frontend; 63 struct dvb_frontend frontend;
64 64
65 fe_modulation_t current_modulation; 65 enum fe_modulation current_modulation;
66 u32 current_frequency; 66 u32 current_frequency;
67 u32 snr; 67 u32 snr;
68}; 68};
@@ -1558,7 +1558,8 @@ lgdt3306a_qam_lock_poll(struct lgdt3306a_state *state)
1558 return LG3306_UNLOCK; 1558 return LG3306_UNLOCK;
1559} 1559}
1560 1560
1561static int lgdt3306a_read_status(struct dvb_frontend *fe, fe_status_t *status) 1561static int lgdt3306a_read_status(struct dvb_frontend *fe,
1562 enum fe_status *status)
1562{ 1563{
1563 struct lgdt3306a_state *state = fe->demodulator_priv; 1564 struct lgdt3306a_state *state = fe->demodulator_priv;
1564 u16 strength = 0; 1565 u16 strength = 0;
@@ -1705,7 +1706,7 @@ static int lgdt3306a_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1705 1706
1706static int lgdt3306a_tune(struct dvb_frontend *fe, bool re_tune, 1707static int lgdt3306a_tune(struct dvb_frontend *fe, bool re_tune,
1707 unsigned int mode_flags, unsigned int *delay, 1708 unsigned int mode_flags, unsigned int *delay,
1708 fe_status_t *status) 1709 enum fe_status *status)
1709{ 1710{
1710 int ret = 0; 1711 int ret = 0;
1711 struct lgdt3306a_state *state = fe->demodulator_priv; 1712 struct lgdt3306a_state *state = fe->demodulator_priv;
@@ -1735,7 +1736,7 @@ static int lgdt3306a_get_tune_settings(struct dvb_frontend *fe,
1735 1736
1736static int lgdt3306a_search(struct dvb_frontend *fe) 1737static int lgdt3306a_search(struct dvb_frontend *fe)
1737{ 1738{
1738 fe_status_t status = 0; 1739 enum fe_status status = 0;
1739 int i, ret; 1740 int i, ret;
1740 1741
1741 /* set frontend */ 1742 /* set frontend */
@@ -2101,7 +2102,7 @@ static void lgdt3306a_DumpRegs(struct lgdt3306a_state *state)
2101 lgdt3306a_read_reg(state, regtab[i], &regval1[i]); 2102 lgdt3306a_read_reg(state, regtab[i], &regval1[i]);
2102 if (regval1[i] != regval2[i]) { 2103 if (regval1[i] != regval2[i]) {
2103 lg_debug(" %04X = %02X\n", regtab[i], regval1[i]); 2104 lg_debug(" %04X = %02X\n", regtab[i], regval1[i]);
2104 regval2[i] = regval1[i]; 2105 regval2[i] = regval1[i];
2105 } 2106 }
2106 } 2107 }
2107 debug = sav_debug; 2108 debug = sav_debug;
diff --git a/drivers/media/dvb-frontends/lgdt330x.c b/drivers/media/dvb-frontends/lgdt330x.c
index 2e1a61893fc1..cf3cc20510da 100644
--- a/drivers/media/dvb-frontends/lgdt330x.c
+++ b/drivers/media/dvb-frontends/lgdt330x.c
@@ -67,7 +67,7 @@ struct lgdt330x_state
67 struct dvb_frontend frontend; 67 struct dvb_frontend frontend;
68 68
69 /* Demodulator private data */ 69 /* Demodulator private data */
70 fe_modulation_t current_modulation; 70 enum fe_modulation current_modulation;
71 u32 snr; /* Result of last SNR calculation */ 71 u32 snr; /* Result of last SNR calculation */
72 72
73 /* Tuner private data */ 73 /* Tuner private data */
@@ -447,7 +447,8 @@ static int lgdt330x_get_frontend(struct dvb_frontend *fe)
447 return 0; 447 return 0;
448} 448}
449 449
450static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status) 450static int lgdt3302_read_status(struct dvb_frontend *fe,
451 enum fe_status *status)
451{ 452{
452 struct lgdt330x_state* state = fe->demodulator_priv; 453 struct lgdt330x_state* state = fe->demodulator_priv;
453 u8 buf[3]; 454 u8 buf[3];
@@ -505,7 +506,8 @@ static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
505 return 0; 506 return 0;
506} 507}
507 508
508static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status) 509static int lgdt3303_read_status(struct dvb_frontend *fe,
510 enum fe_status *status)
509{ 511{
510 struct lgdt330x_state* state = fe->demodulator_priv; 512 struct lgdt330x_state* state = fe->demodulator_priv;
511 int err; 513 int err;
diff --git a/drivers/media/dvb-frontends/lgs8gl5.c b/drivers/media/dvb-frontends/lgs8gl5.c
index 416cce3fefc7..7bbb2c18c2dd 100644
--- a/drivers/media/dvb-frontends/lgs8gl5.c
+++ b/drivers/media/dvb-frontends/lgs8gl5.c
@@ -249,7 +249,7 @@ lgs8gl5_init(struct dvb_frontend *fe)
249 249
250 250
251static int 251static int
252lgs8gl5_read_status(struct dvb_frontend *fe, fe_status_t *status) 252lgs8gl5_read_status(struct dvb_frontend *fe, enum fe_status *status)
253{ 253{
254 struct lgs8gl5_state *state = fe->demodulator_priv; 254 struct lgs8gl5_state *state = fe->demodulator_priv;
255 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH); 255 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
diff --git a/drivers/media/dvb-frontends/lgs8gxx.c b/drivers/media/dvb-frontends/lgs8gxx.c
index 3c92f36ea5c7..e2c191c8b196 100644
--- a/drivers/media/dvb-frontends/lgs8gxx.c
+++ b/drivers/media/dvb-frontends/lgs8gxx.c
@@ -732,7 +732,8 @@ int lgs8gxx_get_tune_settings(struct dvb_frontend *fe,
732 return 0; 732 return 0;
733} 733}
734 734
735static int lgs8gxx_read_status(struct dvb_frontend *fe, fe_status_t *fe_status) 735static int lgs8gxx_read_status(struct dvb_frontend *fe,
736 enum fe_status *fe_status)
736{ 737{
737 struct lgs8gxx_state *priv = fe->demodulator_priv; 738 struct lgs8gxx_state *priv = fe->demodulator_priv;
738 s8 ret; 739 s8 ret;
diff --git a/drivers/media/dvb-frontends/lnbp21.c b/drivers/media/dvb-frontends/lnbp21.c
index f3ba7b5faa2e..4aca0fb9a8a7 100644
--- a/drivers/media/dvb-frontends/lnbp21.c
+++ b/drivers/media/dvb-frontends/lnbp21.c
@@ -45,7 +45,7 @@ struct lnbp21 {
45}; 45};
46 46
47static int lnbp21_set_voltage(struct dvb_frontend *fe, 47static int lnbp21_set_voltage(struct dvb_frontend *fe,
48 fe_sec_voltage_t voltage) 48 enum fe_sec_voltage voltage)
49{ 49{
50 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv; 50 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
51 struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0, 51 struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
@@ -92,7 +92,7 @@ static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
92} 92}
93 93
94static int lnbp21_set_tone(struct dvb_frontend *fe, 94static int lnbp21_set_tone(struct dvb_frontend *fe,
95 fe_sec_tone_mode_t tone) 95 enum fe_sec_tone_mode tone)
96{ 96{
97 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv; 97 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
98 struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0, 98 struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
diff --git a/drivers/media/dvb-frontends/lnbp22.c b/drivers/media/dvb-frontends/lnbp22.c
index c463da7f6dcc..d7ca0fdd0084 100644
--- a/drivers/media/dvb-frontends/lnbp22.c
+++ b/drivers/media/dvb-frontends/lnbp22.c
@@ -48,7 +48,8 @@ struct lnbp22 {
48 struct i2c_adapter *i2c; 48 struct i2c_adapter *i2c;
49}; 49};
50 50
51static int lnbp22_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 51static int lnbp22_set_voltage(struct dvb_frontend *fe,
52 enum fe_sec_voltage voltage)
52{ 53{
53 struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv; 54 struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv;
54 struct i2c_msg msg = { 55 struct i2c_msg msg = {
diff --git a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c
index d3d928e1c0ce..e9b2d2b69b1d 100644
--- a/drivers/media/dvb-frontends/m88ds3103.c
+++ b/drivers/media/dvb-frontends/m88ds3103.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Montage M88DS3103/M88RS6000 demodulator driver 2 * Montage Technology M88DS3103/M88RS6000 demodulator driver
3 * 3 *
4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -18,149 +18,15 @@
18 18
19static struct dvb_frontend_ops m88ds3103_ops; 19static struct dvb_frontend_ops m88ds3103_ops;
20 20
21/* write multiple registers */
22static int m88ds3103_wr_regs(struct m88ds3103_priv *priv,
23 u8 reg, const u8 *val, int len)
24{
25#define MAX_WR_LEN 32
26#define MAX_WR_XFER_LEN (MAX_WR_LEN + 1)
27 int ret;
28 u8 buf[MAX_WR_XFER_LEN];
29 struct i2c_msg msg[1] = {
30 {
31 .addr = priv->cfg->i2c_addr,
32 .flags = 0,
33 .len = 1 + len,
34 .buf = buf,
35 }
36 };
37
38 if (WARN_ON(len > MAX_WR_LEN))
39 return -EINVAL;
40
41 buf[0] = reg;
42 memcpy(&buf[1], val, len);
43
44 mutex_lock(&priv->i2c_mutex);
45 ret = i2c_transfer(priv->i2c, msg, 1);
46 mutex_unlock(&priv->i2c_mutex);
47 if (ret == 1) {
48 ret = 0;
49 } else {
50 dev_warn(&priv->i2c->dev,
51 "%s: i2c wr failed=%d reg=%02x len=%d\n",
52 KBUILD_MODNAME, ret, reg, len);
53 ret = -EREMOTEIO;
54 }
55
56 return ret;
57}
58
59/* read multiple registers */
60static int m88ds3103_rd_regs(struct m88ds3103_priv *priv,
61 u8 reg, u8 *val, int len)
62{
63#define MAX_RD_LEN 3
64#define MAX_RD_XFER_LEN (MAX_RD_LEN)
65 int ret;
66 u8 buf[MAX_RD_XFER_LEN];
67 struct i2c_msg msg[2] = {
68 {
69 .addr = priv->cfg->i2c_addr,
70 .flags = 0,
71 .len = 1,
72 .buf = &reg,
73 }, {
74 .addr = priv->cfg->i2c_addr,
75 .flags = I2C_M_RD,
76 .len = len,
77 .buf = buf,
78 }
79 };
80
81 if (WARN_ON(len > MAX_RD_LEN))
82 return -EINVAL;
83
84 mutex_lock(&priv->i2c_mutex);
85 ret = i2c_transfer(priv->i2c, msg, 2);
86 mutex_unlock(&priv->i2c_mutex);
87 if (ret == 2) {
88 memcpy(val, buf, len);
89 ret = 0;
90 } else {
91 dev_warn(&priv->i2c->dev,
92 "%s: i2c rd failed=%d reg=%02x len=%d\n",
93 KBUILD_MODNAME, ret, reg, len);
94 ret = -EREMOTEIO;
95 }
96
97 return ret;
98}
99
100/* write single register */
101static int m88ds3103_wr_reg(struct m88ds3103_priv *priv, u8 reg, u8 val)
102{
103 return m88ds3103_wr_regs(priv, reg, &val, 1);
104}
105
106/* read single register */
107static int m88ds3103_rd_reg(struct m88ds3103_priv *priv, u8 reg, u8 *val)
108{
109 return m88ds3103_rd_regs(priv, reg, val, 1);
110}
111
112/* write single register with mask */
113static int m88ds3103_wr_reg_mask(struct m88ds3103_priv *priv,
114 u8 reg, u8 val, u8 mask)
115{
116 int ret;
117 u8 u8tmp;
118
119 /* no need for read if whole reg is written */
120 if (mask != 0xff) {
121 ret = m88ds3103_rd_regs(priv, reg, &u8tmp, 1);
122 if (ret)
123 return ret;
124
125 val &= mask;
126 u8tmp &= ~mask;
127 val |= u8tmp;
128 }
129
130 return m88ds3103_wr_regs(priv, reg, &val, 1);
131}
132
133/* read single register with mask */
134static int m88ds3103_rd_reg_mask(struct m88ds3103_priv *priv,
135 u8 reg, u8 *val, u8 mask)
136{
137 int ret, i;
138 u8 u8tmp;
139
140 ret = m88ds3103_rd_regs(priv, reg, &u8tmp, 1);
141 if (ret)
142 return ret;
143
144 u8tmp &= mask;
145
146 /* find position of the first bit */
147 for (i = 0; i < 8; i++) {
148 if ((mask >> i) & 0x01)
149 break;
150 }
151 *val = u8tmp >> i;
152
153 return 0;
154}
155
156/* write reg val table using reg addr auto increment */ 21/* write reg val table using reg addr auto increment */
157static int m88ds3103_wr_reg_val_tab(struct m88ds3103_priv *priv, 22static int m88ds3103_wr_reg_val_tab(struct m88ds3103_dev *dev,
158 const struct m88ds3103_reg_val *tab, int tab_len) 23 const struct m88ds3103_reg_val *tab, int tab_len)
159{ 24{
25 struct i2c_client *client = dev->client;
160 int ret, i, j; 26 int ret, i, j;
161 u8 buf[83]; 27 u8 buf[83];
162 28
163 dev_dbg(&priv->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len); 29 dev_dbg(&client->dev, "tab_len=%d\n", tab_len);
164 30
165 if (tab_len > 86) { 31 if (tab_len > 86) {
166 ret = -EINVAL; 32 ret = -EINVAL;
@@ -171,8 +37,8 @@ static int m88ds3103_wr_reg_val_tab(struct m88ds3103_priv *priv,
171 buf[j] = tab[i].val; 37 buf[j] = tab[i].val;
172 38
173 if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1 || 39 if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1 ||
174 !((j + 1) % (priv->cfg->i2c_wr_max - 1))) { 40 !((j + 1) % (dev->cfg->i2c_wr_max - 1))) {
175 ret = m88ds3103_wr_regs(priv, tab[i].reg - j, buf, j + 1); 41 ret = regmap_bulk_write(dev->regmap, tab[i].reg - j, buf, j + 1);
176 if (ret) 42 if (ret)
177 goto err; 43 goto err;
178 44
@@ -182,66 +48,238 @@ static int m88ds3103_wr_reg_val_tab(struct m88ds3103_priv *priv,
182 48
183 return 0; 49 return 0;
184err: 50err:
185 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 51 dev_dbg(&client->dev, "failed=%d\n", ret);
52 return ret;
53}
54
55/*
56 * Get the demodulator AGC PWM voltage setting supplied to the tuner.
57 */
58int m88ds3103_get_agc_pwm(struct dvb_frontend *fe, u8 *_agc_pwm)
59{
60 struct m88ds3103_dev *dev = fe->demodulator_priv;
61 unsigned tmp;
62 int ret;
63
64 ret = regmap_read(dev->regmap, 0x3f, &tmp);
65 if (ret == 0)
66 *_agc_pwm = tmp;
186 return ret; 67 return ret;
187} 68}
69EXPORT_SYMBOL(m88ds3103_get_agc_pwm);
188 70
189static int m88ds3103_read_status(struct dvb_frontend *fe, fe_status_t *status) 71static int m88ds3103_read_status(struct dvb_frontend *fe,
72 enum fe_status *status)
190{ 73{
191 struct m88ds3103_priv *priv = fe->demodulator_priv; 74 struct m88ds3103_dev *dev = fe->demodulator_priv;
75 struct i2c_client *client = dev->client;
192 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 76 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
193 int ret; 77 int ret, i, itmp;
194 u8 u8tmp; 78 unsigned int utmp;
79 u8 buf[3];
195 80
196 *status = 0; 81 *status = 0;
197 82
198 if (!priv->warm) { 83 if (!dev->warm) {
199 ret = -EAGAIN; 84 ret = -EAGAIN;
200 goto err; 85 goto err;
201 } 86 }
202 87
203 switch (c->delivery_system) { 88 switch (c->delivery_system) {
204 case SYS_DVBS: 89 case SYS_DVBS:
205 ret = m88ds3103_rd_reg_mask(priv, 0xd1, &u8tmp, 0x07); 90 ret = regmap_read(dev->regmap, 0xd1, &utmp);
206 if (ret) 91 if (ret)
207 goto err; 92 goto err;
208 93
209 if (u8tmp == 0x07) 94 if ((utmp & 0x07) == 0x07)
210 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 95 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
211 FE_HAS_VITERBI | FE_HAS_SYNC | 96 FE_HAS_VITERBI | FE_HAS_SYNC |
212 FE_HAS_LOCK; 97 FE_HAS_LOCK;
213 break; 98 break;
214 case SYS_DVBS2: 99 case SYS_DVBS2:
215 ret = m88ds3103_rd_reg_mask(priv, 0x0d, &u8tmp, 0x8f); 100 ret = regmap_read(dev->regmap, 0x0d, &utmp);
216 if (ret) 101 if (ret)
217 goto err; 102 goto err;
218 103
219 if (u8tmp == 0x8f) 104 if ((utmp & 0x8f) == 0x8f)
220 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 105 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
221 FE_HAS_VITERBI | FE_HAS_SYNC | 106 FE_HAS_VITERBI | FE_HAS_SYNC |
222 FE_HAS_LOCK; 107 FE_HAS_LOCK;
223 break; 108 break;
224 default: 109 default:
225 dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n", 110 dev_dbg(&client->dev, "invalid delivery_system\n");
226 __func__);
227 ret = -EINVAL; 111 ret = -EINVAL;
228 goto err; 112 goto err;
229 } 113 }
230 114
231 priv->fe_status = *status; 115 dev->fe_status = *status;
116 dev_dbg(&client->dev, "lock=%02x status=%02x\n", utmp, *status);
117
118 /* CNR */
119 if (dev->fe_status & FE_HAS_VITERBI) {
120 unsigned int cnr, noise, signal, noise_tot, signal_tot;
121
122 cnr = 0;
123 /* more iterations for more accurate estimation */
124 #define M88DS3103_SNR_ITERATIONS 3
125
126 switch (c->delivery_system) {
127 case SYS_DVBS:
128 itmp = 0;
129
130 for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) {
131 ret = regmap_read(dev->regmap, 0xff, &utmp);
132 if (ret)
133 goto err;
134
135 itmp += utmp;
136 }
137
138 /* use of single register limits max value to 15 dB */
139 /* SNR(X) dB = 10 * ln(X) / ln(10) dB */
140 itmp = DIV_ROUND_CLOSEST(itmp, 8 * M88DS3103_SNR_ITERATIONS);
141 if (itmp)
142 cnr = div_u64((u64) 10000 * intlog2(itmp), intlog2(10));
143 break;
144 case SYS_DVBS2:
145 noise_tot = 0;
146 signal_tot = 0;
147
148 for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) {
149 ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3);
150 if (ret)
151 goto err;
152
153 noise = buf[1] << 6; /* [13:6] */
154 noise |= buf[0] & 0x3f; /* [5:0] */
155 noise >>= 2;
156 signal = buf[2] * buf[2];
157 signal >>= 1;
158
159 noise_tot += noise;
160 signal_tot += signal;
161 }
162
163 noise = noise_tot / M88DS3103_SNR_ITERATIONS;
164 signal = signal_tot / M88DS3103_SNR_ITERATIONS;
165
166 /* SNR(X) dB = 10 * log10(X) dB */
167 if (signal > noise) {
168 itmp = signal / noise;
169 cnr = div_u64((u64) 10000 * intlog10(itmp), (1 << 24));
170 }
171 break;
172 default:
173 dev_dbg(&client->dev, "invalid delivery_system\n");
174 ret = -EINVAL;
175 goto err;
176 }
177
178 if (cnr) {
179 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
180 c->cnr.stat[0].svalue = cnr;
181 } else {
182 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
183 }
184 } else {
185 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
186 }
187
188 /* BER */
189 if (dev->fe_status & FE_HAS_LOCK) {
190 unsigned int utmp, post_bit_error, post_bit_count;
232 191
233 dev_dbg(&priv->i2c->dev, "%s: lock=%02x status=%02x\n", 192 switch (c->delivery_system) {
234 __func__, u8tmp, *status); 193 case SYS_DVBS:
194 ret = regmap_write(dev->regmap, 0xf9, 0x04);
195 if (ret)
196 goto err;
197
198 ret = regmap_read(dev->regmap, 0xf8, &utmp);
199 if (ret)
200 goto err;
201
202 /* measurement ready? */
203 if (!(utmp & 0x10)) {
204 ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2);
205 if (ret)
206 goto err;
207
208 post_bit_error = buf[1] << 8 | buf[0] << 0;
209 post_bit_count = 0x800000;
210 dev->post_bit_error += post_bit_error;
211 dev->post_bit_count += post_bit_count;
212 dev->dvbv3_ber = post_bit_error;
213
214 /* restart measurement */
215 utmp |= 0x10;
216 ret = regmap_write(dev->regmap, 0xf8, utmp);
217 if (ret)
218 goto err;
219 }
220 break;
221 case SYS_DVBS2:
222 ret = regmap_bulk_read(dev->regmap, 0xd5, buf, 3);
223 if (ret)
224 goto err;
225
226 utmp = buf[2] << 16 | buf[1] << 8 | buf[0] << 0;
227
228 /* enough data? */
229 if (utmp > 4000) {
230 ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2);
231 if (ret)
232 goto err;
233
234 post_bit_error = buf[1] << 8 | buf[0] << 0;
235 post_bit_count = 32 * utmp; /* TODO: FEC */
236 dev->post_bit_error += post_bit_error;
237 dev->post_bit_count += post_bit_count;
238 dev->dvbv3_ber = post_bit_error;
239
240 /* restart measurement */
241 ret = regmap_write(dev->regmap, 0xd1, 0x01);
242 if (ret)
243 goto err;
244
245 ret = regmap_write(dev->regmap, 0xf9, 0x01);
246 if (ret)
247 goto err;
248
249 ret = regmap_write(dev->regmap, 0xf9, 0x00);
250 if (ret)
251 goto err;
252
253 ret = regmap_write(dev->regmap, 0xd1, 0x00);
254 if (ret)
255 goto err;
256 }
257 break;
258 default:
259 dev_dbg(&client->dev, "invalid delivery_system\n");
260 ret = -EINVAL;
261 goto err;
262 }
263
264 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
265 c->post_bit_error.stat[0].uvalue = dev->post_bit_error;
266 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
267 c->post_bit_count.stat[0].uvalue = dev->post_bit_count;
268 } else {
269 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
270 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
271 }
235 272
236 return 0; 273 return 0;
237err: 274err:
238 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 275 dev_dbg(&client->dev, "failed=%d\n", ret);
239 return ret; 276 return ret;
240} 277}
241 278
242static int m88ds3103_set_frontend(struct dvb_frontend *fe) 279static int m88ds3103_set_frontend(struct dvb_frontend *fe)
243{ 280{
244 struct m88ds3103_priv *priv = fe->demodulator_priv; 281 struct m88ds3103_dev *dev = fe->demodulator_priv;
282 struct i2c_client *client = dev->client;
245 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 283 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
246 int ret, len; 284 int ret, len;
247 const struct m88ds3103_reg_val *init; 285 const struct m88ds3103_reg_val *init;
@@ -251,29 +289,28 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
251 u32 tuner_frequency, target_mclk; 289 u32 tuner_frequency, target_mclk;
252 s32 s32tmp; 290 s32 s32tmp;
253 291
254 dev_dbg(&priv->i2c->dev, 292 dev_dbg(&client->dev,
255 "%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 293 "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
256 __func__, c->delivery_system, 294 c->delivery_system, c->modulation, c->frequency, c->symbol_rate,
257 c->modulation, c->frequency, c->symbol_rate, 295 c->inversion, c->pilot, c->rolloff);
258 c->inversion, c->pilot, c->rolloff);
259 296
260 if (!priv->warm) { 297 if (!dev->warm) {
261 ret = -EAGAIN; 298 ret = -EAGAIN;
262 goto err; 299 goto err;
263 } 300 }
264 301
265 /* reset */ 302 /* reset */
266 ret = m88ds3103_wr_reg(priv, 0x07, 0x80); 303 ret = regmap_write(dev->regmap, 0x07, 0x80);
267 if (ret) 304 if (ret)
268 goto err; 305 goto err;
269 306
270 ret = m88ds3103_wr_reg(priv, 0x07, 0x00); 307 ret = regmap_write(dev->regmap, 0x07, 0x00);
271 if (ret) 308 if (ret)
272 goto err; 309 goto err;
273 310
274 /* Disable demod clock path */ 311 /* Disable demod clock path */
275 if (priv->chip_id == M88RS6000_CHIP_ID) { 312 if (dev->chip_id == M88RS6000_CHIP_ID) {
276 ret = m88ds3103_wr_reg(priv, 0x06, 0xe0); 313 ret = regmap_write(dev->regmap, 0x06, 0xe0);
277 if (ret) 314 if (ret)
278 goto err; 315 goto err;
279 } 316 }
@@ -299,11 +336,11 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
299 } 336 }
300 337
301 /* select M88RS6000 demod main mclk and ts mclk from tuner die. */ 338 /* select M88RS6000 demod main mclk and ts mclk from tuner die. */
302 if (priv->chip_id == M88RS6000_CHIP_ID) { 339 if (dev->chip_id == M88RS6000_CHIP_ID) {
303 if (c->symbol_rate > 45010000) 340 if (c->symbol_rate > 45010000)
304 priv->mclk_khz = 110250; 341 dev->mclk_khz = 110250;
305 else 342 else
306 priv->mclk_khz = 96000; 343 dev->mclk_khz = 96000;
307 344
308 if (c->delivery_system == SYS_DVBS) 345 if (c->delivery_system == SYS_DVBS)
309 target_mclk = 96000; 346 target_mclk = 96000;
@@ -311,18 +348,18 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
311 target_mclk = 144000; 348 target_mclk = 144000;
312 349
313 /* Enable demod clock path */ 350 /* Enable demod clock path */
314 ret = m88ds3103_wr_reg(priv, 0x06, 0x00); 351 ret = regmap_write(dev->regmap, 0x06, 0x00);
315 if (ret) 352 if (ret)
316 goto err; 353 goto err;
317 usleep_range(10000, 20000); 354 usleep_range(10000, 20000);
318 } else { 355 } else {
319 /* set M88DS3103 mclk and ts mclk. */ 356 /* set M88DS3103 mclk and ts mclk. */
320 priv->mclk_khz = 96000; 357 dev->mclk_khz = 96000;
321 358
322 switch (priv->cfg->ts_mode) { 359 switch (dev->cfg->ts_mode) {
323 case M88DS3103_TS_SERIAL: 360 case M88DS3103_TS_SERIAL:
324 case M88DS3103_TS_SERIAL_D7: 361 case M88DS3103_TS_SERIAL_D7:
325 target_mclk = priv->cfg->ts_clk; 362 target_mclk = dev->cfg->ts_clk;
326 break; 363 break;
327 case M88DS3103_TS_PARALLEL: 364 case M88DS3103_TS_PARALLEL:
328 case M88DS3103_TS_CI: 365 case M88DS3103_TS_CI:
@@ -338,8 +375,7 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
338 } 375 }
339 break; 376 break;
340 default: 377 default:
341 dev_dbg(&priv->i2c->dev, "%s: invalid ts_mode\n", 378 dev_dbg(&client->dev, "invalid ts_mode\n");
342 __func__);
343 ret = -EINVAL; 379 ret = -EINVAL;
344 goto err; 380 goto err;
345 } 381 }
@@ -358,25 +394,25 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
358 u8tmp2 = 0x00; /* 0b00 */ 394 u8tmp2 = 0x00; /* 0b00 */
359 break; 395 break;
360 } 396 }
361 ret = m88ds3103_wr_reg_mask(priv, 0x22, u8tmp1 << 6, 0xc0); 397 ret = regmap_update_bits(dev->regmap, 0x22, 0xc0, u8tmp1 << 6);
362 if (ret) 398 if (ret)
363 goto err; 399 goto err;
364 ret = m88ds3103_wr_reg_mask(priv, 0x24, u8tmp2 << 6, 0xc0); 400 ret = regmap_update_bits(dev->regmap, 0x24, 0xc0, u8tmp2 << 6);
365 if (ret) 401 if (ret)
366 goto err; 402 goto err;
367 } 403 }
368 404
369 ret = m88ds3103_wr_reg(priv, 0xb2, 0x01); 405 ret = regmap_write(dev->regmap, 0xb2, 0x01);
370 if (ret) 406 if (ret)
371 goto err; 407 goto err;
372 408
373 ret = m88ds3103_wr_reg(priv, 0x00, 0x01); 409 ret = regmap_write(dev->regmap, 0x00, 0x01);
374 if (ret) 410 if (ret)
375 goto err; 411 goto err;
376 412
377 switch (c->delivery_system) { 413 switch (c->delivery_system) {
378 case SYS_DVBS: 414 case SYS_DVBS:
379 if (priv->chip_id == M88RS6000_CHIP_ID) { 415 if (dev->chip_id == M88RS6000_CHIP_ID) {
380 len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals); 416 len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals);
381 init = m88rs6000_dvbs_init_reg_vals; 417 init = m88rs6000_dvbs_init_reg_vals;
382 } else { 418 } else {
@@ -385,7 +421,7 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
385 } 421 }
386 break; 422 break;
387 case SYS_DVBS2: 423 case SYS_DVBS2:
388 if (priv->chip_id == M88RS6000_CHIP_ID) { 424 if (dev->chip_id == M88RS6000_CHIP_ID) {
389 len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals); 425 len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals);
390 init = m88rs6000_dvbs2_init_reg_vals; 426 init = m88rs6000_dvbs2_init_reg_vals;
391 } else { 427 } else {
@@ -394,44 +430,43 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
394 } 430 }
395 break; 431 break;
396 default: 432 default:
397 dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n", 433 dev_dbg(&client->dev, "invalid delivery_system\n");
398 __func__);
399 ret = -EINVAL; 434 ret = -EINVAL;
400 goto err; 435 goto err;
401 } 436 }
402 437
403 /* program init table */ 438 /* program init table */
404 if (c->delivery_system != priv->delivery_system) { 439 if (c->delivery_system != dev->delivery_system) {
405 ret = m88ds3103_wr_reg_val_tab(priv, init, len); 440 ret = m88ds3103_wr_reg_val_tab(dev, init, len);
406 if (ret) 441 if (ret)
407 goto err; 442 goto err;
408 } 443 }
409 444
410 if (priv->chip_id == M88RS6000_CHIP_ID) { 445 if (dev->chip_id == M88RS6000_CHIP_ID) {
411 if ((c->delivery_system == SYS_DVBS2) 446 if ((c->delivery_system == SYS_DVBS2)
412 && ((c->symbol_rate / 1000) <= 5000)) { 447 && ((c->symbol_rate / 1000) <= 5000)) {
413 ret = m88ds3103_wr_reg(priv, 0xc0, 0x04); 448 ret = regmap_write(dev->regmap, 0xc0, 0x04);
414 if (ret) 449 if (ret)
415 goto err; 450 goto err;
416 buf[0] = 0x09; 451 buf[0] = 0x09;
417 buf[1] = 0x22; 452 buf[1] = 0x22;
418 buf[2] = 0x88; 453 buf[2] = 0x88;
419 ret = m88ds3103_wr_regs(priv, 0x8a, buf, 3); 454 ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3);
420 if (ret) 455 if (ret)
421 goto err; 456 goto err;
422 } 457 }
423 ret = m88ds3103_wr_reg_mask(priv, 0x9d, 0x08, 0x08); 458 ret = regmap_update_bits(dev->regmap, 0x9d, 0x08, 0x08);
424 if (ret) 459 if (ret)
425 goto err; 460 goto err;
426 ret = m88ds3103_wr_reg(priv, 0xf1, 0x01); 461 ret = regmap_write(dev->regmap, 0xf1, 0x01);
427 if (ret) 462 if (ret)
428 goto err; 463 goto err;
429 ret = m88ds3103_wr_reg_mask(priv, 0x30, 0x80, 0x80); 464 ret = regmap_update_bits(dev->regmap, 0x30, 0x80, 0x80);
430 if (ret) 465 if (ret)
431 goto err; 466 goto err;
432 } 467 }
433 468
434 switch (priv->cfg->ts_mode) { 469 switch (dev->cfg->ts_mode) {
435 case M88DS3103_TS_SERIAL: 470 case M88DS3103_TS_SERIAL:
436 u8tmp1 = 0x00; 471 u8tmp1 = 0x00;
437 u8tmp = 0x06; 472 u8tmp = 0x06;
@@ -447,39 +482,39 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
447 u8tmp = 0x03; 482 u8tmp = 0x03;
448 break; 483 break;
449 default: 484 default:
450 dev_dbg(&priv->i2c->dev, "%s: invalid ts_mode\n", __func__); 485 dev_dbg(&client->dev, "invalid ts_mode\n");
451 ret = -EINVAL; 486 ret = -EINVAL;
452 goto err; 487 goto err;
453 } 488 }
454 489
455 if (priv->cfg->ts_clk_pol) 490 if (dev->cfg->ts_clk_pol)
456 u8tmp |= 0x40; 491 u8tmp |= 0x40;
457 492
458 /* TS mode */ 493 /* TS mode */
459 ret = m88ds3103_wr_reg(priv, 0xfd, u8tmp); 494 ret = regmap_write(dev->regmap, 0xfd, u8tmp);
460 if (ret) 495 if (ret)
461 goto err; 496 goto err;
462 497
463 switch (priv->cfg->ts_mode) { 498 switch (dev->cfg->ts_mode) {
464 case M88DS3103_TS_SERIAL: 499 case M88DS3103_TS_SERIAL:
465 case M88DS3103_TS_SERIAL_D7: 500 case M88DS3103_TS_SERIAL_D7:
466 ret = m88ds3103_wr_reg_mask(priv, 0x29, u8tmp1, 0x20); 501 ret = regmap_update_bits(dev->regmap, 0x29, 0x20, u8tmp1);
467 if (ret) 502 if (ret)
468 goto err; 503 goto err;
469 u8tmp1 = 0; 504 u8tmp1 = 0;
470 u8tmp2 = 0; 505 u8tmp2 = 0;
471 break; 506 break;
472 default: 507 default:
473 if (priv->cfg->ts_clk) { 508 if (dev->cfg->ts_clk) {
474 divide_ratio = DIV_ROUND_UP(target_mclk, priv->cfg->ts_clk); 509 divide_ratio = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk);
475 u8tmp1 = divide_ratio / 2; 510 u8tmp1 = divide_ratio / 2;
476 u8tmp2 = DIV_ROUND_UP(divide_ratio, 2); 511 u8tmp2 = DIV_ROUND_UP(divide_ratio, 2);
477 } 512 }
478 } 513 }
479 514
480 dev_dbg(&priv->i2c->dev, 515 dev_dbg(&client->dev,
481 "%s: target_mclk=%d ts_clk=%d divide_ratio=%d\n", 516 "target_mclk=%d ts_clk=%d divide_ratio=%d\n",
482 __func__, target_mclk, priv->cfg->ts_clk, divide_ratio); 517 target_mclk, dev->cfg->ts_clk, divide_ratio);
483 518
484 u8tmp1--; 519 u8tmp1--;
485 u8tmp2--; 520 u8tmp2--;
@@ -488,17 +523,17 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
488 /* u8tmp2[5:0] => ea[5:0] */ 523 /* u8tmp2[5:0] => ea[5:0] */
489 u8tmp2 &= 0x3f; 524 u8tmp2 &= 0x3f;
490 525
491 ret = m88ds3103_rd_reg(priv, 0xfe, &u8tmp); 526 ret = regmap_bulk_read(dev->regmap, 0xfe, &u8tmp, 1);
492 if (ret) 527 if (ret)
493 goto err; 528 goto err;
494 529
495 u8tmp = ((u8tmp & 0xf0) << 0) | u8tmp1 >> 2; 530 u8tmp = ((u8tmp & 0xf0) << 0) | u8tmp1 >> 2;
496 ret = m88ds3103_wr_reg(priv, 0xfe, u8tmp); 531 ret = regmap_write(dev->regmap, 0xfe, u8tmp);
497 if (ret) 532 if (ret)
498 goto err; 533 goto err;
499 534
500 u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; 535 u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0;
501 ret = m88ds3103_wr_reg(priv, 0xea, u8tmp); 536 ret = regmap_write(dev->regmap, 0xea, u8tmp);
502 if (ret) 537 if (ret)
503 goto err; 538 goto err;
504 539
@@ -509,250 +544,254 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
509 else 544 else
510 u8tmp = 0x06; 545 u8tmp = 0x06;
511 546
512 ret = m88ds3103_wr_reg(priv, 0xc3, 0x08); 547 ret = regmap_write(dev->regmap, 0xc3, 0x08);
513 if (ret) 548 if (ret)
514 goto err; 549 goto err;
515 550
516 ret = m88ds3103_wr_reg(priv, 0xc8, u8tmp); 551 ret = regmap_write(dev->regmap, 0xc8, u8tmp);
517 if (ret) 552 if (ret)
518 goto err; 553 goto err;
519 554
520 ret = m88ds3103_wr_reg(priv, 0xc4, 0x08); 555 ret = regmap_write(dev->regmap, 0xc4, 0x08);
521 if (ret) 556 if (ret)
522 goto err; 557 goto err;
523 558
524 ret = m88ds3103_wr_reg(priv, 0xc7, 0x00); 559 ret = regmap_write(dev->regmap, 0xc7, 0x00);
525 if (ret) 560 if (ret)
526 goto err; 561 goto err;
527 562
528 u16tmp = DIV_ROUND_CLOSEST((c->symbol_rate / 1000) << 15, priv->mclk_khz / 2); 563 u16tmp = DIV_ROUND_CLOSEST((c->symbol_rate / 1000) << 15, dev->mclk_khz / 2);
529 buf[0] = (u16tmp >> 0) & 0xff; 564 buf[0] = (u16tmp >> 0) & 0xff;
530 buf[1] = (u16tmp >> 8) & 0xff; 565 buf[1] = (u16tmp >> 8) & 0xff;
531 ret = m88ds3103_wr_regs(priv, 0x61, buf, 2); 566 ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2);
532 if (ret) 567 if (ret)
533 goto err; 568 goto err;
534 569
535 ret = m88ds3103_wr_reg_mask(priv, 0x4d, priv->cfg->spec_inv << 1, 0x02); 570 ret = regmap_update_bits(dev->regmap, 0x4d, 0x02, dev->cfg->spec_inv << 1);
536 if (ret) 571 if (ret)
537 goto err; 572 goto err;
538 573
539 ret = m88ds3103_wr_reg_mask(priv, 0x30, priv->cfg->agc_inv << 4, 0x10); 574 ret = regmap_update_bits(dev->regmap, 0x30, 0x10, dev->cfg->agc_inv << 4);
540 if (ret) 575 if (ret)
541 goto err; 576 goto err;
542 577
543 ret = m88ds3103_wr_reg(priv, 0x33, priv->cfg->agc); 578 ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc);
544 if (ret) 579 if (ret)
545 goto err; 580 goto err;
546 581
547 dev_dbg(&priv->i2c->dev, "%s: carrier offset=%d\n", __func__, 582 dev_dbg(&client->dev, "carrier offset=%d\n",
548 (tuner_frequency - c->frequency)); 583 (tuner_frequency - c->frequency));
549 584
550 s32tmp = 0x10000 * (tuner_frequency - c->frequency); 585 s32tmp = 0x10000 * (tuner_frequency - c->frequency);
551 s32tmp = DIV_ROUND_CLOSEST(s32tmp, priv->mclk_khz); 586 s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk_khz);
552 if (s32tmp < 0) 587 if (s32tmp < 0)
553 s32tmp += 0x10000; 588 s32tmp += 0x10000;
554 589
555 buf[0] = (s32tmp >> 0) & 0xff; 590 buf[0] = (s32tmp >> 0) & 0xff;
556 buf[1] = (s32tmp >> 8) & 0xff; 591 buf[1] = (s32tmp >> 8) & 0xff;
557 ret = m88ds3103_wr_regs(priv, 0x5e, buf, 2); 592 ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2);
558 if (ret) 593 if (ret)
559 goto err; 594 goto err;
560 595
561 ret = m88ds3103_wr_reg(priv, 0x00, 0x00); 596 ret = regmap_write(dev->regmap, 0x00, 0x00);
562 if (ret) 597 if (ret)
563 goto err; 598 goto err;
564 599
565 ret = m88ds3103_wr_reg(priv, 0xb2, 0x00); 600 ret = regmap_write(dev->regmap, 0xb2, 0x00);
566 if (ret) 601 if (ret)
567 goto err; 602 goto err;
568 603
569 priv->delivery_system = c->delivery_system; 604 dev->delivery_system = c->delivery_system;
570 605
571 return 0; 606 return 0;
572err: 607err:
573 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 608 dev_dbg(&client->dev, "failed=%d\n", ret);
574 return ret; 609 return ret;
575} 610}
576 611
577static int m88ds3103_init(struct dvb_frontend *fe) 612static int m88ds3103_init(struct dvb_frontend *fe)
578{ 613{
579 struct m88ds3103_priv *priv = fe->demodulator_priv; 614 struct m88ds3103_dev *dev = fe->demodulator_priv;
615 struct i2c_client *client = dev->client;
616 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
580 int ret, len, remaining; 617 int ret, len, remaining;
618 unsigned int utmp;
581 const struct firmware *fw = NULL; 619 const struct firmware *fw = NULL;
582 u8 *fw_file; 620 u8 *fw_file;
583 u8 u8tmp;
584 621
585 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 622 dev_dbg(&client->dev, "\n");
586 623
587 /* set cold state by default */ 624 /* set cold state by default */
588 priv->warm = false; 625 dev->warm = false;
589 626
590 /* wake up device from sleep */ 627 /* wake up device from sleep */
591 ret = m88ds3103_wr_reg_mask(priv, 0x08, 0x01, 0x01); 628 ret = regmap_update_bits(dev->regmap, 0x08, 0x01, 0x01);
592 if (ret) 629 if (ret)
593 goto err; 630 goto err;
594 631 ret = regmap_update_bits(dev->regmap, 0x04, 0x01, 0x00);
595 ret = m88ds3103_wr_reg_mask(priv, 0x04, 0x00, 0x01);
596 if (ret) 632 if (ret)
597 goto err; 633 goto err;
598 634 ret = regmap_update_bits(dev->regmap, 0x23, 0x10, 0x00);
599 ret = m88ds3103_wr_reg_mask(priv, 0x23, 0x00, 0x10);
600 if (ret) 635 if (ret)
601 goto err; 636 goto err;
602 637
603 /* firmware status */ 638 /* firmware status */
604 ret = m88ds3103_rd_reg(priv, 0xb9, &u8tmp); 639 ret = regmap_read(dev->regmap, 0xb9, &utmp);
605 if (ret) 640 if (ret)
606 goto err; 641 goto err;
607 642
608 dev_dbg(&priv->i2c->dev, "%s: firmware=%02x\n", __func__, u8tmp); 643 dev_dbg(&client->dev, "firmware=%02x\n", utmp);
609 644
610 if (u8tmp) 645 if (utmp)
611 goto skip_fw_download; 646 goto skip_fw_download;
612 647
613 /* global reset, global diseqc reset, golbal fec reset */ 648 /* global reset, global diseqc reset, golbal fec reset */
614 ret = m88ds3103_wr_reg(priv, 0x07, 0xe0); 649 ret = regmap_write(dev->regmap, 0x07, 0xe0);
615 if (ret) 650 if (ret)
616 goto err; 651 goto err;
617 652 ret = regmap_write(dev->regmap, 0x07, 0x00);
618 ret = m88ds3103_wr_reg(priv, 0x07, 0x00);
619 if (ret) 653 if (ret)
620 goto err; 654 goto err;
621 655
622 /* cold state - try to download firmware */ 656 /* cold state - try to download firmware */
623 dev_info(&priv->i2c->dev, "%s: found a '%s' in cold state\n", 657 dev_info(&client->dev, "found a '%s' in cold state\n",
624 KBUILD_MODNAME, m88ds3103_ops.info.name); 658 m88ds3103_ops.info.name);
625 659
626 if (priv->chip_id == M88RS6000_CHIP_ID) 660 if (dev->chip_id == M88RS6000_CHIP_ID)
627 fw_file = M88RS6000_FIRMWARE; 661 fw_file = M88RS6000_FIRMWARE;
628 else 662 else
629 fw_file = M88DS3103_FIRMWARE; 663 fw_file = M88DS3103_FIRMWARE;
630 /* request the firmware, this will block and timeout */ 664 /* request the firmware, this will block and timeout */
631 ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent); 665 ret = request_firmware(&fw, fw_file, &client->dev);
632 if (ret) { 666 if (ret) {
633 dev_err(&priv->i2c->dev, "%s: firmware file '%s' not found\n", 667 dev_err(&client->dev, "firmare file '%s' not found\n", fw_file);
634 KBUILD_MODNAME, fw_file);
635 goto err; 668 goto err;
636 } 669 }
637 670
638 dev_info(&priv->i2c->dev, "%s: downloading firmware from file '%s'\n", 671 dev_info(&client->dev, "downloading firmware from file '%s'\n",
639 KBUILD_MODNAME, fw_file); 672 fw_file);
640 673
641 ret = m88ds3103_wr_reg(priv, 0xb2, 0x01); 674 ret = regmap_write(dev->regmap, 0xb2, 0x01);
642 if (ret) 675 if (ret)
643 goto error_fw_release; 676 goto error_fw_release;
644 677
645 for (remaining = fw->size; remaining > 0; 678 for (remaining = fw->size; remaining > 0;
646 remaining -= (priv->cfg->i2c_wr_max - 1)) { 679 remaining -= (dev->cfg->i2c_wr_max - 1)) {
647 len = remaining; 680 len = remaining;
648 if (len > (priv->cfg->i2c_wr_max - 1)) 681 if (len > (dev->cfg->i2c_wr_max - 1))
649 len = (priv->cfg->i2c_wr_max - 1); 682 len = (dev->cfg->i2c_wr_max - 1);
650 683
651 ret = m88ds3103_wr_regs(priv, 0xb0, 684 ret = regmap_bulk_write(dev->regmap, 0xb0,
652 &fw->data[fw->size - remaining], len); 685 &fw->data[fw->size - remaining], len);
653 if (ret) { 686 if (ret) {
654 dev_err(&priv->i2c->dev, 687 dev_err(&client->dev, "firmware download failed=%d\n",
655 "%s: firmware download failed=%d\n", 688 ret);
656 KBUILD_MODNAME, ret);
657 goto error_fw_release; 689 goto error_fw_release;
658 } 690 }
659 } 691 }
660 692
661 ret = m88ds3103_wr_reg(priv, 0xb2, 0x00); 693 ret = regmap_write(dev->regmap, 0xb2, 0x00);
662 if (ret) 694 if (ret)
663 goto error_fw_release; 695 goto error_fw_release;
664 696
665 release_firmware(fw); 697 release_firmware(fw);
666 fw = NULL; 698 fw = NULL;
667 699
668 ret = m88ds3103_rd_reg(priv, 0xb9, &u8tmp); 700 ret = regmap_read(dev->regmap, 0xb9, &utmp);
669 if (ret) 701 if (ret)
670 goto err; 702 goto err;
671 703
672 if (!u8tmp) { 704 if (!utmp) {
673 dev_info(&priv->i2c->dev, "%s: firmware did not run\n", 705 dev_info(&client->dev, "firmware did not run\n");
674 KBUILD_MODNAME);
675 ret = -EFAULT; 706 ret = -EFAULT;
676 goto err; 707 goto err;
677 } 708 }
678 709
679 dev_info(&priv->i2c->dev, "%s: found a '%s' in warm state\n", 710 dev_info(&client->dev, "found a '%s' in warm state\n",
680 KBUILD_MODNAME, m88ds3103_ops.info.name); 711 m88ds3103_ops.info.name);
681 dev_info(&priv->i2c->dev, "%s: firmware version %X.%X\n", 712 dev_info(&client->dev, "firmware version: %X.%X\n",
682 KBUILD_MODNAME, (u8tmp >> 4) & 0xf, (u8tmp >> 0 & 0xf)); 713 (utmp >> 4) & 0xf, (utmp >> 0 & 0xf));
683 714
684skip_fw_download: 715skip_fw_download:
685 /* warm state */ 716 /* warm state */
686 priv->warm = true; 717 dev->warm = true;
687 718
688 return 0; 719 /* init stats here in order signal app which stats are supported */
720 c->cnr.len = 1;
721 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
722 c->post_bit_error.len = 1;
723 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
724 c->post_bit_count.len = 1;
725 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
689 726
727 return 0;
690error_fw_release: 728error_fw_release:
691 release_firmware(fw); 729 release_firmware(fw);
692err: 730err:
693 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 731 dev_dbg(&client->dev, "failed=%d\n", ret);
694 return ret; 732 return ret;
695} 733}
696 734
697static int m88ds3103_sleep(struct dvb_frontend *fe) 735static int m88ds3103_sleep(struct dvb_frontend *fe)
698{ 736{
699 struct m88ds3103_priv *priv = fe->demodulator_priv; 737 struct m88ds3103_dev *dev = fe->demodulator_priv;
738 struct i2c_client *client = dev->client;
700 int ret; 739 int ret;
701 u8 u8tmp; 740 unsigned int utmp;
702 741
703 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 742 dev_dbg(&client->dev, "\n");
704 743
705 priv->delivery_system = SYS_UNDEFINED; 744 dev->fe_status = 0;
745 dev->delivery_system = SYS_UNDEFINED;
706 746
707 /* TS Hi-Z */ 747 /* TS Hi-Z */
708 if (priv->chip_id == M88RS6000_CHIP_ID) 748 if (dev->chip_id == M88RS6000_CHIP_ID)
709 u8tmp = 0x29; 749 utmp = 0x29;
710 else 750 else
711 u8tmp = 0x27; 751 utmp = 0x27;
712 ret = m88ds3103_wr_reg_mask(priv, u8tmp, 0x00, 0x01); 752 ret = regmap_update_bits(dev->regmap, utmp, 0x01, 0x00);
713 if (ret) 753 if (ret)
714 goto err; 754 goto err;
715 755
716 /* sleep */ 756 /* sleep */
717 ret = m88ds3103_wr_reg_mask(priv, 0x08, 0x00, 0x01); 757 ret = regmap_update_bits(dev->regmap, 0x08, 0x01, 0x00);
718 if (ret) 758 if (ret)
719 goto err; 759 goto err;
720 760 ret = regmap_update_bits(dev->regmap, 0x04, 0x01, 0x01);
721 ret = m88ds3103_wr_reg_mask(priv, 0x04, 0x01, 0x01);
722 if (ret) 761 if (ret)
723 goto err; 762 goto err;
724 763 ret = regmap_update_bits(dev->regmap, 0x23, 0x10, 0x10);
725 ret = m88ds3103_wr_reg_mask(priv, 0x23, 0x10, 0x10);
726 if (ret) 764 if (ret)
727 goto err; 765 goto err;
728 766
729 return 0; 767 return 0;
730err: 768err:
731 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 769 dev_dbg(&client->dev, "failed=%d\n", ret);
732 return ret; 770 return ret;
733} 771}
734 772
735static int m88ds3103_get_frontend(struct dvb_frontend *fe) 773static int m88ds3103_get_frontend(struct dvb_frontend *fe)
736{ 774{
737 struct m88ds3103_priv *priv = fe->demodulator_priv; 775 struct m88ds3103_dev *dev = fe->demodulator_priv;
776 struct i2c_client *client = dev->client;
738 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 777 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
739 int ret; 778 int ret;
740 u8 buf[3]; 779 u8 buf[3];
741 780
742 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 781 dev_dbg(&client->dev, "\n");
743 782
744 if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { 783 if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
745 ret = -EAGAIN; 784 ret = 0;
746 goto err; 785 goto err;
747 } 786 }
748 787
749 switch (c->delivery_system) { 788 switch (c->delivery_system) {
750 case SYS_DVBS: 789 case SYS_DVBS:
751 ret = m88ds3103_rd_reg(priv, 0xe0, &buf[0]); 790 ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1);
752 if (ret) 791 if (ret)
753 goto err; 792 goto err;
754 793
755 ret = m88ds3103_rd_reg(priv, 0xe6, &buf[1]); 794 ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1);
756 if (ret) 795 if (ret)
757 goto err; 796 goto err;
758 797
@@ -782,23 +821,22 @@ static int m88ds3103_get_frontend(struct dvb_frontend *fe)
782 c->fec_inner = FEC_1_2; 821 c->fec_inner = FEC_1_2;
783 break; 822 break;
784 default: 823 default:
785 dev_dbg(&priv->i2c->dev, "%s: invalid fec_inner\n", 824 dev_dbg(&client->dev, "invalid fec_inner\n");
786 __func__);
787 } 825 }
788 826
789 c->modulation = QPSK; 827 c->modulation = QPSK;
790 828
791 break; 829 break;
792 case SYS_DVBS2: 830 case SYS_DVBS2:
793 ret = m88ds3103_rd_reg(priv, 0x7e, &buf[0]); 831 ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1);
794 if (ret) 832 if (ret)
795 goto err; 833 goto err;
796 834
797 ret = m88ds3103_rd_reg(priv, 0x89, &buf[1]); 835 ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1);
798 if (ret) 836 if (ret)
799 goto err; 837 goto err;
800 838
801 ret = m88ds3103_rd_reg(priv, 0xf2, &buf[2]); 839 ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1);
802 if (ret) 840 if (ret)
803 goto err; 841 goto err;
804 842
@@ -831,8 +869,7 @@ static int m88ds3103_get_frontend(struct dvb_frontend *fe)
831 c->fec_inner = FEC_9_10; 869 c->fec_inner = FEC_9_10;
832 break; 870 break;
833 default: 871 default:
834 dev_dbg(&priv->i2c->dev, "%s: invalid fec_inner\n", 872 dev_dbg(&client->dev, "invalid fec_inner\n");
835 __func__);
836 } 873 }
837 874
838 switch ((buf[0] >> 5) & 0x01) { 875 switch ((buf[0] >> 5) & 0x01) {
@@ -858,8 +895,7 @@ static int m88ds3103_get_frontend(struct dvb_frontend *fe)
858 c->modulation = APSK_32; 895 c->modulation = APSK_32;
859 break; 896 break;
860 default: 897 default:
861 dev_dbg(&priv->i2c->dev, "%s: invalid modulation\n", 898 dev_dbg(&client->dev, "invalid modulation\n");
862 __func__);
863 } 899 }
864 900
865 switch ((buf[1] >> 7) & 0x01) { 901 switch ((buf[1] >> 7) & 0x01) {
@@ -882,201 +918,60 @@ static int m88ds3103_get_frontend(struct dvb_frontend *fe)
882 c->rolloff = ROLLOFF_20; 918 c->rolloff = ROLLOFF_20;
883 break; 919 break;
884 default: 920 default:
885 dev_dbg(&priv->i2c->dev, "%s: invalid rolloff\n", 921 dev_dbg(&client->dev, "invalid rolloff\n");
886 __func__);
887 } 922 }
888 break; 923 break;
889 default: 924 default:
890 dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n", 925 dev_dbg(&client->dev, "invalid delivery_system\n");
891 __func__);
892 ret = -EINVAL; 926 ret = -EINVAL;
893 goto err; 927 goto err;
894 } 928 }
895 929
896 ret = m88ds3103_rd_regs(priv, 0x6d, buf, 2); 930 ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2);
897 if (ret) 931 if (ret)
898 goto err; 932 goto err;
899 933
900 c->symbol_rate = 1ull * ((buf[1] << 8) | (buf[0] << 0)) * 934 c->symbol_rate = 1ull * ((buf[1] << 8) | (buf[0] << 0)) *
901 priv->mclk_khz * 1000 / 0x10000; 935 dev->mclk_khz * 1000 / 0x10000;
902 936
903 return 0; 937 return 0;
904err: 938err:
905 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 939 dev_dbg(&client->dev, "failed=%d\n", ret);
906 return ret; 940 return ret;
907} 941}
908 942
909static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr) 943static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr)
910{ 944{
911 struct m88ds3103_priv *priv = fe->demodulator_priv;
912 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 945 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
913 int ret, i, tmp;
914 u8 buf[3];
915 u16 noise, signal;
916 u32 noise_tot, signal_tot;
917
918 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
919 /* reports SNR in resolution of 0.1 dB */
920
921 /* more iterations for more accurate estimation */
922 #define M88DS3103_SNR_ITERATIONS 3
923
924 switch (c->delivery_system) {
925 case SYS_DVBS:
926 tmp = 0;
927 946
928 for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 947 if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
929 ret = m88ds3103_rd_reg(priv, 0xff, &buf[0]); 948 *snr = div_s64(c->cnr.stat[0].svalue, 100);
930 if (ret) 949 else
931 goto err; 950 *snr = 0;
932
933 tmp += buf[0];
934 }
935
936 /* use of one register limits max value to 15 dB */
937 /* SNR(X) dB = 10 * ln(X) / ln(10) dB */
938 tmp = DIV_ROUND_CLOSEST(tmp, 8 * M88DS3103_SNR_ITERATIONS);
939 if (tmp)
940 *snr = div_u64((u64) 100 * intlog2(tmp), intlog2(10));
941 else
942 *snr = 0;
943 break;
944 case SYS_DVBS2:
945 noise_tot = 0;
946 signal_tot = 0;
947
948 for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) {
949 ret = m88ds3103_rd_regs(priv, 0x8c, buf, 3);
950 if (ret)
951 goto err;
952
953 noise = buf[1] << 6; /* [13:6] */
954 noise |= buf[0] & 0x3f; /* [5:0] */
955 noise >>= 2;
956 signal = buf[2] * buf[2];
957 signal >>= 1;
958
959 noise_tot += noise;
960 signal_tot += signal;
961 }
962
963 noise = noise_tot / M88DS3103_SNR_ITERATIONS;
964 signal = signal_tot / M88DS3103_SNR_ITERATIONS;
965
966 /* SNR(X) dB = 10 * log10(X) dB */
967 if (signal > noise) {
968 tmp = signal / noise;
969 *snr = div_u64((u64) 100 * intlog10(tmp), (1 << 24));
970 } else {
971 *snr = 0;
972 }
973 break;
974 default:
975 dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n",
976 __func__);
977 ret = -EINVAL;
978 goto err;
979 }
980 951
981 return 0; 952 return 0;
982err:
983 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
984 return ret;
985} 953}
986 954
987static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber) 955static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber)
988{ 956{
989 struct m88ds3103_priv *priv = fe->demodulator_priv; 957 struct m88ds3103_dev *dev = fe->demodulator_priv;
990 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
991 int ret;
992 unsigned int utmp;
993 u8 buf[3], u8tmp;
994
995 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
996
997 switch (c->delivery_system) {
998 case SYS_DVBS:
999 ret = m88ds3103_wr_reg(priv, 0xf9, 0x04);
1000 if (ret)
1001 goto err;
1002
1003 ret = m88ds3103_rd_reg(priv, 0xf8, &u8tmp);
1004 if (ret)
1005 goto err;
1006
1007 if (!(u8tmp & 0x10)) {
1008 u8tmp |= 0x10;
1009
1010 ret = m88ds3103_rd_regs(priv, 0xf6, buf, 2);
1011 if (ret)
1012 goto err;
1013
1014 priv->ber = (buf[1] << 8) | (buf[0] << 0);
1015
1016 /* restart counters */
1017 ret = m88ds3103_wr_reg(priv, 0xf8, u8tmp);
1018 if (ret)
1019 goto err;
1020 }
1021 break;
1022 case SYS_DVBS2:
1023 ret = m88ds3103_rd_regs(priv, 0xd5, buf, 3);
1024 if (ret)
1025 goto err;
1026
1027 utmp = (buf[2] << 16) | (buf[1] << 8) | (buf[0] << 0);
1028
1029 if (utmp > 3000) {
1030 ret = m88ds3103_rd_regs(priv, 0xf7, buf, 2);
1031 if (ret)
1032 goto err;
1033
1034 priv->ber = (buf[1] << 8) | (buf[0] << 0);
1035
1036 /* restart counters */
1037 ret = m88ds3103_wr_reg(priv, 0xd1, 0x01);
1038 if (ret)
1039 goto err;
1040
1041 ret = m88ds3103_wr_reg(priv, 0xf9, 0x01);
1042 if (ret)
1043 goto err;
1044
1045 ret = m88ds3103_wr_reg(priv, 0xf9, 0x00);
1046 if (ret)
1047 goto err;
1048
1049 ret = m88ds3103_wr_reg(priv, 0xd1, 0x00);
1050 if (ret)
1051 goto err;
1052 }
1053 break;
1054 default:
1055 dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n",
1056 __func__);
1057 ret = -EINVAL;
1058 goto err;
1059 }
1060 958
1061 *ber = priv->ber; 959 *ber = dev->dvbv3_ber;
1062 960
1063 return 0; 961 return 0;
1064err:
1065 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
1066 return ret;
1067} 962}
1068 963
1069static int m88ds3103_set_tone(struct dvb_frontend *fe, 964static int m88ds3103_set_tone(struct dvb_frontend *fe,
1070 fe_sec_tone_mode_t fe_sec_tone_mode) 965 enum fe_sec_tone_mode fe_sec_tone_mode)
1071{ 966{
1072 struct m88ds3103_priv *priv = fe->demodulator_priv; 967 struct m88ds3103_dev *dev = fe->demodulator_priv;
968 struct i2c_client *client = dev->client;
1073 int ret; 969 int ret;
1074 u8 u8tmp, tone, reg_a1_mask; 970 unsigned int utmp, tone, reg_a1_mask;
1075 971
1076 dev_dbg(&priv->i2c->dev, "%s: fe_sec_tone_mode=%d\n", __func__, 972 dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode);
1077 fe_sec_tone_mode);
1078 973
1079 if (!priv->warm) { 974 if (!dev->warm) {
1080 ret = -EAGAIN; 975 ret = -EAGAIN;
1081 goto err; 976 goto err;
1082 } 977 }
@@ -1091,40 +986,39 @@ static int m88ds3103_set_tone(struct dvb_frontend *fe,
1091 reg_a1_mask = 0x00; 986 reg_a1_mask = 0x00;
1092 break; 987 break;
1093 default: 988 default:
1094 dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_tone_mode\n", 989 dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n");
1095 __func__);
1096 ret = -EINVAL; 990 ret = -EINVAL;
1097 goto err; 991 goto err;
1098 } 992 }
1099 993
1100 u8tmp = tone << 7 | priv->cfg->envelope_mode << 5; 994 utmp = tone << 7 | dev->cfg->envelope_mode << 5;
1101 ret = m88ds3103_wr_reg_mask(priv, 0xa2, u8tmp, 0xe0); 995 ret = regmap_update_bits(dev->regmap, 0xa2, 0xe0, utmp);
1102 if (ret) 996 if (ret)
1103 goto err; 997 goto err;
1104 998
1105 u8tmp = 1 << 2; 999 utmp = 1 << 2;
1106 ret = m88ds3103_wr_reg_mask(priv, 0xa1, u8tmp, reg_a1_mask); 1000 ret = regmap_update_bits(dev->regmap, 0xa1, reg_a1_mask, utmp);
1107 if (ret) 1001 if (ret)
1108 goto err; 1002 goto err;
1109 1003
1110 return 0; 1004 return 0;
1111err: 1005err:
1112 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1006 dev_dbg(&client->dev, "failed=%d\n", ret);
1113 return ret; 1007 return ret;
1114} 1008}
1115 1009
1116static int m88ds3103_set_voltage(struct dvb_frontend *fe, 1010static int m88ds3103_set_voltage(struct dvb_frontend *fe,
1117 fe_sec_voltage_t fe_sec_voltage) 1011 enum fe_sec_voltage fe_sec_voltage)
1118{ 1012{
1119 struct m88ds3103_priv *priv = fe->demodulator_priv; 1013 struct m88ds3103_dev *dev = fe->demodulator_priv;
1014 struct i2c_client *client = dev->client;
1120 int ret; 1015 int ret;
1121 u8 u8tmp; 1016 unsigned int utmp;
1122 bool voltage_sel, voltage_dis; 1017 bool voltage_sel, voltage_dis;
1123 1018
1124 dev_dbg(&priv->i2c->dev, "%s: fe_sec_voltage=%d\n", __func__, 1019 dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage);
1125 fe_sec_voltage);
1126 1020
1127 if (!priv->warm) { 1021 if (!dev->warm) {
1128 ret = -EAGAIN; 1022 ret = -EAGAIN;
1129 goto err; 1023 goto err;
1130 } 1024 }
@@ -1143,38 +1037,39 @@ static int m88ds3103_set_voltage(struct dvb_frontend *fe,
1143 voltage_dis = true; 1037 voltage_dis = true;
1144 break; 1038 break;
1145 default: 1039 default:
1146 dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_voltage\n", 1040 dev_dbg(&client->dev, "invalid fe_sec_voltage\n");
1147 __func__);
1148 ret = -EINVAL; 1041 ret = -EINVAL;
1149 goto err; 1042 goto err;
1150 } 1043 }
1151 1044
1152 /* output pin polarity */ 1045 /* output pin polarity */
1153 voltage_sel ^= priv->cfg->lnb_hv_pol; 1046 voltage_sel ^= dev->cfg->lnb_hv_pol;
1154 voltage_dis ^= priv->cfg->lnb_en_pol; 1047 voltage_dis ^= dev->cfg->lnb_en_pol;
1155 1048
1156 u8tmp = voltage_dis << 1 | voltage_sel << 0; 1049 utmp = voltage_dis << 1 | voltage_sel << 0;
1157 ret = m88ds3103_wr_reg_mask(priv, 0xa2, u8tmp, 0x03); 1050 ret = regmap_update_bits(dev->regmap, 0xa2, 0x03, utmp);
1158 if (ret) 1051 if (ret)
1159 goto err; 1052 goto err;
1160 1053
1161 return 0; 1054 return 0;
1162err: 1055err:
1163 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1056 dev_dbg(&client->dev, "failed=%d\n", ret);
1164 return ret; 1057 return ret;
1165} 1058}
1166 1059
1167static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe, 1060static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe,
1168 struct dvb_diseqc_master_cmd *diseqc_cmd) 1061 struct dvb_diseqc_master_cmd *diseqc_cmd)
1169{ 1062{
1170 struct m88ds3103_priv *priv = fe->demodulator_priv; 1063 struct m88ds3103_dev *dev = fe->demodulator_priv;
1171 int ret, i; 1064 struct i2c_client *client = dev->client;
1172 u8 u8tmp; 1065 int ret;
1066 unsigned int utmp;
1067 unsigned long timeout;
1173 1068
1174 dev_dbg(&priv->i2c->dev, "%s: msg=%*ph\n", __func__, 1069 dev_dbg(&client->dev, "msg=%*ph\n",
1175 diseqc_cmd->msg_len, diseqc_cmd->msg); 1070 diseqc_cmd->msg_len, diseqc_cmd->msg);
1176 1071
1177 if (!priv->warm) { 1072 if (!dev->warm) {
1178 ret = -EAGAIN; 1073 ret = -EAGAIN;
1179 goto err; 1074 goto err;
1180 } 1075 }
@@ -1184,75 +1079,80 @@ static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe,
1184 goto err; 1079 goto err;
1185 } 1080 }
1186 1081
1187 u8tmp = priv->cfg->envelope_mode << 5; 1082 utmp = dev->cfg->envelope_mode << 5;
1188 ret = m88ds3103_wr_reg_mask(priv, 0xa2, u8tmp, 0xe0); 1083 ret = regmap_update_bits(dev->regmap, 0xa2, 0xe0, utmp);
1189 if (ret) 1084 if (ret)
1190 goto err; 1085 goto err;
1191 1086
1192 ret = m88ds3103_wr_regs(priv, 0xa3, diseqc_cmd->msg, 1087 ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg,
1193 diseqc_cmd->msg_len); 1088 diseqc_cmd->msg_len);
1194 if (ret) 1089 if (ret)
1195 goto err; 1090 goto err;
1196 1091
1197 ret = m88ds3103_wr_reg(priv, 0xa1, 1092 ret = regmap_write(dev->regmap, 0xa1,
1198 (diseqc_cmd->msg_len - 1) << 3 | 0x07); 1093 (diseqc_cmd->msg_len - 1) << 3 | 0x07);
1199 if (ret) 1094 if (ret)
1200 goto err; 1095 goto err;
1201 1096
1202 /* DiSEqC message typical period is 54 ms */
1203 usleep_range(40000, 60000);
1204
1205 /* wait DiSEqC TX ready */ 1097 /* wait DiSEqC TX ready */
1206 for (i = 20, u8tmp = 1; i && u8tmp; i--) { 1098 #define SEND_MASTER_CMD_TIMEOUT 120
1207 usleep_range(5000, 10000); 1099 timeout = jiffies + msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT);
1100
1101 /* DiSEqC message typical period is 54 ms */
1102 usleep_range(50000, 54000);
1208 1103
1209 ret = m88ds3103_rd_reg_mask(priv, 0xa1, &u8tmp, 0x40); 1104 for (utmp = 1; !time_after(jiffies, timeout) && utmp;) {
1105 ret = regmap_read(dev->regmap, 0xa1, &utmp);
1210 if (ret) 1106 if (ret)
1211 goto err; 1107 goto err;
1108 utmp = (utmp >> 6) & 0x1;
1212 } 1109 }
1213 1110
1214 dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); 1111 if (utmp == 0) {
1215 1112 dev_dbg(&client->dev, "diseqc tx took %u ms\n",
1216 if (i == 0) { 1113 jiffies_to_msecs(jiffies) -
1217 dev_dbg(&priv->i2c->dev, "%s: diseqc tx timeout\n", __func__); 1114 (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT));
1115 } else {
1116 dev_dbg(&client->dev, "diseqc tx timeout\n");
1218 1117
1219 ret = m88ds3103_wr_reg_mask(priv, 0xa1, 0x40, 0xc0); 1118 ret = regmap_update_bits(dev->regmap, 0xa1, 0xc0, 0x40);
1220 if (ret) 1119 if (ret)
1221 goto err; 1120 goto err;
1222 } 1121 }
1223 1122
1224 ret = m88ds3103_wr_reg_mask(priv, 0xa2, 0x80, 0xc0); 1123 ret = regmap_update_bits(dev->regmap, 0xa2, 0xc0, 0x80);
1225 if (ret) 1124 if (ret)
1226 goto err; 1125 goto err;
1227 1126
1228 if (i == 0) { 1127 if (utmp == 1) {
1229 ret = -ETIMEDOUT; 1128 ret = -ETIMEDOUT;
1230 goto err; 1129 goto err;
1231 } 1130 }
1232 1131
1233 return 0; 1132 return 0;
1234err: 1133err:
1235 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1134 dev_dbg(&client->dev, "failed=%d\n", ret);
1236 return ret; 1135 return ret;
1237} 1136}
1238 1137
1239static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe, 1138static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe,
1240 fe_sec_mini_cmd_t fe_sec_mini_cmd) 1139 enum fe_sec_mini_cmd fe_sec_mini_cmd)
1241{ 1140{
1242 struct m88ds3103_priv *priv = fe->demodulator_priv; 1141 struct m88ds3103_dev *dev = fe->demodulator_priv;
1243 int ret, i; 1142 struct i2c_client *client = dev->client;
1244 u8 u8tmp, burst; 1143 int ret;
1144 unsigned int utmp, burst;
1145 unsigned long timeout;
1245 1146
1246 dev_dbg(&priv->i2c->dev, "%s: fe_sec_mini_cmd=%d\n", __func__, 1147 dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd);
1247 fe_sec_mini_cmd);
1248 1148
1249 if (!priv->warm) { 1149 if (!dev->warm) {
1250 ret = -EAGAIN; 1150 ret = -EAGAIN;
1251 goto err; 1151 goto err;
1252 } 1152 }
1253 1153
1254 u8tmp = priv->cfg->envelope_mode << 5; 1154 utmp = dev->cfg->envelope_mode << 5;
1255 ret = m88ds3103_wr_reg_mask(priv, 0xa2, u8tmp, 0xe0); 1155 ret = regmap_update_bits(dev->regmap, 0xa2, 0xe0, utmp);
1256 if (ret) 1156 if (ret)
1257 goto err; 1157 goto err;
1258 1158
@@ -1264,43 +1164,53 @@ static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe,
1264 burst = 0x01; 1164 burst = 0x01;
1265 break; 1165 break;
1266 default: 1166 default:
1267 dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_mini_cmd\n", 1167 dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n");
1268 __func__);
1269 ret = -EINVAL; 1168 ret = -EINVAL;
1270 goto err; 1169 goto err;
1271 } 1170 }
1272 1171
1273 ret = m88ds3103_wr_reg(priv, 0xa1, burst); 1172 ret = regmap_write(dev->regmap, 0xa1, burst);
1274 if (ret) 1173 if (ret)
1275 goto err; 1174 goto err;
1276 1175
1277 /* DiSEqC ToneBurst period is 12.5 ms */
1278 usleep_range(11000, 20000);
1279
1280 /* wait DiSEqC TX ready */ 1176 /* wait DiSEqC TX ready */
1281 for (i = 5, u8tmp = 1; i && u8tmp; i--) { 1177 #define SEND_BURST_TIMEOUT 40
1282 usleep_range(800, 2000); 1178 timeout = jiffies + msecs_to_jiffies(SEND_BURST_TIMEOUT);
1283 1179
1284 ret = m88ds3103_rd_reg_mask(priv, 0xa1, &u8tmp, 0x40); 1180 /* DiSEqC ToneBurst period is 12.5 ms */
1181 usleep_range(8500, 12500);
1182
1183 for (utmp = 1; !time_after(jiffies, timeout) && utmp;) {
1184 ret = regmap_read(dev->regmap, 0xa1, &utmp);
1285 if (ret) 1185 if (ret)
1286 goto err; 1186 goto err;
1187 utmp = (utmp >> 6) & 0x1;
1287 } 1188 }
1288 1189
1289 dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); 1190 if (utmp == 0) {
1191 dev_dbg(&client->dev, "diseqc tx took %u ms\n",
1192 jiffies_to_msecs(jiffies) -
1193 (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT));
1194 } else {
1195 dev_dbg(&client->dev, "diseqc tx timeout\n");
1290 1196
1291 ret = m88ds3103_wr_reg_mask(priv, 0xa2, 0x80, 0xc0); 1197 ret = regmap_update_bits(dev->regmap, 0xa1, 0xc0, 0x40);
1198 if (ret)
1199 goto err;
1200 }
1201
1202 ret = regmap_update_bits(dev->regmap, 0xa2, 0xc0, 0x80);
1292 if (ret) 1203 if (ret)
1293 goto err; 1204 goto err;
1294 1205
1295 if (i == 0) { 1206 if (utmp == 1) {
1296 dev_dbg(&priv->i2c->dev, "%s: diseqc tx timeout\n", __func__);
1297 ret = -ETIMEDOUT; 1207 ret = -ETIMEDOUT;
1298 goto err; 1208 goto err;
1299 } 1209 }
1300 1210
1301 return 0; 1211 return 0;
1302err: 1212err:
1303 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1213 dev_dbg(&client->dev, "failed=%d\n", ret);
1304 return ret; 1214 return ret;
1305} 1215}
1306 1216
@@ -1314,193 +1224,290 @@ static int m88ds3103_get_tune_settings(struct dvb_frontend *fe,
1314 1224
1315static void m88ds3103_release(struct dvb_frontend *fe) 1225static void m88ds3103_release(struct dvb_frontend *fe)
1316{ 1226{
1317 struct m88ds3103_priv *priv = fe->demodulator_priv; 1227 struct m88ds3103_dev *dev = fe->demodulator_priv;
1228 struct i2c_client *client = dev->client;
1318 1229
1319 i2c_del_mux_adapter(priv->i2c_adapter); 1230 i2c_unregister_device(client);
1320 kfree(priv);
1321} 1231}
1322 1232
1323static int m88ds3103_select(struct i2c_adapter *adap, void *mux_priv, u32 chan) 1233static int m88ds3103_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
1324{ 1234{
1325 struct m88ds3103_priv *priv = mux_priv; 1235 struct m88ds3103_dev *dev = mux_priv;
1236 struct i2c_client *client = dev->client;
1326 int ret; 1237 int ret;
1327 struct i2c_msg gate_open_msg[1] = { 1238 struct i2c_msg msg = {
1328 { 1239 .addr = client->addr,
1329 .addr = priv->cfg->i2c_addr, 1240 .flags = 0,
1330 .flags = 0, 1241 .len = 2,
1331 .len = 2, 1242 .buf = "\x03\x11",
1332 .buf = "\x03\x11",
1333 }
1334 }; 1243 };
1335 1244
1336 mutex_lock(&priv->i2c_mutex); 1245 /* Open tuner I2C repeater for 1 xfer, closes automatically */
1337 1246 ret = __i2c_transfer(client->adapter, &msg, 1);
1338 /* open tuner I2C repeater for 1 xfer, closes automatically */
1339 ret = __i2c_transfer(priv->i2c, gate_open_msg, 1);
1340 if (ret != 1) { 1247 if (ret != 1) {
1341 dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d\n", 1248 dev_warn(&client->dev, "i2c wr failed=%d\n", ret);
1342 KBUILD_MODNAME, ret);
1343 if (ret >= 0) 1249 if (ret >= 0)
1344 ret = -EREMOTEIO; 1250 ret = -EREMOTEIO;
1345
1346 return ret; 1251 return ret;
1347 } 1252 }
1348 1253
1349 return 0; 1254 return 0;
1350} 1255}
1351 1256
1352static int m88ds3103_deselect(struct i2c_adapter *adap, void *mux_priv, 1257/*
1353 u32 chan) 1258 * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide
1259 * proper I2C client for legacy media attach binding.
1260 * New users must use I2C client binding directly!
1261 */
1262struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg,
1263 struct i2c_adapter *i2c, struct i2c_adapter **tuner_i2c_adapter)
1354{ 1264{
1355 struct m88ds3103_priv *priv = mux_priv; 1265 struct i2c_client *client;
1266 struct i2c_board_info board_info;
1267 struct m88ds3103_platform_data pdata;
1268
1269 pdata.clk = cfg->clock;
1270 pdata.i2c_wr_max = cfg->i2c_wr_max;
1271 pdata.ts_mode = cfg->ts_mode;
1272 pdata.ts_clk = cfg->ts_clk;
1273 pdata.ts_clk_pol = cfg->ts_clk_pol;
1274 pdata.spec_inv = cfg->spec_inv;
1275 pdata.agc = cfg->agc;
1276 pdata.agc_inv = cfg->agc_inv;
1277 pdata.clk_out = cfg->clock_out;
1278 pdata.envelope_mode = cfg->envelope_mode;
1279 pdata.lnb_hv_pol = cfg->lnb_hv_pol;
1280 pdata.lnb_en_pol = cfg->lnb_en_pol;
1281 pdata.attach_in_use = true;
1282
1283 memset(&board_info, 0, sizeof(board_info));
1284 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1285 board_info.addr = cfg->i2c_addr;
1286 board_info.platform_data = &pdata;
1287 client = i2c_new_device(i2c, &board_info);
1288 if (!client || !client->dev.driver)
1289 return NULL;
1290
1291 *tuner_i2c_adapter = pdata.get_i2c_adapter(client);
1292 return pdata.get_dvb_frontend(client);
1293}
1294EXPORT_SYMBOL(m88ds3103_attach);
1295
1296static struct dvb_frontend_ops m88ds3103_ops = {
1297 .delsys = {SYS_DVBS, SYS_DVBS2},
1298 .info = {
1299 .name = "Montage Technology M88DS3103",
1300 .frequency_min = 950000,
1301 .frequency_max = 2150000,
1302 .frequency_tolerance = 5000,
1303 .symbol_rate_min = 1000000,
1304 .symbol_rate_max = 45000000,
1305 .caps = FE_CAN_INVERSION_AUTO |
1306 FE_CAN_FEC_1_2 |
1307 FE_CAN_FEC_2_3 |
1308 FE_CAN_FEC_3_4 |
1309 FE_CAN_FEC_4_5 |
1310 FE_CAN_FEC_5_6 |
1311 FE_CAN_FEC_6_7 |
1312 FE_CAN_FEC_7_8 |
1313 FE_CAN_FEC_8_9 |
1314 FE_CAN_FEC_AUTO |
1315 FE_CAN_QPSK |
1316 FE_CAN_RECOVER |
1317 FE_CAN_2G_MODULATION
1318 },
1356 1319
1357 mutex_unlock(&priv->i2c_mutex); 1320 .release = m88ds3103_release,
1358 1321
1359 return 0; 1322 .get_tune_settings = m88ds3103_get_tune_settings,
1323
1324 .init = m88ds3103_init,
1325 .sleep = m88ds3103_sleep,
1326
1327 .set_frontend = m88ds3103_set_frontend,
1328 .get_frontend = m88ds3103_get_frontend,
1329
1330 .read_status = m88ds3103_read_status,
1331 .read_snr = m88ds3103_read_snr,
1332 .read_ber = m88ds3103_read_ber,
1333
1334 .diseqc_send_master_cmd = m88ds3103_diseqc_send_master_cmd,
1335 .diseqc_send_burst = m88ds3103_diseqc_send_burst,
1336
1337 .set_tone = m88ds3103_set_tone,
1338 .set_voltage = m88ds3103_set_voltage,
1339};
1340
1341static struct dvb_frontend *m88ds3103_get_dvb_frontend(struct i2c_client *client)
1342{
1343 struct m88ds3103_dev *dev = i2c_get_clientdata(client);
1344
1345 dev_dbg(&client->dev, "\n");
1346
1347 return &dev->fe;
1360} 1348}
1361 1349
1362struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, 1350static struct i2c_adapter *m88ds3103_get_i2c_adapter(struct i2c_client *client)
1363 struct i2c_adapter *i2c, struct i2c_adapter **tuner_i2c_adapter) 1351{
1352 struct m88ds3103_dev *dev = i2c_get_clientdata(client);
1353
1354 dev_dbg(&client->dev, "\n");
1355
1356 return dev->i2c_adapter;
1357}
1358
1359static int m88ds3103_probe(struct i2c_client *client,
1360 const struct i2c_device_id *id)
1364{ 1361{
1362 struct m88ds3103_dev *dev;
1363 struct m88ds3103_platform_data *pdata = client->dev.platform_data;
1365 int ret; 1364 int ret;
1366 struct m88ds3103_priv *priv; 1365 unsigned int utmp;
1367 u8 chip_id, u8tmp;
1368 1366
1369 /* allocate memory for the internal priv */ 1367 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1370 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1368 if (!dev) {
1371 if (!priv) {
1372 ret = -ENOMEM; 1369 ret = -ENOMEM;
1373 dev_err(&i2c->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
1374 goto err; 1370 goto err;
1375 } 1371 }
1376 1372
1377 priv->cfg = cfg; 1373 dev->client = client;
1378 priv->i2c = i2c; 1374 dev->config.clock = pdata->clk;
1379 mutex_init(&priv->i2c_mutex); 1375 dev->config.i2c_wr_max = pdata->i2c_wr_max;
1376 dev->config.ts_mode = pdata->ts_mode;
1377 dev->config.ts_clk = pdata->ts_clk;
1378 dev->config.ts_clk_pol = pdata->ts_clk_pol;
1379 dev->config.spec_inv = pdata->spec_inv;
1380 dev->config.agc_inv = pdata->agc_inv;
1381 dev->config.clock_out = pdata->clk_out;
1382 dev->config.envelope_mode = pdata->envelope_mode;
1383 dev->config.agc = pdata->agc;
1384 dev->config.lnb_hv_pol = pdata->lnb_hv_pol;
1385 dev->config.lnb_en_pol = pdata->lnb_en_pol;
1386 dev->cfg = &dev->config;
1387 /* create regmap */
1388 dev->regmap_config.reg_bits = 8,
1389 dev->regmap_config.val_bits = 8,
1390 dev->regmap_config.lock_arg = dev,
1391 dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config);
1392 if (IS_ERR(dev->regmap)) {
1393 ret = PTR_ERR(dev->regmap);
1394 goto err_kfree;
1395 }
1380 1396
1381 /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */ 1397 /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */
1382 ret = m88ds3103_rd_reg(priv, 0x00, &chip_id); 1398 ret = regmap_read(dev->regmap, 0x00, &utmp);
1383 if (ret) 1399 if (ret)
1384 goto err; 1400 goto err_kfree;
1385 1401
1386 chip_id >>= 1; 1402 dev->chip_id = utmp >> 1;
1387 dev_info(&priv->i2c->dev, "%s: chip_id=%02x\n", __func__, chip_id); 1403 dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id);
1388 1404
1389 switch (chip_id) { 1405 switch (dev->chip_id) {
1390 case M88RS6000_CHIP_ID: 1406 case M88RS6000_CHIP_ID:
1391 case M88DS3103_CHIP_ID: 1407 case M88DS3103_CHIP_ID:
1392 break; 1408 break;
1393 default: 1409 default:
1394 goto err; 1410 goto err_kfree;
1395 } 1411 }
1396 priv->chip_id = chip_id;
1397 1412
1398 switch (priv->cfg->clock_out) { 1413 switch (dev->cfg->clock_out) {
1399 case M88DS3103_CLOCK_OUT_DISABLED: 1414 case M88DS3103_CLOCK_OUT_DISABLED:
1400 u8tmp = 0x80; 1415 utmp = 0x80;
1401 break; 1416 break;
1402 case M88DS3103_CLOCK_OUT_ENABLED: 1417 case M88DS3103_CLOCK_OUT_ENABLED:
1403 u8tmp = 0x00; 1418 utmp = 0x00;
1404 break; 1419 break;
1405 case M88DS3103_CLOCK_OUT_ENABLED_DIV2: 1420 case M88DS3103_CLOCK_OUT_ENABLED_DIV2:
1406 u8tmp = 0x10; 1421 utmp = 0x10;
1407 break; 1422 break;
1408 default: 1423 default:
1409 goto err; 1424 ret = -EINVAL;
1425 goto err_kfree;
1410 } 1426 }
1411 1427
1412 /* 0x29 register is defined differently for m88rs6000. */ 1428 /* 0x29 register is defined differently for m88rs6000. */
1413 /* set internal tuner address to 0x21 */ 1429 /* set internal tuner address to 0x21 */
1414 if (chip_id == M88RS6000_CHIP_ID) 1430 if (dev->chip_id == M88RS6000_CHIP_ID)
1415 u8tmp = 0x00; 1431 utmp = 0x00;
1416 1432
1417 ret = m88ds3103_wr_reg(priv, 0x29, u8tmp); 1433 ret = regmap_write(dev->regmap, 0x29, utmp);
1418 if (ret) 1434 if (ret)
1419 goto err; 1435 goto err_kfree;
1420 1436
1421 /* sleep */ 1437 /* sleep */
1422 ret = m88ds3103_wr_reg_mask(priv, 0x08, 0x00, 0x01); 1438 ret = regmap_update_bits(dev->regmap, 0x08, 0x01, 0x00);
1423 if (ret) 1439 if (ret)
1424 goto err; 1440 goto err_kfree;
1425 1441 ret = regmap_update_bits(dev->regmap, 0x04, 0x01, 0x01);
1426 ret = m88ds3103_wr_reg_mask(priv, 0x04, 0x01, 0x01);
1427 if (ret) 1442 if (ret)
1428 goto err; 1443 goto err_kfree;
1429 1444 ret = regmap_update_bits(dev->regmap, 0x23, 0x10, 0x10);
1430 ret = m88ds3103_wr_reg_mask(priv, 0x23, 0x10, 0x10);
1431 if (ret) 1445 if (ret)
1432 goto err; 1446 goto err_kfree;
1433 1447
1434 /* create mux i2c adapter for tuner */ 1448 /* create mux i2c adapter for tuner */
1435 priv->i2c_adapter = i2c_add_mux_adapter(i2c, &i2c->dev, priv, 0, 0, 0, 1449 dev->i2c_adapter = i2c_add_mux_adapter(client->adapter, &client->dev,
1436 m88ds3103_select, m88ds3103_deselect); 1450 dev, 0, 0, 0, m88ds3103_select,
1437 if (priv->i2c_adapter == NULL) 1451 NULL);
1438 goto err; 1452 if (dev->i2c_adapter == NULL) {
1439 1453 ret = -ENOMEM;
1440 *tuner_i2c_adapter = priv->i2c_adapter; 1454 goto err_kfree;
1455 }
1441 1456
1442 /* create dvb_frontend */ 1457 /* create dvb_frontend */
1443 memcpy(&priv->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); 1458 memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops));
1444 if (priv->chip_id == M88RS6000_CHIP_ID) 1459 if (dev->chip_id == M88RS6000_CHIP_ID)
1445 strncpy(priv->fe.ops.info.name, 1460 strncpy(dev->fe.ops.info.name, "Montage Technology M88RS6000",
1446 "Montage M88RS6000", sizeof(priv->fe.ops.info.name)); 1461 sizeof(dev->fe.ops.info.name));
1447 priv->fe.demodulator_priv = priv; 1462 if (!pdata->attach_in_use)
1448 1463 dev->fe.ops.release = NULL;
1449 return &priv->fe; 1464 dev->fe.demodulator_priv = dev;
1465 i2c_set_clientdata(client, dev);
1466
1467 /* setup callbacks */
1468 pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend;
1469 pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter;
1470 return 0;
1471err_kfree:
1472 kfree(dev);
1450err: 1473err:
1451 dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 1474 dev_dbg(&client->dev, "failed=%d\n", ret);
1452 kfree(priv); 1475 return ret;
1453 return NULL;
1454} 1476}
1455EXPORT_SYMBOL(m88ds3103_attach);
1456
1457static struct dvb_frontend_ops m88ds3103_ops = {
1458 .delsys = { SYS_DVBS, SYS_DVBS2 },
1459 .info = {
1460 .name = "Montage M88DS3103",
1461 .frequency_min = 950000,
1462 .frequency_max = 2150000,
1463 .frequency_tolerance = 5000,
1464 .symbol_rate_min = 1000000,
1465 .symbol_rate_max = 45000000,
1466 .caps = FE_CAN_INVERSION_AUTO |
1467 FE_CAN_FEC_1_2 |
1468 FE_CAN_FEC_2_3 |
1469 FE_CAN_FEC_3_4 |
1470 FE_CAN_FEC_4_5 |
1471 FE_CAN_FEC_5_6 |
1472 FE_CAN_FEC_6_7 |
1473 FE_CAN_FEC_7_8 |
1474 FE_CAN_FEC_8_9 |
1475 FE_CAN_FEC_AUTO |
1476 FE_CAN_QPSK |
1477 FE_CAN_RECOVER |
1478 FE_CAN_2G_MODULATION
1479 },
1480 1477
1481 .release = m88ds3103_release, 1478static int m88ds3103_remove(struct i2c_client *client)
1479{
1480 struct m88ds3103_dev *dev = i2c_get_clientdata(client);
1482 1481
1483 .get_tune_settings = m88ds3103_get_tune_settings, 1482 dev_dbg(&client->dev, "\n");
1484 1483
1485 .init = m88ds3103_init, 1484 i2c_del_mux_adapter(dev->i2c_adapter);
1486 .sleep = m88ds3103_sleep,
1487 1485
1488 .set_frontend = m88ds3103_set_frontend, 1486 kfree(dev);
1489 .get_frontend = m88ds3103_get_frontend, 1487 return 0;
1490 1488}
1491 .read_status = m88ds3103_read_status,
1492 .read_snr = m88ds3103_read_snr,
1493 .read_ber = m88ds3103_read_ber,
1494 1489
1495 .diseqc_send_master_cmd = m88ds3103_diseqc_send_master_cmd, 1490static const struct i2c_device_id m88ds3103_id_table[] = {
1496 .diseqc_send_burst = m88ds3103_diseqc_send_burst, 1491 {"m88ds3103", 0},
1492 {}
1493};
1494MODULE_DEVICE_TABLE(i2c, m88ds3103_id_table);
1497 1495
1498 .set_tone = m88ds3103_set_tone, 1496static struct i2c_driver m88ds3103_driver = {
1499 .set_voltage = m88ds3103_set_voltage, 1497 .driver = {
1498 .owner = THIS_MODULE,
1499 .name = "m88ds3103",
1500 .suppress_bind_attrs = true,
1501 },
1502 .probe = m88ds3103_probe,
1503 .remove = m88ds3103_remove,
1504 .id_table = m88ds3103_id_table,
1500}; 1505};
1501 1506
1507module_i2c_driver(m88ds3103_driver);
1508
1502MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 1509MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1503MODULE_DESCRIPTION("Montage M88DS3103 DVB-S/S2 demodulator driver"); 1510MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver");
1504MODULE_LICENSE("GPL"); 1511MODULE_LICENSE("GPL");
1505MODULE_FIRMWARE(M88DS3103_FIRMWARE); 1512MODULE_FIRMWARE(M88DS3103_FIRMWARE);
1506MODULE_FIRMWARE(M88RS6000_FIRMWARE); 1513MODULE_FIRMWARE(M88RS6000_FIRMWARE);
diff --git a/drivers/media/dvb-frontends/m88ds3103.h b/drivers/media/dvb-frontends/m88ds3103.h
index 9b3b4962da7c..04b355a005fb 100644
--- a/drivers/media/dvb-frontends/m88ds3103.h
+++ b/drivers/media/dvb-frontends/m88ds3103.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Montage M88DS3103 demodulator driver 2 * Montage Technology M88DS3103/M88RS6000 demodulator driver
3 * 3 *
4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -19,6 +19,63 @@
19 19
20#include <linux/dvb/frontend.h> 20#include <linux/dvb/frontend.h>
21 21
22/*
23 * I2C address
24 * 0x68,
25 */
26
27/**
28 * struct m88ds3103_platform_data - Platform data for the m88ds3103 driver
29 * @clk: Clock frequency.
30 * @i2c_wr_max: Max bytes I2C adapter can write at once.
31 * @ts_mode: TS mode.
32 * @ts_clk: TS clock (KHz).
33 * @ts_clk_pol: TS clk polarity. 1-active at falling edge; 0-active at rising
34 * edge.
35 * @spec_inv: Input spectrum inversion.
36 * @agc: AGC configuration.
37 * @agc_inv: AGC polarity.
38 * @clk_out: Clock output.
39 * @envelope_mode: DiSEqC envelope mode.
40 * @lnb_hv_pol: LNB H/V pin polarity. 0: pin high set to VOLTAGE_18, pin low to
41 * set VOLTAGE_13. 1: pin high set to VOLTAGE_13, pin low to set VOLTAGE_18.
42 * @lnb_en_pol: LNB enable pin polarity. 0: pin high to disable, pin low to
43 * enable. 1: pin high to enable, pin low to disable.
44 * @get_dvb_frontend: Get DVB frontend.
45 * @get_i2c_adapter: Get I2C adapter.
46 */
47
48struct m88ds3103_platform_data {
49 u32 clk;
50 u16 i2c_wr_max;
51#define M88DS3103_TS_SERIAL 0 /* TS output pin D0, normal */
52#define M88DS3103_TS_SERIAL_D7 1 /* TS output pin D7 */
53#define M88DS3103_TS_PARALLEL 2 /* TS Parallel mode */
54#define M88DS3103_TS_CI 3 /* TS CI Mode */
55 u8 ts_mode:2;
56 u32 ts_clk;
57 u8 ts_clk_pol:1;
58 u8 spec_inv:1;
59 u8 agc;
60 u8 agc_inv:1;
61#define M88DS3103_CLOCK_OUT_DISABLED 0
62#define M88DS3103_CLOCK_OUT_ENABLED 1
63#define M88DS3103_CLOCK_OUT_ENABLED_DIV2 2
64 u8 clk_out:2;
65 u8 envelope_mode:1;
66 u8 lnb_hv_pol:1;
67 u8 lnb_en_pol:1;
68
69 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
70 struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
71
72/* private: For legacy media attach wrapper. Do not set value. */
73 u8 attach_in_use:1;
74};
75
76/*
77 * Do not add new m88ds3103_attach() users! Use I2C bindings instead.
78 */
22struct m88ds3103_config { 79struct m88ds3103_config {
23 /* 80 /*
24 * I2C address 81 * I2C address
@@ -113,18 +170,13 @@ struct m88ds3103_config {
113 u8 lnb_en_pol:1; 170 u8 lnb_en_pol:1;
114}; 171};
115 172
116/*
117 * Driver implements own I2C-adapter for tuner I2C access. That's since chip
118 * has I2C-gate control which closes gate automatically after I2C transfer.
119 * Using own I2C adapter we can workaround that.
120 */
121
122#if defined(CONFIG_DVB_M88DS3103) || \ 173#if defined(CONFIG_DVB_M88DS3103) || \
123 (defined(CONFIG_DVB_M88DS3103_MODULE) && defined(MODULE)) 174 (defined(CONFIG_DVB_M88DS3103_MODULE) && defined(MODULE))
124extern struct dvb_frontend *m88ds3103_attach( 175extern struct dvb_frontend *m88ds3103_attach(
125 const struct m88ds3103_config *config, 176 const struct m88ds3103_config *config,
126 struct i2c_adapter *i2c, 177 struct i2c_adapter *i2c,
127 struct i2c_adapter **tuner_i2c); 178 struct i2c_adapter **tuner_i2c);
179extern int m88ds3103_get_agc_pwm(struct dvb_frontend *fe, u8 *_agc_pwm);
128#else 180#else
129static inline struct dvb_frontend *m88ds3103_attach( 181static inline struct dvb_frontend *m88ds3103_attach(
130 const struct m88ds3103_config *config, 182 const struct m88ds3103_config *config,
@@ -134,6 +186,7 @@ static inline struct dvb_frontend *m88ds3103_attach(
134 pr_warn("%s: driver disabled by Kconfig\n", __func__); 186 pr_warn("%s: driver disabled by Kconfig\n", __func__);
135 return NULL; 187 return NULL;
136} 188}
189#define m88ds3103_get_agc_pwm NULL
137#endif 190#endif
138 191
139#endif 192#endif
diff --git a/drivers/media/dvb-frontends/m88ds3103_priv.h b/drivers/media/dvb-frontends/m88ds3103_priv.h
index a2c0958111f8..eee8c22c51ec 100644
--- a/drivers/media/dvb-frontends/m88ds3103_priv.h
+++ b/drivers/media/dvb-frontends/m88ds3103_priv.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Montage M88DS3103 demodulator driver 2 * Montage Technology M88DS3103/M88RS6000 demodulator driver
3 * 3 *
4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -22,6 +22,7 @@
22#include "dvb_math.h" 22#include "dvb_math.h"
23#include <linux/firmware.h> 23#include <linux/firmware.h>
24#include <linux/i2c-mux.h> 24#include <linux/i2c-mux.h>
25#include <linux/regmap.h>
25#include <linux/math64.h> 26#include <linux/math64.h>
26 27
27#define M88DS3103_FIRMWARE "dvb-demod-m88ds3103.fw" 28#define M88DS3103_FIRMWARE "dvb-demod-m88ds3103.fw"
@@ -30,21 +31,24 @@
30#define M88RS6000_CHIP_ID 0x74 31#define M88RS6000_CHIP_ID 0x74
31#define M88DS3103_CHIP_ID 0x70 32#define M88DS3103_CHIP_ID 0x70
32 33
33struct m88ds3103_priv { 34struct m88ds3103_dev {
34 struct i2c_adapter *i2c; 35 struct i2c_client *client;
35 /* mutex needed due to own tuner I2C adapter */ 36 struct regmap_config regmap_config;
36 struct mutex i2c_mutex; 37 struct regmap *regmap;
38 struct m88ds3103_config config;
37 const struct m88ds3103_config *cfg; 39 const struct m88ds3103_config *cfg;
38 struct dvb_frontend fe; 40 struct dvb_frontend fe;
39 fe_delivery_system_t delivery_system; 41 enum fe_delivery_system delivery_system;
40 fe_status_t fe_status; 42 enum fe_status fe_status;
41 u32 ber; 43 u32 dvbv3_ber; /* for old DVBv3 API read_ber */
42 bool warm; /* FW running */ 44 bool warm; /* FW running */
43 struct i2c_adapter *i2c_adapter; 45 struct i2c_adapter *i2c_adapter;
44 /* auto detect chip id to do different config */ 46 /* auto detect chip id to do different config */
45 u8 chip_id; 47 u8 chip_id;
46 /* main mclk is calculated for M88RS6000 dynamically */ 48 /* main mclk is calculated for M88RS6000 dynamically */
47 u32 mclk_khz; 49 u32 mclk_khz;
50 u64 post_bit_error;
51 u64 post_bit_count;
48}; 52};
49 53
50struct m88ds3103_reg_val { 54struct m88ds3103_reg_val {
diff --git a/drivers/media/dvb-frontends/m88rs2000.c b/drivers/media/dvb-frontends/m88rs2000.c
index d63bc9c13dce..9b6f464c48bd 100644
--- a/drivers/media/dvb-frontends/m88rs2000.c
+++ b/drivers/media/dvb-frontends/m88rs2000.c
@@ -41,7 +41,7 @@ struct m88rs2000_state {
41 u8 no_lock_count; 41 u8 no_lock_count;
42 u32 tuner_frequency; 42 u32 tuner_frequency;
43 u32 symbol_rate; 43 u32 symbol_rate;
44 fe_code_rate_t fec_inner; 44 enum fe_code_rate fec_inner;
45 u8 tuner_level; 45 u8 tuner_level;
46 int errmode; 46 int errmode;
47}; 47};
@@ -247,7 +247,7 @@ static int m88rs2000_send_diseqc_msg(struct dvb_frontend *fe,
247} 247}
248 248
249static int m88rs2000_send_diseqc_burst(struct dvb_frontend *fe, 249static int m88rs2000_send_diseqc_burst(struct dvb_frontend *fe,
250 fe_sec_mini_cmd_t burst) 250 enum fe_sec_mini_cmd burst)
251{ 251{
252 struct m88rs2000_state *state = fe->demodulator_priv; 252 struct m88rs2000_state *state = fe->demodulator_priv;
253 u8 reg0, reg1; 253 u8 reg0, reg1;
@@ -264,7 +264,8 @@ static int m88rs2000_send_diseqc_burst(struct dvb_frontend *fe,
264 return 0; 264 return 0;
265} 265}
266 266
267static int m88rs2000_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 267static int m88rs2000_set_tone(struct dvb_frontend *fe,
268 enum fe_sec_tone_mode tone)
268{ 269{
269 struct m88rs2000_state *state = fe->demodulator_priv; 270 struct m88rs2000_state *state = fe->demodulator_priv;
270 u8 reg0, reg1; 271 u8 reg0, reg1;
@@ -412,7 +413,8 @@ static int m88rs2000_tab_set(struct m88rs2000_state *state,
412 return 0; 413 return 0;
413} 414}
414 415
415static int m88rs2000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt) 416static int m88rs2000_set_voltage(struct dvb_frontend *fe,
417 enum fe_sec_voltage volt)
416{ 418{
417 struct m88rs2000_state *state = fe->demodulator_priv; 419 struct m88rs2000_state *state = fe->demodulator_priv;
418 u8 data; 420 u8 data;
@@ -462,7 +464,8 @@ static int m88rs2000_sleep(struct dvb_frontend *fe)
462 return ret; 464 return ret;
463} 465}
464 466
465static int m88rs2000_read_status(struct dvb_frontend *fe, fe_status_t *status) 467static int m88rs2000_read_status(struct dvb_frontend *fe,
468 enum fe_status *status)
466{ 469{
467 struct m88rs2000_state *state = fe->demodulator_priv; 470 struct m88rs2000_state *state = fe->demodulator_priv;
468 u8 reg = m88rs2000_readreg(state, 0x8c); 471 u8 reg = m88rs2000_readreg(state, 0x8c);
@@ -539,7 +542,7 @@ static int m88rs2000_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
539} 542}
540 543
541static int m88rs2000_set_fec(struct m88rs2000_state *state, 544static int m88rs2000_set_fec(struct m88rs2000_state *state,
542 fe_code_rate_t fec) 545 enum fe_code_rate fec)
543{ 546{
544 u8 fec_set, reg; 547 u8 fec_set, reg;
545 int ret; 548 int ret;
@@ -574,7 +577,7 @@ static int m88rs2000_set_fec(struct m88rs2000_state *state,
574 return ret; 577 return ret;
575} 578}
576 579
577static fe_code_rate_t m88rs2000_get_fec(struct m88rs2000_state *state) 580static enum fe_code_rate m88rs2000_get_fec(struct m88rs2000_state *state)
578{ 581{
579 u8 reg; 582 u8 reg;
580 m88rs2000_writereg(state, 0x9a, 0x30); 583 m88rs2000_writereg(state, 0x9a, 0x30);
@@ -606,7 +609,7 @@ static int m88rs2000_set_frontend(struct dvb_frontend *fe)
606{ 609{
607 struct m88rs2000_state *state = fe->demodulator_priv; 610 struct m88rs2000_state *state = fe->demodulator_priv;
608 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 611 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
609 fe_status_t status; 612 enum fe_status status;
610 int i, ret = 0; 613 int i, ret = 0;
611 u32 tuner_freq; 614 u32 tuner_freq;
612 s16 offset = 0; 615 s16 offset = 0;
diff --git a/drivers/media/dvb-frontends/mb86a16.c b/drivers/media/dvb-frontends/mb86a16.c
index 3ddea4471d2b..79bc671e8769 100644
--- a/drivers/media/dvb-frontends/mb86a16.c
+++ b/drivers/media/dvb-frontends/mb86a16.c
@@ -593,7 +593,7 @@ err:
593 return -EREMOTEIO; 593 return -EREMOTEIO;
594} 594}
595 595
596static int mb86a16_read_status(struct dvb_frontend *fe, fe_status_t *status) 596static int mb86a16_read_status(struct dvb_frontend *fe, enum fe_status *status)
597{ 597{
598 u8 stat, stat2; 598 u8 stat, stat2;
599 struct mb86a16_state *state = fe->demodulator_priv; 599 struct mb86a16_state *state = fe->demodulator_priv;
@@ -1562,7 +1562,8 @@ err:
1562 return -EREMOTEIO; 1562 return -EREMOTEIO;
1563} 1563}
1564 1564
1565static int mb86a16_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst) 1565static int mb86a16_send_diseqc_burst(struct dvb_frontend *fe,
1566 enum fe_sec_mini_cmd burst)
1566{ 1567{
1567 struct mb86a16_state *state = fe->demodulator_priv; 1568 struct mb86a16_state *state = fe->demodulator_priv;
1568 1569
@@ -1590,7 +1591,7 @@ err:
1590 return -EREMOTEIO; 1591 return -EREMOTEIO;
1591} 1592}
1592 1593
1593static int mb86a16_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 1594static int mb86a16_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
1594{ 1595{
1595 struct mb86a16_state *state = fe->demodulator_priv; 1596 struct mb86a16_state *state = fe->demodulator_priv;
1596 1597
diff --git a/drivers/media/dvb-frontends/mb86a16.h b/drivers/media/dvb-frontends/mb86a16.h
index e486dc0d8e60..dbd5f43fa128 100644
--- a/drivers/media/dvb-frontends/mb86a16.h
+++ b/drivers/media/dvb-frontends/mb86a16.h
@@ -28,7 +28,8 @@
28struct mb86a16_config { 28struct mb86a16_config {
29 u8 demod_address; 29 u8 demod_address;
30 30
31 int (*set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 31 int (*set_voltage)(struct dvb_frontend *fe,
32 enum fe_sec_voltage voltage);
32}; 33};
33 34
34 35
diff --git a/drivers/media/dvb-frontends/mb86a20s.c b/drivers/media/dvb-frontends/mb86a20s.c
index 8f54c39ca63f..cfc005ee11d8 100644
--- a/drivers/media/dvb-frontends/mb86a20s.c
+++ b/drivers/media/dvb-frontends/mb86a20s.c
@@ -294,7 +294,7 @@ static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,
294 * The functions below assume that gateway lock has already obtained 294 * The functions below assume that gateway lock has already obtained
295 */ 295 */
296 296
297static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status) 297static int mb86a20s_read_status(struct dvb_frontend *fe, enum fe_status *status)
298{ 298{
299 struct mb86a20s_state *state = fe->demodulator_priv; 299 struct mb86a20s_state *state = fe->demodulator_priv;
300 int val; 300 int val;
@@ -1951,7 +1951,7 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)
1951} 1951}
1952 1952
1953static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe, 1953static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,
1954 fe_status_t *status) 1954 enum fe_status *status)
1955{ 1955{
1956 struct mb86a20s_state *state = fe->demodulator_priv; 1956 struct mb86a20s_state *state = fe->demodulator_priv;
1957 int rc, status_nr; 1957 int rc, status_nr;
@@ -2042,7 +2042,7 @@ static int mb86a20s_tune(struct dvb_frontend *fe,
2042 bool re_tune, 2042 bool re_tune,
2043 unsigned int mode_flags, 2043 unsigned int mode_flags,
2044 unsigned int *delay, 2044 unsigned int *delay,
2045 fe_status_t *status) 2045 enum fe_status *status)
2046{ 2046{
2047 struct mb86a20s_state *state = fe->demodulator_priv; 2047 struct mb86a20s_state *state = fe->demodulator_priv;
2048 int rc = 0; 2048 int rc = 0;
diff --git a/drivers/media/dvb-frontends/mb86a20s.h b/drivers/media/dvb-frontends/mb86a20s.h
index f749c8ac5f39..a113282d6956 100644
--- a/drivers/media/dvb-frontends/mb86a20s.h
+++ b/drivers/media/dvb-frontends/mb86a20s.h
@@ -45,7 +45,7 @@ static inline struct dvb_frontend *mb86a20s_attach(
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46 return NULL; 46 return NULL;
47} 47}
48static struct i2c_adapter * 48static inline struct i2c_adapter *
49 mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *fe) 49 mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *fe)
50{ 50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
diff --git a/drivers/media/dvb-frontends/mt312.c b/drivers/media/dvb-frontends/mt312.c
index 2163490c1e6b..c36e6764eead 100644
--- a/drivers/media/dvb-frontends/mt312.c
+++ b/drivers/media/dvb-frontends/mt312.c
@@ -156,7 +156,7 @@ static int mt312_reset(struct mt312_state *state, const u8 full)
156} 156}
157 157
158static int mt312_get_inversion(struct mt312_state *state, 158static int mt312_get_inversion(struct mt312_state *state,
159 fe_spectral_inversion_t *i) 159 enum fe_spectral_inversion *i)
160{ 160{
161 int ret; 161 int ret;
162 u8 vit_mode; 162 u8 vit_mode;
@@ -225,9 +225,9 @@ static int mt312_get_symbol_rate(struct mt312_state *state, u32 *sr)
225 return 0; 225 return 0;
226} 226}
227 227
228static int mt312_get_code_rate(struct mt312_state *state, fe_code_rate_t *cr) 228static int mt312_get_code_rate(struct mt312_state *state, enum fe_code_rate *cr)
229{ 229{
230 const fe_code_rate_t fec_tab[8] = 230 const enum fe_code_rate fec_tab[8] =
231 { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8, 231 { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8,
232 FEC_AUTO, FEC_AUTO }; 232 FEC_AUTO, FEC_AUTO };
233 233
@@ -380,7 +380,8 @@ static int mt312_send_master_cmd(struct dvb_frontend *fe,
380 return 0; 380 return 0;
381} 381}
382 382
383static int mt312_send_burst(struct dvb_frontend *fe, const fe_sec_mini_cmd_t c) 383static int mt312_send_burst(struct dvb_frontend *fe,
384 const enum fe_sec_mini_cmd c)
384{ 385{
385 struct mt312_state *state = fe->demodulator_priv; 386 struct mt312_state *state = fe->demodulator_priv;
386 const u8 mini_tab[2] = { 0x02, 0x03 }; 387 const u8 mini_tab[2] = { 0x02, 0x03 };
@@ -403,7 +404,8 @@ static int mt312_send_burst(struct dvb_frontend *fe, const fe_sec_mini_cmd_t c)
403 return 0; 404 return 0;
404} 405}
405 406
406static int mt312_set_tone(struct dvb_frontend *fe, const fe_sec_tone_mode_t t) 407static int mt312_set_tone(struct dvb_frontend *fe,
408 const enum fe_sec_tone_mode t)
407{ 409{
408 struct mt312_state *state = fe->demodulator_priv; 410 struct mt312_state *state = fe->demodulator_priv;
409 const u8 tone_tab[2] = { 0x01, 0x00 }; 411 const u8 tone_tab[2] = { 0x01, 0x00 };
@@ -426,7 +428,8 @@ static int mt312_set_tone(struct dvb_frontend *fe, const fe_sec_tone_mode_t t)
426 return 0; 428 return 0;
427} 429}
428 430
429static int mt312_set_voltage(struct dvb_frontend *fe, const fe_sec_voltage_t v) 431static int mt312_set_voltage(struct dvb_frontend *fe,
432 const enum fe_sec_voltage v)
430{ 433{
431 struct mt312_state *state = fe->demodulator_priv; 434 struct mt312_state *state = fe->demodulator_priv;
432 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 }; 435 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
@@ -442,7 +445,7 @@ static int mt312_set_voltage(struct dvb_frontend *fe, const fe_sec_voltage_t v)
442 return mt312_writereg(state, DISEQC_MODE, val); 445 return mt312_writereg(state, DISEQC_MODE, val);
443} 446}
444 447
445static int mt312_read_status(struct dvb_frontend *fe, fe_status_t *s) 448static int mt312_read_status(struct dvb_frontend *fe, enum fe_status *s)
446{ 449{
447 struct mt312_state *state = fe->demodulator_priv; 450 struct mt312_state *state = fe->demodulator_priv;
448 int ret; 451 int ret;
diff --git a/drivers/media/dvb-frontends/mt352.c b/drivers/media/dvb-frontends/mt352.c
index 2c3b50e828d7..123bb2f8e4b6 100644
--- a/drivers/media/dvb-frontends/mt352.c
+++ b/drivers/media/dvb-frontends/mt352.c
@@ -417,7 +417,7 @@ static int mt352_get_parameters(struct dvb_frontend* fe)
417 return 0; 417 return 0;
418} 418}
419 419
420static int mt352_read_status(struct dvb_frontend* fe, fe_status_t* status) 420static int mt352_read_status(struct dvb_frontend *fe, enum fe_status *status)
421{ 421{
422 struct mt352_state* state = fe->demodulator_priv; 422 struct mt352_state* state = fe->demodulator_priv;
423 int s0, s1, s3; 423 int s0, s1, s3;
diff --git a/drivers/media/dvb-frontends/nxt200x.c b/drivers/media/dvb-frontends/nxt200x.c
index 8a8e1ecb762d..79c3040912ab 100644
--- a/drivers/media/dvb-frontends/nxt200x.c
+++ b/drivers/media/dvb-frontends/nxt200x.c
@@ -781,7 +781,7 @@ static int nxt200x_setup_frontend_parameters(struct dvb_frontend *fe)
781 return 0; 781 return 0;
782} 782}
783 783
784static int nxt200x_read_status(struct dvb_frontend* fe, fe_status_t* status) 784static int nxt200x_read_status(struct dvb_frontend *fe, enum fe_status *status)
785{ 785{
786 struct nxt200x_state* state = fe->demodulator_priv; 786 struct nxt200x_state* state = fe->demodulator_priv;
787 u8 lock; 787 u8 lock;
diff --git a/drivers/media/dvb-frontends/nxt6000.c b/drivers/media/dvb-frontends/nxt6000.c
index 90ae6c72c0e3..73f9505367ac 100644
--- a/drivers/media/dvb-frontends/nxt6000.c
+++ b/drivers/media/dvb-frontends/nxt6000.c
@@ -109,7 +109,8 @@ static int nxt6000_set_bandwidth(struct nxt6000_state *state, u32 bandwidth)
109 return nxt6000_writereg(state, OFDM_TRL_NOMINALRATE_2, (nominal_rate >> 8) & 0xFF); 109 return nxt6000_writereg(state, OFDM_TRL_NOMINALRATE_2, (nominal_rate >> 8) & 0xFF);
110} 110}
111 111
112static int nxt6000_set_guard_interval(struct nxt6000_state* state, fe_guard_interval_t guard_interval) 112static int nxt6000_set_guard_interval(struct nxt6000_state *state,
113 enum fe_guard_interval guard_interval)
113{ 114{
114 switch (guard_interval) { 115 switch (guard_interval) {
115 116
@@ -131,7 +132,8 @@ static int nxt6000_set_guard_interval(struct nxt6000_state* state, fe_guard_inte
131 } 132 }
132} 133}
133 134
134static int nxt6000_set_inversion(struct nxt6000_state* state, fe_spectral_inversion_t inversion) 135static int nxt6000_set_inversion(struct nxt6000_state *state,
136 enum fe_spectral_inversion inversion)
135{ 137{
136 switch (inversion) { 138 switch (inversion) {
137 139
@@ -147,7 +149,9 @@ static int nxt6000_set_inversion(struct nxt6000_state* state, fe_spectral_invers
147 } 149 }
148} 150}
149 151
150static int nxt6000_set_transmission_mode(struct nxt6000_state* state, fe_transmit_mode_t transmission_mode) 152static int
153nxt6000_set_transmission_mode(struct nxt6000_state *state,
154 enum fe_transmit_mode transmission_mode)
151{ 155{
152 int result; 156 int result;
153 157
@@ -416,7 +420,7 @@ static void nxt6000_dump_status(struct nxt6000_state *state)
416 printk("\n"); 420 printk("\n");
417} 421}
418 422
419static int nxt6000_read_status(struct dvb_frontend* fe, fe_status_t* status) 423static int nxt6000_read_status(struct dvb_frontend *fe, enum fe_status *status)
420{ 424{
421 u8 core_status; 425 u8 core_status;
422 struct nxt6000_state* state = fe->demodulator_priv; 426 struct nxt6000_state* state = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/or51132.c b/drivers/media/dvb-frontends/or51132.c
index cbbd259eacfe..35b1053b3640 100644
--- a/drivers/media/dvb-frontends/or51132.c
+++ b/drivers/media/dvb-frontends/or51132.c
@@ -63,7 +63,7 @@ struct or51132_state
63 struct dvb_frontend frontend; 63 struct dvb_frontend frontend;
64 64
65 /* Demodulator private data */ 65 /* Demodulator private data */
66 fe_modulation_t current_modulation; 66 enum fe_modulation current_modulation;
67 u32 snr; /* Result of last SNR calculation */ 67 u32 snr; /* Result of last SNR calculation */
68 68
69 /* Tuner private data */ 69 /* Tuner private data */
@@ -292,7 +292,7 @@ static int or51132_setmode(struct dvb_frontend* fe)
292#define MOD_FWCLASS_UNKNOWN 0 292#define MOD_FWCLASS_UNKNOWN 0
293#define MOD_FWCLASS_VSB 1 293#define MOD_FWCLASS_VSB 1
294#define MOD_FWCLASS_QAM 2 294#define MOD_FWCLASS_QAM 2
295static int modulation_fw_class(fe_modulation_t modulation) 295static int modulation_fw_class(enum fe_modulation modulation)
296{ 296{
297 switch(modulation) { 297 switch(modulation) {
298 case VSB_8: 298 case VSB_8:
@@ -415,7 +415,7 @@ start:
415 return 0; 415 return 0;
416} 416}
417 417
418static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status) 418static int or51132_read_status(struct dvb_frontend *fe, enum fe_status *status)
419{ 419{
420 struct or51132_state* state = fe->demodulator_priv; 420 struct or51132_state* state = fe->demodulator_priv;
421 int reg; 421 int reg;
diff --git a/drivers/media/dvb-frontends/or51211.c b/drivers/media/dvb-frontends/or51211.c
index 873ea1da844b..e82413b975e6 100644
--- a/drivers/media/dvb-frontends/or51211.c
+++ b/drivers/media/dvb-frontends/or51211.c
@@ -237,7 +237,7 @@ static int or51211_set_parameters(struct dvb_frontend *fe)
237 return 0; 237 return 0;
238} 238}
239 239
240static int or51211_read_status(struct dvb_frontend* fe, fe_status_t* status) 240static int or51211_read_status(struct dvb_frontend *fe, enum fe_status *status)
241{ 241{
242 struct or51211_state* state = fe->demodulator_priv; 242 struct or51211_state* state = fe->demodulator_priv;
243 unsigned char rec_buf[2]; 243 unsigned char rec_buf[2];
diff --git a/drivers/media/dvb-frontends/rtl2830.c b/drivers/media/dvb-frontends/rtl2830.c
index e1b8df62bd59..3d01f4f22aca 100644
--- a/drivers/media/dvb-frontends/rtl2830.c
+++ b/drivers/media/dvb-frontends/rtl2830.c
@@ -392,7 +392,7 @@ err:
392 return ret; 392 return ret;
393} 393}
394 394
395static int rtl2830_read_status(struct dvb_frontend *fe, fe_status_t *status) 395static int rtl2830_read_status(struct dvb_frontend *fe, enum fe_status *status)
396{ 396{
397 struct i2c_client *client = fe->demodulator_priv; 397 struct i2c_client *client = fe->demodulator_priv;
398 struct rtl2830_dev *dev = i2c_get_clientdata(client); 398 struct rtl2830_dev *dev = i2c_get_clientdata(client);
diff --git a/drivers/media/dvb-frontends/rtl2830_priv.h b/drivers/media/dvb-frontends/rtl2830_priv.h
index d50d5376c9c5..cf793f39a09b 100644
--- a/drivers/media/dvb-frontends/rtl2830_priv.h
+++ b/drivers/media/dvb-frontends/rtl2830_priv.h
@@ -34,7 +34,7 @@ struct rtl2830_dev {
34 bool sleeping; 34 bool sleeping;
35 unsigned long filters; 35 unsigned long filters;
36 struct delayed_work stat_work; 36 struct delayed_work stat_work;
37 fe_status_t fe_status; 37 enum fe_status fe_status;
38 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */ 38 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */
39 u64 post_bit_error; 39 u64 post_bit_error;
40 u64 post_bit_count; 40 u64 post_bit_count;
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index b400f7b3c2e7..822ea4b7a7ff 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -358,6 +358,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
358 dev_dbg(&client->dev, "load settings for tuner=%02x\n", 358 dev_dbg(&client->dev, "load settings for tuner=%02x\n",
359 dev->pdata->tuner); 359 dev->pdata->tuner);
360 switch (dev->pdata->tuner) { 360 switch (dev->pdata->tuner) {
361 case RTL2832_TUNER_FC2580:
362 len = ARRAY_SIZE(rtl2832_tuner_init_fc2580);
363 init = rtl2832_tuner_init_fc2580;
364 break;
361 case RTL2832_TUNER_FC0012: 365 case RTL2832_TUNER_FC0012:
362 case RTL2832_TUNER_FC0013: 366 case RTL2832_TUNER_FC0013:
363 len = ARRAY_SIZE(rtl2832_tuner_init_fc0012); 367 len = ARRAY_SIZE(rtl2832_tuner_init_fc0012);
@@ -376,6 +380,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
376 len = ARRAY_SIZE(rtl2832_tuner_init_r820t); 380 len = ARRAY_SIZE(rtl2832_tuner_init_r820t);
377 init = rtl2832_tuner_init_r820t; 381 init = rtl2832_tuner_init_r820t;
378 break; 382 break;
383 case RTL2832_TUNER_SI2157:
384 len = ARRAY_SIZE(rtl2832_tuner_init_si2157);
385 init = rtl2832_tuner_init_si2157;
386 break;
379 default: 387 default:
380 ret = -EINVAL; 388 ret = -EINVAL;
381 goto err; 389 goto err;
@@ -680,7 +688,7 @@ err:
680 return ret; 688 return ret;
681} 689}
682 690
683static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status) 691static int rtl2832_read_status(struct dvb_frontend *fe, enum fe_status *status)
684{ 692{
685 struct rtl2832_dev *dev = fe->demodulator_priv; 693 struct rtl2832_dev *dev = fe->demodulator_priv;
686 struct i2c_client *client = dev->client; 694 struct i2c_client *client = dev->client;
diff --git a/drivers/media/dvb-frontends/rtl2832.h b/drivers/media/dvb-frontends/rtl2832.h
index a8e912e679a5..c29a4c2bf71a 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -41,12 +41,14 @@ struct rtl2832_platform_data {
41 /* 41 /*
42 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver. 42 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver.
43 */ 43 */
44#define RTL2832_TUNER_FC2580 0x21
44#define RTL2832_TUNER_TUA9001 0x24 45#define RTL2832_TUNER_TUA9001 0x24
45#define RTL2832_TUNER_FC0012 0x26 46#define RTL2832_TUNER_FC0012 0x26
46#define RTL2832_TUNER_E4000 0x27 47#define RTL2832_TUNER_E4000 0x27
47#define RTL2832_TUNER_FC0013 0x29 48#define RTL2832_TUNER_FC0013 0x29
48#define RTL2832_TUNER_R820T 0x2a 49#define RTL2832_TUNER_R820T 0x2a
49#define RTL2832_TUNER_R828D 0x2b 50#define RTL2832_TUNER_R828D 0x2b
51#define RTL2832_TUNER_SI2157 0x2c
50 u8 tuner; 52 u8 tuner;
51 53
52 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *); 54 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h b/drivers/media/dvb-frontends/rtl2832_priv.h
index c3a922c37903..5dcd3a41d23f 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -39,7 +39,7 @@ struct rtl2832_dev {
39 struct i2c_adapter *i2c_adapter_tuner; 39 struct i2c_adapter *i2c_adapter_tuner;
40 struct dvb_frontend fe; 40 struct dvb_frontend fe;
41 struct delayed_work stat_work; 41 struct delayed_work stat_work;
42 fe_status_t fe_status; 42 enum fe_status fe_status;
43 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */ 43 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */
44 u64 post_bit_error; 44 u64 post_bit_error;
45 u64 post_bit_count; 45 u64 post_bit_count;
@@ -252,6 +252,30 @@ enum DVBT_REG_BIT_NAME {
252 DVBT_REG_BIT_NAME_ITEM_TERMINATOR, 252 DVBT_REG_BIT_NAME_ITEM_TERMINATOR,
253}; 253};
254 254
255static const struct rtl2832_reg_value rtl2832_tuner_init_fc2580[] = {
256 {DVBT_DAGC_TRG_VAL, 0x39},
257 {DVBT_AGC_TARG_VAL_0, 0x0},
258 {DVBT_AGC_TARG_VAL_8_1, 0x5a},
259 {DVBT_AAGC_LOOP_GAIN, 0x16},
260 {DVBT_LOOP_GAIN2_3_0, 0x6},
261 {DVBT_LOOP_GAIN2_4, 0x1},
262 {DVBT_LOOP_GAIN3, 0x16},
263 {DVBT_VTOP1, 0x35},
264 {DVBT_VTOP2, 0x21},
265 {DVBT_VTOP3, 0x21},
266 {DVBT_KRF1, 0x0},
267 {DVBT_KRF2, 0x40},
268 {DVBT_KRF3, 0x10},
269 {DVBT_KRF4, 0x10},
270 {DVBT_IF_AGC_MIN, 0x80},
271 {DVBT_IF_AGC_MAX, 0x7f},
272 {DVBT_RF_AGC_MIN, 0x9c},
273 {DVBT_RF_AGC_MAX, 0x7f},
274 {DVBT_POLAR_RF_AGC, 0x0},
275 {DVBT_POLAR_IF_AGC, 0x0},
276 {DVBT_AD7_SETTING, 0xe9f4},
277};
278
255static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001[] = { 279static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001[] = {
256 {DVBT_DAGC_TRG_VAL, 0x39}, 280 {DVBT_DAGC_TRG_VAL, 0x39},
257 {DVBT_AGC_TARG_VAL_0, 0x0}, 281 {DVBT_AGC_TARG_VAL_0, 0x0},
@@ -377,4 +401,29 @@ static const struct rtl2832_reg_value rtl2832_tuner_init_r820t[] = {
377 {DVBT_SPEC_INV, 0x1}, 401 {DVBT_SPEC_INV, 0x1},
378}; 402};
379 403
404static const struct rtl2832_reg_value rtl2832_tuner_init_si2157[] = {
405 {DVBT_DAGC_TRG_VAL, 0x39},
406 {DVBT_AGC_TARG_VAL_0, 0x0},
407 {DVBT_AGC_TARG_VAL_8_1, 0x40},
408 {DVBT_AAGC_LOOP_GAIN, 0x16},
409 {DVBT_LOOP_GAIN2_3_0, 0x8},
410 {DVBT_LOOP_GAIN2_4, 0x1},
411 {DVBT_LOOP_GAIN3, 0x18},
412 {DVBT_VTOP1, 0x35},
413 {DVBT_VTOP2, 0x21},
414 {DVBT_VTOP3, 0x21},
415 {DVBT_KRF1, 0x0},
416 {DVBT_KRF2, 0x40},
417 {DVBT_KRF3, 0x10},
418 {DVBT_KRF4, 0x10},
419 {DVBT_IF_AGC_MIN, 0x80},
420 {DVBT_IF_AGC_MAX, 0x7f},
421 {DVBT_RF_AGC_MIN, 0x80},
422 {DVBT_RF_AGC_MAX, 0x7f},
423 {DVBT_POLAR_RF_AGC, 0x0},
424 {DVBT_POLAR_IF_AGC, 0x0},
425 {DVBT_AD7_SETTING, 0xe9f4},
426 {DVBT_SPEC_INV, 0x0},
427};
428
380#endif /* RTL2832_PRIV_H */ 429#endif /* RTL2832_PRIV_H */
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 3ff8806ca584..7edb885ae9c8 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -39,6 +39,10 @@ static bool rtl2832_sdr_emulated_fmt;
39module_param_named(emulated_formats, rtl2832_sdr_emulated_fmt, bool, 0644); 39module_param_named(emulated_formats, rtl2832_sdr_emulated_fmt, bool, 0644);
40MODULE_PARM_DESC(emulated_formats, "enable emulated formats (disappears in future)"); 40MODULE_PARM_DESC(emulated_formats, "enable emulated formats (disappears in future)");
41 41
42/* Original macro does not contain enough null pointer checks for our need */
43#define V4L2_SUBDEV_HAS_OP(sd, o, f) \
44 ((sd) && (sd)->ops && (sd)->ops->o && (sd)->ops->o->f)
45
42#define MAX_BULK_BUFS (10) 46#define MAX_BULK_BUFS (10)
43#define BULK_BUFFER_SIZE (128 * 512) 47#define BULK_BUFFER_SIZE (128 * 512)
44 48
@@ -108,14 +112,15 @@ struct rtl2832_sdr_frame_buf {
108}; 112};
109 113
110struct rtl2832_sdr_dev { 114struct rtl2832_sdr_dev {
111#define POWER_ON (1 << 1) 115#define POWER_ON 0 /* BIT(0) */
112#define URB_BUF (1 << 2) 116#define URB_BUF 1 /* BIT(1) */
113 unsigned long flags; 117 unsigned long flags;
114 118
115 struct platform_device *pdev; 119 struct platform_device *pdev;
116 120
117 struct video_device vdev; 121 struct video_device vdev;
118 struct v4l2_device v4l2_dev; 122 struct v4l2_device v4l2_dev;
123 struct v4l2_subdev *v4l2_subdev;
119 124
120 /* videobuf2 queue and queued buffers list */ 125 /* videobuf2 queue and queued buffers list */
121 struct vb2_queue vb_queue; 126 struct vb2_queue vb_queue;
@@ -351,7 +356,7 @@ static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
351{ 356{
352 struct platform_device *pdev = dev->pdev; 357 struct platform_device *pdev = dev->pdev;
353 358
354 if (dev->flags & USB_STATE_URB_BUF) { 359 if (test_bit(URB_BUF, &dev->flags)) {
355 while (dev->buf_num) { 360 while (dev->buf_num) {
356 dev->buf_num--; 361 dev->buf_num--;
357 dev_dbg(&pdev->dev, "free buf=%d\n", dev->buf_num); 362 dev_dbg(&pdev->dev, "free buf=%d\n", dev->buf_num);
@@ -360,7 +365,7 @@ static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
360 dev->dma_addr[dev->buf_num]); 365 dev->dma_addr[dev->buf_num]);
361 } 366 }
362 } 367 }
363 dev->flags &= ~USB_STATE_URB_BUF; 368 clear_bit(URB_BUF, &dev->flags);
364 369
365 return 0; 370 return 0;
366} 371}
@@ -389,7 +394,7 @@ static int rtl2832_sdr_alloc_stream_bufs(struct rtl2832_sdr_dev *dev)
389 dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n", 394 dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n",
390 dev->buf_num, dev->buf_list[dev->buf_num], 395 dev->buf_num, dev->buf_list[dev->buf_num],
391 (long long)dev->dma_addr[dev->buf_num]); 396 (long long)dev->dma_addr[dev->buf_num]);
392 dev->flags |= USB_STATE_URB_BUF; 397 set_bit(URB_BUF, &dev->flags);
393 } 398 }
394 399
395 return 0; 400 return 0;
@@ -742,6 +747,29 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_dev *dev)
742 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1); 747 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
743 ret = rtl2832_sdr_wr_regs(dev, 0x011, "\xf4", 1); 748 ret = rtl2832_sdr_wr_regs(dev, 0x011, "\xf4", 1);
744 break; 749 break;
750 case RTL2832_SDR_TUNER_FC2580:
751 ret = rtl2832_sdr_wr_regs(dev, 0x112, "\x39", 1);
752 ret = rtl2832_sdr_wr_regs(dev, 0x102, "\x40", 1);
753 ret = rtl2832_sdr_wr_regs(dev, 0x103, "\x5a", 1);
754 ret = rtl2832_sdr_wr_regs(dev, 0x1c7, "\x2c", 1);
755 ret = rtl2832_sdr_wr_regs(dev, 0x104, "\xcc", 1);
756 ret = rtl2832_sdr_wr_regs(dev, 0x105, "\xbe", 1);
757 ret = rtl2832_sdr_wr_regs(dev, 0x1c8, "\x16", 1);
758 ret = rtl2832_sdr_wr_regs(dev, 0x106, "\x35", 1);
759 ret = rtl2832_sdr_wr_regs(dev, 0x1c9, "\x21", 1);
760 ret = rtl2832_sdr_wr_regs(dev, 0x1ca, "\x21", 1);
761 ret = rtl2832_sdr_wr_regs(dev, 0x1cb, "\x00", 1);
762 ret = rtl2832_sdr_wr_regs(dev, 0x107, "\x40", 1);
763 ret = rtl2832_sdr_wr_regs(dev, 0x1cd, "\x10", 1);
764 ret = rtl2832_sdr_wr_regs(dev, 0x1ce, "\x10", 1);
765 ret = rtl2832_sdr_wr_regs(dev, 0x108, "\x80", 1);
766 ret = rtl2832_sdr_wr_regs(dev, 0x109, "\x7f", 1);
767 ret = rtl2832_sdr_wr_regs(dev, 0x10a, "\x9c", 1);
768 ret = rtl2832_sdr_wr_regs(dev, 0x10b, "\x7f", 1);
769 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
770 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
771 ret = rtl2832_sdr_wr_regs(dev, 0x011, "\xe9\xf4", 2);
772 break;
745 default: 773 default:
746 dev_notice(&pdev->dev, "Unsupported tuner\n"); 774 dev_notice(&pdev->dev, "Unsupported tuner\n");
747 } 775 }
@@ -832,8 +860,10 @@ static int rtl2832_sdr_set_tuner_freq(struct rtl2832_sdr_dev *dev)
832 if (!test_bit(POWER_ON, &dev->flags)) 860 if (!test_bit(POWER_ON, &dev->flags))
833 return 0; 861 return 0;
834 862
835 if (fe->ops.tuner_ops.set_params) 863 if (!V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, s_frequency)) {
836 fe->ops.tuner_ops.set_params(fe); 864 if (fe->ops.tuner_ops.set_params)
865 fe->ops.tuner_ops.set_params(fe);
866 }
837 867
838 return 0; 868 return 0;
839}; 869};
@@ -891,7 +921,11 @@ static int rtl2832_sdr_start_streaming(struct vb2_queue *vq, unsigned int count)
891 921
892 set_bit(POWER_ON, &dev->flags); 922 set_bit(POWER_ON, &dev->flags);
893 923
894 ret = rtl2832_sdr_set_tuner(dev); 924 /* wake-up tuner */
925 if (V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, core, s_power))
926 ret = v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 1);
927 else
928 ret = rtl2832_sdr_set_tuner(dev);
895 if (ret) 929 if (ret)
896 goto err; 930 goto err;
897 931
@@ -939,7 +973,12 @@ static void rtl2832_sdr_stop_streaming(struct vb2_queue *vq)
939 rtl2832_sdr_free_stream_bufs(dev); 973 rtl2832_sdr_free_stream_bufs(dev);
940 rtl2832_sdr_cleanup_queued_bufs(dev); 974 rtl2832_sdr_cleanup_queued_bufs(dev);
941 rtl2832_sdr_unset_adc(dev); 975 rtl2832_sdr_unset_adc(dev);
942 rtl2832_sdr_unset_tuner(dev); 976
977 /* sleep tuner */
978 if (V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, core, s_power))
979 v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 0);
980 else
981 rtl2832_sdr_unset_tuner(dev);
943 982
944 clear_bit(POWER_ON, &dev->flags); 983 clear_bit(POWER_ON, &dev->flags);
945 984
@@ -968,6 +1007,7 @@ static int rtl2832_sdr_g_tuner(struct file *file, void *priv,
968{ 1007{
969 struct rtl2832_sdr_dev *dev = video_drvdata(file); 1008 struct rtl2832_sdr_dev *dev = video_drvdata(file);
970 struct platform_device *pdev = dev->pdev; 1009 struct platform_device *pdev = dev->pdev;
1010 int ret;
971 1011
972 dev_dbg(&pdev->dev, "index=%d type=%d\n", v->index, v->type); 1012 dev_dbg(&pdev->dev, "index=%d type=%d\n", v->index, v->type);
973 1013
@@ -977,17 +1017,21 @@ static int rtl2832_sdr_g_tuner(struct file *file, void *priv,
977 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; 1017 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
978 v->rangelow = 300000; 1018 v->rangelow = 300000;
979 v->rangehigh = 3200000; 1019 v->rangehigh = 3200000;
1020 ret = 0;
1021 } else if (v->index == 1 &&
1022 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, g_tuner)) {
1023 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_tuner, v);
980 } else if (v->index == 1) { 1024 } else if (v->index == 1) {
981 strlcpy(v->name, "RF: <unknown>", sizeof(v->name)); 1025 strlcpy(v->name, "RF: <unknown>", sizeof(v->name));
982 v->type = V4L2_TUNER_RF; 1026 v->type = V4L2_TUNER_RF;
983 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; 1027 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
984 v->rangelow = 50000000; 1028 v->rangelow = 50000000;
985 v->rangehigh = 2000000000; 1029 v->rangehigh = 2000000000;
1030 ret = 0;
986 } else { 1031 } else {
987 return -EINVAL; 1032 ret = -EINVAL;
988 } 1033 }
989 1034 return ret;
990 return 0;
991} 1035}
992 1036
993static int rtl2832_sdr_s_tuner(struct file *file, void *priv, 1037static int rtl2832_sdr_s_tuner(struct file *file, void *priv,
@@ -995,12 +1039,21 @@ static int rtl2832_sdr_s_tuner(struct file *file, void *priv,
995{ 1039{
996 struct rtl2832_sdr_dev *dev = video_drvdata(file); 1040 struct rtl2832_sdr_dev *dev = video_drvdata(file);
997 struct platform_device *pdev = dev->pdev; 1041 struct platform_device *pdev = dev->pdev;
1042 int ret;
998 1043
999 dev_dbg(&pdev->dev, "\n"); 1044 dev_dbg(&pdev->dev, "\n");
1000 1045
1001 if (v->index > 1) 1046 if (v->index == 0) {
1002 return -EINVAL; 1047 ret = 0;
1003 return 0; 1048 } else if (v->index == 1 &&
1049 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, s_tuner)) {
1050 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_tuner, v);
1051 } else if (v->index == 1) {
1052 ret = 0;
1053 } else {
1054 ret = -EINVAL;
1055 }
1056 return ret;
1004} 1057}
1005 1058
1006static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv, 1059static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
@@ -1008,6 +1061,7 @@ static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
1008{ 1061{
1009 struct rtl2832_sdr_dev *dev = video_drvdata(file); 1062 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1010 struct platform_device *pdev = dev->pdev; 1063 struct platform_device *pdev = dev->pdev;
1064 int ret;
1011 1065
1012 dev_dbg(&pdev->dev, "tuner=%d type=%d index=%d\n", 1066 dev_dbg(&pdev->dev, "tuner=%d type=%d index=%d\n",
1013 band->tuner, band->type, band->index); 1067 band->tuner, band->type, band->index);
@@ -1017,16 +1071,20 @@ static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
1017 return -EINVAL; 1071 return -EINVAL;
1018 1072
1019 *band = bands_adc[band->index]; 1073 *band = bands_adc[band->index];
1074 ret = 0;
1075 } else if (band->tuner == 1 &&
1076 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, enum_freq_bands)) {
1077 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, enum_freq_bands, band);
1020 } else if (band->tuner == 1) { 1078 } else if (band->tuner == 1) {
1021 if (band->index >= ARRAY_SIZE(bands_fm)) 1079 if (band->index >= ARRAY_SIZE(bands_fm))
1022 return -EINVAL; 1080 return -EINVAL;
1023 1081
1024 *band = bands_fm[band->index]; 1082 *band = bands_fm[band->index];
1083 ret = 0;
1025 } else { 1084 } else {
1026 return -EINVAL; 1085 ret = -EINVAL;
1027 } 1086 }
1028 1087 return ret;
1029 return 0;
1030} 1088}
1031 1089
1032static int rtl2832_sdr_g_frequency(struct file *file, void *priv, 1090static int rtl2832_sdr_g_frequency(struct file *file, void *priv,
@@ -1034,20 +1092,25 @@ static int rtl2832_sdr_g_frequency(struct file *file, void *priv,
1034{ 1092{
1035 struct rtl2832_sdr_dev *dev = video_drvdata(file); 1093 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1036 struct platform_device *pdev = dev->pdev; 1094 struct platform_device *pdev = dev->pdev;
1037 int ret = 0; 1095 int ret;
1038 1096
1039 dev_dbg(&pdev->dev, "tuner=%d type=%d\n", f->tuner, f->type); 1097 dev_dbg(&pdev->dev, "tuner=%d type=%d\n", f->tuner, f->type);
1040 1098
1041 if (f->tuner == 0) { 1099 if (f->tuner == 0) {
1042 f->frequency = dev->f_adc; 1100 f->frequency = dev->f_adc;
1043 f->type = V4L2_TUNER_ADC; 1101 f->type = V4L2_TUNER_ADC;
1102 ret = 0;
1103 } else if (f->tuner == 1 &&
1104 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, g_frequency)) {
1105 f->type = V4L2_TUNER_RF;
1106 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_frequency, f);
1044 } else if (f->tuner == 1) { 1107 } else if (f->tuner == 1) {
1045 f->frequency = dev->f_tuner; 1108 f->frequency = dev->f_tuner;
1046 f->type = V4L2_TUNER_RF; 1109 f->type = V4L2_TUNER_RF;
1110 ret = 0;
1047 } else { 1111 } else {
1048 return -EINVAL; 1112 ret = -EINVAL;
1049 } 1113 }
1050
1051 return ret; 1114 return ret;
1052} 1115}
1053 1116
@@ -1074,11 +1137,14 @@ static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
1074 band = 2; 1137 band = 2;
1075 1138
1076 dev->f_adc = clamp_t(unsigned int, f->frequency, 1139 dev->f_adc = clamp_t(unsigned int, f->frequency,
1077 bands_adc[band].rangelow, 1140 bands_adc[band].rangelow,
1078 bands_adc[band].rangehigh); 1141 bands_adc[band].rangehigh);
1079 1142
1080 dev_dbg(&pdev->dev, "ADC frequency=%u Hz\n", dev->f_adc); 1143 dev_dbg(&pdev->dev, "ADC frequency=%u Hz\n", dev->f_adc);
1081 ret = rtl2832_sdr_set_adc(dev); 1144 ret = rtl2832_sdr_set_adc(dev);
1145 } else if (f->tuner == 1 &&
1146 V4L2_SUBDEV_HAS_OP(dev->v4l2_subdev, tuner, s_frequency)) {
1147 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_frequency, f);
1082 } else if (f->tuner == 1) { 1148 } else if (f->tuner == 1) {
1083 dev->f_tuner = clamp_t(unsigned int, f->frequency, 1149 dev->f_tuner = clamp_t(unsigned int, f->frequency,
1084 bands_fm[0].rangelow, 1150 bands_fm[0].rangelow,
@@ -1089,7 +1155,6 @@ static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
1089 } else { 1155 } else {
1090 ret = -EINVAL; 1156 ret = -EINVAL;
1091 } 1157 }
1092
1093 return ret; 1158 return ret;
1094} 1159}
1095 1160
@@ -1329,6 +1394,7 @@ static int rtl2832_sdr_probe(struct platform_device *pdev)
1329 1394
1330 /* setup the state */ 1395 /* setup the state */
1331 subdev = pdata->v4l2_subdev; 1396 subdev = pdata->v4l2_subdev;
1397 dev->v4l2_subdev = pdata->v4l2_subdev;
1332 dev->pdev = pdev; 1398 dev->pdev = pdev;
1333 dev->udev = pdata->dvb_usb_device->udev; 1399 dev->udev = pdata->dvb_usb_device->udev;
1334 dev->f_adc = bands_adc[0].rangelow; 1400 dev->f_adc = bands_adc[0].rangelow;
@@ -1388,6 +1454,12 @@ static int rtl2832_sdr_probe(struct platform_device *pdev)
1388 6000000); 1454 6000000);
1389 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false); 1455 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
1390 break; 1456 break;
1457 case RTL2832_SDR_TUNER_FC2580:
1458 v4l2_ctrl_handler_init(&dev->hdl, 2);
1459 if (subdev)
1460 v4l2_ctrl_add_handler(&dev->hdl, subdev->ctrl_handler,
1461 NULL);
1462 break;
1391 default: 1463 default:
1392 v4l2_ctrl_handler_init(&dev->hdl, 0); 1464 v4l2_ctrl_handler_init(&dev->hdl, 0);
1393 dev_err(&pdev->dev, "Unsupported tuner\n"); 1465 dev_err(&pdev->dev, "Unsupported tuner\n");
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.h b/drivers/media/dvb-frontends/rtl2832_sdr.h
index d2594768bff2..342ea84860df 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.h
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.h
@@ -47,6 +47,7 @@ struct rtl2832_sdr_platform_data {
47 /* 47 /*
48 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver. 48 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver.
49 */ 49 */
50#define RTL2832_SDR_TUNER_FC2580 0x21
50#define RTL2832_SDR_TUNER_TUA9001 0x24 51#define RTL2832_SDR_TUNER_TUA9001 0x24
51#define RTL2832_SDR_TUNER_FC0012 0x26 52#define RTL2832_SDR_TUNER_FC0012 0x26
52#define RTL2832_SDR_TUNER_E4000 0x27 53#define RTL2832_SDR_TUNER_E4000 0x27
diff --git a/drivers/media/dvb-frontends/s5h1409.c b/drivers/media/dvb-frontends/s5h1409.c
index 5ff474a7ff29..10964848a2f1 100644
--- a/drivers/media/dvb-frontends/s5h1409.c
+++ b/drivers/media/dvb-frontends/s5h1409.c
@@ -38,7 +38,7 @@ struct s5h1409_state {
38 struct dvb_frontend frontend; 38 struct dvb_frontend frontend;
39 39
40 /* previous uncorrected block counter */ 40 /* previous uncorrected block counter */
41 fe_modulation_t current_modulation; 41 enum fe_modulation current_modulation;
42 42
43 u32 current_frequency; 43 u32 current_frequency;
44 int if_freq; 44 int if_freq;
@@ -400,7 +400,7 @@ static int s5h1409_set_spectralinversion(struct dvb_frontend *fe, int inverted)
400} 400}
401 401
402static int s5h1409_enable_modulation(struct dvb_frontend *fe, 402static int s5h1409_enable_modulation(struct dvb_frontend *fe,
403 fe_modulation_t m) 403 enum fe_modulation m)
404{ 404{
405 struct s5h1409_state *state = fe->demodulator_priv; 405 struct s5h1409_state *state = fe->demodulator_priv;
406 406
@@ -755,7 +755,7 @@ static int s5h1409_init(struct dvb_frontend *fe)
755 return 0; 755 return 0;
756} 756}
757 757
758static int s5h1409_read_status(struct dvb_frontend *fe, fe_status_t *status) 758static int s5h1409_read_status(struct dvb_frontend *fe, enum fe_status *status)
759{ 759{
760 struct s5h1409_state *state = fe->demodulator_priv; 760 struct s5h1409_state *state = fe->demodulator_priv;
761 u16 reg; 761 u16 reg;
diff --git a/drivers/media/dvb-frontends/s5h1411.c b/drivers/media/dvb-frontends/s5h1411.c
index 64f35fed7ae1..9afc3f42290e 100644
--- a/drivers/media/dvb-frontends/s5h1411.c
+++ b/drivers/media/dvb-frontends/s5h1411.c
@@ -37,7 +37,7 @@ struct s5h1411_state {
37 37
38 struct dvb_frontend frontend; 38 struct dvb_frontend frontend;
39 39
40 fe_modulation_t current_modulation; 40 enum fe_modulation current_modulation;
41 unsigned int first_tune:1; 41 unsigned int first_tune:1;
42 42
43 u32 current_frequency; 43 u32 current_frequency;
@@ -484,7 +484,7 @@ static int s5h1411_set_serialmode(struct dvb_frontend *fe, int serial)
484} 484}
485 485
486static int s5h1411_enable_modulation(struct dvb_frontend *fe, 486static int s5h1411_enable_modulation(struct dvb_frontend *fe,
487 fe_modulation_t m) 487 enum fe_modulation m)
488{ 488{
489 struct s5h1411_state *state = fe->demodulator_priv; 489 struct s5h1411_state *state = fe->demodulator_priv;
490 490
@@ -659,7 +659,7 @@ static int s5h1411_init(struct dvb_frontend *fe)
659 return 0; 659 return 0;
660} 660}
661 661
662static int s5h1411_read_status(struct dvb_frontend *fe, fe_status_t *status) 662static int s5h1411_read_status(struct dvb_frontend *fe, enum fe_status *status)
663{ 663{
664 struct s5h1411_state *state = fe->demodulator_priv; 664 struct s5h1411_state *state = fe->demodulator_priv;
665 u16 reg; 665 u16 reg;
diff --git a/drivers/media/dvb-frontends/s5h1420.c b/drivers/media/dvb-frontends/s5h1420.c
index 93eeaf7118fd..9c22a4c70d87 100644
--- a/drivers/media/dvb-frontends/s5h1420.c
+++ b/drivers/media/dvb-frontends/s5h1420.c
@@ -52,7 +52,7 @@ struct s5h1420_state {
52 u8 postlocked:1; 52 u8 postlocked:1;
53 u32 fclk; 53 u32 fclk;
54 u32 tunedfreq; 54 u32 tunedfreq;
55 fe_code_rate_t fec_inner; 55 enum fe_code_rate fec_inner;
56 u32 symbol_rate; 56 u32 symbol_rate;
57 57
58 /* FIXME: ugly workaround for flexcop's incapable i2c-controller 58 /* FIXME: ugly workaround for flexcop's incapable i2c-controller
@@ -124,7 +124,8 @@ static int s5h1420_writereg (struct s5h1420_state* state, u8 reg, u8 data)
124 return 0; 124 return 0;
125} 125}
126 126
127static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 127static int s5h1420_set_voltage(struct dvb_frontend *fe,
128 enum fe_sec_voltage voltage)
128{ 129{
129 struct s5h1420_state* state = fe->demodulator_priv; 130 struct s5h1420_state* state = fe->demodulator_priv;
130 131
@@ -149,7 +150,8 @@ static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
149 return 0; 150 return 0;
150} 151}
151 152
152static int s5h1420_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 153static int s5h1420_set_tone(struct dvb_frontend *fe,
154 enum fe_sec_tone_mode tone)
153{ 155{
154 struct s5h1420_state* state = fe->demodulator_priv; 156 struct s5h1420_state* state = fe->demodulator_priv;
155 157
@@ -180,7 +182,7 @@ static int s5h1420_send_master_cmd (struct dvb_frontend* fe,
180 int result = 0; 182 int result = 0;
181 183
182 dprintk("enter %s\n", __func__); 184 dprintk("enter %s\n", __func__);
183 if (cmd->msg_len > 8) 185 if (cmd->msg_len > sizeof(cmd->msg))
184 return -EINVAL; 186 return -EINVAL;
185 187
186 /* setup for DISEQC */ 188 /* setup for DISEQC */
@@ -270,7 +272,8 @@ exit:
270 return result; 272 return result;
271} 273}
272 274
273static int s5h1420_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 275static int s5h1420_send_burst(struct dvb_frontend *fe,
276 enum fe_sec_mini_cmd minicmd)
274{ 277{
275 struct s5h1420_state* state = fe->demodulator_priv; 278 struct s5h1420_state* state = fe->demodulator_priv;
276 u8 val; 279 u8 val;
@@ -307,10 +310,10 @@ static int s5h1420_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicm
307 return result; 310 return result;
308} 311}
309 312
310static fe_status_t s5h1420_get_status_bits(struct s5h1420_state* state) 313static enum fe_status s5h1420_get_status_bits(struct s5h1420_state *state)
311{ 314{
312 u8 val; 315 u8 val;
313 fe_status_t status = 0; 316 enum fe_status status = 0;
314 317
315 val = s5h1420_readreg(state, 0x14); 318 val = s5h1420_readreg(state, 0x14);
316 if (val & 0x02) 319 if (val & 0x02)
@@ -328,7 +331,8 @@ static fe_status_t s5h1420_get_status_bits(struct s5h1420_state* state)
328 return status; 331 return status;
329} 332}
330 333
331static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status) 334static int s5h1420_read_status(struct dvb_frontend *fe,
335 enum fe_status *status)
332{ 336{
333 struct s5h1420_state* state = fe->demodulator_priv; 337 struct s5h1420_state* state = fe->demodulator_priv;
334 u8 val; 338 u8 val;
@@ -561,27 +565,33 @@ static void s5h1420_setfec_inversion(struct s5h1420_state* state,
561 } else { 565 } else {
562 switch (p->fec_inner) { 566 switch (p->fec_inner) {
563 case FEC_1_2: 567 case FEC_1_2:
564 vit08 = 0x01; vit09 = 0x10; 568 vit08 = 0x01;
569 vit09 = 0x10;
565 break; 570 break;
566 571
567 case FEC_2_3: 572 case FEC_2_3:
568 vit08 = 0x02; vit09 = 0x11; 573 vit08 = 0x02;
574 vit09 = 0x11;
569 break; 575 break;
570 576
571 case FEC_3_4: 577 case FEC_3_4:
572 vit08 = 0x04; vit09 = 0x12; 578 vit08 = 0x04;
579 vit09 = 0x12;
573 break; 580 break;
574 581
575 case FEC_5_6: 582 case FEC_5_6:
576 vit08 = 0x08; vit09 = 0x13; 583 vit08 = 0x08;
584 vit09 = 0x13;
577 break; 585 break;
578 586
579 case FEC_6_7: 587 case FEC_6_7:
580 vit08 = 0x10; vit09 = 0x14; 588 vit08 = 0x10;
589 vit09 = 0x14;
581 break; 590 break;
582 591
583 case FEC_7_8: 592 case FEC_7_8:
584 vit08 = 0x20; vit09 = 0x15; 593 vit08 = 0x20;
594 vit09 = 0x15;
585 break; 595 break;
586 596
587 default: 597 default:
@@ -595,7 +605,7 @@ static void s5h1420_setfec_inversion(struct s5h1420_state* state,
595 dprintk("leave %s\n", __func__); 605 dprintk("leave %s\n", __func__);
596} 606}
597 607
598static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state) 608static enum fe_code_rate s5h1420_getfec(struct s5h1420_state *state)
599{ 609{
600 switch(s5h1420_readreg(state, 0x32) & 0x07) { 610 switch(s5h1420_readreg(state, 0x32) & 0x07) {
601 case 0: 611 case 0:
@@ -620,7 +630,8 @@ static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state)
620 return FEC_NONE; 630 return FEC_NONE;
621} 631}
622 632
623static fe_spectral_inversion_t s5h1420_getinversion(struct s5h1420_state* state) 633static enum fe_spectral_inversion
634s5h1420_getinversion(struct s5h1420_state *state)
624{ 635{
625 if (s5h1420_readreg(state, 0x32) & 0x08) 636 if (s5h1420_readreg(state, 0x32) & 0x08)
626 return INVERSION_ON; 637 return INVERSION_ON;
diff --git a/drivers/media/dvb-frontends/s5h1432.c b/drivers/media/dvb-frontends/s5h1432.c
index 6ec16a243741..4215652f8eb7 100644
--- a/drivers/media/dvb-frontends/s5h1432.c
+++ b/drivers/media/dvb-frontends/s5h1432.c
@@ -36,7 +36,7 @@ struct s5h1432_state {
36 36
37 struct dvb_frontend frontend; 37 struct dvb_frontend frontend;
38 38
39 fe_modulation_t current_modulation; 39 enum fe_modulation current_modulation;
40 unsigned int first_tune:1; 40 unsigned int first_tune:1;
41 41
42 u32 current_frequency; 42 u32 current_frequency;
@@ -302,7 +302,7 @@ static int s5h1432_init(struct dvb_frontend *fe)
302 return 0; 302 return 0;
303} 303}
304 304
305static int s5h1432_read_status(struct dvb_frontend *fe, fe_status_t *status) 305static int s5h1432_read_status(struct dvb_frontend *fe, enum fe_status *status)
306{ 306{
307 return 0; 307 return 0;
308} 308}
diff --git a/drivers/media/dvb-frontends/s921.c b/drivers/media/dvb-frontends/s921.c
index 69862e1fd9e9..b2d9fe13e1a0 100644
--- a/drivers/media/dvb-frontends/s921.c
+++ b/drivers/media/dvb-frontends/s921.c
@@ -348,7 +348,7 @@ static int s921_initfe(struct dvb_frontend *fe)
348 return 0; 348 return 0;
349} 349}
350 350
351static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status) 351static int s921_read_status(struct dvb_frontend *fe, enum fe_status *status)
352{ 352{
353 struct s921_state *state = fe->demodulator_priv; 353 struct s921_state *state = fe->demodulator_priv;
354 int regstatus, rc; 354 int regstatus, rc;
@@ -389,7 +389,7 @@ static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status)
389 389
390static int s921_read_signal_strength(struct dvb_frontend *fe, u16 *strength) 390static int s921_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
391{ 391{
392 fe_status_t status; 392 enum fe_status status;
393 struct s921_state *state = fe->demodulator_priv; 393 struct s921_state *state = fe->demodulator_priv;
394 int rc; 394 int rc;
395 395
@@ -449,7 +449,7 @@ static int s921_tune(struct dvb_frontend *fe,
449 bool re_tune, 449 bool re_tune,
450 unsigned int mode_flags, 450 unsigned int mode_flags,
451 unsigned int *delay, 451 unsigned int *delay,
452 fe_status_t *status) 452 enum fe_status *status)
453{ 453{
454 int rc = 0; 454 int rc = 0;
455 455
diff --git a/drivers/media/dvb-frontends/s921.h b/drivers/media/dvb-frontends/s921.h
index 7d3999a4e974..f5b722d8081b 100644
--- a/drivers/media/dvb-frontends/s921.h
+++ b/drivers/media/dvb-frontends/s921.h
@@ -36,7 +36,7 @@ static inline struct dvb_frontend *s921_attach(
36 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 36 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
37 return NULL; 37 return NULL;
38} 38}
39static struct i2c_adapter * 39static inline struct i2c_adapter *
40 s921_get_tuner_i2c_adapter(struct dvb_frontend *fe) 40 s921_get_tuner_i2c_adapter(struct dvb_frontend *fe)
41{ 41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index 4cc5d10ed0d4..7c2eeee69757 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -698,7 +698,7 @@ static int si2165_sleep(struct dvb_frontend *fe)
698 return 0; 698 return 0;
699} 699}
700 700
701static int si2165_read_status(struct dvb_frontend *fe, fe_status_t *status) 701static int si2165_read_status(struct dvb_frontend *fe, enum fe_status *status)
702{ 702{
703 int ret; 703 int ret;
704 u8 fec_lock = 0; 704 u8 fec_lock = 0;
diff --git a/drivers/media/dvb-frontends/si2168.c b/drivers/media/dvb-frontends/si2168.c
index 5db588ebfc24..25e238c370e5 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -18,23 +18,53 @@
18 18
19static const struct dvb_frontend_ops si2168_ops; 19static const struct dvb_frontend_ops si2168_ops;
20 20
21/* Own I2C adapter locking is needed because of I2C gate logic. */
22static int si2168_i2c_master_send_unlocked(const struct i2c_client *client,
23 const char *buf, int count)
24{
25 int ret;
26 struct i2c_msg msg = {
27 .addr = client->addr,
28 .flags = 0,
29 .len = count,
30 .buf = (char *)buf,
31 };
32
33 ret = __i2c_transfer(client->adapter, &msg, 1);
34 return (ret == 1) ? count : ret;
35}
36
37static int si2168_i2c_master_recv_unlocked(const struct i2c_client *client,
38 char *buf, int count)
39{
40 int ret;
41 struct i2c_msg msg = {
42 .addr = client->addr,
43 .flags = I2C_M_RD,
44 .len = count,
45 .buf = buf,
46 };
47
48 ret = __i2c_transfer(client->adapter, &msg, 1);
49 return (ret == 1) ? count : ret;
50}
51
21/* execute firmware command */ 52/* execute firmware command */
22static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd) 53static int si2168_cmd_execute_unlocked(struct i2c_client *client,
54 struct si2168_cmd *cmd)
23{ 55{
24 struct si2168_dev *dev = i2c_get_clientdata(client);
25 int ret; 56 int ret;
26 unsigned long timeout; 57 unsigned long timeout;
27 58
28 mutex_lock(&dev->i2c_mutex);
29
30 if (cmd->wlen) { 59 if (cmd->wlen) {
31 /* write cmd and args for firmware */ 60 /* write cmd and args for firmware */
32 ret = i2c_master_send(client, cmd->args, cmd->wlen); 61 ret = si2168_i2c_master_send_unlocked(client, cmd->args,
62 cmd->wlen);
33 if (ret < 0) { 63 if (ret < 0) {
34 goto err_mutex_unlock; 64 goto err;
35 } else if (ret != cmd->wlen) { 65 } else if (ret != cmd->wlen) {
36 ret = -EREMOTEIO; 66 ret = -EREMOTEIO;
37 goto err_mutex_unlock; 67 goto err;
38 } 68 }
39 } 69 }
40 70
@@ -43,12 +73,13 @@ static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd)
43 #define TIMEOUT 70 73 #define TIMEOUT 70
44 timeout = jiffies + msecs_to_jiffies(TIMEOUT); 74 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
45 while (!time_after(jiffies, timeout)) { 75 while (!time_after(jiffies, timeout)) {
46 ret = i2c_master_recv(client, cmd->args, cmd->rlen); 76 ret = si2168_i2c_master_recv_unlocked(client, cmd->args,
77 cmd->rlen);
47 if (ret < 0) { 78 if (ret < 0) {
48 goto err_mutex_unlock; 79 goto err;
49 } else if (ret != cmd->rlen) { 80 } else if (ret != cmd->rlen) {
50 ret = -EREMOTEIO; 81 ret = -EREMOTEIO;
51 goto err_mutex_unlock; 82 goto err;
52 } 83 }
53 84
54 /* firmware ready? */ 85 /* firmware ready? */
@@ -60,22 +91,36 @@ static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd)
60 jiffies_to_msecs(jiffies) - 91 jiffies_to_msecs(jiffies) -
61 (jiffies_to_msecs(timeout) - TIMEOUT)); 92 (jiffies_to_msecs(timeout) - TIMEOUT));
62 93
94 /* error bit set? */
95 if ((cmd->args[0] >> 6) & 0x01) {
96 ret = -EREMOTEIO;
97 goto err;
98 }
99
63 if (!((cmd->args[0] >> 7) & 0x01)) { 100 if (!((cmd->args[0] >> 7) & 0x01)) {
64 ret = -ETIMEDOUT; 101 ret = -ETIMEDOUT;
65 goto err_mutex_unlock; 102 goto err;
66 } 103 }
67 } 104 }
68 105
69 mutex_unlock(&dev->i2c_mutex);
70 return 0; 106 return 0;
71 107err:
72err_mutex_unlock:
73 mutex_unlock(&dev->i2c_mutex);
74 dev_dbg(&client->dev, "failed=%d\n", ret); 108 dev_dbg(&client->dev, "failed=%d\n", ret);
75 return ret; 109 return ret;
76} 110}
77 111
78static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status) 112static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd)
113{
114 int ret;
115
116 i2c_lock_adapter(client->adapter);
117 ret = si2168_cmd_execute_unlocked(client, cmd);
118 i2c_unlock_adapter(client->adapter);
119
120 return ret;
121}
122
123static int si2168_read_status(struct dvb_frontend *fe, enum fe_status *status)
79{ 124{
80 struct i2c_client *client = fe->demodulator_priv; 125 struct i2c_client *client = fe->demodulator_priv;
81 struct si2168_dev *dev = i2c_get_clientdata(client); 126 struct si2168_dev *dev = i2c_get_clientdata(client);
@@ -508,6 +553,8 @@ static int si2168_init(struct dvb_frontend *fe)
508 /* set ts mode */ 553 /* set ts mode */
509 memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6); 554 memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
510 cmd.args[4] |= dev->ts_mode; 555 cmd.args[4] |= dev->ts_mode;
556 if (dev->ts_clock_gapped)
557 cmd.args[4] |= 0x40;
511 cmd.wlen = 6; 558 cmd.wlen = 6;
512 cmd.rlen = 4; 559 cmd.rlen = 4;
513 ret = si2168_cmd_execute(client, &cmd); 560 ret = si2168_cmd_execute(client, &cmd);
@@ -561,60 +608,46 @@ static int si2168_get_tune_settings(struct dvb_frontend *fe,
561 608
562/* 609/*
563 * I2C gate logic 610 * I2C gate logic
564 * We must use unlocked i2c_transfer() here because I2C lock is already taken 611 * We must use unlocked I2C I/O because I2C adapter lock is already taken
565 * by tuner driver. 612 * by the caller (usually tuner driver).
566 */ 613 */
567static int si2168_select(struct i2c_adapter *adap, void *mux_priv, u32 chan) 614static int si2168_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
568{ 615{
569 struct i2c_client *client = mux_priv; 616 struct i2c_client *client = mux_priv;
570 struct si2168_dev *dev = i2c_get_clientdata(client);
571 int ret; 617 int ret;
572 struct i2c_msg gate_open_msg = { 618 struct si2168_cmd cmd;
573 .addr = client->addr,
574 .flags = 0,
575 .len = 3,
576 .buf = "\xc0\x0d\x01",
577 };
578
579 mutex_lock(&dev->i2c_mutex);
580 619
581 /* open tuner I2C gate */ 620 /* open I2C gate */
582 ret = __i2c_transfer(client->adapter, &gate_open_msg, 1); 621 memcpy(cmd.args, "\xc0\x0d\x01", 3);
583 if (ret != 1) { 622 cmd.wlen = 3;
584 dev_warn(&client->dev, "i2c write failed=%d\n", ret); 623 cmd.rlen = 0;
585 if (ret >= 0) 624 ret = si2168_cmd_execute_unlocked(client, &cmd);
586 ret = -EREMOTEIO; 625 if (ret)
587 } else { 626 goto err;
588 ret = 0;
589 }
590 627
628 return 0;
629err:
630 dev_dbg(&client->dev, "failed=%d\n", ret);
591 return ret; 631 return ret;
592} 632}
593 633
594static int si2168_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan) 634static int si2168_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan)
595{ 635{
596 struct i2c_client *client = mux_priv; 636 struct i2c_client *client = mux_priv;
597 struct si2168_dev *dev = i2c_get_clientdata(client);
598 int ret; 637 int ret;
599 struct i2c_msg gate_close_msg = { 638 struct si2168_cmd cmd;
600 .addr = client->addr,
601 .flags = 0,
602 .len = 3,
603 .buf = "\xc0\x0d\x00",
604 };
605
606 /* close tuner I2C gate */
607 ret = __i2c_transfer(client->adapter, &gate_close_msg, 1);
608 if (ret != 1) {
609 dev_warn(&client->dev, "i2c write failed=%d\n", ret);
610 if (ret >= 0)
611 ret = -EREMOTEIO;
612 } else {
613 ret = 0;
614 }
615 639
616 mutex_unlock(&dev->i2c_mutex); 640 /* close I2C gate */
641 memcpy(cmd.args, "\xc0\x0d\x00", 3);
642 cmd.wlen = 3;
643 cmd.rlen = 0;
644 ret = si2168_cmd_execute_unlocked(client, &cmd);
645 if (ret)
646 goto err;
617 647
648 return 0;
649err:
650 dev_dbg(&client->dev, "failed=%d\n", ret);
618 return ret; 651 return ret;
619} 652}
620 653
@@ -671,8 +704,6 @@ static int si2168_probe(struct i2c_client *client,
671 goto err; 704 goto err;
672 } 705 }
673 706
674 mutex_init(&dev->i2c_mutex);
675
676 /* create mux i2c adapter for tuner */ 707 /* create mux i2c adapter for tuner */
677 dev->adapter = i2c_add_mux_adapter(client->adapter, &client->dev, 708 dev->adapter = i2c_add_mux_adapter(client->adapter, &client->dev,
678 client, 0, 0, 0, si2168_select, si2168_deselect); 709 client, 0, 0, 0, si2168_select, si2168_deselect);
@@ -688,6 +719,7 @@ static int si2168_probe(struct i2c_client *client,
688 *config->fe = &dev->fe; 719 *config->fe = &dev->fe;
689 dev->ts_mode = config->ts_mode; 720 dev->ts_mode = config->ts_mode;
690 dev->ts_clock_inv = config->ts_clock_inv; 721 dev->ts_clock_inv = config->ts_clock_inv;
722 dev->ts_clock_gapped = config->ts_clock_gapped;
691 dev->fw_loaded = false; 723 dev->fw_loaded = false;
692 724
693 i2c_set_clientdata(client, dev); 725 i2c_set_clientdata(client, dev);
diff --git a/drivers/media/dvb-frontends/si2168.h b/drivers/media/dvb-frontends/si2168.h
index 70d702ae6f49..3225d0cc93c7 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -42,6 +42,9 @@ struct si2168_config {
42 42
43 /* TS clock inverted */ 43 /* TS clock inverted */
44 bool ts_clock_inv; 44 bool ts_clock_inv;
45
46 /* TS clock gapped */
47 bool ts_clock_gapped;
45}; 48};
46 49
47#endif 50#endif
diff --git a/drivers/media/dvb-frontends/si2168_priv.h b/drivers/media/dvb-frontends/si2168_priv.h
index d7efce8043ed..c07e6fe2cb10 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -30,14 +30,14 @@
30/* state struct */ 30/* state struct */
31struct si2168_dev { 31struct si2168_dev {
32 struct i2c_adapter *adapter; 32 struct i2c_adapter *adapter;
33 struct mutex i2c_mutex;
34 struct dvb_frontend fe; 33 struct dvb_frontend fe;
35 fe_delivery_system_t delivery_system; 34 enum fe_delivery_system delivery_system;
36 fe_status_t fe_status; 35 enum fe_status fe_status;
37 bool active; 36 bool active;
38 bool fw_loaded; 37 bool fw_loaded;
39 u8 ts_mode; 38 u8 ts_mode;
40 bool ts_clock_inv; 39 bool ts_clock_inv;
40 bool ts_clock_gapped;
41}; 41};
42 42
43/* firmware command struct */ 43/* firmware command struct */
diff --git a/drivers/media/dvb-frontends/si21xx.c b/drivers/media/dvb-frontends/si21xx.c
index 16850e2bf02f..62ad7a7be9f8 100644
--- a/drivers/media/dvb-frontends/si21xx.c
+++ b/drivers/media/dvb-frontends/si21xx.c
@@ -410,7 +410,7 @@ static int si21xx_send_diseqc_msg(struct dvb_frontend *fe,
410} 410}
411 411
412static int si21xx_send_diseqc_burst(struct dvb_frontend *fe, 412static int si21xx_send_diseqc_burst(struct dvb_frontend *fe,
413 fe_sec_mini_cmd_t burst) 413 enum fe_sec_mini_cmd burst)
414{ 414{
415 struct si21xx_state *state = fe->demodulator_priv; 415 struct si21xx_state *state = fe->demodulator_priv;
416 u8 val; 416 u8 val;
@@ -434,7 +434,7 @@ static int si21xx_send_diseqc_burst(struct dvb_frontend *fe,
434 return 0; 434 return 0;
435} 435}
436/* 30.06.2008 */ 436/* 30.06.2008 */
437static int si21xx_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 437static int si21xx_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
438{ 438{
439 struct si21xx_state *state = fe->demodulator_priv; 439 struct si21xx_state *state = fe->demodulator_priv;
440 u8 val; 440 u8 val;
@@ -454,7 +454,7 @@ static int si21xx_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
454 } 454 }
455} 455}
456 456
457static int si21xx_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt) 457static int si21xx_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage volt)
458{ 458{
459 struct si21xx_state *state = fe->demodulator_priv; 459 struct si21xx_state *state = fe->demodulator_priv;
460 460
@@ -536,7 +536,7 @@ static int si21xx_init(struct dvb_frontend *fe)
536 536
537} 537}
538 538
539static int si21_read_status(struct dvb_frontend *fe, fe_status_t *status) 539static int si21_read_status(struct dvb_frontend *fe, enum fe_status *status)
540{ 540{
541 struct si21xx_state *state = fe->demodulator_priv; 541 struct si21xx_state *state = fe->demodulator_priv;
542 u8 regs_read[2]; 542 u8 regs_read[2];
@@ -641,7 +641,7 @@ static int si21_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
641/* initiates a channel acquisition sequence 641/* initiates a channel acquisition sequence
642 using the specified symbol rate and code rate */ 642 using the specified symbol rate and code rate */
643static int si21xx_setacquire(struct dvb_frontend *fe, int symbrate, 643static int si21xx_setacquire(struct dvb_frontend *fe, int symbrate,
644 fe_code_rate_t crate) 644 enum fe_code_rate crate)
645{ 645{
646 646
647 struct si21xx_state *state = fe->demodulator_priv; 647 struct si21xx_state *state = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/sp8870.c b/drivers/media/dvb-frontends/sp8870.c
index 57dc2abaa87b..e87ac30d7fb8 100644
--- a/drivers/media/dvb-frontends/sp8870.c
+++ b/drivers/media/dvb-frontends/sp8870.c
@@ -350,7 +350,8 @@ static int sp8870_init (struct dvb_frontend* fe)
350 return 0; 350 return 0;
351} 351}
352 352
353static int sp8870_read_status (struct dvb_frontend* fe, fe_status_t * fe_status) 353static int sp8870_read_status(struct dvb_frontend *fe,
354 enum fe_status *fe_status)
354{ 355{
355 struct sp8870_state* state = fe->demodulator_priv; 356 struct sp8870_state* state = fe->demodulator_priv;
356 int status; 357 int status;
diff --git a/drivers/media/dvb-frontends/sp887x.c b/drivers/media/dvb-frontends/sp887x.c
index 1bb81b5ae6e0..4378fe1b978e 100644
--- a/drivers/media/dvb-frontends/sp887x.c
+++ b/drivers/media/dvb-frontends/sp887x.c
@@ -416,7 +416,7 @@ static int sp887x_setup_frontend_parameters(struct dvb_frontend *fe)
416 return 0; 416 return 0;
417} 417}
418 418
419static int sp887x_read_status(struct dvb_frontend* fe, fe_status_t* status) 419static int sp887x_read_status(struct dvb_frontend *fe, enum fe_status *status)
420{ 420{
421 struct sp887x_state* state = fe->demodulator_priv; 421 struct sp887x_state* state = fe->demodulator_priv;
422 u16 snr12 = sp887x_readreg(state, 0xf16); 422 u16 snr12 = sp887x_readreg(state, 0xf16);
diff --git a/drivers/media/dvb-frontends/stb0899_drv.c b/drivers/media/dvb-frontends/stb0899_drv.c
index c73899d3a53d..756650f154ab 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.c
+++ b/drivers/media/dvb-frontends/stb0899_drv.c
@@ -792,7 +792,8 @@ static int stb0899_wait_diseqc_txidle(struct stb0899_state *state, int timeout)
792 return 0; 792 return 0;
793} 793}
794 794
795static int stb0899_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst) 795static int stb0899_send_diseqc_burst(struct dvb_frontend *fe,
796 enum fe_sec_mini_cmd burst)
796{ 797{
797 struct stb0899_state *state = fe->demodulator_priv; 798 struct stb0899_state *state = fe->demodulator_priv;
798 u8 reg, old_state; 799 u8 reg, old_state;
@@ -1178,7 +1179,8 @@ static int stb0899_read_ber(struct dvb_frontend *fe, u32 *ber)
1178 return 0; 1179 return 0;
1179} 1180}
1180 1181
1181static int stb0899_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 1182static int stb0899_set_voltage(struct dvb_frontend *fe,
1183 enum fe_sec_voltage voltage)
1182{ 1184{
1183 struct stb0899_state *state = fe->demodulator_priv; 1185 struct stb0899_state *state = fe->demodulator_priv;
1184 1186
@@ -1205,7 +1207,7 @@ static int stb0899_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage
1205 return 0; 1207 return 0;
1206} 1208}
1207 1209
1208static int stb0899_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 1210static int stb0899_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
1209{ 1211{
1210 struct stb0899_state *state = fe->demodulator_priv; 1212 struct stb0899_state *state = fe->demodulator_priv;
1211 struct stb0899_internal *internal = &state->internal; 1213 struct stb0899_internal *internal = &state->internal;
diff --git a/drivers/media/dvb-frontends/stv0288.c b/drivers/media/dvb-frontends/stv0288.c
index 632b25156e4c..c93d9a45f7f7 100644
--- a/drivers/media/dvb-frontends/stv0288.c
+++ b/drivers/media/dvb-frontends/stv0288.c
@@ -44,7 +44,7 @@ struct stv0288_state {
44 u8 initialised:1; 44 u8 initialised:1;
45 u32 tuner_frequency; 45 u32 tuner_frequency;
46 u32 symbol_rate; 46 u32 symbol_rate;
47 fe_code_rate_t fec_inner; 47 enum fe_code_rate fec_inner;
48 int errmode; 48 int errmode;
49}; 49};
50 50
@@ -134,20 +134,20 @@ static int stv0288_set_symbolrate(struct dvb_frontend *fe, u32 srate)
134 134
135 temp = (unsigned int)srate / 1000; 135 temp = (unsigned int)srate / 1000;
136 136
137 temp = temp * 32768; 137 temp = temp * 32768;
138 temp = temp / 25; 138 temp = temp / 25;
139 temp = temp / 125; 139 temp = temp / 125;
140 b[0] = (unsigned char)((temp >> 12) & 0xff); 140 b[0] = (unsigned char)((temp >> 12) & 0xff);
141 b[1] = (unsigned char)((temp >> 4) & 0xff); 141 b[1] = (unsigned char)((temp >> 4) & 0xff);
142 b[2] = (unsigned char)((temp << 4) & 0xf0); 142 b[2] = (unsigned char)((temp << 4) & 0xf0);
143 stv0288_writeregI(state, 0x28, 0x80); /* SFRH */ 143 stv0288_writeregI(state, 0x28, 0x80); /* SFRH */
144 stv0288_writeregI(state, 0x29, 0); /* SFRM */ 144 stv0288_writeregI(state, 0x29, 0); /* SFRM */
145 stv0288_writeregI(state, 0x2a, 0); /* SFRL */ 145 stv0288_writeregI(state, 0x2a, 0); /* SFRL */
146 146
147 stv0288_writeregI(state, 0x28, b[0]); 147 stv0288_writeregI(state, 0x28, b[0]);
148 stv0288_writeregI(state, 0x29, b[1]); 148 stv0288_writeregI(state, 0x29, b[1]);
149 stv0288_writeregI(state, 0x2a, b[2]); 149 stv0288_writeregI(state, 0x2a, b[2]);
150 dprintk("stv0288: stv0288_set_symbolrate\n"); 150 dprintk("stv0288: stv0288_set_symbolrate\n");
151 151
152 return 0; 152 return 0;
153} 153}
@@ -174,7 +174,7 @@ static int stv0288_send_diseqc_msg(struct dvb_frontend *fe,
174} 174}
175 175
176static int stv0288_send_diseqc_burst(struct dvb_frontend *fe, 176static int stv0288_send_diseqc_burst(struct dvb_frontend *fe,
177 fe_sec_mini_cmd_t burst) 177 enum fe_sec_mini_cmd burst)
178{ 178{
179 struct stv0288_state *state = fe->demodulator_priv; 179 struct stv0288_state *state = fe->demodulator_priv;
180 180
@@ -193,7 +193,7 @@ static int stv0288_send_diseqc_burst(struct dvb_frontend *fe,
193 return 0; 193 return 0;
194} 194}
195 195
196static int stv0288_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 196static int stv0288_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
197{ 197{
198 struct stv0288_state *state = fe->demodulator_priv; 198 struct stv0288_state *state = fe->demodulator_priv;
199 199
@@ -323,7 +323,8 @@ static u8 stv0288_inittab[] = {
323 0xff, 0xff, 323 0xff, 0xff,
324}; 324};
325 325
326static int stv0288_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt) 326static int stv0288_set_voltage(struct dvb_frontend *fe,
327 enum fe_sec_voltage volt)
327{ 328{
328 dprintk("%s: %s\n", __func__, 329 dprintk("%s: %s\n", __func__,
329 volt == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" : 330 volt == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
@@ -361,7 +362,7 @@ static int stv0288_init(struct dvb_frontend *fe)
361 return 0; 362 return 0;
362} 363}
363 364
364static int stv0288_read_status(struct dvb_frontend *fe, fe_status_t *status) 365static int stv0288_read_status(struct dvb_frontend *fe, enum fe_status *status)
365{ 366{
366 struct stv0288_state *state = fe->demodulator_priv; 367 struct stv0288_state *state = fe->demodulator_priv;
367 368
diff --git a/drivers/media/dvb-frontends/stv0297.c b/drivers/media/dvb-frontends/stv0297.c
index d40f226160ef..75b4d8b25657 100644
--- a/drivers/media/dvb-frontends/stv0297.c
+++ b/drivers/media/dvb-frontends/stv0297.c
@@ -136,10 +136,10 @@ static u32 stv0297_get_symbolrate(struct stv0297_state *state)
136{ 136{
137 u64 tmp; 137 u64 tmp;
138 138
139 tmp = stv0297_readreg(state, 0x55); 139 tmp = (u64)(stv0297_readreg(state, 0x55)
140 tmp |= stv0297_readreg(state, 0x56) << 8; 140 | (stv0297_readreg(state, 0x56) << 8)
141 tmp |= stv0297_readreg(state, 0x57) << 16; 141 | (stv0297_readreg(state, 0x57) << 16)
142 tmp |= stv0297_readreg(state, 0x58) << 24; 142 | (stv0297_readreg(state, 0x58) << 24));
143 143
144 tmp *= STV0297_CLOCK_KHZ; 144 tmp *= STV0297_CLOCK_KHZ;
145 tmp >>= 32; 145 tmp >>= 32;
@@ -233,7 +233,8 @@ static void stv0297_set_initialdemodfreq(struct stv0297_state *state, long freq)
233 stv0297_writereg(state, 0x20, tmp); 233 stv0297_writereg(state, 0x20, tmp);
234} 234}
235 235
236static int stv0297_set_qam(struct stv0297_state *state, fe_modulation_t modulation) 236static int stv0297_set_qam(struct stv0297_state *state,
237 enum fe_modulation modulation)
237{ 238{
238 int val = 0; 239 int val = 0;
239 240
@@ -267,7 +268,8 @@ static int stv0297_set_qam(struct stv0297_state *state, fe_modulation_t modulati
267 return 0; 268 return 0;
268} 269}
269 270
270static int stv0297_set_inversion(struct stv0297_state *state, fe_spectral_inversion_t inversion) 271static int stv0297_set_inversion(struct stv0297_state *state,
272 enum fe_spectral_inversion inversion)
271{ 273{
272 int val = 0; 274 int val = 0;
273 275
@@ -325,7 +327,8 @@ static int stv0297_sleep(struct dvb_frontend *fe)
325 return 0; 327 return 0;
326} 328}
327 329
328static int stv0297_read_status(struct dvb_frontend *fe, fe_status_t * status) 330static int stv0297_read_status(struct dvb_frontend *fe,
331 enum fe_status *status)
329{ 332{
330 struct stv0297_state *state = fe->demodulator_priv; 333 struct stv0297_state *state = fe->demodulator_priv;
331 334
@@ -415,7 +418,7 @@ static int stv0297_set_frontend(struct dvb_frontend *fe)
415 int sweeprate; 418 int sweeprate;
416 int carrieroffset; 419 int carrieroffset;
417 unsigned long timeout; 420 unsigned long timeout;
418 fe_spectral_inversion_t inversion; 421 enum fe_spectral_inversion inversion;
419 422
420 switch (p->modulation) { 423 switch (p->modulation) {
421 case QAM_16: 424 case QAM_16:
diff --git a/drivers/media/dvb-frontends/stv0299.c b/drivers/media/dvb-frontends/stv0299.c
index b57ecf42e75a..a8177807fb65 100644
--- a/drivers/media/dvb-frontends/stv0299.c
+++ b/drivers/media/dvb-frontends/stv0299.c
@@ -44,6 +44,7 @@
44 44
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/ktime.h>
47#include <linux/module.h> 48#include <linux/module.h>
48#include <linux/string.h> 49#include <linux/string.h>
49#include <linux/slab.h> 50#include <linux/slab.h>
@@ -61,7 +62,7 @@ struct stv0299_state {
61 u8 initialised:1; 62 u8 initialised:1;
62 u32 tuner_frequency; 63 u32 tuner_frequency;
63 u32 symbol_rate; 64 u32 symbol_rate;
64 fe_code_rate_t fec_inner; 65 enum fe_code_rate fec_inner;
65 int errmode; 66 int errmode;
66 u32 ucblocks; 67 u32 ucblocks;
67 u8 mcr_reg; 68 u8 mcr_reg;
@@ -134,7 +135,7 @@ static int stv0299_readregs (struct stv0299_state* state, u8 reg1, u8 *b, u8 len
134 return ret == 2 ? 0 : ret; 135 return ret == 2 ? 0 : ret;
135} 136}
136 137
137static int stv0299_set_FEC (struct stv0299_state* state, fe_code_rate_t fec) 138static int stv0299_set_FEC(struct stv0299_state *state, enum fe_code_rate fec)
138{ 139{
139 dprintk ("%s\n", __func__); 140 dprintk ("%s\n", __func__);
140 141
@@ -170,10 +171,10 @@ static int stv0299_set_FEC (struct stv0299_state* state, fe_code_rate_t fec)
170 } 171 }
171} 172}
172 173
173static fe_code_rate_t stv0299_get_fec (struct stv0299_state* state) 174static enum fe_code_rate stv0299_get_fec(struct stv0299_state *state)
174{ 175{
175 static fe_code_rate_t fec_tab [] = { FEC_2_3, FEC_3_4, FEC_5_6, 176 static enum fe_code_rate fec_tab[] = { FEC_2_3, FEC_3_4, FEC_5_6,
176 FEC_7_8, FEC_1_2 }; 177 FEC_7_8, FEC_1_2 };
177 u8 index; 178 u8 index;
178 179
179 dprintk ("%s\n", __func__); 180 dprintk ("%s\n", __func__);
@@ -302,7 +303,8 @@ static int stv0299_send_diseqc_msg (struct dvb_frontend* fe,
302 return 0; 303 return 0;
303} 304}
304 305
305static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 306static int stv0299_send_diseqc_burst(struct dvb_frontend *fe,
307 enum fe_sec_mini_cmd burst)
306{ 308{
307 struct stv0299_state* state = fe->demodulator_priv; 309 struct stv0299_state* state = fe->demodulator_priv;
308 u8 val; 310 u8 val;
@@ -329,7 +331,8 @@ static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t
329 return 0; 331 return 0;
330} 332}
331 333
332static int stv0299_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 334static int stv0299_set_tone(struct dvb_frontend *fe,
335 enum fe_sec_tone_mode tone)
333{ 336{
334 struct stv0299_state* state = fe->demodulator_priv; 337 struct stv0299_state* state = fe->demodulator_priv;
335 u8 val; 338 u8 val;
@@ -351,7 +354,8 @@ static int stv0299_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
351 } 354 }
352} 355}
353 356
354static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 357static int stv0299_set_voltage(struct dvb_frontend *fe,
358 enum fe_sec_voltage voltage)
355{ 359{
356 struct stv0299_state* state = fe->demodulator_priv; 360 struct stv0299_state* state = fe->demodulator_priv;
357 u8 reg0x08; 361 u8 reg0x08;
@@ -404,8 +408,8 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
404 u8 lv_mask = 0x40; 408 u8 lv_mask = 0x40;
405 u8 last = 1; 409 u8 last = 1;
406 int i; 410 int i;
407 struct timeval nexttime; 411 ktime_t nexttime;
408 struct timeval tv[10]; 412 ktime_t tv[10];
409 413
410 reg0x08 = stv0299_readreg (state, 0x08); 414 reg0x08 = stv0299_readreg (state, 0x08);
411 reg0x0c = stv0299_readreg (state, 0x0c); 415 reg0x0c = stv0299_readreg (state, 0x0c);
@@ -418,7 +422,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
418 if (debug_legacy_dish_switch) 422 if (debug_legacy_dish_switch)
419 printk ("%s switch command: 0x%04lx\n",__func__, cmd); 423 printk ("%s switch command: 0x%04lx\n",__func__, cmd);
420 424
421 do_gettimeofday (&nexttime); 425 nexttime = ktime_get_real();
422 if (debug_legacy_dish_switch) 426 if (debug_legacy_dish_switch)
423 tv[0] = nexttime; 427 tv[0] = nexttime;
424 stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */ 428 stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */
@@ -427,7 +431,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
427 431
428 for (i=0; i<9; i++) { 432 for (i=0; i<9; i++) {
429 if (debug_legacy_dish_switch) 433 if (debug_legacy_dish_switch)
430 do_gettimeofday (&tv[i+1]); 434 tv[i+1] = ktime_get_real();
431 if((cmd & 0x01) != last) { 435 if((cmd & 0x01) != last) {
432 /* set voltage to (last ? 13V : 18V) */ 436 /* set voltage to (last ? 13V : 18V) */
433 stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50)); 437 stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50));
@@ -443,7 +447,8 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
443 printk ("%s(%d): switch delay (should be 32k followed by all 8k\n", 447 printk ("%s(%d): switch delay (should be 32k followed by all 8k\n",
444 __func__, fe->dvb->num); 448 __func__, fe->dvb->num);
445 for (i = 1; i < 10; i++) 449 for (i = 1; i < 10; i++)
446 printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); 450 printk("%d: %d\n", i,
451 (int) ktime_us_delta(tv[i], tv[i-1]));
447 } 452 }
448 453
449 return 0; 454 return 0;
@@ -476,7 +481,8 @@ static int stv0299_init (struct dvb_frontend* fe)
476 return 0; 481 return 0;
477} 482}
478 483
479static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status) 484static int stv0299_read_status(struct dvb_frontend *fe,
485 enum fe_status *status)
480{ 486{
481 struct stv0299_state* state = fe->demodulator_priv; 487 struct stv0299_state* state = fe->demodulator_priv;
482 488
diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c
index b31ff265ff24..ec3e18e5ff50 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -59,7 +59,7 @@ struct stv0367cab_state {
59 int locked; /* channel found */ 59 int locked; /* channel found */
60 u32 freq_khz; /* found frequency (in kHz) */ 60 u32 freq_khz; /* found frequency (in kHz) */
61 u32 symbol_rate; /* found symbol rate (in Bds) */ 61 u32 symbol_rate; /* found symbol rate (in Bds) */
62 fe_spectral_inversion_t spect_inv; /* Spectrum Inversion */ 62 enum fe_spectral_inversion spect_inv; /* Spectrum Inversion */
63}; 63};
64 64
65struct stv0367ter_state { 65struct stv0367ter_state {
@@ -67,10 +67,10 @@ struct stv0367ter_state {
67 enum stv0367_ter_signal_type state; 67 enum stv0367_ter_signal_type state;
68 enum stv0367_ter_if_iq_mode if_iq_mode; 68 enum stv0367_ter_if_iq_mode if_iq_mode;
69 enum stv0367_ter_mode mode;/* mode 2K or 8K */ 69 enum stv0367_ter_mode mode;/* mode 2K or 8K */
70 fe_guard_interval_t guard; 70 enum fe_guard_interval guard;
71 enum stv0367_ter_hierarchy hierarchy; 71 enum stv0367_ter_hierarchy hierarchy;
72 u32 frequency; 72 u32 frequency;
73 fe_spectral_inversion_t sense; /* current search spectrum */ 73 enum fe_spectral_inversion sense; /* current search spectrum */
74 u8 force; /* force mode/guard */ 74 u8 force; /* force mode/guard */
75 u8 bw; /* channel width 6, 7 or 8 in MHz */ 75 u8 bw; /* channel width 6, 7 or 8 in MHz */
76 u8 pBW; /* channel width used during previous lock */ 76 u8 pBW; /* channel width used during previous lock */
@@ -2074,7 +2074,8 @@ static int stv0367ter_status(struct dvb_frontend *fe)
2074 return locked; 2074 return locked;
2075} 2075}
2076#endif 2076#endif
2077static int stv0367ter_read_status(struct dvb_frontend *fe, fe_status_t *status) 2077static int stv0367ter_read_status(struct dvb_frontend *fe,
2078 enum fe_status *status)
2078{ 2079{
2079 struct stv0367_state *state = fe->demodulator_priv; 2080 struct stv0367_state *state = fe->demodulator_priv;
2080 2081
@@ -2716,7 +2717,8 @@ static u32 stv0367cab_GetSymbolRate(struct stv0367_state *state, u32 mclk_hz)
2716 return regsym; 2717 return regsym;
2717} 2718}
2718 2719
2719static int stv0367cab_read_status(struct dvb_frontend *fe, fe_status_t *status) 2720static int stv0367cab_read_status(struct dvb_frontend *fe,
2721 enum fe_status *status)
2720{ 2722{
2721 struct stv0367_state *state = fe->demodulator_priv; 2723 struct stv0367_state *state = fe->demodulator_priv;
2722 2724
diff --git a/drivers/media/dvb-frontends/stv0367_priv.h b/drivers/media/dvb-frontends/stv0367_priv.h
index 995db0689ddd..89bf6f64b078 100644
--- a/drivers/media/dvb-frontends/stv0367_priv.h
+++ b/drivers/media/dvb-frontends/stv0367_priv.h
@@ -188,7 +188,7 @@ struct stv0367_cab_signal_info {
188 u32 frequency; /* kHz */ 188 u32 frequency; /* kHz */
189 u32 symbol_rate; /* Mbds */ 189 u32 symbol_rate; /* Mbds */
190 enum stv0367cab_mod modulation; 190 enum stv0367cab_mod modulation;
191 fe_spectral_inversion_t spect_inv; 191 enum fe_spectral_inversion spect_inv;
192 s32 Power_dBmx10; /* Power of the RF signal (dBm x 10) */ 192 s32 Power_dBmx10; /* Power of the RF signal (dBm x 10) */
193 u32 CN_dBx10; /* Carrier to noise ratio (dB x 10) */ 193 u32 CN_dBx10; /* Carrier to noise ratio (dB x 10) */
194 u32 BER; /* Bit error rate (x 10000000) */ 194 u32 BER; /* Bit error rate (x 10000000) */
diff --git a/drivers/media/dvb-frontends/stv0900_core.c b/drivers/media/dvb-frontends/stv0900_core.c
index 2c88abfab531..fe31dd541955 100644
--- a/drivers/media/dvb-frontends/stv0900_core.c
+++ b/drivers/media/dvb-frontends/stv0900_core.c
@@ -1744,7 +1744,8 @@ static int stv0900_send_master_cmd(struct dvb_frontend *fe,
1744 state->demod); 1744 state->demod);
1745} 1745}
1746 1746
1747static int stv0900_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst) 1747static int stv0900_send_burst(struct dvb_frontend *fe,
1748 enum fe_sec_mini_cmd burst)
1748{ 1749{
1749 struct stv0900_state *state = fe->demodulator_priv; 1750 struct stv0900_state *state = fe->demodulator_priv;
1750 struct stv0900_internal *intp = state->internal; 1751 struct stv0900_internal *intp = state->internal;
@@ -1793,7 +1794,8 @@ static int stv0900_recv_slave_reply(struct dvb_frontend *fe,
1793 return 0; 1794 return 0;
1794} 1795}
1795 1796
1796static int stv0900_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t toneoff) 1797static int stv0900_set_tone(struct dvb_frontend *fe,
1798 enum fe_sec_tone_mode toneoff)
1797{ 1799{
1798 struct stv0900_state *state = fe->demodulator_priv; 1800 struct stv0900_state *state = fe->demodulator_priv;
1799 struct stv0900_internal *intp = state->internal; 1801 struct stv0900_internal *intp = state->internal;
diff --git a/drivers/media/dvb-frontends/stv0900_sw.c b/drivers/media/dvb-frontends/stv0900_sw.c
index a0a7b1664c53..fa63a9e929ce 100644
--- a/drivers/media/dvb-frontends/stv0900_sw.c
+++ b/drivers/media/dvb-frontends/stv0900_sw.c
@@ -1556,8 +1556,8 @@ static u32 stv0900_search_srate_fine(struct dvb_frontend *fe)
1556 } 1556 }
1557 1557
1558 symbcomp = 13 * (coarse_srate / 10); 1558 symbcomp = 13 * (coarse_srate / 10);
1559 coarse_freq = (stv0900_read_reg(intp, CFR2) << 8) 1559 coarse_freq = (stv0900_read_reg(intp, CFR2) << 8)
1560 | stv0900_read_reg(intp, CFR1); 1560 | stv0900_read_reg(intp, CFR1);
1561 1561
1562 if (symbcomp < intp->symbol_rate[demod]) 1562 if (symbcomp < intp->symbol_rate[demod])
1563 coarse_srate = 0; 1563 coarse_srate = 0;
@@ -2009,7 +2009,7 @@ enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe)
2009 signal_type = STV0900_NODATA; 2009 signal_type = STV0900_NODATA;
2010 no_signal = stv0900_check_signal_presence(intp, demod); 2010 no_signal = stv0900_check_signal_presence(intp, demod);
2011 2011
2012 intp->result[demod].locked = FALSE; 2012 intp->result[demod].locked = FALSE;
2013 } 2013 }
2014 } 2014 }
2015 2015
diff --git a/drivers/media/dvb-frontends/stv090x.c b/drivers/media/dvb-frontends/stv090x.c
index 0b2a934f53e5..25bdf6e0f963 100644
--- a/drivers/media/dvb-frontends/stv090x.c
+++ b/drivers/media/dvb-frontends/stv090x.c
@@ -3732,7 +3732,7 @@ static int stv090x_read_cnr(struct dvb_frontend *fe, u16 *cnr)
3732 return 0; 3732 return 0;
3733} 3733}
3734 3734
3735static int stv090x_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 3735static int stv090x_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
3736{ 3736{
3737 struct stv090x_state *state = fe->demodulator_priv; 3737 struct stv090x_state *state = fe->demodulator_priv;
3738 u32 reg; 3738 u32 reg;
@@ -3822,7 +3822,8 @@ err:
3822 return -1; 3822 return -1;
3823} 3823}
3824 3824
3825static int stv090x_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst) 3825static int stv090x_send_diseqc_burst(struct dvb_frontend *fe,
3826 enum fe_sec_mini_cmd burst)
3826{ 3827{
3827 struct stv090x_state *state = fe->demodulator_priv; 3828 struct stv090x_state *state = fe->demodulator_priv;
3828 u32 reg, idle = 0, fifo_full = 1; 3829 u32 reg, idle = 0, fifo_full = 1;
diff --git a/drivers/media/dvb-frontends/stv6110.c b/drivers/media/dvb-frontends/stv6110.c
index b1425830a24e..91c6dcf65d2a 100644
--- a/drivers/media/dvb-frontends/stv6110.c
+++ b/drivers/media/dvb-frontends/stv6110.c
@@ -158,7 +158,7 @@ static int stv6110_sleep(struct dvb_frontend *fe)
158 return 0; 158 return 0;
159} 159}
160 160
161static u32 carrier_width(u32 symbol_rate, fe_rolloff_t rolloff) 161static u32 carrier_width(u32 symbol_rate, enum fe_rolloff rolloff)
162{ 162{
163 u32 rlf; 163 u32 rlf;
164 164
diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c
index dce22ce35d20..456cdc7fb1e7 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -130,7 +130,7 @@ static int tc90522t_set_layers(struct dvb_frontend *fe)
130 130
131/* frontend ops */ 131/* frontend ops */
132 132
133static int tc90522s_read_status(struct dvb_frontend *fe, fe_status_t *status) 133static int tc90522s_read_status(struct dvb_frontend *fe, enum fe_status *status)
134{ 134{
135 struct tc90522_state *state; 135 struct tc90522_state *state;
136 int ret; 136 int ret;
@@ -158,7 +158,7 @@ static int tc90522s_read_status(struct dvb_frontend *fe, fe_status_t *status)
158 return 0; 158 return 0;
159} 159}
160 160
161static int tc90522t_read_status(struct dvb_frontend *fe, fe_status_t *status) 161static int tc90522t_read_status(struct dvb_frontend *fe, enum fe_status *status)
162{ 162{
163 struct tc90522_state *state; 163 struct tc90522_state *state;
164 int ret; 164 int ret;
@@ -194,7 +194,7 @@ static int tc90522t_read_status(struct dvb_frontend *fe, fe_status_t *status)
194 return 0; 194 return 0;
195} 195}
196 196
197static const fe_code_rate_t fec_conv_sat[] = { 197static const enum fe_code_rate fec_conv_sat[] = {
198 FEC_NONE, /* unused */ 198 FEC_NONE, /* unused */
199 FEC_1_2, /* for BPSK */ 199 FEC_1_2, /* for BPSK */
200 FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, /* for QPSK */ 200 FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, /* for QPSK */
@@ -238,7 +238,10 @@ static int tc90522s_get_frontend(struct dvb_frontend *fe)
238 c->layer[1].segment_count = 0; 238 c->layer[1].segment_count = 0;
239 else 239 else
240 c->layer[1].segment_count = val[4] & 0x3f; /* slots */ 240 c->layer[1].segment_count = val[4] & 0x3f; /* slots */
241 /* actually, BPSK if v==1, but not defined in fe_modulation_t */ 241 /*
242 * actually, BPSK if v==1, but not defined in
243 * enum fe_modulation
244 */
242 c->layer[1].modulation = QPSK; 245 c->layer[1].modulation = QPSK;
243 layers = (v > 0) ? 2 : 1; 246 layers = (v > 0) ? 2 : 1;
244 } 247 }
@@ -319,18 +322,18 @@ static int tc90522s_get_frontend(struct dvb_frontend *fe)
319} 322}
320 323
321 324
322static const fe_transmit_mode_t tm_conv[] = { 325static const enum fe_transmit_mode tm_conv[] = {
323 TRANSMISSION_MODE_2K, 326 TRANSMISSION_MODE_2K,
324 TRANSMISSION_MODE_4K, 327 TRANSMISSION_MODE_4K,
325 TRANSMISSION_MODE_8K, 328 TRANSMISSION_MODE_8K,
326 0 329 0
327}; 330};
328 331
329static const fe_code_rate_t fec_conv_ter[] = { 332static const enum fe_code_rate fec_conv_ter[] = {
330 FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, 0, 0, 0 333 FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, 0, 0, 0
331}; 334};
332 335
333static const fe_modulation_t mod_conv[] = { 336static const enum fe_modulation mod_conv[] = {
334 DQPSK, QPSK, QAM_16, QAM_64, 0, 0, 0, 0 337 DQPSK, QPSK, QAM_16, QAM_64, 0, 0, 0, 0
335}; 338};
336 339
diff --git a/drivers/media/dvb-frontends/tda10021.c b/drivers/media/dvb-frontends/tda10021.c
index 1bff7f457e19..a684424e665a 100644
--- a/drivers/media/dvb-frontends/tda10021.c
+++ b/drivers/media/dvb-frontends/tda10021.c
@@ -129,8 +129,8 @@ static int unlock_tuner(struct tda10021_state* state)
129 return 0; 129 return 0;
130} 130}
131 131
132static int tda10021_setup_reg0 (struct tda10021_state* state, u8 reg0, 132static int tda10021_setup_reg0(struct tda10021_state *state, u8 reg0,
133 fe_spectral_inversion_t inversion) 133 enum fe_spectral_inversion inversion)
134{ 134{
135 reg0 |= state->reg0 & 0x63; 135 reg0 |= state->reg0 & 0x63;
136 136
@@ -258,7 +258,7 @@ static int tda10021_set_parameters(struct dvb_frontend *fe)
258 } 258 }
259 259
260 /* 260 /*
261 * gcc optimizes the code bellow the same way as it would code: 261 * gcc optimizes the code below the same way as it would code:
262 * "if (qam > 5) return -EINVAL;" 262 * "if (qam > 5) return -EINVAL;"
263 * Yet, the code is clearer, as it shows what QAM standards are 263 * Yet, the code is clearer, as it shows what QAM standards are
264 * supported by the driver, and avoids the usage of magic numbers on 264 * supported by the driver, and avoids the usage of magic numbers on
@@ -308,7 +308,8 @@ static int tda10021_set_parameters(struct dvb_frontend *fe)
308 return 0; 308 return 0;
309} 309}
310 310
311static int tda10021_read_status(struct dvb_frontend* fe, fe_status_t* status) 311static int tda10021_read_status(struct dvb_frontend *fe,
312 enum fe_status *status)
312{ 313{
313 struct tda10021_state* state = fe->demodulator_priv; 314 struct tda10021_state* state = fe->demodulator_priv;
314 int sync; 315 int sync;
diff --git a/drivers/media/dvb-frontends/tda10023.c b/drivers/media/dvb-frontends/tda10023.c
index ca1e0d54b69a..44a55656093f 100644
--- a/drivers/media/dvb-frontends/tda10023.c
+++ b/drivers/media/dvb-frontends/tda10023.c
@@ -331,7 +331,7 @@ static int tda10023_set_parameters(struct dvb_frontend *fe)
331 } 331 }
332 332
333 /* 333 /*
334 * gcc optimizes the code bellow the same way as it would code: 334 * gcc optimizes the code below the same way as it would code:
335 * "if (qam > 5) return -EINVAL;" 335 * "if (qam > 5) return -EINVAL;"
336 * Yet, the code is clearer, as it shows what QAM standards are 336 * Yet, the code is clearer, as it shows what QAM standards are
337 * supported by the driver, and avoids the usage of magic numbers on 337 * supported by the driver, and avoids the usage of magic numbers on
@@ -376,7 +376,8 @@ static int tda10023_set_parameters(struct dvb_frontend *fe)
376 return 0; 376 return 0;
377} 377}
378 378
379static int tda10023_read_status(struct dvb_frontend* fe, fe_status_t* status) 379static int tda10023_read_status(struct dvb_frontend *fe,
380 enum fe_status *status)
380{ 381{
381 struct tda10023_state* state = fe->demodulator_priv; 382 struct tda10023_state* state = fe->demodulator_priv;
382 int sync; 383 int sync;
diff --git a/drivers/media/dvb-frontends/tda10048.c b/drivers/media/dvb-frontends/tda10048.c
index 71fb63299de7..8451086c563f 100644
--- a/drivers/media/dvb-frontends/tda10048.c
+++ b/drivers/media/dvb-frontends/tda10048.c
@@ -792,7 +792,7 @@ static int tda10048_init(struct dvb_frontend *fe)
792 return ret; 792 return ret;
793} 793}
794 794
795static int tda10048_read_status(struct dvb_frontend *fe, fe_status_t *status) 795static int tda10048_read_status(struct dvb_frontend *fe, enum fe_status *status)
796{ 796{
797 struct tda10048_state *state = fe->demodulator_priv; 797 struct tda10048_state *state = fe->demodulator_priv;
798 u8 reg; 798 u8 reg;
diff --git a/drivers/media/dvb-frontends/tda1004x.c b/drivers/media/dvb-frontends/tda1004x.c
index a2631be7ffac..0e209b56c76c 100644
--- a/drivers/media/dvb-frontends/tda1004x.c
+++ b/drivers/media/dvb-frontends/tda1004x.c
@@ -650,7 +650,7 @@ static int tda10046_init(struct dvb_frontend* fe)
650 650
651 if (tda10046_fwupload(fe)) { 651 if (tda10046_fwupload(fe)) {
652 printk("tda1004x: firmware upload failed\n"); 652 printk("tda1004x: firmware upload failed\n");
653 return -EIO; 653 return -EIO;
654 } 654 }
655 655
656 // tda setup 656 // tda setup
@@ -1005,7 +1005,8 @@ static int tda1004x_get_fe(struct dvb_frontend *fe)
1005 return 0; 1005 return 0;
1006} 1006}
1007 1007
1008static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status) 1008static int tda1004x_read_status(struct dvb_frontend *fe,
1009 enum fe_status *fe_status)
1009{ 1010{
1010 struct tda1004x_state* state = fe->demodulator_priv; 1011 struct tda1004x_state* state = fe->demodulator_priv;
1011 int status; 1012 int status;
diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index 4a19b85995f1..f6dc6307d35a 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -203,7 +203,7 @@ error:
203} 203}
204 204
205static int tda10071_set_tone(struct dvb_frontend *fe, 205static int tda10071_set_tone(struct dvb_frontend *fe,
206 fe_sec_tone_mode_t fe_sec_tone_mode) 206 enum fe_sec_tone_mode fe_sec_tone_mode)
207{ 207{
208 struct tda10071_priv *priv = fe->demodulator_priv; 208 struct tda10071_priv *priv = fe->demodulator_priv;
209 struct tda10071_cmd cmd; 209 struct tda10071_cmd cmd;
@@ -249,7 +249,7 @@ error:
249} 249}
250 250
251static int tda10071_set_voltage(struct dvb_frontend *fe, 251static int tda10071_set_voltage(struct dvb_frontend *fe,
252 fe_sec_voltage_t fe_sec_voltage) 252 enum fe_sec_voltage fe_sec_voltage)
253{ 253{
254 struct tda10071_priv *priv = fe->demodulator_priv; 254 struct tda10071_priv *priv = fe->demodulator_priv;
255 struct tda10071_cmd cmd; 255 struct tda10071_cmd cmd;
@@ -413,7 +413,7 @@ error:
413} 413}
414 414
415static int tda10071_diseqc_send_burst(struct dvb_frontend *fe, 415static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
416 fe_sec_mini_cmd_t fe_sec_mini_cmd) 416 enum fe_sec_mini_cmd fe_sec_mini_cmd)
417{ 417{
418 struct tda10071_priv *priv = fe->demodulator_priv; 418 struct tda10071_priv *priv = fe->demodulator_priv;
419 struct tda10071_cmd cmd; 419 struct tda10071_cmd cmd;
@@ -476,7 +476,7 @@ error:
476 return ret; 476 return ret;
477} 477}
478 478
479static int tda10071_read_status(struct dvb_frontend *fe, fe_status_t *status) 479static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
480{ 480{
481 struct tda10071_priv *priv = fe->demodulator_priv; 481 struct tda10071_priv *priv = fe->demodulator_priv;
482 int ret; 482 int ret;
@@ -668,7 +668,7 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
668 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 668 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
669 int ret, i; 669 int ret, i;
670 u8 mode, rolloff, pilot, inversion, div; 670 u8 mode, rolloff, pilot, inversion, div;
671 fe_modulation_t modulation; 671 enum fe_modulation modulation;
672 672
673 dev_dbg(&priv->i2c->dev, 673 dev_dbg(&priv->i2c->dev,
674 "%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 674 "%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
@@ -1313,6 +1313,113 @@ static struct dvb_frontend_ops tda10071_ops = {
1313 .set_voltage = tda10071_set_voltage, 1313 .set_voltage = tda10071_set_voltage,
1314}; 1314};
1315 1315
1316static struct dvb_frontend *tda10071_get_dvb_frontend(struct i2c_client *client)
1317{
1318 struct tda10071_priv *dev = i2c_get_clientdata(client);
1319
1320 dev_dbg(&client->dev, "\n");
1321
1322 return &dev->fe;
1323}
1324
1325static int tda10071_probe(struct i2c_client *client,
1326 const struct i2c_device_id *id)
1327{
1328 struct tda10071_priv *dev;
1329 struct tda10071_platform_data *pdata = client->dev.platform_data;
1330 int ret;
1331 u8 u8tmp;
1332
1333 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1334 if (!dev) {
1335 ret = -ENOMEM;
1336 goto err;
1337 }
1338
1339 dev->client = client;
1340 dev->i2c = client->adapter;
1341 dev->cfg.demod_i2c_addr = client->addr;
1342 dev->cfg.i2c_wr_max = pdata->i2c_wr_max;
1343 dev->cfg.ts_mode = pdata->ts_mode;
1344 dev->cfg.spec_inv = pdata->spec_inv;
1345 dev->cfg.xtal = pdata->clk;
1346 dev->cfg.pll_multiplier = pdata->pll_multiplier;
1347 dev->cfg.tuner_i2c_addr = pdata->tuner_i2c_addr;
1348
1349 /* chip ID */
1350 ret = tda10071_rd_reg(dev, 0xff, &u8tmp);
1351 if (ret)
1352 goto err_kfree;
1353 if (u8tmp != 0x0f) {
1354 ret = -ENODEV;
1355 goto err_kfree;
1356 }
1357
1358 /* chip type */
1359 ret = tda10071_rd_reg(dev, 0xdd, &u8tmp);
1360 if (ret)
1361 goto err_kfree;
1362 if (u8tmp != 0x00) {
1363 ret = -ENODEV;
1364 goto err_kfree;
1365 }
1366
1367 /* chip version */
1368 ret = tda10071_rd_reg(dev, 0xfe, &u8tmp);
1369 if (ret)
1370 goto err_kfree;
1371 if (u8tmp != 0x01) {
1372 ret = -ENODEV;
1373 goto err_kfree;
1374 }
1375
1376 /* create dvb_frontend */
1377 memcpy(&dev->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops));
1378 dev->fe.ops.release = NULL;
1379 dev->fe.demodulator_priv = dev;
1380 i2c_set_clientdata(client, dev);
1381
1382 /* setup callbacks */
1383 pdata->get_dvb_frontend = tda10071_get_dvb_frontend;
1384
1385 dev_info(&client->dev, "NXP TDA10071 successfully identified\n");
1386 return 0;
1387err_kfree:
1388 kfree(dev);
1389err:
1390 dev_dbg(&client->dev, "failed=%d\n", ret);
1391 return ret;
1392}
1393
1394static int tda10071_remove(struct i2c_client *client)
1395{
1396 struct tda10071_dev *dev = i2c_get_clientdata(client);
1397
1398 dev_dbg(&client->dev, "\n");
1399
1400 kfree(dev);
1401 return 0;
1402}
1403
1404static const struct i2c_device_id tda10071_id_table[] = {
1405 {"tda10071_cx24118", 0},
1406 {}
1407};
1408MODULE_DEVICE_TABLE(i2c, tda10071_id_table);
1409
1410static struct i2c_driver tda10071_driver = {
1411 .driver = {
1412 .owner = THIS_MODULE,
1413 .name = "tda10071",
1414 .suppress_bind_attrs = true,
1415 },
1416 .probe = tda10071_probe,
1417 .remove = tda10071_remove,
1418 .id_table = tda10071_id_table,
1419};
1420
1421module_i2c_driver(tda10071_driver);
1422
1316MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 1423MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1317MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver"); 1424MODULE_DESCRIPTION("NXP TDA10071 DVB-S/S2 demodulator driver");
1318MODULE_LICENSE("GPL"); 1425MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/tda10071.h b/drivers/media/dvb-frontends/tda10071.h
index da89f4249846..0ffbfa5b2dfb 100644
--- a/drivers/media/dvb-frontends/tda10071.h
+++ b/drivers/media/dvb-frontends/tda10071.h
@@ -24,6 +24,35 @@
24#include <linux/kconfig.h> 24#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
26 26
27/*
28 * I2C address
29 * 0x55,
30 */
31
32/**
33 * struct tda10071_platform_data - Platform data for the tda10071 driver
34 * @clk: Clock frequency.
35 * @i2c_wr_max: Max bytes I2C adapter can write at once.
36 * @ts_mode: TS mode.
37 * @spec_inv: Input spectrum inversion.
38 * @pll_multiplier: PLL multiplier.
39 * @tuner_i2c_addr: CX24118A tuner I2C address (0x14, 0x54, ...).
40 * @get_dvb_frontend: Get DVB frontend.
41 */
42
43struct tda10071_platform_data {
44 u32 clk;
45 u16 i2c_wr_max;
46#define TDA10071_TS_SERIAL 0
47#define TDA10071_TS_PARALLEL 1
48 u8 ts_mode;
49 bool spec_inv;
50 u8 pll_multiplier;
51 u8 tuner_i2c_addr;
52
53 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
54};
55
27struct tda10071_config { 56struct tda10071_config {
28 /* Demodulator I2C address. 57 /* Demodulator I2C address.
29 * Default: none, must set 58 * Default: none, must set
diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h
index 03f839c431e9..54d7c713eec8 100644
--- a/drivers/media/dvb-frontends/tda10071_priv.h
+++ b/drivers/media/dvb-frontends/tda10071_priv.h
@@ -28,20 +28,21 @@
28struct tda10071_priv { 28struct tda10071_priv {
29 struct i2c_adapter *i2c; 29 struct i2c_adapter *i2c;
30 struct dvb_frontend fe; 30 struct dvb_frontend fe;
31 struct i2c_client *client;
31 struct tda10071_config cfg; 32 struct tda10071_config cfg;
32 33
33 u8 meas_count[2]; 34 u8 meas_count[2];
34 u32 ber; 35 u32 ber;
35 u32 ucb; 36 u32 ucb;
36 fe_status_t fe_status; 37 enum fe_status fe_status;
37 fe_delivery_system_t delivery_system; 38 enum fe_delivery_system delivery_system;
38 bool warm; /* FW running */ 39 bool warm; /* FW running */
39}; 40};
40 41
41static struct tda10071_modcod { 42static struct tda10071_modcod {
42 fe_delivery_system_t delivery_system; 43 enum fe_delivery_system delivery_system;
43 fe_modulation_t modulation; 44 enum fe_modulation modulation;
44 fe_code_rate_t fec; 45 enum fe_code_rate fec;
45 u8 val; 46 u8 val;
46} TDA10071_MODCOD[] = { 47} TDA10071_MODCOD[] = {
47 /* NBC-QPSK */ 48 /* NBC-QPSK */
diff --git a/drivers/media/dvb-frontends/tda10086.c b/drivers/media/dvb-frontends/tda10086.c
index fcfe2e080cb0..95a33e187f8e 100644
--- a/drivers/media/dvb-frontends/tda10086.c
+++ b/drivers/media/dvb-frontends/tda10086.c
@@ -185,7 +185,8 @@ static void tda10086_diseqc_wait(struct tda10086_state *state)
185 } 185 }
186} 186}
187 187
188static int tda10086_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 188static int tda10086_set_tone(struct dvb_frontend *fe,
189 enum fe_sec_tone_mode tone)
189{ 190{
190 struct tda10086_state* state = fe->demodulator_priv; 191 struct tda10086_state* state = fe->demodulator_priv;
191 u8 t22k_off = 0x80; 192 u8 t22k_off = 0x80;
@@ -238,7 +239,8 @@ static int tda10086_send_master_cmd (struct dvb_frontend* fe,
238 return 0; 239 return 0;
239} 240}
240 241
241static int tda10086_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 242static int tda10086_send_burst(struct dvb_frontend *fe,
243 enum fe_sec_mini_cmd minicmd)
242{ 244{
243 struct tda10086_state* state = fe->demodulator_priv; 245 struct tda10086_state* state = fe->demodulator_priv;
244 u8 oldval = tda10086_read_byte(state, 0x36); 246 u8 oldval = tda10086_read_byte(state, 0x36);
@@ -472,8 +474,8 @@ static int tda10086_get_frontend(struct dvb_frontend *fe)
472 return -EINVAL; 474 return -EINVAL;
473 475
474 /* calculate the updated frequency (note: we convert from Hz->kHz) */ 476 /* calculate the updated frequency (note: we convert from Hz->kHz) */
475 tmp64 = tda10086_read_byte(state, 0x52); 477 tmp64 = ((u64)tda10086_read_byte(state, 0x52)
476 tmp64 |= (tda10086_read_byte(state, 0x51) << 8); 478 | (tda10086_read_byte(state, 0x51) << 8));
477 if (tmp64 & 0x8000) 479 if (tmp64 & 0x8000)
478 tmp64 |= 0xffffffffffff0000ULL; 480 tmp64 |= 0xffffffffffff0000ULL;
479 tmp64 = (tmp64 * (SACLK/1000ULL)); 481 tmp64 = (tmp64 * (SACLK/1000ULL));
@@ -551,7 +553,8 @@ static int tda10086_get_frontend(struct dvb_frontend *fe)
551 return 0; 553 return 0;
552} 554}
553 555
554static int tda10086_read_status(struct dvb_frontend* fe, fe_status_t *fe_status) 556static int tda10086_read_status(struct dvb_frontend *fe,
557 enum fe_status *fe_status)
555{ 558{
556 struct tda10086_state* state = fe->demodulator_priv; 559 struct tda10086_state* state = fe->demodulator_priv;
557 u8 val; 560 u8 val;
diff --git a/drivers/media/dvb-frontends/tda8083.c b/drivers/media/dvb-frontends/tda8083.c
index 69e62f42e2e1..796543fa2c8d 100644
--- a/drivers/media/dvb-frontends/tda8083.c
+++ b/drivers/media/dvb-frontends/tda8083.c
@@ -97,7 +97,8 @@ static inline u8 tda8083_readreg (struct tda8083_state* state, u8 reg)
97 return val; 97 return val;
98} 98}
99 99
100static int tda8083_set_inversion (struct tda8083_state* state, fe_spectral_inversion_t inversion) 100static int tda8083_set_inversion(struct tda8083_state *state,
101 enum fe_spectral_inversion inversion)
101{ 102{
102 /* XXX FIXME: implement other modes than FEC_AUTO */ 103 /* XXX FIXME: implement other modes than FEC_AUTO */
103 if (inversion == INVERSION_AUTO) 104 if (inversion == INVERSION_AUTO)
@@ -106,7 +107,7 @@ static int tda8083_set_inversion (struct tda8083_state* state, fe_spectral_inver
106 return -EINVAL; 107 return -EINVAL;
107} 108}
108 109
109static int tda8083_set_fec (struct tda8083_state* state, fe_code_rate_t fec) 110static int tda8083_set_fec(struct tda8083_state *state, enum fe_code_rate fec)
110{ 111{
111 if (fec == FEC_AUTO) 112 if (fec == FEC_AUTO)
112 return tda8083_writereg (state, 0x07, 0xff); 113 return tda8083_writereg (state, 0x07, 0xff);
@@ -117,11 +118,13 @@ static int tda8083_set_fec (struct tda8083_state* state, fe_code_rate_t fec)
117 return -EINVAL; 118 return -EINVAL;
118} 119}
119 120
120static fe_code_rate_t tda8083_get_fec (struct tda8083_state* state) 121static enum fe_code_rate tda8083_get_fec(struct tda8083_state *state)
121{ 122{
122 u8 index; 123 u8 index;
123 static fe_code_rate_t fec_tab [] = { FEC_8_9, FEC_1_2, FEC_2_3, FEC_3_4, 124 static enum fe_code_rate fec_tab[] = {
124 FEC_4_5, FEC_5_6, FEC_6_7, FEC_7_8 }; 125 FEC_8_9, FEC_1_2, FEC_2_3, FEC_3_4,
126 FEC_4_5, FEC_5_6, FEC_6_7, FEC_7_8
127 };
125 128
126 index = tda8083_readreg(state, 0x0e) & 0x07; 129 index = tda8083_readreg(state, 0x0e) & 0x07;
127 130
@@ -178,7 +181,8 @@ static void tda8083_wait_diseqc_fifo (struct tda8083_state* state, int timeout)
178 } 181 }
179} 182}
180 183
181static int tda8083_set_tone (struct tda8083_state* state, fe_sec_tone_mode_t tone) 184static int tda8083_set_tone(struct tda8083_state *state,
185 enum fe_sec_tone_mode tone)
182{ 186{
183 tda8083_writereg (state, 0x26, 0xf1); 187 tda8083_writereg (state, 0x26, 0xf1);
184 188
@@ -192,7 +196,8 @@ static int tda8083_set_tone (struct tda8083_state* state, fe_sec_tone_mode_t ton
192 } 196 }
193} 197}
194 198
195static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t voltage) 199static int tda8083_set_voltage(struct tda8083_state *state,
200 enum fe_sec_voltage voltage)
196{ 201{
197 switch (voltage) { 202 switch (voltage) {
198 case SEC_VOLTAGE_13: 203 case SEC_VOLTAGE_13:
@@ -204,7 +209,8 @@ static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t vo
204 } 209 }
205} 210}
206 211
207static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_cmd_t burst) 212static int tda8083_send_diseqc_burst(struct tda8083_state *state,
213 enum fe_sec_mini_cmd burst)
208{ 214{
209 switch (burst) { 215 switch (burst) {
210 case SEC_MINI_A: 216 case SEC_MINI_A:
@@ -222,8 +228,8 @@ static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_c
222 return 0; 228 return 0;
223} 229}
224 230
225static int tda8083_send_diseqc_msg (struct dvb_frontend* fe, 231static int tda8083_send_diseqc_msg(struct dvb_frontend *fe,
226 struct dvb_diseqc_master_cmd *m) 232 struct dvb_diseqc_master_cmd *m)
227{ 233{
228 struct tda8083_state* state = fe->demodulator_priv; 234 struct tda8083_state* state = fe->demodulator_priv;
229 int i; 235 int i;
@@ -240,7 +246,8 @@ static int tda8083_send_diseqc_msg (struct dvb_frontend* fe,
240 return 0; 246 return 0;
241} 247}
242 248
243static int tda8083_read_status(struct dvb_frontend* fe, fe_status_t* status) 249static int tda8083_read_status(struct dvb_frontend *fe,
250 enum fe_status *status)
244{ 251{
245 struct tda8083_state* state = fe->demodulator_priv; 252 struct tda8083_state* state = fe->demodulator_priv;
246 253
@@ -372,7 +379,8 @@ static int tda8083_init(struct dvb_frontend* fe)
372 return 0; 379 return 0;
373} 380}
374 381
375static int tda8083_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 382static int tda8083_diseqc_send_burst(struct dvb_frontend *fe,
383 enum fe_sec_mini_cmd burst)
376{ 384{
377 struct tda8083_state* state = fe->demodulator_priv; 385 struct tda8083_state* state = fe->demodulator_priv;
378 386
@@ -383,7 +391,8 @@ static int tda8083_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
383 return 0; 391 return 0;
384} 392}
385 393
386static int tda8083_diseqc_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 394static int tda8083_diseqc_set_tone(struct dvb_frontend *fe,
395 enum fe_sec_tone_mode tone)
387{ 396{
388 struct tda8083_state* state = fe->demodulator_priv; 397 struct tda8083_state* state = fe->demodulator_priv;
389 398
@@ -394,7 +403,8 @@ static int tda8083_diseqc_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t t
394 return 0; 403 return 0;
395} 404}
396 405
397static int tda8083_diseqc_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 406static int tda8083_diseqc_set_voltage(struct dvb_frontend *fe,
407 enum fe_sec_voltage voltage)
398{ 408{
399 struct tda8083_state* state = fe->demodulator_priv; 409 struct tda8083_state* state = fe->demodulator_priv;
400 410
diff --git a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
index 90164a38cd36..f61b143a0052 100644
--- a/drivers/media/dvb-frontends/ts2020.c
+++ b/drivers/media/dvb-frontends/ts2020.c
@@ -21,23 +21,32 @@
21 21
22#include "dvb_frontend.h" 22#include "dvb_frontend.h"
23#include "ts2020.h" 23#include "ts2020.h"
24#include <linux/regmap.h>
25#include <linux/math64.h>
24 26
25#define TS2020_XTAL_FREQ 27000 /* in kHz */ 27#define TS2020_XTAL_FREQ 27000 /* in kHz */
26#define FREQ_OFFSET_LOW_SYM_RATE 3000 28#define FREQ_OFFSET_LOW_SYM_RATE 3000
27 29
28struct ts2020_priv { 30struct ts2020_priv {
31 struct i2c_client *client;
32 struct mutex regmap_mutex;
33 struct regmap_config regmap_config;
34 struct regmap *regmap;
29 struct dvb_frontend *fe; 35 struct dvb_frontend *fe;
36 struct delayed_work stat_work;
37 int (*get_agc_pwm)(struct dvb_frontend *fe, u8 *_agc_pwm);
30 /* i2c details */ 38 /* i2c details */
31 int i2c_address;
32 struct i2c_adapter *i2c; 39 struct i2c_adapter *i2c;
40 int i2c_address;
41 bool loop_through:1;
33 u8 clk_out:2; 42 u8 clk_out:2;
34 u8 clk_out_div:5; 43 u8 clk_out_div:5;
35 u32 frequency; 44 bool dont_poll:1;
36 u32 frequency_div; 45 u32 frequency_div; /* LO output divider switch frequency */
46 u32 frequency_khz; /* actual used LO frequency */
37#define TS2020_M88TS2020 0 47#define TS2020_M88TS2020 0
38#define TS2020_M88TS2022 1 48#define TS2020_M88TS2022 1
39 u8 tuner; 49 u8 tuner;
40 u8 loop_through:1;
41}; 50};
42 51
43struct ts2020_reg_val { 52struct ts2020_reg_val {
@@ -45,84 +54,23 @@ struct ts2020_reg_val {
45 u8 val; 54 u8 val;
46}; 55};
47 56
48static int ts2020_release(struct dvb_frontend *fe) 57static void ts2020_stat_work(struct work_struct *work);
49{
50 kfree(fe->tuner_priv);
51 fe->tuner_priv = NULL;
52 return 0;
53}
54 58
55static int ts2020_writereg(struct dvb_frontend *fe, int reg, int data) 59static int ts2020_release(struct dvb_frontend *fe)
56{ 60{
57 struct ts2020_priv *priv = fe->tuner_priv; 61 struct ts2020_priv *priv = fe->tuner_priv;
58 u8 buf[] = { reg, data }; 62 struct i2c_client *client = priv->client;
59 struct i2c_msg msg[] = {
60 {
61 .addr = priv->i2c_address,
62 .flags = 0,
63 .buf = buf,
64 .len = 2
65 }
66 };
67 int err;
68
69 if (fe->ops.i2c_gate_ctrl)
70 fe->ops.i2c_gate_ctrl(fe, 1);
71
72 err = i2c_transfer(priv->i2c, msg, 1);
73 if (err != 1) {
74 printk(KERN_ERR
75 "%s: writereg error(err == %i, reg == 0x%02x, value == 0x%02x)\n",
76 __func__, err, reg, data);
77 return -EREMOTEIO;
78 }
79 63
80 if (fe->ops.i2c_gate_ctrl) 64 dev_dbg(&client->dev, "\n");
81 fe->ops.i2c_gate_ctrl(fe, 0);
82 65
66 i2c_unregister_device(client);
83 return 0; 67 return 0;
84} 68}
85 69
86static int ts2020_readreg(struct dvb_frontend *fe, u8 reg)
87{
88 struct ts2020_priv *priv = fe->tuner_priv;
89 int ret;
90 u8 b0[] = { reg };
91 u8 b1[] = { 0 };
92 struct i2c_msg msg[] = {
93 {
94 .addr = priv->i2c_address,
95 .flags = 0,
96 .buf = b0,
97 .len = 1
98 }, {
99 .addr = priv->i2c_address,
100 .flags = I2C_M_RD,
101 .buf = b1,
102 .len = 1
103 }
104 };
105
106 if (fe->ops.i2c_gate_ctrl)
107 fe->ops.i2c_gate_ctrl(fe, 1);
108
109 ret = i2c_transfer(priv->i2c, msg, 2);
110
111 if (ret != 2) {
112 printk(KERN_ERR "%s: reg=0x%x(error=%d)\n",
113 __func__, reg, ret);
114 return ret;
115 }
116
117 if (fe->ops.i2c_gate_ctrl)
118 fe->ops.i2c_gate_ctrl(fe, 0);
119
120 return b1[0];
121}
122
123static int ts2020_sleep(struct dvb_frontend *fe) 70static int ts2020_sleep(struct dvb_frontend *fe)
124{ 71{
125 struct ts2020_priv *priv = fe->tuner_priv; 72 struct ts2020_priv *priv = fe->tuner_priv;
73 int ret;
126 u8 u8tmp; 74 u8 u8tmp;
127 75
128 if (priv->tuner == TS2020_M88TS2020) 76 if (priv->tuner == TS2020_M88TS2020)
@@ -130,24 +78,32 @@ static int ts2020_sleep(struct dvb_frontend *fe)
130 else 78 else
131 u8tmp = 0x00; 79 u8tmp = 0x00;
132 80
133 return ts2020_writereg(fe, u8tmp, 0x00); 81 ret = regmap_write(priv->regmap, u8tmp, 0x00);
82 if (ret < 0)
83 return ret;
84
85 /* stop statistics polling */
86 if (!priv->dont_poll)
87 cancel_delayed_work_sync(&priv->stat_work);
88 return 0;
134} 89}
135 90
136static int ts2020_init(struct dvb_frontend *fe) 91static int ts2020_init(struct dvb_frontend *fe)
137{ 92{
93 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
138 struct ts2020_priv *priv = fe->tuner_priv; 94 struct ts2020_priv *priv = fe->tuner_priv;
139 int i; 95 int i;
140 u8 u8tmp; 96 u8 u8tmp;
141 97
142 if (priv->tuner == TS2020_M88TS2020) { 98 if (priv->tuner == TS2020_M88TS2020) {
143 ts2020_writereg(fe, 0x42, 0x73); 99 regmap_write(priv->regmap, 0x42, 0x73);
144 ts2020_writereg(fe, 0x05, priv->clk_out_div); 100 regmap_write(priv->regmap, 0x05, priv->clk_out_div);
145 ts2020_writereg(fe, 0x20, 0x27); 101 regmap_write(priv->regmap, 0x20, 0x27);
146 ts2020_writereg(fe, 0x07, 0x02); 102 regmap_write(priv->regmap, 0x07, 0x02);
147 ts2020_writereg(fe, 0x11, 0xff); 103 regmap_write(priv->regmap, 0x11, 0xff);
148 ts2020_writereg(fe, 0x60, 0xf9); 104 regmap_write(priv->regmap, 0x60, 0xf9);
149 ts2020_writereg(fe, 0x08, 0x01); 105 regmap_write(priv->regmap, 0x08, 0x01);
150 ts2020_writereg(fe, 0x00, 0x41); 106 regmap_write(priv->regmap, 0x00, 0x41);
151 } else { 107 } else {
152 static const struct ts2020_reg_val reg_vals[] = { 108 static const struct ts2020_reg_val reg_vals[] = {
153 {0x7d, 0x9d}, 109 {0x7d, 0x9d},
@@ -163,8 +119,8 @@ static int ts2020_init(struct dvb_frontend *fe)
163 {0x12, 0xa0}, 119 {0x12, 0xa0},
164 }; 120 };
165 121
166 ts2020_writereg(fe, 0x00, 0x01); 122 regmap_write(priv->regmap, 0x00, 0x01);
167 ts2020_writereg(fe, 0x00, 0x03); 123 regmap_write(priv->regmap, 0x00, 0x03);
168 124
169 switch (priv->clk_out) { 125 switch (priv->clk_out) {
170 case TS2020_CLK_OUT_DISABLED: 126 case TS2020_CLK_OUT_DISABLED:
@@ -172,7 +128,7 @@ static int ts2020_init(struct dvb_frontend *fe)
172 break; 128 break;
173 case TS2020_CLK_OUT_ENABLED: 129 case TS2020_CLK_OUT_ENABLED:
174 u8tmp = 0x70; 130 u8tmp = 0x70;
175 ts2020_writereg(fe, 0x05, priv->clk_out_div); 131 regmap_write(priv->regmap, 0x05, priv->clk_out_div);
176 break; 132 break;
177 case TS2020_CLK_OUT_ENABLED_XTALOUT: 133 case TS2020_CLK_OUT_ENABLED_XTALOUT:
178 u8tmp = 0x6c; 134 u8tmp = 0x6c;
@@ -182,50 +138,61 @@ static int ts2020_init(struct dvb_frontend *fe)
182 break; 138 break;
183 } 139 }
184 140
185 ts2020_writereg(fe, 0x42, u8tmp); 141 regmap_write(priv->regmap, 0x42, u8tmp);
186 142
187 if (priv->loop_through) 143 if (priv->loop_through)
188 u8tmp = 0xec; 144 u8tmp = 0xec;
189 else 145 else
190 u8tmp = 0x6c; 146 u8tmp = 0x6c;
191 147
192 ts2020_writereg(fe, 0x62, u8tmp); 148 regmap_write(priv->regmap, 0x62, u8tmp);
193 149
194 for (i = 0; i < ARRAY_SIZE(reg_vals); i++) 150 for (i = 0; i < ARRAY_SIZE(reg_vals); i++)
195 ts2020_writereg(fe, reg_vals[i].reg, reg_vals[i].val); 151 regmap_write(priv->regmap, reg_vals[i].reg,
152 reg_vals[i].val);
196 } 153 }
197 154
155 /* Initialise v5 stats here */
156 c->strength.len = 1;
157 c->strength.stat[0].scale = FE_SCALE_DECIBEL;
158 c->strength.stat[0].uvalue = 0;
159
160 /* Start statistics polling by invoking the work function */
161 ts2020_stat_work(&priv->stat_work.work);
198 return 0; 162 return 0;
199} 163}
200 164
201static int ts2020_tuner_gate_ctrl(struct dvb_frontend *fe, u8 offset) 165static int ts2020_tuner_gate_ctrl(struct dvb_frontend *fe, u8 offset)
202{ 166{
167 struct ts2020_priv *priv = fe->tuner_priv;
203 int ret; 168 int ret;
204 ret = ts2020_writereg(fe, 0x51, 0x1f - offset); 169 ret = regmap_write(priv->regmap, 0x51, 0x1f - offset);
205 ret |= ts2020_writereg(fe, 0x51, 0x1f); 170 ret |= regmap_write(priv->regmap, 0x51, 0x1f);
206 ret |= ts2020_writereg(fe, 0x50, offset); 171 ret |= regmap_write(priv->regmap, 0x50, offset);
207 ret |= ts2020_writereg(fe, 0x50, 0x00); 172 ret |= regmap_write(priv->regmap, 0x50, 0x00);
208 msleep(20); 173 msleep(20);
209 return ret; 174 return ret;
210} 175}
211 176
212static int ts2020_set_tuner_rf(struct dvb_frontend *fe) 177static int ts2020_set_tuner_rf(struct dvb_frontend *fe)
213{ 178{
214 int reg; 179 struct ts2020_priv *dev = fe->tuner_priv;
215 180 int ret;
216 reg = ts2020_readreg(fe, 0x3d); 181 unsigned int utmp;
217 reg &= 0x7f; 182
218 if (reg < 0x16) 183 ret = regmap_read(dev->regmap, 0x3d, &utmp);
219 reg = 0xa1; 184 utmp &= 0x7f;
220 else if (reg == 0x16) 185 if (utmp < 0x16)
221 reg = 0x99; 186 utmp = 0xa1;
187 else if (utmp == 0x16)
188 utmp = 0x99;
222 else 189 else
223 reg = 0xf9; 190 utmp = 0xf9;
224 191
225 ts2020_writereg(fe, 0x60, reg); 192 regmap_write(dev->regmap, 0x60, utmp);
226 reg = ts2020_tuner_gate_ctrl(fe, 0x08); 193 ret = ts2020_tuner_gate_ctrl(fe, 0x08);
227 194
228 return reg; 195 return ret;
229} 196}
230 197
231static int ts2020_set_params(struct dvb_frontend *fe) 198static int ts2020_set_params(struct dvb_frontend *fe)
@@ -233,45 +200,62 @@ static int ts2020_set_params(struct dvb_frontend *fe)
233 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 200 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
234 struct ts2020_priv *priv = fe->tuner_priv; 201 struct ts2020_priv *priv = fe->tuner_priv;
235 int ret; 202 int ret;
236 u32 frequency = c->frequency; 203 unsigned int utmp;
237 s32 offset_khz;
238 u32 symbol_rate = (c->symbol_rate / 1000);
239 u32 f3db, gdiv28; 204 u32 f3db, gdiv28;
240 u16 value, ndiv, lpf_coeff; 205 u16 u16tmp, value, lpf_coeff;
241 u8 lpf_mxdiv, mlpf_max, mlpf_min, nlpf; 206 u8 buf[3], reg10, lpf_mxdiv, mlpf_max, mlpf_min, nlpf;
242 u8 lo = 0x01, div4 = 0x0; 207 unsigned int f_ref_khz, f_vco_khz, div_ref, div_out, pll_n;
243 208 unsigned int frequency_khz = c->frequency;
244 /* Calculate frequency divider */ 209
245 if (frequency < priv->frequency_div) { 210 /*
246 lo |= 0x10; 211 * Integer-N PLL synthesizer
247 div4 = 0x1; 212 * kHz is used for all calculations to keep calculations within 32-bit
248 ndiv = (frequency * 14 * 4) / TS2020_XTAL_FREQ; 213 */
249 } else 214 f_ref_khz = TS2020_XTAL_FREQ;
250 ndiv = (frequency * 14 * 2) / TS2020_XTAL_FREQ; 215 div_ref = DIV_ROUND_CLOSEST(f_ref_khz, 2000);
251 ndiv = ndiv + ndiv % 2; 216
252 ndiv = ndiv - 1024; 217 /* select LO output divider */
218 if (frequency_khz < priv->frequency_div) {
219 div_out = 4;
220 reg10 = 0x10;
221 } else {
222 div_out = 2;
223 reg10 = 0x00;
224 }
225
226 f_vco_khz = frequency_khz * div_out;
227 pll_n = f_vco_khz * div_ref / f_ref_khz;
228 pll_n += pll_n % 2;
229 priv->frequency_khz = pll_n * f_ref_khz / div_ref / div_out;
230
231 pr_debug("frequency=%u offset=%d f_vco_khz=%u pll_n=%u div_ref=%u div_out=%u\n",
232 priv->frequency_khz, priv->frequency_khz - c->frequency,
233 f_vco_khz, pll_n, div_ref, div_out);
253 234
254 if (priv->tuner == TS2020_M88TS2020) { 235 if (priv->tuner == TS2020_M88TS2020) {
255 lpf_coeff = 2766; 236 lpf_coeff = 2766;
256 ret = ts2020_writereg(fe, 0x10, 0x80 | lo); 237 reg10 |= 0x01;
238 ret = regmap_write(priv->regmap, 0x10, reg10);
257 } else { 239 } else {
258 lpf_coeff = 3200; 240 lpf_coeff = 3200;
259 ret = ts2020_writereg(fe, 0x10, 0x0b); 241 reg10 |= 0x0b;
260 ret |= ts2020_writereg(fe, 0x11, 0x40); 242 ret = regmap_write(priv->regmap, 0x10, reg10);
243 ret |= regmap_write(priv->regmap, 0x11, 0x40);
261 } 244 }
262 245
263 /* Set frequency divider */ 246 u16tmp = pll_n - 1024;
264 ret |= ts2020_writereg(fe, 0x01, (ndiv >> 8) & 0xf); 247 buf[0] = (u16tmp >> 8) & 0xff;
265 ret |= ts2020_writereg(fe, 0x02, ndiv & 0xff); 248 buf[1] = (u16tmp >> 0) & 0xff;
249 buf[2] = div_ref - 8;
250
251 ret |= regmap_write(priv->regmap, 0x01, buf[0]);
252 ret |= regmap_write(priv->regmap, 0x02, buf[1]);
253 ret |= regmap_write(priv->regmap, 0x03, buf[2]);
266 254
267 ret |= ts2020_writereg(fe, 0x03, 0x06);
268 ret |= ts2020_tuner_gate_ctrl(fe, 0x10); 255 ret |= ts2020_tuner_gate_ctrl(fe, 0x10);
269 if (ret < 0) 256 if (ret < 0)
270 return -ENODEV; 257 return -ENODEV;
271 258
272 /* Tuner Frequency Range */
273 ret = ts2020_writereg(fe, 0x10, lo);
274
275 ret |= ts2020_tuner_gate_ctrl(fe, 0x08); 259 ret |= ts2020_tuner_gate_ctrl(fe, 0x08);
276 260
277 /* Tuner RF */ 261 /* Tuner RF */
@@ -279,28 +263,26 @@ static int ts2020_set_params(struct dvb_frontend *fe)
279 ret |= ts2020_set_tuner_rf(fe); 263 ret |= ts2020_set_tuner_rf(fe);
280 264
281 gdiv28 = (TS2020_XTAL_FREQ / 1000 * 1694 + 500) / 1000; 265 gdiv28 = (TS2020_XTAL_FREQ / 1000 * 1694 + 500) / 1000;
282 ret |= ts2020_writereg(fe, 0x04, gdiv28 & 0xff); 266 ret |= regmap_write(priv->regmap, 0x04, gdiv28 & 0xff);
283 ret |= ts2020_tuner_gate_ctrl(fe, 0x04); 267 ret |= ts2020_tuner_gate_ctrl(fe, 0x04);
284 if (ret < 0) 268 if (ret < 0)
285 return -ENODEV; 269 return -ENODEV;
286 270
287 if (priv->tuner == TS2020_M88TS2022) { 271 if (priv->tuner == TS2020_M88TS2022) {
288 ret = ts2020_writereg(fe, 0x25, 0x00); 272 ret = regmap_write(priv->regmap, 0x25, 0x00);
289 ret |= ts2020_writereg(fe, 0x27, 0x70); 273 ret |= regmap_write(priv->regmap, 0x27, 0x70);
290 ret |= ts2020_writereg(fe, 0x41, 0x09); 274 ret |= regmap_write(priv->regmap, 0x41, 0x09);
291 ret |= ts2020_writereg(fe, 0x08, 0x0b); 275 ret |= regmap_write(priv->regmap, 0x08, 0x0b);
292 if (ret < 0) 276 if (ret < 0)
293 return -ENODEV; 277 return -ENODEV;
294 } 278 }
295 279
296 value = ts2020_readreg(fe, 0x26); 280 regmap_read(priv->regmap, 0x26, &utmp);
281 value = utmp;
297 282
298 f3db = (symbol_rate * 135) / 200 + 2000; 283 f3db = (c->bandwidth_hz / 1000 / 2) + 2000;
299 f3db += FREQ_OFFSET_LOW_SYM_RATE; 284 f3db += FREQ_OFFSET_LOW_SYM_RATE; /* FIXME: ~always too wide filter */
300 if (f3db < 7000) 285 f3db = clamp(f3db, 7000U, 40000U);
301 f3db = 7000;
302 if (f3db > 40000)
303 f3db = 40000;
304 286
305 gdiv28 = gdiv28 * 207 / (value * 2 + 151); 287 gdiv28 = gdiv28 * 207 / (value * 2 + 151);
306 mlpf_max = gdiv28 * 135 / 100; 288 mlpf_max = gdiv28 * 135 / 100;
@@ -327,19 +309,14 @@ static int ts2020_set_params(struct dvb_frontend *fe)
327 if (lpf_mxdiv > mlpf_max) 309 if (lpf_mxdiv > mlpf_max)
328 lpf_mxdiv = mlpf_max; 310 lpf_mxdiv = mlpf_max;
329 311
330 ret = ts2020_writereg(fe, 0x04, lpf_mxdiv); 312 ret = regmap_write(priv->regmap, 0x04, lpf_mxdiv);
331 ret |= ts2020_writereg(fe, 0x06, nlpf); 313 ret |= regmap_write(priv->regmap, 0x06, nlpf);
332 314
333 ret |= ts2020_tuner_gate_ctrl(fe, 0x04); 315 ret |= ts2020_tuner_gate_ctrl(fe, 0x04);
334 316
335 ret |= ts2020_tuner_gate_ctrl(fe, 0x01); 317 ret |= ts2020_tuner_gate_ctrl(fe, 0x01);
336 318
337 msleep(80); 319 msleep(80);
338 /* calculate offset assuming 96000kHz*/
339 offset_khz = (ndiv - ndiv % 2 + 1024) * TS2020_XTAL_FREQ
340 / (6 + 8) / (div4 + 1) / 2;
341
342 priv->frequency = offset_khz;
343 320
344 return (ret < 0) ? -EINVAL : 0; 321 return (ret < 0) ? -EINVAL : 0;
345} 322}
@@ -347,8 +324,8 @@ static int ts2020_set_params(struct dvb_frontend *fe)
347static int ts2020_get_frequency(struct dvb_frontend *fe, u32 *frequency) 324static int ts2020_get_frequency(struct dvb_frontend *fe, u32 *frequency)
348{ 325{
349 struct ts2020_priv *priv = fe->tuner_priv; 326 struct ts2020_priv *priv = fe->tuner_priv;
350 *frequency = priv->frequency;
351 327
328 *frequency = priv->frequency_khz;
352 return 0; 329 return 0;
353} 330}
354 331
@@ -358,28 +335,164 @@ static int ts2020_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
358 return 0; 335 return 0;
359} 336}
360 337
361/* read TS2020 signal strength */ 338/*
362static int ts2020_read_signal_strength(struct dvb_frontend *fe, 339 * Get the tuner gain.
363 u16 *signal_strength) 340 * @fe: The front end for which we're determining the gain
341 * @v_agc: The voltage of the AGC from the demodulator (0-2600mV)
342 * @_gain: Where to store the gain (in 0.001dB units)
343 *
344 * Returns 0 or a negative error code.
345 */
346static int ts2020_read_tuner_gain(struct dvb_frontend *fe, unsigned v_agc,
347 __s64 *_gain)
348{
349 struct ts2020_priv *priv = fe->tuner_priv;
350 unsigned long gain1, gain2, gain3;
351 unsigned utmp;
352 int ret;
353
354 /* Read the RF gain */
355 ret = regmap_read(priv->regmap, 0x3d, &utmp);
356 if (ret < 0)
357 return ret;
358 gain1 = utmp & 0x1f;
359
360 /* Read the baseband gain */
361 ret = regmap_read(priv->regmap, 0x21, &utmp);
362 if (ret < 0)
363 return ret;
364 gain2 = utmp & 0x1f;
365
366 switch (priv->tuner) {
367 case TS2020_M88TS2020:
368 gain1 = clamp_t(long, gain1, 0, 15);
369 gain2 = clamp_t(long, gain2, 0, 13);
370 v_agc = clamp_t(long, v_agc, 400, 1100);
371
372 *_gain = -(gain1 * 2330 +
373 gain2 * 3500 +
374 v_agc * 24 / 10 * 10 +
375 10000);
376 /* gain in range -19600 to -116850 in units of 0.001dB */
377 break;
378
379 case TS2020_M88TS2022:
380 ret = regmap_read(priv->regmap, 0x66, &utmp);
381 if (ret < 0)
382 return ret;
383 gain3 = (utmp >> 3) & 0x07;
384
385 gain1 = clamp_t(long, gain1, 0, 15);
386 gain2 = clamp_t(long, gain2, 2, 16);
387 gain3 = clamp_t(long, gain3, 0, 6);
388 v_agc = clamp_t(long, v_agc, 600, 1600);
389
390 *_gain = -(gain1 * 2650 +
391 gain2 * 3380 +
392 gain3 * 2850 +
393 v_agc * 176 / 100 * 10 -
394 30000);
395 /* gain in range -47320 to -158950 in units of 0.001dB */
396 break;
397 }
398
399 return 0;
400}
401
402/*
403 * Get the AGC information from the demodulator and use that to calculate the
404 * tuner gain.
405 */
406static int ts2020_get_tuner_gain(struct dvb_frontend *fe, __s64 *_gain)
364{ 407{
365 u16 sig_reading, sig_strength; 408 struct ts2020_priv *priv = fe->tuner_priv;
366 u8 rfgain, bbgain; 409 int v_agc = 0, ret;
410 u8 agc_pwm;
367 411
368 rfgain = ts2020_readreg(fe, 0x3d) & 0x1f; 412 /* Read the AGC PWM rate from the demodulator */
369 bbgain = ts2020_readreg(fe, 0x21) & 0x1f; 413 if (priv->get_agc_pwm) {
414 ret = priv->get_agc_pwm(fe, &agc_pwm);
415 if (ret < 0)
416 return ret;
370 417
371 if (rfgain > 15) 418 switch (priv->tuner) {
372 rfgain = 15; 419 case TS2020_M88TS2020:
373 if (bbgain > 13) 420 v_agc = (int)agc_pwm * 20 - 1166;
374 bbgain = 13; 421 break;
422 case TS2020_M88TS2022:
423 v_agc = (int)agc_pwm * 16 - 670;
424 break;
425 }
375 426
376 sig_reading = rfgain * 2 + bbgain * 3; 427 if (v_agc < 0)
428 v_agc = 0;
429 }
377 430
378 sig_strength = 40 + (64 - sig_reading) * 50 / 64 ; 431 return ts2020_read_tuner_gain(fe, v_agc, _gain);
432}
379 433
380 /* cook the value to be suitable for szap-s2 human readable output */ 434/*
381 *signal_strength = sig_strength * 1000; 435 * Gather statistics on a regular basis
436 */
437static void ts2020_stat_work(struct work_struct *work)
438{
439 struct ts2020_priv *priv = container_of(work, struct ts2020_priv,
440 stat_work.work);
441 struct i2c_client *client = priv->client;
442 struct dtv_frontend_properties *c = &priv->fe->dtv_property_cache;
443 int ret;
444
445 dev_dbg(&client->dev, "\n");
446
447 ret = ts2020_get_tuner_gain(priv->fe, &c->strength.stat[0].svalue);
448 if (ret < 0)
449 goto err;
382 450
451 c->strength.stat[0].scale = FE_SCALE_DECIBEL;
452
453 if (!priv->dont_poll)
454 schedule_delayed_work(&priv->stat_work, msecs_to_jiffies(2000));
455 return;
456err:
457 dev_dbg(&client->dev, "failed=%d\n", ret);
458}
459
460/*
461 * Read TS2020 signal strength in v3 format.
462 */
463static int ts2020_read_signal_strength(struct dvb_frontend *fe,
464 u16 *_signal_strength)
465{
466 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
467 struct ts2020_priv *priv = fe->tuner_priv;
468 unsigned strength;
469 __s64 gain;
470
471 if (priv->dont_poll)
472 ts2020_stat_work(&priv->stat_work.work);
473
474 if (c->strength.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
475 *_signal_strength = 0;
476 return 0;
477 }
478
479 gain = c->strength.stat[0].svalue;
480
481 /* Calculate the signal strength based on the total gain of the tuner */
482 if (gain < -85000)
483 /* 0%: no signal or weak signal */
484 strength = 0;
485 else if (gain < -65000)
486 /* 0% - 60%: weak signal */
487 strength = 0 + div64_s64((85000 + gain) * 3, 1000);
488 else if (gain < -45000)
489 /* 60% - 90%: normal signal */
490 strength = 60 + div64_s64((65000 + gain) * 3, 2000);
491 else
492 /* 90% - 99%: strong signal */
493 strength = 90 + div64_s64((45000 + gain), 5000);
494
495 *_signal_strength = strength * 65535 / 100;
383 return 0; 496 return 0;
384} 497}
385 498
@@ -402,53 +515,50 @@ struct dvb_frontend *ts2020_attach(struct dvb_frontend *fe,
402 const struct ts2020_config *config, 515 const struct ts2020_config *config,
403 struct i2c_adapter *i2c) 516 struct i2c_adapter *i2c)
404{ 517{
405 struct ts2020_priv *priv = NULL; 518 struct i2c_client *client;
406 u8 buf; 519 struct i2c_board_info board_info;
407 520
408 priv = kzalloc(sizeof(struct ts2020_priv), GFP_KERNEL); 521 /* This is only used by ts2020_probe() so can be on the stack */
409 if (priv == NULL) 522 struct ts2020_config pdata;
523
524 memcpy(&pdata, config, sizeof(pdata));
525 pdata.fe = fe;
526 pdata.attach_in_use = true;
527
528 memset(&board_info, 0, sizeof(board_info));
529 strlcpy(board_info.type, "ts2020", I2C_NAME_SIZE);
530 board_info.addr = config->tuner_address;
531 board_info.platform_data = &pdata;
532 client = i2c_new_device(i2c, &board_info);
533 if (!client || !client->dev.driver)
410 return NULL; 534 return NULL;
411 535
412 priv->i2c_address = config->tuner_address; 536 return fe;
413 priv->i2c = i2c; 537}
414 priv->clk_out = config->clk_out; 538EXPORT_SYMBOL(ts2020_attach);
415 priv->clk_out_div = config->clk_out_div;
416 priv->frequency_div = config->frequency_div;
417 priv->fe = fe;
418 fe->tuner_priv = priv;
419
420 if (!priv->frequency_div)
421 priv->frequency_div = 1060000;
422
423 /* Wake Up the tuner */
424 if ((0x03 & ts2020_readreg(fe, 0x00)) == 0x00) {
425 ts2020_writereg(fe, 0x00, 0x01);
426 msleep(2);
427 }
428 539
429 ts2020_writereg(fe, 0x00, 0x03); 540/*
430 msleep(2); 541 * We implement own regmap locking due to legacy DVB attach which uses frontend
431 542 * gate control callback to control I2C bus access. We can open / close gate and
432 /* Check the tuner version */ 543 * serialize whole open / I2C-operation / close sequence at the same.
433 buf = ts2020_readreg(fe, 0x00); 544 */
434 if ((buf == 0x01) || (buf == 0x41) || (buf == 0x81)) { 545static void ts2020_regmap_lock(void *__dev)
435 printk(KERN_INFO "%s: Find tuner TS2020!\n", __func__); 546{
436 priv->tuner = TS2020_M88TS2020; 547 struct ts2020_priv *dev = __dev;
437 } else if ((buf == 0x83) || (buf == 0xc3)) {
438 printk(KERN_INFO "%s: Find tuner TS2022!\n", __func__);
439 priv->tuner = TS2020_M88TS2022;
440 } else {
441 printk(KERN_ERR "%s: Read tuner reg[0] = %d\n", __func__, buf);
442 kfree(priv);
443 return NULL;
444 }
445 548
446 memcpy(&fe->ops.tuner_ops, &ts2020_tuner_ops, 549 mutex_lock(&dev->regmap_mutex);
447 sizeof(struct dvb_tuner_ops)); 550 if (dev->fe->ops.i2c_gate_ctrl)
551 dev->fe->ops.i2c_gate_ctrl(dev->fe, 1);
552}
448 553
449 return fe; 554static void ts2020_regmap_unlock(void *__dev)
555{
556 struct ts2020_priv *dev = __dev;
557
558 if (dev->fe->ops.i2c_gate_ctrl)
559 dev->fe->ops.i2c_gate_ctrl(dev->fe, 0);
560 mutex_unlock(&dev->regmap_mutex);
450} 561}
451EXPORT_SYMBOL(ts2020_attach);
452 562
453static int ts2020_probe(struct i2c_client *client, 563static int ts2020_probe(struct i2c_client *client,
454 const struct i2c_device_id *id) 564 const struct i2c_device_id *id)
@@ -467,38 +577,54 @@ static int ts2020_probe(struct i2c_client *client,
467 goto err; 577 goto err;
468 } 578 }
469 579
580 /* create regmap */
581 mutex_init(&dev->regmap_mutex);
582 dev->regmap_config.reg_bits = 8,
583 dev->regmap_config.val_bits = 8,
584 dev->regmap_config.lock = ts2020_regmap_lock,
585 dev->regmap_config.unlock = ts2020_regmap_unlock,
586 dev->regmap_config.lock_arg = dev,
587 dev->regmap = regmap_init_i2c(client, &dev->regmap_config);
588 if (IS_ERR(dev->regmap)) {
589 ret = PTR_ERR(dev->regmap);
590 goto err_kfree;
591 }
592
470 dev->i2c = client->adapter; 593 dev->i2c = client->adapter;
471 dev->i2c_address = client->addr; 594 dev->i2c_address = client->addr;
595 dev->loop_through = pdata->loop_through;
472 dev->clk_out = pdata->clk_out; 596 dev->clk_out = pdata->clk_out;
473 dev->clk_out_div = pdata->clk_out_div; 597 dev->clk_out_div = pdata->clk_out_div;
598 dev->dont_poll = pdata->dont_poll;
474 dev->frequency_div = pdata->frequency_div; 599 dev->frequency_div = pdata->frequency_div;
475 dev->fe = fe; 600 dev->fe = fe;
601 dev->get_agc_pwm = pdata->get_agc_pwm;
476 fe->tuner_priv = dev; 602 fe->tuner_priv = dev;
603 dev->client = client;
604 INIT_DELAYED_WORK(&dev->stat_work, ts2020_stat_work);
477 605
478 /* check if the tuner is there */ 606 /* check if the tuner is there */
479 ret = ts2020_readreg(fe, 0x00); 607 ret = regmap_read(dev->regmap, 0x00, &utmp);
480 if (ret < 0) 608 if (ret)
481 goto err; 609 goto err_regmap_exit;
482 utmp = ret;
483 610
484 if ((utmp & 0x03) == 0x00) { 611 if ((utmp & 0x03) == 0x00) {
485 ret = ts2020_writereg(fe, 0x00, 0x01); 612 ret = regmap_write(dev->regmap, 0x00, 0x01);
486 if (ret) 613 if (ret)
487 goto err; 614 goto err_regmap_exit;
488 615
489 usleep_range(2000, 50000); 616 usleep_range(2000, 50000);
490 } 617 }
491 618
492 ret = ts2020_writereg(fe, 0x00, 0x03); 619 ret = regmap_write(dev->regmap, 0x00, 0x03);
493 if (ret) 620 if (ret)
494 goto err; 621 goto err_regmap_exit;
495 622
496 usleep_range(2000, 50000); 623 usleep_range(2000, 50000);
497 624
498 ret = ts2020_readreg(fe, 0x00); 625 ret = regmap_read(dev->regmap, 0x00, &utmp);
499 if (ret < 0) 626 if (ret)
500 goto err; 627 goto err_regmap_exit;
501 utmp = ret;
502 628
503 dev_dbg(&client->dev, "chip_id=%02x\n", utmp); 629 dev_dbg(&client->dev, "chip_id=%02x\n", utmp);
504 630
@@ -520,7 +646,7 @@ static int ts2020_probe(struct i2c_client *client,
520 break; 646 break;
521 default: 647 default:
522 ret = -ENODEV; 648 ret = -ENODEV;
523 goto err; 649 goto err_regmap_exit;
524 } 650 }
525 651
526 if (dev->tuner == TS2020_M88TS2022) { 652 if (dev->tuner == TS2020_M88TS2022) {
@@ -530,63 +656,64 @@ static int ts2020_probe(struct i2c_client *client,
530 break; 656 break;
531 case TS2020_CLK_OUT_ENABLED: 657 case TS2020_CLK_OUT_ENABLED:
532 u8tmp = 0x70; 658 u8tmp = 0x70;
533 ret = ts2020_writereg(fe, 0x05, dev->clk_out_div); 659 ret = regmap_write(dev->regmap, 0x05, dev->clk_out_div);
534 if (ret) 660 if (ret)
535 goto err; 661 goto err_regmap_exit;
536 break; 662 break;
537 case TS2020_CLK_OUT_ENABLED_XTALOUT: 663 case TS2020_CLK_OUT_ENABLED_XTALOUT:
538 u8tmp = 0x6c; 664 u8tmp = 0x6c;
539 break; 665 break;
540 default: 666 default:
541 ret = -EINVAL; 667 ret = -EINVAL;
542 goto err; 668 goto err_regmap_exit;
543 } 669 }
544 670
545 ret = ts2020_writereg(fe, 0x42, u8tmp); 671 ret = regmap_write(dev->regmap, 0x42, u8tmp);
546 if (ret) 672 if (ret)
547 goto err; 673 goto err_regmap_exit;
548 674
549 if (dev->loop_through) 675 if (dev->loop_through)
550 u8tmp = 0xec; 676 u8tmp = 0xec;
551 else 677 else
552 u8tmp = 0x6c; 678 u8tmp = 0x6c;
553 679
554 ret = ts2020_writereg(fe, 0x62, u8tmp); 680 ret = regmap_write(dev->regmap, 0x62, u8tmp);
555 if (ret) 681 if (ret)
556 goto err; 682 goto err_regmap_exit;
557 } 683 }
558 684
559 /* sleep */ 685 /* sleep */
560 ret = ts2020_writereg(fe, 0x00, 0x00); 686 ret = regmap_write(dev->regmap, 0x00, 0x00);
561 if (ret) 687 if (ret)
562 goto err; 688 goto err_regmap_exit;
563 689
564 dev_info(&client->dev, 690 dev_info(&client->dev,
565 "Montage Technology %s successfully identified\n", chip_str); 691 "Montage Technology %s successfully identified\n", chip_str);
566 692
567 memcpy(&fe->ops.tuner_ops, &ts2020_tuner_ops, 693 memcpy(&fe->ops.tuner_ops, &ts2020_tuner_ops,
568 sizeof(struct dvb_tuner_ops)); 694 sizeof(struct dvb_tuner_ops));
569 fe->ops.tuner_ops.release = NULL; 695 if (!pdata->attach_in_use)
696 fe->ops.tuner_ops.release = NULL;
570 697
571 i2c_set_clientdata(client, dev); 698 i2c_set_clientdata(client, dev);
572 return 0; 699 return 0;
700err_regmap_exit:
701 regmap_exit(dev->regmap);
702err_kfree:
703 kfree(dev);
573err: 704err:
574 dev_dbg(&client->dev, "failed=%d\n", ret); 705 dev_dbg(&client->dev, "failed=%d\n", ret);
575 kfree(dev);
576 return ret; 706 return ret;
577} 707}
578 708
579static int ts2020_remove(struct i2c_client *client) 709static int ts2020_remove(struct i2c_client *client)
580{ 710{
581 struct ts2020_priv *dev = i2c_get_clientdata(client); 711 struct ts2020_priv *dev = i2c_get_clientdata(client);
582 struct dvb_frontend *fe = dev->fe;
583 712
584 dev_dbg(&client->dev, "\n"); 713 dev_dbg(&client->dev, "\n");
585 714
586 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); 715 regmap_exit(dev->regmap);
587 fe->tuner_priv = NULL;
588 kfree(dev); 716 kfree(dev);
589
590 return 0; 717 return 0;
591} 718}
592 719
diff --git a/drivers/media/dvb-frontends/ts2020.h b/drivers/media/dvb-frontends/ts2020.h
index 1714af94eca2..9220e5cf0d21 100644
--- a/drivers/media/dvb-frontends/ts2020.h
+++ b/drivers/media/dvb-frontends/ts2020.h
@@ -32,7 +32,7 @@ struct ts2020_config {
32 /* 32 /*
33 * RF loop-through 33 * RF loop-through
34 */ 34 */
35 u8 loop_through:1; 35 bool loop_through:1;
36 36
37 /* 37 /*
38 * clock output 38 * clock output
@@ -48,14 +48,27 @@ struct ts2020_config {
48 */ 48 */
49 u8 clk_out_div:5; 49 u8 clk_out_div:5;
50 50
51 /* Set to true to suppress stat polling */
52 bool dont_poll:1;
53
51 /* 54 /*
52 * pointer to DVB frontend 55 * pointer to DVB frontend
53 */ 56 */
54 struct dvb_frontend *fe; 57 struct dvb_frontend *fe;
58
59 /*
60 * driver private, do not set value
61 */
62 u8 attach_in_use:1;
63
64 /* Operation to be called by the ts2020 driver to get the value of the
65 * AGC PWM tuner input as theoretically output by the demodulator.
66 */
67 int (*get_agc_pwm)(struct dvb_frontend *fe, u8 *_agc_pwm);
55}; 68};
56 69
70/* Do not add new ts2020_attach() users! Use I2C bindings instead. */
57#if IS_REACHABLE(CONFIG_DVB_TS2020) 71#if IS_REACHABLE(CONFIG_DVB_TS2020)
58
59extern struct dvb_frontend *ts2020_attach( 72extern struct dvb_frontend *ts2020_attach(
60 struct dvb_frontend *fe, 73 struct dvb_frontend *fe,
61 const struct ts2020_config *config, 74 const struct ts2020_config *config,
diff --git a/drivers/media/dvb-frontends/ves1820.c b/drivers/media/dvb-frontends/ves1820.c
index bb42b563c42d..aacfdda3e005 100644
--- a/drivers/media/dvb-frontends/ves1820.c
+++ b/drivers/media/dvb-frontends/ves1820.c
@@ -90,7 +90,8 @@ static u8 ves1820_readreg(struct ves1820_state *state, u8 reg)
90 return b1[0]; 90 return b1[0];
91} 91}
92 92
93static int ves1820_setup_reg0(struct ves1820_state *state, u8 reg0, fe_spectral_inversion_t inversion) 93static int ves1820_setup_reg0(struct ves1820_state *state,
94 u8 reg0, enum fe_spectral_inversion inversion)
94{ 95{
95 reg0 |= state->reg0 & 0x62; 96 reg0 |= state->reg0 & 0x62;
96 97
@@ -237,7 +238,8 @@ static int ves1820_set_parameters(struct dvb_frontend *fe)
237 return 0; 238 return 0;
238} 239}
239 240
240static int ves1820_read_status(struct dvb_frontend* fe, fe_status_t* status) 241static int ves1820_read_status(struct dvb_frontend *fe,
242 enum fe_status *status)
241{ 243{
242 struct ves1820_state* state = fe->demodulator_priv; 244 struct ves1820_state* state = fe->demodulator_priv;
243 int sync; 245 int sync;
diff --git a/drivers/media/dvb-frontends/ves1x93.c b/drivers/media/dvb-frontends/ves1x93.c
index 9c17eacaec24..526952396422 100644
--- a/drivers/media/dvb-frontends/ves1x93.c
+++ b/drivers/media/dvb-frontends/ves1x93.c
@@ -41,7 +41,7 @@ struct ves1x93_state {
41 struct dvb_frontend frontend; 41 struct dvb_frontend frontend;
42 42
43 /* previous uncorrected block counter */ 43 /* previous uncorrected block counter */
44 fe_spectral_inversion_t inversion; 44 enum fe_spectral_inversion inversion;
45 u8 *init_1x93_tab; 45 u8 *init_1x93_tab;
46 u8 *init_1x93_wtab; 46 u8 *init_1x93_wtab;
47 u8 tab_size; 47 u8 tab_size;
@@ -130,7 +130,8 @@ static int ves1x93_clr_bit (struct ves1x93_state* state)
130 return 0; 130 return 0;
131} 131}
132 132
133static int ves1x93_set_inversion (struct ves1x93_state* state, fe_spectral_inversion_t inversion) 133static int ves1x93_set_inversion(struct ves1x93_state *state,
134 enum fe_spectral_inversion inversion)
134{ 135{
135 u8 val; 136 u8 val;
136 137
@@ -156,7 +157,7 @@ static int ves1x93_set_inversion (struct ves1x93_state* state, fe_spectral_inver
156 return ves1x93_writereg (state, 0x0c, (state->init_1x93_tab[0x0c] & 0x3f) | val); 157 return ves1x93_writereg (state, 0x0c, (state->init_1x93_tab[0x0c] & 0x3f) | val);
157} 158}
158 159
159static int ves1x93_set_fec (struct ves1x93_state* state, fe_code_rate_t fec) 160static int ves1x93_set_fec(struct ves1x93_state *state, enum fe_code_rate fec)
160{ 161{
161 if (fec == FEC_AUTO) 162 if (fec == FEC_AUTO)
162 return ves1x93_writereg (state, 0x0d, 0x08); 163 return ves1x93_writereg (state, 0x0d, 0x08);
@@ -166,7 +167,7 @@ static int ves1x93_set_fec (struct ves1x93_state* state, fe_code_rate_t fec)
166 return ves1x93_writereg (state, 0x0d, fec - FEC_1_2); 167 return ves1x93_writereg (state, 0x0d, fec - FEC_1_2);
167} 168}
168 169
169static fe_code_rate_t ves1x93_get_fec (struct ves1x93_state* state) 170static enum fe_code_rate ves1x93_get_fec(struct ves1x93_state *state)
170{ 171{
171 return FEC_1_2 + ((ves1x93_readreg (state, 0x0d) >> 4) & 0x7); 172 return FEC_1_2 + ((ves1x93_readreg (state, 0x0d) >> 4) & 0x7);
172} 173}
@@ -281,7 +282,8 @@ static int ves1x93_init (struct dvb_frontend* fe)
281 return 0; 282 return 0;
282} 283}
283 284
284static int ves1x93_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 285static int ves1x93_set_voltage(struct dvb_frontend *fe,
286 enum fe_sec_voltage voltage)
285{ 287{
286 struct ves1x93_state* state = fe->demodulator_priv; 288 struct ves1x93_state* state = fe->demodulator_priv;
287 289
@@ -297,7 +299,8 @@ static int ves1x93_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
297 } 299 }
298} 300}
299 301
300static int ves1x93_read_status(struct dvb_frontend* fe, fe_status_t* status) 302static int ves1x93_read_status(struct dvb_frontend *fe,
303 enum fe_status *status)
301{ 304{
302 struct ves1x93_state* state = fe->demodulator_priv; 305 struct ves1x93_state* state = fe->demodulator_priv;
303 306
diff --git a/drivers/media/dvb-frontends/zl10353.c b/drivers/media/dvb-frontends/zl10353.c
index 82946cd517f5..ef9764a02d4c 100644
--- a/drivers/media/dvb-frontends/zl10353.c
+++ b/drivers/media/dvb-frontends/zl10353.c
@@ -462,7 +462,7 @@ static int zl10353_get_parameters(struct dvb_frontend *fe)
462 return 0; 462 return 0;
463} 463}
464 464
465static int zl10353_read_status(struct dvb_frontend *fe, fe_status_t *status) 465static int zl10353_read_status(struct dvb_frontend *fe, enum fe_status *status)
466{ 466{
467 struct zl10353_state *state = fe->demodulator_priv; 467 struct zl10353_state *state = fe->demodulator_priv;
468 int s6, s7, s8; 468 int s6, s7, s8;
@@ -533,13 +533,13 @@ static int zl10353_read_snr(struct dvb_frontend *fe, u16 *snr)
533static int zl10353_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 533static int zl10353_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
534{ 534{
535 struct zl10353_state *state = fe->demodulator_priv; 535 struct zl10353_state *state = fe->demodulator_priv;
536 u32 ubl = 0; 536 u32 ubl = 0;
537 537
538 ubl = zl10353_read_register(state, RS_UBC_1) << 8 | 538 ubl = zl10353_read_register(state, RS_UBC_1) << 8 |
539 zl10353_read_register(state, RS_UBC_0); 539 zl10353_read_register(state, RS_UBC_0);
540 540
541 state->ucblocks += ubl; 541 state->ucblocks += ubl;
542 *ucblocks = state->ucblocks; 542 *ucblocks = state->ucblocks;
543 543
544 return 0; 544 return 0;
545} 545}
diff --git a/drivers/media/firewire/firedtv-fe.c b/drivers/media/firewire/firedtv-fe.c
index 6fe9793b98b3..17acda6bcb6e 100644
--- a/drivers/media/firewire/firedtv-fe.c
+++ b/drivers/media/firewire/firedtv-fe.c
@@ -61,12 +61,12 @@ static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe,
61} 61}
62 62
63static int fdtv_diseqc_send_burst(struct dvb_frontend *fe, 63static int fdtv_diseqc_send_burst(struct dvb_frontend *fe,
64 fe_sec_mini_cmd_t minicmd) 64 enum fe_sec_mini_cmd minicmd)
65{ 65{
66 return 0; 66 return 0;
67} 67}
68 68
69static int fdtv_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 69static int fdtv_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
70{ 70{
71 struct firedtv *fdtv = fe->sec_priv; 71 struct firedtv *fdtv = fe->sec_priv;
72 72
@@ -75,7 +75,7 @@ static int fdtv_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
75} 75}
76 76
77static int fdtv_set_voltage(struct dvb_frontend *fe, 77static int fdtv_set_voltage(struct dvb_frontend *fe,
78 fe_sec_voltage_t voltage) 78 enum fe_sec_voltage voltage)
79{ 79{
80 struct firedtv *fdtv = fe->sec_priv; 80 struct firedtv *fdtv = fe->sec_priv;
81 81
@@ -83,7 +83,7 @@ static int fdtv_set_voltage(struct dvb_frontend *fe,
83 return 0; 83 return 0;
84} 84}
85 85
86static int fdtv_read_status(struct dvb_frontend *fe, fe_status_t *status) 86static int fdtv_read_status(struct dvb_frontend *fe, enum fe_status *status)
87{ 87{
88 struct firedtv *fdtv = fe->sec_priv; 88 struct firedtv *fdtv = fe->sec_priv;
89 struct firedtv_tuner_status stat; 89 struct firedtv_tuner_status stat;
diff --git a/drivers/media/firewire/firedtv.h b/drivers/media/firewire/firedtv.h
index 346a85be6de2..345d1eda8c05 100644
--- a/drivers/media/firewire/firedtv.h
+++ b/drivers/media/firewire/firedtv.h
@@ -99,8 +99,8 @@ struct firedtv {
99 s8 isochannel; 99 s8 isochannel;
100 struct fdtv_ir_context *ir_context; 100 struct fdtv_ir_context *ir_context;
101 101
102 fe_sec_voltage_t voltage; 102 enum fe_sec_voltage voltage;
103 fe_sec_tone_mode_t tone; 103 enum fe_sec_tone_mode tone;
104 104
105 struct mutex demux_mutex; 105 struct mutex demux_mutex;
106 unsigned long channel_active; 106 unsigned long channel_active;
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 6f30ea76151a..71ee8f586430 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -196,7 +196,8 @@ config VIDEO_ADV7183
196 196
197config VIDEO_ADV7604 197config VIDEO_ADV7604
198 tristate "Analog Devices ADV7604 decoder" 198 tristate "Analog Devices ADV7604 decoder"
199 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API 199 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && GPIOLIB
200 select HDMI
200 ---help--- 201 ---help---
201 Support for the Analog Devices ADV7604 video decoder. 202 Support for the Analog Devices ADV7604 video decoder.
202 203
@@ -424,6 +425,7 @@ config VIDEO_ADV7393
424config VIDEO_ADV7511 425config VIDEO_ADV7511
425 tristate "Analog Devices ADV7511 encoder" 426 tristate "Analog Devices ADV7511 encoder"
426 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API 427 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
428 select HDMI
427 ---help--- 429 ---help---
428 Support for the Analog Devices ADV7511 video encoder. 430 Support for the Analog Devices ADV7511 video encoder.
429 431
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
index 873fe1949e98..c70ababce954 100644
--- a/drivers/media/i2c/adp1653.c
+++ b/drivers/media/i2c/adp1653.c
@@ -8,6 +8,7 @@
8 * Contributors: 8 * Contributors:
9 * Sakari Ailus <sakari.ailus@iki.fi> 9 * Sakari Ailus <sakari.ailus@iki.fi>
10 * Tuukka Toivonen <tuukkat76@gmail.com> 10 * Tuukka Toivonen <tuukkat76@gmail.com>
11 * Pavel Machek <pavel@ucw.cz>
11 * 12 *
12 * This program is free software; you can redistribute it and/or 13 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License 14 * modify it under the terms of the GNU General Public License
@@ -34,6 +35,8 @@
34#include <linux/module.h> 35#include <linux/module.h>
35#include <linux/i2c.h> 36#include <linux/i2c.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/of.h>
39#include <linux/gpio/consumer.h>
37#include <media/adp1653.h> 40#include <media/adp1653.h>
38#include <media/v4l2-device.h> 41#include <media/v4l2-device.h>
39 42
@@ -308,16 +311,28 @@ __adp1653_set_power(struct adp1653_flash *flash, int on)
308{ 311{
309 int ret; 312 int ret;
310 313
311 ret = flash->platform_data->power(&flash->subdev, on); 314 if (flash->platform_data->power) {
312 if (ret < 0) 315 ret = flash->platform_data->power(&flash->subdev, on);
313 return ret; 316 if (ret < 0)
317 return ret;
318 } else {
319 gpiod_set_value(flash->platform_data->enable_gpio, on);
320 if (on)
321 /* Some delay is apparently required. */
322 udelay(20);
323 }
314 324
315 if (!on) 325 if (!on)
316 return 0; 326 return 0;
317 327
318 ret = adp1653_init_device(flash); 328 ret = adp1653_init_device(flash);
319 if (ret < 0) 329 if (ret >= 0)
330 return ret;
331
332 if (flash->platform_data->power)
320 flash->platform_data->power(&flash->subdev, 0); 333 flash->platform_data->power(&flash->subdev, 0);
334 else
335 gpiod_set_value(flash->platform_data->enable_gpio, 0);
321 336
322 return ret; 337 return ret;
323} 338}
@@ -407,21 +422,85 @@ static int adp1653_resume(struct device *dev)
407 422
408#endif /* CONFIG_PM */ 423#endif /* CONFIG_PM */
409 424
425static int adp1653_of_init(struct i2c_client *client,
426 struct adp1653_flash *flash,
427 struct device_node *node)
428{
429 struct adp1653_platform_data *pd;
430 struct device_node *child;
431
432 pd = devm_kzalloc(&client->dev, sizeof(*pd), GFP_KERNEL);
433 if (!pd)
434 return -ENOMEM;
435 flash->platform_data = pd;
436
437 child = of_get_child_by_name(node, "flash");
438 if (!child)
439 return -EINVAL;
440
441 if (of_property_read_u32(child, "flash-timeout-us",
442 &pd->max_flash_timeout))
443 goto err;
444
445 if (of_property_read_u32(child, "flash-max-microamp",
446 &pd->max_flash_intensity))
447 goto err;
448
449 pd->max_flash_intensity /= 1000;
450
451 if (of_property_read_u32(child, "led-max-microamp",
452 &pd->max_torch_intensity))
453 goto err;
454
455 pd->max_torch_intensity /= 1000;
456 of_node_put(child);
457
458 child = of_get_child_by_name(node, "indicator");
459 if (!child)
460 return -EINVAL;
461
462 if (of_property_read_u32(child, "led-max-microamp",
463 &pd->max_indicator_intensity))
464 goto err;
465
466 of_node_put(child);
467
468 pd->enable_gpio = devm_gpiod_get(&client->dev, "enable");
469 if (!pd->enable_gpio) {
470 dev_err(&client->dev, "Error getting GPIO\n");
471 return -EINVAL;
472 }
473
474 return 0;
475err:
476 dev_err(&client->dev, "Required property not found\n");
477 of_node_put(child);
478 return -EINVAL;
479}
480
481
410static int adp1653_probe(struct i2c_client *client, 482static int adp1653_probe(struct i2c_client *client,
411 const struct i2c_device_id *devid) 483 const struct i2c_device_id *devid)
412{ 484{
413 struct adp1653_flash *flash; 485 struct adp1653_flash *flash;
414 int ret; 486 int ret;
415 487
416 /* we couldn't work without platform data */
417 if (client->dev.platform_data == NULL)
418 return -ENODEV;
419
420 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); 488 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
421 if (flash == NULL) 489 if (flash == NULL)
422 return -ENOMEM; 490 return -ENOMEM;
423 491
424 flash->platform_data = client->dev.platform_data; 492 if (client->dev.of_node) {
493 ret = adp1653_of_init(client, flash, client->dev.of_node);
494 if (ret)
495 return ret;
496 } else {
497 if (!client->dev.platform_data) {
498 dev_err(&client->dev,
499 "Neither DT not platform data provided\n");
500 return EINVAL;
501 }
502 flash->platform_data = client->dev.platform_data;
503 }
425 504
426 mutex_init(&flash->power_lock); 505 mutex_init(&flash->power_lock);
427 506
@@ -442,6 +521,7 @@ static int adp1653_probe(struct i2c_client *client,
442 return 0; 521 return 0;
443 522
444free_and_quit: 523free_and_quit:
524 dev_err(&client->dev, "adp1653: failed to register device\n");
445 v4l2_ctrl_handler_free(&flash->ctrls); 525 v4l2_ctrl_handler_free(&flash->ctrls);
446 return ret; 526 return ret;
447} 527}
@@ -464,7 +544,7 @@ static const struct i2c_device_id adp1653_id_table[] = {
464}; 544};
465MODULE_DEVICE_TABLE(i2c, adp1653_id_table); 545MODULE_DEVICE_TABLE(i2c, adp1653_id_table);
466 546
467static struct dev_pm_ops adp1653_pm_ops = { 547static const struct dev_pm_ops adp1653_pm_ops = {
468 .suspend = adp1653_suspend, 548 .suspend = adp1653_suspend,
469 .resume = adp1653_resume, 549 .resume = adp1653_resume,
470}; 550};
diff --git a/drivers/media/i2c/adv7170.c b/drivers/media/i2c/adv7170.c
index 40a1a95c7ce9..f0d3f5a2da46 100644
--- a/drivers/media/i2c/adv7170.c
+++ b/drivers/media/i2c/adv7170.c
@@ -262,21 +262,27 @@ static int adv7170_s_routing(struct v4l2_subdev *sd,
262 return 0; 262 return 0;
263} 263}
264 264
265static int adv7170_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 265static int adv7170_enum_mbus_code(struct v4l2_subdev *sd,
266 u32 *code) 266 struct v4l2_subdev_pad_config *cfg,
267 struct v4l2_subdev_mbus_code_enum *code)
267{ 268{
268 if (index >= ARRAY_SIZE(adv7170_codes)) 269 if (code->pad || code->index >= ARRAY_SIZE(adv7170_codes))
269 return -EINVAL; 270 return -EINVAL;
270 271
271 *code = adv7170_codes[index]; 272 code->code = adv7170_codes[code->index];
272 return 0; 273 return 0;
273} 274}
274 275
275static int adv7170_g_fmt(struct v4l2_subdev *sd, 276static int adv7170_get_fmt(struct v4l2_subdev *sd,
276 struct v4l2_mbus_framefmt *mf) 277 struct v4l2_subdev_pad_config *cfg,
278 struct v4l2_subdev_format *format)
277{ 279{
280 struct v4l2_mbus_framefmt *mf = &format->format;
278 u8 val = adv7170_read(sd, 0x7); 281 u8 val = adv7170_read(sd, 0x7);
279 282
283 if (format->pad)
284 return -EINVAL;
285
280 if ((val & 0x40) == (1 << 6)) 286 if ((val & 0x40) == (1 << 6))
281 mf->code = MEDIA_BUS_FMT_UYVY8_1X16; 287 mf->code = MEDIA_BUS_FMT_UYVY8_1X16;
282 else 288 else
@@ -290,11 +296,16 @@ static int adv7170_g_fmt(struct v4l2_subdev *sd,
290 return 0; 296 return 0;
291} 297}
292 298
293static int adv7170_s_fmt(struct v4l2_subdev *sd, 299static int adv7170_set_fmt(struct v4l2_subdev *sd,
294 struct v4l2_mbus_framefmt *mf) 300 struct v4l2_subdev_pad_config *cfg,
301 struct v4l2_subdev_format *format)
295{ 302{
303 struct v4l2_mbus_framefmt *mf = &format->format;
296 u8 val = adv7170_read(sd, 0x7); 304 u8 val = adv7170_read(sd, 0x7);
297 int ret; 305 int ret = 0;
306
307 if (format->pad)
308 return -EINVAL;
298 309
299 switch (mf->code) { 310 switch (mf->code) {
300 case MEDIA_BUS_FMT_UYVY8_2X8: 311 case MEDIA_BUS_FMT_UYVY8_2X8:
@@ -311,7 +322,8 @@ static int adv7170_s_fmt(struct v4l2_subdev *sd,
311 return -EINVAL; 322 return -EINVAL;
312 } 323 }
313 324
314 ret = adv7170_write(sd, 0x7, val); 325 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
326 ret = adv7170_write(sd, 0x7, val);
315 327
316 return ret; 328 return ret;
317} 329}
@@ -321,13 +333,17 @@ static int adv7170_s_fmt(struct v4l2_subdev *sd,
321static const struct v4l2_subdev_video_ops adv7170_video_ops = { 333static const struct v4l2_subdev_video_ops adv7170_video_ops = {
322 .s_std_output = adv7170_s_std_output, 334 .s_std_output = adv7170_s_std_output,
323 .s_routing = adv7170_s_routing, 335 .s_routing = adv7170_s_routing,
324 .s_mbus_fmt = adv7170_s_fmt, 336};
325 .g_mbus_fmt = adv7170_g_fmt, 337
326 .enum_mbus_fmt = adv7170_enum_fmt, 338static const struct v4l2_subdev_pad_ops adv7170_pad_ops = {
339 .enum_mbus_code = adv7170_enum_mbus_code,
340 .get_fmt = adv7170_get_fmt,
341 .set_fmt = adv7170_set_fmt,
327}; 342};
328 343
329static const struct v4l2_subdev_ops adv7170_ops = { 344static const struct v4l2_subdev_ops adv7170_ops = {
330 .video = &adv7170_video_ops, 345 .video = &adv7170_video_ops,
346 .pad = &adv7170_pad_ops,
331}; 347};
332 348
333/* ----------------------------------------------------------------------- */ 349/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/i2c/adv7175.c b/drivers/media/i2c/adv7175.c
index d220af579a64..321834ba8f57 100644
--- a/drivers/media/i2c/adv7175.c
+++ b/drivers/media/i2c/adv7175.c
@@ -300,21 +300,27 @@ static int adv7175_s_routing(struct v4l2_subdev *sd,
300 return 0; 300 return 0;
301} 301}
302 302
303static int adv7175_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 303static int adv7175_enum_mbus_code(struct v4l2_subdev *sd,
304 u32 *code) 304 struct v4l2_subdev_pad_config *cfg,
305 struct v4l2_subdev_mbus_code_enum *code)
305{ 306{
306 if (index >= ARRAY_SIZE(adv7175_codes)) 307 if (code->pad || code->index >= ARRAY_SIZE(adv7175_codes))
307 return -EINVAL; 308 return -EINVAL;
308 309
309 *code = adv7175_codes[index]; 310 code->code = adv7175_codes[code->index];
310 return 0; 311 return 0;
311} 312}
312 313
313static int adv7175_g_fmt(struct v4l2_subdev *sd, 314static int adv7175_get_fmt(struct v4l2_subdev *sd,
314 struct v4l2_mbus_framefmt *mf) 315 struct v4l2_subdev_pad_config *cfg,
316 struct v4l2_subdev_format *format)
315{ 317{
318 struct v4l2_mbus_framefmt *mf = &format->format;
316 u8 val = adv7175_read(sd, 0x7); 319 u8 val = adv7175_read(sd, 0x7);
317 320
321 if (format->pad)
322 return -EINVAL;
323
318 if ((val & 0x40) == (1 << 6)) 324 if ((val & 0x40) == (1 << 6))
319 mf->code = MEDIA_BUS_FMT_UYVY8_1X16; 325 mf->code = MEDIA_BUS_FMT_UYVY8_1X16;
320 else 326 else
@@ -328,11 +334,16 @@ static int adv7175_g_fmt(struct v4l2_subdev *sd,
328 return 0; 334 return 0;
329} 335}
330 336
331static int adv7175_s_fmt(struct v4l2_subdev *sd, 337static int adv7175_set_fmt(struct v4l2_subdev *sd,
332 struct v4l2_mbus_framefmt *mf) 338 struct v4l2_subdev_pad_config *cfg,
339 struct v4l2_subdev_format *format)
333{ 340{
341 struct v4l2_mbus_framefmt *mf = &format->format;
334 u8 val = adv7175_read(sd, 0x7); 342 u8 val = adv7175_read(sd, 0x7);
335 int ret; 343 int ret = 0;
344
345 if (format->pad)
346 return -EINVAL;
336 347
337 switch (mf->code) { 348 switch (mf->code) {
338 case MEDIA_BUS_FMT_UYVY8_2X8: 349 case MEDIA_BUS_FMT_UYVY8_2X8:
@@ -349,7 +360,8 @@ static int adv7175_s_fmt(struct v4l2_subdev *sd,
349 return -EINVAL; 360 return -EINVAL;
350 } 361 }
351 362
352 ret = adv7175_write(sd, 0x7, val); 363 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
364 ret = adv7175_write(sd, 0x7, val);
353 365
354 return ret; 366 return ret;
355} 367}
@@ -374,14 +386,18 @@ static const struct v4l2_subdev_core_ops adv7175_core_ops = {
374static const struct v4l2_subdev_video_ops adv7175_video_ops = { 386static const struct v4l2_subdev_video_ops adv7175_video_ops = {
375 .s_std_output = adv7175_s_std_output, 387 .s_std_output = adv7175_s_std_output,
376 .s_routing = adv7175_s_routing, 388 .s_routing = adv7175_s_routing,
377 .s_mbus_fmt = adv7175_s_fmt, 389};
378 .g_mbus_fmt = adv7175_g_fmt, 390
379 .enum_mbus_fmt = adv7175_enum_fmt, 391static const struct v4l2_subdev_pad_ops adv7175_pad_ops = {
392 .enum_mbus_code = adv7175_enum_mbus_code,
393 .get_fmt = adv7175_get_fmt,
394 .set_fmt = adv7175_set_fmt,
380}; 395};
381 396
382static const struct v4l2_subdev_ops adv7175_ops = { 397static const struct v4l2_subdev_ops adv7175_ops = {
383 .core = &adv7175_core_ops, 398 .core = &adv7175_core_ops,
384 .video = &adv7175_video_ops, 399 .video = &adv7175_video_ops,
400 .pad = &adv7175_pad_ops,
385}; 401};
386 402
387/* ----------------------------------------------------------------------- */ 403/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/i2c/adv7183.c b/drivers/media/i2c/adv7183.c
index 28940cc3a766..e2dd1617662f 100644
--- a/drivers/media/i2c/adv7183.c
+++ b/drivers/media/i2c/adv7183.c
@@ -420,20 +420,26 @@ static int adv7183_g_input_status(struct v4l2_subdev *sd, u32 *status)
420 return 0; 420 return 0;
421} 421}
422 422
423static int adv7183_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index, 423static int adv7183_enum_mbus_code(struct v4l2_subdev *sd,
424 u32 *code) 424 struct v4l2_subdev_pad_config *cfg,
425 struct v4l2_subdev_mbus_code_enum *code)
425{ 426{
426 if (index > 0) 427 if (code->pad || code->index > 0)
427 return -EINVAL; 428 return -EINVAL;
428 429
429 *code = MEDIA_BUS_FMT_UYVY8_2X8; 430 code->code = MEDIA_BUS_FMT_UYVY8_2X8;
430 return 0; 431 return 0;
431} 432}
432 433
433static int adv7183_try_mbus_fmt(struct v4l2_subdev *sd, 434static int adv7183_set_fmt(struct v4l2_subdev *sd,
434 struct v4l2_mbus_framefmt *fmt) 435 struct v4l2_subdev_pad_config *cfg,
436 struct v4l2_subdev_format *format)
435{ 437{
436 struct adv7183 *decoder = to_adv7183(sd); 438 struct adv7183 *decoder = to_adv7183(sd);
439 struct v4l2_mbus_framefmt *fmt = &format->format;
440
441 if (format->pad)
442 return -EINVAL;
437 443
438 fmt->code = MEDIA_BUS_FMT_UYVY8_2X8; 444 fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
439 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 445 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -446,25 +452,23 @@ static int adv7183_try_mbus_fmt(struct v4l2_subdev *sd,
446 fmt->width = 720; 452 fmt->width = 720;
447 fmt->height = 576; 453 fmt->height = 576;
448 } 454 }
455 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
456 decoder->fmt = *fmt;
457 else
458 cfg->try_fmt = *fmt;
449 return 0; 459 return 0;
450} 460}
451 461
452static int adv7183_s_mbus_fmt(struct v4l2_subdev *sd, 462static int adv7183_get_fmt(struct v4l2_subdev *sd,
453 struct v4l2_mbus_framefmt *fmt) 463 struct v4l2_subdev_pad_config *cfg,
464 struct v4l2_subdev_format *format)
454{ 465{
455 struct adv7183 *decoder = to_adv7183(sd); 466 struct adv7183 *decoder = to_adv7183(sd);
456 467
457 adv7183_try_mbus_fmt(sd, fmt); 468 if (format->pad)
458 decoder->fmt = *fmt; 469 return -EINVAL;
459 return 0;
460}
461
462static int adv7183_g_mbus_fmt(struct v4l2_subdev *sd,
463 struct v4l2_mbus_framefmt *fmt)
464{
465 struct adv7183 *decoder = to_adv7183(sd);
466 470
467 *fmt = decoder->fmt; 471 format->format = decoder->fmt;
468 return 0; 472 return 0;
469} 473}
470 474
@@ -514,16 +518,19 @@ static const struct v4l2_subdev_video_ops adv7183_video_ops = {
514 .s_routing = adv7183_s_routing, 518 .s_routing = adv7183_s_routing,
515 .querystd = adv7183_querystd, 519 .querystd = adv7183_querystd,
516 .g_input_status = adv7183_g_input_status, 520 .g_input_status = adv7183_g_input_status,
517 .enum_mbus_fmt = adv7183_enum_mbus_fmt,
518 .try_mbus_fmt = adv7183_try_mbus_fmt,
519 .s_mbus_fmt = adv7183_s_mbus_fmt,
520 .g_mbus_fmt = adv7183_g_mbus_fmt,
521 .s_stream = adv7183_s_stream, 521 .s_stream = adv7183_s_stream,
522}; 522};
523 523
524static const struct v4l2_subdev_pad_ops adv7183_pad_ops = {
525 .enum_mbus_code = adv7183_enum_mbus_code,
526 .get_fmt = adv7183_get_fmt,
527 .set_fmt = adv7183_set_fmt,
528};
529
524static const struct v4l2_subdev_ops adv7183_ops = { 530static const struct v4l2_subdev_ops adv7183_ops = {
525 .core = &adv7183_core_ops, 531 .core = &adv7183_core_ops,
526 .video = &adv7183_video_ops, 532 .video = &adv7183_video_ops,
533 .pad = &adv7183_pad_ops,
527}; 534};
528 535
529static int adv7183_probe(struct i2c_client *client, 536static int adv7183_probe(struct i2c_client *client,
@@ -533,7 +540,9 @@ static int adv7183_probe(struct i2c_client *client,
533 struct v4l2_subdev *sd; 540 struct v4l2_subdev *sd;
534 struct v4l2_ctrl_handler *hdl; 541 struct v4l2_ctrl_handler *hdl;
535 int ret; 542 int ret;
536 struct v4l2_mbus_framefmt fmt; 543 struct v4l2_subdev_format fmt = {
544 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
545 };
537 const unsigned *pin_array; 546 const unsigned *pin_array;
538 547
539 /* Check if the adapter supports the needed features */ 548 /* Check if the adapter supports the needed features */
@@ -603,9 +612,9 @@ static int adv7183_probe(struct i2c_client *client,
603 612
604 adv7183_writeregs(sd, adv7183_init_regs, ARRAY_SIZE(adv7183_init_regs)); 613 adv7183_writeregs(sd, adv7183_init_regs, ARRAY_SIZE(adv7183_init_regs));
605 adv7183_s_std(sd, decoder->std); 614 adv7183_s_std(sd, decoder->std);
606 fmt.width = 720; 615 fmt.format.width = 720;
607 fmt.height = 576; 616 fmt.format.height = 576;
608 adv7183_s_mbus_fmt(sd, &fmt); 617 adv7183_set_fmt(sd, NULL, &fmt);
609 618
610 /* initialize the hardware to the default control values */ 619 /* initialize the hardware to the default control values */
611 ret = v4l2_ctrl_handler_setup(hdl); 620 ret = v4l2_ctrl_handler_setup(hdl);
diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index 12d93203d405..95bcd4026451 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -77,7 +77,7 @@ struct adv7511_state_edid {
77 u32 blocks; 77 u32 blocks;
78 /* Number of segments read */ 78 /* Number of segments read */
79 u32 segments; 79 u32 segments;
80 uint8_t data[EDID_MAX_SEGM * 256]; 80 u8 data[EDID_MAX_SEGM * 256];
81 /* Number of EDID read retries left */ 81 /* Number of EDID read retries left */
82 unsigned read_retries; 82 unsigned read_retries;
83 bool complete; 83 bool complete;
@@ -89,8 +89,9 @@ struct adv7511_state {
89 struct media_pad pad; 89 struct media_pad pad;
90 struct v4l2_ctrl_handler hdl; 90 struct v4l2_ctrl_handler hdl;
91 int chip_revision; 91 int chip_revision;
92 uint8_t i2c_edid_addr; 92 u8 i2c_edid_addr;
93 uint8_t i2c_cec_addr; 93 u8 i2c_cec_addr;
94 u8 i2c_pktmem_addr;
94 /* Is the adv7511 powered on? */ 95 /* Is the adv7511 powered on? */
95 bool power_on; 96 bool power_on;
96 /* Did we receive hotplug and rx-sense signals? */ 97 /* Did we receive hotplug and rx-sense signals? */
@@ -101,6 +102,7 @@ struct adv7511_state {
101 u32 colorspace; 102 u32 colorspace;
102 u32 ycbcr_enc; 103 u32 ycbcr_enc;
103 u32 quantization; 104 u32 quantization;
105 u32 xfer_func;
104 /* controls */ 106 /* controls */
105 struct v4l2_ctrl *hdmi_mode_ctrl; 107 struct v4l2_ctrl *hdmi_mode_ctrl;
106 struct v4l2_ctrl *hotplug_ctrl; 108 struct v4l2_ctrl *hotplug_ctrl;
@@ -108,6 +110,7 @@ struct adv7511_state {
108 struct v4l2_ctrl *have_edid0_ctrl; 110 struct v4l2_ctrl *have_edid0_ctrl;
109 struct v4l2_ctrl *rgb_quantization_range_ctrl; 111 struct v4l2_ctrl *rgb_quantization_range_ctrl;
110 struct i2c_client *i2c_edid; 112 struct i2c_client *i2c_edid;
113 struct i2c_client *i2c_pktmem;
111 struct adv7511_state_edid edid; 114 struct adv7511_state_edid edid;
112 /* Running counter of the number of detected EDIDs (for debugging) */ 115 /* Running counter of the number of detected EDIDs (for debugging) */
113 unsigned edid_detect_counter; 116 unsigned edid_detect_counter;
@@ -200,7 +203,7 @@ static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
200 203
201/* To set specific bits in the register, a clear-mask is given (to be AND-ed), 204/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
202 and then the value-mask (to be OR-ed). */ 205 and then the value-mask (to be OR-ed). */
203static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, uint8_t clr_mask, uint8_t val_mask) 206static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
204{ 207{
205 adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask); 208 adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask);
206} 209}
@@ -222,7 +225,7 @@ static int adv_smbus_read_i2c_block_data(struct i2c_client *client,
222 return ret; 225 return ret;
223} 226}
224 227
225static inline void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf) 228static inline void adv7511_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf)
226{ 229{
227 struct adv7511_state *state = get_adv7511_state(sd); 230 struct adv7511_state *state = get_adv7511_state(sd);
228 int i; 231 int i;
@@ -237,6 +240,35 @@ static inline void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t
237 v4l2_err(sd, "%s: i2c read error\n", __func__); 240 v4l2_err(sd, "%s: i2c read error\n", __func__);
238} 241}
239 242
243static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
244{
245 struct adv7511_state *state = get_adv7511_state(sd);
246
247 return adv_smbus_read_byte_data(state->i2c_pktmem, reg);
248}
249
250static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
251{
252 struct adv7511_state *state = get_adv7511_state(sd);
253 int ret;
254 int i;
255
256 for (i = 0; i < 3; i++) {
257 ret = i2c_smbus_write_byte_data(state->i2c_pktmem, reg, val);
258 if (ret == 0)
259 return 0;
260 }
261 v4l2_err(sd, "%s: i2c write error\n", __func__);
262 return ret;
263}
264
265/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
266 and then the value-mask (to be OR-ed). */
267static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
268{
269 adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask);
270}
271
240static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd) 272static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd)
241{ 273{
242 return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT; 274 return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT;
@@ -247,7 +279,7 @@ static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd)
247 return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT; 279 return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT;
248} 280}
249 281
250static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, uint8_t mode) 282static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode)
251{ 283{
252 adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5); 284 adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5);
253} 285}
@@ -291,7 +323,7 @@ static void adv7511_csc_coeff(struct v4l2_subdev *sd,
291static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable) 323static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable)
292{ 324{
293 if (enable) { 325 if (enable) {
294 uint8_t csc_mode = 0; 326 u8 csc_mode = 0;
295 adv7511_csc_conversion_mode(sd, csc_mode); 327 adv7511_csc_conversion_mode(sd, csc_mode);
296 adv7511_csc_coeff(sd, 328 adv7511_csc_coeff(sd,
297 4096-564, 0, 0, 256, 329 4096-564, 0, 0, 256,
@@ -414,6 +446,80 @@ static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regi
414} 446}
415#endif 447#endif
416 448
449struct adv7511_cfg_read_infoframe {
450 const char *desc;
451 u8 present_reg;
452 u8 present_mask;
453 u8 header[3];
454 u16 payload_addr;
455};
456
457static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size)
458{
459 u8 csum = 0;
460 size_t i;
461
462 /* compute checksum */
463 for (i = 0; i < size; i++)
464 csum += ptr[i];
465
466 return 256 - csum;
467}
468
469static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri)
470{
471 struct i2c_client *client = v4l2_get_subdevdata(sd);
472 struct device *dev = &client->dev;
473 union hdmi_infoframe frame;
474 u8 buffer[32];
475 u8 len;
476 int i;
477
478 if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) {
479 v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc);
480 return;
481 }
482
483 memcpy(buffer, cri->header, sizeof(cri->header));
484
485 len = buffer[2];
486
487 if (len + 4 > sizeof(buffer)) {
488 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len);
489 return;
490 }
491
492 if (cri->payload_addr >= 0x100) {
493 for (i = 0; i < len; i++)
494 buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100);
495 } else {
496 for (i = 0; i < len; i++)
497 buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i);
498 }
499 buffer[3] = 0;
500 buffer[3] = hdmi_infoframe_checksum(buffer, len + 4);
501
502 if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
503 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
504 return;
505 }
506
507 hdmi_infoframe_log(KERN_INFO, dev, &frame);
508}
509
510static void adv7511_log_infoframes(struct v4l2_subdev *sd)
511{
512 static const struct adv7511_cfg_read_infoframe cri[] = {
513 { "AVI", 0x44, 0x10, { 0x82, 2, 13 }, 0x55 },
514 { "Audio", 0x44, 0x08, { 0x84, 1, 10 }, 0x73 },
515 { "SDP", 0x40, 0x40, { 0x83, 1, 25 }, 0x103 },
516 };
517 int i;
518
519 for (i = 0; i < ARRAY_SIZE(cri); i++)
520 log_infoframe(sd, &cri[i]);
521}
522
417static int adv7511_log_status(struct v4l2_subdev *sd) 523static int adv7511_log_status(struct v4l2_subdev *sd)
418{ 524{
419 struct adv7511_state *state = get_adv7511_state(sd); 525 struct adv7511_state *state = get_adv7511_state(sd);
@@ -479,6 +585,7 @@ static int adv7511_log_status(struct v4l2_subdev *sd)
479 manual_cts ? "manual" : "automatic", N, CTS); 585 manual_cts ? "manual" : "automatic", N, CTS);
480 v4l2_info(sd, "VIC: detected %d, sent %d\n", 586 v4l2_info(sd, "VIC: detected %d, sent %d\n",
481 vic_detect, vic_sent); 587 vic_detect, vic_sent);
588 adv7511_log_infoframes(sd);
482 } 589 }
483 if (state->dv_timings.type == V4L2_DV_BT_656_1120) 590 if (state->dv_timings.type == V4L2_DV_BT_656_1120)
484 v4l2_print_dv_timings(sd->name, "timings: ", 591 v4l2_print_dv_timings(sd->name, "timings: ",
@@ -487,6 +594,7 @@ static int adv7511_log_status(struct v4l2_subdev *sd)
487 v4l2_info(sd, "no timings set\n"); 594 v4l2_info(sd, "no timings set\n");
488 v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr); 595 v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr);
489 v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr); 596 v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr);
597 v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr);
490 return 0; 598 return 0;
491} 599}
492 600
@@ -536,6 +644,7 @@ static int adv7511_s_power(struct v4l2_subdev *sd, int on)
536 adv7511_wr(sd, 0xf9, 0x00); 644 adv7511_wr(sd, 0xf9, 0x00);
537 645
538 adv7511_wr(sd, 0x43, state->i2c_edid_addr); 646 adv7511_wr(sd, 0x43, state->i2c_edid_addr);
647 adv7511_wr(sd, 0x45, state->i2c_pktmem_addr);
539 648
540 /* Set number of attempts to read the EDID */ 649 /* Set number of attempts to read the EDID */
541 adv7511_wr(sd, 0xc9, 0xf); 650 adv7511_wr(sd, 0xc9, 0xf);
@@ -545,8 +654,8 @@ static int adv7511_s_power(struct v4l2_subdev *sd, int on)
545/* Enable interrupts */ 654/* Enable interrupts */
546static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable) 655static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable)
547{ 656{
548 uint8_t irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT; 657 u8 irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT;
549 uint8_t irqs_rd; 658 u8 irqs_rd;
550 int retries = 100; 659 int retries = 100;
551 660
552 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable"); 661 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable");
@@ -579,7 +688,7 @@ static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable)
579/* Interrupt handler */ 688/* Interrupt handler */
580static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled) 689static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
581{ 690{
582 uint8_t irq_status; 691 u8 irq_status;
583 692
584 /* disable interrupts to prevent a race condition */ 693 /* disable interrupts to prevent a race condition */
585 adv7511_set_isr(sd, false); 694 adv7511_set_isr(sd, false);
@@ -861,11 +970,13 @@ static int adv7511_get_fmt(struct v4l2_subdev *sd,
861 format->format.colorspace = fmt->colorspace; 970 format->format.colorspace = fmt->colorspace;
862 format->format.ycbcr_enc = fmt->ycbcr_enc; 971 format->format.ycbcr_enc = fmt->ycbcr_enc;
863 format->format.quantization = fmt->quantization; 972 format->format.quantization = fmt->quantization;
973 format->format.xfer_func = fmt->xfer_func;
864 } else { 974 } else {
865 format->format.code = state->fmt_code; 975 format->format.code = state->fmt_code;
866 format->format.colorspace = state->colorspace; 976 format->format.colorspace = state->colorspace;
867 format->format.ycbcr_enc = state->ycbcr_enc; 977 format->format.ycbcr_enc = state->ycbcr_enc;
868 format->format.quantization = state->quantization; 978 format->format.quantization = state->quantization;
979 format->format.xfer_func = state->xfer_func;
869 } 980 }
870 981
871 return 0; 982 return 0;
@@ -912,6 +1023,7 @@ static int adv7511_set_fmt(struct v4l2_subdev *sd,
912 fmt->colorspace = format->format.colorspace; 1023 fmt->colorspace = format->format.colorspace;
913 fmt->ycbcr_enc = format->format.ycbcr_enc; 1024 fmt->ycbcr_enc = format->format.ycbcr_enc;
914 fmt->quantization = format->format.quantization; 1025 fmt->quantization = format->format.quantization;
1026 fmt->xfer_func = format->format.xfer_func;
915 return 0; 1027 return 0;
916 } 1028 }
917 1029
@@ -936,6 +1048,7 @@ static int adv7511_set_fmt(struct v4l2_subdev *sd,
936 state->colorspace = format->format.colorspace; 1048 state->colorspace = format->format.colorspace;
937 state->ycbcr_enc = format->format.ycbcr_enc; 1049 state->ycbcr_enc = format->format.ycbcr_enc;
938 state->quantization = format->format.quantization; 1050 state->quantization = format->format.quantization;
1051 state->xfer_func = format->format.xfer_func;
939 1052
940 switch (format->format.colorspace) { 1053 switch (format->format.colorspace) {
941 case V4L2_COLORSPACE_ADOBERGB: 1054 case V4L2_COLORSPACE_ADOBERGB:
@@ -1028,7 +1141,7 @@ static const struct v4l2_subdev_ops adv7511_ops = {
1028}; 1141};
1029 1142
1030/* ----------------------------------------------------------------------- */ 1143/* ----------------------------------------------------------------------- */
1031static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, uint8_t *buf) 1144static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf)
1032{ 1145{
1033 if (debug >= lvl) { 1146 if (debug >= lvl) {
1034 int i, j; 1147 int i, j;
@@ -1140,7 +1253,7 @@ static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd)
1140{ 1253{
1141 struct adv7511_state *state = get_adv7511_state(sd); 1254 struct adv7511_state *state = get_adv7511_state(sd);
1142 /* read hotplug and rx-sense state */ 1255 /* read hotplug and rx-sense state */
1143 uint8_t status = adv7511_rd(sd, 0x42); 1256 u8 status = adv7511_rd(sd, 0x42);
1144 1257
1145 v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n", 1258 v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n",
1146 __func__, 1259 __func__,
@@ -1184,9 +1297,9 @@ static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd)
1184 } 1297 }
1185} 1298}
1186 1299
1187static bool edid_block_verify_crc(uint8_t *edid_block) 1300static bool edid_block_verify_crc(u8 *edid_block)
1188{ 1301{
1189 uint8_t sum = 0; 1302 u8 sum = 0;
1190 int i; 1303 int i;
1191 1304
1192 for (i = 0; i < 128; i++) 1305 for (i = 0; i < 128; i++)
@@ -1198,7 +1311,7 @@ static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment)
1198{ 1311{
1199 struct adv7511_state *state = get_adv7511_state(sd); 1312 struct adv7511_state *state = get_adv7511_state(sd);
1200 u32 blocks = state->edid.blocks; 1313 u32 blocks = state->edid.blocks;
1201 uint8_t *data = state->edid.data; 1314 u8 *data = state->edid.data;
1202 1315
1203 if (!edid_block_verify_crc(&data[segment * 256])) 1316 if (!edid_block_verify_crc(&data[segment * 256]))
1204 return false; 1317 return false;
@@ -1223,7 +1336,7 @@ static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment)
1223static bool adv7511_check_edid_status(struct v4l2_subdev *sd) 1336static bool adv7511_check_edid_status(struct v4l2_subdev *sd)
1224{ 1337{
1225 struct adv7511_state *state = get_adv7511_state(sd); 1338 struct adv7511_state *state = get_adv7511_state(sd);
1226 uint8_t edidRdy = adv7511_rd(sd, 0xc5); 1339 u8 edidRdy = adv7511_rd(sd, 0xc5);
1227 1340
1228 v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n", 1341 v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n",
1229 __func__, EDID_MAX_RETRIES - state->edid.read_retries); 1342 __func__, EDID_MAX_RETRIES - state->edid.read_retries);
@@ -1376,6 +1489,7 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
1376 /* EDID and CEC i2c addr */ 1489 /* EDID and CEC i2c addr */
1377 state->i2c_edid_addr = state->pdata.i2c_edid << 1; 1490 state->i2c_edid_addr = state->pdata.i2c_edid << 1;
1378 state->i2c_cec_addr = state->pdata.i2c_cec << 1; 1491 state->i2c_cec_addr = state->pdata.i2c_cec << 1;
1492 state->i2c_pktmem_addr = state->pdata.i2c_pktmem << 1;
1379 1493
1380 state->chip_revision = adv7511_rd(sd, 0x0); 1494 state->chip_revision = adv7511_rd(sd, 0x0);
1381 chip_id[0] = adv7511_rd(sd, 0xf5); 1495 chip_id[0] = adv7511_rd(sd, 0xf5);
@@ -1393,12 +1507,19 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
1393 goto err_entity; 1507 goto err_entity;
1394 } 1508 }
1395 1509
1510 state->i2c_pktmem = i2c_new_dummy(client->adapter, state->i2c_pktmem_addr >> 1);
1511 if (state->i2c_pktmem == NULL) {
1512 v4l2_err(sd, "failed to register pktmem i2c client\n");
1513 err = -ENOMEM;
1514 goto err_unreg_edid;
1515 }
1516
1396 adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ 1517 adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */
1397 state->work_queue = create_singlethread_workqueue(sd->name); 1518 state->work_queue = create_singlethread_workqueue(sd->name);
1398 if (state->work_queue == NULL) { 1519 if (state->work_queue == NULL) {
1399 v4l2_err(sd, "could not create workqueue\n"); 1520 v4l2_err(sd, "could not create workqueue\n");
1400 err = -ENOMEM; 1521 err = -ENOMEM;
1401 goto err_unreg_cec; 1522 goto err_unreg_pktmem;
1402 } 1523 }
1403 1524
1404 INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler); 1525 INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler);
@@ -1411,7 +1532,9 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
1411 client->addr << 1, client->adapter->name); 1532 client->addr << 1, client->adapter->name);
1412 return 0; 1533 return 0;
1413 1534
1414err_unreg_cec: 1535err_unreg_pktmem:
1536 i2c_unregister_device(state->i2c_pktmem);
1537err_unreg_edid:
1415 i2c_unregister_device(state->i2c_edid); 1538 i2c_unregister_device(state->i2c_edid);
1416err_entity: 1539err_entity:
1417 media_entity_cleanup(&sd->entity); 1540 media_entity_cleanup(&sd->entity);
@@ -1435,6 +1558,7 @@ static int adv7511_remove(struct i2c_client *client)
1435 adv7511_init_setup(sd); 1558 adv7511_init_setup(sd);
1436 cancel_delayed_work(&state->edid_handler); 1559 cancel_delayed_work(&state->edid_handler);
1437 i2c_unregister_device(state->i2c_edid); 1560 i2c_unregister_device(state->i2c_edid);
1561 i2c_unregister_device(state->i2c_pktmem);
1438 destroy_workqueue(state->work_queue); 1562 destroy_workqueue(state->work_queue);
1439 v4l2_device_unregister_subdev(sd); 1563 v4l2_device_unregister_subdev(sd);
1440 media_entity_cleanup(&sd->entity); 1564 media_entity_cleanup(&sd->entity);
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 60ffcf098bef..808360fd6539 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -29,6 +29,7 @@
29 29
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/gpio/consumer.h> 31#include <linux/gpio/consumer.h>
32#include <linux/hdmi.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33#include <linux/kernel.h> 34#include <linux/kernel.h>
34#include <linux/module.h> 35#include <linux/module.h>
@@ -95,6 +96,13 @@ struct adv76xx_format_info {
95 u8 op_format_sel; 96 u8 op_format_sel;
96}; 97};
97 98
99struct adv76xx_cfg_read_infoframe {
100 const char *desc;
101 u8 present_mask;
102 u8 head_addr;
103 u8 payload_addr;
104};
105
98struct adv76xx_chip_info { 106struct adv76xx_chip_info {
99 enum adv76xx_type type; 107 enum adv76xx_type type;
100 108
@@ -124,6 +132,20 @@ struct adv76xx_chip_info {
124 unsigned int num_recommended_settings[2]; 132 unsigned int num_recommended_settings[2];
125 133
126 unsigned long page_mask; 134 unsigned long page_mask;
135
136 /* Masks for timings */
137 unsigned int linewidth_mask;
138 unsigned int field0_height_mask;
139 unsigned int field1_height_mask;
140 unsigned int hfrontporch_mask;
141 unsigned int hsync_mask;
142 unsigned int hbackporch_mask;
143 unsigned int field0_vfrontporch_mask;
144 unsigned int field1_vfrontporch_mask;
145 unsigned int field0_vsync_mask;
146 unsigned int field1_vsync_mask;
147 unsigned int field0_vbackporch_mask;
148 unsigned int field1_vbackporch_mask;
127}; 149};
128 150
129/* 151/*
@@ -327,6 +349,11 @@ static const struct adv76xx_video_standards adv76xx_prim_mode_hdmi_gr[] = {
327 { }, 349 { },
328}; 350};
329 351
352static const struct v4l2_event adv76xx_ev_fmt = {
353 .type = V4L2_EVENT_SOURCE_CHANGE,
354 .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
355};
356
330/* ----------------------------------------------------------------------- */ 357/* ----------------------------------------------------------------------- */
331 358
332static inline struct adv76xx_state *to_state(struct v4l2_subdev *sd) 359static inline struct adv76xx_state *to_state(struct v4l2_subdev *sd)
@@ -1304,12 +1331,12 @@ static int stdi2dv_timings(struct v4l2_subdev *sd,
1304 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 1331 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs,
1305 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1332 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) |
1306 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1333 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0),
1307 timings)) 1334 false, timings))
1308 return 0; 1335 return 0;
1309 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs, 1336 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs,
1310 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1337 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) |
1311 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1338 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0),
1312 state->aspect_ratio, timings)) 1339 false, state->aspect_ratio, timings))
1313 return 0; 1340 return 0;
1314 1341
1315 v4l2_dbg(2, debug, sd, 1342 v4l2_dbg(2, debug, sd,
@@ -1504,23 +1531,28 @@ static int adv76xx_query_dv_timings(struct v4l2_subdev *sd,
1504 if (is_digital_input(sd)) { 1531 if (is_digital_input(sd)) {
1505 timings->type = V4L2_DV_BT_656_1120; 1532 timings->type = V4L2_DV_BT_656_1120;
1506 1533
1507 /* FIXME: All masks are incorrect for ADV7611 */ 1534 bt->width = hdmi_read16(sd, 0x07, info->linewidth_mask);
1508 bt->width = hdmi_read16(sd, 0x07, 0xfff); 1535 bt->height = hdmi_read16(sd, 0x09, info->field0_height_mask);
1509 bt->height = hdmi_read16(sd, 0x09, 0xfff);
1510 bt->pixelclock = info->read_hdmi_pixelclock(sd); 1536 bt->pixelclock = info->read_hdmi_pixelclock(sd);
1511 bt->hfrontporch = hdmi_read16(sd, 0x20, 0x3ff); 1537 bt->hfrontporch = hdmi_read16(sd, 0x20, info->hfrontporch_mask);
1512 bt->hsync = hdmi_read16(sd, 0x22, 0x3ff); 1538 bt->hsync = hdmi_read16(sd, 0x22, info->hsync_mask);
1513 bt->hbackporch = hdmi_read16(sd, 0x24, 0x3ff); 1539 bt->hbackporch = hdmi_read16(sd, 0x24, info->hbackporch_mask);
1514 bt->vfrontporch = hdmi_read16(sd, 0x2a, 0x1fff) / 2; 1540 bt->vfrontporch = hdmi_read16(sd, 0x2a,
1515 bt->vsync = hdmi_read16(sd, 0x2e, 0x1fff) / 2; 1541 info->field0_vfrontporch_mask) / 2;
1516 bt->vbackporch = hdmi_read16(sd, 0x32, 0x1fff) / 2; 1542 bt->vsync = hdmi_read16(sd, 0x2e, info->field0_vsync_mask) / 2;
1543 bt->vbackporch = hdmi_read16(sd, 0x32,
1544 info->field0_vbackporch_mask) / 2;
1517 bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) | 1545 bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) |
1518 ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0); 1546 ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0);
1519 if (bt->interlaced == V4L2_DV_INTERLACED) { 1547 if (bt->interlaced == V4L2_DV_INTERLACED) {
1520 bt->height += hdmi_read16(sd, 0x0b, 0xfff); 1548 bt->height += hdmi_read16(sd, 0x0b,
1521 bt->il_vfrontporch = hdmi_read16(sd, 0x2c, 0x1fff) / 2; 1549 info->field1_height_mask);
1522 bt->il_vsync = hdmi_read16(sd, 0x30, 0x1fff) / 2; 1550 bt->il_vfrontporch = hdmi_read16(sd, 0x2c,
1523 bt->il_vbackporch = hdmi_read16(sd, 0x34, 0x1fff) / 2; 1551 info->field1_vfrontporch_mask) / 2;
1552 bt->il_vsync = hdmi_read16(sd, 0x30,
1553 info->field1_vsync_mask) / 2;
1554 bt->il_vbackporch = hdmi_read16(sd, 0x34,
1555 info->field1_vbackporch_mask) / 2;
1524 } 1556 }
1525 adv76xx_fill_optional_dv_timings_fields(sd, timings); 1557 adv76xx_fill_optional_dv_timings_fields(sd, timings);
1526 } else { 1558 } else {
@@ -1725,11 +1757,11 @@ static int adv76xx_s_routing(struct v4l2_subdev *sd,
1725 state->selected_input = input; 1757 state->selected_input = input;
1726 1758
1727 disable_input(sd); 1759 disable_input(sd);
1728
1729 select_input(sd); 1760 select_input(sd);
1730
1731 enable_input(sd); 1761 enable_input(sd);
1732 1762
1763 v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
1764 (void *)&adv76xx_ev_fmt);
1733 return 0; 1765 return 0;
1734} 1766}
1735 1767
@@ -1896,7 +1928,8 @@ static int adv76xx_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
1896 "%s: fmt_change = 0x%x, fmt_change_digital = 0x%x\n", 1928 "%s: fmt_change = 0x%x, fmt_change_digital = 0x%x\n",
1897 __func__, fmt_change, fmt_change_digital); 1929 __func__, fmt_change, fmt_change_digital);
1898 1930
1899 v4l2_subdev_notify(sd, ADV76XX_FMT_CHANGE, NULL); 1931 v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
1932 (void *)&adv76xx_ev_fmt);
1900 1933
1901 if (handled) 1934 if (handled)
1902 *handled = true; 1935 *handled = true;
@@ -2102,46 +2135,67 @@ static int adv76xx_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
2102 2135
2103/*********** avi info frame CEA-861-E **************/ 2136/*********** avi info frame CEA-861-E **************/
2104 2137
2105static void print_avi_infoframe(struct v4l2_subdev *sd) 2138static const struct adv76xx_cfg_read_infoframe adv76xx_cri[] = {
2139 { "AVI", 0x01, 0xe0, 0x00 },
2140 { "Audio", 0x02, 0xe3, 0x1c },
2141 { "SDP", 0x04, 0xe6, 0x2a },
2142 { "Vendor", 0x10, 0xec, 0x54 }
2143};
2144
2145static int adv76xx_read_infoframe(struct v4l2_subdev *sd, int index,
2146 union hdmi_infoframe *frame)
2106{ 2147{
2148 uint8_t buffer[32];
2149 u8 len;
2107 int i; 2150 int i;
2108 u8 buf[14];
2109 u8 avi_len;
2110 u8 avi_ver;
2111 2151
2112 if (!is_hdmi(sd)) { 2152 if (!(io_read(sd, 0x60) & adv76xx_cri[index].present_mask)) {
2113 v4l2_info(sd, "receive DVI-D signal (AVI infoframe not supported)\n"); 2153 v4l2_info(sd, "%s infoframe not received\n",
2114 return; 2154 adv76xx_cri[index].desc);
2155 return -ENOENT;
2115 } 2156 }
2116 if (!(io_read(sd, 0x60) & 0x01)) { 2157
2117 v4l2_info(sd, "AVI infoframe not received\n"); 2158 for (i = 0; i < 3; i++)
2118 return; 2159 buffer[i] = infoframe_read(sd,
2160 adv76xx_cri[index].head_addr + i);
2161
2162 len = buffer[2] + 1;
2163
2164 if (len + 3 > sizeof(buffer)) {
2165 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__,
2166 adv76xx_cri[index].desc, len);
2167 return -ENOENT;
2119 } 2168 }
2120 2169
2121 if (io_read(sd, 0x83) & 0x01) { 2170 for (i = 0; i < len; i++)
2122 v4l2_info(sd, "AVI infoframe checksum error has occurred earlier\n"); 2171 buffer[i + 3] = infoframe_read(sd,
2123 io_write(sd, 0x85, 0x01); /* clear AVI_INF_CKS_ERR_RAW */ 2172 adv76xx_cri[index].payload_addr + i);
2124 if (io_read(sd, 0x83) & 0x01) { 2173
2125 v4l2_info(sd, "AVI infoframe checksum error still present\n"); 2174 if (hdmi_infoframe_unpack(frame, buffer) < 0) {
2126 io_write(sd, 0x85, 0x01); /* clear AVI_INF_CKS_ERR_RAW */ 2175 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__,
2127 } 2176 adv76xx_cri[index].desc);
2177 return -ENOENT;
2128 } 2178 }
2179 return 0;
2180}
2129 2181
2130 avi_len = infoframe_read(sd, 0xe2); 2182static void adv76xx_log_infoframes(struct v4l2_subdev *sd)
2131 avi_ver = infoframe_read(sd, 0xe1); 2183{
2132 v4l2_info(sd, "AVI infoframe version %d (%d byte)\n", 2184 int i;
2133 avi_ver, avi_len);
2134 2185
2135 if (avi_ver != 0x02) 2186 if (!is_hdmi(sd)) {
2187 v4l2_info(sd, "receive DVI-D signal, no infoframes\n");
2136 return; 2188 return;
2189 }
2137 2190
2138 for (i = 0; i < 14; i++) 2191 for (i = 0; i < ARRAY_SIZE(adv76xx_cri); i++) {
2139 buf[i] = infoframe_read(sd, i); 2192 union hdmi_infoframe frame;
2193 struct i2c_client *client = v4l2_get_subdevdata(sd);
2140 2194
2141 v4l2_info(sd, 2195 if (adv76xx_read_infoframe(sd, i, &frame))
2142 "\t%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 2196 return;
2143 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], 2197 hdmi_infoframe_log(KERN_INFO, &client->dev, &frame);
2144 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13]); 2198 }
2145} 2199}
2146 2200
2147static int adv76xx_log_status(struct v4l2_subdev *sd) 2201static int adv76xx_log_status(struct v4l2_subdev *sd)
@@ -2168,6 +2222,14 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
2168 "invalid", "invalid", "invalid", "invalid", "invalid", 2222 "invalid", "invalid", "invalid", "invalid", "invalid",
2169 "invalid", "invalid", "automatic" 2223 "invalid", "invalid", "automatic"
2170 }; 2224 };
2225 static const char * const hdmi_color_space_txt[16] = {
2226 "RGB limited range (16-235)", "RGB full range (0-255)",
2227 "YCbCr Bt.601 (16-235)", "YCbCr Bt.709 (16-235)",
2228 "xvYCC Bt.601", "xvYCC Bt.709",
2229 "YCbCr Bt.601 (0-255)", "YCbCr Bt.709 (0-255)",
2230 "sYCC", "Adobe YCC 601", "AdobeRGB", "invalid", "invalid",
2231 "invalid", "invalid", "invalid"
2232 };
2171 static const char * const rgb_quantization_range_txt[] = { 2233 static const char * const rgb_quantization_range_txt[] = {
2172 "Automatic", 2234 "Automatic",
2173 "RGB limited range (16-235)", 2235 "RGB limited range (16-235)",
@@ -2235,11 +2297,12 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
2235 rgb_quantization_range_txt[state->rgb_quantization_range]); 2297 rgb_quantization_range_txt[state->rgb_quantization_range]);
2236 v4l2_info(sd, "Input color space: %s\n", 2298 v4l2_info(sd, "Input color space: %s\n",
2237 input_color_space_txt[reg_io_0x02 >> 4]); 2299 input_color_space_txt[reg_io_0x02 >> 4]);
2238 v4l2_info(sd, "Output color space: %s %s, saturator %s\n", 2300 v4l2_info(sd, "Output color space: %s %s, saturator %s, alt-gamma %s\n",
2239 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr", 2301 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2240 (reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)", 2302 (reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)",
2241 ((reg_io_0x02 & 0x04) ^ (reg_io_0x02 & 0x01)) ? 2303 (((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2242 "enabled" : "disabled"); 2304 "enabled" : "disabled",
2305 (reg_io_0x02 & 0x08) ? "enabled" : "disabled");
2243 v4l2_info(sd, "Color space conversion: %s\n", 2306 v4l2_info(sd, "Color space conversion: %s\n",
2244 csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]); 2307 csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]);
2245 2308
@@ -2276,8 +2339,9 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
2276 v4l2_info(sd, "AV Mute: %s\n", (hdmi_read(sd, 0x04) & 0x40) ? "on" : "off"); 2339 v4l2_info(sd, "AV Mute: %s\n", (hdmi_read(sd, 0x04) & 0x40) ? "on" : "off");
2277 2340
2278 v4l2_info(sd, "Deep color mode: %s\n", deep_color_mode_txt[(hdmi_read(sd, 0x0b) & 0x60) >> 5]); 2341 v4l2_info(sd, "Deep color mode: %s\n", deep_color_mode_txt[(hdmi_read(sd, 0x0b) & 0x60) >> 5]);
2342 v4l2_info(sd, "HDMI colorspace: %s\n", hdmi_color_space_txt[hdmi_read(sd, 0x53) & 0xf]);
2279 2343
2280 print_avi_infoframe(sd); 2344 adv76xx_log_infoframes(sd);
2281 } 2345 }
2282 2346
2283 return 0; 2347 return 0;
@@ -2567,6 +2631,18 @@ static const struct adv76xx_chip_info adv76xx_chip_info[] = {
2567 BIT(ADV76XX_PAGE_EDID) | BIT(ADV76XX_PAGE_HDMI) | 2631 BIT(ADV76XX_PAGE_EDID) | BIT(ADV76XX_PAGE_HDMI) |
2568 BIT(ADV76XX_PAGE_TEST) | BIT(ADV76XX_PAGE_CP) | 2632 BIT(ADV76XX_PAGE_TEST) | BIT(ADV76XX_PAGE_CP) |
2569 BIT(ADV7604_PAGE_VDP), 2633 BIT(ADV7604_PAGE_VDP),
2634 .linewidth_mask = 0xfff,
2635 .field0_height_mask = 0xfff,
2636 .field1_height_mask = 0xfff,
2637 .hfrontporch_mask = 0x3ff,
2638 .hsync_mask = 0x3ff,
2639 .hbackporch_mask = 0x3ff,
2640 .field0_vfrontporch_mask = 0x1fff,
2641 .field0_vsync_mask = 0x1fff,
2642 .field0_vbackporch_mask = 0x1fff,
2643 .field1_vfrontporch_mask = 0x1fff,
2644 .field1_vsync_mask = 0x1fff,
2645 .field1_vbackporch_mask = 0x1fff,
2570 }, 2646 },
2571 [ADV7611] = { 2647 [ADV7611] = {
2572 .type = ADV7611, 2648 .type = ADV7611,
@@ -2596,17 +2672,29 @@ static const struct adv76xx_chip_info adv76xx_chip_info[] = {
2596 BIT(ADV76XX_PAGE_INFOFRAME) | BIT(ADV76XX_PAGE_AFE) | 2672 BIT(ADV76XX_PAGE_INFOFRAME) | BIT(ADV76XX_PAGE_AFE) |
2597 BIT(ADV76XX_PAGE_REP) | BIT(ADV76XX_PAGE_EDID) | 2673 BIT(ADV76XX_PAGE_REP) | BIT(ADV76XX_PAGE_EDID) |
2598 BIT(ADV76XX_PAGE_HDMI) | BIT(ADV76XX_PAGE_CP), 2674 BIT(ADV76XX_PAGE_HDMI) | BIT(ADV76XX_PAGE_CP),
2675 .linewidth_mask = 0x1fff,
2676 .field0_height_mask = 0x1fff,
2677 .field1_height_mask = 0x1fff,
2678 .hfrontporch_mask = 0x1fff,
2679 .hsync_mask = 0x1fff,
2680 .hbackporch_mask = 0x1fff,
2681 .field0_vfrontporch_mask = 0x3fff,
2682 .field0_vsync_mask = 0x3fff,
2683 .field0_vbackporch_mask = 0x3fff,
2684 .field1_vfrontporch_mask = 0x3fff,
2685 .field1_vsync_mask = 0x3fff,
2686 .field1_vbackporch_mask = 0x3fff,
2599 }, 2687 },
2600}; 2688};
2601 2689
2602static struct i2c_device_id adv76xx_i2c_id[] = { 2690static const struct i2c_device_id adv76xx_i2c_id[] = {
2603 { "adv7604", (kernel_ulong_t)&adv76xx_chip_info[ADV7604] }, 2691 { "adv7604", (kernel_ulong_t)&adv76xx_chip_info[ADV7604] },
2604 { "adv7611", (kernel_ulong_t)&adv76xx_chip_info[ADV7611] }, 2692 { "adv7611", (kernel_ulong_t)&adv76xx_chip_info[ADV7611] },
2605 { } 2693 { }
2606}; 2694};
2607MODULE_DEVICE_TABLE(i2c, adv76xx_i2c_id); 2695MODULE_DEVICE_TABLE(i2c, adv76xx_i2c_id);
2608 2696
2609static struct of_device_id adv76xx_of_id[] __maybe_unused = { 2697static const struct of_device_id adv76xx_of_id[] __maybe_unused = {
2610 { .compatible = "adi,adv7611", .data = &adv76xx_chip_info[ADV7611] }, 2698 { .compatible = "adi,adv7611", .data = &adv76xx_chip_info[ADV7611] },
2611 { } 2699 { }
2612}; 2700};
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index b5a37fe10a6a..4cf79b2422d4 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -56,6 +56,28 @@ MODULE_LICENSE("GPL");
56/* ADV7842 system clock frequency */ 56/* ADV7842 system clock frequency */
57#define ADV7842_fsc (28636360) 57#define ADV7842_fsc (28636360)
58 58
59#define ADV7842_RGB_OUT (1 << 1)
60
61#define ADV7842_OP_FORMAT_SEL_8BIT (0 << 0)
62#define ADV7842_OP_FORMAT_SEL_10BIT (1 << 0)
63#define ADV7842_OP_FORMAT_SEL_12BIT (2 << 0)
64
65#define ADV7842_OP_MODE_SEL_SDR_422 (0 << 5)
66#define ADV7842_OP_MODE_SEL_DDR_422 (1 << 5)
67#define ADV7842_OP_MODE_SEL_SDR_444 (2 << 5)
68#define ADV7842_OP_MODE_SEL_DDR_444 (3 << 5)
69#define ADV7842_OP_MODE_SEL_SDR_422_2X (4 << 5)
70#define ADV7842_OP_MODE_SEL_ADI_CM (5 << 5)
71
72#define ADV7842_OP_CH_SEL_GBR (0 << 5)
73#define ADV7842_OP_CH_SEL_GRB (1 << 5)
74#define ADV7842_OP_CH_SEL_BGR (2 << 5)
75#define ADV7842_OP_CH_SEL_RGB (3 << 5)
76#define ADV7842_OP_CH_SEL_BRG (4 << 5)
77#define ADV7842_OP_CH_SEL_RBG (5 << 5)
78
79#define ADV7842_OP_SWAP_CB_CR (1 << 0)
80
59/* 81/*
60********************************************************************** 82**********************************************************************
61* 83*
@@ -64,6 +86,14 @@ MODULE_LICENSE("GPL");
64********************************************************************** 86**********************************************************************
65*/ 87*/
66 88
89struct adv7842_format_info {
90 u32 code;
91 u8 op_ch_sel;
92 bool rgb_out;
93 bool swap_cb_cr;
94 u8 op_format_sel;
95};
96
67struct adv7842_state { 97struct adv7842_state {
68 struct adv7842_platform_data pdata; 98 struct adv7842_platform_data pdata;
69 struct v4l2_subdev sd; 99 struct v4l2_subdev sd;
@@ -72,6 +102,9 @@ struct adv7842_state {
72 enum adv7842_mode mode; 102 enum adv7842_mode mode;
73 struct v4l2_dv_timings timings; 103 struct v4l2_dv_timings timings;
74 enum adv7842_vid_std_select vid_std_select; 104 enum adv7842_vid_std_select vid_std_select;
105
106 const struct adv7842_format_info *format;
107
75 v4l2_std_id norm; 108 v4l2_std_id norm;
76 struct { 109 struct {
77 u8 edid[256]; 110 u8 edid[256];
@@ -209,6 +242,11 @@ static const struct adv7842_video_standards adv7842_prim_mode_hdmi_gr[] = {
209 { }, 242 { },
210}; 243};
211 244
245static const struct v4l2_event adv7842_ev_fmt = {
246 .type = V4L2_EVENT_SOURCE_CHANGE,
247 .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
248};
249
212/* ----------------------------------------------------------------------- */ 250/* ----------------------------------------------------------------------- */
213 251
214static inline struct adv7842_state *to_state(struct v4l2_subdev *sd) 252static inline struct adv7842_state *to_state(struct v4l2_subdev *sd)
@@ -221,11 +259,21 @@ static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
221 return &container_of(ctrl->handler, struct adv7842_state, hdl)->sd; 259 return &container_of(ctrl->handler, struct adv7842_state, hdl)->sd;
222} 260}
223 261
262static inline unsigned hblanking(const struct v4l2_bt_timings *t)
263{
264 return V4L2_DV_BT_BLANKING_WIDTH(t);
265}
266
224static inline unsigned htotal(const struct v4l2_bt_timings *t) 267static inline unsigned htotal(const struct v4l2_bt_timings *t)
225{ 268{
226 return V4L2_DV_BT_FRAME_WIDTH(t); 269 return V4L2_DV_BT_FRAME_WIDTH(t);
227} 270}
228 271
272static inline unsigned vblanking(const struct v4l2_bt_timings *t)
273{
274 return V4L2_DV_BT_BLANKING_HEIGHT(t);
275}
276
229static inline unsigned vtotal(const struct v4l2_bt_timings *t) 277static inline unsigned vtotal(const struct v4l2_bt_timings *t)
230{ 278{
231 return V4L2_DV_BT_FRAME_HEIGHT(t); 279 return V4L2_DV_BT_FRAME_HEIGHT(t);
@@ -335,6 +383,12 @@ static inline int io_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 va
335 return io_write(sd, reg, (io_read(sd, reg) & mask) | val); 383 return io_write(sd, reg, (io_read(sd, reg) & mask) | val);
336} 384}
337 385
386static inline int io_write_clr_set(struct v4l2_subdev *sd,
387 u8 reg, u8 mask, u8 val)
388{
389 return io_write(sd, reg, (io_read(sd, reg) & ~mask) | val);
390}
391
338static inline int avlink_read(struct v4l2_subdev *sd, u8 reg) 392static inline int avlink_read(struct v4l2_subdev *sd, u8 reg)
339{ 393{
340 struct adv7842_state *state = to_state(sd); 394 struct adv7842_state *state = to_state(sd);
@@ -535,6 +589,64 @@ static void main_reset(struct v4l2_subdev *sd)
535 mdelay(5); 589 mdelay(5);
536} 590}
537 591
592/* -----------------------------------------------------------------------------
593 * Format helpers
594 */
595
596static const struct adv7842_format_info adv7842_formats[] = {
597 { MEDIA_BUS_FMT_RGB888_1X24, ADV7842_OP_CH_SEL_RGB, true, false,
598 ADV7842_OP_MODE_SEL_SDR_444 | ADV7842_OP_FORMAT_SEL_8BIT },
599 { MEDIA_BUS_FMT_YUYV8_2X8, ADV7842_OP_CH_SEL_RGB, false, false,
600 ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_8BIT },
601 { MEDIA_BUS_FMT_YVYU8_2X8, ADV7842_OP_CH_SEL_RGB, false, true,
602 ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_8BIT },
603 { MEDIA_BUS_FMT_YUYV10_2X10, ADV7842_OP_CH_SEL_RGB, false, false,
604 ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_10BIT },
605 { MEDIA_BUS_FMT_YVYU10_2X10, ADV7842_OP_CH_SEL_RGB, false, true,
606 ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_10BIT },
607 { MEDIA_BUS_FMT_YUYV12_2X12, ADV7842_OP_CH_SEL_RGB, false, false,
608 ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_12BIT },
609 { MEDIA_BUS_FMT_YVYU12_2X12, ADV7842_OP_CH_SEL_RGB, false, true,
610 ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_12BIT },
611 { MEDIA_BUS_FMT_UYVY8_1X16, ADV7842_OP_CH_SEL_RBG, false, false,
612 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_8BIT },
613 { MEDIA_BUS_FMT_VYUY8_1X16, ADV7842_OP_CH_SEL_RBG, false, true,
614 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_8BIT },
615 { MEDIA_BUS_FMT_YUYV8_1X16, ADV7842_OP_CH_SEL_RGB, false, false,
616 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_8BIT },
617 { MEDIA_BUS_FMT_YVYU8_1X16, ADV7842_OP_CH_SEL_RGB, false, true,
618 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_8BIT },
619 { MEDIA_BUS_FMT_UYVY10_1X20, ADV7842_OP_CH_SEL_RBG, false, false,
620 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_10BIT },
621 { MEDIA_BUS_FMT_VYUY10_1X20, ADV7842_OP_CH_SEL_RBG, false, true,
622 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_10BIT },
623 { MEDIA_BUS_FMT_YUYV10_1X20, ADV7842_OP_CH_SEL_RGB, false, false,
624 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_10BIT },
625 { MEDIA_BUS_FMT_YVYU10_1X20, ADV7842_OP_CH_SEL_RGB, false, true,
626 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_10BIT },
627 { MEDIA_BUS_FMT_UYVY12_1X24, ADV7842_OP_CH_SEL_RBG, false, false,
628 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_12BIT },
629 { MEDIA_BUS_FMT_VYUY12_1X24, ADV7842_OP_CH_SEL_RBG, false, true,
630 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_12BIT },
631 { MEDIA_BUS_FMT_YUYV12_1X24, ADV7842_OP_CH_SEL_RGB, false, false,
632 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_12BIT },
633 { MEDIA_BUS_FMT_YVYU12_1X24, ADV7842_OP_CH_SEL_RGB, false, true,
634 ADV7842_OP_MODE_SEL_SDR_422_2X | ADV7842_OP_FORMAT_SEL_12BIT },
635};
636
637static const struct adv7842_format_info *
638adv7842_format_info(struct adv7842_state *state, u32 code)
639{
640 unsigned int i;
641
642 for (i = 0; i < ARRAY_SIZE(adv7842_formats); ++i) {
643 if (adv7842_formats[i].code == code)
644 return &adv7842_formats[i];
645 }
646
647 return NULL;
648}
649
538/* ----------------------------------------------------------------------- */ 650/* ----------------------------------------------------------------------- */
539 651
540static inline bool is_analog_input(struct v4l2_subdev *sd) 652static inline bool is_analog_input(struct v4l2_subdev *sd)
@@ -1333,12 +1445,12 @@ static int stdi2dv_timings(struct v4l2_subdev *sd,
1333 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 1445 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs,
1334 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1446 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) |
1335 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1447 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0),
1336 timings)) 1448 false, timings))
1337 return 0; 1449 return 0;
1338 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs, 1450 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs,
1339 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1451 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) |
1340 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1452 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0),
1341 state->aspect_ratio, timings)) 1453 false, state->aspect_ratio, timings))
1342 return 0; 1454 return 0;
1343 1455
1344 v4l2_dbg(2, debug, sd, 1456 v4l2_dbg(2, debug, sd,
@@ -1440,9 +1552,11 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
1440 } 1552 }
1441 bt->interlaced = stdi.interlaced ? 1553 bt->interlaced = stdi.interlaced ?
1442 V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE; 1554 V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE;
1555 bt->standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
1556 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT;
1443 1557
1444 if (is_digital_input(sd)) { 1558 if (is_digital_input(sd)) {
1445 uint32_t freq; 1559 u32 freq;
1446 1560
1447 timings->type = V4L2_DV_BT_656_1120; 1561 timings->type = V4L2_DV_BT_656_1120;
1448 1562
@@ -1478,6 +1592,10 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
1478 hdmi_read(sd, 0x31)) / 2; 1592 hdmi_read(sd, 0x31)) / 2;
1479 bt->il_vbackporch = ((hdmi_read(sd, 0x34) & 0x1f) * 256 + 1593 bt->il_vbackporch = ((hdmi_read(sd, 0x34) & 0x1f) * 256 +
1480 hdmi_read(sd, 0x35)) / 2; 1594 hdmi_read(sd, 0x35)) / 2;
1595 } else {
1596 bt->il_vfrontporch = 0;
1597 bt->il_vsync = 0;
1598 bt->il_vbackporch = 0;
1481 } 1599 }
1482 adv7842_fill_optional_dv_timings_fields(sd, timings); 1600 adv7842_fill_optional_dv_timings_fields(sd, timings);
1483 } else { 1601 } else {
@@ -1862,50 +1980,155 @@ static int adv7842_s_routing(struct v4l2_subdev *sd,
1862 select_input(sd, state->vid_std_select); 1980 select_input(sd, state->vid_std_select);
1863 enable_input(sd); 1981 enable_input(sd);
1864 1982
1865 v4l2_subdev_notify(sd, ADV7842_FMT_CHANGE, NULL); 1983 v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
1984 (void *)&adv7842_ev_fmt);
1866 1985
1867 return 0; 1986 return 0;
1868} 1987}
1869 1988
1870static int adv7842_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index, 1989static int adv7842_enum_mbus_code(struct v4l2_subdev *sd,
1871 u32 *code) 1990 struct v4l2_subdev_pad_config *cfg,
1991 struct v4l2_subdev_mbus_code_enum *code)
1872{ 1992{
1873 if (index) 1993 if (code->index >= ARRAY_SIZE(adv7842_formats))
1874 return -EINVAL; 1994 return -EINVAL;
1875 /* Good enough for now */ 1995 code->code = adv7842_formats[code->index].code;
1876 *code = MEDIA_BUS_FMT_FIXED;
1877 return 0; 1996 return 0;
1878} 1997}
1879 1998
1880static int adv7842_g_mbus_fmt(struct v4l2_subdev *sd, 1999static void adv7842_fill_format(struct adv7842_state *state,
1881 struct v4l2_mbus_framefmt *fmt) 2000 struct v4l2_mbus_framefmt *format)
2001{
2002 memset(format, 0, sizeof(*format));
2003
2004 format->width = state->timings.bt.width;
2005 format->height = state->timings.bt.height;
2006 format->field = V4L2_FIELD_NONE;
2007 format->colorspace = V4L2_COLORSPACE_SRGB;
2008
2009 if (state->timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO)
2010 format->colorspace = (state->timings.bt.height <= 576) ?
2011 V4L2_COLORSPACE_SMPTE170M : V4L2_COLORSPACE_REC709;
2012}
2013
2014/*
2015 * Compute the op_ch_sel value required to obtain on the bus the component order
2016 * corresponding to the selected format taking into account bus reordering
2017 * applied by the board at the output of the device.
2018 *
2019 * The following table gives the op_ch_value from the format component order
2020 * (expressed as op_ch_sel value in column) and the bus reordering (expressed as
2021 * adv7842_bus_order value in row).
2022 *
2023 * | GBR(0) GRB(1) BGR(2) RGB(3) BRG(4) RBG(5)
2024 * ----------+-------------------------------------------------
2025 * RGB (NOP) | GBR GRB BGR RGB BRG RBG
2026 * GRB (1-2) | BGR RGB GBR GRB RBG BRG
2027 * RBG (2-3) | GRB GBR BRG RBG BGR RGB
2028 * BGR (1-3) | RBG BRG RGB BGR GRB GBR
2029 * BRG (ROR) | BRG RBG GRB GBR RGB BGR
2030 * GBR (ROL) | RGB BGR RBG BRG GBR GRB
2031 */
2032static unsigned int adv7842_op_ch_sel(struct adv7842_state *state)
2033{
2034#define _SEL(a, b, c, d, e, f) { \
2035 ADV7842_OP_CH_SEL_##a, ADV7842_OP_CH_SEL_##b, ADV7842_OP_CH_SEL_##c, \
2036 ADV7842_OP_CH_SEL_##d, ADV7842_OP_CH_SEL_##e, ADV7842_OP_CH_SEL_##f }
2037#define _BUS(x) [ADV7842_BUS_ORDER_##x]
2038
2039 static const unsigned int op_ch_sel[6][6] = {
2040 _BUS(RGB) /* NOP */ = _SEL(GBR, GRB, BGR, RGB, BRG, RBG),
2041 _BUS(GRB) /* 1-2 */ = _SEL(BGR, RGB, GBR, GRB, RBG, BRG),
2042 _BUS(RBG) /* 2-3 */ = _SEL(GRB, GBR, BRG, RBG, BGR, RGB),
2043 _BUS(BGR) /* 1-3 */ = _SEL(RBG, BRG, RGB, BGR, GRB, GBR),
2044 _BUS(BRG) /* ROR */ = _SEL(BRG, RBG, GRB, GBR, RGB, BGR),
2045 _BUS(GBR) /* ROL */ = _SEL(RGB, BGR, RBG, BRG, GBR, GRB),
2046 };
2047
2048 return op_ch_sel[state->pdata.bus_order][state->format->op_ch_sel >> 5];
2049}
2050
2051static void adv7842_setup_format(struct adv7842_state *state)
2052{
2053 struct v4l2_subdev *sd = &state->sd;
2054
2055 io_write_clr_set(sd, 0x02, 0x02,
2056 state->format->rgb_out ? ADV7842_RGB_OUT : 0);
2057 io_write(sd, 0x03, state->format->op_format_sel |
2058 state->pdata.op_format_mode_sel);
2059 io_write_clr_set(sd, 0x04, 0xe0, adv7842_op_ch_sel(state));
2060 io_write_clr_set(sd, 0x05, 0x01,
2061 state->format->swap_cb_cr ? ADV7842_OP_SWAP_CB_CR : 0);
2062}
2063
2064static int adv7842_get_format(struct v4l2_subdev *sd,
2065 struct v4l2_subdev_pad_config *cfg,
2066 struct v4l2_subdev_format *format)
1882{ 2067{
1883 struct adv7842_state *state = to_state(sd); 2068 struct adv7842_state *state = to_state(sd);
1884 2069
1885 fmt->width = state->timings.bt.width; 2070 if (format->pad != ADV7842_PAD_SOURCE)
1886 fmt->height = state->timings.bt.height; 2071 return -EINVAL;
1887 fmt->code = MEDIA_BUS_FMT_FIXED;
1888 fmt->field = V4L2_FIELD_NONE;
1889 2072
1890 if (state->mode == ADV7842_MODE_SDP) { 2073 if (state->mode == ADV7842_MODE_SDP) {
1891 /* SPD block */ 2074 /* SPD block */
1892 if (!(sdp_read(sd, 0x5A) & 0x01)) 2075 if (!(sdp_read(sd, 0x5a) & 0x01))
1893 return -EINVAL; 2076 return -EINVAL;
1894 fmt->width = 720; 2077 format->format.code = MEDIA_BUS_FMT_YUYV8_2X8;
2078 format->format.width = 720;
1895 /* valid signal */ 2079 /* valid signal */
1896 if (state->norm & V4L2_STD_525_60) 2080 if (state->norm & V4L2_STD_525_60)
1897 fmt->height = 480; 2081 format->format.height = 480;
1898 else 2082 else
1899 fmt->height = 576; 2083 format->format.height = 576;
1900 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 2084 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
1901 return 0; 2085 return 0;
1902 } 2086 }
1903 2087
1904 fmt->colorspace = V4L2_COLORSPACE_SRGB; 2088 adv7842_fill_format(state, &format->format);
1905 if (state->timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) { 2089
1906 fmt->colorspace = (state->timings.bt.height <= 576) ? 2090 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
1907 V4L2_COLORSPACE_SMPTE170M : V4L2_COLORSPACE_REC709; 2091 struct v4l2_mbus_framefmt *fmt;
2092
2093 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
2094 format->format.code = fmt->code;
2095 } else {
2096 format->format.code = state->format->code;
2097 }
2098
2099 return 0;
2100}
2101
2102static int adv7842_set_format(struct v4l2_subdev *sd,
2103 struct v4l2_subdev_pad_config *cfg,
2104 struct v4l2_subdev_format *format)
2105{
2106 struct adv7842_state *state = to_state(sd);
2107 const struct adv7842_format_info *info;
2108
2109 if (format->pad != ADV7842_PAD_SOURCE)
2110 return -EINVAL;
2111
2112 if (state->mode == ADV7842_MODE_SDP)
2113 return adv7842_get_format(sd, cfg, format);
2114
2115 info = adv7842_format_info(state, format->format.code);
2116 if (info == NULL)
2117 info = adv7842_format_info(state, MEDIA_BUS_FMT_YUYV8_2X8);
2118
2119 adv7842_fill_format(state, &format->format);
2120 format->format.code = info->code;
2121
2122 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
2123 struct v4l2_mbus_framefmt *fmt;
2124
2125 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
2126 fmt->code = format->format.code;
2127 } else {
2128 state->format = info;
2129 adv7842_setup_format(state);
1908 } 2130 }
2131
1909 return 0; 2132 return 0;
1910} 2133}
1911 2134
@@ -1991,7 +2214,8 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
1991 "%s: fmt_change_cp = 0x%x, fmt_change_digital = 0x%x, fmt_change_sdp = 0x%x\n", 2214 "%s: fmt_change_cp = 0x%x, fmt_change_digital = 0x%x, fmt_change_sdp = 0x%x\n",
1992 __func__, fmt_change_cp, fmt_change_digital, 2215 __func__, fmt_change_cp, fmt_change_digital,
1993 fmt_change_sdp); 2216 fmt_change_sdp);
1994 v4l2_subdev_notify(sd, ADV7842_FMT_CHANGE, NULL); 2217 v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
2218 (void *)&adv7842_ev_fmt);
1995 if (handled) 2219 if (handled)
1996 *handled = true; 2220 *handled = true;
1997 } 2221 }
@@ -2110,7 +2334,7 @@ struct adv7842_cfg_read_infoframe {
2110static void log_infoframe(struct v4l2_subdev *sd, struct adv7842_cfg_read_infoframe *cri) 2334static void log_infoframe(struct v4l2_subdev *sd, struct adv7842_cfg_read_infoframe *cri)
2111{ 2335{
2112 int i; 2336 int i;
2113 uint8_t buffer[32]; 2337 u8 buffer[32];
2114 union hdmi_infoframe frame; 2338 union hdmi_infoframe frame;
2115 u8 len; 2339 u8 len;
2116 struct i2c_client *client = v4l2_get_subdevdata(sd); 2340 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -2183,7 +2407,7 @@ static const char * const prim_mode_txt[] = {
2183static int adv7842_sdp_log_status(struct v4l2_subdev *sd) 2407static int adv7842_sdp_log_status(struct v4l2_subdev *sd)
2184{ 2408{
2185 /* SDP (Standard definition processor) block */ 2409 /* SDP (Standard definition processor) block */
2186 uint8_t sdp_signal_detected = sdp_read(sd, 0x5A) & 0x01; 2410 u8 sdp_signal_detected = sdp_read(sd, 0x5A) & 0x01;
2187 2411
2188 v4l2_info(sd, "Chip powered %s\n", no_power(sd) ? "off" : "on"); 2412 v4l2_info(sd, "Chip powered %s\n", no_power(sd) ? "off" : "on");
2189 v4l2_info(sd, "Prim-mode = 0x%x, video std = 0x%x\n", 2413 v4l2_info(sd, "Prim-mode = 0x%x, video std = 0x%x\n",
@@ -2227,10 +2451,10 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
2227 /* CP block */ 2451 /* CP block */
2228 struct adv7842_state *state = to_state(sd); 2452 struct adv7842_state *state = to_state(sd);
2229 struct v4l2_dv_timings timings; 2453 struct v4l2_dv_timings timings;
2230 uint8_t reg_io_0x02 = io_read(sd, 0x02); 2454 u8 reg_io_0x02 = io_read(sd, 0x02);
2231 uint8_t reg_io_0x21 = io_read(sd, 0x21); 2455 u8 reg_io_0x21 = io_read(sd, 0x21);
2232 uint8_t reg_rep_0x77 = rep_read(sd, 0x77); 2456 u8 reg_rep_0x77 = rep_read(sd, 0x77);
2233 uint8_t reg_rep_0x7d = rep_read(sd, 0x7d); 2457 u8 reg_rep_0x7d = rep_read(sd, 0x7d);
2234 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01; 2458 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01;
2235 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01; 2459 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01;
2236 bool audio_mute = io_read(sd, 0x65) & 0x40; 2460 bool audio_mute = io_read(sd, 0x65) & 0x40;
@@ -2302,10 +2526,10 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
2302 if (no_cp_signal(sd)) { 2526 if (no_cp_signal(sd)) {
2303 v4l2_info(sd, "STDI: not locked\n"); 2527 v4l2_info(sd, "STDI: not locked\n");
2304 } else { 2528 } else {
2305 uint32_t bl = ((cp_read(sd, 0xb1) & 0x3f) << 8) | cp_read(sd, 0xb2); 2529 u32 bl = ((cp_read(sd, 0xb1) & 0x3f) << 8) | cp_read(sd, 0xb2);
2306 uint32_t lcf = ((cp_read(sd, 0xb3) & 0x7) << 8) | cp_read(sd, 0xb4); 2530 u32 lcf = ((cp_read(sd, 0xb3) & 0x7) << 8) | cp_read(sd, 0xb4);
2307 uint32_t lcvs = cp_read(sd, 0xb3) >> 3; 2531 u32 lcvs = cp_read(sd, 0xb3) >> 3;
2308 uint32_t fcl = ((cp_read(sd, 0xb8) & 0x1f) << 8) | cp_read(sd, 0xb9); 2532 u32 fcl = ((cp_read(sd, 0xb8) & 0x1f) << 8) | cp_read(sd, 0xb9);
2309 char hs_pol = ((cp_read(sd, 0xb5) & 0x10) ? 2533 char hs_pol = ((cp_read(sd, 0xb5) & 0x10) ?
2310 ((cp_read(sd, 0xb5) & 0x08) ? '+' : '-') : 'x'); 2534 ((cp_read(sd, 0xb5) & 0x08) ? '+' : '-') : 'x');
2311 char vs_pol = ((cp_read(sd, 0xb5) & 0x40) ? 2535 char vs_pol = ((cp_read(sd, 0xb5) & 0x40) ?
@@ -2545,14 +2769,11 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
2545 0xf0 | 2769 0xf0 |
2546 pdata->alt_gamma << 3 | 2770 pdata->alt_gamma << 3 |
2547 pdata->op_656_range << 2 | 2771 pdata->op_656_range << 2 |
2548 pdata->rgb_out << 1 |
2549 pdata->alt_data_sat << 0); 2772 pdata->alt_data_sat << 0);
2550 io_write(sd, 0x03, pdata->op_format_sel);
2551 io_write_and_or(sd, 0x04, 0x1f, pdata->op_ch_sel << 5);
2552 io_write_and_or(sd, 0x05, 0xf0, pdata->blank_data << 3 | 2773 io_write_and_or(sd, 0x05, 0xf0, pdata->blank_data << 3 |
2553 pdata->insert_av_codes << 2 | 2774 pdata->insert_av_codes << 2 |
2554 pdata->replicate_av_codes << 1 | 2775 pdata->replicate_av_codes << 1);
2555 pdata->invert_cbcr << 0); 2776 adv7842_setup_format(state);
2556 2777
2557 /* HDMI audio */ 2778 /* HDMI audio */
2558 hdmi_write_and_or(sd, 0x1a, 0xf1, 0x08); /* Wait 1 s before unmute */ 2779 hdmi_write_and_or(sd, 0x1a, 0xf1, 0x08); /* Wait 1 s before unmute */
@@ -2809,13 +3030,12 @@ static const struct v4l2_subdev_video_ops adv7842_video_ops = {
2809 .s_dv_timings = adv7842_s_dv_timings, 3030 .s_dv_timings = adv7842_s_dv_timings,
2810 .g_dv_timings = adv7842_g_dv_timings, 3031 .g_dv_timings = adv7842_g_dv_timings,
2811 .query_dv_timings = adv7842_query_dv_timings, 3032 .query_dv_timings = adv7842_query_dv_timings,
2812 .enum_mbus_fmt = adv7842_enum_mbus_fmt,
2813 .g_mbus_fmt = adv7842_g_mbus_fmt,
2814 .try_mbus_fmt = adv7842_g_mbus_fmt,
2815 .s_mbus_fmt = adv7842_g_mbus_fmt,
2816}; 3033};
2817 3034
2818static const struct v4l2_subdev_pad_ops adv7842_pad_ops = { 3035static const struct v4l2_subdev_pad_ops adv7842_pad_ops = {
3036 .enum_mbus_code = adv7842_enum_mbus_code,
3037 .get_fmt = adv7842_get_format,
3038 .set_fmt = adv7842_set_format,
2819 .get_edid = adv7842_get_edid, 3039 .get_edid = adv7842_get_edid,
2820 .set_edid = adv7842_set_edid, 3040 .set_edid = adv7842_set_edid,
2821 .enum_dv_timings = adv7842_enum_dv_timings, 3041 .enum_dv_timings = adv7842_enum_dv_timings,
@@ -2986,6 +3206,7 @@ static int adv7842_probe(struct i2c_client *client,
2986 /* platform data */ 3206 /* platform data */
2987 state->pdata = *pdata; 3207 state->pdata = *pdata;
2988 state->timings = cea640x480; 3208 state->timings = cea640x480;
3209 state->format = adv7842_format_info(state, MEDIA_BUS_FMT_YUYV8_2X8);
2989 3210
2990 sd = &state->sd; 3211 sd = &state->sd;
2991 v4l2_i2c_subdev_init(sd, client, &adv7842_ops); 3212 v4l2_i2c_subdev_init(sd, client, &adv7842_ops);
diff --git a/drivers/media/i2c/ak881x.c b/drivers/media/i2c/ak881x.c
index 69aeaf397624..29846245aa3b 100644
--- a/drivers/media/i2c/ak881x.c
+++ b/drivers/media/i2c/ak881x.c
@@ -93,12 +93,17 @@ static int ak881x_s_register(struct v4l2_subdev *sd,
93} 93}
94#endif 94#endif
95 95
96static int ak881x_try_g_mbus_fmt(struct v4l2_subdev *sd, 96static int ak881x_fill_fmt(struct v4l2_subdev *sd,
97 struct v4l2_mbus_framefmt *mf) 97 struct v4l2_subdev_pad_config *cfg,
98 struct v4l2_subdev_format *format)
98{ 99{
100 struct v4l2_mbus_framefmt *mf = &format->format;
99 struct i2c_client *client = v4l2_get_subdevdata(sd); 101 struct i2c_client *client = v4l2_get_subdevdata(sd);
100 struct ak881x *ak881x = to_ak881x(client); 102 struct ak881x *ak881x = to_ak881x(client);
101 103
104 if (format->pad)
105 return -EINVAL;
106
102 v4l_bound_align_image(&mf->width, 0, 720, 2, 107 v4l_bound_align_image(&mf->width, 0, 720, 2,
103 &mf->height, 0, ak881x->lines, 1, 0); 108 &mf->height, 0, ak881x->lines, 1, 0);
104 mf->field = V4L2_FIELD_INTERLACED; 109 mf->field = V4L2_FIELD_INTERLACED;
@@ -108,23 +113,14 @@ static int ak881x_try_g_mbus_fmt(struct v4l2_subdev *sd,
108 return 0; 113 return 0;
109} 114}
110 115
111static int ak881x_s_mbus_fmt(struct v4l2_subdev *sd, 116static int ak881x_enum_mbus_code(struct v4l2_subdev *sd,
112 struct v4l2_mbus_framefmt *mf) 117 struct v4l2_subdev_pad_config *cfg,
118 struct v4l2_subdev_mbus_code_enum *code)
113{ 119{
114 if (mf->field != V4L2_FIELD_INTERLACED || 120 if (code->pad || code->index)
115 mf->code != MEDIA_BUS_FMT_YUYV8_2X8)
116 return -EINVAL; 121 return -EINVAL;
117 122
118 return ak881x_try_g_mbus_fmt(sd, mf); 123 code->code = MEDIA_BUS_FMT_YUYV8_2X8;
119}
120
121static int ak881x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index,
122 u32 *code)
123{
124 if (index)
125 return -EINVAL;
126
127 *code = MEDIA_BUS_FMT_YUYV8_2X8;
128 return 0; 124 return 0;
129} 125}
130 126
@@ -211,18 +207,21 @@ static struct v4l2_subdev_core_ops ak881x_subdev_core_ops = {
211}; 207};
212 208
213static struct v4l2_subdev_video_ops ak881x_subdev_video_ops = { 209static struct v4l2_subdev_video_ops ak881x_subdev_video_ops = {
214 .s_mbus_fmt = ak881x_s_mbus_fmt,
215 .g_mbus_fmt = ak881x_try_g_mbus_fmt,
216 .try_mbus_fmt = ak881x_try_g_mbus_fmt,
217 .cropcap = ak881x_cropcap, 210 .cropcap = ak881x_cropcap,
218 .enum_mbus_fmt = ak881x_enum_mbus_fmt,
219 .s_std_output = ak881x_s_std_output, 211 .s_std_output = ak881x_s_std_output,
220 .s_stream = ak881x_s_stream, 212 .s_stream = ak881x_s_stream,
221}; 213};
222 214
215static const struct v4l2_subdev_pad_ops ak881x_subdev_pad_ops = {
216 .enum_mbus_code = ak881x_enum_mbus_code,
217 .set_fmt = ak881x_fill_fmt,
218 .get_fmt = ak881x_fill_fmt,
219};
220
223static struct v4l2_subdev_ops ak881x_subdev_ops = { 221static struct v4l2_subdev_ops ak881x_subdev_ops = {
224 .core = &ak881x_subdev_core_ops, 222 .core = &ak881x_subdev_core_ops,
225 .video = &ak881x_subdev_video_ops, 223 .video = &ak881x_subdev_video_ops,
224 .pad = &ak881x_subdev_pad_ops,
226}; 225};
227 226
228static int ak881x_probe(struct i2c_client *client, 227static int ak881x_probe(struct i2c_client *client,
diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c
index bd496447749a..e15a789ad596 100644
--- a/drivers/media/i2c/cx25840/cx25840-core.c
+++ b/drivers/media/i2c/cx25840/cx25840-core.c
@@ -971,7 +971,7 @@ static void input_change(struct i2c_client *client)
971 not used by any public broadcast network, force 971 not used by any public broadcast network, force
972 6.5 MHz carrier to be interpreted as System DK, 972 6.5 MHz carrier to be interpreted as System DK,
973 this avoids DK audio detection instability */ 973 this avoids DK audio detection instability */
974 cx25840_write(client, 0x80b, 0x00); 974 cx25840_write(client, 0x80b, 0x00);
975 } else if (std & V4L2_STD_SECAM) { 975 } else if (std & V4L2_STD_SECAM) {
976 /* Autodetect audio standard and audio system */ 976 /* Autodetect audio standard and audio system */
977 cx25840_write(client, 0x808, 0xff); 977 cx25840_write(client, 0x808, 0xff);
@@ -1366,14 +1366,17 @@ static int cx25840_s_ctrl(struct v4l2_ctrl *ctrl)
1366 1366
1367/* ----------------------------------------------------------------------- */ 1367/* ----------------------------------------------------------------------- */
1368 1368
1369static int cx25840_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt) 1369static int cx25840_set_fmt(struct v4l2_subdev *sd,
1370 struct v4l2_subdev_pad_config *cfg,
1371 struct v4l2_subdev_format *format)
1370{ 1372{
1373 struct v4l2_mbus_framefmt *fmt = &format->format;
1371 struct cx25840_state *state = to_state(sd); 1374 struct cx25840_state *state = to_state(sd);
1372 struct i2c_client *client = v4l2_get_subdevdata(sd); 1375 struct i2c_client *client = v4l2_get_subdevdata(sd);
1373 int HSC, VSC, Vsrc, Hsrc, filter, Vlines; 1376 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
1374 int is_50Hz = !(state->std & V4L2_STD_525_60); 1377 int is_50Hz = !(state->std & V4L2_STD_525_60);
1375 1378
1376 if (fmt->code != MEDIA_BUS_FMT_FIXED) 1379 if (format->pad || fmt->code != MEDIA_BUS_FMT_FIXED)
1377 return -EINVAL; 1380 return -EINVAL;
1378 1381
1379 fmt->field = V4L2_FIELD_INTERLACED; 1382 fmt->field = V4L2_FIELD_INTERLACED;
@@ -1403,6 +1406,8 @@ static int cx25840_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt
1403 fmt->width, fmt->height); 1406 fmt->width, fmt->height);
1404 return -ERANGE; 1407 return -ERANGE;
1405 } 1408 }
1409 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
1410 return 0;
1406 1411
1407 HSC = (Hsrc * (1 << 20)) / fmt->width - (1 << 20); 1412 HSC = (Hsrc * (1 << 20)) / fmt->width - (1 << 20);
1408 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9)); 1413 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
@@ -5068,7 +5073,6 @@ static const struct v4l2_subdev_video_ops cx25840_video_ops = {
5068 .s_std = cx25840_s_std, 5073 .s_std = cx25840_s_std,
5069 .g_std = cx25840_g_std, 5074 .g_std = cx25840_g_std,
5070 .s_routing = cx25840_s_video_routing, 5075 .s_routing = cx25840_s_video_routing,
5071 .s_mbus_fmt = cx25840_s_mbus_fmt,
5072 .s_stream = cx25840_s_stream, 5076 .s_stream = cx25840_s_stream,
5073 .g_input_status = cx25840_g_input_status, 5077 .g_input_status = cx25840_g_input_status,
5074}; 5078};
@@ -5080,12 +5084,17 @@ static const struct v4l2_subdev_vbi_ops cx25840_vbi_ops = {
5080 .g_sliced_fmt = cx25840_g_sliced_fmt, 5084 .g_sliced_fmt = cx25840_g_sliced_fmt,
5081}; 5085};
5082 5086
5087static const struct v4l2_subdev_pad_ops cx25840_pad_ops = {
5088 .set_fmt = cx25840_set_fmt,
5089};
5090
5083static const struct v4l2_subdev_ops cx25840_ops = { 5091static const struct v4l2_subdev_ops cx25840_ops = {
5084 .core = &cx25840_core_ops, 5092 .core = &cx25840_core_ops,
5085 .tuner = &cx25840_tuner_ops, 5093 .tuner = &cx25840_tuner_ops,
5086 .audio = &cx25840_audio_ops, 5094 .audio = &cx25840_audio_ops,
5087 .video = &cx25840_video_ops, 5095 .video = &cx25840_video_ops,
5088 .vbi = &cx25840_vbi_ops, 5096 .vbi = &cx25840_vbi_ops,
5097 .pad = &cx25840_pad_ops,
5089 .ir = &cx25840_ir_ops, 5098 .ir = &cx25840_ir_ops,
5090}; 5099};
5091 5100
diff --git a/drivers/media/i2c/ml86v7667.c b/drivers/media/i2c/ml86v7667.c
index d7307862c2c5..af5eaf2db2a0 100644
--- a/drivers/media/i2c/ml86v7667.c
+++ b/drivers/media/i2c/ml86v7667.c
@@ -191,21 +191,27 @@ static int ml86v7667_g_input_status(struct v4l2_subdev *sd, u32 *status)
191 return 0; 191 return 0;
192} 192}
193 193
194static int ml86v7667_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index, 194static int ml86v7667_enum_mbus_code(struct v4l2_subdev *sd,
195 u32 *code) 195 struct v4l2_subdev_pad_config *cfg,
196 struct v4l2_subdev_mbus_code_enum *code)
196{ 197{
197 if (index > 0) 198 if (code->pad || code->index > 0)
198 return -EINVAL; 199 return -EINVAL;
199 200
200 *code = MEDIA_BUS_FMT_YUYV8_2X8; 201 code->code = MEDIA_BUS_FMT_YUYV8_2X8;
201 202
202 return 0; 203 return 0;
203} 204}
204 205
205static int ml86v7667_mbus_fmt(struct v4l2_subdev *sd, 206static int ml86v7667_fill_fmt(struct v4l2_subdev *sd,
206 struct v4l2_mbus_framefmt *fmt) 207 struct v4l2_subdev_pad_config *cfg,
208 struct v4l2_subdev_format *format)
207{ 209{
208 struct ml86v7667_priv *priv = to_ml86v7667(sd); 210 struct ml86v7667_priv *priv = to_ml86v7667(sd);
211 struct v4l2_mbus_framefmt *fmt = &format->format;
212
213 if (format->pad)
214 return -EINVAL;
209 215
210 fmt->code = MEDIA_BUS_FMT_YUYV8_2X8; 216 fmt->code = MEDIA_BUS_FMT_YUYV8_2X8;
211 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 217 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -279,13 +285,15 @@ static struct v4l2_subdev_video_ops ml86v7667_subdev_video_ops = {
279 .s_std = ml86v7667_s_std, 285 .s_std = ml86v7667_s_std,
280 .querystd = ml86v7667_querystd, 286 .querystd = ml86v7667_querystd,
281 .g_input_status = ml86v7667_g_input_status, 287 .g_input_status = ml86v7667_g_input_status,
282 .enum_mbus_fmt = ml86v7667_enum_mbus_fmt,
283 .try_mbus_fmt = ml86v7667_mbus_fmt,
284 .g_mbus_fmt = ml86v7667_mbus_fmt,
285 .s_mbus_fmt = ml86v7667_mbus_fmt,
286 .g_mbus_config = ml86v7667_g_mbus_config, 288 .g_mbus_config = ml86v7667_g_mbus_config,
287}; 289};
288 290
291static const struct v4l2_subdev_pad_ops ml86v7667_subdev_pad_ops = {
292 .enum_mbus_code = ml86v7667_enum_mbus_code,
293 .get_fmt = ml86v7667_fill_fmt,
294 .set_fmt = ml86v7667_fill_fmt,
295};
296
289static struct v4l2_subdev_core_ops ml86v7667_subdev_core_ops = { 297static struct v4l2_subdev_core_ops ml86v7667_subdev_core_ops = {
290#ifdef CONFIG_VIDEO_ADV_DEBUG 298#ifdef CONFIG_VIDEO_ADV_DEBUG
291 .g_register = ml86v7667_g_register, 299 .g_register = ml86v7667_g_register,
@@ -296,6 +304,7 @@ static struct v4l2_subdev_core_ops ml86v7667_subdev_core_ops = {
296static struct v4l2_subdev_ops ml86v7667_subdev_ops = { 304static struct v4l2_subdev_ops ml86v7667_subdev_ops = {
297 .core = &ml86v7667_subdev_core_ops, 305 .core = &ml86v7667_subdev_core_ops,
298 .video = &ml86v7667_subdev_video_ops, 306 .video = &ml86v7667_subdev_video_ops,
307 .pad = &ml86v7667_subdev_pad_ops,
299}; 308};
300 309
301static int ml86v7667_init(struct ml86v7667_priv *priv) 310static int ml86v7667_init(struct ml86v7667_priv *priv)
diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
index a10f7f8f0558..57132cdba5ea 100644
--- a/drivers/media/i2c/mt9v011.c
+++ b/drivers/media/i2c/mt9v011.c
@@ -324,19 +324,25 @@ static int mt9v011_reset(struct v4l2_subdev *sd, u32 val)
324 return 0; 324 return 0;
325} 325}
326 326
327static int mt9v011_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index, 327static int mt9v011_enum_mbus_code(struct v4l2_subdev *sd,
328 u32 *code) 328 struct v4l2_subdev_pad_config *cfg,
329 struct v4l2_subdev_mbus_code_enum *code)
329{ 330{
330 if (index > 0) 331 if (code->pad || code->index > 0)
331 return -EINVAL; 332 return -EINVAL;
332 333
333 *code = MEDIA_BUS_FMT_SGRBG8_1X8; 334 code->code = MEDIA_BUS_FMT_SGRBG8_1X8;
334 return 0; 335 return 0;
335} 336}
336 337
337static int mt9v011_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt) 338static int mt9v011_set_fmt(struct v4l2_subdev *sd,
339 struct v4l2_subdev_pad_config *cfg,
340 struct v4l2_subdev_format *format)
338{ 341{
339 if (fmt->code != MEDIA_BUS_FMT_SGRBG8_1X8) 342 struct v4l2_mbus_framefmt *fmt = &format->format;
343 struct mt9v011 *core = to_mt9v011(sd);
344
345 if (format->pad || fmt->code != MEDIA_BUS_FMT_SGRBG8_1X8)
340 return -EINVAL; 346 return -EINVAL;
341 347
342 v4l_bound_align_image(&fmt->width, 48, 639, 1, 348 v4l_bound_align_image(&fmt->width, 48, 639, 1,
@@ -344,6 +350,15 @@ static int mt9v011_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
344 fmt->field = V4L2_FIELD_NONE; 350 fmt->field = V4L2_FIELD_NONE;
345 fmt->colorspace = V4L2_COLORSPACE_SRGB; 351 fmt->colorspace = V4L2_COLORSPACE_SRGB;
346 352
353 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
354 core->width = fmt->width;
355 core->height = fmt->height;
356
357 set_res(sd);
358 } else {
359 cfg->try_fmt = *fmt;
360 }
361
347 return 0; 362 return 0;
348} 363}
349 364
@@ -385,23 +400,6 @@ static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
385 return 0; 400 return 0;
386} 401}
387 402
388static int mt9v011_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt)
389{
390 struct mt9v011 *core = to_mt9v011(sd);
391 int rc;
392
393 rc = mt9v011_try_mbus_fmt(sd, fmt);
394 if (rc < 0)
395 return -EINVAL;
396
397 core->width = fmt->width;
398 core->height = fmt->height;
399
400 set_res(sd);
401
402 return 0;
403}
404
405#ifdef CONFIG_VIDEO_ADV_DEBUG 403#ifdef CONFIG_VIDEO_ADV_DEBUG
406static int mt9v011_g_register(struct v4l2_subdev *sd, 404static int mt9v011_g_register(struct v4l2_subdev *sd,
407 struct v4l2_dbg_register *reg) 405 struct v4l2_dbg_register *reg)
@@ -469,16 +467,19 @@ static const struct v4l2_subdev_core_ops mt9v011_core_ops = {
469}; 467};
470 468
471static const struct v4l2_subdev_video_ops mt9v011_video_ops = { 469static const struct v4l2_subdev_video_ops mt9v011_video_ops = {
472 .enum_mbus_fmt = mt9v011_enum_mbus_fmt,
473 .try_mbus_fmt = mt9v011_try_mbus_fmt,
474 .s_mbus_fmt = mt9v011_s_mbus_fmt,
475 .g_parm = mt9v011_g_parm, 470 .g_parm = mt9v011_g_parm,
476 .s_parm = mt9v011_s_parm, 471 .s_parm = mt9v011_s_parm,
477}; 472};
478 473
474static const struct v4l2_subdev_pad_ops mt9v011_pad_ops = {
475 .enum_mbus_code = mt9v011_enum_mbus_code,
476 .set_fmt = mt9v011_set_fmt,
477};
478
479static const struct v4l2_subdev_ops mt9v011_ops = { 479static const struct v4l2_subdev_ops mt9v011_ops = {
480 .core = &mt9v011_core_ops, 480 .core = &mt9v011_core_ops,
481 .video = &mt9v011_video_ops, 481 .video = &mt9v011_video_ops,
482 .pad = &mt9v011_pad_ops,
482}; 483};
483 484
484 485
diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
index edebd114279d..6edffc7b74e3 100644
--- a/drivers/media/i2c/ov2659.c
+++ b/drivers/media/i2c/ov2659.c
@@ -1046,16 +1046,21 @@ static int ov2659_get_fmt(struct v4l2_subdev *sd,
1046{ 1046{
1047 struct i2c_client *client = v4l2_get_subdevdata(sd); 1047 struct i2c_client *client = v4l2_get_subdevdata(sd);
1048 struct ov2659 *ov2659 = to_ov2659(sd); 1048 struct ov2659 *ov2659 = to_ov2659(sd);
1049 struct v4l2_mbus_framefmt *mf;
1050 1049
1051 dev_dbg(&client->dev, "ov2659_get_fmt\n"); 1050 dev_dbg(&client->dev, "ov2659_get_fmt\n");
1052 1051
1053 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 1052 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1053#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1054 struct v4l2_mbus_framefmt *mf;
1055
1054 mf = v4l2_subdev_get_try_format(sd, cfg, 0); 1056 mf = v4l2_subdev_get_try_format(sd, cfg, 0);
1055 mutex_lock(&ov2659->lock); 1057 mutex_lock(&ov2659->lock);
1056 fmt->format = *mf; 1058 fmt->format = *mf;
1057 mutex_unlock(&ov2659->lock); 1059 mutex_unlock(&ov2659->lock);
1058 return 0; 1060 return 0;
1061#else
1062 return -ENOTTY;
1063#endif
1059 } 1064 }
1060 1065
1061 mutex_lock(&ov2659->lock); 1066 mutex_lock(&ov2659->lock);
@@ -1102,7 +1107,7 @@ static int ov2659_set_fmt(struct v4l2_subdev *sd,
1102 struct v4l2_subdev_format *fmt) 1107 struct v4l2_subdev_format *fmt)
1103{ 1108{
1104 struct i2c_client *client = v4l2_get_subdevdata(sd); 1109 struct i2c_client *client = v4l2_get_subdevdata(sd);
1105 unsigned int index = ARRAY_SIZE(ov2659_formats); 1110 int index = ARRAY_SIZE(ov2659_formats);
1106 struct v4l2_mbus_framefmt *mf = &fmt->format; 1111 struct v4l2_mbus_framefmt *mf = &fmt->format;
1107 const struct ov2659_framesize *size = NULL; 1112 const struct ov2659_framesize *size = NULL;
1108 struct ov2659 *ov2659 = to_ov2659(sd); 1113 struct ov2659 *ov2659 = to_ov2659(sd);
@@ -1126,8 +1131,12 @@ static int ov2659_set_fmt(struct v4l2_subdev *sd,
1126 mutex_lock(&ov2659->lock); 1131 mutex_lock(&ov2659->lock);
1127 1132
1128 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 1133 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1134#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1129 mf = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); 1135 mf = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
1130 *mf = fmt->format; 1136 *mf = fmt->format;
1137#else
1138 return -ENOTTY;
1139#endif
1131 } else { 1140 } else {
1132 s64 val; 1141 s64 val;
1133 1142
@@ -1257,6 +1266,7 @@ static const char * const ov2659_test_pattern_menu[] = {
1257 * V4L2 subdev internal operations 1266 * V4L2 subdev internal operations
1258 */ 1267 */
1259 1268
1269#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1260static int ov2659_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 1270static int ov2659_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1261{ 1271{
1262 struct i2c_client *client = v4l2_get_subdevdata(sd); 1272 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -1269,6 +1279,7 @@ static int ov2659_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1269 1279
1270 return 0; 1280 return 0;
1271} 1281}
1282#endif
1272 1283
1273static const struct v4l2_subdev_core_ops ov2659_subdev_core_ops = { 1284static const struct v4l2_subdev_core_ops ov2659_subdev_core_ops = {
1274 .log_status = v4l2_ctrl_subdev_log_status, 1285 .log_status = v4l2_ctrl_subdev_log_status,
@@ -1287,6 +1298,7 @@ static const struct v4l2_subdev_pad_ops ov2659_subdev_pad_ops = {
1287 .set_fmt = ov2659_set_fmt, 1298 .set_fmt = ov2659_set_fmt,
1288}; 1299};
1289 1300
1301#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1290static const struct v4l2_subdev_ops ov2659_subdev_ops = { 1302static const struct v4l2_subdev_ops ov2659_subdev_ops = {
1291 .core = &ov2659_subdev_core_ops, 1303 .core = &ov2659_subdev_core_ops,
1292 .video = &ov2659_subdev_video_ops, 1304 .video = &ov2659_subdev_video_ops,
@@ -1296,6 +1308,7 @@ static const struct v4l2_subdev_ops ov2659_subdev_ops = {
1296static const struct v4l2_subdev_internal_ops ov2659_subdev_internal_ops = { 1308static const struct v4l2_subdev_internal_ops ov2659_subdev_internal_ops = {
1297 .open = ov2659_open, 1309 .open = ov2659_open,
1298}; 1310};
1311#endif
1299 1312
1300static int ov2659_detect(struct v4l2_subdev *sd) 1313static int ov2659_detect(struct v4l2_subdev *sd)
1301{ 1314{
@@ -1340,8 +1353,8 @@ static struct ov2659_platform_data *
1340ov2659_get_pdata(struct i2c_client *client) 1353ov2659_get_pdata(struct i2c_client *client)
1341{ 1354{
1342 struct ov2659_platform_data *pdata; 1355 struct ov2659_platform_data *pdata;
1356 struct v4l2_of_endpoint *bus_cfg;
1343 struct device_node *endpoint; 1357 struct device_node *endpoint;
1344 int ret;
1345 1358
1346 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) 1359 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
1347 return client->dev.platform_data; 1360 return client->dev.platform_data;
@@ -1350,18 +1363,27 @@ ov2659_get_pdata(struct i2c_client *client)
1350 if (!endpoint) 1363 if (!endpoint)
1351 return NULL; 1364 return NULL;
1352 1365
1366 bus_cfg = v4l2_of_alloc_parse_endpoint(endpoint);
1367 if (IS_ERR(bus_cfg)) {
1368 pdata = NULL;
1369 goto done;
1370 }
1371
1353 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); 1372 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1354 if (!pdata) 1373 if (!pdata)
1355 goto done; 1374 goto done;
1356 1375
1357 ret = of_property_read_u64(endpoint, "link-frequencies", 1376 if (!bus_cfg->nr_of_link_frequencies) {
1358 &pdata->link_frequency); 1377 dev_err(&client->dev,
1359 if (ret) { 1378 "link-frequencies property not found or too many\n");
1360 dev_err(&client->dev, "link-frequencies property not found\n");
1361 pdata = NULL; 1379 pdata = NULL;
1380 goto done;
1362 } 1381 }
1363 1382
1383 pdata->link_frequency = bus_cfg->link_frequencies[0];
1384
1364done: 1385done:
1386 v4l2_of_free_endpoint(bus_cfg);
1365 of_node_put(endpoint); 1387 of_node_put(endpoint);
1366 return pdata; 1388 return pdata;
1367} 1389}
@@ -1417,11 +1439,13 @@ static int ov2659_probe(struct i2c_client *client,
1417 1439
1418 sd = &ov2659->sd; 1440 sd = &ov2659->sd;
1419 client->flags |= I2C_CLIENT_SCCB; 1441 client->flags |= I2C_CLIENT_SCCB;
1442#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1420 v4l2_i2c_subdev_init(sd, client, &ov2659_subdev_ops); 1443 v4l2_i2c_subdev_init(sd, client, &ov2659_subdev_ops);
1421 1444
1422 sd->internal_ops = &ov2659_subdev_internal_ops; 1445 sd->internal_ops = &ov2659_subdev_internal_ops;
1423 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | 1446 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
1424 V4L2_SUBDEV_FL_HAS_EVENTS; 1447 V4L2_SUBDEV_FL_HAS_EVENTS;
1448#endif
1425 1449
1426#if defined(CONFIG_MEDIA_CONTROLLER) 1450#if defined(CONFIG_MEDIA_CONTROLLER)
1427 ov2659->pad.flags = MEDIA_PAD_FL_SOURCE; 1451 ov2659->pad.flags = MEDIA_PAD_FL_SOURCE;
diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index b9847527eb5a..2d1e25f10973 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -639,7 +639,7 @@ static struct ov7670_format_struct {
639} ov7670_formats[] = { 639} ov7670_formats[] = {
640 { 640 {
641 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8, 641 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
642 .colorspace = V4L2_COLORSPACE_JPEG, 642 .colorspace = V4L2_COLORSPACE_SRGB,
643 .regs = ov7670_fmt_yuv422, 643 .regs = ov7670_fmt_yuv422,
644 .cmatrix = { 128, -128, 0, -34, -94, 128 }, 644 .cmatrix = { 128, -128, 0, -34, -94, 128 },
645 }, 645 },
@@ -899,13 +899,14 @@ static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop,
899} 899}
900 900
901 901
902static int ov7670_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index, 902static int ov7670_enum_mbus_code(struct v4l2_subdev *sd,
903 u32 *code) 903 struct v4l2_subdev_pad_config *cfg,
904 struct v4l2_subdev_mbus_code_enum *code)
904{ 905{
905 if (index >= N_OV7670_FMTS) 906 if (code->pad || code->index >= N_OV7670_FMTS)
906 return -EINVAL; 907 return -EINVAL;
907 908
908 *code = ov7670_formats[index].mbus_code; 909 code->code = ov7670_formats[code->index].mbus_code;
909 return 0; 910 return 0;
910} 911}
911 912
@@ -970,17 +971,12 @@ static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
970 return 0; 971 return 0;
971} 972}
972 973
973static int ov7670_try_mbus_fmt(struct v4l2_subdev *sd,
974 struct v4l2_mbus_framefmt *fmt)
975{
976 return ov7670_try_fmt_internal(sd, fmt, NULL, NULL);
977}
978
979/* 974/*
980 * Set a format. 975 * Set a format.
981 */ 976 */
982static int ov7670_s_mbus_fmt(struct v4l2_subdev *sd, 977static int ov7670_set_fmt(struct v4l2_subdev *sd,
983 struct v4l2_mbus_framefmt *fmt) 978 struct v4l2_subdev_pad_config *cfg,
979 struct v4l2_subdev_format *format)
984{ 980{
985 struct ov7670_format_struct *ovfmt; 981 struct ov7670_format_struct *ovfmt;
986 struct ov7670_win_size *wsize; 982 struct ov7670_win_size *wsize;
@@ -988,7 +984,18 @@ static int ov7670_s_mbus_fmt(struct v4l2_subdev *sd,
988 unsigned char com7; 984 unsigned char com7;
989 int ret; 985 int ret;
990 986
991 ret = ov7670_try_fmt_internal(sd, fmt, &ovfmt, &wsize); 987 if (format->pad)
988 return -EINVAL;
989
990 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
991 ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL);
992 if (ret)
993 return ret;
994 cfg->try_fmt = format->format;
995 return 0;
996 }
997
998 ret = ov7670_try_fmt_internal(sd, &format->format, &ovfmt, &wsize);
992 999
993 if (ret) 1000 if (ret)
994 return ret; 1001 return ret;
@@ -1073,10 +1080,33 @@ static int ov7670_enum_frame_interval(struct v4l2_subdev *sd,
1073 struct v4l2_subdev_pad_config *cfg, 1080 struct v4l2_subdev_pad_config *cfg,
1074 struct v4l2_subdev_frame_interval_enum *fie) 1081 struct v4l2_subdev_frame_interval_enum *fie)
1075{ 1082{
1083 struct ov7670_info *info = to_state(sd);
1084 unsigned int n_win_sizes = info->devtype->n_win_sizes;
1085 int i;
1086
1076 if (fie->pad) 1087 if (fie->pad)
1077 return -EINVAL; 1088 return -EINVAL;
1078 if (fie->index >= ARRAY_SIZE(ov7670_frame_rates)) 1089 if (fie->index >= ARRAY_SIZE(ov7670_frame_rates))
1079 return -EINVAL; 1090 return -EINVAL;
1091
1092 /*
1093 * Check if the width/height is valid.
1094 *
1095 * If a minimum width/height was requested, filter out the capture
1096 * windows that fall outside that.
1097 */
1098 for (i = 0; i < n_win_sizes; i++) {
1099 struct ov7670_win_size *win = &info->devtype->win_sizes[i];
1100
1101 if (info->min_width && win->width < info->min_width)
1102 continue;
1103 if (info->min_height && win->height < info->min_height)
1104 continue;
1105 if (fie->width == win->width && fie->height == win->height)
1106 break;
1107 }
1108 if (i == n_win_sizes)
1109 return -EINVAL;
1080 fie->interval.numerator = 1; 1110 fie->interval.numerator = 1;
1081 fie->interval.denominator = ov7670_frame_rates[fie->index]; 1111 fie->interval.denominator = ov7670_frame_rates[fie->index];
1082 return 0; 1112 return 0;
@@ -1362,7 +1392,7 @@ static int ov7670_s_exp(struct v4l2_subdev *sd, int value)
1362 unsigned char com1, com8, aech, aechh; 1392 unsigned char com1, com8, aech, aechh;
1363 1393
1364 ret = ov7670_read(sd, REG_COM1, &com1) + 1394 ret = ov7670_read(sd, REG_COM1, &com1) +
1365 ov7670_read(sd, REG_COM8, &com8); 1395 ov7670_read(sd, REG_COM8, &com8) +
1366 ov7670_read(sd, REG_AECHH, &aechh); 1396 ov7670_read(sd, REG_AECHH, &aechh);
1367 if (ret) 1397 if (ret)
1368 return ret; 1398 return ret;
@@ -1485,9 +1515,6 @@ static const struct v4l2_subdev_core_ops ov7670_core_ops = {
1485}; 1515};
1486 1516
1487static const struct v4l2_subdev_video_ops ov7670_video_ops = { 1517static const struct v4l2_subdev_video_ops ov7670_video_ops = {
1488 .enum_mbus_fmt = ov7670_enum_mbus_fmt,
1489 .try_mbus_fmt = ov7670_try_mbus_fmt,
1490 .s_mbus_fmt = ov7670_s_mbus_fmt,
1491 .s_parm = ov7670_s_parm, 1518 .s_parm = ov7670_s_parm,
1492 .g_parm = ov7670_g_parm, 1519 .g_parm = ov7670_g_parm,
1493}; 1520};
@@ -1495,6 +1522,8 @@ static const struct v4l2_subdev_video_ops ov7670_video_ops = {
1495static const struct v4l2_subdev_pad_ops ov7670_pad_ops = { 1522static const struct v4l2_subdev_pad_ops ov7670_pad_ops = {
1496 .enum_frame_interval = ov7670_enum_frame_interval, 1523 .enum_frame_interval = ov7670_enum_frame_interval,
1497 .enum_frame_size = ov7670_enum_frame_size, 1524 .enum_frame_size = ov7670_enum_frame_size,
1525 .enum_mbus_code = ov7670_enum_mbus_code,
1526 .set_fmt = ov7670_set_fmt,
1498}; 1527};
1499 1528
1500static const struct v4l2_subdev_ops ov7670_ops = { 1529static const struct v4l2_subdev_ops ov7670_ops = {
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 08b234bd2962..53c5ea89f0b9 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1453,7 +1453,7 @@ static int s5c73m3_oif_set_power(struct v4l2_subdev *sd, int on)
1453 state->apply_fiv = 1; 1453 state->apply_fiv = 1;
1454 state->apply_fmt = 1; 1454 state->apply_fmt = 1;
1455 } 1455 }
1456 } else if (!on == state->power) { 1456 } else if (state->power == !on) {
1457 ret = s5c73m3_set_af_softlanding(state); 1457 ret = s5c73m3_set_af_softlanding(state);
1458 if (!ret) 1458 if (!ret)
1459 ret = __s5c73m3_power_off(state); 1459 ret = __s5c73m3_power_off(state);
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 297ef04e146a..774e0d0c94cb 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -491,7 +491,7 @@ static void s5k5baf_write_arr_seq(struct s5k5baf *state, u16 addr,
491 v4l2_dbg(3, debug, c, "i2c_write_seq(count=%d): %*ph\n", count, 491 v4l2_dbg(3, debug, c, "i2c_write_seq(count=%d): %*ph\n", count,
492 min(2 * count, 64), seq); 492 min(2 * count, 64), seq);
493 493
494 buf[0] = __constant_cpu_to_be16(REG_CMD_BUF); 494 buf[0] = cpu_to_be16(REG_CMD_BUF);
495 495
496 while (count > 0) { 496 while (count > 0) {
497 int n = min_t(int, count, ARRAY_SIZE(buf) - 1); 497 int n = min_t(int, count, ARRAY_SIZE(buf) - 1);
@@ -1054,7 +1054,7 @@ static int s5k5baf_set_power(struct v4l2_subdev *sd, int on)
1054 1054
1055 mutex_lock(&state->lock); 1055 mutex_lock(&state->lock);
1056 1056
1057 if (!on != state->power) 1057 if (state->power != !on)
1058 goto out; 1058 goto out;
1059 1059
1060 if (on) { 1060 if (on) {
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index de803a11efb4..d0ad6a25bdab 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -875,7 +875,7 @@ static int s5k6aa_set_power(struct v4l2_subdev *sd, int on)
875 875
876 mutex_lock(&s5k6aa->lock); 876 mutex_lock(&s5k6aa->lock);
877 877
878 if (!on == s5k6aa->power) { 878 if (s5k6aa->power == !on) {
879 if (on) { 879 if (on) {
880 ret = __s5k6aa_power_on(s5k6aa); 880 ret = __s5k6aa_power_on(s5k6aa);
881 if (!ret) 881 if (!ret)
diff --git a/drivers/media/i2c/saa6752hs.c b/drivers/media/i2c/saa6752hs.c
index f14c0e6435a3..ba3c4156644d 100644
--- a/drivers/media/i2c/saa6752hs.c
+++ b/drivers/media/i2c/saa6752hs.c
@@ -554,10 +554,16 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
554 return 0; 554 return 0;
555} 555}
556 556
557static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) 557static int saa6752hs_get_fmt(struct v4l2_subdev *sd,
558 struct v4l2_subdev_pad_config *cfg,
559 struct v4l2_subdev_format *format)
558{ 560{
561 struct v4l2_mbus_framefmt *f = &format->format;
559 struct saa6752hs_state *h = to_state(sd); 562 struct saa6752hs_state *h = to_state(sd);
560 563
564 if (format->pad)
565 return -EINVAL;
566
561 if (h->video_format == SAA6752HS_VF_UNKNOWN) 567 if (h->video_format == SAA6752HS_VF_UNKNOWN)
562 h->video_format = SAA6752HS_VF_D1; 568 h->video_format = SAA6752HS_VF_D1;
563 f->width = v4l2_format_table[h->video_format].fmt.pix.width; 569 f->width = v4l2_format_table[h->video_format].fmt.pix.width;
@@ -568,10 +574,17 @@ static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
568 return 0; 574 return 0;
569} 575}
570 576
571static int saa6752hs_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) 577static int saa6752hs_set_fmt(struct v4l2_subdev *sd,
578 struct v4l2_subdev_pad_config *cfg,
579 struct v4l2_subdev_format *format)
572{ 580{
581 struct v4l2_mbus_framefmt *f = &format->format;
582 struct saa6752hs_state *h = to_state(sd);
573 int dist_352, dist_480, dist_720; 583 int dist_352, dist_480, dist_720;
574 584
585 if (format->pad)
586 return -EINVAL;
587
575 f->code = MEDIA_BUS_FMT_FIXED; 588 f->code = MEDIA_BUS_FMT_FIXED;
576 589
577 dist_352 = abs(f->width - 352); 590 dist_352 = abs(f->width - 352);
@@ -592,15 +605,11 @@ static int saa6752hs_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_frame
592 } 605 }
593 f->field = V4L2_FIELD_INTERLACED; 606 f->field = V4L2_FIELD_INTERLACED;
594 f->colorspace = V4L2_COLORSPACE_SMPTE170M; 607 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
595 return 0;
596}
597
598static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
599{
600 struct saa6752hs_state *h = to_state(sd);
601 608
602 if (f->code != MEDIA_BUS_FMT_FIXED) 609 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
603 return -EINVAL; 610 cfg->try_fmt = *f;
611 return 0;
612 }
604 613
605 /* 614 /*
606 FIXME: translate and round width/height into EMPRESS 615 FIXME: translate and round width/height into EMPRESS
@@ -614,7 +623,9 @@ static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
614 D1 | 720x576 | 720x480 623 D1 | 720x576 | 720x480
615 */ 624 */
616 625
617 saa6752hs_try_mbus_fmt(sd, f); 626 if (f->code != MEDIA_BUS_FMT_FIXED)
627 return -EINVAL;
628
618 if (f->width == 720) 629 if (f->width == 720)
619 h->video_format = SAA6752HS_VF_D1; 630 h->video_format = SAA6752HS_VF_D1;
620 else if (f->width == 480) 631 else if (f->width == 480)
@@ -647,14 +658,17 @@ static const struct v4l2_subdev_core_ops saa6752hs_core_ops = {
647 658
648static const struct v4l2_subdev_video_ops saa6752hs_video_ops = { 659static const struct v4l2_subdev_video_ops saa6752hs_video_ops = {
649 .s_std = saa6752hs_s_std, 660 .s_std = saa6752hs_s_std,
650 .s_mbus_fmt = saa6752hs_s_mbus_fmt, 661};
651 .try_mbus_fmt = saa6752hs_try_mbus_fmt, 662
652 .g_mbus_fmt = saa6752hs_g_mbus_fmt, 663static const struct v4l2_subdev_pad_ops saa6752hs_pad_ops = {
664 .get_fmt = saa6752hs_get_fmt,
665 .set_fmt = saa6752hs_set_fmt,
653}; 666};
654 667
655static const struct v4l2_subdev_ops saa6752hs_ops = { 668static const struct v4l2_subdev_ops saa6752hs_ops = {
656 .core = &saa6752hs_core_ops, 669 .core = &saa6752hs_core_ops,
657 .video = &saa6752hs_video_ops, 670 .video = &saa6752hs_video_ops,
671 .pad = &saa6752hs_pad_ops,
658}; 672};
659 673
660static int saa6752hs_probe(struct i2c_client *client, 674static int saa6752hs_probe(struct i2c_client *client,
diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c
index 7147c8b68fac..0eae5f4471e2 100644
--- a/drivers/media/i2c/saa7115.c
+++ b/drivers/media/i2c/saa7115.c
@@ -1170,12 +1170,18 @@ static int saa711x_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_f
1170 return 0; 1170 return 0;
1171} 1171}
1172 1172
1173static int saa711x_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt) 1173static int saa711x_set_fmt(struct v4l2_subdev *sd,
1174 struct v4l2_subdev_pad_config *cfg,
1175 struct v4l2_subdev_format *format)
1174{ 1176{
1175 if (fmt->code != MEDIA_BUS_FMT_FIXED) 1177 struct v4l2_mbus_framefmt *fmt = &format->format;
1178
1179 if (format->pad || fmt->code != MEDIA_BUS_FMT_FIXED)
1176 return -EINVAL; 1180 return -EINVAL;
1177 fmt->field = V4L2_FIELD_INTERLACED; 1181 fmt->field = V4L2_FIELD_INTERLACED;
1178 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 1182 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
1183 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
1184 return 0;
1179 return saa711x_set_size(sd, fmt->width, fmt->height); 1185 return saa711x_set_size(sd, fmt->width, fmt->height);
1180} 1186}
1181 1187
@@ -1603,7 +1609,6 @@ static const struct v4l2_subdev_video_ops saa711x_video_ops = {
1603 .s_std = saa711x_s_std, 1609 .s_std = saa711x_s_std,
1604 .s_routing = saa711x_s_routing, 1610 .s_routing = saa711x_s_routing,
1605 .s_crystal_freq = saa711x_s_crystal_freq, 1611 .s_crystal_freq = saa711x_s_crystal_freq,
1606 .s_mbus_fmt = saa711x_s_mbus_fmt,
1607 .s_stream = saa711x_s_stream, 1612 .s_stream = saa711x_s_stream,
1608 .querystd = saa711x_querystd, 1613 .querystd = saa711x_querystd,
1609 .g_input_status = saa711x_g_input_status, 1614 .g_input_status = saa711x_g_input_status,
@@ -1617,12 +1622,17 @@ static const struct v4l2_subdev_vbi_ops saa711x_vbi_ops = {
1617 .s_raw_fmt = saa711x_s_raw_fmt, 1622 .s_raw_fmt = saa711x_s_raw_fmt,
1618}; 1623};
1619 1624
1625static const struct v4l2_subdev_pad_ops saa711x_pad_ops = {
1626 .set_fmt = saa711x_set_fmt,
1627};
1628
1620static const struct v4l2_subdev_ops saa711x_ops = { 1629static const struct v4l2_subdev_ops saa711x_ops = {
1621 .core = &saa711x_core_ops, 1630 .core = &saa711x_core_ops,
1622 .tuner = &saa711x_tuner_ops, 1631 .tuner = &saa711x_tuner_ops,
1623 .audio = &saa711x_audio_ops, 1632 .audio = &saa711x_audio_ops,
1624 .video = &saa711x_video_ops, 1633 .video = &saa711x_video_ops,
1625 .vbi = &saa711x_vbi_ops, 1634 .vbi = &saa711x_vbi_ops,
1635 .pad = &saa711x_pad_ops,
1626}; 1636};
1627 1637
1628#define CHIP_VER_SIZE 16 1638#define CHIP_VER_SIZE 16
diff --git a/drivers/media/i2c/saa717x.c b/drivers/media/i2c/saa717x.c
index 0d0f9a917cd3..7d517361e419 100644
--- a/drivers/media/i2c/saa717x.c
+++ b/drivers/media/i2c/saa717x.c
@@ -152,9 +152,9 @@ static u32 saa717x_read(struct v4l2_subdev *sd, u32 reg)
152 i2c_transfer(adap, msgs, 2); 152 i2c_transfer(adap, msgs, 2);
153 153
154 if (fw_addr) 154 if (fw_addr)
155 value = (mm2[2] & 0xff) | ((mm2[1] & 0xff) >> 8) | ((mm2[0] & 0xff) >> 16); 155 value = (mm2[2] << 16) | (mm2[1] << 8) | mm2[0];
156 else 156 else
157 value = mm2[0] & 0xff; 157 value = mm2[0];
158 158
159 v4l2_dbg(2, debug, sd, "read: reg 0x%03x=0x%08x\n", reg, value); 159 v4l2_dbg(2, debug, sd, "read: reg 0x%03x=0x%08x\n", reg, value);
160 return value; 160 return value;
@@ -992,13 +992,16 @@ static int saa717x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regi
992} 992}
993#endif 993#endif
994 994
995static int saa717x_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt) 995static int saa717x_set_fmt(struct v4l2_subdev *sd,
996 struct v4l2_subdev_pad_config *cfg,
997 struct v4l2_subdev_format *format)
996{ 998{
999 struct v4l2_mbus_framefmt *fmt = &format->format;
997 int prescale, h_scale, v_scale; 1000 int prescale, h_scale, v_scale;
998 1001
999 v4l2_dbg(1, debug, sd, "decoder set size\n"); 1002 v4l2_dbg(1, debug, sd, "decoder set size\n");
1000 1003
1001 if (fmt->code != MEDIA_BUS_FMT_FIXED) 1004 if (format->pad || fmt->code != MEDIA_BUS_FMT_FIXED)
1002 return -EINVAL; 1005 return -EINVAL;
1003 1006
1004 /* FIXME need better bounds checking here */ 1007 /* FIXME need better bounds checking here */
@@ -1010,6 +1013,9 @@ static int saa717x_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt
1010 fmt->field = V4L2_FIELD_INTERLACED; 1013 fmt->field = V4L2_FIELD_INTERLACED;
1011 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 1014 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
1012 1015
1016 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
1017 return 0;
1018
1013 /* scaling setting */ 1019 /* scaling setting */
1014 /* NTSC and interlace only */ 1020 /* NTSC and interlace only */
1015 prescale = SAA717X_NTSC_WIDTH / fmt->width; 1021 prescale = SAA717X_NTSC_WIDTH / fmt->width;
@@ -1217,7 +1223,6 @@ static const struct v4l2_subdev_tuner_ops saa717x_tuner_ops = {
1217static const struct v4l2_subdev_video_ops saa717x_video_ops = { 1223static const struct v4l2_subdev_video_ops saa717x_video_ops = {
1218 .s_std = saa717x_s_std, 1224 .s_std = saa717x_s_std,
1219 .s_routing = saa717x_s_video_routing, 1225 .s_routing = saa717x_s_video_routing,
1220 .s_mbus_fmt = saa717x_s_mbus_fmt,
1221 .s_stream = saa717x_s_stream, 1226 .s_stream = saa717x_s_stream,
1222}; 1227};
1223 1228
@@ -1225,11 +1230,16 @@ static const struct v4l2_subdev_audio_ops saa717x_audio_ops = {
1225 .s_routing = saa717x_s_audio_routing, 1230 .s_routing = saa717x_s_audio_routing,
1226}; 1231};
1227 1232
1233static const struct v4l2_subdev_pad_ops saa717x_pad_ops = {
1234 .set_fmt = saa717x_set_fmt,
1235};
1236
1228static const struct v4l2_subdev_ops saa717x_ops = { 1237static const struct v4l2_subdev_ops saa717x_ops = {
1229 .core = &saa717x_core_ops, 1238 .core = &saa717x_core_ops,
1230 .tuner = &saa717x_tuner_ops, 1239 .tuner = &saa717x_tuner_ops,
1231 .audio = &saa717x_audio_ops, 1240 .audio = &saa717x_audio_ops,
1232 .video = &saa717x_video_ops, 1241 .video = &saa717x_video_ops,
1242 .pad = &saa717x_pad_ops,
1233}; 1243};
1234 1244
1235/* ----------------------------------------------------------------------- */ 1245/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 557f25def3a0..636ebd6fe5dc 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2975,9 +2975,9 @@ static int smiapp_resume(struct device *dev)
2975static struct smiapp_platform_data *smiapp_get_pdata(struct device *dev) 2975static struct smiapp_platform_data *smiapp_get_pdata(struct device *dev)
2976{ 2976{
2977 struct smiapp_platform_data *pdata; 2977 struct smiapp_platform_data *pdata;
2978 struct v4l2_of_endpoint bus_cfg; 2978 struct v4l2_of_endpoint *bus_cfg;
2979 struct device_node *ep; 2979 struct device_node *ep;
2980 uint32_t asize; 2980 int i;
2981 int rval; 2981 int rval;
2982 2982
2983 if (!dev->of_node) 2983 if (!dev->of_node)
@@ -2987,13 +2987,15 @@ static struct smiapp_platform_data *smiapp_get_pdata(struct device *dev)
2987 if (!ep) 2987 if (!ep)
2988 return NULL; 2988 return NULL;
2989 2989
2990 bus_cfg = v4l2_of_alloc_parse_endpoint(ep);
2991 if (IS_ERR(bus_cfg))
2992 goto out_err;
2993
2990 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 2994 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2991 if (!pdata) 2995 if (!pdata)
2992 goto out_err; 2996 goto out_err;
2993 2997
2994 v4l2_of_parse_endpoint(ep, &bus_cfg); 2998 switch (bus_cfg->bus_type) {
2995
2996 switch (bus_cfg.bus_type) {
2997 case V4L2_MBUS_CSI2: 2999 case V4L2_MBUS_CSI2:
2998 pdata->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2; 3000 pdata->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2;
2999 break; 3001 break;
@@ -3002,7 +3004,7 @@ static struct smiapp_platform_data *smiapp_get_pdata(struct device *dev)
3002 goto out_err; 3004 goto out_err;
3003 } 3005 }
3004 3006
3005 pdata->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes; 3007 pdata->lanes = bus_cfg->bus.mipi_csi2.num_data_lanes;
3006 dev_dbg(dev, "lanes %u\n", pdata->lanes); 3008 dev_dbg(dev, "lanes %u\n", pdata->lanes);
3007 3009
3008 /* xshutdown GPIO is optional */ 3010 /* xshutdown GPIO is optional */
@@ -3022,34 +3024,30 @@ static struct smiapp_platform_data *smiapp_get_pdata(struct device *dev)
3022 dev_dbg(dev, "reset %d, nvm %d, clk %d, csi %d\n", pdata->xshutdown, 3024 dev_dbg(dev, "reset %d, nvm %d, clk %d, csi %d\n", pdata->xshutdown,
3023 pdata->nvm_size, pdata->ext_clk, pdata->csi_signalling_mode); 3025 pdata->nvm_size, pdata->ext_clk, pdata->csi_signalling_mode);
3024 3026
3025 rval = of_get_property(ep, "link-frequencies", &asize) ? 0 : -ENOENT; 3027 if (!bus_cfg->nr_of_link_frequencies) {
3026 if (rval) { 3028 dev_warn(dev, "no link frequencies defined\n");
3027 dev_warn(dev, "can't get link-frequencies array size\n");
3028 goto out_err; 3029 goto out_err;
3029 } 3030 }
3030 3031
3031 pdata->op_sys_clock = devm_kzalloc(dev, asize, GFP_KERNEL); 3032 pdata->op_sys_clock = devm_kcalloc(
3033 dev, bus_cfg->nr_of_link_frequencies + 1 /* guardian */,
3034 sizeof(*pdata->op_sys_clock), GFP_KERNEL);
3032 if (!pdata->op_sys_clock) { 3035 if (!pdata->op_sys_clock) {
3033 rval = -ENOMEM; 3036 rval = -ENOMEM;
3034 goto out_err; 3037 goto out_err;
3035 } 3038 }
3036 3039
3037 asize /= sizeof(*pdata->op_sys_clock); 3040 for (i = 0; i < bus_cfg->nr_of_link_frequencies; i++) {
3038 rval = of_property_read_u64_array( 3041 pdata->op_sys_clock[i] = bus_cfg->link_frequencies[i];
3039 ep, "link-frequencies", pdata->op_sys_clock, asize); 3042 dev_dbg(dev, "freq %d: %lld\n", i, pdata->op_sys_clock[i]);
3040 if (rval) {
3041 dev_warn(dev, "can't get link-frequencies\n");
3042 goto out_err;
3043 } 3043 }
3044 3044
3045 for (; asize > 0; asize--) 3045 v4l2_of_free_endpoint(bus_cfg);
3046 dev_dbg(dev, "freq %d: %lld\n", asize - 1,
3047 pdata->op_sys_clock[asize - 1]);
3048
3049 of_node_put(ep); 3046 of_node_put(ep);
3050 return pdata; 3047 return pdata;
3051 3048
3052out_err: 3049out_err:
3050 v4l2_of_free_endpoint(bus_cfg);
3053 of_node_put(ep); 3051 of_node_put(ep);
3054 return NULL; 3052 return NULL;
3055} 3053}
diff --git a/drivers/media/i2c/soc_camera/imx074.c b/drivers/media/i2c/soc_camera/imx074.c
index ec89cfa927a2..f68c2352c63c 100644
--- a/drivers/media/i2c/soc_camera/imx074.c
+++ b/drivers/media/i2c/soc_camera/imx074.c
@@ -153,14 +153,24 @@ static int reg_read(struct i2c_client *client, const u16 addr)
153 return buf[0] & 0xff; /* no sign-extension */ 153 return buf[0] & 0xff; /* no sign-extension */
154} 154}
155 155
156static int imx074_try_fmt(struct v4l2_subdev *sd, 156static int imx074_set_fmt(struct v4l2_subdev *sd,
157 struct v4l2_mbus_framefmt *mf) 157 struct v4l2_subdev_pad_config *cfg,
158 struct v4l2_subdev_format *format)
158{ 159{
160 struct v4l2_mbus_framefmt *mf = &format->format;
159 const struct imx074_datafmt *fmt = imx074_find_datafmt(mf->code); 161 const struct imx074_datafmt *fmt = imx074_find_datafmt(mf->code);
162 struct i2c_client *client = v4l2_get_subdevdata(sd);
163 struct imx074 *priv = to_imx074(client);
164
165 if (format->pad)
166 return -EINVAL;
160 167
161 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code); 168 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
162 169
163 if (!fmt) { 170 if (!fmt) {
171 /* MIPI CSI could have changed the format, double-check */
172 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
173 return -EINVAL;
164 mf->code = imx074_colour_fmts[0].code; 174 mf->code = imx074_colour_fmts[0].code;
165 mf->colorspace = imx074_colour_fmts[0].colorspace; 175 mf->colorspace = imx074_colour_fmts[0].colorspace;
166 } 176 }
@@ -169,36 +179,27 @@ static int imx074_try_fmt(struct v4l2_subdev *sd,
169 mf->height = IMX074_HEIGHT; 179 mf->height = IMX074_HEIGHT;
170 mf->field = V4L2_FIELD_NONE; 180 mf->field = V4L2_FIELD_NONE;
171 181
172 return 0; 182 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
173} 183 priv->fmt = imx074_find_datafmt(mf->code);
174 184 else
175static int imx074_s_fmt(struct v4l2_subdev *sd, 185 cfg->try_fmt = *mf;
176 struct v4l2_mbus_framefmt *mf)
177{
178 struct i2c_client *client = v4l2_get_subdevdata(sd);
179 struct imx074 *priv = to_imx074(client);
180
181 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
182
183 /* MIPI CSI could have changed the format, double-check */
184 if (!imx074_find_datafmt(mf->code))
185 return -EINVAL;
186
187 imx074_try_fmt(sd, mf);
188
189 priv->fmt = imx074_find_datafmt(mf->code);
190 186
191 return 0; 187 return 0;
192} 188}
193 189
194static int imx074_g_fmt(struct v4l2_subdev *sd, 190static int imx074_get_fmt(struct v4l2_subdev *sd,
195 struct v4l2_mbus_framefmt *mf) 191 struct v4l2_subdev_pad_config *cfg,
192 struct v4l2_subdev_format *format)
196{ 193{
194 struct v4l2_mbus_framefmt *mf = &format->format;
197 struct i2c_client *client = v4l2_get_subdevdata(sd); 195 struct i2c_client *client = v4l2_get_subdevdata(sd);
198 struct imx074 *priv = to_imx074(client); 196 struct imx074 *priv = to_imx074(client);
199 197
200 const struct imx074_datafmt *fmt = priv->fmt; 198 const struct imx074_datafmt *fmt = priv->fmt;
201 199
200 if (format->pad)
201 return -EINVAL;
202
202 mf->code = fmt->code; 203 mf->code = fmt->code;
203 mf->colorspace = fmt->colorspace; 204 mf->colorspace = fmt->colorspace;
204 mf->width = IMX074_WIDTH; 205 mf->width = IMX074_WIDTH;
@@ -235,13 +236,15 @@ static int imx074_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
235 return 0; 236 return 0;
236} 237}
237 238
238static int imx074_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 239static int imx074_enum_mbus_code(struct v4l2_subdev *sd,
239 u32 *code) 240 struct v4l2_subdev_pad_config *cfg,
241 struct v4l2_subdev_mbus_code_enum *code)
240{ 242{
241 if ((unsigned int)index >= ARRAY_SIZE(imx074_colour_fmts)) 243 if (code->pad ||
244 (unsigned int)code->index >= ARRAY_SIZE(imx074_colour_fmts))
242 return -EINVAL; 245 return -EINVAL;
243 246
244 *code = imx074_colour_fmts[index].code; 247 code->code = imx074_colour_fmts[code->index].code;
245 return 0; 248 return 0;
246} 249}
247 250
@@ -275,10 +278,6 @@ static int imx074_g_mbus_config(struct v4l2_subdev *sd,
275 278
276static struct v4l2_subdev_video_ops imx074_subdev_video_ops = { 279static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
277 .s_stream = imx074_s_stream, 280 .s_stream = imx074_s_stream,
278 .s_mbus_fmt = imx074_s_fmt,
279 .g_mbus_fmt = imx074_g_fmt,
280 .try_mbus_fmt = imx074_try_fmt,
281 .enum_mbus_fmt = imx074_enum_fmt,
282 .g_crop = imx074_g_crop, 281 .g_crop = imx074_g_crop,
283 .cropcap = imx074_cropcap, 282 .cropcap = imx074_cropcap,
284 .g_mbus_config = imx074_g_mbus_config, 283 .g_mbus_config = imx074_g_mbus_config,
@@ -288,9 +287,16 @@ static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
288 .s_power = imx074_s_power, 287 .s_power = imx074_s_power,
289}; 288};
290 289
290static const struct v4l2_subdev_pad_ops imx074_subdev_pad_ops = {
291 .enum_mbus_code = imx074_enum_mbus_code,
292 .get_fmt = imx074_get_fmt,
293 .set_fmt = imx074_set_fmt,
294};
295
291static struct v4l2_subdev_ops imx074_subdev_ops = { 296static struct v4l2_subdev_ops imx074_subdev_ops = {
292 .core = &imx074_subdev_core_ops, 297 .core = &imx074_subdev_core_ops,
293 .video = &imx074_subdev_video_ops, 298 .video = &imx074_subdev_video_ops,
299 .pad = &imx074_subdev_pad_ops,
294}; 300};
295 301
296static int imx074_video_probe(struct i2c_client *client) 302static int imx074_video_probe(struct i2c_client *client)
diff --git a/drivers/media/i2c/soc_camera/mt9m001.c b/drivers/media/i2c/soc_camera/mt9m001.c
index 2e9a53502551..4fbdd1e9f7ee 100644
--- a/drivers/media/i2c/soc_camera/mt9m001.c
+++ b/drivers/media/i2c/soc_camera/mt9m001.c
@@ -205,7 +205,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
205 205
206 /* 206 /*
207 * The caller provides a supported format, as verified per 207 * The caller provides a supported format, as verified per
208 * call to .try_mbus_fmt() 208 * call to .set_fmt(FORMAT_TRY).
209 */ 209 */
210 if (!ret) 210 if (!ret)
211 ret = reg_write(client, MT9M001_COLUMN_START, rect.left); 211 ret = reg_write(client, MT9M001_COLUMN_START, rect.left);
@@ -250,11 +250,16 @@ static int mt9m001_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
250 return 0; 250 return 0;
251} 251}
252 252
253static int mt9m001_g_fmt(struct v4l2_subdev *sd, 253static int mt9m001_get_fmt(struct v4l2_subdev *sd,
254 struct v4l2_mbus_framefmt *mf) 254 struct v4l2_subdev_pad_config *cfg,
255 struct v4l2_subdev_format *format)
255{ 256{
256 struct i2c_client *client = v4l2_get_subdevdata(sd); 257 struct i2c_client *client = v4l2_get_subdevdata(sd);
257 struct mt9m001 *mt9m001 = to_mt9m001(client); 258 struct mt9m001 *mt9m001 = to_mt9m001(client);
259 struct v4l2_mbus_framefmt *mf = &format->format;
260
261 if (format->pad)
262 return -EINVAL;
258 263
259 mf->width = mt9m001->rect.width; 264 mf->width = mt9m001->rect.width;
260 mf->height = mt9m001->rect.height; 265 mf->height = mt9m001->rect.height;
@@ -293,13 +298,18 @@ static int mt9m001_s_fmt(struct v4l2_subdev *sd,
293 return ret; 298 return ret;
294} 299}
295 300
296static int mt9m001_try_fmt(struct v4l2_subdev *sd, 301static int mt9m001_set_fmt(struct v4l2_subdev *sd,
297 struct v4l2_mbus_framefmt *mf) 302 struct v4l2_subdev_pad_config *cfg,
303 struct v4l2_subdev_format *format)
298{ 304{
305 struct v4l2_mbus_framefmt *mf = &format->format;
299 struct i2c_client *client = v4l2_get_subdevdata(sd); 306 struct i2c_client *client = v4l2_get_subdevdata(sd);
300 struct mt9m001 *mt9m001 = to_mt9m001(client); 307 struct mt9m001 *mt9m001 = to_mt9m001(client);
301 const struct mt9m001_datafmt *fmt; 308 const struct mt9m001_datafmt *fmt;
302 309
310 if (format->pad)
311 return -EINVAL;
312
303 v4l_bound_align_image(&mf->width, MT9M001_MIN_WIDTH, 313 v4l_bound_align_image(&mf->width, MT9M001_MIN_WIDTH,
304 MT9M001_MAX_WIDTH, 1, 314 MT9M001_MAX_WIDTH, 1,
305 &mf->height, MT9M001_MIN_HEIGHT + mt9m001->y_skip_top, 315 &mf->height, MT9M001_MIN_HEIGHT + mt9m001->y_skip_top,
@@ -317,6 +327,9 @@ static int mt9m001_try_fmt(struct v4l2_subdev *sd,
317 327
318 mf->colorspace = fmt->colorspace; 328 mf->colorspace = fmt->colorspace;
319 329
330 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
331 return mt9m001_s_fmt(sd, mf);
332 cfg->try_fmt = *mf;
320 return 0; 333 return 0;
321} 334}
322 335
@@ -562,16 +575,17 @@ static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
562 .s_power = mt9m001_s_power, 575 .s_power = mt9m001_s_power,
563}; 576};
564 577
565static int mt9m001_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 578static int mt9m001_enum_mbus_code(struct v4l2_subdev *sd,
566 u32 *code) 579 struct v4l2_subdev_pad_config *cfg,
580 struct v4l2_subdev_mbus_code_enum *code)
567{ 581{
568 struct i2c_client *client = v4l2_get_subdevdata(sd); 582 struct i2c_client *client = v4l2_get_subdevdata(sd);
569 struct mt9m001 *mt9m001 = to_mt9m001(client); 583 struct mt9m001 *mt9m001 = to_mt9m001(client);
570 584
571 if (index >= mt9m001->num_fmts) 585 if (code->pad || code->index >= mt9m001->num_fmts)
572 return -EINVAL; 586 return -EINVAL;
573 587
574 *code = mt9m001->fmts[index].code; 588 code->code = mt9m001->fmts[code->index].code;
575 return 0; 589 return 0;
576} 590}
577 591
@@ -611,13 +625,9 @@ static int mt9m001_s_mbus_config(struct v4l2_subdev *sd,
611 625
612static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = { 626static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
613 .s_stream = mt9m001_s_stream, 627 .s_stream = mt9m001_s_stream,
614 .s_mbus_fmt = mt9m001_s_fmt,
615 .g_mbus_fmt = mt9m001_g_fmt,
616 .try_mbus_fmt = mt9m001_try_fmt,
617 .s_crop = mt9m001_s_crop, 628 .s_crop = mt9m001_s_crop,
618 .g_crop = mt9m001_g_crop, 629 .g_crop = mt9m001_g_crop,
619 .cropcap = mt9m001_cropcap, 630 .cropcap = mt9m001_cropcap,
620 .enum_mbus_fmt = mt9m001_enum_fmt,
621 .g_mbus_config = mt9m001_g_mbus_config, 631 .g_mbus_config = mt9m001_g_mbus_config,
622 .s_mbus_config = mt9m001_s_mbus_config, 632 .s_mbus_config = mt9m001_s_mbus_config,
623}; 633};
@@ -626,10 +636,17 @@ static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
626 .g_skip_top_lines = mt9m001_g_skip_top_lines, 636 .g_skip_top_lines = mt9m001_g_skip_top_lines,
627}; 637};
628 638
639static const struct v4l2_subdev_pad_ops mt9m001_subdev_pad_ops = {
640 .enum_mbus_code = mt9m001_enum_mbus_code,
641 .get_fmt = mt9m001_get_fmt,
642 .set_fmt = mt9m001_set_fmt,
643};
644
629static struct v4l2_subdev_ops mt9m001_subdev_ops = { 645static struct v4l2_subdev_ops mt9m001_subdev_ops = {
630 .core = &mt9m001_subdev_core_ops, 646 .core = &mt9m001_subdev_core_ops,
631 .video = &mt9m001_subdev_video_ops, 647 .video = &mt9m001_subdev_video_ops,
632 .sensor = &mt9m001_subdev_sensor_ops, 648 .sensor = &mt9m001_subdev_sensor_ops,
649 .pad = &mt9m001_subdev_pad_ops,
633}; 650};
634 651
635static int mt9m001_probe(struct i2c_client *client, 652static int mt9m001_probe(struct i2c_client *client,
diff --git a/drivers/media/i2c/soc_camera/mt9m111.c b/drivers/media/i2c/soc_camera/mt9m111.c
index 441e0fda24fe..6dfaead6aaa8 100644
--- a/drivers/media/i2c/soc_camera/mt9m111.c
+++ b/drivers/media/i2c/soc_camera/mt9m111.c
@@ -447,11 +447,16 @@ static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
447 return 0; 447 return 0;
448} 448}
449 449
450static int mt9m111_g_fmt(struct v4l2_subdev *sd, 450static int mt9m111_get_fmt(struct v4l2_subdev *sd,
451 struct v4l2_mbus_framefmt *mf) 451 struct v4l2_subdev_pad_config *cfg,
452 struct v4l2_subdev_format *format)
452{ 453{
454 struct v4l2_mbus_framefmt *mf = &format->format;
453 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); 455 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
454 456
457 if (format->pad)
458 return -EINVAL;
459
455 mf->width = mt9m111->width; 460 mf->width = mt9m111->width;
456 mf->height = mt9m111->height; 461 mf->height = mt9m111->height;
457 mf->code = mt9m111->fmt->code; 462 mf->code = mt9m111->fmt->code;
@@ -531,14 +536,20 @@ static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111,
531 return ret; 536 return ret;
532} 537}
533 538
534static int mt9m111_try_fmt(struct v4l2_subdev *sd, 539static int mt9m111_set_fmt(struct v4l2_subdev *sd,
535 struct v4l2_mbus_framefmt *mf) 540 struct v4l2_subdev_pad_config *cfg,
541 struct v4l2_subdev_format *format)
536{ 542{
543 struct v4l2_mbus_framefmt *mf = &format->format;
537 struct i2c_client *client = v4l2_get_subdevdata(sd); 544 struct i2c_client *client = v4l2_get_subdevdata(sd);
538 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); 545 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
539 const struct mt9m111_datafmt *fmt; 546 const struct mt9m111_datafmt *fmt;
540 struct v4l2_rect *rect = &mt9m111->rect; 547 struct v4l2_rect *rect = &mt9m111->rect;
541 bool bayer; 548 bool bayer;
549 int ret;
550
551 if (format->pad)
552 return -EINVAL;
542 553
543 fmt = mt9m111_find_datafmt(mt9m111, mf->code); 554 fmt = mt9m111_find_datafmt(mt9m111, mf->code);
544 555
@@ -572,20 +583,10 @@ static int mt9m111_try_fmt(struct v4l2_subdev *sd,
572 mf->code = fmt->code; 583 mf->code = fmt->code;
573 mf->colorspace = fmt->colorspace; 584 mf->colorspace = fmt->colorspace;
574 585
575 return 0; 586 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
576} 587 cfg->try_fmt = *mf;
577 588 return 0;
578static int mt9m111_s_fmt(struct v4l2_subdev *sd, 589 }
579 struct v4l2_mbus_framefmt *mf)
580{
581 const struct mt9m111_datafmt *fmt;
582 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
583 struct v4l2_rect *rect = &mt9m111->rect;
584 int ret;
585
586 mt9m111_try_fmt(sd, mf);
587 fmt = mt9m111_find_datafmt(mt9m111, mf->code);
588 /* try_fmt() guarantees fmt != NULL && fmt->code == mf->code */
589 590
590 ret = mt9m111_setup_geometry(mt9m111, rect, mf->width, mf->height, mf->code); 591 ret = mt9m111_setup_geometry(mt9m111, rect, mf->width, mf->height, mf->code);
591 if (!ret) 592 if (!ret)
@@ -839,13 +840,14 @@ static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = {
839#endif 840#endif
840}; 841};
841 842
842static int mt9m111_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 843static int mt9m111_enum_mbus_code(struct v4l2_subdev *sd,
843 u32 *code) 844 struct v4l2_subdev_pad_config *cfg,
845 struct v4l2_subdev_mbus_code_enum *code)
844{ 846{
845 if (index >= ARRAY_SIZE(mt9m111_colour_fmts)) 847 if (code->pad || code->index >= ARRAY_SIZE(mt9m111_colour_fmts))
846 return -EINVAL; 848 return -EINVAL;
847 849
848 *code = mt9m111_colour_fmts[index].code; 850 code->code = mt9m111_colour_fmts[code->index].code;
849 return 0; 851 return 0;
850} 852}
851 853
@@ -865,19 +867,22 @@ static int mt9m111_g_mbus_config(struct v4l2_subdev *sd,
865} 867}
866 868
867static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = { 869static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = {
868 .s_mbus_fmt = mt9m111_s_fmt,
869 .g_mbus_fmt = mt9m111_g_fmt,
870 .try_mbus_fmt = mt9m111_try_fmt,
871 .s_crop = mt9m111_s_crop, 870 .s_crop = mt9m111_s_crop,
872 .g_crop = mt9m111_g_crop, 871 .g_crop = mt9m111_g_crop,
873 .cropcap = mt9m111_cropcap, 872 .cropcap = mt9m111_cropcap,
874 .enum_mbus_fmt = mt9m111_enum_fmt,
875 .g_mbus_config = mt9m111_g_mbus_config, 873 .g_mbus_config = mt9m111_g_mbus_config,
876}; 874};
877 875
876static const struct v4l2_subdev_pad_ops mt9m111_subdev_pad_ops = {
877 .enum_mbus_code = mt9m111_enum_mbus_code,
878 .get_fmt = mt9m111_get_fmt,
879 .set_fmt = mt9m111_set_fmt,
880};
881
878static struct v4l2_subdev_ops mt9m111_subdev_ops = { 882static struct v4l2_subdev_ops mt9m111_subdev_ops = {
879 .core = &mt9m111_subdev_core_ops, 883 .core = &mt9m111_subdev_core_ops,
880 .video = &mt9m111_subdev_video_ops, 884 .video = &mt9m111_subdev_video_ops,
885 .pad = &mt9m111_subdev_pad_ops,
881}; 886};
882 887
883/* 888/*
diff --git a/drivers/media/i2c/soc_camera/mt9t031.c b/drivers/media/i2c/soc_camera/mt9t031.c
index 35d9c8d25589..3b6eeed2e2b9 100644
--- a/drivers/media/i2c/soc_camera/mt9t031.c
+++ b/drivers/media/i2c/soc_camera/mt9t031.c
@@ -264,7 +264,7 @@ static int mt9t031_set_params(struct i2c_client *client,
264 264
265 /* 265 /*
266 * The caller provides a supported format, as guaranteed by 266 * The caller provides a supported format, as guaranteed by
267 * .try_mbus_fmt(), soc_camera_s_crop() and soc_camera_cropcap() 267 * .set_fmt(FORMAT_TRY), soc_camera_s_crop() and soc_camera_cropcap()
268 */ 268 */
269 if (ret >= 0) 269 if (ret >= 0)
270 ret = reg_write(client, MT9T031_COLUMN_START, rect->left); 270 ret = reg_write(client, MT9T031_COLUMN_START, rect->left);
@@ -337,12 +337,17 @@ static int mt9t031_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
337 return 0; 337 return 0;
338} 338}
339 339
340static int mt9t031_g_fmt(struct v4l2_subdev *sd, 340static int mt9t031_get_fmt(struct v4l2_subdev *sd,
341 struct v4l2_mbus_framefmt *mf) 341 struct v4l2_subdev_pad_config *cfg,
342 struct v4l2_subdev_format *format)
342{ 343{
344 struct v4l2_mbus_framefmt *mf = &format->format;
343 struct i2c_client *client = v4l2_get_subdevdata(sd); 345 struct i2c_client *client = v4l2_get_subdevdata(sd);
344 struct mt9t031 *mt9t031 = to_mt9t031(client); 346 struct mt9t031 *mt9t031 = to_mt9t031(client);
345 347
348 if (format->pad)
349 return -EINVAL;
350
346 mf->width = mt9t031->rect.width / mt9t031->xskip; 351 mf->width = mt9t031->rect.width / mt9t031->xskip;
347 mf->height = mt9t031->rect.height / mt9t031->yskip; 352 mf->height = mt9t031->rect.height / mt9t031->yskip;
348 mf->code = MEDIA_BUS_FMT_SBGGR10_1X10; 353 mf->code = MEDIA_BUS_FMT_SBGGR10_1X10;
@@ -352,16 +357,36 @@ static int mt9t031_g_fmt(struct v4l2_subdev *sd,
352 return 0; 357 return 0;
353} 358}
354 359
355static int mt9t031_s_fmt(struct v4l2_subdev *sd, 360/*
356 struct v4l2_mbus_framefmt *mf) 361 * If a user window larger than sensor window is requested, we'll increase the
362 * sensor window.
363 */
364static int mt9t031_set_fmt(struct v4l2_subdev *sd,
365 struct v4l2_subdev_pad_config *cfg,
366 struct v4l2_subdev_format *format)
357{ 367{
368 struct v4l2_mbus_framefmt *mf = &format->format;
358 struct i2c_client *client = v4l2_get_subdevdata(sd); 369 struct i2c_client *client = v4l2_get_subdevdata(sd);
359 struct mt9t031 *mt9t031 = to_mt9t031(client); 370 struct mt9t031 *mt9t031 = to_mt9t031(client);
360 u16 xskip, yskip; 371 u16 xskip, yskip;
361 struct v4l2_rect rect = mt9t031->rect; 372 struct v4l2_rect rect = mt9t031->rect;
362 373
374 if (format->pad)
375 return -EINVAL;
376
377 mf->code = MEDIA_BUS_FMT_SBGGR10_1X10;
378 mf->colorspace = V4L2_COLORSPACE_SRGB;
379 v4l_bound_align_image(
380 &mf->width, MT9T031_MIN_WIDTH, MT9T031_MAX_WIDTH, 1,
381 &mf->height, MT9T031_MIN_HEIGHT, MT9T031_MAX_HEIGHT, 1, 0);
382
383 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
384 cfg->try_fmt = *mf;
385 return 0;
386 }
387
363 /* 388 /*
364 * try_fmt has put width and height within limits. 389 * Width and height are within limits.
365 * S_FMT: use binning and skipping for scaling 390 * S_FMT: use binning and skipping for scaling
366 */ 391 */
367 xskip = mt9t031_skip(&rect.width, mf->width, MT9T031_MAX_WIDTH); 392 xskip = mt9t031_skip(&rect.width, mf->width, MT9T031_MAX_WIDTH);
@@ -374,23 +399,6 @@ static int mt9t031_s_fmt(struct v4l2_subdev *sd,
374 return mt9t031_set_params(client, &rect, xskip, yskip); 399 return mt9t031_set_params(client, &rect, xskip, yskip);
375} 400}
376 401
377/*
378 * If a user window larger than sensor window is requested, we'll increase the
379 * sensor window.
380 */
381static int mt9t031_try_fmt(struct v4l2_subdev *sd,
382 struct v4l2_mbus_framefmt *mf)
383{
384 v4l_bound_align_image(
385 &mf->width, MT9T031_MIN_WIDTH, MT9T031_MAX_WIDTH, 1,
386 &mf->height, MT9T031_MIN_HEIGHT, MT9T031_MAX_HEIGHT, 1, 0);
387
388 mf->code = MEDIA_BUS_FMT_SBGGR10_1X10;
389 mf->colorspace = V4L2_COLORSPACE_SRGB;
390
391 return 0;
392}
393
394#ifdef CONFIG_VIDEO_ADV_DEBUG 402#ifdef CONFIG_VIDEO_ADV_DEBUG
395static int mt9t031_g_register(struct v4l2_subdev *sd, 403static int mt9t031_g_register(struct v4l2_subdev *sd,
396 struct v4l2_dbg_register *reg) 404 struct v4l2_dbg_register *reg)
@@ -672,13 +680,14 @@ static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
672#endif 680#endif
673}; 681};
674 682
675static int mt9t031_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 683static int mt9t031_enum_mbus_code(struct v4l2_subdev *sd,
676 u32 *code) 684 struct v4l2_subdev_pad_config *cfg,
685 struct v4l2_subdev_mbus_code_enum *code)
677{ 686{
678 if (index) 687 if (code->pad || code->index)
679 return -EINVAL; 688 return -EINVAL;
680 689
681 *code = MEDIA_BUS_FMT_SBGGR10_1X10; 690 code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
682 return 0; 691 return 0;
683} 692}
684 693
@@ -712,13 +721,9 @@ static int mt9t031_s_mbus_config(struct v4l2_subdev *sd,
712 721
713static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = { 722static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
714 .s_stream = mt9t031_s_stream, 723 .s_stream = mt9t031_s_stream,
715 .s_mbus_fmt = mt9t031_s_fmt,
716 .g_mbus_fmt = mt9t031_g_fmt,
717 .try_mbus_fmt = mt9t031_try_fmt,
718 .s_crop = mt9t031_s_crop, 724 .s_crop = mt9t031_s_crop,
719 .g_crop = mt9t031_g_crop, 725 .g_crop = mt9t031_g_crop,
720 .cropcap = mt9t031_cropcap, 726 .cropcap = mt9t031_cropcap,
721 .enum_mbus_fmt = mt9t031_enum_fmt,
722 .g_mbus_config = mt9t031_g_mbus_config, 727 .g_mbus_config = mt9t031_g_mbus_config,
723 .s_mbus_config = mt9t031_s_mbus_config, 728 .s_mbus_config = mt9t031_s_mbus_config,
724}; 729};
@@ -727,10 +732,17 @@ static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
727 .g_skip_top_lines = mt9t031_g_skip_top_lines, 732 .g_skip_top_lines = mt9t031_g_skip_top_lines,
728}; 733};
729 734
735static const struct v4l2_subdev_pad_ops mt9t031_subdev_pad_ops = {
736 .enum_mbus_code = mt9t031_enum_mbus_code,
737 .get_fmt = mt9t031_get_fmt,
738 .set_fmt = mt9t031_set_fmt,
739};
740
730static struct v4l2_subdev_ops mt9t031_subdev_ops = { 741static struct v4l2_subdev_ops mt9t031_subdev_ops = {
731 .core = &mt9t031_subdev_core_ops, 742 .core = &mt9t031_subdev_core_ops,
732 .video = &mt9t031_subdev_video_ops, 743 .video = &mt9t031_subdev_video_ops,
733 .sensor = &mt9t031_subdev_sensor_ops, 744 .sensor = &mt9t031_subdev_sensor_ops,
745 .pad = &mt9t031_subdev_pad_ops,
734}; 746};
735 747
736static int mt9t031_probe(struct i2c_client *client, 748static int mt9t031_probe(struct i2c_client *client,
diff --git a/drivers/media/i2c/soc_camera/mt9t112.c b/drivers/media/i2c/soc_camera/mt9t112.c
index 64f08365e6b2..de10a76ba6df 100644
--- a/drivers/media/i2c/soc_camera/mt9t112.c
+++ b/drivers/media/i2c/soc_camera/mt9t112.c
@@ -904,12 +904,17 @@ static int mt9t112_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
904 return mt9t112_set_params(priv, rect, priv->format->code); 904 return mt9t112_set_params(priv, rect, priv->format->code);
905} 905}
906 906
907static int mt9t112_g_fmt(struct v4l2_subdev *sd, 907static int mt9t112_get_fmt(struct v4l2_subdev *sd,
908 struct v4l2_mbus_framefmt *mf) 908 struct v4l2_subdev_pad_config *cfg,
909 struct v4l2_subdev_format *format)
909{ 910{
911 struct v4l2_mbus_framefmt *mf = &format->format;
910 struct i2c_client *client = v4l2_get_subdevdata(sd); 912 struct i2c_client *client = v4l2_get_subdevdata(sd);
911 struct mt9t112_priv *priv = to_mt9t112(client); 913 struct mt9t112_priv *priv = to_mt9t112(client);
912 914
915 if (format->pad)
916 return -EINVAL;
917
913 mf->width = priv->frame.width; 918 mf->width = priv->frame.width;
914 mf->height = priv->frame.height; 919 mf->height = priv->frame.height;
915 mf->colorspace = priv->format->colorspace; 920 mf->colorspace = priv->format->colorspace;
@@ -940,14 +945,19 @@ static int mt9t112_s_fmt(struct v4l2_subdev *sd,
940 return ret; 945 return ret;
941} 946}
942 947
943static int mt9t112_try_fmt(struct v4l2_subdev *sd, 948static int mt9t112_set_fmt(struct v4l2_subdev *sd,
944 struct v4l2_mbus_framefmt *mf) 949 struct v4l2_subdev_pad_config *cfg,
950 struct v4l2_subdev_format *format)
945{ 951{
952 struct v4l2_mbus_framefmt *mf = &format->format;
946 struct i2c_client *client = v4l2_get_subdevdata(sd); 953 struct i2c_client *client = v4l2_get_subdevdata(sd);
947 struct mt9t112_priv *priv = to_mt9t112(client); 954 struct mt9t112_priv *priv = to_mt9t112(client);
948 unsigned int top, left; 955 unsigned int top, left;
949 int i; 956 int i;
950 957
958 if (format->pad)
959 return -EINVAL;
960
951 for (i = 0; i < priv->num_formats; i++) 961 for (i = 0; i < priv->num_formats; i++)
952 if (mt9t112_cfmts[i].code == mf->code) 962 if (mt9t112_cfmts[i].code == mf->code)
953 break; 963 break;
@@ -963,19 +973,23 @@ static int mt9t112_try_fmt(struct v4l2_subdev *sd,
963 973
964 mf->field = V4L2_FIELD_NONE; 974 mf->field = V4L2_FIELD_NONE;
965 975
976 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
977 return mt9t112_s_fmt(sd, mf);
978 cfg->try_fmt = *mf;
966 return 0; 979 return 0;
967} 980}
968 981
969static int mt9t112_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 982static int mt9t112_enum_mbus_code(struct v4l2_subdev *sd,
970 u32 *code) 983 struct v4l2_subdev_pad_config *cfg,
984 struct v4l2_subdev_mbus_code_enum *code)
971{ 985{
972 struct i2c_client *client = v4l2_get_subdevdata(sd); 986 struct i2c_client *client = v4l2_get_subdevdata(sd);
973 struct mt9t112_priv *priv = to_mt9t112(client); 987 struct mt9t112_priv *priv = to_mt9t112(client);
974 988
975 if (index >= priv->num_formats) 989 if (code->pad || code->index >= priv->num_formats)
976 return -EINVAL; 990 return -EINVAL;
977 991
978 *code = mt9t112_cfmts[index].code; 992 code->code = mt9t112_cfmts[code->index].code;
979 993
980 return 0; 994 return 0;
981} 995}
@@ -1010,23 +1024,26 @@ static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
1010 1024
1011static struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = { 1025static struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = {
1012 .s_stream = mt9t112_s_stream, 1026 .s_stream = mt9t112_s_stream,
1013 .g_mbus_fmt = mt9t112_g_fmt,
1014 .s_mbus_fmt = mt9t112_s_fmt,
1015 .try_mbus_fmt = mt9t112_try_fmt,
1016 .cropcap = mt9t112_cropcap, 1027 .cropcap = mt9t112_cropcap,
1017 .g_crop = mt9t112_g_crop, 1028 .g_crop = mt9t112_g_crop,
1018 .s_crop = mt9t112_s_crop, 1029 .s_crop = mt9t112_s_crop,
1019 .enum_mbus_fmt = mt9t112_enum_fmt,
1020 .g_mbus_config = mt9t112_g_mbus_config, 1030 .g_mbus_config = mt9t112_g_mbus_config,
1021 .s_mbus_config = mt9t112_s_mbus_config, 1031 .s_mbus_config = mt9t112_s_mbus_config,
1022}; 1032};
1023 1033
1034static const struct v4l2_subdev_pad_ops mt9t112_subdev_pad_ops = {
1035 .enum_mbus_code = mt9t112_enum_mbus_code,
1036 .get_fmt = mt9t112_get_fmt,
1037 .set_fmt = mt9t112_set_fmt,
1038};
1039
1024/************************************************************************ 1040/************************************************************************
1025 i2c driver 1041 i2c driver
1026************************************************************************/ 1042************************************************************************/
1027static struct v4l2_subdev_ops mt9t112_subdev_ops = { 1043static struct v4l2_subdev_ops mt9t112_subdev_ops = {
1028 .core = &mt9t112_subdev_core_ops, 1044 .core = &mt9t112_subdev_core_ops,
1029 .video = &mt9t112_subdev_video_ops, 1045 .video = &mt9t112_subdev_video_ops,
1046 .pad = &mt9t112_subdev_pad_ops,
1030}; 1047};
1031 1048
1032static int mt9t112_camera_probe(struct i2c_client *client) 1049static int mt9t112_camera_probe(struct i2c_client *client)
diff --git a/drivers/media/i2c/soc_camera/mt9v022.c b/drivers/media/i2c/soc_camera/mt9v022.c
index a246d4d64b8b..f31377408550 100644
--- a/drivers/media/i2c/soc_camera/mt9v022.c
+++ b/drivers/media/i2c/soc_camera/mt9v022.c
@@ -375,12 +375,17 @@ static int mt9v022_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
375 return 0; 375 return 0;
376} 376}
377 377
378static int mt9v022_g_fmt(struct v4l2_subdev *sd, 378static int mt9v022_get_fmt(struct v4l2_subdev *sd,
379 struct v4l2_mbus_framefmt *mf) 379 struct v4l2_subdev_pad_config *cfg,
380 struct v4l2_subdev_format *format)
380{ 381{
382 struct v4l2_mbus_framefmt *mf = &format->format;
381 struct i2c_client *client = v4l2_get_subdevdata(sd); 383 struct i2c_client *client = v4l2_get_subdevdata(sd);
382 struct mt9v022 *mt9v022 = to_mt9v022(client); 384 struct mt9v022 *mt9v022 = to_mt9v022(client);
383 385
386 if (format->pad)
387 return -EINVAL;
388
384 mf->width = mt9v022->rect.width; 389 mf->width = mt9v022->rect.width;
385 mf->height = mt9v022->rect.height; 390 mf->height = mt9v022->rect.height;
386 mf->code = mt9v022->fmt->code; 391 mf->code = mt9v022->fmt->code;
@@ -407,7 +412,7 @@ static int mt9v022_s_fmt(struct v4l2_subdev *sd,
407 412
408 /* 413 /*
409 * The caller provides a supported format, as verified per call to 414 * The caller provides a supported format, as verified per call to
410 * .try_mbus_fmt(), datawidth is from our supported format list 415 * .set_fmt(FORMAT_TRY), datawidth is from our supported format list
411 */ 416 */
412 switch (mf->code) { 417 switch (mf->code) {
413 case MEDIA_BUS_FMT_Y8_1X8: 418 case MEDIA_BUS_FMT_Y8_1X8:
@@ -437,15 +442,20 @@ static int mt9v022_s_fmt(struct v4l2_subdev *sd,
437 return ret; 442 return ret;
438} 443}
439 444
440static int mt9v022_try_fmt(struct v4l2_subdev *sd, 445static int mt9v022_set_fmt(struct v4l2_subdev *sd,
441 struct v4l2_mbus_framefmt *mf) 446 struct v4l2_subdev_pad_config *cfg,
447 struct v4l2_subdev_format *format)
442{ 448{
449 struct v4l2_mbus_framefmt *mf = &format->format;
443 struct i2c_client *client = v4l2_get_subdevdata(sd); 450 struct i2c_client *client = v4l2_get_subdevdata(sd);
444 struct mt9v022 *mt9v022 = to_mt9v022(client); 451 struct mt9v022 *mt9v022 = to_mt9v022(client);
445 const struct mt9v022_datafmt *fmt; 452 const struct mt9v022_datafmt *fmt;
446 int align = mf->code == MEDIA_BUS_FMT_SBGGR8_1X8 || 453 int align = mf->code == MEDIA_BUS_FMT_SBGGR8_1X8 ||
447 mf->code == MEDIA_BUS_FMT_SBGGR10_1X10; 454 mf->code == MEDIA_BUS_FMT_SBGGR10_1X10;
448 455
456 if (format->pad)
457 return -EINVAL;
458
449 v4l_bound_align_image(&mf->width, MT9V022_MIN_WIDTH, 459 v4l_bound_align_image(&mf->width, MT9V022_MIN_WIDTH,
450 MT9V022_MAX_WIDTH, align, 460 MT9V022_MAX_WIDTH, align,
451 &mf->height, MT9V022_MIN_HEIGHT + mt9v022->y_skip_top, 461 &mf->height, MT9V022_MIN_HEIGHT + mt9v022->y_skip_top,
@@ -460,6 +470,9 @@ static int mt9v022_try_fmt(struct v4l2_subdev *sd,
460 470
461 mf->colorspace = fmt->colorspace; 471 mf->colorspace = fmt->colorspace;
462 472
473 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
474 return mt9v022_s_fmt(sd, mf);
475 cfg->try_fmt = *mf;
463 return 0; 476 return 0;
464} 477}
465 478
@@ -758,16 +771,17 @@ static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
758 .s_power = mt9v022_s_power, 771 .s_power = mt9v022_s_power,
759}; 772};
760 773
761static int mt9v022_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 774static int mt9v022_enum_mbus_code(struct v4l2_subdev *sd,
762 u32 *code) 775 struct v4l2_subdev_pad_config *cfg,
776 struct v4l2_subdev_mbus_code_enum *code)
763{ 777{
764 struct i2c_client *client = v4l2_get_subdevdata(sd); 778 struct i2c_client *client = v4l2_get_subdevdata(sd);
765 struct mt9v022 *mt9v022 = to_mt9v022(client); 779 struct mt9v022 *mt9v022 = to_mt9v022(client);
766 780
767 if (index >= mt9v022->num_fmts) 781 if (code->pad || code->index >= mt9v022->num_fmts)
768 return -EINVAL; 782 return -EINVAL;
769 783
770 *code = mt9v022->fmts[index].code; 784 code->code = mt9v022->fmts[code->index].code;
771 return 0; 785 return 0;
772} 786}
773 787
@@ -839,13 +853,9 @@ static int mt9v022_s_mbus_config(struct v4l2_subdev *sd,
839 853
840static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = { 854static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
841 .s_stream = mt9v022_s_stream, 855 .s_stream = mt9v022_s_stream,
842 .s_mbus_fmt = mt9v022_s_fmt,
843 .g_mbus_fmt = mt9v022_g_fmt,
844 .try_mbus_fmt = mt9v022_try_fmt,
845 .s_crop = mt9v022_s_crop, 856 .s_crop = mt9v022_s_crop,
846 .g_crop = mt9v022_g_crop, 857 .g_crop = mt9v022_g_crop,
847 .cropcap = mt9v022_cropcap, 858 .cropcap = mt9v022_cropcap,
848 .enum_mbus_fmt = mt9v022_enum_fmt,
849 .g_mbus_config = mt9v022_g_mbus_config, 859 .g_mbus_config = mt9v022_g_mbus_config,
850 .s_mbus_config = mt9v022_s_mbus_config, 860 .s_mbus_config = mt9v022_s_mbus_config,
851}; 861};
@@ -854,10 +864,17 @@ static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
854 .g_skip_top_lines = mt9v022_g_skip_top_lines, 864 .g_skip_top_lines = mt9v022_g_skip_top_lines,
855}; 865};
856 866
867static const struct v4l2_subdev_pad_ops mt9v022_subdev_pad_ops = {
868 .enum_mbus_code = mt9v022_enum_mbus_code,
869 .get_fmt = mt9v022_get_fmt,
870 .set_fmt = mt9v022_set_fmt,
871};
872
857static struct v4l2_subdev_ops mt9v022_subdev_ops = { 873static struct v4l2_subdev_ops mt9v022_subdev_ops = {
858 .core = &mt9v022_subdev_core_ops, 874 .core = &mt9v022_subdev_core_ops,
859 .video = &mt9v022_subdev_video_ops, 875 .video = &mt9v022_subdev_video_ops,
860 .sensor = &mt9v022_subdev_sensor_ops, 876 .sensor = &mt9v022_subdev_sensor_ops,
877 .pad = &mt9v022_subdev_pad_ops,
861}; 878};
862 879
863static int mt9v022_probe(struct i2c_client *client, 880static int mt9v022_probe(struct i2c_client *client,
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index e3c907a97765..9b4f5deec748 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -845,12 +845,17 @@ err:
845 return ret; 845 return ret;
846} 846}
847 847
848static int ov2640_g_fmt(struct v4l2_subdev *sd, 848static int ov2640_get_fmt(struct v4l2_subdev *sd,
849 struct v4l2_mbus_framefmt *mf) 849 struct v4l2_subdev_pad_config *cfg,
850 struct v4l2_subdev_format *format)
850{ 851{
852 struct v4l2_mbus_framefmt *mf = &format->format;
851 struct i2c_client *client = v4l2_get_subdevdata(sd); 853 struct i2c_client *client = v4l2_get_subdevdata(sd);
852 struct ov2640_priv *priv = to_ov2640(client); 854 struct ov2640_priv *priv = to_ov2640(client);
853 855
856 if (format->pad)
857 return -EINVAL;
858
854 if (!priv->win) { 859 if (!priv->win) {
855 u32 width = SVGA_WIDTH, height = SVGA_HEIGHT; 860 u32 width = SVGA_WIDTH, height = SVGA_HEIGHT;
856 priv->win = ov2640_select_win(&width, &height); 861 priv->win = ov2640_select_win(&width, &height);
@@ -876,33 +881,16 @@ static int ov2640_g_fmt(struct v4l2_subdev *sd,
876 return 0; 881 return 0;
877} 882}
878 883
879static int ov2640_s_fmt(struct v4l2_subdev *sd, 884static int ov2640_set_fmt(struct v4l2_subdev *sd,
880 struct v4l2_mbus_framefmt *mf) 885 struct v4l2_subdev_pad_config *cfg,
886 struct v4l2_subdev_format *format)
881{ 887{
888 struct v4l2_mbus_framefmt *mf = &format->format;
882 struct i2c_client *client = v4l2_get_subdevdata(sd); 889 struct i2c_client *client = v4l2_get_subdevdata(sd);
883 int ret;
884 890
891 if (format->pad)
892 return -EINVAL;
885 893
886 switch (mf->code) {
887 case MEDIA_BUS_FMT_RGB565_2X8_BE:
888 case MEDIA_BUS_FMT_RGB565_2X8_LE:
889 mf->colorspace = V4L2_COLORSPACE_SRGB;
890 break;
891 default:
892 mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
893 case MEDIA_BUS_FMT_YUYV8_2X8:
894 case MEDIA_BUS_FMT_UYVY8_2X8:
895 mf->colorspace = V4L2_COLORSPACE_JPEG;
896 }
897
898 ret = ov2640_set_params(client, &mf->width, &mf->height, mf->code);
899
900 return ret;
901}
902
903static int ov2640_try_fmt(struct v4l2_subdev *sd,
904 struct v4l2_mbus_framefmt *mf)
905{
906 /* 894 /*
907 * select suitable win, but don't store it 895 * select suitable win, but don't store it
908 */ 896 */
@@ -922,16 +910,21 @@ static int ov2640_try_fmt(struct v4l2_subdev *sd,
922 mf->colorspace = V4L2_COLORSPACE_JPEG; 910 mf->colorspace = V4L2_COLORSPACE_JPEG;
923 } 911 }
924 912
913 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
914 return ov2640_set_params(client, &mf->width,
915 &mf->height, mf->code);
916 cfg->try_fmt = *mf;
925 return 0; 917 return 0;
926} 918}
927 919
928static int ov2640_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 920static int ov2640_enum_mbus_code(struct v4l2_subdev *sd,
929 u32 *code) 921 struct v4l2_subdev_pad_config *cfg,
922 struct v4l2_subdev_mbus_code_enum *code)
930{ 923{
931 if (index >= ARRAY_SIZE(ov2640_codes)) 924 if (code->pad || code->index >= ARRAY_SIZE(ov2640_codes))
932 return -EINVAL; 925 return -EINVAL;
933 926
934 *code = ov2640_codes[index]; 927 code->code = ov2640_codes[code->index];
935 return 0; 928 return 0;
936} 929}
937 930
@@ -1031,18 +1024,21 @@ static int ov2640_g_mbus_config(struct v4l2_subdev *sd,
1031 1024
1032static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = { 1025static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
1033 .s_stream = ov2640_s_stream, 1026 .s_stream = ov2640_s_stream,
1034 .g_mbus_fmt = ov2640_g_fmt,
1035 .s_mbus_fmt = ov2640_s_fmt,
1036 .try_mbus_fmt = ov2640_try_fmt,
1037 .cropcap = ov2640_cropcap, 1027 .cropcap = ov2640_cropcap,
1038 .g_crop = ov2640_g_crop, 1028 .g_crop = ov2640_g_crop,
1039 .enum_mbus_fmt = ov2640_enum_fmt,
1040 .g_mbus_config = ov2640_g_mbus_config, 1029 .g_mbus_config = ov2640_g_mbus_config,
1041}; 1030};
1042 1031
1032static const struct v4l2_subdev_pad_ops ov2640_subdev_pad_ops = {
1033 .enum_mbus_code = ov2640_enum_mbus_code,
1034 .get_fmt = ov2640_get_fmt,
1035 .set_fmt = ov2640_set_fmt,
1036};
1037
1043static struct v4l2_subdev_ops ov2640_subdev_ops = { 1038static struct v4l2_subdev_ops ov2640_subdev_ops = {
1044 .core = &ov2640_subdev_core_ops, 1039 .core = &ov2640_subdev_core_ops,
1045 .video = &ov2640_subdev_video_ops, 1040 .video = &ov2640_subdev_video_ops,
1041 .pad = &ov2640_subdev_pad_ops,
1046}; 1042};
1047 1043
1048/* OF probe functions */ 1044/* OF probe functions */
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 93ae031bdafb..bab9ac0c1764 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -786,50 +786,50 @@ static int ov5642_set_resolution(struct v4l2_subdev *sd)
786 return ret; 786 return ret;
787} 787}
788 788
789static int ov5642_try_fmt(struct v4l2_subdev *sd, 789static int ov5642_set_fmt(struct v4l2_subdev *sd,
790 struct v4l2_mbus_framefmt *mf) 790 struct v4l2_subdev_pad_config *cfg,
791 struct v4l2_subdev_format *format)
791{ 792{
793 struct v4l2_mbus_framefmt *mf = &format->format;
792 struct i2c_client *client = v4l2_get_subdevdata(sd); 794 struct i2c_client *client = v4l2_get_subdevdata(sd);
793 struct ov5642 *priv = to_ov5642(client); 795 struct ov5642 *priv = to_ov5642(client);
794 const struct ov5642_datafmt *fmt = ov5642_find_datafmt(mf->code); 796 const struct ov5642_datafmt *fmt = ov5642_find_datafmt(mf->code);
795 797
798 if (format->pad)
799 return -EINVAL;
800
796 mf->width = priv->crop_rect.width; 801 mf->width = priv->crop_rect.width;
797 mf->height = priv->crop_rect.height; 802 mf->height = priv->crop_rect.height;
798 803
799 if (!fmt) { 804 if (!fmt) {
805 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
806 return -EINVAL;
800 mf->code = ov5642_colour_fmts[0].code; 807 mf->code = ov5642_colour_fmts[0].code;
801 mf->colorspace = ov5642_colour_fmts[0].colorspace; 808 mf->colorspace = ov5642_colour_fmts[0].colorspace;
802 } 809 }
803 810
804 mf->field = V4L2_FIELD_NONE; 811 mf->field = V4L2_FIELD_NONE;
805 812
813 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
814 priv->fmt = ov5642_find_datafmt(mf->code);
815 else
816 cfg->try_fmt = *mf;
806 return 0; 817 return 0;
807} 818}
808 819
809static int ov5642_s_fmt(struct v4l2_subdev *sd, 820static int ov5642_get_fmt(struct v4l2_subdev *sd,
810 struct v4l2_mbus_framefmt *mf) 821 struct v4l2_subdev_pad_config *cfg,
811{ 822 struct v4l2_subdev_format *format)
812 struct i2c_client *client = v4l2_get_subdevdata(sd);
813 struct ov5642 *priv = to_ov5642(client);
814
815 /* MIPI CSI could have changed the format, double-check */
816 if (!ov5642_find_datafmt(mf->code))
817 return -EINVAL;
818
819 ov5642_try_fmt(sd, mf);
820 priv->fmt = ov5642_find_datafmt(mf->code);
821
822 return 0;
823}
824
825static int ov5642_g_fmt(struct v4l2_subdev *sd,
826 struct v4l2_mbus_framefmt *mf)
827{ 823{
824 struct v4l2_mbus_framefmt *mf = &format->format;
828 struct i2c_client *client = v4l2_get_subdevdata(sd); 825 struct i2c_client *client = v4l2_get_subdevdata(sd);
829 struct ov5642 *priv = to_ov5642(client); 826 struct ov5642 *priv = to_ov5642(client);
830 827
831 const struct ov5642_datafmt *fmt = priv->fmt; 828 const struct ov5642_datafmt *fmt = priv->fmt;
832 829
830 if (format->pad)
831 return -EINVAL;
832
833 mf->code = fmt->code; 833 mf->code = fmt->code;
834 mf->colorspace = fmt->colorspace; 834 mf->colorspace = fmt->colorspace;
835 mf->width = priv->crop_rect.width; 835 mf->width = priv->crop_rect.width;
@@ -839,13 +839,14 @@ static int ov5642_g_fmt(struct v4l2_subdev *sd,
839 return 0; 839 return 0;
840} 840}
841 841
842static int ov5642_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 842static int ov5642_enum_mbus_code(struct v4l2_subdev *sd,
843 u32 *code) 843 struct v4l2_subdev_pad_config *cfg,
844 struct v4l2_subdev_mbus_code_enum *code)
844{ 845{
845 if (index >= ARRAY_SIZE(ov5642_colour_fmts)) 846 if (code->pad || code->index >= ARRAY_SIZE(ov5642_colour_fmts))
846 return -EINVAL; 847 return -EINVAL;
847 848
848 *code = ov5642_colour_fmts[index].code; 849 code->code = ov5642_colour_fmts[code->index].code;
849 return 0; 850 return 0;
850} 851}
851 852
@@ -939,16 +940,18 @@ static int ov5642_s_power(struct v4l2_subdev *sd, int on)
939} 940}
940 941
941static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = { 942static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = {
942 .s_mbus_fmt = ov5642_s_fmt,
943 .g_mbus_fmt = ov5642_g_fmt,
944 .try_mbus_fmt = ov5642_try_fmt,
945 .enum_mbus_fmt = ov5642_enum_fmt,
946 .s_crop = ov5642_s_crop, 943 .s_crop = ov5642_s_crop,
947 .g_crop = ov5642_g_crop, 944 .g_crop = ov5642_g_crop,
948 .cropcap = ov5642_cropcap, 945 .cropcap = ov5642_cropcap,
949 .g_mbus_config = ov5642_g_mbus_config, 946 .g_mbus_config = ov5642_g_mbus_config,
950}; 947};
951 948
949static const struct v4l2_subdev_pad_ops ov5642_subdev_pad_ops = {
950 .enum_mbus_code = ov5642_enum_mbus_code,
951 .get_fmt = ov5642_get_fmt,
952 .set_fmt = ov5642_set_fmt,
953};
954
952static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = { 955static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = {
953 .s_power = ov5642_s_power, 956 .s_power = ov5642_s_power,
954#ifdef CONFIG_VIDEO_ADV_DEBUG 957#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -960,6 +963,7 @@ static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = {
960static struct v4l2_subdev_ops ov5642_subdev_ops = { 963static struct v4l2_subdev_ops ov5642_subdev_ops = {
961 .core = &ov5642_subdev_core_ops, 964 .core = &ov5642_subdev_core_ops,
962 .video = &ov5642_subdev_video_ops, 965 .video = &ov5642_subdev_video_ops,
966 .pad = &ov5642_subdev_pad_ops,
963}; 967};
964 968
965static int ov5642_video_probe(struct i2c_client *client) 969static int ov5642_video_probe(struct i2c_client *client)
diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c
index f4eef2fa6f6f..1f8af1ee8352 100644
--- a/drivers/media/i2c/soc_camera/ov6650.c
+++ b/drivers/media/i2c/soc_camera/ov6650.c
@@ -499,12 +499,17 @@ static int ov6650_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
499 return 0; 499 return 0;
500} 500}
501 501
502static int ov6650_g_fmt(struct v4l2_subdev *sd, 502static int ov6650_get_fmt(struct v4l2_subdev *sd,
503 struct v4l2_mbus_framefmt *mf) 503 struct v4l2_subdev_pad_config *cfg,
504 struct v4l2_subdev_format *format)
504{ 505{
506 struct v4l2_mbus_framefmt *mf = &format->format;
505 struct i2c_client *client = v4l2_get_subdevdata(sd); 507 struct i2c_client *client = v4l2_get_subdevdata(sd);
506 struct ov6650 *priv = to_ov6650(client); 508 struct ov6650 *priv = to_ov6650(client);
507 509
510 if (format->pad)
511 return -EINVAL;
512
508 mf->width = priv->rect.width >> priv->half_scale; 513 mf->width = priv->rect.width >> priv->half_scale;
509 mf->height = priv->rect.height >> priv->half_scale; 514 mf->height = priv->rect.height >> priv->half_scale;
510 mf->code = priv->code; 515 mf->code = priv->code;
@@ -680,16 +685,20 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
680 mf->width = priv->rect.width >> half_scale; 685 mf->width = priv->rect.width >> half_scale;
681 mf->height = priv->rect.height >> half_scale; 686 mf->height = priv->rect.height >> half_scale;
682 } 687 }
683
684 return ret; 688 return ret;
685} 689}
686 690
687static int ov6650_try_fmt(struct v4l2_subdev *sd, 691static int ov6650_set_fmt(struct v4l2_subdev *sd,
688 struct v4l2_mbus_framefmt *mf) 692 struct v4l2_subdev_pad_config *cfg,
693 struct v4l2_subdev_format *format)
689{ 694{
695 struct v4l2_mbus_framefmt *mf = &format->format;
690 struct i2c_client *client = v4l2_get_subdevdata(sd); 696 struct i2c_client *client = v4l2_get_subdevdata(sd);
691 struct ov6650 *priv = to_ov6650(client); 697 struct ov6650 *priv = to_ov6650(client);
692 698
699 if (format->pad)
700 return -EINVAL;
701
693 if (is_unscaled_ok(mf->width, mf->height, &priv->rect)) 702 if (is_unscaled_ok(mf->width, mf->height, &priv->rect))
694 v4l_bound_align_image(&mf->width, 2, W_CIF, 1, 703 v4l_bound_align_image(&mf->width, 2, W_CIF, 1,
695 &mf->height, 2, H_CIF, 1, 0); 704 &mf->height, 2, H_CIF, 1, 0);
@@ -713,16 +722,21 @@ static int ov6650_try_fmt(struct v4l2_subdev *sd,
713 break; 722 break;
714 } 723 }
715 724
725 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
726 return ov6650_s_fmt(sd, mf);
727 cfg->try_fmt = *mf;
728
716 return 0; 729 return 0;
717} 730}
718 731
719static int ov6650_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 732static int ov6650_enum_mbus_code(struct v4l2_subdev *sd,
720 u32 *code) 733 struct v4l2_subdev_pad_config *cfg,
734 struct v4l2_subdev_mbus_code_enum *code)
721{ 735{
722 if (index >= ARRAY_SIZE(ov6650_codes)) 736 if (code->pad || code->index >= ARRAY_SIZE(ov6650_codes))
723 return -EINVAL; 737 return -EINVAL;
724 738
725 *code = ov6650_codes[index]; 739 code->code = ov6650_codes[code->index];
726 return 0; 740 return 0;
727} 741}
728 742
@@ -929,10 +943,6 @@ static int ov6650_s_mbus_config(struct v4l2_subdev *sd,
929 943
930static struct v4l2_subdev_video_ops ov6650_video_ops = { 944static struct v4l2_subdev_video_ops ov6650_video_ops = {
931 .s_stream = ov6650_s_stream, 945 .s_stream = ov6650_s_stream,
932 .g_mbus_fmt = ov6650_g_fmt,
933 .s_mbus_fmt = ov6650_s_fmt,
934 .try_mbus_fmt = ov6650_try_fmt,
935 .enum_mbus_fmt = ov6650_enum_fmt,
936 .cropcap = ov6650_cropcap, 946 .cropcap = ov6650_cropcap,
937 .g_crop = ov6650_g_crop, 947 .g_crop = ov6650_g_crop,
938 .s_crop = ov6650_s_crop, 948 .s_crop = ov6650_s_crop,
@@ -942,9 +952,16 @@ static struct v4l2_subdev_video_ops ov6650_video_ops = {
942 .s_mbus_config = ov6650_s_mbus_config, 952 .s_mbus_config = ov6650_s_mbus_config,
943}; 953};
944 954
955static const struct v4l2_subdev_pad_ops ov6650_pad_ops = {
956 .enum_mbus_code = ov6650_enum_mbus_code,
957 .get_fmt = ov6650_get_fmt,
958 .set_fmt = ov6650_set_fmt,
959};
960
945static struct v4l2_subdev_ops ov6650_subdev_ops = { 961static struct v4l2_subdev_ops ov6650_subdev_ops = {
946 .core = &ov6650_core_ops, 962 .core = &ov6650_core_ops,
947 .video = &ov6650_video_ops, 963 .video = &ov6650_video_ops,
964 .pad = &ov6650_pad_ops,
948}; 965};
949 966
950/* 967/*
diff --git a/drivers/media/i2c/soc_camera/ov772x.c b/drivers/media/i2c/soc_camera/ov772x.c
index 8daac88b33fe..f150a8bd94dc 100644
--- a/drivers/media/i2c/soc_camera/ov772x.c
+++ b/drivers/media/i2c/soc_camera/ov772x.c
@@ -876,11 +876,16 @@ static int ov772x_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
876 return 0; 876 return 0;
877} 877}
878 878
879static int ov772x_g_fmt(struct v4l2_subdev *sd, 879static int ov772x_get_fmt(struct v4l2_subdev *sd,
880 struct v4l2_mbus_framefmt *mf) 880 struct v4l2_subdev_pad_config *cfg,
881 struct v4l2_subdev_format *format)
881{ 882{
883 struct v4l2_mbus_framefmt *mf = &format->format;
882 struct ov772x_priv *priv = to_ov772x(sd); 884 struct ov772x_priv *priv = to_ov772x(sd);
883 885
886 if (format->pad)
887 return -EINVAL;
888
884 mf->width = priv->win->rect.width; 889 mf->width = priv->win->rect.width;
885 mf->height = priv->win->rect.height; 890 mf->height = priv->win->rect.height;
886 mf->code = priv->cfmt->code; 891 mf->code = priv->cfmt->code;
@@ -915,12 +920,17 @@ static int ov772x_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
915 return 0; 920 return 0;
916} 921}
917 922
918static int ov772x_try_fmt(struct v4l2_subdev *sd, 923static int ov772x_set_fmt(struct v4l2_subdev *sd,
919 struct v4l2_mbus_framefmt *mf) 924 struct v4l2_subdev_pad_config *cfg,
925 struct v4l2_subdev_format *format)
920{ 926{
927 struct v4l2_mbus_framefmt *mf = &format->format;
921 const struct ov772x_color_format *cfmt; 928 const struct ov772x_color_format *cfmt;
922 const struct ov772x_win_size *win; 929 const struct ov772x_win_size *win;
923 930
931 if (format->pad)
932 return -EINVAL;
933
924 ov772x_select_params(mf, &cfmt, &win); 934 ov772x_select_params(mf, &cfmt, &win);
925 935
926 mf->code = cfmt->code; 936 mf->code = cfmt->code;
@@ -929,6 +939,9 @@ static int ov772x_try_fmt(struct v4l2_subdev *sd,
929 mf->field = V4L2_FIELD_NONE; 939 mf->field = V4L2_FIELD_NONE;
930 mf->colorspace = cfmt->colorspace; 940 mf->colorspace = cfmt->colorspace;
931 941
942 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
943 return ov772x_s_fmt(sd, mf);
944 cfg->try_fmt = *mf;
932 return 0; 945 return 0;
933} 946}
934 947
@@ -989,13 +1002,14 @@ static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
989 .s_power = ov772x_s_power, 1002 .s_power = ov772x_s_power,
990}; 1003};
991 1004
992static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 1005static int ov772x_enum_mbus_code(struct v4l2_subdev *sd,
993 u32 *code) 1006 struct v4l2_subdev_pad_config *cfg,
1007 struct v4l2_subdev_mbus_code_enum *code)
994{ 1008{
995 if (index >= ARRAY_SIZE(ov772x_cfmts)) 1009 if (code->pad || code->index >= ARRAY_SIZE(ov772x_cfmts))
996 return -EINVAL; 1010 return -EINVAL;
997 1011
998 *code = ov772x_cfmts[index].code; 1012 code->code = ov772x_cfmts[code->index].code;
999 return 0; 1013 return 0;
1000} 1014}
1001 1015
@@ -1016,18 +1030,21 @@ static int ov772x_g_mbus_config(struct v4l2_subdev *sd,
1016 1030
1017static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = { 1031static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
1018 .s_stream = ov772x_s_stream, 1032 .s_stream = ov772x_s_stream,
1019 .g_mbus_fmt = ov772x_g_fmt,
1020 .s_mbus_fmt = ov772x_s_fmt,
1021 .try_mbus_fmt = ov772x_try_fmt,
1022 .cropcap = ov772x_cropcap, 1033 .cropcap = ov772x_cropcap,
1023 .g_crop = ov772x_g_crop, 1034 .g_crop = ov772x_g_crop,
1024 .enum_mbus_fmt = ov772x_enum_fmt,
1025 .g_mbus_config = ov772x_g_mbus_config, 1035 .g_mbus_config = ov772x_g_mbus_config,
1026}; 1036};
1027 1037
1038static const struct v4l2_subdev_pad_ops ov772x_subdev_pad_ops = {
1039 .enum_mbus_code = ov772x_enum_mbus_code,
1040 .get_fmt = ov772x_get_fmt,
1041 .set_fmt = ov772x_set_fmt,
1042};
1043
1028static struct v4l2_subdev_ops ov772x_subdev_ops = { 1044static struct v4l2_subdev_ops ov772x_subdev_ops = {
1029 .core = &ov772x_subdev_core_ops, 1045 .core = &ov772x_subdev_core_ops,
1030 .video = &ov772x_subdev_video_ops, 1046 .video = &ov772x_subdev_video_ops,
1047 .pad = &ov772x_subdev_pad_ops,
1031}; 1048};
1032 1049
1033/* 1050/*
diff --git a/drivers/media/i2c/soc_camera/ov9640.c b/drivers/media/i2c/soc_camera/ov9640.c
index aa93d2e88572..8caae1c07541 100644
--- a/drivers/media/i2c/soc_camera/ov9640.c
+++ b/drivers/media/i2c/soc_camera/ov9640.c
@@ -519,9 +519,15 @@ static int ov9640_s_fmt(struct v4l2_subdev *sd,
519 return ret; 519 return ret;
520} 520}
521 521
522static int ov9640_try_fmt(struct v4l2_subdev *sd, 522static int ov9640_set_fmt(struct v4l2_subdev *sd,
523 struct v4l2_mbus_framefmt *mf) 523 struct v4l2_subdev_pad_config *cfg,
524 struct v4l2_subdev_format *format)
524{ 525{
526 struct v4l2_mbus_framefmt *mf = &format->format;
527
528 if (format->pad)
529 return -EINVAL;
530
525 ov9640_res_roundup(&mf->width, &mf->height); 531 ov9640_res_roundup(&mf->width, &mf->height);
526 532
527 mf->field = V4L2_FIELD_NONE; 533 mf->field = V4L2_FIELD_NONE;
@@ -537,16 +543,21 @@ static int ov9640_try_fmt(struct v4l2_subdev *sd,
537 mf->colorspace = V4L2_COLORSPACE_JPEG; 543 mf->colorspace = V4L2_COLORSPACE_JPEG;
538 } 544 }
539 545
546 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
547 return ov9640_s_fmt(sd, mf);
548
549 cfg->try_fmt = *mf;
540 return 0; 550 return 0;
541} 551}
542 552
543static int ov9640_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 553static int ov9640_enum_mbus_code(struct v4l2_subdev *sd,
544 u32 *code) 554 struct v4l2_subdev_pad_config *cfg,
555 struct v4l2_subdev_mbus_code_enum *code)
545{ 556{
546 if (index >= ARRAY_SIZE(ov9640_codes)) 557 if (code->pad || code->index >= ARRAY_SIZE(ov9640_codes))
547 return -EINVAL; 558 return -EINVAL;
548 559
549 *code = ov9640_codes[index]; 560 code->code = ov9640_codes[code->index];
550 return 0; 561 return 0;
551} 562}
552 563
@@ -656,17 +667,20 @@ static int ov9640_g_mbus_config(struct v4l2_subdev *sd,
656 667
657static struct v4l2_subdev_video_ops ov9640_video_ops = { 668static struct v4l2_subdev_video_ops ov9640_video_ops = {
658 .s_stream = ov9640_s_stream, 669 .s_stream = ov9640_s_stream,
659 .s_mbus_fmt = ov9640_s_fmt,
660 .try_mbus_fmt = ov9640_try_fmt,
661 .enum_mbus_fmt = ov9640_enum_fmt,
662 .cropcap = ov9640_cropcap, 670 .cropcap = ov9640_cropcap,
663 .g_crop = ov9640_g_crop, 671 .g_crop = ov9640_g_crop,
664 .g_mbus_config = ov9640_g_mbus_config, 672 .g_mbus_config = ov9640_g_mbus_config,
665}; 673};
666 674
675static const struct v4l2_subdev_pad_ops ov9640_pad_ops = {
676 .enum_mbus_code = ov9640_enum_mbus_code,
677 .set_fmt = ov9640_set_fmt,
678};
679
667static struct v4l2_subdev_ops ov9640_subdev_ops = { 680static struct v4l2_subdev_ops ov9640_subdev_ops = {
668 .core = &ov9640_core_ops, 681 .core = &ov9640_core_ops,
669 .video = &ov9640_video_ops, 682 .video = &ov9640_video_ops,
683 .pad = &ov9640_pad_ops,
670}; 684};
671 685
672/* 686/*
diff --git a/drivers/media/i2c/soc_camera/ov9740.c b/drivers/media/i2c/soc_camera/ov9740.c
index 841dc55457cf..03a7fc7316ae 100644
--- a/drivers/media/i2c/soc_camera/ov9740.c
+++ b/drivers/media/i2c/soc_camera/ov9740.c
@@ -704,25 +704,35 @@ static int ov9740_s_fmt(struct v4l2_subdev *sd,
704 return ret; 704 return ret;
705} 705}
706 706
707static int ov9740_try_fmt(struct v4l2_subdev *sd, 707static int ov9740_set_fmt(struct v4l2_subdev *sd,
708 struct v4l2_mbus_framefmt *mf) 708 struct v4l2_subdev_pad_config *cfg,
709 struct v4l2_subdev_format *format)
709{ 710{
711 struct v4l2_mbus_framefmt *mf = &format->format;
712
713 if (format->pad)
714 return -EINVAL;
715
710 ov9740_res_roundup(&mf->width, &mf->height); 716 ov9740_res_roundup(&mf->width, &mf->height);
711 717
712 mf->field = V4L2_FIELD_NONE; 718 mf->field = V4L2_FIELD_NONE;
713 mf->code = MEDIA_BUS_FMT_YUYV8_2X8; 719 mf->code = MEDIA_BUS_FMT_YUYV8_2X8;
714 mf->colorspace = V4L2_COLORSPACE_SRGB; 720 mf->colorspace = V4L2_COLORSPACE_SRGB;
715 721
722 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
723 return ov9740_s_fmt(sd, mf);
724 cfg->try_fmt = *mf;
716 return 0; 725 return 0;
717} 726}
718 727
719static int ov9740_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 728static int ov9740_enum_mbus_code(struct v4l2_subdev *sd,
720 u32 *code) 729 struct v4l2_subdev_pad_config *cfg,
730 struct v4l2_subdev_mbus_code_enum *code)
721{ 731{
722 if (index >= ARRAY_SIZE(ov9740_codes)) 732 if (code->pad || code->index >= ARRAY_SIZE(ov9740_codes))
723 return -EINVAL; 733 return -EINVAL;
724 734
725 *code = ov9740_codes[index]; 735 code->code = ov9740_codes[code->index];
726 736
727 return 0; 737 return 0;
728} 738}
@@ -904,9 +914,6 @@ static int ov9740_g_mbus_config(struct v4l2_subdev *sd,
904 914
905static struct v4l2_subdev_video_ops ov9740_video_ops = { 915static struct v4l2_subdev_video_ops ov9740_video_ops = {
906 .s_stream = ov9740_s_stream, 916 .s_stream = ov9740_s_stream,
907 .s_mbus_fmt = ov9740_s_fmt,
908 .try_mbus_fmt = ov9740_try_fmt,
909 .enum_mbus_fmt = ov9740_enum_fmt,
910 .cropcap = ov9740_cropcap, 917 .cropcap = ov9740_cropcap,
911 .g_crop = ov9740_g_crop, 918 .g_crop = ov9740_g_crop,
912 .g_mbus_config = ov9740_g_mbus_config, 919 .g_mbus_config = ov9740_g_mbus_config,
@@ -920,9 +927,15 @@ static struct v4l2_subdev_core_ops ov9740_core_ops = {
920#endif 927#endif
921}; 928};
922 929
930static const struct v4l2_subdev_pad_ops ov9740_pad_ops = {
931 .enum_mbus_code = ov9740_enum_mbus_code,
932 .set_fmt = ov9740_set_fmt,
933};
934
923static struct v4l2_subdev_ops ov9740_subdev_ops = { 935static struct v4l2_subdev_ops ov9740_subdev_ops = {
924 .core = &ov9740_core_ops, 936 .core = &ov9740_core_ops,
925 .video = &ov9740_video_ops, 937 .video = &ov9740_video_ops,
938 .pad = &ov9740_pad_ops,
926}; 939};
927 940
928static const struct v4l2_ctrl_ops ov9740_ctrl_ops = { 941static const struct v4l2_ctrl_ops ov9740_ctrl_ops = {
diff --git a/drivers/media/i2c/soc_camera/rj54n1cb0c.c b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
index 1752428c43c5..c769cf663f84 100644
--- a/drivers/media/i2c/soc_camera/rj54n1cb0c.c
+++ b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
@@ -485,13 +485,14 @@ static int reg_write_multiple(struct i2c_client *client,
485 return 0; 485 return 0;
486} 486}
487 487
488static int rj54n1_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 488static int rj54n1_enum_mbus_code(struct v4l2_subdev *sd,
489 u32 *code) 489 struct v4l2_subdev_pad_config *cfg,
490 struct v4l2_subdev_mbus_code_enum *code)
490{ 491{
491 if (index >= ARRAY_SIZE(rj54n1_colour_fmts)) 492 if (code->pad || code->index >= ARRAY_SIZE(rj54n1_colour_fmts))
492 return -EINVAL; 493 return -EINVAL;
493 494
494 *code = rj54n1_colour_fmts[index].code; 495 code->code = rj54n1_colour_fmts[code->index].code;
495 return 0; 496 return 0;
496} 497}
497 498
@@ -597,12 +598,17 @@ static int rj54n1_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
597 return 0; 598 return 0;
598} 599}
599 600
600static int rj54n1_g_fmt(struct v4l2_subdev *sd, 601static int rj54n1_get_fmt(struct v4l2_subdev *sd,
601 struct v4l2_mbus_framefmt *mf) 602 struct v4l2_subdev_pad_config *cfg,
603 struct v4l2_subdev_format *format)
602{ 604{
605 struct v4l2_mbus_framefmt *mf = &format->format;
603 struct i2c_client *client = v4l2_get_subdevdata(sd); 606 struct i2c_client *client = v4l2_get_subdevdata(sd);
604 struct rj54n1 *rj54n1 = to_rj54n1(client); 607 struct rj54n1 *rj54n1 = to_rj54n1(client);
605 608
609 if (format->pad)
610 return -EINVAL;
611
606 mf->code = rj54n1->fmt->code; 612 mf->code = rj54n1->fmt->code;
607 mf->colorspace = rj54n1->fmt->colorspace; 613 mf->colorspace = rj54n1->fmt->colorspace;
608 mf->field = V4L2_FIELD_NONE; 614 mf->field = V4L2_FIELD_NONE;
@@ -959,17 +965,25 @@ static int rj54n1_reg_init(struct i2c_client *client)
959 return ret; 965 return ret;
960} 966}
961 967
962static int rj54n1_try_fmt(struct v4l2_subdev *sd, 968static int rj54n1_set_fmt(struct v4l2_subdev *sd,
963 struct v4l2_mbus_framefmt *mf) 969 struct v4l2_subdev_pad_config *cfg,
970 struct v4l2_subdev_format *format)
964{ 971{
972 struct v4l2_mbus_framefmt *mf = &format->format;
965 struct i2c_client *client = v4l2_get_subdevdata(sd); 973 struct i2c_client *client = v4l2_get_subdevdata(sd);
966 struct rj54n1 *rj54n1 = to_rj54n1(client); 974 struct rj54n1 *rj54n1 = to_rj54n1(client);
967 const struct rj54n1_datafmt *fmt; 975 const struct rj54n1_datafmt *fmt;
976 int output_w, output_h, max_w, max_h,
977 input_w = rj54n1->rect.width, input_h = rj54n1->rect.height;
968 int align = mf->code == MEDIA_BUS_FMT_SBGGR10_1X10 || 978 int align = mf->code == MEDIA_BUS_FMT_SBGGR10_1X10 ||
969 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE || 979 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE ||
970 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE || 980 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE ||
971 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE || 981 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE ||
972 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE; 982 mf->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE;
983 int ret;
984
985 if (format->pad)
986 return -EINVAL;
973 987
974 dev_dbg(&client->dev, "%s: code = %d, width = %u, height = %u\n", 988 dev_dbg(&client->dev, "%s: code = %d, width = %u, height = %u\n",
975 __func__, mf->code, mf->width, mf->height); 989 __func__, mf->code, mf->width, mf->height);
@@ -987,24 +1001,10 @@ static int rj54n1_try_fmt(struct v4l2_subdev *sd,
987 v4l_bound_align_image(&mf->width, 112, RJ54N1_MAX_WIDTH, align, 1001 v4l_bound_align_image(&mf->width, 112, RJ54N1_MAX_WIDTH, align,
988 &mf->height, 84, RJ54N1_MAX_HEIGHT, align, 0); 1002 &mf->height, 84, RJ54N1_MAX_HEIGHT, align, 0);
989 1003
990 return 0; 1004 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
991} 1005 cfg->try_fmt = *mf;
992 1006 return 0;
993static int rj54n1_s_fmt(struct v4l2_subdev *sd, 1007 }
994 struct v4l2_mbus_framefmt *mf)
995{
996 struct i2c_client *client = v4l2_get_subdevdata(sd);
997 struct rj54n1 *rj54n1 = to_rj54n1(client);
998 const struct rj54n1_datafmt *fmt;
999 int output_w, output_h, max_w, max_h,
1000 input_w = rj54n1->rect.width, input_h = rj54n1->rect.height;
1001 int ret;
1002
1003 /*
1004 * The host driver can call us without .try_fmt(), so, we have to take
1005 * care ourseleves
1006 */
1007 rj54n1_try_fmt(sd, mf);
1008 1008
1009 /* 1009 /*
1010 * Verify if the sensor has just been powered on. TODO: replace this 1010 * Verify if the sensor has just been powered on. TODO: replace this
@@ -1020,9 +1020,6 @@ static int rj54n1_s_fmt(struct v4l2_subdev *sd,
1020 return ret; 1020 return ret;
1021 } 1021 }
1022 1022
1023 dev_dbg(&client->dev, "%s: code = %d, width = %u, height = %u\n",
1024 __func__, mf->code, mf->width, mf->height);
1025
1026 /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */ 1023 /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */
1027 switch (mf->code) { 1024 switch (mf->code) {
1028 case MEDIA_BUS_FMT_YUYV8_2X8: 1025 case MEDIA_BUS_FMT_YUYV8_2X8:
@@ -1249,10 +1246,6 @@ static int rj54n1_s_mbus_config(struct v4l2_subdev *sd,
1249 1246
1250static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = { 1247static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
1251 .s_stream = rj54n1_s_stream, 1248 .s_stream = rj54n1_s_stream,
1252 .s_mbus_fmt = rj54n1_s_fmt,
1253 .g_mbus_fmt = rj54n1_g_fmt,
1254 .try_mbus_fmt = rj54n1_try_fmt,
1255 .enum_mbus_fmt = rj54n1_enum_fmt,
1256 .g_crop = rj54n1_g_crop, 1249 .g_crop = rj54n1_g_crop,
1257 .s_crop = rj54n1_s_crop, 1250 .s_crop = rj54n1_s_crop,
1258 .cropcap = rj54n1_cropcap, 1251 .cropcap = rj54n1_cropcap,
@@ -1260,9 +1253,16 @@ static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
1260 .s_mbus_config = rj54n1_s_mbus_config, 1253 .s_mbus_config = rj54n1_s_mbus_config,
1261}; 1254};
1262 1255
1256static const struct v4l2_subdev_pad_ops rj54n1_subdev_pad_ops = {
1257 .enum_mbus_code = rj54n1_enum_mbus_code,
1258 .get_fmt = rj54n1_get_fmt,
1259 .set_fmt = rj54n1_set_fmt,
1260};
1261
1263static struct v4l2_subdev_ops rj54n1_subdev_ops = { 1262static struct v4l2_subdev_ops rj54n1_subdev_ops = {
1264 .core = &rj54n1_subdev_core_ops, 1263 .core = &rj54n1_subdev_core_ops,
1265 .video = &rj54n1_subdev_video_ops, 1264 .video = &rj54n1_subdev_video_ops,
1265 .pad = &rj54n1_subdev_pad_ops,
1266}; 1266};
1267 1267
1268/* 1268/*
diff --git a/drivers/media/i2c/soc_camera/tw9910.c b/drivers/media/i2c/soc_camera/tw9910.c
index 9b853215d146..42bec9bf1892 100644
--- a/drivers/media/i2c/soc_camera/tw9910.c
+++ b/drivers/media/i2c/soc_camera/tw9910.c
@@ -691,12 +691,17 @@ static int tw9910_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
691 return 0; 691 return 0;
692} 692}
693 693
694static int tw9910_g_fmt(struct v4l2_subdev *sd, 694static int tw9910_get_fmt(struct v4l2_subdev *sd,
695 struct v4l2_mbus_framefmt *mf) 695 struct v4l2_subdev_pad_config *cfg,
696 struct v4l2_subdev_format *format)
696{ 697{
698 struct v4l2_mbus_framefmt *mf = &format->format;
697 struct i2c_client *client = v4l2_get_subdevdata(sd); 699 struct i2c_client *client = v4l2_get_subdevdata(sd);
698 struct tw9910_priv *priv = to_tw9910(client); 700 struct tw9910_priv *priv = to_tw9910(client);
699 701
702 if (format->pad)
703 return -EINVAL;
704
700 if (!priv->scale) { 705 if (!priv->scale) {
701 priv->scale = tw9910_select_norm(priv->norm, 640, 480); 706 priv->scale = tw9910_select_norm(priv->norm, 640, 480);
702 if (!priv->scale) 707 if (!priv->scale)
@@ -737,13 +742,18 @@ static int tw9910_s_fmt(struct v4l2_subdev *sd,
737 return ret; 742 return ret;
738} 743}
739 744
740static int tw9910_try_fmt(struct v4l2_subdev *sd, 745static int tw9910_set_fmt(struct v4l2_subdev *sd,
741 struct v4l2_mbus_framefmt *mf) 746 struct v4l2_subdev_pad_config *cfg,
747 struct v4l2_subdev_format *format)
742{ 748{
749 struct v4l2_mbus_framefmt *mf = &format->format;
743 struct i2c_client *client = v4l2_get_subdevdata(sd); 750 struct i2c_client *client = v4l2_get_subdevdata(sd);
744 struct tw9910_priv *priv = to_tw9910(client); 751 struct tw9910_priv *priv = to_tw9910(client);
745 const struct tw9910_scale_ctrl *scale; 752 const struct tw9910_scale_ctrl *scale;
746 753
754 if (format->pad)
755 return -EINVAL;
756
747 if (V4L2_FIELD_ANY == mf->field) { 757 if (V4L2_FIELD_ANY == mf->field) {
748 mf->field = V4L2_FIELD_INTERLACED_BT; 758 mf->field = V4L2_FIELD_INTERLACED_BT;
749 } else if (V4L2_FIELD_INTERLACED_BT != mf->field) { 759 } else if (V4L2_FIELD_INTERLACED_BT != mf->field) {
@@ -764,6 +774,9 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd,
764 mf->width = scale->width; 774 mf->width = scale->width;
765 mf->height = scale->height; 775 mf->height = scale->height;
766 776
777 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
778 return tw9910_s_fmt(sd, mf);
779 cfg->try_fmt = *mf;
767 return 0; 780 return 0;
768} 781}
769 782
@@ -821,13 +834,14 @@ static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
821 .s_power = tw9910_s_power, 834 .s_power = tw9910_s_power,
822}; 835};
823 836
824static int tw9910_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 837static int tw9910_enum_mbus_code(struct v4l2_subdev *sd,
825 u32 *code) 838 struct v4l2_subdev_pad_config *cfg,
839 struct v4l2_subdev_mbus_code_enum *code)
826{ 840{
827 if (index) 841 if (code->pad || code->index)
828 return -EINVAL; 842 return -EINVAL;
829 843
830 *code = MEDIA_BUS_FMT_UYVY8_2X8; 844 code->code = MEDIA_BUS_FMT_UYVY8_2X8;
831 return 0; 845 return 0;
832} 846}
833 847
@@ -880,20 +894,23 @@ static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
880 .s_std = tw9910_s_std, 894 .s_std = tw9910_s_std,
881 .g_std = tw9910_g_std, 895 .g_std = tw9910_g_std,
882 .s_stream = tw9910_s_stream, 896 .s_stream = tw9910_s_stream,
883 .g_mbus_fmt = tw9910_g_fmt,
884 .s_mbus_fmt = tw9910_s_fmt,
885 .try_mbus_fmt = tw9910_try_fmt,
886 .cropcap = tw9910_cropcap, 897 .cropcap = tw9910_cropcap,
887 .g_crop = tw9910_g_crop, 898 .g_crop = tw9910_g_crop,
888 .enum_mbus_fmt = tw9910_enum_fmt,
889 .g_mbus_config = tw9910_g_mbus_config, 899 .g_mbus_config = tw9910_g_mbus_config,
890 .s_mbus_config = tw9910_s_mbus_config, 900 .s_mbus_config = tw9910_s_mbus_config,
891 .g_tvnorms = tw9910_g_tvnorms, 901 .g_tvnorms = tw9910_g_tvnorms,
892}; 902};
893 903
904static const struct v4l2_subdev_pad_ops tw9910_subdev_pad_ops = {
905 .enum_mbus_code = tw9910_enum_mbus_code,
906 .get_fmt = tw9910_get_fmt,
907 .set_fmt = tw9910_set_fmt,
908};
909
894static struct v4l2_subdev_ops tw9910_subdev_ops = { 910static struct v4l2_subdev_ops tw9910_subdev_ops = {
895 .core = &tw9910_subdev_core_ops, 911 .core = &tw9910_subdev_core_ops,
896 .video = &tw9910_subdev_video_ops, 912 .video = &tw9910_subdev_video_ops,
913 .pad = &tw9910_subdev_pad_ops,
897}; 914};
898 915
899/* 916/*
diff --git a/drivers/media/i2c/sr030pc30.c b/drivers/media/i2c/sr030pc30.c
index 10c735c3a082..b62b6ddc4356 100644
--- a/drivers/media/i2c/sr030pc30.c
+++ b/drivers/media/i2c/sr030pc30.c
@@ -471,25 +471,31 @@ static int sr030pc30_s_ctrl(struct v4l2_ctrl *ctrl)
471 return 0; 471 return 0;
472} 472}
473 473
474static int sr030pc30_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 474static int sr030pc30_enum_mbus_code(struct v4l2_subdev *sd,
475 u32 *code) 475 struct v4l2_subdev_pad_config *cfg,
476 struct v4l2_subdev_mbus_code_enum *code)
476{ 477{
477 if (!code || index >= ARRAY_SIZE(sr030pc30_formats)) 478 if (!code || code->pad ||
479 code->index >= ARRAY_SIZE(sr030pc30_formats))
478 return -EINVAL; 480 return -EINVAL;
479 481
480 *code = sr030pc30_formats[index].code; 482 code->code = sr030pc30_formats[code->index].code;
481 return 0; 483 return 0;
482} 484}
483 485
484static int sr030pc30_g_fmt(struct v4l2_subdev *sd, 486static int sr030pc30_get_fmt(struct v4l2_subdev *sd,
485 struct v4l2_mbus_framefmt *mf) 487 struct v4l2_subdev_pad_config *cfg,
488 struct v4l2_subdev_format *format)
486{ 489{
490 struct v4l2_mbus_framefmt *mf;
487 struct sr030pc30_info *info = to_sr030pc30(sd); 491 struct sr030pc30_info *info = to_sr030pc30(sd);
488 int ret; 492 int ret;
489 493
490 if (!mf) 494 if (!format || format->pad)
491 return -EINVAL; 495 return -EINVAL;
492 496
497 mf = &format->format;
498
493 if (!info->curr_win || !info->curr_fmt) { 499 if (!info->curr_win || !info->curr_fmt) {
494 ret = sr030pc30_set_params(sd); 500 ret = sr030pc30_set_params(sd);
495 if (ret) 501 if (ret)
@@ -523,25 +529,28 @@ static const struct sr030pc30_format *try_fmt(struct v4l2_subdev *sd,
523} 529}
524 530
525/* Return nearest media bus frame format. */ 531/* Return nearest media bus frame format. */
526static int sr030pc30_try_fmt(struct v4l2_subdev *sd, 532static int sr030pc30_set_fmt(struct v4l2_subdev *sd,
527 struct v4l2_mbus_framefmt *mf) 533 struct v4l2_subdev_pad_config *cfg,
534 struct v4l2_subdev_format *format)
528{ 535{
529 if (!sd || !mf) 536 struct sr030pc30_info *info = sd ? to_sr030pc30(sd) : NULL;
530 return -EINVAL; 537 const struct sr030pc30_format *fmt;
531 538 struct v4l2_mbus_framefmt *mf;
532 try_fmt(sd, mf);
533 return 0;
534}
535 539
536static int sr030pc30_s_fmt(struct v4l2_subdev *sd, 540 if (!sd || !format)
537 struct v4l2_mbus_framefmt *mf) 541 return -EINVAL;
538{
539 struct sr030pc30_info *info = to_sr030pc30(sd);
540 542
541 if (!sd || !mf) 543 mf = &format->format;
544 if (format->pad)
542 return -EINVAL; 545 return -EINVAL;
543 546
544 info->curr_fmt = try_fmt(sd, mf); 547 fmt = try_fmt(sd, mf);
548 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
549 cfg->try_fmt = *mf;
550 return 0;
551 }
552
553 info->curr_fmt = fmt;
545 554
546 return sr030pc30_set_params(sd); 555 return sr030pc30_set_params(sd);
547} 556}
@@ -636,16 +645,15 @@ static const struct v4l2_subdev_core_ops sr030pc30_core_ops = {
636 .querymenu = v4l2_subdev_querymenu, 645 .querymenu = v4l2_subdev_querymenu,
637}; 646};
638 647
639static const struct v4l2_subdev_video_ops sr030pc30_video_ops = { 648static const struct v4l2_subdev_pad_ops sr030pc30_pad_ops = {
640 .g_mbus_fmt = sr030pc30_g_fmt, 649 .enum_mbus_code = sr030pc30_enum_mbus_code,
641 .s_mbus_fmt = sr030pc30_s_fmt, 650 .get_fmt = sr030pc30_get_fmt,
642 .try_mbus_fmt = sr030pc30_try_fmt, 651 .set_fmt = sr030pc30_set_fmt,
643 .enum_mbus_fmt = sr030pc30_enum_fmt,
644}; 652};
645 653
646static const struct v4l2_subdev_ops sr030pc30_ops = { 654static const struct v4l2_subdev_ops sr030pc30_ops = {
647 .core = &sr030pc30_core_ops, 655 .core = &sr030pc30_core_ops,
648 .video = &sr030pc30_video_ops, 656 .pad = &sr030pc30_pad_ops,
649}; 657};
650 658
651/* 659/*
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index 070c152da95a..0c50e5285cf6 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -272,7 +272,7 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
272 return -EINVAL; 272 return -EINVAL;
273 } 273 }
274 274
275 /* FIXME: it seems that the shadow bytes are wrong bellow !*/ 275 /* FIXME: it seems that the shadow bytes are wrong below !*/
276 276
277 /* update our shadow register set; print bytes if (debug > 0) */ 277 /* update our shadow register set; print bytes if (debug > 0) */
278 v4l2_dbg(1, debug, sd, "chip_cmd(%s): reg=%d, data:", 278 v4l2_dbg(1, debug, sd, "chip_cmd(%s): reg=%d, data:",
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 1c6bc306ecdc..24e47279e30c 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -747,54 +747,6 @@ static int tvp514x_s_ctrl(struct v4l2_ctrl *ctrl)
747} 747}
748 748
749/** 749/**
750 * tvp514x_enum_mbus_fmt() - V4L2 decoder interface handler for enum_mbus_fmt
751 * @sd: pointer to standard V4L2 sub-device structure
752 * @index: index of pixelcode to retrieve
753 * @code: receives the pixelcode
754 *
755 * Enumerates supported mediabus formats
756 */
757static int
758tvp514x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
759 u32 *code)
760{
761 if (index)
762 return -EINVAL;
763
764 *code = MEDIA_BUS_FMT_YUYV10_2X10;
765 return 0;
766}
767
768/**
769 * tvp514x_mbus_fmt() - V4L2 decoder interface handler for try/s/g_mbus_fmt
770 * @sd: pointer to standard V4L2 sub-device structure
771 * @f: pointer to the mediabus format structure
772 *
773 * Negotiates the image capture size and mediabus format.
774 */
775static int
776tvp514x_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
777{
778 struct tvp514x_decoder *decoder = to_decoder(sd);
779 enum tvp514x_std current_std;
780
781 if (f == NULL)
782 return -EINVAL;
783
784 /* Calculate height and width based on current standard */
785 current_std = decoder->current_std;
786
787 f->code = MEDIA_BUS_FMT_YUYV8_2X8;
788 f->width = decoder->std_list[current_std].width;
789 f->height = decoder->std_list[current_std].height;
790 f->field = V4L2_FIELD_INTERLACED;
791 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
792 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n",
793 f->width, f->height);
794 return 0;
795}
796
797/**
798 * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm 750 * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm
799 * @sd: pointer to standard V4L2 sub-device structure 751 * @sd: pointer to standard V4L2 sub-device structure
800 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure 752 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
@@ -962,6 +914,9 @@ static int tvp514x_get_pad_format(struct v4l2_subdev *sd,
962 struct tvp514x_decoder *decoder = to_decoder(sd); 914 struct tvp514x_decoder *decoder = to_decoder(sd);
963 __u32 which = format->which; 915 __u32 which = format->which;
964 916
917 if (format->pad)
918 return -EINVAL;
919
965 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) { 920 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
966 format->format = decoder->format; 921 format->format = decoder->format;
967 return 0; 922 return 0;
@@ -1016,10 +971,6 @@ static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
1016 .s_std = tvp514x_s_std, 971 .s_std = tvp514x_s_std,
1017 .s_routing = tvp514x_s_routing, 972 .s_routing = tvp514x_s_routing,
1018 .querystd = tvp514x_querystd, 973 .querystd = tvp514x_querystd,
1019 .enum_mbus_fmt = tvp514x_enum_mbus_fmt,
1020 .g_mbus_fmt = tvp514x_mbus_fmt,
1021 .try_mbus_fmt = tvp514x_mbus_fmt,
1022 .s_mbus_fmt = tvp514x_mbus_fmt,
1023 .g_parm = tvp514x_g_parm, 974 .g_parm = tvp514x_g_parm,
1024 .s_parm = tvp514x_s_parm, 975 .s_parm = tvp514x_s_parm,
1025 .s_stream = tvp514x_s_stream, 976 .s_stream = tvp514x_s_stream,
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 68cdab9c0903..e4fa0746f75e 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -817,24 +817,29 @@ static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd)
817 } 817 }
818} 818}
819 819
820static int tvp5150_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index, 820static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd,
821 u32 *code) 821 struct v4l2_subdev_pad_config *cfg,
822 struct v4l2_subdev_mbus_code_enum *code)
822{ 823{
823 if (index) 824 if (code->pad || code->index)
824 return -EINVAL; 825 return -EINVAL;
825 826
826 *code = MEDIA_BUS_FMT_UYVY8_2X8; 827 code->code = MEDIA_BUS_FMT_UYVY8_2X8;
827 return 0; 828 return 0;
828} 829}
829 830
830static int tvp5150_mbus_fmt(struct v4l2_subdev *sd, 831static int tvp5150_fill_fmt(struct v4l2_subdev *sd,
831 struct v4l2_mbus_framefmt *f) 832 struct v4l2_subdev_pad_config *cfg,
833 struct v4l2_subdev_format *format)
832{ 834{
835 struct v4l2_mbus_framefmt *f;
833 struct tvp5150 *decoder = to_tvp5150(sd); 836 struct tvp5150 *decoder = to_tvp5150(sd);
834 837
835 if (f == NULL) 838 if (!format || format->pad)
836 return -EINVAL; 839 return -EINVAL;
837 840
841 f = &format->format;
842
838 tvp5150_reset(sd, 0); 843 tvp5150_reset(sd, 0);
839 844
840 f->width = decoder->rect.width; 845 f->width = decoder->rect.width;
@@ -1068,10 +1073,6 @@ static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
1068static const struct v4l2_subdev_video_ops tvp5150_video_ops = { 1073static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
1069 .s_std = tvp5150_s_std, 1074 .s_std = tvp5150_s_std,
1070 .s_routing = tvp5150_s_routing, 1075 .s_routing = tvp5150_s_routing,
1071 .enum_mbus_fmt = tvp5150_enum_mbus_fmt,
1072 .s_mbus_fmt = tvp5150_mbus_fmt,
1073 .try_mbus_fmt = tvp5150_mbus_fmt,
1074 .g_mbus_fmt = tvp5150_mbus_fmt,
1075 .s_crop = tvp5150_s_crop, 1076 .s_crop = tvp5150_s_crop,
1076 .g_crop = tvp5150_g_crop, 1077 .g_crop = tvp5150_g_crop,
1077 .cropcap = tvp5150_cropcap, 1078 .cropcap = tvp5150_cropcap,
@@ -1084,11 +1085,18 @@ static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
1084 .s_raw_fmt = tvp5150_s_raw_fmt, 1085 .s_raw_fmt = tvp5150_s_raw_fmt,
1085}; 1086};
1086 1087
1088static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = {
1089 .enum_mbus_code = tvp5150_enum_mbus_code,
1090 .set_fmt = tvp5150_fill_fmt,
1091 .get_fmt = tvp5150_fill_fmt,
1092};
1093
1087static const struct v4l2_subdev_ops tvp5150_ops = { 1094static const struct v4l2_subdev_ops tvp5150_ops = {
1088 .core = &tvp5150_core_ops, 1095 .core = &tvp5150_core_ops,
1089 .tuner = &tvp5150_tuner_ops, 1096 .tuner = &tvp5150_tuner_ops,
1090 .video = &tvp5150_video_ops, 1097 .video = &tvp5150_video_ops,
1091 .vbi = &tvp5150_vbi_ops, 1098 .vbi = &tvp5150_vbi_ops,
1099 .pad = &tvp5150_pad_ops,
1092}; 1100};
1093 1101
1094 1102
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 787cdfb08749..05077cffd235 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -611,31 +611,6 @@ static int tvp7002_s_ctrl(struct v4l2_ctrl *ctrl)
611} 611}
612 612
613/* 613/*
614 * tvp7002_mbus_fmt() - V4L2 decoder interface handler for try/s/g_mbus_fmt
615 * @sd: pointer to standard V4L2 sub-device structure
616 * @f: pointer to mediabus format structure
617 *
618 * Negotiate the image capture size and mediabus format.
619 * There is only one possible format, so this single function works for
620 * get, set and try.
621 */
622static int tvp7002_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
623{
624 struct tvp7002 *device = to_tvp7002(sd);
625 const struct v4l2_bt_timings *bt = &device->current_timings->timings.bt;
626
627 f->width = bt->width;
628 f->height = bt->height;
629 f->code = MEDIA_BUS_FMT_YUYV10_1X20;
630 f->field = device->current_timings->scanmode;
631 f->colorspace = device->current_timings->color_space;
632
633 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d",
634 f->width, f->height);
635 return 0;
636}
637
638/*
639 * tvp7002_query_dv() - query DV timings 614 * tvp7002_query_dv() - query DV timings
640 * @sd: pointer to standard V4L2 sub-device structure 615 * @sd: pointer to standard V4L2 sub-device structure
641 * @index: index into the tvp7002_timings array 616 * @index: index into the tvp7002_timings array
@@ -747,25 +722,6 @@ static int tvp7002_s_register(struct v4l2_subdev *sd,
747#endif 722#endif
748 723
749/* 724/*
750 * tvp7002_enum_mbus_fmt() - Enum supported mediabus formats
751 * @sd: pointer to standard V4L2 sub-device structure
752 * @index: format index
753 * @code: pointer to mediabus format
754 *
755 * Enumerate supported mediabus formats.
756 */
757
758static int tvp7002_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
759 u32 *code)
760{
761 /* Check requested format index is within range */
762 if (index)
763 return -EINVAL;
764 *code = MEDIA_BUS_FMT_YUYV10_1X20;
765 return 0;
766}
767
768/*
769 * tvp7002_s_stream() - V4L2 decoder i/f handler for s_stream 725 * tvp7002_s_stream() - V4L2 decoder i/f handler for s_stream
770 * @sd: pointer to standard V4L2 sub-device structure 726 * @sd: pointer to standard V4L2 sub-device structure
771 * @enable: streaming enable or disable 727 * @enable: streaming enable or disable
@@ -924,10 +880,6 @@ static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
924 .s_dv_timings = tvp7002_s_dv_timings, 880 .s_dv_timings = tvp7002_s_dv_timings,
925 .query_dv_timings = tvp7002_query_dv_timings, 881 .query_dv_timings = tvp7002_query_dv_timings,
926 .s_stream = tvp7002_s_stream, 882 .s_stream = tvp7002_s_stream,
927 .g_mbus_fmt = tvp7002_mbus_fmt,
928 .try_mbus_fmt = tvp7002_mbus_fmt,
929 .s_mbus_fmt = tvp7002_mbus_fmt,
930 .enum_mbus_fmt = tvp7002_enum_mbus_fmt,
931}; 883};
932 884
933/* media pad related operation handlers */ 885/* media pad related operation handlers */
diff --git a/drivers/media/i2c/vs6624.c b/drivers/media/i2c/vs6624.c
index 00e7f043977e..4c72a18c0b8c 100644
--- a/drivers/media/i2c/vs6624.c
+++ b/drivers/media/i2c/vs6624.c
@@ -557,21 +557,28 @@ static int vs6624_s_ctrl(struct v4l2_ctrl *ctrl)
557 return 0; 557 return 0;
558} 558}
559 559
560static int vs6624_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index, 560static int vs6624_enum_mbus_code(struct v4l2_subdev *sd,
561 u32 *code) 561 struct v4l2_subdev_pad_config *cfg,
562 struct v4l2_subdev_mbus_code_enum *code)
562{ 563{
563 if (index >= ARRAY_SIZE(vs6624_formats)) 564 if (code->pad || code->index >= ARRAY_SIZE(vs6624_formats))
564 return -EINVAL; 565 return -EINVAL;
565 566
566 *code = vs6624_formats[index].mbus_code; 567 code->code = vs6624_formats[code->index].mbus_code;
567 return 0; 568 return 0;
568} 569}
569 570
570static int vs6624_try_mbus_fmt(struct v4l2_subdev *sd, 571static int vs6624_set_fmt(struct v4l2_subdev *sd,
571 struct v4l2_mbus_framefmt *fmt) 572 struct v4l2_subdev_pad_config *cfg,
573 struct v4l2_subdev_format *format)
572{ 574{
575 struct v4l2_mbus_framefmt *fmt = &format->format;
576 struct vs6624 *sensor = to_vs6624(sd);
573 int index; 577 int index;
574 578
579 if (format->pad)
580 return -EINVAL;
581
575 for (index = 0; index < ARRAY_SIZE(vs6624_formats); index++) 582 for (index = 0; index < ARRAY_SIZE(vs6624_formats); index++)
576 if (vs6624_formats[index].mbus_code == fmt->code) 583 if (vs6624_formats[index].mbus_code == fmt->code)
577 break; 584 break;
@@ -590,18 +597,11 @@ static int vs6624_try_mbus_fmt(struct v4l2_subdev *sd,
590 fmt->height = fmt->height & (~3); 597 fmt->height = fmt->height & (~3);
591 fmt->field = V4L2_FIELD_NONE; 598 fmt->field = V4L2_FIELD_NONE;
592 fmt->colorspace = vs6624_formats[index].colorspace; 599 fmt->colorspace = vs6624_formats[index].colorspace;
593 return 0;
594}
595
596static int vs6624_s_mbus_fmt(struct v4l2_subdev *sd,
597 struct v4l2_mbus_framefmt *fmt)
598{
599 struct vs6624 *sensor = to_vs6624(sd);
600 int ret;
601 600
602 ret = vs6624_try_mbus_fmt(sd, fmt); 601 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
603 if (ret) 602 cfg->try_fmt = *fmt;
604 return ret; 603 return 0;
604 }
605 605
606 /* set image format */ 606 /* set image format */
607 switch (fmt->code) { 607 switch (fmt->code) {
@@ -648,12 +648,16 @@ static int vs6624_s_mbus_fmt(struct v4l2_subdev *sd,
648 return 0; 648 return 0;
649} 649}
650 650
651static int vs6624_g_mbus_fmt(struct v4l2_subdev *sd, 651static int vs6624_get_fmt(struct v4l2_subdev *sd,
652 struct v4l2_mbus_framefmt *fmt) 652 struct v4l2_subdev_pad_config *cfg,
653 struct v4l2_subdev_format *format)
653{ 654{
654 struct vs6624 *sensor = to_vs6624(sd); 655 struct vs6624 *sensor = to_vs6624(sd);
655 656
656 *fmt = sensor->fmt; 657 if (format->pad)
658 return -EINVAL;
659
660 format->format = sensor->fmt;
657 return 0; 661 return 0;
658} 662}
659 663
@@ -738,18 +742,21 @@ static const struct v4l2_subdev_core_ops vs6624_core_ops = {
738}; 742};
739 743
740static const struct v4l2_subdev_video_ops vs6624_video_ops = { 744static const struct v4l2_subdev_video_ops vs6624_video_ops = {
741 .enum_mbus_fmt = vs6624_enum_mbus_fmt,
742 .try_mbus_fmt = vs6624_try_mbus_fmt,
743 .s_mbus_fmt = vs6624_s_mbus_fmt,
744 .g_mbus_fmt = vs6624_g_mbus_fmt,
745 .s_parm = vs6624_s_parm, 745 .s_parm = vs6624_s_parm,
746 .g_parm = vs6624_g_parm, 746 .g_parm = vs6624_g_parm,
747 .s_stream = vs6624_s_stream, 747 .s_stream = vs6624_s_stream,
748}; 748};
749 749
750static const struct v4l2_subdev_pad_ops vs6624_pad_ops = {
751 .enum_mbus_code = vs6624_enum_mbus_code,
752 .get_fmt = vs6624_get_fmt,
753 .set_fmt = vs6624_set_fmt,
754};
755
750static const struct v4l2_subdev_ops vs6624_ops = { 756static const struct v4l2_subdev_ops vs6624_ops = {
751 .core = &vs6624_core_ops, 757 .core = &vs6624_core_ops,
752 .video = &vs6624_video_ops, 758 .video = &vs6624_video_ops,
759 .pad = &vs6624_pad_ops,
753}; 760};
754 761
755static int vs6624_probe(struct i2c_client *client, 762static int vs6624_probe(struct i2c_client *client,
diff --git a/drivers/media/pci/Kconfig b/drivers/media/pci/Kconfig
index 218144a99016..f318ae9bb57a 100644
--- a/drivers/media/pci/Kconfig
+++ b/drivers/media/pci/Kconfig
@@ -21,6 +21,7 @@ source "drivers/media/pci/zoran/Kconfig"
21source "drivers/media/pci/saa7146/Kconfig" 21source "drivers/media/pci/saa7146/Kconfig"
22source "drivers/media/pci/solo6x10/Kconfig" 22source "drivers/media/pci/solo6x10/Kconfig"
23source "drivers/media/pci/tw68/Kconfig" 23source "drivers/media/pci/tw68/Kconfig"
24source "drivers/media/pci/dt3155/Kconfig"
24endif 25endif
25 26
26if MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT 27if MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT
@@ -32,6 +33,7 @@ source "drivers/media/pci/cx88/Kconfig"
32source "drivers/media/pci/bt8xx/Kconfig" 33source "drivers/media/pci/bt8xx/Kconfig"
33source "drivers/media/pci/saa7134/Kconfig" 34source "drivers/media/pci/saa7134/Kconfig"
34source "drivers/media/pci/saa7164/Kconfig" 35source "drivers/media/pci/saa7164/Kconfig"
36source "drivers/media/pci/cobalt/Kconfig"
35 37
36endif 38endif
37 39
diff --git a/drivers/media/pci/Makefile b/drivers/media/pci/Makefile
index 0baf0d2967ee..23ce53bd47c3 100644
--- a/drivers/media/pci/Makefile
+++ b/drivers/media/pci/Makefile
@@ -24,6 +24,8 @@ obj-$(CONFIG_VIDEO_BT848) += bt8xx/
24obj-$(CONFIG_VIDEO_SAA7134) += saa7134/ 24obj-$(CONFIG_VIDEO_SAA7134) += saa7134/
25obj-$(CONFIG_VIDEO_SAA7164) += saa7164/ 25obj-$(CONFIG_VIDEO_SAA7164) += saa7164/
26obj-$(CONFIG_VIDEO_TW68) += tw68/ 26obj-$(CONFIG_VIDEO_TW68) += tw68/
27obj-$(CONFIG_VIDEO_DT3155) += dt3155/
27obj-$(CONFIG_VIDEO_MEYE) += meye/ 28obj-$(CONFIG_VIDEO_MEYE) += meye/
28obj-$(CONFIG_STA2X11_VIP) += sta2x11/ 29obj-$(CONFIG_STA2X11_VIP) += sta2x11/
29obj-$(CONFIG_VIDEO_SOLO6X10) += solo6x10/ 30obj-$(CONFIG_VIDEO_SOLO6X10) += solo6x10/
31obj-$(CONFIG_VIDEO_COBALT) += cobalt/
diff --git a/drivers/media/pci/bt8xx/bttv-audio-hook.c b/drivers/media/pci/bt8xx/bttv-audio-hook.c
index 2364d16586b3..9f1f9169fb5b 100644
--- a/drivers/media/pci/bt8xx/bttv-audio-hook.c
+++ b/drivers/media/pci/bt8xx/bttv-audio-hook.c
@@ -54,23 +54,33 @@ void winview_volume(struct bttv *btv, __u16 volume)
54 54
55void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set) 55void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
56{ 56{
57 unsigned int con = 0; 57 unsigned int con;
58 58
59 if (set) { 59 if (!set) {
60 gpio_inout(0x300, 0x300); 60 /* Not much to do here */
61 if (t->audmode & V4L2_TUNER_MODE_LANG1) 61 t->audmode = V4L2_TUNER_MODE_LANG1;
62 con = 0x000; 62 t->rxsubchans = V4L2_TUNER_SUB_MONO |
63 if (t->audmode & V4L2_TUNER_MODE_LANG2) 63 V4L2_TUNER_SUB_STEREO |
64 con = 0x300; 64 V4L2_TUNER_SUB_LANG1 |
65 if (t->audmode & V4L2_TUNER_MODE_STEREO) 65 V4L2_TUNER_SUB_LANG2;
66 con = 0x200; 66
67/* if (t->audmode & V4L2_TUNER_MODE_MONO) 67 return;
68 * con = 0x100; */ 68 }
69 gpio_bits(0x300, con); 69
70 } else { 70 gpio_inout(0x300, 0x300);
71 t->audmode = V4L2_TUNER_MODE_STEREO | 71 switch (t->audmode) {
72 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; 72 case V4L2_TUNER_MODE_LANG1:
73 default:
74 con = 0x000;
75 break;
76 case V4L2_TUNER_MODE_LANG2:
77 con = 0x300;
78 break;
79 case V4L2_TUNER_MODE_STEREO:
80 con = 0x200;
81 break;
73 } 82 }
83 gpio_bits(0x300, con);
74} 84}
75 85
76void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set) 86void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
@@ -82,47 +92,51 @@ void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
82 92
83 val = gpio_read(); 93 val = gpio_read();
84 if (set) { 94 if (set) {
85 con = 0x000; 95 switch (t->audmode) {
86 if (t->audmode & V4L2_TUNER_MODE_LANG2) { 96 case V4L2_TUNER_MODE_LANG2:
87 if (t->audmode & V4L2_TUNER_MODE_LANG1) { 97 con = 0x300;
88 /* LANG1 + LANG2 */ 98 break;
89 con = 0x100; 99 case V4L2_TUNER_MODE_LANG1_LANG2:
90 } 100 con = 0x100;
91 else { 101 break;
92 /* LANG2 */ 102 default:
93 con = 0x300; 103 con = 0x000;
94 } 104 break;
95 } 105 }
96 if (con != (val & 0x300)) { 106 if (con != (val & 0x300)) {
97 gpio_bits(0x300, con); 107 gpio_bits(0x300, con);
98 if (bttv_gpio) 108 if (bttv_gpio)
99 bttv_gpio_tracking(btv,"gvbctv5pci"); 109 bttv_gpio_tracking(btv, "gvbctv5pci");
100 } 110 }
101 } else { 111 } else {
102 switch (val & 0x70) { 112 switch (val & 0x70) {
103 case 0x10: 113 case 0x10:
104 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 114 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
115 t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
105 break; 116 break;
106 case 0x30: 117 case 0x30:
107 t->rxsubchans = V4L2_TUNER_SUB_LANG2; 118 t->rxsubchans = V4L2_TUNER_SUB_LANG2;
119 t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
108 break; 120 break;
109 case 0x50: 121 case 0x50:
110 t->rxsubchans = V4L2_TUNER_SUB_LANG1; 122 t->rxsubchans = V4L2_TUNER_SUB_LANG1;
123 t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
111 break; 124 break;
112 case 0x60: 125 case 0x60:
113 t->rxsubchans = V4L2_TUNER_SUB_STEREO; 126 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
127 t->audmode = V4L2_TUNER_MODE_STEREO;
114 break; 128 break;
115 case 0x70: 129 case 0x70:
116 t->rxsubchans = V4L2_TUNER_SUB_MONO; 130 t->rxsubchans = V4L2_TUNER_SUB_MONO;
131 t->audmode = V4L2_TUNER_MODE_MONO;
117 break; 132 break;
118 default: 133 default:
119 t->rxsubchans = V4L2_TUNER_SUB_MONO | 134 t->rxsubchans = V4L2_TUNER_SUB_MONO |
120 V4L2_TUNER_SUB_STEREO | 135 V4L2_TUNER_SUB_STEREO |
121 V4L2_TUNER_SUB_LANG1 | 136 V4L2_TUNER_SUB_LANG1 |
122 V4L2_TUNER_SUB_LANG2; 137 V4L2_TUNER_SUB_LANG2;
138 t->audmode = V4L2_TUNER_MODE_LANG1;
123 } 139 }
124 t->audmode = V4L2_TUNER_MODE_STEREO |
125 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
126 } 140 }
127} 141}
128 142
@@ -142,23 +156,32 @@ void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
142 156
143void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set) 157void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
144{ 158{
145 int val = 0; 159 int val;
146 160
147 if (set) { 161 if (!set) {
148 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */ 162 /* Not much to do here */
149 val = 0x02; 163 t->audmode = V4L2_TUNER_MODE_LANG1;
150 if (t->audmode & V4L2_TUNER_MODE_STEREO) 164 t->rxsubchans = V4L2_TUNER_SUB_MONO |
151 val = 0x01; 165 V4L2_TUNER_SUB_STEREO |
152 if (val) { 166 V4L2_TUNER_SUB_LANG1 |
153 gpio_bits(0x03,val); 167 V4L2_TUNER_SUB_LANG2;
154 if (bttv_gpio) 168
155 bttv_gpio_tracking(btv,"avermedia"); 169 return;
156 } 170 }
157 } else { 171
158 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO | 172 switch (t->audmode) {
159 V4L2_TUNER_MODE_LANG1; 173 case V4L2_TUNER_MODE_LANG2: /* SAP */
174 val = 0x02;
175 break;
176 case V4L2_TUNER_MODE_STEREO:
177 val = 0x01;
178 break;
179 default:
160 return; 180 return;
161 } 181 }
182 gpio_bits(0x03, val);
183 if (bttv_gpio)
184 bttv_gpio_tracking(btv, "avermedia");
162} 185}
163 186
164 187
@@ -166,19 +189,31 @@ void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
166{ 189{
167 int val = 0; 190 int val = 0;
168 191
169 if (set) { 192 if (!set) {
170 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */ 193 /* Not much to do here */
171 val = 0x01; 194 t->audmode = V4L2_TUNER_MODE_LANG1;
172 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */ 195 t->rxsubchans = V4L2_TUNER_SUB_MONO |
173 val = 0x02; 196 V4L2_TUNER_SUB_STEREO |
174 btaor(val, ~0x03, BT848_GPIO_DATA); 197 V4L2_TUNER_SUB_LANG1 |
175 if (bttv_gpio) 198 V4L2_TUNER_SUB_LANG2;
176 bttv_gpio_tracking(btv,"avermedia"); 199
177 } else {
178 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
179 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
180 return; 200 return;
181 } 201 }
202
203 switch (t->audmode) {
204 case V4L2_TUNER_MODE_LANG2: /* SAP */
205 val = 0x01;
206 break;
207 case V4L2_TUNER_MODE_STEREO:
208 val = 0x02;
209 break;
210 default:
211 val = 0;
212 break;
213 }
214 btaor(val, ~0x03, BT848_GPIO_DATA);
215 if (bttv_gpio)
216 bttv_gpio_tracking(btv, "avermedia");
182} 217}
183 218
184/* Lifetec 9415 handling */ 219/* Lifetec 9415 handling */
@@ -192,23 +227,32 @@ void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
192 return; 227 return;
193 } 228 }
194 229
195 if (set) { 230 if (!set) {
196 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */ 231 /* Not much to do here */
197 val = 0x0080; 232 t->audmode = V4L2_TUNER_MODE_LANG1;
198 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */ 233 t->rxsubchans = V4L2_TUNER_SUB_MONO |
199 val = 0x0880; 234 V4L2_TUNER_SUB_STEREO |
200 if ((t->audmode & V4L2_TUNER_MODE_LANG1) || 235 V4L2_TUNER_SUB_LANG1 |
201 (t->audmode & V4L2_TUNER_MODE_MONO)) 236 V4L2_TUNER_SUB_LANG2;
202 val = 0; 237
203 gpio_bits(0x0880, val);
204 if (bttv_gpio)
205 bttv_gpio_tracking(btv,"lt9415");
206 } else {
207 /* autodetect doesn't work with this card :-( */
208 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
209 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
210 return; 238 return;
211 } 239 }
240
241 switch (t->audmode) {
242 case V4L2_TUNER_MODE_LANG2: /* A2 SAP */
243 val = 0x0080;
244 break;
245 case V4L2_TUNER_MODE_STEREO: /* A2 stereo */
246 val = 0x0880;
247 break;
248 default:
249 val = 0;
250 break;
251 }
252
253 gpio_bits(0x0880, val);
254 if (bttv_gpio)
255 bttv_gpio_tracking(btv, "lt9415");
212} 256}
213 257
214/* TDA9821 on TerraTV+ Bt848, Bt878 */ 258/* TDA9821 on TerraTV+ Bt848, Bt878 */
@@ -216,45 +260,69 @@ void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
216{ 260{
217 unsigned int con = 0; 261 unsigned int con = 0;
218 262
219 if (set) { 263 if (!set) {
220 gpio_inout(0x180000,0x180000); 264 /* Not much to do here */
221 if (t->audmode & V4L2_TUNER_MODE_LANG2) 265 t->audmode = V4L2_TUNER_MODE_LANG1;
222 con = 0x080000; 266 t->rxsubchans = V4L2_TUNER_SUB_MONO |
223 if (t->audmode & V4L2_TUNER_MODE_STEREO) 267 V4L2_TUNER_SUB_STEREO |
224 con = 0x180000; 268 V4L2_TUNER_SUB_LANG1 |
225 gpio_bits(0x180000, con); 269 V4L2_TUNER_SUB_LANG2;
226 if (bttv_gpio) 270
227 bttv_gpio_tracking(btv,"terratv"); 271 return;
228 } else { 272 }
229 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO | 273
230 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; 274 gpio_inout(0x180000, 0x180000);
275 switch (t->audmode) {
276 case V4L2_TUNER_MODE_LANG2:
277 con = 0x080000;
278 break;
279 case V4L2_TUNER_MODE_STEREO:
280 con = 0x180000;
281 break;
282 default:
283 con = 0;
284 break;
231 } 285 }
286 gpio_bits(0x180000, con);
287 if (bttv_gpio)
288 bttv_gpio_tracking(btv, "terratv");
232} 289}
233 290
234 291
235void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set) 292void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
236{ 293{
237 unsigned long val = 0; 294 unsigned long val;
238 295
239 if (set) { 296 if (!set) {
240 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/ 297 /* Not much to do here */
241 if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */ 298 t->audmode = V4L2_TUNER_MODE_LANG1;
242 val = 0x420000; 299 t->rxsubchans = V4L2_TUNER_SUB_MONO |
243 if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */ 300 V4L2_TUNER_SUB_STEREO |
244 val = 0x420000; 301 V4L2_TUNER_SUB_LANG1 |
245 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */ 302 V4L2_TUNER_SUB_LANG2;
246 val = 0x410000; 303
247 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */ 304 return;
248 val = 0x020000;
249 if (val) {
250 gpio_bits(0x430000, val);
251 if (bttv_gpio)
252 bttv_gpio_tracking(btv,"winfast2000");
253 }
254 } else {
255 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
256 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
257 } 305 }
306
307 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
308 switch (t->audmode) {
309 case V4L2_TUNER_MODE_MONO:
310 case V4L2_TUNER_MODE_LANG1:
311 val = 0x420000;
312 break;
313 case V4L2_TUNER_MODE_LANG2: /* SAP */
314 val = 0x410000;
315 break;
316 case V4L2_TUNER_MODE_STEREO:
317 val = 0x020000;
318 break;
319 default:
320 return;
321 }
322
323 gpio_bits(0x430000, val);
324 if (bttv_gpio)
325 bttv_gpio_tracking(btv, "winfast2000");
258} 326}
259 327
260/* 328/*
@@ -272,23 +340,33 @@ void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
272 if (btv->radio_user) 340 if (btv->radio_user)
273 return; 341 return;
274 342
275 if (set) { 343 if (!set) {
276 if (t->audmode & V4L2_TUNER_MODE_MONO) { 344 /* Not much to do here */
277 val = 0x01; 345 t->audmode = V4L2_TUNER_MODE_LANG1;
278 } 346 t->rxsubchans = V4L2_TUNER_SUB_MONO |
279 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2)) 347 V4L2_TUNER_SUB_STEREO |
280 || (t->audmode & V4L2_TUNER_MODE_STEREO)) { 348 V4L2_TUNER_SUB_LANG1 |
281 val = 0x02; 349 V4L2_TUNER_SUB_LANG2;
282 } 350
283 if (val) { 351 return;
284 gpio_bits(0x03,val);
285 if (bttv_gpio)
286 bttv_gpio_tracking(btv,"pvbt878p9b");
287 }
288 } else {
289 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
290 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
291 } 352 }
353
354 switch (t->audmode) {
355 case V4L2_TUNER_MODE_MONO:
356 val = 0x01;
357 break;
358 case V4L2_TUNER_MODE_LANG1:
359 case V4L2_TUNER_MODE_LANG2:
360 case V4L2_TUNER_MODE_STEREO:
361 val = 0x02;
362 break;
363 default:
364 return;
365 }
366
367 gpio_bits(0x03, val);
368 if (bttv_gpio)
369 bttv_gpio_tracking(btv, "pvbt878p9b");
292} 370}
293 371
294/* 372/*
@@ -298,28 +376,37 @@ void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
298 */ 376 */
299void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set) 377void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
300{ 378{
301 unsigned int val = 0xffff; 379 unsigned int val;
302 380
303 if (btv->radio_user) 381 if (btv->radio_user)
304 return; 382 return;
305 383
306 if (set) { 384 if (!set) {
307 if (t->audmode & V4L2_TUNER_MODE_MONO) { 385 /* Not much to do here */
308 val = 0x0000; 386 t->audmode = V4L2_TUNER_MODE_LANG1;
309 } 387 t->rxsubchans = V4L2_TUNER_SUB_MONO |
310 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2)) 388 V4L2_TUNER_SUB_STEREO |
311 || (t->audmode & V4L2_TUNER_MODE_STEREO)) { 389 V4L2_TUNER_SUB_LANG1 |
312 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */ 390 V4L2_TUNER_SUB_LANG2;
313 } 391
314 if (val != 0xffff) { 392 return;
315 gpio_bits(0x1800, val);
316 if (bttv_gpio)
317 bttv_gpio_tracking(btv,"fv2000s");
318 }
319 } else {
320 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
321 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
322 } 393 }
394
395 switch (t->audmode) {
396 case V4L2_TUNER_MODE_MONO:
397 val = 0x0000;
398 break;
399 case V4L2_TUNER_MODE_LANG1:
400 case V4L2_TUNER_MODE_LANG2:
401 case V4L2_TUNER_MODE_STEREO:
402 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
403 break;
404 default:
405 return;
406 }
407 gpio_bits(0x1800, val);
408 if (bttv_gpio)
409 bttv_gpio_tracking(btv, "fv2000s");
323} 410}
324 411
325/* 412/*
@@ -328,26 +415,33 @@ void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
328 */ 415 */
329void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set) 416void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
330{ 417{
331 unsigned long val = 0; 418 unsigned long val;
332 419
333 if (set) { 420 if (!set) {
334 if (t->audmode & V4L2_TUNER_MODE_MONO) 421 /* Not much to do here */
335 val = 0x040000; 422 t->audmode = V4L2_TUNER_MODE_LANG1;
336 if (t->audmode & V4L2_TUNER_MODE_LANG1) 423 t->rxsubchans = V4L2_TUNER_SUB_MONO |
337 val = 0; 424 V4L2_TUNER_SUB_STEREO |
338 if (t->audmode & V4L2_TUNER_MODE_LANG2) 425 V4L2_TUNER_SUB_LANG1 |
339 val = 0x100000; 426 V4L2_TUNER_SUB_LANG2;
340 if (t->audmode & V4L2_TUNER_MODE_STEREO) 427
341 val = 0; 428 return;
342 if (val) { 429 }
343 gpio_bits(0x140000, val); 430
344 if (bttv_gpio) 431 switch (t->audmode) {
345 bttv_gpio_tracking(btv,"windvr"); 432 case V4L2_TUNER_MODE_MONO:
346 } 433 val = 0x040000;
347 } else { 434 break;
348 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO | 435 case V4L2_TUNER_MODE_LANG2:
349 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; 436 val = 0x100000;
437 break;
438 default:
439 return;
350 } 440 }
441
442 gpio_bits(0x140000, val);
443 if (bttv_gpio)
444 bttv_gpio_tracking(btv, "windvr");
351} 445}
352 446
353/* 447/*
@@ -360,23 +454,36 @@ void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
360 454
361 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */ 455 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
362 456
363 if (set) { 457 if (!set) {
364 /* btor(***, BT848_GPIO_OUT_EN); */ 458 /* Not much to do here */
365 if (t->audmode & V4L2_TUNER_MODE_LANG1) 459 t->audmode = V4L2_TUNER_MODE_LANG1;
366 con = 0x00000000; 460 t->rxsubchans = V4L2_TUNER_SUB_MONO |
367 if (t->audmode & V4L2_TUNER_MODE_LANG2) 461 V4L2_TUNER_SUB_STEREO |
368 con = 0x00180000; 462 V4L2_TUNER_SUB_LANG1 |
369 if (t->audmode & V4L2_TUNER_MODE_STEREO) 463 V4L2_TUNER_SUB_LANG2;
370 con = 0x00000000; 464
371 if (t->audmode & V4L2_TUNER_MODE_MONO) 465 return;
372 con = 0x00060000;
373 if (con != 0xffffff) {
374 gpio_bits(0x1e0000,con);
375 if (bttv_gpio)
376 bttv_gpio_tracking(btv, "adtvk503");
377 }
378 } else {
379 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
380 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
381 } 466 }
467
468 /* btor(***, BT848_GPIO_OUT_EN); */
469 switch (t->audmode) {
470 case V4L2_TUNER_MODE_LANG1:
471 con = 0x00000000;
472 break;
473 case V4L2_TUNER_MODE_LANG2:
474 con = 0x00180000;
475 break;
476 case V4L2_TUNER_MODE_STEREO:
477 con = 0x00000000;
478 break;
479 case V4L2_TUNER_MODE_MONO:
480 con = 0x00060000;
481 break;
482 default:
483 return;
484 }
485
486 gpio_bits(0x1e0000, con);
487 if (bttv_gpio)
488 bttv_gpio_tracking(btv, "adtvk503");
382} 489}
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index bc12060e0882..3632958f2158 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -2676,7 +2676,8 @@ static int bttv_s_fbuf(struct file *file, void *f,
2676 fh->ov.w.height = fb->fmt.height; 2676 fh->ov.w.height = fb->fmt.height;
2677 btv->init.ov.w.width = fb->fmt.width; 2677 btv->init.ov.w.width = fb->fmt.width;
2678 btv->init.ov.w.height = fb->fmt.height; 2678 btv->init.ov.w.height = fb->fmt.height;
2679 kfree(fh->ov.clips); 2679
2680 kfree(fh->ov.clips);
2680 fh->ov.clips = NULL; 2681 fh->ov.clips = NULL;
2681 fh->ov.nclips = 0; 2682 fh->ov.nclips = 0;
2682 2683
@@ -4238,6 +4239,7 @@ fail0:
4238 iounmap(btv->bt848_mmio); 4239 iounmap(btv->bt848_mmio);
4239 release_mem_region(pci_resource_start(btv->c.pci,0), 4240 release_mem_region(pci_resource_start(btv->c.pci,0),
4240 pci_resource_len(btv->c.pci,0)); 4241 pci_resource_len(btv->c.pci,0));
4242 pci_disable_device(btv->c.pci);
4241 return result; 4243 return result;
4242} 4244}
4243 4245
@@ -4281,6 +4283,7 @@ static void bttv_remove(struct pci_dev *pci_dev)
4281 iounmap(btv->bt848_mmio); 4283 iounmap(btv->bt848_mmio);
4282 release_mem_region(pci_resource_start(btv->c.pci,0), 4284 release_mem_region(pci_resource_start(btv->c.pci,0),
4283 pci_resource_len(btv->c.pci,0)); 4285 pci_resource_len(btv->c.pci,0));
4286 pci_disable_device(btv->c.pci);
4284 4287
4285 v4l2_device_unregister(&btv->c.v4l2_dev); 4288 v4l2_device_unregister(&btv->c.v4l2_dev);
4286 bttvs[btv->c.nr] = NULL; 4289 bttvs[btv->c.nr] = NULL;
diff --git a/drivers/media/pci/bt8xx/dst.c b/drivers/media/pci/bt8xx/dst.c
index f2261dfe5d1a..4a90eee5e3bb 100644
--- a/drivers/media/pci/bt8xx/dst.c
+++ b/drivers/media/pci/bt8xx/dst.c
@@ -425,7 +425,8 @@ static int dst_set_bandwidth(struct dst_state *state, u32 bandwidth)
425 return 0; 425 return 0;
426} 426}
427 427
428static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t inversion) 428static int dst_set_inversion(struct dst_state *state,
429 enum fe_spectral_inversion inversion)
429{ 430{
430 state->inversion = inversion; 431 state->inversion = inversion;
431 switch (inversion) { 432 switch (inversion) {
@@ -442,13 +443,13 @@ static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t in
442 return 0; 443 return 0;
443} 444}
444 445
445static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec) 446static int dst_set_fec(struct dst_state *state, enum fe_code_rate fec)
446{ 447{
447 state->fec = fec; 448 state->fec = fec;
448 return 0; 449 return 0;
449} 450}
450 451
451static fe_code_rate_t dst_get_fec(struct dst_state *state) 452static enum fe_code_rate dst_get_fec(struct dst_state *state)
452{ 453{
453 return state->fec; 454 return state->fec;
454} 455}
@@ -499,7 +500,8 @@ static int dst_set_symbolrate(struct dst_state *state, u32 srate)
499 return 0; 500 return 0;
500} 501}
501 502
502static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation) 503static int dst_set_modulation(struct dst_state *state,
504 enum fe_modulation modulation)
503{ 505{
504 if (state->dst_type != DST_TYPE_IS_CABLE) 506 if (state->dst_type != DST_TYPE_IS_CABLE)
505 return -EOPNOTSUPP; 507 return -EOPNOTSUPP;
@@ -536,7 +538,7 @@ static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulatio
536 return 0; 538 return 0;
537} 539}
538 540
539static fe_modulation_t dst_get_modulation(struct dst_state *state) 541static enum fe_modulation dst_get_modulation(struct dst_state *state)
540{ 542{
541 return state->modulation; 543 return state->modulation;
542} 544}
@@ -1376,7 +1378,8 @@ static int dst_get_tuna(struct dst_state *state)
1376 return 1; 1378 return 1;
1377} 1379}
1378 1380
1379static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 1381static int dst_set_voltage(struct dvb_frontend *fe,
1382 enum fe_sec_voltage voltage);
1380 1383
1381static int dst_write_tuna(struct dvb_frontend *fe) 1384static int dst_write_tuna(struct dvb_frontend *fe)
1382{ 1385{
@@ -1466,7 +1469,7 @@ static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd
1466 return dst_command(state, paket, 8); 1469 return dst_command(state, paket, 8);
1467} 1470}
1468 1471
1469static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 1472static int dst_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
1470{ 1473{
1471 int need_cmd, retval = 0; 1474 int need_cmd, retval = 0;
1472 struct dst_state *state = fe->demodulator_priv; 1475 struct dst_state *state = fe->demodulator_priv;
@@ -1500,7 +1503,7 @@ static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
1500 return retval; 1503 return retval;
1501} 1504}
1502 1505
1503static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 1506static int dst_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
1504{ 1507{
1505 struct dst_state *state = fe->demodulator_priv; 1508 struct dst_state *state = fe->demodulator_priv;
1506 1509
@@ -1525,7 +1528,7 @@ static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
1525 return dst_tone_power_cmd(state); 1528 return dst_tone_power_cmd(state);
1526} 1529}
1527 1530
1528static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd) 1531static int dst_send_burst(struct dvb_frontend *fe, enum fe_sec_mini_cmd minicmd)
1529{ 1532{
1530 struct dst_state *state = fe->demodulator_priv; 1533 struct dst_state *state = fe->demodulator_priv;
1531 1534
@@ -1575,7 +1578,7 @@ static int bt8xx_dst_init(struct dvb_frontend *fe)
1575 return 0; 1578 return 0;
1576} 1579}
1577 1580
1578static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status) 1581static int dst_read_status(struct dvb_frontend *fe, enum fe_status *status)
1579{ 1582{
1580 struct dst_state *state = fe->demodulator_priv; 1583 struct dst_state *state = fe->demodulator_priv;
1581 1584
@@ -1646,7 +1649,7 @@ static int dst_tune_frontend(struct dvb_frontend* fe,
1646 bool re_tune, 1649 bool re_tune,
1647 unsigned int mode_flags, 1650 unsigned int mode_flags,
1648 unsigned int *delay, 1651 unsigned int *delay,
1649 fe_status_t *status) 1652 enum fe_status *status)
1650{ 1653{
1651 struct dst_state *state = fe->demodulator_priv; 1654 struct dst_state *state = fe->demodulator_priv;
1652 struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1655 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
diff --git a/drivers/media/pci/bt8xx/dst_ca.c b/drivers/media/pci/bt8xx/dst_ca.c
index c22c4ae06844..c5cc14ef8347 100644
--- a/drivers/media/pci/bt8xx/dst_ca.c
+++ b/drivers/media/pci/bt8xx/dst_ca.c
@@ -320,29 +320,27 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message,
320 if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) 320 if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg)))
321 return -EFAULT; 321 return -EFAULT;
322 322
323 if (p_ca_message->msg) { 323 dprintk(verbose, DST_CA_NOTICE, 1, " Message = [%*ph]",
324 dprintk(verbose, DST_CA_NOTICE, 1, " Message = [%*ph]", 324 3, p_ca_message->msg);
325 3, p_ca_message->msg);
326
327 for (i = 0; i < 3; i++) {
328 command = command | p_ca_message->msg[i];
329 if (i < 2)
330 command = command << 8;
331 }
332 dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);
333 325
334 switch (command) { 326 for (i = 0; i < 3; i++) {
335 case CA_APP_INFO: 327 command = command | p_ca_message->msg[i];
336 memcpy(p_ca_message->msg, state->messages, 128); 328 if (i < 2)
337 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) ) 329 command = command << 8;
338 return -EFAULT; 330 }
339 break; 331 dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);
340 case CA_INFO: 332
341 memcpy(p_ca_message->msg, state->messages, 128); 333 switch (command) {
342 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) ) 334 case CA_APP_INFO:
343 return -EFAULT; 335 memcpy(p_ca_message->msg, state->messages, 128);
344 break; 336 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
345 } 337 return -EFAULT;
338 break;
339 case CA_INFO:
340 memcpy(p_ca_message->msg, state->messages, 128);
341 if (copy_to_user(arg, p_ca_message, sizeof (struct ca_msg)) )
342 return -EFAULT;
343 break;
346 } 344 }
347 345
348 return 0; 346 return 0;
@@ -494,60 +492,58 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
494 goto free_mem_and_exit; 492 goto free_mem_and_exit;
495 } 493 }
496 494
495 /* EN50221 tag */
496 command = 0;
497 497
498 if (p_ca_message->msg) { 498 for (i = 0; i < 3; i++) {
499 /* EN50221 tag */ 499 command = command | p_ca_message->msg[i];
500 command = 0; 500 if (i < 2)
501 command = command << 8;
502 }
503 dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);
501 504
502 for (i = 0; i < 3; i++) { 505 switch (command) {
503 command = command | p_ca_message->msg[i]; 506 case CA_PMT:
504 if (i < 2) 507 dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");
505 command = command << 8; 508 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
509 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");
510 result = -1;
511 goto free_mem_and_exit;
506 } 512 }
507 dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command); 513 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");
508 514 break;
509 switch (command) { 515 case CA_PMT_REPLY:
510 case CA_PMT: 516 dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");
511 dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT"); 517 /* Have to handle the 2 basic types of cards here */
512 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started 518 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
513 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !"); 519 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");
514 result = -1; 520 result = -1;
515 goto free_mem_and_exit; 521 goto free_mem_and_exit;
516 } 522 }
517 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !"); 523 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
518 break; 524 break;
519 case CA_PMT_REPLY: 525 case CA_APP_INFO_ENQUIRY: // only for debugging
520 dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY"); 526 dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
521 /* Have to handle the 2 basic types of cards here */ 527
522 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) { 528 if ((ca_get_app_info(state)) < 0) {
523 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !"); 529 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
524 result = -1; 530 result = -1;
525 goto free_mem_and_exit; 531 goto free_mem_and_exit;
526 }
527 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
528 break;
529 case CA_APP_INFO_ENQUIRY: // only for debugging
530 dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
531
532 if ((ca_get_app_info(state)) < 0) {
533 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
534 result = -1;
535 goto free_mem_and_exit;
536 }
537 dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
538 break;
539 case CA_INFO_ENQUIRY:
540 dprintk(verbose, DST_CA_INFO, 1, " Getting CA Information");
541
542 if ((ca_get_ca_info(state)) < 0) {
543 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_INFO_ENQUIRY Failed !");
544 result = -1;
545 goto free_mem_and_exit;
546 }
547 dprintk(verbose, DST_CA_INFO, 1, " -->CA_INFO_ENQUIRY Success !");
548 break;
549 } 532 }
533 dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
534 break;
535 case CA_INFO_ENQUIRY:
536 dprintk(verbose, DST_CA_INFO, 1, " Getting CA Information");
537
538 if ((ca_get_ca_info(state)) < 0) {
539 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_INFO_ENQUIRY Failed !");
540 result = -1;
541 goto free_mem_and_exit;
542 }
543 dprintk(verbose, DST_CA_INFO, 1, " -->CA_INFO_ENQUIRY Success !");
544 break;
550 } 545 }
546
551free_mem_and_exit: 547free_mem_and_exit:
552 kfree (hw_buffer); 548 kfree (hw_buffer);
553 549
diff --git a/drivers/media/pci/bt8xx/dst_common.h b/drivers/media/pci/bt8xx/dst_common.h
index d70d98f1a571..6a2cfdd44e3e 100644
--- a/drivers/media/pci/bt8xx/dst_common.h
+++ b/drivers/media/pci/bt8xx/dst_common.h
@@ -113,11 +113,11 @@ struct dst_state {
113 u8 dst_type; 113 u8 dst_type;
114 u32 type_flags; 114 u32 type_flags;
115 u32 frequency; /* intermediate frequency in kHz for QPSK */ 115 u32 frequency; /* intermediate frequency in kHz for QPSK */
116 fe_spectral_inversion_t inversion; 116 enum fe_spectral_inversion inversion;
117 u32 symbol_rate; /* symbol rate in Symbols per second */ 117 u32 symbol_rate; /* symbol rate in Symbols per second */
118 fe_code_rate_t fec; 118 enum fe_code_rate fec;
119 fe_sec_voltage_t voltage; 119 enum fe_sec_voltage voltage;
120 fe_sec_tone_mode_t tone; 120 enum fe_sec_tone_mode tone;
121 u32 decode_freq; 121 u32 decode_freq;
122 u8 decode_lock; 122 u8 decode_lock;
123 u16 decode_strength; 123 u16 decode_strength;
@@ -127,8 +127,8 @@ struct dst_state {
127 u32 bandwidth; 127 u32 bandwidth;
128 u32 dst_hw_cap; 128 u32 dst_hw_cap;
129 u8 dst_fw_version; 129 u8 dst_fw_version;
130 fe_sec_mini_cmd_t minicmd; 130 enum fe_sec_mini_cmd minicmd;
131 fe_modulation_t modulation; 131 enum fe_modulation modulation;
132 u8 messages[256]; 132 u8 messages[256];
133 u8 mac_address[8]; 133 u8 mac_address[8];
134 u8 fw_version[8]; 134 u8 fw_version[8];
diff --git a/drivers/media/pci/cobalt/Kconfig b/drivers/media/pci/cobalt/Kconfig
new file mode 100644
index 000000000000..3be1b2c3c386
--- /dev/null
+++ b/drivers/media/pci/cobalt/Kconfig
@@ -0,0 +1,18 @@
1config VIDEO_COBALT
2 tristate "Cisco Cobalt support"
3 depends on VIDEO_V4L2 && I2C && MEDIA_CONTROLLER
4 depends on PCI_MSI && MTD_COMPLEX_MAPPINGS && GPIOLIB
5 select I2C_ALGOBIT
6 select VIDEO_ADV7604
7 select VIDEO_ADV7511
8 select VIDEO_ADV7842
9 select VIDEOBUF2_DMA_SG
10 ---help---
11 This is a video4linux driver for the Cisco PCIe Cobalt card.
12
13 This board is sadly not available outside of Cisco, but it is
14 very useful as an example of a real driver that uses all the
15 latest frameworks and APIs.
16
17 To compile this driver as a module, choose M here: the
18 module will be called cobalt.
diff --git a/drivers/media/pci/cobalt/Makefile b/drivers/media/pci/cobalt/Makefile
new file mode 100644
index 000000000000..b328955abbd2
--- /dev/null
+++ b/drivers/media/pci/cobalt/Makefile
@@ -0,0 +1,5 @@
1cobalt-objs := cobalt-driver.o cobalt-irq.o cobalt-v4l2.o \
2 cobalt-i2c.o cobalt-omnitek.o cobalt-flash.o cobalt-cpld.o \
3 cobalt-alsa-main.o cobalt-alsa-pcm.o
4
5obj-$(CONFIG_VIDEO_COBALT) += cobalt.o
diff --git a/drivers/media/pci/cobalt/cobalt-alsa-main.c b/drivers/media/pci/cobalt/cobalt-alsa-main.c
new file mode 100644
index 000000000000..720e3ad93a9e
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-alsa-main.c
@@ -0,0 +1,162 @@
1/*
2 * ALSA interface to cobalt PCM capture streams
3 *
4 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/device.h>
26#include <linux/spinlock.h>
27
28#include <media/v4l2-device.h>
29
30#include <sound/core.h>
31#include <sound/initval.h>
32
33#include "cobalt-driver.h"
34#include "cobalt-alsa.h"
35#include "cobalt-alsa-pcm.h"
36
37static void snd_cobalt_card_free(struct snd_cobalt_card *cobsc)
38{
39 if (cobsc == NULL)
40 return;
41
42 cobsc->s->alsa = NULL;
43
44 kfree(cobsc);
45}
46
47static void snd_cobalt_card_private_free(struct snd_card *sc)
48{
49 if (sc == NULL)
50 return;
51 snd_cobalt_card_free(sc->private_data);
52 sc->private_data = NULL;
53 sc->private_free = NULL;
54}
55
56static int snd_cobalt_card_create(struct cobalt_stream *s,
57 struct snd_card *sc,
58 struct snd_cobalt_card **cobsc)
59{
60 *cobsc = kzalloc(sizeof(struct snd_cobalt_card), GFP_KERNEL);
61 if (*cobsc == NULL)
62 return -ENOMEM;
63
64 (*cobsc)->s = s;
65 (*cobsc)->sc = sc;
66
67 sc->private_data = *cobsc;
68 sc->private_free = snd_cobalt_card_private_free;
69
70 return 0;
71}
72
73static int snd_cobalt_card_set_names(struct snd_cobalt_card *cobsc)
74{
75 struct cobalt_stream *s = cobsc->s;
76 struct cobalt *cobalt = s->cobalt;
77 struct snd_card *sc = cobsc->sc;
78
79 /* sc->driver is used by alsa-lib's configurator: simple, unique */
80 strlcpy(sc->driver, "cobalt", sizeof(sc->driver));
81
82 /* sc->shortname is a symlink in /proc/asound: COBALT-M -> cardN */
83 snprintf(sc->shortname, sizeof(sc->shortname), "cobalt-%d-%d",
84 cobalt->instance, s->video_channel);
85
86 /* sc->longname is read from /proc/asound/cards */
87 snprintf(sc->longname, sizeof(sc->longname),
88 "Cobalt %d HDMI %d",
89 cobalt->instance, s->video_channel);
90
91 return 0;
92}
93
94int cobalt_alsa_init(struct cobalt_stream *s)
95{
96 struct cobalt *cobalt = s->cobalt;
97 struct snd_card *sc = NULL;
98 struct snd_cobalt_card *cobsc;
99 int ret;
100
101 /* Numbrs steps from "Writing an ALSA Driver" by Takashi Iwai */
102
103 /* (1) Check and increment the device index */
104 /* This is a no-op for us. We'll use the cobalt->instance */
105
106 /* (2) Create a card instance */
107 ret = snd_card_new(&cobalt->pci_dev->dev, SNDRV_DEFAULT_IDX1,
108 SNDRV_DEFAULT_STR1, THIS_MODULE, 0, &sc);
109 if (ret) {
110 cobalt_err("snd_card_new() failed with err %d\n", ret);
111 goto err_exit;
112 }
113
114 /* (3) Create a main component */
115 ret = snd_cobalt_card_create(s, sc, &cobsc);
116 if (ret) {
117 cobalt_err("snd_cobalt_card_create() failed with err %d\n",
118 ret);
119 goto err_exit_free;
120 }
121
122 /* (4) Set the driver ID and name strings */
123 snd_cobalt_card_set_names(cobsc);
124
125 ret = snd_cobalt_pcm_create(cobsc);
126 if (ret) {
127 cobalt_err("snd_cobalt_pcm_create() failed with err %d\n",
128 ret);
129 goto err_exit_free;
130 }
131 /* FIXME - proc files */
132
133 /* (7) Set the driver data and return 0 */
134 /* We do this out of normal order for PCI drivers to avoid races */
135 s->alsa = cobsc;
136
137 /* (6) Register the card instance */
138 ret = snd_card_register(sc);
139 if (ret) {
140 s->alsa = NULL;
141 cobalt_err("snd_card_register() failed with err %d\n", ret);
142 goto err_exit_free;
143 }
144
145 return 0;
146
147err_exit_free:
148 if (sc != NULL)
149 snd_card_free(sc);
150 kfree(cobsc);
151err_exit:
152 return ret;
153}
154
155void cobalt_alsa_exit(struct cobalt_stream *s)
156{
157 struct snd_cobalt_card *cobsc = s->alsa;
158
159 if (cobsc)
160 snd_card_free(cobsc->sc);
161 s->alsa = NULL;
162}
diff --git a/drivers/media/pci/cobalt/cobalt-alsa-pcm.c b/drivers/media/pci/cobalt/cobalt-alsa-pcm.c
new file mode 100644
index 000000000000..f0bdf10cfd57
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-alsa-pcm.c
@@ -0,0 +1,603 @@
1/*
2 * ALSA PCM device for the
3 * ALSA interface to cobalt PCM capture streams
4 *
5 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
6 * All rights reserved.
7 *
8 * This program is free software; you may redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
16 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
17 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 * SOFTWARE.
20 */
21
22#include <linux/init.h>
23#include <linux/kernel.h>
24#include <linux/vmalloc.h>
25#include <linux/delay.h>
26
27#include <media/v4l2-device.h>
28
29#include <sound/core.h>
30#include <sound/pcm.h>
31
32#include "cobalt-driver.h"
33#include "cobalt-alsa.h"
34#include "cobalt-alsa-pcm.h"
35
36static unsigned int pcm_debug;
37module_param(pcm_debug, int, 0644);
38MODULE_PARM_DESC(pcm_debug, "enable debug messages for pcm");
39
40#define dprintk(fmt, arg...) \
41 do { \
42 if (pcm_debug) \
43 pr_info("cobalt-alsa-pcm %s: " fmt, __func__, ##arg); \
44 } while (0)
45
46static struct snd_pcm_hardware snd_cobalt_hdmi_capture = {
47 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
48 SNDRV_PCM_INFO_MMAP |
49 SNDRV_PCM_INFO_INTERLEAVED |
50 SNDRV_PCM_INFO_MMAP_VALID,
51
52 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
53
54 .rates = SNDRV_PCM_RATE_48000,
55
56 .rate_min = 48000,
57 .rate_max = 48000,
58 .channels_min = 1,
59 .channels_max = 8,
60 .buffer_bytes_max = 4 * 240 * 8 * 4, /* 5 ms of data */
61 .period_bytes_min = 1920, /* 1 sample = 8 * 4 bytes */
62 .period_bytes_max = 240 * 8 * 4, /* 5 ms of 8 channel data */
63 .periods_min = 1,
64 .periods_max = 4,
65};
66
67static struct snd_pcm_hardware snd_cobalt_playback = {
68 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
69 SNDRV_PCM_INFO_MMAP |
70 SNDRV_PCM_INFO_INTERLEAVED |
71 SNDRV_PCM_INFO_MMAP_VALID,
72
73 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
74
75 .rates = SNDRV_PCM_RATE_48000,
76
77 .rate_min = 48000,
78 .rate_max = 48000,
79 .channels_min = 1,
80 .channels_max = 8,
81 .buffer_bytes_max = 4 * 240 * 8 * 4, /* 5 ms of data */
82 .period_bytes_min = 1920, /* 1 sample = 8 * 4 bytes */
83 .period_bytes_max = 240 * 8 * 4, /* 5 ms of 8 channel data */
84 .periods_min = 1,
85 .periods_max = 4,
86};
87
88static void sample_cpy(u8 *dst, const u8 *src, u32 len, bool is_s32)
89{
90 static const unsigned map[8] = { 0, 1, 5, 4, 2, 3, 6, 7 };
91 unsigned idx = 0;
92
93 while (len >= (is_s32 ? 4 : 2)) {
94 unsigned offset = map[idx] * 4;
95 u32 val = src[offset + 1] + (src[offset + 2] << 8) +
96 (src[offset + 3] << 16);
97
98 if (is_s32) {
99 *dst++ = 0;
100 *dst++ = val & 0xff;
101 }
102 *dst++ = (val >> 8) & 0xff;
103 *dst++ = (val >> 16) & 0xff;
104 len -= is_s32 ? 4 : 2;
105 idx++;
106 }
107}
108
109static void cobalt_alsa_announce_pcm_data(struct snd_cobalt_card *cobsc,
110 u8 *pcm_data,
111 size_t skip,
112 size_t samples)
113{
114 struct snd_pcm_substream *substream;
115 struct snd_pcm_runtime *runtime;
116 unsigned long flags;
117 unsigned int oldptr;
118 unsigned int stride;
119 int length = samples;
120 int period_elapsed = 0;
121 bool is_s32;
122
123 dprintk("cobalt alsa announce ptr=%p data=%p num_bytes=%zd\n", cobsc,
124 pcm_data, samples);
125
126 substream = cobsc->capture_pcm_substream;
127 if (substream == NULL) {
128 dprintk("substream was NULL\n");
129 return;
130 }
131
132 runtime = substream->runtime;
133 if (runtime == NULL) {
134 dprintk("runtime was NULL\n");
135 return;
136 }
137 is_s32 = runtime->format == SNDRV_PCM_FORMAT_S32_LE;
138
139 stride = runtime->frame_bits >> 3;
140 if (stride == 0) {
141 dprintk("stride is zero\n");
142 return;
143 }
144
145 if (length == 0) {
146 dprintk("%s: length was zero\n", __func__);
147 return;
148 }
149
150 if (runtime->dma_area == NULL) {
151 dprintk("dma area was NULL - ignoring\n");
152 return;
153 }
154
155 oldptr = cobsc->hwptr_done_capture;
156 if (oldptr + length >= runtime->buffer_size) {
157 unsigned int cnt = runtime->buffer_size - oldptr;
158 unsigned i;
159
160 for (i = 0; i < cnt; i++)
161 sample_cpy(runtime->dma_area + (oldptr + i) * stride,
162 pcm_data + i * skip,
163 stride, is_s32);
164 for (i = cnt; i < length; i++)
165 sample_cpy(runtime->dma_area + (i - cnt) * stride,
166 pcm_data + i * skip, stride, is_s32);
167 } else {
168 unsigned i;
169
170 for (i = 0; i < length; i++)
171 sample_cpy(runtime->dma_area + (oldptr + i) * stride,
172 pcm_data + i * skip,
173 stride, is_s32);
174 }
175 snd_pcm_stream_lock_irqsave(substream, flags);
176
177 cobsc->hwptr_done_capture += length;
178 if (cobsc->hwptr_done_capture >=
179 runtime->buffer_size)
180 cobsc->hwptr_done_capture -=
181 runtime->buffer_size;
182
183 cobsc->capture_transfer_done += length;
184 if (cobsc->capture_transfer_done >=
185 runtime->period_size) {
186 cobsc->capture_transfer_done -=
187 runtime->period_size;
188 period_elapsed = 1;
189 }
190
191 snd_pcm_stream_unlock_irqrestore(substream, flags);
192
193 if (period_elapsed)
194 snd_pcm_period_elapsed(substream);
195}
196
197static int alsa_fnc(struct vb2_buffer *vb, void *priv)
198{
199 struct cobalt_stream *s = priv;
200 unsigned char *p = vb2_plane_vaddr(vb, 0);
201 int i;
202
203 if (pcm_debug) {
204 pr_info("alsa: ");
205 for (i = 0; i < 8 * 4; i++) {
206 if (!(i & 3))
207 pr_cont(" ");
208 pr_cont("%02x", p[i]);
209 }
210 pr_cont("\n");
211 }
212 cobalt_alsa_announce_pcm_data(s->alsa,
213 vb2_plane_vaddr(vb, 0),
214 8 * 4,
215 vb2_get_plane_payload(vb, 0) / (8 * 4));
216 return 0;
217}
218
219static int snd_cobalt_pcm_capture_open(struct snd_pcm_substream *substream)
220{
221 struct snd_pcm_runtime *runtime = substream->runtime;
222 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
223 struct cobalt_stream *s = cobsc->s;
224
225 runtime->hw = snd_cobalt_hdmi_capture;
226 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
227 cobsc->capture_pcm_substream = substream;
228 runtime->private_data = s;
229 cobsc->alsa_record_cnt++;
230 if (cobsc->alsa_record_cnt == 1) {
231 int rc;
232
233 rc = vb2_thread_start(&s->q, alsa_fnc, s, s->vdev.name);
234 if (rc) {
235 cobsc->alsa_record_cnt--;
236 return rc;
237 }
238 }
239 return 0;
240}
241
242static int snd_cobalt_pcm_capture_close(struct snd_pcm_substream *substream)
243{
244 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
245 struct cobalt_stream *s = cobsc->s;
246
247 cobsc->alsa_record_cnt--;
248 if (cobsc->alsa_record_cnt == 0)
249 vb2_thread_stop(&s->q);
250 return 0;
251}
252
253static int snd_cobalt_pcm_ioctl(struct snd_pcm_substream *substream,
254 unsigned int cmd, void *arg)
255{
256 return snd_pcm_lib_ioctl(substream, cmd, arg);
257}
258
259
260static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
261 size_t size)
262{
263 struct snd_pcm_runtime *runtime = subs->runtime;
264
265 dprintk("Allocating vbuffer\n");
266 if (runtime->dma_area) {
267 if (runtime->dma_bytes > size)
268 return 0;
269
270 vfree(runtime->dma_area);
271 }
272 runtime->dma_area = vmalloc(size);
273 if (!runtime->dma_area)
274 return -ENOMEM;
275
276 runtime->dma_bytes = size;
277
278 return 0;
279}
280
281static int snd_cobalt_pcm_hw_params(struct snd_pcm_substream *substream,
282 struct snd_pcm_hw_params *params)
283{
284 dprintk("%s called\n", __func__);
285
286 return snd_pcm_alloc_vmalloc_buffer(substream,
287 params_buffer_bytes(params));
288}
289
290static int snd_cobalt_pcm_hw_free(struct snd_pcm_substream *substream)
291{
292 if (substream->runtime->dma_area) {
293 dprintk("freeing pcm capture region\n");
294 vfree(substream->runtime->dma_area);
295 substream->runtime->dma_area = NULL;
296 }
297
298 return 0;
299}
300
301static int snd_cobalt_pcm_prepare(struct snd_pcm_substream *substream)
302{
303 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
304
305 cobsc->hwptr_done_capture = 0;
306 cobsc->capture_transfer_done = 0;
307
308 return 0;
309}
310
311static int snd_cobalt_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
312{
313 switch (cmd) {
314 case SNDRV_PCM_TRIGGER_START:
315 case SNDRV_PCM_TRIGGER_STOP:
316 return 0;
317 default:
318 return -EINVAL;
319 }
320 return 0;
321}
322
323static
324snd_pcm_uframes_t snd_cobalt_pcm_pointer(struct snd_pcm_substream *substream)
325{
326 snd_pcm_uframes_t hwptr_done;
327 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
328
329 hwptr_done = cobsc->hwptr_done_capture;
330
331 return hwptr_done;
332}
333
334static void pb_sample_cpy(u8 *dst, const u8 *src, u32 len, bool is_s32)
335{
336 static const unsigned map[8] = { 0, 1, 5, 4, 2, 3, 6, 7 };
337 unsigned idx = 0;
338
339 while (len >= (is_s32 ? 4 : 2)) {
340 unsigned offset = map[idx] * 4;
341 u8 *out = dst + offset;
342
343 *out++ = 0;
344 if (is_s32) {
345 src++;
346 *out++ = *src++;
347 } else {
348 *out++ = 0;
349 }
350 *out++ = *src++;
351 *out = *src++;
352 len -= is_s32 ? 4 : 2;
353 idx++;
354 }
355}
356
357static void cobalt_alsa_pb_pcm_data(struct snd_cobalt_card *cobsc,
358 u8 *pcm_data,
359 size_t skip,
360 size_t samples)
361{
362 struct snd_pcm_substream *substream;
363 struct snd_pcm_runtime *runtime;
364 unsigned long flags;
365 unsigned int pos;
366 unsigned int stride;
367 bool is_s32;
368 unsigned i;
369
370 dprintk("cobalt alsa pb ptr=%p data=%p samples=%zd\n", cobsc,
371 pcm_data, samples);
372
373 substream = cobsc->playback_pcm_substream;
374 if (substream == NULL) {
375 dprintk("substream was NULL\n");
376 return;
377 }
378
379 runtime = substream->runtime;
380 if (runtime == NULL) {
381 dprintk("runtime was NULL\n");
382 return;
383 }
384
385 is_s32 = runtime->format == SNDRV_PCM_FORMAT_S32_LE;
386 stride = runtime->frame_bits >> 3;
387 if (stride == 0) {
388 dprintk("stride is zero\n");
389 return;
390 }
391
392 if (samples == 0) {
393 dprintk("%s: samples was zero\n", __func__);
394 return;
395 }
396
397 if (runtime->dma_area == NULL) {
398 dprintk("dma area was NULL - ignoring\n");
399 return;
400 }
401
402 pos = cobsc->pb_pos % cobsc->pb_size;
403 for (i = 0; i < cobsc->pb_count / (8 * 4); i++)
404 pb_sample_cpy(pcm_data + i * skip,
405 runtime->dma_area + pos + i * stride,
406 stride, is_s32);
407 snd_pcm_stream_lock_irqsave(substream, flags);
408
409 cobsc->pb_pos += i * stride;
410
411 snd_pcm_stream_unlock_irqrestore(substream, flags);
412 if (cobsc->pb_pos % cobsc->pb_count == 0)
413 snd_pcm_period_elapsed(substream);
414}
415
416static int alsa_pb_fnc(struct vb2_buffer *vb, void *priv)
417{
418 struct cobalt_stream *s = priv;
419
420 if (s->alsa->alsa_pb_channel)
421 cobalt_alsa_pb_pcm_data(s->alsa,
422 vb2_plane_vaddr(vb, 0),
423 8 * 4,
424 vb2_get_plane_payload(vb, 0) / (8 * 4));
425 return 0;
426}
427
428static int snd_cobalt_pcm_playback_open(struct snd_pcm_substream *substream)
429{
430 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
431 struct snd_pcm_runtime *runtime = substream->runtime;
432 struct cobalt_stream *s = cobsc->s;
433
434 runtime->hw = snd_cobalt_playback;
435 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
436 cobsc->playback_pcm_substream = substream;
437 runtime->private_data = s;
438 cobsc->alsa_playback_cnt++;
439 if (cobsc->alsa_playback_cnt == 1) {
440 int rc;
441
442 rc = vb2_thread_start(&s->q, alsa_pb_fnc, s, s->vdev.name);
443 if (rc) {
444 cobsc->alsa_playback_cnt--;
445 return rc;
446 }
447 }
448
449 return 0;
450}
451
452static int snd_cobalt_pcm_playback_close(struct snd_pcm_substream *substream)
453{
454 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
455 struct cobalt_stream *s = cobsc->s;
456
457 cobsc->alsa_playback_cnt--;
458 if (cobsc->alsa_playback_cnt == 0)
459 vb2_thread_stop(&s->q);
460 return 0;
461}
462
463static int snd_cobalt_pcm_pb_prepare(struct snd_pcm_substream *substream)
464{
465 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
466
467 cobsc->pb_size = snd_pcm_lib_buffer_bytes(substream);
468 cobsc->pb_count = snd_pcm_lib_period_bytes(substream);
469 cobsc->pb_pos = 0;
470
471 return 0;
472}
473
474static int snd_cobalt_pcm_pb_trigger(struct snd_pcm_substream *substream,
475 int cmd)
476{
477 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
478
479 switch (cmd) {
480 case SNDRV_PCM_TRIGGER_START:
481 if (cobsc->alsa_pb_channel)
482 return -EBUSY;
483 cobsc->alsa_pb_channel = true;
484 return 0;
485 case SNDRV_PCM_TRIGGER_STOP:
486 cobsc->alsa_pb_channel = false;
487 return 0;
488 default:
489 return -EINVAL;
490 }
491}
492
493static
494snd_pcm_uframes_t snd_cobalt_pcm_pb_pointer(struct snd_pcm_substream *substream)
495{
496 struct snd_cobalt_card *cobsc = snd_pcm_substream_chip(substream);
497 size_t ptr;
498
499 ptr = cobsc->pb_pos;
500
501 return bytes_to_frames(substream->runtime, ptr) %
502 substream->runtime->buffer_size;
503}
504
505static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
506 unsigned long offset)
507{
508 void *pageptr = subs->runtime->dma_area + offset;
509
510 return vmalloc_to_page(pageptr);
511}
512
513static struct snd_pcm_ops snd_cobalt_pcm_capture_ops = {
514 .open = snd_cobalt_pcm_capture_open,
515 .close = snd_cobalt_pcm_capture_close,
516 .ioctl = snd_cobalt_pcm_ioctl,
517 .hw_params = snd_cobalt_pcm_hw_params,
518 .hw_free = snd_cobalt_pcm_hw_free,
519 .prepare = snd_cobalt_pcm_prepare,
520 .trigger = snd_cobalt_pcm_trigger,
521 .pointer = snd_cobalt_pcm_pointer,
522 .page = snd_pcm_get_vmalloc_page,
523};
524
525static struct snd_pcm_ops snd_cobalt_pcm_playback_ops = {
526 .open = snd_cobalt_pcm_playback_open,
527 .close = snd_cobalt_pcm_playback_close,
528 .ioctl = snd_cobalt_pcm_ioctl,
529 .hw_params = snd_cobalt_pcm_hw_params,
530 .hw_free = snd_cobalt_pcm_hw_free,
531 .prepare = snd_cobalt_pcm_pb_prepare,
532 .trigger = snd_cobalt_pcm_pb_trigger,
533 .pointer = snd_cobalt_pcm_pb_pointer,
534 .page = snd_pcm_get_vmalloc_page,
535};
536
537int snd_cobalt_pcm_create(struct snd_cobalt_card *cobsc)
538{
539 struct snd_pcm *sp;
540 struct snd_card *sc = cobsc->sc;
541 struct cobalt_stream *s = cobsc->s;
542 struct cobalt *cobalt = s->cobalt;
543 int ret;
544
545 s->q.gfp_flags |= __GFP_ZERO;
546
547 if (!s->is_output) {
548 cobalt_s_bit_sysctrl(cobalt,
549 COBALT_SYS_CTRL_AUDIO_IPP_RESETN_BIT(s->video_channel),
550 0);
551 mdelay(2);
552 cobalt_s_bit_sysctrl(cobalt,
553 COBALT_SYS_CTRL_AUDIO_IPP_RESETN_BIT(s->video_channel),
554 1);
555 mdelay(1);
556
557 ret = snd_pcm_new(sc, "Cobalt PCM-In HDMI",
558 0, /* PCM device 0, the only one for this card */
559 0, /* 0 playback substreams */
560 1, /* 1 capture substream */
561 &sp);
562 if (ret) {
563 cobalt_err("snd_cobalt_pcm_create() failed for input with err %d\n",
564 ret);
565 goto err_exit;
566 }
567
568 snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_CAPTURE,
569 &snd_cobalt_pcm_capture_ops);
570 sp->info_flags = 0;
571 sp->private_data = cobsc;
572 strlcpy(sp->name, "cobalt", sizeof(sp->name));
573 } else {
574 cobalt_s_bit_sysctrl(cobalt,
575 COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT, 0);
576 mdelay(2);
577 cobalt_s_bit_sysctrl(cobalt,
578 COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT, 1);
579 mdelay(1);
580
581 ret = snd_pcm_new(sc, "Cobalt PCM-Out HDMI",
582 0, /* PCM device 0, the only one for this card */
583 1, /* 0 playback substreams */
584 0, /* 1 capture substream */
585 &sp);
586 if (ret) {
587 cobalt_err("snd_cobalt_pcm_create() failed for output with err %d\n",
588 ret);
589 goto err_exit;
590 }
591
592 snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_PLAYBACK,
593 &snd_cobalt_pcm_playback_ops);
594 sp->info_flags = 0;
595 sp->private_data = cobsc;
596 strlcpy(sp->name, "cobalt", sizeof(sp->name));
597 }
598
599 return 0;
600
601err_exit:
602 return ret;
603}
diff --git a/drivers/media/pci/cobalt/cobalt-alsa-pcm.h b/drivers/media/pci/cobalt/cobalt-alsa-pcm.h
new file mode 100644
index 000000000000..513fb1f71794
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-alsa-pcm.h
@@ -0,0 +1,22 @@
1/*
2 * ALSA PCM device for the
3 * ALSA interface to cobalt PCM capture streams
4 *
5 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
6 * All rights reserved.
7 *
8 * This program is free software; you may redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
16 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
17 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 * SOFTWARE.
20 */
21
22int snd_cobalt_pcm_create(struct snd_cobalt_card *cobsc);
diff --git a/drivers/media/pci/cobalt/cobalt-alsa.h b/drivers/media/pci/cobalt/cobalt-alsa.h
new file mode 100644
index 000000000000..08db699ced37
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-alsa.h
@@ -0,0 +1,41 @@
1/*
2 * ALSA interface to cobalt PCM capture streams
3 *
4 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21struct snd_card;
22
23struct snd_cobalt_card {
24 struct cobalt_stream *s;
25 struct snd_card *sc;
26 unsigned int capture_transfer_done;
27 unsigned int hwptr_done_capture;
28 unsigned alsa_record_cnt;
29 struct snd_pcm_substream *capture_pcm_substream;
30
31 unsigned int pb_size;
32 unsigned int pb_count;
33 unsigned int pb_pos;
34 unsigned pb_filled;
35 bool alsa_pb_channel;
36 unsigned alsa_playback_cnt;
37 struct snd_pcm_substream *playback_pcm_substream;
38};
39
40int cobalt_alsa_init(struct cobalt_stream *s);
41void cobalt_alsa_exit(struct cobalt_stream *s);
diff --git a/drivers/media/pci/cobalt/cobalt-cpld.c b/drivers/media/pci/cobalt/cobalt-cpld.c
new file mode 100644
index 000000000000..e83f5c9f7e7d
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-cpld.c
@@ -0,0 +1,341 @@
1/*
2 * Cobalt CPLD functions
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#include <linux/delay.h>
22
23#include "cobalt-cpld.h"
24
25#define ADRS(offset) (COBALT_BUS_CPLD_BASE + offset)
26
27static u16 cpld_read(struct cobalt *cobalt, u32 offset)
28{
29 return cobalt_bus_read32(cobalt->bar1, ADRS(offset));
30}
31
32static void cpld_write(struct cobalt *cobalt, u32 offset, u16 val)
33{
34 return cobalt_bus_write32(cobalt->bar1, ADRS(offset), val);
35}
36
37static void cpld_info_ver3(struct cobalt *cobalt)
38{
39 u32 rd;
40 u32 tmp;
41
42 cobalt_info("CPLD System control register (read/write)\n");
43 cobalt_info("\t\tSystem control: 0x%04x (0x0f00)\n",
44 cpld_read(cobalt, 0));
45 cobalt_info("CPLD Clock control register (read/write)\n");
46 cobalt_info("\t\tClock control: 0x%04x (0x0000)\n",
47 cpld_read(cobalt, 0x04));
48 cobalt_info("CPLD HSMA Clk Osc register (read/write) - Must set wr trigger to load default values\n");
49 cobalt_info("\t\tRegister #7:\t0x%04x (0x0022)\n",
50 cpld_read(cobalt, 0x08));
51 cobalt_info("\t\tRegister #8:\t0x%04x (0x0047)\n",
52 cpld_read(cobalt, 0x0c));
53 cobalt_info("\t\tRegister #9:\t0x%04x (0x00fa)\n",
54 cpld_read(cobalt, 0x10));
55 cobalt_info("\t\tRegister #10:\t0x%04x (0x0061)\n",
56 cpld_read(cobalt, 0x14));
57 cobalt_info("\t\tRegister #11:\t0x%04x (0x001e)\n",
58 cpld_read(cobalt, 0x18));
59 cobalt_info("\t\tRegister #12:\t0x%04x (0x0045)\n",
60 cpld_read(cobalt, 0x1c));
61 cobalt_info("\t\tRegister #135:\t0x%04x\n",
62 cpld_read(cobalt, 0x20));
63 cobalt_info("\t\tRegister #137:\t0x%04x\n",
64 cpld_read(cobalt, 0x24));
65 cobalt_info("CPLD System status register (read only)\n");
66 cobalt_info("\t\tSystem status: 0x%04x\n",
67 cpld_read(cobalt, 0x28));
68 cobalt_info("CPLD MAXII info register (read only)\n");
69 cobalt_info("\t\tBoard serial number: 0x%04x\n",
70 cpld_read(cobalt, 0x2c));
71 cobalt_info("\t\tMAXII program revision: 0x%04x\n",
72 cpld_read(cobalt, 0x30));
73 cobalt_info("CPLD temp and voltage ADT7411 registers (read only)\n");
74 cobalt_info("\t\tBoard temperature: %u Celcius\n",
75 cpld_read(cobalt, 0x34) / 4);
76 cobalt_info("\t\tFPGA temperature: %u Celcius\n",
77 cpld_read(cobalt, 0x38) / 4);
78 rd = cpld_read(cobalt, 0x3c);
79 tmp = (rd * 33 * 1000) / (483 * 10);
80 cobalt_info("\t\tVDD 3V3: %u,%03uV\n", tmp / 1000, tmp % 1000);
81 rd = cpld_read(cobalt, 0x40);
82 tmp = (rd * 74 * 2197) / (27 * 1000);
83 cobalt_info("\t\tADC ch3 5V: %u,%03uV\n", tmp / 1000, tmp % 1000);
84 rd = cpld_read(cobalt, 0x44);
85 tmp = (rd * 74 * 2197) / (47 * 1000);
86 cobalt_info("\t\tADC ch4 3V: %u,%03uV\n", tmp / 1000, tmp % 1000);
87 rd = cpld_read(cobalt, 0x48);
88 tmp = (rd * 57 * 2197) / (47 * 1000);
89 cobalt_info("\t\tADC ch5 2V5: %u,%03uV\n", tmp / 1000, tmp % 1000);
90 rd = cpld_read(cobalt, 0x4c);
91 tmp = (rd * 2197) / 1000;
92 cobalt_info("\t\tADC ch6 1V8: %u,%03uV\n", tmp / 1000, tmp % 1000);
93 rd = cpld_read(cobalt, 0x50);
94 tmp = (rd * 2197) / 1000;
95 cobalt_info("\t\tADC ch7 1V5: %u,%03uV\n", tmp / 1000, tmp % 1000);
96 rd = cpld_read(cobalt, 0x54);
97 tmp = (rd * 2197) / 1000;
98 cobalt_info("\t\tADC ch8 0V9: %u,%03uV\n", tmp / 1000, tmp % 1000);
99}
100
101void cobalt_cpld_status(struct cobalt *cobalt)
102{
103 u32 rev = cpld_read(cobalt, 0x30);
104
105 switch (rev) {
106 case 3:
107 case 4:
108 case 5:
109 cpld_info_ver3(cobalt);
110 break;
111 default:
112 cobalt_info("CPLD revision %u is not supported!\n", rev);
113 break;
114 }
115}
116
117#define DCO_MIN 4850000000ULL
118#define DCO_MAX 5670000000ULL
119
120#define SI570_CLOCK_CTRL 0x04
121#define S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_WR_TRIGGER 0x200
122#define S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_RST_TRIGGER 0x100
123#define S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_FPGA_CTRL 0x80
124#define S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN 0x40
125
126#define SI570_REG7 0x08
127#define SI570_REG8 0x0c
128#define SI570_REG9 0x10
129#define SI570_REG10 0x14
130#define SI570_REG11 0x18
131#define SI570_REG12 0x1c
132#define SI570_REG135 0x20
133#define SI570_REG137 0x24
134
135struct multiplier {
136 unsigned mult, hsdiv, n1;
137};
138
139/* List all possible multipliers (= hsdiv * n1). There are lots of duplicates,
140 which are all removed in this list to keep the list as short as possible.
141 The values for hsdiv and n1 are the actual values, not the register values.
142 */
143static const struct multiplier multipliers[] = {
144 { 4, 4, 1 }, { 5, 5, 1 }, { 6, 6, 1 },
145 { 7, 7, 1 }, { 8, 4, 2 }, { 9, 9, 1 },
146 { 10, 5, 2 }, { 11, 11, 1 }, { 12, 6, 2 },
147 { 14, 7, 2 }, { 16, 4, 4 }, { 18, 9, 2 },
148 { 20, 5, 4 }, { 22, 11, 2 }, { 24, 4, 6 },
149 { 28, 7, 4 }, { 30, 5, 6 }, { 32, 4, 8 },
150 { 36, 6, 6 }, { 40, 4, 10 }, { 42, 7, 6 },
151 { 44, 11, 4 }, { 48, 4, 12 }, { 50, 5, 10 },
152 { 54, 9, 6 }, { 56, 4, 14 }, { 60, 5, 12 },
153 { 64, 4, 16 }, { 66, 11, 6 }, { 70, 5, 14 },
154 { 72, 4, 18 }, { 80, 4, 20 }, { 84, 6, 14 },
155 { 88, 11, 8 }, { 90, 5, 18 }, { 96, 4, 24 },
156 { 98, 7, 14 }, { 100, 5, 20 }, { 104, 4, 26 },
157 { 108, 6, 18 }, { 110, 11, 10 }, { 112, 4, 28 },
158 { 120, 4, 30 }, { 126, 7, 18 }, { 128, 4, 32 },
159 { 130, 5, 26 }, { 132, 11, 12 }, { 136, 4, 34 },
160 { 140, 5, 28 }, { 144, 4, 36 }, { 150, 5, 30 },
161 { 152, 4, 38 }, { 154, 11, 14 }, { 156, 6, 26 },
162 { 160, 4, 40 }, { 162, 9, 18 }, { 168, 4, 42 },
163 { 170, 5, 34 }, { 176, 11, 16 }, { 180, 5, 36 },
164 { 182, 7, 26 }, { 184, 4, 46 }, { 190, 5, 38 },
165 { 192, 4, 48 }, { 196, 7, 28 }, { 198, 11, 18 },
166 { 198, 9, 22 }, { 200, 4, 50 }, { 204, 6, 34 },
167 { 208, 4, 52 }, { 210, 5, 42 }, { 216, 4, 54 },
168 { 220, 11, 20 }, { 224, 4, 56 }, { 228, 6, 38 },
169 { 230, 5, 46 }, { 232, 4, 58 }, { 234, 9, 26 },
170 { 238, 7, 34 }, { 240, 4, 60 }, { 242, 11, 22 },
171 { 248, 4, 62 }, { 250, 5, 50 }, { 252, 6, 42 },
172 { 256, 4, 64 }, { 260, 5, 52 }, { 264, 11, 24 },
173 { 266, 7, 38 }, { 270, 5, 54 }, { 272, 4, 68 },
174 { 276, 6, 46 }, { 280, 4, 70 }, { 286, 11, 26 },
175 { 288, 4, 72 }, { 290, 5, 58 }, { 294, 7, 42 },
176 { 296, 4, 74 }, { 300, 5, 60 }, { 304, 4, 76 },
177 { 306, 9, 34 }, { 308, 11, 28 }, { 310, 5, 62 },
178 { 312, 4, 78 }, { 320, 4, 80 }, { 322, 7, 46 },
179 { 324, 6, 54 }, { 328, 4, 82 }, { 330, 11, 30 },
180 { 336, 4, 84 }, { 340, 5, 68 }, { 342, 9, 38 },
181 { 344, 4, 86 }, { 348, 6, 58 }, { 350, 5, 70 },
182 { 352, 11, 32 }, { 360, 4, 90 }, { 364, 7, 52 },
183 { 368, 4, 92 }, { 370, 5, 74 }, { 372, 6, 62 },
184 { 374, 11, 34 }, { 376, 4, 94 }, { 378, 7, 54 },
185 { 380, 5, 76 }, { 384, 4, 96 }, { 390, 5, 78 },
186 { 392, 4, 98 }, { 396, 11, 36 }, { 400, 4, 100 },
187 { 406, 7, 58 }, { 408, 4, 102 }, { 410, 5, 82 },
188 { 414, 9, 46 }, { 416, 4, 104 }, { 418, 11, 38 },
189 { 420, 5, 84 }, { 424, 4, 106 }, { 430, 5, 86 },
190 { 432, 4, 108 }, { 434, 7, 62 }, { 440, 11, 40 },
191 { 444, 6, 74 }, { 448, 4, 112 }, { 450, 5, 90 },
192 { 456, 4, 114 }, { 460, 5, 92 }, { 462, 11, 42 },
193 { 464, 4, 116 }, { 468, 6, 78 }, { 470, 5, 94 },
194 { 472, 4, 118 }, { 476, 7, 68 }, { 480, 4, 120 },
195 { 484, 11, 44 }, { 486, 9, 54 }, { 488, 4, 122 },
196 { 490, 5, 98 }, { 492, 6, 82 }, { 496, 4, 124 },
197 { 500, 5, 100 }, { 504, 4, 126 }, { 506, 11, 46 },
198 { 510, 5, 102 }, { 512, 4, 128 }, { 516, 6, 86 },
199 { 518, 7, 74 }, { 520, 5, 104 }, { 522, 9, 58 },
200 { 528, 11, 48 }, { 530, 5, 106 }, { 532, 7, 76 },
201 { 540, 5, 108 }, { 546, 7, 78 }, { 550, 11, 50 },
202 { 552, 6, 92 }, { 558, 9, 62 }, { 560, 5, 112 },
203 { 564, 6, 94 }, { 570, 5, 114 }, { 572, 11, 52 },
204 { 574, 7, 82 }, { 576, 6, 96 }, { 580, 5, 116 },
205 { 588, 6, 98 }, { 590, 5, 118 }, { 594, 11, 54 },
206 { 600, 5, 120 }, { 602, 7, 86 }, { 610, 5, 122 },
207 { 612, 6, 102 }, { 616, 11, 56 }, { 620, 5, 124 },
208 { 624, 6, 104 }, { 630, 5, 126 }, { 636, 6, 106 },
209 { 638, 11, 58 }, { 640, 5, 128 }, { 644, 7, 92 },
210 { 648, 6, 108 }, { 658, 7, 94 }, { 660, 11, 60 },
211 { 666, 9, 74 }, { 672, 6, 112 }, { 682, 11, 62 },
212 { 684, 6, 114 }, { 686, 7, 98 }, { 696, 6, 116 },
213 { 700, 7, 100 }, { 702, 9, 78 }, { 704, 11, 64 },
214 { 708, 6, 118 }, { 714, 7, 102 }, { 720, 6, 120 },
215 { 726, 11, 66 }, { 728, 7, 104 }, { 732, 6, 122 },
216 { 738, 9, 82 }, { 742, 7, 106 }, { 744, 6, 124 },
217 { 748, 11, 68 }, { 756, 6, 126 }, { 768, 6, 128 },
218 { 770, 11, 70 }, { 774, 9, 86 }, { 784, 7, 112 },
219 { 792, 11, 72 }, { 798, 7, 114 }, { 810, 9, 90 },
220 { 812, 7, 116 }, { 814, 11, 74 }, { 826, 7, 118 },
221 { 828, 9, 92 }, { 836, 11, 76 }, { 840, 7, 120 },
222 { 846, 9, 94 }, { 854, 7, 122 }, { 858, 11, 78 },
223 { 864, 9, 96 }, { 868, 7, 124 }, { 880, 11, 80 },
224 { 882, 7, 126 }, { 896, 7, 128 }, { 900, 9, 100 },
225 { 902, 11, 82 }, { 918, 9, 102 }, { 924, 11, 84 },
226 { 936, 9, 104 }, { 946, 11, 86 }, { 954, 9, 106 },
227 { 968, 11, 88 }, { 972, 9, 108 }, { 990, 11, 90 },
228 { 1008, 9, 112 }, { 1012, 11, 92 }, { 1026, 9, 114 },
229 { 1034, 11, 94 }, { 1044, 9, 116 }, { 1056, 11, 96 },
230 { 1062, 9, 118 }, { 1078, 11, 98 }, { 1080, 9, 120 },
231 { 1098, 9, 122 }, { 1100, 11, 100 }, { 1116, 9, 124 },
232 { 1122, 11, 102 }, { 1134, 9, 126 }, { 1144, 11, 104 },
233 { 1152, 9, 128 }, { 1166, 11, 106 }, { 1188, 11, 108 },
234 { 1210, 11, 110 }, { 1232, 11, 112 }, { 1254, 11, 114 },
235 { 1276, 11, 116 }, { 1298, 11, 118 }, { 1320, 11, 120 },
236 { 1342, 11, 122 }, { 1364, 11, 124 }, { 1386, 11, 126 },
237 { 1408, 11, 128 },
238};
239
240bool cobalt_cpld_set_freq(struct cobalt *cobalt, unsigned f_out)
241{
242 const unsigned f_xtal = 39170000; /* xtal for si598 */
243 u64 dco;
244 u64 rfreq;
245 unsigned delta = 0xffffffff;
246 unsigned i_best = 0;
247 unsigned i;
248 u8 n1, hsdiv;
249 u8 regs[6];
250 int found = 0;
251 u16 clock_ctrl;
252 int retries = 3;
253
254 for (i = 0; i < ARRAY_SIZE(multipliers); i++) {
255 unsigned mult = multipliers[i].mult;
256 u32 d;
257
258 dco = (u64)f_out * mult;
259 if (dco < DCO_MIN || dco > DCO_MAX)
260 continue;
261 div_u64_rem((dco << 28) + f_xtal / 2, f_xtal, &d);
262 if (d < delta) {
263 found = 1;
264 i_best = i;
265 delta = d;
266 }
267 }
268 if (!found)
269 return false;
270 dco = (u64)f_out * multipliers[i_best].mult;
271 n1 = multipliers[i_best].n1 - 1;
272 hsdiv = multipliers[i_best].hsdiv - 4;
273 rfreq = div_u64(dco << 28, f_xtal);
274
275 clock_ctrl = cpld_read(cobalt, SI570_CLOCK_CTRL);
276 clock_ctrl |= S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_FPGA_CTRL;
277 clock_ctrl |= S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN;
278
279 regs[0] = (hsdiv << 5) | (n1 >> 2);
280 regs[1] = ((n1 & 0x3) << 6) | (rfreq >> 32);
281 regs[2] = (rfreq >> 24) & 0xff;
282 regs[3] = (rfreq >> 16) & 0xff;
283 regs[4] = (rfreq >> 8) & 0xff;
284 regs[5] = rfreq & 0xff;
285
286 /* The sequence of clock_ctrl flags to set is very weird. It looks
287 like I have to reset it, then set the new frequency and reset it
288 again. It shouldn't be necessary to do a reset, but if I don't,
289 then a strange frequency is set (156.412034 MHz, or register values
290 0x01, 0xc7, 0xfc, 0x7f, 0x53, 0x62).
291 */
292
293 cobalt_dbg(1, "%u: %02x %02x %02x %02x %02x %02x\n", f_out,
294 regs[0], regs[1], regs[2], regs[3], regs[4], regs[5]);
295 while (retries--) {
296 u8 read_regs[6];
297
298 cpld_write(cobalt, SI570_CLOCK_CTRL,
299 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN |
300 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_FPGA_CTRL);
301 usleep_range(10000, 15000);
302 cpld_write(cobalt, SI570_REG7, regs[0]);
303 cpld_write(cobalt, SI570_REG8, regs[1]);
304 cpld_write(cobalt, SI570_REG9, regs[2]);
305 cpld_write(cobalt, SI570_REG10, regs[3]);
306 cpld_write(cobalt, SI570_REG11, regs[4]);
307 cpld_write(cobalt, SI570_REG12, regs[5]);
308 cpld_write(cobalt, SI570_CLOCK_CTRL,
309 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN |
310 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_WR_TRIGGER);
311 usleep_range(10000, 15000);
312 cpld_write(cobalt, SI570_CLOCK_CTRL,
313 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN |
314 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_FPGA_CTRL);
315 usleep_range(10000, 15000);
316 read_regs[0] = cpld_read(cobalt, SI570_REG7);
317 read_regs[1] = cpld_read(cobalt, SI570_REG8);
318 read_regs[2] = cpld_read(cobalt, SI570_REG9);
319 read_regs[3] = cpld_read(cobalt, SI570_REG10);
320 read_regs[4] = cpld_read(cobalt, SI570_REG11);
321 read_regs[5] = cpld_read(cobalt, SI570_REG12);
322 cpld_write(cobalt, SI570_CLOCK_CTRL,
323 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN |
324 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_FPGA_CTRL |
325 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_RST_TRIGGER);
326 usleep_range(10000, 15000);
327 cpld_write(cobalt, SI570_CLOCK_CTRL,
328 S01755_REG_CLOCK_CTRL_BITMAP_CLKHSMA_EN);
329 usleep_range(10000, 15000);
330
331 if (!memcmp(read_regs, regs, sizeof(read_regs)))
332 break;
333 cobalt_dbg(1, "retry: %02x %02x %02x %02x %02x %02x\n",
334 read_regs[0], read_regs[1], read_regs[2],
335 read_regs[3], read_regs[4], read_regs[5]);
336 }
337 if (2 - retries)
338 cobalt_info("Needed %d retries\n", 2 - retries);
339
340 return true;
341}
diff --git a/drivers/media/pci/cobalt/cobalt-cpld.h b/drivers/media/pci/cobalt/cobalt-cpld.h
new file mode 100644
index 000000000000..0fc88fd5fa7b
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-cpld.h
@@ -0,0 +1,29 @@
1/*
2 * Cobalt CPLD functions
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#ifndef COBALT_CPLD_H
22#define COBALT_CPLD_H
23
24#include "cobalt-driver.h"
25
26void cobalt_cpld_status(struct cobalt *cobalt);
27bool cobalt_cpld_set_freq(struct cobalt *cobalt, unsigned freq);
28
29#endif
diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
new file mode 100644
index 000000000000..b994b8efdc99
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -0,0 +1,832 @@
1/*
2 * cobalt driver initialization and card probing
3 *
4 * Derived from cx18-driver.c
5 *
6 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
7 * All rights reserved.
8 *
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#include <linux/delay.h>
24#include <media/adv7604.h>
25#include <media/adv7842.h>
26#include <media/adv7511.h>
27#include <media/v4l2-event.h>
28#include <media/v4l2-ctrls.h>
29
30#include "cobalt-driver.h"
31#include "cobalt-irq.h"
32#include "cobalt-i2c.h"
33#include "cobalt-v4l2.h"
34#include "cobalt-flash.h"
35#include "cobalt-alsa.h"
36#include "cobalt-omnitek.h"
37
38/* add your revision and whatnot here */
39static struct pci_device_id cobalt_pci_tbl[] = {
40 {PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_COBALT,
41 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
42 {0,}
43};
44
45MODULE_DEVICE_TABLE(pci, cobalt_pci_tbl);
46
47static atomic_t cobalt_instance = ATOMIC_INIT(0);
48
49int cobalt_debug;
50module_param_named(debug, cobalt_debug, int, 0644);
51MODULE_PARM_DESC(debug, "Debug level. Default: 0\n");
52
53int cobalt_ignore_err;
54module_param_named(ignore_err, cobalt_ignore_err, int, 0644);
55MODULE_PARM_DESC(ignore_err,
56 "If set then ignore missing i2c adapters/receivers. Default: 0\n");
57
58MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com> & Morten Hestnes");
59MODULE_DESCRIPTION("cobalt driver");
60MODULE_LICENSE("GPL");
61
62static u8 edid[256] = {
63 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
64 0x50, 0x21, 0x9C, 0x27, 0x00, 0x00, 0x00, 0x00,
65 0x19, 0x12, 0x01, 0x03, 0x80, 0x00, 0x00, 0x78,
66 0x0E, 0x00, 0xB2, 0xA0, 0x57, 0x49, 0x9B, 0x26,
67 0x10, 0x48, 0x4F, 0x2F, 0xCF, 0x00, 0x31, 0x59,
68 0x45, 0x59, 0x61, 0x59, 0x81, 0x99, 0x01, 0x01,
69 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3A,
70 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C,
71 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E,
72 0x00, 0x00, 0x00, 0xFD, 0x00, 0x31, 0x55, 0x18,
73 0x5E, 0x11, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20,
74 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x43,
75 0x20, 0x39, 0x30, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
76 0x0A, 0x0A, 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x10,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x68,
79 0x02, 0x03, 0x1a, 0xc0, 0x48, 0xa2, 0x10, 0x04,
80 0x02, 0x01, 0x21, 0x14, 0x13, 0x23, 0x09, 0x07,
81 0x07, 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0xe2,
82 0x00, 0x2a, 0x01, 0x1d, 0x00, 0x80, 0x51, 0xd0,
83 0x1c, 0x20, 0x40, 0x80, 0x35, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x1e, 0x8c, 0x0a, 0xd0, 0x8a,
85 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd7
95};
96
97static void cobalt_set_interrupt(struct cobalt *cobalt, bool enable)
98{
99 if (enable) {
100 unsigned irqs = COBALT_SYSSTAT_VI0_INT1_MSK |
101 COBALT_SYSSTAT_VI1_INT1_MSK |
102 COBALT_SYSSTAT_VI2_INT1_MSK |
103 COBALT_SYSSTAT_VI3_INT1_MSK |
104 COBALT_SYSSTAT_VI0_INT2_MSK |
105 COBALT_SYSSTAT_VI1_INT2_MSK |
106 COBALT_SYSSTAT_VI2_INT2_MSK |
107 COBALT_SYSSTAT_VI3_INT2_MSK |
108 COBALT_SYSSTAT_VI0_LOST_DATA_MSK |
109 COBALT_SYSSTAT_VI1_LOST_DATA_MSK |
110 COBALT_SYSSTAT_VI2_LOST_DATA_MSK |
111 COBALT_SYSSTAT_VI3_LOST_DATA_MSK |
112 COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK;
113
114 if (cobalt->have_hsma_rx)
115 irqs |= COBALT_SYSSTAT_VIHSMA_INT1_MSK |
116 COBALT_SYSSTAT_VIHSMA_INT2_MSK |
117 COBALT_SYSSTAT_VIHSMA_LOST_DATA_MSK;
118
119 if (cobalt->have_hsma_tx)
120 irqs |= COBALT_SYSSTAT_VOHSMA_INT1_MSK |
121 COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK |
122 COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK;
123 /* Clear any existing interrupts */
124 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_EDGE, 0xffffffff);
125 /* PIO Core interrupt mask register.
126 Enable ADV7604 INT1 interrupts */
127 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_MASK, irqs);
128 } else {
129 /* Disable all ADV7604 interrupts */
130 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_MASK, 0);
131 }
132}
133
134static unsigned cobalt_get_sd_nr(struct v4l2_subdev *sd)
135{
136 struct cobalt *cobalt = to_cobalt(sd->v4l2_dev);
137 unsigned i;
138
139 for (i = 0; i < COBALT_NUM_NODES; i++)
140 if (sd == cobalt->streams[i].sd)
141 return i;
142 cobalt_err("Invalid adv7604 subdev pointer!\n");
143 return 0;
144}
145
146static void cobalt_notify(struct v4l2_subdev *sd,
147 unsigned int notification, void *arg)
148{
149 struct cobalt *cobalt = to_cobalt(sd->v4l2_dev);
150 unsigned sd_nr = cobalt_get_sd_nr(sd);
151 struct cobalt_stream *s = &cobalt->streams[sd_nr];
152 bool hotplug = arg ? *((int *)arg) : false;
153
154 if (s->is_output)
155 return;
156
157 switch (notification) {
158 case ADV76XX_HOTPLUG:
159 cobalt_s_bit_sysctrl(cobalt,
160 COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(sd_nr), hotplug);
161 cobalt_dbg(1, "Set hotplug for adv %d to %d\n", sd_nr, hotplug);
162 break;
163 case V4L2_DEVICE_NOTIFY_EVENT:
164 cobalt_dbg(1, "Format changed for adv %d\n", sd_nr);
165 v4l2_event_queue(&s->vdev, arg);
166 break;
167 default:
168 break;
169 }
170}
171
172static int get_payload_size(u16 code)
173{
174 switch (code) {
175 case 0: return 128;
176 case 1: return 256;
177 case 2: return 512;
178 case 3: return 1024;
179 case 4: return 2048;
180 case 5: return 4096;
181 default: return 0;
182 }
183 return 0;
184}
185
186static const char *get_link_speed(u16 stat)
187{
188 switch (stat & PCI_EXP_LNKSTA_CLS) {
189 case 1: return "2.5 Gbit/s";
190 case 2: return "5 Gbit/s";
191 case 3: return "10 Gbit/s";
192 }
193 return "Unknown speed";
194}
195
196void cobalt_pcie_status_show(struct cobalt *cobalt)
197{
198 struct pci_dev *pci_dev = cobalt->pci_dev;
199 struct pci_dev *pci_bus_dev = cobalt->pci_dev->bus->self;
200 int offset;
201 int bus_offset;
202 u32 capa;
203 u16 stat, ctrl;
204
205 offset = pci_find_capability(pci_dev, PCI_CAP_ID_EXP);
206 bus_offset = pci_find_capability(pci_bus_dev, PCI_CAP_ID_EXP);
207
208 /* Device */
209 pci_read_config_dword(pci_dev, offset + PCI_EXP_DEVCAP, &capa);
210 pci_read_config_word(pci_dev, offset + PCI_EXP_DEVCTL, &ctrl);
211 pci_read_config_word(pci_dev, offset + PCI_EXP_DEVSTA, &stat);
212 cobalt_info("PCIe device capability 0x%08x: Max payload %d\n",
213 capa, get_payload_size(capa & PCI_EXP_DEVCAP_PAYLOAD));
214 cobalt_info("PCIe device control 0x%04x: Max payload %d. Max read request %d\n",
215 ctrl,
216 get_payload_size((ctrl & PCI_EXP_DEVCTL_PAYLOAD) >> 5),
217 get_payload_size((ctrl & PCI_EXP_DEVCTL_READRQ) >> 12));
218 cobalt_info("PCIe device status 0x%04x\n", stat);
219
220 /* Link */
221 pci_read_config_dword(pci_dev, offset + PCI_EXP_LNKCAP, &capa);
222 pci_read_config_word(pci_dev, offset + PCI_EXP_LNKCTL, &ctrl);
223 pci_read_config_word(pci_dev, offset + PCI_EXP_LNKSTA, &stat);
224 cobalt_info("PCIe link capability 0x%08x: %s per lane and %u lanes\n",
225 capa, get_link_speed(capa),
226 (capa & PCI_EXP_LNKCAP_MLW) >> 4);
227 cobalt_info("PCIe link control 0x%04x\n", ctrl);
228 cobalt_info("PCIe link status 0x%04x: %s per lane and %u lanes\n",
229 stat, get_link_speed(stat),
230 (stat & PCI_EXP_LNKSTA_NLW) >> 4);
231
232 /* Bus */
233 pci_read_config_dword(pci_bus_dev, bus_offset + PCI_EXP_LNKCAP, &capa);
234 cobalt_info("PCIe bus link capability 0x%08x: %s per lane and %u lanes\n",
235 capa, get_link_speed(capa),
236 (capa & PCI_EXP_LNKCAP_MLW) >> 4);
237
238 /* Slot */
239 pci_read_config_dword(pci_dev, offset + PCI_EXP_SLTCAP, &capa);
240 pci_read_config_word(pci_dev, offset + PCI_EXP_SLTCTL, &ctrl);
241 pci_read_config_word(pci_dev, offset + PCI_EXP_SLTSTA, &stat);
242 cobalt_info("PCIe slot capability 0x%08x\n", capa);
243 cobalt_info("PCIe slot control 0x%04x\n", ctrl);
244 cobalt_info("PCIe slot status 0x%04x\n", stat);
245}
246
247static unsigned pcie_link_get_lanes(struct cobalt *cobalt)
248{
249 struct pci_dev *pci_dev = cobalt->pci_dev;
250 unsigned offset;
251 u16 link;
252
253 offset = pci_find_capability(pci_dev, PCI_CAP_ID_EXP);
254 if (!offset)
255 return 0;
256 pci_read_config_word(pci_dev, offset + PCI_EXP_LNKSTA, &link);
257 return (link & PCI_EXP_LNKSTA_NLW) >> 4;
258}
259
260static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
261{
262 struct pci_dev *pci_dev = cobalt->pci_dev->bus->self;
263 unsigned offset;
264 u32 link;
265
266 offset = pci_find_capability(pci_dev, PCI_CAP_ID_EXP);
267 if (!offset)
268 return 0;
269 pci_read_config_dword(pci_dev, offset + PCI_EXP_LNKCAP, &link);
270 return (link & PCI_EXP_LNKCAP_MLW) >> 4;
271}
272
273static void msi_config_show(struct cobalt *cobalt, struct pci_dev *pci_dev)
274{
275 u16 ctrl, data;
276 u32 adrs_l, adrs_h;
277
278 pci_read_config_word(pci_dev, 0x52, &ctrl);
279 cobalt_info("MSI %s\n", ctrl & 1 ? "enable" : "disable");
280 cobalt_info("MSI multiple message: Capable %u. Enable %u\n",
281 (1 << ((ctrl >> 1) & 7)), (1 << ((ctrl >> 4) & 7)));
282 if (ctrl & 0x80)
283 cobalt_info("MSI: 64-bit address capable\n");
284 pci_read_config_dword(pci_dev, 0x54, &adrs_l);
285 pci_read_config_dword(pci_dev, 0x58, &adrs_h);
286 pci_read_config_word(pci_dev, 0x5c, &data);
287 if (ctrl & 0x80)
288 cobalt_info("MSI: Address 0x%08x%08x. Data 0x%04x\n",
289 adrs_h, adrs_l, data);
290 else
291 cobalt_info("MSI: Address 0x%08x. Data 0x%04x\n",
292 adrs_l, data);
293}
294
295static void cobalt_pci_iounmap(struct cobalt *cobalt, struct pci_dev *pci_dev)
296{
297 if (cobalt->bar0) {
298 pci_iounmap(pci_dev, cobalt->bar0);
299 cobalt->bar0 = NULL;
300 }
301 if (cobalt->bar1) {
302 pci_iounmap(pci_dev, cobalt->bar1);
303 cobalt->bar1 = NULL;
304 }
305}
306
307static void cobalt_free_msi(struct cobalt *cobalt, struct pci_dev *pci_dev)
308{
309 free_irq(pci_dev->irq, (void *)cobalt);
310
311 if (cobalt->msi_enabled)
312 pci_disable_msi(pci_dev);
313}
314
315static int cobalt_setup_pci(struct cobalt *cobalt, struct pci_dev *pci_dev,
316 const struct pci_device_id *pci_id)
317{
318 u32 ctrl;
319 int ret;
320
321 cobalt_dbg(1, "enabling pci device\n");
322
323 ret = pci_enable_device(pci_dev);
324 if (ret) {
325 cobalt_err("can't enable device\n");
326 return ret;
327 }
328 pci_set_master(pci_dev);
329 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &cobalt->card_rev);
330 pci_read_config_word(pci_dev, PCI_DEVICE_ID, &cobalt->device_id);
331
332 switch (cobalt->device_id) {
333 case PCI_DEVICE_ID_COBALT:
334 cobalt_info("PCI Express interface from Omnitek\n");
335 break;
336 default:
337 cobalt_info("PCI Express interface provider is unknown!\n");
338 break;
339 }
340
341 if (pcie_link_get_lanes(cobalt) != 8) {
342 cobalt_err("PCI Express link width is not 8 lanes (%d)\n",
343 pcie_link_get_lanes(cobalt));
344 if (pcie_bus_link_get_lanes(cobalt) < 8)
345 cobalt_err("The current slot only supports %d lanes, at least 8 are needed\n",
346 pcie_bus_link_get_lanes(cobalt));
347 else
348 cobalt_err("The card is most likely not seated correctly in the PCIe slot\n");
349 ret = -EIO;
350 goto err_disable;
351 }
352
353 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(64))) {
354 ret = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
355 if (ret) {
356 cobalt_err("no suitable DMA available\n");
357 goto err_disable;
358 }
359 }
360
361 ret = pci_request_regions(pci_dev, "cobalt");
362 if (ret) {
363 cobalt_err("error requesting regions\n");
364 goto err_disable;
365 }
366
367 cobalt_pcie_status_show(cobalt);
368
369 cobalt->bar0 = pci_iomap(pci_dev, 0, 0);
370 cobalt->bar1 = pci_iomap(pci_dev, 1, 0);
371 if (cobalt->bar1 == NULL) {
372 cobalt->bar1 = pci_iomap(pci_dev, 2, 0);
373 cobalt_info("64-bit BAR\n");
374 }
375 if (!cobalt->bar0 || !cobalt->bar1) {
376 ret = -EIO;
377 goto err_release;
378 }
379
380 /* Reset the video inputs before enabling any interrupts */
381 ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
382 cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE, ctrl & ~0xf00);
383
384 /* Disable interrupts to prevent any spurious interrupts
385 from being generated. */
386 cobalt_set_interrupt(cobalt, false);
387
388 if (pci_enable_msi_range(pci_dev, 1, 1) < 1) {
389 cobalt_err("Could not enable MSI\n");
390 cobalt->msi_enabled = false;
391 ret = -EIO;
392 goto err_release;
393 }
394 msi_config_show(cobalt, pci_dev);
395 cobalt->msi_enabled = true;
396
397 /* Register IRQ */
398 if (request_irq(pci_dev->irq, cobalt_irq_handler, IRQF_SHARED,
399 cobalt->v4l2_dev.name, (void *)cobalt)) {
400 cobalt_err("Failed to register irq %d\n", pci_dev->irq);
401 ret = -EIO;
402 goto err_msi;
403 }
404
405 omni_sg_dma_init(cobalt);
406 return 0;
407
408err_msi:
409 pci_disable_msi(pci_dev);
410
411err_release:
412 cobalt_pci_iounmap(cobalt, pci_dev);
413 pci_release_regions(pci_dev);
414
415err_disable:
416 pci_disable_device(cobalt->pci_dev);
417 return ret;
418}
419
420static int cobalt_hdl_info_get(struct cobalt *cobalt)
421{
422 int i;
423
424 for (i = 0; i < COBALT_HDL_INFO_SIZE; i++)
425 cobalt->hdl_info[i] =
426 ioread8(cobalt->bar1 + COBALT_HDL_INFO_BASE + i);
427 cobalt->hdl_info[COBALT_HDL_INFO_SIZE - 1] = '\0';
428 if (strstr(cobalt->hdl_info, COBALT_HDL_SEARCH_STR))
429 return 0;
430
431 return 1;
432}
433
434static void cobalt_stream_struct_init(struct cobalt *cobalt)
435{
436 int i;
437
438 for (i = 0; i < COBALT_NUM_STREAMS; i++) {
439 struct cobalt_stream *s = &cobalt->streams[i];
440
441 s->cobalt = cobalt;
442 s->flags = 0;
443 s->is_audio = false;
444 s->is_output = false;
445 s->is_dummy = true;
446
447 /* The Memory DMA channels will always get a lower channel
448 * number than the FIFO DMA. Video input should map to the
449 * stream 0-3. The other can use stream struct from 4 and
450 * higher */
451 if (i <= COBALT_HSMA_IN_NODE) {
452 s->dma_channel = i + cobalt->first_fifo_channel;
453 s->video_channel = i;
454 s->dma_fifo_mask =
455 COBALT_SYSSTAT_VI0_LOST_DATA_MSK << (4 * i);
456 s->adv_irq_mask =
457 COBALT_SYSSTAT_VI0_INT1_MSK << (4 * i);
458 } else if (i >= COBALT_AUDIO_IN_STREAM &&
459 i <= COBALT_AUDIO_IN_STREAM + 4) {
460 unsigned idx = i - COBALT_AUDIO_IN_STREAM;
461
462 s->dma_channel = 6 + idx;
463 s->is_audio = true;
464 s->video_channel = idx;
465 s->dma_fifo_mask = COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK;
466 } else if (i == COBALT_HSMA_OUT_NODE) {
467 s->dma_channel = 11;
468 s->is_output = true;
469 s->video_channel = 5;
470 s->dma_fifo_mask = COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK;
471 s->adv_irq_mask = COBALT_SYSSTAT_VOHSMA_INT1_MSK;
472 } else if (i == COBALT_AUDIO_OUT_STREAM) {
473 s->dma_channel = 12;
474 s->is_audio = true;
475 s->is_output = true;
476 s->video_channel = 5;
477 s->dma_fifo_mask = COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK;
478 } else {
479 /* FIXME: Memory DMA for debug purpose */
480 s->dma_channel = i - COBALT_NUM_NODES;
481 }
482 cobalt_info("stream #%d -> dma channel #%d <- video channel %d\n",
483 i, s->dma_channel, s->video_channel);
484 }
485}
486
487static int cobalt_subdevs_init(struct cobalt *cobalt)
488{
489 static struct adv76xx_platform_data adv7604_pdata = {
490 .disable_pwrdnb = 1,
491 .ain_sel = ADV7604_AIN7_8_9_NC_SYNC_3_1,
492 .bus_order = ADV7604_BUS_ORDER_BRG,
493 .blank_data = 1,
494 .op_656_range = 1,
495 .op_format_mode_sel = ADV7604_OP_FORMAT_MODE0,
496 .int1_config = ADV76XX_INT1_CONFIG_ACTIVE_HIGH,
497 .dr_str_data = ADV76XX_DR_STR_HIGH,
498 .dr_str_clk = ADV76XX_DR_STR_HIGH,
499 .dr_str_sync = ADV76XX_DR_STR_HIGH,
500 .hdmi_free_run_mode = 1,
501 .inv_vs_pol = 1,
502 .inv_hs_pol = 1,
503 };
504 static struct i2c_board_info adv7604_info = {
505 .type = "adv7604",
506 .addr = 0x20,
507 .platform_data = &adv7604_pdata,
508 };
509
510 struct cobalt_stream *s = cobalt->streams;
511 int i;
512
513 for (i = 0; i < COBALT_NUM_INPUTS; i++) {
514 struct v4l2_subdev_format sd_fmt = {
515 .pad = ADV7604_PAD_SOURCE,
516 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
517 .format.code = MEDIA_BUS_FMT_YUYV8_1X16,
518 };
519 struct v4l2_subdev_edid cobalt_edid = {
520 .pad = ADV76XX_PAD_HDMI_PORT_A,
521 .start_block = 0,
522 .blocks = 2,
523 .edid = edid,
524 };
525 int err;
526
527 s[i].pad_source = ADV7604_PAD_SOURCE;
528 s[i].i2c_adap = &cobalt->i2c_adap[i];
529 if (s[i].i2c_adap->dev.parent == NULL)
530 continue;
531 cobalt_s_bit_sysctrl(cobalt,
532 COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(i), 1);
533 s[i].sd = v4l2_i2c_new_subdev_board(&cobalt->v4l2_dev,
534 s[i].i2c_adap, &adv7604_info, NULL);
535 if (!s[i].sd) {
536 if (cobalt_ignore_err)
537 continue;
538 return -ENODEV;
539 }
540 err = v4l2_subdev_call(s[i].sd, video, s_routing,
541 ADV76XX_PAD_HDMI_PORT_A, 0, 0);
542 if (err)
543 return err;
544 err = v4l2_subdev_call(s[i].sd, pad, set_edid,
545 &cobalt_edid);
546 if (err)
547 return err;
548 err = v4l2_subdev_call(s[i].sd, pad, set_fmt, NULL,
549 &sd_fmt);
550 if (err)
551 return err;
552 /* Reset channel video module */
553 cobalt_s_bit_sysctrl(cobalt,
554 COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(i), 0);
555 mdelay(2);
556 cobalt_s_bit_sysctrl(cobalt,
557 COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(i), 1);
558 mdelay(1);
559 s[i].is_dummy = false;
560 cobalt->streams[i + COBALT_AUDIO_IN_STREAM].is_dummy = false;
561 }
562 return 0;
563}
564
565static int cobalt_subdevs_hsma_init(struct cobalt *cobalt)
566{
567 static struct adv7842_platform_data adv7842_pdata = {
568 .disable_pwrdnb = 1,
569 .ain_sel = ADV7842_AIN1_2_3_NC_SYNC_1_2,
570 .bus_order = ADV7842_BUS_ORDER_RBG,
571 .op_format_mode_sel = ADV7842_OP_FORMAT_MODE0,
572 .blank_data = 1,
573 .op_656_range = 1,
574 .dr_str_data = 3,
575 .dr_str_clk = 3,
576 .dr_str_sync = 3,
577 .mode = ADV7842_MODE_HDMI,
578 .hdmi_free_run_enable = 1,
579 .vid_std_select = ADV7842_HDMI_COMP_VID_STD_HD_1250P,
580 .i2c_sdp_io = 0x4a,
581 .i2c_sdp = 0x48,
582 .i2c_cp = 0x22,
583 .i2c_vdp = 0x24,
584 .i2c_afe = 0x26,
585 .i2c_hdmi = 0x34,
586 .i2c_repeater = 0x32,
587 .i2c_edid = 0x36,
588 .i2c_infoframe = 0x3e,
589 .i2c_cec = 0x40,
590 .i2c_avlink = 0x42,
591 };
592 static struct i2c_board_info adv7842_info = {
593 .type = "adv7842",
594 .addr = 0x20,
595 .platform_data = &adv7842_pdata,
596 };
597 static struct v4l2_subdev_format sd_fmt = {
598 .pad = ADV7842_PAD_SOURCE,
599 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
600 .format.code = MEDIA_BUS_FMT_YUYV8_1X16,
601 };
602 static struct adv7511_platform_data adv7511_pdata = {
603 .i2c_edid = 0x7e >> 1,
604 .i2c_cec = 0x7c >> 1,
605 .i2c_pktmem = 0x70 >> 1,
606 .cec_clk = 12000000,
607 };
608 static struct i2c_board_info adv7511_info = {
609 .type = "adv7511",
610 .addr = 0x39, /* 0x39 or 0x3d */
611 .platform_data = &adv7511_pdata,
612 };
613 struct v4l2_subdev_edid cobalt_edid = {
614 .pad = ADV7842_EDID_PORT_A,
615 .start_block = 0,
616 .blocks = 2,
617 .edid = edid,
618 };
619 struct cobalt_stream *s = &cobalt->streams[COBALT_HSMA_IN_NODE];
620
621 s->i2c_adap = &cobalt->i2c_adap[COBALT_NUM_ADAPTERS - 1];
622 if (s->i2c_adap->dev.parent == NULL)
623 return 0;
624 cobalt_s_bit_sysctrl(cobalt, COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(4), 1);
625
626 s->sd = v4l2_i2c_new_subdev_board(&cobalt->v4l2_dev,
627 s->i2c_adap, &adv7842_info, NULL);
628 if (s->sd) {
629 int err = v4l2_subdev_call(s->sd, pad, set_edid, &cobalt_edid);
630
631 if (err)
632 return err;
633 err = v4l2_subdev_call(s->sd, pad, set_fmt, NULL,
634 &sd_fmt);
635 if (err)
636 return err;
637 cobalt->have_hsma_rx = true;
638 s->pad_source = ADV7842_PAD_SOURCE;
639 s->is_dummy = false;
640 cobalt->streams[4 + COBALT_AUDIO_IN_STREAM].is_dummy = false;
641 /* Reset channel video module */
642 cobalt_s_bit_sysctrl(cobalt,
643 COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(4), 0);
644 mdelay(2);
645 cobalt_s_bit_sysctrl(cobalt,
646 COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(4), 1);
647 mdelay(1);
648 return err;
649 }
650 cobalt_s_bit_sysctrl(cobalt, COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(4), 0);
651 cobalt_s_bit_sysctrl(cobalt, COBALT_SYS_CTRL_PWRDN0_TO_HSMA_TX_BIT, 0);
652 s++;
653 s->i2c_adap = &cobalt->i2c_adap[COBALT_NUM_ADAPTERS - 1];
654 s->sd = v4l2_i2c_new_subdev_board(&cobalt->v4l2_dev,
655 s->i2c_adap, &adv7511_info, NULL);
656 if (s->sd) {
657 /* A transmitter is hooked up, so we can set this bit */
658 cobalt_s_bit_sysctrl(cobalt,
659 COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT, 1);
660 cobalt_s_bit_sysctrl(cobalt,
661 COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(4), 0);
662 cobalt_s_bit_sysctrl(cobalt,
663 COBALT_SYS_CTRL_VIDEO_TX_RESETN_BIT, 1);
664 cobalt->have_hsma_tx = true;
665 v4l2_subdev_call(s->sd, core, s_power, 1);
666 v4l2_subdev_call(s->sd, video, s_stream, 1);
667 v4l2_subdev_call(s->sd, audio, s_stream, 1);
668 v4l2_ctrl_s_ctrl(v4l2_ctrl_find(s->sd->ctrl_handler,
669 V4L2_CID_DV_TX_MODE), V4L2_DV_TX_MODE_HDMI);
670 s->is_dummy = false;
671 cobalt->streams[COBALT_AUDIO_OUT_STREAM].is_dummy = false;
672 return 0;
673 }
674 return -ENODEV;
675}
676
677static int cobalt_probe(struct pci_dev *pci_dev,
678 const struct pci_device_id *pci_id)
679{
680 struct cobalt *cobalt;
681 int retval = 0;
682 int i;
683
684 /* FIXME - module parameter arrays constrain max instances */
685 i = atomic_inc_return(&cobalt_instance) - 1;
686
687 cobalt = kzalloc(sizeof(struct cobalt), GFP_ATOMIC);
688 if (cobalt == NULL)
689 return -ENOMEM;
690 cobalt->pci_dev = pci_dev;
691 cobalt->instance = i;
692
693 cobalt->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev);
694 if (IS_ERR(cobalt->alloc_ctx)) {
695 kfree(cobalt);
696 return -ENOMEM;
697 }
698
699 retval = v4l2_device_register(&pci_dev->dev, &cobalt->v4l2_dev);
700 if (retval) {
701 pr_err("cobalt: v4l2_device_register of card %d failed\n",
702 cobalt->instance);
703 vb2_dma_sg_cleanup_ctx(cobalt->alloc_ctx);
704 kfree(cobalt);
705 return retval;
706 }
707 snprintf(cobalt->v4l2_dev.name, sizeof(cobalt->v4l2_dev.name),
708 "cobalt-%d", cobalt->instance);
709 cobalt->v4l2_dev.notify = cobalt_notify;
710 cobalt_info("Initializing card %d\n", cobalt->instance);
711
712 cobalt->irq_work_queues =
713 create_singlethread_workqueue(cobalt->v4l2_dev.name);
714 if (cobalt->irq_work_queues == NULL) {
715 cobalt_err("Could not create workqueue\n");
716 retval = -ENOMEM;
717 goto err;
718 }
719
720 INIT_WORK(&cobalt->irq_work_queue, cobalt_irq_work_handler);
721
722 /* PCI Device Setup */
723 retval = cobalt_setup_pci(cobalt, pci_dev, pci_id);
724 if (retval != 0)
725 goto err_wq;
726
727 /* Show HDL version info */
728 if (cobalt_hdl_info_get(cobalt))
729 cobalt_info("Not able to read the HDL info\n");
730 else
731 cobalt_info("%s", cobalt->hdl_info);
732
733 retval = cobalt_i2c_init(cobalt);
734 if (retval)
735 goto err_pci;
736
737 cobalt_stream_struct_init(cobalt);
738
739 retval = cobalt_subdevs_init(cobalt);
740 if (retval)
741 goto err_i2c;
742
743 if (!(cobalt_read_bar1(cobalt, COBALT_SYS_STAT_BASE) &
744 COBALT_SYSSTAT_HSMA_PRSNTN_MSK)) {
745 retval = cobalt_subdevs_hsma_init(cobalt);
746 if (retval)
747 goto err_i2c;
748 }
749
750 retval = v4l2_device_register_subdev_nodes(&cobalt->v4l2_dev);
751 if (retval)
752 goto err_i2c;
753 retval = cobalt_nodes_register(cobalt);
754 if (retval) {
755 cobalt_err("Error %d registering device nodes\n", retval);
756 goto err_i2c;
757 }
758 cobalt_set_interrupt(cobalt, true);
759 v4l2_device_call_all(&cobalt->v4l2_dev, 0, core,
760 interrupt_service_routine, 0, NULL);
761
762 cobalt_info("Initialized cobalt card\n");
763
764 cobalt_flash_probe(cobalt);
765
766 return 0;
767
768err_i2c:
769 cobalt_i2c_exit(cobalt);
770 cobalt_s_bit_sysctrl(cobalt, COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT, 0);
771err_pci:
772 cobalt_free_msi(cobalt, pci_dev);
773 cobalt_pci_iounmap(cobalt, pci_dev);
774 pci_release_regions(cobalt->pci_dev);
775 pci_disable_device(cobalt->pci_dev);
776err_wq:
777 destroy_workqueue(cobalt->irq_work_queues);
778err:
779 if (retval == 0)
780 retval = -ENODEV;
781 cobalt_err("error %d on initialization\n", retval);
782
783 v4l2_device_unregister(&cobalt->v4l2_dev);
784 vb2_dma_sg_cleanup_ctx(cobalt->alloc_ctx);
785 kfree(cobalt);
786 return retval;
787}
788
789static void cobalt_remove(struct pci_dev *pci_dev)
790{
791 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
792 struct cobalt *cobalt = to_cobalt(v4l2_dev);
793 int i;
794
795 cobalt_flash_remove(cobalt);
796 cobalt_set_interrupt(cobalt, false);
797 flush_workqueue(cobalt->irq_work_queues);
798 cobalt_nodes_unregister(cobalt);
799 for (i = 0; i < COBALT_NUM_ADAPTERS; i++) {
800 struct v4l2_subdev *sd = cobalt->streams[i].sd;
801 struct i2c_client *client;
802
803 if (sd == NULL)
804 continue;
805 client = v4l2_get_subdevdata(sd);
806 v4l2_device_unregister_subdev(sd);
807 i2c_unregister_device(client);
808 }
809 cobalt_i2c_exit(cobalt);
810 cobalt_free_msi(cobalt, pci_dev);
811 cobalt_s_bit_sysctrl(cobalt, COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT, 0);
812 cobalt_pci_iounmap(cobalt, pci_dev);
813 pci_release_regions(cobalt->pci_dev);
814 pci_disable_device(cobalt->pci_dev);
815 destroy_workqueue(cobalt->irq_work_queues);
816
817 cobalt_info("removed cobalt card\n");
818
819 v4l2_device_unregister(v4l2_dev);
820 vb2_dma_sg_cleanup_ctx(cobalt->alloc_ctx);
821 kfree(cobalt);
822}
823
824/* define a pci_driver for card detection */
825static struct pci_driver cobalt_pci_driver = {
826 .name = "cobalt",
827 .id_table = cobalt_pci_tbl,
828 .probe = cobalt_probe,
829 .remove = cobalt_remove,
830};
831
832module_pci_driver(cobalt_pci_driver);
diff --git a/drivers/media/pci/cobalt/cobalt-driver.h b/drivers/media/pci/cobalt/cobalt-driver.h
new file mode 100644
index 000000000000..c206df930669
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-driver.h
@@ -0,0 +1,380 @@
1/*
2 * cobalt driver internal defines and structures
3 *
4 * Derived from cx18-driver.h
5 *
6 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
7 * All rights reserved.
8 *
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#ifndef COBALT_DRIVER_H
24#define COBALT_DRIVER_H
25
26#include <linux/module.h>
27#include <linux/pci.h>
28#include <linux/spinlock.h>
29#include <linux/i2c.h>
30#include <linux/list.h>
31#include <linux/workqueue.h>
32#include <linux/mutex.h>
33
34#include <media/v4l2-common.h>
35#include <media/v4l2-ioctl.h>
36#include <media/v4l2-device.h>
37#include <media/v4l2-fh.h>
38#include <media/videobuf2-dma-sg.h>
39
40#include "m00233_video_measure_memmap_package.h"
41#include "m00235_fdma_packer_memmap_package.h"
42#include "m00389_cvi_memmap_package.h"
43#include "m00460_evcnt_memmap_package.h"
44#include "m00473_freewheel_memmap_package.h"
45#include "m00479_clk_loss_detector_memmap_package.h"
46#include "m00514_syncgen_flow_evcnt_memmap_package.h"
47
48/* System device ID */
49#define PCI_DEVICE_ID_COBALT 0x2732
50
51/* Number of cobalt device nodes. */
52#define COBALT_NUM_INPUTS 4
53#define COBALT_NUM_NODES 6
54
55/* Number of cobalt device streams. */
56#define COBALT_NUM_STREAMS 12
57
58#define COBALT_HSMA_IN_NODE 4
59#define COBALT_HSMA_OUT_NODE 5
60
61/* Cobalt audio streams */
62#define COBALT_AUDIO_IN_STREAM 6
63#define COBALT_AUDIO_OUT_STREAM 11
64
65/* DMA stuff */
66#define DMA_CHANNELS_MAX 16
67
68/* i2c stuff */
69#define I2C_CLIENTS_MAX 16
70#define COBALT_NUM_ADAPTERS 5
71
72#define COBALT_CLK 50000000
73
74/* System status register */
75#define COBALT_SYSSTAT_DIP0_MSK (1 << 0)
76#define COBALT_SYSSTAT_DIP1_MSK (1 << 1)
77#define COBALT_SYSSTAT_HSMA_PRSNTN_MSK (1 << 2)
78#define COBALT_SYSSTAT_FLASH_RDYBSYN_MSK (1 << 3)
79#define COBALT_SYSSTAT_VI0_5V_MSK (1 << 4)
80#define COBALT_SYSSTAT_VI0_INT1_MSK (1 << 5)
81#define COBALT_SYSSTAT_VI0_INT2_MSK (1 << 6)
82#define COBALT_SYSSTAT_VI0_LOST_DATA_MSK (1 << 7)
83#define COBALT_SYSSTAT_VI1_5V_MSK (1 << 8)
84#define COBALT_SYSSTAT_VI1_INT1_MSK (1 << 9)
85#define COBALT_SYSSTAT_VI1_INT2_MSK (1 << 10)
86#define COBALT_SYSSTAT_VI1_LOST_DATA_MSK (1 << 11)
87#define COBALT_SYSSTAT_VI2_5V_MSK (1 << 12)
88#define COBALT_SYSSTAT_VI2_INT1_MSK (1 << 13)
89#define COBALT_SYSSTAT_VI2_INT2_MSK (1 << 14)
90#define COBALT_SYSSTAT_VI2_LOST_DATA_MSK (1 << 15)
91#define COBALT_SYSSTAT_VI3_5V_MSK (1 << 16)
92#define COBALT_SYSSTAT_VI3_INT1_MSK (1 << 17)
93#define COBALT_SYSSTAT_VI3_INT2_MSK (1 << 18)
94#define COBALT_SYSSTAT_VI3_LOST_DATA_MSK (1 << 19)
95#define COBALT_SYSSTAT_VIHSMA_5V_MSK (1 << 20)
96#define COBALT_SYSSTAT_VIHSMA_INT1_MSK (1 << 21)
97#define COBALT_SYSSTAT_VIHSMA_INT2_MSK (1 << 22)
98#define COBALT_SYSSTAT_VIHSMA_LOST_DATA_MSK (1 << 23)
99#define COBALT_SYSSTAT_VOHSMA_INT1_MSK (1 << 24)
100#define COBALT_SYSSTAT_VOHSMA_PLL_LOCKED_MSK (1 << 25)
101#define COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK (1 << 26)
102#define COBALT_SYSSTAT_AUD_PLL_LOCKED_MSK (1 << 28)
103#define COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK (1 << 29)
104#define COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK (1 << 30)
105#define COBALT_SYSSTAT_PCIE_SMBCLK_MSK (1 << 31)
106
107/* Cobalt memory map */
108#define COBALT_I2C_0_BASE 0x0
109#define COBALT_I2C_1_BASE 0x080
110#define COBALT_I2C_2_BASE 0x100
111#define COBALT_I2C_3_BASE 0x180
112#define COBALT_I2C_HSMA_BASE 0x200
113
114#define COBALT_SYS_CTRL_BASE 0x400
115#define COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT 1
116#define COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(n) (4 + 4 * (n))
117#define COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(n) (5 + 4 * (n))
118#define COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(n) (6 + 4 * (n))
119#define COBALT_SYS_CTRL_AUDIO_IPP_RESETN_BIT(n) (7 + 4 * (n))
120#define COBALT_SYS_CTRL_PWRDN0_TO_HSMA_TX_BIT 24
121#define COBALT_SYS_CTRL_VIDEO_TX_RESETN_BIT 25
122#define COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT 27
123
124#define COBALT_SYS_STAT_BASE 0x500
125#define COBALT_SYS_STAT_MASK (COBALT_SYS_STAT_BASE + 0x08)
126#define COBALT_SYS_STAT_EDGE (COBALT_SYS_STAT_BASE + 0x0c)
127
128#define COBALT_HDL_INFO_BASE 0x4800
129#define COBALT_HDL_INFO_SIZE 0x200
130
131#define COBALT_VID_BASE 0x10000
132#define COBALT_VID_SIZE 0x1000
133
134#define COBALT_CVI(cobalt, c) \
135 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE)
136#define COBALT_CVI_VMR(cobalt, c) \
137 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x100)
138#define COBALT_CVI_EVCNT(cobalt, c) \
139 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x200)
140#define COBALT_CVI_FREEWHEEL(cobalt, c) \
141 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x300)
142#define COBALT_CVI_CLK_LOSS(cobalt, c) \
143 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x400)
144#define COBALT_CVI_PACKER(cobalt, c) \
145 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x500)
146
147#define COBALT_TX_BASE(cobalt) (cobalt->bar1 + COBALT_VID_BASE + 0x5000)
148
149#define DMA_INTERRUPT_STATUS_REG 0x08
150
151#define COBALT_HDL_SEARCH_STR "** HDL version info **"
152
153/* Cobalt CPU bus interface */
154#define COBALT_BUS_BAR1_BASE 0x600
155#define COBALT_BUS_SRAM_BASE 0x0
156#define COBALT_BUS_CPLD_BASE 0x00600000
157#define COBALT_BUS_FLASH_BASE 0x08000000
158
159/* FDMA to PCIe packing */
160#define COBALT_BYTES_PER_PIXEL_YUYV 2
161#define COBALT_BYTES_PER_PIXEL_RGB24 3
162#define COBALT_BYTES_PER_PIXEL_RGB32 4
163
164/* debugging */
165extern int cobalt_debug;
166extern int cobalt_ignore_err;
167
168#define cobalt_err(fmt, arg...) v4l2_err(&cobalt->v4l2_dev, fmt, ## arg)
169#define cobalt_warn(fmt, arg...) v4l2_warn(&cobalt->v4l2_dev, fmt, ## arg)
170#define cobalt_info(fmt, arg...) v4l2_info(&cobalt->v4l2_dev, fmt, ## arg)
171#define cobalt_dbg(level, fmt, arg...) \
172 v4l2_dbg(level, cobalt_debug, &cobalt->v4l2_dev, fmt, ## arg)
173
174struct cobalt;
175struct cobalt_i2c_regs;
176
177/* Per I2C bus private algo callback data */
178struct cobalt_i2c_data {
179 struct cobalt *cobalt;
180 struct cobalt_i2c_regs __iomem *regs;
181};
182
183struct pci_consistent_buffer {
184 void *virt;
185 dma_addr_t bus;
186 size_t bytes;
187};
188
189struct sg_dma_desc_info {
190 void *virt;
191 dma_addr_t bus;
192 unsigned size;
193 void *last_desc_virt;
194 struct device *dev;
195};
196
197#define COBALT_MAX_WIDTH 1920
198#define COBALT_MAX_HEIGHT 1200
199#define COBALT_MAX_BPP 3
200#define COBALT_MAX_FRAMESZ \
201 (COBALT_MAX_WIDTH * COBALT_MAX_HEIGHT * COBALT_MAX_BPP)
202
203#define NR_BUFS VIDEO_MAX_FRAME
204
205#define COBALT_STREAM_FL_DMA_IRQ 0
206#define COBALT_STREAM_FL_ADV_IRQ 1
207
208struct cobalt_buffer {
209 struct vb2_buffer vb;
210 struct list_head list;
211};
212
213static inline struct cobalt_buffer *to_cobalt_buffer(struct vb2_buffer *vb2)
214{
215 return container_of(vb2, struct cobalt_buffer, vb);
216}
217
218struct cobalt_stream {
219 struct video_device vdev;
220 struct vb2_queue q;
221 struct list_head bufs;
222 struct i2c_adapter *i2c_adap;
223 struct v4l2_subdev *sd;
224 struct mutex lock;
225 spinlock_t irqlock;
226 struct v4l2_dv_timings timings;
227 u32 input;
228 u32 pad_source;
229 u32 width, height, bpp;
230 u32 stride;
231 u32 pixfmt;
232 u32 sequence;
233 u32 colorspace;
234 u32 xfer_func;
235 u32 ycbcr_enc;
236 u32 quantization;
237
238 u8 dma_channel;
239 int video_channel;
240 unsigned dma_fifo_mask;
241 unsigned adv_irq_mask;
242 struct sg_dma_desc_info dma_desc_info[NR_BUFS];
243 unsigned long flags;
244 bool unstable_frame;
245 bool enable_cvi;
246 bool enable_freewheel;
247 unsigned skip_first_frames;
248 bool is_output;
249 bool is_audio;
250 bool is_dummy;
251
252 struct cobalt *cobalt;
253 struct snd_cobalt_card *alsa;
254};
255
256struct snd_cobalt_card;
257
258/* Struct to hold info about cobalt cards */
259struct cobalt {
260 int instance;
261 struct pci_dev *pci_dev;
262 struct v4l2_device v4l2_dev;
263 void *alloc_ctx;
264
265 void __iomem *bar0, *bar1;
266
267 u8 card_rev;
268 u16 device_id;
269
270 /* device nodes */
271 struct cobalt_stream streams[DMA_CHANNELS_MAX];
272 struct i2c_adapter i2c_adap[COBALT_NUM_ADAPTERS];
273 struct cobalt_i2c_data i2c_data[COBALT_NUM_ADAPTERS];
274 bool have_hsma_rx;
275 bool have_hsma_tx;
276
277 /* irq */
278 struct workqueue_struct *irq_work_queues;
279 struct work_struct irq_work_queue; /* work entry */
280 /* irq counters */
281 u32 irq_adv1;
282 u32 irq_adv2;
283 u32 irq_advout;
284 u32 irq_dma_tot;
285 u32 irq_dma[COBALT_NUM_STREAMS];
286 u32 irq_none;
287 u32 irq_full_fifo;
288
289 bool msi_enabled;
290
291 /* omnitek dma */
292 int dma_channels;
293 int first_fifo_channel;
294 bool pci_32_bit;
295
296 char hdl_info[COBALT_HDL_INFO_SIZE];
297
298 /* NOR flash */
299 struct mtd_info *mtd;
300};
301
302static inline struct cobalt *to_cobalt(struct v4l2_device *v4l2_dev)
303{
304 return container_of(v4l2_dev, struct cobalt, v4l2_dev);
305}
306
307static inline void cobalt_write_bar0(struct cobalt *cobalt, u32 reg, u32 val)
308{
309 iowrite32(val, cobalt->bar0 + reg);
310}
311
312static inline u32 cobalt_read_bar0(struct cobalt *cobalt, u32 reg)
313{
314 return ioread32(cobalt->bar0 + reg);
315}
316
317static inline void cobalt_write_bar1(struct cobalt *cobalt, u32 reg, u32 val)
318{
319 iowrite32(val, cobalt->bar1 + reg);
320}
321
322static inline u32 cobalt_read_bar1(struct cobalt *cobalt, u32 reg)
323{
324 return ioread32(cobalt->bar1 + reg);
325}
326
327static inline u32 cobalt_g_sysctrl(struct cobalt *cobalt)
328{
329 return cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
330}
331
332static inline void cobalt_s_bit_sysctrl(struct cobalt *cobalt,
333 int bit, int val)
334{
335 u32 ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
336
337 cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE,
338 (ctrl & ~(1UL << bit)) | (val << bit));
339}
340
341static inline u32 cobalt_g_sysstat(struct cobalt *cobalt)
342{
343 return cobalt_read_bar1(cobalt, COBALT_SYS_STAT_BASE);
344}
345
346#define ADRS_REG (bar1 + COBALT_BUS_BAR1_BASE + 0)
347#define LOWER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 4)
348#define UPPER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 6)
349
350static inline u32 cobalt_bus_read32(void __iomem *bar1, u32 bus_adrs)
351{
352 iowrite32(bus_adrs, ADRS_REG);
353 return ioread32(LOWER_DATA);
354}
355
356static inline void cobalt_bus_write16(void __iomem *bar1,
357 u32 bus_adrs, u16 data)
358{
359 iowrite32(bus_adrs, ADRS_REG);
360 if (bus_adrs & 2)
361 iowrite16(data, UPPER_DATA);
362 else
363 iowrite16(data, LOWER_DATA);
364}
365
366static inline void cobalt_bus_write32(void __iomem *bar1,
367 u32 bus_adrs, u16 data)
368{
369 iowrite32(bus_adrs, ADRS_REG);
370 if (bus_adrs & 2)
371 iowrite32(data, UPPER_DATA);
372 else
373 iowrite32(data, LOWER_DATA);
374}
375
376/*==============Prototypes==================*/
377
378void cobalt_pcie_status_show(struct cobalt *cobalt);
379
380#endif
diff --git a/drivers/media/pci/cobalt/cobalt-flash.c b/drivers/media/pci/cobalt/cobalt-flash.c
new file mode 100644
index 000000000000..04dcaf9198d2
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-flash.c
@@ -0,0 +1,128 @@
1/*
2 * Cobalt NOR flash functions
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#include <linux/mtd/mtd.h>
22#include <linux/mtd/map.h>
23#include <linux/mtd/cfi.h>
24#include <linux/time.h>
25
26#include "cobalt-flash.h"
27
28#define ADRS(offset) (COBALT_BUS_FLASH_BASE + offset)
29
30static struct map_info cobalt_flash_map = {
31 .name = "cobalt-flash",
32 .bankwidth = 2, /* 16 bits */
33 .size = 0x4000000, /* 64MB */
34 .phys = 0, /* offset */
35};
36
37static map_word flash_read16(struct map_info *map, unsigned long offset)
38{
39 map_word r;
40
41 r.x[0] = cobalt_bus_read32(map->virt, ADRS(offset));
42 if (offset & 0x2)
43 r.x[0] >>= 16;
44 else
45 r.x[0] &= 0x0000ffff;
46
47 return r;
48}
49
50static void flash_write16(struct map_info *map, const map_word datum,
51 unsigned long offset)
52{
53 u16 data = (u16)datum.x[0];
54
55 cobalt_bus_write16(map->virt, ADRS(offset), data);
56}
57
58static void flash_copy_from(struct map_info *map, void *to,
59 unsigned long from, ssize_t len)
60{
61 u32 src = from;
62 u8 *dest = to;
63 u32 data;
64
65 while (len) {
66 data = cobalt_bus_read32(map->virt, ADRS(src));
67 do {
68 *dest = data >> (8 * (src & 3));
69 src++;
70 dest++;
71 len--;
72 } while (len && (src % 4));
73 }
74}
75
76static void flash_copy_to(struct map_info *map, unsigned long to,
77 const void *from, ssize_t len)
78{
79 const u8 *src = from;
80 u32 dest = to;
81
82 pr_info("%s: offset 0x%x: length %zu\n", __func__, dest, len);
83 while (len) {
84 u16 data = 0xffff;
85
86 do {
87 data = *src << (8 * (dest & 1));
88 src++;
89 dest++;
90 len--;
91 } while (len && (dest % 2));
92
93 cobalt_bus_write16(map->virt, ADRS(dest - 2), data);
94 }
95}
96
97int cobalt_flash_probe(struct cobalt *cobalt)
98{
99 struct map_info *map = &cobalt_flash_map;
100 struct mtd_info *mtd;
101
102 BUG_ON(!map_bankwidth_supported(map->bankwidth));
103 map->virt = cobalt->bar1;
104 map->read = flash_read16;
105 map->write = flash_write16;
106 map->copy_from = flash_copy_from;
107 map->copy_to = flash_copy_to;
108
109 mtd = do_map_probe("cfi_probe", map);
110 cobalt->mtd = mtd;
111 if (!mtd) {
112 cobalt_err("Probe CFI flash failed!\n");
113 return -1;
114 }
115
116 mtd->owner = THIS_MODULE;
117 mtd->dev.parent = &cobalt->pci_dev->dev;
118 mtd_device_register(mtd, NULL, 0);
119 return 0;
120}
121
122void cobalt_flash_remove(struct cobalt *cobalt)
123{
124 if (cobalt->mtd) {
125 mtd_device_unregister(cobalt->mtd);
126 map_destroy(cobalt->mtd);
127 }
128}
diff --git a/drivers/media/pci/cobalt/cobalt-flash.h b/drivers/media/pci/cobalt/cobalt-flash.h
new file mode 100644
index 000000000000..8077daea51cd
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-flash.h
@@ -0,0 +1,29 @@
1/*
2 * Cobalt NOR flash functions
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#ifndef COBALT_FLASH_H
22#define COBALT_FLASH_H
23
24#include "cobalt-driver.h"
25
26int cobalt_flash_probe(struct cobalt *cobalt);
27void cobalt_flash_remove(struct cobalt *cobalt);
28
29#endif
diff --git a/drivers/media/pci/cobalt/cobalt-i2c.c b/drivers/media/pci/cobalt/cobalt-i2c.c
new file mode 100644
index 000000000000..ad16b89b8d0c
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-i2c.c
@@ -0,0 +1,396 @@
1/*
2 * cobalt I2C functions
3 *
4 * Derived from cx18-i2c.c
5 *
6 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
7 * All rights reserved.
8 *
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#include "cobalt-driver.h"
24#include "cobalt-i2c.h"
25
26struct cobalt_i2c_regs {
27 /* Clock prescaler register lo-byte */
28 u8 prerlo;
29 u8 dummy0[3];
30 /* Clock prescaler register high-byte */
31 u8 prerhi;
32 u8 dummy1[3];
33 /* Control register */
34 u8 ctr;
35 u8 dummy2[3];
36 /* Transmit/Receive register */
37 u8 txr_rxr;
38 u8 dummy3[3];
39 /* Command and Status register */
40 u8 cr_sr;
41 u8 dummy4[3];
42};
43
44/* CTR[7:0] - Control register */
45
46/* I2C Core enable bit */
47#define M00018_CTR_BITMAP_EN_MSK (1 << 7)
48
49/* I2C Core interrupt enable bit */
50#define M00018_CTR_BITMAP_IEN_MSK (1 << 6)
51
52/* CR[7:0] - Command register */
53
54/* I2C start condition */
55#define M00018_CR_BITMAP_STA_MSK (1 << 7)
56
57/* I2C stop condition */
58#define M00018_CR_BITMAP_STO_MSK (1 << 6)
59
60/* I2C read from slave */
61#define M00018_CR_BITMAP_RD_MSK (1 << 5)
62
63/* I2C write to slave */
64#define M00018_CR_BITMAP_WR_MSK (1 << 4)
65
66/* I2C ack */
67#define M00018_CR_BITMAP_ACK_MSK (1 << 3)
68
69/* I2C Interrupt ack */
70#define M00018_CR_BITMAP_IACK_MSK (1 << 0)
71
72/* SR[7:0] - Status register */
73
74/* Receive acknowledge from slave */
75#define M00018_SR_BITMAP_RXACK_MSK (1 << 7)
76
77/* Busy, I2C bus busy (as defined by start / stop bits) */
78#define M00018_SR_BITMAP_BUSY_MSK (1 << 6)
79
80/* Arbitration lost - core lost arbitration */
81#define M00018_SR_BITMAP_AL_MSK (1 << 5)
82
83/* Transfer in progress */
84#define M00018_SR_BITMAP_TIP_MSK (1 << 1)
85
86/* Interrupt flag */
87#define M00018_SR_BITMAP_IF_MSK (1 << 0)
88
89/* Frequency, in Hz */
90#define I2C_FREQUENCY 400000
91#define ALT_CPU_FREQ 83333333
92
93static struct cobalt_i2c_regs __iomem *
94cobalt_i2c_regs(struct cobalt *cobalt, unsigned idx)
95{
96 switch (idx) {
97 case 0:
98 default:
99 return (struct cobalt_i2c_regs __iomem *)
100 (cobalt->bar1 + COBALT_I2C_0_BASE);
101 case 1:
102 return (struct cobalt_i2c_regs __iomem *)
103 (cobalt->bar1 + COBALT_I2C_1_BASE);
104 case 2:
105 return (struct cobalt_i2c_regs __iomem *)
106 (cobalt->bar1 + COBALT_I2C_2_BASE);
107 case 3:
108 return (struct cobalt_i2c_regs __iomem *)
109 (cobalt->bar1 + COBALT_I2C_3_BASE);
110 case 4:
111 return (struct cobalt_i2c_regs __iomem *)
112 (cobalt->bar1 + COBALT_I2C_HSMA_BASE);
113 }
114}
115
116/* Do low-level i2c byte transfer.
117 * Returns -1 in case of an error or 0 otherwise.
118 */
119static int cobalt_tx_bytes(struct cobalt_i2c_regs __iomem *regs,
120 struct i2c_adapter *adap, bool start, bool stop,
121 u8 *data, u16 len)
122{
123 unsigned long start_time;
124 int status;
125 int cmd;
126 int i;
127
128 for (i = 0; i < len; i++) {
129 /* Setup data */
130 iowrite8(data[i], &regs->txr_rxr);
131
132 /* Setup command */
133 if (i == 0 && start != 0) {
134 /* Write + Start */
135 cmd = M00018_CR_BITMAP_WR_MSK |
136 M00018_CR_BITMAP_STA_MSK;
137 } else if (i == len - 1 && stop != 0) {
138 /* Write + Stop */
139 cmd = M00018_CR_BITMAP_WR_MSK |
140 M00018_CR_BITMAP_STO_MSK;
141 } else {
142 /* Write only */
143 cmd = M00018_CR_BITMAP_WR_MSK;
144 }
145
146 /* Execute command */
147 iowrite8(cmd, &regs->cr_sr);
148
149 /* Wait for transfer to complete (TIP = 0) */
150 start_time = jiffies;
151 status = ioread8(&regs->cr_sr);
152 while (status & M00018_SR_BITMAP_TIP_MSK) {
153 if (time_after(jiffies, start_time + adap->timeout))
154 return -ETIMEDOUT;
155 cond_resched();
156 status = ioread8(&regs->cr_sr);
157 }
158
159 /* Verify ACK */
160 if (status & M00018_SR_BITMAP_RXACK_MSK) {
161 /* NO ACK! */
162 return -EIO;
163 }
164
165 /* Verify arbitration */
166 if (status & M00018_SR_BITMAP_AL_MSK) {
167 /* Arbitration lost! */
168 return -EIO;
169 }
170 }
171 return 0;
172}
173
174/* Do low-level i2c byte read.
175 * Returns -1 in case of an error or 0 otherwise.
176 */
177static int cobalt_rx_bytes(struct cobalt_i2c_regs __iomem *regs,
178 struct i2c_adapter *adap, bool start, bool stop,
179 u8 *data, u16 len)
180{
181 unsigned long start_time;
182 int status;
183 int cmd;
184 int i;
185
186 for (i = 0; i < len; i++) {
187 /* Setup command */
188 if (i == 0 && start != 0) {
189 /* Read + Start */
190 cmd = M00018_CR_BITMAP_RD_MSK |
191 M00018_CR_BITMAP_STA_MSK;
192 } else if (i == len - 1 && stop != 0) {
193 /* Read + Stop */
194 cmd = M00018_CR_BITMAP_RD_MSK |
195 M00018_CR_BITMAP_STO_MSK;
196 } else {
197 /* Read only */
198 cmd = M00018_CR_BITMAP_RD_MSK;
199 }
200
201 /* Last byte to read, no ACK */
202 if (i == len - 1)
203 cmd |= M00018_CR_BITMAP_ACK_MSK;
204
205 /* Execute command */
206 iowrite8(cmd, &regs->cr_sr);
207
208 /* Wait for transfer to complete (TIP = 0) */
209 start_time = jiffies;
210 status = ioread8(&regs->cr_sr);
211 while (status & M00018_SR_BITMAP_TIP_MSK) {
212 if (time_after(jiffies, start_time + adap->timeout))
213 return -ETIMEDOUT;
214 cond_resched();
215 status = ioread8(&regs->cr_sr);
216 }
217
218 /* Verify arbitration */
219 if (status & M00018_SR_BITMAP_AL_MSK) {
220 /* Arbitration lost! */
221 return -EIO;
222 }
223
224 /* Store data */
225 data[i] = ioread8(&regs->txr_rxr);
226 }
227 return 0;
228}
229
230/* Generate stop condition on i2c bus.
231 * The m00018 stop isn't doing the right thing (wrong timing).
232 * So instead send a start condition, 8 zeroes and a stop condition.
233 */
234static int cobalt_stop(struct cobalt_i2c_regs __iomem *regs,
235 struct i2c_adapter *adap)
236{
237 u8 data = 0;
238
239 return cobalt_tx_bytes(regs, adap, true, true, &data, 1);
240}
241
242static int cobalt_xfer(struct i2c_adapter *adap,
243 struct i2c_msg msgs[], int num)
244{
245 struct cobalt_i2c_data *data = adap->algo_data;
246 struct cobalt_i2c_regs __iomem *regs = data->regs;
247 struct i2c_msg *pmsg;
248 unsigned short flags;
249 int ret = 0;
250 int i, j;
251
252 for (i = 0; i < num; i++) {
253 int stop = (i == num - 1);
254
255 pmsg = &msgs[i];
256 flags = pmsg->flags;
257
258 if (!(pmsg->flags & I2C_M_NOSTART)) {
259 u8 addr = pmsg->addr << 1;
260
261 if (flags & I2C_M_RD)
262 addr |= 1;
263 if (flags & I2C_M_REV_DIR_ADDR)
264 addr ^= 1;
265 for (j = 0; j < adap->retries; j++) {
266 ret = cobalt_tx_bytes(regs, adap, true, false,
267 &addr, 1);
268 if (!ret)
269 break;
270 cobalt_stop(regs, adap);
271 }
272 if (ret < 0)
273 return ret;
274 ret = 0;
275 }
276 if (pmsg->flags & I2C_M_RD) {
277 /* read bytes into buffer */
278 ret = cobalt_rx_bytes(regs, adap, false, stop,
279 pmsg->buf, pmsg->len);
280 if (ret < 0)
281 goto bailout;
282 } else {
283 /* write bytes from buffer */
284 ret = cobalt_tx_bytes(regs, adap, false, stop,
285 pmsg->buf, pmsg->len);
286 if (ret < 0)
287 goto bailout;
288 }
289 }
290 ret = i;
291
292bailout:
293 if (ret < 0)
294 cobalt_stop(regs, adap);
295 return ret;
296}
297
298static u32 cobalt_func(struct i2c_adapter *adap)
299{
300 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
301}
302
303/* template for i2c-bit-algo */
304static struct i2c_adapter cobalt_i2c_adap_template = {
305 .name = "cobalt i2c driver",
306 .algo = NULL, /* set by i2c-algo-bit */
307 .algo_data = NULL, /* filled from template */
308 .owner = THIS_MODULE,
309};
310
311static const struct i2c_algorithm cobalt_algo = {
312 .master_xfer = cobalt_xfer,
313 .functionality = cobalt_func,
314};
315
316/* init + register i2c algo-bit adapter */
317int cobalt_i2c_init(struct cobalt *cobalt)
318{
319 int i, err;
320 int status;
321 int prescale;
322 unsigned long start_time;
323
324 cobalt_dbg(1, "i2c init\n");
325
326 /* Define I2C clock prescaler */
327 prescale = ((ALT_CPU_FREQ) / (5 * I2C_FREQUENCY)) - 1;
328
329 for (i = 0; i < COBALT_NUM_ADAPTERS; i++) {
330 struct cobalt_i2c_regs __iomem *regs =
331 cobalt_i2c_regs(cobalt, i);
332 struct i2c_adapter *adap = &cobalt->i2c_adap[i];
333
334 /* Disable I2C */
335 iowrite8(M00018_CTR_BITMAP_EN_MSK, &regs->cr_sr);
336 iowrite8(0, &regs->ctr);
337 iowrite8(0, &regs->cr_sr);
338
339 start_time = jiffies;
340 do {
341 if (time_after(jiffies, start_time + HZ)) {
342 if (cobalt_ignore_err) {
343 adap->dev.parent = NULL;
344 return 0;
345 }
346 return -ETIMEDOUT;
347 }
348 status = ioread8(&regs->cr_sr);
349 } while (status & M00018_SR_BITMAP_TIP_MSK);
350
351 /* Disable I2C */
352 iowrite8(0, &regs->ctr);
353 iowrite8(0, &regs->cr_sr);
354
355 /* Calculate i2c prescaler */
356 iowrite8(prescale & 0xff, &regs->prerlo);
357 iowrite8((prescale >> 8) & 0xff, &regs->prerhi);
358 /* Enable I2C, interrupts disabled */
359 iowrite8(M00018_CTR_BITMAP_EN_MSK, &regs->ctr);
360 /* Setup algorithm for adapter */
361 cobalt->i2c_data[i].cobalt = cobalt;
362 cobalt->i2c_data[i].regs = regs;
363 *adap = cobalt_i2c_adap_template;
364 adap->algo = &cobalt_algo;
365 adap->algo_data = &cobalt->i2c_data[i];
366 adap->retries = 3;
367 sprintf(adap->name + strlen(adap->name),
368 " #%d-%d", cobalt->instance, i);
369 i2c_set_adapdata(adap, &cobalt->v4l2_dev);
370 adap->dev.parent = &cobalt->pci_dev->dev;
371 err = i2c_add_adapter(adap);
372 if (err) {
373 if (cobalt_ignore_err) {
374 adap->dev.parent = NULL;
375 return 0;
376 }
377 while (i--)
378 i2c_del_adapter(&cobalt->i2c_adap[i]);
379 return err;
380 }
381 cobalt_info("registered bus %s\n", adap->name);
382 }
383 return 0;
384}
385
386void cobalt_i2c_exit(struct cobalt *cobalt)
387{
388 int i;
389
390 cobalt_dbg(1, "i2c exit\n");
391
392 for (i = 0; i < COBALT_NUM_ADAPTERS; i++) {
393 cobalt_err("unregistered bus %s\n", cobalt->i2c_adap[i].name);
394 i2c_del_adapter(&cobalt->i2c_adap[i]);
395 }
396}
diff --git a/drivers/media/pci/cobalt/cobalt-i2c.h b/drivers/media/pci/cobalt/cobalt-i2c.h
new file mode 100644
index 000000000000..a4c1cfaacf95
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-i2c.h
@@ -0,0 +1,25 @@
1/*
2 * cobalt I2C functions
3 *
4 * Derived from cx18-i2c.h
5 *
6 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
7 * All rights reserved.
8 *
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23/* init + register i2c algo-bit adapter */
24int cobalt_i2c_init(struct cobalt *cobalt);
25void cobalt_i2c_exit(struct cobalt *cobalt);
diff --git a/drivers/media/pci/cobalt/cobalt-irq.c b/drivers/media/pci/cobalt/cobalt-irq.c
new file mode 100644
index 000000000000..dd4bff9cf339
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-irq.c
@@ -0,0 +1,258 @@
1/*
2 * cobalt interrupt handling
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#include <media/adv7604.h>
22
23#include "cobalt-driver.h"
24#include "cobalt-irq.h"
25#include "cobalt-omnitek.h"
26
27static void cobalt_dma_stream_queue_handler(struct cobalt_stream *s)
28{
29 struct cobalt *cobalt = s->cobalt;
30 int rx = s->video_channel;
31 struct m00473_freewheel_regmap __iomem *fw =
32 COBALT_CVI_FREEWHEEL(s->cobalt, rx);
33 struct m00233_video_measure_regmap __iomem *vmr =
34 COBALT_CVI_VMR(s->cobalt, rx);
35 struct m00389_cvi_regmap __iomem *cvi =
36 COBALT_CVI(s->cobalt, rx);
37 struct m00479_clk_loss_detector_regmap __iomem *clkloss =
38 COBALT_CVI_CLK_LOSS(s->cobalt, rx);
39 struct cobalt_buffer *cb;
40 bool skip = false;
41
42 spin_lock(&s->irqlock);
43
44 if (list_empty(&s->bufs)) {
45 pr_err("no buffers!\n");
46 spin_unlock(&s->irqlock);
47 return;
48 }
49
50 /* Give the fresh filled up buffer to the user.
51 * Note that the interrupt is only sent if the DMA can continue
52 * with a new buffer, so it is always safe to return this buffer
53 * to userspace. */
54 cb = list_first_entry(&s->bufs, struct cobalt_buffer, list);
55 list_del(&cb->list);
56 spin_unlock(&s->irqlock);
57
58 if (s->is_audio || s->is_output)
59 goto done;
60
61 if (s->unstable_frame) {
62 uint32_t stat = ioread32(&vmr->irq_status);
63
64 iowrite32(stat, &vmr->irq_status);
65 if (!(ioread32(&vmr->status) &
66 M00233_STATUS_BITMAP_INIT_DONE_MSK)) {
67 cobalt_dbg(1, "!init_done\n");
68 if (s->enable_freewheel)
69 goto restart_fw;
70 goto done;
71 }
72
73 if (ioread32(&clkloss->status) &
74 M00479_STATUS_BITMAP_CLOCK_MISSING_MSK) {
75 iowrite32(0, &clkloss->ctrl);
76 iowrite32(M00479_CTRL_BITMAP_ENABLE_MSK, &clkloss->ctrl);
77 cobalt_dbg(1, "no clock\n");
78 if (s->enable_freewheel)
79 goto restart_fw;
80 goto done;
81 }
82 if ((stat & (M00233_IRQ_STATUS_BITMAP_VACTIVE_AREA_MSK |
83 M00233_IRQ_STATUS_BITMAP_HACTIVE_AREA_MSK)) ||
84 ioread32(&vmr->vactive_area) != s->timings.bt.height ||
85 ioread32(&vmr->hactive_area) != s->timings.bt.width) {
86 cobalt_dbg(1, "unstable\n");
87 if (s->enable_freewheel)
88 goto restart_fw;
89 goto done;
90 }
91 if (!s->enable_cvi) {
92 s->enable_cvi = true;
93 iowrite32(M00389_CONTROL_BITMAP_ENABLE_MSK, &cvi->control);
94 goto done;
95 }
96 if (!(ioread32(&cvi->status) & M00389_STATUS_BITMAP_LOCK_MSK)) {
97 cobalt_dbg(1, "cvi no lock\n");
98 if (s->enable_freewheel)
99 goto restart_fw;
100 goto done;
101 }
102 if (!s->enable_freewheel) {
103 cobalt_dbg(1, "stable\n");
104 s->enable_freewheel = true;
105 iowrite32(0, &fw->ctrl);
106 goto done;
107 }
108 cobalt_dbg(1, "enabled fw\n");
109 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK |
110 M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_MSK,
111 &vmr->control);
112 iowrite32(M00473_CTRL_BITMAP_ENABLE_MSK, &fw->ctrl);
113 s->enable_freewheel = false;
114 s->unstable_frame = false;
115 s->skip_first_frames = 2;
116 skip = true;
117 goto done;
118 }
119 if (ioread32(&fw->status) & M00473_STATUS_BITMAP_FREEWHEEL_MODE_MSK) {
120restart_fw:
121 cobalt_dbg(1, "lost lock\n");
122 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK,
123 &vmr->control);
124 iowrite32(M00473_CTRL_BITMAP_ENABLE_MSK |
125 M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK,
126 &fw->ctrl);
127 iowrite32(0, &cvi->control);
128 s->unstable_frame = true;
129 s->enable_freewheel = false;
130 s->enable_cvi = false;
131 }
132done:
133 if (s->skip_first_frames) {
134 skip = true;
135 s->skip_first_frames--;
136 }
137 v4l2_get_timestamp(&cb->vb.v4l2_buf.timestamp);
138 /* TODO: the sequence number should be read from the FPGA so we
139 also know about dropped frames. */
140 cb->vb.v4l2_buf.sequence = s->sequence++;
141 vb2_buffer_done(&cb->vb, (skip || s->unstable_frame) ?
142 VB2_BUF_STATE_QUEUED : VB2_BUF_STATE_DONE);
143}
144
145irqreturn_t cobalt_irq_handler(int irq, void *dev_id)
146{
147 struct cobalt *cobalt = (struct cobalt *)dev_id;
148 u32 dma_interrupt =
149 cobalt_read_bar0(cobalt, DMA_INTERRUPT_STATUS_REG) & 0xffff;
150 u32 mask = cobalt_read_bar1(cobalt, COBALT_SYS_STAT_MASK);
151 u32 edge = cobalt_read_bar1(cobalt, COBALT_SYS_STAT_EDGE);
152 int i;
153
154 /* Clear DMA interrupt */
155 cobalt_write_bar0(cobalt, DMA_INTERRUPT_STATUS_REG, dma_interrupt);
156 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_MASK, mask & ~edge);
157 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_EDGE, edge);
158
159 for (i = 0; i < COBALT_NUM_STREAMS; i++) {
160 struct cobalt_stream *s = &cobalt->streams[i];
161 unsigned dma_fifo_mask = s->dma_fifo_mask;
162
163 if (dma_interrupt & (1 << s->dma_channel)) {
164 cobalt->irq_dma[i]++;
165 /* Give fresh buffer to user and chain newly
166 * queued buffers */
167 cobalt_dma_stream_queue_handler(s);
168 if (!s->is_audio) {
169 edge &= ~dma_fifo_mask;
170 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_MASK,
171 mask & ~edge);
172 }
173 }
174 if (s->is_audio)
175 continue;
176 if (edge & s->adv_irq_mask)
177 set_bit(COBALT_STREAM_FL_ADV_IRQ, &s->flags);
178 if ((edge & mask & dma_fifo_mask) && vb2_is_streaming(&s->q)) {
179 cobalt_info("full rx FIFO %d\n", i);
180 cobalt->irq_full_fifo++;
181 }
182 }
183
184 queue_work(cobalt->irq_work_queues, &cobalt->irq_work_queue);
185
186 if (edge & mask & (COBALT_SYSSTAT_VI0_INT1_MSK |
187 COBALT_SYSSTAT_VI1_INT1_MSK |
188 COBALT_SYSSTAT_VI2_INT1_MSK |
189 COBALT_SYSSTAT_VI3_INT1_MSK |
190 COBALT_SYSSTAT_VIHSMA_INT1_MSK |
191 COBALT_SYSSTAT_VOHSMA_INT1_MSK))
192 cobalt->irq_adv1++;
193 if (edge & mask & (COBALT_SYSSTAT_VI0_INT2_MSK |
194 COBALT_SYSSTAT_VI1_INT2_MSK |
195 COBALT_SYSSTAT_VI2_INT2_MSK |
196 COBALT_SYSSTAT_VI3_INT2_MSK |
197 COBALT_SYSSTAT_VIHSMA_INT2_MSK))
198 cobalt->irq_adv2++;
199 if (edge & mask & COBALT_SYSSTAT_VOHSMA_INT1_MSK)
200 cobalt->irq_advout++;
201 if (dma_interrupt)
202 cobalt->irq_dma_tot++;
203 if (!(edge & mask) && !dma_interrupt)
204 cobalt->irq_none++;
205 dma_interrupt = cobalt_read_bar0(cobalt, DMA_INTERRUPT_STATUS_REG);
206
207 return IRQ_HANDLED;
208}
209
210void cobalt_irq_work_handler(struct work_struct *work)
211{
212 struct cobalt *cobalt =
213 container_of(work, struct cobalt, irq_work_queue);
214 int i;
215
216 for (i = 0; i < COBALT_NUM_NODES; i++) {
217 struct cobalt_stream *s = &cobalt->streams[i];
218
219 if (test_and_clear_bit(COBALT_STREAM_FL_ADV_IRQ, &s->flags)) {
220 u32 mask;
221
222 v4l2_subdev_call(cobalt->streams[i].sd, core,
223 interrupt_service_routine, 0, NULL);
224 mask = cobalt_read_bar1(cobalt, COBALT_SYS_STAT_MASK);
225 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_MASK,
226 mask | s->adv_irq_mask);
227 }
228 }
229}
230
231void cobalt_irq_log_status(struct cobalt *cobalt)
232{
233 u32 mask;
234 int i;
235
236 cobalt_info("irq: adv1=%u adv2=%u advout=%u none=%u full=%u\n",
237 cobalt->irq_adv1, cobalt->irq_adv2, cobalt->irq_advout,
238 cobalt->irq_none, cobalt->irq_full_fifo);
239 cobalt_info("irq: dma_tot=%u (", cobalt->irq_dma_tot);
240 for (i = 0; i < COBALT_NUM_STREAMS; i++)
241 pr_cont("%s%u", i ? "/" : "", cobalt->irq_dma[i]);
242 pr_cont(")\n");
243 cobalt->irq_dma_tot = cobalt->irq_adv1 = cobalt->irq_adv2 = 0;
244 cobalt->irq_advout = cobalt->irq_none = cobalt->irq_full_fifo = 0;
245 memset(cobalt->irq_dma, 0, sizeof(cobalt->irq_dma));
246
247 mask = cobalt_read_bar1(cobalt, COBALT_SYS_STAT_MASK);
248 cobalt_write_bar1(cobalt, COBALT_SYS_STAT_MASK,
249 mask |
250 COBALT_SYSSTAT_VI0_LOST_DATA_MSK |
251 COBALT_SYSSTAT_VI1_LOST_DATA_MSK |
252 COBALT_SYSSTAT_VI2_LOST_DATA_MSK |
253 COBALT_SYSSTAT_VI3_LOST_DATA_MSK |
254 COBALT_SYSSTAT_VIHSMA_LOST_DATA_MSK |
255 COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK |
256 COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK |
257 COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK);
258}
diff --git a/drivers/media/pci/cobalt/cobalt-irq.h b/drivers/media/pci/cobalt/cobalt-irq.h
new file mode 100644
index 000000000000..5119484a24d9
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-irq.h
@@ -0,0 +1,25 @@
1/*
2 * cobalt interrupt handling
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#include <linux/interrupt.h>
22
23irqreturn_t cobalt_irq_handler(int irq, void *dev_id);
24void cobalt_irq_work_handler(struct work_struct *work);
25void cobalt_irq_log_status(struct cobalt *cobalt);
diff --git a/drivers/media/pci/cobalt/cobalt-omnitek.c b/drivers/media/pci/cobalt/cobalt-omnitek.c
new file mode 100644
index 000000000000..a28a8482c1d4
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-omnitek.c
@@ -0,0 +1,341 @@
1/*
2 * Omnitek Scatter-Gather DMA Controller
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#include <linux/string.h>
22#include <linux/io.h>
23#include <linux/pci_regs.h>
24#include <linux/spinlock.h>
25
26#include "cobalt-driver.h"
27#include "cobalt-omnitek.h"
28
29/* descriptor */
30#define END_OF_CHAIN (1 << 1)
31#define INTERRUPT_ENABLE (1 << 2)
32#define WRITE_TO_PCI (1 << 3)
33#define READ_FROM_PCI (0 << 3)
34#define DESCRIPTOR_FLAG_MSK (END_OF_CHAIN | INTERRUPT_ENABLE | WRITE_TO_PCI)
35#define NEXT_ADRS_MSK 0xffffffe0
36
37/* control/status register */
38#define ENABLE (1 << 0)
39#define START (1 << 1)
40#define ABORT (1 << 2)
41#define DONE (1 << 4)
42#define SG_INTERRUPT (1 << 5)
43#define EVENT_INTERRUPT (1 << 6)
44#define SCATTER_GATHER_MODE (1 << 8)
45#define DISABLE_VIDEO_RESYNC (1 << 9)
46#define EVENT_INTERRUPT_ENABLE (1 << 10)
47#define DIRECTIONAL_MSK (3 << 16)
48#define INPUT_ONLY (0 << 16)
49#define OUTPUT_ONLY (1 << 16)
50#define BIDIRECTIONAL (2 << 16)
51#define DMA_TYPE_MEMORY (0 << 18)
52#define DMA_TYPE_FIFO (1 << 18)
53
54#define BASE (cobalt->bar0)
55#define CAPABILITY_HEADER (BASE)
56#define CAPABILITY_REGISTER (BASE + 0x04)
57#define PCI_64BIT (1 << 8)
58#define LOCAL_64BIT (1 << 9)
59#define INTERRUPT_STATUS (BASE + 0x08)
60#define PCI(c) (BASE + 0x40 + ((c) * 0x40))
61#define SIZE(c) (BASE + 0x58 + ((c) * 0x40))
62#define DESCRIPTOR(c) (BASE + 0x50 + ((c) * 0x40))
63#define CS_REG(c) (BASE + 0x60 + ((c) * 0x40))
64#define BYTES_TRANSFERRED(c) (BASE + 0x64 + ((c) * 0x40))
65
66
67static char *get_dma_direction(u32 status)
68{
69 switch (status & DIRECTIONAL_MSK) {
70 case INPUT_ONLY: return "Input";
71 case OUTPUT_ONLY: return "Output";
72 case BIDIRECTIONAL: return "Bidirectional";
73 }
74 return "";
75}
76
77static void show_dma_capability(struct cobalt *cobalt)
78{
79 u32 header = ioread32(CAPABILITY_HEADER);
80 u32 capa = ioread32(CAPABILITY_REGISTER);
81 u32 i;
82
83 cobalt_info("Omnitek DMA capability: ID 0x%02x Version 0x%02x Next 0x%x Size 0x%x\n",
84 header & 0xff, (header >> 8) & 0xff,
85 (header >> 16) & 0xffff, (capa >> 24) & 0xff);
86
87 switch ((capa >> 8) & 0x3) {
88 case 0:
89 cobalt_info("Omnitek DMA: 32 bits PCIe and Local\n");
90 break;
91 case 1:
92 cobalt_info("Omnitek DMA: 64 bits PCIe, 32 bits Local\n");
93 break;
94 case 3:
95 cobalt_info("Omnitek DMA: 64 bits PCIe and Local\n");
96 break;
97 }
98
99 for (i = 0; i < (capa & 0xf); i++) {
100 u32 status = ioread32(CS_REG(i));
101
102 cobalt_info("Omnitek DMA channel #%d: %s %s\n", i,
103 status & DMA_TYPE_FIFO ? "FIFO" : "MEMORY",
104 get_dma_direction(status));
105 }
106}
107
108void omni_sg_dma_start(struct cobalt_stream *s, struct sg_dma_desc_info *desc)
109{
110 struct cobalt *cobalt = s->cobalt;
111
112 iowrite32((u32)((u64)desc->bus >> 32), DESCRIPTOR(s->dma_channel) + 4);
113 iowrite32((u32)desc->bus & NEXT_ADRS_MSK, DESCRIPTOR(s->dma_channel));
114 iowrite32(ENABLE | SCATTER_GATHER_MODE | START, CS_REG(s->dma_channel));
115}
116
117bool is_dma_done(struct cobalt_stream *s)
118{
119 struct cobalt *cobalt = s->cobalt;
120
121 if (ioread32(CS_REG(s->dma_channel)) & DONE)
122 return true;
123
124 return false;
125}
126
127void omni_sg_dma_abort_channel(struct cobalt_stream *s)
128{
129 struct cobalt *cobalt = s->cobalt;
130
131 if (is_dma_done(s) == false)
132 iowrite32(ABORT, CS_REG(s->dma_channel));
133}
134
135int omni_sg_dma_init(struct cobalt *cobalt)
136{
137 u32 capa = ioread32(CAPABILITY_REGISTER);
138 int i;
139
140 cobalt->first_fifo_channel = 0;
141 cobalt->dma_channels = capa & 0xf;
142 if (capa & PCI_64BIT)
143 cobalt->pci_32_bit = false;
144 else
145 cobalt->pci_32_bit = true;
146
147 for (i = 0; i < cobalt->dma_channels; i++) {
148 u32 status = ioread32(CS_REG(i));
149 u32 ctrl = ioread32(CS_REG(i));
150
151 if (!(ctrl & DONE))
152 iowrite32(ABORT, CS_REG(i));
153
154 if (!(status & DMA_TYPE_FIFO))
155 cobalt->first_fifo_channel++;
156 }
157 show_dma_capability(cobalt);
158 return 0;
159}
160
161int descriptor_list_create(struct cobalt *cobalt,
162 struct scatterlist *scatter_list, bool to_pci, unsigned sglen,
163 unsigned size, unsigned width, unsigned stride,
164 struct sg_dma_desc_info *desc)
165{
166 struct sg_dma_descriptor *d = (struct sg_dma_descriptor *)desc->virt;
167 dma_addr_t next = desc->bus;
168 unsigned offset = 0;
169 unsigned copy_bytes = width;
170 unsigned copied = 0;
171 bool first = true;
172
173 /* Must be 4-byte aligned */
174 WARN_ON(sg_dma_address(scatter_list) & 3);
175 WARN_ON(size & 3);
176 WARN_ON(next & 3);
177 WARN_ON(stride & 3);
178 WARN_ON(stride < width);
179 if (width >= stride)
180 copy_bytes = stride = size;
181
182 while (size) {
183 dma_addr_t addr = sg_dma_address(scatter_list) + offset;
184 unsigned bytes;
185
186 if (addr == 0)
187 return -EFAULT;
188 if (cobalt->pci_32_bit) {
189 WARN_ON((u64)addr >> 32);
190 if ((u64)addr >> 32)
191 return -EFAULT;
192 }
193
194 /* PCIe address */
195 d->pci_l = addr & 0xffffffff;
196 /* If dma_addr_t is 32 bits, then addr >> 32 is actually the
197 equivalent of addr >> 0 in gcc. So must cast to u64. */
198 d->pci_h = (u64)addr >> 32;
199
200 /* Sync to start of streaming frame */
201 d->local = 0;
202 d->reserved0 = 0;
203
204 /* Transfer bytes */
205 bytes = min(sg_dma_len(scatter_list) - offset,
206 copy_bytes - copied);
207
208 if (first) {
209 if (to_pci)
210 d->local = 0x11111111;
211 first = false;
212 if (sglen == 1) {
213 /* Make sure there are always at least two
214 * descriptors */
215 d->bytes = (bytes / 2) & ~3;
216 d->reserved1 = 0;
217 size -= d->bytes;
218 copied += d->bytes;
219 offset += d->bytes;
220 addr += d->bytes;
221 next += sizeof(struct sg_dma_descriptor);
222 d->next_h = (u32)((u64)next >> 32);
223 d->next_l = (u32)next |
224 (to_pci ? WRITE_TO_PCI : 0);
225 bytes -= d->bytes;
226 d++;
227 /* PCIe address */
228 d->pci_l = addr & 0xffffffff;
229 /* If dma_addr_t is 32 bits, then addr >> 32
230 * is actually the equivalent of addr >> 0 in
231 * gcc. So must cast to u64. */
232 d->pci_h = (u64)addr >> 32;
233
234 /* Sync to start of streaming frame */
235 d->local = 0;
236 d->reserved0 = 0;
237 }
238 }
239
240 d->bytes = bytes;
241 d->reserved1 = 0;
242 size -= bytes;
243 copied += bytes;
244 offset += bytes;
245
246 if (copied == copy_bytes) {
247 while (copied < stride) {
248 bytes = min(sg_dma_len(scatter_list) - offset,
249 stride - copied);
250 copied += bytes;
251 offset += bytes;
252 size -= bytes;
253 if (sg_dma_len(scatter_list) == offset) {
254 offset = 0;
255 scatter_list = sg_next(scatter_list);
256 }
257 }
258 copied = 0;
259 } else {
260 offset = 0;
261 scatter_list = sg_next(scatter_list);
262 }
263
264 /* Next descriptor + control bits */
265 next += sizeof(struct sg_dma_descriptor);
266 if (size == 0) {
267 /* Loopback to the first descriptor */
268 d->next_h = (u32)((u64)desc->bus >> 32);
269 d->next_l = (u32)desc->bus |
270 (to_pci ? WRITE_TO_PCI : 0) | INTERRUPT_ENABLE;
271 if (!to_pci)
272 d->local = 0x22222222;
273 desc->last_desc_virt = d;
274 } else {
275 d->next_h = (u32)((u64)next >> 32);
276 d->next_l = (u32)next | (to_pci ? WRITE_TO_PCI : 0);
277 }
278 d++;
279 }
280 return 0;
281}
282
283void descriptor_list_chain(struct sg_dma_desc_info *this,
284 struct sg_dma_desc_info *next)
285{
286 struct sg_dma_descriptor *d = this->last_desc_virt;
287 u32 direction = d->next_l & WRITE_TO_PCI;
288
289 if (next == NULL) {
290 d->next_h = 0;
291 d->next_l = direction | INTERRUPT_ENABLE | END_OF_CHAIN;
292 } else {
293 d->next_h = (u32)((u64)next->bus >> 32);
294 d->next_l = (u32)next->bus | direction | INTERRUPT_ENABLE;
295 }
296}
297
298void *descriptor_list_allocate(struct sg_dma_desc_info *desc, size_t bytes)
299{
300 desc->size = bytes;
301 desc->virt = dma_alloc_coherent(desc->dev, bytes,
302 &desc->bus, GFP_KERNEL);
303 return desc->virt;
304}
305
306void descriptor_list_free(struct sg_dma_desc_info *desc)
307{
308 if (desc->virt)
309 dma_free_coherent(desc->dev, desc->size,
310 desc->virt, desc->bus);
311 desc->virt = NULL;
312}
313
314void descriptor_list_interrupt_enable(struct sg_dma_desc_info *desc)
315{
316 struct sg_dma_descriptor *d = desc->last_desc_virt;
317
318 d->next_l |= INTERRUPT_ENABLE;
319}
320
321void descriptor_list_interrupt_disable(struct sg_dma_desc_info *desc)
322{
323 struct sg_dma_descriptor *d = desc->last_desc_virt;
324
325 d->next_l &= ~INTERRUPT_ENABLE;
326}
327
328void descriptor_list_loopback(struct sg_dma_desc_info *desc)
329{
330 struct sg_dma_descriptor *d = desc->last_desc_virt;
331
332 d->next_h = (u32)((u64)desc->bus >> 32);
333 d->next_l = (u32)desc->bus | (d->next_l & DESCRIPTOR_FLAG_MSK);
334}
335
336void descriptor_list_end_of_chain(struct sg_dma_desc_info *desc)
337{
338 struct sg_dma_descriptor *d = desc->last_desc_virt;
339
340 d->next_l |= END_OF_CHAIN;
341}
diff --git a/drivers/media/pci/cobalt/cobalt-omnitek.h b/drivers/media/pci/cobalt/cobalt-omnitek.h
new file mode 100644
index 000000000000..e5c6d032c6f2
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-omnitek.h
@@ -0,0 +1,62 @@
1/*
2 * Omnitek Scatter-Gather DMA Controller
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#ifndef COBALT_OMNITEK_H
22#define COBALT_OMNITEK_H
23
24#include <linux/scatterlist.h>
25#include "cobalt-driver.h"
26
27struct sg_dma_descriptor {
28 u32 pci_l;
29 u32 pci_h;
30
31 u32 local;
32 u32 reserved0;
33
34 u32 next_l;
35 u32 next_h;
36
37 u32 bytes;
38 u32 reserved1;
39};
40
41int omni_sg_dma_init(struct cobalt *cobalt);
42void omni_sg_dma_abort_channel(struct cobalt_stream *s);
43void omni_sg_dma_start(struct cobalt_stream *s, struct sg_dma_desc_info *desc);
44bool is_dma_done(struct cobalt_stream *s);
45
46int descriptor_list_create(struct cobalt *cobalt,
47 struct scatterlist *scatter_list, bool to_pci, unsigned sglen,
48 unsigned size, unsigned width, unsigned stride,
49 struct sg_dma_desc_info *desc);
50
51void descriptor_list_chain(struct sg_dma_desc_info *this,
52 struct sg_dma_desc_info *next);
53void descriptor_list_loopback(struct sg_dma_desc_info *desc);
54void descriptor_list_end_of_chain(struct sg_dma_desc_info *desc);
55
56void *descriptor_list_allocate(struct sg_dma_desc_info *desc, size_t bytes);
57void descriptor_list_free(struct sg_dma_desc_info *desc);
58
59void descriptor_list_interrupt_enable(struct sg_dma_desc_info *desc);
60void descriptor_list_interrupt_disable(struct sg_dma_desc_info *desc);
61
62#endif
diff --git a/drivers/media/pci/cobalt/cobalt-v4l2.c b/drivers/media/pci/cobalt/cobalt-v4l2.c
new file mode 100644
index 000000000000..b40c2d141b58
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-v4l2.c
@@ -0,0 +1,1272 @@
1/*
2 * cobalt V4L2 API
3 *
4 * Derived from ivtv-ioctl.c and cx18-fileops.c
5 *
6 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
7 * All rights reserved.
8 *
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#include <linux/dma-mapping.h>
24#include <linux/delay.h>
25#include <linux/math64.h>
26#include <linux/pci.h>
27#include <linux/v4l2-dv-timings.h>
28
29#include <media/v4l2-ctrls.h>
30#include <media/v4l2-event.h>
31#include <media/adv7604.h>
32#include <media/adv7842.h>
33
34#include "cobalt-alsa.h"
35#include "cobalt-cpld.h"
36#include "cobalt-driver.h"
37#include "cobalt-v4l2.h"
38#include "cobalt-irq.h"
39#include "cobalt-omnitek.h"
40
41static const struct v4l2_dv_timings cea1080p60 = V4L2_DV_BT_CEA_1920X1080P60;
42
43/* vb2 DMA streaming ops */
44
45static int cobalt_queue_setup(struct vb2_queue *q,
46 const struct v4l2_format *fmt,
47 unsigned int *num_buffers, unsigned int *num_planes,
48 unsigned int sizes[], void *alloc_ctxs[])
49{
50 struct cobalt_stream *s = q->drv_priv;
51 unsigned size = s->stride * s->height;
52
53 if (*num_buffers < 3)
54 *num_buffers = 3;
55 if (*num_buffers > NR_BUFS)
56 *num_buffers = NR_BUFS;
57 *num_planes = 1;
58 if (fmt) {
59 if (fmt->fmt.pix.sizeimage < size)
60 return -EINVAL;
61 size = fmt->fmt.pix.sizeimage;
62 }
63 sizes[0] = size;
64 alloc_ctxs[0] = s->cobalt->alloc_ctx;
65 return 0;
66}
67
68static int cobalt_buf_init(struct vb2_buffer *vb)
69{
70 struct cobalt_stream *s = vb->vb2_queue->drv_priv;
71 struct cobalt *cobalt = s->cobalt;
72 const size_t max_pages_per_line =
73 (COBALT_MAX_WIDTH * COBALT_MAX_BPP) / PAGE_SIZE + 2;
74 const size_t bytes =
75 COBALT_MAX_HEIGHT * max_pages_per_line * 0x20;
76 const size_t audio_bytes = ((1920 * 4) / PAGE_SIZE + 1) * 0x20;
77 struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->v4l2_buf.index];
78 struct sg_table *sg_desc = vb2_dma_sg_plane_desc(vb, 0);
79 unsigned size;
80 int ret;
81
82 size = s->stride * s->height;
83 if (vb2_plane_size(vb, 0) < size) {
84 cobalt_info("data will not fit into plane (%lu < %u)\n",
85 vb2_plane_size(vb, 0), size);
86 return -EINVAL;
87 }
88
89 if (desc->virt == NULL) {
90 desc->dev = &cobalt->pci_dev->dev;
91 descriptor_list_allocate(desc,
92 s->is_audio ? audio_bytes : bytes);
93 if (desc->virt == NULL)
94 return -ENOMEM;
95 }
96 ret = descriptor_list_create(cobalt, sg_desc->sgl,
97 !s->is_output, sg_desc->nents, size,
98 s->width * s->bpp, s->stride, desc);
99 if (ret)
100 descriptor_list_free(desc);
101 return ret;
102}
103
104static void cobalt_buf_cleanup(struct vb2_buffer *vb)
105{
106 struct cobalt_stream *s = vb->vb2_queue->drv_priv;
107 struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->v4l2_buf.index];
108
109 descriptor_list_free(desc);
110}
111
112static int cobalt_buf_prepare(struct vb2_buffer *vb)
113{
114 struct cobalt_stream *s = vb->vb2_queue->drv_priv;
115
116 vb2_set_plane_payload(vb, 0, s->stride * s->height);
117 vb->v4l2_buf.field = V4L2_FIELD_NONE;
118 return 0;
119}
120
121static void chain_all_buffers(struct cobalt_stream *s)
122{
123 struct sg_dma_desc_info *desc[NR_BUFS];
124 struct cobalt_buffer *cb;
125 struct list_head *p;
126 int i = 0;
127
128 list_for_each(p, &s->bufs) {
129 cb = list_entry(p, struct cobalt_buffer, list);
130 desc[i] = &s->dma_desc_info[cb->vb.v4l2_buf.index];
131 if (i > 0)
132 descriptor_list_chain(desc[i-1], desc[i]);
133 i++;
134 }
135}
136
137static void cobalt_buf_queue(struct vb2_buffer *vb)
138{
139 struct vb2_queue *q = vb->vb2_queue;
140 struct cobalt_stream *s = q->drv_priv;
141 struct cobalt_buffer *cb = to_cobalt_buffer(vb);
142 struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->v4l2_buf.index];
143 unsigned long flags;
144
145 /* Prepare new buffer */
146 descriptor_list_loopback(desc);
147 descriptor_list_interrupt_disable(desc);
148
149 spin_lock_irqsave(&s->irqlock, flags);
150 list_add_tail(&cb->list, &s->bufs);
151 chain_all_buffers(s);
152 spin_unlock_irqrestore(&s->irqlock, flags);
153}
154
155static void cobalt_enable_output(struct cobalt_stream *s)
156{
157 struct cobalt *cobalt = s->cobalt;
158 struct v4l2_bt_timings *bt = &s->timings.bt;
159 struct m00514_syncgen_flow_evcnt_regmap __iomem *vo =
160 COBALT_TX_BASE(cobalt);
161 unsigned fmt = s->pixfmt != V4L2_PIX_FMT_BGR32 ?
162 M00514_CONTROL_BITMAP_FORMAT_16_BPP_MSK : 0;
163 struct v4l2_subdev_format sd_fmt = {
164 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
165 };
166
167 if (!cobalt_cpld_set_freq(cobalt, bt->pixelclock)) {
168 cobalt_err("pixelclock out of range\n");
169 return;
170 }
171
172 sd_fmt.format.colorspace = s->colorspace;
173 sd_fmt.format.xfer_func = s->xfer_func;
174 sd_fmt.format.ycbcr_enc = s->ycbcr_enc;
175 sd_fmt.format.quantization = s->quantization;
176 sd_fmt.format.width = bt->width;
177 sd_fmt.format.height = bt->height;
178
179 /* Set up FDMA packer */
180 switch (s->pixfmt) {
181 case V4L2_PIX_FMT_YUYV:
182 sd_fmt.format.code = MEDIA_BUS_FMT_UYVY8_1X16;
183 break;
184 case V4L2_PIX_FMT_BGR32:
185 sd_fmt.format.code = MEDIA_BUS_FMT_RGB888_1X24;
186 break;
187 }
188 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, &sd_fmt);
189
190 iowrite32(0, &vo->control);
191 /* 1080p60 */
192 iowrite32(bt->hsync, &vo->sync_generator_h_sync_length);
193 iowrite32(bt->hbackporch, &vo->sync_generator_h_backporch_length);
194 iowrite32(bt->width, &vo->sync_generator_h_active_length);
195 iowrite32(bt->hfrontporch, &vo->sync_generator_h_frontporch_length);
196 iowrite32(bt->vsync, &vo->sync_generator_v_sync_length);
197 iowrite32(bt->vbackporch, &vo->sync_generator_v_backporch_length);
198 iowrite32(bt->height, &vo->sync_generator_v_active_length);
199 iowrite32(bt->vfrontporch, &vo->sync_generator_v_frontporch_length);
200 iowrite32(0x9900c1, &vo->error_color);
201
202 iowrite32(M00514_CONTROL_BITMAP_SYNC_GENERATOR_LOAD_PARAM_MSK | fmt,
203 &vo->control);
204 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK | fmt, &vo->control);
205 iowrite32(M00514_CONTROL_BITMAP_SYNC_GENERATOR_ENABLE_MSK |
206 M00514_CONTROL_BITMAP_FLOW_CTRL_OUTPUT_ENABLE_MSK |
207 fmt, &vo->control);
208}
209
210static void cobalt_enable_input(struct cobalt_stream *s)
211{
212 struct cobalt *cobalt = s->cobalt;
213 int ch = (int)s->video_channel;
214 struct m00235_fdma_packer_regmap __iomem *packer;
215 struct v4l2_subdev_format sd_fmt_yuyv = {
216 .pad = s->pad_source,
217 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
218 .format.code = MEDIA_BUS_FMT_YUYV8_1X16,
219 };
220 struct v4l2_subdev_format sd_fmt_rgb = {
221 .pad = s->pad_source,
222 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
223 .format.code = MEDIA_BUS_FMT_RGB888_1X24,
224 };
225
226 cobalt_dbg(1, "video_channel %d (%s, %s)\n",
227 s->video_channel,
228 s->input == 0 ? "hdmi" : "generator",
229 "YUYV");
230
231 packer = COBALT_CVI_PACKER(cobalt, ch);
232
233 /* Set up FDMA packer */
234 switch (s->pixfmt) {
235 case V4L2_PIX_FMT_YUYV:
236 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK |
237 (1 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST),
238 &packer->control);
239 v4l2_subdev_call(s->sd, pad, set_fmt, NULL,
240 &sd_fmt_yuyv);
241 break;
242 case V4L2_PIX_FMT_RGB24:
243 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK |
244 (2 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST),
245 &packer->control);
246 v4l2_subdev_call(s->sd, pad, set_fmt, NULL,
247 &sd_fmt_rgb);
248 break;
249 case V4L2_PIX_FMT_BGR32:
250 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK |
251 M00235_CONTROL_BITMAP_ENDIAN_FORMAT_MSK |
252 (3 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST),
253 &packer->control);
254 v4l2_subdev_call(s->sd, pad, set_fmt, NULL,
255 &sd_fmt_rgb);
256 break;
257 }
258}
259
260static void cobalt_dma_start_streaming(struct cobalt_stream *s)
261{
262 struct cobalt *cobalt = s->cobalt;
263 int rx = s->video_channel;
264 struct m00460_evcnt_regmap __iomem *evcnt =
265 COBALT_CVI_EVCNT(cobalt, rx);
266 struct cobalt_buffer *cb;
267 unsigned long flags;
268
269 spin_lock_irqsave(&s->irqlock, flags);
270 if (!s->is_output) {
271 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK, &evcnt->control);
272 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK, &evcnt->control);
273 } else {
274 struct m00514_syncgen_flow_evcnt_regmap __iomem *vo =
275 COBALT_TX_BASE(cobalt);
276 u32 ctrl = ioread32(&vo->control);
277
278 ctrl &= ~(M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK |
279 M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK);
280 iowrite32(ctrl | M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK,
281 &vo->control);
282 iowrite32(ctrl | M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK,
283 &vo->control);
284 }
285 cb = list_first_entry(&s->bufs, struct cobalt_buffer, list);
286 omni_sg_dma_start(s, &s->dma_desc_info[cb->vb.v4l2_buf.index]);
287 spin_unlock_irqrestore(&s->irqlock, flags);
288}
289
290static int cobalt_start_streaming(struct vb2_queue *q, unsigned int count)
291{
292 struct cobalt_stream *s = q->drv_priv;
293 struct cobalt *cobalt = s->cobalt;
294 struct m00233_video_measure_regmap __iomem *vmr;
295 struct m00473_freewheel_regmap __iomem *fw;
296 struct m00479_clk_loss_detector_regmap __iomem *clkloss;
297 int rx = s->video_channel;
298 struct m00389_cvi_regmap __iomem *cvi = COBALT_CVI(cobalt, rx);
299 struct m00460_evcnt_regmap __iomem *evcnt = COBALT_CVI_EVCNT(cobalt, rx);
300 struct v4l2_bt_timings *bt = &s->timings.bt;
301 u64 tot_size;
302 u32 clk_freq;
303
304 if (s->is_audio)
305 goto done;
306 if (s->is_output) {
307 s->unstable_frame = false;
308 cobalt_enable_output(s);
309 goto done;
310 }
311
312 cobalt_enable_input(s);
313
314 fw = COBALT_CVI_FREEWHEEL(cobalt, rx);
315 vmr = COBALT_CVI_VMR(cobalt, rx);
316 clkloss = COBALT_CVI_CLK_LOSS(cobalt, rx);
317
318 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK, &evcnt->control);
319 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK, &evcnt->control);
320 iowrite32(bt->width, &cvi->frame_width);
321 iowrite32(bt->height, &cvi->frame_height);
322 tot_size = V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt);
323 iowrite32(div_u64((u64)V4L2_DV_BT_FRAME_WIDTH(bt) * COBALT_CLK * 4,
324 bt->pixelclock), &vmr->hsync_timeout_val);
325 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK, &vmr->control);
326 clk_freq = ioread32(&fw->clk_freq);
327 iowrite32(clk_freq / 1000000, &clkloss->ref_clk_cnt_val);
328 /* The lower bound for the clock frequency is 0.5% lower as is
329 * allowed by the spec */
330 iowrite32(div_u64(bt->pixelclock * 995, 1000000000),
331 &clkloss->test_clk_cnt_val);
332 /* will be enabled after the first frame has been received */
333 iowrite32(bt->width * bt->height, &fw->active_length);
334 iowrite32(div_u64((u64)clk_freq * tot_size, bt->pixelclock),
335 &fw->total_length);
336 iowrite32(M00233_IRQ_TRIGGERS_BITMAP_VACTIVE_AREA_MSK |
337 M00233_IRQ_TRIGGERS_BITMAP_HACTIVE_AREA_MSK,
338 &vmr->irq_triggers);
339 iowrite32(0, &cvi->control);
340 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK, &vmr->control);
341
342 iowrite32(0xff, &fw->output_color);
343 iowrite32(M00479_CTRL_BITMAP_ENABLE_MSK, &clkloss->ctrl);
344 iowrite32(M00473_CTRL_BITMAP_ENABLE_MSK |
345 M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK, &fw->ctrl);
346 s->unstable_frame = true;
347 s->enable_freewheel = false;
348 s->enable_cvi = false;
349 s->skip_first_frames = 0;
350
351done:
352 s->sequence = 0;
353 cobalt_dma_start_streaming(s);
354 return 0;
355}
356
357static void cobalt_dma_stop_streaming(struct cobalt_stream *s)
358{
359 struct cobalt *cobalt = s->cobalt;
360 struct sg_dma_desc_info *desc;
361 struct cobalt_buffer *cb;
362 struct list_head *p;
363 unsigned long flags;
364 int timeout_msec = 100;
365 int rx = s->video_channel;
366 struct m00460_evcnt_regmap __iomem *evcnt =
367 COBALT_CVI_EVCNT(cobalt, rx);
368
369 if (!s->is_output) {
370 iowrite32(0, &evcnt->control);
371 } else if (!s->is_audio) {
372 struct m00514_syncgen_flow_evcnt_regmap __iomem *vo =
373 COBALT_TX_BASE(cobalt);
374
375 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK, &vo->control);
376 iowrite32(0, &vo->control);
377 }
378
379 /* Try to stop the DMA engine gracefully */
380 spin_lock_irqsave(&s->irqlock, flags);
381 list_for_each(p, &s->bufs) {
382 cb = list_entry(p, struct cobalt_buffer, list);
383 desc = &s->dma_desc_info[cb->vb.v4l2_buf.index];
384 /* Stop DMA after this descriptor chain */
385 descriptor_list_end_of_chain(desc);
386 }
387 spin_unlock_irqrestore(&s->irqlock, flags);
388
389 /* Wait 100 milisecond for DMA to finish, abort on timeout. */
390 if (!wait_event_timeout(s->q.done_wq, is_dma_done(s),
391 msecs_to_jiffies(timeout_msec))) {
392 omni_sg_dma_abort_channel(s);
393 pr_warn("aborted\n");
394 }
395 cobalt_write_bar0(cobalt, DMA_INTERRUPT_STATUS_REG,
396 1 << s->dma_channel);
397}
398
399static void cobalt_stop_streaming(struct vb2_queue *q)
400{
401 struct cobalt_stream *s = q->drv_priv;
402 struct cobalt *cobalt = s->cobalt;
403 int rx = s->video_channel;
404 struct m00233_video_measure_regmap __iomem *vmr;
405 struct m00473_freewheel_regmap __iomem *fw;
406 struct m00479_clk_loss_detector_regmap __iomem *clkloss;
407 struct cobalt_buffer *cb;
408 struct list_head *p, *safe;
409 unsigned long flags;
410
411 cobalt_dma_stop_streaming(s);
412
413 /* Return all buffers to user space */
414 spin_lock_irqsave(&s->irqlock, flags);
415 list_for_each_safe(p, safe, &s->bufs) {
416 cb = list_entry(p, struct cobalt_buffer, list);
417 list_del(&cb->list);
418 vb2_buffer_done(&cb->vb, VB2_BUF_STATE_ERROR);
419 }
420 spin_unlock_irqrestore(&s->irqlock, flags);
421
422 if (s->is_audio || s->is_output)
423 return;
424
425 fw = COBALT_CVI_FREEWHEEL(cobalt, rx);
426 vmr = COBALT_CVI_VMR(cobalt, rx);
427 clkloss = COBALT_CVI_CLK_LOSS(cobalt, rx);
428 iowrite32(0, &vmr->control);
429 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK, &vmr->control);
430 iowrite32(0, &fw->ctrl);
431 iowrite32(0, &clkloss->ctrl);
432}
433
434static const struct vb2_ops cobalt_qops = {
435 .queue_setup = cobalt_queue_setup,
436 .buf_init = cobalt_buf_init,
437 .buf_cleanup = cobalt_buf_cleanup,
438 .buf_prepare = cobalt_buf_prepare,
439 .buf_queue = cobalt_buf_queue,
440 .start_streaming = cobalt_start_streaming,
441 .stop_streaming = cobalt_stop_streaming,
442 .wait_prepare = vb2_ops_wait_prepare,
443 .wait_finish = vb2_ops_wait_finish,
444};
445
446/* V4L2 ioctls */
447
448#ifdef CONFIG_VIDEO_ADV_DEBUG
449static int cobalt_cobaltc(struct cobalt *cobalt, unsigned int cmd, void *arg)
450{
451 struct v4l2_dbg_register *regs = arg;
452 void __iomem *adrs = cobalt->bar1 + regs->reg;
453
454 cobalt_info("cobalt_cobaltc: adrs = %p\n", adrs);
455
456 if (!capable(CAP_SYS_ADMIN))
457 return -EPERM;
458
459 regs->size = 4;
460 if (cmd == VIDIOC_DBG_S_REGISTER)
461 iowrite32(regs->val, adrs);
462 else
463 regs->val = ioread32(adrs);
464 return 0;
465}
466
467static int cobalt_g_register(struct file *file, void *priv_fh,
468 struct v4l2_dbg_register *reg)
469{
470 struct cobalt_stream *s = video_drvdata(file);
471 struct cobalt *cobalt = s->cobalt;
472
473 return cobalt_cobaltc(cobalt, VIDIOC_DBG_G_REGISTER, reg);
474}
475
476static int cobalt_s_register(struct file *file, void *priv_fh,
477 const struct v4l2_dbg_register *reg)
478{
479 struct cobalt_stream *s = video_drvdata(file);
480 struct cobalt *cobalt = s->cobalt;
481
482 return cobalt_cobaltc(cobalt, VIDIOC_DBG_S_REGISTER,
483 (struct v4l2_dbg_register *)reg);
484}
485#endif
486
487static int cobalt_querycap(struct file *file, void *priv_fh,
488 struct v4l2_capability *vcap)
489{
490 struct cobalt_stream *s = video_drvdata(file);
491 struct cobalt *cobalt = s->cobalt;
492
493 strlcpy(vcap->driver, "cobalt", sizeof(vcap->driver));
494 strlcpy(vcap->card, "cobalt", sizeof(vcap->card));
495 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
496 "PCIe:%s", pci_name(cobalt->pci_dev));
497 vcap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
498 if (s->is_output)
499 vcap->device_caps |= V4L2_CAP_VIDEO_OUTPUT;
500 else
501 vcap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
502 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS |
503 V4L2_CAP_VIDEO_CAPTURE;
504 if (cobalt->have_hsma_tx)
505 vcap->capabilities |= V4L2_CAP_VIDEO_OUTPUT;
506 return 0;
507}
508
509static void cobalt_video_input_status_show(struct cobalt_stream *s)
510{
511 struct m00389_cvi_regmap __iomem *cvi;
512 struct m00233_video_measure_regmap __iomem *vmr;
513 struct m00473_freewheel_regmap __iomem *fw;
514 struct m00479_clk_loss_detector_regmap __iomem *clkloss;
515 struct m00235_fdma_packer_regmap __iomem *packer;
516 int rx = s->video_channel;
517 struct cobalt *cobalt = s->cobalt;
518 u32 cvi_ctrl, cvi_stat;
519 u32 vmr_ctrl, vmr_stat;
520
521 cvi = COBALT_CVI(cobalt, rx);
522 vmr = COBALT_CVI_VMR(cobalt, rx);
523 fw = COBALT_CVI_FREEWHEEL(cobalt, rx);
524 clkloss = COBALT_CVI_CLK_LOSS(cobalt, rx);
525 packer = COBALT_CVI_PACKER(cobalt, rx);
526 cvi_ctrl = ioread32(&cvi->control);
527 cvi_stat = ioread32(&cvi->status);
528 vmr_ctrl = ioread32(&vmr->control);
529 vmr_stat = ioread32(&vmr->control);
530 cobalt_info("rx%d: cvi resolution: %dx%d\n", rx,
531 ioread32(&cvi->frame_width), ioread32(&cvi->frame_height));
532 cobalt_info("rx%d: cvi control: %s%s%s\n", rx,
533 (cvi_ctrl & M00389_CONTROL_BITMAP_ENABLE_MSK) ?
534 "enable " : "disable ",
535 (cvi_ctrl & M00389_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK) ?
536 "HSync- " : "HSync+ ",
537 (cvi_ctrl & M00389_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK) ?
538 "VSync- " : "VSync+ ");
539 cobalt_info("rx%d: cvi status: %s%s\n", rx,
540 (cvi_stat & M00389_STATUS_BITMAP_LOCK_MSK) ?
541 "lock " : "no-lock ",
542 (cvi_stat & M00389_STATUS_BITMAP_ERROR_MSK) ?
543 "error " : "no-error ");
544
545 cobalt_info("rx%d: Measurements: %s%s%s%s%s%s%s\n", rx,
546 (vmr_ctrl & M00233_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK) ?
547 "HSync- " : "HSync+ ",
548 (vmr_ctrl & M00233_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK) ?
549 "VSync- " : "VSync+ ",
550 (vmr_ctrl & M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK) ?
551 "enabled " : "disabled ",
552 (vmr_ctrl & M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_MSK) ?
553 "irq-enabled " : "irq-disabled ",
554 (vmr_ctrl & M00233_CONTROL_BITMAP_UPDATE_ON_HSYNC_MSK) ?
555 "update-on-hsync " : "",
556 (vmr_stat & M00233_STATUS_BITMAP_HSYNC_TIMEOUT_MSK) ?
557 "hsync-timeout " : "",
558 (vmr_stat & M00233_STATUS_BITMAP_INIT_DONE_MSK) ?
559 "init-done" : "");
560 cobalt_info("rx%d: irq_status: 0x%02x irq_triggers: 0x%02x\n", rx,
561 ioread32(&vmr->irq_status) & 0xff,
562 ioread32(&vmr->irq_triggers) & 0xff);
563 cobalt_info("rx%d: vsync: %d\n", rx, ioread32(&vmr->vsync_time));
564 cobalt_info("rx%d: vbp: %d\n", rx, ioread32(&vmr->vback_porch));
565 cobalt_info("rx%d: vact: %d\n", rx, ioread32(&vmr->vactive_area));
566 cobalt_info("rx%d: vfb: %d\n", rx, ioread32(&vmr->vfront_porch));
567 cobalt_info("rx%d: hsync: %d\n", rx, ioread32(&vmr->hsync_time));
568 cobalt_info("rx%d: hbp: %d\n", rx, ioread32(&vmr->hback_porch));
569 cobalt_info("rx%d: hact: %d\n", rx, ioread32(&vmr->hactive_area));
570 cobalt_info("rx%d: hfb: %d\n", rx, ioread32(&vmr->hfront_porch));
571 cobalt_info("rx%d: Freewheeling: %s%s%s\n", rx,
572 (ioread32(&fw->ctrl) & M00473_CTRL_BITMAP_ENABLE_MSK) ?
573 "enabled " : "disabled ",
574 (ioread32(&fw->ctrl) & M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK) ?
575 "forced " : "",
576 (ioread32(&fw->status) & M00473_STATUS_BITMAP_FREEWHEEL_MODE_MSK) ?
577 "freewheeling " : "video-passthrough ");
578 iowrite32(0xff, &vmr->irq_status);
579 cobalt_info("rx%d: Clock Loss Detection: %s%s\n", rx,
580 (ioread32(&clkloss->ctrl) & M00479_CTRL_BITMAP_ENABLE_MSK) ?
581 "enabled " : "disabled ",
582 (ioread32(&clkloss->status) & M00479_STATUS_BITMAP_CLOCK_MISSING_MSK) ?
583 "clock-missing " : "found-clock ");
584 cobalt_info("rx%d: Packer: %x\n", rx, ioread32(&packer->control));
585}
586
587static int cobalt_log_status(struct file *file, void *priv_fh)
588{
589 struct cobalt_stream *s = video_drvdata(file);
590 struct cobalt *cobalt = s->cobalt;
591 struct m00514_syncgen_flow_evcnt_regmap __iomem *vo =
592 COBALT_TX_BASE(cobalt);
593 u8 stat;
594
595 cobalt_info("%s", cobalt->hdl_info);
596 cobalt_info("sysctrl: %08x, sysstat: %08x\n",
597 cobalt_g_sysctrl(cobalt),
598 cobalt_g_sysstat(cobalt));
599 cobalt_info("dma channel: %d, video channel: %d\n",
600 s->dma_channel, s->video_channel);
601 cobalt_pcie_status_show(cobalt);
602 cobalt_cpld_status(cobalt);
603 cobalt_irq_log_status(cobalt);
604 v4l2_subdev_call(s->sd, core, log_status);
605 if (!s->is_output) {
606 cobalt_video_input_status_show(s);
607 return 0;
608 }
609
610 stat = ioread32(&vo->rd_status);
611
612 cobalt_info("tx: status: %s%s\n",
613 (stat & M00514_RD_STATUS_BITMAP_FLOW_CTRL_NO_DATA_ERROR_MSK) ?
614 "no_data " : "",
615 (stat & M00514_RD_STATUS_BITMAP_READY_BUFFER_FULL_MSK) ?
616 "ready_buffer_full " : "");
617 cobalt_info("tx: evcnt: %d\n", ioread32(&vo->rd_evcnt_count));
618 return 0;
619}
620
621static int cobalt_enum_dv_timings(struct file *file, void *priv_fh,
622 struct v4l2_enum_dv_timings *timings)
623{
624 struct cobalt_stream *s = video_drvdata(file);
625
626 if (s->input == 1) {
627 if (timings->index)
628 return -EINVAL;
629 memset(timings->reserved, 0, sizeof(timings->reserved));
630 timings->timings = cea1080p60;
631 return 0;
632 }
633 timings->pad = 0;
634 return v4l2_subdev_call(s->sd,
635 pad, enum_dv_timings, timings);
636}
637
638static int cobalt_s_dv_timings(struct file *file, void *priv_fh,
639 struct v4l2_dv_timings *timings)
640{
641 struct cobalt_stream *s = video_drvdata(file);
642 int err;
643
644 if (vb2_is_busy(&s->q))
645 return -EBUSY;
646
647 if (s->input == 1) {
648 *timings = cea1080p60;
649 return 0;
650 }
651 err = v4l2_subdev_call(s->sd,
652 video, s_dv_timings, timings);
653 if (!err) {
654 s->timings = *timings;
655 s->width = timings->bt.width;
656 s->height = timings->bt.height;
657 s->stride = timings->bt.width * s->bpp;
658 }
659 return err;
660}
661
662static int cobalt_g_dv_timings(struct file *file, void *priv_fh,
663 struct v4l2_dv_timings *timings)
664{
665 struct cobalt_stream *s = video_drvdata(file);
666
667 if (s->input == 1) {
668 *timings = cea1080p60;
669 return 0;
670 }
671 return v4l2_subdev_call(s->sd,
672 video, g_dv_timings, timings);
673}
674
675static int cobalt_query_dv_timings(struct file *file, void *priv_fh,
676 struct v4l2_dv_timings *timings)
677{
678 struct cobalt_stream *s = video_drvdata(file);
679
680 if (s->input == 1) {
681 *timings = cea1080p60;
682 return 0;
683 }
684 return v4l2_subdev_call(s->sd,
685 video, query_dv_timings, timings);
686}
687
688static int cobalt_dv_timings_cap(struct file *file, void *priv_fh,
689 struct v4l2_dv_timings_cap *cap)
690{
691 struct cobalt_stream *s = video_drvdata(file);
692
693 cap->pad = 0;
694 return v4l2_subdev_call(s->sd,
695 pad, dv_timings_cap, cap);
696}
697
698static int cobalt_enum_fmt_vid_cap(struct file *file, void *priv_fh,
699 struct v4l2_fmtdesc *f)
700{
701 switch (f->index) {
702 case 0:
703 strlcpy(f->description, "YUV 4:2:2", sizeof(f->description));
704 f->pixelformat = V4L2_PIX_FMT_YUYV;
705 break;
706 case 1:
707 strlcpy(f->description, "RGB24", sizeof(f->description));
708 f->pixelformat = V4L2_PIX_FMT_RGB24;
709 break;
710 case 2:
711 strlcpy(f->description, "RGB32", sizeof(f->description));
712 f->pixelformat = V4L2_PIX_FMT_BGR32;
713 break;
714 default:
715 return -EINVAL;
716 }
717
718 return 0;
719}
720
721static int cobalt_g_fmt_vid_cap(struct file *file, void *priv_fh,
722 struct v4l2_format *f)
723{
724 struct cobalt_stream *s = video_drvdata(file);
725 struct v4l2_pix_format *pix = &f->fmt.pix;
726 struct v4l2_subdev_format sd_fmt;
727
728 pix->width = s->width;
729 pix->height = s->height;
730 pix->bytesperline = s->stride;
731 pix->field = V4L2_FIELD_NONE;
732
733 if (s->input == 1) {
734 pix->colorspace = V4L2_COLORSPACE_SRGB;
735 } else {
736 sd_fmt.pad = s->pad_source;
737 sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
738 v4l2_subdev_call(s->sd, pad, get_fmt, NULL, &sd_fmt);
739 v4l2_fill_pix_format(pix, &sd_fmt.format);
740 }
741
742 pix->pixelformat = s->pixfmt;
743 pix->sizeimage = pix->bytesperline * pix->height;
744
745 return 0;
746}
747
748static int cobalt_try_fmt_vid_cap(struct file *file, void *priv_fh,
749 struct v4l2_format *f)
750{
751 struct cobalt_stream *s = video_drvdata(file);
752 struct v4l2_pix_format *pix = &f->fmt.pix;
753 struct v4l2_subdev_format sd_fmt;
754
755 /* Check for min (QCIF) and max (Full HD) size */
756 if ((pix->width < 176) || (pix->height < 144)) {
757 pix->width = 176;
758 pix->height = 144;
759 }
760
761 if ((pix->width > 1920) || (pix->height > 1080)) {
762 pix->width = 1920;
763 pix->height = 1080;
764 }
765
766 /* Make width multiple of 4 */
767 pix->width &= ~0x3;
768
769 /* Make height multiple of 2 */
770 pix->height &= ~0x1;
771
772 if (s->input == 1) {
773 /* Generator => fixed format only */
774 pix->width = 1920;
775 pix->height = 1080;
776 pix->colorspace = V4L2_COLORSPACE_SRGB;
777 } else {
778 sd_fmt.pad = s->pad_source;
779 sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
780 v4l2_subdev_call(s->sd, pad, get_fmt, NULL, &sd_fmt);
781 v4l2_fill_pix_format(pix, &sd_fmt.format);
782 }
783
784 switch (pix->pixelformat) {
785 case V4L2_PIX_FMT_YUYV:
786 default:
787 pix->bytesperline = max(pix->bytesperline & ~0x3,
788 pix->width * COBALT_BYTES_PER_PIXEL_YUYV);
789 pix->pixelformat = V4L2_PIX_FMT_YUYV;
790 break;
791 case V4L2_PIX_FMT_RGB24:
792 pix->bytesperline = max(pix->bytesperline & ~0x3,
793 pix->width * COBALT_BYTES_PER_PIXEL_RGB24);
794 break;
795 case V4L2_PIX_FMT_BGR32:
796 pix->bytesperline = max(pix->bytesperline & ~0x3,
797 pix->width * COBALT_BYTES_PER_PIXEL_RGB32);
798 break;
799 }
800
801 pix->sizeimage = pix->bytesperline * pix->height;
802 pix->field = V4L2_FIELD_NONE;
803 pix->priv = 0;
804
805 return 0;
806}
807
808static int cobalt_s_fmt_vid_cap(struct file *file, void *priv_fh,
809 struct v4l2_format *f)
810{
811 struct cobalt_stream *s = video_drvdata(file);
812 struct v4l2_pix_format *pix = &f->fmt.pix;
813
814 if (vb2_is_busy(&s->q))
815 return -EBUSY;
816
817 if (cobalt_try_fmt_vid_cap(file, priv_fh, f))
818 return -EINVAL;
819
820 s->width = pix->width;
821 s->height = pix->height;
822 s->stride = pix->bytesperline;
823 switch (pix->pixelformat) {
824 case V4L2_PIX_FMT_YUYV:
825 s->bpp = COBALT_BYTES_PER_PIXEL_YUYV;
826 break;
827 case V4L2_PIX_FMT_RGB24:
828 s->bpp = COBALT_BYTES_PER_PIXEL_RGB24;
829 break;
830 case V4L2_PIX_FMT_BGR32:
831 s->bpp = COBALT_BYTES_PER_PIXEL_RGB32;
832 break;
833 default:
834 return -EINVAL;
835 }
836 s->pixfmt = pix->pixelformat;
837 cobalt_enable_input(s);
838
839 return 0;
840}
841
842static int cobalt_try_fmt_vid_out(struct file *file, void *priv_fh,
843 struct v4l2_format *f)
844{
845 struct v4l2_pix_format *pix = &f->fmt.pix;
846
847 /* Check for min (QCIF) and max (Full HD) size */
848 if ((pix->width < 176) || (pix->height < 144)) {
849 pix->width = 176;
850 pix->height = 144;
851 }
852
853 if ((pix->width > 1920) || (pix->height > 1080)) {
854 pix->width = 1920;
855 pix->height = 1080;
856 }
857
858 /* Make width multiple of 4 */
859 pix->width &= ~0x3;
860
861 /* Make height multiple of 2 */
862 pix->height &= ~0x1;
863
864 switch (pix->pixelformat) {
865 case V4L2_PIX_FMT_YUYV:
866 default:
867 pix->bytesperline = max(pix->bytesperline & ~0x3,
868 pix->width * COBALT_BYTES_PER_PIXEL_YUYV);
869 pix->pixelformat = V4L2_PIX_FMT_YUYV;
870 break;
871 case V4L2_PIX_FMT_BGR32:
872 pix->bytesperline = max(pix->bytesperline & ~0x3,
873 pix->width * COBALT_BYTES_PER_PIXEL_RGB32);
874 break;
875 }
876
877 pix->sizeimage = pix->bytesperline * pix->height;
878 pix->field = V4L2_FIELD_NONE;
879
880 return 0;
881}
882
883static int cobalt_g_fmt_vid_out(struct file *file, void *priv_fh,
884 struct v4l2_format *f)
885{
886 struct cobalt_stream *s = video_drvdata(file);
887 struct v4l2_pix_format *pix = &f->fmt.pix;
888
889 pix->width = s->width;
890 pix->height = s->height;
891 pix->bytesperline = s->stride;
892 pix->field = V4L2_FIELD_NONE;
893 pix->pixelformat = s->pixfmt;
894 pix->colorspace = s->colorspace;
895 pix->xfer_func = s->xfer_func;
896 pix->ycbcr_enc = s->ycbcr_enc;
897 pix->quantization = s->quantization;
898 pix->sizeimage = pix->bytesperline * pix->height;
899
900 return 0;
901}
902
903static int cobalt_enum_fmt_vid_out(struct file *file, void *priv_fh,
904 struct v4l2_fmtdesc *f)
905{
906 switch (f->index) {
907 case 0:
908 strlcpy(f->description, "YUV 4:2:2", sizeof(f->description));
909 f->pixelformat = V4L2_PIX_FMT_YUYV;
910 break;
911 case 1:
912 strlcpy(f->description, "RGB32", sizeof(f->description));
913 f->pixelformat = V4L2_PIX_FMT_BGR32;
914 break;
915 default:
916 return -EINVAL;
917 }
918
919 return 0;
920}
921
922static int cobalt_s_fmt_vid_out(struct file *file, void *priv_fh,
923 struct v4l2_format *f)
924{
925 struct cobalt_stream *s = video_drvdata(file);
926 struct v4l2_pix_format *pix = &f->fmt.pix;
927 struct v4l2_subdev_format sd_fmt = { 0 };
928 u32 code;
929
930 if (cobalt_try_fmt_vid_out(file, priv_fh, f))
931 return -EINVAL;
932
933 if (vb2_is_busy(&s->q) && (pix->pixelformat != s->pixfmt ||
934 pix->width != s->width || pix->height != s->height ||
935 pix->bytesperline != s->stride))
936 return -EBUSY;
937
938 switch (pix->pixelformat) {
939 case V4L2_PIX_FMT_YUYV:
940 s->bpp = COBALT_BYTES_PER_PIXEL_YUYV;
941 code = MEDIA_BUS_FMT_UYVY8_1X16;
942 break;
943 case V4L2_PIX_FMT_BGR32:
944 s->bpp = COBALT_BYTES_PER_PIXEL_RGB32;
945 code = MEDIA_BUS_FMT_RGB888_1X24;
946 break;
947 default:
948 return -EINVAL;
949 }
950 s->width = pix->width;
951 s->height = pix->height;
952 s->stride = pix->bytesperline;
953 s->pixfmt = pix->pixelformat;
954 s->colorspace = pix->colorspace;
955 s->xfer_func = pix->xfer_func;
956 s->ycbcr_enc = pix->ycbcr_enc;
957 s->quantization = pix->quantization;
958 sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
959 v4l2_fill_mbus_format(&sd_fmt.format, pix, code);
960 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, &sd_fmt);
961 return 0;
962}
963
964static int cobalt_enum_input(struct file *file, void *priv_fh,
965 struct v4l2_input *inp)
966{
967 struct cobalt_stream *s = video_drvdata(file);
968
969 if (inp->index > 1)
970 return -EINVAL;
971 if (inp->index == 0)
972 snprintf(inp->name, sizeof(inp->name),
973 "HDMI-%d", s->video_channel);
974 else
975 snprintf(inp->name, sizeof(inp->name),
976 "Generator-%d", s->video_channel);
977 inp->type = V4L2_INPUT_TYPE_CAMERA;
978 inp->capabilities = V4L2_IN_CAP_DV_TIMINGS;
979 if (inp->index == 1)
980 return 0;
981 return v4l2_subdev_call(s->sd,
982 video, g_input_status, &inp->status);
983}
984
985static int cobalt_g_input(struct file *file, void *priv_fh, unsigned int *i)
986{
987 struct cobalt_stream *s = video_drvdata(file);
988
989 *i = s->input;
990 return 0;
991}
992
993static int cobalt_s_input(struct file *file, void *priv_fh, unsigned int i)
994{
995 struct cobalt_stream *s = video_drvdata(file);
996
997 if (i >= 2)
998 return -EINVAL;
999 if (vb2_is_busy(&s->q))
1000 return -EBUSY;
1001 s->input = i;
1002
1003 cobalt_enable_input(s);
1004
1005 if (s->input == 1) /* Test Pattern Generator */
1006 return 0;
1007
1008 return v4l2_subdev_call(s->sd, video, s_routing,
1009 ADV76XX_PAD_HDMI_PORT_A, 0, 0);
1010}
1011
1012static int cobalt_enum_output(struct file *file, void *priv_fh,
1013 struct v4l2_output *out)
1014{
1015 if (out->index)
1016 return -EINVAL;
1017 snprintf(out->name, sizeof(out->name), "HDMI-%d", out->index);
1018 out->type = V4L2_OUTPUT_TYPE_ANALOG;
1019 out->capabilities = V4L2_OUT_CAP_DV_TIMINGS;
1020 return 0;
1021}
1022
1023static int cobalt_g_output(struct file *file, void *priv_fh, unsigned int *i)
1024{
1025 *i = 0;
1026 return 0;
1027}
1028
1029static int cobalt_s_output(struct file *file, void *priv_fh, unsigned int i)
1030{
1031 return i ? -EINVAL : 0;
1032}
1033
1034static int cobalt_g_edid(struct file *file, void *fh, struct v4l2_edid *edid)
1035{
1036 struct cobalt_stream *s = video_drvdata(file);
1037 u32 pad = edid->pad;
1038 int ret;
1039
1040 if (edid->pad >= (s->is_output ? 1 : 2))
1041 return -EINVAL;
1042 edid->pad = 0;
1043 ret = v4l2_subdev_call(s->sd, pad, get_edid, edid);
1044 edid->pad = pad;
1045 return ret;
1046}
1047
1048static int cobalt_s_edid(struct file *file, void *fh, struct v4l2_edid *edid)
1049{
1050 struct cobalt_stream *s = video_drvdata(file);
1051 u32 pad = edid->pad;
1052 int ret;
1053
1054 if (edid->pad >= 2)
1055 return -EINVAL;
1056 edid->pad = 0;
1057 ret = v4l2_subdev_call(s->sd, pad, set_edid, edid);
1058 edid->pad = pad;
1059 return ret;
1060}
1061
1062static int cobalt_subscribe_event(struct v4l2_fh *fh,
1063 const struct v4l2_event_subscription *sub)
1064{
1065 switch (sub->type) {
1066 case V4L2_EVENT_SOURCE_CHANGE:
1067 return v4l2_event_subscribe(fh, sub, 4, NULL);
1068 }
1069 return v4l2_ctrl_subscribe_event(fh, sub);
1070}
1071
1072static int cobalt_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
1073{
1074 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1075 return -EINVAL;
1076 a->parm.capture.timeperframe.numerator = 1;
1077 a->parm.capture.timeperframe.denominator = 60;
1078 a->parm.capture.readbuffers = 3;
1079 return 0;
1080}
1081
1082static const struct v4l2_ioctl_ops cobalt_ioctl_ops = {
1083 .vidioc_querycap = cobalt_querycap,
1084 .vidioc_g_parm = cobalt_g_parm,
1085 .vidioc_log_status = cobalt_log_status,
1086 .vidioc_streamon = vb2_ioctl_streamon,
1087 .vidioc_streamoff = vb2_ioctl_streamoff,
1088 .vidioc_enum_input = cobalt_enum_input,
1089 .vidioc_g_input = cobalt_g_input,
1090 .vidioc_s_input = cobalt_s_input,
1091 .vidioc_enum_fmt_vid_cap = cobalt_enum_fmt_vid_cap,
1092 .vidioc_g_fmt_vid_cap = cobalt_g_fmt_vid_cap,
1093 .vidioc_s_fmt_vid_cap = cobalt_s_fmt_vid_cap,
1094 .vidioc_try_fmt_vid_cap = cobalt_try_fmt_vid_cap,
1095 .vidioc_enum_output = cobalt_enum_output,
1096 .vidioc_g_output = cobalt_g_output,
1097 .vidioc_s_output = cobalt_s_output,
1098 .vidioc_enum_fmt_vid_out = cobalt_enum_fmt_vid_out,
1099 .vidioc_g_fmt_vid_out = cobalt_g_fmt_vid_out,
1100 .vidioc_s_fmt_vid_out = cobalt_s_fmt_vid_out,
1101 .vidioc_try_fmt_vid_out = cobalt_try_fmt_vid_out,
1102 .vidioc_s_dv_timings = cobalt_s_dv_timings,
1103 .vidioc_g_dv_timings = cobalt_g_dv_timings,
1104 .vidioc_query_dv_timings = cobalt_query_dv_timings,
1105 .vidioc_enum_dv_timings = cobalt_enum_dv_timings,
1106 .vidioc_dv_timings_cap = cobalt_dv_timings_cap,
1107 .vidioc_g_edid = cobalt_g_edid,
1108 .vidioc_s_edid = cobalt_s_edid,
1109 .vidioc_subscribe_event = cobalt_subscribe_event,
1110 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1111 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1112 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1113 .vidioc_querybuf = vb2_ioctl_querybuf,
1114 .vidioc_qbuf = vb2_ioctl_qbuf,
1115 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1116 .vidioc_expbuf = vb2_ioctl_expbuf,
1117#ifdef CONFIG_VIDEO_ADV_DEBUG
1118 .vidioc_g_register = cobalt_g_register,
1119 .vidioc_s_register = cobalt_s_register,
1120#endif
1121};
1122
1123static const struct v4l2_ioctl_ops cobalt_ioctl_empty_ops = {
1124#ifdef CONFIG_VIDEO_ADV_DEBUG
1125 .vidioc_g_register = cobalt_g_register,
1126 .vidioc_s_register = cobalt_s_register,
1127#endif
1128};
1129
1130/* Register device nodes */
1131
1132static const struct v4l2_file_operations cobalt_fops = {
1133 .owner = THIS_MODULE,
1134 .open = v4l2_fh_open,
1135 .unlocked_ioctl = video_ioctl2,
1136 .release = vb2_fop_release,
1137 .poll = vb2_fop_poll,
1138 .mmap = vb2_fop_mmap,
1139 .read = vb2_fop_read,
1140};
1141
1142static const struct v4l2_file_operations cobalt_out_fops = {
1143 .owner = THIS_MODULE,
1144 .open = v4l2_fh_open,
1145 .unlocked_ioctl = video_ioctl2,
1146 .release = vb2_fop_release,
1147 .poll = vb2_fop_poll,
1148 .mmap = vb2_fop_mmap,
1149 .write = vb2_fop_write,
1150};
1151
1152static const struct v4l2_file_operations cobalt_empty_fops = {
1153 .owner = THIS_MODULE,
1154 .open = v4l2_fh_open,
1155 .unlocked_ioctl = video_ioctl2,
1156 .release = v4l2_fh_release,
1157};
1158
1159static int cobalt_node_register(struct cobalt *cobalt, int node)
1160{
1161 static const struct v4l2_dv_timings dv1080p60 =
1162 V4L2_DV_BT_CEA_1920X1080P60;
1163 struct cobalt_stream *s = cobalt->streams + node;
1164 struct video_device *vdev = &s->vdev;
1165 struct vb2_queue *q = &s->q;
1166 int ret;
1167
1168 mutex_init(&s->lock);
1169 spin_lock_init(&s->irqlock);
1170
1171 snprintf(vdev->name, sizeof(vdev->name),
1172 "%s-%d", cobalt->v4l2_dev.name, node);
1173 s->width = 1920;
1174 /* Audio frames are just 4 lines of 1920 bytes */
1175 s->height = s->is_audio ? 4 : 1080;
1176
1177 if (s->is_audio) {
1178 s->bpp = 1;
1179 s->pixfmt = V4L2_PIX_FMT_GREY;
1180 } else if (s->is_output) {
1181 s->bpp = COBALT_BYTES_PER_PIXEL_RGB32;
1182 s->pixfmt = V4L2_PIX_FMT_BGR32;
1183 } else {
1184 s->bpp = COBALT_BYTES_PER_PIXEL_YUYV;
1185 s->pixfmt = V4L2_PIX_FMT_YUYV;
1186 }
1187 s->colorspace = V4L2_COLORSPACE_SRGB;
1188 s->stride = s->width * s->bpp;
1189
1190 if (!s->is_audio) {
1191 if (s->is_dummy)
1192 cobalt_warn("Setting up dummy video node %d\n", node);
1193 vdev->v4l2_dev = &cobalt->v4l2_dev;
1194 if (s->is_dummy)
1195 vdev->fops = &cobalt_empty_fops;
1196 else
1197 vdev->fops = s->is_output ? &cobalt_out_fops :
1198 &cobalt_fops;
1199 vdev->release = video_device_release_empty;
1200 vdev->vfl_dir = s->is_output ? VFL_DIR_TX : VFL_DIR_RX;
1201 vdev->lock = &s->lock;
1202 if (s->sd)
1203 vdev->ctrl_handler = s->sd->ctrl_handler;
1204 s->timings = dv1080p60;
1205 v4l2_subdev_call(s->sd, video, s_dv_timings, &s->timings);
1206 if (!s->is_output && s->sd)
1207 cobalt_enable_input(s);
1208 vdev->ioctl_ops = s->is_dummy ? &cobalt_ioctl_empty_ops :
1209 &cobalt_ioctl_ops;
1210 }
1211
1212 INIT_LIST_HEAD(&s->bufs);
1213 q->type = s->is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT :
1214 V4L2_BUF_TYPE_VIDEO_CAPTURE;
1215 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1216 q->io_modes |= s->is_output ? VB2_WRITE : VB2_READ;
1217 q->drv_priv = s;
1218 q->buf_struct_size = sizeof(struct cobalt_buffer);
1219 q->ops = &cobalt_qops;
1220 q->mem_ops = &vb2_dma_sg_memops;
1221 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1222 q->min_buffers_needed = 2;
1223 q->lock = &s->lock;
1224 vdev->queue = q;
1225
1226 video_set_drvdata(vdev, s);
1227 ret = vb2_queue_init(q);
1228 if (!s->is_audio && ret == 0)
1229 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1230 else if (!s->is_dummy)
1231 ret = cobalt_alsa_init(s);
1232
1233 if (ret < 0) {
1234 if (!s->is_audio)
1235 cobalt_err("couldn't register v4l2 device node %d\n",
1236 node);
1237 return ret;
1238 }
1239 cobalt_info("registered node %d\n", node);
1240 return 0;
1241}
1242
1243/* Initialize v4l2 variables and register v4l2 devices */
1244int cobalt_nodes_register(struct cobalt *cobalt)
1245{
1246 int node, ret;
1247
1248 /* Setup V4L2 Devices */
1249 for (node = 0; node < COBALT_NUM_STREAMS; node++) {
1250 ret = cobalt_node_register(cobalt, node);
1251 if (ret)
1252 return ret;
1253 }
1254 return 0;
1255}
1256
1257/* Unregister v4l2 devices */
1258void cobalt_nodes_unregister(struct cobalt *cobalt)
1259{
1260 int node;
1261
1262 /* Teardown all streams */
1263 for (node = 0; node < COBALT_NUM_STREAMS; node++) {
1264 struct cobalt_stream *s = cobalt->streams + node;
1265 struct video_device *vdev = &s->vdev;
1266
1267 if (!s->is_audio)
1268 video_unregister_device(vdev);
1269 else if (!s->is_dummy)
1270 cobalt_alsa_exit(s);
1271 }
1272}
diff --git a/drivers/media/pci/cobalt/cobalt-v4l2.h b/drivers/media/pci/cobalt/cobalt-v4l2.h
new file mode 100644
index 000000000000..62be553cd8e2
--- /dev/null
+++ b/drivers/media/pci/cobalt/cobalt-v4l2.h
@@ -0,0 +1,22 @@
1/*
2 * cobalt V4L2 API
3 *
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21int cobalt_nodes_register(struct cobalt *cobalt);
22void cobalt_nodes_unregister(struct cobalt *cobalt);
diff --git a/drivers/media/pci/cobalt/m00233_video_measure_memmap_package.h b/drivers/media/pci/cobalt/m00233_video_measure_memmap_package.h
new file mode 100644
index 000000000000..9bc9ef1fd3a8
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00233_video_measure_memmap_package.h
@@ -0,0 +1,115 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00233_VIDEO_MEASURE_MEMMAP_PACKAGE_H
20#define M00233_VIDEO_MEASURE_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00233_VIDEO_MEASURE_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00233_video_measure_regmap {
27 uint32_t irq_status; /* Reg 0x0000 */
28 /* The vertical counter starts on rising edge of vsync */
29 uint32_t vsync_time; /* Reg 0x0004 */
30 uint32_t vback_porch; /* Reg 0x0008 */
31 uint32_t vactive_area; /* Reg 0x000c */
32 uint32_t vfront_porch; /* Reg 0x0010 */
33 /* The horizontal counter starts on rising edge of hsync. */
34 uint32_t hsync_time; /* Reg 0x0014 */
35 uint32_t hback_porch; /* Reg 0x0018 */
36 uint32_t hactive_area; /* Reg 0x001c */
37 uint32_t hfront_porch; /* Reg 0x0020 */
38 uint32_t control; /* Reg 0x0024, Default=0x0 */
39 uint32_t irq_triggers; /* Reg 0x0028, Default=0xff */
40 /* Value is given in number of register bus clock periods between */
41 /* falling and rising edge of hsync. Must be non-zero. */
42 uint32_t hsync_timeout_val; /* Reg 0x002c, Default=0x1fff */
43 uint32_t status; /* Reg 0x0030 */
44};
45
46#define M00233_VIDEO_MEASURE_REG_IRQ_STATUS_OFST 0
47#define M00233_VIDEO_MEASURE_REG_VSYNC_TIME_OFST 4
48#define M00233_VIDEO_MEASURE_REG_VBACK_PORCH_OFST 8
49#define M00233_VIDEO_MEASURE_REG_VACTIVE_AREA_OFST 12
50#define M00233_VIDEO_MEASURE_REG_VFRONT_PORCH_OFST 16
51#define M00233_VIDEO_MEASURE_REG_HSYNC_TIME_OFST 20
52#define M00233_VIDEO_MEASURE_REG_HBACK_PORCH_OFST 24
53#define M00233_VIDEO_MEASURE_REG_HACTIVE_AREA_OFST 28
54#define M00233_VIDEO_MEASURE_REG_HFRONT_PORCH_OFST 32
55#define M00233_VIDEO_MEASURE_REG_CONTROL_OFST 36
56#define M00233_VIDEO_MEASURE_REG_IRQ_TRIGGERS_OFST 40
57#define M00233_VIDEO_MEASURE_REG_HSYNC_TIMEOUT_VAL_OFST 44
58#define M00233_VIDEO_MEASURE_REG_STATUS_OFST 48
59
60/*******************************************************************
61 * Bit Mask for register
62 * M00233_VIDEO_MEASURE_MEMMAP_PACKAGE_VHD_BITMAP
63 *******************************************************************/
64/* irq_status [7:0] */
65#define M00233_IRQ_STATUS_BITMAP_VSYNC_TIME_OFST (0)
66#define M00233_IRQ_STATUS_BITMAP_VSYNC_TIME_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_VSYNC_TIME_OFST)
67#define M00233_IRQ_STATUS_BITMAP_VBACK_PORCH_OFST (1)
68#define M00233_IRQ_STATUS_BITMAP_VBACK_PORCH_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_VBACK_PORCH_OFST)
69#define M00233_IRQ_STATUS_BITMAP_VACTIVE_AREA_OFST (2)
70#define M00233_IRQ_STATUS_BITMAP_VACTIVE_AREA_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_VACTIVE_AREA_OFST)
71#define M00233_IRQ_STATUS_BITMAP_VFRONT_PORCH_OFST (3)
72#define M00233_IRQ_STATUS_BITMAP_VFRONT_PORCH_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_VFRONT_PORCH_OFST)
73#define M00233_IRQ_STATUS_BITMAP_HSYNC_TIME_OFST (4)
74#define M00233_IRQ_STATUS_BITMAP_HSYNC_TIME_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_HSYNC_TIME_OFST)
75#define M00233_IRQ_STATUS_BITMAP_HBACK_PORCH_OFST (5)
76#define M00233_IRQ_STATUS_BITMAP_HBACK_PORCH_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_HBACK_PORCH_OFST)
77#define M00233_IRQ_STATUS_BITMAP_HACTIVE_AREA_OFST (6)
78#define M00233_IRQ_STATUS_BITMAP_HACTIVE_AREA_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_HACTIVE_AREA_OFST)
79#define M00233_IRQ_STATUS_BITMAP_HFRONT_PORCH_OFST (7)
80#define M00233_IRQ_STATUS_BITMAP_HFRONT_PORCH_MSK (0x1 << M00233_IRQ_STATUS_BITMAP_HFRONT_PORCH_OFST)
81/* control [4:0] */
82#define M00233_CONTROL_BITMAP_HSYNC_POLARITY_LOW_OFST (0)
83#define M00233_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK (0x1 << M00233_CONTROL_BITMAP_HSYNC_POLARITY_LOW_OFST)
84#define M00233_CONTROL_BITMAP_VSYNC_POLARITY_LOW_OFST (1)
85#define M00233_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK (0x1 << M00233_CONTROL_BITMAP_VSYNC_POLARITY_LOW_OFST)
86#define M00233_CONTROL_BITMAP_ENABLE_MEASURE_OFST (2)
87#define M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK (0x1 << M00233_CONTROL_BITMAP_ENABLE_MEASURE_OFST)
88#define M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_OFST (3)
89#define M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_MSK (0x1 << M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_OFST)
90#define M00233_CONTROL_BITMAP_UPDATE_ON_HSYNC_OFST (4)
91#define M00233_CONTROL_BITMAP_UPDATE_ON_HSYNC_MSK (0x1 << M00233_CONTROL_BITMAP_UPDATE_ON_HSYNC_OFST)
92/* irq_triggers [7:0] */
93#define M00233_IRQ_TRIGGERS_BITMAP_VSYNC_TIME_OFST (0)
94#define M00233_IRQ_TRIGGERS_BITMAP_VSYNC_TIME_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_VSYNC_TIME_OFST)
95#define M00233_IRQ_TRIGGERS_BITMAP_VBACK_PORCH_OFST (1)
96#define M00233_IRQ_TRIGGERS_BITMAP_VBACK_PORCH_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_VBACK_PORCH_OFST)
97#define M00233_IRQ_TRIGGERS_BITMAP_VACTIVE_AREA_OFST (2)
98#define M00233_IRQ_TRIGGERS_BITMAP_VACTIVE_AREA_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_VACTIVE_AREA_OFST)
99#define M00233_IRQ_TRIGGERS_BITMAP_VFRONT_PORCH_OFST (3)
100#define M00233_IRQ_TRIGGERS_BITMAP_VFRONT_PORCH_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_VFRONT_PORCH_OFST)
101#define M00233_IRQ_TRIGGERS_BITMAP_HSYNC_TIME_OFST (4)
102#define M00233_IRQ_TRIGGERS_BITMAP_HSYNC_TIME_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_HSYNC_TIME_OFST)
103#define M00233_IRQ_TRIGGERS_BITMAP_HBACK_PORCH_OFST (5)
104#define M00233_IRQ_TRIGGERS_BITMAP_HBACK_PORCH_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_HBACK_PORCH_OFST)
105#define M00233_IRQ_TRIGGERS_BITMAP_HACTIVE_AREA_OFST (6)
106#define M00233_IRQ_TRIGGERS_BITMAP_HACTIVE_AREA_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_HACTIVE_AREA_OFST)
107#define M00233_IRQ_TRIGGERS_BITMAP_HFRONT_PORCH_OFST (7)
108#define M00233_IRQ_TRIGGERS_BITMAP_HFRONT_PORCH_MSK (0x1 << M00233_IRQ_TRIGGERS_BITMAP_HFRONT_PORCH_OFST)
109/* status [1:0] */
110#define M00233_STATUS_BITMAP_HSYNC_TIMEOUT_OFST (0)
111#define M00233_STATUS_BITMAP_HSYNC_TIMEOUT_MSK (0x1 << M00233_STATUS_BITMAP_HSYNC_TIMEOUT_OFST)
112#define M00233_STATUS_BITMAP_INIT_DONE_OFST (1)
113#define M00233_STATUS_BITMAP_INIT_DONE_MSK (0x1 << M00233_STATUS_BITMAP_INIT_DONE_OFST)
114
115#endif /*M00233_VIDEO_MEASURE_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cobalt/m00235_fdma_packer_memmap_package.h b/drivers/media/pci/cobalt/m00235_fdma_packer_memmap_package.h
new file mode 100644
index 000000000000..a480529f561e
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00235_fdma_packer_memmap_package.h
@@ -0,0 +1,44 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00235_FDMA_PACKER_MEMMAP_PACKAGE_H
20#define M00235_FDMA_PACKER_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00235_FDMA_PACKER_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00235_fdma_packer_regmap {
27 uint32_t control; /* Reg 0x0000, Default=0x0 */
28};
29
30#define M00235_FDMA_PACKER_REG_CONTROL_OFST 0
31
32/*******************************************************************
33 * Bit Mask for register
34 * M00235_FDMA_PACKER_MEMMAP_PACKAGE_VHD_BITMAP
35 *******************************************************************/
36/* control [3:0] */
37#define M00235_CONTROL_BITMAP_ENABLE_OFST (0)
38#define M00235_CONTROL_BITMAP_ENABLE_MSK (0x1 << M00235_CONTROL_BITMAP_ENABLE_OFST)
39#define M00235_CONTROL_BITMAP_PACK_FORMAT_OFST (1)
40#define M00235_CONTROL_BITMAP_PACK_FORMAT_MSK (0x3 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST)
41#define M00235_CONTROL_BITMAP_ENDIAN_FORMAT_OFST (3)
42#define M00235_CONTROL_BITMAP_ENDIAN_FORMAT_MSK (0x1 << M00235_CONTROL_BITMAP_ENDIAN_FORMAT_OFST)
43
44#endif /*M00235_FDMA_PACKER_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cobalt/m00389_cvi_memmap_package.h b/drivers/media/pci/cobalt/m00389_cvi_memmap_package.h
new file mode 100644
index 000000000000..602419e589d3
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00389_cvi_memmap_package.h
@@ -0,0 +1,59 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00389_CVI_MEMMAP_PACKAGE_H
20#define M00389_CVI_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00389_CVI_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00389_cvi_regmap {
27 uint32_t control; /* Reg 0x0000, Default=0x0 */
28 uint32_t frame_width; /* Reg 0x0004, Default=0x10 */
29 uint32_t frame_height; /* Reg 0x0008, Default=0xc */
30 uint32_t freewheel_period; /* Reg 0x000c, Default=0x0 */
31 uint32_t error_color; /* Reg 0x0010, Default=0x0 */
32 uint32_t status; /* Reg 0x0014 */
33};
34
35#define M00389_CVI_REG_CONTROL_OFST 0
36#define M00389_CVI_REG_FRAME_WIDTH_OFST 4
37#define M00389_CVI_REG_FRAME_HEIGHT_OFST 8
38#define M00389_CVI_REG_FREEWHEEL_PERIOD_OFST 12
39#define M00389_CVI_REG_ERROR_COLOR_OFST 16
40#define M00389_CVI_REG_STATUS_OFST 20
41
42/*******************************************************************
43 * Bit Mask for register
44 * M00389_CVI_MEMMAP_PACKAGE_VHD_BITMAP
45 *******************************************************************/
46/* control [2:0] */
47#define M00389_CONTROL_BITMAP_ENABLE_OFST (0)
48#define M00389_CONTROL_BITMAP_ENABLE_MSK (0x1 << M00389_CONTROL_BITMAP_ENABLE_OFST)
49#define M00389_CONTROL_BITMAP_HSYNC_POLARITY_LOW_OFST (1)
50#define M00389_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK (0x1 << M00389_CONTROL_BITMAP_HSYNC_POLARITY_LOW_OFST)
51#define M00389_CONTROL_BITMAP_VSYNC_POLARITY_LOW_OFST (2)
52#define M00389_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK (0x1 << M00389_CONTROL_BITMAP_VSYNC_POLARITY_LOW_OFST)
53/* status [1:0] */
54#define M00389_STATUS_BITMAP_LOCK_OFST (0)
55#define M00389_STATUS_BITMAP_LOCK_MSK (0x1 << M00389_STATUS_BITMAP_LOCK_OFST)
56#define M00389_STATUS_BITMAP_ERROR_OFST (1)
57#define M00389_STATUS_BITMAP_ERROR_MSK (0x1 << M00389_STATUS_BITMAP_ERROR_OFST)
58
59#endif /*M00389_CVI_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cobalt/m00460_evcnt_memmap_package.h b/drivers/media/pci/cobalt/m00460_evcnt_memmap_package.h
new file mode 100644
index 000000000000..95471c995067
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00460_evcnt_memmap_package.h
@@ -0,0 +1,44 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00460_EVCNT_MEMMAP_PACKAGE_H
20#define M00460_EVCNT_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00460_EVCNT_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00460_evcnt_regmap {
27 uint32_t control; /* Reg 0x0000, Default=0x0 */
28 uint32_t count; /* Reg 0x0004 */
29};
30
31#define M00460_EVCNT_REG_CONTROL_OFST 0
32#define M00460_EVCNT_REG_COUNT_OFST 4
33
34/*******************************************************************
35 * Bit Mask for register
36 * M00460_EVCNT_MEMMAP_PACKAGE_VHD_BITMAP
37 *******************************************************************/
38/* control [1:0] */
39#define M00460_CONTROL_BITMAP_ENABLE_OFST (0)
40#define M00460_CONTROL_BITMAP_ENABLE_MSK (0x1 << M00460_CONTROL_BITMAP_ENABLE_OFST)
41#define M00460_CONTROL_BITMAP_CLEAR_OFST (1)
42#define M00460_CONTROL_BITMAP_CLEAR_MSK (0x1 << M00460_CONTROL_BITMAP_CLEAR_OFST)
43
44#endif /*M00460_EVCNT_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cobalt/m00473_freewheel_memmap_package.h b/drivers/media/pci/cobalt/m00473_freewheel_memmap_package.h
new file mode 100644
index 000000000000..384a3e156301
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00473_freewheel_memmap_package.h
@@ -0,0 +1,57 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00473_FREEWHEEL_MEMMAP_PACKAGE_H
20#define M00473_FREEWHEEL_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00473_FREEWHEEL_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00473_freewheel_regmap {
27 uint32_t ctrl; /* Reg 0x0000, Default=0x0 */
28 uint32_t status; /* Reg 0x0004 */
29 uint32_t active_length; /* Reg 0x0008, Default=0x1fa400 */
30 uint32_t total_length; /* Reg 0x000c, Default=0x31151b */
31 uint32_t data_width; /* Reg 0x0010 */
32 uint32_t output_color; /* Reg 0x0014, Default=0xffff */
33 uint32_t clk_freq; /* Reg 0x0018 */
34};
35
36#define M00473_FREEWHEEL_REG_CTRL_OFST 0
37#define M00473_FREEWHEEL_REG_STATUS_OFST 4
38#define M00473_FREEWHEEL_REG_ACTIVE_LENGTH_OFST 8
39#define M00473_FREEWHEEL_REG_TOTAL_LENGTH_OFST 12
40#define M00473_FREEWHEEL_REG_DATA_WIDTH_OFST 16
41#define M00473_FREEWHEEL_REG_OUTPUT_COLOR_OFST 20
42#define M00473_FREEWHEEL_REG_CLK_FREQ_OFST 24
43
44/*******************************************************************
45 * Bit Mask for register
46 * M00473_FREEWHEEL_MEMMAP_PACKAGE_VHD_BITMAP
47 *******************************************************************/
48/* ctrl [1:0] */
49#define M00473_CTRL_BITMAP_ENABLE_OFST (0)
50#define M00473_CTRL_BITMAP_ENABLE_MSK (0x1 << M00473_CTRL_BITMAP_ENABLE_OFST)
51#define M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_OFST (1)
52#define M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK (0x1 << M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_OFST)
53/* status [0:0] */
54#define M00473_STATUS_BITMAP_FREEWHEEL_MODE_OFST (0)
55#define M00473_STATUS_BITMAP_FREEWHEEL_MODE_MSK (0x1 << M00473_STATUS_BITMAP_FREEWHEEL_MODE_OFST)
56
57#endif /*M00473_FREEWHEEL_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cobalt/m00479_clk_loss_detector_memmap_package.h b/drivers/media/pci/cobalt/m00479_clk_loss_detector_memmap_package.h
new file mode 100644
index 000000000000..2a029026bf82
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00479_clk_loss_detector_memmap_package.h
@@ -0,0 +1,53 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00479_CLK_LOSS_DETECTOR_MEMMAP_PACKAGE_H
20#define M00479_CLK_LOSS_DETECTOR_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00479_CLK_LOSS_DETECTOR_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00479_clk_loss_detector_regmap {
27 /* Control module */
28 uint32_t ctrl; /* Reg 0x0000, Default=0x0 */
29 uint32_t status; /* Reg 0x0004 */
30 /* Number of ref clk cycles before checking the clock under test */
31 uint32_t ref_clk_cnt_val; /* Reg 0x0008, Default=0xc4 */
32 /* Number of test clk cycles required in the ref_clk_cnt_val period
33 * to ensure that the test clock is performing as expected */
34 uint32_t test_clk_cnt_val; /* Reg 0x000c, Default=0xa */
35};
36
37#define M00479_CLK_LOSS_DETECTOR_REG_CTRL_OFST 0
38#define M00479_CLK_LOSS_DETECTOR_REG_STATUS_OFST 4
39#define M00479_CLK_LOSS_DETECTOR_REG_REF_CLK_CNT_VAL_OFST 8
40#define M00479_CLK_LOSS_DETECTOR_REG_TEST_CLK_CNT_VAL_OFST 12
41
42/*******************************************************************
43 * Bit Mask for register
44 * M00479_CLK_LOSS_DETECTOR_MEMMAP_PACKAGE_VHD_BITMAP
45 *******************************************************************/
46/* ctrl [0:0] */
47#define M00479_CTRL_BITMAP_ENABLE_OFST (0)
48#define M00479_CTRL_BITMAP_ENABLE_MSK (0x1 << M00479_CTRL_BITMAP_ENABLE_OFST)
49/* status [0:0] */
50#define M00479_STATUS_BITMAP_CLOCK_MISSING_OFST (0)
51#define M00479_STATUS_BITMAP_CLOCK_MISSING_MSK (0x1 << M00479_STATUS_BITMAP_CLOCK_MISSING_OFST)
52
53#endif /*M00479_CLK_LOSS_DETECTOR_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cobalt/m00514_syncgen_flow_evcnt_memmap_package.h b/drivers/media/pci/cobalt/m00514_syncgen_flow_evcnt_memmap_package.h
new file mode 100644
index 000000000000..bdef2df5d689
--- /dev/null
+++ b/drivers/media/pci/cobalt/m00514_syncgen_flow_evcnt_memmap_package.h
@@ -0,0 +1,88 @@
1/*
2 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
3 * All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18
19#ifndef M00514_SYNCGEN_FLOW_EVCNT_MEMMAP_PACKAGE_H
20#define M00514_SYNCGEN_FLOW_EVCNT_MEMMAP_PACKAGE_H
21
22/*******************************************************************
23 * Register Block
24 * M00514_SYNCGEN_FLOW_EVCNT_MEMMAP_PACKAGE_VHD_REGMAP
25 *******************************************************************/
26struct m00514_syncgen_flow_evcnt_regmap {
27 uint32_t control; /* Reg 0x0000, Default=0x0 */
28 uint32_t sync_generator_h_sync_length; /* Reg 0x0004, Default=0x0 */
29 uint32_t sync_generator_h_backporch_length; /* Reg 0x0008, Default=0x0 */
30 uint32_t sync_generator_h_active_length; /* Reg 0x000c, Default=0x0 */
31 uint32_t sync_generator_h_frontporch_length; /* Reg 0x0010, Default=0x0 */
32 uint32_t sync_generator_v_sync_length; /* Reg 0x0014, Default=0x0 */
33 uint32_t sync_generator_v_backporch_length; /* Reg 0x0018, Default=0x0 */
34 uint32_t sync_generator_v_active_length; /* Reg 0x001c, Default=0x0 */
35 uint32_t sync_generator_v_frontporch_length; /* Reg 0x0020, Default=0x0 */
36 uint32_t error_color; /* Reg 0x0024, Default=0x0 */
37 uint32_t rd_status; /* Reg 0x0028 */
38 uint32_t rd_evcnt_count; /* Reg 0x002c */
39};
40
41#define M00514_SYNCGEN_FLOW_EVCNT_REG_CONTROL_OFST 0
42#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_H_SYNC_LENGTH_OFST 4
43#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_H_BACKPORCH_LENGTH_OFST 8
44#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_H_ACTIVE_LENGTH_OFST 12
45#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_H_FRONTPORCH_LENGTH_OFST 16
46#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_V_SYNC_LENGTH_OFST 20
47#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_V_BACKPORCH_LENGTH_OFST 24
48#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_V_ACTIVE_LENGTH_OFST 28
49#define M00514_SYNCGEN_FLOW_EVCNT_REG_SYNC_GENERATOR_V_FRONTPORCH_LENGTH_OFST 32
50#define M00514_SYNCGEN_FLOW_EVCNT_REG_ERROR_COLOR_OFST 36
51#define M00514_SYNCGEN_FLOW_EVCNT_REG_RD_STATUS_OFST 40
52#define M00514_SYNCGEN_FLOW_EVCNT_REG_RD_EVCNT_COUNT_OFST 44
53
54/*******************************************************************
55 * Bit Mask for register
56 * M00514_SYNCGEN_FLOW_EVCNT_MEMMAP_PACKAGE_VHD_BITMAP
57 *******************************************************************/
58/* control [7:0] */
59#define M00514_CONTROL_BITMAP_SYNC_GENERATOR_LOAD_PARAM_OFST (0)
60#define M00514_CONTROL_BITMAP_SYNC_GENERATOR_LOAD_PARAM_MSK (0x1 << M00514_CONTROL_BITMAP_SYNC_GENERATOR_LOAD_PARAM_OFST)
61#define M00514_CONTROL_BITMAP_SYNC_GENERATOR_ENABLE_OFST (1)
62#define M00514_CONTROL_BITMAP_SYNC_GENERATOR_ENABLE_MSK (0x1 << M00514_CONTROL_BITMAP_SYNC_GENERATOR_ENABLE_OFST)
63#define M00514_CONTROL_BITMAP_FLOW_CTRL_OUTPUT_ENABLE_OFST (2)
64#define M00514_CONTROL_BITMAP_FLOW_CTRL_OUTPUT_ENABLE_MSK (0x1 << M00514_CONTROL_BITMAP_FLOW_CTRL_OUTPUT_ENABLE_OFST)
65#define M00514_CONTROL_BITMAP_HSYNC_POLARITY_LOW_OFST (3)
66#define M00514_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK (0x1 << M00514_CONTROL_BITMAP_HSYNC_POLARITY_LOW_OFST)
67#define M00514_CONTROL_BITMAP_VSYNC_POLARITY_LOW_OFST (4)
68#define M00514_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK (0x1 << M00514_CONTROL_BITMAP_VSYNC_POLARITY_LOW_OFST)
69#define M00514_CONTROL_BITMAP_EVCNT_ENABLE_OFST (5)
70#define M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK (0x1 << M00514_CONTROL_BITMAP_EVCNT_ENABLE_OFST)
71#define M00514_CONTROL_BITMAP_EVCNT_CLEAR_OFST (6)
72#define M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK (0x1 << M00514_CONTROL_BITMAP_EVCNT_CLEAR_OFST)
73#define M00514_CONTROL_BITMAP_FORMAT_16_BPP_OFST (7)
74#define M00514_CONTROL_BITMAP_FORMAT_16_BPP_MSK (0x1 << M00514_CONTROL_BITMAP_FORMAT_16_BPP_OFST)
75/* error_color [23:0] */
76#define M00514_ERROR_COLOR_BITMAP_BLUE_OFST (0)
77#define M00514_ERROR_COLOR_BITMAP_BLUE_MSK (0xff << M00514_ERROR_COLOR_BITMAP_BLUE_OFST)
78#define M00514_ERROR_COLOR_BITMAP_GREEN_OFST (8)
79#define M00514_ERROR_COLOR_BITMAP_GREEN_MSK (0xff << M00514_ERROR_COLOR_BITMAP_GREEN_OFST)
80#define M00514_ERROR_COLOR_BITMAP_RED_OFST (16)
81#define M00514_ERROR_COLOR_BITMAP_RED_MSK (0xff << M00514_ERROR_COLOR_BITMAP_RED_OFST)
82/* rd_status [1:0] */
83#define M00514_RD_STATUS_BITMAP_FLOW_CTRL_NO_DATA_ERROR_OFST (0)
84#define M00514_RD_STATUS_BITMAP_FLOW_CTRL_NO_DATA_ERROR_MSK (0x1 << M00514_RD_STATUS_BITMAP_FLOW_CTRL_NO_DATA_ERROR_OFST)
85#define M00514_RD_STATUS_BITMAP_READY_BUFFER_FULL_OFST (1)
86#define M00514_RD_STATUS_BITMAP_READY_BUFFER_FULL_MSK (0x1 << M00514_RD_STATUS_BITMAP_READY_BUFFER_FULL_OFST)
87
88#endif /*M00514_SYNCGEN_FLOW_EVCNT_MEMMAP_PACKAGE_H*/
diff --git a/drivers/media/pci/cx18/cx18-av-core.c b/drivers/media/pci/cx18/cx18-av-core.c
index 5a55630d09db..30bbe8d1ea55 100644
--- a/drivers/media/pci/cx18/cx18-av-core.c
+++ b/drivers/media/pci/cx18/cx18-av-core.c
@@ -945,14 +945,17 @@ static int cx18_av_s_ctrl(struct v4l2_ctrl *ctrl)
945 return 0; 945 return 0;
946} 946}
947 947
948static int cx18_av_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt) 948static int cx18_av_set_fmt(struct v4l2_subdev *sd,
949 struct v4l2_subdev_pad_config *cfg,
950 struct v4l2_subdev_format *format)
949{ 951{
952 struct v4l2_mbus_framefmt *fmt = &format->format;
950 struct cx18_av_state *state = to_cx18_av_state(sd); 953 struct cx18_av_state *state = to_cx18_av_state(sd);
951 struct cx18 *cx = v4l2_get_subdevdata(sd); 954 struct cx18 *cx = v4l2_get_subdevdata(sd);
952 int HSC, VSC, Vsrc, Hsrc, filter, Vlines; 955 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
953 int is_50Hz = !(state->std & V4L2_STD_525_60); 956 int is_50Hz = !(state->std & V4L2_STD_525_60);
954 957
955 if (fmt->code != MEDIA_BUS_FMT_FIXED) 958 if (format->pad || fmt->code != MEDIA_BUS_FMT_FIXED)
956 return -EINVAL; 959 return -EINVAL;
957 960
958 fmt->field = V4L2_FIELD_INTERLACED; 961 fmt->field = V4L2_FIELD_INTERLACED;
@@ -987,6 +990,9 @@ static int cx18_av_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt
987 return -ERANGE; 990 return -ERANGE;
988 } 991 }
989 992
993 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
994 return 0;
995
990 HSC = (Hsrc * (1 << 20)) / fmt->width - (1 << 20); 996 HSC = (Hsrc * (1 << 20)) / fmt->width - (1 << 20);
991 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9)); 997 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
992 VSC &= 0x1fff; 998 VSC &= 0x1fff;
@@ -1285,7 +1291,6 @@ static const struct v4l2_subdev_video_ops cx18_av_video_ops = {
1285 .s_std = cx18_av_s_std, 1291 .s_std = cx18_av_s_std,
1286 .s_routing = cx18_av_s_video_routing, 1292 .s_routing = cx18_av_s_video_routing,
1287 .s_stream = cx18_av_s_stream, 1293 .s_stream = cx18_av_s_stream,
1288 .s_mbus_fmt = cx18_av_s_mbus_fmt,
1289}; 1294};
1290 1295
1291static const struct v4l2_subdev_vbi_ops cx18_av_vbi_ops = { 1296static const struct v4l2_subdev_vbi_ops cx18_av_vbi_ops = {
@@ -1295,12 +1300,17 @@ static const struct v4l2_subdev_vbi_ops cx18_av_vbi_ops = {
1295 .s_raw_fmt = cx18_av_s_raw_fmt, 1300 .s_raw_fmt = cx18_av_s_raw_fmt,
1296}; 1301};
1297 1302
1303static const struct v4l2_subdev_pad_ops cx18_av_pad_ops = {
1304 .set_fmt = cx18_av_set_fmt,
1305};
1306
1298static const struct v4l2_subdev_ops cx18_av_ops = { 1307static const struct v4l2_subdev_ops cx18_av_ops = {
1299 .core = &cx18_av_general_ops, 1308 .core = &cx18_av_general_ops,
1300 .tuner = &cx18_av_tuner_ops, 1309 .tuner = &cx18_av_tuner_ops,
1301 .audio = &cx18_av_audio_ops, 1310 .audio = &cx18_av_audio_ops,
1302 .video = &cx18_av_video_ops, 1311 .video = &cx18_av_video_ops,
1303 .vbi = &cx18_av_vbi_ops, 1312 .vbi = &cx18_av_vbi_ops,
1313 .pad = &cx18_av_pad_ops,
1304}; 1314};
1305 1315
1306int cx18_av_probe(struct cx18 *cx) 1316int cx18_av_probe(struct cx18 *cx)
diff --git a/drivers/media/pci/cx18/cx18-controls.c b/drivers/media/pci/cx18/cx18-controls.c
index 4aeb7c6b8ce1..71227a155cba 100644
--- a/drivers/media/pci/cx18/cx18-controls.c
+++ b/drivers/media/pci/cx18/cx18-controls.c
@@ -93,13 +93,16 @@ static int cx18_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
93{ 93{
94 struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl); 94 struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
95 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 95 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
96 struct v4l2_mbus_framefmt fmt; 96 struct v4l2_subdev_format format = {
97 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
98 };
99 struct v4l2_mbus_framefmt *fmt = &format.format;
97 100
98 /* fix videodecoder resolution */ 101 /* fix videodecoder resolution */
99 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1); 102 fmt->width = cxhdl->width / (is_mpeg1 ? 2 : 1);
100 fmt.height = cxhdl->height; 103 fmt->height = cxhdl->height;
101 fmt.code = MEDIA_BUS_FMT_FIXED; 104 fmt->code = MEDIA_BUS_FMT_FIXED;
102 v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &fmt); 105 v4l2_subdev_call(cx->sd_av, pad, set_fmt, NULL, &format);
103 return 0; 106 return 0;
104} 107}
105 108
diff --git a/drivers/media/pci/cx18/cx18-driver.c b/drivers/media/pci/cx18/cx18-driver.c
index 83f5074706f9..260e462d91b4 100644
--- a/drivers/media/pci/cx18/cx18-driver.c
+++ b/drivers/media/pci/cx18/cx18-driver.c
@@ -786,11 +786,11 @@ static void cx18_init_struct2(struct cx18 *cx)
786{ 786{
787 int i; 787 int i;
788 788
789 for (i = 0; i < CX18_CARD_MAX_VIDEO_INPUTS; i++) 789 for (i = 0; i < CX18_CARD_MAX_VIDEO_INPUTS - 1; i++)
790 if (cx->card->video_inputs[i].video_type == 0) 790 if (cx->card->video_inputs[i].video_type == 0)
791 break; 791 break;
792 cx->nof_inputs = i; 792 cx->nof_inputs = i;
793 for (i = 0; i < CX18_CARD_MAX_AUDIO_INPUTS; i++) 793 for (i = 0; i < CX18_CARD_MAX_AUDIO_INPUTS - 1; i++)
794 if (cx->card->audio_inputs[i].audio_type == 0) 794 if (cx->card->audio_inputs[i].audio_type == 0)
795 break; 795 break;
796 cx->nof_audio_inputs = i; 796 cx->nof_audio_inputs = i;
diff --git a/drivers/media/pci/cx18/cx18-ioctl.c b/drivers/media/pci/cx18/cx18-ioctl.c
index 79aee30d5fd8..55525af1f482 100644
--- a/drivers/media/pci/cx18/cx18-ioctl.c
+++ b/drivers/media/pci/cx18/cx18-ioctl.c
@@ -267,7 +267,9 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
267{ 267{
268 struct cx18_open_id *id = fh2id(fh); 268 struct cx18_open_id *id = fh2id(fh);
269 struct cx18 *cx = id->cx; 269 struct cx18 *cx = id->cx;
270 struct v4l2_mbus_framefmt mbus_fmt; 270 struct v4l2_subdev_format format = {
271 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
272 };
271 struct cx18_stream *s = &cx->streams[id->type]; 273 struct cx18_stream *s = &cx->streams[id->type];
272 int ret; 274 int ret;
273 int w, h; 275 int w, h;
@@ -296,10 +298,10 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
296 s->vb_bytes_per_line = 1440; /* Packed */ 298 s->vb_bytes_per_line = 1440; /* Packed */
297 } 299 }
298 300
299 mbus_fmt.width = cx->cxhdl.width = w; 301 format.format.width = cx->cxhdl.width = w;
300 mbus_fmt.height = cx->cxhdl.height = h; 302 format.format.height = cx->cxhdl.height = h;
301 mbus_fmt.code = MEDIA_BUS_FMT_FIXED; 303 format.format.code = MEDIA_BUS_FMT_FIXED;
302 v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &mbus_fmt); 304 v4l2_subdev_call(cx->sd_av, pad, set_fmt, NULL, &format);
303 return cx18_g_fmt_vid_cap(file, fh, fmt); 305 return cx18_g_fmt_vid_cap(file, fh, fmt);
304} 306}
305 307
diff --git a/drivers/media/pci/cx18/cx18-streams.c b/drivers/media/pci/cx18/cx18-streams.c
index c82d25d53341..c9860845264f 100644
--- a/drivers/media/pci/cx18/cx18-streams.c
+++ b/drivers/media/pci/cx18/cx18-streams.c
@@ -90,6 +90,7 @@ static struct {
90 "encoder PCM audio", 90 "encoder PCM audio",
91 VFL_TYPE_GRABBER, CX18_V4L2_ENC_PCM_OFFSET, 91 VFL_TYPE_GRABBER, CX18_V4L2_ENC_PCM_OFFSET,
92 PCI_DMA_FROMDEVICE, 92 PCI_DMA_FROMDEVICE,
93 V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
93 }, 94 },
94 { /* CX18_ENC_STREAM_TYPE_IDX */ 95 { /* CX18_ENC_STREAM_TYPE_IDX */
95 "encoder IDX", 96 "encoder IDX",
diff --git a/drivers/media/pci/cx23885/altera-ci.c b/drivers/media/pci/cx23885/altera-ci.c
index 0a91df2c9f08..aaf4e46ff3e9 100644
--- a/drivers/media/pci/cx23885/altera-ci.c
+++ b/drivers/media/pci/cx23885/altera-ci.c
@@ -759,7 +759,7 @@ int altera_ci_init(struct altera_ci_config *config, int ci_nr)
759 if (0 != ret) 759 if (0 != ret)
760 goto err; 760 goto err;
761 761
762 inter->state[ci_nr - 1] = state; 762 inter->state[ci_nr - 1] = state;
763 763
764 altera_hw_filt_init(config, ci_nr); 764 altera_hw_filt_init(config, ci_nr);
765 765
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 745caabe3397..6e8c24cdb2cd 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -572,7 +572,8 @@ static struct stb6100_config prof_8000_stb6100_config = {
572 .refclock = 27000000, 572 .refclock = 27000000,
573}; 573};
574 574
575static int p8000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 575static int p8000_set_voltage(struct dvb_frontend *fe,
576 enum fe_sec_voltage voltage)
576{ 577{
577 struct cx23885_tsport *port = fe->dvb->priv; 578 struct cx23885_tsport *port = fe->dvb->priv;
578 struct cx23885_dev *dev = port->dev; 579 struct cx23885_dev *dev = port->dev;
@@ -587,7 +588,7 @@ static int p8000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
587} 588}
588 589
589static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe, 590static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe,
590 fe_sec_voltage_t voltage) 591 enum fe_sec_voltage voltage)
591{ 592{
592 struct cx23885_tsport *port = fe->dvb->priv; 593 struct cx23885_tsport *port = fe->dvb->priv;
593 struct cx23885_dev *dev = port->dev; 594 struct cx23885_dev *dev = port->dev;
@@ -616,7 +617,7 @@ static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe,
616} 617}
617 618
618static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe, 619static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe,
619 fe_sec_voltage_t voltage) 620 enum fe_sec_voltage voltage)
620{ 621{
621 struct cx23885_tsport *port = fe->dvb->priv; 622 struct cx23885_tsport *port = fe->dvb->priv;
622 struct cx23885_dev *dev = port->dev; 623 struct cx23885_dev *dev = port->dev;
@@ -856,18 +857,12 @@ static struct mt2063_config terratec_mt2063_config[] = {
856 }, 857 },
857}; 858};
858 859
859static const struct tda10071_config hauppauge_tda10071_config = { 860static const struct tda10071_platform_data hauppauge_tda10071_pdata = {
860 .demod_i2c_addr = 0x05, 861 .clk = 40444000, /* 40.444 MHz */
861 .tuner_i2c_addr = 0x54,
862 .i2c_wr_max = 64, 862 .i2c_wr_max = 64,
863 .ts_mode = TDA10071_TS_SERIAL, 863 .ts_mode = TDA10071_TS_SERIAL,
864 .spec_inv = 0,
865 .xtal = 40444000, /* 40.444 MHz */
866 .pll_multiplier = 20, 864 .pll_multiplier = 20,
867}; 865 .tuner_i2c_addr = 0x54,
868
869static const struct a8293_config hauppauge_a8293_config = {
870 .i2c_addr = 0x0b,
871}; 866};
872 867
873static const struct si2165_config hauppauge_hvr4400_si2165_config = { 868static const struct si2165_config hauppauge_hvr4400_si2165_config = {
@@ -1190,8 +1185,10 @@ static int dvb_register(struct cx23885_tsport *port)
1190 struct i2c_board_info info; 1185 struct i2c_board_info info;
1191 struct i2c_adapter *adapter; 1186 struct i2c_adapter *adapter;
1192 struct i2c_client *client_demod = NULL, *client_tuner = NULL; 1187 struct i2c_client *client_demod = NULL, *client_tuner = NULL;
1188 struct i2c_client *client_sec = NULL;
1193 const struct m88ds3103_config *p_m88ds3103_config = NULL; 1189 const struct m88ds3103_config *p_m88ds3103_config = NULL;
1194 int (*p_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage) = NULL; 1190 int (*p_set_voltage)(struct dvb_frontend *fe,
1191 enum fe_sec_voltage voltage) = NULL;
1195 int mfe_shared = 0; /* bus not shared by default */ 1192 int mfe_shared = 0; /* bus not shared by default */
1196 int ret; 1193 int ret;
1197 1194
@@ -1797,21 +1794,46 @@ static int dvb_register(struct cx23885_tsport *port)
1797 1794
1798 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage; 1795 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
1799 break; 1796 break;
1800 case CX23885_BOARD_HAUPPAUGE_HVR4400: 1797 case CX23885_BOARD_HAUPPAUGE_HVR4400: {
1798 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1799 struct a8293_platform_data a8293_pdata = {};
1800
1801 i2c_bus = &dev->i2c_bus[0]; 1801 i2c_bus = &dev->i2c_bus[0];
1802 i2c_bus2 = &dev->i2c_bus[1]; 1802 i2c_bus2 = &dev->i2c_bus[1];
1803 switch (port->nr) { 1803 switch (port->nr) {
1804 /* port b */ 1804 /* port b */
1805 case 1: 1805 case 1:
1806 fe0->dvb.frontend = dvb_attach(tda10071_attach, 1806 /* attach demod + tuner combo */
1807 &hauppauge_tda10071_config, 1807 memset(&info, 0, sizeof(info));
1808 &i2c_bus->i2c_adap); 1808 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1809 if (fe0->dvb.frontend == NULL) 1809 info.addr = 0x05;
1810 break; 1810 info.platform_data = &tda10071_pdata;
1811 if (!dvb_attach(a8293_attach, fe0->dvb.frontend, 1811 request_module("tda10071");
1812 &i2c_bus->i2c_adap, 1812 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1813 &hauppauge_a8293_config)) 1813 if (!client_demod || !client_demod->dev.driver)
1814 goto frontend_detach;
1815 if (!try_module_get(client_demod->dev.driver->owner)) {
1816 i2c_unregister_device(client_demod);
1817 goto frontend_detach;
1818 }
1819 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1820 port->i2c_client_demod = client_demod;
1821
1822 /* attach SEC */
1823 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1824 memset(&info, 0, sizeof(info));
1825 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1826 info.addr = 0x0b;
1827 info.platform_data = &a8293_pdata;
1828 request_module("a8293");
1829 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1830 if (!client_sec || !client_sec->dev.driver)
1831 goto frontend_detach;
1832 if (!try_module_get(client_sec->dev.driver->owner)) {
1833 i2c_unregister_device(client_sec);
1814 goto frontend_detach; 1834 goto frontend_detach;
1835 }
1836 port->i2c_client_sec = client_sec;
1815 break; 1837 break;
1816 /* port c */ 1838 /* port c */
1817 case 2: 1839 case 2:
@@ -1829,17 +1851,46 @@ static int dvb_register(struct cx23885_tsport *port)
1829 break; 1851 break;
1830 } 1852 }
1831 break; 1853 break;
1832 case CX23885_BOARD_HAUPPAUGE_STARBURST: 1854 }
1855 case CX23885_BOARD_HAUPPAUGE_STARBURST: {
1856 struct tda10071_platform_data tda10071_pdata = hauppauge_tda10071_pdata;
1857 struct a8293_platform_data a8293_pdata = {};
1858
1833 i2c_bus = &dev->i2c_bus[0]; 1859 i2c_bus = &dev->i2c_bus[0];
1834 fe0->dvb.frontend = dvb_attach(tda10071_attach, 1860
1835 &hauppauge_tda10071_config, 1861 /* attach demod + tuner combo */
1836 &i2c_bus->i2c_adap); 1862 memset(&info, 0, sizeof(info));
1837 if (fe0->dvb.frontend != NULL) { 1863 strlcpy(info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1838 dvb_attach(a8293_attach, fe0->dvb.frontend, 1864 info.addr = 0x05;
1839 &i2c_bus->i2c_adap, 1865 info.platform_data = &tda10071_pdata;
1840 &hauppauge_a8293_config); 1866 request_module("tda10071");
1867 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1868 if (!client_demod || !client_demod->dev.driver)
1869 goto frontend_detach;
1870 if (!try_module_get(client_demod->dev.driver->owner)) {
1871 i2c_unregister_device(client_demod);
1872 goto frontend_detach;
1841 } 1873 }
1874 fe0->dvb.frontend = tda10071_pdata.get_dvb_frontend(client_demod);
1875 port->i2c_client_demod = client_demod;
1876
1877 /* attach SEC */
1878 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
1879 memset(&info, 0, sizeof(info));
1880 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
1881 info.addr = 0x0b;
1882 info.platform_data = &a8293_pdata;
1883 request_module("a8293");
1884 client_sec = i2c_new_device(&i2c_bus->i2c_adap, &info);
1885 if (!client_sec || !client_sec->dev.driver)
1886 goto frontend_detach;
1887 if (!try_module_get(client_sec->dev.driver->owner)) {
1888 i2c_unregister_device(client_sec);
1889 goto frontend_detach;
1890 }
1891 port->i2c_client_sec = client_sec;
1842 break; 1892 break;
1893 }
1843 case CX23885_BOARD_DVBSKY_T9580: 1894 case CX23885_BOARD_DVBSKY_T9580:
1844 case CX23885_BOARD_DVBSKY_S950: 1895 case CX23885_BOARD_DVBSKY_S950:
1845 i2c_bus = &dev->i2c_bus[0]; 1896 i2c_bus = &dev->i2c_bus[0];
@@ -1857,6 +1908,7 @@ static int dvb_register(struct cx23885_tsport *port)
1857 /* attach tuner */ 1908 /* attach tuner */
1858 memset(&ts2020_config, 0, sizeof(ts2020_config)); 1909 memset(&ts2020_config, 0, sizeof(ts2020_config));
1859 ts2020_config.fe = fe0->dvb.frontend; 1910 ts2020_config.fe = fe0->dvb.frontend;
1911 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
1860 memset(&info, 0, sizeof(struct i2c_board_info)); 1912 memset(&info, 0, sizeof(struct i2c_board_info));
1861 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 1913 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
1862 info.addr = 0x60; 1914 info.addr = 0x60;
@@ -1912,6 +1964,7 @@ static int dvb_register(struct cx23885_tsport *port)
1912 /* attach tuner */ 1964 /* attach tuner */
1913 memset(&si2157_config, 0, sizeof(si2157_config)); 1965 memset(&si2157_config, 0, sizeof(si2157_config));
1914 si2157_config.fe = fe0->dvb.frontend; 1966 si2157_config.fe = fe0->dvb.frontend;
1967 si2157_config.if_port = 1;
1915 memset(&info, 0, sizeof(struct i2c_board_info)); 1968 memset(&info, 0, sizeof(struct i2c_board_info));
1916 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 1969 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1917 info.addr = 0x60; 1970 info.addr = 0x60;
@@ -1957,6 +2010,7 @@ static int dvb_register(struct cx23885_tsport *port)
1957 /* attach tuner */ 2010 /* attach tuner */
1958 memset(&si2157_config, 0, sizeof(si2157_config)); 2011 memset(&si2157_config, 0, sizeof(si2157_config));
1959 si2157_config.fe = fe0->dvb.frontend; 2012 si2157_config.fe = fe0->dvb.frontend;
2013 si2157_config.if_port = 1;
1960 memset(&info, 0, sizeof(struct i2c_board_info)); 2014 memset(&info, 0, sizeof(struct i2c_board_info));
1961 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2015 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1962 info.addr = 0x60; 2016 info.addr = 0x60;
@@ -1986,6 +2040,7 @@ static int dvb_register(struct cx23885_tsport *port)
1986 /* attach tuner */ 2040 /* attach tuner */
1987 memset(&ts2020_config, 0, sizeof(ts2020_config)); 2041 memset(&ts2020_config, 0, sizeof(ts2020_config));
1988 ts2020_config.fe = fe0->dvb.frontend; 2042 ts2020_config.fe = fe0->dvb.frontend;
2043 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
1989 memset(&info, 0, sizeof(struct i2c_board_info)); 2044 memset(&info, 0, sizeof(struct i2c_board_info));
1990 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 2045 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
1991 info.addr = 0x60; 2046 info.addr = 0x60;
@@ -2031,6 +2086,7 @@ static int dvb_register(struct cx23885_tsport *port)
2031 /* attach tuner */ 2086 /* attach tuner */
2032 memset(&ts2020_config, 0, sizeof(ts2020_config)); 2087 memset(&ts2020_config, 0, sizeof(ts2020_config));
2033 ts2020_config.fe = fe0->dvb.frontend; 2088 ts2020_config.fe = fe0->dvb.frontend;
2089 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
2034 memset(&info, 0, sizeof(struct i2c_board_info)); 2090 memset(&info, 0, sizeof(struct i2c_board_info));
2035 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 2091 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
2036 info.addr = 0x60; 2092 info.addr = 0x60;
@@ -2093,6 +2149,7 @@ static int dvb_register(struct cx23885_tsport *port)
2093 /* attach tuner */ 2149 /* attach tuner */
2094 memset(&si2157_config, 0, sizeof(si2157_config)); 2150 memset(&si2157_config, 0, sizeof(si2157_config));
2095 si2157_config.fe = fe0->dvb.frontend; 2151 si2157_config.fe = fe0->dvb.frontend;
2152 si2157_config.if_port = 1;
2096 memset(&info, 0, sizeof(struct i2c_board_info)); 2153 memset(&info, 0, sizeof(struct i2c_board_info));
2097 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2154 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2098 info.addr = 0x60; 2155 info.addr = 0x60;
@@ -2111,6 +2168,7 @@ static int dvb_register(struct cx23885_tsport *port)
2111 case CX23885_BOARD_HAUPPAUGE_HVR5525: 2168 case CX23885_BOARD_HAUPPAUGE_HVR5525:
2112 switch (port->nr) { 2169 switch (port->nr) {
2113 struct m88rs6000t_config m88rs6000t_config; 2170 struct m88rs6000t_config m88rs6000t_config;
2171 struct a8293_platform_data a8293_pdata = {};
2114 2172
2115 /* port b - satellite */ 2173 /* port b - satellite */
2116 case 1: 2174 case 1:
@@ -2122,10 +2180,20 @@ static int dvb_register(struct cx23885_tsport *port)
2122 break; 2180 break;
2123 2181
2124 /* attach SEC */ 2182 /* attach SEC */
2125 if (!dvb_attach(a8293_attach, fe0->dvb.frontend, 2183 a8293_pdata.dvb_frontend = fe0->dvb.frontend;
2126 &dev->i2c_bus[0].i2c_adap, 2184 memset(&info, 0, sizeof(info));
2127 &hauppauge_a8293_config)) 2185 strlcpy(info.type, "a8293", I2C_NAME_SIZE);
2186 info.addr = 0x0b;
2187 info.platform_data = &a8293_pdata;
2188 request_module("a8293");
2189 client_sec = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2190 if (!client_sec || !client_sec->dev.driver)
2191 goto frontend_detach;
2192 if (!try_module_get(client_sec->dev.driver->owner)) {
2193 i2c_unregister_device(client_sec);
2128 goto frontend_detach; 2194 goto frontend_detach;
2195 }
2196 port->i2c_client_sec = client_sec;
2129 2197
2130 /* attach tuner */ 2198 /* attach tuner */
2131 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config)); 2199 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
@@ -2172,6 +2240,7 @@ static int dvb_register(struct cx23885_tsport *port)
2172 /* attach tuner */ 2240 /* attach tuner */
2173 memset(&si2157_config, 0, sizeof(si2157_config)); 2241 memset(&si2157_config, 0, sizeof(si2157_config));
2174 si2157_config.fe = fe0->dvb.frontend; 2242 si2157_config.fe = fe0->dvb.frontend;
2243 si2157_config.if_port = 1;
2175 memset(&info, 0, sizeof(struct i2c_board_info)); 2244 memset(&info, 0, sizeof(struct i2c_board_info));
2176 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 2245 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2177 info.addr = 0x60; 2246 info.addr = 0x60;
@@ -2238,6 +2307,14 @@ static int dvb_register(struct cx23885_tsport *port)
2238 return 0; 2307 return 0;
2239 2308
2240frontend_detach: 2309frontend_detach:
2310 /* remove I2C client for SEC */
2311 client_sec = port->i2c_client_sec;
2312 if (client_sec) {
2313 module_put(client_sec->dev.driver->owner);
2314 i2c_unregister_device(client_sec);
2315 port->i2c_client_sec = NULL;
2316 }
2317
2241 /* remove I2C client for tuner */ 2318 /* remove I2C client for tuner */
2242 client_tuner = port->i2c_client_tuner; 2319 client_tuner = port->i2c_client_tuner;
2243 if (client_tuner) { 2320 if (client_tuner) {
@@ -2339,6 +2416,13 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
2339 i2c_unregister_device(client); 2416 i2c_unregister_device(client);
2340 } 2417 }
2341 2418
2419 /* remove I2C client for SEC */
2420 client = port->i2c_client_sec;
2421 if (client) {
2422 module_put(client->dev.driver->owner);
2423 i2c_unregister_device(client);
2424 }
2425
2342 /* remove I2C client for tuner */ 2426 /* remove I2C client for tuner */
2343 client = port->i2c_client_tuner; 2427 client = port->i2c_client_tuner;
2344 if (client) { 2428 if (client) {
diff --git a/drivers/media/pci/cx23885/cx23885-f300.c b/drivers/media/pci/cx23885/cx23885-f300.c
index 6f817d8732da..a6c45eb0a105 100644
--- a/drivers/media/pci/cx23885/cx23885-f300.c
+++ b/drivers/media/pci/cx23885/cx23885-f300.c
@@ -144,7 +144,7 @@ static u8 f300_xfer(struct dvb_frontend *fe, u8 *buf)
144 return ret; 144 return ret;
145} 145}
146 146
147int f300_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 147int f300_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
148{ 148{
149 u8 buf[16]; 149 u8 buf[16];
150 150
diff --git a/drivers/media/pci/cx23885/cx23885-f300.h b/drivers/media/pci/cx23885/cx23885-f300.h
index e73344c94963..be14d7de7cd8 100644
--- a/drivers/media/pci/cx23885/cx23885-f300.h
+++ b/drivers/media/pci/cx23885/cx23885-f300.h
@@ -1,2 +1,2 @@
1extern int f300_set_voltage(struct dvb_frontend *fe, 1extern int f300_set_voltage(struct dvb_frontend *fe,
2 fe_sec_voltage_t voltage); 2 enum fe_sec_voltage voltage);
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index 2232b389c441..ec76470d12a4 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -581,7 +581,9 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
581 struct v4l2_format *f) 581 struct v4l2_format *f)
582{ 582{
583 struct cx23885_dev *dev = video_drvdata(file); 583 struct cx23885_dev *dev = video_drvdata(file);
584 struct v4l2_mbus_framefmt mbus_fmt; 584 struct v4l2_subdev_format format = {
585 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
586 };
585 int err; 587 int err;
586 588
587 dprintk(2, "%s()\n", __func__); 589 dprintk(2, "%s()\n", __func__);
@@ -600,10 +602,10 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
600 dev->field = f->fmt.pix.field; 602 dev->field = f->fmt.pix.field;
601 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, 603 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
602 dev->width, dev->height, dev->field); 604 dev->width, dev->height, dev->field);
603 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); 605 v4l2_fill_mbus_format(&format.format, &f->fmt.pix, MEDIA_BUS_FMT_FIXED);
604 call_all(dev, video, s_mbus_fmt, &mbus_fmt); 606 call_all(dev, pad, set_fmt, NULL, &format);
605 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); 607 v4l2_fill_pix_format(&f->fmt.pix, &format.format);
606 /* s_mbus_fmt overwrites f->fmt.pix.field, restore it */ 608 /* set_fmt overwrites f->fmt.pix.field, restore it */
607 f->fmt.pix.field = dev->field; 609 f->fmt.pix.field = dev->field;
608 return 0; 610 return 0;
609} 611}
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index aeda8d3990ae..027ead438194 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -304,11 +304,12 @@ struct cx23885_tsport {
304 304
305 struct i2c_client *i2c_client_demod; 305 struct i2c_client *i2c_client_demod;
306 struct i2c_client *i2c_client_tuner; 306 struct i2c_client *i2c_client_tuner;
307 struct i2c_client *i2c_client_sec;
307 struct i2c_client *i2c_client_ci; 308 struct i2c_client *i2c_client_ci;
308 309
309 int (*set_frontend)(struct dvb_frontend *fe); 310 int (*set_frontend)(struct dvb_frontend *fe);
310 int (*fe_set_voltage)(struct dvb_frontend *fe, 311 int (*fe_set_voltage)(struct dvb_frontend *fe,
311 fe_sec_voltage_t voltage); 312 enum fe_sec_voltage voltage);
312}; 313};
313 314
314struct cx23885_kernel_ir { 315struct cx23885_kernel_ir {
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index 3501be9f19d8..aab7cf4c9825 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -519,6 +519,8 @@ void cx88_wakeup(struct cx88_core *core,
519 buf = list_entry(q->active.next, 519 buf = list_entry(q->active.next,
520 struct cx88_buffer, list); 520 struct cx88_buffer, list);
521 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp); 521 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
522 buf->vb.v4l2_buf.field = core->field;
523 buf->vb.v4l2_buf.sequence = q->count++;
522 list_del(&buf->list); 524 list_del(&buf->list);
523 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); 525 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
524} 526}
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index 1b2ed238cdb6..9dfa5ee32a8f 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -449,7 +449,7 @@ static int cx24123_set_ts_param(struct dvb_frontend* fe,
449} 449}
450 450
451static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe, 451static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
452 fe_sec_voltage_t voltage) 452 enum fe_sec_voltage voltage)
453{ 453{
454 struct cx8802_dev *dev= fe->dvb->priv; 454 struct cx8802_dev *dev= fe->dvb->priv;
455 struct cx88_core *core = dev->core; 455 struct cx88_core *core = dev->core;
@@ -465,7 +465,7 @@ static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
465} 465}
466 466
467static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe, 467static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
468 fe_sec_voltage_t voltage) 468 enum fe_sec_voltage voltage)
469{ 469{
470 struct cx8802_dev *dev= fe->dvb->priv; 470 struct cx8802_dev *dev= fe->dvb->priv;
471 struct cx88_core *core = dev->core; 471 struct cx88_core *core = dev->core;
@@ -481,7 +481,7 @@ static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
481} 481}
482 482
483static int tevii_dvbs_set_voltage(struct dvb_frontend *fe, 483static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
484 fe_sec_voltage_t voltage) 484 enum fe_sec_voltage voltage)
485{ 485{
486 struct cx8802_dev *dev= fe->dvb->priv; 486 struct cx8802_dev *dev= fe->dvb->priv;
487 struct cx88_core *core = dev->core; 487 struct cx88_core *core = dev->core;
@@ -505,7 +505,7 @@ static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
505} 505}
506 506
507static int vp1027_set_voltage(struct dvb_frontend *fe, 507static int vp1027_set_voltage(struct dvb_frontend *fe,
508 fe_sec_voltage_t voltage) 508 enum fe_sec_voltage voltage)
509{ 509{
510 struct cx8802_dev *dev = fe->dvb->priv; 510 struct cx8802_dev *dev = fe->dvb->priv;
511 struct cx88_core *core = dev->core; 511 struct cx88_core *core = dev->core;
@@ -897,7 +897,7 @@ static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe)
897} 897}
898 898
899static int samsung_smt_7020_set_tone(struct dvb_frontend *fe, 899static int samsung_smt_7020_set_tone(struct dvb_frontend *fe,
900 fe_sec_tone_mode_t tone) 900 enum fe_sec_tone_mode tone)
901{ 901{
902 struct cx8802_dev *dev = fe->dvb->priv; 902 struct cx8802_dev *dev = fe->dvb->priv;
903 struct cx88_core *core = dev->core; 903 struct cx88_core *core = dev->core;
@@ -919,7 +919,7 @@ static int samsung_smt_7020_set_tone(struct dvb_frontend *fe,
919} 919}
920 920
921static int samsung_smt_7020_set_voltage(struct dvb_frontend *fe, 921static int samsung_smt_7020_set_voltage(struct dvb_frontend *fe,
922 fe_sec_voltage_t voltage) 922 enum fe_sec_voltage voltage)
923{ 923{
924 struct cx8802_dev *dev = fe->dvb->priv; 924 struct cx8802_dev *dev = fe->dvb->priv;
925 struct cx88_core *core = dev->core; 925 struct cx88_core *core = dev->core;
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index 98344540c51f..34f505744477 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -173,7 +173,7 @@ int cx8802_start_dma(struct cx8802_dev *dev,
173 173
174 /* reset counter */ 174 /* reset counter */
175 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET); 175 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET);
176 q->count = 1; 176 q->count = 0;
177 177
178 /* enable irqs */ 178 /* enable irqs */
179 dprintk( 1, "setting the interrupt mask\n" ); 179 dprintk( 1, "setting the interrupt mask\n" );
@@ -216,8 +216,6 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
216 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 216 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
217 buf, buf->vb.v4l2_buf.index); 217 buf, buf->vb.v4l2_buf.index);
218 cx8802_start_dma(dev, q, buf); 218 cx8802_start_dma(dev, q, buf);
219 list_for_each_entry(buf, &q->active, list)
220 buf->count = q->count++;
221 return 0; 219 return 0;
222} 220}
223 221
@@ -260,7 +258,6 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
260 if (list_empty(&cx88q->active)) { 258 if (list_empty(&cx88q->active)) {
261 dprintk( 1, "queue is empty - first active\n" ); 259 dprintk( 1, "queue is empty - first active\n" );
262 list_add_tail(&buf->list, &cx88q->active); 260 list_add_tail(&buf->list, &cx88q->active);
263 buf->count = cx88q->count++;
264 dprintk(1,"[%p/%d] %s - first active\n", 261 dprintk(1,"[%p/%d] %s - first active\n",
265 buf, buf->vb.v4l2_buf.index, __func__); 262 buf, buf->vb.v4l2_buf.index, __func__);
266 263
@@ -269,7 +266,6 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
269 dprintk( 1, "queue is not empty - append to active\n" ); 266 dprintk( 1, "queue is not empty - append to active\n" );
270 prev = list_entry(cx88q->active.prev, struct cx88_buffer, list); 267 prev = list_entry(cx88q->active.prev, struct cx88_buffer, list);
271 list_add_tail(&buf->list, &cx88q->active); 268 list_add_tail(&buf->list, &cx88q->active);
272 buf->count = cx88q->count++;
273 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 269 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
274 dprintk( 1, "[%p/%d] %s - append to active\n", 270 dprintk( 1, "[%p/%d] %s - append to active\n",
275 buf, buf->vb.v4l2_buf.index, __func__); 271 buf, buf->vb.v4l2_buf.index, __func__);
diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c
index 32eb7fdb875e..7510e80eb2ff 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -59,7 +59,7 @@ static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
59 59
60 /* reset counter */ 60 /* reset counter */
61 cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET); 61 cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET);
62 q->count = 1; 62 q->count = 0;
63 63
64 /* enable irqs */ 64 /* enable irqs */
65 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT); 65 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
@@ -102,8 +102,6 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
102 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 102 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
103 buf, buf->vb.v4l2_buf.index); 103 buf, buf->vb.v4l2_buf.index);
104 cx8800_start_vbi_dma(dev, q, buf); 104 cx8800_start_vbi_dma(dev, q, buf);
105 list_for_each_entry(buf, &q->active, list)
106 buf->count = q->count++;
107 return 0; 105 return 0;
108} 106}
109 107
@@ -175,7 +173,6 @@ static void buffer_queue(struct vb2_buffer *vb)
175 if (list_empty(&q->active)) { 173 if (list_empty(&q->active)) {
176 list_add_tail(&buf->list, &q->active); 174 list_add_tail(&buf->list, &q->active);
177 cx8800_start_vbi_dma(dev, q, buf); 175 cx8800_start_vbi_dma(dev, q, buf);
178 buf->count = q->count++;
179 dprintk(2,"[%p/%d] vbi_queue - first active\n", 176 dprintk(2,"[%p/%d] vbi_queue - first active\n",
180 buf, buf->vb.v4l2_buf.index); 177 buf, buf->vb.v4l2_buf.index);
181 178
@@ -183,7 +180,6 @@ static void buffer_queue(struct vb2_buffer *vb)
183 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); 180 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1);
184 prev = list_entry(q->active.prev, struct cx88_buffer, list); 181 prev = list_entry(q->active.prev, struct cx88_buffer, list);
185 list_add_tail(&buf->list, &q->active); 182 list_add_tail(&buf->list, &q->active);
186 buf->count = q->count++;
187 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 183 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
188 dprintk(2,"[%p/%d] buffer_queue - append to active\n", 184 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
189 buf, buf->vb.v4l2_buf.index); 185 buf, buf->vb.v4l2_buf.index);
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index c9decd80bf61..400e5caefd58 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -370,7 +370,7 @@ static int start_video_dma(struct cx8800_dev *dev,
370 370
371 /* reset counter */ 371 /* reset counter */
372 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET); 372 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET);
373 q->count = 1; 373 q->count = 0;
374 374
375 /* enable irqs */ 375 /* enable irqs */
376 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT); 376 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
@@ -410,7 +410,6 @@ static int stop_video_dma(struct cx8800_dev *dev)
410 cx_clear(MO_VID_INTMSK, 0x0f0011); 410 cx_clear(MO_VID_INTMSK, 0x0f0011);
411 return 0; 411 return 0;
412} 412}
413#endif
414 413
415static int restart_video_queue(struct cx8800_dev *dev, 414static int restart_video_queue(struct cx8800_dev *dev,
416 struct cx88_dmaqueue *q) 415 struct cx88_dmaqueue *q)
@@ -423,11 +422,10 @@ static int restart_video_queue(struct cx8800_dev *dev,
423 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 422 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
424 buf, buf->vb.v4l2_buf.index); 423 buf, buf->vb.v4l2_buf.index);
425 start_video_dma(dev, q, buf); 424 start_video_dma(dev, q, buf);
426 list_for_each_entry(buf, &q->active, list)
427 buf->count = q->count++;
428 } 425 }
429 return 0; 426 return 0;
430} 427}
428#endif
431 429
432/* ------------------------------------------------------------------ */ 430/* ------------------------------------------------------------------ */
433 431
@@ -523,7 +521,6 @@ static void buffer_queue(struct vb2_buffer *vb)
523 521
524 if (list_empty(&q->active)) { 522 if (list_empty(&q->active)) {
525 list_add_tail(&buf->list, &q->active); 523 list_add_tail(&buf->list, &q->active);
526 buf->count = q->count++;
527 dprintk(2,"[%p/%d] buffer_queue - first active\n", 524 dprintk(2,"[%p/%d] buffer_queue - first active\n",
528 buf, buf->vb.v4l2_buf.index); 525 buf, buf->vb.v4l2_buf.index);
529 526
@@ -531,7 +528,6 @@ static void buffer_queue(struct vb2_buffer *vb)
531 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); 528 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1);
532 prev = list_entry(q->active.prev, struct cx88_buffer, list); 529 prev = list_entry(q->active.prev, struct cx88_buffer, list);
533 list_add_tail(&buf->list, &q->active); 530 list_add_tail(&buf->list, &q->active);
534 buf->count = q->count++;
535 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 531 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
536 dprintk(2, "[%p/%d] buffer_queue - append to active\n", 532 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
537 buf, buf->vb.v4l2_buf.index); 533 buf, buf->vb.v4l2_buf.index);
@@ -771,6 +767,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
771 (f->fmt.pix.width * fmt->depth) >> 3; 767 (f->fmt.pix.width * fmt->depth) >> 3;
772 f->fmt.pix.sizeimage = 768 f->fmt.pix.sizeimage =
773 f->fmt.pix.height * f->fmt.pix.bytesperline; 769 f->fmt.pix.height * f->fmt.pix.bytesperline;
770 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
774 771
775 return 0; 772 return 0;
776} 773}
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index b9fe1ac24803..785fe2e0d702 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -327,7 +327,6 @@ struct cx88_buffer {
327 /* cx88 specific */ 327 /* cx88 specific */
328 unsigned int bpl; 328 unsigned int bpl;
329 struct cx88_riscmem risc; 329 struct cx88_riscmem risc;
330 u32 count;
331}; 330};
332 331
333struct cx88_dmaqueue { 332struct cx88_dmaqueue {
@@ -376,9 +375,10 @@ struct cx88_core {
376 375
377 /* config info -- dvb */ 376 /* config info -- dvb */
378#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB) 377#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
379 int (*prev_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 378 int (*prev_set_voltage)(struct dvb_frontend *fe,
379 enum fe_sec_voltage voltage);
380#endif 380#endif
381 void (*gate_ctrl)(struct cx88_core *core, int open); 381 void (*gate_ctrl)(struct cx88_core *core, int open);
382 382
383 /* state info */ 383 /* state info */
384 struct task_struct *kthread; 384 struct task_struct *kthread;
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 9e3492e20766..0ac2dd35fe50 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1630,7 +1630,8 @@ fail1:
1630 printk(KERN_ERR "fail1\n"); 1630 printk(KERN_ERR "fail1\n");
1631 if (dev->msi) 1631 if (dev->msi)
1632 pci_disable_msi(dev->pdev); 1632 pci_disable_msi(dev->pdev);
1633 free_irq(dev->pdev->irq, dev); 1633 if (stat == 0)
1634 free_irq(dev->pdev->irq, dev);
1634fail: 1635fail:
1635 printk(KERN_ERR "fail\n"); 1636 printk(KERN_ERR "fail\n");
1636 ddb_unmap(dev); 1637 ddb_unmap(dev);
diff --git a/drivers/media/pci/dm1105/dm1105.c b/drivers/media/pci/dm1105/dm1105.c
index ed11716731e9..88915fb87e80 100644
--- a/drivers/media/pci/dm1105/dm1105.c
+++ b/drivers/media/pci/dm1105/dm1105.c
@@ -591,7 +591,8 @@ static inline struct dm1105_dev *frontend_to_dm1105_dev(struct dvb_frontend *fe)
591 return container_of(fe->dvb, struct dm1105_dev, dvb_adapter); 591 return container_of(fe->dvb, struct dm1105_dev, dvb_adapter);
592} 592}
593 593
594static int dm1105_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 594static int dm1105_set_voltage(struct dvb_frontend *fe,
595 enum fe_sec_voltage voltage)
595{ 596{
596 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe); 597 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe);
597 598
diff --git a/drivers/media/pci/dt3155/Kconfig b/drivers/media/pci/dt3155/Kconfig
new file mode 100644
index 000000000000..5145e0dfa2aa
--- /dev/null
+++ b/drivers/media/pci/dt3155/Kconfig
@@ -0,0 +1,13 @@
1config VIDEO_DT3155
2 tristate "DT3155 frame grabber"
3 depends on PCI && VIDEO_DEV && VIDEO_V4L2
4 depends on HAS_DMA
5 select VIDEOBUF2_DMA_CONTIG
6 default n
7 ---help---
8 Enables dt3155 device driver for the DataTranslation DT3155 frame grabber.
9 Say Y here if you have this hardware.
10 In doubt, say N.
11
12 To compile this driver as a module, choose M here: the
13 module will be called dt3155.
diff --git a/drivers/media/pci/dt3155/Makefile b/drivers/media/pci/dt3155/Makefile
new file mode 100644
index 000000000000..89fa637ec54c
--- /dev/null
+++ b/drivers/media/pci/dt3155/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_VIDEO_DT3155) += dt3155.o
diff --git a/drivers/media/pci/dt3155/dt3155.c b/drivers/media/pci/dt3155/dt3155.c
new file mode 100644
index 000000000000..89d0dc705e4a
--- /dev/null
+++ b/drivers/media/pci/dt3155/dt3155.c
@@ -0,0 +1,632 @@
1/***************************************************************************
2 * Copyright (C) 2006-2010 by Marin Mitov *
3 * mitov@issp.bas.bg *
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 ***************************************************************************/
16
17#include <linux/module.h>
18#include <linux/version.h>
19#include <linux/stringify.h>
20#include <linux/delay.h>
21#include <linux/kthread.h>
22#include <linux/slab.h>
23#include <media/v4l2-dev.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-common.h>
26#include <media/videobuf2-dma-contig.h>
27
28#include "dt3155.h"
29
30#define DT3155_DEVICE_ID 0x1223
31
32/**
33 * read_i2c_reg - reads an internal i2c register
34 *
35 * @addr: dt3155 mmio base address
36 * @index: index (internal address) of register to read
37 * @data: pointer to byte the read data will be placed in
38 *
39 * returns: zero on success or error code
40 *
41 * This function starts reading the specified (by index) register
42 * and busy waits for the process to finish. The result is placed
43 * in a byte pointed by data.
44 */
45static int read_i2c_reg(void __iomem *addr, u8 index, u8 *data)
46{
47 u32 tmp = index;
48
49 iowrite32((tmp << 17) | IIC_READ, addr + IIC_CSR2);
50 mmiowb();
51 udelay(45); /* wait at least 43 usec for NEW_CYCLE to clear */
52 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
53 return -EIO; /* error: NEW_CYCLE not cleared */
54 tmp = ioread32(addr + IIC_CSR1);
55 if (tmp & DIRECT_ABORT) {
56 /* reset DIRECT_ABORT bit */
57 iowrite32(DIRECT_ABORT, addr + IIC_CSR1);
58 return -EIO; /* error: DIRECT_ABORT set */
59 }
60 *data = tmp >> 24;
61 return 0;
62}
63
64/**
65 * write_i2c_reg - writes to an internal i2c register
66 *
67 * @addr: dt3155 mmio base address
68 * @index: index (internal address) of register to read
69 * @data: data to be written
70 *
71 * returns: zero on success or error code
72 *
73 * This function starts writing the specified (by index) register
74 * and busy waits for the process to finish.
75 */
76static int write_i2c_reg(void __iomem *addr, u8 index, u8 data)
77{
78 u32 tmp = index;
79
80 iowrite32((tmp << 17) | IIC_WRITE | data, addr + IIC_CSR2);
81 mmiowb();
82 udelay(65); /* wait at least 63 usec for NEW_CYCLE to clear */
83 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
84 return -EIO; /* error: NEW_CYCLE not cleared */
85 if (ioread32(addr + IIC_CSR1) & DIRECT_ABORT) {
86 /* reset DIRECT_ABORT bit */
87 iowrite32(DIRECT_ABORT, addr + IIC_CSR1);
88 return -EIO; /* error: DIRECT_ABORT set */
89 }
90 return 0;
91}
92
93/**
94 * write_i2c_reg_nowait - writes to an internal i2c register
95 *
96 * @addr: dt3155 mmio base address
97 * @index: index (internal address) of register to read
98 * @data: data to be written
99 *
100 * This function starts writing the specified (by index) register
101 * and then returns.
102 */
103static void write_i2c_reg_nowait(void __iomem *addr, u8 index, u8 data)
104{
105 u32 tmp = index;
106
107 iowrite32((tmp << 17) | IIC_WRITE | data, addr + IIC_CSR2);
108 mmiowb();
109}
110
111/**
112 * wait_i2c_reg - waits the read/write to finish
113 *
114 * @addr: dt3155 mmio base address
115 *
116 * returns: zero on success or error code
117 *
118 * This function waits reading/writing to finish.
119 */
120static int wait_i2c_reg(void __iomem *addr)
121{
122 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
123 udelay(65); /* wait at least 63 usec for NEW_CYCLE to clear */
124 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
125 return -EIO; /* error: NEW_CYCLE not cleared */
126 if (ioread32(addr + IIC_CSR1) & DIRECT_ABORT) {
127 /* reset DIRECT_ABORT bit */
128 iowrite32(DIRECT_ABORT, addr + IIC_CSR1);
129 return -EIO; /* error: DIRECT_ABORT set */
130 }
131 return 0;
132}
133
134static int
135dt3155_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
136 unsigned int *nbuffers, unsigned int *num_planes,
137 unsigned int sizes[], void *alloc_ctxs[])
138
139{
140 struct dt3155_priv *pd = vb2_get_drv_priv(vq);
141 unsigned size = pd->width * pd->height;
142
143 if (vq->num_buffers + *nbuffers < 2)
144 *nbuffers = 2 - vq->num_buffers;
145 if (fmt && fmt->fmt.pix.sizeimage < size)
146 return -EINVAL;
147 *num_planes = 1;
148 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
149 alloc_ctxs[0] = pd->alloc_ctx;
150 return 0;
151}
152
153static int dt3155_buf_prepare(struct vb2_buffer *vb)
154{
155 struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue);
156
157 vb2_set_plane_payload(vb, 0, pd->width * pd->height);
158 return 0;
159}
160
161static int dt3155_start_streaming(struct vb2_queue *q, unsigned count)
162{
163 struct dt3155_priv *pd = vb2_get_drv_priv(q);
164 struct vb2_buffer *vb = pd->curr_buf;
165 dma_addr_t dma_addr;
166
167 pd->sequence = 0;
168 dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
169 iowrite32(dma_addr, pd->regs + EVEN_DMA_START);
170 iowrite32(dma_addr + pd->width, pd->regs + ODD_DMA_START);
171 iowrite32(pd->width, pd->regs + EVEN_DMA_STRIDE);
172 iowrite32(pd->width, pd->regs + ODD_DMA_STRIDE);
173 /* enable interrupts, clear all irq flags */
174 iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START |
175 FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR);
176 iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN |
177 FLD_DN_ODD | FLD_DN_EVEN | CAP_CONT_EVEN | CAP_CONT_ODD,
178 pd->regs + CSR1);
179 wait_i2c_reg(pd->regs);
180 write_i2c_reg(pd->regs, CONFIG, pd->config);
181 write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE);
182 write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_DONE);
183
184 /* start the board */
185 write_i2c_reg(pd->regs, CSR2, pd->csr2 | BUSY_EVEN | BUSY_ODD);
186 return 0;
187}
188
189static void dt3155_stop_streaming(struct vb2_queue *q)
190{
191 struct dt3155_priv *pd = vb2_get_drv_priv(q);
192 struct vb2_buffer *vb;
193
194 spin_lock_irq(&pd->lock);
195 /* stop the board */
196 write_i2c_reg_nowait(pd->regs, CSR2, pd->csr2);
197 iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN |
198 FLD_DN_ODD | FLD_DN_EVEN, pd->regs + CSR1);
199 /* disable interrupts, clear all irq flags */
200 iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR);
201 spin_unlock_irq(&pd->lock);
202
203 /*
204 * It is not clear whether the DMA stops at once or whether it
205 * will finish the current frame or field first. To be on the
206 * safe side we wait a bit.
207 */
208 msleep(45);
209
210 spin_lock_irq(&pd->lock);
211 if (pd->curr_buf) {
212 vb2_buffer_done(pd->curr_buf, VB2_BUF_STATE_ERROR);
213 pd->curr_buf = NULL;
214 }
215
216 while (!list_empty(&pd->dmaq)) {
217 vb = list_first_entry(&pd->dmaq, typeof(*vb), done_entry);
218 list_del(&vb->done_entry);
219 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
220 }
221 spin_unlock_irq(&pd->lock);
222}
223
224static void dt3155_buf_queue(struct vb2_buffer *vb)
225{
226 struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue);
227
228 /* pd->vidq.streaming = 1 when dt3155_buf_queue() is invoked */
229 spin_lock_irq(&pd->lock);
230 if (pd->curr_buf)
231 list_add_tail(&vb->done_entry, &pd->dmaq);
232 else
233 pd->curr_buf = vb;
234 spin_unlock_irq(&pd->lock);
235}
236
237static const struct vb2_ops q_ops = {
238 .queue_setup = dt3155_queue_setup,
239 .wait_prepare = vb2_ops_wait_prepare,
240 .wait_finish = vb2_ops_wait_finish,
241 .buf_prepare = dt3155_buf_prepare,
242 .start_streaming = dt3155_start_streaming,
243 .stop_streaming = dt3155_stop_streaming,
244 .buf_queue = dt3155_buf_queue,
245};
246
247static irqreturn_t dt3155_irq_handler_even(int irq, void *dev_id)
248{
249 struct dt3155_priv *ipd = dev_id;
250 struct vb2_buffer *ivb;
251 dma_addr_t dma_addr;
252 u32 tmp;
253
254 tmp = ioread32(ipd->regs + INT_CSR) & (FLD_START | FLD_END_ODD);
255 if (!tmp)
256 return IRQ_NONE; /* not our irq */
257 if ((tmp & FLD_START) && !(tmp & FLD_END_ODD)) {
258 iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START,
259 ipd->regs + INT_CSR);
260 return IRQ_HANDLED; /* start of field irq */
261 }
262 tmp = ioread32(ipd->regs + CSR1) & (FLD_CRPT_EVEN | FLD_CRPT_ODD);
263 if (tmp) {
264 iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN |
265 FLD_DN_ODD | FLD_DN_EVEN |
266 CAP_CONT_EVEN | CAP_CONT_ODD,
267 ipd->regs + CSR1);
268 mmiowb();
269 }
270
271 spin_lock(&ipd->lock);
272 if (ipd->curr_buf && !list_empty(&ipd->dmaq)) {
273 v4l2_get_timestamp(&ipd->curr_buf->v4l2_buf.timestamp);
274 ipd->curr_buf->v4l2_buf.sequence = ipd->sequence++;
275 ipd->curr_buf->v4l2_buf.field = V4L2_FIELD_NONE;
276 vb2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE);
277
278 ivb = list_first_entry(&ipd->dmaq, typeof(*ivb), done_entry);
279 list_del(&ivb->done_entry);
280 ipd->curr_buf = ivb;
281 dma_addr = vb2_dma_contig_plane_dma_addr(ivb, 0);
282 iowrite32(dma_addr, ipd->regs + EVEN_DMA_START);
283 iowrite32(dma_addr + ipd->width, ipd->regs + ODD_DMA_START);
284 iowrite32(ipd->width, ipd->regs + EVEN_DMA_STRIDE);
285 iowrite32(ipd->width, ipd->regs + ODD_DMA_STRIDE);
286 mmiowb();
287 }
288
289 /* enable interrupts, clear all irq flags */
290 iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START |
291 FLD_END_EVEN | FLD_END_ODD, ipd->regs + INT_CSR);
292 spin_unlock(&ipd->lock);
293 return IRQ_HANDLED;
294}
295
296static const struct v4l2_file_operations dt3155_fops = {
297 .owner = THIS_MODULE,
298 .open = v4l2_fh_open,
299 .release = vb2_fop_release,
300 .unlocked_ioctl = video_ioctl2,
301 .read = vb2_fop_read,
302 .mmap = vb2_fop_mmap,
303 .poll = vb2_fop_poll
304};
305
306static int dt3155_querycap(struct file *filp, void *p,
307 struct v4l2_capability *cap)
308{
309 struct dt3155_priv *pd = video_drvdata(filp);
310
311 strcpy(cap->driver, DT3155_NAME);
312 strcpy(cap->card, DT3155_NAME " frame grabber");
313 sprintf(cap->bus_info, "PCI:%s", pci_name(pd->pdev));
314 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
315 V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
316 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
317 return 0;
318}
319
320static int dt3155_enum_fmt_vid_cap(struct file *filp,
321 void *p, struct v4l2_fmtdesc *f)
322{
323 if (f->index)
324 return -EINVAL;
325 f->pixelformat = V4L2_PIX_FMT_GREY;
326 strcpy(f->description, "8-bit Greyscale");
327 return 0;
328}
329
330static int dt3155_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f)
331{
332 struct dt3155_priv *pd = video_drvdata(filp);
333
334 f->fmt.pix.width = pd->width;
335 f->fmt.pix.height = pd->height;
336 f->fmt.pix.pixelformat = V4L2_PIX_FMT_GREY;
337 f->fmt.pix.field = V4L2_FIELD_NONE;
338 f->fmt.pix.bytesperline = f->fmt.pix.width;
339 f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height;
340 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
341 return 0;
342}
343
344static int dt3155_g_std(struct file *filp, void *p, v4l2_std_id *norm)
345{
346 struct dt3155_priv *pd = video_drvdata(filp);
347
348 *norm = pd->std;
349 return 0;
350}
351
352static int dt3155_s_std(struct file *filp, void *p, v4l2_std_id norm)
353{
354 struct dt3155_priv *pd = video_drvdata(filp);
355
356 if (pd->std == norm)
357 return 0;
358 if (vb2_is_busy(&pd->vidq))
359 return -EBUSY;
360 pd->std = norm;
361 if (pd->std & V4L2_STD_525_60) {
362 pd->csr2 = VT_60HZ;
363 pd->width = 640;
364 pd->height = 480;
365 } else {
366 pd->csr2 = VT_50HZ;
367 pd->width = 768;
368 pd->height = 576;
369 }
370 return 0;
371}
372
373static int dt3155_enum_input(struct file *filp, void *p,
374 struct v4l2_input *input)
375{
376 if (input->index > 3)
377 return -EINVAL;
378 if (input->index)
379 snprintf(input->name, sizeof(input->name), "VID%d",
380 input->index);
381 else
382 strlcpy(input->name, "J2/VID0", sizeof(input->name));
383 input->type = V4L2_INPUT_TYPE_CAMERA;
384 input->std = V4L2_STD_ALL;
385 input->status = 0;
386 return 0;
387}
388
389static int dt3155_g_input(struct file *filp, void *p, unsigned int *i)
390{
391 struct dt3155_priv *pd = video_drvdata(filp);
392
393 *i = pd->input;
394 return 0;
395}
396
397static int dt3155_s_input(struct file *filp, void *p, unsigned int i)
398{
399 struct dt3155_priv *pd = video_drvdata(filp);
400
401 if (i > 3)
402 return -EINVAL;
403 pd->input = i;
404 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
405 write_i2c_reg(pd->regs, AD_CMD, (i << 6) | (i << 4) | SYNC_LVL_3);
406 return 0;
407}
408
409static const struct v4l2_ioctl_ops dt3155_ioctl_ops = {
410 .vidioc_querycap = dt3155_querycap,
411 .vidioc_enum_fmt_vid_cap = dt3155_enum_fmt_vid_cap,
412 .vidioc_try_fmt_vid_cap = dt3155_fmt_vid_cap,
413 .vidioc_g_fmt_vid_cap = dt3155_fmt_vid_cap,
414 .vidioc_s_fmt_vid_cap = dt3155_fmt_vid_cap,
415 .vidioc_reqbufs = vb2_ioctl_reqbufs,
416 .vidioc_create_bufs = vb2_ioctl_create_bufs,
417 .vidioc_querybuf = vb2_ioctl_querybuf,
418 .vidioc_expbuf = vb2_ioctl_expbuf,
419 .vidioc_qbuf = vb2_ioctl_qbuf,
420 .vidioc_dqbuf = vb2_ioctl_dqbuf,
421 .vidioc_streamon = vb2_ioctl_streamon,
422 .vidioc_streamoff = vb2_ioctl_streamoff,
423 .vidioc_g_std = dt3155_g_std,
424 .vidioc_s_std = dt3155_s_std,
425 .vidioc_enum_input = dt3155_enum_input,
426 .vidioc_g_input = dt3155_g_input,
427 .vidioc_s_input = dt3155_s_input,
428};
429
430static int dt3155_init_board(struct dt3155_priv *pd)
431{
432 struct pci_dev *pdev = pd->pdev;
433 int i;
434 u8 tmp = 0;
435
436 pci_set_master(pdev); /* dt3155 needs it */
437
438 /* resetting the adapter */
439 iowrite32(ADDR_ERR_ODD | ADDR_ERR_EVEN | FLD_CRPT_ODD | FLD_CRPT_EVEN |
440 FLD_DN_ODD | FLD_DN_EVEN, pd->regs + CSR1);
441 mmiowb();
442 msleep(20);
443
444 /* initializing adapter registers */
445 iowrite32(FIFO_EN | SRST, pd->regs + CSR1);
446 mmiowb();
447 iowrite32(0xEEEEEE01, pd->regs + EVEN_PIXEL_FMT);
448 iowrite32(0xEEEEEE01, pd->regs + ODD_PIXEL_FMT);
449 iowrite32(0x00000020, pd->regs + FIFO_TRIGER);
450 iowrite32(0x00000103, pd->regs + XFER_MODE);
451 iowrite32(0, pd->regs + RETRY_WAIT_CNT);
452 iowrite32(0, pd->regs + INT_CSR);
453 iowrite32(1, pd->regs + EVEN_FLD_MASK);
454 iowrite32(1, pd->regs + ODD_FLD_MASK);
455 iowrite32(0, pd->regs + MASK_LENGTH);
456 iowrite32(0x0005007C, pd->regs + FIFO_FLAG_CNT);
457 iowrite32(0x01010101, pd->regs + IIC_CLK_DUR);
458 mmiowb();
459
460 /* verifying that we have a DT3155 board (not just a SAA7116 chip) */
461 read_i2c_reg(pd->regs, DT_ID, &tmp);
462 if (tmp != DT3155_ID)
463 return -ENODEV;
464
465 /* initialize AD LUT */
466 write_i2c_reg(pd->regs, AD_ADDR, 0);
467 for (i = 0; i < 256; i++)
468 write_i2c_reg(pd->regs, AD_LUT, i);
469
470 /* initialize ADC references */
471 /* FIXME: pos_ref & neg_ref depend on VT_50HZ */
472 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
473 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3);
474 write_i2c_reg(pd->regs, AD_ADDR, AD_POS_REF);
475 write_i2c_reg(pd->regs, AD_CMD, 34);
476 write_i2c_reg(pd->regs, AD_ADDR, AD_NEG_REF);
477 write_i2c_reg(pd->regs, AD_CMD, 0);
478
479 /* initialize PM LUT */
480 write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM);
481 for (i = 0; i < 256; i++) {
482 write_i2c_reg(pd->regs, PM_LUT_ADDR, i);
483 write_i2c_reg(pd->regs, PM_LUT_DATA, i);
484 }
485 write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM | PM_LUT_SEL);
486 for (i = 0; i < 256; i++) {
487 write_i2c_reg(pd->regs, PM_LUT_ADDR, i);
488 write_i2c_reg(pd->regs, PM_LUT_DATA, i);
489 }
490 write_i2c_reg(pd->regs, CONFIG, pd->config); /* ACQ_MODE_EVEN */
491
492 /* select channel 1 for input and set sync level */
493 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
494 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3);
495
496 /* disable all irqs, clear all irq flags */
497 iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD,
498 pd->regs + INT_CSR);
499
500 return 0;
501}
502
503static struct video_device dt3155_vdev = {
504 .name = DT3155_NAME,
505 .fops = &dt3155_fops,
506 .ioctl_ops = &dt3155_ioctl_ops,
507 .minor = -1,
508 .release = video_device_release_empty,
509 .tvnorms = V4L2_STD_ALL,
510};
511
512static int dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id)
513{
514 int err;
515 struct dt3155_priv *pd;
516
517 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
518 if (err)
519 return -ENODEV;
520 pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL);
521 if (!pd)
522 return -ENOMEM;
523
524 err = v4l2_device_register(&pdev->dev, &pd->v4l2_dev);
525 if (err)
526 return err;
527 pd->vdev = dt3155_vdev;
528 pd->vdev.v4l2_dev = &pd->v4l2_dev;
529 video_set_drvdata(&pd->vdev, pd); /* for use in video_fops */
530 pd->pdev = pdev;
531 pd->std = V4L2_STD_625_50;
532 pd->csr2 = VT_50HZ;
533 pd->width = 768;
534 pd->height = 576;
535 INIT_LIST_HEAD(&pd->dmaq);
536 mutex_init(&pd->mux);
537 pd->vdev.lock = &pd->mux; /* for locking v4l2_file_operations */
538 pd->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
539 pd->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
540 pd->vidq.io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
541 pd->vidq.ops = &q_ops;
542 pd->vidq.mem_ops = &vb2_dma_contig_memops;
543 pd->vidq.drv_priv = pd;
544 pd->vidq.min_buffers_needed = 2;
545 pd->vidq.gfp_flags = GFP_DMA32;
546 pd->vidq.lock = &pd->mux; /* for locking v4l2_file_operations */
547 pd->vdev.queue = &pd->vidq;
548 err = vb2_queue_init(&pd->vidq);
549 if (err < 0)
550 goto err_v4l2_dev_unreg;
551 pd->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
552 if (IS_ERR(pd->alloc_ctx)) {
553 dev_err(&pdev->dev, "Can't allocate buffer context");
554 err = PTR_ERR(pd->alloc_ctx);
555 goto err_v4l2_dev_unreg;
556 }
557 spin_lock_init(&pd->lock);
558 pd->config = ACQ_MODE_EVEN;
559 err = pci_enable_device(pdev);
560 if (err)
561 goto err_free_ctx;
562 err = pci_request_region(pdev, 0, pci_name(pdev));
563 if (err)
564 goto err_pci_disable;
565 pd->regs = pci_iomap(pdev, 0, pci_resource_len(pd->pdev, 0));
566 if (!pd->regs) {
567 err = -ENOMEM;
568 goto err_free_reg;
569 }
570 err = dt3155_init_board(pd);
571 if (err)
572 goto err_iounmap;
573 err = request_irq(pd->pdev->irq, dt3155_irq_handler_even,
574 IRQF_SHARED, DT3155_NAME, pd);
575 if (err)
576 goto err_iounmap;
577 err = video_register_device(&pd->vdev, VFL_TYPE_GRABBER, -1);
578 if (err)
579 goto err_free_irq;
580 dev_info(&pdev->dev, "/dev/video%i is ready\n", pd->vdev.minor);
581 return 0; /* success */
582
583err_free_irq:
584 free_irq(pd->pdev->irq, pd);
585err_iounmap:
586 pci_iounmap(pdev, pd->regs);
587err_free_reg:
588 pci_release_region(pdev, 0);
589err_pci_disable:
590 pci_disable_device(pdev);
591err_free_ctx:
592 vb2_dma_contig_cleanup_ctx(pd->alloc_ctx);
593err_v4l2_dev_unreg:
594 v4l2_device_unregister(&pd->v4l2_dev);
595 return err;
596}
597
598static void dt3155_remove(struct pci_dev *pdev)
599{
600 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
601 struct dt3155_priv *pd = container_of(v4l2_dev, struct dt3155_priv,
602 v4l2_dev);
603
604 video_unregister_device(&pd->vdev);
605 free_irq(pd->pdev->irq, pd);
606 vb2_queue_release(&pd->vidq);
607 v4l2_device_unregister(&pd->v4l2_dev);
608 pci_iounmap(pdev, pd->regs);
609 pci_release_region(pdev, 0);
610 pci_disable_device(pdev);
611 vb2_dma_contig_cleanup_ctx(pd->alloc_ctx);
612}
613
614static const struct pci_device_id pci_ids[] = {
615 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, DT3155_DEVICE_ID) },
616 { 0, /* zero marks the end */ },
617};
618MODULE_DEVICE_TABLE(pci, pci_ids);
619
620static struct pci_driver pci_driver = {
621 .name = DT3155_NAME,
622 .id_table = pci_ids,
623 .probe = dt3155_probe,
624 .remove = dt3155_remove,
625};
626
627module_pci_driver(pci_driver);
628
629MODULE_DESCRIPTION("video4linux pci-driver for dt3155 frame grabber");
630MODULE_AUTHOR("Marin Mitov <mitov@issp.bas.bg>");
631MODULE_VERSION(DT3155_VERSION);
632MODULE_LICENSE("GPL");
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.h b/drivers/media/pci/dt3155/dt3155.h
index 96f01a0c7581..4e1f4d598d57 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.h
+++ b/drivers/media/pci/dt3155/dt3155.h
@@ -12,24 +12,20 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. * 13 * GNU General Public License for more details. *
14 * * 14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/ 15 ***************************************************************************/
20 16
21/* DT3155 header file */ 17/* DT3155 header file */
22#ifndef _DT3155_H_ 18#ifndef _DT3155_H_
23#define _DT3155_H_ 19#define _DT3155_H_
24 20
25#ifdef __KERNEL__
26
27#include <linux/pci.h> 21#include <linux/pci.h>
28#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <media/v4l2-device.h>
24#include <media/v4l2-dev.h>
29 25
30#define DT3155_NAME "dt3155" 26#define DT3155_NAME "dt3155"
31#define DT3155_VER_MAJ 1 27#define DT3155_VER_MAJ 2
32#define DT3155_VER_MIN 1 28#define DT3155_VER_MIN 0
33#define DT3155_VER_EXT 0 29#define DT3155_VER_EXT 0
34#define DT3155_VERSION __stringify(DT3155_VER_MAJ) "." \ 30#define DT3155_VERSION __stringify(DT3155_VER_MAJ) "." \
35 __stringify(DT3155_VER_MIN) "." \ 31 __stringify(DT3155_VER_MIN) "." \
@@ -78,7 +74,10 @@
78#define AD_NEG_REF 0x02 74#define AD_NEG_REF 0x02
79 75
80/* CSR1 bit masks */ 76/* CSR1 bit masks */
77#define RANGE_EN 0x00008000
81#define CRPT_DIS 0x00004000 78#define CRPT_DIS 0x00004000
79#define ADDR_ERR_ODD 0x00000800
80#define ADDR_ERR_EVEN 0x00000400
82#define FLD_CRPT_ODD 0x00000200 81#define FLD_CRPT_ODD 0x00000200
83#define FLD_CRPT_EVEN 0x00000100 82#define FLD_CRPT_EVEN 0x00000100
84#define FIFO_EN 0x00000080 83#define FIFO_EN 0x00000080
@@ -153,60 +152,45 @@
153/* DT3155 identificator */ 152/* DT3155 identificator */
154#define DT3155_ID 0x20 153#define DT3155_ID 0x20
155 154
156#ifdef CONFIG_DT3155_CCIR
157#define DMA_STRIDE 768
158#else
159#define DMA_STRIDE 640
160#endif
161
162/**
163 * struct dt3155_stats - statistics structure
164 *
165 * @free_bufs_empty: no free image buffers
166 * @corrupted_fields: corrupted fields
167 * @dma_map_failed: dma mapping failed
168 * @start_before_end: new started before old ended
169 */
170struct dt3155_stats {
171 int free_bufs_empty;
172 int corrupted_fields;
173 int dma_map_failed;
174 int start_before_end;
175};
176
177/* per board private data structure */ 155/* per board private data structure */
178/** 156/**
179 * struct dt3155_priv - private data structure 157 * struct dt3155_priv - private data structure
180 * 158 *
159 * @v4l2_dev: v4l2_device structure
181 * @vdev: video_device structure 160 * @vdev: video_device structure
182 * @pdev: pointer to pci_dev structure 161 * @pdev: pointer to pci_dev structure
183 * @q pointer to vb2_queue structure 162 * @vidq: vb2_queue structure
163 * @alloc_ctx: dma_contig allocation context
184 * @curr_buf: pointer to curren buffer 164 * @curr_buf: pointer to curren buffer
185 * @mux: mutex to protect the instance 165 * @mux: mutex to protect the instance
186 * @dmaq queue for dma buffers 166 * @dmaq: queue for dma buffers
187 * @lock spinlock for dma queue 167 * @lock: spinlock for dma queue
188 * @field_count fields counter 168 * @std: input standard
169 * @width: frame width
170 * @height: frame height
171 * @input: current input
172 * @sequence: frame counter
189 * @stats: statistics structure 173 * @stats: statistics structure
190 * @users open count
191 * @regs: local copy of mmio base register 174 * @regs: local copy of mmio base register
192 * @csr2: local copy of csr2 register 175 * @csr2: local copy of csr2 register
193 * @config: local copy of config register 176 * @config: local copy of config register
194 */ 177 */
195struct dt3155_priv { 178struct dt3155_priv {
179 struct v4l2_device v4l2_dev;
196 struct video_device vdev; 180 struct video_device vdev;
197 struct pci_dev *pdev; 181 struct pci_dev *pdev;
198 struct vb2_queue *q; 182 struct vb2_queue vidq;
183 struct vb2_alloc_ctx *alloc_ctx;
199 struct vb2_buffer *curr_buf; 184 struct vb2_buffer *curr_buf;
200 struct mutex mux; 185 struct mutex mux;
201 struct list_head dmaq; 186 struct list_head dmaq;
202 spinlock_t lock; 187 spinlock_t lock;
203 unsigned int field_count; 188 v4l2_std_id std;
204 struct dt3155_stats stats; 189 unsigned width, height;
190 unsigned input;
191 unsigned int sequence;
205 void __iomem *regs; 192 void __iomem *regs;
206 int users;
207 u8 csr2, config; 193 u8 csr2, config;
208}; 194};
209 195
210#endif /* __KERNEL__ */
211
212#endif /* _DT3155_H_ */ 196#endif /* _DT3155_H_ */
diff --git a/drivers/media/pci/ivtv/ivtv-controls.c b/drivers/media/pci/ivtv/ivtv-controls.c
index ccf548c255f1..8a55ccb8f0c9 100644
--- a/drivers/media/pci/ivtv/ivtv-controls.c
+++ b/drivers/media/pci/ivtv/ivtv-controls.c
@@ -64,13 +64,15 @@ static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
64{ 64{
65 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); 65 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
66 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 66 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
67 struct v4l2_mbus_framefmt fmt; 67 struct v4l2_subdev_format format = {
68 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
69 };
68 70
69 /* fix videodecoder resolution */ 71 /* fix videodecoder resolution */
70 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1); 72 format.format.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
71 fmt.height = cxhdl->height; 73 format.format.height = cxhdl->height;
72 fmt.code = MEDIA_BUS_FMT_FIXED; 74 format.format.code = MEDIA_BUS_FMT_FIXED;
73 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt); 75 v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format);
74 return 0; 76 return 0;
75} 77}
76 78
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index c2e60b4f292d..8616fa8193bc 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -805,11 +805,11 @@ static void ivtv_init_struct2(struct ivtv *itv)
805{ 805{
806 int i; 806 int i;
807 807
808 for (i = 0; i < IVTV_CARD_MAX_VIDEO_INPUTS; i++) 808 for (i = 0; i < IVTV_CARD_MAX_VIDEO_INPUTS - 1; i++)
809 if (itv->card->video_inputs[i].video_type == 0) 809 if (itv->card->video_inputs[i].video_type == 0)
810 break; 810 break;
811 itv->nof_inputs = i; 811 itv->nof_inputs = i;
812 for (i = 0; i < IVTV_CARD_MAX_AUDIO_INPUTS; i++) 812 for (i = 0; i < IVTV_CARD_MAX_AUDIO_INPUTS - 1; i++)
813 if (itv->card->audio_inputs[i].audio_type == 0) 813 if (itv->card->audio_inputs[i].audio_type == 0)
814 break; 814 break;
815 itv->nof_audio_inputs = i; 815 itv->nof_audio_inputs = i;
diff --git a/drivers/media/pci/ivtv/ivtv-driver.h b/drivers/media/pci/ivtv/ivtv-driver.h
index e8b6c7ad2ba9..ee0ef6e48c7d 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.h
+++ b/drivers/media/pci/ivtv/ivtv-driver.h
@@ -830,7 +830,8 @@ static inline int ivtv_raw_vbi(const struct ivtv *itv)
830 do { \ 830 do { \
831 struct v4l2_subdev *__sd; \ 831 struct v4l2_subdev *__sd; \
832 __v4l2_device_call_subdevs_p(&(itv)->v4l2_dev, __sd, \ 832 __v4l2_device_call_subdevs_p(&(itv)->v4l2_dev, __sd, \
833 !(hw) || (__sd->grp_id & (hw)), o, f , ##args); \ 833 !(hw) ? true : (__sd->grp_id & (hw)), \
834 o, f, ##args); \
834 } while (0) 835 } while (0)
835 836
836#define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args) 837#define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args)
diff --git a/drivers/media/pci/ivtv/ivtv-ioctl.c b/drivers/media/pci/ivtv/ivtv-ioctl.c
index 6fe6c4a0e858..9a21c17fc376 100644
--- a/drivers/media/pci/ivtv/ivtv-ioctl.c
+++ b/drivers/media/pci/ivtv/ivtv-ioctl.c
@@ -581,7 +581,9 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
581{ 581{
582 struct ivtv_open_id *id = fh2id(fh); 582 struct ivtv_open_id *id = fh2id(fh);
583 struct ivtv *itv = id->itv; 583 struct ivtv *itv = id->itv;
584 struct v4l2_mbus_framefmt mbus_fmt; 584 struct v4l2_subdev_format format = {
585 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
586 };
585 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt); 587 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
586 int w = fmt->fmt.pix.width; 588 int w = fmt->fmt.pix.width;
587 int h = fmt->fmt.pix.height; 589 int h = fmt->fmt.pix.height;
@@ -599,10 +601,10 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
599 itv->cxhdl.height = h; 601 itv->cxhdl.height = h;
600 if (v4l2_ctrl_g_ctrl(itv->cxhdl.video_encoding) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) 602 if (v4l2_ctrl_g_ctrl(itv->cxhdl.video_encoding) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
601 fmt->fmt.pix.width /= 2; 603 fmt->fmt.pix.width /= 2;
602 mbus_fmt.width = fmt->fmt.pix.width; 604 format.format.width = fmt->fmt.pix.width;
603 mbus_fmt.height = h; 605 format.format.height = h;
604 mbus_fmt.code = MEDIA_BUS_FMT_FIXED; 606 format.format.code = MEDIA_BUS_FMT_FIXED;
605 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &mbus_fmt); 607 v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format);
606 return ivtv_g_fmt_vid_cap(file, fh, fmt); 608 return ivtv_g_fmt_vid_cap(file, fh, fmt);
607} 609}
608 610
@@ -1529,7 +1531,8 @@ static int ivtv_log_status(struct file *file, void *fh)
1529 ivtv_get_audio_input(itv, itv->audio_input, &audin); 1531 ivtv_get_audio_input(itv, itv->audio_input, &audin);
1530 IVTV_INFO("Video Input: %s\n", vidin.name); 1532 IVTV_INFO("Video Input: %s\n", vidin.name);
1531 IVTV_INFO("Audio Input: %s%s\n", audin.name, 1533 IVTV_INFO("Audio Input: %s%s\n", audin.name,
1532 (itv->dualwatch_stereo_mode & ~0x300) == 0x200 ? " (Bilingual)" : ""); 1534 itv->dualwatch_stereo_mode == V4L2_MPEG_AUDIO_MODE_DUAL ?
1535 " (Bilingual)" : "");
1533 if (has_output) { 1536 if (has_output) {
1534 struct v4l2_output vidout; 1537 struct v4l2_output vidout;
1535 struct v4l2_audioout audout; 1538 struct v4l2_audioout audout;
diff --git a/drivers/media/pci/mantis/hopper_cards.c b/drivers/media/pci/mantis/hopper_cards.c
index 104914a5bf06..68b5800030b7 100644
--- a/drivers/media/pci/mantis/hopper_cards.c
+++ b/drivers/media/pci/mantis/hopper_cards.c
@@ -106,6 +106,10 @@ static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
106 } 106 }
107 if (stat & MANTIS_INT_IRQ1) { 107 if (stat & MANTIS_INT_IRQ1) {
108 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); 108 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
109 spin_lock(&mantis->intmask_lock);
110 mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1,
111 MANTIS_INT_MASK);
112 spin_unlock(&mantis->intmask_lock);
109 schedule_work(&mantis->uart_work); 113 schedule_work(&mantis->uart_work);
110 } 114 }
111 if (stat & MANTIS_INT_OCERR) { 115 if (stat & MANTIS_INT_OCERR) {
@@ -154,6 +158,7 @@ static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
154static int hopper_pci_probe(struct pci_dev *pdev, 158static int hopper_pci_probe(struct pci_dev *pdev,
155 const struct pci_device_id *pci_id) 159 const struct pci_device_id *pci_id)
156{ 160{
161 struct mantis_pci_drvdata *drvdata;
157 struct mantis_pci *mantis; 162 struct mantis_pci *mantis;
158 struct mantis_hwconfig *config; 163 struct mantis_hwconfig *config;
159 int err = 0; 164 int err = 0;
@@ -165,12 +170,16 @@ static int hopper_pci_probe(struct pci_dev *pdev,
165 goto fail0; 170 goto fail0;
166 } 171 }
167 172
173 drvdata = (void *)pci_id->driver_data;
168 mantis->num = devs; 174 mantis->num = devs;
169 mantis->verbose = verbose; 175 mantis->verbose = verbose;
170 mantis->pdev = pdev; 176 mantis->pdev = pdev;
171 config = (struct mantis_hwconfig *) pci_id->driver_data; 177 config = drvdata->hwconfig;
172 config->irq_handler = &hopper_irq_handler; 178 config->irq_handler = &hopper_irq_handler;
173 mantis->hwconfig = config; 179 mantis->hwconfig = config;
180 mantis->rc_map_name = drvdata->rc_map_name;
181
182 spin_lock_init(&mantis->intmask_lock);
174 183
175 err = mantis_pci_init(mantis); 184 err = mantis_pci_init(mantis);
176 if (err) { 185 if (err) {
@@ -247,7 +256,8 @@ static void hopper_pci_remove(struct pci_dev *pdev)
247} 256}
248 257
249static struct pci_device_id hopper_pci_table[] = { 258static struct pci_device_id hopper_pci_table[] = {
250 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config), 259 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config,
260 NULL),
251 { } 261 { }
252}; 262};
253 263
diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
index 801fc55b6167..cdefffc16d9e 100644
--- a/drivers/media/pci/mantis/mantis_cards.c
+++ b/drivers/media/pci/mantis/mantis_cards.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <asm/irq.h> 26#include <asm/irq.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <media/rc-map.h>
28 29
29#include "dmxdev.h" 30#include "dmxdev.h"
30#include "dvbdev.h" 31#include "dvbdev.h"
@@ -49,6 +50,7 @@
49#include "mantis_pci.h" 50#include "mantis_pci.h"
50#include "mantis_i2c.h" 51#include "mantis_i2c.h"
51#include "mantis_reg.h" 52#include "mantis_reg.h"
53#include "mantis_input.h"
52 54
53static unsigned int verbose; 55static unsigned int verbose;
54module_param(verbose, int, 0644); 56module_param(verbose, int, 0644);
@@ -114,6 +116,10 @@ static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
114 } 116 }
115 if (stat & MANTIS_INT_IRQ1) { 117 if (stat & MANTIS_INT_IRQ1) {
116 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); 118 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
119 spin_lock(&mantis->intmask_lock);
120 mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1,
121 MANTIS_INT_MASK);
122 spin_unlock(&mantis->intmask_lock);
117 schedule_work(&mantis->uart_work); 123 schedule_work(&mantis->uart_work);
118 } 124 }
119 if (stat & MANTIS_INT_OCERR) { 125 if (stat & MANTIS_INT_OCERR) {
@@ -162,6 +168,7 @@ static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
162static int mantis_pci_probe(struct pci_dev *pdev, 168static int mantis_pci_probe(struct pci_dev *pdev,
163 const struct pci_device_id *pci_id) 169 const struct pci_device_id *pci_id)
164{ 170{
171 struct mantis_pci_drvdata *drvdata;
165 struct mantis_pci *mantis; 172 struct mantis_pci *mantis;
166 struct mantis_hwconfig *config; 173 struct mantis_hwconfig *config;
167 int err = 0; 174 int err = 0;
@@ -169,84 +176,91 @@ static int mantis_pci_probe(struct pci_dev *pdev,
169 mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL); 176 mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);
170 if (mantis == NULL) { 177 if (mantis == NULL) {
171 printk(KERN_ERR "%s ERROR: Out of memory\n", __func__); 178 printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
172 err = -ENOMEM; 179 return -ENOMEM;
173 goto fail0;
174 } 180 }
175 181
182 drvdata = (void *)pci_id->driver_data;
176 mantis->num = devs; 183 mantis->num = devs;
177 mantis->verbose = verbose; 184 mantis->verbose = verbose;
178 mantis->pdev = pdev; 185 mantis->pdev = pdev;
179 config = (struct mantis_hwconfig *) pci_id->driver_data; 186 config = drvdata->hwconfig;
180 config->irq_handler = &mantis_irq_handler; 187 config->irq_handler = &mantis_irq_handler;
181 mantis->hwconfig = config; 188 mantis->hwconfig = config;
189 mantis->rc_map_name = drvdata->rc_map_name;
190
191 spin_lock_init(&mantis->intmask_lock);
182 192
183 err = mantis_pci_init(mantis); 193 err = mantis_pci_init(mantis);
184 if (err) { 194 if (err) {
185 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); 195 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
186 goto fail1; 196 goto err_free_mantis;
187 } 197 }
188 198
189 err = mantis_stream_control(mantis, STREAM_TO_HIF); 199 err = mantis_stream_control(mantis, STREAM_TO_HIF);
190 if (err < 0) { 200 if (err < 0) {
191 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); 201 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
192 goto fail1; 202 goto err_pci_exit;
193 } 203 }
194 204
195 err = mantis_i2c_init(mantis); 205 err = mantis_i2c_init(mantis);
196 if (err < 0) { 206 if (err < 0) {
197 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); 207 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
198 goto fail2; 208 goto err_pci_exit;
199 } 209 }
200 210
201 err = mantis_get_mac(mantis); 211 err = mantis_get_mac(mantis);
202 if (err < 0) { 212 if (err < 0) {
203 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); 213 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
204 goto fail2; 214 goto err_i2c_exit;
205 } 215 }
206 216
207 err = mantis_dma_init(mantis); 217 err = mantis_dma_init(mantis);
208 if (err < 0) { 218 if (err < 0) {
209 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); 219 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
210 goto fail3; 220 goto err_i2c_exit;
211 } 221 }
212 222
213 err = mantis_dvb_init(mantis); 223 err = mantis_dvb_init(mantis);
214 if (err < 0) { 224 if (err < 0) {
215 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); 225 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
216 goto fail4; 226 goto err_dma_exit;
227 }
228
229 err = mantis_input_init(mantis);
230 if (err < 0) {
231 dprintk(MANTIS_ERROR, 1,
232 "ERROR: Mantis DVB initialization failed <%d>", err);
233 goto err_dvb_exit;
217 } 234 }
235
218 err = mantis_uart_init(mantis); 236 err = mantis_uart_init(mantis);
219 if (err < 0) { 237 if (err < 0) {
220 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err); 238 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
221 goto fail6; 239 goto err_input_exit;
222 } 240 }
223 241
224 devs++; 242 devs++;
225 243
226 return err; 244 return 0;
227 245
246err_input_exit:
247 mantis_input_exit(mantis);
228 248
229 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err); 249err_dvb_exit:
230 mantis_uart_exit(mantis); 250 mantis_dvb_exit(mantis);
231 251
232fail6: 252err_dma_exit:
233fail4:
234 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
235 mantis_dma_exit(mantis); 253 mantis_dma_exit(mantis);
236 254
237fail3: 255err_i2c_exit:
238 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
239 mantis_i2c_exit(mantis); 256 mantis_i2c_exit(mantis);
240 257
241fail2: 258err_pci_exit:
242 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
243 mantis_pci_exit(mantis); 259 mantis_pci_exit(mantis);
244 260
245fail1: 261err_free_mantis:
246 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
247 kfree(mantis); 262 kfree(mantis);
248 263
249fail0:
250 return err; 264 return err;
251} 265}
252 266
@@ -257,6 +271,7 @@ static void mantis_pci_remove(struct pci_dev *pdev)
257 if (mantis) { 271 if (mantis) {
258 272
259 mantis_uart_exit(mantis); 273 mantis_uart_exit(mantis);
274 mantis_input_exit(mantis);
260 mantis_dvb_exit(mantis); 275 mantis_dvb_exit(mantis);
261 mantis_dma_exit(mantis); 276 mantis_dma_exit(mantis);
262 mantis_i2c_exit(mantis); 277 mantis_i2c_exit(mantis);
@@ -267,17 +282,28 @@ static void mantis_pci_remove(struct pci_dev *pdev)
267} 282}
268 283
269static struct pci_device_id mantis_pci_table[] = { 284static struct pci_device_id mantis_pci_table[] = {
270 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config), 285 MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config,
271 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config), 286 RC_MAP_TECHNISAT_TS35),
272 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config), 287 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config,
273 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config), 288 NULL),
274 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config), 289 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config,
275 MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config), 290 NULL),
276 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config), 291 MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config,
277 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config), 292 RC_MAP_TERRATEC_CINERGY_C_PCI),
278 MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config), 293 MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config,
279 MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config), 294 RC_MAP_TERRATEC_CINERGY_S2_HD),
280 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config), 295 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config,
296 NULL),
297 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config,
298 NULL),
299 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config,
300 RC_MAP_TWINHAN_DTV_CAB_CI),
301 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config,
302 RC_MAP_TWINHAN_DTV_CAB_CI),
303 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config,
304 NULL),
305 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config,
306 NULL),
281 { } 307 { }
282}; 308};
283 309
diff --git a/drivers/media/pci/mantis/mantis_common.h b/drivers/media/pci/mantis/mantis_common.h
index 8ff448bb792d..d48778a366a9 100644
--- a/drivers/media/pci/mantis/mantis_common.h
+++ b/drivers/media/pci/mantis/mantis_common.h
@@ -25,6 +25,7 @@
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/workqueue.h> 26#include <linux/workqueue.h>
27 27
28#include "mantis_reg.h"
28#include "mantis_uart.h" 29#include "mantis_uart.h"
29 30
30#include "mantis_link.h" 31#include "mantis_link.h"
@@ -68,12 +69,13 @@
68#define TECHNISAT 0x1ae4 69#define TECHNISAT 0x1ae4
69#define TERRATEC 0x153b 70#define TERRATEC 0x153b
70 71
71#define MAKE_ENTRY(__subven, __subdev, __configptr) { \ 72#define MAKE_ENTRY(__subven, __subdev, __configptr, __rc) { \
72 .vendor = TWINHAN_TECHNOLOGIES, \ 73 .vendor = TWINHAN_TECHNOLOGIES, \
73 .device = MANTIS, \ 74 .device = MANTIS, \
74 .subvendor = (__subven), \ 75 .subvendor = (__subven), \
75 .subdevice = (__subdev), \ 76 .subdevice = (__subdev), \
76 .driver_data = (unsigned long) (__configptr) \ 77 .driver_data = (unsigned long) \
78 &(struct mantis_pci_drvdata){__configptr, __rc} \
77} 79}
78 80
79enum mantis_i2c_mode { 81enum mantis_i2c_mode {
@@ -101,6 +103,11 @@ struct mantis_hwconfig {
101 enum mantis_i2c_mode i2c_mode; 103 enum mantis_i2c_mode i2c_mode;
102}; 104};
103 105
106struct mantis_pci_drvdata {
107 struct mantis_hwconfig *hwconfig;
108 char *rc_map_name;
109};
110
104struct mantis_pci { 111struct mantis_pci {
105 unsigned int verbose; 112 unsigned int verbose;
106 113
@@ -131,6 +138,7 @@ struct mantis_pci {
131 dma_addr_t risc_dma; 138 dma_addr_t risc_dma;
132 139
133 struct tasklet_struct tasklet; 140 struct tasklet_struct tasklet;
141 spinlock_t intmask_lock;
134 142
135 struct i2c_adapter adapter; 143 struct i2c_adapter adapter;
136 int i2c_rc; 144 int i2c_rc;
@@ -165,15 +173,32 @@ struct mantis_pci {
165 173
166 struct mantis_ca *mantis_ca; 174 struct mantis_ca *mantis_ca;
167 175
168 wait_queue_head_t uart_wq;
169 struct work_struct uart_work; 176 struct work_struct uart_work;
170 spinlock_t uart_lock;
171 177
172 struct rc_dev *rc; 178 struct rc_dev *rc;
173 char input_name[80]; 179 char input_name[80];
174 char input_phys[80]; 180 char input_phys[80];
181 char *rc_map_name;
175}; 182};
176 183
177#define MANTIS_HIF_STATUS (mantis->gpio_status) 184#define MANTIS_HIF_STATUS (mantis->gpio_status)
178 185
186static inline void mantis_mask_ints(struct mantis_pci *mantis, u32 mask)
187{
188 unsigned long flags;
189
190 spin_lock_irqsave(&mantis->intmask_lock, flags);
191 mmwrite(mmread(MANTIS_INT_MASK) & ~mask, MANTIS_INT_MASK);
192 spin_unlock_irqrestore(&mantis->intmask_lock, flags);
193}
194
195static inline void mantis_unmask_ints(struct mantis_pci *mantis, u32 mask)
196{
197 unsigned long flags;
198
199 spin_lock_irqsave(&mantis->intmask_lock, flags);
200 mmwrite(mmread(MANTIS_INT_MASK) | mask, MANTIS_INT_MASK);
201 spin_unlock_irqrestore(&mantis->intmask_lock, flags);
202}
203
179#endif /* __MANTIS_COMMON_H */ 204#endif /* __MANTIS_COMMON_H */
diff --git a/drivers/media/pci/mantis/mantis_dma.c b/drivers/media/pci/mantis/mantis_dma.c
index 566c407175a4..1d59c7e039f7 100644
--- a/drivers/media/pci/mantis/mantis_dma.c
+++ b/drivers/media/pci/mantis/mantis_dma.c
@@ -190,7 +190,7 @@ void mantis_dma_start(struct mantis_pci *mantis)
190 mmwrite(0, MANTIS_DMA_CTL); 190 mmwrite(0, MANTIS_DMA_CTL);
191 mantis->last_block = mantis->busy_block = 0; 191 mantis->last_block = mantis->busy_block = 0;
192 192
193 mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_RISCI, MANTIS_INT_MASK); 193 mantis_unmask_ints(mantis, MANTIS_INT_RISCI);
194 194
195 mmwrite(MANTIS_FIFO_EN | MANTIS_DCAP_EN 195 mmwrite(MANTIS_FIFO_EN | MANTIS_DCAP_EN
196 | MANTIS_RISC_EN, MANTIS_DMA_CTL); 196 | MANTIS_RISC_EN, MANTIS_DMA_CTL);
@@ -209,8 +209,7 @@ void mantis_dma_stop(struct mantis_pci *mantis)
209 209
210 mmwrite(mmread(MANTIS_INT_STAT), MANTIS_INT_STAT); 210 mmwrite(mmread(MANTIS_INT_STAT), MANTIS_INT_STAT);
211 211
212 mmwrite(mmread(MANTIS_INT_MASK) & ~(MANTIS_INT_RISCI | 212 mantis_mask_ints(mantis, MANTIS_INT_RISCI | MANTIS_INT_RISCEN);
213 MANTIS_INT_RISCEN), MANTIS_INT_MASK);
214} 213}
215 214
216 215
diff --git a/drivers/media/pci/mantis/mantis_i2c.c b/drivers/media/pci/mantis/mantis_i2c.c
index 895ddba3c0fb..d72ee47dc6e4 100644
--- a/drivers/media/pci/mantis/mantis_i2c.c
+++ b/drivers/media/pci/mantis/mantis_i2c.c
@@ -219,7 +219,7 @@ static struct i2c_algorithm mantis_algo = {
219 219
220int mantis_i2c_init(struct mantis_pci *mantis) 220int mantis_i2c_init(struct mantis_pci *mantis)
221{ 221{
222 u32 intstat, intmask; 222 u32 intstat;
223 struct i2c_adapter *i2c_adapter = &mantis->adapter; 223 struct i2c_adapter *i2c_adapter = &mantis->adapter;
224 struct pci_dev *pdev = mantis->pdev; 224 struct pci_dev *pdev = mantis->pdev;
225 225
@@ -242,11 +242,10 @@ int mantis_i2c_init(struct mantis_pci *mantis)
242 dprintk(MANTIS_DEBUG, 1, "Initializing I2C .."); 242 dprintk(MANTIS_DEBUG, 1, "Initializing I2C ..");
243 243
244 intstat = mmread(MANTIS_INT_STAT); 244 intstat = mmread(MANTIS_INT_STAT);
245 intmask = mmread(MANTIS_INT_MASK); 245 mmread(MANTIS_INT_MASK);
246 mmwrite(intstat, MANTIS_INT_STAT); 246 mmwrite(intstat, MANTIS_INT_STAT);
247 dprintk(MANTIS_DEBUG, 1, "Disabling I2C interrupt"); 247 dprintk(MANTIS_DEBUG, 1, "Disabling I2C interrupt");
248 intmask = mmread(MANTIS_INT_MASK); 248 mantis_mask_ints(mantis, MANTIS_INT_I2CDONE);
249 mmwrite((intmask & ~MANTIS_INT_I2CDONE), MANTIS_INT_MASK);
250 249
251 return 0; 250 return 0;
252} 251}
@@ -254,11 +253,8 @@ EXPORT_SYMBOL_GPL(mantis_i2c_init);
254 253
255int mantis_i2c_exit(struct mantis_pci *mantis) 254int mantis_i2c_exit(struct mantis_pci *mantis)
256{ 255{
257 u32 intmask;
258
259 dprintk(MANTIS_DEBUG, 1, "Disabling I2C interrupt"); 256 dprintk(MANTIS_DEBUG, 1, "Disabling I2C interrupt");
260 intmask = mmread(MANTIS_INT_MASK); 257 mantis_mask_ints(mantis, MANTIS_INT_I2CDONE);
261 mmwrite((intmask & ~MANTIS_INT_I2CDONE), MANTIS_INT_MASK);
262 258
263 dprintk(MANTIS_DEBUG, 1, "Removing I2C adapter"); 259 dprintk(MANTIS_DEBUG, 1, "Removing I2C adapter");
264 i2c_del_adapter(&mantis->adapter); 260 i2c_del_adapter(&mantis->adapter);
diff --git a/drivers/media/pci/mantis/mantis_input.c b/drivers/media/pci/mantis/mantis_input.c
index 0e5252e5c0ef..7f7f1d4d7bb1 100644
--- a/drivers/media/pci/mantis/mantis_input.c
+++ b/drivers/media/pci/mantis/mantis_input.c
@@ -12,14 +12,8 @@
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 15*/
20 16
21#if 0 /* Currently unused */
22
23#include <media/rc-core.h> 17#include <media/rc-core.h>
24#include <linux/pci.h> 18#include <linux/pci.h>
25 19
@@ -30,100 +24,32 @@
30#include "dvb_net.h" 24#include "dvb_net.h"
31 25
32#include "mantis_common.h" 26#include "mantis_common.h"
33#include "mantis_reg.h" 27#include "mantis_input.h"
34#include "mantis_uart.h"
35 28
36#define MODULE_NAME "mantis_core" 29#define MODULE_NAME "mantis_core"
37#define RC_MAP_MANTIS "rc-mantis" 30
38 31void mantis_input_process(struct mantis_pci *mantis, int scancode)
39static struct rc_map_table mantis_ir_table[] = { 32{
40 { 0x29, KEY_POWER }, 33 if (mantis->rc)
41 { 0x28, KEY_FAVORITES }, 34 rc_keydown(mantis->rc, RC_TYPE_UNKNOWN, scancode, 0);
42 { 0x30, KEY_TEXT }, 35}
43 { 0x17, KEY_INFO }, /* Preview */
44 { 0x23, KEY_EPG },
45 { 0x3b, KEY_F22 }, /* Record List */
46 { 0x3c, KEY_1 },
47 { 0x3e, KEY_2 },
48 { 0x39, KEY_3 },
49 { 0x36, KEY_4 },
50 { 0x22, KEY_5 },
51 { 0x20, KEY_6 },
52 { 0x32, KEY_7 },
53 { 0x26, KEY_8 },
54 { 0x24, KEY_9 },
55 { 0x2a, KEY_0 },
56
57 { 0x33, KEY_CANCEL },
58 { 0x2c, KEY_BACK },
59 { 0x15, KEY_CLEAR },
60 { 0x3f, KEY_TAB },
61 { 0x10, KEY_ENTER },
62 { 0x14, KEY_UP },
63 { 0x0d, KEY_RIGHT },
64 { 0x0e, KEY_DOWN },
65 { 0x11, KEY_LEFT },
66
67 { 0x21, KEY_VOLUMEUP },
68 { 0x35, KEY_VOLUMEDOWN },
69 { 0x3d, KEY_CHANNELDOWN },
70 { 0x3a, KEY_CHANNELUP },
71 { 0x2e, KEY_RECORD },
72 { 0x2b, KEY_PLAY },
73 { 0x13, KEY_PAUSE },
74 { 0x25, KEY_STOP },
75
76 { 0x1f, KEY_REWIND },
77 { 0x2d, KEY_FASTFORWARD },
78 { 0x1e, KEY_PREVIOUS }, /* Replay |< */
79 { 0x1d, KEY_NEXT }, /* Skip >| */
80
81 { 0x0b, KEY_CAMERA }, /* Capture */
82 { 0x0f, KEY_LANGUAGE }, /* SAP */
83 { 0x18, KEY_MODE }, /* PIP */
84 { 0x12, KEY_ZOOM }, /* Full screen */
85 { 0x1c, KEY_SUBTITLE },
86 { 0x2f, KEY_MUTE },
87 { 0x16, KEY_F20 }, /* L/R */
88 { 0x38, KEY_F21 }, /* Hibernate */
89
90 { 0x37, KEY_SWITCHVIDEOMODE }, /* A/V */
91 { 0x31, KEY_AGAIN }, /* Recall */
92 { 0x1a, KEY_KPPLUS }, /* Zoom+ */
93 { 0x19, KEY_KPMINUS }, /* Zoom- */
94 { 0x27, KEY_RED },
95 { 0x0C, KEY_GREEN },
96 { 0x01, KEY_YELLOW },
97 { 0x00, KEY_BLUE },
98};
99
100static struct rc_map_list ir_mantis_map = {
101 .map = {
102 .scan = mantis_ir_table,
103 .size = ARRAY_SIZE(mantis_ir_table),
104 .rc_type = RC_TYPE_UNKNOWN,
105 .name = RC_MAP_MANTIS,
106 }
107};
108 36
109int mantis_input_init(struct mantis_pci *mantis) 37int mantis_input_init(struct mantis_pci *mantis)
110{ 38{
111 struct rc_dev *dev; 39 struct rc_dev *dev;
112 int err; 40 int err;
113 41
114 err = rc_map_register(&ir_mantis_map);
115 if (err)
116 goto out;
117
118 dev = rc_allocate_device(); 42 dev = rc_allocate_device();
119 if (!dev) { 43 if (!dev) {
120 dprintk(MANTIS_ERROR, 1, "Remote device allocation failed"); 44 dprintk(MANTIS_ERROR, 1, "Remote device allocation failed");
121 err = -ENOMEM; 45 err = -ENOMEM;
122 goto out_map; 46 goto out;
123 } 47 }
124 48
125 sprintf(mantis->input_name, "Mantis %s IR receiver", mantis->hwconfig->model_name); 49 snprintf(mantis->input_name, sizeof(mantis->input_name),
126 sprintf(mantis->input_phys, "pci-%s/ir0", pci_name(mantis->pdev)); 50 "Mantis %s IR receiver", mantis->hwconfig->model_name);
51 snprintf(mantis->input_phys, sizeof(mantis->input_phys),
52 "pci-%s/ir0", pci_name(mantis->pdev));
127 53
128 dev->input_name = mantis->input_name; 54 dev->input_name = mantis->input_name;
129 dev->input_phys = mantis->input_phys; 55 dev->input_phys = mantis->input_phys;
@@ -132,7 +58,7 @@ int mantis_input_init(struct mantis_pci *mantis)
132 dev->input_id.product = mantis->device_id; 58 dev->input_id.product = mantis->device_id;
133 dev->input_id.version = 1; 59 dev->input_id.version = 1;
134 dev->driver_name = MODULE_NAME; 60 dev->driver_name = MODULE_NAME;
135 dev->map_name = RC_MAP_MANTIS; 61 dev->map_name = mantis->rc_map_name ? : RC_MAP_EMPTY;
136 dev->dev.parent = &mantis->pdev->dev; 62 dev->dev.parent = &mantis->pdev->dev;
137 63
138 err = rc_register_device(dev); 64 err = rc_register_device(dev);
@@ -146,17 +72,13 @@ int mantis_input_init(struct mantis_pci *mantis)
146 72
147out_dev: 73out_dev:
148 rc_free_device(dev); 74 rc_free_device(dev);
149out_map:
150 rc_map_unregister(&ir_mantis_map);
151out: 75out:
152 return err; 76 return err;
153} 77}
78EXPORT_SYMBOL_GPL(mantis_input_init);
154 79
155int mantis_init_exit(struct mantis_pci *mantis) 80void mantis_input_exit(struct mantis_pci *mantis)
156{ 81{
157 rc_unregister_device(mantis->rc); 82 rc_unregister_device(mantis->rc);
158 rc_map_unregister(&ir_mantis_map);
159 return 0;
160} 83}
161 84EXPORT_SYMBOL_GPL(mantis_input_exit);
162#endif
diff --git a/drivers/media/pci/mantis/mantis_input.h b/drivers/media/pci/mantis/mantis_input.h
new file mode 100644
index 000000000000..0fbd92987c02
--- /dev/null
+++ b/drivers/media/pci/mantis/mantis_input.h
@@ -0,0 +1,24 @@
1/*
2 Mantis PCI bridge driver
3
4 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License 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
17#ifndef __MANTIS_INPUT_H
18#define __MANTIS_INPUT_H
19
20int mantis_input_init(struct mantis_pci *mantis);
21void mantis_input_exit(struct mantis_pci *mantis);
22void mantis_input_process(struct mantis_pci *mantis, int scancode);
23
24#endif /* __MANTIS_UART_H */
diff --git a/drivers/media/pci/mantis/mantis_pcmcia.c b/drivers/media/pci/mantis/mantis_pcmcia.c
index 2f188c089666..b2dbc7b2e0f6 100644
--- a/drivers/media/pci/mantis/mantis_pcmcia.c
+++ b/drivers/media/pci/mantis/mantis_pcmcia.c
@@ -89,7 +89,7 @@ int mantis_pcmcia_init(struct mantis_ca *ca)
89 89
90 u32 gpif_stat, card_stat; 90 u32 gpif_stat, card_stat;
91 91
92 mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_IRQ0, MANTIS_INT_MASK); 92 mantis_unmask_ints(mantis, MANTIS_INT_IRQ0);
93 gpif_stat = mmread(MANTIS_GPIF_STATUS); 93 gpif_stat = mmread(MANTIS_GPIF_STATUS);
94 card_stat = mmread(MANTIS_GPIF_IRQCFG); 94 card_stat = mmread(MANTIS_GPIF_IRQCFG);
95 95
@@ -117,5 +117,5 @@ void mantis_pcmcia_exit(struct mantis_ca *ca)
117 struct mantis_pci *mantis = ca->ca_priv; 117 struct mantis_pci *mantis = ca->ca_priv;
118 118
119 mmwrite(mmread(MANTIS_GPIF_STATUS) & (~MANTIS_CARD_PLUGOUT | ~MANTIS_CARD_PLUGIN), MANTIS_GPIF_STATUS); 119 mmwrite(mmread(MANTIS_GPIF_STATUS) & (~MANTIS_CARD_PLUGOUT | ~MANTIS_CARD_PLUGIN), MANTIS_GPIF_STATUS);
120 mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ0, MANTIS_INT_MASK); 120 mantis_mask_ints(mantis, MANTIS_INT_IRQ0);
121} 121}
diff --git a/drivers/media/pci/mantis/mantis_uart.c b/drivers/media/pci/mantis/mantis_uart.c
index a70719218631..f1c96aec8c7b 100644
--- a/drivers/media/pci/mantis/mantis_uart.c
+++ b/drivers/media/pci/mantis/mantis_uart.c
@@ -25,6 +25,7 @@
25#include <linux/signal.h> 25#include <linux/signal.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/pci.h>
28 29
29#include "dmxdev.h" 30#include "dmxdev.h"
30#include "dvbdev.h" 31#include "dvbdev.h"
@@ -35,6 +36,7 @@
35#include "mantis_common.h" 36#include "mantis_common.h"
36#include "mantis_reg.h" 37#include "mantis_reg.h"
37#include "mantis_uart.h" 38#include "mantis_uart.h"
39#include "mantis_input.h"
38 40
39struct mantis_uart_params { 41struct mantis_uart_params {
40 enum mantis_baud baud_rate; 42 enum mantis_baud baud_rate;
@@ -59,51 +61,54 @@ static struct {
59 { "EVEN" } 61 { "EVEN" }
60}; 62};
61 63
62#define UART_MAX_BUF 16 64static void mantis_uart_read(struct mantis_pci *mantis)
63
64static int mantis_uart_read(struct mantis_pci *mantis, u8 *data)
65{ 65{
66 struct mantis_hwconfig *config = mantis->hwconfig; 66 struct mantis_hwconfig *config = mantis->hwconfig;
67 u32 stat = 0, i; 67 int i, scancode = 0, err = 0;
68 68
69 /* get data */ 69 /* get data */
70 dprintk(MANTIS_DEBUG, 1, "UART Reading ...");
70 for (i = 0; i < (config->bytes + 1); i++) { 71 for (i = 0; i < (config->bytes + 1); i++) {
72 int data = mmread(MANTIS_UART_RXD);
71 73
72 stat = mmread(MANTIS_UART_STAT); 74 dprintk(MANTIS_DEBUG, 0, " <%02x>", data);
73
74 if (stat & MANTIS_UART_RXFIFO_FULL) {
75 dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");
76 }
77 data[i] = mmread(MANTIS_UART_RXD) & 0x3f;
78 75
79 dprintk(MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f); 76 scancode = (scancode << 8) | (data & 0x3f);
77 err |= data;
80 78
81 if (data[i] & (1 << 7)) { 79 if (data & (1 << 7))
82 dprintk(MANTIS_ERROR, 1, "UART framing error"); 80 dprintk(MANTIS_ERROR, 1, "UART framing error");
83 return -EINVAL; 81
84 } 82 if (data & (1 << 6))
85 if (data[i] & (1 << 6)) {
86 dprintk(MANTIS_ERROR, 1, "UART parity error"); 83 dprintk(MANTIS_ERROR, 1, "UART parity error");
87 return -EINVAL;
88 }
89 } 84 }
85 dprintk(MANTIS_DEBUG, 0, "\n");
90 86
91 return 0; 87 if ((err & 0xC0) == 0)
88 mantis_input_process(mantis, scancode);
92} 89}
93 90
94static void mantis_uart_work(struct work_struct *work) 91static void mantis_uart_work(struct work_struct *work)
95{ 92{
96 struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work); 93 struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work);
97 struct mantis_hwconfig *config = mantis->hwconfig; 94 u32 stat;
98 u8 buf[16];
99 int i;
100 95
101 mantis_uart_read(mantis, buf); 96 stat = mmread(MANTIS_UART_STAT);
102 97
103 for (i = 0; i < (config->bytes + 1); i++) 98 if (stat & MANTIS_UART_RXFIFO_FULL)
104 dprintk(MANTIS_INFO, 1, "UART BUF:%d <%02x> ", i, buf[i]); 99 dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");
105 100
106 dprintk(MANTIS_DEBUG, 0, "\n"); 101 /*
102 * MANTIS_UART_RXFIFO_DATA is only set if at least
103 * config->bytes + 1 bytes are in the FIFO.
104 */
105 while (stat & MANTIS_UART_RXFIFO_DATA) {
106 mantis_uart_read(mantis);
107 stat = mmread(MANTIS_UART_STAT);
108 }
109
110 /* re-enable UART (RX) interrupt */
111 mantis_unmask_ints(mantis, MANTIS_INT_IRQ1);
107} 112}
108 113
109static int mantis_uart_setup(struct mantis_pci *mantis, 114static int mantis_uart_setup(struct mantis_pci *mantis,
@@ -152,9 +157,6 @@ int mantis_uart_init(struct mantis_pci *mantis)
152 rates[params.baud_rate].string, 157 rates[params.baud_rate].string,
153 parity[params.parity].string); 158 parity[params.parity].string);
154 159
155 init_waitqueue_head(&mantis->uart_wq);
156 spin_lock_init(&mantis->uart_lock);
157
158 INIT_WORK(&mantis->uart_work, mantis_uart_work); 160 INIT_WORK(&mantis->uart_work, mantis_uart_work);
159 161
160 /* disable interrupt */ 162 /* disable interrupt */
@@ -169,8 +171,8 @@ int mantis_uart_init(struct mantis_pci *mantis)
169 mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL); 171 mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL);
170 172
171 /* enable interrupt */ 173 /* enable interrupt */
172 mmwrite(mmread(MANTIS_INT_MASK) | 0x800, MANTIS_INT_MASK);
173 mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL); 174 mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL);
175 mantis_unmask_ints(mantis, MANTIS_INT_IRQ1);
174 176
175 schedule_work(&mantis->uart_work); 177 schedule_work(&mantis->uart_work);
176 dprintk(MANTIS_DEBUG, 1, "UART successfully initialized"); 178 dprintk(MANTIS_DEBUG, 1, "UART successfully initialized");
@@ -182,6 +184,7 @@ EXPORT_SYMBOL_GPL(mantis_uart_init);
182void mantis_uart_exit(struct mantis_pci *mantis) 184void mantis_uart_exit(struct mantis_pci *mantis)
183{ 185{
184 /* disable interrupt */ 186 /* disable interrupt */
187 mantis_mask_ints(mantis, MANTIS_INT_IRQ1);
185 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL); 188 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
186 flush_work(&mantis->uart_work); 189 flush_work(&mantis->uart_work);
187} 190}
diff --git a/drivers/media/pci/mantis/mantis_vp1034.c b/drivers/media/pci/mantis/mantis_vp1034.c
index 7c1bd167225c..3b1928594b12 100644
--- a/drivers/media/pci/mantis/mantis_vp1034.c
+++ b/drivers/media/pci/mantis/mantis_vp1034.c
@@ -44,7 +44,7 @@ static struct mb86a16_config vp1034_mb86a16_config = {
44#define MANTIS_MODEL_NAME "VP-1034" 44#define MANTIS_MODEL_NAME "VP-1034"
45#define MANTIS_DEV_TYPE "DVB-S/DSS" 45#define MANTIS_DEV_TYPE "DVB-S/DSS"
46 46
47int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 47int vp1034_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
48{ 48{
49 struct mantis_pci *mantis = fe->dvb->priv; 49 struct mantis_pci *mantis = fe->dvb->priv;
50 50
diff --git a/drivers/media/pci/mantis/mantis_vp1034.h b/drivers/media/pci/mantis/mantis_vp1034.h
index 323f38ef8e3d..764b1c66ea1b 100644
--- a/drivers/media/pci/mantis/mantis_vp1034.h
+++ b/drivers/media/pci/mantis/mantis_vp1034.h
@@ -28,6 +28,7 @@
28#define MANTIS_VP_1034_DVB_S 0x0014 28#define MANTIS_VP_1034_DVB_S 0x0014
29 29
30extern struct mantis_hwconfig vp1034_config; 30extern struct mantis_hwconfig vp1034_config;
31extern int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 31extern int vp1034_set_voltage(struct dvb_frontend *fe,
32 enum fe_sec_voltage voltage);
32 33
33#endif /* __MANTIS_VP1034_H */ 34#endif /* __MANTIS_VP1034_H */
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index e29bc3af4baf..1b92d836a564 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1526,10 +1526,12 @@ static int init_channel(struct ngene_channel *chan)
1526 if (chan->fe2) { 1526 if (chan->fe2) {
1527 if (dvb_register_frontend(adapter, chan->fe2) < 0) 1527 if (dvb_register_frontend(adapter, chan->fe2) < 0)
1528 goto err; 1528 goto err;
1529 chan->fe2->tuner_priv = chan->fe->tuner_priv; 1529 if (chan->fe) {
1530 memcpy(&chan->fe2->ops.tuner_ops, 1530 chan->fe2->tuner_priv = chan->fe->tuner_priv;
1531 &chan->fe->ops.tuner_ops, 1531 memcpy(&chan->fe2->ops.tuner_ops,
1532 sizeof(struct dvb_tuner_ops)); 1532 &chan->fe->ops.tuner_ops,
1533 sizeof(struct dvb_tuner_ops));
1534 }
1533 } 1535 }
1534 1536
1535 if (chan->has_demux) { 1537 if (chan->has_demux) {
diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h
index 51e2fbd18b1b..fa30930d7047 100644
--- a/drivers/media/pci/ngene/ngene.h
+++ b/drivers/media/pci/ngene/ngene.h
@@ -682,7 +682,7 @@ struct ngene_channel {
682 int AudioDTOUpdated; 682 int AudioDTOUpdated;
683 u32 AudioDTOValue; 683 u32 AudioDTOValue;
684 684
685 int (*set_tone)(struct dvb_frontend *, fe_sec_tone_mode_t); 685 int (*set_tone)(struct dvb_frontend *, enum fe_sec_tone_mode);
686 u8 lnbh; 686 u8 lnbh;
687 687
688 /* stuff from analog driver */ 688 /* stuff from analog driver */
diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index acc35b42e53c..e7e4428109c3 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -101,11 +101,11 @@ struct pt1_adapter {
101 struct dmxdev dmxdev; 101 struct dmxdev dmxdev;
102 struct dvb_frontend *fe; 102 struct dvb_frontend *fe;
103 int (*orig_set_voltage)(struct dvb_frontend *fe, 103 int (*orig_set_voltage)(struct dvb_frontend *fe,
104 fe_sec_voltage_t voltage); 104 enum fe_sec_voltage voltage);
105 int (*orig_sleep)(struct dvb_frontend *fe); 105 int (*orig_sleep)(struct dvb_frontend *fe);
106 int (*orig_init)(struct dvb_frontend *fe); 106 int (*orig_init)(struct dvb_frontend *fe);
107 107
108 fe_sec_voltage_t voltage; 108 enum fe_sec_voltage voltage;
109 int sleep; 109 int sleep;
110}; 110};
111 111
@@ -575,7 +575,7 @@ pt1_update_power(struct pt1 *pt1)
575 mutex_unlock(&pt1->lock); 575 mutex_unlock(&pt1->lock);
576} 576}
577 577
578static int pt1_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 578static int pt1_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
579{ 579{
580 struct pt1_adapter *adap; 580 struct pt1_adapter *adap;
581 581
diff --git a/drivers/media/pci/pt1/va1j5jf8007s.c b/drivers/media/pci/pt1/va1j5jf8007s.c
index 1b637b74ef58..d0e70dc0e16f 100644
--- a/drivers/media/pci/pt1/va1j5jf8007s.c
+++ b/drivers/media/pci/pt1/va1j5jf8007s.c
@@ -108,7 +108,7 @@ static int va1j5jf8007s_get_frontend_algo(struct dvb_frontend *fe)
108} 108}
109 109
110static int 110static int
111va1j5jf8007s_read_status(struct dvb_frontend *fe, fe_status_t *status) 111va1j5jf8007s_read_status(struct dvb_frontend *fe, enum fe_status *status)
112{ 112{
113 struct va1j5jf8007s_state *state; 113 struct va1j5jf8007s_state *state;
114 114
@@ -387,7 +387,7 @@ static int
387va1j5jf8007s_tune(struct dvb_frontend *fe, 387va1j5jf8007s_tune(struct dvb_frontend *fe,
388 bool re_tune, 388 bool re_tune,
389 unsigned int mode_flags, unsigned int *delay, 389 unsigned int mode_flags, unsigned int *delay,
390 fe_status_t *status) 390 enum fe_status *status)
391{ 391{
392 struct va1j5jf8007s_state *state; 392 struct va1j5jf8007s_state *state;
393 int ret; 393 int ret;
diff --git a/drivers/media/pci/pt1/va1j5jf8007t.c b/drivers/media/pci/pt1/va1j5jf8007t.c
index 2db15159d514..0268f20b8097 100644
--- a/drivers/media/pci/pt1/va1j5jf8007t.c
+++ b/drivers/media/pci/pt1/va1j5jf8007t.c
@@ -98,7 +98,7 @@ static int va1j5jf8007t_get_frontend_algo(struct dvb_frontend *fe)
98} 98}
99 99
100static int 100static int
101va1j5jf8007t_read_status(struct dvb_frontend *fe, fe_status_t *status) 101va1j5jf8007t_read_status(struct dvb_frontend *fe, enum fe_status *status)
102{ 102{
103 struct va1j5jf8007t_state *state; 103 struct va1j5jf8007t_state *state;
104 104
@@ -266,7 +266,7 @@ static int
266va1j5jf8007t_tune(struct dvb_frontend *fe, 266va1j5jf8007t_tune(struct dvb_frontend *fe,
267 bool re_tune, 267 bool re_tune,
268 unsigned int mode_flags, unsigned int *delay, 268 unsigned int mode_flags, unsigned int *delay,
269 fe_status_t *status) 269 enum fe_status *status)
270{ 270{
271 struct va1j5jf8007t_state *state; 271 struct va1j5jf8007t_state *state;
272 int ret; 272 int ret;
diff --git a/drivers/media/pci/pt3/pt3.c b/drivers/media/pci/pt3/pt3.c
index 7a37e8fe2ee2..0d2e2b217121 100644
--- a/drivers/media/pci/pt3/pt3.c
+++ b/drivers/media/pci/pt3/pt3.c
@@ -188,7 +188,7 @@ static int pt3_set_lna(struct dvb_frontend *fe)
188 return ret; 188 return ret;
189} 189}
190 190
191static int pt3_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt) 191static int pt3_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage volt)
192{ 192{
193 struct pt3_adapter *adap; 193 struct pt3_adapter *adap;
194 struct pt3_board *pt3; 194 struct pt3_board *pt3;
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index ac3cd74e824e..1d2c310ce838 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -16,6 +16,9 @@
16 * 16 *
17 */ 17 */
18 18
19#include "saa7134.h"
20#include "saa7134-reg.h"
21
19#include <linux/init.h> 22#include <linux/init.h>
20#include <linux/slab.h> 23#include <linux/slab.h>
21#include <linux/time.h> 24#include <linux/time.h>
@@ -29,13 +32,6 @@
29#include <linux/interrupt.h> 32#include <linux/interrupt.h>
30#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
31 34
32#include "saa7134.h"
33#include "saa7134-reg.h"
34
35static unsigned int debug;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug,"enable debug messages [alsa]");
38
39/* 35/*
40 * Configuration macros 36 * Configuration macros
41 */ 37 */
@@ -57,11 +53,6 @@ module_param_array(enable, int, NULL, 0444);
57MODULE_PARM_DESC(index, "Index value for SAA7134 capture interface(s)."); 53MODULE_PARM_DESC(index, "Index value for SAA7134 capture interface(s).");
58MODULE_PARM_DESC(enable, "Enable (or not) the SAA7134 capture interface(s)."); 54MODULE_PARM_DESC(enable, "Enable (or not) the SAA7134 capture interface(s).");
59 55
60#define dprintk(fmt, arg...) if (debug) \
61 printk(KERN_DEBUG "%s/alsa: " fmt, dev->name , ##arg)
62
63
64
65/* 56/*
66 * Main chip structure 57 * Main chip structure
67 */ 58 */
@@ -149,11 +140,11 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
149 140
150 spin_lock(&dev->slock); 141 spin_lock(&dev->slock);
151 if (UNSET == dev->dmasound.dma_blk) { 142 if (UNSET == dev->dmasound.dma_blk) {
152 dprintk("irq: recording stopped\n"); 143 pr_debug("irq: recording stopped\n");
153 goto done; 144 goto done;
154 } 145 }
155 if (0 != (status & 0x0f000000)) 146 if (0 != (status & 0x0f000000))
156 dprintk("irq: lost %ld\n", (status >> 24) & 0x0f); 147 pr_debug("irq: lost %ld\n", (status >> 24) & 0x0f);
157 if (0 == (status & 0x10000000)) { 148 if (0 == (status & 0x10000000)) {
158 /* odd */ 149 /* odd */
159 if (0 == (dev->dmasound.dma_blk & 0x01)) 150 if (0 == (dev->dmasound.dma_blk & 0x01))
@@ -164,13 +155,14 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
164 reg = SAA7134_RS_BA2(6); 155 reg = SAA7134_RS_BA2(6);
165 } 156 }
166 if (0 == reg) { 157 if (0 == reg) {
167 dprintk("irq: field oops [%s]\n", 158 pr_debug("irq: field oops [%s]\n",
168 (status & 0x10000000) ? "even" : "odd"); 159 (status & 0x10000000) ? "even" : "odd");
169 goto done; 160 goto done;
170 } 161 }
171 162
172 if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) { 163 if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) {
173 dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count, 164 pr_debug("irq: overrun [full=%d/%d] - Blocks in %d\n",
165 dev->dmasound.read_count,
174 dev->dmasound.bufsize, dev->dmasound.blocks); 166 dev->dmasound.bufsize, dev->dmasound.blocks);
175 spin_unlock(&dev->slock); 167 spin_unlock(&dev->slock);
176 snd_pcm_stop_xrun(dev->dmasound.substream); 168 snd_pcm_stop_xrun(dev->dmasound.substream);
@@ -180,10 +172,10 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
180 /* next block addr */ 172 /* next block addr */
181 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks; 173 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
182 saa_writel(reg,next_blk * dev->dmasound.blksize); 174 saa_writel(reg,next_blk * dev->dmasound.blksize);
183 if (debug > 2) 175 pr_debug("irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, read=%u\n",
184 dprintk("irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, read=%u\n", 176 (status & 0x10000000) ? "even" : "odd ", next_blk,
185 (status & 0x10000000) ? "even" : "odd ", next_blk, 177 next_blk * dev->dmasound.blksize, dev->dmasound.blocks,
186 next_blk * dev->dmasound.blksize, dev->dmasound.blocks, dev->dmasound.blksize, dev->dmasound.read_count); 178 dev->dmasound.blksize, dev->dmasound.read_count);
187 179
188 /* update status & wake waiting readers */ 180 /* update status & wake waiting readers */
189 dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks; 181 dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks;
@@ -233,7 +225,7 @@ static irqreturn_t saa7134_alsa_irq(int irq, void *dev_id)
233 } 225 }
234 226
235 if (loop == 10) { 227 if (loop == 10) {
236 dprintk("error! looping IRQ!"); 228 pr_debug("error! looping IRQ!");
237 } 229 }
238 230
239out: 231out:
@@ -281,11 +273,11 @@ static int saa7134_alsa_dma_init(struct saa7134_dev *dev, int nr_pages)
281 273
282 dma->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); 274 dma->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
283 if (NULL == dma->vaddr) { 275 if (NULL == dma->vaddr) {
284 dprintk("vmalloc_32(%d pages) failed\n", nr_pages); 276 pr_debug("vmalloc_32(%d pages) failed\n", nr_pages);
285 return -ENOMEM; 277 return -ENOMEM;
286 } 278 }
287 279
288 dprintk("vmalloc is at addr 0x%08lx, size=%d\n", 280 pr_debug("vmalloc is at addr 0x%08lx, size=%d\n",
289 (unsigned long)dma->vaddr, 281 (unsigned long)dma->vaddr,
290 nr_pages << PAGE_SHIFT); 282 nr_pages << PAGE_SHIFT);
291 283
@@ -572,7 +564,7 @@ static int snd_card_saa7134_capture_prepare(struct snd_pcm_substream * substream
572 break; 564 break;
573 } 565 }
574 566
575 dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n", 567 pr_debug("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
576 runtime->format, runtime->channels, fmt, 568 runtime->format, runtime->channels, fmt,
577 bswap ? 'b' : '-'); 569 bswap ? 'b' : '-');
578 /* dma: setup channel 6 (= AUDIO) */ 570 /* dma: setup channel 6 (= AUDIO) */
@@ -821,7 +813,7 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
821 int amux, err; 813 int amux, err;
822 814
823 if (!saa7134) { 815 if (!saa7134) {
824 printk(KERN_ERR "BUG: saa7134 can't find device struct." 816 pr_err("BUG: saa7134 can't find device struct."
825 " Can't proceed with open\n"); 817 " Can't proceed with open\n");
826 return -ENODEV; 818 return -ENODEV;
827 } 819 }
@@ -1175,7 +1167,7 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
1175 (void*) &dev->dmasound); 1167 (void*) &dev->dmasound);
1176 1168
1177 if (err < 0) { 1169 if (err < 0) {
1178 printk(KERN_ERR "%s: can't get IRQ %d for ALSA\n", 1170 pr_err("%s: can't get IRQ %d for ALSA\n",
1179 dev->name, dev->pci->irq); 1171 dev->name, dev->pci->irq);
1180 goto __nodev; 1172 goto __nodev;
1181 } 1173 }
@@ -1196,7 +1188,8 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
1196 sprintf(card->longname, "%s at 0x%lx irq %d", 1188 sprintf(card->longname, "%s at 0x%lx irq %d",
1197 chip->dev->name, chip->iobase, chip->irq); 1189 chip->dev->name, chip->iobase, chip->irq);
1198 1190
1199 printk(KERN_INFO "%s/alsa: %s registered as card %d\n",dev->name,card->longname,index[devnum]); 1191 pr_info("%s/alsa: %s registered as card %d\n",
1192 dev->name, card->longname, index[devnum]);
1200 1193
1201 if ((err = snd_card_register(card)) == 0) { 1194 if ((err = snd_card_register(card)) == 0) {
1202 snd_saa7134_cards[devnum] = card; 1195 snd_saa7134_cards[devnum] = card;
@@ -1240,19 +1233,19 @@ static int saa7134_alsa_init(void)
1240 saa7134_dmasound_init = alsa_device_init; 1233 saa7134_dmasound_init = alsa_device_init;
1241 saa7134_dmasound_exit = alsa_device_exit; 1234 saa7134_dmasound_exit = alsa_device_exit;
1242 1235
1243 printk(KERN_INFO "saa7134 ALSA driver for DMA sound loaded\n"); 1236 pr_info("saa7134 ALSA driver for DMA sound loaded\n");
1244 1237
1245 list_for_each(list,&saa7134_devlist) { 1238 list_for_each(list,&saa7134_devlist) {
1246 dev = list_entry(list, struct saa7134_dev, devlist); 1239 dev = list_entry(list, struct saa7134_dev, devlist);
1247 if (dev->pci->device == PCI_DEVICE_ID_PHILIPS_SAA7130) 1240 if (dev->pci->device == PCI_DEVICE_ID_PHILIPS_SAA7130)
1248 printk(KERN_INFO "%s/alsa: %s doesn't support digital audio\n", 1241 pr_info("%s/alsa: %s doesn't support digital audio\n",
1249 dev->name, saa7134_boards[dev->board].name); 1242 dev->name, saa7134_boards[dev->board].name);
1250 else 1243 else
1251 alsa_device_init(dev); 1244 alsa_device_init(dev);
1252 } 1245 }
1253 1246
1254 if (dev == NULL) 1247 if (dev == NULL)
1255 printk(KERN_INFO "saa7134 ALSA: no saa7134 cards found\n"); 1248 pr_info("saa7134 ALSA: no saa7134 cards found\n");
1256 1249
1257 return 0; 1250 return 0;
1258 1251
@@ -1272,7 +1265,7 @@ static void saa7134_alsa_exit(void)
1272 1265
1273 saa7134_dmasound_init = NULL; 1266 saa7134_dmasound_init = NULL;
1274 saa7134_dmasound_exit = NULL; 1267 saa7134_dmasound_exit = NULL;
1275 printk(KERN_INFO "saa7134 ALSA driver for DMA sound unloaded\n"); 1268 pr_info("saa7134 ALSA driver for DMA sound unloaded\n");
1276 1269
1277 return; 1270 return;
1278} 1271}
diff --git a/drivers/media/pci/saa7134/saa7134-cards.c b/drivers/media/pci/saa7134/saa7134-cards.c
index 3ca078057755..c7405766609c 100644
--- a/drivers/media/pci/saa7134/saa7134-cards.c
+++ b/drivers/media/pci/saa7134/saa7134-cards.c
@@ -20,13 +20,14 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/module.h> 27#include <linux/module.h>
25#include <linux/i2c.h> 28#include <linux/i2c.h>
26#include <linux/i2c-algo-bit.h> 29#include <linux/i2c-algo-bit.h>
27 30
28#include "saa7134-reg.h"
29#include "saa7134.h"
30#include "tuner-xc2028.h" 31#include "tuner-xc2028.h"
31#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
32#include <media/tveeprom.h> 33#include <media/tveeprom.h>
@@ -5850,6 +5851,39 @@ struct saa7134_board saa7134_boards[] = {
5850 .amux = LINE1, 5851 .amux = LINE1,
5851 } }, 5852 } },
5852 }, 5853 },
5854 [SAA7134_BOARD_AVERMEDIA_505] = {
5855 /* much like the "studio" version but without radio
5856 * and another tuner (dbaryshkov@gmail.com) */
5857 .name = "AverMedia AverTV/505",
5858 .audio_clock = 0x00187de7,
5859 .tuner_type = TUNER_PHILIPS_FQ1216ME,
5860 .radio_type = UNSET,
5861 .tuner_addr = ADDR_UNSET,
5862 .radio_addr = ADDR_UNSET,
5863 .tda9887_conf = TDA9887_PRESENT,
5864 .inputs = {{
5865 .name = name_tv,
5866 .vmux = 1,
5867 .amux = LINE2,
5868 .tv = 1,
5869 }, {
5870 .name = name_comp1,
5871 .vmux = 0,
5872 .amux = LINE2,
5873 }, {
5874 .name = name_comp2,
5875 .vmux = 3,
5876 .amux = LINE2,
5877 }, {
5878 .name = name_svideo,
5879 .vmux = 8,
5880 .amux = LINE2,
5881 } },
5882 .mute = {
5883 .name = name_mute,
5884 .amux = LINE1,
5885 },
5886 },
5853 5887
5854}; 5888};
5855 5889
@@ -7109,6 +7143,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
7109 .subdevice = 0x7007, 7143 .subdevice = 0x7007,
7110 .driver_data = SAA7134_BOARD_WIS_VOYAGER, 7144 .driver_data = SAA7134_BOARD_WIS_VOYAGER,
7111 }, { 7145 }, {
7146 .vendor = PCI_VENDOR_ID_PHILIPS,
7147 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
7148 .subvendor = 0x1461, /* Avermedia Technologies Inc */
7149 .subdevice = 0xa10a,
7150 .driver_data = SAA7134_BOARD_AVERMEDIA_505,
7151 }, {
7112 /* --- boards without eeprom + subsystem ID --- */ 7152 /* --- boards without eeprom + subsystem ID --- */
7113 .vendor = PCI_VENDOR_ID_PHILIPS, 7153 .vendor = PCI_VENDOR_ID_PHILIPS,
7114 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 7154 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -7158,10 +7198,10 @@ MODULE_DEVICE_TABLE(pci, saa7134_pci_tbl);
7158 7198
7159static void board_flyvideo(struct saa7134_dev *dev) 7199static void board_flyvideo(struct saa7134_dev *dev)
7160{ 7200{
7161 printk("%s: there are different flyvideo cards with different tuners\n" 7201 pr_warn("%s: there are different flyvideo cards with different tuners\n"
7162 "%s: out there, you might have to use the tuner=<nr> insmod\n" 7202 "%s: out there, you might have to use the tuner=<nr> insmod\n"
7163 "%s: option to override the default value.\n", 7203 "%s: option to override the default value.\n",
7164 dev->name, dev->name, dev->name); 7204 dev->name, dev->name, dev->name);
7165} 7205}
7166 7206
7167static int saa7134_xc2028_callback(struct saa7134_dev *dev, 7207static int saa7134_xc2028_callback(struct saa7134_dev *dev,
@@ -7194,7 +7234,7 @@ static int saa7134_xc2028_callback(struct saa7134_dev *dev,
7194 saa7134_set_gpio(dev, 20, 1); 7234 saa7134_set_gpio(dev, 20, 1);
7195 break; 7235 break;
7196 } 7236 }
7197 return 0; 7237 return 0;
7198 } 7238 }
7199 return -EINVAL; 7239 return -EINVAL;
7200} 7240}
@@ -7380,7 +7420,7 @@ int saa7134_tuner_callback(void *priv, int component, int command, int arg)
7380 return saa7134_xc5000_callback(dev, command, arg); 7420 return saa7134_xc5000_callback(dev, command, arg);
7381 } 7421 }
7382 } else { 7422 } else {
7383 printk(KERN_ERR "saa7134: Error - device struct undefined.\n"); 7423 pr_err("saa7134: Error - device struct undefined.\n");
7384 return -EINVAL; 7424 return -EINVAL;
7385 } 7425 }
7386 return -EINVAL; 7426 return -EINVAL;
@@ -7411,12 +7451,12 @@ static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data)
7411 case 67659: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */ 7451 case 67659: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */
7412 break; 7452 break;
7413 default: 7453 default:
7414 printk(KERN_WARNING "%s: warning: " 7454 pr_warn("%s: warning: "
7415 "unknown hauppauge model #%d\n", dev->name, tv.model); 7455 "unknown hauppauge model #%d\n", dev->name, tv.model);
7416 break; 7456 break;
7417 } 7457 }
7418 7458
7419 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n", 7459 pr_info("%s: hauppauge eeprom: model=%d\n",
7420 dev->name, tv.model); 7460 dev->name, tv.model);
7421} 7461}
7422 7462
@@ -7427,7 +7467,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
7427 /* Always print gpio, often manufacturers encode tuner type and other info. */ 7467 /* Always print gpio, often manufacturers encode tuner type and other info. */
7428 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0); 7468 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0);
7429 dev->gpio_value = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); 7469 dev->gpio_value = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
7430 printk(KERN_INFO "%s: board init: gpio is %x\n", dev->name, dev->gpio_value); 7470 pr_info("%s: board init: gpio is %x\n", dev->name, dev->gpio_value);
7431 7471
7432 switch (dev->board) { 7472 switch (dev->board) {
7433 case SAA7134_BOARD_FLYVIDEO2000: 7473 case SAA7134_BOARD_FLYVIDEO2000:
@@ -7448,8 +7488,9 @@ int saa7134_board_init1(struct saa7134_dev *dev)
7448 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 7488 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
7449 case SAA7134_BOARD_KWORLD_XPERT: 7489 case SAA7134_BOARD_KWORLD_XPERT:
7450 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 7490 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
7451 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
7452 case SAA7134_BOARD_AVERMEDIA_305: 7491 case SAA7134_BOARD_AVERMEDIA_305:
7492 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
7493 case SAA7134_BOARD_AVERMEDIA_505:
7453 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 7494 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
7454 case SAA7134_BOARD_AVERMEDIA_307: 7495 case SAA7134_BOARD_AVERMEDIA_307:
7455 case SAA7134_BOARD_AVERMEDIA_STUDIO_507: 7496 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
@@ -7512,10 +7553,10 @@ int saa7134_board_init1(struct saa7134_dev *dev)
7512 dev->has_remote = SAA7134_REMOTE_GPIO; 7553 dev->has_remote = SAA7134_REMOTE_GPIO;
7513 break; 7554 break;
7514 case SAA7134_BOARD_MD5044: 7555 case SAA7134_BOARD_MD5044:
7515 printk("%s: seems there are two different versions of the MD5044\n" 7556 pr_warn("%s: seems there are two different versions of the MD5044\n"
7516 "%s: (with the same ID) out there. If sound doesn't work for\n" 7557 "%s: (with the same ID) out there. If sound doesn't work for\n"
7517 "%s: you try the audio_clock_override=0x200000 insmod option.\n", 7558 "%s: you try the audio_clock_override=0x200000 insmod option.\n",
7518 dev->name,dev->name,dev->name); 7559 dev->name, dev->name, dev->name);
7519 break; 7560 break;
7520 case SAA7134_BOARD_CINERGY400_CARDBUS: 7561 case SAA7134_BOARD_CINERGY400_CARDBUS:
7521 /* power-up tuner chip */ 7562 /* power-up tuner chip */
@@ -7640,10 +7681,10 @@ int saa7134_board_init1(struct saa7134_dev *dev)
7640 dev->has_remote = SAA7134_REMOTE_I2C; 7681 dev->has_remote = SAA7134_REMOTE_I2C;
7641 break; 7682 break;
7642 case SAA7134_BOARD_AVERMEDIA_A169_B: 7683 case SAA7134_BOARD_AVERMEDIA_A169_B:
7643 printk("%s: %s: dual saa713x broadcast decoders\n" 7684 pr_warn("%s: %s: dual saa713x broadcast decoders\n"
7644 "%s: Sorry, none of the inputs to this chip are supported yet.\n" 7685 "%s: Sorry, none of the inputs to this chip are supported yet.\n"
7645 "%s: Dual decoder functionality is disabled for now, use the other chip.\n", 7686 "%s: Dual decoder functionality is disabled for now, use the other chip.\n",
7646 dev->name,card(dev).name,dev->name,dev->name); 7687 dev->name, card(dev).name, dev->name, dev->name);
7647 break; 7688 break;
7648 case SAA7134_BOARD_AVERMEDIA_M102: 7689 case SAA7134_BOARD_AVERMEDIA_M102:
7649 /* enable tuner */ 7690 /* enable tuner */
@@ -7789,7 +7830,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7789 if (board == dev->board) 7830 if (board == dev->board)
7790 break; 7831 break;
7791 dev->board = board; 7832 dev->board = board;
7792 printk("%s: board type fixup: %s\n", dev->name, 7833 pr_warn("%s: board type fixup: %s\n", dev->name,
7793 saa7134_boards[dev->board].name); 7834 saa7134_boards[dev->board].name);
7794 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 7835 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
7795 7836
@@ -7797,10 +7838,11 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7797 case SAA7134_BOARD_MD7134: 7838 case SAA7134_BOARD_MD7134:
7798 { 7839 {
7799 u8 subaddr; 7840 u8 subaddr;
7800 u8 data[3]; 7841 u8 data[3], data1[] = { 0x09, 0x9f, 0x86, 0x11};
7801 int ret, tuner_t; 7842 int ret, tuner_t;
7802 struct i2c_msg msg[] = {{.addr=0x50, .flags=0, .buf=&subaddr, .len = 1}, 7843 struct i2c_msg msg[] = {{.addr = 0x50, .flags = 0, .buf = &subaddr, .len = 1},
7803 {.addr=0x50, .flags=I2C_M_RD, .buf=data, .len = 3}}; 7844 {.addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = 3}},
7845 msg1 = {.addr = 0x61, .flags = 0, .buf = data1, .len = sizeof(data1)};
7804 7846
7805 subaddr= 0x14; 7847 subaddr= 0x14;
7806 tuner_t = 0; 7848 tuner_t = 0;
@@ -7810,7 +7852,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7810 */ 7852 */
7811 ret = i2c_transfer(&dev->i2c_adap, msg, 2); 7853 ret = i2c_transfer(&dev->i2c_adap, msg, 2);
7812 if (ret != 2) { 7854 if (ret != 2) {
7813 printk(KERN_ERR "EEPROM read failure\n"); 7855 pr_err("EEPROM read failure\n");
7814 } else if ((data[0] != 0) && (data[0] != 0xff)) { 7856 } else if ((data[0] != 0) && (data[0] != 0xff)) {
7815 /* old config structure */ 7857 /* old config structure */
7816 subaddr = data[0] + 2; 7858 subaddr = data[0] + 2;
@@ -7825,7 +7867,8 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7825 dev->tuner_type = TUNER_PHILIPS_FM1216ME_MK3; 7867 dev->tuner_type = TUNER_PHILIPS_FM1216ME_MK3;
7826 break; 7868 break;
7827 default: 7869 default:
7828 printk(KERN_ERR "%s Can't determine tuner type %x from EEPROM\n", dev->name, tuner_t); 7870 pr_err("%s Can't determine tuner type %x from EEPROM\n",
7871 dev->name, tuner_t);
7829 } 7872 }
7830 } else if ((data[1] != 0) && (data[1] != 0xff)) { 7873 } else if ((data[1] != 0) && (data[1] != 0xff)) {
7831 /* new config structure */ 7874 /* new config structure */
@@ -7842,16 +7885,28 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7842 break; 7885 break;
7843 case 0x001d: 7886 case 0x001d:
7844 dev->tuner_type = TUNER_PHILIPS_FMD1216ME_MK3; 7887 dev->tuner_type = TUNER_PHILIPS_FMD1216ME_MK3;
7845 printk(KERN_INFO "%s Board has DVB-T\n", dev->name); 7888 pr_info("%s Board has DVB-T\n",
7889 dev->name);
7846 break; 7890 break;
7847 default: 7891 default:
7848 printk(KERN_ERR "%s Can't determine tuner type %x from EEPROM\n", dev->name, tuner_t); 7892 pr_err("%s Can't determine tuner type %x from EEPROM\n",
7893 dev->name, tuner_t);
7849 } 7894 }
7850 } else { 7895 } else {
7851 printk(KERN_ERR "%s unexpected config structure\n", dev->name); 7896 pr_err("%s unexpected config structure\n", dev->name);
7852 } 7897 }
7853 7898
7854 printk(KERN_INFO "%s Tuner type is %d\n", dev->name, dev->tuner_type); 7899 pr_info("%s Tuner type is %d\n", dev->name, dev->tuner_type);
7900
7901 /* The tuner TUNER_PHILIPS_FMD1216ME_MK3 after hardware */
7902 /* start has disabled IF and enabled DVB-T. When saa7134 */
7903 /* scan I2C devices it will not detect IF tda9887 and can`t*/
7904 /* watch TV without software reboot. To solve this problem */
7905 /* switch the tuner to analog TV mode manually. */
7906 if (dev->tuner_type == TUNER_PHILIPS_FMD1216ME_MK3) {
7907 if (i2c_transfer(&dev->i2c_adap, &msg1, 1) != 1)
7908 printk(KERN_WARNING "%s: Unable to enable IF of the tuner.\n", dev->name);
7909 }
7855 break; 7910 break;
7856 } 7911 }
7857 case SAA7134_BOARD_PHILIPS_EUROPA: 7912 case SAA7134_BOARD_PHILIPS_EUROPA:
@@ -7859,7 +7914,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7859 /* Reconfigure board as Snake reference design */ 7914 /* Reconfigure board as Snake reference design */
7860 dev->board = SAA7134_BOARD_PHILIPS_SNAKE; 7915 dev->board = SAA7134_BOARD_PHILIPS_SNAKE;
7861 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 7916 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
7862 printk(KERN_INFO "%s: Reconfigured board as %s\n", 7917 pr_info("%s: Reconfigured board as %s\n",
7863 dev->name, saa7134_boards[dev->board].name); 7918 dev->name, saa7134_boards[dev->board].name);
7864 break; 7919 break;
7865 } 7920 }
@@ -7887,7 +7942,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7887 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)}; 7942 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
7888 if (dev->autodetected && (dev->eedata[0x49] == 0x50)) { 7943 if (dev->autodetected && (dev->eedata[0x49] == 0x50)) {
7889 dev->board = SAA7134_BOARD_PHILIPS_TIGER_S; 7944 dev->board = SAA7134_BOARD_PHILIPS_TIGER_S;
7890 printk(KERN_INFO "%s: Reconfigured board as %s\n", 7945 pr_info("%s: Reconfigured board as %s\n",
7891 dev->name, saa7134_boards[dev->board].name); 7946 dev->name, saa7134_boards[dev->board].name);
7892 } 7947 }
7893 if (dev->board == SAA7134_BOARD_PHILIPS_TIGER_S) { 7948 if (dev->board == SAA7134_BOARD_PHILIPS_TIGER_S) {
@@ -7903,13 +7958,14 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7903 case SAA7134_BOARD_ASUSTeK_TVFM7135: 7958 case SAA7134_BOARD_ASUSTeK_TVFM7135:
7904 /* The card below is detected as card=53, but is different */ 7959 /* The card below is detected as card=53, but is different */
7905 if (dev->autodetected && (dev->eedata[0x27] == 0x03)) { 7960 if (dev->autodetected && (dev->eedata[0x27] == 0x03)) {
7906 dev->board = SAA7134_BOARD_ASUSTeK_P7131_ANALOG; 7961 dev->board = SAA7134_BOARD_ASUSTeK_P7131_ANALOG;
7907 printk(KERN_INFO "%s: P7131 analog only, using " 7962 pr_info("%s: P7131 analog only, using entry of %s\n",
7908 "entry of %s\n", 7963 dev->name, saa7134_boards[dev->board].name);
7909 dev->name, saa7134_boards[dev->board].name);
7910 7964
7911 /* IR init has already happened for other cards, so 7965 /*
7912 * we have to catch up. */ 7966 * IR init has already happened for other cards, so
7967 * we have to catch up.
7968 */
7913 dev->has_remote = SAA7134_REMOTE_GPIO; 7969 dev->has_remote = SAA7134_REMOTE_GPIO;
7914 saa7134_input_init1(dev); 7970 saa7134_input_init1(dev);
7915 } 7971 }
@@ -7972,12 +8028,12 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7972 msg.addr = 0x0b; 8028 msg.addr = 0x0b;
7973 msg.len = 1; 8029 msg.len = 1;
7974 if (1 != i2c_transfer(&dev->i2c_adap, &msg, 1)) { 8030 if (1 != i2c_transfer(&dev->i2c_adap, &msg, 1)) {
7975 printk(KERN_WARNING "%s: send wake up byte to pic16C505" 8031 pr_warn("%s: send wake up byte to pic16C505"
7976 "(IR chip) failed\n", dev->name); 8032 "(IR chip) failed\n", dev->name);
7977 } else { 8033 } else {
7978 msg.flags = I2C_M_RD; 8034 msg.flags = I2C_M_RD;
7979 rc = i2c_transfer(&dev->i2c_adap, &msg, 1); 8035 rc = i2c_transfer(&dev->i2c_adap, &msg, 1);
7980 printk(KERN_INFO "%s: probe IR chip @ i2c 0x%02x: %s\n", 8036 pr_info("%s: probe IR chip @ i2c 0x%02x: %s\n",
7981 dev->name, msg.addr, 8037 dev->name, msg.addr,
7982 (1 == rc) ? "yes" : "no"); 8038 (1 == rc) ? "yes" : "no");
7983 if (rc == 1) 8039 if (rc == 1)
@@ -8018,10 +8074,10 @@ int saa7134_board_init2(struct saa7134_dev *dev)
8018 dev->board = SAA7134_BOARD_VIDEOMATE_DVBT_200A; 8074 dev->board = SAA7134_BOARD_VIDEOMATE_DVBT_200A;
8019 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 8075 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
8020 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf; 8076 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
8021 printk(KERN_INFO "%s: Reconfigured board as %s\n", 8077 pr_info("%s: Reconfigured board as %s\n",
8022 dev->name, saa7134_boards[dev->board].name); 8078 dev->name, saa7134_boards[dev->board].name);
8023 } else { 8079 } else {
8024 printk(KERN_WARNING "%s: Unexpected tuner type info: %x in eeprom\n", 8080 pr_warn("%s: Unexpected tuner type info: %x in eeprom\n",
8025 dev->name, dev->eedata[0x41]); 8081 dev->name, dev->eedata[0x41]);
8026 break; 8082 break;
8027 } 8083 }
@@ -8043,9 +8099,8 @@ int saa7134_board_init2(struct saa7134_dev *dev)
8043 msg.buf = &buffer[i][0]; 8099 msg.buf = &buffer[i][0];
8044 msg.len = ARRAY_SIZE(buffer[0]); 8100 msg.len = ARRAY_SIZE(buffer[0]);
8045 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) 8101 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
8046 printk(KERN_WARNING 8102 pr_warn("%s: Unable to enable tuner(%i).\n",
8047 "%s: Unable to enable tuner(%i).\n", 8103 dev->name, i);
8048 dev->name, i);
8049 } 8104 }
8050 break; 8105 break;
8051 } 8106 }
@@ -8061,9 +8116,8 @@ int saa7134_board_init2(struct saa7134_dev *dev)
8061 /* watch TV without software reboot. For solve this problem */ 8116 /* watch TV without software reboot. For solve this problem */
8062 /* switch the tuner to analog TV mode manually. */ 8117 /* switch the tuner to analog TV mode manually. */
8063 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) 8118 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
8064 printk(KERN_WARNING 8119 pr_warn("%s: Unable to enable IF of the tuner.\n",
8065 "%s: Unable to enable IF of the tuner.\n", 8120 dev->name);
8066 dev->name);
8067 break; 8121 break;
8068 } 8122 }
8069 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG: 8123 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index a349e964e0bc..72d7f992375e 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -20,6 +20,9 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
@@ -33,9 +36,6 @@
33#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
34#include <linux/pm.h> 37#include <linux/pm.h>
35 38
36#include "saa7134-reg.h"
37#include "saa7134.h"
38
39MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards"); 39MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards");
40MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 40MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
41MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
@@ -102,8 +102,15 @@ static unsigned int saa7134_devcount;
102int (*saa7134_dmasound_init)(struct saa7134_dev *dev); 102int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
103int (*saa7134_dmasound_exit)(struct saa7134_dev *dev); 103int (*saa7134_dmasound_exit)(struct saa7134_dev *dev);
104 104
105#define dprintk(fmt, arg...) if (core_debug) \ 105#define core_dbg(fmt, arg...) do { \
106 printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg) 106 if (core_debug) \
107 printk(KERN_DEBUG pr_fmt("core: " fmt), ## arg); \
108 } while (0)
109
110#define irq_dbg(level, fmt, arg...) do {\
111 if (irq_debug > level) \
112 printk(KERN_DEBUG pr_fmt("irq: " fmt), ## arg); \
113 } while (0)
107 114
108void saa7134_track_gpio(struct saa7134_dev *dev, char *msg) 115void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
109{ 116{
@@ -116,8 +123,7 @@ void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
116 saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,SAA7134_GPIO_GPRESCAN); 123 saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,SAA7134_GPIO_GPRESCAN);
117 mode = saa_readl(SAA7134_GPIO_GPMODE0 >> 2) & 0xfffffff; 124 mode = saa_readl(SAA7134_GPIO_GPMODE0 >> 2) & 0xfffffff;
118 status = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & 0xfffffff; 125 status = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & 0xfffffff;
119 printk(KERN_DEBUG 126 core_dbg("%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
120 "%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
121 dev->name, mode, (~mode) & status, mode & status, msg); 127 dev->name, mode, (~mode) & status, mode & status, msg);
122} 128}
123 129
@@ -128,7 +134,8 @@ void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value)
128 index = 1 << bit_no; 134 index = 1 << bit_no;
129 switch (value) { 135 switch (value) {
130 case 0: /* static value */ 136 case 0: /* static value */
131 case 1: dprintk("setting GPIO%d to static %d\n", bit_no, value); 137 case 1:
138 core_dbg("setting GPIO%d to static %d\n", bit_no, value);
132 /* turn sync mode off if necessary */ 139 /* turn sync mode off if necessary */
133 if (index & 0x00c00000) 140 if (index & 0x00c00000)
134 saa_andorb(SAA7134_VIDEO_PORT_CTRL6, 0x0f, 0x00); 141 saa_andorb(SAA7134_VIDEO_PORT_CTRL6, 0x0f, 0x00);
@@ -140,7 +147,7 @@ void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value)
140 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, index, bitval); 147 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, index, bitval);
141 break; 148 break;
142 case 3: /* tristate */ 149 case 3: /* tristate */
143 dprintk("setting GPIO%d to tristate\n", bit_no); 150 core_dbg("setting GPIO%d to tristate\n", bit_no);
144 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, index, 0); 151 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, index, 0);
145 break; 152 break;
146 } 153 }
@@ -274,7 +281,7 @@ int saa7134_buffer_queue(struct saa7134_dev *dev,
274 unsigned long flags; 281 unsigned long flags;
275 282
276 spin_lock_irqsave(&dev->slock, flags); 283 spin_lock_irqsave(&dev->slock, flags);
277 dprintk("buffer_queue %p\n", buf); 284 core_dbg("buffer_queue %p\n", buf);
278 if (NULL == q->curr) { 285 if (NULL == q->curr) {
279 if (!q->need_two) { 286 if (!q->need_two) {
280 q->curr = buf; 287 q->curr = buf;
@@ -298,7 +305,7 @@ void saa7134_buffer_finish(struct saa7134_dev *dev,
298 struct saa7134_dmaqueue *q, 305 struct saa7134_dmaqueue *q,
299 unsigned int state) 306 unsigned int state)
300{ 307{
301 dprintk("buffer_finish %p\n", q->curr); 308 core_dbg("buffer_finish %p\n", q->curr);
302 309
303 /* finish current buffer */ 310 /* finish current buffer */
304 v4l2_get_timestamp(&q->curr->vb2.v4l2_buf.timestamp); 311 v4l2_get_timestamp(&q->curr->vb2.v4l2_buf.timestamp);
@@ -318,18 +325,18 @@ void saa7134_buffer_next(struct saa7134_dev *dev,
318 if (!list_empty(&q->queue)) { 325 if (!list_empty(&q->queue)) {
319 /* activate next one from queue */ 326 /* activate next one from queue */
320 buf = list_entry(q->queue.next, struct saa7134_buf, entry); 327 buf = list_entry(q->queue.next, struct saa7134_buf, entry);
321 dprintk("buffer_next %p [prev=%p/next=%p]\n", 328 core_dbg("buffer_next %p [prev=%p/next=%p]\n",
322 buf, q->queue.prev, q->queue.next); 329 buf, q->queue.prev, q->queue.next);
323 list_del(&buf->entry); 330 list_del(&buf->entry);
324 if (!list_empty(&q->queue)) 331 if (!list_empty(&q->queue))
325 next = list_entry(q->queue.next, struct saa7134_buf, entry); 332 next = list_entry(q->queue.next, struct saa7134_buf, entry);
326 q->curr = buf; 333 q->curr = buf;
327 buf->activate(dev, buf, next); 334 buf->activate(dev, buf, next);
328 dprintk("buffer_next #2 prev=%p/next=%p\n", 335 core_dbg("buffer_next #2 prev=%p/next=%p\n",
329 q->queue.prev, q->queue.next); 336 q->queue.prev, q->queue.next);
330 } else { 337 } else {
331 /* nothing to do -- just stop DMA */ 338 /* nothing to do -- just stop DMA */
332 dprintk("buffer_next %p\n", NULL); 339 core_dbg("buffer_next %p\n", NULL);
333 saa7134_set_dmabits(dev); 340 saa7134_set_dmabits(dev);
334 del_timer(&q->timeout); 341 del_timer(&q->timeout);
335 } 342 }
@@ -351,7 +358,7 @@ void saa7134_buffer_timeout(unsigned long data)
351 /* flag current buffer as failed, 358 /* flag current buffer as failed,
352 try to start over with the next one. */ 359 try to start over with the next one. */
353 if (q->curr) { 360 if (q->curr) {
354 dprintk("timeout on %p\n", q->curr); 361 core_dbg("timeout on %p\n", q->curr);
355 saa7134_buffer_finish(dev, q, VB2_BUF_STATE_ERROR); 362 saa7134_buffer_finish(dev, q, VB2_BUF_STATE_ERROR);
356 } 363 }
357 saa7134_buffer_next(dev, q); 364 saa7134_buffer_next(dev, q);
@@ -474,7 +481,7 @@ int saa7134_set_dmabits(struct saa7134_dev *dev)
474 SAA7134_MAIN_CTRL_TE5 | 481 SAA7134_MAIN_CTRL_TE5 |
475 SAA7134_MAIN_CTRL_TE6, 482 SAA7134_MAIN_CTRL_TE6,
476 ctrl); 483 ctrl);
477 dprintk("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n", 484 core_dbg("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n",
478 task, ctrl, irq, split ? "no" : "yes"); 485 task, ctrl, irq, split ? "no" : "yes");
479 486
480 return 0; 487 return 0;
@@ -496,21 +503,21 @@ static void print_irqstatus(struct saa7134_dev *dev, int loop,
496{ 503{
497 unsigned int i; 504 unsigned int i;
498 505
499 printk(KERN_DEBUG "%s/irq[%d,%ld]: r=0x%lx s=0x%02lx", 506 irq_dbg(1, "[%d,%ld]: r=0x%lx s=0x%02lx",
500 dev->name,loop,jiffies,report,status); 507 loop, jiffies, report, status);
501 for (i = 0; i < IRQBITS; i++) { 508 for (i = 0; i < IRQBITS; i++) {
502 if (!(report & (1 << i))) 509 if (!(report & (1 << i)))
503 continue; 510 continue;
504 printk(" %s",irqbits[i]); 511 pr_cont(" %s", irqbits[i]);
505 } 512 }
506 if (report & SAA7134_IRQ_REPORT_DONE_RA0) { 513 if (report & SAA7134_IRQ_REPORT_DONE_RA0) {
507 printk(" | RA0=%s,%s,%s,%ld", 514 pr_cont(" | RA0=%s,%s,%s,%ld",
508 (status & 0x40) ? "vbi" : "video", 515 (status & 0x40) ? "vbi" : "video",
509 (status & 0x20) ? "b" : "a", 516 (status & 0x20) ? "b" : "a",
510 (status & 0x10) ? "odd" : "even", 517 (status & 0x10) ? "odd" : "even",
511 (status & 0x0f)); 518 (status & 0x0f));
512 } 519 }
513 printk("\n"); 520 pr_cont("\n");
514} 521}
515 522
516static irqreturn_t saa7134_irq(int irq, void *dev_id) 523static irqreturn_t saa7134_irq(int irq, void *dev_id)
@@ -532,16 +539,12 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
532 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) && 539 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) &&
533 (dev->dmasound.priv_data != NULL) ) 540 (dev->dmasound.priv_data != NULL) )
534 { 541 {
535 if (irq_debug > 1) 542 irq_dbg(2, "preserving DMA sound interrupt\n");
536 printk(KERN_DEBUG "%s/irq: preserving DMA sound interrupt\n",
537 dev->name);
538 report &= ~SAA7134_IRQ_REPORT_DONE_RA3; 543 report &= ~SAA7134_IRQ_REPORT_DONE_RA3;
539 } 544 }
540 545
541 if (0 == report) { 546 if (0 == report) {
542 if (irq_debug > 1) 547 irq_dbg(2, "no (more) work\n");
543 printk(KERN_DEBUG "%s/irq: no (more) work\n",
544 dev->name);
545 goto out; 548 goto out;
546 } 549 }
547 550
@@ -614,24 +617,24 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
614 print_irqstatus(dev,loop,report,status); 617 print_irqstatus(dev,loop,report,status);
615 if (report & SAA7134_IRQ_REPORT_PE) { 618 if (report & SAA7134_IRQ_REPORT_PE) {
616 /* disable all parity error */ 619 /* disable all parity error */
617 printk(KERN_WARNING "%s/irq: looping -- " 620 pr_warn("%s/irq: looping -- "
618 "clearing PE (parity error!) enable bit\n",dev->name); 621 "clearing PE (parity error!) enable bit\n",dev->name);
619 saa_clearl(SAA7134_IRQ2,SAA7134_IRQ2_INTE_PE); 622 saa_clearl(SAA7134_IRQ2,SAA7134_IRQ2_INTE_PE);
620 } else if (report & SAA7134_IRQ_REPORT_GPIO16) { 623 } else if (report & SAA7134_IRQ_REPORT_GPIO16) {
621 /* disable gpio16 IRQ */ 624 /* disable gpio16 IRQ */
622 printk(KERN_WARNING "%s/irq: looping -- " 625 pr_warn("%s/irq: looping -- "
623 "clearing GPIO16 enable bit\n",dev->name); 626 "clearing GPIO16 enable bit\n",dev->name);
624 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_P); 627 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_P);
625 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_N); 628 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_N);
626 } else if (report & SAA7134_IRQ_REPORT_GPIO18) { 629 } else if (report & SAA7134_IRQ_REPORT_GPIO18) {
627 /* disable gpio18 IRQs */ 630 /* disable gpio18 IRQs */
628 printk(KERN_WARNING "%s/irq: looping -- " 631 pr_warn("%s/irq: looping -- "
629 "clearing GPIO18 enable bit\n",dev->name); 632 "clearing GPIO18 enable bit\n",dev->name);
630 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P); 633 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
631 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_N); 634 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_N);
632 } else { 635 } else {
633 /* disable all irqs */ 636 /* disable all irqs */
634 printk(KERN_WARNING "%s/irq: looping -- " 637 pr_warn("%s/irq: looping -- "
635 "clearing all enable bits\n",dev->name); 638 "clearing all enable bits\n",dev->name);
636 saa_writel(SAA7134_IRQ1,0); 639 saa_writel(SAA7134_IRQ1,0);
637 saa_writel(SAA7134_IRQ2,0); 640 saa_writel(SAA7134_IRQ2,0);
@@ -680,7 +683,7 @@ static int saa7134_hw_enable1(struct saa7134_dev *dev)
680 683
681static int saa7134_hwinit1(struct saa7134_dev *dev) 684static int saa7134_hwinit1(struct saa7134_dev *dev)
682{ 685{
683 dprintk("hwinit1\n"); 686 core_dbg("hwinit1\n");
684 687
685 saa_writel(SAA7134_IRQ1, 0); 688 saa_writel(SAA7134_IRQ1, 0);
686 saa_writel(SAA7134_IRQ2, 0); 689 saa_writel(SAA7134_IRQ2, 0);
@@ -742,7 +745,7 @@ static int saa7134_hw_enable2(struct saa7134_dev *dev)
742static int saa7134_hwinit2(struct saa7134_dev *dev) 745static int saa7134_hwinit2(struct saa7134_dev *dev)
743{ 746{
744 747
745 dprintk("hwinit2\n"); 748 core_dbg("hwinit2\n");
746 749
747 saa7134_video_init2(dev); 750 saa7134_video_init2(dev);
748 saa7134_tvaudio_init2(dev); 751 saa7134_tvaudio_init2(dev);
@@ -756,7 +759,7 @@ static int saa7134_hwinit2(struct saa7134_dev *dev)
756/* shutdown */ 759/* shutdown */
757static int saa7134_hwfini(struct saa7134_dev *dev) 760static int saa7134_hwfini(struct saa7134_dev *dev)
758{ 761{
759 dprintk("hwfini\n"); 762 core_dbg("hwfini\n");
760 763
761 if (card_has_mpeg(dev)) 764 if (card_has_mpeg(dev))
762 saa7134_ts_fini(dev); 765 saa7134_ts_fini(dev);
@@ -772,34 +775,32 @@ static void must_configure_manually(int has_eeprom)
772 unsigned int i,p; 775 unsigned int i,p;
773 776
774 if (!has_eeprom) 777 if (!has_eeprom)
775 printk(KERN_WARNING 778 pr_warn("saa7134: <rant>\n"
776 "saa7134: <rant>\n" 779 "saa7134: Congratulations! Your TV card vendor saved a few\n"
777 "saa7134: Congratulations! Your TV card vendor saved a few\n" 780 "saa7134: cents for a eeprom, thus your pci board has no\n"
778 "saa7134: cents for a eeprom, thus your pci board has no\n" 781 "saa7134: subsystem ID and I can't identify it automatically\n"
779 "saa7134: subsystem ID and I can't identify it automatically\n" 782 "saa7134: </rant>\n"
780 "saa7134: </rant>\n" 783 "saa7134: I feel better now. Ok, here are the good news:\n"
781 "saa7134: I feel better now. Ok, here are the good news:\n" 784 "saa7134: You can use the card=<nr> insmod option to specify\n"
782 "saa7134: You can use the card=<nr> insmod option to specify\n" 785 "saa7134: which board do you have. The list:\n");
783 "saa7134: which board do you have. The list:\n");
784 else 786 else
785 printk(KERN_WARNING 787 pr_warn("saa7134: Board is currently unknown. You might try to use the card=<nr>\n"
786 "saa7134: Board is currently unknown. You might try to use the card=<nr>\n" 788 "saa7134: insmod option to specify which board do you have, but this is\n"
787 "saa7134: insmod option to specify which board do you have, but this is\n" 789 "saa7134: somewhat risky, as might damage your card. It is better to ask\n"
788 "saa7134: somewhat risky, as might damage your card. It is better to ask\n" 790 "saa7134: for support at linux-media@vger.kernel.org.\n"
789 "saa7134: for support at linux-media@vger.kernel.org.\n" 791 "saa7134: The supported cards are:\n");
790 "saa7134: The supported cards are:\n");
791 792
792 for (i = 0; i < saa7134_bcount; i++) { 793 for (i = 0; i < saa7134_bcount; i++) {
793 printk(KERN_WARNING "saa7134: card=%d -> %-40.40s", 794 pr_warn("saa7134: card=%d -> %-40.40s",
794 i,saa7134_boards[i].name); 795 i,saa7134_boards[i].name);
795 for (p = 0; saa7134_pci_tbl[p].driver_data; p++) { 796 for (p = 0; saa7134_pci_tbl[p].driver_data; p++) {
796 if (saa7134_pci_tbl[p].driver_data != i) 797 if (saa7134_pci_tbl[p].driver_data != i)
797 continue; 798 continue;
798 printk(" %04x:%04x", 799 pr_cont(" %04x:%04x",
799 saa7134_pci_tbl[p].subvendor, 800 saa7134_pci_tbl[p].subvendor,
800 saa7134_pci_tbl[p].subdevice); 801 saa7134_pci_tbl[p].subdevice);
801 } 802 }
802 printk("\n"); 803 pr_cont("\n");
803 } 804 }
804} 805}
805 806
@@ -903,31 +904,31 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
903 /* pci quirks */ 904 /* pci quirks */
904 if (pci_pci_problems) { 905 if (pci_pci_problems) {
905 if (pci_pci_problems & PCIPCI_TRITON) 906 if (pci_pci_problems & PCIPCI_TRITON)
906 printk(KERN_INFO "%s: quirk: PCIPCI_TRITON\n", dev->name); 907 pr_info("%s: quirk: PCIPCI_TRITON\n", dev->name);
907 if (pci_pci_problems & PCIPCI_NATOMA) 908 if (pci_pci_problems & PCIPCI_NATOMA)
908 printk(KERN_INFO "%s: quirk: PCIPCI_NATOMA\n", dev->name); 909 pr_info("%s: quirk: PCIPCI_NATOMA\n", dev->name);
909 if (pci_pci_problems & PCIPCI_VIAETBF) 910 if (pci_pci_problems & PCIPCI_VIAETBF)
910 printk(KERN_INFO "%s: quirk: PCIPCI_VIAETBF\n", dev->name); 911 pr_info("%s: quirk: PCIPCI_VIAETBF\n", dev->name);
911 if (pci_pci_problems & PCIPCI_VSFX) 912 if (pci_pci_problems & PCIPCI_VSFX)
912 printk(KERN_INFO "%s: quirk: PCIPCI_VSFX\n",dev->name); 913 pr_info("%s: quirk: PCIPCI_VSFX\n", dev->name);
913#ifdef PCIPCI_ALIMAGIK 914#ifdef PCIPCI_ALIMAGIK
914 if (pci_pci_problems & PCIPCI_ALIMAGIK) { 915 if (pci_pci_problems & PCIPCI_ALIMAGIK) {
915 printk(KERN_INFO "%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n", 916 pr_info("%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
916 dev->name); 917 dev->name);
917 latency = 0x0A; 918 latency = 0x0A;
918 } 919 }
919#endif 920#endif
920 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) { 921 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) {
921 printk(KERN_INFO "%s: quirk: this driver and your " 922 pr_info("%s: quirk: this driver and your "
922 "chipset may not work together" 923 "chipset may not work together"
923 " in overlay mode.\n",dev->name); 924 " in overlay mode.\n",dev->name);
924 if (!saa7134_no_overlay) { 925 if (!saa7134_no_overlay) {
925 printk(KERN_INFO "%s: quirk: overlay " 926 pr_info("%s: quirk: overlay "
926 "mode will be disabled.\n", 927 "mode will be disabled.\n",
927 dev->name); 928 dev->name);
928 saa7134_no_overlay = 1; 929 saa7134_no_overlay = 1;
929 } else { 930 } else {
930 printk(KERN_INFO "%s: quirk: overlay " 931 pr_info("%s: quirk: overlay "
931 "mode will be forced. Use this" 932 "mode will be forced. Use this"
932 " option at your own risk.\n", 933 " option at your own risk.\n",
933 dev->name); 934 dev->name);
@@ -935,7 +936,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
935 } 936 }
936 } 937 }
937 if (UNSET != latency) { 938 if (UNSET != latency) {
938 printk(KERN_INFO "%s: setting pci latency timer to %d\n", 939 pr_info("%s: setting pci latency timer to %d\n",
939 dev->name,latency); 940 dev->name,latency);
940 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency); 941 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
941 } 942 }
@@ -943,13 +944,13 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
943 /* print pci info */ 944 /* print pci info */
944 dev->pci_rev = pci_dev->revision; 945 dev->pci_rev = pci_dev->revision;
945 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat); 946 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
946 printk(KERN_INFO "%s: found at %s, rev: %d, irq: %d, " 947 pr_info("%s: found at %s, rev: %d, irq: %d, "
947 "latency: %d, mmio: 0x%llx\n", dev->name, 948 "latency: %d, mmio: 0x%llx\n", dev->name,
948 pci_name(pci_dev), dev->pci_rev, pci_dev->irq, 949 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
949 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0)); 950 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
950 pci_set_master(pci_dev); 951 pci_set_master(pci_dev);
951 if (!pci_dma_supported(pci_dev, DMA_BIT_MASK(32))) { 952 if (!pci_dma_supported(pci_dev, DMA_BIT_MASK(32))) {
952 printk("%s: Oops: no 32bit PCI DMA ???\n",dev->name); 953 pr_warn("%s: Oops: no 32bit PCI DMA ???\n", dev->name);
953 err = -EIO; 954 err = -EIO;
954 goto fail1; 955 goto fail1;
955 } 956 }
@@ -972,7 +973,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
972 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf; 973 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
973 if (UNSET != tuner[dev->nr]) 974 if (UNSET != tuner[dev->nr])
974 dev->tuner_type = tuner[dev->nr]; 975 dev->tuner_type = tuner[dev->nr];
975 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 976 pr_info("%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
976 dev->name,pci_dev->subsystem_vendor, 977 dev->name,pci_dev->subsystem_vendor,
977 pci_dev->subsystem_device,saa7134_boards[dev->board].name, 978 pci_dev->subsystem_device,saa7134_boards[dev->board].name,
978 dev->board, dev->autodetected ? 979 dev->board, dev->autodetected ?
@@ -983,7 +984,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
983 pci_resource_len(pci_dev,0), 984 pci_resource_len(pci_dev,0),
984 dev->name)) { 985 dev->name)) {
985 err = -EBUSY; 986 err = -EBUSY;
986 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n", 987 pr_err("%s: can't get MMIO memory @ 0x%llx\n",
987 dev->name,(unsigned long long)pci_resource_start(pci_dev,0)); 988 dev->name,(unsigned long long)pci_resource_start(pci_dev,0));
988 goto fail1; 989 goto fail1;
989 } 990 }
@@ -992,7 +993,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
992 dev->bmmio = (__u8 __iomem *)dev->lmmio; 993 dev->bmmio = (__u8 __iomem *)dev->lmmio;
993 if (NULL == dev->lmmio) { 994 if (NULL == dev->lmmio) {
994 err = -EIO; 995 err = -EIO;
995 printk(KERN_ERR "%s: can't ioremap() MMIO memory\n", 996 pr_err("%s: can't ioremap() MMIO memory\n",
996 dev->name); 997 dev->name);
997 goto fail2; 998 goto fail2;
998 } 999 }
@@ -1010,7 +1011,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1010 err = request_irq(pci_dev->irq, saa7134_irq, 1011 err = request_irq(pci_dev->irq, saa7134_irq,
1011 IRQF_SHARED, dev->name, dev); 1012 IRQF_SHARED, dev->name, dev);
1012 if (err < 0) { 1013 if (err < 0) {
1013 printk(KERN_ERR "%s: can't get IRQ %d\n", 1014 pr_err("%s: can't get IRQ %d\n",
1014 dev->name,pci_dev->irq); 1015 dev->name,pci_dev->irq);
1015 goto fail4; 1016 goto fail4;
1016 } 1017 }
@@ -1040,7 +1041,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1040 &dev->i2c_adap, "saa6588", 1041 &dev->i2c_adap, "saa6588",
1041 0, I2C_ADDRS(saa7134_boards[dev->board].rds_addr)); 1042 0, I2C_ADDRS(saa7134_boards[dev->board].rds_addr));
1042 if (sd) { 1043 if (sd) {
1043 printk(KERN_INFO "%s: found RDS decoder\n", dev->name); 1044 pr_info("%s: found RDS decoder\n", dev->name);
1044 dev->has_rds = 1; 1045 dev->has_rds = 1;
1045 } 1046 }
1046 } 1047 }
@@ -1059,7 +1060,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1059 1060
1060 /* register v4l devices */ 1061 /* register v4l devices */
1061 if (saa7134_no_overlay > 0) 1062 if (saa7134_no_overlay > 0)
1062 printk(KERN_INFO "%s: Overlay support disabled.\n", dev->name); 1063 pr_info("%s: Overlay support disabled.\n", dev->name);
1063 1064
1064 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video"); 1065 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video");
1065 dev->video_dev->ctrl_handler = &dev->ctrl_handler; 1066 dev->video_dev->ctrl_handler = &dev->ctrl_handler;
@@ -1068,11 +1069,11 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1068 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, 1069 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1069 video_nr[dev->nr]); 1070 video_nr[dev->nr]);
1070 if (err < 0) { 1071 if (err < 0) {
1071 printk(KERN_INFO "%s: can't register video device\n", 1072 pr_info("%s: can't register video device\n",
1072 dev->name); 1073 dev->name);
1073 goto fail5; 1074 goto fail5;
1074 } 1075 }
1075 printk(KERN_INFO "%s: registered device %s [v4l2]\n", 1076 pr_info("%s: registered device %s [v4l2]\n",
1076 dev->name, video_device_node_name(dev->video_dev)); 1077 dev->name, video_device_node_name(dev->video_dev));
1077 1078
1078 dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi"); 1079 dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi");
@@ -1084,7 +1085,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1084 vbi_nr[dev->nr]); 1085 vbi_nr[dev->nr]);
1085 if (err < 0) 1086 if (err < 0)
1086 goto fail5; 1087 goto fail5;
1087 printk(KERN_INFO "%s: registered device %s\n", 1088 pr_info("%s: registered device %s\n",
1088 dev->name, video_device_node_name(dev->vbi_dev)); 1089 dev->name, video_device_node_name(dev->vbi_dev));
1089 1090
1090 if (card_has_radio(dev)) { 1091 if (card_has_radio(dev)) {
@@ -1095,7 +1096,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1095 radio_nr[dev->nr]); 1096 radio_nr[dev->nr]);
1096 if (err < 0) 1097 if (err < 0)
1097 goto fail5; 1098 goto fail5;
1098 printk(KERN_INFO "%s: registered device %s\n", 1099 pr_info("%s: registered device %s\n",
1099 dev->name, video_device_node_name(dev->radio_dev)); 1100 dev->name, video_device_node_name(dev->radio_dev));
1100 } 1101 }
1101 1102
@@ -1204,12 +1205,12 @@ static int saa7134_buffer_requeue(struct saa7134_dev *dev,
1204 1205
1205 buf = q->curr; 1206 buf = q->curr;
1206 next = buf; 1207 next = buf;
1207 dprintk("buffer_requeue\n"); 1208 core_dbg("buffer_requeue\n");
1208 1209
1209 if (!buf) 1210 if (!buf)
1210 return 0; 1211 return 0;
1211 1212
1212 dprintk("buffer_requeue : resending active buffers \n"); 1213 core_dbg("buffer_requeue : resending active buffer\n");
1213 1214
1214 if (!list_empty(&q->queue)) 1215 if (!list_empty(&q->queue))
1215 next = list_entry(q->queue.next, struct saa7134_buf, 1216 next = list_entry(q->queue.next, struct saa7134_buf,
@@ -1358,7 +1359,7 @@ static struct pci_driver saa7134_pci_driver = {
1358static int __init saa7134_init(void) 1359static int __init saa7134_init(void)
1359{ 1360{
1360 INIT_LIST_HEAD(&saa7134_devlist); 1361 INIT_LIST_HEAD(&saa7134_devlist);
1361 printk(KERN_INFO "saa7130/34: v4l2 driver version %s loaded\n", 1362 pr_info("saa7130/34: v4l2 driver version %s loaded\n",
1362 SAA7134_VERSION); 1363 SAA7134_VERSION);
1363 return pci_register_driver(&saa7134_pci_driver); 1364 return pci_register_driver(&saa7134_pci_driver);
1364} 1365}
diff --git a/drivers/media/pci/saa7134/saa7134-dvb.c b/drivers/media/pci/saa7134/saa7134-dvb.c
index 73ffbabf831c..101ba8729416 100644
--- a/drivers/media/pci/saa7134/saa7134-dvb.c
+++ b/drivers/media/pci/saa7134/saa7134-dvb.c
@@ -20,6 +20,9 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
@@ -28,8 +31,6 @@
28#include <linux/kthread.h> 31#include <linux/kthread.h>
29#include <linux/suspend.h> 32#include <linux/suspend.h>
30 33
31#include "saa7134-reg.h"
32#include "saa7134.h"
33#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
34#include "dvb-pll.h" 35#include "dvb-pll.h"
35#include <dvb_frontend.h> 36#include <dvb_frontend.h>
@@ -75,19 +76,8 @@ static int use_frontend;
75module_param(use_frontend, int, 0644); 76module_param(use_frontend, int, 0644);
76MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)"); 77MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
77 78
78static int debug;
79module_param(debug, int, 0644);
80MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
81
82DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 79DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
83 80
84#define dprintk(fmt, arg...) do { if (debug) \
85 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
86
87/* Print a warning */
88#define wprintk(fmt, arg...) \
89 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
90
91/* ------------------------------------------------------------------ 81/* ------------------------------------------------------------------
92 * mt352 based DVB-T cards 82 * mt352 based DVB-T cards
93 */ 83 */
@@ -112,7 +102,7 @@ static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
112 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28)); 102 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
113 udelay(10); 103 udelay(10);
114 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27); 104 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
115 dprintk("%s %s\n", __func__, ok ? "on" : "off"); 105 pr_debug("%s %s\n", __func__, ok ? "on" : "off");
116 106
117 if (!ok) 107 if (!ok)
118 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26)); 108 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
@@ -130,9 +120,8 @@ static int mt352_pinnacle_init(struct dvb_frontend* fe)
130 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f }; 120 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
131 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d }; 121 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
132 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 }; 122 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
133 struct saa7134_dev *dev= fe->dvb->priv;
134 123
135 dprintk("%s called\n", __func__); 124 pr_debug("%s called\n", __func__);
136 125
137 mt352_write(fe, clock_config, sizeof(clock_config)); 126 mt352_write(fe, clock_config, sizeof(clock_config));
138 udelay(200); 127 udelay(200);
@@ -258,7 +247,7 @@ static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)
258 struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2}; 247 struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
259 248
260 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) { 249 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
261 wprintk("could not access the I2C gate\n"); 250 pr_warn("could not access the I2C gate\n");
262 return -EIO; 251 return -EIO;
263 } 252 }
264 if (enable) 253 if (enable)
@@ -266,7 +255,7 @@ static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)
266 else 255 else
267 msg.buf = msg_disable; 256 msg.buf = msg_disable;
268 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) { 257 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
269 wprintk("could not access the I2C gate\n"); 258 pr_warn("could not access the I2C gate\n");
270 return -EIO; 259 return -EIO;
271 } 260 }
272 msleep(20); 261 msleep(20);
@@ -369,7 +358,7 @@ static int philips_tda6651_pll_set(struct dvb_frontend *fe)
369 if (fe->ops.i2c_gate_ctrl) 358 if (fe->ops.i2c_gate_ctrl)
370 fe->ops.i2c_gate_ctrl(fe, 1); 359 fe->ops.i2c_gate_ctrl(fe, 1);
371 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) { 360 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
372 wprintk("could not write to tuner at addr: 0x%02x\n", 361 pr_warn("could not write to tuner at addr: 0x%02x\n",
373 addr << 1); 362 addr << 1);
374 return -EIO; 363 return -EIO;
375 } 364 }
@@ -556,8 +545,7 @@ static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
556 tda8290_msg.buf = tda8290_open; 545 tda8290_msg.buf = tda8290_open;
557 } 546 }
558 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) { 547 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
559 struct saa7134_dev *dev = fe->dvb->priv; 548 pr_warn("could not access tda8290 I2C gate\n");
560 wprintk("could not access tda8290 I2C gate\n");
561 return -EIO; 549 return -EIO;
562 } 550 }
563 msleep(20); 551 msleep(20);
@@ -570,11 +558,14 @@ static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
570 struct tda1004x_state *state = fe->demodulator_priv; 558 struct tda1004x_state *state = fe->demodulator_priv;
571 559
572 switch (state->config->antenna_switch) { 560 switch (state->config->antenna_switch) {
573 case 0: break; 561 case 0:
574 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n"); 562 break;
563 case 1:
564 pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
575 saa7134_set_gpio(dev, 21, 0); 565 saa7134_set_gpio(dev, 21, 0);
576 break; 566 break;
577 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n"); 567 case 2:
568 pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
578 saa7134_set_gpio(dev, 21, 1); 569 saa7134_set_gpio(dev, 21, 1);
579 break; 570 break;
580 } 571 }
@@ -587,11 +578,14 @@ static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
587 struct tda1004x_state *state = fe->demodulator_priv; 578 struct tda1004x_state *state = fe->demodulator_priv;
588 579
589 switch (state->config->antenna_switch) { 580 switch (state->config->antenna_switch) {
590 case 0: break; 581 case 0:
591 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n"); 582 break;
583 case 1:
584 pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");
592 saa7134_set_gpio(dev, 21, 1); 585 saa7134_set_gpio(dev, 21, 1);
593 break; 586 break;
594 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n"); 587 case 2:
588 pr_debug("setting GPIO21 to 0 (TV antenna?)\n");
595 saa7134_set_gpio(dev, 21, 0); 589 saa7134_set_gpio(dev, 21, 0);
596 break; 590 break;
597 } 591 }
@@ -619,7 +613,7 @@ static int configure_tda827x_fe(struct saa7134_dev *dev,
619 &dev->i2c_adap, tuner_conf)) 613 &dev->i2c_adap, tuner_conf))
620 return 0; 614 return 0;
621 615
622 wprintk("no tda827x tuner found at addr: %02x\n", 616 pr_warn("no tda827x tuner found at addr: %02x\n",
623 cdec_conf->tuner_address); 617 cdec_conf->tuner_address);
624 } 618 }
625 return -EINVAL; 619 return -EINVAL;
@@ -993,7 +987,8 @@ static struct tda10086_config sd1878_4m = {
993 * special case: lnb supply is connected to the gated i2c 987 * special case: lnb supply is connected to the gated i2c
994 */ 988 */
995 989
996static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 990static int md8800_set_voltage(struct dvb_frontend *fe,
991 enum fe_sec_voltage voltage)
997{ 992{
998 int res = -EIO; 993 int res = -EIO;
999 struct saa7134_dev *dev = fe->dvb->priv; 994 struct saa7134_dev *dev = fe->dvb->priv;
@@ -1019,7 +1014,8 @@ static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
1019 return res; 1014 return res;
1020}; 1015};
1021 1016
1022static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 1017static int md8800_set_voltage2(struct dvb_frontend *fe,
1018 enum fe_sec_voltage voltage)
1023{ 1019{
1024 struct saa7134_dev *dev = fe->dvb->priv; 1020 struct saa7134_dev *dev = fe->dvb->priv;
1025 u8 wbuf[2] = { 0x1f, 00 }; 1021 u8 wbuf[2] = { 0x1f, 00 };
@@ -1041,8 +1037,8 @@ static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage
1041 1037
1042static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg) 1038static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
1043{ 1039{
1044 struct saa7134_dev *dev = fe->dvb->priv; 1040 pr_warn("%s: sorry can't set high LNB supply voltage from here\n",
1045 wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__); 1041 __func__);
1046 return -EIO; 1042 return -EIO;
1047} 1043}
1048 1044
@@ -1222,10 +1218,10 @@ static int dvb_init(struct saa7134_dev *dev)
1222 mutex_init(&dev->frontends.lock); 1218 mutex_init(&dev->frontends.lock);
1223 INIT_LIST_HEAD(&dev->frontends.felist); 1219 INIT_LIST_HEAD(&dev->frontends.felist);
1224 1220
1225 printk(KERN_INFO "%s() allocating 1 frontend\n", __func__); 1221 pr_info("%s() allocating 1 frontend\n", __func__);
1226 fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1); 1222 fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1);
1227 if (!fe0) { 1223 if (!fe0) {
1228 printk(KERN_ERR "%s() failed to alloc\n", __func__); 1224 pr_err("%s() failed to alloc\n", __func__);
1229 return -ENOMEM; 1225 return -ENOMEM;
1230 } 1226 }
1231 1227
@@ -1250,7 +1246,7 @@ static int dvb_init(struct saa7134_dev *dev)
1250 1246
1251 switch (dev->board) { 1247 switch (dev->board) {
1252 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 1248 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1253 dprintk("pinnacle 300i dvb setup\n"); 1249 pr_debug("pinnacle 300i dvb setup\n");
1254 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i, 1250 fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
1255 &dev->i2c_adap); 1251 &dev->i2c_adap);
1256 if (fe0->dvb.frontend) { 1252 if (fe0->dvb.frontend) {
@@ -1259,7 +1255,7 @@ static int dvb_init(struct saa7134_dev *dev)
1259 break; 1255 break;
1260 case SAA7134_BOARD_AVERMEDIA_777: 1256 case SAA7134_BOARD_AVERMEDIA_777:
1261 case SAA7134_BOARD_AVERMEDIA_A16AR: 1257 case SAA7134_BOARD_AVERMEDIA_A16AR:
1262 dprintk("avertv 777 dvb setup\n"); 1258 pr_debug("avertv 777 dvb setup\n");
1263 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777, 1259 fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
1264 &dev->i2c_adap); 1260 &dev->i2c_adap);
1265 if (fe0->dvb.frontend) { 1261 if (fe0->dvb.frontend) {
@@ -1269,7 +1265,7 @@ static int dvb_init(struct saa7134_dev *dev)
1269 } 1265 }
1270 break; 1266 break;
1271 case SAA7134_BOARD_AVERMEDIA_A16D: 1267 case SAA7134_BOARD_AVERMEDIA_A16D:
1272 dprintk("AverMedia A16D dvb setup\n"); 1268 pr_debug("AverMedia A16D dvb setup\n");
1273 fe0->dvb.frontend = dvb_attach(mt352_attach, 1269 fe0->dvb.frontend = dvb_attach(mt352_attach,
1274 &avermedia_xc3028_mt352_dev, 1270 &avermedia_xc3028_mt352_dev,
1275 &dev->i2c_adap); 1271 &dev->i2c_adap);
@@ -1401,13 +1397,15 @@ static int dvb_init(struct saa7134_dev *dev)
1401 if (fe0->dvb.frontend) { 1397 if (fe0->dvb.frontend) {
1402 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63, 1398 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
1403 &dev->i2c_adap, 0) == NULL) { 1399 &dev->i2c_adap, 0) == NULL) {
1404 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__); 1400 pr_warn("%s: Lifeview Trio, No tda826x found!\n",
1401 __func__);
1405 goto detach_frontend; 1402 goto detach_frontend;
1406 } 1403 }
1407 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, 1404 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1408 &dev->i2c_adap, 1405 &dev->i2c_adap,
1409 0x08, 0, 0, false) == NULL) { 1406 0x08, 0, 0, false) == NULL) {
1410 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__); 1407 pr_warn("%s: Lifeview Trio, No ISL6421 found!\n",
1408 __func__);
1411 goto detach_frontend; 1409 goto detach_frontend;
1412 } 1410 }
1413 } 1411 }
@@ -1422,12 +1420,12 @@ static int dvb_init(struct saa7134_dev *dev)
1422 if (dvb_attach(tda827x_attach,fe0->dvb.frontend, 1420 if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
1423 ads_tech_duo_config.tuner_address, &dev->i2c_adap, 1421 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1424 &ads_duo_cfg) == NULL) { 1422 &ads_duo_cfg) == NULL) {
1425 wprintk("no tda827x tuner found at addr: %02x\n", 1423 pr_warn("no tda827x tuner found at addr: %02x\n",
1426 ads_tech_duo_config.tuner_address); 1424 ads_tech_duo_config.tuner_address);
1427 goto detach_frontend; 1425 goto detach_frontend;
1428 } 1426 }
1429 } else 1427 } else
1430 wprintk("failed to attach tda10046\n"); 1428 pr_warn("failed to attach tda10046\n");
1431 break; 1429 break;
1432 case SAA7134_BOARD_TEVION_DVBT_220RF: 1430 case SAA7134_BOARD_TEVION_DVBT_220RF:
1433 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config, 1431 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
@@ -1450,7 +1448,7 @@ static int dvb_init(struct saa7134_dev *dev)
1450 1448
1451 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 1449 if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
1452 0x60, &dev->i2c_adap, 0) == NULL) { 1450 0x60, &dev->i2c_adap, 0) == NULL) {
1453 wprintk("%s: Medion Quadro, no tda826x " 1451 pr_warn("%s: Medion Quadro, no tda826x "
1454 "found !\n", __func__); 1452 "found !\n", __func__);
1455 goto detach_frontend; 1453 goto detach_frontend;
1456 } 1454 }
@@ -1459,7 +1457,7 @@ static int dvb_init(struct saa7134_dev *dev)
1459 fe->ops.i2c_gate_ctrl(fe, 1); 1457 fe->ops.i2c_gate_ctrl(fe, 1);
1460 if (dvb_attach(isl6405_attach, fe, 1458 if (dvb_attach(isl6405_attach, fe,
1461 &dev->i2c_adap, 0x08, 0, 0) == NULL) { 1459 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1462 wprintk("%s: Medion Quadro, no ISL6405 " 1460 pr_warn("%s: Medion Quadro, no ISL6405 "
1463 "found !\n", __func__); 1461 "found !\n", __func__);
1464 goto detach_frontend; 1462 goto detach_frontend;
1465 } 1463 }
@@ -1519,13 +1517,13 @@ static int dvb_init(struct saa7134_dev *dev)
1519 if (fe0->dvb.frontend) { 1517 if (fe0->dvb.frontend) {
1520 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60, 1518 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1521 &dev->i2c_adap, 0) == NULL) { 1519 &dev->i2c_adap, 0) == NULL) {
1522 wprintk("%s: No tda826x found!\n", __func__); 1520 pr_warn("%s: No tda826x found!\n", __func__);
1523 goto detach_frontend; 1521 goto detach_frontend;
1524 } 1522 }
1525 if (dvb_attach(isl6421_attach, fe0->dvb.frontend, 1523 if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
1526 &dev->i2c_adap, 1524 &dev->i2c_adap,
1527 0x08, 0, 0, false) == NULL) { 1525 0x08, 0, 0, false) == NULL) {
1528 wprintk("%s: No ISL6421 found!\n", __func__); 1526 pr_warn("%s: No ISL6421 found!\n", __func__);
1529 goto detach_frontend; 1527 goto detach_frontend;
1530 } 1528 }
1531 } 1529 }
@@ -1593,12 +1591,12 @@ static int dvb_init(struct saa7134_dev *dev)
1593 if (fe0->dvb.frontend) { 1591 if (fe0->dvb.frontend) {
1594 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60, 1592 if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
1595 &dev->i2c_adap, 0) == NULL) { 1593 &dev->i2c_adap, 0) == NULL) {
1596 wprintk("%s: No tda826x found!\n", __func__); 1594 pr_warn("%s: No tda826x found!\n", __func__);
1597 goto detach_frontend; 1595 goto detach_frontend;
1598 } 1596 }
1599 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend, 1597 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1600 &dev->i2c_adap, 0, 0) == NULL) { 1598 &dev->i2c_adap, 0, 0) == NULL) {
1601 wprintk("%s: No lnbp21 found!\n", __func__); 1599 pr_warn("%s: No lnbp21 found!\n", __func__);
1602 goto detach_frontend; 1600 goto detach_frontend;
1603 } 1601 }
1604 } 1602 }
@@ -1614,7 +1612,7 @@ static int dvb_init(struct saa7134_dev *dev)
1614 goto detach_frontend; 1612 goto detach_frontend;
1615 break; 1613 break;
1616 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: 1614 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1617 dprintk("AverMedia E506R dvb setup\n"); 1615 pr_debug("AverMedia E506R dvb setup\n");
1618 saa7134_set_gpio(dev, 25, 0); 1616 saa7134_set_gpio(dev, 25, 0);
1619 msleep(10); 1617 msleep(10);
1620 saa7134_set_gpio(dev, 25, 1); 1618 saa7134_set_gpio(dev, 25, 1);
@@ -1630,7 +1628,7 @@ static int dvb_init(struct saa7134_dev *dev)
1630 struct dvb_frontend *fe; 1628 struct dvb_frontend *fe;
1631 if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60, 1629 if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1632 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) { 1630 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
1633 wprintk("%s: MD7134 DVB-S, no SD1878 " 1631 pr_warn("%s: MD7134 DVB-S, no SD1878 "
1634 "found !\n", __func__); 1632 "found !\n", __func__);
1635 goto detach_frontend; 1633 goto detach_frontend;
1636 } 1634 }
@@ -1639,7 +1637,7 @@ static int dvb_init(struct saa7134_dev *dev)
1639 fe->ops.i2c_gate_ctrl(fe, 1); 1637 fe->ops.i2c_gate_ctrl(fe, 1);
1640 if (dvb_attach(isl6405_attach, fe, 1638 if (dvb_attach(isl6405_attach, fe,
1641 &dev->i2c_adap, 0x08, 0, 0) == NULL) { 1639 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1642 wprintk("%s: MD7134 DVB-S, no ISL6405 " 1640 pr_warn("%s: MD7134 DVB-S, no ISL6405 "
1643 "found !\n", __func__); 1641 "found !\n", __func__);
1644 goto detach_frontend; 1642 goto detach_frontend;
1645 } 1643 }
@@ -1671,15 +1669,15 @@ static int dvb_init(struct saa7134_dev *dev)
1671 if (dvb_attach(tda826x_attach, 1669 if (dvb_attach(tda826x_attach,
1672 fe0->dvb.frontend, 0x60, 1670 fe0->dvb.frontend, 0x60,
1673 &dev->i2c_adap, 0) == NULL) { 1671 &dev->i2c_adap, 0) == NULL) {
1674 wprintk("%s: Asus Tiger 3in1, no " 1672 pr_warn("%s: Asus Tiger 3in1, no "
1675 "tda826x found!\n", __func__); 1673 "tda826x found!\n", __func__);
1676 goto detach_frontend; 1674 goto detach_frontend;
1677 } 1675 }
1678 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend, 1676 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1679 &dev->i2c_adap, 0, 0) == NULL) { 1677 &dev->i2c_adap, 0, 0) == NULL) {
1680 wprintk("%s: Asus Tiger 3in1, no lnbp21" 1678 pr_warn("%s: Asus Tiger 3in1, no lnbp21"
1681 " found!\n", __func__); 1679 " found!\n", __func__);
1682 goto detach_frontend; 1680 goto detach_frontend;
1683 } 1681 }
1684 } 1682 }
1685 } 1683 }
@@ -1696,13 +1694,13 @@ static int dvb_init(struct saa7134_dev *dev)
1696 if (dvb_attach(tda826x_attach, 1694 if (dvb_attach(tda826x_attach,
1697 fe0->dvb.frontend, 0x60, 1695 fe0->dvb.frontend, 0x60,
1698 &dev->i2c_adap, 0) == NULL) { 1696 &dev->i2c_adap, 0) == NULL) {
1699 wprintk("%s: Asus My Cinema PS3-100, no " 1697 pr_warn("%s: Asus My Cinema PS3-100, no "
1700 "tda826x found!\n", __func__); 1698 "tda826x found!\n", __func__);
1701 goto detach_frontend; 1699 goto detach_frontend;
1702 } 1700 }
1703 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend, 1701 if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
1704 &dev->i2c_adap, 0, 0) == NULL) { 1702 &dev->i2c_adap, 0, 0) == NULL) {
1705 wprintk("%s: Asus My Cinema PS3-100, no lnbp21" 1703 pr_warn("%s: Asus My Cinema PS3-100, no lnbp21"
1706 " found!\n", __func__); 1704 " found!\n", __func__);
1707 goto detach_frontend; 1705 goto detach_frontend;
1708 } 1706 }
@@ -1750,7 +1748,7 @@ static int dvb_init(struct saa7134_dev *dev)
1750 if (fe0->dvb.frontend) { 1748 if (fe0->dvb.frontend) {
1751 if (dvb_attach(zl10036_attach, fe0->dvb.frontend, 1749 if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
1752 &avertv_a700_tuner, &dev->i2c_adap) == NULL) { 1750 &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
1753 wprintk("%s: No zl10036 found!\n", 1751 pr_warn("%s: No zl10036 found!\n",
1754 __func__); 1752 __func__);
1755 } 1753 }
1756 } 1754 }
@@ -1761,7 +1759,7 @@ static int dvb_init(struct saa7134_dev *dev)
1761 if (fe0->dvb.frontend) 1759 if (fe0->dvb.frontend)
1762 if (dvb_attach(zl10039_attach, fe0->dvb.frontend, 1760 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1763 0x60, &dev->i2c_adap) == NULL) 1761 0x60, &dev->i2c_adap) == NULL)
1764 wprintk("%s: No zl10039 found!\n", 1762 pr_warn("%s: No zl10039 found!\n",
1765 __func__); 1763 __func__);
1766 1764
1767 break; 1765 break;
@@ -1774,7 +1772,7 @@ static int dvb_init(struct saa7134_dev *dev)
1774 fe0->dvb.frontend, 1772 fe0->dvb.frontend,
1775 &dev->i2c_adap, 1773 &dev->i2c_adap,
1776 &videomate_t750_qt1010_config) == NULL) 1774 &videomate_t750_qt1010_config) == NULL)
1777 wprintk("error attaching QT1010\n"); 1775 pr_warn("error attaching QT1010\n");
1778 } 1776 }
1779 break; 1777 break;
1780 case SAA7134_BOARD_ZOLID_HYBRID_PCI: 1778 case SAA7134_BOARD_ZOLID_HYBRID_PCI:
@@ -1850,12 +1848,12 @@ static int dvb_init(struct saa7134_dev *dev)
1850 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL; 1848 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1851 if (dvb_attach(zl10039_attach, fe0->dvb.frontend, 1849 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1852 0x60, &dev->i2c_adap) == NULL) 1850 0x60, &dev->i2c_adap) == NULL)
1853 wprintk("%s: No zl10039 found!\n", 1851 pr_warn("%s: No zl10039 found!\n",
1854 __func__); 1852 __func__);
1855 } 1853 }
1856 break; 1854 break;
1857 default: 1855 default:
1858 wprintk("Huh? unknown DVB card?\n"); 1856 pr_warn("Huh? unknown DVB card?\n");
1859 break; 1857 break;
1860 } 1858 }
1861 1859
@@ -1871,14 +1869,14 @@ static int dvb_init(struct saa7134_dev *dev)
1871 1869
1872 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg); 1870 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
1873 if (!fe) { 1871 if (!fe) {
1874 printk(KERN_ERR "%s/2: xc3028 attach failed\n", 1872 pr_err("%s/2: xc3028 attach failed\n",
1875 dev->name); 1873 dev->name);
1876 goto detach_frontend; 1874 goto detach_frontend;
1877 } 1875 }
1878 } 1876 }
1879 1877
1880 if (NULL == fe0->dvb.frontend) { 1878 if (NULL == fe0->dvb.frontend) {
1881 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name); 1879 pr_err("%s/dvb: frontend initialization failed\n", dev->name);
1882 goto detach_frontend; 1880 goto detach_frontend;
1883 } 1881 }
1884 /* define general-purpose callback pointer */ 1882 /* define general-purpose callback pointer */
diff --git a/drivers/media/pci/saa7134/saa7134-empress.c b/drivers/media/pci/saa7134/saa7134-empress.c
index 594dc3ad4750..56b932c97196 100644
--- a/drivers/media/pci/saa7134/saa7134-empress.c
+++ b/drivers/media/pci/saa7134/saa7134-empress.c
@@ -17,6 +17,9 @@
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */ 18 */
19 19
20#include "saa7134.h"
21#include "saa7134-reg.h"
22
20#include <linux/init.h> 23#include <linux/init.h>
21#include <linux/list.h> 24#include <linux/list.h>
22#include <linux/module.h> 25#include <linux/module.h>
@@ -26,9 +29,6 @@
26#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
27#include <media/v4l2-event.h> 30#include <media/v4l2-event.h>
28 31
29#include "saa7134-reg.h"
30#include "saa7134.h"
31
32/* ------------------------------------------------------------------ */ 32/* ------------------------------------------------------------------ */
33 33
34MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 34MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
@@ -39,13 +39,6 @@ static unsigned int empress_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
39module_param_array(empress_nr, int, NULL, 0444); 39module_param_array(empress_nr, int, NULL, 0444);
40MODULE_PARM_DESC(empress_nr,"ts device number"); 40MODULE_PARM_DESC(empress_nr,"ts device number");
41 41
42static unsigned int debug;
43module_param(debug, int, 0644);
44MODULE_PARM_DESC(debug,"enable debug messages");
45
46#define dprintk(fmt, arg...) if (debug) \
47 printk(KERN_DEBUG "%s/empress: " fmt, dev->name , ## arg)
48
49/* ------------------------------------------------------------------ */ 42/* ------------------------------------------------------------------ */
50 43
51static int start_streaming(struct vb2_queue *vq, unsigned int count) 44static int start_streaming(struct vb2_queue *vq, unsigned int count)
@@ -121,11 +114,14 @@ static int empress_g_fmt_vid_cap(struct file *file, void *priv,
121 struct v4l2_format *f) 114 struct v4l2_format *f)
122{ 115{
123 struct saa7134_dev *dev = video_drvdata(file); 116 struct saa7134_dev *dev = video_drvdata(file);
124 struct v4l2_mbus_framefmt mbus_fmt; 117 struct v4l2_subdev_format fmt = {
118 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
119 };
120 struct v4l2_mbus_framefmt *mbus_fmt = &fmt.format;
125 121
126 saa_call_all(dev, video, g_mbus_fmt, &mbus_fmt); 122 saa_call_all(dev, pad, get_fmt, NULL, &fmt);
127 123
128 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); 124 v4l2_fill_pix_format(&f->fmt.pix, mbus_fmt);
129 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 125 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
130 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 126 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
131 f->fmt.pix.bytesperline = 0; 127 f->fmt.pix.bytesperline = 0;
@@ -137,11 +133,13 @@ static int empress_s_fmt_vid_cap(struct file *file, void *priv,
137 struct v4l2_format *f) 133 struct v4l2_format *f)
138{ 134{
139 struct saa7134_dev *dev = video_drvdata(file); 135 struct saa7134_dev *dev = video_drvdata(file);
140 struct v4l2_mbus_framefmt mbus_fmt; 136 struct v4l2_subdev_format format = {
137 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
138 };
141 139
142 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); 140 v4l2_fill_mbus_format(&format.format, &f->fmt.pix, MEDIA_BUS_FMT_FIXED);
143 saa_call_all(dev, video, s_mbus_fmt, &mbus_fmt); 141 saa_call_all(dev, pad, set_fmt, NULL, &format);
144 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); 142 v4l2_fill_pix_format(&f->fmt.pix, &format.format);
145 143
146 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 144 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
147 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 145 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
@@ -154,11 +152,14 @@ static int empress_try_fmt_vid_cap(struct file *file, void *priv,
154 struct v4l2_format *f) 152 struct v4l2_format *f)
155{ 153{
156 struct saa7134_dev *dev = video_drvdata(file); 154 struct saa7134_dev *dev = video_drvdata(file);
157 struct v4l2_mbus_framefmt mbus_fmt; 155 struct v4l2_subdev_pad_config pad_cfg;
156 struct v4l2_subdev_format format = {
157 .which = V4L2_SUBDEV_FORMAT_TRY,
158 };
158 159
159 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); 160 v4l2_fill_mbus_format(&format.format, &f->fmt.pix, MEDIA_BUS_FMT_FIXED);
160 saa_call_all(dev, video, try_mbus_fmt, &mbus_fmt); 161 saa_call_all(dev, pad, set_fmt, &pad_cfg, &format);
161 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); 162 v4l2_fill_pix_format(&f->fmt.pix, &format.format);
162 163
163 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 164 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
164 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 165 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
@@ -221,9 +222,9 @@ static void empress_signal_update(struct work_struct *work)
221 container_of(work, struct saa7134_dev, empress_workqueue); 222 container_of(work, struct saa7134_dev, empress_workqueue);
222 223
223 if (dev->nosignal) { 224 if (dev->nosignal) {
224 dprintk("no video signal\n"); 225 pr_debug("no video signal\n");
225 } else { 226 } else {
226 dprintk("video signal acquired\n"); 227 pr_debug("video signal acquired\n");
227 } 228 }
228} 229}
229 230
@@ -255,7 +256,7 @@ static int empress_init(struct saa7134_dev *dev)
255 struct vb2_queue *q; 256 struct vb2_queue *q;
256 int err; 257 int err;
257 258
258 dprintk("%s: %s\n",dev->name,__func__); 259 pr_debug("%s: %s\n", dev->name, __func__);
259 dev->empress_dev = video_device_alloc(); 260 dev->empress_dev = video_device_alloc();
260 if (NULL == dev->empress_dev) 261 if (NULL == dev->empress_dev)
261 return -ENOMEM; 262 return -ENOMEM;
@@ -302,13 +303,13 @@ static int empress_init(struct saa7134_dev *dev)
302 err = video_register_device(dev->empress_dev,VFL_TYPE_GRABBER, 303 err = video_register_device(dev->empress_dev,VFL_TYPE_GRABBER,
303 empress_nr[dev->nr]); 304 empress_nr[dev->nr]);
304 if (err < 0) { 305 if (err < 0) {
305 printk(KERN_INFO "%s: can't register video device\n", 306 pr_info("%s: can't register video device\n",
306 dev->name); 307 dev->name);
307 video_device_release(dev->empress_dev); 308 video_device_release(dev->empress_dev);
308 dev->empress_dev = NULL; 309 dev->empress_dev = NULL;
309 return err; 310 return err;
310 } 311 }
311 printk(KERN_INFO "%s: registered device %s [mpeg]\n", 312 pr_info("%s: registered device %s [mpeg]\n",
312 dev->name, video_device_node_name(dev->empress_dev)); 313 dev->name, video_device_node_name(dev->empress_dev));
313 314
314 empress_signal_update(&dev->empress_workqueue); 315 empress_signal_update(&dev->empress_workqueue);
@@ -317,7 +318,7 @@ static int empress_init(struct saa7134_dev *dev)
317 318
318static int empress_fini(struct saa7134_dev *dev) 319static int empress_fini(struct saa7134_dev *dev)
319{ 320{
320 dprintk("%s: %s\n",dev->name,__func__); 321 pr_debug("%s: %s\n", dev->name, __func__);
321 322
322 if (NULL == dev->empress_dev) 323 if (NULL == dev->empress_dev)
323 return 0; 324 return 0;
diff --git a/drivers/media/pci/saa7134/saa7134-go7007.c b/drivers/media/pci/saa7134/saa7134-go7007.c
index 54e650b4dff1..8a2abb34186b 100644
--- a/drivers/media/pci/saa7134/saa7134-go7007.c
+++ b/drivers/media/pci/saa7134/saa7134-go7007.c
@@ -11,6 +11,9 @@
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 */ 12 */
13 13
14#include "saa7134.h"
15#include "saa7134-reg.h"
16
14#include <linux/module.h> 17#include <linux/module.h>
15#include <linux/kernel.h> 18#include <linux/kernel.h>
16#include <linux/init.h> 19#include <linux/init.h>
@@ -27,8 +30,6 @@
27#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
28#include <media/v4l2-subdev.h> 31#include <media/v4l2-subdev.h>
29 32
30#include "saa7134.h"
31#include "saa7134-reg.h"
32#include "go7007-priv.h" 33#include "go7007-priv.h"
33 34
34/*#define GO7007_HPI_DEBUG*/ 35/*#define GO7007_HPI_DEBUG*/
@@ -288,9 +289,9 @@ static int saa7134_go7007_stream_start(struct go7007 *go)
288 289
289 /* Set up transfer block size */ 290 /* Set up transfer block size */
290 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, 128 - 1); 291 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, 128 - 1);
291 saa_writeb(SAA7134_TS_DMA0, (PAGE_SIZE >> 7) - 1); 292 saa_writeb(SAA7134_TS_DMA0, ((PAGE_SIZE >> 7) - 1) & 0xff);
292 saa_writeb(SAA7134_TS_DMA1, 0); 293 saa_writeb(SAA7134_TS_DMA1, (PAGE_SIZE >> 15) & 0xff);
293 saa_writeb(SAA7134_TS_DMA2, 0); 294 saa_writeb(SAA7134_TS_DMA2, (PAGE_SIZE >> 31) & 0x3f);
294 295
295 /* Enable video streaming mode */ 296 /* Enable video streaming mode */
296 saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_VIDEO); 297 saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_VIDEO);
diff --git a/drivers/media/pci/saa7134/saa7134-i2c.c b/drivers/media/pci/saa7134/saa7134-i2c.c
index f4da674e7f26..8ef6399d794f 100644
--- a/drivers/media/pci/saa7134/saa7134-i2c.c
+++ b/drivers/media/pci/saa7134/saa7134-i2c.c
@@ -20,14 +20,15 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
26#include <linux/kernel.h> 29#include <linux/kernel.h>
27#include <linux/delay.h> 30#include <linux/delay.h>
28 31
29#include "saa7134-reg.h"
30#include "saa7134.h"
31#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
32 33
33/* ----------------------------------------------------------- */ 34/* ----------------------------------------------------------- */
@@ -40,8 +41,15 @@ static unsigned int i2c_scan;
40module_param(i2c_scan, int, 0444); 41module_param(i2c_scan, int, 0444);
41MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 42MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
42 43
43#define d1printk if (1 == i2c_debug) printk 44#define i2c_dbg(level, fmt, arg...) do { \
44#define d2printk if (2 == i2c_debug) printk 45 if (i2c_debug == level) \
46 printk(KERN_DEBUG pr_fmt("i2c: " fmt), ## arg); \
47 } while (0)
48
49#define i2c_cont(level, fmt, arg...) do { \
50 if (i2c_debug == level) \
51 pr_cont(fmt, ## arg); \
52 } while (0)
45 53
46#define I2C_WAIT_DELAY 32 54#define I2C_WAIT_DELAY 32
47#define I2C_WAIT_RETRY 16 55#define I2C_WAIT_RETRY 16
@@ -89,23 +97,20 @@ static inline enum i2c_status i2c_get_status(struct saa7134_dev *dev)
89 enum i2c_status status; 97 enum i2c_status status;
90 98
91 status = saa_readb(SAA7134_I2C_ATTR_STATUS) & 0x0f; 99 status = saa_readb(SAA7134_I2C_ATTR_STATUS) & 0x0f;
92 d2printk(KERN_DEBUG "%s: i2c stat <= %s\n",dev->name, 100 i2c_dbg(2, "i2c stat <= %s\n", str_i2c_status[status]);
93 str_i2c_status[status]);
94 return status; 101 return status;
95} 102}
96 103
97static inline void i2c_set_status(struct saa7134_dev *dev, 104static inline void i2c_set_status(struct saa7134_dev *dev,
98 enum i2c_status status) 105 enum i2c_status status)
99{ 106{
100 d2printk(KERN_DEBUG "%s: i2c stat => %s\n",dev->name, 107 i2c_dbg(2, "i2c stat => %s\n", str_i2c_status[status]);
101 str_i2c_status[status]);
102 saa_andorb(SAA7134_I2C_ATTR_STATUS,0x0f,status); 108 saa_andorb(SAA7134_I2C_ATTR_STATUS,0x0f,status);
103} 109}
104 110
105static inline void i2c_set_attr(struct saa7134_dev *dev, enum i2c_attr attr) 111static inline void i2c_set_attr(struct saa7134_dev *dev, enum i2c_attr attr)
106{ 112{
107 d2printk(KERN_DEBUG "%s: i2c attr => %s\n",dev->name, 113 i2c_dbg(2, "i2c attr => %s\n", str_i2c_attr[attr]);
108 str_i2c_attr[attr]);
109 saa_andorb(SAA7134_I2C_ATTR_STATUS,0xc0,attr << 6); 114 saa_andorb(SAA7134_I2C_ATTR_STATUS,0xc0,attr << 6);
110} 115}
111 116
@@ -168,7 +173,7 @@ static int i2c_reset(struct saa7134_dev *dev)
168 enum i2c_status status; 173 enum i2c_status status;
169 int count; 174 int count;
170 175
171 d2printk(KERN_DEBUG "%s: i2c reset\n",dev->name); 176 i2c_dbg(2, "i2c reset\n");
172 status = i2c_get_status(dev); 177 status = i2c_get_status(dev);
173 if (!i2c_is_error(status)) 178 if (!i2c_is_error(status))
174 return true; 179 return true;
@@ -206,7 +211,7 @@ static inline int i2c_send_byte(struct saa7134_dev *dev,
206// dword |= 0x40 << 16; /* 400 kHz */ 211// dword |= 0x40 << 16; /* 400 kHz */
207 dword |= 0xf0 << 24; 212 dword |= 0xf0 << 24;
208 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword); 213 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword);
209 d2printk(KERN_DEBUG "%s: i2c data => 0x%x\n",dev->name,data); 214 i2c_dbg(2, "i2c data => 0x%x\n", data);
210 215
211 if (!i2c_is_busy_wait(dev)) 216 if (!i2c_is_busy_wait(dev))
212 return -EIO; 217 return -EIO;
@@ -228,7 +233,7 @@ static inline int i2c_recv_byte(struct saa7134_dev *dev)
228 if (i2c_is_error(status)) 233 if (i2c_is_error(status))
229 return -EIO; 234 return -EIO;
230 data = saa_readb(SAA7134_I2C_DATA); 235 data = saa_readb(SAA7134_I2C_DATA);
231 d2printk(KERN_DEBUG "%s: i2c data <= 0x%x\n",dev->name,data); 236 i2c_dbg(2, "i2c data <= 0x%x\n", data);
232 return data; 237 return data;
233} 238}
234 239
@@ -245,12 +250,12 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
245 if (!i2c_reset(dev)) 250 if (!i2c_reset(dev))
246 return -EIO; 251 return -EIO;
247 252
248 d2printk("start xfer\n"); 253 i2c_dbg(2, "start xfer\n");
249 d1printk(KERN_DEBUG "%s: i2c xfer:",dev->name); 254 i2c_dbg(1, "i2c xfer:");
250 for (i = 0; i < num; i++) { 255 for (i = 0; i < num; i++) {
251 if (!(msgs[i].flags & I2C_M_NOSTART) || 0 == i) { 256 if (!(msgs[i].flags & I2C_M_NOSTART) || 0 == i) {
252 /* send address */ 257 /* send address */
253 d2printk("send address\n"); 258 i2c_dbg(2, "send address\n");
254 addr = msgs[i].addr << 1; 259 addr = msgs[i].addr << 1;
255 if (msgs[i].flags & I2C_M_RD) 260 if (msgs[i].flags & I2C_M_RD)
256 addr |= 1; 261 addr |= 1;
@@ -262,50 +267,50 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
262 * needed to talk to the mt352 demux 267 * needed to talk to the mt352 demux
263 * thanks to pinnacle for the hint */ 268 * thanks to pinnacle for the hint */
264 int quirk = 0xfe; 269 int quirk = 0xfe;
265 d1printk(" [%02x quirk]",quirk); 270 i2c_cont(1, " [%02x quirk]", quirk);
266 i2c_send_byte(dev,START,quirk); 271 i2c_send_byte(dev,START,quirk);
267 i2c_recv_byte(dev); 272 i2c_recv_byte(dev);
268 } 273 }
269 d1printk(" < %02x", addr); 274 i2c_cont(1, " < %02x", addr);
270 rc = i2c_send_byte(dev,START,addr); 275 rc = i2c_send_byte(dev,START,addr);
271 if (rc < 0) 276 if (rc < 0)
272 goto err; 277 goto err;
273 } 278 }
274 if (msgs[i].flags & I2C_M_RD) { 279 if (msgs[i].flags & I2C_M_RD) {
275 /* read bytes */ 280 /* read bytes */
276 d2printk("read bytes\n"); 281 i2c_dbg(2, "read bytes\n");
277 for (byte = 0; byte < msgs[i].len; byte++) { 282 for (byte = 0; byte < msgs[i].len; byte++) {
278 d1printk(" ="); 283 i2c_cont(1, " =");
279 rc = i2c_recv_byte(dev); 284 rc = i2c_recv_byte(dev);
280 if (rc < 0) 285 if (rc < 0)
281 goto err; 286 goto err;
282 d1printk("%02x", rc); 287 i2c_cont(1, "%02x", rc);
283 msgs[i].buf[byte] = rc; 288 msgs[i].buf[byte] = rc;
284 } 289 }
285 /* discard mysterious extra byte when reading 290 /* discard mysterious extra byte when reading
286 from Samsung S5H1411. i2c bus gets error 291 from Samsung S5H1411. i2c bus gets error
287 if we do not. */ 292 if we do not. */
288 if (0x19 == msgs[i].addr) { 293 if (0x19 == msgs[i].addr) {
289 d1printk(" ?"); 294 i2c_cont(1, " ?");
290 rc = i2c_recv_byte(dev); 295 rc = i2c_recv_byte(dev);
291 if (rc < 0) 296 if (rc < 0)
292 goto err; 297 goto err;
293 d1printk("%02x", rc); 298 i2c_cont(1, "%02x", rc);
294 } 299 }
295 } else { 300 } else {
296 /* write bytes */ 301 /* write bytes */
297 d2printk("write bytes\n"); 302 i2c_dbg(2, "write bytes\n");
298 for (byte = 0; byte < msgs[i].len; byte++) { 303 for (byte = 0; byte < msgs[i].len; byte++) {
299 data = msgs[i].buf[byte]; 304 data = msgs[i].buf[byte];
300 d1printk(" %02x", data); 305 i2c_cont(1, " %02x", data);
301 rc = i2c_send_byte(dev,CONTINUE,data); 306 rc = i2c_send_byte(dev,CONTINUE,data);
302 if (rc < 0) 307 if (rc < 0)
303 goto err; 308 goto err;
304 } 309 }
305 } 310 }
306 } 311 }
307 d2printk("xfer done\n"); 312 i2c_dbg(2, "xfer done\n");
308 d1printk(" >"); 313 i2c_cont(1, " >");
309 i2c_set_attr(dev,STOP); 314 i2c_set_attr(dev,STOP);
310 rc = -EIO; 315 rc = -EIO;
311 if (!i2c_is_busy_wait(dev)) 316 if (!i2c_is_busy_wait(dev))
@@ -316,12 +321,12 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
316 /* ensure that the bus is idle for at least one bit slot */ 321 /* ensure that the bus is idle for at least one bit slot */
317 msleep(1); 322 msleep(1);
318 323
319 d1printk("\n"); 324 i2c_cont(1, "\n");
320 return num; 325 return num;
321 err: 326 err:
322 if (1 == i2c_debug) { 327 if (1 == i2c_debug) {
323 status = i2c_get_status(dev); 328 status = i2c_get_status(dev);
324 printk(" ERROR: %s\n",str_i2c_status[status]); 329 i2c_cont(1, " ERROR: %s\n", str_i2c_status[status]);
325 } 330 }
326 return rc; 331 return rc;
327} 332}
@@ -359,22 +364,22 @@ saa7134_i2c_eeprom(struct saa7134_dev *dev, unsigned char *eedata, int len)
359 dev->i2c_client.addr = 0xa0 >> 1; 364 dev->i2c_client.addr = 0xa0 >> 1;
360 buf = 0; 365 buf = 0;
361 if (1 != (err = i2c_master_send(&dev->i2c_client,&buf,1))) { 366 if (1 != (err = i2c_master_send(&dev->i2c_client,&buf,1))) {
362 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", 367 pr_info("%s: Huh, no eeprom present (err=%d)?\n",
363 dev->name,err); 368 dev->name,err);
364 return -1; 369 return -1;
365 } 370 }
366 if (len != (err = i2c_master_recv(&dev->i2c_client,eedata,len))) { 371 if (len != (err = i2c_master_recv(&dev->i2c_client,eedata,len))) {
367 printk(KERN_WARNING "%s: i2c eeprom read error (err=%d)\n", 372 pr_warn("%s: i2c eeprom read error (err=%d)\n",
368 dev->name,err); 373 dev->name,err);
369 return -1; 374 return -1;
370 } 375 }
371 for (i = 0; i < len; i++) { 376
372 if (0 == (i % 16)) 377 for (i = 0; i < len; i += 16) {
373 printk(KERN_INFO "%s: i2c eeprom %02x:",dev->name,i); 378 int size = (len - i) > 16 ? 16 : len - i;
374 printk(" %02x",eedata[i]); 379
375 if (15 == (i % 16)) 380 pr_info("i2c eeprom %02x: %*ph\n", i, size, &eedata[i]);
376 printk("\n");
377 } 381 }
382
378 return 0; 383 return 0;
379} 384}
380 385
@@ -386,7 +391,7 @@ static char *i2c_devs[128] = {
386 [ 0x5a >> 1 ] = "remote control", 391 [ 0x5a >> 1 ] = "remote control",
387}; 392};
388 393
389static void do_i2c_scan(char *name, struct i2c_client *c) 394static void do_i2c_scan(struct i2c_client *c)
390{ 395{
391 unsigned char buf; 396 unsigned char buf;
392 int i,rc; 397 int i,rc;
@@ -396,8 +401,8 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
396 rc = i2c_master_recv(c,&buf,0); 401 rc = i2c_master_recv(c,&buf,0);
397 if (rc < 0) 402 if (rc < 0)
398 continue; 403 continue;
399 printk("%s: i2c scan: found device @ 0x%x [%s]\n", 404 pr_info("i2c scan: found device @ 0x%x [%s]\n",
400 name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); 405 i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
401 } 406 }
402} 407}
403 408
@@ -415,7 +420,7 @@ int saa7134_i2c_register(struct saa7134_dev *dev)
415 420
416 saa7134_i2c_eeprom(dev,dev->eedata,sizeof(dev->eedata)); 421 saa7134_i2c_eeprom(dev,dev->eedata,sizeof(dev->eedata));
417 if (i2c_scan) 422 if (i2c_scan)
418 do_i2c_scan(dev->name,&dev->i2c_client); 423 do_i2c_scan(&dev->i2c_client);
419 424
420 /* Instantiate the IR receiver device, if present */ 425 /* Instantiate the IR receiver device, if present */
421 saa7134_probe_i2c_ir(dev); 426 saa7134_probe_i2c_ir(dev);
diff --git a/drivers/media/pci/saa7134/saa7134-input.c b/drivers/media/pci/saa7134/saa7134-input.c
index dc3d6516edf7..11a172000291 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -18,15 +18,15 @@
18 * 18 *
19 */ 19 */
20 20
21#include "saa7134.h"
22#include "saa7134-reg.h"
23
21#include <linux/module.h> 24#include <linux/module.h>
22#include <linux/init.h> 25#include <linux/init.h>
23#include <linux/delay.h> 26#include <linux/delay.h>
24#include <linux/interrupt.h> 27#include <linux/interrupt.h>
25#include <linux/slab.h> 28#include <linux/slab.h>
26 29
27#include "saa7134-reg.h"
28#include "saa7134.h"
29
30#define MODULE_NAME "saa7134" 30#define MODULE_NAME "saa7134"
31 31
32static unsigned int disable_ir; 32static unsigned int disable_ir;
@@ -41,10 +41,14 @@ static int pinnacle_remote;
41module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ 41module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
42MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); 42MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
43 43
44#define dprintk(fmt, arg...) if (ir_debug) \ 44#define input_dbg(fmt, arg...) do { \
45 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) 45 if (ir_debug) \
46#define i2cdprintk(fmt, arg...) if (ir_debug) \ 46 printk(KERN_DEBUG pr_fmt("input: " fmt), ## arg); \
47 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg) 47 } while (0)
48#define ir_dbg(ir, fmt, arg...) do { \
49 if (ir_debug) \
50 printk(KERN_DEBUG pr_fmt("ir %s: " fmt), ir->name, ## arg); \
51 } while (0)
48 52
49/* Helper function for raw decoding at GPIO16 or GPIO18 */ 53/* Helper function for raw decoding at GPIO16 or GPIO18 */
50static int saa7134_raw_decode_irq(struct saa7134_dev *dev); 54static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
@@ -75,7 +79,7 @@ static int build_key(struct saa7134_dev *dev)
75 } 79 }
76 80
77 data = ir_extract_bits(gpio, ir->mask_keycode); 81 data = ir_extract_bits(gpio, ir->mask_keycode);
78 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n", 82 input_dbg("build_key gpio=0x%x mask=0x%x data=%d\n",
79 gpio, ir->mask_keycode, data); 83 gpio, ir->mask_keycode, data);
80 84
81 switch (dev->board) { 85 switch (dev->board) {
@@ -119,7 +123,7 @@ static int get_key_flydvb_trio(struct IR_i2c *ir, enum rc_type *protocol,
119 struct saa7134_dev *dev = ir->c->adapter->algo_data; 123 struct saa7134_dev *dev = ir->c->adapter->algo_data;
120 124
121 if (dev == NULL) { 125 if (dev == NULL) {
122 i2cdprintk("get_key_flydvb_trio: " 126 ir_dbg(ir, "get_key_flydvb_trio: "
123 "ir->c->adapter->algo_data is NULL!\n"); 127 "ir->c->adapter->algo_data is NULL!\n");
124 return -EIO; 128 return -EIO;
125 } 129 }
@@ -146,12 +150,12 @@ static int get_key_flydvb_trio(struct IR_i2c *ir, enum rc_type *protocol,
146 msleep(10); 150 msleep(10);
147 continue; 151 continue;
148 } 152 }
149 i2cdprintk("send wake up byte to pic16C505 (IR chip)" 153 ir_dbg(ir, "send wake up byte to pic16C505 (IR chip)"
150 "failed %dx\n", attempt); 154 "failed %dx\n", attempt);
151 return -EIO; 155 return -EIO;
152 } 156 }
153 if (1 != i2c_master_recv(ir->c, &b, 1)) { 157 if (1 != i2c_master_recv(ir->c, &b, 1)) {
154 i2cdprintk("read error\n"); 158 ir_dbg(ir, "read error\n");
155 return -EIO; 159 return -EIO;
156 } 160 }
157 161
@@ -170,7 +174,7 @@ static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, enum rc_type *protocol
170 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */ 174 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
171 struct saa7134_dev *dev = ir->c->adapter->algo_data; 175 struct saa7134_dev *dev = ir->c->adapter->algo_data;
172 if (dev == NULL) { 176 if (dev == NULL) {
173 i2cdprintk("get_key_msi_tvanywhere_plus: " 177 ir_dbg(ir, "get_key_msi_tvanywhere_plus: "
174 "ir->c->adapter->algo_data is NULL!\n"); 178 "ir->c->adapter->algo_data is NULL!\n");
175 return -EIO; 179 return -EIO;
176 } 180 }
@@ -191,7 +195,7 @@ static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, enum rc_type *protocol
191 /* GPIO says there is a button press. Get it. */ 195 /* GPIO says there is a button press. Get it. */
192 196
193 if (1 != i2c_master_recv(ir->c, &b, 1)) { 197 if (1 != i2c_master_recv(ir->c, &b, 1)) {
194 i2cdprintk("read error\n"); 198 ir_dbg(ir, "read error\n");
195 return -EIO; 199 return -EIO;
196 } 200 }
197 201
@@ -202,7 +206,7 @@ static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, enum rc_type *protocol
202 206
203 /* Button pressed */ 207 /* Button pressed */
204 208
205 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b); 209 input_dbg("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
206 *protocol = RC_TYPE_UNKNOWN; 210 *protocol = RC_TYPE_UNKNOWN;
207 *scancode = b; 211 *scancode = b;
208 *toggle = 0; 212 *toggle = 0;
@@ -219,7 +223,7 @@ static int get_key_kworld_pc150u(struct IR_i2c *ir, enum rc_type *protocol,
219 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */ 223 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
220 struct saa7134_dev *dev = ir->c->adapter->algo_data; 224 struct saa7134_dev *dev = ir->c->adapter->algo_data;
221 if (dev == NULL) { 225 if (dev == NULL) {
222 i2cdprintk("get_key_kworld_pc150u: " 226 ir_dbg(ir, "get_key_kworld_pc150u: "
223 "ir->c->adapter->algo_data is NULL!\n"); 227 "ir->c->adapter->algo_data is NULL!\n");
224 return -EIO; 228 return -EIO;
225 } 229 }
@@ -240,7 +244,7 @@ static int get_key_kworld_pc150u(struct IR_i2c *ir, enum rc_type *protocol,
240 /* GPIO says there is a button press. Get it. */ 244 /* GPIO says there is a button press. Get it. */
241 245
242 if (1 != i2c_master_recv(ir->c, &b, 1)) { 246 if (1 != i2c_master_recv(ir->c, &b, 1)) {
243 i2cdprintk("read error\n"); 247 ir_dbg(ir, "read error\n");
244 return -EIO; 248 return -EIO;
245 } 249 }
246 250
@@ -251,7 +255,7 @@ static int get_key_kworld_pc150u(struct IR_i2c *ir, enum rc_type *protocol,
251 255
252 /* Button pressed */ 256 /* Button pressed */
253 257
254 dprintk("get_key_kworld_pc150u: Key = 0x%02X\n", b); 258 input_dbg("get_key_kworld_pc150u: Key = 0x%02X\n", b);
255 *protocol = RC_TYPE_UNKNOWN; 259 *protocol = RC_TYPE_UNKNOWN;
256 *scancode = b; 260 *scancode = b;
257 *toggle = 0; 261 *toggle = 0;
@@ -265,7 +269,7 @@ static int get_key_purpletv(struct IR_i2c *ir, enum rc_type *protocol,
265 269
266 /* poll IR chip */ 270 /* poll IR chip */
267 if (1 != i2c_master_recv(ir->c, &b, 1)) { 271 if (1 != i2c_master_recv(ir->c, &b, 1)) {
268 i2cdprintk("read error\n"); 272 ir_dbg(ir, "read error\n");
269 return -EIO; 273 return -EIO;
270 } 274 }
271 275
@@ -334,7 +338,7 @@ static int get_key_beholdm6xx(struct IR_i2c *ir, enum rc_type *protocol,
334 ir->c->addr = 0x5a >> 1; 338 ir->c->addr = 0x5a >> 1;
335 339
336 if (12 != i2c_master_recv(ir->c, data, 12)) { 340 if (12 != i2c_master_recv(ir->c, data, 12)) {
337 i2cdprintk("read error\n"); 341 ir_dbg(ir, "read error\n");
338 return -EIO; 342 return -EIO;
339 } 343 }
340 344
@@ -359,7 +363,7 @@ static int get_key_pinnacle(struct IR_i2c *ir, enum rc_type *protocol,
359 363
360 /* poll IR chip */ 364 /* poll IR chip */
361 if (4 != i2c_master_recv(ir->c, b, 4)) { 365 if (4 != i2c_master_recv(ir->c, b, 4)) {
362 i2cdprintk("read error\n"); 366 ir_dbg(ir, "read error\n");
363 return -EIO; 367 return -EIO;
364 } 368 }
365 369
@@ -391,7 +395,7 @@ static int get_key_pinnacle(struct IR_i2c *ir, enum rc_type *protocol,
391 *scancode = code; 395 *scancode = code;
392 *toggle = 0; 396 *toggle = 0;
393 397
394 i2cdprintk("Pinnacle PCTV key %02x\n", code); 398 ir_dbg(ir, "Pinnacle PCTV key %02x\n", code);
395 return 1; 399 return 1;
396} 400}
397 401
@@ -481,6 +485,7 @@ static int __saa7134_ir_start(void *priv)
481 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 485 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
482 case SAA7134_BOARD_AVERMEDIA_305: 486 case SAA7134_BOARD_AVERMEDIA_305:
483 case SAA7134_BOARD_AVERMEDIA_307: 487 case SAA7134_BOARD_AVERMEDIA_307:
488 case SAA7134_BOARD_AVERMEDIA_505:
484 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 489 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
485 case SAA7134_BOARD_AVERMEDIA_STUDIO_505: 490 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
486 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 491 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
@@ -629,6 +634,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
629 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 634 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
630 case SAA7134_BOARD_AVERMEDIA_305: 635 case SAA7134_BOARD_AVERMEDIA_305:
631 case SAA7134_BOARD_AVERMEDIA_307: 636 case SAA7134_BOARD_AVERMEDIA_307:
637 case SAA7134_BOARD_AVERMEDIA_505:
632 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 638 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
633 case SAA7134_BOARD_AVERMEDIA_STUDIO_505: 639 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
634 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 640 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
@@ -831,8 +837,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
831 break; 837 break;
832 } 838 }
833 if (NULL == ir_codes) { 839 if (NULL == ir_codes) {
834 printk("%s: Oops: IR config error [card=%d]\n", 840 pr_err("Oops: IR config error [card=%d]\n", dev->board);
835 dev->name, dev->board);
836 return -ENODEV; 841 return -ENODEV;
837 } 842 }
838 843
@@ -916,7 +921,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
916 int rc; 921 int rc;
917 922
918 if (disable_ir) { 923 if (disable_ir) {
919 dprintk("IR has been disabled, not probing for i2c remote\n"); 924 input_dbg("IR has been disabled, not probing for i2c remote\n");
920 return; 925 return;
921 } 926 }
922 927
@@ -959,7 +964,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
959 an existing device. Weird... 964 an existing device. Weird...
960 REVISIT: might no longer be needed */ 965 REVISIT: might no longer be needed */
961 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1); 966 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
962 dprintk("probe 0x%02x @ %s: %s\n", 967 input_dbg("probe 0x%02x @ %s: %s\n",
963 msg_msi.addr, dev->i2c_adap.name, 968 msg_msi.addr, dev->i2c_adap.name,
964 (1 == rc) ? "yes" : "no"); 969 (1 == rc) ? "yes" : "no");
965 break; 970 break;
@@ -974,7 +979,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
974 an existing device. Weird... 979 an existing device. Weird...
975 REVISIT: might no longer be needed */ 980 REVISIT: might no longer be needed */
976 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1); 981 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
977 dprintk("probe 0x%02x @ %s: %s\n", 982 input_dbg("probe 0x%02x @ %s: %s\n",
978 msg_msi.addr, dev->i2c_adap.name, 983 msg_msi.addr, dev->i2c_adap.name,
979 (1 == rc) ? "yes" : "no"); 984 (1 == rc) ? "yes" : "no");
980 break; 985 break;
@@ -1019,7 +1024,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1019 info.addr = 0x0b; 1024 info.addr = 0x0b;
1020 break; 1025 break;
1021 default: 1026 default:
1022 dprintk("No I2C IR support for board %x\n", dev->board); 1027 input_dbg("No I2C IR support for board %x\n", dev->board);
1023 return; 1028 return;
1024 } 1029 }
1025 1030
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c
index 2709b83d57b1..4b202fa5fbc4 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -20,23 +20,25 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
26#include <linux/kernel.h> 29#include <linux/kernel.h>
27#include <linux/delay.h> 30#include <linux/delay.h>
28 31
29#include "saa7134-reg.h"
30#include "saa7134.h"
31
32/* ------------------------------------------------------------------ */ 32/* ------------------------------------------------------------------ */
33 33
34static unsigned int ts_debug; 34static unsigned int ts_debug;
35module_param(ts_debug, int, 0644); 35module_param(ts_debug, int, 0644);
36MODULE_PARM_DESC(ts_debug,"enable debug messages [ts]"); 36MODULE_PARM_DESC(ts_debug,"enable debug messages [ts]");
37 37
38#define dprintk(fmt, arg...) if (ts_debug) \ 38#define ts_dbg(fmt, arg...) do { \
39 printk(KERN_DEBUG "%s/ts: " fmt, dev->name , ## arg) 39 if (ts_debug) \
40 printk(KERN_DEBUG pr_fmt("ts: " fmt), ## arg); \
41 } while (0)
40 42
41/* ------------------------------------------------------------------ */ 43/* ------------------------------------------------------------------ */
42static int buffer_activate(struct saa7134_dev *dev, 44static int buffer_activate(struct saa7134_dev *dev,
@@ -44,7 +46,7 @@ static int buffer_activate(struct saa7134_dev *dev,
44 struct saa7134_buf *next) 46 struct saa7134_buf *next)
45{ 47{
46 48
47 dprintk("buffer_activate [%p]",buf); 49 ts_dbg("buffer_activate [%p]", buf);
48 buf->top_seen = 0; 50 buf->top_seen = 0;
49 51
50 if (!dev->ts_started) 52 if (!dev->ts_started)
@@ -53,12 +55,12 @@ static int buffer_activate(struct saa7134_dev *dev,
53 if (NULL == next) 55 if (NULL == next)
54 next = buf; 56 next = buf;
55 if (V4L2_FIELD_TOP == dev->ts_field) { 57 if (V4L2_FIELD_TOP == dev->ts_field) {
56 dprintk("- [top] buf=%p next=%p\n",buf,next); 58 ts_dbg("- [top] buf=%p next=%p\n", buf, next);
57 saa_writel(SAA7134_RS_BA1(5),saa7134_buffer_base(buf)); 59 saa_writel(SAA7134_RS_BA1(5),saa7134_buffer_base(buf));
58 saa_writel(SAA7134_RS_BA2(5),saa7134_buffer_base(next)); 60 saa_writel(SAA7134_RS_BA2(5),saa7134_buffer_base(next));
59 dev->ts_field = V4L2_FIELD_BOTTOM; 61 dev->ts_field = V4L2_FIELD_BOTTOM;
60 } else { 62 } else {
61 dprintk("- [bottom] buf=%p next=%p\n",buf,next); 63 ts_dbg("- [bottom] buf=%p next=%p\n", buf, next);
62 saa_writel(SAA7134_RS_BA1(5),saa7134_buffer_base(next)); 64 saa_writel(SAA7134_RS_BA1(5),saa7134_buffer_base(next));
63 saa_writel(SAA7134_RS_BA2(5),saa7134_buffer_base(buf)); 65 saa_writel(SAA7134_RS_BA2(5),saa7134_buffer_base(buf));
64 dev->ts_field = V4L2_FIELD_TOP; 66 dev->ts_field = V4L2_FIELD_TOP;
@@ -95,7 +97,7 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2)
95 struct sg_table *dma = vb2_dma_sg_plane_desc(vb2, 0); 97 struct sg_table *dma = vb2_dma_sg_plane_desc(vb2, 0);
96 unsigned int lines, llength, size; 98 unsigned int lines, llength, size;
97 99
98 dprintk("buffer_prepare [%p]\n", buf); 100 ts_dbg("buffer_prepare [%p]\n", buf);
99 101
100 llength = TS_PACKET_SIZE; 102 llength = TS_PACKET_SIZE;
101 lines = dev->ts.nr_packets; 103 lines = dev->ts.nr_packets;
@@ -239,7 +241,7 @@ int saa7134_ts_init1(struct saa7134_dev *dev)
239/* Function for stop TS */ 241/* Function for stop TS */
240int saa7134_ts_stop(struct saa7134_dev *dev) 242int saa7134_ts_stop(struct saa7134_dev *dev)
241{ 243{
242 dprintk("TS stop\n"); 244 ts_dbg("TS stop\n");
243 245
244 if (!dev->ts_started) 246 if (!dev->ts_started)
245 return 0; 247 return 0;
@@ -261,7 +263,7 @@ int saa7134_ts_stop(struct saa7134_dev *dev)
261/* Function for start TS */ 263/* Function for start TS */
262int saa7134_ts_start(struct saa7134_dev *dev) 264int saa7134_ts_start(struct saa7134_dev *dev)
263{ 265{
264 dprintk("TS start\n"); 266 ts_dbg("TS start\n");
265 267
266 if (WARN_ON(dev->ts_started)) 268 if (WARN_ON(dev->ts_started))
267 return 0; 269 return 0;
diff --git a/drivers/media/pci/saa7134/saa7134-tvaudio.c b/drivers/media/pci/saa7134/saa7134-tvaudio.c
index 3afbcb70b518..21a579309575 100644
--- a/drivers/media/pci/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/pci/saa7134/saa7134-tvaudio.c
@@ -20,6 +20,9 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
@@ -29,9 +32,6 @@
29#include <linux/freezer.h> 32#include <linux/freezer.h>
30#include <asm/div64.h> 33#include <asm/div64.h>
31 34
32#include "saa7134-reg.h"
33#include "saa7134.h"
34
35/* ------------------------------------------------------------------ */ 35/* ------------------------------------------------------------------ */
36 36
37static unsigned int audio_debug; 37static unsigned int audio_debug;
@@ -49,13 +49,10 @@ static int audio_clock_tweak;
49module_param(audio_clock_tweak, int, 0644); 49module_param(audio_clock_tweak, int, 0644);
50MODULE_PARM_DESC(audio_clock_tweak, "Audio clock tick fine tuning for cards with audio crystal that's slightly off (range [-1024 .. 1024])"); 50MODULE_PARM_DESC(audio_clock_tweak, "Audio clock tick fine tuning for cards with audio crystal that's slightly off (range [-1024 .. 1024])");
51 51
52#define dprintk(fmt, arg...) if (audio_debug) \ 52#define audio_dbg(level, fmt, arg...) do { \
53 printk(KERN_DEBUG "%s/audio: " fmt, dev->name , ## arg) 53 if (audio_debug >= level) \
54#define d2printk(fmt, arg...) if (audio_debug > 1) \ 54 printk(KERN_DEBUG pr_fmt("audio: " fmt), ## arg); \
55 printk(KERN_DEBUG "%s/audio: " fmt, dev->name, ## arg) 55 } while (0)
56
57#define print_regb(reg) printk("%s: reg 0x%03x [%-16s]: 0x%02x\n", \
58 dev->name,(SAA7134_##reg),(#reg),saa_readb((SAA7134_##reg)))
59 56
60/* msecs */ 57/* msecs */
61#define SCAN_INITIAL_DELAY 1000 58#define SCAN_INITIAL_DELAY 1000
@@ -206,13 +203,14 @@ static void mute_input_7134(struct saa7134_dev *dev)
206 203
207 if (dev->hw_mute == mute && 204 if (dev->hw_mute == mute &&
208 dev->hw_input == in && !dev->insuspend) { 205 dev->hw_input == in && !dev->insuspend) {
209 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n", 206 audio_dbg(1, "mute/input: nothing to do [mute=%d,input=%s]\n",
210 mute,in->name); 207 mute, in->name);
211 return; 208 return;
212 } 209 }
213 210
214 dprintk("ctl_mute=%d automute=%d input=%s => mute=%d input=%s\n", 211 audio_dbg(1, "ctl_mute=%d automute=%d input=%s => mute=%d input=%s\n",
215 dev->ctl_mute,dev->automute,dev->input->name,mute,in->name); 212 dev->ctl_mute, dev->automute,
213 dev->input->name, mute, in->name);
216 dev->hw_mute = mute; 214 dev->hw_mute = mute;
217 dev->hw_input = in; 215 dev->hw_input = in;
218 216
@@ -265,8 +263,8 @@ static void tvaudio_setmode(struct saa7134_dev *dev,
265 tweak = audio_clock_tweak; 263 tweak = audio_clock_tweak;
266 264
267 if (note) 265 if (note)
268 dprintk("tvaudio_setmode: %s %s [%d.%03d/%d.%03d MHz] acpf=%d%+d\n", 266 audio_dbg(1, "tvaudio_setmode: %s %s [%d.%03d/%d.%03d MHz] acpf=%d%+d\n",
269 note,audio->name, 267 note, audio->name,
270 audio->carr1 / 1000, audio->carr1 % 1000, 268 audio->carr1 / 1000, audio->carr1 % 1000,
271 audio->carr2 / 1000, audio->carr2 % 1000, 269 audio->carr2 / 1000, audio->carr2 % 1000,
272 acpf, tweak); 270 acpf, tweak);
@@ -334,14 +332,14 @@ static int tvaudio_checkcarrier(struct saa7134_dev *dev, struct mainscan *scan)
334 332
335 if (!(dev->tvnorm->id & scan->std)) { 333 if (!(dev->tvnorm->id & scan->std)) {
336 value = 0; 334 value = 0;
337 dprintk("skipping %d.%03d MHz [%4s]\n", 335 audio_dbg(1, "skipping %d.%03d MHz [%4s]\n",
338 scan->carr / 1000, scan->carr % 1000, scan->name); 336 scan->carr / 1000, scan->carr % 1000, scan->name);
339 return 0; 337 return 0;
340 } 338 }
341 339
342 if (audio_debug > 1) { 340 if (audio_debug > 1) {
343 int i; 341 int i;
344 dprintk("debug %d:",scan->carr); 342 audio_dbg(1, "debug %d:", scan->carr);
345 for (i = -150; i <= 150; i += 30) { 343 for (i = -150; i <= 150; i += 30) {
346 tvaudio_setcarrier(dev,scan->carr+i,scan->carr+i); 344 tvaudio_setcarrier(dev,scan->carr+i,scan->carr+i);
347 saa_readl(SAA7134_LEVEL_READOUT1 >> 2); 345 saa_readl(SAA7134_LEVEL_READOUT1 >> 2);
@@ -349,11 +347,11 @@ static int tvaudio_checkcarrier(struct saa7134_dev *dev, struct mainscan *scan)
349 return -1; 347 return -1;
350 value = saa_readl(SAA7134_LEVEL_READOUT1 >> 2); 348 value = saa_readl(SAA7134_LEVEL_READOUT1 >> 2);
351 if (0 == i) 349 if (0 == i)
352 printk(" # %6d # ",value >> 16); 350 pr_cont(" # %6d # ", value >> 16);
353 else 351 else
354 printk(" %6d",value >> 16); 352 pr_cont(" %6d", value >> 16);
355 } 353 }
356 printk("\n"); 354 pr_cont("\n");
357 } 355 }
358 356
359 tvaudio_setcarrier(dev,scan->carr-90,scan->carr-90); 357 tvaudio_setcarrier(dev,scan->carr-90,scan->carr-90);
@@ -371,9 +369,9 @@ static int tvaudio_checkcarrier(struct saa7134_dev *dev, struct mainscan *scan)
371 left >>= 16; 369 left >>= 16;
372 right >>= 16; 370 right >>= 16;
373 value = left > right ? left - right : right - left; 371 value = left > right ? left - right : right - left;
374 dprintk("scanning %d.%03d MHz [%4s] => dc is %5d [%d/%d]\n", 372 audio_dbg(1, "scanning %d.%03d MHz [%4s] => dc is %5d [%d/%d]\n",
375 scan->carr / 1000, scan->carr % 1000, 373 scan->carr / 1000, scan->carr % 1000,
376 scan->name, value, left, right); 374 scan->name, value, left, right);
377 return value; 375 return value;
378} 376}
379 377
@@ -389,7 +387,7 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
389 case TVAUDIO_FM_K_STEREO: 387 case TVAUDIO_FM_K_STEREO:
390 case TVAUDIO_FM_BG_STEREO: 388 case TVAUDIO_FM_BG_STEREO:
391 idp = (saa_readb(SAA7134_IDENT_SIF) & 0xe0) >> 5; 389 idp = (saa_readb(SAA7134_IDENT_SIF) & 0xe0) >> 5;
392 dprintk("getstereo: fm/stereo: idp=0x%x\n",idp); 390 audio_dbg(1, "getstereo: fm/stereo: idp=0x%x\n", idp);
393 if (0x03 == (idp & 0x03)) 391 if (0x03 == (idp & 0x03))
394 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 392 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
395 else if (0x05 == (idp & 0x05)) 393 else if (0x05 == (idp & 0x05))
@@ -403,10 +401,11 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
403 case TVAUDIO_NICAM_FM: 401 case TVAUDIO_NICAM_FM:
404 case TVAUDIO_NICAM_AM: 402 case TVAUDIO_NICAM_AM:
405 nicam = saa_readb(SAA7134_AUDIO_STATUS); 403 nicam = saa_readb(SAA7134_AUDIO_STATUS);
406 dprintk("getstereo: nicam=0x%x\n",nicam); 404 audio_dbg(1, "getstereo: nicam=0x%x\n", nicam);
407 if (nicam & 0x1) { 405 if (nicam & 0x1) {
408 nicam_status = saa_readb(SAA7134_NICAM_STATUS); 406 nicam_status = saa_readb(SAA7134_NICAM_STATUS);
409 dprintk("getstereo: nicam_status=0x%x\n", nicam_status); 407 audio_dbg(1, "getstereo: nicam_status=0x%x\n",
408 nicam_status);
410 409
411 switch (nicam_status & 0x03) { 410 switch (nicam_status & 0x03) {
412 case 0x01: 411 case 0x01:
@@ -424,7 +423,7 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
424 break; 423 break;
425 } 424 }
426 if (retval != -1) 425 if (retval != -1)
427 dprintk("found audio subchannels:%s%s%s%s\n", 426 audio_dbg(1, "found audio subchannels:%s%s%s%s\n",
428 (retval & V4L2_TUNER_SUB_MONO) ? " mono" : "", 427 (retval & V4L2_TUNER_SUB_MONO) ? " mono" : "",
429 (retval & V4L2_TUNER_SUB_STEREO) ? " stereo" : "", 428 (retval & V4L2_TUNER_SUB_STEREO) ? " stereo" : "",
430 (retval & V4L2_TUNER_SUB_LANG1) ? " lang1" : "", 429 (retval & V4L2_TUNER_SUB_LANG1) ? " lang1" : "",
@@ -459,8 +458,8 @@ static int tvaudio_setstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
459 case TVAUDIO_FM_BG_STEREO: 458 case TVAUDIO_FM_BG_STEREO:
460 case TVAUDIO_NICAM_AM: 459 case TVAUDIO_NICAM_AM:
461 case TVAUDIO_NICAM_FM: 460 case TVAUDIO_NICAM_FM:
462 dprintk("setstereo [fm] => %s\n", 461 audio_dbg(1, "setstereo [fm] => %s\n",
463 name[ mode % ARRAY_SIZE(name) ]); 462 name[mode % ARRAY_SIZE(name)]);
464 reg = fm[ mode % ARRAY_SIZE(fm) ]; 463 reg = fm[ mode % ARRAY_SIZE(fm) ];
465 saa_writeb(SAA7134_FM_DEMATRIX, reg); 464 saa_writeb(SAA7134_FM_DEMATRIX, reg);
466 break; 465 break;
@@ -489,7 +488,8 @@ static int tvaudio_thread(void *data)
489 try_to_freeze(); 488 try_to_freeze();
490 489
491 dev->thread.scan1 = dev->thread.scan2; 490 dev->thread.scan1 = dev->thread.scan2;
492 dprintk("tvaudio thread scan start [%d]\n",dev->thread.scan1); 491 audio_dbg(1, "tvaudio thread scan start [%d]\n",
492 dev->thread.scan1);
493 dev->tvaudio = NULL; 493 dev->tvaudio = NULL;
494 494
495 saa_writeb(SAA7134_MONITOR_SELECT, 0xa0); 495 saa_writeb(SAA7134_MONITOR_SELECT, 0xa0);
@@ -519,7 +519,7 @@ static int tvaudio_thread(void *data)
519 519
520 if (1 == nscan) { 520 if (1 == nscan) {
521 /* only one candidate -- skip scan ;) */ 521 /* only one candidate -- skip scan ;) */
522 dprintk("only one main carrier candidate - skipping scan\n"); 522 audio_dbg(1, "only one main carrier candidate - skipping scan\n");
523 max1 = 12345; 523 max1 = 12345;
524 carrier = default_carrier; 524 carrier = default_carrier;
525 } else { 525 } else {
@@ -544,26 +544,24 @@ static int tvaudio_thread(void *data)
544 544
545 if (0 != carrier && max1 > 2000 && max1 > max2*3) { 545 if (0 != carrier && max1 > 2000 && max1 > max2*3) {
546 /* found good carrier */ 546 /* found good carrier */
547 dprintk("found %s main sound carrier @ %d.%03d MHz [%d/%d]\n", 547 audio_dbg(1, "found %s main sound carrier @ %d.%03d MHz [%d/%d]\n",
548 dev->tvnorm->name, carrier/1000, carrier%1000, 548 dev->tvnorm->name, carrier/1000, carrier%1000,
549 max1, max2); 549 max1, max2);
550 dev->last_carrier = carrier; 550 dev->last_carrier = carrier;
551 dev->automute = 0; 551 dev->automute = 0;
552 552
553 } else if (0 != dev->last_carrier) { 553 } else if (0 != dev->last_carrier) {
554 /* no carrier -- try last detected one as fallback */ 554 /* no carrier -- try last detected one as fallback */
555 carrier = dev->last_carrier; 555 carrier = dev->last_carrier;
556 dprintk("audio carrier scan failed, " 556 audio_dbg(1, "audio carrier scan failed, using %d.%03d MHz [last detected]\n",
557 "using %d.%03d MHz [last detected]\n", 557 carrier/1000, carrier%1000);
558 carrier/1000, carrier%1000);
559 dev->automute = 1; 558 dev->automute = 1;
560 559
561 } else { 560 } else {
562 /* no carrier + no fallback -- use default */ 561 /* no carrier + no fallback -- use default */
563 carrier = default_carrier; 562 carrier = default_carrier;
564 dprintk("audio carrier scan failed, " 563 audio_dbg(1, "audio carrier scan failed, using %d.%03d MHz [default]\n",
565 "using %d.%03d MHz [default]\n", 564 carrier/1000, carrier%1000);
566 carrier/1000, carrier%1000);
567 dev->automute = 1; 565 dev->automute = 1;
568 } 566 }
569 tvaudio_setcarrier(dev,carrier,carrier); 567 tvaudio_setcarrier(dev,carrier,carrier);
@@ -661,7 +659,7 @@ static inline int saa_dsp_reset_error_bit(struct saa7134_dev *dev)
661{ 659{
662 int state = saa_readb(SAA7135_DSP_RWSTATE); 660 int state = saa_readb(SAA7135_DSP_RWSTATE);
663 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) { 661 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) {
664 d2printk("%s: resetting error bit\n", dev->name); 662 audio_dbg(2, "%s: resetting error bit\n", dev->name);
665 saa_writeb(SAA7135_DSP_RWCLEAR, SAA7135_DSP_RWCLEAR_RERR); 663 saa_writeb(SAA7135_DSP_RWCLEAR, SAA7135_DSP_RWCLEAR_RERR);
666 } 664 }
667 return 0; 665 return 0;
@@ -673,18 +671,17 @@ static inline int saa_dsp_wait_bit(struct saa7134_dev *dev, int bit)
673 671
674 state = saa_readb(SAA7135_DSP_RWSTATE); 672 state = saa_readb(SAA7135_DSP_RWSTATE);
675 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) { 673 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) {
676 printk(KERN_WARNING "%s: dsp access error\n", dev->name); 674 pr_warn("%s: dsp access error\n", dev->name);
677 saa_dsp_reset_error_bit(dev); 675 saa_dsp_reset_error_bit(dev);
678 return -EIO; 676 return -EIO;
679 } 677 }
680 while (0 == (state & bit)) { 678 while (0 == (state & bit)) {
681 if (unlikely(0 == count)) { 679 if (unlikely(0 == count)) {
682 printk("%s: dsp access wait timeout [bit=%s]\n", 680 pr_err("dsp access wait timeout [bit=%s]\n",
683 dev->name, 681 (bit & SAA7135_DSP_RWSTATE_WRR) ? "WRR" :
684 (bit & SAA7135_DSP_RWSTATE_WRR) ? "WRR" : 682 (bit & SAA7135_DSP_RWSTATE_RDB) ? "RDB" :
685 (bit & SAA7135_DSP_RWSTATE_RDB) ? "RDB" : 683 (bit & SAA7135_DSP_RWSTATE_IDA) ? "IDA" :
686 (bit & SAA7135_DSP_RWSTATE_IDA) ? "IDA" : 684 "???");
687 "???");
688 return -EIO; 685 return -EIO;
689 } 686 }
690 saa_wait(DSP_DELAY); 687 saa_wait(DSP_DELAY);
@@ -699,7 +696,7 @@ int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value)
699{ 696{
700 int err; 697 int err;
701 698
702 d2printk("dsp write reg 0x%x = 0x%06x\n",reg<<2,value); 699 audio_dbg(2, "dsp write reg 0x%x = 0x%06x\n", reg << 2, value);
703 err = saa_dsp_wait_bit(dev,SAA7135_DSP_RWSTATE_WRR); 700 err = saa_dsp_wait_bit(dev,SAA7135_DSP_RWSTATE_WRR);
704 if (err < 0) 701 if (err < 0)
705 return err; 702 return err;
@@ -786,14 +783,16 @@ static int tvaudio_thread_ddep(void *data)
786 try_to_freeze(); 783 try_to_freeze();
787 784
788 dev->thread.scan1 = dev->thread.scan2; 785 dev->thread.scan1 = dev->thread.scan2;
789 dprintk("tvaudio thread scan start [%d]\n",dev->thread.scan1); 786 audio_dbg(1, "tvaudio thread scan start [%d]\n",
787 dev->thread.scan1);
790 788
791 if (audio_ddep >= 0x04 && audio_ddep <= 0x0e) { 789 if (audio_ddep >= 0x04 && audio_ddep <= 0x0e) {
792 /* insmod option override */ 790 /* insmod option override */
793 norms = (audio_ddep << 2) | 0x01; 791 norms = (audio_ddep << 2) | 0x01;
794 dprintk("ddep override: %s\n",stdres[audio_ddep]); 792 audio_dbg(1, "ddep override: %s\n",
793 stdres[audio_ddep]);
795 } else if (&card(dev).radio == dev->input) { 794 } else if (&card(dev).radio == dev->input) {
796 dprintk("FM Radio\n"); 795 audio_dbg(1, "FM Radio\n");
797 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) { 796 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) {
798 norms = (0x11 << 2) | 0x01; 797 norms = (0x11 << 2) | 0x01;
799 /* set IF frequency to 5.5 MHz */ 798 /* set IF frequency to 5.5 MHz */
@@ -816,12 +815,12 @@ static int tvaudio_thread_ddep(void *data)
816 norms |= 0x10; 815 norms |= 0x10;
817 if (0 == norms) 816 if (0 == norms)
818 norms = 0x7c; /* all */ 817 norms = 0x7c; /* all */
819 dprintk("scanning:%s%s%s%s%s\n", 818 audio_dbg(1, "scanning:%s%s%s%s%s\n",
820 (norms & 0x04) ? " B/G" : "", 819 (norms & 0x04) ? " B/G" : "",
821 (norms & 0x08) ? " D/K" : "", 820 (norms & 0x08) ? " D/K" : "",
822 (norms & 0x10) ? " L/L'" : "", 821 (norms & 0x10) ? " L/L'" : "",
823 (norms & 0x20) ? " I" : "", 822 (norms & 0x20) ? " I" : "",
824 (norms & 0x40) ? " M" : ""); 823 (norms & 0x40) ? " M" : "");
825 } 824 }
826 825
827 /* kick automatic standard detection */ 826 /* kick automatic standard detection */
@@ -836,29 +835,28 @@ static int tvaudio_thread_ddep(void *data)
836 goto restart; 835 goto restart;
837 value = saa_readl(0x528 >> 2) & 0xffffff; 836 value = saa_readl(0x528 >> 2) & 0xffffff;
838 837
839 dprintk("tvaudio thread status: 0x%x [%s%s%s]\n", 838 audio_dbg(1, "tvaudio thread status: 0x%x [%s%s%s]\n",
840 value, stdres[value & 0x1f], 839 value, stdres[value & 0x1f],
841 (value & 0x000020) ? ",stereo" : "", 840 (value & 0x000020) ? ",stereo" : "",
842 (value & 0x000040) ? ",dual" : ""); 841 (value & 0x000040) ? ",dual" : "");
843 dprintk("detailed status: " 842 audio_dbg(1, "detailed status: %s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s\n",
844 "%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s\n", 843 (value & 0x000080) ? " A2/EIAJ pilot tone " : "",
845 (value & 0x000080) ? " A2/EIAJ pilot tone " : "", 844 (value & 0x000100) ? " A2/EIAJ dual " : "",
846 (value & 0x000100) ? " A2/EIAJ dual " : "", 845 (value & 0x000200) ? " A2/EIAJ stereo " : "",
847 (value & 0x000200) ? " A2/EIAJ stereo " : "", 846 (value & 0x000400) ? " A2/EIAJ noise mute " : "",
848 (value & 0x000400) ? " A2/EIAJ noise mute " : "", 847
849 848 (value & 0x000800) ? " BTSC/FM radio pilot " : "",
850 (value & 0x000800) ? " BTSC/FM radio pilot " : "", 849 (value & 0x001000) ? " SAP carrier " : "",
851 (value & 0x001000) ? " SAP carrier " : "", 850 (value & 0x002000) ? " BTSC stereo noise mute " : "",
852 (value & 0x002000) ? " BTSC stereo noise mute " : "", 851 (value & 0x004000) ? " SAP noise mute " : "",
853 (value & 0x004000) ? " SAP noise mute " : "", 852 (value & 0x008000) ? " VDSP " : "",
854 (value & 0x008000) ? " VDSP " : "", 853
855 854 (value & 0x010000) ? " NICST " : "",
856 (value & 0x010000) ? " NICST " : "", 855 (value & 0x020000) ? " NICDU " : "",
857 (value & 0x020000) ? " NICDU " : "", 856 (value & 0x040000) ? " NICAM muted " : "",
858 (value & 0x040000) ? " NICAM muted " : "", 857 (value & 0x080000) ? " NICAM reserve sound " : "",
859 (value & 0x080000) ? " NICAM reserve sound " : "", 858
860 859 (value & 0x100000) ? " init done " : "");
861 (value & 0x100000) ? " init done " : "");
862 } 860 }
863 861
864 done: 862 done:
@@ -1031,7 +1029,7 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
1031 /* start tvaudio thread */ 1029 /* start tvaudio thread */
1032 dev->thread.thread = kthread_run(my_thread, dev, "%s", dev->name); 1030 dev->thread.thread = kthread_run(my_thread, dev, "%s", dev->name);
1033 if (IS_ERR(dev->thread.thread)) { 1031 if (IS_ERR(dev->thread.thread)) {
1034 printk(KERN_WARNING "%s: kernel_thread() failed\n", 1032 pr_warn("%s: kernel_thread() failed\n",
1035 dev->name); 1033 dev->name);
1036 /* XXX: missing error handling here */ 1034 /* XXX: missing error handling here */
1037 } 1035 }
@@ -1061,7 +1059,7 @@ int saa7134_tvaudio_fini(struct saa7134_dev *dev)
1061int saa7134_tvaudio_do_scan(struct saa7134_dev *dev) 1059int saa7134_tvaudio_do_scan(struct saa7134_dev *dev)
1062{ 1060{
1063 if (dev->input->amux != TV) { 1061 if (dev->input->amux != TV) {
1064 dprintk("sound IF not in use, skipping scan\n"); 1062 audio_dbg(1, "sound IF not in use, skipping scan\n");
1065 dev->automute = 0; 1063 dev->automute = 0;
1066 saa7134_tvaudio_setmute(dev); 1064 saa7134_tvaudio_setmute(dev);
1067 } else if (dev->thread.thread) { 1065 } else if (dev->thread.thread) {
diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c
index 5306e549e526..4d36586ad752 100644
--- a/drivers/media/pci/saa7134/saa7134-vbi.c
+++ b/drivers/media/pci/saa7134/saa7134-vbi.c
@@ -20,14 +20,14 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
26#include <linux/kernel.h> 29#include <linux/kernel.h>
27 30
28#include "saa7134-reg.h"
29#include "saa7134.h"
30
31/* ------------------------------------------------------------------ */ 31/* ------------------------------------------------------------------ */
32 32
33static unsigned int vbi_debug; 33static unsigned int vbi_debug;
@@ -38,8 +38,10 @@ static unsigned int vbibufs = 4;
38module_param(vbibufs, int, 0444); 38module_param(vbibufs, int, 0444);
39MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32"); 39MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32");
40 40
41#define dprintk(fmt, arg...) if (vbi_debug) \ 41#define vbi_dbg(fmt, arg...) do { \
42 printk(KERN_DEBUG "%s/vbi: " fmt, dev->name , ## arg) 42 if (vbi_debug) \
43 printk(KERN_DEBUG pr_fmt("vbi: " fmt), ## arg); \
44 } while (0)
43 45
44/* ------------------------------------------------------------------ */ 46/* ------------------------------------------------------------------ */
45 47
@@ -84,7 +86,7 @@ static int buffer_activate(struct saa7134_dev *dev,
84 struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_queue->drv_priv; 86 struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_queue->drv_priv;
85 unsigned long control, base; 87 unsigned long control, base;
86 88
87 dprintk("buffer_activate [%p]\n", buf); 89 vbi_dbg("buffer_activate [%p]\n", buf);
88 buf->top_seen = 0; 90 buf->top_seen = 0;
89 91
90 task_init(dev, buf, TASK_A); 92 task_init(dev, buf, TASK_A);
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 99d09a7566d3..035039cfae6d 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -20,6 +20,9 @@
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 "saa7134.h"
24#include "saa7134-reg.h"
25
23#include <linux/init.h> 26#include <linux/init.h>
24#include <linux/list.h> 27#include <linux/list.h>
25#include <linux/module.h> 28#include <linux/module.h>
@@ -31,9 +34,6 @@
31#include <media/v4l2-event.h> 34#include <media/v4l2-event.h>
32#include <media/saa6588.h> 35#include <media/saa6588.h>
33 36
34#include "saa7134-reg.h"
35#include "saa7134.h"
36
37/* ------------------------------------------------------------------ */ 37/* ------------------------------------------------------------------ */
38 38
39unsigned int video_debug; 39unsigned int video_debug;
@@ -52,8 +52,10 @@ module_param_string(secam, secam, sizeof(secam), 0644);
52MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc"); 52MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc");
53 53
54 54
55#define dprintk(fmt, arg...) if (video_debug&0x04) \ 55#define video_dbg(fmt, arg...) do { \
56 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg) 56 if (video_debug & 0x04) \
57 printk(KERN_DEBUG pr_fmt("video: " fmt), ## arg); \
58 } while (0)
57 59
58/* ------------------------------------------------------------------ */ 60/* ------------------------------------------------------------------ */
59/* Defines for Video Output Port Register at address 0x191 */ 61/* Defines for Video Output Port Register at address 0x191 */
@@ -385,7 +387,7 @@ static struct saa7134_format* format_by_fourcc(unsigned int fourcc)
385 387
386static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm) 388static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
387{ 389{
388 dprintk("set tv norm = %s\n",norm->name); 390 video_dbg("set tv norm = %s\n", norm->name);
389 dev->tvnorm = norm; 391 dev->tvnorm = norm;
390 392
391 /* setup cropping */ 393 /* setup cropping */
@@ -407,7 +409,7 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
407 409
408static void video_mux(struct saa7134_dev *dev, int input) 410static void video_mux(struct saa7134_dev *dev, int input)
409{ 411{
410 dprintk("video input = %d [%s]\n", input, card_in(dev, input).name); 412 video_dbg("video input = %d [%s]\n", input, card_in(dev, input).name);
411 dev->ctl_input = input; 413 dev->ctl_input = input;
412 set_tvnorm(dev, dev->tvnorm); 414 set_tvnorm(dev, dev->tvnorm);
413 saa7134_tvaudio_setinput(dev, &card_in(dev, input)); 415 saa7134_tvaudio_setinput(dev, &card_in(dev, input));
@@ -531,14 +533,14 @@ static void set_v_scale(struct saa7134_dev *dev, int task, int yscale)
531 mirror = (dev->ctl_mirror) ? 0x02 : 0x00; 533 mirror = (dev->ctl_mirror) ? 0x02 : 0x00;
532 if (yscale < 2048) { 534 if (yscale < 2048) {
533 /* LPI */ 535 /* LPI */
534 dprintk("yscale LPI yscale=%d\n",yscale); 536 video_dbg("yscale LPI yscale=%d\n", yscale);
535 saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror); 537 saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror);
536 saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40); 538 saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40);
537 saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40); 539 saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40);
538 } else { 540 } else {
539 /* ACM */ 541 /* ACM */
540 val = 0x40 * 1024 / yscale; 542 val = 0x40 * 1024 / yscale;
541 dprintk("yscale ACM yscale=%d val=0x%x\n",yscale,val); 543 video_dbg("yscale ACM yscale=%d val=0x%x\n", yscale, val);
542 saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror); 544 saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror);
543 saa_writeb(SAA7134_LUMA_CONTRAST(task), val); 545 saa_writeb(SAA7134_LUMA_CONTRAST(task), val);
544 saa_writeb(SAA7134_CHROMA_SATURATION(task), val); 546 saa_writeb(SAA7134_CHROMA_SATURATION(task), val);
@@ -573,7 +575,8 @@ static void set_size(struct saa7134_dev *dev, int task,
573 prescale = 1; 575 prescale = 1;
574 xscale = 1024 * dev->crop_current.width / prescale / width; 576 xscale = 1024 * dev->crop_current.width / prescale / width;
575 yscale = 512 * div * dev->crop_current.height / height; 577 yscale = 512 * div * dev->crop_current.height / height;
576 dprintk("prescale=%d xscale=%d yscale=%d\n",prescale,xscale,yscale); 578 video_dbg("prescale=%d xscale=%d yscale=%d\n",
579 prescale, xscale, yscale);
577 set_h_prescale(dev,task,prescale); 580 set_h_prescale(dev,task,prescale);
578 saa_writeb(SAA7134_H_SCALE_INC1(task), xscale & 0xff); 581 saa_writeb(SAA7134_H_SCALE_INC1(task), xscale & 0xff);
579 saa_writeb(SAA7134_H_SCALE_INC2(task), xscale >> 8); 582 saa_writeb(SAA7134_H_SCALE_INC2(task), xscale >> 8);
@@ -615,7 +618,7 @@ static void set_cliplist(struct saa7134_dev *dev, int reg,
615 saa_writeb(reg + 0, winbits); 618 saa_writeb(reg + 0, winbits);
616 saa_writeb(reg + 2, cl[i].position & 0xff); 619 saa_writeb(reg + 2, cl[i].position & 0xff);
617 saa_writeb(reg + 3, cl[i].position >> 8); 620 saa_writeb(reg + 3, cl[i].position >> 8);
618 dprintk("clip: %s winbits=%02x pos=%d\n", 621 video_dbg("clip: %s winbits=%02x pos=%d\n",
619 name,winbits,cl[i].position); 622 name,winbits,cl[i].position);
620 reg += 8; 623 reg += 8;
621 } 624 }
@@ -730,7 +733,7 @@ static int start_preview(struct saa7134_dev *dev)
730 return err; 733 return err;
731 734
732 dev->ovfield = dev->win.field; 735 dev->ovfield = dev->win.field;
733 dprintk("start_preview %dx%d+%d+%d %s field=%s\n", 736 video_dbg("start_preview %dx%d+%d+%d %s field=%s\n",
734 dev->win.w.width, dev->win.w.height, 737 dev->win.w.width, dev->win.w.height,
735 dev->win.w.left, dev->win.w.top, 738 dev->win.w.left, dev->win.w.top,
736 dev->ovfmt->name, v4l2_field_names[dev->ovfield]); 739 dev->ovfmt->name, v4l2_field_names[dev->ovfield]);
@@ -792,7 +795,7 @@ static int buffer_activate(struct saa7134_dev *dev,
792 unsigned long base,control,bpl; 795 unsigned long base,control,bpl;
793 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */ 796 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
794 797
795 dprintk("buffer_activate buf=%p\n",buf); 798 video_dbg("buffer_activate buf=%p\n", buf);
796 buf->top_seen = 0; 799 buf->top_seen = 0;
797 800
798 set_size(dev, TASK_A, dev->width, dev->height, 801 set_size(dev, TASK_A, dev->width, dev->height,
@@ -837,7 +840,7 @@ static int buffer_activate(struct saa7134_dev *dev,
837 base3 = base2 + bpl_uv * lines_uv; 840 base3 = base2 + bpl_uv * lines_uv;
838 if (dev->fmt->uvswap) 841 if (dev->fmt->uvswap)
839 tmp = base2, base2 = base3, base3 = tmp; 842 tmp = base2, base2 = base3, base3 = tmp;
840 dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n", 843 video_dbg("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
841 bpl_uv,lines_uv,base2,base3); 844 bpl_uv,lines_uv,base2,base3);
842 if (V4L2_FIELD_HAS_BOTH(dev->field)) { 845 if (V4L2_FIELD_HAS_BOTH(dev->field)) {
843 /* interlaced */ 846 /* interlaced */
@@ -1229,7 +1232,7 @@ static int saa7134_g_fmt_vid_overlay(struct file *file, void *priv,
1229 int i; 1232 int i;
1230 1233
1231 if (saa7134_no_overlay > 0) { 1234 if (saa7134_no_overlay > 0) {
1232 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1235 pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1233 return -EINVAL; 1236 return -EINVAL;
1234 } 1237 }
1235 f->fmt.win = dev->win; 1238 f->fmt.win = dev->win;
@@ -1305,7 +1308,7 @@ static int saa7134_try_fmt_vid_overlay(struct file *file, void *priv,
1305 struct saa7134_dev *dev = video_drvdata(file); 1308 struct saa7134_dev *dev = video_drvdata(file);
1306 1309
1307 if (saa7134_no_overlay > 0) { 1310 if (saa7134_no_overlay > 0) {
1308 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1311 pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1309 return -EINVAL; 1312 return -EINVAL;
1310 } 1313 }
1311 1314
@@ -1339,7 +1342,7 @@ static int saa7134_s_fmt_vid_overlay(struct file *file, void *priv,
1339 unsigned long flags; 1342 unsigned long flags;
1340 1343
1341 if (saa7134_no_overlay > 0) { 1344 if (saa7134_no_overlay > 0) {
1342 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1345 pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1343 return -EINVAL; 1346 return -EINVAL;
1344 } 1347 }
1345 if (f->fmt.win.clips == NULL) 1348 if (f->fmt.win.clips == NULL)
@@ -1738,7 +1741,7 @@ static int saa7134_enum_fmt_vid_overlay(struct file *file, void *priv,
1738 struct v4l2_fmtdesc *f) 1741 struct v4l2_fmtdesc *f)
1739{ 1742{
1740 if (saa7134_no_overlay > 0) { 1743 if (saa7134_no_overlay > 0) {
1741 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1744 pr_err("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1742 return -EINVAL; 1745 return -EINVAL;
1743 } 1746 }
1744 1747
@@ -1795,7 +1798,7 @@ static int saa7134_overlay(struct file *file, void *priv, unsigned int on)
1795 1798
1796 if (on) { 1799 if (on) {
1797 if (saa7134_no_overlay > 0) { 1800 if (saa7134_no_overlay > 0) {
1798 dprintk("no_overlay\n"); 1801 video_dbg("no_overlay\n");
1799 return -EINVAL; 1802 return -EINVAL;
1800 } 1803 }
1801 1804
@@ -2184,7 +2187,7 @@ void saa7134_irq_video_signalchange(struct saa7134_dev *dev)
2184 2187
2185 st1 = saa_readb(SAA7134_STATUS_VIDEO1); 2188 st1 = saa_readb(SAA7134_STATUS_VIDEO1);
2186 st2 = saa_readb(SAA7134_STATUS_VIDEO2); 2189 st2 = saa_readb(SAA7134_STATUS_VIDEO2);
2187 dprintk("DCSDT: pll: %s, sync: %s, norm: %s\n", 2190 video_dbg("DCSDT: pll: %s, sync: %s, norm: %s\n",
2188 (st1 & 0x40) ? "not locked" : "locked", 2191 (st1 & 0x40) ? "not locked" : "locked",
2189 (st2 & 0x40) ? "no" : "yes", 2192 (st2 & 0x40) ? "no" : "yes",
2190 st[st1 & 0x03]); 2193 st[st1 & 0x03]);
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index 8bf0553b8d2f..6b5f6f45d285 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -21,6 +21,8 @@
21 21
22#define SAA7134_VERSION "0, 2, 17" 22#define SAA7134_VERSION "0, 2, 17"
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/pci.h> 26#include <linux/pci.h>
25#include <linux/i2c.h> 27#include <linux/i2c.h>
26#include <linux/videodev2.h> 28#include <linux/videodev2.h>
@@ -339,6 +341,7 @@ struct saa7134_card_ir {
339#define SAA7134_BOARD_HAWELL_HW_9004V1 191 341#define SAA7134_BOARD_HAWELL_HW_9004V1 191
340#define SAA7134_BOARD_AVERMEDIA_A706 192 342#define SAA7134_BOARD_AVERMEDIA_A706 192
341#define SAA7134_BOARD_WIS_VOYAGER 193 343#define SAA7134_BOARD_WIS_VOYAGER 193
344#define SAA7134_BOARD_AVERMEDIA_505 194
342 345
343#define SAA7134_MAXBOARDS 32 346#define SAA7134_MAXBOARDS 32
344#define SAA7134_INPUT_MAX 8 347#define SAA7134_INPUT_MAX 8
@@ -654,7 +657,8 @@ struct saa7134_dev {
654 /* SAA7134_MPEG_DVB only */ 657 /* SAA7134_MPEG_DVB only */
655 struct vb2_dvb_frontends frontends; 658 struct vb2_dvb_frontends frontends;
656 int (*original_demod_sleep)(struct dvb_frontend *fe); 659 int (*original_demod_sleep)(struct dvb_frontend *fe);
657 int (*original_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 660 int (*original_set_voltage)(struct dvb_frontend *fe,
661 enum fe_sec_voltage voltage);
658 int (*original_set_high_voltage)(struct dvb_frontend *fe, long arg); 662 int (*original_set_high_voltage)(struct dvb_frontend *fe, long arg);
659#endif 663#endif
660 void (*gate_ctrl)(struct saa7134_dev *dev, int open); 664 void (*gate_ctrl)(struct saa7134_dev *dev, int open);
diff --git a/drivers/media/pci/saa7164/saa7164-api.c b/drivers/media/pci/saa7164/saa7164-api.c
index 4f3b1dd18ba4..e7e586c1ba53 100644
--- a/drivers/media/pci/saa7164/saa7164-api.c
+++ b/drivers/media/pci/saa7164/saa7164-api.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -1373,7 +1373,8 @@ int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
1373 u8 buf[256]; 1373 u8 buf[256];
1374 int ret; 1374 int ret;
1375 1375
1376 dprintk(DBGLVL_API, "%s()\n", __func__); 1376 dprintk(DBGLVL_API, "%s() addr=%x reglen=%d datalen=%d\n",
1377 __func__, addr, reglen, datalen);
1377 1378
1378 if (reglen > 4) 1379 if (reglen > 4)
1379 return -EIO; 1380 return -EIO;
@@ -1434,7 +1435,8 @@ int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen,
1434 u8 buf[256]; 1435 u8 buf[256];
1435 int ret; 1436 int ret;
1436 1437
1437 dprintk(DBGLVL_API, "%s()\n", __func__); 1438 dprintk(DBGLVL_API, "%s() addr=0x%2x len=0x%x\n",
1439 __func__, addr, datalen);
1438 1440
1439 if ((datalen == 0) || (datalen > 232)) 1441 if ((datalen == 0) || (datalen > 232))
1440 return -EIO; 1442 return -EIO;
@@ -1464,7 +1466,8 @@ int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen,
1464 return -EIO; 1466 return -EIO;
1465 } 1467 }
1466 1468
1467 dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len); 1469 dprintk(DBGLVL_API, "%s() len = %d bytes unitid=0x%x\n", __func__,
1470 len, unitid);
1468 1471
1469 /* Prepare the send buffer */ 1472 /* Prepare the send buffer */
1470 /* Bytes 00-03 dest register length 1473 /* Bytes 00-03 dest register length
diff --git a/drivers/media/pci/saa7164/saa7164-buffer.c b/drivers/media/pci/saa7164/saa7164-buffer.c
index 9bd1f73f82da..f30758e24f5d 100644
--- a/drivers/media/pci/saa7164/saa7164-buffer.c
+++ b/drivers/media/pci/saa7164/saa7164-buffer.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/pci/saa7164/saa7164-bus.c b/drivers/media/pci/saa7164/saa7164-bus.c
index 6c73f5b155f6..a18fe5d47238 100644
--- a/drivers/media/pci/saa7164/saa7164-bus.c
+++ b/drivers/media/pci/saa7164/saa7164-bus.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/pci/saa7164/saa7164-cards.c b/drivers/media/pci/saa7164/saa7164-cards.c
index 5b72da5ce418..c2b738227f58 100644
--- a/drivers/media/pci/saa7164/saa7164-cards.c
+++ b/drivers/media/pci/saa7164/saa7164-cards.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@
30 * attached I2C devices, so we can simplify the virtual i2c mechansms 30 * attached I2C devices, so we can simplify the virtual i2c mechansms
31 * and keep the -i2c.c implementation clean. 31 * and keep the -i2c.c implementation clean.
32 */ 32 */
33#define REGLEN_0bit 0
33#define REGLEN_8bit 1 34#define REGLEN_8bit 1
34#define REGLEN_16bit 2 35#define REGLEN_16bit 2
35 36
@@ -499,6 +500,144 @@ struct saa7164_board saa7164_boards[] = {
499 .i2c_reg_len = REGLEN_8bit, 500 .i2c_reg_len = REGLEN_8bit,
500 } }, 501 } },
501 }, 502 },
503 [SAA7164_BOARD_HAUPPAUGE_HVR2255proto] = {
504 .name = "Hauppauge WinTV-HVR2255(proto)",
505 .porta = SAA7164_MPEG_DVB,
506 .portb = SAA7164_MPEG_DVB,
507 .portc = SAA7164_MPEG_ENCODER,
508 .portd = SAA7164_MPEG_ENCODER,
509 .porte = SAA7164_MPEG_VBI,
510 .portf = SAA7164_MPEG_VBI,
511 .chiprev = SAA7164_CHIP_REV3,
512 .unit = {{
513 .id = 0x27,
514 .type = SAA7164_UNIT_EEPROM,
515 .name = "4K EEPROM",
516 .i2c_bus_nr = SAA7164_I2C_BUS_0,
517 .i2c_bus_addr = 0xa0 >> 1,
518 .i2c_reg_len = REGLEN_8bit,
519 }, {
520 .id = 0x04,
521 .type = SAA7164_UNIT_TUNER,
522 .name = "SI2157-1",
523 .i2c_bus_nr = SAA7164_I2C_BUS_0,
524 .i2c_bus_addr = 0xc0 >> 1,
525 .i2c_reg_len = REGLEN_0bit,
526 }, {
527 .id = 0x06,
528 .type = SAA7164_UNIT_DIGITAL_DEMODULATOR,
529 .name = "LGDT3306",
530 .i2c_bus_nr = SAA7164_I2C_BUS_2,
531 .i2c_bus_addr = 0xb2 >> 1,
532 .i2c_reg_len = REGLEN_8bit,
533 }, {
534 .id = 0x24,
535 .type = SAA7164_UNIT_TUNER,
536 .name = "SI2157-2",
537 .i2c_bus_nr = SAA7164_I2C_BUS_1,
538 .i2c_bus_addr = 0xc0 >> 1,
539 .i2c_reg_len = REGLEN_0bit,
540 }, {
541 .id = 0x26,
542 .type = SAA7164_UNIT_DIGITAL_DEMODULATOR,
543 .name = "LGDT3306-2",
544 .i2c_bus_nr = SAA7164_I2C_BUS_2,
545 .i2c_bus_addr = 0x1c >> 1,
546 .i2c_reg_len = REGLEN_8bit,
547 } },
548 },
549 [SAA7164_BOARD_HAUPPAUGE_HVR2255] = {
550 .name = "Hauppauge WinTV-HVR2255",
551 .porta = SAA7164_MPEG_DVB,
552 .portb = SAA7164_MPEG_DVB,
553 .portc = SAA7164_MPEG_ENCODER,
554 .portd = SAA7164_MPEG_ENCODER,
555 .porte = SAA7164_MPEG_VBI,
556 .portf = SAA7164_MPEG_VBI,
557 .chiprev = SAA7164_CHIP_REV3,
558 .unit = {{
559 .id = 0x28,
560 .type = SAA7164_UNIT_EEPROM,
561 .name = "4K EEPROM",
562 .i2c_bus_nr = SAA7164_I2C_BUS_0,
563 .i2c_bus_addr = 0xa0 >> 1,
564 .i2c_reg_len = REGLEN_8bit,
565 }, {
566 .id = 0x04,
567 .type = SAA7164_UNIT_TUNER,
568 .name = "SI2157-1",
569 .i2c_bus_nr = SAA7164_I2C_BUS_0,
570 .i2c_bus_addr = 0xc0 >> 1,
571 .i2c_reg_len = REGLEN_0bit,
572 }, {
573 .id = 0x06,
574 .type = SAA7164_UNIT_DIGITAL_DEMODULATOR,
575 .name = "LGDT3306-1",
576 .i2c_bus_nr = SAA7164_I2C_BUS_2,
577 .i2c_bus_addr = 0xb2 >> 1,
578 .i2c_reg_len = REGLEN_8bit,
579 }, {
580 .id = 0x25,
581 .type = SAA7164_UNIT_TUNER,
582 .name = "SI2157-2",
583 .i2c_bus_nr = SAA7164_I2C_BUS_1,
584 .i2c_bus_addr = 0xc0 >> 1,
585 .i2c_reg_len = REGLEN_0bit,
586 }, {
587 .id = 0x27,
588 .type = SAA7164_UNIT_DIGITAL_DEMODULATOR,
589 .name = "LGDT3306-2",
590 .i2c_bus_nr = SAA7164_I2C_BUS_2,
591 .i2c_bus_addr = 0x1c >> 1,
592 .i2c_reg_len = REGLEN_8bit,
593 } },
594 },
595 [SAA7164_BOARD_HAUPPAUGE_HVR2205] = {
596 .name = "Hauppauge WinTV-HVR2205",
597 .porta = SAA7164_MPEG_DVB,
598 .portb = SAA7164_MPEG_DVB,
599 .portc = SAA7164_MPEG_ENCODER,
600 .portd = SAA7164_MPEG_ENCODER,
601 .porte = SAA7164_MPEG_VBI,
602 .portf = SAA7164_MPEG_VBI,
603 .chiprev = SAA7164_CHIP_REV3,
604 .unit = {{
605 .id = 0x28,
606 .type = SAA7164_UNIT_EEPROM,
607 .name = "4K EEPROM",
608 .i2c_bus_nr = SAA7164_I2C_BUS_0,
609 .i2c_bus_addr = 0xa0 >> 1,
610 .i2c_reg_len = REGLEN_8bit,
611 }, {
612 .id = 0x04,
613 .type = SAA7164_UNIT_TUNER,
614 .name = "SI2157-1",
615 .i2c_bus_nr = SAA7164_I2C_BUS_0,
616 .i2c_bus_addr = 0xc0 >> 1,
617 .i2c_reg_len = REGLEN_0bit,
618 }, {
619 .id = 0x06,
620 .type = SAA7164_UNIT_DIGITAL_DEMODULATOR,
621 .name = "SI2168-1",
622 .i2c_bus_nr = SAA7164_I2C_BUS_2,
623 .i2c_bus_addr = 0xc8 >> 1,
624 .i2c_reg_len = REGLEN_0bit,
625 }, {
626 .id = 0x25,
627 .type = SAA7164_UNIT_TUNER,
628 .name = "SI2157-2",
629 .i2c_bus_nr = SAA7164_I2C_BUS_1,
630 .i2c_bus_addr = 0xc0 >> 1,
631 .i2c_reg_len = REGLEN_0bit,
632 }, {
633 .id = 0x27,
634 .type = SAA7164_UNIT_DIGITAL_DEMODULATOR,
635 .name = "SI2168-2",
636 .i2c_bus_nr = SAA7164_I2C_BUS_2,
637 .i2c_bus_addr = 0xcc >> 1,
638 .i2c_reg_len = REGLEN_0bit,
639 } },
640 },
502}; 641};
503const unsigned int saa7164_bcount = ARRAY_SIZE(saa7164_boards); 642const unsigned int saa7164_bcount = ARRAY_SIZE(saa7164_boards);
504 643
@@ -546,6 +685,21 @@ struct saa7164_subid saa7164_subids[] = {
546 .subvendor = 0x0070, 685 .subvendor = 0x0070,
547 .subdevice = 0x8953, 686 .subdevice = 0x8953,
548 .card = SAA7164_BOARD_HAUPPAUGE_HVR2200_5, 687 .card = SAA7164_BOARD_HAUPPAUGE_HVR2200_5,
688 }, {
689 .subvendor = 0x0070,
690 .subdevice = 0xf111,
691 .card = SAA7164_BOARD_HAUPPAUGE_HVR2255,
692 /* Prototype card left here for documenation purposes.
693 .card = SAA7164_BOARD_HAUPPAUGE_HVR2255proto,
694 */
695 }, {
696 .subvendor = 0x0070,
697 .subdevice = 0xf123,
698 .card = SAA7164_BOARD_HAUPPAUGE_HVR2205,
699 }, {
700 .subvendor = 0x0070,
701 .subdevice = 0xf120,
702 .card = SAA7164_BOARD_HAUPPAUGE_HVR2205,
549 }, 703 },
550}; 704};
551const unsigned int saa7164_idcount = ARRAY_SIZE(saa7164_subids); 705const unsigned int saa7164_idcount = ARRAY_SIZE(saa7164_subids);
@@ -594,12 +748,26 @@ void saa7164_gpio_setup(struct saa7164_dev *dev)
594 case SAA7164_BOARD_HAUPPAUGE_HVR2250: 748 case SAA7164_BOARD_HAUPPAUGE_HVR2250:
595 case SAA7164_BOARD_HAUPPAUGE_HVR2250_2: 749 case SAA7164_BOARD_HAUPPAUGE_HVR2250_2:
596 case SAA7164_BOARD_HAUPPAUGE_HVR2250_3: 750 case SAA7164_BOARD_HAUPPAUGE_HVR2250_3:
751 case SAA7164_BOARD_HAUPPAUGE_HVR2255proto:
752 case SAA7164_BOARD_HAUPPAUGE_HVR2255:
753 case SAA7164_BOARD_HAUPPAUGE_HVR2205:
597 /* 754 /*
755 HVR2200 / HVR2250
598 GPIO 2: s5h1411 / tda10048-1 demod reset 756 GPIO 2: s5h1411 / tda10048-1 demod reset
599 GPIO 3: s5h1411 / tda10048-2 demod reset 757 GPIO 3: s5h1411 / tda10048-2 demod reset
600 GPIO 7: IRBlaster Zilog reset 758 GPIO 7: IRBlaster Zilog reset
601 */ 759 */
602 760
761 /* HVR2255
762 * GPIO 2: lgdg3306-1 demod reset
763 * GPIO 3: lgdt3306-2 demod reset
764 */
765
766 /* HVR2205
767 * GPIO 2: si2168-1 demod reset
768 * GPIO 3: si2168-2 demod reset
769 */
770
603 /* Reset parts by going in and out of reset */ 771 /* Reset parts by going in and out of reset */
604 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 2); 772 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 2);
605 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 3); 773 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 3);
@@ -647,6 +815,21 @@ static void hauppauge_eeprom(struct saa7164_dev *dev, u8 *eeprom_data)
647 /* WinTV-HVR2200 (PCIe, Retail, half-height) 815 /* WinTV-HVR2200 (PCIe, Retail, half-height)
648 * DVB-T (TDA18271/TDA10048) and basic analog, no IR */ 816 * DVB-T (TDA18271/TDA10048) and basic analog, no IR */
649 break; 817 break;
818 case 151009:
819 /* First production board rev B2I6 */
820 /* WinTV-HVR2205 (PCIe, Retail, full-height bracket)
821 * DVB-T/T2/C (SI2157/SI2168) and basic analog, FM */
822 break;
823 case 151609:
824 /* First production board rev B2I6 */
825 /* WinTV-HVR2205 (PCIe, Retail, half-height bracket)
826 * DVB-T/T2/C (SI2157/SI2168) and basic analog, FM */
827 break;
828 case 151061:
829 /* First production board rev B1I6 */
830 /* WinTV-HVR2255 (PCIe, Retail, full-height bracket)
831 * ATSC/QAM (SI2157/LGDT3306) and basic analog, FM */
832 break;
650 default: 833 default:
651 printk(KERN_ERR "%s: Warning: Unknown Hauppauge model #%d\n", 834 printk(KERN_ERR "%s: Warning: Unknown Hauppauge model #%d\n",
652 dev->name, tv.model); 835 dev->name, tv.model);
@@ -676,6 +859,9 @@ void saa7164_card_setup(struct saa7164_dev *dev)
676 case SAA7164_BOARD_HAUPPAUGE_HVR2250: 859 case SAA7164_BOARD_HAUPPAUGE_HVR2250:
677 case SAA7164_BOARD_HAUPPAUGE_HVR2250_2: 860 case SAA7164_BOARD_HAUPPAUGE_HVR2250_2:
678 case SAA7164_BOARD_HAUPPAUGE_HVR2250_3: 861 case SAA7164_BOARD_HAUPPAUGE_HVR2250_3:
862 case SAA7164_BOARD_HAUPPAUGE_HVR2255proto:
863 case SAA7164_BOARD_HAUPPAUGE_HVR2255:
864 case SAA7164_BOARD_HAUPPAUGE_HVR2205:
679 hauppauge_eeprom(dev, &eeprom[0]); 865 hauppauge_eeprom(dev, &eeprom[0]);
680 break; 866 break;
681 } 867 }
diff --git a/drivers/media/pci/saa7164/saa7164-cmd.c b/drivers/media/pci/saa7164/saa7164-cmd.c
index cfabcbacc33d..3285c37b4583 100644
--- a/drivers/media/pci/saa7164/saa7164-cmd.c
+++ b/drivers/media/pci/saa7164/saa7164-cmd.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
index 9cf3c6cba498..3206a826b80d 100644
--- a/drivers/media/pci/saa7164/saa7164-core.c
+++ b/drivers/media/pci/saa7164/saa7164-core.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -85,6 +85,11 @@ module_param(guard_checking, int, 0644);
85MODULE_PARM_DESC(guard_checking, 85MODULE_PARM_DESC(guard_checking,
86 "enable dma sanity checking for buffer overruns"); 86 "enable dma sanity checking for buffer overruns");
87 87
88static bool enable_msi = true;
89module_param(enable_msi, bool, 0444);
90MODULE_PARM_DESC(enable_msi,
91 "enable the use of an msi interrupt if available");
92
88static unsigned int saa7164_devcount; 93static unsigned int saa7164_devcount;
89 94
90static DEFINE_MUTEX(devlist); 95static DEFINE_MUTEX(devlist);
@@ -618,12 +623,7 @@ static irqreturn_t saa7164_irq_ts(struct saa7164_port *port)
618static irqreturn_t saa7164_irq(int irq, void *dev_id) 623static irqreturn_t saa7164_irq(int irq, void *dev_id)
619{ 624{
620 struct saa7164_dev *dev = dev_id; 625 struct saa7164_dev *dev = dev_id;
621 struct saa7164_port *porta = &dev->ports[SAA7164_PORT_TS1]; 626 struct saa7164_port *porta, *portb, *portc, *portd, *porte, *portf;
622 struct saa7164_port *portb = &dev->ports[SAA7164_PORT_TS2];
623 struct saa7164_port *portc = &dev->ports[SAA7164_PORT_ENC1];
624 struct saa7164_port *portd = &dev->ports[SAA7164_PORT_ENC2];
625 struct saa7164_port *porte = &dev->ports[SAA7164_PORT_VBI1];
626 struct saa7164_port *portf = &dev->ports[SAA7164_PORT_VBI2];
627 627
628 u32 intid, intstat[INT_SIZE/4]; 628 u32 intid, intstat[INT_SIZE/4];
629 int i, handled = 0, bit; 629 int i, handled = 0, bit;
@@ -634,6 +634,13 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
634 goto out; 634 goto out;
635 } 635 }
636 636
637 porta = &dev->ports[SAA7164_PORT_TS1];
638 portb = &dev->ports[SAA7164_PORT_TS2];
639 portc = &dev->ports[SAA7164_PORT_ENC1];
640 portd = &dev->ports[SAA7164_PORT_ENC2];
641 porte = &dev->ports[SAA7164_PORT_VBI1];
642 portf = &dev->ports[SAA7164_PORT_VBI2];
643
637 /* Check that the hardware is accessible. If the status bytes are 644 /* Check that the hardware is accessible. If the status bytes are
638 * 0xFF then the device is not accessible, the the IRQ belongs 645 * 0xFF then the device is not accessible, the the IRQ belongs
639 * to another driver. 646 * to another driver.
@@ -1184,6 +1191,39 @@ static int saa7164_thread_function(void *data)
1184 return 0; 1191 return 0;
1185} 1192}
1186 1193
1194static bool saa7164_enable_msi(struct pci_dev *pci_dev, struct saa7164_dev *dev)
1195{
1196 int err;
1197
1198 if (!enable_msi) {
1199 printk(KERN_WARNING "%s() MSI disabled by module parameter 'enable_msi'"
1200 , __func__);
1201 return false;
1202 }
1203
1204 err = pci_enable_msi(pci_dev);
1205
1206 if (err) {
1207 printk(KERN_ERR "%s() Failed to enable MSI interrupt."
1208 " Falling back to a shared IRQ\n", __func__);
1209 return false;
1210 }
1211
1212 /* no error - so request an msi interrupt */
1213 err = request_irq(pci_dev->irq, saa7164_irq, 0,
1214 dev->name, dev);
1215
1216 if (err) {
1217 /* fall back to legacy interrupt */
1218 printk(KERN_ERR "%s() Failed to get an MSI interrupt."
1219 " Falling back to a shared IRQ\n", __func__);
1220 pci_disable_msi(pci_dev);
1221 return false;
1222 }
1223
1224 return true;
1225}
1226
1187static int saa7164_initdev(struct pci_dev *pci_dev, 1227static int saa7164_initdev(struct pci_dev *pci_dev,
1188 const struct pci_device_id *pci_id) 1228 const struct pci_device_id *pci_id)
1189{ 1229{
@@ -1230,13 +1270,22 @@ static int saa7164_initdev(struct pci_dev *pci_dev,
1230 goto fail_irq; 1270 goto fail_irq;
1231 } 1271 }
1232 1272
1233 err = request_irq(pci_dev->irq, saa7164_irq, 1273 /* irq bit */
1234 IRQF_SHARED, dev->name, dev); 1274 if (saa7164_enable_msi(pci_dev, dev)) {
1235 if (err < 0) { 1275 dev->msi = true;
1236 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name, 1276 } else {
1237 pci_dev->irq); 1277 /* if we have an error (i.e. we don't have an interrupt)
1238 err = -EIO; 1278 or msi is not enabled - fallback to shared interrupt */
1239 goto fail_irq; 1279
1280 err = request_irq(pci_dev->irq, saa7164_irq,
1281 IRQF_SHARED, dev->name, dev);
1282
1283 if (err < 0) {
1284 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
1285 pci_dev->irq);
1286 err = -EIO;
1287 goto fail_irq;
1288 }
1240 } 1289 }
1241 1290
1242 pci_set_drvdata(pci_dev, dev); 1291 pci_set_drvdata(pci_dev, dev);
@@ -1439,6 +1488,11 @@ static void saa7164_finidev(struct pci_dev *pci_dev)
1439 /* unregister stuff */ 1488 /* unregister stuff */
1440 free_irq(pci_dev->irq, dev); 1489 free_irq(pci_dev->irq, dev);
1441 1490
1491 if (dev->msi) {
1492 pci_disable_msi(pci_dev);
1493 dev->msi = false;
1494 }
1495
1442 pci_disable_device(pci_dev); 1496 pci_disable_device(pci_dev);
1443 1497
1444 mutex_lock(&devlist); 1498 mutex_lock(&devlist);
diff --git a/drivers/media/pci/saa7164/saa7164-dvb.c b/drivers/media/pci/saa7164/saa7164-dvb.c
index 16ae71592e8c..e9a783b71b45 100644
--- a/drivers/media/pci/saa7164/saa7164-dvb.c
+++ b/drivers/media/pci/saa7164/saa7164-dvb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,9 @@
24#include "tda10048.h" 24#include "tda10048.h"
25#include "tda18271.h" 25#include "tda18271.h"
26#include "s5h1411.h" 26#include "s5h1411.h"
27#include "si2157.h"
28#include "si2168.h"
29#include "lgdt3306a.h"
27 30
28#define DRIVER_NAME "saa7164" 31#define DRIVER_NAME "saa7164"
29 32
@@ -82,6 +85,65 @@ static struct s5h1411_config hauppauge_s5h1411_config = {
82 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 85 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
83}; 86};
84 87
88static struct lgdt3306a_config hauppauge_hvr2255a_config = {
89 .i2c_addr = 0xb2 >> 1,
90 .qam_if_khz = 4000,
91 .vsb_if_khz = 3250,
92 .deny_i2c_rptr = 1, /* Disabled */
93 .spectral_inversion = 0, /* Disabled */
94 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
95 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
96 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
97 .xtalMHz = 25, /* 24 or 25 */
98};
99
100static struct lgdt3306a_config hauppauge_hvr2255b_config = {
101 .i2c_addr = 0x1c >> 1,
102 .qam_if_khz = 4000,
103 .vsb_if_khz = 3250,
104 .deny_i2c_rptr = 1, /* Disabled */
105 .spectral_inversion = 0, /* Disabled */
106 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
107 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
108 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
109 .xtalMHz = 25, /* 24 or 25 */
110};
111
112static struct si2157_config hauppauge_hvr2255_tuner_config = {
113 .inversion = 1,
114 .if_port = 1,
115};
116
117static int si2157_attach(struct saa7164_port *port, struct i2c_adapter *adapter,
118 struct dvb_frontend *fe, u8 addr8bit, struct si2157_config *cfg)
119{
120 struct i2c_board_info bi;
121 struct i2c_client *tuner;
122
123 cfg->fe = fe;
124
125 memset(&bi, 0, sizeof(bi));
126
127 strlcpy(bi.type, "si2157", I2C_NAME_SIZE);
128 bi.platform_data = cfg;
129 bi.addr = addr8bit >> 1;
130
131 request_module(bi.type);
132
133 tuner = i2c_new_device(adapter, &bi);
134 if (tuner == NULL || tuner->dev.driver == NULL)
135 return -ENODEV;
136
137 if (!try_module_get(tuner->dev.driver->owner)) {
138 i2c_unregister_device(tuner);
139 return -ENODEV;
140 }
141
142 port->i2c_client_tuner = tuner;
143
144 return 0;
145}
146
85static int saa7164_dvb_stop_port(struct saa7164_port *port) 147static int saa7164_dvb_stop_port(struct saa7164_port *port)
86{ 148{
87 struct saa7164_dev *dev = port->dev; 149 struct saa7164_dev *dev = port->dev;
@@ -242,14 +304,16 @@ static int saa7164_dvb_start_feed(struct dvb_demux_feed *feed)
242 if (!demux->dmx.frontend) 304 if (!demux->dmx.frontend)
243 return -EINVAL; 305 return -EINVAL;
244 306
245 mutex_lock(&dvb->lock); 307 if (dvb) {
246 if (dvb->feeding++ == 0) { 308 mutex_lock(&dvb->lock);
247 /* Start transport */ 309 if (dvb->feeding++ == 0) {
248 ret = saa7164_dvb_start_port(port); 310 /* Start transport */
311 ret = saa7164_dvb_start_port(port);
312 }
313 mutex_unlock(&dvb->lock);
314 dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n",
315 __func__, port->nr, dvb->feeding);
249 } 316 }
250 mutex_unlock(&dvb->lock);
251 dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n",
252 __func__, port->nr, dvb->feeding);
253 317
254 return ret; 318 return ret;
255} 319}
@@ -264,14 +328,16 @@ static int saa7164_dvb_stop_feed(struct dvb_demux_feed *feed)
264 328
265 dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); 329 dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr);
266 330
267 mutex_lock(&dvb->lock); 331 if (dvb) {
268 if (--dvb->feeding == 0) { 332 mutex_lock(&dvb->lock);
269 /* Stop transport */ 333 if (--dvb->feeding == 0) {
270 ret = saa7164_dvb_stop_streaming(port); 334 /* Stop transport */
335 ret = saa7164_dvb_stop_streaming(port);
336 }
337 mutex_unlock(&dvb->lock);
338 dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n",
339 __func__, port->nr, dvb->feeding);
271 } 340 }
272 mutex_unlock(&dvb->lock);
273 dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n",
274 __func__, port->nr, dvb->feeding);
275 341
276 return ret; 342 return ret;
277} 343}
@@ -425,6 +491,7 @@ int saa7164_dvb_unregister(struct saa7164_port *port)
425 struct saa7164_dev *dev = port->dev; 491 struct saa7164_dev *dev = port->dev;
426 struct saa7164_buffer *b; 492 struct saa7164_buffer *b;
427 struct list_head *c, *n; 493 struct list_head *c, *n;
494 struct i2c_client *client;
428 495
429 dprintk(DBGLVL_DVB, "%s()\n", __func__); 496 dprintk(DBGLVL_DVB, "%s()\n", __func__);
430 497
@@ -443,6 +510,20 @@ int saa7164_dvb_unregister(struct saa7164_port *port)
443 if (dvb->frontend == NULL) 510 if (dvb->frontend == NULL)
444 return 0; 511 return 0;
445 512
513 /* remove I2C client for tuner */
514 client = port->i2c_client_tuner;
515 if (client) {
516 module_put(client->dev.driver->owner);
517 i2c_unregister_device(client);
518 }
519
520 /* remove I2C client for demodulator */
521 client = port->i2c_client_demod;
522 if (client) {
523 module_put(client->dev.driver->owner);
524 i2c_unregister_device(client);
525 }
526
446 dvb_net_release(&dvb->net); 527 dvb_net_release(&dvb->net);
447 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); 528 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
448 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); 529 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
@@ -462,6 +543,12 @@ int saa7164_dvb_register(struct saa7164_port *port)
462 struct saa7164_dev *dev = port->dev; 543 struct saa7164_dev *dev = port->dev;
463 struct saa7164_dvb *dvb = &port->dvb; 544 struct saa7164_dvb *dvb = &port->dvb;
464 struct saa7164_i2c *i2c_bus = NULL; 545 struct saa7164_i2c *i2c_bus = NULL;
546 struct si2168_config si2168_config;
547 struct si2157_config si2157_config;
548 struct i2c_adapter *adapter;
549 struct i2c_board_info info;
550 struct i2c_client *client_demod;
551 struct i2c_client *client_tuner;
465 int ret; 552 int ret;
466 553
467 dprintk(DBGLVL_DVB, "%s()\n", __func__); 554 dprintk(DBGLVL_DVB, "%s()\n", __func__);
@@ -528,6 +615,126 @@ int saa7164_dvb_register(struct saa7164_port *port)
528 } 615 }
529 616
530 break; 617 break;
618 case SAA7164_BOARD_HAUPPAUGE_HVR2255proto:
619 case SAA7164_BOARD_HAUPPAUGE_HVR2255:
620 i2c_bus = &dev->i2c_bus[2];
621
622 if (port->nr == 0) {
623 port->dvb.frontend = dvb_attach(lgdt3306a_attach,
624 &hauppauge_hvr2255a_config, &i2c_bus->i2c_adap);
625 } else {
626 port->dvb.frontend = dvb_attach(lgdt3306a_attach,
627 &hauppauge_hvr2255b_config, &i2c_bus->i2c_adap);
628 }
629
630 if (port->dvb.frontend != NULL) {
631
632 if (port->nr == 0) {
633 si2157_attach(port, &dev->i2c_bus[0].i2c_adap,
634 port->dvb.frontend, 0xc0,
635 &hauppauge_hvr2255_tuner_config);
636 } else {
637 si2157_attach(port, &dev->i2c_bus[1].i2c_adap,
638 port->dvb.frontend, 0xc0,
639 &hauppauge_hvr2255_tuner_config);
640 }
641 }
642 break;
643 case SAA7164_BOARD_HAUPPAUGE_HVR2205:
644
645 if (port->nr == 0) {
646 /* attach frontend */
647 memset(&si2168_config, 0, sizeof(si2168_config));
648 si2168_config.i2c_adapter = &adapter;
649 si2168_config.fe = &port->dvb.frontend;
650 si2168_config.ts_mode = SI2168_TS_SERIAL;
651 memset(&info, 0, sizeof(struct i2c_board_info));
652 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
653 info.addr = 0xc8 >> 1;
654 info.platform_data = &si2168_config;
655 request_module(info.type);
656 client_demod = i2c_new_device(&dev->i2c_bus[2].i2c_adap,
657 &info);
658 if (!client_demod || !client_demod->dev.driver)
659 goto frontend_detach;
660
661 if (!try_module_get(client_demod->dev.driver->owner)) {
662 i2c_unregister_device(client_demod);
663 goto frontend_detach;
664 }
665 port->i2c_client_demod = client_demod;
666
667 /* attach tuner */
668 memset(&si2157_config, 0, sizeof(si2157_config));
669 si2157_config.if_port = 1;
670 si2157_config.fe = port->dvb.frontend;
671 memset(&info, 0, sizeof(struct i2c_board_info));
672 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
673 info.addr = 0xc0 >> 1;
674 info.platform_data = &si2157_config;
675 request_module(info.type);
676 client_tuner = i2c_new_device(&dev->i2c_bus[0].i2c_adap,
677 &info);
678 if (!client_tuner || !client_tuner->dev.driver) {
679 module_put(client_demod->dev.driver->owner);
680 i2c_unregister_device(client_demod);
681 goto frontend_detach;
682 }
683 if (!try_module_get(client_tuner->dev.driver->owner)) {
684 i2c_unregister_device(client_tuner);
685 module_put(client_demod->dev.driver->owner);
686 i2c_unregister_device(client_demod);
687 goto frontend_detach;
688 }
689 port->i2c_client_tuner = client_tuner;
690 } else {
691 /* attach frontend */
692 memset(&si2168_config, 0, sizeof(si2168_config));
693 si2168_config.i2c_adapter = &adapter;
694 si2168_config.fe = &port->dvb.frontend;
695 si2168_config.ts_mode = SI2168_TS_SERIAL;
696 memset(&info, 0, sizeof(struct i2c_board_info));
697 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
698 info.addr = 0xcc >> 1;
699 info.platform_data = &si2168_config;
700 request_module(info.type);
701 client_demod = i2c_new_device(&dev->i2c_bus[2].i2c_adap,
702 &info);
703 if (!client_demod || !client_demod->dev.driver)
704 goto frontend_detach;
705
706 if (!try_module_get(client_demod->dev.driver->owner)) {
707 i2c_unregister_device(client_demod);
708 goto frontend_detach;
709 }
710 port->i2c_client_demod = client_demod;
711
712 /* attach tuner */
713 memset(&si2157_config, 0, sizeof(si2157_config));
714 si2157_config.fe = port->dvb.frontend;
715 si2157_config.if_port = 1;
716 memset(&info, 0, sizeof(struct i2c_board_info));
717 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
718 info.addr = 0xc0 >> 1;
719 info.platform_data = &si2157_config;
720 request_module(info.type);
721 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap,
722 &info);
723 if (!client_tuner || !client_tuner->dev.driver) {
724 module_put(client_demod->dev.driver->owner);
725 i2c_unregister_device(client_demod);
726 goto frontend_detach;
727 }
728 if (!try_module_get(client_tuner->dev.driver->owner)) {
729 i2c_unregister_device(client_tuner);
730 module_put(client_demod->dev.driver->owner);
731 i2c_unregister_device(client_demod);
732 goto frontend_detach;
733 }
734 port->i2c_client_tuner = client_tuner;
735 }
736
737 break;
531 default: 738 default:
532 printk(KERN_ERR "%s: The frontend isn't supported\n", 739 printk(KERN_ERR "%s: The frontend isn't supported\n",
533 dev->name); 740 dev->name);
@@ -548,5 +755,9 @@ int saa7164_dvb_register(struct saa7164_port *port)
548 } 755 }
549 756
550 return 0; 757 return 0;
758
759frontend_detach:
760 printk(KERN_ERR "%s() Frontend/I2C initialization failed\n", __func__);
761 return -1;
551} 762}
552 763
diff --git a/drivers/media/pci/saa7164/saa7164-encoder.c b/drivers/media/pci/saa7164/saa7164-encoder.c
index 9266965412c3..4434e0f28c26 100644
--- a/drivers/media/pci/saa7164/saa7164-encoder.c
+++ b/drivers/media/pci/saa7164/saa7164-encoder.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -721,13 +721,14 @@ static int vidioc_querycap(struct file *file, void *priv,
721 sizeof(cap->card)); 721 sizeof(cap->card));
722 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); 722 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
723 723
724 cap->capabilities = 724 cap->device_caps =
725 V4L2_CAP_VIDEO_CAPTURE | 725 V4L2_CAP_VIDEO_CAPTURE |
726 V4L2_CAP_READWRITE | 726 V4L2_CAP_READWRITE |
727 0; 727 V4L2_CAP_TUNER;
728 728
729 cap->capabilities |= V4L2_CAP_TUNER; 729 cap->capabilities = cap->device_caps |
730 cap->version = 0; 730 V4L2_CAP_VBI_CAPTURE |
731 V4L2_CAP_DEVICE_CAPS;
731 732
732 return 0; 733 return 0;
733} 734}
diff --git a/drivers/media/pci/saa7164/saa7164-fw.c b/drivers/media/pci/saa7164/saa7164-fw.c
index add06ab5124d..269e0782c7b6 100644
--- a/drivers/media/pci/saa7164/saa7164-fw.c
+++ b/drivers/media/pci/saa7164/saa7164-fw.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/pci/saa7164/saa7164-i2c.c b/drivers/media/pci/saa7164/saa7164-i2c.c
index 4f7e3b42263f..0342d84913b8 100644
--- a/drivers/media/pci/saa7164/saa7164-i2c.c
+++ b/drivers/media/pci/saa7164/saa7164-i2c.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -39,9 +39,10 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
39 dprintk(DBGLVL_I2C, "%s(num = %d) addr = 0x%02x len = 0x%x\n", 39 dprintk(DBGLVL_I2C, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
40 __func__, num, msgs[i].addr, msgs[i].len); 40 __func__, num, msgs[i].addr, msgs[i].len);
41 if (msgs[i].flags & I2C_M_RD) { 41 if (msgs[i].flags & I2C_M_RD) {
42 /* Unsupported - Yet*/ 42 retval = saa7164_api_i2c_read(bus,
43 printk(KERN_ERR "%s() Unsupported - Yet\n", __func__); 43 msgs[i].addr,
44 continue; 44 0 /* reglen */,
45 NULL /* reg */, msgs[i].len, msgs[i].buf);
45 } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && 46 } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
46 msgs[i].addr == msgs[i + 1].addr) { 47 msgs[i].addr == msgs[i + 1].addr) {
47 /* write then read from same address */ 48 /* write then read from same address */
diff --git a/drivers/media/pci/saa7164/saa7164-reg.h b/drivers/media/pci/saa7164/saa7164-reg.h
index 2bbf81583d33..37521a2ee504 100644
--- a/drivers/media/pci/saa7164/saa7164-reg.h
+++ b/drivers/media/pci/saa7164/saa7164-reg.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/pci/saa7164/saa7164-types.h b/drivers/media/pci/saa7164/saa7164-types.h
index f48ba978f835..1efba6c64ebf 100644
--- a/drivers/media/pci/saa7164/saa7164-types.h
+++ b/drivers/media/pci/saa7164/saa7164-types.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/pci/saa7164/saa7164-vbi.c b/drivers/media/pci/saa7164/saa7164-vbi.c
index 6e025fea2542..859fd03d82f9 100644
--- a/drivers/media/pci/saa7164/saa7164-vbi.c
+++ b/drivers/media/pci/saa7164/saa7164-vbi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -660,13 +660,14 @@ static int vidioc_querycap(struct file *file, void *priv,
660 sizeof(cap->card)); 660 sizeof(cap->card));
661 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); 661 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
662 662
663 cap->capabilities = 663 cap->device_caps =
664 V4L2_CAP_VBI_CAPTURE | 664 V4L2_CAP_VBI_CAPTURE |
665 V4L2_CAP_READWRITE | 665 V4L2_CAP_READWRITE |
666 0; 666 V4L2_CAP_TUNER;
667 667
668 cap->capabilities |= V4L2_CAP_TUNER; 668 cap->capabilities = cap->device_caps |
669 cap->version = 0; 669 V4L2_CAP_VIDEO_CAPTURE |
670 V4L2_CAP_DEVICE_CAPS;
670 671
671 return 0; 672 return 0;
672} 673}
diff --git a/drivers/media/pci/saa7164/saa7164.h b/drivers/media/pci/saa7164/saa7164.h
index cd1a07ce27cb..18906e0c80e1 100644
--- a/drivers/media/pci/saa7164/saa7164.h
+++ b/drivers/media/pci/saa7164/saa7164.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the NXP SAA7164 PCIe bridge 2 * Driver for the NXP SAA7164 PCIe bridge
3 * 3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> 4 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License as published by
@@ -83,6 +83,9 @@
83#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8 83#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3 8
84#define SAA7164_BOARD_HAUPPAUGE_HVR2200_4 9 84#define SAA7164_BOARD_HAUPPAUGE_HVR2200_4 9
85#define SAA7164_BOARD_HAUPPAUGE_HVR2200_5 10 85#define SAA7164_BOARD_HAUPPAUGE_HVR2200_5 10
86#define SAA7164_BOARD_HAUPPAUGE_HVR2255proto 11
87#define SAA7164_BOARD_HAUPPAUGE_HVR2255 12
88#define SAA7164_BOARD_HAUPPAUGE_HVR2205 13
86 89
87#define SAA7164_MAX_UNITS 8 90#define SAA7164_MAX_UNITS 8
88#define SAA7164_TS_NUMBER_OF_LINES 312 91#define SAA7164_TS_NUMBER_OF_LINES 312
@@ -371,6 +374,8 @@ struct saa7164_port {
371 374
372 /* --- DVB Transport Specific --- */ 375 /* --- DVB Transport Specific --- */
373 struct saa7164_dvb dvb; 376 struct saa7164_dvb dvb;
377 struct i2c_client *i2c_client_demod;
378 struct i2c_client *i2c_client_tuner;
374 379
375 /* --- Encoder/V4L related attributes --- */ 380 /* --- Encoder/V4L related attributes --- */
376 /* Encoder */ 381 /* Encoder */
@@ -459,6 +464,7 @@ struct saa7164_dev {
459 /* Interrupt status and ack registers */ 464 /* Interrupt status and ack registers */
460 u32 int_status; 465 u32 int_status;
461 u32 int_ack; 466 u32 int_ack;
467 bool msi;
462 468
463 struct cmd cmds[SAA_CMD_MAX_MSG_UNITS]; 469 struct cmd cmds[SAA_CMD_MAX_MSG_UNITS];
464 struct mutex lock; 470 struct mutex lock;
diff --git a/drivers/media/pci/smipcie/smipcie.c b/drivers/media/pci/smipcie/smipcie.c
index 411592524c63..143fd7899ecd 100644
--- a/drivers/media/pci/smipcie/smipcie.c
+++ b/drivers/media/pci/smipcie/smipcie.c
@@ -657,6 +657,7 @@ static int smi_dvbsky_sit2_fe_attach(struct smi_port *port)
657 /* attach tuner */ 657 /* attach tuner */
658 memset(&si2157_config, 0, sizeof(si2157_config)); 658 memset(&si2157_config, 0, sizeof(si2157_config));
659 si2157_config.fe = port->fe; 659 si2157_config.fe = port->fe;
660 si2157_config.if_port = 1;
660 661
661 memset(&client_info, 0, sizeof(struct i2c_board_info)); 662 memset(&client_info, 0, sizeof(struct i2c_board_info));
662 strlcpy(client_info.type, "si2157", I2C_NAME_SIZE); 663 strlcpy(client_info.type, "si2157", I2C_NAME_SIZE);
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index d384a6b0b09f..59b3a36a3639 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -813,7 +813,7 @@ static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
813 /* Disable acquisition */ 813 /* Disable acquisition */
814 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA); 814 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
815 /* Remove the active buffer from the list */ 815 /* Remove the active buffer from the list */
816 do_gettimeofday(&vip->active->vb.v4l2_buf.timestamp); 816 v4l2_get_timestamp(&vip->active->vb.v4l2_buf.timestamp);
817 vip->active->vb.v4l2_buf.sequence = vip->sequence++; 817 vip->active->vb.v4l2_buf.sequence = vip->sequence++;
818 vb2_buffer_done(&vip->active->vb, VB2_BUF_STATE_DONE); 818 vb2_buffer_done(&vip->active->vb, VB2_BUF_STATE_DONE);
819 } 819 }
@@ -864,6 +864,7 @@ static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
864 vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer); 864 vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer);
865 vip->vb_vidq.ops = &vip_video_qops; 865 vip->vb_vidq.ops = &vip_video_qops;
866 vip->vb_vidq.mem_ops = &vb2_dma_contig_memops; 866 vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
867 vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
867 err = vb2_queue_init(&vip->vb_vidq); 868 err = vb2_queue_init(&vip->vb_vidq);
868 if (err) 869 if (err)
869 return err; 870 return err;
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index 45199a12b9d9..3f24fce74fc1 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -1172,7 +1172,7 @@ static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1172 ******************************************************************************/ 1172 ******************************************************************************/
1173 1173
1174 1174
1175static int av7110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 1175static int av7110_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
1176{ 1176{
1177 struct av7110* av7110 = fe->dvb->priv; 1177 struct av7110* av7110 = fe->dvb->priv;
1178 1178
@@ -1197,7 +1197,7 @@ static int av7110_diseqc_send_master_cmd(struct dvb_frontend* fe,
1197} 1197}
1198 1198
1199static int av7110_diseqc_send_burst(struct dvb_frontend* fe, 1199static int av7110_diseqc_send_burst(struct dvb_frontend* fe,
1200 fe_sec_mini_cmd_t minicmd) 1200 enum fe_sec_mini_cmd minicmd)
1201{ 1201{
1202 struct av7110* av7110 = fe->dvb->priv; 1202 struct av7110* av7110 = fe->dvb->priv;
1203 1203
@@ -1946,7 +1946,7 @@ static struct l64781_config grundig_29504_401_config = {
1946 1946
1947 1947
1948 1948
1949static int av7110_fe_lock_fix(struct av7110* av7110, fe_status_t status) 1949static int av7110_fe_lock_fix(struct av7110 *av7110, enum fe_status status)
1950{ 1950{
1951 int ret = 0; 1951 int ret = 0;
1952 int synced = (status & FE_HAS_LOCK) ? 1 : 0; 1952 int synced = (status & FE_HAS_LOCK) ? 1 : 0;
@@ -2008,7 +2008,8 @@ static int av7110_fe_init(struct dvb_frontend* fe)
2008 return ret; 2008 return ret;
2009} 2009}
2010 2010
2011static int av7110_fe_read_status(struct dvb_frontend* fe, fe_status_t* status) 2011static int av7110_fe_read_status(struct dvb_frontend *fe,
2012 enum fe_status *status)
2012{ 2013{
2013 struct av7110* av7110 = fe->dvb->priv; 2014 struct av7110* av7110 = fe->dvb->priv;
2014 2015
@@ -2043,7 +2044,8 @@ static int av7110_fe_diseqc_send_master_cmd(struct dvb_frontend* fe,
2043 return ret; 2044 return ret;
2044} 2045}
2045 2046
2046static int av7110_fe_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 2047static int av7110_fe_diseqc_send_burst(struct dvb_frontend *fe,
2048 enum fe_sec_mini_cmd minicmd)
2047{ 2049{
2048 struct av7110* av7110 = fe->dvb->priv; 2050 struct av7110* av7110 = fe->dvb->priv;
2049 2051
@@ -2055,7 +2057,8 @@ static int av7110_fe_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_
2055 return ret; 2057 return ret;
2056} 2058}
2057 2059
2058static int av7110_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 2060static int av7110_fe_set_tone(struct dvb_frontend *fe,
2061 enum fe_sec_tone_mode tone)
2059{ 2062{
2060 struct av7110* av7110 = fe->dvb->priv; 2063 struct av7110* av7110 = fe->dvb->priv;
2061 2064
@@ -2067,7 +2070,8 @@ static int av7110_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
2067 return ret; 2070 return ret;
2068} 2071}
2069 2072
2070static int av7110_fe_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 2073static int av7110_fe_set_voltage(struct dvb_frontend *fe,
2074 enum fe_sec_voltage voltage)
2071{ 2075{
2072 struct av7110* av7110 = fe->dvb->priv; 2076 struct av7110* av7110 = fe->dvb->priv;
2073 2077
diff --git a/drivers/media/pci/ttpci/av7110.h b/drivers/media/pci/ttpci/av7110.h
index 835635b0c712..3a55927edb95 100644
--- a/drivers/media/pci/ttpci/av7110.h
+++ b/drivers/media/pci/ttpci/av7110.h
@@ -269,25 +269,30 @@ struct av7110 {
269 unsigned long size_root; 269 unsigned long size_root;
270 270
271 struct dvb_frontend* fe; 271 struct dvb_frontend* fe;
272 fe_status_t fe_status; 272 enum fe_status fe_status;
273 273
274 struct mutex ioctl_mutex; 274 struct mutex ioctl_mutex;
275 275
276 /* crash recovery */ 276 /* crash recovery */
277 void (*recover)(struct av7110* av7110); 277 void (*recover)(struct av7110* av7110);
278 fe_sec_voltage_t saved_voltage; 278 enum fe_sec_voltage saved_voltage;
279 fe_sec_tone_mode_t saved_tone; 279 enum fe_sec_tone_mode saved_tone;
280 struct dvb_diseqc_master_cmd saved_master_cmd; 280 struct dvb_diseqc_master_cmd saved_master_cmd;
281 fe_sec_mini_cmd_t saved_minicmd; 281 enum fe_sec_mini_cmd saved_minicmd;
282 282
283 int (*fe_init)(struct dvb_frontend* fe); 283 int (*fe_init)(struct dvb_frontend* fe);
284 int (*fe_read_status)(struct dvb_frontend* fe, fe_status_t* status); 284 int (*fe_read_status)(struct dvb_frontend *fe, enum fe_status *status);
285 int (*fe_diseqc_reset_overload)(struct dvb_frontend* fe); 285 int (*fe_diseqc_reset_overload)(struct dvb_frontend *fe);
286 int (*fe_diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd); 286 int (*fe_diseqc_send_master_cmd)(struct dvb_frontend *fe,
287 int (*fe_diseqc_send_burst)(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd); 287 struct dvb_diseqc_master_cmd *cmd);
288 int (*fe_set_tone)(struct dvb_frontend* fe, fe_sec_tone_mode_t tone); 288 int (*fe_diseqc_send_burst)(struct dvb_frontend *fe,
289 int (*fe_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage); 289 enum fe_sec_mini_cmd minicmd);
290 int (*fe_dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd); 290 int (*fe_set_tone)(struct dvb_frontend *fe,
291 enum fe_sec_tone_mode tone);
292 int (*fe_set_voltage)(struct dvb_frontend *fe,
293 enum fe_sec_voltage voltage);
294 int (*fe_dishnetwork_send_legacy_command)(struct dvb_frontend *fe,
295 unsigned long cmd);
291 int (*fe_set_frontend)(struct dvb_frontend *fe); 296 int (*fe_set_frontend)(struct dvb_frontend *fe);
292}; 297};
293 298
diff --git a/drivers/media/pci/ttpci/budget-core.c b/drivers/media/pci/ttpci/budget-core.c
index 23e05499b509..e9674b40007c 100644
--- a/drivers/media/pci/ttpci/budget-core.c
+++ b/drivers/media/pci/ttpci/budget-core.c
@@ -161,7 +161,8 @@ static int start_ts_capture(struct budget *budget)
161 return 0; 161 return 0;
162} 162}
163 163
164static int budget_read_fe_status(struct dvb_frontend *fe, fe_status_t *status) 164static int budget_read_fe_status(struct dvb_frontend *fe,
165 enum fe_status *status)
165{ 166{
166 struct budget *budget = (struct budget *) fe->dvb->priv; 167 struct budget *budget = (struct budget *) fe->dvb->priv;
167 int synced; 168 int synced;
diff --git a/drivers/media/pci/ttpci/budget-patch.c b/drivers/media/pci/ttpci/budget-patch.c
index a4d8867e1d7b..b5b65962ce8f 100644
--- a/drivers/media/pci/ttpci/budget-patch.c
+++ b/drivers/media/pci/ttpci/budget-patch.c
@@ -128,9 +128,9 @@ static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long
128 return 0; 128 return 0;
129} 129}
130 130
131/* shamelessly copy/pasted from budget.c 131/* shamelessly copy/pasted from budget.c */
132*/ 132static int budget_set_tone(struct dvb_frontend *fe,
133static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 133 enum fe_sec_tone_mode tone)
134{ 134{
135 struct budget* budget = (struct budget*) fe->dvb->priv; 135 struct budget* budget = (struct budget*) fe->dvb->priv;
136 136
@@ -159,7 +159,8 @@ static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_dis
159 return 0; 159 return 0;
160} 160}
161 161
162static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 162static int budget_diseqc_send_burst(struct dvb_frontend *fe,
163 enum fe_sec_mini_cmd minicmd)
163{ 164{
164 struct budget* budget = (struct budget*) fe->dvb->priv; 165 struct budget* budget = (struct budget*) fe->dvb->priv;
165 166
@@ -223,7 +224,8 @@ static int av7110_send_diseqc_msg(struct budget_patch *budget, int len, u8 *msg,
223 return 0; 224 return 0;
224} 225}
225 226
226static int budget_patch_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 227static int budget_patch_set_tone(struct dvb_frontend *fe,
228 enum fe_sec_tone_mode tone)
227{ 229{
228 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv; 230 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
229 231
@@ -252,7 +254,8 @@ static int budget_patch_diseqc_send_master_cmd(struct dvb_frontend* fe, struct d
252 return 0; 254 return 0;
253} 255}
254 256
255static int budget_patch_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 257static int budget_patch_diseqc_send_burst(struct dvb_frontend *fe,
258 enum fe_sec_mini_cmd minicmd)
256{ 259{
257 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv; 260 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
258 261
diff --git a/drivers/media/pci/ttpci/budget.c b/drivers/media/pci/ttpci/budget.c
index 6ccc48833fd8..99972beca262 100644
--- a/drivers/media/pci/ttpci/budget.c
+++ b/drivers/media/pci/ttpci/budget.c
@@ -132,7 +132,8 @@ static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long
132 * Voltage must be set here. 132 * Voltage must be set here.
133 * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL 133 * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
134 */ 134 */
135static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage) 135static int SetVoltage_Activy(struct budget *budget,
136 enum fe_sec_voltage voltage)
136{ 137{
137 struct saa7146_dev *dev=budget->dev; 138 struct saa7146_dev *dev=budget->dev;
138 139
@@ -157,14 +158,16 @@ static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage)
157 return 0; 158 return 0;
158} 159}
159 160
160static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 161static int siemens_budget_set_voltage(struct dvb_frontend *fe,
162 enum fe_sec_voltage voltage)
161{ 163{
162 struct budget* budget = (struct budget*) fe->dvb->priv; 164 struct budget* budget = (struct budget*) fe->dvb->priv;
163 165
164 return SetVoltage_Activy (budget, voltage); 166 return SetVoltage_Activy (budget, voltage);
165} 167}
166 168
167static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 169static int budget_set_tone(struct dvb_frontend *fe,
170 enum fe_sec_tone_mode tone)
168{ 171{
169 struct budget* budget = (struct budget*) fe->dvb->priv; 172 struct budget* budget = (struct budget*) fe->dvb->priv;
170 173
@@ -193,7 +196,8 @@ static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_dis
193 return 0; 196 return 0;
194} 197}
195 198
196static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 199static int budget_diseqc_send_burst(struct dvb_frontend *fe,
200 enum fe_sec_mini_cmd minicmd)
197{ 201{
198 struct budget* budget = (struct budget*) fe->dvb->priv; 202 struct budget* budget = (struct budget*) fe->dvb->priv;
199 203
diff --git a/drivers/media/pci/ttpci/budget.h b/drivers/media/pci/ttpci/budget.h
index 3d8a806c20bb..1ccbe1a49a4b 100644
--- a/drivers/media/pci/ttpci/budget.h
+++ b/drivers/media/pci/ttpci/budget.h
@@ -72,7 +72,7 @@ struct budget {
72 72
73 struct dvb_adapter dvb_adapter; 73 struct dvb_adapter dvb_adapter;
74 struct dvb_frontend *dvb_frontend; 74 struct dvb_frontend *dvb_frontend;
75 int (*read_fe_status)(struct dvb_frontend *fe, fe_status_t *status); 75 int (*read_fe_status)(struct dvb_frontend *fe, enum fe_status *status);
76 int fe_synced; 76 int fe_synced;
77 77
78 void *priv; 78 void *priv;
diff --git a/drivers/media/pci/zoran/zoran_device.c b/drivers/media/pci/zoran/zoran_device.c
index b6801e035ea4..40119b3c52c1 100644
--- a/drivers/media/pci/zoran/zoran_device.c
+++ b/drivers/media/pci/zoran/zoran_device.c
@@ -1584,14 +1584,11 @@ zoran_init_hardware (struct zoran *zr)
1584 jpeg_codec_sleep(zr, 1); 1584 jpeg_codec_sleep(zr, 1);
1585 jpeg_codec_sleep(zr, 0); 1585 jpeg_codec_sleep(zr, 0);
1586 1586
1587 /* set individual interrupt enables (without GIRQ1) 1587 /*
1588 * but don't global enable until zoran_open() */ 1588 * set individual interrupt enables (without GIRQ1)
1589 1589 * but don't global enable until zoran_open()
1590 //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW 1590 */
1591 // It looks like using only JPEGRepIRQEn is not always reliable, 1591 zr36057_init_vfe(zr);
1592 // may be when JPEG codec crashes it won't generate IRQ? So,
1593 /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
1594 zr36057_init_vfe(zr);
1595 1592
1596 zr36057_enable_jpg(zr, BUZ_MODE_IDLE); 1593 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
1597 1594
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 421f53188c6c..a4e7d21c9e4c 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -212,6 +212,16 @@ config VIDEO_SAMSUNG_EXYNOS_GSC
212 help 212 help
213 This is a v4l2 driver for Samsung EXYNOS5 SoC G-Scaler. 213 This is a v4l2 driver for Samsung EXYNOS5 SoC G-Scaler.
214 214
215config VIDEO_STI_BDISP
216 tristate "STMicroelectronics BDISP 2D blitter driver"
217 depends on VIDEO_DEV && VIDEO_V4L2
218 depends on ARCH_STI || COMPILE_TEST
219 depends on HAVE_DMA_ATTRS
220 select VIDEOBUF2_DMA_CONTIG
221 select V4L2_MEM2MEM_DEV
222 help
223 This v4l2 mem2mem driver is a 2D blitter for STMicroelectronics SoC.
224
215config VIDEO_SH_VEU 225config VIDEO_SH_VEU
216 tristate "SuperH VEU mem2mem video processing driver" 226 tristate "SuperH VEU mem2mem video processing driver"
217 depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA 227 depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 8f855616c237..114f9aba1c00 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -34,6 +34,8 @@ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
34obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D) += s5p-g2d/ 34obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D) += s5p-g2d/
35obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS_GSC) += exynos-gsc/ 35obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS_GSC) += exynos-gsc/
36 36
37obj-$(CONFIG_VIDEO_STI_BDISP) += sti/bdisp/
38
37obj-$(CONFIG_BLACKFIN) += blackfin/ 39obj-$(CONFIG_BLACKFIN) += blackfin/
38 40
39obj-$(CONFIG_ARCH_DAVINCI) += davinci/ 41obj-$(CONFIG_ARCH_DAVINCI) += davinci/
diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index a30cc2f7e4f1..1fba339cddc1 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -288,7 +288,8 @@ cmp_v4l2_format(const struct v4l2_format *lhs, const struct v4l2_format *rhs)
288 lhs->fmt.pix.field == rhs->fmt.pix.field && 288 lhs->fmt.pix.field == rhs->fmt.pix.field &&
289 lhs->fmt.pix.colorspace == rhs->fmt.pix.colorspace && 289 lhs->fmt.pix.colorspace == rhs->fmt.pix.colorspace &&
290 lhs->fmt.pix.ycbcr_enc == rhs->fmt.pix.ycbcr_enc && 290 lhs->fmt.pix.ycbcr_enc == rhs->fmt.pix.ycbcr_enc &&
291 lhs->fmt.pix.quantization == rhs->fmt.pix.quantization; 291 lhs->fmt.pix.quantization == rhs->fmt.pix.quantization &&
292 lhs->fmt.pix.xfer_func == rhs->fmt.pix.xfer_func;
292} 293}
293 294
294static inline u32 vpfe_reg_read(struct vpfe_ccdc *ccdc, u32 offset) 295static inline u32 vpfe_reg_read(struct vpfe_ccdc *ccdc, u32 offset)
@@ -430,7 +431,7 @@ vpfe_ccdc_update_raw_params(struct vpfe_ccdc *ccdc,
430 struct vpfe_ccdc_config_params_raw *config_params = 431 struct vpfe_ccdc_config_params_raw *config_params =
431 &ccdc->ccdc_cfg.bayer.config_params; 432 &ccdc->ccdc_cfg.bayer.config_params;
432 433
433 config_params = raw_params; 434 *config_params = *raw_params;
434} 435}
435 436
436/* 437/*
@@ -510,7 +511,7 @@ static int vpfe_ccdc_set_params(struct vpfe_ccdc *ccdc, void __user *params)
510 511
511 if (!vpfe_ccdc_validate_param(ccdc, &raw_params)) { 512 if (!vpfe_ccdc_validate_param(ccdc, &raw_params)) {
512 vpfe_ccdc_update_raw_params(ccdc, &raw_params); 513 vpfe_ccdc_update_raw_params(ccdc, &raw_params);
513 return 0; 514 return 0;
514 } 515 }
515 516
516 return -EINVAL; 517 return -EINVAL;
@@ -1095,7 +1096,7 @@ static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe)
1095 * For a given standard, this functions sets up the default 1096 * For a given standard, this functions sets up the default
1096 * pix format & crop values in the vpfe device and ccdc. It first 1097 * pix format & crop values in the vpfe device and ccdc. It first
1097 * starts with defaults based values from the standard table. 1098 * starts with defaults based values from the standard table.
1098 * It then checks if sub device support g_mbus_fmt and then override the 1099 * It then checks if sub device supports get_fmt and then override the
1099 * values based on that.Sets crop values to match with scan resolution 1100 * values based on that.Sets crop values to match with scan resolution
1100 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the 1101 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
1101 * values in ccdc 1102 * values in ccdc
@@ -1432,8 +1433,8 @@ static int __vpfe_get_format(struct vpfe_device *vpfe,
1432 } else { 1433 } else {
1433 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev, 1434 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev,
1434 sdinfo->grp_id, 1435 sdinfo->grp_id,
1435 video, g_mbus_fmt, 1436 pad, get_fmt,
1436 &mbus_fmt); 1437 NULL, &fmt);
1437 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) 1438 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1438 return ret; 1439 return ret;
1439 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt); 1440 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt);
@@ -1455,7 +1456,6 @@ static int __vpfe_get_format(struct vpfe_device *vpfe,
1455static int __vpfe_set_format(struct vpfe_device *vpfe, 1456static int __vpfe_set_format(struct vpfe_device *vpfe,
1456 struct v4l2_format *format, unsigned int *bpp) 1457 struct v4l2_format *format, unsigned int *bpp)
1457{ 1458{
1458 struct v4l2_mbus_framefmt mbus_fmt;
1459 struct vpfe_subdev_info *sdinfo; 1459 struct vpfe_subdev_info *sdinfo;
1460 struct v4l2_subdev_format fmt; 1460 struct v4l2_subdev_format fmt;
1461 int ret; 1461 int ret;
@@ -1472,23 +1472,11 @@ static int __vpfe_set_format(struct vpfe_device *vpfe,
1472 pix_to_mbus(vpfe, &format->fmt.pix, &fmt.format); 1472 pix_to_mbus(vpfe, &format->fmt.pix, &fmt.format);
1473 1473
1474 ret = v4l2_subdev_call(sdinfo->sd, pad, set_fmt, NULL, &fmt); 1474 ret = v4l2_subdev_call(sdinfo->sd, pad, set_fmt, NULL, &fmt);
1475 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) 1475 if (ret)
1476 return ret; 1476 return ret;
1477 1477
1478 if (!ret) { 1478 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format);
1479 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format); 1479 mbus_to_pix(vpfe, &fmt.format, &format->fmt.pix, bpp);
1480 mbus_to_pix(vpfe, &fmt.format, &format->fmt.pix, bpp);
1481 } else {
1482 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev,
1483 sdinfo->grp_id,
1484 video, s_mbus_fmt,
1485 &mbus_fmt);
1486 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1487 return ret;
1488
1489 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt);
1490 mbus_to_pix(vpfe, &mbus_fmt, &format->fmt.pix, bpp);
1491 }
1492 1480
1493 format->type = vpfe->fmt.type; 1481 format->type = vpfe->fmt.type;
1494 1482
@@ -1675,12 +1663,9 @@ vpfe_get_subdev_input_index(struct vpfe_device *vpfe,
1675 int *subdev_input_index, 1663 int *subdev_input_index,
1676 int app_input_index) 1664 int app_input_index)
1677{ 1665{
1678 struct vpfe_config *cfg = vpfe->cfg;
1679 struct vpfe_subdev_info *sdinfo;
1680 int i, j = 0; 1666 int i, j = 0;
1681 1667
1682 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) { 1668 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
1683 sdinfo = &cfg->sub_devs[i];
1684 if (app_input_index < (j + 1)) { 1669 if (app_input_index < (j + 1)) {
1685 *subdev_index = i; 1670 *subdev_index = i;
1686 *subdev_input_index = app_input_index - j; 1671 *subdev_input_index = app_input_index - j;
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 6a437f86dcdc..b7e70fb05eb8 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -156,14 +156,18 @@ static struct bcap_buffer *to_bcap_vb(struct vb2_buffer *vb)
156 156
157static int bcap_init_sensor_formats(struct bcap_device *bcap_dev) 157static int bcap_init_sensor_formats(struct bcap_device *bcap_dev)
158{ 158{
159 u32 code; 159 struct v4l2_subdev_mbus_code_enum code = {
160 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
161 };
160 struct bcap_format *sf; 162 struct bcap_format *sf;
161 unsigned int num_formats = 0; 163 unsigned int num_formats = 0;
162 int i, j; 164 int i, j;
163 165
164 while (!v4l2_subdev_call(bcap_dev->sd, video, 166 while (!v4l2_subdev_call(bcap_dev->sd, pad,
165 enum_mbus_fmt, num_formats, &code)) 167 enum_mbus_code, NULL, &code)) {
166 num_formats++; 168 num_formats++;
169 code.index++;
170 }
167 if (!num_formats) 171 if (!num_formats)
168 return -ENXIO; 172 return -ENXIO;
169 173
@@ -172,10 +176,11 @@ static int bcap_init_sensor_formats(struct bcap_device *bcap_dev)
172 return -ENOMEM; 176 return -ENOMEM;
173 177
174 for (i = 0; i < num_formats; i++) { 178 for (i = 0; i < num_formats; i++) {
175 v4l2_subdev_call(bcap_dev->sd, video, 179 code.index = i;
176 enum_mbus_fmt, i, &code); 180 v4l2_subdev_call(bcap_dev->sd, pad,
181 enum_mbus_code, NULL, &code);
177 for (j = 0; j < BCAP_MAX_FMTS; j++) 182 for (j = 0; j < BCAP_MAX_FMTS; j++)
178 if (code == bcap_formats[j].mbus_code) 183 if (code.code == bcap_formats[j].mbus_code)
179 break; 184 break;
180 if (j == BCAP_MAX_FMTS) { 185 if (j == BCAP_MAX_FMTS) {
181 /* we don't allow this sensor working with our bridge */ 186 /* we don't allow this sensor working with our bridge */
@@ -597,7 +602,10 @@ static int bcap_try_format(struct bcap_device *bcap,
597{ 602{
598 struct bcap_format *sf = bcap->sensor_formats; 603 struct bcap_format *sf = bcap->sensor_formats;
599 struct bcap_format *fmt = NULL; 604 struct bcap_format *fmt = NULL;
600 struct v4l2_mbus_framefmt mbus_fmt; 605 struct v4l2_subdev_pad_config pad_cfg;
606 struct v4l2_subdev_format format = {
607 .which = V4L2_SUBDEV_FORMAT_TRY,
608 };
601 int ret, i; 609 int ret, i;
602 610
603 for (i = 0; i < bcap->num_sensor_formats; i++) { 611 for (i = 0; i < bcap->num_sensor_formats; i++) {
@@ -608,16 +616,16 @@ static int bcap_try_format(struct bcap_device *bcap,
608 if (i == bcap->num_sensor_formats) 616 if (i == bcap->num_sensor_formats)
609 fmt = &sf[0]; 617 fmt = &sf[0];
610 618
611 v4l2_fill_mbus_format(&mbus_fmt, pixfmt, fmt->mbus_code); 619 v4l2_fill_mbus_format(&format.format, pixfmt, fmt->mbus_code);
612 ret = v4l2_subdev_call(bcap->sd, video, 620 ret = v4l2_subdev_call(bcap->sd, pad, set_fmt, &pad_cfg,
613 try_mbus_fmt, &mbus_fmt); 621 &format);
614 if (ret < 0) 622 if (ret < 0)
615 return ret; 623 return ret;
616 v4l2_fill_pix_format(pixfmt, &mbus_fmt); 624 v4l2_fill_pix_format(pixfmt, &format.format);
617 if (bcap_fmt) { 625 if (bcap_fmt) {
618 for (i = 0; i < bcap->num_sensor_formats; i++) { 626 for (i = 0; i < bcap->num_sensor_formats; i++) {
619 fmt = &sf[i]; 627 fmt = &sf[i];
620 if (mbus_fmt.code == fmt->mbus_code) 628 if (format.format.code == fmt->mbus_code)
621 break; 629 break;
622 } 630 }
623 *bcap_fmt = *fmt; 631 *bcap_fmt = *fmt;
@@ -666,7 +674,9 @@ static int bcap_s_fmt_vid_cap(struct file *file, void *priv,
666 struct v4l2_format *fmt) 674 struct v4l2_format *fmt)
667{ 675{
668 struct bcap_device *bcap_dev = video_drvdata(file); 676 struct bcap_device *bcap_dev = video_drvdata(file);
669 struct v4l2_mbus_framefmt mbus_fmt; 677 struct v4l2_subdev_format format = {
678 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
679 };
670 struct bcap_format bcap_fmt; 680 struct bcap_format bcap_fmt;
671 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 681 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
672 int ret; 682 int ret;
@@ -679,8 +689,8 @@ static int bcap_s_fmt_vid_cap(struct file *file, void *priv,
679 if (ret < 0) 689 if (ret < 0)
680 return ret; 690 return ret;
681 691
682 v4l2_fill_mbus_format(&mbus_fmt, pixfmt, bcap_fmt.mbus_code); 692 v4l2_fill_mbus_format(&format.format, pixfmt, bcap_fmt.mbus_code);
683 ret = v4l2_subdev_call(bcap_dev->sd, video, s_mbus_fmt, &mbus_fmt); 693 ret = v4l2_subdev_call(bcap_dev->sd, pad, set_fmt, NULL, &format);
684 if (ret < 0) 694 if (ret < 0)
685 return ret; 695 return ret;
686 bcap_dev->fmt = *pixfmt; 696 bcap_dev->fmt = *pixfmt;
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index d0430071d2ee..109797bb8fbb 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1305,7 +1305,7 @@ static void coda_finish_encode(struct coda_ctx *ctx)
1305 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); 1305 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
1306 1306
1307 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 1307 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
1308 v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); 1308 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE);
1309 1309
1310 ctx->gopcounter--; 1310 ctx->gopcounter--;
1311 if (ctx->gopcounter < 0) 1311 if (ctx->gopcounter < 0)
@@ -1975,7 +1975,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
1975 } 1975 }
1976 vb2_set_plane_payload(dst_buf, 0, payload); 1976 vb2_set_plane_payload(dst_buf, 0, payload);
1977 1977
1978 v4l2_m2m_buf_done(dst_buf, ctx->frame_errors[display_idx] ? 1978 coda_m2m_buf_done(ctx, dst_buf, ctx->frame_errors[display_idx] ?
1979 VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); 1979 VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
1980 1980
1981 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, 1981 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 8e6fe0200117..6d6e0ca91fb4 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -724,35 +724,30 @@ static int coda_qbuf(struct file *file, void *priv,
724} 724}
725 725
726static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx, 726static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
727 struct v4l2_buffer *buf) 727 struct vb2_buffer *buf)
728{ 728{
729 struct vb2_queue *src_vq; 729 struct vb2_queue *src_vq;
730 730
731 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); 731 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
732 732
733 return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) && 733 return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) &&
734 (buf->sequence == (ctx->qsequence - 1))); 734 (buf->v4l2_buf.sequence == (ctx->qsequence - 1)));
735} 735}
736 736
737static int coda_dqbuf(struct file *file, void *priv, 737void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_buffer *buf,
738 struct v4l2_buffer *buf) 738 enum vb2_buffer_state state)
739{ 739{
740 struct coda_ctx *ctx = fh_to_ctx(priv); 740 const struct v4l2_event eos_event = {
741 int ret; 741 .type = V4L2_EVENT_EOS
742 };
742 743
743 ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf); 744 if (coda_buf_is_end_of_stream(ctx, buf)) {
744 745 buf->v4l2_buf.flags |= V4L2_BUF_FLAG_LAST;
745 /* If this is the last capture buffer, emit an end-of-stream event */
746 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
747 coda_buf_is_end_of_stream(ctx, buf)) {
748 const struct v4l2_event eos_event = {
749 .type = V4L2_EVENT_EOS
750 };
751 746
752 v4l2_event_queue_fh(&ctx->fh, &eos_event); 747 v4l2_event_queue_fh(&ctx->fh, &eos_event);
753 } 748 }
754 749
755 return ret; 750 v4l2_m2m_buf_done(buf, state);
756} 751}
757 752
758static int coda_g_selection(struct file *file, void *fh, 753static int coda_g_selection(struct file *file, void *fh,
@@ -865,7 +860,7 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
865 860
866 .vidioc_qbuf = coda_qbuf, 861 .vidioc_qbuf = coda_qbuf,
867 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, 862 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
868 .vidioc_dqbuf = coda_dqbuf, 863 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
869 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, 864 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
870 865
871 .vidioc_streamon = v4l2_m2m_ioctl_streamon, 866 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 6a5c8f6c688e..8e0af221b2e9 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -287,6 +287,9 @@ static inline unsigned int coda_get_bitstream_payload(struct coda_ctx *ctx)
287 287
288void coda_bit_stream_end_flag(struct coda_ctx *ctx); 288void coda_bit_stream_end_flag(struct coda_ctx *ctx);
289 289
290void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_buffer *buf,
291 enum vb2_buffer_state state);
292
290int coda_h264_padding(int size, char *p); 293int coda_h264_padding(int size, char *p);
291 294
292bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb); 295bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb);
diff --git a/drivers/media/platform/coda/trace.h b/drivers/media/platform/coda/trace.h
index d1d06cbd1f6a..781bf7286d53 100644
--- a/drivers/media/platform/coda/trace.h
+++ b/drivers/media/platform/coda/trace.h
@@ -9,8 +9,6 @@
9 9
10#include "coda.h" 10#include "coda.h"
11 11
12#define TRACE_SYSTEM_STRING __stringify(TRACE_SYSTEM)
13
14TRACE_EVENT(coda_bit_run, 12TRACE_EVENT(coda_bit_run,
15 TP_PROTO(struct coda_ctx *ctx, int cmd), 13 TP_PROTO(struct coda_ctx *ctx, int cmd),
16 14
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index c4ab46f5bd92..f69cdd7da10c 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -71,15 +71,10 @@ static int venc_is_second_field(struct vpbe_display *disp_dev)
71static void vpbe_isr_even_field(struct vpbe_display *disp_obj, 71static void vpbe_isr_even_field(struct vpbe_display *disp_obj,
72 struct vpbe_layer *layer) 72 struct vpbe_layer *layer)
73{ 73{
74 struct timespec timevalue;
75
76 if (layer->cur_frm == layer->next_frm) 74 if (layer->cur_frm == layer->next_frm)
77 return; 75 return;
78 ktime_get_ts(&timevalue); 76
79 layer->cur_frm->vb.v4l2_buf.timestamp.tv_sec = 77 v4l2_get_timestamp(&layer->cur_frm->vb.v4l2_buf.timestamp);
80 timevalue.tv_sec;
81 layer->cur_frm->vb.v4l2_buf.timestamp.tv_usec =
82 timevalue.tv_nsec / NSEC_PER_USEC;
83 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_DONE); 78 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_DONE);
84 /* Make cur_frm pointing to next_frm */ 79 /* Make cur_frm pointing to next_frm */
85 layer->cur_frm = layer->next_frm; 80 layer->cur_frm = layer->next_frm;
diff --git a/drivers/media/platform/davinci/vpfe_capture.c b/drivers/media/platform/davinci/vpfe_capture.c
index ccfcf3f528d3..7767e072d623 100644
--- a/drivers/media/platform/davinci/vpfe_capture.c
+++ b/drivers/media/platform/davinci/vpfe_capture.c
@@ -370,7 +370,7 @@ static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe_dev)
370 * For a given standard, this functions sets up the default 370 * For a given standard, this functions sets up the default
371 * pix format & crop values in the vpfe device and ccdc. It first 371 * pix format & crop values in the vpfe device and ccdc. It first
372 * starts with defaults based values from the standard table. 372 * starts with defaults based values from the standard table.
373 * It then checks if sub device support g_mbus_fmt and then override the 373 * It then checks if sub device supports get_fmt and then override the
374 * values based on that.Sets crop values to match with scan resolution 374 * values based on that.Sets crop values to match with scan resolution
375 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the 375 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
376 * values in ccdc 376 * values in ccdc
@@ -379,7 +379,10 @@ static int vpfe_config_image_format(struct vpfe_device *vpfe_dev,
379 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_subdev_format fmt = {
383 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
384 };
385 struct v4l2_mbus_framefmt *mbus_fmt = &fmt.format;
383 struct v4l2_pix_format *pix = &vpfe_dev->fmt.fmt.pix; 386 struct v4l2_pix_format *pix = &vpfe_dev->fmt.fmt.pix;
384 int i, ret = 0; 387 int i, ret = 0;
385 388
@@ -413,26 +416,26 @@ static int vpfe_config_image_format(struct vpfe_device *vpfe_dev,
413 pix->field = V4L2_FIELD_INTERLACED; 416 pix->field = V4L2_FIELD_INTERLACED;
414 /* assume V4L2_PIX_FMT_UYVY as default */ 417 /* assume V4L2_PIX_FMT_UYVY as default */
415 pix->pixelformat = V4L2_PIX_FMT_UYVY; 418 pix->pixelformat = V4L2_PIX_FMT_UYVY;
416 v4l2_fill_mbus_format(&mbus_fmt, pix, 419 v4l2_fill_mbus_format(mbus_fmt, pix,
417 MEDIA_BUS_FMT_YUYV10_2X10); 420 MEDIA_BUS_FMT_YUYV10_2X10);
418 } else { 421 } else {
419 pix->field = V4L2_FIELD_NONE; 422 pix->field = V4L2_FIELD_NONE;
420 /* assume V4L2_PIX_FMT_SBGGR8 */ 423 /* assume V4L2_PIX_FMT_SBGGR8 */
421 pix->pixelformat = V4L2_PIX_FMT_SBGGR8; 424 pix->pixelformat = V4L2_PIX_FMT_SBGGR8;
422 v4l2_fill_mbus_format(&mbus_fmt, pix, 425 v4l2_fill_mbus_format(mbus_fmt, pix,
423 MEDIA_BUS_FMT_SBGGR8_1X8); 426 MEDIA_BUS_FMT_SBGGR8_1X8);
424 } 427 }
425 428
426 /* if sub device supports g_mbus_fmt, override the defaults */ 429 /* if sub device supports get_fmt, override the defaults */
427 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, 430 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev,
428 sdinfo->grp_id, video, g_mbus_fmt, &mbus_fmt); 431 sdinfo->grp_id, pad, get_fmt, NULL, &fmt);
429 432
430 if (ret && ret != -ENOIOCTLCMD) { 433 if (ret && ret != -ENOIOCTLCMD) {
431 v4l2_err(&vpfe_dev->v4l2_dev, 434 v4l2_err(&vpfe_dev->v4l2_dev,
432 "error in getting g_mbus_fmt from sub device\n"); 435 "error in getting get_fmt from sub device\n");
433 return ret; 436 return ret;
434 } 437 }
435 v4l2_fill_pix_format(pix, &mbus_fmt); 438 v4l2_fill_pix_format(pix, mbus_fmt);
436 pix->bytesperline = pix->width * 2; 439 pix->bytesperline = pix->width * 2;
437 pix->sizeimage = pix->bytesperline * pix->height; 440 pix->sizeimage = pix->bytesperline * pix->height;
438 441
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index fd2891c886a3..9b9e423e4fc4 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -967,7 +967,7 @@ static struct gsc_driverdata gsc_v_100_drvdata = {
967 .lclk_frequency = 266000000UL, 967 .lclk_frequency = 266000000UL,
968}; 968};
969 969
970static struct platform_device_id gsc_driver_ids[] = { 970static const struct platform_device_id gsc_driver_ids[] = {
971 { 971 {
972 .name = "exynos-gsc", 972 .name = "exynos-gsc",
973 .driver_data = (unsigned long)&gsc_v_100_drvdata, 973 .driver_data = (unsigned long)&gsc_v_100_drvdata,
diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig
index b7b2e472240a..40423c6c5324 100644
--- a/drivers/media/platform/exynos4-is/Kconfig
+++ b/drivers/media/platform/exynos4-is/Kconfig
@@ -57,6 +57,7 @@ endif
57 57
58config VIDEO_EXYNOS4_FIMC_IS 58config VIDEO_EXYNOS4_FIMC_IS
59 tristate "EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver" 59 tristate "EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver"
60 depends on I2C
60 depends on HAS_DMA 61 depends on HAS_DMA
61 select VIDEOBUF2_DMA_CONTIG 62 select VIDEOBUF2_DMA_CONTIG
62 depends on OF 63 depends on OF
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index f315ef946cd4..4f5586a4cbff 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1451,7 +1451,7 @@ static int fimc_md_remove(struct platform_device *pdev)
1451 return 0; 1451 return 0;
1452} 1452}
1453 1453
1454static struct platform_device_id fimc_driver_ids[] __always_unused = { 1454static const struct platform_device_id fimc_driver_ids[] __always_unused = {
1455 { .name = "s5p-fimc-md" }, 1455 { .name = "s5p-fimc-md" },
1456 { }, 1456 { },
1457}; 1457};
diff --git a/drivers/media/platform/fsl-viu.c b/drivers/media/platform/fsl-viu.c
index bbf428104871..5b76e3db6a92 100644
--- a/drivers/media/platform/fsl-viu.c
+++ b/drivers/media/platform/fsl-viu.c
@@ -1664,7 +1664,7 @@ static int viu_resume(struct platform_device *op)
1664/* 1664/*
1665 * Initialization and module stuff 1665 * Initialization and module stuff
1666 */ 1666 */
1667static struct of_device_id mpc512x_viu_of_match[] = { 1667static const struct of_device_id mpc512x_viu_of_match[] = {
1668 { 1668 {
1669 .compatible = "fsl,mpc5121-viu", 1669 .compatible = "fsl,mpc5121-viu",
1670 }, 1670 },
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 92d954973ccf..c07f367aa436 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -1060,7 +1060,6 @@ static int deinterlace_probe(struct platform_device *pdev)
1060 1060
1061 return 0; 1061 return 0;
1062 1062
1063 v4l2_m2m_release(pcdev->m2m_dev);
1064err_m2m: 1063err_m2m:
1065 video_unregister_device(&pcdev->vfd); 1064 video_unregister_device(&pcdev->vfd);
1066err_ctx: 1065err_ctx:
diff --git a/drivers/media/platform/marvell-ccic/cafe-driver.c b/drivers/media/platform/marvell-ccic/cafe-driver.c
index 562845361246..77890bd0deab 100644
--- a/drivers/media/platform/marvell-ccic/cafe-driver.c
+++ b/drivers/media/platform/marvell-ccic/cafe-driver.c
@@ -339,17 +339,21 @@ static int cafe_smbus_setup(struct cafe_camera *cam)
339 adap = kzalloc(sizeof(*adap), GFP_KERNEL); 339 adap = kzalloc(sizeof(*adap), GFP_KERNEL);
340 if (adap == NULL) 340 if (adap == NULL)
341 return -ENOMEM; 341 return -ENOMEM;
342 cam->mcam.i2c_adapter = adap;
343 cafe_smbus_enable_irq(cam);
344 adap->owner = THIS_MODULE; 342 adap->owner = THIS_MODULE;
345 adap->algo = &cafe_smbus_algo; 343 adap->algo = &cafe_smbus_algo;
346 strcpy(adap->name, "cafe_ccic"); 344 strcpy(adap->name, "cafe_ccic");
347 adap->dev.parent = &cam->pdev->dev; 345 adap->dev.parent = &cam->pdev->dev;
348 i2c_set_adapdata(adap, cam); 346 i2c_set_adapdata(adap, cam);
349 ret = i2c_add_adapter(adap); 347 ret = i2c_add_adapter(adap);
350 if (ret) 348 if (ret) {
351 printk(KERN_ERR "Unable to register cafe i2c adapter\n"); 349 printk(KERN_ERR "Unable to register cafe i2c adapter\n");
352 return ret; 350 kfree(adap);
351 return ret;
352 }
353
354 cam->mcam.i2c_adapter = adap;
355 cafe_smbus_enable_irq(cam);
356 return 0;
353} 357}
354 358
355static void cafe_smbus_shutdown(struct cafe_camera *cam) 359static void cafe_smbus_shutdown(struct cafe_camera *cam)
@@ -476,6 +480,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
476 mcam->plat_power_up = cafe_ctlr_power_up; 480 mcam->plat_power_up = cafe_ctlr_power_up;
477 mcam->plat_power_down = cafe_ctlr_power_down; 481 mcam->plat_power_down = cafe_ctlr_power_down;
478 mcam->dev = &pdev->dev; 482 mcam->dev = &pdev->dev;
483 snprintf(mcam->bus_info, sizeof(mcam->bus_info), "PCI:%s", pci_name(pdev));
479 /* 484 /*
480 * Set the clock speed for the XO 1; I don't believe this 485 * Set the clock speed for the XO 1; I don't believe this
481 * driver has ever run anywhere else. 486 * driver has ever run anywhere else.
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 110fd70c7326..5e2b4df48b3c 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -24,6 +24,7 @@
24#include <media/v4l2-device.h> 24#include <media/v4l2-device.h>
25#include <media/v4l2-ioctl.h> 25#include <media/v4l2-ioctl.h>
26#include <media/v4l2-ctrls.h> 26#include <media/v4l2-ctrls.h>
27#include <media/v4l2-event.h>
27#include <media/ov7670.h> 28#include <media/ov7670.h>
28#include <media/videobuf2-vmalloc.h> 29#include <media/videobuf2-vmalloc.h>
29#include <media/videobuf2-dma-contig.h> 30#include <media/videobuf2-dma-contig.h>
@@ -123,29 +124,22 @@ static struct mcam_format_struct {
123 .planar = false, 124 .planar = false,
124 }, 125 },
125 { 126 {
126 .desc = "YUV 4:2:2 PLANAR",
127 .pixelformat = V4L2_PIX_FMT_YUV422P,
128 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
129 .bpp = 2,
130 .planar = true,
131 },
132 {
133 .desc = "YUV 4:2:0 PLANAR", 127 .desc = "YUV 4:2:0 PLANAR",
134 .pixelformat = V4L2_PIX_FMT_YUV420, 128 .pixelformat = V4L2_PIX_FMT_YUV420,
135 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8, 129 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
136 .bpp = 2, 130 .bpp = 1,
137 .planar = true, 131 .planar = true,
138 }, 132 },
139 { 133 {
140 .desc = "YVU 4:2:0 PLANAR", 134 .desc = "YVU 4:2:0 PLANAR",
141 .pixelformat = V4L2_PIX_FMT_YVU420, 135 .pixelformat = V4L2_PIX_FMT_YVU420,
142 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8, 136 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
143 .bpp = 2, 137 .bpp = 1,
144 .planar = true, 138 .planar = true,
145 }, 139 },
146 { 140 {
147 .desc = "RGB 444", 141 .desc = "XRGB 444",
148 .pixelformat = V4L2_PIX_FMT_RGB444, 142 .pixelformat = V4L2_PIX_FMT_XRGB444,
149 .mbus_code = MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE, 143 .mbus_code = MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE,
150 .bpp = 2, 144 .bpp = 2,
151 .planar = false, 145 .planar = false,
@@ -188,6 +182,7 @@ static const struct v4l2_pix_format mcam_def_pix_format = {
188 .field = V4L2_FIELD_NONE, 182 .field = V4L2_FIELD_NONE,
189 .bytesperline = VGA_WIDTH*2, 183 .bytesperline = VGA_WIDTH*2,
190 .sizeimage = VGA_WIDTH*VGA_HEIGHT*2, 184 .sizeimage = VGA_WIDTH*VGA_HEIGHT*2,
185 .colorspace = V4L2_COLORSPACE_SRGB,
191}; 186};
192 187
193static const u32 mcam_def_mbus_code = MEDIA_BUS_FMT_YUYV8_2X8; 188static const u32 mcam_def_mbus_code = MEDIA_BUS_FMT_YUYV8_2X8;
@@ -204,12 +199,6 @@ struct mcam_dma_desc {
204 u32 segment_len; 199 u32 segment_len;
205}; 200};
206 201
207struct yuv_pointer_t {
208 dma_addr_t y;
209 dma_addr_t u;
210 dma_addr_t v;
211};
212
213/* 202/*
214 * Our buffer type for working with videobuf2. Note that the vb2 203 * Our buffer type for working with videobuf2. Note that the vb2
215 * developers have decreed that struct vb2_buffer must be at the 204 * developers have decreed that struct vb2_buffer must be at the
@@ -221,7 +210,6 @@ struct mcam_vb_buffer {
221 struct mcam_dma_desc *dma_desc; /* Descriptor virtual address */ 210 struct mcam_dma_desc *dma_desc; /* Descriptor virtual address */
222 dma_addr_t dma_desc_pa; /* Descriptor physical address */ 211 dma_addr_t dma_desc_pa; /* Descriptor physical address */
223 int dma_desc_nent; /* Number of mapped descriptors */ 212 int dma_desc_nent; /* Number of mapped descriptors */
224 struct yuv_pointer_t yuv_p;
225}; 213};
226 214
227static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb) 215static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb)
@@ -237,6 +225,8 @@ static void mcam_buffer_done(struct mcam_camera *cam, int frame,
237{ 225{
238 vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage; 226 vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage;
239 vbuf->v4l2_buf.sequence = cam->buf_seq[frame]; 227 vbuf->v4l2_buf.sequence = cam->buf_seq[frame];
228 vbuf->v4l2_buf.field = V4L2_FIELD_NONE;
229 v4l2_get_timestamp(&vbuf->v4l2_buf.timestamp);
240 vb2_set_plane_payload(vbuf, 0, cam->pix_format.sizeimage); 230 vb2_set_plane_payload(vbuf, 0, cam->pix_format.sizeimage);
241 vb2_buffer_done(vbuf, VB2_BUF_STATE_DONE); 231 vb2_buffer_done(vbuf, VB2_BUF_STATE_DONE);
242} 232}
@@ -337,6 +327,43 @@ static void mcam_disable_mipi(struct mcam_camera *mcam)
337 mcam->mipi_enabled = false; 327 mcam->mipi_enabled = false;
338} 328}
339 329
330static bool mcam_fmt_is_planar(__u32 pfmt)
331{
332 struct mcam_format_struct *f;
333
334 f = mcam_find_format(pfmt);
335 return f->planar;
336}
337
338static void mcam_write_yuv_bases(struct mcam_camera *cam,
339 unsigned frame, dma_addr_t base)
340{
341 struct v4l2_pix_format *fmt = &cam->pix_format;
342 u32 pixel_count = fmt->width * fmt->height;
343 dma_addr_t y, u = 0, v = 0;
344
345 y = base;
346
347 switch (fmt->pixelformat) {
348 case V4L2_PIX_FMT_YUV420:
349 u = y + pixel_count;
350 v = u + pixel_count / 4;
351 break;
352 case V4L2_PIX_FMT_YVU420:
353 v = y + pixel_count;
354 u = v + pixel_count / 4;
355 break;
356 default:
357 break;
358 }
359
360 mcam_reg_write(cam, REG_Y0BAR + frame * 4, y);
361 if (mcam_fmt_is_planar(fmt->pixelformat)) {
362 mcam_reg_write(cam, REG_U0BAR + frame * 4, u);
363 mcam_reg_write(cam, REG_V0BAR + frame * 4, v);
364 }
365}
366
340/* ------------------------------------------------------------------- */ 367/* ------------------------------------------------------------------- */
341 368
342#ifdef MCAM_MODE_VMALLOC 369#ifdef MCAM_MODE_VMALLOC
@@ -407,15 +434,14 @@ static void mcam_free_dma_bufs(struct mcam_camera *cam)
407static void mcam_ctlr_dma_vmalloc(struct mcam_camera *cam) 434static void mcam_ctlr_dma_vmalloc(struct mcam_camera *cam)
408{ 435{
409 /* 436 /*
410 * Store the first two Y buffers (we aren't supporting 437 * Store the first two YUV buffers. Then either
411 * planar formats for now, so no UV bufs). Then either
412 * set the third if it exists, or tell the controller 438 * set the third if it exists, or tell the controller
413 * to just use two. 439 * to just use two.
414 */ 440 */
415 mcam_reg_write(cam, REG_Y0BAR, cam->dma_handles[0]); 441 mcam_write_yuv_bases(cam, 0, cam->dma_handles[0]);
416 mcam_reg_write(cam, REG_Y1BAR, cam->dma_handles[1]); 442 mcam_write_yuv_bases(cam, 1, cam->dma_handles[1]);
417 if (cam->nbufs > 2) { 443 if (cam->nbufs > 2) {
418 mcam_reg_write(cam, REG_Y2BAR, cam->dma_handles[2]); 444 mcam_write_yuv_bases(cam, 2, cam->dma_handles[2]);
419 mcam_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS); 445 mcam_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS);
420 } else 446 } else
421 mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS); 447 mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
@@ -510,14 +536,6 @@ static inline int mcam_check_dma_buffers(struct mcam_camera *cam)
510 * DMA-contiguous code. 536 * DMA-contiguous code.
511 */ 537 */
512 538
513static bool mcam_fmt_is_planar(__u32 pfmt)
514{
515 struct mcam_format_struct *f;
516
517 f = mcam_find_format(pfmt);
518 return f->planar;
519}
520
521/* 539/*
522 * Set up a contiguous buffer for the given frame. Here also is where 540 * Set up a contiguous buffer for the given frame. Here also is where
523 * the underrun strategy is set: if there is no buffer available, reuse 541 * the underrun strategy is set: if there is no buffer available, reuse
@@ -529,9 +547,7 @@ static bool mcam_fmt_is_planar(__u32 pfmt)
529static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame) 547static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
530{ 548{
531 struct mcam_vb_buffer *buf; 549 struct mcam_vb_buffer *buf;
532 struct v4l2_pix_format *fmt = &cam->pix_format;
533 dma_addr_t dma_handle; 550 dma_addr_t dma_handle;
534 u32 pixel_count = fmt->width * fmt->height;
535 struct vb2_buffer *vb; 551 struct vb2_buffer *vb;
536 552
537 /* 553 /*
@@ -555,32 +571,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
555 vb = &buf->vb_buf; 571 vb = &buf->vb_buf;
556 572
557 dma_handle = vb2_dma_contig_plane_dma_addr(vb, 0); 573 dma_handle = vb2_dma_contig_plane_dma_addr(vb, 0);
558 buf->yuv_p.y = dma_handle; 574 mcam_write_yuv_bases(cam, frame, dma_handle);
559
560 switch (cam->pix_format.pixelformat) {
561 case V4L2_PIX_FMT_YUV422P:
562 buf->yuv_p.u = buf->yuv_p.y + pixel_count;
563 buf->yuv_p.v = buf->yuv_p.u + pixel_count / 2;
564 break;
565 case V4L2_PIX_FMT_YUV420:
566 buf->yuv_p.u = buf->yuv_p.y + pixel_count;
567 buf->yuv_p.v = buf->yuv_p.u + pixel_count / 4;
568 break;
569 case V4L2_PIX_FMT_YVU420:
570 buf->yuv_p.v = buf->yuv_p.y + pixel_count;
571 buf->yuv_p.u = buf->yuv_p.v + pixel_count / 4;
572 break;
573 default:
574 break;
575 }
576
577 mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR, buf->yuv_p.y);
578 if (mcam_fmt_is_planar(fmt->pixelformat)) {
579 mcam_reg_write(cam, frame == 0 ?
580 REG_U0BAR : REG_U1BAR, buf->yuv_p.u);
581 mcam_reg_write(cam, frame == 0 ?
582 REG_V0BAR : REG_V1BAR, buf->yuv_p.v);
583 }
584} 575}
585 576
586/* 577/*
@@ -603,6 +594,7 @@ static void mcam_dma_contig_done(struct mcam_camera *cam, int frame)
603 594
604 if (!test_bit(CF_SINGLE_BUFFER, &cam->flags)) { 595 if (!test_bit(CF_SINGLE_BUFFER, &cam->flags)) {
605 cam->frame_state.delivered++; 596 cam->frame_state.delivered++;
597 cam->vb_bufs[frame] = NULL;
606 mcam_buffer_done(cam, frame, &buf->vb_buf); 598 mcam_buffer_done(cam, frame, &buf->vb_buf);
607 } 599 }
608 mcam_set_contig_buffer(cam, frame); 600 mcam_set_contig_buffer(cam, frame);
@@ -752,12 +744,6 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
752 widthy = fmt->width * 2; 744 widthy = fmt->width * 2;
753 widthuv = 0; 745 widthuv = 0;
754 break; 746 break;
755 case V4L2_PIX_FMT_JPEG:
756 imgsz_h = (fmt->sizeimage / fmt->bytesperline) << IMGSZ_V_SHIFT;
757 widthy = fmt->bytesperline;
758 widthuv = 0;
759 break;
760 case V4L2_PIX_FMT_YUV422P:
761 case V4L2_PIX_FMT_YUV420: 747 case V4L2_PIX_FMT_YUV420:
762 case V4L2_PIX_FMT_YVU420: 748 case V4L2_PIX_FMT_YVU420:
763 widthy = fmt->width; 749 widthy = fmt->width;
@@ -766,6 +752,7 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
766 default: 752 default:
767 widthy = fmt->bytesperline; 753 widthy = fmt->bytesperline;
768 widthuv = 0; 754 widthuv = 0;
755 break;
769 } 756 }
770 757
771 mcam_reg_write_mask(cam, REG_IMGPITCH, widthuv << 16 | widthy, 758 mcam_reg_write_mask(cam, REG_IMGPITCH, widthuv << 16 | widthy,
@@ -777,10 +764,6 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
777 * Tell the controller about the image format we are using. 764 * Tell the controller about the image format we are using.
778 */ 765 */
779 switch (fmt->pixelformat) { 766 switch (fmt->pixelformat) {
780 case V4L2_PIX_FMT_YUV422P:
781 mcam_reg_write_mask(cam, REG_CTRL0,
782 C0_DF_YUV | C0_YUV_PLANAR | C0_YUVE_YVYU, C0_DF_MASK);
783 break;
784 case V4L2_PIX_FMT_YUV420: 767 case V4L2_PIX_FMT_YUV420:
785 case V4L2_PIX_FMT_YVU420: 768 case V4L2_PIX_FMT_YVU420:
786 mcam_reg_write_mask(cam, REG_CTRL0, 769 mcam_reg_write_mask(cam, REG_CTRL0,
@@ -794,19 +777,18 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
794 mcam_reg_write_mask(cam, REG_CTRL0, 777 mcam_reg_write_mask(cam, REG_CTRL0,
795 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_SWAP24, C0_DF_MASK); 778 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_SWAP24, C0_DF_MASK);
796 break; 779 break;
797 case V4L2_PIX_FMT_JPEG: 780 case V4L2_PIX_FMT_XRGB444:
798 mcam_reg_write_mask(cam, REG_CTRL0,
799 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_YUYV, C0_DF_MASK);
800 break;
801 case V4L2_PIX_FMT_RGB444:
802 mcam_reg_write_mask(cam, REG_CTRL0, 781 mcam_reg_write_mask(cam, REG_CTRL0,
803 C0_DF_RGB | C0_RGBF_444 | C0_RGB4_XRGB, C0_DF_MASK); 782 C0_DF_RGB | C0_RGBF_444 | C0_RGB4_XBGR, C0_DF_MASK);
804 /* Alpha value? */
805 break; 783 break;
806 case V4L2_PIX_FMT_RGB565: 784 case V4L2_PIX_FMT_RGB565:
807 mcam_reg_write_mask(cam, REG_CTRL0, 785 mcam_reg_write_mask(cam, REG_CTRL0,
808 C0_DF_RGB | C0_RGBF_565 | C0_RGB5_BGGR, C0_DF_MASK); 786 C0_DF_RGB | C0_RGBF_565 | C0_RGB5_BGGR, C0_DF_MASK);
809 break; 787 break;
788 case V4L2_PIX_FMT_SBGGR8:
789 mcam_reg_write_mask(cam, REG_CTRL0,
790 C0_DF_RGB | C0_RGB5_GRBG, C0_DF_MASK);
791 break;
810 default: 792 default:
811 cam_err(cam, "camera: unknown format: %#x\n", fmt->pixelformat); 793 cam_err(cam, "camera: unknown format: %#x\n", fmt->pixelformat);
812 break; 794 break;
@@ -969,7 +951,6 @@ static int mcam_cam_init(struct mcam_camera *cam)
969{ 951{
970 int ret; 952 int ret;
971 953
972 mutex_lock(&cam->s_mutex);
973 if (cam->state != S_NOTREADY) 954 if (cam->state != S_NOTREADY)
974 cam_warn(cam, "Cam init with device in funky state %d", 955 cam_warn(cam, "Cam init with device in funky state %d",
975 cam->state); 956 cam->state);
@@ -977,7 +958,6 @@ static int mcam_cam_init(struct mcam_camera *cam)
977 /* Get/set parameters? */ 958 /* Get/set parameters? */
978 cam->state = S_IDLE; 959 cam->state = S_IDLE;
979 mcam_ctlr_power_down(cam); 960 mcam_ctlr_power_down(cam);
980 mutex_unlock(&cam->s_mutex);
981 return ret; 961 return ret;
982} 962}
983 963
@@ -998,13 +978,15 @@ static int mcam_cam_set_flip(struct mcam_camera *cam)
998 978
999static int mcam_cam_configure(struct mcam_camera *cam) 979static int mcam_cam_configure(struct mcam_camera *cam)
1000{ 980{
1001 struct v4l2_mbus_framefmt mbus_fmt; 981 struct v4l2_subdev_format format = {
982 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
983 };
1002 int ret; 984 int ret;
1003 985
1004 v4l2_fill_mbus_format(&mbus_fmt, &cam->pix_format, cam->mbus_code); 986 v4l2_fill_mbus_format(&format.format, &cam->pix_format, cam->mbus_code);
1005 ret = sensor_call(cam, core, init, 0); 987 ret = sensor_call(cam, core, init, 0);
1006 if (ret == 0) 988 if (ret == 0)
1007 ret = sensor_call(cam, video, s_mbus_fmt, &mbus_fmt); 989 ret = sensor_call(cam, pad, set_fmt, NULL, &format);
1008 /* 990 /*
1009 * OV7670 does weird things if flip is set *before* format... 991 * OV7670 does weird things if flip is set *before* format...
1010 */ 992 */
@@ -1073,7 +1055,9 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
1073 struct mcam_camera *cam = vb2_get_drv_priv(vq); 1055 struct mcam_camera *cam = vb2_get_drv_priv(vq);
1074 int minbufs = (cam->buffer_mode == B_DMA_contig) ? 3 : 2; 1056 int minbufs = (cam->buffer_mode == B_DMA_contig) ? 3 : 2;
1075 1057
1076 sizes[0] = cam->pix_format.sizeimage; 1058 if (fmt && fmt->fmt.pix.sizeimage < cam->pix_format.sizeimage)
1059 return -EINVAL;
1060 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : cam->pix_format.sizeimage;
1077 *num_planes = 1; /* Someday we have to support planar formats... */ 1061 *num_planes = 1; /* Someday we have to support planar formats... */
1078 if (*nbufs < minbufs) 1062 if (*nbufs < minbufs)
1079 *nbufs = minbufs; 1063 *nbufs = minbufs;
@@ -1102,6 +1086,30 @@ static void mcam_vb_buf_queue(struct vb2_buffer *vb)
1102 mcam_read_setup(cam); 1086 mcam_read_setup(cam);
1103} 1087}
1104 1088
1089static void mcam_vb_requeue_bufs(struct vb2_queue *vq,
1090 enum vb2_buffer_state state)
1091{
1092 struct mcam_camera *cam = vb2_get_drv_priv(vq);
1093 struct mcam_vb_buffer *buf, *node;
1094 unsigned long flags;
1095 unsigned i;
1096
1097 spin_lock_irqsave(&cam->dev_lock, flags);
1098 list_for_each_entry_safe(buf, node, &cam->buffers, queue) {
1099 vb2_buffer_done(&buf->vb_buf, state);
1100 list_del(&buf->queue);
1101 }
1102 for (i = 0; i < MAX_DMA_BUFS; i++) {
1103 buf = cam->vb_bufs[i];
1104
1105 if (buf) {
1106 vb2_buffer_done(&buf->vb_buf, state);
1107 cam->vb_bufs[i] = NULL;
1108 }
1109 }
1110 spin_unlock_irqrestore(&cam->dev_lock, flags);
1111}
1112
1105/* 1113/*
1106 * These need to be called with the mutex held from vb2 1114 * These need to be called with the mutex held from vb2
1107 */ 1115 */
@@ -1109,11 +1117,15 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
1109{ 1117{
1110 struct mcam_camera *cam = vb2_get_drv_priv(vq); 1118 struct mcam_camera *cam = vb2_get_drv_priv(vq);
1111 unsigned int frame; 1119 unsigned int frame;
1120 int ret;
1112 1121
1113 if (cam->state != S_IDLE) { 1122 if (cam->state != S_IDLE) {
1114 INIT_LIST_HEAD(&cam->buffers); 1123 mcam_vb_requeue_bufs(vq, VB2_BUF_STATE_QUEUED);
1115 return -EINVAL; 1124 return -EINVAL;
1116 } 1125 }
1126 cam->frame_state.frames = 0;
1127 cam->frame_state.singles = 0;
1128 cam->frame_state.delivered = 0;
1117 cam->sequence = 0; 1129 cam->sequence = 0;
1118 /* 1130 /*
1119 * Videobuf2 sneakily hoards all the buffers and won't 1131 * Videobuf2 sneakily hoards all the buffers and won't
@@ -1134,14 +1146,19 @@ static int mcam_vb_start_streaming(struct vb2_queue *vq, unsigned int count)
1134 for (frame = 0; frame < cam->nbufs; frame++) 1146 for (frame = 0; frame < cam->nbufs; frame++)
1135 clear_bit(CF_FRAME_SOF0 + frame, &cam->flags); 1147 clear_bit(CF_FRAME_SOF0 + frame, &cam->flags);
1136 1148
1137 return mcam_read_setup(cam); 1149 ret = mcam_read_setup(cam);
1150 if (ret)
1151 mcam_vb_requeue_bufs(vq, VB2_BUF_STATE_QUEUED);
1152 return ret;
1138} 1153}
1139 1154
1140static void mcam_vb_stop_streaming(struct vb2_queue *vq) 1155static void mcam_vb_stop_streaming(struct vb2_queue *vq)
1141{ 1156{
1142 struct mcam_camera *cam = vb2_get_drv_priv(vq); 1157 struct mcam_camera *cam = vb2_get_drv_priv(vq);
1143 unsigned long flags;
1144 1158
1159 cam_dbg(cam, "stop_streaming: %d frames, %d singles, %d delivered\n",
1160 cam->frame_state.frames, cam->frame_state.singles,
1161 cam->frame_state.delivered);
1145 if (cam->state == S_BUFWAIT) { 1162 if (cam->state == S_BUFWAIT) {
1146 /* They never gave us buffers */ 1163 /* They never gave us buffers */
1147 cam->state = S_IDLE; 1164 cam->state = S_IDLE;
@@ -1160,9 +1177,7 @@ static void mcam_vb_stop_streaming(struct vb2_queue *vq)
1160 * VB2 reclaims the buffers, so we need to forget 1177 * VB2 reclaims the buffers, so we need to forget
1161 * about them. 1178 * about them.
1162 */ 1179 */
1163 spin_lock_irqsave(&cam->dev_lock, flags); 1180 mcam_vb_requeue_bufs(vq, VB2_BUF_STATE_ERROR);
1164 INIT_LIST_HEAD(&cam->buffers);
1165 spin_unlock_irqrestore(&cam->dev_lock, flags);
1166} 1181}
1167 1182
1168 1183
@@ -1246,14 +1261,15 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
1246 vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1261 vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1247 vq->drv_priv = cam; 1262 vq->drv_priv = cam;
1248 vq->lock = &cam->s_mutex; 1263 vq->lock = &cam->s_mutex;
1264 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1265 vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
1266 vq->buf_struct_size = sizeof(struct mcam_vb_buffer);
1249 INIT_LIST_HEAD(&cam->buffers); 1267 INIT_LIST_HEAD(&cam->buffers);
1250 switch (cam->buffer_mode) { 1268 switch (cam->buffer_mode) {
1251 case B_DMA_contig: 1269 case B_DMA_contig:
1252#ifdef MCAM_MODE_DMA_CONTIG 1270#ifdef MCAM_MODE_DMA_CONTIG
1253 vq->ops = &mcam_vb2_ops; 1271 vq->ops = &mcam_vb2_ops;
1254 vq->mem_ops = &vb2_dma_contig_memops; 1272 vq->mem_ops = &vb2_dma_contig_memops;
1255 vq->buf_struct_size = sizeof(struct mcam_vb_buffer);
1256 vq->io_modes = VB2_MMAP | VB2_USERPTR;
1257 cam->dma_setup = mcam_ctlr_dma_contig; 1273 cam->dma_setup = mcam_ctlr_dma_contig;
1258 cam->frame_complete = mcam_dma_contig_done; 1274 cam->frame_complete = mcam_dma_contig_done;
1259 cam->vb_alloc_ctx = vb2_dma_contig_init_ctx(cam->dev); 1275 cam->vb_alloc_ctx = vb2_dma_contig_init_ctx(cam->dev);
@@ -1265,8 +1281,6 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
1265#ifdef MCAM_MODE_DMA_SG 1281#ifdef MCAM_MODE_DMA_SG
1266 vq->ops = &mcam_vb2_sg_ops; 1282 vq->ops = &mcam_vb2_sg_ops;
1267 vq->mem_ops = &vb2_dma_sg_memops; 1283 vq->mem_ops = &vb2_dma_sg_memops;
1268 vq->buf_struct_size = sizeof(struct mcam_vb_buffer);
1269 vq->io_modes = VB2_MMAP | VB2_USERPTR;
1270 cam->dma_setup = mcam_ctlr_dma_sg; 1284 cam->dma_setup = mcam_ctlr_dma_sg;
1271 cam->frame_complete = mcam_dma_sg_done; 1285 cam->frame_complete = mcam_dma_sg_done;
1272 cam->vb_alloc_ctx_sg = vb2_dma_sg_init_ctx(cam->dev); 1286 cam->vb_alloc_ctx_sg = vb2_dma_sg_init_ctx(cam->dev);
@@ -1280,8 +1294,6 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
1280 (unsigned long) cam); 1294 (unsigned long) cam);
1281 vq->ops = &mcam_vb2_ops; 1295 vq->ops = &mcam_vb2_ops;
1282 vq->mem_ops = &vb2_vmalloc_memops; 1296 vq->mem_ops = &vb2_vmalloc_memops;
1283 vq->buf_struct_size = sizeof(struct mcam_vb_buffer);
1284 vq->io_modes = VB2_MMAP;
1285 cam->dma_setup = mcam_ctlr_dma_vmalloc; 1297 cam->dma_setup = mcam_ctlr_dma_vmalloc;
1286 cam->frame_complete = mcam_vmalloc_done; 1298 cam->frame_complete = mcam_vmalloc_done;
1287#endif 1299#endif
@@ -1292,7 +1304,6 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
1292 1304
1293static void mcam_cleanup_vb2(struct mcam_camera *cam) 1305static void mcam_cleanup_vb2(struct mcam_camera *cam)
1294{ 1306{
1295 vb2_queue_release(&cam->vb_queue);
1296#ifdef MCAM_MODE_DMA_CONTIG 1307#ifdef MCAM_MODE_DMA_CONTIG
1297 if (cam->buffer_mode == B_DMA_contig) 1308 if (cam->buffer_mode == B_DMA_contig)
1298 vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx); 1309 vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx);
@@ -1309,86 +1320,14 @@ static void mcam_cleanup_vb2(struct mcam_camera *cam)
1309 * The long list of V4L2 ioctl() operations. 1320 * The long list of V4L2 ioctl() operations.
1310 */ 1321 */
1311 1322
1312static int mcam_vidioc_streamon(struct file *filp, void *priv,
1313 enum v4l2_buf_type type)
1314{
1315 struct mcam_camera *cam = filp->private_data;
1316 int ret;
1317
1318 mutex_lock(&cam->s_mutex);
1319 ret = vb2_streamon(&cam->vb_queue, type);
1320 mutex_unlock(&cam->s_mutex);
1321 return ret;
1322}
1323
1324
1325static int mcam_vidioc_streamoff(struct file *filp, void *priv,
1326 enum v4l2_buf_type type)
1327{
1328 struct mcam_camera *cam = filp->private_data;
1329 int ret;
1330
1331 mutex_lock(&cam->s_mutex);
1332 ret = vb2_streamoff(&cam->vb_queue, type);
1333 mutex_unlock(&cam->s_mutex);
1334 return ret;
1335}
1336
1337
1338static int mcam_vidioc_reqbufs(struct file *filp, void *priv,
1339 struct v4l2_requestbuffers *req)
1340{
1341 struct mcam_camera *cam = filp->private_data;
1342 int ret;
1343
1344 mutex_lock(&cam->s_mutex);
1345 ret = vb2_reqbufs(&cam->vb_queue, req);
1346 mutex_unlock(&cam->s_mutex);
1347 return ret;
1348}
1349
1350
1351static int mcam_vidioc_querybuf(struct file *filp, void *priv,
1352 struct v4l2_buffer *buf)
1353{
1354 struct mcam_camera *cam = filp->private_data;
1355 int ret;
1356
1357 mutex_lock(&cam->s_mutex);
1358 ret = vb2_querybuf(&cam->vb_queue, buf);
1359 mutex_unlock(&cam->s_mutex);
1360 return ret;
1361}
1362
1363static int mcam_vidioc_qbuf(struct file *filp, void *priv,
1364 struct v4l2_buffer *buf)
1365{
1366 struct mcam_camera *cam = filp->private_data;
1367 int ret;
1368
1369 mutex_lock(&cam->s_mutex);
1370 ret = vb2_qbuf(&cam->vb_queue, buf);
1371 mutex_unlock(&cam->s_mutex);
1372 return ret;
1373}
1374
1375static int mcam_vidioc_dqbuf(struct file *filp, void *priv,
1376 struct v4l2_buffer *buf)
1377{
1378 struct mcam_camera *cam = filp->private_data;
1379 int ret;
1380
1381 mutex_lock(&cam->s_mutex);
1382 ret = vb2_dqbuf(&cam->vb_queue, buf, filp->f_flags & O_NONBLOCK);
1383 mutex_unlock(&cam->s_mutex);
1384 return ret;
1385}
1386
1387static int mcam_vidioc_querycap(struct file *file, void *priv, 1323static int mcam_vidioc_querycap(struct file *file, void *priv,
1388 struct v4l2_capability *cap) 1324 struct v4l2_capability *cap)
1389{ 1325{
1326 struct mcam_camera *cam = video_drvdata(file);
1327
1390 strcpy(cap->driver, "marvell_ccic"); 1328 strcpy(cap->driver, "marvell_ccic");
1391 strcpy(cap->card, "marvell_ccic"); 1329 strcpy(cap->card, "marvell_ccic");
1330 strlcpy(cap->bus_info, cam->bus_info, sizeof(cap->bus_info));
1392 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | 1331 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
1393 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 1332 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1394 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 1333 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
@@ -1410,36 +1349,38 @@ static int mcam_vidioc_enum_fmt_vid_cap(struct file *filp,
1410static int mcam_vidioc_try_fmt_vid_cap(struct file *filp, void *priv, 1349static int mcam_vidioc_try_fmt_vid_cap(struct file *filp, void *priv,
1411 struct v4l2_format *fmt) 1350 struct v4l2_format *fmt)
1412{ 1351{
1413 struct mcam_camera *cam = priv; 1352 struct mcam_camera *cam = video_drvdata(filp);
1414 struct mcam_format_struct *f; 1353 struct mcam_format_struct *f;
1415 struct v4l2_pix_format *pix = &fmt->fmt.pix; 1354 struct v4l2_pix_format *pix = &fmt->fmt.pix;
1416 struct v4l2_mbus_framefmt mbus_fmt; 1355 struct v4l2_subdev_pad_config pad_cfg;
1356 struct v4l2_subdev_format format = {
1357 .which = V4L2_SUBDEV_FORMAT_TRY,
1358 };
1417 int ret; 1359 int ret;
1418 1360
1419 f = mcam_find_format(pix->pixelformat); 1361 f = mcam_find_format(pix->pixelformat);
1420 pix->pixelformat = f->pixelformat; 1362 pix->pixelformat = f->pixelformat;
1421 v4l2_fill_mbus_format(&mbus_fmt, pix, f->mbus_code); 1363 v4l2_fill_mbus_format(&format.format, pix, f->mbus_code);
1422 mutex_lock(&cam->s_mutex); 1364 ret = sensor_call(cam, pad, set_fmt, &pad_cfg, &format);
1423 ret = sensor_call(cam, video, try_mbus_fmt, &mbus_fmt); 1365 v4l2_fill_pix_format(pix, &format.format);
1424 mutex_unlock(&cam->s_mutex); 1366 pix->bytesperline = pix->width * f->bpp;
1425 v4l2_fill_pix_format(pix, &mbus_fmt);
1426 switch (f->pixelformat) { 1367 switch (f->pixelformat) {
1427 case V4L2_PIX_FMT_YUV420: 1368 case V4L2_PIX_FMT_YUV420:
1428 case V4L2_PIX_FMT_YVU420: 1369 case V4L2_PIX_FMT_YVU420:
1429 pix->bytesperline = pix->width * 3 / 2; 1370 pix->sizeimage = pix->height * pix->bytesperline * 3 / 2;
1430 break; 1371 break;
1431 default: 1372 default:
1432 pix->bytesperline = pix->width * f->bpp; 1373 pix->sizeimage = pix->height * pix->bytesperline;
1433 break; 1374 break;
1434 } 1375 }
1435 pix->sizeimage = pix->height * pix->bytesperline; 1376 pix->colorspace = V4L2_COLORSPACE_SRGB;
1436 return ret; 1377 return ret;
1437} 1378}
1438 1379
1439static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv, 1380static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
1440 struct v4l2_format *fmt) 1381 struct v4l2_format *fmt)
1441{ 1382{
1442 struct mcam_camera *cam = priv; 1383 struct mcam_camera *cam = video_drvdata(filp);
1443 struct mcam_format_struct *f; 1384 struct mcam_format_struct *f;
1444 int ret; 1385 int ret;
1445 1386
@@ -1447,7 +1388,7 @@ static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
1447 * Can't do anything if the device is not idle 1388 * Can't do anything if the device is not idle
1448 * Also can't if there are streaming buffers in place. 1389 * Also can't if there are streaming buffers in place.
1449 */ 1390 */
1450 if (cam->state != S_IDLE || cam->vb_queue.num_buffers > 0) 1391 if (cam->state != S_IDLE || vb2_is_busy(&cam->vb_queue))
1451 return -EBUSY; 1392 return -EBUSY;
1452 1393
1453 f = mcam_find_format(fmt->fmt.pix.pixelformat); 1394 f = mcam_find_format(fmt->fmt.pix.pixelformat);
@@ -1462,7 +1403,6 @@ static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
1462 * Now we start to change things for real, so let's do it 1403 * Now we start to change things for real, so let's do it
1463 * under lock. 1404 * under lock.
1464 */ 1405 */
1465 mutex_lock(&cam->s_mutex);
1466 cam->pix_format = fmt->fmt.pix; 1406 cam->pix_format = fmt->fmt.pix;
1467 cam->mbus_code = f->mbus_code; 1407 cam->mbus_code = f->mbus_code;
1468 1408
@@ -1476,7 +1416,6 @@ static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
1476 } 1416 }
1477 mcam_set_config_needed(cam, 1); 1417 mcam_set_config_needed(cam, 1);
1478out: 1418out:
1479 mutex_unlock(&cam->s_mutex);
1480 return ret; 1419 return ret;
1481} 1420}
1482 1421
@@ -1488,7 +1427,7 @@ out:
1488static int mcam_vidioc_g_fmt_vid_cap(struct file *filp, void *priv, 1427static int mcam_vidioc_g_fmt_vid_cap(struct file *filp, void *priv,
1489 struct v4l2_format *f) 1428 struct v4l2_format *f)
1490{ 1429{
1491 struct mcam_camera *cam = priv; 1430 struct mcam_camera *cam = video_drvdata(filp);
1492 1431
1493 f->fmt.pix = cam->pix_format; 1432 f->fmt.pix = cam->pix_format;
1494 return 0; 1433 return 0;
@@ -1504,7 +1443,6 @@ static int mcam_vidioc_enum_input(struct file *filp, void *priv,
1504 return -EINVAL; 1443 return -EINVAL;
1505 1444
1506 input->type = V4L2_INPUT_TYPE_CAMERA; 1445 input->type = V4L2_INPUT_TYPE_CAMERA;
1507 input->std = V4L2_STD_ALL; /* Not sure what should go here */
1508 strcpy(input->name, "Camera"); 1446 strcpy(input->name, "Camera");
1509 return 0; 1447 return 0;
1510} 1448}
@@ -1522,18 +1460,6 @@ static int mcam_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
1522 return 0; 1460 return 0;
1523} 1461}
1524 1462
1525/* from vivi.c */
1526static int mcam_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id a)
1527{
1528 return 0;
1529}
1530
1531static int mcam_vidioc_g_std(struct file *filp, void *priv, v4l2_std_id *a)
1532{
1533 *a = V4L2_STD_NTSC_M;
1534 return 0;
1535}
1536
1537/* 1463/*
1538 * G/S_PARM. Most of this is done by the sensor, but we are 1464 * G/S_PARM. Most of this is done by the sensor, but we are
1539 * the level which controls the number of read buffers. 1465 * the level which controls the number of read buffers.
@@ -1541,12 +1467,10 @@ static int mcam_vidioc_g_std(struct file *filp, void *priv, v4l2_std_id *a)
1541static int mcam_vidioc_g_parm(struct file *filp, void *priv, 1467static int mcam_vidioc_g_parm(struct file *filp, void *priv,
1542 struct v4l2_streamparm *parms) 1468 struct v4l2_streamparm *parms)
1543{ 1469{
1544 struct mcam_camera *cam = priv; 1470 struct mcam_camera *cam = video_drvdata(filp);
1545 int ret; 1471 int ret;
1546 1472
1547 mutex_lock(&cam->s_mutex);
1548 ret = sensor_call(cam, video, g_parm, parms); 1473 ret = sensor_call(cam, video, g_parm, parms);
1549 mutex_unlock(&cam->s_mutex);
1550 parms->parm.capture.readbuffers = n_dma_bufs; 1474 parms->parm.capture.readbuffers = n_dma_bufs;
1551 return ret; 1475 return ret;
1552} 1476}
@@ -1554,12 +1478,10 @@ static int mcam_vidioc_g_parm(struct file *filp, void *priv,
1554static int mcam_vidioc_s_parm(struct file *filp, void *priv, 1478static int mcam_vidioc_s_parm(struct file *filp, void *priv,
1555 struct v4l2_streamparm *parms) 1479 struct v4l2_streamparm *parms)
1556{ 1480{
1557 struct mcam_camera *cam = priv; 1481 struct mcam_camera *cam = video_drvdata(filp);
1558 int ret; 1482 int ret;
1559 1483
1560 mutex_lock(&cam->s_mutex);
1561 ret = sensor_call(cam, video, s_parm, parms); 1484 ret = sensor_call(cam, video, s_parm, parms);
1562 mutex_unlock(&cam->s_mutex);
1563 parms->parm.capture.readbuffers = n_dma_bufs; 1485 parms->parm.capture.readbuffers = n_dma_bufs;
1564 return ret; 1486 return ret;
1565} 1487}
@@ -1567,7 +1489,7 @@ static int mcam_vidioc_s_parm(struct file *filp, void *priv,
1567static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv, 1489static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv,
1568 struct v4l2_frmsizeenum *sizes) 1490 struct v4l2_frmsizeenum *sizes)
1569{ 1491{
1570 struct mcam_camera *cam = priv; 1492 struct mcam_camera *cam = video_drvdata(filp);
1571 struct mcam_format_struct *f; 1493 struct mcam_format_struct *f;
1572 struct v4l2_subdev_frame_size_enum fse = { 1494 struct v4l2_subdev_frame_size_enum fse = {
1573 .index = sizes->index, 1495 .index = sizes->index,
@@ -1579,9 +1501,7 @@ static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv,
1579 if (f->pixelformat != sizes->pixel_format) 1501 if (f->pixelformat != sizes->pixel_format)
1580 return -EINVAL; 1502 return -EINVAL;
1581 fse.code = f->mbus_code; 1503 fse.code = f->mbus_code;
1582 mutex_lock(&cam->s_mutex);
1583 ret = sensor_call(cam, pad, enum_frame_size, NULL, &fse); 1504 ret = sensor_call(cam, pad, enum_frame_size, NULL, &fse);
1584 mutex_unlock(&cam->s_mutex);
1585 if (ret) 1505 if (ret)
1586 return ret; 1506 return ret;
1587 if (fse.min_width == fse.max_width && 1507 if (fse.min_width == fse.max_width &&
@@ -1604,7 +1524,7 @@ static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv,
1604static int mcam_vidioc_enum_frameintervals(struct file *filp, void *priv, 1524static int mcam_vidioc_enum_frameintervals(struct file *filp, void *priv,
1605 struct v4l2_frmivalenum *interval) 1525 struct v4l2_frmivalenum *interval)
1606{ 1526{
1607 struct mcam_camera *cam = priv; 1527 struct mcam_camera *cam = video_drvdata(filp);
1608 struct mcam_format_struct *f; 1528 struct mcam_format_struct *f;
1609 struct v4l2_subdev_frame_interval_enum fie = { 1529 struct v4l2_subdev_frame_interval_enum fie = {
1610 .index = interval->index, 1530 .index = interval->index,
@@ -1618,9 +1538,7 @@ static int mcam_vidioc_enum_frameintervals(struct file *filp, void *priv,
1618 if (f->pixelformat != interval->pixel_format) 1538 if (f->pixelformat != interval->pixel_format)
1619 return -EINVAL; 1539 return -EINVAL;
1620 fie.code = f->mbus_code; 1540 fie.code = f->mbus_code;
1621 mutex_lock(&cam->s_mutex);
1622 ret = sensor_call(cam, pad, enum_frame_interval, NULL, &fie); 1541 ret = sensor_call(cam, pad, enum_frame_interval, NULL, &fie);
1623 mutex_unlock(&cam->s_mutex);
1624 if (ret) 1542 if (ret)
1625 return ret; 1543 return ret;
1626 interval->type = V4L2_FRMIVAL_TYPE_DISCRETE; 1544 interval->type = V4L2_FRMIVAL_TYPE_DISCRETE;
@@ -1632,7 +1550,7 @@ static int mcam_vidioc_enum_frameintervals(struct file *filp, void *priv,
1632static int mcam_vidioc_g_register(struct file *file, void *priv, 1550static int mcam_vidioc_g_register(struct file *file, void *priv,
1633 struct v4l2_dbg_register *reg) 1551 struct v4l2_dbg_register *reg)
1634{ 1552{
1635 struct mcam_camera *cam = priv; 1553 struct mcam_camera *cam = video_drvdata(file);
1636 1554
1637 if (reg->reg > cam->regs_size - 4) 1555 if (reg->reg > cam->regs_size - 4)
1638 return -EINVAL; 1556 return -EINVAL;
@@ -1644,7 +1562,7 @@ static int mcam_vidioc_g_register(struct file *file, void *priv,
1644static int mcam_vidioc_s_register(struct file *file, void *priv, 1562static int mcam_vidioc_s_register(struct file *file, void *priv,
1645 const struct v4l2_dbg_register *reg) 1563 const struct v4l2_dbg_register *reg)
1646{ 1564{
1647 struct mcam_camera *cam = priv; 1565 struct mcam_camera *cam = video_drvdata(file);
1648 1566
1649 if (reg->reg > cam->regs_size - 4) 1567 if (reg->reg > cam->regs_size - 4)
1650 return -EINVAL; 1568 return -EINVAL;
@@ -1662,18 +1580,20 @@ static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
1662 .vidioc_enum_input = mcam_vidioc_enum_input, 1580 .vidioc_enum_input = mcam_vidioc_enum_input,
1663 .vidioc_g_input = mcam_vidioc_g_input, 1581 .vidioc_g_input = mcam_vidioc_g_input,
1664 .vidioc_s_input = mcam_vidioc_s_input, 1582 .vidioc_s_input = mcam_vidioc_s_input,
1665 .vidioc_s_std = mcam_vidioc_s_std, 1583 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1666 .vidioc_g_std = mcam_vidioc_g_std, 1584 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1667 .vidioc_reqbufs = mcam_vidioc_reqbufs, 1585 .vidioc_querybuf = vb2_ioctl_querybuf,
1668 .vidioc_querybuf = mcam_vidioc_querybuf, 1586 .vidioc_qbuf = vb2_ioctl_qbuf,
1669 .vidioc_qbuf = mcam_vidioc_qbuf, 1587 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1670 .vidioc_dqbuf = mcam_vidioc_dqbuf, 1588 .vidioc_expbuf = vb2_ioctl_expbuf,
1671 .vidioc_streamon = mcam_vidioc_streamon, 1589 .vidioc_streamon = vb2_ioctl_streamon,
1672 .vidioc_streamoff = mcam_vidioc_streamoff, 1590 .vidioc_streamoff = vb2_ioctl_streamoff,
1673 .vidioc_g_parm = mcam_vidioc_g_parm, 1591 .vidioc_g_parm = mcam_vidioc_g_parm,
1674 .vidioc_s_parm = mcam_vidioc_s_parm, 1592 .vidioc_s_parm = mcam_vidioc_s_parm,
1675 .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes, 1593 .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes,
1676 .vidioc_enum_frameintervals = mcam_vidioc_enum_frameintervals, 1594 .vidioc_enum_frameintervals = mcam_vidioc_enum_frameintervals,
1595 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1596 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1677#ifdef CONFIG_VIDEO_ADV_DEBUG 1597#ifdef CONFIG_VIDEO_ADV_DEBUG
1678 .vidioc_g_register = mcam_vidioc_g_register, 1598 .vidioc_g_register = mcam_vidioc_g_register,
1679 .vidioc_s_register = mcam_vidioc_s_register, 1599 .vidioc_s_register = mcam_vidioc_s_register,
@@ -1687,43 +1607,36 @@ static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
1687static int mcam_v4l_open(struct file *filp) 1607static int mcam_v4l_open(struct file *filp)
1688{ 1608{
1689 struct mcam_camera *cam = video_drvdata(filp); 1609 struct mcam_camera *cam = video_drvdata(filp);
1690 int ret = 0; 1610 int ret;
1691
1692 filp->private_data = cam;
1693 1611
1694 cam->frame_state.frames = 0;
1695 cam->frame_state.singles = 0;
1696 cam->frame_state.delivered = 0;
1697 mutex_lock(&cam->s_mutex); 1612 mutex_lock(&cam->s_mutex);
1698 if (cam->users == 0) { 1613 ret = v4l2_fh_open(filp);
1699 ret = mcam_setup_vb2(cam); 1614 if (ret)
1700 if (ret) 1615 goto out;
1701 goto out; 1616 if (v4l2_fh_is_singular_file(filp)) {
1702 ret = mcam_ctlr_power_up(cam); 1617 ret = mcam_ctlr_power_up(cam);
1703 if (ret) 1618 if (ret)
1704 goto out; 1619 goto out;
1705 __mcam_cam_reset(cam); 1620 __mcam_cam_reset(cam);
1706 mcam_set_config_needed(cam, 1); 1621 mcam_set_config_needed(cam, 1);
1707 } 1622 }
1708 (cam->users)++;
1709out: 1623out:
1710 mutex_unlock(&cam->s_mutex); 1624 mutex_unlock(&cam->s_mutex);
1625 if (ret)
1626 v4l2_fh_release(filp);
1711 return ret; 1627 return ret;
1712} 1628}
1713 1629
1714 1630
1715static int mcam_v4l_release(struct file *filp) 1631static int mcam_v4l_release(struct file *filp)
1716{ 1632{
1717 struct mcam_camera *cam = filp->private_data; 1633 struct mcam_camera *cam = video_drvdata(filp);
1634 bool last_open;
1718 1635
1719 cam_dbg(cam, "Release, %d frames, %d singles, %d delivered\n",
1720 cam->frame_state.frames, cam->frame_state.singles,
1721 cam->frame_state.delivered);
1722 mutex_lock(&cam->s_mutex); 1636 mutex_lock(&cam->s_mutex);
1723 (cam->users)--; 1637 last_open = v4l2_fh_is_singular_file(filp);
1724 if (cam->users == 0) { 1638 _vb2_fop_release(filp, NULL);
1725 mcam_ctlr_stop_dma(cam); 1639 if (last_open) {
1726 mcam_cleanup_vb2(cam);
1727 mcam_disable_mipi(cam); 1640 mcam_disable_mipi(cam);
1728 mcam_ctlr_power_down(cam); 1641 mcam_ctlr_power_down(cam);
1729 if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read) 1642 if (cam->buffer_mode == B_vmalloc && alloc_bufs_at_read)
@@ -1734,54 +1647,13 @@ static int mcam_v4l_release(struct file *filp)
1734 return 0; 1647 return 0;
1735} 1648}
1736 1649
1737static ssize_t mcam_v4l_read(struct file *filp,
1738 char __user *buffer, size_t len, loff_t *pos)
1739{
1740 struct mcam_camera *cam = filp->private_data;
1741 int ret;
1742
1743 mutex_lock(&cam->s_mutex);
1744 ret = vb2_read(&cam->vb_queue, buffer, len, pos,
1745 filp->f_flags & O_NONBLOCK);
1746 mutex_unlock(&cam->s_mutex);
1747 return ret;
1748}
1749
1750
1751
1752static unsigned int mcam_v4l_poll(struct file *filp,
1753 struct poll_table_struct *pt)
1754{
1755 struct mcam_camera *cam = filp->private_data;
1756 int ret;
1757
1758 mutex_lock(&cam->s_mutex);
1759 ret = vb2_poll(&cam->vb_queue, filp, pt);
1760 mutex_unlock(&cam->s_mutex);
1761 return ret;
1762}
1763
1764
1765static int mcam_v4l_mmap(struct file *filp, struct vm_area_struct *vma)
1766{
1767 struct mcam_camera *cam = filp->private_data;
1768 int ret;
1769
1770 mutex_lock(&cam->s_mutex);
1771 ret = vb2_mmap(&cam->vb_queue, vma);
1772 mutex_unlock(&cam->s_mutex);
1773 return ret;
1774}
1775
1776
1777
1778static const struct v4l2_file_operations mcam_v4l_fops = { 1650static const struct v4l2_file_operations mcam_v4l_fops = {
1779 .owner = THIS_MODULE, 1651 .owner = THIS_MODULE,
1780 .open = mcam_v4l_open, 1652 .open = mcam_v4l_open,
1781 .release = mcam_v4l_release, 1653 .release = mcam_v4l_release,
1782 .read = mcam_v4l_read, 1654 .read = vb2_fop_read,
1783 .poll = mcam_v4l_poll, 1655 .poll = vb2_fop_poll,
1784 .mmap = mcam_v4l_mmap, 1656 .mmap = vb2_fop_mmap,
1785 .unlocked_ioctl = video_ioctl2, 1657 .unlocked_ioctl = video_ioctl2,
1786}; 1658};
1787 1659
@@ -1792,8 +1664,6 @@ static const struct v4l2_file_operations mcam_v4l_fops = {
1792 */ 1664 */
1793static struct video_device mcam_v4l_template = { 1665static struct video_device mcam_v4l_template = {
1794 .name = "mcam", 1666 .name = "mcam",
1795 .tvnorms = V4L2_STD_NTSC_M,
1796
1797 .fops = &mcam_v4l_fops, 1667 .fops = &mcam_v4l_fops,
1798 .ioctl_ops = &mcam_v4l_ioctl_ops, 1668 .ioctl_ops = &mcam_v4l_ioctl_ops,
1799 .release = video_device_release_empty, 1669 .release = video_device_release_empty,
@@ -1811,7 +1681,7 @@ static void mcam_frame_complete(struct mcam_camera *cam, int frame)
1811 set_bit(frame, &cam->flags); 1681 set_bit(frame, &cam->flags);
1812 clear_bit(CF_DMA_ACTIVE, &cam->flags); 1682 clear_bit(CF_DMA_ACTIVE, &cam->flags);
1813 cam->next_buf = frame; 1683 cam->next_buf = frame;
1814 cam->buf_seq[frame] = ++(cam->sequence); 1684 cam->buf_seq[frame] = cam->sequence++;
1815 cam->frame_state.frames++; 1685 cam->frame_state.frames++;
1816 /* 1686 /*
1817 * "This should never happen" 1687 * "This should never happen"
@@ -1924,10 +1794,17 @@ int mccic_register(struct mcam_camera *cam)
1924 mcam_set_config_needed(cam, 1); 1794 mcam_set_config_needed(cam, 1);
1925 cam->pix_format = mcam_def_pix_format; 1795 cam->pix_format = mcam_def_pix_format;
1926 cam->mbus_code = mcam_def_mbus_code; 1796 cam->mbus_code = mcam_def_mbus_code;
1927 INIT_LIST_HEAD(&cam->buffers);
1928 mcam_ctlr_init(cam); 1797 mcam_ctlr_init(cam);
1929 1798
1930 /* 1799 /*
1800 * Get the v4l2 setup done.
1801 */
1802 ret = v4l2_ctrl_handler_init(&cam->ctrl_handler, 10);
1803 if (ret)
1804 goto out_unregister;
1805 cam->v4l2_dev.ctrl_handler = &cam->ctrl_handler;
1806
1807 /*
1931 * Try to find the sensor. 1808 * Try to find the sensor.
1932 */ 1809 */
1933 sensor_cfg.clock_speed = cam->clock_speed; 1810 sensor_cfg.clock_speed = cam->clock_speed;
@@ -1943,21 +1820,22 @@ int mccic_register(struct mcam_camera *cam)
1943 ret = mcam_cam_init(cam); 1820 ret = mcam_cam_init(cam);
1944 if (ret) 1821 if (ret)
1945 goto out_unregister; 1822 goto out_unregister;
1946 /* 1823
1947 * Get the v4l2 setup done. 1824 ret = mcam_setup_vb2(cam);
1948 */
1949 ret = v4l2_ctrl_handler_init(&cam->ctrl_handler, 10);
1950 if (ret) 1825 if (ret)
1951 goto out_unregister; 1826 goto out_unregister;
1952 cam->v4l2_dev.ctrl_handler = &cam->ctrl_handler;
1953 1827
1954 mutex_lock(&cam->s_mutex); 1828 mutex_lock(&cam->s_mutex);
1955 cam->vdev = mcam_v4l_template; 1829 cam->vdev = mcam_v4l_template;
1956 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1830 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1831 cam->vdev.lock = &cam->s_mutex;
1832 cam->vdev.queue = &cam->vb_queue;
1957 video_set_drvdata(&cam->vdev, cam); 1833 video_set_drvdata(&cam->vdev, cam);
1958 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); 1834 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
1959 if (ret) 1835 if (ret) {
1960 goto out; 1836 mutex_unlock(&cam->s_mutex);
1837 goto out_unregister;
1838 }
1961 1839
1962 /* 1840 /*
1963 * If so requested, try to get our DMA buffers now. 1841 * If so requested, try to get our DMA buffers now.
@@ -1968,11 +1846,11 @@ int mccic_register(struct mcam_camera *cam)
1968 " will try again later."); 1846 " will try again later.");
1969 } 1847 }
1970 1848
1971out:
1972 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1973 mutex_unlock(&cam->s_mutex); 1849 mutex_unlock(&cam->s_mutex);
1974 return ret; 1850 return 0;
1851
1975out_unregister: 1852out_unregister:
1853 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1976 v4l2_device_unregister(&cam->v4l2_dev); 1854 v4l2_device_unregister(&cam->v4l2_dev);
1977 return ret; 1855 return ret;
1978} 1856}
@@ -1986,11 +1864,11 @@ void mccic_shutdown(struct mcam_camera *cam)
1986 * take it down again will wedge the machine, which is frowned 1864 * take it down again will wedge the machine, which is frowned
1987 * upon. 1865 * upon.
1988 */ 1866 */
1989 if (cam->users > 0) { 1867 if (!list_empty(&cam->vdev.fh_list)) {
1990 cam_warn(cam, "Removing a device with users!\n"); 1868 cam_warn(cam, "Removing a device with users!\n");
1991 mcam_ctlr_power_down(cam); 1869 mcam_ctlr_power_down(cam);
1992 } 1870 }
1993 vb2_queue_release(&cam->vb_queue); 1871 mcam_cleanup_vb2(cam);
1994 if (cam->buffer_mode == B_vmalloc) 1872 if (cam->buffer_mode == B_vmalloc)
1995 mcam_free_dma_bufs(cam); 1873 mcam_free_dma_bufs(cam);
1996 video_unregister_device(&cam->vdev); 1874 video_unregister_device(&cam->vdev);
@@ -2006,7 +1884,7 @@ void mccic_shutdown(struct mcam_camera *cam)
2006void mccic_suspend(struct mcam_camera *cam) 1884void mccic_suspend(struct mcam_camera *cam)
2007{ 1885{
2008 mutex_lock(&cam->s_mutex); 1886 mutex_lock(&cam->s_mutex);
2009 if (cam->users > 0) { 1887 if (!list_empty(&cam->vdev.fh_list)) {
2010 enum mcam_state cstate = cam->state; 1888 enum mcam_state cstate = cam->state;
2011 1889
2012 mcam_ctlr_stop_dma(cam); 1890 mcam_ctlr_stop_dma(cam);
@@ -2021,7 +1899,7 @@ int mccic_resume(struct mcam_camera *cam)
2021 int ret = 0; 1899 int ret = 0;
2022 1900
2023 mutex_lock(&cam->s_mutex); 1901 mutex_lock(&cam->s_mutex);
2024 if (cam->users > 0) { 1902 if (!list_empty(&cam->vdev.fh_list)) {
2025 ret = mcam_ctlr_power_up(cam); 1903 ret = mcam_ctlr_power_up(cam);
2026 if (ret) { 1904 if (ret) {
2027 mutex_unlock(&cam->s_mutex); 1905 mutex_unlock(&cam->s_mutex);
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index 7ffdf4dbaf8c..97167f6ffd1e 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -146,7 +146,6 @@ struct mcam_camera {
146 struct v4l2_ctrl_handler ctrl_handler; 146 struct v4l2_ctrl_handler ctrl_handler;
147 enum mcam_state state; 147 enum mcam_state state;
148 unsigned long flags; /* Buffer status, mainly (dev_lock) */ 148 unsigned long flags; /* Buffer status, mainly (dev_lock) */
149 int users; /* How many open FDs */
150 149
151 struct mcam_frame_state frame_state; /* Frame state counter */ 150 struct mcam_frame_state frame_state; /* Frame state counter */
152 /* 151 /*
@@ -163,6 +162,8 @@ struct mcam_camera {
163 unsigned int nbufs; /* How many are alloc'd */ 162 unsigned int nbufs; /* How many are alloc'd */
164 int next_buf; /* Next to consume (dev_lock) */ 163 int next_buf; /* Next to consume (dev_lock) */
165 164
165 char bus_info[32]; /* querycap bus_info */
166
166 /* DMA buffers - vmalloc mode */ 167 /* DMA buffers - vmalloc mode */
167#ifdef MCAM_MODE_VMALLOC 168#ifdef MCAM_MODE_VMALLOC
168 unsigned int dma_buf_size; /* allocated size */ 169 unsigned int dma_buf_size; /* allocated size */
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index 0ed9b3adfcdf..b5f165a68566 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -371,6 +371,7 @@ static int mmpcam_probe(struct platform_device *pdev)
371 mcam->lane = pdata->lane; 371 mcam->lane = pdata->lane;
372 mcam->chip_id = MCAM_ARMADA610; 372 mcam->chip_id = MCAM_ARMADA610;
373 mcam->buffer_mode = B_DMA_sg; 373 mcam->buffer_mode = B_DMA_sg;
374 strlcpy(mcam->bus_info, "platform:mmp-camera", sizeof(mcam->bus_info));
374 spin_lock_init(&mcam->dev_lock); 375 spin_lock_init(&mcam->dev_lock);
375 /* 376 /*
376 * Get our I/O memory. 377 * Get our I/O memory.
diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
index 17b189a81ec5..f09c5f17a42f 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -445,7 +445,7 @@ static int omapvid_init(struct omap_vout_device *vout, u32 addr)
445 int ret = 0, i; 445 int ret = 0, i;
446 struct v4l2_window *win; 446 struct v4l2_window *win;
447 struct omap_overlay *ovl; 447 struct omap_overlay *ovl;
448 int posx, posy, outw, outh, temp; 448 int posx, posy, outw, outh;
449 struct omap_video_timings *timing; 449 struct omap_video_timings *timing;
450 struct omapvideo_info *ovid = &vout->vid_info; 450 struct omapvideo_info *ovid = &vout->vid_info;
451 451
@@ -468,9 +468,7 @@ static int omapvid_init(struct omap_vout_device *vout, u32 addr)
468 /* Invert the height and width for 90 468 /* Invert the height and width for 90
469 * and 270 degree rotation 469 * and 270 degree rotation
470 */ 470 */
471 temp = outw; 471 swap(outw, outh);
472 outw = outh;
473 outh = temp;
474 posy = (timing->y_res - win->w.width) - win->w.left; 472 posy = (timing->y_res - win->w.width) - win->w.left;
475 posx = win->w.top; 473 posx = win->w.top;
476 break; 474 break;
@@ -481,9 +479,7 @@ static int omapvid_init(struct omap_vout_device *vout, u32 addr)
481 break; 479 break;
482 480
483 case dss_rotation_270_degree: 481 case dss_rotation_270_degree:
484 temp = outw; 482 swap(outw, outh);
485 outw = outh;
486 outh = temp;
487 posy = win->w.left; 483 posy = win->w.left;
488 posx = (timing->x_res - win->w.height) - win->w.top; 484 posx = (timing->x_res - win->w.height) - win->w.top;
489 break; 485 break;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index 15cb254ccc39..13803270d104 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -929,14 +929,10 @@ static void preview_setup_hw(struct isp_prev_device *prev, u32 update,
929 u32 active) 929 u32 active)
930{ 930{
931 unsigned int i; 931 unsigned int i;
932 u32 features;
933 932
934 if (update == 0) 933 if (update == 0)
935 return; 934 return;
936 935
937 features = (prev->params.params[0].features & active)
938 | (prev->params.params[1].features & ~active);
939
940 for (i = 0; i < ARRAY_SIZE(update_attrs); i++) { 936 for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
941 const struct preview_update *attr = &update_attrs[i]; 937 const struct preview_update *attr = &update_attrs[i];
942 struct prev_params *params; 938 struct prev_params *params;
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index f6a61b9ceff4..76e6289a5612 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -115,7 +115,7 @@ static int sensor_set_power(struct camif_dev *camif, int on)
115 struct cam_sensor *sensor = &camif->sensor; 115 struct cam_sensor *sensor = &camif->sensor;
116 int err = 0; 116 int err = 0;
117 117
118 if (!on == camif->sensor.power_count) 118 if (camif->sensor.power_count == !on)
119 err = v4l2_subdev_call(sensor->sd, core, s_power, on); 119 err = v4l2_subdev_call(sensor->sd, core, s_power, on);
120 if (!err) 120 if (!err)
121 sensor->power_count += on ? 1 : -1; 121 sensor->power_count += on ? 1 : -1;
@@ -131,7 +131,7 @@ static int sensor_set_streaming(struct camif_dev *camif, int on)
131 struct cam_sensor *sensor = &camif->sensor; 131 struct cam_sensor *sensor = &camif->sensor;
132 int err = 0; 132 int err = 0;
133 133
134 if (!on == camif->sensor.stream_count) 134 if (camif->sensor.stream_count == !on)
135 err = v4l2_subdev_call(sensor->sd, video, s_stream, on); 135 err = v4l2_subdev_call(sensor->sd, video, s_stream, on);
136 if (!err) 136 if (!err)
137 sensor->stream_count += on ? 1 : -1; 137 sensor->stream_count += on ? 1 : -1;
@@ -449,19 +449,22 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
449 struct camif_vp *vp = vb2_get_drv_priv(vq); 449 struct camif_vp *vp = vb2_get_drv_priv(vq);
450 struct camif_dev *camif = vp->camif; 450 struct camif_dev *camif = vp->camif;
451 struct camif_frame *frame = &vp->out_frame; 451 struct camif_frame *frame = &vp->out_frame;
452 const struct camif_fmt *fmt = vp->out_fmt; 452 const struct camif_fmt *fmt;
453 unsigned int size; 453 unsigned int size;
454 454
455 if (pfmt) { 455 if (pfmt) {
456 pix = &pfmt->fmt.pix; 456 pix = &pfmt->fmt.pix;
457 fmt = s3c_camif_find_format(vp, &pix->pixelformat, -1); 457 fmt = s3c_camif_find_format(vp, &pix->pixelformat, -1);
458 if (fmt == NULL)
459 return -EINVAL;
458 size = (pix->width * pix->height * fmt->depth) / 8; 460 size = (pix->width * pix->height * fmt->depth) / 8;
459 } else { 461 } else {
462 fmt = vp->out_fmt;
463 if (fmt == NULL)
464 return -EINVAL;
460 size = (frame->f_width * frame->f_height * fmt->depth) / 8; 465 size = (frame->f_width * frame->f_height * fmt->depth) / 8;
461 } 466 }
462 467
463 if (fmt == NULL)
464 return -EINVAL;
465 *num_planes = 1; 468 *num_planes = 1;
466 469
467 if (pix) 470 if (pix)
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index 2d5bd3ac7f81..f47b332f0418 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -628,7 +628,7 @@ static struct s3c_camif_drvdata s3c6410_camif_drvdata = {
628 .bus_clk_freq = 133000000UL, 628 .bus_clk_freq = 133000000UL,
629}; 629};
630 630
631static struct platform_device_id s3c_camif_driver_ids[] = { 631static const struct platform_device_id s3c_camif_driver_ids[] = {
632 { 632 {
633 .name = "s3c2440-camif", 633 .name = "s3c2440-camif",
634 .driver_data = (unsigned long)&s3c244x_camif_drvdata, 634 .driver_data = (unsigned long)&s3c244x_camif_drvdata,
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index ec3e1248923d..421a7c3b595b 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -787,7 +787,7 @@ static const struct of_device_id exynos_g2d_match[] = {
787}; 787};
788MODULE_DEVICE_TABLE(of, exynos_g2d_match); 788MODULE_DEVICE_TABLE(of, exynos_g2d_match);
789 789
790static struct platform_device_id g2d_driver_ids[] = { 790static const struct platform_device_id g2d_driver_ids[] = {
791 { 791 {
792 .name = "s5p-g2d", 792 .name = "s5p-g2d",
793 .driver_data = (unsigned long)&g2d_drvdata_v3x, 793 .driver_data = (unsigned long)&g2d_drvdata_v3x,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 8333fbc2fe96..8de61dc1e142 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -211,6 +211,7 @@ static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
211 dst_buf->b->v4l2_buf.field = V4L2_FIELD_NONE; 211 dst_buf->b->v4l2_buf.field = V4L2_FIELD_NONE;
212 else 212 else
213 dst_buf->b->v4l2_buf.field = V4L2_FIELD_INTERLACED; 213 dst_buf->b->v4l2_buf.field = V4L2_FIELD_INTERLACED;
214 dst_buf->b->v4l2_buf.flags |= V4L2_BUF_FLAG_LAST;
214 215
215 ctx->dec_dst_flag &= ~(1 << dst_buf->b->v4l2_buf.index); 216 ctx->dec_dst_flag &= ~(1 << dst_buf->b->v4l2_buf.index);
216 vb2_buffer_done(dst_buf->b, VB2_BUF_STATE_DONE); 217 vb2_buffer_done(dst_buf->b, VB2_BUF_STATE_DONE);
@@ -1337,8 +1338,6 @@ static int s5p_mfc_runtime_resume(struct device *dev)
1337 struct platform_device *pdev = to_platform_device(dev); 1338 struct platform_device *pdev = to_platform_device(dev);
1338 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev); 1339 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1339 1340
1340 if (!m_dev->alloc_ctx)
1341 return 0;
1342 atomic_set(&m_dev->pm.power, 1); 1341 atomic_set(&m_dev->pm.power, 1);
1343 return 0; 1342 return 0;
1344} 1343}
@@ -1463,7 +1462,7 @@ static struct s5p_mfc_variant mfc_drvdata_v8 = {
1463 .fw_name[0] = "s5p-mfc-v8.fw", 1462 .fw_name[0] = "s5p-mfc-v8.fw",
1464}; 1463};
1465 1464
1466static struct platform_device_id mfc_driver_ids[] = { 1465static const struct platform_device_id mfc_driver_ids[] = {
1467 { 1466 {
1468 .name = "s5p-mfc", 1467 .name = "s5p-mfc",
1469 .driver_data = (unsigned long)&mfc_drvdata_v5, 1468 .driver_data = (unsigned long)&mfc_drvdata_v5,
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 b09bcd140491..9a923b1a9bac 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -184,7 +184,7 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
184 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_r, &ctx->bank2); 184 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_r, &ctx->bank2);
185 if (ret) { 185 if (ret) {
186 mfc_err("Failed to allocate Bank2 temporary buffer\n"); 186 mfc_err("Failed to allocate Bank2 temporary buffer\n");
187 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1); 187 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
188 return ret; 188 return ret;
189 } 189 }
190 BUG_ON(ctx->bank2.dma & ((1 << MFC_BANK2_ALIGN_ORDER) - 1)); 190 BUG_ON(ctx->bank2.dma & ((1 << MFC_BANK2_ALIGN_ORDER) - 1));
@@ -263,7 +263,7 @@ static void s5p_mfc_release_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
263static void s5p_mfc_write_info_v5(struct s5p_mfc_ctx *ctx, unsigned int data, 263static void s5p_mfc_write_info_v5(struct s5p_mfc_ctx *ctx, unsigned int data,
264 unsigned int ofs) 264 unsigned int ofs)
265{ 265{
266 writel(data, (void *)(ctx->shm.virt + ofs)); 266 *(u32 *)(ctx->shm.virt + ofs) = data;
267 wmb(); 267 wmb();
268} 268}
269 269
@@ -271,7 +271,7 @@ static unsigned int s5p_mfc_read_info_v5(struct s5p_mfc_ctx *ctx,
271 unsigned long ofs) 271 unsigned long ofs)
272{ 272{
273 rmb(); 273 rmb();
274 return readl((void *)(ctx->shm.virt + ofs)); 274 return *(u32 *)(ctx->shm.virt + ofs);
275} 275}
276 276
277static void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx *ctx) 277static void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx *ctx)
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 cefad184fe96..12497f5ed8e9 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1852,7 +1852,7 @@ static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
1852 unsigned int ofs) 1852 unsigned int ofs)
1853{ 1853{
1854 s5p_mfc_clock_on(); 1854 s5p_mfc_clock_on();
1855 writel(data, (void *)((unsigned long)ofs)); 1855 writel(data, (void __iomem *)((unsigned long)ofs));
1856 s5p_mfc_clock_off(); 1856 s5p_mfc_clock_off();
1857} 1857}
1858 1858
@@ -1862,7 +1862,7 @@ s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned long ofs)
1862 int ret; 1862 int ret;
1863 1863
1864 s5p_mfc_clock_on(); 1864 s5p_mfc_clock_on();
1865 ret = readl((void *)ofs); 1865 ret = readl((void __iomem *)ofs);
1866 s5p_mfc_clock_off(); 1866 s5p_mfc_clock_off();
1867 1867
1868 return ret; 1868 return ret;
diff --git a/drivers/media/platform/s5p-tv/hdmi_drv.c b/drivers/media/platform/s5p-tv/hdmi_drv.c
index 0e74aabf5f9a..79940757b34f 100644
--- a/drivers/media/platform/s5p-tv/hdmi_drv.c
+++ b/drivers/media/platform/s5p-tv/hdmi_drv.c
@@ -96,7 +96,7 @@ struct hdmi_device {
96 struct hdmi_resources res; 96 struct hdmi_resources res;
97}; 97};
98 98
99static struct platform_device_id hdmi_driver_types[] = { 99static const struct platform_device_id hdmi_driver_types[] = {
100 { 100 {
101 .name = "s5pv210-hdmi", 101 .name = "s5pv210-hdmi",
102 }, { 102 }, {
@@ -648,15 +648,20 @@ static int hdmi_g_dv_timings(struct v4l2_subdev *sd,
648 return 0; 648 return 0;
649} 649}
650 650
651static int hdmi_g_mbus_fmt(struct v4l2_subdev *sd, 651static int hdmi_get_fmt(struct v4l2_subdev *sd,
652 struct v4l2_mbus_framefmt *fmt) 652 struct v4l2_subdev_pad_config *cfg,
653 struct v4l2_subdev_format *format)
653{ 654{
655 struct v4l2_mbus_framefmt *fmt = &format->format;
654 struct hdmi_device *hdev = sd_to_hdmi_dev(sd); 656 struct hdmi_device *hdev = sd_to_hdmi_dev(sd);
655 const struct hdmi_timings *t = hdev->cur_conf; 657 const struct hdmi_timings *t = hdev->cur_conf;
656 658
657 dev_dbg(hdev->dev, "%s\n", __func__); 659 dev_dbg(hdev->dev, "%s\n", __func__);
658 if (!hdev->cur_conf) 660 if (!hdev->cur_conf)
659 return -EINVAL; 661 return -EINVAL;
662 if (format->pad)
663 return -EINVAL;
664
660 memset(fmt, 0, sizeof(*fmt)); 665 memset(fmt, 0, sizeof(*fmt));
661 fmt->width = t->hact.end - t->hact.beg; 666 fmt->width = t->hact.end - t->hact.beg;
662 fmt->height = t->vact[0].end - t->vact[0].beg; 667 fmt->height = t->vact[0].end - t->vact[0].beg;
@@ -712,18 +717,19 @@ static const struct v4l2_subdev_core_ops hdmi_sd_core_ops = {
712static const struct v4l2_subdev_video_ops hdmi_sd_video_ops = { 717static const struct v4l2_subdev_video_ops hdmi_sd_video_ops = {
713 .s_dv_timings = hdmi_s_dv_timings, 718 .s_dv_timings = hdmi_s_dv_timings,
714 .g_dv_timings = hdmi_g_dv_timings, 719 .g_dv_timings = hdmi_g_dv_timings,
715 .g_mbus_fmt = hdmi_g_mbus_fmt,
716 .s_stream = hdmi_s_stream, 720 .s_stream = hdmi_s_stream,
717}; 721};
718 722
719static const struct v4l2_subdev_pad_ops hdmi_sd_pad_ops = { 723static const struct v4l2_subdev_pad_ops hdmi_sd_pad_ops = {
720 .enum_dv_timings = hdmi_enum_dv_timings, 724 .enum_dv_timings = hdmi_enum_dv_timings,
721 .dv_timings_cap = hdmi_dv_timings_cap, 725 .dv_timings_cap = hdmi_dv_timings_cap,
726 .get_fmt = hdmi_get_fmt,
722}; 727};
723 728
724static const struct v4l2_subdev_ops hdmi_sd_ops = { 729static const struct v4l2_subdev_ops hdmi_sd_ops = {
725 .core = &hdmi_sd_core_ops, 730 .core = &hdmi_sd_core_ops,
726 .video = &hdmi_sd_video_ops, 731 .video = &hdmi_sd_video_ops,
732 .pad = &hdmi_sd_pad_ops,
727}; 733};
728 734
729static int hdmi_runtime_suspend(struct device *dev) 735static int hdmi_runtime_suspend(struct device *dev)
diff --git a/drivers/media/platform/s5p-tv/mixer_drv.c b/drivers/media/platform/s5p-tv/mixer_drv.c
index 2a9501d7e7c8..5ef67774971d 100644
--- a/drivers/media/platform/s5p-tv/mixer_drv.c
+++ b/drivers/media/platform/s5p-tv/mixer_drv.c
@@ -46,11 +46,15 @@ void mxr_get_mbus_fmt(struct mxr_device *mdev,
46 struct v4l2_mbus_framefmt *mbus_fmt) 46 struct v4l2_mbus_framefmt *mbus_fmt)
47{ 47{
48 struct v4l2_subdev *sd; 48 struct v4l2_subdev *sd;
49 struct v4l2_subdev_format fmt = {
50 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
51 };
49 int ret; 52 int ret;
50 53
51 mutex_lock(&mdev->mutex); 54 mutex_lock(&mdev->mutex);
52 sd = to_outsd(mdev); 55 sd = to_outsd(mdev);
53 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, mbus_fmt); 56 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
57 *mbus_fmt = fmt.format;
54 WARN(ret, "failed to get mbus_fmt for output %s\n", sd->name); 58 WARN(ret, "failed to get mbus_fmt for output %s\n", sd->name);
55 mutex_unlock(&mdev->mutex); 59 mutex_unlock(&mdev->mutex);
56} 60}
@@ -62,7 +66,10 @@ void mxr_streamer_get(struct mxr_device *mdev)
62 mxr_dbg(mdev, "%s(%d)\n", __func__, mdev->n_streamer); 66 mxr_dbg(mdev, "%s(%d)\n", __func__, mdev->n_streamer);
63 if (mdev->n_streamer == 1) { 67 if (mdev->n_streamer == 1) {
64 struct v4l2_subdev *sd = to_outsd(mdev); 68 struct v4l2_subdev *sd = to_outsd(mdev);
65 struct v4l2_mbus_framefmt mbus_fmt; 69 struct v4l2_subdev_format fmt = {
70 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
71 };
72 struct v4l2_mbus_framefmt *mbus_fmt = &fmt.format;
66 struct mxr_resources *res = &mdev->res; 73 struct mxr_resources *res = &mdev->res;
67 int ret; 74 int ret;
68 75
@@ -72,12 +79,12 @@ void mxr_streamer_get(struct mxr_device *mdev)
72 clk_set_parent(res->sclk_mixer, res->sclk_hdmi); 79 clk_set_parent(res->sclk_mixer, res->sclk_hdmi);
73 mxr_reg_s_output(mdev, to_output(mdev)->cookie); 80 mxr_reg_s_output(mdev, to_output(mdev)->cookie);
74 81
75 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mbus_fmt); 82 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
76 WARN(ret, "failed to get mbus_fmt for output %s\n", sd->name); 83 WARN(ret, "failed to get mbus_fmt for output %s\n", sd->name);
77 ret = v4l2_subdev_call(sd, video, s_stream, 1); 84 ret = v4l2_subdev_call(sd, video, s_stream, 1);
78 WARN(ret, "starting stream failed for output %s\n", sd->name); 85 WARN(ret, "starting stream failed for output %s\n", sd->name);
79 86
80 mxr_reg_set_mbus_fmt(mdev, &mbus_fmt); 87 mxr_reg_set_mbus_fmt(mdev, mbus_fmt);
81 mxr_reg_streamon(mdev); 88 mxr_reg_streamon(mdev);
82 ret = mxr_reg_wait4vsync(mdev); 89 ret = mxr_reg_wait4vsync(mdev);
83 WARN(ret, "failed to get vsync (%d) from output\n", ret); 90 WARN(ret, "failed to get vsync (%d) from output\n", ret);
diff --git a/drivers/media/platform/s5p-tv/sdo_drv.c b/drivers/media/platform/s5p-tv/sdo_drv.c
index 3621af91d460..c75d4354d182 100644
--- a/drivers/media/platform/s5p-tv/sdo_drv.c
+++ b/drivers/media/platform/s5p-tv/sdo_drv.c
@@ -160,13 +160,17 @@ static int sdo_g_std_output(struct v4l2_subdev *sd, v4l2_std_id *std)
160 return 0; 160 return 0;
161} 161}
162 162
163static int sdo_g_mbus_fmt(struct v4l2_subdev *sd, 163static int sdo_get_fmt(struct v4l2_subdev *sd,
164 struct v4l2_mbus_framefmt *fmt) 164 struct v4l2_subdev_pad_config *cfg,
165 struct v4l2_subdev_format *format)
165{ 166{
167 struct v4l2_mbus_framefmt *fmt = &format->format;
166 struct sdo_device *sdev = sd_to_sdev(sd); 168 struct sdo_device *sdev = sd_to_sdev(sd);
167 169
168 if (!sdev->fmt) 170 if (!sdev->fmt)
169 return -ENXIO; 171 return -ENXIO;
172 if (format->pad)
173 return -EINVAL;
170 /* all modes are 720 pixels wide */ 174 /* all modes are 720 pixels wide */
171 fmt->width = 720; 175 fmt->width = 720;
172 fmt->height = sdev->fmt->height; 176 fmt->height = sdev->fmt->height;
@@ -256,13 +260,17 @@ static const struct v4l2_subdev_video_ops sdo_sd_video_ops = {
256 .s_std_output = sdo_s_std_output, 260 .s_std_output = sdo_s_std_output,
257 .g_std_output = sdo_g_std_output, 261 .g_std_output = sdo_g_std_output,
258 .g_tvnorms_output = sdo_g_tvnorms_output, 262 .g_tvnorms_output = sdo_g_tvnorms_output,
259 .g_mbus_fmt = sdo_g_mbus_fmt,
260 .s_stream = sdo_s_stream, 263 .s_stream = sdo_s_stream,
261}; 264};
262 265
266static const struct v4l2_subdev_pad_ops sdo_sd_pad_ops = {
267 .get_fmt = sdo_get_fmt,
268};
269
263static const struct v4l2_subdev_ops sdo_sd_ops = { 270static const struct v4l2_subdev_ops sdo_sd_ops = {
264 .core = &sdo_sd_core_ops, 271 .core = &sdo_sd_core_ops,
265 .video = &sdo_sd_video_ops, 272 .video = &sdo_sd_video_ops,
273 .pad = &sdo_sd_pad_ops,
266}; 274};
267 275
268static int sdo_runtime_suspend(struct device *dev) 276static int sdo_runtime_suspend(struct device *dev)
diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index dde1ccc730be..8b799bae01b8 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -600,7 +600,7 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
600{ 600{
601 unsigned int best_err = UINT_MAX, best = geo->in_width, 601 unsigned int best_err = UINT_MAX, best = geo->in_width,
602 width_max, height_max, img_height_max; 602 width_max, height_max, img_height_max;
603 int i, idx = 0; 603 int i, idx_h = 0, idx_v = 0;
604 604
605 if (std & V4L2_STD_525_60) { 605 if (std & V4L2_STD_525_60) {
606 width_max = 858; 606 width_max = 858;
@@ -625,7 +625,7 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
625 err = abs(found - geo->output.width); 625 err = abs(found - geo->output.width);
626 if (err < best_err) { 626 if (err < best_err) {
627 best_err = err; 627 best_err = err;
628 idx = i; 628 idx_h = i;
629 best = found; 629 best = found;
630 } 630 }
631 if (!err) 631 if (!err)
@@ -633,12 +633,12 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
633 } 633 }
634 634
635 geo->output.width = best; 635 geo->output.width = best;
636 geo->scale_idx_h = idx; 636 geo->scale_idx_h = idx_h;
637 if (geo->output.left + best > width_max) 637 if (geo->output.left + best > width_max)
638 geo->output.left = width_max - best; 638 geo->output.left = width_max - best;
639 639
640 pr_debug("%s(): W %u * %u/%u = %u\n", __func__, geo->in_width, 640 pr_debug("%s(): W %u * %u/%u = %u\n", __func__, geo->in_width,
641 vou_scale_h_num[idx], vou_scale_h_den[idx], best); 641 vou_scale_h_num[idx_h], vou_scale_h_den[idx_h], best);
642 642
643 best_err = UINT_MAX; 643 best_err = UINT_MAX;
644 644
@@ -655,7 +655,7 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
655 err = abs(found - geo->output.height); 655 err = abs(found - geo->output.height);
656 if (err < best_err) { 656 if (err < best_err) {
657 best_err = err; 657 best_err = err;
658 idx = i; 658 idx_v = i;
659 best = found; 659 best = found;
660 } 660 }
661 if (!err) 661 if (!err)
@@ -663,12 +663,12 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
663 } 663 }
664 664
665 geo->output.height = best; 665 geo->output.height = best;
666 geo->scale_idx_v = idx; 666 geo->scale_idx_v = idx_v;
667 if (geo->output.top + best > height_max) 667 if (geo->output.top + best > height_max)
668 geo->output.top = height_max - best; 668 geo->output.top = height_max - best;
669 669
670 pr_debug("%s(): H %u * %u/%u = %u\n", __func__, geo->in_height, 670 pr_debug("%s(): H %u * %u/%u = %u\n", __func__, geo->in_height,
671 vou_scale_v_num[idx], vou_scale_v_den[idx], best); 671 vou_scale_v_num[idx_v], vou_scale_v_den[idx_v], best);
672} 672}
673 673
674static int sh_vou_s_fmt_vid_out(struct file *file, void *priv, 674static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
@@ -679,12 +679,14 @@ static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
679 unsigned int img_height_max; 679 unsigned int img_height_max;
680 int pix_idx; 680 int pix_idx;
681 struct sh_vou_geometry geo; 681 struct sh_vou_geometry geo;
682 struct v4l2_mbus_framefmt mbfmt = { 682 struct v4l2_subdev_format format = {
683 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
683 /* Revisit: is this the correct code? */ 684 /* Revisit: is this the correct code? */
684 .code = MEDIA_BUS_FMT_YUYV8_2X8, 685 .format.code = MEDIA_BUS_FMT_YUYV8_2X8,
685 .field = V4L2_FIELD_INTERLACED, 686 .format.field = V4L2_FIELD_INTERLACED,
686 .colorspace = V4L2_COLORSPACE_SMPTE170M, 687 .format.colorspace = V4L2_COLORSPACE_SMPTE170M,
687 }; 688 };
689 struct v4l2_mbus_framefmt *mbfmt = &format.format;
688 int ret; 690 int ret;
689 691
690 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__, 692 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__,
@@ -720,27 +722,27 @@ static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
720 722
721 vou_adjust_output(&geo, vou_dev->std); 723 vou_adjust_output(&geo, vou_dev->std);
722 724
723 mbfmt.width = geo.output.width; 725 mbfmt->width = geo.output.width;
724 mbfmt.height = geo.output.height; 726 mbfmt->height = geo.output.height;
725 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, 727 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, pad,
726 s_mbus_fmt, &mbfmt); 728 set_fmt, NULL, &format);
727 /* Must be implemented, so, don't check for -ENOIOCTLCMD */ 729 /* Must be implemented, so, don't check for -ENOIOCTLCMD */
728 if (ret < 0) 730 if (ret < 0)
729 return ret; 731 return ret;
730 732
731 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__, 733 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__,
732 geo.output.width, geo.output.height, mbfmt.width, mbfmt.height); 734 geo.output.width, geo.output.height, mbfmt->width, mbfmt->height);
733 735
734 /* Sanity checks */ 736 /* Sanity checks */
735 if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH || 737 if ((unsigned)mbfmt->width > VOU_MAX_IMAGE_WIDTH ||
736 (unsigned)mbfmt.height > img_height_max || 738 (unsigned)mbfmt->height > img_height_max ||
737 mbfmt.code != MEDIA_BUS_FMT_YUYV8_2X8) 739 mbfmt->code != MEDIA_BUS_FMT_YUYV8_2X8)
738 return -EIO; 740 return -EIO;
739 741
740 if (mbfmt.width != geo.output.width || 742 if (mbfmt->width != geo.output.width ||
741 mbfmt.height != geo.output.height) { 743 mbfmt->height != geo.output.height) {
742 geo.output.width = mbfmt.width; 744 geo.output.width = mbfmt->width;
743 geo.output.height = mbfmt.height; 745 geo.output.height = mbfmt->height;
744 746
745 vou_adjust_input(&geo, vou_dev->std); 747 vou_adjust_input(&geo, vou_dev->std);
746 } 748 }
@@ -942,11 +944,12 @@ static int sh_vou_s_crop(struct file *file, void *fh, const struct v4l2_crop *a)
942 struct v4l2_crop sd_crop = {.type = V4L2_BUF_TYPE_VIDEO_OUTPUT}; 944 struct v4l2_crop sd_crop = {.type = V4L2_BUF_TYPE_VIDEO_OUTPUT};
943 struct v4l2_pix_format *pix = &vou_dev->pix; 945 struct v4l2_pix_format *pix = &vou_dev->pix;
944 struct sh_vou_geometry geo; 946 struct sh_vou_geometry geo;
945 struct v4l2_mbus_framefmt mbfmt = { 947 struct v4l2_subdev_format format = {
948 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
946 /* Revisit: is this the correct code? */ 949 /* Revisit: is this the correct code? */
947 .code = MEDIA_BUS_FMT_YUYV8_2X8, 950 .format.code = MEDIA_BUS_FMT_YUYV8_2X8,
948 .field = V4L2_FIELD_INTERLACED, 951 .format.field = V4L2_FIELD_INTERLACED,
949 .colorspace = V4L2_COLORSPACE_SMPTE170M, 952 .format.colorspace = V4L2_COLORSPACE_SMPTE170M,
950 }; 953 };
951 unsigned int img_height_max; 954 unsigned int img_height_max;
952 int ret; 955 int ret;
@@ -984,22 +987,22 @@ static int sh_vou_s_crop(struct file *file, void *fh, const struct v4l2_crop *a)
984 */ 987 */
985 v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, 988 v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
986 s_crop, &sd_crop); 989 s_crop, &sd_crop);
987 mbfmt.width = geo.output.width; 990 format.format.width = geo.output.width;
988 mbfmt.height = geo.output.height; 991 format.format.height = geo.output.height;
989 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, 992 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, pad,
990 s_mbus_fmt, &mbfmt); 993 set_fmt, NULL, &format);
991 /* Must be implemented, so, don't check for -ENOIOCTLCMD */ 994 /* Must be implemented, so, don't check for -ENOIOCTLCMD */
992 if (ret < 0) 995 if (ret < 0)
993 return ret; 996 return ret;
994 997
995 /* Sanity checks */ 998 /* Sanity checks */
996 if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH || 999 if ((unsigned)format.format.width > VOU_MAX_IMAGE_WIDTH ||
997 (unsigned)mbfmt.height > img_height_max || 1000 (unsigned)format.format.height > img_height_max ||
998 mbfmt.code != MEDIA_BUS_FMT_YUYV8_2X8) 1001 format.format.code != MEDIA_BUS_FMT_YUYV8_2X8)
999 return -EIO; 1002 return -EIO;
1000 1003
1001 geo.output.width = mbfmt.width; 1004 geo.output.width = format.format.width;
1002 geo.output.height = mbfmt.height; 1005 geo.output.height = format.format.height;
1003 1006
1004 /* 1007 /*
1005 * No down-scaling. According to the API, current call has precedence: 1008 * No down-scaling. According to the API, current call has precedence:
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index c835beb2a1a8..287902681164 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -487,7 +487,10 @@ static int isi_camera_set_fmt(struct soc_camera_device *icd,
487 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 487 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
488 const struct soc_camera_format_xlate *xlate; 488 const struct soc_camera_format_xlate *xlate;
489 struct v4l2_pix_format *pix = &f->fmt.pix; 489 struct v4l2_pix_format *pix = &f->fmt.pix;
490 struct v4l2_mbus_framefmt mf; 490 struct v4l2_subdev_format format = {
491 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
492 };
493 struct v4l2_mbus_framefmt *mf = &format.format;
491 int ret; 494 int ret;
492 495
493 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 496 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
@@ -500,27 +503,27 @@ static int isi_camera_set_fmt(struct soc_camera_device *icd,
500 dev_dbg(icd->parent, "Plan to set format %dx%d\n", 503 dev_dbg(icd->parent, "Plan to set format %dx%d\n",
501 pix->width, pix->height); 504 pix->width, pix->height);
502 505
503 mf.width = pix->width; 506 mf->width = pix->width;
504 mf.height = pix->height; 507 mf->height = pix->height;
505 mf.field = pix->field; 508 mf->field = pix->field;
506 mf.colorspace = pix->colorspace; 509 mf->colorspace = pix->colorspace;
507 mf.code = xlate->code; 510 mf->code = xlate->code;
508 511
509 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 512 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format);
510 if (ret < 0) 513 if (ret < 0)
511 return ret; 514 return ret;
512 515
513 if (mf.code != xlate->code) 516 if (mf->code != xlate->code)
514 return -EINVAL; 517 return -EINVAL;
515 518
516 ret = configure_geometry(isi, pix->width, pix->height, xlate->code); 519 ret = configure_geometry(isi, pix->width, pix->height, xlate->code);
517 if (ret < 0) 520 if (ret < 0)
518 return ret; 521 return ret;
519 522
520 pix->width = mf.width; 523 pix->width = mf->width;
521 pix->height = mf.height; 524 pix->height = mf->height;
522 pix->field = mf.field; 525 pix->field = mf->field;
523 pix->colorspace = mf.colorspace; 526 pix->colorspace = mf->colorspace;
524 icd->current_fmt = xlate; 527 icd->current_fmt = xlate;
525 528
526 dev_dbg(icd->parent, "Finally set format %dx%d\n", 529 dev_dbg(icd->parent, "Finally set format %dx%d\n",
@@ -535,7 +538,11 @@ static int isi_camera_try_fmt(struct soc_camera_device *icd,
535 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 538 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
536 const struct soc_camera_format_xlate *xlate; 539 const struct soc_camera_format_xlate *xlate;
537 struct v4l2_pix_format *pix = &f->fmt.pix; 540 struct v4l2_pix_format *pix = &f->fmt.pix;
538 struct v4l2_mbus_framefmt mf; 541 struct v4l2_subdev_pad_config pad_cfg;
542 struct v4l2_subdev_format format = {
543 .which = V4L2_SUBDEV_FORMAT_TRY,
544 };
545 struct v4l2_mbus_framefmt *mf = &format.format;
539 u32 pixfmt = pix->pixelformat; 546 u32 pixfmt = pix->pixelformat;
540 int ret; 547 int ret;
541 548
@@ -552,21 +559,21 @@ static int isi_camera_try_fmt(struct soc_camera_device *icd,
552 pix->width = MAX_SUPPORT_WIDTH; 559 pix->width = MAX_SUPPORT_WIDTH;
553 560
554 /* limit to sensor capabilities */ 561 /* limit to sensor capabilities */
555 mf.width = pix->width; 562 mf->width = pix->width;
556 mf.height = pix->height; 563 mf->height = pix->height;
557 mf.field = pix->field; 564 mf->field = pix->field;
558 mf.colorspace = pix->colorspace; 565 mf->colorspace = pix->colorspace;
559 mf.code = xlate->code; 566 mf->code = xlate->code;
560 567
561 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 568 ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format);
562 if (ret < 0) 569 if (ret < 0)
563 return ret; 570 return ret;
564 571
565 pix->width = mf.width; 572 pix->width = mf->width;
566 pix->height = mf.height; 573 pix->height = mf->height;
567 pix->colorspace = mf.colorspace; 574 pix->colorspace = mf->colorspace;
568 575
569 switch (mf.field) { 576 switch (mf->field) {
570 case V4L2_FIELD_ANY: 577 case V4L2_FIELD_ANY:
571 pix->field = V4L2_FIELD_NONE; 578 pix->field = V4L2_FIELD_NONE;
572 break; 579 break;
@@ -574,7 +581,7 @@ static int isi_camera_try_fmt(struct soc_camera_device *icd,
574 break; 581 break;
575 default: 582 default:
576 dev_err(icd->parent, "Field type %d unsupported.\n", 583 dev_err(icd->parent, "Field type %d unsupported.\n",
577 mf.field); 584 mf->field);
578 ret = -EINVAL; 585 ret = -EINVAL;
579 } 586 }
580 587
@@ -648,19 +655,22 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
648 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 655 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
649 int formats = 0, ret; 656 int formats = 0, ret;
650 /* sensor format */ 657 /* sensor format */
651 u32 code; 658 struct v4l2_subdev_mbus_code_enum code = {
659 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
660 .index = idx,
661 };
652 /* soc camera host format */ 662 /* soc camera host format */
653 const struct soc_mbus_pixelfmt *fmt; 663 const struct soc_mbus_pixelfmt *fmt;
654 664
655 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 665 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
656 if (ret < 0) 666 if (ret < 0)
657 /* No more formats */ 667 /* No more formats */
658 return 0; 668 return 0;
659 669
660 fmt = soc_mbus_get_fmtdesc(code); 670 fmt = soc_mbus_get_fmtdesc(code.code);
661 if (!fmt) { 671 if (!fmt) {
662 dev_err(icd->parent, 672 dev_err(icd->parent,
663 "Invalid format code #%u: %d\n", idx, code); 673 "Invalid format code #%u: %d\n", idx, code.code);
664 return 0; 674 return 0;
665 } 675 }
666 676
@@ -672,7 +682,7 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
672 return 0; 682 return 0;
673 } 683 }
674 684
675 switch (code) { 685 switch (code.code) {
676 case MEDIA_BUS_FMT_UYVY8_2X8: 686 case MEDIA_BUS_FMT_UYVY8_2X8:
677 case MEDIA_BUS_FMT_VYUY8_2X8: 687 case MEDIA_BUS_FMT_VYUY8_2X8:
678 case MEDIA_BUS_FMT_YUYV8_2X8: 688 case MEDIA_BUS_FMT_YUYV8_2X8:
@@ -680,10 +690,10 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
680 formats++; 690 formats++;
681 if (xlate) { 691 if (xlate) {
682 xlate->host_fmt = &isi_camera_formats[0]; 692 xlate->host_fmt = &isi_camera_formats[0];
683 xlate->code = code; 693 xlate->code = code.code;
684 xlate++; 694 xlate++;
685 dev_dbg(icd->parent, "Providing format %s using code %d\n", 695 dev_dbg(icd->parent, "Providing format %s using code %d\n",
686 isi_camera_formats[0].name, code); 696 isi_camera_formats[0].name, code.code);
687 } 697 }
688 break; 698 break;
689 default: 699 default:
@@ -699,7 +709,7 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
699 formats++; 709 formats++;
700 if (xlate) { 710 if (xlate) {
701 xlate->host_fmt = fmt; 711 xlate->host_fmt = fmt;
702 xlate->code = code; 712 xlate->code = code.code;
703 xlate++; 713 xlate++;
704 } 714 }
705 715
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index 192377f55840..ea4c423f0cf8 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -912,7 +912,10 @@ static int mx2_camera_set_crop(struct soc_camera_device *icd,
912 struct v4l2_crop a_writable = *a; 912 struct v4l2_crop a_writable = *a;
913 struct v4l2_rect *rect = &a_writable.c; 913 struct v4l2_rect *rect = &a_writable.c;
914 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 914 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
915 struct v4l2_mbus_framefmt mf; 915 struct v4l2_subdev_format fmt = {
916 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
917 };
918 struct v4l2_mbus_framefmt *mf = &fmt.format;
916 int ret; 919 int ret;
917 920
918 soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096); 921 soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096);
@@ -923,15 +926,15 @@ static int mx2_camera_set_crop(struct soc_camera_device *icd,
923 return ret; 926 return ret;
924 927
925 /* The capture device might have changed its output */ 928 /* The capture device might have changed its output */
926 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 929 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
927 if (ret < 0) 930 if (ret < 0)
928 return ret; 931 return ret;
929 932
930 dev_dbg(icd->parent, "Sensor cropped %dx%d\n", 933 dev_dbg(icd->parent, "Sensor cropped %dx%d\n",
931 mf.width, mf.height); 934 mf->width, mf->height);
932 935
933 icd->user_width = mf.width; 936 icd->user_width = mf->width;
934 icd->user_height = mf.height; 937 icd->user_height = mf->height;
935 938
936 return ret; 939 return ret;
937} 940}
@@ -943,22 +946,25 @@ static int mx2_camera_get_formats(struct soc_camera_device *icd,
943 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 946 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
944 const struct soc_mbus_pixelfmt *fmt; 947 const struct soc_mbus_pixelfmt *fmt;
945 struct device *dev = icd->parent; 948 struct device *dev = icd->parent;
946 u32 code; 949 struct v4l2_subdev_mbus_code_enum code = {
950 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
951 .index = idx,
952 };
947 int ret, formats = 0; 953 int ret, formats = 0;
948 954
949 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 955 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
950 if (ret < 0) 956 if (ret < 0)
951 /* no more formats */ 957 /* no more formats */
952 return 0; 958 return 0;
953 959
954 fmt = soc_mbus_get_fmtdesc(code); 960 fmt = soc_mbus_get_fmtdesc(code.code);
955 if (!fmt) { 961 if (!fmt) {
956 dev_err(dev, "Invalid format code #%u: %d\n", idx, code); 962 dev_err(dev, "Invalid format code #%u: %d\n", idx, code.code);
957 return 0; 963 return 0;
958 } 964 }
959 965
960 if (code == MEDIA_BUS_FMT_YUYV8_2X8 || 966 if (code.code == MEDIA_BUS_FMT_YUYV8_2X8 ||
961 code == MEDIA_BUS_FMT_UYVY8_2X8) { 967 code.code == MEDIA_BUS_FMT_UYVY8_2X8) {
962 formats++; 968 formats++;
963 if (xlate) { 969 if (xlate) {
964 /* 970 /*
@@ -967,21 +973,21 @@ static int mx2_camera_get_formats(struct soc_camera_device *icd,
967 */ 973 */
968 xlate->host_fmt = 974 xlate->host_fmt =
969 soc_mbus_get_fmtdesc(MEDIA_BUS_FMT_YUYV8_1_5X8); 975 soc_mbus_get_fmtdesc(MEDIA_BUS_FMT_YUYV8_1_5X8);
970 xlate->code = code; 976 xlate->code = code.code;
971 dev_dbg(dev, "Providing host format %s for sensor code %d\n", 977 dev_dbg(dev, "Providing host format %s for sensor code %d\n",
972 xlate->host_fmt->name, code); 978 xlate->host_fmt->name, code.code);
973 xlate++; 979 xlate++;
974 } 980 }
975 } 981 }
976 982
977 if (code == MEDIA_BUS_FMT_UYVY8_2X8) { 983 if (code.code == MEDIA_BUS_FMT_UYVY8_2X8) {
978 formats++; 984 formats++;
979 if (xlate) { 985 if (xlate) {
980 xlate->host_fmt = 986 xlate->host_fmt =
981 soc_mbus_get_fmtdesc(MEDIA_BUS_FMT_YUYV8_2X8); 987 soc_mbus_get_fmtdesc(MEDIA_BUS_FMT_YUYV8_2X8);
982 xlate->code = code; 988 xlate->code = code.code;
983 dev_dbg(dev, "Providing host format %s for sensor code %d\n", 989 dev_dbg(dev, "Providing host format %s for sensor code %d\n",
984 xlate->host_fmt->name, code); 990 xlate->host_fmt->name, code.code);
985 xlate++; 991 xlate++;
986 } 992 }
987 } 993 }
@@ -990,7 +996,7 @@ static int mx2_camera_get_formats(struct soc_camera_device *icd,
990 formats++; 996 formats++;
991 if (xlate) { 997 if (xlate) {
992 xlate->host_fmt = fmt; 998 xlate->host_fmt = fmt;
993 xlate->code = code; 999 xlate->code = code.code;
994 xlate++; 1000 xlate++;
995 } 1001 }
996 return formats; 1002 return formats;
@@ -1121,7 +1127,10 @@ static int mx2_camera_set_fmt(struct soc_camera_device *icd,
1121 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1127 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1122 const struct soc_camera_format_xlate *xlate; 1128 const struct soc_camera_format_xlate *xlate;
1123 struct v4l2_pix_format *pix = &f->fmt.pix; 1129 struct v4l2_pix_format *pix = &f->fmt.pix;
1124 struct v4l2_mbus_framefmt mf; 1130 struct v4l2_subdev_format format = {
1131 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1132 };
1133 struct v4l2_mbus_framefmt *mf = &format.format;
1125 int ret; 1134 int ret;
1126 1135
1127 dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n", 1136 dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n",
@@ -1134,19 +1143,19 @@ static int mx2_camera_set_fmt(struct soc_camera_device *icd,
1134 return -EINVAL; 1143 return -EINVAL;
1135 } 1144 }
1136 1145
1137 mf.width = pix->width; 1146 mf->width = pix->width;
1138 mf.height = pix->height; 1147 mf->height = pix->height;
1139 mf.field = pix->field; 1148 mf->field = pix->field;
1140 mf.colorspace = pix->colorspace; 1149 mf->colorspace = pix->colorspace;
1141 mf.code = xlate->code; 1150 mf->code = xlate->code;
1142 1151
1143 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 1152 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format);
1144 if (ret < 0 && ret != -ENOIOCTLCMD) 1153 if (ret < 0 && ret != -ENOIOCTLCMD)
1145 return ret; 1154 return ret;
1146 1155
1147 /* Store width and height returned by the sensor for resizing */ 1156 /* Store width and height returned by the sensor for resizing */
1148 pcdev->s_width = mf.width; 1157 pcdev->s_width = mf->width;
1149 pcdev->s_height = mf.height; 1158 pcdev->s_height = mf->height;
1150 dev_dbg(icd->parent, "%s: sensor params: width = %d, height = %d\n", 1159 dev_dbg(icd->parent, "%s: sensor params: width = %d, height = %d\n",
1151 __func__, pcdev->s_width, pcdev->s_height); 1160 __func__, pcdev->s_width, pcdev->s_height);
1152 1161
@@ -1154,19 +1163,19 @@ static int mx2_camera_set_fmt(struct soc_camera_device *icd,
1154 xlate->host_fmt->fourcc); 1163 xlate->host_fmt->fourcc);
1155 1164
1156 memset(pcdev->resizing, 0, sizeof(pcdev->resizing)); 1165 memset(pcdev->resizing, 0, sizeof(pcdev->resizing));
1157 if ((mf.width != pix->width || mf.height != pix->height) && 1166 if ((mf->width != pix->width || mf->height != pix->height) &&
1158 pcdev->emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) { 1167 pcdev->emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) {
1159 if (mx2_emmaprp_resize(pcdev, &mf, pix, true) < 0) 1168 if (mx2_emmaprp_resize(pcdev, mf, pix, true) < 0)
1160 dev_dbg(icd->parent, "%s: can't resize\n", __func__); 1169 dev_dbg(icd->parent, "%s: can't resize\n", __func__);
1161 } 1170 }
1162 1171
1163 if (mf.code != xlate->code) 1172 if (mf->code != xlate->code)
1164 return -EINVAL; 1173 return -EINVAL;
1165 1174
1166 pix->width = mf.width; 1175 pix->width = mf->width;
1167 pix->height = mf.height; 1176 pix->height = mf->height;
1168 pix->field = mf.field; 1177 pix->field = mf->field;
1169 pix->colorspace = mf.colorspace; 1178 pix->colorspace = mf->colorspace;
1170 icd->current_fmt = xlate; 1179 icd->current_fmt = xlate;
1171 1180
1172 dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n", 1181 dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n",
@@ -1181,7 +1190,11 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1181 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1190 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1182 const struct soc_camera_format_xlate *xlate; 1191 const struct soc_camera_format_xlate *xlate;
1183 struct v4l2_pix_format *pix = &f->fmt.pix; 1192 struct v4l2_pix_format *pix = &f->fmt.pix;
1184 struct v4l2_mbus_framefmt mf; 1193 struct v4l2_subdev_pad_config pad_cfg;
1194 struct v4l2_subdev_format format = {
1195 .which = V4L2_SUBDEV_FORMAT_TRY,
1196 };
1197 struct v4l2_mbus_framefmt *mf = &format.format;
1185 __u32 pixfmt = pix->pixelformat; 1198 __u32 pixfmt = pix->pixelformat;
1186 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1199 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1187 struct mx2_camera_dev *pcdev = ici->priv; 1200 struct mx2_camera_dev *pcdev = ici->priv;
@@ -1204,13 +1217,13 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1204 pix->width &= ~0x7; 1217 pix->width &= ~0x7;
1205 1218
1206 /* limit to sensor capabilities */ 1219 /* limit to sensor capabilities */
1207 mf.width = pix->width; 1220 mf->width = pix->width;
1208 mf.height = pix->height; 1221 mf->height = pix->height;
1209 mf.field = pix->field; 1222 mf->field = pix->field;
1210 mf.colorspace = pix->colorspace; 1223 mf->colorspace = pix->colorspace;
1211 mf.code = xlate->code; 1224 mf->code = xlate->code;
1212 1225
1213 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 1226 ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format);
1214 if (ret < 0) 1227 if (ret < 0)
1215 return ret; 1228 return ret;
1216 1229
@@ -1221,29 +1234,29 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1221 emma_prp = mx27_emma_prp_get_format(xlate->code, 1234 emma_prp = mx27_emma_prp_get_format(xlate->code,
1222 xlate->host_fmt->fourcc); 1235 xlate->host_fmt->fourcc);
1223 1236
1224 if ((mf.width != pix->width || mf.height != pix->height) && 1237 if ((mf->width != pix->width || mf->height != pix->height) &&
1225 emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) { 1238 emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) {
1226 if (mx2_emmaprp_resize(pcdev, &mf, pix, false) < 0) 1239 if (mx2_emmaprp_resize(pcdev, mf, pix, false) < 0)
1227 dev_dbg(icd->parent, "%s: can't resize\n", __func__); 1240 dev_dbg(icd->parent, "%s: can't resize\n", __func__);
1228 } 1241 }
1229 1242
1230 if (mf.field == V4L2_FIELD_ANY) 1243 if (mf->field == V4L2_FIELD_ANY)
1231 mf.field = V4L2_FIELD_NONE; 1244 mf->field = V4L2_FIELD_NONE;
1232 /* 1245 /*
1233 * Driver supports interlaced images provided they have 1246 * Driver supports interlaced images provided they have
1234 * both fields so that they can be processed as if they 1247 * both fields so that they can be processed as if they
1235 * were progressive. 1248 * were progressive.
1236 */ 1249 */
1237 if (mf.field != V4L2_FIELD_NONE && !V4L2_FIELD_HAS_BOTH(mf.field)) { 1250 if (mf->field != V4L2_FIELD_NONE && !V4L2_FIELD_HAS_BOTH(mf->field)) {
1238 dev_err(icd->parent, "Field type %d unsupported.\n", 1251 dev_err(icd->parent, "Field type %d unsupported.\n",
1239 mf.field); 1252 mf->field);
1240 return -EINVAL; 1253 return -EINVAL;
1241 } 1254 }
1242 1255
1243 pix->width = mf.width; 1256 pix->width = mf->width;
1244 pix->height = mf.height; 1257 pix->height = mf->height;
1245 pix->field = mf.field; 1258 pix->field = mf->field;
1246 pix->colorspace = mf.colorspace; 1259 pix->colorspace = mf->colorspace;
1247 1260
1248 dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n", 1261 dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n",
1249 __func__, pix->width, pix->height); 1262 __func__, pix->width, pix->height);
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 3435fd2ca8ec..ace41f53caca 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -659,18 +659,21 @@ static int mx3_camera_get_formats(struct soc_camera_device *icd, unsigned int id
659 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 659 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
660 struct device *dev = icd->parent; 660 struct device *dev = icd->parent;
661 int formats = 0, ret; 661 int formats = 0, ret;
662 u32 code; 662 struct v4l2_subdev_mbus_code_enum code = {
663 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
664 .index = idx,
665 };
663 const struct soc_mbus_pixelfmt *fmt; 666 const struct soc_mbus_pixelfmt *fmt;
664 667
665 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 668 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
666 if (ret < 0) 669 if (ret < 0)
667 /* No more formats */ 670 /* No more formats */
668 return 0; 671 return 0;
669 672
670 fmt = soc_mbus_get_fmtdesc(code); 673 fmt = soc_mbus_get_fmtdesc(code.code);
671 if (!fmt) { 674 if (!fmt) {
672 dev_warn(icd->parent, 675 dev_warn(icd->parent,
673 "Unsupported format code #%u: 0x%x\n", idx, code); 676 "Unsupported format code #%u: 0x%x\n", idx, code.code);
674 return 0; 677 return 0;
675 } 678 }
676 679
@@ -679,25 +682,25 @@ static int mx3_camera_get_formats(struct soc_camera_device *icd, unsigned int id
679 if (ret < 0) 682 if (ret < 0)
680 return 0; 683 return 0;
681 684
682 switch (code) { 685 switch (code.code) {
683 case MEDIA_BUS_FMT_SBGGR10_1X10: 686 case MEDIA_BUS_FMT_SBGGR10_1X10:
684 formats++; 687 formats++;
685 if (xlate) { 688 if (xlate) {
686 xlate->host_fmt = &mx3_camera_formats[0]; 689 xlate->host_fmt = &mx3_camera_formats[0];
687 xlate->code = code; 690 xlate->code = code.code;
688 xlate++; 691 xlate++;
689 dev_dbg(dev, "Providing format %s using code 0x%x\n", 692 dev_dbg(dev, "Providing format %s using code 0x%x\n",
690 mx3_camera_formats[0].name, code); 693 mx3_camera_formats[0].name, code.code);
691 } 694 }
692 break; 695 break;
693 case MEDIA_BUS_FMT_Y10_1X10: 696 case MEDIA_BUS_FMT_Y10_1X10:
694 formats++; 697 formats++;
695 if (xlate) { 698 if (xlate) {
696 xlate->host_fmt = &mx3_camera_formats[1]; 699 xlate->host_fmt = &mx3_camera_formats[1];
697 xlate->code = code; 700 xlate->code = code.code;
698 xlate++; 701 xlate++;
699 dev_dbg(dev, "Providing format %s using code 0x%x\n", 702 dev_dbg(dev, "Providing format %s using code 0x%x\n",
700 mx3_camera_formats[1].name, code); 703 mx3_camera_formats[1].name, code.code);
701 } 704 }
702 break; 705 break;
703 default: 706 default:
@@ -709,7 +712,7 @@ static int mx3_camera_get_formats(struct soc_camera_device *icd, unsigned int id
709 formats++; 712 formats++;
710 if (xlate) { 713 if (xlate) {
711 xlate->host_fmt = fmt; 714 xlate->host_fmt = fmt;
712 xlate->code = code; 715 xlate->code = code.code;
713 dev_dbg(dev, "Providing format %c%c%c%c in pass-through mode\n", 716 dev_dbg(dev, "Providing format %c%c%c%c in pass-through mode\n",
714 (fmt->fourcc >> (0*8)) & 0xFF, 717 (fmt->fourcc >> (0*8)) & 0xFF,
715 (fmt->fourcc >> (1*8)) & 0xFF, 718 (fmt->fourcc >> (1*8)) & 0xFF,
@@ -801,7 +804,10 @@ static int mx3_camera_set_crop(struct soc_camera_device *icd,
801 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 804 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
802 struct mx3_camera_dev *mx3_cam = ici->priv; 805 struct mx3_camera_dev *mx3_cam = ici->priv;
803 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 806 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
804 struct v4l2_mbus_framefmt mf; 807 struct v4l2_subdev_format fmt = {
808 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
809 };
810 struct v4l2_mbus_framefmt *mf = &fmt.format;
805 int ret; 811 int ret;
806 812
807 soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096); 813 soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096);
@@ -812,30 +818,30 @@ static int mx3_camera_set_crop(struct soc_camera_device *icd,
812 return ret; 818 return ret;
813 819
814 /* The capture device might have changed its output sizes */ 820 /* The capture device might have changed its output sizes */
815 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 821 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
816 if (ret < 0) 822 if (ret < 0)
817 return ret; 823 return ret;
818 824
819 if (mf.code != icd->current_fmt->code) 825 if (mf->code != icd->current_fmt->code)
820 return -EINVAL; 826 return -EINVAL;
821 827
822 if (mf.width & 7) { 828 if (mf->width & 7) {
823 /* Ouch! We can only handle 8-byte aligned width... */ 829 /* Ouch! We can only handle 8-byte aligned width... */
824 stride_align(&mf.width); 830 stride_align(&mf->width);
825 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 831 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &fmt);
826 if (ret < 0) 832 if (ret < 0)
827 return ret; 833 return ret;
828 } 834 }
829 835
830 if (mf.width != icd->user_width || mf.height != icd->user_height) 836 if (mf->width != icd->user_width || mf->height != icd->user_height)
831 configure_geometry(mx3_cam, mf.width, mf.height, 837 configure_geometry(mx3_cam, mf->width, mf->height,
832 icd->current_fmt->host_fmt); 838 icd->current_fmt->host_fmt);
833 839
834 dev_dbg(icd->parent, "Sensor cropped %dx%d\n", 840 dev_dbg(icd->parent, "Sensor cropped %dx%d\n",
835 mf.width, mf.height); 841 mf->width, mf->height);
836 842
837 icd->user_width = mf.width; 843 icd->user_width = mf->width;
838 icd->user_height = mf.height; 844 icd->user_height = mf->height;
839 845
840 return ret; 846 return ret;
841} 847}
@@ -848,7 +854,10 @@ static int mx3_camera_set_fmt(struct soc_camera_device *icd,
848 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 854 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
849 const struct soc_camera_format_xlate *xlate; 855 const struct soc_camera_format_xlate *xlate;
850 struct v4l2_pix_format *pix = &f->fmt.pix; 856 struct v4l2_pix_format *pix = &f->fmt.pix;
851 struct v4l2_mbus_framefmt mf; 857 struct v4l2_subdev_format format = {
858 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
859 };
860 struct v4l2_mbus_framefmt *mf = &format.format;
852 int ret; 861 int ret;
853 862
854 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 863 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
@@ -869,17 +878,17 @@ static int mx3_camera_set_fmt(struct soc_camera_device *icd,
869 878
870 configure_geometry(mx3_cam, pix->width, pix->height, xlate->host_fmt); 879 configure_geometry(mx3_cam, pix->width, pix->height, xlate->host_fmt);
871 880
872 mf.width = pix->width; 881 mf->width = pix->width;
873 mf.height = pix->height; 882 mf->height = pix->height;
874 mf.field = pix->field; 883 mf->field = pix->field;
875 mf.colorspace = pix->colorspace; 884 mf->colorspace = pix->colorspace;
876 mf.code = xlate->code; 885 mf->code = xlate->code;
877 886
878 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 887 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format);
879 if (ret < 0) 888 if (ret < 0)
880 return ret; 889 return ret;
881 890
882 if (mf.code != xlate->code) 891 if (mf->code != xlate->code)
883 return -EINVAL; 892 return -EINVAL;
884 893
885 if (!mx3_cam->idmac_channel[0]) { 894 if (!mx3_cam->idmac_channel[0]) {
@@ -888,11 +897,11 @@ static int mx3_camera_set_fmt(struct soc_camera_device *icd,
888 return ret; 897 return ret;
889 } 898 }
890 899
891 pix->width = mf.width; 900 pix->width = mf->width;
892 pix->height = mf.height; 901 pix->height = mf->height;
893 pix->field = mf.field; 902 pix->field = mf->field;
894 mx3_cam->field = mf.field; 903 mx3_cam->field = mf->field;
895 pix->colorspace = mf.colorspace; 904 pix->colorspace = mf->colorspace;
896 icd->current_fmt = xlate; 905 icd->current_fmt = xlate;
897 906
898 dev_dbg(icd->parent, "Sensor set %dx%d\n", pix->width, pix->height); 907 dev_dbg(icd->parent, "Sensor set %dx%d\n", pix->width, pix->height);
@@ -906,7 +915,11 @@ static int mx3_camera_try_fmt(struct soc_camera_device *icd,
906 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 915 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
907 const struct soc_camera_format_xlate *xlate; 916 const struct soc_camera_format_xlate *xlate;
908 struct v4l2_pix_format *pix = &f->fmt.pix; 917 struct v4l2_pix_format *pix = &f->fmt.pix;
909 struct v4l2_mbus_framefmt mf; 918 struct v4l2_subdev_pad_config pad_cfg;
919 struct v4l2_subdev_format format = {
920 .which = V4L2_SUBDEV_FORMAT_TRY,
921 };
922 struct v4l2_mbus_framefmt *mf = &format.format;
910 __u32 pixfmt = pix->pixelformat; 923 __u32 pixfmt = pix->pixelformat;
911 int ret; 924 int ret;
912 925
@@ -923,21 +936,21 @@ static int mx3_camera_try_fmt(struct soc_camera_device *icd,
923 pix->width = 4096; 936 pix->width = 4096;
924 937
925 /* limit to sensor capabilities */ 938 /* limit to sensor capabilities */
926 mf.width = pix->width; 939 mf->width = pix->width;
927 mf.height = pix->height; 940 mf->height = pix->height;
928 mf.field = pix->field; 941 mf->field = pix->field;
929 mf.colorspace = pix->colorspace; 942 mf->colorspace = pix->colorspace;
930 mf.code = xlate->code; 943 mf->code = xlate->code;
931 944
932 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 945 ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format);
933 if (ret < 0) 946 if (ret < 0)
934 return ret; 947 return ret;
935 948
936 pix->width = mf.width; 949 pix->width = mf->width;
937 pix->height = mf.height; 950 pix->height = mf->height;
938 pix->colorspace = mf.colorspace; 951 pix->colorspace = mf->colorspace;
939 952
940 switch (mf.field) { 953 switch (mf->field) {
941 case V4L2_FIELD_ANY: 954 case V4L2_FIELD_ANY:
942 pix->field = V4L2_FIELD_NONE; 955 pix->field = V4L2_FIELD_NONE;
943 break; 956 break;
@@ -945,7 +958,7 @@ static int mx3_camera_try_fmt(struct soc_camera_device *icd,
945 break; 958 break;
946 default: 959 default:
947 dev_err(icd->parent, "Field type %d unsupported.\n", 960 dev_err(icd->parent, "Field type %d unsupported.\n",
948 mf.field); 961 mf->field);
949 ret = -EINVAL; 962 ret = -EINVAL;
950 } 963 }
951 964
diff --git a/drivers/media/platform/soc_camera/omap1_camera.c b/drivers/media/platform/soc_camera/omap1_camera.c
index 16f65ecb70a3..ba8dcd11ae0e 100644
--- a/drivers/media/platform/soc_camera/omap1_camera.c
+++ b/drivers/media/platform/soc_camera/omap1_camera.c
@@ -1068,18 +1068,21 @@ static int omap1_cam_get_formats(struct soc_camera_device *icd,
1068 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1068 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1069 struct device *dev = icd->parent; 1069 struct device *dev = icd->parent;
1070 int formats = 0, ret; 1070 int formats = 0, ret;
1071 u32 code; 1071 struct v4l2_subdev_mbus_code_enum code = {
1072 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1073 .index = idx,
1074 };
1072 const struct soc_mbus_pixelfmt *fmt; 1075 const struct soc_mbus_pixelfmt *fmt;
1073 1076
1074 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 1077 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
1075 if (ret < 0) 1078 if (ret < 0)
1076 /* No more formats */ 1079 /* No more formats */
1077 return 0; 1080 return 0;
1078 1081
1079 fmt = soc_mbus_get_fmtdesc(code); 1082 fmt = soc_mbus_get_fmtdesc(code.code);
1080 if (!fmt) { 1083 if (!fmt) {
1081 dev_warn(dev, "%s: unsupported format code #%d: %d\n", __func__, 1084 dev_warn(dev, "%s: unsupported format code #%d: %d\n", __func__,
1082 idx, code); 1085 idx, code.code);
1083 return 0; 1086 return 0;
1084 } 1087 }
1085 1088
@@ -1087,7 +1090,7 @@ static int omap1_cam_get_formats(struct soc_camera_device *icd,
1087 if (fmt->bits_per_sample != 8) 1090 if (fmt->bits_per_sample != 8)
1088 return 0; 1091 return 0;
1089 1092
1090 switch (code) { 1093 switch (code.code) {
1091 case MEDIA_BUS_FMT_YUYV8_2X8: 1094 case MEDIA_BUS_FMT_YUYV8_2X8:
1092 case MEDIA_BUS_FMT_YVYU8_2X8: 1095 case MEDIA_BUS_FMT_YVYU8_2X8:
1093 case MEDIA_BUS_FMT_UYVY8_2X8: 1096 case MEDIA_BUS_FMT_UYVY8_2X8:
@@ -1098,14 +1101,14 @@ static int omap1_cam_get_formats(struct soc_camera_device *icd,
1098 case MEDIA_BUS_FMT_RGB565_2X8_LE: 1101 case MEDIA_BUS_FMT_RGB565_2X8_LE:
1099 formats++; 1102 formats++;
1100 if (xlate) { 1103 if (xlate) {
1101 xlate->host_fmt = soc_mbus_find_fmtdesc(code, 1104 xlate->host_fmt = soc_mbus_find_fmtdesc(code.code,
1102 omap1_cam_formats, 1105 omap1_cam_formats,
1103 ARRAY_SIZE(omap1_cam_formats)); 1106 ARRAY_SIZE(omap1_cam_formats));
1104 xlate->code = code; 1107 xlate->code = code.code;
1105 xlate++; 1108 xlate++;
1106 dev_dbg(dev, 1109 dev_dbg(dev,
1107 "%s: providing format %s as byte swapped code #%d\n", 1110 "%s: providing format %s as byte swapped code #%d\n",
1108 __func__, xlate->host_fmt->name, code); 1111 __func__, xlate->host_fmt->name, code.code);
1109 } 1112 }
1110 default: 1113 default:
1111 if (xlate) 1114 if (xlate)
@@ -1116,7 +1119,7 @@ static int omap1_cam_get_formats(struct soc_camera_device *icd,
1116 formats++; 1119 formats++;
1117 if (xlate) { 1120 if (xlate) {
1118 xlate->host_fmt = fmt; 1121 xlate->host_fmt = fmt;
1119 xlate->code = code; 1122 xlate->code = code.code;
1120 xlate++; 1123 xlate++;
1121 } 1124 }
1122 1125
@@ -1154,7 +1157,7 @@ static int dma_align(int *width, int *height,
1154 return 1; 1157 return 1;
1155} 1158}
1156 1159
1157#define subdev_call_with_sense(pcdev, dev, icd, sd, function, args...) \ 1160#define subdev_call_with_sense(pcdev, dev, icd, sd, op, function, args...) \
1158({ \ 1161({ \
1159 struct soc_camera_sense sense = { \ 1162 struct soc_camera_sense sense = { \
1160 .master_clock = pcdev->camexclk, \ 1163 .master_clock = pcdev->camexclk, \
@@ -1165,7 +1168,7 @@ static int dma_align(int *width, int *height,
1165 if (pcdev->pdata) \ 1168 if (pcdev->pdata) \
1166 sense.pixel_clock_max = pcdev->pdata->lclk_khz_max * 1000; \ 1169 sense.pixel_clock_max = pcdev->pdata->lclk_khz_max * 1000; \
1167 icd->sense = &sense; \ 1170 icd->sense = &sense; \
1168 __ret = v4l2_subdev_call(sd, video, function, ##args); \ 1171 __ret = v4l2_subdev_call(sd, op, function, ##args); \
1169 icd->sense = NULL; \ 1172 icd->sense = NULL; \
1170 \ 1173 \
1171 if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { \ 1174 if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { \
@@ -1179,16 +1182,17 @@ static int dma_align(int *width, int *height,
1179 __ret; \ 1182 __ret; \
1180}) 1183})
1181 1184
1182static int set_mbus_format(struct omap1_cam_dev *pcdev, struct device *dev, 1185static int set_format(struct omap1_cam_dev *pcdev, struct device *dev,
1183 struct soc_camera_device *icd, struct v4l2_subdev *sd, 1186 struct soc_camera_device *icd, struct v4l2_subdev *sd,
1184 struct v4l2_mbus_framefmt *mf, 1187 struct v4l2_subdev_format *format,
1185 const struct soc_camera_format_xlate *xlate) 1188 const struct soc_camera_format_xlate *xlate)
1186{ 1189{
1187 s32 bytes_per_line; 1190 s32 bytes_per_line;
1188 int ret = subdev_call_with_sense(pcdev, dev, icd, sd, s_mbus_fmt, mf); 1191 struct v4l2_mbus_framefmt *mf = &format->format;
1192 int ret = subdev_call_with_sense(pcdev, dev, icd, sd, pad, set_fmt, NULL, format);
1189 1193
1190 if (ret < 0) { 1194 if (ret < 0) {
1191 dev_err(dev, "%s: s_mbus_fmt failed\n", __func__); 1195 dev_err(dev, "%s: set_fmt failed\n", __func__);
1192 return ret; 1196 return ret;
1193 } 1197 }
1194 1198
@@ -1221,42 +1225,45 @@ static int omap1_cam_set_crop(struct soc_camera_device *icd,
1221 struct device *dev = icd->parent; 1225 struct device *dev = icd->parent;
1222 struct soc_camera_host *ici = to_soc_camera_host(dev); 1226 struct soc_camera_host *ici = to_soc_camera_host(dev);
1223 struct omap1_cam_dev *pcdev = ici->priv; 1227 struct omap1_cam_dev *pcdev = ici->priv;
1224 struct v4l2_mbus_framefmt mf; 1228 struct v4l2_subdev_format fmt = {
1229 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1230 };
1231 struct v4l2_mbus_framefmt *mf = &fmt.format;
1225 int ret; 1232 int ret;
1226 1233
1227 ret = subdev_call_with_sense(pcdev, dev, icd, sd, s_crop, crop); 1234 ret = subdev_call_with_sense(pcdev, dev, icd, sd, video, s_crop, crop);
1228 if (ret < 0) { 1235 if (ret < 0) {
1229 dev_warn(dev, "%s: failed to crop to %ux%u@%u:%u\n", __func__, 1236 dev_warn(dev, "%s: failed to crop to %ux%u@%u:%u\n", __func__,
1230 rect->width, rect->height, rect->left, rect->top); 1237 rect->width, rect->height, rect->left, rect->top);
1231 return ret; 1238 return ret;
1232 } 1239 }
1233 1240
1234 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 1241 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
1235 if (ret < 0) { 1242 if (ret < 0) {
1236 dev_warn(dev, "%s: failed to fetch current format\n", __func__); 1243 dev_warn(dev, "%s: failed to fetch current format\n", __func__);
1237 return ret; 1244 return ret;
1238 } 1245 }
1239 1246
1240 ret = dma_align(&mf.width, &mf.height, xlate->host_fmt, pcdev->vb_mode, 1247 ret = dma_align(&mf->width, &mf->height, xlate->host_fmt, pcdev->vb_mode,
1241 false); 1248 false);
1242 if (ret < 0) { 1249 if (ret < 0) {
1243 dev_err(dev, "%s: failed to align %ux%u %s with DMA\n", 1250 dev_err(dev, "%s: failed to align %ux%u %s with DMA\n",
1244 __func__, mf.width, mf.height, 1251 __func__, mf->width, mf->height,
1245 xlate->host_fmt->name); 1252 xlate->host_fmt->name);
1246 return ret; 1253 return ret;
1247 } 1254 }
1248 1255
1249 if (!ret) { 1256 if (!ret) {
1250 /* sensor returned geometry not DMA aligned, trying to fix */ 1257 /* sensor returned geometry not DMA aligned, trying to fix */
1251 ret = set_mbus_format(pcdev, dev, icd, sd, &mf, xlate); 1258 ret = set_format(pcdev, dev, icd, sd, &fmt, xlate);
1252 if (ret < 0) { 1259 if (ret < 0) {
1253 dev_err(dev, "%s: failed to set format\n", __func__); 1260 dev_err(dev, "%s: failed to set format\n", __func__);
1254 return ret; 1261 return ret;
1255 } 1262 }
1256 } 1263 }
1257 1264
1258 icd->user_width = mf.width; 1265 icd->user_width = mf->width;
1259 icd->user_height = mf.height; 1266 icd->user_height = mf->height;
1260 1267
1261 return 0; 1268 return 0;
1262} 1269}
@@ -1270,7 +1277,10 @@ static int omap1_cam_set_fmt(struct soc_camera_device *icd,
1270 struct soc_camera_host *ici = to_soc_camera_host(dev); 1277 struct soc_camera_host *ici = to_soc_camera_host(dev);
1271 struct omap1_cam_dev *pcdev = ici->priv; 1278 struct omap1_cam_dev *pcdev = ici->priv;
1272 struct v4l2_pix_format *pix = &f->fmt.pix; 1279 struct v4l2_pix_format *pix = &f->fmt.pix;
1273 struct v4l2_mbus_framefmt mf; 1280 struct v4l2_subdev_format format = {
1281 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1282 };
1283 struct v4l2_mbus_framefmt *mf = &format.format;
1274 int ret; 1284 int ret;
1275 1285
1276 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 1286 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
@@ -1280,13 +1290,13 @@ static int omap1_cam_set_fmt(struct soc_camera_device *icd,
1280 return -EINVAL; 1290 return -EINVAL;
1281 } 1291 }
1282 1292
1283 mf.width = pix->width; 1293 mf->width = pix->width;
1284 mf.height = pix->height; 1294 mf->height = pix->height;
1285 mf.field = pix->field; 1295 mf->field = pix->field;
1286 mf.colorspace = pix->colorspace; 1296 mf->colorspace = pix->colorspace;
1287 mf.code = xlate->code; 1297 mf->code = xlate->code;
1288 1298
1289 ret = dma_align(&mf.width, &mf.height, xlate->host_fmt, pcdev->vb_mode, 1299 ret = dma_align(&mf->width, &mf->height, xlate->host_fmt, pcdev->vb_mode,
1290 true); 1300 true);
1291 if (ret < 0) { 1301 if (ret < 0) {
1292 dev_err(dev, "%s: failed to align %ux%u %s with DMA\n", 1302 dev_err(dev, "%s: failed to align %ux%u %s with DMA\n",
@@ -1295,16 +1305,16 @@ static int omap1_cam_set_fmt(struct soc_camera_device *icd,
1295 return ret; 1305 return ret;
1296 } 1306 }
1297 1307
1298 ret = set_mbus_format(pcdev, dev, icd, sd, &mf, xlate); 1308 ret = set_format(pcdev, dev, icd, sd, &format, xlate);
1299 if (ret < 0) { 1309 if (ret < 0) {
1300 dev_err(dev, "%s: failed to set format\n", __func__); 1310 dev_err(dev, "%s: failed to set format\n", __func__);
1301 return ret; 1311 return ret;
1302 } 1312 }
1303 1313
1304 pix->width = mf.width; 1314 pix->width = mf->width;
1305 pix->height = mf.height; 1315 pix->height = mf->height;
1306 pix->field = mf.field; 1316 pix->field = mf->field;
1307 pix->colorspace = mf.colorspace; 1317 pix->colorspace = mf->colorspace;
1308 icd->current_fmt = xlate; 1318 icd->current_fmt = xlate;
1309 1319
1310 return 0; 1320 return 0;
@@ -1316,7 +1326,11 @@ static int omap1_cam_try_fmt(struct soc_camera_device *icd,
1316 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1326 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1317 const struct soc_camera_format_xlate *xlate; 1327 const struct soc_camera_format_xlate *xlate;
1318 struct v4l2_pix_format *pix = &f->fmt.pix; 1328 struct v4l2_pix_format *pix = &f->fmt.pix;
1319 struct v4l2_mbus_framefmt mf; 1329 struct v4l2_subdev_pad_config pad_cfg;
1330 struct v4l2_subdev_format format = {
1331 .which = V4L2_SUBDEV_FORMAT_TRY,
1332 };
1333 struct v4l2_mbus_framefmt *mf = &format.format;
1320 int ret; 1334 int ret;
1321 /* TODO: limit to mx1 hardware capabilities */ 1335 /* TODO: limit to mx1 hardware capabilities */
1322 1336
@@ -1327,21 +1341,21 @@ static int omap1_cam_try_fmt(struct soc_camera_device *icd,
1327 return -EINVAL; 1341 return -EINVAL;
1328 } 1342 }
1329 1343
1330 mf.width = pix->width; 1344 mf->width = pix->width;
1331 mf.height = pix->height; 1345 mf->height = pix->height;
1332 mf.field = pix->field; 1346 mf->field = pix->field;
1333 mf.colorspace = pix->colorspace; 1347 mf->colorspace = pix->colorspace;
1334 mf.code = xlate->code; 1348 mf->code = xlate->code;
1335 1349
1336 /* limit to sensor capabilities */ 1350 /* limit to sensor capabilities */
1337 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 1351 ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format);
1338 if (ret < 0) 1352 if (ret < 0)
1339 return ret; 1353 return ret;
1340 1354
1341 pix->width = mf.width; 1355 pix->width = mf->width;
1342 pix->height = mf.height; 1356 pix->height = mf->height;
1343 pix->field = mf.field; 1357 pix->field = mf->field;
1344 pix->colorspace = mf.colorspace; 1358 pix->colorspace = mf->colorspace;
1345 1359
1346 return 0; 1360 return 0;
1347} 1361}
diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c
index 8d6e343fec0f..fcb942de0c7f 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -1253,17 +1253,20 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int id
1253 struct device *dev = icd->parent; 1253 struct device *dev = icd->parent;
1254 int formats = 0, ret; 1254 int formats = 0, ret;
1255 struct pxa_cam *cam; 1255 struct pxa_cam *cam;
1256 u32 code; 1256 struct v4l2_subdev_mbus_code_enum code = {
1257 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1258 .index = idx,
1259 };
1257 const struct soc_mbus_pixelfmt *fmt; 1260 const struct soc_mbus_pixelfmt *fmt;
1258 1261
1259 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 1262 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
1260 if (ret < 0) 1263 if (ret < 0)
1261 /* No more formats */ 1264 /* No more formats */
1262 return 0; 1265 return 0;
1263 1266
1264 fmt = soc_mbus_get_fmtdesc(code); 1267 fmt = soc_mbus_get_fmtdesc(code.code);
1265 if (!fmt) { 1268 if (!fmt) {
1266 dev_err(dev, "Invalid format code #%u: %d\n", idx, code); 1269 dev_err(dev, "Invalid format code #%u: %d\n", idx, code.code);
1267 return 0; 1270 return 0;
1268 } 1271 }
1269 1272
@@ -1282,15 +1285,15 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int id
1282 cam = icd->host_priv; 1285 cam = icd->host_priv;
1283 } 1286 }
1284 1287
1285 switch (code) { 1288 switch (code.code) {
1286 case MEDIA_BUS_FMT_UYVY8_2X8: 1289 case MEDIA_BUS_FMT_UYVY8_2X8:
1287 formats++; 1290 formats++;
1288 if (xlate) { 1291 if (xlate) {
1289 xlate->host_fmt = &pxa_camera_formats[0]; 1292 xlate->host_fmt = &pxa_camera_formats[0];
1290 xlate->code = code; 1293 xlate->code = code.code;
1291 xlate++; 1294 xlate++;
1292 dev_dbg(dev, "Providing format %s using code %d\n", 1295 dev_dbg(dev, "Providing format %s using code %d\n",
1293 pxa_camera_formats[0].name, code); 1296 pxa_camera_formats[0].name, code.code);
1294 } 1297 }
1295 case MEDIA_BUS_FMT_VYUY8_2X8: 1298 case MEDIA_BUS_FMT_VYUY8_2X8:
1296 case MEDIA_BUS_FMT_YUYV8_2X8: 1299 case MEDIA_BUS_FMT_YUYV8_2X8:
@@ -1314,7 +1317,7 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int id
1314 formats++; 1317 formats++;
1315 if (xlate) { 1318 if (xlate) {
1316 xlate->host_fmt = fmt; 1319 xlate->host_fmt = fmt;
1317 xlate->code = code; 1320 xlate->code = code.code;
1318 xlate++; 1321 xlate++;
1319 } 1322 }
1320 1323
@@ -1346,7 +1349,10 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1346 .master_clock = pcdev->mclk, 1349 .master_clock = pcdev->mclk,
1347 .pixel_clock_max = pcdev->ciclk / 4, 1350 .pixel_clock_max = pcdev->ciclk / 4,
1348 }; 1351 };
1349 struct v4l2_mbus_framefmt mf; 1352 struct v4l2_subdev_format fmt = {
1353 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1354 };
1355 struct v4l2_mbus_framefmt *mf = &fmt.format;
1350 struct pxa_cam *cam = icd->host_priv; 1356 struct pxa_cam *cam = icd->host_priv;
1351 u32 fourcc = icd->current_fmt->host_fmt->fourcc; 1357 u32 fourcc = icd->current_fmt->host_fmt->fourcc;
1352 int ret; 1358 int ret;
@@ -1365,23 +1371,23 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1365 return ret; 1371 return ret;
1366 } 1372 }
1367 1373
1368 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 1374 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
1369 if (ret < 0) 1375 if (ret < 0)
1370 return ret; 1376 return ret;
1371 1377
1372 if (pxa_camera_check_frame(mf.width, mf.height)) { 1378 if (pxa_camera_check_frame(mf->width, mf->height)) {
1373 /* 1379 /*
1374 * Camera cropping produced a frame beyond our capabilities. 1380 * Camera cropping produced a frame beyond our capabilities.
1375 * FIXME: just extract a subframe, that we can process. 1381 * FIXME: just extract a subframe, that we can process.
1376 */ 1382 */
1377 v4l_bound_align_image(&mf.width, 48, 2048, 1, 1383 v4l_bound_align_image(&mf->width, 48, 2048, 1,
1378 &mf.height, 32, 2048, 0, 1384 &mf->height, 32, 2048, 0,
1379 fourcc == V4L2_PIX_FMT_YUV422P ? 4 : 0); 1385 fourcc == V4L2_PIX_FMT_YUV422P ? 4 : 0);
1380 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 1386 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &fmt);
1381 if (ret < 0) 1387 if (ret < 0)
1382 return ret; 1388 return ret;
1383 1389
1384 if (pxa_camera_check_frame(mf.width, mf.height)) { 1390 if (pxa_camera_check_frame(mf->width, mf->height)) {
1385 dev_warn(icd->parent, 1391 dev_warn(icd->parent,
1386 "Inconsistent state. Use S_FMT to repair\n"); 1392 "Inconsistent state. Use S_FMT to repair\n");
1387 return -EINVAL; 1393 return -EINVAL;
@@ -1398,8 +1404,8 @@ static int pxa_camera_set_crop(struct soc_camera_device *icd,
1398 recalculate_fifo_timeout(pcdev, sense.pixel_clock); 1404 recalculate_fifo_timeout(pcdev, sense.pixel_clock);
1399 } 1405 }
1400 1406
1401 icd->user_width = mf.width; 1407 icd->user_width = mf->width;
1402 icd->user_height = mf.height; 1408 icd->user_height = mf->height;
1403 1409
1404 pxa_camera_setup_cicr(icd, cam->flags, fourcc); 1410 pxa_camera_setup_cicr(icd, cam->flags, fourcc);
1405 1411
@@ -1419,7 +1425,10 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1419 .pixel_clock_max = pcdev->ciclk / 4, 1425 .pixel_clock_max = pcdev->ciclk / 4,
1420 }; 1426 };
1421 struct v4l2_pix_format *pix = &f->fmt.pix; 1427 struct v4l2_pix_format *pix = &f->fmt.pix;
1422 struct v4l2_mbus_framefmt mf; 1428 struct v4l2_subdev_format format = {
1429 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1430 };
1431 struct v4l2_mbus_framefmt *mf = &format.format;
1423 int ret; 1432 int ret;
1424 1433
1425 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 1434 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
@@ -1433,15 +1442,15 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1433 /* The caller holds a mutex. */ 1442 /* The caller holds a mutex. */
1434 icd->sense = &sense; 1443 icd->sense = &sense;
1435 1444
1436 mf.width = pix->width; 1445 mf->width = pix->width;
1437 mf.height = pix->height; 1446 mf->height = pix->height;
1438 mf.field = pix->field; 1447 mf->field = pix->field;
1439 mf.colorspace = pix->colorspace; 1448 mf->colorspace = pix->colorspace;
1440 mf.code = xlate->code; 1449 mf->code = xlate->code;
1441 1450
1442 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 1451 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format);
1443 1452
1444 if (mf.code != xlate->code) 1453 if (mf->code != xlate->code)
1445 return -EINVAL; 1454 return -EINVAL;
1446 1455
1447 icd->sense = NULL; 1456 icd->sense = NULL;
@@ -1449,10 +1458,10 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1449 if (ret < 0) { 1458 if (ret < 0) {
1450 dev_warn(dev, "Failed to configure for format %x\n", 1459 dev_warn(dev, "Failed to configure for format %x\n",
1451 pix->pixelformat); 1460 pix->pixelformat);
1452 } else if (pxa_camera_check_frame(mf.width, mf.height)) { 1461 } else if (pxa_camera_check_frame(mf->width, mf->height)) {
1453 dev_warn(dev, 1462 dev_warn(dev,
1454 "Camera driver produced an unsupported frame %dx%d\n", 1463 "Camera driver produced an unsupported frame %dx%d\n",
1455 mf.width, mf.height); 1464 mf->width, mf->height);
1456 ret = -EINVAL; 1465 ret = -EINVAL;
1457 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { 1466 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) {
1458 if (sense.pixel_clock > sense.pixel_clock_max) { 1467 if (sense.pixel_clock > sense.pixel_clock_max) {
@@ -1467,10 +1476,10 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1467 if (ret < 0) 1476 if (ret < 0)
1468 return ret; 1477 return ret;
1469 1478
1470 pix->width = mf.width; 1479 pix->width = mf->width;
1471 pix->height = mf.height; 1480 pix->height = mf->height;
1472 pix->field = mf.field; 1481 pix->field = mf->field;
1473 pix->colorspace = mf.colorspace; 1482 pix->colorspace = mf->colorspace;
1474 icd->current_fmt = xlate; 1483 icd->current_fmt = xlate;
1475 1484
1476 return ret; 1485 return ret;
@@ -1482,7 +1491,11 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1482 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1491 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1483 const struct soc_camera_format_xlate *xlate; 1492 const struct soc_camera_format_xlate *xlate;
1484 struct v4l2_pix_format *pix = &f->fmt.pix; 1493 struct v4l2_pix_format *pix = &f->fmt.pix;
1485 struct v4l2_mbus_framefmt mf; 1494 struct v4l2_subdev_pad_config pad_cfg;
1495 struct v4l2_subdev_format format = {
1496 .which = V4L2_SUBDEV_FORMAT_TRY,
1497 };
1498 struct v4l2_mbus_framefmt *mf = &format.format;
1486 __u32 pixfmt = pix->pixelformat; 1499 __u32 pixfmt = pix->pixelformat;
1487 int ret; 1500 int ret;
1488 1501
@@ -1503,22 +1516,22 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1503 pixfmt == V4L2_PIX_FMT_YUV422P ? 4 : 0); 1516 pixfmt == V4L2_PIX_FMT_YUV422P ? 4 : 0);
1504 1517
1505 /* limit to sensor capabilities */ 1518 /* limit to sensor capabilities */
1506 mf.width = pix->width; 1519 mf->width = pix->width;
1507 mf.height = pix->height; 1520 mf->height = pix->height;
1508 /* Only progressive video supported so far */ 1521 /* Only progressive video supported so far */
1509 mf.field = V4L2_FIELD_NONE; 1522 mf->field = V4L2_FIELD_NONE;
1510 mf.colorspace = pix->colorspace; 1523 mf->colorspace = pix->colorspace;
1511 mf.code = xlate->code; 1524 mf->code = xlate->code;
1512 1525
1513 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 1526 ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format);
1514 if (ret < 0) 1527 if (ret < 0)
1515 return ret; 1528 return ret;
1516 1529
1517 pix->width = mf.width; 1530 pix->width = mf->width;
1518 pix->height = mf.height; 1531 pix->height = mf->height;
1519 pix->colorspace = mf.colorspace; 1532 pix->colorspace = mf->colorspace;
1520 1533
1521 switch (mf.field) { 1534 switch (mf->field) {
1522 case V4L2_FIELD_ANY: 1535 case V4L2_FIELD_ANY:
1523 case V4L2_FIELD_NONE: 1536 case V4L2_FIELD_NONE:
1524 pix->field = V4L2_FIELD_NONE; 1537 pix->field = V4L2_FIELD_NONE;
@@ -1526,7 +1539,7 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd,
1526 default: 1539 default:
1527 /* TODO: support interlaced at least in pass-through mode */ 1540 /* TODO: support interlaced at least in pass-through mode */
1528 dev_err(icd->parent, "Field type %d unsupported.\n", 1541 dev_err(icd->parent, "Field type %d unsupported.\n",
1529 mf.field); 1542 mf->field);
1530 return -EINVAL; 1543 return -EINVAL;
1531 } 1544 }
1532 1545
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index 6460f8e1b07f..db7700b0af7c 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -899,7 +899,7 @@ static irqreturn_t rcar_vin_irq(int irq, void *data)
899 899
900 priv->queue_buf[slot]->v4l2_buf.field = priv->field; 900 priv->queue_buf[slot]->v4l2_buf.field = priv->field;
901 priv->queue_buf[slot]->v4l2_buf.sequence = priv->sequence++; 901 priv->queue_buf[slot]->v4l2_buf.sequence = priv->sequence++;
902 do_gettimeofday(&priv->queue_buf[slot]->v4l2_buf.timestamp); 902 v4l2_get_timestamp(&priv->queue_buf[slot]->v4l2_buf.timestamp);
903 vb2_buffer_done(priv->queue_buf[slot], VB2_BUF_STATE_DONE); 903 vb2_buffer_done(priv->queue_buf[slot], VB2_BUF_STATE_DONE);
904 priv->queue_buf[slot] = NULL; 904 priv->queue_buf[slot] = NULL;
905 905
@@ -1323,16 +1323,19 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1323 int ret, k, n; 1323 int ret, k, n;
1324 int formats = 0; 1324 int formats = 0;
1325 struct rcar_vin_cam *cam; 1325 struct rcar_vin_cam *cam;
1326 u32 code; 1326 struct v4l2_subdev_mbus_code_enum code = {
1327 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1328 .index = idx,
1329 };
1327 const struct soc_mbus_pixelfmt *fmt; 1330 const struct soc_mbus_pixelfmt *fmt;
1328 1331
1329 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 1332 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
1330 if (ret < 0) 1333 if (ret < 0)
1331 return 0; 1334 return 0;
1332 1335
1333 fmt = soc_mbus_get_fmtdesc(code); 1336 fmt = soc_mbus_get_fmtdesc(code.code);
1334 if (!fmt) { 1337 if (!fmt) {
1335 dev_warn(dev, "unsupported format code #%u: %d\n", idx, code); 1338 dev_warn(dev, "unsupported format code #%u: %d\n", idx, code.code);
1336 return 0; 1339 return 0;
1337 } 1340 }
1338 1341
@@ -1341,12 +1344,15 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1341 return 0; 1344 return 0;
1342 1345
1343 if (!icd->host_priv) { 1346 if (!icd->host_priv) {
1344 struct v4l2_mbus_framefmt mf; 1347 struct v4l2_subdev_format fmt = {
1348 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1349 };
1350 struct v4l2_mbus_framefmt *mf = &fmt.format;
1345 struct v4l2_rect rect; 1351 struct v4l2_rect rect;
1346 struct device *dev = icd->parent; 1352 struct device *dev = icd->parent;
1347 int shift; 1353 int shift;
1348 1354
1349 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 1355 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
1350 if (ret < 0) 1356 if (ret < 0)
1351 return ret; 1357 return ret;
1352 1358
@@ -1356,8 +1362,8 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1356 /* Sensor driver doesn't support cropping */ 1362 /* Sensor driver doesn't support cropping */
1357 rect.left = 0; 1363 rect.left = 0;
1358 rect.top = 0; 1364 rect.top = 0;
1359 rect.width = mf.width; 1365 rect.width = mf->width;
1360 rect.height = mf.height; 1366 rect.height = mf->height;
1361 } else if (ret < 0) { 1367 } else if (ret < 0) {
1362 return ret; 1368 return ret;
1363 } 1369 }
@@ -1367,16 +1373,16 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1367 * 1280x960, 640x480, 320x240 1373 * 1280x960, 640x480, 320x240
1368 */ 1374 */
1369 for (shift = 0; shift < 3; shift++) { 1375 for (shift = 0; shift < 3; shift++) {
1370 if (mf.width <= VIN_MAX_WIDTH && 1376 if (mf->width <= VIN_MAX_WIDTH &&
1371 mf.height <= VIN_MAX_HEIGHT) 1377 mf->height <= VIN_MAX_HEIGHT)
1372 break; 1378 break;
1373 1379
1374 mf.width = 1280 >> shift; 1380 mf->width = 1280 >> shift;
1375 mf.height = 960 >> shift; 1381 mf->height = 960 >> shift;
1376 ret = v4l2_device_call_until_err(sd->v4l2_dev, 1382 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1377 soc_camera_grp_id(icd), 1383 soc_camera_grp_id(icd),
1378 video, s_mbus_fmt, 1384 pad, set_fmt, NULL,
1379 &mf); 1385 &fmt);
1380 if (ret < 0) 1386 if (ret < 0)
1381 return ret; 1387 return ret;
1382 } 1388 }
@@ -1384,11 +1390,11 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1384 if (shift == 3) { 1390 if (shift == 3) {
1385 dev_err(dev, 1391 dev_err(dev,
1386 "Failed to configure the client below %ux%u\n", 1392 "Failed to configure the client below %ux%u\n",
1387 mf.width, mf.height); 1393 mf->width, mf->height);
1388 return -EIO; 1394 return -EIO;
1389 } 1395 }
1390 1396
1391 dev_dbg(dev, "camera fmt %ux%u\n", mf.width, mf.height); 1397 dev_dbg(dev, "camera fmt %ux%u\n", mf->width, mf->height);
1392 1398
1393 cam = kzalloc(sizeof(*cam), GFP_KERNEL); 1399 cam = kzalloc(sizeof(*cam), GFP_KERNEL);
1394 if (!cam) 1400 if (!cam)
@@ -1399,10 +1405,10 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1399 */ 1405 */
1400 cam->rect = rect; 1406 cam->rect = rect;
1401 cam->subrect = rect; 1407 cam->subrect = rect;
1402 cam->width = mf.width; 1408 cam->width = mf->width;
1403 cam->height = mf.height; 1409 cam->height = mf->height;
1404 cam->out_width = mf.width; 1410 cam->out_width = mf->width;
1405 cam->out_height = mf.height; 1411 cam->out_height = mf->height;
1406 1412
1407 icd->host_priv = cam; 1413 icd->host_priv = cam;
1408 } else { 1414 } else {
@@ -1413,7 +1419,7 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1413 if (!idx) 1419 if (!idx)
1414 cam->extra_fmt = NULL; 1420 cam->extra_fmt = NULL;
1415 1421
1416 switch (code) { 1422 switch (code.code) {
1417 case MEDIA_BUS_FMT_YUYV8_1X16: 1423 case MEDIA_BUS_FMT_YUYV8_1X16:
1418 case MEDIA_BUS_FMT_YUYV8_2X8: 1424 case MEDIA_BUS_FMT_YUYV8_2X8:
1419 case MEDIA_BUS_FMT_YUYV10_2X10: 1425 case MEDIA_BUS_FMT_YUYV10_2X10:
@@ -1427,9 +1433,9 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1427 formats += n; 1433 formats += n;
1428 for (k = 0; xlate && k < n; k++, xlate++) { 1434 for (k = 0; xlate && k < n; k++, xlate++) {
1429 xlate->host_fmt = &rcar_vin_formats[k]; 1435 xlate->host_fmt = &rcar_vin_formats[k];
1430 xlate->code = code; 1436 xlate->code = code.code;
1431 dev_dbg(dev, "Providing format %s using code %d\n", 1437 dev_dbg(dev, "Providing format %s using code %d\n",
1432 rcar_vin_formats[k].name, code); 1438 rcar_vin_formats[k].name, code.code);
1433 } 1439 }
1434 break; 1440 break;
1435 default: 1441 default:
@@ -1445,7 +1451,7 @@ static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
1445 formats++; 1451 formats++;
1446 if (xlate) { 1452 if (xlate) {
1447 xlate->host_fmt = fmt; 1453 xlate->host_fmt = fmt;
1448 xlate->code = code; 1454 xlate->code = code.code;
1449 xlate++; 1455 xlate++;
1450 } 1456 }
1451 1457
@@ -1470,7 +1476,10 @@ static int rcar_vin_set_crop(struct soc_camera_device *icd,
1470 struct v4l2_rect *cam_rect = &cam_crop.c; 1476 struct v4l2_rect *cam_rect = &cam_crop.c;
1471 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1477 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1472 struct device *dev = icd->parent; 1478 struct device *dev = icd->parent;
1473 struct v4l2_mbus_framefmt mf; 1479 struct v4l2_subdev_format fmt = {
1480 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1481 };
1482 struct v4l2_mbus_framefmt *mf = &fmt.format;
1474 u32 vnmc; 1483 u32 vnmc;
1475 int ret, i; 1484 int ret, i;
1476 1485
@@ -1494,16 +1503,16 @@ static int rcar_vin_set_crop(struct soc_camera_device *icd,
1494 /* On success cam_crop contains current camera crop */ 1503 /* On success cam_crop contains current camera crop */
1495 1504
1496 /* Retrieve camera output window */ 1505 /* Retrieve camera output window */
1497 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 1506 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
1498 if (ret < 0) 1507 if (ret < 0)
1499 return ret; 1508 return ret;
1500 1509
1501 if (mf.width > VIN_MAX_WIDTH || mf.height > VIN_MAX_HEIGHT) 1510 if (mf->width > VIN_MAX_WIDTH || mf->height > VIN_MAX_HEIGHT)
1502 return -EINVAL; 1511 return -EINVAL;
1503 1512
1504 /* Cache camera output window */ 1513 /* Cache camera output window */
1505 cam->width = mf.width; 1514 cam->width = mf->width;
1506 cam->height = mf.height; 1515 cam->height = mf->height;
1507 1516
1508 icd->user_width = cam->width; 1517 icd->user_width = cam->width;
1509 icd->user_height = cam->height; 1518 icd->user_height = cam->height;
@@ -1679,7 +1688,11 @@ static int rcar_vin_try_fmt(struct soc_camera_device *icd,
1679 const struct soc_camera_format_xlate *xlate; 1688 const struct soc_camera_format_xlate *xlate;
1680 struct v4l2_pix_format *pix = &f->fmt.pix; 1689 struct v4l2_pix_format *pix = &f->fmt.pix;
1681 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1690 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1682 struct v4l2_mbus_framefmt mf; 1691 struct v4l2_subdev_pad_config pad_cfg;
1692 struct v4l2_subdev_format format = {
1693 .which = V4L2_SUBDEV_FORMAT_TRY,
1694 };
1695 struct v4l2_mbus_framefmt *mf = &format.format;
1683 __u32 pixfmt = pix->pixelformat; 1696 __u32 pixfmt = pix->pixelformat;
1684 int width, height; 1697 int width, height;
1685 int ret; 1698 int ret;
@@ -1706,25 +1719,25 @@ static int rcar_vin_try_fmt(struct soc_camera_device *icd,
1706 pix->sizeimage = 0; 1719 pix->sizeimage = 0;
1707 1720
1708 /* limit to sensor capabilities */ 1721 /* limit to sensor capabilities */
1709 mf.width = pix->width; 1722 mf->width = pix->width;
1710 mf.height = pix->height; 1723 mf->height = pix->height;
1711 mf.field = pix->field; 1724 mf->field = pix->field;
1712 mf.code = xlate->code; 1725 mf->code = xlate->code;
1713 mf.colorspace = pix->colorspace; 1726 mf->colorspace = pix->colorspace;
1714 1727
1715 ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd), 1728 ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd),
1716 video, try_mbus_fmt, &mf); 1729 pad, set_fmt, &pad_cfg, &format);
1717 if (ret < 0) 1730 if (ret < 0)
1718 return ret; 1731 return ret;
1719 1732
1720 /* Adjust only if VIN cannot scale */ 1733 /* Adjust only if VIN cannot scale */
1721 if (pix->width > mf.width * 2) 1734 if (pix->width > mf->width * 2)
1722 pix->width = mf.width * 2; 1735 pix->width = mf->width * 2;
1723 if (pix->height > mf.height * 3) 1736 if (pix->height > mf->height * 3)
1724 pix->height = mf.height * 3; 1737 pix->height = mf->height * 3;
1725 1738
1726 pix->field = mf.field; 1739 pix->field = mf->field;
1727 pix->colorspace = mf.colorspace; 1740 pix->colorspace = mf->colorspace;
1728 1741
1729 if (pixfmt == V4L2_PIX_FMT_NV16) { 1742 if (pixfmt == V4L2_PIX_FMT_NV16) {
1730 /* FIXME: check against rect_max after converting soc-camera */ 1743 /* FIXME: check against rect_max after converting soc-camera */
@@ -1735,12 +1748,12 @@ static int rcar_vin_try_fmt(struct soc_camera_device *icd,
1735 * requested a bigger rectangle, it will not return a 1748 * requested a bigger rectangle, it will not return a
1736 * smaller one. 1749 * smaller one.
1737 */ 1750 */
1738 mf.width = VIN_MAX_WIDTH; 1751 mf->width = VIN_MAX_WIDTH;
1739 mf.height = VIN_MAX_HEIGHT; 1752 mf->height = VIN_MAX_HEIGHT;
1740 ret = v4l2_device_call_until_err(sd->v4l2_dev, 1753 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1741 soc_camera_grp_id(icd), 1754 soc_camera_grp_id(icd),
1742 video, try_mbus_fmt, 1755 pad, set_fmt, &pad_cfg,
1743 &mf); 1756 &format);
1744 if (ret < 0) { 1757 if (ret < 0) {
1745 dev_err(icd->parent, 1758 dev_err(icd->parent,
1746 "client try_fmt() = %d\n", ret); 1759 "client try_fmt() = %d\n", ret);
@@ -1748,9 +1761,9 @@ static int rcar_vin_try_fmt(struct soc_camera_device *icd,
1748 } 1761 }
1749 } 1762 }
1750 /* We will scale exactly */ 1763 /* We will scale exactly */
1751 if (mf.width > width) 1764 if (mf->width > width)
1752 pix->width = width; 1765 pix->width = width;
1753 if (mf.height > height) 1766 if (mf->height > height)
1754 pix->height = height; 1767 pix->height = height;
1755 } 1768 }
1756 1769
@@ -1808,7 +1821,7 @@ static struct soc_camera_host_ops rcar_vin_host_ops = {
1808}; 1821};
1809 1822
1810#ifdef CONFIG_OF 1823#ifdef CONFIG_OF
1811static struct of_device_id rcar_vin_of_table[] = { 1824static const struct of_device_id rcar_vin_of_table[] = {
1812 { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 }, 1825 { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
1813 { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 }, 1826 { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
1814 { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 }, 1827 { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
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 9ce202f53934..c5c6c4e91f7b 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -1048,17 +1048,20 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1048 int ret, k, n; 1048 int ret, k, n;
1049 int formats = 0; 1049 int formats = 0;
1050 struct sh_mobile_ceu_cam *cam; 1050 struct sh_mobile_ceu_cam *cam;
1051 u32 code; 1051 struct v4l2_subdev_mbus_code_enum code = {
1052 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1053 .index = idx,
1054 };
1052 const struct soc_mbus_pixelfmt *fmt; 1055 const struct soc_mbus_pixelfmt *fmt;
1053 1056
1054 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); 1057 ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
1055 if (ret < 0) 1058 if (ret < 0)
1056 /* No more formats */ 1059 /* No more formats */
1057 return 0; 1060 return 0;
1058 1061
1059 fmt = soc_mbus_get_fmtdesc(code); 1062 fmt = soc_mbus_get_fmtdesc(code.code);
1060 if (!fmt) { 1063 if (!fmt) {
1061 dev_warn(dev, "unsupported format code #%u: %d\n", idx, code); 1064 dev_warn(dev, "unsupported format code #%u: %d\n", idx, code.code);
1062 return 0; 1065 return 0;
1063 } 1066 }
1064 1067
@@ -1070,7 +1073,10 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1070 } 1073 }
1071 1074
1072 if (!icd->host_priv) { 1075 if (!icd->host_priv) {
1073 struct v4l2_mbus_framefmt mf; 1076 struct v4l2_subdev_format fmt = {
1077 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1078 };
1079 struct v4l2_mbus_framefmt *mf = &fmt.format;
1074 struct v4l2_rect rect; 1080 struct v4l2_rect rect;
1075 int shift = 0; 1081 int shift = 0;
1076 1082
@@ -1088,7 +1094,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1088 return ret; 1094 return ret;
1089 1095
1090 /* First time */ 1096 /* First time */
1091 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 1097 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
1092 if (ret < 0) 1098 if (ret < 0)
1093 return ret; 1099 return ret;
1094 1100
@@ -1099,14 +1105,14 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1099 * sizes, just try VGA multiples. If needed, this can be 1105 * sizes, just try VGA multiples. If needed, this can be
1100 * adjusted in the future. 1106 * adjusted in the future.
1101 */ 1107 */
1102 while ((mf.width > pcdev->max_width || 1108 while ((mf->width > pcdev->max_width ||
1103 mf.height > pcdev->max_height) && shift < 4) { 1109 mf->height > pcdev->max_height) && shift < 4) {
1104 /* Try 2560x1920, 1280x960, 640x480, 320x240 */ 1110 /* Try 2560x1920, 1280x960, 640x480, 320x240 */
1105 mf.width = 2560 >> shift; 1111 mf->width = 2560 >> shift;
1106 mf.height = 1920 >> shift; 1112 mf->height = 1920 >> shift;
1107 ret = v4l2_device_call_until_err(sd->v4l2_dev, 1113 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1108 soc_camera_grp_id(icd), video, 1114 soc_camera_grp_id(icd), pad,
1109 s_mbus_fmt, &mf); 1115 set_fmt, NULL, &fmt);
1110 if (ret < 0) 1116 if (ret < 0)
1111 return ret; 1117 return ret;
1112 shift++; 1118 shift++;
@@ -1114,11 +1120,11 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1114 1120
1115 if (shift == 4) { 1121 if (shift == 4) {
1116 dev_err(dev, "Failed to configure the client below %ux%x\n", 1122 dev_err(dev, "Failed to configure the client below %ux%x\n",
1117 mf.width, mf.height); 1123 mf->width, mf->height);
1118 return -EIO; 1124 return -EIO;
1119 } 1125 }
1120 1126
1121 dev_geo(dev, "camera fmt %ux%u\n", mf.width, mf.height); 1127 dev_geo(dev, "camera fmt %ux%u\n", mf->width, mf->height);
1122 1128
1123 cam = kzalloc(sizeof(*cam), GFP_KERNEL); 1129 cam = kzalloc(sizeof(*cam), GFP_KERNEL);
1124 if (!cam) 1130 if (!cam)
@@ -1128,8 +1134,8 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1128 cam->rect = rect; 1134 cam->rect = rect;
1129 cam->subrect = rect; 1135 cam->subrect = rect;
1130 1136
1131 cam->width = mf.width; 1137 cam->width = mf->width;
1132 cam->height = mf.height; 1138 cam->height = mf->height;
1133 1139
1134 icd->host_priv = cam; 1140 icd->host_priv = cam;
1135 } else { 1141 } else {
@@ -1140,7 +1146,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1140 if (!idx) 1146 if (!idx)
1141 cam->extra_fmt = NULL; 1147 cam->extra_fmt = NULL;
1142 1148
1143 switch (code) { 1149 switch (code.code) {
1144 case MEDIA_BUS_FMT_UYVY8_2X8: 1150 case MEDIA_BUS_FMT_UYVY8_2X8:
1145 case MEDIA_BUS_FMT_VYUY8_2X8: 1151 case MEDIA_BUS_FMT_VYUY8_2X8:
1146 case MEDIA_BUS_FMT_YUYV8_2X8: 1152 case MEDIA_BUS_FMT_YUYV8_2X8:
@@ -1163,10 +1169,10 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1163 formats += n; 1169 formats += n;
1164 for (k = 0; xlate && k < n; k++) { 1170 for (k = 0; xlate && k < n; k++) {
1165 xlate->host_fmt = &sh_mobile_ceu_formats[k]; 1171 xlate->host_fmt = &sh_mobile_ceu_formats[k];
1166 xlate->code = code; 1172 xlate->code = code.code;
1167 xlate++; 1173 xlate++;
1168 dev_dbg(dev, "Providing format %s using code %d\n", 1174 dev_dbg(dev, "Providing format %s using code %d\n",
1169 sh_mobile_ceu_formats[k].name, code); 1175 sh_mobile_ceu_formats[k].name, code.code);
1170 } 1176 }
1171 break; 1177 break;
1172 default: 1178 default:
@@ -1178,7 +1184,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1178 formats++; 1184 formats++;
1179 if (xlate) { 1185 if (xlate) {
1180 xlate->host_fmt = fmt; 1186 xlate->host_fmt = fmt;
1181 xlate->code = code; 1187 xlate->code = code.code;
1182 xlate++; 1188 xlate++;
1183 dev_dbg(dev, "Providing format %s in pass-through mode\n", 1189 dev_dbg(dev, "Providing format %s in pass-through mode\n",
1184 fmt->name); 1190 fmt->name);
@@ -1214,7 +1220,10 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1214 struct sh_mobile_ceu_cam *cam = icd->host_priv; 1220 struct sh_mobile_ceu_cam *cam = icd->host_priv;
1215 struct v4l2_rect *cam_rect = &cam_crop.c; 1221 struct v4l2_rect *cam_rect = &cam_crop.c;
1216 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1222 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1217 struct v4l2_mbus_framefmt mf; 1223 struct v4l2_subdev_format fmt = {
1224 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1225 };
1226 struct v4l2_mbus_framefmt *mf = &fmt.format;
1218 unsigned int scale_cam_h, scale_cam_v, scale_ceu_h, scale_ceu_v, 1227 unsigned int scale_cam_h, scale_cam_v, scale_ceu_h, scale_ceu_v,
1219 out_width, out_height; 1228 out_width, out_height;
1220 int interm_width, interm_height; 1229 int interm_width, interm_height;
@@ -1244,16 +1253,16 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1244 /* On success cam_crop contains current camera crop */ 1253 /* On success cam_crop contains current camera crop */
1245 1254
1246 /* 3. Retrieve camera output window */ 1255 /* 3. Retrieve camera output window */
1247 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); 1256 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
1248 if (ret < 0) 1257 if (ret < 0)
1249 return ret; 1258 return ret;
1250 1259
1251 if (mf.width > pcdev->max_width || mf.height > pcdev->max_height) 1260 if (mf->width > pcdev->max_width || mf->height > pcdev->max_height)
1252 return -EINVAL; 1261 return -EINVAL;
1253 1262
1254 /* 4. Calculate camera scales */ 1263 /* 4. Calculate camera scales */
1255 scale_cam_h = calc_generic_scale(cam_rect->width, mf.width); 1264 scale_cam_h = calc_generic_scale(cam_rect->width, mf->width);
1256 scale_cam_v = calc_generic_scale(cam_rect->height, mf.height); 1265 scale_cam_v = calc_generic_scale(cam_rect->height, mf->height);
1257 1266
1258 /* Calculate intermediate window */ 1267 /* Calculate intermediate window */
1259 interm_width = scale_down(rect->width, scale_cam_h); 1268 interm_width = scale_down(rect->width, scale_cam_h);
@@ -1264,7 +1273,7 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1264 1273
1265 new_scale_h = calc_generic_scale(rect->width, icd->user_width); 1274 new_scale_h = calc_generic_scale(rect->width, icd->user_width);
1266 1275
1267 mf.width = scale_down(cam_rect->width, new_scale_h); 1276 mf->width = scale_down(cam_rect->width, new_scale_h);
1268 } 1277 }
1269 1278
1270 if (interm_height < icd->user_height) { 1279 if (interm_height < icd->user_height) {
@@ -1272,26 +1281,26 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1272 1281
1273 new_scale_v = calc_generic_scale(rect->height, icd->user_height); 1282 new_scale_v = calc_generic_scale(rect->height, icd->user_height);
1274 1283
1275 mf.height = scale_down(cam_rect->height, new_scale_v); 1284 mf->height = scale_down(cam_rect->height, new_scale_v);
1276 } 1285 }
1277 1286
1278 if (interm_width < icd->user_width || interm_height < icd->user_height) { 1287 if (interm_width < icd->user_width || interm_height < icd->user_height) {
1279 ret = v4l2_device_call_until_err(sd->v4l2_dev, 1288 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1280 soc_camera_grp_id(icd), video, 1289 soc_camera_grp_id(icd), pad,
1281 s_mbus_fmt, &mf); 1290 set_fmt, NULL, &fmt);
1282 if (ret < 0) 1291 if (ret < 0)
1283 return ret; 1292 return ret;
1284 1293
1285 dev_geo(dev, "New camera output %ux%u\n", mf.width, mf.height); 1294 dev_geo(dev, "New camera output %ux%u\n", mf->width, mf->height);
1286 scale_cam_h = calc_generic_scale(cam_rect->width, mf.width); 1295 scale_cam_h = calc_generic_scale(cam_rect->width, mf->width);
1287 scale_cam_v = calc_generic_scale(cam_rect->height, mf.height); 1296 scale_cam_v = calc_generic_scale(cam_rect->height, mf->height);
1288 interm_width = scale_down(rect->width, scale_cam_h); 1297 interm_width = scale_down(rect->width, scale_cam_h);
1289 interm_height = scale_down(rect->height, scale_cam_v); 1298 interm_height = scale_down(rect->height, scale_cam_v);
1290 } 1299 }
1291 1300
1292 /* Cache camera output window */ 1301 /* Cache camera output window */
1293 cam->width = mf.width; 1302 cam->width = mf->width;
1294 cam->height = mf.height; 1303 cam->height = mf->height;
1295 1304
1296 if (pcdev->image_mode) { 1305 if (pcdev->image_mode) {
1297 out_width = min(interm_width, icd->user_width); 1306 out_width = min(interm_width, icd->user_width);
@@ -1490,7 +1499,11 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1490 const struct soc_camera_format_xlate *xlate; 1499 const struct soc_camera_format_xlate *xlate;
1491 struct v4l2_pix_format *pix = &f->fmt.pix; 1500 struct v4l2_pix_format *pix = &f->fmt.pix;
1492 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1501 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1493 struct v4l2_mbus_framefmt mf; 1502 struct v4l2_subdev_pad_config pad_cfg;
1503 struct v4l2_subdev_format format = {
1504 .which = V4L2_SUBDEV_FORMAT_TRY,
1505 };
1506 struct v4l2_mbus_framefmt *mf = &format.format;
1494 __u32 pixfmt = pix->pixelformat; 1507 __u32 pixfmt = pix->pixelformat;
1495 int width, height; 1508 int width, height;
1496 int ret; 1509 int ret;
@@ -1518,21 +1531,21 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1518 height = pix->height; 1531 height = pix->height;
1519 1532
1520 /* limit to sensor capabilities */ 1533 /* limit to sensor capabilities */
1521 mf.width = pix->width; 1534 mf->width = pix->width;
1522 mf.height = pix->height; 1535 mf->height = pix->height;
1523 mf.field = pix->field; 1536 mf->field = pix->field;
1524 mf.code = xlate->code; 1537 mf->code = xlate->code;
1525 mf.colorspace = pix->colorspace; 1538 mf->colorspace = pix->colorspace;
1526 1539
1527 ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd), 1540 ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd),
1528 video, try_mbus_fmt, &mf); 1541 pad, set_fmt, &pad_cfg, &format);
1529 if (ret < 0) 1542 if (ret < 0)
1530 return ret; 1543 return ret;
1531 1544
1532 pix->width = mf.width; 1545 pix->width = mf->width;
1533 pix->height = mf.height; 1546 pix->height = mf->height;
1534 pix->field = mf.field; 1547 pix->field = mf->field;
1535 pix->colorspace = mf.colorspace; 1548 pix->colorspace = mf->colorspace;
1536 1549
1537 switch (pixfmt) { 1550 switch (pixfmt) {
1538 case V4L2_PIX_FMT_NV12: 1551 case V4L2_PIX_FMT_NV12:
@@ -1547,11 +1560,11 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1547 * requested a bigger rectangle, it will not return a 1560 * requested a bigger rectangle, it will not return a
1548 * smaller one. 1561 * smaller one.
1549 */ 1562 */
1550 mf.width = pcdev->max_width; 1563 mf->width = pcdev->max_width;
1551 mf.height = pcdev->max_height; 1564 mf->height = pcdev->max_height;
1552 ret = v4l2_device_call_until_err(sd->v4l2_dev, 1565 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1553 soc_camera_grp_id(icd), video, 1566 soc_camera_grp_id(icd), pad,
1554 try_mbus_fmt, &mf); 1567 set_fmt, &pad_cfg, &format);
1555 if (ret < 0) { 1568 if (ret < 0) {
1556 /* Shouldn't actually happen... */ 1569 /* Shouldn't actually happen... */
1557 dev_err(icd->parent, 1570 dev_err(icd->parent,
@@ -1560,9 +1573,9 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1560 } 1573 }
1561 } 1574 }
1562 /* We will scale exactly */ 1575 /* We will scale exactly */
1563 if (mf.width > width) 1576 if (mf->width > width)
1564 pix->width = width; 1577 pix->width = width;
1565 if (mf.height > height) 1578 if (mf->height > height)
1566 pix->height = height; 1579 pix->height = height;
1567 1580
1568 pix->bytesperline = max(pix->bytesperline, pix->width); 1581 pix->bytesperline = max(pix->bytesperline, pix->width);
diff --git a/drivers/media/platform/soc_camera/sh_mobile_csi2.c b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
index cd93241eb497..12d3626ecf22 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_csi2.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
@@ -45,11 +45,17 @@ struct sh_csi2 {
45 45
46static void sh_csi2_hwinit(struct sh_csi2 *priv); 46static void sh_csi2_hwinit(struct sh_csi2 *priv);
47 47
48static int sh_csi2_try_fmt(struct v4l2_subdev *sd, 48static int sh_csi2_set_fmt(struct v4l2_subdev *sd,
49 struct v4l2_mbus_framefmt *mf) 49 struct v4l2_subdev_pad_config *cfg,
50 struct v4l2_subdev_format *format)
50{ 51{
51 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev); 52 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
52 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data; 53 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
54 struct v4l2_mbus_framefmt *mf = &format->format;
55 u32 tmp = (priv->client->channel & 3) << 8;
56
57 if (format->pad)
58 return -EINVAL;
53 59
54 if (mf->width > 8188) 60 if (mf->width > 8188)
55 mf->width = 8188; 61 mf->width = 8188;
@@ -85,21 +91,11 @@ static int sh_csi2_try_fmt(struct v4l2_subdev *sd,
85 break; 91 break;
86 } 92 }
87 93
88 return 0; 94 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
89} 95 cfg->try_fmt = *mf;
90 96 return 0;
91/* 97 }
92 * We have done our best in try_fmt to try and tell the sensor, which formats
93 * we support. If now the configuration is unsuitable for us we can only
94 * error out.
95 */
96static int sh_csi2_s_fmt(struct v4l2_subdev *sd,
97 struct v4l2_mbus_framefmt *mf)
98{
99 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
100 u32 tmp = (priv->client->channel & 3) << 8;
101 98
102 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
103 if (mf->width > 8188 || mf->width & 1) 99 if (mf->width > 8188 || mf->width & 1)
104 return -EINVAL; 100 return -EINVAL;
105 101
@@ -211,12 +207,14 @@ static int sh_csi2_s_mbus_config(struct v4l2_subdev *sd,
211} 207}
212 208
213static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = { 209static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
214 .s_mbus_fmt = sh_csi2_s_fmt,
215 .try_mbus_fmt = sh_csi2_try_fmt,
216 .g_mbus_config = sh_csi2_g_mbus_config, 210 .g_mbus_config = sh_csi2_g_mbus_config,
217 .s_mbus_config = sh_csi2_s_mbus_config, 211 .s_mbus_config = sh_csi2_s_mbus_config,
218}; 212};
219 213
214static struct v4l2_subdev_pad_ops sh_csi2_subdev_pad_ops = {
215 .set_fmt = sh_csi2_set_fmt,
216};
217
220static void sh_csi2_hwinit(struct sh_csi2 *priv) 218static void sh_csi2_hwinit(struct sh_csi2 *priv)
221{ 219{
222 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data; 220 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
@@ -313,6 +311,7 @@ static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops = {
313static struct v4l2_subdev_ops sh_csi2_subdev_ops = { 311static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
314 .core = &sh_csi2_subdev_core_ops, 312 .core = &sh_csi2_subdev_core_ops,
315 .video = &sh_csi2_subdev_video_ops, 313 .video = &sh_csi2_subdev_video_ops,
314 .pad = &sh_csi2_subdev_pad_ops,
316}; 315};
317 316
318static int sh_csi2_probe(struct platform_device *pdev) 317static int sh_csi2_probe(struct platform_device *pdev)
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 7bfe7665687f..d708df410f74 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -484,10 +484,14 @@ static int soc_camera_init_user_formats(struct soc_camera_device *icd)
484 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 484 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
485 unsigned int i, fmts = 0, raw_fmts = 0; 485 unsigned int i, fmts = 0, raw_fmts = 0;
486 int ret; 486 int ret;
487 u32 code; 487 struct v4l2_subdev_mbus_code_enum code = {
488 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
489 };
488 490
489 while (!v4l2_subdev_call(sd, video, enum_mbus_fmt, raw_fmts, &code)) 491 while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code)) {
490 raw_fmts++; 492 raw_fmts++;
493 code.index++;
494 }
491 495
492 if (!ici->ops->get_formats) 496 if (!ici->ops->get_formats)
493 /* 497 /*
@@ -521,11 +525,12 @@ static int soc_camera_init_user_formats(struct soc_camera_device *icd)
521 fmts = 0; 525 fmts = 0;
522 for (i = 0; i < raw_fmts; i++) 526 for (i = 0; i < raw_fmts; i++)
523 if (!ici->ops->get_formats) { 527 if (!ici->ops->get_formats) {
524 v4l2_subdev_call(sd, video, enum_mbus_fmt, i, &code); 528 code.index = i;
529 v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
525 icd->user_formats[fmts].host_fmt = 530 icd->user_formats[fmts].host_fmt =
526 soc_mbus_get_fmtdesc(code); 531 soc_mbus_get_fmtdesc(code.code);
527 if (icd->user_formats[fmts].host_fmt) 532 if (icd->user_formats[fmts].host_fmt)
528 icd->user_formats[fmts++].code = code; 533 icd->user_formats[fmts++].code = code.code;
529 } else { 534 } else {
530 ret = ici->ops->get_formats(icd, i, 535 ret = ici->ops->get_formats(icd, i,
531 &icd->user_formats[fmts]); 536 &icd->user_formats[fmts]);
@@ -1284,7 +1289,10 @@ static struct soc_camera_device *soc_camera_add_pdev(struct soc_camera_async_cli
1284static int soc_camera_probe_finish(struct soc_camera_device *icd) 1289static int soc_camera_probe_finish(struct soc_camera_device *icd)
1285{ 1290{
1286 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1291 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1287 struct v4l2_mbus_framefmt mf; 1292 struct v4l2_subdev_format fmt = {
1293 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1294 };
1295 struct v4l2_mbus_framefmt *mf = &fmt.format;
1288 int ret; 1296 int ret;
1289 1297
1290 sd->grp_id = soc_camera_grp_id(icd); 1298 sd->grp_id = soc_camera_grp_id(icd);
@@ -1314,11 +1322,11 @@ static int soc_camera_probe_finish(struct soc_camera_device *icd)
1314 goto evidstart; 1322 goto evidstart;
1315 1323
1316 /* Try to improve our guess of a reasonable window format */ 1324 /* Try to improve our guess of a reasonable window format */
1317 if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) { 1325 if (!v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt)) {
1318 icd->user_width = mf.width; 1326 icd->user_width = mf->width;
1319 icd->user_height = mf.height; 1327 icd->user_height = mf->height;
1320 icd->colorspace = mf.colorspace; 1328 icd->colorspace = mf->colorspace;
1321 icd->field = mf.field; 1329 icd->field = mf->field;
1322 } 1330 }
1323 soc_camera_remove_device(icd); 1331 soc_camera_remove_device(icd);
1324 1332
diff --git a/drivers/media/platform/soc_camera/soc_camera_platform.c b/drivers/media/platform/soc_camera/soc_camera_platform.c
index f535910b4187..cc8eb0758219 100644
--- a/drivers/media/platform/soc_camera/soc_camera_platform.c
+++ b/drivers/media/platform/soc_camera/soc_camera_platform.c
@@ -37,9 +37,11 @@ static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
37} 37}
38 38
39static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd, 39static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
40 struct v4l2_mbus_framefmt *mf) 40 struct v4l2_subdev_pad_config *cfg,
41 struct v4l2_subdev_format *format)
41{ 42{
42 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); 43 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
44 struct v4l2_mbus_framefmt *mf = &format->format;
43 45
44 mf->width = p->format.width; 46 mf->width = p->format.width;
45 mf->height = p->format.height; 47 mf->height = p->format.height;
@@ -61,15 +63,16 @@ static struct v4l2_subdev_core_ops platform_subdev_core_ops = {
61 .s_power = soc_camera_platform_s_power, 63 .s_power = soc_camera_platform_s_power,
62}; 64};
63 65
64static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 66static int soc_camera_platform_enum_mbus_code(struct v4l2_subdev *sd,
65 u32 *code) 67 struct v4l2_subdev_pad_config *cfg,
68 struct v4l2_subdev_mbus_code_enum *code)
66{ 69{
67 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); 70 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
68 71
69 if (index) 72 if (code->pad || code->index)
70 return -EINVAL; 73 return -EINVAL;
71 74
72 *code = p->format.code; 75 code->code = p->format.code;
73 return 0; 76 return 0;
74} 77}
75 78
@@ -117,18 +120,21 @@ static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd,
117 120
118static struct v4l2_subdev_video_ops platform_subdev_video_ops = { 121static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
119 .s_stream = soc_camera_platform_s_stream, 122 .s_stream = soc_camera_platform_s_stream,
120 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
121 .cropcap = soc_camera_platform_cropcap, 123 .cropcap = soc_camera_platform_cropcap,
122 .g_crop = soc_camera_platform_g_crop, 124 .g_crop = soc_camera_platform_g_crop,
123 .try_mbus_fmt = soc_camera_platform_fill_fmt,
124 .g_mbus_fmt = soc_camera_platform_fill_fmt,
125 .s_mbus_fmt = soc_camera_platform_fill_fmt,
126 .g_mbus_config = soc_camera_platform_g_mbus_config, 125 .g_mbus_config = soc_camera_platform_g_mbus_config,
127}; 126};
128 127
128static const struct v4l2_subdev_pad_ops platform_subdev_pad_ops = {
129 .enum_mbus_code = soc_camera_platform_enum_mbus_code,
130 .get_fmt = soc_camera_platform_fill_fmt,
131 .set_fmt = soc_camera_platform_fill_fmt,
132};
133
129static struct v4l2_subdev_ops platform_subdev_ops = { 134static struct v4l2_subdev_ops platform_subdev_ops = {
130 .core = &platform_subdev_core_ops, 135 .core = &platform_subdev_core_ops,
131 .video = &platform_subdev_video_ops, 136 .video = &platform_subdev_video_ops,
137 .pad = &platform_subdev_pad_ops,
132}; 138};
133 139
134static int soc_camera_platform_probe(struct platform_device *pdev) 140static int soc_camera_platform_probe(struct platform_device *pdev)
diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.c b/drivers/media/platform/soc_camera/soc_scale_crop.c
index 8e74fb7f2a07..bda29bc1b933 100644
--- a/drivers/media/platform/soc_camera/soc_scale_crop.c
+++ b/drivers/media/platform/soc_camera/soc_scale_crop.c
@@ -211,22 +211,23 @@ int soc_camera_client_s_crop(struct v4l2_subdev *sd,
211} 211}
212EXPORT_SYMBOL(soc_camera_client_s_crop); 212EXPORT_SYMBOL(soc_camera_client_s_crop);
213 213
214/* Iterative s_mbus_fmt, also updates cached client crop on success */ 214/* Iterative set_fmt, also updates cached client crop on success */
215static int client_s_fmt(struct soc_camera_device *icd, 215static int client_set_fmt(struct soc_camera_device *icd,
216 struct v4l2_rect *rect, struct v4l2_rect *subrect, 216 struct v4l2_rect *rect, struct v4l2_rect *subrect,
217 unsigned int max_width, unsigned int max_height, 217 unsigned int max_width, unsigned int max_height,
218 struct v4l2_mbus_framefmt *mf, bool host_can_scale) 218 struct v4l2_subdev_format *format, bool host_can_scale)
219{ 219{
220 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 220 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
221 struct device *dev = icd->parent; 221 struct device *dev = icd->parent;
222 struct v4l2_mbus_framefmt *mf = &format->format;
222 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h; 223 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
223 struct v4l2_cropcap cap; 224 struct v4l2_cropcap cap;
224 bool host_1to1; 225 bool host_1to1;
225 int ret; 226 int ret;
226 227
227 ret = v4l2_device_call_until_err(sd->v4l2_dev, 228 ret = v4l2_device_call_until_err(sd->v4l2_dev,
228 soc_camera_grp_id(icd), video, 229 soc_camera_grp_id(icd), pad,
229 s_mbus_fmt, mf); 230 set_fmt, NULL, format);
230 if (ret < 0) 231 if (ret < 0)
231 return ret; 232 return ret;
232 233
@@ -265,8 +266,8 @@ static int client_s_fmt(struct soc_camera_device *icd,
265 mf->width = tmp_w; 266 mf->width = tmp_w;
266 mf->height = tmp_h; 267 mf->height = tmp_h;
267 ret = v4l2_device_call_until_err(sd->v4l2_dev, 268 ret = v4l2_device_call_until_err(sd->v4l2_dev,
268 soc_camera_grp_id(icd), video, 269 soc_camera_grp_id(icd), pad,
269 s_mbus_fmt, mf); 270 set_fmt, NULL, format);
270 dev_geo(dev, "Camera scaled to %ux%u\n", 271 dev_geo(dev, "Camera scaled to %ux%u\n",
271 mf->width, mf->height); 272 mf->width, mf->height);
272 if (ret < 0) { 273 if (ret < 0) {
@@ -309,7 +310,11 @@ int soc_camera_client_scale(struct soc_camera_device *icd,
309 bool host_can_scale, unsigned int shift) 310 bool host_can_scale, unsigned int shift)
310{ 311{
311 struct device *dev = icd->parent; 312 struct device *dev = icd->parent;
312 struct v4l2_mbus_framefmt mf_tmp = *mf; 313 struct v4l2_subdev_format fmt_tmp = {
314 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
315 .format = *mf,
316 };
317 struct v4l2_mbus_framefmt *mf_tmp = &fmt_tmp.format;
313 unsigned int scale_h, scale_v; 318 unsigned int scale_h, scale_v;
314 int ret; 319 int ret;
315 320
@@ -317,25 +322,25 @@ int soc_camera_client_scale(struct soc_camera_device *icd,
317 * 5. Apply iterative camera S_FMT for camera user window (also updates 322 * 5. Apply iterative camera S_FMT for camera user window (also updates
318 * client crop cache and the imaginary sub-rectangle). 323 * client crop cache and the imaginary sub-rectangle).
319 */ 324 */
320 ret = client_s_fmt(icd, rect, subrect, *width, *height, 325 ret = client_set_fmt(icd, rect, subrect, *width, *height,
321 &mf_tmp, host_can_scale); 326 &fmt_tmp, host_can_scale);
322 if (ret < 0) 327 if (ret < 0)
323 return ret; 328 return ret;
324 329
325 dev_geo(dev, "5: camera scaled to %ux%u\n", 330 dev_geo(dev, "5: camera scaled to %ux%u\n",
326 mf_tmp.width, mf_tmp.height); 331 mf_tmp->width, mf_tmp->height);
327 332
328 /* 6. Retrieve camera output window (g_fmt) */ 333 /* 6. Retrieve camera output window (g_fmt) */
329 334
330 /* unneeded - it is already in "mf_tmp" */ 335 /* unneeded - it is already in "mf_tmp" */
331 336
332 /* 7. Calculate new client scales. */ 337 /* 7. Calculate new client scales. */
333 scale_h = soc_camera_calc_scale(rect->width, shift, mf_tmp.width); 338 scale_h = soc_camera_calc_scale(rect->width, shift, mf_tmp->width);
334 scale_v = soc_camera_calc_scale(rect->height, shift, mf_tmp.height); 339 scale_v = soc_camera_calc_scale(rect->height, shift, mf_tmp->height);
335 340
336 mf->width = mf_tmp.width; 341 mf->width = mf_tmp->width;
337 mf->height = mf_tmp.height; 342 mf->height = mf_tmp->height;
338 mf->colorspace = mf_tmp.colorspace; 343 mf->colorspace = mf_tmp->colorspace;
339 344
340 /* 345 /*
341 * 8. Calculate new host crop - apply camera scales to previously 346 * 8. Calculate new host crop - apply camera scales to previously
diff --git a/drivers/media/platform/sti/bdisp/Makefile b/drivers/media/platform/sti/bdisp/Makefile
new file mode 100644
index 000000000000..bc53496fa74c
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_VIDEO_STI_BDISP) := bdisp.o
2
3bdisp-objs := bdisp-v4l2.o bdisp-hw.o bdisp-debug.o
diff --git a/drivers/media/platform/sti/bdisp/bdisp-debug.c b/drivers/media/platform/sti/bdisp/bdisp-debug.c
new file mode 100644
index 000000000000..18282a0f80c9
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/bdisp-debug.c
@@ -0,0 +1,679 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6
7#include <linux/debugfs.h>
8#include <linux/pm_runtime.h>
9
10#include "bdisp.h"
11#include "bdisp-filter.h"
12#include "bdisp-reg.h"
13
14void bdisp_dbg_perf_begin(struct bdisp_dev *bdisp)
15{
16 bdisp->dbg.hw_start = ktime_get();
17}
18
19void bdisp_dbg_perf_end(struct bdisp_dev *bdisp)
20{
21 s64 time_us;
22
23 time_us = ktime_us_delta(ktime_get(), bdisp->dbg.hw_start);
24
25 if (!bdisp->dbg.min_duration)
26 bdisp->dbg.min_duration = time_us;
27 else
28 bdisp->dbg.min_duration = min(time_us, bdisp->dbg.min_duration);
29
30 bdisp->dbg.last_duration = time_us;
31 bdisp->dbg.max_duration = max(time_us, bdisp->dbg.max_duration);
32 bdisp->dbg.tot_duration += time_us;
33}
34
35static void bdisp_dbg_dump_ins(struct seq_file *s, u32 val)
36{
37 seq_printf(s, "INS\t0x%08X\t", val);
38
39 switch (val & BLT_INS_S1_MASK) {
40 case BLT_INS_S1_OFF:
41 break;
42 case BLT_INS_S1_MEM:
43 seq_puts(s, "SRC1=mem - ");
44 break;
45 case BLT_INS_S1_CF:
46 seq_puts(s, "SRC1=ColorFill - ");
47 break;
48 case BLT_INS_S1_COPY:
49 seq_puts(s, "SRC1=copy - ");
50 break;
51 case BLT_INS_S1_FILL:
52 seq_puts(s, "SRC1=fil - ");
53 break;
54 default:
55 seq_puts(s, "SRC1=??? - ");
56 break;
57 }
58
59 switch (val & BLT_INS_S2_MASK) {
60 case BLT_INS_S2_OFF:
61 break;
62 case BLT_INS_S2_MEM:
63 seq_puts(s, "SRC2=mem - ");
64 break;
65 case BLT_INS_S2_CF:
66 seq_puts(s, "SRC2=ColorFill - ");
67 break;
68 default:
69 seq_puts(s, "SRC2=??? - ");
70 break;
71 }
72
73 if ((val & BLT_INS_S3_MASK) == BLT_INS_S3_MEM)
74 seq_puts(s, "SRC3=mem - ");
75
76 if (val & BLT_INS_IVMX)
77 seq_puts(s, "IVMX - ");
78 if (val & BLT_INS_CLUT)
79 seq_puts(s, "CLUT - ");
80 if (val & BLT_INS_SCALE)
81 seq_puts(s, "Scale - ");
82 if (val & BLT_INS_FLICK)
83 seq_puts(s, "Flicker - ");
84 if (val & BLT_INS_CLIP)
85 seq_puts(s, "Clip - ");
86 if (val & BLT_INS_CKEY)
87 seq_puts(s, "ColorKey - ");
88 if (val & BLT_INS_OVMX)
89 seq_puts(s, "OVMX - ");
90 if (val & BLT_INS_DEI)
91 seq_puts(s, "Deint - ");
92 if (val & BLT_INS_PMASK)
93 seq_puts(s, "PlaneMask - ");
94 if (val & BLT_INS_VC1R)
95 seq_puts(s, "VC1R - ");
96 if (val & BLT_INS_ROTATE)
97 seq_puts(s, "Rotate - ");
98 if (val & BLT_INS_GRAD)
99 seq_puts(s, "GradFill - ");
100 if (val & BLT_INS_AQLOCK)
101 seq_puts(s, "AQLock - ");
102 if (val & BLT_INS_PACE)
103 seq_puts(s, "Pace - ");
104 if (val & BLT_INS_IRQ)
105 seq_puts(s, "IRQ - ");
106
107 seq_puts(s, "\n");
108}
109
110static void bdisp_dbg_dump_tty(struct seq_file *s, u32 val)
111{
112 seq_printf(s, "TTY\t0x%08X\t", val);
113 seq_printf(s, "Pitch=%d - ", val & 0xFFFF);
114
115 switch ((val & BLT_TTY_COL_MASK) >> BLT_TTY_COL_SHIFT) {
116 case BDISP_RGB565:
117 seq_puts(s, "RGB565 - ");
118 break;
119 case BDISP_XRGB8888:
120 seq_puts(s, "xRGB888 - ");
121 break;
122 case BDISP_ARGB8888:
123 seq_puts(s, "ARGB8888 - ");
124 break;
125 case BDISP_NV12:
126 seq_puts(s, "NV12 - ");
127 break;
128 case BDISP_YUV_3B:
129 seq_puts(s, "YUV420P - ");
130 break;
131 default:
132 seq_puts(s, "ColorFormat ??? - ");
133 break;
134 }
135
136 if (val & BLT_TTY_ALPHA_R)
137 seq_puts(s, "AlphaRange - ");
138 if (val & BLT_TTY_CR_NOT_CB)
139 seq_puts(s, "CrNotCb - ");
140 if (val & BLT_TTY_MB)
141 seq_puts(s, "MB - ");
142 if (val & BLT_TTY_HSO)
143 seq_puts(s, "HSO inverse - ");
144 if (val & BLT_TTY_VSO)
145 seq_puts(s, "VSO inverse - ");
146 if (val & BLT_TTY_DITHER)
147 seq_puts(s, "Dither - ");
148 if (val & BLT_TTY_CHROMA)
149 seq_puts(s, "Write CHROMA - ");
150 if (val & BLT_TTY_BIG_END)
151 seq_puts(s, "BigEndian - ");
152
153 seq_puts(s, "\n");
154}
155
156static void bdisp_dbg_dump_xy(struct seq_file *s, u32 val, char *name)
157{
158 seq_printf(s, "%s\t0x%08X\t", name, val);
159 seq_printf(s, "(%d,%d)\n", val & 0xFFFF, (val >> 16));
160}
161
162static void bdisp_dbg_dump_sz(struct seq_file *s, u32 val, char *name)
163{
164 seq_printf(s, "%s\t0x%08X\t", name, val);
165 seq_printf(s, "%dx%d\n", val & 0x1FFF, (val >> 16) & 0x1FFF);
166}
167
168static void bdisp_dbg_dump_sty(struct seq_file *s,
169 u32 val, u32 addr, char *name)
170{
171 bool s1, s2, s3;
172
173 seq_printf(s, "%s\t0x%08X\t", name, val);
174
175 if (!addr || !name || (strlen(name) < 2))
176 goto done;
177
178 s1 = name[strlen(name) - 1] == '1';
179 s2 = name[strlen(name) - 1] == '2';
180 s3 = name[strlen(name) - 1] == '3';
181
182 seq_printf(s, "Pitch=%d - ", val & 0xFFFF);
183
184 switch ((val & BLT_TTY_COL_MASK) >> BLT_TTY_COL_SHIFT) {
185 case BDISP_RGB565:
186 seq_puts(s, "RGB565 - ");
187 break;
188 case BDISP_XRGB8888:
189 seq_puts(s, "xRGB888 - ");
190 break;
191 case BDISP_ARGB8888:
192 seq_puts(s, "ARGB888 - ");
193 break;
194 case BDISP_NV12:
195 seq_puts(s, "NV12 - ");
196 break;
197 case BDISP_YUV_3B:
198 seq_puts(s, "YUV420P - ");
199 break;
200 default:
201 seq_puts(s, "ColorFormat ??? - ");
202 break;
203 }
204
205 if ((val & BLT_TTY_ALPHA_R) && !s3)
206 seq_puts(s, "AlphaRange - ");
207 if ((val & BLT_S1TY_A1_SUBSET) && !s3)
208 seq_puts(s, "A1SubSet - ");
209 if ((val & BLT_TTY_MB) && !s1)
210 seq_puts(s, "MB - ");
211 if (val & BLT_TTY_HSO)
212 seq_puts(s, "HSO inverse - ");
213 if (val & BLT_TTY_VSO)
214 seq_puts(s, "VSO inverse - ");
215 if ((val & BLT_S1TY_CHROMA_EXT) && (s1 || s2))
216 seq_puts(s, "ChromaExt - ");
217 if ((val & BLT_S3TY_BLANK_ACC) && s3)
218 seq_puts(s, "Blank Acc - ");
219 if ((val & BTL_S1TY_SUBBYTE) && !s3)
220 seq_puts(s, "SubByte - ");
221 if ((val & BLT_S1TY_RGB_EXP) && !s3)
222 seq_puts(s, "RGBExpand - ");
223 if ((val & BLT_TTY_BIG_END) && !s3)
224 seq_puts(s, "BigEndian - ");
225
226done:
227 seq_puts(s, "\n");
228}
229
230static void bdisp_dbg_dump_fctl(struct seq_file *s, u32 val)
231{
232 seq_printf(s, "FCTL\t0x%08X\t", val);
233
234 if ((val & BLT_FCTL_Y_HV_SCALE) == BLT_FCTL_Y_HV_SCALE)
235 seq_puts(s, "Resize Luma - ");
236 else if ((val & BLT_FCTL_Y_HV_SCALE) == BLT_FCTL_Y_HV_SAMPLE)
237 seq_puts(s, "Sample Luma - ");
238
239 if ((val & BLT_FCTL_HV_SCALE) == BLT_FCTL_HV_SCALE)
240 seq_puts(s, "Resize Chroma");
241 else if ((val & BLT_FCTL_HV_SCALE) == BLT_FCTL_HV_SAMPLE)
242 seq_puts(s, "Sample Chroma");
243
244 seq_puts(s, "\n");
245}
246
247static void bdisp_dbg_dump_rsf(struct seq_file *s, u32 val, char *name)
248{
249 u32 inc;
250
251 seq_printf(s, "%s\t0x%08X\t", name, val);
252
253 if (!val)
254 goto done;
255
256 inc = val & 0xFFFF;
257 seq_printf(s, "H: %d(6.10) / scale~%dx0.1 - ", inc, 1024 * 10 / inc);
258
259 inc = val >> 16;
260 seq_printf(s, "V: %d(6.10) / scale~%dx0.1", inc, 1024 * 10 / inc);
261
262done:
263 seq_puts(s, "\n");
264}
265
266static void bdisp_dbg_dump_rzi(struct seq_file *s, u32 val, char *name)
267{
268 seq_printf(s, "%s\t0x%08X\t", name, val);
269
270 if (!val)
271 goto done;
272
273 seq_printf(s, "H: init=%d repeat=%d - ", val & 0x3FF, (val >> 12) & 7);
274 val >>= 16;
275 seq_printf(s, "V: init=%d repeat=%d", val & 0x3FF, (val >> 12) & 7);
276
277done:
278 seq_puts(s, "\n");
279}
280
281static void bdisp_dbg_dump_ivmx(struct seq_file *s,
282 u32 c0, u32 c1, u32 c2, u32 c3)
283{
284 seq_printf(s, "IVMX0\t0x%08X\n", c0);
285 seq_printf(s, "IVMX1\t0x%08X\n", c1);
286 seq_printf(s, "IVMX2\t0x%08X\n", c2);
287 seq_printf(s, "IVMX3\t0x%08X\t", c3);
288
289 if (!c0 && !c1 && !c2 && !c3) {
290 seq_puts(s, "\n");
291 return;
292 }
293
294 if ((c0 == bdisp_rgb_to_yuv[0]) &&
295 (c1 == bdisp_rgb_to_yuv[1]) &&
296 (c2 == bdisp_rgb_to_yuv[2]) &&
297 (c3 == bdisp_rgb_to_yuv[3])) {
298 seq_puts(s, "RGB to YUV\n");
299 return;
300 }
301
302 if ((c0 == bdisp_yuv_to_rgb[0]) &&
303 (c1 == bdisp_yuv_to_rgb[1]) &&
304 (c2 == bdisp_yuv_to_rgb[2]) &&
305 (c3 == bdisp_yuv_to_rgb[3])) {
306 seq_puts(s, "YUV to RGB\n");
307 return;
308 }
309 seq_puts(s, "Unknown conversion\n");
310}
311
312static int bdisp_dbg_last_nodes(struct seq_file *s, void *data)
313{
314 /* Not dumping all fields, focusing on significant ones */
315 struct bdisp_dev *bdisp = s->private;
316 struct bdisp_node *node;
317 int i = 0;
318
319 if (!bdisp->dbg.copy_node[0]) {
320 seq_puts(s, "No node built yet\n");
321 return 0;
322 }
323
324 do {
325 node = bdisp->dbg.copy_node[i];
326 if (!node)
327 break;
328 seq_printf(s, "--------\nNode %d:\n", i);
329 seq_puts(s, "-- General --\n");
330 seq_printf(s, "NIP\t0x%08X\n", node->nip);
331 seq_printf(s, "CIC\t0x%08X\n", node->cic);
332 bdisp_dbg_dump_ins(s, node->ins);
333 seq_printf(s, "ACK\t0x%08X\n", node->ack);
334 seq_puts(s, "-- Target --\n");
335 seq_printf(s, "TBA\t0x%08X\n", node->tba);
336 bdisp_dbg_dump_tty(s, node->tty);
337 bdisp_dbg_dump_xy(s, node->txy, "TXY");
338 bdisp_dbg_dump_sz(s, node->tsz, "TSZ");
339 /* Color Fill not dumped */
340 seq_puts(s, "-- Source 1 --\n");
341 seq_printf(s, "S1BA\t0x%08X\n", node->s1ba);
342 bdisp_dbg_dump_sty(s, node->s1ty, node->s1ba, "S1TY");
343 bdisp_dbg_dump_xy(s, node->s1xy, "S1XY");
344 seq_puts(s, "-- Source 2 --\n");
345 seq_printf(s, "S2BA\t0x%08X\n", node->s2ba);
346 bdisp_dbg_dump_sty(s, node->s2ty, node->s2ba, "S2TY");
347 bdisp_dbg_dump_xy(s, node->s2xy, "S2XY");
348 bdisp_dbg_dump_sz(s, node->s2sz, "S2SZ");
349 seq_puts(s, "-- Source 3 --\n");
350 seq_printf(s, "S3BA\t0x%08X\n", node->s3ba);
351 bdisp_dbg_dump_sty(s, node->s3ty, node->s3ba, "S3TY");
352 bdisp_dbg_dump_xy(s, node->s3xy, "S3XY");
353 bdisp_dbg_dump_sz(s, node->s3sz, "S3SZ");
354 /* Clipping not dumped */
355 /* CLUT not dumped */
356 seq_puts(s, "-- Filter & Mask --\n");
357 bdisp_dbg_dump_fctl(s, node->fctl);
358 /* PMK not dumped */
359 seq_puts(s, "-- Chroma Filter --\n");
360 bdisp_dbg_dump_rsf(s, node->rsf, "RSF");
361 bdisp_dbg_dump_rzi(s, node->rzi, "RZI");
362 seq_printf(s, "HFP\t0x%08X\n", node->hfp);
363 seq_printf(s, "VFP\t0x%08X\n", node->vfp);
364 seq_puts(s, "-- Luma Filter --\n");
365 bdisp_dbg_dump_rsf(s, node->y_rsf, "Y_RSF");
366 bdisp_dbg_dump_rzi(s, node->y_rzi, "Y_RZI");
367 seq_printf(s, "Y_HFP\t0x%08X\n", node->y_hfp);
368 seq_printf(s, "Y_VFP\t0x%08X\n", node->y_vfp);
369 /* Flicker not dumped */
370 /* Color key not dumped */
371 /* Reserved not dumped */
372 /* Static Address & User not dumped */
373 seq_puts(s, "-- Input Versatile Matrix --\n");
374 bdisp_dbg_dump_ivmx(s, node->ivmx0, node->ivmx1,
375 node->ivmx2, node->ivmx3);
376 /* Output Versatile Matrix not dumped */
377 /* Pace not dumped */
378 /* VC1R & DEI not dumped */
379 /* Gradient Fill not dumped */
380 } while ((++i < MAX_NB_NODE) && node->nip);
381
382 return 0;
383}
384
385static int bdisp_dbg_last_nodes_raw(struct seq_file *s, void *data)
386{
387 struct bdisp_dev *bdisp = s->private;
388 struct bdisp_node *node;
389 u32 *val;
390 int j, i = 0;
391
392 if (!bdisp->dbg.copy_node[0]) {
393 seq_puts(s, "No node built yet\n");
394 return 0;
395 }
396
397 do {
398 node = bdisp->dbg.copy_node[i];
399 if (!node)
400 break;
401
402 seq_printf(s, "--------\nNode %d:\n", i);
403 val = (u32 *)node;
404 for (j = 0; j < sizeof(struct bdisp_node) / sizeof(u32); j++)
405 seq_printf(s, "0x%08X\n", *val++);
406 } while ((++i < MAX_NB_NODE) && node->nip);
407
408 return 0;
409}
410
411static const char *bdisp_fmt_to_str(struct bdisp_frame frame)
412{
413 switch (frame.fmt->pixelformat) {
414 case V4L2_PIX_FMT_YUV420:
415 return "YUV420P";
416 case V4L2_PIX_FMT_NV12:
417 if (frame.field == V4L2_FIELD_INTERLACED)
418 return "NV12 interlaced";
419 else
420 return "NV12";
421 case V4L2_PIX_FMT_RGB565:
422 return "RGB16";
423 case V4L2_PIX_FMT_XBGR32:
424 return "XRGB";
425 case V4L2_PIX_FMT_ABGR32:
426 return "ARGB";
427 default:
428 return "????";
429 }
430}
431
432static int bdisp_dbg_last_request(struct seq_file *s, void *data)
433{
434 struct bdisp_dev *bdisp = s->private;
435 struct bdisp_request *request = &bdisp->dbg.copy_request;
436 struct bdisp_frame src, dst;
437
438 if (!request->nb_req) {
439 seq_puts(s, "No request\n");
440 return 0;
441 }
442
443 src = request->src;
444 dst = request->dst;
445
446 seq_printf(s, "\nRequest #%d\n", request->nb_req);
447
448 seq_printf(s, "Format: %s\t\t\t%s\n",
449 bdisp_fmt_to_str(src), bdisp_fmt_to_str(dst));
450 seq_printf(s, "Crop area: %dx%d @ %d,%d ==>\t%dx%d @ %d,%d\n",
451 src.crop.width, src.crop.height,
452 src.crop.left, src.crop.top,
453 dst.crop.width, dst.crop.height,
454 dst.crop.left, dst.crop.top);
455 seq_printf(s, "Buff size: %dx%d\t\t%dx%d\n\n",
456 src.width, src.height, dst.width, dst.height);
457
458 if (request->hflip)
459 seq_puts(s, "Horizontal flip\n\n");
460
461 if (request->vflip)
462 seq_puts(s, "Vertical flip\n\n");
463
464 return 0;
465}
466
467#define DUMP(reg) seq_printf(s, #reg " \t0x%08X\n", readl(bdisp->regs + reg))
468
469static int bdisp_dbg_regs(struct seq_file *s, void *data)
470{
471 struct bdisp_dev *bdisp = s->private;
472 int ret;
473 unsigned int i;
474
475 ret = pm_runtime_get_sync(bdisp->dev);
476 if (ret < 0) {
477 seq_puts(s, "Cannot wake up IP\n");
478 return 0;
479 }
480
481 seq_printf(s, "Reg @ = 0x%p\n", bdisp->regs);
482
483 seq_puts(s, "\nStatic:\n");
484 DUMP(BLT_CTL);
485 DUMP(BLT_ITS);
486 DUMP(BLT_STA1);
487 DUMP(BLT_AQ1_CTL);
488 DUMP(BLT_AQ1_IP);
489 DUMP(BLT_AQ1_LNA);
490 DUMP(BLT_AQ1_STA);
491 DUMP(BLT_ITM0);
492
493 seq_puts(s, "\nPlugs:\n");
494 DUMP(BLT_PLUGS1_OP2);
495 DUMP(BLT_PLUGS1_CHZ);
496 DUMP(BLT_PLUGS1_MSZ);
497 DUMP(BLT_PLUGS1_PGZ);
498 DUMP(BLT_PLUGS2_OP2);
499 DUMP(BLT_PLUGS2_CHZ);
500 DUMP(BLT_PLUGS2_MSZ);
501 DUMP(BLT_PLUGS2_PGZ);
502 DUMP(BLT_PLUGS3_OP2);
503 DUMP(BLT_PLUGS3_CHZ);
504 DUMP(BLT_PLUGS3_MSZ);
505 DUMP(BLT_PLUGS3_PGZ);
506 DUMP(BLT_PLUGT_OP2);
507 DUMP(BLT_PLUGT_CHZ);
508 DUMP(BLT_PLUGT_MSZ);
509 DUMP(BLT_PLUGT_PGZ);
510
511 seq_puts(s, "\nNode:\n");
512 DUMP(BLT_NIP);
513 DUMP(BLT_CIC);
514 DUMP(BLT_INS);
515 DUMP(BLT_ACK);
516 DUMP(BLT_TBA);
517 DUMP(BLT_TTY);
518 DUMP(BLT_TXY);
519 DUMP(BLT_TSZ);
520 DUMP(BLT_S1BA);
521 DUMP(BLT_S1TY);
522 DUMP(BLT_S1XY);
523 DUMP(BLT_S2BA);
524 DUMP(BLT_S2TY);
525 DUMP(BLT_S2XY);
526 DUMP(BLT_S2SZ);
527 DUMP(BLT_S3BA);
528 DUMP(BLT_S3TY);
529 DUMP(BLT_S3XY);
530 DUMP(BLT_S3SZ);
531 DUMP(BLT_FCTL);
532 DUMP(BLT_RSF);
533 DUMP(BLT_RZI);
534 DUMP(BLT_HFP);
535 DUMP(BLT_VFP);
536 DUMP(BLT_Y_RSF);
537 DUMP(BLT_Y_RZI);
538 DUMP(BLT_Y_HFP);
539 DUMP(BLT_Y_VFP);
540 DUMP(BLT_IVMX0);
541 DUMP(BLT_IVMX1);
542 DUMP(BLT_IVMX2);
543 DUMP(BLT_IVMX3);
544 DUMP(BLT_OVMX0);
545 DUMP(BLT_OVMX1);
546 DUMP(BLT_OVMX2);
547 DUMP(BLT_OVMX3);
548 DUMP(BLT_DEI);
549
550 seq_puts(s, "\nFilter:\n");
551 for (i = 0; i < BLT_NB_H_COEF; i++) {
552 seq_printf(s, "BLT_HFC%d \t0x%08X\n", i,
553 readl(bdisp->regs + BLT_HFC_N + i * 4));
554 }
555 for (i = 0; i < BLT_NB_V_COEF; i++) {
556 seq_printf(s, "BLT_VFC%d \t0x%08X\n", i,
557 readl(bdisp->regs + BLT_VFC_N + i * 4));
558 }
559
560 seq_puts(s, "\nLuma filter:\n");
561 for (i = 0; i < BLT_NB_H_COEF; i++) {
562 seq_printf(s, "BLT_Y_HFC%d \t0x%08X\n", i,
563 readl(bdisp->regs + BLT_Y_HFC_N + i * 4));
564 }
565 for (i = 0; i < BLT_NB_V_COEF; i++) {
566 seq_printf(s, "BLT_Y_VFC%d \t0x%08X\n", i,
567 readl(bdisp->regs + BLT_Y_VFC_N + i * 4));
568 }
569
570 pm_runtime_put(bdisp->dev);
571
572 return 0;
573}
574
575#define SECOND 1000000
576
577static int bdisp_dbg_perf(struct seq_file *s, void *data)
578{
579 struct bdisp_dev *bdisp = s->private;
580 struct bdisp_request *request = &bdisp->dbg.copy_request;
581 s64 avg_time_us;
582 int avg_fps, min_fps, max_fps, last_fps;
583
584 if (!request->nb_req) {
585 seq_puts(s, "No request\n");
586 return 0;
587 }
588
589 avg_time_us = div64_s64(bdisp->dbg.tot_duration, request->nb_req);
590 if (avg_time_us > SECOND)
591 avg_fps = 0;
592 else
593 avg_fps = SECOND / (s32)avg_time_us;
594
595 if (bdisp->dbg.min_duration > SECOND)
596 min_fps = 0;
597 else
598 min_fps = SECOND / (s32)bdisp->dbg.min_duration;
599
600 if (bdisp->dbg.max_duration > SECOND)
601 max_fps = 0;
602 else
603 max_fps = SECOND / (s32)bdisp->dbg.max_duration;
604
605 if (bdisp->dbg.last_duration > SECOND)
606 last_fps = 0;
607 else
608 last_fps = SECOND / (s32)bdisp->dbg.last_duration;
609
610 seq_printf(s, "HW processing (%d requests):\n", request->nb_req);
611 seq_printf(s, " Average: %5lld us (%3d fps)\n",
612 avg_time_us, avg_fps);
613 seq_printf(s, " Min-Max: %5lld us (%3d fps) - %5lld us (%3d fps)\n",
614 bdisp->dbg.min_duration, min_fps,
615 bdisp->dbg.max_duration, max_fps);
616 seq_printf(s, " Last: %5lld us (%3d fps)\n",
617 bdisp->dbg.last_duration, last_fps);
618
619 return 0;
620}
621
622#define bdisp_dbg_declare(name) \
623 static int bdisp_dbg_##name##_open(struct inode *i, struct file *f) \
624 { \
625 return single_open(f, bdisp_dbg_##name, i->i_private); \
626 } \
627 static const struct file_operations bdisp_dbg_##name##_fops = { \
628 .open = bdisp_dbg_##name##_open, \
629 .read = seq_read, \
630 .llseek = seq_lseek, \
631 .release = single_release, \
632 }
633
634#define bdisp_dbg_create_entry(name) \
635 debugfs_create_file(#name, S_IRUGO, bdisp->dbg.debugfs_entry, bdisp, \
636 &bdisp_dbg_##name##_fops)
637
638bdisp_dbg_declare(regs);
639bdisp_dbg_declare(last_nodes);
640bdisp_dbg_declare(last_nodes_raw);
641bdisp_dbg_declare(last_request);
642bdisp_dbg_declare(perf);
643
644int bdisp_debugfs_create(struct bdisp_dev *bdisp)
645{
646 char dirname[16];
647
648 snprintf(dirname, sizeof(dirname), "%s%d", BDISP_NAME, bdisp->id);
649 bdisp->dbg.debugfs_entry = debugfs_create_dir(dirname, NULL);
650 if (!bdisp->dbg.debugfs_entry)
651 goto err;
652
653 if (!bdisp_dbg_create_entry(regs))
654 goto err;
655
656 if (!bdisp_dbg_create_entry(last_nodes))
657 goto err;
658
659 if (!bdisp_dbg_create_entry(last_nodes_raw))
660 goto err;
661
662 if (!bdisp_dbg_create_entry(last_request))
663 goto err;
664
665 if (!bdisp_dbg_create_entry(perf))
666 goto err;
667
668 return 0;
669
670err:
671 bdisp_debugfs_remove(bdisp);
672 return 0;
673}
674
675void bdisp_debugfs_remove(struct bdisp_dev *bdisp)
676{
677 debugfs_remove_recursive(bdisp->dbg.debugfs_entry);
678 bdisp->dbg.debugfs_entry = NULL;
679}
diff --git a/drivers/media/platform/sti/bdisp/bdisp-filter.h b/drivers/media/platform/sti/bdisp/bdisp-filter.h
new file mode 100644
index 000000000000..fc8c54f725ad
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/bdisp-filter.h
@@ -0,0 +1,346 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6
7#define BDISP_HF_NB 64
8#define BDISP_VF_NB 40
9
10/**
11 * struct bdisp_filter_h_spec - Horizontal filter specification
12 *
13 * @min: min scale factor for this filter (6.10 fixed point)
14 * @max: max scale factor for this filter (6.10 fixed point)
15 * coef: filter coefficients
16 */
17struct bdisp_filter_h_spec {
18 const u16 min;
19 const u16 max;
20 const u8 coef[BDISP_HF_NB];
21};
22
23static const struct bdisp_filter_h_spec bdisp_h_spec[] = {
24 {
25 .min = 0,
26 .max = 921,
27 .coef = {
28 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0xff, 0x07, 0x3d, 0xfc, 0x01, 0x00,
30 0x00, 0x01, 0xfd, 0x11, 0x36, 0xf9, 0x02, 0x00,
31 0x00, 0x01, 0xfb, 0x1b, 0x2e, 0xf9, 0x02, 0x00,
32 0x00, 0x01, 0xf9, 0x26, 0x26, 0xf9, 0x01, 0x00,
33 0x00, 0x02, 0xf9, 0x30, 0x19, 0xfb, 0x01, 0x00,
34 0x00, 0x02, 0xf9, 0x39, 0x0e, 0xfd, 0x01, 0x00,
35 0x00, 0x01, 0xfc, 0x3e, 0x06, 0xff, 0x00, 0x00
36 }
37 },
38 {
39 .min = 921,
40 .max = 1024,
41 .coef = {
42 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
43 0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
44 0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
45 0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
46 0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
47 0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
48 0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
49 0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
50 }
51 },
52 {
53 .min = 1024,
54 .max = 1126,
55 .coef = {
56 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
57 0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
58 0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
59 0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
60 0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
61 0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
62 0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
63 0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
64 }
65 },
66 {
67 .min = 1126,
68 .max = 1228,
69 .coef = {
70 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
71 0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
72 0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
73 0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
74 0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
75 0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
76 0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
77 0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
78 }
79 },
80 {
81 .min = 1228,
82 .max = 1331,
83 .coef = {
84 0xfd, 0x04, 0xfc, 0x05, 0x39, 0x05, 0xfc, 0x04,
85 0xfc, 0x06, 0xf9, 0x0c, 0x39, 0xfe, 0x00, 0x02,
86 0xfb, 0x08, 0xf6, 0x17, 0x35, 0xf9, 0x02, 0x00,
87 0xfc, 0x08, 0xf4, 0x20, 0x30, 0xf4, 0x05, 0xff,
88 0xfd, 0x07, 0xf4, 0x29, 0x28, 0xf3, 0x07, 0xfd,
89 0xff, 0x05, 0xf5, 0x31, 0x1f, 0xf3, 0x08, 0xfc,
90 0x00, 0x02, 0xf9, 0x38, 0x14, 0xf6, 0x08, 0xfb,
91 0x02, 0x00, 0xff, 0x3a, 0x0b, 0xf8, 0x06, 0xfc
92 }
93 },
94 {
95 .min = 1331,
96 .max = 1433,
97 .coef = {
98 0xfc, 0x06, 0xf9, 0x09, 0x34, 0x09, 0xf9, 0x06,
99 0xfd, 0x07, 0xf7, 0x10, 0x32, 0x02, 0xfc, 0x05,
100 0xfe, 0x07, 0xf6, 0x17, 0x2f, 0xfc, 0xff, 0x04,
101 0xff, 0x06, 0xf5, 0x20, 0x2a, 0xf9, 0x01, 0x02,
102 0x00, 0x04, 0xf6, 0x27, 0x25, 0xf6, 0x04, 0x00,
103 0x02, 0x01, 0xf9, 0x2d, 0x1d, 0xf5, 0x06, 0xff,
104 0x04, 0xff, 0xfd, 0x31, 0x15, 0xf5, 0x07, 0xfe,
105 0x05, 0xfc, 0x02, 0x35, 0x0d, 0xf7, 0x07, 0xfd
106 }
107 },
108 {
109 .min = 1433,
110 .max = 1536,
111 .coef = {
112 0xfe, 0x06, 0xf8, 0x0b, 0x30, 0x0b, 0xf8, 0x06,
113 0xff, 0x06, 0xf7, 0x12, 0x2d, 0x05, 0xfa, 0x06,
114 0x00, 0x04, 0xf6, 0x18, 0x2c, 0x00, 0xfc, 0x06,
115 0x01, 0x02, 0xf7, 0x1f, 0x27, 0xfd, 0xff, 0x04,
116 0x03, 0x00, 0xf9, 0x24, 0x24, 0xf9, 0x00, 0x03,
117 0x04, 0xff, 0xfd, 0x29, 0x1d, 0xf7, 0x02, 0x01,
118 0x06, 0xfc, 0x00, 0x2d, 0x17, 0xf6, 0x04, 0x00,
119 0x06, 0xfa, 0x05, 0x30, 0x0f, 0xf7, 0x06, 0xff
120 }
121 },
122 {
123 .min = 1536,
124 .max = 2048,
125 .coef = {
126 0x05, 0xfd, 0xfb, 0x13, 0x25, 0x13, 0xfb, 0xfd,
127 0x05, 0xfc, 0xfd, 0x17, 0x24, 0x0f, 0xf9, 0xff,
128 0x04, 0xfa, 0xff, 0x1b, 0x24, 0x0b, 0xf9, 0x00,
129 0x03, 0xf9, 0x01, 0x1f, 0x23, 0x08, 0xf8, 0x01,
130 0x02, 0xf9, 0x04, 0x22, 0x20, 0x04, 0xf9, 0x02,
131 0x01, 0xf8, 0x08, 0x25, 0x1d, 0x01, 0xf9, 0x03,
132 0x00, 0xf9, 0x0c, 0x25, 0x1a, 0xfe, 0xfa, 0x04,
133 0xff, 0xf9, 0x10, 0x26, 0x15, 0xfc, 0xfc, 0x05
134 }
135 },
136 {
137 .min = 2048,
138 .max = 3072,
139 .coef = {
140 0xfc, 0xfd, 0x06, 0x13, 0x18, 0x13, 0x06, 0xfd,
141 0xfc, 0xfe, 0x08, 0x15, 0x17, 0x12, 0x04, 0xfc,
142 0xfb, 0xfe, 0x0a, 0x16, 0x18, 0x10, 0x03, 0xfc,
143 0xfb, 0x00, 0x0b, 0x18, 0x17, 0x0f, 0x01, 0xfb,
144 0xfb, 0x00, 0x0d, 0x19, 0x17, 0x0d, 0x00, 0xfb,
145 0xfb, 0x01, 0x0f, 0x19, 0x16, 0x0b, 0x00, 0xfb,
146 0xfc, 0x03, 0x11, 0x19, 0x15, 0x09, 0xfe, 0xfb,
147 0xfc, 0x04, 0x12, 0x1a, 0x12, 0x08, 0xfe, 0xfc
148 }
149 },
150 {
151 .min = 3072,
152 .max = 4096,
153 .coef = {
154 0xfe, 0x02, 0x09, 0x0f, 0x0e, 0x0f, 0x09, 0x02,
155 0xff, 0x02, 0x09, 0x0f, 0x10, 0x0e, 0x08, 0x01,
156 0xff, 0x03, 0x0a, 0x10, 0x10, 0x0d, 0x07, 0x00,
157 0x00, 0x04, 0x0b, 0x10, 0x0f, 0x0c, 0x06, 0x00,
158 0x00, 0x05, 0x0c, 0x10, 0x0e, 0x0c, 0x05, 0x00,
159 0x00, 0x06, 0x0c, 0x11, 0x0e, 0x0b, 0x04, 0x00,
160 0x00, 0x07, 0x0d, 0x11, 0x0f, 0x0a, 0x03, 0xff,
161 0x01, 0x08, 0x0e, 0x11, 0x0e, 0x09, 0x02, 0xff
162 }
163 },
164 {
165 .min = 4096,
166 .max = 5120,
167 .coef = {
168 0x00, 0x04, 0x09, 0x0c, 0x0e, 0x0c, 0x09, 0x04,
169 0x01, 0x05, 0x09, 0x0c, 0x0d, 0x0c, 0x08, 0x04,
170 0x01, 0x05, 0x0a, 0x0c, 0x0e, 0x0b, 0x08, 0x03,
171 0x02, 0x06, 0x0a, 0x0d, 0x0c, 0x0b, 0x07, 0x03,
172 0x02, 0x07, 0x0a, 0x0d, 0x0d, 0x0a, 0x07, 0x02,
173 0x03, 0x07, 0x0b, 0x0d, 0x0c, 0x0a, 0x06, 0x02,
174 0x03, 0x08, 0x0b, 0x0d, 0x0d, 0x0a, 0x05, 0x01,
175 0x04, 0x08, 0x0c, 0x0d, 0x0c, 0x09, 0x05, 0x01
176 }
177 },
178 {
179 .min = 5120,
180 .max = 65535,
181 .coef = {
182 0x03, 0x06, 0x09, 0x0b, 0x09, 0x0b, 0x09, 0x06,
183 0x03, 0x06, 0x09, 0x0b, 0x0c, 0x0a, 0x08, 0x05,
184 0x03, 0x06, 0x09, 0x0b, 0x0c, 0x0a, 0x08, 0x05,
185 0x04, 0x07, 0x09, 0x0b, 0x0b, 0x0a, 0x08, 0x04,
186 0x04, 0x07, 0x0a, 0x0b, 0x0b, 0x0a, 0x07, 0x04,
187 0x04, 0x08, 0x0a, 0x0b, 0x0b, 0x09, 0x07, 0x04,
188 0x05, 0x08, 0x0a, 0x0b, 0x0c, 0x09, 0x06, 0x03,
189 0x05, 0x08, 0x0a, 0x0b, 0x0c, 0x09, 0x06, 0x03
190 }
191 }
192};
193
194/**
195 * struct bdisp_filter_v_spec - Vertical filter specification
196 *
197 * @min: min scale factor for this filter (6.10 fixed point)
198 * @max: max scale factor for this filter (6.10 fixed point)
199 * coef: filter coefficients
200 */
201struct bdisp_filter_v_spec {
202 const u16 min;
203 const u16 max;
204 const u8 coef[BDISP_VF_NB];
205};
206
207static const struct bdisp_filter_v_spec bdisp_v_spec[] = {
208 {
209 .min = 0,
210 .max = 1024,
211 .coef = {
212 0x00, 0x00, 0x40, 0x00, 0x00,
213 0x00, 0x06, 0x3d, 0xfd, 0x00,
214 0xfe, 0x0f, 0x38, 0xfb, 0x00,
215 0xfd, 0x19, 0x2f, 0xfb, 0x00,
216 0xfc, 0x24, 0x24, 0xfc, 0x00,
217 0xfb, 0x2f, 0x19, 0xfd, 0x00,
218 0xfb, 0x38, 0x0f, 0xfe, 0x00,
219 0xfd, 0x3d, 0x06, 0x00, 0x00
220 }
221 },
222 {
223 .min = 1024,
224 .max = 1331,
225 .coef = {
226 0xfc, 0x05, 0x3e, 0x05, 0xfc,
227 0xf8, 0x0e, 0x3b, 0xff, 0x00,
228 0xf5, 0x18, 0x38, 0xf9, 0x02,
229 0xf4, 0x21, 0x31, 0xf5, 0x05,
230 0xf4, 0x2a, 0x27, 0xf4, 0x07,
231 0xf6, 0x30, 0x1e, 0xf4, 0x08,
232 0xf9, 0x35, 0x15, 0xf6, 0x07,
233 0xff, 0x37, 0x0b, 0xf9, 0x06
234 }
235 },
236 {
237 .min = 1331,
238 .max = 1433,
239 .coef = {
240 0xf8, 0x0a, 0x3c, 0x0a, 0xf8,
241 0xf6, 0x12, 0x3b, 0x02, 0xfb,
242 0xf4, 0x1b, 0x35, 0xfd, 0xff,
243 0xf4, 0x23, 0x30, 0xf8, 0x01,
244 0xf6, 0x29, 0x27, 0xf6, 0x04,
245 0xf9, 0x2e, 0x1e, 0xf5, 0x06,
246 0xfd, 0x31, 0x16, 0xf6, 0x06,
247 0x02, 0x32, 0x0d, 0xf8, 0x07
248 }
249 },
250 {
251 .min = 1433,
252 .max = 1536,
253 .coef = {
254 0xf6, 0x0e, 0x38, 0x0e, 0xf6,
255 0xf5, 0x15, 0x38, 0x06, 0xf8,
256 0xf5, 0x1d, 0x33, 0x00, 0xfb,
257 0xf6, 0x23, 0x2d, 0xfc, 0xfe,
258 0xf9, 0x28, 0x26, 0xf9, 0x00,
259 0xfc, 0x2c, 0x1e, 0xf7, 0x03,
260 0x00, 0x2e, 0x18, 0xf6, 0x04,
261 0x05, 0x2e, 0x11, 0xf7, 0x05
262 }
263 },
264 {
265 .min = 1536,
266 .max = 2048,
267 .coef = {
268 0xfb, 0x13, 0x24, 0x13, 0xfb,
269 0xfd, 0x17, 0x23, 0x0f, 0xfa,
270 0xff, 0x1a, 0x23, 0x0b, 0xf9,
271 0x01, 0x1d, 0x22, 0x07, 0xf9,
272 0x04, 0x20, 0x1f, 0x04, 0xf9,
273 0x07, 0x22, 0x1c, 0x01, 0xfa,
274 0x0b, 0x24, 0x17, 0xff, 0xfb,
275 0x0f, 0x24, 0x14, 0xfd, 0xfc
276 }
277 },
278 {
279 .min = 2048,
280 .max = 3072,
281 .coef = {
282 0x05, 0x10, 0x16, 0x10, 0x05,
283 0x06, 0x11, 0x16, 0x0f, 0x04,
284 0x08, 0x13, 0x15, 0x0e, 0x02,
285 0x09, 0x14, 0x16, 0x0c, 0x01,
286 0x0b, 0x15, 0x15, 0x0b, 0x00,
287 0x0d, 0x16, 0x13, 0x0a, 0x00,
288 0x0f, 0x17, 0x13, 0x08, 0xff,
289 0x11, 0x18, 0x12, 0x07, 0xfe
290 }
291 },
292 {
293 .min = 3072,
294 .max = 4096,
295 .coef = {
296 0x09, 0x0f, 0x10, 0x0f, 0x09,
297 0x09, 0x0f, 0x12, 0x0e, 0x08,
298 0x0a, 0x10, 0x11, 0x0e, 0x07,
299 0x0b, 0x11, 0x11, 0x0d, 0x06,
300 0x0c, 0x11, 0x12, 0x0c, 0x05,
301 0x0d, 0x12, 0x11, 0x0c, 0x04,
302 0x0e, 0x12, 0x11, 0x0b, 0x04,
303 0x0f, 0x13, 0x11, 0x0a, 0x03
304 }
305 },
306 {
307 .min = 4096,
308 .max = 5120,
309 .coef = {
310 0x0a, 0x0e, 0x10, 0x0e, 0x0a,
311 0x0b, 0x0e, 0x0f, 0x0e, 0x0a,
312 0x0b, 0x0f, 0x10, 0x0d, 0x09,
313 0x0c, 0x0f, 0x10, 0x0d, 0x08,
314 0x0d, 0x0f, 0x0f, 0x0d, 0x08,
315 0x0d, 0x10, 0x10, 0x0c, 0x07,
316 0x0e, 0x10, 0x0f, 0x0c, 0x07,
317 0x0f, 0x10, 0x10, 0x0b, 0x06
318 }
319 },
320 {
321 .min = 5120,
322 .max = 65535,
323 .coef = {
324 0x0b, 0x0e, 0x0e, 0x0e, 0x0b,
325 0x0b, 0x0e, 0x0f, 0x0d, 0x0b,
326 0x0c, 0x0e, 0x0f, 0x0d, 0x0a,
327 0x0c, 0x0e, 0x0f, 0x0d, 0x0a,
328 0x0d, 0x0f, 0x0e, 0x0d, 0x09,
329 0x0d, 0x0f, 0x0f, 0x0c, 0x09,
330 0x0e, 0x0f, 0x0e, 0x0c, 0x09,
331 0x0e, 0x0f, 0x0f, 0x0c, 0x08
332 }
333 }
334};
335
336#define NB_H_FILTER ARRAY_SIZE(bdisp_h_spec)
337#define NB_V_FILTER ARRAY_SIZE(bdisp_v_spec)
338
339/* RGB YUV 601 standard conversion */
340static const u32 bdisp_rgb_to_yuv[] = {
341 0x0e1e8bee, 0x08420419, 0xfb5ed471, 0x08004080,
342};
343
344static const u32 bdisp_yuv_to_rgb[] = {
345 0x3324a800, 0xe604ab9c, 0x0004a957, 0x32121eeb,
346};
diff --git a/drivers/media/platform/sti/bdisp/bdisp-hw.c b/drivers/media/platform/sti/bdisp/bdisp-hw.c
new file mode 100644
index 000000000000..465828e859e2
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/bdisp-hw.c
@@ -0,0 +1,823 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6
7#include <linux/delay.h>
8
9#include "bdisp.h"
10#include "bdisp-filter.h"
11#include "bdisp-reg.h"
12
13/* Max width of the source frame in a single node */
14#define MAX_SRC_WIDTH 2048
15
16/* Reset & boot poll config */
17#define POLL_RST_MAX 50
18#define POLL_RST_DELAY_MS 20
19
20enum bdisp_target_plan {
21 BDISP_RGB,
22 BDISP_Y,
23 BDISP_CBCR
24};
25
26struct bdisp_op_cfg {
27 bool cconv; /* RGB - YUV conversion */
28 bool hflip; /* Horizontal flip */
29 bool vflip; /* Vertical flip */
30 bool wide; /* Wide (>MAX_SRC_WIDTH) */
31 bool scale; /* Scale */
32 u16 h_inc; /* Horizontal increment in 6.10 format */
33 u16 v_inc; /* Vertical increment in 6.10 format */
34 bool src_interlaced; /* is the src an interlaced buffer */
35 u8 src_nbp; /* nb of planes of the src */
36 bool src_yuv; /* is the src a YUV color format */
37 bool src_420; /* is the src 4:2:0 chroma subsampled */
38 u8 dst_nbp; /* nb of planes of the dst */
39 bool dst_yuv; /* is the dst a YUV color format */
40 bool dst_420; /* is the dst 4:2:0 chroma subsampled */
41};
42
43struct bdisp_filter_addr {
44 u16 min; /* Filter min scale factor (6.10 fixed point) */
45 u16 max; /* Filter max scale factor (6.10 fixed point) */
46 void *virt; /* Virtual address for filter table */
47 dma_addr_t paddr; /* Physical address for filter table */
48};
49
50static struct bdisp_filter_addr bdisp_h_filter[NB_H_FILTER];
51static struct bdisp_filter_addr bdisp_v_filter[NB_V_FILTER];
52
53/**
54 * bdisp_hw_reset
55 * @bdisp: bdisp entity
56 *
57 * Resets HW
58 *
59 * RETURNS:
60 * 0 on success.
61 */
62int bdisp_hw_reset(struct bdisp_dev *bdisp)
63{
64 unsigned int i;
65
66 dev_dbg(bdisp->dev, "%s\n", __func__);
67
68 /* Mask Interrupt */
69 writel(0, bdisp->regs + BLT_ITM0);
70
71 /* Reset */
72 writel(readl(bdisp->regs + BLT_CTL) | BLT_CTL_RESET,
73 bdisp->regs + BLT_CTL);
74 writel(0, bdisp->regs + BLT_CTL);
75
76 /* Wait for reset done */
77 for (i = 0; i < POLL_RST_MAX; i++) {
78 if (readl(bdisp->regs + BLT_STA1) & BLT_STA1_IDLE)
79 break;
80 msleep(POLL_RST_DELAY_MS);
81 }
82 if (i == POLL_RST_MAX)
83 dev_err(bdisp->dev, "Reset timeout\n");
84
85 return (i == POLL_RST_MAX) ? -EAGAIN : 0;
86}
87
88/**
89 * bdisp_hw_get_and_clear_irq
90 * @bdisp: bdisp entity
91 *
92 * Read then reset interrupt status
93 *
94 * RETURNS:
95 * 0 if expected interrupt was raised.
96 */
97int bdisp_hw_get_and_clear_irq(struct bdisp_dev *bdisp)
98{
99 u32 its;
100
101 its = readl(bdisp->regs + BLT_ITS);
102
103 /* Check for the only expected IT: LastNode of AQ1 */
104 if (!(its & BLT_ITS_AQ1_LNA)) {
105 dev_dbg(bdisp->dev, "Unexpected IT status: 0x%08X\n", its);
106 writel(its, bdisp->regs + BLT_ITS);
107 return -1;
108 }
109
110 /* Clear and mask */
111 writel(its, bdisp->regs + BLT_ITS);
112 writel(0, bdisp->regs + BLT_ITM0);
113
114 return 0;
115}
116
117/**
118 * bdisp_hw_free_nodes
119 * @ctx: bdisp context
120 *
121 * Free node memory
122 *
123 * RETURNS:
124 * None
125 */
126void bdisp_hw_free_nodes(struct bdisp_ctx *ctx)
127{
128 if (ctx && ctx->node[0]) {
129 DEFINE_DMA_ATTRS(attrs);
130
131 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
132 dma_free_attrs(ctx->bdisp_dev->dev,
133 sizeof(struct bdisp_node) * MAX_NB_NODE,
134 ctx->node[0], ctx->node_paddr[0], &attrs);
135 }
136}
137
138/**
139 * bdisp_hw_alloc_nodes
140 * @ctx: bdisp context
141 *
142 * Allocate dma memory for nodes
143 *
144 * RETURNS:
145 * 0 on success
146 */
147int bdisp_hw_alloc_nodes(struct bdisp_ctx *ctx)
148{
149 struct device *dev = ctx->bdisp_dev->dev;
150 unsigned int i, node_size = sizeof(struct bdisp_node);
151 void *base;
152 dma_addr_t paddr;
153 DEFINE_DMA_ATTRS(attrs);
154
155 /* Allocate all the nodes within a single memory page */
156 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
157 base = dma_alloc_attrs(dev, node_size * MAX_NB_NODE, &paddr,
158 GFP_KERNEL | GFP_DMA, &attrs);
159 if (!base) {
160 dev_err(dev, "%s no mem\n", __func__);
161 return -ENOMEM;
162 }
163
164 memset(base, 0, node_size * MAX_NB_NODE);
165
166 for (i = 0; i < MAX_NB_NODE; i++) {
167 ctx->node[i] = base;
168 ctx->node_paddr[i] = paddr;
169 dev_dbg(dev, "node[%d]=0x%p (paddr=%pad)\n", i, ctx->node[i],
170 &paddr);
171 base += node_size;
172 paddr += node_size;
173 }
174
175 return 0;
176}
177
178/**
179 * bdisp_hw_free_filters
180 * @dev: device
181 *
182 * Free filters memory
183 *
184 * RETURNS:
185 * None
186 */
187void bdisp_hw_free_filters(struct device *dev)
188{
189 int size = (BDISP_HF_NB * NB_H_FILTER) + (BDISP_VF_NB * NB_V_FILTER);
190
191 if (bdisp_h_filter[0].virt) {
192 DEFINE_DMA_ATTRS(attrs);
193
194 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
195 dma_free_attrs(dev, size, bdisp_h_filter[0].virt,
196 bdisp_h_filter[0].paddr, &attrs);
197 }
198}
199
200/**
201 * bdisp_hw_alloc_filters
202 * @dev: device
203 *
204 * Allocate dma memory for filters
205 *
206 * RETURNS:
207 * 0 on success
208 */
209int bdisp_hw_alloc_filters(struct device *dev)
210{
211 unsigned int i, size;
212 void *base;
213 dma_addr_t paddr;
214 DEFINE_DMA_ATTRS(attrs);
215
216 /* Allocate all the filters within a single memory page */
217 size = (BDISP_HF_NB * NB_H_FILTER) + (BDISP_VF_NB * NB_V_FILTER);
218 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
219 base = dma_alloc_attrs(dev, size, &paddr, GFP_KERNEL | GFP_DMA, &attrs);
220 if (!base)
221 return -ENOMEM;
222
223 /* Setup filter addresses */
224 for (i = 0; i < NB_H_FILTER; i++) {
225 bdisp_h_filter[i].min = bdisp_h_spec[i].min;
226 bdisp_h_filter[i].max = bdisp_h_spec[i].max;
227 memcpy(base, bdisp_h_spec[i].coef, BDISP_HF_NB);
228 bdisp_h_filter[i].virt = base;
229 bdisp_h_filter[i].paddr = paddr;
230 base += BDISP_HF_NB;
231 paddr += BDISP_HF_NB;
232 }
233
234 for (i = 0; i < NB_V_FILTER; i++) {
235 bdisp_v_filter[i].min = bdisp_v_spec[i].min;
236 bdisp_v_filter[i].max = bdisp_v_spec[i].max;
237 memcpy(base, bdisp_v_spec[i].coef, BDISP_VF_NB);
238 bdisp_v_filter[i].virt = base;
239 bdisp_v_filter[i].paddr = paddr;
240 base += BDISP_VF_NB;
241 paddr += BDISP_VF_NB;
242 }
243
244 return 0;
245}
246
247/**
248 * bdisp_hw_get_hf_addr
249 * @inc: resize increment
250 *
251 * Find the horizontal filter table that fits the resize increment
252 *
253 * RETURNS:
254 * table physical address
255 */
256static dma_addr_t bdisp_hw_get_hf_addr(u16 inc)
257{
258 unsigned int i;
259
260 for (i = NB_H_FILTER - 1; i > 0; i--)
261 if ((bdisp_h_filter[i].min < inc) &&
262 (inc <= bdisp_h_filter[i].max))
263 break;
264
265 return bdisp_h_filter[i].paddr;
266}
267
268/**
269 * bdisp_hw_get_vf_addr
270 * @inc: resize increment
271 *
272 * Find the vertical filter table that fits the resize increment
273 *
274 * RETURNS:
275 * table physical address
276 */
277static dma_addr_t bdisp_hw_get_vf_addr(u16 inc)
278{
279 unsigned int i;
280
281 for (i = NB_V_FILTER - 1; i > 0; i--)
282 if ((bdisp_v_filter[i].min < inc) &&
283 (inc <= bdisp_v_filter[i].max))
284 break;
285
286 return bdisp_v_filter[i].paddr;
287}
288
289/**
290 * bdisp_hw_get_inc
291 * @from: input size
292 * @to: output size
293 * @inc: resize increment in 6.10 format
294 *
295 * Computes the increment (inverse of scale) in 6.10 format
296 *
297 * RETURNS:
298 * 0 on success
299 */
300static int bdisp_hw_get_inc(u32 from, u32 to, u16 *inc)
301{
302 u32 tmp;
303
304 if (!to)
305 return -EINVAL;
306
307 if (to == from) {
308 *inc = 1 << 10;
309 return 0;
310 }
311
312 tmp = (from << 10) / to;
313 if ((tmp > 0xFFFF) || (!tmp))
314 /* overflow (downscale x 63) or too small (upscale x 1024) */
315 return -EINVAL;
316
317 *inc = (u16)tmp;
318
319 return 0;
320}
321
322/**
323 * bdisp_hw_get_hv_inc
324 * @ctx: device context
325 * @h_inc: horizontal increment
326 * @v_inc: vertical increment
327 *
328 * Computes the horizontal & vertical increments (inverse of scale)
329 *
330 * RETURNS:
331 * 0 on success
332 */
333static int bdisp_hw_get_hv_inc(struct bdisp_ctx *ctx, u16 *h_inc, u16 *v_inc)
334{
335 u32 src_w, src_h, dst_w, dst_h;
336
337 src_w = ctx->src.crop.width;
338 src_h = ctx->src.crop.height;
339 dst_w = ctx->dst.width;
340 dst_h = ctx->dst.height;
341
342 if (bdisp_hw_get_inc(src_w, dst_w, h_inc) ||
343 bdisp_hw_get_inc(src_h, dst_h, v_inc)) {
344 dev_err(ctx->bdisp_dev->dev,
345 "scale factors failed (%dx%d)->(%dx%d)\n",
346 src_w, src_h, dst_w, dst_h);
347 return -EINVAL;
348 }
349
350 return 0;
351}
352
353/**
354 * bdisp_hw_get_op_cfg
355 * @ctx: device context
356 * @c: operation configuration
357 *
358 * Check which blitter operations are expected and sets the scaling increments
359 *
360 * RETURNS:
361 * 0 on success
362 */
363static int bdisp_hw_get_op_cfg(struct bdisp_ctx *ctx, struct bdisp_op_cfg *c)
364{
365 struct device *dev = ctx->bdisp_dev->dev;
366 struct bdisp_frame *src = &ctx->src;
367 struct bdisp_frame *dst = &ctx->dst;
368
369 if (src->width > MAX_SRC_WIDTH * MAX_VERTICAL_STRIDES) {
370 dev_err(dev, "Image width out of HW caps\n");
371 return -EINVAL;
372 }
373
374 c->wide = src->width > MAX_SRC_WIDTH;
375
376 c->hflip = ctx->hflip;
377 c->vflip = ctx->vflip;
378
379 c->src_interlaced = (src->field == V4L2_FIELD_INTERLACED);
380
381 c->src_nbp = src->fmt->nb_planes;
382 c->src_yuv = (src->fmt->pixelformat == V4L2_PIX_FMT_NV12) ||
383 (src->fmt->pixelformat == V4L2_PIX_FMT_YUV420);
384 c->src_420 = c->src_yuv;
385
386 c->dst_nbp = dst->fmt->nb_planes;
387 c->dst_yuv = (dst->fmt->pixelformat == V4L2_PIX_FMT_NV12) ||
388 (dst->fmt->pixelformat == V4L2_PIX_FMT_YUV420);
389 c->dst_420 = c->dst_yuv;
390
391 c->cconv = (c->src_yuv != c->dst_yuv);
392
393 if (bdisp_hw_get_hv_inc(ctx, &c->h_inc, &c->v_inc)) {
394 dev_err(dev, "Scale factor out of HW caps\n");
395 return -EINVAL;
396 }
397
398 /* Deinterlacing adjustment : stretch a field to a frame */
399 if (c->src_interlaced)
400 c->v_inc /= 2;
401
402 if ((c->h_inc != (1 << 10)) || (c->v_inc != (1 << 10)))
403 c->scale = true;
404 else
405 c->scale = false;
406
407 return 0;
408}
409
410/**
411 * bdisp_hw_color_format
412 * @pixelformat: v4l2 pixel format
413 *
414 * v4l2 to bdisp pixel format convert
415 *
416 * RETURNS:
417 * bdisp pixel format
418 */
419static u32 bdisp_hw_color_format(u32 pixelformat)
420{
421 u32 ret;
422
423 switch (pixelformat) {
424 case V4L2_PIX_FMT_YUV420:
425 ret = (BDISP_YUV_3B << BLT_TTY_COL_SHIFT);
426 break;
427 case V4L2_PIX_FMT_NV12:
428 ret = (BDISP_NV12 << BLT_TTY_COL_SHIFT) | BLT_TTY_BIG_END;
429 break;
430 case V4L2_PIX_FMT_RGB565:
431 ret = (BDISP_RGB565 << BLT_TTY_COL_SHIFT);
432 break;
433 case V4L2_PIX_FMT_XBGR32: /* This V4L format actually refers to xRGB */
434 ret = (BDISP_XRGB8888 << BLT_TTY_COL_SHIFT);
435 break;
436 case V4L2_PIX_FMT_RGB24: /* RGB888 format */
437 ret = (BDISP_RGB888 << BLT_TTY_COL_SHIFT) | BLT_TTY_BIG_END;
438 break;
439 case V4L2_PIX_FMT_ABGR32: /* This V4L format actually refers to ARGB */
440
441 default:
442 ret = (BDISP_ARGB8888 << BLT_TTY_COL_SHIFT) | BLT_TTY_ALPHA_R;
443 break;
444 }
445
446 return ret;
447}
448
449/**
450 * bdisp_hw_build_node
451 * @ctx: device context
452 * @cfg: operation configuration
453 * @node: node to be set
454 * @t_plan: whether the node refers to a RGB/Y or a CbCr plane
455 * @src_x_offset: x offset in the source image
456 *
457 * Build a node
458 *
459 * RETURNS:
460 * None
461 */
462static void bdisp_hw_build_node(struct bdisp_ctx *ctx,
463 struct bdisp_op_cfg *cfg,
464 struct bdisp_node *node,
465 enum bdisp_target_plan t_plan, int src_x_offset)
466{
467 struct bdisp_frame *src = &ctx->src;
468 struct bdisp_frame *dst = &ctx->dst;
469 u16 h_inc, v_inc, yh_inc, yv_inc;
470 struct v4l2_rect src_rect = src->crop;
471 struct v4l2_rect dst_rect = dst->crop;
472 int dst_x_offset;
473 s32 dst_width = dst->crop.width;
474 u32 src_fmt, dst_fmt;
475 const u32 *ivmx;
476
477 dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__);
478
479 memset(node, 0, sizeof(*node));
480
481 /* Adjust src and dst areas wrt src_x_offset */
482 src_rect.left += src_x_offset;
483 src_rect.width -= src_x_offset;
484 src_rect.width = min_t(__s32, MAX_SRC_WIDTH, src_rect.width);
485
486 dst_x_offset = (src_x_offset * dst->width) / ctx->src.crop.width;
487 dst_rect.left += dst_x_offset;
488 dst_rect.width = (src_rect.width * dst->width) / ctx->src.crop.width;
489
490 /* General */
491 src_fmt = src->fmt->pixelformat;
492 dst_fmt = dst->fmt->pixelformat;
493
494 node->nip = 0;
495 node->cic = BLT_CIC_ALL_GRP;
496 node->ack = BLT_ACK_BYPASS_S2S3;
497
498 switch (cfg->src_nbp) {
499 case 1:
500 /* Src2 = RGB / Src1 = Src3 = off */
501 node->ins = BLT_INS_S1_OFF | BLT_INS_S2_MEM | BLT_INS_S3_OFF;
502 break;
503 case 2:
504 /* Src3 = Y
505 * Src2 = CbCr or ColorFill if writing the Y plane
506 * Src1 = off */
507 node->ins = BLT_INS_S1_OFF | BLT_INS_S3_MEM;
508 if (t_plan == BDISP_Y)
509 node->ins |= BLT_INS_S2_CF;
510 else
511 node->ins |= BLT_INS_S2_MEM;
512 break;
513 case 3:
514 default:
515 /* Src3 = Y
516 * Src2 = Cb or ColorFill if writing the Y plane
517 * Src1 = Cr or ColorFill if writing the Y plane */
518 node->ins = BLT_INS_S3_MEM;
519 if (t_plan == BDISP_Y)
520 node->ins |= BLT_INS_S2_CF | BLT_INS_S1_CF;
521 else
522 node->ins |= BLT_INS_S2_MEM | BLT_INS_S1_MEM;
523 break;
524 }
525
526 /* Color convert */
527 node->ins |= cfg->cconv ? BLT_INS_IVMX : 0;
528 /* Scale needed if scaling OR 4:2:0 up/downsampling */
529 node->ins |= (cfg->scale || cfg->src_420 || cfg->dst_420) ?
530 BLT_INS_SCALE : 0;
531
532 /* Target */
533 node->tba = (t_plan == BDISP_CBCR) ? dst->paddr[1] : dst->paddr[0];
534
535 node->tty = dst->bytesperline;
536 node->tty |= bdisp_hw_color_format(dst_fmt);
537 node->tty |= BLT_TTY_DITHER;
538 node->tty |= (t_plan == BDISP_CBCR) ? BLT_TTY_CHROMA : 0;
539 node->tty |= cfg->hflip ? BLT_TTY_HSO : 0;
540 node->tty |= cfg->vflip ? BLT_TTY_VSO : 0;
541
542 if (cfg->dst_420 && (t_plan == BDISP_CBCR)) {
543 /* 420 chroma downsampling */
544 dst_rect.height /= 2;
545 dst_rect.width /= 2;
546 dst_rect.left /= 2;
547 dst_rect.top /= 2;
548 dst_x_offset /= 2;
549 dst_width /= 2;
550 }
551
552 node->txy = cfg->vflip ? (dst_rect.height - 1) : dst_rect.top;
553 node->txy <<= 16;
554 node->txy |= cfg->hflip ? (dst_width - dst_x_offset - 1) :
555 dst_rect.left;
556
557 node->tsz = dst_rect.height << 16 | dst_rect.width;
558
559 if (cfg->src_interlaced) {
560 /* handle only the top field which is half height of a frame */
561 src_rect.top /= 2;
562 src_rect.height /= 2;
563 }
564
565 if (cfg->src_nbp == 1) {
566 /* Src 2 : RGB */
567 node->s2ba = src->paddr[0];
568
569 node->s2ty = src->bytesperline;
570 if (cfg->src_interlaced)
571 node->s2ty *= 2;
572
573 node->s2ty |= bdisp_hw_color_format(src_fmt);
574
575 node->s2xy = src_rect.top << 16 | src_rect.left;
576 node->s2sz = src_rect.height << 16 | src_rect.width;
577 } else {
578 /* Src 2 : Cb or CbCr */
579 if (cfg->src_420) {
580 /* 420 chroma upsampling */
581 src_rect.top /= 2;
582 src_rect.left /= 2;
583 src_rect.width /= 2;
584 src_rect.height /= 2;
585 }
586
587 node->s2ba = src->paddr[1];
588
589 node->s2ty = src->bytesperline;
590 if (cfg->src_nbp == 3)
591 node->s2ty /= 2;
592 if (cfg->src_interlaced)
593 node->s2ty *= 2;
594
595 node->s2ty |= bdisp_hw_color_format(src_fmt);
596
597 node->s2xy = src_rect.top << 16 | src_rect.left;
598 node->s2sz = src_rect.height << 16 | src_rect.width;
599
600 if (cfg->src_nbp == 3) {
601 /* Src 1 : Cr */
602 node->s1ba = src->paddr[2];
603
604 node->s1ty = node->s2ty;
605 node->s1xy = node->s2xy;
606 }
607
608 /* Src 3 : Y */
609 node->s3ba = src->paddr[0];
610
611 node->s3ty = src->bytesperline;
612 if (cfg->src_interlaced)
613 node->s3ty *= 2;
614 node->s3ty |= bdisp_hw_color_format(src_fmt);
615
616 if ((t_plan != BDISP_CBCR) && cfg->src_420) {
617 /* No chroma upsampling for output RGB / Y plane */
618 node->s3xy = node->s2xy * 2;
619 node->s3sz = node->s2sz * 2;
620 } else {
621 /* No need to read Y (Src3) when writing Chroma */
622 node->s3ty |= BLT_S3TY_BLANK_ACC;
623 node->s3xy = node->s2xy;
624 node->s3sz = node->s2sz;
625 }
626 }
627
628 /* Resize (scale OR 4:2:0: chroma up/downsampling) */
629 if (node->ins & BLT_INS_SCALE) {
630 /* no need to compute Y when writing CbCr from RGB input */
631 bool skip_y = (t_plan == BDISP_CBCR) && !cfg->src_yuv;
632
633 /* FCTL */
634 if (cfg->scale) {
635 node->fctl = BLT_FCTL_HV_SCALE;
636 if (!skip_y)
637 node->fctl |= BLT_FCTL_Y_HV_SCALE;
638 } else {
639 node->fctl = BLT_FCTL_HV_SAMPLE;
640 if (!skip_y)
641 node->fctl |= BLT_FCTL_Y_HV_SAMPLE;
642 }
643
644 /* RSF - Chroma may need to be up/downsampled */
645 h_inc = cfg->h_inc;
646 v_inc = cfg->v_inc;
647 if (!cfg->src_420 && cfg->dst_420 && (t_plan == BDISP_CBCR)) {
648 /* RGB to 4:2:0 for Chroma: downsample */
649 h_inc *= 2;
650 v_inc *= 2;
651 } else if (cfg->src_420 && !cfg->dst_420) {
652 /* 4:2:0: to RGB: upsample*/
653 h_inc /= 2;
654 v_inc /= 2;
655 }
656 node->rsf = v_inc << 16 | h_inc;
657
658 /* RZI */
659 node->rzi = BLT_RZI_DEFAULT;
660
661 /* Filter table physical addr */
662 node->hfp = bdisp_hw_get_hf_addr(h_inc);
663 node->vfp = bdisp_hw_get_vf_addr(v_inc);
664
665 /* Y version */
666 if (!skip_y) {
667 yh_inc = cfg->h_inc;
668 yv_inc = cfg->v_inc;
669
670 node->y_rsf = yv_inc << 16 | yh_inc;
671 node->y_rzi = BLT_RZI_DEFAULT;
672 node->y_hfp = bdisp_hw_get_hf_addr(yh_inc);
673 node->y_vfp = bdisp_hw_get_vf_addr(yv_inc);
674 }
675 }
676
677 /* Versatile matrix for RGB / YUV conversion */
678 if (cfg->cconv) {
679 ivmx = cfg->src_yuv ? bdisp_yuv_to_rgb : bdisp_rgb_to_yuv;
680
681 node->ivmx0 = ivmx[0];
682 node->ivmx1 = ivmx[1];
683 node->ivmx2 = ivmx[2];
684 node->ivmx3 = ivmx[3];
685 }
686}
687
688/**
689 * bdisp_hw_build_all_nodes
690 * @ctx: device context
691 *
692 * Build all the nodes for the blitter operation
693 *
694 * RETURNS:
695 * 0 on success
696 */
697static int bdisp_hw_build_all_nodes(struct bdisp_ctx *ctx)
698{
699 struct bdisp_op_cfg cfg;
700 unsigned int i, nid = 0;
701 int src_x_offset = 0;
702
703 for (i = 0; i < MAX_NB_NODE; i++)
704 if (!ctx->node[i]) {
705 dev_err(ctx->bdisp_dev->dev, "node %d is null\n", i);
706 return -EINVAL;
707 }
708
709 /* Get configuration (scale, flip, ...) */
710 if (bdisp_hw_get_op_cfg(ctx, &cfg))
711 return -EINVAL;
712
713 /* Split source in vertical strides (HW constraint) */
714 for (i = 0; i < MAX_VERTICAL_STRIDES; i++) {
715 /* Build RGB/Y node and link it to the previous node */
716 bdisp_hw_build_node(ctx, &cfg, ctx->node[nid],
717 cfg.dst_nbp == 1 ? BDISP_RGB : BDISP_Y,
718 src_x_offset);
719 if (nid)
720 ctx->node[nid - 1]->nip = ctx->node_paddr[nid];
721 nid++;
722
723 /* Build additional Cb(Cr) node, link it to the previous one */
724 if (cfg.dst_nbp > 1) {
725 bdisp_hw_build_node(ctx, &cfg, ctx->node[nid],
726 BDISP_CBCR, src_x_offset);
727 ctx->node[nid - 1]->nip = ctx->node_paddr[nid];
728 nid++;
729 }
730
731 /* Next stride until full width covered */
732 src_x_offset += MAX_SRC_WIDTH;
733 if (src_x_offset >= ctx->src.crop.width)
734 break;
735 }
736
737 /* Mark last node as the last */
738 ctx->node[nid - 1]->nip = 0;
739
740 return 0;
741}
742
743/**
744 * bdisp_hw_save_request
745 * @ctx: device context
746 *
747 * Save a copy of the request and of the built nodes
748 *
749 * RETURNS:
750 * None
751 */
752static void bdisp_hw_save_request(struct bdisp_ctx *ctx)
753{
754 struct bdisp_node **copy_node = ctx->bdisp_dev->dbg.copy_node;
755 struct bdisp_request *request = &ctx->bdisp_dev->dbg.copy_request;
756 struct bdisp_node **node = ctx->node;
757 int i;
758
759 /* Request copy */
760 request->src = ctx->src;
761 request->dst = ctx->dst;
762 request->hflip = ctx->hflip;
763 request->vflip = ctx->vflip;
764 request->nb_req++;
765
766 /* Nodes copy */
767 for (i = 0; i < MAX_NB_NODE; i++) {
768 /* Allocate memory if not done yet */
769 if (!copy_node[i]) {
770 copy_node[i] = devm_kzalloc(ctx->bdisp_dev->dev,
771 sizeof(*copy_node),
772 GFP_KERNEL);
773 if (!copy_node[i])
774 return;
775 }
776 copy_node[i] = node[i];
777 }
778}
779
780/**
781 * bdisp_hw_update
782 * @ctx: device context
783 *
784 * Send the request to the HW
785 *
786 * RETURNS:
787 * 0 on success
788 */
789int bdisp_hw_update(struct bdisp_ctx *ctx)
790{
791 int ret;
792 struct bdisp_dev *bdisp = ctx->bdisp_dev;
793 struct device *dev = bdisp->dev;
794 unsigned int node_id;
795
796 dev_dbg(dev, "%s\n", __func__);
797
798 /* build nodes */
799 ret = bdisp_hw_build_all_nodes(ctx);
800 if (ret) {
801 dev_err(dev, "cannot build nodes (%d)\n", ret);
802 return ret;
803 }
804
805 /* Save a copy of the request */
806 bdisp_hw_save_request(ctx);
807
808 /* Configure interrupt to 'Last Node Reached for AQ1' */
809 writel(BLT_AQ1_CTL_CFG, bdisp->regs + BLT_AQ1_CTL);
810 writel(BLT_ITS_AQ1_LNA, bdisp->regs + BLT_ITM0);
811
812 /* Write first node addr */
813 writel(ctx->node_paddr[0], bdisp->regs + BLT_AQ1_IP);
814
815 /* Find and write last node addr : this starts the HW processing */
816 for (node_id = 0; node_id < MAX_NB_NODE - 1; node_id++) {
817 if (!ctx->node[node_id]->nip)
818 break;
819 }
820 writel(ctx->node_paddr[node_id], bdisp->regs + BLT_AQ1_LNA);
821
822 return 0;
823}
diff --git a/drivers/media/platform/sti/bdisp/bdisp-reg.h b/drivers/media/platform/sti/bdisp/bdisp-reg.h
new file mode 100644
index 000000000000..e7e1a425f65a
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/bdisp-reg.h
@@ -0,0 +1,235 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6
7struct bdisp_node {
8 /* 0 - General */
9 u32 nip;
10 u32 cic;
11 u32 ins;
12 u32 ack;
13 /* 1 - Target */
14 u32 tba;
15 u32 tty;
16 u32 txy;
17 u32 tsz;
18 /* 2 - Color Fill */
19 u32 s1cf;
20 u32 s2cf;
21 /* 3 - Source 1 */
22 u32 s1ba;
23 u32 s1ty;
24 u32 s1xy;
25 u32 s1sz_tsz;
26 /* 4 - Source 2 */
27 u32 s2ba;
28 u32 s2ty;
29 u32 s2xy;
30 u32 s2sz;
31 /* 5 - Source 3 */
32 u32 s3ba;
33 u32 s3ty;
34 u32 s3xy;
35 u32 s3sz;
36 /* 6 - Clipping */
37 u32 cwo;
38 u32 cws;
39 /* 7 - CLUT */
40 u32 cco;
41 u32 cml;
42 /* 8 - Filter & Mask */
43 u32 fctl;
44 u32 pmk;
45 /* 9 - Chroma Filter */
46 u32 rsf;
47 u32 rzi;
48 u32 hfp;
49 u32 vfp;
50 /* 10 - Luma Filter */
51 u32 y_rsf;
52 u32 y_rzi;
53 u32 y_hfp;
54 u32 y_vfp;
55 /* 11 - Flicker */
56 u32 ff0;
57 u32 ff1;
58 u32 ff2;
59 u32 ff3;
60 /* 12 - Color Key */
61 u32 key1;
62 u32 key2;
63 /* 14 - Static Address & User */
64 u32 sar;
65 u32 usr;
66 /* 15 - Input Versatile Matrix */
67 u32 ivmx0;
68 u32 ivmx1;
69 u32 ivmx2;
70 u32 ivmx3;
71 /* 16 - Output Versatile Matrix */
72 u32 ovmx0;
73 u32 ovmx1;
74 u32 ovmx2;
75 u32 ovmx3;
76 /* 17 - Pace */
77 u32 pace;
78 /* 18 - VC1R & DEI */
79 u32 vc1r;
80 u32 dei;
81 /* 19 - Gradient Fill */
82 u32 hgf;
83 u32 vgf;
84};
85
86/* HW registers : static */
87#define BLT_CTL 0x0A00
88#define BLT_ITS 0x0A04
89#define BLT_STA1 0x0A08
90#define BLT_AQ1_CTL 0x0A60
91#define BLT_AQ1_IP 0x0A64
92#define BLT_AQ1_LNA 0x0A68
93#define BLT_AQ1_STA 0x0A6C
94#define BLT_ITM0 0x0AD0
95/* HW registers : plugs */
96#define BLT_PLUGS1_OP2 0x0B04
97#define BLT_PLUGS1_CHZ 0x0B08
98#define BLT_PLUGS1_MSZ 0x0B0C
99#define BLT_PLUGS1_PGZ 0x0B10
100#define BLT_PLUGS2_OP2 0x0B24
101#define BLT_PLUGS2_CHZ 0x0B28
102#define BLT_PLUGS2_MSZ 0x0B2C
103#define BLT_PLUGS2_PGZ 0x0B30
104#define BLT_PLUGS3_OP2 0x0B44
105#define BLT_PLUGS3_CHZ 0x0B48
106#define BLT_PLUGS3_MSZ 0x0B4C
107#define BLT_PLUGS3_PGZ 0x0B50
108#define BLT_PLUGT_OP2 0x0B84
109#define BLT_PLUGT_CHZ 0x0B88
110#define BLT_PLUGT_MSZ 0x0B8C
111#define BLT_PLUGT_PGZ 0x0B90
112/* HW registers : node */
113#define BLT_NIP 0x0C00
114#define BLT_CIC 0x0C04
115#define BLT_INS 0x0C08
116#define BLT_ACK 0x0C0C
117#define BLT_TBA 0x0C10
118#define BLT_TTY 0x0C14
119#define BLT_TXY 0x0C18
120#define BLT_TSZ 0x0C1C
121#define BLT_S1BA 0x0C28
122#define BLT_S1TY 0x0C2C
123#define BLT_S1XY 0x0C30
124#define BLT_S2BA 0x0C38
125#define BLT_S2TY 0x0C3C
126#define BLT_S2XY 0x0C40
127#define BLT_S2SZ 0x0C44
128#define BLT_S3BA 0x0C48
129#define BLT_S3TY 0x0C4C
130#define BLT_S3XY 0x0C50
131#define BLT_S3SZ 0x0C54
132#define BLT_FCTL 0x0C68
133#define BLT_RSF 0x0C70
134#define BLT_RZI 0x0C74
135#define BLT_HFP 0x0C78
136#define BLT_VFP 0x0C7C
137#define BLT_Y_RSF 0x0C80
138#define BLT_Y_RZI 0x0C84
139#define BLT_Y_HFP 0x0C88
140#define BLT_Y_VFP 0x0C8C
141#define BLT_IVMX0 0x0CC0
142#define BLT_IVMX1 0x0CC4
143#define BLT_IVMX2 0x0CC8
144#define BLT_IVMX3 0x0CCC
145#define BLT_OVMX0 0x0CD0
146#define BLT_OVMX1 0x0CD4
147#define BLT_OVMX2 0x0CD8
148#define BLT_OVMX3 0x0CDC
149#define BLT_DEI 0x0CEC
150/* HW registers : filters */
151#define BLT_HFC_N 0x0D00
152#define BLT_VFC_N 0x0D90
153#define BLT_Y_HFC_N 0x0E00
154#define BLT_Y_VFC_N 0x0E90
155#define BLT_NB_H_COEF 16
156#define BLT_NB_V_COEF 10
157
158/* Registers values */
159#define BLT_CTL_RESET BIT(31) /* Global soft reset */
160
161#define BLT_ITS_AQ1_LNA BIT(12) /* AQ1 LNA reached */
162
163#define BLT_STA1_IDLE BIT(0) /* BDISP idle */
164
165#define BLT_AQ1_CTL_CFG 0x80400003 /* Enable, P3, LNA reached */
166
167#define BLT_INS_S1_MASK (BIT(0) | BIT(1) | BIT(2))
168#define BLT_INS_S1_OFF 0x00000000 /* src1 disabled */
169#define BLT_INS_S1_MEM 0x00000001 /* src1 fetched from memory */
170#define BLT_INS_S1_CF 0x00000003 /* src1 color fill */
171#define BLT_INS_S1_COPY 0x00000004 /* src1 direct copy */
172#define BLT_INS_S1_FILL 0x00000007 /* src1 firect fill */
173#define BLT_INS_S2_MASK (BIT(3) | BIT(4))
174#define BLT_INS_S2_OFF 0x00000000 /* src2 disabled */
175#define BLT_INS_S2_MEM 0x00000008 /* src2 fetched from memory */
176#define BLT_INS_S2_CF 0x00000018 /* src2 color fill */
177#define BLT_INS_S3_MASK BIT(5)
178#define BLT_INS_S3_OFF 0x00000000 /* src3 disabled */
179#define BLT_INS_S3_MEM 0x00000020 /* src3 fetched from memory */
180#define BLT_INS_IVMX BIT(6) /* Input versatile matrix */
181#define BLT_INS_CLUT BIT(7) /* Color Look Up Table */
182#define BLT_INS_SCALE BIT(8) /* Scaling */
183#define BLT_INS_FLICK BIT(9) /* Flicker filter */
184#define BLT_INS_CLIP BIT(10) /* Clipping */
185#define BLT_INS_CKEY BIT(11) /* Color key */
186#define BLT_INS_OVMX BIT(12) /* Output versatile matrix */
187#define BLT_INS_DEI BIT(13) /* Deinterlace */
188#define BLT_INS_PMASK BIT(14) /* Plane mask */
189#define BLT_INS_VC1R BIT(17) /* VC1 Range mapping */
190#define BLT_INS_ROTATE BIT(18) /* Rotation */
191#define BLT_INS_GRAD BIT(19) /* Gradient fill */
192#define BLT_INS_AQLOCK BIT(29) /* AQ lock */
193#define BLT_INS_PACE BIT(30) /* Pace down */
194#define BLT_INS_IRQ BIT(31) /* Raise IRQ when node done */
195#define BLT_CIC_ALL_GRP 0x000FDFFC /* all valid groups present */
196#define BLT_ACK_BYPASS_S2S3 0x00000007 /* Bypass src2 and src3 */
197
198#define BLT_TTY_COL_SHIFT 16 /* Color format */
199#define BLT_TTY_COL_MASK 0x001F0000 /* Color format mask */
200#define BLT_TTY_ALPHA_R BIT(21) /* Alpha range */
201#define BLT_TTY_CR_NOT_CB BIT(22) /* CR not Cb */
202#define BLT_TTY_MB BIT(23) /* MB frame / field*/
203#define BLT_TTY_HSO BIT(24) /* H scan order */
204#define BLT_TTY_VSO BIT(25) /* V scan order */
205#define BLT_TTY_DITHER BIT(26) /* Dithering */
206#define BLT_TTY_CHROMA BIT(27) /* Write chroma / luma */
207#define BLT_TTY_BIG_END BIT(30) /* Big endianness */
208
209#define BLT_S1TY_A1_SUBSET BIT(22) /* A1 subset */
210#define BLT_S1TY_CHROMA_EXT BIT(26) /* Chroma Extended */
211#define BTL_S1TY_SUBBYTE BIT(28) /* Sub-byte fmt, pixel order */
212#define BLT_S1TY_RGB_EXP BIT(29) /* RGB expansion mode */
213
214#define BLT_S2TY_A1_SUBSET BIT(22) /* A1 subset */
215#define BLT_S2TY_CHROMA_EXT BIT(26) /* Chroma Extended */
216#define BTL_S2TY_SUBBYTE BIT(28) /* Sub-byte fmt, pixel order */
217#define BLT_S2TY_RGB_EXP BIT(29) /* RGB expansion mode */
218
219#define BLT_S3TY_BLANK_ACC BIT(26) /* Blank access */
220
221#define BLT_FCTL_HV_SCALE 0x00000055 /* H/V resize + color filter */
222#define BLT_FCTL_Y_HV_SCALE 0x33000000 /* Luma version */
223
224#define BLT_FCTL_HV_SAMPLE 0x00000044 /* H/V resize */
225#define BLT_FCTL_Y_HV_SAMPLE 0x22000000 /* Luma version */
226
227#define BLT_RZI_DEFAULT 0x20003000 /* H/VNB_repeat = 3/2 */
228
229/* Color format */
230#define BDISP_RGB565 0x00 /* RGB565 */
231#define BDISP_RGB888 0x01 /* RGB888 */
232#define BDISP_XRGB8888 0x02 /* RGB888_32 */
233#define BDISP_ARGB8888 0x05 /* ARGB888 */
234#define BDISP_NV12 0x16 /* YCbCr42x R2B */
235#define BDISP_YUV_3B 0x1E /* YUV (3 buffer) */
diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
new file mode 100644
index 000000000000..9e782ebe18da
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
@@ -0,0 +1,1416 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6
7#include <linux/errno.h>
8#include <linux/interrupt.h>
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/of.h>
12#include <linux/pm_runtime.h>
13#include <linux/slab.h>
14
15#include <media/v4l2-event.h>
16#include <media/v4l2-ioctl.h>
17
18#include "bdisp.h"
19
20#define BDISP_MAX_CTRL_NUM 10
21
22#define BDISP_WORK_TIMEOUT ((100 * HZ) / 1000)
23
24/* User configuration change */
25#define BDISP_PARAMS BIT(0) /* Config updated */
26#define BDISP_SRC_FMT BIT(1) /* Source set */
27#define BDISP_DST_FMT BIT(2) /* Destination set */
28#define BDISP_CTX_STOP_REQ BIT(3) /* Stop request */
29#define BDISP_CTX_ABORT BIT(4) /* Abort while device run */
30
31#define BDISP_MIN_W 1
32#define BDISP_MAX_W 8191
33#define BDISP_MIN_H 1
34#define BDISP_MAX_H 8191
35
36#define fh_to_ctx(__fh) container_of(__fh, struct bdisp_ctx, fh)
37
38enum bdisp_dev_flags {
39 ST_M2M_OPEN, /* Driver opened */
40 ST_M2M_RUNNING, /* HW device running */
41 ST_M2M_SUSPENDED, /* Driver suspended */
42 ST_M2M_SUSPENDING, /* Driver being suspended */
43};
44
45static const struct bdisp_fmt bdisp_formats[] = {
46 /* ARGB888. [31:0] A:R:G:B 8:8:8:8 little endian */
47 {
48 .pixelformat = V4L2_PIX_FMT_ABGR32, /* is actually ARGB */
49 .nb_planes = 1,
50 .bpp = 32,
51 .bpp_plane0 = 32,
52 .w_align = 1,
53 .h_align = 1
54 },
55 /* XRGB888. [31:0] x:R:G:B 8:8:8:8 little endian */
56 {
57 .pixelformat = V4L2_PIX_FMT_XBGR32, /* is actually xRGB */
58 .nb_planes = 1,
59 .bpp = 32,
60 .bpp_plane0 = 32,
61 .w_align = 1,
62 .h_align = 1
63 },
64 /* RGB565. [15:0] R:G:B 5:6:5 little endian */
65 {
66 .pixelformat = V4L2_PIX_FMT_RGB565,
67 .nb_planes = 1,
68 .bpp = 16,
69 .bpp_plane0 = 16,
70 .w_align = 1,
71 .h_align = 1
72 },
73 /* NV12. YUV420SP - 1 plane for Y + 1 plane for (CbCr) */
74 {
75 .pixelformat = V4L2_PIX_FMT_NV12,
76 .nb_planes = 2,
77 .bpp = 12,
78 .bpp_plane0 = 8,
79 .w_align = 2,
80 .h_align = 2
81 },
82 /* RGB888. [23:0] B:G:R 8:8:8 little endian */
83 {
84 .pixelformat = V4L2_PIX_FMT_RGB24,
85 .nb_planes = 1,
86 .bpp = 24,
87 .bpp_plane0 = 24,
88 .w_align = 1,
89 .h_align = 1
90 },
91 /* YU12. YUV420P - 1 plane for Y + 1 plane for Cb + 1 plane for Cr
92 * To keep as the LAST element of this table (no support on capture)
93 */
94 {
95 .pixelformat = V4L2_PIX_FMT_YUV420,
96 .nb_planes = 3,
97 .bpp = 12,
98 .bpp_plane0 = 8,
99 .w_align = 2,
100 .h_align = 2
101 }
102};
103
104/* Default format : HD ARGB32*/
105#define BDISP_DEF_WIDTH 1920
106#define BDISP_DEF_HEIGHT 1080
107
108static const struct bdisp_frame bdisp_dflt_fmt = {
109 .width = BDISP_DEF_WIDTH,
110 .height = BDISP_DEF_HEIGHT,
111 .fmt = &bdisp_formats[0],
112 .field = V4L2_FIELD_NONE,
113 .bytesperline = BDISP_DEF_WIDTH * 4,
114 .sizeimage = BDISP_DEF_WIDTH * BDISP_DEF_HEIGHT * 4,
115 .colorspace = V4L2_COLORSPACE_REC709,
116 .crop = {0, 0, BDISP_DEF_WIDTH, BDISP_DEF_HEIGHT},
117 .paddr = {0, 0, 0, 0}
118};
119
120static inline void bdisp_ctx_state_lock_set(u32 state, struct bdisp_ctx *ctx)
121{
122 unsigned long flags;
123
124 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags);
125 ctx->state |= state;
126 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags);
127}
128
129static inline void bdisp_ctx_state_lock_clear(u32 state, struct bdisp_ctx *ctx)
130{
131 unsigned long flags;
132
133 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags);
134 ctx->state &= ~state;
135 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags);
136}
137
138static inline bool bdisp_ctx_state_is_set(u32 mask, struct bdisp_ctx *ctx)
139{
140 unsigned long flags;
141 bool ret;
142
143 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags);
144 ret = (ctx->state & mask) == mask;
145 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags);
146
147 return ret;
148}
149
150static const struct bdisp_fmt *bdisp_find_fmt(u32 pixelformat)
151{
152 const struct bdisp_fmt *fmt;
153 unsigned int i;
154
155 for (i = 0; i < ARRAY_SIZE(bdisp_formats); i++) {
156 fmt = &bdisp_formats[i];
157 if (fmt->pixelformat == pixelformat)
158 return fmt;
159 }
160
161 return NULL;
162}
163
164static struct bdisp_frame *ctx_get_frame(struct bdisp_ctx *ctx,
165 enum v4l2_buf_type type)
166{
167 switch (type) {
168 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
169 return &ctx->src;
170 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
171 return &ctx->dst;
172 default:
173 dev_err(ctx->bdisp_dev->dev,
174 "Wrong buffer/video queue type (%d)\n", type);
175 break;
176 }
177
178 return ERR_PTR(-EINVAL);
179}
180
181static void bdisp_job_finish(struct bdisp_ctx *ctx, int vb_state)
182{
183 struct vb2_buffer *src_vb, *dst_vb;
184
185 if (WARN(!ctx || !ctx->fh.m2m_ctx, "Null hardware context\n"))
186 return;
187
188 dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__);
189
190 src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
191 dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
192
193 if (src_vb && dst_vb) {
194 dst_vb->v4l2_buf.timestamp = src_vb->v4l2_buf.timestamp;
195 dst_vb->v4l2_buf.timecode = src_vb->v4l2_buf.timecode;
196 dst_vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
197 dst_vb->v4l2_buf.flags |= src_vb->v4l2_buf.flags &
198 V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
199
200 v4l2_m2m_buf_done(src_vb, vb_state);
201 v4l2_m2m_buf_done(dst_vb, vb_state);
202
203 v4l2_m2m_job_finish(ctx->bdisp_dev->m2m.m2m_dev,
204 ctx->fh.m2m_ctx);
205 }
206}
207
208static int bdisp_ctx_stop_req(struct bdisp_ctx *ctx)
209{
210 struct bdisp_ctx *curr_ctx;
211 struct bdisp_dev *bdisp = ctx->bdisp_dev;
212 int ret;
213
214 dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__);
215
216 cancel_delayed_work(&bdisp->timeout_work);
217
218 curr_ctx = v4l2_m2m_get_curr_priv(bdisp->m2m.m2m_dev);
219 if (!test_bit(ST_M2M_RUNNING, &bdisp->state) || (curr_ctx != ctx))
220 return 0;
221
222 bdisp_ctx_state_lock_set(BDISP_CTX_STOP_REQ, ctx);
223
224 ret = wait_event_timeout(bdisp->irq_queue,
225 !bdisp_ctx_state_is_set(BDISP_CTX_STOP_REQ, ctx),
226 BDISP_WORK_TIMEOUT);
227
228 if (!ret) {
229 dev_err(ctx->bdisp_dev->dev, "%s IRQ timeout\n", __func__);
230 return -ETIMEDOUT;
231 }
232
233 return 0;
234}
235
236static void __bdisp_job_abort(struct bdisp_ctx *ctx)
237{
238 int ret;
239
240 ret = bdisp_ctx_stop_req(ctx);
241 if ((ret == -ETIMEDOUT) || (ctx->state & BDISP_CTX_ABORT)) {
242 bdisp_ctx_state_lock_clear(BDISP_CTX_STOP_REQ | BDISP_CTX_ABORT,
243 ctx);
244 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR);
245 }
246}
247
248static void bdisp_job_abort(void *priv)
249{
250 __bdisp_job_abort((struct bdisp_ctx *)priv);
251}
252
253static int bdisp_get_addr(struct bdisp_ctx *ctx, struct vb2_buffer *vb,
254 struct bdisp_frame *frame, dma_addr_t *paddr)
255{
256 if (!vb || !frame)
257 return -EINVAL;
258
259 paddr[0] = vb2_dma_contig_plane_dma_addr(vb, 0);
260
261 if (frame->fmt->nb_planes > 1)
262 /* UV (NV12) or U (420P) */
263 paddr[1] = (dma_addr_t)(paddr[0] +
264 frame->bytesperline * frame->height);
265
266 if (frame->fmt->nb_planes > 2)
267 /* V (420P) */
268 paddr[2] = (dma_addr_t)(paddr[1] +
269 (frame->bytesperline * frame->height) / 4);
270
271 if (frame->fmt->nb_planes > 3)
272 dev_dbg(ctx->bdisp_dev->dev, "ignoring some planes\n");
273
274 dev_dbg(ctx->bdisp_dev->dev,
275 "%s plane[0]=%pad plane[1]=%pad plane[2]=%pad\n",
276 __func__, &paddr[0], &paddr[1], &paddr[2]);
277
278 return 0;
279}
280
281static int bdisp_get_bufs(struct bdisp_ctx *ctx)
282{
283 struct bdisp_frame *src, *dst;
284 struct vb2_buffer *src_vb, *dst_vb;
285 int ret;
286
287 src = &ctx->src;
288 dst = &ctx->dst;
289
290 src_vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
291 ret = bdisp_get_addr(ctx, src_vb, src, src->paddr);
292 if (ret)
293 return ret;
294
295 dst_vb = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
296 ret = bdisp_get_addr(ctx, dst_vb, dst, dst->paddr);
297 if (ret)
298 return ret;
299
300 dst_vb->v4l2_buf.timestamp = src_vb->v4l2_buf.timestamp;
301
302 return 0;
303}
304
305static void bdisp_device_run(void *priv)
306{
307 struct bdisp_ctx *ctx = priv;
308 struct bdisp_dev *bdisp;
309 unsigned long flags;
310 int err = 0;
311
312 if (WARN(!ctx, "Null hardware context\n"))
313 return;
314
315 bdisp = ctx->bdisp_dev;
316 dev_dbg(bdisp->dev, "%s\n", __func__);
317 spin_lock_irqsave(&bdisp->slock, flags);
318
319 if (bdisp->m2m.ctx != ctx) {
320 dev_dbg(bdisp->dev, "ctx updated: %p -> %p\n",
321 bdisp->m2m.ctx, ctx);
322 ctx->state |= BDISP_PARAMS;
323 bdisp->m2m.ctx = ctx;
324 }
325
326 if (ctx->state & BDISP_CTX_STOP_REQ) {
327 ctx->state &= ~BDISP_CTX_STOP_REQ;
328 ctx->state |= BDISP_CTX_ABORT;
329 wake_up(&bdisp->irq_queue);
330 goto out;
331 }
332
333 err = bdisp_get_bufs(ctx);
334 if (err) {
335 dev_err(bdisp->dev, "cannot get address\n");
336 goto out;
337 }
338
339 bdisp_dbg_perf_begin(bdisp);
340
341 err = bdisp_hw_reset(bdisp);
342 if (err) {
343 dev_err(bdisp->dev, "could not get HW ready\n");
344 goto out;
345 }
346
347 err = bdisp_hw_update(ctx);
348 if (err) {
349 dev_err(bdisp->dev, "could not send HW request\n");
350 goto out;
351 }
352
353 queue_delayed_work(bdisp->work_queue, &bdisp->timeout_work,
354 BDISP_WORK_TIMEOUT);
355 set_bit(ST_M2M_RUNNING, &bdisp->state);
356out:
357 ctx->state &= ~BDISP_PARAMS;
358 spin_unlock_irqrestore(&bdisp->slock, flags);
359 if (err)
360 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR);
361}
362
363static struct v4l2_m2m_ops bdisp_m2m_ops = {
364 .device_run = bdisp_device_run,
365 .job_abort = bdisp_job_abort,
366};
367
368static int __bdisp_s_ctrl(struct bdisp_ctx *ctx, struct v4l2_ctrl *ctrl)
369{
370 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
371 return 0;
372
373 switch (ctrl->id) {
374 case V4L2_CID_HFLIP:
375 ctx->hflip = ctrl->val;
376 break;
377 case V4L2_CID_VFLIP:
378 ctx->vflip = ctrl->val;
379 break;
380 default:
381 dev_err(ctx->bdisp_dev->dev, "unknown control %d\n", ctrl->id);
382 return -EINVAL;
383 }
384
385 ctx->state |= BDISP_PARAMS;
386
387 return 0;
388}
389
390static int bdisp_s_ctrl(struct v4l2_ctrl *ctrl)
391{
392 struct bdisp_ctx *ctx = container_of(ctrl->handler, struct bdisp_ctx,
393 ctrl_handler);
394 unsigned long flags;
395 int ret;
396
397 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags);
398 ret = __bdisp_s_ctrl(ctx, ctrl);
399 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags);
400
401 return ret;
402}
403
404static const struct v4l2_ctrl_ops bdisp_c_ops = {
405 .s_ctrl = bdisp_s_ctrl,
406};
407
408static int bdisp_ctrls_create(struct bdisp_ctx *ctx)
409{
410 if (ctx->ctrls_rdy)
411 return 0;
412
413 v4l2_ctrl_handler_init(&ctx->ctrl_handler, BDISP_MAX_CTRL_NUM);
414
415 ctx->bdisp_ctrls.hflip = v4l2_ctrl_new_std(&ctx->ctrl_handler,
416 &bdisp_c_ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
417 ctx->bdisp_ctrls.vflip = v4l2_ctrl_new_std(&ctx->ctrl_handler,
418 &bdisp_c_ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
419
420 if (ctx->ctrl_handler.error) {
421 int err = ctx->ctrl_handler.error;
422
423 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
424 return err;
425 }
426
427 ctx->ctrls_rdy = true;
428
429 return 0;
430}
431
432static void bdisp_ctrls_delete(struct bdisp_ctx *ctx)
433{
434 if (ctx->ctrls_rdy) {
435 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
436 ctx->ctrls_rdy = false;
437 }
438}
439
440static int bdisp_queue_setup(struct vb2_queue *vq,
441 const struct v4l2_format *fmt,
442 unsigned int *nb_buf, unsigned int *nb_planes,
443 unsigned int sizes[], void *allocators[])
444{
445 struct bdisp_ctx *ctx = vb2_get_drv_priv(vq);
446 struct bdisp_frame *frame = ctx_get_frame(ctx, vq->type);
447
448 if (IS_ERR(frame)) {
449 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame);
450 return PTR_ERR(frame);
451 }
452
453 if (!frame->fmt) {
454 dev_err(ctx->bdisp_dev->dev, "Invalid format\n");
455 return -EINVAL;
456 }
457
458 if (fmt && fmt->fmt.pix.sizeimage < frame->sizeimage)
459 return -EINVAL;
460
461 *nb_planes = 1;
462 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : frame->sizeimage;
463 allocators[0] = ctx->bdisp_dev->alloc_ctx;
464
465 return 0;
466}
467
468static int bdisp_buf_prepare(struct vb2_buffer *vb)
469{
470 struct bdisp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
471 struct bdisp_frame *frame = ctx_get_frame(ctx, vb->vb2_queue->type);
472
473 if (IS_ERR(frame)) {
474 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame);
475 return PTR_ERR(frame);
476 }
477
478 if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
479 vb2_set_plane_payload(vb, 0, frame->sizeimage);
480
481 return 0;
482}
483
484static void bdisp_buf_queue(struct vb2_buffer *vb)
485{
486 struct bdisp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
487
488 /* return to V4L2 any 0-size buffer so it can be dequeued by user */
489 if (!vb2_get_plane_payload(vb, 0)) {
490 dev_dbg(ctx->bdisp_dev->dev, "0 data buffer, skip it\n");
491 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
492 return;
493 }
494
495 if (ctx->fh.m2m_ctx)
496 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
497}
498
499static int bdisp_start_streaming(struct vb2_queue *q, unsigned int count)
500{
501 struct bdisp_ctx *ctx = q->drv_priv;
502 struct vb2_buffer *buf;
503 int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev);
504
505 if (ret < 0) {
506 dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n");
507
508 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
509 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
510 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_QUEUED);
511 } else {
512 while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx)))
513 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_QUEUED);
514 }
515
516 return ret;
517 }
518
519 return 0;
520}
521
522static void bdisp_stop_streaming(struct vb2_queue *q)
523{
524 struct bdisp_ctx *ctx = q->drv_priv;
525
526 __bdisp_job_abort(ctx);
527
528 pm_runtime_put(ctx->bdisp_dev->dev);
529}
530
531static struct vb2_ops bdisp_qops = {
532 .queue_setup = bdisp_queue_setup,
533 .buf_prepare = bdisp_buf_prepare,
534 .buf_queue = bdisp_buf_queue,
535 .wait_prepare = vb2_ops_wait_prepare,
536 .wait_finish = vb2_ops_wait_finish,
537 .stop_streaming = bdisp_stop_streaming,
538 .start_streaming = bdisp_start_streaming,
539};
540
541static int queue_init(void *priv,
542 struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
543{
544 struct bdisp_ctx *ctx = priv;
545 int ret;
546
547 memset(src_vq, 0, sizeof(*src_vq));
548 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
549 src_vq->io_modes = VB2_MMAP | VB2_DMABUF;
550 src_vq->drv_priv = ctx;
551 src_vq->ops = &bdisp_qops;
552 src_vq->mem_ops = &vb2_dma_contig_memops;
553 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
554 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
555 src_vq->lock = &ctx->bdisp_dev->lock;
556
557 ret = vb2_queue_init(src_vq);
558 if (ret)
559 return ret;
560
561 memset(dst_vq, 0, sizeof(*dst_vq));
562 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
563 dst_vq->io_modes = VB2_MMAP | VB2_DMABUF;
564 dst_vq->drv_priv = ctx;
565 dst_vq->ops = &bdisp_qops;
566 dst_vq->mem_ops = &vb2_dma_contig_memops;
567 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
568 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
569 dst_vq->lock = &ctx->bdisp_dev->lock;
570
571 return vb2_queue_init(dst_vq);
572}
573
574static int bdisp_open(struct file *file)
575{
576 struct bdisp_dev *bdisp = video_drvdata(file);
577 struct bdisp_ctx *ctx = NULL;
578 int ret;
579
580 if (mutex_lock_interruptible(&bdisp->lock))
581 return -ERESTARTSYS;
582
583 /* Allocate memory for both context and node */
584 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
585 if (!ctx) {
586 ret = -ENOMEM;
587 goto unlock;
588 }
589 ctx->bdisp_dev = bdisp;
590
591 if (bdisp_hw_alloc_nodes(ctx)) {
592 dev_err(bdisp->dev, "no memory for nodes\n");
593 ret = -ENOMEM;
594 goto mem_ctx;
595 }
596
597 v4l2_fh_init(&ctx->fh, bdisp->m2m.vdev);
598
599 ret = bdisp_ctrls_create(ctx);
600 if (ret) {
601 dev_err(bdisp->dev, "Failed to create control\n");
602 goto error_fh;
603 }
604
605 /* Use separate control handler per file handle */
606 ctx->fh.ctrl_handler = &ctx->ctrl_handler;
607 file->private_data = &ctx->fh;
608 v4l2_fh_add(&ctx->fh);
609
610 /* Default format */
611 ctx->src = bdisp_dflt_fmt;
612 ctx->dst = bdisp_dflt_fmt;
613
614 /* Setup the device context for mem2mem mode. */
615 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(bdisp->m2m.m2m_dev, ctx,
616 queue_init);
617 if (IS_ERR(ctx->fh.m2m_ctx)) {
618 dev_err(bdisp->dev, "Failed to initialize m2m context\n");
619 ret = PTR_ERR(ctx->fh.m2m_ctx);
620 goto error_ctrls;
621 }
622
623 bdisp->m2m.refcnt++;
624 set_bit(ST_M2M_OPEN, &bdisp->state);
625
626 dev_dbg(bdisp->dev, "driver opened, ctx = 0x%p\n", ctx);
627
628 mutex_unlock(&bdisp->lock);
629
630 return 0;
631
632error_ctrls:
633 bdisp_ctrls_delete(ctx);
634error_fh:
635 v4l2_fh_del(&ctx->fh);
636 v4l2_fh_exit(&ctx->fh);
637 bdisp_hw_free_nodes(ctx);
638mem_ctx:
639 kfree(ctx);
640unlock:
641 mutex_unlock(&bdisp->lock);
642
643 return ret;
644}
645
646static int bdisp_release(struct file *file)
647{
648 struct bdisp_ctx *ctx = fh_to_ctx(file->private_data);
649 struct bdisp_dev *bdisp = ctx->bdisp_dev;
650
651 dev_dbg(bdisp->dev, "%s\n", __func__);
652
653 if (mutex_lock_interruptible(&bdisp->lock))
654 return -ERESTARTSYS;
655
656 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
657
658 bdisp_ctrls_delete(ctx);
659
660 v4l2_fh_del(&ctx->fh);
661 v4l2_fh_exit(&ctx->fh);
662
663 if (--bdisp->m2m.refcnt <= 0)
664 clear_bit(ST_M2M_OPEN, &bdisp->state);
665
666 bdisp_hw_free_nodes(ctx);
667
668 kfree(ctx);
669
670 mutex_unlock(&bdisp->lock);
671
672 return 0;
673}
674
675static const struct v4l2_file_operations bdisp_fops = {
676 .owner = THIS_MODULE,
677 .open = bdisp_open,
678 .release = bdisp_release,
679 .poll = v4l2_m2m_fop_poll,
680 .unlocked_ioctl = video_ioctl2,
681 .mmap = v4l2_m2m_fop_mmap,
682};
683
684static int bdisp_querycap(struct file *file, void *fh,
685 struct v4l2_capability *cap)
686{
687 struct bdisp_ctx *ctx = fh_to_ctx(fh);
688 struct bdisp_dev *bdisp = ctx->bdisp_dev;
689
690 strlcpy(cap->driver, bdisp->pdev->name, sizeof(cap->driver));
691 strlcpy(cap->card, bdisp->pdev->name, sizeof(cap->card));
692 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s%d",
693 BDISP_NAME, bdisp->id);
694
695 cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M;
696
697 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
698
699 return 0;
700}
701
702static int bdisp_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
703{
704 struct bdisp_ctx *ctx = fh_to_ctx(fh);
705 const struct bdisp_fmt *fmt;
706
707 if (f->index >= ARRAY_SIZE(bdisp_formats))
708 return -EINVAL;
709
710 fmt = &bdisp_formats[f->index];
711
712 if ((fmt->pixelformat == V4L2_PIX_FMT_YUV420) &&
713 (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
714 dev_dbg(ctx->bdisp_dev->dev, "No YU12 on capture\n");
715 return -EINVAL;
716 }
717 f->pixelformat = fmt->pixelformat;
718
719 return 0;
720}
721
722static int bdisp_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
723{
724 struct bdisp_ctx *ctx = fh_to_ctx(fh);
725 struct v4l2_pix_format *pix = &f->fmt.pix;
726 struct bdisp_frame *frame = ctx_get_frame(ctx, f->type);
727
728 if (IS_ERR(frame)) {
729 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame);
730 return PTR_ERR(frame);
731 }
732
733 pix = &f->fmt.pix;
734 pix->width = frame->width;
735 pix->height = frame->height;
736 pix->pixelformat = frame->fmt->pixelformat;
737 pix->field = frame->field;
738 pix->bytesperline = frame->bytesperline;
739 pix->sizeimage = frame->sizeimage;
740 pix->colorspace = (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
741 frame->colorspace : bdisp_dflt_fmt.colorspace;
742
743 return 0;
744}
745
746static int bdisp_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
747{
748 struct bdisp_ctx *ctx = fh_to_ctx(fh);
749 struct v4l2_pix_format *pix = &f->fmt.pix;
750 const struct bdisp_fmt *format;
751 u32 in_w, in_h;
752
753 format = bdisp_find_fmt(pix->pixelformat);
754 if (!format) {
755 dev_dbg(ctx->bdisp_dev->dev, "Unknown format 0x%x\n",
756 pix->pixelformat);
757 return -EINVAL;
758 }
759
760 /* YUV420P only supported for VIDEO_OUTPUT */
761 if ((format->pixelformat == V4L2_PIX_FMT_YUV420) &&
762 (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
763 dev_dbg(ctx->bdisp_dev->dev, "No YU12 on capture\n");
764 return -EINVAL;
765 }
766
767 /* Field (interlaced only supported on OUTPUT) */
768 if ((f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
769 (pix->field != V4L2_FIELD_INTERLACED))
770 pix->field = V4L2_FIELD_NONE;
771
772 /* Adjust width & height */
773 in_w = pix->width;
774 in_h = pix->height;
775 v4l_bound_align_image(&pix->width,
776 BDISP_MIN_W, BDISP_MAX_W,
777 ffs(format->w_align) - 1,
778 &pix->height,
779 BDISP_MIN_H, BDISP_MAX_H,
780 ffs(format->h_align) - 1,
781 0);
782 if ((pix->width != in_w) || (pix->height != in_h))
783 dev_dbg(ctx->bdisp_dev->dev,
784 "%s size updated: %dx%d -> %dx%d\n", __func__,
785 in_w, in_h, pix->width, pix->height);
786
787 pix->bytesperline = (pix->width * format->bpp_plane0) / 8;
788 pix->sizeimage = (pix->width * pix->height * format->bpp) / 8;
789
790 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
791 pix->colorspace = bdisp_dflt_fmt.colorspace;
792
793 return 0;
794}
795
796static int bdisp_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
797{
798 struct bdisp_ctx *ctx = fh_to_ctx(fh);
799 struct vb2_queue *vq;
800 struct bdisp_frame *frame;
801 struct v4l2_pix_format *pix;
802 int ret;
803 u32 state;
804
805 ret = bdisp_try_fmt(file, fh, f);
806 if (ret) {
807 dev_err(ctx->bdisp_dev->dev, "Cannot set format\n");
808 return ret;
809 }
810
811 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
812 if (vb2_is_streaming(vq)) {
813 dev_err(ctx->bdisp_dev->dev, "queue (%d) busy\n", f->type);
814 return -EBUSY;
815 }
816
817 frame = (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
818 &ctx->src : &ctx->dst;
819 pix = &f->fmt.pix;
820 frame->fmt = bdisp_find_fmt(pix->pixelformat);
821 if (!frame->fmt) {
822 dev_err(ctx->bdisp_dev->dev, "Unknown format 0x%x\n",
823 pix->pixelformat);
824 return -EINVAL;
825 }
826
827 frame->width = pix->width;
828 frame->height = pix->height;
829 frame->bytesperline = pix->bytesperline;
830 frame->sizeimage = pix->sizeimage;
831 frame->field = pix->field;
832 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
833 frame->colorspace = pix->colorspace;
834
835 frame->crop.width = frame->width;
836 frame->crop.height = frame->height;
837 frame->crop.left = 0;
838 frame->crop.top = 0;
839
840 state = BDISP_PARAMS;
841 state |= (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
842 BDISP_DST_FMT : BDISP_SRC_FMT;
843 bdisp_ctx_state_lock_set(state, ctx);
844
845 return 0;
846}
847
848static int bdisp_g_selection(struct file *file, void *fh,
849 struct v4l2_selection *s)
850{
851 struct bdisp_frame *frame;
852 struct bdisp_ctx *ctx = fh_to_ctx(fh);
853
854 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
855 /* Composing / capture is not supported */
856 dev_dbg(ctx->bdisp_dev->dev, "Not supported for capture\n");
857 return -EINVAL;
858 }
859
860 frame = ctx_get_frame(ctx, s->type);
861 if (IS_ERR(frame)) {
862 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame);
863 return PTR_ERR(frame);
864 }
865
866 switch (s->target) {
867 case V4L2_SEL_TGT_CROP:
868 /* cropped frame */
869 s->r = frame->crop;
870 break;
871 case V4L2_SEL_TGT_CROP_DEFAULT:
872 case V4L2_SEL_TGT_CROP_BOUNDS:
873 /* complete frame */
874 s->r.left = 0;
875 s->r.top = 0;
876 s->r.width = frame->width;
877 s->r.height = frame->height;
878 break;
879 default:
880 dev_dbg(ctx->bdisp_dev->dev, "Invalid target\n");
881 return -EINVAL;
882 }
883
884 return 0;
885}
886
887static int is_rect_enclosed(struct v4l2_rect *a, struct v4l2_rect *b)
888{
889 /* Return 1 if a is enclosed in b, or 0 otherwise. */
890
891 if (a->left < b->left || a->top < b->top)
892 return 0;
893
894 if (a->left + a->width > b->left + b->width)
895 return 0;
896
897 if (a->top + a->height > b->top + b->height)
898 return 0;
899
900 return 1;
901}
902
903static int bdisp_s_selection(struct file *file, void *fh,
904 struct v4l2_selection *s)
905{
906 struct bdisp_frame *frame;
907 struct bdisp_ctx *ctx = fh_to_ctx(fh);
908 struct v4l2_rect *in, out;
909
910 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
911 /* Composing / capture is not supported */
912 dev_dbg(ctx->bdisp_dev->dev, "Not supported for capture\n");
913 return -EINVAL;
914 }
915
916 if (s->target != V4L2_SEL_TGT_CROP) {
917 dev_dbg(ctx->bdisp_dev->dev, "Invalid target\n");
918 return -EINVAL;
919 }
920
921 frame = ctx_get_frame(ctx, s->type);
922 if (IS_ERR(frame)) {
923 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame);
924 return PTR_ERR(frame);
925 }
926
927 in = &s->r;
928 out = *in;
929
930 /* Align and check origin */
931 out.left = ALIGN(in->left, frame->fmt->w_align);
932 out.top = ALIGN(in->top, frame->fmt->h_align);
933
934 if ((out.left < 0) || (out.left >= frame->width) ||
935 (out.top < 0) || (out.top >= frame->height)) {
936 dev_err(ctx->bdisp_dev->dev,
937 "Invalid crop: %dx%d@(%d,%d) vs frame: %dx%d\n",
938 out.width, out.height, out.left, out.top,
939 frame->width, frame->height);
940 return -EINVAL;
941 }
942
943 /* Align and check size */
944 out.width = ALIGN(in->width, frame->fmt->w_align);
945 out.height = ALIGN(in->height, frame->fmt->w_align);
946
947 if (((out.left + out.width) > frame->width) ||
948 ((out.top + out.height) > frame->height)) {
949 dev_err(ctx->bdisp_dev->dev,
950 "Invalid crop: %dx%d@(%d,%d) vs frame: %dx%d\n",
951 out.width, out.height, out.left, out.top,
952 frame->width, frame->height);
953 return -EINVAL;
954 }
955
956 /* Checks adjust constraints flags */
957 if (s->flags & V4L2_SEL_FLAG_LE && !is_rect_enclosed(&out, in))
958 return -ERANGE;
959
960 if (s->flags & V4L2_SEL_FLAG_GE && !is_rect_enclosed(in, &out))
961 return -ERANGE;
962
963 if ((out.left != in->left) || (out.top != in->top) ||
964 (out.width != in->width) || (out.height != in->height)) {
965 dev_dbg(ctx->bdisp_dev->dev,
966 "%s crop updated: %dx%d@(%d,%d) -> %dx%d@(%d,%d)\n",
967 __func__, in->width, in->height, in->left, in->top,
968 out.width, out.height, out.left, out.top);
969 *in = out;
970 }
971
972 frame->crop = out;
973
974 bdisp_ctx_state_lock_set(BDISP_PARAMS, ctx);
975
976 return 0;
977}
978
979static int bdisp_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
980{
981 struct bdisp_ctx *ctx = fh_to_ctx(fh);
982
983 if ((type == V4L2_BUF_TYPE_VIDEO_OUTPUT) &&
984 !bdisp_ctx_state_is_set(BDISP_SRC_FMT, ctx)) {
985 dev_err(ctx->bdisp_dev->dev, "src not defined\n");
986 return -EINVAL;
987 }
988
989 if ((type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
990 !bdisp_ctx_state_is_set(BDISP_DST_FMT, ctx)) {
991 dev_err(ctx->bdisp_dev->dev, "dst not defined\n");
992 return -EINVAL;
993 }
994
995 return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type);
996}
997
998static const struct v4l2_ioctl_ops bdisp_ioctl_ops = {
999 .vidioc_querycap = bdisp_querycap,
1000 .vidioc_enum_fmt_vid_cap = bdisp_enum_fmt,
1001 .vidioc_enum_fmt_vid_out = bdisp_enum_fmt,
1002 .vidioc_g_fmt_vid_cap = bdisp_g_fmt,
1003 .vidioc_g_fmt_vid_out = bdisp_g_fmt,
1004 .vidioc_try_fmt_vid_cap = bdisp_try_fmt,
1005 .vidioc_try_fmt_vid_out = bdisp_try_fmt,
1006 .vidioc_s_fmt_vid_cap = bdisp_s_fmt,
1007 .vidioc_s_fmt_vid_out = bdisp_s_fmt,
1008 .vidioc_g_selection = bdisp_g_selection,
1009 .vidioc_s_selection = bdisp_s_selection,
1010 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
1011 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
1012 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
1013 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
1014 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
1015 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
1016 .vidioc_streamon = bdisp_streamon,
1017 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
1018 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1019 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1020};
1021
1022static int bdisp_register_device(struct bdisp_dev *bdisp)
1023{
1024 int ret;
1025
1026 if (!bdisp)
1027 return -ENODEV;
1028
1029 bdisp->vdev.fops = &bdisp_fops;
1030 bdisp->vdev.ioctl_ops = &bdisp_ioctl_ops;
1031 bdisp->vdev.release = video_device_release_empty;
1032 bdisp->vdev.lock = &bdisp->lock;
1033 bdisp->vdev.vfl_dir = VFL_DIR_M2M;
1034 bdisp->vdev.v4l2_dev = &bdisp->v4l2_dev;
1035 snprintf(bdisp->vdev.name, sizeof(bdisp->vdev.name), "%s.%d",
1036 BDISP_NAME, bdisp->id);
1037
1038 video_set_drvdata(&bdisp->vdev, bdisp);
1039
1040 bdisp->m2m.vdev = &bdisp->vdev;
1041 bdisp->m2m.m2m_dev = v4l2_m2m_init(&bdisp_m2m_ops);
1042 if (IS_ERR(bdisp->m2m.m2m_dev)) {
1043 dev_err(bdisp->dev, "failed to initialize v4l2-m2m device\n");
1044 return PTR_ERR(bdisp->m2m.m2m_dev);
1045 }
1046
1047 ret = video_register_device(&bdisp->vdev, VFL_TYPE_GRABBER, -1);
1048 if (ret) {
1049 dev_err(bdisp->dev,
1050 "%s(): failed to register video device\n", __func__);
1051 v4l2_m2m_release(bdisp->m2m.m2m_dev);
1052 return ret;
1053 }
1054
1055 return 0;
1056}
1057
1058static void bdisp_unregister_device(struct bdisp_dev *bdisp)
1059{
1060 if (!bdisp)
1061 return;
1062
1063 if (bdisp->m2m.m2m_dev)
1064 v4l2_m2m_release(bdisp->m2m.m2m_dev);
1065
1066 video_unregister_device(bdisp->m2m.vdev);
1067}
1068
1069static irqreturn_t bdisp_irq_thread(int irq, void *priv)
1070{
1071 struct bdisp_dev *bdisp = priv;
1072 struct bdisp_ctx *ctx;
1073
1074 spin_lock(&bdisp->slock);
1075
1076 bdisp_dbg_perf_end(bdisp);
1077
1078 cancel_delayed_work(&bdisp->timeout_work);
1079
1080 if (!test_and_clear_bit(ST_M2M_RUNNING, &bdisp->state))
1081 goto isr_unlock;
1082
1083 if (test_and_clear_bit(ST_M2M_SUSPENDING, &bdisp->state)) {
1084 set_bit(ST_M2M_SUSPENDED, &bdisp->state);
1085 wake_up(&bdisp->irq_queue);
1086 goto isr_unlock;
1087 }
1088
1089 ctx = v4l2_m2m_get_curr_priv(bdisp->m2m.m2m_dev);
1090 if (!ctx || !ctx->fh.m2m_ctx)
1091 goto isr_unlock;
1092
1093 spin_unlock(&bdisp->slock);
1094
1095 bdisp_job_finish(ctx, VB2_BUF_STATE_DONE);
1096
1097 if (bdisp_ctx_state_is_set(BDISP_CTX_STOP_REQ, ctx)) {
1098 bdisp_ctx_state_lock_clear(BDISP_CTX_STOP_REQ, ctx);
1099 wake_up(&bdisp->irq_queue);
1100 }
1101
1102 return IRQ_HANDLED;
1103
1104isr_unlock:
1105 spin_unlock(&bdisp->slock);
1106
1107 return IRQ_HANDLED;
1108}
1109
1110static irqreturn_t bdisp_irq_handler(int irq, void *priv)
1111{
1112 if (bdisp_hw_get_and_clear_irq((struct bdisp_dev *)priv))
1113 return IRQ_NONE;
1114 else
1115 return IRQ_WAKE_THREAD;
1116}
1117
1118static void bdisp_irq_timeout(struct work_struct *ptr)
1119{
1120 struct delayed_work *twork = to_delayed_work(ptr);
1121 struct bdisp_dev *bdisp = container_of(twork, struct bdisp_dev,
1122 timeout_work);
1123 struct bdisp_ctx *ctx;
1124
1125 ctx = v4l2_m2m_get_curr_priv(bdisp->m2m.m2m_dev);
1126
1127 dev_err(ctx->bdisp_dev->dev, "Device work timeout\n");
1128
1129 spin_lock(&bdisp->slock);
1130 clear_bit(ST_M2M_RUNNING, &bdisp->state);
1131 spin_unlock(&bdisp->slock);
1132
1133 bdisp_hw_reset(bdisp);
1134
1135 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR);
1136}
1137
1138static int bdisp_m2m_suspend(struct bdisp_dev *bdisp)
1139{
1140 unsigned long flags;
1141 int timeout;
1142
1143 spin_lock_irqsave(&bdisp->slock, flags);
1144 if (!test_bit(ST_M2M_RUNNING, &bdisp->state)) {
1145 spin_unlock_irqrestore(&bdisp->slock, flags);
1146 return 0;
1147 }
1148 clear_bit(ST_M2M_SUSPENDED, &bdisp->state);
1149 set_bit(ST_M2M_SUSPENDING, &bdisp->state);
1150 spin_unlock_irqrestore(&bdisp->slock, flags);
1151
1152 timeout = wait_event_timeout(bdisp->irq_queue,
1153 test_bit(ST_M2M_SUSPENDED, &bdisp->state),
1154 BDISP_WORK_TIMEOUT);
1155
1156 clear_bit(ST_M2M_SUSPENDING, &bdisp->state);
1157
1158 if (!timeout) {
1159 dev_err(bdisp->dev, "%s IRQ timeout\n", __func__);
1160 return -EAGAIN;
1161 }
1162
1163 return 0;
1164}
1165
1166static int bdisp_m2m_resume(struct bdisp_dev *bdisp)
1167{
1168 struct bdisp_ctx *ctx;
1169 unsigned long flags;
1170
1171 spin_lock_irqsave(&bdisp->slock, flags);
1172 ctx = bdisp->m2m.ctx;
1173 bdisp->m2m.ctx = NULL;
1174 spin_unlock_irqrestore(&bdisp->slock, flags);
1175
1176 if (test_and_clear_bit(ST_M2M_SUSPENDED, &bdisp->state))
1177 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR);
1178
1179 return 0;
1180}
1181
1182static int bdisp_runtime_resume(struct device *dev)
1183{
1184 struct bdisp_dev *bdisp = dev_get_drvdata(dev);
1185 int ret = clk_enable(bdisp->clock);
1186
1187 if (ret)
1188 return ret;
1189
1190 return bdisp_m2m_resume(bdisp);
1191}
1192
1193static int bdisp_runtime_suspend(struct device *dev)
1194{
1195 struct bdisp_dev *bdisp = dev_get_drvdata(dev);
1196 int ret = bdisp_m2m_suspend(bdisp);
1197
1198 if (!ret)
1199 clk_disable(bdisp->clock);
1200
1201 return ret;
1202}
1203
1204static int bdisp_resume(struct device *dev)
1205{
1206 struct bdisp_dev *bdisp = dev_get_drvdata(dev);
1207 unsigned long flags;
1208 int opened;
1209
1210 spin_lock_irqsave(&bdisp->slock, flags);
1211 opened = test_bit(ST_M2M_OPEN, &bdisp->state);
1212 spin_unlock_irqrestore(&bdisp->slock, flags);
1213
1214 if (!opened)
1215 return 0;
1216
1217 if (!pm_runtime_suspended(dev))
1218 return bdisp_runtime_resume(dev);
1219
1220 return 0;
1221}
1222
1223static int bdisp_suspend(struct device *dev)
1224{
1225 if (!pm_runtime_suspended(dev))
1226 return bdisp_runtime_suspend(dev);
1227
1228 return 0;
1229}
1230
1231static const struct dev_pm_ops bdisp_pm_ops = {
1232 .suspend = bdisp_suspend,
1233 .resume = bdisp_resume,
1234 .runtime_suspend = bdisp_runtime_suspend,
1235 .runtime_resume = bdisp_runtime_resume,
1236};
1237
1238static int bdisp_remove(struct platform_device *pdev)
1239{
1240 struct bdisp_dev *bdisp = platform_get_drvdata(pdev);
1241
1242 bdisp_unregister_device(bdisp);
1243
1244 bdisp_hw_free_filters(bdisp->dev);
1245
1246 vb2_dma_contig_cleanup_ctx(bdisp->alloc_ctx);
1247
1248 pm_runtime_disable(&pdev->dev);
1249
1250 bdisp_debugfs_remove(bdisp);
1251
1252 v4l2_device_unregister(&bdisp->v4l2_dev);
1253
1254 if (!IS_ERR(bdisp->clock))
1255 clk_unprepare(bdisp->clock);
1256
1257 dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
1258
1259 return 0;
1260}
1261
1262static int bdisp_probe(struct platform_device *pdev)
1263{
1264 struct bdisp_dev *bdisp;
1265 struct resource *res;
1266 struct device *dev = &pdev->dev;
1267 int ret;
1268
1269 dev_dbg(dev, "%s\n", __func__);
1270
1271 bdisp = devm_kzalloc(dev, sizeof(struct bdisp_dev), GFP_KERNEL);
1272 if (!bdisp)
1273 return -ENOMEM;
1274
1275 bdisp->pdev = pdev;
1276 bdisp->dev = dev;
1277 platform_set_drvdata(pdev, bdisp);
1278
1279 if (dev->of_node)
1280 bdisp->id = of_alias_get_id(pdev->dev.of_node, BDISP_NAME);
1281 else
1282 bdisp->id = pdev->id;
1283
1284 init_waitqueue_head(&bdisp->irq_queue);
1285 INIT_DELAYED_WORK(&bdisp->timeout_work, bdisp_irq_timeout);
1286 bdisp->work_queue = create_workqueue(BDISP_NAME);
1287
1288 spin_lock_init(&bdisp->slock);
1289 mutex_init(&bdisp->lock);
1290
1291 /* get resources */
1292 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1293 bdisp->regs = devm_ioremap_resource(dev, res);
1294 if (IS_ERR(bdisp->regs)) {
1295 dev_err(dev, "failed to get regs\n");
1296 return PTR_ERR(bdisp->regs);
1297 }
1298
1299 bdisp->clock = devm_clk_get(dev, BDISP_NAME);
1300 if (IS_ERR(bdisp->clock)) {
1301 dev_err(dev, "failed to get clock\n");
1302 return PTR_ERR(bdisp->clock);
1303 }
1304
1305 ret = clk_prepare(bdisp->clock);
1306 if (ret < 0) {
1307 dev_err(dev, "clock prepare failed\n");
1308 bdisp->clock = ERR_PTR(-EINVAL);
1309 return ret;
1310 }
1311
1312 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1313 if (!res) {
1314 dev_err(dev, "failed to get IRQ resource\n");
1315 goto err_clk;
1316 }
1317
1318 ret = devm_request_threaded_irq(dev, res->start, bdisp_irq_handler,
1319 bdisp_irq_thread, IRQF_ONESHOT,
1320 pdev->name, bdisp);
1321 if (ret) {
1322 dev_err(dev, "failed to install irq\n");
1323 goto err_clk;
1324 }
1325
1326 /* v4l2 register */
1327 ret = v4l2_device_register(dev, &bdisp->v4l2_dev);
1328 if (ret) {
1329 dev_err(dev, "failed to register\n");
1330 goto err_clk;
1331 }
1332
1333 /* Debug */
1334 ret = bdisp_debugfs_create(bdisp);
1335 if (ret) {
1336 dev_err(dev, "failed to create debugfs\n");
1337 goto err_v4l2;
1338 }
1339
1340 /* Power management */
1341 pm_runtime_enable(dev);
1342 ret = pm_runtime_get_sync(dev);
1343 if (ret < 0) {
1344 dev_err(dev, "failed to set PM\n");
1345 goto err_dbg;
1346 }
1347
1348 /* Continuous memory allocator */
1349 bdisp->alloc_ctx = vb2_dma_contig_init_ctx(dev);
1350 if (IS_ERR(bdisp->alloc_ctx)) {
1351 ret = PTR_ERR(bdisp->alloc_ctx);
1352 goto err_pm;
1353 }
1354
1355 /* Filters */
1356 if (bdisp_hw_alloc_filters(bdisp->dev)) {
1357 dev_err(bdisp->dev, "no memory for filters\n");
1358 ret = -ENOMEM;
1359 goto err_vb2_dma;
1360 }
1361
1362 /* Register */
1363 ret = bdisp_register_device(bdisp);
1364 if (ret) {
1365 dev_err(dev, "failed to register\n");
1366 goto err_filter;
1367 }
1368
1369 dev_info(dev, "%s%d registered as /dev/video%d\n", BDISP_NAME,
1370 bdisp->id, bdisp->vdev.num);
1371
1372 pm_runtime_put(dev);
1373
1374 return 0;
1375
1376err_filter:
1377 bdisp_hw_free_filters(bdisp->dev);
1378err_vb2_dma:
1379 vb2_dma_contig_cleanup_ctx(bdisp->alloc_ctx);
1380err_pm:
1381 pm_runtime_put(dev);
1382err_dbg:
1383 bdisp_debugfs_remove(bdisp);
1384err_v4l2:
1385 v4l2_device_unregister(&bdisp->v4l2_dev);
1386err_clk:
1387 if (!IS_ERR(bdisp->clock))
1388 clk_unprepare(bdisp->clock);
1389
1390 return ret;
1391}
1392
1393static const struct of_device_id bdisp_match_types[] = {
1394 {
1395 .compatible = "st,stih407-bdisp",
1396 },
1397 { /* end node */ }
1398};
1399
1400MODULE_DEVICE_TABLE(of, bdisp_match_types);
1401
1402static struct platform_driver bdisp_driver = {
1403 .probe = bdisp_probe,
1404 .remove = bdisp_remove,
1405 .driver = {
1406 .name = BDISP_NAME,
1407 .of_match_table = bdisp_match_types,
1408 .pm = &bdisp_pm_ops,
1409 },
1410};
1411
1412module_platform_driver(bdisp_driver);
1413
1414MODULE_DESCRIPTION("2D blitter for STMicroelectronics SoC");
1415MODULE_AUTHOR("Fabien Dessenne <fabien.dessenne@st.com>");
1416MODULE_LICENSE("GPL");
diff --git a/drivers/media/platform/sti/bdisp/bdisp.h b/drivers/media/platform/sti/bdisp/bdisp.h
new file mode 100644
index 000000000000..0cf98577222c
--- /dev/null
+++ b/drivers/media/platform/sti/bdisp/bdisp.h
@@ -0,0 +1,216 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
6
7#include <linux/clk.h>
8#include <linux/ktime.h>
9#include <linux/platform_device.h>
10#include <linux/spinlock.h>
11
12#include <media/v4l2-ctrls.h>
13#include <media/v4l2-device.h>
14#include <media/v4l2-mem2mem.h>
15
16#include <media/videobuf2-dma-contig.h>
17
18#define BDISP_NAME "bdisp"
19
20/*
21 * Max nb of nodes in node-list:
22 * - 2 nodes to handle wide 4K pictures
23 * - 2 nodes to handle two planes (Y & CbCr) */
24#define MAX_OUTPUT_PLANES 2
25#define MAX_VERTICAL_STRIDES 2
26#define MAX_NB_NODE (MAX_OUTPUT_PLANES * MAX_VERTICAL_STRIDES)
27
28/* struct bdisp_ctrls - bdisp control set
29 * @hflip: horizontal flip
30 * @vflip: vertical flip
31 */
32struct bdisp_ctrls {
33 struct v4l2_ctrl *hflip;
34 struct v4l2_ctrl *vflip;
35};
36
37/**
38 * struct bdisp_fmt - driver's internal color format data
39 * @pixelformat:fourcc code for this format
40 * @nb_planes: number of planes (ex: [0]=RGB/Y - [1]=Cb/Cr, ...)
41 * @bpp: bits per pixel (general)
42 * @bpp_plane0: byte per pixel for the 1st plane
43 * @w_align: width alignment in pixel (multiple of)
44 * @h_align: height alignment in pixel (multiple of)
45 */
46struct bdisp_fmt {
47 u32 pixelformat;
48 u8 nb_planes;
49 u8 bpp;
50 u8 bpp_plane0;
51 u8 w_align;
52 u8 h_align;
53};
54
55/**
56 * struct bdisp_frame - frame properties
57 *
58 * @width: frame width (including padding)
59 * @height: frame height (including padding)
60 * @fmt: pointer to frame format descriptor
61 * @field: frame / field type
62 * @bytesperline: stride of the 1st plane
63 * @sizeimage: image size in bytes
64 * @colorspace: colorspace
65 * @crop: crop area
66 * @paddr: image physical addresses per plane ([0]=RGB/Y - [1]=Cb/Cr, ...)
67 */
68struct bdisp_frame {
69 u32 width;
70 u32 height;
71 const struct bdisp_fmt *fmt;
72 enum v4l2_field field;
73 u32 bytesperline;
74 u32 sizeimage;
75 enum v4l2_colorspace colorspace;
76 struct v4l2_rect crop;
77 dma_addr_t paddr[4];
78};
79
80/**
81 * struct bdisp_request - bdisp request
82 *
83 * @src: source frame properties
84 * @dst: destination frame properties
85 * @hflip: horizontal flip
86 * @vflip: vertical flip
87 * @nb_req: number of run request
88 */
89struct bdisp_request {
90 struct bdisp_frame src;
91 struct bdisp_frame dst;
92 unsigned int hflip:1;
93 unsigned int vflip:1;
94 int nb_req;
95};
96
97/**
98 * struct bdisp_ctx - device context data
99 *
100 * @src: source frame properties
101 * @dst: destination frame properties
102 * @state: flags to keep track of user configuration
103 * @hflip: horizontal flip
104 * @vflip: vertical flip
105 * @bdisp_dev: the device this context applies to
106 * @node: node array
107 * @node_paddr: node physical address array
108 * @fh: v4l2 file handle
109 * @ctrl_handler: v4l2 controls handler
110 * @bdisp_ctrls: bdisp control set
111 * @ctrls_rdy: true if the control handler is initialized
112 */
113struct bdisp_ctx {
114 struct bdisp_frame src;
115 struct bdisp_frame dst;
116 u32 state;
117 unsigned int hflip:1;
118 unsigned int vflip:1;
119 struct bdisp_dev *bdisp_dev;
120 struct bdisp_node *node[MAX_NB_NODE];
121 dma_addr_t node_paddr[MAX_NB_NODE];
122 struct v4l2_fh fh;
123 struct v4l2_ctrl_handler ctrl_handler;
124 struct bdisp_ctrls bdisp_ctrls;
125 bool ctrls_rdy;
126};
127
128/**
129 * struct bdisp_m2m_device - v4l2 memory-to-memory device data
130 *
131 * @vdev: video device node for v4l2 m2m mode
132 * @m2m_dev: v4l2 m2m device data
133 * @ctx: hardware context data
134 * @refcnt: reference counter
135 */
136struct bdisp_m2m_device {
137 struct video_device *vdev;
138 struct v4l2_m2m_dev *m2m_dev;
139 struct bdisp_ctx *ctx;
140 int refcnt;
141};
142
143/**
144 * struct bdisp_dbg - debug info
145 *
146 * @debugfs_entry: debugfs
147 * @copy_node: array of last used nodes
148 * @copy_request: last bdisp request
149 * @hw_start: start time of last HW request
150 * @last_duration: last HW processing duration in microsecs
151 * @min_duration: min HW processing duration in microsecs
152 * @max_duration: max HW processing duration in microsecs
153 * @tot_duration: total HW processing duration in microsecs
154 */
155struct bdisp_dbg {
156 struct dentry *debugfs_entry;
157 struct bdisp_node *copy_node[MAX_NB_NODE];
158 struct bdisp_request copy_request;
159 ktime_t hw_start;
160 s64 last_duration;
161 s64 min_duration;
162 s64 max_duration;
163 s64 tot_duration;
164};
165
166/**
167 * struct bdisp_dev - abstraction for bdisp entity
168 *
169 * @v4l2_dev: v4l2 device
170 * @vdev: video device
171 * @pdev: platform device
172 * @dev: device
173 * @lock: mutex protecting this data structure
174 * @slock: spinlock protecting this data structure
175 * @id: device index
176 * @m2m: memory-to-memory V4L2 device information
177 * @state: flags used to synchronize m2m and capture mode operation
178 * @alloc_ctx: videobuf2 memory allocator context
179 * @clock: IP clock
180 * @regs: registers
181 * @irq_queue: interrupt handler waitqueue
182 * @work_queue: workqueue to handle timeouts
183 * @timeout_work: IRQ timeout structure
184 * @dbg: debug info
185 */
186struct bdisp_dev {
187 struct v4l2_device v4l2_dev;
188 struct video_device vdev;
189 struct platform_device *pdev;
190 struct device *dev;
191 spinlock_t slock;
192 struct mutex lock;
193 u16 id;
194 struct bdisp_m2m_device m2m;
195 unsigned long state;
196 struct vb2_alloc_ctx *alloc_ctx;
197 struct clk *clock;
198 void __iomem *regs;
199 wait_queue_head_t irq_queue;
200 struct workqueue_struct *work_queue;
201 struct delayed_work timeout_work;
202 struct bdisp_dbg dbg;
203};
204
205void bdisp_hw_free_nodes(struct bdisp_ctx *ctx);
206int bdisp_hw_alloc_nodes(struct bdisp_ctx *ctx);
207void bdisp_hw_free_filters(struct device *dev);
208int bdisp_hw_alloc_filters(struct device *dev);
209int bdisp_hw_reset(struct bdisp_dev *bdisp);
210int bdisp_hw_get_and_clear_irq(struct bdisp_dev *bdisp);
211int bdisp_hw_update(struct bdisp_ctx *ctx);
212
213void bdisp_debugfs_remove(struct bdisp_dev *bdisp);
214int bdisp_debugfs_create(struct bdisp_dev *bdisp);
215void bdisp_dbg_perf_begin(struct bdisp_dev *bdisp);
216void bdisp_dbg_perf_end(struct bdisp_dev *bdisp);
diff --git a/drivers/media/platform/via-camera.c b/drivers/media/platform/via-camera.c
index 678ed9f353cb..32e4ff46daf3 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -249,13 +249,15 @@ static int viacam_set_flip(struct via_camera *cam)
249 */ 249 */
250static int viacam_configure_sensor(struct via_camera *cam) 250static int viacam_configure_sensor(struct via_camera *cam)
251{ 251{
252 struct v4l2_mbus_framefmt mbus_fmt; 252 struct v4l2_subdev_format format = {
253 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
254 };
253 int ret; 255 int ret;
254 256
255 v4l2_fill_mbus_format(&mbus_fmt, &cam->sensor_format, cam->mbus_code); 257 v4l2_fill_mbus_format(&format.format, &cam->sensor_format, cam->mbus_code);
256 ret = sensor_call(cam, core, init, 0); 258 ret = sensor_call(cam, core, init, 0);
257 if (ret == 0) 259 if (ret == 0)
258 ret = sensor_call(cam, video, s_mbus_fmt, &mbus_fmt); 260 ret = sensor_call(cam, pad, set_fmt, NULL, &format);
259 /* 261 /*
260 * OV7670 does weird things if flip is set *before* format... 262 * OV7670 does weird things if flip is set *before* format...
261 */ 263 */
@@ -903,14 +905,17 @@ static int viacam_do_try_fmt(struct via_camera *cam,
903 struct v4l2_pix_format *upix, struct v4l2_pix_format *spix) 905 struct v4l2_pix_format *upix, struct v4l2_pix_format *spix)
904{ 906{
905 int ret; 907 int ret;
906 struct v4l2_mbus_framefmt mbus_fmt; 908 struct v4l2_subdev_pad_config pad_cfg;
909 struct v4l2_subdev_format format = {
910 .which = V4L2_SUBDEV_FORMAT_TRY,
911 };
907 struct via_format *f = via_find_format(upix->pixelformat); 912 struct via_format *f = via_find_format(upix->pixelformat);
908 913
909 upix->pixelformat = f->pixelformat; 914 upix->pixelformat = f->pixelformat;
910 viacam_fmt_pre(upix, spix); 915 viacam_fmt_pre(upix, spix);
911 v4l2_fill_mbus_format(&mbus_fmt, spix, f->mbus_code); 916 v4l2_fill_mbus_format(&format.format, spix, f->mbus_code);
912 ret = sensor_call(cam, video, try_mbus_fmt, &mbus_fmt); 917 ret = sensor_call(cam, pad, set_fmt, &pad_cfg, &format);
913 v4l2_fill_pix_format(spix, &mbus_fmt); 918 v4l2_fill_pix_format(spix, &format.format);
914 viacam_fmt_post(upix, spix); 919 viacam_fmt_post(upix, spix);
915 return ret; 920 return ret;
916} 921}
diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index 4d6b4cc57c57..295fde5fdb75 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -80,7 +80,6 @@ static struct platform_device vim2m_pdev = {
80}; 80};
81 81
82struct vim2m_fmt { 82struct vim2m_fmt {
83 char *name;
84 u32 fourcc; 83 u32 fourcc;
85 int depth; 84 int depth;
86 /* Types the format can be used for */ 85 /* Types the format can be used for */
@@ -89,14 +88,12 @@ struct vim2m_fmt {
89 88
90static struct vim2m_fmt formats[] = { 89static struct vim2m_fmt formats[] = {
91 { 90 {
92 .name = "RGB565 (BE)",
93 .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */ 91 .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
94 .depth = 16, 92 .depth = 16,
95 /* Both capture and output format */ 93 /* Both capture and output format */
96 .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, 94 .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
97 }, 95 },
98 { 96 {
99 .name = "4:2:2, packed, YUYV",
100 .fourcc = V4L2_PIX_FMT_YUYV, 97 .fourcc = V4L2_PIX_FMT_YUYV,
101 .depth = 16, 98 .depth = 16,
102 /* Output-only format */ 99 /* Output-only format */
@@ -458,7 +455,6 @@ static int enum_fmt(struct v4l2_fmtdesc *f, u32 type)
458 if (i < NUM_FORMATS) { 455 if (i < NUM_FORMATS) {
459 /* Format found */ 456 /* Format found */
460 fmt = &formats[i]; 457 fmt = &formats[i];
461 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
462 f->pixelformat = fmt->fourcc; 458 f->pixelformat = fmt->fourcc;
463 return 0; 459 return 0;
464 } 460 }
@@ -697,6 +693,8 @@ static const struct v4l2_ioctl_ops vim2m_ioctl_ops = {
697 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 693 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
698 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 694 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
699 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 695 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
696 .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf,
697 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
700 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, 698 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
701 699
702 .vidioc_streamon = v4l2_m2m_ioctl_streamon, 700 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
@@ -724,6 +722,12 @@ static int vim2m_queue_setup(struct vb2_queue *vq,
724 722
725 size = q_data->width * q_data->height * q_data->fmt->depth >> 3; 723 size = q_data->width * q_data->height * q_data->fmt->depth >> 3;
726 724
725 if (fmt) {
726 if (fmt->fmt.pix.sizeimage < size)
727 return -EINVAL;
728 size = fmt->fmt.pix.sizeimage;
729 }
730
727 while (size * count > MEM2MEM_VID_MEM_LIMIT) 731 while (size * count > MEM2MEM_VID_MEM_LIMIT)
728 (count)--; 732 (count)--;
729 733
diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c
index d33f16495dbc..a047b4716741 100644
--- a/drivers/media/platform/vivid/vivid-core.c
+++ b/drivers/media/platform/vivid/vivid-core.c
@@ -392,6 +392,17 @@ static int vidioc_s_parm(struct file *file, void *fh,
392 return vivid_vid_out_g_parm(file, fh, parm); 392 return vivid_vid_out_g_parm(file, fh, parm);
393} 393}
394 394
395static int vidioc_log_status(struct file *file, void *fh)
396{
397 struct vivid_dev *dev = video_drvdata(file);
398 struct video_device *vdev = video_devdata(file);
399
400 v4l2_ctrl_log_status(file, fh);
401 if (vdev->vfl_dir == VFL_DIR_RX && vdev->vfl_type == VFL_TYPE_GRABBER)
402 tpg_log_status(&dev->tpg);
403 return 0;
404}
405
395static ssize_t vivid_radio_read(struct file *file, char __user *buf, 406static ssize_t vivid_radio_read(struct file *file, char __user *buf,
396 size_t size, loff_t *offset) 407 size_t size, loff_t *offset)
397{ 408{
@@ -548,8 +559,8 @@ static const struct v4l2_ioctl_ops vivid_ioctl_ops = {
548 559
549 .vidioc_enum_fmt_sdr_cap = vidioc_enum_fmt_sdr_cap, 560 .vidioc_enum_fmt_sdr_cap = vidioc_enum_fmt_sdr_cap,
550 .vidioc_g_fmt_sdr_cap = vidioc_g_fmt_sdr_cap, 561 .vidioc_g_fmt_sdr_cap = vidioc_g_fmt_sdr_cap,
551 .vidioc_try_fmt_sdr_cap = vidioc_g_fmt_sdr_cap, 562 .vidioc_try_fmt_sdr_cap = vidioc_try_fmt_sdr_cap,
552 .vidioc_s_fmt_sdr_cap = vidioc_g_fmt_sdr_cap, 563 .vidioc_s_fmt_sdr_cap = vidioc_s_fmt_sdr_cap,
553 564
554 .vidioc_overlay = vidioc_overlay, 565 .vidioc_overlay = vidioc_overlay,
555 .vidioc_enum_framesizes = vidioc_enum_framesizes, 566 .vidioc_enum_framesizes = vidioc_enum_framesizes,
@@ -610,7 +621,7 @@ static const struct v4l2_ioctl_ops vivid_ioctl_ops = {
610 .vidioc_g_edid = vidioc_g_edid, 621 .vidioc_g_edid = vidioc_g_edid,
611 .vidioc_s_edid = vidioc_s_edid, 622 .vidioc_s_edid = vidioc_s_edid,
612 623
613 .vidioc_log_status = v4l2_ctrl_log_status, 624 .vidioc_log_status = vidioc_log_status,
614 .vidioc_subscribe_event = vidioc_subscribe_event, 625 .vidioc_subscribe_event = vidioc_subscribe_event,
615 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 626 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
616}; 627};
@@ -966,6 +977,9 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
966 dev->radio_tx_subchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_RDS; 977 dev->radio_tx_subchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_RDS;
967 dev->sdr_adc_freq = 300000; 978 dev->sdr_adc_freq = 300000;
968 dev->sdr_fm_freq = 50000000; 979 dev->sdr_fm_freq = 50000000;
980 dev->sdr_pixelformat = V4L2_SDR_FMT_CU8;
981 dev->sdr_buffersize = SDR_CAP_SAMPLES_PER_BUF * 2;
982
969 dev->edid_max_blocks = dev->edid_blocks = 2; 983 dev->edid_max_blocks = dev->edid_blocks = 2;
970 memcpy(dev->edid, vivid_hdmi_edid, sizeof(vivid_hdmi_edid)); 984 memcpy(dev->edid, vivid_hdmi_edid, sizeof(vivid_hdmi_edid));
971 ktime_get_ts(&dev->radio_rds_init_ts); 985 ktime_get_ts(&dev->radio_rds_init_ts);
diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h
index 9e15aee9a52e..c72349c83fab 100644
--- a/drivers/media/platform/vivid/vivid-core.h
+++ b/drivers/media/platform/vivid/vivid-core.h
@@ -77,7 +77,6 @@ extern const struct v4l2_rect vivid_max_rect;
77extern unsigned vivid_debug; 77extern unsigned vivid_debug;
78 78
79struct vivid_fmt { 79struct vivid_fmt {
80 const char *name;
81 u32 fourcc; /* v4l2 format id */ 80 u32 fourcc; /* v4l2 format id */
82 bool is_yuv; 81 bool is_yuv;
83 bool can_do_overlay; 82 bool can_do_overlay;
@@ -140,7 +139,7 @@ struct vivid_dev {
140 struct v4l2_ctrl_handler ctrl_hdl_user_aud; 139 struct v4l2_ctrl_handler ctrl_hdl_user_aud;
141 struct v4l2_ctrl_handler ctrl_hdl_streaming; 140 struct v4l2_ctrl_handler ctrl_hdl_streaming;
142 struct v4l2_ctrl_handler ctrl_hdl_sdtv_cap; 141 struct v4l2_ctrl_handler ctrl_hdl_sdtv_cap;
143 struct v4l2_ctrl_handler ctrl_hdl_loop_out; 142 struct v4l2_ctrl_handler ctrl_hdl_loop_cap;
144 struct video_device vid_cap_dev; 143 struct video_device vid_cap_dev;
145 struct v4l2_ctrl_handler ctrl_hdl_vid_cap; 144 struct v4l2_ctrl_handler ctrl_hdl_vid_cap;
146 struct video_device vid_out_dev; 145 struct video_device vid_out_dev;
@@ -333,6 +332,7 @@ struct vivid_dev {
333 u32 colorspace_out; 332 u32 colorspace_out;
334 u32 ycbcr_enc_out; 333 u32 ycbcr_enc_out;
335 u32 quantization_out; 334 u32 quantization_out;
335 u32 xfer_func_out;
336 u32 service_set_out; 336 u32 service_set_out;
337 unsigned bytesperline_out[TPG_MAX_PLANES]; 337 unsigned bytesperline_out[TPG_MAX_PLANES];
338 unsigned tv_field_out; 338 unsigned tv_field_out;
@@ -447,6 +447,8 @@ struct vivid_dev {
447 /* SDR capture */ 447 /* SDR capture */
448 struct vb2_queue vb_sdr_cap_q; 448 struct vb2_queue vb_sdr_cap_q;
449 struct list_head sdr_cap_active; 449 struct list_head sdr_cap_active;
450 u32 sdr_pixelformat; /* v4l2 format id */
451 unsigned sdr_buffersize;
450 unsigned sdr_adc_freq; 452 unsigned sdr_adc_freq;
451 unsigned sdr_fm_freq; 453 unsigned sdr_fm_freq;
452 int sdr_fixp_src_phase; 454 int sdr_fixp_src_phase;
diff --git a/drivers/media/platform/vivid/vivid-ctrls.c b/drivers/media/platform/vivid/vivid-ctrls.c
index 2b9070098b08..339c8b7e53c8 100644
--- a/drivers/media/platform/vivid/vivid-ctrls.c
+++ b/drivers/media/platform/vivid/vivid-ctrls.c
@@ -62,21 +62,22 @@
62#define VIVID_CID_DV_TIMINGS_ASPECT_RATIO (VIVID_CID_VIVID_BASE + 23) 62#define VIVID_CID_DV_TIMINGS_ASPECT_RATIO (VIVID_CID_VIVID_BASE + 23)
63#define VIVID_CID_TSTAMP_SRC (VIVID_CID_VIVID_BASE + 24) 63#define VIVID_CID_TSTAMP_SRC (VIVID_CID_VIVID_BASE + 24)
64#define VIVID_CID_COLORSPACE (VIVID_CID_VIVID_BASE + 25) 64#define VIVID_CID_COLORSPACE (VIVID_CID_VIVID_BASE + 25)
65#define VIVID_CID_YCBCR_ENC (VIVID_CID_VIVID_BASE + 26) 65#define VIVID_CID_XFER_FUNC (VIVID_CID_VIVID_BASE + 26)
66#define VIVID_CID_QUANTIZATION (VIVID_CID_VIVID_BASE + 27) 66#define VIVID_CID_YCBCR_ENC (VIVID_CID_VIVID_BASE + 27)
67#define VIVID_CID_LIMITED_RGB_RANGE (VIVID_CID_VIVID_BASE + 28) 67#define VIVID_CID_QUANTIZATION (VIVID_CID_VIVID_BASE + 28)
68#define VIVID_CID_ALPHA_MODE (VIVID_CID_VIVID_BASE + 29) 68#define VIVID_CID_LIMITED_RGB_RANGE (VIVID_CID_VIVID_BASE + 29)
69#define VIVID_CID_HAS_CROP_CAP (VIVID_CID_VIVID_BASE + 30) 69#define VIVID_CID_ALPHA_MODE (VIVID_CID_VIVID_BASE + 30)
70#define VIVID_CID_HAS_COMPOSE_CAP (VIVID_CID_VIVID_BASE + 31) 70#define VIVID_CID_HAS_CROP_CAP (VIVID_CID_VIVID_BASE + 31)
71#define VIVID_CID_HAS_SCALER_CAP (VIVID_CID_VIVID_BASE + 32) 71#define VIVID_CID_HAS_COMPOSE_CAP (VIVID_CID_VIVID_BASE + 32)
72#define VIVID_CID_HAS_CROP_OUT (VIVID_CID_VIVID_BASE + 33) 72#define VIVID_CID_HAS_SCALER_CAP (VIVID_CID_VIVID_BASE + 33)
73#define VIVID_CID_HAS_COMPOSE_OUT (VIVID_CID_VIVID_BASE + 34) 73#define VIVID_CID_HAS_CROP_OUT (VIVID_CID_VIVID_BASE + 34)
74#define VIVID_CID_HAS_SCALER_OUT (VIVID_CID_VIVID_BASE + 35) 74#define VIVID_CID_HAS_COMPOSE_OUT (VIVID_CID_VIVID_BASE + 35)
75#define VIVID_CID_LOOP_VIDEO (VIVID_CID_VIVID_BASE + 36) 75#define VIVID_CID_HAS_SCALER_OUT (VIVID_CID_VIVID_BASE + 36)
76#define VIVID_CID_SEQ_WRAP (VIVID_CID_VIVID_BASE + 37) 76#define VIVID_CID_LOOP_VIDEO (VIVID_CID_VIVID_BASE + 37)
77#define VIVID_CID_TIME_WRAP (VIVID_CID_VIVID_BASE + 38) 77#define VIVID_CID_SEQ_WRAP (VIVID_CID_VIVID_BASE + 38)
78#define VIVID_CID_MAX_EDID_BLOCKS (VIVID_CID_VIVID_BASE + 39) 78#define VIVID_CID_TIME_WRAP (VIVID_CID_VIVID_BASE + 39)
79#define VIVID_CID_PERCENTAGE_FILL (VIVID_CID_VIVID_BASE + 40) 79#define VIVID_CID_MAX_EDID_BLOCKS (VIVID_CID_VIVID_BASE + 40)
80#define VIVID_CID_PERCENTAGE_FILL (VIVID_CID_VIVID_BASE + 41)
80 81
81#define VIVID_CID_STD_SIGNAL_MODE (VIVID_CID_VIVID_BASE + 60) 82#define VIVID_CID_STD_SIGNAL_MODE (VIVID_CID_VIVID_BASE + 60)
82#define VIVID_CID_STANDARD (VIVID_CID_VIVID_BASE + 61) 83#define VIVID_CID_STANDARD (VIVID_CID_VIVID_BASE + 61)
@@ -360,6 +361,13 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)
360 vivid_send_source_change(dev, HDMI); 361 vivid_send_source_change(dev, HDMI);
361 vivid_send_source_change(dev, WEBCAM); 362 vivid_send_source_change(dev, WEBCAM);
362 break; 363 break;
364 case VIVID_CID_XFER_FUNC:
365 tpg_s_xfer_func(&dev->tpg, ctrl->val);
366 vivid_send_source_change(dev, TV);
367 vivid_send_source_change(dev, SVID);
368 vivid_send_source_change(dev, HDMI);
369 vivid_send_source_change(dev, WEBCAM);
370 break;
363 case VIVID_CID_YCBCR_ENC: 371 case VIVID_CID_YCBCR_ENC:
364 tpg_s_ycbcr_enc(&dev->tpg, ctrl->val); 372 tpg_s_ycbcr_enc(&dev->tpg, ctrl->val);
365 vivid_send_source_change(dev, TV); 373 vivid_send_source_change(dev, TV);
@@ -709,6 +717,25 @@ static const struct v4l2_ctrl_config vivid_ctrl_colorspace = {
709 .qmenu = vivid_ctrl_colorspace_strings, 717 .qmenu = vivid_ctrl_colorspace_strings,
710}; 718};
711 719
720static const char * const vivid_ctrl_xfer_func_strings[] = {
721 "Default",
722 "Rec. 709",
723 "sRGB",
724 "AdobeRGB",
725 "SMPTE 240M",
726 "None",
727 NULL,
728};
729
730static const struct v4l2_ctrl_config vivid_ctrl_xfer_func = {
731 .ops = &vivid_vid_cap_ctrl_ops,
732 .id = VIVID_CID_XFER_FUNC,
733 .name = "Transfer Function",
734 .type = V4L2_CTRL_TYPE_MENU,
735 .max = 5,
736 .qmenu = vivid_ctrl_xfer_func_strings,
737};
738
712static const char * const vivid_ctrl_ycbcr_enc_strings[] = { 739static const char * const vivid_ctrl_ycbcr_enc_strings[] = {
713 "Default", 740 "Default",
714 "ITU-R 601", 741 "ITU-R 601",
@@ -766,6 +793,37 @@ static const struct v4l2_ctrl_config vivid_ctrl_limited_rgb_range = {
766}; 793};
767 794
768 795
796/* Video Loop Control */
797
798static int vivid_loop_cap_s_ctrl(struct v4l2_ctrl *ctrl)
799{
800 struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_loop_cap);
801
802 switch (ctrl->id) {
803 case VIVID_CID_LOOP_VIDEO:
804 dev->loop_video = ctrl->val;
805 vivid_update_quality(dev);
806 vivid_send_source_change(dev, SVID);
807 vivid_send_source_change(dev, HDMI);
808 break;
809 }
810 return 0;
811}
812
813static const struct v4l2_ctrl_ops vivid_loop_cap_ctrl_ops = {
814 .s_ctrl = vivid_loop_cap_s_ctrl,
815};
816
817static const struct v4l2_ctrl_config vivid_ctrl_loop_video = {
818 .ops = &vivid_loop_cap_ctrl_ops,
819 .id = VIVID_CID_LOOP_VIDEO,
820 .name = "Loop Video",
821 .type = V4L2_CTRL_TYPE_BOOLEAN,
822 .max = 1,
823 .step = 1,
824};
825
826
769/* VBI Capture Control */ 827/* VBI Capture Control */
770 828
771static int vivid_vbi_cap_s_ctrl(struct v4l2_ctrl *ctrl) 829static int vivid_vbi_cap_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -1199,38 +1257,6 @@ static const struct v4l2_ctrl_config vivid_ctrl_radio_tx_rds_blockio = {
1199}; 1257};
1200 1258
1201 1259
1202
1203/* Video Loop Control */
1204
1205static int vivid_loop_out_s_ctrl(struct v4l2_ctrl *ctrl)
1206{
1207 struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_loop_out);
1208
1209 switch (ctrl->id) {
1210 case VIVID_CID_LOOP_VIDEO:
1211 dev->loop_video = ctrl->val;
1212 vivid_update_quality(dev);
1213 vivid_send_source_change(dev, SVID);
1214 vivid_send_source_change(dev, HDMI);
1215 break;
1216 }
1217 return 0;
1218}
1219
1220static const struct v4l2_ctrl_ops vivid_loop_out_ctrl_ops = {
1221 .s_ctrl = vivid_loop_out_s_ctrl,
1222};
1223
1224static const struct v4l2_ctrl_config vivid_ctrl_loop_video = {
1225 .ops = &vivid_loop_out_ctrl_ops,
1226 .id = VIVID_CID_LOOP_VIDEO,
1227 .name = "Loop Video",
1228 .type = V4L2_CTRL_TYPE_BOOLEAN,
1229 .max = 1,
1230 .step = 1,
1231};
1232
1233
1234static const struct v4l2_ctrl_config vivid_ctrl_class = { 1260static const struct v4l2_ctrl_config vivid_ctrl_class = {
1235 .ops = &vivid_user_gen_ctrl_ops, 1261 .ops = &vivid_user_gen_ctrl_ops,
1236 .flags = V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY, 1262 .flags = V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY,
@@ -1248,7 +1274,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1248 struct v4l2_ctrl_handler *hdl_user_aud = &dev->ctrl_hdl_user_aud; 1274 struct v4l2_ctrl_handler *hdl_user_aud = &dev->ctrl_hdl_user_aud;
1249 struct v4l2_ctrl_handler *hdl_streaming = &dev->ctrl_hdl_streaming; 1275 struct v4l2_ctrl_handler *hdl_streaming = &dev->ctrl_hdl_streaming;
1250 struct v4l2_ctrl_handler *hdl_sdtv_cap = &dev->ctrl_hdl_sdtv_cap; 1276 struct v4l2_ctrl_handler *hdl_sdtv_cap = &dev->ctrl_hdl_sdtv_cap;
1251 struct v4l2_ctrl_handler *hdl_loop_out = &dev->ctrl_hdl_loop_out; 1277 struct v4l2_ctrl_handler *hdl_loop_cap = &dev->ctrl_hdl_loop_cap;
1252 struct v4l2_ctrl_handler *hdl_vid_cap = &dev->ctrl_hdl_vid_cap; 1278 struct v4l2_ctrl_handler *hdl_vid_cap = &dev->ctrl_hdl_vid_cap;
1253 struct v4l2_ctrl_handler *hdl_vid_out = &dev->ctrl_hdl_vid_out; 1279 struct v4l2_ctrl_handler *hdl_vid_out = &dev->ctrl_hdl_vid_out;
1254 struct v4l2_ctrl_handler *hdl_vbi_cap = &dev->ctrl_hdl_vbi_cap; 1280 struct v4l2_ctrl_handler *hdl_vbi_cap = &dev->ctrl_hdl_vbi_cap;
@@ -1274,8 +1300,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1274 v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_class, NULL); 1300 v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_class, NULL);
1275 v4l2_ctrl_handler_init(hdl_sdtv_cap, 2); 1301 v4l2_ctrl_handler_init(hdl_sdtv_cap, 2);
1276 v4l2_ctrl_new_custom(hdl_sdtv_cap, &vivid_ctrl_class, NULL); 1302 v4l2_ctrl_new_custom(hdl_sdtv_cap, &vivid_ctrl_class, NULL);
1277 v4l2_ctrl_handler_init(hdl_loop_out, 1); 1303 v4l2_ctrl_handler_init(hdl_loop_cap, 1);
1278 v4l2_ctrl_new_custom(hdl_loop_out, &vivid_ctrl_class, NULL); 1304 v4l2_ctrl_new_custom(hdl_loop_cap, &vivid_ctrl_class, NULL);
1279 v4l2_ctrl_handler_init(hdl_vid_cap, 55); 1305 v4l2_ctrl_handler_init(hdl_vid_cap, 55);
1280 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_class, NULL); 1306 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_class, NULL);
1281 v4l2_ctrl_handler_init(hdl_vid_out, 26); 1307 v4l2_ctrl_handler_init(hdl_vid_out, 26);
@@ -1365,6 +1391,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1365 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_tstamp_src, NULL); 1391 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_tstamp_src, NULL);
1366 dev->colorspace = v4l2_ctrl_new_custom(hdl_vid_cap, 1392 dev->colorspace = v4l2_ctrl_new_custom(hdl_vid_cap,
1367 &vivid_ctrl_colorspace, NULL); 1393 &vivid_ctrl_colorspace, NULL);
1394 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_xfer_func, NULL);
1368 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_ycbcr_enc, NULL); 1395 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_ycbcr_enc, NULL);
1369 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_quantization, NULL); 1396 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_quantization, NULL);
1370 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_alpha_mode, NULL); 1397 v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_alpha_mode, NULL);
@@ -1445,7 +1472,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1445 } 1472 }
1446 if ((dev->has_vid_cap && dev->has_vid_out) || 1473 if ((dev->has_vid_cap && dev->has_vid_out) ||
1447 (dev->has_vbi_cap && dev->has_vbi_out)) 1474 (dev->has_vbi_cap && dev->has_vbi_out))
1448 v4l2_ctrl_new_custom(hdl_loop_out, &vivid_ctrl_loop_video, NULL); 1475 v4l2_ctrl_new_custom(hdl_loop_cap, &vivid_ctrl_loop_video, NULL);
1449 1476
1450 if (dev->has_fb) 1477 if (dev->has_fb)
1451 v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_clear_fb, NULL); 1478 v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_clear_fb, NULL);
@@ -1528,8 +1555,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1528 return hdl_streaming->error; 1555 return hdl_streaming->error;
1529 if (hdl_sdr_cap->error) 1556 if (hdl_sdr_cap->error)
1530 return hdl_sdr_cap->error; 1557 return hdl_sdr_cap->error;
1531 if (hdl_loop_out->error) 1558 if (hdl_loop_cap->error)
1532 return hdl_loop_out->error; 1559 return hdl_loop_cap->error;
1533 1560
1534 if (dev->autogain) 1561 if (dev->autogain)
1535 v4l2_ctrl_auto_cluster(2, &dev->autogain, 0, true); 1562 v4l2_ctrl_auto_cluster(2, &dev->autogain, 0, true);
@@ -1540,6 +1567,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1540 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_user_aud, NULL); 1567 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_user_aud, NULL);
1541 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_streaming, NULL); 1568 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_streaming, NULL);
1542 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_sdtv_cap, NULL); 1569 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_sdtv_cap, NULL);
1570 v4l2_ctrl_add_handler(hdl_vid_cap, hdl_loop_cap, NULL);
1543 if (hdl_vid_cap->error) 1571 if (hdl_vid_cap->error)
1544 return hdl_vid_cap->error; 1572 return hdl_vid_cap->error;
1545 dev->vid_cap_dev.ctrl_handler = hdl_vid_cap; 1573 dev->vid_cap_dev.ctrl_handler = hdl_vid_cap;
@@ -1548,7 +1576,6 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1548 v4l2_ctrl_add_handler(hdl_vid_out, hdl_user_gen, NULL); 1576 v4l2_ctrl_add_handler(hdl_vid_out, hdl_user_gen, NULL);
1549 v4l2_ctrl_add_handler(hdl_vid_out, hdl_user_aud, NULL); 1577 v4l2_ctrl_add_handler(hdl_vid_out, hdl_user_aud, NULL);
1550 v4l2_ctrl_add_handler(hdl_vid_out, hdl_streaming, NULL); 1578 v4l2_ctrl_add_handler(hdl_vid_out, hdl_streaming, NULL);
1551 v4l2_ctrl_add_handler(hdl_vid_out, hdl_loop_out, NULL);
1552 if (hdl_vid_out->error) 1579 if (hdl_vid_out->error)
1553 return hdl_vid_out->error; 1580 return hdl_vid_out->error;
1554 dev->vid_out_dev.ctrl_handler = hdl_vid_out; 1581 dev->vid_out_dev.ctrl_handler = hdl_vid_out;
@@ -1557,6 +1584,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1557 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_user_gen, NULL); 1584 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_user_gen, NULL);
1558 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_streaming, NULL); 1585 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_streaming, NULL);
1559 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_sdtv_cap, NULL); 1586 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_sdtv_cap, NULL);
1587 v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_loop_cap, NULL);
1560 if (hdl_vbi_cap->error) 1588 if (hdl_vbi_cap->error)
1561 return hdl_vbi_cap->error; 1589 return hdl_vbi_cap->error;
1562 dev->vbi_cap_dev.ctrl_handler = hdl_vbi_cap; 1590 dev->vbi_cap_dev.ctrl_handler = hdl_vbi_cap;
@@ -1564,7 +1592,6 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
1564 if (dev->has_vbi_out) { 1592 if (dev->has_vbi_out) {
1565 v4l2_ctrl_add_handler(hdl_vbi_out, hdl_user_gen, NULL); 1593 v4l2_ctrl_add_handler(hdl_vbi_out, hdl_user_gen, NULL);
1566 v4l2_ctrl_add_handler(hdl_vbi_out, hdl_streaming, NULL); 1594 v4l2_ctrl_add_handler(hdl_vbi_out, hdl_streaming, NULL);
1567 v4l2_ctrl_add_handler(hdl_vbi_out, hdl_loop_out, NULL);
1568 if (hdl_vbi_out->error) 1595 if (hdl_vbi_out->error)
1569 return hdl_vbi_out->error; 1596 return hdl_vbi_out->error;
1570 dev->vbi_out_dev.ctrl_handler = hdl_vbi_out; 1597 dev->vbi_out_dev.ctrl_handler = hdl_vbi_out;
@@ -1607,5 +1634,5 @@ void vivid_free_controls(struct vivid_dev *dev)
1607 v4l2_ctrl_handler_free(&dev->ctrl_hdl_user_aud); 1634 v4l2_ctrl_handler_free(&dev->ctrl_hdl_user_aud);
1608 v4l2_ctrl_handler_free(&dev->ctrl_hdl_streaming); 1635 v4l2_ctrl_handler_free(&dev->ctrl_hdl_streaming);
1609 v4l2_ctrl_handler_free(&dev->ctrl_hdl_sdtv_cap); 1636 v4l2_ctrl_handler_free(&dev->ctrl_hdl_sdtv_cap);
1610 v4l2_ctrl_handler_free(&dev->ctrl_hdl_loop_out); 1637 v4l2_ctrl_handler_free(&dev->ctrl_hdl_loop_cap);
1611} 1638}
diff --git a/drivers/media/platform/vivid/vivid-radio-rx.c b/drivers/media/platform/vivid/vivid-radio-rx.c
index c7651a506668..f99092ca8f5c 100644
--- a/drivers/media/platform/vivid/vivid-radio-rx.c
+++ b/drivers/media/platform/vivid/vivid-radio-rx.c
@@ -195,6 +195,8 @@ int vivid_radio_rx_s_hw_freq_seek(struct file *file, void *fh, const struct v4l2
195 if (dev->radio_rx_freq >= vivid_radio_bands[band].rangelow && 195 if (dev->radio_rx_freq >= vivid_radio_bands[band].rangelow &&
196 dev->radio_rx_freq <= vivid_radio_bands[band].rangehigh) 196 dev->radio_rx_freq <= vivid_radio_bands[band].rangehigh)
197 break; 197 break;
198 if (band == TOT_BANDS)
199 return -EINVAL;
198 low = vivid_radio_bands[band].rangelow; 200 low = vivid_radio_bands[band].rangelow;
199 high = vivid_radio_bands[band].rangehigh; 201 high = vivid_radio_bands[band].rangehigh;
200 } 202 }
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
index caf131666e37..d2f2188a0efe 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -33,6 +33,25 @@
33#include "vivid-ctrls.h" 33#include "vivid-ctrls.h"
34#include "vivid-sdr-cap.h" 34#include "vivid-sdr-cap.h"
35 35
36/* stream formats */
37struct vivid_format {
38 u32 pixelformat;
39 u32 buffersize;
40};
41
42/* format descriptions for capture and preview */
43static struct vivid_format formats[] = {
44 {
45 .pixelformat = V4L2_SDR_FMT_CU8,
46 .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
47 }, {
48 .pixelformat = V4L2_SDR_FMT_CS8,
49 .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
50 },
51};
52
53static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
54
36static const struct v4l2_frequency_band bands_adc[] = { 55static const struct v4l2_frequency_band bands_adc[] = {
37 { 56 {
38 .tuner = 0, 57 .tuner = 0,
@@ -409,21 +428,63 @@ int vivid_sdr_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
409 428
410int vidioc_enum_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f) 429int vidioc_enum_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
411{ 430{
412 if (f->index) 431 if (f->index >= ARRAY_SIZE(formats))
413 return -EINVAL; 432 return -EINVAL;
414 f->pixelformat = V4L2_SDR_FMT_CU8; 433 f->pixelformat = formats[f->index].pixelformat;
415 strlcpy(f->description, "IQ U8", sizeof(f->description));
416 return 0; 434 return 0;
417} 435}
418 436
419int vidioc_g_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f) 437int vidioc_g_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
420{ 438{
421 f->fmt.sdr.pixelformat = V4L2_SDR_FMT_CU8; 439 struct vivid_dev *dev = video_drvdata(file);
422 f->fmt.sdr.buffersize = SDR_CAP_SAMPLES_PER_BUF * 2; 440
441 f->fmt.sdr.pixelformat = dev->sdr_pixelformat;
442 f->fmt.sdr.buffersize = dev->sdr_buffersize;
423 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 443 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
424 return 0; 444 return 0;
425} 445}
426 446
447int vidioc_s_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
448{
449 struct vivid_dev *dev = video_drvdata(file);
450 struct vb2_queue *q = &dev->vb_sdr_cap_q;
451 int i;
452
453 if (vb2_is_busy(q))
454 return -EBUSY;
455
456 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
457 for (i = 0; i < ARRAY_SIZE(formats); i++) {
458 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
459 dev->sdr_pixelformat = formats[i].pixelformat;
460 dev->sdr_buffersize = formats[i].buffersize;
461 f->fmt.sdr.buffersize = formats[i].buffersize;
462 return 0;
463 }
464 }
465 dev->sdr_pixelformat = formats[0].pixelformat;
466 dev->sdr_buffersize = formats[0].buffersize;
467 f->fmt.sdr.pixelformat = formats[0].pixelformat;
468 f->fmt.sdr.buffersize = formats[0].buffersize;
469 return 0;
470}
471
472int vidioc_try_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
473{
474 int i;
475
476 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
477 for (i = 0; i < ARRAY_SIZE(formats); i++) {
478 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
479 f->fmt.sdr.buffersize = formats[i].buffersize;
480 return 0;
481 }
482 }
483 f->fmt.sdr.pixelformat = formats[0].pixelformat;
484 f->fmt.sdr.buffersize = formats[0].buffersize;
485 return 0;
486}
487
427#define FIXP_N (15) 488#define FIXP_N (15)
428#define FIXP_FRAC (1 << FIXP_N) 489#define FIXP_FRAC (1 << FIXP_N)
429#define FIXP_2PI ((int)(2 * 3.141592653589 * FIXP_FRAC)) 490#define FIXP_2PI ((int)(2 * 3.141592653589 * FIXP_FRAC))
@@ -477,11 +538,24 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
477 fixp_i >>= (31 - FIXP_N); 538 fixp_i >>= (31 - FIXP_N);
478 fixp_q >>= (31 - FIXP_N); 539 fixp_q >>= (31 - FIXP_N);
479 540
480 /* convert 'fixp float' to u8 */ 541 switch (dev->sdr_pixelformat) {
481 /* u8 = X * 127.5f + 127.5f; where X is float [-1.0 / +1.0] */ 542 case V4L2_SDR_FMT_CU8:
482 fixp_i = fixp_i * 1275 + FIXP_FRAC * 1275; 543 /* convert 'fixp float' to u8 */
483 fixp_q = fixp_q * 1275 + FIXP_FRAC * 1275; 544 /* u8 = X * 127.5 + 127.5; X is float [-1.0, +1.0] */
484 *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10); 545 fixp_i = fixp_i * 1275 + FIXP_FRAC * 1275;
485 *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10); 546 fixp_q = fixp_q * 1275 + FIXP_FRAC * 1275;
547 *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10);
548 *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10);
549 break;
550 case V4L2_SDR_FMT_CS8:
551 /* convert 'fixp float' to s8 */
552 fixp_i = fixp_i * 1275;
553 fixp_q = fixp_q * 1275;
554 *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10);
555 *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10);
556 break;
557 default:
558 break;
559 }
486 } 560 }
487} 561}
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.h b/drivers/media/platform/vivid/vivid-sdr-cap.h
index 79c1890de972..43014b2733db 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.h
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.h
@@ -27,6 +27,8 @@ int vivid_sdr_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt);
27int vivid_sdr_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt); 27int vivid_sdr_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt);
28int vidioc_enum_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f); 28int vidioc_enum_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f);
29int vidioc_g_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f); 29int vidioc_g_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f);
30int vidioc_s_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f);
31int vidioc_try_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f);
30void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf); 32void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf);
31 33
32extern const struct vb2_ops vivid_sdr_cap_qops; 34extern const struct vb2_ops vivid_sdr_cap_qops;
diff --git a/drivers/media/platform/vivid/vivid-tpg-colors.c b/drivers/media/platform/vivid/vivid-tpg-colors.c
index 424aa7abc723..8f231a6e68c9 100644
--- a/drivers/media/platform/vivid/vivid-tpg-colors.c
+++ b/drivers/media/platform/vivid/vivid-tpg-colors.c
@@ -598,71 +598,327 @@ const unsigned short tpg_linear_to_rec709[255 * 16 + 1] = {
598}; 598};
599 599
600/* Generated table */ 600/* Generated table */
601const struct color16 tpg_csc_colors[V4L2_COLORSPACE_BT2020 + 1][TPG_COLOR_CSC_BLACK + 1] = { 601const struct color16 tpg_csc_colors[V4L2_COLORSPACE_BT2020 + 1][V4L2_XFER_FUNC_NONE + 1][TPG_COLOR_CSC_BLACK + 1] = {
602 [V4L2_COLORSPACE_SMPTE170M][0] = { 2939, 2939, 2939 }, 602 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
603 [V4L2_COLORSPACE_SMPTE170M][1] = { 2953, 2963, 586 }, 603 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][1] = { 2953, 2963, 586 },
604 [V4L2_COLORSPACE_SMPTE170M][2] = { 0, 2967, 2937 }, 604 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][2] = { 0, 2967, 2937 },
605 [V4L2_COLORSPACE_SMPTE170M][3] = { 88, 2990, 575 }, 605 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][3] = { 88, 2990, 575 },
606 [V4L2_COLORSPACE_SMPTE170M][4] = { 3016, 259, 2933 }, 606 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][4] = { 3016, 259, 2933 },
607 [V4L2_COLORSPACE_SMPTE170M][5] = { 3030, 405, 558 }, 607 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][5] = { 3030, 405, 558 },
608 [V4L2_COLORSPACE_SMPTE170M][6] = { 478, 428, 2931 }, 608 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][6] = { 478, 428, 2931 },
609 [V4L2_COLORSPACE_SMPTE170M][7] = { 547, 547, 547 }, 609 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
610 [V4L2_COLORSPACE_SMPTE240M][0] = { 2926, 2926, 2926 }, 610 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
611 [V4L2_COLORSPACE_SMPTE240M][1] = { 2941, 2950, 546 }, 611 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][1] = { 3068, 3077, 838 },
612 [V4L2_COLORSPACE_SMPTE240M][2] = { 0, 2954, 2924 }, 612 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][2] = { 0, 3081, 3053 },
613 [V4L2_COLORSPACE_SMPTE240M][3] = { 78, 2978, 536 }, 613 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][3] = { 241, 3102, 828 },
614 [V4L2_COLORSPACE_SMPTE240M][4] = { 3004, 230, 2920 }, 614 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][4] = { 3126, 504, 3050 },
615 [V4L2_COLORSPACE_SMPTE240M][5] = { 3018, 363, 518 }, 615 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][5] = { 3138, 657, 810 },
616 [V4L2_COLORSPACE_SMPTE240M][6] = { 437, 387, 2918 }, 616 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][6] = { 731, 680, 3048 },
617 [V4L2_COLORSPACE_SMPTE240M][7] = { 507, 507, 507 }, 617 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SRGB][7] = { 800, 799, 800 },
618 [V4L2_COLORSPACE_REC709][0] = { 2939, 2939, 2939 }, 618 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
619 [V4L2_COLORSPACE_REC709][1] = { 2939, 2939, 547 }, 619 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][1] = { 3046, 3054, 886 },
620 [V4L2_COLORSPACE_REC709][2] = { 547, 2939, 2939 }, 620 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][2] = { 0, 3058, 3031 },
621 [V4L2_COLORSPACE_REC709][3] = { 547, 2939, 547 }, 621 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][3] = { 360, 3079, 877 },
622 [V4L2_COLORSPACE_REC709][4] = { 2939, 547, 2939 }, 622 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][4] = { 3103, 587, 3027 },
623 [V4L2_COLORSPACE_REC709][5] = { 2939, 547, 547 }, 623 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][5] = { 3116, 723, 861 },
624 [V4L2_COLORSPACE_REC709][6] = { 547, 547, 2939 }, 624 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][6] = { 789, 744, 3025 },
625 [V4L2_COLORSPACE_REC709][7] = { 547, 547, 547 }, 625 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
626 [V4L2_COLORSPACE_470_SYSTEM_M][0] = { 2892, 2988, 2807 }, 626 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
627 [V4L2_COLORSPACE_470_SYSTEM_M][1] = { 2846, 3070, 843 }, 627 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][1] = { 2941, 2950, 546 },
628 [V4L2_COLORSPACE_470_SYSTEM_M][2] = { 1656, 2962, 2783 }, 628 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][2] = { 0, 2954, 2924 },
629 [V4L2_COLORSPACE_470_SYSTEM_M][3] = { 1572, 3045, 763 }, 629 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][3] = { 78, 2978, 536 },
630 [V4L2_COLORSPACE_470_SYSTEM_M][4] = { 2476, 229, 2742 }, 630 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][4] = { 3004, 230, 2920 },
631 [V4L2_COLORSPACE_470_SYSTEM_M][5] = { 2420, 672, 614 }, 631 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][5] = { 3018, 363, 518 },
632 [V4L2_COLORSPACE_470_SYSTEM_M][6] = { 725, 63, 2718 }, 632 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][6] = { 437, 387, 2918 },
633 [V4L2_COLORSPACE_470_SYSTEM_M][7] = { 534, 561, 509 }, 633 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
634 [V4L2_COLORSPACE_470_SYSTEM_BG][0] = { 2939, 2939, 2939 }, 634 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
635 [V4L2_COLORSPACE_470_SYSTEM_BG][1] = { 2939, 2939, 464 }, 635 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][1] = { 2145, 2159, 142 },
636 [V4L2_COLORSPACE_470_SYSTEM_BG][2] = { 786, 2939, 2939 }, 636 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][2] = { 0, 2164, 2122 },
637 [V4L2_COLORSPACE_470_SYSTEM_BG][3] = { 786, 2939, 464 }, 637 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][3] = { 19, 2198, 138 },
638 [V4L2_COLORSPACE_470_SYSTEM_BG][4] = { 2879, 547, 2956 }, 638 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][4] = { 2236, 57, 2116 },
639 [V4L2_COLORSPACE_470_SYSTEM_BG][5] = { 2879, 547, 547 }, 639 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][5] = { 2256, 90, 133 },
640 [V4L2_COLORSPACE_470_SYSTEM_BG][6] = { 547, 547, 2956 }, 640 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][6] = { 110, 96, 2113 },
641 [V4L2_COLORSPACE_470_SYSTEM_BG][7] = { 547, 547, 547 }, 641 [V4L2_COLORSPACE_SMPTE170M][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
642 [V4L2_COLORSPACE_SRGB][0] = { 3056, 3056, 3056 }, 642 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
643 [V4L2_COLORSPACE_SRGB][1] = { 3056, 3056, 800 }, 643 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][1] = { 2953, 2963, 586 },
644 [V4L2_COLORSPACE_SRGB][2] = { 800, 3056, 3056 }, 644 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][2] = { 0, 2967, 2937 },
645 [V4L2_COLORSPACE_SRGB][3] = { 800, 3056, 800 }, 645 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][3] = { 88, 2990, 575 },
646 [V4L2_COLORSPACE_SRGB][4] = { 3056, 800, 3056 }, 646 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][4] = { 3016, 259, 2933 },
647 [V4L2_COLORSPACE_SRGB][5] = { 3056, 800, 800 }, 647 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][5] = { 3030, 405, 558 },
648 [V4L2_COLORSPACE_SRGB][6] = { 800, 800, 3056 }, 648 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][6] = { 478, 428, 2931 },
649 [V4L2_COLORSPACE_SRGB][7] = { 800, 800, 800 }, 649 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
650 [V4L2_COLORSPACE_ADOBERGB][0] = { 3033, 3033, 3033 }, 650 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
651 [V4L2_COLORSPACE_ADOBERGB][1] = { 3033, 3033, 1063 }, 651 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][1] = { 3068, 3077, 838 },
652 [V4L2_COLORSPACE_ADOBERGB][2] = { 1828, 3033, 3033 }, 652 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][2] = { 0, 3081, 3053 },
653 [V4L2_COLORSPACE_ADOBERGB][3] = { 1828, 3033, 1063 }, 653 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][3] = { 241, 3102, 828 },
654 [V4L2_COLORSPACE_ADOBERGB][4] = { 2633, 851, 2979 }, 654 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][4] = { 3126, 504, 3050 },
655 [V4L2_COLORSPACE_ADOBERGB][5] = { 2633, 851, 851 }, 655 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][5] = { 3138, 657, 810 },
656 [V4L2_COLORSPACE_ADOBERGB][6] = { 851, 851, 2979 }, 656 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][6] = { 731, 680, 3048 },
657 [V4L2_COLORSPACE_ADOBERGB][7] = { 851, 851, 851 }, 657 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SRGB][7] = { 800, 799, 800 },
658 [V4L2_COLORSPACE_BT2020][0] = { 2939, 2939, 2939 }, 658 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
659 [V4L2_COLORSPACE_BT2020][1] = { 2877, 2923, 1058 }, 659 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][1] = { 3046, 3054, 886 },
660 [V4L2_COLORSPACE_BT2020][2] = { 1837, 2840, 2916 }, 660 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][2] = { 0, 3058, 3031 },
661 [V4L2_COLORSPACE_BT2020][3] = { 1734, 2823, 993 }, 661 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][3] = { 360, 3079, 877 },
662 [V4L2_COLORSPACE_BT2020][4] = { 2427, 961, 2812 }, 662 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][4] = { 3103, 587, 3027 },
663 [V4L2_COLORSPACE_BT2020][5] = { 2351, 912, 648 }, 663 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][5] = { 3116, 723, 861 },
664 [V4L2_COLORSPACE_BT2020][6] = { 792, 618, 2788 }, 664 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][6] = { 789, 744, 3025 },
665 [V4L2_COLORSPACE_BT2020][7] = { 547, 547, 547 }, 665 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
666 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
667 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][1] = { 2941, 2950, 546 },
668 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][2] = { 0, 2954, 2924 },
669 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][3] = { 78, 2978, 536 },
670 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][4] = { 3004, 230, 2920 },
671 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][5] = { 3018, 363, 518 },
672 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][6] = { 437, 387, 2918 },
673 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
674 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
675 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][1] = { 2145, 2159, 142 },
676 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][2] = { 0, 2164, 2122 },
677 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][3] = { 19, 2198, 138 },
678 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][4] = { 2236, 57, 2116 },
679 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][5] = { 2256, 90, 133 },
680 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][6] = { 110, 96, 2113 },
681 [V4L2_COLORSPACE_SMPTE240M][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
682 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
683 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][1] = { 2939, 2939, 547 },
684 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][2] = { 547, 2939, 2939 },
685 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][3] = { 547, 2939, 547 },
686 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][4] = { 2939, 547, 2939 },
687 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][5] = { 2939, 547, 547 },
688 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][6] = { 547, 547, 2939 },
689 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
690 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
691 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][1] = { 3056, 3056, 800 },
692 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][2] = { 800, 3056, 3056 },
693 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][3] = { 800, 3056, 800 },
694 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][4] = { 3056, 800, 3056 },
695 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][5] = { 3056, 800, 800 },
696 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][6] = { 800, 800, 3056 },
697 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SRGB][7] = { 800, 800, 800 },
698 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
699 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][1] = { 3033, 3033, 851 },
700 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][2] = { 851, 3033, 3033 },
701 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][3] = { 851, 3033, 851 },
702 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][4] = { 3033, 851, 3033 },
703 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][5] = { 3033, 851, 851 },
704 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][6] = { 851, 851, 3033 },
705 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
706 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
707 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][1] = { 2926, 2926, 507 },
708 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][2] = { 507, 2926, 2926 },
709 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][3] = { 507, 2926, 507 },
710 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][4] = { 2926, 507, 2926 },
711 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][5] = { 2926, 507, 507 },
712 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][6] = { 507, 507, 2926 },
713 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
714 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
715 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][1] = { 2125, 2125, 130 },
716 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][2] = { 130, 2125, 2125 },
717 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][3] = { 130, 2125, 130 },
718 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][4] = { 2125, 130, 2125 },
719 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][5] = { 2125, 130, 130 },
720 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][6] = { 130, 130, 2125 },
721 [V4L2_COLORSPACE_REC709][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
722 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][0] = { 2892, 2988, 2807 },
723 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][1] = { 2846, 3070, 843 },
724 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][2] = { 1656, 2962, 2783 },
725 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][3] = { 1572, 3045, 763 },
726 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][4] = { 2476, 229, 2742 },
727 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][5] = { 2420, 672, 614 },
728 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][6] = { 725, 63, 2718 },
729 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_709][7] = { 534, 561, 509 },
730 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][0] = { 3013, 3099, 2935 },
731 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][1] = { 2970, 3174, 1091 },
732 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][2] = { 1871, 3076, 2913 },
733 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][3] = { 1791, 3152, 1013 },
734 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][4] = { 2632, 468, 2876 },
735 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][5] = { 2581, 924, 866 },
736 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][6] = { 976, 180, 2854 },
737 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SRGB][7] = { 786, 813, 762 },
738 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][0] = { 2990, 3077, 2912 },
739 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][1] = { 2947, 3153, 1119 },
740 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][2] = { 1859, 3053, 2889 },
741 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][3] = { 1782, 3130, 1047 },
742 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][4] = { 2608, 556, 2852 },
743 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][5] = { 2557, 964, 912 },
744 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][6] = { 1013, 309, 2830 },
745 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_ADOBERGB][7] = { 839, 864, 817 },
746 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][0] = { 2879, 2975, 2793 },
747 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][1] = { 2832, 3059, 806 },
748 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][2] = { 1629, 2949, 2768 },
749 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][3] = { 1543, 3033, 725 },
750 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][4] = { 2457, 203, 2727 },
751 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][5] = { 2401, 633, 574 },
752 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][6] = { 687, 56, 2702 },
753 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_SMPTE240M][7] = { 493, 521, 469 },
754 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][0] = { 2060, 2194, 1943 },
755 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][1] = { 1995, 2314, 237 },
756 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][2] = { 725, 2157, 1911 },
757 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][3] = { 660, 2278, 205 },
758 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][4] = { 1525, 50, 1857 },
759 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][5] = { 1461, 171, 151 },
760 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][6] = { 190, 14, 1825 },
761 [V4L2_COLORSPACE_470_SYSTEM_M][V4L2_XFER_FUNC_NONE][7] = { 126, 134, 118 },
762 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
763 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][1] = { 2939, 2939, 464 },
764 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][2] = { 786, 2939, 2939 },
765 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][3] = { 786, 2939, 464 },
766 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][4] = { 2879, 547, 2956 },
767 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][5] = { 2879, 547, 547 },
768 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][6] = { 547, 547, 2956 },
769 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
770 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
771 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][1] = { 3056, 3056, 717 },
772 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][2] = { 1036, 3056, 3056 },
773 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][3] = { 1036, 3056, 717 },
774 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][4] = { 3001, 800, 3071 },
775 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][5] = { 3001, 800, 799 },
776 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][6] = { 800, 800, 3071 },
777 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SRGB][7] = { 800, 800, 799 },
778 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
779 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][1] = { 3033, 3033, 776 },
780 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][2] = { 1068, 3033, 3033 },
781 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][3] = { 1068, 3033, 776 },
782 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][4] = { 2977, 851, 3048 },
783 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][5] = { 2977, 851, 851 },
784 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][6] = { 851, 851, 3048 },
785 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
786 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
787 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][1] = { 2926, 2926, 423 },
788 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][2] = { 749, 2926, 2926 },
789 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][3] = { 749, 2926, 423 },
790 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][4] = { 2865, 507, 2943 },
791 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][5] = { 2865, 507, 507 },
792 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][6] = { 507, 507, 2943 },
793 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
794 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
795 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][1] = { 2125, 2125, 106 },
796 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][2] = { 214, 2125, 2125 },
797 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][3] = { 214, 2125, 106 },
798 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][4] = { 2041, 130, 2149 },
799 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][5] = { 2041, 130, 130 },
800 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][6] = { 130, 130, 2149 },
801 [V4L2_COLORSPACE_470_SYSTEM_BG][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
802 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
803 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][1] = { 2939, 2939, 547 },
804 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][2] = { 547, 2939, 2939 },
805 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][3] = { 547, 2939, 547 },
806 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][4] = { 2939, 547, 2939 },
807 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][5] = { 2939, 547, 547 },
808 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][6] = { 547, 547, 2939 },
809 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
810 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
811 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][1] = { 3056, 3056, 800 },
812 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][2] = { 800, 3056, 3056 },
813 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][3] = { 800, 3056, 800 },
814 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][4] = { 3056, 800, 3056 },
815 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][5] = { 3056, 800, 800 },
816 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][6] = { 800, 800, 3056 },
817 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SRGB][7] = { 800, 800, 800 },
818 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
819 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][1] = { 3033, 3033, 851 },
820 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][2] = { 851, 3033, 3033 },
821 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][3] = { 851, 3033, 851 },
822 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][4] = { 3033, 851, 3033 },
823 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][5] = { 3033, 851, 851 },
824 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][6] = { 851, 851, 3033 },
825 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
826 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
827 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][1] = { 2926, 2926, 507 },
828 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][2] = { 507, 2926, 2926 },
829 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][3] = { 507, 2926, 507 },
830 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][4] = { 2926, 507, 2926 },
831 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][5] = { 2926, 507, 507 },
832 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][6] = { 507, 507, 2926 },
833 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
834 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
835 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][1] = { 2125, 2125, 130 },
836 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][2] = { 130, 2125, 2125 },
837 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][3] = { 130, 2125, 130 },
838 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][4] = { 2125, 130, 2125 },
839 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][5] = { 2125, 130, 130 },
840 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][6] = { 130, 130, 2125 },
841 [V4L2_COLORSPACE_SRGB][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
842 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
843 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][1] = { 2939, 2939, 781 },
844 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][2] = { 1622, 2939, 2939 },
845 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][3] = { 1622, 2939, 781 },
846 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][4] = { 2502, 547, 2881 },
847 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][5] = { 2502, 547, 547 },
848 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][6] = { 547, 547, 2881 },
849 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
850 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
851 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][1] = { 3056, 3056, 1031 },
852 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][2] = { 1838, 3056, 3056 },
853 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][3] = { 1838, 3056, 1031 },
854 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][4] = { 2657, 800, 3002 },
855 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][5] = { 2657, 800, 800 },
856 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][6] = { 800, 800, 3002 },
857 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SRGB][7] = { 800, 800, 800 },
858 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
859 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][1] = { 3033, 3033, 1063 },
860 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][2] = { 1828, 3033, 3033 },
861 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][3] = { 1828, 3033, 1063 },
862 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][4] = { 2633, 851, 2979 },
863 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][5] = { 2633, 851, 851 },
864 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][6] = { 851, 851, 2979 },
865 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
866 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
867 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][1] = { 2926, 2926, 744 },
868 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][2] = { 1594, 2926, 2926 },
869 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][3] = { 1594, 2926, 744 },
870 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][4] = { 2484, 507, 2867 },
871 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][5] = { 2484, 507, 507 },
872 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][6] = { 507, 507, 2867 },
873 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
874 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
875 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][1] = { 2125, 2125, 212 },
876 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][2] = { 698, 2125, 2125 },
877 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][3] = { 698, 2125, 212 },
878 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][4] = { 1557, 130, 2043 },
879 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][5] = { 1557, 130, 130 },
880 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][6] = { 130, 130, 2043 },
881 [V4L2_COLORSPACE_ADOBERGB][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
882 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][0] = { 2939, 2939, 2939 },
883 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][1] = { 2877, 2923, 1058 },
884 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][2] = { 1837, 2840, 2916 },
885 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][3] = { 1734, 2823, 993 },
886 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][4] = { 2427, 961, 2812 },
887 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][5] = { 2351, 912, 648 },
888 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][6] = { 792, 618, 2788 },
889 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_709][7] = { 547, 547, 547 },
890 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][0] = { 3056, 3056, 3056 },
891 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][1] = { 2999, 3041, 1301 },
892 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][2] = { 2040, 2965, 3034 },
893 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][3] = { 1944, 2950, 1238 },
894 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][4] = { 2587, 1207, 2940 },
895 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][5] = { 2517, 1159, 900 },
896 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][6] = { 1042, 870, 2917 },
897 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SRGB][7] = { 800, 800, 800 },
898 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][0] = { 3033, 3033, 3033 },
899 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][1] = { 2976, 3018, 1315 },
900 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][2] = { 2024, 2942, 3011 },
901 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][3] = { 1930, 2926, 1256 },
902 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][4] = { 2563, 1227, 2916 },
903 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][5] = { 2494, 1183, 943 },
904 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][6] = { 1073, 916, 2894 },
905 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_ADOBERGB][7] = { 851, 851, 851 },
906 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][0] = { 2926, 2926, 2926 },
907 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][1] = { 2864, 2910, 1024 },
908 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][2] = { 1811, 2826, 2903 },
909 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][3] = { 1707, 2809, 958 },
910 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][4] = { 2408, 926, 2798 },
911 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][5] = { 2331, 876, 609 },
912 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][6] = { 755, 579, 2773 },
913 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_SMPTE240M][7] = { 507, 507, 507 },
914 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][0] = { 2125, 2125, 2125 },
915 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][1] = { 2039, 2102, 338 },
916 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][2] = { 873, 1987, 2092 },
917 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][3] = { 787, 1965, 305 },
918 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][4] = { 1468, 290, 1949 },
919 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][5] = { 1382, 268, 162 },
920 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][6] = { 216, 152, 1917 },
921 [V4L2_COLORSPACE_BT2020][V4L2_XFER_FUNC_NONE][7] = { 130, 130, 130 },
666}; 922};
667 923
668#else 924#else
@@ -764,50 +1020,38 @@ static double transfer_srgb_to_rec709(double v)
764 return transfer_rgb_to_rec709(transfer_srgb_to_rgb(v)); 1020 return transfer_rgb_to_rec709(transfer_srgb_to_rgb(v));
765} 1021}
766 1022
767static void csc(enum v4l2_colorspace colorspace, double *r, double *g, double *b) 1023static void csc(enum v4l2_colorspace colorspace, enum v4l2_xfer_func xfer_func,
1024 double *r, double *g, double *b)
768{ 1025{
769 int clamp = 1; 1026 int clamp = 1;
770 1027
1028 *r = transfer_srgb_to_rgb(*r);
1029 *g = transfer_srgb_to_rgb(*g);
1030 *b = transfer_srgb_to_rgb(*b);
1031
771 /* Convert the primaries of Rec. 709 Linear RGB */ 1032 /* Convert the primaries of Rec. 709 Linear RGB */
772 switch (colorspace) { 1033 switch (colorspace) {
773 case V4L2_COLORSPACE_SMPTE240M: 1034 case V4L2_COLORSPACE_SMPTE240M:
774 *r = transfer_srgb_to_rgb(*r);
775 *g = transfer_srgb_to_rgb(*g);
776 *b = transfer_srgb_to_rgb(*b);
777 mult_matrix(r, g, b, rec709_to_240m); 1035 mult_matrix(r, g, b, rec709_to_240m);
778 break; 1036 break;
779 case V4L2_COLORSPACE_SMPTE170M: 1037 case V4L2_COLORSPACE_SMPTE170M:
780 *r = transfer_srgb_to_rgb(*r);
781 *g = transfer_srgb_to_rgb(*g);
782 *b = transfer_srgb_to_rgb(*b);
783 mult_matrix(r, g, b, rec709_to_170m); 1038 mult_matrix(r, g, b, rec709_to_170m);
784 break; 1039 break;
785 case V4L2_COLORSPACE_470_SYSTEM_BG: 1040 case V4L2_COLORSPACE_470_SYSTEM_BG:
786 *r = transfer_srgb_to_rgb(*r);
787 *g = transfer_srgb_to_rgb(*g);
788 *b = transfer_srgb_to_rgb(*b);
789 mult_matrix(r, g, b, rec709_to_ebu); 1041 mult_matrix(r, g, b, rec709_to_ebu);
790 break; 1042 break;
791 case V4L2_COLORSPACE_470_SYSTEM_M: 1043 case V4L2_COLORSPACE_470_SYSTEM_M:
792 *r = transfer_srgb_to_rgb(*r);
793 *g = transfer_srgb_to_rgb(*g);
794 *b = transfer_srgb_to_rgb(*b);
795 mult_matrix(r, g, b, rec709_to_ntsc1953); 1044 mult_matrix(r, g, b, rec709_to_ntsc1953);
796 break; 1045 break;
797 case V4L2_COLORSPACE_ADOBERGB: 1046 case V4L2_COLORSPACE_ADOBERGB:
798 *r = transfer_srgb_to_rgb(*r);
799 *g = transfer_srgb_to_rgb(*g);
800 *b = transfer_srgb_to_rgb(*b);
801 mult_matrix(r, g, b, rec709_to_adobergb); 1047 mult_matrix(r, g, b, rec709_to_adobergb);
802 break; 1048 break;
803 case V4L2_COLORSPACE_BT2020: 1049 case V4L2_COLORSPACE_BT2020:
804 *r = transfer_srgb_to_rgb(*r);
805 *g = transfer_srgb_to_rgb(*g);
806 *b = transfer_srgb_to_rgb(*b);
807 mult_matrix(r, g, b, rec709_to_bt2020); 1050 mult_matrix(r, g, b, rec709_to_bt2020);
808 break; 1051 break;
809 case V4L2_COLORSPACE_SRGB: 1052 case V4L2_COLORSPACE_SRGB:
810 case V4L2_COLORSPACE_REC709: 1053 case V4L2_COLORSPACE_REC709:
1054 break;
811 default: 1055 default:
812 break; 1056 break;
813 } 1057 }
@@ -818,33 +1062,28 @@ static void csc(enum v4l2_colorspace colorspace, double *r, double *g, double *b
818 *b = ((*b) < 0) ? 0 : (((*b) > 1) ? 1 : (*b)); 1062 *b = ((*b) < 0) ? 0 : (((*b) > 1) ? 1 : (*b));
819 } 1063 }
820 1064
821 /* Encode to gamma corrected colorspace */ 1065 switch (xfer_func) {
822 switch (colorspace) { 1066 case V4L2_XFER_FUNC_709:
823 case V4L2_COLORSPACE_SMPTE240M:
824 *r = transfer_rgb_to_smpte240m(*r);
825 *g = transfer_rgb_to_smpte240m(*g);
826 *b = transfer_rgb_to_smpte240m(*b);
827 break;
828 case V4L2_COLORSPACE_SMPTE170M:
829 case V4L2_COLORSPACE_470_SYSTEM_M:
830 case V4L2_COLORSPACE_470_SYSTEM_BG:
831 case V4L2_COLORSPACE_BT2020:
832 *r = transfer_rgb_to_rec709(*r); 1067 *r = transfer_rgb_to_rec709(*r);
833 *g = transfer_rgb_to_rec709(*g); 1068 *g = transfer_rgb_to_rec709(*g);
834 *b = transfer_rgb_to_rec709(*b); 1069 *b = transfer_rgb_to_rec709(*b);
835 break; 1070 break;
836 case V4L2_COLORSPACE_SRGB: 1071 case V4L2_XFER_FUNC_SRGB:
1072 *r = transfer_rgb_to_srgb(*r);
1073 *g = transfer_rgb_to_srgb(*g);
1074 *b = transfer_rgb_to_srgb(*b);
837 break; 1075 break;
838 case V4L2_COLORSPACE_ADOBERGB: 1076 case V4L2_XFER_FUNC_ADOBERGB:
839 *r = transfer_rgb_to_adobergb(*r); 1077 *r = transfer_rgb_to_adobergb(*r);
840 *g = transfer_rgb_to_adobergb(*g); 1078 *g = transfer_rgb_to_adobergb(*g);
841 *b = transfer_rgb_to_adobergb(*b); 1079 *b = transfer_rgb_to_adobergb(*b);
842 break; 1080 break;
843 case V4L2_COLORSPACE_REC709: 1081 case V4L2_XFER_FUNC_SMPTE240M:
844 default: 1082 *r = transfer_rgb_to_smpte240m(*r);
845 *r = transfer_srgb_to_rec709(*r); 1083 *g = transfer_rgb_to_smpte240m(*g);
846 *g = transfer_srgb_to_rec709(*g); 1084 *b = transfer_rgb_to_smpte240m(*b);
847 *b = transfer_srgb_to_rec709(*b); 1085 break;
1086 case V4L2_XFER_FUNC_NONE:
848 break; 1087 break;
849 } 1088 }
850} 1089}
@@ -877,7 +1116,16 @@ int main(int argc, char **argv)
877 "V4L2_COLORSPACE_ADOBERGB", 1116 "V4L2_COLORSPACE_ADOBERGB",
878 "V4L2_COLORSPACE_BT2020", 1117 "V4L2_COLORSPACE_BT2020",
879 }; 1118 };
1119 static const char * const xfer_func_names[] = {
1120 "",
1121 "V4L2_XFER_FUNC_709",
1122 "V4L2_XFER_FUNC_SRGB",
1123 "V4L2_XFER_FUNC_ADOBERGB",
1124 "V4L2_XFER_FUNC_SMPTE240M",
1125 "V4L2_XFER_FUNC_NONE",
1126 };
880 int i; 1127 int i;
1128 int x;
881 int c; 1129 int c;
882 1130
883 printf("/* Generated table */\n"); 1131 printf("/* Generated table */\n");
@@ -905,22 +1153,26 @@ int main(int argc, char **argv)
905 printf("\n};\n\n"); 1153 printf("\n};\n\n");
906 1154
907 printf("/* Generated table */\n"); 1155 printf("/* Generated table */\n");
908 printf("const struct color16 tpg_csc_colors[V4L2_COLORSPACE_BT2020 + 1][TPG_COLOR_CSC_BLACK + 1] = {\n"); 1156 printf("const struct color16 tpg_csc_colors[V4L2_COLORSPACE_BT2020 + 1][V4L2_XFER_FUNC_NONE + 1][TPG_COLOR_CSC_BLACK + 1] = {\n");
909 for (c = 0; c <= V4L2_COLORSPACE_BT2020; c++) { 1157 for (c = 0; c <= V4L2_COLORSPACE_BT2020; c++) {
910 for (i = 0; i <= TPG_COLOR_CSC_BLACK; i++) { 1158 for (x = 1; x <= V4L2_XFER_FUNC_NONE; x++) {
911 double r, g, b; 1159 for (i = 0; i <= TPG_COLOR_CSC_BLACK; i++) {
1160 double r, g, b;
912 1161
913 if (colorspaces[c] == 0) 1162 if (colorspaces[c] == 0)
914 continue; 1163 continue;
915 1164
916 r = tpg_colors[i].r / 255.0; 1165 r = tpg_colors[i].r / 255.0;
917 g = tpg_colors[i].g / 255.0; 1166 g = tpg_colors[i].g / 255.0;
918 b = tpg_colors[i].b / 255.0; 1167 b = tpg_colors[i].b / 255.0;
919 1168
920 csc(c, &r, &g, &b); 1169 csc(c, x, &r, &g, &b);
921 1170
922 printf("\t[%s][%d] = { %d, %d, %d },\n", colorspace_names[c], i, 1171 printf("\t[%s][%s][%d] = { %d, %d, %d },\n",
923 (int)(r * 4080), (int)(g * 4080), (int)(b * 4080)); 1172 colorspace_names[c],
1173 xfer_func_names[x], i,
1174 (int)(r * 4080), (int)(g * 4080), (int)(b * 4080));
1175 }
924 } 1176 }
925 } 1177 }
926 printf("};\n\n"); 1178 printf("};\n\n");
diff --git a/drivers/media/platform/vivid/vivid-tpg-colors.h b/drivers/media/platform/vivid/vivid-tpg-colors.h
index 2c333356451c..86b8bf3fe745 100644
--- a/drivers/media/platform/vivid/vivid-tpg-colors.h
+++ b/drivers/media/platform/vivid/vivid-tpg-colors.h
@@ -61,6 +61,8 @@ enum tpg_color {
61extern const struct color tpg_colors[TPG_COLOR_MAX]; 61extern const struct color tpg_colors[TPG_COLOR_MAX];
62extern const unsigned short tpg_rec709_to_linear[255 * 16 + 1]; 62extern const unsigned short tpg_rec709_to_linear[255 * 16 + 1];
63extern const unsigned short tpg_linear_to_rec709[255 * 16 + 1]; 63extern const unsigned short tpg_linear_to_rec709[255 * 16 + 1];
64extern const struct color16 tpg_csc_colors[V4L2_COLORSPACE_BT2020 + 1][TPG_COLOR_CSC_BLACK + 1]; 64extern const struct color16 tpg_csc_colors[V4L2_COLORSPACE_BT2020 + 1]
65 [V4L2_XFER_FUNC_NONE + 1]
66 [TPG_COLOR_CSC_BLACK + 1];
65 67
66#endif 68#endif
diff --git a/drivers/media/platform/vivid/vivid-tpg.c b/drivers/media/platform/vivid/vivid-tpg.c
index cb766eb154e7..1458c7955547 100644
--- a/drivers/media/platform/vivid/vivid-tpg.c
+++ b/drivers/media/platform/vivid/vivid-tpg.c
@@ -220,6 +220,8 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
220 case V4L2_PIX_FMT_ARGB32: 220 case V4L2_PIX_FMT_ARGB32:
221 case V4L2_PIX_FMT_ABGR32: 221 case V4L2_PIX_FMT_ABGR32:
222 case V4L2_PIX_FMT_GREY: 222 case V4L2_PIX_FMT_GREY:
223 case V4L2_PIX_FMT_Y16:
224 case V4L2_PIX_FMT_Y16_BE:
223 tpg->is_yuv = false; 225 tpg->is_yuv = false;
224 break; 226 break;
225 case V4L2_PIX_FMT_YUV444: 227 case V4L2_PIX_FMT_YUV444:
@@ -292,6 +294,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
292 } 294 }
293 295
294 switch (fourcc) { 296 switch (fourcc) {
297 case V4L2_PIX_FMT_GREY:
295 case V4L2_PIX_FMT_RGB332: 298 case V4L2_PIX_FMT_RGB332:
296 tpg->twopixelsize[0] = 2; 299 tpg->twopixelsize[0] = 2;
297 break; 300 break;
@@ -313,6 +316,8 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
313 case V4L2_PIX_FMT_YUV444: 316 case V4L2_PIX_FMT_YUV444:
314 case V4L2_PIX_FMT_YUV555: 317 case V4L2_PIX_FMT_YUV555:
315 case V4L2_PIX_FMT_YUV565: 318 case V4L2_PIX_FMT_YUV565:
319 case V4L2_PIX_FMT_Y16:
320 case V4L2_PIX_FMT_Y16_BE:
316 tpg->twopixelsize[0] = 2 * 2; 321 tpg->twopixelsize[0] = 2 * 2;
317 break; 322 break;
318 case V4L2_PIX_FMT_RGB24: 323 case V4L2_PIX_FMT_RGB24:
@@ -329,9 +334,6 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
329 case V4L2_PIX_FMT_YUV32: 334 case V4L2_PIX_FMT_YUV32:
330 tpg->twopixelsize[0] = 2 * 4; 335 tpg->twopixelsize[0] = 2 * 4;
331 break; 336 break;
332 case V4L2_PIX_FMT_GREY:
333 tpg->twopixelsize[0] = 2;
334 break;
335 case V4L2_PIX_FMT_NV12: 337 case V4L2_PIX_FMT_NV12:
336 case V4L2_PIX_FMT_NV21: 338 case V4L2_PIX_FMT_NV21:
337 case V4L2_PIX_FMT_NV12M: 339 case V4L2_PIX_FMT_NV12M:
@@ -479,44 +481,71 @@ static void color_to_ycbcr(struct tpg_data *tpg, int r, int g, int b,
479 { COEFF(-0.116, 224), COEFF(-0.384, 224), COEFF(0.5, 224) }, 481 { COEFF(-0.116, 224), COEFF(-0.384, 224), COEFF(0.5, 224) },
480 { COEFF(0.5, 224), COEFF(-0.445, 224), COEFF(-0.055, 224) }, 482 { COEFF(0.5, 224), COEFF(-0.445, 224), COEFF(-0.055, 224) },
481 }; 483 };
484 static const int smpte240m_full[3][3] = {
485 { COEFF(0.212, 255), COEFF(0.701, 255), COEFF(0.087, 255) },
486 { COEFF(-0.116, 255), COEFF(-0.384, 255), COEFF(0.5, 255) },
487 { COEFF(0.5, 255), COEFF(-0.445, 255), COEFF(-0.055, 255) },
488 };
482 static const int bt2020[3][3] = { 489 static const int bt2020[3][3] = {
483 { COEFF(0.2627, 219), COEFF(0.6780, 219), COEFF(0.0593, 219) }, 490 { COEFF(0.2627, 219), COEFF(0.6780, 219), COEFF(0.0593, 219) },
484 { COEFF(-0.1396, 224), COEFF(-0.3604, 224), COEFF(0.5, 224) }, 491 { COEFF(-0.1396, 224), COEFF(-0.3604, 224), COEFF(0.5, 224) },
485 { COEFF(0.5, 224), COEFF(-0.4598, 224), COEFF(-0.0402, 224) }, 492 { COEFF(0.5, 224), COEFF(-0.4598, 224), COEFF(-0.0402, 224) },
486 }; 493 };
494 static const int bt2020_full[3][3] = {
495 { COEFF(0.2627, 255), COEFF(0.6780, 255), COEFF(0.0593, 255) },
496 { COEFF(-0.1396, 255), COEFF(-0.3604, 255), COEFF(0.5, 255) },
497 { COEFF(0.5, 255), COEFF(-0.4698, 255), COEFF(-0.0402, 255) },
498 };
499 static const int bt2020c[4] = {
500 COEFF(1.0 / 1.9404, 224), COEFF(1.0 / 1.5816, 224),
501 COEFF(1.0 / 1.7184, 224), COEFF(1.0 / 0.9936, 224),
502 };
503 static const int bt2020c_full[4] = {
504 COEFF(1.0 / 1.9404, 255), COEFF(1.0 / 1.5816, 255),
505 COEFF(1.0 / 1.7184, 255), COEFF(1.0 / 0.9936, 255),
506 };
507
487 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; 508 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE;
488 unsigned y_offset = full ? 0 : 16; 509 unsigned y_offset = full ? 0 : 16;
489 int lin_y, yc; 510 int lin_y, yc;
490 511
491 switch (tpg->real_ycbcr_enc) { 512 switch (tpg->real_ycbcr_enc) {
492 case V4L2_YCBCR_ENC_601: 513 case V4L2_YCBCR_ENC_601:
493 case V4L2_YCBCR_ENC_XV601:
494 case V4L2_YCBCR_ENC_SYCC: 514 case V4L2_YCBCR_ENC_SYCC:
495 rgb2ycbcr(full ? bt601_full : bt601, r, g, b, y_offset, y, cb, cr); 515 rgb2ycbcr(full ? bt601_full : bt601, r, g, b, y_offset, y, cb, cr);
496 break; 516 break;
517 case V4L2_YCBCR_ENC_XV601:
518 /* Ignore quantization range, there is only one possible
519 * Y'CbCr encoding. */
520 rgb2ycbcr(bt601, r, g, b, 16, y, cb, cr);
521 break;
522 case V4L2_YCBCR_ENC_XV709:
523 /* Ignore quantization range, there is only one possible
524 * Y'CbCr encoding. */
525 rgb2ycbcr(rec709, r, g, b, 16, y, cb, cr);
526 break;
497 case V4L2_YCBCR_ENC_BT2020: 527 case V4L2_YCBCR_ENC_BT2020:
498 rgb2ycbcr(bt2020, r, g, b, 16, y, cb, cr); 528 rgb2ycbcr(full ? bt2020_full : bt2020, r, g, b, y_offset, y, cb, cr);
499 break; 529 break;
500 case V4L2_YCBCR_ENC_BT2020_CONST_LUM: 530 case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
501 lin_y = (COEFF(0.2627, 255) * rec709_to_linear(r) + 531 lin_y = (COEFF(0.2627, 255) * rec709_to_linear(r) +
502 COEFF(0.6780, 255) * rec709_to_linear(g) + 532 COEFF(0.6780, 255) * rec709_to_linear(g) +
503 COEFF(0.0593, 255) * rec709_to_linear(b)) >> 16; 533 COEFF(0.0593, 255) * rec709_to_linear(b)) >> 16;
504 yc = linear_to_rec709(lin_y); 534 yc = linear_to_rec709(lin_y);
505 *y = (yc * 219) / 255 + (16 << 4); 535 *y = full ? yc : (yc * 219) / 255 + (16 << 4);
506 if (b <= yc) 536 if (b <= yc)
507 *cb = (((b - yc) * COEFF(1.0 / 1.9404, 224)) >> 16) + (128 << 4); 537 *cb = (((b - yc) * (full ? bt2020c_full[0] : bt2020c[0])) >> 16) + (128 << 4);
508 else 538 else
509 *cb = (((b - yc) * COEFF(1.0 / 1.5816, 224)) >> 16) + (128 << 4); 539 *cb = (((b - yc) * (full ? bt2020c_full[1] : bt2020c[1])) >> 16) + (128 << 4);
510 if (r <= yc) 540 if (r <= yc)
511 *cr = (((r - yc) * COEFF(1.0 / 1.7184, 224)) >> 16) + (128 << 4); 541 *cr = (((r - yc) * (full ? bt2020c_full[2] : bt2020c[2])) >> 16) + (128 << 4);
512 else 542 else
513 *cr = (((r - yc) * COEFF(1.0 / 0.9936, 224)) >> 16) + (128 << 4); 543 *cr = (((r - yc) * (full ? bt2020c_full[3] : bt2020c[3])) >> 16) + (128 << 4);
514 break; 544 break;
515 case V4L2_YCBCR_ENC_SMPTE240M: 545 case V4L2_YCBCR_ENC_SMPTE240M:
516 rgb2ycbcr(smpte240m, r, g, b, 16, y, cb, cr); 546 rgb2ycbcr(full ? smpte240m_full : smpte240m, r, g, b, y_offset, y, cb, cr);
517 break; 547 break;
518 case V4L2_YCBCR_ENC_709: 548 case V4L2_YCBCR_ENC_709:
519 case V4L2_YCBCR_ENC_XV709:
520 default: 549 default:
521 rgb2ycbcr(full ? rec709_full : rec709, r, g, b, y_offset, y, cb, cr); 550 rgb2ycbcr(full ? rec709_full : rec709, r, g, b, y_offset, y, cb, cr);
522 break; 551 break;
@@ -567,42 +596,71 @@ static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr,
567 { COEFF(1, 219), COEFF(-0.2253, 224), COEFF(-0.4767, 224) }, 596 { COEFF(1, 219), COEFF(-0.2253, 224), COEFF(-0.4767, 224) },
568 { COEFF(1, 219), COEFF(1.8270, 224), COEFF(0, 224) }, 597 { COEFF(1, 219), COEFF(1.8270, 224), COEFF(0, 224) },
569 }; 598 };
599 static const int smpte240m_full[3][3] = {
600 { COEFF(1, 255), COEFF(0, 255), COEFF(1.5756, 255) },
601 { COEFF(1, 255), COEFF(-0.2253, 255), COEFF(-0.4767, 255) },
602 { COEFF(1, 255), COEFF(1.8270, 255), COEFF(0, 255) },
603 };
570 static const int bt2020[3][3] = { 604 static const int bt2020[3][3] = {
571 { COEFF(1, 219), COEFF(0, 224), COEFF(1.4746, 224) }, 605 { COEFF(1, 219), COEFF(0, 224), COEFF(1.4746, 224) },
572 { COEFF(1, 219), COEFF(-0.1646, 224), COEFF(-0.5714, 224) }, 606 { COEFF(1, 219), COEFF(-0.1646, 224), COEFF(-0.5714, 224) },
573 { COEFF(1, 219), COEFF(1.8814, 224), COEFF(0, 224) }, 607 { COEFF(1, 219), COEFF(1.8814, 224), COEFF(0, 224) },
574 }; 608 };
609 static const int bt2020_full[3][3] = {
610 { COEFF(1, 255), COEFF(0, 255), COEFF(1.4746, 255) },
611 { COEFF(1, 255), COEFF(-0.1646, 255), COEFF(-0.5714, 255) },
612 { COEFF(1, 255), COEFF(1.8814, 255), COEFF(0, 255) },
613 };
614 static const int bt2020c[4] = {
615 COEFF(1.9404, 224), COEFF(1.5816, 224),
616 COEFF(1.7184, 224), COEFF(0.9936, 224),
617 };
618 static const int bt2020c_full[4] = {
619 COEFF(1.9404, 255), COEFF(1.5816, 255),
620 COEFF(1.7184, 255), COEFF(0.9936, 255),
621 };
622
575 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; 623 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE;
576 unsigned y_offset = full ? 0 : 16; 624 unsigned y_offset = full ? 0 : 16;
625 int y_fac = full ? COEFF(1.0, 255) : COEFF(1.0, 219);
577 int lin_r, lin_g, lin_b, lin_y; 626 int lin_r, lin_g, lin_b, lin_y;
578 627
579 switch (tpg->real_ycbcr_enc) { 628 switch (tpg->real_ycbcr_enc) {
580 case V4L2_YCBCR_ENC_601: 629 case V4L2_YCBCR_ENC_601:
581 case V4L2_YCBCR_ENC_XV601:
582 case V4L2_YCBCR_ENC_SYCC: 630 case V4L2_YCBCR_ENC_SYCC:
583 ycbcr2rgb(full ? bt601_full : bt601, y, cb, cr, y_offset, r, g, b); 631 ycbcr2rgb(full ? bt601_full : bt601, y, cb, cr, y_offset, r, g, b);
584 break; 632 break;
633 case V4L2_YCBCR_ENC_XV601:
634 /* Ignore quantization range, there is only one possible
635 * Y'CbCr encoding. */
636 ycbcr2rgb(bt601, y, cb, cr, 16, r, g, b);
637 break;
638 case V4L2_YCBCR_ENC_XV709:
639 /* Ignore quantization range, there is only one possible
640 * Y'CbCr encoding. */
641 ycbcr2rgb(rec709, y, cb, cr, 16, r, g, b);
642 break;
585 case V4L2_YCBCR_ENC_BT2020: 643 case V4L2_YCBCR_ENC_BT2020:
586 ycbcr2rgb(bt2020, y, cb, cr, 16, r, g, b); 644 ycbcr2rgb(full ? bt2020_full : bt2020, y, cb, cr, y_offset, r, g, b);
587 break; 645 break;
588 case V4L2_YCBCR_ENC_BT2020_CONST_LUM: 646 case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
589 y -= 16 << 4; 647 y -= full ? 0 : 16 << 4;
590 cb -= 128 << 4; 648 cb -= 128 << 4;
591 cr -= 128 << 4; 649 cr -= 128 << 4;
592 650
593 if (cb <= 0) 651 if (cb <= 0)
594 *b = COEFF(1.0, 219) * y + COEFF(1.9404, 224) * cb; 652 *b = y_fac * y + (full ? bt2020c_full[0] : bt2020c[0]) * cb;
595 else 653 else
596 *b = COEFF(1.0, 219) * y + COEFF(1.5816, 224) * cb; 654 *b = y_fac * y + (full ? bt2020c_full[1] : bt2020c[1]) * cb;
597 *b = *b >> 12; 655 *b = *b >> 12;
598 if (cr <= 0) 656 if (cr <= 0)
599 *r = COEFF(1.0, 219) * y + COEFF(1.7184, 224) * cr; 657 *r = y_fac * y + (full ? bt2020c_full[2] : bt2020c[2]) * cr;
600 else 658 else
601 *r = COEFF(1.0, 219) * y + COEFF(0.9936, 224) * cr; 659 *r = y_fac * y + (full ? bt2020c_full[3] : bt2020c[3]) * cr;
602 *r = *r >> 12; 660 *r = *r >> 12;
603 lin_r = rec709_to_linear(*r); 661 lin_r = rec709_to_linear(*r);
604 lin_b = rec709_to_linear(*b); 662 lin_b = rec709_to_linear(*b);
605 lin_y = rec709_to_linear((y * 255) / 219); 663 lin_y = rec709_to_linear((y * 255) / (full ? 255 : 219));
606 664
607 lin_g = COEFF(1.0 / 0.6780, 255) * lin_y - 665 lin_g = COEFF(1.0 / 0.6780, 255) * lin_y -
608 COEFF(0.2627 / 0.6780, 255) * lin_r - 666 COEFF(0.2627 / 0.6780, 255) * lin_r -
@@ -610,10 +668,9 @@ static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr,
610 *g = linear_to_rec709(lin_g >> 12); 668 *g = linear_to_rec709(lin_g >> 12);
611 break; 669 break;
612 case V4L2_YCBCR_ENC_SMPTE240M: 670 case V4L2_YCBCR_ENC_SMPTE240M:
613 ycbcr2rgb(smpte240m, y, cb, cr, 16, r, g, b); 671 ycbcr2rgb(full ? smpte240m_full : smpte240m, y, cb, cr, y_offset, r, g, b);
614 break; 672 break;
615 case V4L2_YCBCR_ENC_709: 673 case V4L2_YCBCR_ENC_709:
616 case V4L2_YCBCR_ENC_XV709:
617 default: 674 default:
618 ycbcr2rgb(full ? rec709_full : rec709, y, cb, cr, y_offset, r, g, b); 675 ycbcr2rgb(full ? rec709_full : rec709, y, cb, cr, y_offset, r, g, b);
619 break; 676 break;
@@ -649,15 +706,17 @@ static void precalculate_color(struct tpg_data *tpg, int k)
649 } 706 }
650 707
651 if (tpg->pattern == TPG_PAT_CSC_COLORBAR && col <= TPG_COLOR_CSC_BLACK) { 708 if (tpg->pattern == TPG_PAT_CSC_COLORBAR && col <= TPG_COLOR_CSC_BLACK) {
652 r = tpg_csc_colors[tpg->colorspace][col].r; 709 r = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].r;
653 g = tpg_csc_colors[tpg->colorspace][col].g; 710 g = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].g;
654 b = tpg_csc_colors[tpg->colorspace][col].b; 711 b = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].b;
655 } else { 712 } else {
656 r <<= 4; 713 r <<= 4;
657 g <<= 4; 714 g <<= 4;
658 b <<= 4; 715 b <<= 4;
659 } 716 }
660 if (tpg->qual == TPG_QUAL_GRAY || tpg->fourcc == V4L2_PIX_FMT_GREY) { 717 if (tpg->qual == TPG_QUAL_GRAY || tpg->fourcc == V4L2_PIX_FMT_GREY ||
718 tpg->fourcc == V4L2_PIX_FMT_Y16 ||
719 tpg->fourcc == V4L2_PIX_FMT_Y16_BE) {
661 /* Rec. 709 Luma function */ 720 /* Rec. 709 Luma function */
662 /* (0.2126, 0.7152, 0.0722) * (255 * 256) */ 721 /* (0.2126, 0.7152, 0.0722) * (255 * 256) */
663 r = g = b = (13879 * r + 46688 * g + 4713 * b) >> 16; 722 r = g = b = (13879 * r + 46688 * g + 4713 * b) >> 16;
@@ -840,6 +899,21 @@ static void gen_twopix(struct tpg_data *tpg,
840 case V4L2_PIX_FMT_GREY: 899 case V4L2_PIX_FMT_GREY:
841 buf[0][offset] = r_y; 900 buf[0][offset] = r_y;
842 break; 901 break;
902 case V4L2_PIX_FMT_Y16:
903 /*
904 * Ideally both bytes should be set to r_y, but then you won't
905 * be able to detect endian problems. So keep it 0 except for
906 * the corner case where r_y is 0xff so white really will be
907 * white (0xffff).
908 */
909 buf[0][offset] = r_y == 0xff ? r_y : 0;
910 buf[0][offset+1] = r_y;
911 break;
912 case V4L2_PIX_FMT_Y16_BE:
913 /* See comment for V4L2_PIX_FMT_Y16 above */
914 buf[0][offset] = r_y;
915 buf[0][offset+1] = r_y == 0xff ? r_y : 0;
916 break;
843 case V4L2_PIX_FMT_YUV422P: 917 case V4L2_PIX_FMT_YUV422P:
844 case V4L2_PIX_FMT_YUV420: 918 case V4L2_PIX_FMT_YUV420:
845 case V4L2_PIX_FMT_YUV420M: 919 case V4L2_PIX_FMT_YUV420M:
@@ -1395,42 +1469,10 @@ static void tpg_precalculate_line(struct tpg_data *tpg)
1395/* need this to do rgb24 rendering */ 1469/* need this to do rgb24 rendering */
1396typedef struct { u16 __; u8 _; } __packed x24; 1470typedef struct { u16 __; u8 _; } __packed x24;
1397 1471
1398void tpg_gen_text(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1399 int y, int x, char *text)
1400{
1401 int line;
1402 unsigned step = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1;
1403 unsigned div = step;
1404 unsigned first = 0;
1405 unsigned len = strlen(text);
1406 unsigned p;
1407
1408 if (font8x16 == NULL || basep == NULL)
1409 return;
1410
1411 /* Checks if it is possible to show string */
1412 if (y + 16 >= tpg->compose.height || x + 8 >= tpg->compose.width)
1413 return;
1414
1415 if (len > (tpg->compose.width - x) / 8)
1416 len = (tpg->compose.width - x) / 8;
1417 if (tpg->vflip)
1418 y = tpg->compose.height - y - 16;
1419 if (tpg->hflip)
1420 x = tpg->compose.width - x - 8;
1421 y += tpg->compose.top;
1422 x += tpg->compose.left;
1423 if (tpg->field == V4L2_FIELD_BOTTOM)
1424 first = 1;
1425 else if (tpg->field == V4L2_FIELD_SEQ_TB || tpg->field == V4L2_FIELD_SEQ_BT)
1426 div = 2;
1427
1428 for (p = 0; p < tpg->planes; p++) {
1429 unsigned vdiv = tpg->vdownsampling[p];
1430 unsigned hdiv = tpg->hdownsampling[p];
1431
1432 /* Print text */
1433#define PRINTSTR(PIXTYPE) do { \ 1472#define PRINTSTR(PIXTYPE) do { \
1473 unsigned vdiv = tpg->vdownsampling[p]; \
1474 unsigned hdiv = tpg->hdownsampling[p]; \
1475 int line; \
1434 PIXTYPE fg; \ 1476 PIXTYPE fg; \
1435 PIXTYPE bg; \ 1477 PIXTYPE bg; \
1436 memcpy(&fg, tpg->textfg[p], sizeof(PIXTYPE)); \ 1478 memcpy(&fg, tpg->textfg[p], sizeof(PIXTYPE)); \
@@ -1481,15 +1523,82 @@ void tpg_gen_text(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1481 } \ 1523 } \
1482} while (0) 1524} while (0)
1483 1525
1526static noinline void tpg_print_str_2(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1527 unsigned p, unsigned first, unsigned div, unsigned step,
1528 int y, int x, char *text, unsigned len)
1529{
1530 PRINTSTR(u8);
1531}
1532
1533static noinline void tpg_print_str_4(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1534 unsigned p, unsigned first, unsigned div, unsigned step,
1535 int y, int x, char *text, unsigned len)
1536{
1537 PRINTSTR(u16);
1538}
1539
1540static noinline void tpg_print_str_6(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1541 unsigned p, unsigned first, unsigned div, unsigned step,
1542 int y, int x, char *text, unsigned len)
1543{
1544 PRINTSTR(x24);
1545}
1546
1547static noinline void tpg_print_str_8(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1548 unsigned p, unsigned first, unsigned div, unsigned step,
1549 int y, int x, char *text, unsigned len)
1550{
1551 PRINTSTR(u32);
1552}
1553
1554void tpg_gen_text(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1555 int y, int x, char *text)
1556{
1557 unsigned step = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1;
1558 unsigned div = step;
1559 unsigned first = 0;
1560 unsigned len = strlen(text);
1561 unsigned p;
1562
1563 if (font8x16 == NULL || basep == NULL)
1564 return;
1565
1566 /* Checks if it is possible to show string */
1567 if (y + 16 >= tpg->compose.height || x + 8 >= tpg->compose.width)
1568 return;
1569
1570 if (len > (tpg->compose.width - x) / 8)
1571 len = (tpg->compose.width - x) / 8;
1572 if (tpg->vflip)
1573 y = tpg->compose.height - y - 16;
1574 if (tpg->hflip)
1575 x = tpg->compose.width - x - 8;
1576 y += tpg->compose.top;
1577 x += tpg->compose.left;
1578 if (tpg->field == V4L2_FIELD_BOTTOM)
1579 first = 1;
1580 else if (tpg->field == V4L2_FIELD_SEQ_TB || tpg->field == V4L2_FIELD_SEQ_BT)
1581 div = 2;
1582
1583 for (p = 0; p < tpg->planes; p++) {
1584 /* Print text */
1484 switch (tpg->twopixelsize[p]) { 1585 switch (tpg->twopixelsize[p]) {
1485 case 2: 1586 case 2:
1486 PRINTSTR(u8); break; 1587 tpg_print_str_2(tpg, basep, p, first, div, step, y, x,
1588 text, len);
1589 break;
1487 case 4: 1590 case 4:
1488 PRINTSTR(u16); break; 1591 tpg_print_str_4(tpg, basep, p, first, div, step, y, x,
1592 text, len);
1593 break;
1489 case 6: 1594 case 6:
1490 PRINTSTR(x24); break; 1595 tpg_print_str_6(tpg, basep, p, first, div, step, y, x,
1596 text, len);
1597 break;
1491 case 8: 1598 case 8:
1492 PRINTSTR(u32); break; 1599 tpg_print_str_8(tpg, basep, p, first, div, step, y, x,
1600 text, len);
1601 break;
1493 } 1602 }
1494 } 1603 }
1495} 1604}
@@ -1583,50 +1692,23 @@ static void tpg_recalc(struct tpg_data *tpg)
1583 if (tpg->recalc_colors) { 1692 if (tpg->recalc_colors) {
1584 tpg->recalc_colors = false; 1693 tpg->recalc_colors = false;
1585 tpg->recalc_lines = true; 1694 tpg->recalc_lines = true;
1695 tpg->real_xfer_func = tpg->xfer_func;
1586 tpg->real_ycbcr_enc = tpg->ycbcr_enc; 1696 tpg->real_ycbcr_enc = tpg->ycbcr_enc;
1587 tpg->real_quantization = tpg->quantization; 1697 tpg->real_quantization = tpg->quantization;
1588 if (tpg->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) { 1698
1589 switch (tpg->colorspace) { 1699 if (tpg->xfer_func == V4L2_XFER_FUNC_DEFAULT)
1590 case V4L2_COLORSPACE_REC709: 1700 tpg->real_xfer_func =
1591 tpg->real_ycbcr_enc = V4L2_YCBCR_ENC_709; 1701 V4L2_MAP_XFER_FUNC_DEFAULT(tpg->colorspace);
1592 break; 1702
1593 case V4L2_COLORSPACE_SRGB: 1703 if (tpg->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
1594 tpg->real_ycbcr_enc = V4L2_YCBCR_ENC_SYCC; 1704 tpg->real_ycbcr_enc =
1595 break; 1705 V4L2_MAP_YCBCR_ENC_DEFAULT(tpg->colorspace);
1596 case V4L2_COLORSPACE_BT2020: 1706
1597 tpg->real_ycbcr_enc = V4L2_YCBCR_ENC_BT2020; 1707 if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT)
1598 break; 1708 tpg->real_quantization =
1599 case V4L2_COLORSPACE_SMPTE240M: 1709 V4L2_MAP_QUANTIZATION_DEFAULT(!tpg->is_yuv,
1600 tpg->real_ycbcr_enc = V4L2_YCBCR_ENC_SMPTE240M; 1710 tpg->colorspace, tpg->real_ycbcr_enc);
1601 break; 1711
1602 case V4L2_COLORSPACE_SMPTE170M:
1603 case V4L2_COLORSPACE_470_SYSTEM_M:
1604 case V4L2_COLORSPACE_470_SYSTEM_BG:
1605 case V4L2_COLORSPACE_ADOBERGB:
1606 default:
1607 tpg->real_ycbcr_enc = V4L2_YCBCR_ENC_601;
1608 break;
1609 }
1610 }
1611 if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT) {
1612 tpg->real_quantization = V4L2_QUANTIZATION_FULL_RANGE;
1613 if (tpg->is_yuv) {
1614 switch (tpg->real_ycbcr_enc) {
1615 case V4L2_YCBCR_ENC_SYCC:
1616 case V4L2_YCBCR_ENC_XV601:
1617 case V4L2_YCBCR_ENC_XV709:
1618 break;
1619 default:
1620 tpg->real_quantization =
1621 V4L2_QUANTIZATION_LIM_RANGE;
1622 break;
1623 }
1624 } else if (tpg->colorspace == V4L2_COLORSPACE_BT2020) {
1625 /* R'G'B' BT.2020 is limited range */
1626 tpg->real_quantization =
1627 V4L2_QUANTIZATION_LIM_RANGE;
1628 }
1629 }
1630 tpg_precalculate_colors(tpg); 1712 tpg_precalculate_colors(tpg);
1631 } 1713 }
1632 if (tpg->recalc_square_border) { 1714 if (tpg->recalc_square_border) {
@@ -1670,6 +1752,23 @@ static int tpg_pattern_avg(const struct tpg_data *tpg,
1670 return -1; 1752 return -1;
1671} 1753}
1672 1754
1755void tpg_log_status(struct tpg_data *tpg)
1756{
1757 pr_info("tpg source WxH: %ux%u (%s)\n",
1758 tpg->src_width, tpg->src_height,
1759 tpg->is_yuv ? "YCbCr" : "RGB");
1760 pr_info("tpg field: %u\n", tpg->field);
1761 pr_info("tpg crop: %ux%u@%dx%d\n", tpg->crop.width, tpg->crop.height,
1762 tpg->crop.left, tpg->crop.top);
1763 pr_info("tpg compose: %ux%u@%dx%d\n", tpg->compose.width, tpg->compose.height,
1764 tpg->compose.left, tpg->compose.top);
1765 pr_info("tpg colorspace: %d\n", tpg->colorspace);
1766 pr_info("tpg transfer function: %d/%d\n", tpg->xfer_func, tpg->real_xfer_func);
1767 pr_info("tpg Y'CbCr encoding: %d/%d\n", tpg->ycbcr_enc, tpg->real_ycbcr_enc);
1768 pr_info("tpg quantization: %d/%d\n", tpg->quantization, tpg->real_quantization);
1769 pr_info("tpg RGB range: %d/%d\n", tpg->rgb_range, tpg->real_rgb_range);
1770}
1771
1673/* 1772/*
1674 * This struct contains common parameters used by both the drawing of the 1773 * This struct contains common parameters used by both the drawing of the
1675 * test pattern and the drawing of the extras (borders, square, etc.) 1774 * test pattern and the drawing of the extras (borders, square, etc.)
diff --git a/drivers/media/platform/vivid/vivid-tpg.h b/drivers/media/platform/vivid/vivid-tpg.h
index a50cd2e2535b..9baed6a10334 100644
--- a/drivers/media/platform/vivid/vivid-tpg.h
+++ b/drivers/media/platform/vivid/vivid-tpg.h
@@ -122,8 +122,14 @@ struct tpg_data {
122 u32 fourcc; 122 u32 fourcc;
123 bool is_yuv; 123 bool is_yuv;
124 u32 colorspace; 124 u32 colorspace;
125 u32 xfer_func;
125 u32 ycbcr_enc; 126 u32 ycbcr_enc;
126 /* 127 /*
128 * Stores the actual transfer function, i.e. will never be
129 * V4L2_XFER_FUNC_DEFAULT.
130 */
131 u32 real_xfer_func;
132 /*
127 * Stores the actual Y'CbCr encoding, i.e. will never be 133 * Stores the actual Y'CbCr encoding, i.e. will never be
128 * V4L2_YCBCR_ENC_DEFAULT. 134 * V4L2_YCBCR_ENC_DEFAULT.
129 */ 135 */
@@ -192,6 +198,7 @@ int tpg_alloc(struct tpg_data *tpg, unsigned max_w);
192void tpg_free(struct tpg_data *tpg); 198void tpg_free(struct tpg_data *tpg);
193void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height, 199void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height,
194 u32 field); 200 u32 field);
201void tpg_log_status(struct tpg_data *tpg);
195 202
196void tpg_set_font(const u8 *f); 203void tpg_set_font(const u8 *f);
197void tpg_gen_text(const struct tpg_data *tpg, 204void tpg_gen_text(const struct tpg_data *tpg,
@@ -328,6 +335,19 @@ static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg)
328 return tpg->ycbcr_enc; 335 return tpg->ycbcr_enc;
329} 336}
330 337
338static inline void tpg_s_xfer_func(struct tpg_data *tpg, u32 xfer_func)
339{
340 if (tpg->xfer_func == xfer_func)
341 return;
342 tpg->xfer_func = xfer_func;
343 tpg->recalc_colors = true;
344}
345
346static inline u32 tpg_g_xfer_func(const struct tpg_data *tpg)
347{
348 return tpg->xfer_func;
349}
350
331static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization) 351static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization)
332{ 352{
333 if (tpg->quantization == quantization) 353 if (tpg->quantization == quantization)
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index dab5990f45a0..c4268d1b2f82 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -40,7 +40,6 @@ static const struct v4l2_fract
40 40
41static const struct vivid_fmt formats_ovl[] = { 41static const struct vivid_fmt formats_ovl[] = {
42 { 42 {
43 .name = "RGB565 (LE)",
44 .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */ 43 .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */
45 .vdownsampling = { 1 }, 44 .vdownsampling = { 1 },
46 .bit_depth = { 16 }, 45 .bit_depth = { 16 },
@@ -48,7 +47,6 @@ static const struct vivid_fmt formats_ovl[] = {
48 .buffers = 1, 47 .buffers = 1,
49 }, 48 },
50 { 49 {
51 .name = "XRGB555 (LE)",
52 .fourcc = V4L2_PIX_FMT_XRGB555, /* gggbbbbb arrrrrgg */ 50 .fourcc = V4L2_PIX_FMT_XRGB555, /* gggbbbbb arrrrrgg */
53 .vdownsampling = { 1 }, 51 .vdownsampling = { 1 },
54 .bit_depth = { 16 }, 52 .bit_depth = { 16 },
@@ -56,7 +54,6 @@ static const struct vivid_fmt formats_ovl[] = {
56 .buffers = 1, 54 .buffers = 1,
57 }, 55 },
58 { 56 {
59 .name = "ARGB555 (LE)",
60 .fourcc = V4L2_PIX_FMT_ARGB555, /* gggbbbbb arrrrrgg */ 57 .fourcc = V4L2_PIX_FMT_ARGB555, /* gggbbbbb arrrrrgg */
61 .vdownsampling = { 1 }, 58 .vdownsampling = { 1 },
62 .bit_depth = { 16 }, 59 .bit_depth = { 16 },
@@ -66,7 +63,7 @@ static const struct vivid_fmt formats_ovl[] = {
66}; 63};
67 64
68/* The number of discrete webcam framesizes */ 65/* The number of discrete webcam framesizes */
69#define VIVID_WEBCAM_SIZES 3 66#define VIVID_WEBCAM_SIZES 4
70/* The number of discrete webcam frameintervals */ 67/* The number of discrete webcam frameintervals */
71#define VIVID_WEBCAM_IVALS (VIVID_WEBCAM_SIZES * 2) 68#define VIVID_WEBCAM_IVALS (VIVID_WEBCAM_SIZES * 2)
72 69
@@ -75,6 +72,7 @@ static const struct v4l2_frmsize_discrete webcam_sizes[VIVID_WEBCAM_SIZES] = {
75 { 320, 180 }, 72 { 320, 180 },
76 { 640, 360 }, 73 { 640, 360 },
77 { 1280, 720 }, 74 { 1280, 720 },
75 { 1920, 1080 },
78}; 76};
79 77
80/* 78/*
@@ -82,6 +80,8 @@ static const struct v4l2_frmsize_discrete webcam_sizes[VIVID_WEBCAM_SIZES] = {
82 * elements in this array as there are in webcam_sizes. 80 * elements in this array as there are in webcam_sizes.
83 */ 81 */
84static const struct v4l2_fract webcam_intervals[VIVID_WEBCAM_IVALS] = { 82static const struct v4l2_fract webcam_intervals[VIVID_WEBCAM_IVALS] = {
83 { 1, 2 },
84 { 1, 5 },
85 { 1, 10 }, 85 { 1, 10 },
86 { 1, 15 }, 86 { 1, 15 },
87 { 1, 25 }, 87 { 1, 25 },
@@ -501,6 +501,13 @@ static unsigned vivid_colorspace_cap(struct vivid_dev *dev)
501 return dev->colorspace_out; 501 return dev->colorspace_out;
502} 502}
503 503
504static unsigned vivid_xfer_func_cap(struct vivid_dev *dev)
505{
506 if (!dev->loop_video || vivid_is_webcam(dev) || vivid_is_tv_cap(dev))
507 return tpg_g_xfer_func(&dev->tpg);
508 return dev->xfer_func_out;
509}
510
504static unsigned vivid_ycbcr_enc_cap(struct vivid_dev *dev) 511static unsigned vivid_ycbcr_enc_cap(struct vivid_dev *dev)
505{ 512{
506 if (!dev->loop_video || vivid_is_webcam(dev) || vivid_is_tv_cap(dev)) 513 if (!dev->loop_video || vivid_is_webcam(dev) || vivid_is_tv_cap(dev))
@@ -527,6 +534,7 @@ int vivid_g_fmt_vid_cap(struct file *file, void *priv,
527 mp->field = dev->field_cap; 534 mp->field = dev->field_cap;
528 mp->pixelformat = dev->fmt_cap->fourcc; 535 mp->pixelformat = dev->fmt_cap->fourcc;
529 mp->colorspace = vivid_colorspace_cap(dev); 536 mp->colorspace = vivid_colorspace_cap(dev);
537 mp->xfer_func = vivid_xfer_func_cap(dev);
530 mp->ycbcr_enc = vivid_ycbcr_enc_cap(dev); 538 mp->ycbcr_enc = vivid_ycbcr_enc_cap(dev);
531 mp->quantization = vivid_quantization_cap(dev); 539 mp->quantization = vivid_quantization_cap(dev);
532 mp->num_planes = dev->fmt_cap->buffers; 540 mp->num_planes = dev->fmt_cap->buffers;
@@ -616,6 +624,7 @@ int vivid_try_fmt_vid_cap(struct file *file, void *priv,
616 } 624 }
617 mp->colorspace = vivid_colorspace_cap(dev); 625 mp->colorspace = vivid_colorspace_cap(dev);
618 mp->ycbcr_enc = vivid_ycbcr_enc_cap(dev); 626 mp->ycbcr_enc = vivid_ycbcr_enc_cap(dev);
627 mp->xfer_func = vivid_xfer_func_cap(dev);
619 mp->quantization = vivid_quantization_cap(dev); 628 mp->quantization = vivid_quantization_cap(dev);
620 memset(mp->reserved, 0, sizeof(mp->reserved)); 629 memset(mp->reserved, 0, sizeof(mp->reserved));
621 return 0; 630 return 0;
@@ -720,8 +729,8 @@ int vivid_s_fmt_vid_cap(struct file *file, void *priv,
720 webcam_sizes[i].height == mp->height) 729 webcam_sizes[i].height == mp->height)
721 break; 730 break;
722 dev->webcam_size_idx = i; 731 dev->webcam_size_idx = i;
723 if (dev->webcam_ival_idx >= 2 * (3 - i)) 732 if (dev->webcam_ival_idx >= 2 * (VIVID_WEBCAM_SIZES - i))
724 dev->webcam_ival_idx = 2 * (3 - i) - 1; 733 dev->webcam_ival_idx = 2 * (VIVID_WEBCAM_SIZES - i) - 1;
725 vivid_update_format_cap(dev, false); 734 vivid_update_format_cap(dev, false);
726 } else { 735 } else {
727 struct v4l2_rect r = { 0, 0, mp->width, mp->height }; 736 struct v4l2_rect r = { 0, 0, mp->width, mp->height };
@@ -1030,7 +1039,6 @@ int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
1030 1039
1031 fmt = &formats_ovl[f->index]; 1040 fmt = &formats_ovl[f->index];
1032 1041
1033 strlcpy(f->description, fmt->name, sizeof(f->description));
1034 f->pixelformat = fmt->fourcc; 1042 f->pixelformat = fmt->fourcc;
1035 return 0; 1043 return 0;
1036} 1044}
@@ -1620,7 +1628,7 @@ static bool valid_cvt_gtf_timings(struct v4l2_dv_timings *timings)
1620 1628
1621 if (bt->standards == 0 || (bt->standards & V4L2_DV_BT_STD_CVT)) { 1629 if (bt->standards == 0 || (bt->standards & V4L2_DV_BT_STD_CVT)) {
1622 if (v4l2_detect_cvt(total_v_lines, h_freq, bt->vsync, 1630 if (v4l2_detect_cvt(total_v_lines, h_freq, bt->vsync,
1623 bt->polarities, timings)) 1631 bt->polarities, bt->interlaced, timings))
1624 return true; 1632 return true;
1625 } 1633 }
1626 1634
@@ -1631,7 +1639,8 @@ static bool valid_cvt_gtf_timings(struct v4l2_dv_timings *timings)
1631 &aspect_ratio.numerator, 1639 &aspect_ratio.numerator,
1632 &aspect_ratio.denominator); 1640 &aspect_ratio.denominator);
1633 if (v4l2_detect_gtf(total_v_lines, h_freq, bt->vsync, 1641 if (v4l2_detect_gtf(total_v_lines, h_freq, bt->vsync,
1634 bt->polarities, aspect_ratio, timings)) 1642 bt->polarities, bt->interlaced,
1643 aspect_ratio, timings))
1635 return true; 1644 return true;
1636 } 1645 }
1637 return false; 1646 return false;
@@ -1768,7 +1777,7 @@ int vidioc_enum_frameintervals(struct file *file, void *priv,
1768 break; 1777 break;
1769 if (i == ARRAY_SIZE(webcam_sizes)) 1778 if (i == ARRAY_SIZE(webcam_sizes))
1770 return -EINVAL; 1779 return -EINVAL;
1771 if (fival->index >= 2 * (3 - i)) 1780 if (fival->index >= 2 * (VIVID_WEBCAM_SIZES - i))
1772 return -EINVAL; 1781 return -EINVAL;
1773 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; 1782 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
1774 fival->discrete = webcam_intervals[fival->index]; 1783 fival->discrete = webcam_intervals[fival->index];
@@ -1798,7 +1807,7 @@ int vivid_vid_cap_s_parm(struct file *file, void *priv,
1798 struct v4l2_streamparm *parm) 1807 struct v4l2_streamparm *parm)
1799{ 1808{
1800 struct vivid_dev *dev = video_drvdata(file); 1809 struct vivid_dev *dev = video_drvdata(file);
1801 unsigned ival_sz = 2 * (3 - dev->webcam_size_idx); 1810 unsigned ival_sz = 2 * (VIVID_WEBCAM_SIZES - dev->webcam_size_idx);
1802 struct v4l2_fract tpf; 1811 struct v4l2_fract tpf;
1803 unsigned i; 1812 unsigned i;
1804 1813
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index aa446271ad34..fc73927a4abc 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -45,7 +45,6 @@ const struct v4l2_dv_timings_cap vivid_dv_timings_cap = {
45 45
46struct vivid_fmt vivid_formats[] = { 46struct vivid_fmt vivid_formats[] = {
47 { 47 {
48 .name = "4:2:2, packed, YUYV",
49 .fourcc = V4L2_PIX_FMT_YUYV, 48 .fourcc = V4L2_PIX_FMT_YUYV,
50 .vdownsampling = { 1 }, 49 .vdownsampling = { 1 },
51 .bit_depth = { 16 }, 50 .bit_depth = { 16 },
@@ -55,7 +54,6 @@ struct vivid_fmt vivid_formats[] = {
55 .data_offset = { PLANE0_DATA_OFFSET }, 54 .data_offset = { PLANE0_DATA_OFFSET },
56 }, 55 },
57 { 56 {
58 .name = "4:2:2, packed, UYVY",
59 .fourcc = V4L2_PIX_FMT_UYVY, 57 .fourcc = V4L2_PIX_FMT_UYVY,
60 .vdownsampling = { 1 }, 58 .vdownsampling = { 1 },
61 .bit_depth = { 16 }, 59 .bit_depth = { 16 },
@@ -64,7 +62,6 @@ struct vivid_fmt vivid_formats[] = {
64 .buffers = 1, 62 .buffers = 1,
65 }, 63 },
66 { 64 {
67 .name = "4:2:2, packed, YVYU",
68 .fourcc = V4L2_PIX_FMT_YVYU, 65 .fourcc = V4L2_PIX_FMT_YVYU,
69 .vdownsampling = { 1 }, 66 .vdownsampling = { 1 },
70 .bit_depth = { 16 }, 67 .bit_depth = { 16 },
@@ -73,7 +70,6 @@ struct vivid_fmt vivid_formats[] = {
73 .buffers = 1, 70 .buffers = 1,
74 }, 71 },
75 { 72 {
76 .name = "4:2:2, packed, VYUY",
77 .fourcc = V4L2_PIX_FMT_VYUY, 73 .fourcc = V4L2_PIX_FMT_VYUY,
78 .vdownsampling = { 1 }, 74 .vdownsampling = { 1 },
79 .bit_depth = { 16 }, 75 .bit_depth = { 16 },
@@ -82,7 +78,6 @@ struct vivid_fmt vivid_formats[] = {
82 .buffers = 1, 78 .buffers = 1,
83 }, 79 },
84 { 80 {
85 .name = "YUV 4:2:2 triplanar",
86 .fourcc = V4L2_PIX_FMT_YUV422P, 81 .fourcc = V4L2_PIX_FMT_YUV422P,
87 .vdownsampling = { 1, 1, 1 }, 82 .vdownsampling = { 1, 1, 1 },
88 .bit_depth = { 8, 4, 4 }, 83 .bit_depth = { 8, 4, 4 },
@@ -91,7 +86,6 @@ struct vivid_fmt vivid_formats[] = {
91 .buffers = 1, 86 .buffers = 1,
92 }, 87 },
93 { 88 {
94 .name = "YUV 4:2:0 triplanar",
95 .fourcc = V4L2_PIX_FMT_YUV420, 89 .fourcc = V4L2_PIX_FMT_YUV420,
96 .vdownsampling = { 1, 2, 2 }, 90 .vdownsampling = { 1, 2, 2 },
97 .bit_depth = { 8, 4, 4 }, 91 .bit_depth = { 8, 4, 4 },
@@ -100,7 +94,6 @@ struct vivid_fmt vivid_formats[] = {
100 .buffers = 1, 94 .buffers = 1,
101 }, 95 },
102 { 96 {
103 .name = "YVU 4:2:0 triplanar",
104 .fourcc = V4L2_PIX_FMT_YVU420, 97 .fourcc = V4L2_PIX_FMT_YVU420,
105 .vdownsampling = { 1, 2, 2 }, 98 .vdownsampling = { 1, 2, 2 },
106 .bit_depth = { 8, 4, 4 }, 99 .bit_depth = { 8, 4, 4 },
@@ -109,7 +102,6 @@ struct vivid_fmt vivid_formats[] = {
109 .buffers = 1, 102 .buffers = 1,
110 }, 103 },
111 { 104 {
112 .name = "YUV 4:2:0 biplanar",
113 .fourcc = V4L2_PIX_FMT_NV12, 105 .fourcc = V4L2_PIX_FMT_NV12,
114 .vdownsampling = { 1, 2 }, 106 .vdownsampling = { 1, 2 },
115 .bit_depth = { 8, 8 }, 107 .bit_depth = { 8, 8 },
@@ -118,7 +110,6 @@ struct vivid_fmt vivid_formats[] = {
118 .buffers = 1, 110 .buffers = 1,
119 }, 111 },
120 { 112 {
121 .name = "YVU 4:2:0 biplanar",
122 .fourcc = V4L2_PIX_FMT_NV21, 113 .fourcc = V4L2_PIX_FMT_NV21,
123 .vdownsampling = { 1, 2 }, 114 .vdownsampling = { 1, 2 },
124 .bit_depth = { 8, 8 }, 115 .bit_depth = { 8, 8 },
@@ -127,7 +118,6 @@ struct vivid_fmt vivid_formats[] = {
127 .buffers = 1, 118 .buffers = 1,
128 }, 119 },
129 { 120 {
130 .name = "YUV 4:2:2 biplanar",
131 .fourcc = V4L2_PIX_FMT_NV16, 121 .fourcc = V4L2_PIX_FMT_NV16,
132 .vdownsampling = { 1, 1 }, 122 .vdownsampling = { 1, 1 },
133 .bit_depth = { 8, 8 }, 123 .bit_depth = { 8, 8 },
@@ -136,7 +126,6 @@ struct vivid_fmt vivid_formats[] = {
136 .buffers = 1, 126 .buffers = 1,
137 }, 127 },
138 { 128 {
139 .name = "YVU 4:2:2 biplanar",
140 .fourcc = V4L2_PIX_FMT_NV61, 129 .fourcc = V4L2_PIX_FMT_NV61,
141 .vdownsampling = { 1, 1 }, 130 .vdownsampling = { 1, 1 },
142 .bit_depth = { 8, 8 }, 131 .bit_depth = { 8, 8 },
@@ -145,7 +134,6 @@ struct vivid_fmt vivid_formats[] = {
145 .buffers = 1, 134 .buffers = 1,
146 }, 135 },
147 { 136 {
148 .name = "YUV 4:4:4 biplanar",
149 .fourcc = V4L2_PIX_FMT_NV24, 137 .fourcc = V4L2_PIX_FMT_NV24,
150 .vdownsampling = { 1, 1 }, 138 .vdownsampling = { 1, 1 },
151 .bit_depth = { 8, 16 }, 139 .bit_depth = { 8, 16 },
@@ -154,7 +142,6 @@ struct vivid_fmt vivid_formats[] = {
154 .buffers = 1, 142 .buffers = 1,
155 }, 143 },
156 { 144 {
157 .name = "YVU 4:4:4 biplanar",
158 .fourcc = V4L2_PIX_FMT_NV42, 145 .fourcc = V4L2_PIX_FMT_NV42,
159 .vdownsampling = { 1, 1 }, 146 .vdownsampling = { 1, 1 },
160 .bit_depth = { 8, 16 }, 147 .bit_depth = { 8, 16 },
@@ -163,7 +150,6 @@ struct vivid_fmt vivid_formats[] = {
163 .buffers = 1, 150 .buffers = 1,
164 }, 151 },
165 { 152 {
166 .name = "YUV555 (LE)",
167 .fourcc = V4L2_PIX_FMT_YUV555, /* uuuvvvvv ayyyyyuu */ 153 .fourcc = V4L2_PIX_FMT_YUV555, /* uuuvvvvv ayyyyyuu */
168 .vdownsampling = { 1 }, 154 .vdownsampling = { 1 },
169 .bit_depth = { 16 }, 155 .bit_depth = { 16 },
@@ -172,7 +158,6 @@ struct vivid_fmt vivid_formats[] = {
172 .alpha_mask = 0x8000, 158 .alpha_mask = 0x8000,
173 }, 159 },
174 { 160 {
175 .name = "YUV565 (LE)",
176 .fourcc = V4L2_PIX_FMT_YUV565, /* uuuvvvvv yyyyyuuu */ 161 .fourcc = V4L2_PIX_FMT_YUV565, /* uuuvvvvv yyyyyuuu */
177 .vdownsampling = { 1 }, 162 .vdownsampling = { 1 },
178 .bit_depth = { 16 }, 163 .bit_depth = { 16 },
@@ -180,7 +165,6 @@ struct vivid_fmt vivid_formats[] = {
180 .buffers = 1, 165 .buffers = 1,
181 }, 166 },
182 { 167 {
183 .name = "YUV444",
184 .fourcc = V4L2_PIX_FMT_YUV444, /* uuuuvvvv aaaayyyy */ 168 .fourcc = V4L2_PIX_FMT_YUV444, /* uuuuvvvv aaaayyyy */
185 .vdownsampling = { 1 }, 169 .vdownsampling = { 1 },
186 .bit_depth = { 16 }, 170 .bit_depth = { 16 },
@@ -189,7 +173,6 @@ struct vivid_fmt vivid_formats[] = {
189 .alpha_mask = 0xf000, 173 .alpha_mask = 0xf000,
190 }, 174 },
191 { 175 {
192 .name = "YUV32 (LE)",
193 .fourcc = V4L2_PIX_FMT_YUV32, /* ayuv */ 176 .fourcc = V4L2_PIX_FMT_YUV32, /* ayuv */
194 .vdownsampling = { 1 }, 177 .vdownsampling = { 1 },
195 .bit_depth = { 32 }, 178 .bit_depth = { 32 },
@@ -198,7 +181,6 @@ struct vivid_fmt vivid_formats[] = {
198 .alpha_mask = 0x000000ff, 181 .alpha_mask = 0x000000ff,
199 }, 182 },
200 { 183 {
201 .name = "Monochrome",
202 .fourcc = V4L2_PIX_FMT_GREY, 184 .fourcc = V4L2_PIX_FMT_GREY,
203 .vdownsampling = { 1 }, 185 .vdownsampling = { 1 },
204 .bit_depth = { 8 }, 186 .bit_depth = { 8 },
@@ -207,7 +189,22 @@ struct vivid_fmt vivid_formats[] = {
207 .buffers = 1, 189 .buffers = 1,
208 }, 190 },
209 { 191 {
210 .name = "RGB332", 192 .fourcc = V4L2_PIX_FMT_Y16,
193 .vdownsampling = { 1 },
194 .bit_depth = { 16 },
195 .is_yuv = true,
196 .planes = 1,
197 .buffers = 1,
198 },
199 {
200 .fourcc = V4L2_PIX_FMT_Y16_BE,
201 .vdownsampling = { 1 },
202 .bit_depth = { 16 },
203 .is_yuv = true,
204 .planes = 1,
205 .buffers = 1,
206 },
207 {
211 .fourcc = V4L2_PIX_FMT_RGB332, /* rrrgggbb */ 208 .fourcc = V4L2_PIX_FMT_RGB332, /* rrrgggbb */
212 .vdownsampling = { 1 }, 209 .vdownsampling = { 1 },
213 .bit_depth = { 8 }, 210 .bit_depth = { 8 },
@@ -215,7 +212,6 @@ struct vivid_fmt vivid_formats[] = {
215 .buffers = 1, 212 .buffers = 1,
216 }, 213 },
217 { 214 {
218 .name = "RGB565 (LE)",
219 .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */ 215 .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */
220 .vdownsampling = { 1 }, 216 .vdownsampling = { 1 },
221 .bit_depth = { 16 }, 217 .bit_depth = { 16 },
@@ -224,7 +220,6 @@ struct vivid_fmt vivid_formats[] = {
224 .can_do_overlay = true, 220 .can_do_overlay = true,
225 }, 221 },
226 { 222 {
227 .name = "RGB565 (BE)",
228 .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */ 223 .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
229 .vdownsampling = { 1 }, 224 .vdownsampling = { 1 },
230 .bit_depth = { 16 }, 225 .bit_depth = { 16 },
@@ -233,7 +228,6 @@ struct vivid_fmt vivid_formats[] = {
233 .can_do_overlay = true, 228 .can_do_overlay = true,
234 }, 229 },
235 { 230 {
236 .name = "RGB444",
237 .fourcc = V4L2_PIX_FMT_RGB444, /* xxxxrrrr ggggbbbb */ 231 .fourcc = V4L2_PIX_FMT_RGB444, /* xxxxrrrr ggggbbbb */
238 .vdownsampling = { 1 }, 232 .vdownsampling = { 1 },
239 .bit_depth = { 16 }, 233 .bit_depth = { 16 },
@@ -241,7 +235,6 @@ struct vivid_fmt vivid_formats[] = {
241 .buffers = 1, 235 .buffers = 1,
242 }, 236 },
243 { 237 {
244 .name = "XRGB444",
245 .fourcc = V4L2_PIX_FMT_XRGB444, /* xxxxrrrr ggggbbbb */ 238 .fourcc = V4L2_PIX_FMT_XRGB444, /* xxxxrrrr ggggbbbb */
246 .vdownsampling = { 1 }, 239 .vdownsampling = { 1 },
247 .bit_depth = { 16 }, 240 .bit_depth = { 16 },
@@ -249,7 +242,6 @@ struct vivid_fmt vivid_formats[] = {
249 .buffers = 1, 242 .buffers = 1,
250 }, 243 },
251 { 244 {
252 .name = "ARGB444",
253 .fourcc = V4L2_PIX_FMT_ARGB444, /* aaaarrrr ggggbbbb */ 245 .fourcc = V4L2_PIX_FMT_ARGB444, /* aaaarrrr ggggbbbb */
254 .vdownsampling = { 1 }, 246 .vdownsampling = { 1 },
255 .bit_depth = { 16 }, 247 .bit_depth = { 16 },
@@ -258,7 +250,6 @@ struct vivid_fmt vivid_formats[] = {
258 .alpha_mask = 0x00f0, 250 .alpha_mask = 0x00f0,
259 }, 251 },
260 { 252 {
261 .name = "RGB555 (LE)",
262 .fourcc = V4L2_PIX_FMT_RGB555, /* gggbbbbb xrrrrrgg */ 253 .fourcc = V4L2_PIX_FMT_RGB555, /* gggbbbbb xrrrrrgg */
263 .vdownsampling = { 1 }, 254 .vdownsampling = { 1 },
264 .bit_depth = { 16 }, 255 .bit_depth = { 16 },
@@ -267,7 +258,6 @@ struct vivid_fmt vivid_formats[] = {
267 .can_do_overlay = true, 258 .can_do_overlay = true,
268 }, 259 },
269 { 260 {
270 .name = "XRGB555 (LE)",
271 .fourcc = V4L2_PIX_FMT_XRGB555, /* gggbbbbb xrrrrrgg */ 261 .fourcc = V4L2_PIX_FMT_XRGB555, /* gggbbbbb xrrrrrgg */
272 .vdownsampling = { 1 }, 262 .vdownsampling = { 1 },
273 .bit_depth = { 16 }, 263 .bit_depth = { 16 },
@@ -276,7 +266,6 @@ struct vivid_fmt vivid_formats[] = {
276 .can_do_overlay = true, 266 .can_do_overlay = true,
277 }, 267 },
278 { 268 {
279 .name = "ARGB555 (LE)",
280 .fourcc = V4L2_PIX_FMT_ARGB555, /* gggbbbbb arrrrrgg */ 269 .fourcc = V4L2_PIX_FMT_ARGB555, /* gggbbbbb arrrrrgg */
281 .vdownsampling = { 1 }, 270 .vdownsampling = { 1 },
282 .bit_depth = { 16 }, 271 .bit_depth = { 16 },
@@ -286,7 +275,6 @@ struct vivid_fmt vivid_formats[] = {
286 .alpha_mask = 0x8000, 275 .alpha_mask = 0x8000,
287 }, 276 },
288 { 277 {
289 .name = "RGB555 (BE)",
290 .fourcc = V4L2_PIX_FMT_RGB555X, /* xrrrrrgg gggbbbbb */ 278 .fourcc = V4L2_PIX_FMT_RGB555X, /* xrrrrrgg gggbbbbb */
291 .vdownsampling = { 1 }, 279 .vdownsampling = { 1 },
292 .bit_depth = { 16 }, 280 .bit_depth = { 16 },
@@ -294,7 +282,6 @@ struct vivid_fmt vivid_formats[] = {
294 .buffers = 1, 282 .buffers = 1,
295 }, 283 },
296 { 284 {
297 .name = "XRGB555 (BE)",
298 .fourcc = V4L2_PIX_FMT_XRGB555X, /* xrrrrrgg gggbbbbb */ 285 .fourcc = V4L2_PIX_FMT_XRGB555X, /* xrrrrrgg gggbbbbb */
299 .vdownsampling = { 1 }, 286 .vdownsampling = { 1 },
300 .bit_depth = { 16 }, 287 .bit_depth = { 16 },
@@ -302,7 +289,6 @@ struct vivid_fmt vivid_formats[] = {
302 .buffers = 1, 289 .buffers = 1,
303 }, 290 },
304 { 291 {
305 .name = "ARGB555 (BE)",
306 .fourcc = V4L2_PIX_FMT_ARGB555X, /* arrrrrgg gggbbbbb */ 292 .fourcc = V4L2_PIX_FMT_ARGB555X, /* arrrrrgg gggbbbbb */
307 .vdownsampling = { 1 }, 293 .vdownsampling = { 1 },
308 .bit_depth = { 16 }, 294 .bit_depth = { 16 },
@@ -311,7 +297,6 @@ struct vivid_fmt vivid_formats[] = {
311 .alpha_mask = 0x0080, 297 .alpha_mask = 0x0080,
312 }, 298 },
313 { 299 {
314 .name = "RGB24 (LE)",
315 .fourcc = V4L2_PIX_FMT_RGB24, /* rgb */ 300 .fourcc = V4L2_PIX_FMT_RGB24, /* rgb */
316 .vdownsampling = { 1 }, 301 .vdownsampling = { 1 },
317 .bit_depth = { 24 }, 302 .bit_depth = { 24 },
@@ -319,7 +304,6 @@ struct vivid_fmt vivid_formats[] = {
319 .buffers = 1, 304 .buffers = 1,
320 }, 305 },
321 { 306 {
322 .name = "RGB24 (BE)",
323 .fourcc = V4L2_PIX_FMT_BGR24, /* bgr */ 307 .fourcc = V4L2_PIX_FMT_BGR24, /* bgr */
324 .vdownsampling = { 1 }, 308 .vdownsampling = { 1 },
325 .bit_depth = { 24 }, 309 .bit_depth = { 24 },
@@ -327,7 +311,6 @@ struct vivid_fmt vivid_formats[] = {
327 .buffers = 1, 311 .buffers = 1,
328 }, 312 },
329 { 313 {
330 .name = "BGR666",
331 .fourcc = V4L2_PIX_FMT_BGR666, /* bbbbbbgg ggggrrrr rrxxxxxx */ 314 .fourcc = V4L2_PIX_FMT_BGR666, /* bbbbbbgg ggggrrrr rrxxxxxx */
332 .vdownsampling = { 1 }, 315 .vdownsampling = { 1 },
333 .bit_depth = { 32 }, 316 .bit_depth = { 32 },
@@ -335,7 +318,6 @@ struct vivid_fmt vivid_formats[] = {
335 .buffers = 1, 318 .buffers = 1,
336 }, 319 },
337 { 320 {
338 .name = "RGB32 (LE)",
339 .fourcc = V4L2_PIX_FMT_RGB32, /* xrgb */ 321 .fourcc = V4L2_PIX_FMT_RGB32, /* xrgb */
340 .vdownsampling = { 1 }, 322 .vdownsampling = { 1 },
341 .bit_depth = { 32 }, 323 .bit_depth = { 32 },
@@ -343,7 +325,6 @@ struct vivid_fmt vivid_formats[] = {
343 .buffers = 1, 325 .buffers = 1,
344 }, 326 },
345 { 327 {
346 .name = "RGB32 (BE)",
347 .fourcc = V4L2_PIX_FMT_BGR32, /* bgrx */ 328 .fourcc = V4L2_PIX_FMT_BGR32, /* bgrx */
348 .vdownsampling = { 1 }, 329 .vdownsampling = { 1 },
349 .bit_depth = { 32 }, 330 .bit_depth = { 32 },
@@ -351,7 +332,6 @@ struct vivid_fmt vivid_formats[] = {
351 .buffers = 1, 332 .buffers = 1,
352 }, 333 },
353 { 334 {
354 .name = "XRGB32 (LE)",
355 .fourcc = V4L2_PIX_FMT_XRGB32, /* xrgb */ 335 .fourcc = V4L2_PIX_FMT_XRGB32, /* xrgb */
356 .vdownsampling = { 1 }, 336 .vdownsampling = { 1 },
357 .bit_depth = { 32 }, 337 .bit_depth = { 32 },
@@ -359,7 +339,6 @@ struct vivid_fmt vivid_formats[] = {
359 .buffers = 1, 339 .buffers = 1,
360 }, 340 },
361 { 341 {
362 .name = "XRGB32 (BE)",
363 .fourcc = V4L2_PIX_FMT_XBGR32, /* bgrx */ 342 .fourcc = V4L2_PIX_FMT_XBGR32, /* bgrx */
364 .vdownsampling = { 1 }, 343 .vdownsampling = { 1 },
365 .bit_depth = { 32 }, 344 .bit_depth = { 32 },
@@ -367,7 +346,6 @@ struct vivid_fmt vivid_formats[] = {
367 .buffers = 1, 346 .buffers = 1,
368 }, 347 },
369 { 348 {
370 .name = "ARGB32 (LE)",
371 .fourcc = V4L2_PIX_FMT_ARGB32, /* argb */ 349 .fourcc = V4L2_PIX_FMT_ARGB32, /* argb */
372 .vdownsampling = { 1 }, 350 .vdownsampling = { 1 },
373 .bit_depth = { 32 }, 351 .bit_depth = { 32 },
@@ -376,7 +354,6 @@ struct vivid_fmt vivid_formats[] = {
376 .alpha_mask = 0x000000ff, 354 .alpha_mask = 0x000000ff,
377 }, 355 },
378 { 356 {
379 .name = "ARGB32 (BE)",
380 .fourcc = V4L2_PIX_FMT_ABGR32, /* bgra */ 357 .fourcc = V4L2_PIX_FMT_ABGR32, /* bgra */
381 .vdownsampling = { 1 }, 358 .vdownsampling = { 1 },
382 .bit_depth = { 32 }, 359 .bit_depth = { 32 },
@@ -385,7 +362,6 @@ struct vivid_fmt vivid_formats[] = {
385 .alpha_mask = 0xff000000, 362 .alpha_mask = 0xff000000,
386 }, 363 },
387 { 364 {
388 .name = "Bayer BG/GR",
389 .fourcc = V4L2_PIX_FMT_SBGGR8, /* Bayer BG/GR */ 365 .fourcc = V4L2_PIX_FMT_SBGGR8, /* Bayer BG/GR */
390 .vdownsampling = { 1 }, 366 .vdownsampling = { 1 },
391 .bit_depth = { 8 }, 367 .bit_depth = { 8 },
@@ -393,7 +369,6 @@ struct vivid_fmt vivid_formats[] = {
393 .buffers = 1, 369 .buffers = 1,
394 }, 370 },
395 { 371 {
396 .name = "Bayer GB/RG",
397 .fourcc = V4L2_PIX_FMT_SGBRG8, /* Bayer GB/RG */ 372 .fourcc = V4L2_PIX_FMT_SGBRG8, /* Bayer GB/RG */
398 .vdownsampling = { 1 }, 373 .vdownsampling = { 1 },
399 .bit_depth = { 8 }, 374 .bit_depth = { 8 },
@@ -401,7 +376,6 @@ struct vivid_fmt vivid_formats[] = {
401 .buffers = 1, 376 .buffers = 1,
402 }, 377 },
403 { 378 {
404 .name = "Bayer GR/BG",
405 .fourcc = V4L2_PIX_FMT_SGRBG8, /* Bayer GR/BG */ 379 .fourcc = V4L2_PIX_FMT_SGRBG8, /* Bayer GR/BG */
406 .vdownsampling = { 1 }, 380 .vdownsampling = { 1 },
407 .bit_depth = { 8 }, 381 .bit_depth = { 8 },
@@ -409,7 +383,6 @@ struct vivid_fmt vivid_formats[] = {
409 .buffers = 1, 383 .buffers = 1,
410 }, 384 },
411 { 385 {
412 .name = "Bayer RG/GB",
413 .fourcc = V4L2_PIX_FMT_SRGGB8, /* Bayer RG/GB */ 386 .fourcc = V4L2_PIX_FMT_SRGGB8, /* Bayer RG/GB */
414 .vdownsampling = { 1 }, 387 .vdownsampling = { 1 },
415 .bit_depth = { 8 }, 388 .bit_depth = { 8 },
@@ -417,7 +390,6 @@ struct vivid_fmt vivid_formats[] = {
417 .buffers = 1, 390 .buffers = 1,
418 }, 391 },
419 { 392 {
420 .name = "4:2:2, biplanar, YUV",
421 .fourcc = V4L2_PIX_FMT_NV16M, 393 .fourcc = V4L2_PIX_FMT_NV16M,
422 .vdownsampling = { 1, 1 }, 394 .vdownsampling = { 1, 1 },
423 .bit_depth = { 8, 8 }, 395 .bit_depth = { 8, 8 },
@@ -427,7 +399,6 @@ struct vivid_fmt vivid_formats[] = {
427 .data_offset = { PLANE0_DATA_OFFSET, 0 }, 399 .data_offset = { PLANE0_DATA_OFFSET, 0 },
428 }, 400 },
429 { 401 {
430 .name = "4:2:2, biplanar, YVU",
431 .fourcc = V4L2_PIX_FMT_NV61M, 402 .fourcc = V4L2_PIX_FMT_NV61M,
432 .vdownsampling = { 1, 1 }, 403 .vdownsampling = { 1, 1 },
433 .bit_depth = { 8, 8 }, 404 .bit_depth = { 8, 8 },
@@ -437,7 +408,6 @@ struct vivid_fmt vivid_formats[] = {
437 .data_offset = { 0, PLANE0_DATA_OFFSET }, 408 .data_offset = { 0, PLANE0_DATA_OFFSET },
438 }, 409 },
439 { 410 {
440 .name = "4:2:0, triplanar, YUV",
441 .fourcc = V4L2_PIX_FMT_YUV420M, 411 .fourcc = V4L2_PIX_FMT_YUV420M,
442 .vdownsampling = { 1, 2, 2 }, 412 .vdownsampling = { 1, 2, 2 },
443 .bit_depth = { 8, 4, 4 }, 413 .bit_depth = { 8, 4, 4 },
@@ -446,7 +416,6 @@ struct vivid_fmt vivid_formats[] = {
446 .buffers = 3, 416 .buffers = 3,
447 }, 417 },
448 { 418 {
449 .name = "4:2:0, triplanar, YVU",
450 .fourcc = V4L2_PIX_FMT_YVU420M, 419 .fourcc = V4L2_PIX_FMT_YVU420M,
451 .vdownsampling = { 1, 2, 2 }, 420 .vdownsampling = { 1, 2, 2 },
452 .bit_depth = { 8, 4, 4 }, 421 .bit_depth = { 8, 4, 4 },
@@ -455,7 +424,6 @@ struct vivid_fmt vivid_formats[] = {
455 .buffers = 3, 424 .buffers = 3,
456 }, 425 },
457 { 426 {
458 .name = "4:2:0, biplanar, YUV",
459 .fourcc = V4L2_PIX_FMT_NV12M, 427 .fourcc = V4L2_PIX_FMT_NV12M,
460 .vdownsampling = { 1, 2 }, 428 .vdownsampling = { 1, 2 },
461 .bit_depth = { 8, 8 }, 429 .bit_depth = { 8, 8 },
@@ -464,7 +432,6 @@ struct vivid_fmt vivid_formats[] = {
464 .buffers = 2, 432 .buffers = 2,
465 }, 433 },
466 { 434 {
467 .name = "4:2:0, biplanar, YVU",
468 .fourcc = V4L2_PIX_FMT_NV21M, 435 .fourcc = V4L2_PIX_FMT_NV21M,
469 .vdownsampling = { 1, 2 }, 436 .vdownsampling = { 1, 2 },
470 .bit_depth = { 8, 8 }, 437 .bit_depth = { 8, 8 },
@@ -557,6 +524,7 @@ void fmt_sp2mp(const struct v4l2_format *sp_fmt, struct v4l2_format *mp_fmt)
557 mp->pixelformat = pix->pixelformat; 524 mp->pixelformat = pix->pixelformat;
558 mp->field = pix->field; 525 mp->field = pix->field;
559 mp->colorspace = pix->colorspace; 526 mp->colorspace = pix->colorspace;
527 mp->xfer_func = pix->xfer_func;
560 mp->ycbcr_enc = pix->ycbcr_enc; 528 mp->ycbcr_enc = pix->ycbcr_enc;
561 mp->quantization = pix->quantization; 529 mp->quantization = pix->quantization;
562 mp->num_planes = 1; 530 mp->num_planes = 1;
@@ -585,6 +553,7 @@ int fmt_sp2mp_func(struct file *file, void *priv,
585 pix->pixelformat = mp->pixelformat; 553 pix->pixelformat = mp->pixelformat;
586 pix->field = mp->field; 554 pix->field = mp->field;
587 pix->colorspace = mp->colorspace; 555 pix->colorspace = mp->colorspace;
556 pix->xfer_func = mp->xfer_func;
588 pix->ycbcr_enc = mp->ycbcr_enc; 557 pix->ycbcr_enc = mp->ycbcr_enc;
589 pix->quantization = mp->quantization; 558 pix->quantization = mp->quantization;
590 pix->sizeimage = ppix->sizeimage; 559 pix->sizeimage = ppix->sizeimage;
@@ -750,7 +719,6 @@ int vivid_enum_fmt_vid(struct file *file, void *priv,
750 719
751 fmt = &vivid_formats[f->index]; 720 fmt = &vivid_formats[f->index];
752 721
753 strlcpy(f->description, fmt->name, sizeof(f->description));
754 f->pixelformat = fmt->fourcc; 722 f->pixelformat = fmt->fourcc;
755 return 0; 723 return 0;
756} 724}
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index 0af43dc7715c..0862c1f24f57 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -258,6 +258,7 @@ void vivid_update_format_out(struct vivid_dev *dev)
258 } 258 }
259 break; 259 break;
260 } 260 }
261 dev->xfer_func_out = V4L2_XFER_FUNC_DEFAULT;
261 dev->ycbcr_enc_out = V4L2_YCBCR_ENC_DEFAULT; 262 dev->ycbcr_enc_out = V4L2_YCBCR_ENC_DEFAULT;
262 dev->quantization_out = V4L2_QUANTIZATION_DEFAULT; 263 dev->quantization_out = V4L2_QUANTIZATION_DEFAULT;
263 dev->compose_out = dev->sink_rect; 264 dev->compose_out = dev->sink_rect;
@@ -320,6 +321,7 @@ int vivid_g_fmt_vid_out(struct file *file, void *priv,
320 mp->field = dev->field_out; 321 mp->field = dev->field_out;
321 mp->pixelformat = fmt->fourcc; 322 mp->pixelformat = fmt->fourcc;
322 mp->colorspace = dev->colorspace_out; 323 mp->colorspace = dev->colorspace_out;
324 mp->xfer_func = dev->xfer_func_out;
323 mp->ycbcr_enc = dev->ycbcr_enc_out; 325 mp->ycbcr_enc = dev->ycbcr_enc_out;
324 mp->quantization = dev->quantization_out; 326 mp->quantization = dev->quantization_out;
325 mp->num_planes = fmt->buffers; 327 mp->num_planes = fmt->buffers;
@@ -407,6 +409,7 @@ int vivid_try_fmt_vid_out(struct file *file, void *priv,
407 for (p = fmt->buffers; p < fmt->planes; p++) 409 for (p = fmt->buffers; p < fmt->planes; p++)
408 pfmt[0].sizeimage += (pfmt[0].bytesperline * fmt->bit_depth[p]) / 410 pfmt[0].sizeimage += (pfmt[0].bytesperline * fmt->bit_depth[p]) /
409 (fmt->bit_depth[0] * fmt->vdownsampling[p]); 411 (fmt->bit_depth[0] * fmt->vdownsampling[p]);
412 mp->xfer_func = V4L2_XFER_FUNC_DEFAULT;
410 mp->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; 413 mp->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
411 mp->quantization = V4L2_QUANTIZATION_DEFAULT; 414 mp->quantization = V4L2_QUANTIZATION_DEFAULT;
412 if (vivid_is_svid_out(dev)) { 415 if (vivid_is_svid_out(dev)) {
@@ -546,6 +549,7 @@ int vivid_s_fmt_vid_out(struct file *file, void *priv,
546 549
547set_colorspace: 550set_colorspace:
548 dev->colorspace_out = mp->colorspace; 551 dev->colorspace_out = mp->colorspace;
552 dev->xfer_func_out = mp->xfer_func;
549 dev->ycbcr_enc_out = mp->ycbcr_enc; 553 dev->ycbcr_enc_out = mp->ycbcr_enc;
550 dev->quantization_out = mp->quantization; 554 dev->quantization_out = mp->quantization;
551 if (dev->loop_video) { 555 if (dev->loop_video) {
@@ -1152,7 +1156,8 @@ int vivid_vid_out_g_parm(struct file *file, void *priv,
1152 parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; 1156 parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
1153 parm->parm.output.timeperframe = dev->timeperframe_vid_out; 1157 parm->parm.output.timeperframe = dev->timeperframe_vid_out;
1154 parm->parm.output.writebuffers = 1; 1158 parm->parm.output.writebuffers = 1;
1155return 0; 1159
1160 return 0;
1156} 1161}
1157 1162
1158int vidioc_subscribe_event(struct v4l2_fh *fh, 1163int vidioc_subscribe_event(struct v4l2_fh *fh,
diff --git a/drivers/media/platform/xilinx/Kconfig b/drivers/media/platform/xilinx/Kconfig
index d7324c726fc2..84bae795b70d 100644
--- a/drivers/media/platform/xilinx/Kconfig
+++ b/drivers/media/platform/xilinx/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_XILINX 1config VIDEO_XILINX
2 tristate "Xilinx Video IP (EXPERIMENTAL)" 2 tristate "Xilinx Video IP (EXPERIMENTAL)"
3 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF 3 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF && HAS_DMA
4 select VIDEOBUF2_DMA_CONTIG 4 select VIDEOBUF2_DMA_CONTIG
5 ---help--- 5 ---help---
6 Driver for Xilinx Video IP Pipelines 6 Driver for Xilinx Video IP Pipelines
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index efde88adf624..98e50e446d57 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -653,7 +653,7 @@ static const struct v4l2_file_operations xvip_dma_fops = {
653int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma, 653int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma,
654 enum v4l2_buf_type type, unsigned int port) 654 enum v4l2_buf_type type, unsigned int port)
655{ 655{
656 char name[14]; 656 char name[16];
657 int ret; 657 int ret;
658 658
659 dma->xdev = xdev; 659 dma->xdev = xdev;
@@ -725,7 +725,7 @@ int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma,
725 } 725 }
726 726
727 /* ... and the DMA channel. */ 727 /* ... and the DMA channel. */
728 sprintf(name, "port%u", port); 728 snprintf(name, sizeof(name), "port%u", port);
729 dma->dma = dma_request_slave_channel(dma->xdev->dev, name); 729 dma->dma = dma_request_slave_channel(dma->xdev->dev, name);
730 if (dma->dma == NULL) { 730 if (dma->dma == NULL) {
731 dev_err(dma->xdev->dev, "no VDMA channel found\n"); 731 dev_err(dma->xdev->dev, "no VDMA channel found\n");
diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
index dccf58691650..9cbb8cdf0ac0 100644
--- a/drivers/media/radio/radio-si476x.c
+++ b/drivers/media/radio/radio-si476x.c
@@ -568,8 +568,8 @@ static int si476x_radio_do_post_powerup_init(struct si476x_radio *radio,
568 err = regcache_sync_region(radio->core->regmap, 568 err = regcache_sync_region(radio->core->regmap,
569 SI476X_PROP_DIGITAL_IO_INPUT_SAMPLE_RATE, 569 SI476X_PROP_DIGITAL_IO_INPUT_SAMPLE_RATE,
570 SI476X_PROP_DIGITAL_IO_OUTPUT_FORMAT); 570 SI476X_PROP_DIGITAL_IO_OUTPUT_FORMAT);
571 if (err < 0) 571 if (err < 0)
572 return err; 572 return err;
573 573
574 err = regcache_sync_region(radio->core->regmap, 574 err = regcache_sync_region(radio->core->regmap,
575 SI476X_PROP_AUDIO_DEEMPHASIS, 575 SI476X_PROP_AUDIO_DEEMPHASIS,
diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c
index e6b55edc8f8d..04baafe5e901 100644
--- a/drivers/media/radio/radio-timb.c
+++ b/drivers/media/radio/radio-timb.c
@@ -138,8 +138,10 @@ static int timbradio_probe(struct platform_device *pdev)
138 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL); 138 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL);
139 tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev, 139 tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
140 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL); 140 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL);
141 if (tr->sd_tuner == NULL || tr->sd_dsp == NULL) 141 if (tr->sd_tuner == NULL || tr->sd_dsp == NULL) {
142 err = -ENODEV;
142 goto err_video_req; 143 goto err_video_req;
144 }
143 145
144 tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler; 146 tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler;
145 147
diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c
index 2a497c80c77f..471d6a8ae8a4 100644
--- a/drivers/media/radio/si470x/radio-si470x-i2c.c
+++ b/drivers/media/radio/si470x/radio-si470x-i2c.c
@@ -384,14 +384,14 @@ static int si470x_i2c_probe(struct i2c_client *client,
384 goto err_radio; 384 goto err_radio;
385 } 385 }
386 dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n", 386 dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
387 radio->registers[DEVICEID], radio->registers[CHIPID]); 387 radio->registers[DEVICEID], radio->registers[SI_CHIPID]);
388 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE) < RADIO_FW_VERSION) { 388 if ((radio->registers[SI_CHIPID] & SI_CHIPID_FIRMWARE) < RADIO_FW_VERSION) {
389 dev_warn(&client->dev, 389 dev_warn(&client->dev,
390 "This driver is known to work with " 390 "This driver is known to work with "
391 "firmware version %hu,\n", RADIO_FW_VERSION); 391 "firmware version %hu,\n", RADIO_FW_VERSION);
392 dev_warn(&client->dev, 392 dev_warn(&client->dev,
393 "but the device has firmware version %hu.\n", 393 "but the device has firmware version %hu.\n",
394 radio->registers[CHIPID] & CHIPID_FIRMWARE); 394 radio->registers[SI_CHIPID] & SI_CHIPID_FIRMWARE);
395 version_warning = 1; 395 version_warning = 1;
396 } 396 }
397 397
@@ -421,7 +421,8 @@ static int si470x_i2c_probe(struct i2c_client *client,
421 init_waitqueue_head(&radio->read_queue); 421 init_waitqueue_head(&radio->read_queue);
422 422
423 retval = request_threaded_irq(client->irq, NULL, si470x_i2c_interrupt, 423 retval = request_threaded_irq(client->irq, NULL, si470x_i2c_interrupt,
424 IRQF_TRIGGER_FALLING, DRIVER_NAME, radio); 424 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DRIVER_NAME,
425 radio);
425 if (retval) { 426 if (retval) {
426 dev_err(&client->dev, "Failed to register interrupt\n"); 427 dev_err(&client->dev, "Failed to register interrupt\n");
427 goto err_rds; 428 goto err_rds;
diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c
index 57f0bc3b60e7..091d793f6583 100644
--- a/drivers/media/radio/si470x/radio-si470x-usb.c
+++ b/drivers/media/radio/si470x/radio-si470x-usb.c
@@ -686,14 +686,14 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
686 goto err_ctrl; 686 goto err_ctrl;
687 } 687 }
688 dev_info(&intf->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n", 688 dev_info(&intf->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
689 radio->registers[DEVICEID], radio->registers[CHIPID]); 689 radio->registers[DEVICEID], radio->registers[SI_CHIPID]);
690 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE) < RADIO_FW_VERSION) { 690 if ((radio->registers[SI_CHIPID] & SI_CHIPID_FIRMWARE) < RADIO_FW_VERSION) {
691 dev_warn(&intf->dev, 691 dev_warn(&intf->dev,
692 "This driver is known to work with " 692 "This driver is known to work with "
693 "firmware version %hu,\n", RADIO_FW_VERSION); 693 "firmware version %hu,\n", RADIO_FW_VERSION);
694 dev_warn(&intf->dev, 694 dev_warn(&intf->dev,
695 "but the device has firmware version %hu.\n", 695 "but the device has firmware version %hu.\n",
696 radio->registers[CHIPID] & CHIPID_FIRMWARE); 696 radio->registers[SI_CHIPID] & SI_CHIPID_FIRMWARE);
697 version_warning = 1; 697 version_warning = 1;
698 } 698 }
699 699
diff --git a/drivers/media/radio/si470x/radio-si470x.h b/drivers/media/radio/si470x/radio-si470x.h
index 4b7660470e2f..6c0ca900702e 100644
--- a/drivers/media/radio/si470x/radio-si470x.h
+++ b/drivers/media/radio/si470x/radio-si470x.h
@@ -54,10 +54,10 @@
54#define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */ 54#define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */
55#define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */ 55#define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */
56 56
57#define CHIPID 1 /* Chip ID */ 57#define SI_CHIPID 1 /* Chip ID */
58#define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */ 58#define SI_CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */
59#define CHIPID_DEV 0x0200 /* bits 09..09: Device */ 59#define SI_CHIPID_DEV 0x0200 /* bits 09..09: Device */
60#define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */ 60#define SI_CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */
61 61
62#define POWERCFG 2 /* Power Configuration */ 62#define POWERCFG 2 /* Power Configuration */
63#define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */ 63#define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */
diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
index e9d03ac69a27..0b04b56571da 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -1609,8 +1609,10 @@ static int si4713_probe(struct i2c_client *client,
1609 return 0; 1609 return 0;
1610 1610
1611 si4713_pdev = platform_device_alloc("radio-si4713", -1); 1611 si4713_pdev = platform_device_alloc("radio-si4713", -1);
1612 if (!si4713_pdev) 1612 if (!si4713_pdev) {
1613 rval = -ENOMEM;
1613 goto put_main_pdev; 1614 goto put_main_pdev;
1615 }
1614 1616
1615 si4713_pdev_pdata.subdev = client; 1617 si4713_pdev_pdata.subdev = client;
1616 rval = platform_device_add_data(si4713_pdev, &si4713_pdev_pdata, 1618 rval = platform_device_add_data(si4713_pdev, &si4713_pdev_pdata,
diff --git a/drivers/media/radio/wl128x/Kconfig b/drivers/media/radio/wl128x/Kconfig
index 9d6574bebf78..c9e349b169c4 100644
--- a/drivers/media/radio/wl128x/Kconfig
+++ b/drivers/media/radio/wl128x/Kconfig
@@ -4,8 +4,8 @@
4menu "Texas Instruments WL128x FM driver (ST based)" 4menu "Texas Instruments WL128x FM driver (ST based)"
5config RADIO_WL128X 5config RADIO_WL128X
6 tristate "Texas Instruments WL128x FM Radio" 6 tristate "Texas Instruments WL128x FM Radio"
7 depends on VIDEO_V4L2 && RFKILL && GPIOLIB && TTY 7 depends on VIDEO_V4L2 && RFKILL && TTY && TI_ST
8 depends on TI_ST 8 depends on GPIOLIB || COMPILE_TEST
9 help 9 help
10 Choose Y here if you have this FM radio chip. 10 Choose Y here if you have this FM radio chip.
11 11
diff --git a/drivers/media/radio/wl128x/fmdrv.h b/drivers/media/radio/wl128x/fmdrv.h
index a587c9bac930..dd203de5de95 100644
--- a/drivers/media/radio/wl128x/fmdrv.h
+++ b/drivers/media/radio/wl128x/fmdrv.h
@@ -210,7 +210,7 @@ struct fmdev {
210 spinlock_t resp_skb_lock; /* To protect access to received SKB */ 210 spinlock_t resp_skb_lock; /* To protect access to received SKB */
211 211
212 long flag; /* FM driver state machine info */ 212 long flag; /* FM driver state machine info */
213 u8 streg_cbdata; /* status of ST registration */ 213 int streg_cbdata; /* status of ST registration */
214 214
215 struct sk_buff_head rx_q; /* RX queue */ 215 struct sk_buff_head rx_q; /* RX queue */
216 struct tasklet_struct rx_task; /* RX Tasklet */ 216 struct tasklet_struct rx_task; /* RX Tasklet */
diff --git a/drivers/media/rc/fintek-cir.c b/drivers/media/rc/fintek-cir.c
index 5c63c2ec6183..bd7b3bdb1a88 100644
--- a/drivers/media/rc/fintek-cir.c
+++ b/drivers/media/rc/fintek-cir.c
@@ -33,7 +33,6 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <media/rc-core.h> 35#include <media/rc-core.h>
36#include <linux/pci_ids.h>
37 36
38#include "fintek-cir.h" 37#include "fintek-cir.h"
39 38
diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c
index 229853d68451..7dbc9ca6d885 100644
--- a/drivers/media/rc/gpio-ir-recv.c
+++ b/drivers/media/rc/gpio-ir-recv.c
@@ -59,7 +59,7 @@ static int gpio_ir_recv_get_devtree_pdata(struct device *dev,
59 return 0; 59 return 0;
60} 60}
61 61
62static struct of_device_id gpio_ir_recv_of_match[] = { 62static const struct of_device_id gpio_ir_recv_of_match[] = {
63 { .compatible = "gpio-ir-receiver", }, 63 { .compatible = "gpio-ir-receiver", },
64 { }, 64 { },
65}; 65};
@@ -78,7 +78,7 @@ static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id)
78 int rc = 0; 78 int rc = 0;
79 enum raw_event_type type = IR_SPACE; 79 enum raw_event_type type = IR_SPACE;
80 80
81 gval = gpio_get_value_cansleep(gpio_dev->gpio_nr); 81 gval = gpio_get_value(gpio_dev->gpio_nr);
82 82
83 if (gval < 0) 83 if (gval < 0)
84 goto err_get_value; 84 goto err_get_value;
diff --git a/drivers/media/rc/ir-hix5hd2.c b/drivers/media/rc/ir-hix5hd2.c
index 58ec5986274e..1c087cb76815 100644
--- a/drivers/media/rc/ir-hix5hd2.c
+++ b/drivers/media/rc/ir-hix5hd2.c
@@ -63,7 +63,7 @@
63 63
64struct hix5hd2_ir_priv { 64struct hix5hd2_ir_priv {
65 int irq; 65 int irq;
66 void volatile __iomem *base; 66 void __iomem *base;
67 struct device *dev; 67 struct device *dev;
68 struct rc_dev *rdev; 68 struct rc_dev *rdev;
69 struct regmap *regmap; 69 struct regmap *regmap;
@@ -213,8 +213,8 @@ static int hix5hd2_ir_probe(struct platform_device *pdev)
213 213
214 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 214 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
215 priv->base = devm_ioremap_resource(dev, res); 215 priv->base = devm_ioremap_resource(dev, res);
216 if (IS_ERR((__force void *)priv->base)) 216 if (IS_ERR(priv->base))
217 return PTR_ERR((__force void *)priv->base); 217 return PTR_ERR(priv->base);
218 218
219 priv->irq = platform_get_irq(pdev, 0); 219 priv->irq = platform_get_irq(pdev, 0);
220 if (priv->irq < 0) { 220 if (priv->irq < 0) {
@@ -319,7 +319,7 @@ static int hix5hd2_ir_resume(struct device *dev)
319static SIMPLE_DEV_PM_OPS(hix5hd2_ir_pm_ops, hix5hd2_ir_suspend, 319static SIMPLE_DEV_PM_OPS(hix5hd2_ir_pm_ops, hix5hd2_ir_suspend,
320 hix5hd2_ir_resume); 320 hix5hd2_ir_resume);
321 321
322static struct of_device_id hix5hd2_ir_table[] = { 322static const struct of_device_id hix5hd2_ir_table[] = {
323 { .compatible = "hisilicon,hix5hd2-ir", }, 323 { .compatible = "hisilicon,hix5hd2-ir", },
324 {}, 324 {},
325}; 325};
diff --git a/drivers/media/rc/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c
index 84fa6e9b59a1..8939ebd74391 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -184,9 +184,125 @@ out:
184 return -EINVAL; 184 return -EINVAL;
185} 185}
186 186
187static struct ir_raw_timings_manchester ir_rc5_timings = {
188 .leader = RC5_UNIT,
189 .pulse_space_start = 0,
190 .clock = RC5_UNIT,
191 .trailer_space = RC5_UNIT * 10,
192};
193
194static struct ir_raw_timings_manchester ir_rc5x_timings[2] = {
195 {
196 .leader = RC5_UNIT,
197 .pulse_space_start = 0,
198 .clock = RC5_UNIT,
199 .trailer_space = RC5X_SPACE,
200 },
201 {
202 .clock = RC5_UNIT,
203 .trailer_space = RC5_UNIT * 10,
204 },
205};
206
207static struct ir_raw_timings_manchester ir_rc5_sz_timings = {
208 .leader = RC5_UNIT,
209 .pulse_space_start = 0,
210 .clock = RC5_UNIT,
211 .trailer_space = RC5_UNIT * 10,
212};
213
214static int ir_rc5_validate_filter(const struct rc_scancode_filter *scancode,
215 unsigned int important_bits)
216{
217 /* all important bits of scancode should be set in mask */
218 if (~scancode->mask & important_bits)
219 return -EINVAL;
220 /* extra bits in mask should be zero in data */
221 if (scancode->mask & scancode->data & ~important_bits)
222 return -EINVAL;
223 return 0;
224}
225
226/**
227 * ir_rc5_encode() - Encode a scancode as a stream of raw events
228 *
229 * @protocols: allowed protocols
230 * @scancode: scancode filter describing scancode (helps distinguish between
231 * protocol subtypes when scancode is ambiguous)
232 * @events: array of raw ir events to write into
233 * @max: maximum size of @events
234 *
235 * Returns: The number of events written.
236 * -ENOBUFS if there isn't enough space in the array to fit the
237 * encoding. In this case all @max events will have been written.
238 * -EINVAL if the scancode is ambiguous or invalid.
239 */
240static int ir_rc5_encode(u64 protocols,
241 const struct rc_scancode_filter *scancode,
242 struct ir_raw_event *events, unsigned int max)
243{
244 int ret;
245 struct ir_raw_event *e = events;
246 unsigned int data, xdata, command, commandx, system;
247
248 /* Detect protocol and convert scancode to raw data */
249 if (protocols & RC_BIT_RC5 &&
250 !ir_rc5_validate_filter(scancode, 0x1f7f)) {
251 /* decode scancode */
252 command = (scancode->data & 0x003f) >> 0;
253 commandx = (scancode->data & 0x0040) >> 6;
254 system = (scancode->data & 0x1f00) >> 8;
255 /* encode data */
256 data = !commandx << 12 | system << 6 | command;
257
258 /* Modulate the data */
259 ret = ir_raw_gen_manchester(&e, max, &ir_rc5_timings, RC5_NBITS,
260 data);
261 if (ret < 0)
262 return ret;
263 } else if (protocols & RC_BIT_RC5X &&
264 !ir_rc5_validate_filter(scancode, 0x1f7f3f)) {
265 /* decode scancode */
266 xdata = (scancode->data & 0x00003f) >> 0;
267 command = (scancode->data & 0x003f00) >> 8;
268 commandx = (scancode->data & 0x004000) >> 14;
269 system = (scancode->data & 0x1f0000) >> 16;
270 /* commandx and system overlap, bits must match when encoded */
271 if (commandx == (system & 0x1))
272 return -EINVAL;
273 /* encode data */
274 data = 1 << 18 | system << 12 | command << 6 | xdata;
275
276 /* Modulate the data */
277 ret = ir_raw_gen_manchester(&e, max, &ir_rc5x_timings[0],
278 CHECK_RC5X_NBITS,
279 data >> (RC5X_NBITS-CHECK_RC5X_NBITS));
280 if (ret < 0)
281 return ret;
282 ret = ir_raw_gen_manchester(&e, max - (e - events),
283 &ir_rc5x_timings[1],
284 RC5X_NBITS - CHECK_RC5X_NBITS,
285 data);
286 if (ret < 0)
287 return ret;
288 } else if (protocols & RC_BIT_RC5_SZ &&
289 !ir_rc5_validate_filter(scancode, 0x2fff)) {
290 /* RC5-SZ scancode is raw enough for Manchester as it is */
291 ret = ir_raw_gen_manchester(&e, max, &ir_rc5_sz_timings,
292 RC5_SZ_NBITS, scancode->data & 0x2fff);
293 if (ret < 0)
294 return ret;
295 } else {
296 return -EINVAL;
297 }
298
299 return e - events;
300}
301
187static struct ir_raw_handler rc5_handler = { 302static struct ir_raw_handler rc5_handler = {
188 .protocols = RC_BIT_RC5 | RC_BIT_RC5X | RC_BIT_RC5_SZ, 303 .protocols = RC_BIT_RC5 | RC_BIT_RC5X | RC_BIT_RC5_SZ,
189 .decode = ir_rc5_decode, 304 .decode = ir_rc5_decode,
305 .encode = ir_rc5_encode,
190}; 306};
191 307
192static int __init ir_rc5_decode_init(void) 308static int __init ir_rc5_decode_init(void)
diff --git a/drivers/media/rc/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c
index d16bc67af732..f9c70baf6e0c 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -291,11 +291,133 @@ out:
291 return -EINVAL; 291 return -EINVAL;
292} 292}
293 293
294static struct ir_raw_timings_manchester ir_rc6_timings[4] = {
295 {
296 .leader = RC6_PREFIX_PULSE,
297 .pulse_space_start = 0,
298 .clock = RC6_UNIT,
299 .invert = 1,
300 .trailer_space = RC6_PREFIX_SPACE,
301 },
302 {
303 .clock = RC6_UNIT,
304 .invert = 1,
305 },
306 {
307 .clock = RC6_UNIT * 2,
308 .invert = 1,
309 },
310 {
311 .clock = RC6_UNIT,
312 .invert = 1,
313 .trailer_space = RC6_SUFFIX_SPACE,
314 },
315};
316
317static int ir_rc6_validate_filter(const struct rc_scancode_filter *scancode,
318 unsigned int important_bits)
319{
320 /* all important bits of scancode should be set in mask */
321 if (~scancode->mask & important_bits)
322 return -EINVAL;
323 /* extra bits in mask should be zero in data */
324 if (scancode->mask & scancode->data & ~important_bits)
325 return -EINVAL;
326 return 0;
327}
328
329/**
330 * ir_rc6_encode() - Encode a scancode as a stream of raw events
331 *
332 * @protocols: allowed protocols
333 * @scancode: scancode filter describing scancode (helps distinguish between
334 * protocol subtypes when scancode is ambiguous)
335 * @events: array of raw ir events to write into
336 * @max: maximum size of @events
337 *
338 * Returns: The number of events written.
339 * -ENOBUFS if there isn't enough space in the array to fit the
340 * encoding. In this case all @max events will have been written.
341 * -EINVAL if the scancode is ambiguous or invalid.
342 */
343static int ir_rc6_encode(u64 protocols,
344 const struct rc_scancode_filter *scancode,
345 struct ir_raw_event *events, unsigned int max)
346{
347 int ret;
348 struct ir_raw_event *e = events;
349
350 if (protocols & RC_BIT_RC6_0 &&
351 !ir_rc6_validate_filter(scancode, 0xffff)) {
352
353 /* Modulate the preamble */
354 ret = ir_raw_gen_manchester(&e, max, &ir_rc6_timings[0], 0, 0);
355 if (ret < 0)
356 return ret;
357
358 /* Modulate the header (Start Bit & Mode-0) */
359 ret = ir_raw_gen_manchester(&e, max - (e - events),
360 &ir_rc6_timings[1],
361 RC6_HEADER_NBITS, (1 << 3));
362 if (ret < 0)
363 return ret;
364
365 /* Modulate Trailer Bit */
366 ret = ir_raw_gen_manchester(&e, max - (e - events),
367 &ir_rc6_timings[2], 1, 0);
368 if (ret < 0)
369 return ret;
370
371 /* Modulate rest of the data */
372 ret = ir_raw_gen_manchester(&e, max - (e - events),
373 &ir_rc6_timings[3], RC6_0_NBITS,
374 scancode->data);
375 if (ret < 0)
376 return ret;
377
378 } else if (protocols & (RC_BIT_RC6_6A_20 | RC_BIT_RC6_6A_24 |
379 RC_BIT_RC6_6A_32 | RC_BIT_RC6_MCE) &&
380 !ir_rc6_validate_filter(scancode, 0x8fffffff)) {
381
382 /* Modulate the preamble */
383 ret = ir_raw_gen_manchester(&e, max, &ir_rc6_timings[0], 0, 0);
384 if (ret < 0)
385 return ret;
386
387 /* Modulate the header (Start Bit & Header-version 6 */
388 ret = ir_raw_gen_manchester(&e, max - (e - events),
389 &ir_rc6_timings[1],
390 RC6_HEADER_NBITS, (1 << 3 | 6));
391 if (ret < 0)
392 return ret;
393
394 /* Modulate Trailer Bit */
395 ret = ir_raw_gen_manchester(&e, max - (e - events),
396 &ir_rc6_timings[2], 1, 0);
397 if (ret < 0)
398 return ret;
399
400 /* Modulate rest of the data */
401 ret = ir_raw_gen_manchester(&e, max - (e - events),
402 &ir_rc6_timings[3],
403 fls(scancode->mask),
404 scancode->data);
405 if (ret < 0)
406 return ret;
407
408 } else {
409 return -EINVAL;
410 }
411
412 return e - events;
413}
414
294static struct ir_raw_handler rc6_handler = { 415static struct ir_raw_handler rc6_handler = {
295 .protocols = RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 | 416 .protocols = RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 |
296 RC_BIT_RC6_6A_24 | RC_BIT_RC6_6A_32 | 417 RC_BIT_RC6_6A_24 | RC_BIT_RC6_6A_32 |
297 RC_BIT_RC6_MCE, 418 RC_BIT_RC6_MCE,
298 .decode = ir_rc6_decode, 419 .decode = ir_rc6_decode,
420 .encode = ir_rc6_encode,
299}; 421};
300 422
301static int __init ir_rc6_decode_init(void) 423static int __init ir_rc6_decode_init(void)
diff --git a/drivers/media/rc/ir-sony-decoder.c b/drivers/media/rc/ir-sony-decoder.c
index d12dc3da5931..58ef06f35175 100644
--- a/drivers/media/rc/ir-sony-decoder.c
+++ b/drivers/media/rc/ir-sony-decoder.c
@@ -125,30 +125,27 @@ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
125 125
126 switch (data->count) { 126 switch (data->count) {
127 case 12: 127 case 12:
128 if (!(dev->enabled_protocols & RC_BIT_SONY12)) { 128 if (!(dev->enabled_protocols & RC_BIT_SONY12))
129 data->state = STATE_INACTIVE; 129 goto finish_state_machine;
130 return 0; 130
131 }
132 device = bitrev8((data->bits << 3) & 0xF8); 131 device = bitrev8((data->bits << 3) & 0xF8);
133 subdevice = 0; 132 subdevice = 0;
134 function = bitrev8((data->bits >> 4) & 0xFE); 133 function = bitrev8((data->bits >> 4) & 0xFE);
135 protocol = RC_TYPE_SONY12; 134 protocol = RC_TYPE_SONY12;
136 break; 135 break;
137 case 15: 136 case 15:
138 if (!(dev->enabled_protocols & RC_BIT_SONY15)) { 137 if (!(dev->enabled_protocols & RC_BIT_SONY15))
139 data->state = STATE_INACTIVE; 138 goto finish_state_machine;
140 return 0; 139
141 }
142 device = bitrev8((data->bits >> 0) & 0xFF); 140 device = bitrev8((data->bits >> 0) & 0xFF);
143 subdevice = 0; 141 subdevice = 0;
144 function = bitrev8((data->bits >> 7) & 0xFE); 142 function = bitrev8((data->bits >> 7) & 0xFE);
145 protocol = RC_TYPE_SONY15; 143 protocol = RC_TYPE_SONY15;
146 break; 144 break;
147 case 20: 145 case 20:
148 if (!(dev->enabled_protocols & RC_BIT_SONY20)) { 146 if (!(dev->enabled_protocols & RC_BIT_SONY20))
149 data->state = STATE_INACTIVE; 147 goto finish_state_machine;
150 return 0; 148
151 }
152 device = bitrev8((data->bits >> 5) & 0xF8); 149 device = bitrev8((data->bits >> 5) & 0xF8);
153 subdevice = bitrev8((data->bits >> 0) & 0xFF); 150 subdevice = bitrev8((data->bits >> 0) & 0xFF);
154 function = bitrev8((data->bits >> 12) & 0xFE); 151 function = bitrev8((data->bits >> 12) & 0xFE);
@@ -162,8 +159,7 @@ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
162 scancode = device << 16 | subdevice << 8 | function; 159 scancode = device << 16 | subdevice << 8 | function;
163 IR_dprintk(1, "Sony(%u) scancode 0x%05x\n", data->count, scancode); 160 IR_dprintk(1, "Sony(%u) scancode 0x%05x\n", data->count, scancode);
164 rc_keydown(dev, protocol, scancode, 0); 161 rc_keydown(dev, protocol, scancode, 0);
165 data->state = STATE_INACTIVE; 162 goto finish_state_machine;
166 return 0;
167 } 163 }
168 164
169out: 165out:
@@ -171,6 +167,10 @@ out:
171 data->state, TO_US(ev.duration), TO_STR(ev.pulse)); 167 data->state, TO_US(ev.duration), TO_STR(ev.pulse));
172 data->state = STATE_INACTIVE; 168 data->state = STATE_INACTIVE;
173 return -EINVAL; 169 return -EINVAL;
170
171finish_state_machine:
172 data->state = STATE_INACTIVE;
173 return 0;
174} 174}
175 175
176static struct ir_raw_handler sony_handler = { 176static struct ir_raw_handler sony_handler = {
diff --git a/drivers/media/rc/keymaps/Makefile b/drivers/media/rc/keymaps/Makefile
index abf60794223d..fbbd3bbcd252 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -84,7 +84,10 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
84 rc-snapstream-firefly.o \ 84 rc-snapstream-firefly.o \
85 rc-streamzap.o \ 85 rc-streamzap.o \
86 rc-tbs-nec.o \ 86 rc-tbs-nec.o \
87 rc-technisat-ts35.o \
87 rc-technisat-usb2.o \ 88 rc-technisat-usb2.o \
89 rc-terratec-cinergy-c-pci.o \
90 rc-terratec-cinergy-s2-hd.o \
88 rc-terratec-cinergy-xs.o \ 91 rc-terratec-cinergy-xs.o \
89 rc-terratec-slim.o \ 92 rc-terratec-slim.o \
90 rc-terratec-slim-2.o \ 93 rc-terratec-slim-2.o \
@@ -94,6 +97,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
94 rc-total-media-in-hand-02.o \ 97 rc-total-media-in-hand-02.o \
95 rc-trekstor.o \ 98 rc-trekstor.o \
96 rc-tt-1500.o \ 99 rc-tt-1500.o \
100 rc-twinhan-dtv-cab-ci.o \
97 rc-twinhan1027.o \ 101 rc-twinhan1027.o \
98 rc-videomate-m1f.o \ 102 rc-videomate-m1f.o \
99 rc-videomate-s350.o \ 103 rc-videomate-s350.o \
diff --git a/drivers/media/rc/keymaps/rc-technisat-ts35.c b/drivers/media/rc/keymaps/rc-technisat-ts35.c
new file mode 100644
index 000000000000..3328cbefabad
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-technisat-ts35.c
@@ -0,0 +1,76 @@
1/* rc-technisat-ts35.c - Keytable for TechniSat TS35 remote
2 *
3 * Copyright (c) 2013 by Jan Klötzke <jan@kloetzke.net>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 */
10
11#include <media/rc-map.h>
12#include <linux/module.h>
13
14static struct rc_map_table technisat_ts35[] = {
15 {0x32, KEY_MUTE},
16 {0x07, KEY_MEDIA},
17 {0x1c, KEY_AB},
18 {0x33, KEY_POWER},
19
20 {0x3e, KEY_1},
21 {0x3d, KEY_2},
22 {0x3c, KEY_3},
23 {0x3b, KEY_4},
24 {0x3a, KEY_5},
25 {0x39, KEY_6},
26 {0x38, KEY_7},
27 {0x37, KEY_8},
28 {0x36, KEY_9},
29 {0x3f, KEY_0},
30 {0x35, KEY_DIGITS},
31 {0x2c, KEY_TV},
32
33 {0x20, KEY_INFO},
34 {0x2d, KEY_MENU},
35 {0x1f, KEY_UP},
36 {0x1e, KEY_DOWN},
37 {0x2e, KEY_LEFT},
38 {0x2f, KEY_RIGHT},
39 {0x28, KEY_OK},
40 {0x10, KEY_EPG},
41 {0x1d, KEY_BACK},
42
43 {0x14, KEY_RED},
44 {0x13, KEY_GREEN},
45 {0x12, KEY_YELLOW},
46 {0x11, KEY_BLUE},
47
48 {0x09, KEY_SELECT},
49 {0x03, KEY_TEXT},
50 {0x16, KEY_STOP},
51 {0x30, KEY_HELP},
52};
53
54static struct rc_map_list technisat_ts35_map = {
55 .map = {
56 .scan = technisat_ts35,
57 .size = ARRAY_SIZE(technisat_ts35),
58 .rc_type = RC_TYPE_UNKNOWN,
59 .name = RC_MAP_TECHNISAT_TS35,
60 }
61};
62
63static int __init init_rc_map(void)
64{
65 return rc_map_register(&technisat_ts35_map);
66}
67
68static void __exit exit_rc_map(void)
69{
70 rc_map_unregister(&technisat_ts35_map);
71}
72
73module_init(init_rc_map)
74module_exit(exit_rc_map)
75
76MODULE_LICENSE("GPL");
diff --git a/drivers/media/rc/keymaps/rc-terratec-cinergy-c-pci.c b/drivers/media/rc/keymaps/rc-terratec-cinergy-c-pci.c
new file mode 100644
index 000000000000..7958f458527a
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-terratec-cinergy-c-pci.c
@@ -0,0 +1,88 @@
1/* keytable for Terratec Cinergy C PCI Remote Controller
2 *
3 * Copyright (c) 2010 by Igor M. Liplianin <liplianin@me.by>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#include <media/rc-map.h>
12#include <linux/module.h>
13
14static struct rc_map_table terratec_cinergy_c_pci[] = {
15 { 0x3e, KEY_POWER},
16 { 0x3d, KEY_1},
17 { 0x3c, KEY_2},
18 { 0x3b, KEY_3},
19 { 0x3a, KEY_4},
20 { 0x39, KEY_5},
21 { 0x38, KEY_6},
22 { 0x37, KEY_7},
23 { 0x36, KEY_8},
24 { 0x35, KEY_9},
25 { 0x34, KEY_VIDEO_NEXT}, /* AV */
26 { 0x33, KEY_0},
27 { 0x32, KEY_REFRESH},
28 { 0x30, KEY_EPG},
29 { 0x2f, KEY_UP},
30 { 0x2e, KEY_LEFT},
31 { 0x2d, KEY_OK},
32 { 0x2c, KEY_RIGHT},
33 { 0x2b, KEY_DOWN},
34 { 0x29, KEY_INFO},
35 { 0x28, KEY_RED},
36 { 0x27, KEY_GREEN},
37 { 0x26, KEY_YELLOW},
38 { 0x25, KEY_BLUE},
39 { 0x24, KEY_CHANNELUP},
40 { 0x23, KEY_VOLUMEUP},
41 { 0x22, KEY_MUTE},
42 { 0x21, KEY_VOLUMEDOWN},
43 { 0x20, KEY_CHANNELDOWN},
44 { 0x1f, KEY_PAUSE},
45 { 0x1e, KEY_HOME},
46 { 0x1d, KEY_MENU}, /* DVD Menu */
47 { 0x1c, KEY_SUBTITLE},
48 { 0x1b, KEY_TEXT}, /* Teletext */
49 { 0x1a, KEY_DELETE},
50 { 0x19, KEY_TV},
51 { 0x18, KEY_DVD},
52 { 0x17, KEY_STOP},
53 { 0x16, KEY_VIDEO},
54 { 0x15, KEY_AUDIO}, /* Music */
55 { 0x14, KEY_SCREEN}, /* Pic */
56 { 0x13, KEY_PLAY},
57 { 0x12, KEY_BACK},
58 { 0x11, KEY_REWIND},
59 { 0x10, KEY_FASTFORWARD},
60 { 0x0b, KEY_PREVIOUS},
61 { 0x07, KEY_RECORD},
62 { 0x03, KEY_NEXT},
63
64};
65
66static struct rc_map_list terratec_cinergy_c_pci_map = {
67 .map = {
68 .scan = terratec_cinergy_c_pci,
69 .size = ARRAY_SIZE(terratec_cinergy_c_pci),
70 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
71 .name = RC_MAP_TERRATEC_CINERGY_C_PCI,
72 }
73};
74
75static int __init init_rc_map_terratec_cinergy_c_pci(void)
76{
77 return rc_map_register(&terratec_cinergy_c_pci_map);
78}
79
80static void __exit exit_rc_map_terratec_cinergy_c_pci(void)
81{
82 rc_map_unregister(&terratec_cinergy_c_pci_map);
83}
84
85module_init(init_rc_map_terratec_cinergy_c_pci);
86module_exit(exit_rc_map_terratec_cinergy_c_pci);
87
88MODULE_LICENSE("GPL");
diff --git a/drivers/media/rc/keymaps/rc-terratec-cinergy-s2-hd.c b/drivers/media/rc/keymaps/rc-terratec-cinergy-s2-hd.c
new file mode 100644
index 000000000000..1e096bbda4a0
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-terratec-cinergy-s2-hd.c
@@ -0,0 +1,86 @@
1/* keytable for Terratec Cinergy S2 HD Remote Controller
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
9#include <media/rc-map.h>
10#include <linux/module.h>
11
12static struct rc_map_table terratec_cinergy_s2_hd[] = {
13 { 0x03, KEY_NEXT}, /* >| */
14 { 0x07, KEY_RECORD},
15 { 0x0b, KEY_PREVIOUS}, /* |< */
16 { 0x10, KEY_FASTFORWARD}, /* >> */
17 { 0x11, KEY_REWIND}, /* << */
18 { 0x12, KEY_ESC}, /* Back */
19 { 0x13, KEY_PLAY},
20 { 0x14, KEY_IMAGES},
21 { 0x15, KEY_AUDIO},
22 { 0x16, KEY_MEDIA}, /* Video-Menu */
23 { 0x17, KEY_STOP},
24 { 0x18, KEY_DVD},
25 { 0x19, KEY_TV},
26 { 0x1a, KEY_DELETE},
27 { 0x1b, KEY_TEXT},
28 { 0x1c, KEY_SUBTITLE},
29 { 0x1d, KEY_MENU}, /* DVD-Menu */
30 { 0x1e, KEY_HOME},
31 { 0x1f, KEY_PAUSE},
32 { 0x20, KEY_CHANNELDOWN},
33 { 0x21, KEY_VOLUMEDOWN},
34 { 0x22, KEY_MUTE},
35 { 0x23, KEY_VOLUMEUP},
36 { 0x24, KEY_CHANNELUP},
37 { 0x25, KEY_BLUE},
38 { 0x26, KEY_YELLOW},
39 { 0x27, KEY_GREEN},
40 { 0x28, KEY_RED},
41 { 0x29, KEY_INFO},
42 { 0x2b, KEY_DOWN},
43 { 0x2c, KEY_RIGHT},
44 { 0x2d, KEY_OK},
45 { 0x2e, KEY_LEFT},
46 { 0x2f, KEY_UP},
47 { 0x30, KEY_EPG},
48 { 0x32, KEY_VIDEO}, /* A<=>B */
49 { 0x33, KEY_0},
50 { 0x34, KEY_VCR}, /* AV */
51 { 0x35, KEY_9},
52 { 0x36, KEY_8},
53 { 0x37, KEY_7},
54 { 0x38, KEY_6},
55 { 0x39, KEY_5},
56 { 0x3a, KEY_4},
57 { 0x3b, KEY_3},
58 { 0x3c, KEY_2},
59 { 0x3d, KEY_1},
60 { 0x3e, KEY_POWER},
61
62};
63
64static struct rc_map_list terratec_cinergy_s2_hd_map = {
65 .map = {
66 .scan = terratec_cinergy_s2_hd,
67 .size = ARRAY_SIZE(terratec_cinergy_s2_hd),
68 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
69 .name = RC_MAP_TERRATEC_CINERGY_S2_HD,
70 }
71};
72
73static int __init init_rc_map_terratec_cinergy_s2_hd(void)
74{
75 return rc_map_register(&terratec_cinergy_s2_hd_map);
76}
77
78static void __exit exit_rc_map_terratec_cinergy_s2_hd(void)
79{
80 rc_map_unregister(&terratec_cinergy_s2_hd_map);
81}
82
83module_init(init_rc_map_terratec_cinergy_s2_hd);
84module_exit(exit_rc_map_terratec_cinergy_s2_hd);
85
86MODULE_LICENSE("GPL");
diff --git a/drivers/media/rc/keymaps/rc-twinhan-dtv-cab-ci.c b/drivers/media/rc/keymaps/rc-twinhan-dtv-cab-ci.c
new file mode 100644
index 000000000000..202500cb3061
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-twinhan-dtv-cab-ci.c
@@ -0,0 +1,98 @@
1/* keytable for Twinhan DTV CAB CI Remote Controller
2 *
3 * Copyright (c) 2010 by Igor M. Liplianin <liplianin@me.by>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#include <media/rc-map.h>
12#include <linux/module.h>
13
14static struct rc_map_table twinhan_dtv_cab_ci[] = {
15 { 0x29, KEY_POWER},
16 { 0x28, KEY_FAVORITES},
17 { 0x30, KEY_TEXT},
18 { 0x17, KEY_INFO}, /* Preview */
19 { 0x23, KEY_EPG},
20 { 0x3b, KEY_F22}, /* Record List */
21
22 { 0x3c, KEY_1},
23 { 0x3e, KEY_2},
24 { 0x39, KEY_3},
25 { 0x36, KEY_4},
26 { 0x22, KEY_5},
27 { 0x20, KEY_6},
28 { 0x32, KEY_7},
29 { 0x26, KEY_8},
30 { 0x24, KEY_9},
31 { 0x2a, KEY_0},
32
33 { 0x33, KEY_CANCEL},
34 { 0x2c, KEY_BACK},
35 { 0x15, KEY_CLEAR},
36 { 0x3f, KEY_TAB},
37 { 0x10, KEY_ENTER},
38 { 0x14, KEY_UP},
39 { 0x0d, KEY_RIGHT},
40 { 0x0e, KEY_DOWN},
41 { 0x11, KEY_LEFT},
42
43 { 0x21, KEY_VOLUMEUP},
44 { 0x35, KEY_VOLUMEDOWN},
45 { 0x3d, KEY_CHANNELDOWN},
46 { 0x3a, KEY_CHANNELUP},
47 { 0x2e, KEY_RECORD},
48 { 0x2b, KEY_PLAY},
49 { 0x13, KEY_PAUSE},
50 { 0x25, KEY_STOP},
51
52 { 0x1f, KEY_REWIND},
53 { 0x2d, KEY_FASTFORWARD},
54 { 0x1e, KEY_PREVIOUS}, /* Replay |< */
55 { 0x1d, KEY_NEXT}, /* Skip >| */
56
57 { 0x0b, KEY_CAMERA}, /* Capture */
58 { 0x0f, KEY_LANGUAGE}, /* SAP */
59 { 0x18, KEY_MODE}, /* PIP */
60 { 0x12, KEY_ZOOM}, /* Full screen */
61 { 0x1c, KEY_SUBTITLE},
62 { 0x2f, KEY_MUTE},
63 { 0x16, KEY_F20}, /* L/R */
64 { 0x38, KEY_F21}, /* Hibernate */
65
66 { 0x37, KEY_SWITCHVIDEOMODE}, /* A/V */
67 { 0x31, KEY_AGAIN}, /* Recall */
68 { 0x1a, KEY_KPPLUS}, /* Zoom+ */
69 { 0x19, KEY_KPMINUS}, /* Zoom- */
70 { 0x27, KEY_RED},
71 { 0x0C, KEY_GREEN},
72 { 0x01, KEY_YELLOW},
73 { 0x00, KEY_BLUE},
74};
75
76static struct rc_map_list twinhan_dtv_cab_ci_map = {
77 .map = {
78 .scan = twinhan_dtv_cab_ci,
79 .size = ARRAY_SIZE(twinhan_dtv_cab_ci),
80 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
81 .name = RC_MAP_TWINHAN_DTV_CAB_CI,
82 }
83};
84
85static int __init init_rc_map_twinhan_dtv_cab_ci(void)
86{
87 return rc_map_register(&twinhan_dtv_cab_ci_map);
88}
89
90static void __exit exit_rc_map_twinhan_dtv_cab_ci(void)
91{
92 rc_map_unregister(&twinhan_dtv_cab_ci_map);
93}
94
95module_init(init_rc_map_twinhan_dtv_cab_ci);
96module_exit(exit_rc_map_twinhan_dtv_cab_ci);
97
98MODULE_LICENSE("GPL");
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index 85af7a869167..baeb5971fd52 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -526,6 +526,130 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
526 return 0; 526 return 0;
527} 527}
528 528
529static int nvt_write_wakeup_codes(struct rc_dev *dev,
530 const u8 *wakeup_sample_buf, int count)
531{
532 int i = 0;
533 u8 reg, reg_learn_mode;
534 unsigned long flags;
535 struct nvt_dev *nvt = dev->priv;
536
537 nvt_dbg_wake("writing wakeup samples");
538
539 reg = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON);
540 reg_learn_mode = reg & ~CIR_WAKE_IRCON_MODE0;
541 reg_learn_mode |= CIR_WAKE_IRCON_MODE1;
542
543 /* Lock the learn area to prevent racing with wake-isr */
544 spin_lock_irqsave(&nvt->nvt_lock, flags);
545
546 /* Enable fifo writes */
547 nvt_cir_wake_reg_write(nvt, reg_learn_mode, CIR_WAKE_IRCON);
548
549 /* Clear cir wake rx fifo */
550 nvt_clear_cir_wake_fifo(nvt);
551
552 if (count > WAKE_FIFO_LEN) {
553 nvt_dbg_wake("HW FIFO too small for all wake samples");
554 count = WAKE_FIFO_LEN;
555 }
556
557 if (count)
558 pr_info("Wake samples (%d) =", count);
559 else
560 pr_info("Wake sample fifo cleared");
561
562 /* Write wake samples to fifo */
563 for (i = 0; i < count; i++) {
564 pr_cont(" %02x", wakeup_sample_buf[i]);
565 nvt_cir_wake_reg_write(nvt, wakeup_sample_buf[i],
566 CIR_WAKE_WR_FIFO_DATA);
567 }
568 pr_cont("\n");
569
570 /* Switch cir to wakeup mode and disable fifo writing */
571 nvt_cir_wake_reg_write(nvt, reg, CIR_WAKE_IRCON);
572
573 /* Set number of bytes needed for wake */
574 nvt_cir_wake_reg_write(nvt, count ? count :
575 CIR_WAKE_FIFO_CMP_BYTES,
576 CIR_WAKE_FIFO_CMP_DEEP);
577
578 spin_unlock_irqrestore(&nvt->nvt_lock, flags);
579
580 return 0;
581}
582
583static int nvt_ir_raw_set_wakeup_filter(struct rc_dev *dev,
584 struct rc_scancode_filter *sc_filter)
585{
586 u8 *reg_buf;
587 u8 buf_val;
588 int i, ret, count;
589 unsigned int val;
590 struct ir_raw_event *raw;
591 bool complete;
592
593 /* Require both mask and data to be set before actually committing */
594 if (!sc_filter->mask || !sc_filter->data)
595 return 0;
596
597 raw = kmalloc_array(WAKE_FIFO_LEN, sizeof(*raw), GFP_KERNEL);
598 if (!raw)
599 return -ENOMEM;
600
601 ret = ir_raw_encode_scancode(dev->enabled_wakeup_protocols, sc_filter,
602 raw, WAKE_FIFO_LEN);
603 complete = (ret != -ENOBUFS);
604 if (!complete)
605 ret = WAKE_FIFO_LEN;
606 else if (ret < 0)
607 goto out_raw;
608
609 reg_buf = kmalloc_array(WAKE_FIFO_LEN, sizeof(*reg_buf), GFP_KERNEL);
610 if (!reg_buf) {
611 ret = -ENOMEM;
612 goto out_raw;
613 }
614
615 /* Inspect the ir samples */
616 for (i = 0, count = 0; i < ret && count < WAKE_FIFO_LEN; ++i) {
617 val = NS_TO_US((raw[i]).duration) / SAMPLE_PERIOD;
618
619 /* Split too large values into several smaller ones */
620 while (val > 0 && count < WAKE_FIFO_LEN) {
621
622 /* Skip last value for better comparison tolerance */
623 if (complete && i == ret - 1 && val < BUF_LEN_MASK)
624 break;
625
626 /* Clamp values to BUF_LEN_MASK at most */
627 buf_val = (val > BUF_LEN_MASK) ? BUF_LEN_MASK : val;
628
629 reg_buf[count] = buf_val;
630 val -= buf_val;
631 if ((raw[i]).pulse)
632 reg_buf[count] |= BUF_PULSE_BIT;
633 count++;
634 }
635 }
636
637 ret = nvt_write_wakeup_codes(dev, reg_buf, count);
638
639 kfree(reg_buf);
640out_raw:
641 kfree(raw);
642
643 return ret;
644}
645
646/* Dummy implementation. nuvoton is agnostic to the protocol used */
647static int nvt_ir_raw_change_wakeup_protocol(struct rc_dev *dev,
648 u64 *rc_type)
649{
650 return 0;
651}
652
529/* 653/*
530 * nvt_tx_ir 654 * nvt_tx_ir
531 * 655 *
@@ -1043,11 +1167,14 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
1043 /* Set up the rc device */ 1167 /* Set up the rc device */
1044 rdev->priv = nvt; 1168 rdev->priv = nvt;
1045 rdev->driver_type = RC_DRIVER_IR_RAW; 1169 rdev->driver_type = RC_DRIVER_IR_RAW;
1170 rdev->encode_wakeup = true;
1046 rdev->allowed_protocols = RC_BIT_ALL; 1171 rdev->allowed_protocols = RC_BIT_ALL;
1047 rdev->open = nvt_open; 1172 rdev->open = nvt_open;
1048 rdev->close = nvt_close; 1173 rdev->close = nvt_close;
1049 rdev->tx_ir = nvt_tx_ir; 1174 rdev->tx_ir = nvt_tx_ir;
1050 rdev->s_tx_carrier = nvt_set_tx_carrier; 1175 rdev->s_tx_carrier = nvt_set_tx_carrier;
1176 rdev->s_wakeup_filter = nvt_ir_raw_set_wakeup_filter;
1177 rdev->change_wakeup_protocol = nvt_ir_raw_change_wakeup_protocol;
1051 rdev->input_name = "Nuvoton w836x7hg Infrared Remote Transceiver"; 1178 rdev->input_name = "Nuvoton w836x7hg Infrared Remote Transceiver";
1052 rdev->input_phys = "nuvoton/cir0"; 1179 rdev->input_phys = "nuvoton/cir0";
1053 rdev->input_id.bustype = BUS_HOST; 1180 rdev->input_id.bustype = BUS_HOST;
diff --git a/drivers/media/rc/nuvoton-cir.h b/drivers/media/rc/nuvoton-cir.h
index e1cf23c3875b..9d0e161c2a88 100644
--- a/drivers/media/rc/nuvoton-cir.h
+++ b/drivers/media/rc/nuvoton-cir.h
@@ -63,6 +63,7 @@ static int debug;
63 */ 63 */
64#define TX_BUF_LEN 256 64#define TX_BUF_LEN 256
65#define RX_BUF_LEN 32 65#define RX_BUF_LEN 32
66#define WAKE_FIFO_LEN 67
66 67
67struct nvt_dev { 68struct nvt_dev {
68 struct pnp_dev *pdev; 69 struct pnp_dev *pdev;
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index b68d4f762734..4b994aa2f2a7 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -25,6 +25,8 @@ struct ir_raw_handler {
25 25
26 u64 protocols; /* which are handled by this handler */ 26 u64 protocols; /* which are handled by this handler */
27 int (*decode)(struct rc_dev *dev, struct ir_raw_event event); 27 int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
28 int (*encode)(u64 protocols, const struct rc_scancode_filter *scancode,
29 struct ir_raw_event *events, unsigned int max);
28 30
29 /* These two should only be used by the lirc decoder */ 31 /* These two should only be used by the lirc decoder */
30 int (*raw_register)(struct rc_dev *dev); 32 int (*raw_register)(struct rc_dev *dev);
@@ -150,10 +152,44 @@ static inline bool is_timing_event(struct ir_raw_event ev)
150#define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000) 152#define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000)
151#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space") 153#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space")
152 154
155/* functions for IR encoders */
156
157static inline void init_ir_raw_event_duration(struct ir_raw_event *ev,
158 unsigned int pulse,
159 u32 duration)
160{
161 init_ir_raw_event(ev);
162 ev->duration = duration;
163 ev->pulse = pulse;
164}
165
166/**
167 * struct ir_raw_timings_manchester - Manchester coding timings
168 * @leader: duration of leader pulse (if any) 0 if continuing
169 * existing signal (see @pulse_space_start)
170 * @pulse_space_start: 1 for starting with pulse (0 for starting with space)
171 * @clock: duration of each pulse/space in ns
172 * @invert: if set clock logic is inverted
173 * (0 = space + pulse, 1 = pulse + space)
174 * @trailer_space: duration of trailer space in ns
175 */
176struct ir_raw_timings_manchester {
177 unsigned int leader;
178 unsigned int pulse_space_start:1;
179 unsigned int clock;
180 unsigned int invert:1;
181 unsigned int trailer_space;
182};
183
184int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
185 const struct ir_raw_timings_manchester *timings,
186 unsigned int n, unsigned int data);
187
153/* 188/*
154 * Routines from rc-raw.c to be used internally and by decoders 189 * Routines from rc-raw.c to be used internally and by decoders
155 */ 190 */
156u64 ir_raw_get_allowed_protocols(void); 191u64 ir_raw_get_allowed_protocols(void);
192u64 ir_raw_get_encode_protocols(void);
157int ir_raw_event_register(struct rc_dev *dev); 193int ir_raw_event_register(struct rc_dev *dev);
158void ir_raw_event_unregister(struct rc_dev *dev); 194void ir_raw_event_unregister(struct rc_dev *dev);
159int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler); 195int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
index b732ac6a26d8..b9e4645c731c 100644
--- a/drivers/media/rc/rc-ir-raw.c
+++ b/drivers/media/rc/rc-ir-raw.c
@@ -30,6 +30,7 @@ static LIST_HEAD(ir_raw_client_list);
30static DEFINE_MUTEX(ir_raw_handler_lock); 30static DEFINE_MUTEX(ir_raw_handler_lock);
31static LIST_HEAD(ir_raw_handler_list); 31static LIST_HEAD(ir_raw_handler_list);
32static u64 available_protocols; 32static u64 available_protocols;
33static u64 encode_protocols;
33 34
34static int ir_raw_event_thread(void *data) 35static int ir_raw_event_thread(void *data)
35{ 36{
@@ -240,12 +241,146 @@ ir_raw_get_allowed_protocols(void)
240 return protocols; 241 return protocols;
241} 242}
242 243
244/* used internally by the sysfs interface */
245u64
246ir_raw_get_encode_protocols(void)
247{
248 u64 protocols;
249
250 mutex_lock(&ir_raw_handler_lock);
251 protocols = encode_protocols;
252 mutex_unlock(&ir_raw_handler_lock);
253 return protocols;
254}
255
243static int change_protocol(struct rc_dev *dev, u64 *rc_type) 256static int change_protocol(struct rc_dev *dev, u64 *rc_type)
244{ 257{
245 /* the caller will update dev->enabled_protocols */ 258 /* the caller will update dev->enabled_protocols */
246 return 0; 259 return 0;
247} 260}
248 261
262/**
263 * ir_raw_gen_manchester() - Encode data with Manchester (bi-phase) modulation.
264 * @ev: Pointer to pointer to next free event. *@ev is incremented for
265 * each raw event filled.
266 * @max: Maximum number of raw events to fill.
267 * @timings: Manchester modulation timings.
268 * @n: Number of bits of data.
269 * @data: Data bits to encode.
270 *
271 * Encodes the @n least significant bits of @data using Manchester (bi-phase)
272 * modulation with the timing characteristics described by @timings, writing up
273 * to @max raw IR events using the *@ev pointer.
274 *
275 * Returns: 0 on success.
276 * -ENOBUFS if there isn't enough space in the array to fit the
277 * full encoded data. In this case all @max events will have been
278 * written.
279 */
280int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
281 const struct ir_raw_timings_manchester *timings,
282 unsigned int n, unsigned int data)
283{
284 bool need_pulse;
285 unsigned int i;
286 int ret = -ENOBUFS;
287
288 i = 1 << (n - 1);
289
290 if (timings->leader) {
291 if (!max--)
292 return ret;
293 if (timings->pulse_space_start) {
294 init_ir_raw_event_duration((*ev)++, 1, timings->leader);
295
296 if (!max--)
297 return ret;
298 init_ir_raw_event_duration((*ev), 0, timings->leader);
299 } else {
300 init_ir_raw_event_duration((*ev), 1, timings->leader);
301 }
302 i >>= 1;
303 } else {
304 /* continue existing signal */
305 --(*ev);
306 }
307 /* from here on *ev will point to the last event rather than the next */
308
309 while (n && i > 0) {
310 need_pulse = !(data & i);
311 if (timings->invert)
312 need_pulse = !need_pulse;
313 if (need_pulse == !!(*ev)->pulse) {
314 (*ev)->duration += timings->clock;
315 } else {
316 if (!max--)
317 goto nobufs;
318 init_ir_raw_event_duration(++(*ev), need_pulse,
319 timings->clock);
320 }
321
322 if (!max--)
323 goto nobufs;
324 init_ir_raw_event_duration(++(*ev), !need_pulse,
325 timings->clock);
326 i >>= 1;
327 }
328
329 if (timings->trailer_space) {
330 if (!(*ev)->pulse)
331 (*ev)->duration += timings->trailer_space;
332 else if (!max--)
333 goto nobufs;
334 else
335 init_ir_raw_event_duration(++(*ev), 0,
336 timings->trailer_space);
337 }
338
339 ret = 0;
340nobufs:
341 /* point to the next event rather than last event before returning */
342 ++(*ev);
343 return ret;
344}
345EXPORT_SYMBOL(ir_raw_gen_manchester);
346
347/**
348 * ir_raw_encode_scancode() - Encode a scancode as raw events
349 *
350 * @protocols: permitted protocols
351 * @scancode: scancode filter describing a single scancode
352 * @events: array of raw events to write into
353 * @max: max number of raw events
354 *
355 * Attempts to encode the scancode as raw events.
356 *
357 * Returns: The number of events written.
358 * -ENOBUFS if there isn't enough space in the array to fit the
359 * encoding. In this case all @max events will have been written.
360 * -EINVAL if the scancode is ambiguous or invalid, or if no
361 * compatible encoder was found.
362 */
363int ir_raw_encode_scancode(u64 protocols,
364 const struct rc_scancode_filter *scancode,
365 struct ir_raw_event *events, unsigned int max)
366{
367 struct ir_raw_handler *handler;
368 int ret = -EINVAL;
369
370 mutex_lock(&ir_raw_handler_lock);
371 list_for_each_entry(handler, &ir_raw_handler_list, list) {
372 if (handler->protocols & protocols && handler->encode) {
373 ret = handler->encode(protocols, scancode, events, max);
374 if (ret >= 0 || ret == -ENOBUFS)
375 break;
376 }
377 }
378 mutex_unlock(&ir_raw_handler_lock);
379
380 return ret;
381}
382EXPORT_SYMBOL(ir_raw_encode_scancode);
383
249/* 384/*
250 * Used to (un)register raw event clients 385 * Used to (un)register raw event clients
251 */ 386 */
@@ -328,6 +463,8 @@ int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler)
328 list_for_each_entry(raw, &ir_raw_client_list, list) 463 list_for_each_entry(raw, &ir_raw_client_list, list)
329 ir_raw_handler->raw_register(raw->dev); 464 ir_raw_handler->raw_register(raw->dev);
330 available_protocols |= ir_raw_handler->protocols; 465 available_protocols |= ir_raw_handler->protocols;
466 if (ir_raw_handler->encode)
467 encode_protocols |= ir_raw_handler->protocols;
331 mutex_unlock(&ir_raw_handler_lock); 468 mutex_unlock(&ir_raw_handler_lock);
332 469
333 return 0; 470 return 0;
@@ -344,6 +481,8 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)
344 list_for_each_entry(raw, &ir_raw_client_list, list) 481 list_for_each_entry(raw, &ir_raw_client_list, list)
345 ir_raw_handler->raw_unregister(raw->dev); 482 ir_raw_handler->raw_unregister(raw->dev);
346 available_protocols &= ~ir_raw_handler->protocols; 483 available_protocols &= ~ir_raw_handler->protocols;
484 if (ir_raw_handler->encode)
485 encode_protocols &= ~ir_raw_handler->protocols;
347 mutex_unlock(&ir_raw_handler_lock); 486 mutex_unlock(&ir_raw_handler_lock);
348} 487}
349EXPORT_SYMBOL(ir_raw_handler_unregister); 488EXPORT_SYMBOL(ir_raw_handler_unregister);
diff --git a/drivers/media/rc/rc-loopback.c b/drivers/media/rc/rc-loopback.c
index 63dace8198b0..d8bdf63ce985 100644
--- a/drivers/media/rc/rc-loopback.c
+++ b/drivers/media/rc/rc-loopback.c
@@ -26,6 +26,7 @@
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/slab.h>
29#include <media/rc-core.h> 30#include <media/rc-core.h>
30 31
31#define DRIVER_NAME "rc-loopback" 32#define DRIVER_NAME "rc-loopback"
@@ -176,6 +177,39 @@ static int loop_set_carrier_report(struct rc_dev *dev, int enable)
176 return 0; 177 return 0;
177} 178}
178 179
180static int loop_set_wakeup_filter(struct rc_dev *dev,
181 struct rc_scancode_filter *sc_filter)
182{
183 static const unsigned int max = 512;
184 struct ir_raw_event *raw;
185 int ret;
186 int i;
187
188 /* fine to disable filter */
189 if (!sc_filter->mask)
190 return 0;
191
192 /* encode the specified filter and loop it back */
193 raw = kmalloc_array(max, sizeof(*raw), GFP_KERNEL);
194 ret = ir_raw_encode_scancode(dev->enabled_wakeup_protocols, sc_filter,
195 raw, max);
196 /* still loop back the partial raw IR even if it's incomplete */
197 if (ret == -ENOBUFS)
198 ret = max;
199 if (ret >= 0) {
200 /* do the loopback */
201 for (i = 0; i < ret; ++i)
202 ir_raw_event_store(dev, &raw[i]);
203 ir_raw_event_handle(dev);
204
205 ret = 0;
206 }
207
208 kfree(raw);
209
210 return ret;
211}
212
179static int __init loop_init(void) 213static int __init loop_init(void)
180{ 214{
181 struct rc_dev *rc; 215 struct rc_dev *rc;
@@ -195,6 +229,7 @@ static int __init loop_init(void)
195 rc->map_name = RC_MAP_EMPTY; 229 rc->map_name = RC_MAP_EMPTY;
196 rc->priv = &loopdev; 230 rc->priv = &loopdev;
197 rc->driver_type = RC_DRIVER_IR_RAW; 231 rc->driver_type = RC_DRIVER_IR_RAW;
232 rc->encode_wakeup = true;
198 rc->allowed_protocols = RC_BIT_ALL; 233 rc->allowed_protocols = RC_BIT_ALL;
199 rc->timeout = 100 * 1000 * 1000; /* 100 ms */ 234 rc->timeout = 100 * 1000 * 1000; /* 100 ms */
200 rc->min_timeout = 1; 235 rc->min_timeout = 1;
@@ -209,6 +244,7 @@ static int __init loop_init(void)
209 rc->s_idle = loop_set_idle; 244 rc->s_idle = loop_set_idle;
210 rc->s_learning_mode = loop_set_learning_mode; 245 rc->s_learning_mode = loop_set_learning_mode;
211 rc->s_carrier_report = loop_set_carrier_report; 246 rc->s_carrier_report = loop_set_carrier_report;
247 rc->s_wakeup_filter = loop_set_wakeup_filter;
212 248
213 loopdev.txmask = RXMASK_REGULAR; 249 loopdev.txmask = RXMASK_REGULAR;
214 loopdev.txcarrier = 36000; 250 loopdev.txcarrier = 36000;
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index f8c5e47a30aa..9d015db65280 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -746,7 +746,7 @@ void rc_close(struct rc_dev *rdev)
746 if (rdev) { 746 if (rdev) {
747 mutex_lock(&rdev->lock); 747 mutex_lock(&rdev->lock);
748 748
749 if (!--rdev->users && rdev->close != NULL) 749 if (!--rdev->users && rdev->close != NULL)
750 rdev->close(rdev); 750 rdev->close(rdev);
751 751
752 mutex_unlock(&rdev->lock); 752 mutex_unlock(&rdev->lock);
@@ -865,6 +865,8 @@ static ssize_t show_protocols(struct device *device,
865 } else { 865 } else {
866 enabled = dev->enabled_wakeup_protocols; 866 enabled = dev->enabled_wakeup_protocols;
867 allowed = dev->allowed_wakeup_protocols; 867 allowed = dev->allowed_wakeup_protocols;
868 if (dev->encode_wakeup && !allowed)
869 allowed = ir_raw_get_encode_protocols();
868 } 870 }
869 871
870 mutex_unlock(&dev->lock); 872 mutex_unlock(&dev->lock);
@@ -1406,13 +1408,16 @@ int rc_register_device(struct rc_dev *dev)
1406 path ? path : "N/A"); 1408 path ? path : "N/A");
1407 kfree(path); 1409 kfree(path);
1408 1410
1409 if (dev->driver_type == RC_DRIVER_IR_RAW) { 1411 if (dev->driver_type == RC_DRIVER_IR_RAW || dev->encode_wakeup) {
1410 /* Load raw decoders, if they aren't already */ 1412 /* Load raw decoders, if they aren't already */
1411 if (!raw_init) { 1413 if (!raw_init) {
1412 IR_dprintk(1, "Loading raw decoders\n"); 1414 IR_dprintk(1, "Loading raw decoders\n");
1413 ir_raw_init(); 1415 ir_raw_init();
1414 raw_init = true; 1416 raw_init = true;
1415 } 1417 }
1418 }
1419
1420 if (dev->driver_type == RC_DRIVER_IR_RAW) {
1416 /* calls ir_register_device so unlock mutex here*/ 1421 /* calls ir_register_device so unlock mutex here*/
1417 mutex_unlock(&dev->lock); 1422 mutex_unlock(&dev->lock);
1418 rc = ir_raw_event_register(dev); 1423 rc = ir_raw_event_register(dev);
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index c4def66f9aa2..ec74244a3853 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -322,7 +322,7 @@ static u32 redrat3_us_to_len(u32 microsec)
322 u32 result; 322 u32 result;
323 u32 divisor; 323 u32 divisor;
324 324
325 microsec &= IR_MAX_DURATION; 325 microsec = (microsec > IR_MAX_DURATION) ? IR_MAX_DURATION : microsec;
326 divisor = (RR3_CLK_CONV_FACTOR / 1000); 326 divisor = (RR3_CLK_CONV_FACTOR / 1000);
327 result = (u32)(microsec * divisor) / 1000; 327 result = (u32)(microsec * divisor) / 1000;
328 328
@@ -380,7 +380,8 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)
380 if (i == 0) 380 if (i == 0)
381 trailer = rawir.duration; 381 trailer = rawir.duration;
382 /* cap the value to IR_MAX_DURATION */ 382 /* cap the value to IR_MAX_DURATION */
383 rawir.duration &= IR_MAX_DURATION; 383 rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
384 IR_MAX_DURATION : rawir.duration;
384 385
385 dev_dbg(dev, "storing %s with duration %d (i: %d)\n", 386 dev_dbg(dev, "storing %s with duration %d (i: %d)\n",
386 rawir.pulse ? "pulse" : "space", rawir.duration, i); 387 rawir.pulse ? "pulse" : "space", rawir.duration, i);
@@ -405,7 +406,7 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)
405} 406}
406 407
407/* Util fn to send rr3 cmds */ 408/* Util fn to send rr3 cmds */
408static u8 redrat3_send_cmd(int cmd, struct redrat3_dev *rr3) 409static int redrat3_send_cmd(int cmd, struct redrat3_dev *rr3)
409{ 410{
410 struct usb_device *udev; 411 struct usb_device *udev;
411 u8 *data; 412 u8 *data;
diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
index 0e758ae2e529..37d040158dff 100644
--- a/drivers/media/rc/st_rc.c
+++ b/drivers/media/rc/st_rc.c
@@ -22,8 +22,8 @@ struct st_rc_device {
22 int irq; 22 int irq;
23 int irq_wake; 23 int irq_wake;
24 struct clk *sys_clock; 24 struct clk *sys_clock;
25 volatile void __iomem *base; /* Register base address */ 25 void __iomem *base; /* Register base address */
26 volatile void __iomem *rx_base;/* RX Register base address */ 26 void __iomem *rx_base;/* RX Register base address */
27 struct rc_dev *rdev; 27 struct rc_dev *rdev;
28 bool overclocking; 28 bool overclocking;
29 int sample_mult; 29 int sample_mult;
@@ -267,8 +267,8 @@ static int st_rc_probe(struct platform_device *pdev)
267 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 267 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
268 268
269 rc_dev->base = devm_ioremap_resource(dev, res); 269 rc_dev->base = devm_ioremap_resource(dev, res);
270 if (IS_ERR((__force void *)rc_dev->base)) { 270 if (IS_ERR(rc_dev->base)) {
271 ret = PTR_ERR((__force void *)rc_dev->base); 271 ret = PTR_ERR(rc_dev->base);
272 goto err; 272 goto err;
273 } 273 }
274 274
@@ -334,7 +334,7 @@ err:
334 return ret; 334 return ret;
335} 335}
336 336
337#ifdef CONFIG_PM 337#ifdef CONFIG_PM_SLEEP
338static int st_rc_suspend(struct device *dev) 338static int st_rc_suspend(struct device *dev)
339{ 339{
340 struct st_rc_device *rc_dev = dev_get_drvdata(dev); 340 struct st_rc_device *rc_dev = dev_get_drvdata(dev);
@@ -381,7 +381,7 @@ static int st_rc_resume(struct device *dev)
381static SIMPLE_DEV_PM_OPS(st_rc_pm_ops, st_rc_suspend, st_rc_resume); 381static SIMPLE_DEV_PM_OPS(st_rc_pm_ops, st_rc_suspend, st_rc_resume);
382 382
383#ifdef CONFIG_OF 383#ifdef CONFIG_OF
384static struct of_device_id st_rc_match[] = { 384static const struct of_device_id st_rc_match[] = {
385 { .compatible = "st,comms-irb", }, 385 { .compatible = "st,comms-irb", },
386 {}, 386 {},
387}; 387};
diff --git a/drivers/media/rc/streamzap.c b/drivers/media/rc/streamzap.c
index bf4a44272f0e..5a17cb88ff27 100644
--- a/drivers/media/rc/streamzap.c
+++ b/drivers/media/rc/streamzap.c
@@ -152,7 +152,8 @@ static void sz_push_full_pulse(struct streamzap_ir *sz,
152 sz->signal_last.tv_usec); 152 sz->signal_last.tv_usec);
153 rawir.duration -= sz->sum; 153 rawir.duration -= sz->sum;
154 rawir.duration = US_TO_NS(rawir.duration); 154 rawir.duration = US_TO_NS(rawir.duration);
155 rawir.duration &= IR_MAX_DURATION; 155 rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
156 IR_MAX_DURATION : rawir.duration;
156 } 157 }
157 sz_push(sz, rawir); 158 sz_push(sz, rawir);
158 159
@@ -165,7 +166,8 @@ static void sz_push_full_pulse(struct streamzap_ir *sz,
165 rawir.duration += SZ_RESOLUTION / 2; 166 rawir.duration += SZ_RESOLUTION / 2;
166 sz->sum += rawir.duration; 167 sz->sum += rawir.duration;
167 rawir.duration = US_TO_NS(rawir.duration); 168 rawir.duration = US_TO_NS(rawir.duration);
168 rawir.duration &= IR_MAX_DURATION; 169 rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
170 IR_MAX_DURATION : rawir.duration;
169 sz_push(sz, rawir); 171 sz_push(sz, rawir);
170} 172}
171 173
diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index 983510d282f6..8294af909174 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -220,6 +220,7 @@ config MEDIA_TUNER_E4000
220config MEDIA_TUNER_FC2580 220config MEDIA_TUNER_FC2580
221 tristate "FCI FC2580 silicon tuner" 221 tristate "FCI FC2580 silicon tuner"
222 depends on MEDIA_SUPPORT && I2C 222 depends on MEDIA_SUPPORT && I2C
223 select REGMAP_I2C
223 default m if !MEDIA_SUBDRV_AUTOSELECT 224 default m if !MEDIA_SUBDRV_AUTOSELECT
224 help 225 help
225 FCI FC2580 silicon tuner driver. 226 FCI FC2580 silicon tuner driver.
@@ -233,8 +234,9 @@ config MEDIA_TUNER_M88RS6000T
233 Montage M88RS6000 internal tuner. 234 Montage M88RS6000 internal tuner.
234 235
235config MEDIA_TUNER_TUA9001 236config MEDIA_TUNER_TUA9001
236 tristate "Infineon TUA 9001 silicon tuner" 237 tristate "Infineon TUA9001 silicon tuner"
237 depends on MEDIA_SUPPORT && I2C 238 depends on MEDIA_SUPPORT && I2C
239 select REGMAP_I2C
238 default m if !MEDIA_SUBDRV_AUTOSELECT 240 default m if !MEDIA_SUBDRV_AUTOSELECT
239 help 241 help
240 Infineon TUA 9001 silicon tuner driver. 242 Infineon TUA 9001 silicon tuner driver.
@@ -258,6 +260,7 @@ config MEDIA_TUNER_R820T
258 tristate "Rafael Micro R820T silicon tuner" 260 tristate "Rafael Micro R820T silicon tuner"
259 depends on MEDIA_SUPPORT && I2C 261 depends on MEDIA_SUPPORT && I2C
260 default m if !MEDIA_SUBDRV_AUTOSELECT 262 default m if !MEDIA_SUBDRV_AUTOSELECT
263 select BITREVERSE
261 help 264 help
262 Rafael Micro R820T silicon tuner driver. 265 Rafael Micro R820T silicon tuner driver.
263 266
diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 510239f80c0d..03538f88f488 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -19,164 +19,176 @@
19 */ 19 */
20 20
21#include "e4000_priv.h" 21#include "e4000_priv.h"
22#include <linux/math64.h>
23 22
24static int e4000_init(struct dvb_frontend *fe) 23static int e4000_init(struct e4000_dev *dev)
25{ 24{
26 struct e4000 *s = fe->tuner_priv; 25 struct i2c_client *client = dev->client;
27 int ret; 26 int ret;
28 27
29 dev_dbg(&s->client->dev, "\n"); 28 dev_dbg(&client->dev, "\n");
30
31 /* dummy I2C to ensure I2C wakes up */
32 ret = regmap_write(s->regmap, 0x02, 0x40);
33 29
34 /* reset */ 30 /* reset */
35 ret = regmap_write(s->regmap, 0x00, 0x01); 31 ret = regmap_write(dev->regmap, 0x00, 0x01);
36 if (ret) 32 if (ret)
37 goto err; 33 goto err;
38 34
39 /* disable output clock */ 35 /* disable output clock */
40 ret = regmap_write(s->regmap, 0x06, 0x00); 36 ret = regmap_write(dev->regmap, 0x06, 0x00);
41 if (ret) 37 if (ret)
42 goto err; 38 goto err;
43 39
44 ret = regmap_write(s->regmap, 0x7a, 0x96); 40 ret = regmap_write(dev->regmap, 0x7a, 0x96);
45 if (ret) 41 if (ret)
46 goto err; 42 goto err;
47 43
48 /* configure gains */ 44 /* configure gains */
49 ret = regmap_bulk_write(s->regmap, 0x7e, "\x01\xfe", 2); 45 ret = regmap_bulk_write(dev->regmap, 0x7e, "\x01\xfe", 2);
50 if (ret) 46 if (ret)
51 goto err; 47 goto err;
52 48
53 ret = regmap_write(s->regmap, 0x82, 0x00); 49 ret = regmap_write(dev->regmap, 0x82, 0x00);
54 if (ret) 50 if (ret)
55 goto err; 51 goto err;
56 52
57 ret = regmap_write(s->regmap, 0x24, 0x05); 53 ret = regmap_write(dev->regmap, 0x24, 0x05);
58 if (ret) 54 if (ret)
59 goto err; 55 goto err;
60 56
61 ret = regmap_bulk_write(s->regmap, 0x87, "\x20\x01", 2); 57 ret = regmap_bulk_write(dev->regmap, 0x87, "\x20\x01", 2);
62 if (ret) 58 if (ret)
63 goto err; 59 goto err;
64 60
65 ret = regmap_bulk_write(s->regmap, 0x9f, "\x7f\x07", 2); 61 ret = regmap_bulk_write(dev->regmap, 0x9f, "\x7f\x07", 2);
66 if (ret) 62 if (ret)
67 goto err; 63 goto err;
68 64
69 /* DC offset control */ 65 /* DC offset control */
70 ret = regmap_write(s->regmap, 0x2d, 0x1f); 66 ret = regmap_write(dev->regmap, 0x2d, 0x1f);
71 if (ret) 67 if (ret)
72 goto err; 68 goto err;
73 69
74 ret = regmap_bulk_write(s->regmap, 0x70, "\x01\x01", 2); 70 ret = regmap_bulk_write(dev->regmap, 0x70, "\x01\x01", 2);
75 if (ret) 71 if (ret)
76 goto err; 72 goto err;
77 73
78 /* gain control */ 74 /* gain control */
79 ret = regmap_write(s->regmap, 0x1a, 0x17); 75 ret = regmap_write(dev->regmap, 0x1a, 0x17);
80 if (ret) 76 if (ret)
81 goto err; 77 goto err;
82 78
83 ret = regmap_write(s->regmap, 0x1f, 0x1a); 79 ret = regmap_write(dev->regmap, 0x1f, 0x1a);
84 if (ret) 80 if (ret)
85 goto err; 81 goto err;
86 82
87 s->active = true; 83 dev->active = true;
88err:
89 if (ret)
90 dev_dbg(&s->client->dev, "failed=%d\n", ret);
91 84
85 return 0;
86err:
87 dev_dbg(&client->dev, "failed=%d\n", ret);
92 return ret; 88 return ret;
93} 89}
94 90
95static int e4000_sleep(struct dvb_frontend *fe) 91static int e4000_sleep(struct e4000_dev *dev)
96{ 92{
97 struct e4000 *s = fe->tuner_priv; 93 struct i2c_client *client = dev->client;
98 int ret; 94 int ret;
99 95
100 dev_dbg(&s->client->dev, "\n"); 96 dev_dbg(&client->dev, "\n");
101 97
102 s->active = false; 98 dev->active = false;
103 99
104 ret = regmap_write(s->regmap, 0x00, 0x00); 100 ret = regmap_write(dev->regmap, 0x00, 0x00);
105 if (ret) 101 if (ret)
106 goto err; 102 goto err;
107err:
108 if (ret)
109 dev_dbg(&s->client->dev, "failed=%d\n", ret);
110 103
104 return 0;
105err:
106 dev_dbg(&client->dev, "failed=%d\n", ret);
111 return ret; 107 return ret;
112} 108}
113 109
114static int e4000_set_params(struct dvb_frontend *fe) 110static int e4000_set_params(struct e4000_dev *dev)
115{ 111{
116 struct e4000 *s = fe->tuner_priv; 112 struct i2c_client *client = dev->client;
117 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 113 int ret, i;
118 int ret, i, sigma_delta; 114 unsigned int div_n, k, k_cw, div_out;
119 unsigned int pll_n, pll_f;
120 u64 f_vco; 115 u64 f_vco;
121 u8 buf[5], i_data[4], q_data[4]; 116 u8 buf[5], i_data[4], q_data[4];
122 117
123 dev_dbg(&s->client->dev, 118 if (!dev->active) {
124 "delivery_system=%d frequency=%u bandwidth_hz=%u\n", 119 dev_dbg(&client->dev, "tuner is sleeping\n");
125 c->delivery_system, c->frequency, c->bandwidth_hz); 120 return 0;
121 }
126 122
127 /* gain control manual */ 123 /* gain control manual */
128 ret = regmap_write(s->regmap, 0x1a, 0x00); 124 ret = regmap_write(dev->regmap, 0x1a, 0x00);
129 if (ret) 125 if (ret)
130 goto err; 126 goto err;
131 127
132 /* PLL */ 128 /*
129 * Fractional-N synthesizer
130 *
131 * +----------------------------+
132 * v |
133 * Fref +----+ +-------+ +------+ +---+
134 * ------> | PD | --> | VCO | ------> | /N.F | <-- | K |
135 * +----+ +-------+ +------+ +---+
136 * |
137 * |
138 * v
139 * +-------+ Fout
140 * | /Rout | ------>
141 * +-------+
142 */
133 for (i = 0; i < ARRAY_SIZE(e4000_pll_lut); i++) { 143 for (i = 0; i < ARRAY_SIZE(e4000_pll_lut); i++) {
134 if (c->frequency <= e4000_pll_lut[i].freq) 144 if (dev->f_frequency <= e4000_pll_lut[i].freq)
135 break; 145 break;
136 } 146 }
137
138 if (i == ARRAY_SIZE(e4000_pll_lut)) { 147 if (i == ARRAY_SIZE(e4000_pll_lut)) {
139 ret = -EINVAL; 148 ret = -EINVAL;
140 goto err; 149 goto err;
141 } 150 }
142 151
143 f_vco = 1ull * c->frequency * e4000_pll_lut[i].mul; 152 #define F_REF dev->clk
144 pll_n = div_u64_rem(f_vco, s->clock, &pll_f); 153 div_out = e4000_pll_lut[i].div_out;
145 sigma_delta = div_u64(0x10000ULL * pll_f, s->clock); 154 f_vco = (u64) dev->f_frequency * div_out;
146 buf[0] = pll_n; 155 /* calculate PLL integer and fractional control word */
147 buf[1] = (sigma_delta >> 0) & 0xff; 156 div_n = div_u64_rem(f_vco, F_REF, &k);
148 buf[2] = (sigma_delta >> 8) & 0xff; 157 k_cw = div_u64((u64) k * 0x10000, F_REF);
158
159 dev_dbg(&client->dev,
160 "frequency=%u bandwidth=%u f_vco=%llu F_REF=%u div_n=%u k=%u k_cw=%04x div_out=%u\n",
161 dev->f_frequency, dev->f_bandwidth, f_vco, F_REF, div_n, k,
162 k_cw, div_out);
163
164 buf[0] = div_n;
165 buf[1] = (k_cw >> 0) & 0xff;
166 buf[2] = (k_cw >> 8) & 0xff;
149 buf[3] = 0x00; 167 buf[3] = 0x00;
150 buf[4] = e4000_pll_lut[i].div; 168 buf[4] = e4000_pll_lut[i].div_out_reg;
151 169 ret = regmap_bulk_write(dev->regmap, 0x09, buf, 5);
152 dev_dbg(&s->client->dev, "f_vco=%llu pll div=%d sigma_delta=%04x\n",
153 f_vco, buf[0], sigma_delta);
154
155 ret = regmap_bulk_write(s->regmap, 0x09, buf, 5);
156 if (ret) 170 if (ret)
157 goto err; 171 goto err;
158 172
159 /* LNA filter (RF filter) */ 173 /* LNA filter (RF filter) */
160 for (i = 0; i < ARRAY_SIZE(e400_lna_filter_lut); i++) { 174 for (i = 0; i < ARRAY_SIZE(e400_lna_filter_lut); i++) {
161 if (c->frequency <= e400_lna_filter_lut[i].freq) 175 if (dev->f_frequency <= e400_lna_filter_lut[i].freq)
162 break; 176 break;
163 } 177 }
164
165 if (i == ARRAY_SIZE(e400_lna_filter_lut)) { 178 if (i == ARRAY_SIZE(e400_lna_filter_lut)) {
166 ret = -EINVAL; 179 ret = -EINVAL;
167 goto err; 180 goto err;
168 } 181 }
169 182
170 ret = regmap_write(s->regmap, 0x10, e400_lna_filter_lut[i].val); 183 ret = regmap_write(dev->regmap, 0x10, e400_lna_filter_lut[i].val);
171 if (ret) 184 if (ret)
172 goto err; 185 goto err;
173 186
174 /* IF filters */ 187 /* IF filters */
175 for (i = 0; i < ARRAY_SIZE(e4000_if_filter_lut); i++) { 188 for (i = 0; i < ARRAY_SIZE(e4000_if_filter_lut); i++) {
176 if (c->bandwidth_hz <= e4000_if_filter_lut[i].freq) 189 if (dev->f_bandwidth <= e4000_if_filter_lut[i].freq)
177 break; 190 break;
178 } 191 }
179
180 if (i == ARRAY_SIZE(e4000_if_filter_lut)) { 192 if (i == ARRAY_SIZE(e4000_if_filter_lut)) {
181 ret = -EINVAL; 193 ret = -EINVAL;
182 goto err; 194 goto err;
@@ -185,48 +197,47 @@ static int e4000_set_params(struct dvb_frontend *fe)
185 buf[0] = e4000_if_filter_lut[i].reg11_val; 197 buf[0] = e4000_if_filter_lut[i].reg11_val;
186 buf[1] = e4000_if_filter_lut[i].reg12_val; 198 buf[1] = e4000_if_filter_lut[i].reg12_val;
187 199
188 ret = regmap_bulk_write(s->regmap, 0x11, buf, 2); 200 ret = regmap_bulk_write(dev->regmap, 0x11, buf, 2);
189 if (ret) 201 if (ret)
190 goto err; 202 goto err;
191 203
192 /* frequency band */ 204 /* frequency band */
193 for (i = 0; i < ARRAY_SIZE(e4000_band_lut); i++) { 205 for (i = 0; i < ARRAY_SIZE(e4000_band_lut); i++) {
194 if (c->frequency <= e4000_band_lut[i].freq) 206 if (dev->f_frequency <= e4000_band_lut[i].freq)
195 break; 207 break;
196 } 208 }
197
198 if (i == ARRAY_SIZE(e4000_band_lut)) { 209 if (i == ARRAY_SIZE(e4000_band_lut)) {
199 ret = -EINVAL; 210 ret = -EINVAL;
200 goto err; 211 goto err;
201 } 212 }
202 213
203 ret = regmap_write(s->regmap, 0x07, e4000_band_lut[i].reg07_val); 214 ret = regmap_write(dev->regmap, 0x07, e4000_band_lut[i].reg07_val);
204 if (ret) 215 if (ret)
205 goto err; 216 goto err;
206 217
207 ret = regmap_write(s->regmap, 0x78, e4000_band_lut[i].reg78_val); 218 ret = regmap_write(dev->regmap, 0x78, e4000_band_lut[i].reg78_val);
208 if (ret) 219 if (ret)
209 goto err; 220 goto err;
210 221
211 /* DC offset */ 222 /* DC offset */
212 for (i = 0; i < 4; i++) { 223 for (i = 0; i < 4; i++) {
213 if (i == 0) 224 if (i == 0)
214 ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7e\x24", 3); 225 ret = regmap_bulk_write(dev->regmap, 0x15, "\x00\x7e\x24", 3);
215 else if (i == 1) 226 else if (i == 1)
216 ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7f", 2); 227 ret = regmap_bulk_write(dev->regmap, 0x15, "\x00\x7f", 2);
217 else if (i == 2) 228 else if (i == 2)
218 ret = regmap_bulk_write(s->regmap, 0x15, "\x01", 1); 229 ret = regmap_bulk_write(dev->regmap, 0x15, "\x01", 1);
219 else 230 else
220 ret = regmap_bulk_write(s->regmap, 0x16, "\x7e", 1); 231 ret = regmap_bulk_write(dev->regmap, 0x16, "\x7e", 1);
221 232
222 if (ret) 233 if (ret)
223 goto err; 234 goto err;
224 235
225 ret = regmap_write(s->regmap, 0x29, 0x01); 236 ret = regmap_write(dev->regmap, 0x29, 0x01);
226 if (ret) 237 if (ret)
227 goto err; 238 goto err;
228 239
229 ret = regmap_bulk_read(s->regmap, 0x2a, buf, 3); 240 ret = regmap_bulk_read(dev->regmap, 0x2a, buf, 3);
230 if (ret) 241 if (ret)
231 goto err; 242 goto err;
232 243
@@ -237,174 +248,294 @@ static int e4000_set_params(struct dvb_frontend *fe)
237 swap(q_data[2], q_data[3]); 248 swap(q_data[2], q_data[3]);
238 swap(i_data[2], i_data[3]); 249 swap(i_data[2], i_data[3]);
239 250
240 ret = regmap_bulk_write(s->regmap, 0x50, q_data, 4); 251 ret = regmap_bulk_write(dev->regmap, 0x50, q_data, 4);
241 if (ret) 252 if (ret)
242 goto err; 253 goto err;
243 254
244 ret = regmap_bulk_write(s->regmap, 0x60, i_data, 4); 255 ret = regmap_bulk_write(dev->regmap, 0x60, i_data, 4);
245 if (ret) 256 if (ret)
246 goto err; 257 goto err;
247 258
248 /* gain control auto */ 259 /* gain control auto */
249 ret = regmap_write(s->regmap, 0x1a, 0x17); 260 ret = regmap_write(dev->regmap, 0x1a, 0x17);
250 if (ret) 261 if (ret)
251 goto err; 262 goto err;
263
264 return 0;
252err: 265err:
266 dev_dbg(&client->dev, "failed=%d\n", ret);
267 return ret;
268}
269
270/*
271 * V4L2 API
272 */
273#if IS_ENABLED(CONFIG_VIDEO_V4L2)
274static const struct v4l2_frequency_band bands[] = {
275 {
276 .type = V4L2_TUNER_RF,
277 .index = 0,
278 .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
279 .rangelow = 59000000,
280 .rangehigh = 1105000000,
281 },
282 {
283 .type = V4L2_TUNER_RF,
284 .index = 1,
285 .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
286 .rangelow = 1249000000,
287 .rangehigh = 2208000000UL,
288 },
289};
290
291static inline struct e4000_dev *e4000_subdev_to_dev(struct v4l2_subdev *sd)
292{
293 return container_of(sd, struct e4000_dev, sd);
294}
295
296static int e4000_s_power(struct v4l2_subdev *sd, int on)
297{
298 struct e4000_dev *dev = e4000_subdev_to_dev(sd);
299 struct i2c_client *client = dev->client;
300 int ret;
301
302 dev_dbg(&client->dev, "on=%d\n", on);
303
304 if (on)
305 ret = e4000_init(dev);
306 else
307 ret = e4000_sleep(dev);
253 if (ret) 308 if (ret)
254 dev_dbg(&s->client->dev, "failed=%d\n", ret); 309 return ret;
255 310
256 return ret; 311 return e4000_set_params(dev);
312}
313
314static const struct v4l2_subdev_core_ops e4000_subdev_core_ops = {
315 .s_power = e4000_s_power,
316};
317
318static int e4000_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
319{
320 struct e4000_dev *dev = e4000_subdev_to_dev(sd);
321 struct i2c_client *client = dev->client;
322
323 dev_dbg(&client->dev, "index=%d\n", v->index);
324
325 strlcpy(v->name, "Elonics E4000", sizeof(v->name));
326 v->type = V4L2_TUNER_RF;
327 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
328 v->rangelow = bands[0].rangelow;
329 v->rangehigh = bands[1].rangehigh;
330 return 0;
257} 331}
258 332
259static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) 333static int e4000_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
260{ 334{
261 struct e4000 *s = fe->tuner_priv; 335 struct e4000_dev *dev = e4000_subdev_to_dev(sd);
336 struct i2c_client *client = dev->client;
262 337
263 dev_dbg(&s->client->dev, "\n"); 338 dev_dbg(&client->dev, "index=%d\n", v->index);
339 return 0;
340}
264 341
265 *frequency = 0; /* Zero-IF */ 342static int e4000_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
343{
344 struct e4000_dev *dev = e4000_subdev_to_dev(sd);
345 struct i2c_client *client = dev->client;
266 346
347 dev_dbg(&client->dev, "tuner=%d\n", f->tuner);
348 f->frequency = dev->f_frequency;
267 return 0; 349 return 0;
268} 350}
269 351
270#if IS_ENABLED(CONFIG_VIDEO_V4L2) 352static int e4000_s_frequency(struct v4l2_subdev *sd,
353 const struct v4l2_frequency *f)
354{
355 struct e4000_dev *dev = e4000_subdev_to_dev(sd);
356 struct i2c_client *client = dev->client;
357
358 dev_dbg(&client->dev, "tuner=%d type=%d frequency=%u\n",
359 f->tuner, f->type, f->frequency);
360
361 dev->f_frequency = clamp_t(unsigned int, f->frequency,
362 bands[0].rangelow, bands[1].rangehigh);
363 return e4000_set_params(dev);
364}
365
366static int e4000_enum_freq_bands(struct v4l2_subdev *sd,
367 struct v4l2_frequency_band *band)
368{
369 struct e4000_dev *dev = e4000_subdev_to_dev(sd);
370 struct i2c_client *client = dev->client;
371
372 dev_dbg(&client->dev, "tuner=%d type=%d index=%d\n",
373 band->tuner, band->type, band->index);
374
375 if (band->index >= ARRAY_SIZE(bands))
376 return -EINVAL;
377
378 band->capability = bands[band->index].capability;
379 band->rangelow = bands[band->index].rangelow;
380 band->rangehigh = bands[band->index].rangehigh;
381 return 0;
382}
383
384static const struct v4l2_subdev_tuner_ops e4000_subdev_tuner_ops = {
385 .g_tuner = e4000_g_tuner,
386 .s_tuner = e4000_s_tuner,
387 .g_frequency = e4000_g_frequency,
388 .s_frequency = e4000_s_frequency,
389 .enum_freq_bands = e4000_enum_freq_bands,
390};
391
392static const struct v4l2_subdev_ops e4000_subdev_ops = {
393 .core = &e4000_subdev_core_ops,
394 .tuner = &e4000_subdev_tuner_ops,
395};
396
271static int e4000_set_lna_gain(struct dvb_frontend *fe) 397static int e4000_set_lna_gain(struct dvb_frontend *fe)
272{ 398{
273 struct e4000 *s = fe->tuner_priv; 399 struct e4000_dev *dev = fe->tuner_priv;
400 struct i2c_client *client = dev->client;
274 int ret; 401 int ret;
275 u8 u8tmp; 402 u8 u8tmp;
276 403
277 dev_dbg(&s->client->dev, "lna auto=%d->%d val=%d->%d\n", 404 dev_dbg(&client->dev, "lna auto=%d->%d val=%d->%d\n",
278 s->lna_gain_auto->cur.val, s->lna_gain_auto->val, 405 dev->lna_gain_auto->cur.val, dev->lna_gain_auto->val,
279 s->lna_gain->cur.val, s->lna_gain->val); 406 dev->lna_gain->cur.val, dev->lna_gain->val);
280 407
281 if (s->lna_gain_auto->val && s->if_gain_auto->cur.val) 408 if (dev->lna_gain_auto->val && dev->if_gain_auto->cur.val)
282 u8tmp = 0x17; 409 u8tmp = 0x17;
283 else if (s->lna_gain_auto->val) 410 else if (dev->lna_gain_auto->val)
284 u8tmp = 0x19; 411 u8tmp = 0x19;
285 else if (s->if_gain_auto->cur.val) 412 else if (dev->if_gain_auto->cur.val)
286 u8tmp = 0x16; 413 u8tmp = 0x16;
287 else 414 else
288 u8tmp = 0x10; 415 u8tmp = 0x10;
289 416
290 ret = regmap_write(s->regmap, 0x1a, u8tmp); 417 ret = regmap_write(dev->regmap, 0x1a, u8tmp);
291 if (ret) 418 if (ret)
292 goto err; 419 goto err;
293 420
294 if (s->lna_gain_auto->val == false) { 421 if (dev->lna_gain_auto->val == false) {
295 ret = regmap_write(s->regmap, 0x14, s->lna_gain->val); 422 ret = regmap_write(dev->regmap, 0x14, dev->lna_gain->val);
296 if (ret) 423 if (ret)
297 goto err; 424 goto err;
298 } 425 }
299err:
300 if (ret)
301 dev_dbg(&s->client->dev, "failed=%d\n", ret);
302 426
427 return 0;
428err:
429 dev_dbg(&client->dev, "failed=%d\n", ret);
303 return ret; 430 return ret;
304} 431}
305 432
306static int e4000_set_mixer_gain(struct dvb_frontend *fe) 433static int e4000_set_mixer_gain(struct dvb_frontend *fe)
307{ 434{
308 struct e4000 *s = fe->tuner_priv; 435 struct e4000_dev *dev = fe->tuner_priv;
436 struct i2c_client *client = dev->client;
309 int ret; 437 int ret;
310 u8 u8tmp; 438 u8 u8tmp;
311 439
312 dev_dbg(&s->client->dev, "mixer auto=%d->%d val=%d->%d\n", 440 dev_dbg(&client->dev, "mixer auto=%d->%d val=%d->%d\n",
313 s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val, 441 dev->mixer_gain_auto->cur.val, dev->mixer_gain_auto->val,
314 s->mixer_gain->cur.val, s->mixer_gain->val); 442 dev->mixer_gain->cur.val, dev->mixer_gain->val);
315 443
316 if (s->mixer_gain_auto->val) 444 if (dev->mixer_gain_auto->val)
317 u8tmp = 0x15; 445 u8tmp = 0x15;
318 else 446 else
319 u8tmp = 0x14; 447 u8tmp = 0x14;
320 448
321 ret = regmap_write(s->regmap, 0x20, u8tmp); 449 ret = regmap_write(dev->regmap, 0x20, u8tmp);
322 if (ret) 450 if (ret)
323 goto err; 451 goto err;
324 452
325 if (s->mixer_gain_auto->val == false) { 453 if (dev->mixer_gain_auto->val == false) {
326 ret = regmap_write(s->regmap, 0x15, s->mixer_gain->val); 454 ret = regmap_write(dev->regmap, 0x15, dev->mixer_gain->val);
327 if (ret) 455 if (ret)
328 goto err; 456 goto err;
329 } 457 }
330err:
331 if (ret)
332 dev_dbg(&s->client->dev, "failed=%d\n", ret);
333 458
459 return 0;
460err:
461 dev_dbg(&client->dev, "failed=%d\n", ret);
334 return ret; 462 return ret;
335} 463}
336 464
337static int e4000_set_if_gain(struct dvb_frontend *fe) 465static int e4000_set_if_gain(struct dvb_frontend *fe)
338{ 466{
339 struct e4000 *s = fe->tuner_priv; 467 struct e4000_dev *dev = fe->tuner_priv;
468 struct i2c_client *client = dev->client;
340 int ret; 469 int ret;
341 u8 buf[2]; 470 u8 buf[2];
342 u8 u8tmp; 471 u8 u8tmp;
343 472
344 dev_dbg(&s->client->dev, "if auto=%d->%d val=%d->%d\n", 473 dev_dbg(&client->dev, "if auto=%d->%d val=%d->%d\n",
345 s->if_gain_auto->cur.val, s->if_gain_auto->val, 474 dev->if_gain_auto->cur.val, dev->if_gain_auto->val,
346 s->if_gain->cur.val, s->if_gain->val); 475 dev->if_gain->cur.val, dev->if_gain->val);
347 476
348 if (s->if_gain_auto->val && s->lna_gain_auto->cur.val) 477 if (dev->if_gain_auto->val && dev->lna_gain_auto->cur.val)
349 u8tmp = 0x17; 478 u8tmp = 0x17;
350 else if (s->lna_gain_auto->cur.val) 479 else if (dev->lna_gain_auto->cur.val)
351 u8tmp = 0x19; 480 u8tmp = 0x19;
352 else if (s->if_gain_auto->val) 481 else if (dev->if_gain_auto->val)
353 u8tmp = 0x16; 482 u8tmp = 0x16;
354 else 483 else
355 u8tmp = 0x10; 484 u8tmp = 0x10;
356 485
357 ret = regmap_write(s->regmap, 0x1a, u8tmp); 486 ret = regmap_write(dev->regmap, 0x1a, u8tmp);
358 if (ret) 487 if (ret)
359 goto err; 488 goto err;
360 489
361 if (s->if_gain_auto->val == false) { 490 if (dev->if_gain_auto->val == false) {
362 buf[0] = e4000_if_gain_lut[s->if_gain->val].reg16_val; 491 buf[0] = e4000_if_gain_lut[dev->if_gain->val].reg16_val;
363 buf[1] = e4000_if_gain_lut[s->if_gain->val].reg17_val; 492 buf[1] = e4000_if_gain_lut[dev->if_gain->val].reg17_val;
364 ret = regmap_bulk_write(s->regmap, 0x16, buf, 2); 493 ret = regmap_bulk_write(dev->regmap, 0x16, buf, 2);
365 if (ret) 494 if (ret)
366 goto err; 495 goto err;
367 } 496 }
368err:
369 if (ret)
370 dev_dbg(&s->client->dev, "failed=%d\n", ret);
371 497
498 return 0;
499err:
500 dev_dbg(&client->dev, "failed=%d\n", ret);
372 return ret; 501 return ret;
373} 502}
374 503
375static int e4000_pll_lock(struct dvb_frontend *fe) 504static int e4000_pll_lock(struct dvb_frontend *fe)
376{ 505{
377 struct e4000 *s = fe->tuner_priv; 506 struct e4000_dev *dev = fe->tuner_priv;
507 struct i2c_client *client = dev->client;
378 int ret; 508 int ret;
379 unsigned int utmp; 509 unsigned int uitmp;
380 510
381 ret = regmap_read(s->regmap, 0x07, &utmp); 511 ret = regmap_read(dev->regmap, 0x07, &uitmp);
382 if (ret) 512 if (ret)
383 goto err; 513 goto err;
384 514
385 s->pll_lock->val = (utmp & 0x01); 515 dev->pll_lock->val = (uitmp & 0x01);
386err:
387 if (ret)
388 dev_dbg(&s->client->dev, "failed=%d\n", ret);
389 516
517 return 0;
518err:
519 dev_dbg(&client->dev, "failed=%d\n", ret);
390 return ret; 520 return ret;
391} 521}
392 522
393static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 523static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
394{ 524{
395 struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); 525 struct e4000_dev *dev = container_of(ctrl->handler, struct e4000_dev, hdl);
526 struct i2c_client *client = dev->client;
396 int ret; 527 int ret;
397 528
398 if (!s->active) 529 if (!dev->active)
399 return 0; 530 return 0;
400 531
401 switch (ctrl->id) { 532 switch (ctrl->id) {
402 case V4L2_CID_RF_TUNER_PLL_LOCK: 533 case V4L2_CID_RF_TUNER_PLL_LOCK:
403 ret = e4000_pll_lock(s->fe); 534 ret = e4000_pll_lock(dev->fe);
404 break; 535 break;
405 default: 536 default:
406 dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", 537 dev_dbg(&client->dev, "unknown ctrl: id=%d name=%s\n",
407 ctrl->id, ctrl->name); 538 ctrl->id, ctrl->name);
408 ret = -EINVAL; 539 ret = -EINVAL;
409 } 540 }
410 541
@@ -413,35 +544,39 @@ static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
413 544
414static int e4000_s_ctrl(struct v4l2_ctrl *ctrl) 545static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
415{ 546{
416 struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); 547 struct e4000_dev *dev = container_of(ctrl->handler, struct e4000_dev, hdl);
417 struct dvb_frontend *fe = s->fe; 548 struct i2c_client *client = dev->client;
418 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
419 int ret; 549 int ret;
420 550
421 if (!s->active) 551 if (!dev->active)
422 return 0; 552 return 0;
423 553
424 switch (ctrl->id) { 554 switch (ctrl->id) {
425 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO: 555 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
426 case V4L2_CID_RF_TUNER_BANDWIDTH: 556 case V4L2_CID_RF_TUNER_BANDWIDTH:
427 c->bandwidth_hz = s->bandwidth->val; 557 /*
428 ret = e4000_set_params(s->fe); 558 * TODO: Auto logic does not work 100% correctly as tuner driver
559 * do not have information to calculate maximum suitable
560 * bandwidth. Calculating it is responsible of master driver.
561 */
562 dev->f_bandwidth = dev->bandwidth->val;
563 ret = e4000_set_params(dev);
429 break; 564 break;
430 case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO: 565 case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO:
431 case V4L2_CID_RF_TUNER_LNA_GAIN: 566 case V4L2_CID_RF_TUNER_LNA_GAIN:
432 ret = e4000_set_lna_gain(s->fe); 567 ret = e4000_set_lna_gain(dev->fe);
433 break; 568 break;
434 case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO: 569 case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO:
435 case V4L2_CID_RF_TUNER_MIXER_GAIN: 570 case V4L2_CID_RF_TUNER_MIXER_GAIN:
436 ret = e4000_set_mixer_gain(s->fe); 571 ret = e4000_set_mixer_gain(dev->fe);
437 break; 572 break;
438 case V4L2_CID_RF_TUNER_IF_GAIN_AUTO: 573 case V4L2_CID_RF_TUNER_IF_GAIN_AUTO:
439 case V4L2_CID_RF_TUNER_IF_GAIN: 574 case V4L2_CID_RF_TUNER_IF_GAIN:
440 ret = e4000_set_if_gain(s->fe); 575 ret = e4000_set_if_gain(dev->fe);
441 break; 576 break;
442 default: 577 default:
443 dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", 578 dev_dbg(&client->dev, "unknown ctrl: id=%d name=%s\n",
444 ctrl->id, ctrl->name); 579 ctrl->id, ctrl->name);
445 ret = -EINVAL; 580 ret = -EINVAL;
446 } 581 }
447 582
@@ -454,157 +589,176 @@ static const struct v4l2_ctrl_ops e4000_ctrl_ops = {
454}; 589};
455#endif 590#endif
456 591
457static const struct dvb_tuner_ops e4000_tuner_ops = { 592/*
593 * DVB API
594 */
595static int e4000_dvb_set_params(struct dvb_frontend *fe)
596{
597 struct e4000_dev *dev = fe->tuner_priv;
598 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
599
600 dev->f_frequency = c->frequency;
601 dev->f_bandwidth = c->bandwidth_hz;
602 return e4000_set_params(dev);
603}
604
605static int e4000_dvb_init(struct dvb_frontend *fe)
606{
607 return e4000_init(fe->tuner_priv);
608}
609
610static int e4000_dvb_sleep(struct dvb_frontend *fe)
611{
612 return e4000_sleep(fe->tuner_priv);
613}
614
615static int e4000_dvb_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
616{
617 *frequency = 0; /* Zero-IF */
618 return 0;
619}
620
621static const struct dvb_tuner_ops e4000_dvb_tuner_ops = {
458 .info = { 622 .info = {
459 .name = "Elonics E4000", 623 .name = "Elonics E4000",
460 .frequency_min = 174000000, 624 .frequency_min = 174000000,
461 .frequency_max = 862000000, 625 .frequency_max = 862000000,
462 }, 626 },
463 627
464 .init = e4000_init, 628 .init = e4000_dvb_init,
465 .sleep = e4000_sleep, 629 .sleep = e4000_dvb_sleep,
466 .set_params = e4000_set_params, 630 .set_params = e4000_dvb_set_params,
467 631
468 .get_if_frequency = e4000_get_if_frequency, 632 .get_if_frequency = e4000_dvb_get_if_frequency,
469}; 633};
470 634
471/*
472 * Use V4L2 subdev to carry V4L2 control handler, even we don't implement
473 * subdev itself, just to avoid reinventing the wheel.
474 */
475static int e4000_probe(struct i2c_client *client, 635static int e4000_probe(struct i2c_client *client,
476 const struct i2c_device_id *id) 636 const struct i2c_device_id *id)
477{ 637{
638 struct e4000_dev *dev;
478 struct e4000_config *cfg = client->dev.platform_data; 639 struct e4000_config *cfg = client->dev.platform_data;
479 struct dvb_frontend *fe = cfg->fe; 640 struct dvb_frontend *fe = cfg->fe;
480 struct e4000 *s;
481 int ret; 641 int ret;
482 unsigned int utmp; 642 unsigned int uitmp;
483 static const struct regmap_config regmap_config = { 643 static const struct regmap_config regmap_config = {
484 .reg_bits = 8, 644 .reg_bits = 8,
485 .val_bits = 8, 645 .val_bits = 8,
486 .max_register = 0xff,
487 }; 646 };
488 647
489 s = kzalloc(sizeof(struct e4000), GFP_KERNEL); 648 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
490 if (!s) { 649 if (!dev) {
491 ret = -ENOMEM; 650 ret = -ENOMEM;
492 dev_err(&client->dev, "kzalloc() failed\n");
493 goto err; 651 goto err;
494 } 652 }
495 653
496 s->clock = cfg->clock; 654 dev->clk = cfg->clock;
497 s->client = client; 655 dev->client = client;
498 s->fe = cfg->fe; 656 dev->fe = cfg->fe;
499 s->regmap = devm_regmap_init_i2c(client, &regmap_config); 657 dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
500 if (IS_ERR(s->regmap)) { 658 if (IS_ERR(dev->regmap)) {
501 ret = PTR_ERR(s->regmap); 659 ret = PTR_ERR(dev->regmap);
502 goto err; 660 goto err_kfree;
503 } 661 }
504 662
505 /* check if the tuner is there */ 663 /* check if the tuner is there */
506 ret = regmap_read(s->regmap, 0x02, &utmp); 664 ret = regmap_read(dev->regmap, 0x02, &uitmp);
507 if (ret) 665 if (ret)
508 goto err; 666 goto err_kfree;
509 667
510 dev_dbg(&s->client->dev, "chip id=%02x\n", utmp); 668 dev_dbg(&client->dev, "chip id=%02x\n", uitmp);
511 669
512 if (utmp != 0x40) { 670 if (uitmp != 0x40) {
513 ret = -ENODEV; 671 ret = -ENODEV;
514 goto err; 672 goto err_kfree;
515 } 673 }
516 674
517 /* put sleep as chip seems to be in normal mode by default */ 675 /* put sleep as chip seems to be in normal mode by default */
518 ret = regmap_write(s->regmap, 0x00, 0x00); 676 ret = regmap_write(dev->regmap, 0x00, 0x00);
519 if (ret) 677 if (ret)
520 goto err; 678 goto err_kfree;
521 679
522#if IS_ENABLED(CONFIG_VIDEO_V4L2) 680#if IS_ENABLED(CONFIG_VIDEO_V4L2)
523 /* Register controls */ 681 /* Register controls */
524 v4l2_ctrl_handler_init(&s->hdl, 9); 682 v4l2_ctrl_handler_init(&dev->hdl, 9);
525 s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 683 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
526 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1); 684 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1);
527 s->bandwidth = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 685 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
528 V4L2_CID_RF_TUNER_BANDWIDTH, 4300000, 11000000, 100000, 4300000); 686 V4L2_CID_RF_TUNER_BANDWIDTH, 4300000, 11000000, 100000, 4300000);
529 v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false); 687 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
530 s->lna_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 688 dev->lna_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
531 V4L2_CID_RF_TUNER_LNA_GAIN_AUTO, 0, 1, 1, 1); 689 V4L2_CID_RF_TUNER_LNA_GAIN_AUTO, 0, 1, 1, 1);
532 s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 690 dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
533 V4L2_CID_RF_TUNER_LNA_GAIN, 0, 15, 1, 10); 691 V4L2_CID_RF_TUNER_LNA_GAIN, 0, 15, 1, 10);
534 v4l2_ctrl_auto_cluster(2, &s->lna_gain_auto, 0, false); 692 v4l2_ctrl_auto_cluster(2, &dev->lna_gain_auto, 0, false);
535 s->mixer_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 693 dev->mixer_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
536 V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO, 0, 1, 1, 1); 694 V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO, 0, 1, 1, 1);
537 s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 695 dev->mixer_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
538 V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1); 696 V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1);
539 v4l2_ctrl_auto_cluster(2, &s->mixer_gain_auto, 0, false); 697 v4l2_ctrl_auto_cluster(2, &dev->mixer_gain_auto, 0, false);
540 s->if_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 698 dev->if_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
541 V4L2_CID_RF_TUNER_IF_GAIN_AUTO, 0, 1, 1, 1); 699 V4L2_CID_RF_TUNER_IF_GAIN_AUTO, 0, 1, 1, 1);
542 s->if_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 700 dev->if_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
543 V4L2_CID_RF_TUNER_IF_GAIN, 0, 54, 1, 0); 701 V4L2_CID_RF_TUNER_IF_GAIN, 0, 54, 1, 0);
544 v4l2_ctrl_auto_cluster(2, &s->if_gain_auto, 0, false); 702 v4l2_ctrl_auto_cluster(2, &dev->if_gain_auto, 0, false);
545 s->pll_lock = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 703 dev->pll_lock = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
546 V4L2_CID_RF_TUNER_PLL_LOCK, 0, 1, 1, 0); 704 V4L2_CID_RF_TUNER_PLL_LOCK, 0, 1, 1, 0);
547 if (s->hdl.error) { 705 if (dev->hdl.error) {
548 ret = s->hdl.error; 706 ret = dev->hdl.error;
549 dev_err(&s->client->dev, "Could not initialize controls\n"); 707 dev_err(&client->dev, "Could not initialize controls\n");
550 v4l2_ctrl_handler_free(&s->hdl); 708 v4l2_ctrl_handler_free(&dev->hdl);
551 goto err; 709 goto err_kfree;
552 } 710 }
553 711
554 s->sd.ctrl_handler = &s->hdl; 712 dev->sd.ctrl_handler = &dev->hdl;
713 dev->f_frequency = bands[0].rangelow;
714 dev->f_bandwidth = dev->bandwidth->val;
715 v4l2_i2c_subdev_init(&dev->sd, client, &e4000_subdev_ops);
555#endif 716#endif
717 fe->tuner_priv = dev;
718 memcpy(&fe->ops.tuner_ops, &e4000_dvb_tuner_ops,
719 sizeof(fe->ops.tuner_ops));
720 v4l2_set_subdevdata(&dev->sd, client);
721 i2c_set_clientdata(client, &dev->sd);
556 722
557 dev_info(&s->client->dev, "Elonics E4000 successfully identified\n"); 723 dev_info(&client->dev, "Elonics E4000 successfully identified\n");
558
559 fe->tuner_priv = s;
560 memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops,
561 sizeof(struct dvb_tuner_ops));
562
563 v4l2_set_subdevdata(&s->sd, client);
564 i2c_set_clientdata(client, &s->sd);
565
566 return 0; 724 return 0;
725err_kfree:
726 kfree(dev);
567err: 727err:
568 if (ret) { 728 dev_dbg(&client->dev, "failed=%d\n", ret);
569 dev_dbg(&client->dev, "failed=%d\n", ret);
570 kfree(s);
571 }
572
573 return ret; 729 return ret;
574} 730}
575 731
576static int e4000_remove(struct i2c_client *client) 732static int e4000_remove(struct i2c_client *client)
577{ 733{
578 struct v4l2_subdev *sd = i2c_get_clientdata(client); 734 struct v4l2_subdev *sd = i2c_get_clientdata(client);
579 struct e4000 *s = container_of(sd, struct e4000, sd); 735 struct e4000_dev *dev = container_of(sd, struct e4000_dev, sd);
580 struct dvb_frontend *fe = s->fe;
581 736
582 dev_dbg(&client->dev, "\n"); 737 dev_dbg(&client->dev, "\n");
583 738
584#if IS_ENABLED(CONFIG_VIDEO_V4L2) 739#if IS_ENABLED(CONFIG_VIDEO_V4L2)
585 v4l2_ctrl_handler_free(&s->hdl); 740 v4l2_ctrl_handler_free(&dev->hdl);
586#endif 741#endif
587 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); 742 kfree(dev);
588 fe->tuner_priv = NULL;
589 kfree(s);
590 743
591 return 0; 744 return 0;
592} 745}
593 746
594static const struct i2c_device_id e4000_id[] = { 747static const struct i2c_device_id e4000_id_table[] = {
595 {"e4000", 0}, 748 {"e4000", 0},
596 {} 749 {}
597}; 750};
598MODULE_DEVICE_TABLE(i2c, e4000_id); 751MODULE_DEVICE_TABLE(i2c, e4000_id_table);
599 752
600static struct i2c_driver e4000_driver = { 753static struct i2c_driver e4000_driver = {
601 .driver = { 754 .driver = {
602 .owner = THIS_MODULE, 755 .owner = THIS_MODULE,
603 .name = "e4000", 756 .name = "e4000",
757 .suppress_bind_attrs = true,
604 }, 758 },
605 .probe = e4000_probe, 759 .probe = e4000_probe,
606 .remove = e4000_remove, 760 .remove = e4000_remove,
607 .id_table = e4000_id, 761 .id_table = e4000_id_table,
608}; 762};
609 763
610module_i2c_driver(e4000_driver); 764module_i2c_driver(e4000_driver);
diff --git a/drivers/media/tuners/e4000.h b/drivers/media/tuners/e4000.h
index e74b8b2f2fc3..aa9340c05b43 100644
--- a/drivers/media/tuners/e4000.h
+++ b/drivers/media/tuners/e4000.h
@@ -21,7 +21,6 @@
21#ifndef E4000_H 21#ifndef E4000_H
22#define E4000_H 22#define E4000_H
23 23
24#include <linux/kconfig.h>
25#include "dvb_frontend.h" 24#include "dvb_frontend.h"
26 25
27/* 26/*
diff --git a/drivers/media/tuners/e4000_priv.h b/drivers/media/tuners/e4000_priv.h
index cb0070483e65..d6d5d11bbfe0 100644
--- a/drivers/media/tuners/e4000_priv.h
+++ b/drivers/media/tuners/e4000_priv.h
@@ -22,17 +22,20 @@
22#define E4000_PRIV_H 22#define E4000_PRIV_H
23 23
24#include "e4000.h" 24#include "e4000.h"
25#include <linux/math64.h>
25#include <media/v4l2-ctrls.h> 26#include <media/v4l2-ctrls.h>
26#include <media/v4l2-subdev.h> 27#include <media/v4l2-subdev.h>
27#include <linux/regmap.h> 28#include <linux/regmap.h>
28 29
29struct e4000 { 30struct e4000_dev {
30 struct i2c_client *client; 31 struct i2c_client *client;
31 struct regmap *regmap; 32 struct regmap *regmap;
32 u32 clock; 33 u32 clk;
33 struct dvb_frontend *fe; 34 struct dvb_frontend *fe;
34 struct v4l2_subdev sd; 35 struct v4l2_subdev sd;
35 bool active; 36 bool active;
37 unsigned int f_frequency;
38 unsigned int f_bandwidth;
36 39
37 /* Controls */ 40 /* Controls */
38 struct v4l2_ctrl_handler hdl; 41 struct v4l2_ctrl_handler hdl;
@@ -49,8 +52,8 @@ struct e4000 {
49 52
50struct e4000_pll { 53struct e4000_pll {
51 u32 freq; 54 u32 freq;
52 u8 div; 55 u8 div_out_reg;
53 u8 mul; 56 u8 div_out;
54}; 57};
55 58
56static const struct e4000_pll e4000_pll_lut[] = { 59static const struct e4000_pll e4000_pll_lut[] = {
diff --git a/drivers/media/tuners/fc0013.c b/drivers/media/tuners/fc0013.c
index b4162315773d..522690d97b42 100644
--- a/drivers/media/tuners/fc0013.c
+++ b/drivers/media/tuners/fc0013.c
@@ -217,8 +217,6 @@ static int fc0013_set_vhf_track(struct fc0013_priv *priv, u32 freq)
217 } else { /* UHF and GPS */ 217 } else { /* UHF and GPS */
218 ret = fc0013_writereg(priv, 0x1d, tmp | 0x1c); 218 ret = fc0013_writereg(priv, 0x1d, tmp | 0x1c);
219 } 219 }
220 if (ret)
221 goto error_out;
222error_out: 220error_out:
223 return ret; 221 return ret;
224} 222}
diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index f0c9c42867de..12f916e53150 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -20,535 +20,628 @@
20 20
21#include "fc2580_priv.h" 21#include "fc2580_priv.h"
22 22
23/* Max transfer size done by I2C transfer functions */
24#define MAX_XFER_SIZE 64
25
26/* 23/*
27 * TODO: 24 * TODO:
28 * I2C write and read works only for one single register. Multiple registers 25 * I2C write and read works only for one single register. Multiple registers
29 * could not be accessed using normal register address auto-increment. 26 * could not be accessed using normal register address auto-increment.
30 * There could be (very likely) register to change that behavior.... 27 * There could be (very likely) register to change that behavior....
31 *
32 * Due to that limitation functions:
33 * fc2580_wr_regs()
34 * fc2580_rd_regs()
35 * could not be used for accessing more than one register at once.
36 *
37 * TODO:
38 * Currently it blind writes bunch of static registers from the
39 * fc2580_freq_regs_lut[] when fc2580_set_params() is called. Add some
40 * logic to reduce unneeded register writes.
41 */ 28 */
42 29
43/* write multiple registers */
44static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
45{
46 int ret;
47 u8 buf[MAX_XFER_SIZE];
48 struct i2c_msg msg[1] = {
49 {
50 .addr = priv->cfg->i2c_addr,
51 .flags = 0,
52 .len = 1 + len,
53 .buf = buf,
54 }
55 };
56
57 if (1 + len > sizeof(buf)) {
58 dev_warn(&priv->i2c->dev,
59 "%s: i2c wr reg=%04x: len=%d is too big!\n",
60 KBUILD_MODNAME, reg, len);
61 return -EINVAL;
62 }
63
64 buf[0] = reg;
65 memcpy(&buf[1], val, len);
66
67 ret = i2c_transfer(priv->i2c, msg, 1);
68 if (ret == 1) {
69 ret = 0;
70 } else {
71 dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
72 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
73 ret = -EREMOTEIO;
74 }
75 return ret;
76}
77
78/* read multiple registers */
79static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
80{
81 int ret;
82 u8 buf[MAX_XFER_SIZE];
83 struct i2c_msg msg[2] = {
84 {
85 .addr = priv->cfg->i2c_addr,
86 .flags = 0,
87 .len = 1,
88 .buf = &reg,
89 }, {
90 .addr = priv->cfg->i2c_addr,
91 .flags = I2C_M_RD,
92 .len = len,
93 .buf = buf,
94 }
95 };
96
97 if (len > sizeof(buf)) {
98 dev_warn(&priv->i2c->dev,
99 "%s: i2c rd reg=%04x: len=%d is too big!\n",
100 KBUILD_MODNAME, reg, len);
101 return -EINVAL;
102 }
103
104 ret = i2c_transfer(priv->i2c, msg, 2);
105 if (ret == 2) {
106 memcpy(val, buf, len);
107 ret = 0;
108 } else {
109 dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%02x " \
110 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
111 ret = -EREMOTEIO;
112 }
113
114 return ret;
115}
116
117/* write single register */
118static int fc2580_wr_reg(struct fc2580_priv *priv, u8 reg, u8 val)
119{
120 return fc2580_wr_regs(priv, reg, &val, 1);
121}
122
123/* read single register */
124static int fc2580_rd_reg(struct fc2580_priv *priv, u8 reg, u8 *val)
125{
126 return fc2580_rd_regs(priv, reg, val, 1);
127}
128
129/* write single register conditionally only when value differs from 0xff 30/* write single register conditionally only when value differs from 0xff
130 * XXX: This is special routine meant only for writing fc2580_freq_regs_lut[] 31 * XXX: This is special routine meant only for writing fc2580_freq_regs_lut[]
131 * values. Do not use for the other purposes. */ 32 * values. Do not use for the other purposes. */
132static int fc2580_wr_reg_ff(struct fc2580_priv *priv, u8 reg, u8 val) 33static int fc2580_wr_reg_ff(struct fc2580_dev *dev, u8 reg, u8 val)
133{ 34{
134 if (val == 0xff) 35 if (val == 0xff)
135 return 0; 36 return 0;
136 else 37 else
137 return fc2580_wr_regs(priv, reg, &val, 1); 38 return regmap_write(dev->regmap, reg, val);
138} 39}
139 40
140static int fc2580_set_params(struct dvb_frontend *fe) 41static int fc2580_set_params(struct fc2580_dev *dev)
141{ 42{
142 struct fc2580_priv *priv = fe->tuner_priv; 43 struct i2c_client *client = dev->client;
143 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 44 int ret, i;
144 int ret = 0, i; 45 unsigned int uitmp, div_ref, div_ref_val, div_n, k, k_cw, div_out;
145 unsigned int r_val, n_val, k_val, k_val_reg, f_ref;
146 u8 tmp_val, r18_val;
147 u64 f_vco; 46 u64 f_vco;
47 u8 synth_config;
48 unsigned long timeout;
49
50 if (!dev->active) {
51 dev_dbg(&client->dev, "tuner is sleeping\n");
52 return 0;
53 }
148 54
149 /* 55 /*
150 * Fractional-N synthesizer/PLL. 56 * Fractional-N synthesizer
151 * Most likely all those PLL calculations are not correct. I am not 57 *
152 * sure, but it looks like it is divider based Fractional-N synthesizer. 58 * +---------------------------------------+
153 * There is divider for reference clock too? 59 * v |
154 * Anyhow, synthesizer calculation results seems to be quite correct. 60 * Fref +----+ +----+ +-------+ +----+ +------+ +---+
61 * ------> | /R | --> | PD | --> | VCO | ------> | /2 | --> | /N.F | <-- | K |
62 * +----+ +----+ +-------+ +----+ +------+ +---+
63 * |
64 * |
65 * v
66 * +-------+ Fout
67 * | /Rout | ------>
68 * +-------+
155 */ 69 */
156
157 dev_dbg(&priv->i2c->dev, "%s: delivery_system=%d frequency=%d " \
158 "bandwidth_hz=%d\n", __func__,
159 c->delivery_system, c->frequency, c->bandwidth_hz);
160
161 if (fe->ops.i2c_gate_ctrl)
162 fe->ops.i2c_gate_ctrl(fe, 1);
163
164 /* PLL */
165 for (i = 0; i < ARRAY_SIZE(fc2580_pll_lut); i++) { 70 for (i = 0; i < ARRAY_SIZE(fc2580_pll_lut); i++) {
166 if (c->frequency <= fc2580_pll_lut[i].freq) 71 if (dev->f_frequency <= fc2580_pll_lut[i].freq)
167 break; 72 break;
168 } 73 }
169 74 if (i == ARRAY_SIZE(fc2580_pll_lut)) {
170 if (i == ARRAY_SIZE(fc2580_pll_lut)) 75 ret = -EINVAL;
171 goto err; 76 goto err;
77 }
172 78
173 f_vco = c->frequency; 79 #define DIV_PRE_N 2
174 f_vco *= fc2580_pll_lut[i].div; 80 #define F_REF dev->clk
175 81 div_out = fc2580_pll_lut[i].div_out;
176 if (f_vco >= 2600000000UL) 82 f_vco = (u64) dev->f_frequency * div_out;
177 tmp_val = 0x0e | fc2580_pll_lut[i].band; 83 synth_config = fc2580_pll_lut[i].band;
84 if (f_vco < 2600000000ULL)
85 synth_config |= 0x06;
178 else 86 else
179 tmp_val = 0x06 | fc2580_pll_lut[i].band; 87 synth_config |= 0x0e;
180 88
181 ret = fc2580_wr_reg(priv, 0x02, tmp_val); 89 /* select reference divider R (keep PLL div N in valid range) */
182 if (ret < 0) 90 #define DIV_N_MIN 76
183 goto err; 91 if (f_vco >= div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 1)) {
184 92 div_ref = 1;
185 if (f_vco >= 2UL * 76 * priv->cfg->clock) { 93 div_ref_val = 0x00;
186 r_val = 1; 94 } else if (f_vco >= div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 2)) {
187 r18_val = 0x00; 95 div_ref = 2;
188 } else if (f_vco >= 1UL * 76 * priv->cfg->clock) { 96 div_ref_val = 0x10;
189 r_val = 2;
190 r18_val = 0x10;
191 } else { 97 } else {
192 r_val = 4; 98 div_ref = 4;
193 r18_val = 0x20; 99 div_ref_val = 0x20;
194 } 100 }
195 101
196 f_ref = 2UL * priv->cfg->clock / r_val; 102 /* calculate PLL integer and fractional control word */
197 n_val = div_u64_rem(f_vco, f_ref, &k_val); 103 uitmp = DIV_PRE_N * F_REF / div_ref;
198 k_val_reg = div_u64(1ULL * k_val * (1 << 20), f_ref); 104 div_n = div_u64_rem(f_vco, uitmp, &k);
105 k_cw = div_u64((u64) k * 0x100000, uitmp);
199 106
200 ret = fc2580_wr_reg(priv, 0x18, r18_val | ((k_val_reg >> 16) & 0xff)); 107 dev_dbg(&client->dev,
201 if (ret < 0) 108 "frequency=%u bandwidth=%u f_vco=%llu F_REF=%u div_ref=%u div_n=%u k=%u div_out=%u k_cw=%0x\n",
202 goto err; 109 dev->f_frequency, dev->f_bandwidth, f_vco, F_REF, div_ref,
110 div_n, k, div_out, k_cw);
203 111
204 ret = fc2580_wr_reg(priv, 0x1a, (k_val_reg >> 8) & 0xff); 112 ret = regmap_write(dev->regmap, 0x02, synth_config);
205 if (ret < 0) 113 if (ret)
206 goto err; 114 goto err;
207 115
208 ret = fc2580_wr_reg(priv, 0x1b, (k_val_reg >> 0) & 0xff); 116 ret = regmap_write(dev->regmap, 0x18, div_ref_val << 0 | k_cw >> 16);
209 if (ret < 0) 117 if (ret)
210 goto err; 118 goto err;
211 119
212 ret = fc2580_wr_reg(priv, 0x1c, n_val); 120 ret = regmap_write(dev->regmap, 0x1a, (k_cw >> 8) & 0xff);
213 if (ret < 0) 121 if (ret)
214 goto err; 122 goto err;
215 123
216 if (priv->cfg->clock >= 28000000) { 124 ret = regmap_write(dev->regmap, 0x1b, (k_cw >> 0) & 0xff);
217 ret = fc2580_wr_reg(priv, 0x4b, 0x22); 125 if (ret)
218 if (ret < 0) 126 goto err;
219 goto err;
220 }
221
222 if (fc2580_pll_lut[i].band == 0x00) {
223 if (c->frequency <= 794000000)
224 tmp_val = 0x9f;
225 else
226 tmp_val = 0x8f;
227 127
228 ret = fc2580_wr_reg(priv, 0x2d, tmp_val); 128 ret = regmap_write(dev->regmap, 0x1c, div_n);
229 if (ret < 0) 129 if (ret)
230 goto err; 130 goto err;
231 }
232 131
233 /* registers */ 132 /* registers */
234 for (i = 0; i < ARRAY_SIZE(fc2580_freq_regs_lut); i++) { 133 for (i = 0; i < ARRAY_SIZE(fc2580_freq_regs_lut); i++) {
235 if (c->frequency <= fc2580_freq_regs_lut[i].freq) 134 if (dev->f_frequency <= fc2580_freq_regs_lut[i].freq)
236 break; 135 break;
237 } 136 }
238 137 if (i == ARRAY_SIZE(fc2580_freq_regs_lut)) {
239 if (i == ARRAY_SIZE(fc2580_freq_regs_lut)) 138 ret = -EINVAL;
240 goto err; 139 goto err;
140 }
241 141
242 ret = fc2580_wr_reg_ff(priv, 0x25, fc2580_freq_regs_lut[i].r25_val); 142 ret = fc2580_wr_reg_ff(dev, 0x25, fc2580_freq_regs_lut[i].r25_val);
243 if (ret < 0) 143 if (ret)
244 goto err; 144 goto err;
245 145
246 ret = fc2580_wr_reg_ff(priv, 0x27, fc2580_freq_regs_lut[i].r27_val); 146 ret = fc2580_wr_reg_ff(dev, 0x27, fc2580_freq_regs_lut[i].r27_val);
247 if (ret < 0) 147 if (ret)
248 goto err; 148 goto err;
249 149
250 ret = fc2580_wr_reg_ff(priv, 0x28, fc2580_freq_regs_lut[i].r28_val); 150 ret = fc2580_wr_reg_ff(dev, 0x28, fc2580_freq_regs_lut[i].r28_val);
251 if (ret < 0) 151 if (ret)
252 goto err; 152 goto err;
253 153
254 ret = fc2580_wr_reg_ff(priv, 0x29, fc2580_freq_regs_lut[i].r29_val); 154 ret = fc2580_wr_reg_ff(dev, 0x29, fc2580_freq_regs_lut[i].r29_val);
255 if (ret < 0) 155 if (ret)
256 goto err; 156 goto err;
257 157
258 ret = fc2580_wr_reg_ff(priv, 0x2b, fc2580_freq_regs_lut[i].r2b_val); 158 ret = fc2580_wr_reg_ff(dev, 0x2b, fc2580_freq_regs_lut[i].r2b_val);
259 if (ret < 0) 159 if (ret)
260 goto err; 160 goto err;
261 161
262 ret = fc2580_wr_reg_ff(priv, 0x2c, fc2580_freq_regs_lut[i].r2c_val); 162 ret = fc2580_wr_reg_ff(dev, 0x2c, fc2580_freq_regs_lut[i].r2c_val);
263 if (ret < 0) 163 if (ret)
264 goto err; 164 goto err;
265 165
266 ret = fc2580_wr_reg_ff(priv, 0x2d, fc2580_freq_regs_lut[i].r2d_val); 166 ret = fc2580_wr_reg_ff(dev, 0x2d, fc2580_freq_regs_lut[i].r2d_val);
267 if (ret < 0) 167 if (ret)
268 goto err; 168 goto err;
269 169
270 ret = fc2580_wr_reg_ff(priv, 0x30, fc2580_freq_regs_lut[i].r30_val); 170 ret = fc2580_wr_reg_ff(dev, 0x30, fc2580_freq_regs_lut[i].r30_val);
271 if (ret < 0) 171 if (ret)
272 goto err; 172 goto err;
273 173
274 ret = fc2580_wr_reg_ff(priv, 0x44, fc2580_freq_regs_lut[i].r44_val); 174 ret = fc2580_wr_reg_ff(dev, 0x44, fc2580_freq_regs_lut[i].r44_val);
275 if (ret < 0) 175 if (ret)
276 goto err; 176 goto err;
277 177
278 ret = fc2580_wr_reg_ff(priv, 0x50, fc2580_freq_regs_lut[i].r50_val); 178 ret = fc2580_wr_reg_ff(dev, 0x50, fc2580_freq_regs_lut[i].r50_val);
279 if (ret < 0) 179 if (ret)
280 goto err; 180 goto err;
281 181
282 ret = fc2580_wr_reg_ff(priv, 0x53, fc2580_freq_regs_lut[i].r53_val); 182 ret = fc2580_wr_reg_ff(dev, 0x53, fc2580_freq_regs_lut[i].r53_val);
283 if (ret < 0) 183 if (ret)
284 goto err; 184 goto err;
285 185
286 ret = fc2580_wr_reg_ff(priv, 0x5f, fc2580_freq_regs_lut[i].r5f_val); 186 ret = fc2580_wr_reg_ff(dev, 0x5f, fc2580_freq_regs_lut[i].r5f_val);
287 if (ret < 0) 187 if (ret)
288 goto err; 188 goto err;
289 189
290 ret = fc2580_wr_reg_ff(priv, 0x61, fc2580_freq_regs_lut[i].r61_val); 190 ret = fc2580_wr_reg_ff(dev, 0x61, fc2580_freq_regs_lut[i].r61_val);
291 if (ret < 0) 191 if (ret)
292 goto err; 192 goto err;
293 193
294 ret = fc2580_wr_reg_ff(priv, 0x62, fc2580_freq_regs_lut[i].r62_val); 194 ret = fc2580_wr_reg_ff(dev, 0x62, fc2580_freq_regs_lut[i].r62_val);
295 if (ret < 0) 195 if (ret)
296 goto err; 196 goto err;
297 197
298 ret = fc2580_wr_reg_ff(priv, 0x63, fc2580_freq_regs_lut[i].r63_val); 198 ret = fc2580_wr_reg_ff(dev, 0x63, fc2580_freq_regs_lut[i].r63_val);
299 if (ret < 0) 199 if (ret)
300 goto err; 200 goto err;
301 201
302 ret = fc2580_wr_reg_ff(priv, 0x67, fc2580_freq_regs_lut[i].r67_val); 202 ret = fc2580_wr_reg_ff(dev, 0x67, fc2580_freq_regs_lut[i].r67_val);
303 if (ret < 0) 203 if (ret)
304 goto err; 204 goto err;
305 205
306 ret = fc2580_wr_reg_ff(priv, 0x68, fc2580_freq_regs_lut[i].r68_val); 206 ret = fc2580_wr_reg_ff(dev, 0x68, fc2580_freq_regs_lut[i].r68_val);
307 if (ret < 0) 207 if (ret)
308 goto err; 208 goto err;
309 209
310 ret = fc2580_wr_reg_ff(priv, 0x69, fc2580_freq_regs_lut[i].r69_val); 210 ret = fc2580_wr_reg_ff(dev, 0x69, fc2580_freq_regs_lut[i].r69_val);
311 if (ret < 0) 211 if (ret)
312 goto err; 212 goto err;
313 213
314 ret = fc2580_wr_reg_ff(priv, 0x6a, fc2580_freq_regs_lut[i].r6a_val); 214 ret = fc2580_wr_reg_ff(dev, 0x6a, fc2580_freq_regs_lut[i].r6a_val);
315 if (ret < 0) 215 if (ret)
316 goto err; 216 goto err;
317 217
318 ret = fc2580_wr_reg_ff(priv, 0x6b, fc2580_freq_regs_lut[i].r6b_val); 218 ret = fc2580_wr_reg_ff(dev, 0x6b, fc2580_freq_regs_lut[i].r6b_val);
319 if (ret < 0) 219 if (ret)
320 goto err; 220 goto err;
321 221
322 ret = fc2580_wr_reg_ff(priv, 0x6c, fc2580_freq_regs_lut[i].r6c_val); 222 ret = fc2580_wr_reg_ff(dev, 0x6c, fc2580_freq_regs_lut[i].r6c_val);
323 if (ret < 0) 223 if (ret)
324 goto err; 224 goto err;
325 225
326 ret = fc2580_wr_reg_ff(priv, 0x6d, fc2580_freq_regs_lut[i].r6d_val); 226 ret = fc2580_wr_reg_ff(dev, 0x6d, fc2580_freq_regs_lut[i].r6d_val);
327 if (ret < 0) 227 if (ret)
328 goto err; 228 goto err;
329 229
330 ret = fc2580_wr_reg_ff(priv, 0x6e, fc2580_freq_regs_lut[i].r6e_val); 230 ret = fc2580_wr_reg_ff(dev, 0x6e, fc2580_freq_regs_lut[i].r6e_val);
331 if (ret < 0) 231 if (ret)
332 goto err; 232 goto err;
333 233
334 ret = fc2580_wr_reg_ff(priv, 0x6f, fc2580_freq_regs_lut[i].r6f_val); 234 ret = fc2580_wr_reg_ff(dev, 0x6f, fc2580_freq_regs_lut[i].r6f_val);
335 if (ret < 0) 235 if (ret)
336 goto err; 236 goto err;
337 237
338 /* IF filters */ 238 /* IF filters */
339 for (i = 0; i < ARRAY_SIZE(fc2580_if_filter_lut); i++) { 239 for (i = 0; i < ARRAY_SIZE(fc2580_if_filter_lut); i++) {
340 if (c->bandwidth_hz <= fc2580_if_filter_lut[i].freq) 240 if (dev->f_bandwidth <= fc2580_if_filter_lut[i].freq)
341 break; 241 break;
342 } 242 }
343 243 if (i == ARRAY_SIZE(fc2580_if_filter_lut)) {
344 if (i == ARRAY_SIZE(fc2580_if_filter_lut)) 244 ret = -EINVAL;
345 goto err;
346
347 ret = fc2580_wr_reg(priv, 0x36, fc2580_if_filter_lut[i].r36_val);
348 if (ret < 0)
349 goto err; 245 goto err;
246 }
350 247
351 ret = fc2580_wr_reg(priv, 0x37, div_u64(1ULL * priv->cfg->clock * 248 ret = regmap_write(dev->regmap, 0x36, fc2580_if_filter_lut[i].r36_val);
352 fc2580_if_filter_lut[i].mul, 1000000000)); 249 if (ret)
353 if (ret < 0)
354 goto err; 250 goto err;
355 251
356 ret = fc2580_wr_reg(priv, 0x39, fc2580_if_filter_lut[i].r39_val); 252 uitmp = (unsigned int) 8058000 - (dev->f_bandwidth * 122 / 100 / 2);
357 if (ret < 0) 253 uitmp = div64_u64((u64) dev->clk * uitmp, 1000000000000ULL);
254 ret = regmap_write(dev->regmap, 0x37, uitmp);
255 if (ret)
358 goto err; 256 goto err;
359 257
360 /* calibration? */ 258 ret = regmap_write(dev->regmap, 0x39, fc2580_if_filter_lut[i].r39_val);
361 ret = fc2580_wr_reg(priv, 0x2e, 0x09); 259 if (ret)
362 if (ret < 0)
363 goto err; 260 goto err;
364 261
365 for (i = 0; i < 5; i++) { 262 timeout = jiffies + msecs_to_jiffies(30);
366 ret = fc2580_rd_reg(priv, 0x2f, &tmp_val); 263 for (uitmp = ~0xc0; !time_after(jiffies, timeout) && uitmp != 0xc0;) {
367 if (ret < 0) 264 /* trigger filter */
265 ret = regmap_write(dev->regmap, 0x2e, 0x09);
266 if (ret)
368 goto err; 267 goto err;
369 268
370 /* done when [7:6] are set */ 269 /* locked when [7:6] are set (val: d7 6MHz, d5 7MHz, cd 8MHz) */
371 if ((tmp_val & 0xc0) == 0xc0) 270 ret = regmap_read(dev->regmap, 0x2f, &uitmp);
372 break; 271 if (ret)
373
374 ret = fc2580_wr_reg(priv, 0x2e, 0x01);
375 if (ret < 0)
376 goto err; 272 goto err;
273 uitmp &= 0xc0;
377 274
378 ret = fc2580_wr_reg(priv, 0x2e, 0x09); 275 ret = regmap_write(dev->regmap, 0x2e, 0x01);
379 if (ret < 0) 276 if (ret)
380 goto err; 277 goto err;
381
382 usleep_range(5000, 25000);
383 } 278 }
384 279 if (uitmp != 0xc0)
385 dev_dbg(&priv->i2c->dev, "%s: loop=%i\n", __func__, i); 280 dev_dbg(&client->dev, "filter did not lock %02x\n", uitmp);
386
387 ret = fc2580_wr_reg(priv, 0x2e, 0x01);
388 if (ret < 0)
389 goto err;
390
391 if (fe->ops.i2c_gate_ctrl)
392 fe->ops.i2c_gate_ctrl(fe, 0);
393 281
394 return 0; 282 return 0;
395err: 283err:
396 if (fe->ops.i2c_gate_ctrl) 284 dev_dbg(&client->dev, "failed=%d\n", ret);
397 fe->ops.i2c_gate_ctrl(fe, 0);
398
399 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
400 return ret; 285 return ret;
401} 286}
402 287
403static int fc2580_init(struct dvb_frontend *fe) 288static int fc2580_init(struct fc2580_dev *dev)
404{ 289{
405 struct fc2580_priv *priv = fe->tuner_priv; 290 struct i2c_client *client = dev->client;
406 int ret, i; 291 int ret, i;
407 292
408 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 293 dev_dbg(&client->dev, "\n");
409
410 if (fe->ops.i2c_gate_ctrl)
411 fe->ops.i2c_gate_ctrl(fe, 1);
412 294
413 for (i = 0; i < ARRAY_SIZE(fc2580_init_reg_vals); i++) { 295 for (i = 0; i < ARRAY_SIZE(fc2580_init_reg_vals); i++) {
414 ret = fc2580_wr_reg(priv, fc2580_init_reg_vals[i].reg, 296 ret = regmap_write(dev->regmap, fc2580_init_reg_vals[i].reg,
415 fc2580_init_reg_vals[i].val); 297 fc2580_init_reg_vals[i].val);
416 if (ret < 0) 298 if (ret)
417 goto err; 299 goto err;
418 } 300 }
419 301
420 if (fe->ops.i2c_gate_ctrl) 302 dev->active = true;
421 fe->ops.i2c_gate_ctrl(fe, 0);
422
423 return 0; 303 return 0;
424err: 304err:
425 if (fe->ops.i2c_gate_ctrl) 305 dev_dbg(&client->dev, "failed=%d\n", ret);
426 fe->ops.i2c_gate_ctrl(fe, 0);
427
428 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
429 return ret; 306 return ret;
430} 307}
431 308
432static int fc2580_sleep(struct dvb_frontend *fe) 309static int fc2580_sleep(struct fc2580_dev *dev)
433{ 310{
434 struct fc2580_priv *priv = fe->tuner_priv; 311 struct i2c_client *client = dev->client;
435 int ret; 312 int ret;
436 313
437 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 314 dev_dbg(&client->dev, "\n");
438 315
439 if (fe->ops.i2c_gate_ctrl) 316 dev->active = false;
440 fe->ops.i2c_gate_ctrl(fe, 1);
441 317
442 ret = fc2580_wr_reg(priv, 0x02, 0x0a); 318 ret = regmap_write(dev->regmap, 0x02, 0x0a);
443 if (ret < 0) 319 if (ret)
444 goto err; 320 goto err;
445
446 if (fe->ops.i2c_gate_ctrl)
447 fe->ops.i2c_gate_ctrl(fe, 0);
448
449 return 0; 321 return 0;
450err: 322err:
451 if (fe->ops.i2c_gate_ctrl) 323 dev_dbg(&client->dev, "failed=%d\n", ret);
452 fe->ops.i2c_gate_ctrl(fe, 0);
453
454 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
455 return ret; 324 return ret;
456} 325}
457 326
458static int fc2580_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) 327/*
328 * DVB API
329 */
330static int fc2580_dvb_set_params(struct dvb_frontend *fe)
459{ 331{
460 struct fc2580_priv *priv = fe->tuner_priv; 332 struct fc2580_dev *dev = fe->tuner_priv;
461 333 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
462 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
463
464 *frequency = 0; /* Zero-IF */
465 334
466 return 0; 335 dev->f_frequency = c->frequency;
336 dev->f_bandwidth = c->bandwidth_hz;
337 return fc2580_set_params(dev);
467} 338}
468 339
469static int fc2580_release(struct dvb_frontend *fe) 340static int fc2580_dvb_init(struct dvb_frontend *fe)
470{ 341{
471 struct fc2580_priv *priv = fe->tuner_priv; 342 return fc2580_init(fe->tuner_priv);
472 343}
473 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
474 344
475 kfree(fe->tuner_priv); 345static int fc2580_dvb_sleep(struct dvb_frontend *fe)
346{
347 return fc2580_sleep(fe->tuner_priv);
348}
476 349
350static int fc2580_dvb_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
351{
352 *frequency = 0; /* Zero-IF */
477 return 0; 353 return 0;
478} 354}
479 355
480static const struct dvb_tuner_ops fc2580_tuner_ops = { 356static const struct dvb_tuner_ops fc2580_dvb_tuner_ops = {
481 .info = { 357 .info = {
482 .name = "FCI FC2580", 358 .name = "FCI FC2580",
483 .frequency_min = 174000000, 359 .frequency_min = 174000000,
484 .frequency_max = 862000000, 360 .frequency_max = 862000000,
485 }, 361 },
486 362
487 .release = fc2580_release, 363 .init = fc2580_dvb_init,
364 .sleep = fc2580_dvb_sleep,
365 .set_params = fc2580_dvb_set_params,
366
367 .get_if_frequency = fc2580_dvb_get_if_frequency,
368};
369
370/*
371 * V4L2 API
372 */
373#if IS_ENABLED(CONFIG_VIDEO_V4L2)
374static const struct v4l2_frequency_band bands[] = {
375 {
376 .type = V4L2_TUNER_RF,
377 .index = 0,
378 .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
379 .rangelow = 130000000,
380 .rangehigh = 2000000000,
381 },
382};
383
384static inline struct fc2580_dev *fc2580_subdev_to_dev(struct v4l2_subdev *sd)
385{
386 return container_of(sd, struct fc2580_dev, subdev);
387}
388
389static int fc2580_s_power(struct v4l2_subdev *sd, int on)
390{
391 struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
392 struct i2c_client *client = dev->client;
393 int ret;
394
395 dev_dbg(&client->dev, "on=%d\n", on);
396
397 if (on)
398 ret = fc2580_init(dev);
399 else
400 ret = fc2580_sleep(dev);
401 if (ret)
402 return ret;
403
404 return fc2580_set_params(dev);
405}
406
407static const struct v4l2_subdev_core_ops fc2580_subdev_core_ops = {
408 .s_power = fc2580_s_power,
409};
410
411static int fc2580_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
412{
413 struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
414 struct i2c_client *client = dev->client;
415
416 dev_dbg(&client->dev, "index=%d\n", v->index);
417
418 strlcpy(v->name, "FCI FC2580", sizeof(v->name));
419 v->type = V4L2_TUNER_RF;
420 v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
421 v->rangelow = bands[0].rangelow;
422 v->rangehigh = bands[0].rangehigh;
423 return 0;
424}
425
426static int fc2580_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
427{
428 struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
429 struct i2c_client *client = dev->client;
430
431 dev_dbg(&client->dev, "index=%d\n", v->index);
432 return 0;
433}
434
435static int fc2580_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
436{
437 struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
438 struct i2c_client *client = dev->client;
439
440 dev_dbg(&client->dev, "tuner=%d\n", f->tuner);
441 f->frequency = dev->f_frequency;
442 return 0;
443}
444
445static int fc2580_s_frequency(struct v4l2_subdev *sd,
446 const struct v4l2_frequency *f)
447{
448 struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
449 struct i2c_client *client = dev->client;
450
451 dev_dbg(&client->dev, "tuner=%d type=%d frequency=%u\n",
452 f->tuner, f->type, f->frequency);
453
454 dev->f_frequency = clamp_t(unsigned int, f->frequency,
455 bands[0].rangelow, bands[0].rangehigh);
456 return fc2580_set_params(dev);
457}
458
459static int fc2580_enum_freq_bands(struct v4l2_subdev *sd,
460 struct v4l2_frequency_band *band)
461{
462 struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
463 struct i2c_client *client = dev->client;
464
465 dev_dbg(&client->dev, "tuner=%d type=%d index=%d\n",
466 band->tuner, band->type, band->index);
488 467
489 .init = fc2580_init, 468 if (band->index >= ARRAY_SIZE(bands))
490 .sleep = fc2580_sleep, 469 return -EINVAL;
491 .set_params = fc2580_set_params,
492 470
493 .get_if_frequency = fc2580_get_if_frequency, 471 band->capability = bands[band->index].capability;
472 band->rangelow = bands[band->index].rangelow;
473 band->rangehigh = bands[band->index].rangehigh;
474 return 0;
475}
476
477static const struct v4l2_subdev_tuner_ops fc2580_subdev_tuner_ops = {
478 .g_tuner = fc2580_g_tuner,
479 .s_tuner = fc2580_s_tuner,
480 .g_frequency = fc2580_g_frequency,
481 .s_frequency = fc2580_s_frequency,
482 .enum_freq_bands = fc2580_enum_freq_bands,
483};
484
485static const struct v4l2_subdev_ops fc2580_subdev_ops = {
486 .core = &fc2580_subdev_core_ops,
487 .tuner = &fc2580_subdev_tuner_ops,
494}; 488};
495 489
496struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe, 490static int fc2580_s_ctrl(struct v4l2_ctrl *ctrl)
497 struct i2c_adapter *i2c, const struct fc2580_config *cfg)
498{ 491{
499 struct fc2580_priv *priv; 492 struct fc2580_dev *dev = container_of(ctrl->handler, struct fc2580_dev, hdl);
493 struct i2c_client *client = dev->client;
500 int ret; 494 int ret;
501 u8 chip_id;
502 495
503 if (fe->ops.i2c_gate_ctrl) 496 dev_dbg(&client->dev, "ctrl: id=%d name=%s cur.val=%d val=%d\n",
504 fe->ops.i2c_gate_ctrl(fe, 1); 497 ctrl->id, ctrl->name, ctrl->cur.val, ctrl->val);
498
499 switch (ctrl->id) {
500 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
501 case V4L2_CID_RF_TUNER_BANDWIDTH:
502 /*
503 * TODO: Auto logic does not work 100% correctly as tuner driver
504 * do not have information to calculate maximum suitable
505 * bandwidth. Calculating it is responsible of master driver.
506 */
507 dev->f_bandwidth = dev->bandwidth->val;
508 ret = fc2580_set_params(dev);
509 break;
510 default:
511 dev_dbg(&client->dev, "unknown ctrl");
512 ret = -EINVAL;
513 }
514 return ret;
515}
516
517static const struct v4l2_ctrl_ops fc2580_ctrl_ops = {
518 .s_ctrl = fc2580_s_ctrl,
519};
520#endif
521
522static struct v4l2_subdev *fc2580_get_v4l2_subdev(struct i2c_client *client)
523{
524 struct fc2580_dev *dev = i2c_get_clientdata(client);
525
526 if (dev->subdev.ops)
527 return &dev->subdev;
528 else
529 return NULL;
530}
531
532static int fc2580_probe(struct i2c_client *client,
533 const struct i2c_device_id *id)
534{
535 struct fc2580_dev *dev;
536 struct fc2580_platform_data *pdata = client->dev.platform_data;
537 struct dvb_frontend *fe = pdata->dvb_frontend;
538 int ret;
539 unsigned int uitmp;
540 static const struct regmap_config regmap_config = {
541 .reg_bits = 8,
542 .val_bits = 8,
543 };
505 544
506 priv = kzalloc(sizeof(struct fc2580_priv), GFP_KERNEL); 545 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
507 if (!priv) { 546 if (!dev) {
508 ret = -ENOMEM; 547 ret = -ENOMEM;
509 dev_err(&i2c->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
510 goto err; 548 goto err;
511 } 549 }
512 550
513 priv->cfg = cfg; 551 if (pdata->clk)
514 priv->i2c = i2c; 552 dev->clk = pdata->clk;
553 else
554 dev->clk = 16384000; /* internal clock */
555 dev->client = client;
556 dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
557 if (IS_ERR(dev->regmap)) {
558 ret = PTR_ERR(dev->regmap);
559 goto err_kfree;
560 }
515 561
516 /* check if the tuner is there */ 562 /* check if the tuner is there */
517 ret = fc2580_rd_reg(priv, 0x01, &chip_id); 563 ret = regmap_read(dev->regmap, 0x01, &uitmp);
518 if (ret < 0) 564 if (ret)
519 goto err; 565 goto err_kfree;
520 566
521 dev_dbg(&priv->i2c->dev, "%s: chip_id=%02x\n", __func__, chip_id); 567 dev_dbg(&client->dev, "chip_id=%02x\n", uitmp);
522 568
523 switch (chip_id) { 569 switch (uitmp) {
524 case 0x56: 570 case 0x56:
525 case 0x5a: 571 case 0x5a:
526 break; 572 break;
527 default: 573 default:
528 goto err; 574 ret = -ENODEV;
575 goto err_kfree;
529 } 576 }
530 577
531 dev_info(&priv->i2c->dev, 578#if IS_ENABLED(CONFIG_VIDEO_V4L2)
532 "%s: FCI FC2580 successfully identified\n", 579 /* Register controls */
533 KBUILD_MODNAME); 580 v4l2_ctrl_handler_init(&dev->hdl, 2);
534 581 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &fc2580_ctrl_ops,
535 fe->tuner_priv = priv; 582 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
536 memcpy(&fe->ops.tuner_ops, &fc2580_tuner_ops, 583 0, 1, 1, 1);
537 sizeof(struct dvb_tuner_ops)); 584 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &fc2580_ctrl_ops,
585 V4L2_CID_RF_TUNER_BANDWIDTH,
586 3000, 10000000, 1, 3000);
587 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
588 if (dev->hdl.error) {
589 ret = dev->hdl.error;
590 dev_err(&client->dev, "Could not initialize controls\n");
591 v4l2_ctrl_handler_free(&dev->hdl);
592 goto err_kfree;
593 }
594 dev->subdev.ctrl_handler = &dev->hdl;
595 dev->f_frequency = bands[0].rangelow;
596 dev->f_bandwidth = dev->bandwidth->val;
597 v4l2_i2c_subdev_init(&dev->subdev, client, &fc2580_subdev_ops);
598#endif
599 fe->tuner_priv = dev;
600 memcpy(&fe->ops.tuner_ops, &fc2580_dvb_tuner_ops,
601 sizeof(fe->ops.tuner_ops));
602 pdata->get_v4l2_subdev = fc2580_get_v4l2_subdev;
603 i2c_set_clientdata(client, dev);
604
605 dev_info(&client->dev, "FCI FC2580 successfully identified\n");
606 return 0;
607err_kfree:
608 kfree(dev);
609err:
610 dev_dbg(&client->dev, "failed=%d\n", ret);
611 return ret;
612}
538 613
539 if (fe->ops.i2c_gate_ctrl) 614static int fc2580_remove(struct i2c_client *client)
540 fe->ops.i2c_gate_ctrl(fe, 0); 615{
616 struct fc2580_dev *dev = i2c_get_clientdata(client);
541 617
542 return fe; 618 dev_dbg(&client->dev, "\n");
543err:
544 if (fe->ops.i2c_gate_ctrl)
545 fe->ops.i2c_gate_ctrl(fe, 0);
546 619
547 dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 620#if IS_ENABLED(CONFIG_VIDEO_V4L2)
548 kfree(priv); 621 v4l2_ctrl_handler_free(&dev->hdl);
549 return NULL; 622#endif
623 kfree(dev);
624 return 0;
550} 625}
551EXPORT_SYMBOL(fc2580_attach); 626
627static const struct i2c_device_id fc2580_id_table[] = {
628 {"fc2580", 0},
629 {}
630};
631MODULE_DEVICE_TABLE(i2c, fc2580_id_table);
632
633static struct i2c_driver fc2580_driver = {
634 .driver = {
635 .owner = THIS_MODULE,
636 .name = "fc2580",
637 .suppress_bind_attrs = true,
638 },
639 .probe = fc2580_probe,
640 .remove = fc2580_remove,
641 .id_table = fc2580_id_table,
642};
643
644module_i2c_driver(fc2580_driver);
552 645
553MODULE_DESCRIPTION("FCI FC2580 silicon tuner driver"); 646MODULE_DESCRIPTION("FCI FC2580 silicon tuner driver");
554MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 647MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
diff --git a/drivers/media/tuners/fc2580.h b/drivers/media/tuners/fc2580.h
index b1ce6770f88e..862ea46995d7 100644
--- a/drivers/media/tuners/fc2580.h
+++ b/drivers/media/tuners/fc2580.h
@@ -21,32 +21,26 @@
21#ifndef FC2580_H 21#ifndef FC2580_H
22#define FC2580_H 22#define FC2580_H
23 23
24#include <linux/kconfig.h>
25#include "dvb_frontend.h" 24#include "dvb_frontend.h"
25#include <media/v4l2-subdev.h>
26#include <linux/i2c.h>
26 27
27struct fc2580_config { 28/*
28 /* 29 * I2C address
29 * I2C address 30 * 0x56, ...
30 * 0x56, ... 31 */
31 */
32 u8 i2c_addr;
33 32
34 /* 33/**
35 * clock 34 * struct fc2580_platform_data - Platform data for the fc2580 driver
36 */ 35 * @clk: Clock frequency (0 = internal clock).
37 u32 clock; 36 * @dvb_frontend: DVB frontend.
38}; 37 * @get_v4l2_subdev: Get V4L2 subdev.
38 */
39struct fc2580_platform_data {
40 u32 clk;
41 struct dvb_frontend *dvb_frontend;
39 42
40#if IS_REACHABLE(CONFIG_MEDIA_TUNER_FC2580) 43 struct v4l2_subdev* (*get_v4l2_subdev)(struct i2c_client *);
41extern struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe, 44};
42 struct i2c_adapter *i2c, const struct fc2580_config *cfg);
43#else
44static inline struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
45 struct i2c_adapter *i2c, const struct fc2580_config *cfg)
46{
47 pr_warn("%s: driver disabled by Kconfig\n", __func__);
48 return NULL;
49}
50#endif
51 45
52#endif 46#endif
diff --git a/drivers/media/tuners/fc2580_priv.h b/drivers/media/tuners/fc2580_priv.h
index 646c99452136..031a43d7e7af 100644
--- a/drivers/media/tuners/fc2580_priv.h
+++ b/drivers/media/tuners/fc2580_priv.h
@@ -22,6 +22,9 @@
22#define FC2580_PRIV_H 22#define FC2580_PRIV_H
23 23
24#include "fc2580.h" 24#include "fc2580.h"
25#include <media/v4l2-ctrls.h>
26#include <media/v4l2-subdev.h>
27#include <linux/regmap.h>
25#include <linux/math64.h> 28#include <linux/math64.h>
26 29
27struct fc2580_reg_val { 30struct fc2580_reg_val {
@@ -50,7 +53,7 @@ static const struct fc2580_reg_val fc2580_init_reg_vals[] = {
50 53
51struct fc2580_pll { 54struct fc2580_pll {
52 u32 freq; 55 u32 freq;
53 u8 div; 56 u8 div_out;
54 u8 band; 57 u8 band;
55}; 58};
56 59
@@ -63,16 +66,15 @@ static const struct fc2580_pll fc2580_pll_lut[] = {
63 66
64struct fc2580_if_filter { 67struct fc2580_if_filter {
65 u32 freq; 68 u32 freq;
66 u16 mul;
67 u8 r36_val; 69 u8 r36_val;
68 u8 r39_val; 70 u8 r39_val;
69}; 71};
70 72
71static const struct fc2580_if_filter fc2580_if_filter_lut[] = { 73static const struct fc2580_if_filter fc2580_if_filter_lut[] = {
72 { 6000000, 4400, 0x18, 0x00}, 74 { 6000000, 0x18, 0x00},
73 { 7000000, 3910, 0x18, 0x80}, 75 { 7000000, 0x18, 0x80},
74 { 8000000, 3300, 0x18, 0x80}, 76 { 8000000, 0x18, 0x80},
75 {0xffffffff, 3300, 0x18, 0x80}, 77 {0xffffffff, 0x18, 0x80},
76}; 78};
77 79
78struct fc2580_freq_regs { 80struct fc2580_freq_regs {
@@ -110,15 +112,15 @@ static const struct fc2580_freq_regs fc2580_freq_regs_lut[] = {
110 0x50, 0x0f, 0x07, 0x00, 0x15, 0x03, 0x05, 0x10, 0x12, 0x08, 112 0x50, 0x0f, 0x07, 0x00, 0x15, 0x03, 0x05, 0x10, 0x12, 0x08,
111 0x0a, 0x78, 0x32, 0x54}, 113 0x0a, 0x78, 0x32, 0x54},
112 { 538000000, 114 { 538000000,
113 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c, 115 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x9f, 0x09, 0xff, 0x8c,
114 0x50, 0x13, 0x07, 0x06, 0x15, 0x06, 0x08, 0x10, 0x12, 0x0b, 116 0x50, 0x13, 0x07, 0x06, 0x15, 0x06, 0x08, 0x10, 0x12, 0x0b,
115 0x0c, 0x78, 0x32, 0x14}, 117 0x0c, 0x78, 0x32, 0x14},
116 { 794000000, 118 { 794000000,
117 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c, 119 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x9f, 0x09, 0xff, 0x8c,
118 0x50, 0x15, 0x03, 0x03, 0x15, 0x03, 0x05, 0x0c, 0x0e, 0x0b, 120 0x50, 0x15, 0x03, 0x03, 0x15, 0x03, 0x05, 0x0c, 0x0e, 0x0b,
119 0x0c, 0x78, 0x32, 0x14}, 121 0x0c, 0x78, 0x32, 0x14},
120 {1000000000, 122 {1000000000,
121 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c, 123 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x8f, 0x09, 0xff, 0x8c,
122 0x50, 0x15, 0x07, 0x06, 0x15, 0x07, 0x09, 0x10, 0x12, 0x0b, 124 0x50, 0x15, 0x07, 0x06, 0x15, 0x07, 0x09, 0x10, 0x12, 0x0b,
123 0x0c, 0x78, 0x32, 0x14}, 125 0x0c, 0x78, 0x32, 0x14},
124 {0xffffffff, 126 {0xffffffff,
@@ -127,9 +129,19 @@ static const struct fc2580_freq_regs fc2580_freq_regs_lut[] = {
127 0x0a, 0xa0, 0x50, 0x14}, 129 0x0a, 0xa0, 0x50, 0x14},
128}; 130};
129 131
130struct fc2580_priv { 132struct fc2580_dev {
131 const struct fc2580_config *cfg; 133 u32 clk;
132 struct i2c_adapter *i2c; 134 struct i2c_client *client;
135 struct regmap *regmap;
136 struct v4l2_subdev subdev;
137 bool active;
138 unsigned int f_frequency;
139 unsigned int f_bandwidth;
140
141 /* Controls */
142 struct v4l2_ctrl_handler hdl;
143 struct v4l2_ctrl *bandwidth_auto;
144 struct v4l2_ctrl *bandwidth;
133}; 145};
134 146
135#endif 147#endif
diff --git a/drivers/media/tuners/msi001.c b/drivers/media/tuners/msi001.c
index 74cfc3c98edb..b533240f8ec0 100644
--- a/drivers/media/tuners/msi001.c
+++ b/drivers/media/tuners/msi001.c
@@ -36,7 +36,7 @@ static const struct v4l2_frequency_band bands[] = {
36 }, 36 },
37}; 37};
38 38
39struct msi001 { 39struct msi001_dev {
40 struct spi_device *spi; 40 struct spi_device *spi;
41 struct v4l2_subdev sd; 41 struct v4l2_subdev sd;
42 42
@@ -51,25 +51,26 @@ struct msi001 {
51 unsigned int f_tuner; 51 unsigned int f_tuner;
52}; 52};
53 53
54static inline struct msi001 *sd_to_msi001(struct v4l2_subdev *sd) 54static inline struct msi001_dev *sd_to_msi001_dev(struct v4l2_subdev *sd)
55{ 55{
56 return container_of(sd, struct msi001, sd); 56 return container_of(sd, struct msi001_dev, sd);
57} 57}
58 58
59static int msi001_wreg(struct msi001 *s, u32 data) 59static int msi001_wreg(struct msi001_dev *dev, u32 data)
60{ 60{
61 /* Register format: 4 bits addr + 20 bits value */ 61 /* Register format: 4 bits addr + 20 bits value */
62 return spi_write(s->spi, &data, 3); 62 return spi_write(dev->spi, &data, 3);
63}; 63};
64 64
65static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain, 65static int msi001_set_gain(struct msi001_dev *dev, int lna_gain, int mixer_gain,
66 int if_gain) 66 int if_gain)
67{ 67{
68 struct spi_device *spi = dev->spi;
68 int ret; 69 int ret;
69 u32 reg; 70 u32 reg;
70 71
71 dev_dbg(&s->spi->dev, "lna=%d mixer=%d if=%d\n", 72 dev_dbg(&spi->dev, "lna=%d mixer=%d if=%d\n",
72 lna_gain, mixer_gain, if_gain); 73 lna_gain, mixer_gain, if_gain);
73 74
74 reg = 1 << 0; 75 reg = 1 << 0;
75 reg |= (59 - if_gain) << 4; 76 reg |= (59 - if_gain) << 4;
@@ -78,28 +79,29 @@ static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain,
78 reg |= (1 - lna_gain) << 13; 79 reg |= (1 - lna_gain) << 13;
79 reg |= 4 << 14; 80 reg |= 4 << 14;
80 reg |= 0 << 17; 81 reg |= 0 << 17;
81 ret = msi001_wreg(s, reg); 82 ret = msi001_wreg(dev, reg);
82 if (ret) 83 if (ret)
83 goto err; 84 goto err;
84 85
85 return 0; 86 return 0;
86err: 87err:
87 dev_dbg(&s->spi->dev, "failed %d\n", ret); 88 dev_dbg(&spi->dev, "failed %d\n", ret);
88 return ret; 89 return ret;
89}; 90};
90 91
91static int msi001_set_tuner(struct msi001 *s) 92static int msi001_set_tuner(struct msi001_dev *dev)
92{ 93{
94 struct spi_device *spi = dev->spi;
93 int ret, i; 95 int ret, i;
94 unsigned int n, m, thresh, frac, vco_step, tmp, f_if1; 96 unsigned int uitmp, div_n, k, k_thresh, k_frac, div_lo, f_if1;
95 u32 reg; 97 u32 reg;
96 u64 f_vco, tmp64; 98 u64 f_vco;
97 u8 mode, filter_mode, lo_div; 99 u8 mode, filter_mode;
98 100
99 static const struct { 101 static const struct {
100 u32 rf; 102 u32 rf;
101 u8 mode; 103 u8 mode;
102 u8 lo_div; 104 u8 div_lo;
103 } band_lut[] = { 105 } band_lut[] = {
104 { 50000000, 0xe1, 16}, /* AM_MODE2, antenna 2 */ 106 { 50000000, 0xe1, 16}, /* AM_MODE2, antenna 2 */
105 {108000000, 0x42, 32}, /* VHF_MODE */ 107 {108000000, 0x42, 32}, /* VHF_MODE */
@@ -130,7 +132,7 @@ static int msi001_set_tuner(struct msi001 *s)
130 {8000000, 0x07}, /* 8 MHz */ 132 {8000000, 0x07}, /* 8 MHz */
131 }; 133 };
132 134
133 unsigned int f_rf = s->f_tuner; 135 unsigned int f_rf = dev->f_tuner;
134 136
135 /* 137 /*
136 * bandwidth (Hz) 138 * bandwidth (Hz)
@@ -144,19 +146,18 @@ static int msi001_set_tuner(struct msi001 *s)
144 */ 146 */
145 unsigned int f_if = 0; 147 unsigned int f_if = 0;
146 #define F_REF 24000000 148 #define F_REF 24000000
147 #define R_REF 4 149 #define DIV_PRE_N 4
148 #define F_OUT_STEP 1 150 #define F_VCO_STEP div_lo
149 151
150 dev_dbg(&s->spi->dev, "f_rf=%d f_if=%d\n", f_rf, f_if); 152 dev_dbg(&spi->dev, "f_rf=%d f_if=%d\n", f_rf, f_if);
151 153
152 for (i = 0; i < ARRAY_SIZE(band_lut); i++) { 154 for (i = 0; i < ARRAY_SIZE(band_lut); i++) {
153 if (f_rf <= band_lut[i].rf) { 155 if (f_rf <= band_lut[i].rf) {
154 mode = band_lut[i].mode; 156 mode = band_lut[i].mode;
155 lo_div = band_lut[i].lo_div; 157 div_lo = band_lut[i].div_lo;
156 break; 158 break;
157 } 159 }
158 } 160 }
159
160 if (i == ARRAY_SIZE(band_lut)) { 161 if (i == ARRAY_SIZE(band_lut)) {
161 ret = -EINVAL; 162 ret = -EINVAL;
162 goto err; 163 goto err;
@@ -174,14 +175,13 @@ static int msi001_set_tuner(struct msi001 *s)
174 break; 175 break;
175 } 176 }
176 } 177 }
177
178 if (i == ARRAY_SIZE(if_freq_lut)) { 178 if (i == ARRAY_SIZE(if_freq_lut)) {
179 ret = -EINVAL; 179 ret = -EINVAL;
180 goto err; 180 goto err;
181 } 181 }
182 182
183 /* filters */ 183 /* filters */
184 bandwidth = s->bandwidth->val; 184 bandwidth = dev->bandwidth->val;
185 bandwidth = clamp(bandwidth, 200000U, 8000000U); 185 bandwidth = clamp(bandwidth, 200000U, 8000000U);
186 186
187 for (i = 0; i < ARRAY_SIZE(bandwidth_lut); i++) { 187 for (i = 0; i < ARRAY_SIZE(bandwidth_lut); i++) {
@@ -190,48 +190,61 @@ static int msi001_set_tuner(struct msi001 *s)
190 break; 190 break;
191 } 191 }
192 } 192 }
193
194 if (i == ARRAY_SIZE(bandwidth_lut)) { 193 if (i == ARRAY_SIZE(bandwidth_lut)) {
195 ret = -EINVAL; 194 ret = -EINVAL;
196 goto err; 195 goto err;
197 } 196 }
198 197
199 s->bandwidth->val = bandwidth_lut[i].freq; 198 dev->bandwidth->val = bandwidth_lut[i].freq;
200 199
201 dev_dbg(&s->spi->dev, "bandwidth selected=%d\n", bandwidth_lut[i].freq); 200 dev_dbg(&spi->dev, "bandwidth selected=%d\n", bandwidth_lut[i].freq);
202 201
203 f_vco = (u64) (f_rf + f_if + f_if1) * lo_div; 202 /*
204 tmp64 = f_vco; 203 * Fractional-N synthesizer
205 m = do_div(tmp64, F_REF * R_REF); 204 *
206 n = (unsigned int) tmp64; 205 * +---------------------------------------+
206 * v |
207 * Fref +----+ +-------+ +----+ +------+ +---+
208 * ------> | PD | --> | VCO | ------> | /4 | --> | /N.F | <-- | K |
209 * +----+ +-------+ +----+ +------+ +---+
210 * |
211 * |
212 * v
213 * +-------+ Fout
214 * | /Rout | ------>
215 * +-------+
216 */
207 217
208 vco_step = F_OUT_STEP * lo_div; 218 /* Calculate PLL integer and fractional control word. */
209 thresh = (F_REF * R_REF) / vco_step; 219 f_vco = (u64) (f_rf + f_if + f_if1) * div_lo;
210 frac = 1ul * thresh * m / (F_REF * R_REF); 220 div_n = div_u64_rem(f_vco, DIV_PRE_N * F_REF, &k);
221 k_thresh = (DIV_PRE_N * F_REF) / F_VCO_STEP;
222 k_frac = div_u64((u64) k * k_thresh, (DIV_PRE_N * F_REF));
211 223
212 /* Find out greatest common divisor and divide to smaller. */ 224 /* Find out greatest common divisor and divide to smaller. */
213 tmp = gcd(thresh, frac); 225 uitmp = gcd(k_thresh, k_frac);
214 thresh /= tmp; 226 k_thresh /= uitmp;
215 frac /= tmp; 227 k_frac /= uitmp;
216 228
217 /* Force divide to reg max. Resolution will be reduced. */ 229 /* Force divide to reg max. Resolution will be reduced. */
218 tmp = DIV_ROUND_UP(thresh, 4095); 230 uitmp = DIV_ROUND_UP(k_thresh, 4095);
219 thresh = DIV_ROUND_CLOSEST(thresh, tmp); 231 k_thresh = DIV_ROUND_CLOSEST(k_thresh, uitmp);
220 frac = DIV_ROUND_CLOSEST(frac, tmp); 232 k_frac = DIV_ROUND_CLOSEST(k_frac, uitmp);
221 233
222 /* calc real RF set */ 234 /* Calculate real RF set. */
223 tmp = 1ul * F_REF * R_REF * n; 235 uitmp = (unsigned int) F_REF * DIV_PRE_N * div_n;
224 tmp += 1ul * F_REF * R_REF * frac / thresh; 236 uitmp += (unsigned int) F_REF * DIV_PRE_N * k_frac / k_thresh;
225 tmp /= lo_div; 237 uitmp /= div_lo;
226 238
227 dev_dbg(&s->spi->dev, "rf=%u:%u n=%d thresh=%d frac=%d\n", 239 dev_dbg(&spi->dev,
228 f_rf, tmp, n, thresh, frac); 240 "f_rf=%u:%u f_vco=%llu div_n=%u k_thresh=%u k_frac=%u div_lo=%u\n",
241 f_rf, uitmp, f_vco, div_n, k_thresh, k_frac, div_lo);
229 242
230 ret = msi001_wreg(s, 0x00000e); 243 ret = msi001_wreg(dev, 0x00000e);
231 if (ret) 244 if (ret)
232 goto err; 245 goto err;
233 246
234 ret = msi001_wreg(s, 0x000003); 247 ret = msi001_wreg(dev, 0x000003);
235 if (ret) 248 if (ret)
236 goto err; 249 goto err;
237 250
@@ -241,54 +254,55 @@ static int msi001_set_tuner(struct msi001 *s)
241 reg |= bandwidth << 14; 254 reg |= bandwidth << 14;
242 reg |= 0x02 << 17; 255 reg |= 0x02 << 17;
243 reg |= 0x00 << 20; 256 reg |= 0x00 << 20;
244 ret = msi001_wreg(s, reg); 257 ret = msi001_wreg(dev, reg);
245 if (ret) 258 if (ret)
246 goto err; 259 goto err;
247 260
248 reg = 5 << 0; 261 reg = 5 << 0;
249 reg |= thresh << 4; 262 reg |= k_thresh << 4;
250 reg |= 1 << 19; 263 reg |= 1 << 19;
251 reg |= 1 << 21; 264 reg |= 1 << 21;
252 ret = msi001_wreg(s, reg); 265 ret = msi001_wreg(dev, reg);
253 if (ret) 266 if (ret)
254 goto err; 267 goto err;
255 268
256 reg = 2 << 0; 269 reg = 2 << 0;
257 reg |= frac << 4; 270 reg |= k_frac << 4;
258 reg |= n << 16; 271 reg |= div_n << 16;
259 ret = msi001_wreg(s, reg); 272 ret = msi001_wreg(dev, reg);
260 if (ret) 273 if (ret)
261 goto err; 274 goto err;
262 275
263 ret = msi001_set_gain(s, s->lna_gain->cur.val, s->mixer_gain->cur.val, 276 ret = msi001_set_gain(dev, dev->lna_gain->cur.val,
264 s->if_gain->cur.val); 277 dev->mixer_gain->cur.val, dev->if_gain->cur.val);
265 if (ret) 278 if (ret)
266 goto err; 279 goto err;
267 280
268 reg = 6 << 0; 281 reg = 6 << 0;
269 reg |= 63 << 4; 282 reg |= 63 << 4;
270 reg |= 4095 << 10; 283 reg |= 4095 << 10;
271 ret = msi001_wreg(s, reg); 284 ret = msi001_wreg(dev, reg);
272 if (ret) 285 if (ret)
273 goto err; 286 goto err;
274 287
275 return 0; 288 return 0;
276err: 289err:
277 dev_dbg(&s->spi->dev, "failed %d\n", ret); 290 dev_dbg(&spi->dev, "failed %d\n", ret);
278 return ret; 291 return ret;
279}; 292}
280 293
281static int msi001_s_power(struct v4l2_subdev *sd, int on) 294static int msi001_s_power(struct v4l2_subdev *sd, int on)
282{ 295{
283 struct msi001 *s = sd_to_msi001(sd); 296 struct msi001_dev *dev = sd_to_msi001_dev(sd);
297 struct spi_device *spi = dev->spi;
284 int ret; 298 int ret;
285 299
286 dev_dbg(&s->spi->dev, "on=%d\n", on); 300 dev_dbg(&spi->dev, "on=%d\n", on);
287 301
288 if (on) 302 if (on)
289 ret = 0; 303 ret = 0;
290 else 304 else
291 ret = msi001_wreg(s, 0x000000); 305 ret = msi001_wreg(dev, 0x000000);
292 306
293 return ret; 307 return ret;
294} 308}
@@ -299,9 +313,10 @@ static const struct v4l2_subdev_core_ops msi001_core_ops = {
299 313
300static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v) 314static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
301{ 315{
302 struct msi001 *s = sd_to_msi001(sd); 316 struct msi001_dev *dev = sd_to_msi001_dev(sd);
317 struct spi_device *spi = dev->spi;
303 318
304 dev_dbg(&s->spi->dev, "index=%d\n", v->index); 319 dev_dbg(&spi->dev, "index=%d\n", v->index);
305 320
306 strlcpy(v->name, "Mirics MSi001", sizeof(v->name)); 321 strlcpy(v->name, "Mirics MSi001", sizeof(v->name));
307 v->type = V4L2_TUNER_RF; 322 v->type = V4L2_TUNER_RF;
@@ -314,47 +329,51 @@ static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
314 329
315static int msi001_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v) 330static int msi001_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
316{ 331{
317 struct msi001 *s = sd_to_msi001(sd); 332 struct msi001_dev *dev = sd_to_msi001_dev(sd);
333 struct spi_device *spi = dev->spi;
318 334
319 dev_dbg(&s->spi->dev, "index=%d\n", v->index); 335 dev_dbg(&spi->dev, "index=%d\n", v->index);
320 return 0; 336 return 0;
321} 337}
322 338
323static int msi001_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) 339static int msi001_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
324{ 340{
325 struct msi001 *s = sd_to_msi001(sd); 341 struct msi001_dev *dev = sd_to_msi001_dev(sd);
342 struct spi_device *spi = dev->spi;
326 343
327 dev_dbg(&s->spi->dev, "tuner=%d\n", f->tuner); 344 dev_dbg(&spi->dev, "tuner=%d\n", f->tuner);
328 f->frequency = s->f_tuner; 345 f->frequency = dev->f_tuner;
329 return 0; 346 return 0;
330} 347}
331 348
332static int msi001_s_frequency(struct v4l2_subdev *sd, 349static int msi001_s_frequency(struct v4l2_subdev *sd,
333 const struct v4l2_frequency *f) 350 const struct v4l2_frequency *f)
334{ 351{
335 struct msi001 *s = sd_to_msi001(sd); 352 struct msi001_dev *dev = sd_to_msi001_dev(sd);
353 struct spi_device *spi = dev->spi;
336 unsigned int band; 354 unsigned int band;
337 355
338 dev_dbg(&s->spi->dev, "tuner=%d type=%d frequency=%u\n", 356 dev_dbg(&spi->dev, "tuner=%d type=%d frequency=%u\n",
339 f->tuner, f->type, f->frequency); 357 f->tuner, f->type, f->frequency);
340 358
341 if (f->frequency < ((bands[0].rangehigh + bands[1].rangelow) / 2)) 359 if (f->frequency < ((bands[0].rangehigh + bands[1].rangelow) / 2))
342 band = 0; 360 band = 0;
343 else 361 else
344 band = 1; 362 band = 1;
345 s->f_tuner = clamp_t(unsigned int, f->frequency, 363 dev->f_tuner = clamp_t(unsigned int, f->frequency,
346 bands[band].rangelow, bands[band].rangehigh); 364 bands[band].rangelow, bands[band].rangehigh);
347 365
348 return msi001_set_tuner(s); 366 return msi001_set_tuner(dev);
349} 367}
350 368
351static int msi001_enum_freq_bands(struct v4l2_subdev *sd, 369static int msi001_enum_freq_bands(struct v4l2_subdev *sd,
352 struct v4l2_frequency_band *band) 370 struct v4l2_frequency_band *band)
353{ 371{
354 struct msi001 *s = sd_to_msi001(sd); 372 struct msi001_dev *dev = sd_to_msi001_dev(sd);
373 struct spi_device *spi = dev->spi;
355 374
356 dev_dbg(&s->spi->dev, "tuner=%d type=%d index=%d\n", 375 dev_dbg(&spi->dev, "tuner=%d type=%d index=%d\n",
357 band->tuner, band->type, band->index); 376 band->tuner, band->type, band->index);
358 377
359 if (band->index >= ARRAY_SIZE(bands)) 378 if (band->index >= ARRAY_SIZE(bands))
360 return -EINVAL; 379 return -EINVAL;
@@ -381,34 +400,37 @@ static const struct v4l2_subdev_ops msi001_ops = {
381 400
382static int msi001_s_ctrl(struct v4l2_ctrl *ctrl) 401static int msi001_s_ctrl(struct v4l2_ctrl *ctrl)
383{ 402{
384 struct msi001 *s = container_of(ctrl->handler, struct msi001, hdl); 403 struct msi001_dev *dev = container_of(ctrl->handler, struct msi001_dev, hdl);
404 struct spi_device *spi = dev->spi;
385 405
386 int ret; 406 int ret;
387 407
388 dev_dbg(&s->spi->dev, 408 dev_dbg(&spi->dev, "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n",
389 "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n", 409 ctrl->id, ctrl->name, ctrl->val, ctrl->minimum, ctrl->maximum,
390 ctrl->id, ctrl->name, ctrl->val, 410 ctrl->step);
391 ctrl->minimum, ctrl->maximum, ctrl->step);
392 411
393 switch (ctrl->id) { 412 switch (ctrl->id) {
394 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO: 413 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
395 case V4L2_CID_RF_TUNER_BANDWIDTH: 414 case V4L2_CID_RF_TUNER_BANDWIDTH:
396 ret = msi001_set_tuner(s); 415 ret = msi001_set_tuner(dev);
397 break; 416 break;
398 case V4L2_CID_RF_TUNER_LNA_GAIN: 417 case V4L2_CID_RF_TUNER_LNA_GAIN:
399 ret = msi001_set_gain(s, s->lna_gain->val, 418 ret = msi001_set_gain(dev, dev->lna_gain->val,
400 s->mixer_gain->cur.val, s->if_gain->cur.val); 419 dev->mixer_gain->cur.val,
420 dev->if_gain->cur.val);
401 break; 421 break;
402 case V4L2_CID_RF_TUNER_MIXER_GAIN: 422 case V4L2_CID_RF_TUNER_MIXER_GAIN:
403 ret = msi001_set_gain(s, s->lna_gain->cur.val, 423 ret = msi001_set_gain(dev, dev->lna_gain->cur.val,
404 s->mixer_gain->val, s->if_gain->cur.val); 424 dev->mixer_gain->val,
425 dev->if_gain->cur.val);
405 break; 426 break;
406 case V4L2_CID_RF_TUNER_IF_GAIN: 427 case V4L2_CID_RF_TUNER_IF_GAIN:
407 ret = msi001_set_gain(s, s->lna_gain->cur.val, 428 ret = msi001_set_gain(dev, dev->lna_gain->cur.val,
408 s->mixer_gain->cur.val, s->if_gain->val); 429 dev->mixer_gain->cur.val,
430 dev->if_gain->val);
409 break; 431 break;
410 default: 432 default:
411 dev_dbg(&s->spi->dev, "unknown control %d\n", ctrl->id); 433 dev_dbg(&spi->dev, "unknown control %d\n", ctrl->id);
412 ret = -EINVAL; 434 ret = -EINVAL;
413 } 435 }
414 436
@@ -421,56 +443,54 @@ static const struct v4l2_ctrl_ops msi001_ctrl_ops = {
421 443
422static int msi001_probe(struct spi_device *spi) 444static int msi001_probe(struct spi_device *spi)
423{ 445{
424 struct msi001 *s; 446 struct msi001_dev *dev;
425 int ret; 447 int ret;
426 448
427 dev_dbg(&spi->dev, "\n"); 449 dev_dbg(&spi->dev, "\n");
428 450
429 s = kzalloc(sizeof(struct msi001), GFP_KERNEL); 451 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
430 if (s == NULL) { 452 if (!dev) {
431 ret = -ENOMEM; 453 ret = -ENOMEM;
432 dev_dbg(&spi->dev, "Could not allocate memory for msi001\n"); 454 goto err;
433 goto err_kfree;
434 } 455 }
435 456
436 s->spi = spi; 457 dev->spi = spi;
437 s->f_tuner = bands[0].rangelow; 458 dev->f_tuner = bands[0].rangelow;
438 v4l2_spi_subdev_init(&s->sd, spi, &msi001_ops); 459 v4l2_spi_subdev_init(&dev->sd, spi, &msi001_ops);
439 460
440 /* Register controls */ 461 /* Register controls */
441 v4l2_ctrl_handler_init(&s->hdl, 5); 462 v4l2_ctrl_handler_init(&dev->hdl, 5);
442 s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops, 463 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
443 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1); 464 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1);
444 s->bandwidth = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops, 465 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
445 V4L2_CID_RF_TUNER_BANDWIDTH, 200000, 8000000, 1, 200000); 466 V4L2_CID_RF_TUNER_BANDWIDTH, 200000, 8000000, 1, 200000);
446 v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false); 467 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
447 s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops, 468 dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
448 V4L2_CID_RF_TUNER_LNA_GAIN, 0, 1, 1, 1); 469 V4L2_CID_RF_TUNER_LNA_GAIN, 0, 1, 1, 1);
449 s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops, 470 dev->mixer_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
450 V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1); 471 V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1);
451 s->if_gain = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops, 472 dev->if_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
452 V4L2_CID_RF_TUNER_IF_GAIN, 0, 59, 1, 0); 473 V4L2_CID_RF_TUNER_IF_GAIN, 0, 59, 1, 0);
453 if (s->hdl.error) { 474 if (dev->hdl.error) {
454 ret = s->hdl.error; 475 ret = dev->hdl.error;
455 dev_err(&s->spi->dev, "Could not initialize controls\n"); 476 dev_err(&spi->dev, "Could not initialize controls\n");
456 /* control init failed, free handler */ 477 /* control init failed, free handler */
457 goto err_ctrl_handler_free; 478 goto err_ctrl_handler_free;
458 } 479 }
459 480
460 s->sd.ctrl_handler = &s->hdl; 481 dev->sd.ctrl_handler = &dev->hdl;
461 return 0; 482 return 0;
462
463err_ctrl_handler_free: 483err_ctrl_handler_free:
464 v4l2_ctrl_handler_free(&s->hdl); 484 v4l2_ctrl_handler_free(&dev->hdl);
465err_kfree: 485 kfree(dev);
466 kfree(s); 486err:
467 return ret; 487 return ret;
468} 488}
469 489
470static int msi001_remove(struct spi_device *spi) 490static int msi001_remove(struct spi_device *spi)
471{ 491{
472 struct v4l2_subdev *sd = spi_get_drvdata(spi); 492 struct v4l2_subdev *sd = spi_get_drvdata(spi);
473 struct msi001 *s = sd_to_msi001(sd); 493 struct msi001_dev *dev = sd_to_msi001_dev(sd);
474 494
475 dev_dbg(&spi->dev, "\n"); 495 dev_dbg(&spi->dev, "\n");
476 496
@@ -478,26 +498,27 @@ static int msi001_remove(struct spi_device *spi)
478 * Registered by v4l2_spi_new_subdev() from master driver, but we must 498 * Registered by v4l2_spi_new_subdev() from master driver, but we must
479 * unregister it from here. Weird. 499 * unregister it from here. Weird.
480 */ 500 */
481 v4l2_device_unregister_subdev(&s->sd); 501 v4l2_device_unregister_subdev(&dev->sd);
482 v4l2_ctrl_handler_free(&s->hdl); 502 v4l2_ctrl_handler_free(&dev->hdl);
483 kfree(s); 503 kfree(dev);
484 return 0; 504 return 0;
485} 505}
486 506
487static const struct spi_device_id msi001_id[] = { 507static const struct spi_device_id msi001_id_table[] = {
488 {"msi001", 0}, 508 {"msi001", 0},
489 {} 509 {}
490}; 510};
491MODULE_DEVICE_TABLE(spi, msi001_id); 511MODULE_DEVICE_TABLE(spi, msi001_id_table);
492 512
493static struct spi_driver msi001_driver = { 513static struct spi_driver msi001_driver = {
494 .driver = { 514 .driver = {
495 .name = "msi001", 515 .name = "msi001",
496 .owner = THIS_MODULE, 516 .owner = THIS_MODULE,
517 .suppress_bind_attrs = true,
497 }, 518 },
498 .probe = msi001_probe, 519 .probe = msi001_probe,
499 .remove = msi001_remove, 520 .remove = msi001_remove,
500 .id_table = msi001_id, 521 .id_table = msi001_id_table,
501}; 522};
502module_spi_driver(msi001_driver); 523module_spi_driver(msi001_driver);
503 524
diff --git a/drivers/media/tuners/qt1010.c b/drivers/media/tuners/qt1010.c
index bc419f8a9671..ae8cbece6d2b 100644
--- a/drivers/media/tuners/qt1010.c
+++ b/drivers/media/tuners/qt1010.c
@@ -294,7 +294,7 @@ static int qt1010_init(struct dvb_frontend *fe)
294 int err = 0; 294 int err = 0;
295 u8 i, tmpval, *valptr = NULL; 295 u8 i, tmpval, *valptr = NULL;
296 296
297 qt1010_i2c_oper_t i2c_data[] = { 297 static const qt1010_i2c_oper_t i2c_data[] = {
298 { QT1010_WR, 0x01, 0x80 }, 298 { QT1010_WR, 0x01, 0x80 },
299 { QT1010_WR, 0x0d, 0x84 }, 299 { QT1010_WR, 0x0d, 0x84 },
300 { QT1010_WR, 0x0e, 0xb7 }, 300 { QT1010_WR, 0x0e, 0xb7 },
@@ -354,13 +354,17 @@ static int qt1010_init(struct dvb_frontend *fe)
354 valptr = &priv->reg1f_init_val; 354 valptr = &priv->reg1f_init_val;
355 else 355 else
356 valptr = &tmpval; 356 valptr = &tmpval;
357
358 BUG_ON(i >= ARRAY_SIZE(i2c_data) - 1);
359
357 err = qt1010_init_meas1(priv, i2c_data[i+1].reg, 360 err = qt1010_init_meas1(priv, i2c_data[i+1].reg,
358 i2c_data[i].reg, 361 i2c_data[i].reg,
359 i2c_data[i].val, valptr); 362 i2c_data[i].val, valptr);
360 i++; 363 i++;
361 break; 364 break;
362 } 365 }
363 if (err) return err; 366 if (err)
367 return err;
364 } 368 }
365 369
366 for (i = 0x31; i < 0x3a; i++) /* 0x31 - 0x39 */ 370 for (i = 0x31; i < 0x3a; i++) /* 0x31 - 0x39 */
diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 71159a58860f..a7a8452e99d2 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -941,8 +941,8 @@ static int r820t_sysfreq_sel(struct r820t_priv *priv, u32 freq,
941 rc = r820t_write_reg_mask(priv, 0x10, 0x00, 0x04); 941 rc = r820t_write_reg_mask(priv, 0x10, 0x00, 0x04);
942 if (rc < 0) 942 if (rc < 0)
943 return rc; 943 return rc;
944 } 944 }
945 return 0; 945 return 0;
946} 946}
947 947
948static int r820t_set_tv_standard(struct r820t_priv *priv, 948static int r820t_set_tv_standard(struct r820t_priv *priv,
diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index d74ae26621ca..a6245ef379c4 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -79,6 +79,7 @@ static int si2157_init(struct dvb_frontend *fe)
79{ 79{
80 struct i2c_client *client = fe->tuner_priv; 80 struct i2c_client *client = fe->tuner_priv;
81 struct si2157_dev *dev = i2c_get_clientdata(client); 81 struct si2157_dev *dev = i2c_get_clientdata(client);
82 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
82 int ret, len, remaining; 83 int ret, len, remaining;
83 struct si2157_cmd cmd; 84 struct si2157_cmd cmd;
84 const struct firmware *fw; 85 const struct firmware *fw;
@@ -201,9 +202,14 @@ skip_fw_download:
201 dev->fw_loaded = true; 202 dev->fw_loaded = true;
202 203
203warm: 204warm:
205 /* init statistics in order signal app which are supported */
206 c->strength.len = 1;
207 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
208 /* start statistics polling */
209 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(1000));
210
204 dev->active = true; 211 dev->active = true;
205 return 0; 212 return 0;
206
207err_release_firmware: 213err_release_firmware:
208 release_firmware(fw); 214 release_firmware(fw);
209err: 215err:
@@ -222,6 +228,9 @@ static int si2157_sleep(struct dvb_frontend *fe)
222 228
223 dev->active = false; 229 dev->active = false;
224 230
231 /* stop statistics polling */
232 cancel_delayed_work_sync(&dev->stat_work);
233
225 /* standby */ 234 /* standby */
226 memcpy(cmd.args, "\x16\x00", 2); 235 memcpy(cmd.args, "\x16\x00", 2);
227 cmd.wlen = 2; 236 cmd.wlen = 2;
@@ -298,7 +307,8 @@ static int si2157_set_params(struct dvb_frontend *fe)
298 if (dev->chiptype == SI2157_CHIPTYPE_SI2146) 307 if (dev->chiptype == SI2157_CHIPTYPE_SI2146)
299 memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6); 308 memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6);
300 else 309 else
301 memcpy(cmd.args, "\x14\x00\x02\x07\x01\x00", 6); 310 memcpy(cmd.args, "\x14\x00\x02\x07\x00\x00", 6);
311 cmd.args[4] = dev->if_port;
302 cmd.wlen = 6; 312 cmd.wlen = 6;
303 cmd.rlen = 4; 313 cmd.rlen = 4;
304 ret = si2157_cmd_execute(client, &cmd); 314 ret = si2157_cmd_execute(client, &cmd);
@@ -359,6 +369,34 @@ static const struct dvb_tuner_ops si2157_ops = {
359 .get_if_frequency = si2157_get_if_frequency, 369 .get_if_frequency = si2157_get_if_frequency,
360}; 370};
361 371
372static void si2157_stat_work(struct work_struct *work)
373{
374 struct si2157_dev *dev = container_of(work, struct si2157_dev, stat_work.work);
375 struct dvb_frontend *fe = dev->fe;
376 struct i2c_client *client = fe->tuner_priv;
377 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
378 struct si2157_cmd cmd;
379 int ret;
380
381 dev_dbg(&client->dev, "\n");
382
383 memcpy(cmd.args, "\x42\x00", 2);
384 cmd.wlen = 2;
385 cmd.rlen = 12;
386 ret = si2157_cmd_execute(client, &cmd);
387 if (ret)
388 goto err;
389
390 c->strength.stat[0].scale = FE_SCALE_DECIBEL;
391 c->strength.stat[0].svalue = (s8) cmd.args[3] * 1000;
392
393 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
394 return;
395err:
396 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
397 dev_dbg(&client->dev, "failed=%d\n", ret);
398}
399
362static int si2157_probe(struct i2c_client *client, 400static int si2157_probe(struct i2c_client *client,
363 const struct i2c_device_id *id) 401 const struct i2c_device_id *id)
364{ 402{
@@ -378,10 +416,12 @@ static int si2157_probe(struct i2c_client *client,
378 i2c_set_clientdata(client, dev); 416 i2c_set_clientdata(client, dev);
379 dev->fe = cfg->fe; 417 dev->fe = cfg->fe;
380 dev->inversion = cfg->inversion; 418 dev->inversion = cfg->inversion;
419 dev->if_port = cfg->if_port;
381 dev->fw_loaded = false; 420 dev->fw_loaded = false;
382 dev->chiptype = (u8)id->driver_data; 421 dev->chiptype = (u8)id->driver_data;
383 dev->if_frequency = 5000000; /* default value of property 0x0706 */ 422 dev->if_frequency = 5000000; /* default value of property 0x0706 */
384 mutex_init(&dev->i2c_mutex); 423 mutex_init(&dev->i2c_mutex);
424 INIT_DELAYED_WORK(&dev->stat_work, si2157_stat_work);
385 425
386 /* check if the tuner is there */ 426 /* check if the tuner is there */
387 cmd.wlen = 0; 427 cmd.wlen = 0;
diff --git a/drivers/media/tuners/si2157.h b/drivers/media/tuners/si2157.h
index a564c4a9fba7..4db97ab744d6 100644
--- a/drivers/media/tuners/si2157.h
+++ b/drivers/media/tuners/si2157.h
@@ -34,6 +34,12 @@ struct si2157_config {
34 * Spectral Inversion 34 * Spectral Inversion
35 */ 35 */
36 bool inversion; 36 bool inversion;
37
38 /*
39 * Port selection
40 * Select the RF interface to use (pins 9+11 or 12+13)
41 */
42 u8 if_port;
37}; 43};
38 44
39#endif 45#endif
diff --git a/drivers/media/tuners/si2157_priv.h b/drivers/media/tuners/si2157_priv.h
index cd8fa5b25304..ecc463db8f69 100644
--- a/drivers/media/tuners/si2157_priv.h
+++ b/drivers/media/tuners/si2157_priv.h
@@ -28,7 +28,9 @@ struct si2157_dev {
28 bool fw_loaded; 28 bool fw_loaded;
29 bool inversion; 29 bool inversion;
30 u8 chiptype; 30 u8 chiptype;
31 u8 if_port;
31 u32 if_frequency; 32 u32 if_frequency;
33 struct delayed_work stat_work;
32}; 34};
33 35
34#define SI2157_CHIPTYPE_SI2157 0 36#define SI2157_CHIPTYPE_SI2157 0
diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index 83a6240f64d3..d4f6ca0c4d92 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Infineon TUA 9001 silicon tuner driver 2 * Infineon TUA9001 silicon tuner driver
3 * 3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -12,138 +12,87 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
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 */ 15 */
20 16
21#include "tua9001.h"
22#include "tua9001_priv.h" 17#include "tua9001_priv.h"
23 18
24/* write register */
25static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val)
26{
27 int ret;
28 u8 buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff };
29 struct i2c_msg msg[1] = {
30 {
31 .addr = priv->cfg->i2c_addr,
32 .flags = 0,
33 .len = sizeof(buf),
34 .buf = buf,
35 }
36 };
37
38 ret = i2c_transfer(priv->i2c, msg, 1);
39 if (ret == 1) {
40 ret = 0;
41 } else {
42 dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x\n",
43 KBUILD_MODNAME, ret, reg);
44 ret = -EREMOTEIO;
45 }
46
47 return ret;
48}
49
50static int tua9001_release(struct dvb_frontend *fe)
51{
52 struct tua9001_priv *priv = fe->tuner_priv;
53 int ret = 0;
54
55 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
56
57 if (fe->callback)
58 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
59 TUA9001_CMD_CEN, 0);
60
61 kfree(fe->tuner_priv);
62 fe->tuner_priv = NULL;
63
64 return ret;
65}
66
67static int tua9001_init(struct dvb_frontend *fe) 19static int tua9001_init(struct dvb_frontend *fe)
68{ 20{
69 struct tua9001_priv *priv = fe->tuner_priv; 21 struct tua9001_dev *dev = fe->tuner_priv;
70 int ret = 0; 22 struct i2c_client *client = dev->client;
71 u8 i; 23 int ret, i;
72 struct reg_val data[] = { 24 static const struct tua9001_reg_val data[] = {
73 { 0x1e, 0x6512 }, 25 {0x1e, 0x6512},
74 { 0x25, 0xb888 }, 26 {0x25, 0xb888},
75 { 0x39, 0x5460 }, 27 {0x39, 0x5460},
76 { 0x3b, 0x00c0 }, 28 {0x3b, 0x00c0},
77 { 0x3a, 0xf000 }, 29 {0x3a, 0xf000},
78 { 0x08, 0x0000 }, 30 {0x08, 0x0000},
79 { 0x32, 0x0030 }, 31 {0x32, 0x0030},
80 { 0x41, 0x703a }, 32 {0x41, 0x703a},
81 { 0x40, 0x1c78 }, 33 {0x40, 0x1c78},
82 { 0x2c, 0x1c00 }, 34 {0x2c, 0x1c00},
83 { 0x36, 0xc013 }, 35 {0x36, 0xc013},
84 { 0x37, 0x6f18 }, 36 {0x37, 0x6f18},
85 { 0x27, 0x0008 }, 37 {0x27, 0x0008},
86 { 0x2a, 0x0001 }, 38 {0x2a, 0x0001},
87 { 0x34, 0x0a40 }, 39 {0x34, 0x0a40},
88 }; 40 };
89 41
90 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 42 dev_dbg(&client->dev, "\n");
91 43
92 if (fe->callback) { 44 if (fe->callback) {
93 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 45 ret = fe->callback(client->adapter,
94 TUA9001_CMD_RESETN, 0); 46 DVB_FRONTEND_COMPONENT_TUNER,
95 if (ret < 0) 47 TUA9001_CMD_RESETN, 0);
48 if (ret)
96 goto err; 49 goto err;
97 } 50 }
98 51
99 if (fe->ops.i2c_gate_ctrl)
100 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */
101
102 for (i = 0; i < ARRAY_SIZE(data); i++) { 52 for (i = 0; i < ARRAY_SIZE(data); i++) {
103 ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); 53 ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
104 if (ret < 0) 54 if (ret)
105 goto err_i2c_gate_ctrl; 55 goto err;
106 } 56 }
107 57 return 0;
108err_i2c_gate_ctrl:
109 if (fe->ops.i2c_gate_ctrl)
110 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */
111err: 58err:
112 if (ret < 0) 59 dev_dbg(&client->dev, "failed=%d\n", ret);
113 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
114
115 return ret; 60 return ret;
116} 61}
117 62
118static int tua9001_sleep(struct dvb_frontend *fe) 63static int tua9001_sleep(struct dvb_frontend *fe)
119{ 64{
120 struct tua9001_priv *priv = fe->tuner_priv; 65 struct tua9001_dev *dev = fe->tuner_priv;
121 int ret = 0; 66 struct i2c_client *client = dev->client;
122 67 int ret;
123 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
124
125 if (fe->callback)
126 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
127 TUA9001_CMD_RESETN, 1);
128 68
129 if (ret < 0) 69 dev_dbg(&client->dev, "\n");
130 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
131 70
71 if (fe->callback) {
72 ret = fe->callback(client->adapter,
73 DVB_FRONTEND_COMPONENT_TUNER,
74 TUA9001_CMD_RESETN, 1);
75 if (ret)
76 goto err;
77 }
78 return 0;
79err:
80 dev_dbg(&client->dev, "failed=%d\n", ret);
132 return ret; 81 return ret;
133} 82}
134 83
135static int tua9001_set_params(struct dvb_frontend *fe) 84static int tua9001_set_params(struct dvb_frontend *fe)
136{ 85{
137 struct tua9001_priv *priv = fe->tuner_priv; 86 struct tua9001_dev *dev = fe->tuner_priv;
87 struct i2c_client *client = dev->client;
138 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 88 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
139 int ret = 0, i; 89 int ret, i;
140 u16 val; 90 u16 val;
141 u32 frequency; 91 struct tua9001_reg_val data[2];
142 struct reg_val data[2];
143 92
144 dev_dbg(&priv->i2c->dev, "%s: delivery_system=%d frequency=%d " \ 93 dev_dbg(&client->dev,
145 "bandwidth_hz=%d\n", __func__, 94 "delivery_system=%u frequency=%u bandwidth_hz=%u\n",
146 c->delivery_system, c->frequency, c->bandwidth_hz); 95 c->delivery_system, c->frequency, c->bandwidth_hz);
147 96
148 switch (c->delivery_system) { 97 switch (c->delivery_system) {
149 case SYS_DVBT: 98 case SYS_DVBT:
@@ -172,70 +121,54 @@ static int tua9001_set_params(struct dvb_frontend *fe)
172 121
173 data[0].reg = 0x04; 122 data[0].reg = 0x04;
174 data[0].val = val; 123 data[0].val = val;
175
176 frequency = (c->frequency - 150000000);
177 frequency /= 100;
178 frequency *= 48;
179 frequency /= 10000;
180
181 data[1].reg = 0x1f; 124 data[1].reg = 0x1f;
182 data[1].val = frequency; 125 data[1].val = div_u64((u64) (c->frequency - 150000000) * 48, 1000000);
183
184 if (fe->ops.i2c_gate_ctrl)
185 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */
186 126
187 if (fe->callback) { 127 if (fe->callback) {
188 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 128 ret = fe->callback(client->adapter,
189 TUA9001_CMD_RXEN, 0); 129 DVB_FRONTEND_COMPONENT_TUNER,
190 if (ret < 0) 130 TUA9001_CMD_RXEN, 0);
191 goto err_i2c_gate_ctrl; 131 if (ret)
132 goto err;
192 } 133 }
193 134
194 for (i = 0; i < ARRAY_SIZE(data); i++) { 135 for (i = 0; i < ARRAY_SIZE(data); i++) {
195 ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); 136 ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
196 if (ret < 0) 137 if (ret)
197 goto err_i2c_gate_ctrl; 138 goto err;
198 } 139 }
199 140
200 if (fe->callback) { 141 if (fe->callback) {
201 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 142 ret = fe->callback(client->adapter,
202 TUA9001_CMD_RXEN, 1); 143 DVB_FRONTEND_COMPONENT_TUNER,
203 if (ret < 0) 144 TUA9001_CMD_RXEN, 1);
204 goto err_i2c_gate_ctrl; 145 if (ret)
146 goto err;
205 } 147 }
206 148 return 0;
207err_i2c_gate_ctrl:
208 if (fe->ops.i2c_gate_ctrl)
209 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */
210err: 149err:
211 if (ret < 0) 150 dev_dbg(&client->dev, "failed=%d\n", ret);
212 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
213
214 return ret; 151 return ret;
215} 152}
216 153
217static int tua9001_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) 154static int tua9001_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
218{ 155{
219 struct tua9001_priv *priv = fe->tuner_priv; 156 struct tua9001_dev *dev = fe->tuner_priv;
157 struct i2c_client *client = dev->client;
220 158
221 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 159 dev_dbg(&client->dev, "\n");
222 160
223 *frequency = 0; /* Zero-IF */ 161 *frequency = 0; /* Zero-IF */
224
225 return 0; 162 return 0;
226} 163}
227 164
228static const struct dvb_tuner_ops tua9001_tuner_ops = { 165static const struct dvb_tuner_ops tua9001_tuner_ops = {
229 .info = { 166 .info = {
230 .name = "Infineon TUA 9001", 167 .name = "Infineon TUA9001",
231
232 .frequency_min = 170000000, 168 .frequency_min = 170000000,
233 .frequency_max = 862000000, 169 .frequency_max = 862000000,
234 .frequency_step = 0,
235 }, 170 },
236 171
237 .release = tua9001_release,
238
239 .init = tua9001_init, 172 .init = tua9001_init,
240 .sleep = tua9001_sleep, 173 .sleep = tua9001_sleep,
241 .set_params = tua9001_set_params, 174 .set_params = tua9001_set_params,
@@ -243,52 +176,108 @@ static const struct dvb_tuner_ops tua9001_tuner_ops = {
243 .get_if_frequency = tua9001_get_if_frequency, 176 .get_if_frequency = tua9001_get_if_frequency,
244}; 177};
245 178
246struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, 179static int tua9001_probe(struct i2c_client *client,
247 struct i2c_adapter *i2c, struct tua9001_config *cfg) 180 const struct i2c_device_id *id)
248{ 181{
249 struct tua9001_priv *priv = NULL; 182 struct tua9001_dev *dev;
183 struct tua9001_platform_data *pdata = client->dev.platform_data;
184 struct dvb_frontend *fe = pdata->dvb_frontend;
250 int ret; 185 int ret;
186 static const struct regmap_config regmap_config = {
187 .reg_bits = 8,
188 .val_bits = 16,
189 };
251 190
252 priv = kzalloc(sizeof(struct tua9001_priv), GFP_KERNEL); 191 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
253 if (priv == NULL) 192 if (!dev) {
254 return NULL; 193 ret = -ENOMEM;
194 goto err;
195 }
255 196
256 priv->cfg = cfg; 197 dev->fe = pdata->dvb_frontend;
257 priv->i2c = i2c; 198 dev->client = client;
199 dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
200 if (IS_ERR(dev->regmap)) {
201 ret = PTR_ERR(dev->regmap);
202 goto err_kfree;
203 }
258 204
259 if (fe->callback) { 205 if (fe->callback) {
260 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 206 ret = fe->callback(client->adapter,
261 TUA9001_CMD_CEN, 1); 207 DVB_FRONTEND_COMPONENT_TUNER,
262 if (ret < 0) 208 TUA9001_CMD_CEN, 1);
263 goto err; 209 if (ret)
264 210 goto err_kfree;
265 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 211
266 TUA9001_CMD_RXEN, 0); 212 ret = fe->callback(client->adapter,
267 if (ret < 0) 213 DVB_FRONTEND_COMPONENT_TUNER,
268 goto err; 214 TUA9001_CMD_RXEN, 0);
269 215 if (ret)
270 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 216 goto err_kfree;
271 TUA9001_CMD_RESETN, 1); 217
272 if (ret < 0) 218 ret = fe->callback(client->adapter,
273 goto err; 219 DVB_FRONTEND_COMPONENT_TUNER,
220 TUA9001_CMD_RESETN, 1);
221 if (ret)
222 goto err_kfree;
274 } 223 }
275 224
276 dev_info(&priv->i2c->dev, 225 fe->tuner_priv = dev;
277 "%s: Infineon TUA 9001 successfully attached\n",
278 KBUILD_MODNAME);
279
280 memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops, 226 memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops,
281 sizeof(struct dvb_tuner_ops)); 227 sizeof(struct dvb_tuner_ops));
228 i2c_set_clientdata(client, dev);
282 229
283 fe->tuner_priv = priv; 230 dev_info(&client->dev, "Infineon TUA9001 successfully attached\n");
284 return fe; 231 return 0;
232err_kfree:
233 kfree(dev);
285err: 234err:
286 dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 235 dev_dbg(&client->dev, "failed=%d\n", ret);
287 kfree(priv); 236 return ret;
288 return NULL; 237}
238
239static int tua9001_remove(struct i2c_client *client)
240{
241 struct tua9001_dev *dev = i2c_get_clientdata(client);
242 struct dvb_frontend *fe = dev->fe;
243 int ret;
244
245 dev_dbg(&client->dev, "\n");
246
247 if (fe->callback) {
248 ret = fe->callback(client->adapter,
249 DVB_FRONTEND_COMPONENT_TUNER,
250 TUA9001_CMD_CEN, 0);
251 if (ret)
252 goto err_kfree;
253 }
254 kfree(dev);
255 return 0;
256err_kfree:
257 kfree(dev);
258 dev_dbg(&client->dev, "failed=%d\n", ret);
259 return ret;
289} 260}
290EXPORT_SYMBOL(tua9001_attach);
291 261
292MODULE_DESCRIPTION("Infineon TUA 9001 silicon tuner driver"); 262static const struct i2c_device_id tua9001_id_table[] = {
263 {"tua9001", 0},
264 {}
265};
266MODULE_DEVICE_TABLE(i2c, tua9001_id_table);
267
268static struct i2c_driver tua9001_driver = {
269 .driver = {
270 .owner = THIS_MODULE,
271 .name = "tua9001",
272 .suppress_bind_attrs = true,
273 },
274 .probe = tua9001_probe,
275 .remove = tua9001_remove,
276 .id_table = tua9001_id_table,
277};
278
279module_i2c_driver(tua9001_driver);
280
281MODULE_DESCRIPTION("Infineon TUA9001 silicon tuner driver");
293MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 282MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
294MODULE_LICENSE("GPL"); 283MODULE_LICENSE("GPL");
diff --git a/drivers/media/tuners/tua9001.h b/drivers/media/tuners/tua9001.h
index 2c3375c7aeb9..7b0548181cdc 100644
--- a/drivers/media/tuners/tua9001.h
+++ b/drivers/media/tuners/tua9001.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Infineon TUA 9001 silicon tuner driver 2 * Infineon TUA9001 silicon tuner driver
3 * 3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -12,23 +12,24 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
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 */ 15 */
20 16
21#ifndef TUA9001_H 17#ifndef TUA9001_H
22#define TUA9001_H 18#define TUA9001_H
23 19
24#include <linux/kconfig.h>
25#include "dvb_frontend.h" 20#include "dvb_frontend.h"
26 21
27struct tua9001_config { 22/*
28 /* 23 * I2C address
29 * I2C address 24 * 0x60,
30 */ 25 */
31 u8 i2c_addr; 26
27/**
28 * struct tua9001_platform_data - Platform data for the tua9001 driver
29 * @dvb_frontend: DVB frontend.
30 */
31struct tua9001_platform_data {
32 struct dvb_frontend *dvb_frontend;
32}; 33};
33 34
34/* 35/*
@@ -51,16 +52,4 @@ struct tua9001_config {
51#define TUA9001_CMD_RESETN 1 52#define TUA9001_CMD_RESETN 1
52#define TUA9001_CMD_RXEN 2 53#define TUA9001_CMD_RXEN 2
53 54
54#if IS_REACHABLE(CONFIG_MEDIA_TUNER_TUA9001)
55extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
56 struct i2c_adapter *i2c, struct tua9001_config *cfg);
57#else
58static inline struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
59 struct i2c_adapter *i2c, struct tua9001_config *cfg)
60{
61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
62 return NULL;
63}
64#endif
65
66#endif 55#endif
diff --git a/drivers/media/tuners/tua9001_priv.h b/drivers/media/tuners/tua9001_priv.h
index 73cc1ce0575c..bc406c5ec69d 100644
--- a/drivers/media/tuners/tua9001_priv.h
+++ b/drivers/media/tuners/tua9001_priv.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Infineon TUA 9001 silicon tuner driver 2 * Infineon TUA9001 silicon tuner driver
3 * 3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -12,23 +12,24 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
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 */ 15 */
20 16
21#ifndef TUA9001_PRIV_H 17#ifndef TUA9001_PRIV_H
22#define TUA9001_PRIV_H 18#define TUA9001_PRIV_H
23 19
24struct reg_val { 20#include "tua9001.h"
21#include <linux/math64.h>
22#include <linux/regmap.h>
23
24struct tua9001_reg_val {
25 u8 reg; 25 u8 reg;
26 u16 val; 26 u16 val;
27}; 27};
28 28
29struct tua9001_priv { 29struct tua9001_dev {
30 struct tua9001_config *cfg; 30 struct dvb_frontend *fe;
31 struct i2c_adapter *i2c; 31 struct i2c_client *client;
32 struct regmap *regmap;
32}; 33};
33 34
34#endif 35#endif
diff --git a/drivers/media/tuners/tuner-i2c.h b/drivers/media/tuners/tuner-i2c.h
index 18f005634c67..bda67a5a76f2 100644
--- a/drivers/media/tuners/tuner-i2c.h
+++ b/drivers/media/tuners/tuner-i2c.h
@@ -33,7 +33,8 @@ struct tuner_i2c_props {
33 char *name; 33 char *name;
34}; 34};
35 35
36static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len) 36static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props,
37 unsigned char *buf, int len)
37{ 38{
38 struct i2c_msg msg = { .addr = props->addr, .flags = 0, 39 struct i2c_msg msg = { .addr = props->addr, .flags = 0,
39 .buf = buf, .len = len }; 40 .buf = buf, .len = len };
@@ -42,7 +43,8 @@ static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf,
42 return (ret == 1) ? len : ret; 43 return (ret == 1) ? len : ret;
43} 44}
44 45
45static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len) 46static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props,
47 unsigned char *buf, int len)
46{ 48{
47 struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD, 49 struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
48 .buf = buf, .len = len }; 50 .buf = buf, .len = len };
@@ -52,8 +54,8 @@ static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf,
52} 54}
53 55
54static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props, 56static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
55 char *obuf, int olen, 57 unsigned char *obuf, int olen,
56 char *ibuf, int ilen) 58 unsigned char *ibuf, int ilen)
57{ 59{
58 struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0, 60 struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
59 .buf = obuf, .len = olen }, 61 .buf = obuf, .len = olen },
diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index d12f5e4ad8bf..4e941f00b600 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -1094,7 +1094,7 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
1094 * Still need tests for XC3028L (firmware 3.2 or upper) 1094 * Still need tests for XC3028L (firmware 3.2 or upper)
1095 * So, for now, let's just comment the per-firmware 1095 * So, for now, let's just comment the per-firmware
1096 * version of this change. Reports with xc3028l working 1096 * version of this change. Reports with xc3028l working
1097 * with and without the lines bellow are welcome 1097 * with and without the lines below are welcome
1098 */ 1098 */
1099 1099
1100 if (priv->firm_version < 0x0302) { 1100 if (priv->firm_version < 0x0302) {
diff --git a/drivers/media/usb/as102/as102_drv.c b/drivers/media/usb/as102/as102_drv.c
index 8be1474b2c36..9dd7c7cb06b1 100644
--- a/drivers/media/usb/as102/as102_drv.c
+++ b/drivers/media/usb/as102/as102_drv.c
@@ -337,6 +337,7 @@ int as102_dvb_register(struct as102_dev_t *as102_dev)
337 &as102_dev->bus_adap, 337 &as102_dev->bus_adap,
338 as102_dev->elna_cfg); 338 as102_dev->elna_cfg);
339 if (!as102_dev->dvb_fe) { 339 if (!as102_dev->dvb_fe) {
340 ret = -ENODEV;
340 dev_err(dev, "%s: as102_attach() failed: %d", 341 dev_err(dev, "%s: as102_attach() failed: %d",
341 __func__, ret); 342 __func__, ret);
342 goto efereg; 343 goto efereg;
diff --git a/drivers/media/usb/au0828/au0828-cards.c b/drivers/media/usb/au0828/au0828-cards.c
index edc27355f271..6b469e8c4c6e 100644
--- a/drivers/media/usb/au0828/au0828-cards.c
+++ b/drivers/media/usb/au0828/au0828-cards.c
@@ -195,8 +195,6 @@ void au0828_card_setup(struct au0828_dev *dev)
195 195
196 dprintk(1, "%s()\n", __func__); 196 dprintk(1, "%s()\n", __func__);
197 197
198 dev->board = au0828_boards[dev->boardnr];
199
200 if (dev->i2c_rc == 0) { 198 if (dev->i2c_rc == 0) {
201 dev->i2c_client.addr = 0xa0 >> 1; 199 dev->i2c_client.addr = 0xa0 >> 1;
202 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom)); 200 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 082ae6ba492f..0934024fb89d 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -222,6 +222,8 @@ static int au0828_usb_probe(struct usb_interface *interface,
222 mutex_init(&dev->dvb.lock); 222 mutex_init(&dev->dvb.lock);
223 dev->usbdev = usbdev; 223 dev->usbdev = usbdev;
224 dev->boardnr = id->driver_info; 224 dev->boardnr = id->driver_info;
225 dev->board = au0828_boards[dev->boardnr];
226
225 227
226#ifdef CONFIG_VIDEO_AU0828_V4L2 228#ifdef CONFIG_VIDEO_AU0828_V4L2
227 dev->v4l2_dev.release = au0828_usb_v4l2_release; 229 dev->v4l2_dev.release = au0828_usb_v4l2_release;
diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index 983ea8339154..47a98a2014a5 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -1160,9 +1160,9 @@ static int cx231xx_initialize_codec(struct cx231xx *dev)
1160 } 1160 }
1161 1161
1162 cx231xx_enable656(dev); 1162 cx231xx_enable656(dev);
1163 /* stop mpeg capture */ 1163
1164 cx231xx_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 1164 /* stop mpeg capture */
1165 3, 0, 1, 3, 4); 1165 cx231xx_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, 1, 3, 4);
1166 1166
1167 cx231xx_codec_settings(dev); 1167 cx231xx_codec_settings(dev);
1168 msleep(60); 1168 msleep(60);
@@ -1249,8 +1249,7 @@ static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
1249 struct cx231xx *dev = fh->dev; 1249 struct cx231xx *dev = fh->dev;
1250 unsigned long flags = 0; 1250 unsigned long flags = 0;
1251 1251
1252 if (in_interrupt()) 1252 BUG_ON(in_interrupt());
1253 BUG();
1254 1253
1255 spin_lock_irqsave(&dev->video_mode.slock, flags); 1254 spin_lock_irqsave(&dev->video_mode.slock, flags);
1256 if (dev->USE_ISO) { 1255 if (dev->USE_ISO) {
@@ -1878,13 +1877,15 @@ static int cx231xx_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
1878{ 1877{
1879 struct cx231xx *dev = container_of(cxhdl, struct cx231xx, mpeg_ctrl_handler); 1878 struct cx231xx *dev = container_of(cxhdl, struct cx231xx, mpeg_ctrl_handler);
1880 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 1879 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
1881 struct v4l2_mbus_framefmt fmt; 1880 struct v4l2_subdev_format format = {
1881 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1882 };
1882 1883
1883 /* fix videodecoder resolution */ 1884 /* fix videodecoder resolution */
1884 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1); 1885 format.format.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
1885 fmt.height = cxhdl->height; 1886 format.format.height = cxhdl->height;
1886 fmt.code = MEDIA_BUS_FMT_FIXED; 1887 format.format.code = MEDIA_BUS_FMT_FIXED;
1887 v4l2_subdev_call(dev->sd_cx25840, video, s_mbus_fmt, &fmt); 1888 v4l2_subdev_call(dev->sd_cx25840, pad, set_fmt, NULL, &format);
1888 return 0; 1889 return 0;
1889} 1890}
1890 1891
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 39e887925e3d..491913778bcc 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -1595,31 +1595,31 @@ void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
1595 /*pll_freq_word = 0x3463497;*/ 1595 /*pll_freq_word = 0x3463497;*/
1596 vid_blk_write_word(dev, DIF_PLL_FREQ_WORD, pll_freq_word); 1596 vid_blk_write_word(dev, DIF_PLL_FREQ_WORD, pll_freq_word);
1597 1597
1598 if (spectral_invert) { 1598 if (spectral_invert) {
1599 if_freq -= 400000; 1599 if_freq -= 400000;
1600 /* Enable Spectral Invert*/ 1600 /* Enable Spectral Invert*/
1601 vid_blk_read_word(dev, DIF_MISC_CTRL, 1601 vid_blk_read_word(dev, DIF_MISC_CTRL,
1602 &dif_misc_ctrl_value); 1602 &dif_misc_ctrl_value);
1603 dif_misc_ctrl_value = dif_misc_ctrl_value | 0x00200000; 1603 dif_misc_ctrl_value = dif_misc_ctrl_value | 0x00200000;
1604 vid_blk_write_word(dev, DIF_MISC_CTRL, 1604 vid_blk_write_word(dev, DIF_MISC_CTRL,
1605 dif_misc_ctrl_value); 1605 dif_misc_ctrl_value);
1606 } else { 1606 } else {
1607 if_freq += 400000; 1607 if_freq += 400000;
1608 /* Disable Spectral Invert*/ 1608 /* Disable Spectral Invert*/
1609 vid_blk_read_word(dev, DIF_MISC_CTRL, 1609 vid_blk_read_word(dev, DIF_MISC_CTRL,
1610 &dif_misc_ctrl_value); 1610 &dif_misc_ctrl_value);
1611 dif_misc_ctrl_value = dif_misc_ctrl_value & 0xFFDFFFFF; 1611 dif_misc_ctrl_value = dif_misc_ctrl_value & 0xFFDFFFFF;
1612 vid_blk_write_word(dev, DIF_MISC_CTRL, 1612 vid_blk_write_word(dev, DIF_MISC_CTRL,
1613 dif_misc_ctrl_value); 1613 dif_misc_ctrl_value);
1614 } 1614 }
1615 1615
1616 if_freq = (if_freq/100000)*100000; 1616 if_freq = (if_freq / 100000) * 100000;
1617 1617
1618 if (if_freq < 3000000) 1618 if (if_freq < 3000000)
1619 if_freq = 3000000; 1619 if_freq = 3000000;
1620 1620
1621 if (if_freq > 16000000) 1621 if (if_freq > 16000000)
1622 if_freq = 16000000; 1622 if_freq = 16000000;
1623 } 1623 }
1624 1624
1625 dev_dbg(dev->dev, "Enter IF=%zu\n", ARRAY_SIZE(Dif_set_array)); 1625 dev_dbg(dev->dev, "Enter IF=%zu\n", ARRAY_SIZE(Dif_set_array));
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index fe00da105e77..4a117a58c39a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -815,6 +815,32 @@ struct cx231xx_board cx231xx_boards[] = {
815 .gpio = NULL, 815 .gpio = NULL,
816 } }, 816 } },
817 }, 817 },
818 [CX231XX_BOARD_TERRATEC_GRABBY] = {
819 .name = "Terratec Grabby",
820 .tuner_type = TUNER_ABSENT,
821 .decoder = CX231XX_AVDECODER,
822 .output_mode = OUT_MODE_VIP11,
823 .demod_xfer_mode = 0,
824 .ctl_pin_status_mask = 0xFFFFFFC4,
825 .agc_analog_digital_select_gpio = 0x0c,
826 .gpio_pin_status_mask = 0x4001000,
827 .norm = V4L2_STD_PAL,
828 .no_alt_vanc = 1,
829 .external_av = 1,
830 .input = {{
831 .type = CX231XX_VMUX_COMPOSITE1,
832 .vmux = CX231XX_VIN_2_1,
833 .amux = CX231XX_AMUX_LINE_IN,
834 .gpio = NULL,
835 }, {
836 .type = CX231XX_VMUX_SVIDEO,
837 .vmux = CX231XX_VIN_1_1 |
838 (CX231XX_VIN_1_2 << 8) |
839 CX25840_SVIDEO_ON,
840 .amux = CX231XX_AMUX_LINE_IN,
841 .gpio = NULL,
842 } },
843 },
818}; 844};
819const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); 845const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
820 846
@@ -880,6 +906,8 @@ struct usb_device_id cx231xx_id_table[] = {
880 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2}, 906 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
881 {USB_DEVICE(0x1f4d, 0x0102), 907 {USB_DEVICE(0x1f4d, 0x0102),
882 .driver_info = CX231XX_BOARD_OTG102}, 908 .driver_info = CX231XX_BOARD_OTG102},
909 {USB_DEVICE(USB_VID_TERRATEC, 0x00a6),
910 .driver_info = CX231XX_BOARD_TERRATEC_GRABBY},
883 {}, 911 {},
884}; 912};
885 913
@@ -1092,17 +1120,25 @@ void cx231xx_card_setup(struct cx231xx *dev)
1092 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx: 1120 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
1093 case CX231XX_BOARD_HAUPPAUGE_955Q: 1121 case CX231XX_BOARD_HAUPPAUGE_955Q:
1094 { 1122 {
1095 struct tveeprom tvee; 1123 struct eeprom {
1096 static u8 eeprom[256]; 1124 struct tveeprom tvee;
1097 struct i2c_client client; 1125 u8 eeprom[256];
1098 1126 struct i2c_client client;
1099 memset(&client, 0, sizeof(client)); 1127 };
1100 client.adapter = cx231xx_get_i2c_adap(dev, I2C_1_MUX_1); 1128 struct eeprom *e = kzalloc(sizeof(*e), GFP_KERNEL);
1101 client.addr = 0xa0 >> 1; 1129
1130 if (e == NULL) {
1131 dev_err(dev->dev,
1132 "failed to allocate memory to read eeprom\n");
1133 break;
1134 }
1135 e->client.adapter = cx231xx_get_i2c_adap(dev, I2C_1_MUX_1);
1136 e->client.addr = 0xa0 >> 1;
1102 1137
1103 read_eeprom(dev, &client, eeprom, sizeof(eeprom)); 1138 read_eeprom(dev, &e->client, e->eeprom, sizeof(e->eeprom));
1104 tveeprom_hauppauge_analog(&client, 1139 tveeprom_hauppauge_analog(&e->client,
1105 &tvee, eeprom + 0xc0); 1140 &e->tvee, e->eeprom + 0xc0);
1141 kfree(e);
1106 break; 1142 break;
1107 } 1143 }
1108 } 1144 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index e42bde081cd7..a2fd49b6be83 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -653,22 +653,20 @@ int cx231xx_demod_reset(struct cx231xx *dev)
653 653
654 cx231xx_coredbg("Enter cx231xx_demod_reset()\n"); 654 cx231xx_coredbg("Enter cx231xx_demod_reset()\n");
655 655
656 value[1] = (u8) 0x3; 656 value[1] = (u8) 0x3;
657 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, 657 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
658 PWR_CTL_EN, value, 4); 658 PWR_CTL_EN, value, 4);
659 msleep(10); 659 msleep(10);
660 660
661 value[1] = (u8) 0x0; 661 value[1] = (u8) 0x0;
662 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, 662 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
663 PWR_CTL_EN, value, 4); 663 PWR_CTL_EN, value, 4);
664 msleep(10); 664 msleep(10);
665 665
666 value[1] = (u8) 0x3; 666 value[1] = (u8) 0x3;
667 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, 667 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
668 PWR_CTL_EN, value, 4); 668 PWR_CTL_EN, value, 4);
669 msleep(10); 669 msleep(10);
670
671
672 670
673 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, 671 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN,
674 value, 4); 672 value, 4);
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 610d5675bde6..66ee161fc7ba 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -797,6 +797,7 @@ static int dvb_init(struct cx231xx *dev)
797 /* attach tuner */ 797 /* attach tuner */
798 memset(&si2157_config, 0, sizeof(si2157_config)); 798 memset(&si2157_config, 0, sizeof(si2157_config));
799 si2157_config.fe = dev->dvb->frontend; 799 si2157_config.fe = dev->dvb->frontend;
800 si2157_config.if_port = 1;
800 si2157_config.inversion = true; 801 si2157_config.inversion = true;
801 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 802 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
802 info.addr = 0x60; 803 info.addr = 0x60;
@@ -852,6 +853,7 @@ static int dvb_init(struct cx231xx *dev)
852 /* attach tuner */ 853 /* attach tuner */
853 memset(&si2157_config, 0, sizeof(si2157_config)); 854 memset(&si2157_config, 0, sizeof(si2157_config));
854 si2157_config.fe = dev->dvb->frontend; 855 si2157_config.fe = dev->dvb->frontend;
856 si2157_config.if_port = 1;
855 si2157_config.inversion = true; 857 si2157_config.inversion = true;
856 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 858 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
857 info.addr = 0x60; 859 info.addr = 0x60;
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index 80261ac40208..a08014d20a5c 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -192,8 +192,7 @@ static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
192 struct cx231xx_fh *fh = vq->priv_data; 192 struct cx231xx_fh *fh = vq->priv_data;
193 struct cx231xx *dev = fh->dev; 193 struct cx231xx *dev = fh->dev;
194 unsigned long flags = 0; 194 unsigned long flags = 0;
195 if (in_interrupt()) 195 BUG_ON(in_interrupt());
196 BUG();
197 196
198 /* We used to wait for the buffer to finish here, but this didn't work 197 /* We used to wait for the buffer to finish here, but this didn't work
199 because, as we were keeping the state as VIDEOBUF_QUEUED, 198 because, as we were keeping the state as VIDEOBUF_QUEUED,
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index c261e160c158..c6ff8968286a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -749,8 +749,7 @@ static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
749 struct cx231xx *dev = fh->dev; 749 struct cx231xx *dev = fh->dev;
750 unsigned long flags = 0; 750 unsigned long flags = 0;
751 751
752 if (in_interrupt()) 752 BUG_ON(in_interrupt());
753 BUG();
754 753
755 /* We used to wait for the buffer to finish here, but this didn't work 754 /* We used to wait for the buffer to finish here, but this didn't work
756 because, as we were keeping the state as VIDEOBUF_QUEUED, 755 because, as we were keeping the state as VIDEOBUF_QUEUED,
@@ -1013,7 +1012,9 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1013 struct cx231xx *dev = fh->dev; 1012 struct cx231xx *dev = fh->dev;
1014 int rc; 1013 int rc;
1015 struct cx231xx_fmt *fmt; 1014 struct cx231xx_fmt *fmt;
1016 struct v4l2_mbus_framefmt mbus_fmt; 1015 struct v4l2_subdev_format format = {
1016 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1017 };
1017 1018
1018 rc = check_dev(dev); 1019 rc = check_dev(dev);
1019 if (rc < 0) 1020 if (rc < 0)
@@ -1041,9 +1042,9 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1041 dev->height = f->fmt.pix.height; 1042 dev->height = f->fmt.pix.height;
1042 dev->format = fmt; 1043 dev->format = fmt;
1043 1044
1044 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); 1045 v4l2_fill_mbus_format(&format.format, &f->fmt.pix, MEDIA_BUS_FMT_FIXED);
1045 call_all(dev, video, s_mbus_fmt, &mbus_fmt); 1046 call_all(dev, pad, set_fmt, NULL, &format);
1046 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); 1047 v4l2_fill_pix_format(&f->fmt.pix, &format.format);
1047 1048
1048 return rc; 1049 return rc;
1049} 1050}
@@ -1061,7 +1062,9 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1061{ 1062{
1062 struct cx231xx_fh *fh = priv; 1063 struct cx231xx_fh *fh = priv;
1063 struct cx231xx *dev = fh->dev; 1064 struct cx231xx *dev = fh->dev;
1064 struct v4l2_mbus_framefmt mbus_fmt; 1065 struct v4l2_subdev_format format = {
1066 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1067 };
1065 int rc; 1068 int rc;
1066 1069
1067 rc = check_dev(dev); 1070 rc = check_dev(dev);
@@ -1085,11 +1088,10 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1085 /* We need to reset basic properties in the decoder related to 1088 /* We need to reset basic properties in the decoder related to
1086 resolution (since a standard change effects things like the number 1089 resolution (since a standard change effects things like the number
1087 of lines in VACT, etc) */ 1090 of lines in VACT, etc) */
1088 memset(&mbus_fmt, 0, sizeof(mbus_fmt)); 1091 format.format.code = MEDIA_BUS_FMT_FIXED;
1089 mbus_fmt.code = MEDIA_BUS_FMT_FIXED; 1092 format.format.width = dev->width;
1090 mbus_fmt.width = dev->width; 1093 format.format.height = dev->height;
1091 mbus_fmt.height = dev->height; 1094 call_all(dev, pad, set_fmt, NULL, &format);
1092 call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1093 1095
1094 /* do mode control overrides */ 1096 /* do mode control overrides */
1095 cx231xx_do_mode_ctrl_overrides(dev); 1097 cx231xx_do_mode_ctrl_overrides(dev);
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 00d3bce9a690..54790fbe8fdc 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -77,6 +77,7 @@
77#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx 19 77#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx 19
78#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx 20 78#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx 20
79#define CX231XX_BOARD_HAUPPAUGE_955Q 21 79#define CX231XX_BOARD_HAUPPAUGE_955Q 21
80#define CX231XX_BOARD_TERRATEC_GRABBY 22
80 81
81/* Limits minimum and default number of buffers */ 82/* Limits minimum and default number of buffers */
82#define CX231XX_MIN_BUF 4 83#define CX231XX_MIN_BUF 4
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.c b/drivers/media/usb/dvb-usb-v2/af9015.c
index 16c0b7d4f8e7..95a7388e89d4 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.c
+++ b/drivers/media/usb/dvb-usb-v2/af9015.c
@@ -641,7 +641,7 @@ static int af9015_af9013_set_frontend(struct dvb_frontend *fe)
641 641
642/* override demod callbacks for resource locking */ 642/* override demod callbacks for resource locking */
643static int af9015_af9013_read_status(struct dvb_frontend *fe, 643static int af9015_af9013_read_status(struct dvb_frontend *fe,
644 fe_status_t *status) 644 enum fe_status *status)
645{ 645{
646 int ret; 646 int ret;
647 struct af9015_state *state = fe_to_priv(fe); 647 struct af9015_state *state = fe_to_priv(fe);
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.h b/drivers/media/usb/dvb-usb-v2/af9015.h
index 3a6f3ad1eadb..1db1bb0d57bc 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.h
+++ b/drivers/media/usb/dvb-usb-v2/af9015.h
@@ -133,7 +133,7 @@ struct af9015_state {
133 133
134 /* for demod callback override */ 134 /* for demod callback override */
135 int (*set_frontend[2]) (struct dvb_frontend *fe); 135 int (*set_frontend[2]) (struct dvb_frontend *fe);
136 int (*read_status[2]) (struct dvb_frontend *fe, fe_status_t *status); 136 int (*read_status[2]) (struct dvb_frontend *fe, enum fe_status *status);
137 int (*init[2]) (struct dvb_frontend *fe); 137 int (*init[2]) (struct dvb_frontend *fe);
138 int (*sleep[2]) (struct dvb_frontend *fe); 138 int (*sleep[2]) (struct dvb_frontend *fe);
139 int (*tuner_init[2]) (struct dvb_frontend *fe); 139 int (*tuner_init[2]) (struct dvb_frontend *fe);
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 80a29f5377ea..6e02a15d39ce 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1234,10 +1234,6 @@ static int af9035_frontend_detach(struct dvb_usb_adapter *adap)
1234 return 0; 1234 return 0;
1235} 1235}
1236 1236
1237static struct tua9001_config af9035_tua9001_config = {
1238 .i2c_addr = 0x60,
1239};
1240
1241static const struct fc0011_config af9035_fc0011_config = { 1237static const struct fc0011_config af9035_fc0011_config = {
1242 .i2c_address = 0x60, 1238 .i2c_address = 0x60,
1243}; 1239};
@@ -1265,11 +1261,6 @@ static struct tda18218_config af9035_tda18218_config = {
1265 .i2c_wr_max = 21, 1261 .i2c_wr_max = 21,
1266}; 1262};
1267 1263
1268static const struct fc2580_config af9035_fc2580_config = {
1269 .i2c_addr = 0x56,
1270 .clock = 16384000,
1271};
1272
1273static const struct fc0012_config af9035_fc0012_config[] = { 1264static const struct fc0012_config af9035_fc0012_config[] = {
1274 { 1265 {
1275 .i2c_address = 0x63, 1266 .i2c_address = 0x63,
@@ -1301,9 +1292,15 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
1301 */ 1292 */
1302 1293
1303 switch (state->af9033_config[adap->id].tuner) { 1294 switch (state->af9033_config[adap->id].tuner) {
1304 case AF9033_TUNER_TUA9001: 1295 case AF9033_TUNER_TUA9001: {
1305 /* AF9035 gpiot3 = TUA9001 RESETN 1296 struct tua9001_platform_data tua9001_pdata = {
1306 AF9035 gpiot2 = TUA9001 RXEN */ 1297 .dvb_frontend = adap->fe[0],
1298 };
1299
1300 /*
1301 * AF9035 gpiot3 = TUA9001 RESETN
1302 * AF9035 gpiot2 = TUA9001 RXEN
1303 */
1307 1304
1308 /* configure gpiot2 and gpiot2 as output */ 1305 /* configure gpiot2 and gpiot2 as output */
1309 ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01); 1306 ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01);
@@ -1323,9 +1320,14 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
1323 goto err; 1320 goto err;
1324 1321
1325 /* attach tuner */ 1322 /* attach tuner */
1326 fe = dvb_attach(tua9001_attach, adap->fe[0], 1323 ret = af9035_add_i2c_dev(d, "tua9001", 0x60, &tua9001_pdata,
1327 &d->i2c_adap, &af9035_tua9001_config); 1324 &d->i2c_adap);
1325 if (ret)
1326 goto err;
1327
1328 fe = adap->fe[0];
1328 break; 1329 break;
1330 }
1329 case AF9033_TUNER_FC0011: 1331 case AF9033_TUNER_FC0011:
1330 fe = dvb_attach(fc0011_attach, adap->fe[0], 1332 fe = dvb_attach(fc0011_attach, adap->fe[0],
1331 &d->i2c_adap, &af9035_fc0011_config); 1333 &d->i2c_adap, &af9035_fc0011_config);
@@ -1390,7 +1392,11 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
1390 fe = dvb_attach(tda18218_attach, adap->fe[0], 1392 fe = dvb_attach(tda18218_attach, adap->fe[0],
1391 &d->i2c_adap, &af9035_tda18218_config); 1393 &d->i2c_adap, &af9035_tda18218_config);
1392 break; 1394 break;
1393 case AF9033_TUNER_FC2580: 1395 case AF9033_TUNER_FC2580: {
1396 struct fc2580_platform_data fc2580_pdata = {
1397 .dvb_frontend = adap->fe[0],
1398 };
1399
1394 /* Tuner enable using gpiot2_o, gpiot2_en and gpiot2_on */ 1400 /* Tuner enable using gpiot2_o, gpiot2_en and gpiot2_on */
1395 ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01); 1401 ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01);
1396 if (ret < 0) 1402 if (ret < 0)
@@ -1406,9 +1412,14 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
1406 1412
1407 usleep_range(10000, 50000); 1413 usleep_range(10000, 50000);
1408 /* attach tuner */ 1414 /* attach tuner */
1409 fe = dvb_attach(fc2580_attach, adap->fe[0], 1415 ret = af9035_add_i2c_dev(d, "fc2580", 0x56, &fc2580_pdata,
1410 &d->i2c_adap, &af9035_fc2580_config); 1416 &d->i2c_adap);
1417 if (ret)
1418 goto err;
1419
1420 fe = adap->fe[0];
1411 break; 1421 break;
1422 }
1412 case AF9033_TUNER_FC0012: 1423 case AF9033_TUNER_FC0012:
1413 /* 1424 /*
1414 * AF9035 gpiot2 = FC0012 enable 1425 * AF9035 gpiot2 = FC0012 enable
@@ -1569,6 +1580,7 @@ static int it930x_tuner_attach(struct dvb_usb_adapter *adap)
1569 1580
1570 memset(&si2157_config, 0, sizeof(si2157_config)); 1581 memset(&si2157_config, 0, sizeof(si2157_config));
1571 si2157_config.fe = adap->fe[0]; 1582 si2157_config.fe = adap->fe[0];
1583 si2157_config.if_port = 1;
1572 ret = af9035_add_i2c_dev(d, "si2157", 0x63, 1584 ret = af9035_add_i2c_dev(d, "si2157", 0x63,
1573 &si2157_config, state->i2c_adapter_demod); 1585 &si2157_config, state->i2c_adapter_demod);
1574 1586
@@ -1611,6 +1623,8 @@ static int af9035_tuner_detach(struct dvb_usb_adapter *adap)
1611 dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id); 1623 dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
1612 1624
1613 switch (state->af9033_config[adap->id].tuner) { 1625 switch (state->af9033_config[adap->id].tuner) {
1626 case AF9033_TUNER_TUA9001:
1627 case AF9033_TUNER_FC2580:
1614 case AF9033_TUNER_IT9135_38: 1628 case AF9033_TUNER_IT9135_38:
1615 case AF9033_TUNER_IT9135_51: 1629 case AF9033_TUNER_IT9135_51:
1616 case AF9033_TUNER_IT9135_52: 1630 case AF9033_TUNER_IT9135_52:
@@ -2021,6 +2035,9 @@ static const struct usb_device_id af9035_id_table[] = {
2021 &af9035_props, "Asus U3100Mini Plus", NULL) }, 2035 &af9035_props, "Asus U3100Mini Plus", NULL) },
2022 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa, 2036 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa,
2023 &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) }, 2037 &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) },
2038 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, 0x0337,
2039 &af9035_props, "AVerMedia HD Volar (A867)", NULL) },
2040
2024 /* IT9135 devices */ 2041 /* IT9135 devices */
2025 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135, 2042 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135,
2026 &af9035_props, "ITE 9135 Generic", RC_MAP_IT913X_V1) }, 2043 &af9035_props, "ITE 9135 Generic", RC_MAP_IT913X_V1) },
@@ -2046,9 +2063,6 @@ static const struct usb_device_id af9035_id_table[] = {
2046 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CTVDIGDUAL_V2, 2063 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CTVDIGDUAL_V2,
2047 &af9035_props, "Digital Dual TV Receiver CTVDIGDUAL_V2", 2064 &af9035_props, "Digital Dual TV Receiver CTVDIGDUAL_V2",
2048 RC_MAP_IT913X_V1) }, 2065 RC_MAP_IT913X_V1) },
2049 /* IT930x devices */
2050 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303,
2051 &it930x_props, "ITE 9303 Generic", NULL) },
2052 /* XXX: that same ID [0ccd:0099] is used by af9015 driver too */ 2066 /* XXX: that same ID [0ccd:0099] is used by af9015 driver too */
2053 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099, 2067 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099,
2054 &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", 2068 &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)",
@@ -2061,6 +2075,10 @@ static const struct usb_device_id af9035_id_table[] = {
2061 &af9035_props, "PCTV AndroiDTV (78e)", RC_MAP_IT913X_V1) }, 2075 &af9035_props, "PCTV AndroiDTV (78e)", RC_MAP_IT913X_V1) },
2062 { DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_79E, 2076 { DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_79E,
2063 &af9035_props, "PCTV microStick (79e)", RC_MAP_IT913X_V2) }, 2077 &af9035_props, "PCTV microStick (79e)", RC_MAP_IT913X_V2) },
2078
2079 /* IT930x devices */
2080 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303,
2081 &it930x_props, "ITE 9303 Generic", NULL) },
2064 { } 2082 { }
2065}; 2083};
2066MODULE_DEVICE_TABLE(usb, af9035_id_table); 2084MODULE_DEVICE_TABLE(usb, af9035_id_table);
diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index cdf59bcd760c..0376c092bab8 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -45,9 +45,9 @@ struct dvbsky_state {
45 45
46 /* fe hook functions*/ 46 /* fe hook functions*/
47 int (*fe_set_voltage)(struct dvb_frontend *fe, 47 int (*fe_set_voltage)(struct dvb_frontend *fe,
48 fe_sec_voltage_t voltage); 48 enum fe_sec_voltage voltage);
49 int (*fe_read_status)(struct dvb_frontend *fe, 49 int (*fe_read_status)(struct dvb_frontend *fe,
50 fe_status_t *status); 50 enum fe_status *status);
51}; 51};
52 52
53static int dvbsky_usb_generic_rw(struct dvb_usb_device *d, 53static int dvbsky_usb_generic_rw(struct dvb_usb_device *d,
@@ -237,7 +237,7 @@ static int dvbsky_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
237#endif 237#endif
238 238
239static int dvbsky_usb_set_voltage(struct dvb_frontend *fe, 239static int dvbsky_usb_set_voltage(struct dvb_frontend *fe,
240 fe_sec_voltage_t voltage) 240 enum fe_sec_voltage voltage)
241{ 241{
242 struct dvb_usb_device *d = fe_to_d(fe); 242 struct dvb_usb_device *d = fe_to_d(fe);
243 struct dvbsky_state *state = d_to_priv(d); 243 struct dvbsky_state *state = d_to_priv(d);
@@ -277,7 +277,8 @@ static int dvbsky_read_mac_addr(struct dvb_usb_adapter *adap, u8 mac[6])
277 return 0; 277 return 0;
278} 278}
279 279
280static int dvbsky_usb_read_status(struct dvb_frontend *fe, fe_status_t *status) 280static int dvbsky_usb_read_status(struct dvb_frontend *fe,
281 enum fe_status *status)
281{ 282{
282 struct dvb_usb_device *d = fe_to_d(fe); 283 struct dvb_usb_device *d = fe_to_d(fe);
283 struct dvbsky_state *state = d_to_priv(d); 284 struct dvbsky_state *state = d_to_priv(d);
@@ -331,6 +332,7 @@ static int dvbsky_s960_attach(struct dvb_usb_adapter *adap)
331 332
332 /* attach tuner */ 333 /* attach tuner */
333 ts2020_config.fe = adap->fe[0]; 334 ts2020_config.fe = adap->fe[0];
335 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
334 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 336 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
335 info.addr = 0x60; 337 info.addr = 0x60;
336 info.platform_data = &ts2020_config; 338 info.platform_data = &ts2020_config;
@@ -368,7 +370,7 @@ fail_attach:
368} 370}
369 371
370static int dvbsky_usb_ci_set_voltage(struct dvb_frontend *fe, 372static int dvbsky_usb_ci_set_voltage(struct dvb_frontend *fe,
371 fe_sec_voltage_t voltage) 373 enum fe_sec_voltage voltage)
372{ 374{
373 struct dvb_usb_device *d = fe_to_d(fe); 375 struct dvb_usb_device *d = fe_to_d(fe);
374 struct dvbsky_state *state = d_to_priv(d); 376 struct dvbsky_state *state = d_to_priv(d);
@@ -453,6 +455,7 @@ static int dvbsky_s960c_attach(struct dvb_usb_adapter *adap)
453 455
454 /* attach tuner */ 456 /* attach tuner */
455 ts2020_config.fe = adap->fe[0]; 457 ts2020_config.fe = adap->fe[0];
458 ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
456 strlcpy(info.type, "ts2020", I2C_NAME_SIZE); 459 strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
457 info.addr = 0x60; 460 info.addr = 0x60;
458 info.platform_data = &ts2020_config; 461 info.platform_data = &ts2020_config;
@@ -549,6 +552,7 @@ static int dvbsky_t680c_attach(struct dvb_usb_adapter *adap)
549 /* attach tuner */ 552 /* attach tuner */
550 memset(&si2157_config, 0, sizeof(si2157_config)); 553 memset(&si2157_config, 0, sizeof(si2157_config));
551 si2157_config.fe = adap->fe[0]; 554 si2157_config.fe = adap->fe[0];
555 si2157_config.if_port = 1;
552 memset(&info, 0, sizeof(struct i2c_board_info)); 556 memset(&info, 0, sizeof(struct i2c_board_info));
553 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 557 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
554 info.addr = 0x60; 558 info.addr = 0x60;
@@ -615,7 +619,8 @@ static int dvbsky_t330_attach(struct dvb_usb_adapter *adap)
615 memset(&si2168_config, 0, sizeof(si2168_config)); 619 memset(&si2168_config, 0, sizeof(si2168_config));
616 si2168_config.i2c_adapter = &i2c_adapter; 620 si2168_config.i2c_adapter = &i2c_adapter;
617 si2168_config.fe = &adap->fe[0]; 621 si2168_config.fe = &adap->fe[0];
618 si2168_config.ts_mode = SI2168_TS_PARALLEL | 0x40; 622 si2168_config.ts_mode = SI2168_TS_PARALLEL;
623 si2168_config.ts_clock_gapped = true;
619 memset(&info, 0, sizeof(struct i2c_board_info)); 624 memset(&info, 0, sizeof(struct i2c_board_info));
620 strlcpy(info.type, "si2168", I2C_NAME_SIZE); 625 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
621 info.addr = 0x64; 626 info.addr = 0x64;
@@ -632,6 +637,7 @@ static int dvbsky_t330_attach(struct dvb_usb_adapter *adap)
632 /* attach tuner */ 637 /* attach tuner */
633 memset(&si2157_config, 0, sizeof(si2157_config)); 638 memset(&si2157_config, 0, sizeof(si2157_config));
634 si2157_config.fe = adap->fe[0]; 639 si2157_config.fe = adap->fe[0];
640 si2157_config.if_port = 1;
635 memset(&info, 0, sizeof(struct i2c_board_info)); 641 memset(&info, 0, sizeof(struct i2c_board_info));
636 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 642 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
637 info.addr = 0x60; 643 info.addr = 0x60;
diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c b/drivers/media/usb/dvb-usb-v2/lmedm04.c
index 5de6f7c04d09..4cc55b3a0558 100644
--- a/drivers/media/usb/dvb-usb-v2/lmedm04.c
+++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c
@@ -126,7 +126,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
126 126
127struct lme2510_state { 127struct lme2510_state {
128 unsigned long int_urb_due; 128 unsigned long int_urb_due;
129 fe_status_t lock_status; 129 enum fe_status lock_status;
130 u8 id; 130 u8 id;
131 u8 tuner_config; 131 u8 tuner_config;
132 u8 signal_level; 132 u8 signal_level;
@@ -144,12 +144,12 @@ struct lme2510_state {
144 struct urb *lme_urb; 144 struct urb *lme_urb;
145 void *usb_buffer; 145 void *usb_buffer;
146 /* Frontend original calls */ 146 /* Frontend original calls */
147 int (*fe_read_status)(struct dvb_frontend *, fe_status_t *); 147 int (*fe_read_status)(struct dvb_frontend *, enum fe_status *);
148 int (*fe_read_signal_strength)(struct dvb_frontend *, u16 *); 148 int (*fe_read_signal_strength)(struct dvb_frontend *, u16 *);
149 int (*fe_read_snr)(struct dvb_frontend *, u16 *); 149 int (*fe_read_snr)(struct dvb_frontend *, u16 *);
150 int (*fe_read_ber)(struct dvb_frontend *, u32 *); 150 int (*fe_read_ber)(struct dvb_frontend *, u32 *);
151 int (*fe_read_ucblocks)(struct dvb_frontend *, u32 *); 151 int (*fe_read_ucblocks)(struct dvb_frontend *, u32 *);
152 int (*fe_set_voltage)(struct dvb_frontend *, fe_sec_voltage_t); 152 int (*fe_set_voltage)(struct dvb_frontend *, enum fe_sec_voltage);
153 u8 dvb_usb_lme2510_firmware; 153 u8 dvb_usb_lme2510_firmware;
154}; 154};
155 155
@@ -257,6 +257,62 @@ static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out)
257 return ret; 257 return ret;
258} 258}
259 259
260/* Convert range from 0x00-0xff to 0x0000-0xffff */
261#define reg_to_16bits(x) ((x) | ((x) << 8))
262
263static void lme2510_update_stats(struct dvb_usb_adapter *adap)
264{
265 struct lme2510_state *st = adap_to_priv(adap);
266 struct dvb_frontend *fe = adap->fe[0];
267 struct dtv_frontend_properties *c;
268 u32 s_tmp = 0, c_tmp = 0;
269
270 if (!fe)
271 return;
272
273 c = &fe->dtv_property_cache;
274
275 c->block_count.len = 1;
276 c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
277 c->block_error.len = 1;
278 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
279 c->post_bit_count.len = 1;
280 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
281 c->post_bit_error.len = 1;
282 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
283
284 if (st->i2c_talk_onoff) {
285 c->strength.len = 1;
286 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
287 c->cnr.len = 1;
288 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
289 return;
290 }
291
292 switch (st->tuner_config) {
293 case TUNER_LG:
294 s_tmp = reg_to_16bits(0xff - st->signal_level);
295 c_tmp = reg_to_16bits(0xff - st->signal_sn);
296 break;
297 case TUNER_S7395:
298 case TUNER_S0194:
299 s_tmp = 0xffff - (((st->signal_level * 2) << 8) * 5 / 4);
300 c_tmp = reg_to_16bits((0xff - st->signal_sn - 0xa1) * 3);
301 break;
302 case TUNER_RS2000:
303 s_tmp = reg_to_16bits(st->signal_level);
304 c_tmp = reg_to_16bits(st->signal_sn);
305 }
306
307 c->strength.len = 1;
308 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
309 c->strength.stat[0].uvalue = (u64)s_tmp;
310
311 c->cnr.len = 1;
312 c->cnr.stat[0].scale = FE_SCALE_RELATIVE;
313 c->cnr.stat[0].uvalue = (u64)c_tmp;
314}
315
260static void lme2510_int_response(struct urb *lme_urb) 316static void lme2510_int_response(struct urb *lme_urb)
261{ 317{
262 struct dvb_usb_adapter *adap = lme_urb->context; 318 struct dvb_usb_adapter *adap = lme_urb->context;
@@ -337,6 +393,8 @@ static void lme2510_int_response(struct urb *lme_urb)
337 if (!signal_lock) 393 if (!signal_lock)
338 st->lock_status &= ~FE_HAS_LOCK; 394 st->lock_status &= ~FE_HAS_LOCK;
339 395
396 lme2510_update_stats(adap);
397
340 debug_data_snipet(5, "INT Remote data snipet in", ibuf); 398 debug_data_snipet(5, "INT Remote data snipet in", ibuf);
341 break; 399 break;
342 case 0xcc: 400 case 0xcc:
@@ -799,10 +857,11 @@ static struct m88rs2000_config m88rs2000_config = {
799static struct ts2020_config ts2020_config = { 857static struct ts2020_config ts2020_config = {
800 .tuner_address = 0x60, 858 .tuner_address = 0x60,
801 .clk_out_div = 7, 859 .clk_out_div = 7,
860 .dont_poll = true
802}; 861};
803 862
804static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, 863static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
805 fe_sec_voltage_t voltage) 864 enum fe_sec_voltage voltage)
806{ 865{
807 struct dvb_usb_device *d = fe_to_d(fe); 866 struct dvb_usb_device *d = fe_to_d(fe);
808 struct lme2510_state *st = fe_to_priv(fe); 867 struct lme2510_state *st = fe_to_priv(fe);
@@ -837,7 +896,7 @@ static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
837 return (ret < 0) ? -ENODEV : 0; 896 return (ret < 0) ? -ENODEV : 0;
838} 897}
839 898
840static int dm04_read_status(struct dvb_frontend *fe, fe_status_t *status) 899static int dm04_read_status(struct dvb_frontend *fe, enum fe_status *status)
841{ 900{
842 struct dvb_usb_device *d = fe_to_d(fe); 901 struct dvb_usb_device *d = fe_to_d(fe);
843 struct lme2510_state *st = d->priv; 902 struct lme2510_state *st = d->priv;
@@ -871,56 +930,45 @@ static int dm04_read_status(struct dvb_frontend *fe, fe_status_t *status)
871 930
872 *status = st->lock_status; 931 *status = st->lock_status;
873 932
874 if (!(*status & FE_HAS_LOCK)) 933 if (!(*status & FE_HAS_LOCK)) {
934 struct dvb_usb_adapter *adap = fe_to_adap(fe);
935
875 st->i2c_talk_onoff = 1; 936 st->i2c_talk_onoff = 1;
876 937
938 lme2510_update_stats(adap);
939 }
940
877 return ret; 941 return ret;
878} 942}
879 943
880static int dm04_read_signal_strength(struct dvb_frontend *fe, u16 *strength) 944static int dm04_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
881{ 945{
946 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
882 struct lme2510_state *st = fe_to_priv(fe); 947 struct lme2510_state *st = fe_to_priv(fe);
883 948
884 if (st->fe_read_signal_strength && !st->stream_on) 949 if (st->fe_read_signal_strength && !st->stream_on)
885 return st->fe_read_signal_strength(fe, strength); 950 return st->fe_read_signal_strength(fe, strength);
886 951
887 switch (st->tuner_config) { 952 if (c->strength.stat[0].scale == FE_SCALE_RELATIVE)
888 case TUNER_LG: 953 *strength = (u16)c->strength.stat[0].uvalue;
889 *strength = 0xff - st->signal_level; 954 else
890 *strength |= *strength << 8; 955 *strength = 0;
891 break;
892 /* fall through */
893 case TUNER_S7395:
894 case TUNER_S0194:
895 *strength = 0xffff - (((st->signal_level * 2) << 8) * 5 / 4);
896 break;
897 case TUNER_RS2000:
898 *strength = (u16)((u32)st->signal_level * 0xffff / 0xff);
899 }
900 956
901 return 0; 957 return 0;
902} 958}
903 959
904static int dm04_read_snr(struct dvb_frontend *fe, u16 *snr) 960static int dm04_read_snr(struct dvb_frontend *fe, u16 *snr)
905{ 961{
962 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
906 struct lme2510_state *st = fe_to_priv(fe); 963 struct lme2510_state *st = fe_to_priv(fe);
907 964
908 if (st->fe_read_snr && !st->stream_on) 965 if (st->fe_read_snr && !st->stream_on)
909 return st->fe_read_snr(fe, snr); 966 return st->fe_read_snr(fe, snr);
910 967
911 switch (st->tuner_config) { 968 if (c->cnr.stat[0].scale == FE_SCALE_RELATIVE)
912 case TUNER_LG: 969 *snr = (u16)c->cnr.stat[0].uvalue;
913 *snr = 0xff - st->signal_sn; 970 else
914 *snr |= *snr << 8; 971 *snr = 0;
915 break;
916 /* fall through */
917 case TUNER_S7395:
918 case TUNER_S0194:
919 *snr = (u16)((0xff - st->signal_sn - 0xa1) * 3) << 8;
920 break;
921 case TUNER_RS2000:
922 *snr = (u16)((u32)st->signal_sn * 0xffff / 0x7f);
923 }
924 972
925 return 0; 973 return 0;
926} 974}
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
index ecefa5c477fa..ea3753653368 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
@@ -72,7 +72,7 @@ int mxl111sf_demod_program_regs(struct mxl111sf_demod_state *state,
72 72
73static 73static
74int mxl1x1sf_demod_get_tps_code_rate(struct mxl111sf_demod_state *state, 74int mxl1x1sf_demod_get_tps_code_rate(struct mxl111sf_demod_state *state,
75 fe_code_rate_t *code_rate) 75 enum fe_code_rate *code_rate)
76{ 76{
77 u8 val; 77 u8 val;
78 int ret = mxl111sf_demod_read_reg(state, V6_CODE_RATE_TPS_REG, &val); 78 int ret = mxl111sf_demod_read_reg(state, V6_CODE_RATE_TPS_REG, &val);
@@ -103,7 +103,7 @@ fail:
103 103
104static 104static
105int mxl1x1sf_demod_get_tps_modulation(struct mxl111sf_demod_state *state, 105int mxl1x1sf_demod_get_tps_modulation(struct mxl111sf_demod_state *state,
106 fe_modulation_t *modulation) 106 enum fe_modulation *modulation)
107{ 107{
108 u8 val; 108 u8 val;
109 int ret = mxl111sf_demod_read_reg(state, V6_MODORDER_TPS_REG, &val); 109 int ret = mxl111sf_demod_read_reg(state, V6_MODORDER_TPS_REG, &val);
@@ -128,7 +128,7 @@ fail:
128 128
129static 129static
130int mxl1x1sf_demod_get_tps_guard_fft_mode(struct mxl111sf_demod_state *state, 130int mxl1x1sf_demod_get_tps_guard_fft_mode(struct mxl111sf_demod_state *state,
131 fe_transmit_mode_t *fft_mode) 131 enum fe_transmit_mode *fft_mode)
132{ 132{
133 u8 val; 133 u8 val;
134 int ret = mxl111sf_demod_read_reg(state, V6_MODE_TPS_REG, &val); 134 int ret = mxl111sf_demod_read_reg(state, V6_MODE_TPS_REG, &val);
@@ -153,7 +153,7 @@ fail:
153 153
154static 154static
155int mxl1x1sf_demod_get_tps_guard_interval(struct mxl111sf_demod_state *state, 155int mxl1x1sf_demod_get_tps_guard_interval(struct mxl111sf_demod_state *state,
156 fe_guard_interval_t *guard) 156 enum fe_guard_interval *guard)
157{ 157{
158 u8 val; 158 u8 val;
159 int ret = mxl111sf_demod_read_reg(state, V6_CP_TPS_REG, &val); 159 int ret = mxl111sf_demod_read_reg(state, V6_CP_TPS_REG, &val);
@@ -181,7 +181,7 @@ fail:
181 181
182static 182static
183int mxl1x1sf_demod_get_tps_hierarchy(struct mxl111sf_demod_state *state, 183int mxl1x1sf_demod_get_tps_hierarchy(struct mxl111sf_demod_state *state,
184 fe_hierarchy_t *hierarchy) 184 enum fe_hierarchy *hierarchy)
185{ 185{
186 u8 val; 186 u8 val;
187 int ret = mxl111sf_demod_read_reg(state, V6_TPS_HIERACHY_REG, &val); 187 int ret = mxl111sf_demod_read_reg(state, V6_TPS_HIERACHY_REG, &val);
@@ -441,7 +441,7 @@ fail:
441} 441}
442 442
443static int mxl111sf_demod_read_status(struct dvb_frontend *fe, 443static int mxl111sf_demod_read_status(struct dvb_frontend *fe,
444 fe_status_t *status) 444 enum fe_status *status)
445{ 445{
446 struct mxl111sf_demod_state *state = fe->demodulator_priv; 446 struct mxl111sf_demod_state *state = fe->demodulator_priv;
447 int ret, locked, cr_lock, sync_lock, fec_lock; 447 int ret, locked, cr_lock, sync_lock, fec_lock;
@@ -480,7 +480,7 @@ static int mxl111sf_demod_read_signal_strength(struct dvb_frontend *fe,
480 u16 *signal_strength) 480 u16 *signal_strength)
481{ 481{
482 struct mxl111sf_demod_state *state = fe->demodulator_priv; 482 struct mxl111sf_demod_state *state = fe->demodulator_priv;
483 fe_modulation_t modulation; 483 enum fe_modulation modulation;
484 u16 snr; 484 u16 snr;
485 485
486 mxl111sf_demod_calc_snr(state, &snr); 486 mxl111sf_demod_calc_snr(state, &snr);
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 895441fe90f7..c3cac4c12fb3 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -217,7 +217,7 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
217 req.data = &msg[0].buf[1]; 217 req.data = &msg[0].buf[1];
218 ret = rtl28xxu_ctrl_msg(d, &req); 218 ret = rtl28xxu_ctrl_msg(d, &req);
219 } 219 }
220 } else if (msg[0].len < 23) { 220 } else if ((msg[0].len < 23) && (!dev->new_i2c_write)) {
221 /* method 2 - old I2C */ 221 /* method 2 - old I2C */
222 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); 222 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
223 req.index = CMD_I2C_WR; 223 req.index = CMD_I2C_WR;
@@ -232,8 +232,14 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
232 req.data = msg[0].buf; 232 req.data = msg[0].buf;
233 ret = rtl28xxu_ctrl_msg(d, &req); 233 ret = rtl28xxu_ctrl_msg(d, &req);
234 } 234 }
235 } else if (num == 1 && (msg[0].flags & I2C_M_RD)) {
236 req.value = (msg[0].addr << 1);
237 req.index = CMD_I2C_DA_RD;
238 req.size = msg[0].len;
239 req.data = msg[0].buf;
240 ret = rtl28xxu_ctrl_msg(d, &req);
235 } else { 241 } else {
236 ret = -EINVAL; 242 ret = -EOPNOTSUPP;
237 } 243 }
238 244
239err_mutex_unlock: 245err_mutex_unlock:
@@ -357,6 +363,8 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
357 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf}; 363 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
358 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf}; 364 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
359 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf}; 365 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
366 struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf};
367 struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf};
360 368
361 dev_dbg(&d->intf->dev, "\n"); 369 dev_dbg(&d->intf->dev, "\n");
362 370
@@ -477,6 +485,35 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
477 goto tuner_found; 485 goto tuner_found;
478 } 486 }
479 487
488 /* GPIO0 and GPIO5 to reset Si2157/Si2168 tuner and demod */
489 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x21);
490 if (ret)
491 goto err;
492
493 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x00, 0x21);
494 if (ret)
495 goto err;
496
497 msleep(50);
498
499 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x21, 0x21);
500 if (ret)
501 goto err;
502
503 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x21, 0x21);
504 if (ret)
505 goto err;
506
507 msleep(50);
508
509 /* check Si2157 ID register; reg=c0 val=80 */
510 ret = rtl28xxu_ctrl_msg(d, &req_si2157);
511 if (ret == 0 && ((buf[0] & 0x80) == 0x80)) {
512 dev->tuner = TUNER_RTL2832_SI2157;
513 dev->tuner_name = "SI2157";
514 goto tuner_found;
515 }
516
480tuner_found: 517tuner_found:
481 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name); 518 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
482 519
@@ -510,6 +547,15 @@ tuner_found:
510 goto demod_found; 547 goto demod_found;
511 } 548 }
512 } 549 }
550 if (dev->tuner == TUNER_RTL2832_SI2157) {
551 /* check Si2168 ID register; reg=c8 val=80 */
552 ret = rtl28xxu_ctrl_msg(d, &req_si2168);
553 if (ret == 0 && ((buf[0] & 0x80) == 0x80)) {
554 dev_dbg(&d->intf->dev, "Si2168 found\n");
555 dev->slave_demod = SLAVE_DEMOD_SI2168;
556 goto demod_found;
557 }
558 }
513 559
514demod_found: 560demod_found:
515 /* close demod I2C gate */ 561 /* close demod I2C gate */
@@ -643,6 +689,11 @@ err:
643 return ret; 689 return ret;
644} 690}
645 691
692static const struct rtl2832_platform_data rtl2832_fc2580_platform_data = {
693 .clk = 28800000,
694 .tuner = TUNER_RTL2832_FC2580,
695};
696
646static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = { 697static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = {
647 .clk = 28800000, 698 .clk = 28800000,
648 .tuner = TUNER_RTL2832_FC0012 699 .tuner = TUNER_RTL2832_FC0012
@@ -668,6 +719,11 @@ static const struct rtl2832_platform_data rtl2832_r820t_platform_data = {
668 .tuner = TUNER_RTL2832_R820T, 719 .tuner = TUNER_RTL2832_R820T,
669}; 720};
670 721
722static const struct rtl2832_platform_data rtl2832_si2157_platform_data = {
723 .clk = 28800000,
724 .tuner = TUNER_RTL2832_SI2157,
725};
726
671static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d, 727static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
672 int cmd, int arg) 728 int cmd, int arg)
673{ 729{
@@ -804,8 +860,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
804 *pdata = rtl2832_fc0013_platform_data; 860 *pdata = rtl2832_fc0013_platform_data;
805 break; 861 break;
806 case TUNER_RTL2832_FC2580: 862 case TUNER_RTL2832_FC2580:
807 /* FIXME: do not abuse fc0012 settings */ 863 *pdata = rtl2832_fc2580_platform_data;
808 *pdata = rtl2832_fc0012_platform_data;
809 break; 864 break;
810 case TUNER_RTL2832_TUA9001: 865 case TUNER_RTL2832_TUA9001:
811 *pdata = rtl2832_tua9001_platform_data; 866 *pdata = rtl2832_tua9001_platform_data;
@@ -817,6 +872,9 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
817 case TUNER_RTL2832_R828D: 872 case TUNER_RTL2832_R828D:
818 *pdata = rtl2832_r820t_platform_data; 873 *pdata = rtl2832_r820t_platform_data;
819 break; 874 break;
875 case TUNER_RTL2832_SI2157:
876 *pdata = rtl2832_si2157_platform_data;
877 break;
820 default: 878 default:
821 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name); 879 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
822 ret = -ENODEV; 880 ret = -ENODEV;
@@ -884,7 +942,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
884 } 942 }
885 943
886 dev->i2c_client_slave_demod = client; 944 dev->i2c_client_slave_demod = client;
887 } else { 945 } else if (dev->slave_demod == SLAVE_DEMOD_MN88473) {
888 struct mn88473_config mn88473_config = {}; 946 struct mn88473_config mn88473_config = {};
889 947
890 mn88473_config.fe = &adap->fe[1]; 948 mn88473_config.fe = &adap->fe[1];
@@ -906,9 +964,37 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
906 } 964 }
907 965
908 dev->i2c_client_slave_demod = client; 966 dev->i2c_client_slave_demod = client;
967 } else {
968 struct si2168_config si2168_config = {};
969 struct i2c_adapter *adapter;
970
971 si2168_config.i2c_adapter = &adapter;
972 si2168_config.fe = &adap->fe[1];
973 si2168_config.ts_mode = SI2168_TS_SERIAL;
974 si2168_config.ts_clock_inv = false;
975 si2168_config.ts_clock_gapped = true;
976 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
977 info.addr = 0x64;
978 info.platform_data = &si2168_config;
979 request_module(info.type);
980 client = i2c_new_device(&d->i2c_adap, &info);
981 if (client == NULL || client->dev.driver == NULL) {
982 dev->slave_demod = SLAVE_DEMOD_NONE;
983 goto err_slave_demod_failed;
984 }
985
986 if (!try_module_get(client->dev.driver->owner)) {
987 i2c_unregister_device(client);
988 dev->slave_demod = SLAVE_DEMOD_NONE;
989 goto err_slave_demod_failed;
990 }
991
992 dev->i2c_client_slave_demod = client;
993
994 /* for Si2168 devices use only new I2C write method */
995 dev->new_i2c_write = true;
909 } 996 }
910 } 997 }
911
912 return 0; 998 return 0;
913err_slave_demod_failed: 999err_slave_demod_failed:
914err: 1000err:
@@ -1018,15 +1104,6 @@ err:
1018 return ret; 1104 return ret;
1019} 1105}
1020 1106
1021static const struct fc2580_config rtl2832u_fc2580_config = {
1022 .i2c_addr = 0x56,
1023 .clock = 16384000,
1024};
1025
1026static struct tua9001_config rtl2832u_tua9001_config = {
1027 .i2c_addr = 0x60,
1028};
1029
1030static const struct fc0012_config rtl2832u_fc0012_config = { 1107static const struct fc0012_config rtl2832u_fc0012_config = {
1031 .i2c_address = 0x63, /* 0xc6 >> 1 */ 1108 .i2c_address = 0x63, /* 0xc6 >> 1 */
1032 .xtal_freq = FC_XTAL_28_8_MHZ, 1109 .xtal_freq = FC_XTAL_28_8_MHZ,
@@ -1105,12 +1182,34 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1105 subdev = i2c_get_clientdata(client); 1182 subdev = i2c_get_clientdata(client);
1106 } 1183 }
1107 break; 1184 break;
1108 case TUNER_RTL2832_FC2580: 1185 case TUNER_RTL2832_FC2580: {
1109 fe = dvb_attach(fc2580_attach, adap->fe[0], 1186 struct fc2580_platform_data fc2580_pdata = {
1110 dev->demod_i2c_adapter, 1187 .dvb_frontend = adap->fe[0],
1111 &rtl2832u_fc2580_config); 1188 };
1189 struct i2c_board_info board_info = {};
1190
1191 strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE);
1192 board_info.addr = 0x56;
1193 board_info.platform_data = &fc2580_pdata;
1194 request_module("fc2580");
1195 client = i2c_new_device(dev->demod_i2c_adapter,
1196 &board_info);
1197 if (client == NULL || client->dev.driver == NULL)
1198 break;
1199 if (!try_module_get(client->dev.driver->owner)) {
1200 i2c_unregister_device(client);
1201 break;
1202 }
1203 dev->i2c_client_tuner = client;
1204 subdev = fc2580_pdata.get_v4l2_subdev(client);
1205 }
1112 break; 1206 break;
1113 case TUNER_RTL2832_TUA9001: 1207 case TUNER_RTL2832_TUA9001: {
1208 struct tua9001_platform_data tua9001_pdata = {
1209 .dvb_frontend = adap->fe[0],
1210 };
1211 struct i2c_board_info board_info = {};
1212
1114 /* enable GPIO1 and GPIO4 as output */ 1213 /* enable GPIO1 and GPIO4 as output */
1115 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); 1214 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
1116 if (ret) 1215 if (ret)
@@ -1120,10 +1219,20 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1120 if (ret) 1219 if (ret)
1121 goto err; 1220 goto err;
1122 1221
1123 fe = dvb_attach(tua9001_attach, adap->fe[0], 1222 strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE);
1124 dev->demod_i2c_adapter, 1223 board_info.addr = 0x60;
1125 &rtl2832u_tua9001_config); 1224 board_info.platform_data = &tua9001_pdata;
1225 request_module("tua9001");
1226 client = i2c_new_device(dev->demod_i2c_adapter, &board_info);
1227 if (client == NULL || client->dev.driver == NULL)
1228 break;
1229 if (!try_module_get(client->dev.driver->owner)) {
1230 i2c_unregister_device(client);
1231 break;
1232 }
1233 dev->i2c_client_tuner = client;
1126 break; 1234 break;
1235 }
1127 case TUNER_RTL2832_R820T: 1236 case TUNER_RTL2832_R820T:
1128 fe = dvb_attach(r820t_attach, adap->fe[0], 1237 fe = dvb_attach(r820t_attach, adap->fe[0],
1129 dev->demod_i2c_adapter, 1238 dev->demod_i2c_adapter,
@@ -1148,6 +1257,39 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1148 adap->fe[1]->ops.tuner_ops.get_rf_strength; 1257 adap->fe[1]->ops.tuner_ops.get_rf_strength;
1149 } 1258 }
1150 break; 1259 break;
1260 case TUNER_RTL2832_SI2157: {
1261 struct si2157_config si2157_config = {
1262 .fe = adap->fe[0],
1263 .if_port = 0,
1264 .inversion = false,
1265 };
1266
1267 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1268 info.addr = 0x60;
1269 info.platform_data = &si2157_config;
1270 request_module(info.type);
1271 client = i2c_new_device(&d->i2c_adap, &info);
1272 if (client == NULL || client->dev.driver == NULL)
1273 break;
1274
1275 if (!try_module_get(client->dev.driver->owner)) {
1276 i2c_unregister_device(client);
1277 break;
1278 }
1279
1280 dev->i2c_client_tuner = client;
1281 subdev = i2c_get_clientdata(client);
1282
1283 /* copy tuner ops for 2nd FE as tuner is shared */
1284 if (adap->fe[1]) {
1285 adap->fe[1]->tuner_priv =
1286 adap->fe[0]->tuner_priv;
1287 memcpy(&adap->fe[1]->ops.tuner_ops,
1288 &adap->fe[0]->ops.tuner_ops,
1289 sizeof(struct dvb_tuner_ops));
1290 }
1291 }
1292 break;
1151 default: 1293 default:
1152 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner); 1294 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
1153 } 1295 }
@@ -1158,6 +1300,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1158 1300
1159 /* register SDR */ 1301 /* register SDR */
1160 switch (dev->tuner) { 1302 switch (dev->tuner) {
1303 case TUNER_RTL2832_FC2580:
1161 case TUNER_RTL2832_FC0012: 1304 case TUNER_RTL2832_FC0012:
1162 case TUNER_RTL2832_FC0013: 1305 case TUNER_RTL2832_FC0013:
1163 case TUNER_RTL2832_E4000: 1306 case TUNER_RTL2832_E4000:
@@ -1178,7 +1321,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1178 "rtl2832_sdr", 1321 "rtl2832_sdr",
1179 PLATFORM_DEVID_AUTO, 1322 PLATFORM_DEVID_AUTO,
1180 &pdata, sizeof(pdata)); 1323 &pdata, sizeof(pdata));
1181 if (pdev == NULL || pdev->dev.driver == NULL) 1324 if (IS_ERR(pdev) || pdev->dev.driver == NULL)
1182 break; 1325 break;
1183 dev->platform_device_sdr = pdev; 1326 dev->platform_device_sdr = pdev;
1184 break; 1327 break;
@@ -1764,6 +1907,8 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1764 /* RTL2832P devices: */ 1907 /* RTL2832P devices: */
1765 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131, 1908 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
1766 &rtl28xxu_props, "Astrometa DVB-T2", NULL) }, 1909 &rtl28xxu_props, "Astrometa DVB-T2", NULL) },
1910 { DVB_USB_DEVICE(0x5654, 0xca42,
1911 &rtl28xxu_props, "GoTView MasterHD 3", NULL) },
1767 { } 1912 { }
1768}; 1913};
1769MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); 1914MODULE_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 1b5d7ffb685e..9f6115a2ee01 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
@@ -41,6 +41,8 @@
41#include "fc2580.h" 41#include "fc2580.h"
42#include "tua9001.h" 42#include "tua9001.h"
43#include "r820t.h" 43#include "r820t.h"
44#include "si2168.h"
45#include "si2157.h"
44 46
45/* 47/*
46 * USB commands 48 * USB commands
@@ -76,6 +78,7 @@ struct rtl28xxu_dev {
76 u8 page; /* integrated demod active register page */ 78 u8 page; /* integrated demod active register page */
77 struct i2c_adapter *demod_i2c_adapter; 79 struct i2c_adapter *demod_i2c_adapter;
78 bool rc_active; 80 bool rc_active;
81 bool new_i2c_write;
79 struct i2c_client *i2c_client_demod; 82 struct i2c_client *i2c_client_demod;
80 struct i2c_client *i2c_client_tuner; 83 struct i2c_client *i2c_client_tuner;
81 struct i2c_client *i2c_client_slave_demod; 84 struct i2c_client *i2c_client_slave_demod;
@@ -83,6 +86,7 @@ struct rtl28xxu_dev {
83 #define SLAVE_DEMOD_NONE 0 86 #define SLAVE_DEMOD_NONE 0
84 #define SLAVE_DEMOD_MN88472 1 87 #define SLAVE_DEMOD_MN88472 1
85 #define SLAVE_DEMOD_MN88473 2 88 #define SLAVE_DEMOD_MN88473 2
89 #define SLAVE_DEMOD_SI2168 3
86 unsigned int slave_demod:2; 90 unsigned int slave_demod:2;
87 union { 91 union {
88 struct rtl2830_platform_data rtl2830_platform_data; 92 struct rtl2830_platform_data rtl2830_platform_data;
@@ -116,6 +120,7 @@ enum rtl28xxu_tuner {
116 TUNER_RTL2832_FC0013, 120 TUNER_RTL2832_FC0013,
117 TUNER_RTL2832_R820T, 121 TUNER_RTL2832_R820T,
118 TUNER_RTL2832_R828D, 122 TUNER_RTL2832_R828D,
123 TUNER_RTL2832_SI2157,
119}; 124};
120 125
121struct rtl28xxu_req { 126struct rtl28xxu_req {
diff --git a/drivers/media/usb/dvb-usb/af9005-fe.c b/drivers/media/usb/dvb-usb/af9005-fe.c
index 740f3f496f12..ac97075d75f7 100644
--- a/drivers/media/usb/dvb-usb/af9005-fe.c
+++ b/drivers/media/usb/dvb-usb/af9005-fe.c
@@ -29,7 +29,7 @@
29 29
30struct af9005_fe_state { 30struct af9005_fe_state {
31 struct dvb_usb_device *d; 31 struct dvb_usb_device *d;
32 fe_status_t stat; 32 enum fe_status stat;
33 33
34 /* retraining parameters */ 34 /* retraining parameters */
35 u32 original_fcw; 35 u32 original_fcw;
@@ -437,7 +437,8 @@ static int af9005_fe_refresh_state(struct dvb_frontend *fe)
437 return 0; 437 return 0;
438} 438}
439 439
440static int af9005_fe_read_status(struct dvb_frontend *fe, fe_status_t * stat) 440static int af9005_fe_read_status(struct dvb_frontend *fe,
441 enum fe_status *stat)
441{ 442{
442 struct af9005_fe_state *state = fe->demodulator_priv; 443 struct af9005_fe_state *state = fe->demodulator_priv;
443 u8 temp; 444 u8 temp;
@@ -481,7 +482,7 @@ static int af9005_fe_read_status(struct dvb_frontend *fe, fe_status_t * stat)
481 return ret; 482 return ret;
482 if (temp != state->strong) { 483 if (temp != state->strong) {
483 deb_info("adjust for strong signal %d\n", temp); 484 deb_info("adjust for strong signal %d\n", temp);
484 state->strong = temp; 485 state->strong = temp;
485 } 486 }
486 return 0; 487 return 0;
487} 488}
diff --git a/drivers/media/usb/dvb-usb/az6027.c b/drivers/media/usb/dvb-usb/az6027.c
index 0df52ab32a7b..92e47d6c3ee3 100644
--- a/drivers/media/usb/dvb-usb/az6027.c
+++ b/drivers/media/usb/dvb-usb/az6027.c
@@ -778,7 +778,8 @@ static int az6027_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
778} 778}
779*/ 779*/
780 780
781static int az6027_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 781static int az6027_set_voltage(struct dvb_frontend *fe,
782 enum fe_sec_voltage voltage)
782{ 783{
783 784
784 u8 buf; 785 u8 buf;
diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index c890fe46acd3..b3ec743a7a2e 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -142,7 +142,7 @@ struct cinergyt2_fe_state {
142}; 142};
143 143
144static int cinergyt2_fe_read_status(struct dvb_frontend *fe, 144static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
145 fe_status_t *status) 145 enum fe_status *status)
146{ 146{
147 struct cinergyt2_fe_state *state = fe->demodulator_priv; 147 struct cinergyt2_fe_state *state = fe->demodulator_priv;
148 struct dvbt_get_status_msg result; 148 struct dvbt_get_status_msg result;
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index ffc3704abded..ab7151181728 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -1350,6 +1350,7 @@ static int cxusb_mygica_t230_frontend_attach(struct dvb_usb_adapter *adap)
1350 /* attach tuner */ 1350 /* attach tuner */
1351 memset(&si2157_config, 0, sizeof(si2157_config)); 1351 memset(&si2157_config, 0, sizeof(si2157_config));
1352 si2157_config.fe = adap->fe_adap[0].fe; 1352 si2157_config.fe = adap->fe_adap[0].fe;
1353 si2157_config.if_port = 1;
1353 memset(&info, 0, sizeof(struct i2c_board_info)); 1354 memset(&info, 0, sizeof(struct i2c_board_info));
1354 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 1355 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1355 info.addr = 0x60; 1356 info.addr = 0x60;
diff --git a/drivers/media/usb/dvb-usb/dib0700.h b/drivers/media/usb/dvb-usb/dib0700.h
index 927617d95616..8fd8f5b489d2 100644
--- a/drivers/media/usb/dvb-usb/dib0700.h
+++ b/drivers/media/usb/dvb-usb/dib0700.h
@@ -48,7 +48,7 @@ struct dib0700_state {
48 u8 disable_streaming_master_mode; 48 u8 disable_streaming_master_mode;
49 u32 fw_version; 49 u32 fw_version;
50 u32 nb_packet_buffer_size; 50 u32 nb_packet_buffer_size;
51 int (*read_status)(struct dvb_frontend *, fe_status_t *); 51 int (*read_status)(struct dvb_frontend *, enum fe_status *);
52 int (*sleep)(struct dvb_frontend* fe); 52 int (*sleep)(struct dvb_frontend* fe);
53 u8 buf[255]; 53 u8 buf[255];
54}; 54};
diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c b/drivers/media/usb/dvb-usb/dib0700_core.c
index 2b40393836ff..0d248ce02a9b 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -655,10 +655,20 @@ out:
655struct dib0700_rc_response { 655struct dib0700_rc_response {
656 u8 report_id; 656 u8 report_id;
657 u8 data_state; 657 u8 data_state;
658 u8 system; 658 union {
659 u8 not_system; 659 struct {
660 u8 data; 660 u8 system;
661 u8 not_data; 661 u8 not_system;
662 u8 data;
663 u8 not_data;
664 } nec;
665 struct {
666 u8 not_used;
667 u8 system;
668 u8 data;
669 u8 not_data;
670 } rc5;
671 };
662}; 672};
663#define RC_MSG_SIZE_V1_20 6 673#define RC_MSG_SIZE_V1_20 6
664 674
@@ -694,8 +704,8 @@ static void dib0700_rc_urb_completion(struct urb *purb)
694 704
695 deb_data("IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d)\n", 705 deb_data("IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d)\n",
696 poll_reply->report_id, poll_reply->data_state, 706 poll_reply->report_id, poll_reply->data_state,
697 poll_reply->system, poll_reply->not_system, 707 poll_reply->nec.system, poll_reply->nec.not_system,
698 poll_reply->data, poll_reply->not_data, 708 poll_reply->nec.data, poll_reply->nec.not_data,
699 purb->actual_length); 709 purb->actual_length);
700 710
701 switch (d->props.rc.core.protocol) { 711 switch (d->props.rc.core.protocol) {
@@ -704,30 +714,30 @@ static void dib0700_rc_urb_completion(struct urb *purb)
704 toggle = 0; 714 toggle = 0;
705 715
706 /* NEC protocol sends repeat code as 0 0 0 FF */ 716 /* NEC protocol sends repeat code as 0 0 0 FF */
707 if (poll_reply->system == 0x00 && 717 if (poll_reply->nec.system == 0x00 &&
708 poll_reply->not_system == 0x00 && 718 poll_reply->nec.not_system == 0x00 &&
709 poll_reply->data == 0x00 && 719 poll_reply->nec.data == 0x00 &&
710 poll_reply->not_data == 0xff) { 720 poll_reply->nec.not_data == 0xff) {
711 poll_reply->data_state = 2; 721 poll_reply->data_state = 2;
712 break; 722 break;
713 } 723 }
714 724
715 if ((poll_reply->data ^ poll_reply->not_data) != 0xff) { 725 if ((poll_reply->nec.data ^ poll_reply->nec.not_data) != 0xff) {
716 deb_data("NEC32 protocol\n"); 726 deb_data("NEC32 protocol\n");
717 keycode = RC_SCANCODE_NEC32(poll_reply->system << 24 | 727 keycode = RC_SCANCODE_NEC32(poll_reply->nec.system << 24 |
718 poll_reply->not_system << 16 | 728 poll_reply->nec.not_system << 16 |
719 poll_reply->data << 8 | 729 poll_reply->nec.data << 8 |
720 poll_reply->not_data); 730 poll_reply->nec.not_data);
721 } else if ((poll_reply->system ^ poll_reply->not_system) != 0xff) { 731 } else if ((poll_reply->nec.system ^ poll_reply->nec.not_system) != 0xff) {
722 deb_data("NEC extended protocol\n"); 732 deb_data("NEC extended protocol\n");
723 keycode = RC_SCANCODE_NECX(poll_reply->system << 8 | 733 keycode = RC_SCANCODE_NECX(poll_reply->nec.system << 8 |
724 poll_reply->not_system, 734 poll_reply->nec.not_system,
725 poll_reply->data); 735 poll_reply->nec.data);
726 736
727 } else { 737 } else {
728 deb_data("NEC normal protocol\n"); 738 deb_data("NEC normal protocol\n");
729 keycode = RC_SCANCODE_NEC(poll_reply->system, 739 keycode = RC_SCANCODE_NEC(poll_reply->nec.system,
730 poll_reply->data); 740 poll_reply->nec.data);
731 } 741 }
732 742
733 break; 743 break;
@@ -735,19 +745,19 @@ static void dib0700_rc_urb_completion(struct urb *purb)
735 deb_data("RC5 protocol\n"); 745 deb_data("RC5 protocol\n");
736 protocol = RC_TYPE_RC5; 746 protocol = RC_TYPE_RC5;
737 toggle = poll_reply->report_id; 747 toggle = poll_reply->report_id;
738 keycode = RC_SCANCODE_RC5(poll_reply->system, poll_reply->data); 748 keycode = RC_SCANCODE_RC5(poll_reply->rc5.system, poll_reply->rc5.data);
749
750 if ((poll_reply->rc5.data ^ poll_reply->rc5.not_data) != 0xff) {
751 /* Key failed integrity check */
752 err("key failed integrity check: %02x %02x %02x %02x",
753 poll_reply->rc5.not_used, poll_reply->rc5.system,
754 poll_reply->rc5.data, poll_reply->rc5.not_data);
755 goto resubmit;
756 }
739 757
740 break; 758 break;
741 } 759 }
742 760
743 if ((poll_reply->data + poll_reply->not_data) != 0xff) {
744 /* Key failed integrity check */
745 err("key failed integrity check: %02x %02x %02x %02x",
746 poll_reply->system, poll_reply->not_system,
747 poll_reply->data, poll_reply->not_data);
748 goto resubmit;
749 }
750
751 rc_keydown(d->rc_dev, protocol, keycode, toggle); 761 rc_keydown(d->rc_dev, protocol, keycode, toggle);
752 762
753resubmit: 763resubmit:
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
index d7d55a20e959..7ed49646a699 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -861,22 +861,22 @@ static int dib7770_set_param_override(struct dvb_frontend *fe)
861 struct dvb_usb_adapter *adap = fe->dvb->priv; 861 struct dvb_usb_adapter *adap = fe->dvb->priv;
862 struct dib0700_adapter_state *state = adap->priv; 862 struct dib0700_adapter_state *state = adap->priv;
863 863
864 u16 offset; 864 u16 offset;
865 u8 band = BAND_OF_FREQUENCY(p->frequency/1000); 865 u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
866 switch (band) { 866 switch (band) {
867 case BAND_VHF: 867 case BAND_VHF:
868 state->dib7000p_ops.set_gpio(fe, 0, 0, 1); 868 state->dib7000p_ops.set_gpio(fe, 0, 0, 1);
869 offset = 850; 869 offset = 850;
870 break; 870 break;
871 case BAND_UHF: 871 case BAND_UHF:
872 default: 872 default:
873 state->dib7000p_ops.set_gpio(fe, 0, 0, 0); 873 state->dib7000p_ops.set_gpio(fe, 0, 0, 0);
874 offset = 250; 874 offset = 250;
875 break; 875 break;
876 } 876 }
877 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe)); 877 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
878 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe)); 878 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
879 return state->set_param_save(fe); 879 return state->set_param_save(fe);
880} 880}
881 881
882static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap) 882static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap)
@@ -3309,7 +3309,7 @@ static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
3309} 3309}
3310 3310
3311static int novatd_read_status_override(struct dvb_frontend *fe, 3311static int novatd_read_status_override(struct dvb_frontend *fe,
3312 fe_status_t *stat) 3312 enum fe_status *stat)
3313{ 3313{
3314 struct dvb_usb_adapter *adap = fe->dvb->priv; 3314 struct dvb_usb_adapter *adap = fe->dvb->priv;
3315 struct dvb_usb_device *dev = adap->dev; 3315 struct dvb_usb_device *dev = adap->dev;
@@ -3821,6 +3821,10 @@ MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
3821 } \ 3821 } \
3822 } 3822 }
3823 3823
3824#define DIB0700_NUM_FRONTENDS(n) \
3825 .num_frontends = n, \
3826 .size_of_priv = sizeof(struct dib0700_adapter_state)
3827
3824struct dvb_usb_device_properties dib0700_devices[] = { 3828struct dvb_usb_device_properties dib0700_devices[] = {
3825 { 3829 {
3826 DIB0700_DEFAULT_DEVICE_PROPERTIES, 3830 DIB0700_DEFAULT_DEVICE_PROPERTIES,
@@ -3828,7 +3832,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3828 .num_adapters = 1, 3832 .num_adapters = 1,
3829 .adapter = { 3833 .adapter = {
3830 { 3834 {
3831 .num_frontends = 1, 3835 DIB0700_NUM_FRONTENDS(1),
3832 .fe = {{ 3836 .fe = {{
3833 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 3837 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3834 .pid_filter_count = 32, 3838 .pid_filter_count = 32,
@@ -3839,7 +3843,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3839 3843
3840 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 3844 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3841 }}, 3845 }},
3842 .size_of_priv = sizeof(struct dib0700_adapter_state),
3843 }, 3846 },
3844 }, 3847 },
3845 3848
@@ -3893,7 +3896,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3893 .num_adapters = 2, 3896 .num_adapters = 2,
3894 .adapter = { 3897 .adapter = {
3895 { 3898 {
3896 .num_frontends = 1, 3899 DIB0700_NUM_FRONTENDS(1),
3897 .fe = {{ 3900 .fe = {{
3898 .frontend_attach = bristol_frontend_attach, 3901 .frontend_attach = bristol_frontend_attach,
3899 .tuner_attach = bristol_tuner_attach, 3902 .tuner_attach = bristol_tuner_attach,
@@ -3901,7 +3904,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3901 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 3904 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3902 }}, 3905 }},
3903 }, { 3906 }, {
3904 .num_frontends = 1, 3907 DIB0700_NUM_FRONTENDS(1),
3905 .fe = {{ 3908 .fe = {{
3906 .frontend_attach = bristol_frontend_attach, 3909 .frontend_attach = bristol_frontend_attach,
3907 .tuner_attach = bristol_tuner_attach, 3910 .tuner_attach = bristol_tuner_attach,
@@ -3933,7 +3936,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3933 .num_adapters = 2, 3936 .num_adapters = 2,
3934 .adapter = { 3937 .adapter = {
3935 { 3938 {
3936 .num_frontends = 1, 3939 DIB0700_NUM_FRONTENDS(1),
3937 .fe = {{ 3940 .fe = {{
3938 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 3941 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3939 .pid_filter_count = 32, 3942 .pid_filter_count = 32,
@@ -3945,7 +3948,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3945 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 3948 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3946 }}, 3949 }},
3947 }, { 3950 }, {
3948 .num_frontends = 1, 3951 DIB0700_NUM_FRONTENDS(1),
3949 .fe = {{ 3952 .fe = {{
3950 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 3953 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3951 .pid_filter_count = 32, 3954 .pid_filter_count = 32,
@@ -3998,7 +4001,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
3998 .num_adapters = 1, 4001 .num_adapters = 1,
3999 .adapter = { 4002 .adapter = {
4000 { 4003 {
4001 .num_frontends = 1, 4004 DIB0700_NUM_FRONTENDS(1),
4002 .fe = {{ 4005 .fe = {{
4003 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4006 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4004 .pid_filter_count = 32, 4007 .pid_filter_count = 32,
@@ -4043,7 +4046,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4043 .num_adapters = 1, 4046 .num_adapters = 1,
4044 .adapter = { 4047 .adapter = {
4045 { 4048 {
4046 .num_frontends = 1, 4049 DIB0700_NUM_FRONTENDS(1),
4047 .fe = {{ 4050 .fe = {{
4048 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4051 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4049 .pid_filter_count = 32, 4052 .pid_filter_count = 32,
@@ -4054,7 +4057,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4054 4057
4055 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4058 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4056 }}, 4059 }},
4057 .size_of_priv = sizeof(struct dib0700_adapter_state),
4058 }, 4060 },
4059 }, 4061 },
4060 4062
@@ -4125,7 +4127,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4125 .num_adapters = 1, 4127 .num_adapters = 1,
4126 .adapter = { 4128 .adapter = {
4127 { 4129 {
4128 .num_frontends = 1, 4130 DIB0700_NUM_FRONTENDS(1),
4129 .fe = {{ 4131 .fe = {{
4130 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4132 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4131 .pid_filter_count = 32, 4133 .pid_filter_count = 32,
@@ -4136,7 +4138,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4136 4138
4137 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4139 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4138 }}, 4140 }},
4139 .size_of_priv = sizeof(struct dib0700_adapter_state),
4140 }, 4141 },
4141 }, 4142 },
4142 4143
@@ -4171,7 +4172,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4171 .num_adapters = 2, 4172 .num_adapters = 2,
4172 .adapter = { 4173 .adapter = {
4173 { 4174 {
4174 .num_frontends = 1, 4175 DIB0700_NUM_FRONTENDS(1),
4175 .fe = {{ 4176 .fe = {{
4176 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4177 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4177 .pid_filter_count = 32, 4178 .pid_filter_count = 32,
@@ -4182,9 +4183,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4182 4183
4183 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4184 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4184 }}, 4185 }},
4185 .size_of_priv = sizeof(struct dib0700_adapter_state),
4186 }, { 4186 }, {
4187 .num_frontends = 1, 4187 DIB0700_NUM_FRONTENDS(1),
4188 .fe = {{ 4188 .fe = {{
4189 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4189 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4190 .pid_filter_count = 32, 4190 .pid_filter_count = 32,
@@ -4195,7 +4195,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4195 4195
4196 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4196 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4197 }}, 4197 }},
4198 .size_of_priv = sizeof(struct dib0700_adapter_state),
4199 } 4198 }
4200 }, 4199 },
4201 4200
@@ -4230,7 +4229,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4230 .num_adapters = 2, 4229 .num_adapters = 2,
4231 .adapter = { 4230 .adapter = {
4232 { 4231 {
4233 .num_frontends = 1, 4232 DIB0700_NUM_FRONTENDS(1),
4234 .fe = {{ 4233 .fe = {{
4235 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4234 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4236 .pid_filter_count = 32, 4235 .pid_filter_count = 32,
@@ -4241,9 +4240,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4241 4240
4242 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4241 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4243 }}, 4242 }},
4244 .size_of_priv = sizeof(struct dib0700_adapter_state),
4245 }, { 4243 }, {
4246 .num_frontends = 1, 4244 DIB0700_NUM_FRONTENDS(1),
4247 .fe = {{ 4245 .fe = {{
4248 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4246 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4249 .pid_filter_count = 32, 4247 .pid_filter_count = 32,
@@ -4254,7 +4252,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4254 4252
4255 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4253 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4256 }}, 4254 }},
4257 .size_of_priv = sizeof(struct dib0700_adapter_state),
4258 } 4255 }
4259 }, 4256 },
4260 4257
@@ -4298,7 +4295,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4298 .num_adapters = 2, 4295 .num_adapters = 2,
4299 .adapter = { 4296 .adapter = {
4300 { 4297 {
4301 .num_frontends = 1, 4298 DIB0700_NUM_FRONTENDS(1),
4302 .fe = {{ 4299 .fe = {{
4303 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4300 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4304 .pid_filter_count = 32, 4301 .pid_filter_count = 32,
@@ -4309,9 +4306,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4309 4306
4310 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4307 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4311 }}, 4308 }},
4312 .size_of_priv = sizeof(struct dib0700_adapter_state),
4313 }, { 4309 }, {
4314 .num_frontends = 1, 4310 DIB0700_NUM_FRONTENDS(1),
4315 .fe = {{ 4311 .fe = {{
4316 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4312 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4317 .pid_filter_count = 32, 4313 .pid_filter_count = 32,
@@ -4322,7 +4318,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4322 4318
4323 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4319 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4324 }}, 4320 }},
4325 .size_of_priv = sizeof(struct dib0700_adapter_state),
4326 } 4321 }
4327 }, 4322 },
4328 4323
@@ -4349,7 +4344,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4349 .num_adapters = 1, 4344 .num_adapters = 1,
4350 .adapter = { 4345 .adapter = {
4351 { 4346 {
4352 .num_frontends = 1, 4347 DIB0700_NUM_FRONTENDS(1),
4353 .fe = {{ 4348 .fe = {{
4354 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4349 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4355 .pid_filter_count = 32, 4350 .pid_filter_count = 32,
@@ -4360,8 +4355,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4360 4355
4361 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4356 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4362 }}, 4357 }},
4363 .size_of_priv = sizeof(struct
4364 dib0700_adapter_state),
4365 }, 4358 },
4366 }, 4359 },
4367 4360
@@ -4419,15 +4412,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4419 .num_adapters = 1, 4412 .num_adapters = 1,
4420 .adapter = { 4413 .adapter = {
4421 { 4414 {
4422 .num_frontends = 1, 4415 DIB0700_NUM_FRONTENDS(1),
4423 .fe = {{ 4416 .fe = {{
4424 .frontend_attach = s5h1411_frontend_attach, 4417 .frontend_attach = s5h1411_frontend_attach,
4425 .tuner_attach = xc5000_tuner_attach, 4418 .tuner_attach = xc5000_tuner_attach,
4426 4419
4427 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4420 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4428 }}, 4421 }},
4429 .size_of_priv = sizeof(struct
4430 dib0700_adapter_state),
4431 }, 4422 },
4432 }, 4423 },
4433 4424
@@ -4457,15 +4448,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4457 .num_adapters = 1, 4448 .num_adapters = 1,
4458 .adapter = { 4449 .adapter = {
4459 { 4450 {
4460 .num_frontends = 1, 4451 DIB0700_NUM_FRONTENDS(1),
4461 .fe = {{ 4452 .fe = {{
4462 .frontend_attach = lgdt3305_frontend_attach, 4453 .frontend_attach = lgdt3305_frontend_attach,
4463 .tuner_attach = mxl5007t_tuner_attach, 4454 .tuner_attach = mxl5007t_tuner_attach,
4464 4455
4465 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4456 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4466 }}, 4457 }},
4467 .size_of_priv = sizeof(struct
4468 dib0700_adapter_state),
4469 }, 4458 },
4470 }, 4459 },
4471 4460
@@ -4485,7 +4474,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4485 .num_adapters = 1, 4474 .num_adapters = 1,
4486 .adapter = { 4475 .adapter = {
4487 { 4476 {
4488 .num_frontends = 1, 4477 DIB0700_NUM_FRONTENDS(1),
4489 .fe = {{ 4478 .fe = {{
4490 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4479 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4491 .pid_filter_count = 32, 4480 .pid_filter_count = 32,
@@ -4496,8 +4485,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4496 4485
4497 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4486 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4498 }}, 4487 }},
4499 .size_of_priv =
4500 sizeof(struct dib0700_adapter_state),
4501 }, 4488 },
4502 }, 4489 },
4503 4490
@@ -4537,7 +4524,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4537 .num_adapters = 1, 4524 .num_adapters = 1,
4538 .adapter = { 4525 .adapter = {
4539 { 4526 {
4540 .num_frontends = 1, 4527 DIB0700_NUM_FRONTENDS(1),
4541 .fe = {{ 4528 .fe = {{
4542 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4529 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4543 .pid_filter_count = 32, 4530 .pid_filter_count = 32,
@@ -4548,8 +4535,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4548 4535
4549 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4536 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4550 }}, 4537 }},
4551 .size_of_priv =
4552 sizeof(struct dib0700_adapter_state),
4553 }, 4538 },
4554 }, 4539 },
4555 4540
@@ -4583,7 +4568,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4583 .num_adapters = 2, 4568 .num_adapters = 2,
4584 .adapter = { 4569 .adapter = {
4585 { 4570 {
4586 .num_frontends = 1, 4571 DIB0700_NUM_FRONTENDS(1),
4587 .fe = {{ 4572 .fe = {{
4588 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4573 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4589 .pid_filter_count = 32, 4574 .pid_filter_count = 32,
@@ -4594,11 +4579,9 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4594 4579
4595 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4580 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4596 }}, 4581 }},
4597 .size_of_priv =
4598 sizeof(struct dib0700_adapter_state),
4599 }, 4582 },
4600 { 4583 {
4601 .num_frontends = 1, 4584 DIB0700_NUM_FRONTENDS(1),
4602 .fe = {{ 4585 .fe = {{
4603 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4586 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4604 .pid_filter_count = 32, 4587 .pid_filter_count = 32,
@@ -4609,8 +4592,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4609 4592
4610 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4593 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4611 }}, 4594 }},
4612 .size_of_priv =
4613 sizeof(struct dib0700_adapter_state),
4614 }, 4595 },
4615 }, 4596 },
4616 4597
@@ -4636,7 +4617,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4636 .num_adapters = 1, 4617 .num_adapters = 1,
4637 .adapter = { 4618 .adapter = {
4638 { 4619 {
4639 .num_frontends = 1, 4620 DIB0700_NUM_FRONTENDS(1),
4640 .fe = {{ 4621 .fe = {{
4641 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4622 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4642 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4623 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4648,8 +4629,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4648 4629
4649 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4630 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4650 }}, 4631 }},
4651 .size_of_priv =
4652 sizeof(struct dib0700_adapter_state),
4653 }, 4632 },
4654 }, 4633 },
4655 4634
@@ -4675,7 +4654,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4675 .num_adapters = 1, 4654 .num_adapters = 1,
4676 .adapter = { 4655 .adapter = {
4677 { 4656 {
4678 .num_frontends = 1, 4657 DIB0700_NUM_FRONTENDS(1),
4679 .fe = {{ 4658 .fe = {{
4680 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4659 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4681 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4660 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4687,8 +4666,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4687 4666
4688 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4667 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4689 }}, 4668 }},
4690 .size_of_priv =
4691 sizeof(struct dib0700_adapter_state),
4692 }, 4669 },
4693 }, 4670 },
4694 4671
@@ -4714,7 +4691,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4714 .num_adapters = 1, 4691 .num_adapters = 1,
4715 .adapter = { 4692 .adapter = {
4716 { 4693 {
4717 .num_frontends = 1, 4694 DIB0700_NUM_FRONTENDS(1),
4718 .fe = {{ 4695 .fe = {{
4719 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4696 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4720 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4697 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4726,8 +4703,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4726 4703
4727 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4704 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4728 }}, 4705 }},
4729 .size_of_priv =
4730 sizeof(struct dib0700_adapter_state),
4731 }, 4706 },
4732 }, 4707 },
4733 4708
@@ -4753,7 +4728,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4753 .num_adapters = 1, 4728 .num_adapters = 1,
4754 .adapter = { 4729 .adapter = {
4755 { 4730 {
4756 .num_frontends = 1, 4731 DIB0700_NUM_FRONTENDS(1),
4757 .fe = {{ 4732 .fe = {{
4758 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4733 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4759 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4734 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4765,8 +4740,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4765 4740
4766 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4741 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4767 }}, 4742 }},
4768 .size_of_priv =
4769 sizeof(struct dib0700_adapter_state),
4770 }, 4743 },
4771 }, 4744 },
4772 4745
@@ -4792,7 +4765,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4792 .num_adapters = 1, 4765 .num_adapters = 1,
4793 .adapter = { 4766 .adapter = {
4794 { 4767 {
4795 .num_frontends = 1, 4768 DIB0700_NUM_FRONTENDS(1),
4796 .fe = {{ 4769 .fe = {{
4797 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4770 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4798 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4771 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4804,8 +4777,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4804 4777
4805 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4778 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4806 }}, 4779 }},
4807 .size_of_priv =
4808 sizeof(struct dib0700_adapter_state),
4809 }, 4780 },
4810 }, 4781 },
4811 4782
@@ -4831,7 +4802,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4831 .num_adapters = 2, 4802 .num_adapters = 2,
4832 .adapter = { 4803 .adapter = {
4833 { 4804 {
4834 .num_frontends = 1, 4805 DIB0700_NUM_FRONTENDS(1),
4835 .fe = {{ 4806 .fe = {{
4836 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4807 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4837 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4808 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4843,11 +4814,9 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4843 4814
4844 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4815 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4845 }}, 4816 }},
4846 .size_of_priv =
4847 sizeof(struct dib0700_adapter_state),
4848 }, 4817 },
4849 { 4818 {
4850 .num_frontends = 1, 4819 DIB0700_NUM_FRONTENDS(1),
4851 .fe = {{ 4820 .fe = {{
4852 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4821 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4853 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4822 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4859,8 +4828,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4859 4828
4860 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4829 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4861 }}, 4830 }},
4862 .size_of_priv =
4863 sizeof(struct dib0700_adapter_state),
4864 }, 4831 },
4865 }, 4832 },
4866 4833
@@ -4886,15 +4853,13 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4886 .num_adapters = 1, 4853 .num_adapters = 1,
4887 .adapter = { 4854 .adapter = {
4888 { 4855 {
4889 .num_frontends = 1, 4856 DIB0700_NUM_FRONTENDS(1),
4890 .fe = {{ 4857 .fe = {{
4891 .frontend_attach = pctv340e_frontend_attach, 4858 .frontend_attach = pctv340e_frontend_attach,
4892 .tuner_attach = xc4000_tuner_attach, 4859 .tuner_attach = xc4000_tuner_attach,
4893 4860
4894 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4861 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4895 }}, 4862 }},
4896 .size_of_priv = sizeof(struct
4897 dib0700_adapter_state),
4898 }, 4863 },
4899 }, 4864 },
4900 4865
@@ -4923,7 +4888,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4923 .num_adapters = 1, 4888 .num_adapters = 1,
4924 .adapter = { 4889 .adapter = {
4925 { 4890 {
4926 .num_frontends = 1, 4891 DIB0700_NUM_FRONTENDS(1),
4927 .fe = {{ 4892 .fe = {{
4928 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4893 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4929 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4894 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4935,9 +4900,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4935 4900
4936 DIB0700_DEFAULT_STREAMING_CONFIG(0x03), 4901 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4937 } }, 4902 } },
4938
4939 .size_of_priv =
4940 sizeof(struct dib0700_adapter_state),
4941 }, 4903 },
4942 }, 4904 },
4943 4905
@@ -4963,7 +4925,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4963 .num_adapters = 1, 4925 .num_adapters = 1,
4964 .adapter = { 4926 .adapter = {
4965 { 4927 {
4966 .num_frontends = 1, 4928 DIB0700_NUM_FRONTENDS(1),
4967 .fe = {{ 4929 .fe = {{
4968 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 4930 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
4969 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 4931 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
@@ -4976,9 +4938,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
4976 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 4938 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4977 4939
4978 } }, 4940 } },
4979
4980 .size_of_priv =
4981 sizeof(struct dib0700_adapter_state),
4982 }, 4941 },
4983 }, 4942 },
4984 4943
diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index 3d81daa49172..8637ad1be6be 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -14,13 +14,14 @@
14struct dtt200u_fe_state { 14struct dtt200u_fe_state {
15 struct dvb_usb_device *d; 15 struct dvb_usb_device *d;
16 16
17 fe_status_t stat; 17 enum fe_status stat;
18 18
19 struct dtv_frontend_properties fep; 19 struct dtv_frontend_properties fep;
20 struct dvb_frontend frontend; 20 struct dvb_frontend frontend;
21}; 21};
22 22
23static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat) 23static int dtt200u_fe_read_status(struct dvb_frontend *fe,
24 enum fe_status *stat)
24{ 25{
25 struct dtt200u_fe_state *state = fe->demodulator_priv; 26 struct dtt200u_fe_state *state = fe->demodulator_priv;
26 u8 st = GET_TUNE_STATUS, b[3]; 27 u8 st = GET_TUNE_STATUS, b[3];
@@ -105,7 +106,7 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
105 struct dtv_frontend_properties *fep = &fe->dtv_property_cache; 106 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
106 struct dtt200u_fe_state *state = fe->demodulator_priv; 107 struct dtt200u_fe_state *state = fe->demodulator_priv;
107 int i; 108 int i;
108 fe_status_t st; 109 enum fe_status st;
109 u16 freq = fep->frequency / 250000; 110 u16 freq = fep->frequency / 250000;
110 u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 }; 111 u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
111 112
diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index f1f357f43ff0..14ef25dc6cd3 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -117,8 +117,13 @@
117 117
118struct dw2102_state { 118struct dw2102_state {
119 u8 initialized; 119 u8 initialized;
120 u8 last_lock;
120 struct i2c_client *i2c_client_tuner; 121 struct i2c_client *i2c_client_tuner;
121 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v); 122
123 /* fe hook functions*/
124 int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
125 int (*fe_read_status)(struct dvb_frontend *fe,
126 enum fe_status *status);
122}; 127};
123 128
124/* debug */ 129/* debug */
@@ -437,7 +442,7 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
437 ibuf, msg[j].len + 2, 442 ibuf, msg[j].len + 2,
438 DW210X_READ_MSG); 443 DW210X_READ_MSG);
439 memcpy(msg[j].buf, ibuf + 2, msg[j].len); 444 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
440 mdelay(10); 445 mdelay(10);
441 } else if (((msg[j].buf[0] == 0xb0) && 446 } else if (((msg[j].buf[0] == 0xb0) &&
442 (msg[j].addr == 0x68)) || 447 (msg[j].addr == 0x68)) ||
443 ((msg[j].buf[0] == 0xf7) && 448 ((msg[j].buf[0] == 0xf7) &&
@@ -928,8 +933,6 @@ static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
928 break; 933 break;
929 else 934 else
930 mac[i] = ibuf[0]; 935 mac[i] = ibuf[0];
931
932 debug_dump(mac, 6, printk);
933 } 936 }
934 937
935 return 0; 938 return 0;
@@ -946,7 +949,8 @@ static int su3000_identify_state(struct usb_device *udev,
946 return 0; 949 return 0;
947} 950}
948 951
949static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 952static int dw210x_set_voltage(struct dvb_frontend *fe,
953 enum fe_sec_voltage voltage)
950{ 954{
951 static u8 command_13v[] = {0x00, 0x01}; 955 static u8 command_13v[] = {0x00, 0x01};
952 static u8 command_18v[] = {0x01, 0x01}; 956 static u8 command_18v[] = {0x01, 0x01};
@@ -970,7 +974,8 @@ static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
970 return 0; 974 return 0;
971} 975}
972 976
973static int s660_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 977static int s660_set_voltage(struct dvb_frontend *fe,
978 enum fe_sec_voltage voltage)
974{ 979{
975 struct dvb_usb_adapter *d = 980 struct dvb_usb_adapter *d =
976 (struct dvb_usb_adapter *)(fe->dvb->priv); 981 (struct dvb_usb_adapter *)(fe->dvb->priv);
@@ -1001,6 +1006,24 @@ static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1001 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1); 1006 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1002} 1007}
1003 1008
1009static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1010 enum fe_status *status)
1011{
1012 struct dvb_usb_adapter *d =
1013 (struct dvb_usb_adapter *)(fe->dvb->priv);
1014 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1015 int ret;
1016
1017 ret = st->fe_read_status(fe, status);
1018
1019 /* resync slave fifo when signal change from unlock to lock */
1020 if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1021 su3000_streaming_ctrl(d, 1);
1022
1023 st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1024 return ret;
1025}
1026
1004static struct stv0299_config sharp_z0194a_config = { 1027static struct stv0299_config sharp_z0194a_config = {
1005 .demod_address = 0x68, 1028 .demod_address = 0x68,
1006 .inittab = sharp_z0194a_inittab, 1029 .inittab = sharp_z0194a_inittab,
@@ -1553,6 +1576,12 @@ static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1553 1576
1554 state->i2c_client_tuner = client; 1577 state->i2c_client_tuner = client;
1555 1578
1579 /* hook fe: need to resync the slave fifo when signal locks */
1580 state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1581 adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1582
1583 state->last_lock = 0;
1584
1556 return 0; 1585 return 0;
1557} 1586}
1558 1587
@@ -1657,6 +1686,8 @@ enum dw2102_table_entry {
1657 GOTVIEW_SAT_HD, 1686 GOTVIEW_SAT_HD,
1658 GENIATECH_T220, 1687 GENIATECH_T220,
1659 TECHNOTREND_S2_4600, 1688 TECHNOTREND_S2_4600,
1689 TEVII_S482_1,
1690 TEVII_S482_2,
1660}; 1691};
1661 1692
1662static struct usb_device_id dw2102_table[] = { 1693static struct usb_device_id dw2102_table[] = {
@@ -1682,6 +1713,8 @@ static struct usb_device_id dw2102_table[] = {
1682 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)}, 1713 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1683 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND, 1714 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1684 USB_PID_TECHNOTREND_CONNECT_S2_4600)}, 1715 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1716 [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1717 [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1685 { } 1718 { }
1686}; 1719};
1687 1720
@@ -2199,12 +2232,20 @@ static struct dvb_usb_device_properties tt_s2_4600_properties = {
2199 } }, 2232 } },
2200 } 2233 }
2201 }, 2234 },
2202 .num_device_descs = 1, 2235 .num_device_descs = 3,
2203 .devices = { 2236 .devices = {
2204 { "TechnoTrend TT-connect S2-4600", 2237 { "TechnoTrend TT-connect S2-4600",
2205 { &dw2102_table[TECHNOTREND_S2_4600], NULL }, 2238 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2206 { NULL }, 2239 { NULL },
2207 }, 2240 },
2241 { "TeVii S482 (tuner 1)",
2242 { &dw2102_table[TEVII_S482_1], NULL },
2243 { NULL },
2244 },
2245 { "TeVii S482 (tuner 2)",
2246 { &dw2102_table[TEVII_S482_2], NULL },
2247 { NULL },
2248 },
2208 } 2249 }
2209}; 2250};
2210 2251
diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
index d56f927fc31a..8ec92fbeabad 100644
--- a/drivers/media/usb/dvb-usb/friio-fe.c
+++ b/drivers/media/usb/dvb-usb/friio-fe.c
@@ -210,7 +210,8 @@ error:
210 return -EREMOTEIO; 210 return -EREMOTEIO;
211} 211}
212 212
213static int jdvbt90502_read_status(struct dvb_frontend *fe, fe_status_t *state) 213static int jdvbt90502_read_status(struct dvb_frontend *fe,
214 enum fe_status *state)
214{ 215{
215 u8 result; 216 u8 result;
216 int ret; 217 int ret;
diff --git a/drivers/media/usb/dvb-usb/gp8psk-fe.c b/drivers/media/usb/dvb-usb/gp8psk-fe.c
index 67957dd99ede..db6eb79cde07 100644
--- a/drivers/media/usb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/usb/dvb-usb/gp8psk-fe.c
@@ -51,7 +51,8 @@ static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
51 return 0; 51 return 0;
52} 52}
53 53
54static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status) 54static int gp8psk_fe_read_status(struct dvb_frontend *fe,
55 enum fe_status *status)
55{ 56{
56 struct gp8psk_fe_state *st = fe->demodulator_priv; 57 struct gp8psk_fe_state *st = fe->demodulator_priv;
57 gp8psk_fe_update_status(st); 58 gp8psk_fe_update_status(st);
@@ -236,8 +237,8 @@ static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
236 return 0; 237 return 0;
237} 238}
238 239
239static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe, 240static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
240 fe_sec_mini_cmd_t burst) 241 enum fe_sec_mini_cmd burst)
241{ 242{
242 struct gp8psk_fe_state *st = fe->demodulator_priv; 243 struct gp8psk_fe_state *st = fe->demodulator_priv;
243 u8 cmd; 244 u8 cmd;
@@ -254,7 +255,8 @@ static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
254 return 0; 255 return 0;
255} 256}
256 257
257static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 258static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
259 enum fe_sec_tone_mode tone)
258{ 260{
259 struct gp8psk_fe_state* state = fe->demodulator_priv; 261 struct gp8psk_fe_state* state = fe->demodulator_priv;
260 262
@@ -265,7 +267,8 @@ static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
265 return 0; 267 return 0;
266} 268}
267 269
268static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 270static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
271 enum fe_sec_voltage voltage)
269{ 272{
270 struct gp8psk_fe_state* state = fe->demodulator_priv; 273 struct gp8psk_fe_state* state = fe->demodulator_priv;
271 274
diff --git a/drivers/media/usb/dvb-usb/opera1.c b/drivers/media/usb/dvb-usb/opera1.c
index 14a2119912ba..2566d2f1c2ad 100644
--- a/drivers/media/usb/dvb-usb/opera1.c
+++ b/drivers/media/usb/dvb-usb/opera1.c
@@ -167,7 +167,8 @@ static struct i2c_algorithm opera1_i2c_algo = {
167 .functionality = opera1_i2c_func, 167 .functionality = opera1_i2c_func,
168}; 168};
169 169
170static int opera1_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 170static int opera1_set_voltage(struct dvb_frontend *fe,
171 enum fe_sec_voltage voltage)
171{ 172{
172 static u8 command_13v[1]={0x00}; 173 static u8 command_13v[1]={0x00};
173 static u8 command_18v[1]={0x01}; 174 static u8 command_18v[1]={0x01};
diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
index 5801ae7f672a..03f334d3a8f4 100644
--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
@@ -453,7 +453,7 @@ static struct stv090x_config technisat_usb2_stv090x_config;
453 453
454/* frontend attach */ 454/* frontend attach */
455static int technisat_usb2_set_voltage(struct dvb_frontend *fe, 455static int technisat_usb2_set_voltage(struct dvb_frontend *fe,
456 fe_sec_voltage_t voltage) 456 enum fe_sec_voltage voltage)
457{ 457{
458 int i; 458 int i;
459 u8 gpio[3] = { 0 }; /* 0 = 2, 1 = 3, 2 = 4 */ 459 u8 gpio[3] = { 0 }; /* 0 = 2, 1 = 3, 2 = 4 */
diff --git a/drivers/media/usb/dvb-usb/vp702x-fe.c b/drivers/media/usb/dvb-usb/vp702x-fe.c
index 5eab468dd904..d361a72ca0fa 100644
--- a/drivers/media/usb/dvb-usb/vp702x-fe.c
+++ b/drivers/media/usb/dvb-usb/vp702x-fe.c
@@ -26,8 +26,8 @@ struct vp702x_fe_state {
26 26
27 struct dvb_frontend_ops ops; 27 struct dvb_frontend_ops ops;
28 28
29 fe_sec_voltage_t voltage; 29 enum fe_sec_voltage voltage;
30 fe_sec_tone_mode_t tone_mode; 30 enum fe_sec_tone_mode tone_mode;
31 31
32 u8 lnb_buf[8]; 32 u8 lnb_buf[8];
33 33
@@ -72,7 +72,8 @@ static u8 vp702x_chksum(u8 *buf,int f, int count)
72 return ~s+1; 72 return ~s+1;
73} 73}
74 74
75static int vp702x_fe_read_status(struct dvb_frontend* fe, fe_status_t *status) 75static int vp702x_fe_read_status(struct dvb_frontend *fe,
76 enum fe_status *status)
76{ 77{
77 struct vp702x_fe_state *st = fe->demodulator_priv; 78 struct vp702x_fe_state *st = fe->demodulator_priv;
78 vp702x_fe_refresh_state(st); 79 vp702x_fe_refresh_state(st);
@@ -243,13 +244,15 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
243 return 0; 244 return 0;
244} 245}
245 246
246static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 247static int vp702x_fe_send_diseqc_burst(struct dvb_frontend *fe,
248 enum fe_sec_mini_cmd burst)
247{ 249{
248 deb_fe("%s\n",__func__); 250 deb_fe("%s\n",__func__);
249 return 0; 251 return 0;
250} 252}
251 253
252static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 254static int vp702x_fe_set_tone(struct dvb_frontend *fe,
255 enum fe_sec_tone_mode tone)
253{ 256{
254 struct vp702x_fe_state *st = fe->demodulator_priv; 257 struct vp702x_fe_state *st = fe->demodulator_priv;
255 struct vp702x_device_state *dst = st->d->priv; 258 struct vp702x_device_state *dst = st->d->priv;
@@ -282,8 +285,8 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
282 return 0; 285 return 0;
283} 286}
284 287
285static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t 288static int vp702x_fe_set_voltage(struct dvb_frontend *fe,
286 voltage) 289 enum fe_sec_voltage voltage)
287{ 290{
288 struct vp702x_fe_state *st = fe->demodulator_priv; 291 struct vp702x_fe_state *st = fe->demodulator_priv;
289 struct vp702x_device_state *dst = st->d->priv; 292 struct vp702x_device_state *dst = st->d->priv;
diff --git a/drivers/media/usb/dvb-usb/vp702x.c b/drivers/media/usb/dvb-usb/vp702x.c
index 22cf9f96cb9e..ee1e19e36445 100644
--- a/drivers/media/usb/dvb-usb/vp702x.c
+++ b/drivers/media/usb/dvb-usb/vp702x.c
@@ -259,12 +259,11 @@ static struct rc_map_table rc_map_vp702x_table[] = {
259/* remote control stuff (does not work with my box) */ 259/* remote control stuff (does not work with my box) */
260static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 260static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
261{ 261{
262/* remove the following return to enabled remote querying */
263#if 0
262 u8 *key; 264 u8 *key;
263 int i; 265 int i;
264 266
265/* remove the following return to enabled remote querying */
266 return 0;
267
268 key = kmalloc(10, GFP_KERNEL); 267 key = kmalloc(10, GFP_KERNEL);
269 if (!key) 268 if (!key)
270 return -ENOMEM; 269 return -ENOMEM;
@@ -286,6 +285,8 @@ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
286 break; 285 break;
287 } 286 }
288 kfree(key); 287 kfree(key);
288#endif
289
289 return 0; 290 return 0;
290} 291}
291 292
diff --git a/drivers/media/usb/dvb-usb/vp7045-fe.c b/drivers/media/usb/dvb-usb/vp7045-fe.c
index b8825b18c003..e708afc6a57f 100644
--- a/drivers/media/usb/dvb-usb/vp7045-fe.c
+++ b/drivers/media/usb/dvb-usb/vp7045-fe.c
@@ -26,7 +26,8 @@ struct vp7045_fe_state {
26 struct dvb_usb_device *d; 26 struct dvb_usb_device *d;
27}; 27};
28 28
29static int vp7045_fe_read_status(struct dvb_frontend* fe, fe_status_t *status) 29static int vp7045_fe_read_status(struct dvb_frontend *fe,
30 enum fe_status *status)
30{ 31{
31 struct vp7045_fe_state *state = fe->demodulator_priv; 32 struct vp7045_fe_state *state = fe->demodulator_priv;
32 u8 s0 = vp7045_read_reg(state->d,0x00), 33 u8 s0 = vp7045_read_reg(state->d,0x00),
diff --git a/drivers/media/usb/em28xx/em28xx-camera.c b/drivers/media/usb/em28xx/em28xx-camera.c
index a4b22c2c3ba7..ed0b3a87983e 100644
--- a/drivers/media/usb/em28xx/em28xx-camera.c
+++ b/drivers/media/usb/em28xx/em28xx-camera.c
@@ -404,7 +404,9 @@ int em28xx_init_camera(struct em28xx *dev)
404 .addr = client->addr, 404 .addr = client->addr,
405 .platform_data = &camlink, 405 .platform_data = &camlink,
406 }; 406 };
407 struct v4l2_mbus_framefmt fmt; 407 struct v4l2_subdev_format format = {
408 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
409 };
408 410
409 /* 411 /*
410 * FIXME: sensor supports resolutions up to 1600x1200, but 412 * FIXME: sensor supports resolutions up to 1600x1200, but
@@ -425,10 +427,10 @@ int em28xx_init_camera(struct em28xx *dev)
425 break; 427 break;
426 } 428 }
427 429
428 fmt.code = MEDIA_BUS_FMT_YUYV8_2X8; 430 format.format.code = MEDIA_BUS_FMT_YUYV8_2X8;
429 fmt.width = 640; 431 format.format.width = 640;
430 fmt.height = 480; 432 format.format.height = 480;
431 v4l2_subdev_call(subdev, video, s_mbus_fmt, &fmt); 433 v4l2_subdev_call(subdev, pad, set_fmt, NULL, &format);
432 434
433 /* NOTE: for UXGA=1600x1200 switch to 12MHz */ 435 /* NOTE: for UXGA=1600x1200 switch to 12MHz */
434 dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ; 436 dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ;
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index a5b22c5a240c..a38248360833 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -96,6 +96,7 @@ struct em28xx_dvb {
96 int lna_gpio; 96 int lna_gpio;
97 struct i2c_client *i2c_client_demod; 97 struct i2c_client *i2c_client_demod;
98 struct i2c_client *i2c_client_tuner; 98 struct i2c_client *i2c_client_tuner;
99 struct i2c_client *i2c_client_sec;
99}; 100};
100 101
101static inline void print_err_status(struct em28xx *dev, 102static inline void print_err_status(struct em28xx *dev,
@@ -807,16 +808,6 @@ static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
807 .gate = TDA18271_GATE_DIGITAL, 808 .gate = TDA18271_GATE_DIGITAL,
808}; 809};
809 810
810static const struct tda10071_config em28xx_tda10071_config = {
811 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
812 .tuner_i2c_addr = 0x14,
813 .i2c_wr_max = 64,
814 .ts_mode = TDA10071_TS_SERIAL,
815 .spec_inv = 0,
816 .xtal = 40444000, /* 40.444 MHz */
817 .pll_multiplier = 20,
818};
819
820static const struct a8293_config em28xx_a8293_config = { 811static const struct a8293_config em28xx_a8293_config = {
821 .i2c_addr = 0x08, /* (0x10 >> 1) */ 812 .i2c_addr = 0x08, /* (0x10 >> 1) */
822}; 813};
@@ -1331,16 +1322,60 @@ static int em28xx_dvb_init(struct em28xx *dev)
1331 &dev->i2c_adap[dev->def_i2c_bus], 1322 &dev->i2c_adap[dev->def_i2c_bus],
1332 &c3tech_duo_tda18271_config); 1323 &c3tech_duo_tda18271_config);
1333 break; 1324 break;
1334 case EM28174_BOARD_PCTV_460E: 1325 case EM28174_BOARD_PCTV_460E: {
1335 /* attach demod */ 1326 struct i2c_client *client;
1336 dvb->fe[0] = dvb_attach(tda10071_attach, 1327 struct i2c_board_info board_info;
1337 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]); 1328 struct tda10071_platform_data tda10071_pdata = {};
1329 struct a8293_platform_data a8293_pdata = {};
1330
1331 /* attach demod + tuner combo */
1332 tda10071_pdata.clk = 40444000, /* 40.444 MHz */
1333 tda10071_pdata.i2c_wr_max = 64,
1334 tda10071_pdata.ts_mode = TDA10071_TS_SERIAL,
1335 tda10071_pdata.pll_multiplier = 20,
1336 tda10071_pdata.tuner_i2c_addr = 0x14,
1337 memset(&board_info, 0, sizeof(board_info));
1338 strlcpy(board_info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1339 board_info.addr = 0x55;
1340 board_info.platform_data = &tda10071_pdata;
1341 request_module("tda10071");
1342 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1343 if (client == NULL || client->dev.driver == NULL) {
1344 result = -ENODEV;
1345 goto out_free;
1346 }
1347 if (!try_module_get(client->dev.driver->owner)) {
1348 i2c_unregister_device(client);
1349 result = -ENODEV;
1350 goto out_free;
1351 }
1352 dvb->fe[0] = tda10071_pdata.get_dvb_frontend(client);
1353 dvb->i2c_client_demod = client;
1338 1354
1339 /* attach SEC */ 1355 /* attach SEC */
1340 if (dvb->fe[0]) 1356 a8293_pdata.dvb_frontend = dvb->fe[0];
1341 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 1357 memset(&board_info, 0, sizeof(board_info));
1342 &em28xx_a8293_config); 1358 strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
1359 board_info.addr = 0x08;
1360 board_info.platform_data = &a8293_pdata;
1361 request_module("a8293");
1362 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1363 if (client == NULL || client->dev.driver == NULL) {
1364 module_put(dvb->i2c_client_demod->dev.driver->owner);
1365 i2c_unregister_device(dvb->i2c_client_demod);
1366 result = -ENODEV;
1367 goto out_free;
1368 }
1369 if (!try_module_get(client->dev.driver->owner)) {
1370 i2c_unregister_device(client);
1371 module_put(dvb->i2c_client_demod->dev.driver->owner);
1372 i2c_unregister_device(dvb->i2c_client_demod);
1373 result = -ENODEV;
1374 goto out_free;
1375 }
1376 dvb->i2c_client_sec = client;
1343 break; 1377 break;
1378 }
1344 case EM2874_BOARD_DELOCK_61959: 1379 case EM2874_BOARD_DELOCK_61959:
1345 case EM2874_BOARD_MAXMEDIA_UB425_TC: 1380 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1346 /* attach demodulator */ 1381 /* attach demodulator */
@@ -1486,64 +1521,94 @@ static int em28xx_dvb_init(struct em28xx *dev)
1486 } 1521 }
1487 } 1522 }
1488 break; 1523 break;
1489 case EM28178_BOARD_PCTV_461E: 1524 case EM28178_BOARD_PCTV_461E: {
1490 { 1525 struct i2c_client *client;
1491 /* demod I2C adapter */ 1526 struct i2c_adapter *i2c_adapter;
1492 struct i2c_adapter *i2c_adapter; 1527 struct i2c_board_info board_info;
1493 struct i2c_client *client; 1528 struct m88ds3103_platform_data m88ds3103_pdata = {};
1494 struct i2c_board_info info; 1529 struct ts2020_config ts2020_config = {};
1495 struct ts2020_config ts2020_config = { 1530 struct a8293_platform_data a8293_pdata = {};
1496 };
1497 memset(&info, 0, sizeof(struct i2c_board_info));
1498
1499 /* attach demod */
1500 dvb->fe[0] = dvb_attach(m88ds3103_attach,
1501 &pctv_461e_m88ds3103_config,
1502 &dev->i2c_adap[dev->def_i2c_bus],
1503 &i2c_adapter);
1504 if (dvb->fe[0] == NULL) {
1505 result = -ENODEV;
1506 goto out_free;
1507 }
1508
1509 /* attach tuner */
1510 ts2020_config.fe = dvb->fe[0];
1511 strlcpy(info.type, "ts2022", I2C_NAME_SIZE);
1512 info.addr = 0x60;
1513 info.platform_data = &ts2020_config;
1514 request_module("ts2020");
1515 client = i2c_new_device(i2c_adapter, &info);
1516 if (client == NULL || client->dev.driver == NULL) {
1517 dvb_frontend_detach(dvb->fe[0]);
1518 result = -ENODEV;
1519 goto out_free;
1520 }
1521
1522 if (!try_module_get(client->dev.driver->owner)) {
1523 i2c_unregister_device(client);
1524 dvb_frontend_detach(dvb->fe[0]);
1525 result = -ENODEV;
1526 goto out_free;
1527 }
1528 1531
1529 /* delegate signal strength measurement to tuner */ 1532 /* attach demod */
1530 dvb->fe[0]->ops.read_signal_strength = 1533 m88ds3103_pdata.clk = 27000000;
1531 dvb->fe[0]->ops.tuner_ops.get_rf_strength; 1534 m88ds3103_pdata.i2c_wr_max = 33;
1535 m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1536 m88ds3103_pdata.ts_clk = 16000;
1537 m88ds3103_pdata.ts_clk_pol = 1;
1538 m88ds3103_pdata.agc = 0x99;
1539 memset(&board_info, 0, sizeof(board_info));
1540 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1541 board_info.addr = 0x68;
1542 board_info.platform_data = &m88ds3103_pdata;
1543 request_module("m88ds3103");
1544 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1545 if (client == NULL || client->dev.driver == NULL) {
1546 result = -ENODEV;
1547 goto out_free;
1548 }
1549 if (!try_module_get(client->dev.driver->owner)) {
1550 i2c_unregister_device(client);
1551 result = -ENODEV;
1552 goto out_free;
1553 }
1554 dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(client);
1555 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1556 dvb->i2c_client_demod = client;
1532 1557
1533 /* attach SEC */ 1558 /* attach tuner */
1534 if (!dvb_attach(a8293_attach, dvb->fe[0], 1559 ts2020_config.fe = dvb->fe[0];
1535 &dev->i2c_adap[dev->def_i2c_bus], 1560 memset(&board_info, 0, sizeof(board_info));
1536 &em28xx_a8293_config)) { 1561 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1537 module_put(client->dev.driver->owner); 1562 board_info.addr = 0x60;
1538 i2c_unregister_device(client); 1563 board_info.platform_data = &ts2020_config;
1539 dvb_frontend_detach(dvb->fe[0]); 1564 request_module("ts2020");
1540 result = -ENODEV; 1565 client = i2c_new_device(i2c_adapter, &board_info);
1541 goto out_free; 1566 if (client == NULL || client->dev.driver == NULL) {
1542 } 1567 module_put(dvb->i2c_client_demod->dev.driver->owner);
1568 i2c_unregister_device(dvb->i2c_client_demod);
1569 result = -ENODEV;
1570 goto out_free;
1571 }
1572 if (!try_module_get(client->dev.driver->owner)) {
1573 i2c_unregister_device(client);
1574 module_put(dvb->i2c_client_demod->dev.driver->owner);
1575 i2c_unregister_device(dvb->i2c_client_demod);
1576 result = -ENODEV;
1577 goto out_free;
1578 }
1579 dvb->i2c_client_tuner = client;
1580 /* delegate signal strength measurement to tuner */
1581 dvb->fe[0]->ops.read_signal_strength =
1582 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1543 1583
1544 dvb->i2c_client_tuner = client; 1584 /* attach SEC */
1585 a8293_pdata.dvb_frontend = dvb->fe[0];
1586 memset(&board_info, 0, sizeof(board_info));
1587 strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
1588 board_info.addr = 0x08;
1589 board_info.platform_data = &a8293_pdata;
1590 request_module("a8293");
1591 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1592 if (client == NULL || client->dev.driver == NULL) {
1593 module_put(dvb->i2c_client_tuner->dev.driver->owner);
1594 i2c_unregister_device(dvb->i2c_client_tuner);
1595 module_put(dvb->i2c_client_demod->dev.driver->owner);
1596 i2c_unregister_device(dvb->i2c_client_demod);
1597 result = -ENODEV;
1598 goto out_free;
1545 } 1599 }
1600 if (!try_module_get(client->dev.driver->owner)) {
1601 i2c_unregister_device(client);
1602 module_put(dvb->i2c_client_tuner->dev.driver->owner);
1603 i2c_unregister_device(dvb->i2c_client_tuner);
1604 module_put(dvb->i2c_client_demod->dev.driver->owner);
1605 i2c_unregister_device(dvb->i2c_client_demod);
1606 result = -ENODEV;
1607 goto out_free;
1608 }
1609 dvb->i2c_client_sec = client;
1546 break; 1610 break;
1611 }
1547 case EM28178_BOARD_PCTV_292E: 1612 case EM28178_BOARD_PCTV_292E:
1548 { 1613 {
1549 struct i2c_adapter *adapter; 1614 struct i2c_adapter *adapter;
@@ -1579,6 +1644,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1579 /* attach tuner */ 1644 /* attach tuner */
1580 memset(&si2157_config, 0, sizeof(si2157_config)); 1645 memset(&si2157_config, 0, sizeof(si2157_config));
1581 si2157_config.fe = dvb->fe[0]; 1646 si2157_config.fe = dvb->fe[0];
1647 si2157_config.if_port = 1;
1582 memset(&info, 0, sizeof(struct i2c_board_info)); 1648 memset(&info, 0, sizeof(struct i2c_board_info));
1583 strlcpy(info.type, "si2157", I2C_NAME_SIZE); 1649 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1584 info.addr = 0x60; 1650 info.addr = 0x60;
@@ -1639,6 +1705,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1639 /* attach tuner */ 1705 /* attach tuner */
1640 memset(&si2157_config, 0, sizeof(si2157_config)); 1706 memset(&si2157_config, 0, sizeof(si2157_config));
1641 si2157_config.fe = dvb->fe[0]; 1707 si2157_config.fe = dvb->fe[0];
1708 si2157_config.if_port = 0;
1642 memset(&info, 0, sizeof(struct i2c_board_info)); 1709 memset(&info, 0, sizeof(struct i2c_board_info));
1643 strlcpy(info.type, "si2146", I2C_NAME_SIZE); 1710 strlcpy(info.type, "si2146", I2C_NAME_SIZE);
1644 info.addr = 0x60; 1711 info.addr = 0x60;
@@ -1727,7 +1794,6 @@ static int em28xx_dvb_fini(struct em28xx *dev)
1727 em28xx_info("Closing DVB extension\n"); 1794 em28xx_info("Closing DVB extension\n");
1728 1795
1729 dvb = dev->dvb; 1796 dvb = dev->dvb;
1730 client = dvb->i2c_client_tuner;
1731 1797
1732 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE); 1798 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
1733 1799
@@ -1744,7 +1810,15 @@ static int em28xx_dvb_fini(struct em28xx *dev)
1744 } 1810 }
1745 } 1811 }
1746 1812
1813 /* remove I2C SEC */
1814 client = dvb->i2c_client_sec;
1815 if (client) {
1816 module_put(client->dev.driver->owner);
1817 i2c_unregister_device(client);
1818 }
1819
1747 /* remove I2C tuner */ 1820 /* remove I2C tuner */
1821 client = dvb->i2c_client_tuner;
1748 if (client) { 1822 if (client) {
1749 module_put(client->dev.driver->owner); 1823 module_put(client->dev.driver->owner);
1750 i2c_unregister_device(client); 1824 i2c_unregister_device(client);
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 14eba9c65de3..4397ce5e78df 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -839,7 +839,6 @@ static int get_ressource(enum v4l2_buf_type f_type)
839 return EM28XX_RESOURCE_VBI; 839 return EM28XX_RESOURCE_VBI;
840 default: 840 default:
841 BUG(); 841 BUG();
842 return 0;
843 } 842 }
844} 843}
845 844
diff --git a/drivers/media/usb/go7007/go7007-driver.c b/drivers/media/usb/go7007/go7007-driver.c
index 95cffb771a62..0ab81ec8897a 100644
--- a/drivers/media/usb/go7007/go7007-driver.c
+++ b/drivers/media/usb/go7007/go7007-driver.c
@@ -446,7 +446,7 @@ static void go7007_motion_regions(struct go7007 *go, struct go7007_buffer *vb)
446 */ 446 */
447static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buffer *vb) 447static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buffer *vb)
448{ 448{
449 u32 *bytesused = &vb->vb.v4l2_planes[0].bytesused; 449 u32 *bytesused;
450 struct go7007_buffer *vb_tmp = NULL; 450 struct go7007_buffer *vb_tmp = NULL;
451 451
452 if (vb == NULL) { 452 if (vb == NULL) {
@@ -458,6 +458,7 @@ static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buf
458 go->next_seq++; 458 go->next_seq++;
459 return vb; 459 return vb;
460 } 460 }
461 bytesused = &vb->vb.v4l2_planes[0].bytesused;
461 462
462 vb->vb.v4l2_buf.sequence = go->next_seq++; 463 vb->vb.v4l2_buf.sequence = go->next_seq++;
463 if (vb->modet_active && *bytesused + 216 < GO7007_BUF_SIZE) 464 if (vb->modet_active && *bytesused + 216 < GO7007_BUF_SIZE)
diff --git a/drivers/media/usb/go7007/go7007-usb.c b/drivers/media/usb/go7007/go7007-usb.c
index 3f986e1178ce..4857c467e76c 100644
--- a/drivers/media/usb/go7007/go7007-usb.c
+++ b/drivers/media/usb/go7007/go7007-usb.c
@@ -338,6 +338,7 @@ static const struct go7007_usb_board board_matrix_revolution = {
338 }, 338 },
339}; 339};
340 340
341#if 0
341static const struct go7007_usb_board board_lifeview_lr192 = { 342static const struct go7007_usb_board board_lifeview_lr192 = {
342 .flags = GO7007_USB_EZUSB, 343 .flags = GO7007_USB_EZUSB,
343 .main_info = { 344 .main_info = {
@@ -364,6 +365,7 @@ static const struct go7007_usb_board board_lifeview_lr192 = {
364 }, 365 },
365 }, 366 },
366}; 367};
368#endif
367 369
368static const struct go7007_usb_board board_endura = { 370static const struct go7007_usb_board board_endura = {
369 .flags = 0, 371 .flags = 0,
@@ -1096,8 +1098,10 @@ static int go7007_usb_probe(struct usb_interface *intf,
1096 case GO7007_BOARDID_LIFEVIEW_LR192: 1098 case GO7007_BOARDID_LIFEVIEW_LR192:
1097 dev_err(&intf->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n"); 1099 dev_err(&intf->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1098 return -ENODEV; 1100 return -ENODEV;
1101#if 0
1099 name = "Lifeview TV Walker Ultra"; 1102 name = "Lifeview TV Walker Ultra";
1100 board = &board_lifeview_lr192; 1103 board = &board_lifeview_lr192;
1104#endif
1101 break; 1105 break;
1102 case GO7007_BOARDID_SENSORAY_2250: 1106 case GO7007_BOARDID_SENSORAY_2250:
1103 dev_info(&intf->dev, "Sensoray 2250 found\n"); 1107 dev_info(&intf->dev, "Sensoray 2250 found\n");
diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
index d6bf982efa42..c57207e268c3 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -250,15 +250,17 @@ static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
250 go->encoder_v_offset = go->board_info->sensor_v_offset; 250 go->encoder_v_offset = go->board_info->sensor_v_offset;
251 251
252 if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) { 252 if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) {
253 struct v4l2_mbus_framefmt mbus_fmt; 253 struct v4l2_subdev_format format = {
254 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
255 };
254 256
255 mbus_fmt.code = MEDIA_BUS_FMT_FIXED; 257 format.format.code = MEDIA_BUS_FMT_FIXED;
256 mbus_fmt.width = fmt ? fmt->fmt.pix.width : width; 258 format.format.width = fmt ? fmt->fmt.pix.width : width;
257 mbus_fmt.height = height; 259 format.format.height = height;
258 go->encoder_h_halve = 0; 260 go->encoder_h_halve = 0;
259 go->encoder_v_halve = 0; 261 go->encoder_v_halve = 0;
260 go->encoder_subsample = 0; 262 go->encoder_subsample = 0;
261 call_all(&go->v4l2_dev, video, s_mbus_fmt, &mbus_fmt); 263 call_all(&go->v4l2_dev, pad, set_fmt, NULL, &format);
262 } else { 264 } else {
263 if (width <= sensor_width / 4) { 265 if (width <= sensor_width / 4) {
264 go->encoder_h_halve = 1; 266 go->encoder_h_halve = 1;
diff --git a/drivers/media/usb/go7007/s2250-board.c b/drivers/media/usb/go7007/s2250-board.c
index bb846680bcd4..5c2a49534d2b 100644
--- a/drivers/media/usb/go7007/s2250-board.c
+++ b/drivers/media/usb/go7007/s2250-board.c
@@ -405,12 +405,20 @@ static int s2250_s_ctrl(struct v4l2_ctrl *ctrl)
405 return 0; 405 return 0;
406} 406}
407 407
408static int s2250_s_mbus_fmt(struct v4l2_subdev *sd, 408static int s2250_set_fmt(struct v4l2_subdev *sd,
409 struct v4l2_mbus_framefmt *fmt) 409 struct v4l2_subdev_pad_config *cfg,
410 struct v4l2_subdev_format *format)
410{ 411{
412 struct v4l2_mbus_framefmt *fmt = &format->format;
411 struct s2250 *state = to_state(sd); 413 struct s2250 *state = to_state(sd);
412 struct i2c_client *client = v4l2_get_subdevdata(sd); 414 struct i2c_client *client = v4l2_get_subdevdata(sd);
413 415
416 if (format->pad)
417 return -EINVAL;
418
419 if (format->which == V4L2_SUBDEV_FORMAT_TRY)
420 return 0;
421
414 if (fmt->height < 640) { 422 if (fmt->height < 640) {
415 write_reg_fp(client, 0x12b, state->reg12b_val | 0x400); 423 write_reg_fp(client, 0x12b, state->reg12b_val | 0x400);
416 write_reg_fp(client, 0x140, 0x060); 424 write_reg_fp(client, 0x140, 0x060);
@@ -479,13 +487,17 @@ static const struct v4l2_subdev_audio_ops s2250_audio_ops = {
479static const struct v4l2_subdev_video_ops s2250_video_ops = { 487static const struct v4l2_subdev_video_ops s2250_video_ops = {
480 .s_std = s2250_s_std, 488 .s_std = s2250_s_std,
481 .s_routing = s2250_s_video_routing, 489 .s_routing = s2250_s_video_routing,
482 .s_mbus_fmt = s2250_s_mbus_fmt, 490};
491
492static const struct v4l2_subdev_pad_ops s2250_pad_ops = {
493 .set_fmt = s2250_set_fmt,
483}; 494};
484 495
485static const struct v4l2_subdev_ops s2250_ops = { 496static const struct v4l2_subdev_ops s2250_ops = {
486 .core = &s2250_core_ops, 497 .core = &s2250_core_ops,
487 .audio = &s2250_audio_ops, 498 .audio = &s2250_audio_ops,
488 .video = &s2250_video_ops, 499 .video = &s2250_video_ops,
500 .pad = &s2250_pad_ops,
489}; 501};
490 502
491/* --------------------------------------------------------------------------*/ 503/* --------------------------------------------------------------------------*/
diff --git a/drivers/media/usb/gspca/benq.c b/drivers/media/usb/gspca/benq.c
index 05f406deae13..790baed33963 100644
--- a/drivers/media/usb/gspca/benq.c
+++ b/drivers/media/usb/gspca/benq.c
@@ -236,8 +236,8 @@ static void sd_isoc_irq(struct urb *urb)
236 } 236 }
237 data = (u8 *) urb->transfer_buffer 237 data = (u8 *) urb->transfer_buffer
238 + urb->iso_frame_desc[i].offset; 238 + urb->iso_frame_desc[i].offset;
239 gspca_frame_add(gspca_dev, INTER_PACKET, 239 gspca_frame_add(gspca_dev, INTER_PACKET,
240 data, SD_PKT_SZ); 240 data, SD_PKT_SZ);
241 } 241 }
242 242
243 /* resubmit the URBs */ 243 /* resubmit the URBs */
diff --git a/drivers/media/usb/gspca/sn9c2028.c b/drivers/media/usb/gspca/sn9c2028.c
index 39b6b2e02963..c75b7388a85c 100644
--- a/drivers/media/usb/gspca/sn9c2028.c
+++ b/drivers/media/usb/gspca/sn9c2028.c
@@ -33,6 +33,16 @@ struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */ 33 struct gspca_dev gspca_dev; /* !! must be the first item */
34 u8 sof_read; 34 u8 sof_read;
35 u16 model; 35 u16 model;
36
37#define MIN_AVG_LUM 8500
38#define MAX_AVG_LUM 10000
39 int avg_lum;
40 u8 avg_lum_l;
41
42 struct { /* autogain and gain control cluster */
43 struct v4l2_ctrl *autogain;
44 struct v4l2_ctrl *gain;
45 };
36}; 46};
37 47
38struct init_command { 48struct init_command {
@@ -128,7 +138,7 @@ static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command)
128 status = -1; 138 status = -1;
129 for (i = 0; i < 256 && status < 2; i++) 139 for (i = 0; i < 256 && status < 2; i++)
130 status = sn9c2028_read1(gspca_dev); 140 status = sn9c2028_read1(gspca_dev);
131 if (status != 2) { 141 if (status < 0) {
132 pr_err("long command status read error %d\n", status); 142 pr_err("long command status read error %d\n", status);
133 return (status < 0) ? status : -EIO; 143 return (status < 0) ? status : -EIO;
134 } 144 }
@@ -178,6 +188,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
178 case 0x7005: 188 case 0x7005:
179 PDEBUG(D_PROBE, "Genius Smart 300 camera"); 189 PDEBUG(D_PROBE, "Genius Smart 300 camera");
180 break; 190 break;
191 case 0x7003:
192 PDEBUG(D_PROBE, "Genius Videocam Live v2");
193 break;
181 case 0x8000: 194 case 0x8000:
182 PDEBUG(D_PROBE, "DC31VC"); 195 PDEBUG(D_PROBE, "DC31VC");
183 break; 196 break;
@@ -248,6 +261,78 @@ static int run_start_commands(struct gspca_dev *gspca_dev,
248 return 0; 261 return 0;
249} 262}
250 263
264static void set_gain(struct gspca_dev *gspca_dev, s32 g)
265{
266 struct sd *sd = (struct sd *) gspca_dev;
267
268 struct init_command genius_vcam_live_gain_cmds[] = {
269 {{0x1d, 0x25, 0x10 /* This byte is gain */,
270 0x20, 0xab, 0x00}, 0},
271 };
272 if (!gspca_dev->streaming)
273 return;
274
275 switch (sd->model) {
276 case 0x7003:
277 genius_vcam_live_gain_cmds[0].instruction[2] = g;
278 run_start_commands(gspca_dev, genius_vcam_live_gain_cmds,
279 ARRAY_SIZE(genius_vcam_live_gain_cmds));
280 break;
281 default:
282 break;
283 }
284}
285
286static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
287{
288 struct gspca_dev *gspca_dev =
289 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
290 struct sd *sd = (struct sd *)gspca_dev;
291
292 gspca_dev->usb_err = 0;
293
294 if (!gspca_dev->streaming)
295 return 0;
296
297 switch (ctrl->id) {
298 /* standalone gain control */
299 case V4L2_CID_GAIN:
300 set_gain(gspca_dev, ctrl->val);
301 break;
302 /* autogain */
303 case V4L2_CID_AUTOGAIN:
304 set_gain(gspca_dev, sd->gain->val);
305 break;
306 }
307 return gspca_dev->usb_err;
308}
309
310static const struct v4l2_ctrl_ops sd_ctrl_ops = {
311 .s_ctrl = sd_s_ctrl,
312};
313
314
315static int sd_init_controls(struct gspca_dev *gspca_dev)
316{
317 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
318 struct sd *sd = (struct sd *)gspca_dev;
319
320 gspca_dev->vdev.ctrl_handler = hdl;
321 v4l2_ctrl_handler_init(hdl, 2);
322
323 switch (sd->model) {
324 case 0x7003:
325 sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
326 V4L2_CID_GAIN, 0, 20, 1, 0);
327 sd->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
328 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
329 break;
330 default:
331 break;
332 }
333
334 return 0;
335}
251static int start_spy_cam(struct gspca_dev *gspca_dev) 336static int start_spy_cam(struct gspca_dev *gspca_dev)
252{ 337{
253 struct init_command spy_start_commands[] = { 338 struct init_command spy_start_commands[] = {
@@ -530,6 +615,119 @@ static int start_genius_cam(struct gspca_dev *gspca_dev)
530 ARRAY_SIZE(genius_start_commands)); 615 ARRAY_SIZE(genius_start_commands));
531} 616}
532 617
618static int start_genius_videocam_live(struct gspca_dev *gspca_dev)
619{
620 int r;
621 struct sd *sd = (struct sd *) gspca_dev;
622 struct init_command genius_vcam_live_start_commands[] = {
623 {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 0},
624 {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
625 {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
626 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
627 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
628
629 {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
630 {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
631 {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
632 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
633 {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
634 {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
635 {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
636 {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
637 {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
638 {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
639 {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
640 {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
641 {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
642 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
643 {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
644 {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
645 {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
646 {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
647 {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
648 {{0x1c, 0x20, 0x00, 0x2d, 0x00, 0x00}, 4},
649 {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
650 {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
651 {{0x13, 0x22, 0x01, 0x00, 0x00, 0x00}, 4},
652 {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
653 {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
654 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
655 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
656 {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
657 {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
658 {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
659 {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
660 {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
661 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
662 {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
663 {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
664 {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
665 {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
666 {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
667 {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
668 {{0x11, 0x01, 0x04, 0x00, 0x00, 0x00}, 4},
669 {{0x11, 0x02, 0x92, 0x00, 0x00, 0x00}, 4},
670 {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
671 {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
672 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
673 {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
674 {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
675 {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
676 {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
677 {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
678 {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
679 {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
680 {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
681 {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
682 {{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
683 {{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
684 {{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
685 {{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
686 {{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
687 {{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
688 {{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
689 {{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
690 {{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
691 {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
692 {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
693 {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
694 {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
695 {{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
696 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
697 {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
698 {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
699 {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
700 {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
701 {{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
702 {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
703 {{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
704 {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
705 {{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
706 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
707 {{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
708 {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
709 {{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
710 {{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
711 {{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
712 {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
713 {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0},
714 /* Camera should start to capture now. */
715 {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 0},
716 {{0x1b, 0x32, 0x26, 0x00, 0x00, 0x00}, 0},
717 {{0x1d, 0x25, 0x10, 0x20, 0xab, 0x00}, 0},
718 };
719
720 r = run_start_commands(gspca_dev, genius_vcam_live_start_commands,
721 ARRAY_SIZE(genius_vcam_live_start_commands));
722 if (r < 0)
723 return r;
724
725 if (sd->gain)
726 set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd->gain));
727
728 return r;
729}
730
533static int start_vivitar_cam(struct gspca_dev *gspca_dev) 731static int start_vivitar_cam(struct gspca_dev *gspca_dev)
534{ 732{
535 struct init_command vivitar_start_commands[] = { 733 struct init_command vivitar_start_commands[] = {
@@ -623,6 +821,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
623 case 0x7005: 821 case 0x7005:
624 err_code = start_genius_cam(gspca_dev); 822 err_code = start_genius_cam(gspca_dev);
625 break; 823 break;
824 case 0x7003:
825 err_code = start_genius_videocam_live(gspca_dev);
826 break;
626 case 0x8001: 827 case 0x8001:
627 err_code = start_spy_cam(gspca_dev); 828 err_code = start_spy_cam(gspca_dev);
628 break; 829 break;
@@ -640,6 +841,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
640 return -ENXIO; 841 return -ENXIO;
641 } 842 }
642 843
844 sd->avg_lum = -1;
845
643 return err_code; 846 return err_code;
644} 847}
645 848
@@ -659,6 +862,39 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
659 PERR("Camera Stop command failed"); 862 PERR("Camera Stop command failed");
660} 863}
661 864
865static void do_autogain(struct gspca_dev *gspca_dev, int avg_lum)
866{
867 struct sd *sd = (struct sd *) gspca_dev;
868 s32 cur_gain = v4l2_ctrl_g_ctrl(sd->gain);
869
870 if (avg_lum == -1)
871 return;
872
873 if (avg_lum < MIN_AVG_LUM) {
874 if (cur_gain == sd->gain->maximum)
875 return;
876 cur_gain++;
877 v4l2_ctrl_s_ctrl(sd->gain, cur_gain);
878 }
879 if (avg_lum > MAX_AVG_LUM) {
880 if (cur_gain == sd->gain->minimum)
881 return;
882 cur_gain--;
883 v4l2_ctrl_s_ctrl(sd->gain, cur_gain);
884 }
885
886}
887
888static void sd_dqcallback(struct gspca_dev *gspca_dev)
889{
890 struct sd *sd = (struct sd *) gspca_dev;
891
892 if (sd->autogain == NULL || !v4l2_ctrl_g_ctrl(sd->autogain))
893 return;
894
895 do_autogain(gspca_dev, sd->avg_lum);
896}
897
662/* Include sn9c2028 sof detection functions */ 898/* Include sn9c2028 sof detection functions */
663#include "sn9c2028.h" 899#include "sn9c2028.h"
664 900
@@ -693,14 +929,17 @@ static const struct sd_desc sd_desc = {
693 .name = MODULE_NAME, 929 .name = MODULE_NAME,
694 .config = sd_config, 930 .config = sd_config,
695 .init = sd_init, 931 .init = sd_init,
932 .init_controls = sd_init_controls,
696 .start = sd_start, 933 .start = sd_start,
697 .stopN = sd_stopN, 934 .stopN = sd_stopN,
935 .dq_callback = sd_dqcallback,
698 .pkt_scan = sd_pkt_scan, 936 .pkt_scan = sd_pkt_scan,
699}; 937};
700 938
701/* -- module initialisation -- */ 939/* -- module initialisation -- */
702static const struct usb_device_id device_table[] = { 940static const struct usb_device_id device_table[] = {
703 {USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */ 941 {USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */
942 {USB_DEVICE(0x0458, 0x7003)}, /* Genius Videocam Live v2 */
704 /* The Genius Smart is untested. I can't find an owner ! */ 943 /* The Genius Smart is untested. I can't find an owner ! */
705 /* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */ 944 /* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */
706 {USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */ 945 {USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */
diff --git a/drivers/media/usb/gspca/sn9c2028.h b/drivers/media/usb/gspca/sn9c2028.h
index 8fd1d3e05665..f85bc106bc52 100644
--- a/drivers/media/usb/gspca/sn9c2028.h
+++ b/drivers/media/usb/gspca/sn9c2028.h
@@ -21,8 +21,15 @@
21 * 21 *
22 */ 22 */
23 23
24static const unsigned char sn9c2028_sof_marker[5] = 24static const unsigned char sn9c2028_sof_marker[] = {
25 { 0xff, 0xff, 0x00, 0xc4, 0xc4 }; 25 0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96,
26 0x00,
27 0x00, /* seq */
28 0x00,
29 0x00,
30 0x00, /* avg luminance lower 8 bit */
31 0x00, /* avg luminance higher 8 bit */
32};
26 33
27static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev, 34static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
28 unsigned char *m, int len) 35 unsigned char *m, int len)
@@ -32,8 +39,13 @@ static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
32 39
33 /* Search for the SOF marker (fixed part) in the header */ 40 /* Search for the SOF marker (fixed part) in the header */
34 for (i = 0; i < len; i++) { 41 for (i = 0; i < len; i++) {
35 if (m[i] == sn9c2028_sof_marker[sd->sof_read]) { 42 if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) ||
43 (sd->sof_read > 5)) {
36 sd->sof_read++; 44 sd->sof_read++;
45 if (sd->sof_read == 11)
46 sd->avg_lum_l = m[i];
47 if (sd->sof_read == 12)
48 sd->avg_lum = (m[i] << 8) + sd->avg_lum_l;
37 if (sd->sof_read == sizeof(sn9c2028_sof_marker)) { 49 if (sd->sof_read == sizeof(sn9c2028_sof_marker)) {
38 PDEBUG(D_FRAM, 50 PDEBUG(D_FRAM,
39 "SOF found, bytes to analyze: %u." 51 "SOF found, bytes to analyze: %u."
diff --git a/drivers/media/usb/gspca/sonixj.c b/drivers/media/usb/gspca/sonixj.c
index c69b45d7cfbf..fd1c8706d86a 100644
--- a/drivers/media/usb/gspca/sonixj.c
+++ b/drivers/media/usb/gspca/sonixj.c
@@ -1789,7 +1789,7 @@ static u32 expo_adjust(struct gspca_dev *gspca_dev,
1789 1789
1790 if (expo > 0x03ff) 1790 if (expo > 0x03ff)
1791 expo = 0x03ff; 1791 expo = 0x03ff;
1792 if (expo < 0x0001) 1792 if (expo < 0x0001)
1793 expo = 0x0001; 1793 expo = 0x0001;
1794 gainOm[3] = expo >> 2; 1794 gainOm[3] = expo >> 2;
1795 i2c_w8(gspca_dev, gainOm); 1795 i2c_w8(gspca_dev, gainOm);
diff --git a/drivers/media/usb/gspca/stk014.c b/drivers/media/usb/gspca/stk014.c
index b0c70fea760b..d324d001e114 100644
--- a/drivers/media/usb/gspca/stk014.c
+++ b/drivers/media/usb/gspca/stk014.c
@@ -276,7 +276,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
276 gspca_dev->usb_err = ret; 276 gspca_dev->usb_err = ret;
277 goto out; 277 goto out;
278 } 278 }
279 reg_r(gspca_dev, 0x0630); 279 reg_r(gspca_dev, 0x0630);
280 rcv_val(gspca_dev, 0x000020); /* << (value ff ff ff ff) */ 280 rcv_val(gspca_dev, 0x000020); /* << (value ff ff ff ff) */
281 reg_r(gspca_dev, 0x0650); 281 reg_r(gspca_dev, 0x0650);
282 snd_val(gspca_dev, 0x000020, 0xffffffff); 282 snd_val(gspca_dev, 0x000020, 0xffffffff);
diff --git a/drivers/media/usb/gspca/xirlink_cit.c b/drivers/media/usb/gspca/xirlink_cit.c
index a41aa7817c54..d5ed9d36ce25 100644
--- a/drivers/media/usb/gspca/xirlink_cit.c
+++ b/drivers/media/usb/gspca/xirlink_cit.c
@@ -1772,7 +1772,8 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1772 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */ 1772 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1773 sd->sof_len = 2; 1773 sd->sof_len = 2;
1774 break; 1774 break;
1775 /* case VIDEOSIZE_352x240: */ 1775#if 0
1776 case VIDEOSIZE_352x240:
1776 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */ 1777 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1777 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1778 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1778 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */ 1779 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
@@ -1780,6 +1781,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1780 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */ 1781 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1781 sd->sof_len = 2; 1782 sd->sof_len = 2;
1782 break; 1783 break;
1784#endif
1783 case 352: /* 352x288 */ 1785 case 352: /* 352x288 */
1784 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */ 1786 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1785 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1787 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
@@ -1853,13 +1855,15 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1853 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */ 1855 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
1854 clock_div = 8; 1856 clock_div = 8;
1855 break; 1857 break;
1856 /* case VIDEOSIZE_352x240: */ 1858#if 0
1859 case VIDEOSIZE_352x240:
1857 /* This mode doesn't work as Windows programs it; changed to work */ 1860 /* This mode doesn't work as Windows programs it; changed to work */
1858 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */ 1861 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
1859 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */ 1862 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
1860 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */ 1863 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
1861 clock_div = 10; 1864 clock_div = 10;
1862 break; 1865 break;
1866#endif
1863 case 352: /* 352x288 */ 1867 case 352: /* 352x288 */
1864 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003); 1868 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
1865 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */ 1869 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
@@ -1906,9 +1910,11 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1906 case 320: /* 320x240 */ 1910 case 320: /* 320x240 */
1907 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044); 1911 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
1908 break; 1912 break;
1909 /* case VIDEOSIZE_352x240: */ 1913#if 0
1914 case VIDEOSIZE_352x240:
1910 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046); 1915 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
1911 break; 1916 break;
1917#endif
1912 case 352: /* 352x288 */ 1918 case 352: /* 352x288 */
1913 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048); 1919 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
1914 break; 1920 break;
diff --git a/drivers/media/usb/gspca/zc3xx.c b/drivers/media/usb/gspca/zc3xx.c
index d3e1b6d8bf49..c5d8ee6fa3c7 100644
--- a/drivers/media/usb/gspca/zc3xx.c
+++ b/drivers/media/usb/gspca/zc3xx.c
@@ -5942,23 +5942,23 @@ static void transfer_update(struct work_struct *work)
5942 reg07 = 0; 5942 reg07 = 0;
5943 5943
5944 good = 0; 5944 good = 0;
5945 for (;;) { 5945 while (1) {
5946 msleep(100); 5946 msleep(100);
5947 5947
5948 /* To protect gspca_dev->usb_buf and gspca_dev->usb_err */ 5948 /* To protect gspca_dev->usb_buf and gspca_dev->usb_err */
5949 mutex_lock(&gspca_dev->usb_lock); 5949 mutex_lock(&gspca_dev->usb_lock);
5950#ifdef CONFIG_PM 5950#ifdef CONFIG_PM
5951 if (gspca_dev->frozen) 5951 if (gspca_dev->frozen)
5952 goto err; 5952 break;
5953#endif 5953#endif
5954 if (!gspca_dev->present || !gspca_dev->streaming) 5954 if (!gspca_dev->present || !gspca_dev->streaming)
5955 goto err; 5955 break;
5956 5956
5957 /* Bit 0 of register 11 indicates FIFO overflow */ 5957 /* Bit 0 of register 11 indicates FIFO overflow */
5958 gspca_dev->usb_err = 0; 5958 gspca_dev->usb_err = 0;
5959 reg11 = reg_r(gspca_dev, 0x0011); 5959 reg11 = reg_r(gspca_dev, 0x0011);
5960 if (gspca_dev->usb_err) 5960 if (gspca_dev->usb_err)
5961 goto err; 5961 break;
5962 5962
5963 change = reg11 & 0x01; 5963 change = reg11 & 0x01;
5964 if (change) { /* overflow */ 5964 if (change) { /* overflow */
@@ -5987,12 +5987,12 @@ static void transfer_update(struct work_struct *work)
5987 gspca_dev->usb_err = 0; 5987 gspca_dev->usb_err = 0;
5988 reg_w(gspca_dev, reg07, 0x0007); 5988 reg_w(gspca_dev, reg07, 0x0007);
5989 if (gspca_dev->usb_err) 5989 if (gspca_dev->usb_err)
5990 goto err; 5990 break;
5991 } 5991 }
5992 mutex_unlock(&gspca_dev->usb_lock); 5992 mutex_unlock(&gspca_dev->usb_lock);
5993 } 5993 }
5994 return; 5994
5995err: 5995 /* Something went wrong. Unlock and return */
5996 mutex_unlock(&gspca_dev->usb_lock); 5996 mutex_unlock(&gspca_dev->usb_lock);
5997} 5997}
5998 5998
@@ -6360,7 +6360,7 @@ static int zcxx_s_ctrl(struct v4l2_ctrl *ctrl)
6360 if (ctrl->val <= jpeg_qual[i]) 6360 if (ctrl->val <= jpeg_qual[i])
6361 break; 6361 break;
6362 } 6362 }
6363 if (i > 0 && i == qual && ctrl->val < jpeg_qual[i]) 6363 if (i == ARRAY_SIZE(jpeg_qual) || (i > 0 && i == qual && ctrl->val < jpeg_qual[i]))
6364 i--; 6364 i--;
6365 6365
6366 /* With high quality settings we need max bandwidth */ 6366 /* With high quality settings we need max bandwidth */
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index efc761c78f72..3f276d921cca 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -1,4 +1,5 @@
1/* 1/*
2 * Mirics MSi2500 driver
2 * Mirics MSi3101 SDR Dongle driver 3 * Mirics MSi3101 SDR Dongle driver
3 * 4 *
4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 5 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
@@ -13,10 +14,6 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
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 * That driver is somehow based of pwc driver: 17 * That driver is somehow based of pwc driver:
21 * (C) 1999-2004 Nemosoft Unv. 18 * (C) 1999-2004 Nemosoft Unv.
22 * (C) 2004-2006 Luc Saillard (luc@saillard.org) 19 * (C) 2004-2006 Luc Saillard (luc@saillard.org)
@@ -119,7 +116,7 @@ struct msi2500_frame_buf {
119 struct list_head list; 116 struct list_head list;
120}; 117};
121 118
122struct msi2500_state { 119struct msi2500_dev {
123 struct device *dev; 120 struct device *dev;
124 struct video_device vdev; 121 struct video_device vdev;
125 struct v4l2_device v4l2_dev; 122 struct v4l2_device v4l2_dev;
@@ -158,19 +155,19 @@ struct msi2500_state {
158 155
159/* Private functions */ 156/* Private functions */
160static struct msi2500_frame_buf *msi2500_get_next_fill_buf( 157static struct msi2500_frame_buf *msi2500_get_next_fill_buf(
161 struct msi2500_state *s) 158 struct msi2500_dev *dev)
162{ 159{
163 unsigned long flags; 160 unsigned long flags;
164 struct msi2500_frame_buf *buf = NULL; 161 struct msi2500_frame_buf *buf = NULL;
165 162
166 spin_lock_irqsave(&s->queued_bufs_lock, flags); 163 spin_lock_irqsave(&dev->queued_bufs_lock, flags);
167 if (list_empty(&s->queued_bufs)) 164 if (list_empty(&dev->queued_bufs))
168 goto leave; 165 goto leave;
169 166
170 buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf, list); 167 buf = list_entry(dev->queued_bufs.next, struct msi2500_frame_buf, list);
171 list_del(&buf->list); 168 list_del(&buf->list);
172leave: 169leave:
173 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 170 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
174 return buf; 171 return buf;
175} 172}
176 173
@@ -256,8 +253,8 @@ leave:
256 * signed 14-bit sample 253 * signed 14-bit sample
257 */ 254 */
258 255
259static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src, 256static int msi2500_convert_stream(struct msi2500_dev *dev, u8 *dst, u8 *src,
260 unsigned int src_len) 257 unsigned int src_len)
261{ 258{
262 unsigned int i, j, transactions, dst_len = 0; 259 unsigned int i, j, transactions, dst_len = 0;
263 u32 sample[3]; 260 u32 sample[3];
@@ -268,26 +265,27 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
268 for (i = 0; i < transactions; i++) { 265 for (i = 0; i < transactions; i++) {
269 sample[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | 266 sample[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 |
270 src[0] << 0; 267 src[0] << 0;
271 if (i == 0 && s->next_sample != sample[0]) { 268 if (i == 0 && dev->next_sample != sample[0]) {
272 dev_dbg_ratelimited(s->dev, 269 dev_dbg_ratelimited(dev->dev,
273 "%d samples lost, %d %08x:%08x\n", 270 "%d samples lost, %d %08x:%08x\n",
274 sample[0] - s->next_sample, 271 sample[0] - dev->next_sample,
275 src_len, s->next_sample, sample[0]); 272 src_len, dev->next_sample,
273 sample[0]);
276 } 274 }
277 275
278 /* 276 /*
279 * Dump all unknown 'garbage' data - maybe we will discover 277 * Dump all unknown 'garbage' data - maybe we will discover
280 * someday if there is something rational... 278 * someday if there is something rational...
281 */ 279 */
282 dev_dbg_ratelimited(s->dev, "%*ph\n", 12, &src[4]); 280 dev_dbg_ratelimited(dev->dev, "%*ph\n", 12, &src[4]);
283 281
284 src += 16; /* skip header */ 282 src += 16; /* skip header */
285 283
286 switch (s->pixelformat) { 284 switch (dev->pixelformat) {
287 case V4L2_SDR_FMT_CU8: /* 504 x IQ samples */ 285 case V4L2_SDR_FMT_CU8: /* 504 x IQ samples */
288 { 286 {
289 s8 *s8src = (s8 *) src; 287 s8 *s8src = (s8 *)src;
290 u8 *u8dst = (u8 *) dst; 288 u8 *u8dst = (u8 *)dst;
291 289
292 for (j = 0; j < 1008; j++) 290 for (j = 0; j < 1008; j++)
293 *u8dst++ = *s8src++ + 128; 291 *u8dst++ = *s8src++ + 128;
@@ -295,13 +293,13 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
295 src += 1008; 293 src += 1008;
296 dst += 1008; 294 dst += 1008;
297 dst_len += 1008; 295 dst_len += 1008;
298 s->next_sample = sample[i] + 504; 296 dev->next_sample = sample[i] + 504;
299 break; 297 break;
300 } 298 }
301 case V4L2_SDR_FMT_CU16LE: /* 252 x IQ samples */ 299 case V4L2_SDR_FMT_CU16LE: /* 252 x IQ samples */
302 { 300 {
303 s16 *s16src = (s16 *) src; 301 s16 *s16src = (s16 *)src;
304 u16 *u16dst = (u16 *) dst; 302 u16 *u16dst = (u16 *)dst;
305 struct {signed int x:14; } se; /* sign extension */ 303 struct {signed int x:14; } se; /* sign extension */
306 unsigned int utmp; 304 unsigned int utmp;
307 305
@@ -317,38 +315,38 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
317 src += 1008; 315 src += 1008;
318 dst += 1008; 316 dst += 1008;
319 dst_len += 1008; 317 dst_len += 1008;
320 s->next_sample = sample[i] + 252; 318 dev->next_sample = sample[i] + 252;
321 break; 319 break;
322 } 320 }
323 case MSI2500_PIX_FMT_SDR_MSI2500_384: /* 384 x IQ samples */ 321 case MSI2500_PIX_FMT_SDR_MSI2500_384: /* 384 x IQ samples */
324 /* Dump unknown 'garbage' data */ 322 /* Dump unknown 'garbage' data */
325 dev_dbg_ratelimited(s->dev, "%*ph\n", 24, &src[1000]); 323 dev_dbg_ratelimited(dev->dev, "%*ph\n", 24, &src[1000]);
326 memcpy(dst, src, 984); 324 memcpy(dst, src, 984);
327 src += 984 + 24; 325 src += 984 + 24;
328 dst += 984; 326 dst += 984;
329 dst_len += 984; 327 dst_len += 984;
330 s->next_sample = sample[i] + 384; 328 dev->next_sample = sample[i] + 384;
331 break; 329 break;
332 case V4L2_SDR_FMT_CS8: /* 504 x IQ samples */ 330 case V4L2_SDR_FMT_CS8: /* 504 x IQ samples */
333 memcpy(dst, src, 1008); 331 memcpy(dst, src, 1008);
334 src += 1008; 332 src += 1008;
335 dst += 1008; 333 dst += 1008;
336 dst_len += 1008; 334 dst_len += 1008;
337 s->next_sample = sample[i] + 504; 335 dev->next_sample = sample[i] + 504;
338 break; 336 break;
339 case MSI2500_PIX_FMT_SDR_S12: /* 336 x IQ samples */ 337 case MSI2500_PIX_FMT_SDR_S12: /* 336 x IQ samples */
340 memcpy(dst, src, 1008); 338 memcpy(dst, src, 1008);
341 src += 1008; 339 src += 1008;
342 dst += 1008; 340 dst += 1008;
343 dst_len += 1008; 341 dst_len += 1008;
344 s->next_sample = sample[i] + 336; 342 dev->next_sample = sample[i] + 336;
345 break; 343 break;
346 case V4L2_SDR_FMT_CS14LE: /* 252 x IQ samples */ 344 case V4L2_SDR_FMT_CS14LE: /* 252 x IQ samples */
347 memcpy(dst, src, 1008); 345 memcpy(dst, src, 1008);
348 src += 1008; 346 src += 1008;
349 dst += 1008; 347 dst += 1008;
350 dst_len += 1008; 348 dst_len += 1008;
351 s->next_sample = sample[i] + 252; 349 dev->next_sample = sample[i] + 252;
352 break; 350 break;
353 default: 351 default:
354 break; 352 break;
@@ -356,17 +354,17 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
356 } 354 }
357 355
358 /* calculate sample rate and output it in 10 seconds intervals */ 356 /* calculate sample rate and output it in 10 seconds intervals */
359 if (unlikely(time_is_before_jiffies(s->jiffies_next))) { 357 if (unlikely(time_is_before_jiffies(dev->jiffies_next))) {
360 #define MSECS 10000UL 358 #define MSECS 10000UL
361 unsigned int msecs = jiffies_to_msecs(jiffies - 359 unsigned int msecs = jiffies_to_msecs(jiffies -
362 s->jiffies_next + msecs_to_jiffies(MSECS)); 360 dev->jiffies_next + msecs_to_jiffies(MSECS));
363 unsigned int samples = s->next_sample - s->sample; 361 unsigned int samples = dev->next_sample - dev->sample;
364 362
365 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); 363 dev->jiffies_next = jiffies + msecs_to_jiffies(MSECS);
366 s->sample = s->next_sample; 364 dev->sample = dev->next_sample;
367 dev_dbg(s->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n", 365 dev_dbg(dev->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n",
368 src_len, samples, msecs, 366 src_len, samples, msecs,
369 samples * 1000UL / msecs); 367 samples * 1000UL / msecs);
370 } 368 }
371 369
372 return dst_len; 370 return dst_len;
@@ -378,27 +376,28 @@ static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src,
378 */ 376 */
379static void msi2500_isoc_handler(struct urb *urb) 377static void msi2500_isoc_handler(struct urb *urb)
380{ 378{
381 struct msi2500_state *s = (struct msi2500_state *)urb->context; 379 struct msi2500_dev *dev = (struct msi2500_dev *)urb->context;
382 int i, flen, fstatus; 380 int i, flen, fstatus;
383 unsigned char *iso_buf = NULL; 381 unsigned char *iso_buf = NULL;
384 struct msi2500_frame_buf *fbuf; 382 struct msi2500_frame_buf *fbuf;
385 383
386 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 384 if (unlikely(urb->status == -ENOENT ||
387 urb->status == -ESHUTDOWN)) { 385 urb->status == -ECONNRESET ||
388 dev_dbg(s->dev, "URB (%p) unlinked %ssynchronuously\n", 386 urb->status == -ESHUTDOWN)) {
389 urb, urb->status == -ENOENT ? "" : "a"); 387 dev_dbg(dev->dev, "URB (%p) unlinked %ssynchronuously\n",
388 urb, urb->status == -ENOENT ? "" : "a");
390 return; 389 return;
391 } 390 }
392 391
393 if (unlikely(urb->status != 0)) { 392 if (unlikely(urb->status != 0)) {
394 dev_dbg(s->dev, "called with status %d\n", urb->status); 393 dev_dbg(dev->dev, "called with status %d\n", urb->status);
395 /* Give up after a number of contiguous errors */ 394 /* Give up after a number of contiguous errors */
396 if (++s->isoc_errors > MAX_ISOC_ERRORS) 395 if (++dev->isoc_errors > MAX_ISOC_ERRORS)
397 dev_dbg(s->dev, "Too many ISOC errors, bailing out\n"); 396 dev_dbg(dev->dev, "Too many ISOC errors, bailing out\n");
398 goto handler_end; 397 goto handler_end;
399 } else { 398 } else {
400 /* Reset ISOC error counter. We did get here, after all. */ 399 /* Reset ISOC error counter. We did get here, after all. */
401 s->isoc_errors = 0; 400 dev->isoc_errors = 0;
402 } 401 }
403 402
404 /* Compact data */ 403 /* Compact data */
@@ -408,9 +407,9 @@ static void msi2500_isoc_handler(struct urb *urb)
408 /* Check frame error */ 407 /* Check frame error */
409 fstatus = urb->iso_frame_desc[i].status; 408 fstatus = urb->iso_frame_desc[i].status;
410 if (unlikely(fstatus)) { 409 if (unlikely(fstatus)) {
411 dev_dbg_ratelimited(s->dev, 410 dev_dbg_ratelimited(dev->dev,
412 "frame=%d/%d has error %d skipping\n", 411 "frame=%d/%d has error %d skipping\n",
413 i, urb->number_of_packets, fstatus); 412 i, urb->number_of_packets, fstatus);
414 continue; 413 continue;
415 } 414 }
416 415
@@ -422,18 +421,18 @@ static void msi2500_isoc_handler(struct urb *urb)
422 iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 421 iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
423 422
424 /* Get free framebuffer */ 423 /* Get free framebuffer */
425 fbuf = msi2500_get_next_fill_buf(s); 424 fbuf = msi2500_get_next_fill_buf(dev);
426 if (unlikely(fbuf == NULL)) { 425 if (unlikely(fbuf == NULL)) {
427 s->vb_full++; 426 dev->vb_full++;
428 dev_dbg_ratelimited(s->dev, 427 dev_dbg_ratelimited(dev->dev,
429 "videobuf is full, %d packets dropped\n", 428 "videobuf is full, %d packets dropped\n",
430 s->vb_full); 429 dev->vb_full);
431 continue; 430 continue;
432 } 431 }
433 432
434 /* fill framebuffer */ 433 /* fill framebuffer */
435 ptr = vb2_plane_vaddr(&fbuf->vb, 0); 434 ptr = vb2_plane_vaddr(&fbuf->vb, 0);
436 flen = msi2500_convert_stream(s, ptr, iso_buf, flen); 435 flen = msi2500_convert_stream(dev, ptr, iso_buf, flen);
437 vb2_set_plane_payload(&fbuf->vb, 0, flen); 436 vb2_set_plane_payload(&fbuf->vb, 0, flen);
438 vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE); 437 vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
439 } 438 }
@@ -441,66 +440,66 @@ static void msi2500_isoc_handler(struct urb *urb)
441handler_end: 440handler_end:
442 i = usb_submit_urb(urb, GFP_ATOMIC); 441 i = usb_submit_urb(urb, GFP_ATOMIC);
443 if (unlikely(i != 0)) 442 if (unlikely(i != 0))
444 dev_dbg(s->dev, "Error (%d) re-submitting urb\n", i); 443 dev_dbg(dev->dev, "Error (%d) re-submitting urb\n", i);
445} 444}
446 445
447static void msi2500_iso_stop(struct msi2500_state *s) 446static void msi2500_iso_stop(struct msi2500_dev *dev)
448{ 447{
449 int i; 448 int i;
450 449
451 dev_dbg(s->dev, "\n"); 450 dev_dbg(dev->dev, "\n");
452 451
453 /* Unlinking ISOC buffers one by one */ 452 /* Unlinking ISOC buffers one by one */
454 for (i = 0; i < MAX_ISO_BUFS; i++) { 453 for (i = 0; i < MAX_ISO_BUFS; i++) {
455 if (s->urbs[i]) { 454 if (dev->urbs[i]) {
456 dev_dbg(s->dev, "Unlinking URB %p\n", s->urbs[i]); 455 dev_dbg(dev->dev, "Unlinking URB %p\n", dev->urbs[i]);
457 usb_kill_urb(s->urbs[i]); 456 usb_kill_urb(dev->urbs[i]);
458 } 457 }
459 } 458 }
460} 459}
461 460
462static void msi2500_iso_free(struct msi2500_state *s) 461static void msi2500_iso_free(struct msi2500_dev *dev)
463{ 462{
464 int i; 463 int i;
465 464
466 dev_dbg(s->dev, "\n"); 465 dev_dbg(dev->dev, "\n");
467 466
468 /* Freeing ISOC buffers one by one */ 467 /* Freeing ISOC buffers one by one */
469 for (i = 0; i < MAX_ISO_BUFS; i++) { 468 for (i = 0; i < MAX_ISO_BUFS; i++) {
470 if (s->urbs[i]) { 469 if (dev->urbs[i]) {
471 dev_dbg(s->dev, "Freeing URB\n"); 470 dev_dbg(dev->dev, "Freeing URB\n");
472 if (s->urbs[i]->transfer_buffer) { 471 if (dev->urbs[i]->transfer_buffer) {
473 usb_free_coherent(s->udev, 472 usb_free_coherent(dev->udev,
474 s->urbs[i]->transfer_buffer_length, 473 dev->urbs[i]->transfer_buffer_length,
475 s->urbs[i]->transfer_buffer, 474 dev->urbs[i]->transfer_buffer,
476 s->urbs[i]->transfer_dma); 475 dev->urbs[i]->transfer_dma);
477 } 476 }
478 usb_free_urb(s->urbs[i]); 477 usb_free_urb(dev->urbs[i]);
479 s->urbs[i] = NULL; 478 dev->urbs[i] = NULL;
480 } 479 }
481 } 480 }
482} 481}
483 482
484/* Both v4l2_lock and vb_queue_lock should be locked when calling this */ 483/* Both v4l2_lock and vb_queue_lock should be locked when calling this */
485static void msi2500_isoc_cleanup(struct msi2500_state *s) 484static void msi2500_isoc_cleanup(struct msi2500_dev *dev)
486{ 485{
487 dev_dbg(s->dev, "\n"); 486 dev_dbg(dev->dev, "\n");
488 487
489 msi2500_iso_stop(s); 488 msi2500_iso_stop(dev);
490 msi2500_iso_free(s); 489 msi2500_iso_free(dev);
491} 490}
492 491
493/* Both v4l2_lock and vb_queue_lock should be locked when calling this */ 492/* Both v4l2_lock and vb_queue_lock should be locked when calling this */
494static int msi2500_isoc_init(struct msi2500_state *s) 493static int msi2500_isoc_init(struct msi2500_dev *dev)
495{ 494{
496 struct urb *urb; 495 struct urb *urb;
497 int i, j, ret; 496 int i, j, ret;
498 497
499 dev_dbg(s->dev, "\n"); 498 dev_dbg(dev->dev, "\n");
500 499
501 s->isoc_errors = 0; 500 dev->isoc_errors = 0;
502 501
503 ret = usb_set_interface(s->udev, 0, 1); 502 ret = usb_set_interface(dev->udev, 0, 1);
504 if (ret) 503 if (ret)
505 return ret; 504 return ret;
506 505
@@ -508,29 +507,29 @@ static int msi2500_isoc_init(struct msi2500_state *s)
508 for (i = 0; i < MAX_ISO_BUFS; i++) { 507 for (i = 0; i < MAX_ISO_BUFS; i++) {
509 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); 508 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
510 if (urb == NULL) { 509 if (urb == NULL) {
511 dev_err(s->dev, "Failed to allocate urb %d\n", i); 510 dev_err(dev->dev, "Failed to allocate urb %d\n", i);
512 msi2500_isoc_cleanup(s); 511 msi2500_isoc_cleanup(dev);
513 return -ENOMEM; 512 return -ENOMEM;
514 } 513 }
515 s->urbs[i] = urb; 514 dev->urbs[i] = urb;
516 dev_dbg(s->dev, "Allocated URB at 0x%p\n", urb); 515 dev_dbg(dev->dev, "Allocated URB at 0x%p\n", urb);
517 516
518 urb->interval = 1; 517 urb->interval = 1;
519 urb->dev = s->udev; 518 urb->dev = dev->udev;
520 urb->pipe = usb_rcvisocpipe(s->udev, 0x81); 519 urb->pipe = usb_rcvisocpipe(dev->udev, 0x81);
521 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 520 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
522 urb->transfer_buffer = usb_alloc_coherent(s->udev, 521 urb->transfer_buffer = usb_alloc_coherent(dev->udev,
523 ISO_BUFFER_SIZE, 522 ISO_BUFFER_SIZE,
524 GFP_KERNEL, &urb->transfer_dma); 523 GFP_KERNEL, &urb->transfer_dma);
525 if (urb->transfer_buffer == NULL) { 524 if (urb->transfer_buffer == NULL) {
526 dev_err(s->dev, "Failed to allocate urb buffer %d\n", 525 dev_err(dev->dev,
527 i); 526 "Failed to allocate urb buffer %d\n", i);
528 msi2500_isoc_cleanup(s); 527 msi2500_isoc_cleanup(dev);
529 return -ENOMEM; 528 return -ENOMEM;
530 } 529 }
531 urb->transfer_buffer_length = ISO_BUFFER_SIZE; 530 urb->transfer_buffer_length = ISO_BUFFER_SIZE;
532 urb->complete = msi2500_isoc_handler; 531 urb->complete = msi2500_isoc_handler;
533 urb->context = s; 532 urb->context = dev;
534 urb->start_frame = 0; 533 urb->start_frame = 0;
535 urb->number_of_packets = ISO_FRAMES_PER_DESC; 534 urb->number_of_packets = ISO_FRAMES_PER_DESC;
536 for (j = 0; j < ISO_FRAMES_PER_DESC; j++) { 535 for (j = 0; j < ISO_FRAMES_PER_DESC; j++) {
@@ -541,14 +540,15 @@ static int msi2500_isoc_init(struct msi2500_state *s)
541 540
542 /* link */ 541 /* link */
543 for (i = 0; i < MAX_ISO_BUFS; i++) { 542 for (i = 0; i < MAX_ISO_BUFS; i++) {
544 ret = usb_submit_urb(s->urbs[i], GFP_KERNEL); 543 ret = usb_submit_urb(dev->urbs[i], GFP_KERNEL);
545 if (ret) { 544 if (ret) {
546 dev_err(s->dev, "usb_submit_urb %d failed with error %d\n", 545 dev_err(dev->dev,
547 i, ret); 546 "usb_submit_urb %d failed with error %d\n",
548 msi2500_isoc_cleanup(s); 547 i, ret);
548 msi2500_isoc_cleanup(dev);
549 return ret; 549 return ret;
550 } 550 }
551 dev_dbg(s->dev, "URB 0x%p submitted.\n", s->urbs[i]); 551 dev_dbg(dev->dev, "URB 0x%p submitted.\n", dev->urbs[i]);
552 } 552 }
553 553
554 /* All is done... */ 554 /* All is done... */
@@ -556,56 +556,56 @@ static int msi2500_isoc_init(struct msi2500_state *s)
556} 556}
557 557
558/* Must be called with vb_queue_lock hold */ 558/* Must be called with vb_queue_lock hold */
559static void msi2500_cleanup_queued_bufs(struct msi2500_state *s) 559static void msi2500_cleanup_queued_bufs(struct msi2500_dev *dev)
560{ 560{
561 unsigned long flags; 561 unsigned long flags;
562 562
563 dev_dbg(s->dev, "\n"); 563 dev_dbg(dev->dev, "\n");
564 564
565 spin_lock_irqsave(&s->queued_bufs_lock, flags); 565 spin_lock_irqsave(&dev->queued_bufs_lock, flags);
566 while (!list_empty(&s->queued_bufs)) { 566 while (!list_empty(&dev->queued_bufs)) {
567 struct msi2500_frame_buf *buf; 567 struct msi2500_frame_buf *buf;
568 568
569 buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf, 569 buf = list_entry(dev->queued_bufs.next,
570 list); 570 struct msi2500_frame_buf, list);
571 list_del(&buf->list); 571 list_del(&buf->list);
572 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 572 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
573 } 573 }
574 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 574 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
575} 575}
576 576
577/* The user yanked out the cable... */ 577/* The user yanked out the cable... */
578static void msi2500_disconnect(struct usb_interface *intf) 578static void msi2500_disconnect(struct usb_interface *intf)
579{ 579{
580 struct v4l2_device *v = usb_get_intfdata(intf); 580 struct v4l2_device *v = usb_get_intfdata(intf);
581 struct msi2500_state *s = 581 struct msi2500_dev *dev =
582 container_of(v, struct msi2500_state, v4l2_dev); 582 container_of(v, struct msi2500_dev, v4l2_dev);
583 583
584 dev_dbg(s->dev, "\n"); 584 dev_dbg(dev->dev, "\n");
585 585
586 mutex_lock(&s->vb_queue_lock); 586 mutex_lock(&dev->vb_queue_lock);
587 mutex_lock(&s->v4l2_lock); 587 mutex_lock(&dev->v4l2_lock);
588 /* No need to keep the urbs around after disconnection */ 588 /* No need to keep the urbs around after disconnection */
589 s->udev = NULL; 589 dev->udev = NULL;
590 v4l2_device_disconnect(&s->v4l2_dev); 590 v4l2_device_disconnect(&dev->v4l2_dev);
591 video_unregister_device(&s->vdev); 591 video_unregister_device(&dev->vdev);
592 spi_unregister_master(s->master); 592 spi_unregister_master(dev->master);
593 mutex_unlock(&s->v4l2_lock); 593 mutex_unlock(&dev->v4l2_lock);
594 mutex_unlock(&s->vb_queue_lock); 594 mutex_unlock(&dev->vb_queue_lock);
595 595
596 v4l2_device_put(&s->v4l2_dev); 596 v4l2_device_put(&dev->v4l2_dev);
597} 597}
598 598
599static int msi2500_querycap(struct file *file, void *fh, 599static int msi2500_querycap(struct file *file, void *fh,
600 struct v4l2_capability *cap) 600 struct v4l2_capability *cap)
601{ 601{
602 struct msi2500_state *s = video_drvdata(file); 602 struct msi2500_dev *dev = video_drvdata(file);
603 603
604 dev_dbg(s->dev, "\n"); 604 dev_dbg(dev->dev, "\n");
605 605
606 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); 606 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
607 strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); 607 strlcpy(cap->card, dev->vdev.name, sizeof(cap->card));
608 usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info)); 608 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
609 cap->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING | 609 cap->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING |
610 V4L2_CAP_READWRITE | V4L2_CAP_TUNER; 610 V4L2_CAP_READWRITE | V4L2_CAP_TUNER;
611 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 611 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
@@ -614,43 +614,46 @@ static int msi2500_querycap(struct file *file, void *fh,
614 614
615/* Videobuf2 operations */ 615/* Videobuf2 operations */
616static int msi2500_queue_setup(struct vb2_queue *vq, 616static int msi2500_queue_setup(struct vb2_queue *vq,
617 const struct v4l2_format *fmt, unsigned int *nbuffers, 617 const struct v4l2_format *fmt,
618 unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) 618 unsigned int *nbuffers,
619 unsigned int *nplanes, unsigned int sizes[],
620 void *alloc_ctxs[])
619{ 621{
620 struct msi2500_state *s = vb2_get_drv_priv(vq); 622 struct msi2500_dev *dev = vb2_get_drv_priv(vq);
621 623
622 dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers); 624 dev_dbg(dev->dev, "nbuffers=%d\n", *nbuffers);
623 625
624 /* Absolute min and max number of buffers available for mmap() */ 626 /* Absolute min and max number of buffers available for mmap() */
625 *nbuffers = clamp_t(unsigned int, *nbuffers, 8, 32); 627 *nbuffers = clamp_t(unsigned int, *nbuffers, 8, 32);
626 *nplanes = 1; 628 *nplanes = 1;
627 sizes[0] = PAGE_ALIGN(s->buffersize); 629 sizes[0] = PAGE_ALIGN(dev->buffersize);
628 dev_dbg(s->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); 630 dev_dbg(dev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]);
629 return 0; 631 return 0;
630} 632}
631 633
632static void msi2500_buf_queue(struct vb2_buffer *vb) 634static void msi2500_buf_queue(struct vb2_buffer *vb)
633{ 635{
634 struct msi2500_state *s = vb2_get_drv_priv(vb->vb2_queue); 636 struct msi2500_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
635 struct msi2500_frame_buf *buf = 637 struct msi2500_frame_buf *buf = container_of(vb,
636 container_of(vb, struct msi2500_frame_buf, vb); 638 struct msi2500_frame_buf,
639 vb);
637 unsigned long flags; 640 unsigned long flags;
638 641
639 /* Check the device has not disconnected between prep and queuing */ 642 /* Check the device has not disconnected between prep and queuing */
640 if (unlikely(!s->udev)) { 643 if (unlikely(!dev->udev)) {
641 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 644 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
642 return; 645 return;
643 } 646 }
644 647
645 spin_lock_irqsave(&s->queued_bufs_lock, flags); 648 spin_lock_irqsave(&dev->queued_bufs_lock, flags);
646 list_add_tail(&buf->list, &s->queued_bufs); 649 list_add_tail(&buf->list, &dev->queued_bufs);
647 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 650 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
648} 651}
649 652
650#define CMD_WREG 0x41 653#define CMD_WREG 0x41
651#define CMD_START_STREAMING 0x43 654#define CMD_START_STREAMING 0x43
652#define CMD_STOP_STREAMING 0x45 655#define CMD_STOP_STREAMING 0x45
653#define CMD_READ_UNKNOW 0x48 656#define CMD_READ_UNKNOWN 0x48
654 657
655#define msi2500_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \ 658#define msi2500_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \
656 char *_direction; \ 659 char *_direction; \
@@ -663,7 +666,7 @@ static void msi2500_buf_queue(struct vb2_buffer *vb)
663 _l & 0xff, _l >> 8, _direction, _l, _b); \ 666 _l & 0xff, _l >> 8, _direction, _l, _b); \
664} 667}
665 668
666static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data) 669static int msi2500_ctrl_msg(struct msi2500_dev *dev, u8 cmd, u32 data)
667{ 670{
668 int ret; 671 int ret;
669 u8 request = cmd; 672 u8 request = cmd;
@@ -671,39 +674,38 @@ static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data)
671 u16 value = (data >> 0) & 0xffff; 674 u16 value = (data >> 0) & 0xffff;
672 u16 index = (data >> 16) & 0xffff; 675 u16 index = (data >> 16) & 0xffff;
673 676
674 msi2500_dbg_usb_control_msg(s->dev, 677 msi2500_dbg_usb_control_msg(dev->dev, request, requesttype,
675 request, requesttype, value, index, NULL, 0); 678 value, index, NULL, 0);
676 ret = usb_control_msg(s->udev, usb_sndctrlpipe(s->udev, 0), 679 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), request,
677 request, requesttype, value, index, NULL, 0, 2000); 680 requesttype, value, index, NULL, 0, 2000);
678 if (ret) 681 if (ret)
679 dev_err(s->dev, "failed %d, cmd %02x, data %04x\n", 682 dev_err(dev->dev, "failed %d, cmd %02x, data %04x\n",
680 ret, cmd, data); 683 ret, cmd, data);
681 684
682 return ret; 685 return ret;
683} 686}
684 687
685#define F_REF 24000000 688static int msi2500_set_usb_adc(struct msi2500_dev *dev)
686#define DIV_R_IN 2
687static int msi2500_set_usb_adc(struct msi2500_state *s)
688{ 689{
689 int ret, div_n, div_m, div_r_out, f_sr, f_vco, fract; 690 int ret;
691 unsigned int f_vco, f_sr, div_n, k, k_cw, div_out;
690 u32 reg3, reg4, reg7; 692 u32 reg3, reg4, reg7;
691 struct v4l2_ctrl *bandwidth_auto; 693 struct v4l2_ctrl *bandwidth_auto;
692 struct v4l2_ctrl *bandwidth; 694 struct v4l2_ctrl *bandwidth;
693 695
694 f_sr = s->f_adc; 696 f_sr = dev->f_adc;
695 697
696 /* set tuner, subdev, filters according to sampling rate */ 698 /* set tuner, subdev, filters according to sampling rate */
697 bandwidth_auto = v4l2_ctrl_find(&s->hdl, 699 bandwidth_auto = v4l2_ctrl_find(&dev->hdl,
698 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO); 700 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO);
699 if (v4l2_ctrl_g_ctrl(bandwidth_auto)) { 701 if (v4l2_ctrl_g_ctrl(bandwidth_auto)) {
700 bandwidth = v4l2_ctrl_find(&s->hdl, 702 bandwidth = v4l2_ctrl_find(&dev->hdl,
701 V4L2_CID_RF_TUNER_BANDWIDTH); 703 V4L2_CID_RF_TUNER_BANDWIDTH);
702 v4l2_ctrl_s_ctrl(bandwidth, s->f_adc); 704 v4l2_ctrl_s_ctrl(bandwidth, dev->f_adc);
703 } 705 }
704 706
705 /* select stream format */ 707 /* select stream format */
706 switch (s->pixelformat) { 708 switch (dev->pixelformat) {
707 case V4L2_SDR_FMT_CU8: 709 case V4L2_SDR_FMT_CU8:
708 reg7 = 0x000c9407; /* 504 */ 710 reg7 = 0x000c9407; /* 504 */
709 break; 711 break;
@@ -728,6 +730,21 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
728 } 730 }
729 731
730 /* 732 /*
733 * Fractional-N synthesizer
734 *
735 * +----------------------------------------+
736 * v |
737 * Fref +----+ +-------+ +-----+ +------+ +---+
738 * ------> | PD | --> | VCO | --> | /2 | ------> | /N.F | <-- | K |
739 * +----+ +-------+ +-----+ +------+ +---+
740 * |
741 * |
742 * v
743 * +-------+ +-----+ Fout
744 * | /Rout | --> | /12 | ------>
745 * +-------+ +-----+
746 */
747 /*
731 * Synthesizer config is just a educated guess... 748 * Synthesizer config is just a educated guess...
732 * 749 *
733 * [7:0] 0x03, register address 750 * [7:0] 0x03, register address
@@ -754,10 +771,14 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
754 * 771 *
755 * VCO 202000000 - 720000000++ 772 * VCO 202000000 - 720000000++
756 */ 773 */
774
775 #define F_REF 24000000
776 #define DIV_PRE_N 2
777 #define DIV_LO_OUT 12
757 reg3 = 0x01000303; 778 reg3 = 0x01000303;
758 reg4 = 0x00000004; 779 reg4 = 0x00000004;
759 780
760 /* XXX: Filters? AGC? */ 781 /* XXX: Filters? AGC? VCO band? */
761 if (f_sr < 6000000) 782 if (f_sr < 6000000)
762 reg3 |= 0x1 << 20; 783 reg3 |= 0x1 << 20;
763 else if (f_sr < 7000000) 784 else if (f_sr < 7000000)
@@ -767,54 +788,55 @@ static int msi2500_set_usb_adc(struct msi2500_state *s)
767 else 788 else
768 reg3 |= 0xd << 20; 789 reg3 |= 0xd << 20;
769 790
770 for (div_r_out = 4; div_r_out < 16; div_r_out += 2) { 791 for (div_out = 4; div_out < 16; div_out += 2) {
771 f_vco = f_sr * div_r_out * 12; 792 f_vco = f_sr * div_out * DIV_LO_OUT;
772 dev_dbg(s->dev, "div_r_out=%d f_vco=%d\n", div_r_out, f_vco); 793 dev_dbg(dev->dev, "div_out=%u f_vco=%u\n", div_out, f_vco);
773 if (f_vco >= 202000000) 794 if (f_vco >= 202000000)
774 break; 795 break;
775 } 796 }
776 797
777 div_n = f_vco / (F_REF * DIV_R_IN); 798 /* Calculate PLL integer and fractional control word. */
778 div_m = f_vco % (F_REF * DIV_R_IN); 799 div_n = div_u64_rem(f_vco, DIV_PRE_N * F_REF, &k);
779 fract = 0x200000ul * div_m / (F_REF * DIV_R_IN); 800 k_cw = div_u64((u64) k * 0x200000, DIV_PRE_N * F_REF);
780 801
781 reg3 |= div_n << 16; 802 reg3 |= div_n << 16;
782 reg3 |= (div_r_out / 2 - 1) << 10; 803 reg3 |= (div_out / 2 - 1) << 10;
783 reg3 |= ((fract >> 20) & 0x000001) << 15; /* [20] */ 804 reg3 |= ((k_cw >> 20) & 0x000001) << 15; /* [20] */
784 reg4 |= ((fract >> 0) & 0x0fffff) << 8; /* [19:0] */ 805 reg4 |= ((k_cw >> 0) & 0x0fffff) << 8; /* [19:0] */
785 806
786 dev_dbg(s->dev, "f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d reg3=%08x reg4=%08x\n", 807 dev_dbg(dev->dev,
787 f_sr, f_vco, div_n, div_m, div_r_out, reg3, reg4); 808 "f_sr=%u f_vco=%u div_n=%u k=%u div_out=%u reg3=%08x reg4=%08x\n",
809 f_sr, f_vco, div_n, k, div_out, reg3, reg4);
788 810
789 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00608008); 811 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00608008);
790 if (ret) 812 if (ret)
791 goto err; 813 goto err;
792 814
793 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00000c05); 815 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00000c05);
794 if (ret) 816 if (ret)
795 goto err; 817 goto err;
796 818
797 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00020000); 819 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00020000);
798 if (ret) 820 if (ret)
799 goto err; 821 goto err;
800 822
801 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00480102); 823 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00480102);
802 if (ret) 824 if (ret)
803 goto err; 825 goto err;
804 826
805 ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00f38008); 827 ret = msi2500_ctrl_msg(dev, CMD_WREG, 0x00f38008);
806 if (ret) 828 if (ret)
807 goto err; 829 goto err;
808 830
809 ret = msi2500_ctrl_msg(s, CMD_WREG, reg7); 831 ret = msi2500_ctrl_msg(dev, CMD_WREG, reg7);
810 if (ret) 832 if (ret)
811 goto err; 833 goto err;
812 834
813 ret = msi2500_ctrl_msg(s, CMD_WREG, reg4); 835 ret = msi2500_ctrl_msg(dev, CMD_WREG, reg4);
814 if (ret) 836 if (ret)
815 goto err; 837 goto err;
816 838
817 ret = msi2500_ctrl_msg(s, CMD_WREG, reg3); 839 ret = msi2500_ctrl_msg(dev, CMD_WREG, reg3);
818 if (ret) 840 if (ret)
819 goto err; 841 goto err;
820err: 842err:
@@ -823,57 +845,57 @@ err:
823 845
824static int msi2500_start_streaming(struct vb2_queue *vq, unsigned int count) 846static int msi2500_start_streaming(struct vb2_queue *vq, unsigned int count)
825{ 847{
826 struct msi2500_state *s = vb2_get_drv_priv(vq); 848 struct msi2500_dev *dev = vb2_get_drv_priv(vq);
827 int ret; 849 int ret;
828 850
829 dev_dbg(s->dev, "\n"); 851 dev_dbg(dev->dev, "\n");
830 852
831 if (!s->udev) 853 if (!dev->udev)
832 return -ENODEV; 854 return -ENODEV;
833 855
834 if (mutex_lock_interruptible(&s->v4l2_lock)) 856 if (mutex_lock_interruptible(&dev->v4l2_lock))
835 return -ERESTARTSYS; 857 return -ERESTARTSYS;
836 858
837 /* wake-up tuner */ 859 /* wake-up tuner */
838 v4l2_subdev_call(s->v4l2_subdev, core, s_power, 1); 860 v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 1);
839 861
840 ret = msi2500_set_usb_adc(s); 862 ret = msi2500_set_usb_adc(dev);
841 863
842 ret = msi2500_isoc_init(s); 864 ret = msi2500_isoc_init(dev);
843 if (ret) 865 if (ret)
844 msi2500_cleanup_queued_bufs(s); 866 msi2500_cleanup_queued_bufs(dev);
845 867
846 ret = msi2500_ctrl_msg(s, CMD_START_STREAMING, 0); 868 ret = msi2500_ctrl_msg(dev, CMD_START_STREAMING, 0);
847 869
848 mutex_unlock(&s->v4l2_lock); 870 mutex_unlock(&dev->v4l2_lock);
849 871
850 return ret; 872 return ret;
851} 873}
852 874
853static void msi2500_stop_streaming(struct vb2_queue *vq) 875static void msi2500_stop_streaming(struct vb2_queue *vq)
854{ 876{
855 struct msi2500_state *s = vb2_get_drv_priv(vq); 877 struct msi2500_dev *dev = vb2_get_drv_priv(vq);
856 878
857 dev_dbg(s->dev, "\n"); 879 dev_dbg(dev->dev, "\n");
858 880
859 mutex_lock(&s->v4l2_lock); 881 mutex_lock(&dev->v4l2_lock);
860 882
861 if (s->udev) 883 if (dev->udev)
862 msi2500_isoc_cleanup(s); 884 msi2500_isoc_cleanup(dev);
863 885
864 msi2500_cleanup_queued_bufs(s); 886 msi2500_cleanup_queued_bufs(dev);
865 887
866 /* according to tests, at least 700us delay is required */ 888 /* according to tests, at least 700us delay is required */
867 msleep(20); 889 msleep(20);
868 if (!msi2500_ctrl_msg(s, CMD_STOP_STREAMING, 0)) { 890 if (!msi2500_ctrl_msg(dev, CMD_STOP_STREAMING, 0)) {
869 /* sleep USB IF / ADC */ 891 /* sleep USB IF / ADC */
870 msi2500_ctrl_msg(s, CMD_WREG, 0x01000003); 892 msi2500_ctrl_msg(dev, CMD_WREG, 0x01000003);
871 } 893 }
872 894
873 /* sleep tuner */ 895 /* sleep tuner */
874 v4l2_subdev_call(s->v4l2_subdev, core, s_power, 0); 896 v4l2_subdev_call(dev->v4l2_subdev, core, s_power, 0);
875 897
876 mutex_unlock(&s->v4l2_lock); 898 mutex_unlock(&dev->v4l2_lock);
877} 899}
878 900
879static struct vb2_ops msi2500_vb2_ops = { 901static struct vb2_ops msi2500_vb2_ops = {
@@ -886,13 +908,13 @@ static struct vb2_ops msi2500_vb2_ops = {
886}; 908};
887 909
888static int msi2500_enum_fmt_sdr_cap(struct file *file, void *priv, 910static int msi2500_enum_fmt_sdr_cap(struct file *file, void *priv,
889 struct v4l2_fmtdesc *f) 911 struct v4l2_fmtdesc *f)
890{ 912{
891 struct msi2500_state *s = video_drvdata(file); 913 struct msi2500_dev *dev = video_drvdata(file);
892 914
893 dev_dbg(s->dev, "index=%d\n", f->index); 915 dev_dbg(dev->dev, "index=%d\n", f->index);
894 916
895 if (f->index >= s->num_formats) 917 if (f->index >= dev->num_formats)
896 return -EINVAL; 918 return -EINVAL;
897 919
898 strlcpy(f->description, formats[f->index].name, sizeof(f->description)); 920 strlcpy(f->description, formats[f->index].name, sizeof(f->description));
@@ -902,45 +924,45 @@ static int msi2500_enum_fmt_sdr_cap(struct file *file, void *priv,
902} 924}
903 925
904static int msi2500_g_fmt_sdr_cap(struct file *file, void *priv, 926static int msi2500_g_fmt_sdr_cap(struct file *file, void *priv,
905 struct v4l2_format *f) 927 struct v4l2_format *f)
906{ 928{
907 struct msi2500_state *s = video_drvdata(file); 929 struct msi2500_dev *dev = video_drvdata(file);
908 930
909 dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", 931 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n",
910 (char *)&s->pixelformat); 932 (char *)&dev->pixelformat);
911 933
912 f->fmt.sdr.pixelformat = s->pixelformat; 934 f->fmt.sdr.pixelformat = dev->pixelformat;
913 f->fmt.sdr.buffersize = s->buffersize; 935 f->fmt.sdr.buffersize = dev->buffersize;
914 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 936 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
915 937
916 return 0; 938 return 0;
917} 939}
918 940
919static int msi2500_s_fmt_sdr_cap(struct file *file, void *priv, 941static int msi2500_s_fmt_sdr_cap(struct file *file, void *priv,
920 struct v4l2_format *f) 942 struct v4l2_format *f)
921{ 943{
922 struct msi2500_state *s = video_drvdata(file); 944 struct msi2500_dev *dev = video_drvdata(file);
923 struct vb2_queue *q = &s->vb_queue; 945 struct vb2_queue *q = &dev->vb_queue;
924 int i; 946 int i;
925 947
926 dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", 948 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n",
927 (char *)&f->fmt.sdr.pixelformat); 949 (char *)&f->fmt.sdr.pixelformat);
928 950
929 if (vb2_is_busy(q)) 951 if (vb2_is_busy(q))
930 return -EBUSY; 952 return -EBUSY;
931 953
932 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 954 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
933 for (i = 0; i < s->num_formats; i++) { 955 for (i = 0; i < dev->num_formats; i++) {
934 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 956 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
935 s->pixelformat = formats[i].pixelformat; 957 dev->pixelformat = formats[i].pixelformat;
936 s->buffersize = formats[i].buffersize; 958 dev->buffersize = formats[i].buffersize;
937 f->fmt.sdr.buffersize = formats[i].buffersize; 959 f->fmt.sdr.buffersize = formats[i].buffersize;
938 return 0; 960 return 0;
939 } 961 }
940 } 962 }
941 963
942 s->pixelformat = formats[0].pixelformat; 964 dev->pixelformat = formats[0].pixelformat;
943 s->buffersize = formats[0].buffersize; 965 dev->buffersize = formats[0].buffersize;
944 f->fmt.sdr.pixelformat = formats[0].pixelformat; 966 f->fmt.sdr.pixelformat = formats[0].pixelformat;
945 f->fmt.sdr.buffersize = formats[0].buffersize; 967 f->fmt.sdr.buffersize = formats[0].buffersize;
946 968
@@ -948,16 +970,16 @@ static int msi2500_s_fmt_sdr_cap(struct file *file, void *priv,
948} 970}
949 971
950static int msi2500_try_fmt_sdr_cap(struct file *file, void *priv, 972static int msi2500_try_fmt_sdr_cap(struct file *file, void *priv,
951 struct v4l2_format *f) 973 struct v4l2_format *f)
952{ 974{
953 struct msi2500_state *s = video_drvdata(file); 975 struct msi2500_dev *dev = video_drvdata(file);
954 int i; 976 int i;
955 977
956 dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", 978 dev_dbg(dev->dev, "pixelformat fourcc %4.4s\n",
957 (char *)&f->fmt.sdr.pixelformat); 979 (char *)&f->fmt.sdr.pixelformat);
958 980
959 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 981 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
960 for (i = 0; i < s->num_formats; i++) { 982 for (i = 0; i < dev->num_formats; i++) {
961 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 983 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
962 f->fmt.sdr.buffersize = formats[i].buffersize; 984 f->fmt.sdr.buffersize = formats[i].buffersize;
963 return 0; 985 return 0;
@@ -971,17 +993,17 @@ static int msi2500_try_fmt_sdr_cap(struct file *file, void *priv,
971} 993}
972 994
973static int msi2500_s_tuner(struct file *file, void *priv, 995static int msi2500_s_tuner(struct file *file, void *priv,
974 const struct v4l2_tuner *v) 996 const struct v4l2_tuner *v)
975{ 997{
976 struct msi2500_state *s = video_drvdata(file); 998 struct msi2500_dev *dev = video_drvdata(file);
977 int ret; 999 int ret;
978 1000
979 dev_dbg(s->dev, "index=%d\n", v->index); 1001 dev_dbg(dev->dev, "index=%d\n", v->index);
980 1002
981 if (v->index == 0) 1003 if (v->index == 0)
982 ret = 0; 1004 ret = 0;
983 else if (v->index == 1) 1005 else if (v->index == 1)
984 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_tuner, v); 1006 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_tuner, v);
985 else 1007 else
986 ret = -EINVAL; 1008 ret = -EINVAL;
987 1009
@@ -990,10 +1012,10 @@ static int msi2500_s_tuner(struct file *file, void *priv,
990 1012
991static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v) 1013static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
992{ 1014{
993 struct msi2500_state *s = video_drvdata(file); 1015 struct msi2500_dev *dev = video_drvdata(file);
994 int ret; 1016 int ret;
995 1017
996 dev_dbg(s->dev, "index=%d\n", v->index); 1018 dev_dbg(dev->dev, "index=%d\n", v->index);
997 1019
998 if (v->index == 0) { 1020 if (v->index == 0) {
999 strlcpy(v->name, "Mirics MSi2500", sizeof(v->name)); 1021 strlcpy(v->name, "Mirics MSi2500", sizeof(v->name));
@@ -1003,7 +1025,7 @@ static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
1003 v->rangehigh = 15000000; 1025 v->rangehigh = 15000000;
1004 ret = 0; 1026 ret = 0;
1005 } else if (v->index == 1) { 1027 } else if (v->index == 1) {
1006 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, g_tuner, v); 1028 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_tuner, v);
1007 } else { 1029 } else {
1008 ret = -EINVAL; 1030 ret = -EINVAL;
1009 } 1031 }
@@ -1012,19 +1034,19 @@ static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
1012} 1034}
1013 1035
1014static int msi2500_g_frequency(struct file *file, void *priv, 1036static int msi2500_g_frequency(struct file *file, void *priv,
1015 struct v4l2_frequency *f) 1037 struct v4l2_frequency *f)
1016{ 1038{
1017 struct msi2500_state *s = video_drvdata(file); 1039 struct msi2500_dev *dev = video_drvdata(file);
1018 int ret = 0; 1040 int ret = 0;
1019 1041
1020 dev_dbg(s->dev, "tuner=%d type=%d\n", f->tuner, f->type); 1042 dev_dbg(dev->dev, "tuner=%d type=%d\n", f->tuner, f->type);
1021 1043
1022 if (f->tuner == 0) { 1044 if (f->tuner == 0) {
1023 f->frequency = s->f_adc; 1045 f->frequency = dev->f_adc;
1024 ret = 0; 1046 ret = 0;
1025 } else if (f->tuner == 1) { 1047 } else if (f->tuner == 1) {
1026 f->type = V4L2_TUNER_RF; 1048 f->type = V4L2_TUNER_RF;
1027 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, g_frequency, f); 1049 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, g_frequency, f);
1028 } else { 1050 } else {
1029 ret = -EINVAL; 1051 ret = -EINVAL;
1030 } 1052 }
@@ -1033,22 +1055,22 @@ static int msi2500_g_frequency(struct file *file, void *priv,
1033} 1055}
1034 1056
1035static int msi2500_s_frequency(struct file *file, void *priv, 1057static int msi2500_s_frequency(struct file *file, void *priv,
1036 const struct v4l2_frequency *f) 1058 const struct v4l2_frequency *f)
1037{ 1059{
1038 struct msi2500_state *s = video_drvdata(file); 1060 struct msi2500_dev *dev = video_drvdata(file);
1039 int ret; 1061 int ret;
1040 1062
1041 dev_dbg(s->dev, "tuner=%d type=%d frequency=%u\n", 1063 dev_dbg(dev->dev, "tuner=%d type=%d frequency=%u\n",
1042 f->tuner, f->type, f->frequency); 1064 f->tuner, f->type, f->frequency);
1043 1065
1044 if (f->tuner == 0) { 1066 if (f->tuner == 0) {
1045 s->f_adc = clamp_t(unsigned int, f->frequency, 1067 dev->f_adc = clamp_t(unsigned int, f->frequency,
1046 bands[0].rangelow, 1068 bands[0].rangelow,
1047 bands[0].rangehigh); 1069 bands[0].rangehigh);
1048 dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc); 1070 dev_dbg(dev->dev, "ADC frequency=%u Hz\n", dev->f_adc);
1049 ret = msi2500_set_usb_adc(s); 1071 ret = msi2500_set_usb_adc(dev);
1050 } else if (f->tuner == 1) { 1072 } else if (f->tuner == 1) {
1051 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_frequency, f); 1073 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner, s_frequency, f);
1052 } else { 1074 } else {
1053 ret = -EINVAL; 1075 ret = -EINVAL;
1054 } 1076 }
@@ -1057,13 +1079,13 @@ static int msi2500_s_frequency(struct file *file, void *priv,
1057} 1079}
1058 1080
1059static int msi2500_enum_freq_bands(struct file *file, void *priv, 1081static int msi2500_enum_freq_bands(struct file *file, void *priv,
1060 struct v4l2_frequency_band *band) 1082 struct v4l2_frequency_band *band)
1061{ 1083{
1062 struct msi2500_state *s = video_drvdata(file); 1084 struct msi2500_dev *dev = video_drvdata(file);
1063 int ret; 1085 int ret;
1064 1086
1065 dev_dbg(s->dev, "tuner=%d type=%d index=%d\n", 1087 dev_dbg(dev->dev, "tuner=%d type=%d index=%d\n",
1066 band->tuner, band->type, band->index); 1088 band->tuner, band->type, band->index);
1067 1089
1068 if (band->tuner == 0) { 1090 if (band->tuner == 0) {
1069 if (band->index >= ARRAY_SIZE(bands)) { 1091 if (band->index >= ARRAY_SIZE(bands)) {
@@ -1073,8 +1095,8 @@ static int msi2500_enum_freq_bands(struct file *file, void *priv,
1073 ret = 0; 1095 ret = 0;
1074 } 1096 }
1075 } else if (band->tuner == 1) { 1097 } else if (band->tuner == 1) {
1076 ret = v4l2_subdev_call(s->v4l2_subdev, tuner, 1098 ret = v4l2_subdev_call(dev->v4l2_subdev, tuner,
1077 enum_freq_bands, band); 1099 enum_freq_bands, band);
1078 } else { 1100 } else {
1079 ret = -EINVAL; 1101 ret = -EINVAL;
1080 } 1102 }
@@ -1131,29 +1153,28 @@ static struct video_device msi2500_template = {
1131 1153
1132static void msi2500_video_release(struct v4l2_device *v) 1154static void msi2500_video_release(struct v4l2_device *v)
1133{ 1155{
1134 struct msi2500_state *s = 1156 struct msi2500_dev *dev = container_of(v, struct msi2500_dev, v4l2_dev);
1135 container_of(v, struct msi2500_state, v4l2_dev);
1136 1157
1137 v4l2_ctrl_handler_free(&s->hdl); 1158 v4l2_ctrl_handler_free(&dev->hdl);
1138 v4l2_device_unregister(&s->v4l2_dev); 1159 v4l2_device_unregister(&dev->v4l2_dev);
1139 kfree(s); 1160 kfree(dev);
1140} 1161}
1141 1162
1142static int msi2500_transfer_one_message(struct spi_master *master, 1163static int msi2500_transfer_one_message(struct spi_master *master,
1143 struct spi_message *m) 1164 struct spi_message *m)
1144{ 1165{
1145 struct msi2500_state *s = spi_master_get_devdata(master); 1166 struct msi2500_dev *dev = spi_master_get_devdata(master);
1146 struct spi_transfer *t; 1167 struct spi_transfer *t;
1147 int ret = 0; 1168 int ret = 0;
1148 u32 data; 1169 u32 data;
1149 1170
1150 list_for_each_entry(t, &m->transfers, transfer_list) { 1171 list_for_each_entry(t, &m->transfers, transfer_list) {
1151 dev_dbg(s->dev, "msg=%*ph\n", t->len, t->tx_buf); 1172 dev_dbg(dev->dev, "msg=%*ph\n", t->len, t->tx_buf);
1152 data = 0x09; /* reg 9 is SPI adapter */ 1173 data = 0x09; /* reg 9 is SPI adapter */
1153 data |= ((u8 *)t->tx_buf)[0] << 8; 1174 data |= ((u8 *)t->tx_buf)[0] << 8;
1154 data |= ((u8 *)t->tx_buf)[1] << 16; 1175 data |= ((u8 *)t->tx_buf)[1] << 16;
1155 data |= ((u8 *)t->tx_buf)[2] << 24; 1176 data |= ((u8 *)t->tx_buf)[2] << 24;
1156 ret = msi2500_ctrl_msg(s, CMD_WREG, data); 1177 ret = msi2500_ctrl_msg(dev, CMD_WREG, data);
1157 } 1178 }
1158 1179
1159 m->status = ret; 1180 m->status = ret;
@@ -1162,9 +1183,9 @@ static int msi2500_transfer_one_message(struct spi_master *master,
1162} 1183}
1163 1184
1164static int msi2500_probe(struct usb_interface *intf, 1185static int msi2500_probe(struct usb_interface *intf,
1165 const struct usb_device_id *id) 1186 const struct usb_device_id *id)
1166{ 1187{
1167 struct msi2500_state *s; 1188 struct msi2500_dev *dev;
1168 struct v4l2_subdev *sd; 1189 struct v4l2_subdev *sd;
1169 struct spi_master *master; 1190 struct spi_master *master;
1170 int ret; 1191 int ret;
@@ -1175,65 +1196,65 @@ static int msi2500_probe(struct usb_interface *intf,
1175 .max_speed_hz = 12000000, 1196 .max_speed_hz = 12000000,
1176 }; 1197 };
1177 1198
1178 s = kzalloc(sizeof(struct msi2500_state), GFP_KERNEL); 1199 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1179 if (s == NULL) { 1200 if (!dev) {
1180 dev_err(&intf->dev, "Could not allocate memory for state\n"); 1201 ret = -ENOMEM;
1181 return -ENOMEM; 1202 goto err;
1182 } 1203 }
1183 1204
1184 mutex_init(&s->v4l2_lock); 1205 mutex_init(&dev->v4l2_lock);
1185 mutex_init(&s->vb_queue_lock); 1206 mutex_init(&dev->vb_queue_lock);
1186 spin_lock_init(&s->queued_bufs_lock); 1207 spin_lock_init(&dev->queued_bufs_lock);
1187 INIT_LIST_HEAD(&s->queued_bufs); 1208 INIT_LIST_HEAD(&dev->queued_bufs);
1188 s->dev = &intf->dev; 1209 dev->dev = &intf->dev;
1189 s->udev = interface_to_usbdev(intf); 1210 dev->udev = interface_to_usbdev(intf);
1190 s->f_adc = bands[0].rangelow; 1211 dev->f_adc = bands[0].rangelow;
1191 s->pixelformat = formats[0].pixelformat; 1212 dev->pixelformat = formats[0].pixelformat;
1192 s->buffersize = formats[0].buffersize; 1213 dev->buffersize = formats[0].buffersize;
1193 s->num_formats = NUM_FORMATS; 1214 dev->num_formats = NUM_FORMATS;
1194 if (!msi2500_emulated_fmt) 1215 if (!msi2500_emulated_fmt)
1195 s->num_formats -= 2; 1216 dev->num_formats -= 2;
1196 1217
1197 /* Init videobuf2 queue structure */ 1218 /* Init videobuf2 queue structure */
1198 s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; 1219 dev->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE;
1199 s->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; 1220 dev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1200 s->vb_queue.drv_priv = s; 1221 dev->vb_queue.drv_priv = dev;
1201 s->vb_queue.buf_struct_size = sizeof(struct msi2500_frame_buf); 1222 dev->vb_queue.buf_struct_size = sizeof(struct msi2500_frame_buf);
1202 s->vb_queue.ops = &msi2500_vb2_ops; 1223 dev->vb_queue.ops = &msi2500_vb2_ops;
1203 s->vb_queue.mem_ops = &vb2_vmalloc_memops; 1224 dev->vb_queue.mem_ops = &vb2_vmalloc_memops;
1204 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1225 dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1205 ret = vb2_queue_init(&s->vb_queue); 1226 ret = vb2_queue_init(&dev->vb_queue);
1206 if (ret) { 1227 if (ret) {
1207 dev_err(s->dev, "Could not initialize vb2 queue\n"); 1228 dev_err(dev->dev, "Could not initialize vb2 queue\n");
1208 goto err_free_mem; 1229 goto err_free_mem;
1209 } 1230 }
1210 1231
1211 /* Init video_device structure */ 1232 /* Init video_device structure */
1212 s->vdev = msi2500_template; 1233 dev->vdev = msi2500_template;
1213 s->vdev.queue = &s->vb_queue; 1234 dev->vdev.queue = &dev->vb_queue;
1214 s->vdev.queue->lock = &s->vb_queue_lock; 1235 dev->vdev.queue->lock = &dev->vb_queue_lock;
1215 video_set_drvdata(&s->vdev, s); 1236 video_set_drvdata(&dev->vdev, dev);
1216 1237
1217 /* Register the v4l2_device structure */ 1238 /* Register the v4l2_device structure */
1218 s->v4l2_dev.release = msi2500_video_release; 1239 dev->v4l2_dev.release = msi2500_video_release;
1219 ret = v4l2_device_register(&intf->dev, &s->v4l2_dev); 1240 ret = v4l2_device_register(&intf->dev, &dev->v4l2_dev);
1220 if (ret) { 1241 if (ret) {
1221 dev_err(s->dev, "Failed to register v4l2-device (%d)\n", ret); 1242 dev_err(dev->dev, "Failed to register v4l2-device (%d)\n", ret);
1222 goto err_free_mem; 1243 goto err_free_mem;
1223 } 1244 }
1224 1245
1225 /* SPI master adapter */ 1246 /* SPI master adapter */
1226 master = spi_alloc_master(s->dev, 0); 1247 master = spi_alloc_master(dev->dev, 0);
1227 if (master == NULL) { 1248 if (master == NULL) {
1228 ret = -ENOMEM; 1249 ret = -ENOMEM;
1229 goto err_unregister_v4l2_dev; 1250 goto err_unregister_v4l2_dev;
1230 } 1251 }
1231 1252
1232 s->master = master; 1253 dev->master = master;
1233 master->bus_num = 0; 1254 master->bus_num = 0;
1234 master->num_chipselect = 1; 1255 master->num_chipselect = 1;
1235 master->transfer_one_message = msi2500_transfer_one_message; 1256 master->transfer_one_message = msi2500_transfer_one_message;
1236 spi_master_set_devdata(master, s); 1257 spi_master_set_devdata(master, dev);
1237 ret = spi_register_master(master); 1258 ret = spi_register_master(master);
1238 if (ret) { 1259 if (ret) {
1239 spi_master_put(master); 1260 spi_master_put(master);
@@ -1241,57 +1262,57 @@ static int msi2500_probe(struct usb_interface *intf,
1241 } 1262 }
1242 1263
1243 /* load v4l2 subdevice */ 1264 /* load v4l2 subdevice */
1244 sd = v4l2_spi_new_subdev(&s->v4l2_dev, master, &board_info); 1265 sd = v4l2_spi_new_subdev(&dev->v4l2_dev, master, &board_info);
1245 s->v4l2_subdev = sd; 1266 dev->v4l2_subdev = sd;
1246 if (sd == NULL) { 1267 if (sd == NULL) {
1247 dev_err(s->dev, "cannot get v4l2 subdevice\n"); 1268 dev_err(dev->dev, "cannot get v4l2 subdevice\n");
1248 ret = -ENODEV; 1269 ret = -ENODEV;
1249 goto err_unregister_master; 1270 goto err_unregister_master;
1250 } 1271 }
1251 1272
1252 /* Register controls */ 1273 /* Register controls */
1253 v4l2_ctrl_handler_init(&s->hdl, 0); 1274 v4l2_ctrl_handler_init(&dev->hdl, 0);
1254 if (s->hdl.error) { 1275 if (dev->hdl.error) {
1255 ret = s->hdl.error; 1276 ret = dev->hdl.error;
1256 dev_err(s->dev, "Could not initialize controls\n"); 1277 dev_err(dev->dev, "Could not initialize controls\n");
1257 goto err_free_controls; 1278 goto err_free_controls;
1258 } 1279 }
1259 1280
1260 /* currently all controls are from subdev */ 1281 /* currently all controls are from subdev */
1261 v4l2_ctrl_add_handler(&s->hdl, sd->ctrl_handler, NULL); 1282 v4l2_ctrl_add_handler(&dev->hdl, sd->ctrl_handler, NULL);
1262 1283
1263 s->v4l2_dev.ctrl_handler = &s->hdl; 1284 dev->v4l2_dev.ctrl_handler = &dev->hdl;
1264 s->vdev.v4l2_dev = &s->v4l2_dev; 1285 dev->vdev.v4l2_dev = &dev->v4l2_dev;
1265 s->vdev.lock = &s->v4l2_lock; 1286 dev->vdev.lock = &dev->v4l2_lock;
1266 1287
1267 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); 1288 ret = video_register_device(&dev->vdev, VFL_TYPE_SDR, -1);
1268 if (ret) { 1289 if (ret) {
1269 dev_err(s->dev, "Failed to register as video device (%d)\n", 1290 dev_err(dev->dev,
1270 ret); 1291 "Failed to register as video device (%d)\n", ret);
1271 goto err_unregister_v4l2_dev; 1292 goto err_unregister_v4l2_dev;
1272 } 1293 }
1273 dev_info(s->dev, "Registered as %s\n", 1294 dev_info(dev->dev, "Registered as %s\n",
1274 video_device_node_name(&s->vdev)); 1295 video_device_node_name(&dev->vdev));
1275 dev_notice(s->dev, "SDR API is still slightly experimental and functionality changes may follow\n"); 1296 dev_notice(dev->dev,
1276 1297 "SDR API is still slightly experimental and functionality changes may follow\n");
1277 return 0; 1298 return 0;
1278
1279err_free_controls: 1299err_free_controls:
1280 v4l2_ctrl_handler_free(&s->hdl); 1300 v4l2_ctrl_handler_free(&dev->hdl);
1281err_unregister_master: 1301err_unregister_master:
1282 spi_unregister_master(s->master); 1302 spi_unregister_master(dev->master);
1283err_unregister_v4l2_dev: 1303err_unregister_v4l2_dev:
1284 v4l2_device_unregister(&s->v4l2_dev); 1304 v4l2_device_unregister(&dev->v4l2_dev);
1285err_free_mem: 1305err_free_mem:
1286 kfree(s); 1306 kfree(dev);
1307err:
1287 return ret; 1308 return ret;
1288} 1309}
1289 1310
1290/* USB device ID list */ 1311/* USB device ID list */
1291static struct usb_device_id msi2500_id_table[] = { 1312static struct usb_device_id msi2500_id_table[] = {
1292 { USB_DEVICE(0x1df7, 0x2500) }, /* Mirics MSi3101 SDR Dongle */ 1313 {USB_DEVICE(0x1df7, 0x2500)}, /* Mirics MSi3101 SDR Dongle */
1293 { USB_DEVICE(0x2040, 0xd300) }, /* Hauppauge WinTV 133559 LF */ 1314 {USB_DEVICE(0x2040, 0xd300)}, /* Hauppauge WinTV 133559 LF */
1294 { } 1315 {}
1295}; 1316};
1296MODULE_DEVICE_TABLE(usb, msi2500_id_table); 1317MODULE_DEVICE_TABLE(usb, msi2500_id_table);
1297 1318
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-context.c b/drivers/media/usb/pvrusb2/pvrusb2-context.c
index 924fc4c6019a..fd888a604462 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-context.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-context.c
@@ -398,7 +398,8 @@ int pvr2_channel_claim_stream(struct pvr2_channel *cp,
398 if (!sp) break; 398 if (!sp) break;
399 sp->user = cp; 399 sp->user = cp;
400 cp->stream = sp; 400 cp->stream = sp;
401 } while (0); pvr2_context_exit(cp->mc_head); 401 } while (0);
402 pvr2_context_exit(cp->mc_head);
402 return code; 403 return code;
403} 404}
404 405
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index 930593d7028d..0533ef20decf 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -2602,14 +2602,16 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2602 "Error registering with v4l core, giving up"); 2602 "Error registering with v4l core, giving up");
2603 goto fail; 2603 goto fail;
2604 } 2604 }
2605 mutex_lock(&pvr2_unit_mtx); do { 2605 mutex_lock(&pvr2_unit_mtx);
2606 do {
2606 for (idx = 0; idx < PVR_NUM; idx++) { 2607 for (idx = 0; idx < PVR_NUM; idx++) {
2607 if (unit_pointers[idx]) continue; 2608 if (unit_pointers[idx]) continue;
2608 hdw->unit_number = idx; 2609 hdw->unit_number = idx;
2609 unit_pointers[idx] = hdw; 2610 unit_pointers[idx] = hdw;
2610 break; 2611 break;
2611 } 2612 }
2612 } while (0); mutex_unlock(&pvr2_unit_mtx); 2613 } while (0);
2614 mutex_unlock(&pvr2_unit_mtx);
2613 2615
2614 cnt1 = 0; 2616 cnt1 = 0;
2615 cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2"); 2617 cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2");
@@ -2730,13 +2732,15 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2730 pvr2_i2c_core_done(hdw); 2732 pvr2_i2c_core_done(hdw);
2731 v4l2_device_unregister(&hdw->v4l2_dev); 2733 v4l2_device_unregister(&hdw->v4l2_dev);
2732 pvr2_hdw_remove_usb_stuff(hdw); 2734 pvr2_hdw_remove_usb_stuff(hdw);
2733 mutex_lock(&pvr2_unit_mtx); do { 2735 mutex_lock(&pvr2_unit_mtx);
2736 do {
2734 if ((hdw->unit_number >= 0) && 2737 if ((hdw->unit_number >= 0) &&
2735 (hdw->unit_number < PVR_NUM) && 2738 (hdw->unit_number < PVR_NUM) &&
2736 (unit_pointers[hdw->unit_number] == hdw)) { 2739 (unit_pointers[hdw->unit_number] == hdw)) {
2737 unit_pointers[hdw->unit_number] = NULL; 2740 unit_pointers[hdw->unit_number] = NULL;
2738 } 2741 }
2739 } while (0); mutex_unlock(&pvr2_unit_mtx); 2742 } while (0);
2743 mutex_unlock(&pvr2_unit_mtx);
2740 kfree(hdw->controls); 2744 kfree(hdw->controls);
2741 kfree(hdw->mpeg_ctrl_info); 2745 kfree(hdw->mpeg_ctrl_info);
2742 kfree(hdw); 2746 kfree(hdw);
@@ -2958,14 +2962,17 @@ static void pvr2_subdev_update(struct pvr2_hdw *hdw)
2958 } 2962 }
2959 2963
2960 if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->force_dirty) { 2964 if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->force_dirty) {
2961 struct v4l2_mbus_framefmt fmt; 2965 struct v4l2_subdev_format format = {
2962 memset(&fmt, 0, sizeof(fmt)); 2966 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
2963 fmt.width = hdw->res_hor_val; 2967 };
2964 fmt.height = hdw->res_ver_val; 2968
2965 fmt.code = MEDIA_BUS_FMT_FIXED; 2969 format.format.width = hdw->res_hor_val;
2970 format.format.height = hdw->res_ver_val;
2971 format.format.code = MEDIA_BUS_FMT_FIXED;
2966 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_size(%dx%d)", 2972 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_size(%dx%d)",
2967 fmt.width, fmt.height); 2973 format.format.width, format.format.height);
2968 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_mbus_fmt, &fmt); 2974 v4l2_device_call_all(&hdw->v4l2_dev, 0, pad, set_fmt,
2975 NULL, &format);
2969 } 2976 }
2970 2977
2971 if (hdw->srate_dirty || hdw->force_dirty) { 2978 if (hdw->srate_dirty || hdw->force_dirty) {
@@ -3343,14 +3350,16 @@ struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *hp)
3343void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw) 3350void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
3344{ 3351{
3345 int nr = pvr2_hdw_get_unit_number(hdw); 3352 int nr = pvr2_hdw_get_unit_number(hdw);
3346 LOCK_TAKE(hdw->big_lock); do { 3353 LOCK_TAKE(hdw->big_lock);
3354 do {
3347 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr); 3355 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
3348 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status); 3356 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status);
3349 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:"); 3357 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
3350 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2"); 3358 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
3351 pvr2_hdw_state_log_state(hdw); 3359 pvr2_hdw_state_log_state(hdw);
3352 printk(KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr); 3360 printk(KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr);
3353 } while (0); LOCK_GIVE(hdw->big_lock); 3361 } while (0);
3362 LOCK_GIVE(hdw->big_lock);
3354} 3363}
3355 3364
3356 3365
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-io.c b/drivers/media/usb/pvrusb2/pvrusb2-io.c
index 0c08f22bdfce..d860344de84e 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-io.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-io.c
@@ -514,12 +514,14 @@ void pvr2_stream_set_callback(struct pvr2_stream *sp,
514 void *data) 514 void *data)
515{ 515{
516 unsigned long irq_flags; 516 unsigned long irq_flags;
517 mutex_lock(&sp->mutex); do { 517 mutex_lock(&sp->mutex);
518 do {
518 spin_lock_irqsave(&sp->list_lock,irq_flags); 519 spin_lock_irqsave(&sp->list_lock,irq_flags);
519 sp->callback_data = data; 520 sp->callback_data = data;
520 sp->callback_func = func; 521 sp->callback_func = func;
521 spin_unlock_irqrestore(&sp->list_lock,irq_flags); 522 spin_unlock_irqrestore(&sp->list_lock,irq_flags);
522 } while(0); mutex_unlock(&sp->mutex); 523 } while(0);
524 mutex_unlock(&sp->mutex);
523} 525}
524 526
525void pvr2_stream_get_stats(struct pvr2_stream *sp, 527void pvr2_stream_get_stats(struct pvr2_stream *sp,
@@ -554,10 +556,12 @@ int pvr2_stream_set_buffer_count(struct pvr2_stream *sp,unsigned int cnt)
554{ 556{
555 int ret; 557 int ret;
556 if (sp->buffer_target_count == cnt) return 0; 558 if (sp->buffer_target_count == cnt) return 0;
557 mutex_lock(&sp->mutex); do { 559 mutex_lock(&sp->mutex);
560 do {
558 sp->buffer_target_count = cnt; 561 sp->buffer_target_count = cnt;
559 ret = pvr2_stream_achieve_buffer_count(sp); 562 ret = pvr2_stream_achieve_buffer_count(sp);
560 } while(0); mutex_unlock(&sp->mutex); 563 } while(0);
564 mutex_unlock(&sp->mutex);
561 return ret; 565 return ret;
562} 566}
563 567
@@ -590,7 +594,8 @@ int pvr2_stream_get_ready_count(struct pvr2_stream *sp)
590void pvr2_stream_kill(struct pvr2_stream *sp) 594void pvr2_stream_kill(struct pvr2_stream *sp)
591{ 595{
592 struct pvr2_buffer *bp; 596 struct pvr2_buffer *bp;
593 mutex_lock(&sp->mutex); do { 597 mutex_lock(&sp->mutex);
598 do {
594 pvr2_stream_internal_flush(sp); 599 pvr2_stream_internal_flush(sp);
595 while ((bp = pvr2_stream_get_ready_buffer(sp)) != NULL) { 600 while ((bp = pvr2_stream_get_ready_buffer(sp)) != NULL) {
596 pvr2_buffer_set_idle(bp); 601 pvr2_buffer_set_idle(bp);
@@ -598,7 +603,8 @@ void pvr2_stream_kill(struct pvr2_stream *sp)
598 if (sp->buffer_total_count != sp->buffer_target_count) { 603 if (sp->buffer_total_count != sp->buffer_target_count) {
599 pvr2_stream_achieve_buffer_count(sp); 604 pvr2_stream_achieve_buffer_count(sp);
600 } 605 }
601 } while(0); mutex_unlock(&sp->mutex); 606 } while(0);
607 mutex_unlock(&sp->mutex);
602} 608}
603 609
604int pvr2_buffer_queue(struct pvr2_buffer *bp) 610int pvr2_buffer_queue(struct pvr2_buffer *bp)
@@ -612,7 +618,8 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp)
612 struct pvr2_stream *sp; 618 struct pvr2_stream *sp;
613 if (!bp) return -EINVAL; 619 if (!bp) return -EINVAL;
614 sp = bp->stream; 620 sp = bp->stream;
615 mutex_lock(&sp->mutex); do { 621 mutex_lock(&sp->mutex);
622 do {
616 pvr2_buffer_wipe(bp); 623 pvr2_buffer_wipe(bp);
617 if (!sp->dev) { 624 if (!sp->dev) {
618 ret = -EIO; 625 ret = -EIO;
@@ -636,7 +643,8 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp)
636 buffer_complete, 643 buffer_complete,
637 bp); 644 bp);
638 usb_submit_urb(bp->purb,GFP_KERNEL); 645 usb_submit_urb(bp->purb,GFP_KERNEL);
639 } while(0); mutex_unlock(&sp->mutex); 646 } while(0);
647 mutex_unlock(&sp->mutex);
640 return ret; 648 return ret;
641} 649}
642 650
@@ -647,7 +655,8 @@ int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt)
647 struct pvr2_stream *sp; 655 struct pvr2_stream *sp;
648 if (!bp) return -EINVAL; 656 if (!bp) return -EINVAL;
649 sp = bp->stream; 657 sp = bp->stream;
650 mutex_lock(&sp->mutex); do { 658 mutex_lock(&sp->mutex);
659 do {
651 spin_lock_irqsave(&sp->list_lock,irq_flags); 660 spin_lock_irqsave(&sp->list_lock,irq_flags);
652 if (bp->state != pvr2_buffer_state_idle) { 661 if (bp->state != pvr2_buffer_state_idle) {
653 ret = -EPERM; 662 ret = -EPERM;
@@ -664,7 +673,8 @@ int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt)
664 bp->stream->i_bcount,bp->stream->i_count); 673 bp->stream->i_bcount,bp->stream->i_count);
665 } 674 }
666 spin_unlock_irqrestore(&sp->list_lock,irq_flags); 675 spin_unlock_irqrestore(&sp->list_lock,irq_flags);
667 } while(0); mutex_unlock(&sp->mutex); 676 } while(0);
677 mutex_unlock(&sp->mutex);
668 return ret; 678 return ret;
669} 679}
670 680
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
index cd995b54732e..614d55767a4e 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
@@ -205,7 +205,8 @@ int pvr2_ioread_setup(struct pvr2_ioread *cp,struct pvr2_stream *sp)
205 unsigned int idx; 205 unsigned int idx;
206 struct pvr2_buffer *bp; 206 struct pvr2_buffer *bp;
207 207
208 mutex_lock(&cp->mutex); do { 208 mutex_lock(&cp->mutex);
209 do {
209 if (cp->stream) { 210 if (cp->stream) {
210 pvr2_trace(PVR2_TRACE_START_STOP, 211 pvr2_trace(PVR2_TRACE_START_STOP,
211 "/*---TRACE_READ---*/" 212 "/*---TRACE_READ---*/"
@@ -235,7 +236,8 @@ int pvr2_ioread_setup(struct pvr2_ioread *cp,struct pvr2_stream *sp)
235 } 236 }
236 cp->stream = sp; 237 cp->stream = sp;
237 } 238 }
238 } while (0); mutex_unlock(&cp->mutex); 239 } while (0);
240 mutex_unlock(&cp->mutex);
239 241
240 return 0; 242 return 0;
241} 243}
@@ -245,13 +247,15 @@ int pvr2_ioread_set_enabled(struct pvr2_ioread *cp,int fl)
245 int ret = 0; 247 int ret = 0;
246 if ((!fl) == (!(cp->enabled))) return ret; 248 if ((!fl) == (!(cp->enabled))) return ret;
247 249
248 mutex_lock(&cp->mutex); do { 250 mutex_lock(&cp->mutex);
251 do {
249 if (fl) { 252 if (fl) {
250 ret = pvr2_ioread_start(cp); 253 ret = pvr2_ioread_start(cp);
251 } else { 254 } else {
252 pvr2_ioread_stop(cp); 255 pvr2_ioread_stop(cp);
253 } 256 }
254 } while (0); mutex_unlock(&cp->mutex); 257 } while (0);
258 mutex_unlock(&cp->mutex);
255 return ret; 259 return ret;
256} 260}
257 261
@@ -315,7 +319,8 @@ static void pvr2_ioread_filter(struct pvr2_ioread *cp)
315 // Search the stream for our synchronization key. This is made 319 // Search the stream for our synchronization key. This is made
316 // complicated by the fact that in order to be honest with 320 // complicated by the fact that in order to be honest with
317 // ourselves here we must search across buffer boundaries... 321 // ourselves here we must search across buffer boundaries...
318 mutex_lock(&cp->mutex); while (1) { 322 mutex_lock(&cp->mutex);
323 while (1) {
319 // Ensure we have a buffer 324 // Ensure we have a buffer
320 if (!pvr2_ioread_get_buffer(cp)) break; 325 if (!pvr2_ioread_get_buffer(cp)) break;
321 if (!cp->c_data_len) break; 326 if (!cp->c_data_len) break;
@@ -362,7 +367,8 @@ static void pvr2_ioread_filter(struct pvr2_ioread *cp)
362 } 367 }
363 368
364 continue; // (for clarity) 369 continue; // (for clarity)
365 } mutex_unlock(&cp->mutex); 370 }
371 mutex_unlock(&cp->mutex);
366} 372}
367 373
368int pvr2_ioread_avail(struct pvr2_ioread *cp) 374int pvr2_ioread_avail(struct pvr2_ioread *cp)
@@ -422,7 +428,8 @@ int pvr2_ioread_read(struct pvr2_ioread *cp,void __user *buf,unsigned int cnt)
422 428
423 cp->stream_running = !0; 429 cp->stream_running = !0;
424 430
425 mutex_lock(&cp->mutex); do { 431 mutex_lock(&cp->mutex);
432 do {
426 433
427 // Suck data out of the buffers and copy to the user 434 // Suck data out of the buffers and copy to the user
428 copied_cnt = 0; 435 copied_cnt = 0;
@@ -480,7 +487,8 @@ int pvr2_ioread_read(struct pvr2_ioread *cp,void __user *buf,unsigned int cnt)
480 } 487 }
481 } 488 }
482 489
483 } while (0); mutex_unlock(&cp->mutex); 490 } while (0);
491 mutex_unlock(&cp->mutex);
484 492
485 if (!ret) { 493 if (!ret) {
486 if (copied_cnt) { 494 if (copied_cnt) {
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index 749ad5603c9e..4d313ed4c32e 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -500,6 +500,7 @@ static const struct v4l2_ioctl_ops stk1160_ioctl_ops = {
500 .vidioc_dqbuf = vb2_ioctl_dqbuf, 500 .vidioc_dqbuf = vb2_ioctl_dqbuf,
501 .vidioc_streamon = vb2_ioctl_streamon, 501 .vidioc_streamon = vb2_ioctl_streamon,
502 .vidioc_streamoff = vb2_ioctl_streamoff, 502 .vidioc_streamoff = vb2_ioctl_streamoff,
503 .vidioc_expbuf = vb2_ioctl_expbuf,
503 504
504 .vidioc_log_status = v4l2_ctrl_log_status, 505 .vidioc_log_status = v4l2_ctrl_log_status,
505 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 506 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
@@ -645,7 +646,7 @@ int stk1160_vb2_setup(struct stk1160 *dev)
645 646
646 q = &dev->vb_vidq; 647 q = &dev->vb_vidq;
647 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 648 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
648 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR; 649 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
649 q->drv_priv = dev; 650 q->drv_priv = dev;
650 q->buf_struct_size = sizeof(struct stk1160_buffer); 651 q->buf_struct_size = sizeof(struct stk1160_buffer);
651 q->ops = &stk1160_video_qops; 652 q->ops = &stk1160_video_qops;
diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c
index 77ce9efe1f24..fa5e8bda2ae4 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -621,7 +621,7 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
621 dev->isoc_in.maxsize, size); 621 dev->isoc_in.maxsize, size);
622 622
623 623
624 if (!dev->urb_buffer && tm6000_alloc_urb_buffers(dev) < 0) { 624 if (tm6000_alloc_urb_buffers(dev) < 0) {
625 tm6000_err("cannot allocate memory for urb buffers\n"); 625 tm6000_err("cannot allocate memory for urb buffers\n");
626 626
627 /* call free, as some buffers might have been allocated */ 627 /* call free, as some buffers might have been allocated */
@@ -714,8 +714,7 @@ static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
714 struct tm6000_core *dev = fh->dev; 714 struct tm6000_core *dev = fh->dev;
715 unsigned long flags; 715 unsigned long flags;
716 716
717 if (in_interrupt()) 717 BUG_ON(in_interrupt());
718 BUG();
719 718
720 /* We used to wait for the buffer to finish here, but this didn't work 719 /* We used to wait for the buffer to finish here, but this didn't work
721 because, as we were keeping the state as VIDEOBUF_QUEUED, 720 because, as we were keeping the state as VIDEOBUF_QUEUED,
diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
index cef7a00099ea..d52d4a8d39ad 100644
--- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
@@ -111,8 +111,8 @@ struct ttusb {
111 int last_filter; 111 int last_filter;
112 112
113 u8 c; /* transaction counter, wraps around... */ 113 u8 c; /* transaction counter, wraps around... */
114 fe_sec_tone_mode_t tone; 114 enum fe_sec_tone_mode tone;
115 fe_sec_voltage_t voltage; 115 enum fe_sec_voltage voltage;
116 116
117 int mux_state; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack 117 int mux_state; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack
118 u8 mux_npacks; 118 u8 mux_npacks;
@@ -511,7 +511,8 @@ static int ttusb_update_lnb(struct ttusb *ttusb)
511 return err; 511 return err;
512} 512}
513 513
514static int ttusb_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 514static int ttusb_set_voltage(struct dvb_frontend *fe,
515 enum fe_sec_voltage voltage)
515{ 516{
516 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv; 517 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
517 518
@@ -520,7 +521,7 @@ static int ttusb_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
520} 521}
521 522
522#ifdef TTUSB_TONE 523#ifdef TTUSB_TONE
523static int ttusb_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 524static int ttusb_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
524{ 525{
525 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv; 526 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
526 527
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 15ab584cf265..322b53a4f1dd 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -1431,8 +1431,8 @@ static int ttusb_dec_init_stb(struct ttusb_dec *dec)
1431 __func__, model); 1431 __func__, model);
1432 return -ENOENT; 1432 return -ENOENT;
1433 } 1433 }
1434 if (version >= 0x01770000) 1434 if (version >= 0x01770000)
1435 dec->can_playback = 1; 1435 dec->can_playback = 1;
1436 } 1436 }
1437 return 0; 1437 return 0;
1438} 1438}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 9c29552aedec..8781335ab92f 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -39,7 +39,7 @@ struct ttusbdecfe_state {
39 39
40 40
41static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe, 41static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
42 fe_status_t *status) 42 enum fe_status *status)
43{ 43{
44 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | 44 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
45 FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK; 45 FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
@@ -48,7 +48,7 @@ static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
48 48
49 49
50static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe, 50static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
51 fe_status_t *status) 51 enum fe_status *status)
52{ 52{
53 struct ttusbdecfe_state* state = fe->demodulator_priv; 53 struct ttusbdecfe_state* state = fe->demodulator_priv;
54 u8 b[] = { 0x00, 0x00, 0x00, 0x00, 54 u8 b[] = { 0x00, 0x00, 0x00, 0x00,
@@ -169,7 +169,8 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
169} 169}
170 170
171 171
172static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 172static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend *fe,
173 enum fe_sec_tone_mode tone)
173{ 174{
174 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv; 175 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
175 176
@@ -179,7 +180,8 @@ static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t
179} 180}
180 181
181 182
182static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 183static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend *fe,
184 enum fe_sec_voltage voltage)
183{ 185{
184 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv; 186 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
185 187
diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
index 9d3525f659f0..08fb0f2da64d 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -599,15 +599,18 @@ static struct v4l2_file_operations usbtv_fops = {
599}; 599};
600 600
601static int usbtv_queue_setup(struct vb2_queue *vq, 601static int usbtv_queue_setup(struct vb2_queue *vq,
602 const struct v4l2_format *v4l_fmt, unsigned int *nbuffers, 602 const struct v4l2_format *fmt, unsigned int *nbuffers,
603 unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) 603 unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
604{ 604{
605 struct usbtv *usbtv = vb2_get_drv_priv(vq); 605 struct usbtv *usbtv = vb2_get_drv_priv(vq);
606 unsigned size = USBTV_CHUNK * usbtv->n_chunks * 2 * sizeof(u32);
606 607
607 if (*nbuffers < 2) 608 if (vq->num_buffers + *nbuffers < 2)
608 *nbuffers = 2; 609 *nbuffers = 2 - vq->num_buffers;
609 *nplanes = 1; 610 *nplanes = 1;
610 sizes[0] = USBTV_CHUNK * usbtv->n_chunks * 2 * sizeof(u32); 611 if (fmt && fmt->fmt.pix.sizeimage < size)
612 return -EINVAL;
613 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
611 614
612 return 0; 615 return 0;
613} 616}
@@ -635,6 +638,7 @@ static int usbtv_start_streaming(struct vb2_queue *vq, unsigned int count)
635 if (usbtv->udev == NULL) 638 if (usbtv->udev == NULL)
636 return -ENODEV; 639 return -ENODEV;
637 640
641 usbtv->sequence = 0;
638 return usbtv_start(usbtv); 642 return usbtv_start(usbtv);
639} 643}
640 644
diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c
index 44b0c28d69b6..7c04ef697fb6 100644
--- a/drivers/media/usb/usbvision/usbvision-core.c
+++ b/drivers/media/usb/usbvision/usbvision-core.c
@@ -2390,8 +2390,8 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2390 2390
2391 /* Submit all URBs */ 2391 /* Submit all URBs */
2392 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { 2392 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
2393 err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb, 2393 err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb,
2394 GFP_KERNEL); 2394 GFP_KERNEL);
2395 if (err_code) { 2395 if (err_code) {
2396 dev_err(&usbvision->dev->dev, 2396 dev_err(&usbvision->dev->dev,
2397 "%s: usb_submit_urb(%d) failed: error %d\n", 2397 "%s: usb_submit_urb(%d) failed: error %d\n",
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
index 12b403e78d52..1c6d31f7c1b9 100644
--- a/drivers/media/usb/usbvision/usbvision-video.c
+++ b/drivers/media/usb/usbvision/usbvision-video.c
@@ -1061,13 +1061,24 @@ static ssize_t usbvision_read(struct file *file, char __user *buf,
1061 __func__, 1061 __func__,
1062 (unsigned long)count, frame->bytes_read); 1062 (unsigned long)count, frame->bytes_read);
1063 1063
1064 /* For now, forget the frame if it has not been read in one shot. */ 1064#if 1
1065/* if (frame->bytes_read >= frame->scanlength) {*/ /* All data has been read */ 1065 /*
1066 * FIXME:
1067 * For now, forget the frame if it has not been read in one shot.
1068 */
1069 frame->bytes_read = 0;
1070
1071 /* Mark it as available to be used again. */
1072 frame->grabstate = frame_state_unused;
1073#else
1074 if (frame->bytes_read >= frame->scanlength) {
1075 /* All data has been read */
1066 frame->bytes_read = 0; 1076 frame->bytes_read = 0;
1067 1077
1068 /* Mark it as available to be used again. */ 1078 /* Mark it as available to be used again. */
1069 frame->grabstate = frame_state_unused; 1079 frame->grabstate = frame_state_unused;
1070/* } */ 1080 }
1081#endif
1071 1082
1072 return count; 1083 return count;
1073} 1084}
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 5970dd6a1c1c..4b5b3e8fb7d3 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -1967,8 +1967,6 @@ static void uvc_disconnect(struct usb_interface *intf)
1967 UVC_SC_VIDEOSTREAMING) 1967 UVC_SC_VIDEOSTREAMING)
1968 return; 1968 return;
1969 1969
1970 dev->state |= UVC_DEV_DISCONNECTED;
1971
1972 uvc_unregister_video(dev); 1970 uvc_unregister_video(dev);
1973} 1971}
1974 1972
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 87a19f33e460..f16b9b42689d 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -270,6 +270,18 @@ int uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
270 return ret; 270 return ret;
271} 271}
272 272
273int uvc_export_buffer(struct uvc_video_queue *queue,
274 struct v4l2_exportbuffer *exp)
275{
276 int ret;
277
278 mutex_lock(&queue->mutex);
279 ret = vb2_expbuf(&queue->queue, exp);
280 mutex_unlock(&queue->mutex);
281
282 return ret;
283}
284
273int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, 285int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf,
274 int nonblocking) 286 int nonblocking)
275{ 287{
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index c4b1ac6750d8..2764f43607c1 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -483,9 +483,6 @@ static int uvc_v4l2_open(struct file *file)
483 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); 483 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
484 stream = video_drvdata(file); 484 stream = video_drvdata(file);
485 485
486 if (stream->dev->state & UVC_DEV_DISCONNECTED)
487 return -ENODEV;
488
489 ret = usb_autopm_get_interface(stream->dev->intf); 486 ret = usb_autopm_get_interface(stream->dev->intf);
490 if (ret < 0) 487 if (ret < 0)
491 return ret; 488 return ret;
@@ -723,6 +720,18 @@ static int uvc_ioctl_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
723 return uvc_queue_buffer(&stream->queue, buf); 720 return uvc_queue_buffer(&stream->queue, buf);
724} 721}
725 722
723static int uvc_ioctl_expbuf(struct file *file, void *fh,
724 struct v4l2_exportbuffer *exp)
725{
726 struct uvc_fh *handle = fh;
727 struct uvc_streaming *stream = handle->stream;
728
729 if (!uvc_has_privileges(handle))
730 return -EBUSY;
731
732 return uvc_export_buffer(&stream->queue, exp);
733}
734
726static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) 735static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
727{ 736{
728 struct uvc_fh *handle = fh; 737 struct uvc_fh *handle = fh;
@@ -1478,6 +1487,7 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = {
1478 .vidioc_reqbufs = uvc_ioctl_reqbufs, 1487 .vidioc_reqbufs = uvc_ioctl_reqbufs,
1479 .vidioc_querybuf = uvc_ioctl_querybuf, 1488 .vidioc_querybuf = uvc_ioctl_querybuf,
1480 .vidioc_qbuf = uvc_ioctl_qbuf, 1489 .vidioc_qbuf = uvc_ioctl_qbuf,
1490 .vidioc_expbuf = uvc_ioctl_expbuf,
1481 .vidioc_dqbuf = uvc_ioctl_dqbuf, 1491 .vidioc_dqbuf = uvc_ioctl_dqbuf,
1482 .vidioc_create_bufs = uvc_ioctl_create_bufs, 1492 .vidioc_create_bufs = uvc_ioctl_create_bufs,
1483 .vidioc_streamon = uvc_ioctl_streamon, 1493 .vidioc_streamon = uvc_ioctl_streamon,
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 20ccc9d315dc..f839654ea436 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -119,6 +119,14 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
119 ctrl->dwMaxVideoFrameSize = 119 ctrl->dwMaxVideoFrameSize =
120 frame->dwMaxVideoFrameBufferSize; 120 frame->dwMaxVideoFrameBufferSize;
121 121
122 /* The "TOSHIBA Web Camera - 5M" Chicony device (04f2:b50b) seems to
123 * compute the bandwidth on 16 bits and erroneously sign-extend it to
124 * 32 bits, resulting in a huge bandwidth value. Detect and fix that
125 * condition by setting the 16 MSBs to 0 when they're all equal to 1.
126 */
127 if ((ctrl->dwMaxPayloadTransferSize & 0xffff0000) == 0xffff0000)
128 ctrl->dwMaxPayloadTransferSize &= ~0xffff0000;
129
122 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) && 130 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) &&
123 stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && 131 stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH &&
124 stream->intf->num_altsetting > 1) { 132 stream->intf->num_altsetting > 1) {
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 1b594c203992..816dd1a0fd81 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -517,10 +517,6 @@ struct uvc_streaming {
517 } clock; 517 } clock;
518}; 518};
519 519
520enum uvc_device_state {
521 UVC_DEV_DISCONNECTED = 1,
522};
523
524struct uvc_device { 520struct uvc_device {
525 struct usb_device *udev; 521 struct usb_device *udev;
526 struct usb_interface *intf; 522 struct usb_interface *intf;
@@ -529,7 +525,6 @@ struct uvc_device {
529 int intfnum; 525 int intfnum;
530 char name[32]; 526 char name[32];
531 527
532 enum uvc_device_state state;
533 struct mutex lock; /* Protects users */ 528 struct mutex lock; /* Protects users */
534 unsigned int users; 529 unsigned int users;
535 atomic_t nmappings; 530 atomic_t nmappings;
@@ -635,6 +630,8 @@ extern int uvc_create_buffers(struct uvc_video_queue *queue,
635 struct v4l2_create_buffers *v4l2_cb); 630 struct v4l2_create_buffers *v4l2_cb);
636extern int uvc_queue_buffer(struct uvc_video_queue *queue, 631extern int uvc_queue_buffer(struct uvc_video_queue *queue,
637 struct v4l2_buffer *v4l2_buf); 632 struct v4l2_buffer *v4l2_buf);
633extern int uvc_export_buffer(struct uvc_video_queue *queue,
634 struct v4l2_exportbuffer *exp);
638extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, 635extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
639 struct v4l2_buffer *v4l2_buf, int nonblocking); 636 struct v4l2_buffer *v4l2_buf, int nonblocking);
640extern int uvc_queue_streamon(struct uvc_video_queue *queue, 637extern int uvc_queue_streamon(struct uvc_video_queue *queue,
diff --git a/drivers/media/usb/zr364xx/zr364xx.c b/drivers/media/usb/zr364xx/zr364xx.c
index ca850316d379..7433ba5c4bad 100644
--- a/drivers/media/usb/zr364xx/zr364xx.c
+++ b/drivers/media/usb/zr364xx/zr364xx.c
@@ -377,8 +377,7 @@ static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer *buf)
377{ 377{
378 _DBG("%s\n", __func__); 378 _DBG("%s\n", __func__);
379 379
380 if (in_interrupt()) 380 BUG_ON(in_interrupt());
381 BUG();
382 381
383 videobuf_vmalloc_free(&buf->vb); 382 videobuf_vmalloc_free(&buf->vb);
384 buf->vb.state = VIDEOBUF_NEEDS_INIT; 383 buf->vb.state = VIDEOBUF_NEEDS_INIT;
diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig
index ba7e21a73023..f7a01a72eb9e 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -89,7 +89,7 @@ config VIDEOBUF2_VMALLOC
89 89
90config VIDEOBUF2_DMA_SG 90config VIDEOBUF2_DMA_SG
91 tristate 91 tristate
92 #depends on HAS_DMA 92 depends on HAS_DMA
93 select VIDEOBUF2_CORE 93 select VIDEOBUF2_CORE
94 select VIDEOBUF2_MEMOPS 94 select VIDEOBUF2_MEMOPS
95 95
diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c
index c0e96382feba..04dc71e3ebf0 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -25,6 +25,7 @@
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <linux/v4l2-dv-timings.h> 26#include <linux/v4l2-dv-timings.h>
27#include <media/v4l2-dv-timings.h> 27#include <media/v4l2-dv-timings.h>
28#include <linux/math64.h>
28 29
29MODULE_AUTHOR("Hans Verkuil"); 30MODULE_AUTHOR("Hans Verkuil");
30MODULE_DESCRIPTION("V4L2 DV Timings Helper Functions"); 31MODULE_DESCRIPTION("V4L2 DV Timings Helper Functions");
@@ -261,6 +262,8 @@ void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
261 262
262 htot = V4L2_DV_BT_FRAME_WIDTH(bt); 263 htot = V4L2_DV_BT_FRAME_WIDTH(bt);
263 vtot = V4L2_DV_BT_FRAME_HEIGHT(bt); 264 vtot = V4L2_DV_BT_FRAME_HEIGHT(bt);
265 if (bt->interlaced)
266 vtot /= 2;
264 267
265 if (prefix == NULL) 268 if (prefix == NULL)
266 prefix = ""; 269 prefix = "";
@@ -281,6 +284,11 @@ void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
281 dev_prefix, bt->vfrontporch, 284 dev_prefix, bt->vfrontporch,
282 (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-", 285 (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
283 bt->vsync, bt->vbackporch); 286 bt->vsync, bt->vbackporch);
287 if (bt->interlaced)
288 pr_info("%s: vertical bottom field: fp = %u, %ssync = %u, bp = %u\n",
289 dev_prefix, bt->il_vfrontporch,
290 (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
291 bt->il_vsync, bt->il_vbackporch);
284 pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock); 292 pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock);
285 pr_info("%s: flags (0x%x):%s%s%s%s%s\n", dev_prefix, bt->flags, 293 pr_info("%s: flags (0x%x):%s%s%s%s%s\n", dev_prefix, bt->flags,
286 (bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ? 294 (bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ?
@@ -313,6 +321,7 @@ EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
313#define CVT_MIN_V_BPORCH 7 /* lines */ 321#define CVT_MIN_V_BPORCH 7 /* lines */
314#define CVT_MIN_V_PORCH_RND 3 /* lines */ 322#define CVT_MIN_V_PORCH_RND 3 /* lines */
315#define CVT_MIN_VSYNC_BP 550 /* min time of vsync + back porch (us) */ 323#define CVT_MIN_VSYNC_BP 550 /* min time of vsync + back porch (us) */
324#define CVT_HSYNC_PERCENT 8 /* nominal hsync as percentage of line */
316 325
317/* Normal blanking for CVT uses GTF to calculate horizontal blanking */ 326/* Normal blanking for CVT uses GTF to calculate horizontal blanking */
318#define CVT_CELL_GRAN 8 /* character cell granularity */ 327#define CVT_CELL_GRAN 8 /* character cell granularity */
@@ -337,6 +346,7 @@ EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
337 * @vsync - the height of the vertical sync in lines. 346 * @vsync - the height of the vertical sync in lines.
338 * @polarities - the horizontal and vertical polarities (same as struct 347 * @polarities - the horizontal and vertical polarities (same as struct
339 * v4l2_bt_timings polarities). 348 * v4l2_bt_timings polarities).
349 * @interlaced - if this flag is true, it indicates interlaced format
340 * @fmt - the resulting timings. 350 * @fmt - the resulting timings.
341 * 351 *
342 * This function will attempt to detect if the given values correspond to a 352 * This function will attempt to detect if the given values correspond to a
@@ -348,7 +358,7 @@ EXPORT_SYMBOL_GPL(v4l2_print_dv_timings);
348 * detection function. 358 * detection function.
349 */ 359 */
350bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 360bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
351 u32 polarities, struct v4l2_dv_timings *fmt) 361 u32 polarities, bool interlaced, struct v4l2_dv_timings *fmt)
352{ 362{
353 int v_fp, v_bp, h_fp, h_bp, hsync; 363 int v_fp, v_bp, h_fp, h_bp, hsync;
354 int frame_width, image_height, image_width; 364 int frame_width, image_height, image_width;
@@ -365,22 +375,32 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
365 else 375 else
366 return false; 376 return false;
367 377
378 if (hfreq == 0)
379 return false;
380
368 /* Vertical */ 381 /* Vertical */
369 if (reduced_blanking) { 382 if (reduced_blanking) {
370 v_fp = CVT_RB_V_FPORCH; 383 v_fp = CVT_RB_V_FPORCH;
371 v_bp = (CVT_RB_MIN_V_BLANK * hfreq + 1999999) / 1000000; 384 v_bp = (CVT_RB_MIN_V_BLANK * hfreq) / 1000000 + 1;
372 v_bp -= vsync + v_fp; 385 v_bp -= vsync + v_fp;
373 386
374 if (v_bp < CVT_RB_MIN_V_BPORCH) 387 if (v_bp < CVT_RB_MIN_V_BPORCH)
375 v_bp = CVT_RB_MIN_V_BPORCH; 388 v_bp = CVT_RB_MIN_V_BPORCH;
376 } else { 389 } else {
377 v_fp = CVT_MIN_V_PORCH_RND; 390 v_fp = CVT_MIN_V_PORCH_RND;
378 v_bp = (CVT_MIN_VSYNC_BP * hfreq + 1999999) / 1000000 - vsync; 391 v_bp = (CVT_MIN_VSYNC_BP * hfreq) / 1000000 + 1 - vsync;
379 392
380 if (v_bp < CVT_MIN_V_BPORCH) 393 if (v_bp < CVT_MIN_V_BPORCH)
381 v_bp = CVT_MIN_V_BPORCH; 394 v_bp = CVT_MIN_V_BPORCH;
382 } 395 }
383 image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1; 396
397 if (interlaced)
398 image_height = (frame_height - 2 * v_fp - 2 * vsync - 2 * v_bp) & ~0x1;
399 else
400 image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
401
402 if (image_height < 0)
403 return false;
384 404
385 /* Aspect ratio based on vsync */ 405 /* Aspect ratio based on vsync */
386 switch (vsync) { 406 switch (vsync) {
@@ -436,8 +456,8 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
436 h_bp = h_blank / 2; 456 h_bp = h_blank / 2;
437 frame_width = image_width + h_blank; 457 frame_width = image_width + h_blank;
438 458
439 hsync = (frame_width * 8 + 50) / 100; 459 hsync = frame_width * CVT_HSYNC_PERCENT / 100;
440 hsync = hsync - hsync % CVT_CELL_GRAN; 460 hsync = (hsync / CVT_CELL_GRAN) * CVT_CELL_GRAN;
441 h_fp = h_blank - hsync - h_bp; 461 h_fp = h_blank - hsync - h_bp;
442 } 462 }
443 463
@@ -450,11 +470,27 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
450 fmt->bt.hsync = hsync; 470 fmt->bt.hsync = hsync;
451 fmt->bt.vsync = vsync; 471 fmt->bt.vsync = vsync;
452 fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync; 472 fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync;
453 fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync; 473
474 if (!interlaced) {
475 fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync;
476 fmt->bt.interlaced = V4L2_DV_PROGRESSIVE;
477 } else {
478 fmt->bt.vbackporch = (frame_height - image_height - 2 * v_fp -
479 2 * vsync) / 2;
480 fmt->bt.il_vbackporch = frame_height - image_height - 2 * v_fp -
481 2 * vsync - fmt->bt.vbackporch;
482 fmt->bt.il_vfrontporch = v_fp;
483 fmt->bt.il_vsync = vsync;
484 fmt->bt.flags |= V4L2_DV_FL_HALF_LINE;
485 fmt->bt.interlaced = V4L2_DV_INTERLACED;
486 }
487
454 fmt->bt.pixelclock = pix_clk; 488 fmt->bt.pixelclock = pix_clk;
455 fmt->bt.standards = V4L2_DV_BT_STD_CVT; 489 fmt->bt.standards = V4L2_DV_BT_STD_CVT;
490
456 if (reduced_blanking) 491 if (reduced_blanking)
457 fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING; 492 fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING;
493
458 return true; 494 return true;
459} 495}
460EXPORT_SYMBOL_GPL(v4l2_detect_cvt); 496EXPORT_SYMBOL_GPL(v4l2_detect_cvt);
@@ -493,6 +529,7 @@ EXPORT_SYMBOL_GPL(v4l2_detect_cvt);
493 * @vsync - the height of the vertical sync in lines. 529 * @vsync - the height of the vertical sync in lines.
494 * @polarities - the horizontal and vertical polarities (same as struct 530 * @polarities - the horizontal and vertical polarities (same as struct
495 * v4l2_bt_timings polarities). 531 * v4l2_bt_timings polarities).
532 * @interlaced - if this flag is true, it indicates interlaced format
496 * @aspect - preferred aspect ratio. GTF has no method of determining the 533 * @aspect - preferred aspect ratio. GTF has no method of determining the
497 * aspect ratio in order to derive the image width from the 534 * aspect ratio in order to derive the image width from the
498 * image height, so it has to be passed explicitly. Usually 535 * image height, so it has to be passed explicitly. Usually
@@ -508,6 +545,7 @@ bool v4l2_detect_gtf(unsigned frame_height,
508 unsigned hfreq, 545 unsigned hfreq,
509 unsigned vsync, 546 unsigned vsync,
510 u32 polarities, 547 u32 polarities,
548 bool interlaced,
511 struct v4l2_fract aspect, 549 struct v4l2_fract aspect,
512 struct v4l2_dv_timings *fmt) 550 struct v4l2_dv_timings *fmt)
513{ 551{
@@ -527,10 +565,19 @@ bool v4l2_detect_gtf(unsigned frame_height,
527 else 565 else
528 return false; 566 return false;
529 567
568 if (hfreq == 0)
569 return false;
570
530 /* Vertical */ 571 /* Vertical */
531 v_fp = GTF_V_FP; 572 v_fp = GTF_V_FP;
532 v_bp = (GTF_MIN_VSYNC_BP * hfreq + 999999) / 1000000 - vsync; 573 v_bp = (GTF_MIN_VSYNC_BP * hfreq + 500000) / 1000000 - vsync;
533 image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1; 574 if (interlaced)
575 image_height = (frame_height - 2 * v_fp - 2 * vsync - 2 * v_bp) & ~0x1;
576 else
577 image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
578
579 if (image_height < 0)
580 return false;
534 581
535 if (aspect.numerator == 0 || aspect.denominator == 0) { 582 if (aspect.numerator == 0 || aspect.denominator == 0) {
536 aspect.numerator = 16; 583 aspect.numerator = 16;
@@ -540,25 +587,35 @@ bool v4l2_detect_gtf(unsigned frame_height,
540 image_width = (image_width + GTF_CELL_GRAN/2) & ~(GTF_CELL_GRAN - 1); 587 image_width = (image_width + GTF_CELL_GRAN/2) & ~(GTF_CELL_GRAN - 1);
541 588
542 /* Horizontal */ 589 /* Horizontal */
543 if (default_gtf) 590 if (default_gtf) {
544 h_blank = ((image_width * GTF_D_C_PRIME * hfreq) - 591 u64 num;
545 (image_width * GTF_D_M_PRIME * 1000) + 592 u32 den;
546 (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) / 2) / 593
547 (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000); 594 num = ((image_width * GTF_D_C_PRIME * (u64)hfreq) -
548 else 595 ((u64)image_width * GTF_D_M_PRIME * 1000));
549 h_blank = ((image_width * GTF_S_C_PRIME * hfreq) - 596 den = (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) *
550 (image_width * GTF_S_M_PRIME * 1000) + 597 (2 * GTF_CELL_GRAN);
551 (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) / 2) / 598 h_blank = div_u64((num + (den >> 1)), den);
552 (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000); 599 h_blank *= (2 * GTF_CELL_GRAN);
600 } else {
601 u64 num;
602 u32 den;
603
604 num = ((image_width * GTF_S_C_PRIME * (u64)hfreq) -
605 ((u64)image_width * GTF_S_M_PRIME * 1000));
606 den = (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) *
607 (2 * GTF_CELL_GRAN);
608 h_blank = div_u64((num + (den >> 1)), den);
609 h_blank *= (2 * GTF_CELL_GRAN);
610 }
553 611
554 h_blank = h_blank - h_blank % (2 * GTF_CELL_GRAN);
555 frame_width = image_width + h_blank; 612 frame_width = image_width + h_blank;
556 613
557 pix_clk = (image_width + h_blank) * hfreq; 614 pix_clk = (image_width + h_blank) * hfreq;
558 pix_clk = pix_clk / GTF_PXL_CLK_GRAN * GTF_PXL_CLK_GRAN; 615 pix_clk = pix_clk / GTF_PXL_CLK_GRAN * GTF_PXL_CLK_GRAN;
559 616
560 hsync = (frame_width * 8 + 50) / 100; 617 hsync = (frame_width * 8 + 50) / 100;
561 hsync = hsync - hsync % GTF_CELL_GRAN; 618 hsync = ((hsync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN) * GTF_CELL_GRAN;
562 619
563 h_fp = h_blank / 2 - hsync; 620 h_fp = h_blank / 2 - hsync;
564 621
@@ -571,11 +628,27 @@ bool v4l2_detect_gtf(unsigned frame_height,
571 fmt->bt.hsync = hsync; 628 fmt->bt.hsync = hsync;
572 fmt->bt.vsync = vsync; 629 fmt->bt.vsync = vsync;
573 fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync; 630 fmt->bt.hbackporch = frame_width - image_width - h_fp - hsync;
574 fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync; 631
632 if (!interlaced) {
633 fmt->bt.vbackporch = frame_height - image_height - v_fp - vsync;
634 fmt->bt.interlaced = V4L2_DV_PROGRESSIVE;
635 } else {
636 fmt->bt.vbackporch = (frame_height - image_height - 2 * v_fp -
637 2 * vsync) / 2;
638 fmt->bt.il_vbackporch = frame_height - image_height - 2 * v_fp -
639 2 * vsync - fmt->bt.vbackporch;
640 fmt->bt.il_vfrontporch = v_fp;
641 fmt->bt.il_vsync = vsync;
642 fmt->bt.flags |= V4L2_DV_FL_HALF_LINE;
643 fmt->bt.interlaced = V4L2_DV_INTERLACED;
644 }
645
575 fmt->bt.pixelclock = pix_clk; 646 fmt->bt.pixelclock = pix_clk;
576 fmt->bt.standards = V4L2_DV_BT_STD_GTF; 647 fmt->bt.standards = V4L2_DV_BT_STD_GTF;
648
577 if (!default_gtf) 649 if (!default_gtf)
578 fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING; 650 fmt->bt.flags |= V4L2_DV_FL_REDUCED_BLANKING;
651
579 return true; 652 return true;
580} 653}
581EXPORT_SYMBOL_GPL(v4l2_detect_gtf); 654EXPORT_SYMBOL_GPL(v4l2_detect_gtf);
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index aa407cb5f830..85de4557f696 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -142,6 +142,7 @@ const char *v4l2_field_names[] = {
142EXPORT_SYMBOL(v4l2_field_names); 142EXPORT_SYMBOL(v4l2_field_names);
143 143
144const char *v4l2_type_names[] = { 144const char *v4l2_type_names[] = {
145 [0] = "0",
145 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap", 146 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
146 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay", 147 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
147 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out", 148 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
@@ -257,7 +258,8 @@ static void v4l_print_format(const void *arg, bool write_only)
257 pr_cont(", width=%u, height=%u, " 258 pr_cont(", width=%u, height=%u, "
258 "pixelformat=%c%c%c%c, field=%s, " 259 "pixelformat=%c%c%c%c, field=%s, "
259 "bytesperline=%u, sizeimage=%u, colorspace=%d, " 260 "bytesperline=%u, sizeimage=%u, colorspace=%d, "
260 "flags=0x%x, ycbcr_enc=%u, quantization=%u\n", 261 "flags=0x%x, ycbcr_enc=%u, quantization=%u, "
262 "xfer_func=%u\n",
261 pix->width, pix->height, 263 pix->width, pix->height,
262 (pix->pixelformat & 0xff), 264 (pix->pixelformat & 0xff),
263 (pix->pixelformat >> 8) & 0xff, 265 (pix->pixelformat >> 8) & 0xff,
@@ -266,7 +268,7 @@ static void v4l_print_format(const void *arg, bool write_only)
266 prt_names(pix->field, v4l2_field_names), 268 prt_names(pix->field, v4l2_field_names),
267 pix->bytesperline, pix->sizeimage, 269 pix->bytesperline, pix->sizeimage,
268 pix->colorspace, pix->flags, pix->ycbcr_enc, 270 pix->colorspace, pix->flags, pix->ycbcr_enc,
269 pix->quantization); 271 pix->quantization, pix->xfer_func);
270 break; 272 break;
271 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 273 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
272 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 274 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
@@ -274,7 +276,7 @@ static void v4l_print_format(const void *arg, bool write_only)
274 pr_cont(", width=%u, height=%u, " 276 pr_cont(", width=%u, height=%u, "
275 "format=%c%c%c%c, field=%s, " 277 "format=%c%c%c%c, field=%s, "
276 "colorspace=%d, num_planes=%u, flags=0x%x, " 278 "colorspace=%d, num_planes=%u, flags=0x%x, "
277 "ycbcr_enc=%u, quantization=%u\n", 279 "ycbcr_enc=%u, quantization=%u, xfer_func=%u\n",
278 mp->width, mp->height, 280 mp->width, mp->height,
279 (mp->pixelformat & 0xff), 281 (mp->pixelformat & 0xff),
280 (mp->pixelformat >> 8) & 0xff, 282 (mp->pixelformat >> 8) & 0xff,
@@ -282,7 +284,7 @@ static void v4l_print_format(const void *arg, bool write_only)
282 (mp->pixelformat >> 24) & 0xff, 284 (mp->pixelformat >> 24) & 0xff,
283 prt_names(mp->field, v4l2_field_names), 285 prt_names(mp->field, v4l2_field_names),
284 mp->colorspace, mp->num_planes, mp->flags, 286 mp->colorspace, mp->num_planes, mp->flags,
285 mp->ycbcr_enc, mp->quantization); 287 mp->ycbcr_enc, mp->quantization, mp->xfer_func);
286 for (i = 0; i < mp->num_planes; i++) 288 for (i = 0; i < mp->num_planes; i++)
287 printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i, 289 printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i,
288 mp->plane_fmt[i].bytesperline, 290 mp->plane_fmt[i].bytesperline,
@@ -1103,6 +1105,183 @@ static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
1103 return ops->vidioc_enum_output(file, fh, p); 1105 return ops->vidioc_enum_output(file, fh, p);
1104} 1106}
1105 1107
1108static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
1109{
1110 const unsigned sz = sizeof(fmt->description);
1111 const char *descr = NULL;
1112 u32 flags = 0;
1113
1114 /*
1115 * We depart from the normal coding style here since the descriptions
1116 * should be aligned so it is easy to see which descriptions will be
1117 * longer than 31 characters (the max length for a description).
1118 * And frankly, this is easier to read anyway.
1119 *
1120 * Note that gcc will use O(log N) comparisons to find the right case.
1121 */
1122 switch (fmt->pixelformat) {
1123 /* Max description length mask: descr = "0123456789012345678901234567890" */
1124 case V4L2_PIX_FMT_RGB332: descr = "8-bit RGB 3-3-2"; break;
1125 case V4L2_PIX_FMT_RGB444: descr = "16-bit A/XRGB 4-4-4-4"; break;
1126 case V4L2_PIX_FMT_ARGB444: descr = "16-bit ARGB 4-4-4-4"; break;
1127 case V4L2_PIX_FMT_XRGB444: descr = "16-bit XRGB 4-4-4-4"; break;
1128 case V4L2_PIX_FMT_RGB555: descr = "16-bit A/XRGB 1-5-5-5"; break;
1129 case V4L2_PIX_FMT_ARGB555: descr = "16-bit ARGB 1-5-5-5"; break;
1130 case V4L2_PIX_FMT_XRGB555: descr = "16-bit XRGB 1-5-5-5"; break;
1131 case V4L2_PIX_FMT_RGB565: descr = "16-bit RGB 5-6-5"; break;
1132 case V4L2_PIX_FMT_RGB555X: descr = "16-bit A/XRGB 1-5-5-5 BE"; break;
1133 case V4L2_PIX_FMT_ARGB555X: descr = "16-bit ARGB 1-5-5-5 BE"; break;
1134 case V4L2_PIX_FMT_XRGB555X: descr = "16-bit XRGB 1-5-5-5 BE"; break;
1135 case V4L2_PIX_FMT_RGB565X: descr = "16-bit RGB 5-6-5 BE"; break;
1136 case V4L2_PIX_FMT_BGR666: descr = "18-bit BGRX 6-6-6-14"; break;
1137 case V4L2_PIX_FMT_BGR24: descr = "24-bit BGR 8-8-8"; break;
1138 case V4L2_PIX_FMT_RGB24: descr = "24-bit RGB 8-8-8"; break;
1139 case V4L2_PIX_FMT_BGR32: descr = "32-bit BGRA/X 8-8-8-8"; break;
1140 case V4L2_PIX_FMT_ABGR32: descr = "32-bit BGRA 8-8-8-8"; break;
1141 case V4L2_PIX_FMT_XBGR32: descr = "32-bit BGRX 8-8-8-8"; break;
1142 case V4L2_PIX_FMT_RGB32: descr = "32-bit A/XRGB 8-8-8-8"; break;
1143 case V4L2_PIX_FMT_ARGB32: descr = "32-bit ARGB 8-8-8-8"; break;
1144 case V4L2_PIX_FMT_XRGB32: descr = "32-bit XRGB 8-8-8-8"; break;
1145 case V4L2_PIX_FMT_GREY: descr = "8-bit Greyscale"; break;
1146 case V4L2_PIX_FMT_Y4: descr = "4-bit Greyscale"; break;
1147 case V4L2_PIX_FMT_Y6: descr = "6-bit Greyscale"; break;
1148 case V4L2_PIX_FMT_Y10: descr = "10-bit Greyscale"; break;
1149 case V4L2_PIX_FMT_Y12: descr = "12-bit Greyscale"; break;
1150 case V4L2_PIX_FMT_Y16: descr = "16-bit Greyscale"; break;
1151 case V4L2_PIX_FMT_Y16_BE: descr = "16-bit Greyscale BE"; break;
1152 case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; break;
1153 case V4L2_PIX_FMT_PAL8: descr = "8-bit Palette"; break;
1154 case V4L2_PIX_FMT_UV8: descr = "8-bit Chrominance UV 4-4"; break;
1155 case V4L2_PIX_FMT_YVU410: descr = "Planar YVU 4:1:0"; break;
1156 case V4L2_PIX_FMT_YVU420: descr = "Planar YVU 4:2:0"; break;
1157 case V4L2_PIX_FMT_YUYV: descr = "YUYV 4:2:2"; break;
1158 case V4L2_PIX_FMT_YYUV: descr = "YYUV 4:2:2"; break;
1159 case V4L2_PIX_FMT_YVYU: descr = "YVYU 4:2:2"; break;
1160 case V4L2_PIX_FMT_UYVY: descr = "UYVY 4:2:2"; break;
1161 case V4L2_PIX_FMT_VYUY: descr = "VYUY 4:2:2"; break;
1162 case V4L2_PIX_FMT_YUV422P: descr = "Planar YVU 4:2:2"; break;
1163 case V4L2_PIX_FMT_YUV411P: descr = "Planar YUV 4:1:1"; break;
1164 case V4L2_PIX_FMT_Y41P: descr = "YUV 4:1:1 (Packed)"; break;
1165 case V4L2_PIX_FMT_YUV444: descr = "16-bit A/XYUV 4-4-4-4"; break;
1166 case V4L2_PIX_FMT_YUV555: descr = "16-bit A/XYUV 1-5-5-5"; break;
1167 case V4L2_PIX_FMT_YUV565: descr = "16-bit YUV 5-6-5"; break;
1168 case V4L2_PIX_FMT_YUV32: descr = "32-bit A/XYUV 8-8-8-8"; break;
1169 case V4L2_PIX_FMT_YUV410: descr = "Planar YUV 4:1:0"; break;
1170 case V4L2_PIX_FMT_YUV420: descr = "Planar YUV 4:2:0"; break;
1171 case V4L2_PIX_FMT_HI240: descr = "8-bit Dithered RGB (BTTV)"; break;
1172 case V4L2_PIX_FMT_HM12: descr = "YUV 4:2:0 (16x16 Macroblocks)"; break;
1173 case V4L2_PIX_FMT_M420: descr = "YUV 4:2:0 (M420)"; break;
1174 case V4L2_PIX_FMT_NV12: descr = "Y/CbCr 4:2:0"; break;
1175 case V4L2_PIX_FMT_NV21: descr = "Y/CrCb 4:2:0"; break;
1176 case V4L2_PIX_FMT_NV16: descr = "Y/CbCr 4:2:2"; break;
1177 case V4L2_PIX_FMT_NV61: descr = "Y/CrCb 4:2:2"; break;
1178 case V4L2_PIX_FMT_NV24: descr = "Y/CbCr 4:4:4"; break;
1179 case V4L2_PIX_FMT_NV42: descr = "Y/CrCb 4:4:4"; break;
1180 case V4L2_PIX_FMT_NV12M: descr = "Y/CbCr 4:2:0 (N-C)"; break;
1181 case V4L2_PIX_FMT_NV21M: descr = "Y/CrCb 4:2:0 (N-C)"; break;
1182 case V4L2_PIX_FMT_NV16M: descr = "Y/CbCr 4:2:2 (N-C)"; break;
1183 case V4L2_PIX_FMT_NV61M: descr = "Y/CrCb 4:2:2 (N-C)"; break;
1184 case V4L2_PIX_FMT_NV12MT: descr = "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
1185 case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
1186 case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break;
1187 case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break;
1188 case V4L2_PIX_FMT_SBGGR8: descr = "8-bit Bayer BGBG/GRGR"; break;
1189 case V4L2_PIX_FMT_SGBRG8: descr = "8-bit Bayer GBGB/RGRG"; break;
1190 case V4L2_PIX_FMT_SGRBG8: descr = "8-bit Bayer GRGR/BGBG"; break;
1191 case V4L2_PIX_FMT_SRGGB8: descr = "8-bit Bayer RGRG/GBGB"; break;
1192 case V4L2_PIX_FMT_SBGGR10: descr = "10-bit Bayer BGBG/GRGR"; break;
1193 case V4L2_PIX_FMT_SGBRG10: descr = "10-bit Bayer GBGB/RGRG"; break;
1194 case V4L2_PIX_FMT_SGRBG10: descr = "10-bit Bayer GRGR/BGBG"; break;
1195 case V4L2_PIX_FMT_SRGGB10: descr = "10-bit Bayer RGRG/GBGB"; break;
1196 case V4L2_PIX_FMT_SBGGR12: descr = "12-bit Bayer BGBG/GRGR"; break;
1197 case V4L2_PIX_FMT_SGBRG12: descr = "12-bit Bayer GBGB/RGRG"; break;
1198 case V4L2_PIX_FMT_SGRBG12: descr = "12-bit Bayer GRGR/BGBG"; break;
1199 case V4L2_PIX_FMT_SRGGB12: descr = "12-bit Bayer RGRG/GBGB"; break;
1200 case V4L2_PIX_FMT_SBGGR10P: descr = "10-bit Bayer BGBG/GRGR Packed"; break;
1201 case V4L2_PIX_FMT_SGBRG10P: descr = "10-bit Bayer GBGB/RGRG Packed"; break;
1202 case V4L2_PIX_FMT_SGRBG10P: descr = "10-bit Bayer GRGR/BGBG Packed"; break;
1203 case V4L2_PIX_FMT_SRGGB10P: descr = "10-bit Bayer RGRG/GBGB Packed"; break;
1204 case V4L2_PIX_FMT_SBGGR10ALAW8: descr = "8-bit Bayer BGBG/GRGR (A-law)"; break;
1205 case V4L2_PIX_FMT_SGBRG10ALAW8: descr = "8-bit Bayer GBGB/RGRG (A-law)"; break;
1206 case V4L2_PIX_FMT_SGRBG10ALAW8: descr = "8-bit Bayer GRGR/BGBG (A-law)"; break;
1207 case V4L2_PIX_FMT_SRGGB10ALAW8: descr = "8-bit Bayer RGRG/GBGB (A-law)"; break;
1208 case V4L2_PIX_FMT_SBGGR10DPCM8: descr = "8-bit Bayer BGBG/GRGR (DPCM)"; break;
1209 case V4L2_PIX_FMT_SGBRG10DPCM8: descr = "8-bit Bayer GBGB/RGRG (DPCM)"; break;
1210 case V4L2_PIX_FMT_SGRBG10DPCM8: descr = "8-bit Bayer GRGR/BGBG (DPCM)"; break;
1211 case V4L2_PIX_FMT_SRGGB10DPCM8: descr = "8-bit Bayer RGRG/GBGB (DPCM)"; break;
1212 case V4L2_PIX_FMT_SBGGR16: descr = "16-bit Bayer BGBG/GRGR (Exp.)"; break;
1213 case V4L2_PIX_FMT_SN9C20X_I420: descr = "GSPCA SN9C20X I420"; break;
1214 case V4L2_PIX_FMT_SPCA501: descr = "GSPCA SPCA501"; break;
1215 case V4L2_PIX_FMT_SPCA505: descr = "GSPCA SPCA505"; break;
1216 case V4L2_PIX_FMT_SPCA508: descr = "GSPCA SPCA508"; break;
1217 case V4L2_PIX_FMT_STV0680: descr = "GSPCA STV0680"; break;
1218 case V4L2_PIX_FMT_TM6000: descr = "A/V + VBI Mux Packet"; break;
1219 case V4L2_PIX_FMT_CIT_YYVYUY: descr = "GSPCA CIT YYVYUY"; break;
1220 case V4L2_PIX_FMT_KONICA420: descr = "GSPCA KONICA420"; break;
1221 case V4L2_SDR_FMT_CU8: descr = "Complex U8"; break;
1222 case V4L2_SDR_FMT_CU16LE: descr = "Complex U16LE"; break;
1223 case V4L2_SDR_FMT_CS8: descr = "Complex S8"; break;
1224 case V4L2_SDR_FMT_CS14LE: descr = "Complex S14LE"; break;
1225 case V4L2_SDR_FMT_RU12LE: descr = "Real U12LE"; break;
1226
1227 default:
1228 /* Compressed formats */
1229 flags = V4L2_FMT_FLAG_COMPRESSED;
1230 switch (fmt->pixelformat) {
1231 /* Max description length mask: descr = "0123456789012345678901234567890" */
1232 case V4L2_PIX_FMT_MJPEG: descr = "Motion-JPEG"; break;
1233 case V4L2_PIX_FMT_JPEG: descr = "JFIF JPEG"; break;
1234 case V4L2_PIX_FMT_DV: descr = "1394"; break;
1235 case V4L2_PIX_FMT_MPEG: descr = "MPEG-1/2/4"; break;
1236 case V4L2_PIX_FMT_H264: descr = "H.264"; break;
1237 case V4L2_PIX_FMT_H264_NO_SC: descr = "H.264 (No Start Codes)"; break;
1238 case V4L2_PIX_FMT_H264_MVC: descr = "H.264 MVC"; break;
1239 case V4L2_PIX_FMT_H263: descr = "H.263"; break;
1240 case V4L2_PIX_FMT_MPEG1: descr = "MPEG-1 ES"; break;
1241 case V4L2_PIX_FMT_MPEG2: descr = "MPEG-2 ES"; break;
1242 case V4L2_PIX_FMT_MPEG4: descr = "MPEG-4 part 2 ES"; break;
1243 case V4L2_PIX_FMT_XVID: descr = "Xvid"; break;
1244 case V4L2_PIX_FMT_VC1_ANNEX_G: descr = "VC-1 (SMPTE 412M Annex G)"; break;
1245 case V4L2_PIX_FMT_VC1_ANNEX_L: descr = "VC-1 (SMPTE 412M Annex L)"; break;
1246 case V4L2_PIX_FMT_VP8: descr = "VP8"; break;
1247 case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break;
1248 case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break;
1249 case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break;
1250 case V4L2_PIX_FMT_PWC1: descr = "Raw Philips Webcam Type (Old)"; break;
1251 case V4L2_PIX_FMT_PWC2: descr = "Raw Philips Webcam Type (New)"; break;
1252 case V4L2_PIX_FMT_ET61X251: descr = "GSPCA ET61X251"; break;
1253 case V4L2_PIX_FMT_SPCA561: descr = "GSPCA SPCA561"; break;
1254 case V4L2_PIX_FMT_PAC207: descr = "GSPCA PAC207"; break;
1255 case V4L2_PIX_FMT_MR97310A: descr = "GSPCA MR97310A"; break;
1256 case V4L2_PIX_FMT_JL2005BCD: descr = "GSPCA JL2005BCD"; break;
1257 case V4L2_PIX_FMT_SN9C2028: descr = "GSPCA SN9C2028"; break;
1258 case V4L2_PIX_FMT_SQ905C: descr = "GSPCA SQ905C"; break;
1259 case V4L2_PIX_FMT_PJPG: descr = "GSPCA PJPG"; break;
1260 case V4L2_PIX_FMT_OV511: descr = "GSPCA OV511"; break;
1261 case V4L2_PIX_FMT_OV518: descr = "GSPCA OV518"; break;
1262 case V4L2_PIX_FMT_JPGL: descr = "JPEG Lite"; break;
1263 case V4L2_PIX_FMT_SE401: descr = "GSPCA SE401"; break;
1264 case V4L2_PIX_FMT_S5C_UYVY_JPG: descr = "S5C73MX interleaved UYVY/JPEG"; break;
1265 default:
1266 WARN(1, "Unknown pixelformat 0x%08x\n", fmt->pixelformat);
1267 if (fmt->description[0])
1268 return;
1269 flags = 0;
1270 snprintf(fmt->description, sz, "%c%c%c%c%s",
1271 (char)(fmt->pixelformat & 0x7f),
1272 (char)((fmt->pixelformat >> 8) & 0x7f),
1273 (char)((fmt->pixelformat >> 16) & 0x7f),
1274 (char)((fmt->pixelformat >> 24) & 0x7f),
1275 (fmt->pixelformat & (1 << 31)) ? "-BE" : "");
1276 break;
1277 }
1278 }
1279
1280 if (descr)
1281 WARN_ON(strlcpy(fmt->description, descr, sz) >= sz);
1282 fmt->flags = flags;
1283}
1284
1106static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, 1285static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
1107 struct file *file, void *fh, void *arg) 1286 struct file *file, void *fh, void *arg)
1108{ 1287{
@@ -1112,34 +1291,43 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
1112 bool is_sdr = vfd->vfl_type == VFL_TYPE_SDR; 1291 bool is_sdr = vfd->vfl_type == VFL_TYPE_SDR;
1113 bool is_rx = vfd->vfl_dir != VFL_DIR_TX; 1292 bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
1114 bool is_tx = vfd->vfl_dir != VFL_DIR_RX; 1293 bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
1294 int ret = -EINVAL;
1115 1295
1116 switch (p->type) { 1296 switch (p->type) {
1117 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1297 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1118 if (unlikely(!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_cap)) 1298 if (unlikely(!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_cap))
1119 break; 1299 break;
1120 return ops->vidioc_enum_fmt_vid_cap(file, fh, arg); 1300 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, arg);
1301 break;
1121 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 1302 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1122 if (unlikely(!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_cap_mplane)) 1303 if (unlikely(!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_cap_mplane))
1123 break; 1304 break;
1124 return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg); 1305 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg);
1306 break;
1125 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1307 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1126 if (unlikely(!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_overlay)) 1308 if (unlikely(!is_rx || !is_vid || !ops->vidioc_enum_fmt_vid_overlay))
1127 break; 1309 break;
1128 return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg); 1310 ret = ops->vidioc_enum_fmt_vid_overlay(file, fh, arg);
1311 break;
1129 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1312 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1130 if (unlikely(!is_tx || !is_vid || !ops->vidioc_enum_fmt_vid_out)) 1313 if (unlikely(!is_tx || !is_vid || !ops->vidioc_enum_fmt_vid_out))
1131 break; 1314 break;
1132 return ops->vidioc_enum_fmt_vid_out(file, fh, arg); 1315 ret = ops->vidioc_enum_fmt_vid_out(file, fh, arg);
1316 break;
1133 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 1317 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1134 if (unlikely(!is_tx || !is_vid || !ops->vidioc_enum_fmt_vid_out_mplane)) 1318 if (unlikely(!is_tx || !is_vid || !ops->vidioc_enum_fmt_vid_out_mplane))
1135 break; 1319 break;
1136 return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg); 1320 ret = ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg);
1321 break;
1137 case V4L2_BUF_TYPE_SDR_CAPTURE: 1322 case V4L2_BUF_TYPE_SDR_CAPTURE:
1138 if (unlikely(!is_rx || !is_sdr || !ops->vidioc_enum_fmt_sdr_cap)) 1323 if (unlikely(!is_rx || !is_sdr || !ops->vidioc_enum_fmt_sdr_cap))
1139 break; 1324 break;
1140 return ops->vidioc_enum_fmt_sdr_cap(file, fh, arg); 1325 ret = ops->vidioc_enum_fmt_sdr_cap(file, fh, arg);
1326 break;
1141 } 1327 }
1142 return -EINVAL; 1328 if (ret == 0)
1329 v4l_fill_fmtdesc(p);
1330 return ret;
1143} 1331}
1144 1332
1145static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, 1333static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
@@ -1618,6 +1806,8 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
1618 if (ret) 1806 if (ret)
1619 return ret; 1807 return ret;
1620 1808
1809 CLEAR_AFTER_FIELD(create, format);
1810
1621 v4l_sanitize_format(&create->format); 1811 v4l_sanitize_format(&create->format);
1622 1812
1623 ret = ops->vidioc_create_bufs(file, fh, create); 1813 ret = ops->vidioc_create_bufs(file, fh, create);
@@ -2354,7 +2544,7 @@ static long __video_do_ioctl(struct file *file,
2354 if (v4l2_is_known_ioctl(cmd)) { 2544 if (v4l2_is_known_ioctl(cmd)) {
2355 info = &v4l2_ioctls[_IOC_NR(cmd)]; 2545 info = &v4l2_ioctls[_IOC_NR(cmd)];
2356 2546
2357 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) && 2547 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
2358 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler)) 2548 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
2359 goto done; 2549 goto done;
2360 2550
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 73824a5ada83..dc853e57f91f 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -427,6 +427,25 @@ int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
427EXPORT_SYMBOL_GPL(v4l2_m2m_dqbuf); 427EXPORT_SYMBOL_GPL(v4l2_m2m_dqbuf);
428 428
429/** 429/**
430 * v4l2_m2m_prepare_buf() - prepare a source or destination buffer, depending on
431 * the type
432 */
433int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
434 struct v4l2_buffer *buf)
435{
436 struct vb2_queue *vq;
437 int ret;
438
439 vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
440 ret = vb2_prepare_buf(vq, buf);
441 if (!ret)
442 v4l2_m2m_try_schedule(m2m_ctx);
443
444 return ret;
445}
446EXPORT_SYMBOL_GPL(v4l2_m2m_prepare_buf);
447
448/**
430 * v4l2_m2m_create_bufs() - create a source or destination buffer, depending 449 * v4l2_m2m_create_bufs() - create a source or destination buffer, depending
431 * on the type 450 * on the type
432 */ 451 */
@@ -564,8 +583,16 @@ unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
564 583
565 if (list_empty(&src_q->done_list)) 584 if (list_empty(&src_q->done_list))
566 poll_wait(file, &src_q->done_wq, wait); 585 poll_wait(file, &src_q->done_wq, wait);
567 if (list_empty(&dst_q->done_list)) 586 if (list_empty(&dst_q->done_list)) {
587 /*
588 * If the last buffer was dequeued from the capture queue,
589 * return immediately. DQBUF will return -EPIPE.
590 */
591 if (dst_q->last_buffer_dequeued)
592 return rc | POLLIN | POLLRDNORM;
593
568 poll_wait(file, &dst_q->done_wq, wait); 594 poll_wait(file, &dst_q->done_wq, wait);
595 }
569 596
570 if (m2m_ctx->m2m_dev->m2m_ops->lock) 597 if (m2m_ctx->m2m_dev->m2m_ops->lock)
571 m2m_ctx->m2m_dev->m2m_ops->lock(m2m_ctx->priv); 598 m2m_ctx->m2m_dev->m2m_ops->lock(m2m_ctx->priv);
@@ -803,6 +830,15 @@ int v4l2_m2m_ioctl_dqbuf(struct file *file, void *priv,
803} 830}
804EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_dqbuf); 831EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_dqbuf);
805 832
833int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *priv,
834 struct v4l2_buffer *buf)
835{
836 struct v4l2_fh *fh = file->private_data;
837
838 return v4l2_m2m_prepare_buf(file, fh->m2m_ctx, buf);
839}
840EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_prepare_buf);
841
806int v4l2_m2m_ioctl_expbuf(struct file *file, void *priv, 842int v4l2_m2m_ioctl_expbuf(struct file *file, void *priv,
807 struct v4l2_exportbuffer *eb) 843 struct v4l2_exportbuffer *eb)
808{ 844{
diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
index 83143d39dea7..b27cbb1f5afe 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -14,6 +14,7 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/slab.h>
17#include <linux/string.h> 18#include <linux/string.h>
18#include <linux/types.h> 19#include <linux/types.h>
19 20
@@ -92,10 +93,6 @@ static void v4l2_of_parse_parallel_bus(const struct device_node *node,
92 flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH : 93 flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
93 V4L2_MBUS_VSYNC_ACTIVE_LOW; 94 V4L2_MBUS_VSYNC_ACTIVE_LOW;
94 95
95 if (!of_property_read_u32(node, "pclk-sample", &v))
96 flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
97 V4L2_MBUS_PCLK_SAMPLE_FALLING;
98
99 if (!of_property_read_u32(node, "field-even-active", &v)) 96 if (!of_property_read_u32(node, "field-even-active", &v))
100 flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH : 97 flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
101 V4L2_MBUS_FIELD_EVEN_LOW; 98 V4L2_MBUS_FIELD_EVEN_LOW;
@@ -104,6 +101,10 @@ static void v4l2_of_parse_parallel_bus(const struct device_node *node,
104 else 101 else
105 endpoint->bus_type = V4L2_MBUS_BT656; 102 endpoint->bus_type = V4L2_MBUS_BT656;
106 103
104 if (!of_property_read_u32(node, "pclk-sample", &v))
105 flags |= v ? V4L2_MBUS_PCLK_SAMPLE_RISING :
106 V4L2_MBUS_PCLK_SAMPLE_FALLING;
107
107 if (!of_property_read_u32(node, "data-active", &v)) 108 if (!of_property_read_u32(node, "data-active", &v))
108 flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH : 109 flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
109 V4L2_MBUS_DATA_ACTIVE_LOW; 110 V4L2_MBUS_DATA_ACTIVE_LOW;
@@ -141,6 +142,10 @@ static void v4l2_of_parse_parallel_bus(const struct device_node *node,
141 * V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. 142 * V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag.
142 * The caller should hold a reference to @node. 143 * The caller should hold a reference to @node.
143 * 144 *
145 * NOTE: This function does not parse properties the size of which is
146 * variable without a low fixed limit. Please use
147 * v4l2_of_alloc_parse_endpoint() in new drivers instead.
148 *
144 * Return: 0. 149 * Return: 0.
145 */ 150 */
146int v4l2_of_parse_endpoint(const struct device_node *node, 151int v4l2_of_parse_endpoint(const struct device_node *node,
@@ -149,8 +154,9 @@ int v4l2_of_parse_endpoint(const struct device_node *node,
149 int rval; 154 int rval;
150 155
151 of_graph_parse_endpoint(node, &endpoint->base); 156 of_graph_parse_endpoint(node, &endpoint->base);
152 endpoint->bus_type = 0; 157 /* Zero fields from bus_type to until the end */
153 memset(&endpoint->bus, 0, sizeof(endpoint->bus)); 158 memset(&endpoint->bus_type, 0, sizeof(*endpoint) -
159 offsetof(typeof(*endpoint), bus_type));
154 160
155 rval = v4l2_of_parse_csi_bus(node, endpoint); 161 rval = v4l2_of_parse_csi_bus(node, endpoint);
156 if (rval) 162 if (rval)
@@ -166,6 +172,88 @@ int v4l2_of_parse_endpoint(const struct device_node *node,
166} 172}
167EXPORT_SYMBOL(v4l2_of_parse_endpoint); 173EXPORT_SYMBOL(v4l2_of_parse_endpoint);
168 174
175/*
176 * v4l2_of_free_endpoint() - free the endpoint acquired by
177 * v4l2_of_alloc_parse_endpoint()
178 * @endpoint - the endpoint the resources of which are to be released
179 *
180 * It is safe to call this function with NULL argument or on an
181 * endpoint the parsing of which failed.
182 */
183void v4l2_of_free_endpoint(struct v4l2_of_endpoint *endpoint)
184{
185 if (IS_ERR_OR_NULL(endpoint))
186 return;
187
188 kfree(endpoint->link_frequencies);
189 kfree(endpoint);
190}
191EXPORT_SYMBOL(v4l2_of_free_endpoint);
192
193/**
194 * v4l2_of_alloc_parse_endpoint() - parse all endpoint node properties
195 * @node: pointer to endpoint device_node
196 *
197 * All properties are optional. If none are found, we don't set any flags.
198 * This means the port has a static configuration and no properties have
199 * to be specified explicitly.
200 * If any properties that identify the bus as parallel are found and
201 * slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if we recognise
202 * the bus as serial CSI-2 and clock-noncontinuous isn't set, we set the
203 * V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag.
204 * The caller should hold a reference to @node.
205 *
206 * v4l2_of_alloc_parse_endpoint() has two important differences to
207 * v4l2_of_parse_endpoint():
208 *
209 * 1. It also parses variable size data and
210 *
211 * 2. The memory it has allocated to store the variable size data must
212 * be freed using v4l2_of_free_endpoint() when no longer needed.
213 *
214 * Return: Pointer to v4l2_of_endpoint if successful, on error a
215 * negative error code.
216 */
217struct v4l2_of_endpoint *v4l2_of_alloc_parse_endpoint(
218 const struct device_node *node)
219{
220 struct v4l2_of_endpoint *endpoint;
221 int len;
222 int rval;
223
224 endpoint = kzalloc(sizeof(*endpoint), GFP_KERNEL);
225 if (!endpoint)
226 return ERR_PTR(-ENOMEM);
227
228 rval = v4l2_of_parse_endpoint(node, endpoint);
229 if (rval < 0)
230 goto out_err;
231
232 if (of_get_property(node, "link-frequencies", &len)) {
233 endpoint->link_frequencies = kmalloc(len, GFP_KERNEL);
234 if (!endpoint->link_frequencies) {
235 rval = -ENOMEM;
236 goto out_err;
237 }
238
239 endpoint->nr_of_link_frequencies =
240 len / sizeof(*endpoint->link_frequencies);
241
242 rval = of_property_read_u64_array(
243 node, "link-frequencies", endpoint->link_frequencies,
244 endpoint->nr_of_link_frequencies);
245 if (rval < 0)
246 goto out_err;
247 }
248
249 return endpoint;
250
251out_err:
252 v4l2_of_free_endpoint(endpoint);
253 return ERR_PTR(rval);
254}
255EXPORT_SYMBOL(v4l2_of_alloc_parse_endpoint);
256
169/** 257/**
170 * v4l2_of_parse_link() - parse a link between two endpoints 258 * v4l2_of_parse_link() - parse a link between two endpoints
171 * @node: pointer to the endpoint at the local end of the link 259 * @node: pointer to the endpoint at the local end of the link
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 66ada01c796c..93b315459098 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -182,6 +182,7 @@ module_param(debug, int, 0644);
182 V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_TIMECODE) 182 V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_TIMECODE)
183 183
184static void __vb2_queue_cancel(struct vb2_queue *q); 184static void __vb2_queue_cancel(struct vb2_queue *q);
185static void __enqueue_in_driver(struct vb2_buffer *vb);
185 186
186/** 187/**
187 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer 188 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
@@ -1153,8 +1154,9 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
1153/** 1154/**
1154 * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished 1155 * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
1155 * @vb: vb2_buffer returned from the driver 1156 * @vb: vb2_buffer returned from the driver
1156 * @state: either VB2_BUF_STATE_DONE if the operation finished successfully 1157 * @state: either VB2_BUF_STATE_DONE if the operation finished successfully,
1157 * or VB2_BUF_STATE_ERROR if the operation finished with an error. 1158 * VB2_BUF_STATE_ERROR if the operation finished with an error or
1159 * VB2_BUF_STATE_QUEUED if the driver wants to requeue buffers.
1158 * If start_streaming fails then it should return buffers with state 1160 * If start_streaming fails then it should return buffers with state
1159 * VB2_BUF_STATE_QUEUED to put them back into the queue. 1161 * VB2_BUF_STATE_QUEUED to put them back into the queue.
1160 * 1162 *
@@ -1205,8 +1207,11 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
1205 atomic_dec(&q->owned_by_drv_count); 1207 atomic_dec(&q->owned_by_drv_count);
1206 spin_unlock_irqrestore(&q->done_lock, flags); 1208 spin_unlock_irqrestore(&q->done_lock, flags);
1207 1209
1208 if (state == VB2_BUF_STATE_QUEUED) 1210 if (state == VB2_BUF_STATE_QUEUED) {
1211 if (q->start_streaming_called)
1212 __enqueue_in_driver(vb);
1209 return; 1213 return;
1214 }
1210 1215
1211 /* Inform any processes that may be waiting for buffers */ 1216 /* Inform any processes that may be waiting for buffers */
1212 wake_up(&q->done_wq); 1217 wake_up(&q->done_wq);
@@ -1237,6 +1242,23 @@ void vb2_discard_done(struct vb2_queue *q)
1237} 1242}
1238EXPORT_SYMBOL_GPL(vb2_discard_done); 1243EXPORT_SYMBOL_GPL(vb2_discard_done);
1239 1244
1245static void vb2_warn_zero_bytesused(struct vb2_buffer *vb)
1246{
1247 static bool __check_once __read_mostly;
1248
1249 if (__check_once)
1250 return;
1251
1252 __check_once = true;
1253 __WARN();
1254
1255 pr_warn_once("use of bytesused == 0 is deprecated and will be removed in the future,\n");
1256 if (vb->vb2_queue->allow_zero_bytesused)
1257 pr_warn_once("use VIDIOC_DECODER_CMD(V4L2_DEC_CMD_STOP) instead.\n");
1258 else
1259 pr_warn_once("use the actual size instead.\n");
1260}
1261
1240/** 1262/**
1241 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a 1263 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a
1242 * v4l2_buffer by the userspace. The caller has already verified that struct 1264 * v4l2_buffer by the userspace. The caller has already verified that struct
@@ -1247,16 +1269,6 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
1247{ 1269{
1248 unsigned int plane; 1270 unsigned int plane;
1249 1271
1250 if (V4L2_TYPE_IS_OUTPUT(b->type)) {
1251 if (WARN_ON_ONCE(b->bytesused == 0)) {
1252 pr_warn_once("use of bytesused == 0 is deprecated and will be removed in the future,\n");
1253 if (vb->vb2_queue->allow_zero_bytesused)
1254 pr_warn_once("use VIDIOC_DECODER_CMD(V4L2_DEC_CMD_STOP) instead.\n");
1255 else
1256 pr_warn_once("use the actual size instead.\n");
1257 }
1258 }
1259
1260 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { 1272 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
1261 if (b->memory == V4L2_MEMORY_USERPTR) { 1273 if (b->memory == V4L2_MEMORY_USERPTR) {
1262 for (plane = 0; plane < vb->num_planes; ++plane) { 1274 for (plane = 0; plane < vb->num_planes; ++plane) {
@@ -1297,6 +1309,9 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
1297 struct v4l2_plane *pdst = &v4l2_planes[plane]; 1309 struct v4l2_plane *pdst = &v4l2_planes[plane];
1298 struct v4l2_plane *psrc = &b->m.planes[plane]; 1310 struct v4l2_plane *psrc = &b->m.planes[plane];
1299 1311
1312 if (psrc->bytesused == 0)
1313 vb2_warn_zero_bytesused(vb);
1314
1300 if (vb->vb2_queue->allow_zero_bytesused) 1315 if (vb->vb2_queue->allow_zero_bytesused)
1301 pdst->bytesused = psrc->bytesused; 1316 pdst->bytesused = psrc->bytesused;
1302 else 1317 else
@@ -1331,6 +1346,9 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
1331 } 1346 }
1332 1347
1333 if (V4L2_TYPE_IS_OUTPUT(b->type)) { 1348 if (V4L2_TYPE_IS_OUTPUT(b->type)) {
1349 if (b->bytesused == 0)
1350 vb2_warn_zero_bytesused(vb);
1351
1334 if (vb->vb2_queue->allow_zero_bytesused) 1352 if (vb->vb2_queue->allow_zero_bytesused)
1335 v4l2_planes[0].bytesused = b->bytesused; 1353 v4l2_planes[0].bytesused = b->bytesused;
1336 else 1354 else
@@ -1945,6 +1963,11 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
1945 return -EIO; 1963 return -EIO;
1946 } 1964 }
1947 1965
1966 if (q->last_buffer_dequeued) {
1967 dprintk(3, "last buffer dequeued already, will not wait for buffers\n");
1968 return -EPIPE;
1969 }
1970
1948 if (!list_empty(&q->done_list)) { 1971 if (!list_empty(&q->done_list)) {
1949 /* 1972 /*
1950 * Found a buffer that we were waiting for. 1973 * Found a buffer that we were waiting for.
@@ -2100,6 +2123,9 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
2100 /* Remove from videobuf queue */ 2123 /* Remove from videobuf queue */
2101 list_del(&vb->queued_entry); 2124 list_del(&vb->queued_entry);
2102 q->queued_count--; 2125 q->queued_count--;
2126 if (!V4L2_TYPE_IS_OUTPUT(q->type) &&
2127 vb->v4l2_buf.flags & V4L2_BUF_FLAG_LAST)
2128 q->last_buffer_dequeued = true;
2103 /* go back to dequeued state */ 2129 /* go back to dequeued state */
2104 __vb2_dqbuf(vb); 2130 __vb2_dqbuf(vb);
2105 2131
@@ -2313,6 +2339,7 @@ static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
2313 */ 2339 */
2314 __vb2_queue_cancel(q); 2340 __vb2_queue_cancel(q);
2315 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); 2341 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
2342 q->last_buffer_dequeued = false;
2316 2343
2317 dprintk(3, "successful\n"); 2344 dprintk(3, "successful\n");
2318 return 0; 2345 return 0;
@@ -2655,8 +2682,16 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
2655 if (V4L2_TYPE_IS_OUTPUT(q->type) && q->queued_count < q->num_buffers) 2682 if (V4L2_TYPE_IS_OUTPUT(q->type) && q->queued_count < q->num_buffers)
2656 return res | POLLOUT | POLLWRNORM; 2683 return res | POLLOUT | POLLWRNORM;
2657 2684
2658 if (list_empty(&q->done_list)) 2685 if (list_empty(&q->done_list)) {
2686 /*
2687 * If the last buffer was dequeued from a capture queue,
2688 * return immediately. DQBUF will return -EPIPE.
2689 */
2690 if (q->last_buffer_dequeued)
2691 return res | POLLIN | POLLRDNORM;
2692
2659 poll_wait(file, &q->done_wq, wait); 2693 poll_wait(file, &q->done_wq, wait);
2694 }
2660 2695
2661 /* 2696 /*
2662 * Take first buffer available for dequeuing. 2697 * Take first buffer available for dequeuing.
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 644dec73d220..94c1e6455d36 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -299,7 +299,6 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
299 /* stealing dmabuf mutex to serialize map/unmap operations */ 299 /* stealing dmabuf mutex to serialize map/unmap operations */
300 struct mutex *lock = &db_attach->dmabuf->lock; 300 struct mutex *lock = &db_attach->dmabuf->lock;
301 struct sg_table *sgt; 301 struct sg_table *sgt;
302 int ret;
303 302
304 mutex_lock(lock); 303 mutex_lock(lock);
305 304
@@ -318,8 +317,9 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
318 } 317 }
319 318
320 /* mapping to the client with new direction */ 319 /* mapping to the client with new direction */
321 ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir); 320 sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
322 if (ret <= 0) { 321 dma_dir);
322 if (!sgt->nents) {
323 pr_err("failed to map scatterlist\n"); 323 pr_err("failed to map scatterlist\n");
324 mutex_unlock(lock); 324 mutex_unlock(lock);
325 return ERR_PTR(-EIO); 325 return ERR_PTR(-EIO);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 45c708e463b9..7289b81bd7b7 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -147,8 +147,9 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size,
147 * No need to sync to the device, this will happen later when the 147 * No need to sync to the device, this will happen later when the
148 * prepare() memop is called. 148 * prepare() memop is called.
149 */ 149 */
150 if (dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->nents, 150 sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
151 buf->dma_dir, &attrs) == 0) 151 buf->dma_dir, &attrs);
152 if (!sgt->nents)
152 goto fail_map; 153 goto fail_map;
153 154
154 buf->handler.refcount = &buf->refcount; 155 buf->handler.refcount = &buf->refcount;
@@ -187,7 +188,7 @@ static void vb2_dma_sg_put(void *buf_priv)
187 dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs); 188 dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs);
188 dprintk(1, "%s: Freeing buffer of %d pages\n", __func__, 189 dprintk(1, "%s: Freeing buffer of %d pages\n", __func__,
189 buf->num_pages); 190 buf->num_pages);
190 dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->nents, 191 dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
191 buf->dma_dir, &attrs); 192 buf->dma_dir, &attrs);
192 if (buf->vaddr) 193 if (buf->vaddr)
193 vm_unmap_ram(buf->vaddr, buf->num_pages); 194 vm_unmap_ram(buf->vaddr, buf->num_pages);
@@ -314,9 +315,11 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
314 * No need to sync to the device, this will happen later when the 315 * No need to sync to the device, this will happen later when the
315 * prepare() memop is called. 316 * prepare() memop is called.
316 */ 317 */
317 if (dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->nents, 318 sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
318 buf->dma_dir, &attrs) == 0) 319 buf->dma_dir, &attrs);
320 if (!sgt->nents)
319 goto userptr_fail_map; 321 goto userptr_fail_map;
322
320 return buf; 323 return buf;
321 324
322userptr_fail_map: 325userptr_fail_map:
@@ -351,7 +354,8 @@ static void vb2_dma_sg_put_userptr(void *buf_priv)
351 354
352 dprintk(1, "%s: Releasing userspace buffer of %d pages\n", 355 dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
353 __func__, buf->num_pages); 356 __func__, buf->num_pages);
354 dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir, &attrs); 357 dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir,
358 &attrs);
355 if (buf->vaddr) 359 if (buf->vaddr)
356 vm_unmap_ram(buf->vaddr, buf->num_pages); 360 vm_unmap_ram(buf->vaddr, buf->num_pages);
357 sg_free_table(buf->dma_sgt); 361 sg_free_table(buf->dma_sgt);
@@ -502,7 +506,6 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
502 /* stealing dmabuf mutex to serialize map/unmap operations */ 506 /* stealing dmabuf mutex to serialize map/unmap operations */
503 struct mutex *lock = &db_attach->dmabuf->lock; 507 struct mutex *lock = &db_attach->dmabuf->lock;
504 struct sg_table *sgt; 508 struct sg_table *sgt;
505 int ret;
506 509
507 mutex_lock(lock); 510 mutex_lock(lock);
508 511
@@ -521,8 +524,9 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
521 } 524 }
522 525
523 /* mapping to the client with new direction */ 526 /* mapping to the client with new direction */
524 ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir); 527 sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
525 if (ret <= 0) { 528 dma_dir);
529 if (!sgt->nents) {
526 pr_err("failed to map scatterlist\n"); 530 pr_err("failed to map scatterlist\n");
527 mutex_unlock(lock); 531 mutex_unlock(lock);
528 return ERR_PTR(-EIO); 532 return ERR_PTR(-EIO);
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 657ab302a5cf..2fe4c27f524a 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -287,7 +287,6 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
287 /* stealing dmabuf mutex to serialize map/unmap operations */ 287 /* stealing dmabuf mutex to serialize map/unmap operations */
288 struct mutex *lock = &db_attach->dmabuf->lock; 288 struct mutex *lock = &db_attach->dmabuf->lock;
289 struct sg_table *sgt; 289 struct sg_table *sgt;
290 int ret;
291 290
292 mutex_lock(lock); 291 mutex_lock(lock);
293 292
@@ -306,8 +305,9 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
306 } 305 }
307 306
308 /* mapping to the client with new direction */ 307 /* mapping to the client with new direction */
309 ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dma_dir); 308 sgt->nents = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
310 if (ret <= 0) { 309 dma_dir);
310 if (!sgt->nents) {
311 pr_err("failed to map scatterlist\n"); 311 pr_err("failed to map scatterlist\n");
312 mutex_unlock(lock); 312 mutex_unlock(lock);
313 return ERR_PTR(-EIO); 313 return ERR_PTR(-EIO);
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index 96498b7fc20e..14697686eea5 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -25,8 +25,6 @@ source "drivers/staging/media/cxd2099/Kconfig"
25 25
26source "drivers/staging/media/davinci_vpfe/Kconfig" 26source "drivers/staging/media/davinci_vpfe/Kconfig"
27 27
28source "drivers/staging/media/dt3155v4l/Kconfig"
29
30source "drivers/staging/media/mn88472/Kconfig" 28source "drivers/staging/media/mn88472/Kconfig"
31 29
32source "drivers/staging/media/mn88473/Kconfig" 30source "drivers/staging/media/mn88473/Kconfig"
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index a9006bcb4472..34c557b4c6d6 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -1,7 +1,6 @@
1obj-$(CONFIG_I2C_BCM2048) += bcm2048/ 1obj-$(CONFIG_I2C_BCM2048) += bcm2048/
2obj-$(CONFIG_DVB_CXD2099) += cxd2099/ 2obj-$(CONFIG_DVB_CXD2099) += cxd2099/
3obj-$(CONFIG_LIRC_STAGING) += lirc/ 3obj-$(CONFIG_LIRC_STAGING) += lirc/
4obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
5obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/ 4obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
6obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/ 5obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
7obj-$(CONFIG_DVB_MN88472) += mn88472/ 6obj-$(CONFIG_DVB_MN88472) += mn88472/
diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c
index e9d0691b21d3..5e11a78ceef3 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -2593,7 +2593,7 @@ static int bcm2048_i2c_driver_probe(struct i2c_client *client,
2593 const struct i2c_device_id *id) 2593 const struct i2c_device_id *id)
2594{ 2594{
2595 struct bcm2048_device *bdev; 2595 struct bcm2048_device *bdev;
2596 int err, skip_release = 0; 2596 int err;
2597 2597
2598 bdev = kzalloc(sizeof(*bdev), GFP_KERNEL); 2598 bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
2599 if (!bdev) { 2599 if (!bdev) {
@@ -2646,7 +2646,6 @@ free_sysfs:
2646 bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs)); 2646 bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs));
2647free_registration: 2647free_registration:
2648 video_unregister_device(&bdev->videodev); 2648 video_unregister_device(&bdev->videodev);
2649 skip_release = 1;
2650free_irq: 2649free_irq:
2651 if (client->irq) 2650 if (client->irq)
2652 free_irq(client->irq, bdev); 2651 free_irq(client->irq, bdev);
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index b6498137de56..acb293ed9c91 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -321,6 +321,7 @@ static int resizer_configure_output_win(struct vpfe_resizer_device *resizer)
321 321
322 outformat = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE]; 322 outformat = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE];
323 323
324 memset(&output_specs, 0x0, sizeof(struct vpfe_rsz_output_spec));
324 output_specs.vst_y = param->user_config.vst; 325 output_specs.vst_y = param->user_config.vst;
325 if (outformat->code == MEDIA_BUS_FMT_YDYUYDYV8_1X16) 326 if (outformat->code == MEDIA_BUS_FMT_YDYUYDYV8_1X16)
326 output_specs.vst_c = param->user_config.vst; 327 output_specs.vst_c = param->user_config.vst;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h
index 2632a806c4a8..8ad8d743f4e0 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h
@@ -67,8 +67,6 @@ struct vpfe_device {
67 /* CCDC IRQs used when CCDC/ISIF output to SDRAM */ 67 /* CCDC IRQs used when CCDC/ISIF output to SDRAM */
68 unsigned int ccdc_irq0; 68 unsigned int ccdc_irq0;
69 unsigned int ccdc_irq1; 69 unsigned int ccdc_irq1;
70 /* maximum video memory that is available*/
71 unsigned int video_limit;
72 /* media device */ 70 /* media device */
73 struct media_device media_dev; 71 struct media_device media_dev;
74 /* ccdc subdevice */ 72 /* ccdc subdevice */
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 06d48d5eb0a0..87048a14c34d 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -27,9 +27,6 @@
27#include "vpfe.h" 27#include "vpfe.h"
28#include "vpfe_mc_capture.h" 28#include "vpfe_mc_capture.h"
29 29
30/* minimum number of buffers needed in cont-mode */
31#define MIN_NUM_BUFFERS 3
32
33static int debug; 30static int debug;
34 31
35/* get v4l2 subdev pointer to external subdev which is active */ 32/* get v4l2 subdev pointer to external subdev which is active */
@@ -473,7 +470,7 @@ void vpfe_video_process_buffer_complete(struct vpfe_video_device *video)
473{ 470{
474 struct vpfe_pipeline *pipe = &video->pipe; 471 struct vpfe_pipeline *pipe = &video->pipe;
475 472
476 do_gettimeofday(&video->cur_frm->vb.v4l2_buf.timestamp); 473 v4l2_get_timestamp(&video->cur_frm->vb.v4l2_buf.timestamp);
477 vb2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_DONE); 474 vb2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_DONE);
478 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS) 475 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS)
479 video->cur_frm = video->next_frm; 476 video->cur_frm = video->next_frm;
@@ -1088,20 +1085,14 @@ vpfe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
1088 struct vpfe_fh *fh = vb2_get_drv_priv(vq); 1085 struct vpfe_fh *fh = vb2_get_drv_priv(vq);
1089 struct vpfe_video_device *video = fh->video; 1086 struct vpfe_video_device *video = fh->video;
1090 struct vpfe_device *vpfe_dev = video->vpfe_dev; 1087 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1091 struct vpfe_pipeline *pipe = &video->pipe;
1092 unsigned long size; 1088 unsigned long size;
1093 1089
1094 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_queue_setup\n"); 1090 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_queue_setup\n");
1095 size = video->fmt.fmt.pix.sizeimage; 1091 size = video->fmt.fmt.pix.sizeimage;
1096 1092
1097 if (vpfe_dev->video_limit) { 1093 if (vq->num_buffers + *nbuffers < 3)
1098 while (size * *nbuffers > vpfe_dev->video_limit) 1094 *nbuffers = 3 - vq->num_buffers;
1099 (*nbuffers)--; 1095
1100 }
1101 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS) {
1102 if (*nbuffers < MIN_NUM_BUFFERS)
1103 *nbuffers = MIN_NUM_BUFFERS;
1104 }
1105 *nplanes = 1; 1096 *nplanes = 1;
1106 sizes[0] = size; 1097 sizes[0] = size;
1107 alloc_ctxs[0] = video->alloc_ctx; 1098 alloc_ctxs[0] = video->alloc_ctx;
@@ -1346,6 +1337,7 @@ static int vpfe_reqbufs(struct file *file, void *priv,
1346 q->ops = &video_qops; 1337 q->ops = &video_qops;
1347 q->mem_ops = &vb2_dma_contig_memops; 1338 q->mem_ops = &vb2_dma_contig_memops;
1348 q->buf_struct_size = sizeof(struct vpfe_cap_buffer); 1339 q->buf_struct_size = sizeof(struct vpfe_cap_buffer);
1340 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1349 1341
1350 ret = vb2_queue_init(q); 1342 ret = vb2_queue_init(q);
1351 if (ret) { 1343 if (ret) {
diff --git a/drivers/staging/media/dt3155v4l/Kconfig b/drivers/staging/media/dt3155v4l/Kconfig
deleted file mode 100644
index 2d496001b6e8..000000000000
--- a/drivers/staging/media/dt3155v4l/Kconfig
+++ /dev/null
@@ -1,29 +0,0 @@
1config VIDEO_DT3155
2 tristate "DT3155 frame grabber, Video4Linux interface"
3 depends on PCI && VIDEO_DEV && VIDEO_V4L2
4 depends on HAS_DMA
5 select VIDEOBUF2_DMA_CONTIG
6 default n
7 ---help---
8 Enables dt3155 device driver for the DataTranslation DT3155 frame grabber.
9 Say Y here if you have this hardware.
10 In doubt, say N.
11
12 To compile this driver as a module, choose M here: the
13 module will be called dt3155v4l.
14
15config DT3155_CCIR
16 bool "Selects CCIR/50Hz vertical refresh"
17 depends on VIDEO_DT3155
18 default y
19 ---help---
20 Select it for CCIR/50Hz (European region),
21 or leave it unselected for RS-170/60Hz (North America).
22
23config DT3155_STREAMING
24 bool "Selects streaming capture method"
25 depends on VIDEO_DT3155
26 default y
27 ---help---
28 Select it if you want to use streaming of memory mapped buffers
29 or leave it unselected if you want to use read method (one copy more).
diff --git a/drivers/staging/media/dt3155v4l/Makefile b/drivers/staging/media/dt3155v4l/Makefile
deleted file mode 100644
index ce7a3ec2faf3..000000000000
--- a/drivers/staging/media/dt3155v4l/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l.o
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c
deleted file mode 100644
index 52a8ffe560b1..000000000000
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.c
+++ /dev/null
@@ -1,981 +0,0 @@
1/***************************************************************************
2 * Copyright (C) 2006-2010 by Marin Mitov *
3 * mitov@issp.bas.bg *
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 *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#include <linux/module.h>
22#include <linux/version.h>
23#include <linux/stringify.h>
24#include <linux/delay.h>
25#include <linux/kthread.h>
26#include <linux/slab.h>
27#include <media/v4l2-dev.h>
28#include <media/v4l2-ioctl.h>
29#include <media/v4l2-common.h>
30#include <media/videobuf2-dma-contig.h>
31
32#include "dt3155v4l.h"
33
34#define DT3155_DEVICE_ID 0x1223
35
36/* DT3155_CHUNK_SIZE is 4M (2^22) 8 full size buffers */
37#define DT3155_CHUNK_SIZE (1U << 22)
38
39#define DT3155_COH_FLAGS (GFP_KERNEL | GFP_DMA32 | __GFP_COLD | __GFP_NOWARN)
40
41#define DT3155_BUF_SIZE (768 * 576)
42
43#ifdef CONFIG_DT3155_STREAMING
44#define DT3155_CAPTURE_METHOD V4L2_CAP_STREAMING
45#else
46#define DT3155_CAPTURE_METHOD V4L2_CAP_READWRITE
47#endif
48
49/* global initializers (for all boards) */
50#ifdef CONFIG_DT3155_CCIR
51static const u8 csr2_init = VT_50HZ;
52#define DT3155_CURRENT_NORM V4L2_STD_625_50
53static const unsigned int img_width = 768;
54static const unsigned int img_height = 576;
55static const unsigned int frames_per_sec = 25;
56static const struct v4l2_fmtdesc frame_std[] = {
57 {
58 .index = 0,
59 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
60 .flags = 0,
61 .description = "CCIR/50Hz 8 bits gray",
62 .pixelformat = V4L2_PIX_FMT_GREY,
63 },
64};
65#else
66static const u8 csr2_init = VT_60HZ;
67#define DT3155_CURRENT_NORM V4L2_STD_525_60
68static const unsigned int img_width = 640;
69static const unsigned int img_height = 480;
70static const unsigned int frames_per_sec = 30;
71static const struct v4l2_fmtdesc frame_std[] = {
72 {
73 .index = 0,
74 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
75 .flags = 0,
76 .description = "RS-170/60Hz 8 bits gray",
77 .pixelformat = V4L2_PIX_FMT_GREY,
78 },
79};
80#endif
81
82#define NUM_OF_FORMATS ARRAY_SIZE(frame_std)
83
84static u8 config_init = ACQ_MODE_EVEN;
85
86/**
87 * read_i2c_reg - reads an internal i2c register
88 *
89 * @addr: dt3155 mmio base address
90 * @index: index (internal address) of register to read
91 * @data: pointer to byte the read data will be placed in
92 *
93 * returns: zero on success or error code
94 *
95 * This function starts reading the specified (by index) register
96 * and busy waits for the process to finish. The result is placed
97 * in a byte pointed by data.
98 */
99static int
100read_i2c_reg(void __iomem *addr, u8 index, u8 *data)
101{
102 u32 tmp = index;
103
104 iowrite32((tmp<<17) | IIC_READ, addr + IIC_CSR2);
105 mmiowb();
106 udelay(45); /* wait at least 43 usec for NEW_CYCLE to clear */
107 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
108 return -EIO; /* error: NEW_CYCLE not cleared */
109 tmp = ioread32(addr + IIC_CSR1);
110 if (tmp & DIRECT_ABORT) {
111 /* reset DIRECT_ABORT bit */
112 iowrite32(DIRECT_ABORT, addr + IIC_CSR1);
113 return -EIO; /* error: DIRECT_ABORT set */
114 }
115 *data = tmp>>24;
116 return 0;
117}
118
119/**
120 * write_i2c_reg - writes to an internal i2c register
121 *
122 * @addr: dt3155 mmio base address
123 * @index: index (internal address) of register to read
124 * @data: data to be written
125 *
126 * returns: zero on success or error code
127 *
128 * This function starts writting the specified (by index) register
129 * and busy waits for the process to finish.
130 */
131static int
132write_i2c_reg(void __iomem *addr, u8 index, u8 data)
133{
134 u32 tmp = index;
135
136 iowrite32((tmp<<17) | IIC_WRITE | data, addr + IIC_CSR2);
137 mmiowb();
138 udelay(65); /* wait at least 63 usec for NEW_CYCLE to clear */
139 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
140 return -EIO; /* error: NEW_CYCLE not cleared */
141 if (ioread32(addr + IIC_CSR1) & DIRECT_ABORT) {
142 /* reset DIRECT_ABORT bit */
143 iowrite32(DIRECT_ABORT, addr + IIC_CSR1);
144 return -EIO; /* error: DIRECT_ABORT set */
145 }
146 return 0;
147}
148
149/**
150 * write_i2c_reg_nowait - writes to an internal i2c register
151 *
152 * @addr: dt3155 mmio base address
153 * @index: index (internal address) of register to read
154 * @data: data to be written
155 *
156 * This function starts writting the specified (by index) register
157 * and then returns.
158 */
159static void write_i2c_reg_nowait(void __iomem *addr, u8 index, u8 data)
160{
161 u32 tmp = index;
162
163 iowrite32((tmp<<17) | IIC_WRITE | data, addr + IIC_CSR2);
164 mmiowb();
165}
166
167/**
168 * wait_i2c_reg - waits the read/write to finish
169 *
170 * @addr: dt3155 mmio base address
171 *
172 * returns: zero on success or error code
173 *
174 * This function waits reading/writting to finish.
175 */
176static int wait_i2c_reg(void __iomem *addr)
177{
178 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
179 udelay(65); /* wait at least 63 usec for NEW_CYCLE to clear */
180 if (ioread32(addr + IIC_CSR2) & NEW_CYCLE)
181 return -EIO; /* error: NEW_CYCLE not cleared */
182 if (ioread32(addr + IIC_CSR1) & DIRECT_ABORT) {
183 /* reset DIRECT_ABORT bit */
184 iowrite32(DIRECT_ABORT, addr + IIC_CSR1);
185 return -EIO; /* error: DIRECT_ABORT set */
186 }
187 return 0;
188}
189
190static int
191dt3155_start_acq(struct dt3155_priv *pd)
192{
193 struct vb2_buffer *vb = pd->curr_buf;
194 dma_addr_t dma_addr;
195
196 dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
197 iowrite32(dma_addr, pd->regs + EVEN_DMA_START);
198 iowrite32(dma_addr + img_width, pd->regs + ODD_DMA_START);
199 iowrite32(img_width, pd->regs + EVEN_DMA_STRIDE);
200 iowrite32(img_width, pd->regs + ODD_DMA_STRIDE);
201 /* enable interrupts, clear all irq flags */
202 iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START |
203 FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR);
204 iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN |
205 FLD_DN_ODD | FLD_DN_EVEN | CAP_CONT_EVEN | CAP_CONT_ODD,
206 pd->regs + CSR1);
207 wait_i2c_reg(pd->regs);
208 write_i2c_reg(pd->regs, CONFIG, pd->config);
209 write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE);
210 write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_DONE);
211
212 /* start the board */
213 write_i2c_reg(pd->regs, CSR2, pd->csr2 | BUSY_EVEN | BUSY_ODD);
214 return 0; /* success */
215}
216
217/*
218 * driver-specific callbacks (vb2_ops)
219 */
220static int
221dt3155_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
222 unsigned int *num_buffers, unsigned int *num_planes,
223 unsigned int sizes[], void *alloc_ctxs[])
224
225{
226 struct dt3155_priv *pd = vb2_get_drv_priv(q);
227 void *ret;
228
229 if (*num_buffers == 0)
230 *num_buffers = 1;
231 *num_planes = 1;
232 sizes[0] = img_width * img_height;
233 if (pd->q->alloc_ctx[0])
234 return 0;
235 ret = vb2_dma_contig_init_ctx(&pd->pdev->dev);
236 if (IS_ERR(ret))
237 return PTR_ERR(ret);
238 pd->q->alloc_ctx[0] = ret;
239 return 0;
240}
241
242static void
243dt3155_wait_prepare(struct vb2_queue *q)
244{
245 struct dt3155_priv *pd = vb2_get_drv_priv(q);
246
247 mutex_unlock(pd->vdev.lock);
248}
249
250static void
251dt3155_wait_finish(struct vb2_queue *q)
252{
253 struct dt3155_priv *pd = vb2_get_drv_priv(q);
254
255 mutex_lock(pd->vdev.lock);
256}
257
258static int
259dt3155_buf_prepare(struct vb2_buffer *vb)
260{
261 vb2_set_plane_payload(vb, 0, img_width * img_height);
262 return 0;
263}
264
265static void
266dt3155_stop_streaming(struct vb2_queue *q)
267{
268 struct dt3155_priv *pd = vb2_get_drv_priv(q);
269 struct vb2_buffer *vb;
270
271 spin_lock_irq(&pd->lock);
272 while (!list_empty(&pd->dmaq)) {
273 vb = list_first_entry(&pd->dmaq, typeof(*vb), done_entry);
274 list_del(&vb->done_entry);
275 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
276 }
277 spin_unlock_irq(&pd->lock);
278 msleep(45); /* irq hendler will stop the hardware */
279}
280
281static void
282dt3155_buf_queue(struct vb2_buffer *vb)
283{
284 struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue);
285
286 /* pd->q->streaming = 1 when dt3155_buf_queue() is invoked */
287 spin_lock_irq(&pd->lock);
288 if (pd->curr_buf)
289 list_add_tail(&vb->done_entry, &pd->dmaq);
290 else {
291 pd->curr_buf = vb;
292 dt3155_start_acq(pd);
293 }
294 spin_unlock_irq(&pd->lock);
295}
296/*
297 * end driver-specific callbacks
298 */
299
300static const struct vb2_ops q_ops = {
301 .queue_setup = dt3155_queue_setup,
302 .wait_prepare = dt3155_wait_prepare,
303 .wait_finish = dt3155_wait_finish,
304 .buf_prepare = dt3155_buf_prepare,
305 .stop_streaming = dt3155_stop_streaming,
306 .buf_queue = dt3155_buf_queue,
307};
308
309static irqreturn_t
310dt3155_irq_handler_even(int irq, void *dev_id)
311{
312 struct dt3155_priv *ipd = dev_id;
313 struct vb2_buffer *ivb;
314 dma_addr_t dma_addr;
315 u32 tmp;
316
317 tmp = ioread32(ipd->regs + INT_CSR) & (FLD_START | FLD_END_ODD);
318 if (!tmp)
319 return IRQ_NONE; /* not our irq */
320 if ((tmp & FLD_START) && !(tmp & FLD_END_ODD)) {
321 iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START,
322 ipd->regs + INT_CSR);
323 ipd->field_count++;
324 return IRQ_HANDLED; /* start of field irq */
325 }
326 if ((tmp & FLD_START) && (tmp & FLD_END_ODD))
327 ipd->stats.start_before_end++;
328 /* check for corrupted fields */
329/* write_i2c_reg(ipd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE); */
330/* write_i2c_reg(ipd->regs, ODD_CSR, CSR_ERROR | CSR_DONE); */
331 tmp = ioread32(ipd->regs + CSR1) & (FLD_CRPT_EVEN | FLD_CRPT_ODD);
332 if (tmp) {
333 ipd->stats.corrupted_fields++;
334 iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN |
335 FLD_DN_ODD | FLD_DN_EVEN |
336 CAP_CONT_EVEN | CAP_CONT_ODD,
337 ipd->regs + CSR1);
338 mmiowb();
339 }
340
341 spin_lock(&ipd->lock);
342 if (ipd->curr_buf) {
343 v4l2_get_timestamp(&ipd->curr_buf->v4l2_buf.timestamp);
344 ipd->curr_buf->v4l2_buf.sequence = (ipd->field_count) >> 1;
345 vb2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE);
346 }
347
348 if (!ipd->q->streaming || list_empty(&ipd->dmaq))
349 goto stop_dma;
350 ivb = list_first_entry(&ipd->dmaq, typeof(*ivb), done_entry);
351 list_del(&ivb->done_entry);
352 ipd->curr_buf = ivb;
353 dma_addr = vb2_dma_contig_plane_dma_addr(ivb, 0);
354 iowrite32(dma_addr, ipd->regs + EVEN_DMA_START);
355 iowrite32(dma_addr + img_width, ipd->regs + ODD_DMA_START);
356 iowrite32(img_width, ipd->regs + EVEN_DMA_STRIDE);
357 iowrite32(img_width, ipd->regs + ODD_DMA_STRIDE);
358 mmiowb();
359 /* enable interrupts, clear all irq flags */
360 iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START |
361 FLD_END_EVEN | FLD_END_ODD, ipd->regs + INT_CSR);
362 spin_unlock(&ipd->lock);
363 return IRQ_HANDLED;
364
365stop_dma:
366 ipd->curr_buf = NULL;
367 /* stop the board */
368 write_i2c_reg_nowait(ipd->regs, CSR2, ipd->csr2);
369 iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN |
370 FLD_DN_ODD | FLD_DN_EVEN, ipd->regs + CSR1);
371 /* disable interrupts, clear all irq flags */
372 iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, ipd->regs + INT_CSR);
373 spin_unlock(&ipd->lock);
374 return IRQ_HANDLED;
375}
376
377static int
378dt3155_open(struct file *filp)
379{
380 int ret = 0;
381 struct dt3155_priv *pd = video_drvdata(filp);
382
383 if (mutex_lock_interruptible(&pd->mux))
384 return -ERESTARTSYS;
385 if (!pd->users) {
386 pd->q = kzalloc(sizeof(*pd->q), GFP_KERNEL);
387 if (!pd->q) {
388 ret = -ENOMEM;
389 goto err_alloc_queue;
390 }
391 pd->q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
392 pd->q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
393 pd->q->io_modes = VB2_READ | VB2_MMAP;
394 pd->q->ops = &q_ops;
395 pd->q->mem_ops = &vb2_dma_contig_memops;
396 pd->q->drv_priv = pd;
397 pd->curr_buf = NULL;
398 pd->field_count = 0;
399 ret = vb2_queue_init(pd->q);
400 if (ret < 0)
401 goto err_request_irq;
402 INIT_LIST_HEAD(&pd->dmaq);
403 spin_lock_init(&pd->lock);
404 /* disable all irqs, clear all irq flags */
405 iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD,
406 pd->regs + INT_CSR);
407 ret = request_irq(pd->pdev->irq, dt3155_irq_handler_even,
408 IRQF_SHARED, DT3155_NAME, pd);
409 if (ret)
410 goto err_request_irq;
411 }
412 pd->users++;
413 mutex_unlock(&pd->mux);
414 return 0; /* success */
415err_request_irq:
416 kfree(pd->q);
417 pd->q = NULL;
418err_alloc_queue:
419 mutex_unlock(&pd->mux);
420 return ret;
421}
422
423static int
424dt3155_release(struct file *filp)
425{
426 struct dt3155_priv *pd = video_drvdata(filp);
427
428 mutex_lock(&pd->mux);
429 pd->users--;
430 BUG_ON(pd->users < 0);
431 if (!pd->users) {
432 vb2_queue_release(pd->q);
433 free_irq(pd->pdev->irq, pd);
434 if (pd->q->alloc_ctx[0])
435 vb2_dma_contig_cleanup_ctx(pd->q->alloc_ctx[0]);
436 kfree(pd->q);
437 pd->q = NULL;
438 }
439 mutex_unlock(&pd->mux);
440 return 0;
441}
442
443static ssize_t
444dt3155_read(struct file *filp, char __user *user, size_t size, loff_t *loff)
445{
446 struct dt3155_priv *pd = video_drvdata(filp);
447 ssize_t res;
448
449 if (mutex_lock_interruptible(&pd->mux))
450 return -ERESTARTSYS;
451 res = vb2_read(pd->q, user, size, loff, filp->f_flags & O_NONBLOCK);
452 mutex_unlock(&pd->mux);
453 return res;
454}
455
456static unsigned int
457dt3155_poll(struct file *filp, struct poll_table_struct *polltbl)
458{
459 struct dt3155_priv *pd = video_drvdata(filp);
460 unsigned int res;
461
462 mutex_lock(&pd->mux);
463 res = vb2_poll(pd->q, filp, polltbl);
464 mutex_unlock(&pd->mux);
465 return res;
466}
467
468static int
469dt3155_mmap(struct file *filp, struct vm_area_struct *vma)
470{
471 struct dt3155_priv *pd = video_drvdata(filp);
472 int res;
473
474 if (mutex_lock_interruptible(&pd->mux))
475 return -ERESTARTSYS;
476 res = vb2_mmap(pd->q, vma);
477 mutex_unlock(&pd->mux);
478 return res;
479}
480
481static const struct v4l2_file_operations dt3155_fops = {
482 .owner = THIS_MODULE,
483 .open = dt3155_open,
484 .release = dt3155_release,
485 .read = dt3155_read,
486 .poll = dt3155_poll,
487 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
488 .mmap = dt3155_mmap,
489};
490
491static int
492dt3155_ioc_streamon(struct file *filp, void *p, enum v4l2_buf_type type)
493{
494 struct dt3155_priv *pd = video_drvdata(filp);
495
496 return vb2_streamon(pd->q, type);
497}
498
499static int
500dt3155_ioc_streamoff(struct file *filp, void *p, enum v4l2_buf_type type)
501{
502 struct dt3155_priv *pd = video_drvdata(filp);
503
504 return vb2_streamoff(pd->q, type);
505}
506
507static int
508dt3155_ioc_querycap(struct file *filp, void *p, struct v4l2_capability *cap)
509{
510 struct dt3155_priv *pd = video_drvdata(filp);
511
512 strcpy(cap->driver, DT3155_NAME);
513 strcpy(cap->card, DT3155_NAME " frame grabber");
514 sprintf(cap->bus_info, "PCI:%s", pci_name(pd->pdev));
515 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
516 DT3155_CAPTURE_METHOD;
517 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
518 return 0;
519}
520
521static int
522dt3155_ioc_enum_fmt_vid_cap(struct file *filp, void *p, struct v4l2_fmtdesc *f)
523{
524 if (f->index >= NUM_OF_FORMATS)
525 return -EINVAL;
526 *f = frame_std[f->index];
527 return 0;
528}
529
530static int
531dt3155_ioc_g_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f)
532{
533 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
534 return -EINVAL;
535 f->fmt.pix.width = img_width;
536 f->fmt.pix.height = img_height;
537 f->fmt.pix.pixelformat = V4L2_PIX_FMT_GREY;
538 f->fmt.pix.field = V4L2_FIELD_NONE;
539 f->fmt.pix.bytesperline = f->fmt.pix.width;
540 f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height;
541 f->fmt.pix.colorspace = 0;
542 f->fmt.pix.priv = 0;
543 return 0;
544}
545
546static int
547dt3155_ioc_try_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f)
548{
549 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
550 return -EINVAL;
551 if (f->fmt.pix.width == img_width &&
552 f->fmt.pix.height == img_height &&
553 f->fmt.pix.pixelformat == V4L2_PIX_FMT_GREY &&
554 f->fmt.pix.field == V4L2_FIELD_NONE &&
555 f->fmt.pix.bytesperline == f->fmt.pix.width &&
556 f->fmt.pix.sizeimage == f->fmt.pix.width * f->fmt.pix.height)
557 return 0;
558 else
559 return -EINVAL;
560}
561
562static int
563dt3155_ioc_s_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f)
564{
565 return dt3155_ioc_g_fmt_vid_cap(filp, p, f);
566}
567
568static int
569dt3155_ioc_reqbufs(struct file *filp, void *p, struct v4l2_requestbuffers *b)
570{
571 struct dt3155_priv *pd = video_drvdata(filp);
572
573 return vb2_reqbufs(pd->q, b);
574}
575
576static int
577dt3155_ioc_querybuf(struct file *filp, void *p, struct v4l2_buffer *b)
578{
579 struct dt3155_priv *pd = video_drvdata(filp);
580
581 return vb2_querybuf(pd->q, b);
582}
583
584static int
585dt3155_ioc_qbuf(struct file *filp, void *p, struct v4l2_buffer *b)
586{
587 struct dt3155_priv *pd = video_drvdata(filp);
588
589 return vb2_qbuf(pd->q, b);
590}
591
592static int
593dt3155_ioc_dqbuf(struct file *filp, void *p, struct v4l2_buffer *b)
594{
595 struct dt3155_priv *pd = video_drvdata(filp);
596
597 return vb2_dqbuf(pd->q, b, filp->f_flags & O_NONBLOCK);
598}
599
600static int
601dt3155_ioc_querystd(struct file *filp, void *p, v4l2_std_id *norm)
602{
603 *norm = DT3155_CURRENT_NORM;
604 return 0;
605}
606
607static int
608dt3155_ioc_g_std(struct file *filp, void *p, v4l2_std_id *norm)
609{
610 *norm = DT3155_CURRENT_NORM;
611 return 0;
612}
613
614static int
615dt3155_ioc_s_std(struct file *filp, void *p, v4l2_std_id norm)
616{
617 if (norm & DT3155_CURRENT_NORM)
618 return 0;
619 return -EINVAL;
620}
621
622static int
623dt3155_ioc_enum_input(struct file *filp, void *p, struct v4l2_input *input)
624{
625 if (input->index)
626 return -EINVAL;
627 strcpy(input->name, "Coax in");
628 input->type = V4L2_INPUT_TYPE_CAMERA;
629 /*
630 * FIXME: input->std = 0 according to v4l2 API
631 * VIDIOC_G_STD, VIDIOC_S_STD, VIDIOC_QUERYSTD and VIDIOC_ENUMSTD
632 * should return -EINVAL
633 */
634 input->std = DT3155_CURRENT_NORM;
635 input->status = 0;/* FIXME: add sync detection & V4L2_IN_ST_NO_H_LOCK */
636 return 0;
637}
638
639static int
640dt3155_ioc_g_input(struct file *filp, void *p, unsigned int *i)
641{
642 *i = 0;
643 return 0;
644}
645
646static int
647dt3155_ioc_s_input(struct file *filp, void *p, unsigned int i)
648{
649 if (i)
650 return -EINVAL;
651 return 0;
652}
653
654static int
655dt3155_ioc_g_parm(struct file *filp, void *p, struct v4l2_streamparm *parms)
656{
657 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
658 return -EINVAL;
659 parms->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
660 parms->parm.capture.capturemode = 0;
661 parms->parm.capture.timeperframe.numerator = 1001;
662 parms->parm.capture.timeperframe.denominator = frames_per_sec * 1000;
663 parms->parm.capture.extendedmode = 0;
664 parms->parm.capture.readbuffers = 1; /* FIXME: 2 buffers? */
665 return 0;
666}
667
668static int
669dt3155_ioc_s_parm(struct file *filp, void *p, struct v4l2_streamparm *parms)
670{
671 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
672 return -EINVAL;
673 parms->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
674 parms->parm.capture.capturemode = 0;
675 parms->parm.capture.timeperframe.numerator = 1001;
676 parms->parm.capture.timeperframe.denominator = frames_per_sec * 1000;
677 parms->parm.capture.extendedmode = 0;
678 parms->parm.capture.readbuffers = 1; /* FIXME: 2 buffers? */
679 return 0;
680}
681
682static const struct v4l2_ioctl_ops dt3155_ioctl_ops = {
683 .vidioc_streamon = dt3155_ioc_streamon,
684 .vidioc_streamoff = dt3155_ioc_streamoff,
685 .vidioc_querycap = dt3155_ioc_querycap,
686/*
687 .vidioc_g_priority = dt3155_ioc_g_priority,
688 .vidioc_s_priority = dt3155_ioc_s_priority,
689*/
690 .vidioc_enum_fmt_vid_cap = dt3155_ioc_enum_fmt_vid_cap,
691 .vidioc_try_fmt_vid_cap = dt3155_ioc_try_fmt_vid_cap,
692 .vidioc_g_fmt_vid_cap = dt3155_ioc_g_fmt_vid_cap,
693 .vidioc_s_fmt_vid_cap = dt3155_ioc_s_fmt_vid_cap,
694 .vidioc_reqbufs = dt3155_ioc_reqbufs,
695 .vidioc_querybuf = dt3155_ioc_querybuf,
696 .vidioc_qbuf = dt3155_ioc_qbuf,
697 .vidioc_dqbuf = dt3155_ioc_dqbuf,
698 .vidioc_querystd = dt3155_ioc_querystd,
699 .vidioc_g_std = dt3155_ioc_g_std,
700 .vidioc_s_std = dt3155_ioc_s_std,
701 .vidioc_enum_input = dt3155_ioc_enum_input,
702 .vidioc_g_input = dt3155_ioc_g_input,
703 .vidioc_s_input = dt3155_ioc_s_input,
704/*
705 .vidioc_queryctrl = dt3155_ioc_queryctrl,
706 .vidioc_g_ctrl = dt3155_ioc_g_ctrl,
707 .vidioc_s_ctrl = dt3155_ioc_s_ctrl,
708 .vidioc_querymenu = dt3155_ioc_querymenu,
709 .vidioc_g_ext_ctrls = dt3155_ioc_g_ext_ctrls,
710 .vidioc_s_ext_ctrls = dt3155_ioc_s_ext_ctrls,
711*/
712 .vidioc_g_parm = dt3155_ioc_g_parm,
713 .vidioc_s_parm = dt3155_ioc_s_parm,
714/*
715 .vidioc_cropcap = dt3155_ioc_cropcap,
716 .vidioc_g_crop = dt3155_ioc_g_crop,
717 .vidioc_s_crop = dt3155_ioc_s_crop,
718 .vidioc_enum_framesizes = dt3155_ioc_enum_framesizes,
719 .vidioc_enum_frameintervals = dt3155_ioc_enum_frameintervals,
720*/
721};
722
723static int
724dt3155_init_board(struct pci_dev *pdev)
725{
726 struct dt3155_priv *pd = pci_get_drvdata(pdev);
727 void *buf_cpu;
728 dma_addr_t buf_dma;
729 int i;
730 u8 tmp;
731
732 pci_set_master(pdev); /* dt3155 needs it */
733
734 /* resetting the adapter */
735 iowrite32(FLD_CRPT_ODD | FLD_CRPT_EVEN | FLD_DN_ODD | FLD_DN_EVEN,
736 pd->regs + CSR1);
737 mmiowb();
738 msleep(20);
739
740 /* initializing adaper registers */
741 iowrite32(FIFO_EN | SRST, pd->regs + CSR1);
742 mmiowb();
743 iowrite32(0xEEEEEE01, pd->regs + EVEN_PIXEL_FMT);
744 iowrite32(0xEEEEEE01, pd->regs + ODD_PIXEL_FMT);
745 iowrite32(0x00000020, pd->regs + FIFO_TRIGER);
746 iowrite32(0x00000103, pd->regs + XFER_MODE);
747 iowrite32(0, pd->regs + RETRY_WAIT_CNT);
748 iowrite32(0, pd->regs + INT_CSR);
749 iowrite32(1, pd->regs + EVEN_FLD_MASK);
750 iowrite32(1, pd->regs + ODD_FLD_MASK);
751 iowrite32(0, pd->regs + MASK_LENGTH);
752 iowrite32(0x0005007C, pd->regs + FIFO_FLAG_CNT);
753 iowrite32(0x01010101, pd->regs + IIC_CLK_DUR);
754 mmiowb();
755
756 /* verifying that we have a DT3155 board (not just a SAA7116 chip) */
757 read_i2c_reg(pd->regs, DT_ID, &tmp);
758 if (tmp != DT3155_ID)
759 return -ENODEV;
760
761 /* initialize AD LUT */
762 write_i2c_reg(pd->regs, AD_ADDR, 0);
763 for (i = 0; i < 256; i++)
764 write_i2c_reg(pd->regs, AD_LUT, i);
765
766 /* initialize ADC references */
767 /* FIXME: pos_ref & neg_ref depend on VT_50HZ */
768 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
769 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3);
770 write_i2c_reg(pd->regs, AD_ADDR, AD_POS_REF);
771 write_i2c_reg(pd->regs, AD_CMD, 34);
772 write_i2c_reg(pd->regs, AD_ADDR, AD_NEG_REF);
773 write_i2c_reg(pd->regs, AD_CMD, 0);
774
775 /* initialize PM LUT */
776 write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM);
777 for (i = 0; i < 256; i++) {
778 write_i2c_reg(pd->regs, PM_LUT_ADDR, i);
779 write_i2c_reg(pd->regs, PM_LUT_DATA, i);
780 }
781 write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM | PM_LUT_SEL);
782 for (i = 0; i < 256; i++) {
783 write_i2c_reg(pd->regs, PM_LUT_ADDR, i);
784 write_i2c_reg(pd->regs, PM_LUT_DATA, i);
785 }
786 write_i2c_reg(pd->regs, CONFIG, pd->config); /* ACQ_MODE_EVEN */
787
788 /* select channel 1 for input and set sync level */
789 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
790 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3);
791
792 /* allocate memory, and initialize the DMA machine */
793 buf_cpu = dma_alloc_coherent(&pdev->dev, DT3155_BUF_SIZE, &buf_dma,
794 GFP_KERNEL);
795 if (!buf_cpu)
796 return -ENOMEM;
797 iowrite32(buf_dma, pd->regs + EVEN_DMA_START);
798 iowrite32(buf_dma, pd->regs + ODD_DMA_START);
799 iowrite32(0, pd->regs + EVEN_DMA_STRIDE);
800 iowrite32(0, pd->regs + ODD_DMA_STRIDE);
801
802 /* Perform a pseudo even field acquire */
803 iowrite32(FIFO_EN | SRST | CAP_CONT_ODD, pd->regs + CSR1);
804 write_i2c_reg(pd->regs, CSR2, pd->csr2 | SYNC_SNTL);
805 write_i2c_reg(pd->regs, CONFIG, pd->config);
806 write_i2c_reg(pd->regs, EVEN_CSR, CSR_SNGL);
807 write_i2c_reg(pd->regs, CSR2, pd->csr2 | BUSY_EVEN | SYNC_SNTL);
808 msleep(100);
809 read_i2c_reg(pd->regs, CSR2, &tmp);
810 write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_SNGL | CSR_DONE);
811 write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_SNGL | CSR_DONE);
812 write_i2c_reg(pd->regs, CSR2, pd->csr2);
813 iowrite32(FIFO_EN | SRST | FLD_DN_EVEN | FLD_DN_ODD, pd->regs + CSR1);
814
815 /* deallocate memory */
816 dma_free_coherent(&pdev->dev, DT3155_BUF_SIZE, buf_cpu, buf_dma);
817 if (tmp & BUSY_EVEN)
818 return -EIO;
819 return 0;
820}
821
822static struct video_device dt3155_vdev = {
823 .name = DT3155_NAME,
824 .fops = &dt3155_fops,
825 .ioctl_ops = &dt3155_ioctl_ops,
826 .minor = -1,
827 .release = video_device_release_empty,
828 .tvnorms = DT3155_CURRENT_NORM,
829};
830
831/* same as in drivers/base/dma-coherent.c */
832struct dma_coherent_mem {
833 void *virt_base;
834 dma_addr_t device_base;
835 int size;
836 int flags;
837 unsigned long *bitmap;
838};
839
840static int
841dt3155_alloc_coherent(struct device *dev, size_t size, int flags)
842{
843 struct dma_coherent_mem *mem;
844 dma_addr_t dev_base;
845 int pages = size >> PAGE_SHIFT;
846 int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
847
848 if ((flags & DMA_MEMORY_MAP) == 0)
849 goto out;
850 if (!size)
851 goto out;
852 if (dev->dma_mem)
853 goto out;
854
855 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
856 if (!mem)
857 goto out;
858 mem->virt_base = dma_alloc_coherent(dev, size, &dev_base,
859 DT3155_COH_FLAGS);
860 if (!mem->virt_base)
861 goto err_alloc_coherent;
862 mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
863 if (!mem->bitmap)
864 goto err_bitmap;
865
866 /* coherent_dma_mask is already set to 32 bits */
867 mem->device_base = dev_base;
868 mem->size = pages;
869 mem->flags = flags;
870 dev->dma_mem = mem;
871 return DMA_MEMORY_MAP;
872
873err_bitmap:
874 dma_free_coherent(dev, size, mem->virt_base, dev_base);
875err_alloc_coherent:
876 kfree(mem);
877out:
878 return 0;
879}
880
881static void
882dt3155_free_coherent(struct device *dev)
883{
884 struct dma_coherent_mem *mem = dev->dma_mem;
885
886 if (!mem)
887 return;
888 dev->dma_mem = NULL;
889 dma_free_coherent(dev, mem->size << PAGE_SHIFT,
890 mem->virt_base, mem->device_base);
891 kfree(mem->bitmap);
892 kfree(mem);
893}
894
895static int
896dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id)
897{
898 int err;
899 struct dt3155_priv *pd;
900
901 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
902 if (err)
903 return -ENODEV;
904 pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL);
905 if (!pd)
906 return -ENOMEM;
907
908 pd->vdev = dt3155_vdev;
909 pci_set_drvdata(pdev, pd); /* for use in dt3155_remove() */
910 video_set_drvdata(&pd->vdev, pd); /* for use in video_fops */
911 pd->users = 0;
912 pd->pdev = pdev;
913 INIT_LIST_HEAD(&pd->dmaq);
914 mutex_init(&pd->mux);
915 pd->vdev.lock = &pd->mux; /* for locking v4l2_file_operations */
916 spin_lock_init(&pd->lock);
917 pd->csr2 = csr2_init;
918 pd->config = config_init;
919 err = pci_enable_device(pdev);
920 if (err)
921 return err;
922 err = pci_request_region(pdev, 0, pci_name(pdev));
923 if (err)
924 goto err_req_region;
925 pd->regs = pci_iomap(pdev, 0, pci_resource_len(pd->pdev, 0));
926 if (!pd->regs) {
927 err = -ENOMEM;
928 goto err_pci_iomap;
929 }
930 err = dt3155_init_board(pdev);
931 if (err)
932 goto err_init_board;
933 err = video_register_device(&pd->vdev, VFL_TYPE_GRABBER, -1);
934 if (err)
935 goto err_init_board;
936 if (dt3155_alloc_coherent(&pdev->dev, DT3155_CHUNK_SIZE,
937 DMA_MEMORY_MAP))
938 dev_info(&pdev->dev, "preallocated 8 buffers\n");
939 dev_info(&pdev->dev, "/dev/video%i is ready\n", pd->vdev.minor);
940 return 0; /* success */
941
942err_init_board:
943 pci_iounmap(pdev, pd->regs);
944err_pci_iomap:
945 pci_release_region(pdev, 0);
946err_req_region:
947 pci_disable_device(pdev);
948 return err;
949}
950
951static void
952dt3155_remove(struct pci_dev *pdev)
953{
954 struct dt3155_priv *pd = pci_get_drvdata(pdev);
955
956 dt3155_free_coherent(&pdev->dev);
957 video_unregister_device(&pd->vdev);
958 pci_iounmap(pdev, pd->regs);
959 pci_release_region(pdev, 0);
960 pci_disable_device(pdev);
961}
962
963static const struct pci_device_id pci_ids[] = {
964 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, DT3155_DEVICE_ID) },
965 { 0, /* zero marks the end */ },
966};
967MODULE_DEVICE_TABLE(pci, pci_ids);
968
969static struct pci_driver pci_driver = {
970 .name = DT3155_NAME,
971 .id_table = pci_ids,
972 .probe = dt3155_probe,
973 .remove = dt3155_remove,
974};
975
976module_pci_driver(pci_driver);
977
978MODULE_DESCRIPTION("video4linux pci-driver for dt3155 frame grabber");
979MODULE_AUTHOR("Marin Mitov <mitov@issp.bas.bg>");
980MODULE_VERSION(DT3155_VERSION);
981MODULE_LICENSE("GPL");
diff --git a/drivers/staging/media/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c
index 335b98a54237..62ec9f70dae4 100644
--- a/drivers/staging/media/lirc/lirc_imon.c
+++ b/drivers/staging/media/lirc/lirc_imon.c
@@ -693,10 +693,9 @@ static int imon_probe(struct usb_interface *interface,
693 int ifnum; 693 int ifnum;
694 int lirc_minor = 0; 694 int lirc_minor = 0;
695 int num_endpts; 695 int num_endpts;
696 int retval = 0; 696 int retval = -ENOMEM;
697 int display_ep_found = 0; 697 int display_ep_found = 0;
698 int ir_ep_found = 0; 698 int ir_ep_found = 0;
699 int alloc_status = 0;
700 int vfd_proto_6p = 0; 699 int vfd_proto_6p = 0;
701 struct imon_context *context = NULL; 700 struct imon_context *context = NULL;
702 int i; 701 int i;
@@ -706,10 +705,8 @@ static int imon_probe(struct usb_interface *interface,
706 mutex_lock(&driver_lock); 705 mutex_lock(&driver_lock);
707 706
708 context = kzalloc(sizeof(struct imon_context), GFP_KERNEL); 707 context = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
709 if (!context) { 708 if (!context)
710 alloc_status = 1; 709 goto driver_unlock;
711 goto alloc_status_switch;
712 }
713 710
714 /* 711 /*
715 * Try to auto-detect the type of display if the user hasn't set 712 * Try to auto-detect the type of display if the user hasn't set
@@ -775,8 +772,7 @@ static int imon_probe(struct usb_interface *interface,
775 dev_err(dev, "%s: no valid input (IR) endpoint found.\n", 772 dev_err(dev, "%s: no valid input (IR) endpoint found.\n",
776 __func__); 773 __func__);
777 retval = -ENODEV; 774 retval = -ENODEV;
778 alloc_status = 2; 775 goto free_context;
779 goto alloc_status_switch;
780 } 776 }
781 777
782 /* Determine if display requires 6 packets */ 778 /* Determine if display requires 6 packets */
@@ -790,31 +786,26 @@ static int imon_probe(struct usb_interface *interface,
790 786
791 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); 787 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
792 if (!driver) { 788 if (!driver) {
793 alloc_status = 2; 789 goto free_context;
794 goto alloc_status_switch;
795 } 790 }
796 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); 791 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
797 if (!rbuf) { 792 if (!rbuf) {
798 alloc_status = 3; 793 goto free_driver;
799 goto alloc_status_switch;
800 } 794 }
801 if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) { 795 if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) {
802 dev_err(dev, "%s: lirc_buffer_init failed\n", __func__); 796 dev_err(dev, "%s: lirc_buffer_init failed\n", __func__);
803 alloc_status = 4; 797 goto free_rbuf;
804 goto alloc_status_switch;
805 } 798 }
806 rx_urb = usb_alloc_urb(0, GFP_KERNEL); 799 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
807 if (!rx_urb) { 800 if (!rx_urb) {
808 dev_err(dev, "%s: usb_alloc_urb failed for IR urb\n", __func__); 801 dev_err(dev, "%s: usb_alloc_urb failed for IR urb\n", __func__);
809 alloc_status = 5; 802 goto free_lirc_buf;
810 goto alloc_status_switch;
811 } 803 }
812 tx_urb = usb_alloc_urb(0, GFP_KERNEL); 804 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
813 if (!tx_urb) { 805 if (!tx_urb) {
814 dev_err(dev, "%s: usb_alloc_urb failed for display urb\n", 806 dev_err(dev, "%s: usb_alloc_urb failed for display urb\n",
815 __func__); 807 __func__);
816 alloc_status = 6; 808 goto free_rx_urb;
817 goto alloc_status_switch;
818 } 809 }
819 810
820 mutex_init(&context->ctx_lock); 811 mutex_init(&context->ctx_lock);
@@ -840,11 +831,11 @@ static int imon_probe(struct usb_interface *interface,
840 lirc_minor = lirc_register_driver(driver); 831 lirc_minor = lirc_register_driver(driver);
841 if (lirc_minor < 0) { 832 if (lirc_minor < 0) {
842 dev_err(dev, "%s: lirc_register_driver failed\n", __func__); 833 dev_err(dev, "%s: lirc_register_driver failed\n", __func__);
843 alloc_status = 7; 834 goto free_tx_urb;
844 goto unlock; 835 }
845 } else 836
846 dev_info(dev, "Registered iMON driver (lirc minor: %d)\n", 837 dev_info(dev, "Registered iMON driver (lirc minor: %d)\n",
847 lirc_minor); 838 lirc_minor);
848 839
849 /* Needed while unregistering! */ 840 /* Needed while unregistering! */
850 driver->minor = lirc_minor; 841 driver->minor = lirc_minor;
@@ -872,11 +863,9 @@ static int imon_probe(struct usb_interface *interface,
872 context->rx_endpoint->bInterval); 863 context->rx_endpoint->bInterval);
873 864
874 retval = usb_submit_urb(context->rx_urb, GFP_KERNEL); 865 retval = usb_submit_urb(context->rx_urb, GFP_KERNEL);
875
876 if (retval) { 866 if (retval) {
877 dev_err(dev, "usb_submit_urb failed for intf0 (%d)\n", retval); 867 dev_err(dev, "usb_submit_urb failed for intf0 (%d)\n", retval);
878 alloc_status = 8; 868 goto unregister_lirc;
879 goto unlock;
880 } 869 }
881 870
882 usb_set_intfdata(interface, context); 871 usb_set_intfdata(interface, context);
@@ -895,39 +884,31 @@ static int imon_probe(struct usb_interface *interface,
895 dev_info(dev, "iMON device (%04x:%04x, intf%d) on usb<%d:%d> initialized\n", 884 dev_info(dev, "iMON device (%04x:%04x, intf%d) on usb<%d:%d> initialized\n",
896 vendor, product, ifnum, usbdev->bus->busnum, usbdev->devnum); 885 vendor, product, ifnum, usbdev->bus->busnum, usbdev->devnum);
897 886
898unlock: 887 /* Everything went fine. Just unlock and return retval (with is 0) */
899 mutex_unlock(&context->ctx_lock); 888 goto driver_unlock;
900alloc_status_switch: 889
901 890unregister_lirc:
902 switch (alloc_status) { 891 lirc_unregister_driver(driver->minor);
903 case 8: 892
904 lirc_unregister_driver(driver->minor); 893free_tx_urb:
905 case 7: 894 usb_free_urb(tx_urb);
906 usb_free_urb(tx_urb); 895
907 case 6: 896free_rx_urb:
908 usb_free_urb(rx_urb); 897 usb_free_urb(rx_urb);
909 /* fall-through */ 898
910 case 5: 899free_lirc_buf:
911 if (rbuf) 900 lirc_buffer_free(rbuf);
912 lirc_buffer_free(rbuf); 901
913 /* fall-through */ 902free_rbuf:
914 case 4: 903 kfree(rbuf);
915 kfree(rbuf); 904
916 /* fall-through */ 905free_driver:
917 case 3: 906 kfree(driver);
918 kfree(driver); 907free_context:
919 /* fall-through */ 908 kfree(context);
920 case 2: 909 context = NULL;
921 kfree(context);
922 context = NULL;
923 case 1:
924 if (retval != -ENODEV)
925 retval = -ENOMEM;
926 break;
927 case 0:
928 retval = 0;
929 }
930 910
911driver_unlock:
931 mutex_unlock(&driver_lock); 912 mutex_unlock(&driver_lock);
932 913
933 return retval; 914 return retval;
diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
index 29087f66e2f4..4f326e97ad75 100644
--- a/drivers/staging/media/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
@@ -44,7 +44,7 @@
44#include <linux/ioport.h> 44#include <linux/ioport.h>
45#include <linux/kernel.h> 45#include <linux/kernel.h>
46#include <linux/serial_reg.h> 46#include <linux/serial_reg.h>
47#include <linux/time.h> 47#include <linux/ktime.h>
48#include <linux/string.h> 48#include <linux/string.h>
49#include <linux/types.h> 49#include <linux/types.h>
50#include <linux/wait.h> 50#include <linux/wait.h>
@@ -127,9 +127,9 @@ static int threshold = 3;
127static DEFINE_SPINLOCK(timer_lock); 127static DEFINE_SPINLOCK(timer_lock);
128static struct timer_list timerlist; 128static struct timer_list timerlist;
129/* time of last signal change detected */ 129/* time of last signal change detected */
130static struct timeval last_tv = {0, 0}; 130static ktime_t last;
131/* time of last UART data ready interrupt */ 131/* time of last UART data ready interrupt */
132static struct timeval last_intr_tv = {0, 0}; 132static ktime_t last_intr_time;
133static int last_value; 133static int last_value;
134 134
135static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue); 135static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
@@ -400,20 +400,6 @@ static void drop_chrdev(void)
400} 400}
401 401
402/* SECTION: Hardware */ 402/* SECTION: Hardware */
403static long delta(struct timeval *tv1, struct timeval *tv2)
404{
405 unsigned long deltv;
406
407 deltv = tv2->tv_sec - tv1->tv_sec;
408 if (deltv > 15)
409 deltv = 0xFFFFFF;
410 else
411 deltv = deltv*1000000 +
412 tv2->tv_usec -
413 tv1->tv_usec;
414 return deltv;
415}
416
417static void sir_timeout(unsigned long data) 403static void sir_timeout(unsigned long data)
418{ 404{
419 /* 405 /*
@@ -432,12 +418,14 @@ static void sir_timeout(unsigned long data)
432 /* clear unread bits in UART and restart */ 418 /* clear unread bits in UART and restart */
433 outb(UART_FCR_CLEAR_RCVR, io + UART_FCR); 419 outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
434 /* determine 'virtual' pulse end: */ 420 /* determine 'virtual' pulse end: */
435 pulse_end = delta(&last_tv, &last_intr_tv); 421 pulse_end = min_t(unsigned long,
422 ktime_us_delta(last, last_intr_time),
423 PULSE_MASK);
436 dev_dbg(driver.dev, "timeout add %d for %lu usec\n", 424 dev_dbg(driver.dev, "timeout add %d for %lu usec\n",
437 last_value, pulse_end); 425 last_value, pulse_end);
438 add_read_queue(last_value, pulse_end); 426 add_read_queue(last_value, pulse_end);
439 last_value = 0; 427 last_value = 0;
440 last_tv = last_intr_tv; 428 last = last_intr_time;
441 } 429 }
442 spin_unlock_irqrestore(&timer_lock, flags); 430 spin_unlock_irqrestore(&timer_lock, flags);
443} 431}
@@ -445,9 +433,9 @@ static void sir_timeout(unsigned long data)
445static irqreturn_t sir_interrupt(int irq, void *dev_id) 433static irqreturn_t sir_interrupt(int irq, void *dev_id)
446{ 434{
447 unsigned char data; 435 unsigned char data;
448 struct timeval curr_tv; 436 ktime_t curr_time;
449 static unsigned long deltv; 437 static unsigned long delt;
450 unsigned long deltintrtv; 438 unsigned long deltintr;
451 unsigned long flags; 439 unsigned long flags;
452 int iir, lsr; 440 int iir, lsr;
453 441
@@ -471,49 +459,46 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
471 do { 459 do {
472 del_timer(&timerlist); 460 del_timer(&timerlist);
473 data = inb(io + UART_RX); 461 data = inb(io + UART_RX);
474 do_gettimeofday(&curr_tv); 462 curr_time = ktime_get();
475 deltv = delta(&last_tv, &curr_tv); 463 delt = min_t(unsigned long,
476 deltintrtv = delta(&last_intr_tv, &curr_tv); 464 ktime_us_delta(last, curr_time),
465 PULSE_MASK);
466 deltintr = min_t(unsigned long,
467 ktime_us_delta(last_intr_time,
468 curr_time),
469 PULSE_MASK);
477 dev_dbg(driver.dev, "t %lu, d %d\n", 470 dev_dbg(driver.dev, "t %lu, d %d\n",
478 deltintrtv, (int)data); 471 deltintr, (int)data);
479 /* 472 /*
480 * if nothing came in last X cycles, 473 * if nothing came in last X cycles,
481 * it was gap 474 * it was gap
482 */ 475 */
483 if (deltintrtv > TIME_CONST * threshold) { 476 if (deltintr > TIME_CONST * threshold) {
484 if (last_value) { 477 if (last_value) {
485 dev_dbg(driver.dev, "GAP\n"); 478 dev_dbg(driver.dev, "GAP\n");
486 /* simulate signal change */ 479 /* simulate signal change */
487 add_read_queue(last_value, 480 add_read_queue(last_value,
488 deltv - 481 delt -
489 deltintrtv); 482 deltintr);
490 last_value = 0; 483 last_value = 0;
491 last_tv.tv_sec = 484 last = last_intr_time;
492 last_intr_tv.tv_sec; 485 delt = deltintr;
493 last_tv.tv_usec =
494 last_intr_tv.tv_usec;
495 deltv = deltintrtv;
496 } 486 }
497 } 487 }
498 data = 1; 488 data = 1;
499 if (data ^ last_value) { 489 if (data ^ last_value) {
500 /* 490 /*
501 * deltintrtv > 2*TIME_CONST, remember? 491 * deltintr > 2*TIME_CONST, remember?
502 * the other case is timeout 492 * the other case is timeout
503 */ 493 */
504 add_read_queue(last_value, 494 add_read_queue(last_value,
505 deltv-TIME_CONST); 495 delt-TIME_CONST);
506 last_value = data; 496 last_value = data;
507 last_tv = curr_tv; 497 last = curr_time;
508 if (last_tv.tv_usec >= TIME_CONST) { 498 last = ktime_sub_us(last,
509 last_tv.tv_usec -= TIME_CONST; 499 TIME_CONST);
510 } else {
511 last_tv.tv_sec--;
512 last_tv.tv_usec += 1000000 -
513 TIME_CONST;
514 }
515 } 500 }
516 last_intr_tv = curr_tv; 501 last_intr_time = curr_time;
517 if (data) { 502 if (data) {
518 /* 503 /*
519 * start timer for end of 504 * start timer for end of
diff --git a/drivers/staging/media/mn88472/mn88472.c b/drivers/staging/media/mn88472/mn88472.c
index a4cfcf57c99c..a8d45f44765c 100644
--- a/drivers/staging/media/mn88472/mn88472.c
+++ b/drivers/staging/media/mn88472/mn88472.c
@@ -218,7 +218,7 @@ err:
218 return ret; 218 return ret;
219} 219}
220 220
221static int mn88472_read_status(struct dvb_frontend *fe, fe_status_t *status) 221static int mn88472_read_status(struct dvb_frontend *fe, enum fe_status *status)
222{ 222{
223 struct i2c_client *client = fe->demodulator_priv; 223 struct i2c_client *client = fe->demodulator_priv;
224 struct mn88472_dev *dev = i2c_get_clientdata(client); 224 struct mn88472_dev *dev = i2c_get_clientdata(client);
@@ -344,12 +344,12 @@ static int mn88472_init(struct dvb_frontend *fe)
344 if (ret) { 344 if (ret) {
345 dev_err(&client->dev, 345 dev_err(&client->dev,
346 "parity reg read failed=%d\n", ret); 346 "parity reg read failed=%d\n", ret);
347 goto err; 347 goto firmware_release;
348 } 348 }
349 if (tmp & 0x10) { 349 if (tmp & 0x10) {
350 dev_err(&client->dev, 350 dev_err(&client->dev,
351 "firmware parity check failed=0x%x\n", tmp); 351 "firmware parity check failed=0x%x\n", tmp);
352 goto err; 352 goto firmware_release;
353 } 353 }
354 dev_err(&client->dev, "firmware parity check succeeded=0x%x\n", tmp); 354 dev_err(&client->dev, "firmware parity check succeeded=0x%x\n", tmp);
355 355
diff --git a/drivers/staging/media/mn88472/mn88472_priv.h b/drivers/staging/media/mn88472/mn88472_priv.h
index 9ba8c8b3823e..1a0de9e46b66 100644
--- a/drivers/staging/media/mn88472/mn88472_priv.h
+++ b/drivers/staging/media/mn88472/mn88472_priv.h
@@ -29,7 +29,7 @@ struct mn88472_dev {
29 struct regmap *regmap[3]; 29 struct regmap *regmap[3];
30 struct dvb_frontend fe; 30 struct dvb_frontend fe;
31 u16 i2c_wr_max; 31 u16 i2c_wr_max;
32 fe_delivery_system_t delivery_system; 32 enum fe_delivery_system delivery_system;
33 bool warm; /* FW running */ 33 bool warm; /* FW running */
34 u32 xtal; 34 u32 xtal;
35 int ts_mode; 35 int ts_mode;
diff --git a/drivers/staging/media/mn88473/mn88473.c b/drivers/staging/media/mn88473/mn88473.c
index 8b6736c70057..f9146a146d07 100644
--- a/drivers/staging/media/mn88473/mn88473.c
+++ b/drivers/staging/media/mn88473/mn88473.c
@@ -167,7 +167,7 @@ err:
167 return ret; 167 return ret;
168} 168}
169 169
170static int mn88473_read_status(struct dvb_frontend *fe, fe_status_t *status) 170static int mn88473_read_status(struct dvb_frontend *fe, enum fe_status *status)
171{ 171{
172 struct i2c_client *client = fe->demodulator_priv; 172 struct i2c_client *client = fe->demodulator_priv;
173 struct mn88473_dev *dev = i2c_get_clientdata(client); 173 struct mn88473_dev *dev = i2c_get_clientdata(client);
diff --git a/drivers/staging/media/mn88473/mn88473_priv.h b/drivers/staging/media/mn88473/mn88473_priv.h
index ef6f01323ac9..54beb4241ccf 100644
--- a/drivers/staging/media/mn88473/mn88473_priv.h
+++ b/drivers/staging/media/mn88473/mn88473_priv.h
@@ -29,7 +29,7 @@ struct mn88473_dev {
29 struct regmap *regmap[3]; 29 struct regmap *regmap[3];
30 struct dvb_frontend fe; 30 struct dvb_frontend fe;
31 u16 i2c_wr_max; 31 u16 i2c_wr_max;
32 fe_delivery_system_t delivery_system; 32 enum fe_delivery_system delivery_system;
33 bool warm; /* FW running */ 33 bool warm; /* FW running */
34 u32 xtal; 34 u32 xtal;
35}; 35};
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 7ced940bd807..9bfb725b9986 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1489,7 +1489,7 @@ static int iss_remove(struct platform_device *pdev)
1489 return 0; 1489 return 0;
1490} 1490}
1491 1491
1492static struct platform_device_id omap4iss_id_table[] = { 1492static const struct platform_device_id omap4iss_id_table[] = {
1493 { "omap4iss", 0 }, 1493 { "omap4iss", 0 },
1494 { }, 1494 { },
1495}; 1495};
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index d7ff7698a067..bc83f8246101 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -828,8 +828,10 @@ static const struct iss_video_operations csi2_issvideo_ops = {
828 */ 828 */
829 829
830static struct v4l2_mbus_framefmt * 830static struct v4l2_mbus_framefmt *
831__csi2_get_format(struct iss_csi2_device *csi2, struct v4l2_subdev_pad_config *cfg, 831__csi2_get_format(struct iss_csi2_device *csi2,
832 unsigned int pad, enum v4l2_subdev_format_whence which) 832 struct v4l2_subdev_pad_config *cfg,
833 unsigned int pad,
834 enum v4l2_subdev_format_whence which)
833{ 835{
834 if (which == V4L2_SUBDEV_FORMAT_TRY) 836 if (which == V4L2_SUBDEV_FORMAT_TRY)
835 return v4l2_subdev_get_try_format(&csi2->subdev, cfg, pad); 837 return v4l2_subdev_get_try_format(&csi2->subdev, cfg, pad);
@@ -838,8 +840,10 @@ __csi2_get_format(struct iss_csi2_device *csi2, struct v4l2_subdev_pad_config *c
838} 840}
839 841
840static void 842static void
841csi2_try_format(struct iss_csi2_device *csi2, struct v4l2_subdev_pad_config *cfg, 843csi2_try_format(struct iss_csi2_device *csi2,
842 unsigned int pad, struct v4l2_mbus_framefmt *fmt, 844 struct v4l2_subdev_pad_config *cfg,
845 unsigned int pad,
846 struct v4l2_mbus_framefmt *fmt,
843 enum v4l2_subdev_format_whence which) 847 enum v4l2_subdev_format_whence which)
844{ 848{
845 u32 pixelcode; 849 u32 pixelcode;
@@ -967,7 +971,8 @@ static int csi2_enum_frame_size(struct v4l2_subdev *sd,
967 * @fmt: pointer to v4l2 subdev format structure 971 * @fmt: pointer to v4l2 subdev format structure
968 * return -EINVAL or zero on success 972 * return -EINVAL or zero on success
969 */ 973 */
970static int csi2_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 974static int csi2_get_format(struct v4l2_subdev *sd,
975 struct v4l2_subdev_pad_config *cfg,
971 struct v4l2_subdev_format *fmt) 976 struct v4l2_subdev_format *fmt)
972{ 977{
973 struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd); 978 struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd);
@@ -988,7 +993,8 @@ static int csi2_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config
988 * @fmt: pointer to v4l2 subdev format structure 993 * @fmt: pointer to v4l2 subdev format structure
989 * return -EINVAL or zero on success 994 * return -EINVAL or zero on success
990 */ 995 */
991static int csi2_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 996static int csi2_set_format(struct v4l2_subdev *sd,
997 struct v4l2_subdev_pad_config *cfg,
992 struct v4l2_subdev_format *fmt) 998 struct v4l2_subdev_format *fmt)
993{ 999{
994 struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd); 1000 struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd);
diff --git a/drivers/staging/media/omap4iss/iss_ipipe.c b/drivers/staging/media/omap4iss/iss_ipipe.c
index eaa82da30f50..f94a59299a83 100644
--- a/drivers/staging/media/omap4iss/iss_ipipe.c
+++ b/drivers/staging/media/omap4iss/iss_ipipe.c
@@ -24,8 +24,10 @@
24#include "iss_ipipe.h" 24#include "iss_ipipe.h"
25 25
26static struct v4l2_mbus_framefmt * 26static struct v4l2_mbus_framefmt *
27__ipipe_get_format(struct iss_ipipe_device *ipipe, struct v4l2_subdev_pad_config *cfg, 27__ipipe_get_format(struct iss_ipipe_device *ipipe,
28 unsigned int pad, enum v4l2_subdev_format_whence which); 28 struct v4l2_subdev_pad_config *cfg,
29 unsigned int pad,
30 enum v4l2_subdev_format_whence which);
29 31
30static const unsigned int ipipe_fmts[] = { 32static const unsigned int ipipe_fmts[] = {
31 MEDIA_BUS_FMT_SGRBG10_1X10, 33 MEDIA_BUS_FMT_SGRBG10_1X10,
@@ -176,8 +178,10 @@ static int ipipe_set_stream(struct v4l2_subdev *sd, int enable)
176} 178}
177 179
178static struct v4l2_mbus_framefmt * 180static struct v4l2_mbus_framefmt *
179__ipipe_get_format(struct iss_ipipe_device *ipipe, struct v4l2_subdev_pad_config *cfg, 181__ipipe_get_format(struct iss_ipipe_device *ipipe,
180 unsigned int pad, enum v4l2_subdev_format_whence which) 182 struct v4l2_subdev_pad_config *cfg,
183 unsigned int pad,
184 enum v4l2_subdev_format_whence which)
181{ 185{
182 if (which == V4L2_SUBDEV_FORMAT_TRY) 186 if (which == V4L2_SUBDEV_FORMAT_TRY)
183 return v4l2_subdev_get_try_format(&ipipe->subdev, cfg, pad); 187 return v4l2_subdev_get_try_format(&ipipe->subdev, cfg, pad);
@@ -193,9 +197,11 @@ __ipipe_get_format(struct iss_ipipe_device *ipipe, struct v4l2_subdev_pad_config
193 * @fmt: Format 197 * @fmt: Format
194 */ 198 */
195static void 199static void
196ipipe_try_format(struct iss_ipipe_device *ipipe, struct v4l2_subdev_pad_config *cfg, 200ipipe_try_format(struct iss_ipipe_device *ipipe,
197 unsigned int pad, struct v4l2_mbus_framefmt *fmt, 201 struct v4l2_subdev_pad_config *cfg,
198 enum v4l2_subdev_format_whence which) 202 unsigned int pad,
203 struct v4l2_mbus_framefmt *fmt,
204 enum v4l2_subdev_format_whence which)
199{ 205{
200 struct v4l2_mbus_framefmt *format; 206 struct v4l2_mbus_framefmt *format;
201 unsigned int width = fmt->width; 207 unsigned int width = fmt->width;
@@ -306,8 +312,9 @@ static int ipipe_enum_frame_size(struct v4l2_subdev *sd,
306 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond 312 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
307 * to the format type. 313 * to the format type.
308 */ 314 */
309static int ipipe_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 315static int ipipe_get_format(struct v4l2_subdev *sd,
310 struct v4l2_subdev_format *fmt) 316 struct v4l2_subdev_pad_config *cfg,
317 struct v4l2_subdev_format *fmt)
311{ 318{
312 struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd); 319 struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
313 struct v4l2_mbus_framefmt *format; 320 struct v4l2_mbus_framefmt *format;
@@ -329,8 +336,9 @@ static int ipipe_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_confi
329 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond 336 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
330 * to the format type. 337 * to the format type.
331 */ 338 */
332static int ipipe_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 339static int ipipe_set_format(struct v4l2_subdev *sd,
333 struct v4l2_subdev_format *fmt) 340 struct v4l2_subdev_pad_config *cfg,
341 struct v4l2_subdev_format *fmt)
334{ 342{
335 struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd); 343 struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
336 struct v4l2_mbus_framefmt *format; 344 struct v4l2_mbus_framefmt *format;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index 530ac8426b5b..c0da13d55865 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -518,8 +518,9 @@ static int ipipeif_enum_frame_size(struct v4l2_subdev *sd,
518 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond 518 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
519 * to the format type. 519 * to the format type.
520 */ 520 */
521static int ipipeif_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 521static int ipipeif_get_format(struct v4l2_subdev *sd,
522 struct v4l2_subdev_format *fmt) 522 struct v4l2_subdev_pad_config *cfg,
523 struct v4l2_subdev_format *fmt)
523{ 524{
524 struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd); 525 struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
525 struct v4l2_mbus_framefmt *format; 526 struct v4l2_mbus_framefmt *format;
@@ -541,8 +542,9 @@ static int ipipeif_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_con
541 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond 542 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
542 * to the format type. 543 * to the format type.
543 */ 544 */
544static int ipipeif_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 545static int ipipeif_set_format(struct v4l2_subdev *sd,
545 struct v4l2_subdev_format *fmt) 546 struct v4l2_subdev_pad_config *cfg,
547 struct v4l2_subdev_format *fmt)
546{ 548{
547 struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd); 549 struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
548 struct v4l2_mbus_framefmt *format; 550 struct v4l2_mbus_framefmt *format;
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 5f69012c4deb..5030cf3cd34c 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -580,8 +580,9 @@ static int resizer_enum_frame_size(struct v4l2_subdev *sd,
580 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond 580 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
581 * to the format type. 581 * to the format type.
582 */ 582 */
583static int resizer_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 583static int resizer_get_format(struct v4l2_subdev *sd,
584 struct v4l2_subdev_format *fmt) 584 struct v4l2_subdev_pad_config *cfg,
585 struct v4l2_subdev_format *fmt)
585{ 586{
586 struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd); 587 struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
587 struct v4l2_mbus_framefmt *format; 588 struct v4l2_mbus_framefmt *format;
@@ -603,7 +604,8 @@ static int resizer_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_con
603 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond 604 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
604 * to the format type. 605 * to the format type.
605 */ 606 */
606static int resizer_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, 607static int resizer_set_format(struct v4l2_subdev *sd,
608 struct v4l2_subdev_pad_config *cfg,
607 struct v4l2_subdev_format *fmt) 609 struct v4l2_subdev_format *fmt)
608{ 610{
609 struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd); 611 struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
diff --git a/include/media/adp1653.h b/include/media/adp1653.h
index 1d9b48a3bd80..9779c8549eb4 100644
--- a/include/media/adp1653.h
+++ b/include/media/adp1653.h
@@ -100,9 +100,11 @@ struct adp1653_platform_data {
100 int (*power)(struct v4l2_subdev *sd, int on); 100 int (*power)(struct v4l2_subdev *sd, int on);
101 101
102 u32 max_flash_timeout; /* flash light timeout in us */ 102 u32 max_flash_timeout; /* flash light timeout in us */
103 u32 max_flash_intensity; /* led intensity, flash mode */ 103 u32 max_flash_intensity; /* led intensity, flash mode, mA */
104 u32 max_torch_intensity; /* led intensity, torch mode */ 104 u32 max_torch_intensity; /* led intensity, torch mode, mA */
105 u32 max_indicator_intensity; /* indicator led intensity */ 105 u32 max_indicator_intensity; /* indicator led intensity, uA */
106
107 struct gpio_desc *enable_gpio; /* for device-tree based boot */
106}; 108};
107 109
108#define to_adp1653_flash(sd) container_of(sd, struct adp1653_flash, subdev) 110#define to_adp1653_flash(sd) container_of(sd, struct adp1653_flash, subdev)
diff --git a/include/media/adv7511.h b/include/media/adv7511.h
index bb78bed9a5b8..d83b91d80764 100644
--- a/include/media/adv7511.h
+++ b/include/media/adv7511.h
@@ -40,9 +40,10 @@ struct adv7511_cec_arg {
40}; 40};
41 41
42struct adv7511_platform_data { 42struct adv7511_platform_data {
43 uint8_t i2c_edid; 43 u8 i2c_edid;
44 uint8_t i2c_cec; 44 u8 i2c_cec;
45 uint32_t cec_clk; 45 u8 i2c_pktmem;
46 u32 cec_clk;
46}; 47};
47 48
48#endif 49#endif
diff --git a/include/media/adv7604.h b/include/media/adv7604.h
index 9ecf353160c1..a913859bfd30 100644
--- a/include/media/adv7604.h
+++ b/include/media/adv7604.h
@@ -168,6 +168,5 @@ enum adv76xx_pad {
168 168
169/* notify events */ 169/* notify events */
170#define ADV76XX_HOTPLUG 1 170#define ADV76XX_HOTPLUG 1
171#define ADV76XX_FMT_CHANGE 2
172 171
173#endif 172#endif
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index 924cbb8d004a..bc249709bf35 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -30,14 +30,38 @@ enum adv7842_ain_sel {
30 ADV7842_AIN9_4_5_6_SYNC_2_1 = 4, 30 ADV7842_AIN9_4_5_6_SYNC_2_1 = 4,
31}; 31};
32 32
33/* Bus rotation and reordering (IO register 0x04, [7:5]) */ 33/*
34enum adv7842_op_ch_sel { 34 * Bus rotation and reordering. This is used to specify component reordering on
35 ADV7842_OP_CH_SEL_GBR = 0, 35 * the board and describes the components order on the bus when the ADV7842
36 ADV7842_OP_CH_SEL_GRB = 1, 36 * outputs RGB.
37 ADV7842_OP_CH_SEL_BGR = 2, 37 */
38 ADV7842_OP_CH_SEL_RGB = 3, 38enum adv7842_bus_order {
39 ADV7842_OP_CH_SEL_BRG = 4, 39 ADV7842_BUS_ORDER_RGB, /* No operation */
40 ADV7842_OP_CH_SEL_RBG = 5, 40 ADV7842_BUS_ORDER_GRB, /* Swap 1-2 */
41 ADV7842_BUS_ORDER_RBG, /* Swap 2-3 */
42 ADV7842_BUS_ORDER_BGR, /* Swap 1-3 */
43 ADV7842_BUS_ORDER_BRG, /* Rotate right */
44 ADV7842_BUS_ORDER_GBR, /* Rotate left */
45};
46
47/* Input Color Space (IO register 0x02, [7:4]) */
48enum adv7842_inp_color_space {
49 ADV7842_INP_COLOR_SPACE_LIM_RGB = 0,
50 ADV7842_INP_COLOR_SPACE_FULL_RGB = 1,
51 ADV7842_INP_COLOR_SPACE_LIM_YCbCr_601 = 2,
52 ADV7842_INP_COLOR_SPACE_LIM_YCbCr_709 = 3,
53 ADV7842_INP_COLOR_SPACE_XVYCC_601 = 4,
54 ADV7842_INP_COLOR_SPACE_XVYCC_709 = 5,
55 ADV7842_INP_COLOR_SPACE_FULL_YCbCr_601 = 6,
56 ADV7842_INP_COLOR_SPACE_FULL_YCbCr_709 = 7,
57 ADV7842_INP_COLOR_SPACE_AUTO = 0xf,
58};
59
60/* Select output format (IO register 0x03, [4:2]) */
61enum adv7842_op_format_mode_sel {
62 ADV7842_OP_FORMAT_MODE0 = 0x00,
63 ADV7842_OP_FORMAT_MODE1 = 0x04,
64 ADV7842_OP_FORMAT_MODE2 = 0x08,
41}; 65};
42 66
43/* Mode of operation */ 67/* Mode of operation */
@@ -61,44 +85,6 @@ enum adv7842_vid_std_select {
61 ADV7842_HDMI_COMP_VID_STD_HD_1250P = 0x1e, 85 ADV7842_HDMI_COMP_VID_STD_HD_1250P = 0x1e,
62}; 86};
63 87
64/* Input Color Space (IO register 0x02, [7:4]) */
65enum adv7842_inp_color_space {
66 ADV7842_INP_COLOR_SPACE_LIM_RGB = 0,
67 ADV7842_INP_COLOR_SPACE_FULL_RGB = 1,
68 ADV7842_INP_COLOR_SPACE_LIM_YCbCr_601 = 2,
69 ADV7842_INP_COLOR_SPACE_LIM_YCbCr_709 = 3,
70 ADV7842_INP_COLOR_SPACE_XVYCC_601 = 4,
71 ADV7842_INP_COLOR_SPACE_XVYCC_709 = 5,
72 ADV7842_INP_COLOR_SPACE_FULL_YCbCr_601 = 6,
73 ADV7842_INP_COLOR_SPACE_FULL_YCbCr_709 = 7,
74 ADV7842_INP_COLOR_SPACE_AUTO = 0xf,
75};
76
77/* Select output format (IO register 0x03, [7:0]) */
78enum adv7842_op_format_sel {
79 ADV7842_OP_FORMAT_SEL_SDR_ITU656_8 = 0x00,
80 ADV7842_OP_FORMAT_SEL_SDR_ITU656_10 = 0x01,
81 ADV7842_OP_FORMAT_SEL_SDR_ITU656_12_MODE0 = 0x02,
82 ADV7842_OP_FORMAT_SEL_SDR_ITU656_12_MODE1 = 0x06,
83 ADV7842_OP_FORMAT_SEL_SDR_ITU656_12_MODE2 = 0x0a,
84 ADV7842_OP_FORMAT_SEL_DDR_422_8 = 0x20,
85 ADV7842_OP_FORMAT_SEL_DDR_422_10 = 0x21,
86 ADV7842_OP_FORMAT_SEL_DDR_422_12_MODE0 = 0x22,
87 ADV7842_OP_FORMAT_SEL_DDR_422_12_MODE1 = 0x23,
88 ADV7842_OP_FORMAT_SEL_DDR_422_12_MODE2 = 0x24,
89 ADV7842_OP_FORMAT_SEL_SDR_444_24 = 0x40,
90 ADV7842_OP_FORMAT_SEL_SDR_444_30 = 0x41,
91 ADV7842_OP_FORMAT_SEL_SDR_444_36_MODE0 = 0x42,
92 ADV7842_OP_FORMAT_SEL_DDR_444_24 = 0x60,
93 ADV7842_OP_FORMAT_SEL_DDR_444_30 = 0x61,
94 ADV7842_OP_FORMAT_SEL_DDR_444_36 = 0x62,
95 ADV7842_OP_FORMAT_SEL_SDR_ITU656_16 = 0x80,
96 ADV7842_OP_FORMAT_SEL_SDR_ITU656_20 = 0x81,
97 ADV7842_OP_FORMAT_SEL_SDR_ITU656_24_MODE0 = 0x82,
98 ADV7842_OP_FORMAT_SEL_SDR_ITU656_24_MODE1 = 0x86,
99 ADV7842_OP_FORMAT_SEL_SDR_ITU656_24_MODE2 = 0x8a,
100};
101
102enum adv7842_select_input { 88enum adv7842_select_input {
103 ADV7842_SELECT_HDMI_PORT_A, 89 ADV7842_SELECT_HDMI_PORT_A,
104 ADV7842_SELECT_HDMI_PORT_B, 90 ADV7842_SELECT_HDMI_PORT_B,
@@ -117,35 +103,35 @@ enum adv7842_drive_strength {
117 103
118struct adv7842_sdp_csc_coeff { 104struct adv7842_sdp_csc_coeff {
119 bool manual; 105 bool manual;
120 uint16_t scaling; 106 u16 scaling;
121 uint16_t A1; 107 u16 A1;
122 uint16_t A2; 108 u16 A2;
123 uint16_t A3; 109 u16 A3;
124 uint16_t A4; 110 u16 A4;
125 uint16_t B1; 111 u16 B1;
126 uint16_t B2; 112 u16 B2;
127 uint16_t B3; 113 u16 B3;
128 uint16_t B4; 114 u16 B4;
129 uint16_t C1; 115 u16 C1;
130 uint16_t C2; 116 u16 C2;
131 uint16_t C3; 117 u16 C3;
132 uint16_t C4; 118 u16 C4;
133}; 119};
134 120
135struct adv7842_sdp_io_sync_adjustment { 121struct adv7842_sdp_io_sync_adjustment {
136 bool adjust; 122 bool adjust;
137 uint16_t hs_beg; 123 u16 hs_beg;
138 uint16_t hs_width; 124 u16 hs_width;
139 uint16_t de_beg; 125 u16 de_beg;
140 uint16_t de_end; 126 u16 de_end;
141 uint8_t vs_beg_o; 127 u8 vs_beg_o;
142 uint8_t vs_beg_e; 128 u8 vs_beg_e;
143 uint8_t vs_end_o; 129 u8 vs_end_o;
144 uint8_t vs_end_e; 130 u8 vs_end_e;
145 uint8_t de_v_beg_o; 131 u8 de_v_beg_o;
146 uint8_t de_v_beg_e; 132 u8 de_v_beg_e;
147 uint8_t de_v_end_o; 133 u8 de_v_end_o;
148 uint8_t de_v_end_e; 134 u8 de_v_end_e;
149}; 135};
150 136
151/* Platform dependent definition */ 137/* Platform dependent definition */
@@ -163,7 +149,10 @@ struct adv7842_platform_data {
163 enum adv7842_ain_sel ain_sel; 149 enum adv7842_ain_sel ain_sel;
164 150
165 /* Bus rotation and reordering */ 151 /* Bus rotation and reordering */
166 enum adv7842_op_ch_sel op_ch_sel; 152 enum adv7842_bus_order bus_order;
153
154 /* Select output format mode */
155 enum adv7842_op_format_mode_sel op_format_mode_sel;
167 156
168 /* Default mode */ 157 /* Default mode */
169 enum adv7842_mode mode; 158 enum adv7842_mode mode;
@@ -174,20 +163,15 @@ struct adv7842_platform_data {
174 /* Video standard */ 163 /* Video standard */
175 enum adv7842_vid_std_select vid_std_select; 164 enum adv7842_vid_std_select vid_std_select;
176 165
177 /* Select output format */
178 enum adv7842_op_format_sel op_format_sel;
179
180 /* IO register 0x02 */ 166 /* IO register 0x02 */
181 unsigned alt_gamma:1; 167 unsigned alt_gamma:1;
182 unsigned op_656_range:1; 168 unsigned op_656_range:1;
183 unsigned rgb_out:1;
184 unsigned alt_data_sat:1; 169 unsigned alt_data_sat:1;
185 170
186 /* IO register 0x05 */ 171 /* IO register 0x05 */
187 unsigned blank_data:1; 172 unsigned blank_data:1;
188 unsigned insert_av_codes:1; 173 unsigned insert_av_codes:1;
189 unsigned replicate_av_codes:1; 174 unsigned replicate_av_codes:1;
190 unsigned invert_cbcr:1;
191 175
192 /* IO register 0x30 */ 176 /* IO register 0x30 */
193 unsigned output_bus_lsb_to_msb:1; 177 unsigned output_bus_lsb_to_msb:1;
@@ -246,9 +230,6 @@ struct adv7842_platform_data {
246#define V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL (V4L2_CID_DV_CLASS_BASE + 0x1001) 230#define V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL (V4L2_CID_DV_CLASS_BASE + 0x1001)
247#define V4L2_CID_ADV_RX_FREE_RUN_COLOR (V4L2_CID_DV_CLASS_BASE + 0x1002) 231#define V4L2_CID_ADV_RX_FREE_RUN_COLOR (V4L2_CID_DV_CLASS_BASE + 0x1002)
248 232
249/* notify events */
250#define ADV7842_FMT_CHANGE 1
251
252/* custom ioctl, used to test the external RAM that's used by the 233/* custom ioctl, used to test the external RAM that's used by the
253 * deinterlacer. */ 234 * deinterlacer. */
254#define ADV7842_CMD_RAM_TEST _IO('V', BASE_VIDIOC_PRIVATE) 235#define ADV7842_CMD_RAM_TEST _IO('V', BASE_VIDIOC_PRIVATE)
@@ -256,5 +237,6 @@ struct adv7842_platform_data {
256#define ADV7842_EDID_PORT_A 0 237#define ADV7842_EDID_PORT_A 0
257#define ADV7842_EDID_PORT_B 1 238#define ADV7842_EDID_PORT_B 1
258#define ADV7842_EDID_PORT_VGA 2 239#define ADV7842_EDID_PORT_VGA 2
240#define ADV7842_PAD_SOURCE 3
259 241
260#endif 242#endif
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 2c7fbca40b69..45534da57759 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -74,6 +74,8 @@ enum rc_filter_type {
74 * @input_dev: the input child device used to communicate events to userspace 74 * @input_dev: the input child device used to communicate events to userspace
75 * @driver_type: specifies if protocol decoding is done in hardware or software 75 * @driver_type: specifies if protocol decoding is done in hardware or software
76 * @idle: used to keep track of RX state 76 * @idle: used to keep track of RX state
77 * @encode_wakeup: wakeup filtering uses IR encode API, therefore the allowed
78 * wakeup protocols is the set of all raw encoders
77 * @allowed_protocols: bitmask with the supported RC_BIT_* protocols 79 * @allowed_protocols: bitmask with the supported RC_BIT_* protocols
78 * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols 80 * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols
79 * @allowed_wakeup_protocols: bitmask with the supported RC_BIT_* wakeup protocols 81 * @allowed_wakeup_protocols: bitmask with the supported RC_BIT_* wakeup protocols
@@ -134,6 +136,7 @@ struct rc_dev {
134 struct input_dev *input_dev; 136 struct input_dev *input_dev;
135 enum rc_driver_type driver_type; 137 enum rc_driver_type driver_type;
136 bool idle; 138 bool idle;
139 bool encode_wakeup;
137 u64 allowed_protocols; 140 u64 allowed_protocols;
138 u64 enabled_protocols; 141 u64 enabled_protocols;
139 u64 allowed_wakeup_protocols; 142 u64 allowed_wakeup_protocols;
@@ -239,10 +242,11 @@ static inline void init_ir_raw_event(struct ir_raw_event *ev)
239 memset(ev, 0, sizeof(*ev)); 242 memset(ev, 0, sizeof(*ev));
240} 243}
241 244
242#define IR_MAX_DURATION 0xFFFFFFFF /* a bit more than 4 seconds */ 245#define IR_MAX_DURATION 500000000 /* 500 ms */
243#define US_TO_NS(usec) ((usec) * 1000) 246#define US_TO_NS(usec) ((usec) * 1000)
244#define MS_TO_US(msec) ((msec) * 1000) 247#define MS_TO_US(msec) ((msec) * 1000)
245#define MS_TO_NS(msec) ((msec) * 1000 * 1000) 248#define MS_TO_NS(msec) ((msec) * 1000 * 1000)
249#define NS_TO_US(nsec) DIV_ROUND_UP(nsec, 1000L)
246 250
247void ir_raw_event_handle(struct rc_dev *dev); 251void ir_raw_event_handle(struct rc_dev *dev);
248int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev); 252int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);
@@ -250,6 +254,9 @@ int ir_raw_event_store_edge(struct rc_dev *dev, enum raw_event_type type);
250int ir_raw_event_store_with_filter(struct rc_dev *dev, 254int ir_raw_event_store_with_filter(struct rc_dev *dev,
251 struct ir_raw_event *ev); 255 struct ir_raw_event *ev);
252void ir_raw_event_set_idle(struct rc_dev *dev, bool idle); 256void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
257int ir_raw_encode_scancode(u64 protocols,
258 const struct rc_scancode_filter *scancode,
259 struct ir_raw_event *events, unsigned int max);
253 260
254static inline void ir_raw_event_reset(struct rc_dev *dev) 261static inline void ir_raw_event_reset(struct rc_dev *dev)
255{ 262{
diff --git a/include/media/rc-map.h b/include/media/rc-map.h
index e7a1514075ec..27763d5bd261 100644
--- a/include/media/rc-map.h
+++ b/include/media/rc-map.h
@@ -194,7 +194,10 @@ void rc_map_init(void);
194#define RC_MAP_SNAPSTREAM_FIREFLY "rc-snapstream-firefly" 194#define RC_MAP_SNAPSTREAM_FIREFLY "rc-snapstream-firefly"
195#define RC_MAP_STREAMZAP "rc-streamzap" 195#define RC_MAP_STREAMZAP "rc-streamzap"
196#define RC_MAP_TBS_NEC "rc-tbs-nec" 196#define RC_MAP_TBS_NEC "rc-tbs-nec"
197#define RC_MAP_TECHNISAT_TS35 "rc-technisat-ts35"
197#define RC_MAP_TECHNISAT_USB2 "rc-technisat-usb2" 198#define RC_MAP_TECHNISAT_USB2 "rc-technisat-usb2"
199#define RC_MAP_TERRATEC_CINERGY_C_PCI "rc-terratec-cinergy-c-pci"
200#define RC_MAP_TERRATEC_CINERGY_S2_HD "rc-terratec-cinergy-s2-hd"
198#define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs" 201#define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs"
199#define RC_MAP_TERRATEC_SLIM "rc-terratec-slim" 202#define RC_MAP_TERRATEC_SLIM "rc-terratec-slim"
200#define RC_MAP_TERRATEC_SLIM_2 "rc-terratec-slim-2" 203#define RC_MAP_TERRATEC_SLIM_2 "rc-terratec-slim-2"
@@ -204,6 +207,7 @@ void rc_map_init(void);
204#define RC_MAP_TOTAL_MEDIA_IN_HAND_02 "rc-total-media-in-hand-02" 207#define RC_MAP_TOTAL_MEDIA_IN_HAND_02 "rc-total-media-in-hand-02"
205#define RC_MAP_TREKSTOR "rc-trekstor" 208#define RC_MAP_TREKSTOR "rc-trekstor"
206#define RC_MAP_TT_1500 "rc-tt-1500" 209#define RC_MAP_TT_1500 "rc-tt-1500"
210#define RC_MAP_TWINHAN_DTV_CAB_CI "rc-twinhan-dtv-cab-ci"
207#define RC_MAP_TWINHAN_VP1027_DVBS "rc-twinhan1027" 211#define RC_MAP_TWINHAN_VP1027_DVBS "rc-twinhan1027"
208#define RC_MAP_VIDEOMATE_K100 "rc-videomate-k100" 212#define RC_MAP_VIDEOMATE_K100 "rc-videomate-k100"
209#define RC_MAP_VIDEOMATE_S350 "rc-videomate-s350" 213#define RC_MAP_VIDEOMATE_S350 "rc-videomate-s350"
diff --git a/include/media/v4l2-dv-timings.h b/include/media/v4l2-dv-timings.h
index 4becc6716393..eecd3102a618 100644
--- a/include/media/v4l2-dv-timings.h
+++ b/include/media/v4l2-dv-timings.h
@@ -117,6 +117,7 @@ void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
117 * @vsync - the height of the vertical sync in lines. 117 * @vsync - the height of the vertical sync in lines.
118 * @polarities - the horizontal and vertical polarities (same as struct 118 * @polarities - the horizontal and vertical polarities (same as struct
119 * v4l2_bt_timings polarities). 119 * v4l2_bt_timings polarities).
120 * @interlaced - if this flag is true, it indicates interlaced format
120 * @fmt - the resulting timings. 121 * @fmt - the resulting timings.
121 * 122 *
122 * This function will attempt to detect if the given values correspond to a 123 * This function will attempt to detect if the given values correspond to a
@@ -124,7 +125,7 @@ void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix,
124 * in with the found CVT timings. 125 * in with the found CVT timings.
125 */ 126 */
126bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 127bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
127 u32 polarities, struct v4l2_dv_timings *fmt); 128 u32 polarities, bool interlaced, struct v4l2_dv_timings *fmt);
128 129
129/** v4l2_detect_gtf - detect if the given timings follow the GTF standard 130/** v4l2_detect_gtf - detect if the given timings follow the GTF standard
130 * @frame_height - the total height of the frame (including blanking) in lines. 131 * @frame_height - the total height of the frame (including blanking) in lines.
@@ -132,6 +133,7 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
132 * @vsync - the height of the vertical sync in lines. 133 * @vsync - the height of the vertical sync in lines.
133 * @polarities - the horizontal and vertical polarities (same as struct 134 * @polarities - the horizontal and vertical polarities (same as struct
134 * v4l2_bt_timings polarities). 135 * v4l2_bt_timings polarities).
136 * @interlaced - if this flag is true, it indicates interlaced format
135 * @aspect - preferred aspect ratio. GTF has no method of determining the 137 * @aspect - preferred aspect ratio. GTF has no method of determining the
136 * aspect ratio in order to derive the image width from the 138 * aspect ratio in order to derive the image width from the
137 * image height, so it has to be passed explicitly. Usually 139 * image height, so it has to be passed explicitly. Usually
@@ -144,7 +146,7 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
144 * in with the found GTF timings. 146 * in with the found GTF timings.
145 */ 147 */
146bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync, 148bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
147 u32 polarities, struct v4l2_fract aspect, 149 u32 polarities, bool interlaced, struct v4l2_fract aspect,
148 struct v4l2_dv_timings *fmt); 150 struct v4l2_dv_timings *fmt);
149 151
150/** v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes 152/** v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes
diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h
index 38d960d8dccd..73069e4c2796 100644
--- a/include/media/v4l2-mediabus.h
+++ b/include/media/v4l2-mediabus.h
@@ -96,6 +96,7 @@ static inline void v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
96 pix_fmt->colorspace = mbus_fmt->colorspace; 96 pix_fmt->colorspace = mbus_fmt->colorspace;
97 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; 97 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
98 pix_fmt->quantization = mbus_fmt->quantization; 98 pix_fmt->quantization = mbus_fmt->quantization;
99 pix_fmt->xfer_func = mbus_fmt->xfer_func;
99} 100}
100 101
101static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt, 102static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
@@ -108,6 +109,7 @@ static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
108 mbus_fmt->colorspace = pix_fmt->colorspace; 109 mbus_fmt->colorspace = pix_fmt->colorspace;
109 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc; 110 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
110 mbus_fmt->quantization = pix_fmt->quantization; 111 mbus_fmt->quantization = pix_fmt->quantization;
112 mbus_fmt->xfer_func = pix_fmt->xfer_func;
111 mbus_fmt->code = code; 113 mbus_fmt->code = code;
112} 114}
113 115
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index c5f3914bc4d8..3bbd96da25c9 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -116,6 +116,8 @@ int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
116 struct v4l2_buffer *buf); 116 struct v4l2_buffer *buf);
117int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, 117int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
118 struct v4l2_buffer *buf); 118 struct v4l2_buffer *buf);
119int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
120 struct v4l2_buffer *buf);
119int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, 121int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
120 struct v4l2_create_buffers *create); 122 struct v4l2_create_buffers *create);
121 123
@@ -248,6 +250,8 @@ int v4l2_m2m_ioctl_qbuf(struct file *file, void *fh,
248 struct v4l2_buffer *buf); 250 struct v4l2_buffer *buf);
249int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh, 251int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh,
250 struct v4l2_buffer *buf); 252 struct v4l2_buffer *buf);
253int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *fh,
254 struct v4l2_buffer *buf);
251int v4l2_m2m_ioctl_streamon(struct file *file, void *fh, 255int v4l2_m2m_ioctl_streamon(struct file *file, void *fh,
252 enum v4l2_buf_type type); 256 enum v4l2_buf_type type);
253int v4l2_m2m_ioctl_streamoff(struct file *file, void *fh, 257int v4l2_m2m_ioctl_streamoff(struct file *file, void *fh,
diff --git a/include/media/v4l2-of.h b/include/media/v4l2-of.h
index f831c9c225b6..4dc34b245d47 100644
--- a/include/media/v4l2-of.h
+++ b/include/media/v4l2-of.h
@@ -57,16 +57,19 @@ struct v4l2_of_bus_parallel {
57 * @base: struct of_endpoint containing port, id, and local of_node 57 * @base: struct of_endpoint containing port, id, and local of_node
58 * @bus_type: bus type 58 * @bus_type: bus type
59 * @bus: bus configuration data structure 59 * @bus: bus configuration data structure
60 * @head: list head for this structure 60 * @link_frequencies: array of supported link frequencies
61 * @nr_of_link_frequencies: number of elements in link_frequenccies array
61 */ 62 */
62struct v4l2_of_endpoint { 63struct v4l2_of_endpoint {
63 struct of_endpoint base; 64 struct of_endpoint base;
65 /* Fields below this line will be zeroed by v4l2_of_parse_endpoint() */
64 enum v4l2_mbus_type bus_type; 66 enum v4l2_mbus_type bus_type;
65 union { 67 union {
66 struct v4l2_of_bus_parallel parallel; 68 struct v4l2_of_bus_parallel parallel;
67 struct v4l2_of_bus_mipi_csi2 mipi_csi2; 69 struct v4l2_of_bus_mipi_csi2 mipi_csi2;
68 } bus; 70 } bus;
69 struct list_head head; 71 u64 *link_frequencies;
72 unsigned int nr_of_link_frequencies;
70}; 73};
71 74
72/** 75/**
@@ -86,6 +89,9 @@ struct v4l2_of_link {
86#ifdef CONFIG_OF 89#ifdef CONFIG_OF
87int v4l2_of_parse_endpoint(const struct device_node *node, 90int v4l2_of_parse_endpoint(const struct device_node *node,
88 struct v4l2_of_endpoint *endpoint); 91 struct v4l2_of_endpoint *endpoint);
92struct v4l2_of_endpoint *v4l2_of_alloc_parse_endpoint(
93 const struct device_node *node);
94void v4l2_of_free_endpoint(struct v4l2_of_endpoint *endpoint);
89int v4l2_of_parse_link(const struct device_node *node, 95int v4l2_of_parse_link(const struct device_node *node,
90 struct v4l2_of_link *link); 96 struct v4l2_of_link *link);
91void v4l2_of_put_link(struct v4l2_of_link *link); 97void v4l2_of_put_link(struct v4l2_of_link *link);
@@ -97,6 +103,16 @@ static inline int v4l2_of_parse_endpoint(const struct device_node *node,
97 return -ENOSYS; 103 return -ENOSYS;
98} 104}
99 105
106static inline struct v4l2_of_endpoint *v4l2_of_alloc_parse_endpoint(
107 const struct device_node *node)
108{
109 return NULL;
110}
111
112static inline void v4l2_of_free_endpoint(struct v4l2_of_endpoint *endpoint)
113{
114}
115
100static inline int v4l2_of_parse_link(const struct device_node *node, 116static inline int v4l2_of_parse_link(const struct device_node *node,
101 struct v4l2_of_link *link) 117 struct v4l2_of_link *link)
102{ 118{
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 2f0a345a7fed..dc20102ff600 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -40,6 +40,8 @@
40#define V4L2_SUBDEV_IR_TX_NOTIFY _IOW('v', 1, u32) 40#define V4L2_SUBDEV_IR_TX_NOTIFY _IOW('v', 1, u32)
41#define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001 41#define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001
42 42
43#define V4L2_DEVICE_NOTIFY_EVENT _IOW('v', 2, struct v4l2_event)
44
43struct v4l2_device; 45struct v4l2_device;
44struct v4l2_ctrl_handler; 46struct v4l2_ctrl_handler;
45struct v4l2_event_subscription; 47struct v4l2_event_subscription;
@@ -293,14 +295,6 @@ struct v4l2_mbus_frame_desc {
293 295
294 g_dv_timings(): Get custom dv timings in the sub device. 296 g_dv_timings(): Get custom dv timings in the sub device.
295 297
296 enum_mbus_fmt: enumerate pixel formats, provided by a video data source
297
298 g_mbus_fmt: get the current pixel format, provided by a video data source
299
300 try_mbus_fmt: try to set a pixel format on a video data source
301
302 s_mbus_fmt: set a pixel format on a video data source
303
304 g_mbus_config: get supported mediabus configurations 298 g_mbus_config: get supported mediabus configurations
305 299
306 s_mbus_config: set a certain mediabus configuration. This operation is added 300 s_mbus_config: set a certain mediabus configuration. This operation is added
@@ -338,14 +332,6 @@ struct v4l2_subdev_video_ops {
338 struct v4l2_dv_timings *timings); 332 struct v4l2_dv_timings *timings);
339 int (*query_dv_timings)(struct v4l2_subdev *sd, 333 int (*query_dv_timings)(struct v4l2_subdev *sd,
340 struct v4l2_dv_timings *timings); 334 struct v4l2_dv_timings *timings);
341 int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index,
342 u32 *code);
343 int (*g_mbus_fmt)(struct v4l2_subdev *sd,
344 struct v4l2_mbus_framefmt *fmt);
345 int (*try_mbus_fmt)(struct v4l2_subdev *sd,
346 struct v4l2_mbus_framefmt *fmt);
347 int (*s_mbus_fmt)(struct v4l2_subdev *sd,
348 struct v4l2_mbus_framefmt *fmt);
349 int (*g_mbus_config)(struct v4l2_subdev *sd, 335 int (*g_mbus_config)(struct v4l2_subdev *sd,
350 struct v4l2_mbus_config *cfg); 336 struct v4l2_mbus_config *cfg);
351 int (*s_mbus_config)(struct v4l2_subdev *sd, 337 int (*s_mbus_config)(struct v4l2_subdev *sd,
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index a5790fd5d125..22a44c2f5963 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -381,6 +381,9 @@ struct v4l2_fh;
381 * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for 381 * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
382 * buffers. Only set for capture queues if qbuf has not yet been 382 * buffers. Only set for capture queues if qbuf has not yet been
383 * called since poll() needs to return POLLERR in that situation. 383 * called since poll() needs to return POLLERR in that situation.
384 * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
385 * last decoded buffer was already dequeued. Set for capture queues
386 * when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
384 * @fileio: file io emulator internal data, used only if emulator is active 387 * @fileio: file io emulator internal data, used only if emulator is active
385 * @threadio: thread io internal data, used only if thread is active 388 * @threadio: thread io internal data, used only if thread is active
386 */ 389 */
@@ -423,6 +426,7 @@ struct vb2_queue {
423 unsigned int start_streaming_called:1; 426 unsigned int start_streaming_called:1;
424 unsigned int error:1; 427 unsigned int error:1;
425 unsigned int waiting_for_buffers:1; 428 unsigned int waiting_for_buffers:1;
429 unsigned int last_buffer_dequeued:1;
426 430
427 struct vb2_fileio_data *fileio; 431 struct vb2_fileio_data *fileio;
428 struct vb2_threadio_data *threadio; 432 struct vb2_threadio_data *threadio;
@@ -603,6 +607,15 @@ static inline bool vb2_start_streaming_called(struct vb2_queue *q)
603 return q->start_streaming_called; 607 return q->start_streaming_called;
604} 608}
605 609
610/**
611 * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
612 * @q: videobuf queue
613 */
614static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
615{
616 q->last_buffer_dequeued = false;
617}
618
606/* 619/*
607 * The following functions are not part of the vb2 core API, but are simple 620 * The following functions are not part of the vb2 core API, but are simple
608 * helper functions that you can use in your struct v4l2_file_operations, 621 * helper functions that you can use in your struct v4l2_file_operations,
diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h
index 20112170ff11..89d0497c058a 100644
--- a/include/trace/events/v4l2.h
+++ b/include/trace/events/v4l2.h
@@ -83,7 +83,8 @@ SHOW_FIELD
83 { V4L2_BUF_FLAG_TIMESTAMP_MASK, "TIMESTAMP_MASK" }, \ 83 { V4L2_BUF_FLAG_TIMESTAMP_MASK, "TIMESTAMP_MASK" }, \
84 { V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN, "TIMESTAMP_UNKNOWN" }, \ 84 { V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN, "TIMESTAMP_UNKNOWN" }, \
85 { V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC, "TIMESTAMP_MONOTONIC" }, \ 85 { V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC, "TIMESTAMP_MONOTONIC" }, \
86 { V4L2_BUF_FLAG_TIMESTAMP_COPY, "TIMESTAMP_COPY" }) 86 { V4L2_BUF_FLAG_TIMESTAMP_COPY, "TIMESTAMP_COPY" }, \
87 { V4L2_BUF_FLAG_LAST, "LAST" })
87 88
88#define show_timecode_flags(flags) \ 89#define show_timecode_flags(flags) \
89 __print_flags(flags, "|", \ 90 __print_flags(flags, "|", \
diff --git a/include/uapi/linux/dvb/dmx.h b/include/uapi/linux/dvb/dmx.h
index b4fb650d9d4f..427e4899ed69 100644
--- a/include/uapi/linux/dvb/dmx.h
+++ b/include/uapi/linux/dvb/dmx.h
@@ -32,7 +32,7 @@
32 32
33#define DMX_FILTER_SIZE 16 33#define DMX_FILTER_SIZE 16
34 34
35typedef enum 35enum dmx_output
36{ 36{
37 DMX_OUT_DECODER, /* Streaming directly to decoder. */ 37 DMX_OUT_DECODER, /* Streaming directly to decoder. */
38 DMX_OUT_TAP, /* Output going to a memory buffer */ 38 DMX_OUT_TAP, /* Output going to a memory buffer */
@@ -41,10 +41,11 @@ typedef enum
41 /* (to be retrieved by reading from the */ 41 /* (to be retrieved by reading from the */
42 /* logical DVR device). */ 42 /* logical DVR device). */
43 DMX_OUT_TSDEMUX_TAP /* Like TS_TAP but retrieved from the DMX device */ 43 DMX_OUT_TSDEMUX_TAP /* Like TS_TAP but retrieved from the DMX device */
44} dmx_output_t; 44};
45 45
46typedef enum dmx_output dmx_output_t;
46 47
47typedef enum 48typedef enum dmx_input
48{ 49{
49 DMX_IN_FRONTEND, /* Input from a front-end device. */ 50 DMX_IN_FRONTEND, /* Input from a front-end device. */
50 DMX_IN_DVR /* Input from the logical DVR device. */ 51 DMX_IN_DVR /* Input from the logical DVR device. */
@@ -122,7 +123,7 @@ typedef struct dmx_caps {
122 int num_decoders; 123 int num_decoders;
123} dmx_caps_t; 124} dmx_caps_t;
124 125
125typedef enum { 126typedef enum dmx_source {
126 DMX_SOURCE_FRONT0 = 0, 127 DMX_SOURCE_FRONT0 = 0,
127 DMX_SOURCE_FRONT1, 128 DMX_SOURCE_FRONT1,
128 DMX_SOURCE_FRONT2, 129 DMX_SOURCE_FRONT2,
@@ -139,7 +140,6 @@ struct dmx_stc {
139 __u64 stc; /* output: stc in 'base'*90 kHz units */ 140 __u64 stc; /* output: stc in 'base'*90 kHz units */
140}; 141};
141 142
142
143#define DMX_START _IO('o', 41) 143#define DMX_START _IO('o', 41)
144#define DMX_STOP _IO('o', 42) 144#define DMX_STOP _IO('o', 42)
145#define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params) 145#define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params)
diff --git a/include/uapi/linux/dvb/frontend.h b/include/uapi/linux/dvb/frontend.h
index c56d77c496a5..00a20cd21ee2 100644
--- a/include/uapi/linux/dvb/frontend.h
+++ b/include/uapi/linux/dvb/frontend.h
@@ -28,15 +28,14 @@
28 28
29#include <linux/types.h> 29#include <linux/types.h>
30 30
31typedef enum fe_type { 31enum fe_type {
32 FE_QPSK, 32 FE_QPSK,
33 FE_QAM, 33 FE_QAM,
34 FE_OFDM, 34 FE_OFDM,
35 FE_ATSC 35 FE_ATSC
36} fe_type_t; 36};
37
38 37
39typedef enum fe_caps { 38enum fe_caps {
40 FE_IS_STUPID = 0, 39 FE_IS_STUPID = 0,
41 FE_CAN_INVERSION_AUTO = 0x1, 40 FE_CAN_INVERSION_AUTO = 0x1,
42 FE_CAN_FEC_1_2 = 0x2, 41 FE_CAN_FEC_1_2 = 0x2,
@@ -68,12 +67,11 @@ typedef enum fe_caps {
68 FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend requires frequency bending) */ 67 FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend requires frequency bending) */
69 FE_CAN_RECOVER = 0x40000000, /* frontend can recover from a cable unplug automatically */ 68 FE_CAN_RECOVER = 0x40000000, /* frontend can recover from a cable unplug automatically */
70 FE_CAN_MUTE_TS = 0x80000000 /* frontend can stop spurious TS data output */ 69 FE_CAN_MUTE_TS = 0x80000000 /* frontend can stop spurious TS data output */
71} fe_caps_t; 70};
72
73 71
74struct dvb_frontend_info { 72struct dvb_frontend_info {
75 char name[128]; 73 char name[128];
76 fe_type_t type; /* DEPRECATED. Use DTV_ENUM_DELSYS instead */ 74 enum fe_type type; /* DEPRECATED. Use DTV_ENUM_DELSYS instead */
77 __u32 frequency_min; 75 __u32 frequency_min;
78 __u32 frequency_max; 76 __u32 frequency_max;
79 __u32 frequency_stepsize; 77 __u32 frequency_stepsize;
@@ -82,7 +80,7 @@ struct dvb_frontend_info {
82 __u32 symbol_rate_max; 80 __u32 symbol_rate_max;
83 __u32 symbol_rate_tolerance; /* ppm */ 81 __u32 symbol_rate_tolerance; /* ppm */
84 __u32 notifier_delay; /* DEPRECATED */ 82 __u32 notifier_delay; /* DEPRECATED */
85 fe_caps_t caps; 83 enum fe_caps caps;
86}; 84};
87 85
88 86
@@ -95,32 +93,27 @@ struct dvb_diseqc_master_cmd {
95 __u8 msg_len; /* valid values are 3...6 */ 93 __u8 msg_len; /* valid values are 3...6 */
96}; 94};
97 95
98
99struct dvb_diseqc_slave_reply { 96struct dvb_diseqc_slave_reply {
100 __u8 msg [4]; /* { framing, data [3] } */ 97 __u8 msg [4]; /* { framing, data [3] } */
101 __u8 msg_len; /* valid values are 0...4, 0 means no msg */ 98 __u8 msg_len; /* valid values are 0...4, 0 means no msg */
102 int timeout; /* return from ioctl after timeout ms with */ 99 int timeout; /* return from ioctl after timeout ms with */
103}; /* errorcode when no message was received */ 100}; /* errorcode when no message was received */
104 101
105 102enum fe_sec_voltage {
106typedef enum fe_sec_voltage {
107 SEC_VOLTAGE_13, 103 SEC_VOLTAGE_13,
108 SEC_VOLTAGE_18, 104 SEC_VOLTAGE_18,
109 SEC_VOLTAGE_OFF 105 SEC_VOLTAGE_OFF
110} fe_sec_voltage_t; 106};
111
112 107
113typedef enum fe_sec_tone_mode { 108enum fe_sec_tone_mode {
114 SEC_TONE_ON, 109 SEC_TONE_ON,
115 SEC_TONE_OFF 110 SEC_TONE_OFF
116} fe_sec_tone_mode_t; 111};
117
118 112
119typedef enum fe_sec_mini_cmd { 113enum fe_sec_mini_cmd {
120 SEC_MINI_A, 114 SEC_MINI_A,
121 SEC_MINI_B 115 SEC_MINI_B
122} fe_sec_mini_cmd_t; 116};
123
124 117
125/** 118/**
126 * enum fe_status - enumerates the possible frontend status 119 * enum fe_status - enumerates the possible frontend status
@@ -133,8 +126,7 @@ typedef enum fe_sec_mini_cmd {
133 * @FE_REINIT: frontend was reinitialized, application is recommended 126 * @FE_REINIT: frontend was reinitialized, application is recommended
134 * to reset DiSEqC, tone and parameters 127 * to reset DiSEqC, tone and parameters
135 */ 128 */
136 129enum fe_status {
137typedef enum fe_status {
138 FE_HAS_SIGNAL = 0x01, 130 FE_HAS_SIGNAL = 0x01,
139 FE_HAS_CARRIER = 0x02, 131 FE_HAS_CARRIER = 0x02,
140 FE_HAS_VITERBI = 0x04, 132 FE_HAS_VITERBI = 0x04,
@@ -142,16 +134,15 @@ typedef enum fe_status {
142 FE_HAS_LOCK = 0x10, 134 FE_HAS_LOCK = 0x10,
143 FE_TIMEDOUT = 0x20, 135 FE_TIMEDOUT = 0x20,
144 FE_REINIT = 0x40, 136 FE_REINIT = 0x40,
145} fe_status_t; 137};
146 138
147typedef enum fe_spectral_inversion { 139enum fe_spectral_inversion {
148 INVERSION_OFF, 140 INVERSION_OFF,
149 INVERSION_ON, 141 INVERSION_ON,
150 INVERSION_AUTO 142 INVERSION_AUTO
151} fe_spectral_inversion_t; 143};
152
153 144
154typedef enum fe_code_rate { 145enum fe_code_rate {
155 FEC_NONE = 0, 146 FEC_NONE = 0,
156 FEC_1_2, 147 FEC_1_2,
157 FEC_2_3, 148 FEC_2_3,
@@ -165,10 +156,9 @@ typedef enum fe_code_rate {
165 FEC_3_5, 156 FEC_3_5,
166 FEC_9_10, 157 FEC_9_10,
167 FEC_2_5, 158 FEC_2_5,
168} fe_code_rate_t; 159};
169
170 160
171typedef enum fe_modulation { 161enum fe_modulation {
172 QPSK, 162 QPSK,
173 QAM_16, 163 QAM_16,
174 QAM_32, 164 QAM_32,
@@ -183,9 +173,9 @@ typedef enum fe_modulation {
183 APSK_32, 173 APSK_32,
184 DQPSK, 174 DQPSK,
185 QAM_4_NR, 175 QAM_4_NR,
186} fe_modulation_t; 176};
187 177
188typedef enum fe_transmit_mode { 178enum fe_transmit_mode {
189 TRANSMISSION_MODE_2K, 179 TRANSMISSION_MODE_2K,
190 TRANSMISSION_MODE_8K, 180 TRANSMISSION_MODE_8K,
191 TRANSMISSION_MODE_AUTO, 181 TRANSMISSION_MODE_AUTO,
@@ -195,21 +185,9 @@ typedef enum fe_transmit_mode {
195 TRANSMISSION_MODE_32K, 185 TRANSMISSION_MODE_32K,
196 TRANSMISSION_MODE_C1, 186 TRANSMISSION_MODE_C1,
197 TRANSMISSION_MODE_C3780, 187 TRANSMISSION_MODE_C3780,
198} fe_transmit_mode_t; 188};
199
200#if defined(__DVB_CORE__) || !defined (__KERNEL__)
201typedef enum fe_bandwidth {
202 BANDWIDTH_8_MHZ,
203 BANDWIDTH_7_MHZ,
204 BANDWIDTH_6_MHZ,
205 BANDWIDTH_AUTO,
206 BANDWIDTH_5_MHZ,
207 BANDWIDTH_10_MHZ,
208 BANDWIDTH_1_712_MHZ,
209} fe_bandwidth_t;
210#endif
211 189
212typedef enum fe_guard_interval { 190enum fe_guard_interval {
213 GUARD_INTERVAL_1_32, 191 GUARD_INTERVAL_1_32,
214 GUARD_INTERVAL_1_16, 192 GUARD_INTERVAL_1_16,
215 GUARD_INTERVAL_1_8, 193 GUARD_INTERVAL_1_8,
@@ -221,16 +199,15 @@ typedef enum fe_guard_interval {
221 GUARD_INTERVAL_PN420, 199 GUARD_INTERVAL_PN420,
222 GUARD_INTERVAL_PN595, 200 GUARD_INTERVAL_PN595,
223 GUARD_INTERVAL_PN945, 201 GUARD_INTERVAL_PN945,
224} fe_guard_interval_t; 202};
225
226 203
227typedef enum fe_hierarchy { 204enum fe_hierarchy {
228 HIERARCHY_NONE, 205 HIERARCHY_NONE,
229 HIERARCHY_1, 206 HIERARCHY_1,
230 HIERARCHY_2, 207 HIERARCHY_2,
231 HIERARCHY_4, 208 HIERARCHY_4,
232 HIERARCHY_AUTO 209 HIERARCHY_AUTO
233} fe_hierarchy_t; 210};
234 211
235enum fe_interleaving { 212enum fe_interleaving {
236 INTERLEAVING_NONE, 213 INTERLEAVING_NONE,
@@ -239,51 +216,6 @@ enum fe_interleaving {
239 INTERLEAVING_720, 216 INTERLEAVING_720,
240}; 217};
241 218
242#if defined(__DVB_CORE__) || !defined (__KERNEL__)
243struct dvb_qpsk_parameters {
244 __u32 symbol_rate; /* symbol rate in Symbols per second */
245 fe_code_rate_t fec_inner; /* forward error correction (see above) */
246};
247
248struct dvb_qam_parameters {
249 __u32 symbol_rate; /* symbol rate in Symbols per second */
250 fe_code_rate_t fec_inner; /* forward error correction (see above) */
251 fe_modulation_t modulation; /* modulation type (see above) */
252};
253
254struct dvb_vsb_parameters {
255 fe_modulation_t modulation; /* modulation type (see above) */
256};
257
258struct dvb_ofdm_parameters {
259 fe_bandwidth_t bandwidth;
260 fe_code_rate_t code_rate_HP; /* high priority stream code rate */
261 fe_code_rate_t code_rate_LP; /* low priority stream code rate */
262 fe_modulation_t constellation; /* modulation type (see above) */
263 fe_transmit_mode_t transmission_mode;
264 fe_guard_interval_t guard_interval;
265 fe_hierarchy_t hierarchy_information;
266};
267
268
269struct dvb_frontend_parameters {
270 __u32 frequency; /* (absolute) frequency in Hz for QAM/OFDM/ATSC */
271 /* intermediate frequency in kHz for QPSK */
272 fe_spectral_inversion_t inversion;
273 union {
274 struct dvb_qpsk_parameters qpsk;
275 struct dvb_qam_parameters qam;
276 struct dvb_ofdm_parameters ofdm;
277 struct dvb_vsb_parameters vsb;
278 } u;
279};
280
281struct dvb_frontend_event {
282 fe_status_t status;
283 struct dvb_frontend_parameters parameters;
284};
285#endif
286
287/* S2API Commands */ 219/* S2API Commands */
288#define DTV_UNDEFINED 0 220#define DTV_UNDEFINED 0
289#define DTV_TUNE 1 221#define DTV_TUNE 1
@@ -377,20 +309,20 @@ struct dvb_frontend_event {
377 309
378#define DTV_MAX_COMMAND DTV_STAT_TOTAL_BLOCK_COUNT 310#define DTV_MAX_COMMAND DTV_STAT_TOTAL_BLOCK_COUNT
379 311
380typedef enum fe_pilot { 312enum fe_pilot {
381 PILOT_ON, 313 PILOT_ON,
382 PILOT_OFF, 314 PILOT_OFF,
383 PILOT_AUTO, 315 PILOT_AUTO,
384} fe_pilot_t; 316};
385 317
386typedef enum fe_rolloff { 318enum fe_rolloff {
387 ROLLOFF_35, /* Implied value in DVB-S, default for DVB-S2 */ 319 ROLLOFF_35, /* Implied value in DVB-S, default for DVB-S2 */
388 ROLLOFF_20, 320 ROLLOFF_20,
389 ROLLOFF_25, 321 ROLLOFF_25,
390 ROLLOFF_AUTO, 322 ROLLOFF_AUTO,
391} fe_rolloff_t; 323};
392 324
393typedef enum fe_delivery_system { 325enum fe_delivery_system {
394 SYS_UNDEFINED, 326 SYS_UNDEFINED,
395 SYS_DVBC_ANNEX_A, 327 SYS_DVBC_ANNEX_A,
396 SYS_DVBC_ANNEX_B, 328 SYS_DVBC_ANNEX_B,
@@ -410,7 +342,7 @@ typedef enum fe_delivery_system {
410 SYS_DVBT2, 342 SYS_DVBT2,
411 SYS_TURBO, 343 SYS_TURBO,
412 SYS_DVBC_ANNEX_C, 344 SYS_DVBC_ANNEX_C,
413} fe_delivery_system_t; 345};
414 346
415/* backward compatibility */ 347/* backward compatibility */
416#define SYS_DVBC_ANNEX_AC SYS_DVBC_ANNEX_A 348#define SYS_DVBC_ANNEX_AC SYS_DVBC_ANNEX_A
@@ -467,7 +399,7 @@ struct dtv_cmds_h {
467 * @FE_SCALE_NOT_AVAILABLE: That QoS measure is not available. That 399 * @FE_SCALE_NOT_AVAILABLE: That QoS measure is not available. That
468 * could indicate a temporary or a permanent 400 * could indicate a temporary or a permanent
469 * condition. 401 * condition.
470 * @FE_SCALE_DECIBEL: The scale is measured in 0.0001 dB steps, typically 402 * @FE_SCALE_DECIBEL: The scale is measured in 0.001 dB steps, typically
471 * used on signal measures. 403 * used on signal measures.
472 * @FE_SCALE_RELATIVE: The scale is a relative percentual measure, 404 * @FE_SCALE_RELATIVE: The scale is a relative percentual measure,
473 * ranging from 0 (0%) to 0xffff (100%). 405 * ranging from 0 (0%) to 0xffff (100%).
@@ -503,20 +435,20 @@ enum fecap_scale_params {
503 * 435 *
504 * In other words, for ISDB, those values should be filled like: 436 * In other words, for ISDB, those values should be filled like:
505 * u.st.stat.svalue[0] = global statistics; 437 * u.st.stat.svalue[0] = global statistics;
506 * u.st.stat.scale[0] = FE_SCALE_DECIBELS; 438 * u.st.stat.scale[0] = FE_SCALE_DECIBEL;
507 * u.st.stat.value[1] = layer A statistics; 439 * u.st.stat.value[1] = layer A statistics;
508 * u.st.stat.scale[1] = FE_SCALE_NOT_AVAILABLE (if not available); 440 * u.st.stat.scale[1] = FE_SCALE_NOT_AVAILABLE (if not available);
509 * u.st.stat.svalue[2] = layer B statistics; 441 * u.st.stat.svalue[2] = layer B statistics;
510 * u.st.stat.scale[2] = FE_SCALE_DECIBELS; 442 * u.st.stat.scale[2] = FE_SCALE_DECIBEL;
511 * u.st.stat.svalue[3] = layer C statistics; 443 * u.st.stat.svalue[3] = layer C statistics;
512 * u.st.stat.scale[3] = FE_SCALE_DECIBELS; 444 * u.st.stat.scale[3] = FE_SCALE_DECIBEL;
513 * u.st.len = 4; 445 * u.st.len = 4;
514 */ 446 */
515struct dtv_stats { 447struct dtv_stats {
516 __u8 scale; /* enum fecap_scale_params type */ 448 __u8 scale; /* enum fecap_scale_params type */
517 union { 449 union {
518 __u64 uvalue; /* for counters and relative scales */ 450 __u64 uvalue; /* for counters and relative scales */
519 __s64 svalue; /* for 0.0001 dB measures */ 451 __s64 svalue; /* for 0.001 dB measures */
520 }; 452 };
521} __attribute__ ((packed)); 453} __attribute__ ((packed));
522 454
@@ -552,10 +484,88 @@ struct dtv_properties {
552 struct dtv_property *props; 484 struct dtv_property *props;
553}; 485};
554 486
487#if defined(__DVB_CORE__) || !defined (__KERNEL__)
488
489/*
490 * DEPRECATED: The DVBv3 ioctls, structs and enums should not be used on
491 * newer programs, as it doesn't support the second generation of digital
492 * TV standards, nor supports newer delivery systems.
493 */
494
495enum fe_bandwidth {
496 BANDWIDTH_8_MHZ,
497 BANDWIDTH_7_MHZ,
498 BANDWIDTH_6_MHZ,
499 BANDWIDTH_AUTO,
500 BANDWIDTH_5_MHZ,
501 BANDWIDTH_10_MHZ,
502 BANDWIDTH_1_712_MHZ,
503};
504
505/* This is needed for legacy userspace support */
506typedef enum fe_sec_voltage fe_sec_voltage_t;
507typedef enum fe_caps fe_caps_t;
508typedef enum fe_type fe_type_t;
509typedef enum fe_sec_tone_mode fe_sec_tone_mode_t;
510typedef enum fe_sec_mini_cmd fe_sec_mini_cmd_t;
511typedef enum fe_status fe_status_t;
512typedef enum fe_spectral_inversion fe_spectral_inversion_t;
513typedef enum fe_code_rate fe_code_rate_t;
514typedef enum fe_modulation fe_modulation_t;
515typedef enum fe_transmit_mode fe_transmit_mode_t;
516typedef enum fe_bandwidth fe_bandwidth_t;
517typedef enum fe_guard_interval fe_guard_interval_t;
518typedef enum fe_hierarchy fe_hierarchy_t;
519typedef enum fe_pilot fe_pilot_t;
520typedef enum fe_rolloff fe_rolloff_t;
521typedef enum fe_delivery_system fe_delivery_system_t;
522
523struct dvb_qpsk_parameters {
524 __u32 symbol_rate; /* symbol rate in Symbols per second */
525 fe_code_rate_t fec_inner; /* forward error correction (see above) */
526};
527
528struct dvb_qam_parameters {
529 __u32 symbol_rate; /* symbol rate in Symbols per second */
530 fe_code_rate_t fec_inner; /* forward error correction (see above) */
531 fe_modulation_t modulation; /* modulation type (see above) */
532};
533
534struct dvb_vsb_parameters {
535 fe_modulation_t modulation; /* modulation type (see above) */
536};
537
538struct dvb_ofdm_parameters {
539 fe_bandwidth_t bandwidth;
540 fe_code_rate_t code_rate_HP; /* high priority stream code rate */
541 fe_code_rate_t code_rate_LP; /* low priority stream code rate */
542 fe_modulation_t constellation; /* modulation type (see above) */
543 fe_transmit_mode_t transmission_mode;
544 fe_guard_interval_t guard_interval;
545 fe_hierarchy_t hierarchy_information;
546};
547
548struct dvb_frontend_parameters {
549 __u32 frequency; /* (absolute) frequency in Hz for DVB-C/DVB-T/ATSC */
550 /* intermediate frequency in kHz for DVB-S */
551 fe_spectral_inversion_t inversion;
552 union {
553 struct dvb_qpsk_parameters qpsk; /* DVB-S */
554 struct dvb_qam_parameters qam; /* DVB-C */
555 struct dvb_ofdm_parameters ofdm; /* DVB-T */
556 struct dvb_vsb_parameters vsb; /* ATSC */
557 } u;
558};
559
560struct dvb_frontend_event {
561 fe_status_t status;
562 struct dvb_frontend_parameters parameters;
563};
564#endif
565
555#define FE_SET_PROPERTY _IOW('o', 82, struct dtv_properties) 566#define FE_SET_PROPERTY _IOW('o', 82, struct dtv_properties)
556#define FE_GET_PROPERTY _IOR('o', 83, struct dtv_properties) 567#define FE_GET_PROPERTY _IOR('o', 83, struct dtv_properties)
557 568
558
559/** 569/**
560 * When set, this flag will disable any zigzagging or other "normal" tuning 570 * When set, this flag will disable any zigzagging or other "normal" tuning
561 * behaviour. Additionally, there will be no automatic monitoring of the lock 571 * behaviour. Additionally, there will be no automatic monitoring of the lock
@@ -565,7 +575,6 @@ struct dtv_properties {
565 */ 575 */
566#define FE_TUNE_MODE_ONESHOT 0x01 576#define FE_TUNE_MODE_ONESHOT 0x01
567 577
568
569#define FE_GET_INFO _IOR('o', 61, struct dvb_frontend_info) 578#define FE_GET_INFO _IOR('o', 61, struct dvb_frontend_info)
570 579
571#define FE_DISEQC_RESET_OVERLOAD _IO('o', 62) 580#define FE_DISEQC_RESET_OVERLOAD _IO('o', 62)
diff --git a/include/uapi/linux/v4l2-mediabus.h b/include/uapi/linux/v4l2-mediabus.h
index 26db20647e6f..9cac6325cc7e 100644
--- a/include/uapi/linux/v4l2-mediabus.h
+++ b/include/uapi/linux/v4l2-mediabus.h
@@ -24,6 +24,7 @@
24 * @colorspace: colorspace of the data (from enum v4l2_colorspace) 24 * @colorspace: colorspace of the data (from enum v4l2_colorspace)
25 * @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding) 25 * @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding)
26 * @quantization: quantization of the data (from enum v4l2_quantization) 26 * @quantization: quantization of the data (from enum v4l2_quantization)
27 * @xfer_func: transfer function of the data (from enum v4l2_xfer_func)
27 */ 28 */
28struct v4l2_mbus_framefmt { 29struct v4l2_mbus_framefmt {
29 __u32 width; 30 __u32 width;
@@ -33,7 +34,8 @@ struct v4l2_mbus_framefmt {
33 __u32 colorspace; 34 __u32 colorspace;
34 __u16 ycbcr_enc; 35 __u16 ycbcr_enc;
35 __u16 quantization; 36 __u16 quantization;
36 __u32 reserved[6]; 37 __u16 xfer_func;
38 __u16 reserved[11];
37}; 39};
38 40
39#ifndef __KERNEL__ 41#ifndef __KERNEL__
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index fa376f7666ba..3228fbebcd63 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -178,6 +178,12 @@ enum v4l2_memory {
178 178
179/* see also http://vektor.theorem.ca/graphics/ycbcr/ */ 179/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
180enum v4l2_colorspace { 180enum v4l2_colorspace {
181 /*
182 * Default colorspace, i.e. let the driver figure it out.
183 * Can only be used with video capture.
184 */
185 V4L2_COLORSPACE_DEFAULT = 0,
186
181 /* SMPTE 170M: used for broadcast NTSC/PAL SDTV */ 187 /* SMPTE 170M: used for broadcast NTSC/PAL SDTV */
182 V4L2_COLORSPACE_SMPTE170M = 1, 188 V4L2_COLORSPACE_SMPTE170M = 1,
183 189
@@ -220,8 +226,56 @@ enum v4l2_colorspace {
220 226
221 /* BT.2020 colorspace, used for UHDTV. */ 227 /* BT.2020 colorspace, used for UHDTV. */
222 V4L2_COLORSPACE_BT2020 = 10, 228 V4L2_COLORSPACE_BT2020 = 10,
229
230 /* Raw colorspace: for RAW unprocessed images */
231 V4L2_COLORSPACE_RAW = 11,
232};
233
234/*
235 * Determine how COLORSPACE_DEFAULT should map to a proper colorspace.
236 * This depends on whether this is a SDTV image (use SMPTE 170M), an
237 * HDTV image (use Rec. 709), or something else (use sRGB).
238 */
239#define V4L2_MAP_COLORSPACE_DEFAULT(is_sdtv, is_hdtv) \
240 ((is_sdtv) ? V4L2_COLORSPACE_SMPTE170M : \
241 ((is_hdtv) ? V4L2_COLORSPACE_REC709 : V4L2_COLORSPACE_SRGB))
242
243enum v4l2_xfer_func {
244 /*
245 * Mapping of V4L2_XFER_FUNC_DEFAULT to actual transfer functions
246 * for the various colorspaces:
247 *
248 * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M,
249 * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_REC709 and
250 * V4L2_COLORSPACE_BT2020: V4L2_XFER_FUNC_709
251 *
252 * V4L2_COLORSPACE_SRGB, V4L2_COLORSPACE_JPEG: V4L2_XFER_FUNC_SRGB
253 *
254 * V4L2_COLORSPACE_ADOBERGB: V4L2_XFER_FUNC_ADOBERGB
255 *
256 * V4L2_COLORSPACE_SMPTE240M: V4L2_XFER_FUNC_SMPTE240M
257 *
258 * V4L2_COLORSPACE_RAW: V4L2_XFER_FUNC_NONE
259 */
260 V4L2_XFER_FUNC_DEFAULT = 0,
261 V4L2_XFER_FUNC_709 = 1,
262 V4L2_XFER_FUNC_SRGB = 2,
263 V4L2_XFER_FUNC_ADOBERGB = 3,
264 V4L2_XFER_FUNC_SMPTE240M = 4,
265 V4L2_XFER_FUNC_NONE = 5,
223}; 266};
224 267
268/*
269 * Determine how XFER_FUNC_DEFAULT should map to a proper transfer function.
270 * This depends on the colorspace.
271 */
272#define V4L2_MAP_XFER_FUNC_DEFAULT(colsp) \
273 ((colsp) == V4L2_COLORSPACE_ADOBERGB ? V4L2_XFER_FUNC_ADOBERGB : \
274 ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_XFER_FUNC_SMPTE240M : \
275 ((colsp) == V4L2_COLORSPACE_RAW ? V4L2_XFER_FUNC_NONE : \
276 ((colsp) == V4L2_COLORSPACE_SRGB || (colsp) == V4L2_COLORSPACE_JPEG ? \
277 V4L2_XFER_FUNC_SRGB : V4L2_XFER_FUNC_709))))
278
225enum v4l2_ycbcr_encoding { 279enum v4l2_ycbcr_encoding {
226 /* 280 /*
227 * Mapping of V4L2_YCBCR_ENC_DEFAULT to actual encodings for the 281 * Mapping of V4L2_YCBCR_ENC_DEFAULT to actual encodings for the
@@ -266,6 +320,16 @@ enum v4l2_ycbcr_encoding {
266 V4L2_YCBCR_ENC_SMPTE240M = 8, 320 V4L2_YCBCR_ENC_SMPTE240M = 8,
267}; 321};
268 322
323/*
324 * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
325 * This depends on the colorspace.
326 */
327#define V4L2_MAP_YCBCR_ENC_DEFAULT(colsp) \
328 ((colsp) == V4L2_COLORSPACE_REC709 ? V4L2_YCBCR_ENC_709 : \
329 ((colsp) == V4L2_COLORSPACE_BT2020 ? V4L2_YCBCR_ENC_BT2020 : \
330 ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_YCBCR_ENC_SMPTE240M : \
331 V4L2_YCBCR_ENC_601)))
332
269enum v4l2_quantization { 333enum v4l2_quantization {
270 /* 334 /*
271 * The default for R'G'B' quantization is always full range, except 335 * The default for R'G'B' quantization is always full range, except
@@ -278,6 +342,17 @@ enum v4l2_quantization {
278 V4L2_QUANTIZATION_LIM_RANGE = 2, 342 V4L2_QUANTIZATION_LIM_RANGE = 2,
279}; 343};
280 344
345/*
346 * Determine how QUANTIZATION_DEFAULT should map to a proper quantization.
347 * This depends on whether the image is RGB or not, the colorspace and the
348 * Y'CbCr encoding.
349 */
350#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, colsp, ycbcr_enc) \
351 (((is_rgb) && (colsp) == V4L2_COLORSPACE_BT2020) ? V4L2_QUANTIZATION_LIM_RANGE : \
352 (((is_rgb) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \
353 (ycbcr_enc) == V4L2_YCBCR_ENC_XV709 || (colsp) == V4L2_COLORSPACE_JPEG) ? \
354 V4L2_QUANTIZATION_FULL_RANGE : V4L2_QUANTIZATION_LIM_RANGE))
355
281enum v4l2_priority { 356enum v4l2_priority {
282 V4L2_PRIORITY_UNSET = 0, /* not initialized */ 357 V4L2_PRIORITY_UNSET = 0, /* not initialized */
283 V4L2_PRIORITY_BACKGROUND = 1, 358 V4L2_PRIORITY_BACKGROUND = 1,
@@ -370,6 +445,7 @@ struct v4l2_pix_format {
370 __u32 flags; /* format flags (V4L2_PIX_FMT_FLAG_*) */ 445 __u32 flags; /* format flags (V4L2_PIX_FMT_FLAG_*) */
371 __u32 ycbcr_enc; /* enum v4l2_ycbcr_encoding */ 446 __u32 ycbcr_enc; /* enum v4l2_ycbcr_encoding */
372 __u32 quantization; /* enum v4l2_quantization */ 447 __u32 quantization; /* enum v4l2_quantization */
448 __u32 xfer_func; /* enum v4l2_xfer_func */
373}; 449};
374 450
375/* Pixel format FOURCC depth Description */ 451/* Pixel format FOURCC depth Description */
@@ -404,6 +480,7 @@ struct v4l2_pix_format {
404#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */ 480#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */
405#define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */ 481#define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */
406#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */ 482#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */
483#define V4L2_PIX_FMT_Y16_BE v4l2_fourcc_be('Y', '1', '6', ' ') /* 16 Greyscale BE */
407 484
408/* Grey bit-packed formats */ 485/* Grey bit-packed formats */
409#define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */ 486#define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */
@@ -810,6 +887,8 @@ struct v4l2_buffer {
810#define V4L2_BUF_FLAG_TSTAMP_SRC_MASK 0x00070000 887#define V4L2_BUF_FLAG_TSTAMP_SRC_MASK 0x00070000
811#define V4L2_BUF_FLAG_TSTAMP_SRC_EOF 0x00000000 888#define V4L2_BUF_FLAG_TSTAMP_SRC_EOF 0x00000000
812#define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 889#define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000
890/* mem2mem encoder/decoder */
891#define V4L2_BUF_FLAG_LAST 0x00100000
813 892
814/** 893/**
815 * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor 894 * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor
@@ -1865,6 +1944,7 @@ struct v4l2_plane_pix_format {
1865 * @flags: format flags (V4L2_PIX_FMT_FLAG_*) 1944 * @flags: format flags (V4L2_PIX_FMT_FLAG_*)
1866 * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding 1945 * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
1867 * @quantization: enum v4l2_quantization, colorspace quantization 1946 * @quantization: enum v4l2_quantization, colorspace quantization
1947 * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
1868 */ 1948 */
1869struct v4l2_pix_format_mplane { 1949struct v4l2_pix_format_mplane {
1870 __u32 width; 1950 __u32 width;
@@ -1878,7 +1958,8 @@ struct v4l2_pix_format_mplane {
1878 __u8 flags; 1958 __u8 flags;
1879 __u8 ycbcr_enc; 1959 __u8 ycbcr_enc;
1880 __u8 quantization; 1960 __u8 quantization;
1881 __u8 reserved[8]; 1961 __u8 xfer_func;
1962 __u8 reserved[7];
1882} __attribute__ ((packed)); 1963} __attribute__ ((packed));
1883 1964
1884/** 1965/**